Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/minify/lib/Minify/Controller/Base.php
Go to the documentation of this file.
00001 <?php
00017 abstract class Minify_Controller_Base {
00018     
00032     abstract public function setupSources($options);
00033     
00041     public function getDefaultMinifyOptions() {
00042         return array(
00043             'isPublic' => true
00044             ,'encodeOutput' => function_exists('gzdeflate')
00045             ,'encodeMethod' => null // determine later
00046             ,'encodeLevel' => 9
00047             ,'minifierOptions' => array() // no minifier options
00048             ,'contentTypeCharset' => 'utf-8'
00049             ,'maxAge' => 1800 // 30 minutes
00050             ,'rewriteCssUris' => true
00051             ,'bubbleCssImports' => false
00052             ,'quiet' => false // serve() will send headers and output
00053             ,'debug' => false
00054             
00055             // if you override this, the response code MUST be directly after 
00056             // the first space.
00057             ,'badRequestHeader' => 'HTTP/1.0 400 Bad Request'
00058             
00059             // callback function to see/modify content of all sources
00060             ,'postprocessor' => null
00061             // file to require to load preprocessor
00062             ,'postprocessorRequire' => null
00063         );
00064     }  
00065 
00073     public function getDefaultMinifers() {
00074         $ret[Minify::TYPE_JS] = array('JSMin', 'minify');
00075         $ret[Minify::TYPE_CSS] = array('Minify_CSS', 'minify');
00076         $ret[Minify::TYPE_HTML] = array('Minify_HTML', 'minify');
00077         return $ret;
00078     }
00079     
00097     public function loadMinifier($minifierCallback)
00098     {
00099         if (is_array($minifierCallback)
00100             && is_string($minifierCallback[0])
00101             && !class_exists($minifierCallback[0], false)) {
00102             
00103             require str_replace('_', '/', $minifierCallback[0]) . '.php';
00104         }
00105     }
00106     
00121     public static function _fileIsSafe($file, $safeDirs)
00122     {
00123         $pathOk = false;
00124         foreach ((array)$safeDirs as $safeDir) {
00125             if (strpos($file, $safeDir) === 0) {
00126                 $pathOk = true;
00127                 break;
00128             }
00129         }
00130         $base = basename($file);
00131         if (! $pathOk || ! is_file($file) || $base[0] === '.') {
00132             return false;
00133         }
00134         list($revExt) = explode('.', strrev($base));
00135         return in_array(strrev($revExt), array('js', 'css', 'html', 'txt'));
00136     }
00137     
00144     public $sources = array();
00145     
00153     public final function mixInDefaultOptions($options)
00154     {
00155         $ret = array_merge(
00156             $this->getDefaultMinifyOptions(), $options
00157         );
00158         if (! isset($options['minifiers'])) {
00159             $options['minifiers'] = array();
00160         }
00161         $ret['minifiers'] = array_merge(
00162             $this->getDefaultMinifers(), $options['minifiers']
00163         );
00164         return $ret;
00165     }
00166     
00175     public final function analyzeSources($options = array()) 
00176     {
00177         if ($this->sources) {
00178             if (! isset($options['contentType'])) {
00179                 $options['contentType'] = Minify_Source::getContentType($this->sources);
00180             }
00181             // last modified is needed for caching, even if setExpires is set
00182             if (! isset($options['lastModifiedTime'])) {
00183                 $max = 0;
00184                 foreach ($this->sources as $source) {
00185                     $max = max($source->lastModified, $max);
00186                 }
00187                 $options['lastModifiedTime'] = $max;
00188             }    
00189         }
00190         return $options;
00191     }
00192 
00198     protected function log($msg) {
00199         require_once 'Minify/Logger.php';
00200         Minify_Logger::log($msg);
00201     }
00202 }
 All Data Structures Namespaces Files Functions Variables Enumerations