/components/com_kunena/lib/kunena.karma.php

https://github.com/rich20/Kunena-1.6 · PHP · 199 lines · 154 code · 16 blank · 29 comment · 58 complexity · 538cd1e2bde9e94108762e20e1c43ab9 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id$
  4. * Kunena Component
  5. * @package Kunena
  6. *
  7. * @Copyright (C) 2008 - 2011 Kunena Team. All rights reserved.
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. * @link http://www.kunena.org
  10. *
  11. * Based on FireBoard Component
  12. * @Copyright (C) 2006 - 2007 Best Of Joomla All rights reserved.
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  14. * @link http://www.bestofjoomla.com
  15. *
  16. * Based on Joomlaboard Component
  17. * @copyright (C) 2000 - 2004 TSMF / Jan de Graaff / All rights reserved.
  18. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  19. * @author TSMF & Jan de Graaff
  20. **/
  21. defined( '_JEXEC' ) or die();
  22. $kunena_config = KunenaFactory::getConfig ();
  23. $kunena_db = &JFactory::getDBO();
  24. $kunena_app =& JFactory::getApplication();
  25. $do = JRequest::getCmd ( 'do', '' );
  26. $userid = JRequest::getInt ( 'userid', 0 );
  27. $pid = JRequest::getInt ( 'pid', 0 );
  28. if ($pid) {
  29. $kunena_db->setQuery("SELECT catid, thread FROM #__kunena_messages WHERE id={$kunena_db->Quote($pid)}");
  30. $kmsg = $kunena_db->loadObject();
  31. if (KunenaError::checkDatabaseError()) return;
  32. if (is_object($kmsg)) {
  33. $catid = $kmsg->catid;
  34. $thread = $kmsg->thread;
  35. }
  36. }
  37. //Modify this to change the minimum time between karma modifications from the same user
  38. $karma_min_seconds = '14400'; // 14400 seconds = 6 hours
  39. $kunena_my = JFactory::getUser();
  40. ?>
  41. <table>
  42. <tr>
  43. <td>
  44. <center>
  45. <?php
  46. //This checks:
  47. // - if the karma function is activated by the admin
  48. // - if a registered user submits the modify request
  49. // - if he specifies an action related to the karma change
  50. // - if he specifies the user that will have the karma modified
  51. if ($kunena_config->showkarma && $kunena_my->id && $do && $userid)
  52. {
  53. $time = CKunenaTimeformat::internalTime();
  54. if ($kunena_my->id != $userid)
  55. {
  56. if (JRequest::checkToken ( 'get' ) == false) {
  57. $this->_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  58. if ($pid) {
  59. while (@ob_end_clean());
  60. $kunena_app->redirect ( CKunenaLink::GetLatestPageAutoRedirectURL ( $pid, $kunena_config->messages_per_page, $catid) );
  61. } else {
  62. while (@ob_end_clean());
  63. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  64. }
  65. return;
  66. }
  67. // This checkes to see if it's not too soon for a new karma change
  68. if (!CKunenaTools::isModerator($kunena_my->id, $catid))
  69. {
  70. $userprofile = KunenaFactory::getUser($kunena_my->id);
  71. $karma_time_old = $userprofile->karma_time;
  72. $karma_time_diff = $time - $karma_time_old;
  73. }
  74. if (CKunenaTools::isModerator($kunena_my->id, $catid) || $karma_time_diff >= $karma_min_seconds)
  75. {
  76. if ($do == "increase")
  77. {
  78. $kunena_db->setQuery("UPDATE #__kunena_users SET karma_time={$kunena_db->Quote($time)} WHERE userid={$kunena_db->Quote( $kunena_my->id )} ");
  79. $kunena_db->query();
  80. if (KunenaError::checkDatabaseError()) return;
  81. $kunena_db->setQuery("UPDATE #__kunena_users SET karma=karma+1 WHERE userid={$kunena_db->Quote( $userid )}");
  82. $kunena_db->query();
  83. if (KunenaError::checkDatabaseError()) return;
  84. // Activity integration
  85. $activity = KunenaFactory::getActivityIntegration();
  86. $activity->onAfterKarma($userid, $kunena_my->id, 1);
  87. if ($pid) {
  88. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_INCREASED'));
  89. while (@ob_end_clean());
  90. $kunena_app->redirect ( CKunenaLink::GetMessageURL ( $pid, $catid, 0, false ) );
  91. } else {
  92. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_INCREASED'));
  93. while (@ob_end_clean());
  94. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  95. }
  96. }
  97. else if ($do == "decrease")
  98. {
  99. $kunena_db->setQuery("UPDATE #__kunena_users SET karma_time={$kunena_db->Quote($time)} WHERE userid={$kunena_db->Quote($kunena_my->id)}");
  100. $kunena_db->query();
  101. if (KunenaError::checkDatabaseError()) return;
  102. $kunena_db->setQuery("UPDATE #__kunena_users SET karma=karma-1 WHERE userid={$kunena_db->Quote($userid)}");
  103. $kunena_db->query();
  104. if (KunenaError::checkDatabaseError()) return;
  105. // Activity integration
  106. $activity = KunenaFactory::getActivityIntegration();
  107. $activity->onAfterKarma($userid, $kunena_my->id, -1);
  108. if ($pid) {
  109. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_DECREASED'));
  110. while (@ob_end_clean());
  111. $kunena_app->redirect ( CKunenaLink::GetMessageURL ( $pid, $catid, 0, false ) );
  112. } else {
  113. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_DECREASED'));
  114. while (@ob_end_clean());
  115. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  116. }
  117. }
  118. else
  119. { //you got me there... don't know what to $do
  120. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_USER_ERROR_KARMA'));
  121. while (@ob_end_clean());
  122. $kunena_app->redirect ( CKunenaLink::GetLatestPageAutoRedirectURL ( $pid, $kunena_config->messages_per_page ) );
  123. }
  124. } else {
  125. if ($pid) {
  126. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_WAIT'));
  127. while (@ob_end_clean());
  128. $kunena_app->redirect ( CKunenaLink::GetMessageURL ( $pid, $catid, 0, false ) );
  129. }else{
  130. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_WAIT'));
  131. while (@ob_end_clean());
  132. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  133. }
  134. }
  135. }
  136. else if ($kunena_my->id == $userid) // In case the user tries modifing his own karma by changing the userid from the URL...
  137. {
  138. if ($do == "increase") // Seriously decrease his karma if he tries to increase it
  139. {
  140. $kunena_db->setQuery("UPDATE #__kunena_users SET karma=karma-10, karma_time={$kunena_db->Quote($time)} WHERE userid='{$kunena_db->Quote($kunena_my->id)}");
  141. $kunena_db->query();
  142. if (KunenaError::checkDatabaseError()) return;
  143. // Activity integration
  144. $activity = KunenaFactory::getActivityIntegration();
  145. $activity->onAfterKarma($userid, $kunena_my->id, -10);
  146. if ($pid) {
  147. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_SELF_INCREASE'));
  148. while (@ob_end_clean());
  149. $kunena_app->redirect ( CKunenaLink::GetMessageURL ( $pid, $catid, 0, false ) );
  150. } else {
  151. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_SELF_INCREASE'));
  152. while (@ob_end_clean());
  153. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  154. }
  155. }
  156. if ($do == "decrease") // Stop him from decreasing his karma but still update karma_time
  157. {
  158. $kunena_db->setQuery("UPDATE #__kunena_users SET karma_time={$kunena_db->Quote($time)} WHERE userid={$kunena_db->Quote($kunena_my->id)}");
  159. $kunena_db->query();
  160. if (KunenaError::checkDatabaseError()) return;
  161. if ($pid) {
  162. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_SELF_DECREASE'));
  163. while (@ob_end_clean());
  164. $kunena_app->redirect ( CKunenaLink::GetMessageURL ( $pid, $catid, 0, false ) );
  165. } else {
  166. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_KARMA_SELF_DECREASE'));
  167. while (@ob_end_clean());
  168. $kunena_app->redirect ( CKunenaLink::GetMyProfileURL ( $userid) );
  169. }
  170. }
  171. }
  172. }
  173. else
  174. { //get outa here, you fraud!
  175. $kunena_app->enqueueMessage(JText::_('COM_KUNENA_USER_ERROR_KARMA'));
  176. while (@ob_end_clean());
  177. $kunena_app->redirect ( CKunenaLink::GetLatestPageAutoRedirectURL ( $pid, $kunena_config->messages_per_page ) );
  178. }
  179. ?>
  180. </center>
  181. </td>
  182. </tr>
  183. </table>