Footer.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Used to render the footer of PMA's pages
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. require_once 'libraries/Scripts.class.php';
  12. /**
  13. * Class used to output the footer
  14. *
  15. * @package PhpMyAdmin
  16. */
  17. class PMA_Footer
  18. {
  19. /**
  20. * PMA_Scripts instance
  21. *
  22. * @access private
  23. * @var object
  24. */
  25. private $_scripts;
  26. /**
  27. * Whether we are servicing an ajax request.
  28. * We can't simply use $GLOBALS['is_ajax_request']
  29. * here since it may have not been initialised yet.
  30. *
  31. * @access private
  32. * @var bool
  33. */
  34. private $_isAjax;
  35. /**
  36. * Whether to only close the BODY and HTML tags
  37. * or also include scripts, errors and links
  38. *
  39. * @access private
  40. * @var bool
  41. */
  42. private $_isMinimal;
  43. /**
  44. * Whether to display anything
  45. *
  46. * @access private
  47. * @var bool
  48. */
  49. private $_isEnabled;
  50. /**
  51. * Creates a new class instance
  52. *
  53. * @return new PMA_Footer object
  54. */
  55. public function __construct()
  56. {
  57. $this->_isEnabled = true;
  58. $this->_scripts = new PMA_Scripts();
  59. $this->_isMinimal = false;
  60. }
  61. /**
  62. * Renders the debug messages
  63. *
  64. * @return string
  65. */
  66. private function _getDebugMessage()
  67. {
  68. $retval = '';
  69. if (! empty($_SESSION['debug'])) {
  70. $sum_time = 0;
  71. $sum_exec = 0;
  72. foreach ($_SESSION['debug']['queries'] as $query) {
  73. $sum_time += $query['count'] * $query['time'];
  74. $sum_exec += $query['count'];
  75. }
  76. $retval .= '<div id="session_debug">';
  77. $retval .= count($_SESSION['debug']['queries']) . ' queries executed ';
  78. $retval .= $sum_exec . ' times in ' . $sum_time . ' seconds';
  79. $retval .= '<pre>';
  80. ob_start();
  81. print_r($_SESSION['debug']);
  82. $retval .= ob_get_contents();
  83. ob_end_clean();
  84. $retval .= '</pre>';
  85. $retval .= '</div>';
  86. $_SESSION['debug'] = array();
  87. }
  88. return $retval;
  89. }
  90. /**
  91. * Returns the url of the current page
  92. *
  93. * @param mixed $encoding See PMA_generate_common_url()
  94. *
  95. * @return string
  96. */
  97. public function getSelfUrl($encoding = null)
  98. {
  99. $db = ! empty($GLOBALS['db']) ? $GLOBALS['db'] : '';
  100. $table = ! empty($GLOBALS['table']) ? $GLOBALS['table'] : '';
  101. $target = ! empty($_REQUEST['target']) ? $_REQUEST['target'] : '';
  102. return basename(PMA_getenv('SCRIPT_NAME')) . PMA_generate_common_url(
  103. array(
  104. 'db' => $db,
  105. 'table' => $table,
  106. 'server' => $GLOBALS['server'],
  107. 'target' => $target
  108. ),
  109. $encoding
  110. );
  111. }
  112. /**
  113. * Renders the link to open a new page
  114. *
  115. * @param string $url The url of the page
  116. *
  117. * @return string
  118. */
  119. private function _getSelfLink($url)
  120. {
  121. $retval = '';
  122. $retval .= '<div id="selflink" class="print_ignore">';
  123. $retval .= '<a href="' . $url . '"'
  124. . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
  125. if (in_array(
  126. $GLOBALS['cfg']['TabsMode'],
  127. array('icons', 'both')
  128. )
  129. ) {
  130. $retval .= PMA_Util::getImage(
  131. 'window-new.png',
  132. __('Open new phpMyAdmin window')
  133. );
  134. } else {
  135. $retval .= __('Open new phpMyAdmin window');
  136. }
  137. $retval .= '</a>';
  138. $retval .= '</div>';
  139. return $retval;
  140. }
  141. /**
  142. * Renders the link to open a new page
  143. *
  144. * @return string
  145. */
  146. public function getErrorMessages()
  147. {
  148. $retval = '';
  149. if ($GLOBALS['error_handler']->hasDisplayErrors()) {
  150. $retval .= '<div class="clearfloat" id="pma_errors">';
  151. $retval .= $GLOBALS['error_handler']->getDispErrors();
  152. $retval .= '</div>';
  153. }
  154. return $retval;
  155. }
  156. /**
  157. * Saves query in history
  158. *
  159. * @return void
  160. */
  161. private function _setHistory()
  162. {
  163. if (! PMA_isValid($_REQUEST['no_history'])
  164. && empty($GLOBALS['error_message'])
  165. && ! empty($GLOBALS['sql_query'])
  166. ) {
  167. PMA_setHistory(
  168. PMA_ifSetOr($GLOBALS['db'], ''),
  169. PMA_ifSetOr($GLOBALS['table'], ''),
  170. $GLOBALS['cfg']['Server']['user'],
  171. $GLOBALS['sql_query']
  172. );
  173. }
  174. }
  175. /**
  176. * Disables the rendering of the footer
  177. *
  178. * @return void
  179. */
  180. public function disable()
  181. {
  182. $this->_isEnabled = false;
  183. }
  184. /**
  185. * Set the ajax flag to indicate whether
  186. * we are sevicing an ajax request
  187. *
  188. * @param bool $isAjax Whether we are sevicing an ajax request
  189. *
  190. * @return void
  191. */
  192. public function setAjax($isAjax)
  193. {
  194. $this->_isAjax = ($isAjax == true);
  195. }
  196. /**
  197. * Turn on minimal display mode
  198. *
  199. * @return void
  200. */
  201. public function setMinimal()
  202. {
  203. $this->_isMinimal = true;
  204. }
  205. /**
  206. * Returns the PMA_Scripts object
  207. *
  208. * @return PMA_Scripts object
  209. */
  210. public function getScripts()
  211. {
  212. return $this->_scripts;
  213. }
  214. /**
  215. * Renders the footer
  216. *
  217. * @return string
  218. */
  219. public function getDisplay()
  220. {
  221. $retval = '';
  222. $this->_setHistory();
  223. if ($this->_isEnabled) {
  224. if (! $this->_isAjax) {
  225. $retval .= "</div>";
  226. }
  227. if (! $this->_isAjax && ! $this->_isMinimal) {
  228. if (PMA_getenv('SCRIPT_NAME')
  229. && empty($_POST)
  230. && empty($GLOBALS['checked_special'])
  231. && ! $this->_isAjax
  232. ) {
  233. $url = $this->getSelfUrl('unencoded');
  234. $header = PMA_Response::getInstance()->getHeader();
  235. $scripts = $header->getScripts()->getFiles();
  236. $menuHash = $header->getMenu()->getHash();
  237. // prime the client-side cache
  238. $this->_scripts->addCode(
  239. sprintf(
  240. 'AJAX.cache.primer = {'
  241. . ' url: "%s",'
  242. . ' scripts: %s,'
  243. . ' menuHash: "%s"'
  244. . '};',
  245. PMA_escapeJsString($url),
  246. json_encode($scripts),
  247. PMA_escapeJsString($menuHash)
  248. )
  249. );
  250. $url = $this->getSelfUrl();
  251. $retval .= $this->_getSelfLink($url);
  252. }
  253. $retval .= $this->_getDebugMessage();
  254. $retval .= $this->getErrorMessages();
  255. $retval .= $this->_scripts->getDisplay();
  256. // Include possible custom footers
  257. if (file_exists(CUSTOM_FOOTER_FILE)) {
  258. ob_start();
  259. include CUSTOM_FOOTER_FILE;
  260. $retval .= ob_get_contents();
  261. ob_end_clean();
  262. }
  263. }
  264. if (! $this->_isAjax) {
  265. $retval .= "</body></html>";
  266. }
  267. }
  268. return $retval;
  269. }
  270. }