Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/curl_helper.php
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
protected function _resetSettings() | protected function _resetSettings() | ||||
{ | { | ||||
$this->timeout = 90; | $this->timeout = 90; | ||||
$this->followLocation = false; | $this->followLocation = false; | ||||
$this->requestMethod = self::REQUEST_METHOD_GET; | $this->requestMethod = self::REQUEST_METHOD_GET; | ||||
$this->requestData = ''; | $this->requestData = ''; | ||||
$this->requestHeaders = Array (); | $this->requestHeaders = Array (); | ||||
$this->responseHeaders = Array (); | |||||
$this->options = Array (); | $this->options = Array (); | ||||
} | } | ||||
/** | /** | ||||
* Resets information in last* properties. | * Resets information in last* properties. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
// if we have post data, then POST else use GET method instead | // if we have post data, then POST else use GET method instead | ||||
if ($this->requestMethod == self::REQUEST_METHOD_POST) { | if ($this->requestMethod == self::REQUEST_METHOD_POST) { | ||||
$default_options[CURLOPT_POST] = 1; | $default_options[CURLOPT_POST] = 1; | ||||
$default_options[CURLOPT_POSTFIELDS] = $this->requestData; | $default_options[CURLOPT_POSTFIELDS] = $this->requestData; | ||||
} | } | ||||
// $default_options[CURLOPT_HEADERFUNCTION] = Array(&$this, 'ParseHeader'); | $default_options[CURLOPT_HEADERFUNCTION] = array(&$this, 'ParseHeader'); | ||||
$user_options = $this->options; // backup options, that user set directly | $user_options = $this->options; // backup options, that user set directly | ||||
$this->setOptions($default_options); | $this->setOptions($default_options); | ||||
$this->setOptions($user_options); | $this->setOptions($user_options); | ||||
$this->applyOptions(); | $this->applyOptions(); | ||||
} | } | ||||
/** | /** | ||||
Show All 13 Lines | |||||
* | * | ||||
* @param resource $ch | * @param resource $ch | ||||
* @param string $header | * @param string $header | ||||
* @return int | * @return int | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function ParseHeader(&$ch, $header) | protected function ParseHeader(&$ch, $header) | ||||
{ | { | ||||
$this->responseHeaders[] = $header; | $trimmed_header = rtrim($header); | ||||
if ( $trimmed_header ) { | |||||
$this->responseHeaders[] = $trimmed_header; | |||||
} | |||||
return strlen($header); | return strlen($header); | ||||
} | } | ||||
/** | /** | ||||
* Sets request data for next query | * Sets request data for next query | ||||
* | * | ||||
* @param mixed $data Array or string | * @param mixed $data Array or string | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | |||||
'RequestData' => $this->requestData, | 'RequestData' => $this->requestData, | ||||
'RequestDate' => adodb_mktime(), | 'RequestDate' => adodb_mktime(), | ||||
); | ); | ||||
$this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'CurlLog'); | $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'CurlLog'); | ||||
$this->logId = $this->Conn->getInsertID(); | $this->logId = $this->Conn->getInsertID(); | ||||
} | } | ||||
$this->responseHeaders = Array (); | |||||
$this->prepareOptions(); | $this->prepareOptions(); | ||||
$this->lastResponse = $this->_sendRequest(); | $this->lastResponse = $this->_sendRequest(); | ||||
$this->Finalize($close_connection); | $this->Finalize($close_connection); | ||||
return $this->lastResponse; | return $this->lastResponse; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
if ( $info_type == CURLINFO_REDIRECT_COUNT && $this->followLocationLimited() ) { | if ( $info_type == CURLINFO_REDIRECT_COUNT && $this->followLocationLimited() ) { | ||||
return $this->lastRedirectCount; | return $this->lastRedirectCount; | ||||
} | } | ||||
return curl_getinfo($this->connectionID, $info_type); | return curl_getinfo($this->connectionID, $info_type); | ||||
} | } | ||||
/** | /** | ||||
* Returns response headers. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public function getResponseHeaders() | |||||
{ | |||||
return $this->responseHeaders; | |||||
} | |||||
/** | |||||
* Detects, that follow location can't be done automatically by curl due safe_mode/open_basedir restrictions | * Detects, that follow location can't be done automatically by curl due safe_mode/open_basedir restrictions | ||||
* | * | ||||
* @return bool | * @return bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function followLocationLimited() | protected function followLocationLimited() | ||||
{ | { | ||||
return (defined('SAFE_MODE') && SAFE_MODE) || ini_get('open_basedir'); | return (defined('SAFE_MODE') && SAFE_MODE) || ini_get('open_basedir'); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
public function isGoodResponseCode() | public function isGoodResponseCode() | ||||
{ | { | ||||
if ( $this->lastErrorCode != 0 ) { | if ( $this->lastErrorCode != 0 ) { | ||||
return false; | return false; | ||||
} | } | ||||
return ($this->lastHTTPCode == 200) || ($this->lastHTTPCode >= 300 && $this->lastHTTPCode < 310); | return ($this->lastHTTPCode == 200) || ($this->lastHTTPCode >= 300 && $this->lastHTTPCode < 310); | ||||
} | } | ||||
} | } | ||||
No newline at end of file |