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 contains all the screens that control settings for topics and
|
Chris@76
|
18 posts.
|
Chris@76
|
19
|
Chris@76
|
20 void ManagePostSettings()
|
Chris@76
|
21 - the main entrance point for the 'Posts and topics' screen.
|
Chris@76
|
22 - accessed from ?action=admin;area=postsettings.
|
Chris@76
|
23 - calls the right function based on the given sub-action.
|
Chris@76
|
24 - defaults to sub-action 'posts'.
|
Chris@76
|
25 - requires (and checks for) the admin_forum permission.
|
Chris@76
|
26
|
Chris@76
|
27 void SetCensor()
|
Chris@76
|
28 - shows an interface to set and test word censoring.
|
Chris@76
|
29 - requires the admin_forum permission.
|
Chris@76
|
30 - uses the Admin template and the edit_censored sub template.
|
Chris@76
|
31 - tests the censored word if one was posted.
|
Chris@76
|
32 - uses the censor_vulgar, censor_proper, censorWholeWord, and
|
Chris@76
|
33 censorIgnoreCase settings.
|
Chris@76
|
34 - accessed from ?action=admin;area=postsettings;sa=censor.
|
Chris@76
|
35
|
Chris@76
|
36 void ModifyPostSettings()
|
Chris@76
|
37 - set any setting related to posts and posting.
|
Chris@76
|
38 - requires the admin_forum permission
|
Chris@76
|
39 - uses the edit_post_settings sub template of the Admin template.
|
Chris@76
|
40 - accessed from ?action=admin;area=postsettings;sa=posts.
|
Chris@76
|
41
|
Chris@76
|
42 void ModifyBBCSettings()
|
Chris@76
|
43 - set a few Bulletin Board Code settings.
|
Chris@76
|
44 - requires the admin_forum permission
|
Chris@76
|
45 - uses the edit_bbc_settings sub template of the Admin template.
|
Chris@76
|
46 - accessed from ?action=admin;area=postsettings;sa=bbc.
|
Chris@76
|
47 - loads a list of Bulletin Board Code tags to allow disabling tags.
|
Chris@76
|
48
|
Chris@76
|
49 void ModifyTopicSettings()
|
Chris@76
|
50 - set any setting related to topics.
|
Chris@76
|
51 - requires the admin_forum permission
|
Chris@76
|
52 - uses the edit_topic_settings sub template of the Admin template.
|
Chris@76
|
53 - accessed from ?action=admin;area=postsettings;sa=topics.
|
Chris@76
|
54 */
|
Chris@76
|
55
|
Chris@76
|
56 function ManagePostSettings()
|
Chris@76
|
57 {
|
Chris@76
|
58 global $context, $txt, $scripturl;
|
Chris@76
|
59
|
Chris@76
|
60 // Make sure you can be here.
|
Chris@76
|
61 isAllowedTo('admin_forum');
|
Chris@76
|
62
|
Chris@76
|
63 $subActions = array(
|
Chris@76
|
64 'posts' => 'ModifyPostSettings',
|
Chris@76
|
65 'bbc' => 'ModifyBBCSettings',
|
Chris@76
|
66 'censor' => 'SetCensor',
|
Chris@76
|
67 'topics' => 'ModifyTopicSettings',
|
Chris@76
|
68 );
|
Chris@76
|
69
|
Chris@76
|
70 // Default the sub-action to 'posts'.
|
Chris@76
|
71 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'posts';
|
Chris@76
|
72
|
Chris@76
|
73 $context['page_title'] = $txt['manageposts_title'];
|
Chris@76
|
74
|
Chris@76
|
75 // Tabs for browsing the different ban functions.
|
Chris@76
|
76 $context[$context['admin_menu_name']]['tab_data'] = array(
|
Chris@76
|
77 'title' => $txt['manageposts_title'],
|
Chris@76
|
78 'help' => 'posts_and_topics',
|
Chris@76
|
79 'description' => $txt['manageposts_description'],
|
Chris@76
|
80 'tabs' => array(
|
Chris@76
|
81 'posts' => array(
|
Chris@76
|
82 'description' => $txt['manageposts_settings_description'],
|
Chris@76
|
83 ),
|
Chris@76
|
84 'bbc' => array(
|
Chris@76
|
85 'description' => $txt['manageposts_bbc_settings_description'],
|
Chris@76
|
86 ),
|
Chris@76
|
87 'censor' => array(
|
Chris@76
|
88 'description' => $txt['admin_censored_desc'],
|
Chris@76
|
89 ),
|
Chris@76
|
90 'topics' => array(
|
Chris@76
|
91 'description' => $txt['manageposts_topic_settings_description'],
|
Chris@76
|
92 ),
|
Chris@76
|
93 ),
|
Chris@76
|
94 );
|
Chris@76
|
95
|
Chris@76
|
96 // Call the right function for this sub-action.
|
Chris@76
|
97 $subActions[$_REQUEST['sa']]();
|
Chris@76
|
98 }
|
Chris@76
|
99
|
Chris@76
|
100 // Set the censored words.
|
Chris@76
|
101 function SetCensor()
|
Chris@76
|
102 {
|
Chris@76
|
103 global $txt, $modSettings, $context, $smcFunc;
|
Chris@76
|
104
|
Chris@76
|
105 if (!empty($_POST['save_censor']))
|
Chris@76
|
106 {
|
Chris@76
|
107 // Make sure censoring is something they can do.
|
Chris@76
|
108 checkSession();
|
Chris@76
|
109
|
Chris@76
|
110 $censored_vulgar = array();
|
Chris@76
|
111 $censored_proper = array();
|
Chris@76
|
112
|
Chris@76
|
113 // Rip it apart, then split it into two arrays.
|
Chris@76
|
114 if (isset($_POST['censortext']))
|
Chris@76
|
115 {
|
Chris@76
|
116 $_POST['censortext'] = explode("\n", strtr($_POST['censortext'], array("\r" => '')));
|
Chris@76
|
117
|
Chris@76
|
118 foreach ($_POST['censortext'] as $c)
|
Chris@76
|
119 list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
|
Chris@76
|
120 }
|
Chris@76
|
121 elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
|
Chris@76
|
122 {
|
Chris@76
|
123 if (is_array($_POST['censor_vulgar']))
|
Chris@76
|
124 {
|
Chris@76
|
125 foreach ($_POST['censor_vulgar'] as $i => $value)
|
Chris@76
|
126 {
|
Chris@76
|
127 if (trim(strtr($value, '*', ' ')) == '')
|
Chris@76
|
128 unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
|
Chris@76
|
129 }
|
Chris@76
|
130
|
Chris@76
|
131 $censored_vulgar = $_POST['censor_vulgar'];
|
Chris@76
|
132 $censored_proper = $_POST['censor_proper'];
|
Chris@76
|
133 }
|
Chris@76
|
134 else
|
Chris@76
|
135 {
|
Chris@76
|
136 $censored_vulgar = explode("\n", strtr($_POST['censor_vulgar'], array("\r" => '')));
|
Chris@76
|
137 $censored_proper = explode("\n", strtr($_POST['censor_proper'], array("\r" => '')));
|
Chris@76
|
138 }
|
Chris@76
|
139 }
|
Chris@76
|
140
|
Chris@76
|
141 // Set the new arrays and settings in the database.
|
Chris@76
|
142 $updates = array(
|
Chris@76
|
143 'censor_vulgar' => implode("\n", $censored_vulgar),
|
Chris@76
|
144 'censor_proper' => implode("\n", $censored_proper),
|
Chris@76
|
145 'censorWholeWord' => empty($_POST['censorWholeWord']) ? '0' : '1',
|
Chris@76
|
146 'censorIgnoreCase' => empty($_POST['censorIgnoreCase']) ? '0' : '1',
|
Chris@76
|
147 );
|
Chris@76
|
148
|
Chris@76
|
149 updateSettings($updates);
|
Chris@76
|
150 }
|
Chris@76
|
151
|
Chris@76
|
152 if (isset($_POST['censortest']))
|
Chris@76
|
153 {
|
Chris@76
|
154 $censorText = htmlspecialchars($_POST['censortest'], ENT_QUOTES);
|
Chris@76
|
155 $context['censor_test'] = strtr(censorText($censorText), array('"' => '"'));
|
Chris@76
|
156 }
|
Chris@76
|
157
|
Chris@76
|
158 // Set everything up for the template to do its thang.
|
Chris@76
|
159 $censor_vulgar = explode("\n", $modSettings['censor_vulgar']);
|
Chris@76
|
160 $censor_proper = explode("\n", $modSettings['censor_proper']);
|
Chris@76
|
161
|
Chris@76
|
162 $context['censored_words'] = array();
|
Chris@76
|
163 for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++)
|
Chris@76
|
164 {
|
Chris@76
|
165 if (empty($censor_vulgar[$i]))
|
Chris@76
|
166 continue;
|
Chris@76
|
167
|
Chris@76
|
168 // Skip it, it's either spaces or stars only.
|
Chris@76
|
169 if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '')
|
Chris@76
|
170 continue;
|
Chris@76
|
171
|
Chris@76
|
172 $context['censored_words'][htmlspecialchars(trim($censor_vulgar[$i]))] = isset($censor_proper[$i]) ? htmlspecialchars($censor_proper[$i]) : '';
|
Chris@76
|
173 }
|
Chris@76
|
174
|
Chris@76
|
175 $context['sub_template'] = 'edit_censored';
|
Chris@76
|
176 $context['page_title'] = $txt['admin_censored_words'];
|
Chris@76
|
177 }
|
Chris@76
|
178
|
Chris@76
|
179 // Modify all settings related to posts and posting.
|
Chris@76
|
180 function ModifyPostSettings($return_config = false)
|
Chris@76
|
181 {
|
Chris@76
|
182 global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $db_prefix;
|
Chris@76
|
183
|
Chris@76
|
184 // All the settings...
|
Chris@76
|
185 $config_vars = array(
|
Chris@76
|
186 // Simple post options...
|
Chris@76
|
187 array('check', 'removeNestedQuotes'),
|
Chris@76
|
188 array('check', 'enableEmbeddedFlash', 'subtext' => $txt['enableEmbeddedFlash_warning']),
|
Chris@76
|
189 // Note show the warning as read if pspell not installed!
|
Chris@76
|
190 array('check', 'enableSpellChecking', 'subtext' => (function_exists('pspell_new') ? $txt['enableSpellChecking_warning'] : ('<span class="alert">' . $txt['enableSpellChecking_warning'] . '</span>'))),
|
Chris@76
|
191 array('check', 'disable_wysiwyg'),
|
Chris@76
|
192 '',
|
Chris@76
|
193 // Posting limits...
|
Chris@76
|
194 array('int', 'max_messageLength', 'subtext' => $txt['max_messageLength_zero'], 'postinput' => $txt['manageposts_characters']),
|
Chris@76
|
195 array('int', 'fixLongWords', 'subtext' => $txt['fixLongWords_zero'] . ($context['utf8'] ? ' <span class="alert">' . $txt['fixLongWords_warning'] . '</span>' : ''), 'postinput' => $txt['manageposts_characters']),
|
Chris@76
|
196 array('int', 'topicSummaryPosts', 'postinput' => $txt['manageposts_posts']),
|
Chris@76
|
197 '',
|
Chris@76
|
198 // Posting time limits...
|
Chris@76
|
199 array('int', 'spamWaitTime', 'postinput' => $txt['manageposts_seconds']),
|
Chris@76
|
200 array('int', 'edit_wait_time', 'postinput' => $txt['manageposts_seconds']),
|
Chris@76
|
201 array('int', 'edit_disable_time', 'subtext' => $txt['edit_disable_time_zero'], 'postinput' => $txt['manageposts_minutes']),
|
Chris@76
|
202 );
|
Chris@76
|
203
|
Chris@76
|
204 if ($return_config)
|
Chris@76
|
205 return $config_vars;
|
Chris@76
|
206
|
Chris@76
|
207 // We'll want this for our easy save.
|
Chris@76
|
208 require_once($sourcedir . '/ManageServer.php');
|
Chris@76
|
209
|
Chris@76
|
210 // Setup the template.
|
Chris@76
|
211 $context['page_title'] = $txt['manageposts_settings'];
|
Chris@76
|
212 $context['sub_template'] = 'show_settings';
|
Chris@76
|
213
|
Chris@76
|
214 // Are we saving them - are we??
|
Chris@76
|
215 if (isset($_GET['save']))
|
Chris@76
|
216 {
|
Chris@76
|
217 checkSession();
|
Chris@76
|
218
|
Chris@76
|
219 // If we're changing the message length let's check the column is big enough.
|
Chris@76
|
220 if (!empty($_POST['max_messageLength']) && $_POST['max_messageLength'] != $modSettings['max_messageLength'])
|
Chris@76
|
221 {
|
Chris@76
|
222 db_extend('packages');
|
Chris@76
|
223
|
Chris@76
|
224 $colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
|
Chris@76
|
225 foreach ($colData as $column)
|
Chris@76
|
226 if ($column['name'] == 'body')
|
Chris@76
|
227 $body_type = $column['type'];
|
Chris@76
|
228
|
Chris@76
|
229 $indData = $smcFunc['db_list_indexes']('{db_prefix}messages', true);
|
Chris@76
|
230 foreach ($indData as $index)
|
Chris@76
|
231 foreach ($index['columns'] as $column)
|
Chris@76
|
232 if ($column == 'body' && $index['type'] == 'fulltext')
|
Chris@76
|
233 $fulltext = true;
|
Chris@76
|
234
|
Chris@76
|
235 if (isset($body_type) && $_POST['max_messageLength'] > 65535 && $body_type == 'text')
|
Chris@76
|
236 {
|
Chris@76
|
237 // !!! Show an error message?!
|
Chris@76
|
238 // MySQL only likes fulltext indexes on text columns... for now?
|
Chris@76
|
239 if (!empty($fulltext))
|
Chris@76
|
240 $_POST['max_messageLength'] = 65535;
|
Chris@76
|
241 else
|
Chris@76
|
242 {
|
Chris@76
|
243 // Make it longer so we can do their limit.
|
Chris@76
|
244 $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
|
Chris@76
|
245 }
|
Chris@76
|
246 }
|
Chris@76
|
247 elseif (isset($body_type) && $_POST['max_messageLength'] <= 65535 && $body_type != 'text')
|
Chris@76
|
248 {
|
Chris@76
|
249 // Shorten the column so we can have the benefit of fulltext searching again!
|
Chris@76
|
250 $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
|
Chris@76
|
251 }
|
Chris@76
|
252 }
|
Chris@76
|
253
|
Chris@76
|
254 saveDBSettings($config_vars);
|
Chris@76
|
255 redirectexit('action=admin;area=postsettings;sa=posts');
|
Chris@76
|
256 }
|
Chris@76
|
257
|
Chris@76
|
258 // Final settings...
|
Chris@76
|
259 $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=posts';
|
Chris@76
|
260 $context['settings_title'] = $txt['manageposts_settings'];
|
Chris@76
|
261
|
Chris@76
|
262 // Prepare the settings...
|
Chris@76
|
263 prepareDBSettingContext($config_vars);
|
Chris@76
|
264 }
|
Chris@76
|
265
|
Chris@76
|
266 // Bulletin Board Code...a lot of Bulletin Board Code.
|
Chris@76
|
267 function ModifyBBCSettings($return_config = false)
|
Chris@76
|
268 {
|
Chris@76
|
269 global $context, $txt, $modSettings, $helptxt, $scripturl, $sourcedir;
|
Chris@76
|
270
|
Chris@76
|
271 $config_vars = array(
|
Chris@76
|
272 // Main tweaks
|
Chris@76
|
273 array('check', 'enableBBC'),
|
Chris@76
|
274 array('check', 'enablePostHTML'),
|
Chris@76
|
275 array('check', 'autoLinkUrls'),
|
Chris@76
|
276 '',
|
Chris@76
|
277 array('bbc', 'disabledBBC'),
|
Chris@76
|
278 );
|
Chris@76
|
279
|
Chris@76
|
280 if ($return_config)
|
Chris@76
|
281 return $config_vars;
|
Chris@76
|
282
|
Chris@76
|
283 // Setup the template.
|
Chris@76
|
284 require_once($sourcedir . '/ManageServer.php');
|
Chris@76
|
285 $context['sub_template'] = 'show_settings';
|
Chris@76
|
286 $context['page_title'] = $txt['manageposts_bbc_settings_title'];
|
Chris@76
|
287
|
Chris@76
|
288 // Make sure we check the right tags!
|
Chris@76
|
289 $modSettings['bbc_disabled_disabledBBC'] = empty($modSettings['disabledBBC']) ? array() : explode(',', $modSettings['disabledBBC']);
|
Chris@76
|
290
|
Chris@76
|
291 // Saving?
|
Chris@76
|
292 if (isset($_GET['save']))
|
Chris@76
|
293 {
|
Chris@76
|
294 checkSession();
|
Chris@76
|
295
|
Chris@76
|
296 // Clean up the tags.
|
Chris@76
|
297 $bbcTags = array();
|
Chris@76
|
298 foreach (parse_bbc(false) as $tag)
|
Chris@76
|
299 $bbcTags[] = $tag['tag'];
|
Chris@76
|
300
|
Chris@76
|
301 if (!isset($_POST['disabledBBC_enabledTags']))
|
Chris@76
|
302 $_POST['disabledBBC_enabledTags'] = array();
|
Chris@76
|
303 elseif (!is_array($_POST['disabledBBC_enabledTags']))
|
Chris@76
|
304 $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
|
Chris@76
|
305 // Work out what is actually disabled!
|
Chris@76
|
306 $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
|
Chris@76
|
307
|
Chris@76
|
308 saveDBSettings($config_vars);
|
Chris@76
|
309 redirectexit('action=admin;area=postsettings;sa=bbc');
|
Chris@76
|
310 }
|
Chris@76
|
311
|
Chris@76
|
312 $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=bbc';
|
Chris@76
|
313 $context['settings_title'] = $txt['manageposts_bbc_settings_title'];
|
Chris@76
|
314
|
Chris@76
|
315 prepareDBSettingContext($config_vars);
|
Chris@76
|
316 }
|
Chris@76
|
317
|
Chris@76
|
318 // Function for modifying topic settings. Not very exciting.
|
Chris@76
|
319 function ModifyTopicSettings($return_config = false)
|
Chris@76
|
320 {
|
Chris@76
|
321 global $context, $txt, $modSettings, $sourcedir, $scripturl;
|
Chris@76
|
322
|
Chris@76
|
323 // Here are all the topic settings.
|
Chris@76
|
324 $config_vars = array(
|
Chris@76
|
325 // Some simple bools...
|
Chris@76
|
326 array('check', 'enableStickyTopics'),
|
Chris@76
|
327 array('check', 'enableParticipation'),
|
Chris@76
|
328 '',
|
Chris@76
|
329 // Pagination etc...
|
Chris@76
|
330 array('int', 'oldTopicDays', 'postinput' => $txt['manageposts_days'], 'subtext' => $txt['oldTopicDays_zero']),
|
Chris@76
|
331 array('int', 'defaultMaxTopics', 'postinput' => $txt['manageposts_topics']),
|
Chris@76
|
332 array('int', 'defaultMaxMessages', 'postinput' => $txt['manageposts_posts']),
|
Chris@76
|
333 '',
|
Chris@76
|
334 // Hot topics (etc)...
|
Chris@76
|
335 array('int', 'hotTopicPosts', 'postinput' => $txt['manageposts_posts']),
|
Chris@76
|
336 array('int', 'hotTopicVeryPosts', 'postinput' => $txt['manageposts_posts']),
|
Chris@76
|
337 '',
|
Chris@76
|
338 // All, next/prev...
|
Chris@76
|
339 array('int', 'enableAllMessages', 'postinput' => $txt['manageposts_posts'], 'subtext' => $txt['enableAllMessages_zero']),
|
Chris@76
|
340 array('check', 'disableCustomPerPage'),
|
Chris@76
|
341 array('check', 'enablePreviousNext'),
|
Chris@76
|
342
|
Chris@76
|
343 );
|
Chris@76
|
344
|
Chris@76
|
345 if ($return_config)
|
Chris@76
|
346 return $config_vars;
|
Chris@76
|
347
|
Chris@76
|
348 // Get the settings template ready.
|
Chris@76
|
349 require_once($sourcedir . '/ManageServer.php');
|
Chris@76
|
350
|
Chris@76
|
351 // Setup the template.
|
Chris@76
|
352 $context['page_title'] = $txt['manageposts_topic_settings'];
|
Chris@76
|
353 $context['sub_template'] = 'show_settings';
|
Chris@76
|
354
|
Chris@76
|
355 // Are we saving them - are we??
|
Chris@76
|
356 if (isset($_GET['save']))
|
Chris@76
|
357 {
|
Chris@76
|
358 checkSession();
|
Chris@76
|
359
|
Chris@76
|
360 saveDBSettings($config_vars);
|
Chris@76
|
361 redirectexit('action=admin;area=postsettings;sa=topics');
|
Chris@76
|
362 }
|
Chris@76
|
363
|
Chris@76
|
364 // Final settings...
|
Chris@76
|
365 $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=topics';
|
Chris@76
|
366 $context['settings_title'] = $txt['manageposts_topic_settings'];
|
Chris@76
|
367
|
Chris@76
|
368 // Prepare the settings...
|
Chris@76
|
369 prepareDBSettingContext($config_vars);
|
Chris@76
|
370 }
|
Chris@76
|
371
|
Chris@76
|
372 ?> |