Added PMA_OutputBuffering class, dropped ob.lib.php
This commit is contained in:
parent
a054562100
commit
41cb6e20b0
@ -11,6 +11,5 @@ $response = PMA_Response::getInstance();
|
||||
$response->addHTML(
|
||||
PMA_getRelationsParamDiagnostic(PMA_getRelationsParam())
|
||||
);
|
||||
$response->response();
|
||||
|
||||
?>
|
||||
|
||||
@ -34,6 +34,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
|
||||
*
|
||||
@ -226,6 +236,16 @@ class PMA_Footer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function isAjax($isAjax)
|
||||
{
|
||||
$this->_isAjax = $isAjax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PMA_Footnotes object
|
||||
*
|
||||
@ -246,7 +266,7 @@ class PMA_Footer
|
||||
$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;
|
||||
@ -254,7 +274,7 @@ class PMA_Footer
|
||||
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 @@ class PMA_Footer
|
||||
$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)) {
|
||||
|
||||
@ -8,7 +8,6 @@ if (! defined('PHPMYADMIN')) {
|
||||
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(
|
||||
@ -199,6 +195,16 @@ class PMA_Header
|
||||
$this->_scripts->addCode(PMA_getReloadNavigationScript(true));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public function isAjax($isAjax)
|
||||
{
|
||||
$this->_isAjax = $isAjax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PMA_Scripts object
|
||||
*
|
||||
@ -275,7 +281,7 @@ class PMA_Header
|
||||
$retval = '';
|
||||
if (! self::$headerIsSent) {
|
||||
$this->sendHttpHeaders();
|
||||
if ($this->_isAjax === false) {
|
||||
if (! $this->_isAjax) {
|
||||
$retval .= $this->_getHtmlStart();
|
||||
$retval .= $this->_getMetaTags();
|
||||
$retval .= $this->_getLinkTags();
|
||||
@ -321,10 +327,6 @@ class PMA_Header
|
||||
*/
|
||||
public function sendHttpHeaders()
|
||||
{
|
||||
/**
|
||||
* Starts output buffering work
|
||||
*/
|
||||
PMA_outBufferPre();
|
||||
/**
|
||||
* Sends http headers
|
||||
*/
|
||||
|
||||
@ -206,10 +206,6 @@ class PMA_Menu
|
||||
} // 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
|
||||
|
||||
129
libraries/OutputBuffering.class.php
Normal file
129
libraries/OutputBuffering.class.php
Normal file
@ -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
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -9,6 +9,7 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once 'libraries/OutputBuffering.class.php';
|
||||
require_once 'libraries/Header.class.php';
|
||||
require_once 'libraries/Footer.class.php';
|
||||
|
||||
@ -32,6 +33,16 @@ class PMA_Response
|
||||
private $_content;
|
||||
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
|
||||
*
|
||||
@ -39,10 +50,18 @@ class PMA_Response
|
||||
*/
|
||||
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,15 +102,33 @@ class PMA_Response
|
||||
return $retval;
|
||||
}
|
||||
|
||||
public function response()
|
||||
public function simpleResponse()
|
||||
{
|
||||
if (! $GLOBALS['is_ajax_request']) {
|
||||
echo $this->getDisplay();
|
||||
} else {
|
||||
// FIXME
|
||||
}
|
||||
echo $this->getDisplay();
|
||||
exit;
|
||||
}
|
||||
|
||||
public function ajaxResponse()
|
||||
{
|
||||
echo $this->getDisplay();
|
||||
//PMA_ajaxResponse($this->getDisplay()); // FIXME
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function response()
|
||||
{
|
||||
$response = self::$_instance;
|
||||
$buffer = PMA_OutputBuffering::getInstance();
|
||||
if (empty($response->_content)) {
|
||||
$response->_content = $buffer->getContents();
|
||||
}
|
||||
if ($response->_isAjax) {
|
||||
$response->ajaxResponse();
|
||||
} else {
|
||||
$response->simpleResponse();
|
||||
}
|
||||
$buffer->flush();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -19,8 +19,8 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$footer = PMA_Response::getInstance()->getFooter();
|
||||
$footer->display();
|
||||
//$footer = PMA_Response::getInstance()->getFooter();
|
||||
//$footer->display();
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
?>
|
||||
@ -62,13 +62,6 @@ if (empty($_SESSION['debug'])) {
|
||||
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
|
||||
*/
|
||||
|
||||
@ -19,12 +19,6 @@ $is_superuser = PMA_isSuperuser();
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user