Small changes to index.php, moved the page time to the footer (all pages), and hopefu...
[specialops2.git] / lib / class.Topiclist_Default.php
blob540399a88009c4847e1d34a90bfd9517042ca3eb
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 $topicsum;
20 function __construct($tpp = 35, $page = 0)
22 global $DB, $user;
24 $this->tpp = $tpp;
25 $this->page = $page;
26 list($this->topicsum) = $DB->query('SELECT COUNT(*) FROM `topics` WHERE `boardid` = @boardid')->fetch_row();
29 public function display()
31 global $DB, $user;
33 $topics = $DB->query(
34 'SELECT `topics`.`topicid`, `topic_title`, `topics`.`userid`, `alias`, `messageid`, `mtime`,
35 (SELECT COUNT(*) FROM `messages` WHERE `messages`.`topicid` = `topics`.`topicid`) AS `posts`
36 FROM `topics`
37 LEFT JOIN `messages` ON `lastpost` = `messageid`
38 LEFT JOIN `users` ON `topics`.`userid` = `users`.`userid`
39 WHERE `boardid` = @boardid
40 GROUP BY `topicid`
41 ORDER BY `mtime` DESC
42 LIMIT '.($this->page*$this->tpp).', '.$this->tpp);
44 echo
45 "<table>\n",
46 '<col/><col/><col class="num"/><col/>',"\n",
47 "<thead>\n",
48 " <tr>\n",
49 ' <th scope="col">Topic</th>',"\n",
50 ' <th scope="col">Creator</th>',"\n",
51 ' <th scope="col">Posts</th>',"\n",
52 ' <th scope="col">Last Post</th>',"\n",
53 " </tr>\n",
54 "</thead>\n",
55 "<tbody>\n";
57 $a = 1;
59 while ( $topic = $topics->fetch_assoc() ) {
60 printf(
61 '<tr class="content c%d">'."\n".
62 ' <td><a class="topic" href="messagelist?%d">%s</a></td>'."\n".
63 " <td>%s</td>\n".
64 " <td>%d</td>\n".
65 " <td>%s</td>\n".
66 "</tr>\n",
67 (++$a&1),
68 $topic['topicid'],
69 $topic['topic_title'],
70 $user->namelink($topic['userid'], $topic['alias']),
71 $topic['posts'],
72 $user->fdate($topic['mtime'])
75 echo "</tbody>\n</table>\n";
78 public function pagelist()
80 global $boardid;
81 $list = array();
83 if ( $this->topicsum < $this->tpp ) {
84 return null;
87 if ( 0 == $this->tpp ) {
88 $this->tpp = 5;
89 trigger_error(__METHOD__.': $tpp was 0, changing to 5 instead', E_USER_WARNING);
92 for ( $i = 0; $i < $this->topicsum; $i += $this->tpp ) {
93 if ( $i/$this->tpp == $this->page ) {
94 $list[] = '<dd class="curpage">['.($i/$this->tpp+1).']</dd>';
95 } else {
96 $rel = $i/$this->tpp == $this->page+1
97 ? 'next'
98 : ( $i/$this->tpp == $this->page-1
99 ? 'prev'
100 : ''
102 $list[] = sprintf('<dd%s><a href="topiclist?board=%d;page=%d;length=%d"%s>%d</a></dd>',
103 $rel ? ' class="'.$rel.'"' : '', $boardid, ($i/$this->tpp), $this->tpp, $rel ? ' rel="'.$rel.'"' : '', ($i/$this->tpp+1));
107 return "\n\t".implode("\n\t", $list)."\n";