Annotation of linuxtv.org/news.inc, revision 1.2

1.1       js          1: <?PHP
                      2: 
                      3: $NEWSDIR = "news";
                      4: 
                      5: 
                      6: function read_news( $entry, $intro )
                      7: {
                      8:   global $PATH;
                      9:   global $SCRIPT;
                     10:   global $NEWSDIR;
                     11: 
                     12:   if (!preg_match( "/(\d\d\d\d\-\d\d\-\d\d).*\.(\w+)/", $entry, $regs ))
                     13:     trigger_error( "Invalid news entry", E_USER_ERROR );
                     14: 
                     15: 
                     16:   $date = $regs[1];
                     17:   $author = $regs[2];
                     18: 
                     19:   $filename = "$NEWSDIR/$entry";
                     20: 
                     21:   if (!($file = fopen( $filename, "r" )))
                     22:     trigger_error( "Could not open $filename", E_USER_ERROR );
                     23: 
                     24:   if (!($caption = fgets( $file, 128 )))
                     25:     trigger_error( "Error reading news caption from $filename", E_USER_ERROR );
                     26: 
                     27:   if (!($empty = fgets( $file, 2 )))
                     28:     trigger_error( "Nothing but a caption in $filename", E_USER_ERROR );
                     29:   else if (strlen(trim($empty)) > 0)
                     30:     trigger_error( "No blank line after caption in $filename", E_USER_ERROR );
                     31: 
                     32:   if ($intro)
                     33:     {
                     34:       while (($line = fgets( $file, 1024 )) && strlen(trim($line)) > 0)
                     35:         $content .= $line;
                     36:     }
                     37:   else if (!($content = fread( $file, filesize( $filename ) )))
                     38:     trigger_error( "Error reading news content from $filename", E_USER_ERROR );
                     39: 
                     40:   fclose( $file );
                     41: 
                     42: 
                     43:   print( "<div class=\"news\">\n" );
                     44:   print( "  <h3>\n" );
                     45:   if ($intro)
1.2     ! js         46:     print( "    <a href=\"news.php?entry=$entry\">\n" );
1.1       js         47:   print( "        <span class=\"newsdate\">$date &nbsp;</span>\n" );
                     48:   print( "        <span class=\"newscaption\">$caption</span>\n" );
                     49:   if ($intro)
                     50:     print( "    </a>\n" );
                     51:   print( "  </h3>\n" );
                     52:   print( "  <div class=\"newsbody\">\n" );
                     53:   print( "    $content\n" );
                     54:   print( "    <p class=\"newsauthor\">$author</p>\n" );
                     55:   print( "  </div>\n" );
                     56:   print( "</div>\n" );
                     57: }
                     58: 
                     59: 
                     60: function show_news( $num, $intro, $year )
                     61: {
                     62:   global $NEWSDIR;
                     63: 
                     64:   if ($year >= 2000)
                     65:     $match = "/($year\-\d\d\-\d\d)/";
                     66:   else
                     67:     $match = "/(\d\d\d\d\-\d\d\-\d\d)/";
                     68: 
                     69:   if (!is_dir( $NEWSDIR ))
                     70:     trigger_error( "No directory '$NEWSDIR'", E_USER_ERROR );
                     71: 
                     72:   $entries = array();
                     73: 
                     74:   if (!($dir = opendir( $NEWSDIR )))
                     75:     trigger_error( "Could not open directory '$NEWSDIR'", E_USER_ERROR );
                     76: 
                     77:   while (($file = readdir( $dir )))
                     78:     {
                     79:       if (!preg_match( $match, $file ))
                     80:         continue;
                     81: 
                     82:       $entries[] = $file;
                     83:     }
                     84: 
                     85:   closedir( $dir );
                     86:   
                     87:   rsort( $entries );
                     88: 
                     89: 
                     90:   $count = count($entries);
                     91: 
                     92:   if ($num < 1 || $num > $count)
                     93:     $num = $count;
                     94: 
                     95:   for ($index=0; $index<$num; $index++)
                     96:     read_news( $entries[$index], $intro );
                     97: }
                     98: ?>

LinuxTV legacy CVS <linuxtv.org/cvs>