-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuris.php
executable file
·86 lines (66 loc) · 2.51 KB
/
uris.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
85
86
<?php
/**
* Copyright 2008, Jefferson González (JegoYalu.com)
* This file is part of Jaris CMS and licensed under the GPL,
* check the LICENSE.txt file for version and details or visit
* https://opensource.org/licenses/GPL-3.0.
*
* Script to get a json list of uri's that a match a given query. Used
* for the auto complete functionality of uri's
*/
//Register autoloader
require 'src/Autoloader.php';
Jaris\Autoloader::register();
//Include backward compatible functions if include dir exists
if (file_exists("include/forms.php")) {
require 'src/DeprecatedFunctions.php';
}
//Initialize settings.
Jaris\Site::init();
//Starts the main session for the user
Jaris\Session::start();
//Initialize error handler
Jaris\System::initiateErrorCatchSystem();
//Check if cms is run for the first time and run the installer
Jaris\System::checkIfNotInstalled();
//Check if site status is online to continue
Jaris\Site::checkIfOffline();
if (!isset($_REQUEST["type"]) || $_REQUEST["type"] == "uris") {
$query = Jaris\Uri::fromText($_REQUEST["query"], true);
if (Jaris\Sql::dbExists("search_engine")) {
$db = Jaris\Sql::open("search_engine");
$select = "select uri, haspermission(groups, '" .
Jaris\Authentication::currentUserGroup() . "') as has_permissions
from uris where uri like '{$query}%' and has_permissions > 0 limit 0,20";
$result = Jaris\Sql::query($select, $db);
$list = [];
while ($data = Jaris\Sql::fetchArray($result)) {
$list[] = $data["uri"];
}
print json_encode(["query" => $query, "suggestions" => $list]);
} else {
print json_encode(["query" => $query, "suggestions" => []]);
}
} elseif (
$_REQUEST["type"] == "users" &&
Jaris\Authentication::groupHasPermission(
"autocomplete_users",
Jaris\Authentication::currentUserGroup()
)
) {
$query = Jaris\Users::formatUsername($_REQUEST["query"]);
if (Jaris\Sql::dbExists("users")) {
$db = Jaris\Sql::open("users");
$select = "select username from users where username like '{$query}%' limit 0,20";
$result = Jaris\Sql::query($select, $db);
$list = [];
while ($data = Jaris\Sql::fetchArray($result)) {
$list[] = $data["username"];
}
print json_encode(["query" => $query, "suggestions" => $list]);
} else {
print json_encode(["query" => $query, "suggestions" => []]);
}
} else {
print json_encode(["query" => $_REQUEST["query"], "suggestions" => []]);
}