Пример #1
0
 public function postPhotoToAlbum($photoName, $photoPath, $albumName)
 {
     $types = array('jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/jpeg', 'png' => 'image/png');
     $source = $this->gData->newMediaFileSource($photoPath);
     $extension = strtolower(pathinfo($photoPath, PATHINFO_EXTENSION));
     $source->setContentType($types[$extension]);
     $photoEntry = $this->gData->newPhotoEntry();
     $photoEntry->setMediaSource($source);
     $photoEntry->setTitle($this->gData->newTitle($photoName));
     $albumQuery = $this->gData->newAlbumQuery();
     $albumQuery->setUser($this->user);
     $albumQuery->setAlbumName($albumName);
     return $this->gData->insertPhotoEntry($photoEntry, $albumQuery->getQueryUrl());
 }
Пример #2
0
 public function picasaUpload($file)
 {
     $extension = pathinfo($file->getFileName(), PATHINFO_EXTENSION);
     $file_path = $this->tempfolder . $this->random_file_name() . "." . $extension;
     //save file to temp folder
     //move_uploaded_file($file->getFileName(), $file_path);
     copy($file->getTempFile(), $file_path);
     //upload to picasa
     $token = $this->get_login_token();
     //create client
     $client = new Zend_Gdata_HttpClient();
     $client->setAuthSubToken($token);
     $client->setClientLoginToken($token);
     //create new photo
     $gphoto = new Zend_Gdata_Photos($client);
     $photo = $gphoto->newPhotoEntry();
     $gfile = $gphoto->newMediaFileSource($file_path);
     $gfile->setContentType('image/' . $extension);
     $photo->setMediaSource($gfile);
     $photo->setTitle($gphoto->newTitle($file->getFileName()));
     // link to album
     $album = $gphoto->newAlbumQuery();
     $album->setUser($this->config['user']);
     $album->setAlbumId($this->config['album_id']);
     // save photo to album
     $insertedEntry = $gphoto->insertPhotoEntry($photo, $album->getQueryUrl());
     //delete file in temp folder
     if (file_exists($file_path)) {
         unlink($file_path);
     }
     if ($insertedEntry->getMediaGroup()->getContent() != null) {
         $photoUrl = $insertedEntry->getMediaGroup()->getContent()[0]->getUrl();
         $photoThumbnail = $insertedEntry->getMediaGroup()->getThumbnail()[1]->getUrl();
         $photoId = $insertedEntry->getGphotoId();
         return array("thumbnail" => $photoThumbnail, "url" => $photoUrl, "id" => $photoId);
     } else {
         throw new XenForo_Exception("Cannot get file url");
     }
 }
Пример #3
0
 public function insertPhotoEntry($data)
 {
     // Get plugin info
     $plugin =& JPluginHelper::getPlugin('system', 'gdata');
     $params = new JParameter($plugin->params);
     plgSystemGdata::gimport('Zend.Gdata.ClientLogin');
     plgSystemGdata::gimport('Zend.Gdata.Photos');
     plgSystemGdata::gimport('Zend.Gdata.AuthSub');
     $username = $params->get('domain_admin_email');
     $pass = $params->get('domain_admin_password');
     $albumId = $data['album'];
     $photoName = $data['name'];
     // Cleanup photoName
     list($photoName, $extension) = split('[.]', $photoName);
     // Login
     $serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
     $client = Zend_Gdata_ClientLogin::getHttpClient($username, $pass, $serviceName);
     // update the second argument to be CompanyName-ProductName-Version
     $gp = new Zend_Gdata_Photos($client, "Google-DevelopersGuide-1.0");
     $fd = $gp->newMediaFileSource($data['file']);
     $fd->setContentType("image/jpeg");
     // Create a PhotoEntry
     $photoEntry = $gp->newPhotoEntry();
     $photoEntry->setMediaSource($fd);
     $photoEntry->setTitle($gp->newTitle($photoName));
     // We use the AlbumQuery class to generate the URL for the album
     $albumQuery = $gp->newAlbumQuery();
     $albumQuery->setUser($username);
     $albumQuery->setAlbumName($albumId);
     // We insert the photo, and the server returns the entry representing
     // that photo after it is uploaded
     $insertedEntry = $gp->insertPhotoEntry($photoEntry, $albumQuery->getQueryUrl());
     return true;
 }
Пример #4
0
<?php

