public function get($media_item, $width = false, $return = false) { $url = "http://vimeo.com/api/oembed.json?url=" . $media_item->uploaded_location . "&width=" . $width; $curl = new WaxBackgroundCurl(array('url' => $url)); if ($data = json_decode($curl->fetch())) { if ($return) { return $data; } $html = $data->html; preg_match('#src="([^>]+?)"#i', $html, $matches); if ($matches[1]) { return $matches[1]; } } return ""; }
public function geo_locate($address, $key) { if ($res = looks_like_coords($address)) { return $res; } $glocal_search_url = "https://maps.googleapis.com/maps/api/geocode/json?key=" . $key; $url = $glocal_search_url . "&address=" . urlencode($address) . "®ion=GB"; $curl = new WaxBackgroundCurl(array('url' => $url)); $res = json_decode($curl->fetch(), 1); if ($res['status'] != "OK") { WaxLog::log("error", $res['status'] . "\n" . print_r($res, 1), "geocoder"); } if (($res = $res['results'][0]) && ($lng = $res['geometry']['location']['lng']) && ($lat = $res['geometry']['location']['lat'])) { return array('lat' => $lat, 'lng' => $lng); } else { return false; } }
public function sync($location) { $info = array(); list($service_key, $id) = explode("@", $location); $service = $this->fetch[$service_key]; $single = $this->singular[$service_key]; $type = $single . "_id"; //find the photoset name $method = "flickr.photosets.getInfo"; $set_url = $this->api_base . "?" . $type . "=" . $id . "&method=" . $method . "&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id"); $curl = new WaxBackgroundCurl(array('url' => $set_url)); $set_data = json_decode($curl->fetch()); $cat = new WildfireCategory(); //find the category based on the photoset if (($name = $set_data->photoset->title->_content) && !($found_cat = $cat->filter("title", $name)->first())) { $found_cat = $cat->update_attributes(array('title' => $name)); } $url = $this->api_base . "?" . $type . "=" . $id . "&method=" . $service . "&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id"); $curl = new WaxBackgroundCurl(array('url' => $url)); $data = json_decode($curl->fetch()); $class = get_class($this); if ($data->{$single}->total) { $ids = array(); foreach ($data->{$single}->photo as $pic) { $source = $pic->id; $model = new WildfireMedia(); $info_url = $this->api_base . "?method=" . $this->fetch['photo'] . "&photo_id={$source}&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id"); $ncurl = new WaxBackgroundCurl(array('url' => $info_url)); if ($pic_info = json_decode($ncurl->fetch())) { if ($found = $model->filter("media_class", $class)->filter("source", $pic->id)->first()) { $found->update_attributes(array('status' => 1)); } else { $found = $model->update_attributes(array('source' => $source, 'uploaded_location' => str_replace(Config::get("flickr/user_id"), "@USER@", str_replace(Config::get("flickr/key"), "@KEY@", $info_url)), 'status' => 1, 'media_class' => $class, 'media_type' => self::$name, 'ext' => $pic_info->photo->originalformat, 'file_type' => $pic_info->photo->media == "photo" ? "image/" . $pic_info->photo->originalformat : "video", 'title' => $pic->title, 'hash' => $pic->secret, 'sync_location' => $location)); } $ids[] = $found->primval; $info[] = $found; //join $found->categories = $found_cat; //tags -> categories foreach ((array) $pic_info->photo->tags->tag as $tag) { $model = new WildfireCategory(); if (($tag = trim($tag->_content)) && $tag) { if ($cat = $model->filter("title", $tag)->first()) { $found->categories = $cat; } else { $found->categories = $model->update_attributes(array('title' => $tag)); } } } } } $media = new WildfireMedia(); foreach ($ids as $id) { $media->filter("id", $id, "!="); } foreach ($media->filter("status", 1)->filter("media_class", $class)->filter("sync_location", $location)->all() as $missing) { $missing->update_attributes(array('status' => -1)); } } return $info; }