$baseconfig = $config;
}
- $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts',
+ $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts',
'parents_exclude_javascripts', 'layouts', 'resource_mp3player_colors',
'filter_mediaplugin_colors', 'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow');
}
}
- /**
- * 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
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)) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-//TODO
\ No newline at end of file
+
+// 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;
+}