/** * getRSS * * @access protected */ protected function getrss($url) { require_once 'HTTP/Request.php'; $req = new HTTP_Request($url, array('timeout' => 4, 'readTimeout' => array(4, 0))); $result = $req->sendRequest(); if (PEAR::isError($result)) { $mes = htmlspecialchars($result->getMessage()); return "<p class=\"warning\">RSSを読み込めません({$mes})。</p>"; } $xml = @simplexml_load_string($req->getResponseBody()); if ($xml === false) { return '<p class="warning">RSSを解釈できません。</p>'; } $ret[] = '<ul class="plugin_rss">'; foreach ($xml->item as $item) { /** * Namespace付きの子要素を取得 * この場合、<dc:date>要素が対象 */ $dc = $item->children('http://purl.org/dc/elements/1.1/'); $date = isset($dc->date) ? ' (' . date('Y-m-d H:i', strtotime($dc->date)) . ')' : ''; $_link = htmlspecialchars($item->link); $_title = htmlspecialchars(mb_convert_encoding($item->title, 'UTF-8', 'auto')); $line = '<li>'; $line .= "<a href=\"{$_link}\">{$_title}</a>" . $date; $line .= '</li>'; $ret[] = $line; } $ret[] = '</ul>'; return join("\n", $ret); }
/** * @brief HTTP request 객체 생성 **/ function getRequest($url) { $oReqeust = new HTTP_Request($url); $oReqeust->addHeader('Content-Type', 'application/xml'); $oReqeust->setMethod('GET'); return $oReqeust; }
/** * versionCheck - Get the most current version of nterchange and cache the result. * * @return array Information about the newest version of nterchange. **/ function versionCheck() { require_once 'Cache/Lite.php'; $options = array('cacheDir' => CACHE_DIR . '/ntercache/', 'lifeTime' => $this->check_version_interval); $cache = new Cache_Lite($options); $yaml = $cache->get($this->cache_name, $this->cache_group); if (empty($yaml)) { include_once 'HTTP/Request.php'; $req = new HTTP_Request($this->check_version_url); if (!PEAR::isError($req->sendRequest())) { $yaml = $req->getResponseBody(); $cached = $cache->save($yaml, $this->cache_name, $this->cache_group); if ($cached == true) { NDebug::debug('Version check - data is from the web and is now cached.', N_DEBUGTYPE_INFO); } else { NDebug::debug('Version check - data is from the web and is NOT cached.', N_DEBUGTYPE_INFO); } } } else { NDebug::debug('Version check - data is from the cache.', N_DEBUGTYPE_INFO); } require_once 'vendor/spyc.php'; $newest_version_info = @Spyc::YAMLLoad($yaml); return $newest_version_info; }
/** * Sets the input xml file to be parsed * * @access public * @param string $file Filename(full path) * @return mixed True on success or error on failure */ function setInputFile($file) { require_once PEAR_PATH . 'HTTP/Request.php'; $httpRequest = new HTTP_Request($file, $this->_params); $httpRequest->setMethod(HTTP_REQUEST_METHOD_GET); $resRequest = $httpRequest->sendRequest(); if (PEAR::isError($resRequest)) { return $resRequest; } elseif ($httpRequest->getResponseCode() != 200) { return $this->raiseError('HTTP response error', HTTP_REQUEST_ERROR_RESPONSE); } $data = trim($httpRequest->getResponseBody()); if (version_compare(PHP_VERSION, '5.0.0', '<')) { if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $data, $matches)) { $srcenc = strtoupper($matches[1]); if (!in_array($srcenc, $this->_validEncodings)) { if (function_exists('iconv')) { $data = @iconv($srcenc, 'UTF-8', $data); } elseif (function_exists('mb_list_encodings') && in_array($srcenc, array_map('strtoupper', mb_list_encodings()))) { $data = @mb_convert_encoding($data, 'UTF-8', $srcenc); } } } } $this->setInputString($data); return true; }
protected function addRawImage($m) { $url = $m[3]; if (isset($this->addedImage[$url])) { return $m[0]; } if (isset(self::$imageCache[$url])) { $data =& self::$imageCache[$url]; } else { if (ini_get_bool('allow_url_fopen')) { $data = file_get_contents($url); } else { $data = new HTTP_Request($url); $data->sendRequest(); $data = $data->getResponseBody(); } self::$imageCache[$url] =& $data; } switch (strtolower($m[4])) { case 'png': $mime = 'image/png'; break; case 'gif': $mime = 'image/gif'; break; default: $mime = 'image/jpeg'; } $this->addHtmlImage($data, $mime, $url, false); $this->addedImage[$url] = true; return $m[0]; }
/** * Retrieves data from cache, if it's there. If it is, but it's expired, * it performs a conditional GET to see if the data is updated. If it * isn't, it down updates the modification time of the cache file and * returns the data. If the cache is not there, or the remote file has been * modified, it is downloaded and cached. * * @param string URL of remote file to retrieve * @param int Length of time to cache file locally before asking the server * if it changed. * @return string File contents */ function retrieveFile($url, $cacheLength, $cacheDir) { $cacheID = md5($url); $cache = new Cache_Lite(array("cacheDir" => $cacheDir, "lifeTime" => $cacheLength)); if ($data = $cache->get($cacheID)) { return $data; } else { // we need to perform a request, so include HTTP_Request include_once 'HTTP/Request.php'; // HTTP_Request has moronic redirect "handling", turn that off (Alexey Borzov) $req = new HTTP_Request($url, array('allowRedirects' => false)); // if $cache->get($cacheID) found the file, but it was expired, // $cache->_file will exist if (isset($cache->_file) && file_exists($cache->_file)) { $req->addHeader('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($cache->_file)) . " GMT"); } $req->sendRequest(); if (!($req->getResponseCode() == 304)) { // data is changed, so save it to cache $data = $req->getResponseBody(); $cache->save($data, $cacheID); return $data; } else { // retrieve the data, since the first time we did this failed if ($data = $cache->get($cacheID, 'default', true)) { return $data; } } } Services_ExchangeRates::raiseError("Unable to retrieve file {$url} (unknown reason)", SERVICES_EXCHANGERATES_ERROR_RETRIEVAL_FAILED); return false; }
/** Récupèration d'informations à propos de la ressource désignée par $this->href. * * La récupération des infos se fait en cascade : * 1. the encoding given in the charset parameter of the Content-Type HTTP header, or * 2. the encoding given in the encoding attribute of the XML declaration within the document, or * 3. utf-8. * * @see http://diveintomark.org/archives/2004/02/13/xml-media-types * @todo Terminer la recherche d'infos */ function fetchUrlInfo() { // Envoi d'une requete vers l'URL require_once 'HTTP/Request.php'; $r = new HTTP_Request($this->href); $r->sendRequest(); // Récupération des informations contenues dans l'entête de la réponse. $url_info = $r->getResponseHeader(); // --- Détermination du Content-Type et du Charset de la page --- // // 1. D'apres un entete http if (isset($url_info['content-type'])) { // eg. text/html; charset=utf8 $pattern = '/^(\\w+\\/\\w+)(;?.\\w+=(.*))?/'; if (preg_match($pattern, $url_info['content-type'], $matches)) { $content_type = isset($matches[1]) ? $matches[1] : null; $charset = isset($matches[3]) ? $matches[3] : null; } } else { $charset = 'utf8'; } // Mise à jour des propriétés de l'objet en fonction des informations obtenues $this->type = $content_type; $this->charset = $charset; return true; }
/** * Helper function to fetch HTTP-URLs * * @param string $url * @return string * @todo Error handling is missing */ protected function _fetch($url) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $request = new HTTP_Request($url); $request->setMethod(HTTP_REQUEST_METHOD_GET); $request->sendRequest(); return $request->getResponseBody(); }
public function shorten($url) { $req = new HTTP_Request($this->apiurl . urlencode($url)); if (!PEAR::isError($req->sendRequest())) { return $req->getResponseBody(); } return ""; }
/** * @brief HTTP request 객체 생성 **/ function getRequest($url) { $oReqeust = new HTTP_Request($url); $oReqeust->addHeader('Content-Type', 'application/xml'); $oReqeust->setMethod('GET'); $oReqeust->setBasicAuth($this->getUserID(), $this->getPassword()); return $oReqeust; }
public function shorten($url, $text) { $req = new HTTP_Request($this->apiurl . '?url=' . urlencode($url) . "&text=" . urlencode($text) . "&maxchars=120"); if (!PEAR::isError($req->sendRequest())) { return json_decode($req->getResponseBody(), true); } return ""; }
function doSearch($url) { $req = new HTTP_Request($url); $req->sendRequest(); $contents = $req->getResponseBody(); if (!xml_parse($this->_parser, $contents)) { die(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser))); } xml_parser_free($this->_parser); }
/** * Send a trackback to a site * * @access public * @param string $title Title of the Site * @param string $excerpt The Excerpt * @param string $permalink The Permalink to send * @param array $to Where to send the trackback */ function SendTrackback($title, $excerpt, $permalink, $to) { $title = urlencode(stripslashes($title)); $excerpt = urlencode(stripslashes($excerpt)); $blog_name = urlencode(stripslashes($this->gadget->registry->fetch('site_name', 'Settings'))); $permalink = urlencode($permalink); require_once PEAR_PATH . 'HTTP/Request.php'; $options = array(); $timeout = (int) $this->gadget->registry->fetch('connection_timeout', 'Settings'); $options['timeout'] = $timeout; if ($this->gadget->registry->fetch('proxy_enabled', 'Settings') == 'true') { if ($this->gadget->registry->fetch('proxy_auth', 'Settings') == 'true') { $options['proxy_user'] = $this->gadget->registry->fetch('proxy_user', 'Settings'); $options['proxy_pass'] = $this->gadget->registry->fetch('proxy_pass', 'Settings'); } $options['proxy_host'] = $this->gadget->registry->fetch('proxy_host', 'Settings'); $options['proxy_port'] = $this->gadget->registry->fetch('proxy_port', 'Settings'); } $httpRequest = new HTTP_Request('', $options); $httpRequest->setMethod(HTTP_REQUEST_METHOD_POST); foreach ($to as $url) { $httpRequest->setURL($url); $httpRequest->addPostData('title', $title); $httpRequest->addPostData('url', $permalink); $httpRequest->addPostData('blog_name', $blog_name); $httpRequest->addPostData('excerpt', $excerpt); $resRequest = $httpRequest->sendRequest(); $httpRequest->clearPostData(); } }
/** * serendipity_plugin_zooomr::getURL() * downloads the content from an URL and returns it as a string * * @author Stefan Lange-Hegermann * @since 02.08.2006 * @param string $url URL to get * @return string downloaded Data from "$url" */ function get_url($url) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $req = new HTTP_Request($url); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { $store = file_get_contents($url); } else { $store = $req->getResponseBody(); } return $store; }
/** * */ function getURL($url) { require_once PEAR_PATH . 'HTTP/Request.php'; $httpRequest = new HTTP_Request($url); $httpRequest->setMethod(HTTP_REQUEST_METHOD_GET); $resRequest = $httpRequest->sendRequest(); if (!PEAR::isError($resRequest) && $httpRequest->getResponseCode() == 200) { $data = $httpRequest->getResponseBody(); } else { $data = @file_get_contents($url); } return $data; }
function save($data) { if (!$data['GA_optin']) { trigger_error('did not opt to join'); return true; } $options = $this->getOptions(); $request = new HTTP_Request($options['hostname'] . '/offsite-join.tcl'); $request->setMethod(HTTP_REQUEST_METHOD_POST); $request->addPostData('domain', $options['domain']); if ($options['source']) { $request->addPostData('source', $options['source']); } if ($options['update']) { $request->addPostData('update', $options['update']); } foreach ($this->translate($data) as $name => $value) { $request->addPostData($name, $value); } if (!PEAR::isError($request->sendRequest())) { $message = trim($request->getResponseBody()); if ('OK' == $message) { return true; } else { $this->ERROR = $message; trigger_error($message); return false; } } }
/** * Send an HTTP HEAD request for the given URL * * @param string $url URL to request * @param string &$errmsg error message, if any (on return) * @return int HTTP response code or 777 on error * */ function doHeadRequest($url, &$errmsg) { require_once 'HTTP/Request.php'; $req = new HTTP_Request($url); $req->setMethod(HTTP_REQUEST_METHOD_HEAD); $req->addHeader('User-Agent', 'Geeklog/' . VERSION); $response = $req->sendRequest(); if (PEAR::isError($response)) { $errmsg = $response->getMessage(); return 777; } else { return $req->getResponseCode(); } }
private function call($method, $args, $include_api_key = true) { $host = "rest.akismet.com"; if ($include_api_key) { $host = "{$this->api_key}.{$host}"; } $url = "http://{$host}/1.1/{$method}"; $req = new HTTP_Request($url, array("method" => "POST")); $req->addHeader("User-Agent", "Cyberspace-Networks/" . PA_VERSION); foreach ($args as $k => $v) { $req->addPostData($k, $v); } $req->sendRequest(); return $req->getResponseBody(); }
/** * @param $uri * * @return SimpleXMLElement * @throws Exception */ public static function makeAPICall($uri) { require_once 'HTTP/Request.php'; $params = array('method' => HTTP_REQUEST_METHOD_GET, 'allowRedirects' => FALSE); $request = new HTTP_Request(self::$_apiURL . $uri, $params); $result = $request->sendRequest(); if (PEAR::isError($result)) { CRM_Core_Error::fatal($result->getMessage()); } if ($request->getResponseCode() != 200) { CRM_Core_Error::fatal(ts('Invalid response code received from Sunlight servers: %1', array(1 => $request->getResponseCode()))); } $string = $request->getResponseBody(); return simplexml_load_string($string); }
/** * 投稿実行 */ public function post() { $hr = new HTTP_Request($this->getPostUrl()); $hr->addHeader('X-WSSE', $this->wsse); $hr->addHeader('Accept', 'application/x.atom+xml, application/xml, text/xml, */*'); $hr->addHeader('Authorization', 'WSSE profile="UsernameToken"'); $hr->addHeader('Content-Type', 'application/x.atom+xml'); $hr->addRawPostData($this->getRawdata()); $hr->setMethod(HTTP_REQUEST_METHOD_POST); $hr->sendRequest(); $hr->clearPostData(); }
/** * Posts data to the URL * * @access public * @param string $url URL address * @param array $params Associated name/data values * @param string $response Response body * @return mixed Response code on success, otherwise Jaws_Error */ function post($url, $params = array(), &$response) { $httpRequest = new HTTP_Request($url, $this->options); $httpRequest->addHeader('User-Agent', $this->user_agent); $httpRequest->setMethod(HTTP_REQUEST_METHOD_POST); // add post data foreach ($params as $key => $data) { $httpRequest->addPostData($key, urlencode($data)); } $result = $httpRequest->sendRequest(); if (PEAR::isError($result)) { return Jaws_Error::raiseError($result->getMessage(), $result->getCode(), $this->default_error_level, 1); } $response = $httpRequest->getResponseBody(); return $httpRequest->getResponseCode(); }
/** * Create an HTTP_Request object and set all parameters necessary to * perform fetches for this comic. * * @param timestamp $date Date of the comic to retrieve (default today) */ function _initHTTP($date, $url) { if (is_null($this->http)) { $options = array(); if (isset($GLOBALS['conf']['http']['proxy']) && !empty($GLOBALS['conf']['http']['proxy']['proxy_host'])) { $options = array_merge($options, $GLOBALS['conf']['http']['proxy']); } require_once 'HTTP/Request.php'; $this->http = new HTTP_Request($url, $options); $v = $this->getOverride("referer", $date); if (!is_null($v)) { $this->http->addHeader('Referer', $v); } $v = $this->getOverride("agent"); if (!is_null($v)) { $this->http->addHeader('User-Agent', $v); } $user = $this->getOverride("user", $date); $pass = $this->getOverride("pass", $date); if (!is_null($user) and !is_null($pass)) { $this->http->setBasicAuth($user, $pass); } foreach ($this->getOverride('cookies', $date) as $name => $value) { $this->http->addCookie($name, $value); } foreach ($this->getOverride('headers', $date) as $name => $value) { $this->addHeader($name, $value); } } }
/** * @param bool $saveBody * @return PEAR_Error|mixed|void */ function SendRequest($saveBody = true) { // Unless the user has expressly set the proxy setting $defaultProxy = null; if ($this->useProxy == null) { // Is this localhost traffic? if (strstr($this->getUrl(), "localhost") !== false) { // Yes, don't proxy $defaultProxy = false; } } // Setup the proxy if needed // useProxy + defaultProxy both need to be null or true if ($this->useProxy !== false && $defaultProxy !== false) { global $configArray; // Proxy server settings if (isset($configArray['Proxy']['host'])) { if (isset($configArray['Proxy']['port'])) { $this->setProxy($configArray['Proxy']['host'], $configArray['Proxy']['port']); } else { $this->setProxy($configArray['Proxy']['host']); } } } // Send the request via the parent class parent::sendRequest($saveBody); }
/** * Check if the last two parts of the FQDN are whitelisted. * * @param string Host to check if it is whitelisted * @access protected * @return boolean True if the host is whitelisted */ function isDoubleCcTld($fqdn) { // 30 Days should be way enough $options = array('lifeTime' => '2592000', 'automaticSerialization' => true); $id = md5($this->doubleCcTldFile); $cache = new Cache_Lite($options); if ($data = $cache->get($id)) { // Cache hit } else { // Cache miss $http = new HTTP_Request($this->doubleCcTldFile); if (!PEAR::isError($http->sendRequest())) { $data = $http->getResponseBody(); } $data = explode("\n", $data); $data = array_flip($data); $cache->save($data, $id); } // if if (array_key_exists($fqdn, $data)) { return true; } else { return false; } // if }
/** * Fire request via HTTP to the Flickr API * * @param array $arguments List of query string pairs * @return array */ public function sendRequest(array $arguments) { $params = ''; foreach ($arguments as $key => $argument) { $params .= "{$key}=" . urlencode($argument) . "&"; } $url = $this->_url . "?" . $params; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $request = new HTTP_Request($url); $request->setMethod(HTTP_REQUEST_METHOD_GET); $request->sendRequest(); $response = unserialize($request->getResponseBody()); if ($response['stat'] != 'ok') { throw new Exception($response['message'], $response['code']); } return $response; }
/** * preprocess Index action. * * @access public * @return string Forward name (null if no errors.) */ function prepare() { if ($this->af->validate() == 0) { /// download file $url = sprintf('%s/repository.sphp', rtrim($this->af->get('repository_url'), '/')); $cache_file = $this->backend->ctl->repositoryURL2CacheFile($url); $repo_data = unserialize(file_get_contents($cache_file)); list($package, $version) = explode('@', $this->af->get('target_package')); $urls = array(); foreach ($repo_data as $package_name => $package_data) { if ($package_name == $package) { foreach ($package_data as $_pdata) { if ($_pdata['version'] == $version) { $urls = $_pdata['urls']; $filesize = $_pdata['size']; } } } } require_once 'HTTP/Request.php'; $req = new HTTP_Request(); $req->setMethod(HTTP_REQUEST_METHOD_HEAD); $command = 'no command'; foreach ($urls as $_url_data) { $_url = $_url_data['url']; $req->setURL($_url); $req->sendRequest(); if ($req->getResponseCode() == "302") { $headers = $req->getResponseHeader(); $req->setURL($headers['location']); } $req->sendRequest(); if ($req->getResponseCode() == '200') { $data_file = $this->backend->ctl->package2dataFile($package, $version); if ($this->fetchTgzFile($data_file, $req->getUrl())) { if (filesize($data_file) == $filesize || !$filesize) { chmod($data_file, 0666); return null; } } } } $this->ae->add('wget failed', _('file download failed.') . '[debug]' . sprintf('SIZE:[datafile,%d => repos,%d]', filesize($data_file), $filesize)); } return 'json_error_reload'; }
function fetchData($username, $password) { switch ($this->options['cryptType']) { case 'blowfish': include_once 'Crypt/Blowfish.php'; $bf = new Crypt_Blowfish($this->options['cryptKey']); $password = $bf->encrypt($password); $password = base64_encode($password); break; default: if (function_exists($this->options['cryptType'])) { $password = $this->options['cryptType']($password); } break; } $req = new HTTP_Request(); $req->setURL($this->options['URL']); $req->setMethod(HTTP_REQUEST_METHOD_GET); $req->addQueryString($this->options['usernameKey'], $username); $req->addQueryString($this->options['passwordKey'], $password); if (!PEAR::isError($req->sendRequest())) { $response = $req->getResponseBody(); } else { return false; } $unserializer = new XML_Unserializer(); if ($unserializer->unserialize($response)) { $this->result_value = $unserializer->getUnserializedData(); if ($this->result_value[$this->options['resultKey']] == $this->options['correctValue']) { return true; } } return false; }
function getXMLArray($file, $forced_encoding = null) { require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'HTTP/Request.php'; $req = new HTTP_Request($file); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { if (ini_get("allow_url_fopen")) { $data = file_get_contents($file); } else { $data = ""; } } else { $data = $req->getResponseBody(); } if (trim($data) == '') { return false; } return $this->parseXML($data, $forced_encoding); }
function cleanup() { global $serendipity; echo '<div class="serendipity_msg_notice">'; if ($this->get_config('lat') && $this->get_config('long')) { // Try to get the URL include_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $geourl = "http://geourl.org/ping/?p=" . $serendipity['baseURL']; $req = new HTTP_Request($geourl); if (PEAR::isError($req->sendRequest($geourl))) { printf(REMOTE_FILE_NOT_FOUND, $geourl); } else { echo PLUGIN_EVENT_GEOURL_PINGED; } } else { echo PLUGIN_EVENT_GEOURL_NOLATLONG; } echo '</div>'; }
function createTwitterRequest() { $url = $this->config['Twitter']['api']; if (isset($_SERVER['PATH_INFO'])) { $url .= $_SERVER['PATH_INFO']; } if (isset($_SERVER['QUERY_STRING'])) { $url .= '?' . $_SERVER['QUERY_STRING']; } $option = array('allow_redirect' => false); $req = new HTTP_Request($url, array_merge($this->config['HTTP_Request'], $option)); $req->setMethod($_SERVER['REQUEST_METHOD']); if (isset($_SERVER["PHP_AUTH_USER"])) { $req->setBasicAuth($_SERVER["PHP_AUTH_USER"], @$_SERVER["PHP_AUTH_PW"]); } foreach ($_POST as $k => $v) { $req->setPostData($k, $v); } return $req; }