/** * Process a JS file. * * @param string $js file content * @param string $file * @return string */ private static function process_js($js, $file) { if (strpos($file, '.min') === false and strpos($file, '.packed') === false) { require_once PHPWG_ROOT_PATH . 'include/jshrink.class.php'; try { $js = JShrink_Minifier::minify($js); } catch (Exception $e) { } } return trim($js, " \t\r\n;") . ";\n"; }
/** * Minifier::minify takes a string containing javascript and removes * unneeded characters in order to shrink the code without altering it's * functionality. */ public static function minify($js, $options = array()) { try { ob_start(); $currentOptions = array_merge(self::$defaultOptions, $options); if (!isset(self::$jshrink)) { self::$jshrink = new JShrink_Minifier(); } self::$jshrink->breakdownScript($js, $currentOptions); return ob_get_clean(); } catch (Exception $e) { if (isset(self::$jshrink)) { self::$jshrink->clean(); } ob_end_clean(); throw $e; } }