本文整理汇总了PHP中http::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP http::fetch方法的具体用法?PHP http::fetch怎么用?PHP http::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http
的用法示例。
在下文中一共展示了http::fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQuoteData
/** Function to get company quotes from external site
* @param $var -- var:: Type string(company trickersymbol)
* @returns $quote_data -- quote_data:: Type string array
*
*/
function getQuoteData($var)
{
$url = "http://finance.yahoo.com/q?s=" . $var;
$h = new http();
$h->dir = "class_http_dir/";
if (!$h->fetch($url, 2)) {
echo "<h2>There is a problem with the http request!</h2>";
echo $h->log;
exit;
}
$res_arr = array();
$quote_data = http::table_into_array($h->body, 'Delayed quote data', 0, null);
if (is_array($quote_data)) {
array_shift($quote_data);
array_shift($quote_data);
if ($quote_data[0][0] != 'Last Trade:') {
array_shift($quote_data);
}
} else {
die;
}
for ($i = 0; $i < 16; $i++) {
if ($quote_data != '') {
$res_arr[] = $quote_data[$i];
}
}
return $res_arr;
}
示例2: getAvailable
/**
* Поиск доступного обновления.
*
* @return string номер доступной версии.
*/
private static function getAvailable()
{
$release = mcms::version(mcms::VERSION_RELEASE);
$content = http::fetch('http://code.google.com/p/molinos-cms' . '/downloads/list?q=label:R' . $release, http::CONTENT);
if (preg_match($re = "@http://molinos-cms\\.googlecode\\.com/files/molinos-cms-({$release}\\.[0-9]+)\\.zip@", $content, $m)) {
return $m[1];
} else {
return $version;
}
}
示例3: getExistingModules
private function getExistingModules()
{
$result = array();
try {
for ($start = 0;; $start += 100) {
$html = http::fetch('http://code.google.com/p/molinos-cms/downloads/list?can=1&q=label:Type-Module+label:R' . MCMS_RELEASE . '&start=' . $start, http::CONTENT | http::NO_CACHE);
if (preg_match_all('@/files/([^"\']+\\.zip)@', $html, $m)) {
$result = array_merge($result, $m[1]);
} else {
break;
}
}
} catch (Exception $e) {
}
return $result;
}
示例4: fetch_remote_xml
function fetch_remote_xml($url, $fetcher = false)
{
// Create a new instance of Troy Wolf's HTTP class (if a mock one
// wasn't created during testing)
if (!is_object($fetcher)) {
$fetcher = new http();
}
// Set the path of the cache
$fetcher->dir = dirname(__FILE__) . "/cache/";
// Fetch the data from the URL using a GET request (that's really
// all we need for this plugin--we're really only fetching gdata here)
if (!$fetcher->fetch($url, 43200)) {
return false;
}
// Let's return the http class object to the caller function, assuming that we
// actually received some
return $fetcher;
}
示例5: on_get_import
/**
* @route GET//api/xml/cached.xml
*/
public static function on_get_import(Context $ctx)
{
if ($ttl = intval($ctx->get('cache')) < 600) {
$ttl = 600;
}
if (!($url = $ctx->get('url'))) {
throw new BadRequestException(t('Не указан адрес импортируемого XML канала (GET-параметр url).'));
}
$cache = cache::getInstance();
$ttl = floor(time() / $ttl);
$ckey = sprintf('XmlCache|%u|%s', $ttl, $url);
if ($cached = $cache->{$ckey}) {
return new Response($cached, 'text/xml');
}
$xml = http::fetch($url, http::CONTENT);
$cache->{$ckey} = $xml;
Logger::log('Imported XML from ' . $url);
return new Response($xml, 'text/xml');
}
示例6: set
/**
* Сохранение значения.
*/
public function set($value, &$node)
{
$node->{$this->value} = null;
if (!empty($value)) {
if (preg_match('/^[0-9\\.\\,]+$/', $value)) {
list($lat, $lon) = explode(',', $value);
} elseif ($key = Context::last()->config->get('modules/googlemaps/key')) {
$url = 'http://maps.google.com/maps/geo?q=' . urlencode(trim($value)) . '&output=csv&oe=utf8&sensor=false&key=' . urlencode($key);
if ($data = http::fetch($url, http::CONTENT)) {
list($status, $accuracy, $lat, $lon) = explode(',', $data);
if (200 != $status) {
return;
}
} else {
return;
}
} else {
return;
}
$node->{$this->value} = array('query' => $value, 'lat' => $lat, 'lon' => $lon);
}
}
示例7: http
<?php
/*
* Filename.......: image_cache.php
* Author.........: Troy Wolf [troy@troywolf.com]
* Last Modified..: Date: 2005/06/21 10:30:00
* Description....: Companion script to clas_http.php. When used in conjunction
with class_http.php, can be used to "screen-scrape" images
and cache them locally for any number of seconds. You use
this script in-line within img tags like so:
<img src="image_cache.php?ttl=300&url=http%3A%2F%2Fwww.somedomain.com%2Fsomeimage.gif" />
(You must url encode the url within the src attribute.)
*/
/*
Include the http class. Modify path according to where you put the class
file.
*/
require_once 'class_http.php';
$h = new http();
$h->fetch($_GET['url'], $_GET['ttl']);
header("Content-Type: image/jpeg");
echo $h->body;
示例8: header
}
// Instantiate the http object used to make the web requests.
// More info about this object at www.troywolf.com/articles
if (!($h = new http())) {
header("HTTP/1.0 501 Script Error");
echo "proxy.php failed trying to initialize the http object";
exit;
}
$h->url = $proxy_url;
//if (!$h->fetch($h->url)) {
$verb = $_SERVER["REQUEST_METHOD"];
if ($verb == "POST") {
$h->postvars = array(@file_get_contents('php://input'));
//$_POST;
}
if (!$h->fetch($h->url, 0, null, null, null, $verb)) {
header("HTTP/1.0 501 Script Error");
echo "proxy.php had an error attempting to query the url";
exit;
}
// Forward the headers to the client.
$ary_headers = split("\n", $h->header);
foreach ($ary_headers as $hdr) {
header($hdr);
}
// Send the response body to the client.
echo $h->body;
ob_start();
print_r($_SERVER);
print "\n";
$text = ob_get_contents();
示例9: dirname
Include the http class. Modify path according to where you put the class
file.
*/
require_once dirname(__FILE__) . '/class_http.php';
/* First, instantiate a new http object. */
$h = new http();
/*
Where do you want to store your cache files?
Default is current dir. You can set it here, or hard-code in the class.
You must end this value with a "/".
*/
$h->dir = "/home/foo/bar/";
/*
Screen-scrape the Google home page without caching.
*/
if (!$h->fetch("http://www.google.com")) {
/*
The class has a 'log' property that contains a log of events. This log is
useful for testing and debugging.
*/
echo "<h2>There is a problem with the http request!</h2>";
echo $h->log;
exit;
}
/* Echo out the body content fetched from the url. */
echo $h->body;
/* If you just want to know the HTTP status code: */
echo "Status: " . $h->status;
/* If you are interested in seeing all the response headers: */
echo "<pre>" . $h->header . "</pre>";
/*
示例10: updateModule
/**
* Обновление конкретного модуля.
*/
public static function updateModule($name)
{
$db = self::getAllModules();
if (!array_key_exists($name, $db)) {
throw new RuntimeException(t('Нет информации о модуле %name.', array('%name' => $name)));
}
if (empty($db[$name]['url'])) {
Logger::log("no url for module {$name}, not updated.");
return false;
}
$head = http::head($url = $db[$name]['url']);
if (200 != $head['_status']) {
Logger::log('updateModule: file not found: ' . $url);
return false;
}
$tmp = http::fetch($url);
foreach (array('sha1' => 'sha1_file') as $k => $func) {
if (!empty($db[$name][$k]) and $db[$name][$k] != $func($tmp)) {
Logger::log($k . ' hash mismatch for ' . $url);
return false;
}
}
$existed = is_dir($path = os::path('lib', 'modules', $name));
zip::unzipToFolder($tmp, $path);
if ($existed) {
Logger::log($name . ': updated from v' . $db[$name]['version.local'] . ' to v' . $db[$name]['version'] . '.');
} else {
Logger::log($name . ': installed v' . $db[$name]['version'] . '.');
}
return true;
}
示例11: SCOPE
// find all the folders in the inbox for the exchange user.
$h->xmlrequest = '<?xml version="1.0"?>';
$h->xmlrequest .= <<<END
<a:searchrequest xmlns:a="DAV:" xmlns:s="http://schemas.microsoft.com/exchange/security/">
<a:sql>
SELECT "DAV:displayname"
FROM SCOPE('hierarchical traversal of "{$exchange_server}/exchange/{$exchange_alias}/Inbox/"')
</a:sql>
</a:searchrequest>
END;
// IMPORTANT -- The END line above must be completely left-aligned. No white-space.
// The 'fetch' method does the work of sending and receiving the request.
// NOTICE the last parameter passed--'SEARCH' in this example. That is the
// HTTP verb that you must correctly set according to the type of WebDAV request
// you are making. The examples on this page use either 'PROPFIND' or 'SEARCH'.
if (!$h->fetch("{$exchange_server}/exchange/{$exchange_alias}/Inbox/", 0, null, null, null, "SEARCH")) {
echo "<h2>There is a problem with the http request!</h2>";
echo $h->log;
exit;
}
// Note: The following lines can be uncommented to aid in debugging.
#echo "<pre>".$h->log."</pre><hr />\n";
#echo "<pre>".$h->header."</pre><hr />\n";
#echo "<pre>".$h->body."</pre><hr />\n";
#exit();
// Or, these next lines will display the result as an XML doc in the browser.
#header('Content-type: text/xml');
#echo $h->body;
#exit();
// The assumption now is that we've got an XML result back from the Exchange
// Server, so let's parse the XML into an object we can more easily access.
示例12: parse
private function parse($url, $options = array())
{
$options = array_merge(array('width' => 425, 'height' => 318), $options);
$nothing = 'You need Adobe Flash for this.';
$link = array('url' => $url);
if (preg_match('%^http://vimeo.com/([0-9]+)%', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '">' . '<param name="allowfullscreen" value="true" />' . '<param name="allowscriptaccess" value="always" />' . '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $m1[1] . '&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" />' . '<embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $m1[1] . '&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' . $options['width'] . '" height="' . $options['height'] . '">' . '</embed></object>';
$link['host'] = 'Vimeo';
$link['vid'] = $m1[1];
} elseif (preg_match('%^http://video\\.google\\.com/videoplay\\?docid=([0-9\\-]+)%i', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=' . $m1[1] . '&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docId=' . $m1[1] . '&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="' . $options['width'] . '" height="' . $options['height'] . '"></embed></object>';
$link['host'] = 'Google Video';
$link['vid'] = $m1[1];
} elseif (preg_match('%^http://www\\.vesti\\.ru/videos\\?vid=(\\d+)%', $url, $m1)) {
$link['type'] = 'video/flv';
$link['host'] = 'vesti.ru';
$link['vid'] = $m1[1];
try {
$xml = http::fetch('http://www.vesti.ru/v.xml?adv=1&z=2&vid=' . $link['vid'], http::CONTENT);
$s = new SimpleXMLElement($xml);
$link['thumbnail'] = (string) $s->picture;
} catch (Exception $e) {
}
$link['embed'] = t('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,29,0" width="408" height="356" id="flvplayer" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.vesti.ru/i/flvplayer.swf?vid=%vid&autostart=false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="devicefont" value="true" /><param name="bgcolor" value="#000000" /><param name="vid" value="%vid" /><a href="@url"><img src="@thumbnail" alt="preview" /></a></object>', array('%width' => $options['width'], '%height' => $options['height'], '%vid' => $link['vid'], '@thumbnail' => $link['thumbnail'], '@url' => $url));
} elseif (preg_match('%^http://([a-z0-9]+\\.){0,1}youtube\\.com/(?:watch\\?v=|v/)([^&]+)%i', $url, $m1)) {
$link['thumbnail'] = 'http://img.youtube.com/vi/' . $m1[2] . '/2.jpg';
$link['type'] = 'video/flv';
$link['host'] = 'YouTube';
$link['vid'] = $m1[2];
$link['embed'] = t("<object width='%width' height='%height'><param name='movie' value='http://www.youtube.com/v/%vid' /><param name='wmode' value='transparent' /><a href='http://www.youtube.com/watch?v=%vid'><img src='@thumbnail' alt='preview' /></a></object>", array('%width' => $options['width'], '%height' => $options['height'], '%vid' => $m1[2], '@thumbnail' => $link['thumbnail']));
} elseif (preg_match('%^http://vids\\.myspace\\.com/index.cfm\\?fuseaction=[^&]+\\&(?:amp;){0,1}videoID=([0-9]+)%i', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=' . $m1[1] . '&type=video" type="application/x-shockwave-flash" width="' . $options['width'] . '" height="' . $options['height'] . '"></embed>';
$link['host'] = 'MySpace';
$link['vid'] = $m1[1];
} elseif (preg_match('%^http://vision\\.rambler\\.ru/users/(.+)$%i', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="wmode" value="transparent"></param><param name="movie" value="http://vision.rambler.ru/i/e.swf?id=' . $m1[1] . '&logo=1" /><embed src="http://vision.rambler.ru/i/e.swf?id=' . $m1[1] . '&logo=1" width="' . $options['width'] . '" height="' . $options['height'] . '" type="application/x-shockwave-flash" wmode="transparent"/></object>';
$link['host'] = 'Rambler';
$link['vid'] = $m1[1];
} elseif (preg_match('%^http://video\\.mail\\.ru/([a-z]+)/([^/]+)/([0-9]+)/([0-9]+)\\.html*%i', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="flashvars" value="imaginehost=video.mail.ru&perlhost=my.video.mail.ru&alias=' . $m1[1] . '&username=' . $m1[2] . '&albumid=' . $m1[3] . '&id=' . $m1[4] . '&catalogurl=http://video.mail.ru/catalog/music/" /><param name="movie" value="http://img.mail.ru/r/video/player_full_size.swf?par=http://video.mail.ru/' . $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/$' . $m1[4] . '$0$248"></param><embed src="http://img.mail.ru/r/video/player_full_size.swf?par=http://video.mail.ru/' . $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/$' . $m1[4] . '$0$248" type="application/x-shockwave-flash" width="' . $options['width'] . '" height="' . $options['height'] . '" flashvars="imaginehost=video.mail.ru&perlhost=my.video.mail.ru&alias=' . $m1[1] . '&username=' . $m1[2] . '&albumid=' . $m1[3] . '&id=' . $m1[4] . '&catalogurl=http://video.mail.ru/catalog/music/"></embed></object>';
$link['host'] = 'Mail.Ru';
$link['vid'] = $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/' . $m1[4];
} elseif (preg_match('%^http://rutube\\.ru/tracks/(\\d+).html\\?v=(.+)$%i', $url, $m1)) {
$link['type'] = 'video/flv';
$link['embed'] = '<OBJECT width="' . $options['width'] . '" height="' . $options['height'] . '"><PARAM name="movie" value="http://video.rutube.ru/' . $m1[2] . '" /><PARAM name="wmode" value="transparent" /><EMBED src="http://video.rutube.ru/' . $m1[2] . '" type="application/x-shockwave-flash" wmode="transparent" width="' . $options['width'] . '" height="' . $options['height'] . '" /></OBJECT>';
$link['host'] = 'RuTube';
$link['vid'] = $m[2];
} else {
return false;
}
if (0 === strpos($link['type'], 'video/') and empty($link['thumbnail'])) {
mcms::debug($url, $link);
$link['thumbnail'] = 'lib/modules/base/video.png';
}
return $link;
}
示例13: on_post_remote
/**
* Добавление файлов с удалённого сервера (обработка).
*/
public static function on_post_remote(Context $ctx)
{
$files = array();
foreach ($ctx->post('files') as $url) {
if (!empty($url)) {
$head = http::head(str_replace(' ', '+', $url));
if ($head['_status'] == 200) {
$file = array('type' => $head['Content-Type'], 'size' => $head['Content-Length'], 'remove' => true, 'url' => $url);
if (!$ctx->post('symlink')) {
$file['tmp_name'] = http::fetch($url);
}
$tmp = parse_url($url);
$file['name'] = basename($tmp['path']);
if ('application/octet-stream' == $file['type'] and !empty($file['tmp_name'])) {
$file['type'] = os::getFileType($file['tmp_name'], $file['name']);
}
$files[] = $file;
}
}
}
return self::add_files($ctx, $files);
}
示例14: fromURL
public static function fromURL($url)
{
$node = Node::create('file');
$u = parse_url($url);
$name = empty($u['path']) ? 'unnamed' : basename($u['path']);
if (false === ($headers = get_headers($url, 1))) {
throw new RuntimeException(t('Не удалось определить тип файла: %url', array('%url' => $url)));
} else {
$type = $headers['Content-Type'];
}
$node = $node->import($i = array('tmp_name' => http::fetch($url), 'name' => $name, 'type' => $type), false);
return $node;
}
示例15: isset
$verb = $_SERVER['REQUEST_METHOD'];
$user = isset($_GET['user']) ? $_GET['user'] : '';
$pwd = isset($_GET['pwd']) ? $_GET['pwd'] : '';
if (!$proxy_url) {
header("HTTP/1.0 400 Bad Request");
echo "proxy.php failed because proxy_url parameter is missing";
exit;
}
// Instantiate the http object used to make the web requests.
// More info about this object at www.troywolf.com/articles
if (!($h = new http())) {
header("HTTP/1.0 501 Script Error");
echo "proxy.php failed trying to initialize the http object";
exit;
}
$h->url = $proxy_url;
$h->postvars = $_POST;
//$h->headers = getallheaders();
if (!$h->fetch($h->url, 0, "", $user, $pwd, $verb)) {
header("HTTP/1.0 501 Script Error");
echo "proxy.php had an error attempting to query the url";
echo $h->log;
exit;
}
// Forward the headers to the client.
$ary_headers = split("\n", $h->header);
foreach ($ary_headers as $hdr) {
header($hdr);
}
// Send the response body to the client.
echo $h->body;