/** * Retrieving An Album */ function getAlbumDetail($username, $album_id) { require_once 'Zend/Gdata/Photos/AlbumQuery.php'; $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($username); $query->setAlbumId($album_id); //maximum supported for embedding is 800px $query->setImgmax(640); try { $albumFeed = $this->service->getAlbumFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); } foreach ($albumFeed as $item) { $one = array(); $one['title'] = $item->title->text; $one['id'] = $item->getGphotoId()->text; $mediaContentFull = $item->getMediaGroup()->getContent(); $one['full'] = $mediaContentFull[0]->getUrl(); $mediaContentThumbnail = $item->getMediaGroup()->getThumbnail(); $one['thumbnail'] = $mediaContentThumbnail[0]->getUrl(); $one['thumbnail_width'] = $mediaContentThumbnail[0]->getWidth(); $one['thumbnail_height'] = $mediaContentThumbnail[0]->getHeight(); $list[] = $one; } foreach ($list as $item) { $this->tpl->assign('ITEM', $item); $this->tpl->parse('content.album_detail.item'); } $this->tpl->parse('content.album_detail'); }
function getAlbum($user, $pass, $albumName) { $service = Zend_Gdata_Photos::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service); $photos = new Zend_Gdata_Photos($client); $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($user); $query->setAlbumName($albumName); $albumFeed = $photos->getAlbumFeed($query); $ret = array(); foreach ($albumFeed as $entry) { if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) { $thumb = $entry->getMediaGroup()->getThumbnail(); $ret[] = array("url" => $thumb[1]->getUrl(), "id" => $entry->getGphotoId()); } } return $ret; }
/** * Adds a new photo to the specified album * * @param Zend_Http_Client $client The authenticated client * @param string $user The user's account name * @param integer $albumId The album's id * @param array $photo The uploaded photo * @return void */ function addPhoto($client, $user, $albumId, $photo_name, $photo_path) { $photos = new Zend_Gdata_Photos($client); $fd = $photos->newMediaFileSource($photo_path); $fd->setContentType('image/jpeg'); $entry = new Zend_Gdata_Photos_PhotoEntry(); $entry->setMediaSource($fd); $entry->setTitle($photos->newTitle($photo_name)); $albumQuery = new Zend_Gdata_Photos_AlbumQuery(); $albumQuery->setUser($user); $albumQuery->setAlbumId($albumId); $albumEntry = $photos->getAlbumEntry($albumQuery); $result = $photos->insertPhotoEntry($entry, $albumEntry); if ($result) { return $result; } else { echo "There was an issue with the file upload."; } }
/** * Check the consistency of an album feed request for specifically-sized images */ public function testImgAlbumQuery() { $queryString = "https://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1?imgmax=800"; $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser("sample.user"); $query->setAlbumId("1"); $query->setImgMax("800"); // Assert that the set ImgMax is correct $this->assertEquals("800", $query->getImgMax()); $generatedString = $query->getQueryUrl(); // Assert that the generated query matches the correct one $this->assertEquals($queryString, $generatedString); // Check that ImgMax is set back to null $queryString = "https://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1"; $query->setImgMax(null); $generatedString = $query->getQueryUrl(); // Assert that the generated query matches the correct one $this->assertEquals($queryString, $generatedString); }
/** * Outputs an HTML unordered list (ul), with each list item representing a * photo in the user's album feed. * * @param Zend_Http_Client $client The authenticated client object * @param string $user The user's account name * @param integer $albumId The album's id * @return void */ function outputAlbumFeed($client, $user, $albumId) { $photos = new Zend_Gdata_Photos($client); $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($user); $query->setAlbumId($albumId); $albumFeed = $photos->getAlbumFeed($query); echo "<h2>Album Feed for: " . $albumFeed->getTitle() . "</h2>"; echo "<ul class='albums'>\n"; foreach ($albumFeed as $entry) { if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) { echo "\t<li class='albums'>"; echo "<a href='" . getCurrentScript() . "?command=retrievePhotoFeed&user="******"&album=" . $albumId . "&photo=" . $entry->getGphotoId() . "'>"; $thumb = $entry->getMediaGroup()->getThumbnail(); echo "<img class='thumb' src='" . $thumb[1]->getUrl() . "' /><br />"; echo $entry->getTitle() . "</a>"; echo "<form action='" . getCurrentScript() . "' method='post' class='deleteForm'>"; echo "<input type='hidden' name='user' value='" . $user . "' />"; echo "<input type='hidden' name='album' value='" . $albumId . "' />"; echo "<input type='hidden' name='photo' value='" . $entry->getGphotoId(); echo "' /><input type='hidden' name='command' value='deletePhoto' />"; echo "<input type='submit' value='Delete' /></form>"; echo "</li>\n"; } } echo "</ul><br />\n"; echo "<h3>Add a Photo</h3>"; ?> <form enctype="multipart/form-data" method="POST" action="<?php echo getCurrentScript(); ?> "> <input type="hidden" name="MAX_FILE_SIZE" value="20971520" /> <input type="hidden" name="command" value="addPhoto" /> <input type="hidden" name="user" value="<?php echo $user; ?> " /> <input type="hidden" name="album" value="<?php echo $albumId; ?> " /> Please select a photo to upload: <input name="photo" type="file" /><br /> <input type="submit" name="Upload" /> </form> <?php displayBackLink(); }
/** * getAjaxMorePicasaPhotos * * Will get the next 25 photos for the given album id, starting with given index. * Then calls js to get next 25. * * @return string */ function getAjaxMorePicasaPhotos() { $token = $_POST['picasa_session_token']; $albumId = $_POST['albumId']; $startIndex = $_POST['start_index']; $photos = ''; $httpClient = Zend_Gdata_AuthSub::getHttpClient($token); $picasaService = new Zend_Gdata_Photos($httpClient, "Google-DevelopersGuide-1.0"); try { $feed = $picasaService->getUserFeed("default"); } catch (Zend_Gdata_App_Exception $e) { echo ' <p class="error-alert"> ' . T_('Could not get Picasa data.') . ' </p>'; logError(__FILE__ . ' [' . __LINE__ . '] - Could not get user picasa data. - ' . $e->getMessage()); return; } try { $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($feed->getTitle()); $query->setAlbumId($albumId); $query->setStartIndex($startIndex); $query->setMaxResults(25); $albumFeed = $picasaService->getAlbumFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo ' <p class="error-alert"> ' . T_('Could not get Picasa album data.') . ' </p>'; logError(__FILE__ . ' [' . __LINE__ . '] - Could not get user picasa album data. - ' . $e->getMessage()); return; } $count = 0; foreach ($albumFeed as $photo) { // Skip videos $mediaContent = $photo->getMediaGroup()->getContent(); foreach ($mediaContent as $content) { if ($content->getMedium() == 'video') { continue 2; } } $thumb = $photo->getMediaGroup()->getThumbnail(); $sourceId = $photo->getGphotoId()->text; $thumbnail = $thumb[1]->getUrl(); $w = $photo->getGphotoWidth()->text; $h = $photo->getGphotoHeight()->text; $width = '100%;'; $height = 'auto;'; if ($w > $h) { $width = 'auto;'; $height = '100%;'; } $_SESSION['picasa_photos'][$sourceId] = array('thumbnail' => $thumbnail, 'width' => $width, 'height' => $height); $photos .= '<li>'; $photos .= '<label for="picasa' . $startIndex . '">'; $photos .= '<img src="' . $thumbnail . '" style="width:' . $width . ' height:' . $height . '"/>'; $photos .= '<span style="display:none"></span>'; $photos .= '</label>'; $photos .= '<input type="checkbox" id="picasa' . $startIndex . '" name="photos[]" value="' . $sourceId . '"/>'; $photos .= '</li>'; $startIndex++; $count++; } if ($count >= 25) { $photos .= '<script type="text/javascript">loadMorePicasaPhotos(' . $startIndex . ', "' . $token . '", "' . T_('Could not get additional photos.') . '");</script>'; } else { $_SESSION['picasa_album_done'] = 1; } echo $photos; }
/** * setFormData * * Saves all the data passed in from the form upload. * * @param array $formData * * @return void */ public function setFormData($formData) { $this->formData = $formData; $token = getUserPicasaSessionToken($this->fcmsUser->id); $albumId = $formData['albums']; $user = $formData['picasa_user']; $httpClient = Zend_Gdata_AuthSub::getHttpClient($token); $picasaService = new Zend_Gdata_Photos($httpClient, "Google-DevelopersGuide-1.0"); $thumbSizes = '150c,600'; if ($this->usingFullSizePhotos) { $thumbSizes .= ',d'; } try { $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($user); $query->setAlbumId($albumId); $query->setParam('thumbsize', $thumbSizes); $albumFeed = $picasaService->getAlbumFeed($query); } catch (Zend_Gdata_App_Exception $e) { $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Picasa data.'), 'error' => $e->getMessage(), 'file' => __FILE__, 'line' => __LINE__)); return false; } $this->albumFeed = $albumFeed; }
/** * Retrieve list of gallery images and their properties * * @access public * @param string $gallery * @throws Exception * @return array $photoAttrs */ public function getGalleryImages($gallery) { $query = new Zend_Gdata_Photos_AlbumQuery(); $query->setUser($this->getUser()); $query->setStartIndex(self::START_INDEX); $query->setMaxResults(self::MAX_RESULTS); if (Zend_Validate::is($gallery, 'Alnum')) { $query->setAlbumName($gallery); } elseif (Zend_Validate::is($gallery, 'Digits')) { $query->setAlbumId($gallery); } else { throw new Exception("Invalid gallery was given"); } try { $albumFeed = $this->getGphotoService()->getAlbumFeed($query); /* $previousLink = $albumFeed->getLink("previous"); $nextLink = $albumFeed->getLink("next"); if (!is_null($previousLink)) { $previousFeed = $this->getGphotoService()->getAlbumFeed($previousLink->href); $this->setPreviousLink($previousLink->href); } if (!is_null($nextLink)) { $nextFeed = $this->getGphotoService()->getAlbumFeed($nextLink->href); $this->setNextLink($nextLink->href); } */ $this->setGGalleryNumPhotos($albumFeed->getGphotoNumPhotos()); $this->setGGalleryLocation($albumFeed->getGphotoLocation()); $this->setGGalleryTimestamp(substr($albumFeed->getGphotoTimestamp(), 0, 10)); $this->setGGalleryTitle($albumFeed->title); foreach ($albumFeed as $photo) { $photoQuery = new Zend_Gdata_Photos_PhotoQuery(); $photoQuery->setUser($this->getUser()); if (Zend_Validate::is($gallery, 'Alnum')) { $photoQuery->setAlbumName($gallery); } elseif (Zend_Validate::is($gallery, 'Digits')) { $photoQuery->setAlbumId($gallery); } else { throw new Exception("Invalid gallery was given"); } $photoQuery->setPhotoId($photo->getGphotoId()); $photoQuery->setImgMax(self::PIXEL_MAX); $photoFeed = $this->getGphotoService()->getPhotoFeed($photoQuery); $geoRssWhere = empty($photo->getGeoRssWhere()->point->pos->text) ? "" : $photo->getGeoRssWhere()->point->pos->text; $gPicasa = new CW_Google_Picasa_Photo($photo->getGphotoId(), $photo->getGphotoCommentCount(), $photo->getGphotoCommentingEnabled(), $photoFeed->getGphotoSize(), $photoFeed->getGphotoTimestamp(), $photoFeed->mediaGroup->content[0]->url, $photoFeed->mediaGroup->description->text, $photoFeed->mediaGroup->thumbnail[0]->url, $photoFeed->mediaGroup->thumbnail[0]->width, $photoFeed->mediaGroup->thumbnail[0]->height, $geoRssWhere); $this->setPhotoAttrs($gPicasa); } } catch (Zend_Gdata_App_Exception $e) { print "Error: " . $e->__toString(); } catch (Zend_Gdata_App_HttpException $httpexception) { print $httpexception->getResponse()->getBody(); } catch (Exception $e) { print "Error: " . $e->__toString(); } return $this->getPhotoAttrs(); }
public static function upload($pic, $nameImage) { $cUrl = ""; static::auth(); $fd = static::$service->newMediaFileSource($pic["full_path"]); $fd->setContentType($pic["file_type"]); $entry = new Zend_Gdata_Photos_PhotoEntry(); $entry->setMediaSource($fd); $entry->setTitle(static::$service->newTitle($nameImage)); $albumQuery = new Zend_Gdata_Photos_AlbumQuery(); $albumQuery->setUser("default"); $albumQuery->setAlbumId(static::$albumID); $albumEntry = static::$service->getAlbumEntry($albumQuery); try { $insertedEntry = static::$service->insertPhotoEntry($entry, $albumEntry); if ($insertedEntry->getMediaGroup()->getContent() != null) { $mediaContentArray = $insertedEntry->getMediaGroup()->getContent(); $wantReplace = "/" . $nameImage; $cUrl = @str_replace($wantReplace, "", $mediaContentArray[0]->getUrl()); $cUrl = static::changelink($cUrl); } static::$status['error'] = false; static::$status['message'] = "Success !"; } catch (Zend_Gdata_App_Exception $e) { //static::$status['message'] =$e->getMessage(); $cUrl = NULL; } return $cUrl; }