tools.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. function get_root_domain($url)
  3. {
  4. $split_url = explode("/", $url);
  5. $base_url = $split_url[2];
  6. $base_url_main_split = explode(".", strrev($base_url));
  7. $root_domain = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
  8. return $root_domain;
  9. }
  10. function check_ddg_bang($query)
  11. {
  12. $bangs_json = file_get_contents("static/misc/ddg_bang.json");
  13. $bangs = json_decode($bangs_json, true);
  14. if (substr($query, 0, 1) == "!")
  15. $search_word = substr(explode(" ", $query)[0], 1);
  16. else
  17. $search_word = substr(end(explode(" ", $query)), 1);
  18. $bang_url = null;
  19. foreach($bangs as $bang)
  20. {
  21. if ($bang["t"] == $search_word)
  22. {
  23. $bang_url = $bang["u"];
  24. break;
  25. }
  26. }
  27. if ($bang_url)
  28. {
  29. $bang_query_array = explode("!" . $search_word, $query);
  30. $bang_query = trim(implode("", $bang_query_array));
  31. $request_url = str_replace("{{{s}}}", $bang_query, $bang_url);
  32. // $request_url = check_for_privacy_frontend($request_url);
  33. header("Location: " . $request_url);
  34. die();
  35. }
  36. }
  37. // Only works in indivious (original), ahmia (original) and image proxy
  38. function request($url)
  39. {
  40. global $config;
  41. $ch = curl_init($url);
  42. curl_setopt_array($ch, $config->curl_settings);
  43. $response = curl_exec($ch);
  44. return $response;
  45. }
  46. function print_elapsed_time($start_time)
  47. {
  48. $end_time = number_format(microtime(true) - $start_time, 2, '.', '');
  49. echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
  50. }
  51. function print_next_page_button($text, $page, $query, $type)
  52. {
  53. echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
  54. echo "<input type=\"hidden\" name=\"p\" value=\"$page\" />";
  55. echo "<input type=\"hidden\" name=\"q\" value=\"" . htmlspecialchars($query) ."\" />";
  56. echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";
  57. echo "<button type=\"submit\">$text</button>";
  58. echo "</form>";
  59. }
  60. ?>