autocomplete fixes

This commit is contained in:
lolcat committed 2026-11-08 16:33:02 -05:00
1 parent 5d8c9a5798
commit 24130effe6
2 files changed
+29 -16

No files matched your search

+1 -2
View File
@@ -7,7 +7,7 @@ class autocomplete{
public function __construct(){ public function __construct(){
header("Content-Type: application/json"); header("Content-Type: application/x-suggestions+json");
$this->scrapers = [ $this->scrapers = [
"brave" => "https://search.brave.com/api/suggest?q={searchTerms}", "brave" => "https://search.brave.com/api/suggest?q={searchTerms}",
@@ -18,7 +18,6 @@ class autocomplete{
"marginalia" => "https://search.marginalia.nu/suggest/?partial={searchTerms}", "marginalia" => "https://search.marginalia.nu/suggest/?partial={searchTerms}",
"yt" => "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&q={searchTerms}", "yt" => "https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&q={searchTerms}",
"sc" => "", "sc" => "",
"startpage" => "https://www.startpage.com/suggestions?q={searchTerms}&format=opensearch&segment=startpage.defaultffx&lui=english",
"kagi" => "https://kagi.com/api/autosuggest?q={searchTerms}" "kagi" => "https://kagi.com/api/autosuggest?q={searchTerms}"
]; ];
+28 -14
View File
@@ -3,32 +3,46 @@
header("Content-Type: application/xml"); header("Content-Type: application/xml");
include "data/config.php"; include "data/config.php";
$domain = $host = strtolower(explode(":", $_SERVER["HTTP_HOST"], 2)[0]);
htmlspecialchars(
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on" ? "https" : "http") .
'://' . $_SERVER["HTTP_HOST"]
);
// detect if 4get should serve the HTTPS endpoint
if( if(
preg_match( preg_match(
'/\.onion$/', '/\.(onion|i2p)$/',
$domain strtolower($host),
$match
) )
){ ){
$onion = true; $ssl = false;
$src = $match[1];
}elseif(
is_string(
filter_var(
$host,
FILTER_VALIDATE_IP
)
) ||
$host == "localhost"
){
$ssl = false;
$src = "localhost";
}else{ }else{
$onion = false; $ssl = true;
} }
$domain = ($ssl ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"];
echo echo
'<?xml version="1.0" encoding="UTF-8"?>' . '<?xml version="1.0" encoding="UTF-8"?>' .
'<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' . '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">' .
'<ShortName>' . htmlspecialchars(config::SERVER_NAME) . ($onion ? " (onion)" : "") . '</ShortName>' . '<ShortName>' . htmlspecialchars(config::SERVER_NAME) . ($ssl === false ? " ({$src})" : "") . '</ShortName>' .
'<Description>' . htmlspecialchars(config::SERVER_SHORT_DESCRIPTION) . '</Description>' .
'<InputEncoding>UTF-8</InputEncoding>' . '<InputEncoding>UTF-8</InputEncoding>' .
'<Image width="16" height="16">' . $domain . '/favicon.ico</Image>' . '<Image width="16" height="16" type="image/x-icon">' . htmlspecialchars($domain) . '/favicon.ico</Image>' .
'<Url type="text/html" method="GET" template="' . $domain . '/web?s={searchTerms}"/>'; '<Url type="text/html" method="GET" template="' . htmlspecialchars($domain) . '/web?s={searchTerms}"/>';
if( if(
isset($_GET["ac"]) && isset($_GET["ac"]) &&
@@ -36,7 +50,7 @@ if(
$_GET["ac"] != "disabled" $_GET["ac"] != "disabled"
){ ){
echo '<Url rel="suggestions" type="application/x-suggestions+json" template="' . $domain . '/api/v1/ac?s={searchTerms}&amp;scraper=' . htmlspecialchars($_GET["ac"]) . '"/>'; echo '<Url type="application/x-suggestions+json" template="' . $domain . '/api/v1/ac?s={searchTerms}&amp;scraper=' . htmlspecialchars($_GET["ac"]) . '"/>';
} }
echo '</OpenSearchDescription>'; echo '</OpenSearchDescription>';