示例#1
0
function RegbarWarning()
{
    global $context, $settings;
    loadLanguage('smfhacks_languages/regbar-warning');
    loadTemplate('smfhacks_templates/regbar-warning');
    $context['html_headers'] .= "\n" . '<link rel="stylesheet" type="text/css" href="' . $settings['theme_url'] . '/smfhacks_css/regbar-warning.css" />';
    loadSubTemplate('regbar_warning');
}
function retrieveGlobalHFContent($placement)
{
    global $context, $boarddir, $sourcedir, $global_hf, $modSettings;
    if (!isset($_GET['xml']) && (!isset($_GET['action']) || $_GET['action'] != 'dlattach')) {
        $global_hf = array('head' => un_htmlspecialchars(file_get_contents($boarddir . '/smfhacks_resources/global-hf-head.txt')), 'header' => un_htmlspecialchars(file_get_contents($boarddir . '/smfhacks_resources/global-hf-header.txt')), 'footer' => un_htmlspecialchars(file_get_contents($boarddir . '/smfhacks_resources/global-hf-footer.txt')));
        if ($placement != 'load') {
            if (!empty($modSettings['global_header_bbc'])) {
                $global_hf['parsed']['header'] = parse_bbc($global_hf['header']);
            }
            if (!empty($modSettings['global_footer_bbc'])) {
                $global_hf['parsed']['footer'] = parse_bbc($global_hf['footer']);
            }
            loadTemplate('smfhacks_templates/global-hf');
            loadSubTemplate('global_hf' . $placement, true);
        } elseif (!empty($global_hf['head'])) {
            $context['html_headers'] .= "\n" . $global_hf['head'];
        }
    }
}
示例#3
0
文件: Load.php 项目: alencarmo/OCF
function loadTheme($ID_THEME = 0, $initialize = true)
{
    global $ID_MEMBER, $user_info, $board_info, $sc;
    global $db_prefix, $txt, $boardurl, $scripturl, $mbname, $modSettings;
    global $context, $settings, $options;
    // The theme was specified by parameter.
    if (!empty($ID_THEME)) {
        $ID_THEME = (int) $ID_THEME;
    } elseif (!empty($board_info['theme']) && $board_info['override_theme']) {
        $ID_THEME = $board_info['theme'];
    } elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $ID_THEME = (int) $_REQUEST['theme'];
        $_SESSION['ID_THEME'] = $ID_THEME;
    } elseif (!empty($_SESSION['ID_THEME']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $ID_THEME = (int) $_SESSION['ID_THEME'];
    } elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $ID_THEME = $user_info['theme'];
    } elseif (!empty($board_info['theme'])) {
        $ID_THEME = $board_info['theme'];
    } else {
        $ID_THEME = $modSettings['theme_guests'];
    }
    // Verify the ID_THEME... no foul play.
    if (empty($modSettings['theme_default']) && $ID_THEME == 1 && !allowedTo('admin_forum')) {
        $ID_THEME = $modSettings['theme_guests'];
    } elseif (!empty($modSettings['knownThemes']) && !empty($modSettings['theme_allow']) && !allowedTo('admin_forum')) {
        $themes = explode(',', $modSettings['knownThemes']);
        if (!in_array($ID_THEME, $themes)) {
            $ID_THEME = $modSettings['theme_guests'];
        } else {
            $ID_THEME = (int) $ID_THEME;
        }
    } else {
        $ID_THEME = (int) $ID_THEME;
    }
    $member = empty($ID_MEMBER) ? -1 : $ID_MEMBER;
    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $ID_THEME . ':' . $member, 60)) != null) {
        $themeData = $temp;
        $flag = true;
    } elseif (($temp = cache_get_data('theme_settings-' . $ID_THEME, 90)) != null) {
        $themeData = $temp + array($member => array());
    } else {
        $themeData = array(-1 => array(), 0 => array(), $member => array());
    }
    if (empty($flag)) {
        // Load variables from the current or default theme, global or this user's.
        $result = db_query("\n\t\t\tSELECT variable, value, ID_MEMBER, ID_THEME\n\t\t\tFROM {$db_prefix}themes\n\t\t\tWHERE ID_MEMBER" . (empty($themeData[0]) ? " IN (-1, 0, {$member})" : " = {$member}") . "\n\t\t\t\tAND ID_THEME" . ($ID_THEME == 1 ? ' = 1' : " IN ({$ID_THEME}, 1)"), __FILE__, __LINE__);
        // Pick between $settings and $options depending on whose data it is.
        while ($row = mysql_fetch_assoc($result)) {
            // There are just things we shouldn't be able to change as members.
            if ($row['ID_MEMBER'] != 0 && in_array($row['variable'], 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'))) {
                continue;
            }
            // If this is the theme_dir of the default theme, store it.
            if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['ID_THEME'] == '1' && empty($row['ID_MEMBER'])) {
                $themeData[0]['default_' . $row['variable']] = $row['value'];
            }
            // If this isn't set yet, is a theme option, or is not the default theme..
            if (!isset($themeData[$row['ID_MEMBER']][$row['variable']]) || $row['ID_THEME'] != '1') {
                $themeData[$row['ID_MEMBER']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
            }
        }
        mysql_free_result($result);
        if (!empty($themeData[-1])) {
            foreach ($themeData[-1] as $k => $v) {
                if (!isset($themeData[$member][$k])) {
                    $themeData[$member][$k] = $v;
                }
            }
        }
        if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
            cache_put_data('theme_settings-' . $ID_THEME . ':' . $member, $themeData, 60);
        } elseif (!isset($temp)) {
            cache_put_data('theme_settings-' . $ID_THEME, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
        }
    }
    $settings = $themeData[0];
    $options = $themeData[$member];
    $settings['theme_id'] = $ID_THEME;
    $settings['actual_theme_url'] = $settings['theme_url'];
    $settings['actual_images_url'] = $settings['images_url'];
    $settings['actual_theme_dir'] = $settings['theme_dir'];
    if (!$initialize) {
        return;
    }
    // Check to see if they're accessing it from the wrong place.
    if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) {
        $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
        $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
        $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
        if ($temp != '/') {
            $detected_url .= $temp;
        }
    }
    if (isset($detected_url) && $detected_url != $boardurl) {
        // Try #1 - check if it's in a list of alias addresses.
        if (!empty($modSettings['forum_alias_urls'])) {
            $aliases = explode(',', $modSettings['forum_alias_urls']);
            foreach ($aliases as $alias) {
                // Rip off all the boring parts, spaces, etc.
                if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
                    $do_fix = true;
                }
            }
        }
        // Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
        if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1)) {
            // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
            if (empty($_GET)) {
                redirectexit('www');
            } else {
                list($k, $v) = each($_GET);
                if ($k != 'www') {
                    redirectexit('www;' . $k . '=' . $v);
                }
            }
        }
        // #3 is just a check for SSL...
        if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
            $do_fix = true;
        }
        // Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
        if (!empty($do_fix) || preg_match('~^http[s]://[\\d\\.:]+($|/)~', $detected_url) == 1) {
            // Caching is good ;).
            $oldurl = $boardurl;
            // Fix $boardurl and $scripturl.
            $boardurl = $detected_url;
            $scripturl = strtr($scripturl, array($oldurl => $boardurl));
            $_SERVER['REQUEST_URL'] = strtr($_SERVER['REQUEST_URL'], array($oldurl => $boardurl));
            // Fix the theme urls...
            $settings['theme_url'] = strtr($settings['theme_url'], array($oldurl => $boardurl));
            $settings['default_theme_url'] = strtr($settings['default_theme_url'], array($oldurl => $boardurl));
            $settings['actual_theme_url'] = strtr($settings['actual_theme_url'], array($oldurl => $boardurl));
            $settings['images_url'] = strtr($settings['images_url'], array($oldurl => $boardurl));
            $settings['default_images_url'] = strtr($settings['default_images_url'], array($oldurl => $boardurl));
            $settings['actual_images_url'] = strtr($settings['actual_images_url'], array($oldurl => $boardurl));
            // And just a few mod settings :).
            $modSettings['smileys_url'] = strtr($modSettings['smileys_url'], array($oldurl => $boardurl));
            $modSettings['avatar_url'] = strtr($modSettings['avatar_url'], array($oldurl => $boardurl));
            // Clean up after loadBoard().
            foreach ($board_info['moderators'] as $k => $dummy) {
                $board_info['moderators'][$k]['href'] = strtr($dummy['href'], array($oldurl => $boardurl));
                $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
            }
            foreach ($context['linktree'] as $k => $dummy) {
                $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
            }
        }
    }
    // Set up the contextual user array.
    $context['user'] = array('id' => &$ID_MEMBER, 'is_logged' => !$user_info['is_guest'], 'is_guest' => &$user_info['is_guest'], 'is_admin' => &$user_info['is_admin'], 'is_mod' => false, 'username' => &$user_info['username'], 'language' => &$user_info['language'], 'email' => &$user_info['email']);
    if ($context['user']['is_guest']) {
        $context['user']['name'] =& $txt[28];
    } else {
        $context['user']['name'] =& $user_info['name'];
    }
    // Determine the current smiley set.
    $user_info['smiley_set'] = !in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none' || empty($modSettings['smiley_sets_enable']) ? !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'] : $user_info['smiley_set'];
    $context['user']['smiley_set'] =& $user_info['smiley_set'];
    // Some basic information...
    if (!isset($context['html_headers'])) {
        $context['html_headers'] = '';
    }
    $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
    $context['session_id'] =& $sc;
    $context['forum_name'] =& $mbname;
    $context['current_action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
    if (isset($modSettings['load_average'])) {
        $context['load_average'] = $modSettings['load_average'];
    }
    // This determines the server... not used in many places, except for login fixing.
    $context['server'] = array('is_iis' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false, 'is_apache' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false, 'is_cgi' => isset($_SERVER['SERVER_SOFTWARE']) && strpos(php_sapi_name(), 'cgi') !== false, 'is_windows' => stristr(PHP_OS, 'WIN') !== false, 'iso_case_folding' => ord(strtolower(chr(138))) === 154, 'complex_preg_chars' => @version_compare(PHP_VERSION, '4.3.3') != -1);
    // A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
    $context['server']['needs_login_fix'] = $context['server']['is_cgi'];
    // The following determines the user agent (browser) as best it can.
    $context['browser'] = array('is_opera' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false, 'is_opera6' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 6') !== false, 'is_opera7' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 7') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/7') !== false, 'is_opera8' => strpos($_SERVER['HTTP_USER_AGENT'], 'Opera 8') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera/8') !== false, 'is_ie4' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 4') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') === false, 'is_safari' => strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false, 'is_mac_ie' => strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false, 'is_web_tv' => strpos($_SERVER['HTTP_USER_AGENT'], 'WebTV') !== false, 'is_konqueror' => strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror') !== false, 'is_firefox' => strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false, 'is_firefox1' => strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox/1.') !== false, 'is_firefox2' => strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox/2.') !== false);
    $context['browser']['is_gecko'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false && !$context['browser']['is_safari'] && !$context['browser']['is_konqueror'];
    // Internet Explorer 5 and 6 are often "emulated".
    $context['browser']['is_ie7'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];
    $context['browser']['is_ie6'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];
    $context['browser']['is_ie5.5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];
    $context['browser']['is_ie5'] = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.0') !== false && !$context['browser']['is_opera'] && !$context['browser']['is_gecko'] && !$context['browser']['is_web_tv'];
    $context['browser']['is_ie'] = $context['browser']['is_ie4'] || $context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie6'] || $context['browser']['is_ie7'];
    $context['browser']['needs_size_fix'] = ($context['browser']['is_ie5'] || $context['browser']['is_ie5.5'] || $context['browser']['is_ie4'] || $context['browser']['is_opera6']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false;
    // This isn't meant to be reliable, it's just meant to catch most bots to prevent PHPSESSID from showing up.
    $ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    $context['browser']['possibly_robot'] = strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') === false || strpos($ci_user_agent, 'googlebot') !== false || strpos($ci_user_agent, 'slurp') !== false || strpos($ci_user_agent, 'crawl') !== false;
    // Robots shouldn't be logging in or registering.  So, they aren't a bot.  Better to be wrong than sorry (or people won't be able to log in!), anyway.
    if (isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('login', 'login2', 'register')) || !$context['user']['is_guest']) {
        $context['browser']['possibly_robot'] = false;
    }
    // Set the top level linktree up.
    array_unshift($context['linktree'], array('url' => &$scripturl, 'name' => &$context['forum_name']));
    $txt = array();
    $simpleActions = array('findmember', 'helpadmin', 'printpage', 'quotefast', 'spellcheck');
    // Wireless mode?  Load up the wireless stuff.
    if (WIRELESS) {
        $context['template_layers'] = array(WIRELESS_PROTOCOL);
        loadTemplate('Wireless');
        loadLanguage('Wireless');
        loadLanguage('index');
    } elseif (isset($_REQUEST['xml'])) {
        loadLanguage('index');
        loadTemplate('Xml');
        $context['template_layers'] = array();
    } elseif (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $simpleActions)) {
        loadLanguage('index');
        $context['template_layers'] = array();
    } else {
        // Custom templates to load, or just default?
        if (isset($settings['theme_templates'])) {
            $templates = explode(',', $settings['theme_templates']);
        } else {
            $templates = array('index');
        }
        // Custom template layers?
        if (isset($settings['theme_layers'])) {
            $context['template_layers'] = explode(',', $settings['theme_layers']);
        } else {
            $context['template_layers'] = array('main');
        }
        // Load each template.... and attempt to load its associated language file.
        foreach ($templates as $template) {
            loadTemplate($template);
            loadLanguage($template, '', false);
        }
    }
    // Load the Modifications language file, always ;). (but don't sweat it if it doesn't exist.)
    loadLanguage('Modifications', '', false);
    // Initialize the theme.
    loadSubTemplate('init', 'ignore');
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'always') {
        $settings['theme_url'] = $settings['default_theme_url'];
        $settings['images_url'] = $settings['default_images_url'];
        $settings['theme_dir'] = $settings['default_theme_dir'];
    }
    // Set the character set from the template.
    $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
    $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
    $context['right_to_left'] = !empty($txt['lang_rtl']);
    $context['tabindex'] = 1;
    // Fix font size with HTML 4.01, etc.
    if (isset($settings['doctype'])) {
        $context['browser']['needs_size_fix'] |= $settings['doctype'] == 'html' && $context['browser']['is_ie6'];
    }
    // Compatibility.
    if (!isset($settings['theme_version'])) {
        $modSettings['memberCount'] = $modSettings['totalMembers'];
    }
}
示例#4
0
function template_footer()
{
    global $context, $settings, $modSettings, $time_start, $db_count;
    // Show the load time?  (only makes sense for the footer.)
    $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
    $context['load_time'] = round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3);
    $context['load_queries'] = $db_count;
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $settings['actual_theme_url'];
        $settings['images_url'] = $settings['actual_images_url'];
        $settings['theme_dir'] = $settings['actual_theme_dir'];
    }
    foreach (array_reverse($context['template_layers']) as $layer) {
        loadSubTemplate($layer . '_below', true);
    }
}
示例#5
0
文件: Subs.php 项目: Kheros/MMOver
function template_footer()
{
    global $context, $settings, $modSettings, $time_start, $db_count;
    // Show the load time?  (only makes sense for the footer.)
    $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
    $context['load_time'] = round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3);
    $context['load_queries'] = $db_count;
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $settings['actual_theme_url'];
        $settings['images_url'] = $settings['actual_images_url'];
        $settings['theme_dir'] = $settings['actual_theme_dir'];
    }
    foreach (array_reverse($context['template_layers']) as $layer) {
        loadSubTemplate($layer . '_below', true);
    }
    // Do not remove hard-coded text - it's in here so users cannot change the text easily. (as if it were in language file)
    if (!theme_copyright(true) && !empty($context['template_layers']) && SMF !== 'SSI' && !WIRELESS) {
        // DO NOT MODIFY THIS SECTION.  DO NOT REMOVE YOUR COPYRIGHT.
        // DOING SO VOIDS YOUR LICENSE AND IS ILLEGAL.
        echo '
			<div style="text-align: center !important; display: block !important; visibility: visible !important; font-size: large !important; font-weight: bold; color: black !important; background-color: white !important;">
				Sorry, the copyright must be in the template.<br />
				Please notify this forum\'s administrator that this site is missing the copyright message for <a href="http://www.simplemachines.org/" style="color: black !important; font-size: large !important;">SMF</a> so they can rectify the situation. Display of copyright is a <a href="http://www.simplemachines.org/about/license.php" style="color: red;">legal requirement</a>. For more information on this please visit the <a href="http://www.simplemachines.org">Simple Machines</a> website.', empty($context['user']['is_admin']) ? '' : '<br />
				Not sure why this message is appearing?  <a href="http://www.simplemachines.org/redirect/index.php?copyright_error">Take a look at some common causes.</a>', '
			</div>';
        log_error('Copyright removed!!');
    }
}
示例#6
0
function loadTheme($id_theme = 0, $initialize = true)
{
    global $user_info, $user_settings, $board_info, $sc, $boarddir;
    global $txt, $boardurl, $scripturl, $mbname, $modSettings, $language;
    global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc;
    // The theme was specified by parameter.
    if (!empty($id_theme)) {
        $id_theme = (int) $id_theme;
    } elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = (int) $_REQUEST['theme'];
        $_SESSION['id_theme'] = $id_theme;
    } elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = (int) $_SESSION['id_theme'];
    } elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
        $id_theme = $user_info['theme'];
    } elseif (!empty($board_info['theme'])) {
        $id_theme = $board_info['theme'];
    } else {
        $id_theme = $modSettings['theme_guests'];
    }
    // Verify the id_theme... no foul play.
    // Always allow the board specific theme, if they are overriding.
    if (!empty($board_info['theme']) && $board_info['override_theme']) {
        $id_theme = $board_info['theme'];
    } elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
        $id_theme = (int) $id_theme;
    } elseif (!empty($modSettings['knownThemes']) && !allowedTo('admin_forum')) {
        $themes = explode(',', $modSettings['knownThemes']);
        if (!in_array($id_theme, $themes)) {
            $id_theme = $modSettings['theme_guests'];
        } else {
            $id_theme = (int) $id_theme;
        }
    } else {
        $id_theme = (int) $id_theme;
    }
    $member = empty($user_info['id']) ? -1 : $user_info['id'];
    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) {
        $themeData = $temp;
        $flag = true;
    } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
        $themeData = $temp + array($member => array());
    } else {
        $themeData = array(-1 => array(), 0 => array(), $member => array());
    }
    if (empty($flag)) {
        // Load variables from the current or default theme, global or this user's.
        $result = $smcFunc['db_query']('', '
			SELECT variable, value, id_member, id_theme
			FROM {db_prefix}themes
			WHERE id_member' . (empty($themeData[0]) ? ' IN (-1, 0, {int:id_member})' : ' = {int:id_member}') . '
				AND id_theme' . ($id_theme == 1 ? ' = {int:id_theme}' : ' IN ({int:id_theme}, 1)'), array('id_theme' => $id_theme, 'id_member' => $member));
        // Pick between $settings and $options depending on whose data it is.
        while ($row = $smcFunc['db_fetch_assoc']($result)) {
            // There are just things we shouldn't be able to change as members.
            if ($row['id_member'] != 0 && in_array($row['variable'], 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'))) {
                continue;
            }
            // If this is the theme_dir of the default theme, store it.
            if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
                $themeData[0]['default_' . $row['variable']] = $row['value'];
            }
            // If this isn't set yet, is a theme option, or is not the default theme..
            if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
                $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
            }
        }
        $smcFunc['db_free_result']($result);
        if (!empty($themeData[-1])) {
            foreach ($themeData[-1] as $k => $v) {
                if (!isset($themeData[$member][$k])) {
                    $themeData[$member][$k] = $v;
                }
            }
        }
        if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
            cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
        } elseif (!isset($temp)) {
            cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
        }
    }
    $settings = $themeData[0];
    $options = $themeData[$member];
    $settings['theme_id'] = $id_theme;
    $settings['actual_theme_url'] = $settings['theme_url'];
    $settings['actual_images_url'] = $settings['images_url'];
    $settings['actual_theme_dir'] = $settings['theme_dir'];
    $settings['template_dirs'] = array();
    // This theme first.
    $settings['template_dirs'][] = $settings['theme_dir'];
    // Based on theme (if there is one).
    if (!empty($settings['base_theme_dir'])) {
        $settings['template_dirs'][] = $settings['base_theme_dir'];
    }
    // Lastly the default theme.
    if ($settings['theme_dir'] != $settings['default_theme_dir']) {
        $settings['template_dirs'][] = $settings['default_theme_dir'];
    }
    if (!$initialize) {
        return;
    }
    // Check to see if they're accessing it from the wrong place.
    if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) {
        $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
        $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
        $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
        if ($temp != '/') {
            $detected_url .= $temp;
        }
    }
    if (isset($detected_url) && $detected_url != $boardurl) {
        // Try #1 - check if it's in a list of alias addresses.
        if (!empty($modSettings['forum_alias_urls'])) {
            $aliases = explode(',', $modSettings['forum_alias_urls']);
            foreach ($aliases as $alias) {
                // Rip off all the boring parts, spaces, etc.
                if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
                    $do_fix = true;
                }
            }
        }
        // Hmm... check #2 - is it just different by a www?  Send them to the correct place!!
        if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') {
            // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
            if (empty($_GET)) {
                redirectexit('wwwRedirect');
            } else {
                list($k, $v) = each($_GET);
                if ($k != 'wwwRedirect') {
                    redirectexit('wwwRedirect;' . $k . '=' . $v);
                }
            }
        }
        // #3 is just a check for SSL...
        if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
            $do_fix = true;
        }
        // Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
        if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\\d\\.:]+|\\[[\\d:]+\\](?::\\d+)?)(?:$|/)~', $detected_url) == 1) {
            // Caching is good ;).
            $oldurl = $boardurl;
            // Fix $boardurl and $scripturl.
            $boardurl = $detected_url;
            $scripturl = strtr($scripturl, array($oldurl => $boardurl));
            $_SERVER['REQUEST_URL'] = strtr($_SERVER['REQUEST_URL'], array($oldurl => $boardurl));
            // Fix the theme urls...
            $settings['theme_url'] = strtr($settings['theme_url'], array($oldurl => $boardurl));
            $settings['default_theme_url'] = strtr($settings['default_theme_url'], array($oldurl => $boardurl));
            $settings['actual_theme_url'] = strtr($settings['actual_theme_url'], array($oldurl => $boardurl));
            $settings['images_url'] = strtr($settings['images_url'], array($oldurl => $boardurl));
            $settings['default_images_url'] = strtr($settings['default_images_url'], array($oldurl => $boardurl));
            $settings['actual_images_url'] = strtr($settings['actual_images_url'], array($oldurl => $boardurl));
            // And just a few mod settings :).
            $modSettings['smileys_url'] = strtr($modSettings['smileys_url'], array($oldurl => $boardurl));
            $modSettings['avatar_url'] = strtr($modSettings['avatar_url'], array($oldurl => $boardurl));
            // Clean up after loadBoard().
            if (isset($board_info['moderators'])) {
                foreach ($board_info['moderators'] as $k => $dummy) {
                    $board_info['moderators'][$k]['href'] = strtr($dummy['href'], array($oldurl => $boardurl));
                    $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
                }
            }
            foreach ($context['linktree'] as $k => $dummy) {
                $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
            }
        }
    }
    // Set up the contextual user array.
    $context['user'] = array('id' => $user_info['id'], 'is_logged' => !$user_info['is_guest'], 'is_guest' => &$user_info['is_guest'], 'is_admin' => &$user_info['is_admin'], 'is_mod' => &$user_info['is_mod'], 'can_mod' => allowedTo('access_mod_center') || !$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'username' => $user_info['username'], 'language' => $user_info['language'], 'email' => $user_info['email'], 'ignoreusers' => $user_info['ignoreusers']);
    if (!$context['user']['is_guest']) {
        $context['user']['name'] = $user_info['name'];
    } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
        $context['user']['name'] = $txt['guest_title'];
    }
    // Determine the current smiley set.
    $user_info['smiley_set'] = !in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none' || empty($modSettings['smiley_sets_enable']) ? !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'] : $user_info['smiley_set'];
    $context['user']['smiley_set'] = $user_info['smiley_set'];
    // Some basic information...
    if (!isset($context['html_headers'])) {
        $context['html_headers'] = '';
    }
    $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
    $context['session_var'] = $_SESSION['session_var'];
    $context['session_id'] = $_SESSION['session_value'];
    $context['forum_name'] = $mbname;
    $context['forum_name_html_safe'] = $smcFunc['htmlspecialchars']($context['forum_name']);
    $context['header_logo_url_html_safe'] = empty($settings['header_logo_url']) ? '' : $smcFunc['htmlspecialchars']($settings['header_logo_url']);
    $context['current_action'] = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
    $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
    if (isset($modSettings['load_average'])) {
        $context['load_average'] = $modSettings['load_average'];
    }
    // Set some permission related settings.
    $context['show_login_bar'] = $user_info['is_guest'] && !empty($modSettings['enableVBStyleLogin']);
    // This determines the server... not used in many places, except for login fixing.
    $context['server'] = array('is_iis' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false, 'is_apache' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false, 'is_lighttpd' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false, 'is_nginx' => isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false, 'is_cgi' => isset($_SERVER['SERVER_SOFTWARE']) && strpos(php_sapi_name(), 'cgi') !== false, 'is_windows' => strpos(PHP_OS, 'WIN') === 0, 'iso_case_folding' => ord(strtolower(chr(138))) === 154, 'complex_preg_chars' => @version_compare(PHP_VERSION, '4.3.3') != -1);
    // A bug in some versions of IIS under CGI (older ones) makes cookie setting not work with Location: headers.
    $context['server']['needs_login_fix'] = $context['server']['is_cgi'] && $context['server']['is_iis'];
    // Detect the browser. This is separated out because it's also used in attachment downloads
    detectBrowser();
    // Set the top level linktree up.
    array_unshift($context['linktree'], array('url' => $scripturl, 'name' => $context['forum_name_html_safe']));
    // This allows sticking some HTML on the page output - useful for controls.
    $context['insert_after_template'] = '';
    if (!isset($txt)) {
        $txt = array();
    }
    $simpleActions = array('findmember', 'helpadmin', 'printpage', 'quotefast', 'spellcheck');
    // Wireless mode?  Load up the wireless stuff.
    if (WIRELESS) {
        $context['template_layers'] = array(WIRELESS_PROTOCOL);
        loadTemplate('Wireless');
        loadLanguage('Wireless+index+Modifications');
    } elseif (isset($_REQUEST['xml'])) {
        loadLanguage('index+Modifications');
        loadTemplate('Xml');
        $context['template_layers'] = array();
    } elseif (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $simpleActions)) {
        loadLanguage('index+Modifications');
        $context['template_layers'] = array();
    } else {
        // Custom templates to load, or just default?
        if (isset($settings['theme_templates'])) {
            $templates = explode(',', $settings['theme_templates']);
        } else {
            $templates = array('index');
        }
        // Load each template...
        foreach ($templates as $template) {
            loadTemplate($template);
        }
        // ...and attempt to load their associated language files.
        $required_files = implode('+', array_merge($templates, array('Modifications')));
        loadLanguage($required_files, '', false);
        // Custom template layers?
        if (isset($settings['theme_layers'])) {
            $context['template_layers'] = explode(',', $settings['theme_layers']);
        } else {
            $context['template_layers'] = array('html', 'body');
        }
    }
    // Initialize the theme.
    loadSubTemplate('init', 'ignore');
    // Load the compatibility stylesheet if the theme hasn't been updated for 2.0 RC2 (yet).
    if (isset($settings['theme_version']) && (version_compare($settings['theme_version'], '2.0 RC2', '<') || strpos($settings['theme_version'], '2.0 Beta') !== false)) {
        loadTemplate(false, 'compat');
    }
    // Guests may still need a name.
    if ($context['user']['is_guest'] && empty($context['user']['name'])) {
        $context['user']['name'] = $txt['guest_title'];
    }
    // Any theme-related strings that need to be loaded?
    if (!empty($settings['require_theme_strings'])) {
        loadLanguage('ThemeStrings', '', false);
    }
    // We allow theme variants, because we're cool.
    $context['theme_variant'] = '';
    $context['theme_variant_url'] = '';
    if (!empty($settings['theme_variants'])) {
        // Overriding - for previews and that ilk.
        if (!empty($_REQUEST['variant'])) {
            $_SESSION['id_variant'] = $_REQUEST['variant'];
        }
        // User selection?
        if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
            $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
        }
        // If not a user variant, select the default.
        if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
            $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
        }
        // Do this to keep things easier in the templates.
        $context['theme_variant'] = '_' . $context['theme_variant'];
        $context['theme_variant_url'] = $context['theme_variant'] . '/';
    }
    // Let's be compatible with old themes!
    if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
        $context['template_layers'] = array('main');
    }
    // Allow overriding the board wide time/number formats.
    if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
        $user_info['time_format'] = $txt['time_format'];
    }
    $txt['number_format'] = empty($txt['number_format']) ? empty($modSettings['number_format']) ? '' : $modSettings['number_format'] : $txt['number_format'];
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'always') {
        $settings['theme_url'] = $settings['default_theme_url'];
        $settings['images_url'] = $settings['default_images_url'];
        $settings['theme_dir'] = $settings['default_theme_dir'];
    }
    // Make a special URL for the language.
    $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
    // Set the character set from the template.
    $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
    $context['utf8'] = $context['character_set'] === 'UTF-8' && (strpos(strtolower(PHP_OS), 'win') === false || @version_compare(PHP_VERSION, '4.2.3') != -1);
    $context['right_to_left'] = !empty($txt['lang_rtl']);
    $context['tabindex'] = 1;
    // Fix font size with HTML 4.01, etc.
    if (isset($settings['doctype'])) {
        $context['browser']['needs_size_fix'] |= $settings['doctype'] == 'html' && $context['browser']['is_ie6'];
    }
    // Compatibility.
    if (!isset($settings['theme_version'])) {
        $modSettings['memberCount'] = $modSettings['totalMembers'];
    }
    // This allows us to change the way things look for the admin.
    $context['admin_features'] = isset($modSettings['admin_features']) ? explode(',', $modSettings['admin_features']) : array('cd,cp,k,w,rg,ml,pm');
    // If we think we have mail to send, let's offer up some possibilities... robots get pain (Now with scheduled task support!)
    if (!empty($modSettings['mail_next_send']) && $modSettings['mail_next_send'] < time() && empty($modSettings['mail_queue_use_cron']) || empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
        if ($context['browser']['possibly_robot']) {
            //!!! Maybe move this somewhere better?!
            require_once $sourcedir . '/ScheduledTasks.php';
            // What to do, what to do?!
            if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
                AutoTask();
            } else {
                ReduceMailQueue();
            }
        } else {
            $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
            $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
            $context['html_headers'] .= '
	<script type="text/javascript">
		function smfAutoTask()
		{
			var tempImage = new Image();
			tempImage.src = "' . $scripturl . '?scheduled=' . $type . ';ts=' . $ts . '";
		}
		window.setTimeout("smfAutoTask();", 1);
	</script>';
        }
    }
    // Any files to include at this point?
    if (!empty($modSettings['integrate_theme_include'])) {
        $theme_includes = explode(',', $modSettings['integrate_theme_include']);
        foreach ($theme_includes as $include) {
            $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
            if (file_exists($include)) {
                require_once $include;
            }
        }
    }
    // Call load theme integration functions.
    call_integration_hook('integrate_load_theme');
    // We are ready to go.
    $context['theme_loaded'] = true;
}
示例#7
0
文件: Themes.php 项目: Kheros/MMOver
function SetThemeSettings()
{
    global $txt, $context, $settings, $modSettings, $sourcedir, $smcFunc;
    if (empty($_GET['th']) && empty($_GET['id'])) {
        return ThemeAdmin();
    }
    $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
    // Select the best fitting tab.
    $context[$context['admin_menu_name']]['current_subsection'] = 'list';
    loadLanguage('Admin');
    isAllowedTo('admin_forum');
    // Validate inputs/user.
    if (empty($_GET['th'])) {
        fatal_lang_error('no_theme', false);
    }
    // Fetch the smiley sets...
    $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
    $set_names = explode("\n", $txt['smileys_none'] . "\n" . $modSettings['smiley_sets_names']);
    $context['smiley_sets'] = array('' => $txt['smileys_no_default']);
    foreach ($sets as $i => $set) {
        $context['smiley_sets'][$set] = htmlspecialchars($set_names[$i]);
    }
    $old_id = $settings['theme_id'];
    $old_settings = $settings;
    loadTheme($_GET['th'], false);
    // Sadly we really do need to init the template.
    loadSubTemplate('init', 'ignore');
    // Also load the actual themes language file - in case of special settings.
    loadLanguage('Settings', '', true, true);
    // Let the theme take care of the settings.
    loadTemplate('Settings');
    loadSubTemplate('settings');
    // Submitting!
    if (isset($_POST['submit'])) {
        checkSession();
        if (empty($_POST['options'])) {
            $_POST['options'] = array();
        }
        if (empty($_POST['default_options'])) {
            $_POST['default_options'] = array();
        }
        // Make sure items are cast correctly.
        foreach ($context['theme_settings'] as $item) {
            // Disregard this item if this is just a separator.
            if (!is_array($item)) {
                continue;
            }
            foreach (array('options', 'default_options') as $option) {
                if (!isset($_POST[$option][$item['id']])) {
                    continue;
                } elseif (empty($item['type'])) {
                    $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
                } elseif ($item['type'] == 'number') {
                    $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
                }
            }
        }
        // Set up the sql query.
        $inserts = array();
        foreach ($_POST['options'] as $opt => $val) {
            $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val);
        }
        foreach ($_POST['default_options'] as $opt => $val) {
            $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val);
        }
        // If we're actually inserting something..
        if (!empty($inserts)) {
            $smcFunc['db_insert']('replace', '{db_prefix}themes', array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), $inserts, array('id_member', 'id_theme', 'variable'));
        }
        cache_put_data('theme_settings-' . $_GET['th'], null, 90);
        cache_put_data('theme_settings-1', null, 90);
        // Invalidate the cache.
        updateSettings(array('settings_updated' => time()));
        redirectexit('action=admin;area=theme;sa=settings;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id']);
    }
    $context['sub_template'] = 'set_settings';
    $context['page_title'] = $txt['theme_settings'];
    foreach ($settings as $setting => $dummy) {
        if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
            $settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
        }
    }
    $context['settings'] = $context['theme_settings'];
    $context['theme_settings'] = $settings;
    foreach ($context['settings'] as $i => $setting) {
        // Separators are dummies, so leave them alone.
        if (!is_array($setting)) {
            continue;
        }
        if (!isset($setting['type']) || $setting['type'] == 'bool') {
            $context['settings'][$i]['type'] = 'checkbox';
        } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
            $context['settings'][$i]['type'] = 'number';
        } elseif ($setting['type'] == 'string') {
            $context['settings'][$i]['type'] = 'text';
        }
        if (isset($setting['options'])) {
            $context['settings'][$i]['type'] = 'list';
        }
        $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
    }
    // Do we support variants?
    if (!empty($settings['theme_variants'])) {
        $context['theme_variants'] = array();
        foreach ($settings['theme_variants'] as $variant) {
            // Have any text, old chap?
            $context['theme_variants'][$variant] = array('label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, 'thumbnail' => !file_exists($settings['theme_dir'] . '/images/thumbnail.gif') || file_exists($settings['theme_dir'] . '/images/thumbnail_' . $variant . '.gif') ? $settings['images_url'] . '/thumbnail_' . $variant . '.gif' : $settings['images_url'] . '/thumbnail.gif');
        }
        $context['default_variant'] = !empty($settings['default_variant']) && isset($context['theme_variants'][$settings['default_variant']]) ? $settings['default_variant'] : $settings['theme_variants'][0];
    }
    // Restore the current theme.
    loadTheme($old_id, false);
    // Reinit just incase.
    loadSubTemplate('init', 'ignore');
    $settings = $old_settings;
    loadTemplate('Themes');
}
示例#8
0
文件: Errors.php 项目: norv/EosAlpha
function setup_fatal_error_context($error_message)
{
    global $context, $txt, $ssi_on_error_method;
    static $level = 0;
    // Attempt to prevent a recursive loop.
    ++$level;
    if ($level > 1) {
        return false;
    }
    // Maybe they came from dlattach or similar?
    if (SMF != 'SSI' && empty($context['theme_loaded'])) {
        loadTheme();
    }
    // Don't bother indexing errors mate...
    $context['robot_no_index'] = true;
    if (!isset($context['error_title'])) {
        $context['error_title'] = $txt['error_occured'];
    }
    $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
    if (empty($context['page_title'])) {
        $context['page_title'] = $context['error_title'];
    }
    EoS_Smarty::resetTemplates();
    // discard all templates loaded so far. We don't need them any longer
    EoS_Smarty::loadTemplate('errors');
    // If this is SSI, what do they want us to do?
    if (SMF == 'SSI') {
        if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
            call_user_func($ssi_on_error_method);
        } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
            loadSubTemplate('fatal_error');
        }
        // No layers?
        if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
            exit;
        }
    }
    // We want whatever for the header, and a footer. (footer includes sub template!)
    obExit(null, true, false, true);
    /* DO NOT IGNORE:
    		If you are creating a bridge to SMF or modifying this function, you MUST
    		make ABSOLUTELY SURE that this function quits and DOES NOT RETURN TO NORMAL
    		PROGRAM FLOW.  Otherwise, security error messages will not be shown, and
    		your forum will be in a very easily hackable state.
    	*/
    trigger_error('Hacking attempt...', E_USER_ERROR);
}
示例#9
0
文件: Errors.php 项目: KeiroD/Elkarte
/**
 * It is called by fatal_error() and fatal_lang_error().
 *
 * @uses Errors template, fatal_error sub template
 * @param string $error_message
 * @param string $error_code string or int code
 */
