Location: PHPKode > scripts > YahooStatus > yahoostatus/includes/YahooStatus.Class.php
<?

//=============================//
//                             //
//   YahooStatus v0.1          //
//   YahooStatus Class file    //
//   YahooStatus.Class.php     //
//   by Stanga Razvan          //
//   hide@address.com   //
//   http://venom.gent00.org   //
//                             //
//       MADE IN ROMANIA       //
//                             //
//=============================//

class YahooStatus {

    var $config;
    var $status = 0;


//----------
// Get Image
//----------

function getImage () {
	
	            $image_url = 'http://opi.yahoo.com/online?u='.$this->config['screenname'].'&m=g&t=0';

				preg_match("/^(http:\/\/)?([\w\-\.]+)\:?([0-9]*)\/(.*)$/", $image_url, $url_ary);

					$port = (!empty($url_ary[3])) ? $url_ary[3] : 80;

					$base_get = "/" . $url_ary[4];

					if ($Type == 0) {$base_get = substr ($base_get, 0, -4);}
						
						$data = "GET ".$base_get." HTTP/1.1\r\n";
						$data .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n";
						$data .= "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*\r\n";
						$data .= "Accept-Language: en\r\n";
						$data .= "Host: ".$url_ary[2]."\r\n";
						$data .= "Connection: Keep-Alive\r\n";
						$data .= "Cache-Control: no-cache\r\n";
						$data .= "\r\n";

		                $image_data = $this->fetchImage ($data, $url_ary[2].":".$port);

						//if( preg_match("/Content-Length\: ([0-9]+)[^\/ ][\s]+/i", $image_data, $file_data1) && preg_match("/Content-Type\: image\/[x\-]*([a-z]+)[\s]+/i", $image_data, $file_data2) ) {
						if( preg_match("/Content-Type\: image\/[x\-]*([a-z]+)[\s]+/i", $image_data, $file_data2) ) {
							
							$file_size = strlen ( strstr ($image_data, 'GIF89') );
							$this->debuglog('Img Size : '.$file_size);
							//$file_size = $file_data1[1];
							$file_type = $file_data2[1];
							$this->debuglog('Img Type : '.$file_data2[1]);
                        }
                        
                        if ( $file_size == $this->config['imgonline'] ) {
                        	$this->status = 1;
						} elseif ( $file_size == $this->config['imgoffline'] ) {
						    $this->status = 0;
						} else {
							$this->status = 0;
						}

						$image_data = substr($image_data, strlen($image_data) - $file_size, $file_size);

    $this->writetofile ("status/".$this->config['imagename'].".".$file_type, $image_data);
    $this->do_stats();

}


//------------
// Fetch Image
//------------

function fetchImage ($RequestHeader, $Server) {

		$psplit = split(":",$Server);
		$pserver = $psplit[0];
		$pport = $psplit[1];

		$fp = @fsockopen($pserver, $pport);

		if ($fp) {
		@fputs ($fp, $RequestHeader);
		$site = "";
		while (!feof($fp)) {
			$site .= fgets ($fp, 1024);
		}
        fclose ($fp);
		} else {
		  //echo "connecting to $pserver:$pport unsuccesfull";
		}
		return($site);
}


//--------------
// Write to file
//--------------

function writetofile ($path,$data,$backup=0) {

  if (file_exists($path)!=0) {
    if ($backup==1) {
      $filenamenew=$path."venom";

      rename ($path,$filenamenew);
    } else {
      unlink($path);
    }
  }

  if ($data!="") {

    $filenum=fopen($path,"w");

    fwrite($filenum,$data);

    fclose($filenum);

  }

}


//-----------
// FTP Upload
//-----------

function ftp_start () {

    $this->ftp_conn = ftp_connect ($this->config['ftp_server'], $this->config['ftp_port']);
    $login_result = ftp_login($this->ftp_conn, $this->config['ftp_user'], $this->config['ftp_pass']);

}

function ftp_upload ($filename, $filesource) {

    $upload = ftp_put ($this->ftp_conn, $filename, $filesource, FTP_BINARY);

}

function ftp_dir () {

    $upload = ftp_chdir($this->ftp_conn, $this->config['ftp_dir']);

}

function ftp_end () {

    ftp_quit ($this->ftp_conn);

}


//---------------
// Make The Stats
//---------------

function do_stats () {

	if ($this->config['post']) {
	    $this->sendData();
	}

	if ($this->config['ftp_active']) {

		$this->ftp_start ();
		$this->ftp_dir();
		$this->ftp_upload ($this->config['imagename'].".gif", "status/".$this->config['imagename'].".gif");
		$this->ftp_end ();
	}

}


//--------
// Send To
//--------

function sendTo ($host,$method,$path,$data,$useragent=0) {
	if (empty($method)) {
	  $method = 'GET';
	}
	$method = strtoupper($method);
	$fp = fsockopen($host,80);
	if ($fp) {
	if ($method == 'GET') {
	  $path .= '?' . $data;
	}
	fputs($fp, "".$method." $path HTTP/1.0\r\n");
	fputs($fp, "Host: ".$host."\r\n");
	fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
	fputs($fp, "Content-length: " . strlen($data) . "\r\n");
	if ($useragent)
		fputs($fp, "User-Agent: MSIE\r\n");
	fputs($fp, "Connection: close\r\n\r\n");
	if ($method == 'POST') {
	  fputs($fp, $data);
    }
	while (!feof($fp))
		$buf .= fgets($fp,1024);
	fclose($fp);
	}
	return $buf;
}

function sendData () {

 $host      = $this->config['posttourl'];
 $method    = "POST";
 $path      = $this->config['posttopath'];
 $data      = "screenname=".$this->config['screenname']."&status=".$this->status."";
 $useragent = 1;

 $buffer = $this->sendTo ($host,$method,$path,$data,$useragent);

}


//----------
// Debug Log
//----------

function debuglog ($stuff, $f='') {

  if ($this->config['debug']) {
    $this->writetolog ($f.$stuff."\r\n");
    flush ();
    echo $stuff."<br>";
  }

}


//--------------
// Write to file
//--------------

function writetolog ($data) {

  if ($data!="") {

    $filenum=fopen("logs/".$this->config['log']."","a");

    fwrite($filenum,$data);

    fclose($filenum);

  }

}

} // End Class

?>
Return current item: YahooStatus