forked from php/web-news
-
Notifications
You must be signed in to change notification settings - Fork 1
/
group.php
150 lines (139 loc) · 4.39 KB
/
group.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
require 'common.php';
if (isset($_GET['group'])) {
$group = preg_replace('@[^A-Za-z0-9.-]@', '', $_GET['group']);
} else {
error("Missing group");
}
if (isset($_GET['format'])) {
$format = $_GET['format'];
} else {
// assume html
$format = 'html';
}
if (isset($_GET['i'])) {
$i = (int)$_GET['i'];
} else {
$i = 0;
}
try {
$nntpClient = new \Web\News\Nntp(NNTP_HOST);
$overview = $nntpClient->getArticlesOverview($group, $i);
} catch (Exception $e) {
error($e->getMessage());
}
$host = htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, "UTF-8");
switch($format) {
case 'rss':
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";?>
<rss version="2.0">
<channel>
<title><?php echo $host; ?>: <?php echo $group?></title>
<link>http://<?php echo $host; ?>/group.php?group=<?php echo $group?></link>
<description></description>
<?php break;
case 'rdf':
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://my.netscape.com/rdf/simple/0.9/">
<channel>
<title><?php echo $host; ?>: <?php echo $group?></title>
<link>http://<?php echo $host; ?>/group.php?group=<?php echo $group?></link>
<description><?php echo $group?> Newsgroup at <?php echo NNTP_HOST; ?></description>
<language>en-US</language>
</channel>
<?php
break;
case 'html':
default:
head($group);
navbar($group, $overview['group']['low'], $overview['group']['high'], $overview['group']['start']);
echo ' <table class="stripped" width="100%">' . "\n";
echo ' <tr>' . "\n";
echo ' <th>#</td>' . "\n";
echo ' <th>subject</th>' . "\n";
echo ' <th>author</th>' . "\n";
echo ' <th>date</th>' . "\n";
echo ' <th>lines</th>' . "\n";
echo ' </tr>' . "\n";
break;
}
# list of articles
# TODO: somehow determine the correct charset
$charset = "utf-8";
foreach ($overview['articles'] as $articleNumber => $details) {
/* $date = date("H:i:s M/d/y", strtotime($odate)); */
$date822 = date("r", strtotime($details['date']));
switch($format) {
case 'rss':
echo " <item>\n";
echo " <link>http://$host/$group/$articleNumber</link>\n";
echo " <title>", format_subject($details['subject'], $charset), "</title>\n";
echo " <description>", htmlspecialchars(format_author($details['author'], $charset), ENT_QUOTES, "UTF-8"), "</description>\n";
echo " <pubDate>$date822</pubDate>\n";
echo " </item>\n";
break;
case 'rdf':
echo " <item>\n";
echo " <title>", format_subject($details['subject'], $charset), "</title>\n";
echo " <link>http://$host/$group/$articleNumber</link>\n";
echo " <description>", htmlspecialchars(format_author($details['author'], $charset), ENT_QUOTES, "UTF-8"), "</description>\n";
echo " <pubDate>$date822</pubDate>\n";
echo " </item>\n";
break;
case 'html':
default:
echo " <tr>\n";
echo " <td><a href=\"/$group/$articleNumber\">$articleNumber</a></td>\n";
echo " <td><a href=\"/$group/$articleNumber\">";
echo format_subject($details['subject'], $charset);
echo "</a></td>\n";
echo " <td vcard\">".format_author($details['author'], $charset)."</td>\n";
echo " <td align=\"center\"><tt>" . format_date($details['date']) . "</tt></td>\n";
echo " <td align=\"right\">{$details['lines']}</td>\n";
echo " </tr>\n";
}
}
switch ($format) {
case 'rss':
echo " </channel>\n</rss>\n";
break;
case 'rdf':
echo "</rdf:RDF>\n";
break;
case 'html':
default:
echo " </table>\n";
navbar($group, $overview['group']['low'], $overview['group']['high'], $overview['group']['start']);
foot();
}
function navbar($g, $f, $l, $i) {
echo ' <table border="0" cellpadding="2" cellspacing="2" width="100%">' . "\n";
echo ' <tr>' . "\n";
echo ' <th class="nav">';
if ($i > $f) {
$p = max($i-20,$f);
echo "<a href=\"/" . htmlspecialchars($g, ENT_QUOTES, "UTF-8") . "/start/$p\"><b>« previous</b></a>";
} else {
echo " ";
}
echo '</th>' . "\n";
$j = min($i + 20, $l);
$c = $l - $f + 1;
echo ' <th align="center">'.htmlspecialchars($g, ENT_QUOTES, "UTF-8")." ($i-$j of $c)</th>\n";
echo ' <th align="right" class="nav">';
if ($i+20 <= $l) {
$n = min($i + 20, $l - 19);
echo "<a href=\"/" . htmlspecialchars($g, ENT_QUOTES, "UTF-8") . "/start/$n\"><b>next »</b></a>";
}
else {
echo " ";
}
echo '</th>' . "\n";
echo ' </tr>' . "\n";
echo ' </table>' . "\n";
}