示例#1
0
/**
 * Make any theme changes that are sent with the profile.
 *
 * @param int $memID
 * @param int $id_theme
 */
function makeThemeChanges($memID, $id_theme)
{
    global $modSettings, $context, $user_info;
    $db = database();
    $reservedVars = array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url');
    // Can't change reserved vars.
    if (isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0 || isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0) {
        fatal_lang_error('no_access', false);
    }
    // Don't allow any overriding of custom fields with default or non-default options.
    $request = $db->query('', '
		SELECT col_name
		FROM {db_prefix}custom_fields
		WHERE active = {int:is_active}', array('is_active' => 1));
    $custom_fields = array();
    while ($row = $db->fetch_assoc($request)) {
        $custom_fields[] = $row['col_name'];
    }
    $db->free_result($request);
    // These are the theme changes...
    $themeSetArray = array();
    if (isset($_POST['options']) && is_array($_POST['options'])) {
        foreach ($_POST['options'] as $opt => $val) {
            if (in_array($opt, $custom_fields)) {
                continue;
            }
            // These need to be controlled.
            if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
                $val = max(0, min($val, 50));
            } elseif ($opt == 'allow_no_censored') {
                continue;
            }
            $themeSetArray[] = array($id_theme, $memID, $opt, is_array($val) ? implode(',', $val) : $val);
        }
    }
    $erase_options = array();
    if (isset($_POST['default_options']) && is_array($_POST['default_options'])) {
        foreach ($_POST['default_options'] as $opt => $val) {
            if (in_array($opt, $custom_fields)) {
                continue;
            }
            // These need to be controlled.
            if ($opt == 'topics_per_page' || $opt == 'messages_per_page') {
                $val = max(0, min($val, 50));
            } elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) {
                continue;
            }
            $themeSetArray[] = array(1, $memID, $opt, is_array($val) ? implode(',', $val) : $val);
            $erase_options[] = $opt;
        }
    }
    // If themeSetArray isn't still empty, send it to the database.
    if (empty($context['password_auth_failed'])) {
        require_once SUBSDIR . '/Themes.subs.php';
        if (!empty($themeSetArray)) {
            updateThemeOptions($themeSetArray);
        }
        if (!empty($erase_options)) {
            removeThemeOptions('custom', $memID, $erase_options);
        }
        $themes = explode(',', $modSettings['knownThemes']);
        foreach ($themes as $t) {
            cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
        }
    }
}
示例#2
0
/**
 * Saves the admins current preferences to the database.
 *
 * @package Admin
 */
