rewrote entire css, added torrent search

This commit is contained in:
hnhx 2022-02-24 22:29:10 +01:00
parent 479aa0c3b1
commit 65caead67a
19 changed files with 367 additions and 459 deletions

View File

@ -1,5 +1,6 @@
<?php
require "engines/google.php";
require "engines/bittorrent.php";
if (!isset($_REQUEST["q"]))
{
@ -11,7 +12,7 @@
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
$results = get_google_results($query, $page, $type);
$results = $type != 3 ? get_google_results($query, $page, $type) : get_bittorrent_results($query);
header('Content-Type: application/json');
echo json_encode($results, JSON_PRETTY_PRINT);

View File

@ -8,6 +8,10 @@
// Results will be in this language
$config_google_language = "en";
// Maxmium size of the cache
$config_cache_size = 1024 * 1024 * 1024;
/*
youtube.com results will be replaced with the given invidious instance
Get online invidious instances from here: https://docs.invidious.io/Invidious-Instances.md

View File

@ -12,16 +12,16 @@
</head>
<body>
<div class="donate-container">
<h1>Donate</h1>
<p>Support the host</p>
<span>(Your donation thingy goes here...)</span>
<p>Support the creator</p>
<span>You can donate to hnhx via the XMR address found on the <a href="https://github.com/hnhx/librex/" target="_blank">GitHub repo</a></span>
<span>Monero (XMR): <span style="background-color:black;">41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</span></span>
<img src="static/xmr.png" alt="xmr qr code"/>
</div>
<div class="info-container">
<div class="footer-container">
<a href="/">LibreX</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source code &amp; Other instances</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source &amp; Instance list</a>
<a href="/api.php" target="_blank">API</a>
<a href="/donate.xhtml" id="right">Donate ❤️</a>
</div>

44
engines/bittorrent.php Normal file
View File

@ -0,0 +1,44 @@
<?php
function get_bittorrent_results($query)
{
require "config.php";
$query = urlencode($query);
$results = array();
$url = "https://apibay.org/q.php?q=$query";
$ch = curl_init($url);
curl_setopt_array($ch, $config_curl_settings);
$response = curl_exec($ch);
$json_response = json_decode($response, true);
foreach ($json_response as $response)
{
$hash = $response["info_hash"];
$name = $response["name"];
$seeders = $response["seeders"];
$leechers = $response["leechers"];
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name";
array_push($results,
array (
"hash" => $hash,
"name" => $name,
"seeders" => $seeders,
"leechers" => $leechers,
"magnet" => $magnet
)
);
}
return $results;
}
?>

View File

@ -1,5 +1,5 @@
<?php
function get_google_results($query, $page, $type=0)
function get_google_results($query, $page=0, $type=0)
{
require "config.php";
require_once "results/google/image.php";

View File

@ -13,7 +13,7 @@
require_once "results/special/definition.php";
definition_results($query);
}
else if (5 > count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists
else if (3 > count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists
{
require_once "results/special/wikipedia.php";
wikipedia_results($query_lower);

View File

@ -23,9 +23,9 @@
</div>
</form>
<div class="info-container">
<div class="footer-container">
<a href="/">LibreX</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source code &amp; Other instances</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source &amp; Instance list</a>
<a href="/api.php" target="_blank">API</a>
<a href="/donate.xhtml" id="right">Donate ❤️</a>
</div>

View File

@ -14,6 +14,7 @@
if ($page == 0)
check_for_special_search($query);
echo "<div class=\"text-result-container\">";
foreach($results as $result)
{
$title = $result["title"];
@ -21,7 +22,7 @@
$base_url = $result["base_url"];
$description = $result["description"];
echo "<div class=\"result-container\">";
echo "<div class=\"text-result-wrapper\">";
echo "<a href=\"$url\">";
echo "$base_url";
echo "<h2>$title</h2>";
@ -29,6 +30,7 @@
echo "<span>$description</span>";
echo "</div>";
}
echo "</div>";
}
function print_image_results($results)
@ -45,24 +47,52 @@
echo "</a>";
}
echo "</div>";
echo "</div>";
}
function print_video_results($results)
{
echo "<div class=\"text-result-container\">";
foreach($results as $result)
{
$title = $result["title"];
$url = $result["url"];
$base_url = $result["base_url"];
echo "<div class=\"result-container\">";
echo "<div class=\"text-result-wrapper\">";
echo "<a href=\"$url\">";
echo "$base_url";
echo "<h2>$title</h2>";
echo "</a>";
echo "</div>";
}
echo "</div>";
}
function print_bittorrent_results($results)
{
echo "<div class=\"text-result-container\">";
foreach($results as $result)
{
$hash = $result["hash"];
$name = $result["name"];
$seeders = $result["seeders"];
$leechers = $result["leechers"];
$magnet = $result["magnet"];
echo "<div class=\"text-result-wrapper\">";
echo "<a href=\"$magnet\">";
echo "$hash";
echo "<h2>$name</h2>";
echo "</a>";
echo "<span>SE: $seeders - LE: $leechers</span>";
echo "</div>";
}
echo "</div>";
}
function print_next_page_button($page, $button_val, $q, $type)

View File

@ -28,7 +28,7 @@
$conversion_result = ($currency_to_convert_response / $base_currency_response) * $amount_to_convert;
echo "<p id=\"special-result\">";
echo "<p class=\"special-result-container\">";
echo "$amount_to_convert $base_currency = $conversion_result $currency_to_convert";
echo "</p>";
}

View File

@ -19,7 +19,7 @@
{
$definition = $json_response[0]["meanings"][0]["definitions"][0]["definition"];
echo "<p id=\"special-result\">";
echo "<p class=\"special-result-container\">";
echo "$word_to_define meaning<br/>";
echo "<br/>" . $definition . "<br/>";
echo "</p>";

View File

@ -20,7 +20,7 @@
if (strpos($description, "may refer to"))
return;
echo "<p id=\"special-result\">";
echo "<p class=\"special-result-container\">";
if (array_key_exists("thumbnail", $first_page))
{
@ -31,12 +31,12 @@
$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 "<img src=\"data:image/jpeg;base64,$base64_image\">";
echo "</a>";
}
echo "$description";
echo "<a id=\"wiki-link\" href=\"https://en.wikipedia.org/wiki/$query\">";
echo "<a href=\"https://en.wikipedia.org/wiki/$query\">";
echo "Wikipedia";
echo "</a>";

View File

@ -12,9 +12,8 @@
<link rel="shortcut icon" href="static/librex.png" />
</head>
<body>
<form class="small-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
<form class="sub-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
<a href="/"><img id="logo" src="static/librex.png" alt="librex"></a>
<input type="hidden" name="p" value="0">
<input type="text" name="q"
<?php
$query = trim($_REQUEST["q"]);
@ -34,10 +33,12 @@
echo "<input type=\"hidden\" name=\"type\" value=\"$type\"/>";
?>
<button type="submit" style="display:none;"></button>
<div class="result-change">
<button name="type" value="0"><img src="static/text_result.png" id="change-image" style="width:20px;">Text</button>
<button name="type" value="1"><img src="static/image_result.png" id="change-image">Images</button>
<button name="type" value="2"><img src="static/video_result.png" id="change-image" style="width:40px;">Videos</button>
<input type="hidden" name="p" value="0">
<div class="sub-search-button-wrapper">
<button name="type" value="0"><img src="static/text_result.png">Text</button>
<button name="type" value="1"><img src="static/image_result.png">Images</button>
<button name="type" value="2"><img src="static/video_result.png">Videos</button>
<button name="type" value="3"><img src="static/torrent_result.png">Torrents</button>
</div>
<hr>
@ -48,17 +49,18 @@
require_once "engines/google.php";
require_once "engines/special.php";
require_once "misc/tools.php";
require_once "engines/bittorrent.php";
require_once "config.php";
$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);
$results = $type != 3 ? get_google_results($query, $page, $type) : get_bittorrent_results($query);
$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:
@ -70,14 +72,17 @@
case 2:
print_video_results($results);
break;
case 3:
print_bittorrent_results($results);
break;
default:
print_text_results($results);
break;
}
if ($type != 1 )
if ($type != 1 && $type != 3 )
{
echo "<div class=\"page-container\">";
echo "<div class=\"next-page-button-wrapper\">";
if ($page != 0)
{
@ -99,9 +104,9 @@
}
?>
<div class="info-container">
<div class="footer-container">
<a href="/">LibreX</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source code &amp; Other instances</a>
<a href="https://github.com/hnhx/librex/" target="_blank">Source &amp; Instance list</a>
<a href="/api.php" target="_blank">API</a>
<a href="/donate.xhtml" id="right">Donate ❤️</a>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -1,471 +1,295 @@
html {
color: #e8eaed;
background-color: #202124;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
overflow-x: hidden;
}
hr {
margin-top: 30px;
}
img {
border: 1px solid #5f6368;
font-size: 16px;
}
input,
button {
outline: none;
}
/* .search-container START */
.search-container {
max-width: 560px;
text-align: center;
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
margin-top:12%;
padding-left: 16px;
padding-right: 16px;
}
.search-container input {
display: flex;
flex-grow: 1;
}
.search-container button:hover {
border: 1px solid #5f6368;
cursor:pointer;
}
.search-container h1 {
font-size: 70px;
}
/* .search-container END */
/* .small-search-container START */
.small-search-container {
margin:2%;
}
.small-search-container input {
width: 600px;
}
.small-search-container h1, a {
display: inline;
color:inherit;
text-decoration: none;
}
/* .small-search-container END */
/*
.search-container,
.small-search-container
START
*/
.search-container input ,
.small-search-container input {
color: inherit;
background-color: inherit;
padding: 10px;
font-size: 16px;
border: 1px solid #5f6368;
border-radius: 25px;
}
.search-container input:hover ,
.small-search-container input:hover {
background-color: #303134;
border-color: #303134;
}
.search-container input:focus ,
.small-search-container input:focus {
outline: none;
}
/*
.search-container,
.small-search-container
END
*/
/* .search-button-wrapper START */
.search-button-wrapper {
display:flex;
flex-direction: column;
}
.search-button-wrapper button {
color: inherit;
background-color: #303134;
font-size: 14px;
border: none;
border-radius: 4px;
width: auto;
padding: 13px 10px 13px 10px;
margin-top: 30px;
}
/* .search-button-wrapper END */
/* .info-container START */
.info-container {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color:#171717;
font-size:15px;
padding-top: 15px;
padding-bottom: 15px;
border-top:1px solid #303134;
}
.info-container a , p {
color:#999da2;
text-decoration: none;
}
.info-container a {
padding-left:20px;
font-size:16px;
}
.info-container #right {
float:right;
padding-right:20px;
}
.info-container a:hover {
text-decoration: underline;
}
/* .info-container END */
/* .result-container START */
.result-container {
max-width: 550px;
margin-top: 30px;
}
.result-container span {
font-size: 15px;
}
.result-container a {
font-size: 14px;
color:#bdc1c6;
text-decoration: none;
}
.result-container h2 {
font-size: 20px;
color:#8ab4f8;
padding-top:5px;
margin-top:1px;
}
.result-container h2:hover {
text-decoration: underline;
}
.result-container a:visited h2 {
color: #bd93f9;
}
/* .result-container END */
/* .image-result-container START */
.image-result-container {
margin-left:8%;
margin-right:8%;
margin-bottom:30px;
}
/* .image-result-container END */
/* .page-container START */
.page-container {
margin-top:50px;
margin-bottom:100px;
margin-left:10%;
}
.page-container #page {
display: inline;
}
.page-container #page button {
color:#8ab4f8;
background-color: inherit;
padding-right: 10px;
font-size: 16px;
border: none;
}
.page-container #page button:hover {
cursor:pointer;
text-decoration: underline;
}
/* .page-container END */
/* .result-change START */
.result-change {
width: 100%;
}
.result-change button {
color:#bd93f9;
background-color: inherit;
display: inline;
border:none;
margin-right: 20px;
font-size: 18px;
}
.result-change button:hover {
cursor: pointer;
}
.result-change #change-image {
width: 25px;
height: 25px;
vertical-align: middle;
border:none;
}
/* .result-change END */
/* .donate-container START */
.donate-container {
margin-left: 5%;
margin-right: 5%;
padding-right: 10px;
padding-left: 10px;
margin-top: 13%;
border: 1px solid #bdc1c6;
border-top: none;
border-bottom: none;
text-align: center;
}
.donate-container a {
color: #8ab4f8;
text-decoration: underline;
}
/* .donate-container END */
.result-container ,
#time ,
#special-result {
margin-left: 10%;
button {
cursor: pointer;
}
#special-result {
p {
font-size:18px;
color: #999da2;
}
a,
.text-result-wrapper a:hover {
text-decoration: none;
}
a:hover, .text-result-wrapper h2:hover {
text-decoration: underline;
}
.search-container {
text-align: center;
margin-top:15%;
}
.search-container h1 {
font-size: 70px;
}
.search-container input,
.sub-search-container input {
width: 500px;
color: inherit;
background-color: inherit;
padding: 10px;
font-size: inherit;
font-family: inherit;
border: 1px solid #5f6368;
border-radius: 25px;
}
.search-button-wrapper button {
color: inherit;
background-color: #303134;
font-size: 14px;
border: none;
border-radius: 4px;
padding: 13px 10px 13px 10px;
margin: 30px 60px 0px 60px;
}
.sub-search-container {
margin: 2%;
}
.sub-search-container hr {
margin-top: 35px;
margin-bottom: 35px;
}
.sub-search-container input {
margin-bottom: 40px;
width: 600px;
}
.sub-search-container #logo {
vertical-align: middle;
margin-right: 50px;
}
.sub-search-button-wrapper {
margin-left: 150px;
}
.search-button-wrapper button:hover {
border: 1px solid #5f6368;
cursor: pointer;
}
.sub-search-button-wrapper img {
vertical-align: middle;
margin-right: 10px;
}
.sub-search-button-wrapper button {
border: none;
background-color: inherit;
color: #bd93f9;
font-size: 18px;
margin-right: 25px;
}
.text-result-container,
.special-result-container,
#time,
.next-page-button-wrapper {
margin-left:10%;
}
.text-result-container
{
margin-bottom:100px;
}
.special-result-container {
padding: 10px;
border: 1px solid #bdc1c6;
width: 500px;
}
#logo {
vertical-align: middle;
width: 80px;
height: 80px;
border: none;
.text-result-wrapper {
max-width: 500px;
margin-top: 35px;
}
#wiki-image {
border: none;
display: flex;
.text-result-wrapper a {
font-size: 14px;
color:#bdc1c6;
}
.text-result-wrapper h2 {
font-size: 20px;
color: #8ab4f8;
padding-top: 5px;
margin-top: 1px;
}
.special-result-container img {
display: flex;
max-width: 50%;
max-height: 200px;
padding-bottom:10px;
margin-left:auto;
margin-right:auto;
}
}
#wiki-link {
.special-result-container a {
display: flex;
margin-top: 16px;
margin-top: 10px;
color: #bd93f9;
font-size:14px;
color:#bd93f9;
}
/* @media START */
.next-page-button-wrapper {
margin-top:-50px;
margin-bottom:100px;
}
@media only screen and (min-width:900px) {
.search-button-wrapper {
flex-direction: row;
}
.next-page-button-wrapper button {
border:none;
background-color: inherit;
color: #8ab4f8;
font-size: 18px;
}
.search-button-wrapper button {
width: auto;
margin-left: auto;
margin-right: auto;
}
.next-page-button-wrapper #page {
display: inline;
}
.search-container input {
width: auto;
}
.image-result-container {
margin-left:auto;
margin-right: auto;
margin-bottom: 60px;
}
.small-search-container input {
margin-left: 40px;
}
.image-result-container img {
margin: 10px;
border: 1px solid #5f6368;
}
hr {
margin-bottom: -20px;
}
.donate-container {
text-align: center;
word-wrap: break-word;
margin-left: auto;
margin-right: auto;
margin-top: 8%;
border: 1px solid #bdc1c6;
max-width: 500px;
padding:0px 20px 20px 20px;
}
.result-change {
margin-left: 9%
}
.donate-container img {
margin-top:10px;
}
.donate-container a {
color: #bd93f9;
}
.footer-container {
position: fixed;
left: 0;
bottom: 0;
width: 100vw;
background-color: #171717;
padding-top: 15px;
padding-bottom: 15px;
border-top: 1px solid #303134;
text-align: center;
}
.footer-container a {
color: #999da2;
margin-left: 15px;
margin-right: 15px;
}
/* mobile view */
@media only screen and (max-width: 900px) {
.search-container input {
width: 80%;
}
.search-button-wrapper button {
display: table-row;
margin: 30px 0px 0px 0px;
width: 80%;
}
.footer-container a {
margin:10px;
}
.sub-search-container {
margin-left:auto;
margin-right:auto;
text-align: center;
}
.sub-search-container #logo {
margin-left:auto;
margin-right:auto;
display: block;
.donate-container {
margin-left: 25%;
margin-right: 25%;
}
img {
margin:10px;
}
#time {
margin-top: 60px;
}
}
@media only screen and (max-width:900px) {
.info-container
{
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.info-container a
{
margin-top:5px;
}
.small-search-container input {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
width: 80%;
}
.small-search-container a {
display: block;
width: 100%;
text-align: center;
margin-top:10px;
}
.result-change {
margin-left: auto;
margin-right: auto;
text-align: center;
margin-top: 5px;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 98%;
margin-bottom: 30px;
}
#special-result {
width: 70%;
}
.result-container {
width: 70%;
}
#time {
margin-top: 30px;
}
.page-container {
margin-bottom:130px;
}
.sub-search-container input {
width: 80%;
margin-top:30px;
}
/* @media END */
.sub-search-button-wrapper {
margin:0;
padding:0;
display: flex;
}
.sub-search-button-wrapper img {
margin:0;
padding:0;
margin-bottom:20px;
}
.sub-search-button-wrapper button {
margin-left:auto;
margin-right:auto;
padding:0;
display: flex;
flex-direction: column;
align-items: center;
}
.special-result-container {
max-width: 80%;
}
.donate-container {
max-width: 80%;
}
.donate-container img {
display: block;
margin-left:auto;
margin-right:auto;
}
.image-result-container img {
display:block;
margin-left:auto;
margin-right:auto;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
static/torrent_result.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
static/xmr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB