Example #1
0
 public function singlePhoto($id)
 {
     $photoInfo = $this->request('flickr.photos.getInfo', array('photo_id' => $id));
     //print_r($photoInfo);
     echo "  " . $photoInfo->photo->id . " -- " . $photoInfo->photo->title->_content . "\n";
     // Compile required info.
     $dateTaken = $photoInfo->photo->dates->taken;
     $description = '';
     if ($photoInfo->photo->description->_content) {
         $description = trim($photoInfo->photo->description->_content, ' .') . '.';
     }
     $photoDatum = array('id' => $id, 'user_id' => $photoInfo->photo->owner->nsid, 'date_taken_value' => $dateTaken, 'granularity' => $photoInfo->photo->dates->takengranularity, 'date_taken' => Latex::flickrDate($dateTaken, $photoInfo->photo->dates->takengranularity), 'title' => trim($photoInfo->photo->title->_content, '.') . '.', 'description' => $description, 'tags' => array());
     foreach ($photoInfo->photo->tags->tag as $tag) {
         $photoDatum['tags'][] = $tag->raw;
     }
     $localDir = $this->dataDir . "/photos/{$id}";
     if (!is_dir($localDir)) {
         mkdir($localDir, 0755, true);
     }
     // Download files.
     $farm = $photoInfo->photo->farm;
     $server = $photoInfo->photo->server;
     $scrt = $photoInfo->photo->secret;
     // Original?
     if (isset($photoInfo->photo->originalsecret)) {
         $origScrt = $photoInfo->photo->originalsecret;
         $origFmt = $photoInfo->photo->originalformat;
         $origUrl = 'https://farm' . $farm . '.staticflickr.com/' . $server . '/' . $id . '_' . $origScrt . '_o.' . $origFmt;
         if (!file_exists($localDir . '/original.' . $origFmt)) {
             file_put_contents($localDir . '/original.' . $origFmt, file_get_contents($origUrl));
         }
     }
     // Medium. https://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg
     $medUrl = 'https://farm' . $farm . '.staticflickr.com/' . $server . '/' . $id . '_' . $scrt . '_c.jpg';
     if (!file_exists($localDir . '/medium.jpg')) {
         file_put_contents($localDir . '/medium.jpg', file_get_contents($medUrl));
     }
     // Metadata.
     $metadata = Yaml::dump($photoDatum);
     file_put_contents($localDir . '/metadata.yml', $metadata);
     return $photoDatum;
 }