Файл: Luxe-Shop v6.0/application/helpers/curl.class.php
Строк: 199
<?php
class curl {
var $ch;
var $httpget = '';
var $head = '';
var $postparams = array ();
var $httpheader = array ();
var $cookie = array ();
var $proxy = '';
var $proxy_user_data = '';
var $verbose = 0;
var $referer = '';
var $autoreferer = 0;
var $writeheader = '';
var $agent = 'Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0';
var $url = '';
var $followlocation = 0;
var $returntransfer = 1;
var $ssl_verifypeer = 0;
var $ssl_verifyhost = 2;
var $sslcert = '';
var $sslkey = '';
var $cainfo = '';
var $cookiefile = '';
var $timeout = 0;
var $connect_time = 0;
var $encoding = 'deflate';
var $interface = '';
function __construct (){
$this->ch = curl_init();
$this->set_httpheader(array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3','Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'));
}
function get ($url){
$this->url = $url;
return $this->exec();
}
function post ($url, $postparams, $enctype = false){
$this->url = $url;
if (!$enctype) {
$this->postparams = $postparams;
}
else {
$this->postparams = array ();
$params = explode("&", $postparams);
for($i = 0; $i < count($params); $i++) {
list($name, $value) = explode("=", $params[$i]);
$this->postparams[$name] = $value;
}
}
return $this->exec();
}
function set_httpget ($httpget){
$this->httpget = $httpget;
}
function set_referer ($referer){
$this->referer = $referer;
}
function set_autoreferer ($autoreferer){
$this->autoreferer = $autoreferer;
}
function set_useragent ($agent){
$this->agent = $agent;
}
function set_cookie (){
preg_match_all('/Set-Cookie: (.*?)=(.*?);/i', $this->head, $matches, PREG_SET_ORDER);
for ($i = 0; $i < count($matches); $i++) {
$this->cookie[$matches[$i][1]] = $matches[$i][2];
}
}
function add_cookie ($cookie){
foreach ($cookie as $name => $value) {
$this->cookie[$name] = $value;
}
}
function delete_cookie ($name){
if (isset($this->cookie[$name]))
unset($this->cookie[$name]);
}
function get_cookie (){
return $this->cookie;
}
function clear_cookie (){
$this->cookie = array ();
}
function set_httpheader ($httpheader){
$this->httpheader = $httpheader;
}
function clear_httpheader (){
$this->httpheader = array ();
}
function set_head ($head){
$this->head = $head;
}
function set_encoding ($encoding){
$this->encoding = $encoding;
}
function set_interface ($interface){
$this->interface = $interface;
}
function set_writeheader ($writeheader){
$this->writeheader = $writeheader;
}
function set_followlocation ($followlocation){
$this->followlocation = $followlocation;
}
function set_returntransfer ($returntransfer){
$this->returntransfer = $returntransfer;
}
function set_ssl_verifypeer ($ssl_verifypeer){
$this->ssl_verifypeer = $ssl_verifypeer;
}
function set_ssl_verifyhost ($ssl_verifyhost){
$this->ssl_verifyhost = $ssl_verifyhost;
}
function set_sslcert ($sslcert) {
$this->sslcert = $sslcert;
}
function set_sslkey ($sslkey) {
$this->sslkey = $sslkey;
}
function set_cainfo ($cainfo) {
$this->cainfo = $cainfo;
}
function set_timeout ($timeout){
$this->timeout = $timeout;
}
function set_connect_time ($connect_time){
$this->connect_time = $connect_time;
}
function set_cookiefile ($cookiefile){
$this->cookiefile = $cookiefile;
}
function set_proxy ($proxy){
$this->proxy = $proxy;
}
function set_proxy_auth ($proxy_user_data){
$this->proxy_user_data = $proxy_user_data;
}
function set_verbose ($verbose){
$this->verbose = $verbose;
}
function get_error (){
return curl_errno($this->ch);
}
function get_location (){
$result = '';
if (preg_match("/Location: (.*?)rn/is", $this->head, $matches)) {
$result = end($matches);
}
return $result;
}
function get_http_state (){
if (curl_getinfo($this->ch, CURLINFO_HTTP_CODE) == 200) {
return true;
} else {
return false;
}
}
function get_speed_download (){
return curl_getinfo($this->ch, CURLINFO_SPEED_DOWNLOAD);
}
function get_content_type (){
return curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
}
function get_url (){
return curl_getinfo($this->ch, CURLINFO_EFFECTIVE_URL);
}
function join_cookie() {
$tcookie = array ();
foreach ($this->cookie as $key => $value)
$tcookie[] = "$key=$value";
return join('; ', $tcookie);
}
function exec (){
curl_setopt($this->ch, CURLOPT_USERAGENT, $this->agent);
curl_setopt($this->ch, CURLOPT_AUTOREFERER, $this->autoreferer);
curl_setopt($this->ch, CURLOPT_ENCODING, $this->encoding);
curl_setopt($this->ch, CURLOPT_URL, $this->url);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION , $this->followlocation);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,$this->returntransfer);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, $this->ssl_verifyhost);
curl_setopt($this->ch, CURLOPT_HEADER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->connect_time);
curl_setopt($this->ch, CURLOPT_VERBOSE, $this->verbose);
curl_setopt($this->ch, CURLOPT_POST, 0);
if ($this->referer)
curl_setopt($this->ch, CURLOPT_REFERER, $this->referer);
if ($this->interface)
curl_setopt($this->ch, CURLOPT_INTERFACE, $this->interface);
if ($this->httpget)
curl_setopt($this->ch, CURLOPT_HTTPGET, $this->httpget);
if ($this->writeheader != '')
curl_setopt($this->ch, CURLOPT_WRITEHEADER, $this->writeheader);
if ($this->postparams) {
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->postparams);
}
if ($this->proxy)
curl_setopt($this->ch, CURLOPT_PROXY, $this->proxy);
if ($this->proxy_user_data)
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $this->proxy_user_data);
if ($this->cookie)
curl_setopt($this->ch, CURLOPT_COOKIE, $this->join_cookie());
if (count($this->httpheader))
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->httpheader);
if ($this->sslcert)
curl_setopt($this->ch, CURLOPT_SSLCERT, $this->sslcert);
if ($this->sslkey)
curl_setopt($this->ch, CURLOPT_SSLKEY, $this->sslkey);
if ($this->cainfo)
curl_setopt($this->ch, CURLOPT_CAINFO, $this->cainfo);
if ($this->cookiefile) {
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookiefile);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookiefile);
}
$response = curl_exec($this->ch);
$this->set_head(substr($response, 0, curl_getinfo($this->ch, CURLINFO_HEADER_SIZE)));
$response = substr($response, curl_getinfo($this->ch, CURLINFO_HEADER_SIZE));
$this->set_cookie();
$this->postparams = array ();
return $response;
}
function __destruct (){
curl_close($this->ch);
}
}
?>