ManagePosts.php 12 KB

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