예제 #1
0
 /**
  * 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();
     }
 }
예제 #2
0
파일: rss.inc.php 프로젝트: riaf/kinowiki
 /**
  * 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) ? '&nbsp;(' . 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);
 }
예제 #3
0
 /** 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;
 }
예제 #4
0
 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];
 }
예제 #5
0
 /**
  * Método que encapsula a chamada do WEB SERVICE que traduz um arquivo .HTML em outras extensões.
  * Utilizado para exportar dados para arquivos a desejo do usuário.
  * 
  * @param texto $arquivoFetch nome do arquivo a ser utilizado para exportação, desde a pasta 'html'.
  * @param texto $extensaoDestino mine type para arquivo exportado.
  * @param texto $nomeArquivo nome a ser exibido no download do arquivo.
  */
 function exportarDados($arquivoFetch, $nomeArquivo = "Relatório.pdf", $extensaoDestino = "application/pdf", $fazerDownload = true)
 {
     $codigoHtml = $this->smarty->fetch($arquivoFetch);
     $codigoHtml = str_replace("html/css/", URL_COMPLETA . "html/css/", $codigoHtml);
     $codigoHtml = str_replace("html/img/", URL_COMPLETA . "html/img/", $codigoHtml);
     $request = new HTTP_Request(WEBSERVICE_BROFFICE_URL);
     $request->setMethod("POST");
     $request->addHeader("Content-Type", "text/html");
     $request->addHeader("Accept", $extensaoDestino);
     $request->setBody($codigoHtml);
     $request->sendRequest();
     $status = $request->getResponseCode();
     //echo $request->getResponseBody(); die;
     if ($status != 200) {
         echo "Ocorreu um erro na conversão. Favor entrar em contato com o administrador.";
         die;
     }
     if ($fazerDownload) {
         header("Content-Type: " . $extensaoDestino . "\n");
         header("Content-Disposition: attachment; filename=" . $nomeArquivo);
         echo $request->getResponseBody();
         die;
     }
     return $request->getResponseBody();
 }
예제 #6
0
 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;
         }
     }
 }
예제 #7
0
 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;
 }
예제 #8
0
 /**
  * @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);
 }
 /**
  * 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;
 }
예제 #10
0
파일: XML_Feed.php 프로젝트: Dulciane/jaws
 /**
  * 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;
 }
예제 #11
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;
 }
예제 #12
0
 /**
  *  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';
 }
예제 #13
0
 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 "";
 }
예제 #14
0
 /**
  * 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();
 }
예제 #15
0
파일: isgd.php 프로젝트: vijo/rss2twi.php
 public function shorten($url)
 {
     $req = new HTTP_Request($this->apiurl . urlencode($url));
     if (!PEAR::isError($req->sendRequest())) {
         return $req->getResponseBody();
     }
     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);
 }
 /**
  * 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;
 }
예제 #18
0
 function sendRequest($return_body = true)
 {
     $this->Response = $this->HttpRequest->sendRequest();
     $this->code = $this->HttpRequest->getResponseCode();
     if (PEAR::isError($this->Response)) {
         $this->error = $this->Response->getMessage();
         return false;
     } else {
         return $return_body ? $this->HttpRequest->getResponseBody() : true;
     }
 }
예제 #19
0
파일: Ameblo.php 프로젝트: youg0717/ameblo
 /**
  * 投稿実行
  */
 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();
 }
예제 #20
0
 /**
  *
  */
 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;
 }
