Karma.php 7.4 KB

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