Corn
[specialops2.git] / lib / class.Boardlist_IRC.php
blob336e6ebe666d7cb5f67a3aa29f2dc4a14e2f3bbf
1 <?php
2 /**
3 * Gross hack
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
7 * @version $Id$
8 */
9 require_once 'iface.Boardlist.php';
11 class Boardlist_IRC implements Boardlist
13 const ID = 3;
14 const Name = 'Special Ops';
15 private $ircchan = array('##');
17 function display()
19 global $DB, $user;
21 $boards = $DB->query('SELECT `group_name`, `boardid`, `board_name` AS `name`, `caption`, `view_restrict`
22 FROM `boards` LEFT JOIN `board-groups` USING(`groupid`)
23 ORDER BY `groupid` ASC, `boardid` ASC', MYSQLI_USE_RESULT);
25 // Really bad multidimensional array hack
26 while ( $tmp = $boards->fetch_assoc() ) {
27 $groups[array_shift($tmp)][array_shift($tmp)] = $tmp;
31 <table>
32 <col/><col/><col/><col/>
33 <thead>
34 <tr>
35 <th scope="col">Board</th>
36 <th scope="col">Posts</th>
37 <th scope="col">Topics</th>
38 <th scope="col">Last Post</th>
39 </tr>
40 </thead>
41 <?php
42 foreach ( $groups as $groupname => $boards ) {
43 echo '<tbody class="boardgroup">',"\n",
44 '<tr><th scope="rowgroup" colspan="4">',$groupname,"</th></tr>\n";
46 foreach ( $boards as $boardid => $board ) {
47 $DB->query('SET @boardid = '.$boardid);
49 list($postcount, $lastpost) = $DB->query('SELECT COUNT(*), MAX(`messageid`) FROM `messages` WHERE `topicid` IN
50 (SELECT `topicid` FROM `topics` WHERE `boardid` = @boardid)')->fetch_row();
51 list($topiccount) = $DB->query('SELECT COUNT(*) FROM `topics` WHERE `boardid` = @boardid')->fetch_row();
53 if ( $lastpost ) {
54 $postinfo = $DB->query('SELECT `messages`.`userid`, `alias`, `mtime`, `topics`.`topicid`, `topic_title`
55 FROM `messages`
56 LEFT JOIN `topics` USING(`topicid`)
57 LEFT JOIN `users` ON `messages`.`userid` = `users`.`userid`
58 WHERE `messageid` = '.$lastpost)->fetch_assoc();
59 } else {
60 $postinfo = null;
63 echo '<tr class="content">',"\n",
64 ' <td>'.(
65 $user->has_priv('viewboard', $board['view_restrict']) ?
66 '<a href="topiclist?'.$boardid.'">'.$board['name'].'</a>' : $board['name']
67 )."<br/>\n",
68 ' <small style="margin-left:1em">',$board['caption'],"</small></td>\n",
69 ' <td>',$postcount,"</td>\n",
70 ' <td>',$topiccount,"</td>\n";
72 if ( $postinfo && $user->has_priv('viewboard', $board['view_restrict']) ) {
73 printf(
74 " <td><small>\n".
75 " <strong>From:</strong> %s\n".
76 " <strong>at</strong> %s<br/>\n".
77 ' <strong>in topic:</strong> <a class="topic" href="messagelist?%d">%s</a></small></td>'."\n".
78 "</tr>\n",
79 $user->namelink($postinfo['userid'],
80 $postinfo['alias']),
81 $user->fdate($postinfo['mtime']),
82 $postinfo['topicid'],
83 $postinfo['topic_title']
85 } else {
86 echo "\t<td>N/A</td>\n</tr>\n";
89 echo "</tbody>\n";
92 echo '<tbody class="boardgroup">',"\n",
93 '<tr><th scope="rowgroup" colspan="4">IRC</th></tr>',"\n";
95 foreach ( $this->ircchan as $channel ) {
96 $chan = IRCLOGS.'-'.$channel.'.log';
97 $last = `tail -n100 "$chan" | grep -o '^.*<' | tail -n1`;
98 echo '<tr class="content">',"\n",
99 ' <td><a href="irc://specialops.ath.cx/',$channel,'">',$channel,"</a></td>\n",
100 ' <td>',`wc -l "$chan" | grep -o ^[0-9]*`,"</td>\n",
101 " <td>-</td>\n",
102 ' <td>',$user->fdate(strtotime(substr($last, 0, -2))),"</td>\n",
103 "</tr>\n";
106 echo "</tbody>\n</table>\n";