示例#1
0
 /**
  * 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');
 }
示例#2
0
 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;
 }
示例#3
0
/**
 * 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.";
    }
}
示例#4
0
 /**
  * Returns the URL generated for this query, based on it's current
  * parameters.
  *
  * @return string A URL generated based on the state of this query.
  * @throws Zend_Gdata_App_InvalidArgumentException
  */
 public function getQueryUrl($incomingUri = '')
 {
     $uri = '';
     if ($this->getPhotoId() !== null) {
         $uri .= '/photoid/' . $this->getPhotoId();
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('PhotoId cannot be null');
     }
     $uri .= $incomingUri;
     return parent::getQueryUrl($uri);
 }
示例#5
0
 /**
  * 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);
 }
示例#6
0
文件: Photos.php 项目: jsnshrmn/Suma
/**
 * 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();
}
示例#7
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;
 }
示例#8
0
 /**
  * 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;
 }
示例#9
0
 function _insertPhoto($data)
 {
     $s = @getimagesize($data['image_url']);
     $fd = $this->_service->newMediaFileSource($data['image_url']);
     $fd->setContentType(@$s['mime']);
     $entry = new Zend_Gdata_Photos_PhotoEntry();
     $entry->setMediaSource($fd);
     $entry->setGphotoTimestamp($this->_service->newTimestamp((string) strtotime($data['date']) . '000'));
     //$entry->setTitle($this->_service->newTitle($data['description']));
     $query = new Zend_Gdata_Photos_AlbumQuery();
     $query->setAlbumId($data['parentid']);
     $album = $this->_service->getAlbumEntry($query);
     $entry = $this->_service->insertPhotoEntry($entry, $album);
     return $entry ? $entry->getGphotoId() : false;
 }
示例#10
0
文件: Util.php 项目: kwylez/CW-Google
 /**
  * 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();
 }
示例#11
0
 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;
 }
示例#12
0
function add_embpicasa_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array("id" => ''), $atts));
    // do not display anything if there is no "id"
    if (empty($id)) {
        return '';
    }
    $options = get_option('embpicasa_options');
    // do not display anything in loop if "Show only on single post"
    if (!is_single() && $options['embpicasa_options_single_only'] == 'yes') {
        return '';
    }
    if (!empty($options['embpicasa_options_login']) && !empty($options['embpicasa_options_password'])) {
        try {
            set_include_path(implode(PATH_SEPARATOR, array(realpath(dirname(__FILE__) . '/library'), get_include_path())));
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass('Zend_Gdata');
            Zend_Loader::loadClass('Zend_Gdata_Query');
            Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
            Zend_Loader::loadClass('Zend_Gdata_Photos');
            Zend_Loader::loadClass('Zend_Gdata_Photos_UserQuery');
            Zend_Loader::loadClass('Zend_Gdata_Photos_AlbumQuery');
            Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoQuery');
            $client = Zend_Gdata_ClientLogin::getHttpClient($options['embpicasa_options_login'], $options['embpicasa_options_password'], Zend_Gdata_Photos::AUTH_SERVICE_NAME);
            $service = new Zend_Gdata_Photos($client);
            $photos = array();
            $query = new Zend_Gdata_Photos_AlbumQuery();
            $query->setAlbumId($id);
            // http://code.google.com/intl/ru/apis/picasaweb/docs/1.0/reference.html
            $thumb_suffix = $options['embpicasa_options_thumb_crop'] == 'no' ? 'u' : 'c';
            $full_suffix = $options['embpicasa_options_full_crop'] == 'no' ? 'u' : 'c';
            $query->setThumbsize($options['embpicasa_options_thumb_size'] . $thumb_suffix);
            $query->setImgMax($options['embpicasa_options_full_size'] . $full_suffix);
            $results = $service->getAlbumFeed($query);
            while ($results != null) {
                foreach ($results as $entry) {
                    foreach ($results as $photo) {
                        $photos[] = array('thumbnail' => $photo->mediaGroup->thumbnail[0]->url, 'fullsize' => $photo->mediaGroup->content[0]->url, 'title' => $photo->mediaGroup->description->text);
                    }
                }
                try {
                    $results = $results->getNextFeed();
                } catch (Exception $e) {
                    $results = null;
                }
            }
            $plugin_template = dirname(__FILE__) . '/loop-picasa.php';
            $theme_template = get_theme_root() . '/' . get_template() . '/loop-picasa.php';
            $template_path = file_exists($theme_template) ? $theme_template : $plugin_template;
            ob_start();
            include $template_path;
            $html = ob_get_contents();
            ob_end_clean();
            return $html;
        } catch (Exception $ex) {
            return '<p style="color:red">' . $ex->getMessage() . '</p>';
        }
    } else {
        return '';
        //empty login or password
    }
}
示例#13
0
 /**
  * Obtener las fotos de un album especifico.
  *
  * @param  integer          $albumId Id Album
  * @return Zend_Gdata_Photos_AlbumFeed
  */
 public function getPhotos($albumId)
 {
     $query = new Zend_Gdata_Photos_AlbumQuery();
     $query->setAlbumId($albumId);
     $albumFeed = $this->_photos->getAlbumFeed($query);
     return $albumFeed;
 }