PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/Footer.class.php

http://github.com/phpmyadmin/phpmyadmin
PHP | 336 lines | 205 code | 19 blank | 112 comment | 46 complexity | 0b37e5f1a05e52726c72c0bef672768d MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  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. $this->_addDefaultScripts();
  61. }
  62. /**
  63. * Loads common scripts
  64. *
  65. * @return void
  66. */
  67. private function _addDefaultScripts()
  68. {
  69. if (empty($GLOBALS['error_message'])) {
  70. $this->_scripts->addCode("
  71. $(function() {
  72. // updates current settings
  73. if (window.parent.setAll) {
  74. window.parent.setAll(
  75. '" . PMA_escapeJsString($GLOBALS['lang']) . "',
  76. '" . PMA_escapeJsString($GLOBALS['collation_connection']) . "',
  77. '" . PMA_escapeJsString($GLOBALS['server']) . "',
  78. '" . PMA_escapeJsString(PMA_ifSetOr($GLOBALS['db'], '')) . "',
  79. '" . PMA_escapeJsString(PMA_ifSetOr($GLOBALS['table'], '')) . "',
  80. '" . PMA_escapeJsString($_SESSION[' PMA_token ']) . "'
  81. );
  82. }
  83. });
  84. ");
  85. if (! empty($GLOBALS['reload'])) {
  86. $this->_scripts->addCode("
  87. // refresh navigation frame content
  88. if (window.parent.refreshNavigation) {
  89. window.parent.refreshNavigation();
  90. }
  91. ");
  92. } else if (isset($_GET['reload_left_frame'])
  93. && $_GET['reload_left_frame'] == '1'
  94. ) {
  95. // reload left frame (used by user preferences)
  96. $this->_scripts->addCode("
  97. if (window.parent && window.parent.frame_navigation) {
  98. window.parent.frame_navigation.location.reload();
  99. }
  100. ");
  101. }
  102. // set current db, table and sql query in the querywindow
  103. $query = '';
  104. if (isset($GLOBALS['sql_query']) && strlen($GLOBALS['sql_query']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
  105. $query = PMA_escapeJsString($GLOBALS['sql_query']);
  106. }
  107. $this->_scripts->addCode("
  108. if (window.parent.reload_querywindow) {
  109. window.parent.reload_querywindow(
  110. '" . PMA_escapeJsString(PMA_ifSetOr($GLOBALS['db'], '')) . "',
  111. '" . PMA_escapeJsString(PMA_ifSetOr($GLOBALS['table'], '')) . "',
  112. '" . $query . "'
  113. );
  114. }
  115. ");
  116. if (! empty($GLOBALS['focus_querywindow'])) {
  117. // set focus to the querywindow
  118. $this->_scripts->addCode("
  119. if (parent.querywindow && !parent.querywindow.closed
  120. && parent.querywindow.location
  121. ) {
  122. self.focus();
  123. }
  124. ");
  125. }
  126. $this->_scripts->addCode("
  127. if (window.parent.frame_content) {
  128. // reset content frame name, as querywindow needs
  129. // to set a unique name before submitting form data,
  130. // and navigation frame needs the original name
  131. if (typeof(window.parent.frame_content.name) != 'undefined'
  132. && window.parent.frame_content.name != 'frame_content') {
  133. window.parent.frame_content.name = 'frame_content';
  134. }
  135. if (typeof(window.parent.frame_content.id) != 'undefined'
  136. && window.parent.frame_content.id != 'frame_content') {
  137. window.parent.frame_content.id = 'frame_content';
  138. }
  139. //window.parent.frame_content.setAttribute('name', 'frame_content');
  140. //window.parent.frame_content.setAttribute('id', 'frame_content');
  141. }
  142. ");
  143. }
  144. }
  145. /**
  146. * Renders the debug messages
  147. *
  148. * @return string
  149. */
  150. private function _getDebugMessage()
  151. {
  152. $retval = '';
  153. if (! empty($_SESSION['debug'])) {
  154. $sum_time = 0;
  155. $sum_exec = 0;
  156. foreach ($_SESSION['debug']['queries'] as $query) {
  157. $sum_time += $query['count'] * $query['time'];
  158. $sum_exec += $query['count'];
  159. }
  160. $retval .= '<div>';
  161. $retval .= count($_SESSION['debug']['queries']) . ' queries executed ';
  162. $retval .= $sum_exec . ' times in ' . $sum_time . ' seconds';
  163. $retval .= '<pre>';
  164. ob_start();
  165. print_r($_SESSION['debug']);
  166. $retval .= ob_get_contents();
  167. ob_end_clean();
  168. $retval .= '</pre>';
  169. $retval .= '</div>';
  170. $_SESSION['debug'] = array();
  171. }
  172. return $retval;
  173. }
  174. /**
  175. * Renders the link to open a new page
  176. *
  177. * @param string $url_params URL paramater string
  178. *
  179. * @return string
  180. */
  181. private function _getSelfLink($url_params)
  182. {
  183. $retval = '';
  184. $retval .= '<div id="selflink" class="print_ignore">';
  185. $retval .= '<a href="index.php' . PMA_generate_common_url($url_params) . '"'
  186. . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
  187. if ($GLOBALS['cfg']['NavigationBarIconic']) {
  188. $retval .= PMA_getImage(
  189. 'window-new.png',
  190. __('Open new phpMyAdmin window')
  191. );
  192. } else {
  193. $retval .= __('Open new phpMyAdmin window');
  194. }
  195. $retval .= '</a>';
  196. $retval .= '</div>';
  197. return $retval;
  198. }
  199. /**
  200. * Renders the link to open a new page
  201. *
  202. * @return string
  203. */
  204. private function _getErrorMessages()
  205. {
  206. $retval = '';
  207. if ($GLOBALS['error_handler']->hasDisplayErrors()) {
  208. $retval .= '<div class="clearfloat">';
  209. $retval .= $GLOBALS['error_handler']->getDispErrors();
  210. $retval .= '</div>';
  211. }
  212. return $retval;
  213. }
  214. /**
  215. * Saves query in history
  216. *
  217. * @return void
  218. */
  219. private function _setHistory()
  220. {
  221. if (! PMA_isValid($_REQUEST['no_history'])
  222. && empty($GLOBALS['error_message'])
  223. && ! empty($GLOBALS['sql_query'])
  224. ) {
  225. PMA_setHistory(
  226. PMA_ifSetOr($GLOBALS['db'], ''),
  227. PMA_ifSetOr($GLOBALS['table'], ''),
  228. $GLOBALS['cfg']['Server']['user'],
  229. $GLOBALS['sql_query']
  230. );
  231. }
  232. }
  233. /**
  234. * Disables the rendering of the footer
  235. *
  236. * @return void
  237. */
  238. public function disable()
  239. {
  240. $this->_isEnabled = false;
  241. }
  242. /**
  243. * Set the ajax flag to indicate whether
  244. * we are sevicing an ajax request
  245. *
  246. * @param bool $isAjax Whether we are sevicing an ajax request
  247. *
  248. * @return void
  249. */
  250. public function setAjax($isAjax)
  251. {
  252. $this->_isAjax = ($isAjax == true);
  253. }
  254. /**
  255. * Turn on minimal display mode
  256. *
  257. * @return void
  258. */
  259. public function setMinimal()
  260. {
  261. $this->_isMinimal = true;
  262. }
  263. /**
  264. * Returns the PMA_Scripts object
  265. *
  266. * @return PMA_Scripts object
  267. */
  268. public function getScripts()
  269. {
  270. return $this->_scripts;
  271. }
  272. /**
  273. * Renders the footer
  274. *
  275. * @return string
  276. */
  277. public function getDisplay()
  278. {
  279. $retval = '';
  280. $this->_setHistory();
  281. if ($this->_isEnabled) {
  282. if (! $this->_isAjax && ! $this->_isMinimal) {
  283. // Link to itself to replicate windows including frameset
  284. if (! isset($GLOBALS['checked_special'])) {
  285. $GLOBALS['checked_special'] = false;
  286. }
  287. if (PMA_getenv('SCRIPT_NAME')
  288. && empty($_POST)
  289. && ! $GLOBALS['checked_special']
  290. && ! $this->_isAjax
  291. ) {
  292. $url_params['target'] = basename(PMA_getenv('SCRIPT_NAME'));
  293. $url = PMA_generate_common_url($url_params, 'text', '');
  294. $this->_scripts->addCode("
  295. // Store current location in hash part
  296. // of URL to allow direct bookmarking
  297. setURLHash('$url');
  298. ");
  299. $retval .= $this->_getSelfLink($url_params);
  300. }
  301. $retval .= $this->_getDebugMessage();
  302. $retval .= $this->_getErrorMessages();
  303. $retval .= $this->_scripts->getDisplay();
  304. // Include possible custom footers
  305. if (file_exists(CUSTOM_FOOTER_FILE)) {
  306. ob_start();
  307. include CUSTOM_FOOTER_FILE;
  308. $retval .= ob_get_contents();
  309. ob_end_clean();
  310. }
  311. } else if (! $this->_isAjax) {
  312. $retval .= "</body></html>";
  313. }
  314. }
  315. return $retval;
  316. }
  317. }