$this->yui3loader->base = 'http://yui.yahooapis.com/' . $CFG->yui3version . '/build/';
$this->yui2loader->base = 'http://yui.yahooapis.com/' . $CFG->yui2version . '/build/';
} else {
- $this->yui3loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui3version . '/';
- $this->yui2loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui2version . '/';
+ $this->yui3loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui3version . '/build/';
+ $this->yui2loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui2version . '/build/';
}
// This file helps to minimise number of http requests and implements proper caching
- //$this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?file=';
- //$this->yui2loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?file=';
+ $this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?';
+ $this->yui2loader->comboBase = $CFG->httpswwwroot . '/theme/yui_combo.php?';
+
+ // enable combo loader? this significantly helps with caching and performance
+ $this->yui3loader->combine = !empty($CFG->yuicomboloading);
+ $this->yui2loader->combine = !empty($CFG->yuicomboloading);
}
/**
$value = $_GET['amp;'.$name];
}
+ return min_clean_param($value, $type);
+}
+
+/**
+ * Minimalistic parameter cleaning function.
+ * Can not use optional param because moodlelib.php is not loaded yet
+ * @param string $name
+ * @param mixed $default
+ * @param string $type
+ * @return mixed
+ */
+function min_clean_param($value, $type) {
switch($type) {
case 'RAW': break;
case 'INT': $value = (int)$value;
}
return $value;
-}
-
+}
\ No newline at end of file
// legacy YUI2 stylesheets, YUI3 stylesheets are loaded on the fly
$yui2_sheets = "\n\n/*** Standard YUI2 sheets ***/\n\n";
- $items = new DirectoryIterator("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam");
+ $items = new DirectoryIterator("$CFG->libdir/yui/$CFG->yui2version/build/assets/skins/sam");
foreach ($items as $item) {
if ($item->isDot() or !$item->isFile()) {
continue;
if (substr($filename, -4) !== '.css') {
continue;
}
- $yui2_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam/$filename");
+ $yui2_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/build/assets/skins/sam/$filename");
}
unset($item);
unset($items);
// search for all images in yui2 CSS and serve them through the yui_image.php script
- $yui2_sheets = preg_replace('/([a-z-]+)\.(png|gif)/', 'yui_image.php?file='.$CFG->yui2version.'/$1.$2', $yui2_sheets);
- $css['yui2'][] = $this->post_process($yui2_sheets);
+ $css['yui2'][] = preg_replace('/([a-z-]+)\.(png|gif)/', 'yui_image.php?file='.$CFG->yui2version.'/$1.$2', $yui2_sheets);
// get all plugin sheets
$excludes = null;
<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is responsible for serving of yui images
+ *
+ * @package moodlecore
+ * @copyright 2009 Petr Skoda (skodak) {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+// 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
+
+// get special url parameters
+if (!$parts = combo_params()) {
+ combo_not_found();
+}
+
+// find out what we are serving - only one type per request
+$content = '';
+if (substr($parts, -3) === '.js') {
+ $mimetype = 'application/x-javascript';
+} else if (substr($parts, -4) === '.css') {
+ $mimetype = 'text/css';
+} else {
+ combo_not_found();
+}
+
+$parts = explode('&', $parts);
+
+foreach ($parts as $part) {
+ $part = min_clean_param($part, 'SAFEPATH');
+ $bits = explode('/', $part);
+ if (count($bits) < 2) {
+ combo_not_found();
+ }
+ $version = $bits[0];
+ if ($version != $CFG->yui3version and $version != $CFG->yui2version) {
+ combo_not_found();
+ }
+ $contentfile = "$CFG->libdir/yui/$part";
+ if (!file_exists($contentfile) or !is_file($contentfile)) {
+ combo_not_found();
+ }
+ $filecontent = file_get_contents($contentfile);
+
+ if ($mimetype === 'text/css') {
+ // search for all images in yui2 CSS and serve them through the yui_image.php script
+ $filecontent = preg_replace('/([a-z-]+)\.(png|gif)/', 'yui_image.php?file='.$version.'/$1.$2', $filecontent);
+ }
+
+ $content .= $filecontent;
+}
+
+
+combo_send_cached($content, $mimetype);
+
+
+
+function combo_send_cached($content, $mimetype) {
+ $lifetime = 60*60*24*300; // 300 days === forever
+
+ header('Content-Disposition: inline; filename="combo"');
+ header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
+ header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
+ header('Pragma: ');
+ header('Accept-Ranges: none');
+ header('Content-Type: '.$mimetype);
+ header('Content-Length: '.strlen($content));
+
+ while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
+ echo $content;
+ die;
+}
+
+function combo_not_found() {
+ header('HTTP/1.0 404 not found');
+ die('Combo resource not found, sorry.');
+}
+
+function combo_params() {
+ if (!empty($_SERVER['REQUEST_URI'])) {
+ $parts = explode('?', $_SERVER['REQUEST_URI']);
+ if (count($parts) != 2) {
+ return '';
+ }
+ return $parts[1];
+
+ } else if (!empty($_SERVER['QUERY_STRING'])) {
+ return $_SERVER['QUERY_STRING'];
+
+ } else {
+ return '';
+ }
+}
list($version, $image) = $parts;
if ($version == $CFG->yui3version) {
- $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/assets/skins/sam/$image";
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/build/assets/skins/sam/$image";
} else if ($version == $CFG->yui2version) {
- $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/assets/skins/sam/$image";
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/build/assets/skins/sam/$image";
} else {
yui_image_not_found();
}