<?php 

class curl {
	static $headers;
	static $user_agent;
	static $compression;
	static $cookie_file;
	static $proxy;
	static $cookies;
	private static function curl_init($cookies=TRUE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
		self::$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
		self::$headers[] = 'Connection: Keep-Alive';
		self::$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
		self::$user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0a2) Gecko/20110613 Firefox/6.0a2';
		self::$compression=$compression;
		self::$proxy=$proxy;
		self::$cookies=$cookies;
		if (self::$cookies == TRUE) self::cookie($cookie);
	}
	public static function cookie($cookie_file) {
		if (file_exists($cookie_file)) {
			self::$cookie_file=$cookie_file;
		} else {
			fopen($cookie_file,'w') or self::error('The cookie file could not be opened. Make sure this directory has the correct permissions');
			self::$cookie_file=$cookie_file;
			fclose(self::$cookie_file);
		}
	}
	public static function get($url) {
		self::curl_init();
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, self::$headers);
		curl_setopt($process, CURLOPT_HEADER, 0);
		curl_setopt($process, CURLOPT_USERAGENT, self::$user_agent);
		if (self::$cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, self::$cookie_file);
		if (self::$cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, self::$cookie_file);
		curl_setopt($process,CURLOPT_ENCODING , self::$compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		if (self::$proxy) curl_setopt($process, CURLOPT_PROXY, self::$proxy);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		//curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}
	public static function post($url,$data) {
		self::curl_init();
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, self::$headers);
		curl_setopt($process, CURLOPT_HEADER, 0);
		curl_setopt($process, CURLOPT_USERAGENT, self::$user_agent);
		if (self::$cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, self::$cookie_file);
		if (self::$cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, self::$cookie_file);
		curl_setopt($process, CURLOPT_ENCODING , self::$compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		if (self::$proxy) curl_setopt($process, CURLOPT_PROXY, self::$proxy);
		curl_setopt($process, CURLOPT_POSTFIELDS, $data);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		//curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($process, CURLOPT_POST, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}
	public static function error($error) {
		echo "<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
		die;
	}
} 
?>