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 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(); } }
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"; } }
/** * @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 addParams($params = array()) { if (!empty($params)) { foreach (array_keys($params) as $k) { $this->HttpRequest->addPostData($k, $params[$k]); } } }
/** * 配信サーバーへリクエストを送信する. * * @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); foreach ($arrParams as $key => $val) { $objReq->addPostData($key, $val); } foreach ($arrCookies as $cookie) { $objReq->addCookie($cookie['name'], $cookie['value']); } $e = $objReq->sendRequest(); if (PEAR::isError($e)) { return $e; } else { return $objReq; } }
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(); }
/** * Post data to TypePad api server * * @access public */ function Post($method, $params, $apiKey = '') { $path = "/{$this->apiVersion}/{$method}"; if ($apiKey == '') { $host = $this->apiServer; } else { $host = $apiKey . '.' . $this->apiServer; } $url = sprintf('http://%s:%s/%s/%s', $host, $this->apiPort, $this->apiVersion, $method); require_once PEAR_PATH . 'HTTP/Request.php'; $options = array(); $timeout = (int) $GLOBALS['app']->Registry->fetch('connection_timeout', 'Settings'); $options['timeout'] = $timeout; if ($GLOBALS['app']->Registry->fetch('proxy_enabled', 'Settings') == 'true') { if ($GLOBALS['app']->Registry->fetch('proxy_auth', 'Settings') == 'true') { $options['proxy_user'] = $GLOBALS['app']->Registry->fetch('proxy_user', 'Settings'); $options['proxy_pass'] = $GLOBALS['app']->Registry->fetch('proxy_pass', 'Settings'); } $options['proxy_host'] = $GLOBALS['app']->Registry->fetch('proxy_host', 'Settings'); $options['proxy_port'] = $GLOBALS['app']->Registry->fetch('proxy_port', 'Settings'); } $httpRequest = new HTTP_Request('', $options); $httpRequest->setURL($url); $httpRequest->addHeader('User-Agent', $this->userAgent); $httpRequest->setMethod(HTTP_REQUEST_METHOD_POST); foreach ($params as $key => $data) { $httpRequest->addPostData($key, urlencode(stripslashes($data))); } $resRequest = $httpRequest->sendRequest(); if (PEAR::isError($resRequest)) { return new Jaws_Error($resRequest->getMessage()); } elseif ($httpRequest->getResponseCode() != 200) { return new Jaws_Error('HTTP response error ' . $httpRequest->getResponseCode(), 'Policy', JAWS_ERROR_ERROR); } return $httpRequest->getResponseBody(); }
} } } if ($send_email) { $send_mail =& $header; $send_mail .= $body; while (!feof(STDIN)) { $a = fread(STDIN, 8192); if (false !== strpos($a, "\r")) { $a = strtr(str_replace("\r\n", "\n", $a), "\r", "\n"); } $send_mail .= $a; } } if (ini_get_bool('allow_url_fopen')) { foreach ($notify_urls as &$a) { $context = stream_context_create(array('http' => array('method' => 'POST', 'content' => http_build_query(array('event' => $event, 'inside-to' => $a['inside-to'], 'inside-references' => $a['inside-references'], 'email-body' => $send_email))))); file_get_contents($a['notify_url'], false, $context); } } else { require_once 'HTTP/Request.php'; foreach ($notify_urls as &$a) { $r = new HTTP_Request($a['notify_url']); $r->setMethod(HTTP_REQUEST_METHOD_POST); $r->addPostData('event', $event); $r->addPostData('inside-to', $a['inside-to']); $r->addPostData('inside-references', $a['inside-references']); $r->addPostData('email-body', $send_email); $r->sendRequest(); } }
/** * send the given XML to the server as configured in * CSHOP_GIFTCARD_POST_URL. Remove some cruft from the response and return * a XML string * * @private * @param $xmlstr str some stuff to send * @return str */ function _send_request($xmlstr) { $this->log("send_request(): {$xmlstr}"); $hr = new HTTP_Request(CSHOP_GIFTCARD_POST_URL); $hr->setMethod(HTTP_REQUEST_METHOD_POST); $hr->addPostData('Auth_Request', $xmlstr, true); $req =& $hr->sendRequest(); if (PEAR::isError($req)) { return $this->raiseError("Could not send request to giftcard processor gateway: " . $req->getMessage()); } else { $res = $hr->getResponseBody(); $this->log("response: {$res}"); /* STS sends the XML wrapped in some HTML and control chars and other nonsense * remove the cruft: */ preg_match("/" . chr(2) . "(.*)" . chr(3) . "/", $res, $m); return $m[1]; } }
/** * 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(); }
function akismetRequest($api_key, $data, &$ret, $action = 'comment-check', $eventData = null, $addData = null) { global $serendipity; $opt = array('method' => 'POST', 'http' => '1.1', 'timeout' => 20, 'allowRedirects' => true, 'maxRedirects' => 3, 'readTimeout' => array(5, 0)); // Default server type to akismet, in case user has an older version of the plugin // where no server was set $server_type = $this->get_config('akismet_server', 'akismet'); $server = ''; $anon = false; switch ($server_type) { case 'anon-tpas': $anon = true; case 'tpas': $server = 'api.antispam.typepad.com'; break; case 'anon-akismet': $anon = true; case 'akismet': $server = 'rest.akismet.com'; break; } if ($anon) { $data['comment_author'] = 'John Doe'; $data['comment_author_email'] = ''; $data['comment_author_url'] = ''; } if (empty($server)) { $this->log($this->logfile, is_null($eventData) ? 0 : $eventData['id'], 'AKISMET_SERVER', 'No Akismet server found', $addData); $ret['is_spam'] = false; $ret['message'] = 'No server for Akismet request'; return; } else { // DEBUG //$this->log($this->logfile, $eventData['id'], 'AKISMET_SERVER', 'Using Akismet server at ' . $server, $addData); } $req = new HTTP_Request('http://' . $server . '/1.1/verify-key', $opt); $req->addPostData('key', $api_key); $req->addPostData('blog', $serendipity['baseURL']); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { $ret['is_spam'] = false; $ret['message'] = 'API Verification Request failed'; $this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet HTTP verification request failed.', $addData); return; } else { // Fetch response $reqdata = $req->getResponseBody(); } if (!preg_match('@valid@i', $reqdata)) { $ret['is_spam'] = false; $ret['message'] = 'API Verification failed'; $this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API verification failed: ' . $reqdata, $addData); return; } $req = new HTTP_Request('http://' . $api_key . '.' . $server . '/1.1/' . $action, $opt); foreach ($data as $key => $value) { $req->addPostData($key, $value); } if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { $ret['is_spam'] = false; $ret['message'] = 'Akismet Request failed'; $this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet HTTP request failed.', $addData); return; } else { // Fetch response $reqdata = $req->getResponseBody(); } if ($action == 'comment-check' && preg_match('@true@i', $reqdata)) { $ret['is_spam'] = true; $ret['message'] = $reqdata; // DEBUG //$this->log($this->logfile, $eventData['id'], 'AKISMET_SPAM', 'Akismet API returned spam', $addData); } elseif ($action == 'comment-check' && preg_match('@false@i', $reqdata)) { $ret['is_spam'] = false; $ret['message'] = $reqdata; // DEBUG //$this->log($this->logfile, $eventData['id'], 'AKISMET_PASS', 'Passed Akismet verification', $addData); } elseif ($action != 'comment-check' && preg_match('@received@i', $reqdata)) { $ret['is_spam'] = $action == 'submit-spam'; $ret['message'] = $reqdata; $this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API failure: ' . $reqdata, $addData); } else { $ret['is_spam'] = false; $ret['message'] = 'Akismet API failure'; $this->log($this->logfile, $eventData['id'], 'API_ERROR', 'Akismet API failure: ' . $reqdata, $addData); } }
static function request($method, $url, $token = null, $params = array(), $file = null) { $req = new HTTP_Request($url); $req->setMethod($method == "get" ? HTTP_REQUEST_METHOD_GET : HTTP_REQUEST_METHOD_POST); $req->addHeader("X-Gallery-Request-Method", $method); if ($token) { $req->addHeader("X-Gallery-Request-Key", $token); } foreach ($params as $key => $value) { $req->addPostData($key, $value); } if ($file) { $req->addFile("file", $file, mime_content_type($file)); } $req->sendRequest(); switch ($req->getResponseCode()) { case 200: return json_decode($req->getResponseBody()); case 403: throw new Gallery3_Forbidden_Exception($req->getResponseBody()); default: throw new Gallery3_Exception($req->getResponseBody()); } }
/** * Re-send a request after successful re-authentication * * Re-creates a GET or POST request based on data passed along in a form. Used * in case of an expired security token so that the user doesn't lose changes. * */ function resend_request() { global $_CONF; require_once 'HTTP/Request.php'; $method = ''; if (isset($_POST['token_requestmethod'])) { $method = COM_applyFilter($_POST['token_requestmethod']); } $returnurl = ''; if (isset($_POST['token_returnurl'])) { $returnurl = urldecode($_POST['token_returnurl']); if (substr($returnurl, 0, strlen($_CONF['site_url'])) != $_CONF['site_url']) { // only accept URLs on our site $returnurl = ''; } } $postdata = ''; if (isset($_POST['token_postdata'])) { $postdata = urldecode($_POST['token_postdata']); } $getdata = ''; if (isset($_POST['token_getdata'])) { $getdata = urldecode($_POST['token_getdata']); } $files = ''; if (isset($_POST['token_files'])) { $files = urldecode($_POST['token_files']); } if (SECINT_checkToken() && !empty($method) && !empty($returnurl) && ($method == 'POST' && !empty($postdata) || $method == 'GET' && !empty($getdata))) { $magic = get_magic_quotes_gpc(); $req = new HTTP_Request($returnurl); if ($method == 'POST') { $req->setMethod(HTTP_REQUEST_METHOD_POST); $data = unserialize($postdata); foreach ($data as $key => $value) { if ($key == CSRF_TOKEN) { $req->addPostData($key, SEC_createToken()); } else { if ($magic) { $value = stripslashes_gpc_recursive($value); } $req->addPostData($key, $value); } } if (!empty($files)) { $files = unserialize($files); } if (!empty($files)) { foreach ($files as $key => $value) { $req->addPostData('_files_' . $key, $value); } } } else { $req->setMethod(HTTP_REQUEST_METHOD_GET); $data = unserialize($getdata); foreach ($data as $key => $value) { if ($key == CSRF_TOKEN) { $req->addQueryString($key, SEC_createToken()); } else { if ($magic) { $value = stripslashes_gpc_recursive($value); } $req->addQueryString($key, $value); } } } $req->addHeader('User-Agent', 'Geeklog/' . VERSION); // need to fake the referrer so the new token matches $req->addHeader('Referer', COM_getCurrentUrl()); foreach ($_COOKIE as $cookie => $value) { $req->addCookie($cookie, $value); } $response = $req->sendRequest(); if (PEAR::isError($response)) { if (!empty($files)) { SECINT_cleanupFiles($files); } trigger_error("Resending {$method} request failed: " . $response->getMessage()); } else { COM_output($req->getResponseBody()); } } else { if (!empty($files)) { SECINT_cleanupFiles($files); } echo COM_refresh($_CONF['site_url'] . '/index.php'); } // don't return exit; }
/** * Return array contains the response of the given URL. * array[code] => HTTP status code * array[headers] => HTTP headers * array[headers] => Entity body * Throw exception if error. * * @param string $url * @param array $headers * @param array $post * @return array */ private function getHttpResponse($url, $headers = array(), $post = array()) { $url = str_replace('&', '&', trim($url)); $req = new HTTP_Request($url, array('allowRedirects' => true, 'maxRedirects' => 5)); /* * @see HTTP_Request_Listener_Extended */ $listener = new HTTP_Request_Listener_Extended(); $req->attach($listener); if (!isset($headers['user-agent'])) { $headers['user-agent'] = $this->httpUserAgent; } foreach ($headers as $key => $value) { if (!empty($value)) { $req->addHeader($key, $value); } } if (!empty($post)) { $req->setMethod('POST'); foreach ($post as $key => $value) { $req->addPostData($key, $value); } } $result = $req->sendRequest(); $is_error = false; if (PEAR::isError($result)) { $is_error = true; $error_message = $result->getMessage(); /* * $error_message could be empty if the error was raised * when fsockopen() returns false in Net_Socket::connect() */ if (empty($error_message)) { $error_message = "Failed connecting to the server."; /* * HTTP_Request raises 'Malformed response' error * if request path is empty (e.g. http://www.example.com). * This bug still exists in its automatic redirection mechanism * in CVS rev. 1.55 (latest as of May 18, 2007). */ } elseif ($error_message == 'Malformed response.') { $url = $req->getURL(null); if (false !== ($urls = @parse_url($url)) and !isset($urls['path'])) { $req->setURL($url); $result = $req->sendRequest(); if (PEAR::isError($result)) { $error_message = $result->getMessage(); if (empty($error_message)) { $error_message = "Failed connecting to the server."; } } else { $is_error = false; } } } } if ($is_error) { throw new Exception($error_message); } return array('url' => $req->getUrl(null), 'code' => $req->getResponseCode(), 'headers' => $req->getResponseHeader(), 'body' => $req->getResponseBody()); }
case 'complete': $GLOBAL_ERR = ''; $objPage = lfDispComplete($objPage); if (isset($_POST['send_info']) && $_POST['send_info'] === 'true') { // サイト情報を送信 $req = new HTTP_Request('http://www.ec-cube.net/mall/use_site.php'); $req->setMethod(HTTP_REQUEST_METHOD_POST); $arrSendData = array(); foreach ($_POST as $key => $val) { if (preg_match('/^senddata_*/', $key)) { $arrSendDataTmp = array(str_replace('senddata_', '', $key) => $val); $arrSendData = array_merge($arrSendData, $arrSendDataTmp); } } foreach ($arrSendData as $key => $val) { $req->addPostData($key, $val); } if (!PEAR::isError($req->sendRequest())) { $response1 = $req->getResponseBody(); } else { $response1 = ''; } $req->clearPostData(); } break; case 'return_step0': $objPage = lfDispStep0($objPage); break; case 'return_step1': $objPage = lfDispStep1($objPage); break;
function export_datas_to_repo() { $file = "/etc/artica-postfix/smtp.hacks.export.db"; if (!is_file($file)) { echo "{$file} no such file\n"; return; } include_once "HTTP/Request.php"; $ini = new Bs_IniHandler(); $sock = new sockets(); $datas = $sock->GET_INFO("ArticaProxySettings"); $ini->loadString($datas); $ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"]; $ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"]; $ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"]; $ArticaProxyServerUsername = $ini->_params["PROXY"]["ArticaProxyServerUsername"]; $ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"]; $req = new HTTP_Request("http://www.articatech.net/smtphack-import.php"); $req->setURL("http://www.articatech.net/smtphack-import.php"); $req->setMethod('POST'); if ($ArticaProxyServerEnabled == "yes") { $req->setProxy($ArticaProxyServerName, $ArticaProxyServerPort, $ArticaProxyServerUsername, $ArticaProxyServerUserPassword); } $req->addPostData('xyz', time()); $result = $req->addFile('smtp-hack-file', $file, 'multipart/form-data'); // $req->sendRequest(); if (PEAR::isError($result)) { echo $result->getMessage(); } else { $response = $req->sendRequest(); if (PEAR::isError($response)) { echo $response->getMessage(); return false; } if (preg_match("#SUCCESS#", $req->getResponseBody())) { if ($GLOBALS["DEBUG"]) { echo "Central server success\n" . $req->getResponseBody() . "\n"; } return true; } if ($GLOBALS["DEBUG"]) { echo "Central server failed\n" . $req->getResponseBody() . "\n"; } } }
/** * Login * Google Calendar requires you to login first, which is done * by sending the username, and password via a post. If it's * successful, a token is returned, If it fails, an exception * is thrown with the HTTP status code that was included with * the response from google. * * @param String $email Email Address (This can be a gmail.com email, or, if your using google apps, it should be your domain). * @param String $password * @return Boolean */ private function login($email, $password) { $url = 'https://www.google.com/accounts/ClientLogin'; $http = new HTTP_Request('https://www.google.com/accounts/ClientLogin', array('allowRedirects' => true)); $http->setMethod('POST'); $http->addPostData('Email', $email); $http->addPostData('Passwd', $password); $http->addPostData('source', 'example-test-2'); $http->addPostData('service', 'cl'); $http->addPostData('accountType', 'HOSTED_OR_GOOGLE'); $http->sendRequest(); switch ($http->getResponseCode()) { case 403: throw new Exception('Google Auth Failed', 403); break; case 200: case 201: $this->token = $this->extractAuth($http->getResponseBody()); return true; break; default: throw new Exception('Unknown Google Auth Failure', $http->getResponseCode()); break; } }
/** * Return remote file's content via HTTP * * If the target is moved (when return code is 300~399), this function follows the location specified response header. * * @param string $url The address of the target file * @param string $body HTTP request body * @param int $timeout Connection timeout * @param string $method GET/POST * @param string $content_type Content type header of HTTP request * @param string[] $headers Headers key value array. * @param string[] $cookies Cookies key value array. * @param string $post_data Request arguments array for POST method * @return string If success, the content of the target file. Otherwise: none */ function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array()) { require_once _XE_PATH_ . 'libs/idna_convert/idna_convert.class.php'; $IDN = new idna_convert(array('idn_version' => 2008)); $url = $IDN->encode($url); try { requirePear(); require_once 'HTTP/Request.php'; $parsed_url = parse_url(__PROXY_SERVER__); if ($parsed_url["host"] && $parsed_url["path"]) { // Old style proxy server support (POST payload to proxy script) $oRequest = new HTTP_Request(__PROXY_SERVER__); $oRequest->setMethod('POST'); $oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data))); } else { $oRequest = new HTTP_Request($url); // New style proxy server support (Use HTTP_Request2 native config format) if ($parsed_url['host']) { $request_config['proxy_host'] = $parsed_url['host']; $request_config['proxy_port'] = $parsed_url['port'] ? $parsed_url['port'] : ''; $request_config['proxy_user'] = rawurldecode($parsed_url['user'] ? $parsed_url['user'] : ''); $request_config['proxy_password'] = rawurldecode($parsed_url['pass'] ? $parsed_url['pass'] : ''); $request_config['proxy_type'] = $parsed_url['scheme'] ? $parsed_url['scheme'] : 'http'; } if (count($request_config) && method_exists($oRequest, 'setConfig')) { foreach ($request_config as $key => $val) { if ($key === 'observers') { foreach ($val as $observer) { $oRequest->attach($observer); } } else { $oRequest->setConfig($key, $val); } } } if (method_exists($oRequest, 'setConfig')) { if (extension_loaded('curl')) { $oRequest->setConfig('adapter', 'curl'); } elseif (version_compare(PHP_VERSION, '5.6', '<')) { $oRequest->setConfig('ssl_verify_host', false); } if (file_exists(_XE_PATH_ . 'libs/cacert/cacert.pem')) { $oRequest->setConfig('ssl_cafile', _XE_PATH_ . 'libs/cacert/cacert.pem'); } } if (count($headers) > 0) { foreach ($headers as $key => $val) { $oRequest->addHeader($key, $val); } } $host = parse_url($url, PHP_URL_HOST); if ($cookies[$host]) { foreach ($cookies[$host] as $key => $val) { $oRequest->addCookie($key, $val); } } if (count($post_data) > 0) { foreach ($post_data as $key => $val) { $oRequest->addPostData($key, $val); } } if (!$content_type) { $oRequest->addHeader('Content-Type', 'text/html'); } else { $oRequest->addHeader('Content-Type', $content_type); } $oRequest->setMethod($method); if ($body) { $oRequest->setBody($body); } } if (method_exists($oRequest, 'setConfig')) { $oRequest->setConfig('timeout', $timeout); } elseif (property_exists($oRequest, '_timeout')) { $oRequest->_timeout = $timeout; } $oResponse = $oRequest->sendRequest(); $code = $oRequest->getResponseCode(); $header = $oRequest->getResponseHeader(); $response = $oRequest->getResponseBody(); if ($c = $oRequest->getResponseCookies()) { foreach ($c as $k => $v) { $cookies[$host][$v['name']] = $v['value']; } } if ($code > 300 && $code < 399 && $header['location']) { return self::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); } if ($code != 200) { return; } if (isset($request_config['store_body']) && !$request_config['store_body']) { return TRUE; } else { return $response; } } catch (Exception $e) { return NULL; } }
/** * Get PukiWiki Page List via http using cmd=filelist * @access public * @param string $url PukiWiki URL (cmd=filelist) * @return array * Page list whose each element has keys 'href', 'page', 'file'. * FALSE if HTTP GET failed. * @uses PKWKFilelistHandler * @uses PEAR XML/XML_HTMLSax.php * @uses $GLOBALS['ADMINPASS'] * @uses $GLOBALS['USERNAME'] * @uses $GLOBALS['USERPASS'] */ function &pkwk_get_existpages($url, $filter = NULL, $except = NULL) { $parsed = parse_url($url); $queries = array(); parse_str($parsed['query'], $queries); $cmd = $queries['cmd']; if ($cmd == 'filelist' && $GLOBALS['ADMINPASS'] != '') { // POST adminpass require_once 'HTTP/Request.php'; $req = new HTTP_Request($url); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addPostData('pass', $GLOBALS['ADMINPASS']); $req->setBasicAuth($GLOBALS['USERNAME'], $GLOBALS['USERPASS']); if (PEAR::isError($req->sendRequest())) { return FALSE; } $html = $req->getResponseBody(); } else { if (($html = http_get_contents($url, $GLOBALS['USERNAME'], $GLOBALS['USERPASS'])) === FALSE) { return FALSE; } } require_once 'XML/XML_HTMLSax.php'; $parser = new XML_HTMLSax(); $handler = new PKWKFilelistHandler(); $parser->set_object($handler); $parser->set_element_handler('openHandler', 'closeHandler'); $parser->set_data_handler('dataHandler'); $parser->parse($html); if ($filter !== NULL) { $pregfilter = '/' . str_replace('/', '\\/', $filter) . '/'; foreach ($handler->pages as $i => $page) { if (!preg_match($pregfilter, $page['page'])) { unset($handler->pages[$i]); } } } if ($except !== NULL) { $pregexcept = '/' . str_replace('/', '\\/', $except) . '/'; foreach ($handler->pages as $i => $page) { if (preg_match($pregexcept, $page['page'])) { unset($handler->pages[$i]); } } } if ($cmd != 'filelist') { foreach ($handler->pages as $i => $page) { $handler->pages[$i]['file'] = get_wikifilename($page['page']); } } // unique (probably this can be done in html parsing process concurrently, though) $uniq_pages = array(); foreach ($handler->pages as $page) { $uniq_pages[] = $page['page']; } $uniq_pages = array_unique($uniq_pages); $pages = array(); foreach ($uniq_pages as $i => $page) { $pages[] = $handler->pages[$i]; } return $pages; }
public function Logoff() { debugLog("BackendOX::Logoff"); $request = new HTTP_Request(OX_URL . "/login?action=logout", array("method" => "GET")); $request->addPostData("session", $this->session); try { $request->sendRequest(); if ($request->getResponseCode() == 200) { return true; } else { return false; } } catch (HTTP_Exception $e) { return false; } }
/** * Return remote file's content via HTTP * * If the target is moved (when return code is 300~399), this function follows the location specified response header. * * @param string $url The address of the target file * @param string $body HTTP request body * @param int $timeout Connection timeout * @param string $method GET/POST * @param string $content_type Content type header of HTTP request * @param string[] $headers Headers key value array. * @param string[] $cookies Cookies key value array. * @param string $post_data Request arguments array for POST method * @return string If success, the content of the target file. Otherwise: none */ public static function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array(), $request_config = array()) { try { requirePear(); if (!class_exists('HTTP_Request')) { require_once 'HTTP/Request.php'; } $parsed_url = parse_url(__PROXY_SERVER__); if ($parsed_url["host"]) { $oRequest = new HTTP_Request(__PROXY_SERVER__); $oRequest->setMethod('POST'); $oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data))); } else { $oRequest = new HTTP_Request($url); if (count($request_config) && method_exists($oRequest, 'setConfig')) { foreach ($request_config as $key => $val) { $oRequest->setConfig($key, $val); } } if (count($headers) > 0) { foreach ($headers as $key => $val) { $oRequest->addHeader($key, $val); } } if ($cookies[$host]) { foreach ($cookies[$host] as $key => $val) { $oRequest->addCookie($key, $val); } } if (count($post_data) > 0) { foreach ($post_data as $key => $val) { $oRequest->addPostData($key, $val); } } if (!$content_type) { $oRequest->addHeader('Content-Type', 'text/html'); } else { $oRequest->addHeader('Content-Type', $content_type); } $oRequest->setMethod($method); if ($body) { $oRequest->setBody($body); } } if (method_exists($oRequest, 'setConfig')) { $oRequest->setConfig('timeout', $timeout); } elseif (property_exists($oRequest, '_timeout')) { $oRequest->_timeout = $timeout; } $oResponse = $oRequest->sendRequest(); $code = $oRequest->getResponseCode(); $header = $oRequest->getResponseHeader(); $response = $oRequest->getResponseBody(); if ($c = $oRequest->getResponseCookies()) { foreach ($c as $k => $v) { $cookies[$host][$v['name']] = $v['value']; } } if ($code > 300 && $code < 399 && $header['location']) { return self::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); } if ($code != 200) { return; } return $response; } catch (Exception $e) { return NULL; } }
function getRemoteResource($url, $body = null, $timeout = 3, $method = 'GET', $content_type = null, $headers = array(), $cookies = array(), $post_data = array()) { requirePear(); require_once 'HTTP/Request.php'; $parsed_url = parse_url(__PROXY_SERVER__); if ($parsed_url["host"]) { $oRequest = new HTTP_Request(__PROXY_SERVER__); $oRequest->setMethod('POST'); $oRequest->_timeout = $timeout; $oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers, "post_data" => $post_data))); } else { $oRequest = new HTTP_Request($url); if (count($headers)) { foreach ($headers as $key => $val) { $oRequest->addHeader($key, $val); } } if ($cookies[$host]) { foreach ($cookies[$host] as $key => $val) { $oRequest->addCookie($key, $val); } } if (count($post_data)) { foreach ($post_data as $key => $val) { $oRequest->addPostData($key, $val); } } if (!$content_type) { $oRequest->addHeader('Content-Type', 'text/html'); } else { $oRequest->addHeader('Content-Type', $content_type); } $oRequest->setMethod($method); if ($body) { $oRequest->setBody($body); } $oRequest->_timeout = $timeout; } $oResponse = $oRequest->sendRequest(); $code = $oRequest->getResponseCode(); $header = $oRequest->getResponseHeader(); $response = $oRequest->getResponseBody(); if ($c = $oRequest->getResponseCookies()) { foreach ($c as $k => $v) { $cookies[$host][$v['name']] = $v['value']; } } if ($code > 300 && $code < 399 && $header['location']) { return FileHandler::getRemoteResource($header['location'], $body, $timeout, $method, $content_type, $headers, $cookies, $post_data); } return $response; }
/** * callMethod * * @access private * @param string $method_name * @param array $send_param * @param string $method * @return string result XML data */ private function callMethod($method_name, $send_param = array(), $method = 'post') { $request = new HTTP_Request($this->api_url . $method_name); $request->setBasicAuth($this->username, $this->password); if ($method == "post") { $request->setMethod(HTTP_REQUEST_METHOD_POST); } if (count($send_param) != 0) { foreach ($send_param as $key => $value) { if ($key == "photo" && $method_name == "photo_add") { $request->addFile($key, $value, $this->getMime($value)); } else { if ($method == "post") { $request->addPostData($key, $value, true); } else { $request->addQueryString($key, $value, true); } } } } $response = $request->sendRequest(); if (PEAR::isError($response)) { return $response; } else { $body = $request->getResponseBody(); if (strpos($body, 'rsp stat="fail"') !== false) { preg_match('|err code="(.*?)" msg="(.*?)"|', $body, $matches); $code = 0; if (isset($this->error_code[$matches[1]])) { $code = $this->error_code[$matches[1]]; } return PEAR::raiseError($matches[1] . ':' . $matches[2], $code); } else { return $body; } } }
/** * @brief Tool dashboard **/ function dispTextyleToolDashboard() { set_include_path(_XE_PATH_ . "libs/PEAR"); require_once 'PEAR.php'; require_once 'HTTP/Request.php'; $oCounterModel =& getModel('counter'); $oDocumentModel =& getModel('document'); $oCommentModel =& getModel('comment'); $oTextyleModel =& getModel('textyle'); $url = sprintf("http://news.textyle.kr/%s/news.php", Context::getLangType()); $cache_file = sprintf("%sfiles/cache/textyle/news/%s%s.cache.xml", _XE_PATH_, getNumberingPath($this->module_srl), Context::getLangType()); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { FileHandler::writeFile($cache_file, ''); if (__PROXY_SERVER__ !== null) { $oRequest = new HTTP_Request(__PROXY_SERVER__); $oRequest->setMethod('POST'); $oRequest->_timeout = $timeout; $oRequest->addPostData('arg', serialize(array('Destination' => $url))); } else { $oRequest = new HTTP_Request($url); if (!$content_type) { $oRequest->addHeader('Content-Type', 'text/html'); } else { $oRequest->addHeader('Content-Type', $content_type); } if (count($headers)) { foreach ($headers as $key => $val) { $oRequest->addHeader($key, $val); } } $oRequest->_timeout = 2; } if (isSiteID($this->textyle->domain)) { $oRequest->addHeader('REQUESTURL', Context::getRequestUri() . $this->textyle->domain); } else { $oRequest->addHeader('REQUESTURL', $this->textyle->domain); } $oResponse = $oRequest->sendRequest(); $body = $oRequest->getResponseBody(); FileHandler::writeFile($cache_file, $body); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = null; $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } Context::set('news', $news); } } $time = time(); $w = date("D"); while (date("D", $time) != "Sun") { $time += 60 * 60 * 24; } $time -= 60 * 60 * 24; while (date("D", $time) != "Sun") { $thisWeek[] = date("Ymd", $time); $time -= 60 * 60 * 24; } $thisWeek[] = date("Ymd", $time); asort($thisWeek); $thisWeekCounter = $oCounterModel->getStatus($thisWeek, $this->site_srl); $time -= 60 * 60 * 24; while (date("D", $time) != "Sun") { $lastWeek[] = date("Ymd", $time); $time -= 60 * 60 * 24; } $lastWeek[] = date("Ymd", $time); asort($lastWeek); $lastWeekCounter = $oCounterModel->getStatus($lastWeek, $this->site_srl); $max = 0; foreach ($thisWeek as $day) { $v = (int) $thisWeekCounter[$day]->unique_visitor; if ($v && $v > $max) { $max = $v; } $status->week[date("D", strtotime($day))]->this = $v; } foreach ($lastWeek as $day) { $v = (int) $lastWeekCounter[$day]->unique_visitor; if ($v && $v > $max) { $max = $v; } $status->week[date("D", strtotime($day))]->last = $v; } $status->week_max = $max; $idx = 0; foreach ($status->week as $key => $val) { $_item[] = sprintf("<item id=\"%d\" name=\"%s\" />", $idx, $thisWeek[$idx]); $_thisWeek[] = $val->this; $_lastWeek[] = $val->last; $idx++; } $buff = '<?xml version="1.0" encoding="utf-8" ?><Graph><gdata title="Textyle Counter" id="data2"><fact>' . implode('', $_item) . '</fact><subFact>'; $buff .= '<item id="0"><data name="' . Context::getLang('this_week') . '">' . implode('|', $_thisWeek) . '</data></item>'; $buff .= '<item id="1"><data name="' . Context::getLang('last_week') . '">' . implode('|', $_lastWeek) . '</data></item>'; $buff .= '</subFact></gdata></Graph>'; Context::set('xml', $buff); $counter = $oCounterModel->getStatus(array(0, date("Ymd")), $this->site_srl); $status->total_visitor = $counter[0]->unique_visitor; $status->visitor = $counter[date("Ymd")]->unique_visitor; $args->module_srl = $this->module_srl; $args->regdate = date("Ymd"); $output = executeQuery('textyle.getTodayCommentCount', $args); $status->comment_count = $output->data->count; $args->module_srl = $this->module_srl; $args->regdate = date("Ymd"); $output = executeQuery('textyle.getTodayTrackbackCount', $args); $status->trackback_count = $output->data->count; Context::set('status', $status); $doc_args->module_srl = array($this->textyle->get('member_srl'), $this->module_srl); $doc_args->sort_index = 'list_order'; $doc_args->order_type = 'asc'; $doc_args->list_count = 3; $output = $oDocumentModel->getDocumentList($doc_args, false, false); Context::set('newest_documents', $output->data); $com_args->module_srl = $this->textyle->get('module_srl'); $com_args->sort_index = 'list_order'; $com_args->order_type = 'asc'; $com_args->list_count = 5; $output = $oCommentModel->getTotalCommentList($com_args); Context::set('newest_comments', $output->data); unset($args); $args->module_srl = $this->module_srl; $args->page = 1; $args->list_count = 5; $output = $oTextyleModel->getTextyleGuestbookList($args); Context::set('guestbook_list', $output->data); }
/** * Builds appropriate parameters for checking out to google and submits the post params. * * @param array $params * Name value pair of contribution data. * @param string $component * Event/contribution. * @param object $cart * Object of google cart. */ public function submitPostParams($params, $component, $cart) { $url = rtrim($this->_paymentProcessor['url_site'], '/') . '/cws/v2/Merchant/' . $this->_paymentProcessor['user_name'] . '/checkout'; if ($component == "event") { $privateData = "contactID={$params['contactID']},contributionID={$params['contributionID']},contributionTypeID={$params['contributionTypeID']},eventID={$params['eventID']},participantID={$params['participantID']},invoiceID={$params['invoiceID']}"; } elseif ($component == "contribute") { $privateData = "contactID={$params['contactID']},contributionID={$params['contributionID']},contributionTypeID={$params['contributionTypeID']},invoiceID={$params['invoiceID']}"; $contributionRecurID = CRM_Utils_Array::value('contributionRecurID', $params); if ($contributionRecurID) { $privateData .= ",contributionRecurID={$contributionRecurID}"; } $membershipID = CRM_Utils_Array::value('membershipID', $params); if ($membershipID) { $privateData .= ",membershipID={$membershipID}"; } $relatedContactID = CRM_Utils_Array::value('related_contact', $params); if ($relatedContactID) { $privateData .= ",relatedContactID={$relatedContactID}"; $onBehalfDupeAlert = CRM_Utils_Array::value('onbehalf_dupe_alert', $params); if ($onBehalfDupeAlert) { $privateData .= ",onBehalfDupeAlert={$onBehalfDupeAlert}"; } } } // Allow further manipulation of the arguments via custom hooks .. CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $privateData); $cart->SetMerchantPrivateData($privateData); if ($component == "event") { $returnURL = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE); } elseif ($component == "contribute") { $returnURL = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE); } $cart->SetContinueShoppingUrl($returnURL); $cartVal = base64_encode($cart->GetXML()); $signatureVal = base64_encode($cart->CalcHmacSha1($cart->GetXML())); $googleParams = array('cart' => $cartVal, 'signature' => $signatureVal); require_once 'HTTP/Request.php'; $params = array('method' => HTTP_REQUEST_METHOD_POST, 'allowRedirects' => FALSE); $request = new HTTP_Request($url, $params); foreach ($googleParams as $key => $value) { $request->addPostData($key, $value); } $result = $request->sendRequest(); if (PEAR::isError($result)) { CRM_Core_Error::fatal($result->getMessage()); } if ($request->getResponseCode() != 302) { CRM_Core_Error::fatal(ts('Invalid response code received from Google Checkout: %1', array(1 => $request->getResponseCode()))); } CRM_Utils_System::redirect($request->getResponseHeader('location')); CRM_Utils_System::civiExit(); }
function _request($url, $body = null, $content_type = 'text/html', $method = 'GET', $headers = array(), $cookies = array()) { set_include_path(_XE_PATH_ . "libs/PEAR"); require_once 'PEAR.php'; require_once 'HTTP/Request.php'; $url_info = parse_url($url); $host = $url_info['host']; if (__PROXY_SERVER__ !== null) { $oRequest = new HTTP_Request(__PROXY_SERVER__); $oRequest->setMethod('POST'); $oRequest->addPostData('arg', serialize(array('Destination' => $url, 'method' => $method, 'body' => $body, 'content_type' => $content_type, "headers" => $headers))); } else { $oRequest = new HTTP_Request($url); if (count($headers)) { foreach ($headers as $key => $val) { $oRequest->addHeader($key, $val); } } if ($cookies[$host]) { foreach ($cookies[$host] as $key => $val) { $oRequest->addCookie($key, $val); } } if (!$content_type) { $oRequest->addHeader('Content-Type', 'text/html'); } else { $oRequest->addHeader('Content-Type', $content_type); } $oRequest->setMethod($method); if ($body) { $oRequest->setBody($body); } } $oResponse = $oRequest->sendRequest(); $code = $oRequest->getResponseCode(); $header = $oRequest->getResponseHeader(); $response = $oRequest->getResponseBody(); if ($c = $oRequest->getResponseCookies()) { foreach ($c as $k => $v) { $cookies[$host][$v['name']] = $v['value']; } } if ($code > 300 && $code < 399 && $header['location']) { return $this->_request($header['location'], $body, $content_type, $method, $headers, $cookies); } if ($code != 200) { return; } return $response; }
/** * Fake a virtua login on the patron's behalf. * - Return a session id. * * @param array $patron Array with cat_username/cat_password keys * * @return string Session ID * @access private */ private function _fakeLogin($patron) { // Get the iPortal server $web_server = $this->_config['Catalog']['webhost']; $virtua_url = "http://{$web_server}/cgi-bin/chameleon"; $client = new HTTP_Request(); $client->setMethod(HTTP_REQUEST_METHOD_POST); $client->setURL($virtua_url); $client->addPostData("SourceScreen", "INITREQ"); $client->addPostData("conf", "./chameleon.conf"); $client->addPostData("elementcount", "1"); $client->addPostData("function", "PATRONATTEMPT"); $client->addPostData("host", $this->_config['Catalog']['host_string']); $client->addPostData("lng", "en"); $client->addPostData("login", "1"); $client->addPostData("pos", "1"); $client->addPostData("rootsearch", "KEYWORD"); $client->addPostData("search", "NOSRCH"); $client->addPostData("skin", "homepage"); $client->addPostData("patronid", $patron['cat_username']); $client->addPostData("patronpassword", $patron['cat_password']); $client->addPostData("patronhost", $this->_config['Catalog']['patron_host']); $result = $client->sendRequest(); $client->clearPostData(); if (!PEAR::isError($result)) { // Get the response $result = $client->getResponseBody(); // Now find the sessionid. There should be one in the meta tags, // so we can look for the first one in the document // eg. <meta http-equiv="Refresh" content="30000; // url=http://libwebtest2.usq.edu.au:80/cgi-bin/chameleon?sessionid= //2009071712483605131&skin=homepage&lng=en&inst= //consortium&conf=.%26%23047%3bchameleon.conf&timedout=1" /> $start = strpos($result, 'sessionid=') + 10; $end = strpos($result, '&skin='); return substr($result, $start, $end - $start); } }
// I wish API devs wouldn't be lazy, and support digest auth. // That way we wouldn't have to use a two-way encryption algorythm $p->addHeader('Authorization', 'Basic ' . base64_encode($auth["username"] . ":" . $auth["password"])); } // required for some ajax apis $p->addHeader("Referer", "http://" . $_SERVER['SERVER_NAME'] . "/"); $v = false; foreach ($_POST as $key => $value) { if ($key == "DESKTOP_XSITE_PARAMS" || $key == "dojo_preventCache") { continue; } if (!$v) { $v = true; $p->setMethod(HTTP_REQUEST_METHOD_POST); } $p->addPostData($key, $value); } foreach ($_GET as $key => $value) { if ($key == "DESKTOP_XSITE_PARAMS") { continue; } $p->addQueryString($key, $value); } $p->sendRequest(); $type = $p->getResponseHeader("Content-Type"); header("Content-Type: {$type}"); foreach (array("400" => "Bad syntax", "401" => "Unauthorized", "402" => "Not Used (Payment Granted)", "403" => "Forbidden", "404" => "Not Found", "500" => "Internal Error", "501" => "Not Implemented", "502" => "Overloaded", "503" => "Gateway Timeout") as $key => $value) { if ($p->getResponseCode() == $key) { header("HTTP/1.0 " . $key . " " . $value); } }
function replace ($photo, $photo_id, $async = null) { $upload_req = new HTTP_Request(); $upload_req->setMethod(HTTP_REQUEST_METHOD_POST); $upload_req->setURL($this->Replace); $upload_req->clearPostData(); //Process arguments, including method and login data. $args = array("api_key" => $this->api_key, "photo_id" => $photo_id, "async" => $async); if (!empty($this->email)) { $args = array_merge($args, array("email" => $this->email)); } if (!empty($this->password)) { $args = array_merge($args, array("password" => $this->password)); } if (!empty($this->token)) { $args = array_merge($args, array("auth_token" => $this->token)); } elseif (!empty($_SESSION['phpFlickr_auth_token'])) { $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token'])); } ksort($args); $auth_sig = ""; foreach ($args as $key => $data) { if ($data !== null) { $auth_sig .= $key . $data; $upload_req->addPostData($key, $data); } } if (!empty($this->secret)) { $api_sig = md5($this->secret . $auth_sig); $upload_req->addPostData("api_sig", $api_sig); } $photo = realpath($photo); $result = $upload_req->addFile("photo", $photo); if (PEAR::isError($result)) { die($result->getMessage()); } //Send Requests if ($upload_req->sendRequest()) { $this->response = $upload_req->getResponseBody(); } else { die("There has been a problem sending your command to the server."); } if ($async == 1) $find = 'ticketid'; else $find = 'photoid'; $rsp = explode("\n", $this->response); foreach ($rsp as $line) { if (ereg('<err code="([0-9]+)" msg="(.*)"', $line, $match)) { if ($this->die_on_error) die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}"); else { $this->error_code = $match[1]; $this->error_msg = $match[2]; $this->parsed_response = false; return false; } } elseif (ereg("<" . $find . ">(.*)</", $line, $match)) { $this->error_code = false; $this->error_msg = false; return $match[1]; } } }