Annotation of linuxtv.org/news.inc, revision 1.3
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: {
1.3 ! js 34: $content = "";
1.1 js 35: while (($line = fgets( $file, 1024 )) && strlen(trim($line)) > 0)
36: $content .= $line;
37: }
38: else if (!($content = fread( $file, filesize( $filename ) )))
39: trigger_error( "Error reading news content from $filename", E_USER_ERROR );
40:
41: fclose( $file );
42:
43:
44: print( "<div class=\"news\">\n" );
45: print( " <h3>\n" );
46: if ($intro)
1.2 js 47: print( " <a href=\"news.php?entry=$entry\">\n" );
1.1 js 48: print( " <span class=\"newsdate\">$date </span>\n" );
49: print( " <span class=\"newscaption\">$caption</span>\n" );
50: if ($intro)
51: print( " </a>\n" );
52: print( " </h3>\n" );
53: print( " <div class=\"newsbody\">\n" );
54: print( " $content\n" );
55: print( " <p class=\"newsauthor\">$author</p>\n" );
56: print( " </div>\n" );
57: print( "</div>\n" );
58: }
59:
60:
61: function show_news( $num, $intro, $year )
62: {
63: global $NEWSDIR;
64:
65: if ($year >= 2000)
66: $match = "/($year\-\d\d\-\d\d)/";
67: else
68: $match = "/(\d\d\d\d\-\d\d\-\d\d)/";
69:
70: if (!is_dir( $NEWSDIR ))
71: trigger_error( "No directory '$NEWSDIR'", E_USER_ERROR );
72:
73: $entries = array();
74:
75: if (!($dir = opendir( $NEWSDIR )))
76: trigger_error( "Could not open directory '$NEWSDIR'", E_USER_ERROR );
77:
78: while (($file = readdir( $dir )))
79: {
80: if (!preg_match( $match, $file ))
81: continue;
82:
83: $entries[] = $file;
84: }
85:
86: closedir( $dir );
87:
88: rsort( $entries );
89:
90:
91: $count = count($entries);
92:
93: if ($num < 1 || $num > $count)
94: $num = $count;
95:
96: for ($index=0; $index<$num; $index++)
97: read_news( $entries[$index], $intro );
98: }
99: ?>
LinuxTV legacy CVS <linuxtv.org/cvs>