2022-02-24 01:36:29 -08:00
|
|
|
<?php
|
2022-03-01 08:28:37 -08:00
|
|
|
function wikipedia_results($query, $response)
|
2022-02-24 01:36:29 -08:00
|
|
|
{
|
|
|
|
$query_encoded = urlencode($query);
|
|
|
|
|
|
|
|
$json_response = json_decode($response, true);
|
|
|
|
|
|
|
|
$first_page = array_values($json_response["query"]["pages"])[0];
|
|
|
|
|
|
|
|
if (!array_key_exists("missing", $first_page))
|
|
|
|
{
|
|
|
|
$description = substr($first_page["extract"], 0, 250) . "...";
|
|
|
|
|
2022-06-27 14:00:22 -07:00
|
|
|
$source = check_for_privacy_frontend("https://wikipedia.org/wiki/$query");
|
2022-03-30 04:18:31 -07:00
|
|
|
$response = array(
|
2022-03-03 01:32:46 -08:00
|
|
|
"special_response" => array(
|
2022-05-15 01:34:46 -07:00
|
|
|
"response" => htmlspecialchars($description),
|
2022-05-19 03:46:39 -07:00
|
|
|
"source" => $source
|
2022-03-03 01:32:46 -08:00
|
|
|
)
|
|
|
|
);
|
2022-03-30 04:18:31 -07:00
|
|
|
|
|
|
|
if (array_key_exists("thumbnail", $first_page))
|
2022-04-21 02:02:32 -07:00
|
|
|
{
|
2022-06-27 14:00:22 -07:00
|
|
|
$image_url = $first_page["thumbnail"]["source"];
|
|
|
|
$response["special_response"]["image"] = $image_url;
|
2022-04-21 02:02:32 -07:00
|
|
|
}
|
2022-03-30 04:18:31 -07:00
|
|
|
|
|
|
|
return $response;
|
2022-02-24 01:36:29 -08:00
|
|
|
}
|
|
|
|
}
|
2022-05-15 01:34:46 -07:00
|
|
|
?>
|