. /** * 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(); } $parts = trim($parts, '&'); // 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) { if (empty($part)) { continue; } $part = min_clean_param($part, 'SAFEPATH'); $bits = explode('/', $part); if (count($bits) < 2) { $content .= "\n// Wrong combo resource $part!\n"; continue; } $version = $bits[0]; if ($version != $CFG->yui3version and $version != $CFG->yui2version) { $content .= "\n// Wrong yui version $part!\n"; continue; } $contentfile = "$CFG->libdir/yui/$part"; if (!file_exists($contentfile) or !is_file($contentfile)) { $content .= "\n// Combo resource $part not found!\n"; continue; } $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('Cache-Control: max-age=315360000'); header('Accept-Ranges: none'); header('Content-Type: '.$mimetype); if (!min_enable_zlib_compression()) { header('Content-Length: '.strlen($content)); } 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 ''; } }