NavigationHeader.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Header for the navigation panel
  5. *
  6. * @package PhpMyAdmin-Navigation
  7. */
  8. namespace PhpMyAdmin\Navigation;
  9. use PhpMyAdmin\Sanitize;
  10. use PhpMyAdmin\Server\Select;
  11. use PhpMyAdmin\Template;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\Util;
  14. /**
  15. * This class renders the logo, links, server selection,
  16. * which are then displayed at the top of the navigation panel
  17. *
  18. * @package PhpMyAdmin-Navigation
  19. */
  20. class NavigationHeader
  21. {
  22. /**
  23. * Renders the navigation
  24. *
  25. * @return String HTML
  26. */
  27. public function getDisplay()
  28. {
  29. if (empty($GLOBALS['url_query'])) {
  30. $GLOBALS['url_query'] = Url::getCommon();
  31. }
  32. $link_url = Url::getCommon(
  33. array(
  34. 'ajax_request' => true,
  35. )
  36. );
  37. $class = ' class="list_container';
  38. if ($GLOBALS['cfg']['NavigationLinkWithMainPanel']) {
  39. $class .= ' synced';
  40. }
  41. if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
  42. $class .= ' highlight';
  43. }
  44. $class .= '"';
  45. $buffer = '<div id="pma_navigation">';
  46. $buffer .= '<div id="pma_navigation_resizer"></div>';
  47. $buffer .= '<div id="pma_navigation_collapser"></div>';
  48. $buffer .= '<div id="pma_navigation_content">';
  49. $buffer .= '<div id="pma_navigation_header">';
  50. $buffer .= sprintf(
  51. '<a class="hide navigation_url" href="navigation.php%s"></a>',
  52. $link_url
  53. );
  54. $buffer .= $this->_logo();
  55. $buffer .= $this->_links();
  56. $buffer .= $this->_serverChoice();
  57. $buffer .= Util::getImage(
  58. 'ajax_clock_small',
  59. __('Loading…'),
  60. array(
  61. 'style' => 'visibility: hidden; display:none',
  62. 'class' => 'throbber',
  63. )
  64. );
  65. $buffer .= '</div>'; // pma_navigation_header
  66. $buffer .= '<div id="pma_navigation_tree"' . $class . '>';
  67. return $buffer;
  68. }
  69. /**
  70. * Create the code for displaying the phpMyAdmin
  71. * logo based on configuration settings
  72. *
  73. * @return string HTML code for the logo
  74. */
  75. private function _logo()
  76. {
  77. $logo = 'phpMyAdmin';
  78. if (isset($GLOBALS['pmaThemeImage'])) {
  79. $imgTag = '<img src="%s%s" ' . 'alt="' . $logo . '" id="imgpmalogo" />';
  80. if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
  81. $logo = sprintf($imgTag, $GLOBALS['pmaThemeImage'], 'logo_left.png');
  82. } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
  83. $logo = sprintf($imgTag, $GLOBALS['pmaThemeImage'], 'pma_logo2.png');
  84. }
  85. }
  86. // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
  87. if (!$GLOBALS['cfg']['NavigationDisplayLogo']) {
  88. return Template::get('navigation/logo')->render([
  89. 'display_logo' => false,
  90. 'use_logo_link' => false,
  91. 'logo_link' => null,
  92. 'link_attribs' => null,
  93. 'logo' => $logo,
  94. ]);
  95. }
  96. if (!$GLOBALS['cfg']['NavigationLogoLink']) {
  97. return Template::get('navigation/logo')->render([
  98. 'display_logo' => true,
  99. 'use_logo_link' => false,
  100. 'logo_link' => null,
  101. 'link_attribs' => null,
  102. 'logo' => $logo,
  103. ]);
  104. }
  105. $useLogoLink = true;
  106. $linkAttriks = null;
  107. $logoLink = trim(
  108. htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink'])
  109. );
  110. // prevent XSS, see PMASA-2013-9
  111. // if link has protocol, allow only http and https
  112. if (! Sanitize::checkLink($logoLink, true)) {
  113. $logoLink = 'index.php';
  114. }
  115. switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
  116. case 'new':
  117. $linkAttriks = 'target="_blank" rel="noopener noreferrer"';
  118. break;
  119. case 'main':
  120. // do not add our parameters for an external link
  121. $host = parse_url(
  122. $GLOBALS['cfg']['NavigationLogoLink'],
  123. PHP_URL_HOST
  124. );
  125. if (empty($host)) {
  126. $hasStartChar = strpos($logoLink, '?');
  127. $logoLink .= Url::getCommon(
  128. array(),
  129. is_bool($hasStartChar) ? '?' : Url::getArgSeparator()
  130. );
  131. } else {
  132. $linkAttriks = 'target="_blank" rel="noopener noreferrer"';
  133. }
  134. }
  135. return Template::get('navigation/logo')->render([
  136. 'display_logo' => true,
  137. 'use_logo_link' => $useLogoLink,
  138. 'logo_link' => $logoLink,
  139. 'link_attribs' => $linkAttriks,
  140. 'logo' => $logo,
  141. ]);
  142. }
  143. /**
  144. * Creates the code for displaying the links
  145. * at the top of the navigation panel
  146. *
  147. * @return string HTML code for the links
  148. */
  149. private function _links()
  150. {
  151. // always iconic
  152. $showIcon = true;
  153. $showText = false;
  154. $retval = '<!-- LINKS START -->';
  155. $retval .= '<div id="navipanellinks">';
  156. $retval .= Util::getNavigationLink(
  157. 'index.php' . Url::getCommon(),
  158. $showText,
  159. __('Home'),
  160. $showIcon,
  161. 'b_home'
  162. );
  163. // if we have chosen server
  164. if ($GLOBALS['server'] != 0) {
  165. // Logout for advanced authentication
  166. if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
  167. $text = __('Log out');
  168. } else {
  169. $text = __('Empty session data');
  170. }
  171. $link = 'logout.php' . $GLOBALS['url_query'];
  172. $retval .= Util::getNavigationLink(
  173. $link,
  174. $showText,
  175. $text,
  176. $showIcon,
  177. 's_loggoff',
  178. '',
  179. true,
  180. '',
  181. array('logout')
  182. );
  183. }
  184. $retval .= Util::getNavigationLink(
  185. Util::getDocuLink('index'),
  186. $showText,
  187. __('phpMyAdmin documentation'),
  188. $showIcon,
  189. 'b_docs',
  190. '',
  191. false,
  192. 'documentation'
  193. );
  194. $retval .= Util::getNavigationLink(
  195. Util::getMySQLDocuURL('', ''),
  196. $showText,
  197. __('Documentation'),
  198. $showIcon,
  199. 'b_sqlhelp',
  200. '',
  201. false,
  202. 'mysql_doc'
  203. );
  204. $retval .= Util::getNavigationLink(
  205. '#',
  206. $showText,
  207. __('Navigation panel settings'),
  208. $showIcon,
  209. 's_cog',
  210. 'pma_navigation_settings_icon',
  211. false,
  212. '',
  213. defined('PMA_DISABLE_NAVI_SETTINGS') ? array('hide') : array()
  214. );
  215. $retval .= Util::getNavigationLink(
  216. '#',
  217. $showText,
  218. __('Reload navigation panel'),
  219. $showIcon,
  220. 's_reload',
  221. 'pma_navigation_reload'
  222. );
  223. $retval .= '</div>';
  224. $retval .= '<!-- LINKS ENDS -->';
  225. return $retval;
  226. }
  227. /**
  228. * Displays the MySQL servers choice form
  229. *
  230. * @return string HTML code for the MySQL servers choice
  231. */
  232. private function _serverChoice()
  233. {
  234. $retval = '';
  235. if ($GLOBALS['cfg']['NavigationDisplayServers']
  236. && count($GLOBALS['cfg']['Servers']) > 1
  237. ) {
  238. $retval .= '<!-- SERVER CHOICE START -->';
  239. $retval .= '<div id="serverChoice">';
  240. $retval .= Select::render(true, true);
  241. $retval .= '</div>';
  242. $retval .= '<!-- SERVER CHOICE END -->';
  243. }
  244. return $retval;
  245. }
  246. }