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()); }
/** * Adicionar una nueva foto a un album especifico. * * @param integer $albumId id del album * @param array $photo The uploaded photo * @return Zend_Gdata_Photos_PhotoEntry */ public function insertPhoto($albumId, $photo) { $fd = $this->_photos->newMediaFileSource($photo["tmp_name"]); $fd->setContentType($photo["type"]); $entry = new Zend_Gdata_Photos_PhotoEntry(); $entry->setMediaSource($fd); $entry->setTitle($this->_photos->newTitle($photo["name"])); $entry->setSummary($this->_photos->newSummary($photo["summary"])); $albumQuery = new Zend_Gdata_Photos_AlbumQuery(); $albumQuery->setAlbumId($albumId); $albumEntry = $this->_photos->getAlbumEntry($albumQuery); try { $photo = $this->_photos->insertPhotoEntry($entry, $albumEntry); } catch (Zend_Exception $e) { //echo $e->getMessage(); } return $photo; }
/** * 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) { $photos = new Zend_Gdata_Photos($client); $fd = $photos->newMediaFileSource($photo["tmp_name"]); $fd->setContentType($photo["type"]); $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) { outputAlbumFeed($client, $user, $albumId); } else { echo "There was an issue with the file upload."; } }
/** * 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."; } }
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"); } }
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; }