From 4399b9d5dec273e8202ba1435a5f4094c6a0a4a2 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 15 Apr 2010 14:43:25 +0000 Subject: [PATCH] MDL-22091 fix for sloppy IE CSS limits hack --- lib/outputlib.php | 10 +++++---- theme/styles_debug.php | 48 ++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/outputlib.php b/lib/outputlib.php index 018ee9c00f9..f4769ad74c9 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -159,7 +159,7 @@ class theme_config { * @var array */ public $javascripts_footer = array(); - + /** * The names of all the javascript files from parents that should be excluded. * true value may be used to specify all parents or all themes from one parent. @@ -443,7 +443,7 @@ class theme_config { // may contain core and plugin renderers and renderer factory include_once($rendererfile); } - + // cascade all layouts properly foreach ($baseconfig->layouts as $layout=>$value) { if (!isset($this->layouts[$layout])) { @@ -636,7 +636,9 @@ class theme_config { if (check_browser_version('MSIE', 5)) { // lalala, IE does not allow more than 31 linked CSS files from main document - $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', array('theme'=>$this->name, 'type'=>'ie')); + $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', array('theme'=>$this->name, 'type'=>'ie', 'subtype'=>'plugins')); + $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', array('theme'=>$this->name, 'type'=>'ie', 'subtype'=>'parents')); + $urls[] = new moodle_url($CFG->httpswwwroot.'/theme/styles_debug.php', array('theme'=>$this->name, 'type'=>'ie', 'subtype'=>'theme')); } else { foreach ($css['plugins'] as $plugin=>$unused) { @@ -1074,7 +1076,7 @@ class theme_config { } else { $themes = array_merge(array($this->name),$this->parents); } - + foreach ($themes as $theme) { if ($dir = $this->find_theme_location($theme)) { $path = "$dir/layout/$layoutfile"; diff --git a/theme/styles_debug.php b/theme/styles_debug.php index 2cceb182b33..74b87dfdceb 100644 --- a/theme/styles_debug.php +++ b/theme/styles_debug.php @@ -28,7 +28,7 @@ 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'); -$type = min_optional_param('type', 'all', 'SAFEDIR'); +$type = min_optional_param('type', '', 'SAFEDIR'); $subtype = min_optional_param('subtype', '', 'SAFEDIR'); $sheet = min_optional_param('sheet', '', 'SAFEDIR'); @@ -59,7 +59,26 @@ if (!$css = file_get_contents($candidatesheet)) { $css = unserialize($css); if ($type === 'ie') { - send_ie_css($themename, $css); + // IE is a sloppy browser with weird limits, sorry + if ($subtype === 'plugins') { + $sendcss = implode("\n\n", $css['plugins']); + $sendcss = str_replace("\n", "\r\n", $sendcss); + send_uncached_css($sendcss); + + } else if ($subtype === 'parents') { + $sendcss = array(); + foreach ($css['parents'] as $parent=>$sheets) { + $sendcss = array_merge($sendcss, $sheets); + } + $sendcss = implode("\n\n", $sendcss); + $sendcss = str_replace("\n", "\r\n", $sendcss); + send_uncached_css($sendcss); + + } else if ($subtype === 'theme') { + $sendcss = implode("\n\n", $css['theme']); + $sendcss = str_replace("\n", "\r\n", $sendcss); + send_uncached_css($sendcss); + } } else if ($type === 'plugin') { if (isset($css['plugins'][$subtype])) { @@ -101,28 +120,3 @@ function css_not_found() { die('CSS was not found, sorry.'); } -function send_ie_css($themename, $css) { - $output = "/** Unfortunately IE6/7/8 does not support more than 31 CSS files, which means we have to use some ugly hacks :-( **/\n"; - foreach ($css['plugins'] as $plugin=>$unused) { - $output .= "@import url(styles_debug.php?theme=$themename&type=plugin&subtype=$plugin);\n"; - } - foreach ($css['parents'] as $parent=>$sheets) { - foreach ($sheets as $sheet=>$unused2) { - $output .= "@import url(styles_debug.php?theme=$themename&type=parent&subtype=$parent&sheet=$sheet);\n"; - } - } - foreach ($css['theme'] as $sheet=>$unused) { - $output .= "@import url(styles_debug.php?theme=$themename&type=theme&sheet=$sheet);\n"; - } - - header('Content-Disposition: inline; filename="styles_debug.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() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT'); - header('Pragma: '); - header('Accept-Ranges: none'); - header('Content-Type: text/css'); - //header('Content-Length: '.strlen($output)); - - echo $output; - die; -} -- 2.43.0