Added suggestions and fixed drag and drop

This commit is contained in:
Pablo Ferreiro 2022-09-09 23:54:59 +02:00
parent dec8c3ed8e
commit ba589f8361
No known key found for this signature in database
GPG Key ID: 41FBCE65B779FA24
3 changed files with 30 additions and 4 deletions

View File

@ -0,0 +1,16 @@
<?php
function get_suggestions_results($query) {
global $config;
$query_encoded = urlencode($query);
$url = "https://www.google.$config->google_domain/complete/search?q=$query_encoded&output=firefox&hl=$config->google_language";
// Make request
$ch = curl_init($url);
curl_setopt_array($ch, $config->curl_settings);
$result = curl_exec($ch);
return $result;
}
function print_suggestions_results($result) {
echo $result;
}

View File

@ -4,11 +4,11 @@
<Description>A meta search engine for Google.</Description>
<InputEncoding>UTF-8</InputEncoding>
<LongName>LibreX search</LongName>
<Url rel="results" type="text/html" method="post" template="http://localhost/search.php">
<Param name="q" value="{searchTerms}" />
</Url>
<Url rel="results" type="text/html" method="get" template="http://localhost/search.php?q={searchTerms}" />
<Url rel="suggestions" type="application/x-suggestions+json" method="get" template="http://localhost/suggestions.php?q={searchTerms}" />
<Url type="application/opensearchdescription+xml"
rel="self"
template="/opensearch.xml?method=POST" />
</OpenSearchDescription>
</OpenSearchDescription>

10
suggestions.php Normal file
View File

@ -0,0 +1,10 @@
<?php
$config = require "config.php";
require "engines/google/suggestions.php";
header('Content-Type: application/x-suggestions+xml');
header('Content-Disposition: attachment; filename="suggestions.json"');
$q = isset($_REQUEST['q']) ? htmlspecialchars(trim($_REQUEST["q"])) : '';
$result = get_suggestions_results($q);
echo print_suggestions_results($result, $q);