Index: branches/RC/core/units/general/helpers/curl_helper.php =================================================================== diff -u -r9308 -r10299 --- branches/RC/core/units/general/helpers/curl_helper.php (.../curl_helper.php) (revision 9308) +++ branches/RC/core/units/general/helpers/curl_helper.php (.../curl_helper.php) (revision 10299) @@ -69,6 +69,8 @@ var $responceHeaders = Array (); + var $options = Array (); + /** * Indicates debug mode status * @@ -83,30 +85,46 @@ $this->debugMode = $this->Application->isDebugMode(false) && constOn('DBG_CURL'); } - function SetOptions() + function setOptions($options_hash) { - // customizable options - curl_setopt($this->connectionID, CURLOPT_FOLLOWLOCATION, $this->followLocation ? 1 : 0); - curl_setopt($this->connectionID, CURLOPT_TIMEOUT, $this->timeout); + $this->options = array_merge_recursive2($this->options, $options_hash); + } - // 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']); + function prepareOptions() + { + $default_options = Array ( + // customizable options + CURLOPT_FOLLOWLOCATION => $this->followLocation ? 1 : 0, + CURLOPT_TIMEOUT => $this->timeout, + // hardcoded options + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_REFERER => PROTOCOL.SERVER_NAME, + CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], + ); + if ($this->requestHeaders) { - curl_setopt($this->connectionID, CURLOPT_HTTPHEADER, $this->prepareHeaders()); + $default_options[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); + $default_options[CURLOPT_POST] = 1; + $default_options[CURLOPT_POSTFIELDS] = $this->postData; } -// curl_setopt($this->connectionID, CURLOPT_HEADERFUNCTION, Array(&$this, 'ParseHeader')); +// $default_options[CURLOPT_HEADERFUNCTION] = Array(&$this, 'ParseHeader'); + $this->setOptions($default_options); + $this->applyOptions(); } + function applyOptions() + { + foreach ($this->options as $option_name => $option_value) { + curl_setopt($this->connectionID, $option_name, $option_value); + } + } + function ParseHeader(&$ch, $header) { $this->responceHeaders[] = $header; @@ -171,7 +189,7 @@ $this->responceHeaders = Array (); - $this->SetOptions(); + $this->prepareOptions(); $this->lastRespoce = curl_exec($this->connectionID); $this->Finalize($close_connection);