2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Used to render the footer of PMA's pages
8 namespace PMA\libraries
;
11 use PMA\libraries\URL
;
12 use PMA\libraries\Sanitize
;
13 use PMA\libraries\Config
;
16 * Class used to output the footer
30 * Whether we are servicing an ajax request.
37 * Whether to only close the BODY and HTML tags
38 * or also include scripts, errors and links
45 * Whether to display anything
53 * Creates a new class instance
55 public function __construct()
57 $this->_isEnabled
= true;
58 $this->_scripts
= new Scripts();
59 $this->_isMinimal
= false;
63 * Returns the message for demo server to error messages
67 private function _getDemoMessage()
69 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
70 if (file_exists('./revision-info.php')) {
71 include './revision-info.php';
73 __('Currently running Git revision %1$s from the %2$s branch.'),
74 '<a target="_blank" rel="noopener noreferrer" href="' . $repobase . $fullrevision . '">'
76 '<a target="_blank" rel="noopener noreferrer" href="' . $repobranchbase . $branch . '">'
80 $message .= __('Git information missing!');
83 return Message
::notice($message)->getDisplay();
87 * Remove recursions and iterator objects from an object
89 * @param object|array &$object Object to clean
90 * @param array $stack Stack used to keep track of recursion,
91 * need not be passed for the first time
93 * @return object Reference passed object
95 private static function _removeRecursion(&$object, $stack = array())
97 if ((is_object($object) ||
is_array($object)) && $object) {
98 if ($object instanceof Traversable
) {
99 $object = "***ITERATOR***";
100 } else if (!in_array($object, $stack, true)) {
102 foreach ($object as &$subobject) {
103 self
::_removeRecursion($subobject, $stack);
106 $object = "***RECURSION***";
113 * Renders the debug messages
117 public function getDebugMessage()
119 $retval = '\'null\'';
120 if ($GLOBALS['cfg']['DBG']['sql']
121 && empty($_REQUEST['no_debug'])
122 && !empty($_SESSION['debug'])
124 // Remove recursions and iterators from $_SESSION['debug']
125 self
::_removeRecursion($_SESSION['debug']);
127 $retval = JSON_encode($_SESSION['debug']);
128 $_SESSION['debug'] = array();
129 return json_last_error() ?
'\'false\'' : $retval;
131 $_SESSION['debug'] = array();
136 * Returns the url of the current page
140 public function getSelfUrl()
142 $db = ! empty($GLOBALS['db']) ?
$GLOBALS['db'] : '';
143 $table = ! empty($GLOBALS['table']) ?
$GLOBALS['table'] : '';
144 $target = ! empty($_REQUEST['target']) ?
$_REQUEST['target'] : '';
148 'server' => $GLOBALS['server'],
151 // needed for server privileges tabs
152 if (isset($_REQUEST['viewing_mode'])
153 && in_array($_REQUEST['viewing_mode'], array('server', 'db', 'table'))
155 $params['viewing_mode'] = $_REQUEST['viewing_mode'];
158 * @todo coming from server_privileges.php, here $db is not set,
159 * add the following condition below when that is fixed
160 * && $_REQUEST['checkprivsdb'] == $db
162 if (isset($_REQUEST['checkprivsdb'])
164 $params['checkprivsdb'] = $_REQUEST['checkprivsdb'];
167 * @todo coming from server_privileges.php, here $table is not set,
168 * add the following condition below when that is fixed
169 * && $_REQUEST['checkprivstable'] == $table
171 if (isset($_REQUEST['checkprivstable'])
173 $params['checkprivstable'] = $_REQUEST['checkprivstable'];
175 if (isset($_REQUEST['single_table'])
176 && in_array($_REQUEST['single_table'], array(true, false))
178 $params['single_table'] = $_REQUEST['single_table'];
180 return basename(PMA_getenv('SCRIPT_NAME')) . URL
::getCommonRaw($params);
184 * Renders the link to open a new page
186 * @param string $url The url of the page
190 private function _getSelfLink($url)
193 $retval .= '<div id="selflink" class="print_ignore">';
194 $retval .= '<a href="' . htmlspecialchars($url) . '"'
195 . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank" rel="noopener noreferrer">';
196 if (Util
::showIcons('TabsMode')) {
197 $retval .= Util
::getImage(
199 __('Open new phpMyAdmin window')
202 $retval .= __('Open new phpMyAdmin window');
210 * Renders the link to open a new page
214 public function getErrorMessages()
217 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
218 $retval .= $GLOBALS['error_handler']->getDispErrors();
224 $GLOBALS['error_handler']->reportErrors();
230 * Saves query in history
234 private function _setHistory()
236 if (! PMA_isValid($_REQUEST['no_history'])
237 && empty($GLOBALS['error_message'])
238 && ! empty($GLOBALS['sql_query'])
239 && (isset($GLOBALS['dbi'])
240 && ($GLOBALS['dbi']->getLink()
241 ||
isset($GLOBALS['controllink'])
242 && $GLOBALS['controllink']))
245 PMA_ifSetOr($GLOBALS['db'], ''),
246 PMA_ifSetOr($GLOBALS['table'], ''),
247 $GLOBALS['cfg']['Server']['user'],
248 $GLOBALS['sql_query']
254 * Disables the rendering of the footer
258 public function disable()
260 $this->_isEnabled
= false;
264 * Set the ajax flag to indicate whether
265 * we are servicing an ajax request
267 * @param bool $isAjax Whether we are servicing an ajax request
271 public function setAjax($isAjax)
273 $this->_isAjax
= (boolean
) $isAjax;
277 * Turn on minimal display mode
281 public function setMinimal()
283 $this->_isMinimal
= true;
287 * Returns the Scripts object
289 * @return Scripts object
291 public function getScripts()
293 return $this->_scripts
;
301 public function getDisplay()
304 $this->_setHistory();
305 if ($this->_isEnabled
) {
306 if (! $this->_isAjax
) {
309 if (! $this->_isAjax
&& ! $this->_isMinimal
) {
310 if (PMA_getenv('SCRIPT_NAME')
312 && empty($GLOBALS['checked_special'])
315 $url = $this->getSelfUrl();
316 $header = Response
::getInstance()->getHeader();
317 $scripts = $header->getScripts()->getFiles();
318 $menuHash = $header->getMenu()->getHash();
319 // prime the client-side cache
320 $this->_scripts
->addCode(
322 'if (! (history && history.pushState)) '
323 . 'PMA_MicroHistory.primer = {'
328 Sanitize
::escapeJsString($url),
329 json_encode($scripts),
330 Sanitize
::escapeJsString($menuHash)
334 if (PMA_getenv('SCRIPT_NAME')
337 $url = $this->getSelfUrl();
338 $retval .= $this->_getSelfLink($url);
340 $this->_scripts
->addCode(
341 'var debugSQLInfo = ' . $this->getDebugMessage() . ';'
343 $retval .= '<div class="clearfloat" id="pma_errors">';
344 $retval .= $this->getErrorMessages();
346 $retval .= $this->_scripts
->getDisplay();
347 if ($GLOBALS['cfg']['DBG']['demo']) {
348 $retval .= '<div id="pma_demo">';
349 $retval .= $this->_getDemoMessage();
353 $retval .= Config
::renderFooter();
355 if (! $this->_isAjax
) {
356 $retval .= "</body></html>";