added next pages for video results, improved mobile css

This commit is contained in:
hnhx 2022-02-21 22:00:59 +01:00
parent d6ec3a2730
commit 63aee96388
9 changed files with 117 additions and 96 deletions

View File

@ -9,5 +9,5 @@
$results = get_google_results($query, $page, $type);
echo json_encode($results, true);
echo json_encode($results, JSON_PRETTY_PRINT);
?>

View File

@ -6,6 +6,7 @@
<meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="A privacy respecting meta search engine."/>
<meta name="referrer" content="no-referrer">
<link rel="stylesheet" type="text/css" href="static/styles.css"/>
<link rel="shortcut icon" href="static/librex.png" />
</head>

View File

@ -6,6 +6,7 @@
<meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="A privacy respecting meta search engine."/>
<meta name="referrer" content="no-referrer">
<link rel="stylesheet" type="text/css" href="static/styles.css"/>
<link rel="shortcut icon" href="static/librex.png" />
</head>

View File

@ -1,6 +1,4 @@
<?php
function currency_results($query)
{
require "config.php";

View File

@ -33,7 +33,7 @@
array_push($results,
array (
"base64" => $img_base64,
"alt" => $alts[$i]
"alt" => htmlspecialchars($alts[$i])
)
);
}

View File

@ -29,10 +29,12 @@
array_push($results,
array (
"title" => $title->textContent,
"url" => $url,
"base_url" => get_base_url($url),
"description" => $description == null ? "No description was provided for this site." : $description->textContent
"title" => htmlspecialchars($title->textContent),
"url" => htmlspecialchars($url),
"base_url" => htmlspecialchars(get_base_url($url)),
"description" => $description == null ?
"No description was provided for this site." :
htmlspecialchars($description->textContent)
)
);
}

View File

@ -27,9 +27,9 @@
array_push($results,
array (
"title" => $title->textContent,
"url" => $url,
"base_url" => get_base_url($url)
"title" => htmlspecialchars($title->textContent),
"url" => htmlspecialchars($url),
"base_url" => htmlspecialchars(get_base_url($url))
)
);
}

View File

@ -6,6 +6,7 @@
<meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="A privacy respecting meta search engine."/>
<meta name="referrer" content="no-referrer">
<link rel="stylesheet" type="text/css" href="static/styles.css"/>
<link title="LibreX search" type="application/opensearchdescription+xml" href="/opensearch.xml?method=POST" rel="search"/>
<link rel="shortcut icon" href="static/librex.png" />
@ -43,31 +44,24 @@
</form>
<?php
function print_next_pages($page, $button_val, $q)
require_once "google.php";
require_once "config.php";
require_once "tools.php";
function print_next_page_button($page, $button_val, $q, $type)
{
echo "<form id=\"page\" action=\"search.php\" target=\"_top\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">";
echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
echo "<input type=\"hidden\" name=\"q\" value=\"$q\" />";
echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
echo "<button type=\"submit\">$button_val</button>";
echo "</form>";
}
require_once "google.php";
require_once "tools.php";
require_once "config.php";
$page = isset($_REQUEST["p"]) ? (int) htmlspecialchars($_REQUEST["p"]) : 0;
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
$start_time = microtime(true);
$results = get_google_results($query, $page, $type);
$end_time = number_format(microtime(true) - $start_time, 2, '.', '');
echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
if ($type == 0) // text search
function print_text_results($results)
{
global $query;
check_for_special_search($query);
foreach($results as $result)
@ -85,68 +79,86 @@
echo "<span>$description</span>";
echo "</div>";
}
echo "<div class=\"page-container\">";
if ($page != 0)
{
print_next_pages(0, "&lt;&lt;", $query);
print_next_pages($page - 10, "&lt;", $query);
}
for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
{
$page_input = $i * 10;
$page_button = $i + 1;
print_next_pages($page_input, $page_button, $query);
}
print_next_pages($page + 10, "&gt;", $query);
echo "</div>";
}
else if ($type == 1) // image search
{
function print_image_results($results)
{
echo "<div class=\"image-result-container\">";
foreach($results as $result)
{
$src = $result["base64"];
$alt = $result["alt"];
echo "<a title=\"$alt\" href=\"data:image/jpeg;base64,$src\" target=\"_blank\">";
echo "<img src=\"data:image/jpeg;base64,$src\" width=\"350\" height=\"200\">";
echo "</a>";
}
foreach($results as $result)
{
$src = $result["base64"];
$alt = $result["alt"];
echo "<a title=\"$alt\" href=\"data:image/jpeg;base64,$src\" target=\"_blank\">";
echo "<img src=\"data:image/jpeg;base64,$src\" width=\"350\" height=\"200\">";
echo "</a>";
}
echo "</div>";
}
else if ($type == 2) // video search
{
echo "<div class=\"results-wrapper\">";
if ($config_replace_yt_with_invidious != null)
{
echo "<p id=\"special-result\">";
echo "YouTube results got replaced with a privacy friendly Invidious instance.";
echo "</p>";
}
foreach($results as $result)
{
$title = $result["title"];
$url = $result["url"];
$base_url = $result["base_url"];
echo "<div class=\"result-container\">";
echo "<a href=\"$url\">";
echo "$base_url";
echo "<h2>$title</h2>";
echo "</a>";
echo "</div>";
}
}
function print_video_results($results)
{
foreach($results as $result)
{
$title = $result["title"];
$url = $result["url"];
$base_url = $result["base_url"];
echo "<div class=\"result-container\">";
echo "<a href=\"$url\">";
echo "$base_url";
echo "<h2>$title</h2>";
echo "</a>";
echo "</div>";
}
}
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
$start_time = microtime(true);
$results = get_google_results($query, $page, $type);
$end_time = number_format(microtime(true) - $start_time, 2, '.', '');
echo "<p id=\"time\">Fetched the results in $end_time seconds</p>";
switch ($type)
{
case 0:
print_text_results($results);
break;
case 1:
print_image_results($results);
break;
case 2:
print_video_results($results);
break;
default:
print_text_results($results);
break;
}
if ($type != 1 )
{
echo "<div class=\"page-container\">";
if ($page != 0)
{
print_next_page_button(0, "&lt;&lt;", $query, $type);
print_next_page_button($page - 10, "&lt;", $query, $type);
}
for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
{
$page_input = $i * 10;
$page_button = $i + 1;
print_next_page_button($page_input, $page_button, $query, $type);
}
print_next_page_button($page + 10, "&gt;", $query, $type);
echo "</div>";
}

View File

@ -14,7 +14,11 @@ hr {
img {
border: 1px solid #5f6368;
}
}
button {
outline: none;
}
/* .search-container START */
@ -198,10 +202,6 @@ img {
text-decoration: underline;
}
.results-wrapper {
height: 105vh;
}
/* .result-container END */
@ -224,7 +224,7 @@ img {
.page-container {
margin-top:50px;
margin-bottom:100px;
margin-left:15%;
margin-left:10%;
}
.page-container #page {
@ -263,6 +263,7 @@ img {
display: inline;
border:none;
margin-right: 20px;
@ -379,15 +380,17 @@ img {
@media only screen and (max-width:900px) {
.info-container {
.info-container
{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
flex-direction: column;
}
.info-container a {
margin-top: 10px;
.info-container a
{
margin-top:5px;
}
.small-search-container input {
@ -424,11 +427,15 @@ img {
}
#special-result {
width: 80%;
width: 70%;
}
.result-container {
width: 80%;
width: 70%;
}
#time {
margin-top: 30px;
}
}