* Minor TOS change
[specialops2.git] / lib / class.Topiclist_Default.php
blob2294c8f00ec112001dbdf796ed81f3cf66d42944
1 <?php
2 /**
3 * SO2 default topic list layout
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
7 * @version $Id$
8 */
10 require_once 'lib/iface.Topiclist.php';
12 class Topiclist_Default implements Topiclist
14 const ID = 0;
15 const Name = 'SO2';
16 protected $tpp;
17 protected $page;
18 protected $viewable;
19 protected $topicsum;
21 function __construct($tpp = 35, $page = 0, $viewable = false)
23 global $DB, $user;
25 $this->tpp = $tpp;
26 $this->page = $page;
27 $this->viewable = $viewable;
28 list($this->topicsum) = $DB->query('SELECT COUNT(*) FROM `topics` WHERE `boardid` = @boardid')->fetch_row();
31 public function display()
33 global $DB, $user;
35 $topics = $DB->query(
36 'SELECT `topics`.`topicid`, `topic_title`, `topics`.`userid`, `alias`, `messageid`, `mtime`,
37 (SELECT COUNT(*) FROM `messages` WHERE `messages`.`topicid` = `topics`.`topicid`) AS `posts`
38 FROM `topics`
39 LEFT JOIN `messages` ON `lastpost` = `messageid`
40 LEFT JOIN `users` ON `topics`.`userid` = `users`.`userid`
41 WHERE `boardid` = @boardid
42 GROUP BY `topicid`
43 ORDER BY `mtime` DESC
44 LIMIT '.($this->page*$this->tpp).', '.$this->tpp);
46 echo
47 "<table>\n",
48 '<col/><col/><col class="num"/><col/>',"\n",
49 "<thead>\n",
50 " <tr>\n",
51 ' <th scope="col">Topic</th>',"\n",
52 ' <th scope="col">Creator</th>',"\n",
53 ' <th scope="col">Posts</th>',"\n",
54 ' <th scope="col">Last Post</th>',"\n",
55 " </tr>\n",
56 "</thead>\n",
57 "<tbody>\n";
59 $a = 1;
61 while ( $topic = $topics->fetch_assoc() ) {
62 printf(
63 '<tr class="content c%d">'."\n".
64 " <td>%s</td>\n".
65 " <td>%s</td>\n".
66 " <td>%d</td>\n".
67 " <td>%s</td>\n".
68 "</tr>\n",
69 (++$a&1),
70 $this->viewable
71 ? '<a class="topic" href="messagelist?'.$topic['topicid'].'">'.$topic['topic_title'].'</a>'
72 : $topic['topic_title'],
73 $user->namelink($topic['userid'], $topic['alias']),
74 $topic['posts'],
75 $user->fdate($topic['mtime'])
78 echo "</tbody>\n</table>\n";
81 public function pagelist()
83 global $boardid;
84 $list = array();
86 if ( $this->topicsum < $this->tpp ) {
87 return null;
90 if ( 0 == $this->tpp ) {
91 $this->tpp = 5;
92 trigger_error(__METHOD__.': $tpp was 0, changing to 5 instead', E_USER_WARNING);
95 for ( $i = 0; $i < $this->topicsum; $i += $this->tpp ) {
96 if ( $i/$this->tpp == $this->page ) {
97 $list[] = '<dd class="curpage">['.($i/$this->tpp+1).']</dd>';
98 } else {
99 $rel = $i/$this->tpp == $this->page+1
100 ? 'next'
101 : ( $i/$this->tpp == $this->page-1
102 ? 'prev'
103 : ''
105 $list[] = sprintf('<dd%s><a href="topiclist?board=%d;page=%d;length=%d"%s>%d</a></dd>',
106 $rel ? ' class="'.$rel.'"' : '', $boardid, ($i/$this->tpp), $this->tpp, $rel ? ' rel="'.$rel.'"' : '', ($i/$this->tpp+1));
110 return "\n\t".implode("\n\t", $list)."\n";