# HG changeset patch # User Dan # Date 1269827366 14400 # Node ID de56132c008d0441ddb2df95205c3eedc93ffe0b # Parent 4c6da61e613e923b29932c1a927bb5131d18f742 Introduced configurability for gzip compression. Fixes issue 18. diff -r 4c6da61e613e -r de56132c008d includes/clientside/jsres.php --- a/includes/clientside/jsres.php Sun Mar 28 21:40:37 2010 -0400 +++ b/includes/clientside/jsres.php Sun Mar 28 21:49:26 2010 -0400 @@ -105,7 +105,7 @@ // try to gzip the output if ( !defined('ENANO_JSRES_SETUP_ONLY') ): $do_gzip = false; -if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) +if ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) && getConfig('gzip_output', false) == 1 ) { $acceptenc = str_replace(' ', '', strtolower($_SERVER['HTTP_ACCEPT_ENCODING'])); $acceptenc = explode(',', $acceptenc); diff -r 4c6da61e613e -r de56132c008d includes/clientside/static/ajax.js --- a/includes/clientside/static/ajax.js Sun Mar 28 21:40:37 2010 -0400 +++ b/includes/clientside/static/ajax.js Sun Mar 28 21:49:26 2010 -0400 @@ -1724,6 +1724,7 @@ thediv.style.display = 'none'; thediv.style.zIndex = getHighestZ() + 2; thediv.id = 'mdgDynamic_rDnsInfoDiv_'+Math.floor(Math.random() * 1000000); + // FIXME: l10n thediv.innerHTML = 'Reverse DNS:
'+ajax.responseText+' Close'; var body = document.getElementsByTagName('body'); body = body[0]; @@ -1740,3 +1741,48 @@ }); } +window.ajaxGzipCheck = function() +{ + var resultdiv = document.getElementById('gzip_check_result'); + if ( !resultdiv ) + return false; + + resultdiv.innerHTML = 'Loading...'; + ajaxPost(makeUrlNS('Admin', 'GeneralConfig'), 'act=gzip_check', function(ajax) + { + if ( ajax.readyState == 4 && ajax.status == 200 ) + { + resultdiv.innerHTML = ''; + var response = String(ajax.responseText + ''); + if ( !check_json_response(response) ) + { + handle_invalid_json(response); + return false; + } + response = parseJSON(response); + if ( response.error ) + { + resultdiv.innerHTML = '
' + response.error + '
'; + } + else + { + // probably success. + resultdiv.innerHTML += response.server_does_it ? + '
' + $lang.get('acpgc_field_gzip_check_msg_server_does_it') + '
' : + '
' + $lang.get('acpgc_field_gzip_check_msg_server_good') + '
'; + resultdiv.innerHTML += response.php_supports_gzip ? + '
' + $lang.get('acpgc_field_gzip_check_msg_php_good') + '
' : + '
' + $lang.get('acpgc_field_gzip_check_msg_php_bad') + '
'; + + if ( response.php_supports_gzip && !response.server_does_it ) + { + resultdiv.innerHTML += '
' + $lang.get('acpgc_field_gzip_check_msg_success') + '
'; + } + else + { + resultdiv.innerHTML += '
' + $lang.get('acpgc_field_gzip_check_msg_failure') + '
'; + } + } + } + }); +} diff -r 4c6da61e613e -r de56132c008d includes/clientside/static/enano-lib-basic.js --- a/includes/clientside/static/enano-lib-basic.js Sun Mar 28 21:40:37 2010 -0400 +++ b/includes/clientside/static/enano-lib-basic.js Sun Mar 28 21:49:26 2010 -0400 @@ -576,6 +576,7 @@ ajaxCatToTag: 'ajax.js', ajaxCatEdit: 'ajax.js', ajaxReverseDNS: 'ajax.js', + ajaxGzipCheck: 'ajax.js', ajaxOpenACLManager: 'acl.js', ajaxOpenDirectACLRule: 'acl.js', ajaxAdminPage: 'login.js', diff -r 4c6da61e613e -r de56132c008d includes/functions.php --- a/includes/functions.php Sun Mar 28 21:40:37 2010 -0400 +++ b/includes/functions.php Sun Mar 28 21:49:26 2010 -0400 @@ -3215,7 +3215,7 @@ // Compress buffered output if required and send to browser // Sorry, doesn't work in IE. What else is new? // - if ( $do_gzip && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() && $gzip_supported ) + if ( $do_gzip && getConfig('gzip_output', false) == 1 && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() && $gzip_supported ) { $gzip_contents = ob_get_contents(); ob_end_clean(); diff -r 4c6da61e613e -r de56132c008d index.php --- a/index.php Sun Mar 28 21:40:37 2010 -0400 +++ b/index.php Sun Mar 28 21:49:26 2010 -0400 @@ -24,8 +24,7 @@ // Set up gzip encoding before any output is sent global $do_gzip; -// FIXME: make this configurable -$do_gzip = !defined('ENANO_DEBUG'); +$do_gzip = !defined('ENANO_DEBUG') && getConfig('gzip_output', false) == 1 && !isset($_GET['disable_builtin_gzip']); error_reporting(E_ALL); diff -r 4c6da61e613e -r de56132c008d language/english/admin.json --- a/language/english/admin.json Sun Mar 28 21:40:37 2010 -0400 +++ b/language/english/admin.json Sun Mar 28 21:49:26 2010 -0400 @@ -336,7 +336,7 @@ // Section: default theme heading_default_theme: 'Visual defaults', - field_defualt_theme: 'Default theme for guests and new users:', + field_default_theme: 'Default theme for guests and new users:', // Section: breadcrumbs field_breadcrumb_mode: 'Enable breadcrumbs:', @@ -345,11 +345,22 @@ field_breadcrumb_mode_never: 'Never', // Section: CDN - field_cdn_path: 'URL to CDN server:', field_cdn_path_hint: 'A CDN, or Content Delivery Network, allows downloading of shared Enano components from a server designed to serve out only images, CSS, and script files. Since a browser can open separate connections for the page and for images and scripts, the page loads faster. Leave this blank to just use Enano\'s local files (default).', field_cdn_path_example: 'Example: http://cdn.mycompany.com/enano/', + // Section: gzip + field_gzip: 'Enable gzip compression', + field_gzip_hint: 'Compress pages using before sending them to the user. At the cost of a small amount of CPU, this can save a lot of bandwidth. This only enables compression for HTML and some Javascript; to gzip compress CSS and images, please consult your webserver\'s documentation.', + field_gzip_lbl: 'Use gzip compression', + field_gzip_btn_check: 'Check server for support', + field_gzip_check_msg_server_does_it: 'Your server performs gzip compression on its own. There is no need to enable it in Enano, and if you do, you may cause Enano to stop working.', + field_gzip_check_msg_server_good: 'Your server is not automatically compressing PHP-generated pages, so Enano\'s compression facilities are needed.', + field_gzip_check_msg_php_bad: 'PHP does not have gzip support enabled.', + field_gzip_check_msg_php_good: 'Found gzip compression support in PHP.', + field_gzip_check_msg_success: 'Success - all server checks passed. You can enable gzip support.', + field_gzip_check_msg_failure: 'Server check failed. Unless you think Enano is wrong, don\'t enable gzip below.', + // Main section: users and communication heading_users: 'Users and communication', diff -r 4c6da61e613e -r de56132c008d plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Sun Mar 28 21:40:37 2010 -0400 +++ b/plugins/SpecialAdmin.php Sun Mar 28 21:49:26 2010 -0400 @@ -82,6 +82,41 @@ return; } + // FIXME: is this a bad place for this? I couldn't think of anything much better. Not helped by the fact that I hate misc scripts. + if ( isset($_POST['act']) && $_POST['act'] === 'gzip_check' ) + { + global $is_https; + header('Content-type: application/json'); + require(ENANO_ROOT . '/includes/http.php'); + try + { + if ( !isset($_SERVER['SERVER_ADDR']) ) + throw new Exception('No SERVER_ADDR support - can\'t test server environment'); + + $server_addr = $_SERVER['SERVER_ADDR']; + // cheap ipv6 test + if ( strstr($server_addr, ":") ) + $server_addr = "[$server_addr]"; + + $req = new Request_HTTP($server_addr, makeUrlNS('System', 'GzipTest', 'disable_builtin_gzip'), 'GET', intval($_SERVER['SERVER_PORT']), $is_https); + $req->add_header('Accept-Encoding', 'gzip,deflate'); + $headers = $req->get_response_headers_array(); + $send = array( + 'server_does_it' => ( isset($headers['Content-encoding']) && in_array($headers['Content-encoding'], array('gzip', 'deflate')) ), + 'php_supports_gzip' => function_exists('gzdeflate') + ); + } + catch ( Exception $e ) + { + $send = array( + 'mode' => 'error', + 'error' => "HTTP request exception:
$e
" + ); + } + echo enano_json_encode($send); + return; + } + if(isset($_POST['submit']) && !defined('ENANO_DEMO_MODE') ) { @@ -236,6 +271,7 @@ setConfig('avatar_directory', 'files/avatars'); setConfig('userpage_grant_acl', ( isset($_POST['userpage_grant_acl']) ? '1' : '0' )); + setConfig('gzip_output', ( isset($_POST['gzip_output']) ? '1' : '0' )); // Allow plugins to save their changes $code = $plugins->setHook('acp_general_save'); @@ -496,7 +532,7 @@ - get('acpgc_field_defualt_theme'); ?> + get('acpgc_field_default_theme'); ?> /> + get('acpgc_field_gzip_lbl'); ?> + + + + setHook('acp_general_basic');