<?
/*
* @Author Keith Kurson
* @Date January 26th, 2009
* @Version 0.1
* @Email keith@keithkurson.net
*
* This is a cURL class that is based (mostly just touched up) from a previous cURL class I wrote in October of 2006. 
* That class can be found at: http://www.keithkurson.net/curl.phps
* To be added:
*    - Check if the cookies file exists, and if not, create it.
*    - Make the script chmod the cookie file to the correct permissions.
*    - If not possible, use the FTP functions to do it. 

*
*/

class cURL
{
    
// Header Information
    
private $headers = array("Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg","Connection: Keep-Alive","Content-type: application/x-www-form-urlencoded");
    
// User Agent information
    
private $user_agent 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
    
// Level of compression
    
private $compression 'gzip';
    
// Cookie Enabled/Disabled
    
private $cookie TRUE;
    
// Cookie File
    
private $cookie_file 'cookies.txt';
    
// Proxy
    
private $proxy;
    
// FTP Information
    
private $ftp_username;
    private 
$ftp_password;
    private 
$ftp_host;
    
// User / Password information for HTTP Authentication
    
private $username;
    private 
$password;
    
    public function 
__construct()
    {
        if (!
function_exists('curl_setopt'))
            
$this->error('You do not have the <b>cURL</b> package compiled with PHP. Please contact your host.');
    }
    
    public function 
setCookieInformation($cookie_file)
    {
        
$this->cookie TRUE;
        
$this->cookie_file 'cookies.txt';
    }
    
    public function 
setProxy($ip,$port)
    {
        
$this->proxy $ip.':'.$port;
        return 
true;
    }
    
    public function 
setUser($username,$password)
    {
        
$this->username $username;
        
$this->password $password;
    }
    
    public function 
get($url,$refer='')
    {
        
$page curl_init($url);
        
curl_setopt($pageCURLOPT_REFERER$refer);
        
curl_setopt($pageCURLOPT_HTTPHEADER$this->headers);
        
curl_setopt($pageCURLOPT_USERAGENT$this->user_agent);
        if (
$this->cookie == TRUE
        {
            
curl_setopt($pageCURLOPT_COOKIEFILE$this->cookie_file);
            
curl_setopt($pageCURLOPT_COOKIEJAR$this->cookie_file);
        }
        
curl_setopt($pageCURLOPT_ENCODING$this->compression);
        if (
$this->proxy
        {
            
curl_setopt($pageCURLOPT_PROXY$this->proxy);
        }
        
curl_setopt($pageCURLOPT_TIMEOUT30);
        
curl_setopt($pageCURLOPT_RETURNTRANSFER1);
        if (
$this->username)
        {
            
curl_setopt($page,CURLOPT_USERPWD,$this->username ":" $this->password);
        }
        
$return curl_exec($page);
        
curl_close($page);
        return 
$return;
    }
    
    public function 
post($url,$data,$refer)
    {
        
$page curl_init($url);
        
curl_setopt($pageCURLOPT_REFERER$refer);
        
curl_setopt($pageCURLOPT_HTTPHEADER$this->headers);
        
curl_setopt($pageCURLOPT_USERAGENT$this->user_agent);
        if (
$this->cookie == TRUE
        {
            
curl_setopt($pageCURLOPT_COOKIEFILE$this->cookie_file);
            
curl_setopt($pageCURLOPT_COOKIEJAR$this->cookie_file);
        }
        
curl_setopt($pageCURLOPT_ENCODING$this->compression);
        if (
$this->proxy
        {
            
curl_setopt($ch,CURLAUTH_NTLM);
            
curl_setopt($pageCURLOPT_PROXY$this->proxy);
        }
        
curl_setopt($pageCURLOPT_POSTFIELDS$data);
        
curl_setopt($pageCURLOPT_TIMEOUT30);
        
curl_setopt($pageCURLOPT_RETURNTRANSFER1);
        
curl_setopt($pageCURLOPT_FOLLOWLOCATION1);
        if (
$this->username)
        {
            
curl_setopt($page,CURLOPT_USERPWD,$this->username ":" $this->password);
        }
        
curl_setopt($pageCURLOPT_POST1);
        
$return curl_exec($page);
        
curl_close($page);
        return 
$return;
    }
}


?>