Translated using Weblate (Kurdish Sorani)
[phpmyadmin.git] / libraries / OutputBuffering.class.php
blob50a3d1d842db499d798478a27137b499ffe61bca
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 * @return void
28 private function __construct()
30 $this->_mode = $this->_getMode();
31 $this->_on = false;
34 /**
35 * This function could be used eventually to support more modes.
37 * @return integer the output buffer mode
39 private function _getMode()
41 $mode = 0;
42 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
43 if (ini_get('output_handler') == 'ob_gzhandler') {
44 // If a user sets the output_handler in php.ini to ob_gzhandler, then
45 // any right frame file in phpMyAdmin will not be handled properly by
46 // the browser. My fix was to check the ini file within the
47 // PMA_outBufferModeGet() function.
48 $mode = 0;
49 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
50 // If output buffering is enabled in php.ini it's not possible to
51 // add the ob_gzhandler without a warning message from php 4.3.0.
52 // Being better safe than sorry, check for any existing output
53 // handler instead of just checking the 'output_buffering' setting.
54 $mode = 0;
55 } else {
56 $mode = 1;
59 // Zero (0) is no mode or in other words output buffering is OFF.
60 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
61 // Usefull if we ever decide to combine modes. Then a bitmask field of
62 // the sum of all modes will be the natural choice.
63 return $mode;
66 /**
67 * Returns the singleton PMA_OutputBuffering object
69 * @return PMA_OutputBuffering object
71 public static function getInstance()
73 if (empty(self::$_instance)) {
74 self::$_instance = new PMA_OutputBuffering();
76 return self::$_instance;
79 /**
80 * This function will need to run at the top of all pages if output
81 * output buffering is turned on. It also needs to be passed $mode from
82 * the PMA_outBufferModeGet() function or it will be useless.
84 * @return void
86 public function start()
88 if (! $this->_on) {
89 if ($this->_mode) {
90 ob_start('ob_gzhandler');
92 ob_start();
93 if (! defined('TESTSUITE')) {
94 header('X-ob_mode: ' . $this->_mode);
96 register_shutdown_function('PMA_OutputBuffering::stop');
97 $this->_on = true;
102 * This function will need to run at the bottom of all pages if output
103 * buffering is turned on. It also needs to be passed $mode from the
104 * PMA_outBufferModeGet() function or it will be useless.
106 * @return void
108 public static function stop()
110 $buffer = PMA_OutputBuffering::getInstance();
111 if ($buffer->_on) {
112 $buffer->_on = false;
113 $buffer->_content = ob_get_contents();
114 ob_end_clean();
116 PMA_Response::response();
120 * Gets buffer content
122 * @return buffer content
124 public function getContents()
126 return $this->_content;
130 * Flushes output buffer
132 * @return void
134 public function flush()
136 if (ob_get_status() && $this->_mode) {
137 ob_flush();
138 } else {
139 flush();