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