search.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php require "misc/header.php"; ?>
  2. <title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
  3. </head>
  4. <body>
  5. <form class="sub-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
  6. <a href="/"><img id="logo" src="static/images/librex.png" alt="librex"></a>
  7. <input type="text" name="q"
  8. <?php
  9. $query = trim($_REQUEST["q"]);
  10. if (1 > strlen($query) || strlen($query) > 256)
  11. {
  12. header("Location: /");
  13. die();
  14. }
  15. echo "value=\"$query\"";
  16. ?>
  17. >
  18. <br>
  19. <?php
  20. $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
  21. echo "<input type=\"hidden\" name=\"type\" value=\"$type\"/>";
  22. ?>
  23. <button type="submit" style="display:none;"></button>
  24. <input type="hidden" name="p" value="0">
  25. <div class="sub-search-button-wrapper">
  26. <button name="type" value="0"><img src="static/images/text_result.png">Text</button>
  27. <button name="type" value="1"><img src="static/images/image_result.png">Images</button>
  28. <button name="type" value="2"><img src="static/images/video_result.png">Videos</button>
  29. <button name="type" value="3"><img src="static/images/torrent_result.png">Torrents</button>
  30. </div>
  31. <hr>
  32. </form>
  33. <?php
  34. $config = require "config.php";
  35. require "misc/tools.php";
  36. $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
  37. $query_encoded = urlencode($query);
  38. $start_time = microtime(true);
  39. switch ($type)
  40. {
  41. case 0:
  42. require "engines/google/text.php";
  43. $results = get_text_results($query, $page);
  44. print_elapsed_time($start_time);
  45. print_text_results($results);
  46. break;
  47. case 1:
  48. require "engines/google/image.php";
  49. $results = get_image_results($query_encoded);
  50. print_elapsed_time($start_time);
  51. print_image_results($results);
  52. break;
  53. case 2:
  54. require "engines/google/video.php";
  55. $results = get_video_results($query_encoded, $page);
  56. print_elapsed_time($start_time);
  57. print_video_results($results);
  58. break;
  59. case 3:
  60. if ($config->disable_bittorent_search)
  61. echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
  62. else
  63. {
  64. require "engines/bittorrent/merge.php";
  65. $results = get_merged_torrent_results($query_encoded);
  66. print_elapsed_time($start_time);
  67. print_merged_torrent_results($results);
  68. break;
  69. }
  70. break;
  71. default:
  72. require "engines/google/text.php";
  73. $results = get_text_results($query_encoded, $page);
  74. print_text_results($results);
  75. print_elapsed_time($start_time);
  76. break;
  77. }
  78. if ($type == 0 || $type == 2 )
  79. {
  80. echo "<div class=\"next-page-button-wrapper\">";
  81. if ($page != 0)
  82. {
  83. print_next_page_button("&lt;&lt;", 0, $query, $type);
  84. print_next_page_button("&lt;", $page - 10, $query, $type);
  85. }
  86. for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
  87. print_next_page_button($i + 1, $i * 10, $query, $type);
  88. print_next_page_button("&gt;", $page + 10, $query, $type);
  89. echo "</div>";
  90. }
  91. ?>
  92. <?php require "misc/footer.php"; ?>