Source of: php3/txtnewsparser.php3

<?

if(isset($protectmultiinctxtnws)) return;
$protectmultiinctxtnws 1;

include 
"newsformat.inc";

function 
blocknewsparser($hosttitle$hostname$backend$argdesc
                         
$separ ""$maxitems 0$port 80)
{

    
$hosturl        =        "http://" $hostname "/";

    
$header_passed  =       0;
    
$cache "cache/cache." $hostname ".txt";
    
$comment "(cached)";

    if(
file_exists($cache)) {
        
$ctime fileMtime($cache);
        if(
fileSize($cache) < 20$ctime = -1;
    } else 
$ctime = -1;
    
$ntime Time();
    
$dtime $ntime $ctime;

    
$itemcount 0;
    
$uncache 0;
    
$linelengh 1024;
    
$filedate "";
    
    global 
$nocache;
    if(isset(
$nocache) || $dtime $ntime || $dtime 1800) {
        
$cfile fopen($cache"w");

        
$fpread fsockopen("$hostname"$port, &$errno, &$errstr);
        if(!
$fpread) {
                echo 
"Error connecting to $hostname: $errstr<br>\n";
        } else {
            
fputs($fpread"GET " $backend " HTTP/1.0\n");
            
fputs($fpread"User-Agent: PHP NEWSParser/0.2  mkrus@free.fr\n");
            
fputs($fpread"Host: " $hostname ":80\n");
            
fputs($fpread"Accept: */*\n\n");

            
$str fgets($fpread$linelengh);
            
$id strstr($str"404");
            if(
$id != "") {
                echo 
"Document <A HREF=\"http://$hostname$backend\">http://$hostname$backend</A> not found\n";
                exit;
            }

            
writeHeader($cfile$hosttitle$hosturl,
                        
"http://" $hostname ":" $port $backend);
            while (!
feof($fpread)) {
                if (
$header_passed == 1) {

                    if(
$separ != "") {
                        do {
                            
$str Chop(fgets($fpread$linelengh));
                        } while(
$str != $separ && !feof($fpread));
                    }
                    if(
feof($fpread)) break;

                    
$i 0;
                    
$argvals["info"] = "";
                    while(
$i count($argdesc) && !feof($fpread)) {
                        
$str Chop(fgets($fpread$linelengh));
                        if(
strstr($str"<!--")) continue;
                        
$argvals[$argdesc[$i]] = $str;
                        
$i++;
                    }
                    if(
$argvals["info"] != "")
                        
writeItem($cfile$argvals["info"], $argvals["link"]);
                    
$itemcount++;

                    if(
$maxitems && $itemcount $maxitems) break;

                }

                if (
$header_passed == 0) {
                    
$str Chop(fgets($fpread$linelengh));

                    
$id strstr($str"Last-Modified");
                    if(
$id != "") {
                        
$filedate strstr($str" ");
                    }

                    if (
$str == "") {
                        
$header_passed 1;
                    }
                }
            }

            if(
$filedate == "") {
                
$ctime fileMtime($cache);
                
$filedate Date("G:i m/d/y"$ctime);
            }

            if(
$itemcount == 0) {
                
fputs($cfile"No items found");
                
$uncache 1;
            }

            
finishNews($cfile$filedate"");

            
fclose($fpread);
        }

        
fclose($cfile);

        
$comment "";

    }

    include 
$cache;
    
writeFooter($comment);
    
    if(
$uncache) {
        
unlink($cache);
    }

}



function 
linenewsparser($hosttitle$hostname$backend$separator,
                        
$maxitems 0$port 80)
{
    
$hosturl        =        "http://" $hostname "/";

    
$header_passed  =       0;
    
$cache "cache/cache." $hostname ".txt";
    
$comment "(cached)";
    
    if(
file_exists($cache)) {
        
$ctime fileMtime($cache);
        if(
fileSize($cache) < 20$ctime = -1;
    } else 
$ctime = -1;
    
$ntime Time();
    
$dtime $ntime $ctime;

    
$itemcount 0;
    
$uncache 0;
    
$linelengh 1024;
    
$filedate "";
    
    global 
$nocache;
    if(isset(
$nocache) || $dtime $ntime || $dtime 1800) {
        
$cfile fopen($cache"w");

        
$fpread fsockopen("$hostname"$port, &$errno, &$errstr);
        if(!
$fpread) {
                echo 
"Error connecting to $hostname: $errstr<br>\n";
        } else {
            
fputs($fpread"GET " $backend " HTTP/1.0\n");
            
fputs($fpread"User-Agent: PHP NEWSParser/0.2  mkrus@free.fr\n");
            
fputs($fpread"Host: " $hostname ":80\n");
            
fputs($fpread"Accept: */*\n\n");

            
$str fgets($fpread$linelengh);
            
$id strstr($str"404");
            if(
$id != "") {
                echo 
"Document <A HREF=\"http://$hostname$backend\">http://$hostname$backend</A> not found\n";
                exit;
            }

            
writeHeader($cfile$hosttitle$hosturl,
                        
"http://" $hostname ":" $port $backend);

            while (!
feof($fpread)) {
                if (
$header_passed == 1) {

                    
$str Chop(fgets($fpread$linelengh));
                    if(
strstr($str"<!--")) continue;
                    
$items explode($separator$str);

                    if(
count($items) > 2) {
                        
writeItem($cfile$items[0], $items[2]);
                        
$itemcount++;
                    }
                    if(
$maxitems && $itemcount $maxitems) break;

                }

                if (
$header_passed == 0) {
                    
$str Chop(fgets($fpread$linelengh));

                    
$id strstr($str"Last-Modified");
                    if(
$id != "") {
                        
$filedate strstr($str" ");
                    }

                    if (
$str == "") {
                        
$header_passed 1;
                    }
                }
            }

            if(
$filedate == "") {
                
$ctime fileMtime($cache);
                
$filedate Date("G:i m/d/y"$ctime);
            }

            if(
$itemcount == 0) {
                
fputs($cfile"No items found");
                
$uncache 1;
            }

            
finishNews($cfile$filedate"");

            
fclose($fpread);
        }

        
fclose($cfile);

        
$comment "";

    }

    include 
$cache;
    
writeFooter($comment);
    
    if(
$uncache) {
        
unlink($cache);
    }

}
?>

The syntax highlighted source is automatically generated by PHP from the plaintext script.
If you want to see the source of this page, have a look here.