5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://COPYING
10 $prefetch = array('`points`', '`msglist_layout`');
13 $page->title
= 'Message Detail';
16 if ( ! ($user instanceof User_Authenticated
) ) {
17 $page->errorfooter('login');
19 if ( ! $user->has_priv('moderate') ) {
20 $page->errorfooter('level');
22 if ( empty($_SERVER['QUERY_STRING']) ||
!is_numeric($_SERVER['QUERY_STRING']) ) {
23 $page->errorfooter('messageid');
25 if ( isset($_POST['action']) && !in_array($_POST['action'], array('add', 'sub')) ) {
26 $page->errorfooter('request');
30 /* Get topic metadata */
31 $topic = $DB->query('SELECT `board_name`, `boards`.`boardid`, `topic_title`, `view_restrict`, `topicid`
32 FROM `boards` NATURAL LEFT JOIN `topics`
34 (SELECT `topicid` FROM `messages` WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']).')');
37 /* more error checks plz */
38 if ( 0 === $topic->num_rows
) {
39 $page->errorfooter('messageid');
41 $topic = $topic->fetch_assoc();
44 if ( ! $user->has_priv('viewboard', $topic['view_restrict']) ) {
45 $page->errorfooter('level');
49 /* Set header stuff */
50 $page->title
.= ': '.$topic['topic_title'].' (msg#'.$_SERVER['QUERY_STRING'].')';
51 $page->nav
['Topic List: '.$topic['board_name']] = 'topiclist?'.$topic['boardid'];
52 $page->nav
['Message List: '.$topic['topic_title']] = 'messagelist?'.$topic['topicid'];
55 $query = 'SELECT `messages`.`userid`, `alias`, `mtime`, `mtext`, `replyto`,
56 `score`, `marks`, `messages`.`messageid`, INET_NTOA(`origin_ip`) AS `ip`
58 NATURAL LEFT JOIN `messages`
59 NATURAL LEFT JOIN `users`
60 WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']);
62 define('HERE', $_SERVER['REQUEST_URI']);
64 if ( isset($_POST['action']) ) {
66 // Update message with new score
68 $meta = $DB->query($query)->fetch_assoc();
70 $DB->autocommit(false);
72 // Score depends on how many points the user has (i.e. the number of digits in it)
73 $score = ( 'add' === $_POST['action'] ?
74 floor(log($user->points
, 10))
76 floor(log($user->points
, 10)))
79 if ( !isset($_SERVER['HTTP_REFERER']) ||
!preg_match('/messagelist|detail/', $_SERVER['HTTP_REFERER']) ||
80 strpos($_SERVER['HTTP_REFERER'], 'http://'.$_SERVER['HTTP_HOST']) !== 0 ) {
81 throw new InvalidInputException('Invalid HTTP referrer sent: make sure you\'re using the right links.');
83 if ( $DB->query('SELECT `messageid` FROM `marks`
84 WHERE `userid` = @userid AND `messageid` = '.intval($_SERVER['QUERY_STRING']))->num_rows
) {
85 throw new RateLimitException('You\'ve already marked/suggested this message.');
87 if ( $user->userid
=== $meta['userid'] ) {
89 throw new RateLimitException('No.');
92 // Update message score
93 $DB->query('UPDATE `messages` SET `score` = `score` + '.$score.', `marks` = `marks` + 1 WHERE `messageid` = '.$meta['messageid']);
96 $user2 = new User_Registered($meta['userid'], array('`points`'));
97 $user2->points +
= $score;
99 // Add to marked messages list
100 $DB->query('INSERT INTO `marks` VALUES ('.intval($_SERVER['QUERY_STRING']).', @userid, '.$score.', UNIX_TIMESTAMP())');
104 header('Refresh: 5; url='.$_SERVER['HTTP_REFERER']);
106 echo '<p class="notice">Message successfully rated! You will be dumped back wherever you came from in 5 seconds.</p>',"\n";
108 } catch ( Exception
$e ) {
111 echo '<p class="error">',$e->getMessage(),"</p>\n";
117 switch ( $user->msglist_style
) {
118 case Messagestyle_Frozenoven
::ID
:
119 $mo = new Messagestyle_Frozenoven
; break;
120 case Messagestyle_IRC
::ID
:
121 $mo = new Messagestyle_IRC
; break;
122 case Messagestyle_Plain
::ID
:
124 $mo = new Messagestyle_Plain
;
127 $message = $DB->query($query)->fetch_assoc();
129 echo '<div class="',get_class($mo),"\">\n";
130 $mo->display($message);
133 if ( !isset($_POST) && $user->userid
!= $message['userid'] ) {
134 echo '<p class="info">Click the +/- links on the message to give or take points from it.</p>';
137 $m_usrs = $DB->query('SELECT `marks`.`userid`, `alias`
138 FROM `marks` NATURAL LEFT JOIN `users`
139 WHERE `messageid` = '.intval($_SERVER['QUERY_STRING']));
141 if ( $m_usrs->num_rows
) {
142 echo '<p class="info">People who rated this post: ',implode(', ', $user->fillnamecache($m_usrs)),"</p>\n";