Ejemplo n.º 1
0
 public function load($url, $parameters = null)
 {
     require_once __DIR__ . '/../../../../../vendor/phpflickr/lib/Phpflickr/Phpflickr.php';
     $flickrAuthenticationKey = $parameters["authentication_key"];
     $loadCollectionItems = $parameters["load_child_items"];
     $checkForDuplicates = (bool) $parameters["check_for_duplicates"];
     $tags = $parameters["tags"];
     $user = $parameters["user"];
     $originalItems = null;
     $searchParameters = array("tags" => $tags, "tag_mode" => "any", "extras" => "path_alias, description, license, date_upload, date_taken, owner_name, geo, tags, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o", "page" => 1, "per_page" => 500);
     if (FALSE !== $checkForDuplicates) {
         $em = $parameters["entityManager"];
         $originalItems = $em->getRepository('ZeegaDataBundle:Item')->findUriByUserArchive($user->getId(), "Flickr");
         if (isset($originalItems)) {
             $checkForDuplicates = TRUE;
         } else {
             $checkForDuplicates = FALSE;
         }
     } else {
         $checkForDuplicates = FALSE;
     }
     $f = new \Phpflickr_Phpflickr("97ac5e379fbf4df38a357f9c0943e140");
     $currentPage = 1;
     $items = array();
     while (1) {
         $searchParameters["page"] = $currentPage;
         $searchResults = $f->photos_search($searchParameters);
         $photos = $searchResults['photo'];
         $pages = $searchResults['pages'];
         foreach ($photos as $photo) {
             $item = new Item();
             $tags = array();
             if (isset($photo['tags'])) {
                 $item->setTags(explode(" ", $photo['tags']));
             }
             if (isset($photo['datetaken'])) {
                 $item->setMediaDateCreated(new DateTime($photo['datetaken']));
             }
             if (isset($photo['ownername'])) {
                 $item->setMediaCreatorUsername($photo['ownername']);
             }
             if (isset($photo['latitude'])) {
                 $item->setMediaGeoLatitude($photo['latitude']);
             }
             if (isset($photo['longitude'])) {
                 $item->setMediaGeoLongitude($photo['longitude']);
             }
             if (isset($photo['license'])) {
                 $item->setLicense(self::$license[$photo['license']]);
             } else {
                 $item->setLicense('All Rights Reserved');
             }
             if (isset($photo["url_l"])) {
                 $item->setUri($photo['url_l']);
             } else {
                 if (isset($photo["url_o"])) {
                     $item->setUri($photo['url_o']);
                 } else {
                     if (isset($photo["url_m"])) {
                         $item->setUri($photo['url_m']);
                     } else {
                         $item->setUri($photo['url_s']);
                     }
                 }
             }
             if (isset($photo["description"])) {
                 $item->setDescription($photo['description']);
             }
             $item->setTitle($photo['title']);
             $item->setAttributionUri("http://www.flickr.com/photos/" . $photo["owner"] . "/" . $photo["id"]);
             $item->setArchive('Flickr');
             $item->setMediaType('Image');
             $item->setLayerType('Image');
             $item->setChildItemsCount(0);
             if (TRUE === $checkForDuplicates) {
                 if (FALSE === array_key_exists($item->getUri(), $originalItems)) {
                     array_push($items, $item);
                 }
             } else {
                 array_push($items, $item);
             }
             if (true !== $loadCollectionItems) {
                 return parent::returnResponse($items, true, true);
             }
         }
         if ($currentPage++ > $pages || $currentPage > 10) {
             break;
         }
     }
     return parent::returnResponse($items, true, true);
 }
