mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Really big cleanup of how "forced" themes were implemented.
Course themes now work better. theme/xxxx/styles.php is now really short because all the logic is in weblib.php.
This commit is contained in:
parent
373d5f2083
commit
9c4e6e2177
4 changed files with 99 additions and 118 deletions
|
@ -1769,11 +1769,10 @@ function current_theme() {
|
||||||
* @param int $lastmodified ?
|
* @param int $lastmodified ?
|
||||||
* @param int $lifetime ?
|
* @param int $lifetime ?
|
||||||
* @param string $thename ?
|
* @param string $thename ?
|
||||||
* @todo Finish documenting this function
|
|
||||||
*/
|
*/
|
||||||
function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') {
|
function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='', $forceconfig='') {
|
||||||
|
|
||||||
global $CFG;
|
global $CFG, $THEME;
|
||||||
|
|
||||||
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
|
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastmodified) . ' GMT');
|
||||||
header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
|
header('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
|
||||||
|
@ -1781,15 +1780,67 @@ function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='') {
|
||||||
header('Pragma: ');
|
header('Pragma: ');
|
||||||
header('Content-type: text/css'); // Correct MIME type
|
header('Content-type: text/css'); // Correct MIME type
|
||||||
|
|
||||||
if (!empty($themename)) {
|
$DEFAULT_SHEET_LIST = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz');
|
||||||
$CFG->theme = $themename;
|
|
||||||
|
if (empty($themename)) {
|
||||||
|
$themename = current_theme(); // So we have something. Normally not needed.
|
||||||
}
|
}
|
||||||
|
|
||||||
return $CFG->wwwroot .'/theme/'. $CFG->theme;
|
if (!empty($forceconfig)) { // Page wants to use the config from this theme instead
|
||||||
|
unset($THEME);
|
||||||
|
include($CFG->dirroot.'/theme/'.$forceconfig.'/'.'config.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
function theme_setup($theme = '', $extraparams='') {
|
/// If this is the standard theme calling us, then find out what sheets we need
|
||||||
|
|
||||||
|
if ($themename == 'standard') {
|
||||||
|
if (!isset($THEME->standardsheets) or $THEME->standardsheets === true) { // Use all the sheets we have
|
||||||
|
$THEME->sheets = $DEFAULT_SHEET_LIST;
|
||||||
|
} else if (empty($THEME->standardsheets)) { // We can stop right now!
|
||||||
|
echo "/***** Nothing required from this stylesheet by main theme *****/\n\n";
|
||||||
|
exit;
|
||||||
|
} else { // Use the provided subset only
|
||||||
|
$THEME->sheets = $THEME->standardsheets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If we are a parent theme, then check for parent definitions
|
||||||
|
|
||||||
|
} else if (!empty($THEME->parent) && $themename == $THEME->parent) {
|
||||||
|
if (!isset($THEME->parentsheets) or $THEME->parentsheets === true) { // Use all the sheets we have
|
||||||
|
$THEME->sheets = $DEFAULT_SHEET_LIST;
|
||||||
|
} else if (empty($THEME->parentsheets)) { // We can stop right now!
|
||||||
|
echo "/***** Nothing required from this stylesheet by main theme *****/\n\n";
|
||||||
|
exit;
|
||||||
|
} else { // Use the provided subset only
|
||||||
|
$THEME->sheets = $THEME->parentsheets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Work out the last modified date for this theme
|
||||||
|
|
||||||
|
foreach ($THEME->sheets as $sheet) {
|
||||||
|
if (file_exists($CFG->dirroot.'/theme/'.$themename.'/'.$sheet.'.css')) {
|
||||||
|
$sheetmodified = filemtime($CFG->dirroot.'/theme/'.$themename.'/'.$sheet.'.css');
|
||||||
|
if ($sheetmodified > $lastmodified) {
|
||||||
|
$lastmodified = $sheetmodified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Print out the entire style sheet
|
||||||
|
|
||||||
|
foreach ($THEME->sheets as $sheet) {
|
||||||
|
echo "/***** $sheet.css start *****/\n\n";
|
||||||
|
@include_once($CFG->dirroot.'/theme/'.$themename.'/'.$sheet.'.css');
|
||||||
|
echo "\n\n/***** $sheet.css end *****/\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $CFG->wwwroot.'/theme/'.$themename; // Only to help old themes (1.4 and earlier)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function theme_setup($theme = '', $params=NULL) {
|
||||||
/// Sets up global variables related to themes
|
/// Sets up global variables related to themes
|
||||||
|
|
||||||
global $CFG, $THEME;
|
global $CFG, $THEME;
|
||||||
|
@ -1797,17 +1848,25 @@ function theme_setup($theme = '', $extraparams='') {
|
||||||
if (empty($theme)) {
|
if (empty($theme)) {
|
||||||
$theme = current_theme();
|
$theme = current_theme();
|
||||||
}
|
}
|
||||||
if (empty($extraparams)) {
|
|
||||||
$params = '';
|
/// Put together the parameters
|
||||||
$paramsparent = '?parent=true';
|
if (!$params) {
|
||||||
|
$params = array();
|
||||||
|
}
|
||||||
|
if (!empty($CFG->coursetheme) and !empty($CFG->allowcoursethemes)) { // Course theme can override all others
|
||||||
|
$params[] = 'forceconfig='.$CFG->coursetheme;
|
||||||
|
}
|
||||||
|
if ($params) {
|
||||||
|
$paramstring = '?'.implode('&', $params);
|
||||||
} else {
|
} else {
|
||||||
$params = '?'.$extraparams;
|
$paramstring = '';
|
||||||
$paramsparent = '?parent=true&'.$extraparams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$THEME = null;
|
/// Load up the theme config
|
||||||
include($CFG->dirroot .'/theme/'. $theme .'/config.php');
|
$THEME = NULL; // Just to be sure
|
||||||
|
include($CFG->dirroot .'/theme/'. $theme .'/config.php'); // Main config for current theme
|
||||||
|
|
||||||
|
/// Set up image paths
|
||||||
if (empty($CFG->custompix)) { // Could be set in the above file
|
if (empty($CFG->custompix)) { // Could be set in the above file
|
||||||
$CFG->pixpath = $CFG->wwwroot .'/pix';
|
$CFG->pixpath = $CFG->wwwroot .'/pix';
|
||||||
$CFG->modpixpath = $CFG->wwwroot .'/mod';
|
$CFG->modpixpath = $CFG->wwwroot .'/mod';
|
||||||
|
@ -1816,17 +1875,19 @@ function theme_setup($theme = '', $extraparams='') {
|
||||||
$CFG->modpixpath = $CFG->wwwroot .'/theme/'. $theme .'/pix/mod';
|
$CFG->modpixpath = $CFG->wwwroot .'/theme/'. $theme .'/pix/mod';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Header and footer paths
|
||||||
$CFG->header = $CFG->dirroot .'/theme/'. $theme .'/header.html';
|
$CFG->header = $CFG->dirroot .'/theme/'. $theme .'/header.html';
|
||||||
$CFG->footer = $CFG->dirroot .'/theme/'. $theme .'/footer.html';
|
$CFG->footer = $CFG->dirroot .'/theme/'. $theme .'/footer.html';
|
||||||
|
|
||||||
|
/// Define stylesheet loading order
|
||||||
$CFG->stylesheets = array();
|
$CFG->stylesheets = array();
|
||||||
if ($theme != 'standard') { /// The standard sheet is always loaded first
|
if ($theme != 'standard') { /// The standard sheet is always loaded first
|
||||||
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/standard/styles.php'.$params;
|
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/standard/styles.php'.$paramstring;
|
||||||
}
|
}
|
||||||
if (!empty($THEME->parent)) { /// Parent stylesheets are loaded next
|
if (!empty($THEME->parent)) { /// Parent stylesheets are loaded next
|
||||||
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/'.$THEME->parent.'/styles.php'.$paramsparent;
|
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/'.$THEME->parent.'/styles.php'.$paramstring;
|
||||||
}
|
}
|
||||||
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/'.$theme.'/styles.php'.$params;
|
$CFG->stylesheets[] = $CFG->wwwroot.'/theme/'.$theme.'/styles.php'.$paramstring;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,53 +1,18 @@
|
||||||
<?PHP /* $Id$ */
|
<?PHP /* $Id$ */
|
||||||
|
|
||||||
/// This PHP script is used because it provides a place for setting
|
/// Every theme should contain a copy of this script. It lets us
|
||||||
/// up any necessary variables, and lets us include raw CSS files.
|
/// set up variables and so on before we include the raw CSS files.
|
||||||
/// The output of this script should be a completely standard CSS file.
|
/// The output of this script should be a completely standard CSS file.
|
||||||
|
|
||||||
/// There should be no need to modify this file!! Use config.php instead.
|
/// THERE SHOULD BE NO NEED TO MODIFY THIS FILE!! USE CONFIG.PHP INSTEAD.
|
||||||
|
|
||||||
$nomoodlecookie = true;
|
|
||||||
require_once("../../config.php");
|
|
||||||
|
|
||||||
if (isset($localconfig)) {
|
$lifetime = 600; // Seconds to cache this stylesheet
|
||||||
unset($THEME);
|
$nomoodlecookie = true; // Cookies prevent caching, so don't use them
|
||||||
include('config.php');
|
require_once("../../config.php"); // Load up the Moodle libraries
|
||||||
}
|
$themename = basename(dirname(__FILE__)); // Name of the folder we are in
|
||||||
|
$forceconfig = optional_param('forceconfig', '', PARAM_FILE); // Get config from this theme
|
||||||
|
|
||||||
$lastmodified = 0;
|
style_sheet_setup(filemtime('styles.php'), $lifetime, $themename, $forceconfig);
|
||||||
$lifetime = 600;
|
|
||||||
|
|
||||||
/// If we are a parent theme, then check for parent definitions
|
|
||||||
|
|
||||||
if (isset($parent)) {
|
|
||||||
if (!isset($THEME->parentsheets) or $THEME->parentsheets === true) { // Use all the sheets we have
|
|
||||||
$THEME->sheets = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz');
|
|
||||||
} else if (empty($THEME->parentsheets)) { // We can stop right now!
|
|
||||||
exit;
|
|
||||||
} else { // Use the provided subset only
|
|
||||||
$THEME->sheets = $THEME->parentsheets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Work out the last modified date for this theme
|
|
||||||
|
|
||||||
foreach ($THEME->sheets as $sheet) {
|
|
||||||
if (file_exists($sheet.'.css')) {
|
|
||||||
$sheetmodified = @filemtime($sheet.'.css');
|
|
||||||
if ($sheetmodified > $lastmodified) {
|
|
||||||
$lastmodified = $sheetmodified;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Print out the entire style sheet
|
|
||||||
|
|
||||||
style_sheet_setup($lastmodified, $lifetime);
|
|
||||||
|
|
||||||
foreach ($THEME->sheets as $sheet) {
|
|
||||||
echo "/***** $sheet.css start *****/\n\n";
|
|
||||||
include_once($sheet.'.css');
|
|
||||||
echo "\n\n/***** $sheet.css end *****/\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
$CFG->theme = $preview;
|
$CFG->theme = $preview;
|
||||||
|
|
||||||
theme_setup($CFG->theme, 'localconfig=true&themename='.$CFG->theme);
|
theme_setup($CFG->theme, array('forceconfig='.$CFG->theme));
|
||||||
|
|
||||||
$stradministration = get_string("administration");
|
$stradministration = get_string("administration");
|
||||||
$strconfiguration = get_string("configuration");
|
$strconfiguration = get_string("configuration");
|
||||||
|
|
|
@ -1,63 +1,18 @@
|
||||||
<?PHP /* $Id$ */
|
<?PHP /* $Id$ */
|
||||||
|
|
||||||
/// This PHP script is used because it provides a place for setting
|
/// Every theme should contain a copy of this script. It lets us
|
||||||
/// up any necessary variables, and lets us include raw CSS files.
|
/// set up variables and so on before we include the raw CSS files.
|
||||||
/// The output of this script should be a completely standard CSS file.
|
/// The output of this script should be a completely standard CSS file.
|
||||||
|
|
||||||
/// There should be no need to modify this file!! Use config.php instead.
|
/// THERE SHOULD BE NO NEED TO MODIFY THIS FILE!! USE CONFIG.PHP INSTEAD.
|
||||||
|
|
||||||
$nomoodlecookie = true;
|
|
||||||
require_once("../../config.php");
|
|
||||||
|
|
||||||
if (isset($localconfig)) {
|
$lifetime = 600; // Seconds to cache this stylesheet
|
||||||
unset($THEME);
|
$nomoodlecookie = true; // Cookies prevent caching, so don't use them
|
||||||
include('config.php');
|
require_once("../../config.php"); // Load up the Moodle libraries
|
||||||
}
|
$themename = basename(dirname(__FILE__)); // Name of the folder we are in
|
||||||
|
$forceconfig = optional_param('forceconfig', '', PARAM_FILE); // Get config from this theme
|
||||||
|
|
||||||
$lastmodified = 0;
|
style_sheet_setup(filemtime('styles.php'), $lifetime, $themename, $forceconfig);
|
||||||
$lifetime = 600;
|
|
||||||
|
|
||||||
/// The following lines are only for standard/theme/styles.php
|
|
||||||
|
|
||||||
if (!isset($THEME->standardsheets) or $THEME->standardsheets === true) { // Use all the sheets we have
|
|
||||||
$THEME->sheets = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz');
|
|
||||||
} else if (empty($THEME->standardsheets)) { // We can stop right now!
|
|
||||||
exit;
|
|
||||||
} else { // Use the provided subset only
|
|
||||||
$THEME->sheets = $THEME->standardsheets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If we are a parent theme, then check for parent definitions
|
|
||||||
|
|
||||||
if (isset($parent)) {
|
|
||||||
if (!isset($THEME->parentsheets) or $THEME->parentsheets === true) { // Use all the sheets we have
|
|
||||||
$THEME->sheets = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz');
|
|
||||||
} else if (empty($THEME->parentsheets)) { // We can stop right now!
|
|
||||||
exit;
|
|
||||||
} else { // Use the provided subset only
|
|
||||||
$THEME->sheets = $THEME->parentsheets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Work out the last modified date for this theme
|
|
||||||
|
|
||||||
foreach ($THEME->sheets as $sheet) {
|
|
||||||
if (file_exists($sheet.'.css')) {
|
|
||||||
$sheetmodified = filemtime($sheet.'.css');
|
|
||||||
if ($sheetmodified > $lastmodified) {
|
|
||||||
$lastmodified = $sheetmodified;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Print out the entire style sheet
|
|
||||||
|
|
||||||
style_sheet_setup($lastmodified, $lifetime);
|
|
||||||
|
|
||||||
foreach ($THEME->sheets as $sheet) {
|
|
||||||
echo "/***** $sheet.css start *****/\n\n";
|
|
||||||
include_once($sheet.'.css');
|
|
||||||
echo "\n\n/***** $sheet.css end *****/\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue