<?php
class ping
{

	function httppost( $host, $port, $uri, $data, $userAgent = "Logahead UNU/0.1" )
	{
		$url = "http://${host}:${port}${uri}";

		$fp = @fsockopen( $host, $port, $errno, $errstr, 5);
		if (!$fp)
			return false;

		$out = "POST ${uri} HTTP/1.1\r\n";
		$out .= "Host: ${host}\r\n";
		$out .= "Content-Type: text/xml\r\n";
		$out .= "Content-Length: ". strlen($data). "\r\n";

		fwrite($fp, $out);
		fwrite($fp, "\r\n");
		fwrite($fp, $data);
		fwrite($fp, "\r\n");
		// used to see the technorati response
		//fpassthru($fp);

		fclose($fp);
		return true;
	}

	function technorati( $title, $url )
	{
		$uTitle = htmlspecialchars($title);
		$uUrl = htmlspecialchars($url);
		$xml = "<?xml version=\"1.0\"?>\n";
		$xml .= "<methodCall>\n";
		$xml .= "<methodName>weblogUpdates.ping</methodName>\n";
		$xml .= "<params>\n";
		$xml .= "<param>\n<value>$uTitle</value>\n</param>\n";
		$xml .= "<param>\n<value>$uUrl</value>\n</param>\n";
		$xml .= "</params>\n";
		$xml .= "</methodCall>\n";

		ping::httppost( "rpc.technorati.com", 80, "/rpc/ping", $xml );
	}
}
?>
