Translated using Weblate (Indonesian)
[phpmyadmin.git] / libraries / OutputBuffering.class.php
blob1ef764313d6a2e8b908c487f20d672aa2f5ef79a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Output buffering wrapper
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Output buffering wrapper class
15 * @package PhpMyAdmin
17 class PMA_OutputBuffering
19 private static $_instance;
20 private $_mode;
21 private $_content;
22 private $_on;
24 /**
25 * Initializes class
27 * @return void
29 private function __construct()
31 $this->_mode = $this->_getMode();
32 $this->_on = false;
35 /**
36 * This function could be used eventually to support more modes.
38 * @return integer the output buffer mode
40 private function _getMode()
42 $mode = 0;
43 if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
44 if (ini_get('output_handler') == 'ob_gzhandler') {
45 // If a user sets the output_handler in php.ini to ob_gzhandler, then
46 // any right frame file in phpMyAdmin will not be handled properly by
47 // the browser. My fix was to check the ini file within the
48 // PMA_outBufferModeGet() function.
49 $mode = 0;
50 } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
51 // If output buffering is enabled in php.ini it's not possible to
52 // add the ob_gzhandler without a warning message from php 4.3.0.
53 // Being better safe than sorry, check for any existing output handler
54 // instead of just checking the 'output_buffering' setting.
55 $mode = 0;
56 } else {
57 $mode = 1;
60 // Zero (0) is no mode or in other words output buffering is OFF.
61 // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
62 // Usefull if we ever decide to combine modes. Then a bitmask field of
63 // the sum of all modes will be the natural choice.
64 return $mode;
67 /**
68 * Returns the singleton PMA_OutputBuffering object
70 * @return PMA_OutputBuffering object
72 public static function getInstance()
74 if (empty(self::$_instance)) {
75 self::$_instance = new PMA_OutputBuffering();
77 return self::$_instance;
80 /**
81 * This function will need to run at the top of all pages if output
82 * output buffering is turned on. It also needs to be passed $mode from
83 * the PMA_outBufferModeGet() function or it will be useless.
85 * @return void
87 public function start()
89 if (! $this->_on) {
90 if ($this->_mode) {
91 ob_start('ob_gzhandler');
93 ob_start();
94 if (! defined('TESTSUITE')) {
95 header('X-ob_mode: ' . $this->_mode);
97 register_shutdown_function('PMA_OutputBuffering::stop');
98 $this->_on = true;
103 * This function will need to run at the bottom of all pages if output
104 * buffering is turned on. It also needs to be passed $mode from the
105 * PMA_outBufferModeGet() function or it will be useless.
107 * @return void
109 public static function stop()
111 $buffer = PMA_OutputBuffering::getInstance();
112 if ($buffer->_on) {
113 $buffer->_on = false;
114 $buffer->_content = ob_get_contents();
115 ob_end_clean();
117 PMA_Response::response();
121 * Gets buffer content
123 * @return buffer content
125 public function getContents()
127 return $this->_content;
131 * Flushes output buffer
133 * @return void
135 public function flush()
137 if (ob_get_status() && $this->_mode) {
138 ob_flush();
141 * previously we had here an "else flush()" but some PHP versions
142 * (at least PHP 5.2.11) have a bug (49816) that produces garbled
143 * data