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:
tjhunt 2009-07-01 05:54:26 +00:00
parent 0456fc1ac4
commit b70094743a
37 changed files with 1646 additions and 1531 deletions

View file

@ -1765,6 +1765,55 @@ class custom_corners_renderer_factory extends standard_renderer_factory {
}
/**
* Used to be used for setting up the theme. No longer used by core code, and
* should not have been used elsewhere.
*
* The theme is now automatically initialised before it is first used. If you really need
* to force this to happen, just reference $PAGE->theme.
*
* To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
* However, I can't think of any valid reason to do that outside the theme selector UI.
*
* @deprecated
* @param string $theme The theme to use defaults to current theme
* @param array $params An array of parameters to use
*/
function theme_setup($theme = '', $params=NULL) {
throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
'The current theme gets initialised automatically before it is first used.');
}
/**
* @deprecated use $PAGE->theme->name instead.
* @return string the name of the current theme.
*/
function current_theme() {
global $PAGE;
// TODO, uncomment this once we have eliminated all references to current_theme in core code.
// debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
return $PAGE->theme->name;
}
/**
* This used to be the thing that theme styles.php files used to do all the work.
* This is now handled differently. You should copy theme/standard/styes.php
* into your theme.
*
* @deprecated
* @param int $lastmodified Always gets set to now
* @param int $lifetime The max-age header setting (seconds) defaults to 300
* @param string $themename The name of the theme to use (optional) defaults to current theme
* @param string $forceconfig Force a particular theme config (optional)
* @param string $lang Load styles for the specified language (optional)
*/
function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='', $forceconfig='', $lang='') {
global $CFG, $PAGE, $THEME, $showdeprecatedstylesheetsetupwarning;
$showdeprecatedstylesheetsetupwarning = true;
include($CFG->dirroot . '/theme/styles.php');
exit;
}
/**
* Prints some red text using echo
*