com web/news: Use Nntp class to list messages on individual group page: group.php
| From: | Ben Ramsey | Date: | Sat, 23 Jan 2016 05:36:06 +0000 |
| Subject: | com web/news: Use Nntp class to list messages on individual group page: group.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-24513@lists.php.net to get a copy of this message | ||
Commit: 7cbd35c71a8e5c5c76178e19c23af2176f373d80
Author: Ben Ramsey <ben@benramsey.com> Sat, 23 Jan 2016 00:36:06 -0500
Parents: 1a72cf3803f548fd59b5c302b0fa5b1d45341e9c
Branches: master
Link: http://git.php.net/?p=web/news.git;a=commitdiff;h=7cbd35c71a8e5c5c76178e19c23af2176f373d80
Log:
Use Nntp class to list messages on individual group page
Changed paths:
M group.php
Diff:
diff --git a/group.php b/group.php
index 36d61f7..58c0c91 100644
--- a/group.php
+++ b/group.php
@@ -21,25 +21,11 @@ if (isset($_GET['i'])) {
$i = 0;
}
-$s = nntp_connect(NNTP_HOST);
-if (!$s) {
- error("Failed to connect to news server");
-}
-
-$res = nntp_cmd($s,"GROUP $group",211);
-if (!$res) {
- error("Failed to get info on group");
-}
-
-list (, $f, $l, $g) = explode(" ", $res);
-if (!$i || $i > $l - 19 || $i < $f) {
- $i = $l - $f > 19 ? $l - 19 : $f;
-}
-$n = min($l, $i + 19);
-
-$res = nntp_cmd($s,"XOVER $i-$n", 224);
-if (!$res) {
- error("Failed to get xover data");
+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");
@@ -71,7 +57,7 @@ break;
case 'html':
default:
head($group);
-navbar($group,$f,$l,$i);
+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";
@@ -85,43 +71,39 @@ break;
# list of articles
# TODO: somehow determine the correct charset
-$charset = "";
+$charset = "utf-8";
-while ($line = fgets($s, 16384)) {
- if ($line == ".\r\n") break;
- $line = chop($line);
- list($n,$subj,$author,$odate,$messageid,$references,$bytes,$lines,$extra)
- = explode("\t", $line, 9);
+foreach ($overview['articles'] as $articleNumber => $details) {
/* $date = date("H:i:s M/d/y", strtotime($odate)); */
- $date822 = date("r", strtotime($odate));
+ $date822 = date("r", strtotime($details['date']));
switch($format) {
case 'rss':
echo " <item>\n";
- echo " <link>http://$host/$group/$n</link>\n";
- echo " <title>", format_subject($subj, $charset), "</title>\n";
- echo " <description>", htmlspecialchars(format_author($author, $charset),
ENT_QUOTES, "UTF-8"), "</description>\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($subj, $charset), "</title>\n";
- echo " <link>http://$host/$group/$n</link>\n";
- echo " <description>", htmlspecialchars(format_author($author, $charset),
ENT_QUOTES, "UTF-8"), "</description>\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/$n\">$n</a></td>\n";
- echo " <td><a href=\"/$group/$n\">";
- echo format_subject($subj, $charset);
+ 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($author,
$charset)."</td>\n";
- echo " <td align=\"center\"><tt>" . format_date($odate) .
"</tt></td>\n";
- echo " <td align=\"right\">$lines</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";
}
}
@@ -136,7 +118,7 @@ switch ($format) {
case 'html':
default:
echo " </table>\n";
- navbar($group, $f, $l, $i);
+ navbar($group, $overview['group']['low'],
$overview['group']['high'], $overview['group']['start']);
foot();
}