<?php
//------------------------------------------------------------------------
// m_slashdot.php - display a side menu with the current slashdot 
// headlines.
//
// 
//------------------------------------------------------------------------

$currentTag = "";

function startElement2($parser, $name, $attrs) {
   global $currentTag;
   $currentTag = $name;

   
}

function endElement2($parser, $name) {
   global $currentTag, $TITLE, $URL;
   // clear current tag variable   
   switch ($currentTag)
   {
      case "URL":
         print "
				 <font class='fine'>
				 <a href = \"$URL\">$TITLE</a><br>
     		 </font>";
				 break;
   }
   $currentTag = "";
}

// process data between tags
function characterData2($parser, $data) {

   global $currentTag, $TITLE, $URL;
   switch ($currentTag)
   {
   case "TITLE":
      // italics for title
      $TITLE = $data;
      break;

   case "URL":
      // italics for title
      $URL = $data;
      break;
   }
}



          drawMenuTop("Currently at Slashdot");
					
					$slashxml = "engine/shards/xmlcache/slashdot.xml";
		  			
					$filestats = @stat( $slashxml );
					
					//
					// 1800 seconds is 30 minutes.  If the file doesn't exist or
					// if it older than 30 minutes we are allowed to seek slashdot.org
					// for a refresh.  Otherwise use the local copy of slashdot.xml.
					//	
					if( ($filestats == FALSE) || ($filestats[9] < time() - 1800) )
					{
						$feed = fopen( "http://www.slashdot.org/slashdot.xml","r" );
						$localfeed = fopen( $slashxml , "w" );
						if( $feed != FALSE )
						{
							while( $data = fread($feed, 4096 ) )
							{
								fwrite( $localfeed, $data );
							}
							fclose( $feed );
						}
						fclose( $localfeed );
					}
					
					$feed = fopen( $slashxml , "r" );
					
					if( $feed != FALSE )
					{	
						$xparser = xml_parser_create();
						xml_set_element_handler($xparser, "startElement2","endElement2");
						xml_set_character_data_handler($xparser, "characterData2" );

						while( $data = fread( $feed, 4096 ) )
						{
								if( !xml_parse( $xparser, $data, feof($feed)))
								{
										die( "some crazy xml parsing error" );
								}
						}
						xml_parser_free( $xparser );
		  		}
					else
					{
							print("<font class='fine'>failed to open feed</font>");
					}
          
					drawMenuBottom();

?>
