Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
moodler committed Feb 13, 2005
1 parent 373d5f2 commit 9c4e6e2
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 118 deletions.
95 changes: 78 additions & 17 deletions lib/weblib.php
Expand Up @@ -1769,45 +1769,104 @@ function current_theme() {
* @param int $lastmodified ?
* @param int $lifetime ?
* @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('Expires: ' . gmdate("D, d M Y H:i:s", time() + $lifetime) . ' GMT');
header('Cache-control: max_age = '. $lifetime);
header('Pragma: ');
header('Content-type: text/css'); // Correct MIME type

if (!empty($themename)) {
$CFG->theme = $themename;
$DEFAULT_SHEET_LIST = array('styles_layout', 'styles_fonts', 'styles_color', 'styles_moz');

if (empty($themename)) {
$themename = current_theme(); // So we have something. Normally not needed.
}

if (!empty($forceconfig)) { // Page wants to use the config from this theme instead
unset($THEME);
include($CFG->dirroot.'/theme/'.$forceconfig.'/'.'config.php');
}

/// 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;
}
}
}

return $CFG->wwwroot .'/theme/'. $CFG->theme;

/// 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 = '', $extraparams='') {

function theme_setup($theme = '', $params=NULL) {
/// Sets up global variables related to themes

global $CFG, $THEME;

if (empty($theme)) {
$theme = current_theme();
}
if (empty($extraparams)) {
$params = '';
$paramsparent = '?parent=true';

/// Put together the parameters
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 {
$params = '?'.$extraparams;
$paramsparent = '?parent=true&'.$extraparams;
$paramstring = '';
}

$THEME = null;
include($CFG->dirroot .'/theme/'. $theme .'/config.php');
/// Load up the theme config
$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
$CFG->pixpath = $CFG->wwwroot .'/pix';
$CFG->modpixpath = $CFG->wwwroot .'/mod';
Expand All @@ -1816,17 +1875,19 @@ function theme_setup($theme = '', $extraparams='') {
$CFG->modpixpath = $CFG->wwwroot .'/theme/'. $theme .'/pix/mod';
}

/// Header and footer paths
$CFG->header = $CFG->dirroot .'/theme/'. $theme .'/header.html';
$CFG->footer = $CFG->dirroot .'/theme/'. $theme .'/footer.html';

/// Define stylesheet loading order
$CFG->stylesheets = array();
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
$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;

}

Expand Down
55 changes: 10 additions & 45 deletions theme/orangewhite/styles.php
@@ -1,53 +1,18 @@
<?PHP /* $Id$ */

/// This PHP script is used because it provides a place for setting
/// up any necessary variables, and lets us include raw CSS files.
/// Every theme should contain a copy of this script. It lets us
/// 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.

/// 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)) {
unset($THEME);
include('config.php');
}

$lastmodified = 0;
$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";
}
$lifetime = 600; // Seconds to cache this stylesheet
$nomoodlecookie = true; // Cookies prevent caching, so don't use them
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

style_sheet_setup(filemtime('styles.php'), $lifetime, $themename, $forceconfig);

?>
2 changes: 1 addition & 1 deletion theme/preview.php
Expand Up @@ -20,7 +20,7 @@

$CFG->theme = $preview;

theme_setup($CFG->theme, 'localconfig=true&amp;themename='.$CFG->theme);
theme_setup($CFG->theme, array('forceconfig='.$CFG->theme));

$stradministration = get_string("administration");
$strconfiguration = get_string("configuration");
Expand Down
65 changes: 10 additions & 55 deletions theme/standard/styles.php
@@ -1,63 +1,18 @@
<?PHP /* $Id$ */

/// This PHP script is used because it provides a place for setting
/// up any necessary variables, and lets us include raw CSS files.
/// Every theme should contain a copy of this script. It lets us
/// 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.

/// 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)) {
unset($THEME);
include('config.php');
}

$lastmodified = 0;
$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";
}
$lifetime = 600; // Seconds to cache this stylesheet
$nomoodlecookie = true; // Cookies prevent caching, so don't use them
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

style_sheet_setup(filemtime('styles.php'), $lifetime, $themename, $forceconfig);

?>

0 comments on commit 9c4e6e2

Please sign in to comment.