"; return false; } else { // send headers to server fputs($fsock, $out); while(!feof($fsock)) { // grab data $returned_data = fgets($fsock, 256); //echo "rawdat:[".htmlspecialchars($returned_data)."]
"; // is it the first blank line we've received? // (if so, that's the end of the returned headers) if($headersEnded == 0 && ($returned_data=="\r\n" || $returned_data=="\n" || $returned_data=="\r")) { $returned_data = ""; $headersEnded = 1; } if($headersEnded == 1) { // store returned data as one string, for later output $data .= $returned_data; } else { $headers .= $returned_data; } } // close connection fclose($fsock); if($return_array) { return Array($headers,$data); } else { return $data; } } } function make_blathe($word,$entry,$name,$email="",$edition="") { // asks blather to create a new blathe or new blathe entry // eg: make_blathe("fish","fish are nice to eat","fishman","fishman@yahoo.com"); // eg: make_blathe("fish","fish are nice to eat","fishman"); // eg: make_blathe("fish","fish are nice to eat","fishman","","red"); // email address MUST be valid or blather won't allow it. // error check: if(empty($word) || empty($entry) || empty($name)) { return false; } if($edition=="red") { $edition = "/edition=red"; } else { $edition = ""; } // prepare headers to send $out = 'POST /cgi-bin/blather'.$edition.'?add HTTP/1.0'."\r\n"; $out .= 'Accept-Encoding: '."\r\n"; $out .= 'X-Script: lib_blather0.3 from puremango.co.uk'."\r\n"; $out .= 'Host: '.BLATHER_LOCATION."\r\n"; $out .= 'Referer: http://'.BLATHER_LOCATION."/cgi-bin/blather".$edition."?addform;word=".$word."\r\n"; $out .= 'Connection: close'."\r\n"; $out .= 'Content-Type: application/x-www-form-urlencoded'."\r\n"; $postData = 'word='.$word.'&entry='.$entry.'&name='.$name.'&email='.$email; $out .= 'Content-Length: '.strlen($postData)."\r\n"; $out .= ''."\r\n"; $out .= $postData."\r\n"; // terminate headers $out .= "\r\n"; http_request(BLATHER_LOCATION,80,$out); return true; } function who_blathes($who,$email="",$edition="") { // returns array of files, indexed by page name that $who has blathed to // eg: who("u24"); // eg: who("u24","email@address.com"); // eg: who("u24","email@address.com","red"); // eg: who("u24","","red"); if($edition=="red") { $edition = "/edition=red"; } else { $edition = ""; } if(!empty($email)) { $email = ";email=".urlencode($email); } else { $email = ""; } $who_blathes = file("http://".BLATHER_LOCATION."/cgi-bin/blather".$edition."?who;name=".urlencode($who).$email); $lines = Array(); if(!is_array($who_blathes)) { return false; } foreach($who_blathes as $line) { if(strpos($line,'')); // and the name of the page $page_name = substr($line,strrpos($line,'/')+1); $page_name = substr($page_name,0,strpos($page_name,'.html')); // and assign the array space. $lines[$page_name] = $line; } } return $lines; } function recent($edition="") { if($edition=="red") { $edition = "/edition=red"; } else { $edition = ""; } $recent = file("http://".BLATHER_LOCATION."/cgi-bin/blather".$edition."?recent"); $lines = Array(); $index = "today"; foreach($recent as $line) { if($index=="today" && trim($line)=="") { // today/yesterday turnover $index = "yesterday"; } if(strpos($line,'')); // and the name of the page $page_name = substr($line,strrpos($line,'/')+1); $page_name = substr($page_name,0,strpos($page_name,'.html')); // and assign the array space. $lines[$index][$page_name] = $line; } } return $lines; } function go($edition="") { if($edition=="red") { $edition = "/edition=red"; } else { $edition = ""; } $out = "GET /cgi-bin/blather".$edition."?random HTTP/1.0\r\n"; $out .= 'Host: '.BLATHER_LOCATION."\r\n"; $out .= 'Accept-Encoding: '."\r\n"; $out .= 'X-Script: lib_blather0.3 from puremango.co.uk'."\r\n"; $out .= 'Referer: http://'.BLATHER_LOCATION."\r\n"; $out .= 'Connection: close'."\r\n\r\n"; $result = http_request(BLATHER_LOCATION,80,$out,true); $headers = $result[0]; $headers = explode("\n",$headers); foreach($headers as $header) { if(strpos($header,"Location:")!==false) { return trim(substr($header,10)); } } // did not get Location header: return false; } function read_blathe($word,$edition="") { /* will return array as so: $ret[] = Array("who",entry,"date","email"); $ret[] = Array("who2",entry2,"date2","email2"); where entry is an array, index by word, eg: $entry[] = Array("these",true); $entry[] = Array("are",true); $entry[] = Array("blathes",true); $entry[] = Array("butthisisnotablathe",false); */ if($edition=="red") { $edition = "/red"; } else { $edition = ""; } $blathe_contents = @file_get_contents("http://".BLATHER_LOCATION.$edition."/".$word{0}."/".$word.".html"); if(empty($blathe_contents)) { return false; } else { $ret = Array(); $i=0; // break into individual blathes $blathe_contents = explode('>...<',$blathe_contents); foreach($blathe_contents as $rawentry) { $lines = explode("\n",$rawentry); foreach($lines as $line) { if(strpos($line,' class="noline">')!==false && strpos($line,"who;")!==false) { // extract name $name = trim(strip_tags($line)); if(strpos($line,'email=')!==false) { // extract email $email = urldecode(substr($line,strpos($line,"email=")+6,strpos($line," class=")-7-strpos($line,"email="))); } else { // no email given $email = ""; } } if(strpos($line,'day=')!==false) { // extract date $day = urldecode(substr($line,strpos($line,"day=")+4,strpos($line," class=")-5-strpos($line,"day="))); } } if(sizeof($ret)==0) { // first entry (slightly different as includes header): $raw_entry = $lines[42]; } else { // all other entries: $raw_entry = $lines[11]; } // plain text: //$entry = str_replace("
","\n",$raw_entry); //$entry = strip_tags($entry); // with is_blathe flag set: $raw_entry = stripslashes($raw_entry); $words = explode(" ",$raw_entry); foreach($words as $word) { $word = " ".$word; if($word=="
") { $entry[] = Array("
",false); } else { $regex = " href=\"http://".BLATHER_LOCATION.$edition."/[a-z0-9_]/[a-z0-9_]*.html\">"; if(ereg($regex,$word)) { // this is a blathe $word = ereg_replace($regex,"",$word); // catch anything after word (punctuation): $word2 = substr($word,strpos($word,"
")+4); // save word $word = substr($word,0,strpos($word,"")); // add word to return array $entry[] = Array($word,true); // add spurious word-parts to return array (punct) if(!empty($word2)) { $entry[] = Array($word2,false); } } else { // this is not a blathe $word = strip_tags($word); $entry[] = Array($word,false); } } } $ret[$i] = Array("name"=>$name,"day"=>$day,"entry"=>$entry,"email"=>$email); $i++; $entry = Array(); } return $ret; } } function is_blathe($word,$edition="") { // returns true if $word exists in blather $edition // false if not if($edition=="red") { $edition = "red/"; } else { $edition = ""; } // using HEAD not GET to save time $out = "HEAD /".$edition.$word{0}."/".$word.".html HTTP/1.0\r\n"; $out .= 'Host: '.BLATHER_LOCATION."\r\n"; $out .= 'Accept-Encoding: '."\r\n"; $out .= 'X-Script: lib_blather0.3 from puremango.co.uk'."\r\n"; $out .= 'Referer: http://'.BLATHER_LOCATION."\r\n"; $out .= 'Connection: close'."\r\n\r\n"; $result = http_request(BLATHER_LOCATION,80,$out,true); $headers = $result[0]; $headers = explode("\n",$headers); // check first line of response for 200 OK message if(strpos($headers[0],"200")!==false) { return true; } else { return false; } } ?>