Use librex as fallback search engine
This commit is contained in:
parent
b0f449671d
commit
eecaae4a03
|
@ -20,8 +20,8 @@
|
|||
|
||||
"disable_hidden_service_search" => false,
|
||||
|
||||
// You can disable automatic redirection from your instance
|
||||
"automatic_redirection" => true,
|
||||
// Fallback to another librex instance if google search fails
|
||||
"instance_fallback" => true,
|
||||
|
||||
/*
|
||||
Preset privacy friendly frontends for users, these can be overwritten by users in the settings
|
||||
|
|
|
@ -72,16 +72,10 @@
|
|||
curl_multi_exec($mh, $running);
|
||||
} while ($running);
|
||||
|
||||
if (curl_getinfo($google_ch)['http_code'] != '200') {
|
||||
if ($automatic_redirection
|
||||
&& $config->automatic_redirection) {
|
||||
$instances_json = json_decode(file_get_contents("instances.json"), true);
|
||||
$instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));
|
||||
header("Location: " . $instances[array_rand($instances)] . "search.php?q=$query");
|
||||
die();
|
||||
} else {
|
||||
return $results;
|
||||
}
|
||||
if (curl_getinfo($google_ch)['http_code'] != '200')
|
||||
{
|
||||
require "engines/librex/text.php";
|
||||
return get_librex_results($query, $page);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
function get_librex_results($query, $page)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if (!$config->instance_fallback)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$instances_json = json_decode(file_get_contents("instances.json"), true);
|
||||
$instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));
|
||||
$instance = $instances[array_rand($instances)];
|
||||
|
||||
$query_encoded = urlencode($query);
|
||||
|
||||
// TODO add all the required options
|
||||
$url = $instance . "api.php?q=$query_encoded&p=$page&t=0";
|
||||
|
||||
$librex_ch = curl_init($url);
|
||||
curl_setopt_array($librex_ch, $config->curl_settings);
|
||||
$response = curl_exec($librex_ch);
|
||||
curl_close($librex_ch);
|
||||
|
||||
return array_values(json_decode($response, true));
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue