Example #1
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.");
     }
 }
Example #2
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);
 }
 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);
 }
Example #4
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);
 }
 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);
 }
Example #6
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);
     }
 }
Example #7
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;
 }
 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);
 }
Example #9
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);
 }
Example #10
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);
 }
 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);
 }
Example #12
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);
 }