<?
function textwrap($text, $wrap=80, $break="\n"){
$len = strlen($text);
if ($len > $wrap) {
$h = ''; // massaged text
$lastWhite = 0; // position of last whitespace char
$lastChar = 0; // position of last char
$lastBreak = 0; // position of last break
// while there is text to process
while ($lastChar < $len) {
$char = substr($text, $lastChar, 1); // get the next character
// if we are beyond the wrap boundry and there is a place to break
if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)) {
$h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break;
$lastChar = $lastWhite + 1;
$lastBreak = $lastChar;
}
// You may wish to include other characters as valid whitespace...
if ($char == ' ' || $char == chr(13) || $char == chr(10)) {
$lastWhite = $lastChar; // note the position of the last whitespace
}
$lastChar = $lastChar + 1; // advance the last character position by one
}
$h .= substr($text, $lastBreak); // build line
} else {
$h = $text; // in this case everything can fit on one line
}
return $h;
}
function OpenNNTPconnection($server,$port) {
$ns=fsockopen($server,$port);
$weg=lieszeile($ns); // kill the first line
if (substr($weg,0,2) != "20") {
$ns=false;
echo "<p>Îøèáêà1</p>";
} else {
if ($ns != false) {
fputs($ns,"mode reader\r\n");
$weg=lieszeile($ns); // and once more
if (substr($weg,0,2) != "20") {
$ns=false;
echo "<p>Îøèáêà2</p>";
}
}
}
if ($ns == false) echo "connection_failed";
return $ns;
}
/*
* read one line from the NNTP-server
*/
function lieszeile(&$von) {
if ($von != false) {
$t=ereg_replace("\r\n$","",fgets($von,100000));
return $t;
}
}
/*
* Close a NNTP connection
*
* $von: the handle of the connection
*/
function closeNNTPconnection(&$von) {
if ($von != false) {
fputs($von,"quit\r\n");
fclose($von);
}
}
/*
* Post an article to a newsgroup
*
* $subject: The Subject of the article
* $from: The authors name and email of the article
* $newsgroups: The groups to post to
* $ref: The references of the article
* $body: The article itself
*/
function post($subject,$from,$newsgroups,$ref,$body) {
global $send_poster_host;
flush();
$ns=OpenNNTPconnection('news.sochi.ru','119');
if ($ns != false) {
fputs($ns,"post\r\n");
$weg=lieszeile($ns);
fputs($ns,"Subject: $subject\r\n");
fputs($ns,"From: $from\r\n");
fputs($ns,"Sender: $from\r\n");
fputs($ns,"Newsgroups: $newsgroups\r\n");
fputs($ns,"Content-Type: text/plain; charset=koi8-r\r\n");
fputs($ns,"Content-Transfer-Encoding: 8bit\r\n");
fputs($ns,"User-Agent: NewsPortal 0.23\r\n");
if ($send_poster_host)
fputs($ns,"X-HTTP-Posting-Host: ".gethostbyaddr(getenv("REMOTE_ADDR"))."\r\n");
if ($ref!=false) fputs($ns,"References: $ref\r\n");
if (isset($organization)) fputs($ns,"Organization: $organization\r\n");
if ((isset($file_footer)) && ($file_footer!="")) {
$footerfile=fopen($file_footer,"r");
$body.="\n".fread($footerfile,filesize($file_footer));
fclose($footerfile);
}
$body=ereg_replace("\r",'',$body);
$body=str_replace("\n.\n","\n..\n",$body);
$b=split("\n",$body);
$body="";
for ($i=0; $i<count($b); $i++) {
if ((strpos(substr($b[$i],0,strpos($b[$i]," ")),">") != false ) | (strcmp(substr($b[$i],0,1),">") == 0)) {
$body .= textwrap(stripSlashes($b[$i]),78,"\r\n")."\r\n";
} else {
$body .= textwrap(stripSlashes($b[$i]),74,"\r\n")."\r\n";
}
}
//----- Aqui es donde podriamos anadir la cadena que deseamos, siguiendo al body ------//
$linea1="---------------------------------------------------------------------------";
$linea2=" Message has been Posted from [url]www.AvtoSochi.com.ru[/url]";
$linea3="---------------------------------------------------------------------------";
$body = $body."\n\n".$linea1."\n".$linea2."\n".$linea3."\n";
//-------------------------------------------------------------------------------------//
fputs($ns,"\r\n".$body."\r\n.\r\n");
$message=lieszeile($ns);
closeNNTPconnection($ns);
} else {
$message="post_failed";
}
return $message;
}
?>