5 * @author Ant P <p@cpi.merseine.nu>
6 * @licence file://COPYING
12 SO2
::$Page->title
= 'Message Detail';
15 if ( ! (SO2
::$User instanceof User_Authenticated
) ) {
16 SO2
::$Page->message(Page
::ERR_LOGIN
);
18 if ( ! SO2
::$User->has_access('moderate') ) {
19 SO2
::$Page->message(Page
::ERR_ULEVEL
);
21 if ( empty($_SERVER['QUERY_STRING']) ||
!is_numeric($_SERVER['QUERY_STRING']) ) {
22 SO2
::$Page->message(Page
::ERR_NOMSG
);
24 if ( isset($_POST['action']) && !in_array($_POST['action'], array('add', 'sub')) ) {
25 SO2
::$Page->message(Page
::ERR_BADREQ
);
30 $topic = SO2
::$DB->q('SELECT board_name, boards.boardid, topic_title, view_lvl, points, topicid '.
31 'FROM boards LEFT JOIN topics USING(boardid) '.
32 'WHERE topicid = (SELECT topicid FROM messages WHERE messageid = ?)',
33 $_SERVER['QUERY_STRING']);
35 // more error checks plz
37 SO2
::$Page->message(Page
::ERR_NOMSG
);
40 if ( ! SO2
::$User->has_access('viewboard', $topic) ) {
41 SO2
::$Page->message(Page
::ERR_ULEVEL
);
46 SO2
::$Page->title
.= sprintf(': %s (msg#%d)', $topic['topic_title'], $_SERVER['QUERY_STRING']);
47 SO2
::$Page->nav
['Topic List: '.$topic['board_name']] = 'topiclist?'.$topic['boardid'];
48 SO2
::$Page->nav
['Message List: '.$topic['topic_title']] = 'messagelist?'.$topic['topicid'];
51 // Get metadata from the actual message being modified
52 $meta = SO2
::$DB->q('SELECT userid, mtime, topicid, replyto, score, marks, messageid, INET_NTOA(origin_ip) AS ip '.
53 'FROM messages WHERE messageid = ?', $_SERVER['QUERY_STRING']);
55 define('HERE', $_SERVER['REQUEST_URI']);
57 if ( isset($_POST['action']) ) {
59 // Update message with new score
61 SO2
::$DB->beginTransaction();
63 // Score is proportional to the user's number of points
64 $score = ( 'add' === $_POST['action']
65 ? SO2
::$User->has_access('moderate')
66 :-( SO2
::$User->has_access('moderate') )
70 if ( !isset($_SERVER['HTTP_REFERER'])
71 ||
!preg_match('/messagelist|detail/', $_SERVER['HTTP_REFERER'])
72 ||
strpos($_SERVER['HTTP_REFERER'], 'http://'.$_SERVER['HTTP_HOST']) !== 0 ) {
73 throw new InvalidInputException('Invalid HTTP referrer sent: make sure you\'re using the right links.');
76 if ( SO2
::$DB->q('SELECT COUNT(*) FROM marks WHERE userid = @userid AND messageid = ?',
77 $_SERVER['QUERY_STRING'], SO2_PDO
::QVALUE
) ) {
78 throw new RateLimitException('You\'ve already marked/suggested this message.');
81 if ( SO2
::$User->userid
=== $meta['userid'] ) {
82 SO2
::$User->points
-= 5;
83 throw new RateLimitException('No.');
86 // Update message score
87 SO2
::$DB->q('UPDATE messages SET score = score + ?, marks = marks + 1 WHERE messageid = ?',
88 array($score, $meta['messageid']));
91 $user2 = new User_Registered($meta['userid']);
92 $user2->points +
= $score;
94 // Add to marked messages list
95 SO2
::$DB->q('INSERT INTO marks VALUES (?, @userid, ?, UNIX_TIMESTAMP())', array($_SERVER['QUERY_STRING'], $score));
99 header('Refresh: 5; url='.$_SERVER['HTTP_REFERER']);
100 SO2
::$Page->message('Message rated! You will be sent back to the previous page in 5 seconds.', E_USER_NOTICE
);
102 } catch ( RateLimitException
$e ) {
103 SO2
::$Page->message($e->getMessage(), E_USER_WARNING
);
104 } catch ( InvalidInputException
$e ) {
105 SO2
::$Page->message($e->getMessage(), E_USER_WARNING
);
108 SO2
::$Page->pageheader();
111 if ( file_exists('lib/Messagestyle_'.SO2
::$User->msglist_style
.'.php') ) {
112 $style = 'Messagestyle_'.SO2
::$User->msglist_style
;
114 $style = 'Messagestyle_Default';
118 echo '<div class="',get_class($mo),"\">\n";
122 if ( ! isset($_POST) && SO2
::$User->userid
!= $message['userid'] ) {
123 echo '<p class="info">Click the +/- links to give or take points. Everyone can see who voted for a message.</p>';
126 $marks = SO2
::$DB->q('SELECT userid FROM marks WHERE messageid = ?', $_SERVER['QUERY_STRING'], SO2_PDO
::QOBJ
)->fetchAll(PDO
::FETCH_COLUMN
);
128 if ( count($marks) ) {
129 echo '<p class="info">Post modded by: ',implode(', ', array_map(array(SO2
::$Page, 'namelink'), $marks)),"</p>\n";