Ejemplo n.º 1
0
 private function fail($js, $errorMessage)
 {
     Minify0_Minify::$recoverableError = $errorMessage;
     $response = "/* " . $errorMessage . "\n(Using fallback minifier)\n*/\n";
     if (is_callable($this->_fallbackFunc)) {
         $response .= call_user_func($this->_fallbackFunc, $js);
     } else {
         $response .= $js;
     }
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Set up groups of files as sources
  * 
  * @param array $options controller and Minify options
  * @return array Minify options
  * 
  */
 public function setupSources($options)
 {
     // PHP insecure by default: realpath() and other FS functions can't handle null bytes.
     if (isset($_GET['files'])) {
         $_GET['files'] = str_replace("", '', (string) $_GET['files']);
     }
     self::_setupDefines();
     if (MINIFY_USE_CACHE) {
         $cacheDir = defined('MINIFY_CACHE_DIR') ? MINIFY_CACHE_DIR : '';
         Minify0_Minify::setCache($cacheDir);
     }
     $options['badRequestHeader'] = 'HTTP/1.0 404 Not Found';
     $options['contentTypeCharset'] = MINIFY_ENCODING;
     // The following restrictions are to limit the URLs that minify will
     // respond to. Ideally there should be only one way to reference a file.
     if (!isset($_GET['files']) || !preg_match('/^[^,]+\\.(css|js)(,[^,]+\\.\\1)*$/', $_GET['files'], $m) || strpos($_GET['files'], '//') !== false || strpos($_GET['files'], '\\') !== false || preg_match('/(?:^|[^\\.])\\.\\//', $_GET['files'])) {
         return $options;
     }
     $files = explode(',', $_GET['files']);
     if (count($files) > MINIFY_MAX_FILES) {
         return $options;
     }
     // strings for prepending to relative/absolute paths
     $prependRelPaths = dirname($_SERVER['SCRIPT_FILENAME']) . DIRECTORY_SEPARATOR;
     $prependAbsPaths = $_SERVER['DOCUMENT_ROOT'];
     $goodFiles = array();
     $hasBadSource = false;
     $allowDirs = isset($options['allowDirs']) ? $options['allowDirs'] : MINIFY_BASE_DIR;
     foreach ($files as $file) {
         // prepend appropriate string for abs/rel paths
         $file = ($file[0] === '/' ? $prependAbsPaths : $prependRelPaths) . $file;
         // make sure a real file!
         $file = realpath($file);
         // don't allow unsafe or duplicate files
         if (parent::_fileIsSafe($file, $allowDirs) && !in_array($file, $goodFiles)) {
             $goodFiles[] = $file;
             $srcOptions = array('filepath' => $file);
             $this->sources[] = new Minify_Source($srcOptions);
         } else {
             $hasBadSource = true;
             break;
         }
     }
     if ($hasBadSource) {
         $this->sources = array();
     }
     if (!MINIFY_REWRITE_CSS_URLS) {
         $options['rewriteCssUris'] = false;
     }
     return $options;
 }
Ejemplo n.º 3
0
 /**
  * Sets cache ID
  * @param string $cacheId
  */
 public static function setCacheId($cacheId = null)
 {
     self::$_cacheId = $cacheId;
 }
 public function w3tc_usage_statistics_of_request($storage)
 {
     $stats = \Minify0_Minify::getUsageStatistics();
     if (count($stats) > 0) {
         $storage->counter_add('minify_requests_total', 1);
         if ($stats['content_type'] == 'text/css') {
             $storage->counter_add('minify_original_length_css', (int) ($stats['content_original_length'] / 102.4));
             $storage->counter_add('minify_output_length_css', (int) ($stats['content_output_length'] / 102.4));
         } else {
             $storage->counter_add('minify_original_length_js', (int) ($stats['content_original_length'] / 102.4));
             $storage->counter_add('minify_output_length_js', (int) ($stats['content_output_length'] / 102.4));
         }
     }
 }