/** 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; }
/** * Поиск доступного обновления. * * @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; } }
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; }
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; }
/** * @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'); }
/** * Сохранение значения. */ 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); } }
<?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;
} // 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();
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>"; /*
/** * Обновление конкретного модуля. */ 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; }
// 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.
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='******'&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='******'&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; }
/** * Добавление файлов с удалённого сервера (обработка). */ 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); }
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; }
$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;
/* $proxy_url = isset($_GET['proxy_url'])?$_GET['proxy_url']:false; if (!$proxy_url) { header("HTTP/1.0 400 Bad Request"); echo "proxy.php failed because proxy_url parameter is missing"; exit(); } */ $proxy_url = "http://www.it.uu.se/edu/course/homepage/websiteconst/st13/assignments/4/scripts/register"; // 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 = $_REQUEST; //$_POST if (!$h->fetch($h->url)) { 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 = explode("\n", $h->header); foreach ($ary_headers as $hdr) { header($hdr); } // Send the response body to the client. echo $h->body;
function rss20($url = "", $ttl = 0, $count = 0) { if (!$url) { echo "<h2>rss20: Oops! You need to pass a URL!</h2>"; return false; } /* Use http object to retrieve raw RSS XML and to cache the data. Review class_http at http://www.troywolf.com/articles/class_http/ */ $h = new http(); $h->dir = "../../../../../cache/"; if (!$h->fetch($url, $ttl)) { /* 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; } /* Use xml object to parse the raw RSS XML. Review class_xml at http://www.troywolf.com/articles/class_xml/ */ $x = new xml(); if (!$x->fetch($h->body)) { /* The class has a 'log' property that contains a log of events. This log is useful for testing and debugging. */ echo "<h2>There was a problem parsing your XML!</h2>"; echo $x->log; exit; } /* Some debugging help. */ #echo "<hr />"; #echo $h->log; #echo "<hr />"; #echo $x->log; #echo "<pre>\n"; #print_r($x->data); #echo "</pre>\n"; /* Now that we have the RSS data parsed into an object, here is how to work with it. */ #$version = $x->data->RSS[0]->_attr->VERSION; #$channel_link = $x->data->RSS[0]->CHANNEL[0]->LINK[0]->_text; #$channel_title = $x->data->RSS[0]->CHANNEL[0]->TITLE[0]->_text; echo "<div class=\"rss\">\n"; echo "<div class=\"head\">\n"; echo "<a href=\"" . $x->data->RSS[0]->CHANNEL[0]->LINK[0]->_text . "\"><img border=\"0\" src=\"" . $x->data->RSS[0]->CHANNEL[0]->IMAGE[0]->URL[0]->_text . "\"" . " alt=\"" . $x->data->RSS[0]->CHANNEL[0]->TITLE[0]->_text . "\" /></a>"; echo "</div>\n"; $total_items = count($x->data->RSS[0]->CHANNEL[0]->ITEM); if ($count == 0 || $count > $total_items) { $count = $total_items; } for ($idx = 0; $idx < $count; $idx++) { $item = $x->data->RSS[0]->CHANNEL[0]->ITEM[$idx]; echo "<div class=\"item\">\n"; echo "<a class=\"title\" href=\"" . $item->LINK[0]->_text . "\">" . $item->TITLE[0]->_text . "</a>\n"; echo "<div class=\"description\">" . $item->DESCRIPTION[0]->_text . "</div>\n"; echo "<div class=\"pubdate\">" . $item->PUBDATE[0]->_text . "</div>\n"; echo "</div>\n"; } echo "</div>\n"; }