BridgeList.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. final class BridgeList {
  3. private static function getHead() {
  4. return <<<EOD
  5. <head>
  6. <meta charset="utf-8">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <meta name="description" content="RSS-Bridge" />
  9. <title>RSS-Bridge</title>
  10. <link href="static/style.css" rel="stylesheet">
  11. <script src="static/search.js"></script>
  12. <script src="static/select.js"></script>
  13. <noscript>
  14. <style>
  15. .searchbar {
  16. display: none;
  17. }
  18. </style>
  19. </noscript>
  20. </head>
  21. EOD;
  22. }
  23. private static function getBridges($whitelist, $showInactive, &$totalBridges, &$totalActiveBridges) {
  24. $body = '';
  25. $totalActiveBridges = 0;
  26. $inactiveBridges = '';
  27. $bridgeList = Bridge::listBridges();
  28. $formats = Format::searchInformation();
  29. $totalBridges = count($bridgeList);
  30. foreach($bridgeList as $bridgeName) {
  31. if(Bridge::isWhitelisted($whitelist, strtolower($bridgeName))) {
  32. $body .= BridgeCard::displayBridgeCard($bridgeName, $formats);
  33. $totalActiveBridges++;
  34. } elseif($showInactive) {
  35. // inactive bridges
  36. $inactiveBridges .= BridgeCard::displayBridgeCard($bridgeName, $formats, false) . PHP_EOL;
  37. }
  38. }
  39. $body .= $inactiveBridges;
  40. return $body;
  41. }
  42. private static function getHeader() {
  43. $status = '';
  44. if(defined('DEBUG') && DEBUG === true) {
  45. $status .= 'debug mode active';
  46. }
  47. return <<<EOD
  48. <header>
  49. <h1>RSS-Bridge</h1>
  50. <h2>·Reconnecting the Web·</h2>
  51. <p class="status">{$status}</p>
  52. </header>
  53. EOD;
  54. }
  55. private static function getSearchbar() {
  56. $query = filter_input(INPUT_GET, 'q');
  57. return <<<EOD
  58. <section class="searchbar">
  59. <h3>Search</h3>
  60. <input type="text" name="searchfield"
  61. id="searchfield" placeholder="Enter the bridge you want to search for"
  62. onchange="search()" onkeyup="search()" value="{$query}">
  63. </section>
  64. EOD;
  65. }
  66. private static function getFooter($totalBridges, $totalActiveBridges, $showInactive) {
  67. $version = Configuration::getVersion();
  68. $inactive = '';
  69. if($totalActiveBridges !== $totalBridges) {
  70. if(!$showInactive) {
  71. $inactive = '<a href="?show_inactive=1"><button class="small">Show inactive bridges</button></a><br>';
  72. } else {
  73. $inactive = '<a href="?show_inactive=0"><button class="small">Hide inactive bridges</button></a><br>';
  74. }
  75. }
  76. return <<<EOD
  77. <section class="footer">
  78. <a href="https://github.com/rss-bridge/rss-bridge">RSS-Bridge ~ Public Domain</a><br>
  79. <p class="version">{$version}</p>
  80. {$totalActiveBridges}/{$totalBridges} active bridges.<br>
  81. {$inactive}
  82. </section>
  83. EOD;
  84. }
  85. static function create($whitelist, $showInactive = true) {
  86. $totalBridges = 0;
  87. $totalActiveBridges = 0;
  88. return '<!DOCTYPE html><html lang="en">'
  89. . BridgeList::getHead()
  90. . '<body onload="search()">'
  91. . BridgeList::getHeader()
  92. . BridgeList::getSearchbar()
  93. . BridgeList::getBridges($whitelist, $showInactive, $totalBridges, $totalActiveBridges)
  94. . BridgeList::getFooter($totalBridges, $totalActiveBridges, $showInactive)
  95. . '</body></html>';
  96. }
  97. }