2022-02-19 17:40:56 -03:00
|
|
|
<?php
|
2022-11-20 15:00:45 -03:00
|
|
|
function get_text_results($query, $page)
|
2022-02-19 17:40:56 -03:00
|
|
|
{
|
2022-03-11 06:04:36 -03:00
|
|
|
global $config;
|
2022-02-25 06:42:32 -03:00
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
$mh = curl_multi_init();
|
|
|
|
$query_encoded = urlencode($query);
|
2022-02-19 17:40:56 -03:00
|
|
|
$results = array();
|
2022-03-15 07:37:21 -03:00
|
|
|
|
2023-01-13 05:31:48 -03:00
|
|
|
$domain = $config->google_domain;
|
|
|
|
$language = isset($_COOKIE["google_language"]) ? htmlspecialchars($_COOKIE["google_language"]) : $config->google_language;
|
|
|
|
|
|
|
|
$url = "https://www.google.$domain/search?&q=$query_encoded&start=$page&hl=$language&lr=lang_$language";
|
|
|
|
|
|
|
|
if (isset($_COOKIE["safe_search"]))
|
|
|
|
{
|
|
|
|
$url .= "&safe=medium";
|
|
|
|
}
|
|
|
|
|
2022-03-01 13:28:37 -03:00
|
|
|
$google_ch = curl_init($url);
|
2022-03-11 06:04:36 -03:00
|
|
|
curl_setopt_array($google_ch, $config->curl_settings);
|
2022-03-01 13:28:37 -03:00
|
|
|
curl_multi_add_handle($mh, $google_ch);
|
2022-03-15 07:37:21 -03:00
|
|
|
|
2022-12-02 05:41:12 -03:00
|
|
|
$special_search = $page ? 0 : check_for_special_search($query);
|
2022-03-01 13:28:37 -03:00
|
|
|
$special_ch = null;
|
|
|
|
$url = null;
|
2022-03-03 06:32:46 -03:00
|
|
|
if ($special_search != 0)
|
2022-03-01 13:28:37 -03:00
|
|
|
{
|
|
|
|
switch ($special_search)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
$url = "https://cdn.moneyconvert.net/api/latest.json";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$split_query = explode(" ", $query);
|
|
|
|
$reversed_split_q = array_reverse($split_query);
|
|
|
|
$word_to_define = $reversed_split_q[1];
|
|
|
|
$url = "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
|
|
|
|
break;
|
2022-10-29 09:41:05 -03:00
|
|
|
case 5:
|
|
|
|
$url = "https://wttr.in/@" . $_SERVER["REMOTE_ADDR"] . "?format=j1";
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
$url = "https://check.torproject.org/torbulkexitlist";
|
|
|
|
break;
|
|
|
|
case 7:
|
2022-03-30 08:18:31 -03:00
|
|
|
$url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
|
2022-03-01 13:28:37 -03:00
|
|
|
break;
|
|
|
|
}
|
2022-11-20 15:00:45 -03:00
|
|
|
|
|
|
|
if ($url != NULL)
|
|
|
|
{
|
|
|
|
$special_ch = curl_init($url);
|
|
|
|
curl_setopt_array($special_ch, $config->curl_settings);
|
|
|
|
curl_multi_add_handle($mh, $special_ch);
|
|
|
|
}
|
2022-03-01 13:28:37 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
$running = null;
|
|
|
|
do {
|
|
|
|
curl_multi_exec($mh, $running);
|
|
|
|
} while ($running);
|
2022-03-15 07:37:21 -03:00
|
|
|
|
2022-10-25 08:02:01 -03:00
|
|
|
|
2022-03-03 17:57:36 -03:00
|
|
|
if ($special_search != 0)
|
2022-03-01 13:28:37 -03:00
|
|
|
{
|
2022-03-03 17:57:36 -03:00
|
|
|
$special_result = null;
|
|
|
|
|
2022-03-02 09:15:34 -03:00
|
|
|
switch ($special_search)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
require "engines/special/currency.php";
|
2022-03-03 17:57:36 -03:00
|
|
|
$special_result = currency_results($query, curl_multi_getcontent($special_ch));
|
2022-03-02 09:15:34 -03:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
require "engines/special/definition.php";
|
2022-03-03 17:57:36 -03:00
|
|
|
$special_result = definition_results($query, curl_multi_getcontent($special_ch));
|
2022-03-02 09:15:34 -03:00
|
|
|
break;
|
2022-10-29 09:41:05 -03:00
|
|
|
|
2022-03-02 09:15:34 -03:00
|
|
|
case 3:
|
2022-10-25 08:02:01 -03:00
|
|
|
require "engines/special/ip.php";
|
|
|
|
$special_result = ip_result();
|
|
|
|
break;
|
2022-10-29 09:41:05 -03:00
|
|
|
case 4:
|
2022-10-25 08:02:01 -03:00
|
|
|
require "engines/special/user_agent.php";
|
|
|
|
$special_result = user_agent_result();
|
|
|
|
break;
|
2022-10-29 09:41:05 -03:00
|
|
|
case 5:
|
|
|
|
require "engines/special/weather.php";
|
|
|
|
$special_result = weather_results(curl_multi_getcontent($special_ch));
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
require "engines/special/tor.php";
|
|
|
|
$special_result = tor_result(curl_multi_getcontent($special_ch));
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
require "engines/special/wikipedia.php";
|
|
|
|
$special_result = wikipedia_results($query, curl_multi_getcontent($special_ch));
|
|
|
|
break;
|
2022-03-02 09:15:34 -03:00
|
|
|
}
|
2022-03-03 17:57:36 -03:00
|
|
|
|
|
|
|
if ($special_result != null)
|
|
|
|
array_push($results, $special_result);
|
2022-03-01 13:28:37 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
$xpath = get_xpath(curl_multi_getcontent($google_ch));
|
2022-02-19 17:40:56 -03:00
|
|
|
|
|
|
|
foreach($xpath->query("//div[@id='search']//div[contains(@class, 'g')]") as $result)
|
|
|
|
{
|
|
|
|
$url = $xpath->evaluate(".//div[@class='yuRUbf']//a/@href", $result)[0];
|
|
|
|
|
|
|
|
if ($url == null)
|
|
|
|
continue;
|
|
|
|
|
2022-03-03 06:32:46 -03:00
|
|
|
if (!empty($results)) // filter duplicate results, ignore special result
|
|
|
|
{
|
|
|
|
if (!array_key_exists("special_response", end($results)))
|
|
|
|
if (end($results)["url"] == $url->textContent)
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-15 07:37:21 -03:00
|
|
|
|
2022-02-20 18:57:23 -03:00
|
|
|
$url = $url->textContent;
|
2022-03-24 07:28:12 -03:00
|
|
|
|
2022-04-21 05:02:32 -04:00
|
|
|
$url = check_for_privacy_frontend($url);
|
2022-03-15 07:37:21 -03:00
|
|
|
|
2022-02-19 17:40:56 -03:00
|
|
|
$title = $xpath->evaluate(".//h3", $result)[0];
|
|
|
|
$description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
|
|
|
|
|
2022-03-15 07:37:21 -03:00
|
|
|
array_push($results,
|
2022-02-19 17:40:56 -03:00
|
|
|
array (
|
2022-02-21 18:00:59 -03:00
|
|
|
"title" => htmlspecialchars($title->textContent),
|
|
|
|
"url" => htmlspecialchars($url),
|
|
|
|
"base_url" => htmlspecialchars(get_base_url($url)),
|
2022-03-15 07:37:21 -03:00
|
|
|
"description" => $description == null ?
|
|
|
|
"No description was provided for this site." :
|
2022-02-21 18:00:59 -03:00
|
|
|
htmlspecialchars($description->textContent)
|
2022-02-19 17:40:56 -03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
2022-02-25 06:42:32 -03:00
|
|
|
|
2022-03-15 07:37:21 -03:00
|
|
|
function print_text_results($results)
|
2022-02-25 06:42:32 -03:00
|
|
|
{
|
2022-03-03 06:32:46 -03:00
|
|
|
$special = $results[0];
|
|
|
|
if (array_key_exists("special_response", $special))
|
|
|
|
{
|
|
|
|
$response = $special["special_response"]["response"];
|
|
|
|
$source = $special["special_response"]["source"];
|
|
|
|
|
2022-12-28 07:20:38 -03:00
|
|
|
echo "<p class=\"special-result-container\">";
|
2022-03-30 08:18:31 -03:00
|
|
|
if (array_key_exists("image", $special["special_response"]))
|
2022-06-27 17:00:22 -04:00
|
|
|
{
|
|
|
|
$image_url = $special["special_response"]["image"];
|
2022-07-08 15:52:26 -04:00
|
|
|
echo "<img src=\"image_proxy.php?url=$image_url\">";
|
2022-06-27 17:00:22 -04:00
|
|
|
}
|
2022-12-28 07:20:38 -03:00
|
|
|
echo $response;
|
2022-10-25 08:02:01 -03:00
|
|
|
if ($source)
|
|
|
|
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
2022-12-28 07:20:38 -03:00
|
|
|
echo "</p>";
|
2022-03-03 06:32:46 -03:00
|
|
|
|
|
|
|
array_shift($results);
|
|
|
|
}
|
2022-10-29 09:41:05 -03:00
|
|
|
|
2022-08-15 00:04:52 -04:00
|
|
|
echo "<div class=\"text-result-container\">";
|
2022-03-03 06:32:46 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
foreach($results as $result)
|
|
|
|
{
|
|
|
|
$title = $result["title"];
|
|
|
|
$url = $result["url"];
|
|
|
|
$base_url = $result["base_url"];
|
|
|
|
$description = $result["description"];
|
|
|
|
|
|
|
|
echo "<div class=\"text-result-wrapper\">";
|
|
|
|
echo "<a href=\"$url\">";
|
|
|
|
echo "$base_url";
|
|
|
|
echo "<h2>$title</h2>";
|
|
|
|
echo "</a>";
|
|
|
|
echo "<span>$description</span>";
|
|
|
|
echo "</div>";
|
|
|
|
}
|
2022-03-03 06:32:46 -03:00
|
|
|
|
2022-02-25 06:42:32 -03:00
|
|
|
echo "</div>";
|
|
|
|
}
|
2022-03-15 07:37:21 -03:00
|
|
|
?>
|