Special Ops 2.50
[specialops2.git] / lib / Topiclist_Lite.php
blob72dd928150addf93fd1f3957d853d78296e2b307
1 <?php
2 /**
3 * SO2 default topic list layout
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://../COPYING
7 * @version 2.15
8 */
10 require_once 'lib/iface.Topiclist.php';
12 class Topiclist_Lite implements Topiclist
14 protected $tpp;
15 protected $page;
16 protected $topicsum;
18 function __construct($tpp = 35, $page = 0)
20 $this->tpp = $tpp;
21 $this->page = $page;
22 $this->topicsum = SO2::$DB->query('SELECT COUNT(*) FROM topics WHERE boardid = @boardid')->fetchColumn(0);
25 public function display()
27 // bleh
28 $q = SO2::$DB->q(
29 'SELECT topics.topicid, topic_title, topics.userid, messageid, mtime, '.
30 '(SELECT COUNT(*) FROM messages WHERE messages.topicid = topics.topicid) AS posts '.
31 'FROM topics LEFT JOIN messages ON lastpost = messageid '.
32 'WHERE boardid = @boardid '.
33 'GROUP BY topicid '.
34 'ORDER BY mtime DESC '.
35 'LIMIT ?, ?', array($this->page*$this->tpp, $this->tpp), SO2_PDO::QOBJ);
36 $topics = $q->fetchAll();
38 echo
39 "<table>\n",
40 ' <col/><col/><col class="num"/><col/>',"\n",
41 " <thead>\n",
42 " <tr>\n",
43 ' <th scope="col">Topic</th>',"\n",
44 ' <th scope="col">Creator</th>',"\n",
45 ' <th scope="col">Posts</th>',"\n",
46 ' <th scope="col">Last Post</th>',"\n",
47 " </tr>\n",
48 " </thead>\n",
49 " <tbody>\n";
51 $a = 1;
53 foreach ( $topics as $topic ) {
54 printf(
55 ' <tr class="content c%d u%d">'."\n".
56 ' <td><a class="topic" href="messagelist?%d">%s</a></td>'."\n".
57 " <td>%s</td>\n".
58 " <td>%d</td>\n".
59 " <td>%s</td>\n".
60 " </tr>\n",
61 (++$a&1),
62 $topic['topicid'],
63 $topic['userid'],
64 $topic['topic_title'],
65 SO2::$Page->namelink($topic['userid']),
66 $topic['posts'],
67 SO2::$Page->fdate($topic['mtime'])
70 echo " </tbody>\n</table>\n";
73 public function pagelist()
75 global $boardid; // This is a nasty hack
76 $list = array();
78 if ( $this->topicsum < $this->tpp ) {
79 return null;
82 if ( 0 == $this->tpp ) {
83 $this->tpp = 5;
84 trigger_error(__METHOD__.': $tpp was 0, changing to 5 instead', E_USER_WARNING);
87 for ( $i = 0; $i < $this->topicsum; $i += $this->tpp ) {
88 if ( $i/$this->tpp == $this->page ) {
89 $list[] = '<dd class="curpage">['.($i/$this->tpp+1).']</dd>';
90 } else {
91 $rel = ( $i/$this->tpp == $this->page+1
92 ? 'next'
93 : ( $i/$this->tpp == $this->page-1
94 ? 'prev'
95 : '' ) );
96 $list[] = sprintf('<dd%s><a href="topiclist?board=%d;page=%d;length=%d"%s>%d</a></dd>',
97 ( $rel ? ' class="'.$rel.'"' : '' ),
98 $boardid,
99 ($i/$this->tpp),
100 $this->tpp,
101 ( $rel ? ' rel="'.$rel.'"' : '' ),
102 ($i/$this->tpp+1)
107 return "\n\t".implode("\n\t", $list)."\n";