mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
themes: MDL-19077 change how the theme is initialised and CSS is served.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F $THEME is now initialised at the same time as $OUTPUT. Old functions like theme_setup are deprecated in favour of methods on $PAGE. There is a new theme_config class in outputlib.php that deals with loading the theme config.php file. CSS used to be served by themes styles.php files calling a function in weblib.php. Now it works by each theme's styles.php file doing $themename = basename(dirname(__FILE__)); require_once(dirname(__FILE__) . '/../../theme/styles.php'); which is less code to be copied into each theme. (Old-style styles.php files still work thanks to some code in deprecatedlib.php.) Admin UI for choosing a theme cleaned up. A couple of theme-specific hard-coded hacks like $THEME->cssconstants and $THEME->CSSEdit have been replaced by a more generic $THEME->customcssoutputfunction hook. See examples at the end of outputlib.php Also: * Fix setting the theme in the URL, which seems to have been broken since 1.9. * Fix up errors on a few pages caused by the new initialisation order. * MDL-19097 moodle_page::set_course should not set $COURSE unless it is $PAGE. * httpsrequired() from moodlelib.php moved to $PAGE->https_required(). * Move has_started() method to the renderer base class. * Further fixes to display of early errors. * Remove print_header/footer_old from weblib. I did not mean to commit them before.
This commit is contained in:
parent
0456fc1ac4
commit
b70094743a
37 changed files with 1646 additions and 1531 deletions
|
@ -126,7 +126,7 @@ global $MCACHE;
|
|||
* A global to define if the page being displayed must run under HTTPS.
|
||||
*
|
||||
* Its primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false.
|
||||
* Its enabled only by the httpsrequired() function and used in some pages to update some URLs
|
||||
* Its enabled only by the $PAGE->https_required() function and used in some pages to update some URLs
|
||||
*
|
||||
* @global bool $HTTPSPAGEREQUIRED
|
||||
* @name $HTTPSPAGEREQUIRED
|
||||
|
@ -188,13 +188,10 @@ global $SCRIPT;
|
|||
}
|
||||
|
||||
|
||||
/// store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
|
||||
/// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
|
||||
$CFG->config_php_settings = (array)$CFG;
|
||||
|
||||
/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
||||
/// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
|
||||
/// Set up some paths.
|
||||
$CFG->libdir = $CFG->dirroot .'/lib';
|
||||
|
||||
if (!isset($CFG->themedir)) {
|
||||
|
@ -202,6 +199,11 @@ global $SCRIPT;
|
|||
$CFG->themewww = $CFG->wwwroot.'/theme';
|
||||
}
|
||||
|
||||
/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
||||
/// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
$CFG->httpsthemewww = $CFG->themewww;
|
||||
|
||||
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
|
||||
|
||||
/// Time to start counting
|
||||
|
@ -524,20 +526,18 @@ global $SCRIPT;
|
|||
$SESSION = &$_SESSION['SESSION'];
|
||||
$USER = &$_SESSION['USER'];
|
||||
|
||||
/// Load up theme variables (colours etc)
|
||||
|
||||
$CFG->httpsthemewww = $CFG->themewww;
|
||||
|
||||
if (isset($_GET['theme'])) {
|
||||
if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
|
||||
$themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
|
||||
if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
|
||||
$SESSION->theme = $themename;
|
||||
}
|
||||
unset($themename);
|
||||
/// Process theme change in the URL.
|
||||
if (!empty($CFG->allowthemechangeonurl) && ($urlthemename = optional_param('theme', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||
try {
|
||||
theme_config::load($urlthemename); // Makes sure the theme can be loaded without errors.
|
||||
$SESSION->theme = $urlthemename;
|
||||
} catch (Exception $e) {
|
||||
debugging('Failed to set the theme from the URL.', DEBUG_DEVELOPER, $e->getTrace());
|
||||
}
|
||||
}
|
||||
unset($urlthemename);
|
||||
|
||||
/// Ensure a valid theme is set.
|
||||
if (!isset($CFG->theme)) {
|
||||
$CFG->theme = 'standardwhite';
|
||||
}
|
||||
|
@ -547,19 +547,19 @@ global $SCRIPT;
|
|||
/// in the language file. Otherwise, if the admin hasn't specified a locale
|
||||
/// then use the one from the default language. Otherwise (and this is the
|
||||
/// majority of cases), use the stored locale specified by admin.
|
||||
if (isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
||||
if (($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
|
||||
if (file_exists($CFG->dataroot .'/lang/'. $lang) or
|
||||
file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
||||
$SESSION->lang = $lang;
|
||||
} else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
|
||||
file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
|
||||
file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
|
||||
$SESSION->lang = $lang.'_utf8';
|
||||
}
|
||||
}
|
||||
unset($lang);
|
||||
|
||||
setup_lang_from_browser();
|
||||
|
||||
unset($lang);
|
||||
|
||||
if (empty($CFG->lang)) {
|
||||
if (empty($SESSION->lang)) {
|
||||
$CFG->lang = 'en_utf8';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue