-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
70 lines (58 loc) · 2.27 KB
/
api.php
File metadata and controls
70 lines (58 loc) · 2.27 KB
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
/**
* api
*
* @package Sngine
* @author Zamblek
*/
// fetch bootstrap
require('bootstrap.php');
// valid inputs
if(!isset($_GET['query']) || is_empty($_GET['query'])) {
return_json( array('error' => true, 'message' => "Bad Request, query is missing") );
}
// get data
try {
// initialize the return array
$return = array();
switch ($_GET['get']) {
case 'users':
/* get users */
$get_users = $db->query(sprintf('SELECT user_id, user_name, user_firstname, user_gender, user_picture, user_cover, user_registered, user_verified FROM users WHERE user_name LIKE %1$s OR user_firstname LIKE %1$s ORDER BY user_firstname ASC LIMIT %2$s', secure($_GET['query'], 'search'), secure($system['max_results'], 'int', false) )) or _error(SQL_ERROR_THROWEN);
if($get_users->num_rows > 0) {
while($user = $get_users->fetch_assoc()) {
$user['user_picture'] = User::get_picture($user['user_picture'], $user['user_gender']);
$return[] = $user;
}
}
break;
case 'pages':
/* get pages */
$get_pages = $db->query(sprintf('SELECT * FROM pages WHERE page_name LIKE %1$s OR page_title LIKE %1$s ORDER BY page_title ASC LIMIT %2$s', secure($_GET['query'], 'search'), secure($system['max_results'], 'int', false) )) or _error(SQL_ERROR_THROWEN);
if($get_pages->num_rows > 0) {
while($page = $get_pages->fetch_assoc()) {
$page['page_picture'] = User::get_picture($page['page_picture'], 'page');
$return[] = $page;
}
}
break;
case 'groups':
/* get groups */
$get_groups = $db->query(sprintf('SELECT * FROM groups WHERE group_name LIKE %1$s OR group_title LIKE %1$s ORDER BY group_title ASC LIMIT %2$s', secure($_GET['query'], 'search'), secure($system['max_results'], 'int', false) )) or _error(SQL_ERROR_THROWEN);
if($get_groups->num_rows > 0) {
while($group = $get_groups->fetch_assoc()) {
$group['group_picture'] = User::get_picture($group['group_picture'], 'group');
$return[] = $group;
}
}
break;
default:
return_json( array('error' => true, 'message' => "Bad Request, not valid get") );
break;
}
// return & exit
return_json($return);
} catch (Exception $e) {
return_json( array('error' => true, 'message' => $e->getMessage()) );
}
?>