From 73e504bca9389aec96a60edf445ab29ec892a7d0 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 23 Dec 2009 18:52:42 +0000 Subject: [PATCH] MDL-20799 renewed support for alternative theme dir location --- config-dist.php | 8 +++++--- lib/moodlelib.php | 12 +++++++----- theme/image.php | 7 ++++++- theme/javascripts.php | 6 +++++- theme/styles.php | 7 ++++++- theme/styles_debug.php | 7 ++++++- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/config-dist.php b/config-dist.php index 7e87ead7564..94d8ab0310b 100644 --- a/config-dist.php +++ b/config-dist.php @@ -330,8 +330,6 @@ $CFG->admin = 'admin'; // // $CFG->emailconnectionerrorsto = 'your@emailaddress.com'; // -// NOTE: if you are using custompix in your theme, see /fixpix.php. -// // Set the priority of themes from highest to lowest. This is useful (for // example) in sites where the user theme should override all other theme // settings for accessibility reasons. You can also disable types of themes @@ -340,7 +338,11 @@ $CFG->admin = 'admin'; // NOTE: course, category, session, user themes still require the // respective settings to be enabled // - +// It is possible to add extra themes directory stored outside of $CFG->dirroot. +// This local directory does not have to be accessible from internet. +// +// $CFG->themedir = '/location/of/extra/themes'; +// //========================================================================= // 8. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!! //========================================================================= diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8de666157a5..0e17e1f9aa5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -714,7 +714,9 @@ function clean_param($param, $type) { case PARAM_THEME: $param = clean_param($param, PARAM_SAFEDIR); - if (file_exists($CFG->dirroot.'/theme/'.$param)) { + if (file_exists("$CFG->dirroot/theme/$param/config.php")) { + return $param; + } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$param/config.php")) { return $param; } else { return ''; // Specified theme is not installed @@ -6798,8 +6800,11 @@ function get_plugin_list($plugintype) { $fulldirs[] = $CFG->dirroot.'/mod'; } else if ($plugintype === 'theme') { - // themes are an exception because they may be stored also in dataroot $fulldirs[] = $CFG->dirroot.'/theme'; + // themes are special because they may be stored also in separate directory + if (!empty($CFG->themedir) and file_exists($CFG->themedir) and is_dir($CFG->themedir) ) { + $fulldirs[] = $CFG->themedir; + } } else { $types = get_plugin_types(true); @@ -6815,8 +6820,6 @@ function get_plugin_list($plugintype) { $result = array(); - //TODO: MDL-20799 add themedir support - foreach ($fulldirs as $fulldir) { if (!is_dir($fulldir)) { continue; @@ -6863,7 +6866,6 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') { $plugins = array(); if (empty($basedir)) { - // TODO: MDL-20799 megre theme with themedir if defined $basedir = $CFG->dirroot .'/'. $directory; } else { diff --git a/theme/image.php b/theme/image.php index 27ccacf298e..28ccd214da3 100644 --- a/theme/image.php +++ b/theme/image.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php @@ -36,7 +37,11 @@ if (empty($component) or empty($image)) { image_not_found(); } -if (!file_exists("$CFG->dirroot/theme/$themename/config.php") and !file_exists("$CFG->dataroot/theme/$themename/config.php")) { +if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { + // exists +} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { + // exists +} else { image_not_found(); } diff --git a/theme/javascripts.php b/theme/javascripts.php index 7667397eaa9..f347b11c023 100644 --- a/theme/javascripts.php +++ b/theme/javascripts.php @@ -31,7 +31,11 @@ require('../config.php'); // this stops immediately at the beginning of lib/setu $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); $rev = min_optional_param('rev', 0, 'INT'); -if (!file_exists("$CFG->dirroot/theme/$themename/config.php") and !file_exists("$CFG->dataroot/theme/$themename/config.php")) { +if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { + // exists +} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { + // exists +} else { header('HTTP/1.0 404 not found'); die('Theme was not found, sorry.'); } diff --git a/theme/styles.php b/theme/styles.php index 4be3059314a..a68fc2bf91c 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php @@ -36,7 +37,11 @@ if (!in_array($type, array('all', 'ie', 'editor', 'yui', 'plugins', 'parents', ' die('Theme was not found, sorry.'); } -if (!file_exists("$CFG->dirroot/theme/$themename/config.php") and !file_exists("$CFG->dataroot/theme/$themename/config.php")) { +if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { + // exists +} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { + // exists +} else { header('HTTP/1.0 404 not found'); die('Theme was not found, sorry.'); } diff --git a/theme/styles_debug.php b/theme/styles_debug.php index d558d7e9339..c35903b7a81 100644 --- a/theme/styles_debug.php +++ b/theme/styles_debug.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + // no chaching define('NO_MOODLE_COOKIES', true); // Session not used here define('NO_UPGRADE_CHECK', true); // Ignore upgrade check @@ -33,7 +34,11 @@ $type = required_param('type', PARAM_SAFEDIR); $subtype = optional_param('subtype', '', PARAM_SAFEDIR); $sheet = optional_param('sheet', '', PARAM_SAFEDIR); -if (!file_exists("$CFG->dirroot/theme/$themename/config.php") and !file_exists("$CFG->dataroot/theme/$themename/config.php")) { +if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { + // exists +} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { + // exists +} else { css_not_found(); }