Translated using Weblate (Kurdish Sorani)
[phpmyadmin.git] / libraries / Footer.class.php
blob63755abfc2e41dabd58c0b76b8bbc9706d62b152
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 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/Scripts.class.php';
14 /**
15 * Class used to output the footer
17 * @package PhpMyAdmin
19 class PMA_Footer
21 /**
22 * PMA_Scripts instance
24 * @access private
25 * @var object
27 private $_scripts;
28 /**
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.
33 * @access private
34 * @var bool
36 private $_isAjax;
37 /**
38 * Whether to only close the BODY and HTML tags
39 * or also include scripts, errors and links
41 * @access private
42 * @var bool
44 private $_isMinimal;
45 /**
46 * Whether to display anything
48 * @access private
49 * @var bool
51 private $_isEnabled;
53 /**
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;
65 /**
66 * Adds the message for demo server to error messages
68 * @return string
70 private function _addDemoMessage()
72 $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: ';
73 if (file_exists('./revision-info.php')) {
74 include './revision-info.php';
75 $message .= sprintf(
76 __('Currently running Git revision %1$s from the %2$s branch.'),
77 '<a target="_blank" href="' . $repobase . $fullrevision . '">'
78 . $revision .'</a>',
79 '<a target="_blank" href="' . $repobranchbase . $branch . '">'
80 . $branch . '</a>'
82 } else {
83 $message .= __('Git information missing!');
86 $GLOBALS['error_handler']->addError(
87 $message,
88 E_USER_NOTICE,
89 '',
90 '',
91 false
95 /**
96 * Renders the debug messages
98 * @return string
100 private function _getDebugMessage()
102 $retval = '';
103 if (! empty($_SESSION['debug'])) {
104 $sum_time = 0;
105 $sum_exec = 0;
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';
114 $retval .= '<pre>';
116 ob_start();
117 print_r($_SESSION['debug']);
118 $retval .= ob_get_contents();
119 ob_end_clean();
121 $retval .= '</pre>';
122 $retval .= '</div>';
123 $_SESSION['debug'] = array();
125 return $retval;
129 * Returns the url of the current page
131 * @param mixed $encoding See PMA_URL_getCommon()
133 * @return string
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(
141 array(
142 'db' => $db,
143 'table' => $table,
144 'server' => $GLOBALS['server'],
145 'target' => $target
147 $encoding
152 * Renders the link to open a new page
154 * @param string $url The url of the page
156 * @return string
158 private function _getSelfLink($url)
160 $retval = '';
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(
166 'window-new.png',
167 __('Open new phpMyAdmin window')
169 } else {
170 $retval .= __('Open new phpMyAdmin window');
172 $retval .= '</a>';
173 $retval .= '</div>';
174 return $retval;
178 * Renders the link to open a new page
180 * @return string
182 public function getErrorMessages()
184 $retval = '';
185 if ($GLOBALS['error_handler']->hasDisplayErrors()) {
186 $retval .= '<div class="clearfloat" id="pma_errors">';
187 $retval .= $GLOBALS['error_handler']->getDispErrors();
188 $retval .= '</div>';
190 return $retval;
194 * Saves query in history
196 * @return void
198 private function _setHistory()
200 if (! PMA_isValid($_REQUEST['no_history'])
201 && empty($GLOBALS['error_message'])
202 && ! empty($GLOBALS['sql_query'])
204 PMA_setHistory(
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
216 * @return void
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
229 * @return void
231 public function setAjax($isAjax)
233 $this->_isAjax = ($isAjax == true);
237 * Turn on minimal display mode
239 * @return void
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;
257 * Renders the footer
259 * @return string
261 public function getDisplay()
263 $retval = '';
264 $this->_setHistory();
265 if ($this->_isEnabled) {
266 if (! $this->_isAjax) {
267 $retval .= "</div>";
269 if ($GLOBALS['cfg']['DBG']['demo']) {
270 $this->_addDemoMessage();
272 if (! $this->_isAjax && ! $this->_isMinimal) {
273 if (PMA_getenv('SCRIPT_NAME')
274 && empty($_POST)
275 && empty($GLOBALS['checked_special'])
276 && ! $this->_isAjax
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(
284 sprintf(
285 'AJAX.cache.primer = {'
286 . ' url: "%s",'
287 . ' scripts: %s,'
288 . ' menuHash: "%s"'
289 . '};',
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)) {
303 ob_start();
304 include CUSTOM_FOOTER_FILE;
305 $retval .= ob_get_contents();
306 ob_end_clean();
309 if (! $this->_isAjax) {
310 $retval .= "</body></html>";
314 return $retval;