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

@ -1,41 +1,49 @@
<?php // $Id$
<?php
require_once("../config.php");
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
$preview = optional_param('preview','standard',PARAM_FILE); // which theme to show
/**
* This page alows you to preview an arbitrary theme before selecting it.
*/
if (!file_exists($CFG->themedir .'/'. $preview)) {
$preview = 'standard';
}
require_once("../config.php");
if (!$site = get_site()) {
print_error('siteisnotdefined', 'debug');
}
$preview = optional_param('preview','standard',PARAM_FILE); // which theme to show
require_login();
if (!file_exists($CFG->themedir .'/'. $preview)) {
$preview = 'standard';
}
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
require_login();
$CFG->theme = $preview;
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
theme_setup($CFG->theme, array('forceconfig='.$CFG->theme));
$PAGE->force_theme($preview);
$stradministration = get_string("administration");
$strconfiguration = get_string("configuration");
$strthemes = get_string("themes");
$strpreview = get_string("preview");
$strsavechanges = get_string("savechanges");
$strtheme = get_string("theme");
$strthemesaved = get_string("themesaved");
$strthemes = get_string('themes');
$strpreview = get_string('preview');
$navlinks = array();
$navlinks[] = array('name' => $strthemes, 'link' => null, 'type' => 'misc');
$navlinks[] = array('name' => $strpreview, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->shortname: $strpreview", $site->fullname, $navigation);
$navlinks = array();
$navlinks[] = array('name' => $strthemes, 'link' => null, 'type' => 'misc');
$navlinks[] = array('name' => $strpreview, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$SITE->shortname: $strpreview", $SITE->fullname, $navigation);
print_box_start();
print_heading($preview);
print_box_end();
print_box_start();
print_heading($preview);
print_box_end();
print_footer();
print_footer();