function setup_fatal_error_context($error_message, $error_code)
{
    global $context, $txt, $ssi_on_error_method;
    static $level = 0;
    // Attempt to prevent a recursive loop.
    ++$level;
    if ($level > 1) {
        return false;
    }
    // Maybe they came from dlattach or similar?
    if (ELK != 'SSI' && empty($context['theme_loaded'])) {
        loadTheme();
    }
    // Don't bother indexing errors mate...
    $context['robot_no_index'] = true;
    if (!isset($context['error_title'])) {
        $context['error_title'] = $txt['error_occurred'];
    }
    $context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
    $context['error_code'] = isset($error_code) ? 'id="' . htmlspecialchars($error_code) . '" ' : '';
    if (empty($context['page_title'])) {
        $context['page_title'] = $context['error_title'];
    }
    // Load the template and set the sub template.
    loadTemplate('Errors');
    $context['sub_template'] = 'fatal_error';
    // If this is SSI, what do they want us to do?
    if (ELK == 'SSI') {
        if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
            $ssi_on_error_method();
        } elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
            loadSubTemplate('fatal_error');
        }
        // No layers?
        if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
            exit;
        }
    }
    // We want whatever for the header, and a footer. (footer includes sub template!)
    obExit(null, true, false, true);
    /* DO NOT IGNORE:
    		If you are creating a bridge or modifying this function, you MUST
    		make ABSOLUTELY SURE that this function quits and DOES NOT RETURN TO NORMAL
    		PROGRAM FLOW.  Otherwise, security error messages will not be shown, and
    		your forum will be in a very easily hackable state.
    	*/
    trigger_error('Hacking attempt...', E_USER_ERROR);
}
 /**
  * Administrative global settings.
  *
  * What it does:
  * - Saves and requests global theme settings. ($settings)
  * - Loads the Admin language file.
  * - Calls action_admin() if no theme is specified. (the theme center.)
  * - Requires admin_forum permission.
  * - Accessed with ?action=admin;area=theme;sa=list&th=xx.
  */
 public function action_setthemesettings()
 {
     global $txt, $context, $settings, $modSettings;
     require_once SUBSDIR . '/Themes.subs.php';
     // Nothing chosen, back to the start you go
     if (empty($_GET['th']) && empty($_GET['id'])) {
         return $this->action_admin();
     }
     // The theme's ID is needed
     $theme = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
     // Validate inputs/user.
     if (empty($theme)) {
         fatal_lang_error('no_theme', false);
     }
     // Select the best fitting tab.
     $context[$context['admin_menu_name']]['current_subsection'] = 'list';
     loadLanguage('Admin');
     // Fetch the smiley sets...
     $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
     $set_names = explode("\n", $txt['smileys_none'] . "\n" . $modSettings['smiley_sets_names']);
     $context['smiley_sets'] = array('' => $txt['smileys_no_default']);
     foreach ($sets as $i => $set) {
         $context['smiley_sets'][$set] = htmlspecialchars($set_names[$i], ENT_COMPAT, 'UTF-8');
     }
     $old_id = $settings['theme_id'];
     $old_settings = $settings;
     loadTheme($theme, false);
     // Also load the actual themes language file - in case of special settings.
     loadLanguage('Settings', '', true, true);
     // And the custom language strings...
     loadLanguage('ThemeStrings', '', false, true);
     // Let the theme take care of the settings.
     loadTemplate('Settings');
     loadSubTemplate('settings');
     // Load the variants separately...
     $settings['theme_variants'] = array();
     if (file_exists($settings['theme_dir'] . '/index.template.php')) {
         $file_contents = implode("\n", file($settings['theme_dir'] . '/index.template.php'));
         if (preg_match('~\'theme_variants\'\\s*=>(.+?\\)),$~sm', $file_contents, $matches)) {
             eval('global $settings; $settings[\'theme_variants\'] = ' . $matches[1] . ';');
         }
         call_integration_hook('integrate_init_theme', array($theme, &$settings));
     }
     // Submitting!
     if (isset($_POST['save'])) {
         // Allowed?
         checkSession();
         validateToken('admin-sts');
         if (empty($_POST['options'])) {
             $_POST['options'] = array();
         }
         if (empty($_POST['default_options'])) {
             $_POST['default_options'] = array();
         }
         // Make sure items are cast correctly.
         foreach ($context['theme_settings'] as $item) {
             // Unwatch this item if this is just a separator.
             if (!is_array($item)) {
                 continue;
             }
             // Clean them up for the database
             foreach (array('options', 'default_options') as $option) {
                 if (!isset($_POST[$option][$item['id']])) {
                     continue;
                 } elseif (empty($item['type'])) {
                     $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0;
                 } elseif ($item['type'] == 'number') {
                     $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']];
                 }
             }
         }
         // Set up the sql query.
         $inserts = array();
         foreach ($_POST['options'] as $opt => $val) {
             $inserts[] = array($theme, 0, $opt, is_array($val) ? implode(',', $val) : $val);
         }
         foreach ($_POST['default_options'] as $opt => $val) {
             $inserts[] = array(1, 0, $opt, is_array($val) ? implode(',', $val) : $val);
         }
         // If we're actually inserting something..
         if (!empty($inserts)) {
             updateThemeOptions($inserts);
         }
         // Clear and Invalidate the cache.
         cache_put_data('theme_settings-' . $theme, null, 90);
         cache_put_data('theme_settings-1', null, 90);
         updateSettings(array('settings_updated' => time()));
         redirectexit('action=admin;area=theme;sa=list;th=' . $theme . ';' . $context['session_var'] . '=' . $context['session_id']);
     }
     $context['sub_template'] = 'set_settings';
     $context['page_title'] = $txt['theme_settings'];
     foreach ($settings as $setting => $dummy) {
         if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) {
             $settings[$setting] = htmlspecialchars__recursive($settings[$setting]);
         }
     }
     $context['settings'] = $context['theme_settings'];
     $context['theme_settings'] = $settings;
     foreach ($context['settings'] as $i => $setting) {
         // Separators are dummies, so leave them alone.
         if (!is_array($setting)) {
             continue;
         }
         // Create the right input fields for the data
         if (!isset($setting['type']) || $setting['type'] == 'bool') {
             $context['settings'][$i]['type'] = 'checkbox';
         } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
             $context['settings'][$i]['type'] = 'number';
         } elseif ($setting['type'] == 'string') {
             $context['settings'][$i]['type'] = 'text';
         }
         if (isset($setting['options'])) {
             $context['settings'][$i]['type'] = 'list';
         }
         $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
     }
     // Do we support variants?
     if (!empty($settings['theme_variants'])) {
         $context['theme_variants'] = array();
         foreach ($settings['theme_variants'] as $variant) {
             // Have any text, old chap?
             $context['theme_variants'][$variant] = array('label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, 'thumbnail' => !file_exists($settings['theme_dir'] . '/images/thumbnail.png') || file_exists($settings['theme_dir'] . '/images/thumbnail_' . $variant . '.png') ? $settings['images_url'] . '/thumbnail_' . $variant . '.png' : $settings['images_url'] . '/thumbnail.png');
         }
         $context['default_variant'] = !empty($settings['default_variant']) && isset($context['theme_variants'][$settings['default_variant']]) ? $settings['default_variant'] : $settings['theme_variants'][0];
     }
     // Restore the current theme.
     loadTheme($old_id, false);
     $settings = $old_settings;
     // Reinit just incase.
     if (function_exists('template_init')) {
         $settings += template_init();
     }
     loadTemplate('ManageThemes');
     // We like Kenny better than Token.
     createToken('admin-sts');
 }
