I wish to create a snippet that inserts events in my Google Calendar using the Zend Gdata API. This can be downloaded separated from the framework from
http://framework.zend.com/download/gdata
My trial/evaluation code is working flawlessly on my test environment, running from the webroot as a php-file.
However, the same code inside a snippet doesn’t do.
Here’s my Add2GCal.php file and snippet code:
(The Zend folder containing the Loader.php file and others must be either in the php-path or in the webroot.)
<?php
echo "Starting...<br />";
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// Parameters for ClientAuth authentication
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "[email protected]";
$pass = "mypassword";
echo "Creating HTTP client... ";
// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
echo "OK<br />";
// Create an instance of the Calendar service
$service = new Zend_Gdata_Calendar($client);
echo"Calendar service OK...<br />";
// Create a new entry using the calendar service's magic factory method
$event= $service->newEventEntry();
// Populate the event with the desired information
// Note that each attribute is crated as an instance of a matching class
$event->title = $service->newTitle("My Event");
$event->where = array($service->newWhere("Mountain View, California"));
$event->content = $service->newContent(" This is my awesome event. RSVP required.");
// Set the date using RFC 3339 format.
$startDate = "2008-07-21";
$startTime = "14:00";
$endDate = "2008-07-26";
$endTime = "16:00";
$tzOffset = "0";
$when = $service->newWhen();
$when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$event->when = array($when);
echo "Writing... ";
// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$createdEvent = $service->insertEvent($event);
echo "done... ";
if ($createdEvent)
echo "OK";
else
echo "notOK";
?>
Running this code directly from the webroot gives the right results both in the calendar and onscreen:
[tt]Starting...
Creating HTTP client... OK
Calendar service OK
Writing... done... OK[/tt]
Running it within MODx from a snippet gives me the following error:
[tt]Starting...
Creating HTTP client...
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »
PHP error debug
Error: fopen(Zend/Validate/Hostname/Com.php) [function.fopen]: failed to open stream: No such file or directory
Error type/ Nr.: Warning - 2
File: K:\xampp\php\Zend\Zend\Loader.php
Line: 160
Line 160 source: if (!$fh = @fopen($filename, ’r’, true)) { [/tt]
Which means to me that it stucked in creating the HTTP client. Of course there’s no Com.php file in the whole Zend framework. I suppose the MODx parser is fooling Zend somehow...
Line 160 in the Loader.php is part of a function which looks like this:
//Returns TRUE if the $filename is readable, or FALSE otherwise. This function uses the PHP include_path, where PHP's is_readable() does not.
public static function isReadable($filename)
{
if (!$fh = @fopen($filename, 'r', true)) {
return false;
}
return true;
}
Can anyone help, please?