From f40aebaffdde11d95282b77c9ca7018cffcb61dd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 6 Nov 2009 15:02:17 -0700 Subject: [PATCH] Add support for Google Closure Compiler in javascript minfiy filter --- framework/Core/lib/Horde.php | 15 +++++++++++-- .../lib/Horde/Text/Filter/JavascriptMinify.php | 25 +++++++++++++++------- framework/Text_Filter/package.xml | 3 ++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index b088f5d2f..48b646588 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -329,13 +329,24 @@ HTML; : $conf['cachejsparams']['lifetime']; } - if ($conf['cachejsparams']['compress'] == 'yui') { + switch ($conf['cachejsparams']['compress']) { + case 'closure': + $jsmin_params = array( + 'closure' => $conf['cachejsparams']['closurepath'], + 'java' => $conf['cachejsparams']['javapath'] + ); + break; + + case 'yui': $jsmin_params = array( 'java' => $conf['cachejsparams']['javapath'], 'yui' => $conf['cachejsparams']['yuipath'] ); - } else { + break; + + default: $jsmin_params = array(); + break; } /* Output prototype.js separately from the other files. */ diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/JavascriptMinify.php b/framework/Text_Filter/lib/Horde/Text/Filter/JavascriptMinify.php index 1809e832c..5d7b934e0 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/JavascriptMinify.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/JavascriptMinify.php @@ -19,6 +19,7 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter * @var array */ protected $_params = array( + 'closure' => null, 'java' => null, 'yui' => null ); @@ -32,10 +33,16 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter */ public function postProcess($text) { - /* Are we using the YUI Compressor? */ - if (!empty($this->_params['yui']) && - !empty($this->_params['java'])) { - return $this->_runYuiCompressor($text); + if (!empty($this->_params['java'])) { + /* Are we using the YUI Compressor? */ + if (!empty($this->_params['yui'])) { + return $this->_runCompressor($text, $this->_params['yui'], ' --type js'); + } + + /* Are we using the Google Closure Compiler? */ + if (!empty($this->_params['closure'])) { + return $this->_runCompressor($text, $this->_params['closure']); + } } /* Use PHP-based minifier. */ @@ -48,16 +55,18 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter } /** - * Passes javascript through YUI Compressor. + * Passes javascript through a java compressor (YUI or Closure). * * @param string $text The javascript text. + * @param string $jar The JAR location. + * @param string $args Additional command line arguments. * * @return string The modified text. */ - protected function _runYuiCompressor($text) + protected function _runCompressor($jar, $args = '') { if (!is_executable($this->_params['java']) || - !file_exists($this->_params['yui'])) { + !file_exists($jar)) { return $text; } @@ -67,7 +76,7 @@ class Horde_Text_Filter_JavascriptMinify extends Horde_Text_Filter 2 => array('pipe', 'w') ); - $process = proc_open(escapeshellcmd($this->_params['java']) . ' -jar ' . escapeshellarg($this->_params['yui']) . ' --type js', $descspec, $pipes); + $process = proc_open(escapeshellcmd($this->_params['java']) . ' -jar ' . escapeshellarg($jar) . $args, $descspec, $pipes); fwrite($pipes[0], $text); fclose($pipes[0]); diff --git a/framework/Text_Filter/package.xml b/framework/Text_Filter/package.xml index 08d66dc6e..8a9a69bcb 100644 --- a/framework/Text_Filter/package.xml +++ b/framework/Text_Filter/package.xml @@ -37,7 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Fix dimming signatures when mixed with quoted text (Bug #4299). + * Add support for Google Closure Compiler in javascript minfiy filter. + * Fix dimming signatures when mixed with quoted text (Bug #4299). * Added javscript minify filter. * Add support for using the tidy extension when filtering HTML data. * Initial Horde 4 package. -- 2.11.0