comparison forum/Sources/LockTopic.php @ 76:e3e11437ecea website

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