MDL-32683 use slashargument urls for yui combo loader

This commit is contained in:
Petr Skoda 2012-05-05 15:59:43 +02:00
parent ecbad2ad1c
commit 6e7b46018e
2 changed files with 17 additions and 9 deletions

View file

@ -152,6 +152,8 @@ class page_requirements_manager {
public function __construct() { public function __construct() {
global $CFG; global $CFG;
$sep = empty($CFG->slasharguments) ? '?' : '/';
require_once("$CFG->libdir/yui/phploader/phploader/loader.php"); require_once("$CFG->libdir/yui/phploader/phploader/loader.php");
$this->yui3loader = new stdClass(); $this->yui3loader = new stdClass();
@ -174,8 +176,8 @@ class page_requirements_manager {
} else { } else {
$this->yui3loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui3version . '/build/'; $this->yui3loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui3version . '/build/';
$this->yui2loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui2version . '/build/'; $this->yui2loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui2version . '/build/';
$this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?'; $this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep;
$this->yui2loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?'; $this->yui2loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep;
} }
// enable combo loader? this significantly helps with caching and performance! // enable combo loader? this significantly helps with caching and performance!
@ -201,8 +203,8 @@ class page_requirements_manager {
$this->M_yui_loader->groups = array( $this->M_yui_loader->groups = array(
'moodle' => array( 'moodle' => array(
'name' => 'moodle', 'name' => 'moodle',
'base' => $CFG->httpswwwroot . '/theme/yui_combo.php?moodle/'.$jsrev.'/', 'base' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep.'moodle/'.$jsrev.'/',
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php?', 'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep,
'combine' => $this->yui3loader->combine, 'combine' => $this->yui3loader->combine,
'filter' => '', 'filter' => '',
'ext' => false, 'ext' => false,
@ -218,7 +220,7 @@ class page_requirements_manager {
'local' => array( 'local' => array(
'name' => 'gallery', 'name' => 'gallery',
'base' => $CFG->wwwroot.'/lib/yui/gallery/', 'base' => $CFG->wwwroot.'/lib/yui/gallery/',
'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php?', 'comboBase' => $CFG->httpswwwroot . '/theme/yui_combo.php'.$sep,
'combine' => $this->yui3loader->combine, 'combine' => $this->yui3loader->combine,
'filter' => $this->M_yui_loader->filter, 'filter' => $this->M_yui_loader->filter,
'ext' => false, 'ext' => false,

View file

@ -109,12 +109,14 @@ foreach ($parts as $part) {
} }
$filecontent = file_get_contents($contentfile); $filecontent = file_get_contents($contentfile);
$relroot = preg_replace('|^http.?://[^/]+|', '', $CFG->wwwroot);
if ($mimetype === 'text/css') { if ($mimetype === 'text/css') {
if ($version == 'moodle') { if ($version == 'moodle') {
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent); $filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php?file='.$version.'/'.$frankenstyle.'/'.array_shift($bits).'/$1.$2', $filecontent);
} else if ($version == 'gallery') { } else if ($version == 'gallery') {
// search for all images in gallery module CSS and serve them through the yui_image.php script // search for all images in gallery module CSS and serve them through the yui_image.php script
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/'.$bits[0].'/'.$bits[1].'/$1.$2', $filecontent); $filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php?file='.$version.'/'.$bits[0].'/'.$bits[1].'/$1.$2', $filecontent);
} else { } else {
// First we need to remove relative paths to images. These are used by YUI modules to make use of global assets. // First we need to remove relative paths to images. These are used by YUI modules to make use of global assets.
// I've added this as a separate regex so it can be easily removed once // I've added this as a separate regex so it can be easily removed once
@ -122,7 +124,7 @@ foreach ($parts as $part) {
$filecontent = preg_replace('#(\.\./\.\./\.\./\.\./assets/skins/sam/)?([a-z0-9_-]+)\.(png|gif)#', '$2.$3', $filecontent); $filecontent = preg_replace('#(\.\./\.\./\.\./\.\./assets/skins/sam/)?([a-z0-9_-]+)\.(png|gif)#', '$2.$3', $filecontent);
// search for all images in yui2 CSS and serve them through the yui_image.php script // search for all images in yui2 CSS and serve them through the yui_image.php script
$filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent); $filecontent = preg_replace('/([a-z0-9_-]+)\.(png|gif)/', $relroot.'/theme/yui_image.php?file='.$version.'/$1.$2', $filecontent);
} }
} }
@ -195,9 +197,13 @@ function combo_params() {
$parts = explode('?', $_SERVER['REQUEST_URI'], 2); $parts = explode('?', $_SERVER['REQUEST_URI'], 2);
return $parts[1]; return $parts[1];
} else if (isset($_SERVER['QUERY_STRING'])) { } else if (isset($_SERVER['QUERY_STRING']) and strpos($_SERVER['QUERY_STRING'], '?') !== false) {
return $_SERVER['QUERY_STRING']; return $_SERVER['QUERY_STRING'];
} else if ($slashargument = min_get_slash_argument()) {
$slashargument = ltrim($slashargument, '/');
return $slashargument;
} else { } else {
// unsupported server, sorry! // unsupported server, sorry!
combo_not_found('Unsupported server - query string can not be determined, try disabling YUI combo loading in admin settings.'); combo_not_found('Unsupported server - query string can not be determined, try disabling YUI combo loading in admin settings.');