/** @return void */ protected function loadInfo() { $res = FlickrService::$instance->call('flickr.photosets.getInfo', array('photoset_id' => $this->id)); $n =& $res->dom['photoset'][0]; $a =& $n['@']; $this->owner = FlickrUser::findById($a['owner']); $this->primary = FlickrPhoto::findById($a['primary']); $this->secret = $a['secret']; $this->server = $a['server']; $this->photo_count = $a['photos']; $this->title = $n['title'][0]['#']; $this->description = $n['description'][0]['#']; }
/** * Returns all photos within a given photoset. * * @param int $photosetId * @param int|null $userId Optional, but API will respond faster if this is specified * @return ArrayList<FlickrPhoto> */ public function getPhotosInPhotoset($photosetId, $userId = null) { if (!$this->isAPIAvailable()) { return null; } $params = array('method' => 'flickr.photosets.getPhotos', 'photoset_id' => $photosetId, 'extras' => 'description,original_format'); if ($userId) { $params['user_id'] = $userId; } $this->setQueryString(array_merge($this->defaultParams(), $params)); try { $rawResponse = $this->request()->getBody(); $response = unserialize($rawResponse); if (!$response || !isset($response['stat']) || $response['stat'] !== 'ok') { throw new Exception(sprintf("Response from Flickr not expected: %s", var_export($rawResponse, true))); } $results = new ArrayList(); foreach ($response['photoset']['photo'] as $photo) { $obj = FlickrPhoto::create_from_array($photo); if ($obj) { $results->push($obj); } } return $results; } catch (Exception $e) { if (!$this->config()->skip_error_logging) { SS_Log::log(sprintf("Couldn't retrieve Flickr photos in photoset '%s' for optional user '%s'", $photosetId, $userId), SS_Log::ERR); } return null; } }
private function createFromFlickrArray($value, $only_new_photos = false) { gc_collect_cycles(); $flickrPhotoID = $value['id']; // the author, e.g. gordonbanderson $pathalias = $value['pathalias']; // do we have a set object or not $flickrPhoto = DataObject::get_one('FlickrPhoto', 'FlickrID=' . $flickrPhotoID); // if a set exists update data, otherwise create if (!$flickrPhoto) { $flickrPhoto = new FlickrPhoto(); } else { if ($only_new_photos) { continue; } } $flickrPhoto->Title = $value['title']; $flickrPhoto->FlickrID = $flickrPhotoID; $flickrPhoto->KeepClean = true; $flickrPhoto->MediumURL = $value['url_m']; $flickrPhoto->MediumHeight = $value['height_m']; $flickrPhoto->MediumWidth = $value['width_m']; $flickrPhoto->SquareURL = $value['url_s']; $flickrPhoto->SquareHeight = $value['height_s']; $flickrPhoto->SquareWidth = $value['width_s']; $flickrPhoto->ThumbnailURL = $value['url_t']; $flickrPhoto->ThumbnailHeight = $value['height_t']; $flickrPhoto->ThumbnailWidth = $value['width_t']; $flickrPhoto->SmallURL = $value['url_s']; $flickrPhoto->SmallHeight = $value['height_s']; $flickrPhoto->SmallWidth = $value['width_s']; // If the image is too small, large size will not be set if (isset($value['url_l'])) { $flickrPhoto->LargeURL = $value['url_l']; $flickrPhoto->LargeHeight = $value['height_l']; $flickrPhoto->LargeWidth = $value['width_l']; } $flickrPhoto->OriginalURL = $value['url_o']; $flickrPhoto->OriginalHeight = $value['height_o']; $flickrPhoto->OriginalWidth = $value['width_o']; $flickrPhoto->Description = 'test'; // $value['description']['_content']; $author = FlickrAuthor::get()->filter('PathAlias', $pathalias)->first(); if (!$author) { $author = new FlickrAuthor(); $author->PathAlias = $pathalias; $author->write(); } $flickrPhoto->PhotographerID = $author->ID; $lat = number_format($value['latitude'], 15); $lon = number_format($value['longitude'], 15); if ($value['latitude']) { $flickrPhoto->Lat = $lat; $flickrPhoto->ZoomLevel = 15; } if ($value['longitude']) { $flickrPhoto->Lon = $lon; } if ($value['accuracy']) { $flickrPhoto->Accuracy = $value['accuracy']; } if (isset($value['geo_is_public'])) { $flickrPhoto->GeoIsPublic = $value['geo_is_public']; } if (isset($value['woeid'])) { $flickrPhoto->WoeID = $value['woeid']; } $singlePhotoInfo = $this->f->photos_getInfo($flickrPhotoID); $flickrPhoto->Description = $singlePhotoInfo['photo']['description']['_content']; $flickrPhoto->TakenAt = $singlePhotoInfo['photo']['dates']['taken']; $flickrPhoto->Rotation = $singlePhotoInfo['photo']['rotation']; if (isset($singlePhotoInfo['photo']['visibility'])) { $flickrPhoto->IsPublic = $singlePhotoInfo['photo']['visibility']['ispublic']; } $flickrPhoto->write(); foreach ($singlePhotoInfo['photo']['tags']['tag'] as $key => $taginfo) { $tag = DataObject::get_one('FlickrTag', "\"Value\"='" . $taginfo['_content'] . "'"); if (!$tag) { $tag = new FlickrTag(); } $tag->FlickrID = $taginfo['id']; $tag->Value = $taginfo['_content']; $tag->RawValue = $taginfo['raw']; $tag->write(); $ftags = $flickrPhoto->FlickrTags(); $ftags->add($tag); $flickrPhoto->write(); $tag = NULL; $ftags = NULL; gc_collect_cycles(); } return $flickrPhoto; }
/** * @param array * @return FlickrPhoto[] */ public static function valueOfCollection(&$a) { $photo_count = count($a); $photos = array(); for ($i = 0; $i < $photo_count; $i++) { $photos[] = FlickrPhoto::valueOf($a[$i]); } return $photos; }
public function __construct($per_page = 10, $page = 1, $nsid) { $response = Flickr::call(array( 'method' => 'flickr.people.getPublicPhotos', 'page' => $page, 'per_page' => $per_page, 'user_id' => $nsid, 'extras' => 'date_taken,date_upload,original_format,tags,license' )); $this->_photos = array(); foreach($response['photos']['photo'] as $args) { $this->_photos[] = FlickrPhoto::withPublic($args); } $this->_page = $response['photos']['page']; $this->_page = $response['photos']['page']; $this->_pages = $response['photos']['pages']; $this->_perpage = $response['photos']['perpage']; $this->_total = $response['photos']['total']; }
/** * @param int Number of photos to return per page. If this argument is omitted, it defaults to 100. * The maximum allowed value is 500. * * @param int The page of results to return. If this argument is omitted, it defaults to 1. * * @param string A comma-delimited list of extra information to fetch for each returned record. * Currently supported fields are: license, date_upload, date_taken, owner_name, * icon_server, original_format, last_update. * * @return FlickrPhoto[] */ public function getPublicPhotos($per_page = 100, $page = 1) { $res = FlickrService::$instance->call('flickr.people.getPublicPhotos', array('user_id' => $this->id, 'per_page' => $per_page, 'page' => $page, 'extras' => FlickrPhoto::$std_extras)); return FlickrPhoto::valueOfCollection($res->dom['photos'][0]['photo']); }