* Minor TOS change
[specialops2.git] / lib / class.Messagelist_Flat.php
blob82e0d697ccae85272d7f86b9c118909718de9aa0
1 <?php
2 /**
3 * Plain messagelist like GF uses
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://../COPYING
7 * @version $Id$
8 */
9 require_once 'lib/iface.Messagelist.php';
11 class Messagelist_Flat implements Messagelist
13 const ID = 0;
14 const Name = 'Flat';
16 protected $postcount;
17 protected $msgs;
18 protected $topicid;
19 protected $mo;
20 protected $mpp;
21 protected $page;
23 function __construct($topicid, Messagestyle $mo, $mpp, $page)
25 global $DB;
26 $this->msgs = $DB->query('SELECT `messages`.`userid`, `alias`, `mtime`, `mtext`, `replyto`,
27 `score`, `marks`, `messages`.`messageid`, INET_NTOA(`origin_ip`) AS `ip`
28 FROM `message-data` NATURAL LEFT JOIN `messages` NATURAL LEFT JOIN `users`
29 WHERE `topicid` = '.$topicid.'
30 ORDER BY `mtime` ASC LIMIT '.($mpp*$page).', '.$mpp);
31 list($this->postcount) = $DB->query('SELECT COUNT(*) FROM `messages` WHERE `topicid` = '.$topicid)->fetch_row();
32 list($this->topicid, $this->mo, $this->mpp, $this->page) = func_get_args();
35 public function display()
37 while ( $m = $this->msgs->fetch_assoc() ) {
38 $this->mo->display($m);
42 public function pagelist()
44 $list = array();
46 if ( $this->postcount < $this->mpp ) {
47 return null;
50 if ( 0 == $this->mpp ) {
51 $this->mpp = 5;
52 trigger_error(__METHOD__.': $mpp was 0, changing to 5 instead', E_USER_WARNING);
55 for ( $i = 0; $i < $this->postcount; $i += $this->mpp ) {
56 if ( $i/$this->mpp == $this->page ) {
57 $list[] = '<dd class="curpage">['.($i/$this->mpp+1).']</dd>';
58 } else {
59 $rel = $i/$this->mpp == $this->page+1
60 ? 'next'
61 : ( $i/$this->mpp == $this->page-1
62 ? 'prev'
63 : ''
65 $list[] = sprintf('<dd%s><a href="messagelist?topic=%d;page=%d;length=%d"%s>%d</a></dd>',
66 $rel ? ' class="'.$rel.'"' : '', $this->topicid, ($i/$this->mpp), $this->mpp, $rel ? ' rel="'.$rel.'"' : '', ($i/$this->mpp+1));
70 return "\n\t".implode("\n\t", $list)."\n";