function updateAdminPreferences()
{
    global $options, $context, $settings, $user_info;
    // This must exist!
    if (!isset($context['admin_preferences'])) {
        return false;
    }
    // This is what we'll be saving.
    $options['admin_preferences'] = serialize($context['admin_preferences']);
    require_once SUBSDIR . '/Themes.subs.php';
    // Just check we haven't ended up with something theme exclusive somehow.
    removeThemeOptions('custom', 'all', 'admin_preferences');
    updateThemeOptions(array(1, $user_info['id'], 'admin_preferences', $options['admin_preferences']));
    // Make sure we invalidate any cache.
    cache_put_data('theme_settings-' . $settings['theme_id'] . ':' . $user_info['id'], null, 0);
}
 /**
  * Administrative global settings.
  *
  * - Accessed by ?action=admin;area=theme;sa=reset;
  *
  * @uses sub template set_options, template file Settings
  * @uses template file ManageThemes
  */
 public function action_options()
 {
     global $txt, $context, $settings, $modSettings;
     require_once SUBSDIR . '/Themes.subs.php';
     $theme = isset($_GET['th']) ? (int) $_GET['th'] : (isset($_GET['id']) ? (int) $_GET['id'] : 0);
     if (empty($theme) && empty($_GET['id'])) {
         $context['themes'] = installedThemes();
         // How many options do we have setup for guests?
         $guestOptions = countConfiguredGuestOptions();
         foreach ($guestOptions as $guest_option) {
             $context['themes'][$guest_option['id_theme']]['num_default_options'] = $guest_option['value'];
         }
         // How many options do we have setup for members?
         $memberOptions = countConfiguredMemberOptions();
         foreach ($memberOptions as $member_option) {
             $context['themes'][$member_option['id_theme']]['num_members'] = $member_option['value'];
         }
         // There has to be a Settings template!
         foreach ($context['themes'] as $k => $v) {
             if (empty($v['theme_dir']) || !file_exists($v['theme_dir'] . '/Settings.template.php') && empty($v['num_members'])) {
                 unset($context['themes'][$k]);
             }
         }
         loadTemplate('ManageThemes');
         $context['sub_template'] = 'reset_list';
         createToken('admin-stor', 'request');
         return;
     }
     // Submit?
     if (isset($_POST['submit']) && empty($_POST['who'])) {
         checkSession();
         validateToken('admin-sto');
         if (empty($_POST['options'])) {
             $_POST['options'] = array();
         }
         if (empty($_POST['default_options'])) {
             $_POST['default_options'] = array();
         }
         // Set up the query values.
         $setValues = array();
         foreach ($_POST['options'] as $opt => $val) {
             $setValues[] = array($theme, -1, $opt, is_array($val) ? implode(',', $val) : $val);
         }
         $old_settings = array();
         foreach ($_POST['default_options'] as $opt => $val) {
             $old_settings[] = $opt;
             $setValues[] = array(1, -1, $opt, is_array($val) ? implode(',', $val) : $val);
         }
         // If we're actually inserting something..
         if (!empty($setValues)) {
             // Are there options in non-default themes set that should be cleared?
             if (!empty($old_settings)) {
                 removeThemeOptions('custom', 'guests', $old_settings);
             }
             updateThemeOptions($setValues);
         }
         // Cache the theme settings
         cache_put_data('theme_settings-' . $theme, null, 90);
         cache_put_data('theme_settings-1', null, 90);
         redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
     } elseif (isset($_POST['submit']) && $_POST['who'] == 1) {
         checkSession();
         validateToken('admin-sto');
         $_POST['options'] = empty($_POST['options']) ? array() : $_POST['options'];
         $_POST['options_master'] = empty($_POST['options_master']) ? array() : $_POST['options_master'];
         $_POST['default_options'] = empty($_POST['default_options']) ? array() : $_POST['default_options'];
         $_POST['default_options_master'] = empty($_POST['default_options_master']) ? array() : $_POST['default_options_master'];
         $old_settings = array();
         foreach ($_POST['default_options'] as $opt => $val) {
             if ($_POST['default_options_master'][$opt] == 0) {
                 continue;
             } elseif ($_POST['default_options_master'][$opt] == 1) {
                 // Delete then insert for ease of database compatibility!
                 removeThemeOptions('default', 'guests', $opt);
                 addThemeOptions(1, $opt, $val);
                 $old_settings[] = $opt;
             } elseif ($_POST['default_options_master'][$opt] == 2) {
                 removeThemeOptions('all', 'members', $opt);
             }
         }
         // Delete options from other themes.
         if (!empty($old_settings)) {
             removeThemeOptions('custom', 'members', $old_settings);
         }
         foreach ($_POST['options'] as $opt => $val) {
             if ($_POST['options_master'][$opt] == 0) {
                 continue;
             } elseif ($_POST['options_master'][$opt] == 1) {
                 // Delete then insert for ease of database compatibility - again!
                 removeThemeOptions($theme, 'non_default', $opt);
                 addThemeOptions($theme, $opt, $val);
             } elseif ($_POST['options_master'][$opt] == 2) {
                 removeThemeOptions($theme, 'all', $opt);
             }
         }
         redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
     } elseif (!empty($_GET['who']) && $_GET['who'] == 2) {
         checkSession('get');
         validateToken('admin-stor', 'request');
         removeThemeOptions($theme, 'members');
         redirectexit('action=admin;area=theme;' . $context['session_var'] . '=' . $context['session_id'] . ';sa=reset');
     }
     $old_id = $settings['theme_id'];
     $old_settings = $settings;
     loadTheme($theme, false);
     loadLanguage('Profile');
     // @todo Should we just move these options so they are no longer theme dependant?
     loadLanguage('PersonalMessage');
     // Let the theme take care of the settings.
     loadTemplate('Settings');
     loadSubTemplate('options');
     // Set up for the template
     $context['sub_template'] = 'set_options';
     $context['page_title'] = $txt['theme_settings'];
     $context['options'] = $context['theme_options'];
     $context['theme_settings'] = $settings;
     // Load the options for these theme
     if (empty($_REQUEST['who'])) {
         $context['theme_options'] = loadThemeOptionsInto(array(1, $theme), -1, $context['theme_options']);
         $context['theme_options_reset'] = false;
     } else {
         $context['theme_options'] = array();
         $context['theme_options_reset'] = true;
     }
     // Prepare the options for the template
     foreach ($context['options'] as $i => $setting) {
         // Is this disabled?
         if ($setting['id'] == 'calendar_start_day' && empty($modSettings['cal_enabled'])) {
             unset($context['options'][$i]);
             continue;
         } elseif (($setting['id'] == 'topics_per_page' || $setting['id'] == 'messages_per_page') && !empty($modSettings['disableCustomPerPage'])) {
             unset($context['options'][$i]);
             continue;
         }
         // Type of field so we display the right input field
         if (!isset($setting['type']) || $setting['type'] == 'bool') {
             $context['options'][$i]['type'] = 'checkbox';
         } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
             $context['options'][$i]['type'] = 'number';
         } elseif ($setting['type'] == 'string') {
             $context['options'][$i]['type'] = 'text';
         }
         if (isset($setting['options'])) {
             $context['options'][$i]['type'] = 'list';
         }
         $context['options'][$i]['value'] = !isset($context['theme_options'][$setting['id']]) ? '' : $context['theme_options'][$setting['id']];
     }
     // Restore the existing theme.
     loadTheme($old_id, false);
     $settings = $old_settings;
     loadTemplate('ManageThemes');
     createToken('admin-sto');
 }