LockTopic.php 4.5 KB

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