Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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();
 }