本文整理汇总了PHP中Core::requests_options方法的典型用法代码示例。如果您正苦于以下问题:PHP Core::requests_options方法的具体用法?PHP Core::requests_options怎么用?PHP Core::requests_options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core
的用法示例。
在下文中一共展示了Core::requests_options方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query_lastfm
public static function query_lastfm($url)
{
debug_event('Recommendation', 'search url : ' . $url, 5);
$request = Requests::get($url, array(), Core::requests_options());
$content = $request->body;
return simplexml_load_string($content);
}
示例2: query_omdb
protected function query_omdb($title, $year = '')
{
$url = 'http://www.omdbapi.com/?t=' . rawurlencode($title);
if (!empty($year)) {
$url .= '&y=' . rawurlencode($year);
}
$request = Requests::get($url, array(), Core::requests_options());
return json_decode($request->body);
}
示例3: get_lyrics
/**
* get_lyrics
* This will look web services for a song lyrics.
*/
public function get_lyrics($song)
{
$uri = 'http://lyrics.wikia.com/api.php?action=lyrics&artist=' . urlencode($song->f_artist) . '&song=' . urlencode($song->title) . '&fmt=xml&func=getSong';
$request = Requests::get($uri, array(), Core::requests_options());
if ($request->status_code == 200) {
$xml = simplexml_load_string($request->body);
if ($xml) {
if (!empty($xml->lyrics) && $xml->lyrics != "Not found") {
return array('text' => nl2br($xml->lyrics), 'url' => $xml->url);
}
}
}
return false;
}
示例4: get_location_name
public function get_location_name($latitude, $longitude)
{
$name = "";
try {
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $latitude . "," . $longitude . "&sensor=false";
$request = Requests::get($url, array(), Core::requests_options());
$place = json_decode($request->body, true);
if (count($place['results']) > 0) {
$name = $place['results'][0]['formatted_address'];
}
} catch (Exception $e) {
debug_event('gmaps', 'Error getting location name: ' . $e->getMessage(), 1);
}
return $name;
}
示例5: get_lyrics
/**
* get_lyrics
* This will look web services for a song lyrics.
*/
public function get_lyrics($song)
{
$base = 'http://api.chartlyrics.com/apiv1.asmx/';
$uri = $base . 'SearchLyricDirect?artist=' . urlencode($song->f_artist) . '&song=' . urlencode($song->title);
$request = Requests::get($uri, array(), Core::requests_options());
if ($request->status_code == 200) {
$xml = simplexml_load_string($request->body);
if ($xml) {
if (!empty($xml->Lyric)) {
return array('text' => nl2br($xml->Lyric), 'url' => $xml->LyricUrl);
}
}
}
return false;
}
示例6: get_photos
public function get_photos($search, $category = 'concert')
{
$photos = array();
$url = "https://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=" . $this->api_key . "&per_page=20&content_type=1&text=" . rawurlencode(trim($search . " " . $category));
debug_event($this->name, 'Calling ' . $url, '5');
$request = Requests::get($url, array(), Core::requests_options());
if ($request->status_code == 200) {
$xml = simplexml_load_string($request->body);
if ($xml && $xml->photos) {
foreach ($xml->photos->photo as $photo) {
$photos[] = array('title' => $photo->title, 'url' => "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "_m.jpg");
}
}
}
return $photos;
}
示例7: github_request
/**
* Perform a GitHub request.
* @param string $action
* @return string|null
*/
public static function github_request($action)
{
try {
// https is mandatory
$url = "https://api.github.com/repos/ampache/ampache" . $action;
$request = Requests::get($url, array(), Core::requests_options());
// Not connected / API rate limit exceeded: just ignore, it will pass next time
if ($request->status_code != 200) {
debug_event('autoupdate', 'Github API request ' . $url . ' failed with http code ' . $request->status_code, '1');
return null;
}
return json_decode($request->body);
} catch (Exception $e) {
debug_event('autoupdate', 'Request error: ' . $e->getMessage(), '1');
return null;
}
}
示例8: api_call
private function api_call($func)
{
$url = 'http://www.theaudiodb.com/api/v1/json/' . $this->api_key . '/' . $func;
debug_event('tadb', 'API call: ' . $url, 5);
$request = Requests::get($url, array(), Core::requests_options());
if ($request->status_code != 200) {
return null;
}
return json_decode($request->body);
}
示例9: gather_google
/**
* gather_google
* Raw google search to retrieve the art, not very reliable
*
* @param int $limit
* @param array $data
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function gather_google($limit = 5, $data = array())
{
if (!$limit) {
$limit = 5;
}
$images = array();
$search = rawurlencode($data['keyword']);
$size = '&imgsz=m';
// Medium
$url = "http://images.google.com/images?source=hp&q=" . $search . "&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1" . $size;
debug_event('Art', 'Search url: ' . $url, '5');
try {
// Need this to not be considered as a bot (are we? ^^)
$headers = array('User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11');
$query = Requests::get($url, $headers, Core::requests_options());
$html = $query->body;
if (preg_match_all("|imgres\\?imgurl\\=(http.+?)&|", $html, $matches, PREG_PATTERN_ORDER)) {
foreach ($matches[1] as $match) {
$match = rawurldecode($match);
debug_event('Art', 'Found image at: ' . $match, '5');
$results = pathinfo($match);
$mime = 'image/' . $results['extension'];
$images[] = array('url' => $match, 'mime' => $mime, 'title' => 'Google');
if ($limit > 0 && count($images) >= $limit) {
break;
}
}
}
} catch (Exception $e) {
debug_event('Art', 'Error getting google images: ' . $e->getMessage(), '1');
}
return $images;
}
示例10: getavatar
/**
* getAvatar
* Return the user avatar in bytes.
*/
public static function getavatar($input)
{
$username = self::check_parameter($input, 'username');
$r = null;
if ($GLOBALS['user']->access >= 100 || $GLOBALS['user']->username == $username) {
if ($GLOBALS['user']->username == $username) {
$user = $GLOBALS['user'];
} else {
$user = User::get_from_username($username);
}
if ($user !== null) {
$avatar = $user->get_avatar(true);
if (isset($avatar['url']) && !empty($avatar['url'])) {
$request = Requests::get($avatar['url'], array(), Core::requests_options());
header("Content-Type: " . $request->headers['Content-Type']);
echo $request->body;
}
} else {
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
}
} else {
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_UNAUTHORIZED, $GLOBALS['user']->username . ' is not authorized to get avatar for other users.');
}
if ($r != null) {
self::apiOutput($input, $r);
}
}
示例11: photo
public static function photo($params)
{
if (count($params) == 2) {
if ($params[0] == ':' && $params[1] == 'transcode') {
$width = $_REQUEST['width'];
$height = $_REQUEST['height'];
$url = $_REQUEST['url'];
// Replace 32400 request port with the real listening port
// *** To `Plex Inc`: ***
// Please allow listening port server configuration for your Plex server
// and fix your clients to not request resources so hard-coded on 127.0.0.1:32400.
// May be ok on Apple & UPnP world but that's really ugly for a server...
// Yes, it's a little hack but it works.
$localrs = "http://127.0.0.1:32400/";
$options = Core::requests_options();
if (strpos($url, $localrs) !== false) {
$options = array();
// In case proxy is set, no proxy for local addresses
$url = "http://127.0.0.1:" . Plex_XML_Data::getServerPort() . "/" . substr($url, strlen($localrs));
}
if ($width && $height && $url) {
$request = Requests::get($url, array(), $options);
if ($request->status_code == 200) {
ob_clean();
$mime = $request->headers['content-type'];
self::setHeader($mime);
$art = new Art(0);
$art->raw = $request->body;
$thumb = $art->generate_thumb($art->raw, array('width' => $width, 'height' => $height), $mime);
echo $thumb['thumb'];
exit;
}
}
}
}
}
示例12: shortener
public function shortener($url)
{
if (empty($this->bitly_username) || empty($this->bitly_api_key)) {
debug_event($this->name, 'Bit.ly username or api key missing', '3');
return false;
}
$shorturl = '';
$apiurl = 'http://api.bit.ly/v3/shorten?login=' . $this->bitly_username . '&apiKey=' . $this->bitly_api_key . '&longUrl=' . urlencode($url) . '&format=json';
try {
debug_event($this->name, 'Bit.ly api call: ' . $apiurl, '5');
$request = Requests::get($apiurl, array(), Core::requests_options());
$shorturl = json_decode($request->body)->data->url;
} catch (Exception $e) {
debug_event($this->name, 'Bit.ly api http exception: ' . $e->getMessage(), '1');
return false;
}
return $shorturl;
}
示例13: shortener
public function shortener($url)
{
if (empty($this->yourls_domain) || empty($this->yourls_api_key)) {
debug_event($this->name, 'YOURLS domain or api key missing', '3');
return false;
}
$shorturl = '';
$apiurl = 'http://' . $this->yourls_domain . '/yourls-api.php?signature=' . $this->yourls_api_key . '&action=shorturl&format=simple&url=' . urlencode($url);
try {
debug_event($this->name, 'YOURLS api call: ' . $apiurl, '5');
$request = Requests::get($apiurl, array(), Core::requests_options());
$shorturl = $request->body;
if ($this->yourls_use_idn) {
// WARNING: idn_to_utf8 requires php-idn module.
// WARNING: http_build_url requires php-pecl-http module.
$purl = parse_url($shorturl);
$purl['host'] = idn_to_utf8($purl['host']);
$shorturl = http_build_url($purl);
}
} catch (Exception $e) {
debug_event($this->name, 'YOURLS api http exception: ' . $e->getMessage(), '1');
return false;
}
return $shorturl;
}