includes/clientside/jsres.php
author Dan
Fri, 29 May 2009 16:38:14 -0400
changeset 1012 d966be8d79a3
parent 865 7f8262b2004a
child 1046 cfc6c30c5e2d
permissions -rw-r--r--
Stats: fixed missing $q in $db->fetchrow()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
801
eb8b23f11744 Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents: 800
diff changeset
     5
 * Version 1.1.6 (Caoineag beta 1)
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 507
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 * jsres.php - the Enano client-side runtime, a.k.a. AJAX on steroids
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
588
20484deb89cd Upgraded TinyMCE to 3.1.0.1. Ported a couple special pages to the componentized JS system.
Dan
parents: 587
diff changeset
    16
// define('ENANO_JS_DEBUG', 1);
20484deb89cd Upgraded TinyMCE to 3.1.0.1. Ported a couple special pages to the componentized JS system.
Dan
parents: 587
diff changeset
    17
650
e45183014778 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
Dan
parents: 613
diff changeset
    18
// if Enano's already loaded, we've been included from a helper script
e45183014778 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
Dan
parents: 613
diff changeset
    19
if ( defined('ENANO_CONFIG_FETCHED') )
e45183014778 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
Dan
parents: 613
diff changeset
    20
  define('ENANO_JSRES_SETUP_ONLY', 1);
e45183014778 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
Dan
parents: 613
diff changeset
    21
e45183014778 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
Dan
parents: 613
diff changeset
    22
if ( !defined('ENANO_JSRES_SETUP_ONLY') ):
e45183014778 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
Dan
parents: 613
diff changeset
    23
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    24
/**
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    25
 * 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
parents: 582
diff changeset
    26
 * 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
parents: 582
diff changeset
    27
 * @return float
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    28
 */
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    29
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    30
// 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
parents: 582
diff changeset
    31
if ( !function_exists('microtime_float') )
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    32
{
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    33
  function microtime_float()
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    34
  {
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    35
    list($usec, $sec) = explode(" ", microtime());
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    36
    return ((float)$usec + (float)$sec);
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    37
  }
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    38
}
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    39
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    40
$local_start = microtime_float();
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
    41
430
ec90736b9cb9 Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
parents: 421
diff changeset
    42
// Disable for IE, it causes problems.
588
20484deb89cd Upgraded TinyMCE to 3.1.0.1. Ported a couple special pages to the componentized JS system.
Dan
parents: 587
diff changeset
    43
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
parents: 421
diff changeset
    44
{
ec90736b9cb9 Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
parents: 421
diff changeset
    45
  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
parents: 421
diff changeset
    46
  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
parents: 421
diff changeset
    47
  exit();
ec90736b9cb9 Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
parents: 421
diff changeset
    48
}
ec90736b9cb9 Started (but disabled) work on the new theme manager, 1.1.2 is being released with this thing halfway done.
Dan
parents: 421
diff changeset
    49
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    50
// Setup Enano
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    51
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    52
//
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    53
// Determine the location of Enano as an absolute path.
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    54
//
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    55
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    56
// We need to see if this is a specially marked Enano development server. You can create an Enano
865
7f8262b2004a New template feature: template hooks (<!-- HOOK foo -->)
Dan
parents: 801
diff changeset
    57
// development server using the script found on hg.enanocms.org.
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    58
if ( strpos(__FILE__, '/repo/') && ( file_exists('../../.enanodev') || file_exists('../../../.enanodev') ) )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    59
{
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    60
  // We have a development directory. Remove /repo/ from the picture.
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    61
  $filename = str_replace('/repo/', '/', __FILE__);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    62
}
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    63
else
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    64
{
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    65
  // Standard Enano installation
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    66
  $filename = __FILE__;
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    67
}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    68
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    69
// ENANO_ROOT is sometimes defined by plugins like AjIM that need the constant before the Enano API is initialized
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    70
if ( !defined('ENANO_ROOT') )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    71
  define('ENANO_ROOT', dirname(dirname(dirname($filename))));
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    72
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    73
chdir(ENANO_ROOT);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    74
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 594
diff changeset
    75
// fetch only the site config
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 594
diff changeset
    76
define('ENANO_EXIT_AFTER_CONFIG', 1);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 594
diff changeset
    77
require('includes/common.php');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 594
diff changeset
    78
650
e45183014778 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
Dan
parents: 613
diff changeset
    79