예제 #21
0
 /**
  * @param $values
  *
  * @return bool
  */
 public static function checkAddress(&$values)
 {
     if (self::$_disabled) {
         return FALSE;
     }
     if (!isset($values['street_address']) || !isset($values['city']) && !isset($values['state_province']) && !isset($values['postal_code'])) {
         return FALSE;
     }
     $userID = Civi::settings()->get('address_standardization_userid');
     $url = Civi::settings()->get('address_standardization_url');
     if (empty($userID) || empty($url)) {
         return FALSE;
     }
     $address2 = str_replace(',', '', $values['street_address']);
     $XMLQuery = '<AddressValidateRequest USERID="' . $userID . '"><Address ID="0"><Address1>' . CRM_Utils_Array::value('supplemental_address_1', $values, '') . '</Address1><Address2>' . $address2 . '</Address2><City>' . $values['city'] . '</City><State>' . $values['state_province'] . '</State><Zip5>' . $values['postal_code'] . '</Zip5><Zip4>' . CRM_Utils_Array::value('postal_code_suffix', $values, '') . '</Zip4></Address></AddressValidateRequest>';
     require_once 'HTTP/Request.php';
     $request = new HTTP_Request();
     $request->setURL($url);
     $request->addQueryString('API', 'Verify');
     $request->addQueryString('XML', $XMLQuery);
     $response = $request->sendRequest();
     $session = CRM_Core_Session::singleton();
     $code = $request->getResponseCode();
     if ($code != 200) {
         $session->setStatus(ts('USPS Address Lookup Failed with HTTP status code: %1', array(1 => $code)));
         return FALSE;
     }
     $responseBody = $request->getResponseBody();
     $xml = simplexml_load_string($responseBody);
     if (is_null($xml) || is_null($xml->Address)) {
         $session->setStatus(ts('Your USPS API Lookup has Failed.'));
         return FALSE;
     }
     if ($xml->Number == '80040b1a') {
         $session->setStatus(ts('Your USPS API Authorization has Failed.'));
         return FALSE;
     }
     if (array_key_exists('Error', $xml->Address)) {
         $session->setStatus(ts('Address not found in USPS database.'));
         return FALSE;
     }
     $values['street_address'] = (string) $xml->Address->Address2;
     $values['city'] = (string) $xml->Address->City;
     $values['state_province'] = (string) $xml->Address->State;
     $values['postal_code'] = (string) $xml->Address->Zip5;
     $values['postal_code_suffix'] = (string) $xml->Address->Zip4;
     if (array_key_exists('Address1', $xml->Address)) {
         $values['supplemental_address_1'] = (string) $xml->Address->Address1;
     }
     return TRUE;
 }
예제 #22
0
/**
* 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();
    }
}
예제 #23
0
 /**
  * @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);
 }
예제 #24
0
 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();
 }
예제 #25
0
function sendNotification($message, $regId)
{
    $apikey = "AIzaSyDh3_C0r5OxdGGHN516XleJ1G_-aAMxEC4";
    $rq = new HTTP_Request("https://android.googleapis.com/gcm/send");
    $rq->setMethod(HTTP_REQUEST_METHOD_POST);
    $rq->addHeader("Authorization", "key=" . $apikey);
    $rq->addPostData("registration_id", $regId);
    $rq->addPostData("collapse_key", "1");
    $rq->addPostData("data.message", $message);
    if (!PEAR::isError($rq->sendRequest())) {
        print "\n" . $rq->getResponseBody();
    } else {
        print "\nError has occurred";
    }
}
예제 #26
0
 function process($table, $data)
 {
     $req = new HTTP_Request($this->api_url);
     $req->setMethod(HTTP_REQUEST_METHOD_GET);
     foreach ($data as $key => $val) {
         $req->addQueryString($key, $val);
     }
     $req->addQueryString('org', trim($this->org_id));
     $req->addQueryString('table', $table);
     if (!PEAR::isError($req->sendRequest())) {
         $out = $req->getResponseBody();
     } else {
         $out = null;
     }
     return $out;
 }
예제 #27
0
 /**
  * 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;
 }
예제 #28
0
 /**
  * 配信サーバへリクエストを送信する.
  *
  * @param string $mode
  * @param array $arrParams 追加パラメータ.連想配列で渡す.
  * @return string|object レスポンスボディ|エラー時にはPEAR::Errorオブジェクトを返す.
  */
 function request($mode, $arrParams = array(), $arrCookies = array())
 {
     $objReq = new HTTP_Request();
     $objReq->setUrl(OSTORE_URL . 'upgrade/index.php');
     $objReq->setMethod('POST');
     $objReq->addPostData('mode', $mode);
     $objReq->addPostDataArray($arrParams);
     foreach ($arrCookies as $cookie) {
         $objReq->addCookie($cookie['name'], $cookie['value']);
     }
     $e = $objReq->sendRequest();
     if (PEAR::isError($e)) {
         return $e;
     } else {
         return $objReq;
     }
 }
예제 #29
0
 /**
  * @throws BadRequestException
  * @param  $method
  * @param  $args
  * @return mixed
  */
 public function call($method, $args)
 {
     $req = new HTTP_Request($this->conf->endpoint . $method);
     $req->setMethod('POST');
     $args['app_id'] = $this->conf->app_id;
     foreach ($args as $key => $value) {
         $req->addPostData($key, $value);
     }
     $sig = sign($args, $this->conf->key);
     $req->addPostData('signature', $sig['signature']);
     $req->addPostData('time', $sig['time']);
     $req->sendRequest();
     if ($req->getResponseCode() != 200) {
         throw new BadRequestException($req->getResponseBody());
     }
     return json_decode($req->getResponseBody());
 }
 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);
 }