Special Ops 2.50
[specialops2.git] / lib / Messagelist_Flat.php
blob92921e67190575a5a48adadd7cee870ab8ebff2b
1 <?php
2 /**
3 * Plain messagelist like GF uses
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://../COPYING
7 * @version 2.15
8 */
9 require_once 'lib/iface.Messagelist.php';
11 class Messagelist_Flat implements Messagelist
13 protected $postcount;
14 protected $msgs;
15 protected $args;
17 protected $topicid;
18 protected $mo;
19 protected $mpp;
20 protected $page;
23 function __construct($topicid, Messagestyle $mo, $mpp, $page)
25 if ( 0 == $mpp ) {
26 throw new Exception('<blink>CANNOT DIVIDE BY ZERO</blink>');
29 $this->msgs = SO2::$DB->q('SELECT userid, mtime, topicid, replyto, score, marks, messageid, INET_NTOA(origin_ip) AS ip '.
30 'FROM messages WHERE topicid = ? ORDER BY mtime ASC LIMIT ?, ?',
31 array($topicid, $mpp*$page, $mpp), SO2_PDO::QOBJ)->fetchAll(PDO::FETCH_ASSOC);
32 $this->postcount = SO2::$DB->q('SELECT COUNT(*) FROM messages WHERE topicid = ?', $topicid, SO2_PDO::QVALUE);
34 list($this->topicid, $this->mo, $this->mpp, $this->page) = func_get_args();
37 public function display()
39 foreach ( $this->msgs as $m ) {
40 if ( $m['score'] < SO2::$User->cutoff && SO2::$User->userid != $m['userid'] )
41 $m['mtext'] = sprintf(self::MODMSG, SO2::$User->cutoff);
42 $this->mo->display($m);
46 public function pagelist()
48 // Not enough to fill one page
49 if ( $this->postcount < $this->mpp ) {
50 return null;
53 $list = range(0, $this->postcount/$this->mpp);
54 $str = '';
56 foreach ( $list as $pagenum ) {
57 switch ( $pagenum ) {
58 case $this->page-1: // current page in script is off by one from display here
59 $str .= sprintf('<dd class="prev"><a href="messagelist?topic=%d;page=%d;length=%d" rel="prev">%d</a></dd>',
60 $this->topicid, $pagenum, $this->mpp, $pagenum+1); break;
61 case $this->page:
62 $str .= '<dd class="curpage">'.($pagenum+1).'</dd>'; break;
63 case $this->page+1:
64 $str .= sprintf('<dd class="next"><a href="messagelist?topic=%d;page=%d;length=%d" rel="next">%d</a></dd>',
65 $this->topicid, $pagenum, $this->mpp, $pagenum+1); break;
66 default:
67 $str .= sprintf('<dd><a href="messagelist?topic=%d;page=%d;length=%d">%d</a></dd>',
68 $this->topicid, $pagenum, $this->mpp, $pagenum+1); break;
73 return $str;