PageRenderTime 58ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/admin/ManageSettings.php

https://github.com/Arantor/Elkarte
PHP | 2770 lines | 2082 code | 325 blank | 363 comment | 301 complexity | 92f855fda189f2efc4a92c5b20bc0728 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  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 is here to make it easier for installed mods to have
  16. * settings and options.
  17. *
  18. */
  19. if (!defined('ELKARTE'))
  20. die('No access...');
  21. /**
  22. * This just avoids some repetition.
  23. *
  24. * @param array $subActions = array()
  25. * @param string $defaultAction = ''
  26. */
  27. function loadGeneralSettingParameters($subActions = array(), $defaultAction = '')
  28. {
  29. global $context, $txt;
  30. // You need to be an admin to edit settings!
  31. isAllowedTo('admin_forum');
  32. loadLanguage('Help');
  33. loadLanguage('ManageSettings');
  34. // Will need the utility functions from here.
  35. require_once(ADMINDIR . '/ManageServer.php');
  36. $context['sub_template'] = 'show_settings';
  37. // By default do the basic settings.
  38. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (!empty($defaultAction) ? $defaultAction : array_pop($temp = array_keys($subActions)));
  39. $context['sub_action'] = $_REQUEST['sa'];
  40. }
  41. /**
  42. * This function passes control through to the relevant tab.
  43. */
  44. function ModifyFeatureSettings()
  45. {
  46. global $context, $txt, $scripturl, $modSettings, $settings;
  47. $context['page_title'] = $txt['modSettings_title'];
  48. $subActions = array(
  49. 'basic' => 'ModifyBasicSettings',
  50. 'layout' => 'ModifyLayoutSettings',
  51. 'karma' => 'ModifyKarmaSettings',
  52. 'sig' => 'ModifySignatureSettings',
  53. 'profile' => 'ShowCustomProfiles',
  54. 'profileedit' => 'EditCustomProfiles',
  55. );
  56. call_integration_hook('integrate_modify_features', array($subActions));
  57. // If Advanced Profile Fields are disabled don't show the setting page
  58. if (!in_array('cp', $context['admin_features']))
  59. unset($subActions['profile']);
  60. // Same for Karma
  61. if (!in_array('k', $context['admin_features']))
  62. unset($subActions['karma']);
  63. loadGeneralSettingParameters($subActions, 'basic');
  64. // Load up all the tabs...
  65. $context[$context['admin_menu_name']]['tab_data'] = array(
  66. 'title' => $txt['modSettings_title'],
  67. 'help' => 'featuresettings',
  68. 'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']),
  69. 'tabs' => array(
  70. 'basic' => array(
  71. ),
  72. 'layout' => array(
  73. ),
  74. 'karma' => array(
  75. ),
  76. 'sig' => array(
  77. 'description' => $txt['signature_settings_desc'],
  78. ),
  79. 'profile' => array(
  80. 'description' => $txt['custom_profile_desc'],
  81. ),
  82. ),
  83. );
  84. // Call the right function for this sub-acton.
  85. $subActions[$_REQUEST['sa']]();
  86. }
  87. /**
  88. * This function passes control through to the relevant security tab.
  89. */
  90. function ModifySecuritySettings()
  91. {
  92. global $context, $txt, $scripturl, $modSettings, $settings;
  93. $context['page_title'] = $txt['admin_security_moderation'];
  94. $subActions = array(
  95. 'general' => 'ModifyGeneralSecuritySettings',
  96. 'spam' => 'ModifySpamSettings',
  97. 'badbehavior' => 'ModifyBadBehaviorSettings',
  98. 'moderation' => 'ModifyModerationSettings',
  99. );
  100. call_integration_hook('integrate_modify_security', array($subActions));
  101. // If Warning System is disabled don't show the setting page
  102. if (!in_array('w', $context['admin_features']))
  103. unset($subActions['moderation']);
  104. loadGeneralSettingParameters($subActions, 'general');
  105. // Load up all the tabs...
  106. $context[$context['admin_menu_name']]['tab_data'] = array(
  107. 'title' => $txt['admin_security_moderation'],
  108. 'help' => 'securitysettings',
  109. 'description' => $txt['security_settings_desc'],
  110. 'tabs' => array(
  111. 'general' => array(
  112. ),
  113. 'spam' => array(
  114. 'description' => $txt['antispam_Settings_desc'] ,
  115. ),
  116. 'badbehavior' => array(
  117. 'description' => $txt['badbehavior_desc'] ,
  118. ),
  119. 'moderation' => array(
  120. ),
  121. ),
  122. );
  123. // Call the right function for this sub-acton.
  124. $subActions[$_REQUEST['sa']]();
  125. }
  126. /**
  127. * This my friend, is for all the mod authors out there.
  128. */
  129. function ModifyModSettings()
  130. {
  131. global $context, $txt, $scripturl, $modSettings, $settings;
  132. $context['page_title'] = $txt['admin_modifications'];
  133. $subActions = array(
  134. 'general' => 'ModifyGeneralModSettings',
  135. 'hooks' => 'list_integration_hooks',
  136. // Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.
  137. );
  138. // Make it easier for mods to add new areas.
  139. call_integration_hook('integrate_modify_modifications', array(&$subActions));
  140. loadGeneralSettingParameters($subActions, 'general');
  141. // Load up all the tabs...
  142. $context[$context['admin_menu_name']]['tab_data'] = array(
  143. 'title' => $txt['admin_modifications'],
  144. 'help' => 'modsettings',
  145. 'description' => $txt['modification_settings_desc'],
  146. 'tabs' => array(
  147. 'general' => array(
  148. ),
  149. 'hooks' => array(
  150. ),
  151. ),
  152. );
  153. // Call the right function for this sub-acton.
  154. $subActions[$_REQUEST['sa']]();
  155. }
  156. /**
  157. * This is an overall control panel enabling/disabling lots of the forums key features.
  158. *
  159. * @param $return_config
  160. */
  161. function ModifyCoreFeatures($return_config = false)
  162. {
  163. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  164. /* This is an array of all the features that can be enabled/disabled - each option can have the following:
  165. title - Text title of this item (If standard string does not exist).
  166. desc - Description of this feature (If standard string does not exist).
  167. settings - Array of settings to change (For each name => value) on enable - reverse is done for disable. If > 1 will not change value if set.
  168. setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature.
  169. save_callback - Function called on save, takes state as parameter.
  170. */
  171. $core_features = array(
  172. // cd = calendar.
  173. 'cd' => array(
  174. 'url' => 'action=admin;area=managecalendar',
  175. 'settings' => array(
  176. 'cal_enabled' => 1,
  177. ),
  178. ),
  179. // cp = custom profile fields.
  180. 'cp' => array(
  181. 'url' => 'action=admin;area=featuresettings;sa=profile',
  182. 'save_callback' => create_function('$value', '
  183. global $smcFunc;
  184. if (!$value)
  185. {
  186. $smcFunc[\'db_query\'](\'\', \'
  187. UPDATE {db_prefix}custom_fields
  188. SET active = 0\');
  189. }
  190. '),
  191. 'setting_callback' => create_function('$value', '
  192. if (!$value)
  193. return array(
  194. \'disabled_profile_fields\' => \'\',
  195. \'registration_fields\' => \'\',
  196. \'displayFields\' => \'\',
  197. );
  198. else
  199. return array();
  200. '),
  201. ),
  202. // dr = drafts
  203. 'dr' => array(
  204. 'url' => 'action=admin;area=managedrafts',
  205. 'settings' => array(
  206. 'drafts_enabled' => 1,
  207. 'drafts_post_enabled' => 2,
  208. 'drafts_pm_enabled' => 2,
  209. 'drafts_autosave_enabled' => 2,
  210. 'drafts_show_saved_enabled' => 2,
  211. ),
  212. 'setting_callback' => create_function('$value', '
  213. global $smcFunc;
  214. // Set the correct disabled value for the scheduled task.
  215. $smcFunc[\'db_query\'](\'\', \'
  216. UPDATE {db_prefix}scheduled_tasks
  217. SET disabled = {int:disabled}
  218. WHERE task = {string:task}\',
  219. array(
  220. \'disabled\' => $value ? 0 : 1,
  221. \'task\' => \'remove_old_drafts\',
  222. )
  223. );
  224. '),
  225. ),
  226. // ih = Integration Hooks Handling.
  227. 'ih' => array(
  228. 'url' => 'action=admin;area=modsettings;sa=hooks',
  229. 'settings' => array(
  230. 'handlinghooks_enabled' => 1,
  231. ),
  232. ),
  233. // k = karma.
  234. 'k' => array(
  235. 'url' => 'action=admin;area=featuresettings;sa=karma',
  236. 'settings' => array(
  237. 'karmaMode' => 2,
  238. ),
  239. ),
  240. // ml = moderation log.
  241. 'ml' => array(
  242. 'url' => 'action=admin;area=logs;sa=modlog',
  243. 'settings' => array(
  244. 'modlog_enabled' => 1,
  245. ),
  246. ),
  247. // pm = post moderation.
  248. 'pm' => array(
  249. 'url' => 'action=admin;area=permissions;sa=postmod',
  250. 'setting_callback' => create_function('$value', '
  251. // Cant use warning post moderation if disabled!
  252. if (!$value)
  253. {
  254. require_once(CONTROLLERDIR . \'/PostModeration.controller.php\');
  255. approveAllData();
  256. return array(\'warning_moderate\' => 0);
  257. }
  258. else
  259. return array();
  260. '),
  261. ),
  262. // ps = Paid Subscriptions.
  263. 'ps' => array(
  264. 'url' => 'action=admin;area=paidsubscribe',
  265. 'settings' => array(
  266. 'paid_enabled' => 1,
  267. ),
  268. 'setting_callback' => create_function('$value', '
  269. global $smcFunc;
  270. // Set the correct disabled value for scheduled task.
  271. $smcFunc[\'db_query\'](\'\', \'
  272. UPDATE {db_prefix}scheduled_tasks
  273. SET disabled = {int:disabled}
  274. WHERE task = {string:task}\',
  275. array(
  276. \'disabled\' => $value ? 0 : 1,
  277. \'task\' => \'paid_subscriptions\',
  278. )
  279. );
  280. // Should we calculate next trigger?
  281. if ($value)
  282. {
  283. require_once(SOURCEDIR . \'/ScheduledTasks.php\');
  284. CalculateNextTrigger(\'paid_subscriptions\');
  285. }
  286. '),
  287. ),
  288. // rg = report generator.
  289. 'rg' => array(
  290. 'url' => 'action=admin;area=reports',
  291. ),
  292. // w = warning.
  293. 'w' => array(
  294. 'url' => 'action=admin;area=securitysettings;sa=moderation',
  295. 'setting_callback' => create_function('$value', '
  296. global $modSettings;
  297. list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']);
  298. $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\'];
  299. if (!$value)
  300. {
  301. $returnSettings = array(
  302. \'warning_watch\' => 0,
  303. \'warning_moderate\' => 0,
  304. \'warning_mute\' => 0,
  305. );
  306. }
  307. elseif (empty($modSettings[\'warning_enable\']) && $value)
  308. {
  309. $returnSettings = array(
  310. \'warning_watch\' => 10,
  311. \'warning_moderate\' => 35,
  312. \'warning_mute\' => 60,
  313. );
  314. }
  315. else
  316. $returnSettings = array();
  317. $returnSettings[\'warning_settings\'] = $warning_settings;
  318. return $returnSettings;
  319. '),
  320. ),
  321. // Search engines
  322. 'sp' => array(
  323. 'url' => 'action=admin;area=sengines',
  324. 'settings' => array(
  325. 'spider_mode' => 1,
  326. ),
  327. 'setting_callback' => create_function('$value', '
  328. // Turn off the spider group if disabling.
  329. if (!$value)
  330. return array(\'spider_group\' => 0, \'show_spider_online\' => 0);
  331. '),
  332. 'on_save' => create_function('', '
  333. global $modSettings;
  334. require_once(SUBSDIR . \'/SearchEngines.subs.php\');
  335. '),
  336. ),
  337. );
  338. // Anyone who would like to add a core feature?
  339. call_integration_hook('integrate_core_features', array(&$core_features));
  340. // Are we getting info for the help section.
  341. if ($return_config)
  342. {
  343. $return_data = array();
  344. foreach ($core_features as $id => $data)
  345. $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]);
  346. return $return_data;
  347. }
  348. loadGeneralSettingParameters();
  349. // Are we saving?
  350. if (isset($_POST['save']))
  351. {
  352. checkSession();
  353. if (isset($_GET['xml']))
  354. {
  355. $tokenValidation = validateToken('admin-core', 'post', false);
  356. if (empty($tokenValidation))
  357. return 'token_verify_fail';
  358. }
  359. else
  360. validateToken('admin-core');
  361. $setting_changes = array('admin_features' => array());
  362. // Cycle each feature and change things as required!
  363. foreach ($core_features as $id => $feature)
  364. {
  365. // Enabled?
  366. if (!empty($_POST['feature_' . $id]))
  367. $setting_changes['admin_features'][] = $id;
  368. // Setting values to change?
  369. if (isset($feature['settings']))
  370. {
  371. foreach ($feature['settings'] as $key => $value)
  372. {
  373. if (empty($_POST['feature_' . $id]) || (!empty($_POST['feature_' . $id]) && ($value < 2 || empty($modSettings[$key]))))
  374. $setting_changes[$key] = !empty($_POST['feature_' . $id]) ? $value : !$value;
  375. }
  376. }
  377. // Is there a call back for settings?
  378. if (isset($feature['setting_callback']))
  379. {
  380. $returned_settings = $feature['setting_callback'](!empty($_POST['feature_' . $id]));
  381. if (!empty($returned_settings))
  382. $setting_changes = array_merge($setting_changes, $returned_settings);
  383. }
  384. // Standard save callback?
  385. if (isset($feature['on_save']))
  386. $feature['on_save']();
  387. }
  388. // Make sure this one setting is a string!
  389. $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']);
  390. // Make any setting changes!
  391. updateSettings($setting_changes);
  392. // This is needed to let menus appear if cache > 2
  393. if ($modSettings['cache_enable'] > 2)
  394. clean_cache('data');
  395. // Any post save things?
  396. foreach ($core_features as $id => $feature)
  397. {
  398. // Standard save callback?
  399. if (isset($feature['save_callback']))
  400. $feature['save_callback'](!empty($_POST['feature_' . $id]));
  401. }
  402. if (!isset($_REQUEST['xml']))
  403. redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']);
  404. }
  405. // Put them in context.
  406. $context['features'] = array();
  407. foreach ($core_features as $id => $feature)
  408. $context['features'][$id] = array(
  409. 'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id],
  410. 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'],
  411. 'enabled' => in_array($id, $context['admin_features']),
  412. 'state' => in_array($id, $context['admin_features']) ? 'on' : 'off',
  413. 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '',
  414. 'image' => (file_exists($settings['theme_dir'] . '/images/admin/feature_' . $id . '.png') ? $settings['images_url'] : $settings['default_images_url']) . '/admin/feature_' . $id . '.png',
  415. );
  416. // Are they a new user?
  417. $context['is_new_install'] = !isset($modSettings['admin_features']);
  418. $context['force_disable_tabs'] = $context['is_new_install'];
  419. // Don't show them this twice!
  420. if ($context['is_new_install'])
  421. updateSettings(array('admin_features' => ''));
  422. // sub_template is already generic_xml and the token is created somewhere else
  423. if (isset($_REQUEST['xml']))
  424. return;
  425. $context['sub_template'] = 'core_features';
  426. $context['page_title'] = $txt['core_settings_title'];
  427. $context[$context['admin_menu_name']]['tab_data'] = array(
  428. 'title' => $txt['core_settings_title'],
  429. 'help' => '',
  430. 'description' => $txt['core_settings_desc'],
  431. );
  432. // We love our tokens.
  433. createToken('admin-core');
  434. }
  435. /**
  436. * Config array for chaning the basic forum settings
  437. * Accessed from ?action=admin;area=featuresettings;sa=basic;
  438. *
  439. * @param $return_config
  440. */
  441. function ModifyBasicSettings($return_config = false)
  442. {
  443. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  444. $config_vars = array(
  445. // Big Options... polls, sticky, bbc....
  446. array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])),
  447. '',
  448. // Basic stuff, titles, flash, permissions...
  449. array('check', 'allow_guestAccess'),
  450. array('check', 'enable_buddylist'),
  451. array('check', 'enable_disregard'),
  452. array('check', 'allow_editDisplayName'),
  453. array('check', 'allow_hideOnline'),
  454. array('check', 'titlesEnable'),
  455. array('text', 'default_personal_text', 'subtext' => $txt['default_personal_text_note']),
  456. '',
  457. // Javascript and CSS options
  458. array('select', 'jquery_source', array('auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn'])),
  459. array('check', 'minify_css_js'),
  460. '',
  461. // SEO stuff
  462. array('check', 'queryless_urls', 'subtext' => '<strong>' . $txt['queryless_urls_note'] . '</strong>'),
  463. array('text', 'meta_keywords', 'subtext' => $txt['meta_keywords_note'], 'size' => 50),
  464. '',
  465. // Number formatting, timezones.
  466. array('text', 'time_format'),
  467. array('float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']),
  468. 'default_timezone' => array('select', 'default_timezone', array()),
  469. '',
  470. // Who's online?
  471. array('check', 'who_enabled'),
  472. array('int', 'lastActive', 6, 'postinput' => $txt['minutes']),
  473. '',
  474. // Statistics.
  475. array('check', 'trackStats'),
  476. array('check', 'hitStats'),
  477. '',
  478. // Option-ish things... miscellaneous sorta.
  479. array('check', 'allow_disableAnnounce'),
  480. array('check', 'disallow_sendBody'),
  481. array('select', 'enable_contactform', array('disabled' => $txt['contact_form_disabled'], 'registration' => $txt['contact_form_registration'], 'menu' => $txt['contact_form_menu'])),
  482. );
  483. // Get all the time zones.
  484. if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
  485. {
  486. $all_zones = timezone_identifiers_list();
  487. // Make sure we set the value to the same as the printed value.
  488. foreach ($all_zones as $zone)
  489. $config_vars['default_timezone'][2][$zone] = $zone;
  490. }
  491. else
  492. unset($config_vars['default_timezone']);
  493. call_integration_hook('integrate_modify_basic_settings', array($config_vars));
  494. if ($return_config)
  495. return $config_vars;
  496. // Saving?
  497. if (isset($_GET['save']))
  498. {
  499. checkSession();
  500. // Prevent absurd boundaries here - make it a day tops.
  501. if (isset($_POST['lastActive']))
  502. $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440);
  503. call_integration_hook('integrate_save_basic_settings');
  504. saveDBSettings($config_vars);
  505. writeLog();
  506. redirectexit('action=admin;area=featuresettings;sa=basic');
  507. }
  508. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic';
  509. $context['settings_title'] = $txt['mods_cat_features'];
  510. prepareDBSettingContext($config_vars);
  511. }
  512. /**
  513. * Settings really associated with general security aspects.
  514. *
  515. * @param $return_config
  516. */
  517. function ModifyGeneralSecuritySettings($return_config = false)
  518. {
  519. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  520. $config_vars = array(
  521. array('check', 'guest_hideContacts'),
  522. array('check', 'make_email_viewable'),
  523. '',
  524. array('int', 'failed_login_threshold'),
  525. array('int', 'loginHistoryDays'),
  526. '',
  527. array('check', 'enableErrorLogging'),
  528. array('check', 'enableErrorQueryLogging'),
  529. '',
  530. array('check', 'securityDisable'),
  531. array('check', 'securityDisable_moderate'),
  532. '',
  533. // Reactive on email, and approve on delete
  534. array('check', 'send_validation_onChange'),
  535. array('check', 'approveAccountDeletion'),
  536. '',
  537. // Password strength.
  538. array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])),
  539. array('check', 'enable_password_conversion'),
  540. '',
  541. // Reporting of personal messages?
  542. array('check', 'enableReportPM'),
  543. );
  544. call_integration_hook('integrate_general_security_settings', array($config_vars));
  545. if ($return_config)
  546. return $config_vars;
  547. // Saving?
  548. if (isset($_GET['save']))
  549. {
  550. checkSession();
  551. saveDBSettings($config_vars);
  552. call_integration_hook('integrate_save_general_security_settings');
  553. writeLog();
  554. redirectexit('action=admin;area=securitysettings;sa=general');
  555. }
  556. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=general';
  557. $context['settings_title'] = $txt['mods_cat_security_general'];
  558. prepareDBSettingContext($config_vars);
  559. }
  560. /**
  561. * Allows modifying the global layout settings in the forum
  562. * Accessed through ?action=admin;area=featuresettings;sa=layout;
  563. *
  564. * @param $return_config
  565. */
  566. function ModifyLayoutSettings($return_config = false)
  567. {
  568. global $txt, $scripturl, $context, $settings, $sc;
  569. $config_vars = array(
  570. // Pagination stuff.
  571. array('check', 'compactTopicPagesEnable'),
  572. array('int', 'compactTopicPagesContiguous', null, $txt['contiguous_page_display'] . '<div class="smalltext">' . str_replace(' ', '&nbsp;', '"3" ' . $txt['to_display'] . ': <strong>1 ... 4 [5] 6 ... 9</strong>') . '<br />' . str_replace(' ', '&nbsp;', '"5" ' . $txt['to_display'] . ': <strong>1 ... 3 4 [5] 6 7 ... 9</strong>') . '</div>'),
  573. array('int', 'defaultMaxMembers'),
  574. '',
  575. // Stuff that just is everywhere - today, search, online, etc.
  576. array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])),
  577. array('check', 'topbottomEnable'),
  578. array('check', 'onlineEnable'),
  579. array('check', 'enableVBStyleLogin'),
  580. '',
  581. // Automagic image resizing.
  582. array('int', 'max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  583. array('int', 'max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  584. '',
  585. // This is like debugging sorta.
  586. array('check', 'timeLoadPageEnable'),
  587. );
  588. call_integration_hook('integrate_layout_settings', array($config_vars));
  589. if ($return_config)
  590. return $config_vars;
  591. // Saving?
  592. if (isset($_GET['save']))
  593. {
  594. checkSession();
  595. call_integration_hook('integrate_save_layout_settings');
  596. saveDBSettings($config_vars);
  597. writeLog();
  598. redirectexit('action=admin;area=featuresettings;sa=layout');
  599. }
  600. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout';
  601. $context['settings_title'] = $txt['mods_cat_layout'];
  602. prepareDBSettingContext($config_vars);
  603. }
  604. /**
  605. * Config array for chaning the karma settings
  606. * Accessed from ?action=admin;area=featuresettings;sa=karma;
  607. *
  608. * @param $return_config
  609. */
  610. function ModifyKarmaSettings($return_config = false)
  611. {
  612. global $txt, $scripturl, $context, $settings, $sc;
  613. $config_vars = array(
  614. // Karma - On or off?
  615. array('select', 'karmaMode', explode('|', $txt['karma_options'])),
  616. '',
  617. // Who can do it.... and who is restricted by time limits?
  618. array('int', 'karmaMinPosts', 6, 'postinput' => strtolower($txt['posts'])),
  619. array('float', 'karmaWaitTime', 6, 'postinput' => $txt['hours']),
  620. array('check', 'karmaTimeRestrictAdmins'),
  621. '',
  622. // What does it look like? [smite]?
  623. array('text', 'karmaLabel'),
  624. array('text', 'karmaApplaudLabel'),
  625. array('text', 'karmaSmiteLabel'),
  626. );
  627. call_integration_hook('integrate_karma_settings', array($config_vars));
  628. if ($return_config)
  629. return $config_vars;
  630. // Saving?
  631. if (isset($_GET['save']))
  632. {
  633. checkSession();
  634. call_integration_hook('integrate_save_karma_settings');
  635. saveDBSettings($config_vars);
  636. redirectexit('action=admin;area=featuresettings;sa=karma');
  637. }
  638. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma';
  639. $context['settings_title'] = $txt['karma'];
  640. prepareDBSettingContext($config_vars);
  641. }
  642. /**
  643. * Moderation type settings - although there are fewer than we have you believe ;)
  644. *
  645. * @param bool $return_config = false
  646. */
  647. function ModifyModerationSettings($return_config = false)
  648. {
  649. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  650. $config_vars = array(
  651. // Warning system?
  652. array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'], 'help' => 'warning_enable'),
  653. 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note']),
  654. array('int', 'warning_mute', 'subtext' => $txt['setting_warning_mute_note']),
  655. 'rem1' => array('int', 'user_limit', 'subtext' => $txt['setting_user_limit_note']),
  656. 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note']),
  657. array('select', 'warning_show', 'subtext' => $txt['setting_warning_show_note'], array($txt['setting_warning_show_mods'], $txt['setting_warning_show_user'], $txt['setting_warning_show_all'])),
  658. );
  659. call_integration_hook('integrate_moderation_settings', array($config_vars));
  660. if ($return_config)
  661. return $config_vars;
  662. // Cannot use moderation if post moderation is not enabled.
  663. if (!$modSettings['postmod_active'])
  664. unset($config_vars['moderate']);
  665. // Saving?
  666. if (isset($_GET['save']))
  667. {
  668. checkSession();
  669. // Make sure these don't have an effect.
  670. if (substr($modSettings['warning_settings'], 0, 1) != 1)
  671. {
  672. $_POST['warning_watch'] = 0;
  673. $_POST['warning_moderate'] = 0;
  674. $_POST['warning_mute'] = 0;
  675. }
  676. else
  677. {
  678. $_POST['warning_watch'] = min($_POST['warning_watch'], 100);
  679. $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0;
  680. $_POST['warning_mute'] = min($_POST['warning_mute'], 100);
  681. }
  682. // Fix the warning setting array!
  683. $_POST['warning_settings'] = '1,' . min(100, (int) $_POST['user_limit']) . ',' . min(100, (int) $_POST['warning_decrement']);
  684. $save_vars = $config_vars;
  685. $save_vars[] = array('text', 'warning_settings');
  686. unset($save_vars['rem1'], $save_vars['rem2']);
  687. call_integration_hook('integrate_save_karma_settings', array($save_vars));
  688. saveDBSettings($save_vars);
  689. redirectexit('action=admin;area=securitysettings;sa=moderation');
  690. }
  691. // We actually store lots of these together - for efficiency.
  692. list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
  693. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=moderation';
  694. $context['settings_title'] = $txt['moderation_settings'];
  695. prepareDBSettingContext($config_vars);
  696. }
  697. /**
  698. * Let's try keep the spam to a minimum ah Thantos?
  699. * @param bool $return_config = false
  700. */
  701. function ModifySpamSettings($return_config = false)
  702. {
  703. global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
  704. // Generate a sample registration image.
  705. $context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
  706. $context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand());
  707. // Build up our options array
  708. $config_vars = array(
  709. array('title', 'antispam_Settings'),
  710. array('check', 'reg_verification'),
  711. array('check', 'search_enable_captcha'),
  712. // This, my friend, is a cheat :p
  713. 'guest_verify' => array('check', 'guests_require_captcha', 'postinput' => $txt['setting_guests_require_captcha_desc']),
  714. array('int', 'posts_require_captcha', 'postinput' => $txt['posts_require_captcha_desc'], 'onchange' => 'if (this.value > 0){ document.getElementById(\'guests_require_captcha\').checked = true; document.getElementById(\'guests_require_captcha\').disabled = true;} else {document.getElementById(\'guests_require_captcha\').disabled = false;}'),
  715. array('check', 'guests_report_require_captcha'),
  716. // PM Settings
  717. array('title', 'antispam_PM'),
  718. 'pm1' => array('int', 'max_pm_recipients', 'postinput' => $txt['max_pm_recipients_note']),
  719. 'pm2' => array('int', 'pm_posts_verification', 'postinput' => $txt['pm_posts_verification_note']),
  720. 'pm3' => array('int', 'pm_posts_per_hour', 'postinput' => $txt['pm_posts_per_hour_note']),
  721. // Visual verification.
  722. array('title', 'configure_verification_means'),
  723. array('desc', 'configure_verification_means_desc'),
  724. 'vv' => array('select', 'visual_verification_type', array($txt['setting_image_verification_off'], $txt['setting_image_verification_vsimple'], $txt['setting_image_verification_simple'], $txt['setting_image_verification_medium'], $txt['setting_image_verification_high'], $txt['setting_image_verification_extreme']), 'subtext'=> $txt['setting_visual_verification_type_desc'], 'onchange' => $context['use_graphic_library'] ? 'refreshImages();' : ''),
  725. // Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say.
  726. array('title', 'setup_verification_questions'),
  727. array('desc', 'setup_verification_questions_desc'),
  728. array('int', 'qa_verification_number', 'postinput' => $txt['setting_qa_verification_number_desc']),
  729. array('callback', 'question_answer_list'),
  730. );
  731. call_integration_hook('integrate_spam_settings', array($config_vars));
  732. if ($return_config)
  733. return $config_vars;
  734. // Load any question and answers!
  735. $context['question_answers'] = array();
  736. $request = $smcFunc['db_query']('', '
  737. SELECT id_comment, body AS question, recipient_name AS answer
  738. FROM {db_prefix}log_comments
  739. WHERE comment_type = {string:ver_test}',
  740. array(
  741. 'ver_test' => 'ver_test',
  742. )
  743. );
  744. while ($row = $smcFunc['db_fetch_assoc']($request))
  745. {
  746. $context['question_answers'][$row['id_comment']] = array(
  747. 'id' => $row['id_comment'],
  748. 'question' => $row['question'],
  749. 'answer' => $row['answer'],
  750. );
  751. }
  752. $smcFunc['db_free_result']($request);
  753. // Saving?
  754. if (isset($_GET['save']))
  755. {
  756. checkSession();
  757. // Fix PM settings.
  758. $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour'];
  759. // Hack in guest requiring verification!
  760. if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha']))
  761. $_POST['posts_require_captcha'] = -1;
  762. $save_vars = $config_vars;
  763. unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']);
  764. $save_vars[] = array('text', 'pm_spam_settings');
  765. // Handle verification questions.
  766. $questionInserts = array();
  767. $count_questions = 0;
  768. foreach ($_POST['question'] as $id => $question)
  769. {
  770. $question = trim($smcFunc['htmlspecialchars']($question, ENT_COMPAT));
  771. $answer = trim($smcFunc['strtolower']($smcFunc['htmlspecialchars']($_POST['answer'][$id], ENT_COMPAT)));
  772. // Already existed?
  773. if (isset($context['question_answers'][$id]))
  774. {
  775. $count_questions++;
  776. // Changed?
  777. if ($context['question_answers'][$id]['question'] != $question || $context['question_answers'][$id]['answer'] != $answer)
  778. {
  779. if ($question == '' || $answer == '')
  780. {
  781. $smcFunc['db_query']('', '
  782. DELETE FROM {db_prefix}log_comments
  783. WHERE comment_type = {string:ver_test}
  784. AND id_comment = {int:id}',
  785. array(
  786. 'id' => $id,
  787. 'ver_test' => 'ver_test',
  788. )
  789. );
  790. $count_questions--;
  791. }
  792. else
  793. $request = $smcFunc['db_query']('', '
  794. UPDATE {db_prefix}log_comments
  795. SET body = {string:question}, recipient_name = {string:answer}
  796. WHERE comment_type = {string:ver_test}
  797. AND id_comment = {int:id}',
  798. array(
  799. 'id' => $id,
  800. 'ver_test' => 'ver_test',
  801. 'question' => $question,
  802. 'answer' => $answer,
  803. )
  804. );
  805. }
  806. }
  807. // It's so shiney and new!
  808. elseif ($question != '' && $answer != '')
  809. {
  810. $questionInserts[] = array(
  811. 'comment_type' => 'ver_test',
  812. 'body' => $question,
  813. 'recipient_name' => $answer,
  814. );
  815. }
  816. }
  817. // Any questions to insert?
  818. if (!empty($questionInserts))
  819. {
  820. $smcFunc['db_insert']('',
  821. '{db_prefix}log_comments',
  822. array('comment_type' => 'string', 'body' => 'string-65535', 'recipient_name' => 'string-80'),
  823. $questionInserts,
  824. array('id_comment')
  825. );
  826. $count_questions++;
  827. }
  828. if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions)
  829. $_POST['qa_verification_number'] = $count_questions;
  830. call_integration_hook('integrate_save_spam_settings', array($save_vars));
  831. // Now save.
  832. saveDBSettings($save_vars);
  833. cache_put_data('verificationQuestionIds', null, 300);
  834. redirectexit('action=admin;area=securitysettings;sa=spam');
  835. }
  836. $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y'));
  837. $_SESSION['visual_verification_code'] = '';
  838. for ($i = 0; $i < 6; $i++)
  839. $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)];
  840. // Some javascript for CAPTCHA.
  841. $context['settings_post_javascript'] = '';
  842. if ($context['use_graphic_library'])
  843. $context['settings_post_javascript'] .= '
  844. function refreshImages()
  845. {
  846. var imageType = document.getElementById(\'visual_verification_type\').value;
  847. document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType;
  848. }';
  849. // Show the image itself, or text saying we can't.
  850. if ($context['use_graphic_library'])
  851. $config_vars['vv']['postinput'] = '<br /><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image" /><br />';
  852. else
  853. $config_vars['vv']['postinput'] = '<br /><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>';
  854. // Hack for PM spam settings.
  855. list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
  856. // Hack for guests requiring verification.
  857. $modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']);
  858. $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha'];
  859. // Some minor javascript for the guest post setting.
  860. if ($modSettings['posts_require_captcha'])
  861. $context['settings_post_javascript'] .= '
  862. document.getElementById(\'guests_require_captcha\').disabled = true;';
  863. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=spam';
  864. $context['settings_title'] = $txt['antispam_Settings'];
  865. prepareDBSettingContext($config_vars);
  866. }
  867. /**
  868. * Change the way bad behavior ... well behaves
  869. *
  870. * @param $return_config
  871. */
  872. function ModifyBadBehaviorSettings($return_config = false)
  873. {
  874. global $txt, $scripturl, $context, $modSettings, $boardurl;
  875. // Our callback templates are here
  876. loadTemplate('BadBehavior');
  877. // See if they supplied a valid looking http:BL API Key
  878. $context['invalid_badbehavior_httpbl_key'] = (!empty($modSettings['badbehavior_httpbl_key']) && (strlen($modSettings['badbehavior_httpbl_key']) !== 12 || !ctype_lower($modSettings['badbehavior_httpbl_key'])));
  879. // Any errors to display?
  880. if ($context['invalid_badbehavior_httpbl_key'])
  881. {
  882. $context['settings_message'][] = $txt['setting_badbehavior_httpbl_key_invalid'];
  883. $context['error_type'] = 'notice';
  884. }
  885. // Have we blocked anything in the last 7 days?
  886. if (!empty($modSettings['badbehavior_enabled']))
  887. $context['settings_message'][] = bb2_insert_stats(true) . '<a href="' . $boardurl . '/index.php?action=admin;area=logs;sa=badbehaviorlog" /> [' . $txt['badbehavior_details'] . ']</a>';
  888. // Current whitelist data
  889. $whitelist = array('badbehavior_ip_wl', 'badbehavior_useragent_wl', 'badbehavior_url_wl');
  890. foreach ($whitelist as $list)
  891. {
  892. $context[$list] = array();
  893. $context[$list . '_desc'] = array();
  894. if (!empty($modSettings[$list]))
  895. $context[$list] = unserialize($modSettings[$list]);
  896. if (!empty($modSettings[$list . '_desc']))
  897. $context[$list . '_desc'] = unserialize($modSettings[$list . '_desc']);
  898. }
  899. // Build up our options array
  900. $config_vars = array(
  901. array('title', 'badbehavior_title'),
  902. array('desc', 'badbehavior_desc'),
  903. array('check', 'badbehavior_enabled', 'postinput' => $txt['badbehavior_enabled_desc']),
  904. array('check', 'badbehavior_logging', 'postinput' => $txt['badbehavior_default_on']),
  905. array('check', 'badbehavior_verbose', 'postinput' => $txt['badbehavior_default_off']),
  906. array('check', 'badbehavior_strict', 'postinput' => $txt['badbehavior_default_off']),
  907. array('check', 'badbehavior_offsite_forms', 'postinput' => $txt['badbehavior_default_off']),
  908. array('check', 'badbehavior_eucookie', 'postinput' => $txt['badbehavior_default_off']),
  909. array('check', 'badbehavior_display_stats', 'postinput' => $txt['badbehavior_default_off']),
  910. '',
  911. array('check', 'badbehavior_reverse_proxy', 'postinput' => $txt['badbehavior_default_off']),
  912. array('text', 'badbehavior_reverse_proxy_header', 30, 'postinput' => $txt['badbehavior_reverse_proxy_header_desc']),
  913. array('text', 'badbehavior_reverse_proxy_addresses', 30),
  914. '',
  915. array('text', 'badbehavior_httpbl_key', 12, 'invalid' => $context['invalid_badbehavior_httpbl_key']),
  916. array('int', 'badbehavior_httpbl_threat', 'postinput' => $txt['badbehavior_httpbl_threat_desc']),
  917. array('int', 'badbehavior_httpbl_maxage', 'postinput' => $txt['badbehavior_httpbl_maxage_desc']),
  918. array('title', 'badbehavior_whitelist_title'),
  919. array('desc', 'badbehavior_wl_desc'),
  920. array('int', 'badbehavior_postcount_wl', 'postinput' => $txt['badbehavior_postcount_wl_desc']),
  921. array('callback', 'badbehavior_add_ip'),
  922. array('callback', 'badbehavior_add_url'),
  923. array('callback', 'badbehavior_add_useragent'),
  924. );
  925. if ($return_config)
  926. return $config_vars;
  927. // Saving?
  928. if (isset($_GET['save']))
  929. {
  930. checkSession();
  931. // Make sure Bad Behavior defaults are set if nothing was specified
  932. $_POST['badbehavior_httpbl_threat'] = empty($_POST['badbehavior_httpbl_threat']) ? 25 : $_POST['badbehavior_httpbl_threat'];
  933. $_POST['badbehavior_httpbl_maxage'] = empty($_POST['badbehavior_httpbl_maxage']) ? 30 : $_POST['badbehavior_httpbl_maxage'];
  934. $_POST['badbehavior_reverse_proxy_header'] = empty($_POST['badbehavior_reverse_proxy_header']) ? 'X-Forwarded-For' : $_POST['badbehavior_reverse_proxy_header'];
  935. // Build up the whitelist options
  936. foreach ($whitelist as $list)
  937. {
  938. $this_list = array();
  939. $this_desc = array();
  940. if (isset($_POST[$list]))
  941. {
  942. // clear blanks from the data field, only grab the comments that don't have blank data value
  943. $this_list = array_map('trim', array_filter($_POST[$list]));
  944. $this_desc = array_intersect_key($_POST[$list . '_desc'], $this_list);
  945. }
  946. updateSettings(array($list => serialize($this_list), $list . '_desc' => serialize($this_desc)));
  947. }
  948. saveDBSettings($config_vars);
  949. redirectexit('action=admin;area=securitysettings;sa=badbehavior');
  950. }
  951. $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=badbehavior';
  952. // javascript vars for the "add more xyz" buttons in the callback forms
  953. addInlineJavascript('
  954. var sUrlParent = \'add_more_url_placeholder\';
  955. var oUrlOptionsdt = {name: \'badbehavior_url_wl_desc[]\', class: \'input_text\'};
  956. var oUrlOptionsdd = {name: \'badbehavior_url_wl[]\', class: \'input_text\'};
  957. var sUseragentParent = \'add_more_useragent_placeholder\';
  958. var oUseragentOptionsdt = {name: \'badbehavior_useragent_wl_desc[]\', class: \'input_text\'};
  959. var oUseragentOptionsdd = {name: \'badbehavior_useragent_wl[]\', class: \'input_text\'};
  960. var sIpParent = \'add_more_ip_placeholder\';
  961. var oIpOptionsdt = {name: \'badbehavior_ip_wl_desc[]\', class: \'input_text\'};
  962. var oIpOptionsdd = {name: \'badbehavior_ip_wl[]\', class: \'input_text\'};'
  963. );
  964. prepareDBSettingContext($config_vars);
  965. }
  966. /**
  967. * You'll never guess what this function does...
  968. *
  969. * @param $return_config
  970. */
  971. function ModifySignatureSettings($return_config = false)
  972. {
  973. global $context, $txt, $modSettings, $sig_start, $smcFunc, $helptxt, $scripturl;
  974. $config_vars = array(
  975. // Are signatures even enabled?
  976. array('check', 'signature_enable'),
  977. '',
  978. // Tweaking settings!
  979. array('int', 'signature_max_length', 'subtext' => $txt['zero_for_no_limit']),
  980. array('int', 'signature_max_lines', 'subtext' => $txt['zero_for_no_limit']),
  981. array('int', 'signature_max_font_size', 'subtext' => $txt['zero_for_no_limit']),
  982. array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'),
  983. array('int', 'signature_max_smileys', 'subtext' => $txt['zero_for_no_limit']),
  984. '',
  985. // Image settings.
  986. array('int', 'signature_max_images', 'subtext' => $txt['signature_max_images_note']),
  987. array('int', 'signature_max_image_width', 'subtext' => $txt['zero_for_no_limit']),
  988. array('int', 'signature_max_image_height', 'subtext' => $txt['zero_for_no_limit']),
  989. '',
  990. array('bbc', 'signature_bbc'),
  991. );
  992. call_integration_hook('integrate_signature_settings', array($config_vars));
  993. if ($return_config)
  994. return $config_vars;
  995. // Setup the template.
  996. $context['page_title'] = $txt['signature_settings'];
  997. $context['sub_template'] = 'show_settings';
  998. // Disable the max smileys option if we don't allow smileys at all!
  999. $context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;';
  1000. // Load all the signature settings.
  1001. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  1002. $sig_limits = explode(',', $sig_limits);
  1003. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  1004. // Applying to ALL signatures?!!
  1005. if (isset($_GET['apply']))
  1006. {
  1007. // Security!
  1008. checkSession('get');
  1009. $sig_start = time();
  1010. // This is horrid - but I suppose some people will want the option to do it.
  1011. $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0;
  1012. $done = false;
  1013. $request = $smcFunc['db_query']('', '
  1014. SELECT MAX(id_member)
  1015. FROM {db_prefix}members',
  1016. array(
  1017. )
  1018. );
  1019. list ($context['max_member']) = $smcFunc['db_fetch_row']($request);
  1020. $smcFunc['db_free_result']($request);
  1021. while (!$done)
  1022. {
  1023. $changes = array();
  1024. $request = $smcFunc['db_query']('', '
  1025. SELECT id_member, signature
  1026. FROM {db_prefix}members
  1027. WHERE id_member BETWEEN ' . $_GET['step'] . ' AND ' . $_GET['step'] . ' + 49
  1028. AND id_group != {int:admin_group}
  1029. AND FIND_IN_SET({int:admin_group}, additional_groups) = 0',
  1030. array(
  1031. 'admin_group' => 1,
  1032. )
  1033. );
  1034. while ($row = $smcFunc['db_fetch_assoc']($request))
  1035. {
  1036. // Apply all the rules we can realistically do.
  1037. $sig = strtr($row['signature'], array('<br />' => "\n"));
  1038. // Max characters...
  1039. if (!empty($sig_limits[1]))
  1040. $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]);
  1041. // Max lines...
  1042. if (!empty($sig_limits[2]))
  1043. {
  1044. $count = 0;
  1045. for ($i = 0; $i < strlen($sig); $i++)
  1046. {
  1047. if ($sig[$i] == "\n")
  1048. {
  1049. $count++;
  1050. if ($count >= $sig_limits[2])
  1051. $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' '));
  1052. }
  1053. }
  1054. }
  1055. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2]))
  1056. {
  1057. foreach ($matches[1] as $ind => $size)
  1058. {
  1059. $limit_broke = 0;
  1060. // Attempt to allow all sizes of abuse, so to speak.
  1061. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  1062. $limit_broke = $sig_limits[7] . 'px';
  1063. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  1064. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  1065. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  1066. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  1067. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  1068. $limit_broke = 'large';
  1069. if ($limit_broke)
  1070. $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig);
  1071. }
  1072. }
  1073. // Stupid images - this is stupidly, stupidly challenging.
  1074. if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6])))
  1075. {
  1076. $replaces = array();
  1077. $img_count = 0;
  1078. // Get all BBC tags...
  1079. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $sig, $matches);
  1080. // ... and all HTML ones.
  1081. preg_match_all('~&lt;img\s+src=(?:&quot;)?((?:http://|ftp://|https://|ftps://).+?)(?:&quot;)?(?:\s+alt=(?:&quot;)?(.*?)(?:&quot;)?)?(?:\s?/)?&gt;~i', $sig, $matches2, PREG_PATTERN_ORDER);
  1082. // And stick the HTML in the BBC.
  1083. if (!empty($matches2))
  1084. {
  1085. foreach ($matches2[0] as $ind => $dummy)
  1086. {
  1087. $matches[0][] = $matches2[0][$ind];
  1088. $matches[1][] = '';
  1089. $matches[2][] = '';
  1090. $matches[3][] = '';
  1091. $matches[4][] = '';
  1092. $matches[5][] = '';
  1093. $matches[6][] = '';
  1094. $matches[7][] = $matches2[1][$ind];
  1095. }
  1096. }
  1097. // Try to find all the images!
  1098. if (!empty($matches))
  1099. {
  1100. $image_count_holder = array();
  1101. foreach ($matches[0] as $key => $image)
  1102. {
  1103. $width = -1; $height = -1;
  1104. $img_count++;
  1105. // Too many images?
  1106. if (!empty($sig_limits[3]) && $img_count > $sig_limits[3])
  1107. {
  1108. // If we've already had this before we only want to remove the excess.
  1109. if (isset($image_count_holder[$image]))
  1110. {
  1111. $img_offset = -1;
  1112. $rep_img_count = 0;
  1113. while ($img_offset !== false)
  1114. {
  1115. $img_offset = strpos($sig, $image, $img_offset + 1);
  1116. $rep_img_count++;
  1117. if ($rep_img_count > $image_count_holder[$image])
  1118. {
  1119. // Only replace the excess.
  1120. $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset));
  1121. // Stop looping.
  1122. $img_offset = false;
  1123. }
  1124. }
  1125. }
  1126. else
  1127. $replaces[$image] = '';
  1128. continue;
  1129. }
  1130. // Does it have predefined restraints? Width first.
  1131. if ($matches[6][$key])
  1132. $matches[2][$key] = $matches[6][$key];
  1133. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  1134. {
  1135. $width = $sig_limits[5];
  1136. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  1137. }
  1138. elseif ($matches[2][$key])
  1139. $width = $matches[2][$key];
  1140. // ... and height.
  1141. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  1142. {
  1143. $height = $sig_limits[6];
  1144. if ($width != -1)
  1145. $width = $width * ($height / $matches[4][$key]);
  1146. }
  1147. elseif ($matches[4][$key])
  1148. $height = $matches[4][$key];
  1149. // If the dimensions are still not fixed - we need to check the actual image.
  1150. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  1151. {
  1152. // We'll mess up with images, who knows.
  1153. require_once(SUBSDIR . '/Attachments.subs.php');
  1154. $sizes = url_image_size($matches[7][$key]);
  1155. if (is_array($sizes))
  1156. {
  1157. // Too wide?
  1158. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  1159. {
  1160. $width = $sig_limits[5];
  1161. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  1162. }
  1163. // Too high?
  1164. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  1165. {
  1166. $height = $sig_limits[6];
  1167. if ($width == -1)
  1168. $width = $sizes[0];
  1169. $width = $width * ($height / $sizes[1]);
  1170. }
  1171. elseif ($width != -1)
  1172. $height = $sizes[1];
  1173. }
  1174. }
  1175. // Did we come up with some changes? If so remake the string.
  1176. if ($width != -1 || $height != -1)
  1177. {
  1178. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  1179. }
  1180. // Record that we got one.
  1181. $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1;
  1182. }
  1183. if (!empty($replaces))
  1184. $sig = str_replace(array_keys($replaces), array_values($replaces), $sig);
  1185. }
  1186. }
  1187. // Try to fix disabled tags.
  1188. if (!empty($disabledTags))
  1189. {
  1190. $sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig);
  1191. $sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig);
  1192. }
  1193. $sig = strtr($sig, array("\n" => '<br />'));
  1194. call_integration_hook('integrate_apply_signature_settings', array($sig, $sig_limits, $disabledTags));
  1195. if ($sig != $row['signature'])
  1196. $changes[$row['id_member']] = $sig;
  1197. }
  1198. if ($smcFunc['db_num_rows']($request) == 0)
  1199. $done = true;
  1200. $smcFunc['db_free_result']($request);
  1201. // Do we need to delete what we have?
  1202. if (!empty($changes))
  1203. {
  1204. foreach ($changes as $id => $sig)
  1205. $smcFunc['db_query']('', '
  1206. UPDATE {db_prefix}members
  1207. SET signature = {string:signature}
  1208. WHERE id_member = {int:id_member}',
  1209. array(
  1210. 'id_member' => $id,
  1211. 'signature' => $sig,
  1212. )
  1213. );
  1214. }
  1215. $_GET['step'] += 50;
  1216. if (!$done)
  1217. pauseSignatureApplySettings();
  1218. }
  1219. $settings_applied = true;
  1220. }
  1221. $context['signature_settings'] = array(
  1222. 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0,
  1223. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  1224. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  1225. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  1226. 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1,
  1227. 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0,
  1228. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  1229. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  1230. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  1231. );
  1232. // Temporarily make each setting a modSetting!
  1233. foreach ($context['signature_settings'] as $key => $value)
  1234. $modSettings['signature_' . $key] = $value;
  1235. // Make sure we check the right tags!
  1236. $modSettings['bbc_disabled_signature_bbc'] = $disabledTags;
  1237. // Saving?
  1238. if (isset($_GET['save']))
  1239. {
  1240. checkSession();
  1241. // Clean up the tag stuff!
  1242. $bbcTags = array();
  1243. foreach (parse_bbc(false) as $tag)
  1244. $bbcTags[] = $tag['tag'];
  1245. if (!isset($_POST['signature_bbc_enabledTags']))
  1246. $_POST['signature_bbc_enabledTags'] = array();
  1247. elseif (!is_array($_POST['signature_bbc_enabledTags']))
  1248. $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']);
  1249. $sig_limits = array();
  1250. foreach ($context['signature_settings'] as $key => $value)
  1251. {
  1252. if ($key == 'allow_smileys')
  1253. continue;
  1254. elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys']))
  1255. $sig_limits[] = -1;
  1256. else
  1257. $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0;
  1258. }
  1259. call_integration_hook('integrate_save_signature_settings', array($sig_limits, $bbcTags));
  1260. $_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags']));
  1261. // Even though we have practically no settings l…

Large files files are truncated, but you can click here to view the full file