endif; // ENANO_JSRES_SETUP_ONLY
e45183014778 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
Dan
parents: 613
diff changeset
    80
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    81
// CONFIG
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    82
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
    83
// Files safe to run full (aggressive) compression on
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    84
$full_compress_safe = array(
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    85
  // Sorted by file size, descending (du -b *.js | sort -n)
588
20484deb89cd Upgraded TinyMCE to 3.1.0.1. Ported a couple special pages to the componentized JS system.
Dan
parents: 587
diff changeset
    86
  'crypto.js',
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    87
  'ajax.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    88
  'editor.js',
582
a38876c0793c Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents: 581
diff changeset
    89
  'functions.js',
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
    90
  'login.js',
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    91
  'acl.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    92
  'misc.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    93
  'comments.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    94
  'autofill.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    95
  'dropdown.js',
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    96
  'paginate.js',
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
    97
  'enano-lib-basic.js',
437
b66f029ae12d Enabled strong compression on pwstrength.js as it causes problems otherwise in Opera
Dan
parents: 436
diff changeset
    98
  'pwstrength.js',
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
    99
  'flyin.js',
559
cfdc0aa8af50 [YSlow] Added Expires header on jsres.php
Dan
parents: 555
diff changeset
   100
  'rank-manager.js',
672
08a7875258b4 Added tab-based interface to userpage UI. Yes, it is plugin expansible, and yes, it breaks existing plugins that add code to the userpage (but that can be fixed with a "colspan=4")
Dan
parents: 650
diff changeset
   101
  'userpage.js',
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
   102
  'template-compiler.js',
436
242353360e37 Added support for Diffie-Hellman key exchange during login. w00t!
Dan
parents: 430
diff changeset
   103
  'toolbar.js',
421
dbae4d327846 Optimized JS aggressive-compression list a little more
Dan
parents: 420
diff changeset
   104
);
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   105
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   106
// Files that should NOT be compressed due to already being compressed, licensing, or invalid produced code
699
c7d737202d59 Removed Adobe Spry and replaced with jQuery. Please report any new bugs on the forums or via IRC. In a related note, auto-completion should work now at least for usernames. Still hacking away at page name completion...
Dan
parents: 685
diff changeset
   107
$compress_unsafe = array('json.js', 'fat.js', 'admin-menu.js', 'autofill.js', 'jquery.js', 'jquery-ui.js');
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   108
650
e45183014778 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
Dan
parents: 613
diff changeset
   109
require_once('includes/js-compressor.php');
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   110
542
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   111
// try to gzip the output
650
e45183014778 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
Dan
parents: 613
diff changeset
   112
if ( !defined('ENANO_JSRES_SETUP_ONLY') ):
542
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   113
$do_gzip = false;
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   114
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
parents: 536
diff changeset
   115
{
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   116
  $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
parents: 536
diff changeset
   117
  $acceptenc = explode(',', $acceptenc);
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   118
  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
parents: 536
diff changeset
   119
  {
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   120
    $do_gzip = true;
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   121
    ob_start();
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   122
  }
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   123
}
5841df0ab575 Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
parents: 536
diff changeset
   124
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   125
// Output format will always be JS
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   126
header('Content-type: text/javascript');
650
e45183014778 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
Dan
parents: 613
diff changeset
   127
e45183014778 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
Dan
parents: 613
diff changeset
   128
endif; // ENANO_JSRES_SETUP_ONLY
e45183014778 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
Dan
parents: 613
diff changeset
   129
587
705ed7162315 Oops, scriptPath isn't defined in jsres.php.
Dan
parents: 586
diff changeset
   130
$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
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   131
568
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   132
// if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   133
// 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
parents: 588
diff changeset
   134
738c61b498a6 A little more optimization work, client-side this time. I lied, no librijnadel2 here, but it's about to be merged in...
Dan
parents: 588
diff changeset
   135
// note - obfuscated for optimization purposes. The exact same code except properly indented is in enano-lib-basic.
568
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   136
if ( isset($_GET['early']) )
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   137
{
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
parents: 588
diff changeset
   138
  header('ETag: enanocms-lib-early-r2');
568
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   139
  header('Expires: Wed, 1 Jan 2020 00:00:00 GMT');
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   140
  
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   141
  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
parents: 588
diff changeset
   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;};};}
