_isAjax = false; if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $this->_isAjax = true; } $this->_bodyId = ''; $this->_title = 'phpMyAdmin'; $this->_menu = new PMA_Menu( $GLOBALS['server'], $GLOBALS['db'], $GLOBALS['table'] ); $this->_menuEnabled = true; $this->_isPrintView = false; $this->_scripts = new PMA_Scripts(); $this->_addDefaultScripts(); self::$headerIsSent = false; // if database storage for user preferences is transient, // offer to load exported settings from localStorage // (detection will be done in JavaScript) $this->_userprefsOfferImport = false; if ($GLOBALS['PMA_Config']->get('user_preferences') == 'session' && ! isset($_SESSION['userprefs_autoload']) ) { $this->_userprefsOfferImport = true; } } /** * Loads common scripts * * @return void */ private function _addDefaultScripts() { $this->_scripts->addFile('jquery/jquery-1.6.2.js'); $this->_scripts->addFile('jquery/jquery-ui-1.8.16.custom.js'); $this->_scripts->addFile('jquery/jquery.sprintf.js'); $this->_scripts->addFile('update-location.js'); $this->_scripts->addFile('jquery/jquery.qtip-1.0.0-rc3.js'); if ($GLOBALS['cfg']['CodemirrorEnable']) { $this->_scripts->addFile('codemirror/lib/codemirror.js'); $this->_scripts->addFile('codemirror/mode/mysql/mysql.js'); } // Cross-framing protection if ($GLOBALS['cfg']['AllowThirdPartyFraming'] === false) { $this->_scripts->addFile('cross_framing_protection.js'); } // Localised strings $params = array('lang' => $GLOBALS['lang']); if (isset($GLOBALS['db'])) { $params['db'] = $GLOBALS['db']; } $this->_scripts->addFile('messages.php' . PMA_generate_common_url($params)); // Append the theme id to this url to invalidate // the cache on a theme change $this->_scripts->addFile( 'get_image.js.php?theme=' . urlencode($_SESSION['PMA_Theme']->getId()) ); $this->_scripts->addFile('functions.js'); // generate title (unless we already have // $GLOBALS['page_title'], from cookie auth) if (! isset($GLOBALS['page_title'])) { if ($GLOBALS['server'] > 0) { if (! empty($GLOBALS['table'])) { $temp_title = $GLOBALS['cfg']['TitleTable']; } else if (! empty($GLOBALS['db'])) { $temp_title = $GLOBALS['cfg']['TitleDatabase']; } elseif (! empty($GLOBALS['cfg']['Server']['host'])) { $temp_title = $GLOBALS['cfg']['TitleServer']; } else { $temp_title = $GLOBALS['cfg']['TitleDefault']; } $title = PMA_expandUserString($temp_title); } } else { $title = $GLOBALS['page_title']; } if (isset($title)) { $title = PMA_sanitize( PMA_escapeJsString($title), false, true ); $this->_scripts->addCode( "if (typeof(parent.document) != 'undefined'" . " && typeof(parent.document) != 'unknown'" . " && typeof(parent.document.title) == 'string')" . "{" . "parent.document.title = '$title'" . "}" ); } $this->_scripts->addCode(PMA_getReloadNavigationScript(true)); } /** * Returns the singleton PMA_Header object * * @return PMA_Header object */ public static function getInstance() { if (empty(self::$_instance)) { self::$_instance = new PMA_Header(); } return self::$_instance; } /** * Returns the PMA_Scripts object * * @return PMA_Scripts object */ public function getScripts() { return $this->_scripts; } /** * Setter for the ID attribute in the BODY tag * * @param string $id Value for the ID attribute * * @return void */ public function setBodyId($id) { $this->_bodyId = htmlspecialchars($id); } /** * Setter for the title of the page * * @param string $title New title * * @return void */ public function setTitle($title) { $this->_title = htmlspecialchars($title); } /** * Disables the display of the top menu * * @return void */ public function disableMenu() { $this->_menuEnabled = false; } /** * Turns on 'print view' mode * * @return void */ public function enablePrintView() { $this->disableMenu(); $this->setTitle(__('Print view') . ' - phpMyAdmin ' . PMA_VERSION); $this->_isPrintView = true; } /** * Generates and outputs the header * * @return void */ public function display() { echo $this->getDisplay(); } /** * Generates the header * * @return string The header */ public function getDisplay() { $retval = ''; if (! self::$headerIsSent) { $this->sendHttpHeaders(); if ($this->_isAjax === false) { $retval .= $this->_getHtmlStart(); $retval .= $this->_getMetaTags(); $retval .= $this->_getLinkTags(); $retval .= $this->_getTitleTag(); if ($this->_userprefsOfferImport) { $this->_scripts->addFile('config.js'); } $retval .= $this->_scripts->getDisplay(); $retval .= $this->_getBodyStart(); // Include possible custom headers if (file_exists(CUSTOM_HEADER_FILE)) { ob_start(); include CUSTOM_HEADER_FILE; $retval .= ob_end_clean(); } // offer to load user preferences from localStorage if ($this->_userprefsOfferImport) { include_once './libraries/user_preferences.lib.php'; $retval .= PMA_userprefsAutoloadGetHeader(); } // pass configuration for hint tooltip display // (to be used by PMA_createqTip in js/functions.js) if (! $GLOBALS['cfg']['ShowHint']) { $retval .= ''; } $retval .= $this->_getWarnings(); if ($this->_menuEnabled && $GLOBALS['server'] > 0) { $retval .= $this->_menu->getDisplay(); } $retval .= $this->_addRecentTable( $GLOBALS['db'], $GLOBALS['table'] ); } } return $retval; } /** * Sends out the HTTP headers * * @return void */ public function sendHttpHeaders() { /** * Starts output buffering work */ PMA_outBufferPre(); /** * Sends http headers */ $GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT'; /* Prevent against ClickJacking by allowing frames only from same origin */ if (! $GLOBALS['cfg']['AllowThirdPartyFraming']) { header( 'X-Frame-Options: SAMEORIGIN' ); header( "X-Content-Security-Policy: allow 'self'; " . "options inline-script eval-script; " . "frame-ancestors 'self'; img-src 'self' data:; " . "script-src 'self' http://www.phpmyadmin.net" ); header( "X-WebKit-CSP: allow 'self' http://www.phpmyadmin.net; " . "options inline-script eval-script" ); } PMA_noCacheHeader(); if (! defined('IS_TRANSFORMATION_WRAPPER')) { // Define the charset to be used header('Content-Type: text/html; charset=utf-8'); } self::$headerIsSent = true; } /** * Returns the DOCTYPE and the start HTML tag * * @return string DOCTYPE and HTML tags */ private function _getHtmlStart() { $lang = $GLOBALS['available_languages'][$GLOBALS['lang']][1]; $dir = $GLOBALS['text_dir']; $retval = ""; $retval .= ""; return $retval; } /** * Returns the META tags * * @return string the META tags */ private function _getMetaTags() { $retval = ''; $retval .= ''; return $retval; } /** * Returns the LINK tags for the favicon and the stylesheets * * @return string the LINK tags */ private function _getLinkTags() { $retval = '' . ''; // stylesheets $basedir = defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : ''; $common_url = PMA_generate_common_url(array('server' => $GLOBALS['server'])); $theme_id = $GLOBALS['PMA_Config']->getThemeUniqueValue(); $theme_path = $GLOBALS['pmaThemePath']; if ($this->_isPrintView) { $retval .= ''; } else { $retval .= ''; $retval .= ''; } return $retval; } /** * Returns the TITLE tag * * @return string the TITLE tag */ private function _getTitleTag() { $retval = "