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

/forum/Sources/ManagePosts.php

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