Goosle/engines/special/currency.php
Arnan de Gans 86d0d57dc8 Version 1.1
A quality of life update - Mostly.

1.1 - December 21, 2023
- [new] API search for EZTV TV Shows.
- [new] config.default.php with default settings.
- [new] New option 'imdb_id_search' in 'special' settings in config.php.
- [new] New option 'show_zero_seeders' in config.php.
- [new] Special result and torrent redirect for IMDb IDs.
- [new] Replaced image search with Yahoo! Images.
- [new] Styled 'reset' button for search fields.
- [tweak] Removed 'raw_output' option.
- [tweak] Re-arranged results array to be more logical/easy to use.
- [tweak] Re-arranged code for results to do no double checks for search results.
- [tweak] Added more user-agents.
- [tweak] Torrent results page.
- [tweak] Sanitize scraped data earlier in the process.
- [tweak] Consistent single quotes for arrays.
- [tweak] Consistent spaces, tabs and newlines.
- [fix] Inconsistent input height for search field vs search button.
- [fix] Better check if a search is currency conversion or not.
- [fix] Typos in help.php.
2023-12-21 04:02:42 -06:00

55 lines
1.9 KiB
PHP

<?php
/* ------------------------------------------------------------------------------------
* Goosle - A meta search engine for private and fast internet fun.
*
* COPYRIGHT NOTICE
* Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
*
* COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
* By using this code you agree to indemnify Arnan de Gans from any
* liability that might arise from its use.
------------------------------------------------------------------------------------ */
class CurrencyRequest extends EngineRequest {
public function get_request_url() {
return "https://cdn.moneyconvert.net/api/latest.json";
}
public function parse_results($response) {
$json_response = json_decode($response, true);
if(!empty($json_response)) {
$result = $json_response['rates'];
// Process query
// [0] = AMOUNT
// [1] = FROM CURRENCY
// [2] = (to|in)
// [3] = TO CURRENCY
$query_terms = explode(" ", $this->query);
$amount = floatval($query_terms[0]);
$amount_currency = strtoupper($query_terms[1]);
$conversion_currency = strtoupper($query_terms[3]);
// Unknown/misspelled currencies
if (!array_key_exists($amount_currency, $result) || !array_key_exists($conversion_currency, $result)) {
return array();
}
// Calculate exchange rate
$conversion = round(($result[$conversion_currency] / $result[$amount_currency]) * $amount, 4);
return array(
"title" => "Currency conversion:",
"text" => "$amount $amount_currency = $conversion $conversion_currency",
"source" => "https://moneyconvert.net/"
);
} else {
return array(
"title" => "Uh-oh...",
"text" => "No exchange rates could be loaded. Try again later."
);
}
}
}
?>