Example #1
0
	function ajax_download_google_fonts() {
		include_once($this->path . '/pages/usquare_http_functions.php');
		$fonts=usquare_get_http ('http://www.shindiristudio.com/responder/fonts.txt', 8);
		$now = date('m-Y');
		if (strlen($fonts)>1000) {
			$this -> add_settings(array(
				'google_fonts' => $fonts,
				'google_fonts_update' => $now
			));
		}
		die();
	}
Example #2
0
function usquare_get_http ($url, $timeout=20, $redirect=0, $POST="", $referer="", $cookie="")
{
	global $usquare_http_cache, $usquare_http_host, $usquare_http_folder, $usquare_http_ext, $usquare_http_filename, $usquare_http_filetype, $usquare_http_header, $usquare_http_length, $usquare_http_response_code, $usquare_http_redirection_list, $usquare_udarac, $usquare_dont_cache_http, $usquare_http_sent_header, $usquare_http_echo;
	
	if ($POST=="") $method="GET";
	else $method="POST";
	
	$burl=$url;
	$usquare_http_response_code=0;

	if ($url==NULL) {if ($usquare_http_echo==1) echo 'empty URL cannot be downloaded[1].\n'; return "";}
	if ($url=="") {if ($usquare_http_echo==1) echo 'empty URL cannot be downloaded[2].\n'; return "";}
	$url=str_replace(" ", "%20", $url);

	if ($redirect==0)
	{
	    if (isset($usquare_http_redirection_list)) unset ($usquare_http_redirection_list);
	    $usquare_http_redirection_list=array();
	}
	else
	{
	    if (isset($usquare_http_redirection_list[$url]))
	    {
		    if (!isset($usquare_udarac)) $usquare_udarac=0;
		    $usquare_udarac++;
		   	if ($usquare_udarac==3) {if ($usquare_http_echo==1) echo "detected redirection loop\n"; return "";}
	    }
	    $usquare_http_redirection_list[$url]=1;
	}
	
	$pp=strpos($url, "#");
	if ($pp!==FALSE) $url=substr($url, 0, $pp);

	if (!isset($usquare_dont_cache_http)) if (isset($usquare_http_cache[$url])) return $usquare_http_cache[$url];
	$p1=strpos($url, "/", 7);
	$p2=strrpos($url, "/");
	
	$port=80;

	$pp=strpos($url, ":", 7);
	if ($pp!==FALSE)
	{
		if ($pp<$p1)
		{
			$port=substr($url, $pp+1, $p1-$pp-1);
			$port=intval($port);
		}
	}
	
	if ($p1===FALSE)
	{
		return file_get_contents($burl);
	}
	
	if ($port==80) $myhost=substr($url, 7, $p1-7);
	else $myhost=substr($url, 7, $pp-7);
	$myhost=str_replace ("www.yu", "WWW.YU", $myhost);
	$myhost=str_replace (".co.yu", ".rs", $myhost);
	$myhost=str_replace (".yu", ".rs", $myhost);
	$myhost=str_replace ("WWW.YU", "www.yu", $myhost);
	$usquare_http_host=$myhost;
	$myscript=substr($url, $p1);

	if (strpos($myscript, "//")!==FALSE)
	{
		$myscriptN="";
		$ok=1;
		$myscriptLEN = strlen($myscript);
		for ($i=0; $i<$myscriptLEN; $i++)
		{
			if ($ok==1 && $i+1<$myscriptLEN) if (substr($myscript, $i, 2)=="//") continue;
			if (substr($myscript, $i, 1)=="?") $ok=0;
			$myscriptN.=substr($myscript, $i, 1);
		}
		$myscript=$myscriptN;
	}

	$usquare_http_ext=usquare_get_url_extension ($myscript);
	$usquare_http_filename=usquare_get_url_filename ($myscript);
	$usquare_http_filetype=usquare_get_url_ext_type ($usquare_http_ext);
	
	if ($p1==$p2) $usquare_http_folder="";
	else
	{
		$starth=strlen($usquare_http_host)+8;
		$usquare_http_folder=substr($url, $starth, $p2-$starth+1);
	}
//	echo "folder='".$usquare_http_folder."'"; exit;
	if ($usquare_http_echo==1) echo "Downloading URL: ".$url."\n";

	$fp = @fsockopen($myhost, $port, $errno, $errstr, $timeout);
	if ($fp)
	{
		$myscript=str_replace (chr(9), "", $myscript);
		$myscript=str_replace (chr(10), "", $myscript);
		$myscript=str_replace (chr(13), "", $myscript);
		stream_set_timeout($fp, $timeout);
		$usquare_http_sent_header = '';
		$usquare_http_sent_header .= $method." ".$myscript." HTTP/1.0\r\n";
		$usquare_http_sent_header .= "Host: ".$myhost."\r\n";
		$usquare_http_sent_header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2\r\n";
		$usquare_http_sent_header .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n";
		$usquare_http_sent_header .= "Accept-Language: en-us,en;q=0.5\r\n";
		//$usquare_http_sent_header .= "Accept-Encoding: gzip,deflate\r\n";
		$usquare_http_sent_header .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
		if ($referer!="") $usquare_http_sent_header .= "Referer: ".$referer."\r\n";
		if ($cookie!="") $usquare_http_sent_header .= "Cookie: ".$cookie."\r\n";
		$usquare_http_sent_header .= "Connection: close\r\n";
		if ($POST!="")
		{
			$usquare_http_sent_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
			$usquare_http_sent_header .= "Content-Length: ".strlen($POST)."\r\n\r\n";
			$usquare_http_sent_header .= $POST;
		}
		$usquare_http_sent_header .= "\r\n";
		fputs($fp, $usquare_http_sent_header);

		$pass_counter=0;
		$sadrzaj="";
		$goth=0;
		$tb="";
		$usquare_http_header="";
		$usquare_http_length=0;
		$usquare_http_response_code=0;
        if (is_resource($fp))
        {
            while ($data = fread($fp, 4096))
            {
	            $pass_counter++;
	            if ($goth==0)
	            {
		            	$tb.=$data;
		            	$movepnt=4;
		            	$p1=strpos($tb, "\r\n\r\n");
		            	if ($p1===FALSE) {$p1=strpos($tb, "\n\n"); $movepnt=2;}
		            	if ($p1!==FALSE)
		            	{
			            	$goth=1;
			            	$usquare_http_header=substr($tb, 0, $p1);
//			            	echo "\n---\n".$usquare_http_header."\n---\n";
			            	
			            	$usquare_http_response_code=usquare_get_http_response_code($usquare_http_header);
							if ($usquare_http_response_code==301 || $usquare_http_response_code==302)
							{
							    $url=usquare_get_http_header_value($usquare_http_header, 'Location');
							    if ($url=='') $url=usquare_get_http_header_value($usquare_http_header, 'location');
							    if ($url!='')
							    {
								    if (substr($url, 0, 1)=="/") $url="http://".$myhost.$url;
								    elseif (substr($url, 0, 4)!="http") $url="http://".$myhost."/".$usquare_http_folder.$url;
								    if ($usquare_http_echo==1) echo "redirect = '".$url."'\n";
								    $usquare_http_redirection_list[$burl]=1;
								    return usquare_get_http ($url, $timeout, 1);
							    }
							}
			            	$data=substr($tb, $p1+$movepnt);
		            	}
		            	else continue;
	            }

	            $sadrzaj.=$data;
            }
            if ($sadrzaj=="")
            {
	            $usquare_http_length=0;
	            if (!isset($usquare_dont_cache_http)) $usquare_http_cache[$url]=""; //$usquare_http_header;
	            @fclose($fp);
	            return "";
            }
            if (!isset($usquare_dont_cache_http)) if ($usquare_http_filetype=="html") $usquare_http_cache[$url]=$sadrzaj;
            $usquare_http_length=strlen($sadrzaj);
            @fclose($fp);
            return $sadrzaj;
        }
        else
		{
			$usquare_http_length=0;
			if ($usquare_http_echo==1) echo '"'.$url.'" cannot be downloaded[3].'; 
			if (!isset($usquare_dont_cache_http)) $usquare_http_cache[$url]="";
			@fclose($fp);
			return "";
		}
	}
	else
	{
		$usquare_http_length=0;
		if ($usquare_http_echo==1) echo '"'.$url.'" cannot be downloaded[4].'; 
		if (!isset($usquare_dont_cache_http)) $usquare_http_cache[$url]="";
		@fclose($fp);
		return "";
	}
}