NavigationHeader.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. $logoLink .= Url::getCommon();
  127. } else {
  128. $linkAttriks = 'target="_blank" rel="noopener noreferrer"';
  129. }
  130. }
  131. return Template::get('navigation/logo')->render([
  132. 'display_logo' => true,
  133. 'use_logo_link' => $useLogoLink,
  134. 'logo_link' => $logoLink,
  135. 'link_attribs' => $linkAttriks,
  136. 'logo' => $logo,
  137. ]);
  138. }
  139. /**
  140. * Creates the code for displaying the links
  141. * at the top of the navigation panel
  142. *
  143. * @return string HTML code for the links
  144. */
  145. private function _links()
  146. {
  147. // always iconic
  148. $showIcon = true;
  149. $showText = false;
  150. $retval = '<!-- LINKS START -->';
  151. $retval .= '<div id="navipanellinks">';
  152. $retval .= Util::getNavigationLink(
  153. 'index.php' . Url::getCommon(),
  154. $showText,
  155. __('Home'),
  156. $showIcon,
  157. 'b_home'
  158. );
  159. // if we have chosen server
  160. if ($GLOBALS['server'] != 0) {
  161. // Logout for advanced authentication
  162. if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
  163. $text = __('Log out');
  164. } else {
  165. $text = __('Empty session data');
  166. }
  167. $link = 'logout.php' . $GLOBALS['url_query'];
  168. $retval .= Util::getNavigationLink(
  169. $link,
  170. $showText,
  171. $text,
  172. $showIcon,
  173. 's_loggoff',
  174. '',
  175. true,
  176. '',
  177. array('logout')
  178. );
  179. }
  180. $retval .= Util::getNavigationLink(
  181. Util::getDocuLink('index'),
  182. $showText,
  183. __('phpMyAdmin documentation'),
  184. $showIcon,
  185. 'b_docs',
  186. '',
  187. false,
  188. 'documentation'
  189. );
  190. $retval .= Util::getNavigationLink(
  191. Util::getMySQLDocuURL('', ''),
  192. $showText,
  193. __('Documentation'),
  194. $showIcon,
  195. 'b_sqlhelp',
  196. '',
  197. false,
  198. 'mysql_doc'
  199. );
  200. $retval .= Util::getNavigationLink(
  201. '#',
  202. $showText,
  203. __('Navigation panel settings'),
  204. $showIcon,
  205. 's_cog',
  206. 'pma_navigation_settings_icon',
  207. false,
  208. '',
  209. defined('PMA_DISABLE_NAVI_SETTINGS') ? array('hide') : array()
  210. );
  211. $retval .= Util::getNavigationLink(
  212. '#',
  213. $showText,
  214. __('Reload navigation panel'),
  215. $showIcon,
  216. 's_reload',
  217. 'pma_navigation_reload'
  218. );
  219. $retval .= '</div>';
  220. $retval .= '<!-- LINKS ENDS -->';
  221. return $retval;
  222. }
  223. /**
  224. * Displays the MySQL servers choice form
  225. *
  226. * @return string HTML code for the MySQL servers choice
  227. */
  228. private function _serverChoice()
  229. {
  230. $retval = '';
  231. if ($GLOBALS['cfg']['NavigationDisplayServers']
  232. && count($GLOBALS['cfg']['Servers']) > 1
  233. ) {
  234. $retval .= '<!-- SERVER CHOICE START -->';
  235. $retval .= '<div id="serverChoice">';
  236. $retval .= Select::render(true, true);
  237. $retval .= '</div>';
  238. $retval .= '<!-- SERVER CHOICE END -->';
  239. }
  240. return $retval;
  241. }
  242. }