comparison forum/Sources/Karma.php @ 76:e3e11437ecea website

Add forum code
author Chris Cannam
date Sun, 07 Jul 2013 11:25:48 +0200
parents
children
comparison
equal deleted inserted replaced
75:72f59aa7e503 76:e3e11437ecea
1 <?php
2
3 /**
4 * Simple Machines Forum (SMF)
5 *
6 * @package SMF
7 * @author Simple Machines http://www.simplemachines.org
8 * @copyright 2011 Simple Machines
9 * @license http://www.simplemachines.org/about/smf/license.php BSD
10 *
11 * @version 2.0
12 */
13
14 if (!defined('SMF'))
15 die('Hacking attempt...');
16
17 /* This file contains one humble function, which applauds or smites a user.
18
19 void ModifyKarma()
20 - gives or takes karma from a user.
21 - redirects back to the referrer afterward, whether by javascript or
22 the passed parameters.
23 - requires the karma_edit permission, and that the user isn't a guest.
24 - depends on the karmaMode, karmaWaitTime, and karmaTimeRestrictAdmins
25 settings.
26 - is accessed via ?action=modifykarma.
27 */
28
29 // Modify a user's karma.
30 function ModifyKarma()
31 {
32 global $modSettings, $txt, $user_info, $topic, $smcFunc, $context;
33
34 // If the mod is disabled, show an error.
35 if (empty($modSettings['karmaMode']))
36 fatal_lang_error('feature_disabled', true);
37
38 // If you're a guest or can't do this, blow you off...
39 is_not_guest();
40 isAllowedTo('karma_edit');
41
42 checkSession('get');
43
44 // If you don't have enough posts, tough luck.
45 // !!! Should this be dropped in favor of post group permissions? Should this apply to the member you are smiting/applauding?
46 if (!$user_info['is_admin'] && $user_info['posts'] < $modSettings['karmaMinPosts'])
47 fatal_lang_error('not_enough_posts_karma', true, array($modSettings['karmaMinPosts']));
48
49 // And you can't modify your own, punk! (use the profile if you need to.)
50 if (empty($_REQUEST['uid']) || (int) $_REQUEST['uid'] == $user_info['id'])
51 fatal_lang_error('cant_change_own_karma', false);
52
53 // The user ID _must_ be a number, no matter what.
54 $_REQUEST['uid'] = (int) $_REQUEST['uid'];
55
56 // Applauding or smiting?
57 $dir = $_REQUEST['sa'] != 'applaud' ? -1 : 1;
58
59 // Delete any older items from the log. (karmaWaitTime is by hour.)
60 $smcFunc['db_query']('', '
61 DELETE FROM {db_prefix}log_karma
62 WHERE {int:current_time} - log_time > {int:wait_time}',
63 array(
64 'wait_time' => (int) ($modSettings['karmaWaitTime'] * 3600),
65 'current_time' => time(),
66 )
67 );
68
69 // Start off with no change in karma.
70 $action = 0;
71
72 // Not an administrator... or one who is restricted as well.
73 if (!empty($modSettings['karmaTimeRestrictAdmins']) || !allowedTo('moderate_forum'))
74 {
75 // Find out if this user has done this recently...
76 $request = $smcFunc['db_query']('', '
77 SELECT action
78 FROM {db_prefix}log_karma
79 WHERE id_target = {int:id_target}
80 AND id_executor = {int:current_member}
81 LIMIT 1',
82 array(
83 'current_member' => $user_info['id'],
84 'id_target' => $_REQUEST['uid'],
85 )
86 );
87 if ($smcFunc['db_num_rows']($request) > 0)
88 list ($action) = $smcFunc['db_fetch_row']($request);
89 $smcFunc['db_free_result']($request);
90 }
91
92 // They haven't, not before now, anyhow.
93 if (empty($action) || empty($modSettings['karmaWaitTime']))
94 {
95 // Put it in the log.
96 $smcFunc['db_insert']('replace',
97 '{db_prefix}log_karma',
98 array('action' => 'int', 'id_target' => 'int', 'id_executor' => 'int', 'log_time' => 'int'),
99 array($dir, $_REQUEST['uid'], $user_info['id'], time()),
100 array('id_target', 'id_executor')
101 );
102
103 // Change by one.
104 updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karma_good' : 'karma_bad' => '+'));
105 }
106 else
107 {
108 // If you are gonna try to repeat.... don't allow it.
109 if ($action == $dir)
110 fatal_lang_error('karma_wait_time', false, array($modSettings['karmaWaitTime'], $txt['hours']));
111
112 // You decided to go back on your previous choice?
113 $smcFunc['db_query']('', '
114 UPDATE {db_prefix}log_karma
115 SET action = {int:action}, log_time = {int:current_time}
116 WHERE id_target = {int:id_target}
117 AND id_executor = {int:current_member}',
118 array(
119 'current_member' => $user_info['id'],
120 'action' => $dir,
121 'current_time' => time(),
122 'id_target' => $_REQUEST['uid'],
123 )
124 );
125
126 // It was recently changed the OTHER way... so... reverse it!
127 if ($dir == 1)
128 updateMemberData($_REQUEST['uid'], array('karma_good' => '+', 'karma_bad' => '-'));
129 else
130 updateMemberData($_REQUEST['uid'], array('karma_bad' => '+', 'karma_good' => '-'));
131 }
132
133 // Figure out where to go back to.... the topic?
134 if (!empty($topic))
135 redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . '#msg' . (int) $_REQUEST['m']);
136 // Hrm... maybe a personal message?
137 elseif (isset($_REQUEST['f']))
138 redirectexit('action=pm;f=' . $_REQUEST['f'] . ';start=' . $_REQUEST['start'] . (isset($_REQUEST['l']) ? ';l=' . (int) $_REQUEST['l'] : '') . (isset($_REQUEST['pm']) ? '#' . (int) $_REQUEST['pm'] : ''));
139 // JavaScript as a last resort.
140 else
141 {
142 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
143 <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
144 <head>
145 <title>...</title>
146 <script type="text/javascript"><!-- // --><![CDATA[
147 history.go(-1);
148 // ]]></script>
149 </head>
150 <body>&laquo;</body>
151 </html>';
152
153 obExit(false);
154 }
155 }
156
157 // What's this? I dunno, what are you talking about? Never seen this before, nope. No siree.
158 function BookOfUnknown()
159 {
160 global $context;
161
162 if (strpos($_GET['action'], 'mozilla') !== false && !$context['browser']['is_gecko'])
163 redirectexit('http://www.getfirefox.com/');
164 elseif (strpos($_GET['action'], 'mozilla') !== false)
165 redirectexit('about:mozilla');
166
167 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
168 <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
169 <head>
170 <title>The Book of Unknown, ', @$_GET['verse'] == '2:18' ? '2:18' : '4:16', '</title>
171 <style type="text/css">
172 em
173 {
174 font-size: 1.3em;
175 line-height: 0;
176 }
177 </style>
178 </head>
179 <body style="background-color: #444455; color: white; font-style: italic; font-family: serif;">
180 <div style="margin-top: 12%; font-size: 1.1em; line-height: 1.4; text-align: center;">';
181 if (@$_GET['verse'] == '2:18')
182 echo '
183 Woe, it was that his name wasn\'t <em>known</em>, that he came in mystery, and was recognized by none.&nbsp;And it became to be in those days <em>something</em>.&nbsp; Something not yet <em id="unknown" name="[Unknown]">unknown</em> to mankind.&nbsp; And thus what was to be known the <em>secret project</em> began into its existence.&nbsp; Henceforth the opposition was only <em>weary</em> and <em>fearful</em>, for now their match was at arms against them.';
184 else
185 echo '
186 And it came to pass that the <em>unbelievers</em> dwindled in number and saw rise of many <em>proselytizers</em>, and the opposition found fear in the face of the <em>x</em> and the <em>j</em> while those who stood with the <em>something</em> grew stronger and came together.&nbsp; Still, this was only the <em>beginning</em>, and what lay in the future was <em id="unknown" name="[Unknown]">unknown</em> to all, even those on the right side.';
187 echo '
188 </div>
189 <div style="margin-top: 2ex; font-size: 2em; text-align: right;">';
190 if (@$_GET['verse'] == '2:18')
191 echo '
192 from <span style="font-family: Georgia, serif;"><strong><a href="http://www.unknownbrackets.com/about:unknown" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 2:18</span>';
193 else
194 echo '
195 from <span style="font-family: Georgia, serif;"><strong><a href="http://www.unknownbrackets.com/about:unknown" style="color: white; text-decoration: none; cursor: text;">The Book of Unknown</a></strong>, 4:16</span>';
196 echo '
197 </div>
198 </body>
199 </html>';
200
201 obExit(false);
202 }
203
204 ?>