NavigationHeader.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * This class renders the logo, links, server selection,
  13. * which are then displayed at the top of the naviagtion panel
  14. *
  15. * @package PhpMyAdmin-Navigation
  16. */
  17. class PMA_NavigationHeader
  18. {
  19. /**
  20. * Renders the navigation
  21. *
  22. * @return String HTML
  23. */
  24. public function getDisplay()
  25. {
  26. if (empty($GLOBALS['url_query'])) {
  27. $GLOBALS['url_query'] = PMA_URL_getCommon();
  28. }
  29. $link_url = PMA_URL_getCommon(
  30. array(
  31. 'ajax_request' => true
  32. )
  33. );
  34. $class = ' class="list_container';
  35. if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
  36. $class .= ' highlight';
  37. }
  38. $class .= '"';
  39. $buffer = '<div id="pma_navigation">';
  40. $buffer .= '<div id="pma_navigation_resizer"></div>';
  41. $buffer .= '<div id="pma_navigation_collapser"></div>';
  42. $buffer .= '<div id="pma_navigation_content">';
  43. $buffer .= '<div id="pma_navigation_header">';
  44. $buffer .= sprintf(
  45. '<a class="hide navigation_url" href="navigation.php%s"></a>',
  46. $link_url
  47. );
  48. $buffer .= $this->_logo();
  49. $buffer .= $this->_links();
  50. $buffer .= $this->_serverChoice();
  51. $buffer .= PMA_Util::getImage(
  52. 'ajax_clock_small.gif',
  53. __('Loading…'),
  54. array(
  55. 'style' => 'visibility: hidden; display:none',
  56. 'class' => 'throbber'
  57. )
  58. );
  59. $buffer .= '</div>'; // pma_navigation_header
  60. $buffer .= '<div id="pma_navigation_tree"' . $class . '>';
  61. return $buffer;
  62. }
  63. /**
  64. * Create the code for displaying the phpMyAdmin
  65. * logo based on configuration settings
  66. *
  67. * @return string HTML code for the logo
  68. */
  69. private function _logo()
  70. {
  71. $retval = '<!-- LOGO START -->';
  72. // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
  73. if ($GLOBALS['cfg']['NavigationDisplayLogo']) {
  74. $logo = 'phpMyAdmin';
  75. if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
  76. $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" '
  77. . 'alt="' . $logo . '" id="imgpmalogo" />';
  78. } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
  79. $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" '
  80. . 'alt="' . $logo . '" id="imgpmalogo" />';
  81. }
  82. $retval .= '<div id="pmalogo">';
  83. if ($GLOBALS['cfg']['NavigationLogoLink']) {
  84. $logo_link = trim(
  85. htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink'])
  86. );
  87. // prevent XSS, see PMASA-2013-9
  88. // if link has protocol, allow only http and https
  89. if (preg_match('/^[a-z]+:/i', $logo_link)
  90. && ! preg_match('/^https?:/i', $logo_link)
  91. ) {
  92. $logo_link = 'index.php';
  93. }
  94. $retval .= ' <a href="' . $logo_link;
  95. switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
  96. case 'new':
  97. $retval .= '" target="_blank"';
  98. break;
  99. case 'main':
  100. // do not add our parameters for an external link
  101. if (substr(
  102. strtolower($GLOBALS['cfg']['NavigationLogoLink']), 0, 4
  103. ) !== '://') {
  104. $retval .= '?' . $GLOBALS['url_query'] . '"';
  105. } else {
  106. $retval .= '" target="_blank"';
  107. }
  108. }
  109. $retval .= '>';
  110. $retval .= $logo;
  111. $retval .= '</a>';
  112. } else {
  113. $retval .= $logo;
  114. }
  115. $retval .= '</div>';
  116. }
  117. $retval .= '<!-- LOGO END -->';
  118. return $retval;
  119. }
  120. /**
  121. * Renders a single link for the top of the navigation panel
  122. *
  123. * @param string $link The url for the link
  124. * @param bool $showText Whether to show the text or to
  125. * only use it for title attributes
  126. * @param string $text The text to display and use for title attributes
  127. * @param bool $showIcon Whether to show the icon
  128. * @param string $icon The filename of the icon to show
  129. * @param string $linkId Value to use for the ID attribute
  130. * @param boolean $disableAjax Whether to disable ajax page loading for this link
  131. * @param string $linkTarget The name of the target frame for the link
  132. *
  133. * @return string HTML code for one link
  134. */
  135. private function _getLink(
  136. $link,
  137. $showText,
  138. $text,
  139. $showIcon,
  140. $icon,
  141. $linkId = '',
  142. $disableAjax = false,
  143. $linkTarget = ''
  144. ) {
  145. $retval = '<a href="' . $link . '"';
  146. if (! empty($linkId)) {
  147. $retval .= ' id="' . $linkId . '"';
  148. }
  149. if (! empty($linkTarget)) {
  150. $retval .= ' target="' . $linkTarget . '"';
  151. }
  152. if ($disableAjax) {
  153. $retval .= ' class="disableAjax"';
  154. }
  155. $retval .= ' title="' . $text . '">';
  156. if ($showIcon) {
  157. $retval .= PMA_Util::getImage(
  158. $icon,
  159. $text
  160. );
  161. }
  162. if ($showText) {
  163. $retval .= $text;
  164. }
  165. $retval .= '</a>';
  166. if ($showText) {
  167. $retval .= '<br />';
  168. }
  169. return $retval;
  170. }
  171. /**
  172. * Creates the code for displaying the links
  173. * at the top of the navigation panel
  174. *
  175. * @return string HTML code for the links
  176. */
  177. private function _links()
  178. {
  179. // always iconic
  180. $showIcon = true;
  181. $showText = false;
  182. $retval = '<!-- LINKS START -->';
  183. $retval .= '<div id="navipanellinks">';
  184. $retval .= $this->_getLink(
  185. 'index.php?' . PMA_URL_getCommon(),
  186. $showText,
  187. __('Home'),
  188. $showIcon,
  189. 'b_home.png'
  190. );
  191. // if we have chosen server
  192. if ($GLOBALS['server'] != 0) {
  193. // Logout for advanced authentication
  194. if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
  195. $link = 'index.php?' . $GLOBALS['url_query'];
  196. $link .= '&amp;old_usr=' . urlencode($GLOBALS['PHP_AUTH_USER']);
  197. $retval .= $this->_getLink(
  198. $link,
  199. $showText,
  200. __('Log out'),
  201. $showIcon,
  202. 's_loggoff.png',
  203. '',
  204. true
  205. );
  206. }
  207. $link = 'querywindow.php?';
  208. $link .= PMA_URL_getCommon($GLOBALS['db'], $GLOBALS['table']);
  209. $link .= '&amp;no_js=true';
  210. $retval .= $this->_getLink(
  211. $link,
  212. $showText,
  213. __('Query window'),
  214. $showIcon,
  215. 'b_selboard.png',
  216. 'pma_open_querywindow',
  217. true
  218. );
  219. }
  220. $retval .= $this->_getLink(
  221. PMA_Util::getDocuLink('index'),
  222. $showText,
  223. __('phpMyAdmin documentation'),
  224. $showIcon,
  225. 'b_docs.png',
  226. '',
  227. false,
  228. 'documentation'
  229. );
  230. if ($showIcon) {
  231. $retval .= PMA_Util::showMySQLDocu('', true);
  232. }
  233. if ($showText) {
  234. // PMA_showMySQLDocu always spits out an icon,
  235. // we just replace it with some perl regexp.
  236. $link = preg_replace(
  237. '/<img[^>]+>/i',
  238. __('Documentation'),
  239. PMA_Util::showMySQLDocu('', true)
  240. );
  241. $retval .= $link;
  242. $retval .= '<br />';
  243. }
  244. $retval .= $this->_getLink(
  245. '#',
  246. $showText,
  247. __('Reload navigation panel'),
  248. $showIcon,
  249. 's_reload.png',
  250. 'pma_navigation_reload'
  251. );
  252. $retval .= '</div>';
  253. $retval .= '<!-- LINKS ENDS -->';
  254. return $retval;
  255. }
  256. /**
  257. * Displays the MySQL servers choice form
  258. *
  259. * @return string HTML code for the MySQL servers choice
  260. */
  261. private function _serverChoice()
  262. {
  263. $retval = '';
  264. if ($GLOBALS['cfg']['NavigationDisplayServers']
  265. && count($GLOBALS['cfg']['Servers']) > 1
  266. ) {
  267. include_once './libraries/select_server.lib.php';
  268. $retval .= '<!-- SERVER CHOICE START -->';
  269. $retval .= '<div id="serverChoice">';
  270. $retval .= PMA_selectServer(true, true);
  271. $retval .= '</div>';
  272. $retval .= '<!-- SERVER CHOICE END -->';
  273. }
  274. return $retval;
  275. }
  276. }
  277. ?>