mirror of
https://git.bakhai.co.in/FbIN/LibreY.git
synced 2025-11-07 21:00:07 +05:30
commit
c9898cf261
95 changed files with 5217 additions and 0 deletions
35
engines/special/currency.php
Normal file
35
engines/special/currency.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
class CurrencyRequest extends EngineRequest {
|
||||
public function get_request_url() {
|
||||
return "https://cdn.moneyconvert.net/api/latest.json";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
$split_query = explode(" ", $this->query);
|
||||
|
||||
$base_currency = strtoupper($split_query[1]);
|
||||
$currency_to_convert = strtoupper($split_query[3]);
|
||||
$amount_to_convert = floatval($split_query[0]);
|
||||
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
$rates = $json_response["rates"];
|
||||
|
||||
if (!array_key_exists($base_currency, $rates) || !array_key_exists($currency_to_convert, $rates))
|
||||
return array();
|
||||
$base_currency_response = $rates[$base_currency];
|
||||
$currency_to_convert_response = $rates[$currency_to_convert];
|
||||
|
||||
$conversion_result = ($currency_to_convert_response / $base_currency_response) * $amount_to_convert;
|
||||
|
||||
$formatted_response = "$amount_to_convert $base_currency = $conversion_result $currency_to_convert";
|
||||
$source = "https://moneyconvert.net/";
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($formatted_response),
|
||||
"source" => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
32
engines/special/definition.php
Normal file
32
engines/special/definition.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
class DefinitionRequest extends EngineRequest {
|
||||
|
||||
public function get_request_url() {
|
||||
$split_query = explode(" ", $this->query);
|
||||
$reversed_split_q = array_reverse($split_query);
|
||||
$word_to_define = $reversed_split_q[1] == "define" ? $reversed_split_q[0] : $reversed_split_q[1];
|
||||
return "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
if (!$json_response)
|
||||
return array();
|
||||
|
||||
if (!array_key_exists("title", $json_response))
|
||||
{
|
||||
$definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
|
||||
|
||||
$source = "https://dictionaryapi.dev";
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($definition),
|
||||
"source" => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
engines/special/ip.php
Normal file
12
engines/special/ip.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
class IPRequest extends EngineRequest {
|
||||
public function parse_results($response) {
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => $_SERVER["REMOTE_ADDR"],
|
||||
"source" => null
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
91
engines/special/special.php
Normal file
91
engines/special/special.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
function check_for_special_search($query) {
|
||||
if (isset($_COOKIE["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") || str_starts_with($query_lower, "define")) && 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;
|
||||
}
|
||||
|
||||
function get_special_search_request($opts, $mh) {
|
||||
if ($opts->page != 0)
|
||||
return null;
|
||||
|
||||
$special_search = check_for_special_search($opts->query);
|
||||
$special_request = null;
|
||||
$url = null;
|
||||
|
||||
if ($special_search == 0)
|
||||
return null;
|
||||
|
||||
switch ($special_search) {
|
||||
case 1:
|
||||
require_once "engines/special/currency.php";
|
||||
$special_request = new CurrencyRequest($opts, $mh);
|
||||
break;
|
||||
case 2:
|
||||
require_once "engines/special/definition.php";
|
||||
$special_request = new DefinitionRequest($opts, $mh);
|
||||
break;
|
||||
case 3:
|
||||
require_once "engines/special/ip.php";
|
||||
$special_request = new IPRequest($opts, $mh);
|
||||
break;
|
||||
case 4:
|
||||
require_once "engines/special/user_agent.php";
|
||||
$special_request = new UserAgentRequest($opts, $mh);
|
||||
break;
|
||||
case 5:
|
||||
require_once "engines/special/weather.php";
|
||||
$special_request = new WeatherRequest($opts, $mh);
|
||||
break;
|
||||
case 6:
|
||||
require_once "engines/special/tor.php";
|
||||
$special_request = new TorRequest($opts, $mh);
|
||||
break;
|
||||
case 7:
|
||||
require_once "engines/special/wikipedia.php";
|
||||
$special_request = new WikipediaRequest($opts, $mh);
|
||||
break;
|
||||
}
|
||||
|
||||
return $special_request;
|
||||
}
|
||||
?>
|
||||
20
engines/special/tor.php
Normal file
20
engines/special/tor.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
class TorRequest extends EngineRequest {
|
||||
public function get_request_url() {
|
||||
return "https://check.torproject.org/torbulkexitlist";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
$formatted_response = strpos($response, $_SERVER["REMOTE_ADDR"]) ? "It seems like you are using Tor" : "It seems like you are not using Tor";
|
||||
$source = "https://check.torproject.org";
|
||||
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => $formatted_response,
|
||||
"source" => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
engines/special/user_agent.php
Normal file
12
engines/special/user_agent.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
class UserAgentRequest extends EngineRequest {
|
||||
public function parse_results($response) {
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => $_SERVER["HTTP_USER_AGENT"],
|
||||
"source" => null
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
30
engines/special/weather.php
Normal file
30
engines/special/weather.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
class WeatherRequest extends EngineRequest {
|
||||
public function get_request_url () {
|
||||
return "https://wttr.in/@" . $_SERVER["REMOTE_ADDR"] . "?format=j1";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
if (!$json_response)
|
||||
return array();
|
||||
|
||||
$current_weather = $json_response["current_condition"][0];
|
||||
|
||||
$temp_c = $current_weather["temp_C"];
|
||||
$temp_f = $current_weather["temp_F"];
|
||||
$description = $current_weather["weatherDesc"][0]["value"];
|
||||
|
||||
$formatted_response = "$description - $temp_c °C | $temp_f °F";
|
||||
|
||||
$source = "https://wttr.in";
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($formatted_response),
|
||||
"source" => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
44
engines/special/wikipedia.php
Normal file
44
engines/special/wikipedia.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
class WikipediaRequest extends EngineRequest {
|
||||
protected $wikipedia_domain;
|
||||
public function get_request_url() {
|
||||
$this->wikipedia_domain = "wikipedia.org";
|
||||
$query_encoded = urlencode($this->query);
|
||||
|
||||
$languages = json_decode(file_get_contents("static/misc/languages.json"), true);
|
||||
|
||||
if (array_key_exists($this->opts->language, $languages))
|
||||
$this->wikipedia_domain = $languages[$this->opts->language]["wikipedia"] . ".wikipedia.org";
|
||||
|
||||
return "https://$this->wikipedia_domain/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
$json_response = json_decode($response, true);
|
||||
if (!$json_response)
|
||||
return array();
|
||||
|
||||
$first_page = array_values($json_response["query"]["pages"])[0];
|
||||
|
||||
if (array_key_exists("missing", $first_page))
|
||||
return array();
|
||||
|
||||
$description = substr($first_page["extract"], 0, 250) . "...";
|
||||
|
||||
$source = "https://$this->wikipedia_domain/wiki/$this->query";
|
||||
$response = array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($description),
|
||||
"source" => $source
|
||||
)
|
||||
);
|
||||
|
||||
if (array_key_exists("thumbnail", $first_page)) {
|
||||
$image_url = $first_page["thumbnail"]["source"];
|
||||
$response["special_response"]["image"] = $image_url;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue