PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/php/Sources/ManagePosts.php

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