$this->yui2loader->base = $CFG->httpswwwroot . '/lib/yui/'. $CFG->yui2version . '/';
}
- // This file helps to minimise number of http requests
- //$this->yui3loader->comboBase = $CFG->httpswwwroot . '/theme/yuicomboloader.php?';
- //$this->yui2loader->comboBase = $CFG->httpswwwroot . '/theme/yuicomboloader.php?';
+ // 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=';
}
/**
// very, very, very ugly hack, unforunately $OUTPUT->pix_url() is not used properly in javascript code :-(
$value = $_GET['amp;'.$name];
}
+
switch($type) {
- case 'INT': $value = (int)$value; break;
- case 'SAFEDIR': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); break;
- case 'SAFEPATH': $value = preg_replace('/[^a-zA-Z0-9\/_-]/', '', $value); break;
+ case 'RAW': break;
+ case 'INT': $value = (int)$value;
+ break;
+ case 'SAFEDIR': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
+ break;
+ case 'SAFEPATH': $value = preg_replace('/[^a-zA-Z0-9\/\._-]/', '', $value);
+ $value = preg_replace('/\.+/', '.', $value);
+ $value = preg_replace('#/+#', '/', $value);
+ break;
default: die("Coding error: incorrent parameter type specified ($type).");
}
+
return $value;
}
unset($item);
unset($items);
- $yui2_sheets = preg_replace('/([a-z-]+)\.(png|gif)/', '[[pix:yui2|$1]]', $yui2_sheets);
+ // 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);
// get all plugin sheets
}
return null;
- } else if ($component === 'yui2') {
- // YUI2 is here for legacy reasons only, YUI3 images are not handled here
- // yui images need to be overriden with CSS using proper selectors
- if ($imagefile = $this->image_exists("$CFG->libdir/yui/$CFG->yui2version/assets/skins/sam/$image")) {
- return $imagefile;
- }
- return null;
-
} else {
if (strpos($component, '_') === false) {
$component = 'mod_'.$component;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-// special support for highly optimised scripts that do not need libraries and DB connection
-if (defined('ABORT_AFTER_CONFIG')) {
- if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
- require_once("$CFG->dirroot/lib/configonlylib.php");
- return;
- }
-}
-
/**
* Holds the core settings that affect how Moodle works. Some of its fields
* are set in config.php, and the rest are loaded from the config table.
*/
global $CFG;
+// Set up some paths.
+$CFG->libdir = $CFG->dirroot .'/lib';
+
+// exact version of currently used yui2 and 3 library
+$CFG->yui2version = '2.8.0r4';
+$CFG->yui3version = '3.0.0';
+
+// special support for highly optimised scripts that do not need libraries and DB connection
+if (defined('ABORT_AFTER_CONFIG')) {
+ if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
+ require_once("$CFG->dirroot/lib/configonlylib.php");
+ return;
+ }
+}
+
/**
* Database connection. Used for all access to the database.
* @global moodle_database $DB
// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
$CFG->config_php_settings = (array)$CFG;
-// Set up some paths.
-$CFG->libdir = $CFG->dirroot .'/lib';
-
// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
// inside some URLs used in HTTPSPAGEREQUIRED pages.
$CFG->httpswwwroot = $CFG->wwwroot;
$CFG->prefix = '';
}
-// exact version of currently used yui2 and 3 library
-$CFG->yui2version = '2.8.0r4';
-$CFG->yui3version = '3.0.0';
-
// Load up standard libraries
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
require_once($CFG->libdir .'/filterlib.php'); // Functions for filtering test as it is output
// parameters to get the best performance.
function send_cached_image($imagepath, $rev) {
- $lifetime = 60*60*24*3;
+ $lifetime = 60*60*24*3; // 3 days
$pathinfo = pathinfo($imagepath);
$imagename = $pathinfo['filename'].'.'.$pathinfo['extension'];
--- /dev/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
+
+$path = min_optional_param('file', '', 'SAFEPATH');
+
+$parts = explode('/', $path);
+if (count($parts) != 2) {
+ yui_image_not_found();
+}
+list($version, $image) = $parts;
+
+if ($version == $CFG->yui3version) {
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui3version/assets/skins/sam/$image";
+} else if ($version == $CFG->yui2version) {
+ $imagepath = "$CFG->dirroot/lib/yui/$CFG->yui2version/assets/skins/sam/$image";
+} else {
+ yui_image_not_found();
+}
+
+if (!file_exists($imagepath)) {
+ yui_image_not_found();
+}
+
+yui_image_cached($imagepath);
+
+
+
+function yui_image_cached($imagepath) {
+ $lifetime = 60*60*24*300; // 300 days === forever
+ $pathinfo = pathinfo($imagepath);
+ $imagename = $pathinfo['filename'].'.'.$pathinfo['extension'];
+
+ switch($pathinfo['extension']) {
+ case 'gif' : $mimetype = 'image/gif'; break;
+ case 'png' : $mimetype = 'image/png'; break;
+ case 'jpg' : $mimetype = 'image/jpeg'; break;
+ case 'jpeg' : $mimetype = 'image/jpeg'; break;
+ case 'ico' : $mimetype = 'image/vnd.microsoft.icon'; break;
+ default: $mimetype = 'document/unknown';
+ }
+
+ header('Content-Disposition: inline; filename="'.$imagename.'"');
+ header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($imagepath)) .' 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: '.filesize($imagepath));
+
+ while (@ob_end_flush()); //flush the buffers - save memory and disable sid rewrite
+ readfile($imagepath);
+ die;
+}
+
+function yui_image_not_found() {
+ header('HTTP/1.0 404 not found');
+ die('Image was not found, sorry.');
+}