| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Compression API 19 * 20 * @package CoreAPI 21 * @subpackage CompressionAPI 22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 24 * @link http://www.mantisbt.org 25 * 26 * @uses constant_inc.php 27 * @uses php_api.php 28 * @uses utility_api.php 29 */ 30 31 require_api( 'constant_inc.php' ); 32 require_api( 'php_api.php' ); 33 require_api( 'utility_api.php' ); 34 35 /** 36 * Starts the buffering/compression (only if the compression option is ON) 37 * This variable is used internally. It is not used for configuration 38 * @global bool $g_compression_started 39 */ 40 $g_compression_started = false; 41 42 /** 43 * Check if compression handler (ob_gzhandler) should be enabled. Note: this should not be used 44 * as an indicator of whether output received by a client will be compressed, only whether an 45 * output handler is used to compress output. 46 * @return bool 47 * @access public 48 */ 49 function compress_handler_is_enabled() { 50 global $g_compress_html; 51 52 // indicates compression should be disabled for a page. Note: php.ini may still enable zlib.output_compression. 53 // it may be possible to turn this off through the use of ini_set within that specific page. 54 if( defined( 'COMPRESSION_DISABLED' ) ) { 55 return false; 56 } 57 58 // Dont use config_get here so only dependency is on consant.inc.php in this module 59 // We only actively compress html if global configuration compress_html is set. 60 if( ON == $g_compress_html ) { 61 // both compression handlers require zlib module to be loaded 62 if( !extension_loaded( 'zlib' ) ) { 63 return false; 64 } 65 66 if ( ini_get( 'zlib.output_compression' ) ) { 67 /* zlib output compression is already enabled - we can't load the gzip output handler */ 68 return false; 69 } 70 71 // Since php 5.2.10, it's possible to set zlib.output_compression via ini_set. 72 // This method is preferred over ob_gzhandler 73 if( php_version_at_least( '5.2.10' ) && ini_get( 'output_handler' ) == '' && function_exists( 'ini_set' ) ) { 74 ini_set( 'zlib.output_compression', true ); 75 // do it transparently 76 return false; 77 } 78 79 // if php.ini does not already use ob_gzhandler by default, return true. 80 return ( 'ob_gzhandler' != ini_get( 'output_handler' ) ); 81 } 82 } 83 84 /** 85 * Start compression handler if required 86 * @return null 87 * @access public 88 */ 89 function compress_start_handler() { 90 if( compress_handler_is_enabled() ) { 91 # Before doing anything else, start output buffering so we don't prevent 92 # headers from being sent if there's a blank line in an included file 93 ob_start( 'compress_handler' ); 94 } else if ( ini_get_bool( 'zlib.output_compression' ) == true ) { 95 if( defined( 'COMPRESSION_DISABLED' ) ) { 96 return; 97 } 98 ob_start(); 99 } 100 } 101 102 /** 103 * Output Buffering handler that either compresses the buffer or just. 104 * returns it, depending on the return value of compress_handler_is_enabled() 105 * @param string $p_buffer 106 * @param int $p_mode 107 * @return string 108 * @access public 109 */ 110 function compress_handler( & $p_buffer, $p_mode ) { 111 global $g_compression_started; 112 if( $g_compression_started && compress_handler_is_enabled() ) { 113 return ob_gzhandler( $p_buffer, $p_mode ); 114 } else { 115 return $p_buffer; 116 } 117 } 118 119 /** 120 * Enable output buffering with compression. 121 * @return null 122 * @access public 123 */ 124 function compress_enable() { 125 global $g_compression_started; 126 127 $g_compression_started = true; 128 } 129 130 /** 131 * Disable output buffering with compression. 132 * @return null 133 * @access public 134 */ 135 function compress_disable() { 136 global $g_compression_started; 137 138 $g_compression_started = false; 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |