ManagePosts.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /**
  3. * This file contains all the screens that control 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. // !!! Show an error message?!
  191. // MySQL only likes fulltext indexes on text columns... for now?
  192. if (!empty($fulltext))
  193. $_POST['max_messageLength'] = 65535;
  194. else
  195. {
  196. // Make it longer so we can do their limit.
  197. $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'mediumtext'));
  198. }
  199. }
  200. elseif (isset($body_type) && $_POST['max_messageLength'] <= 65535 && $body_type != 'text')
  201. {
  202. // Shorten the column so we can have the benefit of fulltext searching again!
  203. $smcFunc['db_change_column']('{db_prefix}messages', 'body', array('type' => 'text'));
  204. }
  205. }
  206. saveDBSettings($config_vars);
  207. redirectexit('action=admin;area=postsettings;sa=posts');
  208. }
  209. // Final settings...
  210. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=posts';
  211. $context['settings_title'] = $txt['manageposts_settings'];
  212. // Prepare the settings...
  213. prepareDBSettingContext($config_vars);
  214. }
  215. /**
  216. * Set a few Bulletin Board Code settings. It loads a list of Bulletin Board Code tags to allow disabling tags.
  217. * Requires the admin_forum permission.
  218. * Accessed from ?action=admin;area=postsettings;sa=bbc.
  219. *
  220. * @param bool $return_config = false
  221. * @uses Admin template, edit_bbc_settings sub-template.
  222. */
  223. function ModifyBBCSettings($return_config = false)
  224. {
  225. global $context, $txt, $modSettings, $helptxt, $scripturl, $sourcedir;
  226. $config_vars = array(
  227. // Main tweaks
  228. array('check', 'enableBBC'),
  229. array('check', 'enablePostHTML'),
  230. array('check', 'autoLinkUrls'),
  231. '',
  232. array('bbc', 'disabledBBC'),
  233. );
  234. if ($return_config)
  235. return $config_vars;
  236. // Setup the template.
  237. require_once($sourcedir . '/ManageServer.php');
  238. $context['sub_template'] = 'show_settings';
  239. $context['page_title'] = $txt['manageposts_bbc_settings_title'];
  240. // Make sure we check the right tags!
  241. $modSettings['bbc_disabled_disabledBBC'] = empty($modSettings['disabledBBC']) ? array() : explode(',', $modSettings['disabledBBC']);
  242. // Saving?
  243. if (isset($_GET['save']))
  244. {
  245. checkSession();
  246. // Clean up the tags.
  247. $bbcTags = array();
  248. foreach (parse_bbc(false) as $tag)
  249. $bbcTags[] = $tag['tag'];
  250. if (!isset($_POST['disabledBBC_enabledTags']))
  251. $_POST['disabledBBC_enabledTags'] = array();
  252. elseif (!is_array($_POST['disabledBBC_enabledTags']))
  253. $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
  254. // Work out what is actually disabled!
  255. $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
  256. saveDBSettings($config_vars);
  257. redirectexit('action=admin;area=postsettings;sa=bbc');
  258. }
  259. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=bbc';
  260. $context['settings_title'] = $txt['manageposts_bbc_settings_title'];
  261. prepareDBSettingContext($config_vars);
  262. }
  263. /**
  264. * Modify any setting related to topics.
  265. * Requires the admin_forum permission.
  266. * Accessed from ?action=admin;area=postsettings;sa=topics.
  267. * @param $return_config
  268. * @uses Admin template, edit_topic_settings sub-template.
  269. */
  270. function ModifyTopicSettings($return_config = false)
  271. {
  272. global $context, $txt, $modSettings, $sourcedir, $scripturl;
  273. // Here are all the topic settings.
  274. $config_vars = array(
  275. // Some simple bools...
  276. array('check', 'enableStickyTopics'),
  277. array('check', 'enableParticipation'),
  278. '',
  279. // Pagination etc...
  280. array('int', 'oldTopicDays', 'postinput' => $txt['manageposts_days'], 'subtext' => $txt['oldTopicDays_zero']),
  281. array('int', 'defaultMaxTopics', 'postinput' => $txt['manageposts_topics']),
  282. array('int', 'defaultMaxMessages', 'postinput' => $txt['manageposts_posts']),
  283. '',
  284. // Hot topics (etc)...
  285. array('int', 'hotTopicPosts', 'postinput' => $txt['manageposts_posts']),
  286. array('int', 'hotTopicVeryPosts', 'postinput' => $txt['manageposts_posts']),
  287. '',
  288. // All, next/prev...
  289. array('int', 'enableAllMessages', 'postinput' => $txt['manageposts_posts'], 'subtext' => $txt['enableAllMessages_zero']),
  290. array('check', 'disableCustomPerPage'),
  291. array('check', 'enablePreviousNext'),
  292. );
  293. if ($return_config)
  294. return $config_vars;
  295. // Get the settings template ready.
  296. require_once($sourcedir . '/ManageServer.php');
  297. // Setup the template.
  298. $context['page_title'] = $txt['manageposts_topic_settings'];
  299. $context['sub_template'] = 'show_settings';
  300. // Are we saving them - are we??
  301. if (isset($_GET['save']))
  302. {
  303. checkSession();
  304. saveDBSettings($config_vars);
  305. redirectexit('action=admin;area=postsettings;sa=topics');
  306. }
  307. // Final settings...
  308. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=topics';
  309. $context['settings_title'] = $txt['manageposts_topic_settings'];
  310. // Prepare the settings...
  311. prepareDBSettingContext($config_vars);
  312. }
  313. ?>