Index: trunk/core/units/general/helpers/curl_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/curl_helper.php (revision 7997) +++ trunk/core/units/general/helpers/curl_helper.php (revision 0) @@ -1,198 +0,0 @@ -debugMode = $this->Application->isDebugMode(false) && constOn('DBG_CURL'); - } - - function SetOptions() - { - // customizable options - curl_setopt($this->connectionID, CURLOPT_FOLLOWLOCATION, $this->followLocation ? 1 : 0); - curl_setopt($this->connectionID, CURLOPT_TIMEOUT, $this->timeout); - - // hardcoded options - curl_setopt($this->connectionID, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($this->connectionID, CURLOPT_REFERER, PROTOCOL.SERVER_NAME); - curl_setopt($this->connectionID, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); - - if ($this->requestHeaders) { - curl_setopt($this->connectionID, CURLOPT_HTTPHEADER, $this->prepareHeaders()); - } - - // if we have post data, then POST else use GET method instead - if ($this->postData) { - curl_setopt($this->connectionID, CURLOPT_POST, 1); - curl_setopt($this->connectionID, CURLOPT_POSTFIELDS, $this->postData); - } - -// curl_setopt($this->connectionID, CURLOPT_HEADERFUNCTION, Array(&$this, 'ParseHeader')); - } - - function ParseHeader(&$ch, $header) - { - $this->responceHeaders[] = $header; - return strlen($header); - } - - /** - * Sets POST data for next query - * - * @param mixed $post_data Array or string - */ - function SetPostData($post_data) - { - if (is_array($post_data)) { - $params_str = ''; - foreach ($post_data as $key => $value) { - $params_str .= $key.'='.urlencode($value).'&'; - } - $post_data = $params_str; - } - - $this->postData = $post_data; - } - - function SetHeaders($headers) - { - $this->requestHeaders = array_merge_recursive2($this->requestHeaders, $headers); - } - - function SetHeader($name, $value) - { - $this->requestHeaders[$name] = $value; - } - - /** - * Returns compiled header to be used by curl - * - * @return Array - */ - function prepareHeaders() - { - $ret = Array (); - foreach ($this->requestHeaders as $header_name => $header_value) { - $ret[] = $header_name.': '.$header_value; - } - return $ret; - } - - function Send($url) - { - $this->connectionID = curl_init($url); - - if ($this->debugMode) { - safeDefine('DBG_CURL_LOGFILE', '/curl.log'); - $this->logFilePointer = fopen(FULL_PATH.DBG_CURL_LOGFILE, 'a'); - - curl_setopt($this->connectionID, CURLOPT_FILE, $this->logFilePointer); - curl_setopt($this->connectionID, CURLOPT_VERBOSE, true); - curl_setopt($this->connectionID, CURLOPT_STDERR, $this->logFilePointer); - //curl_setopt($this->connectionID, CURLOPT_WRITEHEADER, $this->logFilePointer); - } - - $this->responceHeaders = Array (); - - $this->SetOptions(); - $this->lastRespoce = curl_exec($this->connectionID); - $this->Finalize(); - - return $this->lastRespoce; - } - - function Finalize() - { - $this->lastErrorCode = curl_errno($this->connectionID); - $this->lastErrorMsg = curl_error($this->connectionID); - $this->lastHTTPCode = curl_getinfo($this->connectionID, CURLINFO_HTTP_CODE); - - if ($this->debugMode) { - fwrite($this->logFilePointer, "\n".$this->lastRespoce); - fclose($this->logFilePointer); - } - - curl_close($this->connectionID); - $this->postData = ''; - $this->requestHeaders = Array (); - } - } - -?> \ No newline at end of file