Footer.class.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 PMA_Scripts
  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. public function __construct()
  54. {
  55. $this->_isEnabled = true;
  56. $this->_scripts = new PMA_Scripts();
  57. $this->_isMinimal = false;
  58. }
  59. /**
  60. * Returns the message for demo server to error messages
  61. *
  62. * @return string
  63. */
  64. private function _getDemoMessage()
  65. {
  66. $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
  67. if (file_exists('./revision-info.php')) {
  68. include './revision-info.php';
  69. $message .= sprintf(
  70. __('Currently running Git revision %1$s from the %2$s branch.'),
  71. '<a target="_blank" href="' . $repobase . $fullrevision . '">'
  72. . $revision . '</a>',
  73. '<a target="_blank" href="' . $repobranchbase . $branch . '">'
  74. . $branch . '</a>'
  75. );
  76. } else {
  77. $message .= __('Git information missing!');
  78. }
  79. return PMA_Message::notice($message)->getDisplay();
  80. }
  81. /**
  82. * Renders the debug messages
  83. *
  84. * @return string
  85. */
  86. private function _getDebugMessage()
  87. {
  88. $retval = '';
  89. if (! empty($_SESSION['debug'])) {
  90. $sum_time = 0;
  91. $sum_exec = 0;
  92. foreach ($_SESSION['debug']['queries'] as $query) {
  93. $sum_time += $query['count'] * $query['time'];
  94. $sum_exec += $query['count'];
  95. }
  96. $retval .= '<div id="session_debug">';
  97. $retval .= count($_SESSION['debug']['queries']) . ' queries executed ';
  98. $retval .= $sum_exec . ' times in ' . $sum_time . ' seconds';
  99. $retval .= '<pre>';
  100. ob_start();
  101. print_r($_SESSION['debug']);
  102. $retval .= ob_get_contents();
  103. ob_end_clean();
  104. $retval .= '</pre>';
  105. $retval .= '</div>';
  106. $_SESSION['debug'] = array();
  107. }
  108. return $retval;
  109. }
  110. /**
  111. * Returns the url of the current page
  112. *
  113. * @param mixed $encoding See PMA_URL_getCommon()
  114. *
  115. * @return string
  116. */
  117. public function getSelfUrl($encoding = null)
  118. {
  119. $db = ! empty($GLOBALS['db']) ? $GLOBALS['db'] : '';
  120. $table = ! empty($GLOBALS['table']) ? $GLOBALS['table'] : '';
  121. $target = ! empty($_REQUEST['target']) ? $_REQUEST['target'] : '';
  122. $params = array(
  123. 'db' => $db,
  124. 'table' => $table,
  125. 'server' => $GLOBALS['server'],
  126. 'target' => $target
  127. );
  128. // needed for server privileges tabs
  129. if (isset($_REQUEST['viewing_mode'])
  130. && in_array($_REQUEST['viewing_mode'], array('server', 'db', 'table'))
  131. ) {
  132. $params['viewing_mode'] = $_REQUEST['viewing_mode'];
  133. }
  134. if (isset($_REQUEST['checkprivsdb'])
  135. //TODO: coming from server_privileges.php, here $db is not set,
  136. //uncomment below line when that is fixed
  137. //&& $_REQUEST['checkprivsdb'] == $db
  138. ) {
  139. $params['checkprivsdb'] = $_REQUEST['checkprivsdb'];
  140. }
  141. if (isset($_REQUEST['checkprivstable'])
  142. //TODO: coming from server_privileges.php, here $table is not set,
  143. //uncomment below line when that is fixed
  144. //&& $_REQUEST['checkprivstable'] == $table
  145. ) {
  146. $params['checkprivstable'] = $_REQUEST['checkprivstable'];
  147. }
  148. if (isset($_REQUEST['single_table'])
  149. && in_array($_REQUEST['single_table'], array(true, false))
  150. ) {
  151. $params['single_table'] = $_REQUEST['single_table'];
  152. }
  153. return basename(PMA_getenv('SCRIPT_NAME')) . PMA_URL_getCommon(
  154. $params,
  155. $encoding
  156. );
  157. }
  158. /**
  159. * Renders the link to open a new page
  160. *
  161. * @param string $url The url of the page
  162. *
  163. * @return string
  164. */
  165. private function _getSelfLink($url)
  166. {
  167. $retval = '';
  168. $retval .= '<div id="selflink" class="print_ignore">';
  169. $retval .= '<a href="' . $url . '"'
  170. . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
  171. if (PMA_Util::showIcons('TabsMode')) {
  172. $retval .= PMA_Util::getImage(
  173. 'window-new.png',
  174. __('Open new phpMyAdmin window')
  175. );
  176. } else {
  177. $retval .= __('Open new phpMyAdmin window');
  178. }
  179. $retval .= '</a>';
  180. $retval .= '</div>';
  181. return $retval;
  182. }
  183. /**
  184. * Renders the link to open a new page
  185. *
  186. * @return string
  187. */
  188. public function getErrorMessages()
  189. {
  190. $retval = '';
  191. if ($GLOBALS['error_handler']->hasDisplayErrors()) {
  192. $retval .= '<div class="clearfloat" id="pma_errors">';
  193. $retval .= $GLOBALS['error_handler']->getDispErrors();
  194. $retval .= '</div>';
  195. }
  196. return $retval;
  197. }
  198. /**
  199. * Saves query in history
  200. *
  201. * @return void
  202. */
  203. private function _setHistory()
  204. {
  205. if (! PMA_isValid($_REQUEST['no_history'])
  206. && empty($GLOBALS['error_message'])
  207. && ! empty($GLOBALS['sql_query'])
  208. ) {
  209. PMA_setHistory(
  210. PMA_ifSetOr($GLOBALS['db'], ''),
  211. PMA_ifSetOr($GLOBALS['table'], ''),
  212. $GLOBALS['cfg']['Server']['user'],
  213. $GLOBALS['sql_query']
  214. );
  215. }
  216. }
  217. /**
  218. * Disables the rendering of the footer
  219. *
  220. * @return void
  221. */
  222. public function disable()
  223. {
  224. $this->_isEnabled = false;
  225. }
  226. /**
  227. * Set the ajax flag to indicate whether
  228. * we are sevicing an ajax request
  229. *
  230. * @param bool $isAjax Whether we are sevicing an ajax request
  231. *
  232. * @return void
  233. */
  234. public function setAjax($isAjax)
  235. {
  236. $this->_isAjax = ($isAjax == true);
  237. }
  238. /**
  239. * Turn on minimal display mode
  240. *
  241. * @return void
  242. */
  243. public function setMinimal()
  244. {
  245. $this->_isMinimal = true;
  246. }
  247. /**
  248. * Returns the PMA_Scripts object
  249. *
  250. * @return PMA_Scripts object
  251. */
  252. public function getScripts()
  253. {
  254. return $this->_scripts;
  255. }
  256. /**
  257. * Renders the footer
  258. *
  259. * @return string
  260. */
  261. public function getDisplay()
  262. {
  263. $retval = '';
  264. $this->_setHistory();
  265. if ($this->_isEnabled) {
  266. if (! $this->_isAjax) {
  267. $retval .= "</div>";
  268. }
  269. if (! $this->_isAjax && ! $this->_isMinimal) {
  270. if (PMA_getenv('SCRIPT_NAME')
  271. && empty($_POST)
  272. && empty($GLOBALS['checked_special'])
  273. && ! $this->_isAjax
  274. ) {
  275. $url = $this->getSelfUrl('unencoded');
  276. $header = PMA_Response::getInstance()->getHeader();
  277. $scripts = $header->getScripts()->getFiles();
  278. $menuHash = $header->getMenu()->getHash();
  279. // prime the client-side cache
  280. $this->_scripts->addCode(
  281. sprintf(
  282. 'AJAX.cache.primer = {'
  283. . ' url: "%s",'
  284. . ' scripts: %s,'
  285. . ' menuHash: "%s"'
  286. . '};',
  287. PMA_escapeJsString($url),
  288. json_encode($scripts),
  289. PMA_escapeJsString($menuHash)
  290. )
  291. );
  292. }
  293. if (PMA_getenv('SCRIPT_NAME')
  294. && ! $this->_isAjax
  295. ) {
  296. $url = $this->getSelfUrl();
  297. $retval .= $this->_getSelfLink($url);
  298. }
  299. $retval .= $this->_getDebugMessage();
  300. $retval .= $this->getErrorMessages();
  301. $retval .= $this->_scripts->getDisplay();
  302. if ($GLOBALS['cfg']['DBG']['demo']) {
  303. $retval .= '<div id="pma_demo">';
  304. $retval .= $this->_getDemoMessage();
  305. $retval .= '</div>';
  306. }
  307. // Include possible custom footers
  308. if (file_exists(CUSTOM_FOOTER_FILE)) {
  309. $retval .= '<div id="pma_footer">';
  310. ob_start();
  311. include CUSTOM_FOOTER_FILE;
  312. $retval .= ob_get_contents();
  313. ob_end_clean();
  314. $retval .= '</div>';
  315. }
  316. }
  317. if (! $this->_isAjax) {
  318. $retval .= "</body></html>";
  319. }
  320. }
  321. return $retval;
  322. }
  323. }