Karma.php 7.5 KB

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