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 public function __construct()
58 $this->_isEnabled
= true;
59 $this->_scripts
= new PMA_Scripts();
60 $this->_isMinimal
= false;
64 * Returns the message for demo server to error messages
68 private function _getDemoMessage()
70 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
71 if (file_exists('./revision-info.php')) {
72 include './revision-info.php';
74 __('Currently running Git revision %1$s from the %2$s branch.'),
75 '<a target="_blank" href="' . $repobase . $fullrevision . '">'
77 '<a target="_blank" href="' . $repobranchbase . $branch . '">'
81 $message .= __('Git information missing!');
84 return PMA_Message
::notice($message)->getDisplay();
88 * Remove recursions and iterator objects from an object
90 * @param object|array &$object Object to clean
91 * @param array $stack Stack used to keep track of recursion,
92 * need not be passed for the first time
94 * @return object Reference passed object
96 private static function _removeRecursion(&$object, $stack = array())
98 if ((is_object($object) ||
is_array($object)) && $object) {
99 if ($object instanceof Traversable
) {
100 $object = "***ITERATOR***";
101 } else if (!in_array($object, $stack, true)) {
103 foreach ($object as &$subobject) {
104 self
::_removeRecursion($subobject, $stack);
107 $object = "***RECURSION***";
114 * Renders the debug messages
118 public function getDebugMessage()
120 $retval = '\'null\'';
121 if ($GLOBALS['cfg']['DBG']['sql']
122 && empty($_REQUEST['no_debug'])
123 && !empty($_SESSION['debug'])
125 // Remove recursions and iterators from $_SESSION['debug']
126 self
::_removeRecursion($_SESSION['debug']);
128 $retval = JSON_encode($_SESSION['debug']);
129 $_SESSION['debug'] = array();
130 return json_last_error() ?
'\'false\'' : $retval;
132 $_SESSION['debug'] = array();
137 * Returns the url of the current page
139 * @param string|null $encode See PMA_URL_getCommon()
143 public function getSelfUrl($encode = 'html')
145 $db = ! empty($GLOBALS['db']) ?
$GLOBALS['db'] : '';
146 $table = ! empty($GLOBALS['table']) ?
$GLOBALS['table'] : '';
147 $target = ! empty($_REQUEST['target']) ?
$_REQUEST['target'] : '';
151 'server' => $GLOBALS['server'],
154 // needed for server privileges tabs
155 if (isset($_REQUEST['viewing_mode'])
156 && in_array($_REQUEST['viewing_mode'], array('server', 'db', 'table'))
158 $params['viewing_mode'] = $_REQUEST['viewing_mode'];
161 * @todo coming from server_privileges.php, here $db is not set,
162 * add the following condition below when that is fixed
163 * && $_REQUEST['checkprivsdb'] == $db
165 if (isset($_REQUEST['checkprivsdb'])
167 $params['checkprivsdb'] = $_REQUEST['checkprivsdb'];
170 * @todo coming from server_privileges.php, here $table is not set,
171 * add the following condition below when that is fixed
172 * && $_REQUEST['checkprivstable'] == $table
174 if (isset($_REQUEST['checkprivstable'])
176 $params['checkprivstable'] = $_REQUEST['checkprivstable'];
178 if (isset($_REQUEST['single_table'])
179 && in_array($_REQUEST['single_table'], array(true, false))
181 $params['single_table'] = $_REQUEST['single_table'];
183 return basename(PMA_getenv('SCRIPT_NAME')) . PMA_URL_getCommon(
190 * Renders the link to open a new page
192 * @param string $url The url of the page
196 private function _getSelfLink($url)
199 $retval .= '<div id="selflink" class="print_ignore">';
200 $retval .= '<a href="' . $url . '"'
201 . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank">';
202 if (PMA_Util
::showIcons('TabsMode')) {
203 $retval .= PMA_Util
::getImage(
205 __('Open new phpMyAdmin window')
208 $retval .= __('Open new phpMyAdmin window');
216 * Renders the link to open a new page
220 public function getErrorMessages()
222 $retval = '<div class="clearfloat" id="pma_errors">';
223 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
224 $retval .= $GLOBALS['error_handler']->getDispErrors();
231 $GLOBALS['error_handler']->reportErrors();
237 * Saves query in history
241 private function _setHistory()
243 if (! PMA_isValid($_REQUEST['no_history'])
244 && empty($GLOBALS['error_message'])
245 && ! empty($GLOBALS['sql_query'])
248 PMA_ifSetOr($GLOBALS['db'], ''),
249 PMA_ifSetOr($GLOBALS['table'], ''),
250 $GLOBALS['cfg']['Server']['user'],
251 $GLOBALS['sql_query']
257 * Disables the rendering of the footer
261 public function disable()
263 $this->_isEnabled
= false;
267 * Set the ajax flag to indicate whether
268 * we are servicing an ajax request
270 * @param bool $isAjax Whether we are servicing an ajax request
274 public function setAjax($isAjax)
276 $this->_isAjax
= !!$isAjax;
280 * Turn on minimal display mode
284 public function setMinimal()
286 $this->_isMinimal
= true;
290 * Returns the PMA_Scripts object
292 * @return PMA_Scripts object
294 public function getScripts()
296 return $this->_scripts
;
304 public function getDisplay()
307 $this->_setHistory();
308 if ($this->_isEnabled
) {
309 if (! $this->_isAjax
) {
312 if (! $this->_isAjax
&& ! $this->_isMinimal
) {
313 if (PMA_getenv('SCRIPT_NAME')
315 && empty($GLOBALS['checked_special'])
318 $url = $this->getSelfUrl('unencoded');
319 $header = PMA_Response
::getInstance()->getHeader();
320 $scripts = $header->getScripts()->getFiles();
321 $menuHash = $header->getMenu()->getHash();
322 // prime the client-side cache
323 $this->_scripts
->addCode(
325 'if (! (history && history.pushState)) '
326 . 'PMA_MicroHistory.primer = {'
331 PMA_escapeJsString($url),
332 json_encode($scripts),
333 PMA_escapeJsString($menuHash)
337 if (PMA_getenv('SCRIPT_NAME')
340 $url = $this->getSelfUrl();
341 $retval .= $this->_getSelfLink($url);
343 $this->_scripts
->addCode(
344 'var debugSQLInfo = ' . $this->getDebugMessage() . ';'
346 $retval .= $this->getErrorMessages();
347 $retval .= $this->_scripts
->getDisplay();
348 if ($GLOBALS['cfg']['DBG']['demo']) {
349 $retval .= '<div id="pma_demo">';
350 $retval .= $this->_getDemoMessage();
353 // Include possible custom footers
354 if (file_exists(CUSTOM_FOOTER_FILE
)) {
355 $retval .= '<div id="pma_footer">';
357 include CUSTOM_FOOTER_FILE
;
358 $retval .= ob_get_contents();
363 if (! $this->_isAjax
) {
364 $retval .= "</body></html>";