568
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   143
JSEOF;
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   144
  
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   145
  exit();
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   146
}
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 559
diff changeset
   147
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   148
// Load and parse enano_lib_basic
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   149
$file = @file_get_contents('includes/clientside/static/enano-lib-basic.js');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   150
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   151
$pos_start_includes = strpos($file, '/*!START_INCLUDER*/');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   152
$pos_end_includes = strpos($file, '/*!END_INCLUDER*/');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   153
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   154
if ( !$pos_start_includes || !$pos_end_includes )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   155
{
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   156
  die('// Error: enano-lib-basic does not have required metacomments');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   157
}
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   158
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   159
$pos_end_includes += strlen('/*!END_INCLUDER*/');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   160
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   161
preg_match('/var thefiles = (\[([^\]]+?)\]);/', $file, $match);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   162
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   163
if ( empty($match) )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   164
  die('// Error: could not retrieve file list from enano-lib-basic');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   165
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   166
// Decode file list
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   167
try
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   168
{
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   169
  $file_list = enano_json_decode($match[1]);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   170
}
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   171
catch ( Exception $e )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   172
{
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   173
  die("// Exception caught during file list parsing");
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   174
}
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   175
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   176
$apex = filemtime('includes/clientside/static/enano-lib-basic.js');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   177
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   178
$before_includes = substr($file, 0, $pos_start_includes);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   179
$after_includes = substr($file, $pos_end_includes);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   180
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   181
if ( isset($_GET['f']) )
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   182
{
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   183
  // requested a single file
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   184
  $js_file =& $_GET['f'];
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   185
  if ( strstr($js_file, ',') )
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   186
  {
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   187
    $filelist = explode(',', $js_file);
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   188
    unset($js_file);
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   189
    $everything = '';
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   190
    foreach ( $filelist as $js_file )
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   191
    {
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   192
      if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   193
      {
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   194
        header('HTTP/1.1 404 Not Found');
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   195
        exit('Not found');
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   196
      }
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   197
      
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   198
      $apex = filemtime("includes/clientside/static/$js_file");
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   199
      
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   200
      $file_contents = file_get_contents("includes/clientside/static/$js_file");
780
f65e35566b63 A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents: 779
diff changeset
   201
      $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   202
    }
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   203
  }
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   204
  else
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   205
  {
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   206
    if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   207
    {
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   208
      header('HTTP/1.1 404 Not Found');
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   209
      exit('Not found');
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   210
    }
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   211
    
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   212
    $apex = filemtime("includes/clientside/static/$js_file");
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   213
    
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   214
    $file_contents = file_get_contents("includes/clientside/static/$js_file");
780
f65e35566b63 A few fixes to the most recently added feature: more efficiency tweaks, tweaked l10n to have beetter fetch-on-demand support to ensure that stubs are never returned
Dan
parents: 779
diff changeset
   215
    $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   216
  }
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   217
}
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   218
else
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   219
{
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   220
  // compress enano-lib-basic
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   221
  $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
parents: 582
diff changeset
   222
  $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
parents: 582
diff changeset
   223
  $everything .= $libbasic;
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   224
  
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   225
  // $everything .= $before_includes;
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   226
  // $everything .= $after_includes;
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   227
  
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   228
  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
parents: 582
diff changeset
   229
  {
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   230
    $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
parents: 582
diff changeset
   231
    $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
parents: 582
diff changeset
   232
    if ( $time > $apex )
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   233
      $apex = $time;
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   234
    
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   235
    $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
parents: 582
diff changeset
   236
    
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   237
    $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
parents: 582
diff changeset
   238
    $everything .= "\n" . $file_contents;
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   239
  }
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   240
}
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   241
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   242
// generate ETag
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   243
$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
parents: 542
diff changeset
   244
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   245
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
parents: 542
diff changeset
   246
{
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   247
  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
parents: 542
diff changeset
   248
  {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   249
    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
parents: 542
diff changeset
   250
    exit();
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   251
  }
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   252
}
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   253
559
cfdc0aa8af50 [YSlow] Added Expires header on jsres.php
Dan
parents: 555
diff changeset
   254
// generate expires header
798
ddfc1b554a08 Redid error handler (it was causing some problems with gzip enabled)
Dan
parents: 780
diff changeset
   255
$expires = date('r', mktime(0, 0, 0, intval(date('m')), intval(date('d')), intval(date('y'))+1));
559
cfdc0aa8af50 [YSlow] Added Expires header on jsres.php
Dan
parents: 555
diff changeset
   256
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   257
$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
parents: 542
diff changeset
   258
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   259
$date = date('r', $apex);
650
e45183014778 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
Dan
parents: 613
diff changeset
   260
