/** * @see Minify_Controller_Base::loadMinifier() */ public function loadMinifier($minifierCallback) { if ($this->_loadCssJsMinifiers) { // Minify will not call for these so we must manually load // them when Minify/HTML.php is called for. } parent::loadMinifier($minifierCallback); // load Minify/HTML.php }
/** * @see Minify_Controller_Base::loadMinifier() */ public function loadMinifier($minifierCallback) { if ($this->_loadCssJsMinifiers) { // Minify will not call for these so we must manually load // them when Minify/HTML.php is called for. require_once W3TC_LIB_MINIFY_DIR . '/Minify/CSS.php'; require_once W3TC_LIB_MINIFY_DIR . '/JSMin.php'; } parent::loadMinifier($minifierCallback); // load Minify/HTML.php }
/** * Combines sources and minifies the result. * * @return string */ protected static function _combineMinify() { $type = self::$_options['contentType']; // ease readability // when combining scripts, make sure all statements separated and // trailing single line comment is terminated $implodeSeparator = $type === self::TYPE_JS ? "\n;" : ''; // allow the user to pass a particular array of options to each // minifier (designated by type). source objects may still override // these $defaultOptions = isset(self::$_options['minifierOptions'][$type]) ? self::$_options['minifierOptions'][$type] : array(); // if minifier not set, default is no minification. source objects // may still override this $defaultMinifier = isset(self::$_options['minifiers'][$type]) ? self::$_options['minifiers'][$type] : false; // process groups of sources with identical minifiers/options $content = array(); $i = 0; $l = count(self::$_controller->sources); $groupToProcessTogether = array(); $lastMinifier = null; $lastOptions = null; do { // get next source $source = null; if ($i < $l) { $source = self::$_controller->sources[$i]; /* @var Minify_Source $source */ $sourceContent = $source->getContent(); // allow the source to override our minifier and options $minifier = null !== $source->minifier ? $source->minifier : $defaultMinifier; $options = null !== $source->minifyOptions ? array_merge($defaultOptions, $source->minifyOptions) : $defaultOptions; } // do we need to process our group right now? if ($i > 0 && (!$source || $type === self::TYPE_CSS || $minifier !== $lastMinifier || $options !== $lastOptions)) { // minify previous sources with last settings $imploded = implode($implodeSeparator, $groupToProcessTogether); $groupToProcessTogether = array(); if ($lastMinifier) { self::$_controller->loadMinifier($lastMinifier); try { $content[] = call_user_func($lastMinifier, $imploded, $lastOptions); } catch (Exception $e) { throw new Exception("Exception in minifier: " . $e->getMessage()); } } else { $content[] = $imploded; } } // add content to the group if ($source) { $groupToProcessTogether[] = $sourceContent; $lastMinifier = $minifier; $lastOptions = $options; } $i++; } while ($source); $content = implode($implodeSeparator, $content); if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) { $content = self::_handleCssImports($content); } // do any post-processing (esp. for editing build URIs) if (self::$_options['postprocessorRequire']) { require_once self::$_options['postprocessorRequire']; } if (self::$_options['postprocessor']) { $content = call_user_func(self::$_options['postprocessor'], $content, $type); } return $content; }