<?php
require("config.inc.php");
if( isset(
$debug) ) echo "<xmp>";

function 
bailout($msg) {

 global 
$xml;
 global 
$debug;
  
 if( !isset(
$debug) )
 {
$email "michael@michaelthompson.org";
$header  "From: gms.php <" "$email" ">";
$header  "$header" "\nReply-To: " "$email";
$message "http://michaelthompson.org/news/cnv/gms.php\n\n";
$message .= "error reading" " " "$xml\n\n";
$message .= "\n$msg";
mail("$email","news.php","$message","$header");
  }

$url "<a href=\"$xml\">$xml</a>";
die(
"!!!NO UPDATE!!!<hr>error reading $url <hr>$msg");
}

$url="http://www.siliconvalley.com/mld/siliconvalley/business/columnists/gmsv/";
$xml $url;

$fi fopen("$url","r") or bailout("fopen($url)");

$ln 0;

$item=0;
$nItems=0;
while( !
feof($fi) )
{
  
$buff fgets($fi,1024);
  
$ln++;
  
$buff ltrim($buff);
  
$buff rtrim($buff);
  if( 
strlen($buff)<) continue;
  
$buff str_replace("&nbsp;"," ",$buff);
  
#echo "$buff";
  
if( !isset($channelTitle) && stristr($buff,"<title>") )
  {
    
$channelTitle =  "Good Morning Silicon Valley";
    if( isset(
$debug) ) echo "$ln: channelTitle: \{$channelTitle}\n";
    continue;
  }

  if( !isset(
$channelDesc) &&
      
stristr($buff,"<meta ") &&
      
stristr($buff,"name=\"description\""
  )
  {
    
$ar explode("content=",$buff);
    
$channelDesc $ar[1];
    if( isset(
$debug) ) echo "$ln: channelDesc: \{$channelDesc}\n";
    continue;
  }
  if( !isset(
$channelDate) && strstr($buff,"UTC") )
  {
    
$channelDate $buff;
    if( isset(
$debug) ) echo "$ln: channelDate \{$channelDate}\n";
  }
  if( !isset(
$start) && strstr($buff,"class=\"smalltitle\" nowrap>LATEST") )
  {
    
$start $ln;
    if( isset(
$debug) ) echo "$ln: headlines begin...\n";
  }

  if( 
$start!=)
  {
    if
    ( 
stristr($buff,"class=\"digest-headline\""
    ) 
    {
      
$aItems[$nItems] = $buff;
      while( !
feof($fi) )
      {
        
$buff fgets($fi,1024);
        
$ln++;
        
$buff ltrim($buff);
        
$buff rtrim($buff);
        if( 
strlen($buff)<) continue;
        
$buff str_replace("&nbsp;"," ",
         
str_replace("<span class=\"byline\">","<br>",$buff));
        
        if( 
strstr($buff,"</span>") ) 
        {
          
$arDesc[$nItems] .= str_replace("</span>","",
             
str_replace("</p>","",$buff));
          break;
        }
        
$arDesc[$nItems] .= $buff;
      }
      
$nItems++;
      if( isset(
$debug) ) echo "($ln)headline: $nItems { $buff }";
    }
  }

}

if( 
$nItems<bailout("no items ($nItems)");
if( isset(
$debug) ) echo "\n\n";

$now date("D, d M Y H:i:s T",time());

print <<< EPR
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91">
<channel>
<title>$channelTitle</title>
<copyright> Copyright @ SiliconValley.com</copyright>
<link>http://www.siliconvalley.com/mld/siliconvalley/business/columnists/gmsv/</link>
<description>$channelDesc</description>
<pubDate>$now</pubDate>
<language>en-us</language>
<webMaster>michael@michaelthompson.org</webMaster>
<image>
<title>$channelTitle Headlines</title>
<url>http://michaelthompson.org/news/images/gmsv.jpg</url>
<link>http://www.siliconvalley.com/mld/siliconvalley/business/columnists/gmsv/</link>
</image>

EPR;

$n = (($nItems>10) ? 10 $nItems);
for( 
$i=$i<$n$i++ )
{
  
$ar explode("</a>",$aItems[$i]);
  
$buff $ar[0];
  
$ar explode("<a href=\"",$buff);
  
$link $ar[1];
  
$ar explode("\" class=\"digest-headline\"",$link);
  
$link $ar[0];
  
$title substr($ar[1],1);
  
$title str_replace("&eacute;","e",htmlentities($title));
  
$desc $arDesc[$i];
  
$desc str_replace("&eacute;","e",htmlentities($desc));
  
$link "http://www.siliconvalley.com/mld/siliconvalley/business/columnists/gmsv/" $link;
  print <<< EPR
<item>
<title>$title</title>
<link>$link</link>
EPR;
 if( 
strlen($desc)>)
  {
    print <<< EPR
\n<description>$desc</description>
EPR;
  }
print <<< EPR
</item>

EPR;
}

echo 
"</channel>\n</rss>\n";

if( isset(
$debug) ) echo "</xmp>";
?>