Chris@76: 'ModifyBasicSettings', Chris@76: 'layout' => 'ModifyLayoutSettings', Chris@76: 'karma' => 'ModifyKarmaSettings', Chris@76: 'sig' => 'ModifySignatureSettings', Chris@76: 'profile' => 'ShowCustomProfiles', Chris@76: 'profileedit' => 'EditCustomProfiles', Chris@76: ); Chris@76: Chris@76: loadGeneralSettingParameters($subActions, 'basic'); Chris@76: Chris@76: // Load up all the tabs... Chris@76: $context[$context['admin_menu_name']]['tab_data'] = array( Chris@76: 'title' => $txt['modSettings_title'], Chris@76: 'help' => 'featuresettings', Chris@76: 'description' => sprintf($txt['modSettings_desc'], $settings['theme_id'], $context['session_id'], $context['session_var']), Chris@76: 'tabs' => array( Chris@76: 'basic' => array( Chris@76: ), Chris@76: 'layout' => array( Chris@76: ), Chris@76: 'karma' => array( Chris@76: ), Chris@76: 'sig' => array( Chris@76: 'description' => $txt['signature_settings_desc'], Chris@76: ), Chris@76: 'profile' => array( Chris@76: 'description' => $txt['custom_profile_desc'], Chris@76: ), Chris@76: ), Chris@76: ); Chris@76: Chris@76: // Call the right function for this sub-acton. Chris@76: $subActions[$_REQUEST['sa']](); Chris@76: } Chris@76: Chris@76: // This function passes control through to the relevant security tab. Chris@76: function ModifySecuritySettings() Chris@76: { Chris@76: global $context, $txt, $scripturl, $modSettings, $settings; Chris@76: Chris@76: $context['page_title'] = $txt['admin_security_moderation']; Chris@76: Chris@76: $subActions = array( Chris@76: 'general' => 'ModifyGeneralSecuritySettings', Chris@76: 'spam' => 'ModifySpamSettings', Chris@76: 'moderation' => 'ModifyModerationSettings', Chris@76: ); Chris@76: Chris@76: loadGeneralSettingParameters($subActions, 'general'); Chris@76: Chris@76: // Load up all the tabs... Chris@76: $context[$context['admin_menu_name']]['tab_data'] = array( Chris@76: 'title' => $txt['admin_security_moderation'], Chris@76: 'help' => 'securitysettings', Chris@76: 'description' => $txt['security_settings_desc'], Chris@76: 'tabs' => array( Chris@76: 'general' => array( Chris@76: ), Chris@76: 'spam' => array( Chris@76: 'description' => $txt['antispam_Settings_desc'] , Chris@76: ), Chris@76: 'moderation' => array( Chris@76: ), Chris@76: ), Chris@76: ); Chris@76: Chris@76: // Call the right function for this sub-acton. Chris@76: $subActions[$_REQUEST['sa']](); Chris@76: } Chris@76: Chris@76: // 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 Chris@76: function ModifyModSettings() Chris@76: { Chris@76: global $context, $txt, $scripturl, $modSettings, $settings; Chris@76: Chris@76: $context['page_title'] = $txt['admin_modifications']; Chris@76: Chris@76: $subActions = array( Chris@76: 'general' => 'ModifyGeneralModSettings', Chris@76: // Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end. Chris@76: ); Chris@76: Chris@76: // Make it easier for mods to add new areas. Chris@76: call_integration_hook('integrate_modify_modifications', array(&$subActions)); Chris@76: Chris@76: loadGeneralSettingParameters($subActions, 'general'); Chris@76: Chris@76: // Load up all the tabs... Chris@76: $context[$context['admin_menu_name']]['tab_data'] = array( Chris@76: 'title' => $txt['admin_modifications'], Chris@76: 'help' => 'modsettings', Chris@76: 'description' => $txt['modification_settings_desc'], Chris@76: 'tabs' => array( Chris@76: 'general' => array( Chris@76: ), Chris@76: ), Chris@76: ); Chris@76: Chris@76: // Call the right function for this sub-acton. Chris@76: $subActions[$_REQUEST['sa']](); Chris@76: } Chris@76: Chris@76: // This is an overall control panel enabling/disabling lots of SMF's key feature components. Chris@76: function ModifyCoreFeatures($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: /* This is an array of all the features that can be enabled/disabled - each option can have the following: Chris@76: title - Text title of this item (If standard string does not exist). Chris@76: desc - Description of this feature (If standard string does not exist). Chris@76: image - Custom image to show next to feature. Chris@76: 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. Chris@76: setting_callback- Function that returns an array of settings to save - takes one parameter which is value for this feature. Chris@76: save_callback - Function called on save, takes state as parameter. Chris@76: */ Chris@76: $core_features = array( Chris@76: // cd = calendar. Chris@76: 'cd' => array( Chris@76: 'url' => 'action=admin;area=managecalendar', Chris@76: 'settings' => array( Chris@76: 'cal_enabled' => 1, Chris@76: ), Chris@76: ), Chris@76: // cp = custom profile fields. Chris@76: 'cp' => array( Chris@76: 'url' => 'action=admin;area=featuresettings;sa=profile', Chris@76: 'save_callback' => create_function('$value', ' Chris@76: global $smcFunc; Chris@76: if (!$value) Chris@76: { Chris@76: $smcFunc[\'db_query\'](\'\', \' Chris@76: UPDATE {db_prefix}custom_fields Chris@76: SET active = 0\'); Chris@76: } Chris@76: '), Chris@76: 'setting_callback' => create_function('$value', ' Chris@76: if (!$value) Chris@76: return array( Chris@76: \'disabled_profile_fields\' => \'\', Chris@76: \'registration_fields\' => \'\', Chris@76: \'displayFields\' => \'\', Chris@76: ); Chris@76: else Chris@76: return array(); Chris@76: '), Chris@76: ), Chris@76: // k = karma. Chris@76: 'k' => array( Chris@76: 'url' => 'action=admin;area=featuresettings;sa=karma', Chris@76: 'settings' => array( Chris@76: 'karmaMode' => 2, Chris@76: ), Chris@76: ), Chris@76: // ml = moderation log. Chris@76: 'ml' => array( Chris@76: 'url' => 'action=admin;area=logs;sa=modlog', Chris@76: 'settings' => array( Chris@76: 'modlog_enabled' => 1, Chris@76: ), Chris@76: ), Chris@76: // pm = post moderation. Chris@76: 'pm' => array( Chris@76: 'url' => 'action=admin;area=permissions;sa=postmod', Chris@76: 'setting_callback' => create_function('$value', ' Chris@76: global $sourcedir; Chris@76: Chris@76: // Cant use warning post moderation if disabled! Chris@76: if (!$value) Chris@76: { Chris@76: require_once($sourcedir . \'/PostModeration.php\'); Chris@76: approveAllData(); Chris@76: Chris@76: return array(\'warning_moderate\' => 0); Chris@76: } Chris@76: else Chris@76: return array(); Chris@76: '), Chris@76: ), Chris@76: // ps = Paid Subscriptions. Chris@76: 'ps' => array( Chris@76: 'url' => 'action=admin;area=paidsubscribe', Chris@76: 'settings' => array( Chris@76: 'paid_enabled' => 1, Chris@76: ), Chris@76: 'setting_callback' => create_function('$value', ' Chris@76: global $smcFunc, $sourcedir; Chris@76: Chris@76: // Set the correct disabled value for scheduled task. Chris@76: $smcFunc[\'db_query\'](\'\', \' Chris@76: UPDATE {db_prefix}scheduled_tasks Chris@76: SET disabled = {int:disabled} Chris@76: WHERE task = {string:task}\', Chris@76: array( Chris@76: \'disabled\' => $value ? 0 : 1, Chris@76: \'task\' => \'paid_subscriptions\', Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Should we calculate next trigger? Chris@76: if ($value) Chris@76: { Chris@76: require_once($sourcedir . \'/ScheduledTasks.php\'); Chris@76: CalculateNextTrigger(\'paid_subscriptions\'); Chris@76: } Chris@76: '), Chris@76: ), Chris@76: // rg = report generator. Chris@76: 'rg' => array( Chris@76: 'url' => 'action=admin;area=reports', Chris@76: ), Chris@76: // w = warning. Chris@76: 'w' => array( Chris@76: 'url' => 'action=admin;area=securitysettings;sa=moderation', Chris@76: 'setting_callback' => create_function('$value', ' Chris@76: global $modSettings; Chris@76: list ($modSettings[\'warning_enable\'], $modSettings[\'user_limit\'], $modSettings[\'warning_decrement\']) = explode(\',\', $modSettings[\'warning_settings\']); Chris@76: $warning_settings = ($value ? 1 : 0) . \',\' . $modSettings[\'user_limit\'] . \',\' . $modSettings[\'warning_decrement\']; Chris@76: if (!$value) Chris@76: { Chris@76: $returnSettings = array( Chris@76: \'warning_watch\' => 0, Chris@76: \'warning_moderate\' => 0, Chris@76: \'warning_mute\' => 0, Chris@76: ); Chris@76: } Chris@76: elseif (empty($modSettings[\'warning_enable\']) && $value) Chris@76: { Chris@76: $returnSettings = array( Chris@76: \'warning_watch\' => 10, Chris@76: \'warning_moderate\' => 35, Chris@76: \'warning_mute\' => 60, Chris@76: ); Chris@76: } Chris@76: else Chris@76: $returnSettings = array(); Chris@76: Chris@76: $returnSettings[\'warning_settings\'] = $warning_settings; Chris@76: return $returnSettings; Chris@76: '), Chris@76: ), Chris@76: // Search engines Chris@76: 'sp' => array( Chris@76: 'url' => 'action=admin;area=sengines', Chris@76: 'settings' => array( Chris@76: 'spider_mode' => 1, Chris@76: ), Chris@76: 'setting_callback' => create_function('$value', ' Chris@76: // Turn off the spider group if disabling. Chris@76: if (!$value) Chris@76: return array(\'spider_group\' => 0, \'show_spider_online\' => 0); Chris@76: '), Chris@76: 'on_save' => create_function('', ' Chris@76: global $sourcedir, $modSettings; Chris@76: require_once($sourcedir . \'/ManageSearchEngines.php\'); Chris@76: recacheSpiderNames(); Chris@76: '), Chris@76: ), Chris@76: ); Chris@76: Chris@76: // Anyone who would like to add a core feature? Chris@76: call_integration_hook('integrate_core_features', array(&$core_features)); Chris@76: Chris@76: // Are we getting info for the help section. Chris@76: if ($return_config) Chris@76: { Chris@76: $return_data = array(); Chris@76: foreach ($core_features as $id => $data) Chris@76: $return_data[] = array('switch', isset($data['title']) ? $data['title'] : $txt['core_settings_item_' . $id]); Chris@76: return $return_data; Chris@76: } Chris@76: Chris@76: loadGeneralSettingParameters(); Chris@76: Chris@76: // Are we saving? Chris@76: if (isset($_POST['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: $setting_changes = array('admin_features' => array()); Chris@76: Chris@76: // Are we using the javascript stuff or radios to submit? Chris@76: $post_var_prefix = empty($_POST['js_worked']) ? 'feature_plain_' : 'feature_'; Chris@76: Chris@76: // Cycle each feature and change things as required! Chris@76: foreach ($core_features as $id => $feature) Chris@76: { Chris@76: // Enabled? Chris@76: if (!empty($_POST[$post_var_prefix . $id])) Chris@76: $setting_changes['admin_features'][] = $id; Chris@76: Chris@76: // Setting values to change? Chris@76: if (isset($feature['settings'])) Chris@76: { Chris@76: foreach ($feature['settings'] as $key => $value) Chris@76: { Chris@76: if (empty($_POST[$post_var_prefix . $id]) || (!empty($_POST[$post_var_prefix . $id]) && ($value < 2 || empty($modSettings[$key])))) Chris@76: $setting_changes[$key] = !empty($_POST[$post_var_prefix . $id]) ? $value : !$value; Chris@76: } Chris@76: } Chris@76: // Is there a call back for settings? Chris@76: if (isset($feature['setting_callback'])) Chris@76: { Chris@76: $returned_settings = $feature['setting_callback'](!empty($_POST[$post_var_prefix . $id])); Chris@76: if (!empty($returned_settings)) Chris@76: $setting_changes = array_merge($setting_changes, $returned_settings); Chris@76: } Chris@76: Chris@76: // Standard save callback? Chris@76: if (isset($feature['on_save'])) Chris@76: $feature['on_save'](); Chris@76: } Chris@76: Chris@76: // Make sure this one setting is a string! Chris@76: $setting_changes['admin_features'] = implode(',', $setting_changes['admin_features']); Chris@76: Chris@76: // Make any setting changes! Chris@76: updateSettings($setting_changes); Chris@76: Chris@76: // Any post save things? Chris@76: foreach ($core_features as $id => $feature) Chris@76: { Chris@76: // Standard save callback? Chris@76: if (isset($feature['save_callback'])) Chris@76: $feature['save_callback'](!empty($_POST[$post_var_prefix . $id])); Chris@76: } Chris@76: Chris@76: redirectexit('action=admin;area=corefeatures;' . $context['session_var'] . '=' . $context['session_id']); Chris@76: } Chris@76: Chris@76: // Put them in context. Chris@76: $context['features'] = array(); Chris@76: foreach ($core_features as $id => $feature) Chris@76: $context['features'][$id] = array( Chris@76: 'title' => isset($feature['title']) ? $feature['title'] : $txt['core_settings_item_' . $id], Chris@76: 'desc' => isset($feature['desc']) ? $feature['desc'] : $txt['core_settings_item_' . $id . '_desc'], Chris@76: 'enabled' => in_array($id, $context['admin_features']), Chris@76: 'url' => !empty($feature['url']) ? $scripturl . '?' . $feature['url'] . ';' . $context['session_var'] . '=' . $context['session_id'] : '', Chris@76: ); Chris@76: Chris@76: // Are they a new user? Chris@76: $context['is_new_install'] = !isset($modSettings['admin_features']); Chris@76: $context['force_disable_tabs'] = $context['is_new_install']; Chris@76: // Don't show them this twice! Chris@76: if ($context['is_new_install']) Chris@76: updateSettings(array('admin_features' => '')); Chris@76: Chris@76: $context['sub_template'] = 'core_features'; Chris@76: $context['page_title'] = $txt['core_settings_title']; Chris@76: } Chris@76: Chris@76: function ModifyBasicSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: $config_vars = array( Chris@76: // Big Options... polls, sticky, bbc.... Chris@76: array('select', 'pollMode', array($txt['disable_polls'], $txt['enable_polls'], $txt['polls_as_topics'])), Chris@76: '', Chris@76: // Basic stuff, titles, flash, permissions... Chris@76: array('check', 'allow_guestAccess'), Chris@76: array('check', 'enable_buddylist'), Chris@76: array('check', 'allow_editDisplayName'), Chris@76: array('check', 'allow_hideOnline'), Chris@76: array('check', 'titlesEnable'), Chris@76: array('text', 'default_personal_text'), Chris@76: '', Chris@76: // SEO stuff Chris@76: array('check', 'queryless_urls'), Chris@76: array('text', 'meta_keywords', 'size' => 50), Chris@76: '', Chris@76: // Number formatting, timezones. Chris@76: array('text', 'time_format'), Chris@76: 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')), Chris@76: array('float', 'time_offset'), Chris@76: 'default_timezone' => array('select', 'default_timezone', array()), Chris@76: '', Chris@76: // Who's online? Chris@76: array('check', 'who_enabled'), Chris@76: array('int', 'lastActive'), Chris@76: '', Chris@76: // Statistics. Chris@76: array('check', 'trackStats'), Chris@76: array('check', 'hitStats'), Chris@76: '', Chris@76: // Option-ish things... miscellaneous sorta. Chris@76: array('check', 'allow_disableAnnounce'), Chris@76: array('check', 'disallow_sendBody'), Chris@76: ); Chris@76: Chris@76: // Get all the time zones. Chris@76: if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set')) Chris@76: { Chris@76: $all_zones = timezone_identifiers_list(); Chris@76: // Make sure we set the value to the same as the printed value. Chris@76: foreach ($all_zones as $zone) Chris@76: $config_vars['default_timezone'][2][$zone] = $zone; Chris@76: } Chris@76: else Chris@76: unset($config_vars['default_timezone']); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Prevent absurd boundaries here - make it a day tops. Chris@76: if (isset($_POST['lastActive'])) Chris@76: $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); Chris@76: Chris@76: saveDBSettings($config_vars); Chris@76: Chris@76: writeLog(); Chris@76: redirectexit('action=admin;area=featuresettings;sa=basic'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=basic'; Chris@76: $context['settings_title'] = $txt['mods_cat_features']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // Settings really associated with general security aspects. Chris@76: function ModifyGeneralSecuritySettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: $config_vars = array( Chris@76: array('check', 'guest_hideContacts'), Chris@76: array('check', 'make_email_viewable'), Chris@76: '', Chris@76: array('int', 'failed_login_threshold'), Chris@76: '', Chris@76: array('check', 'enableErrorLogging'), Chris@76: array('check', 'enableErrorQueryLogging'), Chris@76: array('check', 'securityDisable'), Chris@76: '', Chris@76: // Reactive on email, and approve on delete Chris@76: array('check', 'send_validation_onChange'), Chris@76: array('check', 'approveAccountDeletion'), Chris@76: '', Chris@76: // Password strength. Chris@76: array('select', 'password_strength', array($txt['setting_password_strength_low'], $txt['setting_password_strength_medium'], $txt['setting_password_strength_high'])), Chris@76: '', Chris@76: // Reporting of personal messages? Chris@76: array('check', 'enableReportPM'), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: saveDBSettings($config_vars); Chris@76: Chris@76: writeLog(); Chris@76: redirectexit('action=admin;area=securitysettings;sa=general'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=general'; Chris@76: $context['settings_title'] = $txt['mods_cat_security_general']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: function ModifyLayoutSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc; Chris@76: Chris@76: $config_vars = array( Chris@76: // Pagination stuff. Chris@76: array('check', 'compactTopicPagesEnable'), Chris@76: array('int', 'compactTopicPagesContiguous', null, $txt['contiguous_page_display'] . '
' . str_replace(' ', ' ', '"3" ' . $txt['to_display'] . ': 1 ... 4 [5] 6 ... 9') . '
' . str_replace(' ', ' ', '"5" ' . $txt['to_display'] . ': 1 ... 3 4 [5] 6 7 ... 9') . '
'), Chris@76: array('int', 'defaultMaxMembers'), Chris@76: '', Chris@76: // Stuff that just is everywhere - today, search, online, etc. Chris@76: array('select', 'todayMod', array($txt['today_disabled'], $txt['today_only'], $txt['yesterday_today'])), Chris@76: array('check', 'topbottomEnable'), Chris@76: array('check', 'onlineEnable'), Chris@76: array('check', 'enableVBStyleLogin'), Chris@76: '', Chris@76: // Automagic image resizing. Chris@76: array('int', 'max_image_width'), Chris@76: array('int', 'max_image_height'), Chris@76: '', Chris@76: // This is like debugging sorta. Chris@76: array('check', 'timeLoadPageEnable'), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: saveDBSettings($config_vars); Chris@76: writeLog(); Chris@76: Chris@76: redirectexit('action=admin;area=featuresettings;sa=layout'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=layout'; Chris@76: $context['settings_title'] = $txt['mods_cat_layout']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: function ModifyKarmaSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc; Chris@76: Chris@76: $config_vars = array( Chris@76: // Karma - On or off? Chris@76: array('select', 'karmaMode', explode('|', $txt['karma_options'])), Chris@76: '', Chris@76: // Who can do it.... and who is restricted by time limits? Chris@76: array('int', 'karmaMinPosts'), Chris@76: array('float', 'karmaWaitTime'), Chris@76: array('check', 'karmaTimeRestrictAdmins'), Chris@76: '', Chris@76: // What does it look like? [smite]? Chris@76: array('text', 'karmaLabel'), Chris@76: array('text', 'karmaApplaudLabel'), Chris@76: array('text', 'karmaSmiteLabel'), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: saveDBSettings($config_vars); Chris@76: redirectexit('action=admin;area=featuresettings;sa=karma'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=karma'; Chris@76: $context['settings_title'] = $txt['karma']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // Moderation type settings - although there are fewer than we have you believe ;) Chris@76: function ModifyModerationSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: $config_vars = array( Chris@76: // Warning system? Chris@76: array('int', 'warning_watch', 'help' => 'warning_enable'), Chris@76: 'moderate' => array('int', 'warning_moderate'), Chris@76: array('int', 'warning_mute'), Chris@76: 'rem1' => array('int', 'user_limit'), Chris@76: 'rem2' => array('int', 'warning_decrement'), Chris@76: array('select', 'warning_show', array($txt['setting_warning_show_mods'], $txt['setting_warning_show_user'], $txt['setting_warning_show_all'])), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Cannot use moderation if post moderation is not enabled. Chris@76: if (!$modSettings['postmod_active']) Chris@76: unset($config_vars['moderate']); Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Make sure these don't have an effect. Chris@76: if (substr($modSettings['warning_settings'], 0, 1) != 1) Chris@76: { Chris@76: $_POST['warning_watch'] = 0; Chris@76: $_POST['warning_moderate'] = 0; Chris@76: $_POST['warning_mute'] = 0; Chris@76: } Chris@76: else Chris@76: { Chris@76: $_POST['warning_watch'] = min($_POST['warning_watch'], 100); Chris@76: $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0; Chris@76: $_POST['warning_mute'] = min($_POST['warning_mute'], 100); Chris@76: } Chris@76: Chris@76: // Fix the warning setting array! Chris@76: $_POST['warning_settings'] = '1,' . min(100, (int) $_POST['user_limit']) . ',' . min(100, (int) $_POST['warning_decrement']); Chris@76: $save_vars = $config_vars; Chris@76: $save_vars[] = array('text', 'warning_settings'); Chris@76: unset($save_vars['rem1'], $save_vars['rem2']); Chris@76: Chris@76: saveDBSettings($save_vars); Chris@76: redirectexit('action=admin;area=securitysettings;sa=moderation'); Chris@76: } Chris@76: Chris@76: // We actually store lots of these together - for efficiency. Chris@76: list ($modSettings['warning_enable'], $modSettings['user_limit'], $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']); Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=moderation'; Chris@76: $context['settings_title'] = $txt['moderation_settings']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // Let's try keep the spam to a minimum ah Thantos? Chris@76: function ModifySpamSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc; Chris@76: Chris@76: // Generate a sample registration image. Chris@76: $context['use_graphic_library'] = in_array('gd', get_loaded_extensions()); Chris@76: $context['verification_image_href'] = $scripturl . '?action=verificationcode;rand=' . md5(mt_rand()); Chris@76: Chris@76: $config_vars = array( Chris@76: array('check', 'reg_verification'), Chris@76: array('check', 'search_enable_captcha'), Chris@76: // This, my friend, is a cheat :p Chris@76: 'guest_verify' => array('check', 'guests_require_captcha', 'subtext' => $txt['setting_guests_require_captcha_desc']), Chris@76: 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;}'), Chris@76: array('check', 'guests_report_require_captcha'), Chris@76: '', Chris@76: // PM Settings Chris@76: 'pm1' => array('int', 'max_pm_recipients'), Chris@76: 'pm2' => array('int', 'pm_posts_verification'), Chris@76: 'pm3' => array('int', 'pm_posts_per_hour'), Chris@76: // Visual verification. Chris@76: array('title', 'configure_verification_means'), Chris@76: array('desc', 'configure_verification_means_desc'), Chris@76: '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();' : ''), Chris@76: array('int', 'qa_verification_number', 'subtext' => $txt['setting_qa_verification_number_desc']), Chris@76: // Clever Thomas, who is looking sheepy now? Not I, the mighty sword swinger did say. Chris@76: array('title', 'setup_verification_questions'), Chris@76: array('desc', 'setup_verification_questions_desc'), Chris@76: array('callback', 'question_answer_list'), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Load any question and answers! Chris@76: $context['question_answers'] = array(); Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_comment, body AS question, recipient_name AS answer Chris@76: FROM {db_prefix}log_comments Chris@76: WHERE comment_type = {string:ver_test}', Chris@76: array( Chris@76: 'ver_test' => 'ver_test', Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $context['question_answers'][$row['id_comment']] = array( Chris@76: 'id' => $row['id_comment'], Chris@76: 'question' => $row['question'], Chris@76: 'answer' => $row['answer'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Fix PM settings. Chris@76: $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour']; Chris@76: Chris@76: // Hack in guest requiring verification! Chris@76: if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) Chris@76: $_POST['posts_require_captcha'] = -1; Chris@76: Chris@76: $save_vars = $config_vars; Chris@76: unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']); Chris@76: Chris@76: $save_vars[] = array('text', 'pm_spam_settings'); Chris@76: Chris@76: // Handle verification questions. Chris@76: $questionInserts = array(); Chris@76: $count_questions = 0; Chris@76: foreach ($_POST['question'] as $id => $question) Chris@76: { Chris@76: $question = trim($smcFunc['htmlspecialchars']($question, ENT_COMPAT, $context['character_set'])); Chris@76: $answer = trim($smcFunc['strtolower']($smcFunc['htmlspecialchars']($_POST['answer'][$id], ENT_COMPAT, $context['character_set']))); Chris@76: Chris@76: // Already existed? Chris@76: if (isset($context['question_answers'][$id])) Chris@76: { Chris@76: $count_questions++; Chris@76: // Changed? Chris@76: if ($context['question_answers'][$id]['question'] != $question || $context['question_answers'][$id]['answer'] != $answer) Chris@76: { Chris@76: if ($question == '' || $answer == '') Chris@76: { Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}log_comments Chris@76: WHERE comment_type = {string:ver_test} Chris@76: AND id_comment = {int:id}', Chris@76: array( Chris@76: 'id' => $id, Chris@76: 'ver_test' => 'ver_test', Chris@76: ) Chris@76: ); Chris@76: $count_questions--; Chris@76: } Chris@76: else Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}log_comments Chris@76: SET body = {string:question}, recipient_name = {string:answer} Chris@76: WHERE comment_type = {string:ver_test} Chris@76: AND id_comment = {int:id}', Chris@76: array( Chris@76: 'id' => $id, Chris@76: 'ver_test' => 'ver_test', Chris@76: 'question' => $question, Chris@76: 'answer' => $answer, Chris@76: ) Chris@76: ); Chris@76: } Chris@76: } Chris@76: // It's so shiney and new! Chris@76: elseif ($question != '' && $answer != '') Chris@76: { Chris@76: $questionInserts[] = array( Chris@76: 'comment_type' => 'ver_test', Chris@76: 'body' => $question, Chris@76: 'recipient_name' => $answer, Chris@76: ); Chris@76: } Chris@76: } Chris@76: Chris@76: // Any questions to insert? Chris@76: if (!empty($questionInserts)) Chris@76: { Chris@76: $smcFunc['db_insert']('', Chris@76: '{db_prefix}log_comments', Chris@76: array('comment_type' => 'string', 'body' => 'string-65535', 'recipient_name' => 'string-80'), Chris@76: $questionInserts, Chris@76: array('id_comment') Chris@76: ); Chris@76: $count_questions++; Chris@76: } Chris@76: Chris@76: if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) Chris@76: $_POST['qa_verification_number'] = $count_questions; Chris@76: Chris@76: // Now save. Chris@76: saveDBSettings($save_vars); Chris@76: Chris@76: cache_put_data('verificationQuestionIds', null, 300); Chris@76: Chris@76: redirectexit('action=admin;area=securitysettings;sa=spam'); Chris@76: } Chris@76: Chris@76: $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y')); Chris@76: $_SESSION['visual_verification_code'] = ''; Chris@76: for ($i = 0; $i < 6; $i++) Chris@76: $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; Chris@76: Chris@76: // Some javascript for CAPTCHA. Chris@76: $context['settings_post_javascript'] = ''; Chris@76: if ($context['use_graphic_library']) Chris@76: $context['settings_post_javascript'] .= ' Chris@76: function refreshImages() Chris@76: { Chris@76: var imageType = document.getElementById(\'visual_verification_type\').value; Chris@76: document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType; Chris@76: }'; Chris@76: Chris@76: // Show the image itself, or text saying we can't. Chris@76: if ($context['use_graphic_library']) Chris@76: $config_vars['vv']['postinput'] = '
' . $txt['setting_image_verification_sample'] . '
'; Chris@76: else Chris@76: $config_vars['vv']['postinput'] = '
' . $txt['setting_image_verification_nogd'] . ''; Chris@76: Chris@76: // Hack for PM spam settings. Chris@76: list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']); Chris@76: Chris@76: // Hack for guests requiring verification. Chris@76: $modSettings['guests_require_captcha'] = !empty($modSettings['posts_require_captcha']); Chris@76: $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha']; Chris@76: Chris@76: // Some minor javascript for the guest post setting. Chris@76: if ($modSettings['posts_require_captcha']) Chris@76: $context['settings_post_javascript'] .= ' Chris@76: document.getElementById(\'guests_require_captcha\').disabled = true;'; Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=securitysettings;save;sa=spam'; Chris@76: $context['settings_title'] = $txt['antispam_Settings']; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // You'll never guess what this function does... Chris@76: function ModifySignatureSettings($return_config = false) Chris@76: { Chris@76: global $context, $txt, $modSettings, $sig_start, $smcFunc, $helptxt, $scripturl; Chris@76: Chris@76: $config_vars = array( Chris@76: // Are signatures even enabled? Chris@76: array('check', 'signature_enable'), Chris@76: '', Chris@76: // Tweaking settings! Chris@76: array('int', 'signature_max_length'), Chris@76: array('int', 'signature_max_lines'), Chris@76: array('int', 'signature_max_font_size'), Chris@76: array('check', 'signature_allow_smileys', 'onclick' => 'document.getElementById(\'signature_max_smileys\').disabled = !this.checked;'), Chris@76: array('int', 'signature_max_smileys'), Chris@76: '', Chris@76: // Image settings. Chris@76: array('int', 'signature_max_images'), Chris@76: array('int', 'signature_max_image_width'), Chris@76: array('int', 'signature_max_image_height'), Chris@76: '', Chris@76: array('bbc', 'signature_bbc'), Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // Setup the template. Chris@76: $context['page_title'] = $txt['signature_settings']; Chris@76: $context['sub_template'] = 'show_settings'; Chris@76: Chris@76: // Disable the max smileys option if we don't allow smileys at all! Chris@76: $context['settings_post_javascript'] = 'document.getElementById(\'signature_max_smileys\').disabled = !document.getElementById(\'signature_allow_smileys\').checked;'; Chris@76: Chris@76: // Load all the signature settings. Chris@76: list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']); Chris@76: $sig_limits = explode(',', $sig_limits); Chris@76: $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array(); Chris@76: Chris@76: // Applying to ALL signatures?!! Chris@76: if (isset($_GET['apply'])) Chris@76: { Chris@76: // Security! Chris@76: checkSession('get'); Chris@76: Chris@76: $sig_start = time(); Chris@76: // This is horrid - but I suppose some people will want the option to do it. Chris@76: $_GET['step'] = isset($_GET['step']) ? (int) $_GET['step'] : 0; Chris@76: $done = false; Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT MAX(id_member) Chris@76: FROM {db_prefix}members', Chris@76: array( Chris@76: ) Chris@76: ); Chris@76: list ($context['max_member']) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: while (!$done) Chris@76: { Chris@76: $changes = array(); Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_member, signature Chris@76: FROM {db_prefix}members Chris@76: WHERE id_member BETWEEN ' . $_GET['step'] . ' AND ' . $_GET['step'] . ' + 49 Chris@76: AND id_group != {int:admin_group} Chris@76: AND FIND_IN_SET({int:admin_group}, additional_groups) = 0', Chris@76: array( Chris@76: 'admin_group' => 1, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: // Apply all the rules we can realistically do. Chris@76: $sig = strtr($row['signature'], array('
' => "\n")); Chris@76: Chris@76: // Max characters... Chris@76: if (!empty($sig_limits[1])) Chris@76: $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); Chris@76: // Max lines... Chris@76: if (!empty($sig_limits[2])) Chris@76: { Chris@76: $count = 0; Chris@76: for ($i = 0; $i < strlen($sig); $i++) Chris@76: { Chris@76: if ($sig[$i] == "\n") Chris@76: { Chris@76: $count++; Chris@76: if ($count >= $sig_limits[2]) Chris@76: $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); Chris@76: } Chris@76: } Chris@76: } Chris@76: Chris@76: if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $sig, $matches) !== false && isset($matches[2])) Chris@76: { Chris@76: foreach ($matches[1] as $ind => $size) Chris@76: { Chris@76: $limit_broke = 0; Chris@76: // Attempt to allow all sizes of abuse, so to speak. Chris@76: if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) Chris@76: $limit_broke = $sig_limits[7] . 'px'; Chris@76: elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) Chris@76: $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; Chris@76: elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) Chris@76: $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; Chris@76: elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) Chris@76: $limit_broke = 'large'; Chris@76: Chris@76: if ($limit_broke) Chris@76: $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); Chris@76: } Chris@76: } Chris@76: Chris@76: // Stupid images - this is stupidly, stupidly challenging. Chris@76: if ((!empty($sig_limits[3]) || !empty($sig_limits[5]) || !empty($sig_limits[6]))) Chris@76: { Chris@76: $replaces = array(); Chris@76: $img_count = 0; Chris@76: // Get all BBC tags... Chris@76: preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:
)*([^<">]+?)(?:
)*\[/img\]~i', $sig, $matches); Chris@76: // ... and all HTML ones. Chris@76: preg_match_all('~<img\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\s+alt=(?:")?(.*?)(?:")?)?(?:\s?/)?>~i', $sig, $matches2, PREG_PATTERN_ORDER); Chris@76: // And stick the HTML in the BBC. Chris@76: if (!empty($matches2)) Chris@76: { Chris@76: foreach ($matches2[0] as $ind => $dummy) Chris@76: { Chris@76: $matches[0][] = $matches2[0][$ind]; Chris@76: $matches[1][] = ''; Chris@76: $matches[2][] = ''; Chris@76: $matches[3][] = ''; Chris@76: $matches[4][] = ''; Chris@76: $matches[5][] = ''; Chris@76: $matches[6][] = ''; Chris@76: $matches[7][] = $matches2[1][$ind]; Chris@76: } Chris@76: } Chris@76: // Try to find all the images! Chris@76: if (!empty($matches)) Chris@76: { Chris@76: $image_count_holder = array(); Chris@76: foreach ($matches[0] as $key => $image) Chris@76: { Chris@76: $width = -1; $height = -1; Chris@76: $img_count++; Chris@76: // Too many images? Chris@76: if (!empty($sig_limits[3]) && $img_count > $sig_limits[3]) Chris@76: { Chris@76: // If we've already had this before we only want to remove the excess. Chris@76: if (isset($image_count_holder[$image])) Chris@76: { Chris@76: $img_offset = -1; Chris@76: $rep_img_count = 0; Chris@76: while ($img_offset !== false) Chris@76: { Chris@76: $img_offset = strpos($sig, $image, $img_offset + 1); Chris@76: $rep_img_count++; Chris@76: if ($rep_img_count > $image_count_holder[$image]) Chris@76: { Chris@76: // Only replace the excess. Chris@76: $sig = substr($sig, 0, $img_offset) . str_replace($image, '', substr($sig, $img_offset)); Chris@76: // Stop looping. Chris@76: $img_offset = false; Chris@76: } Chris@76: } Chris@76: } Chris@76: else Chris@76: $replaces[$image] = ''; Chris@76: Chris@76: continue; Chris@76: } Chris@76: Chris@76: // Does it have predefined restraints? Width first. Chris@76: if ($matches[6][$key]) Chris@76: $matches[2][$key] = $matches[6][$key]; Chris@76: if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) Chris@76: { Chris@76: $width = $sig_limits[5]; Chris@76: $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); Chris@76: } Chris@76: elseif ($matches[2][$key]) Chris@76: $width = $matches[2][$key]; Chris@76: // ... and height. Chris@76: if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) Chris@76: { Chris@76: $height = $sig_limits[6]; Chris@76: if ($width != -1) Chris@76: $width = $width * ($height / $matches[4][$key]); Chris@76: } Chris@76: elseif ($matches[4][$key]) Chris@76: $height = $matches[4][$key]; Chris@76: Chris@76: // If the dimensions are still not fixed - we need to check the actual image. Chris@76: if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) Chris@76: { Chris@76: $sizes = url_image_size($matches[7][$key]); Chris@76: if (is_array($sizes)) Chris@76: { Chris@76: // Too wide? Chris@76: if ($sizes[0] > $sig_limits[5] && $sig_limits[5]) Chris@76: { Chris@76: $width = $sig_limits[5]; Chris@76: $sizes[1] = $sizes[1] * ($width / $sizes[0]); Chris@76: } Chris@76: // Too high? Chris@76: if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) Chris@76: { Chris@76: $height = $sig_limits[6]; Chris@76: if ($width == -1) Chris@76: $width = $sizes[0]; Chris@76: $width = $width * ($height / $sizes[1]); Chris@76: } Chris@76: elseif ($width != -1) Chris@76: $height = $sizes[1]; Chris@76: } Chris@76: } Chris@76: Chris@76: // Did we come up with some changes? If so remake the string. Chris@76: if ($width != -1 || $height != -1) Chris@76: { Chris@76: $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; Chris@76: } Chris@76: Chris@76: // Record that we got one. Chris@76: $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1; Chris@76: } Chris@76: if (!empty($replaces)) Chris@76: $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); Chris@76: } Chris@76: } Chris@76: // Try to fix disabled tags. Chris@76: if (!empty($disabledTags)) Chris@76: { Chris@76: $sig = preg_replace('~\[(?:' . implode('|', $disabledTags) . ').+?\]~i', '', $sig); Chris@76: $sig = preg_replace('~\[/(?:' . implode('|', $disabledTags) . ')\]~i', '', $sig); Chris@76: } Chris@76: Chris@76: $sig = strtr($sig, array("\n" => '
')); Chris@76: if ($sig != $row['signature']) Chris@76: $changes[$row['id_member']] = $sig; Chris@76: } Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: $done = true; Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: // Do we need to delete what we have? Chris@76: if (!empty($changes)) Chris@76: { Chris@76: foreach ($changes as $id => $sig) Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}members Chris@76: SET signature = {string:signature} Chris@76: WHERE id_member = {int:id_member}', Chris@76: array( Chris@76: 'id_member' => $id, Chris@76: 'signature' => $sig, Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: $_GET['step'] += 50; Chris@76: if (!$done) Chris@76: pauseSignatureApplySettings(); Chris@76: } Chris@76: } Chris@76: Chris@76: $context['signature_settings'] = array( Chris@76: 'enable' => isset($sig_limits[0]) ? $sig_limits[0] : 0, Chris@76: 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0, Chris@76: 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0, Chris@76: 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0, Chris@76: 'allow_smileys' => isset($sig_limits[4]) && $sig_limits[4] == -1 ? 0 : 1, Chris@76: 'max_smileys' => isset($sig_limits[4]) && $sig_limits[4] != -1 ? $sig_limits[4] : 0, Chris@76: 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0, Chris@76: 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0, Chris@76: 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0, Chris@76: ); Chris@76: Chris@76: // Temporarily make each setting a modSetting! Chris@76: foreach ($context['signature_settings'] as $key => $value) Chris@76: $modSettings['signature_' . $key] = $value; Chris@76: Chris@76: // Make sure we check the right tags! Chris@76: $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Clean up the tag stuff! Chris@76: $bbcTags = array(); Chris@76: foreach (parse_bbc(false) as $tag) Chris@76: $bbcTags[] = $tag['tag']; Chris@76: Chris@76: if (!isset($_POST['signature_bbc_enabledTags'])) Chris@76: $_POST['signature_bbc_enabledTags'] = array(); Chris@76: elseif (!is_array($_POST['signature_bbc_enabledTags'])) Chris@76: $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); Chris@76: Chris@76: $sig_limits = array(); Chris@76: foreach ($context['signature_settings'] as $key => $value) Chris@76: { Chris@76: if ($key == 'allow_smileys') Chris@76: continue; Chris@76: elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) Chris@76: $sig_limits[] = -1; Chris@76: else Chris@76: $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; Chris@76: } Chris@76: Chris@76: $_POST['signature_settings'] = implode(',', $sig_limits) . ':' . implode(',', array_diff($bbcTags, $_POST['signature_bbc_enabledTags'])); Chris@76: Chris@76: // Even though we have practically no settings let's keep the convention going! Chris@76: $save_vars = array(); Chris@76: $save_vars[] = array('text', 'signature_settings'); Chris@76: Chris@76: saveDBSettings($save_vars); Chris@76: redirectexit('action=admin;area=featuresettings;sa=sig'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sig'; Chris@76: $context['settings_title'] = $txt['signature_settings']; Chris@76: Chris@76: $context['settings_message'] = '

' . sprintf($txt['signature_settings_warning'], $context['session_id'], $context['session_var']) . '

'; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // Just pause the signature applying thing. Chris@76: function pauseSignatureApplySettings() Chris@76: { Chris@76: global $context, $txt, $sig_start; Chris@76: Chris@76: // Try get more time... Chris@76: @set_time_limit(600); Chris@76: if (function_exists('apache_reset_timeout')) Chris@76: @apache_reset_timeout(); Chris@76: Chris@76: // Have we exhausted all the time we allowed? Chris@76: if (time() - array_sum(explode(' ', $sig_start)) < 3) Chris@76: return; Chris@76: Chris@76: $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id']; Chris@76: $context['page_title'] = $txt['not_done_title']; Chris@76: $context['continue_post_data'] = ''; Chris@76: $context['continue_countdown'] = '2'; Chris@76: $context['sub_template'] = 'not_done'; Chris@76: Chris@76: // Specific stuff to not break this template! Chris@76: $context[$context['admin_menu_name']]['current_subsection'] = 'sig'; Chris@76: Chris@76: // Get the right percent. Chris@76: $context['continue_percent'] = round(($_GET['step'] / $context['max_member']) * 100); Chris@76: Chris@76: // Never more than 100%! Chris@76: $context['continue_percent'] = min($context['continue_percent'], 100); Chris@76: Chris@76: obExit(); Chris@76: } Chris@76: Chris@76: // Show all the custom profile fields available to the user. Chris@76: function ShowCustomProfiles() Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $smcFunc; Chris@76: global $modSettings, $sourcedir; Chris@76: Chris@76: $context['page_title'] = $txt['custom_profile_title']; Chris@76: $context['sub_template'] = 'show_custom_profile'; Chris@76: Chris@76: // What about standard fields they can tweak? Chris@76: $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status'); Chris@76: // What fields can't you put on the registration page? Chris@76: $context['fields_no_registration'] = array('posts', 'warning_status'); Chris@76: Chris@76: // Are we saving any standard field changes? Chris@76: if (isset($_POST['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Do the active ones first. Chris@76: $disable_fields = array_flip($standard_fields); Chris@76: if (!empty($_POST['active'])) Chris@76: { Chris@76: foreach ($_POST['active'] as $value) Chris@76: if (isset($disable_fields[$value])) Chris@76: unset($disable_fields[$value]); Chris@76: } Chris@76: // What we have left! Chris@76: $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields)); Chris@76: Chris@76: // Things we want to show on registration? Chris@76: $reg_fields = array(); Chris@76: if (!empty($_POST['reg'])) Chris@76: { Chris@76: foreach ($_POST['reg'] as $value) Chris@76: if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) Chris@76: $reg_fields[] = $value; Chris@76: } Chris@76: // What we have left! Chris@76: $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields); Chris@76: Chris@76: if (!empty($changes)) Chris@76: updateSettings($changes); Chris@76: } Chris@76: Chris@76: require_once($sourcedir . '/Subs-List.php'); Chris@76: Chris@76: $listOptions = array( Chris@76: 'id' => 'standard_profile_fields', Chris@76: 'title' => $txt['standard_profile_title'], Chris@76: 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile', Chris@76: 'get_items' => array( Chris@76: 'function' => 'list_getProfileFields', Chris@76: 'params' => array( Chris@76: true, Chris@76: ), Chris@76: ), Chris@76: 'columns' => array( Chris@76: 'field' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['standard_profile_field'], Chris@76: 'style' => 'text-align: left;', Chris@76: ), Chris@76: 'data' => array( Chris@76: 'db' => 'label', Chris@76: 'style' => 'width: 60%;', Chris@76: ), Chris@76: ), Chris@76: 'active' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_edit_active'], Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: $isChecked = $rowData[\'disabled\'] ? \'\' : \' checked="checked"\'; Chris@76: $onClickHandler = $rowData[\'can_show_register\'] ? sprintf(\'onclick="document.getElementById(\\\'reg_%1$s\\\').disabled = !this.checked;"\', $rowData[\'id\']) : \'\'; Chris@76: return sprintf(\'\', $rowData[\'id\'], $isChecked, $onClickHandler); Chris@76: '), Chris@76: 'style' => 'width: 20%; text-align: center;', Chris@76: ), Chris@76: ), Chris@76: 'show_on_registration' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_edit_registration'], Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: $isChecked = $rowData[\'on_register\'] && !$rowData[\'disabled\'] ? \' checked="checked"\' : \'\'; Chris@76: $isDisabled = $rowData[\'can_show_register\'] ? \'\' : \' disabled="disabled"\'; Chris@76: return sprintf(\'\', $rowData[\'id\'], $isChecked, $isDisabled); Chris@76: '), Chris@76: 'style' => 'width: 20%; text-align: center;', Chris@76: ), Chris@76: ), Chris@76: ), Chris@76: 'form' => array( Chris@76: 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profile', Chris@76: 'name' => 'standardProfileFields', Chris@76: ), Chris@76: 'additional_rows' => array( Chris@76: array( Chris@76: 'position' => 'below_table_data', Chris@76: 'value' => '', Chris@76: 'style' => 'text-align: right;', Chris@76: ), Chris@76: ), Chris@76: ); Chris@76: createList($listOptions); Chris@76: Chris@76: $listOptions = array( Chris@76: 'id' => 'custom_profile_fields', Chris@76: 'title' => $txt['custom_profile_title'], Chris@76: 'base_href' => $scripturl . '?action=admin;area=featuresettings;sa=profile', Chris@76: 'default_sort_col' => 'field_name', Chris@76: 'no_items_label' => $txt['custom_profile_none'], Chris@76: 'items_per_page' => 25, Chris@76: 'get_items' => array( Chris@76: 'function' => 'list_getProfileFields', Chris@76: 'params' => array( Chris@76: false, Chris@76: ), Chris@76: ), Chris@76: 'get_count' => array( Chris@76: 'function' => 'list_getProfileFieldSize', Chris@76: ), Chris@76: 'columns' => array( Chris@76: 'field_name' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_profile_fieldname'], Chris@76: 'style' => 'text-align: left;', Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: global $scripturl; Chris@76: Chris@76: return sprintf(\'%3$s
%4$s
\', $scripturl, $rowData[\'id_field\'], $rowData[\'field_name\'], $rowData[\'field_desc\']); Chris@76: '), Chris@76: 'style' => 'width: 62%;', Chris@76: ), Chris@76: 'sort' => array( Chris@76: 'default' => 'field_name', Chris@76: 'reverse' => 'field_name DESC', Chris@76: ), Chris@76: ), Chris@76: 'field_type' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_profile_fieldtype'], Chris@76: 'style' => 'text-align: left;', Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: global $txt; Chris@76: Chris@76: $textKey = sprintf(\'custom_profile_type_%1$s\', $rowData[\'field_type\']); Chris@76: return isset($txt[$textKey]) ? $txt[$textKey] : $textKey; Chris@76: '), Chris@76: 'style' => 'width: 15%;', Chris@76: ), Chris@76: 'sort' => array( Chris@76: 'default' => 'field_type', Chris@76: 'reverse' => 'field_type DESC', Chris@76: ), Chris@76: ), Chris@76: 'active' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_profile_active'], Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: global $txt; Chris@76: Chris@76: return $rowData[\'active\'] ? $txt[\'yes\'] : $txt[\'no\']; Chris@76: '), Chris@76: 'style' => 'width: 8%; text-align: center;', Chris@76: ), Chris@76: 'sort' => array( Chris@76: 'default' => 'active DESC', Chris@76: 'reverse' => 'active', Chris@76: ), Chris@76: ), Chris@76: 'placement' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['custom_profile_placement'], Chris@76: ), Chris@76: 'data' => array( Chris@76: 'function' => create_function('$rowData', ' Chris@76: global $txt; Chris@76: Chris@76: return $txt[\'custom_profile_placement_\' . (empty($rowData[\'placement\']) ? \'standard\' : ($rowData[\'placement\'] == 1 ? \'withicons\' : \'abovesignature\'))]; Chris@76: '), Chris@76: 'style' => 'width: 8%; text-align: center;', Chris@76: ), Chris@76: 'sort' => array( Chris@76: 'default' => 'placement DESC', Chris@76: 'reverse' => 'placement', Chris@76: ), Chris@76: ), Chris@76: 'show_on_registration' => array( Chris@76: 'header' => array( Chris@76: 'value' => $txt['modify'], Chris@76: ), Chris@76: 'data' => array( Chris@76: 'sprintf' => array( Chris@76: 'format' => '' . $txt['modify'] . '', Chris@76: 'params' => array( Chris@76: 'id_field' => false, Chris@76: ), Chris@76: ), Chris@76: 'style' => 'width: 15%; text-align: center;', Chris@76: ), Chris@76: ), Chris@76: ), Chris@76: 'form' => array( Chris@76: 'href' => $scripturl . '?action=admin;area=featuresettings;sa=profileedit', Chris@76: 'name' => 'customProfileFields', Chris@76: ), Chris@76: 'additional_rows' => array( Chris@76: array( Chris@76: 'position' => 'below_table_data', Chris@76: 'value' => '', Chris@76: 'style' => 'text-align: right;', Chris@76: ), Chris@76: ), Chris@76: ); Chris@76: createList($listOptions); Chris@76: } Chris@76: Chris@76: function list_getProfileFields($start, $items_per_page, $sort, $standardFields) Chris@76: { Chris@76: global $txt, $modSettings, $smcFunc; Chris@76: Chris@76: $list = array(); Chris@76: Chris@76: if ($standardFields) Chris@76: { Chris@76: $standard_fields = array('icq', 'msn', 'aim', 'yim', 'location', 'gender', 'website', 'posts', 'warning_status'); Chris@76: $fields_no_registration = array('posts', 'warning_status'); Chris@76: $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array(); Chris@76: $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array(); Chris@76: Chris@76: foreach ($standard_fields as $field) Chris@76: $list[] = array( Chris@76: 'id' => $field, Chris@76: 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field), Chris@76: 'disabled' => in_array($field, $disabled_fields), Chris@76: 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration), Chris@76: 'can_show_register' => !in_array($field, $fields_no_registration), Chris@76: ); Chris@76: } Chris@76: else Chris@76: { Chris@76: // Load all the fields. Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_field, col_name, field_name, field_desc, field_type, active, placement Chris@76: FROM {db_prefix}custom_fields Chris@76: ORDER BY {raw:sort} Chris@76: LIMIT {int:start}, {int:items_per_page}', Chris@76: array( Chris@76: 'sort' => $sort, Chris@76: 'start' => $start, Chris@76: 'items_per_page' => $items_per_page, Chris@76: ) Chris@76: ); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: $list[] = $row; Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: return $list; Chris@76: } Chris@76: Chris@76: function list_getProfileFieldSize() Chris@76: { Chris@76: global $smcFunc; Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT COUNT(*) Chris@76: FROM {db_prefix}custom_fields', Chris@76: array( Chris@76: ) Chris@76: ); Chris@76: Chris@76: list ($numProfileFields) = $smcFunc['db_fetch_row']($request); Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: return $numProfileFields; Chris@76: } Chris@76: Chris@76: // Edit some profile fields? Chris@76: function EditCustomProfiles() Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $smcFunc; Chris@76: Chris@76: // Sort out the context! Chris@76: $context['fid'] = isset($_GET['fid']) ? (int) $_GET['fid'] : 0; Chris@76: $context[$context['admin_menu_name']]['current_subsection'] = 'profile'; Chris@76: $context['page_title'] = $context['fid'] ? $txt['custom_edit_title'] : $txt['custom_add_title']; Chris@76: $context['sub_template'] = 'edit_profile_field'; Chris@76: Chris@76: // Load the profile language for section names. Chris@76: loadLanguage('Profile'); Chris@76: Chris@76: if ($context['fid']) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT Chris@76: id_field, col_name, field_name, field_desc, field_type, field_length, field_options, Chris@76: show_reg, show_display, show_profile, private, active, default_value, can_search, Chris@76: bbc, mask, enclose, placement Chris@76: FROM {db_prefix}custom_fields Chris@76: WHERE id_field = {int:current_field}', Chris@76: array( Chris@76: 'current_field' => $context['fid'], Chris@76: ) Chris@76: ); Chris@76: $context['field'] = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: if ($row['field_type'] == 'textarea') Chris@76: @list ($rows, $cols) = @explode(',', $row['default_value']); Chris@76: else Chris@76: { Chris@76: $rows = 3; Chris@76: $cols = 30; Chris@76: } Chris@76: Chris@76: $context['field'] = array( Chris@76: 'name' => $row['field_name'], Chris@76: 'desc' => $row['field_desc'], Chris@76: 'colname' => $row['col_name'], Chris@76: 'profile_area' => $row['show_profile'], Chris@76: 'reg' => $row['show_reg'], Chris@76: 'display' => $row['show_display'], Chris@76: 'type' => $row['field_type'], Chris@76: 'max_length' => $row['field_length'], Chris@76: 'rows' => $rows, Chris@76: 'cols' => $cols, Chris@76: 'bbc' => $row['bbc'] ? true : false, Chris@76: 'default_check' => $row['field_type'] == 'check' && $row['default_value'] ? true : false, Chris@76: 'default_select' => $row['field_type'] == 'select' || $row['field_type'] == 'radio' ? $row['default_value'] : '', Chris@76: 'options' => strlen($row['field_options']) > 1 ? explode(',', $row['field_options']) : array('', '', ''), Chris@76: 'active' => $row['active'], Chris@76: 'private' => $row['private'], Chris@76: 'can_search' => $row['can_search'], Chris@76: 'mask' => $row['mask'], Chris@76: 'regex' => substr($row['mask'], 0, 5) == 'regex' ? substr($row['mask'], 5) : '', Chris@76: 'enclose' => $row['enclose'], Chris@76: 'placement' => $row['placement'], Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: // Setup the default values as needed. Chris@76: if (empty($context['field'])) Chris@76: $context['field'] = array( Chris@76: 'name' => '', Chris@76: 'colname' => '???', Chris@76: 'desc' => '', Chris@76: 'profile_area' => 'forumprofile', Chris@76: 'reg' => false, Chris@76: 'display' => false, Chris@76: 'type' => 'text', Chris@76: 'max_length' => 255, Chris@76: 'rows' => 4, Chris@76: 'cols' => 30, Chris@76: 'bbc' => false, Chris@76: 'default_check' => false, Chris@76: 'default_select' => '', Chris@76: 'options' => array('', '', ''), Chris@76: 'active' => true, Chris@76: 'private' => false, Chris@76: 'can_search' => false, Chris@76: 'mask' => 'nohtml', Chris@76: 'regex' => '', Chris@76: 'enclose' => '', Chris@76: 'placement' => 0, Chris@76: ); Chris@76: Chris@76: // Are we saving? Chris@76: if (isset($_POST['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Everyone needs a name - even the (bracket) unknown... Chris@76: if (trim($_POST['field_name']) == '') Chris@76: fatal_lang_error('custom_option_need_name'); Chris@76: $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']); Chris@76: $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']); Chris@76: Chris@76: // Checkboxes... Chris@76: $show_reg = isset($_POST['reg']) ? (int) $_POST['reg'] : 0; Chris@76: $show_display = isset($_POST['display']) ? 1 : 0; Chris@76: $bbc = isset($_POST['bbc']) ? 1 : 0; Chris@76: $show_profile = $_POST['profile_area']; Chris@76: $active = isset($_POST['active']) ? 1 : 0; Chris@76: $private = isset($_POST['private']) ? (int) $_POST['private'] : 0; Chris@76: $can_search = isset($_POST['can_search']) ? 1 : 0; Chris@76: Chris@76: // Some masking stuff... Chris@76: $mask = isset($_POST['mask']) ? $_POST['mask'] : ''; Chris@76: if ($mask == 'regex' && isset($_POST['regex'])) Chris@76: $mask .= $_POST['regex']; Chris@76: Chris@76: $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255; Chris@76: $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : ''; Chris@76: $placement = isset($_POST['placement']) ? (int) $_POST['placement'] : 0; Chris@76: Chris@76: // Select options? Chris@76: $field_options = ''; Chris@76: $newOptions = array(); Chris@76: $default = isset($_POST['default_check']) && $_POST['field_type'] == 'check' ? 1 : ''; Chris@76: if (!empty($_POST['select_option']) && ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio')) Chris@76: { Chris@76: foreach ($_POST['select_option'] as $k => $v) Chris@76: { Chris@76: // Clean, clean, clean... Chris@76: $v = $smcFunc['htmlspecialchars']($v); Chris@76: $v = strtr($v, array(',' => '')); Chris@76: Chris@76: // Nada, zip, etc... Chris@76: if (trim($v) == '') Chris@76: continue; Chris@76: Chris@76: // Otherwise, save it boy. Chris@76: $field_options .= $v . ','; Chris@76: // This is just for working out what happened with old options... Chris@76: $newOptions[$k] = $v; Chris@76: Chris@76: // Is it default? Chris@76: if (isset($_POST['default_select']) && $_POST['default_select'] == $k) Chris@76: $default = $v; Chris@76: } Chris@76: $field_options = substr($field_options, 0, -1); Chris@76: } Chris@76: Chris@76: // Text area has default has dimensions Chris@76: if ($_POST['field_type'] == 'textarea') Chris@76: $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; Chris@76: Chris@76: // Come up with the unique name? Chris@76: if (empty($context['fid'])) Chris@76: { Chris@76: $colname = $smcFunc['substr'](strtr($_POST['field_name'], array(' ' => '')), 0, 6); Chris@76: preg_match('~([\w\d_-]+)~', $colname, $matches); Chris@76: Chris@76: // If there is nothing to the name, then let's start out own - for foreign languages etc. Chris@76: if (isset($matches[1])) Chris@76: $colname = $initial_colname = 'cust_' . strtolower($matches[1]); Chris@76: else Chris@76: $colname = $initial_colname = 'cust_' . mt_rand(1, 999); Chris@76: Chris@76: // Make sure this is unique. Chris@76: // !!! This may not be the most efficient way to do this. Chris@76: $unique = false; Chris@76: for ($i = 0; !$unique && $i < 9; $i ++) Chris@76: { Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT id_field Chris@76: FROM {db_prefix}custom_fields Chris@76: WHERE col_name = {string:current_column}', Chris@76: array( Chris@76: 'current_column' => $colname, Chris@76: ) Chris@76: ); Chris@76: if ($smcFunc['db_num_rows']($request) == 0) Chris@76: $unique = true; Chris@76: else Chris@76: $colname = $initial_colname . $i; Chris@76: $smcFunc['db_free_result']($request); Chris@76: } Chris@76: Chris@76: // Still not a unique colum name? Leave it up to the user, then. Chris@76: if (!$unique) Chris@76: fatal_lang_error('custom_option_not_unique'); Chris@76: } Chris@76: // Work out what to do with the user data otherwise... Chris@76: else Chris@76: { Chris@76: // Anything going to check or select is pointless keeping - as is anything coming from check! Chris@76: if (($_POST['field_type'] == 'check' && $context['field']['type'] != 'check') Chris@76: || (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && $context['field']['type'] != 'select' && $context['field']['type'] != 'radio') Chris@76: || ($context['field']['type'] == 'check' && $_POST['field_type'] != 'check')) Chris@76: { Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}themes Chris@76: WHERE variable = {string:current_column} Chris@76: AND id_member > {int:no_member}', Chris@76: array( Chris@76: 'no_member' => 0, Chris@76: 'current_column' => $context['field']['colname'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: // Otherwise - if the select is edited may need to adjust! Chris@76: elseif ($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') Chris@76: { Chris@76: $optionChanges = array(); Chris@76: $takenKeys = array(); Chris@76: // Work out what's changed! Chris@76: foreach ($context['field']['options'] as $k => $option) Chris@76: { Chris@76: if (trim($option) == '') Chris@76: continue; Chris@76: Chris@76: // Still exists? Chris@76: if (in_array($option, $newOptions)) Chris@76: { Chris@76: $takenKeys[] = $k; Chris@76: continue; Chris@76: } Chris@76: } Chris@76: Chris@76: // Finally - have we renamed it - or is it really gone? Chris@76: foreach ($optionChanges as $k => $option) Chris@76: { Chris@76: // Just been renamed? Chris@76: if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}themes Chris@76: SET value = {string:new_value} Chris@76: WHERE variable = {string:current_column} Chris@76: AND value = {string:old_value} Chris@76: AND id_member > {int:no_member}', Chris@76: array( Chris@76: 'no_member' => 0, Chris@76: 'new_value' => $newOptions[$k], Chris@76: 'current_column' => $context['field']['colname'], Chris@76: 'old_value' => $option, Chris@76: ) Chris@76: ); Chris@76: } Chris@76: } Chris@76: //!!! Maybe we should adjust based on new text length limits? Chris@76: } Chris@76: Chris@76: // Do the insertion/updates. Chris@76: if ($context['fid']) Chris@76: { Chris@76: $smcFunc['db_query']('', ' Chris@76: UPDATE {db_prefix}custom_fields Chris@76: SET Chris@76: field_name = {string:field_name}, field_desc = {string:field_desc}, Chris@76: field_type = {string:field_type}, field_length = {int:field_length}, Chris@76: field_options = {string:field_options}, show_reg = {int:show_reg}, Chris@76: show_display = {int:show_display}, show_profile = {string:show_profile}, Chris@76: private = {int:private}, active = {int:active}, default_value = {string:default_value}, Chris@76: can_search = {int:can_search}, bbc = {int:bbc}, mask = {string:mask}, Chris@76: enclose = {string:enclose}, placement = {int:placement} Chris@76: WHERE id_field = {int:current_field}', Chris@76: array( Chris@76: 'field_length' => $field_length, Chris@76: 'show_reg' => $show_reg, Chris@76: 'show_display' => $show_display, Chris@76: 'private' => $private, Chris@76: 'active' => $active, Chris@76: 'can_search' => $can_search, Chris@76: 'bbc' => $bbc, Chris@76: 'current_field' => $context['fid'], Chris@76: 'field_name' => $_POST['field_name'], Chris@76: 'field_desc' => $_POST['field_desc'], Chris@76: 'field_type' => $_POST['field_type'], Chris@76: 'field_options' => $field_options, Chris@76: 'show_profile' => $show_profile, Chris@76: 'default_value' => $default, Chris@76: 'mask' => $mask, Chris@76: 'enclose' => $enclose, Chris@76: 'placement' => $placement, Chris@76: ) Chris@76: ); Chris@76: Chris@76: // Just clean up any old selects - these are a pain! Chris@76: if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}themes Chris@76: WHERE variable = {string:current_column} Chris@76: AND value NOT IN ({array_string:new_option_values}) Chris@76: AND id_member > {int:no_member}', Chris@76: array( Chris@76: 'no_member' => 0, Chris@76: 'new_option_values' => $newOptions, Chris@76: 'current_column' => $context['field']['colname'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: else Chris@76: { Chris@76: $smcFunc['db_insert']('', Chris@76: '{db_prefix}custom_fields', Chris@76: array( Chris@76: 'col_name' => 'string', 'field_name' => 'string', 'field_desc' => 'string', Chris@76: 'field_type' => 'string', 'field_length' => 'string', 'field_options' => 'string', Chris@76: 'show_reg' => 'int', 'show_display' => 'int', 'show_profile' => 'string', Chris@76: 'private' => 'int', 'active' => 'int', 'default_value' => 'string', 'can_search' => 'int', Chris@76: 'bbc' => 'int', 'mask' => 'string', 'enclose' => 'string', 'placement' => 'int', Chris@76: ), Chris@76: array( Chris@76: $colname, $_POST['field_name'], $_POST['field_desc'], Chris@76: $_POST['field_type'], $field_length, $field_options, Chris@76: $show_reg, $show_display, $show_profile, Chris@76: $private, $active, $default, $can_search, Chris@76: $bbc, $mask, $enclose, $placement, Chris@76: ), Chris@76: array('id_field') Chris@76: ); Chris@76: } Chris@76: Chris@76: // As there's currently no option to priorize certain fields over others, let's order them alphabetically. Chris@76: $smcFunc['db_query']('alter_table_boards', ' Chris@76: ALTER TABLE {db_prefix}custom_fields Chris@76: ORDER BY field_name', Chris@76: array( Chris@76: 'db_error_skip' => true, Chris@76: ) Chris@76: ); Chris@76: } Chris@76: // Deleting? Chris@76: elseif (isset($_POST['delete']) && $context['field']['colname']) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: // Delete the user data first. Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}themes Chris@76: WHERE variable = {string:current_column} Chris@76: AND id_member > {int:no_member}', Chris@76: array( Chris@76: 'no_member' => 0, Chris@76: 'current_column' => $context['field']['colname'], Chris@76: ) Chris@76: ); Chris@76: // Finally - the field itself is gone! Chris@76: $smcFunc['db_query']('', ' Chris@76: DELETE FROM {db_prefix}custom_fields Chris@76: WHERE id_field = {int:current_field}', Chris@76: array( Chris@76: 'current_field' => $context['fid'], Chris@76: ) Chris@76: ); Chris@76: } Chris@76: Chris@76: // Rebuild display cache etc. Chris@76: if (isset($_POST['delete']) || isset($_POST['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: $request = $smcFunc['db_query']('', ' Chris@76: SELECT col_name, field_name, field_type, bbc, enclose, placement Chris@76: FROM {db_prefix}custom_fields Chris@76: WHERE show_display = {int:is_displayed} Chris@76: AND active = {int:active} Chris@76: AND private != {int:not_owner_only} Chris@76: AND private != {int:not_admin_only}', Chris@76: array( Chris@76: 'is_displayed' => 1, Chris@76: 'active' => 1, Chris@76: 'not_owner_only' => 2, Chris@76: 'not_admin_only' => 3, Chris@76: ) Chris@76: ); Chris@76: Chris@76: $fields = array(); Chris@76: while ($row = $smcFunc['db_fetch_assoc']($request)) Chris@76: { Chris@76: $fields[] = array( Chris@76: 'colname' => strtr($row['col_name'], array('|' => '', ';' => '')), Chris@76: 'title' => strtr($row['field_name'], array('|' => '', ';' => '')), Chris@76: 'type' => $row['field_type'], Chris@76: 'bbc' => $row['bbc'] ? '1' : '0', Chris@76: 'placement' => !empty($row['placement']) ? $row['placement'] : '0', Chris@76: 'enclose' => !empty($row['enclose']) ? $row['enclose'] : '', Chris@76: ); Chris@76: } Chris@76: $smcFunc['db_free_result']($request); Chris@76: Chris@76: updateSettings(array('displayFields' => serialize($fields))); Chris@76: redirectexit('action=admin;area=featuresettings;sa=profile'); Chris@76: } Chris@76: } Chris@76: Chris@76: function ModifyPruningSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $sourcedir, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: // Make sure we understand what's going on. Chris@76: loadLanguage('ManageSettings'); Chris@76: Chris@76: $context['page_title'] = $txt['pruning_title']; Chris@76: Chris@76: $config_vars = array( Chris@76: // Even do the pruning? Chris@76: // The array indexes are there so we can remove/change them before saving. Chris@76: 'pruningOptions' => array('check', 'pruningOptions'), Chris@76: '', Chris@76: // Various logs that could be pruned. Chris@76: array('int', 'pruneErrorLog', 'postinput' => $txt['days_word']), // Error log. Chris@76: array('int', 'pruneModLog', 'postinput' => $txt['days_word']), // Moderation log. Chris@76: array('int', 'pruneBanLog', 'postinput' => $txt['days_word']), // Ban hit log. Chris@76: array('int', 'pruneReportLog', 'postinput' => $txt['days_word']), // Report to moderator log. Chris@76: array('int', 'pruneScheduledTaskLog', 'postinput' => $txt['days_word']), // Log of the scheduled tasks and how long they ran. Chris@76: array('int', 'pruneSpiderHitLog', 'postinput' => $txt['days_word']), // Log of the scheduled tasks and how long they ran. Chris@76: // 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. Chris@76: // Mod Developers: Do NOT use the pruningOptions master variable for this as SMF Core may overwrite your setting in the future! Chris@76: ); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: // We'll need this in a bit. Chris@76: require_once($sourcedir . '/ManageServer.php'); Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: $savevar = array( Chris@76: array('text', 'pruningOptions') Chris@76: ); Chris@76: Chris@76: if (!empty($_POST['pruningOptions'])) Chris@76: { Chris@76: $vals = array(); Chris@76: foreach ($config_vars as $index => $dummy) Chris@76: { Chris@76: if (!is_array($dummy) || $index == 'pruningOptions') Chris@76: continue; Chris@76: Chris@76: $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]]; Chris@76: } Chris@76: $_POST['pruningOptions'] = implode(',', $vals); Chris@76: } Chris@76: else Chris@76: $_POST['pruningOptions'] = ''; Chris@76: Chris@76: saveDBSettings($savevar); Chris@76: redirectexit('action=admin;area=logs;sa=pruning'); Chris@76: } Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=logs;save;sa=pruning'; Chris@76: $context['settings_title'] = $txt['pruning_title']; Chris@76: $context['sub_template'] = 'show_settings'; Chris@76: Chris@76: // Get the actual values Chris@76: if (!empty($modSettings['pruningOptions'])) Chris@76: @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); Chris@76: else Chris@76: $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; Chris@76: Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // If you have a general mod setting to add stick it here. Chris@76: function ModifyGeneralModSettings($return_config = false) Chris@76: { Chris@76: global $txt, $scripturl, $context, $settings, $sc, $modSettings; Chris@76: Chris@76: $config_vars = array( Chris@76: // Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!! Chris@76: ); Chris@76: Chris@76: // Make it even easier to add new settings. Chris@76: call_integration_hook('integrate_general_mod_settings', array(&$config_vars)); Chris@76: Chris@76: if ($return_config) Chris@76: return $config_vars; Chris@76: Chris@76: $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general'; Chris@76: $context['settings_title'] = $txt['mods_cat_modifications_misc']; Chris@76: Chris@76: // No removing this line you, dirty unwashed mod authors. :p Chris@76: if (empty($config_vars)) Chris@76: { Chris@76: $context['settings_save_dont_show'] = true; Chris@76: $context['settings_message'] = '
' . $txt['modification_no_misc_settings'] . '
'; Chris@76: Chris@76: return prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: // Saving? Chris@76: if (isset($_GET['save'])) Chris@76: { Chris@76: checkSession(); Chris@76: Chris@76: $save_vars = $config_vars; Chris@76: Chris@76: // This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS! Chris@76: saveDBSettings($save_vars); Chris@76: Chris@76: // This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA! Chris@76: redirectexit('action=admin;area=modsettings;sa=general'); Chris@76: } Chris@76: Chris@76: // 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! Chris@76: prepareDBSettingContext($config_vars); Chris@76: } Chris@76: Chris@76: ?>