Permalink
Browse files

Added PMA_OutputBuffering class, dropped ob.lib.php

  • Loading branch information...
1 parent a054562 commit 41cb6e20b0285271e91d422dfd334220e2c89e86 @roccivic roccivic committed Jun 1, 2012
View
1 chk_rel.php
@@ -11,6 +11,5 @@
$response->addHTML(
PMA_getRelationsParamDiagnostic(PMA_getRelationsParam())
);
-$response->response();
?>
View
26 libraries/Footer.class.php
@@ -35,6 +35,16 @@ class PMA_Footer
private $_scripts;
/**
+ * Whether we are servicing an ajax request.
+ * We can't simply use $GLOBALS['is_ajax_request']
+ * here since it may have not been initialised yet.
+ *
+ * @access private
+ * @var bool
+ */
+ private $_isAjax;
+
+ /**
* Cretes a new class instance
*
* @return new PMA_Footer object
@@ -227,6 +237,16 @@ private function _setHistory()
}
/**
+ *
+ *
+ * @return
+ */
+ public function isAjax($isAjax)
+ {
+ $this->_isAjax = $isAjax;
+ }
+
+ /**
* Returns the PMA_Footnotes object
*
* @return PMA_Footnotes object
@@ -246,15 +266,15 @@ public function getDisplay()
$retval = '';
$this->_setHistory();
- if ($GLOBALS['is_ajax_request'] != true) {
+ if (! $this->_isAjax) {
// Link to itself to replicate windows including frameset
if (! isset($GLOBALS['checked_special'])) {
$GLOBALS['checked_special'] = false;
}
if (PMA_getenv('SCRIPT_NAME')
&& empty($_POST)
&& ! $GLOBALS['checked_special']
- && ! $GLOBALS['is_ajax_request']
+ && ! $this->_isAjax
) {
$url_params['target'] = basename(PMA_getenv('SCRIPT_NAME'));
$url = PMA_generate_common_url($url_params, 'text', '');
@@ -268,7 +288,7 @@ public function getDisplay()
$retval .= $this->_getDebugMessage();
$retval .= $this->_footnotes->getDisplay();
$retval .= $this->_getErrorMessages();
- if (! $GLOBALS['is_ajax_request']) {
+ if (! $this->_isAjax) {
$retval .= $this->_scripts->getDisplay();
// Include possible custom footers
if (file_exists(CUSTOM_FOOTER_FILE)) {
View
20 libraries/Header.class.php
@@ -8,7 +8,6 @@
exit;
}
-require_once 'libraries/ob.lib.php';
require_once 'libraries/Scripts.class.php';
require_once 'libraries/RecentTable.class.php';
require_once 'libraries/Menu.class.php';
@@ -102,9 +101,6 @@ class PMA_Header
public function __construct()
{
$this->_isAjax = false;
- if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
- $this->_isAjax = true;
- }
$this->_bodyId = '';
$this->_title = 'phpMyAdmin';
$this->_menu = new PMA_Menu(
@@ -200,6 +196,16 @@ private function _addDefaultScripts()
}
/**
+ *
+ *
+ * @return
+ */
+ public function isAjax($isAjax)
+ {
+ $this->_isAjax = $isAjax;
+ }
+
+ /**
* Returns the PMA_Scripts object
*
* @return PMA_Scripts object
@@ -275,7 +281,7 @@ public function getDisplay()
$retval = '';
if (! self::$headerIsSent) {
$this->sendHttpHeaders();
- if ($this->_isAjax === false) {
+ if (! $this->_isAjax) {
$retval .= $this->_getHtmlStart();
$retval .= $this->_getMetaTags();
$retval .= $this->_getLinkTags();
@@ -322,10 +328,6 @@ public function getDisplay()
public function sendHttpHeaders()
{
/**
- * Starts output buffering work
- */
- PMA_outBufferPre();
- /**
* Sends http headers
*/
$GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT';
View
4 libraries/Menu.class.php
@@ -206,10 +206,6 @@ private function _getBreadcrumbs()
} // end if
} else {
// no table selected, display database comment if present
- /**
- * Settings for relations stuff
- */
- include_once './libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam();
// Get additional information about tables for tooltip is done
View
129 libraries/OutputBuffering.class.php
@@ -0,0 +1,129 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ *
+ *
+ * @package PhpMyAdmin
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ *
+ *
+ * @package PhpMyAdmin
+ */
+class PMA_OutputBuffering
+{
+ private static $_instance;
+ private $_mode;
+ private $_content;
+ private $_on;
+
+ private function __construct()
+ {
+ $this->_mode = $this->_getMode();
+ $this->_on = false;
+ }
+
+ /**
+ * This function could be used eventually to support more modes.
+ *
+ * @return integer the output buffer mode
+ */
+ private function _getMode()
+ {
+ $mode = 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.
+ $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;
+ }
+ }
+ // Zero (0) is no mode or in other words output buffering is OFF.
+ // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
+ // Usefull if we ever decide to combine modes. Then a bitmask field of
+ // the sum of all modes will be the natural choice.
+ return $mode;
+ }
+
+ /**
+ * Returns the singleton PMA_Response object
+ *
+ * @return PMA_Response object
+ */
+ public static function getInstance()
+ {
+ if (empty(self::$_instance)) {
+ self::$_instance = new PMA_OutputBuffering();
+ }
+ return self::$_instance;
+ }
+
+ /**
+ * This function will need to run at the top of all pages if output
+ * output buffering is turned on. It also needs to be passed $mode from
+ * the PMA_outBufferModeGet() function or it will be useless.
+ *
+ */
+ public function start()
+ {
+ if (! $this->_on) {
+ if ($this->_mode) {
+ ob_start('ob_gzhandler');
+ }
+ ob_start();
+ header('X-ob_mode: ' . $this->_mode);
+ register_shutdown_function('PMA_OutputBuffering::stop');
+ $this->_on = true;
+ }
+ }
+
+ /**
+ * This function will need to run at the bottom of all pages if output
+ * buffering is turned on. It also needs to be passed $mode from the
+ * PMA_outBufferModeGet() function or it will be useless.
+ *
+ */
+ public static function stop()
+ {
+ $buffer = PMA_OutputBuffering::getInstance();
+ if ($buffer->_on) {
+ $buffer->_on = false;
+ $buffer->_content = ob_get_contents();
+ ob_end_clean();
+ }
+ PMA_Response::response();
+ }
+
+ public function getContents()
+ {
+ return $this->_content;
+ }
+
+ public function flush()
+ {
+ if (ob_get_status() && $this->_mode) {
+ ob_flush();
+ }
+ /**
+ * previously we had here an "else flush()" but some PHP versions
+ * (at least PHP 5.2.11) have a bug (49816) that produces garbled
+ * data
+ */
+ }
+}
+
+?>
View
47 libraries/Response.class.php
@@ -9,6 +9,7 @@
exit;
}
+require_once 'libraries/OutputBuffering.class.php';
require_once 'libraries/Header.class.php';
require_once 'libraries/Footer.class.php';
@@ -33,16 +34,34 @@ class PMA_Response
private $_footer;
/**
+ * Whether we are servicing an ajax request.
+ * We can't simply use $GLOBALS['is_ajax_request']
+ * here since it may have not been initialised yet.
+ *
+ * @access private
+ * @var bool
+ */
+ private $_isAjax;
+
+ /**
* Cretes a new class instance
*
* @return new PMA_Response object
*/
private function __construct()
{
+ $this->_isAjax = false;
+ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
+ $this->_isAjax = true;
+ }
+ $buffer = PMA_OutputBuffering::getInstance();
+ $buffer->start();
$this->_data = array();
$this->_header = new PMA_Header();
+ $this->_header->isAjax($this->_isAjax);
$this->_content = '';
$this->_footer = new PMA_Footer();
+ $this->_footer->isAjax($this->_isAjax);
}
/**
@@ -83,14 +102,32 @@ private function getDisplay()
return $retval;
}
- public function response()
+ public function simpleResponse()
+ {
+ echo $this->getDisplay();
+ exit;
+ }
+
+ public function ajaxResponse()
+ {
+ echo $this->getDisplay();
+ //PMA_ajaxResponse($this->getDisplay()); // FIXME
+ exit;
+ }
+
+ public static function response()
{
- if (! $GLOBALS['is_ajax_request']) {
- echo $this->getDisplay();
+ $response = self::$_instance;
+ $buffer = PMA_OutputBuffering::getInstance();
+ if (empty($response->_content)) {
+ $response->_content = $buffer->getContents();
+ }
+ if ($response->_isAjax) {
+ $response->ajaxResponse();
} else {
- // FIXME
+ $response->simpleResponse();
}
- exit;
+ $buffer->flush();
}
}
View
4 libraries/footer.inc.php
@@ -19,8 +19,8 @@
exit;
}
-$footer = PMA_Response::getInstance()->getFooter();
-$footer->display();
+//$footer = PMA_Response::getInstance()->getFooter();
+//$footer->display();
exit;
View
99 libraries/ob.lib.php
@@ -1,99 +0,0 @@
-<?php
-/* vim: set expandtab sw=4 ts=4 sts=4: */
-/**
- * Output buffer functions for phpMyAdmin
- *
- * Copyright 2001 Jeremy Brand <jeremy@nirvani.net>
- * http://www.jeremybrand.com/Jeremy/Brand/Jeremy_Brand.html
- *
- * Check for all the needed functions for output buffering
- * Make some wrappers for the top and bottoms of our files.
- *
- * @package PhpMyAdmin
- */
-if (! defined('PHPMYADMIN')) {
- exit;
-}
-
-/**
- * This function be used eventually to support more modes. It is needed
- * because both header and footer functions must know what each other is
- * doing.
- *
- * @staticvar integer remember last calculated value
- * @return integer the output buffer mode
- */
-function PMA_outBufferModeGet()
-{
- static $mode = null;
-
- if (null !== $mode) {
- return $mode;
- }
-
- $mode = 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.
- $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;
- }
- }
-
- // Zero (0) is no mode or in other words output buffering is OFF.
- // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
- // Usefull if we ever decide to combine modes. Then a bitmask field of
- // the sum of all modes will be the natural choice.
-
- return $mode;
-} // end of the 'PMA_outBufferModeGet()' function
-
-
-/**
- * This function will need to run at the top of all pages if output
- * output buffering is turned on. It also needs to be passed $mode from
- * the PMA_outBufferModeGet() function or it will be useless.
- *
- */
-function PMA_outBufferPre()
-{
- if ($mode = PMA_outBufferModeGet()) {
- ob_start('ob_gzhandler');
- }
-
- header('X-ob_mode: ' . $mode);
-
- register_shutdown_function('PMA_outBufferPost');
-} // end of the 'PMA_outBufferPre()' function
-
-
-/**
- * This function will need to run at the bottom of all pages if output
- * buffering is turned on. It also needs to be passed $mode from the
- * PMA_outBufferModeGet() function or it will be useless.
- *
- */
-function PMA_outBufferPost()
-{
- if (ob_get_status() && PMA_outBufferModeGet()) {
- ob_flush();
- }
- /**
- * previously we had here an "else flush()" but some PHP versions
- * (at least PHP 5.2.11) have a bug (49816) that produces garbled
- * data
- */
-} // end of the 'PMA_outBufferPost()' function
-
-?>
View
7 navigation.php
@@ -62,13 +62,6 @@ function PMA_exitNavigationFrame()
session_write_close();
}
-/**
- * the output compression library
- */
-require_once 'libraries/ob.lib.php';
-
-PMA_outBufferPre();
-
/*
* selects the database if there is only one on current server
*/
View
6 querywindow.php
@@ -20,12 +20,6 @@
require_once 'libraries/sql_query_form.lib.php';
/**
- * starts output buffering if requested and supported
- */
-require_once 'libraries/ob.lib.php';
-PMA_outBufferPre();
-
-/**
* load relation params
*/
$cfgRelation = PMA_getRelationsParam();

0 comments on commit 41cb6e2

Please sign in to comment.