Author: Jim Winstead (jimwins) Committer: GitHub (web-flow) Pusher: jimwins Date: 2024-08-23T16:12:29-07:00
Commit: https://github.com/php/web-news/commit/7bf968e47b586ec625391c8bc546d71aa74b7a69 Raw diff: https://github.com/php/web-news/commit/7bf968e47b586ec625391c8bc546d71aa74b7a69.diff Show descriptions for each newsgroup (#21) Changed paths: M index.php M lib/Web/News/Nntp.php Diff: diff --git a/index.php b/index.php index 64a9541..278b703 100644 --- a/index.php +++ b/index.php @@ -5,6 +5,7 @@ try { $nntpClient = new \Web\News\Nntp($NNTP_HOST); $groups = $nntpClient->listGroups(); + $descriptions = $nntpClient->listGroupDescriptions(); /* Reorder so it's moderated, active, and inactive */ $order = [ 'm' => 1, 'y' => 2, 'n' => 3 ]; uasort($groups, function ($a, $b) use ($order) { @@ -38,24 +39,26 @@ <table class="standard"> <tr> <th>name</th> + <th>description</th> <th>messages</th> <th>rss</th> <th>rdf</th> </tr> <tr> - <th colspan="4">Moderated Lists</th> + <th colspan="5">Moderated Lists</th> </tr> <?php $last_status = 'm'; foreach ($groups as $group => $details) { if ($details['status'] != $last_status) { $last_status = $details['status']; - echo '<tr><th colspan="4">', + echo '<tr><th colspan="5">', $last_status == 'y' ? 'Discussion Lists' : 'Inactive Lists', "</th></tr>\n"; } echo " <tr>\n"; echo " <td><a class=\"active{$details['status']}\" href=\"/$group\">$group</a></td>\n"; + echo " <td>", htmlspecialchars($descriptions[$group]), "</td>\n"; echo " <td class=\"align-right\">", $details['high'] - $details['low'] + 1, "</td>\n"; echo " <td>"; if ($details['status'] != 'n') { diff --git a/lib/Web/News/Nntp.php b/lib/Web/News/Nntp.php index 10d7c55..e76902d 100644 --- a/lib/Web/News/Nntp.php +++ b/lib/Web/News/Nntp.php @@ -85,6 +85,34 @@ public function listGroups() return $list; } + /** + * Sends the LIST NEWSGROUPS command to the server and returns an array of + * groups descriptions + * + * @return array + */ + public function listGroupDescriptions() + { + $list = []; + + $response = $this->sendCommand('LIST NEWSGROUPS', 215); + + if ($response !== false) { + while ($line = fgets($this->connection)) { + if ($line == ".\r\n") { + break; + } + + $line = rtrim($line); + list($group, $description) = explode(' ', $line, 2); + + $list[$group] = $description; + } + } + + return $list; + } + /** * Sets the active group at the server and returns details about the group *