You can email a special address and it will take the subject of the email and send it to googles quickadd feature. This is a simple way to add events to your google calendar via email.
–http://www.google.com/calendar
–http://framework.zend.com/download/gdata
–http://www.google.com/support/calendar/bin/answer.py?hl=en&answer=36604
- You need to have Zend’s Gdata framework installed.
- The first code example you need to add your google calendar information
- the 2nd peice of code parses the email and calls the the quickadd function
- In cpanel setup a forwarder and pipe it to a program of TOGcal.php
<?php //GoogleCal-Functions.php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
// Enter your Google account credentials
$email = '[email protected]';
$passwd = 'MyPass';
$ourCal = 'Cal Name';
$ourCalUrl = '';
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');
}
catch(Zend_Gdata_App_AuthException $ex)
{
echo "Unable to authenticate";
exit(1);
}
$cal = new Zend_Gdata_Calendar($client);
$calFeed = $cal->getCalendarListFeed();
foreach ($calFeed as $calendar)
{
if ($calendar->title->text == $ourCal)
{
//$ourCalUrl = explode('/',$calendar->id);
//$ourCalUrl = 'http://www.google.com/calendar/feeds/'. $ourCalUrl[6] . '/private/full';
$ourCalUrl = $calendar->getSelfLink()->getHref() . '/private/full';
$ourCalUrl = str_replace("default/", "",$ourCalUrl);
}
//echo $calendar->title->text . " || " . $calendar->getSelfLink()->getHref() . "
";
}
//echo $ourCalUrl;
//echo $client->getUri(true);
//createQuickAddEvent ($client ,$ourCalUrl,'WO Test at Jun 2, 2008 8:00am - Jun 6, 2008 5:00pm');
//createEvent($client,$ourCalUrl);
function createQuickAddEvent ($client, $URI = NULL, $quickAddText) {
$gdataCal = new Zend_Gdata_Calendar($client);
$event = $gdataCal->newEventEntry();
$event->content = $gdataCal->newContent($quickAddText);
$event->quickAdd = $gdataCal->newQuickAdd(true);
$newEvent = $gdataCal->insertEvent($event,$URI);
return $newEvent->id->text;
}
/**
* Creates an event on the authenticated user's default calendar with the
* specified event details.
*
* @param Zend_Http_Client $client The authenticated client object
* @param string $title The event title
* @param string $desc The detailed description of the event
* @param string $where
* @param string $startDate The start date of the event in YYYY-MM-DD format
* @param string $startTime The start time of the event in HH:MM 24hr format
* @param string $endDate The end date of the event in YYYY-MM-DD format
* @param string $endTime The end time of the event in HH:MM 24hr format
* @param string $tzOffset The offset from GMT/UTC in [+-]DD format (eg -08)
* @return string The ID URL for the event.
*/
function createEvent ($client, $URI = NULL, $title = 'Tennis with Beth', $desc='Meet for a quick lesson', $where = 'On the courts',$startDate = '2008-06-20', $startTime = '9:00',$endDate = '2008-06-20', $endTime = '14:00', $tzOffset = '-04')
{
$gc = new Zend_Gdata_Calendar($client);
$newEntry = $gc->newEventEntry();
$newEntry->title = $gc->newTitle(trim($title));
$newEntry->where = array($gc->newWhere($where));
$newEntry->content = $gc->newContent($desc);
$newEntry->content->type = 'text';
$when = $gc->newWhen();
$when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$newEntry->when = array($when);
echo $URI."||".$title."||".$desc."||".$where."||".$startDate."||".$startTime."||".$endDate."||".$endTime."||".$tzOffset;
$createdEntry = $gc->insertEvent($newEntry, $URI);
return $createdEntry->id->text;
}
?>
#!/usr/bin/php -q
<?php
//TOGcal.php
//Takes the subject and uses quickadd to create an event.
include "GoogleCal-Functions.php";
$msg = "";
$email ='';
$fd = fopen("php://stdin", "r");
while (!feof($fd))
{
$email .= fread($fd, 1024);
}
fclose($fd);
$msg .= "got Email || ";
$mail = mailparse_msg_create();
mailparse_msg_parse($mail,$email);
$struct = mailparse_msg_get_structure($mail);
$section = mailparse_msg_get_part($mail, "1");
$info = mailparse_msg_get_part_data($section);
$msg .= $info['headers']['from'] . " || " . $info['headers']['subject'] . " || ";
//valid sending domains
if (preg_match('/@mydomain\.com/', $info['headers']['from']))
{
createQuickAddEvent($client,$ourCalUrl,$info['headers']['subject']);
$msg .= "regex matched || ";
}
mailparse_msg_free($mail);
//emailError($msg);
?>