PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/library/Zend/Gdata/Photos.php

http://firephp.googlecode.com/
PHP | 575 lines | 290 code | 36 blank | 249 comment | 75 complexity | 4fda1e54473bda724f1e492167e8d104 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Photos
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata
  23. */
  24. require_once 'Zend/Gdata.php';
  25. /**
  26. * @see Zend_Gdata_Photos_UserFeed
  27. */
  28. require_once 'Zend/Gdata/Photos/UserFeed.php';
  29. /**
  30. * @see Zend_Gdata_Photos_AlbumFeed
  31. */
  32. require_once 'Zend/Gdata/Photos/AlbumFeed.php';
  33. /**
  34. * @see Zend_Gdata_Photos_PhotoFeed
  35. */
  36. require_once 'Zend/Gdata/Photos/PhotoFeed.php';
  37. /**
  38. * Service class for interacting with the Google Photos Data API.
  39. *
  40. * Like other service classes in this module, this class provides access via
  41. * an HTTP client to Google servers for working with entries and feeds.
  42. *
  43. * @link http://code.google.com/apis/picasaweb/gdata.html
  44. *
  45. * @category Zend
  46. * @package Zend_Gdata
  47. * @subpackage Photos
  48. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  49. * @license http://framework.zend.com/license/new-bsd New BSD License
  50. */
  51. class Zend_Gdata_Photos extends Zend_Gdata
  52. {
  53. const PICASA_BASE_URI = 'http://picasaweb.google.com/data';
  54. const PICASA_BASE_FEED_URI = 'http://picasaweb.google.com/data/feed';
  55. const AUTH_SERVICE_NAME = 'lh2';
  56. /**
  57. * Default projection when interacting with the Picasa server.
  58. */
  59. const DEFAULT_PROJECTION = 'api';
  60. /**
  61. * The default visibility to filter events by.
  62. */
  63. const DEFAULT_VISIBILITY = 'all';
  64. /**
  65. * The default user to retrieve feeds for.
  66. */
  67. const DEFAULT_USER = 'default';
  68. /**
  69. * Path to the user feed on the Picasa server.
  70. */
  71. const USER_PATH = 'user';
  72. /**
  73. * Path to album feeds on the Picasa server.
  74. */
  75. const ALBUM_PATH = 'albumid';
  76. /**
  77. * Path to photo feeds on the Picasa server.
  78. */
  79. const PHOTO_PATH = 'photoid';
  80. /**
  81. * The path to the community search feed on the Picasa server.
  82. */
  83. const COMMUNITY_SEARCH_PATH = 'all';
  84. /**
  85. * The path to use for finding links to feeds within entries
  86. */
  87. const FEED_LINK_PATH = 'http://schemas.google.com/g/2005#feed';
  88. /**
  89. * The path to use for the determining type of an entry
  90. */
  91. const KIND_PATH = 'http://schemas.google.com/g/2005#kind';
  92. /**
  93. * Namespaces used for Zend_Gdata_Photos
  94. *
  95. * @var array
  96. */
  97. public static $namespaces = array(
  98. array('gphoto', 'http://schemas.google.com/photos/2007', 1, 0),
  99. array('photo', 'http://www.pheed.com/pheed/', 1, 0),
  100. array('exif', 'http://schemas.google.com/photos/exif/2007', 1, 0),
  101. array('georss', 'http://www.georss.org/georss', 1, 0),
  102. array('gml', 'http://www.opengis.net/gml', 1, 0),
  103. array('media', 'http://search.yahoo.com/mrss/', 1, 0)
  104. );
  105. /**
  106. * Create Zend_Gdata_Photos object
  107. *
  108. * @param Zend_Http_Client $client (optional) The HTTP client to use when
  109. * when communicating with the servers.
  110. * @param string $applicationId The identity of the app in the form of Company-AppName-Version
  111. */
  112. public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
  113. {
  114. $this->registerPackage('Zend_Gdata_Photos');
  115. $this->registerPackage('Zend_Gdata_Photos_Extension');
  116. parent::__construct($client, $applicationId);
  117. $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
  118. }
  119. /**
  120. * Retrieve a UserFeed containing AlbumEntries, PhotoEntries and
  121. * TagEntries associated with a given user.
  122. *
  123. * @param string $userName The userName of interest
  124. * @param mixed $location (optional) The location for the feed, as a URL
  125. * or Query. If not provided, a default URL will be used instead.
  126. * @return Zend_Gdata_Photos_UserFeed
  127. * @throws Zend_Gdata_App_Exception
  128. * @throws Zend_Gdata_App_HttpException
  129. */
  130. public function getUserFeed($userName = null, $location = null)
  131. {
  132. if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  133. $location->setType('feed');
  134. if ($userName !== null) {
  135. $location->setUser($userName);
  136. }
  137. $uri = $location->getQueryUrl();
  138. } else if ($location instanceof Zend_Gdata_Query) {
  139. if ($userName !== null) {
  140. $location->setUser($userName);
  141. }
  142. $uri = $location->getQueryUrl();
  143. } else if ($location !== null) {
  144. $uri = $location;
  145. } else if ($userName !== null) {
  146. $uri = self::PICASA_BASE_FEED_URI . '/' .
  147. self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
  148. $userName;
  149. } else {
  150. $uri = self::PICASA_BASE_FEED_URI . '/' .
  151. self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
  152. self::DEFAULT_USER;
  153. }
  154. return parent::getFeed($uri, 'Zend_Gdata_Photos_UserFeed');
  155. }
  156. /**
  157. * Retreive AlbumFeed object containing multiple PhotoEntry or TagEntry
  158. * objects.
  159. *
  160. * @param mixed $location (optional) The location for the feed, as a URL or Query.
  161. * @return Zend_Gdata_Photos_AlbumFeed
  162. * @throws Zend_Gdata_App_Exception
  163. * @throws Zend_Gdata_App_HttpException
  164. */
  165. public function getAlbumFeed($location = null)
  166. {
  167. if ($location === null) {
  168. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  169. throw new Zend_Gdata_App_InvalidArgumentException(
  170. 'Location must not be null');
  171. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  172. $location->setType('feed');
  173. $uri = $location->getQueryUrl();
  174. } else if ($location instanceof Zend_Gdata_Query) {
  175. $uri = $location->getQueryUrl();
  176. } else {
  177. $uri = $location;
  178. }
  179. return parent::getFeed($uri, 'Zend_Gdata_Photos_AlbumFeed');
  180. }
  181. /**
  182. * Retreive PhotoFeed object containing comments and tags associated
  183. * with a given photo.
  184. *
  185. * @param mixed $location (optional) The location for the feed, as a URL
  186. * or Query. If not specified, the community search feed will
  187. * be returned instead.
  188. * @return Zend_Gdata_Photos_PhotoFeed
  189. * @throws Zend_Gdata_App_Exception
  190. * @throws Zend_Gdata_App_HttpException
  191. */
  192. public function getPhotoFeed($location = null)
  193. {
  194. if ($location === null) {
  195. $uri = self::PICASA_BASE_FEED_URI . '/' .
  196. self::DEFAULT_PROJECTION . '/' .
  197. self::COMMUNITY_SEARCH_PATH;
  198. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  199. $location->setType('feed');
  200. $uri = $location->getQueryUrl();
  201. } else if ($location instanceof Zend_Gdata_Query) {
  202. $uri = $location->getQueryUrl();
  203. } else {
  204. $uri = $location;
  205. }
  206. return parent::getFeed($uri, 'Zend_Gdata_Photos_PhotoFeed');
  207. }
  208. /**
  209. * Retreive a single UserEntry object.
  210. *
  211. * @param mixed $location The location for the feed, as a URL or Query.
  212. * @return Zend_Gdata_Photos_UserEntry
  213. * @throws Zend_Gdata_App_Exception
  214. * @throws Zend_Gdata_App_HttpException
  215. */
  216. public function getUserEntry($location)
  217. {
  218. if ($location === null) {
  219. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  220. throw new Zend_Gdata_App_InvalidArgumentException(
  221. 'Location must not be null');
  222. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  223. $location->setType('entry');
  224. $uri = $location->getQueryUrl();
  225. } else if ($location instanceof Zend_Gdata_Query) {
  226. $uri = $location->getQueryUrl();
  227. } else {
  228. $uri = $location;
  229. }
  230. return parent::getEntry($uri, 'Zend_Gdata_Photos_UserEntry');
  231. }
  232. /**
  233. * Retreive a single AlbumEntry object.
  234. *
  235. * @param mixed $location The location for the feed, as a URL or Query.
  236. * @return Zend_Gdata_Photos_AlbumEntry
  237. * @throws Zend_Gdata_App_Exception
  238. * @throws Zend_Gdata_App_HttpException
  239. */
  240. public function getAlbumEntry($location)
  241. {
  242. if ($location === null) {
  243. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  244. throw new Zend_Gdata_App_InvalidArgumentException(
  245. 'Location must not be null');
  246. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  247. $location->setType('entry');
  248. $uri = $location->getQueryUrl();
  249. } else if ($location instanceof Zend_Gdata_Query) {
  250. $uri = $location->getQueryUrl();
  251. } else {
  252. $uri = $location;
  253. }
  254. return parent::getEntry($uri, 'Zend_Gdata_Photos_AlbumEntry');
  255. }
  256. /**
  257. * Retreive a single PhotoEntry object.
  258. *
  259. * @param mixed $location The location for the feed, as a URL or Query.
  260. * @return Zend_Gdata_Photos_PhotoEntry
  261. * @throws Zend_Gdata_App_Exception
  262. * @throws Zend_Gdata_App_HttpException
  263. */
  264. public function getPhotoEntry($location)
  265. {
  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();
  275. } else {
  276. $uri = $location;
  277. }
  278. return parent::getEntry($uri, 'Zend_Gdata_Photos_PhotoEntry');
  279. }
  280. /**
  281. * Retreive a single TagEntry object.
  282. *
  283. * @param mixed $location The location for the feed, as a URL or Query.
  284. * @return Zend_Gdata_Photos_TagEntry
  285. * @throws Zend_Gdata_App_Exception
  286. * @throws Zend_Gdata_App_HttpException
  287. */
  288. public function getTagEntry($location)
  289. {
  290. if ($location === null) {
  291. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  292. throw new Zend_Gdata_App_InvalidArgumentException(
  293. 'Location must not be null');
  294. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  295. $location->setType('entry');
  296. $uri = $location->getQueryUrl();
  297. } else if ($location instanceof Zend_Gdata_Query) {
  298. $uri = $location->getQueryUrl();
  299. } else {
  300. $uri = $location;
  301. }
  302. return parent::getEntry($uri, 'Zend_Gdata_Photos_TagEntry');
  303. }
  304. /**
  305. * Retreive a single CommentEntry object.
  306. *
  307. * @param mixed $location The location for the feed, as a URL or Query.
  308. * @return Zend_Gdata_Photos_CommentEntry
  309. * @throws Zend_Gdata_App_Exception
  310. * @throws Zend_Gdata_App_HttpException
  311. */
  312. public function getCommentEntry($location)
  313. {
  314. if ($location === null) {
  315. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  316. throw new Zend_Gdata_App_InvalidArgumentException(
  317. 'Location must not be null');
  318. } else if ($location instanceof Zend_Gdata_Photos_UserQuery) {
  319. $location->setType('entry');
  320. $uri = $location->getQueryUrl();
  321. } else if ($location instanceof Zend_Gdata_Query) {
  322. $uri = $location->getQueryUrl();
  323. } else {
  324. $uri = $location;
  325. }
  326. return parent::getEntry($uri, 'Zend_Gdata_Photos_CommentEntry');
  327. }
  328. /**
  329. * Create a new album from a AlbumEntry.
  330. *
  331. * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
  332. * insert.
  333. * @param string $url (optional) The URI that the album should be
  334. * uploaded to. If null, the default album creation URI for
  335. * this domain will be used.
  336. * @return Zend_Gdata_Photos_AlbumEntry The inserted album entry as
  337. * returned by the server.
  338. * @throws Zend_Gdata_App_Exception
  339. * @throws Zend_Gdata_App_HttpException
  340. */
  341. public function insertAlbumEntry($album, $uri = null)
  342. {
  343. if ($uri === null) {
  344. $uri = self::PICASA_BASE_FEED_URI . '/' .
  345. self::DEFAULT_PROJECTION . '/' . self::USER_PATH . '/' .
  346. self::DEFAULT_USER;
  347. }
  348. $newEntry = $this->insertEntry($album, $uri, 'Zend_Gdata_Photos_AlbumEntry');
  349. return $newEntry;
  350. }
  351. /**
  352. * Create a new photo from a PhotoEntry.
  353. *
  354. * @param Zend_Gdata_Photos_PhotoEntry $photo The photo to insert.
  355. * @param string $url The URI that the photo should be uploaded
  356. * to. Alternatively, an AlbumEntry can be provided and the
  357. * photo will be added to that album.
  358. * @return Zend_Gdata_Photos_PhotoEntry The inserted photo entry
  359. * as returned by the server.
  360. * @throws Zend_Gdata_App_Exception
  361. * @throws Zend_Gdata_App_HttpException
  362. */
  363. public function insertPhotoEntry($photo, $uri = null)
  364. {
  365. if ($uri instanceof Zend_Gdata_Photos_AlbumEntry) {
  366. $uri = $uri->getLink(self::FEED_LINK_PATH)->href;
  367. }
  368. if ($uri === null) {
  369. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  370. throw new Zend_Gdata_App_InvalidArgumentException(
  371. 'URI must not be null');
  372. }
  373. $newEntry = $this->insertEntry($photo, $uri, 'Zend_Gdata_Photos_PhotoEntry');
  374. return $newEntry;
  375. }
  376. /**
  377. * Create a new tag from a TagEntry.
  378. *
  379. * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to insert.
  380. * @param string $url The URI where the tag should be
  381. * uploaded to. Alternatively, a PhotoEntry can be provided and
  382. * the tag will be added to that photo.
  383. * @return Zend_Gdata_Photos_TagEntry The inserted tag entry as returned
  384. * by the server.
  385. * @throws Zend_Gdata_App_Exception
  386. * @throws Zend_Gdata_App_HttpException
  387. */
  388. public function insertTagEntry($tag, $uri = null)
  389. {
  390. if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) {
  391. $uri = $uri->getLink(self::FEED_LINK_PATH)->href;
  392. }
  393. if ($uri === null) {
  394. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  395. throw new Zend_Gdata_App_InvalidArgumentException(
  396. 'URI must not be null');
  397. }
  398. $newEntry = $this->insertEntry($tag, $uri, 'Zend_Gdata_Photos_TagEntry');
  399. return $newEntry;
  400. }
  401. /**
  402. * Create a new comment from a CommentEntry.
  403. *
  404. * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
  405. * insert.
  406. * @param string $url The URI where the comment should be uploaded to.
  407. * Alternatively, a PhotoEntry can be provided and
  408. * the comment will be added to that photo.
  409. * @return Zend_Gdata_Photos_CommentEntry The inserted comment entry
  410. * as returned by the server.
  411. * @throws Zend_Gdata_App_Exception
  412. * @throws Zend_Gdata_App_HttpException
  413. */
  414. public function insertCommentEntry($comment, $uri = null)
  415. {
  416. if ($uri instanceof Zend_Gdata_Photos_PhotoEntry) {
  417. $uri = $uri->getLink(self::FEED_LINK_PATH)->href;
  418. }
  419. if ($uri === null) {
  420. require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  421. throw new Zend_Gdata_App_InvalidArgumentException(
  422. 'URI must not be null');
  423. }
  424. $newEntry = $this->insertEntry($comment, $uri, 'Zend_Gdata_Photos_CommentEntry');
  425. return $newEntry;
  426. }
  427. /**
  428. * Delete an AlbumEntry.
  429. *
  430. * @param Zend_Gdata_Photos_AlbumEntry $album The album entry to
  431. * delete.
  432. * @param boolean $catch Whether to catch an exception when
  433. * modified and re-delete or throw
  434. * @return void.
  435. * @throws Zend_Gdata_App_Exception
  436. * @throws Zend_Gdata_App_HttpException
  437. */
  438. public function deleteAlbumEntry($album, $catch)
  439. {
  440. if ($catch) {
  441. try {
  442. $this->delete($album);
  443. } catch (Zend_Gdata_App_HttpException $e) {
  444. if ($e->getResponse()->getStatus() === 409) {
  445. $entry = new Zend_Gdata_Photos_AlbumEntry($e->getResponse()->getBody());
  446. $this->delete($entry->getLink('edit')->href);
  447. } else {
  448. throw $e;
  449. }
  450. }
  451. } else {
  452. $this->delete($album);
  453. }
  454. }
  455. /**
  456. * Delete a PhotoEntry.
  457. *
  458. * @param Zend_Gdata_Photos_PhotoEntry $photo The photo entry to
  459. * delete.
  460. * @param boolean $catch Whether to catch an exception when
  461. * modified and re-delete or throw
  462. * @return void.
  463. * @throws Zend_Gdata_App_Exception
  464. * @throws Zend_Gdata_App_HttpException
  465. */
  466. public function deletePhotoEntry($photo, $catch)
  467. {
  468. if ($catch) {
  469. try {
  470. $this->delete($photo);
  471. } catch (Zend_Gdata_App_HttpException $e) {
  472. if ($e->getResponse()->getStatus() === 409) {
  473. $entry = new Zend_Gdata_Photos_PhotoEntry($e->getResponse()->getBody());
  474. $this->delete($entry->getLink('edit')->href);
  475. } else {
  476. throw $e;
  477. }
  478. }
  479. } else {
  480. $this->delete($photo);
  481. }
  482. }
  483. /**
  484. * Delete a CommentEntry.
  485. *
  486. * @param Zend_Gdata_Photos_CommentEntry $comment The comment entry to
  487. * delete.
  488. * @param boolean $catch Whether to catch an exception when
  489. * modified and re-delete or throw
  490. * @return void.
  491. * @throws Zend_Gdata_App_Exception
  492. * @throws Zend_Gdata_App_HttpException
  493. */
  494. public function deleteCommentEntry($comment, $catch)
  495. {
  496. if ($catch) {
  497. try {
  498. $this->delete($comment);
  499. } catch (Zend_Gdata_App_HttpException $e) {
  500. if ($e->getResponse()->getStatus() === 409) {
  501. $entry = new Zend_Gdata_Photos_CommentEntry($e->getResponse()->getBody());
  502. $this->delete($entry->getLink('edit')->href);
  503. } else {
  504. throw $e;
  505. }
  506. }
  507. } else {
  508. $this->delete($comment);
  509. }
  510. }
  511. /**
  512. * Delete a TagEntry.
  513. *
  514. * @param Zend_Gdata_Photos_TagEntry $tag The tag entry to
  515. * delete.
  516. * @param boolean $catch Whether to catch an exception when
  517. * modified and re-delete or throw
  518. * @return void.
  519. * @throws Zend_Gdata_App_Exception
  520. * @throws Zend_Gdata_App_HttpException
  521. */
  522. public function deleteTagEntry($tag, $catch)
  523. {
  524. if ($catch) {
  525. try {
  526. $this->delete($tag);
  527. } catch (Zend_Gdata_App_HttpException $e) {
  528. if ($e->getResponse()->getStatus() === 409) {
  529. $entry = new Zend_Gdata_Photos_TagEntry($e->getResponse()->getBody());
  530. $this->delete($entry->getLink('edit')->href);
  531. } else {
  532. throw $e;
  533. }
  534. }
  535. } else {
  536. $this->delete($tag);
  537. }
  538. }
  539. }