-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.php
70 lines (64 loc) · 2.4 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
$config = require "config.php";
require "misc/tools.php";
if (!isset($_REQUEST["q"]))
{
echo "<p>Пример API запроса: <a href=\"./api.php?q=GNU&p=2&t=0\">./api.php?q=GNU&p=2&t=0</a></p>
<br/>
<p>\"q\" это запрос в поиск</p>
<p>\"p\" номер страницы результатов (первая страница 0)</p>
<p>\"t\" тип поиска (0=google, 10=yandex, 1=форумы, 2=видео)</p>
<br/>
<p>Результаты будут в формате JSON.</p>
<p>API поддерживает как запросы POST, так и GET.</p>";
die();
}
$query = $_REQUEST["q"];
$query_encoded = urlencode($query);
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
$type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
$results = array();
switch ($type)
{
case 0:
require "engines/google_mobile/text.php";
$results = get_text_results($query, $page);
break;
case 10:
require "engines/yandex/text.php";
$results = get_text_results($query, $page);
break;
case 1:
require "engines/crowdview/forums.php";
$results = get_text_results($query_encoded, $page);
break;
case 2:
require "engines/brave/video.php";
$results = get_video_results($query_encoded);
break;
case 3:
if ($config->disable_bittorent_search)
$results = array("error" => "disabled");
else
{
require "engines/bittorrent/merge.php";
$results = get_merged_torrent_results($query_encoded);
}
break;
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;
default:
require "engines/google/text.php";
$results = get_text_results($query_encoded, $page);
break;
}
header("Content-Type: application/json");
echo json_encode($results);
?>