mirror of
https://git.bakhai.co.in/FbIN/LibreY.git
synced 2025-11-05 12:31:30 +05:30
32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?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
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|
|
}
|
|
?>
|