LibreY

- privacy respecting meta search engine
git clone git://git.acid.vegas/LibreY.git
Log | Files | Refs | Archive | README | LICENSE

definition.php (1096B)

      1 <?php
      2     class DefinitionRequest extends EngineRequest {
      3 
      4         public function get_request_url() {
      5             $split_query = explode(" ", $this->query);
      6             $reversed_split_q = array_reverse($split_query);
      7             $word_to_define = $reversed_split_q[1] == "define" ? $reversed_split_q[0] : $reversed_split_q[1];
      8             return "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
      9         }
     10 
     11         public function parse_results($response) {
     12             $json_response = json_decode($response, true);
     13 
     14             if (!$json_response)
     15                 return array();
     16 
     17             if (!array_key_exists("title", $json_response))
     18             {
     19                 $definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
     20 
     21                 $source = "https://dictionaryapi.dev";
     22                 return array(
     23                     "special_response" => array(
     24                         "response" => htmlspecialchars($definition),
     25                         "source" => $source
     26                     )
     27                 );
     28             }
     29 
     30         }
     31     }
     32 ?>