search.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php require "misc/header.php"; ?>
  2. <title>
  3. <?php
  4. $query = htmlspecialchars(trim($_REQUEST["q"]));
  5. echo $query;
  6. ?> - LibreX</title>
  7. </head>
  8. <body>
  9. <form class="sub-search-container" method="get" autocomplete="off">
  10. <h1 class="logomobile"><a class="no-decoration" href="./">Libre<span class="X">X</span></a></h1>
  11. <input type="text" name="q"
  12. <?php
  13. $query_encoded = urlencode($query);
  14. if (1 > strlen($query) || strlen($query) > 256)
  15. {
  16. header("Location: ./");
  17. die();
  18. }
  19. echo "value=\"$query\"";
  20. ?>
  21. >
  22. <br>
  23. <?php
  24. foreach($_REQUEST as $key=>$value)
  25. {
  26. if ($key != "q" && $key != "p" && $key != "t")
  27. {
  28. echo "<input type=\"hidden\" name=\"" . htmlspecialchars($key) . "\" value=\"" . htmlspecialchars($value) . "\"/>";
  29. }
  30. }
  31. $type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
  32. echo "<button class=\"hide\" name=\"t\" value=\"$type\"/></button>";
  33. ?>
  34. <button type="submit" class="hide"></button>
  35. <input type="hidden" name="p" value="0">
  36. <div class="sub-search-button-wrapper">
  37. <button name="t" value="0"><img src="static/images/text_result.png" alt="text result" />General</button>
  38. <button name="t" value="1"><img src="static/images/image_result.png" alt="image result" />Images</button>
  39. <button name="t" value="2"><img src="static/images/video_result.png" alt="video result" />Videos</button>
  40. <button name="t" value="3"><img src="static/images/torrent_result.png" alt="torrent result" />Torrents</button>
  41. <button name="t" value="4"><img src="static/images/tor_result.png" alt="tor result" />Tor</button>
  42. </div>
  43. <hr>
  44. </form>
  45. <?php
  46. $config = require "config.php";
  47. require "misc/tools.php";
  48. $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
  49. $start_time = microtime(true);
  50. switch ($type)
  51. {
  52. case 0:
  53. $query_parts = explode(" ", $query);
  54. $last_word_query = end($query_parts);
  55. if (substr($query, 0, 1) == "!" || substr($last_word_query, 0, 1) == "!")
  56. check_ddg_bang($query);
  57. require "engines/google/text.php";
  58. $results = get_text_results($query, $page);
  59. print_elapsed_time($start_time);
  60. print_text_results($results);
  61. break;
  62. case 1:
  63. require "engines/qwant/image.php";
  64. $results = get_image_results($query_encoded, $page);
  65. print_elapsed_time($start_time);
  66. print_image_results($results);
  67. break;
  68. case 2:
  69. require "engines/brave/video.php";
  70. $results = get_video_results($query_encoded);
  71. print_elapsed_time($start_time);
  72. print_video_results($results);
  73. break;
  74. case 3:
  75. if ($config->disable_bittorent_search)
  76. echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
  77. else
  78. {
  79. require "engines/bittorrent/merge.php";
  80. $results = get_merged_torrent_results($query_encoded);
  81. print_elapsed_time($start_time);
  82. print_merged_torrent_results($results);
  83. }
  84. break;
  85. case 4:
  86. if ($config->disable_hidden_service_search)
  87. echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
  88. else
  89. {
  90. require "engines/ahmia/hidden_service.php";
  91. $results = get_hidden_service_results($query_encoded);
  92. print_elapsed_time($start_time);
  93. print_hidden_service_results($results);
  94. }
  95. break;
  96. default:
  97. require "engines/google/text.php";
  98. $results = get_text_results($query_encoded, $page);
  99. print_text_results($results);
  100. print_elapsed_time($start_time);
  101. break;
  102. }
  103. if (2 > $type)
  104. {
  105. echo "<div class=\"next-page-button-wrapper\">";
  106. if ($page != 0)
  107. {
  108. print_next_page_button("&lt;&lt;", 0, $query, $type);
  109. print_next_page_button("&lt;", $page - 10, $query, $type);
  110. }
  111. for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
  112. print_next_page_button($i + 1, $i * 10, $query, $type);
  113. print_next_page_button("&gt;", $page + 10, $query, $type);
  114. echo "</div>";
  115. }
  116. ?>
  117. <?php require "misc/footer.php"; ?>