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