LibreY/engines/special/definition.php

32 lines
1.0 KiB
PHP
Raw Normal View History

<?php
2023-08-21 08:29:50 -07:00
class DefinitionRequest extends EngineRequest {
2023-08-21 08:29:50 -07:00
public function get_request_url() {
$split_query = explode(" ", $this->query);
$reversed_split_q = array_reverse($split_query);
$word_to_define = $reversed_split_q[1];
2023-08-21 08:29:50 -07:00
return "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
}
public function get_results() {
$response = curl_multi_getcontent($this->ch);
$json_response = json_decode($response, true);
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
)
);
}
2023-08-21 08:29:50 -07:00
}
}
?>