<?php
/*
//      golemxml.php
//
//      Version:  1.0.1
//      Author:         Soeren Fuhrmann - sf@golem.de
//      Homepage:       http://www.golem.de
//
//      Based on:       freshmeat.php3
//      Version:  2.0.4
//      Author:           Kalle Kiviaho - kivi@chl.chalmers.se
//      Lastmod:        2000-09-24
//      Homepage:       http://swamp.chl.chalmers.se/backends/
*/
// Customize it to suit your needs

$link_prefix   =  "&middot;&nbsp;";
$link_postfix  =  "<BR>\n";

$show_abstract    =  true;
$ab_link_prefix   =  "";
$ab_link_postfix  =  "<BR>\n";
$ab_prefix        =  "";
$ab_postfix       =  "<BR><BR>\n";
$ab_more          =  "[mehr...]";
$ab_more_prefix   =  "&nbsp;\n";

$cache_file    =  "/tmp/golem.de.cache";
$cache_time    =  300;
$max_items     =  10;
$max_readsize  =  10000;
$target        =  "_top";

// End of customizations

$backend =  "http://www.golem.de/golem_backend.xml";

$items   =  0;
$time    =  split(" "microtime());

mt_srand((double)microtime()*1000000);
$cache_time_rnd   =  mt_rand(0600) - 300;

if ( (!(
file_exists($cache_file))) || ((filectime($cache_file) + $cache_time $time[1]) + $cache_time_rnd 0) || (!(filesize($cache_file))) ) {

   
$fpread = @fopen($backend'r');
   if (!
$fpread) {
//    echo "$errstr ($errno)<br>\n";
//    exit;
   
} else {

      
$fpwrite = @fopen($cache_file'w');
      if (!
$fpwrite) {
//       echo "$errstr ($errno)<br>\n";
//       exit;
      
} else {
         
$string '';
         do {
            
$t_str fread($fpread1024);
            
$string .= $t_str;
         } while (!empty(
$t_str) && (strlen($string) < $max_readsize));

         
$pattern "/<ARTIKEL>(.*?)<\/ARTIKEL>/is";
         if (
preg_match_all($pattern$string$matchPREG_SET_ORDER))
            for (
$i0$imin(count($match), $max_items); $i++) {
               
$artikel$match[$i][1];

               
$pattern "/<HEADLINE>(.*?)<\/HEADLINE>/i";
               
preg_match($pattern$artikel$lmatch);
               
$title$lmatch[1];

               
$pattern "/<URL>(.*?)<\/URL>/i";
               
preg_match($pattern$artikel$lmatch);
               
$link$lmatch[1];


               if (
$items== && $show_abstract) {
                  
$pattern "/<ABSTRACT>(.*?)<\/ABSTRACT>/i";
                  
preg_match($pattern$artikel$lmatch);
                  
$abstract$lmatch[1];

                  
fputs($fpwrite$ab_link_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$title."</A>".$ab_link_postfix);
                  
fputs($fpwrite$ab_prefix.$abstract.$ab_more_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$ab_more."</A>".$ab_postfix);
               } else {
                  
fputs($fpwrite$link_prefix."<A HREF=\"".$link."\" TARGET=\"".$target."\">".$title."</A>".$link_postfix);
               }

               
$items++;
         }
      }
      
fclose($fpread);
   }
   
fclose($fpwrite);
}
if (
file_exists($cache_file)) {
   include(
$cache_file);
}
?>