wikipedia.php 1.1 KB

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