|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00007 require_once 'Minify/Controller/Base.php'; 00008 00019 class Minify_Controller_Version1 extends Minify_Controller_Base { 00020 00028 public function setupSources($options) { 00029 self::_setupDefines(); 00030 if (MINIFY_USE_CACHE) { 00031 $cacheDir = defined('MINIFY_CACHE_DIR') 00032 ? MINIFY_CACHE_DIR 00033 : ''; 00034 Minify::setCache($cacheDir); 00035 } 00036 $options['badRequestHeader'] = 'HTTP/1.0 404 Not Found'; 00037 $options['contentTypeCharset'] = MINIFY_ENCODING; 00038 00039 // The following restrictions are to limit the URLs that minify will 00040 // respond to. Ideally there should be only one way to reference a file. 00041 if (! isset($_GET['files']) 00042 // verify at least one file, files are single comma separated, 00043 // and are all same extension 00044 || ! preg_match('/^[^,]+\\.(css|js)(,[^,]+\\.\\1)*$/', $_GET['files'], $m) 00045 // no "//" (makes URL rewriting easier) 00046 || strpos($_GET['files'], '//') !== false 00047 // no "\" 00048 || strpos($_GET['files'], '\\') !== false 00049 // no "./" 00050 || preg_match('/(?:^|[^\\.])\\.\\//', $_GET['files']) 00051 ) { 00052 return $options; 00053 } 00054 $extension = $m[1]; 00055 00056 $files = explode(',', $_GET['files']); 00057 if (count($files) > MINIFY_MAX_FILES) { 00058 return $options; 00059 } 00060 00061 // strings for prepending to relative/absolute paths 00062 $prependRelPaths = dirname($_SERVER['SCRIPT_FILENAME']) 00063 . DIRECTORY_SEPARATOR; 00064 $prependAbsPaths = $_SERVER['DOCUMENT_ROOT']; 00065 00066 $sources = array(); 00067 $goodFiles = array(); 00068 $hasBadSource = false; 00069 00070 $allowDirs = isset($options['allowDirs']) 00071 ? $options['allowDirs'] 00072 : MINIFY_BASE_DIR; 00073 00074 foreach ($files as $file) { 00075 // prepend appropriate string for abs/rel paths 00076 $file = ($file[0] === '/' ? $prependAbsPaths : $prependRelPaths) . $file; 00077 // make sure a real file! 00078 $file = realpath($file); 00079 // don't allow unsafe or duplicate files 00080 if (parent::_fileIsSafe($file, $allowDirs) 00081 && !in_array($file, $goodFiles)) 00082 { 00083 $goodFiles[] = $file; 00084 $srcOptions = array( 00085 'filepath' => $file 00086 ); 00087 $this->sources[] = new Minify_Source($srcOptions); 00088 } else { 00089 $hasBadSource = true; 00090 break; 00091 } 00092 } 00093 if ($hasBadSource) { 00094 $this->sources = array(); 00095 } 00096 if (! MINIFY_REWRITE_CSS_URLS) { 00097 $options['rewriteCssUris'] = false; 00098 } 00099 return $options; 00100 } 00101 00102 private static function _setupDefines() 00103 { 00104 $defaults = array( 00105 'MINIFY_BASE_DIR' => realpath($_SERVER['DOCUMENT_ROOT']) 00106 ,'MINIFY_ENCODING' => 'utf-8' 00107 ,'MINIFY_MAX_FILES' => 16 00108 ,'MINIFY_REWRITE_CSS_URLS' => true 00109 ,'MINIFY_USE_CACHE' => true 00110 ); 00111 foreach ($defaults as $const => $val) { 00112 if (! defined($const)) { 00113 define($const, $val); 00114 } 00115 } 00116 } 00117 } 00118