|
@@ -6,6 +6,80 @@
|
|
|
return $base_url;
|
|
|
}
|
|
|
|
|
|
+ function special_search($query)
|
|
|
+ {
|
|
|
+ $query_lower = strtolower($query);
|
|
|
+
|
|
|
+
|
|
|
+ if (str_contains($query_lower, "to"))
|
|
|
+ convert_currency($query);
|
|
|
+
|
|
|
+
|
|
|
+ else if (str_contains($query_lower, "mean"))
|
|
|
+ define_word($query);
|
|
|
+ }
|
|
|
+
|
|
|
+ function convert_currency($query)
|
|
|
+ {
|
|
|
+ $split_query = explode(" ", $query);
|
|
|
+
|
|
|
+ if (count($split_query) >= 4)
|
|
|
+ {
|
|
|
+ $amount_to_convert = floatval($split_query[0]);
|
|
|
+
|
|
|
+ if ($amount_to_convert != 0)
|
|
|
+ {
|
|
|
+ $base_currency = strtoupper($split_query[1]);
|
|
|
+ $currency_to_convert = strtoupper($split_query[3]);
|
|
|
+
|
|
|
+ $ch = curl_init("https://cdn.moneyconvert.net/api/latest.json");
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ $json_response = json_decode($response, true);
|
|
|
+
|
|
|
+ $rates = $json_response["rates"];
|
|
|
+
|
|
|
+ if (array_key_exists($base_currency, $rates) && array_key_exists($currency_to_convert, $rates))
|
|
|
+ {
|
|
|
+ $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;
|
|
|
+
|
|
|
+ echo "<p id=\"special-result\">";
|
|
|
+ echo "$amount_to_convert $base_currency = $conversion_result $currency_to_convert";
|
|
|
+ echo "</p>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function define_word($query)
|
|
|
+ {
|
|
|
+ $split_query = explode(" ", $query);
|
|
|
+
|
|
|
+ if (count($split_query) >= 2)
|
|
|
+ {
|
|
|
+ $reversed_split_q = array_reverse($split_query);
|
|
|
+ $word_to_define = $reversed_split_q[1];
|
|
|
+
|
|
|
+ $ch = curl_init("https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define");
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ $json_response = json_decode($response, true);
|
|
|
+
|
|
|
+ if (!array_key_exists("title", $json_response))
|
|
|
+ {
|
|
|
+ $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
|
|
|
+
|
|
|
+ echo "<p id=\"special-result\">";
|
|
|
+ echo "$word_to_define meaning<br/>";
|
|
|
+ echo "<br/>" . $definition . "<br/>";
|
|
|
+ echo "</p>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function fetch_results($query, $page, $get_images=false)
|
|
|
{
|
|
|
require("config.php");
|