* Minor TOS change
[specialops2.git] / lib / class.Boardlist_IRC.php
blobc983ef275494bec540520468c521f64eda1fb8b7
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 WHERE `hidden` = 0
24 ORDER BY `groupid` ASC, `boardid` ASC', MYSQLI_USE_RESULT);
26 // Really bad multidimensional array hack
27 while ( $tmp = $boards->fetch_assoc() ) {
28 $groups[array_shift($tmp)][array_shift($tmp)] = $tmp;
32 <table>
33 <col/><col class="num"/><col class="num"/><col/>
34 <thead>
35 <tr>
36 <th scope="col">Board</th>
37 <th scope="col">Posts</th>
38 <th scope="col">Topics</th>
39 <th scope="col">Last Post</th>
40 </tr>
41 </thead>
42 <?php
43 foreach ( $groups as $groupname => $boards ) {
44 echo '<tbody class="boardgroup">',"\n",
45 '<tr><th scope="rowgroup" colspan="4">',$groupname,"</th></tr>\n";
47 foreach ( $boards as $boardid => $board ) {
48 $DB->query('SET @boardid = '.$boardid);
50 list($postcount, $lastpost) = $DB->query('SELECT COUNT(*), MAX(`messageid`) FROM `messages` WHERE `topicid` IN
51 (SELECT `topicid` FROM `topics` WHERE `boardid` = @boardid)')->fetch_row();
52 list($topiccount) = $DB->query('SELECT COUNT(*) FROM `topics` WHERE `boardid` = @boardid')->fetch_row();
54 if ( $lastpost ) {
55 $postinfo = $DB->query('SELECT `messages`.`userid`, `alias`, `mtime`, `topics`.`topicid`, `topic_title`
56 FROM `messages`
57 LEFT JOIN `topics` USING(`topicid`)
58 LEFT JOIN `users` ON `messages`.`userid` = `users`.`userid`
59 WHERE `messageid` = '.$lastpost)->fetch_assoc();
60 } else {
61 $postinfo = null;
64 echo '<tr class="content">',"\n",
65 ' <td><a href="topiclist?',$boardid,'">',$board['name'],"</a><br/>\n",
66 ' <small style="margin-left:1em">',$board['caption'],"</small></td>\n",
67 ' <td>',$postcount,"</td>\n",
68 ' <td>',$topiccount,"</td>\n";
70 if ( $postinfo ) {
71 printf(
72 " <td><small>\n".
73 " <strong>From:</strong> %s\n".
74 " <strong>at</strong> %s<br/>\n".
75 " <strong>in topic:</strong> %s</small></td>\n".
76 "</tr>\n",
77 $user->namelink($postinfo['userid'], $postinfo['alias']),
78 $user->fdate($postinfo['mtime']),
79 $user->has_priv('viewboard', $board['view_restrict'])
80 ? '<a class="topic" href="messagelist?'.$postinfo['topicid'].'">'.$postinfo['topic_title'].'</a>'
81 : $postinfo['topic_title']
83 } else {
84 echo "\t<td>N/A</td>\n</tr>\n";
87 echo "</tbody>\n";
90 echo '<tbody class="boardgroup">',"\n",
91 '<tr><th scope="rowgroup" colspan="4">IRC</th></tr>',"\n";
93 foreach ( $this->ircchan as $channel ) {
94 $chan = IRCLOGS.'-'.$channel.'.log';
95 $last = `tail -n100 "$chan" | tac | grep -o '^.*<' | head -n1`;
96 echo '<tr class="content">',"\n",
97 ' <td><a href="irc://specialops.ath.cx/',$channel,'">',$channel,"</a></td>\n",
98 ' <td>',`wc -l "$chan" | grep -o ^[0-9]*`,"</td>\n",
99 " <td>-</td>\n",
100 ' <td>',$user->fdate(strtotime(substr($last, 0, -2))),"</td>\n",
101 "</tr>\n";
104 echo "</tbody>\n</table>\n";