/** * Remove whitespaces from HTML code * * @param string $html * @param boolean $compress_all Compress embedded css and js code * * @return string */ public static function process($html, array $settings = array()) { require_once dirname(__FILE__) . '/min-html.php'; $settings = self::$_settings = $settings + array('compress_all' => true, 'css' => array(), 'js' => array(), 'markers' => array('<?'), 'external_services' => true); if ($settings['compress_all']) { return Minify_HTML::minify($html, array('cssMinifier' => array(__CLASS__, '_compress_inline_css'), 'jsMinifier' => array(__CLASS__, '_compress_inline_js'))); } else { return Minify_HTML::minify($html); } }
/** * Compressor libraries */ public function _compressor($language, $code = "") { $root = realpath(__DIR__); require_once $root . "/min-css.php"; require_once $root . "/jshrink.php"; require_once $root . "/html-compress.php"; if (mb_strlen($code, '8bit') > 500000) { return $code; } else { if ($language == "css") { /** * What kind of css stuff should it convert */ $minifier = new MatthiasMullie\Minify\CSS(); $minifier->add($code); return $minifier->minify(); } elseif ($language == "js") { return \JShrink\Minifier::minify($code); } elseif ($language == "html") { $html = new Tinyfier_HTML_Tool(); if ($this->curOptions['compress']["minInline"]) { return $html->process($code, array("compress_all" => true)); } else { return $html->process($code, array("compress_all" => false)); } } } }
/** * Compress each languages * @param string $language The language of source code * @param string $code The source code * @return string Compressed code */ public static function _compressor($language, $code = "", $minInline) { /** * Skip if file size is > 500KB */ if (mb_strlen($code, '8bit') > 500000) { return $code; } else { if ($language == "css") { /** * What kind of css stuff should it convert */ $minifier = new MatthiasMullie\Minify\CSS(); $minifier->add($code); return $minifier->minify(); } else { if ($language == "js") { return JShrink\Minifier::minify($code); } else { if ($language == "html") { $html = new Tinyfier_HTML_Tool(); if ($minInline) { return $html->process($code, array("compress_all" => true)); } else { return $html->process($code, array("compress_all" => false)); } } } } } }