1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / OutputBuffering.class.php
blob1d1d38f024587202c4fb03ab5d1d56f7c5d0b96c
1 <?php /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3 * Output buffering wrapper
5 * @package PhpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
12 * Output buffering wrapper class
14 * @package PhpMyAdmin
16 class PMA_OutputBuffering
18 private static $_instance;
19 private $_mode;
20 private $_content;
21 private $_on;
23 /**
24 * Initializes class
26 private function __construct()
28 $this->_mode = $this->_getMode();
29 $this->_on = false;
32 /**
33 * This function could be used eventually to support more modes.
35 * @return integer the output buffer mode
37 private function _getMode()
39 $mode = 0;
40 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
41 if (ini_get('output_handler') == 'ob_gzhandler') {
42 // If a user sets the output_handler in php.ini to ob_gzhandler, then
43 // any right frame file in phpMyAdmin will not be handled properly by
44 // the browser. My fix was to check the ini file within the
45 // PMA_outBufferModeGet() function.
46 $mode = 0;
47 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
48 // happens when php.ini's output_buffering is not Off
49 ob_end_clean();
50 $mode = 1;
51 } else {
52 $mode = 1;
55 // Zero (0) is no mode or in other words output buffering is OFF.
56 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
57 // Useful if we ever decide to combine modes. Then a bitmask field of
58 // the sum of all modes will be the natural choice.
59 return $mode;
62 /**
63 * Returns the singleton PMA_OutputBuffering object
65 * @return PMA_OutputBuffering object
67 public static function getInstance()
69 if (empty(self::$_instance)) {
70 self::$_instance = new PMA_OutputBuffering();
72 return self::$_instance;
75 /**
76 * This function will need to run at the top of all pages if output
77 * output buffering is turned on. It also needs to be passed $mode from
78 * the PMA_outBufferModeGet() function or it will be useless.
80 * @return void
82 public function start()
84 if (! $this->_on) {
85 if ($this->_mode && function_exists('ob_gzhandler')) {
86 ob_start('ob_gzhandler');
88 ob_start();
89 if (! defined('TESTSUITE')) {
90 header('X-ob_mode: ' . $this->_mode);
92 register_shutdown_function('PMA_OutputBuffering::stop');
93 $this->_on = true;
97 /**
98 * This function will need to run at the bottom of all pages if output
99 * buffering is turned on. It also needs to be passed $mode from the
100 * PMA_outBufferModeGet() function or it will be useless.
102 * @return void
104 public static function stop()
106 $buffer = PMA_OutputBuffering::getInstance();
107 if ($buffer->_on) {
108 $buffer->_on = false;
109 $buffer->_content = ob_get_contents();
110 ob_end_clean();
115 * Gets buffer content
117 * @return string buffer content
119 public function getContents()
121 return $this->_content;
125 * Flushes output buffer
127 * @return void
129 public function flush()
131 if (ob_get_status() && $this->_mode) {
132 ob_flush();
133 } else {
134 flush();