/** * Make sure that the model is configured with a valid URL. * * @return string json */ function build() { if ($user_id = $this->config('user_id')) { $url = 'http://gdata.youtube.com/feeds/api/users/' . $user_id . '/uploads'; $cache = new ReasonObjectCache($url, $this->config('cache_duration')); $result = $cache->fetch(); if (!$result) { $xml = carl_util_get_url_contents($url); $sxml = simplexml_load_string($xml); if ($sxml) { foreach ($sxml->entry as $entry) { $full_id = $entry->id; $id = basename($full_id); $media = $entry->children('media', true); $url = (string) $media->group->player->attributes()->url; $thumbnail_url = (string) $media->group->thumbnail[0]->attributes()->url; $result[$id] = array('url' => $url, 'thumbnail' => $thumbnail_url); } $cache->set($result); } else { $cache = new ReasonObjectCache($url, -1); $result = $cache->fetch(); if ($result) { trigger_error('Reusing expired version of user videos - the cache could not be refreshed using url ' . $url); $cache->set($result); } } } return $result; } else { trigger_error('The YouTubeLatestUserVideosFeedModel must be provided with the configuration parameter user_id.', FATAL); } }
/** * Grab contents of a URL. * * Includes authentication to get at URLs in protected areas. * * @param string $url Absolute URL * @return mixed a string or false on error */ function get_reason_url_contents($url) { if (defined('HTTP_CREDENTIALS_FILEPATH') && file_exists(HTTP_CREDENTIALS_FILEPATH)) { include HTTP_CREDENTIALS_FILEPATH; } else { $http_authentication_username = $http_authentication_password = ''; } return carl_util_get_url_contents($url, REASON_HOST_HAS_VALID_SSL_CERTIFICATE, $http_authentication_username, $http_authentication_password); }
/** * Uploads/Adds an Audio file to Kaltura. * * @param string $filepath * @param entity $media_work * @param string $netid */ public function upload_audio($filepath, $media_work, $netid, $at_remote_url = false) { // Determine the correct transcoding profile from the given filename's extension $extension = strtolower(pathinfo($filepath, PATHINFO_EXTENSION)); if ($extension == 'mp3') { $transcoding_profile = KALTURA_AUDIO_MP3_SOURCE_TRANSCODING_PROFILE; } elseif ($extension == 'ogg') { $transcoding_profile = KALTURA_AUDIO_OGG_SOURCE_TRANSCODING_PROFILE; } else { $transcoding_profile = KALTURA_AUDIO_TRANSCODING_PROFILE; } $tags = explode(" ", $media_work->get_value('keywords')); $categories = $this->_get_categories($media_work); if ($at_remote_url) { $file_contents = carl_util_get_url_contents($filepath); $filename = basename($filepath); $parts = explode('.', $filename); $extension = end($parts); $id = uniqid(); $new_filename = $id . '.' . $extension; $newpath = WEB_PATH . WEB_TEMP . $new_filename; $media_work->set_value('tmp_file_name', $new_filename); if (file_put_contents($newpath, $file_contents)) { $new_entry = $this->_upload_media($newpath, $media_work->get_value('name'), $media_work->get_value('description'), $tags, $categories, $netid, KalturaMediaType::AUDIO, $transcoding_profile); return $new_entry; } } else { $new_entry = $this->_upload_media($filepath, $media_work->get_value('name'), $media_work->get_value('description'), $tags, $categories, $netid, KalturaMediaType::AUDIO, $transcoding_profile); return $new_entry; } }
/** * Get info on a facebook graph id. * * @return mixed array key value pairs for facebook graph id or boolean FALSE */ private function get_graph_info($id) { $url = 'http://graph.facebook.com/'.$id; $json = carl_util_get_url_contents($url, false, '', '', 10, 5, true, false); if ($json) return json_decode($json, true); else return false; }
function _fetch_response_from_remote_server($version) { $url = 'https://apps.carleton.edu/opensource/reason/version_check.php?version='.urlencode($this->get_current_version_id()); $response = carl_util_get_url_contents($url,false,'','',5); // 5 seconds max to try if (!empty($response)) { list($version_info['code'],$version_info['message'],$version_info['url']) = explode("\n",$response); return $version_info; } return false; }
/** Query the geocoding service, given a location and any extra request parameters * * @return array of result sets **/ function get_results_from_service() { $url = 'https://maps.googleapis.com/maps/api/geocode/json?'; if ($this->location_is_address() || $this->location_is_lat_lon()) { if ($this->location_is_address()) { $url .= 'sensor=false&address=' . urlencode($this->get_location()); } elseif ($this->location_is_lat_lon()) { $latlng_str = implode(",", $this->get_location()); $url .= 'sensor=false&latlng=' . urlencode($latlng_str); } foreach ($this->extra_params as $key => $val) { $url .= '&' . urlencode($key) . '=' . urlencode($val); } // Limit requests to one per second if (isset($last_query_time) && time() - $last_query_time == 0) { usleep(1000000); } $last_query_time = time(); if (!($this->raw_query_results = @carl_util_get_url_contents($url, false, '', '', 10, 5))) { trigger_error('Geocoding request failed in geocoder->get_results_from_service()'); return false; } } else { trigger_error('location (address, lat/lng, or ip) not set in geocoder->get_results_from_service()'); return false; } if ($decode = json_decode($this->raw_query_results)) { if (isset($decode->results)) { switch ($decode->status) { case 'OK': $this->query_results = $decode->results; return true; break; case 'ZERO_RESULTS': return 0; break; case 'OVER_QUERY_LIMIT': trigger_error('Currently over query limit for Google geocoding.'); return false; break; case 'REQUEST_DENIED': case 'INVALID_REQUEST': trigger_error('Google denied geocoding request (probable malformed query)'); return false; break; } } else { trigger_error('Response decoding failed in geocoder->get_results_from_service()'); return false; } } else { trigger_error('Response decoding failed in geocoder->get_results_from_service()'); return false; } }
/** * We make this static to avoid various requests for the same resource on pages that might use multiple instances of this class. */ function get_server_ip() { static $server_ip; if (!isset($server_ip)) { $get_ip_url = carl_construct_link(array(''), array(''), REASON_HTTP_BASE_PATH . 'displayers/ip.php'); $result_ip = carl_util_get_url_contents($get_ip_url); $server_ip = !empty($result_ip) ? $result_ip : false; } return $server_ip; }