|
1
|
|
|
<?php |
|
2
|
|
|
namespace ModPleio; |
|
3
|
|
|
|
|
4
|
|
|
class Helpers { |
|
5
|
|
|
public static function generateUsername($username) { |
|
6
|
|
|
$hidden = access_show_hidden_entities(true); |
|
7
|
|
|
|
|
8
|
|
|
while (strlen($username) < 4) { |
|
9
|
|
|
$username .= "0"; |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
View Code Duplication |
if (get_user_by_username($username)) { |
|
13
|
|
|
$i = 1; |
|
14
|
|
|
|
|
15
|
|
|
while (get_user_by_username($username . $i)) { |
|
16
|
|
|
$i++; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$result = $username . $i; |
|
20
|
|
|
} else { |
|
21
|
|
|
$result = $username; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
access_show_hidden_entities($hidden); |
|
25
|
|
|
return $result; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function removeUser(\ElggUser $user) { |
|
29
|
|
|
if (!$user || !$user instanceof \ElggUser) { |
|
30
|
|
|
return false; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// make sure the user cannot login any more, also not with the "rememberme" cookie |
|
34
|
|
|
$user->ban("banned"); |
|
35
|
|
|
$user->removeAdmin(); |
|
36
|
|
|
$user->save(); |
|
37
|
|
|
|
|
38
|
|
|
$result = Helpers::removeAllRelationships($user); |
|
39
|
|
|
$result &= Helpers::removeAllMetadata($user); |
|
40
|
|
|
$result &= Helpers::removeAllPrivateSettings($user); |
|
41
|
|
|
$result &= Helpers::anonymizeAccount($user); |
|
42
|
|
|
|
|
43
|
|
|
return $result; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function removeAllRelationships(\ElggUser $user) { |
|
47
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
48
|
|
|
$result = delete_data("DELETE FROM {$dbprefix}entity_relationships WHERE guid_one = {$user->guid} OR guid_two = {$user->guid}"); |
|
49
|
|
|
|
|
50
|
|
|
return ($result !== false); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function removeAllMetadata(\ElggUser $user) { |
|
54
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
55
|
|
|
$result = delete_data("DELETE FROM {$dbprefix}metadata WHERE entity_guid = {$user->guid}"); |
|
56
|
|
|
|
|
57
|
|
|
return ($result !== false); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function removeAllPrivateSettings(\ElggUser $user) { |
|
61
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
62
|
|
|
$result = delete_data("DELETE FROM {$dbprefix}private_settings WHERE entity_guid = {$user->guid}"); |
|
63
|
|
|
|
|
64
|
|
|
return ($result !== false); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function anonymizeAccount(\ElggUser $user) { |
|
68
|
|
|
$dbprefix = elgg_get_config("dbprefix"); |
|
69
|
|
|
|
|
70
|
|
|
// set site_guid to 0 as we do not want to display the entity in the listing any more |
|
71
|
|
|
$result = update_data("UPDATE {$dbprefix}entities SET |
|
72
|
|
|
site_guid = 0 |
|
73
|
|
|
WHERE guid = {$user->guid}" |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$result &= update_data("UPDATE {$dbprefix}users_entity SET |
|
77
|
|
|
password = NULL, |
|
78
|
|
|
salt = NULL, |
|
79
|
|
|
password_hash = NULL, |
|
80
|
|
|
name = 'Verwijderde gebruiker', |
|
81
|
|
|
username = 'verwijderd{$user->guid}', |
|
82
|
|
|
email = NULL, |
|
83
|
|
|
pleio_guid = NULL, |
|
84
|
|
|
language = NULL, |
|
85
|
|
|
last_action = 0, |
|
86
|
|
|
prev_last_action = 0, |
|
87
|
|
|
last_login = 0, |
|
88
|
|
|
prev_last_login = 0 |
|
89
|
|
|
WHERE guid = {$user->guid}" |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
_elgg_invalidate_cache_for_entity($user->guid); |
|
93
|
|
|
|
|
94
|
|
|
if (is_memcache_available()) { |
|
95
|
|
|
$newentity_cache = new \ElggMemcache("new_entity_cache"); |
|
96
|
|
|
$newentity_cache->delete($user->guid); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
elgg_trigger_event("update", "user", get_entity($user->guid)); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
return ($result !== false); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function getSiteEmail() { |
|
105
|
|
|
global $CONFIG; |
|
106
|
|
|
|
|
107
|
|
|
$site = elgg_get_site_entity(); |
|
108
|
|
|
if ($site->email) { |
|
109
|
|
|
return $site->email; |
|
110
|
|
|
} else { |
|
111
|
|
|
return "noreply@" . get_site_domain($CONFIG->site_guid); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public static function signData($data) { |
|
116
|
|
|
$data = base64_encode(json_encode($data)) . ":" . time(); |
|
117
|
|
|
$hash = hash_hmac("sha256", $data, get_site_secret()); |
|
118
|
|
|
return "{$hash}:{$data}"; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public static function loadSignedData($data) { |
|
122
|
|
|
list($input_hash, $data, $timestamp) = explode(":", $data); |
|
123
|
|
|
$verification_hash = hash_hmac("sha256", $data . ":" . $timestamp, get_site_secret()); |
|
124
|
|
|
|
|
125
|
|
|
if ($verification_hash !== $input_hash) { |
|
126
|
|
|
return false; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if (time() > $timestamp + 3600*24) { |
|
130
|
|
|
return false; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$data = json_decode(base64_decode($data), true); |
|
134
|
|
|
|
|
135
|
|
|
if (!$data) { |
|
136
|
|
|
return false; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $data; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public static function emailInWhitelist($email) { |
|
143
|
|
|
$domain = pleio_get_domain_from_email($email); |
|
144
|
|
|
return pleio_domain_in_whitelist($domain); |
|
145
|
|
|
} |
|
146
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: