PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/sources/admin/ManagePosts.php

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