includes/clientside/jsres.php
changeset 1046 cfc6c30c5e2d
parent 865 7f8262b2004a
child 1053 bdbb49cf6f1b
equal deleted inserted replaced
1045:ce069a06906c 1046:cfc6c30c5e2d
    38 }
    38 }
    39 
    39 
    40 $local_start = microtime_float();
    40 $local_start = microtime_float();
    41 
    41 
    42 // Disable for IE, it causes problems.
    42 // Disable for IE, it causes problems.
    43 if ( ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') || defined('ENANO_JS_DEBUG') ) && !isset($_GET['early']) )
    43 $disable_compress = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') || defined('ENANO_JS_DEBUG') ) && !isset($_GET['early']);
    44 {
       
    45   header('HTTP/1.1 302 Redirect');
       
    46   header('Location: static/enano-lib-basic.js');
       
    47   exit();
       
    48 }
       
    49 
    44 
    50 // Setup Enano
    45 // Setup Enano
    51 
    46 
    52 //
    47 //
    53 // Determine the location of Enano as an absolute path.
    48 // Determine the location of Enano as an absolute path.
   133 // with a simple ETag and far future expires header
   128 // with a simple ETag and far future expires header
   134 
   129 
   135 // note - obfuscated for optimization purposes. The exact same code except properly indented is in enano-lib-basic.
   130 // note - obfuscated for optimization purposes. The exact same code except properly indented is in enano-lib-basic.
   136 if ( isset($_GET['early']) )
   131 if ( isset($_GET['early']) )
   137 {
   132 {
   138   header('ETag: enanocms-lib-early-r2');
   133   header('ETag: enanocms-lib-early-r3');
   139   header('Expires: Wed, 1 Jan 2020 00:00:00 GMT');
   134   header('Expires: Wed, 1 Jan 2020 00:00:00 GMT');
   140   
   135   
   141   echo <<<JSEOF
   136   echo <<<JSEOF
       
   137 window.loaded_components = window.loaded_components || {};
       
   138 window.onload_complete = false;
   142 var onload_hooks = new Array();function addOnloadHook(func){if ( typeof ( func ) == 'function' ){if ( typeof(onload_hooks.push) == 'function' ){onload_hooks.push(func);}else{onload_hooks[onload_hooks.length] = func;};};}
   139 var onload_hooks = new Array();function addOnloadHook(func){if ( typeof ( func ) == 'function' ){if ( typeof(onload_hooks.push) == 'function' ){onload_hooks.push(func);}else{onload_hooks[onload_hooks.length] = func;};};}
   143 JSEOF;
   140 JSEOF;
   144   
   141   
   145   exit();
   142   exit();
   146 }
   143 }
   196       }
   193       }
   197       
   194       
   198       $apex = filemtime("includes/clientside/static/$js_file");
   195       $apex = filemtime("includes/clientside/static/$js_file");
   199       
   196       
   200       $file_contents = file_get_contents("includes/clientside/static/$js_file");
   197       $file_contents = file_get_contents("includes/clientside/static/$js_file");
   201       $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
   198       $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
   202     }
   199     }
       
   200     $everything .= 'if ( onload_complete ) { console.debug("running hooks from jsres"); runOnloadHooks(); onload_hooks = []; };';
   203   }
   201   }
   204   else
   202   else
   205   {
   203   {
   206     if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
   204     if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
   207     {
   205     {
   210     }
   208     }
   211     
   209     
   212     $apex = filemtime("includes/clientside/static/$js_file");
   210     $apex = filemtime("includes/clientside/static/$js_file");
   213     
   211     
   214     $file_contents = file_get_contents("includes/clientside/static/$js_file");
   212     $file_contents = file_get_contents("includes/clientside/static/$js_file");
   215     $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
   213     $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { console.debug("running hooks from jsres"); runOnloadHooks(); onload_hooks = []; };';
   216   }
   214   }
   217 }
   215 }
   218 else
   216 else
   219 {
   217 {
   220   // compress enano-lib-basic
   218   // compress enano-lib-basic
   290  */
   288  */
   291 
   289 
   292 function jsres_cache_check($js_file, $file_contents)
   290 function jsres_cache_check($js_file, $file_contents)
   293 {
   291 {
   294   global $full_compress_safe, $compress_unsafe;
   292   global $full_compress_safe, $compress_unsafe;
       
   293   global $disable_compress;
       
   294   
       
   295   if ( $disable_compress )
       
   296     return $file_contents;
   295   
   297   
   296   $file_md5 = md5($file_contents);
   298   $file_md5 = md5($file_contents);
   297   
   299   
   298   // Is this file cached?
   300   // Is this file cached?
   299   $cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json";
   301   $cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json";