PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/demos/Zend/Gdata/Photos.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 904 lines | 569 code | 95 blank | 240 comment | 44 complexity | 72041f6e983ec34f902506c7e6440dc2 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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 Demos
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * PHP sample code for the Photos data API. Utilizes the
  23. * Zend Framework Gdata components to communicate with the Google API.
  24. *
  25. * Requires the Zend Framework Gdata components and PHP >= 5.2.11
  26. *
  27. * You can run this sample from a web browser.
  28. *
  29. * NOTE: You must ensure that Zend Framework is in your PHP include
  30. * path. You can do this via php.ini settings, or by modifying the
  31. * argument to set_include_path in the code below.
  32. *
  33. * NOTE: As this is sample code, not all of the functions do full error
  34. * handling.
  35. */
  36. /**
  37. * @see Zend_Loader
  38. */
  39. require_once 'Zend/Loader.php';
  40. /**
  41. * @see Zend_Gdata
  42. */
  43. Zend_Loader::loadClass('Zend_Gdata');
  44. /**
  45. * @see Zend_Gdata_AuthSub
  46. */
  47. Zend_Loader::loadClass('Zend_Gdata_AuthSub');
  48. /**
  49. * @see Zend_Gdata_Photos
  50. */
  51. Zend_Loader::loadClass('Zend_Gdata_Photos');
  52. /**
  53. * @see Zend_Gdata_Photos_UserQuery
  54. */
  55. Zend_Loader::loadClass('Zend_Gdata_Photos_UserQuery');
  56. /**
  57. * @see Zend_Gdata_Photos_AlbumQuery
  58. */
  59. Zend_Loader::loadClass('Zend_Gdata_Photos_AlbumQuery');
  60. /**
  61. * @see Zend_Gdata_Photos_PhotoQuery
  62. */
  63. Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoQuery');
  64. /**
  65. * @see Zend_Gdata_App_Extension_Category
  66. */
  67. Zend_Loader::loadClass('Zend_Gdata_App_Extension_Category');
  68. session_start();
  69. /**
  70. * Adds a new photo to the specified album
  71. *
  72. * @param Zend_Http_Client $client The authenticated client
  73. * @param string $user The user's account name
  74. * @param integer $albumId The album's id
  75. * @param array $photo The uploaded photo
  76. * @return void
  77. */
  78. function addPhoto($client, $user, $albumId, $photo)
  79. {
  80. $photos = new Zend_Gdata_Photos($client);
  81. $fd = $photos->newMediaFileSource($photo["tmp_name"]);
  82. $fd->setContentType($photo["type"]);
  83. $entry = new Zend_Gdata_Photos_PhotoEntry();
  84. $entry->setMediaSource($fd);
  85. $entry->setTitle($photos->newTitle($photo["name"]));
  86. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  87. $albumQuery->setUser($user);
  88. $albumQuery->setAlbumId($albumId);
  89. $albumEntry = $photos->getAlbumEntry($albumQuery);
  90. $result = $photos->insertPhotoEntry($entry, $albumEntry);
  91. if ($result) {
  92. outputAlbumFeed($client, $user, $albumId);
  93. } else {
  94. echo "There was an issue with the file upload.";
  95. }
  96. }
  97. /**
  98. * Deletes the specified photo
  99. *
  100. * @param Zend_Http_Client $client The authenticated client
  101. * @param string $user The user's account name
  102. * @param integer $albumId The album's id
  103. * @param integer $photoId The photo's id
  104. * @return void
  105. */
  106. function deletePhoto($client, $user, $albumId, $photoId)
  107. {
  108. $photos = new Zend_Gdata_Photos($client);
  109. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  110. $photoQuery->setUser($user);
  111. $photoQuery->setAlbumId($albumId);
  112. $photoQuery->setPhotoId($photoId);
  113. $photoQuery->setType('entry');
  114. $entry = $photos->getPhotoEntry($photoQuery);
  115. $photos->deletePhotoEntry($entry, true);
  116. outputAlbumFeed($client, $user, $albumId);
  117. }
  118. /**
  119. * Adds a new album to the specified user's album
  120. *
  121. * @param Zend_Http_Client $client The authenticated client
  122. * @param string $user The user's account name
  123. * @param string $name The name of the new album
  124. * @return void
  125. */
  126. function addAlbum($client, $user, $name)
  127. {
  128. $photos = new Zend_Gdata_Photos($client);
  129. $entry = new Zend_Gdata_Photos_AlbumEntry();
  130. $entry->setTitle($photos->newTitle($name));
  131. $result = $photos->insertAlbumEntry($entry);
  132. if ($result) {
  133. outputUserFeed($client, $user);
  134. } else {
  135. echo "There was an issue with the album creation.";
  136. }
  137. }
  138. /**
  139. * Deletes the specified album
  140. *
  141. * @param Zend_Http_Client $client The authenticated client
  142. * @param string $user The user's account name
  143. * @param integer $albumId The album's id
  144. * @return void
  145. */
  146. function deleteAlbum($client, $user, $albumId)
  147. {
  148. $photos = new Zend_Gdata_Photos($client);
  149. $albumQuery = new Zend_Gdata_Photos_AlbumQuery;
  150. $albumQuery->setUser($user);
  151. $albumQuery->setAlbumId($albumId);
  152. $albumQuery->setType('entry');
  153. $entry = $photos->getAlbumEntry($albumQuery);
  154. $photos->deleteAlbumEntry($entry, true);
  155. outputUserFeed($client, $user);
  156. }
  157. /**
  158. * Adds a new comment to the specified photo
  159. *
  160. * @param Zend_Http_Client $client The authenticated client
  161. * @param string $user The user's account name
  162. * @param integer $albumId The album's id
  163. * @param integer $photoId The photo's id
  164. * @param string $comment The comment to add
  165. * @return void
  166. */
  167. function addComment($client, $user, $album, $photo, $comment)
  168. {
  169. $photos = new Zend_Gdata_Photos($client);
  170. $entry = new Zend_Gdata_Photos_CommentEntry();
  171. $entry->setTitle($photos->newTitle($comment));
  172. $entry->setContent($photos->newContent($comment));
  173. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  174. $photoQuery->setUser($user);
  175. $photoQuery->setAlbumId($album);
  176. $photoQuery->setPhotoId($photo);
  177. $photoQuery->setType('entry');
  178. $photoEntry = $photos->getPhotoEntry($photoQuery);
  179. $result = $photos->insertCommentEntry($entry, $photoEntry);
  180. if ($result) {
  181. outputPhotoFeed($client, $user, $album, $photo);
  182. } else {
  183. echo "There was an issue with the comment creation.";
  184. }
  185. }
  186. /**
  187. * Deletes the specified comment
  188. *
  189. * @param Zend_Http_Client $client The authenticated client
  190. * @param string $user The user's account name
  191. * @param integer $albumId The album's id
  192. * @param integer $photoId The photo's id
  193. * @param integer $commentId The comment's id
  194. * @return void
  195. */
  196. function deleteComment($client, $user, $albumId, $photoId, $commentId)
  197. {
  198. $photos = new Zend_Gdata_Photos($client);
  199. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  200. $photoQuery->setUser($user);
  201. $photoQuery->setAlbumId($albumId);
  202. $photoQuery->setPhotoId($photoId);
  203. $photoQuery->setType('entry');
  204. $path = $photoQuery->getQueryUrl() . '/commentid/' . $commentId;
  205. $entry = $photos->getCommentEntry($path);
  206. $photos->deleteCommentEntry($entry, true);
  207. outputPhotoFeed($client, $user, $albumId, $photoId);
  208. }
  209. /**
  210. * Adds a new tag to the specified photo
  211. *
  212. * @param Zend_Http_Client $client The authenticated client
  213. * @param string $user The user's account name
  214. * @param integer $album The album's id
  215. * @param integer $photo The photo's id
  216. * @param string $tag The tag to add to the photo
  217. * @return void
  218. */
  219. function addTag($client, $user, $album, $photo, $tag)
  220. {
  221. $photos = new Zend_Gdata_Photos($client);
  222. $entry = new Zend_Gdata_Photos_TagEntry();
  223. $entry->setTitle($photos->newTitle($tag));
  224. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  225. $photoQuery->setUser($user);
  226. $photoQuery->setAlbumId($album);
  227. $photoQuery->setPhotoId($photo);
  228. $photoQuery->setType('entry');
  229. $photoEntry = $photos->getPhotoEntry($photoQuery);
  230. $result = $photos->insertTagEntry($entry, $photoEntry);
  231. if ($result) {
  232. outputPhotoFeed($client, $user, $album, $photo);
  233. } else {
  234. echo "There was an issue with the tag creation.";
  235. }
  236. }
  237. /**
  238. * Deletes the specified tag
  239. *
  240. * @param Zend_Http_Client $client The authenticated client
  241. * @param string $user The user's account name
  242. * @param integer $albumId The album's id
  243. * @param integer $photoId The photo's id
  244. * @param string $tagContent The name of the tag to be deleted
  245. * @return void
  246. */
  247. function deleteTag($client, $user, $albumId, $photoId, $tagContent)
  248. {
  249. $photos = new Zend_Gdata_Photos($client);
  250. $photoQuery = new Zend_Gdata_Photos_PhotoQuery;
  251. $photoQuery->setUser($user);
  252. $photoQuery->setAlbumId($albumId);
  253. $photoQuery->setPhotoId($photoId);
  254. $query = $photoQuery->getQueryUrl() . "?kind=tag";
  255. $photoFeed = $photos->getPhotoFeed($query);
  256. foreach ($photoFeed as $entry) {
  257. if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  258. if ($entry->getContent() == $tagContent) {
  259. $tagEntry = $entry;
  260. }
  261. }
  262. }
  263. $photos->deleteTagEntry($tagEntry, true);
  264. outputPhotoFeed($client, $user, $albumId, $photoId);
  265. }
  266. /**
  267. * Returns the path to the current script, without any query params
  268. *
  269. * Env variables used:
  270. * $_SERVER['PHP_SELF']
  271. *
  272. * @return string Current script path
  273. */
  274. function getCurrentScript()
  275. {
  276. global $_SERVER;
  277. return $_SERVER["PHP_SELF"];
  278. }
  279. /**
  280. * Returns the full URL of the current page, based upon env variables
  281. *
  282. * Env variables used:
  283. * $_SERVER['HTTPS'] = (on|off|)
  284. * $_SERVER['HTTP_HOST'] = value of the Host: header
  285. * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443)
  286. * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
  287. *
  288. * @return string Current URL
  289. */
  290. function getCurrentUrl()
  291. {
  292. global $_SERVER;
  293. /**
  294. * Filter php_self to avoid a security vulnerability.
  295. */
  296. $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0,
  297. strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);
  298. if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
  299. $protocol = 'https://';
  300. } else {
  301. $protocol = 'http://';
  302. }
  303. $host = $_SERVER['HTTP_HOST'];
  304. if ($_SERVER['SERVER_PORT'] != '' &&
  305. (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
  306. ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
  307. $port = ':' . $_SERVER['SERVER_PORT'];
  308. } else {
  309. $port = '';
  310. }
  311. return $protocol . $host . $port . $php_request_uri;
  312. }
  313. /**
  314. * Returns the AuthSub URL which the user must visit to authenticate requests
  315. * from this application.
  316. *
  317. * Uses getCurrentUrl() to get the next URL which the user will be redirected
  318. * to after successfully authenticating with the Google service.
  319. *
  320. * @return string AuthSub URL
  321. */
  322. function getAuthSubUrl()
  323. {
  324. $next = getCurrentUrl();
  325. $scope = 'http://picasaweb.google.com/data';
  326. $secure = false;
  327. $session = true;
  328. return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure,
  329. $session);
  330. }
  331. /**
  332. * Outputs a request to the user to login to their Google account, including
  333. * a link to the AuthSub URL.
  334. *
  335. * Uses getAuthSubUrl() to get the URL which the user must visit to authenticate
  336. *
  337. * @return void
  338. */
  339. function requestUserLogin($linkText)
  340. {
  341. $authSubUrl = getAuthSubUrl();
  342. echo "<a href=\"{$authSubUrl}\">{$linkText}</a>";
  343. }
  344. /**
  345. * Returns a HTTP client object with the appropriate headers for communicating
  346. * with Google using AuthSub authentication.
  347. *
  348. * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
  349. * it is obtained. The single use token supplied in the URL when redirected
  350. * after the user succesfully authenticated to Google is retrieved from the
  351. * $_GET['token'] variable.
  352. *
  353. * @return Zend_Http_Client
  354. */
  355. function getAuthSubHttpClient()
  356. {
  357. global $_SESSION, $_GET;
  358. if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
  359. $_SESSION['sessionToken'] =
  360. Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  361. }
  362. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
  363. return $client;
  364. }
  365. /**
  366. * Processes loading of this sample code through a web browser. Uses AuthSub
  367. * authentication and outputs a list of a user's albums if succesfully
  368. * authenticated.
  369. *
  370. * @return void
  371. */
  372. function processPageLoad()
  373. {
  374. global $_SESSION, $_GET;
  375. if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
  376. requestUserLogin('Please login to your Google Account.');
  377. } else {
  378. $client = getAuthSubHttpClient();
  379. if (!empty($_REQUEST['command'])) {
  380. switch ($_REQUEST['command']) {
  381. case 'retrieveSelf':
  382. outputUserFeed($client, "default");
  383. break;
  384. case 'retrieveUser':
  385. outputUserFeed($client, $_REQUEST['user']);
  386. break;
  387. case 'retrieveAlbumFeed':
  388. outputAlbumFeed($client, $_REQUEST['user'], $_REQUEST['album']);
  389. break;
  390. case 'retrievePhotoFeed':
  391. outputPhotoFeed($client, $_REQUEST['user'], $_REQUEST['album'],
  392. $_REQUEST['photo']);
  393. break;
  394. }
  395. }
  396. // Now we handle the potentially destructive commands, which have to
  397. // be submitted by POST only.
  398. if (!empty($_POST['command'])) {
  399. switch ($_POST['command']) {
  400. case 'addPhoto':
  401. addPhoto($client, $_POST['user'], $_POST['album'], $_FILES['photo']);
  402. break;
  403. case 'deletePhoto':
  404. deletePhoto($client, $_POST['user'], $_POST['album'],
  405. $_POST['photo']);
  406. break;
  407. case 'addAlbum':
  408. addAlbum($client, $_POST['user'], $_POST['name']);
  409. break;
  410. case 'deleteAlbum':
  411. deleteAlbum($client, $_POST['user'], $_POST['album']);
  412. break;
  413. case 'addComment':
  414. addComment($client, $_POST['user'], $_POST['album'], $_POST['photo'],
  415. $_POST['comment']);
  416. break;
  417. case 'addTag':
  418. addTag($client, $_POST['user'], $_POST['album'], $_POST['photo'],
  419. $_POST['tag']);
  420. break;
  421. case 'deleteComment':
  422. deleteComment($client, $_POST['user'], $_POST['album'],
  423. $_POST['photo'], $_POST['comment']);
  424. break;
  425. case 'deleteTag':
  426. deleteTag($client, $_POST['user'], $_POST['album'], $_POST['photo'],
  427. $_POST['tag']);
  428. break;
  429. default:
  430. break;
  431. }
  432. }
  433. // If a menu parameter is available, display a submenu.
  434. if (!empty($_REQUEST['menu'])) {
  435. switch ($_REQUEST['menu']) {
  436. case 'user':
  437. displayUserMenu();
  438. break;
  439. case 'photo':
  440. displayPhotoMenu();
  441. break;
  442. case 'album':
  443. displayAlbumMenu();
  444. break;
  445. case 'logout':
  446. logout();
  447. break;
  448. default:
  449. header('HTTP/1.1 400 Bad Request');
  450. echo "<h2>Invalid menu selection.</h2>\n";
  451. echo "<p>Please check your request and try again.</p>";
  452. }
  453. }
  454. if (empty($_REQUEST['menu']) && empty($_REQUEST['command'])) {
  455. displayMenu();
  456. }
  457. }
  458. }
  459. /**
  460. * Displays the main menu, allowing the user to select from a list of actions.
  461. *
  462. * @return void
  463. */
  464. function displayMenu()
  465. {
  466. ?>
  467. <h2>Main Menu</h2>
  468. <p>Welcome to the Photos API demo page. Please select
  469. from one of the following four options to fetch information.</p>
  470. <ul>
  471. <li><a href="?command=retrieveSelf">Your Feed</a></li>
  472. <li><a href="?menu=user">User Menu</a></li>
  473. <li><a href="?menu=photo">Photos Menu</a></li>
  474. <li><a href="?menu=album">Albums Menu</a></li>
  475. </ul>
  476. <?php
  477. }
  478. /**
  479. * Outputs an HTML link to return to the previous page.
  480. *
  481. * @return void
  482. */
  483. function displayBackLink()
  484. {
  485. echo "<br><br>";
  486. echo "<a href='javascript: history.go(-1);'><< Back</a>";
  487. }
  488. /**
  489. * Displays the user menu, allowing the user to request a specific user's feed.
  490. *
  491. * @return void
  492. */
  493. function displayUserMenu()
  494. {
  495. ?>
  496. <h2>User Menu</h2>
  497. <div class="menuForm">
  498. <form method="get" accept-charset="utf-8">
  499. <h3 class='nopad'>Retrieve User Feed</h3>
  500. <p>Retrieve the feed for an existing user.</p>
  501. <p>
  502. <input type="hidden" name="command" value="retrieveUser" />
  503. <label for="user">Username: </label>
  504. <input type="text" name="user" value="" /><br />
  505. </p>
  506. <p><input type="submit" value="Retrieve User &rarr;"></p>
  507. </form>
  508. </div>
  509. <?php
  510. displayBackLink();
  511. }
  512. /**
  513. * Displays the photo menu, allowing the user to request a specific photo's feed.
  514. *
  515. * @return void
  516. */
  517. function displayPhotoMenu()
  518. {
  519. ?>
  520. <h2>Photo Menu</h2>
  521. <div class="menuForm">
  522. <form method="get" accept-charset="utf-8">
  523. <h3 class='nopad'>Retrieve Photo Feed</h3>
  524. <p>Retrieve the feed for an existing photo.</p>
  525. <p>
  526. <input type="hidden" name="command" value="retrievePhotoFeed" />
  527. <label for="user">User: </label>
  528. <input type="text" name="user" value="" /><br />
  529. <label for="album">Album ID: </label>
  530. <input type="text" name="album" value="" /><br />
  531. <label for="photoid">Photo ID: </label>
  532. <input type="text" name="photo" value="" /><br />
  533. </p>
  534. <p><input type="submit" value="Retrieve Photo Feed &rarr;"></p>
  535. </form>
  536. </div>
  537. <?php
  538. displayBackLink();
  539. }
  540. /**
  541. * Displays the album menu, allowing the user to request a specific album's feed.
  542. *
  543. * @return void
  544. */
  545. function displayAlbumMenu()
  546. {
  547. ?>
  548. <h2>Album Menu</h2>
  549. <div class="menuForm">
  550. <form method="get" accept-charset="utf-8">
  551. <h3 class='nopad'>Retrieve Album Feed</h3>
  552. <p>Retrieve the feed for an existing album.</p>
  553. <p>
  554. <input type="hidden" name="command" value="retrieveAlbumFeed" />
  555. <label for="user">User: </label>
  556. <input type="text" name="user" value="" /><br />
  557. <label for="album">Album ID: </label>
  558. <input type="text" name="album" value="" /><br />
  559. </p>
  560. <p><input type="submit" value="Retrieve Album Feed &rarr;"></p>
  561. </form>
  562. </div>
  563. <?php
  564. displayBackLink();
  565. }
  566. /**
  567. * Outputs an HTML unordered list (ul), with each list item representing an
  568. * album in the user's feed.
  569. *
  570. * @param Zend_Http_Client $client The authenticated client object
  571. * @param string $user The user's account name
  572. * @return void
  573. */
  574. function outputUserFeed($client, $user)
  575. {
  576. $photos = new Zend_Gdata_Photos($client);
  577. $query = new Zend_Gdata_Photos_UserQuery();
  578. $query->setUser($user);
  579. $userFeed = $photos->getUserFeed(null, $query);
  580. echo "<h2>User Feed for: " . $userFeed->getTitle() . "</h2>";
  581. echo "<ul class='user'>\n";
  582. foreach ($userFeed as $entry) {
  583. if ($entry instanceof Zend_Gdata_Photos_AlbumEntry) {
  584. echo "\t<li class='user'>";
  585. echo "<a href='?command=retrieveAlbumFeed&user=";
  586. echo $userFeed->getTitle() . "&album=" . $entry->getGphotoId();
  587. echo "'>";
  588. $thumb = $entry->getMediaGroup()->getThumbnail();
  589. echo "<img class='thumb' src='" . $thumb[0]->getUrl() . "' /><br />";
  590. echo $entry->getTitle() . "</a>";
  591. echo "<form action='" . getCurrentScript() . "'' method='post' class='deleteForm'>";
  592. echo "<input type='hidden' name='user' value='" . $user . "' />";
  593. echo "<input type='hidden' name='album' value='" . $entry->getGphotoId();
  594. echo "' />";
  595. echo "<input type='hidden' name='command' value='deleteAlbum' />";
  596. echo "<input type='submit' value='Delete' /></form>";
  597. echo "</li>\n";
  598. }
  599. }
  600. echo "</ul><br />\n";
  601. echo "<h3>Add an Album</h3>";
  602. ?>
  603. <form method="POST" action="<?php echo getCurrentScript(); ?>">
  604. <input type="hidden" name="command" value="addAlbum" />
  605. <input type="hidden" name="user" value="<?php echo $user; ?>" />
  606. <input type="text" name="name" />
  607. <input type="submit" name="Add Album" />
  608. </form>
  609. <?php
  610. displayBackLink();
  611. }
  612. /**
  613. * Outputs an HTML unordered list (ul), with each list item representing a
  614. * photo in the user's album feed.
  615. *
  616. * @param Zend_Http_Client $client The authenticated client object
  617. * @param string $user The user's account name
  618. * @param integer $albumId The album's id
  619. * @return void
  620. */
  621. function outputAlbumFeed($client, $user, $albumId)
  622. {
  623. $photos = new Zend_Gdata_Photos($client);
  624. $query = new Zend_Gdata_Photos_AlbumQuery();
  625. $query->setUser($user);
  626. $query->setAlbumId($albumId);
  627. $albumFeed = $photos->getAlbumFeed($query);
  628. echo "<h2>Album Feed for: " . $albumFeed->getTitle() . "</h2>";
  629. echo "<ul class='albums'>\n";
  630. foreach ($albumFeed as $entry) {
  631. if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) {
  632. echo "\t<li class='albums'>";
  633. echo "<a href='" . getCurrentScript() . "?command=retrievePhotoFeed&user=" . $user;
  634. echo "&album=" . $albumId . "&photo=" . $entry->getGphotoId() . "'>";
  635. $thumb = $entry->getMediaGroup()->getThumbnail();
  636. echo "<img class='thumb' src='" . $thumb[1]->getUrl() . "' /><br />";
  637. echo $entry->getTitle() . "</a>";
  638. echo "<form action='" . getCurrentScript() . "' method='post' class='deleteForm'>";
  639. echo "<input type='hidden' name='user' value='" . $user . "' />";
  640. echo "<input type='hidden' name='album' value='" . $albumId . "' />";
  641. echo "<input type='hidden' name='photo' value='" . $entry->getGphotoId();
  642. echo "' /><input type='hidden' name='command' value='deletePhoto' />";
  643. echo "<input type='submit' value='Delete' /></form>";
  644. echo "</li>\n";
  645. }
  646. }
  647. echo "</ul><br />\n";
  648. echo "<h3>Add a Photo</h3>";
  649. ?>
  650. <form enctype="multipart/form-data" method="POST" action="<?php echo getCurrentScript(); ?>">
  651. <input type="hidden" name="MAX_FILE_SIZE" value="20971520" />
  652. <input type="hidden" name="command" value="addPhoto" />
  653. <input type="hidden" name="user" value="<?php echo $user; ?>" />
  654. <input type="hidden" name="album" value="<?php echo $albumId; ?>" />
  655. Please select a photo to upload: <input name="photo" type="file" /><br />
  656. <input type="submit" name="Upload" />
  657. </form>
  658. <?php
  659. displayBackLink();
  660. }
  661. /**
  662. * Outputs the feed of the specified photo
  663. *
  664. * @param Zend_Http_Client $client The authenticated client object
  665. * @param string $user The user's account name
  666. * @param integer $albumId The album's id
  667. * @param integer $photoId The photo's id
  668. * @return void
  669. */
  670. function outputPhotoFeed($client, $user, $albumId, $photoId)
  671. {
  672. $photos = new Zend_Gdata_Photos($client);
  673. $query = new Zend_Gdata_Photos_PhotoQuery();
  674. $query->setUser($user);
  675. $query->setAlbumId($albumId);
  676. $query->setPhotoId($photoId);
  677. $query = $query->getQueryUrl() . "?kind=comment,tag";
  678. $photoFeed = $photos->getPhotoFeed($query);
  679. echo "<h2>Photo Feed for: " . $photoFeed->getTitle() . "</h2>";
  680. $thumbs = $photoFeed->getMediaGroup()->getThumbnail();
  681. echo "<img src='" . $thumbs[2]->url . "' />";
  682. echo "<h3 class='nopad'>Comments:</h3>";
  683. echo "<ul>\n";
  684. foreach ($photoFeed as $entry) {
  685. if ($entry instanceof Zend_Gdata_Photos_CommentEntry) {
  686. echo "\t<li>" . $entry->getContent();
  687. echo "<form action='" . getCurrentScript() . "' method='post' class='deleteForm'>";
  688. echo "<input type='hidden' name='user' value='" . $user . "' />";
  689. echo "<input type='hidden' name='album' value='" . $albumId . "' />";
  690. echo "<input type='hidden' name='photo' value='" . $photoId . "' />";
  691. echo "<input type='hidden' name='comment' value='" . $entry->getGphotoId();
  692. echo "' />";
  693. echo "<input type='hidden' name='command' value='deleteComment' />";
  694. echo "<input type='submit' value='Delete' /></form>";
  695. echo "</li>\n";
  696. }
  697. }
  698. echo "</ul>\n";
  699. echo "<h4>Add a Comment</h4>";
  700. ?>
  701. <form method="POST" action="<?php echo getCurrentScript(); ?>">
  702. <input type="hidden" name="command" value="addComment" />
  703. <input type="hidden" name="user" value="<?php echo $user; ?>" />
  704. <input type="hidden" name="album" value="<?php echo $albumId; ?>" />
  705. <input type="hidden" name="photo" value="<?php echo $photoId; ?>" />
  706. <input type="text" name="comment" />
  707. <input type="submit" name="Comment" value="Comment" />
  708. </form>
  709. <?php
  710. echo "<br />";
  711. echo "<h3 class='nopad'>Tags:</h3>";
  712. echo "<ul>\n";
  713. foreach ($photoFeed as $entry) {
  714. if ($entry instanceof Zend_Gdata_Photos_TagEntry) {
  715. echo "\t<li>" . $entry->getTitle();
  716. echo "<form action='" . getCurrentScript() . "' method='post' class='deleteForm'>";
  717. echo "<input type='hidden' name='user' value='" . $user . "' />";
  718. echo "<input type='hidden' name='album' value='" . $albumId . "' />";
  719. echo "<input type='hidden' name='photo' value='" . $photoId . "' />";
  720. echo "<input type='hidden' name='tag' value='" . $entry->getContent();
  721. echo "' />";
  722. echo "<input type='hidden' name='command' value='deleteTag' />";
  723. echo "<input type='submit' value='Delete' /></form>";
  724. echo "</li>\n";
  725. }
  726. }
  727. echo "</ul>\n";
  728. echo "<h4>Add a Tag</h4>";
  729. ?>
  730. <form method="POST" action="<?php echo getCurrentScript(); ?>">
  731. <input type="hidden" name="command" value="addTag" />
  732. <input type="hidden" name="user" value="<?php echo $user; ?>" />
  733. <input type="hidden" name="album" value="<?php echo $albumId; ?>" />
  734. <input type="hidden" name="photo" value="<?php echo $photoId; ?>" />
  735. <input type="text" name="tag" />
  736. <input type="submit" name="Tag" value="Tag" />
  737. </form>
  738. <?php
  739. displayBackLink();
  740. }
  741. /**
  742. * Output the CSS for the page
  743. */
  744. ?>
  745. <style type="text/css">
  746. h2 {
  747. color: #0056FF;
  748. }
  749. h3 {
  750. color: #0056FF;
  751. padding-top: 15px;
  752. clear: left;
  753. }
  754. h3.nopad {
  755. padding: 0px;
  756. }
  757. ul {
  758. background-color: #E0EAFF;
  759. color: #191D1D;
  760. margin: 10px;
  761. padding: 10px 10px 10px 25px;
  762. border: 1px solid #515B5C;
  763. }
  764. ul.user, ul.albums {
  765. background-color: #FFFFFF;
  766. border: 0px;
  767. padding: 0px;
  768. }
  769. li.user, li.albums {
  770. display: block;
  771. float: left;
  772. margin: 5px;
  773. padding: 5px;
  774. text-align: center;
  775. background-color: #E0EAFF;
  776. border: 1px solid #515B5C;
  777. }
  778. a {
  779. color: #0056FF;
  780. font-weight: bold;
  781. text-decoration: none;
  782. }
  783. a:hover {
  784. text-decoration: underline;
  785. color: #E00000;
  786. }
  787. div.menuForm {
  788. margin: 10px;
  789. padding: 0px 10px;
  790. background-color: #E0EAFF;
  791. border: 1px solid #515B5C;
  792. }
  793. form.deleteForm {
  794. padding-left: 10px;
  795. display: inline;
  796. }
  797. img.thumb {
  798. margin: 5px;
  799. border: 0px;
  800. }
  801. </style>
  802. <?php
  803. /**
  804. * Calls the main processing function for running in a browser
  805. */
  806. processPageLoad();