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