Esempio n. 1
0
 public function load($url, $parameters = null)
 {
     require_once __DIR__ . '/../../../../../vendor/phpflickr/lib/Phpflickr/Phpflickr.php';
     if (isset($parameters["photo_id"])) {
         $itemId = $parameters["photo_id"];
     } else {
         $regexMatches = $parameters["regex_matches"];
         $itemId = $regexMatches[1];
         // bam
     }
     $f = new \Phpflickr_Phpflickr('97ac5e379fbf4df38a357f9c0943e140');
     $info = $f->photos_getInfo($itemId);
     $size = $f->photos_getSizes($itemId);
     if (is_array($info) && is_array($size)) {
         $item = new Item();
         $tags = array();
         $item->setAttributionUri($info['urls']['url'][0]['_content']);
         if ($info['tags']) {
             $tags = array();
             foreach ($info['tags']['tag'] as $t) {
                 array_push($tags, $t["raw"]);
             }
             $item->setTags($tags);
         }
         foreach ($size as $s) {
             $sizes[$s['label']] = array('width' => $s['width'], 'height' => $s['height'], 'source' => $s['source']);
         }
         //return $sizes;
         $attr = array('farm' => $info['farm'], 'server' => $info['server'], 'id' => $info['id'], 'secret' => $info['secret']);
         if (isset($sizes['Original'])) {
             $attr['originalsecret'] = $info['originalsecret'];
         }
         if (isset($sizes['Large'])) {
             $itemSize = 'Large';
         } elseif (isset($sizes['Original'])) {
             $itemSize = 'Original';
         } elseif (isset($sizes['Medium 800'])) {
             $itemSize = 'Medium 800';
         } elseif (isset($sizes['Medium 640'])) {
             $itemSize = 'Medium 640';
         } elseif (isset($sizes['Medium'])) {
             $itemSize = 'Medium';
         } elseif (isset($sizes['Small 320'])) {
             $itemSize = 'Small 320';
         } else {
             $itemSize = 'Small';
         }
         if (isset($sizes['Medium'])) {
             $thumbSize = 'Medium';
         } elseif (isset($sizes['Small 320'])) {
             $thumbSize = 'Small 320';
         } else {
             $thumbSize = 'Small';
         }
         $item->setThumbnailUrl($sizes[$thumbSize]['source']);
         if ($info['dates']['taken']) {
             $item->setMediaDateCreated(new DateTime($info['dates']['taken']));
         }
         $item->setUri($sizes[$itemSize]['source']);
         $item->setChildItemsCount(0);
         $attr['sizes'] = $sizes;
         $item->setDescription($info['description']);
         if ($info['license']) {
             $item->setLicense(self::$license[$info['license']]);
         } else {
             $item->setLicense('All Rights Reserved');
         }
         if ($info['owner']['username']) {
             $item->setMediaCreatorUsername($info['owner']['username']);
         } else {
             $item->setMediaCreatorUsername($info['owner']['realname']);
         }
         if ($info['owner']['realname']) {
             $item->setMediaCreatorRealname($info['owner']['realname']);
         } else {
             $item->setMediaCreatorRealname($item->getMediaCreatorUsername());
         }
         $attr['creator_nsid'] = $info['owner']['nsid'];
         $item->setTitle($info['title']);
         if (array_key_exists('location', $info)) {
             if ($info['location']['latitude']) {
                 $item->setMediaGeoLatitude($info['location']['latitude']);
                 $item->setMediaGeoLongitude($info['location']['longitude']);
             }
         }
         $item->setArchive('Flickr');
         $item->setMediaType('Image');
         $item->setLayerType('Image');
         return $this->returnResponse($item, true, false);
     } else {
         return $this->returnResponse(null, false, false);
     }
 }
Esempio n. 2
0
 public function load($url, $parameters = null)
 {
     require_once __DIR__ . '/../../../../../vendor/phpflickr/lib/Phpflickr/Phpflickr.php';
     $loadCollectionItems = $parameters["load_child_items"];
     $regexMatches = $parameters["regex_matches"];
     $setId = $regexMatches[1];
     // bam
     $f = new \Phpflickr_Phpflickr('97ac5e379fbf4df38a357f9c0943e140');
     $setInfo = $f->photosets_getInfo($setId);
     $collection = new Item();
     $ownerInfo = $f->people_getInfo($setInfo["owner"]);
     $collection->setTitle($setInfo["title"]);
     $collection->setDescription($setInfo["description"]);
     $collection->setMediaType('Collection');
     $collection->setLayerType('Flickr');
     $collection->setArchive('Flickr');
     $collection->setAttributionUri($url);
     $collection->setChildItemsCount($setInfo["count_photos"]);
     $collection->setMediaCreatorUsername($ownerInfo["path_alias"]);
     $collection->setMediaCreatorRealname($ownerInfo["username"]);
     $collection->setMediaDateCreated(new \DateTime());
     if (isset($setInfo["primary"])) {
         $size = $f->photos_getSizes($setInfo["primary"]);
         foreach ($size as $s) {
             $sizes[$s['label']] = array('width' => $s['width'], 'height' => $s['height'], 'source' => $s['source']);
         }
     }
     $collection->setThumbnailUrl($sizes['Square']['source']);
     if (isset($sizes['Large'])) {
         $itemSize = 'Large';
     } elseif (isset($sizes['Original'])) {
         $itemSize = 'Original';
     } elseif (isset($sizes['Medium'])) {
         $itemSize = 'Medium';
     } else {
         $itemSize = 'Small';
     }
     $collection->setUri($sizes[$itemSize]['source']);
     if ($loadCollectionItems == true) {
         $page = 1;
         while (1) {
             $setPhotos = $f->photosets_getPhotos($setId, null, null, 500, $page);
             $photos = $setPhotos['photoset']['photo'];
             if (null !== $photos) {
                 $ownerInfo = $f->people_getInfo($setInfo["owner"]);
                 $collection->setChildItemsCount(count($photos));
                 foreach ($photos as $photo) {
                     $item = $this->itemParser->load(null, array("photo_id" => $photo['id']));
                     if (isset($item)) {
                         $collection->addChildItem($item["items"][0]);
                     }
                 }
             } else {
                 break;
             }
             if ($page > 10) {
                 break;
             }
             ++$page;
         }
     }
     return parent::returnResponse($collection, true, true);
 }