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.
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
26 require_once 'Zend/Gdata.php';
29 * @see Zend_Gdata_Photos_UserFeed
31 require_once 'Zend/Gdata/Photos/UserFeed.php';
34 * @see Zend_Gdata_Photos_AlbumFeed
36 require_once 'Zend/Gdata/Photos/AlbumFeed.php';
39 * @see Zend_Gdata_Photos_PhotoFeed
41 require_once 'Zend/Gdata/Photos/PhotoFeed.php';
44 * Service class for interacting with the Google Photos Data API.
46 * Like other service classes in this module, this class provides access via
47 * an HTTP client to Google servers for working with entries and feeds.
49 * @link http://code.google.com/apis/picasaweb/gdata.html
54 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
55 * @license http://framework.zend.com/license/new-bsd New BSD License
57 class Zend_Gdata_Photos
extends Zend_Gdata
60 const PICASA_BASE_URI
= 'http://picasaweb.google.com/data';
61 const PICASA_BASE_FEED_URI
= 'http://picasaweb.google.com/data/feed';
62 const AUTH_SERVICE_NAME
= 'lh2';
65 * Default projection when interacting with the Picasa server.
67 const DEFAULT_PROJECTION
= 'api';
70 * The default visibility to filter events by.
72 const DEFAULT_VISIBILITY
= 'all';
75 * The default user to retrieve feeds for.
77 const DEFAULT_USER
= 'default';
80 * Path to the user feed on the Picasa server.
82 const USER_PATH
= 'user';
85 * Path to album feeds on the Picasa server.
87 const ALBUM_PATH
= 'albumid';
90 * Path to photo feeds on the Picasa server.
92 const PHOTO_PATH
= 'photoid';
95 * The path to the community search feed on the Picasa server.
97 const COMMUNITY_SEARCH_PATH
= 'all';
100 * The path to use for finding links to feeds within entries
102 const FEED_LINK_PATH
= 'http://schemas.google.com/g/2005#feed';
105 * The path to use for the determining type of an entry
107 const KIND_PATH
= 'http://schemas.google.com/g/2005#kind';
110 * Namespaces used for Zend_Gdata_Photos
114 public static $namespaces = array(
115 array('gphoto', 'http://schemas.google.com/photos/2007', 1, 0),
116 array('photo', 'http://www.pheed.com/pheed/', 1, 0),
117 array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0),
118 array('georss', 'http://www.georss.org/georss', 1, 0),
119 array('gml', 'http://www.opengis.net/gml', 1, 0),
120 array('media', 'http://search.yahoo.com/mrss/', 1, 0)
124 * Create Zend_Gdata_Photos object
126 * @param Zend_Http_Client $client (optional) The HTTP client to use when
127 * when communicating with the servers.
128 * @param string $applicationId The identity of the app in the form of Company-AppName-Version
130 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
132 $this->registerPackage('Zend_Gdata_Photos');
133 $this->registerPackage('Zend_Gdata_Photos_Extension');
134 parent
::__construct($client, $applicationId);
135 $this->_httpClient
->setParameterPost('service', self
::AUTH_SERVICE_NAME
);
139 * Retrieve a UserFeed containing AlbumEntries, PhotoEntries and
140 * TagEntries associated with a given user.
142 * @param string $userName The userName of interest
143 * @param mixed $location (optional) The location for the feed, as a URL
144 * or Query. If not provided, a default URL will be used instead.
145 * @return Zend_Gdata_Photos_UserFeed
146 * @throws Zend_Gdata_App_Exception
147 * @throws Zend_Gdata_App_HttpException
149 public function getUserFeed($userName = null, $location = null)
151 if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
152 $location->setType('feed');
153 if ($userName !== null) {
154 $location->setUser($userName);
156 $uri = $location->getQueryUrl();
157 } else if ($location instanceof Zend_Gdata_Query
) {
158 if ($userName !== null) {
159 $location->setUser($userName);
161 $uri = $location->getQueryUrl();
162 } else if ($location !== null) {
164 } else if ($userName !== null) {
165 $uri = self
::PICASA_BASE_FEED_URI
. '/' .
166 self
::DEFAULT_PROJECTION
. '/' . self
::USER_PATH
. '/' .
169 $uri = self
::PICASA_BASE_FEED_URI
. '/' .
170 self
::DEFAULT_PROJECTION
. '/' . self
::USER_PATH
. '/' .
174 return parent
::getFeed($uri, 'Zend_Gdata_Photos_UserFeed');
178 * Retreive AlbumFeed object containing multiple PhotoEntry or TagEntry
181 * @param mixed $location (optional) The location for the feed, as a URL or Query.
182 * @return Zend_Gdata_Photos_AlbumFeed
183 * @throws Zend_Gdata_App_Exception
184 * @throws Zend_Gdata_App_HttpException
186 public function getAlbumFeed($location = null)
188 if ($location === null) {
189 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
190 throw new Zend_Gdata_App_InvalidArgumentException(
191 'Location must not be null');
192 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
193 $location->setType('feed');
194 $uri = $location->getQueryUrl();
195 } else if ($location instanceof Zend_Gdata_Query
) {
196 $uri = $location->getQueryUrl();
200 return parent
::getFeed($uri, 'Zend_Gdata_Photos_AlbumFeed');
204 * Retreive PhotoFeed object containing comments and tags associated
205 * with a given photo.
207 * @param mixed $location (optional) The location for the feed, as a URL
208 * or Query. If not specified, the community search feed will
209 * be returned instead.
210 * @return Zend_Gdata_Photos_PhotoFeed
211 * @throws Zend_Gdata_App_Exception
212 * @throws Zend_Gdata_App_HttpException
214 public function getPhotoFeed($location = null)
216 if ($location === null) {
217 $uri = self
::PICASA_BASE_FEED_URI
. '/' .
218 self
::DEFAULT_PROJECTION
. '/' .
219 self
::COMMUNITY_SEARCH_PATH
;
220 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
221 $location->setType('feed');
222 $uri = $location->getQueryUrl();
223 } else if ($location instanceof Zend_Gdata_Query
) {
224 $uri = $location->getQueryUrl();
228 return parent
::getFeed($uri, 'Zend_Gdata_Photos_PhotoFeed');
232 * Retreive a single UserEntry object.
234 * @param mixed $location The location for the feed, as a URL or Query.
235 * @return Zend_Gdata_Photos_UserEntry
236 * @throws Zend_Gdata_App_Exception
237 * @throws Zend_Gdata_App_HttpException
239 public function getUserEntry($location)
241 if ($location === null) {
242 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
243 throw new Zend_Gdata_App_InvalidArgumentException(
244 'Location must not be null');
245 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
246 $location->setType('entry');
247 $uri = $location->getQueryUrl();
248 } else if ($location instanceof Zend_Gdata_Query
) {
249 $uri = $location->getQueryUrl();
253 return parent
::getEntry($uri, 'Zend_Gdata_Photos_UserEntry');
257 * Retreive a single AlbumEntry object.
259 * @param mixed $location The location for the feed, as a URL or Query.
260 * @return Zend_Gdata_Photos_AlbumEntry
261 * @throws Zend_Gdata_App_Exception
262 * @throws Zend_Gdata_App_HttpException
264 public function getAlbumEntry($location)
266 if ($location === null) {
267 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
268 throw new Zend_Gdata_App_InvalidArgumentException(
269 'Location must not be null');
270 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
271 $location->setType('entry');
272 $uri = $location->getQueryUrl();
273 } else if ($location instanceof Zend_Gdata_Query
) {
274 $uri = $location->getQueryUrl();
278 return parent
::getEntry($uri, 'Zend_Gdata_Photos_AlbumEntry');
282 * Retreive a single PhotoEntry object.
284 * @param mixed $location The location for the feed, as a URL or Query.
285 * @return Zend_Gdata_Photos_PhotoEntry
286 * @throws Zend_Gdata_App_Exception
287 * @throws Zend_Gdata_App_HttpException
289 public function getPhotoEntry($location)
291 if ($location === null) {
292 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
293 throw new Zend_Gdata_App_InvalidArgumentException(
294 'Location must not be null');
295 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
296 $location->setType('entry');
297 $uri = $location->getQueryUrl();
298 } else if ($location instanceof Zend_Gdata_Query
) {
299 $uri = $location->getQueryUrl();
303 return parent
::getEntry($uri, 'Zend_Gdata_Photos_PhotoEntry');
307 * Retreive a single TagEntry object.
309 * @param mixed $location The location for the feed, as a URL or Query.
310 * @return Zend_Gdata_Photos_TagEntry
311 * @throws Zend_Gdata_App_Exception
312 * @throws Zend_Gdata_App_HttpException
314 public function getTagEntry($location)
316 if ($location === null) {
317 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
318 throw new Zend_Gdata_App_InvalidArgumentException(
319 'Location must not be null');
320 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
321 $location->setType('entry');
322 $uri = $location->getQueryUrl();
323 } else if ($location instanceof Zend_Gdata_Query
) {
324 $uri = $location->getQueryUrl();
328 return parent
::getEntry($uri, 'Zend_Gdata_Photos_TagEntry');
332 * Retreive a single CommentEntry object.
334 * @param mixed $location The location for the feed, as a URL or Query.
335 * @return Zend_Gdata_Photos_CommentEntry
336 * @throws Zend_Gdata_App_Exception
337 * @throws Zend_Gdata_App_HttpException
339 public function getCommentEntry($location)
341 if ($location === null) {
342 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
343 throw new Zend_Gdata_App_InvalidArgumentException(
344 'Location must not be null');
345 } else if ($location instanceof Zend_Gdata_Photos_UserQuery
) {
346 $location->setType('entry');
347 $uri = $location->getQueryUrl();
348 } else if ($location instanceof Zend_Gdata_Query
) {
349 $uri = $location->getQueryUrl();
353 return parent
::getEntry($uri, 'Zend_Gdata_Photos_CommentEntry');
357 * Create a new album from a AlbumEntry.
359 * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
361 * @param string $url (optional) The URI that the album should be
362 * uploaded to. If null, the default album creation URI for
363 * this domain will be used.
364 * @return Zend_Gdata_Photos_AlbumEntry The inserted album entry as
365 * returned by the server.
366 * @throws Zend_Gdata_App_Exception
367 * @throws Zend_Gdata_App_HttpException
369 public function insertAlbumEntry($album, $uri = null)
372 $uri = self
::PICASA_BASE_FEED_URI
. '/' .
373 self
::DEFAULT_PROJECTION
. '/' . self
::USER_PATH
. '/' .
376 $newEntry = $this->insertEntry($album, $uri, 'Zend_Gdata_Photos_AlbumEntry');
381 * Create a new photo from a PhotoEntry.
383 * @param Zend_Gdata_Photos_PhotoEntry $photo The photo to insert.
384 * @param string $url The URI that the photo should be uploaded
385 * to. Alternatively, an AlbumEntry can be provided and the
386 * photo will be added to that album.
387 * @return Zend_Gdata_Photos_PhotoEntry The inserted photo entry
388 * as returned by the server.
389 * @throws Zend_Gdata_App_Exception
390 * @throws Zend_Gdata_App_HttpException
392 public function insertPhotoEntry($photo, $uri = null)
394 if ($uri instanceof Zend_Gdata_Photos_AlbumEntry
) {
395 $uri = $uri->getLink(self
::FEED_LINK_PATH
)->href
;
398 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
399 throw new Zend_Gdata_App_InvalidArgumentException(
400 'URI must not be null');
402 $newEntry = $this->insertEntry($photo, $uri, 'Zend_Gdata_Photos_PhotoEntry');
407 * Create a new tag from a TagEntry.
409 * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to insert.
410 * @param string $url The URI where the tag should be
411 * uploaded to. Alternatively, a PhotoEntry can be provided and
412 * the tag will be added to that photo.
413 * @return Zend_Gdata_Photos_TagEntry The inserted tag entry as returned
415 * @throws Zend_Gdata_App_Exception
416 * @throws Zend_Gdata_App_HttpException
418 public function insertTagEntry($tag, $uri = null)
420 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry
) {
421 $uri = $uri->getLink(self
::FEED_LINK_PATH
)->href
;
424 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
425 throw new Zend_Gdata_App_InvalidArgumentException(
426 'URI must not be null');
428 $newEntry = $this->insertEntry($tag, $uri, 'Zend_Gdata_Photos_TagEntry');
433 * Create a new comment from a CommentEntry.
435 * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
437 * @param string $url The URI where the comment should be uploaded to.
438 * Alternatively, a PhotoEntry can be provided and
439 * the comment will be added to that photo.
440 * @return Zend_Gdata_Photos_CommentEntry The inserted comment entry
441 * as returned by the server.
442 * @throws Zend_Gdata_App_Exception
443 * @throws Zend_Gdata_App_HttpException
445 public function insertCommentEntry($comment, $uri = null)
447 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry
) {
448 $uri = $uri->getLink(self
::FEED_LINK_PATH
)->href
;
451 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
452 throw new Zend_Gdata_App_InvalidArgumentException(
453 'URI must not be null');
455 $newEntry = $this->insertEntry($comment, $uri, 'Zend_Gdata_Photos_CommentEntry');
460 * Delete an AlbumEntry.
462 * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
464 * @param boolean $catch Whether to catch an exception when
465 * modified and re-delete or throw
467 * @throws Zend_Gdata_App_Exception
468 * @throws Zend_Gdata_App_HttpException
470 public function deleteAlbumEntry($album, $catch)
474 $this->delete($album);
475 } catch (Zend_Gdata_App_HttpException
$e) {
476 if ($e->getResponse()->getStatus() === 409) {
477 $entry = new Zend_Gdata_Photos_AlbumEntry($e->getResponse()->getBody());
478 $this->delete($entry->getLink('edit')->href
);
484 $this->delete($album);
489 * Delete a PhotoEntry.
491 * @param Zend_Gdata_Photos_PhotoEntry $photo The photo entry to
493 * @param boolean $catch Whether to catch an exception when
494 * modified and re-delete or throw
496 * @throws Zend_Gdata_App_Exception
497 * @throws Zend_Gdata_App_HttpException
499 public function deletePhotoEntry($photo, $catch)
503 $this->delete($photo);
504 } catch (Zend_Gdata_App_HttpException
$e) {
505 if ($e->getResponse()->getStatus() === 409) {
506 $entry = new Zend_Gdata_Photos_PhotoEntry($e->getResponse()->getBody());
507 $this->delete($entry->getLink('edit')->href
);
513 $this->delete($photo);
518 * Delete a CommentEntry.
520 * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
522 * @param boolean $catch Whether to catch an exception when
523 * modified and re-delete or throw
525 * @throws Zend_Gdata_App_Exception
526 * @throws Zend_Gdata_App_HttpException
528 public function deleteCommentEntry($comment, $catch)
532 $this->delete($comment);
533 } catch (Zend_Gdata_App_HttpException
$e) {
534 if ($e->getResponse()->getStatus() === 409) {
535 $entry = new Zend_Gdata_Photos_CommentEntry($e->getResponse()->getBody());
536 $this->delete($entry->getLink('edit')->href
);
542 $this->delete($comment);
549 * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to
551 * @param boolean $catch Whether to catch an exception when
552 * modified and re-delete or throw
554 * @throws Zend_Gdata_App_Exception
555 * @throws Zend_Gdata_App_HttpException
557 public function deleteTagEntry($tag, $catch)
562 } catch (Zend_Gdata_App_HttpException
$e) {
563 if ($e->getResponse()->getStatus() === 409) {
564 $entry = new Zend_Gdata_Photos_TagEntry($e->getResponse()->getBody());
565 $this->delete($entry->getLink('edit')->href
);