2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Used to render the footer of PMA's pages
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/Scripts.class.php';
15 * Class used to output the footer
22 * PMA_Scripts instance
29 * Whether we are servicing an ajax request.
30 * We can't simply use $GLOBALS['is_ajax_request']
31 * here since it may have not been initialised yet.
38 * Whether to only close the BODY and HTML tags
39 * or also include scripts, errors and links
46 * Whether to display anything
54 * Creates a new class instance
56 * @return new PMA_Footer object
58 public function __construct()
60 $this->_isEnabled
= true;
61 $this->_scripts
= new PMA_Scripts();
62 $this->_isMinimal
= false;
66 * Adds the message for demo server to error messages
70 private function _addDemoMessage()
72 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
73 if (file_exists('./revision-info.php')) {
74 include './revision-info.php';
76 __('Currently running Git revision %1$s from the %2$s branch.'),
77 '<a target="_blank" href="' . $repobase . $fullrevision . '">'
79 '<a target="_blank" href="' . $repobranchbase . $branch . '">'
83 $message .= __('Git information missing!');
86 $GLOBALS['error_handler']->addError(
96 * Renders the debug messages
100 private function _getDebugMessage()
103 if (! empty($_SESSION['debug'])) {
106 foreach ($_SESSION['debug']['queries'] as $query) {
107 $sum_time +
= $query['count'] * $query['time'];
108 $sum_exec +
= $query['count'];
111 $retval .= '<div id="session_debug">';
112 $retval .= count($_SESSION['debug']['queries']) . ' queries executed ';
113 $retval .= $sum_exec . ' times in ' . $sum_time . ' seconds';
117 print_r($_SESSION['debug']);
118 $retval .= ob_get_contents();
123 $_SESSION['debug'] = array();
129 * Returns the url of the current page
131 * @param mixed $encoding See PMA_URL_getCommon()
135 public function getSelfUrl($encoding = null)
137 $db = ! empty($GLOBALS['db']) ?
$GLOBALS['db'] : '';
138 $table = ! empty($GLOBALS['table']) ?
$GLOBALS['table'] : '';
139 $target = ! empty($_REQUEST['target']) ?
$_REQUEST['target'] : '';
140 return basename(PMA_getenv('SCRIPT_NAME')) . PMA_URL_getCommon(
144 'server' => $GLOBALS['server'],
152 * Renders the link to open a new page
154 * @param string $url The url of the page
158 private function _getSelfLink($url)
161 $retval .= '<div id="selflink" class="print_ignore">';
162 $retval .= '<a href="' . $url . '"'
163 . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
164 if (PMA_Util
::showIcons('TabsMode')) {
165 $retval .= PMA_Util
::getImage(
167 __('Open new phpMyAdmin window')
170 $retval .= __('Open new phpMyAdmin window');
178 * Renders the link to open a new page
182 public function getErrorMessages()
185 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
186 $retval .= '<div class="clearfloat" id="pma_errors">';
187 $retval .= $GLOBALS['error_handler']->getDispErrors();
194 * Saves query in history
198 private function _setHistory()
200 if (! PMA_isValid($_REQUEST['no_history'])
201 && empty($GLOBALS['error_message'])
202 && ! empty($GLOBALS['sql_query'])
205 PMA_ifSetOr($GLOBALS['db'], ''),
206 PMA_ifSetOr($GLOBALS['table'], ''),
207 $GLOBALS['cfg']['Server']['user'],
208 $GLOBALS['sql_query']
214 * Disables the rendering of the footer
218 public function disable()
220 $this->_isEnabled
= false;
224 * Set the ajax flag to indicate whether
225 * we are sevicing an ajax request
227 * @param bool $isAjax Whether we are sevicing an ajax request
231 public function setAjax($isAjax)
233 $this->_isAjax
= ($isAjax == true);
237 * Turn on minimal display mode
241 public function setMinimal()
243 $this->_isMinimal
= true;
247 * Returns the PMA_Scripts object
249 * @return PMA_Scripts object
251 public function getScripts()
253 return $this->_scripts
;
261 public function getDisplay()
264 $this->_setHistory();
265 if ($this->_isEnabled
) {
266 if (! $this->_isAjax
) {
269 if ($GLOBALS['cfg']['DBG']['demo']) {
270 $this->_addDemoMessage();
272 if (! $this->_isAjax
&& ! $this->_isMinimal
) {
273 if (PMA_getenv('SCRIPT_NAME')
275 && empty($GLOBALS['checked_special'])
278 $url = $this->getSelfUrl('unencoded');
279 $header = PMA_Response
::getInstance()->getHeader();
280 $scripts = $header->getScripts()->getFiles();
281 $menuHash = $header->getMenu()->getHash();
282 // prime the client-side cache
283 $this->_scripts
->addCode(
285 'AJAX.cache.primer = {'
290 PMA_escapeJsString($url),
291 json_encode($scripts),
292 PMA_escapeJsString($menuHash)
295 $url = $this->getSelfUrl();
296 $retval .= $this->_getSelfLink($url);
298 $retval .= $this->_getDebugMessage();
299 $retval .= $this->getErrorMessages();
300 $retval .= $this->_scripts
->getDisplay();
301 // Include possible custom footers
302 if (file_exists(CUSTOM_FOOTER_FILE
)) {
304 include CUSTOM_FOOTER_FILE
;
305 $retval .= ob_get_contents();
309 if (! $this->_isAjax
) {
310 $retval .= "</body></html>";