2022-02-17 21:14:56 +01:00
|
|
|
<?php
|
2022-03-11 10:04:36 +01:00
|
|
|
$config = require "config.php";
|
|
|
|
require "misc/tools.php";
|
2022-02-24 11:30:15 +01:00
|
|
|
|
|
|
|
if (!isset($_REQUEST["q"]))
|
|
|
|
{
|
2022-10-25 13:02:01 +02:00
|
|
|
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>
|
2022-06-09 11:02:59 +02:00
|
|
|
<br/>
|
|
|
|
<p>\"q\" is the keyword</p>
|
|
|
|
<p>\"p\" is the result page (the first page is 0)</p>
|
2022-12-02 09:41:12 +01:00
|
|
|
<p>\"t\" is the search type (0=text, 1=image, 2=video, 3=torrent, 4=tor)</p>
|
2022-06-09 11:02:59 +02:00
|
|
|
<br/>
|
|
|
|
<p>The results are going to be in JSON format.</p>
|
|
|
|
<p>The API supports both POST and GET requests.</p>";
|
|
|
|
|
2022-02-24 11:30:15 +01:00
|
|
|
die();
|
|
|
|
}
|
2022-02-17 21:14:56 +01:00
|
|
|
|
2022-03-03 10:58:11 +01:00
|
|
|
$query = $_REQUEST["q"];
|
|
|
|
$query_encoded = urlencode($query);
|
2022-02-24 11:30:15 +01:00
|
|
|
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
2022-10-25 13:02:01 +02:00
|
|
|
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
|
2022-02-17 21:14:56 +01:00
|
|
|
|
2022-02-25 10:42:32 +01:00
|
|
|
$results = array();
|
|
|
|
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
require "engines/google/text.php";
|
2022-03-03 10:58:11 +01:00
|
|
|
$results = get_text_results($query, $page);
|
2022-02-25 10:42:32 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-07-08 21:52:26 +02:00
|
|
|
require "engines/qwant/image.php";
|
|
|
|
$results = get_image_results($query_encoded, $page);
|
2022-02-25 10:42:32 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2022-09-11 21:54:40 +08:00
|
|
|
require "engines/brave/video.php";
|
|
|
|
$results = get_video_results($query_encoded);
|
2022-02-25 10:42:32 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2022-03-11 10:04:36 +01:00
|
|
|
if ($config->disable_bittorent_search)
|
2022-02-25 10:42:32 +01:00
|
|
|
$results = array("error" => "disabled");
|
|
|
|
else
|
|
|
|
{
|
2022-02-25 20:26:15 +01:00
|
|
|
require "engines/bittorrent/merge.php";
|
|
|
|
$results = get_merged_torrent_results($query_encoded);
|
2022-02-25 10:42:32 +01:00
|
|
|
}
|
|
|
|
break;
|
2022-11-20 19:00:45 +01:00
|
|
|
case 4:
|
|
|
|
if ($config->disable_hidden_service_search)
|
|
|
|
$results = array("error" => "disabled");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
require "engines/ahmia/hidden_service.php";
|
|
|
|
$results = get_hidden_service_results($query_encoded);
|
|
|
|
}
|
|
|
|
break;
|
2022-02-25 10:42:32 +01:00
|
|
|
default:
|
|
|
|
require "engines/google/text.php";
|
|
|
|
$results = get_text_results($query_encoded, $page);
|
|
|
|
break;
|
|
|
|
}
|
2022-02-17 21:14:56 +01:00
|
|
|
|
2022-06-09 11:02:59 +02:00
|
|
|
header("Content-Type: application/json");
|
2022-11-20 19:00:45 +01:00
|
|
|
echo json_encode($results);
|
2022-09-11 21:54:40 +08:00
|
|
|
?>
|