PageRenderTime 43ms CodeModel.GetById 23ms RepoModel.GetById 1ms 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
  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 let's keep the convention going!
  1262. $save_vars = array();
  1263. $save_vars[] = array('text', 'signature_settings');
  1264. saveDBSettings($save_vars);
  1265. redirectexit('action=admin;area=featuresettings;sa=sig');
  1266. }
  1267. $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig';
  1268. $context['settings_title'] = $txt['signature_settings'];
  1269. $context['settings_message'] = !empty($settings_applied) ? '<div class="infobox">' . $txt['signature_settings_applied'] . '</div>' : '<p class="centertext">' . sprintf($txt['signature_settings_warning'], $context['session_id'], $context['session_var']) . '</p>';
  1270. prepareDBSettingContext($config_vars);
  1271. }
  1272. /**
  1273. * Just pause the signature applying thing.
  1274. */
  1275. function pauseSignatureApplySettings()
  1276. {
  1277. global $context, $txt, $sig_start;
  1278. // Try get more time...
  1279. @set_time_limit(600);
  1280. if (function_exists('apache_reset_timeout'))
  1281. @apache_reset_timeout();
  1282. // Have we exhausted all the time we allowed?
  1283. if (time() - array_sum(explode(' ', $sig_start)) < 3)
  1284. return;
  1285. $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id'];
  1286. $context['page_title'] = $txt['not_done_title'];
  1287. $context['continue_post_data'] = '';
  1288. $context['continue_countdown'] = '2';
  1289. $context['sub_template'] = 'not_done';
  1290. // Specific stuff to not break this template!
  1291. $context[$context['admin_menu_name']]['current_subsection'] = 'sig';
  1292. // Get the right percent.
  1293. $context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100);
  1294. // Never more than 100%!
  1295. $context['continue_percent'] = min($context['continue_percent'], 100);
  1296. obExit();
  1297. }
  1298. /**
  1299. * Show all the custom profile fields available to the user.
  1300. */
  1301. function ShowCustomProfiles()
  1302. {
  1303. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1304. global $modSettings;
  1305. $context['page_title'] = $txt['custom_profile_title'];
  1306. $context['sub_template'] = 'show_custom_profile';
  1307. // What about standard fields they can tweak?
  1308. $standard_fields = array('location', 'gender', 'website', 'posts', 'warning_status');
  1309. // What fields can't you put on the registration page?
  1310. $context['fields_no_registration'] = array('posts', 'warning_status');
  1311. // Are we saving any standard field changes?
  1312. if (isset($_POST['save']))
  1313. {
  1314. checkSession();
  1315. validateToken('admin-scp');
  1316. // Do the active ones first.
  1317. $disable_fields = array_flip($standard_fields);
  1318. if (!empty($_POST['active']))
  1319. {
  1320. foreach ($_POST['active'] as $value)
  1321. if (isset($disable_fields[$value]))
  1322. unset($disable_fields[$value]);
  1323. }
  1324. // What we have left!
  1325. $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields));
  1326. // Things we want to show on registration?
  1327. $reg_fields = array();
  1328. if (!empty($_POST['reg']))
  1329. {
  1330. foreach ($_POST['reg'] as $value)
  1331. if (in_array($value, $standard_fields) && !isset($disable_fields[$value]))
  1332. $reg_fields[] = $value;
  1333. }
  1334. // What we have left!
  1335. $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields);
  1336. if (!empty($changes))
  1337. updateSettings($changes);
  1338. }
  1339. createToken('admin-scp');
  1340. require_once(SUBSDIR . '/List.subs.php');
  1341. $listOptions = array(
  1342. 'id' => 'standard_profile_fields',
  1343. 'title' => $txt['standard_profile_title'],
  1344. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1345. 'get_items' => array(
  1346. 'function' => 'list_getProfileFields',
  1347. 'params' => array(
  1348. true,
  1349. ),
  1350. ),
  1351. 'columns' => array(
  1352. 'field' => array(
  1353. 'header' => array(
  1354. 'value' => $txt['standard_profile_field'],
  1355. ),
  1356. 'data' => array(
  1357. 'db' => 'label',
  1358. 'style' => 'width: 60%;',
  1359. ),
  1360. ),
  1361. 'active' => array(
  1362. 'header' => array(
  1363. 'value' => $txt['custom_edit_active'],
  1364. 'class' => 'centercol',
  1365. ),
  1366. 'data' => array(
  1367. 'function' => create_function('$rowData', '
  1368. $isChecked = $rowData[\'disabled\'] ? \'\' : \' checked="checked"\';
  1369. $onClickHandler = $rowData[\'can_show_register\'] ? sprintf(\'onclick="document.getElementById(\\\'reg_%1$s\\\').disabled = !this.checked;"\', $rowData[\'id\']) : \'\';
  1370. return sprintf(\'<input type="checkbox" name="active[]" id="active_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $onClickHandler);
  1371. '),
  1372. 'style' => 'width: 20%;',
  1373. 'class' => 'centercol',
  1374. ),
  1375. ),
  1376. 'show_on_registration' => array(
  1377. 'header' => array(
  1378. 'value' => $txt['custom_edit_registration'],
  1379. 'class' => 'centercol',
  1380. ),
  1381. 'data' => array(
  1382. 'function' => create_function('$rowData', '
  1383. $isChecked = $rowData[\'on_register\'] && !$rowData[\'disabled\'] ? \' checked="checked"\' : \'\';
  1384. $isDisabled = $rowData[\'can_show_register\'] ? \'\' : \' disabled="disabled"\';
  1385. return sprintf(\'<input type="checkbox" name="reg[]" id="reg_%1$s" value="%1$s" class="input_check"%2$s%3$s />\', $rowData[\'id\'], $isChecked, $isDisabled);
  1386. '),
  1387. 'style' => 'width: 20%;',
  1388. 'class' => 'centercol',
  1389. ),
  1390. ),
  1391. ),
  1392. 'form' => array(
  1393. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1394. 'name' => 'standardProfileFields',
  1395. 'token' => 'admin-scp',
  1396. ),
  1397. 'additional_rows' => array(
  1398. array(
  1399. 'position' => 'below_table_data',
  1400. 'value' => '<input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />',
  1401. ),
  1402. ),
  1403. );
  1404. createList($listOptions);
  1405. $listOptions = array(
  1406. 'id' => 'custom_profile_fields',
  1407. 'title' => $txt['custom_profile_title'],
  1408. 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile',
  1409. 'default_sort_col' => 'field_name',
  1410. 'no_items_label' => $txt['custom_profile_none'],
  1411. 'items_per_page' => 25,
  1412. 'get_items' => array(
  1413. 'function' => 'list_getProfileFields',
  1414. 'params' => array(
  1415. false,
  1416. ),
  1417. ),
  1418. 'get_count' => array(
  1419. 'function' => 'list_getProfileFieldSize',
  1420. ),
  1421. 'columns' => array(
  1422. 'field_name' => array(
  1423. 'header' => array(
  1424. 'value' => $txt['custom_profile_fieldname'],
  1425. ),
  1426. 'data' => array(
  1427. 'function' => create_function('$rowData', '
  1428. global $scripturl;
  1429. return sprintf(\'<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>\', $scripturl, $rowData[\'id_field\'], $rowData[\'field_name\'], $rowData[\'field_desc\']);
  1430. '),
  1431. 'style' => 'width: 62%;',
  1432. ),
  1433. 'sort' => array(
  1434. 'default' => 'field_name',
  1435. 'reverse' => 'field_name DESC',
  1436. ),
  1437. ),
  1438. 'field_type' => array(
  1439. 'header' => array(
  1440. 'value' => $txt['custom_profile_fieldtype'],
  1441. ),
  1442. 'data' => array(
  1443. 'function' => create_function('$rowData', '
  1444. global $txt;
  1445. $textKey = sprintf(\'custom_profile_type_%1$s\', $rowData[\'field_type\']);
  1446. return isset($txt[$textKey]) ? $txt[$textKey] : $textKey;
  1447. '),
  1448. 'style' => 'width: 15%;',
  1449. ),
  1450. 'sort' => array(
  1451. 'default' => 'field_type',
  1452. 'reverse' => 'field_type DESC',
  1453. ),
  1454. ),
  1455. 'active' => array(
  1456. 'header' => array(
  1457. 'value' => $txt['custom_profile_active'],
  1458. ),
  1459. 'data' => array(
  1460. 'function' => create_function('$rowData', '
  1461. global $txt;
  1462. return $rowData[\'active\'] ? $txt[\'yes\'] : $txt[\'no\'];
  1463. '),
  1464. 'style' => 'width: 8%;',
  1465. ),
  1466. 'sort' => array(
  1467. 'default' => 'active DESC',
  1468. 'reverse' => 'active',
  1469. ),
  1470. ),
  1471. 'placement' => array(
  1472. 'header' => array(
  1473. 'value' => $txt['custom_profile_placement'],
  1474. ),
  1475. 'data' => array(
  1476. 'function' => create_function('$rowData', '
  1477. global $txt;
  1478. return $txt[\'custom_profile_placement_\' . (empty($rowData[\'placement\']) ? \'standard\' : ($rowData[\'placement\'] == 1 ? \'withicons\' : \'abovesignature\'))];
  1479. '),
  1480. 'style' => 'width: 8%;',
  1481. ),
  1482. 'sort' => array(
  1483. 'default' => 'placement DESC',
  1484. 'reverse' => 'placement',
  1485. ),
  1486. ),
  1487. 'show_on_registration' => array(
  1488. 'data' => array(
  1489. 'sprintf' => array(
  1490. 'format' => '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=%1$s">' . $txt['modify'] . '</a>',
  1491. 'params' => array(
  1492. 'id_field' => false,
  1493. ),
  1494. ),
  1495. 'style' => 'width: 15%;',
  1496. ),
  1497. ),
  1498. ),
  1499. 'form' => array(
  1500. 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit',
  1501. 'name' => 'customProfileFields',
  1502. ),
  1503. 'additional_rows' => array(
  1504. array(
  1505. 'position' => 'below_table_data',
  1506. 'value' => '<input type="submit" name="new" value="' . $txt['custom_profile_make_new'] . '" class="button_submit" />',
  1507. ),
  1508. ),
  1509. );
  1510. createList($listOptions);
  1511. }
  1512. /**
  1513. * Callback for createList().
  1514. *
  1515. * @param $start
  1516. * @param $items_per_page
  1517. * @param $sort
  1518. * @param $standardFields
  1519. */
  1520. function list_getProfileFields($start, $items_per_page, $sort, $standardFields)
  1521. {
  1522. global $txt, $modSettings, $smcFunc;
  1523. $list = array();
  1524. if ($standardFields)
  1525. {
  1526. $standard_fields = array('location', 'gender', 'website', 'posts', 'warning_status');
  1527. $fields_no_registration = array('posts', 'warning_status');
  1528. $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  1529. $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array();
  1530. foreach ($standard_fields as $field)
  1531. $list[] = array(
  1532. 'id' => $field,
  1533. 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field),
  1534. 'disabled' => in_array($field, $disabled_fields),
  1535. 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration),
  1536. 'can_show_register' => !in_array($field, $fields_no_registration),
  1537. );
  1538. }
  1539. else
  1540. {
  1541. // Load all the fields.
  1542. $request = $smcFunc['db_query']('', '
  1543. SELECT id_field, col_name, field_name, field_desc, field_type, active, placement
  1544. FROM {db_prefix}custom_fields
  1545. ORDER BY {raw:sort}
  1546. LIMIT {int:start}, {int:items_per_page}',
  1547. array(
  1548. 'sort' => $sort,
  1549. 'start' => $start,
  1550. 'items_per_page' => $items_per_page,
  1551. )
  1552. );
  1553. while ($row = $smcFunc['db_fetch_assoc']($request))
  1554. $list[] = $row;
  1555. $smcFunc['db_free_result']($request);
  1556. }
  1557. return $list;
  1558. }
  1559. /**
  1560. * Callback for createList().
  1561. */
  1562. function list_getProfileFieldSize()
  1563. {
  1564. global $smcFunc;
  1565. $request = $smcFunc['db_query']('', '
  1566. SELECT COUNT(*)
  1567. FROM {db_prefix}custom_fields',
  1568. array(
  1569. )
  1570. );
  1571. list ($numProfileFields) = $smcFunc['db_fetch_row']($request);
  1572. $smcFunc['db_free_result']($request);
  1573. return $numProfileFields;
  1574. }
  1575. /**
  1576. * Edit some profile fields?
  1577. */
  1578. function EditCustomProfiles()
  1579. {
  1580. global $txt, $scripturl, $context, $settings, $sc, $smcFunc;
  1581. // Sort out the context!
  1582. $context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0;
  1583. $context[$context['admin_menu_name']]['current_subsection'] = 'profile';
  1584. $context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title'];
  1585. $context['sub_template'] = 'edit_profile_field';
  1586. // Load the profile language for section names.
  1587. loadLanguage('Profile');
  1588. if ($context['fid'])
  1589. {
  1590. $request = $smcFunc['db_query']('', '
  1591. SELECT
  1592. id_field, col_name, field_name, field_desc, field_type, field_length, field_options,
  1593. show_reg, show_display, show_profile, private, active, default_value, can_search,
  1594. bbc, mask, enclose, placement
  1595. FROM {db_prefix}custom_fields
  1596. WHERE id_field = {int:current_field}',
  1597. array(
  1598. 'current_field' => $context['fid'],
  1599. )
  1600. );
  1601. $context['field'] = array();
  1602. while ($row = $smcFunc['db_fetch_assoc']($request))
  1603. {
  1604. if ($row['field_type'] == 'textarea')
  1605. @list ($rows, $cols) = explode(',', $row['default_value']);
  1606. else
  1607. {
  1608. $rows = 3;
  1609. $cols = 30;
  1610. }
  1611. $context['field'] = array(
  1612. 'name' => $row['field_name'],
  1613. 'desc' => $row['field_desc'],
  1614. 'colname' => $row['col_name'],
  1615. 'profile_area' => $row['show_profile'],
  1616. 'reg' => $row['show_reg'],
  1617. 'display' => $row['show_display'],
  1618. 'type' => $row['field_type'],
  1619. 'max_length' => $row['field_length'],
  1620. 'rows' => $rows,
  1621. 'cols' => $cols,
  1622. 'bbc' => $row['bbc'] ? true : false,
  1623. 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false,
  1624. 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '',
  1625. 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''),
  1626. 'active' => $row['active'],
  1627. 'private' => $row['private'],
  1628. 'can_search' => $row['can_search'],
  1629. 'mask' => $row['mask'],
  1630. 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '',
  1631. 'enclose' => $row['enclose'],
  1632. 'placement' => $row['placement'],
  1633. );
  1634. }
  1635. $smcFunc['db_free_result']($request);
  1636. }
  1637. // Setup the default values as needed.
  1638. if (empty($context['field']))
  1639. $context['field'] = array(
  1640. 'name' => '',
  1641. 'colname' => '???',
  1642. 'desc' => '',
  1643. 'profile_area' => 'forumprofile',
  1644. 'reg' => false,
  1645. 'display' => false,
  1646. 'type' => 'text',
  1647. 'max_length' => 255,
  1648. 'rows' => 4,
  1649. 'cols' => 30,
  1650. 'bbc' => false,
  1651. 'default_check' => false,
  1652. 'default_select' => '',
  1653. 'options' => array('', '', ''),
  1654. 'active' => true,
  1655. 'private' => false,
  1656. 'can_search' => false,
  1657. 'mask' => 'nohtml',
  1658. 'regex' => '',
  1659. 'enclose' => '',
  1660. 'placement' => 0,
  1661. );
  1662. // Are we saving?
  1663. if (isset($_POST['save']))
  1664. {
  1665. checkSession();
  1666. validateToken('admin-ecp');
  1667. // Everyone needs a name - even the (bracket) unknown...
  1668. if (trim($_POST['field_name']) == '')
  1669. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name');
  1670. // Regex you say? Do a very basic test to see if the pattern is valid
  1671. if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false)
  1672. redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error');
  1673. $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']);
  1674. $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']);
  1675. // Checkboxes...
  1676. $show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0;
  1677. $show_display = isset($_POST['display']) ? 1 : 0;
  1678. $bbc = isset($_POST['bbc']) ? 1 : 0;
  1679. $show_profile = $_POST['profile_area'];
  1680. $active = isset($_POST['active']) ? 1 : 0;
  1681. $private = isset($_POST['private']) ? (int) $_POST['private'] : 0;
  1682. $can_search = isset($_POST['can_search']) ? 1 : 0;
  1683. // Some masking stuff...
  1684. $mask = isset($_POST['mask']) ? $_POST['mask'] : '';
  1685. if ($mask == 'regex' && isset($_POST['regex']))
  1686. $mask .= $_POST['regex'];
  1687. $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255;
  1688. $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : '';
  1689. $placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0;
  1690. // Select options?
  1691. $field_options = '';
  1692. $newOptions = array();
  1693. $default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : '';
  1694. if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio'))
  1695. {
  1696. foreach ($_POST['select_option'] as $k => $v)
  1697. {
  1698. // Clean, clean, clean...
  1699. $v = $smcFunc['htmlspecialchars']($v);
  1700. $v = strtr($v, array(',' => ''));
  1701. // Nada, zip, etc...
  1702. if (trim($v) == '')
  1703. continue;
  1704. // Otherwise, save it boy.
  1705. $field_options .= $v . ',';
  1706. // This is just for working out what happened with old options...
  1707. $newOptions[$k] = $v;
  1708. // Is it default?
  1709. if (isset($_POST['default_select']) && $_POST['default_select'] == $k)
  1710. $default = $v;
  1711. }
  1712. $field_options = substr($field_options, 0, -1);
  1713. }
  1714. // Text area by default has dimensions
  1715. if ($_POST['field_type'] == 'textarea')
  1716. $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols'];
  1717. // Come up with the unique name?
  1718. if (empty($context['fid']))
  1719. {
  1720. $colname = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6);
  1721. preg_match('~([\w\d_-]+)~', $colname, $matches);
  1722. // If there is nothing to the name, then let's start our own - for foreign languages etc.
  1723. if (isset($matches[1]))
  1724. $colname = $initial_colname = 'cust_' . strtolower($matches[1]);
  1725. else
  1726. $colname = $initial_colname = 'cust_' . mt_rand(1, 999999);
  1727. // Make sure this is unique.
  1728. // @todo This may not be the most efficient way to do this.
  1729. $unique = false;
  1730. for ($i = 0; !$unique && $i < 9; $i ++)
  1731. {
  1732. $request = $smcFunc['db_query']('', '
  1733. SELECT id_field
  1734. FROM {db_prefix}custom_fields
  1735. WHERE col_name = {string:current_column}',
  1736. array(
  1737. 'current_column' => $colname,
  1738. )
  1739. );
  1740. if ($smcFunc['db_num_rows']($request) == 0)
  1741. $unique = true;
  1742. else
  1743. $colname = $initial_colname . $i;
  1744. $smcFunc['db_free_result']($request);
  1745. }
  1746. // Still not a unique colum name? Leave it up to the user, then.
  1747. if (!$unique)
  1748. fatal_lang_error('custom_option_not_unique');
  1749. }
  1750. // Work out what to do with the user data otherwise...
  1751. else
  1752. {
  1753. // Anything going to check or select is pointless keeping - as is anything coming from check!
  1754. if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check')
  1755. || (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio')
  1756. || ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check'))
  1757. {
  1758. $smcFunc['db_query']('', '
  1759. DELETE FROM {db_prefix}themes
  1760. WHERE variable = {string:current_column}
  1761. AND id_member > {int:no_member}',
  1762. array(
  1763. 'no_member' => 0,
  1764. 'current_column' => $context['field']['colname'],
  1765. )
  1766. );
  1767. }
  1768. // Otherwise - if the select is edited may need to adjust!
  1769. elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')
  1770. {
  1771. $optionChanges = array();
  1772. $takenKeys = array();
  1773. // Work out what's changed!
  1774. foreach ($context['field']['options'] as $k => $option)
  1775. {
  1776. if (trim($option) == '')
  1777. continue;
  1778. // Still exists?
  1779. if (in_array($option, $newOptions))
  1780. {
  1781. $takenKeys[] = $k;
  1782. continue;
  1783. }
  1784. }
  1785. // Finally - have we renamed it - or is it really gone?
  1786. foreach ($optionChanges as $k => $option)
  1787. {
  1788. // Just been renamed?
  1789. if (!in_array($k, $takenKeys) && !empty($newOptions[$k]))
  1790. $smcFunc['db_query']('', '
  1791. UPDATE {db_prefix}themes
  1792. SET value = {string:new_value}
  1793. WHERE variable = {string:current_column}
  1794. AND value = {string:old_value}
  1795. AND id_member > {int:no_member}',
  1796. array(
  1797. 'no_member' => 0,
  1798. 'new_value' => $newOptions[$k],
  1799. 'current_column' => $context['field']['colname'],
  1800. 'old_value' => $option,
  1801. )
  1802. );
  1803. }
  1804. }
  1805. // @todo Maybe we should adjust based on new text length limits?
  1806. }
  1807. // Updating an existing field?
  1808. if ($context['fid'])
  1809. {
  1810. $smcFunc['db_query']('', '
  1811. UPDATE {db_prefix}custom_fields
  1812. SET
  1813. field_name = {string:field_name}, field_desc = {string:field_desc},
  1814. field_type = {string:field_type}, field_length = {int:field_length},
  1815. field_options = {string:field_options}, show_reg = {int:show_reg},
  1816. show_display = {int:show_display}, show_profile = {string:show_profile},
  1817. private = {int:private}, active = {int:active}, default_value = {string:default_value},
  1818. can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask},
  1819. enclose = {string:enclose}, placement = {int:placement}
  1820. WHERE id_field = {int:current_field}',
  1821. array(
  1822. 'field_length' => $field_length,
  1823. 'show_reg' => $show_reg,
  1824. 'show_display' => $show_display,
  1825. 'private' => $private,
  1826. 'active' => $active,
  1827. 'can_search' => $can_search,
  1828. 'bbc' => $bbc,
  1829. 'current_field' => $context['fid'],
  1830. 'field_name' => $_POST['field_name'],
  1831. 'field_desc' => $_POST['field_desc'],
  1832. 'field_type' => $_POST['field_type'],
  1833. 'field_options' => $field_options,
  1834. 'show_profile' => $show_profile,
  1835. 'default_value' => $default,
  1836. 'mask' => $mask,
  1837. 'enclose' => $enclose,
  1838. 'placement' => $placement,
  1839. )
  1840. );
  1841. // Just clean up any old selects - these are a pain!
  1842. if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions))
  1843. $smcFunc['db_query']('', '
  1844. DELETE FROM {db_prefix}themes
  1845. WHERE variable = {string:current_column}
  1846. AND value NOT IN ({array_string:new_option_values})
  1847. AND id_member > {int:no_member}',
  1848. array(
  1849. 'no_member' => 0,
  1850. 'new_option_values' => $newOptions,
  1851. 'current_column' => $context['field']['colname'],
  1852. )
  1853. );
  1854. }
  1855. // Otherwise creating a new one
  1856. else
  1857. {
  1858. $smcFunc['db_insert']('',
  1859. '{db_prefix}custom_fields',
  1860. array(
  1861. 'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string',
  1862. 'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string',
  1863. 'show_reg' => 'int', 'show_display' => 'int', 'show_profile' => 'string',
  1864. 'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int',
  1865. 'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int',
  1866. ),
  1867. array(
  1868. $colname, $_POST['field_name'], $_POST['field_desc'],
  1869. $_POST['field_type'], $field_length, $field_options,
  1870. $show_reg, $show_display, $show_profile,
  1871. $private, $active, $default, $can_search,
  1872. $bbc, $mask, $enclose, $placement,
  1873. ),
  1874. array('id_field')
  1875. );
  1876. }
  1877. // As there's currently no option to priorize certain fields over others, let's order them alphabetically.
  1878. $smcFunc['db_query']('alter_table_boards', '
  1879. ALTER TABLE {db_prefix}custom_fields
  1880. ORDER BY field_name',
  1881. array(
  1882. 'db_error_skip' => true,
  1883. )
  1884. );
  1885. }
  1886. // Deleting?
  1887. elseif (isset($_POST['delete']) && $context['field']['colname'])
  1888. {
  1889. checkSession();
  1890. validateToken('admin-ecp');
  1891. // Delete the user data first.
  1892. $smcFunc['db_query']('', '
  1893. DELETE FROM {db_prefix}themes
  1894. WHERE variable = {string:current_column}
  1895. AND id_member > {int:no_member}',
  1896. array(
  1897. 'no_member' => 0,
  1898. 'current_column' => $context['field']['colname'],
  1899. )
  1900. );
  1901. // Finally - the field itself is gone!
  1902. $smcFunc['db_query']('', '
  1903. DELETE FROM {db_prefix}custom_fields
  1904. WHERE id_field = {int:current_field}',
  1905. array(
  1906. 'current_field' => $context['fid'],
  1907. )
  1908. );
  1909. }
  1910. // Rebuild display cache etc.
  1911. if (isset($_POST['delete']) || isset($_POST['save']))
  1912. {
  1913. checkSession();
  1914. $request = $smcFunc['db_query']('', '
  1915. SELECT col_name, field_name, field_type, bbc, enclose, placement
  1916. FROM {db_prefix}custom_fields
  1917. WHERE show_display = {int:is_displayed}
  1918. AND active = {int:active}
  1919. AND private != {int:not_owner_only}
  1920. AND private != {int:not_admin_only}',
  1921. array(
  1922. 'is_displayed' => 1,
  1923. 'active' => 1,
  1924. 'not_owner_only' => 2,
  1925. 'not_admin_only' => 3,
  1926. )
  1927. );
  1928. $fields = array();
  1929. while ($row = $smcFunc['db_fetch_assoc']($request))
  1930. {
  1931. $fields[] = array(
  1932. 'colname' => strtr($row['col_name'], array('|' => '', ';' => '')),
  1933. 'title' => strtr($row['field_name'], array('|' => '', ';' => '')),
  1934. 'type' => $row['field_type'],
  1935. 'bbc' => $row['bbc'] ? 1 : 0,
  1936. 'placement' => !empty($row['placement']) ? $row['placement'] : 0,
  1937. 'enclose' => !empty($row['enclose']) ? $row['enclose'] : '',
  1938. );
  1939. }
  1940. $smcFunc['db_free_result']($request);
  1941. updateSettings(array('displayFields' => serialize($fields)));
  1942. redirectexit('action=admin;area=featuresettings;sa=profile');
  1943. }
  1944. createToken('admin-ecp');
  1945. }
  1946. /**
  1947. * Allow to edit the settings on the pruning screen.
  1948. * @param $return_config
  1949. */
  1950. function ModifyPruningSettings($return_config = false)
  1951. {
  1952. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  1953. // Make sure we understand what's going on.
  1954. loadLanguage('ManageSettings');
  1955. $context['page_title'] = $txt['pruning_title'];
  1956. $config_vars = array(
  1957. // Even do the pruning?
  1958. // The array indexes are there so we can remove/change them before saving.
  1959. 'pruningOptions' => array('check', 'pruningOptions'),
  1960. '',
  1961. // Various logs that could be pruned.
  1962. array('int', 'pruneErrorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Error log.
  1963. array('int', 'pruneModLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Moderation log.
  1964. array('int', 'pruneBanLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Ban hit log.
  1965. array('int', 'pruneReportLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Report to moderator log.
  1966. array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1967. array('int', 'pruneBadbehaviorLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Bad Behavior log.
  1968. array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word'], 'subtext' => $txt['zero_to_disable']), // Log of the scheduled tasks and how long they ran.
  1969. // If you add any additional logs make sure to add them after this point. Additionally, make sure you add them to the weekly scheduled task.
  1970. // Mod Developers: Do NOT use the pruningOptions master variable for this as the Core may overwrite your setting in the future!
  1971. );
  1972. call_integration_hook('integrate_prune_settings', array($config_vars));
  1973. if ($return_config)
  1974. return $config_vars;
  1975. // We'll need this in a bit.
  1976. require_once(ADMINDIR . '/ManageServer.php');
  1977. // Saving?
  1978. if (isset($_GET['save']))
  1979. {
  1980. checkSession();
  1981. $savevar = array(
  1982. array('text', 'pruningOptions')
  1983. );
  1984. if (!empty($_POST['pruningOptions']))
  1985. {
  1986. $vals = array();
  1987. foreach ($config_vars as $index => $dummy)
  1988. {
  1989. if (!is_array($dummy) || $index == 'pruningOptions')
  1990. continue;
  1991. $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]];
  1992. }
  1993. $_POST['pruningOptions'] = implode(',', $vals);
  1994. }
  1995. else
  1996. $_POST['pruningOptions'] = '';
  1997. saveDBSettings($savevar);
  1998. redirectexit('action=admin;area=logs;sa=pruning');
  1999. }
  2000. $context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=pruning';
  2001. $context['settings_title'] = $txt['pruning_title'];
  2002. $context['sub_template'] = 'show_settings';
  2003. // Get the actual values
  2004. if (!empty($modSettings['pruningOptions']))
  2005. @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneBadbehaviorLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']);
  2006. else
  2007. $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneBadbehaviorLog'] = $modSettings['pruneSpiderHitLog'] = 0;
  2008. prepareDBSettingContext($config_vars);
  2009. }
  2010. /**
  2011. * If you have a general mod setting to add stick it here.
  2012. *
  2013. * @param $return_config
  2014. */
  2015. function ModifyGeneralModSettings($return_config = false)
  2016. {
  2017. global $txt, $scripturl, $context, $settings, $sc, $modSettings;
  2018. $config_vars = array(
  2019. // Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
  2020. );
  2021. // Make it even easier to add new settings.
  2022. call_integration_hook('integrate_general_mod_settings', array(&$config_vars));
  2023. if ($return_config)
  2024. return $config_vars;
  2025. $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general';
  2026. $context['settings_title'] = $txt['mods_cat_modifications_misc'];
  2027. // No removing this line you, dirty unwashed mod authors. :p
  2028. if (empty($config_vars))
  2029. {
  2030. $context['settings_save_dont_show'] = true;
  2031. $context['settings_message'] = '<div class="centertext">' . $txt['modification_no_misc_settings'] . '</div>';
  2032. return prepareDBSettingContext($config_vars);
  2033. }
  2034. // Saving?
  2035. if (isset($_GET['save']))
  2036. {
  2037. checkSession();
  2038. $save_vars = $config_vars;
  2039. call_integration_hook('integrate_save_general_mod_settings', array($save_vars));
  2040. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
  2041. saveDBSettings($save_vars);
  2042. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
  2043. redirectexit('action=admin;area=modsettings;sa=general');
  2044. }
  2045. // This line is to help mod authors do a search/add after if you want to add something here. Keyword: RED INK IS FOR TEACHERS AND THOSE WHO LIKE PAIN!
  2046. prepareDBSettingContext($config_vars);
  2047. }
  2048. /**
  2049. * Generates a list of integration hooks for display
  2050. * Accessed through ?action=admin;area=modsettings;sa=hooks;
  2051. * Allows for removal or disabing of selected hooks
  2052. */
  2053. function list_integration_hooks()
  2054. {
  2055. global $scripturl, $context, $txt, $modSettings, $settings;
  2056. $context['filter_url'] = '';
  2057. $context['current_filter'] = '';
  2058. $currentHooks = get_integration_hooks();
  2059. if (isset($_GET['filter']) && in_array($_GET['filter'], array_keys($currentHooks)))
  2060. {
  2061. $context['filter_url'] = ';filter=' . $_GET['filter'];
  2062. $context['current_filter'] = $_GET['filter'];
  2063. }
  2064. if (!empty($modSettings['handlinghooks_enabled']))
  2065. {
  2066. if (!empty($_REQUEST['do']) && isset($_REQUEST['hook']) && isset($_REQUEST['function']))
  2067. {
  2068. checkSession('request');
  2069. validateToken('admin-hook', 'request');
  2070. if ($_REQUEST['do'] == 'remove')
  2071. remove_integration_function($_REQUEST['hook'], urldecode($_REQUEST['function']));
  2072. else
  2073. {
  2074. if ($_REQUEST['do'] == 'disable')
  2075. {
  2076. // It's a hack I know...but I'm way too lazy!!!
  2077. $function_remove = $_REQUEST['function'];
  2078. $function_add = $_REQUEST['function'] . ']';
  2079. }
  2080. else
  2081. {
  2082. $function_remove = $_REQUEST['function'] . ']';
  2083. $function_add = $_REQUEST['function'];
  2084. }
  2085. $file = !empty($_REQUEST['includedfile']) ? urldecode($_REQUEST['includedfile']) : '';
  2086. remove_integration_function($_REQUEST['hook'], $function_remove, $file);
  2087. add_integration_function($_REQUEST['hook'], $function_add, $file);
  2088. redirectexit('action=admin;area=modsettings;sa=hooks' . $context['filter_url']);
  2089. }
  2090. }
  2091. }
  2092. $list_options = array(
  2093. 'id' => 'list_integration_hooks',
  2094. 'title' => $txt['hooks_title_list'],
  2095. 'items_per_page' => 20,
  2096. 'base_href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  2097. 'default_sort_col' => 'hook_name',
  2098. 'get_items' => array(
  2099. 'function' => 'get_integration_hooks_data',
  2100. ),
  2101. 'get_count' => array(
  2102. 'function' => 'get_integration_hooks_count',
  2103. ),
  2104. 'no_items_label' => $txt['hooks_no_hooks'],
  2105. 'columns' => array(
  2106. 'hook_name' => array(
  2107. 'header' => array(
  2108. 'value' => $txt['hooks_field_hook_name'],
  2109. ),
  2110. 'data' => array(
  2111. 'db' => 'hook_name',
  2112. ),
  2113. 'sort' => array(
  2114. 'default' => 'hook_name',
  2115. 'reverse' => 'hook_name DESC',
  2116. ),
  2117. ),
  2118. 'function_name' => array(
  2119. 'header' => array(
  2120. 'value' => $txt['hooks_field_function_name'],
  2121. ),
  2122. 'data' => array(
  2123. 'function' => create_function('$data', '
  2124. global $txt;
  2125. if (!empty($data[\'included_file\']))
  2126. return $txt[\'hooks_field_function\'] . \': \' . $data[\'real_function\'] . \'<br />\' . $txt[\'hooks_field_included_file\'] . \': \' . $data[\'included_file\'];
  2127. else
  2128. return $data[\'real_function\'];
  2129. '),
  2130. ),
  2131. 'sort' => array(
  2132. 'default' => 'function_name',
  2133. 'reverse' => 'function_name DESC',
  2134. ),
  2135. ),
  2136. 'file_name' => array(
  2137. 'header' => array(
  2138. 'value' => $txt['hooks_field_file_name'],
  2139. ),
  2140. 'data' => array(
  2141. 'db' => 'file_name',
  2142. ),
  2143. 'sort' => array(
  2144. 'default' => 'file_name',
  2145. 'reverse' => 'file_name DESC',
  2146. ),
  2147. ),
  2148. 'status' => array(
  2149. 'header' => array(
  2150. 'value' => $txt['hooks_field_hook_exists'],
  2151. 'style' => 'width:3%;',
  2152. ),
  2153. 'data' => array(
  2154. 'function' => create_function('$data', '
  2155. global $txt, $settings, $scripturl, $context;
  2156. $change_status = array(\'before\' => \'\', \'after\' => \'\');
  2157. if ($data[\'can_be_disabled\'] && $data[\'status\'] != \'deny\')
  2158. {
  2159. $change_status[\'before\'] = \'<a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=\' . ($data[\'enabled\'] ? \'disable\' : \'enable\') . \';hook=\' . $data[\'hook_name\'] . \';function=\' . $data[\'real_function\'] . (!empty($data[\'included_file\']) ? \';includedfile=\' . urlencode($data[\'included_file\']) : \'\') . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">\';
  2160. $change_status[\'after\'] = \'</a>\';
  2161. }
  2162. return $change_status[\'before\'] . \'<img src="\' . $settings[\'images_url\'] . \'/admin/post_moderation_\' . $data[\'status\'] . \'.png" alt="\' . $data[\'img_text\'] . \'" title="\' . $data[\'img_text\'] . \'" />\' . $change_status[\'after\'];
  2163. '),
  2164. 'class' => 'centertext',
  2165. ),
  2166. 'sort' => array(
  2167. 'default' => 'status',
  2168. 'reverse' => 'status DESC',
  2169. ),
  2170. ),
  2171. ),
  2172. 'additional_rows' => array(
  2173. array(
  2174. 'position' => 'after_title',
  2175. 'value' => $txt['hooks_disable_instructions'] . '<br />
  2176. ' . $txt['hooks_disable_legend'] . ':
  2177. <ul style="list-style: none;">
  2178. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_allow.png" alt="' . $txt['hooks_active'] . '" title="' . $txt['hooks_active'] . '" /> ' . $txt['hooks_disable_legend_exists'] . '</li>
  2179. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_moderate.png" alt="' . $txt['hooks_disabled'] . '" title="' . $txt['hooks_disabled'] . '" /> ' . $txt['hooks_disable_legend_disabled'] . '</li>
  2180. <li><img src="' . $settings['images_url'] . '/admin/post_moderation_deny.png" alt="' . $txt['hooks_missing'] . '" title="' . $txt['hooks_missing'] . '" /> ' . $txt['hooks_disable_legend_missing'] . '</li>
  2181. </ul>'
  2182. ),
  2183. ),
  2184. );
  2185. if (!empty($modSettings['handlinghooks_enabled']))
  2186. {
  2187. createToken('admin-hook', 'request');
  2188. $list_options['columns']['remove'] = array(
  2189. 'header' => array(
  2190. 'value' => $txt['hooks_button_remove'],
  2191. 'style' => 'width:3%',
  2192. ),
  2193. 'data' => array(
  2194. 'function' => create_function('$data', '
  2195. global $txt, $settings, $scripturl, $context;
  2196. if (!$data[\'hook_exists\'])
  2197. return \'
  2198. <a href="\' . $scripturl . \'?action=admin;area=modsettings;sa=hooks;do=remove;hook=\' . $data[\'hook_name\'] . \';function=\' . urlencode($data[\'function_name\']) . $context[\'filter_url\'] . \';\' . $context[\'admin-hook_token_var\'] . \'=\' . $context[\'admin-hook_token\'] . \';\' . $context[\'session_var\'] . \'=\' . $context[\'session_id\'] . \'" onclick="return confirm(\' . javaScriptEscape($txt[\'quickmod_confirm\']) . \');">
  2199. <img src="\' . $settings[\'images_url\'] . \'/icons/quick_remove.png" alt="\' . $txt[\'hooks_button_remove\'] . \'" title="\' . $txt[\'hooks_button_remove\'] . \'" />
  2200. </a>\';
  2201. '),
  2202. 'class' => 'centertext',
  2203. ),
  2204. );
  2205. $list_options['form'] = array(
  2206. 'href' => $scripturl . '?action=admin;area=modsettings;sa=hooks' . $context['filter_url'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  2207. 'name' => 'list_integration_hooks',
  2208. );
  2209. }
  2210. require_once(SUBSDIR . '/List.subs.php');
  2211. createList($list_options);
  2212. $context['page_title'] = $txt['hooks_title_list'];
  2213. $context['sub_template'] = 'show_list';
  2214. $context['default_list'] = 'list_integration_hooks';
  2215. }
  2216. /**
  2217. * Gets all of the files in a directory and its chidren directories
  2218. *
  2219. * @param type $dir_path
  2220. * @return array
  2221. */
  2222. function get_files_recursive($dir_path)
  2223. {
  2224. $files = array();
  2225. if ($dh = opendir($dir_path))
  2226. {
  2227. while (($file = readdir($dh)) !== false)
  2228. {
  2229. if ($file != '.' && $file != '..')
  2230. {
  2231. if (is_dir($dir_path . '/' . $file))
  2232. $files = array_merge($files, get_files_recursive($dir_path . '/' . $file));
  2233. else
  2234. $files[] = array('dir' => $dir_path, 'name' => $file);
  2235. }
  2236. }
  2237. }
  2238. closedir($dh);
  2239. return $files;
  2240. }
  2241. /**
  2242. * Callback function for the integration hooks list (list_integration_hooks)
  2243. * Gets all of the hooks in the system and their status
  2244. * Would be better documented if Ema was not lazy
  2245. *
  2246. * @param type $start
  2247. * @param type $per_page
  2248. * @param type $sort
  2249. * @return array
  2250. */
  2251. function get_integration_hooks_data($start, $per_page, $sort)
  2252. {
  2253. global $settings, $txt, $context, $scripturl, $modSettings;
  2254. $hooks = $temp_hooks = get_integration_hooks();
  2255. $hooks_data = $temp_data = $hook_status = array();
  2256. $files = get_files_recursive(SOURCEDIR);
  2257. if (!empty($files))
  2258. {
  2259. foreach ($files as $file)
  2260. {
  2261. if (is_file($file['dir'] . '/' . $file['name']) && substr($file['name'], -4) === '.php')
  2262. {
  2263. $fp = fopen($file['dir'] . '/' . $file['name'], 'rb');
  2264. $fc = fread($fp, filesize($file['dir'] . '/' . $file['name']));
  2265. fclose($fp);
  2266. foreach ($temp_hooks as $hook => $functions)
  2267. {
  2268. foreach ($functions as $function_o)
  2269. {
  2270. $hook_name = str_replace(']', '', $function_o);
  2271. if (strpos($hook_name, '::') !== false)
  2272. {
  2273. $function = explode('::', $hook_name);
  2274. $function = $function[1];
  2275. }
  2276. else
  2277. $function = $hook_name;
  2278. $function = explode(':', $function);
  2279. $function = $function[0];
  2280. if (substr($hook, -8) === '_include')
  2281. {
  2282. $hook_status[$hook][$function]['exists'] = file_exists(strtr(trim($function), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])));
  2283. // I need to know if there is at least one function called in this file.
  2284. $temp_data['include'][basename($function)] = array('hook' => $hook, 'function' => $function);
  2285. unset($temp_hooks[$hook][$function_o]);
  2286. }
  2287. elseif (strpos(str_replace(' (', '(', $fc), 'function ' . trim($function) . '(') !== false)
  2288. {
  2289. $hook_status[$hook][$hook_name]['exists'] = true;
  2290. $hook_status[$hook][$hook_name]['in_file'] = $file['name'];
  2291. // I want to remember all the functions called within this file (to check later if they are enabled or disabled and decide if the integrare_*_include of that file can be disabled too)
  2292. $temp_data['function'][$file['name']][] = $function_o;
  2293. unset($temp_hooks[$hook][$function_o]);
  2294. }
  2295. }
  2296. }
  2297. }
  2298. }
  2299. }
  2300. $sort_types = array(
  2301. 'hook_name' => array('hook', SORT_ASC),
  2302. 'hook_name DESC' => array('hook', SORT_DESC),
  2303. 'function_name' => array('function', SORT_ASC),
  2304. 'function_name DESC' => array('function', SORT_DESC),
  2305. 'file_name' => array('file_name', SORT_ASC),
  2306. 'file_name DESC' => array('file_name', SORT_DESC),
  2307. 'status' => array('status', SORT_ASC),
  2308. 'status DESC' => array('status', SORT_DESC),
  2309. );
  2310. $sort_options = $sort_types[$sort];
  2311. $sort = array();
  2312. $hooks_filters = array();
  2313. foreach ($hooks as $hook => $functions)
  2314. {
  2315. $hooks_filters[] = '<option ' . ($context['current_filter'] == $hook ? 'selected="selected" ' : '') . 'onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks;filter=' . $hook . '\';">' . $hook . '</option>';
  2316. foreach ($functions as $function)
  2317. {
  2318. $enabled = strstr($function, ']') === false;
  2319. $function = str_replace(']', '', $function);
  2320. // This is a not an include and the function is included in a certain file (if not it doesn't exists so don't care)
  2321. if (substr($hook, -8) !== '_include' && isset($hook_status[$hook][$function]['in_file']))
  2322. {
  2323. $current_hook = isset($temp_data['include'][$hook_status[$hook][$function]['in_file']]) ? $temp_data['include'][$hook_status[$hook][$function]['in_file']] : '';
  2324. $enabled = false;
  2325. // Checking all the functions within this particular file
  2326. // if any of them is enable then the file *must* be included and the integrate_*_include hook cannot be disabled
  2327. foreach ($temp_data['function'][$hook_status[$hook][$function]['in_file']] as $func)
  2328. $enabled = $enabled || strstr($func, ']') !== false;
  2329. if (!$enabled && !empty($current_hook))
  2330. $hook_status[$current_hook['hook']][$current_hook['function']]['enabled'] = true;
  2331. }
  2332. }
  2333. }
  2334. if (!empty($hooks_filters))
  2335. addInlineJavascript('
  2336. var hook_name_header = document.getElementById(\'header_list_integration_hooks_hook_name\');
  2337. hook_name_header.innerHTML += ' . JavaScriptEscape('
  2338. <select style="margin-left:15px;">
  2339. <option>---</option>
  2340. <option onclick="window.location = \'' . $scripturl . '?action=admin;area=modsettings;sa=hooks\';">' . $txt['hooks_reset_filter'] . '</option>' . implode('', $hooks_filters) . '
  2341. </select>'). ';', true);
  2342. $temp_data = array();
  2343. $id = 0;
  2344. foreach ($hooks as $hook => $functions)
  2345. {
  2346. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2347. {
  2348. foreach ($functions as $function)
  2349. {
  2350. $enabled = strstr($function, ']') === false;
  2351. $function = str_replace(']', '', $function);
  2352. $hook_exists = !empty($hook_status[$hook][$function]['exists']);
  2353. $file_name = isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ((substr($hook, -8) === '_include') ? 'zzzzzzzzz' : 'zzzzzzzza');
  2354. $sort[] = $$sort_options[0];
  2355. if (strpos($function, '::') !== false)
  2356. {
  2357. $function = explode('::', $function);
  2358. $function = $function[1];
  2359. }
  2360. $exploded = explode(':', $function);
  2361. $temp_data[] = array(
  2362. 'id' => 'hookid_' . $id++,
  2363. 'hook_name' => $hook,
  2364. 'function_name' => $function,
  2365. 'real_function' => $exploded[0],
  2366. 'included_file' => isset($exploded[1]) ? strtr(trim($exploded[1]), array('BOARDDIR' => BOARDDIR, 'SOURCEDIR' => SOURCEDIR, '$themedir' => $settings['theme_dir'])) : '',
  2367. 'file_name' => (isset($hook_status[$hook][$function]['in_file']) ? $hook_status[$hook][$function]['in_file'] : ''),
  2368. 'hook_exists' => $hook_exists,
  2369. 'status' => $hook_exists ? ($enabled ? 'allow' : 'moderate') : 'deny',
  2370. 'img_text' => $txt['hooks_' . ($hook_exists ? ($enabled ? 'active' : 'disabled') : 'missing')],
  2371. 'enabled' => $enabled,
  2372. 'can_be_disabled' => !empty($modSettings['handlinghooks_enabled']) && !isset($hook_status[$hook][$function]['enabled']),
  2373. );
  2374. }
  2375. }
  2376. }
  2377. array_multisort($sort, $sort_options[1], $temp_data);
  2378. $counter = 0;
  2379. $start++;
  2380. foreach ($temp_data as $data)
  2381. {
  2382. if (++$counter < $start)
  2383. continue;
  2384. elseif ($counter == $start + $per_page)
  2385. break;
  2386. $hooks_data[] = $data;
  2387. }
  2388. return $hooks_data;
  2389. }
  2390. /**
  2391. * Simply returns the total count of integraion hooks
  2392. * Used but the intergation hooks list function (list_integration_hooks)
  2393. *
  2394. * @global type $context
  2395. * @return int
  2396. */
  2397. function get_integration_hooks_count()
  2398. {
  2399. global $context;
  2400. $hooks = get_integration_hooks();
  2401. $hooks_count = 0;
  2402. $context['filter'] = false;
  2403. if (isset($_GET['filter']))
  2404. $context['filter'] = $_GET['filter'];
  2405. foreach ($hooks as $hook => $functions)
  2406. {
  2407. if (empty($context['filter']) || (!empty($context['filter']) && $context['filter'] == $hook))
  2408. $hooks_count += count($functions);
  2409. }
  2410. return $hooks_count;
  2411. }
  2412. /**
  2413. * Parses modSettings to create integration hook array
  2414. *
  2415. * @staticvar type $integration_hooks
  2416. * @return type
  2417. */
  2418. function get_integration_hooks()
  2419. {
  2420. global $modSettings;
  2421. static $integration_hooks;
  2422. if (!isset($integration_hooks))
  2423. {
  2424. $integration_hooks = array();
  2425. foreach ($modSettings as $key => $value)
  2426. {
  2427. if (!empty($value) && substr($key, 0, 10) === 'integrate_')
  2428. $integration_hooks[$key] = explode(',', $value);
  2429. }
  2430. }
  2431. return $integration_hooks;
  2432. }