RSS Feed

実験的に開発した小さなプログラムやWebサービスを公開。また、気になった最新IT技術情報をブログ形式でメモ。

Google Calendar

Zend Frameworkに付属するデモ:
Google Calendar data APIを利用するサンプル

Google Calendar 関連をサポートするクラス群 ”Zend_Gdata” を利用して、Google Calendarと情報のやり取りが行える。

動作サンプル : なし(当サーバで正しく動作しないため)

ソース: /demos/Zend/Gdata/Calendar.php

  1. < ?php
  2.  
  3. /**
  4. * Zend Framework
  5. *
  6. * LICENSE
  7. *
  8. * This source file is subject to the new BSD license that is bundled
  9. * with this package in the file LICENSE.txt.
  10. * It is also available through the world-wide-web at this URL:
  11. * http://framework.zend.com/license/new-bsd
  12. * If you did not receive a copy of the license and are unable to
  13. * obtain it through the world-wide-web, please send an email
  14. * to license@zend.com so we can send you a copy immediately.
  15. *
  16. * @category   Zend
  17. * @package    Zend_Gdata
  18. * @copyright Copyright (c) 2006-2007 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20. */
  21.  
  22. /**
  23. * PHP sample code for the Google Calendar data API.  Utilizes the
  24. * Zend Framework Gdata components to communicate with the Google API.
  25. *
  26. * Requires the Zend Framework Gdata components and PHP >= 5.1.4
  27. *
  28. * You can run this sample both from the command line (CLI) and also
  29. * from a web browser.  When running through a web browser, only
  30. * AuthSub and outputting a list of calendars is demonstrated.  When
  31. * running via CLI, all functionality except AuthSub is available and dependent
  32. * upon the command line options passed.  Run this script without any
  33. * command line options to see usage, eg:
  34. *     /usr/local/bin/php -f Calendar-expanded.php
  35. *
  36. * More information on the Command Line Interface is available at:
  37. *     http://www.php.net/features.commandline
  38. *
  39. * NOTE: You must ensure that the Zend Framework is in your PHP include
  40. * path.  You can do this via php.ini settings, or by modifying the
  41. * argument to set_include_path in the code below.
  42. *
  43. * NOTE: As this is sample code, not all of the functions do full error
  44. * handling.  Please see getEvent for an example of how errors could
  45. * be handled and the online code samples for additional information.
  46. */
  47.  
  48. require_once 'Zend/Loader.php';
  49. Zend_Loader::loadClass('Zend_Gdata');
  50. Zend_Loader::loadClass('Zend_Gdata_AuthSub');
  51. Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  52. Zend_Loader::loadClass('Zend_Gdata_Calendar');
  53.  
  54. /**
  55. * Returns the full URL of the current page, based upon env variables
  56. *
  57. * Env variables used:
  58. * $_SERVER['HTTPS'] = (on|off|)
  59. * $_SERVER['HTTP_HOST'] = value of the Host: header
  60. * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443
  61. * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
  62. *
  63. * @return string Current URL
  64. */
  65. function getCurrentUrl() 
  66. {
  67.   global $_SERVER;
  68.  
  69.   /**
  70.    * Filter php_self to avoid a security vulnerability.
  71.    */
  72.   $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], "
  73.  
  74. ")), ENT_QUOTES);
  75.  
  76.   if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
  77.     $protocol = 'https://';
  78.   } else {
  79.     $protocol = 'http://';
  80.   }
  81.   $host = $_SERVER['HTTP_HOST'];
  82.   if ($_SERVER['SERVER_PORT'] != '' &&
  83.      (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
  84.      ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
  85.     $port = ':' . $_SERVER['SERVER_PORT'];
  86.   } else {
  87.     $port = '';
  88.   }
  89.   return $protocol . $host . $port . $php_request_uri;
  90. }
  91.  
  92. /**
  93. * Returns the AuthSub URL which the user must visit to authenticate requests
  94. * from this application.
  95. *
  96. * Uses getCurrentUrl() to get the next URL which the user will be redirected
  97. * to after successfully authenticating with the Google service.
  98. *
  99. * @return string AuthSub URL
  100. */
  101. function getAuthSubUrl() 
  102. {
  103.   $next = getCurrentUrl();
  104.   $scope = 'http://www.google.com/calendar/feeds/';
  105.   $secure = false;
  106.   $session = true;
  107.   return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure,
  108.       $session);
  109. }
  110.  
  111. /**
  112. * Outputs a request to the user to login to their Google account, including
  113. * a link to the AuthSub URL.
  114. *
  115. * Uses getAuthSubUrl() to get the URL which the user must visit to authenticate
  116. */
  117. function requestUserLogin($linkText) 
  118. {
  119.   $authSubUrl = getAuthSubUrl();
  120.   echo "<a href="{$authSubUrl}">{$linkText}</a>";
  121. }
  122.  
  123. /**
  124. * Returns a HTTP client object with the appropriate headers for communicating
  125. * with Google using AuthSub authentication.
  126. *
  127. * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  128. * it is obtained.  The single use token supplied in the URL when redirected
  129. * after the user succesfully authenticated to Google is retrieved from the
  130. * $_GET['token'] variable.
  131. *
  132. * @return Zend_Http_Client
  133. */
  134. function getAuthSubHttpClient() 
  135. {
  136.   global $_SESSION, $_GET;
  137.   if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  138.     $_SESSION['sessionToken'] =
  139.         Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  140.   } 
  141.   $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
  142.   return $client;
  143. }
  144.  
  145. /**
  146. * Processes loading of this sample code through a web browser.  Uses AuthSub
  147. * authentication and outputs a list of a user's calendars if succesfully
  148. * authenticated.
  149. *
  150. * @return void
  151. */
  152. function processPageLoad() 
  153. {
  154.   global $_SESSION, $_GET;
  155.   if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
  156.     requestUserLogin('Please login to your Google Account.');
  157.   } else {
  158.     $client = getAuthSubHttpClient();
  159.     outputCalendarList($client);
  160.   }
  161. }
  162.  
  163. /**
  164. * Returns a HTTP client object with the appropriate headers for communicating
  165. * with Google using the ClientLogin credentials supplied.
  166. *
  167. * @param string $user The username, in e-mail address format, to authenticate
  168. * @param string $pass The password for the user specified
  169. * @return Zend_Http_Client
  170. */
  171. function getClientLoginHttpClient($user, $pass) 
  172. {
  173.   $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
  174.  
  175.   $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  176.   return $client;
  177. }
  178.  
  179. /**
  180. * Outputs an HTML unordered list (ul), with each list item representing an event
  181. * in the user's calendar.  The calendar is retrieved using the magic cookie
  182. * which allows read-only access to private calendar data using a special token
  183. * available from within the Calendar UI.
  184. *
  185. * @param string $user The username or address of the calendar to be retrieved.
  186. * @param string $magicCookie The magic cookie token
  187. * @return void
  188. */
  189. function outputCalendarMagicCookie($user, $magicCookie) 
  190. {
  191.   $gdataCal = new Zend_Gdata_Calendar();
  192.   $query = $gdataCal->newEventQuery();
  193.   $query->setUser($user);
  194.   $query->setVisibility('private-' . $magicCookie);
  195.   $query->setProjection('full');
  196.   $eventFeed = $gdataCal->getCalendarEventFeed($query);
  197.   echo "<ul>
  198. ";
  199.   foreach ($eventFeed as $event) {
  200.     echo "    <li>" . $event->title->text . "</li>
  201. ";
  202.     $sl = $event->getLink('self')->href;
  203.   }
  204.   echo "</ul>
  205. ";
  206. }
  207.  
  208. /**
  209. * Outputs an HTML unordered list (ul), with each list item representing a
  210. * calendar in the authenticated user's calendar list. 
  211. *
  212. * @param Zend_Http_Client $client The authenticated client object
  213. * @return void
  214. */
  215. function outputCalendarList($client) 
  216. {
  217.   $gdataCal = new Zend_Gdata_Calendar($client);
  218.   $calFeed = $gdataCal->getCalendarListFeed();
  219.   echo "<h1>" . $calFeed->title->text . "</h1>
  220. ";
  221.   echo "<ul>
  222. ";
  223.   foreach ($calFeed as $calendar) {
  224.     echo "    <li>" . $calendar->title->text . "</li>
  225. ";
  226.   }
  227.   echo "</ul>
  228. ";
  229. } 
  230.  
  231. /**
  232. * Outputs an HTML unordered list (ul), with each list item representing an
  233. * event on the authenticated user's calendar.  Includes the start time and
  234. * event ID in the output.  Events are ordered by starttime and include only
  235. * events occurring in the future.
  236. *
  237. * @param Zend_Http_Client $client The authenticated client object
  238. * @return void
  239. */
  240. function outputCalendar($client) 
  241. {
  242.   $gdataCal = new Zend_Gdata_Calendar($client);
  243.   $query = $gdataCal->newEventQuery();
  244.   $query->setUser('default');
  245.   $query->setVisibility('private');
  246.   $query->setProjection('full');
  247.   $query->setOrderby('starttime');
  248.   $query->setFutureevents(true);
  249.   $eventFeed = $gdataCal->getCalendarEventFeed($query);
  250.   // option 2
  251.   // $eventFeed = $gdataCal->getCalendarEventFeed($query->getQueryUrl());
  252.   echo "<ul>
  253. ";
  254.   foreach ($eventFeed as $event) {
  255.     echo "    <li>" . $event->title->text" (" . $event->id->text . ")
  256. ";
  257.     // Zend_Gdata_App_Extensions_Title->__toString() is defined, so the
  258.     // following will also work on PHP >= 5.2.0
  259.     //echo "    </li><li>" . $event->title .  " (" . $event->id . ")
  260. ";
  261.     echo "        <ul>
  262. ";
  263.     foreach ($event->when as $when) {
  264.       echo "            <li>Starts: " . $when->startTime . "</li>
  265. ";
  266.     }
  267.     echo "        </ul>
  268. ";
  269.     echo "    </li>
  270. ";
  271.   }
  272.   echo "</ul>
  273. ";
  274. }
  275.  
  276. /**
  277. * Outputs an HTML unordered list (ul), with each list item representing an
  278. * event on the authenticated user's calendar which occurs during the
  279. * specified date range.
  280. *
  281. * To query for all events occurring on 2006-12-24, you would query for
  282. * a startDate of '2006-12-24' and an endDate of '2006-12-25' as the upper
  283. * bound for date queries is exclusive.  See the 'query parameters reference':
  284. * http://code.google.com/apis/gdata/calendar.html#Parameters
  285. *
  286. * @param Zend_Http_Client $client The authenticated client object
  287. * @param string $startDate The start date in YYYY-MM-DD format
  288. * @param string $endDate The end date in YYYY-MM-DD format
  289. * @return void
  290. */
  291. function outputCalendarByDateRange($client, $startDate='2007-05-01',
  292.                                    $endDate='2007-08-01')
  293. {
  294.   $gdataCal = new Zend_Gdata_Calendar($client);
  295.   $query = $gdataCal->newEventQuery();
  296.   $query->setUser('default');
  297.   $query->setVisibility('private');
  298.   $query->setProjection('full');
  299.   $query->setOrderby('starttime');
  300.   $query->setStartMin($startDate);
  301.   $query->setStartMax($endDate);
  302.   $eventFeed = $gdataCal->getCalendarEventFeed($query);
  303.   echo "<ul>
  304. ";
  305.   foreach ($eventFeed as $event) {
  306.     echo "    <li>" . $event->title->text .  " (" . $event->id->text . ")
  307. ";
  308.     echo "        <ul>
  309. ";
  310.     foreach ($event->when as $when) {
  311.       echo "            <li>Starts: " . $when->startTime . "</li>
  312. ";
  313.     }
  314.     echo "        </ul>
  315. ";
  316.     echo "    </li>
  317. ";
  318.   }
  319.   echo "</ul>
  320. ";
  321. }
  322.  
  323. /**
  324. * Outputs an HTML unordered list (ul), with each list item representing an
  325. * event on the authenticated user's calendar which matches the search string
  326. * specified as the $fullTextQuery parameter
  327. *
  328. * @param Zend_Http_Client $client The authenticated client object
  329. * @param string $fullTextQuery The string for which you are searching
  330. * @return void
  331. */
  332. function outputCalendarByFullTextQuery($client, $fullTextQuery='tennis')
  333. {
  334.   $gdataCal = new Zend_Gdata_Calendar($client);
  335.   $query = $gdataCal->newEventQuery();
  336.   $query->setUser('default');
  337.   $query->setVisibility('private');
  338.   $query->setProjection('full');
  339.   $query->setQuery($fullTextQuery);
  340.   $eventFeed = $gdataCal->getCalendarEventFeed($query);
  341.   echo "<ul>
  342. ";
  343.   foreach ($eventFeed as $event) {
  344.     echo "    <li>" . $event->title->text .  " (" . $event->id->text . ")
  345. ";
  346.     echo "        <ul>
  347. ";
  348.     foreach ($event->when as $when) {
  349.       echo "            <li>Starts: " . $when->startTime . "</li>
  350. ";
  351.       echo "        </ul>
  352. ";
  353.       echo "    </li>
  354. ";
  355.     }
  356.   }
  357.   echo "</ul>
  358. ";
  359. }
  360.  
  361. /**
  362. * Creates an event on the authenticated user's default calendar with the
  363. * specified event details.
  364. *
  365. * @param Zend_Http_Client $client The authenticated client object
  366. * @param string $title The event title
  367. * @param string $desc The detailed description of the event
  368. * @param string $startDate The start date of the event in YYYY-MM-DD format
  369. * @param string $startTime The start time of the event in HH:MM 24hr format
  370. * @param string $endTime The end time of the event in HH:MM 24hr format
  371. * @param string $tzOffset The offset from GMT/UTC in [+-]DD format (eg -08)
  372. * @return string The ID URL for the event.
  373. */
  374. function createEvent ($client, $title = 'Tennis with Beth',
  375.     $desc='Meet for a quick lesson', $where = 'On the courts',
  376.     $startDate = '2008-01-20', $startTime = '10:00',
  377.     $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
  378. {
  379.   $gc = new Zend_Gdata_Calendar($client);
  380.   $newEntry = $gc->newEventEntry();
  381.   $newEntry->title = $gc->newTitle(trim($title));
  382.   $newEntry->where  = array($gc->newWhere($where));
  383.  
  384.   $newEntry->content = $gc->newContent($desc);
  385.   $newEntry->content->type = 'text';
  386.  
  387.   $when = $gc->newWhen();
  388.   $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
  389.   $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
  390.   $newEntry->when = array($when);
  391.  
  392.   $createdEntry = $gc->insertEvent($newEntry);
  393.   return $createdEntry->id->text;
  394. }
  395.  
  396. /**
  397. * Creates an event on the authenticated user's default calendar using
  398. * the specified QuickAdd string.
  399. *
  400. * @param Zend_Http_Client $client The authenticated client object
  401. * @param string $quickAddText The QuickAdd text for the event
  402. * @return string The ID URL for the event
  403. */
  404. function createQuickAddEvent ($client, $quickAddText) {
  405.   $gdataCal = new Zend_Gdata_Calendar($client);
  406.   $event = $gdataCal->newEventEntry();
  407.   $event->content = $gdataCal->newContent($quickAddText);
  408.   $event->quickAdd = $gdataCal->newQuickAdd(true);
  409.  
  410.   $newEvent = $gdataCal->insertEvent($event);
  411.   return $newEvent->id->text;
  412. }
  413.  
  414. /**
  415. * Creates a new web content event on the authenticated user's default
  416. * calendar with the specified event details. For simplicity, the event
  417. * is created as an all day event and does not include a description.
  418. *
  419. * @param Zend_Http_Client $client The authenticated client object
  420. * @param string $title The event title
  421. * @param string $startDate The start date of the event in YYYY-MM-DD format
  422. * @param string $endDate The end time of the event in HH:MM 24hr format
  423. * @param string $icon URL pointing to a 16x16 px icon representing the event.
  424. * @param string $url The URL containing the web content for the event.
  425. * @param string $height The desired height of the web content pane.
  426. * @param string $width The desired width of the web content pane.
  427. * @param string $type The MIME type of the web content.
  428. * @return string The ID URL for the event.
  429. */
  430. function createWebContentEvent ($client, $title = 'World Cup 2006',
  431.     $startDate = '2006-06-09', $endDate = '2006-06-09',
  432.     $icon = 'http://www.google.com/calendar/images/google-holiday.gif',
  433.     $url = 'http://www.google.com/logos/worldcup06.gif',
  434.     $height  = '120', $width = '276', $type = 'image/gif'
  435.     )
  436. {
  437.   $gc = new Zend_Gdata_Calendar($client);
  438.   $newEntry = $gc->newEventEntry();
  439.   $newEntry->title = $gc->newTitle(trim($title));
  440.  
  441.   $when = $gc->newWhen();
  442.   $when->startTime = $startDate;
  443.   $when->endTime = $endDate;
  444.   $newEntry->when = array($when);
  445.  
  446.   $wc = $gc->newWebContent();
  447.   $wc->url = $url;
  448.   $wc->height = $height;
  449.   $wc->width = $width;
  450.  
  451.   $wcLink = $gc->newLink();
  452.   $wcLink->rel = "http://schemas.google.com/gCal/2005/webContent";
  453.   $wcLink->title = $title;
  454.   $wcLink->type = $type;
  455.   $wcLink->href = $icon;
  456.  
  457.   $wcLink->webContent = $wc;
  458.   $newEntry->link = array($wcLink);
  459.  
  460.   $createdEntry = $gc->insertEvent($newEntry);
  461.   return $createdEntry->id->text;
  462. }
  463.  
  464. /**
  465. * Creates a recurring event on the authenticated user's default calendar with
  466. * the specified event details. 
  467. *
  468. * @param Zend_Http_Client $client The authenticated client object
  469. * @param string $title The event title
  470. * @param string $desc The detailed description of the event
  471. * @param string $recurData The iCalendar recurring event syntax (RFC2445)
  472. * @return void
  473. */
  474. function createRecurringEvent ($client, $title = 'Tennis with Beth',
  475.     $desc='Meet for a quick lesson', $where = 'On the courts',
  476.     $recurData = null)
  477. {
  478.   $gc = new Zend_Gdata_Calendar($client);
  479.   $newEntry = $gc->newEventEntry();
  480.   $newEntry->title = $gc->newTitle(trim($title));
  481.   $newEntry->where = array($gc->newWhere($where));
  482.  
  483.   $newEntry->content = $gc->newContent($desc);
  484.   $newEntry->content->type = 'text';
  485.  
  486.   /**
  487.    * Due to the length of this recurrence syntax, we did not specify
  488.    * it as a default parameter value directly
  489.    */
  490.   if ($recurData == null) {
  491.     $recurData =
  492.         "DTSTART;VALUE=DATE:20070501
  493. " .
  494.         "DTEND;VALUE=DATE:20070502
  495. " .
  496.         "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904
  497. ";
  498.   }
  499.  
  500.   $newEntry->recurrence = $gc->newRecurrence($recurData);
  501.  
  502.   $gc->post($newEntry->saveXML());
  503. }
  504.  
  505. /**
  506. * Returns an entry object representing the event with the specified ID.
  507. *
  508. * @param Zend_Http_Client $client The authenticated client object
  509. * @param string $eventId The event ID string
  510. * @return Zend_Gdata_Calendar_EventEntry if the event is found, null if it's not
  511. */
  512. function getEvent($client, $eventId) 
  513. {
  514.   $gdataCal = new Zend_Gdata_Calendar($client);
  515.   $query = $gdataCal->newEventQuery();
  516.   $query->setUser('default');
  517.   $query->setVisibility('private');
  518.   $query->setProjection('full');
  519.   $query->setEvent($eventId);
  520.  
  521.   try {
  522.     $eventEntry = $gdataCal->getCalendarEventEntry($query);
  523.     return $eventEntry;
  524.   } catch (Zend_Gdata_App_Exception $e) {
  525.     var_dump($e);
  526.     return null;
  527.   }
  528. }
  529.  
  530. /**
  531. * Updates the title of the event with the specified ID to be
  532. * the title specified.  Also outputs the new and old title
  533. * with HTML br elements separating the lines
  534. *
  535. * @param Zend_Http_Client $client The authenticated client object
  536. * @param string $eventId The event ID string
  537. * @param string $newTitle The new title to set on this event
  538. * @return Zend_Gdata_Calendar_EventEntry The updated entry
  539. */
  540. function updateEvent ($client, $eventId, $newTitle) 
  541. {
  542.   $gdataCal = new Zend_Gdata_Calendar($client);
  543.   if ($eventOld = getEvent($client, $eventId)) {
  544.     echo "Old title: " . $eventOld->title->text . "<br />
  545. ";
  546.     $eventOld->title = $gdataCal->newTitle($newTitle);
  547.     try {
  548.         $eventOld->save();
  549.     } catch (Zend_Gdata_App_Exception $e) {
  550.         var_dump($e);
  551.         return null;
  552.     }
  553.     $eventNew = getEvent($client, $eventId);
  554.     echo "New title: " . $eventNew->title->text . "<br />
  555. ";
  556.     return $eventNew;
  557.   } else {
  558.     return null;
  559.   }
  560. }
  561.  
  562. /**
  563. * Adds an extended property to the event specified as a parameter.
  564. * An extended property is an arbitrary name/value pair that can be added
  565. * to an event and retrieved via the API.  It is not accessible from the
  566. * calendar web interface.
  567. *
  568. * @param Zend_Http_Client $client The authenticated client object
  569. * @param string $eventId The event ID string
  570. * @param string $name The name of the extended property
  571. * @param string $value The value of the extended property
  572. * @return Zend_Gdata_Calendar_EventEntry The updated entry
  573. */
  574. function addExtendedProperty ($client, $eventId,
  575.     $name='http://www.example.com/schemas/2005#mycal.id', $value='1234') 
  576. {
  577.   $gc = new Zend_Gdata_Calendar($client);
  578.   if ($event = getEvent($client, $eventId)) {
  579.     $extProp = $gc->newExtendedProperty($name, $value);
  580.     $extProps = array_merge($event->extendedProperty, array($extProp));
  581.     $event->extendedProperty = $extProps;
  582.     $eventNew = $event->save();
  583.     return $eventNew;
  584.   } else {
  585.     return null;
  586.   }
  587. } 
  588.  
  589.  
  590. /**
  591. * Adds a reminder to the event specified as a parameter.
  592. *
  593. * @param Zend_Http_Client $client The authenticated client object
  594. * @param string $eventId The event ID string
  595. * @param int $minutes Minutes before event to set reminder
  596. * @return Zend_Gdata_Calendar_EventEntry The updated entry
  597. */
  598. function setReminder($client, $eventId, $minutes=15)
  599. {
  600.   $gc = new Zend_Gdata_Calendar($client);
  601.   $method = "alert";
  602.   if ($event = getEvent($client, $eventId)) {
  603.     $times = $event->when;
  604.     foreach ($times as $when) {
  605.         $reminder = $gc->newReminder();
  606.         $reminder->setMinutes($minutes);
  607.         $reminder->setMethod($method);
  608.         $when->reminder = array($reminder);
  609.     }
  610.     $eventNew = $event->save();
  611.     return $eventNew;
  612.   } else {
  613.     return null;
  614.   }
  615. }
  616.  
  617. /**
  618. * Deletes the event specified by retrieving the atom entry object
  619. * and calling Zend_Feed_EntryAtom::delete() method.  This is for
  620. * example purposes only, as it is inefficient to retrieve the entire
  621. * atom entry only for the purposes of deleting it.
  622. *
  623. * @param Zend_Http_Client $client The authenticated client object
  624. * @param string $eventId The event ID string
  625. * @return void
  626. */
  627. function deleteEventById ($client, $eventId) 
  628. {
  629.   $event = getEvent($client, $eventId);
  630.   $event->delete();
  631. }
  632.  
  633. /**
  634. * Deletes the event specified by calling the Zend_Gdata::delete()
  635. * method.  The URL is typically in the format of:
  636. * http://www.google.com/calendar/feeds/default/private/full/<eventid>
  637. *
  638. * @param Zend_Http_Client $client The authenticated client object
  639. * @param string $url The url for the event to be deleted
  640. * @return void
  641. */
  642. function deleteEventByUrl ($client, $url) 
  643. {
  644.   $gdataCal = new Zend_Gdata_Calendar($client);
  645.   $gdataCal->delete($url);
  646. }
  647.  
  648. /**
  649. * Main logic for running this sample code via the command line or,
  650. * for AuthSub functionality only, via a web browser.  The output of
  651. * many of the functions is in HTML format for demonstration purposes,
  652. * so you may wish to pipe the output to Tidy when running from the
  653. * command-line for clearer results.
  654. *
  655. * Run without any arguments to get usage information
  656. */
  657. if (isset($argc) && $argc >= 2) {
  658.   switch ($argv[1]) {
  659.     case 'outputCalendar':
  660.       if ($argc == 4) { 
  661.         $client = getClientLoginHttpClient($argv[2], $argv[