mirror of
https://github.com/hnhx/librex.git
synced 2025-04-29 14:09:27 -04:00
added "my ip", "my user agent" special queries, settings set via parameters now persist, changed "type" to "t" for consistency
This commit is contained in:
parent
47c9bc2573
commit
ddaceff4e5
9 changed files with 76 additions and 16 deletions
6
api.php
6
api.php
|
@ -4,11 +4,11 @@
|
|||
|
||||
if (!isset($_REQUEST["q"]))
|
||||
{
|
||||
echo "<p>Example API request: <a href=\"./api.php?q=gentoo&p=2&type=0\">./api.php?q=gentoo&p=2&type=0</a></p>
|
||||
echo "<p>Example API request: <a href=\"./api.php?q=gentoo&p=2&t=0\">./api.php?q=gentoo&p=2&t=0</a></p>
|
||||
<br/>
|
||||
<p>\"q\" is the keyword</p>
|
||||
<p>\"p\" is the result page (the first page is 0)</p>
|
||||
<p>\"type\" is the search type (0=text, 1=image, 2=video, 3=torrent)</p>
|
||||
<p>\"t\" is the search type (0=text, 1=image, 2=video, 3=torrent)</p>
|
||||
<br/>
|
||||
<p>The results are going to be in JSON format.</p>
|
||||
<p>The API supports both POST and GET requests.</p>";
|
||||
|
@ -19,7 +19,7 @@
|
|||
$query = $_REQUEST["q"];
|
||||
$query_encoded = urlencode($query);
|
||||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
||||
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
|
||||
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
|
||||
|
||||
$results = array();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
|
||||
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
|
||||
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
|
||||
|
|
|
@ -14,9 +14,24 @@
|
|||
return 1;
|
||||
}
|
||||
else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if (strpos($query_lower, "my") !== false)
|
||||
{
|
||||
if (strpos($query_lower, "ip"))
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua"))
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
else if (3 > count(explode(" ", $query))) // wikipedia
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -68,6 +83,7 @@
|
|||
curl_multi_exec($mh, $running);
|
||||
} while ($running);
|
||||
|
||||
|
||||
if ($special_search != 0)
|
||||
{
|
||||
$special_result = null;
|
||||
|
@ -86,6 +102,14 @@
|
|||
require "engines/special/wikipedia.php";
|
||||
$special_result = wikipedia_results($query, curl_multi_getcontent($special_ch));
|
||||
break;
|
||||
case 4:
|
||||
require "engines/special/ip.php";
|
||||
$special_result = ip_result();
|
||||
break;
|
||||
case 5:
|
||||
require "engines/special/user_agent.php";
|
||||
$special_result = user_agent_result();
|
||||
break;
|
||||
}
|
||||
|
||||
if ($special_result != null)
|
||||
|
@ -145,7 +169,8 @@
|
|||
echo "<img src=\"image_proxy.php?url=$image_url\">";
|
||||
}
|
||||
echo $response;
|
||||
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
||||
if ($source)
|
||||
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
||||
echo "</p>";
|
||||
|
||||
array_shift($results);
|
||||
|
|
11
engines/special/ip.php
Normal file
11
engines/special/ip.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
function ip_result()
|
||||
{
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => $_SERVER["REMOTE_ADDR"],
|
||||
"source" => null
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
11
engines/special/user_agent.php
Normal file
11
engines/special/user_agent.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
function user_agent_result()
|
||||
{
|
||||
return array(
|
||||
"special_response" => array(
|
||||
"response" => $_SERVER["HTTP_USER_AGENT"],
|
||||
"source" => null
|
||||
)
|
||||
);
|
||||
}
|
||||
?>
|
|
@ -7,11 +7,11 @@
|
|||
<h1>Libre<span class="X">X</span></h1>
|
||||
<input type="text" name="q" autofocus/>
|
||||
<input type="hidden" name="p" value="0"/>
|
||||
<input type="hidden" name="type" value="0"/>
|
||||
<input type="hidden" name="t" value="0"/>
|
||||
<input type="submit" class="hide"/>
|
||||
<div class="search-button-wrapper">
|
||||
<button name="type" value="0" type="submit">Search with LibreX</button>
|
||||
<button name="type" value="3" type="submit">Search torrents with LibreX</button>
|
||||
<button name="t" value="0" type="submit">Search with LibreX</button>
|
||||
<button name="t" value="3" type="submit">Search torrents with LibreX</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -12,5 +12,5 @@
|
|||
if (isset($_COOKIE["theme"]) || isset($_REQUEST["theme"]))
|
||||
echo htmlspecialchars((isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : $_REQUEST["theme"]) . ".css");
|
||||
else
|
||||
echo "dark.css";
|
||||
echo "dark.css";
|
||||
?>"/>
|
||||
|
|
|
@ -141,9 +141,16 @@
|
|||
function print_next_page_button($text, $page, $query, $type)
|
||||
{
|
||||
echo "<form class=\"page\" action=\"search.php\" target=\"_top\" method=\"get\" autocomplete=\"off\">";
|
||||
foreach($_REQUEST as $key=>$value)
|
||||
{
|
||||
if ($key != "q" && $key != "p" && $key != "t")
|
||||
{
|
||||
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\"/>";
|
||||
}
|
||||
}
|
||||
echo "<input type=\"hidden\" name=\"p\" value=\"" . $page . "\" />";
|
||||
echo "<input type=\"hidden\" name=\"q\" value=\"$query\" />";
|
||||
echo "<input type=\"hidden\" name=\"type\" value=\"$type\" />";
|
||||
echo "<input type=\"hidden\" name=\"t\" value=\"$type\" />";
|
||||
echo "<button type=\"submit\">$text</button>";
|
||||
echo "</form>";
|
||||
}
|
||||
|
|
18
search.php
18
search.php
|
@ -24,16 +24,21 @@
|
|||
>
|
||||
<br>
|
||||
<?php
|
||||
$type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
|
||||
echo "<button class=\"hide\" name=\"type\" value=\"$type\"/></button>";
|
||||
foreach($_REQUEST as $key=>$value)
|
||||
{
|
||||
if ($key != "q" && $key != "p" && $key != "t")
|
||||
{
|
||||
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\"/>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<button type="submit" class="hide"></button>
|
||||
<input type="hidden" name="p" value="0">
|
||||
<div class="sub-search-button-wrapper">
|
||||
<button name="type" value="0"><img src="static/images/text_result.png" alt="text result" />General</button>
|
||||
<button name="type" value="1"><img src="static/images/image_result.png" alt="image result" />Images</button>
|
||||
<button name="type" value="2"><img src="static/images/video_result.png" alt="video result" />Videos</button>
|
||||
<button name="type" value="3"><img src="static/images/torrent_result.png" alt="torrent result" />Torrents</button>
|
||||
<button name="t" value="0"><img src="static/images/text_result.png" alt="text result" />General</button>
|
||||
<button name="t" value="1"><img src="static/images/image_result.png" alt="image result" />Images</button>
|
||||
<button name="t" value="2"><img src="static/images/video_result.png" alt="video result" />Videos</button>
|
||||
<button name="t" value="3"><img src="static/images/torrent_result.png" alt="torrent result" />Torrents</button>
|
||||
</div>
|
||||
<hr>
|
||||
</form>
|
||||
|
@ -42,6 +47,7 @@
|
|||
$config = require "config.php";
|
||||
require "misc/tools.php";
|
||||
|
||||
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
|
||||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
||||
|
||||
$start_time = microtime(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue