2022-02-17 12:14:56 -08:00
|
|
|
<?php
|
2022-03-11 01:04:36 -08:00
|
|
|
$config = require "config.php";
|
|
|
|
require "misc/tools.php";
|
2023-08-21 15:58:09 -07:00
|
|
|
require "misc/search_engine.php";
|
2022-02-24 02:30:15 -08:00
|
|
|
|
|
|
|
if (!isset($_REQUEST["q"]))
|
|
|
|
{
|
2022-10-25 04:02:01 -07: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 02:02:59 -07:00
|
|
|
<br/>
|
|
|
|
<p>\"q\" is the keyword</p>
|
|
|
|
<p>\"p\" is the result page (the first page is 0)</p>
|
2022-12-02 00:41:12 -08:00
|
|
|
<p>\"t\" is the search type (0=text, 1=image, 2=video, 3=torrent, 4=tor)</p>
|
2022-06-09 02:02:59 -07: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 02:30:15 -08:00
|
|
|
die();
|
|
|
|
}
|
2022-02-17 12:14:56 -08:00
|
|
|
|
2022-03-03 01:58:11 -08:00
|
|
|
$query = $_REQUEST["q"];
|
|
|
|
$query_encoded = urlencode($query);
|
2022-02-24 02:30:15 -08:00
|
|
|
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
2022-10-25 04:02:01 -07:00
|
|
|
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
|
2022-02-17 12:14:56 -08:00
|
|
|
|
2023-08-21 15:58:09 -07:00
|
|
|
$results = fetch_search_results($type, $query, $page, $config, false);
|
2022-06-09 02:02:59 -07:00
|
|
|
header("Content-Type: application/json");
|
2022-11-20 10:00:45 -08:00
|
|
|
echo json_encode($results);
|
2022-09-11 06:54:40 -07:00
|
|
|
?>
|