Translated using Weblate (Ukrainian)
[phpmyadmin.git] / libraries / Footer.php
blob6bd0027ffb1ae4d0d2030aad0861d6603d102f52
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Used to render the footer of PMA's pages
6 * @package PhpMyAdmin
7 */
8 namespace PMA\libraries;
10 use Traversable;
11 use PMA\libraries\URL;
12 use PMA\libraries\Sanitize;
13 use PMA\libraries\Config;
15 /**
16 * Class used to output the footer
18 * @package PhpMyAdmin
20 class Footer
22 /**
23 * Scripts instance
25 * @access private
26 * @var Scripts
28 private $_scripts;
29 /**
30 * Whether we are servicing an ajax request.
32 * @access private
33 * @var bool
35 private $_isAjax;
36 /**
37 * Whether to only close the BODY and HTML tags
38 * or also include scripts, errors and links
40 * @access private
41 * @var bool
43 private $_isMinimal;
44 /**
45 * Whether to display anything
47 * @access private
48 * @var bool
50 private $_isEnabled;
52 /**
53 * Creates a new class instance
55 public function __construct()
57 $this->_isEnabled = true;
58 $this->_scripts = new Scripts();
59 $this->_isMinimal = false;
62 /**
63 * Returns the message for demo server to error messages
65 * @return string
67 private function _getDemoMessage()
69 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
70 if (@file_exists('./revision-info.php')) {
71 include './revision-info.php';
72 $message .= sprintf(
73 __('Currently running Git revision %1$s from the %2$s branch.'),
74 '<a target="_blank" rel="noopener noreferrer" href="' . $repobase . $fullrevision . '">'
75 . $revision . '</a>',
76 '<a target="_blank" rel="noopener noreferrer" href="' . $repobranchbase . $branch . '">'
77 . $branch . '</a>'
79 } else {
80 $message .= __('Git information missing!');
83 return Message::notice($message)->getDisplay();
86 /**
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)) {
101 $stack[] = $object;
102 foreach ($object as &$subobject) {
103 self::_removeRecursion($subobject, $stack);
105 } else {
106 $object = "***RECURSION***";
109 return $object;
113 * Renders the debug messages
115 * @return string
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();
132 return $retval;
136 * Returns the url of the current page
138 * @return string
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'] : '';
145 $params = array(
146 'db' => $db,
147 'table' => $table,
148 'server' => $GLOBALS['server'],
149 'target' => $target
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
188 * @return string
190 private function _getSelfLink($url)
192 $retval = '';
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(
198 'window-new.png',
199 __('Open new phpMyAdmin window')
201 } else {
202 $retval .= __('Open new phpMyAdmin window');
204 $retval .= '</a>';
205 $retval .= '</div>';
206 return $retval;
210 * Renders the link to open a new page
212 * @return string
214 public function getErrorMessages()
216 $retval = '';
217 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
218 $retval .= $GLOBALS['error_handler']->getDispErrors();
222 * Report php errors
224 $GLOBALS['error_handler']->reportErrors();
226 return $retval;
230 * Saves query in history
232 * @return void
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']))
244 PMA_setHistory(
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
256 * @return void
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
269 * @return void
271 public function setAjax($isAjax)
273 $this->_isAjax = (boolean) $isAjax;
277 * Turn on minimal display mode
279 * @return void
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;
297 * Renders the footer
299 * @return string
301 public function getDisplay()
303 $retval = '';
304 $this->_setHistory();
305 if ($this->_isEnabled) {
306 if (! $this->_isAjax) {
307 $retval .= "</div>";
309 if (! $this->_isAjax && ! $this->_isMinimal) {
310 if (PMA_getenv('SCRIPT_NAME')
311 && empty($_POST)
312 && empty($GLOBALS['checked_special'])
313 && ! $this->_isAjax
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(
321 sprintf(
322 'if (! (history && history.pushState)) '
323 . 'PMA_MicroHistory.primer = {'
324 . ' url: "%s",'
325 . ' scripts: %s,'
326 . ' menuHash: "%s"'
327 . '};',
328 Sanitize::escapeJsString($url),
329 json_encode($scripts),
330 Sanitize::escapeJsString($menuHash)
334 if (PMA_getenv('SCRIPT_NAME')
335 && ! $this->_isAjax
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();
345 $retval .= '</div>';
346 $retval .= $this->_scripts->getDisplay();
347 if ($GLOBALS['cfg']['DBG']['demo']) {
348 $retval .= '<div id="pma_demo">';
349 $retval .= $this->_getDemoMessage();
350 $retval .= '</div>';
353 $retval .= Config::renderFooter();
355 if (! $this->_isAjax) {
356 $retval .= "</body></html>";
360 return $retval;