mirror of
https://github.com/hnhx/librex.git
synced 2025-04-29 14:09:27 -04:00
added wikipedia results, slightly improved mobile css
This commit is contained in:
parent
499eae094b
commit
4d5eefc986
7 changed files with 91 additions and 6 deletions
|
@ -2,9 +2,9 @@
|
||||||
function get_google_results($query, $page, $type=0)
|
function get_google_results($query, $page, $type=0)
|
||||||
{
|
{
|
||||||
require "config.php";
|
require "config.php";
|
||||||
require_once "results/image.php";
|
require_once "results/google/image.php";
|
||||||
require_once "results/text.php";
|
require_once "results/google/text.php";
|
||||||
require_once "results/video.php";
|
require_once "results/google/video.php";
|
||||||
|
|
||||||
$query_encoded = urlencode($query);
|
$query_encoded = urlencode($query);
|
||||||
|
|
||||||
|
|
59
results/wikipedia.php
Normal file
59
results/wikipedia.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
function wikipedia_results($query)
|
||||||
|
{
|
||||||
|
require "config.php";
|
||||||
|
|
||||||
|
$query_encoded = urlencode($query);
|
||||||
|
|
||||||
|
$mh = curl_multi_init();
|
||||||
|
|
||||||
|
$ch_desc = curl_init("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=$query_encoded");
|
||||||
|
curl_setopt_array($ch_desc, $config_curl_settings);
|
||||||
|
curl_multi_add_handle($mh, $ch_desc);
|
||||||
|
|
||||||
|
$ch_image = curl_init("https://en.wikipedia.org/w/api.php?action=query&titles=$query_encoded&prop=pageimages&format=json&pithumbsize=1000");
|
||||||
|
curl_setopt_array($ch_image, $config_curl_settings);
|
||||||
|
curl_multi_add_handle($mh, $ch_image);
|
||||||
|
|
||||||
|
$running = null;
|
||||||
|
do {
|
||||||
|
curl_multi_exec($mh, $running);
|
||||||
|
} while ($running);
|
||||||
|
|
||||||
|
$json_response_desc = json_decode(curl_multi_getcontent($ch_desc), true);
|
||||||
|
$json_response_image = json_decode(curl_multi_getcontent($ch_image), true);
|
||||||
|
|
||||||
|
$first_page_desc = array_values($json_response_desc["query"]["pages"])[0];
|
||||||
|
$first_page_image = array_values($json_response_image["query"]["pages"])[0];
|
||||||
|
|
||||||
|
if (!array_key_exists("missing", $first_page_desc))
|
||||||
|
{
|
||||||
|
$description = substr($first_page_desc["extract"], 0, 250) . "...";
|
||||||
|
|
||||||
|
if (strpos($description, "may refer to"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
echo "<p id=\"special-result\">";
|
||||||
|
|
||||||
|
if (array_key_exists("thumbnail", $first_page_image))
|
||||||
|
{
|
||||||
|
$img_src = $first_page_image["thumbnail"]["source"];
|
||||||
|
$ch_image = curl_init($first_page_image["thumbnail"]["source"]);
|
||||||
|
curl_setopt_array($ch_image, $config_curl_settings);
|
||||||
|
$image_response = curl_exec($ch_image);
|
||||||
|
$base64_image = base64_encode($image_response);
|
||||||
|
|
||||||
|
echo "<a href=\"data:image/jpeg;base64,$base64_image\" target=\"_blank\">";
|
||||||
|
echo "<img src=\"data:image/jpeg;base64,$base64_image\" id=\"wiki-image\">";
|
||||||
|
echo "</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "$description";
|
||||||
|
echo "<a id=\"wiki-link\" href=\"https://en.wikipedia.org/wiki/$query\">";
|
||||||
|
echo "Wikipedia";
|
||||||
|
echo "</a>";
|
||||||
|
|
||||||
|
echo "</p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -336,7 +336,23 @@ button {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#wiki-image {
|
||||||
|
border: none;
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
width: 50%;
|
||||||
|
max-height: 200px;
|
||||||
|
|
||||||
|
padding-bottom:10px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiki-link {
|
||||||
|
display: flex;
|
||||||
|
margin-top: 16px;
|
||||||
|
font-size:14px;
|
||||||
|
color:#bd93f9;
|
||||||
|
}
|
||||||
|
|
||||||
/* @media START */
|
/* @media START */
|
||||||
|
|
||||||
|
@ -427,6 +443,9 @@ button {
|
||||||
|
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
|
|
||||||
|
width: 98%;
|
||||||
|
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,6 +460,10 @@ button {
|
||||||
#time {
|
#time {
|
||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-container {
|
||||||
|
margin-bottom:130px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @media END */
|
/* @media END */
|
|
@ -10,18 +10,21 @@
|
||||||
{
|
{
|
||||||
$query_lower = strtolower($query);
|
$query_lower = strtolower($query);
|
||||||
|
|
||||||
// Check for currency convesion
|
|
||||||
if (strpos($query_lower, "to"))
|
if (strpos($query_lower, "to"))
|
||||||
{
|
{
|
||||||
require_once "results/currency.php";
|
require_once "results/currency.php";
|
||||||
currency_results($query);
|
currency_results($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for definition
|
|
||||||
else if (strpos($query_lower, "mean"))
|
else if (strpos($query_lower, "mean"))
|
||||||
{
|
{
|
||||||
require_once "results/definition.php";
|
require_once "results/definition.php";
|
||||||
definition_results($query);
|
definition_results($query);
|
||||||
}
|
}
|
||||||
|
else if (5 > count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists
|
||||||
|
{
|
||||||
|
require_once "results/wikipedia.php";
|
||||||
|
wikipedia_results($query_lower);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue