File indexing completed on 2025-01-26 05:29:36
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage Photos 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata 0026 */ 0027 // require_once 'Zend/Gdata.php'; 0028 0029 /** 0030 * @see Zend_Gdata_Photos_UserFeed 0031 */ 0032 // require_once 'Zend/Gdata/Photos/UserFeed.php'; 0033 0034 /** 0035 * @see Zend_Gdata_Photos_AlbumFeed 0036 */ 0037 // require_once 'Zend/Gdata/Photos/AlbumFeed.php'; 0038 0039 /** 0040 * @see Zend_Gdata_Photos_PhotoFeed 0041 */ 0042 // require_once 'Zend/Gdata/Photos/PhotoFeed.php'; 0043 0044 /** 0045 * Service class for interacting with the Google Photos Data API. 0046 * 0047 * Like other service classes in this module, this class provides access via 0048 * an HTTP client to Google servers for working with entries and feeds. 0049 * 0050 * @link http://code.google.com/apis/picasaweb/gdata.html 0051 * 0052 * @category Zend 0053 * @package Zend_Gdata 0054 * @subpackage Photos 0055 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0056 * @license http://framework.zend.com/license/new-bsd New BSD License 0057 */ 0058 class Zend_Gdata_Photos extends Zend_Gdata 0059 { 0060 0061 const PICASA_BASE_URI = 'https://picasaweb.google.com/data'; 0062 const PICASA_BASE_FEED_URI = 'https://picasaweb.google.com/data/feed'; 0063 const AUTH_SERVICE_NAME = 'lh2'; 0064 0065 /** 0066 * Default projection when interacting with the Picasa server. 0067 */ 0068 const DEFAULT_PROJECTION = 'api'; 0069 0070 /** 0071 * The default visibility to filter events by. 0072 */ 0073 const DEFAULT_VISIBILITY = 'all'; 0074 0075 /** 0076 * The default user to retrieve feeds for. 0077 */ 0078 const DEFAULT_USER = 'default'; 0079 0080 /** 0081 * Path to the user feed on the Picasa server. 0082 */ 0083 const USER_PATH = 'user'; 0084 0085 /** 0086 * Path to album feeds on the Picasa server. 0087 */ 0088 const ALBUM_PATH = 'albumid'; 0089 0090 /** 0091 * Path to photo feeds on the Picasa server. 0092 */ 0093 const PHOTO_PATH = 'photoid'; 0094 0095 /** 0096 * The path to the community search feed on the Picasa server. 0097 */ 0098 const COMMUNITY_SEARCH_PATH = 'all'; 0099 0100 /** 0101 * The path to use for finding links to feeds within entries 0102 */ 0103 const FEED_LINK_PATH = 'http://schemas.google.com/g/2005#feed'; 0104 0105 /** 0106 * The path to use for the determining type of an entry 0107 */ 0108 const KIND_PATH = 'http://schemas.google.com/g/2005#kind'; 0109 0110 /** 0111 * Namespaces used for Zend_Gdata_Photos 0112 * 0113 * @var array 0114 */ 0115 public static $namespaces = array( 0116 array('gphoto', 'http://schemas.google.com/photos/2007', 1, 0), 0117 array('photo', 'http://www.pheed.com/pheed/', 1, 0), 0118 array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0), 0119 array('georss', 'http://www.georss.org/georss', 1, 0), 0120 array('gml', 'http://www.opengis.net/gml', 1, 0), 0121 array('media', 'http://search.yahoo.com/mrss/', 1, 0) 0122 ); 0123 0124 /** 0125 * Create Zend_Gdata_Photos object 0126 * 0127 * @param Zend_Http_Client $client (optional) The HTTP client to use when 0128 * when communicating with the servers. 0129 * @param string $applicationId The identity of the app in the form of Company-AppName-Version 0130 */ 0131 public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0') 0132 { 0133 $this->registerPackage('Zend_Gdata_Photos'); 0134 $this->registerPackage('Zend_Gdata_Photos_Extension'); 0135 parent::__construct($client, $applicationId); 0136 $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME); 0137 } 0138 0139 /** 0140 * Retrieve a UserFeed containing AlbumEntries, PhotoEntries and 0141 * TagEntries associated with a given user. 0142 * 0143 * @param string $userName The userName of interest 0144 * @param mixed $location (optional) The location for the feed, as a URL 0145 * or Query. If not provided, a default URL will be used instead. 0146 * @return Zend_Gdata_Photos_UserFeed 0147 * @throws Zend_Gdata_App_Exception 0148 * @throws Zend_Gdata_App_HttpException 0149 */ 0150 public function getUserFeed($userName = null, $location = null) 0151 { 0152 if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0153 $location->setType('feed'); 0154 if ($userName !== null) { 0155 $location->setUser($userName); 0156 } 0157 $uri = $location->getQueryUrl(); 0158 } else if ($location instanceof Zend_Gdata_Query) { 0159 if ($userName !== null) { 0160 $location->setUser($userName); 0161 } 0162 $uri = $location->getQueryUrl(); 0163 } else if ($location !== null) { 0164 $uri = $location; 0165 } else if ($userName !== null) { 0166 $uri = self::PICASA_BASE_FEED_URI . '/' . 0167 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 0168 $userName; 0169 } else { 0170 $uri = self::PICASA_BASE_FEED_URI . '/' . 0171 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 0172 self::DEFAULT_USER; 0173 } 0174 0175 return parent::getFeed($uri, 'Zend_Gdata_Photos_UserFeed'); 0176 } 0177 0178 /** 0179 * Retreive AlbumFeed object containing multiple PhotoEntry or TagEntry 0180 * objects. 0181 * 0182 * @param mixed $location (optional) The location for the feed, as a URL or Query. 0183 * @return Zend_Gdata_Photos_AlbumFeed 0184 * @throws Zend_Gdata_App_Exception 0185 * @throws Zend_Gdata_App_HttpException 0186 */ 0187 public function getAlbumFeed($location = null) 0188 { 0189 if ($location === null) { 0190 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0191 throw new Zend_Gdata_App_InvalidArgumentException( 0192 'Location must not be null'); 0193 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0194 $location->setType('feed'); 0195 $uri = $location->getQueryUrl(); 0196 } else if ($location instanceof Zend_Gdata_Query) { 0197 $uri = $location->getQueryUrl(); 0198 } else { 0199 $uri = $location; 0200 } 0201 return parent::getFeed($uri, 'Zend_Gdata_Photos_AlbumFeed'); 0202 } 0203 0204 /** 0205 * Retreive PhotoFeed object containing comments and tags associated 0206 * with a given photo. 0207 * 0208 * @param mixed $location (optional) The location for the feed, as a URL 0209 * or Query. If not specified, the community search feed will 0210 * be returned instead. 0211 * @return Zend_Gdata_Photos_PhotoFeed 0212 * @throws Zend_Gdata_App_Exception 0213 * @throws Zend_Gdata_App_HttpException 0214 */ 0215 public function getPhotoFeed($location = null) 0216 { 0217 if ($location === null) { 0218 $uri = self::PICASA_BASE_FEED_URI . '/' . 0219 self::DEFAULT_PROJECTION . '/' . 0220 self::COMMUNITY_SEARCH_PATH; 0221 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0222 $location->setType('feed'); 0223 $uri = $location->getQueryUrl(); 0224 } else if ($location instanceof Zend_Gdata_Query) { 0225 $uri = $location->getQueryUrl(); 0226 } else { 0227 $uri = $location; 0228 } 0229 return parent::getFeed($uri, 'Zend_Gdata_Photos_PhotoFeed'); 0230 } 0231 0232 /** 0233 * Retreive a single UserEntry object. 0234 * 0235 * @param mixed $location The location for the feed, as a URL or Query. 0236 * @return Zend_Gdata_Photos_UserEntry 0237 * @throws Zend_Gdata_App_Exception 0238 * @throws Zend_Gdata_App_HttpException 0239 */ 0240 public function getUserEntry($location) 0241 { 0242 if ($location === null) { 0243 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0244 throw new Zend_Gdata_App_InvalidArgumentException( 0245 'Location must not be null'); 0246 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0247 $location->setType('entry'); 0248 $uri = $location->getQueryUrl(); 0249 } else if ($location instanceof Zend_Gdata_Query) { 0250 $uri = $location->getQueryUrl(); 0251 } else { 0252 $uri = $location; 0253 } 0254 return parent::getEntry($uri, 'Zend_Gdata_Photos_UserEntry'); 0255 } 0256 0257 /** 0258 * Retreive a single AlbumEntry object. 0259 * 0260 * @param mixed $location The location for the feed, as a URL or Query. 0261 * @return Zend_Gdata_Photos_AlbumEntry 0262 * @throws Zend_Gdata_App_Exception 0263 * @throws Zend_Gdata_App_HttpException 0264 */ 0265 public function getAlbumEntry($location) 0266 { 0267 if ($location === null) { 0268 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0269 throw new Zend_Gdata_App_InvalidArgumentException( 0270 'Location must not be null'); 0271 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0272 $location->setType('entry'); 0273 $uri = $location->getQueryUrl(); 0274 } else if ($location instanceof Zend_Gdata_Query) { 0275 $uri = $location->getQueryUrl(); 0276 } else { 0277 $uri = $location; 0278 } 0279 return parent::getEntry($uri, 'Zend_Gdata_Photos_AlbumEntry'); 0280 } 0281 0282 /** 0283 * Retreive a single PhotoEntry object. 0284 * 0285 * @param mixed $location The location for the feed, as a URL or Query. 0286 * @return Zend_Gdata_Photos_PhotoEntry 0287 * @throws Zend_Gdata_App_Exception 0288 * @throws Zend_Gdata_App_HttpException 0289 */ 0290 public function getPhotoEntry($location) 0291 { 0292 if ($location === null) { 0293 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0294 throw new Zend_Gdata_App_InvalidArgumentException( 0295 'Location must not be null'); 0296 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0297 $location->setType('entry'); 0298 $uri = $location->getQueryUrl(); 0299 } else if ($location instanceof Zend_Gdata_Query) { 0300 $uri = $location->getQueryUrl(); 0301 } else { 0302 $uri = $location; 0303 } 0304 return parent::getEntry($uri, 'Zend_Gdata_Photos_PhotoEntry'); 0305 } 0306 0307 /** 0308 * Retreive a single TagEntry object. 0309 * 0310 * @param mixed $location The location for the feed, as a URL or Query. 0311 * @return Zend_Gdata_Photos_TagEntry 0312 * @throws Zend_Gdata_App_Exception 0313 * @throws Zend_Gdata_App_HttpException 0314 */ 0315 public function getTagEntry($location) 0316 { 0317 if ($location === null) { 0318 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0319 throw new Zend_Gdata_App_InvalidArgumentException( 0320 'Location must not be null'); 0321 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0322 $location->setType('entry'); 0323 $uri = $location->getQueryUrl(); 0324 } else if ($location instanceof Zend_Gdata_Query) { 0325 $uri = $location->getQueryUrl(); 0326 } else { 0327 $uri = $location; 0328 } 0329 return parent::getEntry($uri, 'Zend_Gdata_Photos_TagEntry'); 0330 } 0331 0332 /** 0333 * Retreive a single CommentEntry object. 0334 * 0335 * @param mixed $location The location for the feed, as a URL or Query. 0336 * @return Zend_Gdata_Photos_CommentEntry 0337 * @throws Zend_Gdata_App_Exception 0338 * @throws Zend_Gdata_App_HttpException 0339 */ 0340 public function getCommentEntry($location) 0341 { 0342 if ($location === null) { 0343 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0344 throw new Zend_Gdata_App_InvalidArgumentException( 0345 'Location must not be null'); 0346 } else if ($location instanceof Zend_Gdata_Photos_UserQuery) { 0347 $location->setType('entry'); 0348 $uri = $location->getQueryUrl(); 0349 } else if ($location instanceof Zend_Gdata_Query) { 0350 $uri = $location->getQueryUrl(); 0351 } else { 0352 $uri = $location; 0353 } 0354 return parent::getEntry($uri, 'Zend_Gdata_Photos_CommentEntry'); 0355 } 0356 0357 /** 0358 * Create a new album from a AlbumEntry. 0359 * 0360 * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to 0361 * insert. 0362 * @param string $url (optional) The URI that the album should be 0363 * uploaded to. If null, the default album creation URI for 0364 * this domain will be used. 0365 * @return Zend_Gdata_Photos_AlbumEntry The inserted album entry as 0366 * returned by the server. 0367 * @throws Zend_Gdata_App_Exception 0368 * @throws Zend_Gdata_App_HttpException 0369 */ 0370 public function insertAlbumEntry($album, $uri = null) 0371 { 0372 if ($uri === null) { 0373 $uri = self::PICASA_BASE_FEED_URI . '/' . 0374 self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' . 0375 self::DEFAULT_USER; 0376 } 0377 $newEntry = $this->insertEntry($album, $uri, 'Zend_Gdata_Photos_AlbumEntry'); 0378 return $newEntry; 0379 } 0380 0381 /** 0382 * Create a new photo from a PhotoEntry. 0383 * 0384 * @param Zend_Gdata_Photos_PhotoEntry $photo The photo to insert. 0385 * @param string $url The URI that the photo should be uploaded 0386 * to. Alternatively, an AlbumEntry can be provided and the 0387 * photo will be added to that album. 0388 * @return Zend_Gdata_Photos_PhotoEntry The inserted photo entry 0389 * as returned by the server. 0390 * @throws Zend_Gdata_App_Exception 0391 * @throws Zend_Gdata_App_HttpException 0392 */ 0393 public function insertPhotoEntry($photo, $uri = null) 0394 { 0395 if ($uri instanceof Zend_Gdata_Photos_AlbumEntry) { 0396 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 0397 } 0398 if ($uri === null) { 0399 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0400 throw new Zend_Gdata_App_InvalidArgumentException( 0401 'URI must not be null'); 0402 } 0403 $newEntry = $this->insertEntry($photo, $uri, 'Zend_Gdata_Photos_PhotoEntry'); 0404 return $newEntry; 0405 } 0406 0407 /** 0408 * Create a new tag from a TagEntry. 0409 * 0410 * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to insert. 0411 * @param string $url The URI where the tag should be 0412 * uploaded to. Alternatively, a PhotoEntry can be provided and 0413 * the tag will be added to that photo. 0414 * @return Zend_Gdata_Photos_TagEntry The inserted tag entry as returned 0415 * by the server. 0416 * @throws Zend_Gdata_App_Exception 0417 * @throws Zend_Gdata_App_HttpException 0418 */ 0419 public function insertTagEntry($tag, $uri = null) 0420 { 0421 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) { 0422 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 0423 } 0424 if ($uri === null) { 0425 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0426 throw new Zend_Gdata_App_InvalidArgumentException( 0427 'URI must not be null'); 0428 } 0429 $newEntry = $this->insertEntry($tag, $uri, 'Zend_Gdata_Photos_TagEntry'); 0430 return $newEntry; 0431 } 0432 0433 /** 0434 * Create a new comment from a CommentEntry. 0435 * 0436 * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to 0437 * insert. 0438 * @param string $url The URI where the comment should be uploaded to. 0439 * Alternatively, a PhotoEntry can be provided and 0440 * the comment will be added to that photo. 0441 * @return Zend_Gdata_Photos_CommentEntry The inserted comment entry 0442 * as returned by the server. 0443 * @throws Zend_Gdata_App_Exception 0444 * @throws Zend_Gdata_App_HttpException 0445 */ 0446 public function insertCommentEntry($comment, $uri = null) 0447 { 0448 if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) { 0449 $uri = $uri->getLink(self::FEED_LINK_PATH)->href; 0450 } 0451 if ($uri === null) { 0452 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0453 throw new Zend_Gdata_App_InvalidArgumentException( 0454 'URI must not be null'); 0455 } 0456 $newEntry = $this->insertEntry($comment, $uri, 'Zend_Gdata_Photos_CommentEntry'); 0457 return $newEntry; 0458 } 0459 0460 /** 0461 * Delete an AlbumEntry. 0462 * 0463 * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to 0464 * delete. 0465 * @param boolean $catch Whether to catch an exception when 0466 * modified and re-delete or throw 0467 * @return void. 0468 * @throws Zend_Gdata_App_Exception 0469 * @throws Zend_Gdata_App_HttpException 0470 */ 0471 public function deleteAlbumEntry($album, $catch) 0472 { 0473 if ($catch) { 0474 try { 0475 $this->delete($album); 0476 } catch (Zend_Gdata_App_HttpException $e) { 0477 if ($e->getResponse()->getStatus() === 409) { 0478 $entry = new Zend_Gdata_Photos_AlbumEntry($e->getResponse()->getBody()); 0479 $this->delete($entry->getLink('edit')->href); 0480 } else { 0481 throw $e; 0482 } 0483 } 0484 } else { 0485 $this->delete($album); 0486 } 0487 } 0488 0489 /** 0490 * Delete a PhotoEntry. 0491 * 0492 * @param Zend_Gdata_Photos_PhotoEntry $photo The photo entry to 0493 * delete. 0494 * @param boolean $catch Whether to catch an exception when 0495 * modified and re-delete or throw 0496 * @return void. 0497 * @throws Zend_Gdata_App_Exception 0498 * @throws Zend_Gdata_App_HttpException 0499 */ 0500 public function deletePhotoEntry($photo, $catch) 0501 { 0502 if ($catch) { 0503 try { 0504 $this->delete($photo); 0505 } catch (Zend_Gdata_App_HttpException $e) { 0506 if ($e->getResponse()->getStatus() === 409) { 0507 $entry = new Zend_Gdata_Photos_PhotoEntry($e->getResponse()->getBody()); 0508 $this->delete($entry->getLink('edit')->href); 0509 } else { 0510 throw $e; 0511 } 0512 } 0513 } else { 0514 $this->delete($photo); 0515 } 0516 } 0517 0518 /** 0519 * Delete a CommentEntry. 0520 * 0521 * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to 0522 * delete. 0523 * @param boolean $catch Whether to catch an exception when 0524 * modified and re-delete or throw 0525 * @return void. 0526 * @throws Zend_Gdata_App_Exception 0527 * @throws Zend_Gdata_App_HttpException 0528 */ 0529 public function deleteCommentEntry($comment, $catch) 0530 { 0531 if ($catch) { 0532 try { 0533 $this->delete($comment); 0534 } catch (Zend_Gdata_App_HttpException $e) { 0535 if ($e->getResponse()->getStatus() === 409) { 0536 $entry = new Zend_Gdata_Photos_CommentEntry($e->getResponse()->getBody()); 0537 $this->delete($entry->getLink('edit')->href); 0538 } else { 0539 throw $e; 0540 } 0541 } 0542 } else { 0543 $this->delete($comment); 0544 } 0545 } 0546 0547 /** 0548 * Delete a TagEntry. 0549 * 0550 * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to 0551 * delete. 0552 * @param boolean $catch Whether to catch an exception when 0553 * modified and re-delete or throw 0554 * @return void. 0555 * @throws Zend_Gdata_App_Exception 0556 * @throws Zend_Gdata_App_HttpException 0557 */ 0558 public function deleteTagEntry($tag, $catch) 0559 { 0560 if ($catch) { 0561 try { 0562 $this->delete($tag); 0563 } catch (Zend_Gdata_App_HttpException $e) { 0564 if ($e->getResponse()->getStatus() === 409) { 0565 $entry = new Zend_Gdata_Photos_TagEntry($e->getResponse()->getBody()); 0566 $this->delete($entry->getLink('edit')->href); 0567 } else { 0568 throw $e; 0569 } 0570 } 0571 } else { 0572 $this->delete($tag); 0573 } 0574 } 0575 0576 }