ManagePosts.php 13 KB

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