MySQLDocumentation.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Generate HTML for MySQL Documentation
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Html;
  7. use PhpMyAdmin\Core;
  8. use PhpMyAdmin\Util;
  9. use function defined;
  10. use function file_exists;
  11. use function htmlspecialchars;
  12. /**
  13. * Generate HTML for MySQL Documentation
  14. */
  15. class MySQLDocumentation
  16. {
  17. /**
  18. * Displays a link to the official MySQL documentation
  19. *
  20. * @param string $link contains name of page/anchor that is being linked
  21. * @param bool $bigIcon whether to use big icon (like in left frame)
  22. * @param string|null $url href attribute
  23. * @param string|null $text text of link
  24. * @param string $anchor anchor to page part
  25. *
  26. * @return string the html link
  27. *
  28. * @access public
  29. */
  30. public static function show(
  31. $link,
  32. bool $bigIcon = false,
  33. $url = null,
  34. $text = null,
  35. $anchor = ''
  36. ): string {
  37. if ($url === null) {
  38. $url = Util::getMySQLDocuURL($link, $anchor);
  39. }
  40. $openLink = '<a href="' . htmlspecialchars($url) . '" target="mysql_doc">';
  41. $closeLink = '</a>';
  42. if ($bigIcon) {
  43. $html = $openLink .
  44. Generator::getImage('b_sqlhelp', __('Documentation'))
  45. . $closeLink;
  46. } elseif ($text !== null) {
  47. $html = $openLink . $text . $closeLink;
  48. } else {
  49. $html = Generator::showDocumentationLink($url, 'mysql_doc');
  50. }
  51. return $html;
  52. }
  53. /**
  54. * Displays a link to the phpMyAdmin documentation
  55. *
  56. * @param string $page Page in documentation
  57. * @param string $anchor Optional anchor in page
  58. * @param bool $bbcode Optional flag indicating whether to output bbcode
  59. *
  60. * @return string the html link
  61. *
  62. * @access public
  63. */
  64. public static function showDocumentation($page, $anchor = '', $bbcode = false): string
  65. {
  66. return Generator::showDocumentationLink(self::getDocumentationLink($page, $anchor), 'documentation', $bbcode);
  67. }
  68. /**
  69. * Returns link to documentation.
  70. *
  71. * @param string $page Page in documentation
  72. * @param string $anchor Optional anchor in page
  73. * @param string $pathPrefix Optional path in case it is called in a folder (e.g. setup)
  74. *
  75. * @return string URL
  76. */
  77. public static function getDocumentationLink($page, $anchor = '', string $pathPrefix = './'): string
  78. {
  79. /* Construct base URL */
  80. $url = $page . '.html';
  81. if (! empty($anchor)) {
  82. $url .= '#' . $anchor;
  83. }
  84. /* Check if we have built local documentation, however
  85. * provide consistent URL for testsuite
  86. */
  87. if (! defined('TESTSUITE') && @file_exists(ROOT_PATH . 'doc/html/index.html')) {
  88. return $pathPrefix . 'doc/html/' . $url;
  89. }
  90. return Core::linkURL('https://docs.phpmyadmin.net/en/latest/' . $url);
  91. }
  92. }