From 7070b7f2612c73ecf943935f93a6cdfb1c1deebc Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 5 May 2012 15:25:20 +0200 Subject: [PATCH] MDL-32683 use slashargument urls for theme style sheets --- lib/csslib.php | 15 +++++++++++---- lib/outputlib.php | 20 +++++++++++++++----- theme/styles.php | 21 +++++++++++++++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/csslib.php b/lib/csslib.php index 2fdbb7357a8..3f2b4a08f3b 100644 --- a/lib/csslib.php +++ b/lib/csslib.php @@ -85,14 +85,21 @@ function css_store_css(theme_config $theme, $csspath, array $cssfiles) { * * @param string $themename The name of the theme we are sending CSS for. * @param string $rev The revision to ensure we utilise the cache. + * @param bool $slasharguments */ -function css_send_ie_css($themename, $rev) { +function css_send_ie_css($themename, $rev, $slasharguments) { $lifetime = 60*60*24*30; // 30 days $css = "/** Unfortunately IE6/7 does not support more than 4096 selectors in one CSS file, which means we have to use some ugly hacks :-( **/"; - $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=plugins);"; - $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=parents);"; - $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=theme);"; + if ($slasharguments) { + $css .= "\n@import url(styles.php/$themename/$rev/plugins);"; + $css .= "\n@import url(styles.php/$themename/$rev/parents);"; + $css .= "\n@import url(styles.php/$themename/$rev/theme);"; + } else { + $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=plugins);"; + $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=parents);"; + $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=theme);"; + } header('Etag: '.md5($rev)); header('Content-Disposition: inline; filename="styles.php"'); diff --git a/lib/outputlib.php b/lib/outputlib.php index e9599f64325..48d18220e13 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -518,8 +518,14 @@ class theme_config { $rev = theme_get_revision(); if ($rev > -1) { - $params = array('theme'=>$this->name,'rev'=>$rev, 'type'=>'editor'); - return new moodle_url($CFG->httpswwwroot.'/theme/styles.php', $params); + if (!empty($CFG->slasharguments)) { + $url = new moodle_url("$CFG->httpswwwroot/theme/styles.php"); + $url->set_slashargument('/'.$this->name.'/'.$rev.'/editor', 'noparam', true); + return $url; + } else { + $params = array('theme'=>$this->name,'rev'=>$rev, 'type'=>'editor'); + return new moodle_url($CFG->httpswwwroot.'/theme/styles.php', $params); + } } else { $params = array('theme'=>$this->name, 'type'=>'editor'); return new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', $params); @@ -589,7 +595,13 @@ class theme_config { $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles.php', array('theme'=>$this->name,'rev'=>$rev, 'type'=>'parents')); $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles.php', array('theme'=>$this->name,'rev'=>$rev, 'type'=>'theme')); } else { - $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles.php', array('theme'=>$this->name,'rev'=>$rev)); + if (!empty($CFG->slasharguments)) { + $url = new moodle_url("$CFG->httpswwwroot/theme/styles.php"); + $url->set_slashargument('/'.$this->name.'/'.$rev.'/all', 'noparam', true); + $urls[] = $url; + } else { + $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles.php', array('theme'=>$this->name,'rev'=>$rev, 'type'=>'all')); + } } } else { // find out the current CSS and cache it now for 5 seconds @@ -872,8 +884,6 @@ class theme_config { * @return string The processed CSS. */ public function post_process($css) { - global $CFG; - // now resolve all image locations if (preg_match_all('/\[\[pix:([a-z_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) { $replaced = array(); diff --git a/theme/styles.php b/theme/styles.php index 07bb0a0edd5..254e493e0fa 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -33,9 +33,22 @@ define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php require_once($CFG->dirroot.'/lib/csslib.php'); -$themename = min_optional_param('theme', 'standard', 'SAFEDIR'); -$type = min_optional_param('type', 'all', 'SAFEDIR'); -$rev = min_optional_param('rev', 0, 'INT'); +if ($slashargument = min_get_slash_argument()) { + $slashargument = ltrim($slashargument, '/'); + if (substr_count($slashargument, '/') < 2) { + image_not_found(); + } + // image must be last because it may contain "/" + list($themename, $rev, $type) = explode('/', $slashargument, 3); + $themename = min_clean_param($themename, 'SAFEDIR'); + $rev = min_clean_param($rev, 'INT'); + $type = min_clean_param($type, 'SAFEDIR'); + +} else { + $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); + $rev = min_optional_param('rev', 0, 'INT'); + $type = min_optional_param('type', 'all', 'SAFEDIR'); +} if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) { header('HTTP/1.0 404 not found'); @@ -52,7 +65,7 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { } if ($type === 'ie') { - css_send_ie_css($themename, $rev); + css_send_ie_css($themename, $rev, !empty($slashargument)); } $candidatesheet = "$CFG->cachedir/theme/$themename/css/$type.css";