search.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  3. <head>
  4. <title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
  5. <meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  7. <meta name="description" content="A privacy respecting meta search engine."/>
  8. <link rel="stylesheet" type="text/css" href="static/styles.css"/>
  9. <link title="LibreX search" type="application/opensearchdescription+xml" href="/opensearch.xml?method=POST" rel="search"/>
  10. <link rel="shortcut icon" href="static/librex.png" />
  11. </head>
  12. <body>
  13. <form class="small-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
  14. <a href="/"><img id="logo" src="static/librex.png" alt="librex"></a>
  15. <input type="hidden" name="p" value="0">
  16. <input type="text" name="q"
  17. <?php
  18. $query = trim($_REQUEST["q"]);
  19. if (1 > strlen($query) || strlen($query) > 256)
  20. {
  21. header("Location: /");
  22. die();
  23. }
  24. echo "value=\"$query\"";
  25. ?>
  26. >
  27. <br>
  28. <?php
  29. $type = $_REQUEST["type"];
  30. echo "<input type=\"hidden\" name=\"type\" value=\"$type\"/>";
  31. ?>
  32. <button type="submit" style="display:none;"></button>
  33. <div class="result-change">
  34. <button name="type" value="0"><img src="static/text_result.png" id="change-image" style="width:20px;">Text</button>
  35. <button name="type" value="1"><img src="static/image_result.png" id="change-image">Images</button>
  36. <button name="type" value="2"><img src="static/video_result.png" id="change-image" style="width:40px;">Videos</button>
  37. </div>
  38. <hr>
  39. </form>
  40. <?php
  41. ini_set('display_errors', 1);
  42. ini_set('display_startup_errors', 1);
  43. error_reporting(E_ALL);
  44. function print_next_pages($page, $button_val, $q)
  45. {
  46. echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
  47. echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
  48. echo "<input type=\"hidden\" name=\"q\" value=\"$q\" />";
  49. echo "<button type=\"submit\">$button_val</button>";
  50. echo "</form>";
  51. }
  52. require_once "google.php";
  53. require_once "tools.php";
  54. require_once "config.php";
  55. $page = isset($_REQUEST["p"]) ? (int) htmlspecialchars($_REQUEST["p"]) : 0;
  56. $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
  57. $start_time = microtime(true);
  58. $results = get_google_results($query, $page, $type);
  59. $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
  60. echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
  61. if ($type == 0) // text search
  62. {
  63. check_for_special_search($query);
  64. foreach($results as $result)
  65. {
  66. $title = $result["title"];
  67. $url = $result["url"];
  68. $base_url = $result["base_url"];
  69. $description = $result["description"];
  70. echo "<div class=\"result-container\">";
  71. echo "<a href=\"$url\">";
  72. echo "$base_url";
  73. echo "<h2>$title</h2>";
  74. echo "</a>";
  75. echo "<span>$description</span>";
  76. echo "</div>";
  77. }
  78. echo "<div class=\"page-container\">";
  79. if ($page != 0)
  80. {
  81. print_next_pages(0, "&lt;&lt;", $query);
  82. print_next_pages($page - 10, "&lt;", $query);
  83. }
  84. for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
  85. {
  86. $page_input = $i * 10;
  87. $page_button = $i + 1;
  88. print_next_pages($page_input, $page_button, $query);
  89. }
  90. print_next_pages($page + 10, "&gt;", $query);
  91. echo "</div>";
  92. }
  93. else if ($type == 1) // image search
  94. {
  95. echo "<div class=\"image-result-container\">";
  96. foreach($results as $result)
  97. {
  98. $src = $result["base64"];
  99. $alt = $result["alt"];
  100. echo "<a title=\"$alt\" href=\"data:image/jpeg;base64,$src\" target=\"_blank\">";
  101. echo "<img src=\"data:image/jpeg;base64,$src\" width=\"350\" height=\"200\">";
  102. echo "</a>";
  103. }
  104. echo "</div>";
  105. }
  106. else if ($type == 2) // video search
  107. {
  108. echo "<div class=\"results-wrapper\">";
  109. if ($config_replace_yt_with_invidious != null)
  110. {
  111. echo "<p id=\"special-result\">";
  112. echo "YouTube results got replaced with a privacy friendly Invidious instance.";
  113. echo "</p>";
  114. }
  115. foreach($results as $result)
  116. {
  117. $title = $result["title"];
  118. $url = $result["url"];
  119. $base_url = $result["base_url"];
  120. echo "<div class=\"result-container\">";
  121. echo "<a href=\"$url\">";
  122. echo "$base_url";
  123. echo "<h2>$title</h2>";
  124. echo "</a>";
  125. echo "</div>";
  126. }
  127. echo "</div>";
  128. }
  129. ?>
  130. <div class="info-container">
  131. <a href="/">LibreX</a>
  132. <a href="https://github.com/hnhx/librex/" target="_blank">Source code &amp; Other instances</a>
  133. <a href="/donate.xhtml" id="right">Donate ❤️</a>
  134. </div>
  135. </body>
  136. </html>