From baeb20bba319c5226d124f4d87e4811a5e93d19f Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 7 Feb 2010 13:08:46 +0000 Subject: [PATCH] MDL-21400 thems and JS now using the same script naming convention and parameter style --- lib/javascript.php | 11 +++++------ lib/outputlib.php | 18 ++++++++---------- lib/outputrenderers.php | 4 ++-- theme/{javascripts.php => javascript.php} | 12 +++++------- 4 files changed, 20 insertions(+), 25 deletions(-) rename theme/{javascripts.php => javascript.php} (91%) diff --git a/lib/javascript.php b/lib/javascript.php index 9f75bafe394..e16f657730e 100644 --- a/lib/javascript.php +++ b/lib/javascript.php @@ -30,16 +30,15 @@ require('../config.php'); // this stops immediately at the beginning of lib/setu $file = min_optional_param('file', '', 'SAFEPATH'); $rev = min_optional_param('rev', 0, 'INT'); -if (empty($file) or strpos($file, '/') !== 0 or !preg_match('/\.js$/', $file)) { - die; -} - $jspath = $CFG->dirroot.$file; -if (file_exists($jspath)) { - send_cached_js($jspath); +if (empty($file) or strpos($file, '/') !== 0 or !preg_match('/\.js$/', $file) or !file_exists($jspath)) { + header('HTTP/1.0 404 not found'); + die('JS file was not found, sorry.'); } +send_cached_js($jspath); + //================================================================================= //=== utility functions == diff --git a/lib/outputlib.php b/lib/outputlib.php index bc0d700d339..0c660b237c6 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -749,28 +749,26 @@ class theme_config { /** * Get the javascript URL of this theme - * @param bool $footer true measn footer url, false means head + * @param bool $inhead true means haed url, false means footer * @return moodle_url */ - public function javascript_url($footer=false) { + public function javascript_url($inhead) { global $CFG; $rev = theme_get_revision(); - $params = array('theme'=>$this->name,'rev'=>$rev); - if ($footer) { - $params['type'] = 'footer'; - } - return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params); + $params['type'] = $inhead ? 'head' : 'footer'; + + return new moodle_url($CFG->httpswwwroot.'/theme/javascript.php', $params); } /** * Returns the content of the one huge javascript file merged from all theme javascript files. - * @param bool $footer true measn footer url, false means head + * @param bool $inhead * @return string */ - public function javascript_content($footer=false) { - $type = $footer ? 'javascripts_footer' : 'javascripts'; + public function javascript_content($type) { + $type = ($type === 'footer') ? 'javascripts_footer' : 'javascripts'; $js = array(); // find out wanted parent javascripts diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 12a4c184cb4..30947df8d7c 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -336,9 +336,9 @@ class core_renderer extends renderer_base { } // Get the theme javascript head and footer - $jsurl = $this->page->theme->javascript_url(); - $this->page->requires->js($jsurl, true); $jsurl = $this->page->theme->javascript_url(true); + $this->page->requires->js($jsurl, true); + $jsurl = $this->page->theme->javascript_url(false); $this->page->requires->js($jsurl); // Perform a browser environment check for the flash version. Should only run once per login session. diff --git a/theme/javascripts.php b/theme/javascript.php similarity index 91% rename from theme/javascripts.php rename to theme/javascript.php index 01f13aef230..431114d3cdb 100644 --- a/theme/javascripts.php +++ b/theme/javascript.php @@ -30,15 +30,13 @@ 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'); -$type = min_optional_param('type', 'header', 'RAW'); +$type = min_optional_param('type', 'head', 'RAW'); -if ($type !== 'header' and $type !== 'footer') { +if ($type !== 'head' and $type !== 'footer') { header('HTTP/1.0 404 not found'); die('Theme was not found, sorry.'); } -$footer = ($type === 'footer'); - if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { // exists } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { @@ -71,7 +69,7 @@ require("$CFG->dirroot/lib/setup.php"); $theme = theme_config::load($themename); -$js = $theme->javascript_content($footer); +$js = $theme->javascript_content($type); if ($rev > -1) { check_dir_exists(dirname($candidate), true, true); $fp = fopen($candidate, 'w'); @@ -91,7 +89,7 @@ if ($rev > -1) { function send_cached_js($jspath) { $lifetime = 60*60*24*20; - header('Content-Disposition: inline; filename="javascripts.php"'); + header('Content-Disposition: inline; filename="javascript.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: '); @@ -106,7 +104,7 @@ function send_cached_js($jspath) { } function send_uncached_js($js) { - header('Content-Disposition: inline; filename="javascripts.php"'); + header('Content-Disposition: inline; filename="javascript.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: ');