search.php 5.6 KB

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