error_reporting(E_ALL);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Photos');
// Album and User
$sUserID = "100211726914724722900";
$sAlbumName = "jujuNew";
$serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
$gp = new Zend_Gdata_Photos();
$query = $gp->newAlbumQuery();
$query->setUser($sUserID);
$query->setAlbumName($sAlbumName);
$query->setImgMax("800");
$query->setThumbSize("160");
$albumFeed = $gp->getAlbumFeed($query);
$sPrintThumbs = "";
foreach ($albumFeed as $albumEntry) {
    if ($albumEntry->getMediaGroup()->getThumbnail() != null) {
        // Load Thumbnail Info
        $mediaThumbnailArray = $albumEntry->getMediaGroup()->getThumbnail();
        $ThumbnailUrl = $mediaThumbnailArray[0]->getUrl();
        $ThumbnailHeight = $mediaThumbnailArray[0]->getHeight();
        $ThumbnailWidth = $mediaThumbnailArray[0]->getWidth();
        // Load Picture Info
        $mediaArray = $albumEntry->getMediaGroup()->getContent();
        $ImageUrl = $mediaArray[0]->getUrl();
        $sImageTitle = $albumEntry->getMediaGroup()->getDescription()->text;
        $url = $albumEntry->getLink('alternate')->href;
        $sLinkString = <<<LTEXT
<a href="{$ImageUrl}" title="{$sImageTitle}"><img src="{$ThumbnailUrl}" width="{$ThumbnailWidth}" height="{$ThumbnailHeight}" /></a>
Пример #5
0
        public function __construct() {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass('Zend_Gdata_Photos');
            Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
            Zend_Loader::loadClass('Zend_Gdata_AuthSub'); 

            $serviceName = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
            $username = '******';
            $password = '******';
            $client = Zend_Gdata_ClientLogin::getHttpClient( $username, $password, $serviceName );

            $gp = new Zend_Gdata_Photos( $client, 'Dionyziz-Life-1.0' );

            $query = $gp->newAlbumQuery();

            $query->setUser( 'default' );
            $query->setAlbumName( 'Sikinos' );

            $albumFeed = $gp->getAlbumFeed( $query );

            $i = 0;
            foreach ( $albumFeed as $albumEntry ) {
                try { 
                    $albumid = $albumEntry->getGphotoAlbumId();

                    $exif = $albumEntry->getExifTags();
                    $time = $exif->getTime();
                    if ( $time == null ) {
                        echo "Photo does not contain time information.\n";
                        continue;
                    }
                    $timestamp = $time->getText();

                    $mediaContentArray = $albumEntry->getMediaGroup()->getContent();
                    $contentUrl = $mediaContentArray[ 0 ]->getUrl();
                    $mediaThumbnailArray = $albumEntry->getMediaGroup()->getThumbnail();
                    if ( $mediaThumbnailArray == null ) {
                        echo "Photo does not contain thumbnail.\n";
                        continue;
                    }
                    $maxwidth = 0;
                    $maxid = 0;
                    foreach ( $mediaThumbnailArray as $id => $thumb ) {
                        if ( $thumb->getWidth() > $maxwidth ) {
                            $maxwidth = $thumb->getWidth();
                            $maxid = $id;
                            $thumbnailUrl = $thumb->getUrl();
                        }
                    }

                    // echo "Importing image " . $contentUrl . " from Picasa... ";
                    // $diff = 1310008564116;
                    $link = $albumEntry->getAlternateLink()->getHref();
                    $parts = explode( '/', $link );
                    $userid = $parts[ 3 ];
                    $parts = explode( '#', $link );
                    $photoid = $parts[ 1 ];
                    $link = 'https://plus.google.com/photos/' . $userid . '/albums/' . $albumid . '/' . $photoid;
                    // echo( $link . ': ' . date( "Y-m-d H:i:s", $timestamp - $diff ) . "\n" );
                    Post::update( 
                        Post::create( 'picasa:' . $contentUrl . ' ' . $thumbnailUrl . ' ' . $link, 1, 'photo', 'public' ),
                        date( "Y-m-d H:i:s", $timestamp / 1000 )
                    );
                    ++$i;
                    echo $i . ' / ' . count( $albumFeed ) . "\n";
                }
                catch ( Exception $e ) {
                    echo "Failed to retrieve photo EXIF information.\n";
                }
            }
        }