com web/news: Use new Nntp class to list groups on the index page: index.php
| From: | Ben Ramsey | Date: | Sat, 23 Jan 2016 05:34:32 +0000 |
| Subject: | com web/news: Use new Nntp class to list groups on the index page: index.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-24517@lists.php.net to get a copy of this message | ||
Commit: 1a72cf3803f548fd59b5c302b0fa5b1d45341e9c
Author: Ben Ramsey <ben@benramsey.com> Sat, 23 Jan 2016 00:34:32 -0500
Parents: ba6d4abfeb8407bf9677062f600a8fc61ca70b5d
Branches: master
Link: http://git.php.net/?p=web/news.git;a=commitdiff;h=1a72cf3803f548fd59b5c302b0fa5b1d45341e9c
Log:
Use new Nntp class to list groups on the index page
Changed paths:
M index.php
Diff:
diff --git a/index.php b/index.php
index 624a4b7..0453f3c 100644
--- a/index.php
+++ b/index.php
@@ -2,13 +2,11 @@
require 'common.php';
-$s = nntp_connect(NNTP_HOST);
-if (!$s) {
- error("Failed to connect to news server");
-}
-
-if (!nntp_cmd($s,"LIST",215)) {
- error("failed to get list of news groups");
+try {
+ $nntpClient = new \Web\News\Nntp(NNTP_HOST);
+ $groups = $nntpClient->listGroups();
+} catch (Exception $e) {
+ error($e->getMessage());
}
head();
@@ -25,22 +23,17 @@ head();
<th>rdf</th>
</tr>
<?php
-while ($line = fgets($s, 1024)) {
- if ($line == ".\r\n") {
- break;
- }
- $line = chop($line);
- list($group, $high, $low, $active) = explode(" ", $line);
+foreach ($groups as $group => $details) {
echo " <tr>\n";
- echo " <td><a class=\"active$active\"
href=\"/$group\">$group</a></td>\n";
- echo " <td align=\"right\">", $high-$low+1,
"</td>\n";
+ echo " <td><a class=\"active{$details['status']}\"
href=\"/$group\">$group</a></td>\n";
+ echo " <td align=\"right\">",
$details['high']-$details['low']+1, "</td>\n";
echo " <td>";
- if ($active != 'n') {
+ if ($details['status'] != 'n') {
echo "<a
href=\"group.php?group=$group&format=rss\">rss</a>";
}
echo "</td>\n";
echo " <td>";
- if ($active != 'n') {
+ if ($details['status'] != 'n') {
echo "<a
href=\"group.php?group=$group&format=rdf\">rdf</a>";
}
echo "</td>\n";