mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-21124 towards full JS support in themes
This commit is contained in:
parent
38aafea249
commit
e68c5f36cf
3 changed files with 108 additions and 17 deletions
|
@ -607,20 +607,6 @@ class theme_config {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the javascript URL of this theme
|
||||
* @param bool $encoded false means use & and true use & in URLs
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function javascript_url() {
|
||||
global $CFG;
|
||||
|
||||
$rev = theme_get_revision();
|
||||
|
||||
$params = array('theme'=>$this->name,'rev'=>$rev);
|
||||
return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the one huge CSS merged from all style sheets.
|
||||
* @return string
|
||||
|
@ -741,6 +727,30 @@ class theme_config {
|
|||
return $css;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the javascript URL of this theme
|
||||
* @param bool $encoded false means use & and true use & in URLs
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function javascript_url() {
|
||||
global $CFG;
|
||||
|
||||
$rev = theme_get_revision();
|
||||
|
||||
$params = array('theme'=>$this->name,'rev'=>$rev);
|
||||
return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the one huge javascript file merged from all theme javascript files.
|
||||
* @return string
|
||||
*/
|
||||
public function javascript_content() {
|
||||
//TODO: load contents of all theme JS files
|
||||
return '/*not yet fully implemented*/';
|
||||
}
|
||||
|
||||
protected function post_process($css) {
|
||||
// now resolve all image locations
|
||||
if (preg_match_all('/\[\[pix:([a-z_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) {
|
||||
|
|
|
@ -367,7 +367,7 @@ class core_renderer extends renderer_base {
|
|||
|
||||
// Get the theme javascript
|
||||
$jsurl = $this->page->theme->javascript_url();
|
||||
$this->page->requires->js($jsurl->out_raw(), true)->in_head();
|
||||
$this->page->requires->js($jsurl->out(), true)->in_head();
|
||||
|
||||
// Perform a browser environment check for the flash version. Should only run once per login session.
|
||||
if (isloggedin() && !empty($CFG->excludeoldflashclients) && empty($SESSION->flashversion)) {
|
||||
|
|
|
@ -23,4 +23,85 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
//TODO
|
||||
|
||||
// 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
|
||||
|
||||
$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")) {
|
||||
header('HTTP/1.0 404 not found');
|
||||
die('Theme was not found, sorry.');
|
||||
}
|
||||
|
||||
$candidate = "$CFG->dataroot/cache/theme/$themename/javascript.js";
|
||||
|
||||
if ($rev > -1 and file_exists($candidate)) {
|
||||
if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
||||
// we do not actually need to verify the etag value because our files
|
||||
// never change in cache because we increment the rev parameter
|
||||
header('HTTP/1.1 304 Not Modified');
|
||||
die;
|
||||
}
|
||||
send_cached_js($candidate, $rev);
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
// ok, now we need to start normal moodle script, we need to load all libs and $DB
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
|
||||
define('NO_MOODLE_COOKIES', true); // Session not used here
|
||||
define('NO_UPGRADE_CHECK', true); // Ignore upgrade check
|
||||
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
$theme = theme_config::load($themename);
|
||||
|
||||
$js = $theme->javascript_content();
|
||||
if ($rev > -1) {
|
||||
check_dir_exists(dirname($candidate), true, true);
|
||||
$fp = fopen($candidate, 'w');
|
||||
fwrite($fp, $js);
|
||||
fclose($fp);
|
||||
send_cached_js($candidate);
|
||||
|
||||
} else {
|
||||
send_uncached_js($js);
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
//=== utility functions ==
|
||||
// we are not using filelib because we need to fine tune all header
|
||||
// parameters to get the best performance.
|
||||
|
||||
function send_cached_js($jspath) {
|
||||
$lifetime = 60*60*24*20;
|
||||
|
||||
header('Content-Disposition: inline; filename="javascripts.php"');
|
||||
header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($jspath)) .' GMT');
|
||||
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
|
||||
header('Pragma: ');
|
||||
header('Accept-Ranges: none');
|
||||
header('Content-Type: application/x-javascript');
|
||||
header('Content-Length: '.filesize($jspath));
|
||||
|
||||
while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
|
||||
readfile($jspath);
|
||||
die;
|
||||
}
|
||||
|
||||
function send_uncached_js($js) {
|
||||
header('Content-Disposition: inline; filename="javascripts.php"');
|
||||
header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
|
||||
header('Expires: '. gmdate('D, d M Y H:i:s', time() + 2) .' GMT');
|
||||
header('Pragma: ');
|
||||
header('Accept-Ranges: none');
|
||||
header('Content-Type: application/x-javascript');
|
||||
header('Content-Length: '.strlen($js));
|
||||
|
||||
while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
|
||||
echo $js;
|
||||
die;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue