Beispiel #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());
 }
 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");
     }
 }
Beispiel #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;
 }