4 $prefetch = array('`points`', '`msglist_layout`');
7 $page->title
= 'Message Detail';
10 if ( ! ($user instanceof authuser
) ) {
11 $page->errorfooter('login');
13 if ( ! $user->has_priv('moderate') ) {
14 $page->errorfooter('level');
16 if ( empty($_SERVER['QUERY_STRING']) ||
!is_numeric($_SERVER['QUERY_STRING']) ) {
17 $page->errorfooter('messageid');
19 if ( isset($_POST['action']) && !in_array($_POST['action'], array('add', 'sub')) ) {
20 $page->errorfooter('request');
24 /* Get topic metadata */
25 $topic = $DB->query('SELECT `board_name`, `boards`.`boardid`, `topic_title`, `restrict`, `topicid`
27 NATURAL LEFT JOIN `topics`
28 WHERE `topicid` = (SELECT `topicid` FROM `messages`
29 WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']).')');
32 /* more error checks plz */
33 if ( 0 === $topic->num_rows
) {
34 $page->errorfooter('messageid');
36 $topic = $topic->fetch_assoc();
39 if ( 3 == $topic['restrict'] && !defined('DEVELOPER') ) {
40 $page->errorfooter('level', $topic['restrict']);
44 /* Set header stuff */
45 $page->title
.= ': '.$topic['topic_title'].' (msg#'.$_SERVER['QUERY_STRING'].')';
46 $page->nav
['Topic List: '.$topic['board_name']] = 'topiclist?'.$topic['boardid'];
47 $page->nav
['Message List: '.$topic['topic_title']] = 'messagelist?'.$topic['topicid'];
50 $query = 'SELECT `messages`.`userid`, `alias`, `mtime`, `mtext`, `replyto`,
51 `score`, `messages`.`messageid`, INET_NTOA(`origin_ip`) AS `ip`
53 NATURAL LEFT JOIN `messages`
54 NATURAL LEFT JOIN `users`
55 WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']);
57 define('HERE', $_SERVER['REQUEST_URI']);
59 if ( isset($_POST['action']) ) {
61 // Update message with new score
63 $meta = $DB->query($query)->fetch_assoc();
65 // Score depends on how many points the user has (i.e. the number of digits in it)
66 $score = ( 'add' === $_POST['action'] ?
floor(log($user->points
, 10)) : -(floor(log($user->points
, 10))) ); // :-(
68 if ( !isset($_SERVER['HTTP_REFERER']) ||
!preg_match('/messagelist|detail/', $_SERVER['HTTP_REFERER'])
69 ||
strpos($_SERVER['HTTP_REFERER'], 'http://'.$_SERVER['HTTP_HOST']) !== 0 ) {
70 throw new InvalidInputException
;
72 if ( $DB->query('SELECT `messageid` FROM `marks`
73 WHERE `userid` = @userid AND `messageid` = '.intval($_SERVER['QUERY_STRING']))->num_rows
) {
74 throw new RateLimitException('You\'ve already marked/suggested this message.');
76 if ( $user->userid
=== $meta['userid'] ) {
77 throw new RateLimitException('No self-gratification, kthx.');
80 $DB->autocommit(false);
82 // Update message score
83 $DB->query('UPDATE `messages` SET `score` = `score` + '.$score.' WHERE `messageid` = '.$meta['messageid']);
86 $user2 = new reguser($meta['userid'], array('`points`'));
87 $user2->points +
= $score;
89 // Add to marked messages list
90 $DB->query('INSERT INTO `marks` VALUES
91 ('.intval($_SERVER['QUERY_STRING']).', @userid, b\''.intval('add' === $_POST['action']).'\', UNIX_TIMESTAMP())');
95 header('Refresh: 5; url='.$_SERVER['HTTP_REFERER']);
97 echo '<p class="notice">Message successfully rated! You will be dumped back wherever you came from in 5 seconds.</p>',"\n";
99 } catch ( RateLimitException
$e ) {
102 echo '<p class="error">',$e->getMessage(),"</p>\n";
103 } catch ( InvalidInputException
$e ) {
105 echo '<p class="error">Invalid HTTP referrer sent: make sure you\'re using the right links.</p>',"\n";
110 switch ( $user->msglist_layout
) {
111 case messagelist_irc
::ID
:
112 $message = new messagelist_irc
; break;
114 $message = new messagelist_flat
; break;
117 $msg_sql = $DB->query($query);
119 echo '<div id="',get_class($message),"\">\n";
120 $message->display($msg_sql);
123 $msg_sql->data_seek(0);
124 $meta = $msg_sql->fetch_assoc();
126 if ( !isset($_POST) && $user->userid
!= $meta['userid'] ) {
127 echo '<p class="info">Click the +/- links on the message to give or take points from it.</p>';
130 $list = $DB->query('SELECT `marks`.`userid`, `alias`
131 FROM `marks` NATURAL LEFT JOIN `users`
132 WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']));
134 if ( $list->num_rows
) {
135 echo '<p>Users who rated this message: ',implode(', ', $user->fillnamecache($list)),"</p>\n";