-
Notifications
You must be signed in to change notification settings - Fork 2
/
search.php
85 lines (57 loc) · 1.62 KB
/
search.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
session_start();
require("class.php");
include("json.php");
if (isset($_POST['search']) && isset($_SESSION['root'])){
$searchq = $_POST['search'];
$datab = [];
if (file_exists($_SESSION["JSON"]."search.json")){
$rootfolder = retrieve($_SESSION["JSON"]."search.json");
if (!empty($rootfolder)){
$datab = $rootfolder;
}
}
else $datab = folderscan($_SESSION["share"]);
}
else {
$result = new info("error", "File not found or inaccessible!");
$myJSON = json_encode($result);
die($myJSON);
}
function searcharray($searchq, $datab){
natsort($datab);
$keys = array();
foreach ($datab as $key => $value) {
if (stripos($value, $searchq) !== FALSE){
$new = array_push($keys , $key);
}
}
return $keys;
}
function scanarray($obj, $obj2, $obj3, $datab){
$keys = array();
natsort($datab);
foreach ($datab as $key => $value) {
if (stripos($value, $obj) !== FALSE || stripos($value, $obj2) !== FALSE || stripos($value, $obj3) !== FALSE){
$new = array_push($keys , $key);
}
}
return $keys;
}
$present = new fsOBJ("Search Results", "root", "url-id", "root", "-", "Search Results");
if ($searchq != "media") { $result= searcharray($searchq, $datab); }
else {
$present->name = "Media";
$result = scanarray("mkv", "mp4", "m4v", $datab);
}
if (empty($result)){
$result = new info("prompt", "No results found!");
$myJSON = json_encode($result);
die($myJSON);
}else{
$result = random($result, "root", 1);
$result = handle($result, $present);
$myJSON = json_encode($result);
echo $myJSON;
}
?>