diff -r 74e03196fd43 -r e45183014778 includes/clientside/jscompress.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/includes/clientside/jscompress.php Sun Jul 20 13:32:04 2008 -0400 @@ -0,0 +1,188 @@ +This script is designed to be run from a command-line environment.

'); +} + +if ( !getConfig('cdn_path') ) +{ + die_friendly('CDN support not enabled', 'This script is for compressing the Enano Javascript runtimes for CDN use.'); +} + +echo "\x1B[1mCreating zip file with compressed Javascript runtimes.\x1B[0m\n"; +echo "\x1B[0;32mWhen finished, upload the contents of enano-lib.zip to:\n\x1B[1;34m " . getConfig('cdn_path') . "/includes/clientside/static/\x1B[0m\n"; + +echo "\x1B[0;33mChecking for zip support..."; + +// do we have zip file support? +$have_zip = false; +$path = ( isset($_SERVER['PATH']) ) ? $_SERVER['PATH'] : false; +if ( !$path ) +{ + die_semicritical('Can\'t get your PATH', 'Unable to get the PATH environment variable'); +} + +$path = ( strtolower(PHP_OS) === 'win32' ) ? explode(';', $path) : explode(':', $path); +$pathext = ( strtolower(PHP_OS) === 'win32' ) ? '.exe' : ''; + +foreach ( $path as $dir ) +{ + if ( file_exists("$dir/zip$pathext") ) + { + $have_zip = true; + break; + } +} + +if ( !$have_zip ) +{ + // no zupport zor zipping ziles + echo "\x1B[31;1mnot found\x1B[0m\n\x1B[1mPlease install the zip utility using your distribution's package manager\nand then rerun this script.\x1B[0m"; + exit(1); +} + +echo "\x1B[1mall good\x1B[0m\n"; +echo "\x1B[0;33mMinifying Javascript files..."; + +if ( !@mkdir('includes/clientside/staticmin') ) +{ + echo "\x1B[31;1mcouldn't create temp directory\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create includes/clientside/staticmin.\x1B[0m"; + exit(1); +} + +require('includes/clientside/jsres.php'); + +// $everything now contains the core runtimes +// hack to lie about compression, this keeps load_component() from doing jsres.php?f=... +$everything = str_replace('ENANO_JSRES_COMPRESSED = true', 'ENANO_JSRES_COMPRESSED = false', $everything); + +chdir('includes/clientside/staticmin'); +$handle = @fopen('./enano-lib-basic.js', 'w'); +if ( !$handle ) +{ + echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; + exit(1); +} + +fwrite($handle, $everything); +fclose($handle); + +// for each JS file in includes/clientside/static, compress & write +if ( $dr = @opendir('../static') ) +{ + while ( $dh = @readdir($dr) ) + { + if ( !preg_match('/\.js$/', $dh) || $dh === 'enano-lib-basic.js' ) + continue; + + $contents = @file_get_contents("../static/$dh"); + $compressed = jsres_cache_check($dh, $contents); + $compressed = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $compressed); + + $handle = @fopen("./$dh", 'w'); + if ( !$handle ) + { + echo "\x1B[31;1mcouldn't open file\x1B[0m\n\x1B[1mCheck permissions please, we couldn't create a file inside includes/clientside/staticmin.\x1B[0m"; + exit(1); + } + fwrite($handle, $compressed); + fclose($handle); + } +} +else +{ + echo "\x1B[31;1mcouldn't open includes directory\x1B[0m\n\x1B[1mUnable to get our hands into includes/clientside/static/ to compress everything.\x1B[0m"; + exit(1); +} + +echo "\x1B[1mdone\x1B[0m\n"; +echo "\x1B[0;33mCompressing into enano-lib.zip..."; + +$result = system('zip -yrq9 ../enano-lib.zip *.js'); +if ( $result != 0 ) +{ + // failure + echo "\x1B[31;1mzip creation failed\x1B[0m\n\x1B[1mzip returned result $result\x1B[0m"; + exit(1); +} + +echo "\x1B[1mdone\x1B[0m\n"; + +// done, clean up + +echo "\x1B[0;33mCleaning up..."; +chdir('..'); + +if ( $dr = @opendir('./staticmin') ) +{ + while ( $dh = @readdir($dr) ) + { + if ( preg_match('/\.js$/', $dh) ) + unlink("./staticmin/$dh"); + } +} + +@rmdir('./staticmin'); + +echo "\x1B[1mdone\x1B[0m\n";