File:  [DVB] / linuxtv.org / news.inc
Revision 1.3: download - view: text, annotated - select for diffs
Sat Feb 12 21:06:32 2005 UTC (19 years, 3 months ago) by js
Branches: MAIN
CVS tags: HEAD
fix for new php version

<?PHP

$NEWSDIR = "news";


function read_news( $entry, $intro )
{
  global $PATH;
  global $SCRIPT;
  global $NEWSDIR;

  if (!preg_match( "/(\d\d\d\d\-\d\d\-\d\d).*\.(\w+)/", $entry, $regs ))
    trigger_error( "Invalid news entry", E_USER_ERROR );


  $date = $regs[1];
  $author = $regs[2];

  $filename = "$NEWSDIR/$entry";

  if (!($file = fopen( $filename, "r" )))
    trigger_error( "Could not open $filename", E_USER_ERROR );

  if (!($caption = fgets( $file, 128 )))
    trigger_error( "Error reading news caption from $filename", E_USER_ERROR );

  if (!($empty = fgets( $file, 2 )))
    trigger_error( "Nothing but a caption in $filename", E_USER_ERROR );
  else if (strlen(trim($empty)) > 0)
    trigger_error( "No blank line after caption in $filename", E_USER_ERROR );

  if ($intro)
    {
      $content = "";
      while (($line = fgets( $file, 1024 )) && strlen(trim($line)) > 0)
        $content .= $line;
    }
  else if (!($content = fread( $file, filesize( $filename ) )))
    trigger_error( "Error reading news content from $filename", E_USER_ERROR );

  fclose( $file );


  print( "<div class=\"news\">\n" );
  print( "  <h3>\n" );
  if ($intro)
    print( "    <a href=\"news.php?entry=$entry\">\n" );
  print( "        <span class=\"newsdate\">$date &nbsp;</span>\n" );
  print( "        <span class=\"newscaption\">$caption</span>\n" );
  if ($intro)
    print( "    </a>\n" );
  print( "  </h3>\n" );
  print( "  <div class=\"newsbody\">\n" );
  print( "    $content\n" );
  print( "    <p class=\"newsauthor\">$author</p>\n" );
  print( "  </div>\n" );
  print( "</div>\n" );
}


function show_news( $num, $intro, $year )
{
  global $NEWSDIR;

  if ($year >= 2000)
    $match = "/($year\-\d\d\-\d\d)/";
  else
    $match = "/(\d\d\d\d\-\d\d\-\d\d)/";

  if (!is_dir( $NEWSDIR ))
    trigger_error( "No directory '$NEWSDIR'", E_USER_ERROR );

  $entries = array();

  if (!($dir = opendir( $NEWSDIR )))
    trigger_error( "Could not open directory '$NEWSDIR'", E_USER_ERROR );

  while (($file = readdir( $dir )))
    {
      if (!preg_match( $match, $file ))
        continue;

      $entries[] = $file;
    }

  closedir( $dir );
  
  rsort( $entries );


  $count = count($entries);

  if ($num < 1 || $num > $count)
    $num = $count;

  for ($index=0; $index<$num; $index++)
    read_news( $entries[$index], $intro );
}
?>

LinuxTV legacy CVS <linuxtv.org/cvs>