Ejemplo n.º 2
0
 public function load($url, $parameters = null)
 {
     $tags = $parameters["tags"];
     $user = $parameters["user"];
     $checkForDuplicates = (bool) $parameters["check_for_duplicates"];
     $apiUrl = "https://gdata.youtube.com/feeds/api/videos?alt=json&v=2&category={$tags}";
     // read feed into SimpleXML object
     $videoList = json_decode(file_get_contents($apiUrl), true);
     $videos = $videoList["feed"];
     $items = array();
     if (FALSE !== $checkForDuplicates) {
         $em = $parameters["entityManager"];
         $originalItems = $em->getRepository('ZeegaDataBundle:Item')->findUriByUserArchive($user->getId(), "Youtube");
         if (isset($originalItems)) {
             $checkForDuplicates = TRUE;
         } else {
             $checkForDuplicates = FALSE;
         }
     } else {
         $checkForDuplicates = FALSE;
     }
     foreach ($videos["entry"] as $video) {
         $accessControl = $video["yt\$accessControl"];
         foreach ($accessControl as $access) {
             if ($access["action"] !== "embed" || $access["permission"] !== "allowed") {
                 if (TRUE === $checkForDuplicates) {
                     if (TRUE === array_key_exists($video["media\$group"]["yt\$videoid"]["\$t"], $originalItems)) {
                         break;
                     }
                 }
                 $item = new Item();
                 $item->setUri($video["media\$group"]["yt\$videoid"]["\$t"]);
                 $item->setTitle($video["title"]["\$t"]);
                 $item->setDescription($video["media\$group"]["media\$description"]["\$t"]);
                 $item->setAttributionUri($video["media\$group"]["media\$player"]["url"]);
                 $item->setMediaDateCreated($video["published"]["\$t"]);
                 $item->setDateCreated(new \DateTime("now"));
                 $item->setMediaType('Video');
                 $item->setLayerType('Youtube');
                 $item->setChildItemsCount(0);
                 $item->setThumbnailUrl($video["media\$group"]["media\$thumbnail"][2]["url"]);
                 $item->setArchive("Youtube");
                 $categories = $video["category"];
                 if (isset($categories)) {
                     $itemTags = array();
                     foreach ($categories as $cat) {
                         if (strpos($cat["term"], 'gdata.youtube.com') === false) {
                             array_push($itemTags, $cat["term"]);
                         }
                     }
                     $item->setTags($itemTags);
                 }
                 $item->setMediaCreatorUsername($video["author"][0]["name"]["\$t"]);
                 $item->setMediaCreatorRealname($video["author"][0]["name"]["\$t"]);
                 $item->setLicense($video["media\$group"]["media\$license"]["\$t"]);
                 array_push($items, $item);
                 break;
             }
         }
     }
     return parent::returnResponse($items, true, true);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $loadCollectionItems = $parameters["load_child_items"];
     $setId = $regexMatches[1];
     // bam
     if (strpos($setId, 'PL') === 0) {
         $setId = substr($setId, 2);
     }
     // apparently the playlist ID changed... need to remove the PL prefix.
     $originalUrl = "http://gdata.youtube.com/feeds/api/playlists/{$setId}?v=2&alt=json&max_results=50";
     // read feed into SimpleXML object
     $playlistInfo = json_decode(file_get_contents($originalUrl), true);
     $entry = $playlistInfo["feed"];
     $collection = new Item();
     $collection->setTitle($entry["title"]["\$t"]);
     $collection->setArchive("Youtube");
     $collection->setDescription($entry["subtitle"]["\$t"]);
     $collection->setMediaType('Collection');
     $collection->setLayerType('Youtube');
     $collection->setUri($url);
     $collection->setAttributionUri($entry["media\$group"]["media\$content"][0]["url"]);
     $collection->setEnabled(true);
     $collection->setPublished(true);
     $collection->setChildItemsCount($entry["openSearch\$totalResults"]["\$t"]);
     $collection->setMediaCreatorUsername($entry["author"][0]["name"]["\$t"]);
     $collection->setMediaCreatorRealname('Unknown');
     foreach ($entry["entry"] as $child) {
         $collection->setThumbnailUrl($child["media\$group"]["media\$thumbnail"][0]["url"]);
         if ($loadCollectionItems == false) {
             // we just want the set description - get a thumbnail from the first item and break
             break;
         }
         $item = new Item();
         $item->setUri($child["media\$group"]["yt\$videoid"]["\$t"]);
         $item->setTitle($child["title"]["\$t"]);
         $item->setDescription($child["media\$group"]["media\$description"]["\$t"]);
         $item->setAttributionUri($child["media\$group"]["media\$player"]["url"]);
         $item->setMediaDateCreated($child["published"]["\$t"]);
         $item->setDateCreated(new \DateTime("now"));
         $item->setMediaType('Video');
         $item->setLayerType('Youtube');
         $item->setChildItemsCount(0);
         $item->setThumbnailUrl($child["media\$group"]["media\$thumbnail"][0]["url"]);
         $item->setArchive("Youtube");
         $categories = $child["category"];
         if (isset($categories)) {
             $itemTags = array();
             foreach ($categories as $cat) {
                 if (strpos($cat["term"], 'gdata.youtube.com') === false) {
                     array_push($itemTags, $cat["term"]);
                 }
             }
             $item->setTags($itemTags);
         }
         $item->setMediaCreatorUsername($child["author"][0]["name"]["\$t"]);
         $item->setMediaCreatorRealname($child["author"][0]["name"]["\$t"]);
         $item->setLicense($child["media\$group"]["media\$license"]["\$t"]);
         $accessControl = $child["yt\$accessControl"];
         foreach ($accessControl as $access) {
             if ($access["action"] == "embed" && $access["permission"] == "allowed") {
                 $collection->addChildItem($item);
             }
         }
     }
     return parent::returnResponse($collection, true, true);
 }