-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
executable file
·106 lines (97 loc) · 2.16 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* structure active_users.json
* @var string lastId
* @var int count
* @var string id
*
*/
/**
* searching and sets links for active_users.json
* @param array $arr
*
*/
$cantSearch = false;
/**
* clear all search links
* @return execute record to file
*
*/
function clearSearchLinks() {
$users = getJsonFromFile('active_users.json');
foreach ($users as $u) {
$u->link = null;
}
return setJsonToFile('active_users.json', $users);
}
/**
* clear all search from active_users.json
* @return execute record to file
*
*/
function clearSearch() {
setJsonToFile('active_users.json', null);
}
/**
* add in search users in active_users.json
* @return bool true if added, false if not
*
*/
function addInSearch() {
if ($_SESSION['status'] == (1 || 2)) return false;
$id = $_SESSION['user'];
$activeUsers = getJsonFromFile('active_users.json');
$users = getJsonFromFile('users.json');
$activeUsers->lastId = (int) substr($id, 6);
$activeUsers->count += 1;
$activeUsers->$id = $users->$id->mmr;
dropUser($users, $id);
setJsonToFile('active_users.json', $activeUsers);
setJsonToFile('users.json', $users);
$GLOBALS['cantSearch'] = false;
$_SESSION['status'] = 1;
return $id;
}
/**
* drop users from active_users.json
* @param array &$arr
* @param array $users
* @return
*
*/
function dropFromSearch(&$arr, $users, $chat) {
foreach($users as $user) {
$id = $user;
$obj = new stdClass();
$obj->mmr = $arr->$id;
$obj->chat = $chat;
$obj->online = true;
$obj->visited = time();
addUser($id, $obj);
unset($arr->$user);
$arr->count -=1;
}
return $arr;
}
function searchResult() {
if (isset($_SESSION['chat'])) return true;
$users = getJsonFromFile('users.json');
if($users->$_SESSION['user']->chat === null) return false;
$_SESSION['chat'] = $users->$_SESSION['user']->chat;
$_SESSION['status'] = 2;
return true;
}
/**
* get last user id in array
* @param array @arr
* @return last added user id
*
*/
function getLastUserId($arr) {
$count = -1;
foreach($arr as $id => $user) {
$count = substr($id, 6);
}
return $count;
}
?>