e45183014778 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
Dan
parents: 613
diff changeset
   261
if ( defined('ENANO_JSRES_SETUP_ONLY') )
e45183014778 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
Dan
parents: 613
diff changeset
   262
{
e45183014778 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
Dan
parents: 613
diff changeset
   263
  return; // we're done setting up, break out
e45183014778 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
Dan
parents: 613
diff changeset
   264
}
e45183014778 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
Dan
parents: 613
diff changeset
   265
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   266
header("Date: $date");
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   267
header("Last-Modified: $date");
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   268
header("ETag: \"$etag\"");
559
cfdc0aa8af50 [YSlow] Added Expires header on jsres.php
Dan
parents: 555
diff changeset
   269
header("Expires: $expires");
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents: 798
diff changeset
   270
if ( !$do_gzip )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents: 798
diff changeset
   271
  header("Content-Length: " . strlen($everything));
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   272
586
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   273
$local_end = microtime_float();
234ddd896555 Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
Dan
parents: 582
diff changeset
   274
$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
parents: 582
diff changeset
   275
$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
parents: 582
diff changeset
   276
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
parents: 582
diff changeset
   277
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   278
echo $everything;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   279
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   280
if ( $do_gzip )
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   281
{
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   282
  gzip_output();
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   283
}
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   284
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   285
/**
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   286
 * 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
parents: 542
diff changeset
   287
 * @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
parents: 542
diff changeset
   288
 * @param string Default/current contents
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   289
 * @return string
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   290
 */
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   291
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   292
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
parents: 542
diff changeset
   293
{
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   294
  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
parents: 542
diff changeset
   295
  
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   296
  $file_md5 = md5($file_contents);
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   297
  
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   298
  // Is this file cached?
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   299
  $cache_path = ENANO_ROOT . "/cache/jsres_$js_file.json";
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   300
  $loaded_cache = false;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   301
  
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   302
  if ( file_exists($cache_path) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   303
  {
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   304
    // Load the cache file and parse it.
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   305
    $cache_file = file_get_contents($cache_path);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   306
    try
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   307
    {
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   308
      $cache_file = enano_json_decode($cache_file);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   309
    }
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   310
    catch ( Exception $e )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   311
    {
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   312
      // Don't do anything - let our fallbacks come into place
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   313
    }
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   314
    if ( is_array($cache_file) && isset($cache_file['md5']) && isset($cache_file['src']) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   315
    {
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   316
      if ( $cache_file['md5'] === $file_md5 )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   317
      {
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   318
        @header("X-Cache-Status: cache HIT, hash $file_md5");
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   319
        $loaded_cache = true;
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   320
        $file_contents = $cache_file['src'];
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   321
      }
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   322
    }
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   323
  }
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 594
diff changeset
   324
  if ( !$loaded_cache && getConfig('cache_thumbs') == '1' )
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   325
  {
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   326
    // Try to open the cache file and write to it. If we can't do that, just don't compress the code.
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   327
    $handle = @fopen($cache_path, 'w');
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   328
    if ( $handle )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   329
    {
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   330
      $aggressive = in_array($js_file, $full_compress_safe);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   331
      if ( !in_array($js_file, $compress_unsafe) )
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   332
        $file_contents = perform_js_compress($file_contents, $aggressive);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   333
      
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   334
      $payload = enano_json_encode(array(
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   335
          'md5' => $file_md5,
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   336
          'src' => $file_contents
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   337
        ));
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   338
      fwrite($handle, $payload);
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   339
      fclose($handle);
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   340
      @header("X-Cache-Status: cache MISS, new generated");
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   341
    }
746
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   342
    else
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   343
    {
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   344
      @header("X-Cache-Status: cache MISS, not generated");
746
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   345
    }
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   346
  }
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   347
  else if ( !$loaded_cache )
f81f2a4f8d04 Add some performance info to jsres
Dan
parents: 699
diff changeset
   348
  {
779
609e35845ec3 load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
Dan
parents: 746
diff changeset
   349
    @header("X-Cache-Status: cache MISS, not generated");
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   350
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   351
  
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 542
diff changeset
   352
  return $file_contents;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   353
}
420
301f546688d1 Re-enabled, debugged, and optimized Javascript compression code
Dan
parents: 411
diff changeset
   354