mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 13:33:52 +02:00
MDL-35434 add support for theme setting files
This patch is based on work by Gareth J Barnard, Pau Ferrer Ocaña (crazyserver) and others.
This commit is contained in:
parent
6ddc9278ff
commit
fe7b75f85c
@ -43,7 +43,7 @@ require_once($CFG->libdir.'/outputrequirementslib.php');
|
||||
* this function.
|
||||
*/
|
||||
function theme_reset_all_caches() {
|
||||
global $CFG;
|
||||
global $CFG, $PAGE;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
$next = time();
|
||||
@ -56,6 +56,10 @@ function theme_reset_all_caches() {
|
||||
|
||||
set_config('themerev', $next); // time is unique even when you reset/switch database
|
||||
fulldelete("$CFG->cachedir/theme");
|
||||
|
||||
if ($PAGE) {
|
||||
$PAGE->reload_theme();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1074,6 +1078,74 @@ class theme_config {
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns URL to the stored file via pluginfile.php.
|
||||
*
|
||||
* Note the theme must also implement pluginfile.php handler,
|
||||
* theme revision is used instead of the itemid.
|
||||
*
|
||||
* @param string $setting
|
||||
* @param string $filearea
|
||||
* @return string protocol relative URL or null if not present
|
||||
*/
|
||||
public function setting_file_url($setting, $filearea) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($this->settings->$setting)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$component = 'theme_'.$this->name;
|
||||
$itemid = theme_get_revision();
|
||||
$filepath = $this->settings->$setting;
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
$url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", "/$syscontext->id/$component/$filearea/$itemid".$filepath);
|
||||
|
||||
// Now this is tricky because the we can not hardcode http or https here, lets use the relative link.
|
||||
// Note: unfortunately moodle_url does not support //urls yet.
|
||||
|
||||
$url = preg_replace('|^https?://|i', '//', $url->out(false));
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve the theme setting file.
|
||||
*
|
||||
* @param string $filearea
|
||||
* @param array $args
|
||||
* @param bool $forcedownload
|
||||
* @param array $options
|
||||
* @return bool may terminate if file not found or donotdie not specified
|
||||
*/
|
||||
public function setting_file_serve($filearea, $args, $forcedownload, $options) {
|
||||
global $CFG;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
$component = 'theme_'.$this->name;
|
||||
|
||||
$revision = array_shift($args);
|
||||
if ($revision < 0) {
|
||||
$lifetime = 0;
|
||||
} else {
|
||||
$lifetime = 60*60*24*60;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
$relativepath = implode('/', $args);
|
||||
|
||||
$fullpath = "/{$syscontext->id}/{$component}/{$filearea}/0/{$relativepath}";
|
||||
$fullpath = rtrim($fullpath, '/');
|
||||
if ($file = $fs->get_file_by_hash(sha1($fullpath))) {
|
||||
send_stored_file($file, $lifetime, 0, $forcedownload, $options);
|
||||
return true;
|
||||
} else {
|
||||
send_file_not_found();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the real image location.
|
||||
*
|
||||
|
@ -1296,6 +1296,18 @@ class moodle_page {
|
||||
$this->_theme = theme_config::load($themename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload theme settings.
|
||||
*
|
||||
* This is used when we need to reset settings
|
||||
* because they are now double cached in theme.
|
||||
*/
|
||||
public function reload_theme() {
|
||||
if (!is_null($this->_theme)) {
|
||||
$this->_theme = theme_config::load($this->_theme->name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function indicates that current page requires the https
|
||||
* when $CFG->loginhttps enabled.
|
||||
|
Loading…
x
Reference in New Issue
Block a user