reorganized the whole code base , added disable torrent search to config
|
@ -38,7 +38,7 @@ All you need is a webserver (e.g.: nginx) and PHP, and you are good to go.
|
|||
|
||||
# API
|
||||
Example API request: `.../api.php?q=gentoo&p=2&type=0` <br/>
|
||||
Where `q` is the keyword, `p` is the result page (the first page is `0`) and `type` is the search type (`0`=text, `1`=image, `2`=video)
|
||||
Where `q` is the keyword, `p` is the result page (the first page is `0`) and `type` is the search type (`0`=text, `1`=image, `2`=video, `3`=torrent)
|
||||
<br/><br/>
|
||||
JSON result:
|
||||
+ In case of text search:
|
||||
|
@ -52,6 +52,12 @@ JSON result:
|
|||
+ `title`: Title of the result video
|
||||
+ `url`: Full URL of the video
|
||||
+ `base_url`: The base URL of the result (e.g.: http://youtube.com/watch -> http://youtube.com/)
|
||||
+ In case of torrent search:
|
||||
+ `hash`: Hash of the torrent
|
||||
+ `name`: Name of the torrent
|
||||
+ `seeders`: The amount of seeders
|
||||
+ `leechers`: The amount of leechers
|
||||
+ `magnet`: The magnet link
|
||||
|
||||
<br/>
|
||||
The API also supports both GET and POST requests
|
||||
|
|
36
api.php
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
require "engines/google.php";
|
||||
require "engines/bittorrent.php";
|
||||
require "config.php";
|
||||
|
||||
if (!isset($_REQUEST["q"]))
|
||||
{
|
||||
|
@ -8,11 +7,40 @@
|
|||
die();
|
||||
}
|
||||
|
||||
$query = $_REQUEST["q"];
|
||||
$query_encoded = urlencode($_REQUEST["q"]);
|
||||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
||||
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
|
||||
|
||||
$results = $type != 3 ? get_google_results($query, $page, $type) : get_bittorrent_results($query);
|
||||
$results = array();
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 0:
|
||||
require "engines/google/text.php";
|
||||
$results = get_text_results($query_encoded, $page);
|
||||
break;
|
||||
case 1:
|
||||
require "engines/google/image.php";
|
||||
$results = get_image_results($query_encoded);
|
||||
break;
|
||||
case 2:
|
||||
require "engines/google/video.php";
|
||||
$results = get_video_results($query_encoded, $page);
|
||||
break;
|
||||
case 3:
|
||||
if ($config_disable_bittorent_search)
|
||||
$results = array("error" => "disabled");
|
||||
else
|
||||
{
|
||||
require "engines/bittorrent/thepiratebay.php";
|
||||
$results = get_thepiratebay_results($query_encoded);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
require "engines/google/text.php";
|
||||
$results = get_text_results($query_encoded, $page);
|
||||
break;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($results, JSON_PRETTY_PRINT);
|
||||
|
|
|
@ -8,9 +8,8 @@
|
|||
// Results will be in this language
|
||||
$config_google_language = "en";
|
||||
|
||||
// Maxmium size of the cache
|
||||
$config_cache_size = 1024 * 1024 * 1024;
|
||||
|
||||
// Disable BitTorrent search
|
||||
$config_disable_bittorent_search = false;
|
||||
|
||||
/*
|
||||
youtube.com results will be replaced with the given invidious instance
|
||||
|
|
13
donate.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php require "static/header.html"; ?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="donate-container">
|
||||
<p>Support the host</p>
|
||||
<span>(Your donation thingy goes here...)</span>
|
||||
<p>Support the creator</p>
|
||||
<span>Monero (XMR): <br/><br/><span style="background-color:black;">41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</span></span>
|
||||
<img src="static/images/xmr.png" alt="xmr qr code"/>
|
||||
</div>
|
||||
|
||||
<?php require "static/footer.html"; ?>
|
29
donate.xhtml
|
@ -1,29 +0,0 @@
|
|||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>LibreX - Donate ❤️</title>
|
||||
<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>
|
||||
<body>
|
||||
<div class="donate-container">
|
||||
<p>Support the host</p>
|
||||
<span>(Your donation thingy goes here...)</span>
|
||||
<p>Support the creator</p>
|
||||
<span>Monero (XMR): <span style="background-color:black;">41dGQr9EwZBfYBY3fibTtJZYfssfRuzJZDSVDeneoVcgckehK3BiLxAV4FvEVJiVqdiW996zvMxhFB8G8ot9nBFqQ84VkuC</span></span>
|
||||
<img src="static/xmr.png" alt="xmr qr code"/>
|
||||
</div>
|
||||
|
||||
<div class="footer-container">
|
||||
<a href="/">LibreX</a>
|
||||
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
||||
<a href="/api.php" target="_blank">API</a>
|
||||
<a href="/donate.xhtml" id="right">Donate ❤️</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,20 +1,16 @@
|
|||
<?php
|
||||
|
||||
function get_bittorrent_results($query)
|
||||
function get_thepiratebay_results($query)
|
||||
{
|
||||
require "config.php";
|
||||
require "misc/tools.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);
|
||||
|
||||
|
||||
$response = request($url);
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
foreach ($json_response as $response)
|
||||
|
@ -41,4 +37,28 @@
|
|||
return $results;
|
||||
|
||||
}
|
||||
|
||||
function print_thepiratebay_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>";
|
||||
}
|
||||
?>
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
function get_google_results($query, $page=0, $type=0)
|
||||
{
|
||||
require "config.php";
|
||||
require_once "results/google/image.php";
|
||||
require_once "results/google/text.php";
|
||||
require_once "results/google/video.php";
|
||||
|
||||
$query_encoded = urlencode($query);
|
||||
|
||||
$google = "https://www.google.$config_google_domain/search?&q=$query_encoded&start=$page&hl=$config_google_language";
|
||||
if ($type == 1)
|
||||
$google .= "&tbm=isch";
|
||||
else if ($type == 2)
|
||||
$google .= "&tbm=vid";
|
||||
|
||||
$ch = curl_init($google);
|
||||
curl_setopt_array($ch, $config_curl_settings);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
|
||||
{
|
||||
echo "<p id=\"special-result\">";
|
||||
echo "Google rejected the request! :C";
|
||||
echo "</p>";
|
||||
die();
|
||||
}
|
||||
|
||||
$htmlDom = new DOMDocument;
|
||||
@$htmlDom->loadHTML($response);
|
||||
$xpath = new DOMXPath($htmlDom);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 0:
|
||||
return text_results($xpath);
|
||||
case 1:
|
||||
return image_results($xpath);
|
||||
case 2:
|
||||
return video_results($xpath);
|
||||
default:
|
||||
return text_results($xpath);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,7 +1,12 @@
|
|||
<?php
|
||||
function image_results($xpath)
|
||||
function get_image_results($query)
|
||||
{
|
||||
require "config.php";
|
||||
require "misc/tools.php";
|
||||
|
||||
$url = "https://www.google.$config_google_domain/search?&q=$query&hl=$config_google_language&tbm=isch";
|
||||
$response = request($url);
|
||||
$xpath = get_xpath($response);
|
||||
|
||||
$mh = curl_multi_init();
|
||||
$chs = $alts = $results = array();
|
||||
|
@ -40,4 +45,21 @@
|
|||
|
||||
return $results;
|
||||
}
|
||||
|
||||
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>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
?>
|
|
@ -1,9 +1,13 @@
|
|||
<?php
|
||||
|
||||
function text_results($xpath)
|
||||
function get_text_results($query, $page=0)
|
||||
{
|
||||
require_once "misc/tools.php";
|
||||
require "config.php";
|
||||
require "misc/tools.php";
|
||||
|
||||
$url = "https://www.google.$config_google_domain/search?&q=$query&start=$page&hl=$config_google_language";
|
||||
$response = request($url);
|
||||
$xpath = get_xpath($response);
|
||||
|
||||
$results = array();
|
||||
|
||||
|
@ -41,4 +45,29 @@
|
|||
|
||||
return $results;
|
||||
}
|
||||
|
||||
function print_text_results($results)
|
||||
{
|
||||
global $query , $page;
|
||||
|
||||
//check_for_special_search($query);
|
||||
|
||||
echo "<div class=\"text-result-container\">";
|
||||
foreach($results as $result)
|
||||
{
|
||||
$title = $result["title"];
|
||||
$url = $result["url"];
|
||||
$base_url = $result["base_url"];
|
||||
$description = $result["description"];
|
||||
|
||||
echo "<div class=\"text-result-wrapper\">";
|
||||
echo "<a href=\"$url\">";
|
||||
echo "$base_url";
|
||||
echo "<h2>$title</h2>";
|
||||
echo "</a>";
|
||||
echo "<span>$description</span>";
|
||||
echo "</div>";
|
||||
}
|
||||
echo "</div>";
|
||||
}
|
||||
?>
|
|
@ -1,8 +1,12 @@
|
|||
<?php
|
||||
function video_results($xpath)
|
||||
function get_video_results($query, $page=0)
|
||||
{
|
||||
require_once "misc/tools.php";
|
||||
require "config.php";
|
||||
require "misc/tools.php";
|
||||
|
||||
$url = "https://www.google.$config_google_domain/search?&q=$query&start=$page&hl=$config_google_language&tbm=vid";
|
||||
$response = request($url);
|
||||
$xpath = get_xpath($response);
|
||||
|
||||
$results = array();
|
||||
|
||||
|
@ -36,4 +40,25 @@
|
|||
|
||||
return $results;
|
||||
}
|
||||
|
||||
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=\"text-result-wrapper\">";
|
||||
echo "<a href=\"$url\">";
|
||||
echo "$base_url";
|
||||
echo "<h2>$title</h2>";
|
||||
echo "</a>";
|
||||
echo "</div>";
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
?>
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
function check_for_special_search($query)
|
||||
{
|
||||
$query_lower = strtolower($query);
|
||||
|
||||
if (strpos($query_lower, "to"))
|
||||
{
|
||||
require_once "results/special/currency.php";
|
||||
currency_results($query);
|
||||
}
|
||||
else if (strpos($query_lower, "mean"))
|
||||
{
|
||||
require_once "results/special/definition.php";
|
||||
definition_results($query);
|
||||
}
|
||||
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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -2,6 +2,7 @@
|
|||
function currency_results($query)
|
||||
{
|
||||
require "config.php";
|
||||
require_once "misc/tools.php";
|
||||
|
||||
$split_query = explode(" ", $query);
|
||||
|
||||
|
@ -14,9 +15,8 @@
|
|||
$base_currency = strtoupper($split_query[1]);
|
||||
$currency_to_convert = strtoupper($split_query[3]);
|
||||
|
||||
$ch = curl_init("https://cdn.moneyconvert.net/api/latest.json");
|
||||
curl_setopt_array($ch, $config_curl_settings);
|
||||
$response = curl_exec($ch);
|
||||
$url = "https://cdn.moneyconvert.net/api/latest.json";
|
||||
$response = request($url);
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
$rates = $json_response["rates"];
|
|
@ -2,6 +2,7 @@
|
|||
function definition_results($query)
|
||||
{
|
||||
require "config.php";
|
||||
require_once "misc/tools.php";
|
||||
|
||||
$split_query = explode(" ", $query);
|
||||
|
||||
|
@ -10,9 +11,8 @@
|
|||
$reversed_split_q = array_reverse($split_query);
|
||||
$word_to_define = $reversed_split_q[1];
|
||||
|
||||
$ch = curl_init("https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define");
|
||||
curl_setopt_array($ch, $config_curl_settings);
|
||||
$response = curl_exec($ch);
|
||||
$url = "https://api.dictionaryapi.dev/api/v2/entries/en/$word_to_define";
|
||||
$response = request($url);
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
if (!array_key_exists("title", $json_response))
|
|
@ -2,13 +2,12 @@
|
|||
function wikipedia_results($query)
|
||||
{
|
||||
require "config.php";
|
||||
require_once "misc/tools.php";
|
||||
|
||||
$query_encoded = urlencode($query);
|
||||
|
||||
$ch = curl_init("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded");
|
||||
curl_setopt_array($ch, $config_curl_settings);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
|
||||
$response = request($url);
|
||||
$json_response = json_decode($response, true);
|
||||
|
||||
$first_page = array_values($json_response["query"]["pages"])[0];
|
||||
|
@ -25,9 +24,8 @@
|
|||
if (array_key_exists("thumbnail", $first_page))
|
||||
{
|
||||
$img_src = $first_page["thumbnail"]["source"];
|
||||
$ch_image = curl_init($first_page["thumbnail"]["source"]);
|
||||
curl_setopt_array($ch_image, $config_curl_settings);
|
||||
$image_response = curl_exec($ch_image);
|
||||
$url = $first_page["thumbnail"]["source"];
|
||||
$image_response = request($url);
|
||||
$base64_image = base64_encode($image_response);
|
||||
|
||||
echo "<a href=\"data:image/jpeg;base64,$base64_image\" target=\"_blank\">";
|
17
index.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php require "static/header.html"; ?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<form class="search-container" action="search.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<h1>Libre<span style="color:#bd93f9;">X</span></h1>
|
||||
<input type="text" name="q"/>
|
||||
<input type="hidden" name="p" value="0"/>
|
||||
<input type="hidden" name="type" value="0"/>
|
||||
<input type="submit" style="display:none"/>
|
||||
<div class="search-button-wrapper">
|
||||
<button name="type" value="0" type="submit">Search with LibreX</button>
|
||||
<button name="type" value="1" type="submit">Search images with LibreX</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php require "static/footer.html"; ?>
|
33
index.xhtml
|
@ -1,33 +0,0 @@
|
|||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<title>LibreX</title>
|
||||
<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>
|
||||
<body>
|
||||
<form class="search-container" action="search.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<h1>Libre<span style="color:#bd93f9;">X</span></h1>
|
||||
<input type="text" name="q"/>
|
||||
<input type="hidden" name="p" value="0"/>
|
||||
<input type="hidden" name="type" value="0"/>
|
||||
<input type="submit" style="display:none"/>
|
||||
<div class="search-button-wrapper">
|
||||
<button name="type" value="0" type="submit">Search with LibreX</button>
|
||||
<button name="type" value="1" type="submit">Search images with LibreX</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="footer-container">
|
||||
<a href="/">LibreX</a>
|
||||
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
||||
<a href="/api.php" target="_blank">API</a>
|
||||
<a href="/donate.xhtml" id="right">Donate ❤️</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -6,102 +6,33 @@
|
|||
return $base_url;
|
||||
}
|
||||
|
||||
|
||||
function print_text_results($results)
|
||||
function get_xpath($response)
|
||||
{
|
||||
global $query , $page;
|
||||
$htmlDom = new DOMDocument;
|
||||
@$htmlDom->loadHTML($response);
|
||||
$xpath = new DOMXPath($htmlDom);
|
||||
|
||||
if ($page == 0)
|
||||
check_for_special_search($query);
|
||||
|
||||
echo "<div class=\"text-result-container\">";
|
||||
foreach($results as $result)
|
||||
{
|
||||
$title = $result["title"];
|
||||
$url = $result["url"];
|
||||
$base_url = $result["base_url"];
|
||||
$description = $result["description"];
|
||||
|
||||
echo "<div class=\"text-result-wrapper\">";
|
||||
echo "<a href=\"$url\">";
|
||||
echo "$base_url";
|
||||
echo "<h2>$title</h2>";
|
||||
echo "</a>";
|
||||
echo "<span>$description</span>";
|
||||
echo "</div>";
|
||||
}
|
||||
echo "</div>";
|
||||
return $xpath;
|
||||
}
|
||||
|
||||
function print_image_results($results)
|
||||
function request($url)
|
||||
{
|
||||
echo "<div class=\"image-result-container\">";
|
||||
require "config.php";
|
||||
|
||||
foreach($results as $result)
|
||||
{
|
||||
$src = $result["base64"];
|
||||
$alt = $result["alt"];
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, $config_curl_settings);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
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>";
|
||||
return $response;
|
||||
}
|
||||
|
||||
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=\"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)
|
||||
function print_next_page_button($text, $page, $query, $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=\"q\" value=\"$query\" />";
|
||||
echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
|
||||
echo "<button type=\"submit\">$button_val</button>";
|
||||
echo "<button type=\"submit\">$text</button>";
|
||||
echo "</form>";
|
||||
}
|
||||
?>
|
103
search.php
|
@ -1,19 +1,10 @@
|
|||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<?php require "static/header.html"; ?>
|
||||
<title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
|
||||
<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" />
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
<a href="/"><img id="logo" src="static/images/librex.png" alt="librex"></a>
|
||||
<input type="text" name="q"
|
||||
<?php
|
||||
$query = trim($_REQUEST["q"]);
|
||||
|
@ -35,80 +26,104 @@
|
|||
<button type="submit" style="display:none;"></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>
|
||||
<button name="type" value="0"><img src="static/images/text_result.png">Text</button>
|
||||
<button name="type" value="1"><img src="static/images/image_result.png">Images</button>
|
||||
<button name="type" value="2"><img src="static/images/video_result.png">Videos</button>
|
||||
<button name="type" value="3"><img src="static/images/torrent_result.png">Torrents</button>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require "config.php";
|
||||
|
||||
require_once "engines/google.php";
|
||||
require_once "engines/special.php";
|
||||
require_once "misc/tools.php";
|
||||
require_once "engines/bittorrent.php";
|
||||
require_once "config.php";
|
||||
function check_for_special_search($query)
|
||||
{
|
||||
$query_lower = strtolower($query);
|
||||
|
||||
if (strpos($query_lower, "to"))
|
||||
{
|
||||
require "engines/special/currency.php";
|
||||
currency_results($query);
|
||||
}
|
||||
else if (strpos($query_lower, "mean"))
|
||||
{
|
||||
require "engines/special/definition.php";
|
||||
definition_results($query);
|
||||
}
|
||||
else if (3 > count(explode(" ", $query))) // long queries usually wont return a wiki result thats why this check exists
|
||||
{
|
||||
require "engines/special/wikipedia.php";
|
||||
wikipedia_results($query_lower);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
||||
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
|
||||
|
||||
$start_time = microtime(true);
|
||||
$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>";
|
||||
$query_encoded = urlencode($query);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 0:
|
||||
require "engines/google/text.php";
|
||||
$results = get_text_results($query_encoded, $page);
|
||||
if ($page == 0)
|
||||
check_for_special_search($query);
|
||||
print_text_results($results);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
require "engines/google/image.php";
|
||||
$results = get_image_results($query_encoded);
|
||||
print_image_results($results);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
require "engines/google/video.php";
|
||||
$results = get_video_results($query_encoded, $page);
|
||||
print_video_results($results);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
print_bittorrent_results($results);
|
||||
if ($config_disable_bittorent_search)
|
||||
echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
|
||||
else
|
||||
{
|
||||
require "engines/bittorrent/thepiratebay.php";
|
||||
$results = get_thepiratebay_results($query_encoded);
|
||||
print_thepiratebay_results($results);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
require "engines/google/text.php";
|
||||
$results = get_text_results($query_encoded, $page);
|
||||
print_text_results($results);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type != 1 && $type != 3 )
|
||||
|
||||
if ($type == 0 || $type == 2 )
|
||||
{
|
||||
echo "<div class=\"next-page-button-wrapper\">";
|
||||
|
||||
if ($page != 0)
|
||||
{
|
||||
print_next_page_button(0, "<<", $query, $type);
|
||||
print_next_page_button($page - 10, "<", $query, $type);
|
||||
print_next_page_button("<<", 0, $query, $type);
|
||||
print_next_page_button("<", $page - 10, $query, $type);
|
||||
}
|
||||
|
||||
for ($i=$page / 10; $page / 10 + 10 > $i; $i++)
|
||||
{
|
||||
$page_input = $i * 10;
|
||||
$page_button = $i + 1;
|
||||
print_next_page_button($i + 1, $i * 10, $query, $type);
|
||||
|
||||
print_next_page_button($page_input, $page_button, $query, $type);
|
||||
}
|
||||
|
||||
print_next_page_button($page + 10, ">", $query, $type);
|
||||
print_next_page_button(">", $page + 10, $query, $type);
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="footer-container">
|
||||
<a href="/">LibreX</a>
|
||||
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
||||
<a href="/api.php" target="_blank">API</a>
|
||||
<a href="/donate.xhtml" id="right">Donate ❤️</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php require "static/footer.html"; ?>
|
8
static/footer.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<div class="footer-container">
|
||||
<a href="/">LibreX</a>
|
||||
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
||||
<a href="/api.php" target="_blank">API</a>
|
||||
<a href="/donate.php" id="right">Donate ❤️</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
11
static/header.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html >
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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/images/librex.png" />
|
||||
|
Before Width: | Height: | Size: 5 KiB After Width: | Height: | Size: 5 KiB |
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |