예제 #1
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $itemId = $regexMatches[1];
     // bam
     $info = explode('/map/', $itemId);
     $originalUrl = 'http://api.tiles.mapbox.com/v2/' . $info[0] . '.' . $info[1] . '.json';
     // read feed into SimpleXML object
     $entry = json_decode(file_get_contents($originalUrl));
     $item = new Item();
     $item->setUri((string) $entry->id);
     $item->setTitle((string) $entry->name);
     $item->setAttributionUri((string) $entry->webpage);
     $item->setDateCreated(new \DateTime("now"));
     $item->setMediaType('Map');
     $item->setLayerType('Mapbox');
     $item->setChildItemsCount(0);
     $center = (array) $entry->center;
     $item->setMediaGeoLatitude((string) $center[1]);
     $item->setMediaGeoLongitude((string) $center[0]);
     $item->setAttributes(array('zoom' => (string) $center[2], 'maxzoom' => (string) $entry->maxzoom, 'minzoom' => (string) $entry->minzoom));
     $item->setMediaCreatorUsername((string) $info[0]);
     $item->setMediaCreatorRealname('Unknown');
     $thumbnailUrl = (string) 'http://api.tiles.mapbox.com/v2/' . $info[0] . '.' . $info[1] . '/thumb.png';
     // write metadata
     $item->setArchive('Mapbox');
     $item->setLicense('Unknown');
     $item->setThumbnailUrl($thumbnailUrl);
     $item->setThumbnailUrl($thumbnailUrl);
     return $this->returnResponse($item, true, false);
 }
예제 #2
0
 public function load($url, $parameters = null)
 {
     if (isset($parameters)) {
         if (isset($parameters["regex_matches"][1])) {
             $id = $parameters["regex_matches"][1];
             $embedApiUrl = "http://giphy.com/api/v1/gifs/{$id}";
             $embedInfo = file_get_contents($embedApiUrl, 0, null, null);
             $mediaDetails = json_decode($embedInfo, true);
             if (null != $mediaDetails) {
                 $id = $mediaDetails["id"];
                 $item = new Item();
                 $item->setMediaCreatorUsername("Unknown");
                 $item->setMediaCreatorRealname("Unknown");
                 $item->setMediaType('Image');
                 $item->setLayerType('Image');
                 $item->setArchive('Giphy');
                 $item->setUri($mediaDetails['image_url']);
                 $item->setAttributionUri($mediaDetails['bitly_gif_url']);
                 if (isset($mediaDetails['date'])) {
                     $item->setMediaDateCreated(DateTime::createFromFormat('U', $mediaDetails['date']));
                 } else {
                     if (isset($mediaDetails['tumblr_date'])) {
                         $item->setMediaDateCreated(DateTime::createFromFormat('U', $mediaDetails['tumblr_date']));
                     }
                 }
                 $item->setThumbnailUrl($mediaDetails['image_fixed_width_still_url']);
                 $tags = $mediaDetails["tags"];
                 if (isset($tags)) {
                     $itemTags = array();
                     $first = true;
                     foreach ($tags as $tag) {
                         $itemTags[] = $tag["name_encoded"];
                         if ($first) {
                             $item->setTitle($tag["name"]);
                             $first = false;
                         }
                     }
                     $item->setTags($itemTags);
                 }
                 $item->setTitle("#" . implode($itemTags, " #"));
                 if ((int) $mediaDetails["image_fixed_width_still_width"] > 200 || (int) $mediaDetails["image_fixed_width_still_height"] > 200) {
                     $item->setThumbnailUrl($mediaDetails["image_fixed_height_still_url"]);
                     $animateUrl = $mediaDetails["image_fixed_height_url"];
                     $width = (int) $mediaDetails["image_fixed_height_still_width"];
                     $height = (int) $mediaDetails["image_fixed_height_still_height"];
                 } else {
                     $item->setThumbnailUrl($mediaDetails["image_fixed_width_still_url"]);
                     $animateUrl = $mediaDetails["image_fixed_width_url"];
                     $width = (int) $mediaDetails["image_fixed_width_still_width"];
                     $height = (int) $mediaDetails["image_fixed_width_still_height"];
                 }
                 $item->setAttributes(array("id" => $mediaDetails["id"], "width" => $width, "height" => $height, "animate_url" => $animateUrl));
                 return $this->returnResponse(array($item), true, false);
             }
         }
     }
     return $this->returnResponse(array(), false, true, $kale);
 }
예제 #3
0
 public function load($url, $parameters = null)
 {
     if (isset($parameters)) {
         if (isset($parameters["regex_matches"][1])) {
             $tag = $parameters["regex_matches"][1];
             //$embedApiUrl = "http://giphy.com/api/gifs?tag=$tag&page=1&size=50";
             if ($parameters["regex_matches"][2]) {
                 $offset = $parameters["regex_matches"][2];
                 $embedApiUrl = "http://api.giphy.com/v1/gifs/search?q={$tag}&api_key=Uy5fohPTSnze8&offset={$offset}&limit=50";
             } else {
                 $embedApiUrl = "http://api.giphy.com/v1/gifs/search?q={$tag}&api_key=Uy5fohPTSnze8&limit=50";
             }
             $embedInfo = file_get_contents($embedApiUrl, 0, null, null);
             $embedInfo = json_decode($embedInfo, true);
             $items = array();
             if ($embedInfo["pagination"]["total_count"] > $embedInfo["pagination"]["offset"] + $embedInfo["pagination"]["count"]) {
                 $more = true;
             } else {
                 $more = false;
             }
             if (null != $embedInfo && isset($embedInfo["data"])) {
                 $itemsJson = $embedInfo["data"];
                 foreach ($itemsJson as $itemJson) {
                     $id = $itemJson["id"];
                     $item = new Item();
                     $item->setMediaCreatorUsername("Unknown");
                     $item->setMediaCreatorRealname("Unknown");
                     $item->setMediaType("Image");
                     $item->setLayerType("Image");
                     $item->setArchive("Giphy");
                     $item->setUri($itemJson["images"]["original"]["url"]);
                     $item->setAttributionUri($itemJson["bitly_gif_url"]);
                     $title = "#" . implode(" #", $itemJson["tags"]);
                     $item->setTitle($title);
                     if ((int) $itemJson["images"]["fixed_width_still"]["width"] > 200 || (int) $itemJson["images"]["fixed_width_still"]["height"] > 200) {
                         $item->setThumbnailUrl($itemJson["images"]["fixed_height_still"]["url"]);
                         $width = (int) $itemJson["images"]["fixed_height_still"]["width"];
                         $height = (int) $itemJson["images"]["fixed_height_still"]["height"];
                     } else {
                         $item->setThumbnailUrl($itemJson["images"]["fixed_width_still"]["url"]);
                         $width = (int) $itemJson["images"]["fixed_width_still"]["width"];
                         $height = (int) $itemJson["images"]["fixed_width_still"]["height"];
                     }
                     $item->setAttributes(array("id" => $id, "width" => $width, "height" => $height));
                     array_push($items, $item);
                 }
             }
         }
     }
     return $this->returnResponse($items, true, true, "", $more);
 }
예제 #4
0
 public function load($url, $parameters = null)
 {
     if (isset($parameters)) {
         if (isset($parameters["regex_matches"][1])) {
             $userName = $parameters["regex_matches"][1];
             $userUrl = "https://api.instagram.com/v1/users/search?q={$userName}&access_token=1907240.f59def8.6a53e4264d87413a8e8cd431430b6e94";
             $userInfo = file_get_contents($userUrl, 0, null, null);
             $userInfo = json_decode($userInfo, true);
             if (null != $userInfo) {
                 $userId = $userInfo["data"][0]["id"];
                 $photoUrl = "https://api.instagram.com/v1/users/{$userId}/media/recent?access_token=1907240.f59def8.6a53e4264d87413a8e8cd431430b6e94";
                 $photoInfo = file_get_contents($photoUrl, 0, null, null);
                 $photoInfo = json_decode($photoInfo, true);
                 $items = array();
                 if (null != $photoInfo && isset($photoInfo["data"])) {
                     $itemsJson = $photoInfo["data"];
                     foreach ($itemsJson as $itemJson) {
                         $item = new Item();
                         $item->setMediaCreatorUsername($itemJson["user"]["username"]);
                         $item->setMediaCreatorRealname($itemJson["user"]["username"]);
                         $item->setMediaType("Image");
                         $item->setLayerType("Image");
                         $item->setArchive("Instagram");
                         $item->setUri($itemJson["images"]["standard_resolution"]["url"]);
                         $item->setAttributionUri($url);
                         $item->setThumbnailUrl($itemJson["images"]["low_resolution"]["url"]);
                         array_push($items, $item);
                     }
                 }
             }
         }
     }
     return $this->returnResponse($items, true, true);
 }
예제 #5
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $itemId = $regexMatches[1];
     // bam
     $originalUrl = 'https://www.googleapis.com/books/v1/volumes/' . $itemId;
     // read feed into SimpleXML object
     $entry = json_decode(file_get_contents($originalUrl), true);
     $volume = $entry["volumeInfo"];
     $authors = $volume["authors"];
     $item = new Item();
     $item->setUri($entry["accessInfo"]["webReaderLink"]);
     $item->setTitle($volume["title"]);
     $item->setAttributionUri($volume["infoLink"]);
     $item->setDateCreated(new \DateTime("now"));
     $item->setMediaType('GoogleBook');
     $item->setLayerType('GoogleBook');
     $item->setChildItemsCount(0);
     $item->setMediaCreatorUsername($authors[0]);
     $item->setMediaCreatorRealname('Unknown');
     // write metadata
     $item->setArchive('Google Books');
     $item->setLicense('Unknown');
     $item->setThumbnailUrl($volume["imageLinks"]["thumbnail"]);
     $mainCategories = $entry["volumeInfo"]["categories"];
     if (isset($mainCategories)) {
         $item->setTags($mainCategories);
     }
     if ((bool) $entry["accessInfo"]["embeddable"]) {
         return $this->returnResponse($item, true, false);
     } else {
         return $this->returnResponse($item, false, false, "This book cannot be embedded.");
     }
 }
예제 #6
0
 public function load($url, $parameters = null)
 {
     $itemUrl = "http://api.soundcloud.com/resolve.json?url={$url}&consumer_key=" . self::$soundcloudConsumerKey;
     $itemJson = file_get_contents($itemUrl, 0, null, null);
     $itemJson = json_decode($itemJson, true);
     if (!$itemJson["streamable"]) {
         return $this->returnResponse($item, false, false, "This track is not embeddable and cannot be added to Zeega.");
     }
     $item = new Item();
     $tags = $itemJson["tag_list"];
     if (isset($tags)) {
         $tags = explode(" ", $tags);
         $itemTags = array();
         foreach ($tags as $tag) {
             array_push($itemTags, $tag);
         }
         $item->setTags($itemTags);
     }
     $item->setTitle($itemJson['title']);
     $item->setDescription($itemJson['description']);
     $item->setMediaCreatorUsername($itemJson['user']['username']);
     $item->setMediaCreatorRealname($itemJson['user']['username']);
     $item->setMediaType('Audio');
     $item->setLayerType('Audio');
     $item->setArchive('SoundCloud');
     $item->setUri($itemJson['stream_url']);
     $item->setUri($item->getUri() . '?consumer_key=' . self::$soundcloudConsumerKey);
     $item->setAttributionUri($itemJson['permalink_url']);
     $item->setMediaDateCreated($itemJson['created_at']);
     if (!is_null($itemJson['artwork_url'])) {
         $item->setThumbnailUrl($itemJson['artwork_url']);
     } else {
         if (!is_null($itemJson['user']['avatar_url'])) {
             $item->setThumbnailUrl($itemJson['user']['avatar_url']);
         } else {
             $item->setThumbnailUrl($itemJson['waveform_url']);
         }
     }
     $item->setChildItemsCount(0);
     $item->setLicense($itemJson['license']);
     return $this->returnResponse($item, true, false);
 }
예제 #7
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $itemId = $regexMatches[1];
     // bam
     $originalUrl = 'http://vimeo.com/api/v2/video/' . $itemId . '.json';
     // read feed into SimpleXML object
     $entry = json_decode(file_get_contents($originalUrl));
     $entry = $entry[0];
     $item = new Item();
     $item->setUri((string) $entry->id);
     $item->setTitle((string) $entry->title);
     $item->setDescription((string) $entry->description);
     $item->setAttributionUri('http://vimeo.com/' . $item->getUri());
     $item->setDateCreated(new \DateTime((string) $entry->upload_date));
     $item->setMediaType('Video');
     $item->setLayerType('Vimeo');
     $item->setChildItemsCount(0);
     // TODO: ADD TAGS
     $tags = (string) $entry->tags;
     if (isset($tags)) {
         $tags = explode(", ", $tags);
         $itemTags = array();
         foreach ($tags as $tagName) {
             if (!empty($tagName)) {
                 foreach ($tags as $tag) {
                     array_push($itemTags, $tag);
                 }
                 $item->setTags($itemTags);
             }
         }
     }
     $item->setMediaCreatorUsername((string) $entry->user_name);
     $item->setMediaCreatorRealname('Unknown');
     // write metadata
     $item->setArchive('Vimeo');
     /*
     $metadata->setLicense((string)$entry->embed_privacy);
     $metadata->setThumbnailUrl((string)$entry->thumbnail_medium);
     */
     $item->setThumbnailUrl((string) $entry->thumbnail_medium);
     /*
     
     		// write media information
     		$media->setDuration((string)$entry->duration);
     		$media->setWidth((string)$entry->width);
     		$media->setHeight((string)$entry->height);
     
     		
     		$item->setMetadata($metadata);
     		$item->setMedia($media);
     */
     return $this->returnResponse($item, true, false);
 }
예제 #8
0
 public function load($url, $parameters = null)
 {
     /* TEMP */
     $urlSplit = explode('?', $url);
     $urlClean = $urlSplit[0];
     $fileFormat = strtolower(substr($urlClean, strlen($urlClean) - 4));
     $fileFormatLong = strtolower(substr($urlClean, strlen($urlClean) - 5));
     if (in_array($fileFormat, array('.jpg', '.png', '.gif', 'jpeg'))) {
         $contentType = 'Image';
     } else {
         $item = new Item();
         return $this->returnResponse($item, false, false);
     }
     $archive = 'Absolute';
     $split = explode('/', $urlClean);
     $title = $split[count($split) - 1];
     $url = str_replace(" ", "%20", $url);
     $thumbUrl = $url;
     $itemUrl = $url;
     $item = new Item();
     $item->setMediaType($contentType);
     $item->setLayerType($contentType);
     $item->setUri($url);
     $item->setAttributionUri($url);
     $item->setTitle($title);
     $item->setMediaCreatorUsername('Unknown');
     $item->setMediaCreatorRealname('Unknown');
     $item->setDescription('None');
     $item->setArchive($archive);
     $item->setChildItemsCount(0);
     if ($contentType == 'Image') {
         $item->setThumbnailUrl($itemUrl);
     } elseif ($contentType == 'Audio') {
         $item->setThumbnailUrl($parameters['hostname'] . $parameters['directory'] . 'images/templates/audio.jpg');
     } elseif ($contentType == 'Video') {
         $item->setThumbnailUrl($parameters['hostname'] . $parameters['directory'] . 'images/templates/video.jpg');
     }
     return $this->returnResponse($item, true, false);
 }
예제 #9
0
 public function load($url, $parameters = null)
 {
     // read feed into SimpleXML object
     $entryList = json_decode(file_get_contents($url));
     $docs = $entryList->docs;
     $entry = $docs[0];
     $item = new Item();
     $item->setUri((string) $url);
     $item->setMediaCreatorRealname("David Weinberger");
     $item->setMediaCreatorUsername("David Weinberger");
     $item->setTitle("DPLA Collection");
     $item->setAttributionUri((string) $url);
     $item->setMediaType('Collection');
     $item->setLayerType('Collection');
     $item->setArchive((string) $entry->{"dpla.contributor"});
     $item->setThumbnailUrl('http://dev.zeega.org/dpla/web/images/dpla.jpeg');
     //$item->setDescription((string)$entry->{"dpla.description"}[0]);
     $entry = $docs[0];
     $i = 0;
     foreach ($docs as $entry) {
         if ($i < 10) {
             $i++;
             $childItem = new Item();
             $childItem->setUri((string) $url);
             if (property_exists($entry, "dpla.creator")) {
                 $childItem->setMediaCreatorRealname((string) $entry->{"dpla.creator"}[0]);
             }
             if (property_exists($entry, "dpla.creator")) {
                 $childItem->setMediaCreatorUsername((string) $entry->{"dpla.creator"}[0]);
             }
             if (property_exists($entry, "dpla.title")) {
                 $childItem->setTitle((string) $entry->{"dpla.title"});
             }
             $childItem->setAttributionUri((string) $url);
             $childItem->setChildItemsCount(0);
             $childItem->setMediaType('DPLA');
             $childItem->setLayerType('DPLA');
             $childItem->setArchive((string) $entry->{"dpla.contributor"});
             $childItem->setThumbnailUrl('http://dev.zeega.org/dpla/web/images/dpla.jpeg');
             if (property_exists($entry, "dpla.description")) {
                 $childItem->setDescription((string) $entry->{"dpla.description"}[0]);
             }
             if (property_exists($entry, "dpla.subject")) {
                 $childItem->setTags((array) $entry->{"dpla.subject"});
             }
             $item->addChildItem($childItem);
         }
     }
     $item->setChildItemsCount($i);
     return $this->returnResponse($item, true, true);
 }
예제 #10
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $tag = $regexMatches[2];
     # API key should be moved into a conf file
     $apiKey = "F7zV5AJ9F5I2oKPydkeDcIRydMMm5iiyX3By8Mir6sjMZFpbFv";
     if (isset($regexMatches[3])) {
         $apiCallUrl = "http://api.tumblr.com/v2/tagged?tag=" . $tag . "&api_key=" . $apiKey . "&before=" . $regexMatches[3];
     } else {
         $apiCallUrl = "http://api.tumblr.com/v2/tagged?tag=" . $tag . "&api_key=" . $apiKey;
     }
     $results_str = file_get_contents($apiCallUrl);
     $results_json = json_decode($results_str);
     #print(var_dump($results_json));
     if ($results_json->meta->status == 200) {
         $items = array();
         foreach ($results_json->response as $currentPost) {
             switch ($currentPost->type) {
                 case "photo":
                     $photoArray = $currentPost->photos;
                     foreach ($photoArray as $photo) {
                         $item = new Item();
                         $item->setMediaCreatorUsername($currentPost->blog_name);
                         $item->setMediaCreatorRealname($currentPost->blog_name);
                         $item->setArchive('Tumblr');
                         $item->setAttributionUri($currentPost->post_url);
                         $item->setChildItemsCount(0);
                         $item->setMediaDateCreated(new DateTime($currentPost->date));
                         $item->setTags($currentPost->tags);
                         $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                         $altSizes = $photo->alt_sizes;
                         $img75px = end($altSizes);
                         $item->setMediaType('Image');
                         $item->setLayerType('Image');
                         $item->setThumbnailUrl($img75px->url);
                         $item->setUri($photo->original_size->url);
                         $item->setMediaDateCreated(new DateTime($currentPost->date));
                         $item->setChildItemsCount(0);
                         $item->setTags($currentPost->tags);
                         $item->setAttributes(array("timestamp" => $currentPost->timestamp, "id" => $currentPost->id, "apiRequestUrl" => $apiCallUrl));
                         array_push($items, $item);
                     }
                     break;
             }
         }
     } else {
         die("Failed to retrieve url " . $apiCallUrl);
     }
     return $this->returnResponse($items, true, true);
 }
예제 #11
0
 public function load($url, $parameters = null)
 {
     // to get the photo id we first need to use the embed API
     $embedApiUrl = "https://api.instagram.com/oembed?url={$url}";
     $embedInfo = file_get_contents($embedApiUrl, 0, null, null);
     $embedInfo = json_decode($embedInfo, true);
     if (null != $embedInfo && isset($embedInfo["media_id"])) {
         $mediaId = $embedInfo["media_id"];
         $mediaApiUrl = "https://api.instagram.com/v1/media/{$mediaId}?access_token=1907240.f59def8.6a53e4264d87413a8e8cd431430b6e94";
         $mediaDetails = file_get_contents($mediaApiUrl, 0, null, null);
         $mediaDetails = json_decode($mediaDetails, true);
         if (null !== $mediaDetails && is_array($mediaDetails) && array_key_exists("data", $mediaDetails)) {
             $mediaDetails = $mediaDetails["data"];
             $item = new Item();
             $item->setTitle($mediaDetails["caption"]["text"]);
             $item->setMediaCreatorUsername($mediaDetails['user']['username']);
             $item->setMediaCreatorRealname($mediaDetails['user']['full_name']);
             $item->setMediaType('Image');
             $item->setLayerType('Image');
             $item->setArchive('Instagram');
             $item->setUri($mediaDetails['images']['standard_resolution']['url']);
             $item->setAttributionUri($mediaDetails['link']);
             $item->setMediaDateCreated(DateTime::createFromFormat('U', $mediaDetails['created_time']));
             $item->setThumbnailUrl($mediaDetails['images']['thumbnail']['url']);
             $tags = $mediaDetails["tags"];
             if (isset($tags)) {
                 $item->setTags($tags);
             }
             $location = $mediaDetails["location"];
             if (null !== $location && is_array($location)) {
                 if (array_key_exists("latitude", $location) && array_key_exists("longitude", $location)) {
                     $item->setMediaGeoLatitude($mediaDetails['location']['latitude']);
                     $item->setMediaGeoLongitude($mediaDetails['location']['longitude']);
                 }
                 if (array_key_exists("name", $location)) {
                     $item->setLocation($mediaDetails['location']['name']);
                 }
             }
             return $this->returnResponse(array($item), true, false);
         }
     }
     return $this->returnResponse(array(), false, true);
 }
예제 #12
0
 public function load($url, $parameters = null)
 {
     $originalUrl = $url;
     $url = str_replace('org/documents', 'org/api/documents', $url);
     $url = str_replace('.html', '.json', $url);
     $itemJson = file_get_contents($url, 0, null, null);
     $itemJson = json_decode($itemJson, true);
     $document = $itemJson["document"];
     $item = new Item();
     if ($document["source"]) {
         $item->setMediaCreatorUsername($document["source"]);
         $item->setMediaCreatorRealname($document["source"]);
     } else {
         $item->setMediaCreatorUsername('Unknown');
         $item->setMediaCreatorRealname('Unknown');
     }
     $item->setArchive('DocumentCloud');
     $item->setMediaType('Document');
     $item->setLayerType('DocumentCloud');
     $item->setTitle($document["title"]);
     $item->setUri($document["id"]);
     $item->setAttributionUri($originalUrl);
     $item->setChildItemsCount(0);
     $description = $document["description"];
     if (isset($description)) {
         if (strlen($description) > 500) {
             $description = substr($description, 0, 500);
         }
         $item->setDescription($description);
     }
     $image = $document["resources"]["page"]["image"];
     $image = str_replace('{page}', '1', $image);
     $image = str_replace('{size}', 'small', $image);
     $item->setThumbnailUrl($image);
     return $this->returnResponse($item, true, false);
 }
예제 #13
0
 public function load($url, $parameters = null)
 {
     require_once '../vendor/facebook/facebook.php';
     $facebook = new \Facebook(array('appId' => '459848834048078', 'secret' => 'f5b344b91bff03ace4df454e35fca4e4'));
     $user = $facebook->getUser();
     if (!$user) {
         $item = new Item();
         $item->setArchive('Facebook');
         $item->setChildItemsCount(-1);
         return $this->returnResponse($item, true, false, "You do not appear to be signed into Facebook.");
     }
     $fbid = $parameters["regex_matches"][1];
     $photoData = $facebook->api($fbid, "GET", array('metadata' => 'true', 'format' => 'json'));
     // check if response is false
     if ($photoData == false) {
         return $this->returnResponse(null, false, false, "You do not have Facebook Permissions to add this media.  The owner of the image can resolve this by changing the image's privacy settings.");
     }
     // check for FB error message
     if (array_key_exists("error", $photoData)) {
         return $this->returnResponse(null, false, false, "Facebook responded with this error message: " . $photoData['error']['message']);
     }
     // do FB permissions matter for static image URLs?
     // if so, we'll need to http get the image and verify the HTTP response
     $item = new Item();
     $tags = array();
     $item->setArchive('Facebook');
     $item->setMediaType('Image');
     $item->setLayerType('Image');
     $item->setChildItemsCount(0);
     $item->setLicense('All Rights Reserved');
     // todo: what are the proper permissions here?
     if (array_key_exists("name", $photoData)) {
         $item->setTitle($photoData["name"]);
     }
     if (array_key_exists("from", $photoData)) {
         if (array_key_exists("name", $photoData["from"])) {
             $item->setMediaCreatorRealname($photoData["from"]["name"]);
             $item->setMediaCreatorUsername($photoData["from"]["name"]);
         }
     }
     if (array_key_exists("source", $photoData)) {
         $item->setUri($photoData["source"]);
     }
     if (array_key_exists("picture", $photoData)) {
         $item->setThumbnailUrl($photoData["picture"]);
     }
     if (array_key_exists("link", $photoData)) {
         $item->setAttributionUri($url);
     }
     if (array_key_exists("from", $photoData)) {
         $item->setMediaCreatorUsername($photoData["from"]["name"]);
     }
     if (array_key_exists("created_time", $photoData)) {
         $item->setMediaDateCreated(new DateTime($photoData['created_time']));
     }
     if (array_key_exists("place", $photoData)) {
         $item->setMediaGeoLatitude($photoData['place']['location']['latitude']);
         $item->setMediaGeoLongitude($photoData['place']['location']['longitude']);
     }
     // tags might exist
     if (array_key_exists("tags", $photoData)) {
         $tags = array();
         foreach ($photoData['tags']['data'] as $fb_tag) {
             array_push($tags, $fb_tag['name']);
         }
         $item->setTags($tags);
     }
     return $this->returnResponse($item, true, false);
 }
예제 #14
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);
 }
예제 #15
0
 public function load($url, $parameters = null)
 {
     require_once '../vendor/facebook/facebook.php';
     $facebook = new \Facebook(array('appId' => '459848834048078', 'secret' => 'f5b344b91bff03ace4df454e35fca4e4'));
     $user = $facebook->getUser();
     if (!$user) {
         $item = new Item();
         $item->setArchive('Facebook');
         $item->setChildItemsCount(-1);
         return $this->returnResponse($item, true, false);
     }
     $albumId = $parameters["regex_matches"][2];
     // album id
     $albumData = $facebook->api($albumId, "GET", array('metadata' => 'true', 'format' => 'json'));
     // check if response is false
     if ($albumData == false) {
         return $this->returnResponse(null, false, false, "You do not have Facebook Permissions to add this media.  The owner of the album can resolve this by changing the album's privacy settings.");
     }
     // check for FB error message
     if (array_key_exists("error", $albumData)) {
         return $this->returnResponse(null, false, false, "Facebook responded with this error message: " . $photoData['error']['message']);
     }
     // get album cover image
     $coverImageId = $albumData['cover_photo'];
     $coverData = $facebook->api($coverImageId, "GET", array('metadata' => 'true', 'format' => 'json'));
     // check if response is false
     if ($coverData == false) {
         return $this->returnResponse(null, false, false, "You do not have Facebook Permissions to add this album's cover image.  The owner of the album can resolve this by changing the album's privacy settings.");
     }
     // check for FB error message
     if (array_key_exists("error", $coverData)) {
         return $this->returnResponse(null, false, false, "Facebook responded with this error message: " . $photoData['error']['message']);
     }
     // get album photos
     $photoQueryUrl = $albumId . '/photos';
     $photoData = $facebook->api($photoQueryUrl, "GET", array('metadata' => 'true', 'format' => 'json'));
     // check if response is false
     if ($photoData == false) {
         return $this->returnResponse(null, false, false, "You do not have Facebook Permissions to add one or more of these photos.  The owner of the album can resolve this by changing the album's privacy settings.");
     }
     // check for FB error message
     if (array_key_exists("error", $photoData)) {
         return $this->returnResponse(null, false, false, "Facebook responded with this error message: " . $photoData['error']['message']);
     }
     // create collection and metadata
     $collection = new Item();
     $collection->setMediaType('Collection');
     $collection->setLayerType('Facebook');
     $collection->setTitle($albumData['name']);
     //$collection->setDescription();
     $collection->setAttributionUri($url);
     //$collection->setChildItemsCount($albumData['count']);
     $collection->setMediaCreatorUsername($albumData['from']['name']);
     $collection->setMediaCreatorRealname($albumData['from']['name']);
     $collection->setMediaDateCreated($albumData['created_time']);
     $collection->setThumbnailUrl($coverData['picture']);
     $collection->setArchive('Facebook');
     $itemCount = 0;
     foreach ($photoData['data'] as $photoData) {
         $item = new Item();
         $tags = array();
         $item->setArchive('Facebook');
         $item->setMediaType('Image');
         $item->setLayerType('Image');
         $item->setChildItemsCount(0);
         $item->setLicense('All Rights Reserved');
         // todo: what are the proper permissions here?
         if (array_key_exists("from", $photoData)) {
             if (array_key_exists("name", $photoData["from"])) {
                 $item->setTitle($photoData["from"]["name"]);
             }
         }
         // lat/lon might exist
         if (array_key_exists("place", $photoData)) {
             $item->setMediaGeoLatitude($photoData['place']['location']['latitude']);
             $item->setMediaGeoLongitude($photoData['place']['location']['longitude']);
         }
         if (array_key_exists("source", $photoData)) {
             $item->setUri($photoData["source"]);
         }
         if (array_key_exists("picture", $photoData)) {
             $item->setThumbnailUrl($photoData["picture"]);
         }
         if (array_key_exists("link", $photoData)) {
             $item->setAttributionUri($photoData["link"]);
         }
         if (array_key_exists("from", $photoData)) {
             $item->setMediaCreatorUsername($photoData["from"]["name"]);
             $item->setMediaCreatorRealname($photoData["from"]["name"]);
         }
         if (array_key_exists("created_time", $photoData)) {
             $item->setMediaDateCreated(new DateTime($photoData['created_time']));
         }
         // tags might exist
         if (array_key_exists("tags", $photoData)) {
             $tags = array();
             foreach ($photoData['tags']['data'] as $fb_tag) {
                 array_push($tags, $fb_tag['name']);
             }
             $item->setTags($tags);
         }
         $processeditem = $this->returnResponse($item, true, false);
         $itemCount++;
         $collection->setChildItemsCount($itemCount);
         $collection->addChildItem($processeditem["items"][0]);
     }
     return $this->returnResponse($collection, true, true);
 }
예제 #16
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);
 }
예제 #17
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);
     }
 }
예제 #18
0
 public function parseItem($itemArray, $user, $item = null, $ingestor = null)
 {
     if (!isset($item)) {
         $item = new Item();
         // set the defaults
         $item->setDateCreated(new \DateTime("now"));
         $item->setChildItemsCount(0);
         $item->setEnabled(true);
         $item->setPublished(false);
         $item->setUser($user);
     }
     $item->setDateUpdated(new \DateTime("now"));
     // parse the item
     if (isset($ingestor)) {
         $item->setIngestedBy($ingestor);
     }
     if (isset($itemArray['title'])) {
         $item->setTitle($itemArray['title']);
     }
     if (isset($itemArray['description'])) {
         $item->setDescription($itemArray['description']);
     }
     if (isset($itemArray['text'])) {
         $mediaType = $item->getMediaType();
         $text = $item->getText();
         if ($mediaType !== 'project' || $mediaType == 'project' && !isset($text)) {
             if (is_array($itemArray['text'])) {
                 $itemJson = json_encode($itemArray['text']);
                 // quick fix to encode integers properly before upgrading to php >= 5.3.3
                 $itemJson = preg_replace("/\"(\\d+)\"/", '$1', $itemJson);
                 $item->setText($itemJson);
             } else {
                 $item->setText($itemArray['text']);
             }
         }
     }
     if (isset($itemArray['uri'])) {
         $item->setUri($itemArray['uri']);
     }
     if (isset($itemArray['attribution_uri'])) {
         $item->setAttributionUri($itemArray['attribution_uri']);
     }
     if (isset($itemArray['media_type'])) {
         $item->setMediaType($itemArray['media_type']);
     }
     if (isset($itemArray['layer_type'])) {
         $item->setLayerType($itemArray['layer_type']);
     }
     if (isset($itemArray['media_geo_latitude'])) {
         $item->setMediaGeoLatitude($itemArray['media_geo_latitude']);
     }
     if (isset($itemArray['media_geo_longitude'])) {
         $item->setMediaGeoLongitude($itemArray['media_geo_longitude']);
     }
     if (isset($itemArray['headline'])) {
         $item->setHeadline($itemArray['headline']);
     }
     $thumbnailSize = 4;
     $mediaType = $item->getMediaType();
     if ($mediaType === 'project') {
         $thumbnailSize = 6;
     }
     if (!isset($itemArray['thumbnail_url']) || isset($itemArray['create_thumbnail'])) {
         $thumbnail = $this->thumbnailService->getItemThumbnail($item->getUri(), $thumbnailSize);
     } else {
         $thumbnail = $itemArray['thumbnail_url'];
     }
     if (null !== $thumbnail) {
         $item->setThumbnailUrl($thumbnail);
     }
     if (isset($itemArray['media_date_created'])) {
         $parsedDate = strtotime($itemArray['media_date_created']);
         if ($parsedDate) {
             $d = date("Y-m-d h:i:s", $parsedDate);
             $item->setMediaDateCreated(new \DateTime($d));
         }
     }
     if (isset($itemArray['media_creator_username'])) {
         $item->setMediaCreatorUsername($itemArray['media_creator_username']);
     } else {
         $item->setMediaCreatorUsername($user->getDisplayName());
     }
     if (isset($itemArray['media_creator_realname'])) {
         $item->setMediaCreatorRealname($itemArray['media_creator_realname']);
     } else {
         $item->setMediaCreatorUsername($user->getDisplayName());
     }
     if (isset($itemArray['archive'])) {
         $item->setArchive($itemArray['archive']);
     }
     if (isset($itemArray['location'])) {
         $item->setLocation($itemArray['location']);
     }
     if (isset($itemArray['license'])) {
         $item->setLicense($itemArray['license']);
     }
     if (isset($itemArray['attributes'])) {
         $item->setAttributes($itemArray['attributes']);
     }
     if (isset($itemArray['tags'])) {
         $item->setTags($itemArray['tags']);
     }
     if (isset($itemArray['published'])) {
         $item->setPublished($itemArray['published']);
     }
     if (isset($itemArray["child_items"])) {
         foreach ($itemArray["child_items"] as $child_item) {
             $child = self::parseItem($child_item, $user, $ingestor);
             if (isset($child)) {
                 $item->addChildItem($child);
             }
         }
     }
     return $item;
 }
예제 #19
0
 public function load($url, $parameters = null)
 {
     $loadCollectionItems = $parameters["load_child_items"];
     $itemUrl = "http://api.soundcloud.com/resolve.json?url={$url}&consumer_key=" . self::$soundcloudConsumerKey;
     $itemJson = file_get_contents($itemUrl, 0, null, null);
     $itemJson = json_decode($itemJson, true);
     $item = new Item();
     $item->setTitle($itemJson['permalink']);
     $item->setDescription($itemJson['description']);
     $item->setMediaCreatorUsername($itemJson['user']['username']);
     $item->setMediaCreatorRealname($itemJson['user']['username']);
     $item->setMediaType('Collection');
     $item->setLayerType('Collection');
     $item->setArchive('SoundCloud');
     $item->setUri($itemJson['permalink_url']);
     $item->setUri($item->getUri() . '?consumer_key=' . self::$soundcloudConsumerKey);
     $item->setAttributionUri($itemJson['permalink_url']);
     $item->setDateCreated(new DateTime((string) $itemJson['created_at']));
     $item->setThumbnailUrl($itemJson['tracks'][0]['waveform_url']);
     $item->setChildItemsCount(count($itemJson['tracks']));
     $item->setLicense($itemJson['license']);
     if (isset($tags) && count($tags) > 0) {
         $tags = explode(" ", $tags);
         $itemTags = array();
         foreach ($tags as $tag) {
             array_push($itemTags, $tag);
         }
         $item->setTags($tags);
     }
     if ($loadCollectionItems) {
         foreach ($itemJson["tracks"] as $childItemJson) {
             if ($childItemJson["streamable"]) {
                 $childItem = new Item();
                 $childItem->setTitle($childItemJson['title']);
                 $childItem->setDescription($childItemJson['description']);
                 $childItem->setMediaCreatorUsername($childItemJson['user']['username']);
                 $childItem->setMediaCreatorRealname($childItemJson['user']['username']);
                 $childItem->setMediaType('Audio');
                 $childItem->setLayerType('Audio');
                 $childItem->setArchive('SoundCloud');
                 $childItem->setUri($childItemJson['stream_url']);
                 $childItem->setUri($childItem->getUri() . '?consumer_key=' . self::$soundcloudConsumerKey);
                 $childItem->setAttributionUri($childItemJson['permalink_url']);
                 $childItem->setMediaDateCreated($itemJson['created_at']);
                 if (!is_null($itemJson['artwork_url'])) {
                     $childItem->setThumbnailUrl($itemJson['artwork_url']);
                 } else {
                     if (!is_null($itemJson['user']['avatar_url'])) {
                         $childItem->setThumbnailUrl($itemJson['user']['avatar_url']);
                     } else {
                         $childItem->setThumbnailUrl($itemJson['waveform_url']);
                     }
                 }
                 $childItem->setChildItemsCount(0);
                 $childItem->setLicense($childItemJson['license']);
                 $tags = $childItemJson["tag_list"];
                 if (isset($tags)) {
                     $tags = explode(" ", $tags);
                     $itemTags = array();
                     foreach ($tags as $tag) {
                         array_push($itemTags, $tag);
                     }
                     $childItem->setTags($tags);
                 }
                 $item->addChildItem($childItem);
             }
         }
     }
     return $this->returnResponse($item, true, true);
 }
예제 #20
0
 public function load($url, $parameters = null)
 {
     $originalUrl = $url;
     $url = $url . "?output=json";
     $itemJson = file_get_contents($url, 0, null, null);
     $itemJson = json_decode($itemJson, true);
     $mdata = $itemJson["metadata"];
     $files = (array) $itemJson["files"];
     $fileKeys = array_keys($files);
     $dir = $itemJson["dir"];
     $misc = $itemJson["misc"];
     $item = new Item();
     $attr = array();
     if (isset($mdata["subject"]) && count($mdata["subject"]) > 0) {
         $subjects = $mdata["subject"];
         $subjects = explode(";", $subjects[0]);
         $tags = array();
         foreach ($subjects as $category) {
             array_push($tags, $category);
         }
         $item->setTags($tags);
     }
     $item->setTitle($mdata["title"][0]);
     //if(!$item->getTitle()){return false;}
     $item->setAttributionUri($originalUrl);
     if (isset($mdata["description"][0])) {
         $item->setDescription($mdata["description"][0]);
         $item->setDescription(str_replace('<br />', '', $item->getDescription()));
     }
     $item->setChildItemsCount(0);
     $item->setThumbnailUrl(urldecode($misc["image"]));
     if (isset($mdata->creator)) {
         $item->setMediaCreatorUsername((string) $mdata["creator"][0]);
         $item->setMediaCreatorRealname((string) $mdata["creator"][0]);
     } else {
         $item->setMediaCreatorUsername('Unknown');
         $item->setMediaCreatorRealname('Unknown');
     }
     $newUrl = str_replace("details", "download", $originalUrl);
     $type = (string) $mdata["mediatype"][0];
     if ($type == 'movingImage' || $type == 'movies') {
         $index = 0;
         $format = "mp4";
         for ($i = 0; $i < sizeof($fileKeys); $i++) {
             if (strstr($fileKeys[$i], $format) && $index == 0) {
                 $index = $i;
             }
         }
         $item->setMediaType('Video');
         $item->setLayerType('Video');
         $item->setUri($newUrl . $fileKeys[$index]);
     } else {
         if ($type == 'audio') {
             $index = 0;
             $format = "mp3";
             for ($i = 0; $i < sizeof($fileKeys); $i++) {
                 if (strstr($fileKeys[$i], $format) && $index == 0) {
                     $index = $i;
                 }
             }
             $item->setMediaType('Audio');
             $item->setLayerType('Audio');
             $item->setUri($newUrl . $fileKeys[$index]);
         } else {
             if ($type == 'image') {
                 $index = 0;
                 $format = "JPEG";
                 for ($i = 0; $i < sizeof($fileKeys); $i++) {
                     if (strstr($fileKeys[$i], $format) && $index == 0) {
                         $index = $i;
                     }
                 }
                 $item->setMediaType('Image');
                 $item->setLayerType('Image');
                 $item->setUri($newUrl . $fileKeys[$index]);
             } else {
                 return false;
             }
         }
     }
     $item->setArchive('InternetArchive');
     return $this->returnResponse($item, true, false);
 }
예제 #21
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);
 }
예제 #22
0
 public function load($url, $parameters = null)
 {
     $loadCollectionItems = $parameters["load_child_items"];
     $checkForDuplicates = (bool) $parameters["check_for_duplicates"];
     $tags = $parameters["tags"];
     $user = $parameters["user"];
     $originalItems = null;
     if (FALSE !== $checkForDuplicates) {
         $em = $parameters["entityManager"];
         $originalItems = $em->getRepository('ZeegaDataBundle:Item')->findUriByUserArchive($user->getId(), "SoundCloud");
         if (isset($originalItems)) {
             $checkForDuplicates = TRUE;
         } else {
             $checkForDuplicates = FALSE;
         }
     } else {
         $checkForDuplicates = FALSE;
     }
     $items = array();
     $apiBaseUrl = "http://api.soundcloud.com/tracks.json?tags={$tags}&consumer_key=" . self::$soundcloudConsumerKey;
     $limit = 50;
     $page = 0;
     while (1) {
         $offset = $limit * $page;
         $apiUrl = $apiBaseUrl . "&limit={$limit}&offset={$offset}";
         $itemsJson = file_get_contents($apiUrl, 0, null, null);
         $itemsJson = json_decode($itemsJson, true);
         if (null !== $itemsJson && is_array($itemsJson) && count($itemsJson) > 0) {
             foreach ($itemsJson as $itemJson) {
                 $uri = $itemJson['stream_url'] . '?consumer_key=' . self::$soundcloudConsumerKey;
                 if (TRUE === $checkForDuplicates) {
                     if (TRUE === array_key_exists($uri, $originalItems)) {
                         continue;
                     }
                 }
                 $item = new Item();
                 $item->setTitle($itemJson['title']);
                 $item->setDescription($itemJson['description']);
                 $item->setMediaCreatorUsername($itemJson['user']['username']);
                 $item->setMediaCreatorRealname($itemJson['user']['username']);
                 $item->setMediaType('Audio');
                 $item->setLayerType('Audio');
                 $item->setArchive('SoundCloud');
                 $item->setUri($uri);
                 $item->setAttributionUri($itemJson['permalink_url']);
                 $item->setMediaDateCreated($itemJson['created_at']);
                 if (!is_null($itemJson['artwork_url'])) {
                     $item->setThumbnailUrl($itemJson['artwork_url']);
                 } else {
                     if (!is_null($itemJson['user']['avatar_url'])) {
                         $item->setThumbnailUrl($itemJson['user']['avatar_url']);
                     } else {
                         $item->setThumbnailUrl($itemJson['waveform_url']);
                     }
                 }
                 $item->setChildItemsCount(0);
                 $item->setLicense($itemJson['license']);
                 $tags = $itemJson["tag_list"];
                 if (isset($tags)) {
                     $tags = explode(" ", $tags);
                     $itemTags = array();
                     foreach ($tags as $tag) {
                         array_push($itemTags, $tag);
                     }
                     $item->setTags($tags);
                 }
                 array_push($items, $item);
             }
         } else {
             break;
         }
         if ($page++ > 10) {
             break;
         }
     }
     return $this->returnResponse($items, true, true);
 }
예제 #23
0
 public function load($url, $parameters = null)
 {
     $loadCollectionItems = $parameters["load_child_items"];
     $checkForDuplicates = (bool) $parameters["check_for_duplicates"];
     $tags = $parameters["tags"];
     $user = $parameters["user"];
     $originalItems = null;
     $items = array();
     $apiUrl = "https://api.instagram.com/v1/tags/{$tags}/media/recent?access_token=1907240.f59def8.6a53e4264d87413a8e8cd431430b6e94";
     $itemsJson = file_get_contents($apiUrl, 0, null, null);
     if (FALSE !== $checkForDuplicates) {
         // temp check for duplicates [with duplicated code]. transition to max_id / min_id later.
         $em = $parameters["entityManager"];
         $originalItems = $em->getRepository('ZeegaDataBundle:Item')->findUriByUserArchive($user->getId(), "Instagram");
         if (isset($originalItems)) {
             $checkForDuplicates = TRUE;
         } else {
             $checkForDuplicates = FALSE;
         }
     } else {
         $checkForDuplicates = FALSE;
     }
     if (null !== $itemsJson) {
         $apiItems = json_decode($itemsJson, true);
         if (null !== $apiItems && is_array($apiItems) && array_key_exists("data", $apiItems)) {
             foreach ($apiItems["data"] as $apiItem) {
                 if (TRUE === $checkForDuplicates) {
                     if (TRUE === array_key_exists($apiItem['images']['standard_resolution']['url'], $originalItems)) {
                         continue;
                     }
                 }
                 $item = new Item();
                 $item->setTitle($apiItem["caption"]["text"]);
                 $item->setMediaCreatorUsername($apiItem['user']['username']);
                 $item->setMediaCreatorRealname($apiItem['user']['full_name']);
                 $item->setMediaType('Image');
                 $item->setLayerType('Image');
                 $item->setArchive('Instagram');
                 $item->setUri($apiItem['images']['standard_resolution']['url']);
                 $item->setAttributionUri($apiItem['link']);
                 $item->setMediaDateCreated(DateTime::createFromFormat('U', $apiItem['created_time']));
                 $item->setThumbnailUrl($apiItem['images']['thumbnail']['url']);
                 $tags = $apiItem["tags"];
                 if (isset($tags)) {
                     $item->setTags($tags);
                 }
                 $location = $apiItem["location"];
                 if (null !== $location && is_array($location)) {
                     if (array_key_exists("latitude", $location) && array_key_exists("longitude", $location)) {
                         $item->setMediaGeoLatitude($apiItem['location']['latitude']);
                         $item->setMediaGeoLongitude($apiItem['location']['longitude']);
                     }
                     if (array_key_exists("name", $location)) {
                         $item->setLocation($apiItem['location']['name']);
                     }
                 }
                 array_push($items, $item);
             }
         }
     }
     return $this->returnResponse($items, true, true);
 }
예제 #24
0
 public function load($url, $parameters = null)
 {
     $regexMatches = $parameters["regex_matches"];
     $blogHostname = $regexMatches[1] . ".tumblr.com";
     $postId = $regexMatches[2];
     # API key should be moved into a conf file
     $apiKey = "F7zV5AJ9F5I2oKPydkeDcIRydMMm5iiyX3By8Mir6sjMZFpbFv";
     $apiCallUrl = "http://api.tumblr.com/v2/blog/" . $blogHostname . "/posts?api_key=" . $apiKey . "&id=" . $postId;
     $results_str = file_get_contents($apiCallUrl);
     $results_json = json_decode($results_str);
     #print(var_dump($results_json));
     if ($results_json->meta->status == 200) {
         $item = new Item();
         $currentPost = $results_json->response->posts[0];
         $item->setMediaCreatorUsername($results_json->response->blog->name);
         $item->setMediaCreatorRealname($results_json->response->blog->name);
         switch ($currentPost->type) {
             case "photo":
                 $photoArray = $currentPost->photos;
                 $item->setArchive('Tumblr');
                 $item->setAttributionUri($currentPost->post_url);
                 $item->setChildItemsCount(count($photoArray) - 1);
                 $item->setMediaDateCreated(new DateTime($currentPost->date));
                 $item->setTags($currentPost->tags);
                 $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                 if (count($photoArray) == 1) {
                     $altSizes = $currentPost->photos[0]->alt_sizes;
                     $img75px = end($altSizes);
                     $item->setMediaType('Image');
                     $item->setLayerType('Image');
                     $item->setThumbnailUrl($img75px->url);
                     $item->setUri($currentPost->photos[0]->original_size->url);
                     $item->setMediaDateCreated(new DateTime($currentPost->date));
                     $item->setChildItemsCount(0);
                     $item->setTags($currentPost->tags);
                 } else {
                     $item->setMediaType('Collection');
                     $item->setLayerType('Collection');
                     for ($pi = 0; $pi < count($photoArray); $pi++) {
                         $photoItem = $photoArray[$pi];
                         #print(var_dump($photoItem));
                         #print("***");
                         #print($photoItem -> original_size -> url);
                         $altSizes = $photoItem->alt_sizes;
                         $img75px = end($altSizes);
                         $childItem = new Item();
                         $childItem->setMediaType('Image');
                         $childItem->setLayerType('Image');
                         $childItem->setThumbnailUrl($img75px->url);
                         $childItem->setUri($photoItem->original_size->url);
                         if (strlen($photoItem->caption) > 0) {
                             $childItem->setTitle(strip_tags($currentPost->caption));
                         } else {
                             $childItem->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                         }
                         $childItem->setMediaDateCreated(new DateTime($currentPost->date));
                         $childItem->setAttributionUri($currentPost->post_url);
                         $childItem->setChildItemsCount(0);
                         $childItem->setMediaCreatorUsername($results_json->response->blog->name);
                         $childItem->setMediaCreatorRealname($results_json->response->blog->name);
                         $childItem->setTags($currentPost->tags);
                         $item->addChildItem($childItem);
                     }
                 }
                 break;
             case "video":
                 # not finished
                 die("Video postings not yet supported.");
                 $item->setUri($currentPost->audio_url);
                 $item->setMediaType('Video');
                 $item->setLayerType('Video');
                 $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                 $item->setChildItemsCount(0);
                 $item->setMediaDateCreated(new DateTime($currentPost->date));
                 $item->setArchive('Tumblr');
                 break;
             case "audio":
                 # not finished
                 die("Audio postings not yet supported.");
                 $item->setUri($currentPost->audio_url);
                 $item->setMediaType('Audio');
                 $item->setLayerType('Audio');
                 $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                 $item->setChildItemsCount(0);
                 $item->setMediaDateCreated(new DateTime($currentPost->date));
                 $item->setArchive('Tumblr');
                 break;
             case "text":
                 # not finished
                 die("Text postings not yet supported.");
                 $item->setUri($currentPost->body);
                 $item->setMediaType('tumblr_text');
                 $item->setLayerType('Text');
                 $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                 $item->setChildItemsCount(0);
                 $item->setMediaDateCreated(new DateTime($currentPost->date));
                 $item->setArchive('Tumblr');
                 $item->setTags($currentPost->tags);
                 break;
             case "quote":
                 # not finished
                 die("Quote postings not yet supported.");
                 $item->setUri($currentPost->photos[0]->original_size->url);
                 $item->setMediaType('tumblr_quote');
                 $item->setLayerType('Text');
                 $item->setTitle(ucwords(str_replace('-', ' ', $currentPost->slug)));
                 $item->setChildItemsCount(0);
                 $item->setMediaDateCreated(new DateTime($currentPost->date));
                 $item->setArchive('Tumblr');
                 break;
         }
     } else {
         die("Failed to retrieve url " . $apiCallUrl);
     }
     return $this->returnResponse($item, true, false);
 }