1
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
536
+ − 5
* Version 1.1.4 (Caoineag alpha 4)
+ − 6
* Copyright (C) 2006-2008 Dan Fuhry
1
+ − 7
* jsres.php - the Enano client-side runtime, a.k.a. AJAX on steroids
+ − 8
*
+ − 9
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 10
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 11
*
+ − 12
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 13
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 14
*/
+ − 15
588
+ − 16
// define('ENANO_JS_DEBUG', 1);
+ − 17
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 18
/**
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 19
* Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 20
* from very early on in the script to measure the starting time of Enano.
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 21
* @return float
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 22
*/
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 23
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 24
// First check to see if something already declared this function.... it happens often.
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 25
if ( !function_exists('microtime_float') )
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 26
{
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 27
function microtime_float()
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 28
{
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 29
list($usec, $sec) = explode(" ", microtime());
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 30
return ((float)$usec + (float)$sec);
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 31
}
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 32
}
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 33
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 34
$local_start = microtime_float();
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 35
430
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 36
// Disable for IE, it causes problems.
588
+ − 37
if ( ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') || defined('ENANO_JS_DEBUG') ) && !isset($_GET['early']) )
430
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 38
{
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 39
header('HTTP/1.1 302 Redirect');
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 40
header('Location: static/enano-lib-basic.js');
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 41
exit();
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 42
}
ec90736b9cb9
Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
diff
changeset
+ − 43
420
+ − 44
// Setup Enano
1
+ − 45
420
+ − 46
//
+ − 47
// Determine the location of Enano as an absolute path.
+ − 48
//
1
+ − 49
420
+ − 50
// We need to see if this is a specially marked Enano development server. You can create an Enano
+ − 51
// development server by cloning the Mercurial repository into a directory named repo, and then
+ − 52
// using symlinks to reference the original files so as to segregate unique files from non-unique
+ − 53
// and distribution-standard ones. Enano will pivot its root directory accordingly if the file
+ − 54
// .enanodev is found in the Enano root (not /repo/).
+ − 55
if ( strpos(__FILE__, '/repo/') && ( file_exists('../../.enanodev') || file_exists('../../../.enanodev') ) )
+ − 56
{
+ − 57
// We have a development directory. Remove /repo/ from the picture.
+ − 58
$filename = str_replace('/repo/', '/', __FILE__);
+ − 59
}
+ − 60
else
+ − 61
{
+ − 62
// Standard Enano installation
+ − 63
$filename = __FILE__;
+ − 64
}
1
+ − 65
420
+ − 66
// ENANO_ROOT is sometimes defined by plugins like AjIM that need the constant before the Enano API is initialized
+ − 67
if ( !defined('ENANO_ROOT') )
+ − 68
define('ENANO_ROOT', dirname(dirname(dirname($filename))));
+ − 69
+ − 70
chdir(ENANO_ROOT);
+ − 71
+ − 72
// CONFIG
1
+ − 73
420
+ − 74
// Files safe to run full (aggressive) compression on
421
+ − 75
$full_compress_safe = array(
+ − 76
// Sorted by file size, descending (du -b *.js | sort -n)
588
+ − 77
'crypto.js',
421
+ − 78
'ajax.js',
+ − 79
'editor.js',
582
+ − 80
'functions.js',
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 81
'login.js',
421
+ − 82
'acl.js',
+ − 83
'misc.js',
+ − 84
'comments.js',
+ − 85
'autofill.js',
+ − 86
'dropdown.js',
+ − 87
'paginate.js',
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 88
'enano-lib-basic.js',
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 89
'SpryJSONDataSet.js',
437
+ − 90
'pwstrength.js',
421
+ − 91
'flyin.js',
559
+ − 92
'rank-manager.js',
421
+ − 93
'template-compiler.js',
436
+ − 94
'toolbar.js',
421
+ − 95
);
420
+ − 96
+ − 97
// Files that should NOT be compressed due to already being compressed, licensing, or invalid produced code
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 98
$compress_unsafe = array('SpryEffects.js', 'json.js', 'fat.js', 'admin-menu.js', 'autofill.js');
420
+ − 99
+ − 100
require('includes/functions.php');
+ − 101
require('includes/json2.php');
+ − 102
require('includes/js-compressor.php');
+ − 103
542
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 104
// try to gzip the output
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 105
$do_gzip = false;
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 106
if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) )
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 107
{
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 108
$acceptenc = str_replace(' ', '', strtolower($_SERVER['HTTP_ACCEPT_ENCODING']));
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 109
$acceptenc = explode(',', $acceptenc);
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 110
if ( in_array('gzip', $acceptenc) )
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 111
{
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 112
$do_gzip = true;
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 113
ob_start();
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 114
}
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 115
}
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 116
420
+ − 117
// Output format will always be JS
+ − 118
header('Content-type: text/javascript');
587
+ − 119
$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";
1
+ − 120
568
+ − 121
// if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that
+ − 122
// with a simple ETag and far future expires header
594
738c61b498a6
A little more optimization work, client-side this time. I lied, no librijnadel2 here, but it's about to be merged in...
Dan
diff
changeset
+ − 123
738c61b498a6
A little more optimization work, client-side this time. I lied, no librijnadel2 here, but it's about to be merged in...
Dan
diff
changeset
+ − 124
// note - obfuscated for optimization purposes. The exact same code except properly indented is in enano-lib-basic.
568
+ − 125
if ( isset($_GET['early']) )
+ − 126
{
594
738c61b498a6
A little more optimization work, client-side this time. I lied, no librijnadel2 here, but it's about to be merged in...
Dan
diff
changeset
+ − 127
header('ETag: enanocms-lib-early-r2');
568
+ − 128
header('Expires: Wed, 1 Jan 2020 00:00:00 GMT');
+ − 129
+ − 130
echo <<<JSEOF
594
738c61b498a6
A little more optimization work, client-side this time. I lied, no librijnadel2 here, but it's about to be merged in...
Dan
diff
changeset
+ − 131
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;};};}
568
+ − 132
JSEOF;
+ − 133
+ − 134
exit();
+ − 135
}
+ − 136
420
+ − 137
// Load and parse enano_lib_basic
+ − 138
$file = @file_get_contents('includes/clientside/static/enano-lib-basic.js');
+ − 139
+ − 140
$pos_start_includes = strpos($file, '/*!START_INCLUDER*/');
+ − 141
$pos_end_includes = strpos($file, '/*!END_INCLUDER*/');
1
+ − 142
420
+ − 143
if ( !$pos_start_includes || !$pos_end_includes )
+ − 144
{
+ − 145
die('// Error: enano-lib-basic does not have required metacomments');
+ − 146
}
1
+ − 147
420
+ − 148
$pos_end_includes += strlen('/*!END_INCLUDER*/');
+ − 149
+ − 150
preg_match('/var thefiles = (\[([^\]]+?)\]);/', $file, $match);
+ − 151
+ − 152
if ( empty($match) )
+ − 153
die('// Error: could not retrieve file list from enano-lib-basic');
1
+ − 154
420
+ − 155
// Decode file list
+ − 156
try
+ − 157
{
+ − 158
$file_list = enano_json_decode($match[1]);
+ − 159
}
+ − 160
catch ( Exception $e )
1
+ − 161
{
420
+ − 162
die("// Exception caught during file list parsing");
+ − 163
}
+ − 164
+ − 165
$apex = filemtime('includes/clientside/static/enano-lib-basic.js');
+ − 166
+ − 167
$before_includes = substr($file, 0, $pos_start_includes);
+ − 168
$after_includes = substr($file, $pos_end_includes);
+ − 169
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 170
if ( isset($_GET['f']) )
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 171
{
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 172
// requested a single file
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 173
$js_file =& $_GET['f'];
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 174
if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 175
{
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 176
header('HTTP/1.1 404 Not Found');
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 177
exit('Not found');
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 178
}
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 179
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 180
$apex = filemtime("includes/clientside/static/$js_file");
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 181
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 182
$file_contents = file_get_contents("includes/clientside/static/$js_file");
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 183
$everything = jsres_cache_check($js_file, $file_contents);
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 184
}
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 185
else
420
+ − 186
{
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 187
// compress enano-lib-basic
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 188
$libbasic = "$before_includes\n$after_includes";
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 189
$libbasic = jsres_cache_check('enano-lib-basic.js', $libbasic);
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 190
$everything .= $libbasic;
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 191
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 192
// $everything .= $before_includes;
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 193
// $everything .= $after_includes;
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 194
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 195
foreach ( $file_list as $js_file )
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 196
{
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 197
$file_contents = file_get_contents("includes/clientside/static/$js_file");
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 198
$time = filemtime("includes/clientside/static/$js_file");
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 199
if ( $time > $apex )
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 200
$apex = $time;
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 201
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 202
$file_contents = jsres_cache_check($js_file, $file_contents);
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 203
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 204
$everything .= "\n\n// $js_file\n";
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 205
$everything .= "\n" . $file_contents;
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 206
}
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 207
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 208
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 209
// generate ETag
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 210
$etag = base64_encode(hexdecode(sha1($everything)));
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 211
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 212
if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) )
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 213
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 214
if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] )
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 215
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 216
header('HTTP/1.1 304 Not Modified');
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 217
exit();
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 218
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 219
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 220
559
+ − 221
// generate expires header
+ − 222
$expires = date('r', mktime(-1, -1, -1, -1, -1, intval(date('y'))+1));
+ − 223
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 224
$everything = str_replace('/* JavaScriptCompressor 0.8 [www.devpro.it], thanks to Dean Edwards for idea [dean.edwards.name] */' . "\r\n", '', $everything);
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 225
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 226
$date = date('r', $apex);
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 227
header("Date: $date");
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 228
header("Last-Modified: $date");
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 229
header("ETag: \"$etag\"");
559
+ − 230
header("Expires: $expires");
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 231
586
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 232
$local_end = microtime_float();
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 233
$local_gentime = $local_end - $local_start;
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 234
$local_gentime = round($local_gentime, 5);
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 235
header("X-Performance: generated in $local_gentime seconds");
234ddd896555
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
diff
changeset
+ − 236
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 237
echo $everything;
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 238
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 239
if ( $do_gzip )
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 240
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 241
gzip_output();
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 242
}
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 243
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 244
/**
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 245
* Check the cache for the given JS file and return the best-compressed version.
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 246
* @param string Javascript file (acl.js)
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 247
* @param string Default/current contents
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 248
* @return string
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 249
*/
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 250
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 251
function jsres_cache_check($js_file, $file_contents)
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 252
{
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 253
global $full_compress_safe, $compress_unsafe;
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 254
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 255
$file_md5 = md5($file_contents);
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 256
420
+ − 257
// Is this file cached?
+ − 258
$cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json";
+ − 259
$loaded_cache = false;
1
+ − 260
420
+ − 261
if ( file_exists($cache_path) )
1
+ − 262
{
420
+ − 263
// Load the cache file and parse it.
+ − 264
$cache_file = file_get_contents($cache_path);
+ − 265
try
+ − 266
{
+ − 267
$cache_file = enano_json_decode($cache_file);
+ − 268
}
+ − 269
catch ( Exception $e )
+ − 270
{
+ − 271
// Don't do anything - let our fallbacks come into place
+ − 272
}
+ − 273
if ( is_array($cache_file) && isset($cache_file['md5']) && isset($cache_file['src']) )
1
+ − 274
{
420
+ − 275
if ( $cache_file['md5'] === $file_md5 )
+ − 276
{
+ − 277
$loaded_cache = true;
+ − 278
$file_contents = $cache_file['src'];
+ − 279
}
+ − 280
}
+ − 281
}
+ − 282
if ( !$loaded_cache )
+ − 283
{
+ − 284
// Try to open the cache file and write to it. If we can't do that, just don't compress the code.
+ − 285
$handle = @fopen($cache_path, 'w');
+ − 286
if ( $handle )
+ − 287
{
+ − 288
$aggressive = in_array($js_file, $full_compress_safe);
+ − 289
if ( !in_array($js_file, $compress_unsafe) )
+ − 290
$file_contents = perform_js_compress($file_contents, $aggressive);
+ − 291
+ − 292
$payload = enano_json_encode(array(
+ − 293
'md5' => $file_md5,
+ − 294
'src' => $file_contents
+ − 295
));
+ − 296
fwrite($handle, $payload);
+ − 297
fclose($handle);
1
+ − 298
}
+ − 299
}
+ − 300
555
ac4c6a7f01d8
Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
diff
changeset
+ − 301
return $file_contents;
1
+ − 302
}
420
+ − 303