public static function load_theme()
 {
     global $context, $modSettings, $txt, $settings, $user_info;
     if (($themes = cache_get_data('TS_themes_list', 3600)) === null) {
         loadLanguage('ManageThemes');
         require_once SUBSDIR . '/Themes.subs.php';
         $themes = availableThemes($user_info['theme'], $user_info['id']);
         cache_put_data('TS_themes_list', $themes, 3600);
     }
     foreach ($themes[0] as $theme_id => $theme) {
         $name = $theme['name'];
         $selected = !empty($user_info['theme']) && $user_info['theme'] == $theme_id;
         $context['ThemeSelector'][$theme_id] = array('name' => $name, 'selected' => $selected, 'variants' => array());
         if (isset($theme['variants'])) {
             foreach ($theme['variants'] as $key => $variant) {
                 $context['ThemeSelector'][$theme_id]['variants'][$key] = array('name' => $variant['label'], 'selected' => $context['theme_variant'] == '_' . $key);
             }
         }
     }
     if (!isset($context['theme_header_callbacks'])) {
         $context['theme_header_callbacks'] = array();
     }
     $context['theme_header_callbacks'][] = 'themeselector';
     loadTemplate('ThemeSelector');
     loadJavascriptFile('ThemeSelector.js');
     loadCSSFile('ThemeSelector.css');
 }
예제 #2
0
 /**
  * Choose a theme from a list.
  * Allows a user or administrator to pick a new theme with an interface.
  *
  * What it does:
  * - Can edit everyone's (u = 0), guests' (u = -1), or a specific user's.
  * - Uses the Themes template. (pick sub template.)
  * - Accessed with ?action=admin;area=theme;sa=pick.
  *
  * @uses Profile language text
  * @uses ManageThemes template
  * @todo thought so... Might be better to split this file in ManageThemes and Themes,
  * with centralized admin permissions on ManageThemes.
  */
 public function action_pick()
 {
     global $txt, $context, $modSettings, $user_info, $scripturl, $settings;
     require_once SUBSDIR . '/Themes.subs.php';
     if (!$modSettings['theme_allow'] && $settings['disable_user_variant'] && !allowedTo('admin_forum')) {
         fatal_lang_error('no_access', false);
     }
     loadLanguage('Profile');
     loadTemplate('ManageThemes');
     // Build the link tree.
     $context['linktree'][] = array('url' => $scripturl . '?action=theme;sa=pick;u=' . (!empty($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0), 'name' => $txt['theme_pick']);
     $context['default_theme_id'] = $modSettings['theme_default'];
     $_SESSION['id_theme'] = 0;
     if (isset($_GET['id'])) {
         $_GET['th'] = $_GET['id'];
     }
     // Saving a variant cause JS doesn't work - pretend it did ;)
     if (isset($_POST['save'])) {
         // Which theme?
         foreach ($_POST['save'] as $k => $v) {
             $_GET['th'] = (int) $k;
         }
         if (isset($_POST['vrt'][$k])) {
             $_GET['vrt'] = $_POST['vrt'][$k];
         }
     }
     // Have we made a decision, or are we just browsing?
     if (isset($_GET['th'])) {
         checkSession('get');
         $_GET['th'] = (int) $_GET['th'];
         // Save for this user.
         if (!isset($_REQUEST['u']) || !allowedTo('admin_forum')) {
             updateMemberData($user_info['id'], array('id_theme' => (int) $_GET['th']));
             // A variants to save for the user?
             if (!empty($_GET['vrt'])) {
                 updateThemeOptions(array($_GET['th'], $user_info['id'], 'theme_variant', $_GET['vrt']));
                 cache_put_data('theme_settings-' . $_GET['th'] . ':' . $user_info['id'], null, 90);
                 $_SESSION['id_variant'] = 0;
             }
             redirectexit('action=profile;area=theme');
         }
         // If changing members or guests - and there's a variant - assume changing default variant.
         if (!empty($_GET['vrt']) && ($_REQUEST['u'] == '0' || $_REQUEST['u'] == '-1')) {
             updateThemeOptions(array($_GET['th'], 0, 'default_variant', $_GET['vrt']));
             // Make it obvious that it's changed
             cache_put_data('theme_settings-' . $_GET['th'], null, 90);
         }
         // For everyone.
         if ($_REQUEST['u'] == '0') {
             updateMemberData(null, array('id_theme' => (int) $_GET['th']));
             // Remove any custom variants.
             if (!empty($_GET['vrt'])) {
                 deleteVariants((int) $_GET['th']);
             }
             redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
         } elseif ($_REQUEST['u'] == '-1') {
             updateSettings(array('theme_guests' => (int) $_GET['th']));
             redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
         } else {
             // The forum's default theme is always 0 and we
             if (isset($_GET['th']) && $_GET['th'] == 0) {
                 $_GET['th'] = $modSettings['theme_guests'];
             }
             updateMemberData((int) $_REQUEST['u'], array('id_theme' => (int) $_GET['th']));
             if (!empty($_GET['vrt'])) {
                 updateThemeOptions(array($_GET['th'], (int) $_REQUEST['u'], 'theme_variant', $_GET['vrt']));
                 cache_put_data('theme_settings-' . $_GET['th'] . ':' . (int) $_REQUEST['u'], null, 90);
                 if ($user_info['id'] == $_REQUEST['u']) {
                     $_SESSION['id_variant'] = 0;
                 }
             }
             redirectexit('action=profile;u=' . (int) $_REQUEST['u'] . ';area=theme');
         }
     }
     // Figure out who the member of the minute is, and what theme they've chosen.
     if (!isset($_REQUEST['u']) || !allowedTo('admin_forum')) {
         $context['current_member'] = $user_info['id'];
         $current_theme = $user_info['theme'];
     } elseif ($_REQUEST['u'] == '0') {
         $context['current_member'] = 0;
         $current_theme = 0;
     } elseif ($_REQUEST['u'] == '-1') {
         $context['current_member'] = -1;
         $current_theme = $modSettings['theme_guests'];
     } else {
         $context['current_member'] = (int) $_REQUEST['u'];
         require_once SUBSDIR . '/Members.subs.php';
         $member = getBasicMemberData($context['current_member']);
         $current_theme = $member['id_theme'];
     }
     // Get the theme name and descriptions.
     list($context['available_themes'], $guest_theme) = availableThemes($current_theme, $context['current_member']);
     // As long as we're not doing the default theme...
     if (!isset($_REQUEST['u']) || $_REQUEST['u'] >= 0) {
         if ($guest_theme != 0) {
             $context['available_themes'][0] = $context['available_themes'][$guest_theme];
         }
         $context['available_themes'][0]['id'] = 0;
         $context['available_themes'][0]['name'] = $txt['theme_forum_default'];
         $context['available_themes'][0]['selected'] = $current_theme == 0;
         $context['available_themes'][0]['description'] = $txt['theme_global_description'];
     }
     ksort($context['available_themes']);
     $context['page_title'] = $txt['theme_pick'];
     $context['sub_template'] = 'pick';
 }