Merge branch 'QA_3_3'
[phpmyadmin/dkf.git] / libraries / ob.lib.php
blob180c463fe8f08a4a74f5f792e59c77422c24b535
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Output buffer functions for phpMyAdmin
6 * Copyright 2001 Jeremy Brand <jeremy@nirvani.net>
7 * http://www.jeremybrand.com/Jeremy/Brand/Jeremy_Brand.html
9 * Check for all the needed functions for output buffering
10 * Make some wrappers for the top and bottoms of our files.
12 * @version $Id$
13 * @package phpMyAdmin
16 /**
17 * This function be used eventually to support more modes. It is needed
18 * because both header and footer functions must know what each other is
19 * doing.
21 * @uses $cfg['OBGzip']
22 * @uses function_exists()
23 * @uses ini_get()
24 * @uses ob_get_level()
25 * @staticvar integer remember last calculated value
26 * @return integer the output buffer mode
28 function PMA_outBufferModeGet()
30 static $mode = null;
32 if (null !== $mode) {
33 return $mode;
36 $mode = 0;
38 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
39 if (ini_get('output_handler') == 'ob_gzhandler') {
40 // If a user sets the output_handler in php.ini to ob_gzhandler, then
41 // any right frame file in phpMyAdmin will not be handled properly by
42 // the browser. My fix was to check the ini file within the
43 // PMA_outBufferModeGet() function.
45 // (Patch by Garth Gillespie, modified by Marc Delisle)
46 $mode = 0;
47 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
48 // If output buffering is enabled in php.ini it's not possible to
49 // add the ob_gzhandler without a warning message from php 4.3.0.
50 // Being better safe than sorry, check for any existing output handler
51 // instead of just checking the 'output_buffering' setting.
52 $mode = 0;
53 } else {
54 $mode = 1;
58 // Zero (0) is no mode or in other words output buffering is OFF.
59 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
60 // Usefull if we ever decide to combine modes. Then a bitmask field of
61 // the sum of all modes will be the natural choice.
63 return $mode;
64 } // end of the 'PMA_outBufferModeGet()' function
67 /**
68 * This function will need to run at the top of all pages if output
69 * output buffering is turned on. It also needs to be passed $mode from
70 * the PMA_outBufferModeGet() function or it will be useless.
72 * @uses PMA_outBufferModeGet()
73 * @uses PMA_outBufferPost() to register it as shutdown function
74 * @uses ob_start()
75 * @uses header() to send X-ob_mode:
76 * @uses register_shutdown_function() to register PMA_outBufferPost()
78 function PMA_outBufferPre()
80 if ($mode = PMA_outBufferModeGet()) {
81 ob_start('ob_gzhandler');
84 header('X-ob_mode: ' . $mode);
86 register_shutdown_function('PMA_outBufferPost');
87 } // end of the 'PMA_outBufferPre()' function
90 /**
91 * This function will need to run at the bottom of all pages if output
92 * buffering is turned on. It also needs to be passed $mode from the
93 * PMA_outBufferModeGet() function or it will be useless.
95 * @uses PMA_outBufferModeGet()
96 * @uses ob_flush()
97 * @uses flush()
99 function PMA_outBufferPost()
101 if (ob_get_status() && PMA_outBufferModeGet()) {
102 ob_flush();
105 * previously we had here an "else flush()" but some PHP versions
106 * (at least PHP 5.2.11) have a bug (49816) that produces garbled
107 * data
109 } // end of the 'PMA_outBufferPost()' function