Topic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * This file takes care of actions on topics:
  4. * lock/unlock a topic, sticky/unsticky it,
  5. *
  6. * Simple Machines Forum (SMF)
  7. *
  8. * @package SMF
  9. * @author Simple Machines http://www.simplemachines.org
  10. * @copyright 2012 Simple Machines Forum contributors
  11. * @license http://www.simplemachines.org/about/smf/license.php BSD
  12. *
  13. * @version 2.1 Alpha 1
  14. */
  15. if (!defined('SMF'))
  16. die('Hacking attempt...');
  17. /**
  18. * Locks a topic... either by way of a moderator or the topic starter.
  19. * What this does:
  20. * - locks a topic, toggles between locked/unlocked/admin locked.
  21. * - only admins can unlock topics locked by other admins.
  22. * - requires the lock_own or lock_any permission.
  23. * - logs the action to the moderator log.
  24. * - returns to the topic after it is done.
  25. * - it is accessed via ?action=lock.
  26. */
  27. function LockTopic()
  28. {
  29. global $topic, $user_info, $sourcedir, $board, $smcFunc;
  30. // Just quit if there's no topic to lock.
  31. if (empty($topic))
  32. fatal_lang_error('not_a_topic', false);
  33. checkSession('get');
  34. // Get Subs-Post.php for sendNotifications.
  35. require_once($sourcedir . '/Subs-Post.php');
  36. // Find out who started the topic - in case User Topic Locking is enabled.
  37. $request = $smcFunc['db_query']('', '
  38. SELECT id_member_started, locked
  39. FROM {db_prefix}topics
  40. WHERE id_topic = {int:current_topic}
  41. LIMIT 1',
  42. array(
  43. 'current_topic' => $topic,
  44. )
  45. );
  46. list ($starter, $locked) = $smcFunc['db_fetch_row']($request);
  47. $smcFunc['db_free_result']($request);
  48. // Can you lock topics here, mister?
  49. $user_lock = !allowedTo('lock_any');
  50. if ($user_lock && $starter == $user_info['id'])
  51. isAllowedTo('lock_own');
  52. else
  53. isAllowedTo('lock_any');
  54. // Locking with high privileges.
  55. if ($locked == '0' && !$user_lock)
  56. $locked = '1';
  57. // Locking with low privileges.
  58. elseif ($locked == '0')
  59. $locked = '2';
  60. // Unlocking - make sure you don't unlock what you can't.
  61. elseif ($locked == '2' || ($locked == '1' && !$user_lock))
  62. $locked = '0';
  63. // You cannot unlock this!
  64. else
  65. fatal_lang_error('locked_by_admin', 'user');
  66. // Actually lock the topic in the database with the new value.
  67. $smcFunc['db_query']('', '
  68. UPDATE {db_prefix}topics
  69. SET locked = {int:locked}
  70. WHERE id_topic = {int:current_topic}',
  71. array(
  72. 'current_topic' => $topic,
  73. 'locked' => $locked,
  74. )
  75. );
  76. // If they are allowed a "moderator" permission, log it in the moderator log.
  77. if (!$user_lock)
  78. logAction($locked ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $board));
  79. // Notify people that this topic has been locked?
  80. sendNotifications($topic, empty($locked) ? 'unlock' : 'lock');
  81. // Back to the topic!
  82. redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . (WIRELESS ? ';moderate' : ''));
  83. }
  84. /**
  85. * Sticky a topic.
  86. * Can't be done by topic starters - that would be annoying!
  87. * What this does:
  88. * - stickies a topic - toggles between sticky and normal.
  89. * - requires the make_sticky permission.
  90. * - adds an entry to the moderator log.
  91. * - when done, sends the user back to the topic.
  92. * - accessed via ?action=sticky.
  93. */
  94. function Sticky()
  95. {
  96. global $modSettings, $topic, $board, $sourcedir, $smcFunc;
  97. // Make sure the user can sticky it, and they are stickying *something*.
  98. isAllowedTo('make_sticky');
  99. // You shouldn't be able to (un)sticky a topic if the setting is disabled.
  100. if (empty($modSettings['enableStickyTopics']))
  101. fatal_lang_error('cannot_make_sticky', false);
  102. // You can't sticky a board or something!
  103. if (empty($topic))
  104. fatal_lang_error('not_a_topic', false);
  105. checkSession('get');
  106. // We need Subs-Post.php for the sendNotifications() function.
  107. require_once($sourcedir . '/Subs-Post.php');
  108. // Is this topic already stickied, or no?
  109. $request = $smcFunc['db_query']('', '
  110. SELECT is_sticky
  111. FROM {db_prefix}topics
  112. WHERE id_topic = {int:current_topic}
  113. LIMIT 1',
  114. array(
  115. 'current_topic' => $topic,
  116. )
  117. );
  118. list ($is_sticky) = $smcFunc['db_fetch_row']($request);
  119. $smcFunc['db_free_result']($request);
  120. // Toggle the sticky value.... pretty simple ;).
  121. $smcFunc['db_query']('', '
  122. UPDATE {db_prefix}topics
  123. SET is_sticky = {int:is_sticky}
  124. WHERE id_topic = {int:current_topic}',
  125. array(
  126. 'current_topic' => $topic,
  127. 'is_sticky' => empty($is_sticky) ? 1 : 0,
  128. )
  129. );
  130. // Log this sticky action - always a moderator thing.
  131. logAction(empty($is_sticky) ? 'sticky' : 'unsticky', array('topic' => $topic, 'board' => $board));
  132. // Notify people that this topic has been stickied?
  133. if (empty($is_sticky))
  134. sendNotifications($topic, 'sticky');
  135. // Take them back to the now stickied topic.
  136. redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . (WIRELESS ? ';moderate' : ''));
  137. }
  138. ?>