|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 define('ABORT_AFTER_CONFIG', true); 00028 require('../config.php'); // this stops immediately at the beginning of lib/setup.php 00029 00030 $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); 00031 $type = min_optional_param('type', '', 'SAFEDIR'); 00032 $subtype = min_optional_param('subtype', '', 'SAFEDIR'); 00033 $sheet = min_optional_param('sheet', '', 'SAFEDIR'); 00034 00035 if (!defined('THEME_DESIGNER_CACHE_LIFETIME')) { 00036 define('THEME_DESIGNER_CACHE_LIFETIME', 4); // this can be also set in config.php 00037 } 00038 00039 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { 00040 // exists 00041 } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { 00042 // exists 00043 } else { 00044 css_not_found(); 00045 } 00046 00047 // no gzip compression when debugging 00048 00049 $candidatesheet = "$CFG->cachedir/theme/$themename/designer.ser"; 00050 00051 if (!file_exists($candidatesheet)) { 00052 css_not_found(); 00053 } 00054 00055 if (!$css = file_get_contents($candidatesheet)) { 00056 css_not_found(); 00057 } 00058 00059 $css = unserialize($css); 00060 00061 if ($type === 'editor') { 00062 if (isset($css['editor'])) { 00063 send_uncached_css(implode("\n\n", $css['editor'])); 00064 } 00065 } else if ($type === 'ie') { 00066 // IE is a sloppy browser with weird limits, sorry 00067 if ($subtype === 'plugins') { 00068 $sendcss = implode("\n\n", $css['plugins']); 00069 $sendcss = str_replace("\n", "\r\n", $sendcss); 00070 send_uncached_css($sendcss); 00071 00072 } else if ($subtype === 'parents') { 00073 $sendcss = array(); 00074 if (empty($sheet)) { 00075 // If not specific parent has been specified as $sheet then build a 00076 // collection of @import statements into this one sheet. 00077 // We shouldn't ever actually get here, but none the less we'll deal 00078 // with it incase we ever do. 00079 // @import statements arn't processed until after concurrent CSS requests 00080 // making them slightly evil. 00081 foreach (array_keys($css['parents']) as $sheet) { 00082 $sendcss[] = "@import url(styles_debug.php?theme=$themename&type=$type&subtype=$subtype&sheet=$sheet);"; 00083 } 00084 } else { 00085 // Build up the CSS for that parent so we can serve it as one file. 00086 foreach ($css[$subtype][$sheet] as $parent=>$css) { 00087 $sendcss[] = $css; 00088 } 00089 } 00090 $sendcss = implode("\n\n", $sendcss); 00091 $sendcss = str_replace("\n", "\r\n", $sendcss); 00092 send_uncached_css($sendcss); 00093 00094 } else if ($subtype === 'theme') { 00095 $sendcss = implode("\n\n", $css['theme']); 00096 $sendcss = str_replace("\n", "\r\n", $sendcss); 00097 send_uncached_css($sendcss); 00098 } 00099 00100 } else if ($type === 'plugin') { 00101 if (isset($css['plugins'][$subtype])) { 00102 send_uncached_css($css['plugins'][$subtype]); 00103 } 00104 00105 } else if ($type === 'parent') { 00106 if (isset($css['parents'][$subtype][$sheet])) { 00107 send_uncached_css($css['parents'][$subtype][$sheet]); 00108 } 00109 00110 } else if ($type === 'theme') { 00111 if (isset($css['theme'][$sheet])) { 00112 send_uncached_css($css['theme'][$sheet]); 00113 } 00114 } 00115 css_not_found(); 00116 00117 //================================================================================= 00118 //=== utility functions == 00119 // we are not using filelib because we need to fine tune all header 00120 // parameters to get the best performance. 00121 00122 function send_uncached_css($css) { 00123 header('Content-Disposition: inline; filename="styles_debug.php"'); 00124 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT'); 00125 header('Expires: '. gmdate('D, d M Y H:i:s', time() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT'); 00126 header('Pragma: '); 00127 header('Accept-Ranges: none'); 00128 header('Content-Type: text/css; charset=utf-8'); 00129 //header('Content-Length: '.strlen($css)); 00130 00131 echo($css); 00132 die; 00133 } 00134 00135 function css_not_found() { 00136 header('HTTP/1.0 404 not found'); 00137 die('CSS was not found, sorry.'); 00138 } 00139