ManagePosts.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 2014 Simple Machines and individual contributors
  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('No direct access...');
  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. loadLanguage('Drafts');
  30. $subActions = array(
  31. 'posts' => 'ModifyPostSettings',
  32. 'bbc' => 'ModifyBBCSettings',
  33. 'censor' => 'SetCensor',
  34. 'topics' => 'ModifyTopicSettings',
  35. 'drafts' => 'ModifyDraftSettings',
  36. );
  37. call_integration_hook('integrate_manage_posts', array(&$subActions));
  38. // Default the sub-action to 'posts'.
  39. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'posts';
  40. $context['page_title'] = $txt['manageposts_title'];
  41. // Tabs for browsing the different post functions.
  42. $context[$context['admin_menu_name']]['tab_data'] = array(
  43. 'title' => $txt['manageposts_title'],
  44. 'help' => 'posts_and_topics',
  45. 'description' => $txt['manageposts_description'],
  46. 'tabs' => array(
  47. 'posts' => array(
  48. 'description' => $txt['manageposts_settings_description'],
  49. ),
  50. 'bbc' => array(
  51. 'description' => $txt['manageposts_bbc_settings_description'],
  52. ),
  53. 'censor' => array(
  54. 'description' => $txt['admin_censored_desc'],
  55. ),
  56. 'topics' => array(
  57. 'description' => $txt['manageposts_topic_settings_description'],
  58. ),
  59. 'drafts' => array(
  60. 'description' => $txt['drafts_show_desc'],
  61. ),
  62. ),
  63. );
  64. // Call the right function for this sub-action.
  65. $subActions[$_REQUEST['sa']]();
  66. }
  67. /**
  68. * Shows an interface to set and test censored words.
  69. * It uses the censor_vulgar, censor_proper, censorWholeWord, and censorIgnoreCase
  70. * settings.
  71. * Requires the admin_forum permission.
  72. * Accessed from ?action=admin;area=postsettings;sa=censor.
  73. *
  74. * @uses the Admin template and the edit_censored sub template.
  75. */
  76. function SetCensor()
  77. {
  78. global $txt, $modSettings, $context, $smcFunc, $sourcedir;
  79. if (!empty($_POST['save_censor']))
  80. {
  81. // Make sure censoring is something they can do.
  82. checkSession();
  83. validateToken('admin-censor');
  84. $censored_vulgar = array();
  85. $censored_proper = array();
  86. // Rip it apart, then split it into two arrays.
  87. if (isset($_POST['censortext']))
  88. {
  89. $_POST['censortext'] = explode("\n", strtr($_POST['censortext'], array("\r" => '')));
  90. foreach ($_POST['censortext'] as $c)
  91. list ($censored_vulgar[], $censored_proper[]) = array_pad(explode('=', trim($c)), 2, '');
  92. }
  93. elseif (isset($_POST['censor_vulgar'], $_POST['censor_proper']))
  94. {
  95. if (is_array($_POST['censor_vulgar']))
  96. {
  97. foreach ($_POST['censor_vulgar'] as $i => $value)
  98. {
  99. if (trim(strtr($value, '*', ' ')) == '')
  100. unset($_POST['censor_vulgar'][$i], $_POST['censor_proper'][$i]);
  101. }
  102. $censored_vulgar = $_POST['censor_vulgar'];
  103. $censored_proper = $_POST['censor_proper'];
  104. }
  105. else
  106. {
  107. $censored_vulgar = explode("\n", strtr($_POST['censor_vulgar'], array("\r" => '')));
  108. $censored_proper = explode("\n", strtr($_POST['censor_proper'], array("\r" => '')));
  109. }
  110. }
  111. // Set the new arrays and settings in the database.
  112. $updates = array(
  113. 'censor_vulgar' => implode("\n", $censored_vulgar),
  114. 'censor_proper' => implode("\n", $censored_proper),
  115. 'allow_no_censored' => empty($_POST['allow_no_censored']) ? '0' : '1',
  116. 'censorWholeWord' => empty($_POST['censorWholeWord']) ? '0' : '1',
  117. 'censorIgnoreCase' => empty($_POST['censorIgnoreCase']) ? '0' : '1',
  118. );
  119. call_integration_hook('integrate_save_censors', array(&$updates));
  120. $context['saved_successful'] = true;
  121. updateSettings($updates);
  122. }
  123. if (isset($_POST['censortest']))
  124. {
  125. require_once($sourcedir . '/Subs-Post.php');
  126. $censorText = $smcFunc['htmlspecialchars']($_POST['censortest'], ENT_QUOTES);
  127. preparsecode($censorText);
  128. $context['censor_test'] = strtr(censorText($censorText), array('"' => '&quot;'));
  129. }
  130. // Set everything up for the template to do its thang.
  131. $censor_vulgar = explode("\n", $modSettings['censor_vulgar']);
  132. $censor_proper = explode("\n", $modSettings['censor_proper']);
  133. $context['censored_words'] = array();
  134. for ($i = 0, $n = count($censor_vulgar); $i < $n; $i++)
  135. {
  136. if (empty($censor_vulgar[$i]))
  137. continue;
  138. // Skip it, it's either spaces or stars only.
  139. if (trim(strtr($censor_vulgar[$i], '*', ' ')) == '')
  140. continue;
  141. $context['censored_words'][$smcFunc['htmlspecialchars'](trim($censor_vulgar[$i]))] = isset($censor_proper[$i]) ? $smcFunc['htmlspecialchars']($censor_proper[$i]) : '';
  142. }
  143. call_integration_hook('integrate_censors');
  144. // Since the "Allow users to disable the word censor" stuff was moved from a theme setting to a global one, we need this...
  145. loadLanguage('Themes');
  146. $context['sub_template'] = 'edit_censored';
  147. $context['page_title'] = $txt['admin_censored_words'];
  148. createToken('admin-censor');
  149. }
  150. /**
  151. * Modify any setting related to posts and posting.
  152. * Requires the admin_forum permission.
  153. * Accessed from ?action=admin;area=postsettings;sa=posts.
  154. *
  155. * @param bool $return_config = false
  156. * @uses Admin template, edit_post_settings sub-template.
  157. */
  158. function ModifyPostSettings($return_config = false)
  159. {
  160. global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $db_type;
  161. // Make an inline conditional a little shorter...
  162. $can_spell_check = false;
  163. if (function_exists('pspell_new'))
  164. $can_spell_check = true;
  165. elseif (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))
  166. $can_spell_check = true;
  167. // All the settings...
  168. $config_vars = array(
  169. // Simple post options...
  170. array('check', 'removeNestedQuotes'),
  171. array('check', 'enableEmbeddedFlash', 'subtext' => $txt['enableEmbeddedFlash_warning']),
  172. // Note show the warning as red if: pspell not installed and (enchant not installed or not using UTF-8 and iconv not installed)
  173. array('check', 'enableSpellChecking', 'subtext' => ($can_spell_check ? $txt['enableSpellChecking_warning'] : ('<span class="alert">' . $txt['enableSpellChecking_warning'] . '</span>'))),
  174. array('check', 'disable_wysiwyg'),
  175. '',
  176. // Posting limits...
  177. array('int', 'max_messageLength', 'subtext' => $txt['max_messageLength_zero'], 'postinput' => $txt['manageposts_characters']),
  178. array('int', 'topicSummaryPosts', 'postinput' => $txt['manageposts_posts']),
  179. '',
  180. // Posting time limits...
  181. array('int', 'spamWaitTime', 'postinput' => $txt['manageposts_seconds']),
  182. array('int', 'edit_wait_time', 'postinput' => $txt['manageposts_seconds']),
  183. array('int', 'edit_disable_time', 'subtext' => $txt['edit_disable_time_zero'], 'postinput' => $txt['manageposts_minutes']),
  184. '',
  185. // Automagic image resizing.
  186. array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  187. array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  188. '',
  189. // First & Last message preview lengths
  190. array('int', 'preview_characters', 'subtext' => $txt['preview_characters_zero'], 'postinput' => $txt['preview_characters_units']),
  191. );
  192. call_integration_hook('integrate_modify_post_settings', array(&$config_vars));
  193. if ($return_config)
  194. return $config_vars;
  195. // We'll want this for our easy save.
  196. require_once($sourcedir . '/ManageServer.php');
  197. // Setup the template.
  198. $context['page_title'] = $txt['manageposts_settings'];
  199. $context['sub_template'] = 'show_settings';
  200. // Are we saving them - are we??
  201. if (isset($_GET['save']))
  202. {
  203. checkSession();
  204. // If we're changing the message length (and we are using MySQL) let's check the column is big enough.
  205. if (isset($_POST['max_messageLength']) && $_POST['max_messageLength'] != $modSettings['max_messageLength'] && ($db_type == 'mysql' || $db_type == 'mysqli'))
  206. {
  207. db_extend('packages');
  208. $colData = $smcFunc['db_list_columns']('{db_prefix}messages', true);
  209. foreach ($colData as $column)
  210. if ($column['name'] == 'body')
  211. $body_type = $column['type'];
  212. if (isset($body_type) && ($_POST['max_messageLength'] > 65535 || $_POST['max_messageLength'] == 0) && $body_type == 'text')
  213. fatal_lang_error('convert_to_mediumtext', false, array($scripturl . '?action=admin;area=maintain;sa=database'));
  214. }
  215. // If we're changing the post preview length let's check its valid
  216. if (!empty($_POST['preview_characters']))
  217. $_POST['preview_characters'] = (int) min(max(0, $_POST['preview_characters']), 512);
  218. call_integration_hook('integrate_save_post_settings');
  219. saveDBSettings($config_vars);
  220. $_SESSION['adm-save'] = true;
  221. redirectexit('action=admin;area=postsettings;sa=posts');
  222. }
  223. // Final settings...
  224. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=posts';
  225. $context['settings_title'] = $txt['manageposts_settings'];
  226. // Prepare the settings...
  227. prepareDBSettingContext($config_vars);
  228. }
  229. /**
  230. * Set a few Bulletin Board Code settings. It loads a list of Bulletin Board Code tags to allow disabling tags.
  231. * Requires the admin_forum permission.
  232. * Accessed from ?action=admin;area=postsettings;sa=bbc.
  233. *
  234. * @param bool $return_config = false
  235. * @uses Admin template, edit_bbc_settings sub-template.
  236. */
  237. function ModifyBBCSettings($return_config = false)
  238. {
  239. global $context, $txt, $modSettings, $helptxt, $scripturl, $sourcedir;
  240. $config_vars = array(
  241. // Main tweaks
  242. array('check', 'enableBBC'),
  243. array('check', 'enableBBC', 0, 'onchange' => 'toggleBBCDisabled(\'disabledBBC\', !this.checked);'),
  244. array('check', 'enablePostHTML'),
  245. array('check', 'autoLinkUrls'),
  246. '',
  247. array('bbc', 'disabledBBC'),
  248. );
  249. $context['settings_post_javascript'] = '
  250. toggleBBCDisabled(\'disabledBBC\', ' . (empty($modSettings['enableBBC']) ? 'true' : 'false') . ');';
  251. call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars));
  252. if ($return_config)
  253. return $config_vars;
  254. // Setup the template.
  255. require_once($sourcedir . '/ManageServer.php');
  256. $context['sub_template'] = 'show_settings';
  257. $context['page_title'] = $txt['manageposts_bbc_settings_title'];
  258. // Make sure we check the right tags!
  259. $modSettings['bbc_disabled_disabledBBC'] = empty($modSettings['disabledBBC']) ? array() : explode(',', $modSettings['disabledBBC']);
  260. // Saving?
  261. if (isset($_GET['save']))
  262. {
  263. checkSession();
  264. // Clean up the tags.
  265. $bbcTags = array();
  266. foreach (parse_bbc(false) as $tag)
  267. $bbcTags[] = $tag['tag'];
  268. if (!isset($_POST['disabledBBC_enabledTags']))
  269. $_POST['disabledBBC_enabledTags'] = array();
  270. elseif (!is_array($_POST['disabledBBC_enabledTags']))
  271. $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']);
  272. // Work out what is actually disabled!
  273. $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags']));
  274. call_integration_hook('integrate_save_bbc_settings', array($bbcTags));
  275. saveDBSettings($config_vars);
  276. $_SESSION['adm-save'] = true;
  277. redirectexit('action=admin;area=postsettings;sa=bbc');
  278. }
  279. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=bbc';
  280. $context['settings_title'] = $txt['manageposts_bbc_settings_title'];
  281. prepareDBSettingContext($config_vars);
  282. }
  283. /**
  284. * Modify any setting related to topics.
  285. * Requires the admin_forum permission.
  286. * Accessed from ?action=admin;area=postsettings;sa=topics.
  287. * @param bool $return_config = false
  288. * @uses Admin template, edit_topic_settings sub-template.
  289. */
  290. function ModifyTopicSettings($return_config = false)
  291. {
  292. global $context, $txt, $sourcedir, $scripturl;
  293. // Here are all the topic settings.
  294. $config_vars = array(
  295. // Some simple bools...
  296. array('check', 'enableParticipation'),
  297. '',
  298. // Pagination etc...
  299. array('int', 'oldTopicDays', 'postinput' => $txt['manageposts_days'], 'subtext' => $txt['oldTopicDays_zero']),
  300. array('int', 'defaultMaxTopics', 'postinput' => $txt['manageposts_topics']),
  301. array('int', 'defaultMaxMessages', 'postinput' => $txt['manageposts_posts']),
  302. array('check', 'disable_print_topic'),
  303. '',
  304. // Hot topics (etc)...
  305. array('int', 'hotTopicPosts', 'postinput' => $txt['manageposts_posts']),
  306. array('int', 'hotTopicVeryPosts', 'postinput' => $txt['manageposts_posts']),
  307. '',
  308. // All, next/prev...
  309. array('int', 'enableAllMessages', 'postinput' => $txt['manageposts_posts'], 'subtext' => $txt['enableAllMessages_zero']),
  310. array('check', 'disableCustomPerPage'),
  311. array('check', 'enablePreviousNext'),
  312. );
  313. call_integration_hook('integrate_modify_topic_settings', array(&$config_vars));
  314. if ($return_config)
  315. return $config_vars;
  316. // Get the settings template ready.
  317. require_once($sourcedir . '/ManageServer.php');
  318. // Setup the template.
  319. $context['page_title'] = $txt['manageposts_topic_settings'];
  320. $context['sub_template'] = 'show_settings';
  321. // Are we saving them - are we??
  322. if (isset($_GET['save']))
  323. {
  324. checkSession();
  325. call_integration_hook('integrate_save_topic_settings');
  326. saveDBSettings($config_vars);
  327. $_SESSION['adm-save'] = true;
  328. redirectexit('action=admin;area=postsettings;sa=topics');
  329. }
  330. // Final settings...
  331. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;save;sa=topics';
  332. $context['settings_title'] = $txt['manageposts_topic_settings'];
  333. // Prepare the settings...
  334. prepareDBSettingContext($config_vars);
  335. }
  336. /**
  337. * Modify any setting related to drafts.
  338. * Requires the admin_forum permission.
  339. * Accessed from ?action=admin;area=postsettings;sa=drafts
  340. *
  341. * @param bool $return_config = false
  342. * @uses Admin template, edit_topic_settings sub-template.
  343. */
  344. function ModifyDraftSettings($return_config = false)
  345. {
  346. global $context, $txt, $sourcedir, $scripturl, $smcFunc;
  347. // Here are all the draft settings, a bit lite for now, but we can add more :P
  348. $config_vars = array(
  349. // Draft settings ...
  350. array('check', 'drafts_post_enabled'),
  351. array('check', 'drafts_pm_enabled'),
  352. array('check', 'drafts_show_saved_enabled', 'subtext' => $txt['drafts_show_saved_enabled_subnote']),
  353. array('int', 'drafts_keep_days', 'postinput' => $txt['days_word'], 'subtext' => $txt['drafts_keep_days_subnote']),
  354. '',
  355. array('check', 'drafts_autosave_enabled', 'subtext' => $txt['drafts_autosave_enabled_subnote']),
  356. array('int', 'drafts_autosave_frequency', 'postinput' => $txt['manageposts_seconds'], 'subtext' => $txt['drafts_autosave_frequency_subnote']),
  357. );
  358. if ($return_config)
  359. return $config_vars;
  360. // Get the settings template ready.
  361. require_once($sourcedir . '/ManageServer.php');
  362. // Setup the template.
  363. $context['page_title'] = $txt['managedrafts_settings'];
  364. $context['sub_template'] = 'show_settings';
  365. // Saving them ?
  366. if (isset($_GET['save']))
  367. {
  368. checkSession();
  369. // Protect them from themselves.
  370. $_POST['drafts_autosave_frequency'] = !isset($_POST['drafts_autosave_frequency']) || $_POST['drafts_autosave_frequency'] < 30 ? 30 : $_POST['drafts_autosave_frequency'];
  371. // Also disable the scheduled task if we're not using it.
  372. $smcFunc['db_query']('', '
  373. UPDATE {db_prefix}scheduled_tasks
  374. SET disabled = {int:disabled}
  375. WHERE task = {string:task}',
  376. array(
  377. 'disabled' => !empty($_POST['drafts_keep_days']) ? 0 : 1,
  378. 'task' => 'remove_old_drafts',
  379. )
  380. );
  381. require_once($sourcedir . '/ScheduledTasks.php');
  382. CalculateNextTrigger();
  383. // Save everything else and leave.
  384. saveDBSettings($config_vars);
  385. $_SESSION['adm-save'] = true;
  386. redirectexit('action=admin;area=postsettings;sa=drafts');
  387. }
  388. // some javascript to enable / disable the frequency input box
  389. $context['settings_post_javascript'] = '
  390. function toggle()
  391. {
  392. $("#drafts_autosave_frequency").prop("disabled", !($("#drafts_autosave_enabled").prop("checked")));
  393. };
  394. toggle();
  395. $("#drafts_autosave_enabled").click(function() { toggle(); });
  396. ';
  397. // Final settings...
  398. $context['post_url'] = $scripturl . '?action=admin;area=postsettings;sa=drafts;save';
  399. $context['settings_title'] = $txt['managedrafts_settings'];
  400. // Prepare the settings...
  401. prepareDBSettingContext($config_vars);
  402. }
  403. ?>