includes/clientside/jsres.php
changeset 650 e45183014778
parent 613 c08670a77871
child 672 08a7875258b4
equal deleted inserted replaced
649:74e03196fd43 650:e45183014778
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    14  */
    14  */
    15 
    15 
    16 // define('ENANO_JS_DEBUG', 1);
    16 // define('ENANO_JS_DEBUG', 1);
    17 
    17 
       
    18 // if Enano's already loaded, we've been included from a helper script
       
    19 if ( defined('ENANO_CONFIG_FETCHED') )
       
    20   define('ENANO_JSRES_SETUP_ONLY', 1);
       
    21 
       
    22 if ( !defined('ENANO_JSRES_SETUP_ONLY') ):
       
    23 
    18 /**
    24 /**
    19  * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
    25  * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
    20  * from very early on in the script to measure the starting time of Enano.
    26  * from very early on in the script to measure the starting time of Enano.
    21  * @return float
    27  * @return float
    22  */
    28  */
    70 chdir(ENANO_ROOT);
    76 chdir(ENANO_ROOT);
    71 
    77 
    72 // fetch only the site config
    78 // fetch only the site config
    73 define('ENANO_EXIT_AFTER_CONFIG', 1);
    79 define('ENANO_EXIT_AFTER_CONFIG', 1);
    74 require('includes/common.php');
    80 require('includes/common.php');
       
    81 
       
    82 endif; // ENANO_JSRES_SETUP_ONLY
    75 
    83 
    76 // CONFIG
    84 // CONFIG
    77 
    85 
    78 // Files safe to run full (aggressive) compression on
    86 // Files safe to run full (aggressive) compression on
    79 $full_compress_safe = array(
    87 $full_compress_safe = array(
    99 );
   107 );
   100 
   108 
   101 // Files that should NOT be compressed due to already being compressed, licensing, or invalid produced code
   109 // Files that should NOT be compressed due to already being compressed, licensing, or invalid produced code
   102 $compress_unsafe = array('SpryEffects.js', 'json.js', 'fat.js', 'admin-menu.js', 'autofill.js');
   110 $compress_unsafe = array('SpryEffects.js', 'json.js', 'fat.js', 'admin-menu.js', 'autofill.js');
   103 
   111 
   104 require('includes/js-compressor.php');
   112 require_once('includes/js-compressor.php');
   105 
   113 
   106 // try to gzip the output
   114 // try to gzip the output
       
   115 if ( !defined('ENANO_JSRES_SETUP_ONLY') ):
   107 $do_gzip = false;
   116 $do_gzip = false;
   108 if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
   117 if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
   109 {
   118 {
   110   $acceptenc = str_replace(' ', '', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
   119   $acceptenc = str_replace(' ', '', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
   111   $acceptenc = explode(',', $acceptenc);
   120   $acceptenc = explode(',', $acceptenc);
   116   }
   125   }
   117 }
   126 }
   118 
   127 
   119 // Output format will always be JS
   128 // Output format will always be JS
   120 header('Content-type: text/javascript');
   129 header('Content-type: text/javascript');
       
   130 
       
   131 endif; // ENANO_JSRES_SETUP_ONLY
       
   132 
   121 $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";
   133 $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";
   122 
   134 
   123 // if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that
   135 // if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that
   124 // with a simple ETag and far future expires header
   136 // with a simple ETag and far future expires header
   125 
   137 
   224 $expires = date('r', mktime(-1, -1, -1, -1, -1, intval(date('y'))+1));
   236 $expires = date('r', mktime(-1, -1, -1, -1, -1, intval(date('y'))+1));
   225 
   237 
   226 $everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything);
   238 $everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything);
   227 
   239 
   228 $date = date('r', $apex);
   240 $date = date('r', $apex);
       
   241 
       
   242 if ( defined('ENANO_JSRES_SETUP_ONLY') )
       
   243 {
       
   244   return; // we're done setting up, break out
       
   245 }
       
   246 
   229 header("Date: $date");
   247 header("Date: $date");
   230 header("Last-Modified: $date");
   248 header("Last-Modified: $date");
   231 header("ETag: \"$etag\"");
   249 header("ETag: \"$etag\"");
   232 header("Expires: $expires");
   250 header("Expires: $expires");
   233 
   251