wikipedia.php 958 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. function wikipedia_results($query, $response)
  3. {
  4. $query_encoded = urlencode($query);
  5. $json_response = json_decode($response, true);
  6. $first_page = array_values($json_response["query"]["pages"])[0];
  7. if (!array_key_exists("missing", $first_page))
  8. {
  9. $description = substr($first_page["extract"], 0, 250) . "...";
  10. $source = check_for_privacy_frontend("https://en.wikipedia.org/wiki/$query");
  11. $response = array(
  12. "special_response" => array(
  13. "response" => htmlspecialchars($description),
  14. "source" => $source
  15. )
  16. );
  17. if (array_key_exists("thumbnail", $first_page))
  18. {
  19. $image_url = $first_page["thumbnail"]["source"];
  20. $response["special_response"]["image"] = $image_url;
  21. }
  22. return $response;
  23. }
  24. }
  25. ?>