PageRenderTime 72ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/php/Sources/ManageSettings.php

https://github.com/dekoza/openshift-smf-2.0.7
PHP | 2059 lines | 1556 code | 235 blank | 268 comment | 236 complexity | b0c94110c4bfa4596d68aa889eb459b6 MD5 | raw file
Possible License(s): BSD-3-Clause

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

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

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