PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/phpmyadmin/libraries/ob.lib.php

http://github.com/jyr/MNPP
PHP | 111 lines | 34 code | 13 blank | 64 comment | 10 complexity | ce4cf9d69f8dcd652981317c3538cf64 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, LGPL-2.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, BSD-2-Clause
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Output buffer functions for phpMyAdmin
  5. *
  6. * Copyright 2001 Jeremy Brand <jeremy@nirvani.net>
  7. * http://www.jeremybrand.com/Jeremy/Brand/Jeremy_Brand.html
  8. *
  9. * Check for all the needed functions for output buffering
  10. * Make some wrappers for the top and bottoms of our files.
  11. *
  12. * @version $Id$
  13. * @package phpMyAdmin
  14. */
  15. /**
  16. * This function be used eventually to support more modes. It is needed
  17. * because both header and footer functions must know what each other is
  18. * doing.
  19. *
  20. * @uses $cfg['OBGzip']
  21. * @uses function_exists()
  22. * @uses ini_get()
  23. * @uses ob_get_level()
  24. * @staticvar integer remember last calculated value
  25. * @return integer the output buffer mode
  26. */
  27. function PMA_outBufferModeGet()
  28. {
  29. static $mode = null;
  30. if (null !== $mode) {
  31. return $mode;
  32. }
  33. $mode = 0;
  34. if ($GLOBALS['cfg']['OBGzip'] && function_exists('ob_start')) {
  35. if (ini_get('output_handler') == 'ob_gzhandler') {
  36. // If a user sets the output_handler in php.ini to ob_gzhandler, then
  37. // any right frame file in phpMyAdmin will not be handled properly by
  38. // the browser. My fix was to check the ini file within the
  39. // PMA_outBufferModeGet() function.
  40. //
  41. // (Patch by Garth Gillespie, modified by Marc Delisle)
  42. $mode = 0;
  43. } elseif (function_exists('ob_get_level') && ob_get_level() > 0) {
  44. // If output buffering is enabled in php.ini it's not possible to
  45. // add the ob_gzhandler without a warning message from php 4.3.0.
  46. // Being better safe than sorry, check for any existing output handler
  47. // instead of just checking the 'output_buffering' setting.
  48. $mode = 0;
  49. } else {
  50. $mode = 1;
  51. }
  52. }
  53. // Zero (0) is no mode or in other words output buffering is OFF.
  54. // Follow 2^0, 2^1, 2^2, 2^3 type values for the modes.
  55. // Usefull if we ever decide to combine modes. Then a bitmask field of
  56. // the sum of all modes will be the natural choice.
  57. return $mode;
  58. } // end of the 'PMA_outBufferModeGet()' function
  59. /**
  60. * This function will need to run at the top of all pages if output
  61. * output buffering is turned on. It also needs to be passed $mode from
  62. * the PMA_outBufferModeGet() function or it will be useless.
  63. *
  64. * @uses PMA_outBufferModeGet()
  65. * @uses PMA_outBufferPost() to register it as shutdown function
  66. * @uses ob_start()
  67. * @uses header() to send X-ob_mode:
  68. * @uses register_shutdown_function() to register PMA_outBufferPost()
  69. */
  70. function PMA_outBufferPre()
  71. {
  72. if ($mode = PMA_outBufferModeGet()) {
  73. ob_start('ob_gzhandler');
  74. }
  75. header('X-ob_mode: ' . $mode);
  76. register_shutdown_function('PMA_outBufferPost');
  77. } // end of the 'PMA_outBufferPre()' function
  78. /**
  79. * This function will need to run at the bottom of all pages if output
  80. * buffering is turned on. It also needs to be passed $mode from the
  81. * PMA_outBufferModeGet() function or it will be useless.
  82. *
  83. * @uses PMA_outBufferModeGet()
  84. * @uses ob_flush()
  85. * @uses flush()
  86. */
  87. function PMA_outBufferPost()
  88. {
  89. if (ob_get_status() && PMA_outBufferModeGet()) {
  90. ob_flush();
  91. }
  92. /**
  93. * previously we had here an "else flush()" but some PHP versions
  94. * (at least PHP 5.2.11) have a bug (49816) that produces garbled
  95. * data
  96. */
  97. } // end of the 'PMA_outBufferPost()' function
  98. ?>