示例#11
0
文件: Themes.php 项目: alencarmo/OCF
function SetThemeSettings()
{
    global $txt, $sc, $context, $settings, $db_prefix, $modSettings;
    if (empty($_GET['th']) && empty($_GET['id'])) {
        return ThemeAdmin();
    }
    $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id'];
    // Select the best fitting tab.
    $context['admin_tabs']['tabs']['list']['is_selected'] = true;
    loadLanguage('Admin');
    isAllowedTo('admin_forum');
    // Just for navigation, show some nice bar on the left.
    adminIndex($settings['theme_id'] == $_GET['th'] ? 'edit_theme_settings' : 'manage_themes');
    // Validate inputs/user.
    if (empty($_GET['th'])) {
        fatal_lang_error('theme3', false);
    }
    // Submitting!
    if (isset($_POST['submit'])) {
        checkSession();
        if (empty($_POST['options'])) {
            $_POST['options'] = array();
        }
        if (empty($_POST['default_options'])) {
            $_POST['default_options'] = array();
        }
        // Set up the sql query.
        $setString = '';
        foreach ($_POST['options'] as $opt => $val) {
            $setString .= "\n\t\t\t\t(0, {$_GET['th']}, SUBSTRING('{$opt}', 1, 255), SUBSTRING('" . (is_array($val) ? implode(',', $val) : $val) . "', 1, 65534)),";
        }
        foreach ($_POST['default_options'] as $opt => $val) {
            $setString .= "\n\t\t\t\t(0, 1, SUBSTRING('{$opt}', 1, 255), SUBSTRING('" . (is_array($val) ? implode(',', $val) : $val) . "', 1, 65534)),";
        }
        // If we're actually inserting something..
        if ($setString != '') {
            // Get rid of the last comma.
            $setString = substr($setString, 0, -1);
            db_query("\n\t\t\t\tREPLACE INTO {$db_prefix}themes\n\t\t\t\t\t(ID_MEMBER, ID_THEME, variable, value)\n\t\t\t\tVALUES {$setString}", __FILE__, __LINE__);
        }
        cache_put_data('theme_settings-' . $_GET['th'], null, 90);
        cache_put_data('theme_settings-1', null, 90);
        redirectexit('action=theme;sa=settings;th=' . $_GET['th'] . ';sesc=' . $sc);
    }
    checkSession('get');
    // Fetch the smiley sets...
    $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']);
    $set_names = explode("\n", $txt['smileys_none'] . "\n" . $modSettings['smiley_sets_names']);
    $context['smiley_sets'] = array('' => $txt['smileys_no_default']);
    foreach ($sets as $i => $set) {
        $context['smiley_sets'][$set] = $set_names[$i];
    }
    $old_id = $settings['theme_id'];
    $old_settings = $settings;
    loadTheme($_GET['th'], false);
    // Let the theme take care of the settings.
    loadTemplate('Settings');
    loadSubTemplate('settings');
    $context['sub_template'] = 'set_settings';
    $context['page_title'] = $txt['theme4'];
    foreach ($settings as $setting => $dummy) {
        if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url'))) {
            $settings[$setting] = htmlspecialchars($settings[$setting]);
        }
    }
    $context['settings'] = $context['theme_settings'];
    $context['theme_settings'] = $settings;
    foreach ($context['settings'] as $i => $setting) {
        if (!isset($setting['type']) || $setting['type'] == 'bool') {
            $context['settings'][$i]['type'] = 'checkbox';
        } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') {
            $context['settings'][$i]['type'] = 'number';
        } elseif ($setting['type'] == 'string') {
            $context['settings'][$i]['type'] = 'text';
        }
        if (isset($setting['options'])) {
            $context['settings'][$i]['type'] = 'list';
        }
        $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']];
    }
    // Restore the current theme.
    loadTheme($old_id, false);
    $settings = $old_settings;
    loadTemplate('Themes');
}
示例#12
0
function template_footer()
{
    global $context, $settings, $modSettings, $time_start, $db_count;
    // Show the load time?  (only makes sense for the footer.)
    $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
    $context['load_time'] = round(array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)), 3);
    $context['load_queries'] = $db_count;
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $settings['actual_theme_url'];
        $settings['images_url'] = $settings['actual_images_url'];
        $settings['theme_dir'] = $settings['actual_theme_dir'];
    }
    foreach (array_reverse($context['template_layers']) as $layer) {
        //-- SMFHacks.com; Global Headers and Footers
        if ($layer == 'body' && (empty($context['uninstalling']) && (!isset($_GET['package']) || !stripos($_GET['package'], 'Global-Headers-and-Footers')))) {
            global $sourcedir;
            require_once $sourcedir . '/smfhacks_source/global-hf.php';
            retrieveGlobalHFContent('_below');
        }
        // End SMFHacks.com; Global Headers and Footers --//
        loadSubTemplate($layer . '_below', true);
    }
}
示例#13
0
/**
 * The template footer
 */
function template_footer()
{
    global $context, $settings, $modSettings, $time_start, $db_count;
    // Show the load time?  (only makes sense for the footer.)
    $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
    $context['load_time'] = round(microtime(true) - $time_start, 3);
    $context['load_queries'] = $db_count;
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $settings['actual_theme_url'];
        $settings['images_url'] = $settings['actual_images_url'];
        $settings['theme_dir'] = $settings['actual_theme_dir'];
    }
    foreach (Template_Layers::getInstance()->reverseLayers() as $layer) {
        loadSubTemplate($layer . '_below', 'ignore');
    }
}
示例#14
0
文件: Subs.php 项目: norv/EosAlpha
function template_footer()
{
    global $context, $settings, $modSettings;
    // Show the load time?  (only makes sense for the footer.)
    $context['show_load_time'] = !empty($modSettings['timeLoadPageEnable']);
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $settings['actual_theme_url'];
        $settings['images_url'] = $settings['actual_images_url'];
        $settings['theme_dir'] = $settings['actual_theme_dir'];
    }
    foreach (array_reverse($context['template_layers']) as $layer) {
        loadSubTemplate($layer . '_below', true);
    }
}