2022-02-24 04:36:29 -05:00
|
|
|
<?php
|
2022-03-01 11:28:37 -05:00
|
|
|
function wikipedia_results($query, $response)
|
2022-02-24 04:36:29 -05: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-04-21 05:02:32 -04:00
|
|
|
$source = check_for_privacy_frontend("https://wikipedia.org/wiki/$query");
|
2022-03-30 07:18:31 -04:00
|
|
|
$response = array(
|
2022-03-03 04:32:46 -05:00
|
|
|
"special_response" => array(
|
|
|
|
"response" => $description,
|
|
|
|
"source" => $source
|
|
|
|
)
|
|
|
|
);
|
2022-03-30 07:18:31 -04:00
|
|
|
|
|
|
|
if (array_key_exists("thumbnail", $first_page))
|
2022-04-21 05:02:32 -04:00
|
|
|
{
|
|
|
|
$img_url = $first_page["thumbnail"]["source"];
|
|
|
|
$img_src = request($img_url);
|
|
|
|
$base64_src = base64_encode($img_src);
|
|
|
|
$response["special_response"]["image"] = $base64_src;
|
|
|
|
}
|
2022-03-30 07:18:31 -04:00
|
|
|
|
|
|
|
return $response;
|
2022-02-24 04:36:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|