Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #4
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);
 }
Example #5
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;
 }