diff --git a/repository/curl.class.php b/repository/curl.class.php index 92be67caffa..7765063e196 100644 --- a/repository/curl.class.php +++ b/repository/curl.class.php @@ -25,41 +25,43 @@ */ class curl { - private $options; public $cache = false; public $proxy = false; - private $proxy_host = ''; - private $proxy_auth = ''; - private $proxy_type = ''; - private $debug = false; - private $cookie = false; public $version = '0.4 dev'; public $response = array(); public $header = array(); public $info; public $error; + + private $options; + private $proxy_host = ''; + private $proxy_auth = ''; + private $proxy_type = ''; + private $debug = false; + private $cookie = false; + public function __construct($options = array()){ global $CFG; - if(!function_exists('curl_init')) { + if (!function_exists('curl_init')) { $this->error = 'cURL module must be enabled!'; trigger_error($this->error, E_USER_ERROR); return false; } // the options of curl should be init here. $this->resetopt(); - if(!empty($options['debug'])) { + if (!empty($options['debug'])) { $this->debug = true; } - if(!empty($options['cookie'])) { + if (!empty($options['cookie'])) { $this->cookie = $options['cookie']; } - if(!empty($options['cache'])) { - if(class_exists('repository_cache')) { + if (!empty($options['cache'])) { + if (class_exists('repository_cache')) { $this->cache = new repository_cache; } } - if(!empty($options['proxy'])) { - if(!empty($CFG->proxyhost)) { + if (!empty($options['proxy'])) { + if (!empty($CFG->proxyhost)) { if (empty($CFG->proxyport)) { $this->proxy_host = $CFG->proxyhost; } else { @@ -72,7 +74,7 @@ class curl { 'proxyuserpwd'=>$this->proxy_auth)); } if (!empty($CFG->proxytype)) { - if($CFG->proxytype == 'SOCKS5') { + if ($CFG->proxytype == 'SOCKS5') { $this->proxy_type = CURLPROXY_SOCKS5; } else { $this->proxy_type = CURLPROXY_HTTP; @@ -117,10 +119,10 @@ class curl { * */ public function resetcookie() { - if(!empty($this->cookie)) { - if(is_file($this->cookie)) { + if (!empty($this->cookie)) { + if (is_file($this->cookie)) { $fp = fopen($this->cookie, 'w'); - if(!empty($fp)) { + if (!empty($fp)) { fwrite($fp, ''); fclose($fp); } @@ -138,7 +140,7 @@ class curl { public function setopt($options = array()) { if (is_array($options)) { foreach($options as $name => $val){ - if(stripos($name, 'CURLOPT_') === false) { + if (stripos($name, 'CURLOPT_') === false) { $name = strtoupper('CURLOPT_'.$name); } $this->options[$name] = $val; @@ -192,8 +194,8 @@ class curl { if (strlen($header) > 2) { list($key, $value) = explode(" ", rtrim($header, "\r\n"), 2); $key = rtrim($key, ':'); - if(!empty($this->response[$key])) { - if(is_array($this->response[$key])){ + if (!empty($this->response[$key])) { + if (is_array($this->response[$key])){ $this->response[$key][] = $value; } else { $tmp = $this->response[$key]; @@ -216,21 +218,21 @@ class curl { // Clean up $this->cleanopt(); // set cookie - if(!empty($this->cookie) || !empty($options['cookie'])) { + if (!empty($this->cookie) || !empty($options['cookie'])) { $this->setopt(array('cookiejar'=>$this->cookie, 'cookiefile'=>$this->cookie )); } // set proxy - if(!empty($this->proxy) || !empty($options['proxy'])) { + if (!empty($this->proxy) || !empty($options['proxy'])) { $this->setopt($this->proxy); } $this->setopt($options); // reset before set options curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this,'formatHeader')); // set headers - if(empty($this->header)){ + if (empty($this->header)){ $this->setHeader(array( 'User-Agent: MoodleBot/1.0', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', @@ -239,7 +241,7 @@ class curl { } curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header); - if($this->debug){ + if ($this->debug){ echo '