/** * Get the photo from the provider * @since Version 3.9 * @param int $id The ID of the photo from the provider * @return array */ public function getPhoto($id) { $mckey = sprintf("railpage:railcam.provider=%s;railcam.image=%d", self::PROVIDER_NAME, $id); if ($this->photo = $this->Memcached->fetch($mckey)) { return $this->photo; } else { $return = array(); if ($return = $this->cn->photos_getInfo($id)) { $return['photo']['sizes'] = $this->cn->photos_getSizes($id); } /** * Transform Flickr's result into our standard data format */ $this->photo = array("provider" => self::PROVIDER_NAME, "id" => $id, "dates" => array("taken" => new DateTime($return['photo']['dates']['taken']), "uploaded" => 0, "updated" => 0), "author" => array("id" => $return['photo']['owner']['nsid'], "username" => $return['photo']['owner']['username'], "realname" => $return['photo']['owner']['realname'], "url" => new Url(sprintf("https://www.flickr.com/photos/%s", $return['photo']['owner']['nsid']))), "title" => $return['photo']['title'], "description" => $return['photo']['description'], "tags" => $return['photo']['tags']['tag'], "sizes" => $return['photo']['sizes']); if (isset($return['photo']['dateuploaded'])) { $this->photo['dates']['uploaded'] = new DateTime(sprintf("@%s", $return['photo']['dateuploaded'])); } if (isset($return['photo']['lastupdate'])) { $this->photo['dates']['updated'] = new DateTime(sprintf("@%s", $return['photo']['lastupdate'])); } $this->Memcached->save($mckey, $this->photo, strtotime("+2 days")); return $this->photo; } }
/** * Get photo info and sizes * @since Version 3.5 * @param int $photo_id * @return array */ public function getPhoto($photo_id = false) { if (!$photo_id) { throw new Exception("Cannot fetch photo info and sizes - no photo ID given"); return false; } $mckey = "railpage:railcam.photo.id=" . $photo_id; deleteMemcacheObject($mckey); if ($return = getMemcacheObject($mckey)) { $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']); return $return; } else { $f = new \flickr_railpage(RP_FLICKR_API_KEY); $f->oauth_token = $this->flickr_oauth_token; $f->oauth_secret = $this->flickr_oauth_secret; $f->cache = false; $return = array(); if ($return = $f->photos_getInfo($photo_id)) { $return['photo']['sizes'] = $f->photos_getSizes($photo_id); $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']); setMemcacheObject($mckey, $return, strtotime("+2 hours")); } return $return; } }