function add_new_photo_to_album($gp, $path, $new_album_name) { $user_name = "default"; $file_name = $path; $photo_name = "Photo added by Facebook Album Challenge"; $photo_caption = "Photo added by Facebook Album Challenge"; $photo_tags = "Photo, Facebook-Album-Challenge"; $fd = $gp->newMediaFileSource($file_name); $fd->setContentType("image/jpeg"); // Create a PhotoEntry $photo_entry = $gp->newPhotoEntry(); $photo_entry->setMediaSource($fd); $photo_entry->setTitle($gp->newTitle($photo_name)); $photo_entry->setSummary($gp->newSummary($photo_caption)); // add some tags $photo_media = new Zend_Gdata_Media_Extension_MediaKeywords(); $photo_media->setText($photo_tags); $photo_entry->mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup(); $photo_entry->mediaGroup->keywords = $photo_media; // We use the AlbumQuery class to generate the URL for the album $album_query = $gp->newAlbumQuery(); $album_query->setUser($user_name); $album_query->setAlbumName($new_album_name); $gp->insertPhotoEntry($photo_entry, $album_query->getQueryUrl()); }
/** * Sets the keyword tags for a video. * * @param mixed $tags Either a comma-separated string or an array * of tags for the video * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface */ public function setVideoTags($tags) { $this->ensureMediaGroupIsNotNull(); $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); if (is_array($tags)) { $tags = implode(', ', $tags); } $keywords->setText($tags); $this->getMediaGroup()->setKeywords($keywords); return $this; }
/** * Creates individual Entry objects of the appropriate type and * stores them in the $_entry array based upon DOM data. * * @param DOMNode $child The DOMNode to process */ protected function takeChildFromDOM($child) { $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; switch ($absoluteNodeName) { case $this->lookupNamespace('media') . ':' . 'content': $content = new Zend_Gdata_Media_Extension_MediaContent(); $content->transferFromDOM($child); $this->_content[] = $content; break; case $this->lookupNamespace('media') . ':' . 'category': $category = new Zend_Gdata_Media_Extension_MediaCategory(); $category->transferFromDOM($child); $this->_category[] = $category; break; case $this->lookupNamespace('media') . ':' . 'copyright': $copyright = new Zend_Gdata_Media_Extension_MediaCopyright(); $copyright->transferFromDOM($child); $this->_copyright = $copyright; break; case $this->lookupNamespace('media') . ':' . 'credit': $credit = new Zend_Gdata_Media_Extension_MediaCredit(); $credit->transferFromDOM($child); $this->_credit[] = $credit; break; case $this->lookupNamespace('media') . ':' . 'description': $description = new Zend_Gdata_Media_Extension_MediaDescription(); $description->transferFromDOM($child); $this->_description = $description; break; case $this->lookupNamespace('media') . ':' . 'hash': $hash = new Zend_Gdata_Media_Extension_MediaHash(); $hash->transferFromDOM($child); $this->_hash[] = $hash; break; case $this->lookupNamespace('media') . ':' . 'keywords': $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); $keywords->transferFromDOM($child); $this->_keywords = $keywords; break; case $this->lookupNamespace('media') . ':' . 'player': $player = new Zend_Gdata_Media_Extension_MediaPlayer(); $player->transferFromDOM($child); $this->_player[] = $player; break; case $this->lookupNamespace('media') . ':' . 'rating': $rating = new Zend_Gdata_Media_Extension_MediaRating(); $rating->transferFromDOM($child); $this->_rating[] = $rating; break; case $this->lookupNamespace('media') . ':' . 'restriction': $restriction = new Zend_Gdata_Media_Extension_MediaRestriction(); $restriction->transferFromDOM($child); $this->_restriction[] = $restriction; break; case $this->lookupNamespace('media') . ':' . 'text': $text = new Zend_Gdata_Media_Extension_MediaText(); $text->transferFromDOM($child); $this->_mediaText[] = $text; break; case $this->lookupNamespace('media') . ':' . 'thumbnail': $thumbnail = new Zend_Gdata_Media_Extension_MediaThumbnail(); $thumbnail->transferFromDOM($child); $this->_thumbnail[] = $thumbnail; break; case $this->lookupNamespace('media') . ':' . 'title': $title = new Zend_Gdata_Media_Extension_MediaTitle(); $title->transferFromDOM($child); $this->_title = $title; break; default: parent::takeChildFromDOM($child); break; } }
public function updatePhotoMetaData() { $client = $this->photos; $album = $this->createAlbum(); $insertedEntry = $this->createPhoto($album); $insertedEntry->title->text = "New Photo"; $insertedEntry->summary->text = "Photo caption"; $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); $keywords->setText("foo, bar, baz"); $insertedEntry->mediaGroup->keywords = $keywords; $updatedEntry = $insertedEntry->save(); return array($updatedEntry, $album); }
function uploadpicture() { //uploading photo to server $_data['new_album_name'] = $newAlbumName = $this->input->post('new_album_name'); $_data['album_id'] = $albumId = $this->input->post('album_id'); //var_dump($_SESSION); if (!($albumId || $newAlbumName)) { //echo "test"; $_data['msg'] = $msg = 'You should select album or enter new album name'; $_data['albums'] = $this->_getAlbums(); } elseif (!empty($_FILES['image'])) { $uploaddir = BASEPATH . '../pictures'; $fname = $_FILES['image']['name']; $fsize = $_FILES['image']['size']; $ftmpname = $_FILES['image']['tmp_name']; $ext = ''; if (preg_match("/.+(\\..+)\$/i", $fname, $matches)) { $ext = strtolower($matches[1]); } //file extension $filename = $this->_genFileName($ext, $uploaddir); $uploadfile = $uploaddir . '/' . $filename; //debug: //echo $uploadfile; //$fsize < 3000000 //allow to upload only pics that less then file_upload_size bytes if (in_array($ext, array(".gif", ".png", ".jpg"))) { if (move_uploaded_file($ftmpname, $uploadfile)) { //uploaded $uploaded = TRUE; } else { //Error while uploading file } } else { //Picture shouldn't exceed file_upload_size bytes $_data['msg'] = $msg = 'Uploaded file should be a picture'; } } else { $_data['msg'] = $msg = 'You should select picture to upload'; } if (empty($uploaded)) { if (empty($msg)) { $_data['msg'] = $msg = 'Cannot upload file'; } $_data['albums'] = $this->_getAlbums(); $this->load->view('member_post_picture', $_data); //exit; } else { $photoName = "Test"; $photoCaption = "Uploaded to Picasa Web Albums via PHP."; $photoTags = ""; $fd = $this->gp->newMediaFileSource($uploadfile); $fd->setContentType("image/jpeg"); // Create a PhotoEntry $photoEntry = $this->gp->newPhotoEntry(); $photoEntry->setMediaSource($fd); $photoEntry->setTitle($this->gp->newTitle($photoName)); $photoEntry->setSummary($this->gp->newSummary($photoCaption)); // add some tags $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); $keywords->setText($photoTags); $photoEntry->mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup(); $photoEntry->mediaGroup->keywords = $keywords; // We use the AlbumQuery class to generate the URL for the album $albumQuery = $this->gp->newAlbumQuery(); $albumQuery->setUser($this->username); if ($albumId) { $albumQuery->setAlbumId($albumId); } else { $entry = new Zend_Gdata_Photos_AlbumEntry(); $entry->setTitle($this->gp->newTitle($newAlbumName)); $entry->setSummary($this->gp->newSummary("")); $createdEntry = $this->gp->insertAlbumEntry($entry); //$albumQuery->setAlbumName($newAlbumName); $albumQuery->setAlbumId((string) $createdEntry->gphotoId); //Zend_Debug::dump((string)$createdEntry->gphotoId); } // We insert the photo, and the server returns the entry representing // that photo after it is uploaded $insertedEntry = $this->gp->insertPhotoEntry($photoEntry, $albumQuery->getQueryUrl()); if ($insertedEntry->getMediaGroup()->getContent() != null) { $mediaContentArray = $insertedEntry->getMediaGroup()->getContent(); $contentUrl = $mediaContentArray[0]->getUrl(); print "<pre>"; var_dump($contentUrl); print "</pre>"; if (!empty($this->fbUserId) && !empty($this->userSettings) && $this->userSettings[0]['facebook_pics_y_n'] == 1) { // uploading picture to Facebook //$Albums = $this->facebook->api_client->photos_getAlbums($this->fbUserId, null); //if(!empty($Albums)) $AlbumId = $Albums[0]['aid']; else $AlbumId = null; //print"<pre>";var_dump($AlbumId);print"</pre>"; try { $this->facebook->api_client->photos_upload($uploadfile, null, "Uploading image with " . $this->conf['site_name'], $this->fbUserId); //$this->facebook->api_client->photos_upload($uploadfile, $AlbumId, "Uploading image with pep6", $this->fbUserId); } catch (Exception $ex) { echo $ex->getMessage(); //echo "Cannot upload picture to facebook"; } } $lastMessage = $this->Post_model->getWhere(null, $limit = 1, $offset = 0, $order = 'id DESC'); if (!empty($lastMessage) && $lastMessage[0]['user_id'] == $this->getUserId() && $lastMessage[0]['site_id'] == $this->subdomainId && $lastMessage[0]['post_type'] == 'picture') { $this->Post_pictures_model->insert($lastMessage[0]['id'], $contentUrl); } else { $this->Post_model->insert($this->getUserId(), $this->subdomainId, date("Y-m-d H:i"), 'picture', $contentUrl, NULL, NULL); } $this->load->view('member_post_picture_success', $_data); $sitedata = $this->Site_model->getById($this->subdomainId); $users = $this->User_is_member_of_site_model->getList(0, 0, array('subscribe_y_n' => 1, 'site_id' => $this->subdomainId), '', array('table' => 'users', 'field1' => 'id', 'field2' => 'user_id')); foreach ($users as $user) { $this->_sendemail('newpost', array('sitename' => $sitedata['name'], 'subdomain' => $sitedata['subdomain'], 'email' => $user['email'])); } @unlink($uploadfile); } } }
function UploadPhoto($gp, $filename, $AlbumName) { $BaseName = basename($filename); $extention = file_ext($BaseName); $photoName = str_replace(".{$extention}", "", $BaseName); $photoName = str_replace("_", " ", $photoName); $photoName = str_replace("-", " ", $photoName); $date = date('Y-m-d H:i'); $photoCaption = "Uploaded on {$date}"; $last_modified = filemtime($filename); $photoTags = date("Y-m-d", $last_modified); // We use the albumId of 'default' to indicate that we'd like to upload // this photo into the 'drop box'. This drop box album is automatically // created if it does not already exist. // if ($AlbumName == "default") { $albumId = "default"; } $exts["jpg"] = "image/jpeg"; $exts["gif"] = "image/gif"; $exts["bmp"] = "image/bmp"; $exts["psd"] = "application/photoshop"; $exts["avi"] = "video/x-msvideo"; $exts["mov"] = "video/quicktime"; $exts["mpg"] = "video/mpeg"; $exts["wmv"] = "video/x-ms-wmv"; $exts["asf"] = "video/x-ms-asf"; $exts["tif"] = "image/tiff"; $exts["png"] = "image/png"; $fd = $gp->newMediaFileSource($filename); $fd->setContentType($exts[$extention]); // Create a PhotoEntry $photoEntry = $gp->newPhotoEntry(); $photoEntry->setMediaSource($fd); events("{$BaseName}: title: {$photoName}", __FUNCTION__, __FILE__, __LINE__); $photoEntry->setTitle($gp->newTitle($photoName)); $photoEntry->setSummary($gp->newSummary($photoCaption)); // add some tags $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); $keywords->setText($photoTags); $photoEntry->mediaGroup = new Zend_Gdata_Media_Extension_MediaGroup(); $photoEntry->mediaGroup->keywords = $keywords; $albumQuery = $gp->newAlbumQuery(); //$albumQuery->setUser("David Touzeau"); if ($albumId != null) { $albumQuery->setAlbumId($albumId); } else { $albumQuery->setAlbumName($AlbumName); } // try { $insertedEntry = $gp->insertPhotoEntry($photoEntry, $albumQuery->getQueryUrl()); } catch (Zend_Gdata_App_HttpException $e) { events("Error: Zend_Gdata_App_HttpException:: " . $e->getMessage(), __FUNCTION__, __FILE__, __LINE__); return false; } catch (Zend_Uri_Exception $e) { events("Error: Zend_Uri_Exception:: " . $e->getMessage(), __FUNCTION__, __FILE__, __LINE__); return false; } return true; }