PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/classes/Controllers/ChangeLogController.php

http://github.com/phpmyadmin/phpmyadmin
PHP | 105 lines | 64 code | 22 blank | 19 comment | 3 complexity | 56d186fff93e72492255bc51189ee077 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. <?php
  2. /**
  3. * Simple script to set correct charset for changelog
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Controllers;
  7. use function __;
  8. use function array_keys;
  9. use function file_get_contents;
  10. use function htmlspecialchars;
  11. use function is_readable;
  12. use function ob_get_clean;
  13. use function ob_start;
  14. use function preg_replace;
  15. use function printf;
  16. use function readgzfile;
  17. use function substr;
  18. class ChangeLogController extends AbstractController
  19. {
  20. public function __invoke(): void
  21. {
  22. $this->response->disable();
  23. $this->response->getHeader()->sendHttpHeaders();
  24. $filename = CHANGELOG_FILE;
  25. /**
  26. * Read changelog.
  27. */
  28. // Check if the file is available, some distributions remove these.
  29. if (! @is_readable($filename)) {
  30. printf(
  31. __(
  32. 'The %s file is not available on this system, please visit %s for more information.'
  33. ),
  34. $filename,
  35. '<a href="https://www.phpmyadmin.net/">phpmyadmin.net</a>'
  36. );
  37. return;
  38. }
  39. // Test if the if is in a compressed format
  40. if (substr($filename, -3) === '.gz') {
  41. ob_start();
  42. readgzfile($filename);
  43. $changelog = ob_get_clean();
  44. } else {
  45. $changelog = file_get_contents($filename);
  46. }
  47. /**
  48. * Whole changelog in variable.
  49. */
  50. $changelog = htmlspecialchars((string) $changelog);
  51. $github_url = 'https://github.com/phpmyadmin/phpmyadmin/';
  52. $faq_url = 'https://docs.phpmyadmin.net/en/latest/faq.html';
  53. $replaces = [
  54. '@(https?://[./a-zA-Z0-9.-_-]*[/a-zA-Z0-9_])@' => '<a href="url.php?url=\\1">\\1</a>',
  55. // mail address
  56. '/([0-9]{4}-[0-9]{2}-[0-9]{2}) (.+[^ ]) +&lt;(.*@.*)&gt;/i' => '\\1 <a href="mailto:\\3">\\2</a>',
  57. // FAQ entries
  58. '/FAQ ([0-9]+)\.([0-9a-z]+)/i' => '<a href="url.php?url=' . $faq_url . '#faq\\1-\\2">FAQ \\1.\\2</a>',
  59. // GitHub issues
  60. '/issue\s*#?([0-9]{4,5}) /i' => '<a href="url.php?url=' . $github_url . 'issues/\\1">issue #\\1</a> ',
  61. // CVE/CAN entries
  62. '/((CAN|CVE)-[0-9]+-[0-9]+)/' => '<a href="url.php?url='
  63. . 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=\\1">\\1</a>',
  64. // PMASAentries
  65. '/(PMASA-[0-9]+-[0-9]+)/' => '<a href="url.php?url=https://www.phpmyadmin.net/security/\\1/">\\1</a>',
  66. // Highlight releases (with links)
  67. '/([0-9]+)\.([0-9]+)\.([0-9]+)\.0 (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3"></a>'
  68. . '<a href="url.php?url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3">'
  69. . '\\1.\\2.\\3.0 \\4</a>',
  70. '/([0-9]+)\.([0-9]+)\.([0-9]+)\.([1-9][0-9]*) (\([0-9-]+\))/' => '<a id="\\1_\\2_\\3_\\4"></a>'
  71. . '<a href="url.php?url=' . $github_url . 'commits/RELEASE_\\1_\\2_\\3_\\4">'
  72. . '\\1.\\2.\\3.\\4 \\5</a>',
  73. // Highlight releases (not linkable)
  74. '/( ### )(.*)/' => '\\1<b>\\2</b>',
  75. // Links target and rel
  76. '/a href="/' => 'a target="_blank" rel="noopener noreferrer" href="',
  77. ];
  78. $this->response->header('Content-type: text/html; charset=utf-8');
  79. echo $this->template->render('changelog', [
  80. 'changelog' => preg_replace(array_keys($replaces), $replaces, $changelog),
  81. ]);
  82. }
  83. }