annotate forum/Sources/LockTopic.php @ 85:6d7b61434be7 website

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