# HG changeset patch # User Dan # Date 1216575124 14400 # Node ID e45183014778dfd7fc2c1499a366a8cfee973efa # Parent 74e03196fd43e3574102d3ff1bc420b8ce7e2428 Added CDN support: a URL to a CDN can now be specified and Enano will load all images, CSS, and javascript (except TinyMCE) from that server 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"; diff -r 74e03196fd43 -r e45183014778 includes/clientside/jsres.php --- a/includes/clientside/jsres.php Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/clientside/jsres.php Sun Jul 20 13:32:04 2008 -0400 @@ -15,6 +15,12 @@ // define('ENANO_JS_DEBUG', 1); +// if Enano's already loaded, we've been included from a helper script +if ( defined('ENANO_CONFIG_FETCHED') ) + define('ENANO_JSRES_SETUP_ONLY', 1); + +if ( !defined('ENANO_JSRES_SETUP_ONLY') ): + /** * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it * from very early on in the script to measure the starting time of Enano. @@ -73,6 +79,8 @@ define('ENANO_EXIT_AFTER_CONFIG', 1); require('includes/common.php'); +endif; // ENANO_JSRES_SETUP_ONLY + // CONFIG // Files safe to run full (aggressive) compression on @@ -101,9 +109,10 @@ // Files that should NOT be compressed due to already being compressed, licensing, or invalid produced code $compress_unsafe = array('SpryEffects.js', 'json.js', 'fat.js', 'admin-menu.js', 'autofill.js'); -require('includes/js-compressor.php'); +require_once('includes/js-compressor.php'); // try to gzip the output +if ( !defined('ENANO_JSRES_SETUP_ONLY') ): $do_gzip = false; if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) { @@ -118,6 +127,9 @@ // Output format will always be JS header('Content-type: text/javascript'); + +endif; // ENANO_JSRES_SETUP_ONLY + $everything = "/* The code represented in this file is compressed for optimization purposes. The full source code is available in includes/clientside/static/. */\n\nvar ENANO_JSRES_COMPRESSED = true;\n\n"; // if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that @@ -226,6 +238,12 @@ $everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything); $date = date('r', $apex); + +if ( defined('ENANO_JSRES_SETUP_ONLY') ) +{ + return; // we're done setting up, break out +} + header("Date: $date"); header("Last-Modified: $date"); header("ETag: \"$etag\""); diff -r 74e03196fd43 -r e45183014778 includes/clientside/static/ajax.js --- a/includes/clientside/static/ajax.js Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/clientside/static/ajax.js Sun Jul 20 13:32:04 2008 -0400 @@ -1054,7 +1054,7 @@ var target = document.getElementById(targetelement); target.innerHTML = ''; var img = document.createElement('img'); - img.src = scriptPath + '/images/loading.gif'; + img.src = cdnPath + '/images/loading.gif'; img.alt = 'Loading...'; target.appendChild(img); ajaxGet(makeUrlNS('Admin', 'Home/updates.xml'), function() diff -r 74e03196fd43 -r e45183014778 includes/clientside/static/editor.js --- a/includes/clientside/static/editor.js Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/clientside/static/editor.js Sun Jul 20 13:32:04 2008 -0400 @@ -534,7 +534,7 @@ // ajaxSetEditorLoading(); var img = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0]; var lbl = $dynano('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0]; - img.src = scriptPath + '/images/loading.gif'; + img.src = cdnPath + '/images/loading.gif'; var d = new Date(); var m = String(d.getMinutes()); if ( m.length < 2 ) diff -r 74e03196fd43 -r e45183014778 includes/clientside/static/enano-lib-basic.js --- a/includes/clientside/static/enano-lib-basic.js Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/clientside/static/enano-lib-basic.js Sun Jul 20 13:32:04 2008 -0400 @@ -137,7 +137,7 @@ var startwidth = false; var startheight = false; var do_width = false; -var ajax_load_icon = scriptPath + '/images/loading.gif'; +var ajax_load_icon = cdnPath + '/images/loading.gif'; var editor_use_modal_window = false; var Spry = {}; @@ -220,14 +220,14 @@ _load_component_running = true; file = file.replace(/\.js$/, ''); - console.info('Loading component %s via AJAX', file); - - if ( loaded_components[file] ) + if ( loaded_components[file + '.js'] ) { // already loaded return true; } + console.info('Loading component %s via AJAX', file); + load_show_win(file); // get an XHR instance @@ -252,7 +252,7 @@ function load_show_win(file) { - var img = ''; + var img = ''; if ( document.getElementById('_js_load_component') ) { document.getElementById('_js_load_component').innerHTML = img + msg_loading_component.replace('%component%', file); @@ -268,6 +268,7 @@ ld.innerHTML = img + msg_loading_component.replace('%component%', file); ld.id = '_js_load_component'; + // FYI: The base64 encoded image is a 70% opacity 1x1px white PNG. ld.style.backgroundImage = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAA1JREFUCNdj+P///xkACcgDypG+nnEAAAAASUVORK5CYII=)'; document.body.appendChild(ld); @@ -343,6 +344,37 @@ return true; } +var autofill_check = function() +{ + var inputs = document.getElementsByTagName('input'); + for ( var i = 0; i < inputs.length; i++ ) + { + if ( inputs[i].className ) + { + if ( inputs[i].className.match(/^autofill/) ) + { + load_component('autofill'); + return; + } + } + /* + else if ( typeof(inputs[i].onkeyup) == 'function' ) + { + var f = new String(inputs[i].onkeyup); + if ( f.match(/AutofillUsername/) ) + { + delete(f.onkeyup); + f.className = 'autofill username'; + autofill_check(); + return; + } + } + */ + } +} + +addOnloadHook(autofill_check); + var head = document.getElementsByTagName('head')[0]; // safari has window.console but not the .debug() method @@ -377,7 +409,7 @@ // alert('kill switch and problem script'); continue; } - script.src=scriptPath+"/includes/clientside/static/"+thefiles[f]; + script.src=cdnPath+"/includes/clientside/static/"+thefiles[f]; head.appendChild(script); } diff -r 74e03196fd43 -r e45183014778 includes/clientside/static/functions.js --- a/includes/clientside/static/functions.js Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/clientside/static/functions.js Sun Jul 20 13:32:04 2008 -0400 @@ -629,7 +629,7 @@ { if ( document.getElementById('ajaxloadicon') ) { - document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif'; + document.getElementById('ajaxloadicon').src=cdnPath + '/images/spacer.gif'; } } diff -r 74e03196fd43 -r e45183014778 includes/common.php --- a/includes/common.php Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/common.php Sun Jul 20 13:32:04 2008 -0400 @@ -263,6 +263,9 @@ grinding_halt('Version mismatch', 'It seems that the Enano release we\'re trying to run ('.$version.') is different from the version specified in your database ('.enano_version().'). Perhaps you need to upgrade?
'); } +// Set our CDN path +define('cdnPath', getConfig('cdn_path', scriptPath)); + // // Low level maintenance // diff -r 74e03196fd43 -r e45183014778 includes/common_cli.php --- a/includes/common_cli.php Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/common_cli.php Sun Jul 20 13:32:04 2008 -0400 @@ -75,6 +75,9 @@ grinding_halt('Version mismatch', 'Trying to run Enano version '.$version.' on database version '.enano_version().', you might need to upgrade.'); } +// Set our CDN path +define('cdnPath', getConfig('cdn_path', scriptPath)); + // // Low level maintenance // diff -r 74e03196fd43 -r e45183014778 includes/paths.php --- a/includes/paths.php Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/paths.php Sun Jul 20 13:32:04 2008 -0400 @@ -475,7 +475,7 @@ { $i++; $name = ( preg_match('/^[a-z0-9_]+$/', $key) ) ? $lang->get($c['name']) : $c['name']; - if ( $c['icon'] && $c['icon'] != scriptPath . '/images/spacer.gif' ) + if ( $c['icon'] && $c['icon'] != cdnPath . '/images/spacer.gif' ) { if ( is_array($c['icon']) ) { @@ -520,7 +520,7 @@ { $xpos = 16 * ( $ix - 1 ); $ypos = 16 * ( $iy - 1 ); - return " "; + return " "; } /** @@ -535,7 +535,7 @@ { if ( !$icon ) { - $icon = scriptPath . '/images/spacer.gif'; + $icon = cdnPath . '/images/spacer.gif'; } if(!isset($this->admin_tree[$section])) { diff -r 74e03196fd43 -r e45183014778 includes/template.php --- a/includes/template.php Sat Jul 19 21:14:54 2008 -0400 +++ b/includes/template.php Sun Jul 20 13:32:04 2008 -0400 @@ -56,8 +56,8 @@ $this->plugin_blocks = Array(); $this->theme_loaded = false; - $this->fading_button = '
+ get('acpgc_field_cdn_path'); ?>
+ get('acpgc_field_cdn_path_hint'); ?>
+
+ get('acpgc_field_cdn_path_example'); ?> +
+