mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-21189 custom yui image loading needed for combo yui loader
This commit is contained in:
parent
1b6ab8924f
commit
60f2c8666a
@ -141,9 +141,9 @@ class page_requirements_manager {
|
||||
$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=';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,12 +44,20 @@ function min_optional_param($name, $default, $type) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -632,7 +632,8 @@ class theme_config {
|
||||
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
|
||||
@ -877,14 +878,6 @@ class theme_config {
|
||||
}
|
||||
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;
|
||||
|
@ -26,14 +26,6 @@
|
||||
* @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.
|
||||
@ -48,6 +40,21 @@ if (defined('ABORT_AFTER_CONFIG')) {
|
||||
*/
|
||||
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
|
||||
@ -201,9 +208,6 @@ if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
|
||||
// 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;
|
||||
@ -239,10 +243,6 @@ if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
||||
$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
|
||||
|
@ -121,7 +121,7 @@ if ($rev > -1) {
|
||||
// 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'];
|
||||
|
||||
|
1
theme/yui_combo.php
Normal file
1
theme/yui_combo.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
85
theme/yui_image.php
Normal file
85
theme/yui_image.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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.');
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user