From c9970a29d26eabecbd88c5c47d5b7cc20d366da6 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Fri, 22 Sep 2006 11:58:39 +0000 Subject: [PATCH] refactored output buffer functions --- ChangeLog | 3 ++ libraries/ob.lib.php | 88 ++++++++++++++++++++++---------------------- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index f85caa145..daceab715 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ phpMyAdmin - ChangeLog $Id$ $Source$ +2006-09-22 Sebastian Mendel + * libraries/ob.lib.php: refactored + 2006-09-21 Sebastian Mendel * libraries/PMA_List.class.php: new PMA_List class * libraries/PMA_List_Database.class.php, left.php, libraries\common.lib.php: diff --git a/libraries/ob.lib.php b/libraries/ob.lib.php index 246b6a44c..a42620a4c 100644 --- a/libraries/ob.lib.php +++ b/libraries/ob.lib.php @@ -18,38 +18,41 @@ * because both header and footer functions must know what each other is * doing. * + * @uses $GLOBALS['cfg']['OBGzip'] + * @uses function_exists() + * @uses ini_get() + * @uses ob_get_level() + * @uses header() + * @staticvar integer remember last calculated value * @return integer the output buffer mode */ function PMA_outBufferModeGet() { - if (@function_exists('ob_start')) { - $mode = 1; - } else { - $mode = 0; + static $mode = null; + + if (null !== $mode) { + return $mode; } - // If a user sets the output_handler in php.ini to ob_gzhandler, then - // any right frame file in phpMyAdmin will not be handled properly by - // the browser. My fix was to check the ini file within the - // PMA_outBufferModeGet() function. - // - // (Patch by Garth Gillespie, modified by Marc Delisle) - if (@ini_get('output_handler') == 'ob_gzhandler') { - $mode = 0; - } - if (@get_cfg_var('output_handler') == 'ob_gzhandler') { - $mode = 0; - } - // End patch + $mode = 0; - // If output buffering is enabled in php.ini it's not possible to - // add the ob_gzhandler without a warning message from php 4.3.0. - // Being better safe than sorry, check for any existing output handler - // instead of just checking the 'output_buffering' setting. - // - if (@function_exists('ob_get_level')) { - if (ob_get_level() > 0) { + if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) { + if (ini_get('output_handler') == 'ob_gzhandler') { + // If a user sets the output_handler in php.ini to ob_gzhandler, then + // any right frame file in phpMyAdmin will not be handled properly by + // the browser. My fix was to check the ini file within the + // PMA_outBufferModeGet() function. + // + // (Patch by Garth Gillespie, modified by Marc Delisle) $mode = 0; + } elseif (function_exists('ob_get_level') && ob_get_level() > 0) { + // If output buffering is enabled in php.ini it's not possible to + // add the ob_gzhandler without a warning message from php 4.3.0. + // Being better safe than sorry, check for any existing output handler + // instead of just checking the 'output_buffering' setting. + $mode = 0; + } else { + $mode = 1; } } @@ -69,26 +72,23 @@ function PMA_outBufferModeGet() * output buffering is turned on. It also needs to be passed $mode from * the PMA_outBufferModeGet() function or it will be useless. * - * @param integer the output buffer mode - * + * @uses PMA_outBufferModeGet() + * @uses ob_start() + * @param integer $mode DEPRECATED * @return boolean whether output buffering is enabled or not */ -function PMA_outBufferPre($mode) +function PMA_outBufferPre($mode = null) { - switch($mode) + switch(PMA_outBufferModeGet()) { case 1: ob_start('ob_gzhandler'); - $retval = TRUE; + $retval = true; break; case 0: - $retval = FALSE; - break; - - // loic1: php3 fix default: - $retval = FALSE; + $retval = false; break; } // end switch @@ -101,26 +101,26 @@ function PMA_outBufferPre($mode) * buffering is turned on. It also needs to be passed $mode from the * PMA_outBufferModeGet() function or it will be useless. * - * @param integer the output buffer mode - * + * @uses PMA_outBufferModeGet() + * @uses ob_flush() + * @uses flush() + * @param integer $mode DEPRECATED * @return boolean whether data has been send from the buffer or not */ -function PMA_outBufferPost($mode) +function PMA_outBufferPost($mode = null) { - switch($mode) + switch(PMA_outBufferModeGet()) { case 1: # This output buffer doesn't need a footer. - $retval = TRUE; + ob_flush(); + $retval = true; break; case 0: - $retval = FALSE; - break; - - // loic1: php3 fix default: - $retval = FALSE; + flush(); + $retval = false; break; } // end switch