2022-02-24 07:30:15 -03:00
|
|
|
<?php
|
|
|
|
function get_base_url($url)
|
|
|
|
{
|
|
|
|
$split_url = explode("/", $url);
|
|
|
|
$base_url = $split_url[0] . "//" . $split_url[2] . "/";
|
|
|
|
return $base_url;
|
|
|
|
}
|
|
|
|
|
2022-07-08 15:52:26 -04:00
|
|
|
function try_replace_with_frontend($url, $frontend, $original)
|
2022-03-02 09:12:09 -03:00
|
|
|
{
|
2022-04-21 05:02:32 -04:00
|
|
|
$config = require "config.php";
|
|
|
|
|
|
|
|
if (isset($_COOKIE[$frontend]) || isset($_REQUEST[$frontend]) || !empty($config->$frontend))
|
2022-03-02 09:12:09 -03:00
|
|
|
{
|
2022-04-21 05:02:32 -04:00
|
|
|
if (isset($_COOKIE[$frontend]))
|
|
|
|
$frontend = $_COOKIE[$frontend];
|
|
|
|
else if (isset($_REQUEST[$frontend]))
|
|
|
|
$frontend = $_REQUEST[$frontend];
|
|
|
|
else if (!empty($config->$frontend))
|
|
|
|
$frontend = $config->$frontend;
|
2022-03-02 09:12:09 -03:00
|
|
|
|
2022-09-03 13:45:47 -04:00
|
|
|
if ($original == "instagram.com")
|
2022-03-24 07:28:12 -03:00
|
|
|
{
|
|
|
|
if (!strpos($url, "/p/"))
|
|
|
|
$frontend .= "/u";
|
|
|
|
}
|
2022-09-03 13:45:47 -04:00
|
|
|
|
2022-09-16 05:23:57 -03:00
|
|
|
if (empty(trim($frontend)))
|
|
|
|
return $url;
|
|
|
|
|
2022-07-08 15:52:26 -04:00
|
|
|
$url = $frontend . explode($original, $url)[1];
|
2022-03-24 07:28:12 -03:00
|
|
|
|
|
|
|
return $url;
|
2022-03-02 09:12:09 -03:00
|
|
|
}
|
2022-03-24 07:28:12 -03:00
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2022-04-21 05:02:32 -04:00
|
|
|
function check_for_privacy_frontend($url)
|
2022-03-24 07:28:12 -03:00
|
|
|
{
|
2022-09-16 05:23:57 -03:00
|
|
|
if (isset($_COOKIE["disable_frontends"]))
|
|
|
|
return $url;
|
|
|
|
|
2022-07-08 15:52:26 -04:00
|
|
|
$frontends = array(
|
|
|
|
"youtube.com" => "invidious",
|
|
|
|
"instagram.com" => "bibliogram",
|
|
|
|
"twitter.com" => "nitter",
|
|
|
|
"reddit.com" => "libreddit",
|
|
|
|
"tiktok.com" => "proxitok",
|
2022-12-02 05:41:12 -03:00
|
|
|
"wikipedia.org" => "wikiless",
|
|
|
|
"quora.com" => "quetre",
|
|
|
|
"imdb.com" => "libremdb"
|
2022-07-08 15:52:26 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach($frontends as $original => $frontend)
|
|
|
|
{
|
|
|
|
if (strpos($url, $original))
|
|
|
|
{
|
|
|
|
$url = try_replace_with_frontend($url, $frontend, $original);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 09:12:09 -03:00
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2022-07-08 15:52:26 -04:00
|
|
|
function check_ddg_bang($query)
|
|
|
|
{
|
|
|
|
|
2022-09-03 13:45:47 -04:00
|
|
|
$bangs_json = file_get_contents("static/misc/ddg_bang.json");
|
2022-07-08 15:52:26 -04:00
|
|
|
$bangs = json_decode($bangs_json, true);
|
2022-09-03 13:45:47 -04:00
|
|
|
|
|
|
|
if (substr($query, 0, 1) == "!")
|
|
|
|
$search_word = substr(explode(" ", $query)[0], 1);
|
|
|
|
else
|
|
|
|
$search_word = substr(end(explode(" ", $query)), 1);
|
2022-07-08 15:52:26 -04:00
|
|
|
|
|
|
|
$bang_url = null;
|
|
|
|
|
|
|
|
foreach($bangs as $bang)
|
|
|
|
{
|
|
|
|
if ($bang["t"] == $search_word)
|
|
|
|
{
|
|
|
|
$bang_url = $bang["u"];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bang_url)
|
|
|
|
{
|
|
|
|
$bang_query_array = explode("!" . $search_word, $query);
|
|
|
|
$bang_query = trim(implode("", $bang_query_array));
|
|
|
|
|
|
|
|
$request_url = str_replace("{{{s}}}", $bang_query, $bang_url);
|
|
|
|
$request_url = check_for_privacy_frontend($request_url);
|
|
|
|
|
|
|
|
header("Location: " . $request_url);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 15:00:45 -03:00
|
|
|
function check_for_special_search($query)
|
|
|
|
{
|
|
|
|
if (isset($_COOKIE["disable_special"]) || isset($_REQUEST["disable_special"]))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
$query_lower = strtolower($query);
|
|
|
|
$split_query = explode(" ", $query);
|
|
|
|
|
|
|
|
if (strpos($query_lower, "to") && count($split_query) >= 4) // currency
|
|
|
|
{
|
|
|
|
$amount_to_convert = floatval($split_query[0]);
|
|
|
|
if ($amount_to_convert != 0)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (strpos($query_lower, "my") !== false)
|
|
|
|
{
|
|
|
|
if (strpos($query_lower, "ip"))
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua"))
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (strpos($query_lower, "weather") !== false)
|
|
|
|
{
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
else if ($query_lower == "tor")
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
else if (3 > count(explode(" ", $query))) // wikipedia
|
|
|
|
{
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
function get_xpath($response)
|
2022-02-24 07:30:15 -03:00
|
|
|
{
|
2022-02-25 06:42:32 -03:00
|
|
|
$htmlDom = new DOMDocument;
|
|
|
|
@$htmlDom->loadHTML($response);
|
|
|
|
$xpath = new DOMXPath($htmlDom);
|
2022-02-24 07:30:15 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
return $xpath;
|
2022-02-24 07:30:15 -03:00
|
|
|
}
|
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
function request($url)
|
2022-02-24 07:30:15 -03:00
|
|
|
{
|
2022-03-11 06:46:29 -03:00
|
|
|
global $config;
|
2022-02-24 18:29:10 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
$ch = curl_init($url);
|
2022-03-11 06:04:36 -03:00
|
|
|
curl_setopt_array($ch, $config->curl_settings);
|
2022-02-25 06:42:32 -03:00
|
|
|
$response = curl_exec($ch);
|
2022-02-24 18:29:10 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
return $response;
|
2022-02-24 07:30:15 -03:00
|
|
|
}
|
|
|
|
|
2022-03-15 07:37:21 -03:00
|
|
|
function human_filesize($bytes, $dec = 2)
|
2022-02-25 16:26:15 -03:00
|
|
|
{
|
|
|
|
$size = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
|
|
|
$factor = floor((strlen($bytes) - 1) / 3);
|
|
|
|
|
|
|
|
return sprintf("%.{$dec}f ", $bytes / pow(1024, $factor)) . @$size[$factor];
|
|
|
|
}
|
|
|
|
|
2022-03-15 07:37:21 -03:00
|
|
|
function remove_special($string)
|
2022-03-04 06:36:31 -03:00
|
|
|
{
|
2022-11-20 15:00:45 -03:00
|
|
|
$string = preg_replace("/[\r\n]+/", "\n", $string);
|
|
|
|
return trim(preg_replace("/\s+/", ' ', $string));
|
2022-03-04 06:36:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_elapsed_time($start_time)
|
|
|
|
{
|
|
|
|
$end_time = number_format(microtime(true) - $start_time, 2, '.', '');
|
|
|
|
echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
|
|
|
|
}
|
|
|
|
|
2022-03-15 07:37:21 -03:00
|
|
|
function print_next_page_button($text, $page, $query, $type)
|
2022-02-24 07:30:15 -03:00
|
|
|
{
|
2022-07-15 09:50:23 -04:00
|
|
|
echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"get\" autocomplete=\"off\">";
|
2022-10-25 08:02:01 -03:00
|
|
|
foreach($_REQUEST as $key=>$value)
|
|
|
|
{
|
|
|
|
if ($key != "q" && $key != "p" && $key != "t")
|
|
|
|
{
|
|
|
|
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\"/>";
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 07:30:15 -03:00
|
|
|
echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
|
2022-02-25 06:42:32 -03:00
|
|
|
echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
|
2022-10-25 08:02:01 -03:00
|
|
|
echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";
|
2022-02-25 06:42:32 -03:00
|
|
|
echo "<button type=\"submit\">$text</button>";
|
2022-03-15 07:37:21 -03:00
|
|
|
echo "</form>";
|
2022-02-24 07:30:15 -03:00
|
|
|
}
|
2022-03-15 07:37:21 -03:00
|
|
|
?>
|