@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @access private |
17 | 17 | */ |
18 | 18 | function get_user_entity_as_row($guid) { |
19 | - return _elgg_services()->usersTable->getRow($guid); |
|
19 | + return _elgg_services()->usersTable->getRow($guid); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return bool Depending on success |
28 | 28 | */ |
29 | 29 | function disable_user_entities($owner_guid) { |
30 | - return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
30 | + return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @return bool |
40 | 40 | */ |
41 | 41 | function ban_user($user_guid, $reason = "") { |
42 | - return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
42 | + return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @return bool |
51 | 51 | */ |
52 | 52 | function unban_user($user_guid) { |
53 | - return _elgg_services()->usersTable->unban($user_guid); |
|
53 | + return _elgg_services()->usersTable->unban($user_guid); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return bool |
62 | 62 | */ |
63 | 63 | function make_user_admin($user_guid) { |
64 | - return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
64 | + return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @return bool |
73 | 73 | */ |
74 | 74 | function remove_user_admin($user_guid) { |
75 | - return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
75 | + return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return \ElggUser|false |
86 | 86 | */ |
87 | 87 | function get_user($guid) { |
88 | - return _elgg_services()->entityTable->get($guid, 'user'); |
|
88 | + return _elgg_services()->entityTable->get($guid, 'user'); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return \ElggUser|false Depending on success |
97 | 97 | */ |
98 | 98 | function get_user_by_username($username) { |
99 | - return _elgg_services()->usersTable->getByUsername($username); |
|
99 | + return _elgg_services()->usersTable->getByUsername($username); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @return \ElggUser |
108 | 108 | */ |
109 | 109 | function get_user_by_code($hash) { |
110 | - return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
110 | + return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return array |
119 | 119 | */ |
120 | 120 | function get_user_by_email($email) { |
121 | - return _elgg_services()->usersTable->getByEmail($email); |
|
121 | + return _elgg_services()->usersTable->getByEmail($email); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @return \ElggUser[]|int |
135 | 135 | */ |
136 | 136 | function find_active_users(array $options = []) { |
137 | - return _elgg_services()->usersTable->findActive($options); |
|
137 | + return _elgg_services()->usersTable->findActive($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return bool |
146 | 146 | */ |
147 | 147 | function send_new_password_request($user_guid) { |
148 | - return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
148 | + return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return bool |
160 | 160 | */ |
161 | 161 | function force_user_password_reset($user_guid, $password) { |
162 | - return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
162 | + return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @return bool True on success |
173 | 173 | */ |
174 | 174 | function execute_new_password_request($user_guid, $conf_code, $password = null) { |
175 | - return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
175 | + return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @return string |
182 | 182 | */ |
183 | 183 | function generate_random_cleartext_password() { |
184 | - return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
184 | + return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -197,57 +197,57 @@ discard block |
||
197 | 197 | * @throws RegistrationException on invalid |
198 | 198 | */ |
199 | 199 | function validate_username($username) { |
200 | - global $CONFIG; |
|
201 | - |
|
202 | - // Basic, check length |
|
203 | - if (!isset($CONFIG->minusername)) { |
|
204 | - $CONFIG->minusername = 4; |
|
205 | - } |
|
206 | - |
|
207 | - if (strlen($username) < $CONFIG->minusername) { |
|
208 | - $msg = elgg_echo('registration:usernametooshort', [$CONFIG->minusername]); |
|
209 | - throw new \RegistrationException($msg); |
|
210 | - } |
|
211 | - |
|
212 | - // username in the database has a limit of 128 characters |
|
213 | - if (strlen($username) > 128) { |
|
214 | - $msg = elgg_echo('registration:usernametoolong', [128]); |
|
215 | - throw new \RegistrationException($msg); |
|
216 | - } |
|
217 | - |
|
218 | - // Blacklist for bad characters (partially nicked from mediawiki) |
|
219 | - $blacklist = '/[' . |
|
220 | - '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
221 | - '\x{00a0}' . // non-breaking space |
|
222 | - '\x{2000}-\x{200f}' . // various whitespace |
|
223 | - '\x{2028}-\x{202f}' . // breaks and control chars |
|
224 | - '\x{3000}' . // ideographic space |
|
225 | - '\x{e000}-\x{f8ff}' . // private use |
|
226 | - ']/u'; |
|
227 | - |
|
228 | - if (preg_match($blacklist, $username)) { |
|
229 | - // @todo error message needs work |
|
230 | - throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
231 | - } |
|
232 | - |
|
233 | - // Belts and braces |
|
234 | - // @todo Tidy into main unicode |
|
235 | - $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
236 | - |
|
237 | - $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
238 | - ['blacklist' => $blacklist2], $blacklist2); |
|
239 | - |
|
240 | - for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
241 | - if (strpos($username, $blacklist2[$n]) !== false) { |
|
242 | - $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
243 | - $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); |
|
244 | - throw new \RegistrationException($msg); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - $result = true; |
|
249 | - return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
250 | - ['username' => $username], $result); |
|
200 | + global $CONFIG; |
|
201 | + |
|
202 | + // Basic, check length |
|
203 | + if (!isset($CONFIG->minusername)) { |
|
204 | + $CONFIG->minusername = 4; |
|
205 | + } |
|
206 | + |
|
207 | + if (strlen($username) < $CONFIG->minusername) { |
|
208 | + $msg = elgg_echo('registration:usernametooshort', [$CONFIG->minusername]); |
|
209 | + throw new \RegistrationException($msg); |
|
210 | + } |
|
211 | + |
|
212 | + // username in the database has a limit of 128 characters |
|
213 | + if (strlen($username) > 128) { |
|
214 | + $msg = elgg_echo('registration:usernametoolong', [128]); |
|
215 | + throw new \RegistrationException($msg); |
|
216 | + } |
|
217 | + |
|
218 | + // Blacklist for bad characters (partially nicked from mediawiki) |
|
219 | + $blacklist = '/[' . |
|
220 | + '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
221 | + '\x{00a0}' . // non-breaking space |
|
222 | + '\x{2000}-\x{200f}' . // various whitespace |
|
223 | + '\x{2028}-\x{202f}' . // breaks and control chars |
|
224 | + '\x{3000}' . // ideographic space |
|
225 | + '\x{e000}-\x{f8ff}' . // private use |
|
226 | + ']/u'; |
|
227 | + |
|
228 | + if (preg_match($blacklist, $username)) { |
|
229 | + // @todo error message needs work |
|
230 | + throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
231 | + } |
|
232 | + |
|
233 | + // Belts and braces |
|
234 | + // @todo Tidy into main unicode |
|
235 | + $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
236 | + |
|
237 | + $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
238 | + ['blacklist' => $blacklist2], $blacklist2); |
|
239 | + |
|
240 | + for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
241 | + if (strpos($username, $blacklist2[$n]) !== false) { |
|
242 | + $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
243 | + $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'); |
|
244 | + throw new \RegistrationException($msg); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + $result = true; |
|
249 | + return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
250 | + ['username' => $username], $result); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -259,20 +259,20 @@ discard block |
||
259 | 259 | * @throws RegistrationException on invalid |
260 | 260 | */ |
261 | 261 | function validate_password($password) { |
262 | - global $CONFIG; |
|
262 | + global $CONFIG; |
|
263 | 263 | |
264 | - if (!isset($CONFIG->min_password_length)) { |
|
265 | - $CONFIG->min_password_length = 6; |
|
266 | - } |
|
264 | + if (!isset($CONFIG->min_password_length)) { |
|
265 | + $CONFIG->min_password_length = 6; |
|
266 | + } |
|
267 | 267 | |
268 | - if (strlen($password) < $CONFIG->min_password_length) { |
|
269 | - $msg = elgg_echo('registration:passwordtooshort', [$CONFIG->min_password_length]); |
|
270 | - throw new \RegistrationException($msg); |
|
271 | - } |
|
268 | + if (strlen($password) < $CONFIG->min_password_length) { |
|
269 | + $msg = elgg_echo('registration:passwordtooshort', [$CONFIG->min_password_length]); |
|
270 | + throw new \RegistrationException($msg); |
|
271 | + } |
|
272 | 272 | |
273 | - $result = true; |
|
274 | - return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
275 | - ['password' => $password], $result); |
|
273 | + $result = true; |
|
274 | + return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
275 | + ['password' => $password], $result); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | * @return bool |
285 | 285 | */ |
286 | 286 | function validate_email_address($address) { |
287 | - if (!is_email_address($address)) { |
|
288 | - throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
289 | - } |
|
290 | - |
|
291 | - // Got here, so lets try a hook (defaulting to ok) |
|
292 | - $result = true; |
|
293 | - return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
294 | - ['email' => $address], $result); |
|
287 | + if (!is_email_address($address)) { |
|
288 | + throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
289 | + } |
|
290 | + |
|
291 | + // Got here, so lets try a hook (defaulting to ok) |
|
292 | + $result = true; |
|
293 | + return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
294 | + ['email' => $address], $result); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @throws RegistrationException |
309 | 309 | */ |
310 | 310 | function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { |
311 | - return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
311 | + return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @see elgg_validate_invite_code |
321 | 321 | */ |
322 | 322 | function generate_invite_code($username) { |
323 | - return _elgg_services()->usersTable->generateInviteCode($username); |
|
323 | + return _elgg_services()->usersTable->generateInviteCode($username); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * @since 1.10 |
335 | 335 | */ |
336 | 336 | function elgg_validate_invite_code($username, $code) { |
337 | - return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
337 | + return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @since 1.8.0 |
348 | 348 | */ |
349 | 349 | function elgg_set_user_validation_status($user_guid, $status, $method = '') { |
350 | - return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
350 | + return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * @since 1.8.0 |
359 | 359 | */ |
360 | 360 | function elgg_get_user_validation_status($user_guid) { |
361 | - return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
361 | + return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -372,24 +372,24 @@ discard block |
||
372 | 372 | */ |
373 | 373 | function elgg_user_account_page_handler($page_elements, $handler) { |
374 | 374 | |
375 | - switch ($handler) { |
|
376 | - case 'login': |
|
377 | - echo elgg_view_resource("account/login"); |
|
378 | - break; |
|
379 | - case 'forgotpassword': |
|
380 | - echo elgg_view_resource("account/forgotten_password"); |
|
381 | - break; |
|
382 | - case 'changepassword': |
|
383 | - echo elgg_view_resource("account/change_password"); |
|
384 | - break; |
|
385 | - case 'register': |
|
386 | - echo elgg_view_resource("account/register"); |
|
387 | - break; |
|
388 | - default: |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - return true; |
|
375 | + switch ($handler) { |
|
376 | + case 'login': |
|
377 | + echo elgg_view_resource("account/login"); |
|
378 | + break; |
|
379 | + case 'forgotpassword': |
|
380 | + echo elgg_view_resource("account/forgotten_password"); |
|
381 | + break; |
|
382 | + case 'changepassword': |
|
383 | + echo elgg_view_resource("account/change_password"); |
|
384 | + break; |
|
385 | + case 'register': |
|
386 | + echo elgg_view_resource("account/register"); |
|
387 | + break; |
|
388 | + default: |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + return true; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
@@ -403,9 +403,9 @@ discard block |
||
403 | 403 | * @return string |
404 | 404 | */ |
405 | 405 | function elgg_get_registration_url(array $query = [], $fragment = '') { |
406 | - $url = elgg_normalize_url('register'); |
|
407 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
408 | - return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
406 | + $url = elgg_normalize_url('register'); |
|
407 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
408 | + return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | * @return string |
419 | 419 | */ |
420 | 420 | function elgg_get_login_url(array $query = [], $fragment = '') { |
421 | - $url = elgg_normalize_url('login'); |
|
422 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
423 | - return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
421 | + $url = elgg_normalize_url('login'); |
|
422 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
423 | + return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -430,11 +430,11 @@ discard block |
||
430 | 430 | * @return void |
431 | 431 | */ |
432 | 432 | function set_last_action($user_guid) { |
433 | - $user = get_user($user_guid); |
|
434 | - if (!$user) { |
|
435 | - return; |
|
436 | - } |
|
437 | - _elgg_services()->usersTable->setLastAction($user); |
|
433 | + $user = get_user($user_guid); |
|
434 | + if (!$user) { |
|
435 | + return; |
|
436 | + } |
|
437 | + _elgg_services()->usersTable->setLastAction($user); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | * @return void |
445 | 445 | */ |
446 | 446 | function set_last_login($user_guid) { |
447 | - $user = get_user($user_guid); |
|
448 | - if (!$user) { |
|
449 | - return; |
|
450 | - } |
|
451 | - _elgg_services()->usersTable->setLastLogin($user); |
|
447 | + $user = get_user($user_guid); |
|
448 | + if (!$user) { |
|
449 | + return; |
|
450 | + } |
|
451 | + _elgg_services()->usersTable->setLastLogin($user); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | * @access private |
464 | 464 | */ |
465 | 465 | function user_avatar_hook($hook, $type, $return, $params) { |
466 | - $user = elgg_extract('entity', $params); |
|
467 | - $size = elgg_extract('size', $params, 'medium'); |
|
466 | + $user = elgg_extract('entity', $params); |
|
467 | + $size = elgg_extract('size', $params, 'medium'); |
|
468 | 468 | |
469 | - if (!$user instanceof ElggUser) { |
|
470 | - return; |
|
471 | - } |
|
469 | + if (!$user instanceof ElggUser) { |
|
470 | + return; |
|
471 | + } |
|
472 | 472 | |
473 | - if (elgg_get_config('walled_garden')) { |
|
474 | - return; |
|
475 | - } |
|
473 | + if (elgg_get_config('walled_garden')) { |
|
474 | + return; |
|
475 | + } |
|
476 | 476 | |
477 | - if (!$user->hasIcon($size, 'icon')) { |
|
478 | - return; |
|
479 | - } |
|
477 | + if (!$user->hasIcon($size, 'icon')) { |
|
478 | + return; |
|
479 | + } |
|
480 | 480 | |
481 | - $icon = $user->getIcon($size, 'icon'); |
|
482 | - return elgg_get_inline_url($icon, false); |
|
481 | + $icon = $user->getIcon($size, 'icon'); |
|
482 | + return elgg_get_inline_url($icon, false); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -487,112 +487,112 @@ discard block |
||
487 | 487 | * @access private |
488 | 488 | */ |
489 | 489 | function elgg_user_hover_menu($hook, $type, $return, $params) { |
490 | - $user = elgg_extract('entity', $params); |
|
491 | - /* @var \ElggUser $user */ |
|
490 | + $user = elgg_extract('entity', $params); |
|
491 | + /* @var \ElggUser $user */ |
|
492 | 492 | |
493 | - if (!$user instanceof \ElggUser) { |
|
494 | - return; |
|
495 | - } |
|
493 | + if (!$user instanceof \ElggUser) { |
|
494 | + return; |
|
495 | + } |
|
496 | 496 | |
497 | - if (!elgg_is_logged_in()) { |
|
498 | - return; |
|
499 | - } |
|
497 | + if (!elgg_is_logged_in()) { |
|
498 | + return; |
|
499 | + } |
|
500 | 500 | |
501 | - if ($user->canEdit()) { |
|
502 | - $return[] = ElggMenuItem::factory([ |
|
503 | - 'name' => 'profile:edit', |
|
504 | - 'text' => elgg_echo('profile:edit'), |
|
505 | - 'icon' => 'address-card', |
|
506 | - 'href' => "profile/$user->username/edit", |
|
507 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
508 | - ]); |
|
509 | - |
|
510 | - $return[] = ElggMenuItem::factory([ |
|
511 | - 'name' => 'avatar:edit', |
|
512 | - 'text' => elgg_echo('avatar:edit'), |
|
513 | - 'icon' => 'image', |
|
514 | - 'href' => "avatar/edit/$user->username", |
|
515 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
516 | - ]); |
|
517 | - } |
|
518 | - |
|
519 | - // prevent admins from banning or deleting themselves |
|
520 | - if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
521 | - return $return; |
|
522 | - } |
|
523 | - |
|
524 | - if (!elgg_is_admin_logged_in()) { |
|
525 | - return $return; |
|
526 | - } |
|
501 | + if ($user->canEdit()) { |
|
502 | + $return[] = ElggMenuItem::factory([ |
|
503 | + 'name' => 'profile:edit', |
|
504 | + 'text' => elgg_echo('profile:edit'), |
|
505 | + 'icon' => 'address-card', |
|
506 | + 'href' => "profile/$user->username/edit", |
|
507 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
508 | + ]); |
|
509 | + |
|
510 | + $return[] = ElggMenuItem::factory([ |
|
511 | + 'name' => 'avatar:edit', |
|
512 | + 'text' => elgg_echo('avatar:edit'), |
|
513 | + 'icon' => 'image', |
|
514 | + 'href' => "avatar/edit/$user->username", |
|
515 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
516 | + ]); |
|
517 | + } |
|
518 | + |
|
519 | + // prevent admins from banning or deleting themselves |
|
520 | + if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
521 | + return $return; |
|
522 | + } |
|
523 | + |
|
524 | + if (!elgg_is_admin_logged_in()) { |
|
525 | + return $return; |
|
526 | + } |
|
527 | 527 | |
528 | - // following items are admin only |
|
529 | - if (!$user->isBanned()) { |
|
530 | - $return[] = ElggMenuItem::factory([ |
|
531 | - 'name' => 'ban', |
|
532 | - 'text' => elgg_echo('ban'), |
|
533 | - 'icon' => 'ban', |
|
534 | - 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
535 | - 'confirm' => true, |
|
536 | - 'section' => 'admin', |
|
537 | - ]); |
|
538 | - } else { |
|
539 | - $return[] = ElggMenuItem::factory([ |
|
540 | - 'name' => 'unban', |
|
541 | - 'text' => elgg_echo('unban'), |
|
542 | - 'icon' => 'ban', |
|
543 | - 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
544 | - 'confirm' => true, |
|
545 | - 'section' => 'admin', |
|
546 | - ]); |
|
547 | - } |
|
528 | + // following items are admin only |
|
529 | + if (!$user->isBanned()) { |
|
530 | + $return[] = ElggMenuItem::factory([ |
|
531 | + 'name' => 'ban', |
|
532 | + 'text' => elgg_echo('ban'), |
|
533 | + 'icon' => 'ban', |
|
534 | + 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
535 | + 'confirm' => true, |
|
536 | + 'section' => 'admin', |
|
537 | + ]); |
|
538 | + } else { |
|
539 | + $return[] = ElggMenuItem::factory([ |
|
540 | + 'name' => 'unban', |
|
541 | + 'text' => elgg_echo('unban'), |
|
542 | + 'icon' => 'ban', |
|
543 | + 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
544 | + 'confirm' => true, |
|
545 | + 'section' => 'admin', |
|
546 | + ]); |
|
547 | + } |
|
548 | 548 | |
549 | - $return[] = ElggMenuItem::factory([ |
|
550 | - 'name' => 'delete', |
|
551 | - 'text' => elgg_echo('delete'), |
|
552 | - 'icon' => 'delete', |
|
553 | - 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
554 | - 'confirm' => true, |
|
555 | - 'section' => 'admin', |
|
556 | - ]); |
|
549 | + $return[] = ElggMenuItem::factory([ |
|
550 | + 'name' => 'delete', |
|
551 | + 'text' => elgg_echo('delete'), |
|
552 | + 'icon' => 'delete', |
|
553 | + 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
554 | + 'confirm' => true, |
|
555 | + 'section' => 'admin', |
|
556 | + ]); |
|
557 | 557 | |
558 | - $return[] = ElggMenuItem::factory([ |
|
559 | - 'name' => 'resetpassword', |
|
560 | - 'text' => elgg_echo('resetpassword'), |
|
561 | - 'icon' => 'refresh', |
|
562 | - 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
563 | - 'confirm' => true, |
|
564 | - 'section' => 'admin', |
|
565 | - ]); |
|
558 | + $return[] = ElggMenuItem::factory([ |
|
559 | + 'name' => 'resetpassword', |
|
560 | + 'text' => elgg_echo('resetpassword'), |
|
561 | + 'icon' => 'refresh', |
|
562 | + 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
563 | + 'confirm' => true, |
|
564 | + 'section' => 'admin', |
|
565 | + ]); |
|
566 | 566 | |
567 | - if (!$user->isAdmin()) { |
|
568 | - $return[] = ElggMenuItem::factory([ |
|
569 | - 'name' => 'makeadmin', |
|
570 | - 'text' => elgg_echo('makeadmin'), |
|
571 | - 'icon' => 'level-up', |
|
572 | - 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
573 | - 'confirm' => true, |
|
574 | - 'section' => 'admin', |
|
575 | - ]); |
|
576 | - } else { |
|
577 | - $return[] = ElggMenuItem::factory([ |
|
578 | - 'name' => 'removeadmin', |
|
579 | - 'text' => elgg_echo('removeadmin'), |
|
580 | - 'icon' => 'level-down', |
|
581 | - 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
582 | - 'confirm' => true, |
|
583 | - 'section' => 'admin', |
|
584 | - ]); |
|
585 | - } |
|
567 | + if (!$user->isAdmin()) { |
|
568 | + $return[] = ElggMenuItem::factory([ |
|
569 | + 'name' => 'makeadmin', |
|
570 | + 'text' => elgg_echo('makeadmin'), |
|
571 | + 'icon' => 'level-up', |
|
572 | + 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
573 | + 'confirm' => true, |
|
574 | + 'section' => 'admin', |
|
575 | + ]); |
|
576 | + } else { |
|
577 | + $return[] = ElggMenuItem::factory([ |
|
578 | + 'name' => 'removeadmin', |
|
579 | + 'text' => elgg_echo('removeadmin'), |
|
580 | + 'icon' => 'level-down', |
|
581 | + 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
582 | + 'confirm' => true, |
|
583 | + 'section' => 'admin', |
|
584 | + ]); |
|
585 | + } |
|
586 | 586 | |
587 | - $return[] = ElggMenuItem::factory([ |
|
588 | - 'name' => 'settings:edit', |
|
589 | - 'text' => elgg_echo('settings:edit'), |
|
590 | - 'icon' => 'cogs', |
|
591 | - 'href' => "settings/user/$user->username", |
|
592 | - 'section' => 'admin', |
|
593 | - ]); |
|
594 | - |
|
595 | - return $return; |
|
587 | + $return[] = ElggMenuItem::factory([ |
|
588 | + 'name' => 'settings:edit', |
|
589 | + 'text' => elgg_echo('settings:edit'), |
|
590 | + 'icon' => 'cogs', |
|
591 | + 'href' => "settings/user/$user->username", |
|
592 | + 'section' => 'admin', |
|
593 | + ]); |
|
594 | + |
|
595 | + return $return; |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -607,41 +607,41 @@ discard block |
||
607 | 607 | * @access private |
608 | 608 | */ |
609 | 609 | function elgg_users_setup_entity_menu($hook, $type, $return, $params) { |
610 | - if (elgg_in_context('widgets')) { |
|
611 | - return $return; |
|
612 | - } |
|
613 | - |
|
614 | - $entity = $params['entity']; |
|
615 | - if (!elgg_instanceof($entity, 'user')) { |
|
616 | - return $return; |
|
617 | - } |
|
618 | - /* @var \ElggUser $entity */ |
|
619 | - |
|
620 | - if ($entity->isBanned()) { |
|
621 | - $banned = elgg_echo('banned'); |
|
622 | - $options = [ |
|
623 | - 'name' => 'banned', |
|
624 | - 'text' => "<span>$banned</span>", |
|
625 | - 'href' => false, |
|
626 | - 'priority' => 0, |
|
627 | - ]; |
|
628 | - $return = [\ElggMenuItem::factory($options)]; |
|
629 | - } else { |
|
630 | - $return = []; |
|
631 | - $location = $entity->location; |
|
632 | - if (is_string($location) && $location !== '') { |
|
633 | - $location = htmlspecialchars($location, ENT_QUOTES, 'UTF-8', false); |
|
634 | - $options = [ |
|
635 | - 'name' => 'location', |
|
636 | - 'text' => "<span>$location</span>", |
|
637 | - 'href' => false, |
|
638 | - 'priority' => 150, |
|
639 | - ]; |
|
640 | - $return[] = \ElggMenuItem::factory($options); |
|
641 | - } |
|
642 | - } |
|
643 | - |
|
644 | - return $return; |
|
610 | + if (elgg_in_context('widgets')) { |
|
611 | + return $return; |
|
612 | + } |
|
613 | + |
|
614 | + $entity = $params['entity']; |
|
615 | + if (!elgg_instanceof($entity, 'user')) { |
|
616 | + return $return; |
|
617 | + } |
|
618 | + /* @var \ElggUser $entity */ |
|
619 | + |
|
620 | + if ($entity->isBanned()) { |
|
621 | + $banned = elgg_echo('banned'); |
|
622 | + $options = [ |
|
623 | + 'name' => 'banned', |
|
624 | + 'text' => "<span>$banned</span>", |
|
625 | + 'href' => false, |
|
626 | + 'priority' => 0, |
|
627 | + ]; |
|
628 | + $return = [\ElggMenuItem::factory($options)]; |
|
629 | + } else { |
|
630 | + $return = []; |
|
631 | + $location = $entity->location; |
|
632 | + if (is_string($location) && $location !== '') { |
|
633 | + $location = htmlspecialchars($location, ENT_QUOTES, 'UTF-8', false); |
|
634 | + $options = [ |
|
635 | + 'name' => 'location', |
|
636 | + 'text' => "<span>$location</span>", |
|
637 | + 'href' => false, |
|
638 | + 'priority' => 150, |
|
639 | + ]; |
|
640 | + $return[] = \ElggMenuItem::factory($options); |
|
641 | + } |
|
642 | + } |
|
643 | + |
|
644 | + return $return; |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -653,49 +653,49 @@ discard block |
||
653 | 653 | * @access private |
654 | 654 | */ |
655 | 655 | function elgg_profile_fields_setup() { |
656 | - global $CONFIG; |
|
657 | - |
|
658 | - $profile_defaults = [ |
|
659 | - 'description' => 'longtext', |
|
660 | - 'briefdescription' => 'text', |
|
661 | - 'location' => 'location', |
|
662 | - 'interests' => 'tags', |
|
663 | - 'skills' => 'tags', |
|
664 | - 'contactemail' => 'email', |
|
665 | - 'phone' => 'text', |
|
666 | - 'mobile' => 'text', |
|
667 | - 'website' => 'url', |
|
668 | - 'twitter' => 'text', |
|
669 | - ]; |
|
670 | - |
|
671 | - $loaded_defaults = []; |
|
672 | - $fieldlist = elgg_get_config('profile_custom_fields'); |
|
673 | - if ($fieldlist || $fieldlist === '0') { |
|
674 | - $fieldlistarray = explode(',', $fieldlist); |
|
675 | - foreach ($fieldlistarray as $listitem) { |
|
676 | - if ($translation = elgg_get_config("admin_defined_profile_{$listitem}")) { |
|
677 | - $type = elgg_get_config("admin_defined_profile_type_{$listitem}"); |
|
678 | - $loaded_defaults["admin_defined_profile_{$listitem}"] = $type; |
|
679 | - add_translation(get_current_language(), ["profile:admin_defined_profile_{$listitem}" => $translation]); |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - if (count($loaded_defaults)) { |
|
685 | - $CONFIG->profile_using_custom = true; |
|
686 | - $profile_defaults = $loaded_defaults; |
|
687 | - } |
|
688 | - |
|
689 | - $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults); |
|
690 | - |
|
691 | - // register any tag metadata names |
|
692 | - foreach ($CONFIG->profile_fields as $name => $type) { |
|
693 | - if ($type == 'tags' || $type == 'location' || $type == 'tag') { |
|
694 | - elgg_register_tag_metadata_name($name); |
|
695 | - // register a tag name translation |
|
696 | - add_translation(get_current_language(), ["tag_names:$name" => elgg_echo("profile:$name")]); |
|
697 | - } |
|
698 | - } |
|
656 | + global $CONFIG; |
|
657 | + |
|
658 | + $profile_defaults = [ |
|
659 | + 'description' => 'longtext', |
|
660 | + 'briefdescription' => 'text', |
|
661 | + 'location' => 'location', |
|
662 | + 'interests' => 'tags', |
|
663 | + 'skills' => 'tags', |
|
664 | + 'contactemail' => 'email', |
|
665 | + 'phone' => 'text', |
|
666 | + 'mobile' => 'text', |
|
667 | + 'website' => 'url', |
|
668 | + 'twitter' => 'text', |
|
669 | + ]; |
|
670 | + |
|
671 | + $loaded_defaults = []; |
|
672 | + $fieldlist = elgg_get_config('profile_custom_fields'); |
|
673 | + if ($fieldlist || $fieldlist === '0') { |
|
674 | + $fieldlistarray = explode(',', $fieldlist); |
|
675 | + foreach ($fieldlistarray as $listitem) { |
|
676 | + if ($translation = elgg_get_config("admin_defined_profile_{$listitem}")) { |
|
677 | + $type = elgg_get_config("admin_defined_profile_type_{$listitem}"); |
|
678 | + $loaded_defaults["admin_defined_profile_{$listitem}"] = $type; |
|
679 | + add_translation(get_current_language(), ["profile:admin_defined_profile_{$listitem}" => $translation]); |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + if (count($loaded_defaults)) { |
|
685 | + $CONFIG->profile_using_custom = true; |
|
686 | + $profile_defaults = $loaded_defaults; |
|
687 | + } |
|
688 | + |
|
689 | + $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults); |
|
690 | + |
|
691 | + // register any tag metadata names |
|
692 | + foreach ($CONFIG->profile_fields as $name => $type) { |
|
693 | + if ($type == 'tags' || $type == 'location' || $type == 'tag') { |
|
694 | + elgg_register_tag_metadata_name($name); |
|
695 | + // register a tag name translation |
|
696 | + add_translation(get_current_language(), ["tag_names:$name" => elgg_echo("profile:$name")]); |
|
697 | + } |
|
698 | + } |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
@@ -708,15 +708,15 @@ discard block |
||
708 | 708 | * @access private |
709 | 709 | */ |
710 | 710 | function elgg_avatar_page_handler($page) { |
711 | - $user = get_user_by_username(elgg_extract(1, $page)); |
|
712 | - if ($user) { |
|
713 | - elgg_set_page_owner_guid($user->getGUID()); |
|
714 | - } |
|
715 | - |
|
716 | - if ($page[0] == 'edit') { |
|
717 | - echo elgg_view_resource("avatar/edit"); |
|
718 | - return true; |
|
719 | - } |
|
711 | + $user = get_user_by_username(elgg_extract(1, $page)); |
|
712 | + if ($user) { |
|
713 | + elgg_set_page_owner_guid($user->getGUID()); |
|
714 | + } |
|
715 | + |
|
716 | + if ($page[0] == 'edit') { |
|
717 | + echo elgg_view_resource("avatar/edit"); |
|
718 | + return true; |
|
719 | + } |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
@@ -727,14 +727,14 @@ discard block |
||
727 | 727 | * @access private |
728 | 728 | */ |
729 | 729 | function elgg_profile_page_handler($page) { |
730 | - $user = get_user_by_username($page[0]); |
|
731 | - elgg_set_page_owner_guid($user->guid); |
|
732 | - |
|
733 | - if ($page[1] == 'edit') { |
|
734 | - echo elgg_view_resource("profile/edit"); |
|
735 | - return true; |
|
736 | - } |
|
737 | - return false; |
|
730 | + $user = get_user_by_username($page[0]); |
|
731 | + elgg_set_page_owner_guid($user->guid); |
|
732 | + |
|
733 | + if ($page[1] == 'edit') { |
|
734 | + echo elgg_view_resource("profile/edit"); |
|
735 | + return true; |
|
736 | + } |
|
737 | + return false; |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -753,28 +753,28 @@ discard block |
||
753 | 753 | */ |
754 | 754 | function _elgg_user_page_menu($hook, $type, $return, $params) { |
755 | 755 | |
756 | - $owner = elgg_get_page_owner_entity(); |
|
757 | - if (!$owner) { |
|
758 | - return; |
|
759 | - } |
|
760 | - |
|
761 | - $return[] = \ElggMenuItem::factory([ |
|
762 | - 'name' => 'edit_avatar', |
|
763 | - 'href' => "avatar/edit/{$owner->username}", |
|
764 | - 'text' => elgg_echo('avatar:edit'), |
|
765 | - 'section' => '1_profile', |
|
766 | - 'contexts' => ['settings'], |
|
767 | - ]); |
|
756 | + $owner = elgg_get_page_owner_entity(); |
|
757 | + if (!$owner) { |
|
758 | + return; |
|
759 | + } |
|
760 | + |
|
761 | + $return[] = \ElggMenuItem::factory([ |
|
762 | + 'name' => 'edit_avatar', |
|
763 | + 'href' => "avatar/edit/{$owner->username}", |
|
764 | + 'text' => elgg_echo('avatar:edit'), |
|
765 | + 'section' => '1_profile', |
|
766 | + 'contexts' => ['settings'], |
|
767 | + ]); |
|
768 | 768 | |
769 | - $return[] = \ElggMenuItem::factory([ |
|
770 | - 'name' => 'edit_profile', |
|
771 | - 'href' => "profile/{$owner->username}/edit", |
|
772 | - 'text' => elgg_echo('profile:edit'), |
|
773 | - 'section' => '1_profile', |
|
774 | - 'contexts' => ['settings'], |
|
775 | - ]); |
|
769 | + $return[] = \ElggMenuItem::factory([ |
|
770 | + 'name' => 'edit_profile', |
|
771 | + 'href' => "profile/{$owner->username}/edit", |
|
772 | + 'text' => elgg_echo('profile:edit'), |
|
773 | + 'section' => '1_profile', |
|
774 | + 'contexts' => ['settings'], |
|
775 | + ]); |
|
776 | 776 | |
777 | - return $return; |
|
777 | + return $return; |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /** |
@@ -793,65 +793,65 @@ discard block |
||
793 | 793 | */ |
794 | 794 | function _elgg_user_topbar_menu($hook, $type, $return, $params) { |
795 | 795 | |
796 | - $viewer = elgg_get_logged_in_user_entity(); |
|
797 | - if (!$viewer) { |
|
798 | - return; |
|
799 | - } |
|
800 | - |
|
801 | - $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
802 | - $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
803 | - |
|
804 | - $return[] = \ElggMenuItem::factory([ |
|
805 | - 'name' => 'account', |
|
806 | - 'text' => elgg_echo('account') . $toggle, |
|
807 | - 'href' => '#', |
|
808 | - 'priority' => 800, |
|
809 | - 'section' => 'alt', |
|
810 | - 'child_menu' => [ |
|
811 | - 'display' => 'dropdown', |
|
812 | - 'class' => 'elgg-topbar-child-menu', |
|
813 | - 'data-position' => json_encode([ |
|
814 | - 'at' => 'right+10px bottom', |
|
815 | - 'my' => 'right top', |
|
816 | - 'collision' => 'fit fit', |
|
817 | - ]), |
|
818 | - ], |
|
819 | - ]); |
|
796 | + $viewer = elgg_get_logged_in_user_entity(); |
|
797 | + if (!$viewer) { |
|
798 | + return; |
|
799 | + } |
|
800 | + |
|
801 | + $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
802 | + $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
803 | + |
|
804 | + $return[] = \ElggMenuItem::factory([ |
|
805 | + 'name' => 'account', |
|
806 | + 'text' => elgg_echo('account') . $toggle, |
|
807 | + 'href' => '#', |
|
808 | + 'priority' => 800, |
|
809 | + 'section' => 'alt', |
|
810 | + 'child_menu' => [ |
|
811 | + 'display' => 'dropdown', |
|
812 | + 'class' => 'elgg-topbar-child-menu', |
|
813 | + 'data-position' => json_encode([ |
|
814 | + 'at' => 'right+10px bottom', |
|
815 | + 'my' => 'right top', |
|
816 | + 'collision' => 'fit fit', |
|
817 | + ]), |
|
818 | + ], |
|
819 | + ]); |
|
820 | 820 | |
821 | - $return[] = \ElggMenuItem::factory([ |
|
822 | - 'name' => 'usersettings', |
|
823 | - 'parent_name' => 'account', |
|
824 | - 'href' => "settings/user/{$viewer->username}", |
|
825 | - 'text' => elgg_echo('settings'), |
|
826 | - 'icon' => 'cogs', |
|
827 | - 'priority' => 300, |
|
828 | - 'section' => 'alt', |
|
829 | - ]); |
|
821 | + $return[] = \ElggMenuItem::factory([ |
|
822 | + 'name' => 'usersettings', |
|
823 | + 'parent_name' => 'account', |
|
824 | + 'href' => "settings/user/{$viewer->username}", |
|
825 | + 'text' => elgg_echo('settings'), |
|
826 | + 'icon' => 'cogs', |
|
827 | + 'priority' => 300, |
|
828 | + 'section' => 'alt', |
|
829 | + ]); |
|
830 | 830 | |
831 | - if ($viewer->isAdmin()) { |
|
832 | - $return[] = \ElggMenuItem::factory([ |
|
833 | - 'name' => 'administration', |
|
834 | - 'parent_name' => 'account', |
|
835 | - 'href' => 'admin', |
|
836 | - 'text' => elgg_echo('admin'), |
|
837 | - 'icon' => 'tasks', |
|
838 | - 'priority' => 800, |
|
839 | - 'section' => 'alt', |
|
840 | - ]); |
|
841 | - } |
|
831 | + if ($viewer->isAdmin()) { |
|
832 | + $return[] = \ElggMenuItem::factory([ |
|
833 | + 'name' => 'administration', |
|
834 | + 'parent_name' => 'account', |
|
835 | + 'href' => 'admin', |
|
836 | + 'text' => elgg_echo('admin'), |
|
837 | + 'icon' => 'tasks', |
|
838 | + 'priority' => 800, |
|
839 | + 'section' => 'alt', |
|
840 | + ]); |
|
841 | + } |
|
842 | 842 | |
843 | - $return[] = \ElggMenuItem::factory([ |
|
844 | - 'name' => 'logout', |
|
845 | - 'parent_name' => 'account', |
|
846 | - 'href' => 'action/logout', |
|
847 | - 'text' => elgg_echo('logout'), |
|
848 | - 'icon' => 'sign-out', |
|
849 | - 'is_action' => true, |
|
850 | - 'priority' => 900, |
|
851 | - 'section' => 'alt', |
|
852 | - ]); |
|
843 | + $return[] = \ElggMenuItem::factory([ |
|
844 | + 'name' => 'logout', |
|
845 | + 'parent_name' => 'account', |
|
846 | + 'href' => 'action/logout', |
|
847 | + 'text' => elgg_echo('logout'), |
|
848 | + 'icon' => 'sign-out', |
|
849 | + 'is_action' => true, |
|
850 | + 'priority' => 900, |
|
851 | + 'section' => 'alt', |
|
852 | + ]); |
|
853 | 853 | |
854 | - return $return; |
|
854 | + return $return; |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | */ |
866 | 866 | function _elgg_user_set_icon_file($hook, $type, $icon, $params) { |
867 | 867 | |
868 | - $entity = elgg_extract('entity', $params); |
|
869 | - $size = elgg_extract('size', $params, 'medium'); |
|
868 | + $entity = elgg_extract('entity', $params); |
|
869 | + $size = elgg_extract('size', $params, 'medium'); |
|
870 | 870 | |
871 | - $icon->owner_guid = $entity->guid; |
|
872 | - $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
871 | + $icon->owner_guid = $entity->guid; |
|
872 | + $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
873 | 873 | |
874 | - return $icon; |
|
874 | + return $icon; |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
@@ -886,27 +886,27 @@ discard block |
||
886 | 886 | */ |
887 | 887 | function _elgg_user_get_subscriber_unban_action($hook, $type, $return_value, $params) { |
888 | 888 | |
889 | - if (!elgg_get_config('security_notify_user_ban')) { |
|
890 | - return; |
|
891 | - } |
|
889 | + if (!elgg_get_config('security_notify_user_ban')) { |
|
890 | + return; |
|
891 | + } |
|
892 | 892 | |
893 | - $event = elgg_extract('event', $params); |
|
894 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
895 | - return; |
|
896 | - } |
|
893 | + $event = elgg_extract('event', $params); |
|
894 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
895 | + return; |
|
896 | + } |
|
897 | 897 | |
898 | - if ($event->getAction() !== 'unban') { |
|
899 | - return; |
|
900 | - } |
|
898 | + if ($event->getAction() !== 'unban') { |
|
899 | + return; |
|
900 | + } |
|
901 | 901 | |
902 | - $user = $event->getObject(); |
|
903 | - if (!($user instanceof \ElggUser)) { |
|
904 | - return; |
|
905 | - } |
|
902 | + $user = $event->getObject(); |
|
903 | + if (!($user instanceof \ElggUser)) { |
|
904 | + return; |
|
905 | + } |
|
906 | 906 | |
907 | - $return_value[$user->getGUID()] = ['email']; |
|
907 | + $return_value[$user->getGUID()] = ['email']; |
|
908 | 908 | |
909 | - return $return_value; |
|
909 | + return $return_value; |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | /** |
@@ -922,29 +922,29 @@ discard block |
||
922 | 922 | */ |
923 | 923 | function _elgg_user_ban_notification($event, $type, $user) { |
924 | 924 | |
925 | - if (!elgg_get_config('security_notify_user_ban')) { |
|
926 | - return; |
|
927 | - } |
|
925 | + if (!elgg_get_config('security_notify_user_ban')) { |
|
926 | + return; |
|
927 | + } |
|
928 | 928 | |
929 | - if (!($user instanceof \ElggUser)) { |
|
930 | - return; |
|
931 | - } |
|
929 | + if (!($user instanceof \ElggUser)) { |
|
930 | + return; |
|
931 | + } |
|
932 | 932 | |
933 | - $site = elgg_get_site_entity(); |
|
933 | + $site = elgg_get_site_entity(); |
|
934 | 934 | |
935 | - $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
936 | - $body = elgg_echo('user:notification:ban:body', [ |
|
937 | - $recipient->name, |
|
938 | - $site->name, |
|
939 | - $site->getURL(), |
|
940 | - ], $language); |
|
935 | + $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
936 | + $body = elgg_echo('user:notification:ban:body', [ |
|
937 | + $recipient->name, |
|
938 | + $site->name, |
|
939 | + $site->getURL(), |
|
940 | + ], $language); |
|
941 | 941 | |
942 | - $params = [ |
|
943 | - 'action' => 'ban', |
|
944 | - 'object' => $user, |
|
945 | - ]; |
|
942 | + $params = [ |
|
943 | + 'action' => 'ban', |
|
944 | + 'object' => $user, |
|
945 | + ]; |
|
946 | 946 | |
947 | - notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
947 | + notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -959,34 +959,34 @@ discard block |
||
959 | 959 | */ |
960 | 960 | function _elgg_user_prepare_unban_notification($hook, $type, $return_value, $params) { |
961 | 961 | |
962 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
963 | - return; |
|
964 | - } |
|
962 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
963 | + return; |
|
964 | + } |
|
965 | 965 | |
966 | - $recipient = elgg_extract('recipient', $params); |
|
967 | - $object = elgg_extract('object', $params); |
|
968 | - $language = elgg_extract('language', $params); |
|
966 | + $recipient = elgg_extract('recipient', $params); |
|
967 | + $object = elgg_extract('object', $params); |
|
968 | + $language = elgg_extract('language', $params); |
|
969 | 969 | |
970 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
971 | - return; |
|
972 | - } |
|
970 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
971 | + return; |
|
972 | + } |
|
973 | 973 | |
974 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
975 | - return; |
|
976 | - } |
|
974 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
975 | + return; |
|
976 | + } |
|
977 | 977 | |
978 | - $site = elgg_get_site_entity(); |
|
978 | + $site = elgg_get_site_entity(); |
|
979 | 979 | |
980 | - $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
981 | - $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
982 | - $recipient->name, |
|
983 | - $site->name, |
|
984 | - $site->getURL(), |
|
985 | - ], $language); |
|
986 | - |
|
987 | - $return_value->url = $recipient->getURL(); |
|
980 | + $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
981 | + $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
982 | + $recipient->name, |
|
983 | + $site->name, |
|
984 | + $site->getURL(), |
|
985 | + ], $language); |
|
986 | + |
|
987 | + $return_value->url = $recipient->getURL(); |
|
988 | 988 | |
989 | - return $return_value; |
|
989 | + return $return_value; |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | /** |
@@ -997,42 +997,42 @@ discard block |
||
997 | 997 | */ |
998 | 998 | function users_init() { |
999 | 999 | |
1000 | - elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
1001 | - elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
1002 | - elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
1003 | - elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
1004 | - elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
1005 | - elgg_register_page_handler('profile', 'elgg_profile_page_handler'); |
|
1000 | + elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
1001 | + elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
1002 | + elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
1003 | + elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
1004 | + elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
1005 | + elgg_register_page_handler('profile', 'elgg_profile_page_handler'); |
|
1006 | 1006 | |
1007 | - elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
1008 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
1009 | - elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
1007 | + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
1008 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
1009 | + elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
1010 | 1010 | |
1011 | - elgg_register_action('login', '', 'public'); |
|
1012 | - elgg_register_action('logout'); |
|
1013 | - elgg_register_action('register', '', 'public'); |
|
1014 | - elgg_register_action('useradd', '', 'admin'); |
|
1015 | - elgg_register_action('avatar/upload'); |
|
1016 | - elgg_register_action('avatar/crop'); |
|
1017 | - elgg_register_action('avatar/remove'); |
|
1018 | - elgg_register_action('profile/edit'); |
|
1011 | + elgg_register_action('login', '', 'public'); |
|
1012 | + elgg_register_action('logout'); |
|
1013 | + elgg_register_action('register', '', 'public'); |
|
1014 | + elgg_register_action('useradd', '', 'admin'); |
|
1015 | + elgg_register_action('avatar/upload'); |
|
1016 | + elgg_register_action('avatar/crop'); |
|
1017 | + elgg_register_action('avatar/remove'); |
|
1018 | + elgg_register_action('profile/edit'); |
|
1019 | 1019 | |
1020 | - elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
1020 | + elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
1021 | 1021 | |
1022 | - elgg_register_action('user/changepassword', '', 'public'); |
|
1023 | - elgg_register_action('user/requestnewpassword', '', 'public'); |
|
1022 | + elgg_register_action('user/changepassword', '', 'public'); |
|
1023 | + elgg_register_action('user/requestnewpassword', '', 'public'); |
|
1024 | 1024 | |
1025 | - // Register the user type |
|
1026 | - elgg_register_entity_type('user', ''); |
|
1025 | + // Register the user type |
|
1026 | + elgg_register_entity_type('user', ''); |
|
1027 | 1027 | |
1028 | - elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_users_setup_entity_menu', 501); |
|
1028 | + elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_users_setup_entity_menu', 501); |
|
1029 | 1029 | |
1030 | - elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
1030 | + elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
1031 | 1031 | |
1032 | - elgg_register_notification_event('user', '', ['unban']); |
|
1033 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
1034 | - elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
1035 | - elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
1032 | + elgg_register_notification_event('user', '', ['unban']); |
|
1033 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
1034 | + elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
1035 | + elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
1036 | 1036 | |
1037 | 1037 | } |
1038 | 1038 | |
@@ -1048,13 +1048,13 @@ discard block |
||
1048 | 1048 | * @access private |
1049 | 1049 | */ |
1050 | 1050 | function users_test($hook, $type, $value, $params) { |
1051 | - global $CONFIG; |
|
1052 | - $value[] = "{$CONFIG->path}engine/tests/ElggUserTest.php"; |
|
1053 | - return $value; |
|
1051 | + global $CONFIG; |
|
1052 | + $value[] = "{$CONFIG->path}engine/tests/ElggUserTest.php"; |
|
1053 | + return $value; |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
1057 | - $events->registerHandler('init', 'system', 'users_init', 0); |
|
1058 | - $events->registerHandler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins |
|
1059 | - $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
1057 | + $events->registerHandler('init', 'system', 'users_init', 0); |
|
1058 | + $events->registerHandler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins |
|
1059 | + $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
1060 | 1060 | }; |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | if (empty($title)) { |
546 | 546 | $params['title'] = elgg_get_config('sitename'); |
547 | 547 | } else { |
548 | - $params['title'] = $title . ' : ' . elgg_get_config('sitename'); |
|
548 | + $params['title'] = $title.' : '.elgg_get_config('sitename'); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | $params['metas']['content-type'] = [ |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | $vars = array_merge($item->getValues(), $vars); |
882 | 882 | |
883 | 883 | if ($item->getLinkClass()) { |
884 | - $vars['class'] .= ' ' . $item->getLinkClass(); |
|
884 | + $vars['class'] .= ' '.$item->getLinkClass(); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | if ($item->getHref() === false || $item->getHref() === null) { |
@@ -1448,7 +1448,7 @@ discard block |
||
1448 | 1448 | */ |
1449 | 1449 | function elgg_view_input($input_type, array $vars = []) { |
1450 | 1450 | |
1451 | - elgg_deprecated_notice(__FUNCTION__ . '() is deprecated. Use elgg_view_field()', '2.3'); |
|
1451 | + elgg_deprecated_notice(__FUNCTION__.'() is deprecated. Use elgg_view_field()', '2.3'); |
|
1452 | 1452 | |
1453 | 1453 | $vars['#type'] = $input_type; |
1454 | 1454 | |
@@ -1488,7 +1488,7 @@ discard block |
||
1488 | 1488 | function elgg_view_field(array $params = []) { |
1489 | 1489 | |
1490 | 1490 | if (empty($params['#type'])) { |
1491 | - _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.'); |
|
1491 | + _elgg_services()->logger->error(__FUNCTION__.'(): $params["#type"] is required.'); |
|
1492 | 1492 | return ''; |
1493 | 1493 | } |
1494 | 1494 | |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | |
1509 | 1509 | $id = elgg_extract('id', $params); |
1510 | 1510 | if (!$id) { |
1511 | - $id = "elgg-field-" . base_convert(mt_rand(), 10, 36); |
|
1511 | + $id = "elgg-field-".base_convert(mt_rand(), 10, 36); |
|
1512 | 1512 | $params['id'] = $id; |
1513 | 1513 | } |
1514 | 1514 | |
@@ -1849,7 +1849,7 @@ discard block |
||
1849 | 1849 | } else { |
1850 | 1850 | // relative path |
1851 | 1851 | $root = dirname(dirname(__DIR__)); |
1852 | - $expected_path = "$root/views/$viewtype/" . ltrim($path, '/\\'); |
|
1852 | + $expected_path = "$root/views/$viewtype/".ltrim($path, '/\\'); |
|
1853 | 1853 | } |
1854 | 1854 | |
1855 | 1855 | $view_path = $views->findViewFile($view, $viewtype); |
@@ -1868,10 +1868,10 @@ discard block |
||
1868 | 1868 | function elgg_views_boot() { |
1869 | 1869 | if (!elgg_get_config('system_cache_loaded')) { |
1870 | 1870 | // Core view files in /views |
1871 | - _elgg_services()->views->registerPluginViews(realpath(__DIR__ . '/../../')); |
|
1871 | + _elgg_services()->views->registerPluginViews(realpath(__DIR__.'/../../')); |
|
1872 | 1872 | |
1873 | 1873 | // Core view definitions in /engine/views.php |
1874 | - $file = dirname(__DIR__) . '/views.php'; |
|
1874 | + $file = dirname(__DIR__).'/views.php'; |
|
1875 | 1875 | if (is_file($file)) { |
1876 | 1876 | $spec = Includer::includeFile($file); |
1877 | 1877 | if (is_array($spec)) { |
@@ -1940,7 +1940,7 @@ discard block |
||
1940 | 1940 | $view_path = _elgg_services()->views->view_path; |
1941 | 1941 | $viewtype_dirs = scandir($view_path); |
1942 | 1942 | foreach ($viewtype_dirs as $viewtype) { |
1943 | - if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) { |
|
1943 | + if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path.$viewtype)) { |
|
1944 | 1944 | elgg_register_viewtype($viewtype); |
1945 | 1945 | } |
1946 | 1946 | } |
@@ -2004,7 +2004,7 @@ discard block |
||
2004 | 2004 | function _elgg_get_js_page_data() { |
2005 | 2005 | $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []); |
2006 | 2006 | if (!is_array($data)) { |
2007 | - elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR'); |
|
2007 | + elgg_log('"elgg.data" plugin hook handlers must return an array. Returned '.gettype($data).'.', 'ERROR'); |
|
2008 | 2008 | $data = []; |
2009 | 2009 | } |
2010 | 2010 |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | * @return bool |
73 | 73 | */ |
74 | 74 | function elgg_set_viewtype($viewtype = "") { |
75 | - global $CURRENT_SYSTEM_VIEWTYPE; |
|
75 | + global $CURRENT_SYSTEM_VIEWTYPE; |
|
76 | 76 | |
77 | - $CURRENT_SYSTEM_VIEWTYPE = $viewtype; |
|
77 | + $CURRENT_SYSTEM_VIEWTYPE = $viewtype; |
|
78 | 78 | |
79 | - return true; |
|
79 | + return true; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | * @see elgg_set_viewtype() |
94 | 94 | */ |
95 | 95 | function elgg_get_viewtype() { |
96 | - global $CURRENT_SYSTEM_VIEWTYPE; |
|
96 | + global $CURRENT_SYSTEM_VIEWTYPE; |
|
97 | 97 | |
98 | - if (empty($CURRENT_SYSTEM_VIEWTYPE)) { |
|
99 | - $CURRENT_SYSTEM_VIEWTYPE = _elgg_get_initial_viewtype(); |
|
100 | - } |
|
98 | + if (empty($CURRENT_SYSTEM_VIEWTYPE)) { |
|
99 | + $CURRENT_SYSTEM_VIEWTYPE = _elgg_get_initial_viewtype(); |
|
100 | + } |
|
101 | 101 | |
102 | - return $CURRENT_SYSTEM_VIEWTYPE; |
|
102 | + return $CURRENT_SYSTEM_VIEWTYPE; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -110,18 +110,18 @@ discard block |
||
110 | 110 | * @since 2.0.0 |
111 | 111 | */ |
112 | 112 | function _elgg_get_initial_viewtype() { |
113 | - global $CONFIG; |
|
113 | + global $CONFIG; |
|
114 | 114 | |
115 | - $viewtype = get_input('view', '', false); |
|
116 | - if (_elgg_is_valid_viewtype($viewtype)) { |
|
117 | - return $viewtype; |
|
118 | - } |
|
115 | + $viewtype = get_input('view', '', false); |
|
116 | + if (_elgg_is_valid_viewtype($viewtype)) { |
|
117 | + return $viewtype; |
|
118 | + } |
|
119 | 119 | |
120 | - if (isset($CONFIG->view) && _elgg_is_valid_viewtype($CONFIG->view)) { |
|
121 | - return $CONFIG->view; |
|
122 | - } |
|
120 | + if (isset($CONFIG->view) && _elgg_is_valid_viewtype($CONFIG->view)) { |
|
121 | + return $CONFIG->view; |
|
122 | + } |
|
123 | 123 | |
124 | - return 'default'; |
|
124 | + return 'default'; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | * @return bool |
132 | 132 | */ |
133 | 133 | function elgg_register_viewtype($viewtype) { |
134 | - if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) { |
|
135 | - $GLOBALS['_ELGG']->view_types = []; |
|
136 | - } |
|
134 | + if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) { |
|
135 | + $GLOBALS['_ELGG']->view_types = []; |
|
136 | + } |
|
137 | 137 | |
138 | - if (!in_array($viewtype, $GLOBALS['_ELGG']->view_types)) { |
|
139 | - $GLOBALS['_ELGG']->view_types[] = $viewtype; |
|
140 | - } |
|
138 | + if (!in_array($viewtype, $GLOBALS['_ELGG']->view_types)) { |
|
139 | + $GLOBALS['_ELGG']->view_types[] = $viewtype; |
|
140 | + } |
|
141 | 141 | |
142 | - return true; |
|
142 | + return true; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * @since 1.9.0 |
152 | 152 | */ |
153 | 153 | function elgg_is_registered_viewtype($viewtype) { |
154 | - if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) { |
|
155 | - return false; |
|
156 | - } |
|
154 | + if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) { |
|
155 | + return false; |
|
156 | + } |
|
157 | 157 | |
158 | - return in_array($viewtype, $GLOBALS['_ELGG']->view_types); |
|
158 | + return in_array($viewtype, $GLOBALS['_ELGG']->view_types); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | * @since 1.9 |
170 | 170 | */ |
171 | 171 | function _elgg_is_valid_viewtype($viewtype) { |
172 | - if (!is_string($viewtype) || $viewtype === '') { |
|
173 | - return false; |
|
174 | - } |
|
172 | + if (!is_string($viewtype) || $viewtype === '') { |
|
173 | + return false; |
|
174 | + } |
|
175 | 175 | |
176 | - if (preg_match('/\W/', $viewtype)) { |
|
177 | - return false; |
|
178 | - } |
|
176 | + if (preg_match('/\W/', $viewtype)) { |
|
177 | + return false; |
|
178 | + } |
|
179 | 179 | |
180 | - return true; |
|
180 | + return true; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 1.7.2 |
193 | 193 | */ |
194 | 194 | function elgg_register_viewtype_fallback($viewtype) { |
195 | - _elgg_services()->views->registerViewtypeFallback($viewtype); |
|
195 | + _elgg_services()->views->registerViewtypeFallback($viewtype); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @since 1.7.2 |
205 | 205 | */ |
206 | 206 | function elgg_does_viewtype_fallback($viewtype) { |
207 | - return _elgg_services()->views->doesViewtypeFallback($viewtype); |
|
207 | + return _elgg_services()->views->doesViewtypeFallback($viewtype); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @since 1.8.3 |
220 | 220 | */ |
221 | 221 | function elgg_register_ajax_view($view) { |
222 | - elgg_register_external_view($view, false); |
|
222 | + elgg_register_external_view($view, false); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @since 1.8.3 |
231 | 231 | */ |
232 | 232 | function elgg_unregister_ajax_view($view) { |
233 | - elgg_unregister_external_view($view); |
|
233 | + elgg_unregister_external_view($view); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -243,11 +243,11 @@ discard block |
||
243 | 243 | */ |
244 | 244 | function elgg_register_external_view($view, $cacheable = false) { |
245 | 245 | |
246 | - _elgg_services()->ajax->registerView($view); |
|
246 | + _elgg_services()->ajax->registerView($view); |
|
247 | 247 | |
248 | - if ($cacheable) { |
|
249 | - _elgg_services()->views->registerCacheableView($view); |
|
250 | - } |
|
248 | + if ($cacheable) { |
|
249 | + _elgg_services()->views->registerCacheableView($view); |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @since 1.9.0 |
259 | 259 | */ |
260 | 260 | function elgg_unregister_external_view($view) { |
261 | - _elgg_services()->ajax->unregisterView($view); |
|
261 | + _elgg_services()->ajax->unregisterView($view); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @return void |
277 | 277 | */ |
278 | 278 | function elgg_set_view_location($view, $location, $viewtype = '') { |
279 | - _elgg_services()->views->setViewDir($view, $location, $viewtype); |
|
279 | + _elgg_services()->views->setViewDir($view, $location, $viewtype); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | function elgg_view_exists($view, $viewtype = '', $recurse = true) { |
294 | - return _elgg_services()->views->viewExists($view, $viewtype, $recurse); |
|
294 | + return _elgg_services()->views->viewExists($view, $viewtype, $recurse); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @since 2.0 |
305 | 305 | */ |
306 | 306 | function elgg_list_views($viewtype = 'default') { |
307 | - return _elgg_services()->views->listViews($viewtype); |
|
307 | + return _elgg_services()->views->listViews($viewtype); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * @return string The parsed view |
335 | 335 | */ |
336 | 336 | function elgg_view($view, $vars = [], $ignore1 = false, $ignore2 = false, $viewtype = '') { |
337 | - return _elgg_services()->views->renderView($view, $vars, $ignore1, $viewtype); |
|
337 | + return _elgg_services()->views->renderView($view, $vars, $ignore1, $viewtype); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @access private |
352 | 352 | */ |
353 | 353 | function elgg_view_deprecated($view, array $vars, $suggestion, $version) { |
354 | - return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version); |
|
354 | + return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @since 1.7.0 |
379 | 379 | */ |
380 | 380 | function elgg_extend_view($view, $view_extension, $priority = 501) { |
381 | - _elgg_services()->views->extendView($view, $view_extension, $priority); |
|
381 | + _elgg_services()->views->extendView($view, $view_extension, $priority); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * @since 1.7.2 |
392 | 392 | */ |
393 | 393 | function elgg_unextend_view($view, $view_extension) { |
394 | - return _elgg_services()->views->unextendView($view, $view_extension); |
|
394 | + return _elgg_services()->views->unextendView($view, $view_extension); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -405,9 +405,9 @@ discard block |
||
405 | 405 | * @since 2.3 |
406 | 406 | */ |
407 | 407 | function elgg_get_view_extensions($view) { |
408 | - $list = _elgg_services()->views->getViewList($view); |
|
409 | - unset($list[500]); |
|
410 | - return $list; |
|
408 | + $list = _elgg_services()->views->getViewList($view); |
|
409 | + unset($list[500]); |
|
410 | + return $list; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * @since 2.2 |
423 | 423 | */ |
424 | 424 | function elgg_prepend_css_urls($css, $path) { |
425 | - return Minify_CSS_UriRewriter::prepend($css, $path); |
|
425 | + return Minify_CSS_UriRewriter::prepend($css, $path); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -445,56 +445,56 @@ discard block |
||
445 | 445 | * @since 1.8 |
446 | 446 | */ |
447 | 447 | function elgg_view_page($title, $body, $page_shell = 'default', $vars = []) { |
448 | - $timer = _elgg_services()->timer; |
|
449 | - if (!$timer->hasEnded(['build page'])) { |
|
450 | - $timer->end(['build page']); |
|
451 | - } |
|
452 | - $timer->begin([__FUNCTION__]); |
|
448 | + $timer = _elgg_services()->timer; |
|
449 | + if (!$timer->hasEnded(['build page'])) { |
|
450 | + $timer->end(['build page']); |
|
451 | + } |
|
452 | + $timer->begin([__FUNCTION__]); |
|
453 | 453 | |
454 | - $params = []; |
|
455 | - $params['identifier'] = _elgg_services()->request->getFirstUrlSegment(); |
|
456 | - $params['segments'] = _elgg_services()->request->getUrlSegments(); |
|
457 | - array_shift($params['segments']); |
|
458 | - $page_shell = elgg_trigger_plugin_hook('shell', 'page', $params, $page_shell); |
|
454 | + $params = []; |
|
455 | + $params['identifier'] = _elgg_services()->request->getFirstUrlSegment(); |
|
456 | + $params['segments'] = _elgg_services()->request->getUrlSegments(); |
|
457 | + array_shift($params['segments']); |
|
458 | + $page_shell = elgg_trigger_plugin_hook('shell', 'page', $params, $page_shell); |
|
459 | 459 | |
460 | 460 | |
461 | - $system_messages = _elgg_services()->systemMessages; |
|
461 | + $system_messages = _elgg_services()->systemMessages; |
|
462 | 462 | |
463 | - $messages = null; |
|
464 | - if ($system_messages->count()) { |
|
465 | - $messages = $system_messages->dumpRegister(); |
|
463 | + $messages = null; |
|
464 | + if ($system_messages->count()) { |
|
465 | + $messages = $system_messages->dumpRegister(); |
|
466 | 466 | |
467 | - if (isset($messages['error'])) { |
|
468 | - // always make sure error is the first type |
|
469 | - $errors = [ |
|
470 | - 'error' => $messages['error'] |
|
471 | - ]; |
|
467 | + if (isset($messages['error'])) { |
|
468 | + // always make sure error is the first type |
|
469 | + $errors = [ |
|
470 | + 'error' => $messages['error'] |
|
471 | + ]; |
|
472 | 472 | |
473 | - unset($messages['error']); |
|
474 | - $messages = array_merge($errors, $messages); |
|
475 | - } |
|
476 | - } |
|
473 | + unset($messages['error']); |
|
474 | + $messages = array_merge($errors, $messages); |
|
475 | + } |
|
476 | + } |
|
477 | 477 | |
478 | - $vars['title'] = $title; |
|
479 | - $vars['body'] = $body; |
|
480 | - $vars['sysmessages'] = $messages; |
|
481 | - $vars['page_shell'] = $page_shell; |
|
478 | + $vars['title'] = $title; |
|
479 | + $vars['body'] = $body; |
|
480 | + $vars['sysmessages'] = $messages; |
|
481 | + $vars['page_shell'] = $page_shell; |
|
482 | 482 | |
483 | - // head has keys 'title', 'metas', 'links' |
|
484 | - $head_params = _elgg_views_prepare_head($title); |
|
483 | + // head has keys 'title', 'metas', 'links' |
|
484 | + $head_params = _elgg_views_prepare_head($title); |
|
485 | 485 | |
486 | - $vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, $head_params); |
|
486 | + $vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, $head_params); |
|
487 | 487 | |
488 | - $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars); |
|
488 | + $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars); |
|
489 | 489 | |
490 | - $output = elgg_view("page/$page_shell", $vars); |
|
490 | + $output = elgg_view("page/$page_shell", $vars); |
|
491 | 491 | |
492 | 492 | |
493 | - // Allow plugins to modify the output |
|
494 | - $output = elgg_trigger_plugin_hook('output', 'page', $vars, $output); |
|
493 | + // Allow plugins to modify the output |
|
494 | + $output = elgg_trigger_plugin_hook('output', 'page', $vars, $output); |
|
495 | 495 | |
496 | - $timer->end([__FUNCTION__]); |
|
497 | - return $output; |
|
496 | + $timer->end([__FUNCTION__]); |
|
497 | + return $output; |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
@@ -508,25 +508,25 @@ discard block |
||
508 | 508 | * @throws SecurityException |
509 | 509 | */ |
510 | 510 | function elgg_view_resource($name, array $vars = []) { |
511 | - $view = "resources/$name"; |
|
511 | + $view = "resources/$name"; |
|
512 | 512 | |
513 | - if (elgg_view_exists($view)) { |
|
514 | - return _elgg_services()->views->renderView($view, $vars); |
|
515 | - } |
|
513 | + if (elgg_view_exists($view)) { |
|
514 | + return _elgg_services()->views->renderView($view, $vars); |
|
515 | + } |
|
516 | 516 | |
517 | - if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) { |
|
518 | - return _elgg_services()->views->renderView($view, $vars, false, 'default'); |
|
519 | - } |
|
517 | + if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) { |
|
518 | + return _elgg_services()->views->renderView($view, $vars, false, 'default'); |
|
519 | + } |
|
520 | 520 | |
521 | - _elgg_services()->logger->error("The view $view is missing."); |
|
521 | + _elgg_services()->logger->error("The view $view is missing."); |
|
522 | 522 | |
523 | - if (elgg_get_viewtype() === 'default') { |
|
524 | - // only works for default viewtype |
|
525 | - forward('', '404'); |
|
526 | - } else { |
|
527 | - register_error(elgg_echo('error:404:content')); |
|
528 | - forward(''); |
|
529 | - } |
|
523 | + if (elgg_get_viewtype() === 'default') { |
|
524 | + // only works for default viewtype |
|
525 | + forward('', '404'); |
|
526 | + } else { |
|
527 | + register_error(elgg_echo('error:404:content')); |
|
528 | + forward(''); |
|
529 | + } |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -537,58 +537,58 @@ discard block |
||
537 | 537 | * @access private |
538 | 538 | */ |
539 | 539 | function _elgg_views_prepare_head($title) { |
540 | - $params = [ |
|
541 | - 'links' => [], |
|
542 | - 'metas' => [], |
|
543 | - ]; |
|
544 | - |
|
545 | - if (empty($title)) { |
|
546 | - $params['title'] = elgg_get_config('sitename'); |
|
547 | - } else { |
|
548 | - $params['title'] = $title . ' : ' . elgg_get_config('sitename'); |
|
549 | - } |
|
550 | - |
|
551 | - $params['metas']['content-type'] = [ |
|
552 | - 'http-equiv' => 'Content-Type', |
|
553 | - 'content' => 'text/html; charset=utf-8', |
|
554 | - ]; |
|
555 | - |
|
556 | - $params['metas']['description'] = [ |
|
557 | - 'name' => 'description', |
|
558 | - 'content' => elgg_get_config('sitedescription') |
|
559 | - ]; |
|
560 | - |
|
561 | - // https://developer.chrome.com/multidevice/android/installtohomescreen |
|
562 | - $params['metas']['viewport'] = [ |
|
563 | - 'name' => 'viewport', |
|
564 | - 'content' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0', |
|
565 | - ]; |
|
566 | - $params['metas']['mobile-web-app-capable'] = [ |
|
567 | - 'name' => 'mobile-web-app-capable', |
|
568 | - 'content' => 'yes', |
|
569 | - ]; |
|
570 | - $params['metas']['apple-mobile-web-app-capable'] = [ |
|
571 | - 'name' => 'apple-mobile-web-app-capable', |
|
572 | - 'content' => 'yes', |
|
573 | - ]; |
|
540 | + $params = [ |
|
541 | + 'links' => [], |
|
542 | + 'metas' => [], |
|
543 | + ]; |
|
544 | + |
|
545 | + if (empty($title)) { |
|
546 | + $params['title'] = elgg_get_config('sitename'); |
|
547 | + } else { |
|
548 | + $params['title'] = $title . ' : ' . elgg_get_config('sitename'); |
|
549 | + } |
|
550 | + |
|
551 | + $params['metas']['content-type'] = [ |
|
552 | + 'http-equiv' => 'Content-Type', |
|
553 | + 'content' => 'text/html; charset=utf-8', |
|
554 | + ]; |
|
555 | + |
|
556 | + $params['metas']['description'] = [ |
|
557 | + 'name' => 'description', |
|
558 | + 'content' => elgg_get_config('sitedescription') |
|
559 | + ]; |
|
560 | + |
|
561 | + // https://developer.chrome.com/multidevice/android/installtohomescreen |
|
562 | + $params['metas']['viewport'] = [ |
|
563 | + 'name' => 'viewport', |
|
564 | + 'content' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0', |
|
565 | + ]; |
|
566 | + $params['metas']['mobile-web-app-capable'] = [ |
|
567 | + 'name' => 'mobile-web-app-capable', |
|
568 | + 'content' => 'yes', |
|
569 | + ]; |
|
570 | + $params['metas']['apple-mobile-web-app-capable'] = [ |
|
571 | + 'name' => 'apple-mobile-web-app-capable', |
|
572 | + 'content' => 'yes', |
|
573 | + ]; |
|
574 | 574 | |
575 | - // RSS feed link |
|
576 | - if (_elgg_has_rss_link()) { |
|
577 | - $url = current_page_url(); |
|
578 | - if (substr_count($url, '?')) { |
|
579 | - $url .= "&view=rss"; |
|
580 | - } else { |
|
581 | - $url .= "?view=rss"; |
|
582 | - } |
|
583 | - $params['links']['rss'] = [ |
|
584 | - 'rel' => 'alternative', |
|
585 | - 'type' => 'application/rss+xml', |
|
586 | - 'title' => 'RSS', |
|
587 | - 'href' => $url, |
|
588 | - ]; |
|
589 | - } |
|
575 | + // RSS feed link |
|
576 | + if (_elgg_has_rss_link()) { |
|
577 | + $url = current_page_url(); |
|
578 | + if (substr_count($url, '?')) { |
|
579 | + $url .= "&view=rss"; |
|
580 | + } else { |
|
581 | + $url .= "?view=rss"; |
|
582 | + } |
|
583 | + $params['links']['rss'] = [ |
|
584 | + 'rel' => 'alternative', |
|
585 | + 'type' => 'application/rss+xml', |
|
586 | + 'title' => 'RSS', |
|
587 | + 'href' => $url, |
|
588 | + ]; |
|
589 | + } |
|
590 | 590 | |
591 | - return $params; |
|
591 | + return $params; |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | |
@@ -610,48 +610,48 @@ discard block |
||
610 | 610 | */ |
611 | 611 | function _elgg_views_prepare_favicon_links($hook, $type, $head_params, $params) { |
612 | 612 | |
613 | - $head_params['links']['apple-touch-icon'] = [ |
|
614 | - 'rel' => 'apple-touch-icon', |
|
615 | - 'href' => elgg_get_simplecache_url('graphics/favicon-128.png'), |
|
616 | - ]; |
|
617 | - |
|
618 | - // favicons |
|
619 | - $head_params['links']['icon-ico'] = [ |
|
620 | - 'rel' => 'icon', |
|
621 | - 'href' => elgg_get_simplecache_url('graphics/favicon.ico'), |
|
622 | - ]; |
|
623 | - $head_params['links']['icon-vector'] = [ |
|
624 | - 'rel' => 'icon', |
|
625 | - 'sizes' => '16x16 32x32 48x48 64x64 128x128', |
|
626 | - 'type' => 'image/svg+xml', |
|
627 | - 'href' => elgg_get_simplecache_url('graphics/favicon.svg'), |
|
628 | - ]; |
|
629 | - $head_params['links']['icon-16'] = [ |
|
630 | - 'rel' => 'icon', |
|
631 | - 'sizes' => '16x16', |
|
632 | - 'type' => 'image/png', |
|
633 | - 'href' => elgg_get_simplecache_url('graphics/favicon-16.png'), |
|
634 | - ]; |
|
635 | - $head_params['links']['icon-32'] = [ |
|
636 | - 'rel' => 'icon', |
|
637 | - 'sizes' => '32x32', |
|
638 | - 'type' => 'image/png', |
|
639 | - 'href' => elgg_get_simplecache_url('graphics/favicon-32.png'), |
|
640 | - ]; |
|
641 | - $head_params['links']['icon-64'] = [ |
|
642 | - 'rel' => 'icon', |
|
643 | - 'sizes' => '64x64', |
|
644 | - 'type' => 'image/png', |
|
645 | - 'href' => elgg_get_simplecache_url('graphics/favicon-64.png'), |
|
646 | - ]; |
|
647 | - $head_params['links']['icon-128'] = [ |
|
648 | - 'rel' => 'icon', |
|
649 | - 'sizes' => '128x128', |
|
650 | - 'type' => 'image/png', |
|
651 | - 'href' => elgg_get_simplecache_url('graphics/favicon-128.png'), |
|
652 | - ]; |
|
653 | - |
|
654 | - return $head_params; |
|
613 | + $head_params['links']['apple-touch-icon'] = [ |
|
614 | + 'rel' => 'apple-touch-icon', |
|
615 | + 'href' => elgg_get_simplecache_url('graphics/favicon-128.png'), |
|
616 | + ]; |
|
617 | + |
|
618 | + // favicons |
|
619 | + $head_params['links']['icon-ico'] = [ |
|
620 | + 'rel' => 'icon', |
|
621 | + 'href' => elgg_get_simplecache_url('graphics/favicon.ico'), |
|
622 | + ]; |
|
623 | + $head_params['links']['icon-vector'] = [ |
|
624 | + 'rel' => 'icon', |
|
625 | + 'sizes' => '16x16 32x32 48x48 64x64 128x128', |
|
626 | + 'type' => 'image/svg+xml', |
|
627 | + 'href' => elgg_get_simplecache_url('graphics/favicon.svg'), |
|
628 | + ]; |
|
629 | + $head_params['links']['icon-16'] = [ |
|
630 | + 'rel' => 'icon', |
|
631 | + 'sizes' => '16x16', |
|
632 | + 'type' => 'image/png', |
|
633 | + 'href' => elgg_get_simplecache_url('graphics/favicon-16.png'), |
|
634 | + ]; |
|
635 | + $head_params['links']['icon-32'] = [ |
|
636 | + 'rel' => 'icon', |
|
637 | + 'sizes' => '32x32', |
|
638 | + 'type' => 'image/png', |
|
639 | + 'href' => elgg_get_simplecache_url('graphics/favicon-32.png'), |
|
640 | + ]; |
|
641 | + $head_params['links']['icon-64'] = [ |
|
642 | + 'rel' => 'icon', |
|
643 | + 'sizes' => '64x64', |
|
644 | + 'type' => 'image/png', |
|
645 | + 'href' => elgg_get_simplecache_url('graphics/favicon-64.png'), |
|
646 | + ]; |
|
647 | + $head_params['links']['icon-128'] = [ |
|
648 | + 'rel' => 'icon', |
|
649 | + 'sizes' => '128x128', |
|
650 | + 'type' => 'image/png', |
|
651 | + 'href' => elgg_get_simplecache_url('graphics/favicon-128.png'), |
|
652 | + ]; |
|
653 | + |
|
654 | + return $head_params; |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | /** |
@@ -683,67 +683,67 @@ discard block |
||
683 | 683 | * @return string |
684 | 684 | */ |
685 | 685 | function elgg_view_layout($layout_name, $vars = []) { |
686 | - $timer = _elgg_services()->timer; |
|
687 | - if (!$timer->hasEnded(['build page'])) { |
|
688 | - $timer->end(['build page']); |
|
689 | - } |
|
690 | - $timer->begin([__FUNCTION__]); |
|
691 | - |
|
692 | - // Help plugins transition without breaking them |
|
693 | - switch ($layout_name) { |
|
694 | - case 'content' : |
|
695 | - $layout_name = 'default'; |
|
696 | - $vars = _elgg_normalize_content_layout_vars($vars); |
|
697 | - break; |
|
698 | - |
|
699 | - case 'one_sidebar' : |
|
700 | - $layout_name = 'default'; |
|
701 | - $vars['sidebar'] = elgg_extract('sidebar', $vars, '', false); |
|
702 | - $vars['sidebar_alt'] = false; |
|
703 | - break; |
|
704 | - |
|
705 | - case 'one_column' : |
|
706 | - $layout_name = 'default'; |
|
707 | - $vars['sidebar'] = false; |
|
708 | - $vars['sidebar_alt'] = false; |
|
709 | - break; |
|
710 | - |
|
711 | - case 'two_sidebar' : |
|
712 | - $layout_name = 'default'; |
|
713 | - $vars['sidebar'] = elgg_extract('sidebar', $vars, '', false); |
|
714 | - $vars['sidebar_alt'] = elgg_extract('sidebar_alt', $vars, '', false); |
|
715 | - break; |
|
716 | - } |
|
717 | - |
|
718 | - if (isset($vars['nav'])) { |
|
719 | - // Temporary helper until all core views are updated |
|
720 | - $vars['breadcrumbs'] = $vars['nav']; |
|
721 | - unset($vars['nav']); |
|
722 | - } |
|
723 | - |
|
724 | - $vars['identifier'] = _elgg_services()->request->getFirstUrlSegment(); |
|
725 | - $vars['segments'] = _elgg_services()->request->getUrlSegments(); |
|
726 | - array_shift($vars['segments']); |
|
727 | - |
|
728 | - $layout_name = elgg_trigger_plugin_hook('layout', 'page', $vars, $layout_name); |
|
729 | - |
|
730 | - $vars['layout'] = $layout_name; |
|
731 | - |
|
732 | - $layout_views = [ |
|
733 | - "page/layouts/$layout_name", |
|
734 | - "page/layouts/default", |
|
735 | - ]; |
|
736 | - |
|
737 | - $output = ''; |
|
738 | - foreach ($layout_views as $layout_view) { |
|
739 | - if (elgg_view_exists($layout_view)) { |
|
740 | - $output = elgg_view($layout_view, $vars); |
|
741 | - break; |
|
742 | - } |
|
743 | - } |
|
744 | - |
|
745 | - $timer->end([__FUNCTION__]); |
|
746 | - return $output; |
|
686 | + $timer = _elgg_services()->timer; |
|
687 | + if (!$timer->hasEnded(['build page'])) { |
|
688 | + $timer->end(['build page']); |
|
689 | + } |
|
690 | + $timer->begin([__FUNCTION__]); |
|
691 | + |
|
692 | + // Help plugins transition without breaking them |
|
693 | + switch ($layout_name) { |
|
694 | + case 'content' : |
|
695 | + $layout_name = 'default'; |
|
696 | + $vars = _elgg_normalize_content_layout_vars($vars); |
|
697 | + break; |
|
698 | + |
|
699 | + case 'one_sidebar' : |
|
700 | + $layout_name = 'default'; |
|
701 | + $vars['sidebar'] = elgg_extract('sidebar', $vars, '', false); |
|
702 | + $vars['sidebar_alt'] = false; |
|
703 | + break; |
|
704 | + |
|
705 | + case 'one_column' : |
|
706 | + $layout_name = 'default'; |
|
707 | + $vars['sidebar'] = false; |
|
708 | + $vars['sidebar_alt'] = false; |
|
709 | + break; |
|
710 | + |
|
711 | + case 'two_sidebar' : |
|
712 | + $layout_name = 'default'; |
|
713 | + $vars['sidebar'] = elgg_extract('sidebar', $vars, '', false); |
|
714 | + $vars['sidebar_alt'] = elgg_extract('sidebar_alt', $vars, '', false); |
|
715 | + break; |
|
716 | + } |
|
717 | + |
|
718 | + if (isset($vars['nav'])) { |
|
719 | + // Temporary helper until all core views are updated |
|
720 | + $vars['breadcrumbs'] = $vars['nav']; |
|
721 | + unset($vars['nav']); |
|
722 | + } |
|
723 | + |
|
724 | + $vars['identifier'] = _elgg_services()->request->getFirstUrlSegment(); |
|
725 | + $vars['segments'] = _elgg_services()->request->getUrlSegments(); |
|
726 | + array_shift($vars['segments']); |
|
727 | + |
|
728 | + $layout_name = elgg_trigger_plugin_hook('layout', 'page', $vars, $layout_name); |
|
729 | + |
|
730 | + $vars['layout'] = $layout_name; |
|
731 | + |
|
732 | + $layout_views = [ |
|
733 | + "page/layouts/$layout_name", |
|
734 | + "page/layouts/default", |
|
735 | + ]; |
|
736 | + |
|
737 | + $output = ''; |
|
738 | + foreach ($layout_views as $layout_view) { |
|
739 | + if (elgg_view_exists($layout_view)) { |
|
740 | + $output = elgg_view($layout_view, $vars); |
|
741 | + break; |
|
742 | + } |
|
743 | + } |
|
744 | + |
|
745 | + $timer->end([__FUNCTION__]); |
|
746 | + return $output; |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -756,27 +756,27 @@ discard block |
||
756 | 756 | */ |
757 | 757 | function _elgg_normalize_content_layout_vars(array $vars = []) { |
758 | 758 | |
759 | - $context = elgg_extract('context', $vars, elgg_get_context()); |
|
760 | - |
|
761 | - $vars['title'] = elgg_extract('title', $vars, ''); |
|
762 | - if (!$vars['title'] && $vars['title'] !== false) { |
|
763 | - $vars['title'] = elgg_echo($context); |
|
764 | - } |
|
765 | - |
|
766 | - // 1.8 supported 'filter_override' |
|
767 | - if (isset($vars['filter_override'])) { |
|
768 | - $vars['filter'] = $vars['filter_override']; |
|
769 | - } |
|
770 | - |
|
771 | - // register the default content filters |
|
772 | - if (!isset($vars['filter']) && $context) { |
|
773 | - $selected = elgg_extract('filter_context', $vars); |
|
774 | - $vars['filter'] = elgg_get_filter_tabs($context, $selected, null, $vars); |
|
775 | - $vars['filter_id'] = $context; |
|
776 | - $vars['filter_value'] = $selected; |
|
777 | - } |
|
759 | + $context = elgg_extract('context', $vars, elgg_get_context()); |
|
760 | + |
|
761 | + $vars['title'] = elgg_extract('title', $vars, ''); |
|
762 | + if (!$vars['title'] && $vars['title'] !== false) { |
|
763 | + $vars['title'] = elgg_echo($context); |
|
764 | + } |
|
765 | + |
|
766 | + // 1.8 supported 'filter_override' |
|
767 | + if (isset($vars['filter_override'])) { |
|
768 | + $vars['filter'] = $vars['filter_override']; |
|
769 | + } |
|
770 | + |
|
771 | + // register the default content filters |
|
772 | + if (!isset($vars['filter']) && $context) { |
|
773 | + $selected = elgg_extract('filter_context', $vars); |
|
774 | + $vars['filter'] = elgg_get_filter_tabs($context, $selected, null, $vars); |
|
775 | + $vars['filter_id'] = $context; |
|
776 | + $vars['filter_value'] = $selected; |
|
777 | + } |
|
778 | 778 | |
779 | - return $vars; |
|
779 | + return $vars; |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
@@ -836,33 +836,33 @@ discard block |
||
836 | 836 | */ |
837 | 837 | function elgg_view_menu($menu, array $vars = []) { |
838 | 838 | |
839 | - $menu_view = elgg_extract('menu_view', $vars); |
|
840 | - unset($vars['menu_view']); |
|
841 | - |
|
842 | - if (is_string($menu)) { |
|
843 | - $menu = _elgg_services()->menus->getMenu($menu, $vars); |
|
844 | - } elseif ($menu instanceof UnpreparedMenu) { |
|
845 | - $menu = _elgg_services()->menus->prepareMenu($menu); |
|
846 | - } |
|
847 | - |
|
848 | - if (!$menu instanceof Menu) { |
|
849 | - throw new \InvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu'); |
|
850 | - } |
|
851 | - |
|
852 | - $name = $menu->getName(); |
|
853 | - $params = $menu->getParams(); |
|
854 | - |
|
855 | - $views = [ |
|
856 | - $menu_view, |
|
857 | - "navigation/menu/$name", |
|
858 | - 'navigation/menu/default', |
|
859 | - ]; |
|
860 | - |
|
861 | - foreach ($views as $view) { |
|
862 | - if (elgg_view_exists($view)) { |
|
863 | - return elgg_view($view, $params); |
|
864 | - } |
|
865 | - } |
|
839 | + $menu_view = elgg_extract('menu_view', $vars); |
|
840 | + unset($vars['menu_view']); |
|
841 | + |
|
842 | + if (is_string($menu)) { |
|
843 | + $menu = _elgg_services()->menus->getMenu($menu, $vars); |
|
844 | + } elseif ($menu instanceof UnpreparedMenu) { |
|
845 | + $menu = _elgg_services()->menus->prepareMenu($menu); |
|
846 | + } |
|
847 | + |
|
848 | + if (!$menu instanceof Menu) { |
|
849 | + throw new \InvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu'); |
|
850 | + } |
|
851 | + |
|
852 | + $name = $menu->getName(); |
|
853 | + $params = $menu->getParams(); |
|
854 | + |
|
855 | + $views = [ |
|
856 | + $menu_view, |
|
857 | + "navigation/menu/$name", |
|
858 | + 'navigation/menu/default', |
|
859 | + ]; |
|
860 | + |
|
861 | + foreach ($views as $view) { |
|
862 | + if (elgg_view_exists($view)) { |
|
863 | + return elgg_view($view, $params); |
|
864 | + } |
|
865 | + } |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
@@ -874,36 +874,36 @@ discard block |
||
874 | 874 | * @since 1.9.0 |
875 | 875 | */ |
876 | 876 | function elgg_view_menu_item(\ElggMenuItem $item, array $vars = []) { |
877 | - if (!isset($vars['class'])) { |
|
878 | - $vars['class'] = 'elgg-menu-content'; |
|
879 | - } |
|
877 | + if (!isset($vars['class'])) { |
|
878 | + $vars['class'] = 'elgg-menu-content'; |
|
879 | + } |
|
880 | 880 | |
881 | - $vars = array_merge($item->getValues(), $vars); |
|
881 | + $vars = array_merge($item->getValues(), $vars); |
|
882 | 882 | |
883 | - if ($item->getLinkClass()) { |
|
884 | - $vars['class'] .= ' ' . $item->getLinkClass(); |
|
885 | - } |
|
883 | + if ($item->getLinkClass()) { |
|
884 | + $vars['class'] .= ' ' . $item->getLinkClass(); |
|
885 | + } |
|
886 | 886 | |
887 | - if ($item->getHref() === false || $item->getHref() === null) { |
|
888 | - $text = $item->getText(); |
|
887 | + if ($item->getHref() === false || $item->getHref() === null) { |
|
888 | + $text = $item->getText(); |
|
889 | 889 | |
890 | - // if contains elements, don't wrap |
|
891 | - if (preg_match('~<[a-z]~', $text)) { |
|
892 | - return $text; |
|
893 | - } else { |
|
894 | - return elgg_format_element('span', ['class' => 'elgg-non-link'], $text); |
|
895 | - } |
|
896 | - } |
|
890 | + // if contains elements, don't wrap |
|
891 | + if (preg_match('~<[a-z]~', $text)) { |
|
892 | + return $text; |
|
893 | + } else { |
|
894 | + return elgg_format_element('span', ['class' => 'elgg-non-link'], $text); |
|
895 | + } |
|
896 | + } |
|
897 | 897 | |
898 | - if (!isset($vars['rel']) && !isset($vars['is_trusted'])) { |
|
899 | - $vars['is_trusted'] = true; |
|
900 | - } |
|
898 | + if (!isset($vars['rel']) && !isset($vars['is_trusted'])) { |
|
899 | + $vars['is_trusted'] = true; |
|
900 | + } |
|
901 | 901 | |
902 | - if ($item->getConfirmText()) { |
|
903 | - $vars['confirm'] = $item->getConfirmText(); |
|
904 | - } |
|
902 | + if ($item->getConfirmText()) { |
|
903 | + $vars['confirm'] = $item->getConfirmText(); |
|
904 | + } |
|
905 | 905 | |
906 | - return elgg_view('output/url', $vars); |
|
906 | + return elgg_view('output/url', $vars); |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
@@ -933,50 +933,50 @@ discard block |
||
933 | 933 | */ |
934 | 934 | function elgg_view_entity(\ElggEntity $entity, array $vars = [], $bypass = false, $debug = false) { |
935 | 935 | |
936 | - // No point continuing if entity is null |
|
937 | - if (!$entity || !($entity instanceof \ElggEntity)) { |
|
938 | - return false; |
|
939 | - } |
|
940 | - |
|
941 | - elgg_register_rss_link(); |
|
942 | - |
|
943 | - $defaults = [ |
|
944 | - 'full_view' => true, |
|
945 | - ]; |
|
946 | - |
|
947 | - $vars = array_merge($defaults, $vars); |
|
948 | - |
|
949 | - $vars['entity'] = $entity; |
|
950 | - |
|
951 | - $entity_type = $entity->getType(); |
|
952 | - $entity_subtype = $entity->getSubtype(); |
|
953 | - if (empty($entity_subtype)) { |
|
954 | - $entity_subtype = 'default'; |
|
955 | - } |
|
956 | - |
|
957 | - $entity_views = [ |
|
958 | - elgg_extract('item_view', $vars, ''), |
|
959 | - "$entity_type/$entity_subtype", |
|
960 | - "$entity_type/default", |
|
961 | - ]; |
|
962 | - |
|
963 | - $contents = ''; |
|
964 | - foreach ($entity_views as $view) { |
|
965 | - if (elgg_view_exists($view)) { |
|
966 | - $contents = elgg_view($view, $vars, $bypass, $debug); |
|
967 | - break; |
|
968 | - } |
|
969 | - } |
|
970 | - |
|
971 | - // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964 |
|
972 | - if ($vars['full_view']) { |
|
973 | - $annotations = elgg_view_entity_annotations($entity, $vars['full_view']); |
|
974 | - |
|
975 | - if ($annotations) { |
|
976 | - $contents .= $annotations; |
|
977 | - } |
|
978 | - } |
|
979 | - return $contents; |
|
936 | + // No point continuing if entity is null |
|
937 | + if (!$entity || !($entity instanceof \ElggEntity)) { |
|
938 | + return false; |
|
939 | + } |
|
940 | + |
|
941 | + elgg_register_rss_link(); |
|
942 | + |
|
943 | + $defaults = [ |
|
944 | + 'full_view' => true, |
|
945 | + ]; |
|
946 | + |
|
947 | + $vars = array_merge($defaults, $vars); |
|
948 | + |
|
949 | + $vars['entity'] = $entity; |
|
950 | + |
|
951 | + $entity_type = $entity->getType(); |
|
952 | + $entity_subtype = $entity->getSubtype(); |
|
953 | + if (empty($entity_subtype)) { |
|
954 | + $entity_subtype = 'default'; |
|
955 | + } |
|
956 | + |
|
957 | + $entity_views = [ |
|
958 | + elgg_extract('item_view', $vars, ''), |
|
959 | + "$entity_type/$entity_subtype", |
|
960 | + "$entity_type/default", |
|
961 | + ]; |
|
962 | + |
|
963 | + $contents = ''; |
|
964 | + foreach ($entity_views as $view) { |
|
965 | + if (elgg_view_exists($view)) { |
|
966 | + $contents = elgg_view($view, $vars, $bypass, $debug); |
|
967 | + break; |
|
968 | + } |
|
969 | + } |
|
970 | + |
|
971 | + // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964 |
|
972 | + if ($vars['full_view']) { |
|
973 | + $annotations = elgg_view_entity_annotations($entity, $vars['full_view']); |
|
974 | + |
|
975 | + if ($annotations) { |
|
976 | + $contents .= $annotations; |
|
977 | + } |
|
978 | + } |
|
979 | + return $contents; |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
@@ -996,33 +996,33 @@ discard block |
||
996 | 996 | */ |
997 | 997 | function elgg_view_entity_icon(\ElggEntity $entity, $size = 'medium', $vars = []) { |
998 | 998 | |
999 | - // No point continuing if entity is null |
|
1000 | - if (!$entity || !($entity instanceof \ElggEntity)) { |
|
1001 | - return false; |
|
1002 | - } |
|
1003 | - |
|
1004 | - $vars['entity'] = $entity; |
|
1005 | - $vars['size'] = $size; |
|
1006 | - |
|
1007 | - $entity_type = $entity->getType(); |
|
1008 | - |
|
1009 | - $subtype = $entity->getSubtype(); |
|
1010 | - if (empty($subtype)) { |
|
1011 | - $subtype = 'default'; |
|
1012 | - } |
|
1013 | - |
|
1014 | - $contents = ''; |
|
1015 | - if (elgg_view_exists("icon/$entity_type/$subtype")) { |
|
1016 | - $contents = elgg_view("icon/$entity_type/$subtype", $vars); |
|
1017 | - } |
|
1018 | - if (empty($contents)) { |
|
1019 | - $contents = elgg_view("icon/$entity_type/default", $vars); |
|
1020 | - } |
|
1021 | - if (empty($contents)) { |
|
1022 | - $contents = elgg_view("icon/default", $vars); |
|
1023 | - } |
|
1024 | - |
|
1025 | - return $contents; |
|
999 | + // No point continuing if entity is null |
|
1000 | + if (!$entity || !($entity instanceof \ElggEntity)) { |
|
1001 | + return false; |
|
1002 | + } |
|
1003 | + |
|
1004 | + $vars['entity'] = $entity; |
|
1005 | + $vars['size'] = $size; |
|
1006 | + |
|
1007 | + $entity_type = $entity->getType(); |
|
1008 | + |
|
1009 | + $subtype = $entity->getSubtype(); |
|
1010 | + if (empty($subtype)) { |
|
1011 | + $subtype = 'default'; |
|
1012 | + } |
|
1013 | + |
|
1014 | + $contents = ''; |
|
1015 | + if (elgg_view_exists("icon/$entity_type/$subtype")) { |
|
1016 | + $contents = elgg_view("icon/$entity_type/$subtype", $vars); |
|
1017 | + } |
|
1018 | + if (empty($contents)) { |
|
1019 | + $contents = elgg_view("icon/$entity_type/default", $vars); |
|
1020 | + } |
|
1021 | + if (empty($contents)) { |
|
1022 | + $contents = elgg_view("icon/default", $vars); |
|
1023 | + } |
|
1024 | + |
|
1025 | + return $contents; |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | /** |
@@ -1046,35 +1046,35 @@ discard block |
||
1046 | 1046 | * @return string/false Rendered annotation |
1047 | 1047 | */ |
1048 | 1048 | function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = [], $bypass = false, $debug = false) { |
1049 | - elgg_register_rss_link(); |
|
1050 | - |
|
1051 | - $defaults = [ |
|
1052 | - 'full_view' => true, |
|
1053 | - ]; |
|
1054 | - |
|
1055 | - $vars = array_merge($defaults, $vars); |
|
1056 | - $vars['annotation'] = $annotation; |
|
1057 | - |
|
1058 | - $name = $annotation->name; |
|
1059 | - if (empty($name)) { |
|
1060 | - return false; |
|
1061 | - } |
|
1062 | - |
|
1063 | - $annotation_views = [ |
|
1064 | - elgg_extract('item_view', $vars, ''), |
|
1065 | - "annotation/$name", |
|
1066 | - "annotation/default", |
|
1067 | - ]; |
|
1068 | - |
|
1069 | - $contents = ''; |
|
1070 | - foreach ($annotation_views as $view) { |
|
1071 | - if (elgg_view_exists($view)) { |
|
1072 | - $contents = elgg_view($view, $vars, $bypass, $debug); |
|
1073 | - break; |
|
1074 | - } |
|
1075 | - } |
|
1076 | - |
|
1077 | - return $contents; |
|
1049 | + elgg_register_rss_link(); |
|
1050 | + |
|
1051 | + $defaults = [ |
|
1052 | + 'full_view' => true, |
|
1053 | + ]; |
|
1054 | + |
|
1055 | + $vars = array_merge($defaults, $vars); |
|
1056 | + $vars['annotation'] = $annotation; |
|
1057 | + |
|
1058 | + $name = $annotation->name; |
|
1059 | + if (empty($name)) { |
|
1060 | + return false; |
|
1061 | + } |
|
1062 | + |
|
1063 | + $annotation_views = [ |
|
1064 | + elgg_extract('item_view', $vars, ''), |
|
1065 | + "annotation/$name", |
|
1066 | + "annotation/default", |
|
1067 | + ]; |
|
1068 | + |
|
1069 | + $contents = ''; |
|
1070 | + foreach ($annotation_views as $view) { |
|
1071 | + if (elgg_view_exists($view)) { |
|
1072 | + $contents = elgg_view($view, $vars, $bypass, $debug); |
|
1073 | + break; |
|
1074 | + } |
|
1075 | + } |
|
1076 | + |
|
1077 | + return $contents; |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | /** |
@@ -1107,36 +1107,36 @@ discard block |
||
1107 | 1107 | * @return string The rendered list of entities |
1108 | 1108 | */ |
1109 | 1109 | function elgg_view_entity_list($entities, array $vars = []) { |
1110 | - $offset = (int) get_input('offset', 0); |
|
1111 | - |
|
1112 | - // list type can be passed as request parameter |
|
1113 | - $list_type = get_input('list_type', 'list'); |
|
1114 | - |
|
1115 | - $defaults = [ |
|
1116 | - 'items' => $entities, |
|
1117 | - 'list_class' => 'elgg-list-entity', |
|
1118 | - 'full_view' => true, |
|
1119 | - 'pagination' => true, |
|
1120 | - 'list_type' => $list_type, |
|
1121 | - 'list_type_toggle' => false, |
|
1122 | - 'offset' => $offset, |
|
1123 | - 'limit' => null, |
|
1124 | - ]; |
|
1125 | - |
|
1126 | - $vars = array_merge($defaults, $vars); |
|
1127 | - |
|
1128 | - if (!$vars["limit"] && !$vars["offset"]) { |
|
1129 | - // no need for pagination if listing is unlimited |
|
1130 | - $vars["pagination"] = false; |
|
1131 | - } |
|
1132 | - |
|
1133 | - if ($vars['list_type'] == 'table') { |
|
1134 | - return elgg_view('page/components/table', $vars); |
|
1135 | - } elseif ($vars['list_type'] == 'list') { |
|
1136 | - return elgg_view('page/components/list', $vars); |
|
1137 | - } else { |
|
1138 | - return elgg_view('page/components/gallery', $vars); |
|
1139 | - } |
|
1110 | + $offset = (int) get_input('offset', 0); |
|
1111 | + |
|
1112 | + // list type can be passed as request parameter |
|
1113 | + $list_type = get_input('list_type', 'list'); |
|
1114 | + |
|
1115 | + $defaults = [ |
|
1116 | + 'items' => $entities, |
|
1117 | + 'list_class' => 'elgg-list-entity', |
|
1118 | + 'full_view' => true, |
|
1119 | + 'pagination' => true, |
|
1120 | + 'list_type' => $list_type, |
|
1121 | + 'list_type_toggle' => false, |
|
1122 | + 'offset' => $offset, |
|
1123 | + 'limit' => null, |
|
1124 | + ]; |
|
1125 | + |
|
1126 | + $vars = array_merge($defaults, $vars); |
|
1127 | + |
|
1128 | + if (!$vars["limit"] && !$vars["offset"]) { |
|
1129 | + // no need for pagination if listing is unlimited |
|
1130 | + $vars["pagination"] = false; |
|
1131 | + } |
|
1132 | + |
|
1133 | + if ($vars['list_type'] == 'table') { |
|
1134 | + return elgg_view('page/components/table', $vars); |
|
1135 | + } elseif ($vars['list_type'] == 'list') { |
|
1136 | + return elgg_view('page/components/list', $vars); |
|
1137 | + } else { |
|
1138 | + return elgg_view('page/components/gallery', $vars); |
|
1139 | + } |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
@@ -1158,23 +1158,23 @@ discard block |
||
1158 | 1158 | * @access private |
1159 | 1159 | */ |
1160 | 1160 | function elgg_view_annotation_list($annotations, array $vars = []) { |
1161 | - $defaults = [ |
|
1162 | - 'items' => $annotations, |
|
1163 | - 'offset' => null, |
|
1164 | - 'limit' => null, |
|
1165 | - 'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9 |
|
1166 | - 'full_view' => true, |
|
1167 | - 'offset_key' => 'annoff', |
|
1168 | - ]; |
|
1169 | - |
|
1170 | - $vars = array_merge($defaults, $vars); |
|
1171 | - |
|
1172 | - if (!$vars["limit"] && !$vars["offset"]) { |
|
1173 | - // no need for pagination if listing is unlimited |
|
1174 | - $vars["pagination"] = false; |
|
1175 | - } |
|
1176 | - |
|
1177 | - return elgg_view('page/components/list', $vars); |
|
1161 | + $defaults = [ |
|
1162 | + 'items' => $annotations, |
|
1163 | + 'offset' => null, |
|
1164 | + 'limit' => null, |
|
1165 | + 'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9 |
|
1166 | + 'full_view' => true, |
|
1167 | + 'offset_key' => 'annoff', |
|
1168 | + ]; |
|
1169 | + |
|
1170 | + $vars = array_merge($defaults, $vars); |
|
1171 | + |
|
1172 | + if (!$vars["limit"] && !$vars["offset"]) { |
|
1173 | + // no need for pagination if listing is unlimited |
|
1174 | + $vars["pagination"] = false; |
|
1175 | + } |
|
1176 | + |
|
1177 | + return elgg_view('page/components/list', $vars); |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | /** |
@@ -1192,20 +1192,20 @@ discard block |
||
1192 | 1192 | * @todo Change the hook name. |
1193 | 1193 | */ |
1194 | 1194 | function elgg_view_entity_annotations(\ElggEntity $entity, $full_view = true) { |
1195 | - if (!($entity instanceof \ElggEntity)) { |
|
1196 | - return false; |
|
1197 | - } |
|
1195 | + if (!($entity instanceof \ElggEntity)) { |
|
1196 | + return false; |
|
1197 | + } |
|
1198 | 1198 | |
1199 | - $entity_type = $entity->getType(); |
|
1199 | + $entity_type = $entity->getType(); |
|
1200 | 1200 | |
1201 | - $annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type, |
|
1202 | - [ |
|
1203 | - 'entity' => $entity, |
|
1204 | - 'full_view' => $full_view, |
|
1205 | - ] |
|
1206 | - ); |
|
1201 | + $annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type, |
|
1202 | + [ |
|
1203 | + 'entity' => $entity, |
|
1204 | + 'full_view' => $full_view, |
|
1205 | + ] |
|
1206 | + ); |
|
1207 | 1207 | |
1208 | - return $annotations; |
|
1208 | + return $annotations; |
|
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
@@ -1219,9 +1219,9 @@ discard block |
||
1219 | 1219 | * @return string The HTML (etc) |
1220 | 1220 | */ |
1221 | 1221 | function elgg_view_title($title, array $vars = []) { |
1222 | - $vars['title'] = $title; |
|
1222 | + $vars['title'] = $title; |
|
1223 | 1223 | |
1224 | - return elgg_view('page/elements/title', $vars); |
|
1224 | + return elgg_view('page/elements/title', $vars); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
@@ -1235,11 +1235,11 @@ discard block |
||
1235 | 1235 | * @since 1.7.2 |
1236 | 1236 | */ |
1237 | 1237 | function elgg_view_friendly_time($time) { |
1238 | - $view = 'output/friendlytime'; |
|
1239 | - $vars = ['time' => $time]; |
|
1240 | - $viewtype = elgg_view_exists($view) ? '' : 'default'; |
|
1238 | + $view = 'output/friendlytime'; |
|
1239 | + $vars = ['time' => $time]; |
|
1240 | + $viewtype = elgg_view_exists($view) ? '' : 'default'; |
|
1241 | 1241 | |
1242 | - return _elgg_view_under_viewtype($view, $vars, $viewtype); |
|
1242 | + return _elgg_view_under_viewtype($view, $vars, $viewtype); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | /** |
@@ -1256,20 +1256,20 @@ discard block |
||
1256 | 1256 | * @return string|false Rendered comments or false on failure |
1257 | 1257 | */ |
1258 | 1258 | function elgg_view_comments($entity, $add_comment = true, array $vars = []) { |
1259 | - if (!($entity instanceof \ElggEntity)) { |
|
1260 | - return false; |
|
1261 | - } |
|
1262 | - |
|
1263 | - $vars['entity'] = $entity; |
|
1264 | - $vars['show_add_form'] = $add_comment; |
|
1265 | - $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments"); |
|
1266 | - |
|
1267 | - $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false); |
|
1268 | - if ($output !== false) { |
|
1269 | - return $output; |
|
1270 | - } else { |
|
1271 | - return elgg_view('page/elements/comments', $vars); |
|
1272 | - } |
|
1259 | + if (!($entity instanceof \ElggEntity)) { |
|
1260 | + return false; |
|
1261 | + } |
|
1262 | + |
|
1263 | + $vars['entity'] = $entity; |
|
1264 | + $vars['show_add_form'] = $add_comment; |
|
1265 | + $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments"); |
|
1266 | + |
|
1267 | + $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false); |
|
1268 | + if ($output !== false) { |
|
1269 | + return $output; |
|
1270 | + } else { |
|
1271 | + return elgg_view('page/elements/comments', $vars); |
|
1272 | + } |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | 1275 | /** |
@@ -1291,9 +1291,9 @@ discard block |
||
1291 | 1291 | * @since 1.8.0 |
1292 | 1292 | */ |
1293 | 1293 | function elgg_view_image_block($image, $body, $vars = []) { |
1294 | - $vars['image'] = $image; |
|
1295 | - $vars['body'] = $body; |
|
1296 | - return elgg_view('page/components/image_block', $vars); |
|
1294 | + $vars['image'] = $image; |
|
1295 | + $vars['body'] = $body; |
|
1296 | + return elgg_view('page/components/image_block', $vars); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | /** |
@@ -1312,10 +1312,10 @@ discard block |
||
1312 | 1312 | * @since 1.8.0 |
1313 | 1313 | */ |
1314 | 1314 | function elgg_view_module($type, $title, $body, array $vars = []) { |
1315 | - $vars['type'] = $type; |
|
1316 | - $vars['title'] = $title; |
|
1317 | - $vars['body'] = $body; |
|
1318 | - return elgg_view('page/components/module', $vars); |
|
1315 | + $vars['type'] = $type; |
|
1316 | + $vars['title'] = $title; |
|
1317 | + $vars['body'] = $body; |
|
1318 | + return elgg_view('page/components/module', $vars); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | /** |
@@ -1327,49 +1327,49 @@ discard block |
||
1327 | 1327 | * @return string returns empty string if could not be rendered |
1328 | 1328 | */ |
1329 | 1329 | function elgg_view_river_item($item, array $vars = []) { |
1330 | - if (!($item instanceof \ElggRiverItem)) { |
|
1331 | - return ''; |
|
1332 | - } |
|
1333 | - // checking default viewtype since some viewtypes do not have unique views per item (rss) |
|
1334 | - $view = $item->getView(); |
|
1335 | - if (!$view || !elgg_view_exists($view, 'default')) { |
|
1336 | - return ''; |
|
1337 | - } |
|
1338 | - |
|
1339 | - $subject = $item->getSubjectEntity(); |
|
1340 | - $object = $item->getObjectEntity(); |
|
1341 | - if (!$subject || !$object) { |
|
1342 | - // subject is disabled or subject/object deleted |
|
1343 | - return ''; |
|
1344 | - } |
|
1345 | - |
|
1346 | - // @todo this needs to be cleaned up |
|
1347 | - // Don't hide objects in closed groups that a user can see. |
|
1348 | - // see https://github.com/elgg/elgg/issues/4789 |
|
1349 | - // else { |
|
1350 | - // // hide based on object's container |
|
1351 | - // $visibility = \Elgg\GroupItemVisibility::factory($object->container_guid); |
|
1352 | - // if ($visibility->shouldHideItems) { |
|
1353 | - // return ''; |
|
1354 | - // } |
|
1355 | - // } |
|
1356 | - |
|
1357 | - $vars['item'] = $item; |
|
1358 | - |
|
1359 | - $river_views = [ |
|
1360 | - elgg_extract('item_view', $vars, ''), |
|
1361 | - $view, |
|
1362 | - ]; |
|
1363 | - |
|
1364 | - $contents = ''; |
|
1365 | - foreach ($river_views as $view) { |
|
1366 | - if (elgg_view_exists($view)) { |
|
1367 | - $contents = elgg_view($view, $vars); |
|
1368 | - break; |
|
1369 | - } |
|
1370 | - } |
|
1371 | - |
|
1372 | - return $contents; |
|
1330 | + if (!($item instanceof \ElggRiverItem)) { |
|
1331 | + return ''; |
|
1332 | + } |
|
1333 | + // checking default viewtype since some viewtypes do not have unique views per item (rss) |
|
1334 | + $view = $item->getView(); |
|
1335 | + if (!$view || !elgg_view_exists($view, 'default')) { |
|
1336 | + return ''; |
|
1337 | + } |
|
1338 | + |
|
1339 | + $subject = $item->getSubjectEntity(); |
|
1340 | + $object = $item->getObjectEntity(); |
|
1341 | + if (!$subject || !$object) { |
|
1342 | + // subject is disabled or subject/object deleted |
|
1343 | + return ''; |
|
1344 | + } |
|
1345 | + |
|
1346 | + // @todo this needs to be cleaned up |
|
1347 | + // Don't hide objects in closed groups that a user can see. |
|
1348 | + // see https://github.com/elgg/elgg/issues/4789 |
|
1349 | + // else { |
|
1350 | + // // hide based on object's container |
|
1351 | + // $visibility = \Elgg\GroupItemVisibility::factory($object->container_guid); |
|
1352 | + // if ($visibility->shouldHideItems) { |
|
1353 | + // return ''; |
|
1354 | + // } |
|
1355 | + // } |
|
1356 | + |
|
1357 | + $vars['item'] = $item; |
|
1358 | + |
|
1359 | + $river_views = [ |
|
1360 | + elgg_extract('item_view', $vars, ''), |
|
1361 | + $view, |
|
1362 | + ]; |
|
1363 | + |
|
1364 | + $contents = ''; |
|
1365 | + foreach ($river_views as $view) { |
|
1366 | + if (elgg_view_exists($view)) { |
|
1367 | + $contents = elgg_view($view, $vars); |
|
1368 | + break; |
|
1369 | + } |
|
1370 | + } |
|
1371 | + |
|
1372 | + return $contents; |
|
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | /** |
@@ -1407,7 +1407,7 @@ discard block |
||
1407 | 1407 | * @return string The complete form |
1408 | 1408 | */ |
1409 | 1409 | function elgg_view_form($action, $form_vars = [], $body_vars = []) { |
1410 | - return _elgg_services()->forms->render($action, $form_vars, $body_vars); |
|
1410 | + return _elgg_services()->forms->render($action, $form_vars, $body_vars); |
|
1411 | 1411 | } |
1412 | 1412 | |
1413 | 1413 | /** |
@@ -1420,7 +1420,7 @@ discard block |
||
1420 | 1420 | * @return bool |
1421 | 1421 | */ |
1422 | 1422 | function elgg_set_form_footer($footer = '') { |
1423 | - return _elgg_services()->forms->setFooter($footer); |
|
1423 | + return _elgg_services()->forms->setFooter($footer); |
|
1424 | 1424 | } |
1425 | 1425 | |
1426 | 1426 | /** |
@@ -1428,7 +1428,7 @@ discard block |
||
1428 | 1428 | * @return string|false |
1429 | 1429 | */ |
1430 | 1430 | function elgg_get_form_footer() { |
1431 | - return _elgg_services()->forms->getFooter(); |
|
1431 | + return _elgg_services()->forms->getFooter(); |
|
1432 | 1432 | } |
1433 | 1433 | |
1434 | 1434 | /** |
@@ -1448,24 +1448,24 @@ discard block |
||
1448 | 1448 | */ |
1449 | 1449 | function elgg_view_input($input_type, array $vars = []) { |
1450 | 1450 | |
1451 | - elgg_deprecated_notice(__FUNCTION__ . '() is deprecated. Use elgg_view_field()', '2.3'); |
|
1451 | + elgg_deprecated_notice(__FUNCTION__ . '() is deprecated. Use elgg_view_field()', '2.3'); |
|
1452 | 1452 | |
1453 | - $vars['#type'] = $input_type; |
|
1453 | + $vars['#type'] = $input_type; |
|
1454 | 1454 | |
1455 | - if (isset($vars['label']) && $input_type !== 'checkbox') { |
|
1456 | - $vars['#label'] = $vars['label']; |
|
1457 | - unset($vars['label']); |
|
1458 | - } |
|
1459 | - if (isset($vars['help'])) { |
|
1460 | - $vars['#help'] = $vars['help']; |
|
1461 | - unset($vars['help']); |
|
1462 | - } |
|
1463 | - if (isset($vars['field_class'])) { |
|
1464 | - $vars['#class'] = $vars['field_class']; |
|
1465 | - unset($vars['field_class']); |
|
1466 | - } |
|
1455 | + if (isset($vars['label']) && $input_type !== 'checkbox') { |
|
1456 | + $vars['#label'] = $vars['label']; |
|
1457 | + unset($vars['label']); |
|
1458 | + } |
|
1459 | + if (isset($vars['help'])) { |
|
1460 | + $vars['#help'] = $vars['help']; |
|
1461 | + unset($vars['help']); |
|
1462 | + } |
|
1463 | + if (isset($vars['field_class'])) { |
|
1464 | + $vars['#class'] = $vars['field_class']; |
|
1465 | + unset($vars['field_class']); |
|
1466 | + } |
|
1467 | 1467 | |
1468 | - return elgg_view_field($vars); |
|
1468 | + return elgg_view_field($vars); |
|
1469 | 1469 | } |
1470 | 1470 | |
1471 | 1471 | /** |
@@ -1487,93 +1487,93 @@ discard block |
||
1487 | 1487 | */ |
1488 | 1488 | function elgg_view_field(array $params = []) { |
1489 | 1489 | |
1490 | - if (empty($params['#type'])) { |
|
1491 | - _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.'); |
|
1492 | - return ''; |
|
1493 | - } |
|
1494 | - |
|
1495 | - $input_type = $params['#type']; |
|
1496 | - if (!elgg_view_exists("input/$input_type")) { |
|
1497 | - return ''; |
|
1498 | - } |
|
1499 | - |
|
1500 | - $hidden_types = ['hidden', 'securitytoken']; |
|
1501 | - if (in_array($input_type, $hidden_types)) { |
|
1502 | - unset($params['#type']); |
|
1503 | - unset($params['#label']); |
|
1504 | - unset($params['#help']); |
|
1505 | - unset($params['#class']); |
|
1506 | - return elgg_view("input/$input_type", $params); |
|
1507 | - } |
|
1508 | - |
|
1509 | - $id = elgg_extract('id', $params); |
|
1510 | - if (!$id) { |
|
1511 | - $id = "elgg-field-" . base_convert(mt_rand(), 10, 36); |
|
1512 | - $params['id'] = $id; |
|
1513 | - } |
|
1514 | - |
|
1515 | - // $vars passed to label, help and field wrapper views |
|
1516 | - $element_vars = []; |
|
1517 | - |
|
1518 | - // $vars passed to input/$input_name |
|
1519 | - $input_vars = []; |
|
1490 | + if (empty($params['#type'])) { |
|
1491 | + _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.'); |
|
1492 | + return ''; |
|
1493 | + } |
|
1494 | + |
|
1495 | + $input_type = $params['#type']; |
|
1496 | + if (!elgg_view_exists("input/$input_type")) { |
|
1497 | + return ''; |
|
1498 | + } |
|
1499 | + |
|
1500 | + $hidden_types = ['hidden', 'securitytoken']; |
|
1501 | + if (in_array($input_type, $hidden_types)) { |
|
1502 | + unset($params['#type']); |
|
1503 | + unset($params['#label']); |
|
1504 | + unset($params['#help']); |
|
1505 | + unset($params['#class']); |
|
1506 | + return elgg_view("input/$input_type", $params); |
|
1507 | + } |
|
1508 | + |
|
1509 | + $id = elgg_extract('id', $params); |
|
1510 | + if (!$id) { |
|
1511 | + $id = "elgg-field-" . base_convert(mt_rand(), 10, 36); |
|
1512 | + $params['id'] = $id; |
|
1513 | + } |
|
1514 | + |
|
1515 | + // $vars passed to label, help and field wrapper views |
|
1516 | + $element_vars = []; |
|
1517 | + |
|
1518 | + // $vars passed to input/$input_name |
|
1519 | + $input_vars = []; |
|
1520 | 1520 | |
1521 | - $make_special_checkbox_label = false; |
|
1522 | - if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) { |
|
1523 | - if (isset($params['#label']) && isset($params['label'])) { |
|
1524 | - $params['label_tag'] = 'div'; |
|
1525 | - } else { |
|
1526 | - $label = elgg_extract('label', $params); |
|
1527 | - $label = elgg_extract('#label', $params, $label); |
|
1521 | + $make_special_checkbox_label = false; |
|
1522 | + if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) { |
|
1523 | + if (isset($params['#label']) && isset($params['label'])) { |
|
1524 | + $params['label_tag'] = 'div'; |
|
1525 | + } else { |
|
1526 | + $label = elgg_extract('label', $params); |
|
1527 | + $label = elgg_extract('#label', $params, $label); |
|
1528 | 1528 | |
1529 | - $params['#label'] = $label; |
|
1530 | - unset($params['label']); |
|
1531 | - |
|
1532 | - // Single checkbox input view gets special treatment |
|
1533 | - // We don't want the field label to appear a checkbox without a label |
|
1534 | - $make_special_checkbox_label = true; |
|
1535 | - } |
|
1536 | - } |
|
1537 | - |
|
1538 | - // first pass non-hash keys into both |
|
1539 | - foreach ($params as $key => $value) { |
|
1540 | - if ($key[0] !== '#') { |
|
1541 | - $element_vars[$key] = $value; |
|
1542 | - $input_vars[$key] = $value; |
|
1543 | - } |
|
1544 | - } |
|
1545 | - |
|
1546 | - // field input view needs this |
|
1547 | - $input_vars['input_type'] = $input_type; |
|
1548 | - |
|
1549 | - // field views get more data |
|
1550 | - $element_vars['input_type'] = $input_type; |
|
1529 | + $params['#label'] = $label; |
|
1530 | + unset($params['label']); |
|
1531 | + |
|
1532 | + // Single checkbox input view gets special treatment |
|
1533 | + // We don't want the field label to appear a checkbox without a label |
|
1534 | + $make_special_checkbox_label = true; |
|
1535 | + } |
|
1536 | + } |
|
1537 | + |
|
1538 | + // first pass non-hash keys into both |
|
1539 | + foreach ($params as $key => $value) { |
|
1540 | + if ($key[0] !== '#') { |
|
1541 | + $element_vars[$key] = $value; |
|
1542 | + $input_vars[$key] = $value; |
|
1543 | + } |
|
1544 | + } |
|
1545 | + |
|
1546 | + // field input view needs this |
|
1547 | + $input_vars['input_type'] = $input_type; |
|
1548 | + |
|
1549 | + // field views get more data |
|
1550 | + $element_vars['input_type'] = $input_type; |
|
1551 | 1551 | |
1552 | - unset($element_vars['class']); |
|
1553 | - if (isset($params['#class'])) { |
|
1554 | - $element_vars['class'] = $params['#class']; |
|
1555 | - } |
|
1556 | - unset($element_vars['help']); |
|
1557 | - if (isset($params['#help'])) { |
|
1558 | - $element_vars['help'] = $params['#help']; |
|
1559 | - } |
|
1560 | - unset($element_vars['label']); |
|
1561 | - if (isset($params['#label'])) { |
|
1562 | - $element_vars['label'] = $params['#label']; |
|
1563 | - } |
|
1552 | + unset($element_vars['class']); |
|
1553 | + if (isset($params['#class'])) { |
|
1554 | + $element_vars['class'] = $params['#class']; |
|
1555 | + } |
|
1556 | + unset($element_vars['help']); |
|
1557 | + if (isset($params['#help'])) { |
|
1558 | + $element_vars['help'] = $params['#help']; |
|
1559 | + } |
|
1560 | + unset($element_vars['label']); |
|
1561 | + if (isset($params['#label'])) { |
|
1562 | + $element_vars['label'] = $params['#label']; |
|
1563 | + } |
|
1564 | 1564 | |
1565 | - // wrap if present |
|
1566 | - $element_vars['label'] = elgg_view('elements/forms/label', $element_vars); |
|
1567 | - $element_vars['help'] = elgg_view('elements/forms/help', $element_vars); |
|
1568 | - |
|
1569 | - if ($make_special_checkbox_label) { |
|
1570 | - $input_vars['label'] = $element_vars['label']; |
|
1571 | - $input_vars['label_tag'] = 'div'; |
|
1572 | - unset($element_vars['label']); |
|
1573 | - } |
|
1574 | - $element_vars['input'] = elgg_view("elements/forms/input", $input_vars); |
|
1575 | - |
|
1576 | - return elgg_view('elements/forms/field', $element_vars); |
|
1565 | + // wrap if present |
|
1566 | + $element_vars['label'] = elgg_view('elements/forms/label', $element_vars); |
|
1567 | + $element_vars['help'] = elgg_view('elements/forms/help', $element_vars); |
|
1568 | + |
|
1569 | + if ($make_special_checkbox_label) { |
|
1570 | + $input_vars['label'] = $element_vars['label']; |
|
1571 | + $input_vars['label_tag'] = 'div'; |
|
1572 | + unset($element_vars['label']); |
|
1573 | + } |
|
1574 | + $element_vars['input'] = elgg_view("elements/forms/input", $input_vars); |
|
1575 | + |
|
1576 | + return elgg_view('elements/forms/field', $element_vars); |
|
1577 | 1577 | } |
1578 | 1578 | |
1579 | 1579 | /** |
@@ -1592,20 +1592,20 @@ discard block |
||
1592 | 1592 | */ |
1593 | 1593 | function elgg_view_tagcloud(array $options = []) { |
1594 | 1594 | |
1595 | - $type = $subtype = ''; |
|
1596 | - if (isset($options['type'])) { |
|
1597 | - $type = $options['type']; |
|
1598 | - } |
|
1599 | - if (isset($options['subtype'])) { |
|
1600 | - $subtype = $options['subtype']; |
|
1601 | - } |
|
1602 | - |
|
1603 | - $tag_data = elgg_get_tags($options); |
|
1604 | - return elgg_view("output/tagcloud", [ |
|
1605 | - 'value' => $tag_data, |
|
1606 | - 'type' => $type, |
|
1607 | - 'subtype' => $subtype, |
|
1608 | - ]); |
|
1595 | + $type = $subtype = ''; |
|
1596 | + if (isset($options['type'])) { |
|
1597 | + $type = $options['type']; |
|
1598 | + } |
|
1599 | + if (isset($options['subtype'])) { |
|
1600 | + $subtype = $options['subtype']; |
|
1601 | + } |
|
1602 | + |
|
1603 | + $tag_data = elgg_get_tags($options); |
|
1604 | + return elgg_view("output/tagcloud", [ |
|
1605 | + 'value' => $tag_data, |
|
1606 | + 'type' => $type, |
|
1607 | + 'subtype' => $subtype, |
|
1608 | + ]); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | 1611 | /** |
@@ -1622,21 +1622,21 @@ discard block |
||
1622 | 1622 | */ |
1623 | 1623 | function elgg_view_list_item($item, array $vars = []) { |
1624 | 1624 | |
1625 | - if ($item instanceof \ElggEntity) { |
|
1626 | - return elgg_view_entity($item, $vars); |
|
1627 | - } else if ($item instanceof \ElggAnnotation) { |
|
1628 | - return elgg_view_annotation($item, $vars); |
|
1629 | - } else if ($item instanceof \ElggRiverItem) { |
|
1630 | - return elgg_view_river_item($item, $vars); |
|
1631 | - } |
|
1632 | - |
|
1633 | - $view = elgg_extract('item_view', $vars); |
|
1634 | - if ($view && elgg_view_exists($view)) { |
|
1635 | - $vars['item'] = $item; |
|
1636 | - return elgg_view($view, $vars); |
|
1637 | - } |
|
1638 | - |
|
1639 | - return ''; |
|
1625 | + if ($item instanceof \ElggEntity) { |
|
1626 | + return elgg_view_entity($item, $vars); |
|
1627 | + } else if ($item instanceof \ElggAnnotation) { |
|
1628 | + return elgg_view_annotation($item, $vars); |
|
1629 | + } else if ($item instanceof \ElggRiverItem) { |
|
1630 | + return elgg_view_river_item($item, $vars); |
|
1631 | + } |
|
1632 | + |
|
1633 | + $view = elgg_extract('item_view', $vars); |
|
1634 | + if ($view && elgg_view_exists($view)) { |
|
1635 | + $vars['item'] = $item; |
|
1636 | + return elgg_view($view, $vars); |
|
1637 | + } |
|
1638 | + |
|
1639 | + return ''; |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | /** |
@@ -1652,29 +1652,29 @@ discard block |
||
1652 | 1652 | * @throws InvalidArgumentException |
1653 | 1653 | */ |
1654 | 1654 | function elgg_view_icon($name, $vars = []) { |
1655 | - if (empty($vars)) { |
|
1656 | - $vars = []; |
|
1657 | - } |
|
1655 | + if (empty($vars)) { |
|
1656 | + $vars = []; |
|
1657 | + } |
|
1658 | 1658 | |
1659 | - if (is_string($vars)) { |
|
1660 | - $vars = ['class' => $vars]; |
|
1661 | - } |
|
1659 | + if (is_string($vars)) { |
|
1660 | + $vars = ['class' => $vars]; |
|
1661 | + } |
|
1662 | 1662 | |
1663 | - if (!is_array($vars)) { |
|
1664 | - throw new \InvalidArgumentException('$vars needs to be a string or an array'); |
|
1665 | - } |
|
1663 | + if (!is_array($vars)) { |
|
1664 | + throw new \InvalidArgumentException('$vars needs to be a string or an array'); |
|
1665 | + } |
|
1666 | 1666 | |
1667 | - if (!array_key_exists('class', $vars)) { |
|
1668 | - $vars['class'] = []; |
|
1669 | - } |
|
1667 | + if (!array_key_exists('class', $vars)) { |
|
1668 | + $vars['class'] = []; |
|
1669 | + } |
|
1670 | 1670 | |
1671 | - if (!is_array($vars['class'])) { |
|
1672 | - $vars['class'] = [$vars['class']]; |
|
1673 | - } |
|
1671 | + if (!is_array($vars['class'])) { |
|
1672 | + $vars['class'] = [$vars['class']]; |
|
1673 | + } |
|
1674 | 1674 | |
1675 | - $vars['class'][] = "elgg-icon-$name"; |
|
1675 | + $vars['class'][] = "elgg-icon-$name"; |
|
1676 | 1676 | |
1677 | - return elgg_view("output/icon", $vars); |
|
1677 | + return elgg_view("output/icon", $vars); |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | /** |
@@ -1683,7 +1683,7 @@ discard block |
||
1683 | 1683 | * @return void |
1684 | 1684 | */ |
1685 | 1685 | function elgg_register_rss_link() { |
1686 | - _elgg_services()->config->set('_elgg_autofeed', true); |
|
1686 | + _elgg_services()->config->set('_elgg_autofeed', true); |
|
1687 | 1687 | } |
1688 | 1688 | |
1689 | 1689 | /** |
@@ -1692,7 +1692,7 @@ discard block |
||
1692 | 1692 | * @return void |
1693 | 1693 | */ |
1694 | 1694 | function elgg_unregister_rss_link() { |
1695 | - _elgg_services()->config->set('_elgg_autofeed', false); |
|
1695 | + _elgg_services()->config->set('_elgg_autofeed', false); |
|
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | /** |
@@ -1702,11 +1702,11 @@ discard block |
||
1702 | 1702 | * @access private |
1703 | 1703 | */ |
1704 | 1704 | function _elgg_has_rss_link() { |
1705 | - if (isset($GLOBALS['autofeed']) && is_bool($GLOBALS['autofeed'])) { |
|
1706 | - elgg_deprecated_notice('Do not set the global $autofeed. Use elgg_register_rss_link()', '2.1'); |
|
1707 | - return $GLOBALS['autofeed']; |
|
1708 | - } |
|
1709 | - return (bool) _elgg_services()->config->getVolatile('_elgg_autofeed'); |
|
1705 | + if (isset($GLOBALS['autofeed']) && is_bool($GLOBALS['autofeed'])) { |
|
1706 | + elgg_deprecated_notice('Do not set the global $autofeed. Use elgg_register_rss_link()', '2.1'); |
|
1707 | + return $GLOBALS['autofeed']; |
|
1708 | + } |
|
1709 | + return (bool) _elgg_services()->config->getVolatile('_elgg_autofeed'); |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | 1712 | /** |
@@ -1727,7 +1727,7 @@ discard block |
||
1727 | 1727 | * @access private |
1728 | 1728 | */ |
1729 | 1729 | function autoregister_views($view_base, $folder, $ignored, $viewtype) { |
1730 | - return _elgg_services()->views->autoregisterViews($view_base, $folder, $viewtype); |
|
1730 | + return _elgg_services()->views->autoregisterViews($view_base, $folder, $viewtype); |
|
1731 | 1731 | } |
1732 | 1732 | |
1733 | 1733 | /** |
@@ -1742,21 +1742,21 @@ discard block |
||
1742 | 1742 | * @access private |
1743 | 1743 | */ |
1744 | 1744 | function _elgg_views_minify($hook, $type, $content, $params) { |
1745 | - if (preg_match('~[\.-]min\.~', $params['view'])) { |
|
1746 | - // bypass minification |
|
1747 | - return; |
|
1748 | - } |
|
1749 | - |
|
1750 | - if ($type == 'js') { |
|
1751 | - if (elgg_get_config('simplecache_minify_js')) { |
|
1752 | - return JSMin::minify($content); |
|
1753 | - } |
|
1754 | - } elseif ($type == 'css') { |
|
1755 | - if (elgg_get_config('simplecache_minify_css')) { |
|
1756 | - $cssmin = new CSSmin(); |
|
1757 | - return $cssmin->run($content); |
|
1758 | - } |
|
1759 | - } |
|
1745 | + if (preg_match('~[\.-]min\.~', $params['view'])) { |
|
1746 | + // bypass minification |
|
1747 | + return; |
|
1748 | + } |
|
1749 | + |
|
1750 | + if ($type == 'js') { |
|
1751 | + if (elgg_get_config('simplecache_minify_js')) { |
|
1752 | + return JSMin::minify($content); |
|
1753 | + } |
|
1754 | + } elseif ($type == 'css') { |
|
1755 | + if (elgg_get_config('simplecache_minify_css')) { |
|
1756 | + $cssmin = new CSSmin(); |
|
1757 | + return $cssmin->run($content); |
|
1758 | + } |
|
1759 | + } |
|
1760 | 1760 | } |
1761 | 1761 | |
1762 | 1762 | /** |
@@ -1771,14 +1771,14 @@ discard block |
||
1771 | 1771 | * @access private |
1772 | 1772 | */ |
1773 | 1773 | function _elgg_views_preprocess_css($hook, $type, $content, $params) { |
1774 | - $options = [ |
|
1775 | - 'minify' => false, // minify handled by _elgg_views_minify |
|
1776 | - 'formatter' => 'single-line', // shows lowest byte size |
|
1777 | - 'versioning' => false, // versioning done by Elgg |
|
1778 | - 'rewrite_import_urls' => false, |
|
1779 | - ]; |
|
1774 | + $options = [ |
|
1775 | + 'minify' => false, // minify handled by _elgg_views_minify |
|
1776 | + 'formatter' => 'single-line', // shows lowest byte size |
|
1777 | + 'versioning' => false, // versioning done by Elgg |
|
1778 | + 'rewrite_import_urls' => false, |
|
1779 | + ]; |
|
1780 | 1780 | |
1781 | - return csscrush_string($content, $options); |
|
1781 | + return csscrush_string($content, $options); |
|
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | /** |
@@ -1793,8 +1793,8 @@ discard block |
||
1793 | 1793 | * @access private |
1794 | 1794 | */ |
1795 | 1795 | function _elgg_views_amd($hook, $type, $content, $params) { |
1796 | - $filter = new \Elgg\Amd\ViewFilter(); |
|
1797 | - return $filter->filter($params['view'], $content); |
|
1796 | + $filter = new \Elgg\Amd\ViewFilter(); |
|
1797 | + return $filter->filter($params['view'], $content); |
|
1798 | 1798 | } |
1799 | 1799 | |
1800 | 1800 | /** |
@@ -1803,7 +1803,7 @@ discard block |
||
1803 | 1803 | * @access private |
1804 | 1804 | */ |
1805 | 1805 | function _elgg_views_send_header_x_frame_options() { |
1806 | - header('X-Frame-Options: SAMEORIGIN'); |
|
1806 | + header('X-Frame-Options: SAMEORIGIN'); |
|
1807 | 1807 | } |
1808 | 1808 | |
1809 | 1809 | /** |
@@ -1834,27 +1834,27 @@ discard block |
||
1834 | 1834 | * @access private |
1835 | 1835 | */ |
1836 | 1836 | function _elgg_view_may_be_altered($view, $path) { |
1837 | - $views = _elgg_services()->views; |
|
1837 | + $views = _elgg_services()->views; |
|
1838 | 1838 | |
1839 | - if ($views->viewIsExtended($view) || $views->viewHasHookHandlers($view)) { |
|
1840 | - return true; |
|
1841 | - } |
|
1839 | + if ($views->viewIsExtended($view) || $views->viewHasHookHandlers($view)) { |
|
1840 | + return true; |
|
1841 | + } |
|
1842 | 1842 | |
1843 | - $viewtype = elgg_get_viewtype(); |
|
1843 | + $viewtype = elgg_get_viewtype(); |
|
1844 | 1844 | |
1845 | - // check location |
|
1846 | - if (0 === strpos($path, '/') || preg_match('~^([A-Za-z]\:)?\\\\~', $path)) { |
|
1847 | - // absolute path |
|
1848 | - $expected_path = $path; |
|
1849 | - } else { |
|
1850 | - // relative path |
|
1851 | - $root = dirname(dirname(__DIR__)); |
|
1852 | - $expected_path = "$root/views/$viewtype/" . ltrim($path, '/\\'); |
|
1853 | - } |
|
1845 | + // check location |
|
1846 | + if (0 === strpos($path, '/') || preg_match('~^([A-Za-z]\:)?\\\\~', $path)) { |
|
1847 | + // absolute path |
|
1848 | + $expected_path = $path; |
|
1849 | + } else { |
|
1850 | + // relative path |
|
1851 | + $root = dirname(dirname(__DIR__)); |
|
1852 | + $expected_path = "$root/views/$viewtype/" . ltrim($path, '/\\'); |
|
1853 | + } |
|
1854 | 1854 | |
1855 | - $view_path = $views->findViewFile($view, $viewtype); |
|
1855 | + $view_path = $views->findViewFile($view, $viewtype); |
|
1856 | 1856 | |
1857 | - return realpath($view_path) !== realpath($expected_path); |
|
1857 | + return realpath($view_path) !== realpath($expected_path); |
|
1858 | 1858 | } |
1859 | 1859 | |
1860 | 1860 | /** |
@@ -1866,107 +1866,107 @@ discard block |
||
1866 | 1866 | * @elgg_event_handler boot system |
1867 | 1867 | */ |
1868 | 1868 | function elgg_views_boot() { |
1869 | - if (!elgg_get_config('system_cache_loaded')) { |
|
1870 | - // Core view files in /views |
|
1871 | - _elgg_services()->views->registerPluginViews(realpath(__DIR__ . '/../../')); |
|
1869 | + if (!elgg_get_config('system_cache_loaded')) { |
|
1870 | + // Core view files in /views |
|
1871 | + _elgg_services()->views->registerPluginViews(realpath(__DIR__ . '/../../')); |
|
1872 | 1872 | |
1873 | - // Core view definitions in /engine/views.php |
|
1874 | - $file = dirname(__DIR__) . '/views.php'; |
|
1875 | - if (is_file($file)) { |
|
1876 | - $spec = Includer::includeFile($file); |
|
1877 | - if (is_array($spec)) { |
|
1878 | - _elgg_services()->views->mergeViewsSpec($spec); |
|
1879 | - } |
|
1880 | - } |
|
1881 | - } |
|
1873 | + // Core view definitions in /engine/views.php |
|
1874 | + $file = dirname(__DIR__) . '/views.php'; |
|
1875 | + if (is_file($file)) { |
|
1876 | + $spec = Includer::includeFile($file); |
|
1877 | + if (is_array($spec)) { |
|
1878 | + _elgg_services()->views->mergeViewsSpec($spec); |
|
1879 | + } |
|
1880 | + } |
|
1881 | + } |
|
1882 | 1882 | |
1883 | - // on every page |
|
1883 | + // on every page |
|
1884 | 1884 | |
1885 | - // jQuery and UI must come before require. See #9024 |
|
1886 | - elgg_register_js('jquery', elgg_get_simplecache_url('jquery.js'), 'head'); |
|
1887 | - elgg_load_js('jquery'); |
|
1885 | + // jQuery and UI must come before require. See #9024 |
|
1886 | + elgg_register_js('jquery', elgg_get_simplecache_url('jquery.js'), 'head'); |
|
1887 | + elgg_load_js('jquery'); |
|
1888 | 1888 | |
1889 | - elgg_register_js('jquery-ui', elgg_get_simplecache_url('jquery-ui.js'), 'head'); |
|
1890 | - elgg_load_js('jquery-ui'); |
|
1889 | + elgg_register_js('jquery-ui', elgg_get_simplecache_url('jquery-ui.js'), 'head'); |
|
1890 | + elgg_load_js('jquery-ui'); |
|
1891 | 1891 | |
1892 | - elgg_register_js('elgg.require_config', elgg_get_simplecache_url('elgg/require_config.js'), 'head'); |
|
1893 | - elgg_load_js('elgg.require_config'); |
|
1892 | + elgg_register_js('elgg.require_config', elgg_get_simplecache_url('elgg/require_config.js'), 'head'); |
|
1893 | + elgg_load_js('elgg.require_config'); |
|
1894 | 1894 | |
1895 | - elgg_register_js('require', elgg_get_simplecache_url('require.js'), 'head'); |
|
1896 | - elgg_load_js('require'); |
|
1895 | + elgg_register_js('require', elgg_get_simplecache_url('require.js'), 'head'); |
|
1896 | + elgg_load_js('require'); |
|
1897 | 1897 | |
1898 | - elgg_register_js('elgg', elgg_get_simplecache_url('elgg.js'), 'head'); |
|
1899 | - elgg_load_js('elgg'); |
|
1898 | + elgg_register_js('elgg', elgg_get_simplecache_url('elgg.js'), 'head'); |
|
1899 | + elgg_load_js('elgg'); |
|
1900 | 1900 | |
1901 | - elgg_register_css('font-awesome', elgg_get_simplecache_url('font-awesome/css/font-awesome.css')); |
|
1902 | - elgg_load_css('font-awesome'); |
|
1901 | + elgg_register_css('font-awesome', elgg_get_simplecache_url('font-awesome/css/font-awesome.css')); |
|
1902 | + elgg_load_css('font-awesome'); |
|
1903 | 1903 | |
1904 | - elgg_register_css('elgg', elgg_get_simplecache_url('elgg.css')); |
|
1905 | - elgg_load_css('elgg'); |
|
1904 | + elgg_register_css('elgg', elgg_get_simplecache_url('elgg.css')); |
|
1905 | + elgg_load_css('elgg'); |
|
1906 | 1906 | |
1907 | - elgg_register_simplecache_view('elgg/init.js'); |
|
1907 | + elgg_register_simplecache_view('elgg/init.js'); |
|
1908 | 1908 | |
1909 | - elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
1909 | + elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
1910 | 1910 | |
1911 | - elgg_define_js('jquery.ui.autocomplete.html', [ |
|
1912 | - 'deps' => ['jquery-ui'], |
|
1913 | - ]); |
|
1911 | + elgg_define_js('jquery.ui.autocomplete.html', [ |
|
1912 | + 'deps' => ['jquery-ui'], |
|
1913 | + ]); |
|
1914 | 1914 | |
1915 | - elgg_register_js('elgg.avatar_cropper', elgg_get_simplecache_url('elgg/ui.avatar_cropper.js')); |
|
1915 | + elgg_register_js('elgg.avatar_cropper', elgg_get_simplecache_url('elgg/ui.avatar_cropper.js')); |
|
1916 | 1916 | |
1917 | - // @deprecated 2.2 |
|
1918 | - elgg_register_js('elgg.ui.river', elgg_get_simplecache_url('elgg/ui.river.js')); |
|
1917 | + // @deprecated 2.2 |
|
1918 | + elgg_register_js('elgg.ui.river', elgg_get_simplecache_url('elgg/ui.river.js')); |
|
1919 | 1919 | |
1920 | - elgg_register_js('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.js')); |
|
1921 | - elgg_register_css('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.css')); |
|
1920 | + elgg_register_js('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.js')); |
|
1921 | + elgg_register_css('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.css')); |
|
1922 | 1922 | |
1923 | - elgg_register_ajax_view('languages.js'); |
|
1923 | + elgg_register_ajax_view('languages.js'); |
|
1924 | 1924 | |
1925 | - // pre-process CSS regardless of simplecache |
|
1926 | - elgg_register_plugin_hook_handler('cache:generate', 'css', '_elgg_views_preprocess_css'); |
|
1927 | - elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_preprocess_css'); |
|
1925 | + // pre-process CSS regardless of simplecache |
|
1926 | + elgg_register_plugin_hook_handler('cache:generate', 'css', '_elgg_views_preprocess_css'); |
|
1927 | + elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_preprocess_css'); |
|
1928 | 1928 | |
1929 | - elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd'); |
|
1930 | - elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify'); |
|
1931 | - elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify'); |
|
1929 | + elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd'); |
|
1930 | + elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify'); |
|
1931 | + elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify'); |
|
1932 | 1932 | |
1933 | - elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options'); |
|
1933 | + elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options'); |
|
1934 | 1934 | |
1935 | - // registered with high priority for BC |
|
1936 | - // prior to 2.2 registration used to take place in _elgg_views_prepare_head() before the hook was triggered |
|
1937 | - elgg_register_plugin_hook_handler('head', 'page', '_elgg_views_prepare_favicon_links', 1); |
|
1935 | + // registered with high priority for BC |
|
1936 | + // prior to 2.2 registration used to take place in _elgg_views_prepare_head() before the hook was triggered |
|
1937 | + elgg_register_plugin_hook_handler('head', 'page', '_elgg_views_prepare_favicon_links', 1); |
|
1938 | 1938 | |
1939 | - // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier |
|
1940 | - $view_path = _elgg_services()->views->view_path; |
|
1941 | - $viewtype_dirs = scandir($view_path); |
|
1942 | - foreach ($viewtype_dirs as $viewtype) { |
|
1943 | - if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) { |
|
1944 | - elgg_register_viewtype($viewtype); |
|
1945 | - } |
|
1946 | - } |
|
1947 | - |
|
1948 | - // set default icon sizes - can be overridden in settings.php or with plugin |
|
1949 | - if (!isset($CONFIG->icon_sizes)) { |
|
1950 | - $icon_sizes = [ |
|
1951 | - 'topbar' => ['w' => 16, 'h' => 16, 'square' => true, 'upscale' => true], |
|
1952 | - 'tiny' => ['w' => 25, 'h' => 25, 'square' => true, 'upscale' => true], |
|
1953 | - 'small' => ['w' => 40, 'h' => 40, 'square' => true, 'upscale' => true], |
|
1954 | - 'medium' => ['w' => 100, 'h' => 100, 'square' => true, 'upscale' => true], |
|
1955 | - 'large' => ['w' => 200, 'h' => 200, 'square' => false, 'upscale' => false], |
|
1956 | - 'master' => ['w' => 550, 'h' => 550, 'square' => false, 'upscale' => false], |
|
1957 | - ]; |
|
1958 | - elgg_set_config('icon_sizes', $icon_sizes); |
|
1959 | - } |
|
1960 | - |
|
1961 | - // Patches and features that were included between major releases |
|
1962 | - // sometimes require additional styling, but adding them to core CSS files |
|
1963 | - // is not always feasible, because those can be replaced by themes. |
|
1964 | - // @todo Remove in 3.0 |
|
1965 | - elgg_extend_view('elgg.css', 'elements/pathces.css'); |
|
1966 | - elgg_extend_view('admin.css', 'elements/pathces.css'); |
|
1967 | - |
|
1968 | - // Configure lightbox |
|
1969 | - elgg_register_plugin_hook_handler('elgg.data', 'site', '_elgg_set_lightbox_config'); |
|
1939 | + // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier |
|
1940 | + $view_path = _elgg_services()->views->view_path; |
|
1941 | + $viewtype_dirs = scandir($view_path); |
|
1942 | + foreach ($viewtype_dirs as $viewtype) { |
|
1943 | + if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) { |
|
1944 | + elgg_register_viewtype($viewtype); |
|
1945 | + } |
|
1946 | + } |
|
1947 | + |
|
1948 | + // set default icon sizes - can be overridden in settings.php or with plugin |
|
1949 | + if (!isset($CONFIG->icon_sizes)) { |
|
1950 | + $icon_sizes = [ |
|
1951 | + 'topbar' => ['w' => 16, 'h' => 16, 'square' => true, 'upscale' => true], |
|
1952 | + 'tiny' => ['w' => 25, 'h' => 25, 'square' => true, 'upscale' => true], |
|
1953 | + 'small' => ['w' => 40, 'h' => 40, 'square' => true, 'upscale' => true], |
|
1954 | + 'medium' => ['w' => 100, 'h' => 100, 'square' => true, 'upscale' => true], |
|
1955 | + 'large' => ['w' => 200, 'h' => 200, 'square' => false, 'upscale' => false], |
|
1956 | + 'master' => ['w' => 550, 'h' => 550, 'square' => false, 'upscale' => false], |
|
1957 | + ]; |
|
1958 | + elgg_set_config('icon_sizes', $icon_sizes); |
|
1959 | + } |
|
1960 | + |
|
1961 | + // Patches and features that were included between major releases |
|
1962 | + // sometimes require additional styling, but adding them to core CSS files |
|
1963 | + // is not always feasible, because those can be replaced by themes. |
|
1964 | + // @todo Remove in 3.0 |
|
1965 | + elgg_extend_view('elgg.css', 'elements/pathces.css'); |
|
1966 | + elgg_extend_view('admin.css', 'elements/pathces.css'); |
|
1967 | + |
|
1968 | + // Configure lightbox |
|
1969 | + elgg_register_plugin_hook_handler('elgg.data', 'site', '_elgg_set_lightbox_config'); |
|
1970 | 1970 | } |
1971 | 1971 | |
1972 | 1972 | /** |
@@ -1978,21 +1978,21 @@ discard block |
||
1978 | 1978 | * @access private |
1979 | 1979 | */ |
1980 | 1980 | function _elgg_get_js_site_data() { |
1981 | - $language = elgg_get_config('language'); |
|
1982 | - if (!$language) { |
|
1983 | - $language = 'en'; |
|
1984 | - } |
|
1985 | - |
|
1986 | - return [ |
|
1987 | - 'elgg.data' => (object) elgg_trigger_plugin_hook('elgg.data', 'site', null, []), |
|
1988 | - 'elgg.version' => elgg_get_version(), |
|
1989 | - 'elgg.release' => elgg_get_version(true), |
|
1990 | - 'elgg.config.wwwroot' => elgg_get_site_url(), |
|
1991 | - |
|
1992 | - // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3) |
|
1993 | - 'elgg.security.interval' => (int) _elgg_services()->actions->getActionTokenTimeout() * 333, |
|
1994 | - 'elgg.config.language' => $language, |
|
1995 | - ]; |
|
1981 | + $language = elgg_get_config('language'); |
|
1982 | + if (!$language) { |
|
1983 | + $language = 'en'; |
|
1984 | + } |
|
1985 | + |
|
1986 | + return [ |
|
1987 | + 'elgg.data' => (object) elgg_trigger_plugin_hook('elgg.data', 'site', null, []), |
|
1988 | + 'elgg.version' => elgg_get_version(), |
|
1989 | + 'elgg.release' => elgg_get_version(true), |
|
1990 | + 'elgg.config.wwwroot' => elgg_get_site_url(), |
|
1991 | + |
|
1992 | + // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3) |
|
1993 | + 'elgg.security.interval' => (int) _elgg_services()->actions->getActionTokenTimeout() * 333, |
|
1994 | + 'elgg.config.language' => $language, |
|
1995 | + ]; |
|
1996 | 1996 | } |
1997 | 1997 | |
1998 | 1998 | /** |
@@ -2002,48 +2002,48 @@ discard block |
||
2002 | 2002 | * @access private |
2003 | 2003 | */ |
2004 | 2004 | function _elgg_get_js_page_data() { |
2005 | - $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []); |
|
2006 | - if (!is_array($data)) { |
|
2007 | - elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR'); |
|
2008 | - $data = []; |
|
2009 | - } |
|
2010 | - |
|
2011 | - $elgg = [ |
|
2012 | - 'config' => [ |
|
2013 | - 'lastcache' => (int) elgg_get_config('lastcache'), |
|
2014 | - 'viewtype' => elgg_get_viewtype(), |
|
2015 | - 'simplecache_enabled' => (int) elgg_is_simplecache_enabled(), |
|
2016 | - ], |
|
2017 | - 'security' => [ |
|
2018 | - 'token' => [ |
|
2019 | - '__elgg_ts' => $ts = time(), |
|
2020 | - '__elgg_token' => generate_action_token($ts), |
|
2021 | - ], |
|
2022 | - ], |
|
2023 | - 'session' => [ |
|
2024 | - 'user' => null, |
|
2025 | - 'token' => _elgg_services()->session->get('__elgg_session'), |
|
2026 | - ], |
|
2027 | - '_data' => (object) $data, |
|
2028 | - ]; |
|
2029 | - |
|
2030 | - if (elgg_get_config('elgg_load_sync_code')) { |
|
2031 | - $elgg['config']['load_sync_code'] = true; |
|
2032 | - } |
|
2033 | - |
|
2034 | - $page_owner = elgg_get_page_owner_entity(); |
|
2035 | - if ($page_owner instanceof ElggEntity) { |
|
2036 | - $elgg['page_owner'] = $page_owner->toObject(); |
|
2037 | - } |
|
2038 | - |
|
2039 | - $user = elgg_get_logged_in_user_entity(); |
|
2040 | - if ($user instanceof ElggUser) { |
|
2041 | - $user_object = $user->toObject(); |
|
2042 | - $user_object->admin = $user->isAdmin(); |
|
2043 | - $elgg['session']['user'] = $user_object; |
|
2044 | - } |
|
2045 | - |
|
2046 | - return $elgg; |
|
2005 | + $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []); |
|
2006 | + if (!is_array($data)) { |
|
2007 | + elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR'); |
|
2008 | + $data = []; |
|
2009 | + } |
|
2010 | + |
|
2011 | + $elgg = [ |
|
2012 | + 'config' => [ |
|
2013 | + 'lastcache' => (int) elgg_get_config('lastcache'), |
|
2014 | + 'viewtype' => elgg_get_viewtype(), |
|
2015 | + 'simplecache_enabled' => (int) elgg_is_simplecache_enabled(), |
|
2016 | + ], |
|
2017 | + 'security' => [ |
|
2018 | + 'token' => [ |
|
2019 | + '__elgg_ts' => $ts = time(), |
|
2020 | + '__elgg_token' => generate_action_token($ts), |
|
2021 | + ], |
|
2022 | + ], |
|
2023 | + 'session' => [ |
|
2024 | + 'user' => null, |
|
2025 | + 'token' => _elgg_services()->session->get('__elgg_session'), |
|
2026 | + ], |
|
2027 | + '_data' => (object) $data, |
|
2028 | + ]; |
|
2029 | + |
|
2030 | + if (elgg_get_config('elgg_load_sync_code')) { |
|
2031 | + $elgg['config']['load_sync_code'] = true; |
|
2032 | + } |
|
2033 | + |
|
2034 | + $page_owner = elgg_get_page_owner_entity(); |
|
2035 | + if ($page_owner instanceof ElggEntity) { |
|
2036 | + $elgg['page_owner'] = $page_owner->toObject(); |
|
2037 | + } |
|
2038 | + |
|
2039 | + $user = elgg_get_logged_in_user_entity(); |
|
2040 | + if ($user instanceof ElggUser) { |
|
2041 | + $user_object = $user->toObject(); |
|
2042 | + $user_object->admin = $user->isAdmin(); |
|
2043 | + $elgg['session']['user'] = $user_object; |
|
2044 | + } |
|
2045 | + |
|
2046 | + return $elgg; |
|
2047 | 2047 | } |
2048 | 2048 | |
2049 | 2049 | /** |
@@ -2058,18 +2058,18 @@ discard block |
||
2058 | 2058 | * @access private |
2059 | 2059 | */ |
2060 | 2060 | function _elgg_view_under_viewtype($view, $vars, $viewtype) { |
2061 | - if ($viewtype) { |
|
2062 | - $old = elgg_get_viewtype(); |
|
2063 | - elgg_set_viewtype($viewtype); |
|
2064 | - } |
|
2061 | + if ($viewtype) { |
|
2062 | + $old = elgg_get_viewtype(); |
|
2063 | + elgg_set_viewtype($viewtype); |
|
2064 | + } |
|
2065 | 2065 | |
2066 | - $ret = elgg_view($view, $vars); |
|
2066 | + $ret = elgg_view($view, $vars); |
|
2067 | 2067 | |
2068 | - if ($viewtype) { |
|
2069 | - elgg_set_viewtype($old); |
|
2070 | - } |
|
2068 | + if ($viewtype) { |
|
2069 | + elgg_set_viewtype($old); |
|
2070 | + } |
|
2071 | 2071 | |
2072 | - return $ret; |
|
2072 | + return $ret; |
|
2073 | 2073 | } |
2074 | 2074 | |
2075 | 2075 | /** |
@@ -2084,17 +2084,17 @@ discard block |
||
2084 | 2084 | */ |
2085 | 2085 | function _elgg_set_lightbox_config($hook, $type, $return, $params) { |
2086 | 2086 | |
2087 | - $return['lightbox'] = [ |
|
2088 | - 'current' => elgg_echo('js:lightbox:current', ['{current}', '{total}']), |
|
2089 | - 'previous' => elgg_view_icon('caret-left'), |
|
2090 | - 'next' => elgg_view_icon('caret-right'), |
|
2091 | - 'close' => elgg_view_icon('times'), |
|
2092 | - 'opacity' => 0.5, |
|
2093 | - 'maxWidth' => '990px', |
|
2094 | - 'maxHeight' => '990px', |
|
2095 | - 'initialWidth' => '300px', |
|
2096 | - 'initialHeight' => '300px', |
|
2097 | - ]; |
|
2098 | - |
|
2099 | - return $return; |
|
2087 | + $return['lightbox'] = [ |
|
2088 | + 'current' => elgg_echo('js:lightbox:current', ['{current}', '{total}']), |
|
2089 | + 'previous' => elgg_view_icon('caret-left'), |
|
2090 | + 'next' => elgg_view_icon('caret-right'), |
|
2091 | + 'close' => elgg_view_icon('times'), |
|
2092 | + 'opacity' => 0.5, |
|
2093 | + 'maxWidth' => '990px', |
|
2094 | + 'maxHeight' => '990px', |
|
2095 | + 'initialWidth' => '300px', |
|
2096 | + 'initialHeight' => '300px', |
|
2097 | + ]; |
|
2098 | + |
|
2099 | + return $return; |
|
2100 | 2100 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @since 1.9 |
16 | 16 | */ |
17 | 17 | function elgg_get_session() { |
18 | - return _elgg_services()->session; |
|
18 | + return _elgg_services()->session; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @return \ElggUser|null |
25 | 25 | */ |
26 | 26 | function elgg_get_logged_in_user_entity() { |
27 | - return _elgg_services()->session->getLoggedInUser(); |
|
27 | + return _elgg_services()->session->getLoggedInUser(); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return int |
35 | 35 | */ |
36 | 36 | function elgg_get_logged_in_user_guid() { |
37 | - return _elgg_services()->session->getLoggedInUserGuid(); |
|
37 | + return _elgg_services()->session->getLoggedInUserGuid(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return bool |
44 | 44 | */ |
45 | 45 | function elgg_is_logged_in() { |
46 | - return _elgg_services()->session->isLoggedIn(); |
|
46 | + return _elgg_services()->session->isLoggedIn(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @return bool |
53 | 53 | */ |
54 | 54 | function elgg_is_admin_logged_in() { |
55 | - return _elgg_services()->session->isAdminLoggedIn(); |
|
55 | + return _elgg_services()->session->isAdminLoggedIn(); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -67,28 +67,28 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function elgg_is_admin_user($user_guid) { |
69 | 69 | |
70 | - $user_guid = (int) $user_guid; |
|
70 | + $user_guid = (int) $user_guid; |
|
71 | 71 | |
72 | - $current_user = elgg_get_logged_in_user_entity(); |
|
73 | - if ($current_user && $current_user->guid == $user_guid) { |
|
74 | - return $current_user->isAdmin(); |
|
75 | - } |
|
72 | + $current_user = elgg_get_logged_in_user_entity(); |
|
73 | + if ($current_user && $current_user->guid == $user_guid) { |
|
74 | + return $current_user->isAdmin(); |
|
75 | + } |
|
76 | 76 | |
77 | - // cannot use magic metadata here because of recursion |
|
78 | - $dbprefix = elgg_get_config('dbprefix'); |
|
79 | - $query = "SELECT 1 FROM {$dbprefix}users_entity as e |
|
77 | + // cannot use magic metadata here because of recursion |
|
78 | + $dbprefix = elgg_get_config('dbprefix'); |
|
79 | + $query = "SELECT 1 FROM {$dbprefix}users_entity as e |
|
80 | 80 | WHERE ( |
81 | 81 | e.guid = {$user_guid} |
82 | 82 | AND e.admin = 'yes' |
83 | 83 | )"; |
84 | 84 | |
85 | - // normalizing the results from get_data() |
|
86 | - // See #1242 |
|
87 | - $info = get_data($query); |
|
88 | - if (!((is_array($info) && count($info) < 1) || $info === false)) { |
|
89 | - return true; |
|
90 | - } |
|
91 | - return false; |
|
85 | + // normalizing the results from get_data() |
|
86 | + // See #1242 |
|
87 | + $info = get_data($query); |
|
88 | + if (!((is_array($info) && count($info) < 1) || $info === false)) { |
|
89 | + return true; |
|
90 | + } |
|
91 | + return false; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * @access private |
108 | 108 | */ |
109 | 109 | function elgg_authenticate($username, $password) { |
110 | - $pam = new \ElggPAM('user'); |
|
111 | - $credentials = ['username' => $username, 'password' => $password]; |
|
112 | - $result = $pam->authenticate($credentials); |
|
113 | - if (!$result) { |
|
114 | - return $pam->getFailureMessage(); |
|
115 | - } |
|
116 | - return true; |
|
110 | + $pam = new \ElggPAM('user'); |
|
111 | + $credentials = ['username' => $username, 'password' => $password]; |
|
112 | + $result = $pam->authenticate($credentials); |
|
113 | + if (!$result) { |
|
114 | + return $pam->getFailureMessage(); |
|
115 | + } |
|
116 | + return true; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | */ |
131 | 131 | function pam_auth_userpass(array $credentials = []) { |
132 | 132 | |
133 | - if (!isset($credentials['username']) || !isset($credentials['password'])) { |
|
134 | - return false; |
|
135 | - } |
|
133 | + if (!isset($credentials['username']) || !isset($credentials['password'])) { |
|
134 | + return false; |
|
135 | + } |
|
136 | 136 | |
137 | - $user = get_user_by_username($credentials['username']); |
|
138 | - if (!$user) { |
|
139 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:UsernameFailure')); |
|
140 | - } |
|
137 | + $user = get_user_by_username($credentials['username']); |
|
138 | + if (!$user) { |
|
139 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:UsernameFailure')); |
|
140 | + } |
|
141 | 141 | |
142 | - $password_svc = _elgg_services()->passwords; |
|
143 | - $password = $credentials['password']; |
|
144 | - $hash = $user->password_hash; |
|
142 | + $password_svc = _elgg_services()->passwords; |
|
143 | + $password = $credentials['password']; |
|
144 | + $hash = $user->password_hash; |
|
145 | 145 | |
146 | - if (check_rate_limit_exceeded($user->guid)) { |
|
147 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:AccountLocked')); |
|
148 | - } |
|
146 | + if (check_rate_limit_exceeded($user->guid)) { |
|
147 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:AccountLocked')); |
|
148 | + } |
|
149 | 149 | |
150 | - if (!$password_svc->verify($password, $hash)) { |
|
151 | - log_login_failure($user->guid); |
|
152 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:PasswordFailure')); |
|
153 | - } |
|
150 | + if (!$password_svc->verify($password, $hash)) { |
|
151 | + log_login_failure($user->guid); |
|
152 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:PasswordFailure')); |
|
153 | + } |
|
154 | 154 | |
155 | - if ($password_svc->needsRehash($hash)) { |
|
156 | - $password_svc->forcePasswordReset($user, $password); |
|
157 | - } |
|
155 | + if ($password_svc->needsRehash($hash)) { |
|
156 | + $password_svc->forcePasswordReset($user, $password); |
|
157 | + } |
|
158 | 158 | |
159 | - return true; |
|
159 | + return true; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,19 +167,19 @@ discard block |
||
167 | 167 | * @return bool |
168 | 168 | */ |
169 | 169 | function log_login_failure($user_guid) { |
170 | - $user_guid = (int) $user_guid; |
|
171 | - $user = get_entity($user_guid); |
|
170 | + $user_guid = (int) $user_guid; |
|
171 | + $user = get_entity($user_guid); |
|
172 | 172 | |
173 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
174 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
175 | - $fails++; |
|
173 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
174 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
175 | + $fails++; |
|
176 | 176 | |
177 | - $user->setPrivateSetting("login_failures", $fails); |
|
178 | - $user->setPrivateSetting("login_failure_$fails", time()); |
|
179 | - return true; |
|
180 | - } |
|
177 | + $user->setPrivateSetting("login_failures", $fails); |
|
178 | + $user->setPrivateSetting("login_failure_$fails", time()); |
|
179 | + return true; |
|
180 | + } |
|
181 | 181 | |
182 | - return false; |
|
182 | + return false; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -190,27 +190,27 @@ discard block |
||
190 | 190 | * @return bool true on success (success = user has no logged failed attempts) |
191 | 191 | */ |
192 | 192 | function reset_login_failure_count($user_guid) { |
193 | - $user_guid = (int) $user_guid; |
|
194 | - $user = get_entity($user_guid); |
|
193 | + $user_guid = (int) $user_guid; |
|
194 | + $user = get_entity($user_guid); |
|
195 | 195 | |
196 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
197 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
196 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
197 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
198 | 198 | |
199 | - if ($fails) { |
|
200 | - for ($n = 1; $n <= $fails; $n++) { |
|
201 | - $user->removePrivateSetting("login_failure_$n"); |
|
202 | - } |
|
199 | + if ($fails) { |
|
200 | + for ($n = 1; $n <= $fails; $n++) { |
|
201 | + $user->removePrivateSetting("login_failure_$n"); |
|
202 | + } |
|
203 | 203 | |
204 | - $user->removePrivateSetting("login_failures"); |
|
204 | + $user->removePrivateSetting("login_failures"); |
|
205 | 205 | |
206 | - return true; |
|
207 | - } |
|
206 | + return true; |
|
207 | + } |
|
208 | 208 | |
209 | - // nothing to reset |
|
210 | - return true; |
|
211 | - } |
|
209 | + // nothing to reset |
|
210 | + return true; |
|
211 | + } |
|
212 | 212 | |
213 | - return false; |
|
213 | + return false; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -221,31 +221,31 @@ discard block |
||
221 | 221 | * @return bool on exceeded limit. |
222 | 222 | */ |
223 | 223 | function check_rate_limit_exceeded($user_guid) { |
224 | - // 5 failures in 5 minutes causes temporary block on logins |
|
225 | - $limit = 5; |
|
226 | - $user_guid = (int) $user_guid; |
|
227 | - $user = get_entity($user_guid); |
|
228 | - |
|
229 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
230 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
231 | - if ($fails >= $limit) { |
|
232 | - $cnt = 0; |
|
233 | - $time = time(); |
|
234 | - for ($n = $fails; $n > 0; $n--) { |
|
235 | - $f = $user->getPrivateSetting("login_failure_$n"); |
|
236 | - if ($f > $time - (60 * 5)) { |
|
237 | - $cnt++; |
|
238 | - } |
|
239 | - |
|
240 | - if ($cnt == $limit) { |
|
241 | - // Limit reached |
|
242 | - return true; |
|
243 | - } |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - return false; |
|
224 | + // 5 failures in 5 minutes causes temporary block on logins |
|
225 | + $limit = 5; |
|
226 | + $user_guid = (int) $user_guid; |
|
227 | + $user = get_entity($user_guid); |
|
228 | + |
|
229 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
230 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
231 | + if ($fails >= $limit) { |
|
232 | + $cnt = 0; |
|
233 | + $time = time(); |
|
234 | + for ($n = $fails; $n > 0; $n--) { |
|
235 | + $f = $user->getPrivateSetting("login_failure_$n"); |
|
236 | + if ($f > $time - (60 * 5)) { |
|
237 | + $cnt++; |
|
238 | + } |
|
239 | + |
|
240 | + if ($cnt == $limit) { |
|
241 | + // Limit reached |
|
242 | + return true; |
|
243 | + } |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + return false; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -258,11 +258,11 @@ discard block |
||
258 | 258 | * @since 1.9 |
259 | 259 | */ |
260 | 260 | function elgg_set_cookie(\ElggCookie $cookie) { |
261 | - if (elgg_trigger_event('init:cookie', $cookie->name, $cookie)) { |
|
262 | - return setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, |
|
263 | - $cookie->domain, $cookie->secure, $cookie->httpOnly); |
|
264 | - } |
|
265 | - return false; |
|
261 | + if (elgg_trigger_event('init:cookie', $cookie->name, $cookie)) { |
|
262 | + return setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, |
|
263 | + $cookie->domain, $cookie->secure, $cookie->httpOnly); |
|
264 | + } |
|
265 | + return false; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -278,35 +278,35 @@ discard block |
||
278 | 278 | * @throws LoginException |
279 | 279 | */ |
280 | 280 | function login(\ElggUser $user, $persistent = false) { |
281 | - if ($user->isBanned()) { |
|
282 | - throw new \LoginException(elgg_echo('LoginException:BannedUser')); |
|
283 | - } |
|
281 | + if ($user->isBanned()) { |
|
282 | + throw new \LoginException(elgg_echo('LoginException:BannedUser')); |
|
283 | + } |
|
284 | 284 | |
285 | - $session = _elgg_services()->session; |
|
285 | + $session = _elgg_services()->session; |
|
286 | 286 | |
287 | - // give plugins a chance to reject the login of this user (no user in session!) |
|
288 | - if (!elgg_trigger_before_event('login', 'user', $user)) { |
|
289 | - throw new \LoginException(elgg_echo('LoginException:Unknown')); |
|
290 | - } |
|
287 | + // give plugins a chance to reject the login of this user (no user in session!) |
|
288 | + if (!elgg_trigger_before_event('login', 'user', $user)) { |
|
289 | + throw new \LoginException(elgg_echo('LoginException:Unknown')); |
|
290 | + } |
|
291 | 291 | |
292 | - // #5933: set logged in user early so code in login event will be able to |
|
293 | - // use elgg_get_logged_in_user_entity(). |
|
294 | - $session->setLoggedInUser($user); |
|
292 | + // #5933: set logged in user early so code in login event will be able to |
|
293 | + // use elgg_get_logged_in_user_entity(). |
|
294 | + $session->setLoggedInUser($user); |
|
295 | 295 | |
296 | - // if remember me checked, set cookie with token and store hash(token) for user |
|
297 | - if ($persistent) { |
|
298 | - _elgg_services()->persistentLogin->makeLoginPersistent($user); |
|
299 | - } |
|
296 | + // if remember me checked, set cookie with token and store hash(token) for user |
|
297 | + if ($persistent) { |
|
298 | + _elgg_services()->persistentLogin->makeLoginPersistent($user); |
|
299 | + } |
|
300 | 300 | |
301 | - // User's privilege has been elevated, so change the session id (prevents session fixation) |
|
302 | - $session->migrate(); |
|
301 | + // User's privilege has been elevated, so change the session id (prevents session fixation) |
|
302 | + $session->migrate(); |
|
303 | 303 | |
304 | - set_last_login($user->guid); |
|
305 | - reset_login_failure_count($user->guid); |
|
304 | + set_last_login($user->guid); |
|
305 | + reset_login_failure_count($user->guid); |
|
306 | 306 | |
307 | - elgg_trigger_after_event('login', 'user', $user); |
|
307 | + elgg_trigger_after_event('login', 'user', $user); |
|
308 | 308 | |
309 | - return true; |
|
309 | + return true; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -315,26 +315,26 @@ discard block |
||
315 | 315 | * @return bool |
316 | 316 | */ |
317 | 317 | function logout() { |
318 | - $session = _elgg_services()->session; |
|
319 | - $user = $session->getLoggedInUser(); |
|
320 | - if (!$user) { |
|
321 | - return false; |
|
322 | - } |
|
318 | + $session = _elgg_services()->session; |
|
319 | + $user = $session->getLoggedInUser(); |
|
320 | + if (!$user) { |
|
321 | + return false; |
|
322 | + } |
|
323 | 323 | |
324 | - if (!elgg_trigger_before_event('logout', 'user', $user)) { |
|
325 | - return false; |
|
326 | - } |
|
324 | + if (!elgg_trigger_before_event('logout', 'user', $user)) { |
|
325 | + return false; |
|
326 | + } |
|
327 | 327 | |
328 | - _elgg_services()->persistentLogin->removePersistentLogin(); |
|
328 | + _elgg_services()->persistentLogin->removePersistentLogin(); |
|
329 | 329 | |
330 | - // pass along any messages into new session |
|
331 | - $old_msg = $session->get('msg'); |
|
332 | - $session->invalidate(); |
|
333 | - $session->set('msg', $old_msg); |
|
330 | + // pass along any messages into new session |
|
331 | + $old_msg = $session->get('msg'); |
|
332 | + $session->invalidate(); |
|
333 | + $session->set('msg', $old_msg); |
|
334 | 334 | |
335 | - elgg_trigger_after_event('logout', 'user', $user); |
|
335 | + elgg_trigger_after_event('logout', 'user', $user); |
|
336 | 336 | |
337 | - return true; |
|
337 | + return true; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -344,46 +344,46 @@ discard block |
||
344 | 344 | * @access private |
345 | 345 | */ |
346 | 346 | function _elgg_session_boot() { |
347 | - _elgg_services()->timer->begin([__FUNCTION__]); |
|
348 | - |
|
349 | - $session = _elgg_services()->session; |
|
350 | - $session->start(); |
|
351 | - |
|
352 | - // test whether we have a user session |
|
353 | - if ($session->has('guid')) { |
|
354 | - /** @var ElggUser $user */ |
|
355 | - $user = _elgg_services()->entityTable->get($session->get('guid'), 'user'); |
|
356 | - if (!$user) { |
|
357 | - // OMG user has been deleted. |
|
358 | - $session->invalidate(); |
|
359 | - forward(''); |
|
360 | - } |
|
361 | - |
|
362 | - $session->setLoggedInUser($user); |
|
363 | - |
|
364 | - _elgg_services()->persistentLogin->replaceLegacyToken($user); |
|
365 | - } else { |
|
366 | - $user = _elgg_services()->persistentLogin->bootSession(); |
|
367 | - if ($user) { |
|
368 | - $session->setLoggedInUser($user); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - if ($session->has('guid')) { |
|
373 | - set_last_action($session->get('guid')); |
|
374 | - } |
|
375 | - |
|
376 | - // logout a user with open session who has been banned |
|
377 | - $user = $session->getLoggedInUser(); |
|
378 | - if ($user && $user->isBanned()) { |
|
379 | - logout(); |
|
380 | - return false; |
|
381 | - } |
|
382 | - |
|
383 | - _elgg_services()->timer->end([__FUNCTION__]); |
|
384 | - return true; |
|
347 | + _elgg_services()->timer->begin([__FUNCTION__]); |
|
348 | + |
|
349 | + $session = _elgg_services()->session; |
|
350 | + $session->start(); |
|
351 | + |
|
352 | + // test whether we have a user session |
|
353 | + if ($session->has('guid')) { |
|
354 | + /** @var ElggUser $user */ |
|
355 | + $user = _elgg_services()->entityTable->get($session->get('guid'), 'user'); |
|
356 | + if (!$user) { |
|
357 | + // OMG user has been deleted. |
|
358 | + $session->invalidate(); |
|
359 | + forward(''); |
|
360 | + } |
|
361 | + |
|
362 | + $session->setLoggedInUser($user); |
|
363 | + |
|
364 | + _elgg_services()->persistentLogin->replaceLegacyToken($user); |
|
365 | + } else { |
|
366 | + $user = _elgg_services()->persistentLogin->bootSession(); |
|
367 | + if ($user) { |
|
368 | + $session->setLoggedInUser($user); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + if ($session->has('guid')) { |
|
373 | + set_last_action($session->get('guid')); |
|
374 | + } |
|
375 | + |
|
376 | + // logout a user with open session who has been banned |
|
377 | + $user = $session->getLoggedInUser(); |
|
378 | + if ($user && $user->isBanned()) { |
|
379 | + logout(); |
|
380 | + return false; |
|
381 | + } |
|
382 | + |
|
383 | + _elgg_services()->timer->end([__FUNCTION__]); |
|
384 | + return true; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
388 | - register_pam_handler('pam_auth_userpass'); |
|
388 | + register_pam_handler('pam_auth_userpass'); |
|
389 | 389 | }; |
@@ -56,7 +56,7 @@ |
||
56 | 56 | * @param mixed $default A default value for the variable if it is not found. |
57 | 57 | * @param bool $filter_result If true, then the result is filtered for bad tags. |
58 | 58 | * |
59 | - * @return mixed |
|
59 | + * @return integer |
|
60 | 60 | */ |
61 | 61 | function get($variable, $default = null, $filter_result = true) { |
62 | 62 | $result = $default; |
@@ -13,80 +13,80 @@ |
||
13 | 13 | */ |
14 | 14 | class Input { |
15 | 15 | |
16 | - /** |
|
17 | - * Data set from set_input() or from the request |
|
18 | - * |
|
19 | - * @var array |
|
20 | - */ |
|
21 | - private $data = []; |
|
16 | + /** |
|
17 | + * Data set from set_input() or from the request |
|
18 | + * |
|
19 | + * @var array |
|
20 | + */ |
|
21 | + private $data = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Sets an input value that may later be retrieved by get_input |
|
25 | - * |
|
26 | - * Note: this function does not handle nested arrays (ex: form input of param[m][n]) |
|
27 | - * |
|
28 | - * @param string $variable The name of the variable |
|
29 | - * @param string|string[] $value The value of the variable |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function set($variable, $value) { |
|
34 | - if (is_array($value)) { |
|
35 | - array_walk_recursive($value, function(&$v, $k) { |
|
36 | - $v = trim($v); |
|
37 | - }); |
|
38 | - $this->data[trim($variable)] = $value; |
|
39 | - } else { |
|
40 | - $this->data[trim($variable)] = trim($value); |
|
41 | - } |
|
42 | - } |
|
23 | + /** |
|
24 | + * Sets an input value that may later be retrieved by get_input |
|
25 | + * |
|
26 | + * Note: this function does not handle nested arrays (ex: form input of param[m][n]) |
|
27 | + * |
|
28 | + * @param string $variable The name of the variable |
|
29 | + * @param string|string[] $value The value of the variable |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function set($variable, $value) { |
|
34 | + if (is_array($value)) { |
|
35 | + array_walk_recursive($value, function(&$v, $k) { |
|
36 | + $v = trim($v); |
|
37 | + }); |
|
38 | + $this->data[trim($variable)] = $value; |
|
39 | + } else { |
|
40 | + $this->data[trim($variable)] = trim($value); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get some input from variables passed submitted through GET or POST. |
|
46 | - * |
|
47 | - * If using any data obtained from get_input() in a web page, please be aware that |
|
48 | - * it is a possible vector for a reflected XSS attack. If you are expecting an |
|
49 | - * integer, cast it to an int. If it is a string, escape quotes. |
|
50 | - * |
|
51 | - * Note: this function does not handle nested arrays (ex: form input of param[m][n]) |
|
52 | - * because of the filtering done in htmlawed from the filter_tags call. |
|
53 | - * @todo Is this ^ still true? |
|
54 | - * |
|
55 | - * @param string $variable The variable name we want. |
|
56 | - * @param mixed $default A default value for the variable if it is not found. |
|
57 | - * @param bool $filter_result If true, then the result is filtered for bad tags. |
|
58 | - * |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - function get($variable, $default = null, $filter_result = true) { |
|
62 | - $result = $default; |
|
44 | + /** |
|
45 | + * Get some input from variables passed submitted through GET or POST. |
|
46 | + * |
|
47 | + * If using any data obtained from get_input() in a web page, please be aware that |
|
48 | + * it is a possible vector for a reflected XSS attack. If you are expecting an |
|
49 | + * integer, cast it to an int. If it is a string, escape quotes. |
|
50 | + * |
|
51 | + * Note: this function does not handle nested arrays (ex: form input of param[m][n]) |
|
52 | + * because of the filtering done in htmlawed from the filter_tags call. |
|
53 | + * @todo Is this ^ still true? |
|
54 | + * |
|
55 | + * @param string $variable The variable name we want. |
|
56 | + * @param mixed $default A default value for the variable if it is not found. |
|
57 | + * @param bool $filter_result If true, then the result is filtered for bad tags. |
|
58 | + * |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + function get($variable, $default = null, $filter_result = true) { |
|
62 | + $result = $default; |
|
63 | 63 | |
64 | - elgg_push_context('input'); |
|
64 | + elgg_push_context('input'); |
|
65 | 65 | |
66 | - if (isset($this->data[$variable])) { |
|
67 | - // a plugin has already set this variable |
|
68 | - $result = $this->data[$variable]; |
|
69 | - if ($filter_result) { |
|
70 | - $result = filter_tags($result); |
|
71 | - } |
|
72 | - } else { |
|
73 | - $request = _elgg_services()->request; |
|
74 | - $value = $request->get($variable); |
|
75 | - if ($value !== null) { |
|
76 | - $result = $value; |
|
77 | - if (is_string($result)) { |
|
78 | - // @todo why trim |
|
79 | - $result = trim($result); |
|
80 | - } |
|
66 | + if (isset($this->data[$variable])) { |
|
67 | + // a plugin has already set this variable |
|
68 | + $result = $this->data[$variable]; |
|
69 | + if ($filter_result) { |
|
70 | + $result = filter_tags($result); |
|
71 | + } |
|
72 | + } else { |
|
73 | + $request = _elgg_services()->request; |
|
74 | + $value = $request->get($variable); |
|
75 | + if ($value !== null) { |
|
76 | + $result = $value; |
|
77 | + if (is_string($result)) { |
|
78 | + // @todo why trim |
|
79 | + $result = trim($result); |
|
80 | + } |
|
81 | 81 | |
82 | - if ($filter_result) { |
|
83 | - $result = filter_tags($result); |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
82 | + if ($filter_result) { |
|
83 | + $result = filter_tags($result); |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - elgg_pop_context(); |
|
88 | + elgg_pop_context(); |
|
89 | 89 | |
90 | - return $result; |
|
91 | - } |
|
90 | + return $result; |
|
91 | + } |
|
92 | 92 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * Checks if an account is validated |
147 | 147 | * |
148 | 148 | * @params array $credentials The username and password |
149 | - * @return bool |
|
149 | + * @return boolean|null |
|
150 | 150 | */ |
151 | 151 | function uservalidationbyemail_check_auth_attempt($credentials) { |
152 | 152 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param string $event |
231 | 231 | * @param string $type |
232 | 232 | * @param ElggUser $user |
233 | - * @return bool |
|
233 | + * @return boolean|null |
|
234 | 234 | * |
235 | 235 | * @throws LoginException |
236 | 236 | */ |
@@ -11,41 +11,41 @@ discard block |
||
11 | 11 | |
12 | 12 | function uservalidationbyemail_init() { |
13 | 13 | |
14 | - require_once dirname(__FILE__) . '/lib/functions.php'; |
|
14 | + require_once dirname(__FILE__) . '/lib/functions.php'; |
|
15 | 15 | |
16 | - // Register page handler to validate users |
|
17 | - // This doesn't need to be an action because security is handled by the validation codes. |
|
18 | - elgg_register_page_handler('uservalidationbyemail', 'uservalidationbyemail_page_handler'); |
|
16 | + // Register page handler to validate users |
|
17 | + // This doesn't need to be an action because security is handled by the validation codes. |
|
18 | + elgg_register_page_handler('uservalidationbyemail', 'uservalidationbyemail_page_handler'); |
|
19 | 19 | |
20 | - // mark users as unvalidated and disable when they register |
|
21 | - elgg_register_plugin_hook_handler('register', 'user', 'uservalidationbyemail_disable_new_user'); |
|
20 | + // mark users as unvalidated and disable when they register |
|
21 | + elgg_register_plugin_hook_handler('register', 'user', 'uservalidationbyemail_disable_new_user'); |
|
22 | 22 | |
23 | - // forward to uservalidationbyemail/emailsent page after register |
|
24 | - elgg_register_plugin_hook_handler('forward', 'system', 'uservalidationbyemail_after_registration_url'); |
|
23 | + // forward to uservalidationbyemail/emailsent page after register |
|
24 | + elgg_register_plugin_hook_handler('forward', 'system', 'uservalidationbyemail_after_registration_url'); |
|
25 | 25 | |
26 | - // canEdit override to allow not logged in code to disable a user |
|
27 | - elgg_register_plugin_hook_handler('permissions_check', 'user', 'uservalidationbyemail_allow_new_user_can_edit'); |
|
26 | + // canEdit override to allow not logged in code to disable a user |
|
27 | + elgg_register_plugin_hook_handler('permissions_check', 'user', 'uservalidationbyemail_allow_new_user_can_edit'); |
|
28 | 28 | |
29 | - // prevent users from logging in if they aren't validated |
|
30 | - register_pam_handler('uservalidationbyemail_check_auth_attempt', "required"); |
|
29 | + // prevent users from logging in if they aren't validated |
|
30 | + register_pam_handler('uservalidationbyemail_check_auth_attempt', "required"); |
|
31 | 31 | |
32 | - // prevent the engine from logging in users via login() |
|
33 | - elgg_register_event_handler('login:before', 'user', 'uservalidationbyemail_check_manual_login'); |
|
32 | + // prevent the engine from logging in users via login() |
|
33 | + elgg_register_event_handler('login:before', 'user', 'uservalidationbyemail_check_manual_login'); |
|
34 | 34 | |
35 | - // make admin users always validated |
|
36 | - elgg_register_event_handler('make_admin', 'user', 'uservalidationbyemail_validate_new_admin_user'); |
|
35 | + // make admin users always validated |
|
36 | + elgg_register_event_handler('make_admin', 'user', 'uservalidationbyemail_validate_new_admin_user'); |
|
37 | 37 | |
38 | - // register Walled Garden public pages |
|
39 | - elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'uservalidationbyemail_public_pages'); |
|
38 | + // register Walled Garden public pages |
|
39 | + elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'uservalidationbyemail_public_pages'); |
|
40 | 40 | |
41 | - // admin interface to manually validate users |
|
42 | - elgg_register_admin_menu_item('administer', 'unvalidated', 'users'); |
|
41 | + // admin interface to manually validate users |
|
42 | + elgg_register_admin_menu_item('administer', 'unvalidated', 'users'); |
|
43 | 43 | |
44 | - elgg_extend_view('admin.css', 'uservalidationbyemail/css'); |
|
44 | + elgg_extend_view('admin.css', 'uservalidationbyemail/css'); |
|
45 | 45 | |
46 | - // inline module |
|
47 | - elgg_extend_view('elgg.js', 'elgg/uservalidationbyemail.js'); |
|
48 | - elgg_require_js('elgg/uservalidationbyemail'); |
|
46 | + // inline module |
|
47 | + elgg_extend_view('elgg.js', 'elgg/uservalidationbyemail.js'); |
|
48 | + elgg_require_js('elgg/uservalidationbyemail'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -58,42 +58,42 @@ discard block |
||
58 | 58 | * @return void |
59 | 59 | */ |
60 | 60 | function uservalidationbyemail_disable_new_user($hook, $type, $value, $params) { |
61 | - $user = elgg_extract('user', $params); |
|
62 | - |
|
63 | - // no clue what's going on, so don't react. |
|
64 | - if (!$user instanceof ElggUser) { |
|
65 | - return; |
|
66 | - } |
|
67 | - |
|
68 | - // another plugin is requesting that registration be terminated |
|
69 | - // no need for uservalidationbyemail |
|
70 | - if (!$value) { |
|
71 | - return; |
|
72 | - } |
|
73 | - |
|
74 | - // has the user already been validated? |
|
75 | - if (elgg_get_user_validation_status($user->guid)) { |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - // disable user to prevent showing up on the site |
|
80 | - // set context so our canEdit() override works |
|
81 | - elgg_push_context('uservalidationbyemail_new_user'); |
|
82 | - $hidden_entities = access_get_show_hidden_status(); |
|
83 | - access_show_hidden_entities(true); |
|
84 | - |
|
85 | - // Don't do a recursive disable. Any entities owned by the user at this point |
|
86 | - // are products of plugins that hook into create user and might need |
|
87 | - // access to the entities. |
|
88 | - // @todo That ^ sounds like a specific case...would be nice to track it down... |
|
89 | - $user->disable('uservalidationbyemail_new_user', false); |
|
90 | - |
|
91 | - // set user as unvalidated and send out validation email |
|
92 | - elgg_set_user_validation_status($user->guid, false); |
|
93 | - uservalidationbyemail_request_validation($user->guid); |
|
94 | - |
|
95 | - elgg_pop_context(); |
|
96 | - access_show_hidden_entities($hidden_entities); |
|
61 | + $user = elgg_extract('user', $params); |
|
62 | + |
|
63 | + // no clue what's going on, so don't react. |
|
64 | + if (!$user instanceof ElggUser) { |
|
65 | + return; |
|
66 | + } |
|
67 | + |
|
68 | + // another plugin is requesting that registration be terminated |
|
69 | + // no need for uservalidationbyemail |
|
70 | + if (!$value) { |
|
71 | + return; |
|
72 | + } |
|
73 | + |
|
74 | + // has the user already been validated? |
|
75 | + if (elgg_get_user_validation_status($user->guid)) { |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + // disable user to prevent showing up on the site |
|
80 | + // set context so our canEdit() override works |
|
81 | + elgg_push_context('uservalidationbyemail_new_user'); |
|
82 | + $hidden_entities = access_get_show_hidden_status(); |
|
83 | + access_show_hidden_entities(true); |
|
84 | + |
|
85 | + // Don't do a recursive disable. Any entities owned by the user at this point |
|
86 | + // are products of plugins that hook into create user and might need |
|
87 | + // access to the entities. |
|
88 | + // @todo That ^ sounds like a specific case...would be nice to track it down... |
|
89 | + $user->disable('uservalidationbyemail_new_user', false); |
|
90 | + |
|
91 | + // set user as unvalidated and send out validation email |
|
92 | + elgg_set_user_validation_status($user->guid, false); |
|
93 | + uservalidationbyemail_request_validation($user->guid); |
|
94 | + |
|
95 | + elgg_pop_context(); |
|
96 | + access_show_hidden_entities($hidden_entities); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | * @return string |
107 | 107 | */ |
108 | 108 | function uservalidationbyemail_after_registration_url($hook, $type, $value, $params) { |
109 | - $url = elgg_extract('current_url', $params); |
|
110 | - if ($url == elgg_get_site_url() . 'action/register') { |
|
111 | - $session = elgg_get_session(); |
|
112 | - $email = $session->get('emailsent', ''); |
|
113 | - if ($email) { |
|
114 | - return elgg_get_site_url() . 'uservalidationbyemail/emailsent'; |
|
115 | - } |
|
116 | - } |
|
109 | + $url = elgg_extract('current_url', $params); |
|
110 | + if ($url == elgg_get_site_url() . 'action/register') { |
|
111 | + $session = elgg_get_session(); |
|
112 | + $email = $session->get('emailsent', ''); |
|
113 | + if ($email) { |
|
114 | + return elgg_get_site_url() . 'uservalidationbyemail/emailsent'; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -126,20 +126,20 @@ discard block |
||
126 | 126 | * @return bool|null |
127 | 127 | */ |
128 | 128 | function uservalidationbyemail_allow_new_user_can_edit($hook, $type, $value, $params) { |
129 | - // $params['user'] is the user to check permissions for. |
|
130 | - // we want the entity to check, which is a user. |
|
131 | - $user = elgg_extract('entity', $params); |
|
129 | + // $params['user'] is the user to check permissions for. |
|
130 | + // we want the entity to check, which is a user. |
|
131 | + $user = elgg_extract('entity', $params); |
|
132 | 132 | |
133 | - if (!($user instanceof ElggUser)) { |
|
134 | - return; |
|
135 | - } |
|
133 | + if (!($user instanceof ElggUser)) { |
|
134 | + return; |
|
135 | + } |
|
136 | 136 | |
137 | - $context = elgg_get_context(); |
|
138 | - if ($context == 'uservalidationbyemail_new_user' || $context == 'uservalidationbyemail_validate_user') { |
|
139 | - return true; |
|
140 | - } |
|
137 | + $context = elgg_get_context(); |
|
138 | + if ($context == 'uservalidationbyemail_new_user' || $context == 'uservalidationbyemail_validate_user') { |
|
139 | + return true; |
|
140 | + } |
|
141 | 141 | |
142 | - return; |
|
142 | + return; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -150,33 +150,33 @@ discard block |
||
150 | 150 | */ |
151 | 151 | function uservalidationbyemail_check_auth_attempt($credentials) { |
152 | 152 | |
153 | - if (!isset($credentials['username'])) { |
|
154 | - return; |
|
155 | - } |
|
156 | - |
|
157 | - $username = $credentials['username']; |
|
158 | - |
|
159 | - // See if the user exists and isn't validated |
|
160 | - $access_status = access_get_show_hidden_status(); |
|
161 | - access_show_hidden_entities(true); |
|
162 | - |
|
163 | - // check if logging in with email address |
|
164 | - if (strpos($username, '@') !== false) { |
|
165 | - $users = get_user_by_email($username); |
|
166 | - if ($users) { |
|
167 | - $username = $users[0]->username; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - $user = get_user_by_username($username); |
|
172 | - if ($user && isset($user->validated) && !$user->validated) { |
|
173 | - // show an error and resend validation email |
|
174 | - uservalidationbyemail_request_validation($user->guid); |
|
175 | - access_show_hidden_entities($access_status); |
|
176 | - throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); |
|
177 | - } |
|
178 | - |
|
179 | - access_show_hidden_entities($access_status); |
|
153 | + if (!isset($credentials['username'])) { |
|
154 | + return; |
|
155 | + } |
|
156 | + |
|
157 | + $username = $credentials['username']; |
|
158 | + |
|
159 | + // See if the user exists and isn't validated |
|
160 | + $access_status = access_get_show_hidden_status(); |
|
161 | + access_show_hidden_entities(true); |
|
162 | + |
|
163 | + // check if logging in with email address |
|
164 | + if (strpos($username, '@') !== false) { |
|
165 | + $users = get_user_by_email($username); |
|
166 | + if ($users) { |
|
167 | + $username = $users[0]->username; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + $user = get_user_by_username($username); |
|
172 | + if ($user && isset($user->validated) && !$user->validated) { |
|
173 | + // show an error and resend validation email |
|
174 | + uservalidationbyemail_request_validation($user->guid); |
|
175 | + access_show_hidden_entities($access_status); |
|
176 | + throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); |
|
177 | + } |
|
178 | + |
|
179 | + access_show_hidden_entities($access_status); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | * @return bool |
187 | 187 | */ |
188 | 188 | function uservalidationbyemail_page_handler($page) { |
189 | - switch ($page[0]) { |
|
190 | - case 'confirm': |
|
191 | - echo elgg_view_resource("uservalidationbyemail/confirm"); |
|
192 | - break; |
|
193 | - case 'emailsent': |
|
194 | - echo elgg_view_resource("uservalidationbyemail/emailsent"); |
|
195 | - break; |
|
196 | - default: |
|
197 | - forward('', '404'); |
|
198 | - return false; |
|
199 | - } |
|
200 | - |
|
201 | - // note, safe to include based on input because we validated above. |
|
202 | - return true; |
|
189 | + switch ($page[0]) { |
|
190 | + case 'confirm': |
|
191 | + echo elgg_view_resource("uservalidationbyemail/confirm"); |
|
192 | + break; |
|
193 | + case 'emailsent': |
|
194 | + echo elgg_view_resource("uservalidationbyemail/emailsent"); |
|
195 | + break; |
|
196 | + default: |
|
197 | + forward('', '404'); |
|
198 | + return false; |
|
199 | + } |
|
200 | + |
|
201 | + // note, safe to include based on input because we validated above. |
|
202 | + return true; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | * @param ElggUser $user |
211 | 211 | */ |
212 | 212 | function uservalidationbyemail_validate_new_admin_user($event, $type, $user) { |
213 | - if ($user instanceof ElggUser && !$user->validated) { |
|
214 | - elgg_set_user_validation_status($user->guid, true, 'admin_user'); |
|
215 | - } |
|
213 | + if ($user instanceof ElggUser && !$user->validated) { |
|
214 | + elgg_set_user_validation_status($user->guid, true, 'admin_user'); |
|
215 | + } |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Registers public pages to allow in the case walled garden has been enabled. |
220 | 220 | */ |
221 | 221 | function uservalidationbyemail_public_pages($hook, $type, $return_value, $params) { |
222 | - $return_value[] = 'uservalidationbyemail/confirm'; |
|
223 | - $return_value[] = 'uservalidationbyemail/emailsent'; |
|
224 | - return $return_value; |
|
222 | + $return_value[] = 'uservalidationbyemail/confirm'; |
|
223 | + $return_value[] = 'uservalidationbyemail/emailsent'; |
|
224 | + return $return_value; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | * @throws LoginException |
236 | 236 | */ |
237 | 237 | function uservalidationbyemail_check_manual_login($event, $type, $user) { |
238 | - $access_status = access_get_show_hidden_status(); |
|
239 | - access_show_hidden_entities(true); |
|
238 | + $access_status = access_get_show_hidden_status(); |
|
239 | + access_show_hidden_entities(true); |
|
240 | 240 | |
241 | - if (($user instanceof ElggUser) && !$user->isEnabled() && !$user->validated) { |
|
242 | - // send new validation email |
|
243 | - uservalidationbyemail_request_validation($user->getGUID()); |
|
241 | + if (($user instanceof ElggUser) && !$user->isEnabled() && !$user->validated) { |
|
242 | + // send new validation email |
|
243 | + uservalidationbyemail_request_validation($user->getGUID()); |
|
244 | 244 | |
245 | - // restore hidden entities settings |
|
246 | - access_show_hidden_entities($access_status); |
|
245 | + // restore hidden entities settings |
|
246 | + access_show_hidden_entities($access_status); |
|
247 | 247 | |
248 | - // throw error so we get a nice error message |
|
249 | - throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); |
|
250 | - } |
|
248 | + // throw error so we get a nice error message |
|
249 | + throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); |
|
250 | + } |
|
251 | 251 | |
252 | - access_show_hidden_entities($access_status); |
|
252 | + access_show_hidden_entities($access_status); |
|
253 | 253 | } |
@@ -27,271 +27,271 @@ |
||
27 | 27 | */ |
28 | 28 | class ElggSite extends \ElggEntity { |
29 | 29 | |
30 | - /** |
|
31 | - * Initialize the attributes array. |
|
32 | - * This is vital to distinguish between metadata and base attributes. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - protected function initializeAttributes() { |
|
37 | - parent::initializeAttributes(); |
|
38 | - |
|
39 | - $this->attributes['type'] = "site"; |
|
40 | - $this->attributes += self::getExternalAttributes(); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Get default values for attributes stored in a separate table |
|
45 | - * |
|
46 | - * @return array |
|
47 | - * @access private |
|
48 | - * |
|
49 | - * @see \Elgg\Database\EntityTable::getEntities |
|
50 | - */ |
|
51 | - final public static function getExternalAttributes() { |
|
52 | - return [ |
|
53 | - 'name' => null, |
|
54 | - 'description' => null, |
|
55 | - 'url' => null, |
|
56 | - ]; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a new \ElggSite. |
|
61 | - * |
|
62 | - * Plugin developers should only use the constructor to create a new entity. |
|
63 | - * To retrieve entities, use get_entity() and the elgg_get_entities* functions. |
|
64 | - * |
|
65 | - * @param \stdClass $row Database row result. Default is null to create a new site. |
|
66 | - * |
|
67 | - * @throws IOException If cannot load remaining data from db |
|
68 | - * @throws InvalidParameterException If not passed a db result |
|
69 | - */ |
|
70 | - public function __construct(\stdClass $row = null) { |
|
71 | - $this->initializeAttributes(); |
|
72 | - |
|
73 | - if ($row) { |
|
74 | - // Load the rest |
|
75 | - if (!$this->load($row)) { |
|
76 | - $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; |
|
77 | - throw new \IOException($msg); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * {@inheritdoc} |
|
84 | - */ |
|
85 | - public function save() { |
|
86 | - $db = $this->getDatabase(); |
|
87 | - $row = $db->getDataRow(" |
|
30 | + /** |
|
31 | + * Initialize the attributes array. |
|
32 | + * This is vital to distinguish between metadata and base attributes. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + protected function initializeAttributes() { |
|
37 | + parent::initializeAttributes(); |
|
38 | + |
|
39 | + $this->attributes['type'] = "site"; |
|
40 | + $this->attributes += self::getExternalAttributes(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Get default values for attributes stored in a separate table |
|
45 | + * |
|
46 | + * @return array |
|
47 | + * @access private |
|
48 | + * |
|
49 | + * @see \Elgg\Database\EntityTable::getEntities |
|
50 | + */ |
|
51 | + final public static function getExternalAttributes() { |
|
52 | + return [ |
|
53 | + 'name' => null, |
|
54 | + 'description' => null, |
|
55 | + 'url' => null, |
|
56 | + ]; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a new \ElggSite. |
|
61 | + * |
|
62 | + * Plugin developers should only use the constructor to create a new entity. |
|
63 | + * To retrieve entities, use get_entity() and the elgg_get_entities* functions. |
|
64 | + * |
|
65 | + * @param \stdClass $row Database row result. Default is null to create a new site. |
|
66 | + * |
|
67 | + * @throws IOException If cannot load remaining data from db |
|
68 | + * @throws InvalidParameterException If not passed a db result |
|
69 | + */ |
|
70 | + public function __construct(\stdClass $row = null) { |
|
71 | + $this->initializeAttributes(); |
|
72 | + |
|
73 | + if ($row) { |
|
74 | + // Load the rest |
|
75 | + if (!$this->load($row)) { |
|
76 | + $msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid; |
|
77 | + throw new \IOException($msg); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * {@inheritdoc} |
|
84 | + */ |
|
85 | + public function save() { |
|
86 | + $db = $this->getDatabase(); |
|
87 | + $row = $db->getDataRow(" |
|
88 | 88 | SELECT guid FROM {$db->prefix}sites_entity |
89 | 89 | "); |
90 | - if ($row) { |
|
91 | - if ($row->guid == $this->attributes['guid']) { |
|
92 | - // can save active site |
|
93 | - return parent::save(); |
|
94 | - } |
|
95 | - |
|
96 | - _elgg_services()->logger->error('More than 1 site entity cannot be created.'); |
|
97 | - return false; |
|
98 | - } |
|
99 | - |
|
100 | - return parent::save(); // TODO: Change the autogenerated stub |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Loads the full \ElggSite when given a guid. |
|
105 | - * |
|
106 | - * @param mixed $guid GUID of \ElggSite entity or database row object |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - * @throws InvalidClassException |
|
110 | - */ |
|
111 | - protected function load($guid) { |
|
112 | - // TODO(steve) we only have 1 site, simplify this... |
|
113 | - $attr_loader = new \Elgg\AttributeLoader(get_class(), 'site', $this->attributes); |
|
114 | - $attr_loader->requires_access_control = !($this instanceof \ElggPlugin); |
|
115 | - $attr_loader->secondary_loader = 'get_site_entity_as_row'; |
|
116 | - |
|
117 | - $attrs = $attr_loader->getRequiredAttributes($guid); |
|
118 | - if (!$attrs) { |
|
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - $this->attributes = $attrs; |
|
123 | - $this->loadAdditionalSelectValues($attr_loader->getAdditionalSelectValues()); |
|
124 | - _elgg_services()->entityCache->set($this); |
|
125 | - |
|
126 | - return true; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritdoc} |
|
131 | - */ |
|
132 | - protected function create() { |
|
133 | - $guid = parent::create(); |
|
134 | - $db = $this->getDatabase(); |
|
135 | - |
|
136 | - $query = " |
|
90 | + if ($row) { |
|
91 | + if ($row->guid == $this->attributes['guid']) { |
|
92 | + // can save active site |
|
93 | + return parent::save(); |
|
94 | + } |
|
95 | + |
|
96 | + _elgg_services()->logger->error('More than 1 site entity cannot be created.'); |
|
97 | + return false; |
|
98 | + } |
|
99 | + |
|
100 | + return parent::save(); // TODO: Change the autogenerated stub |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Loads the full \ElggSite when given a guid. |
|
105 | + * |
|
106 | + * @param mixed $guid GUID of \ElggSite entity or database row object |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + * @throws InvalidClassException |
|
110 | + */ |
|
111 | + protected function load($guid) { |
|
112 | + // TODO(steve) we only have 1 site, simplify this... |
|
113 | + $attr_loader = new \Elgg\AttributeLoader(get_class(), 'site', $this->attributes); |
|
114 | + $attr_loader->requires_access_control = !($this instanceof \ElggPlugin); |
|
115 | + $attr_loader->secondary_loader = 'get_site_entity_as_row'; |
|
116 | + |
|
117 | + $attrs = $attr_loader->getRequiredAttributes($guid); |
|
118 | + if (!$attrs) { |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + $this->attributes = $attrs; |
|
123 | + $this->loadAdditionalSelectValues($attr_loader->getAdditionalSelectValues()); |
|
124 | + _elgg_services()->entityCache->set($this); |
|
125 | + |
|
126 | + return true; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritdoc} |
|
131 | + */ |
|
132 | + protected function create() { |
|
133 | + $guid = parent::create(); |
|
134 | + $db = $this->getDatabase(); |
|
135 | + |
|
136 | + $query = " |
|
137 | 137 | INSERT INTO {$db->prefix}sites_entity |
138 | 138 | (guid, name, description, url) VALUES (:guid, :name, :desc, :url) |
139 | 139 | "; |
140 | - $params = [ |
|
141 | - ':guid' => $guid, |
|
142 | - ':name' => (string) $this->attributes['name'], |
|
143 | - ':desc' => (string) $this->attributes['description'], |
|
144 | - ':url' => '', |
|
145 | - ]; |
|
146 | - |
|
147 | - $result = $db->insertData($query, $params); |
|
148 | - if ($result === false) { |
|
149 | - return false; |
|
150 | - } |
|
151 | - |
|
152 | - return $guid; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * {@inheritdoc} |
|
157 | - */ |
|
158 | - protected function update() { |
|
159 | - if (!parent::update()) { |
|
160 | - return false; |
|
161 | - } |
|
162 | - |
|
163 | - $guid = (int) $this->guid; |
|
164 | - $db = $this->getDatabase(); |
|
165 | - |
|
166 | - $query = " |
|
140 | + $params = [ |
|
141 | + ':guid' => $guid, |
|
142 | + ':name' => (string) $this->attributes['name'], |
|
143 | + ':desc' => (string) $this->attributes['description'], |
|
144 | + ':url' => '', |
|
145 | + ]; |
|
146 | + |
|
147 | + $result = $db->insertData($query, $params); |
|
148 | + if ($result === false) { |
|
149 | + return false; |
|
150 | + } |
|
151 | + |
|
152 | + return $guid; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * {@inheritdoc} |
|
157 | + */ |
|
158 | + protected function update() { |
|
159 | + if (!parent::update()) { |
|
160 | + return false; |
|
161 | + } |
|
162 | + |
|
163 | + $guid = (int) $this->guid; |
|
164 | + $db = $this->getDatabase(); |
|
165 | + |
|
166 | + $query = " |
|
167 | 167 | UPDATE {$db->prefix}sites_entity |
168 | 168 | SET name = :name, description = :desc, url = :url WHERE guid = :guid |
169 | 169 | "; |
170 | - $params = [ |
|
171 | - ':guid' => $guid, |
|
172 | - ':name' => (string) $this->attributes['name'], |
|
173 | - ':desc' => (string) $this->attributes['description'], |
|
174 | - ':url' => '', |
|
175 | - ]; |
|
176 | - |
|
177 | - return $db->updateData($query, false, $params) !== false; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Delete the site. |
|
182 | - * |
|
183 | - * @note You cannot delete the current site. |
|
184 | - * |
|
185 | - * @return bool |
|
186 | - * @throws SecurityException |
|
187 | - */ |
|
188 | - public function delete() { |
|
189 | - if ($this->guid == 1) { |
|
190 | - throw new \SecurityException('You cannot delete the current site'); |
|
191 | - } |
|
192 | - |
|
193 | - return parent::delete(); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Disable the site |
|
198 | - * |
|
199 | - * @note You cannot disable the current site. |
|
200 | - * |
|
201 | - * @param string $reason Optional reason for disabling |
|
202 | - * @param bool $recursive Recursively disable all contained entities? |
|
203 | - * |
|
204 | - * @return bool |
|
205 | - * @throws SecurityException |
|
206 | - */ |
|
207 | - public function disable($reason = "", $recursive = true) { |
|
208 | - if ($this->guid == 1) { |
|
209 | - throw new \SecurityException('You cannot disable the current site'); |
|
210 | - } |
|
211 | - |
|
212 | - return parent::disable($reason, $recursive); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * {@inheritdoc} |
|
217 | - */ |
|
218 | - public function __set($name, $value) { |
|
219 | - if ($name === 'url') { |
|
220 | - _elgg_services()->logger->warn("ElggSite::url cannot be set"); |
|
221 | - return; |
|
222 | - } |
|
223 | - parent::__set($name, $value); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * {@inheritdoc} |
|
228 | - */ |
|
229 | - public function __get($name) { |
|
230 | - if ($name === 'url') { |
|
231 | - return $this->getURL(); |
|
232 | - } |
|
233 | - return parent::__get($name); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Returns the URL for this site |
|
238 | - * |
|
239 | - * @return string The URL |
|
240 | - */ |
|
241 | - public function getURL() { |
|
242 | - return _elgg_services()->config->getSiteUrl(); |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * {@inheritdoc} |
|
247 | - */ |
|
248 | - public function getDisplayName() { |
|
249 | - return $this->name; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * {@inheritdoc} |
|
254 | - */ |
|
255 | - public function setDisplayName($displayName) { |
|
256 | - $this->name = $displayName; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * {@inheritdoc} |
|
261 | - */ |
|
262 | - protected function prepareObject($object) { |
|
263 | - $object = parent::prepareObject($object); |
|
264 | - $object->name = $this->getDisplayName(); |
|
265 | - $object->description = $this->description; |
|
266 | - unset($object->read_access); |
|
267 | - return $object; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Get the domain for this site |
|
272 | - * |
|
273 | - * @return string |
|
274 | - * @since 1.9 |
|
275 | - */ |
|
276 | - public function getDomain() { |
|
277 | - $breakdown = parse_url($this->url); |
|
278 | - return $breakdown['host']; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the email address for the site |
|
283 | - * |
|
284 | - * This can be set in the basic site settings or fallback to noreply@domain |
|
285 | - * |
|
286 | - * @return string |
|
287 | - * @since 3.0.0 |
|
288 | - */ |
|
289 | - public function getEmailAddress() { |
|
290 | - $email = $this->email; |
|
291 | - if (empty($email)) { |
|
292 | - $email = "noreply@{$this->getDomain()}"; |
|
293 | - } |
|
294 | - |
|
295 | - return $email; |
|
296 | - } |
|
170 | + $params = [ |
|
171 | + ':guid' => $guid, |
|
172 | + ':name' => (string) $this->attributes['name'], |
|
173 | + ':desc' => (string) $this->attributes['description'], |
|
174 | + ':url' => '', |
|
175 | + ]; |
|
176 | + |
|
177 | + return $db->updateData($query, false, $params) !== false; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Delete the site. |
|
182 | + * |
|
183 | + * @note You cannot delete the current site. |
|
184 | + * |
|
185 | + * @return bool |
|
186 | + * @throws SecurityException |
|
187 | + */ |
|
188 | + public function delete() { |
|
189 | + if ($this->guid == 1) { |
|
190 | + throw new \SecurityException('You cannot delete the current site'); |
|
191 | + } |
|
192 | + |
|
193 | + return parent::delete(); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Disable the site |
|
198 | + * |
|
199 | + * @note You cannot disable the current site. |
|
200 | + * |
|
201 | + * @param string $reason Optional reason for disabling |
|
202 | + * @param bool $recursive Recursively disable all contained entities? |
|
203 | + * |
|
204 | + * @return bool |
|
205 | + * @throws SecurityException |
|
206 | + */ |
|
207 | + public function disable($reason = "", $recursive = true) { |
|
208 | + if ($this->guid == 1) { |
|
209 | + throw new \SecurityException('You cannot disable the current site'); |
|
210 | + } |
|
211 | + |
|
212 | + return parent::disable($reason, $recursive); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * {@inheritdoc} |
|
217 | + */ |
|
218 | + public function __set($name, $value) { |
|
219 | + if ($name === 'url') { |
|
220 | + _elgg_services()->logger->warn("ElggSite::url cannot be set"); |
|
221 | + return; |
|
222 | + } |
|
223 | + parent::__set($name, $value); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * {@inheritdoc} |
|
228 | + */ |
|
229 | + public function __get($name) { |
|
230 | + if ($name === 'url') { |
|
231 | + return $this->getURL(); |
|
232 | + } |
|
233 | + return parent::__get($name); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Returns the URL for this site |
|
238 | + * |
|
239 | + * @return string The URL |
|
240 | + */ |
|
241 | + public function getURL() { |
|
242 | + return _elgg_services()->config->getSiteUrl(); |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * {@inheritdoc} |
|
247 | + */ |
|
248 | + public function getDisplayName() { |
|
249 | + return $this->name; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * {@inheritdoc} |
|
254 | + */ |
|
255 | + public function setDisplayName($displayName) { |
|
256 | + $this->name = $displayName; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * {@inheritdoc} |
|
261 | + */ |
|
262 | + protected function prepareObject($object) { |
|
263 | + $object = parent::prepareObject($object); |
|
264 | + $object->name = $this->getDisplayName(); |
|
265 | + $object->description = $this->description; |
|
266 | + unset($object->read_access); |
|
267 | + return $object; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Get the domain for this site |
|
272 | + * |
|
273 | + * @return string |
|
274 | + * @since 1.9 |
|
275 | + */ |
|
276 | + public function getDomain() { |
|
277 | + $breakdown = parse_url($this->url); |
|
278 | + return $breakdown['host']; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the email address for the site |
|
283 | + * |
|
284 | + * This can be set in the basic site settings or fallback to noreply@domain |
|
285 | + * |
|
286 | + * @return string |
|
287 | + * @since 3.0.0 |
|
288 | + */ |
|
289 | + public function getEmailAddress() { |
|
290 | + $email = $this->email; |
|
291 | + if (empty($email)) { |
|
292 | + $email = "noreply@{$this->getDomain()}"; |
|
293 | + } |
|
294 | + |
|
295 | + return $email; |
|
296 | + } |
|
297 | 297 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @since 2.0.0 |
19 | 19 | */ |
20 | 20 | function elgg() { |
21 | - return Elgg\Application::$_instance; |
|
21 | + return Elgg\Application::$_instance; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | * @since 1.8.0 |
34 | 34 | */ |
35 | 35 | function elgg_register_library($name, $location) { |
36 | - $config = _elgg_services()->config; |
|
36 | + $config = _elgg_services()->config; |
|
37 | 37 | |
38 | - $libraries = $config->get('libraries'); |
|
39 | - if ($libraries === null) { |
|
40 | - $libraries = []; |
|
41 | - } |
|
42 | - $libraries[$name] = $location; |
|
43 | - $config->set('libraries', $libraries); |
|
38 | + $libraries = $config->get('libraries'); |
|
39 | + if ($libraries === null) { |
|
40 | + $libraries = []; |
|
41 | + } |
|
42 | + $libraries[$name] = $location; |
|
43 | + $config->set('libraries', $libraries); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | * @since 1.8.0 |
56 | 56 | */ |
57 | 57 | function elgg_load_library($name) { |
58 | - static $loaded_libraries = []; |
|
58 | + static $loaded_libraries = []; |
|
59 | 59 | |
60 | - if (in_array($name, $loaded_libraries)) { |
|
61 | - return; |
|
62 | - } |
|
60 | + if (in_array($name, $loaded_libraries)) { |
|
61 | + return; |
|
62 | + } |
|
63 | 63 | |
64 | - $libraries = _elgg_services()->config->get('libraries'); |
|
64 | + $libraries = _elgg_services()->config->get('libraries'); |
|
65 | 65 | |
66 | - if (!isset($libraries[$name])) { |
|
67 | - $error = "$name is not a registered library"; |
|
68 | - throw new \InvalidParameterException($error); |
|
69 | - } |
|
66 | + if (!isset($libraries[$name])) { |
|
67 | + $error = "$name is not a registered library"; |
|
68 | + throw new \InvalidParameterException($error); |
|
69 | + } |
|
70 | 70 | |
71 | - if (!include_once($libraries[$name])) { |
|
72 | - $error = "Could not load the $name library from {$libraries[$name]}"; |
|
73 | - throw new \InvalidParameterException($error); |
|
74 | - } |
|
71 | + if (!include_once($libraries[$name])) { |
|
72 | + $error = "Could not load the $name library from {$libraries[$name]}"; |
|
73 | + throw new \InvalidParameterException($error); |
|
74 | + } |
|
75 | 75 | |
76 | - $loaded_libraries[] = $name; |
|
76 | + $loaded_libraries[] = $name; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -92,13 +92,13 @@ discard block |
||
92 | 92 | * @throws SecurityException |
93 | 93 | */ |
94 | 94 | function forward($location = "", $reason = 'system') { |
95 | - if (headers_sent($file, $line)) { |
|
96 | - throw new \SecurityException("Redirect could not be issued due to headers already being sent. Halting execution for security. " |
|
97 | - . "Output started in file $file at line $line. Search http://learn.elgg.org/ for more information."); |
|
98 | - } |
|
95 | + if (headers_sent($file, $line)) { |
|
96 | + throw new \SecurityException("Redirect could not be issued due to headers already being sent. Halting execution for security. " |
|
97 | + . "Output started in file $file at line $line. Search http://learn.elgg.org/ for more information."); |
|
98 | + } |
|
99 | 99 | |
100 | - _elgg_services()->responseFactory->redirect($location, $reason); |
|
101 | - exit; |
|
100 | + _elgg_services()->responseFactory->redirect($location, $reason); |
|
101 | + exit; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -112,17 +112,17 @@ discard block |
||
112 | 112 | * @since 2.3 |
113 | 113 | */ |
114 | 114 | function elgg_set_http_header($header, $replace = true) { |
115 | - if (headers_sent($file, $line)) { |
|
116 | - _elgg_services()->logger->error("Cannot modify header information - headers already sent by |
|
115 | + if (headers_sent($file, $line)) { |
|
116 | + _elgg_services()->logger->error("Cannot modify header information - headers already sent by |
|
117 | 117 | (output started at $file:$line)"); |
118 | - } else { |
|
119 | - header($header, $replace); |
|
120 | - } |
|
118 | + } else { |
|
119 | + header($header, $replace); |
|
120 | + } |
|
121 | 121 | |
122 | - if (!preg_match('~^HTTP/\\d\\.\\d~', $header)) { |
|
123 | - list($name, $value) = explode(':', $header, 2); |
|
124 | - _elgg_services()->responseFactory->setHeader($name, ltrim($value), $replace); |
|
125 | - } |
|
122 | + if (!preg_match('~^HTTP/\\d\\.\\d~', $header)) { |
|
123 | + list($name, $value) = explode(':', $header, 2); |
|
124 | + _elgg_services()->responseFactory->setHeader($name, ltrim($value), $replace); |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @since 1.8.0 |
154 | 154 | */ |
155 | 155 | function elgg_register_js($name, $url, $location = 'head', $priority = null) { |
156 | - return elgg_register_external_file('js', $name, $url, $location, $priority); |
|
156 | + return elgg_register_external_file('js', $name, $url, $location, $priority); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | * @return void |
182 | 182 | */ |
183 | 183 | function elgg_define_js($name, $config) { |
184 | - $src = elgg_extract('src', $config); |
|
184 | + $src = elgg_extract('src', $config); |
|
185 | 185 | |
186 | - if ($src) { |
|
187 | - $url = elgg_normalize_url($src); |
|
188 | - _elgg_services()->amdConfig->addPath($name, $url); |
|
189 | - } |
|
186 | + if ($src) { |
|
187 | + $url = elgg_normalize_url($src); |
|
188 | + _elgg_services()->amdConfig->addPath($name, $url); |
|
189 | + } |
|
190 | 190 | |
191 | - // shimmed module |
|
192 | - if (isset($config['deps']) || isset($config['exports'])) { |
|
193 | - _elgg_services()->amdConfig->addShim($name, $config); |
|
194 | - } |
|
191 | + // shimmed module |
|
192 | + if (isset($config['deps']) || isset($config['exports'])) { |
|
193 | + _elgg_services()->amdConfig->addShim($name, $config); |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @since 1.8.0 |
204 | 204 | */ |
205 | 205 | function elgg_unregister_js($name) { |
206 | - return elgg_unregister_external_file('js', $name); |
|
206 | + return elgg_unregister_external_file('js', $name); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @since 1.8.0 |
219 | 219 | */ |
220 | 220 | function elgg_load_js($name) { |
221 | - elgg_load_external_file('js', $name); |
|
221 | + elgg_load_external_file('js', $name); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @since 1.9.0 |
231 | 231 | */ |
232 | 232 | function elgg_require_js($name) { |
233 | - _elgg_services()->amdConfig->addDependency($name); |
|
233 | + _elgg_services()->amdConfig->addDependency($name); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @since 2.1.0 |
244 | 244 | */ |
245 | 245 | function elgg_unrequire_js($name) { |
246 | - _elgg_services()->amdConfig->removeDependency($name); |
|
246 | + _elgg_services()->amdConfig->removeDependency($name); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @since 1.8.0 |
256 | 256 | */ |
257 | 257 | function elgg_get_loaded_js($location = 'head') { |
258 | - return elgg_get_loaded_external_files('js', $location); |
|
258 | + return elgg_get_loaded_external_files('js', $location); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @since 1.8.0 |
270 | 270 | */ |
271 | 271 | function elgg_register_css($name, $url, $priority = null) { |
272 | - return elgg_register_external_file('css', $name, $url, 'head', $priority); |
|
272 | + return elgg_register_external_file('css', $name, $url, 'head', $priority); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @since 1.8.0 |
282 | 282 | */ |
283 | 283 | function elgg_unregister_css($name) { |
284 | - return elgg_unregister_external_file('css', $name); |
|
284 | + return elgg_unregister_external_file('css', $name); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @since 1.8.0 |
297 | 297 | */ |
298 | 298 | function elgg_load_css($name) { |
299 | - elgg_load_external_file('css', $name); |
|
299 | + elgg_load_external_file('css', $name); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | * @since 1.8.0 |
307 | 307 | */ |
308 | 308 | function elgg_get_loaded_css() { |
309 | - return elgg_get_loaded_external_files('css', 'head'); |
|
309 | + return elgg_get_loaded_external_files('css', 'head'); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @since 1.8.0 |
323 | 323 | */ |
324 | 324 | function elgg_register_external_file($type, $name, $url, $location, $priority = 500) { |
325 | - return _elgg_services()->externalFiles->register($type, $name, $url, $location, $priority); |
|
325 | + return _elgg_services()->externalFiles->register($type, $name, $url, $location, $priority); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @since 1.8.0 |
336 | 336 | */ |
337 | 337 | function elgg_unregister_external_file($type, $name) { |
338 | - return _elgg_services()->externalFiles->unregister($type, $name); |
|
338 | + return _elgg_services()->externalFiles->unregister($type, $name); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * @since 1.8.0 |
349 | 349 | */ |
350 | 350 | function elgg_load_external_file($type, $name) { |
351 | - return _elgg_services()->externalFiles->load($type, $name); |
|
351 | + return _elgg_services()->externalFiles->load($type, $name); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * @since 1.8.0 |
362 | 362 | */ |
363 | 363 | function elgg_get_loaded_external_files($type, $location) { |
364 | - return _elgg_services()->externalFiles->getLoadedFiles($type, $location); |
|
364 | + return _elgg_services()->externalFiles->getLoadedFiles($type, $location); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -378,25 +378,25 @@ discard block |
||
378 | 378 | */ |
379 | 379 | function elgg_get_file_list($directory, $exceptions = [], $list = [], $extensions = null) { |
380 | 380 | |
381 | - $directory = sanitise_filepath($directory); |
|
382 | - if ($handle = opendir($directory)) { |
|
383 | - while (($file = readdir($handle)) !== false) { |
|
384 | - if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
385 | - continue; |
|
386 | - } |
|
381 | + $directory = sanitise_filepath($directory); |
|
382 | + if ($handle = opendir($directory)) { |
|
383 | + while (($file = readdir($handle)) !== false) { |
|
384 | + if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
385 | + continue; |
|
386 | + } |
|
387 | 387 | |
388 | - if (is_array($extensions)) { |
|
389 | - if (in_array(strrchr($file, '.'), $extensions)) { |
|
390 | - $list[] = $directory . $file; |
|
391 | - } |
|
392 | - } else { |
|
393 | - $list[] = $directory . $file; |
|
394 | - } |
|
395 | - } |
|
396 | - closedir($handle); |
|
397 | - } |
|
388 | + if (is_array($extensions)) { |
|
389 | + if (in_array(strrchr($file, '.'), $extensions)) { |
|
390 | + $list[] = $directory . $file; |
|
391 | + } |
|
392 | + } else { |
|
393 | + $list[] = $directory . $file; |
|
394 | + } |
|
395 | + } |
|
396 | + closedir($handle); |
|
397 | + } |
|
398 | 398 | |
399 | - return $list; |
|
399 | + return $list; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -408,22 +408,22 @@ discard block |
||
408 | 408 | * @return string |
409 | 409 | */ |
410 | 410 | function sanitise_filepath($path, $append_slash = true) { |
411 | - // Convert to correct UNIX paths |
|
412 | - $path = str_replace('\\', '/', $path); |
|
413 | - $path = str_replace('../', '/', $path); |
|
414 | - // replace // with / except when preceeded by : |
|
415 | - $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
411 | + // Convert to correct UNIX paths |
|
412 | + $path = str_replace('\\', '/', $path); |
|
413 | + $path = str_replace('../', '/', $path); |
|
414 | + // replace // with / except when preceeded by : |
|
415 | + $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
416 | 416 | |
417 | - // Sort trailing slash |
|
418 | - $path = trim($path); |
|
419 | - // rtrim defaults plus / |
|
420 | - $path = rtrim($path, " \n\t\0\x0B/"); |
|
417 | + // Sort trailing slash |
|
418 | + $path = trim($path); |
|
419 | + // rtrim defaults plus / |
|
420 | + $path = rtrim($path, " \n\t\0\x0B/"); |
|
421 | 421 | |
422 | - if ($append_slash) { |
|
423 | - $path = $path . '/'; |
|
424 | - } |
|
422 | + if ($append_slash) { |
|
423 | + $path = $path . '/'; |
|
424 | + } |
|
425 | 425 | |
426 | - return $path; |
|
426 | + return $path; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @return integer The number of messages |
435 | 435 | */ |
436 | 436 | function count_messages($register = "") { |
437 | - return _elgg_services()->systemMessages->count($register); |
|
437 | + return _elgg_services()->systemMessages->count($register); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * @return bool |
446 | 446 | */ |
447 | 447 | function system_message($message) { |
448 | - _elgg_services()->systemMessages->addSuccessMessage($message); |
|
449 | - return true; |
|
448 | + _elgg_services()->systemMessages->addSuccessMessage($message); |
|
449 | + return true; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -457,8 +457,8 @@ discard block |
||
457 | 457 | * @return bool |
458 | 458 | */ |
459 | 459 | function register_error($error) { |
460 | - _elgg_services()->systemMessages->addErrorMessage($error); |
|
461 | - return true; |
|
460 | + _elgg_services()->systemMessages->addErrorMessage($error); |
|
461 | + return true; |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @since 2.1 |
469 | 469 | */ |
470 | 470 | function elgg_get_system_messages() { |
471 | - return _elgg_services()->systemMessages->loadRegisters(); |
|
471 | + return _elgg_services()->systemMessages->loadRegisters(); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @since 2.1 |
480 | 480 | */ |
481 | 481 | function elgg_set_system_messages(\Elgg\SystemMessages\RegisterSet $set) { |
482 | - _elgg_services()->systemMessages->saveRegisters($set); |
|
482 | + _elgg_services()->systemMessages->saveRegisters($set); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | * @example documentation/events/all.php |
544 | 544 | */ |
545 | 545 | function elgg_register_event_handler($event, $object_type, $callback, $priority = 500) { |
546 | - return _elgg_services()->events->registerHandler($event, $object_type, $callback, $priority); |
|
546 | + return _elgg_services()->events->registerHandler($event, $object_type, $callback, $priority); |
|
547 | 547 | } |
548 | 548 | |
549 | 549 | /** |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | * @since 1.7 |
558 | 558 | */ |
559 | 559 | function elgg_unregister_event_handler($event, $object_type, $callback) { |
560 | - return _elgg_services()->events->unregisterHandler($event, $object_type, $callback); |
|
560 | + return _elgg_services()->events->unregisterHandler($event, $object_type, $callback); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @since 2.3 |
571 | 571 | */ |
572 | 572 | function elgg_clear_event_handlers($event, $object_type) { |
573 | - _elgg_services()->events->clearHandlers($event, $object_type); |
|
573 | + _elgg_services()->events->clearHandlers($event, $object_type); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @example documentation/examples/events/trigger.php |
608 | 608 | */ |
609 | 609 | function elgg_trigger_event($event, $object_type, $object = null) { |
610 | - return _elgg_services()->events->trigger($event, $object_type, $object); |
|
610 | + return _elgg_services()->events->trigger($event, $object_type, $object); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | * @see elgg_trigger_after_event |
629 | 629 | */ |
630 | 630 | function elgg_trigger_before_event($event, $object_type, $object = null) { |
631 | - return _elgg_services()->events->triggerBefore($event, $object_type, $object); |
|
631 | + return _elgg_services()->events->triggerBefore($event, $object_type, $object); |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | /** |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | * @see elgg_trigger_before_event |
648 | 648 | */ |
649 | 649 | function elgg_trigger_after_event($event, $object_type, $object = null) { |
650 | - return _elgg_services()->events->triggerAfter($event, $object_type, $object); |
|
650 | + return _elgg_services()->events->triggerAfter($event, $object_type, $object); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | * @see elgg_trigger_event |
665 | 665 | */ |
666 | 666 | function elgg_trigger_deprecated_event($event, $object_type, $object = null, $message = null, $version = null) { |
667 | - return _elgg_services()->events->triggerDeprecated($event, $object_type, $object, $message, $version); |
|
667 | + return _elgg_services()->events->triggerDeprecated($event, $object_type, $object, $message, $version); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | * @since 1.8.0 |
734 | 734 | */ |
735 | 735 | function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = 500) { |
736 | - return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority); |
|
736 | + return _elgg_services()->hooks->registerHandler($hook, $type, $callback, $priority); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | * @since 1.8.0 |
749 | 749 | */ |
750 | 750 | function elgg_unregister_plugin_hook_handler($hook, $entity_type, $callback) { |
751 | - _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback); |
|
751 | + _elgg_services()->hooks->unregisterHandler($hook, $entity_type, $callback); |
|
752 | 752 | } |
753 | 753 | |
754 | 754 | /** |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | * @since 2.0 |
762 | 762 | */ |
763 | 763 | function elgg_clear_plugin_hook_handlers($hook, $type) { |
764 | - _elgg_services()->hooks->clearHandlers($hook, $type); |
|
764 | + _elgg_services()->hooks->clearHandlers($hook, $type); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @since 1.8.0 |
820 | 820 | */ |
821 | 821 | function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = null) { |
822 | - return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue); |
|
822 | + return _elgg_services()->hooks->trigger($hook, $type, $params, $returnvalue); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | * @since 2.0.0 |
834 | 834 | */ |
835 | 835 | function elgg_get_ordered_hook_handlers($hook, $type) { |
836 | - return _elgg_services()->hooks->getOrderedHandlers($hook, $type); |
|
836 | + return _elgg_services()->hooks->getOrderedHandlers($hook, $type); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * @since 2.0.0 |
848 | 848 | */ |
849 | 849 | function elgg_get_ordered_event_handlers($event, $type) { |
850 | - return _elgg_services()->events->getOrderedHandlers($event, $type); |
|
850 | + return _elgg_services()->events->getOrderedHandlers($event, $type); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | /** |
@@ -868,67 +868,67 @@ discard block |
||
868 | 868 | * @access private |
869 | 869 | */ |
870 | 870 | function _elgg_php_exception_handler($exception) { |
871 | - $timestamp = time(); |
|
872 | - error_log("Exception at time $timestamp: $exception"); |
|
871 | + $timestamp = time(); |
|
872 | + error_log("Exception at time $timestamp: $exception"); |
|
873 | 873 | |
874 | - // Wipe any existing output buffer |
|
875 | - ob_end_clean(); |
|
874 | + // Wipe any existing output buffer |
|
875 | + ob_end_clean(); |
|
876 | 876 | |
877 | - // make sure the error isn't cached |
|
878 | - header("Cache-Control: no-cache, must-revalidate", true); |
|
879 | - header('Expires: Fri, 05 Feb 1982 00:00:00 -0500', true); |
|
877 | + // make sure the error isn't cached |
|
878 | + header("Cache-Control: no-cache, must-revalidate", true); |
|
879 | + header('Expires: Fri, 05 Feb 1982 00:00:00 -0500', true); |
|
880 | 880 | |
881 | - $CONFIG = _elgg_services()->config->getStorageObject(); |
|
881 | + $CONFIG = _elgg_services()->config->getStorageObject(); |
|
882 | 882 | |
883 | - try { |
|
884 | - // allow custom scripts to trigger on exception |
|
885 | - // $CONFIG->exception_include can be set locally in settings.php |
|
886 | - // value should be a system path to a file to include |
|
887 | - if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) { |
|
888 | - ob_start(); |
|
883 | + try { |
|
884 | + // allow custom scripts to trigger on exception |
|
885 | + // $CONFIG->exception_include can be set locally in settings.php |
|
886 | + // value should be a system path to a file to include |
|
887 | + if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) { |
|
888 | + ob_start(); |
|
889 | 889 | |
890 | - // don't isolate, these scripts may use the local $exception var. |
|
891 | - include $CONFIG->exception_include; |
|
890 | + // don't isolate, these scripts may use the local $exception var. |
|
891 | + include $CONFIG->exception_include; |
|
892 | 892 | |
893 | - $exception_output = ob_get_clean(); |
|
893 | + $exception_output = ob_get_clean(); |
|
894 | 894 | |
895 | - // if content is returned from the custom handler we will output |
|
896 | - // that instead of our default failsafe view |
|
897 | - if (!empty($exception_output)) { |
|
898 | - echo $exception_output; |
|
899 | - exit; |
|
900 | - } |
|
901 | - } |
|
902 | - |
|
903 | - if (elgg_is_xhr()) { |
|
904 | - elgg_set_viewtype('json'); |
|
905 | - $response = new \Symfony\Component\HttpFoundation\JsonResponse(null, 500); |
|
906 | - } else { |
|
907 | - elgg_set_viewtype('failsafe'); |
|
908 | - $response = new \Symfony\Component\HttpFoundation\Response('', 500); |
|
909 | - } |
|
910 | - |
|
911 | - if (elgg_is_admin_logged_in()) { |
|
912 | - $body = elgg_view("messages/exceptions/admin_exception", [ |
|
913 | - 'object' => $exception, |
|
914 | - 'ts' => $timestamp |
|
915 | - ]); |
|
916 | - } else { |
|
917 | - $body = elgg_view("messages/exceptions/exception", [ |
|
918 | - 'object' => $exception, |
|
919 | - 'ts' => $timestamp |
|
920 | - ]); |
|
921 | - } |
|
922 | - |
|
923 | - $response->setContent(elgg_view_page(elgg_echo('exception:title'), $body)); |
|
924 | - $response->send(); |
|
925 | - } catch (Exception $e) { |
|
926 | - $timestamp = time(); |
|
927 | - $message = $e->getMessage(); |
|
928 | - http_response_code(500); |
|
929 | - echo "Fatal error in exception handler. Check log for Exception at time $timestamp"; |
|
930 | - error_log("Exception at time $timestamp : fatal error in exception handler : $message"); |
|
931 | - } |
|
895 | + // if content is returned from the custom handler we will output |
|
896 | + // that instead of our default failsafe view |
|
897 | + if (!empty($exception_output)) { |
|
898 | + echo $exception_output; |
|
899 | + exit; |
|
900 | + } |
|
901 | + } |
|
902 | + |
|
903 | + if (elgg_is_xhr()) { |
|
904 | + elgg_set_viewtype('json'); |
|
905 | + $response = new \Symfony\Component\HttpFoundation\JsonResponse(null, 500); |
|
906 | + } else { |
|
907 | + elgg_set_viewtype('failsafe'); |
|
908 | + $response = new \Symfony\Component\HttpFoundation\Response('', 500); |
|
909 | + } |
|
910 | + |
|
911 | + if (elgg_is_admin_logged_in()) { |
|
912 | + $body = elgg_view("messages/exceptions/admin_exception", [ |
|
913 | + 'object' => $exception, |
|
914 | + 'ts' => $timestamp |
|
915 | + ]); |
|
916 | + } else { |
|
917 | + $body = elgg_view("messages/exceptions/exception", [ |
|
918 | + 'object' => $exception, |
|
919 | + 'ts' => $timestamp |
|
920 | + ]); |
|
921 | + } |
|
922 | + |
|
923 | + $response->setContent(elgg_view_page(elgg_echo('exception:title'), $body)); |
|
924 | + $response->send(); |
|
925 | + } catch (Exception $e) { |
|
926 | + $timestamp = time(); |
|
927 | + $message = $e->getMessage(); |
|
928 | + http_response_code(500); |
|
929 | + echo "Fatal error in exception handler. Check log for Exception at time $timestamp"; |
|
930 | + error_log("Exception at time $timestamp : fatal error in exception handler : $message"); |
|
931 | + } |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -956,39 +956,39 @@ discard block |
||
956 | 956 | */ |
957 | 957 | function _elgg_php_error_handler($errno, $errmsg, $filename, $linenum, $vars) { |
958 | 958 | |
959 | - $error = date("Y-m-d H:i:s (T)") . ": \"$errmsg\" in file $filename (line $linenum)"; |
|
959 | + $error = date("Y-m-d H:i:s (T)") . ": \"$errmsg\" in file $filename (line $linenum)"; |
|
960 | 960 | |
961 | - switch ($errno) { |
|
962 | - case E_USER_ERROR: |
|
963 | - if (!elgg_log("PHP: $error", 'ERROR')) { |
|
964 | - error_log("PHP ERROR: $error"); |
|
965 | - } |
|
966 | - register_error("ERROR: $error"); |
|
961 | + switch ($errno) { |
|
962 | + case E_USER_ERROR: |
|
963 | + if (!elgg_log("PHP: $error", 'ERROR')) { |
|
964 | + error_log("PHP ERROR: $error"); |
|
965 | + } |
|
966 | + register_error("ERROR: $error"); |
|
967 | 967 | |
968 | - // Since this is a fatal error, we want to stop any further execution but do so gracefully. |
|
969 | - throw new \Exception($error); |
|
970 | - break; |
|
968 | + // Since this is a fatal error, we want to stop any further execution but do so gracefully. |
|
969 | + throw new \Exception($error); |
|
970 | + break; |
|
971 | 971 | |
972 | - case E_WARNING : |
|
973 | - case E_USER_WARNING : |
|
974 | - case E_RECOVERABLE_ERROR: // (e.g. type hint violation) |
|
972 | + case E_WARNING : |
|
973 | + case E_USER_WARNING : |
|
974 | + case E_RECOVERABLE_ERROR: // (e.g. type hint violation) |
|
975 | 975 | |
976 | - // check if the error wasn't suppressed by the error control operator (@) |
|
977 | - if (error_reporting() && !elgg_log("PHP: $error", 'WARNING')) { |
|
978 | - error_log("PHP WARNING: $error"); |
|
979 | - } |
|
980 | - break; |
|
976 | + // check if the error wasn't suppressed by the error control operator (@) |
|
977 | + if (error_reporting() && !elgg_log("PHP: $error", 'WARNING')) { |
|
978 | + error_log("PHP WARNING: $error"); |
|
979 | + } |
|
980 | + break; |
|
981 | 981 | |
982 | - default: |
|
983 | - $CONFIG = _elgg_services()->config->getStorageObject(); |
|
984 | - if (isset($CONFIG->debug) && $CONFIG->debug === 'NOTICE') { |
|
985 | - if (!elgg_log("PHP (errno $errno): $error", 'NOTICE')) { |
|
986 | - error_log("PHP NOTICE: $error"); |
|
987 | - } |
|
988 | - } |
|
989 | - } |
|
982 | + default: |
|
983 | + $CONFIG = _elgg_services()->config->getStorageObject(); |
|
984 | + if (isset($CONFIG->debug) && $CONFIG->debug === 'NOTICE') { |
|
985 | + if (!elgg_log("PHP (errno $errno): $error", 'NOTICE')) { |
|
986 | + error_log("PHP NOTICE: $error"); |
|
987 | + } |
|
988 | + } |
|
989 | + } |
|
990 | 990 | |
991 | - return true; |
|
991 | + return true; |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | |
@@ -1010,19 +1010,19 @@ discard block |
||
1010 | 1010 | * @since 1.7.0 |
1011 | 1011 | */ |
1012 | 1012 | function elgg_log($message, $level = 'NOTICE') { |
1013 | - static $levels = [ |
|
1014 | - 'INFO' => 200, |
|
1015 | - 'NOTICE' => 250, |
|
1016 | - 'WARNING' => 300, |
|
1017 | - 'ERROR' => 400, |
|
1018 | - ]; |
|
1013 | + static $levels = [ |
|
1014 | + 'INFO' => 200, |
|
1015 | + 'NOTICE' => 250, |
|
1016 | + 'WARNING' => 300, |
|
1017 | + 'ERROR' => 400, |
|
1018 | + ]; |
|
1019 | 1019 | |
1020 | - if (!isset($levels[$level])) { |
|
1021 | - throw new \InvalidArgumentException("Invalid \$level value"); |
|
1022 | - } |
|
1020 | + if (!isset($levels[$level])) { |
|
1021 | + throw new \InvalidArgumentException("Invalid \$level value"); |
|
1022 | + } |
|
1023 | 1023 | |
1024 | - $level = $levels[$level]; |
|
1025 | - return _elgg_services()->logger->log($message, $level); |
|
1024 | + $level = $levels[$level]; |
|
1025 | + return _elgg_services()->logger->log($message, $level); |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | /** |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | * @since 1.7.0 |
1041 | 1041 | */ |
1042 | 1042 | function elgg_dump($value, $to_screen = true) { |
1043 | - _elgg_services()->logger->dump($value, $to_screen); |
|
1043 | + _elgg_services()->logger->dump($value, $to_screen); |
|
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
@@ -1052,17 +1052,17 @@ discard block |
||
1052 | 1052 | * @since 1.9 |
1053 | 1053 | */ |
1054 | 1054 | function elgg_get_version($human_readable = false) { |
1055 | - static $version, $release; |
|
1055 | + static $version, $release; |
|
1056 | 1056 | |
1057 | - if (!isset($version) || !isset($release)) { |
|
1058 | - $path = \Elgg\Application::elggDir()->getPath('version.php'); |
|
1059 | - if (!is_file($path)) { |
|
1060 | - return false; |
|
1061 | - } |
|
1062 | - include $path; |
|
1063 | - } |
|
1057 | + if (!isset($version) || !isset($release)) { |
|
1058 | + $path = \Elgg\Application::elggDir()->getPath('version.php'); |
|
1059 | + if (!is_file($path)) { |
|
1060 | + return false; |
|
1061 | + } |
|
1062 | + include $path; |
|
1063 | + } |
|
1064 | 1064 | |
1065 | - return $human_readable ? $release : $version; |
|
1065 | + return $human_readable ? $release : $version; |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | /** |
@@ -1079,8 +1079,8 @@ discard block |
||
1079 | 1079 | * @since 1.7.0 |
1080 | 1080 | */ |
1081 | 1081 | function elgg_deprecated_notice($msg, $dep_version, $backtrace_level = 1) { |
1082 | - $backtrace_level += 1; |
|
1083 | - return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level); |
|
1082 | + $backtrace_level += 1; |
|
1083 | + return _elgg_services()->deprecation->sendNotice($msg, $dep_version, $backtrace_level); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
@@ -1097,21 +1097,21 @@ discard block |
||
1097 | 1097 | * @since 1.7.0 |
1098 | 1098 | */ |
1099 | 1099 | function elgg_http_build_url(array $parts, $html_encode = true) { |
1100 | - // build only what's given to us. |
|
1101 | - $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : ''; |
|
1102 | - $host = isset($parts['host']) ? "{$parts['host']}" : ''; |
|
1103 | - $port = isset($parts['port']) ? ":{$parts['port']}" : ''; |
|
1104 | - $path = isset($parts['path']) ? "{$parts['path']}" : ''; |
|
1105 | - $query = isset($parts['query']) ? "?{$parts['query']}" : ''; |
|
1106 | - $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : ''; |
|
1100 | + // build only what's given to us. |
|
1101 | + $scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : ''; |
|
1102 | + $host = isset($parts['host']) ? "{$parts['host']}" : ''; |
|
1103 | + $port = isset($parts['port']) ? ":{$parts['port']}" : ''; |
|
1104 | + $path = isset($parts['path']) ? "{$parts['path']}" : ''; |
|
1105 | + $query = isset($parts['query']) ? "?{$parts['query']}" : ''; |
|
1106 | + $fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : ''; |
|
1107 | 1107 | |
1108 | - $string = $scheme . $host . $port . $path . $query . $fragment; |
|
1108 | + $string = $scheme . $host . $port . $path . $query . $fragment; |
|
1109 | 1109 | |
1110 | - if ($html_encode) { |
|
1111 | - return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false); |
|
1112 | - } else { |
|
1113 | - return $string; |
|
1114 | - } |
|
1110 | + if ($html_encode) { |
|
1111 | + return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false); |
|
1112 | + } else { |
|
1113 | + return $string; |
|
1114 | + } |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | /** |
@@ -1132,26 +1132,26 @@ discard block |
||
1132 | 1132 | * @since 1.7.0 |
1133 | 1133 | */ |
1134 | 1134 | function elgg_add_action_tokens_to_url($url, $html_encode = false) { |
1135 | - $url = elgg_normalize_url($url); |
|
1136 | - $components = parse_url($url); |
|
1135 | + $url = elgg_normalize_url($url); |
|
1136 | + $components = parse_url($url); |
|
1137 | 1137 | |
1138 | - if (isset($components['query'])) { |
|
1139 | - $query = elgg_parse_str($components['query']); |
|
1140 | - } else { |
|
1141 | - $query = []; |
|
1142 | - } |
|
1138 | + if (isset($components['query'])) { |
|
1139 | + $query = elgg_parse_str($components['query']); |
|
1140 | + } else { |
|
1141 | + $query = []; |
|
1142 | + } |
|
1143 | 1143 | |
1144 | - if (isset($query['__elgg_ts']) && isset($query['__elgg_token'])) { |
|
1145 | - return $url; |
|
1146 | - } |
|
1144 | + if (isset($query['__elgg_ts']) && isset($query['__elgg_token'])) { |
|
1145 | + return $url; |
|
1146 | + } |
|
1147 | 1147 | |
1148 | - // append action tokens to the existing query |
|
1149 | - $query['__elgg_ts'] = time(); |
|
1150 | - $query['__elgg_token'] = generate_action_token($query['__elgg_ts']); |
|
1151 | - $components['query'] = http_build_query($query); |
|
1148 | + // append action tokens to the existing query |
|
1149 | + $query['__elgg_ts'] = time(); |
|
1150 | + $query['__elgg_token'] = generate_action_token($query['__elgg_ts']); |
|
1151 | + $components['query'] = http_build_query($query); |
|
1152 | 1152 | |
1153 | - // rebuild the full url |
|
1154 | - return elgg_http_build_url($components, $html_encode); |
|
1153 | + // rebuild the full url |
|
1154 | + return elgg_http_build_url($components, $html_encode); |
|
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | /** |
@@ -1166,7 +1166,7 @@ discard block |
||
1166 | 1166 | * @since 1.7.0 |
1167 | 1167 | */ |
1168 | 1168 | function elgg_http_remove_url_query_element($url, $element) { |
1169 | - return elgg_http_add_url_query_elements($url, [$element => null]); |
|
1169 | + return elgg_http_add_url_query_elements($url, [$element => null]); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | 1172 | /** |
@@ -1180,33 +1180,33 @@ discard block |
||
1180 | 1180 | * @since 1.7.0 |
1181 | 1181 | */ |
1182 | 1182 | function elgg_http_add_url_query_elements($url, array $elements) { |
1183 | - $url_array = parse_url($url); |
|
1183 | + $url_array = parse_url($url); |
|
1184 | 1184 | |
1185 | - if (isset($url_array['query'])) { |
|
1186 | - $query = elgg_parse_str($url_array['query']); |
|
1187 | - } else { |
|
1188 | - $query = []; |
|
1189 | - } |
|
1185 | + if (isset($url_array['query'])) { |
|
1186 | + $query = elgg_parse_str($url_array['query']); |
|
1187 | + } else { |
|
1188 | + $query = []; |
|
1189 | + } |
|
1190 | 1190 | |
1191 | - foreach ($elements as $k => $v) { |
|
1192 | - if ($v === null) { |
|
1193 | - unset($query[$k]); |
|
1194 | - } else { |
|
1195 | - $query[$k] = $v; |
|
1196 | - } |
|
1197 | - } |
|
1191 | + foreach ($elements as $k => $v) { |
|
1192 | + if ($v === null) { |
|
1193 | + unset($query[$k]); |
|
1194 | + } else { |
|
1195 | + $query[$k] = $v; |
|
1196 | + } |
|
1197 | + } |
|
1198 | 1198 | |
1199 | - // why check path? A: if no path, this may be a relative URL like "?foo=1". In this case, |
|
1200 | - // the output "" would be interpreted the current URL, so in this case we *must* set |
|
1201 | - // a query to make sure elements are removed. |
|
1202 | - if ($query || empty($url_array['path'])) { |
|
1203 | - $url_array['query'] = http_build_query($query); |
|
1204 | - } else { |
|
1205 | - unset($url_array['query']); |
|
1206 | - } |
|
1207 | - $string = elgg_http_build_url($url_array, false); |
|
1199 | + // why check path? A: if no path, this may be a relative URL like "?foo=1". In this case, |
|
1200 | + // the output "" would be interpreted the current URL, so in this case we *must* set |
|
1201 | + // a query to make sure elements are removed. |
|
1202 | + if ($query || empty($url_array['path'])) { |
|
1203 | + $url_array['query'] = http_build_query($query); |
|
1204 | + } else { |
|
1205 | + unset($url_array['query']); |
|
1206 | + } |
|
1207 | + $string = elgg_http_build_url($url_array, false); |
|
1208 | 1208 | |
1209 | - return $string; |
|
1209 | + return $string; |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | /** |
@@ -1224,83 +1224,83 @@ discard block |
||
1224 | 1224 | * @since 1.8.0 |
1225 | 1225 | */ |
1226 | 1226 | function elgg_http_url_is_identical($url1, $url2, $ignore_params = ['offset', 'limit']) { |
1227 | - $url1 = elgg_normalize_url($url1); |
|
1228 | - $url2 = elgg_normalize_url($url2); |
|
1229 | - |
|
1230 | - // @todo - should probably do something with relative URLs |
|
1231 | - |
|
1232 | - if ($url1 == $url2) { |
|
1233 | - return true; |
|
1234 | - } |
|
1235 | - |
|
1236 | - $url1_info = parse_url($url1); |
|
1237 | - $url2_info = parse_url($url2); |
|
1238 | - |
|
1239 | - if (isset($url1_info['path'])) { |
|
1240 | - $url1_info['path'] = trim($url1_info['path'], '/'); |
|
1241 | - } |
|
1242 | - if (isset($url2_info['path'])) { |
|
1243 | - $url2_info['path'] = trim($url2_info['path'], '/'); |
|
1244 | - } |
|
1245 | - |
|
1246 | - // compare basic bits |
|
1247 | - $parts = ['scheme', 'host', 'path']; |
|
1248 | - |
|
1249 | - foreach ($parts as $part) { |
|
1250 | - if ((isset($url1_info[$part]) && isset($url2_info[$part])) |
|
1251 | - && $url1_info[$part] != $url2_info[$part]) { |
|
1252 | - return false; |
|
1253 | - } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { |
|
1254 | - return false; |
|
1255 | - } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { |
|
1256 | - return false; |
|
1257 | - } |
|
1258 | - } |
|
1259 | - |
|
1260 | - // quick compare of get params |
|
1261 | - if (isset($url1_info['query']) && isset($url2_info['query']) |
|
1262 | - && $url1_info['query'] == $url2_info['query']) { |
|
1263 | - return true; |
|
1264 | - } |
|
1265 | - |
|
1266 | - // compare get params that might be out of order |
|
1267 | - $url1_params = []; |
|
1268 | - $url2_params = []; |
|
1269 | - |
|
1270 | - if (isset($url1_info['query'])) { |
|
1271 | - if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { |
|
1272 | - $url1_params = elgg_parse_str($url1_info['query']); |
|
1273 | - } |
|
1274 | - } |
|
1275 | - |
|
1276 | - if (isset($url2_info['query'])) { |
|
1277 | - if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { |
|
1278 | - $url2_params = elgg_parse_str($url2_info['query']); |
|
1279 | - } |
|
1280 | - } |
|
1281 | - |
|
1282 | - // drop ignored params |
|
1283 | - foreach ($ignore_params as $param) { |
|
1284 | - if (isset($url1_params[$param])) { |
|
1285 | - unset($url1_params[$param]); |
|
1286 | - } |
|
1287 | - if (isset($url2_params[$param])) { |
|
1288 | - unset($url2_params[$param]); |
|
1289 | - } |
|
1290 | - } |
|
1291 | - |
|
1292 | - // array_diff_assoc only returns the items in arr1 that aren't in arrN |
|
1293 | - // but not the items that ARE in arrN but NOT in arr1 |
|
1294 | - // if arr1 is an empty array, this function will return 0 no matter what. |
|
1295 | - // since we only care if they're different and not how different, |
|
1296 | - // add the results together to get a non-zero (ie, different) result |
|
1297 | - $diff_count = count(array_diff_assoc($url1_params, $url2_params)); |
|
1298 | - $diff_count += count(array_diff_assoc($url2_params, $url1_params)); |
|
1299 | - if ($diff_count > 0) { |
|
1300 | - return false; |
|
1301 | - } |
|
1302 | - |
|
1303 | - return true; |
|
1227 | + $url1 = elgg_normalize_url($url1); |
|
1228 | + $url2 = elgg_normalize_url($url2); |
|
1229 | + |
|
1230 | + // @todo - should probably do something with relative URLs |
|
1231 | + |
|
1232 | + if ($url1 == $url2) { |
|
1233 | + return true; |
|
1234 | + } |
|
1235 | + |
|
1236 | + $url1_info = parse_url($url1); |
|
1237 | + $url2_info = parse_url($url2); |
|
1238 | + |
|
1239 | + if (isset($url1_info['path'])) { |
|
1240 | + $url1_info['path'] = trim($url1_info['path'], '/'); |
|
1241 | + } |
|
1242 | + if (isset($url2_info['path'])) { |
|
1243 | + $url2_info['path'] = trim($url2_info['path'], '/'); |
|
1244 | + } |
|
1245 | + |
|
1246 | + // compare basic bits |
|
1247 | + $parts = ['scheme', 'host', 'path']; |
|
1248 | + |
|
1249 | + foreach ($parts as $part) { |
|
1250 | + if ((isset($url1_info[$part]) && isset($url2_info[$part])) |
|
1251 | + && $url1_info[$part] != $url2_info[$part]) { |
|
1252 | + return false; |
|
1253 | + } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) { |
|
1254 | + return false; |
|
1255 | + } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) { |
|
1256 | + return false; |
|
1257 | + } |
|
1258 | + } |
|
1259 | + |
|
1260 | + // quick compare of get params |
|
1261 | + if (isset($url1_info['query']) && isset($url2_info['query']) |
|
1262 | + && $url1_info['query'] == $url2_info['query']) { |
|
1263 | + return true; |
|
1264 | + } |
|
1265 | + |
|
1266 | + // compare get params that might be out of order |
|
1267 | + $url1_params = []; |
|
1268 | + $url2_params = []; |
|
1269 | + |
|
1270 | + if (isset($url1_info['query'])) { |
|
1271 | + if ($url1_info['query'] = html_entity_decode($url1_info['query'])) { |
|
1272 | + $url1_params = elgg_parse_str($url1_info['query']); |
|
1273 | + } |
|
1274 | + } |
|
1275 | + |
|
1276 | + if (isset($url2_info['query'])) { |
|
1277 | + if ($url2_info['query'] = html_entity_decode($url2_info['query'])) { |
|
1278 | + $url2_params = elgg_parse_str($url2_info['query']); |
|
1279 | + } |
|
1280 | + } |
|
1281 | + |
|
1282 | + // drop ignored params |
|
1283 | + foreach ($ignore_params as $param) { |
|
1284 | + if (isset($url1_params[$param])) { |
|
1285 | + unset($url1_params[$param]); |
|
1286 | + } |
|
1287 | + if (isset($url2_params[$param])) { |
|
1288 | + unset($url2_params[$param]); |
|
1289 | + } |
|
1290 | + } |
|
1291 | + |
|
1292 | + // array_diff_assoc only returns the items in arr1 that aren't in arrN |
|
1293 | + // but not the items that ARE in arrN but NOT in arr1 |
|
1294 | + // if arr1 is an empty array, this function will return 0 no matter what. |
|
1295 | + // since we only care if they're different and not how different, |
|
1296 | + // add the results together to get a non-zero (ie, different) result |
|
1297 | + $diff_count = count(array_diff_assoc($url1_params, $url2_params)); |
|
1298 | + $diff_count += count(array_diff_assoc($url2_params, $url1_params)); |
|
1299 | + if ($diff_count > 0) { |
|
1300 | + return false; |
|
1301 | + } |
|
1302 | + |
|
1303 | + return true; |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | /** |
@@ -1315,7 +1315,7 @@ discard block |
||
1315 | 1315 | * @return string |
1316 | 1316 | */ |
1317 | 1317 | function elgg_http_get_signed_url($url, $expires = false) { |
1318 | - return _elgg_services()->urlSigner->sign($url, $expires); |
|
1318 | + return _elgg_services()->urlSigner->sign($url, $expires); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | /** |
@@ -1325,7 +1325,7 @@ discard block |
||
1325 | 1325 | * @return bool |
1326 | 1326 | */ |
1327 | 1327 | function elgg_http_validate_signed_url($url) { |
1328 | - return _elgg_services()->urlSigner->isValid($url); |
|
1328 | + return _elgg_services()->urlSigner->isValid($url); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | 1331 | /** |
@@ -1334,10 +1334,10 @@ discard block |
||
1334 | 1334 | * @return void |
1335 | 1335 | */ |
1336 | 1336 | function elgg_signed_request_gatekeeper() { |
1337 | - if (!elgg_http_validate_signed_url(current_page_url())) { |
|
1338 | - register_error(elgg_echo('invalid_request_signature')); |
|
1339 | - forward('', '403'); |
|
1340 | - } |
|
1337 | + if (!elgg_http_validate_signed_url(current_page_url())) { |
|
1338 | + register_error(elgg_echo('invalid_request_signature')); |
|
1339 | + forward('', '403'); |
|
1340 | + } |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | /** |
@@ -1356,15 +1356,15 @@ discard block |
||
1356 | 1356 | * @since 1.8.0 |
1357 | 1357 | */ |
1358 | 1358 | function elgg_extract($key, $array, $default = null, $strict = true) { |
1359 | - if (!is_array($array)) { |
|
1360 | - return $default; |
|
1361 | - } |
|
1359 | + if (!is_array($array)) { |
|
1360 | + return $default; |
|
1361 | + } |
|
1362 | 1362 | |
1363 | - if ($strict) { |
|
1364 | - return (isset($array[$key])) ? $array[$key] : $default; |
|
1365 | - } else { |
|
1366 | - return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
|
1367 | - } |
|
1363 | + if ($strict) { |
|
1364 | + return (isset($array[$key])) ? $array[$key] : $default; |
|
1365 | + } else { |
|
1366 | + return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
|
1367 | + } |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | /** |
@@ -1377,13 +1377,13 @@ discard block |
||
1377 | 1377 | * @since 2.3.0 |
1378 | 1378 | */ |
1379 | 1379 | function elgg_extract_class(array $array, $existing = []) { |
1380 | - $existing = empty($existing) ? [] : (array) $existing; |
|
1380 | + $existing = empty($existing) ? [] : (array) $existing; |
|
1381 | 1381 | |
1382 | - $merge = (array) elgg_extract('class', $array, []); |
|
1382 | + $merge = (array) elgg_extract('class', $array, []); |
|
1383 | 1383 | |
1384 | - array_splice($existing, count($existing), 0, $merge); |
|
1384 | + array_splice($existing, count($existing), 0, $merge); |
|
1385 | 1385 | |
1386 | - return array_values(array_unique($existing)); |
|
1386 | + return array_values(array_unique($existing)); |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | /** |
@@ -1408,17 +1408,17 @@ discard block |
||
1408 | 1408 | */ |
1409 | 1409 | function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort_type = SORT_LOCALE_STRING) { |
1410 | 1410 | |
1411 | - $sort = []; |
|
1411 | + $sort = []; |
|
1412 | 1412 | |
1413 | - foreach ($array as $v) { |
|
1414 | - if (isset($v[$element])) { |
|
1415 | - $sort[] = strtolower($v[$element]); |
|
1416 | - } else { |
|
1417 | - $sort[] = null; |
|
1418 | - } |
|
1419 | - }; |
|
1413 | + foreach ($array as $v) { |
|
1414 | + if (isset($v[$element])) { |
|
1415 | + $sort[] = strtolower($v[$element]); |
|
1416 | + } else { |
|
1417 | + $sort[] = null; |
|
1418 | + } |
|
1419 | + }; |
|
1420 | 1420 | |
1421 | - return array_multisort($sort, $sort_order, $sort_type, $array); |
|
1421 | + return array_multisort($sort, $sort_order, $sort_type, $array); |
|
1422 | 1422 | } |
1423 | 1423 | |
1424 | 1424 | /** |
@@ -1432,12 +1432,12 @@ discard block |
||
1432 | 1432 | * @return bool Depending on whether it's on or off |
1433 | 1433 | */ |
1434 | 1434 | function ini_get_bool($ini_get_arg) { |
1435 | - $temp = strtolower(ini_get($ini_get_arg)); |
|
1435 | + $temp = strtolower(ini_get($ini_get_arg)); |
|
1436 | 1436 | |
1437 | - if ($temp == '1' || $temp == 'on' || $temp == 'true') { |
|
1438 | - return true; |
|
1439 | - } |
|
1440 | - return false; |
|
1437 | + if ($temp == '1' || $temp == 'on' || $temp == 'true') { |
|
1438 | + return true; |
|
1439 | + } |
|
1440 | + return false; |
|
1441 | 1441 | } |
1442 | 1442 | |
1443 | 1443 | /** |
@@ -1452,24 +1452,24 @@ discard block |
||
1452 | 1452 | * @link http://www.php.net/manual/en/function.ini-get.php |
1453 | 1453 | */ |
1454 | 1454 | function elgg_get_ini_setting_in_bytes($setting) { |
1455 | - // retrieve INI setting |
|
1456 | - $val = ini_get($setting); |
|
1455 | + // retrieve INI setting |
|
1456 | + $val = ini_get($setting); |
|
1457 | 1457 | |
1458 | - // convert INI setting when shorthand notation is used |
|
1459 | - $last = strtolower($val[strlen($val) - 1]); |
|
1460 | - switch ($last) { |
|
1461 | - case 'g': |
|
1462 | - $val *= 1024; |
|
1463 | - // fallthrough intentional |
|
1464 | - case 'm': |
|
1465 | - $val *= 1024; |
|
1466 | - // fallthrough intentional |
|
1467 | - case 'k': |
|
1468 | - $val *= 1024; |
|
1469 | - } |
|
1458 | + // convert INI setting when shorthand notation is used |
|
1459 | + $last = strtolower($val[strlen($val) - 1]); |
|
1460 | + switch ($last) { |
|
1461 | + case 'g': |
|
1462 | + $val *= 1024; |
|
1463 | + // fallthrough intentional |
|
1464 | + case 'm': |
|
1465 | + $val *= 1024; |
|
1466 | + // fallthrough intentional |
|
1467 | + case 'k': |
|
1468 | + $val *= 1024; |
|
1469 | + } |
|
1470 | 1470 | |
1471 | - // return byte value |
|
1472 | - return $val; |
|
1471 | + // return byte value |
|
1472 | + return $val; |
|
1473 | 1473 | } |
1474 | 1474 | |
1475 | 1475 | /** |
@@ -1483,11 +1483,11 @@ discard block |
||
1483 | 1483 | * @todo This is used once in metadata.php. Use a lambda function instead. |
1484 | 1484 | */ |
1485 | 1485 | function is_not_null($string) { |
1486 | - if (($string === '') || ($string === false) || ($string === null)) { |
|
1487 | - return false; |
|
1488 | - } |
|
1486 | + if (($string === '') || ($string === false) || ($string === null)) { |
|
1487 | + return false; |
|
1488 | + } |
|
1489 | 1489 | |
1490 | - return true; |
|
1490 | + return true; |
|
1491 | 1491 | } |
1492 | 1492 | |
1493 | 1493 | /** |
@@ -1504,26 +1504,26 @@ discard block |
||
1504 | 1504 | * @access private |
1505 | 1505 | */ |
1506 | 1506 | function _elgg_normalize_plural_options_array($options, $singulars) { |
1507 | - foreach ($singulars as $singular) { |
|
1508 | - $plural = $singular . 's'; |
|
1507 | + foreach ($singulars as $singular) { |
|
1508 | + $plural = $singular . 's'; |
|
1509 | 1509 | |
1510 | - if (array_key_exists($singular, $options)) { |
|
1511 | - if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { |
|
1512 | - $options[$plural] = $options[$singular]; |
|
1513 | - } else { |
|
1514 | - // Test for array refs #2641 |
|
1515 | - if (!is_array($options[$singular])) { |
|
1516 | - $options[$plural] = [$options[$singular]]; |
|
1517 | - } else { |
|
1518 | - $options[$plural] = $options[$singular]; |
|
1519 | - } |
|
1520 | - } |
|
1521 | - } |
|
1510 | + if (array_key_exists($singular, $options)) { |
|
1511 | + if ($options[$singular] === ELGG_ENTITIES_ANY_VALUE) { |
|
1512 | + $options[$plural] = $options[$singular]; |
|
1513 | + } else { |
|
1514 | + // Test for array refs #2641 |
|
1515 | + if (!is_array($options[$singular])) { |
|
1516 | + $options[$plural] = [$options[$singular]]; |
|
1517 | + } else { |
|
1518 | + $options[$plural] = $options[$singular]; |
|
1519 | + } |
|
1520 | + } |
|
1521 | + } |
|
1522 | 1522 | |
1523 | - unset($options[$singular]); |
|
1524 | - } |
|
1523 | + unset($options[$singular]); |
|
1524 | + } |
|
1525 | 1525 | |
1526 | - return $options; |
|
1526 | + return $options; |
|
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | /** |
@@ -1544,23 +1544,23 @@ discard block |
||
1544 | 1544 | * @access private |
1545 | 1545 | */ |
1546 | 1546 | function _elgg_shutdown_hook() { |
1547 | - try { |
|
1548 | - _elgg_services()->logger->setDisplay(false); |
|
1549 | - elgg_trigger_event('shutdown', 'system'); |
|
1547 | + try { |
|
1548 | + _elgg_services()->logger->setDisplay(false); |
|
1549 | + elgg_trigger_event('shutdown', 'system'); |
|
1550 | 1550 | |
1551 | - $time = (float) (microtime(true) - $GLOBALS['START_MICROTIME']); |
|
1552 | - $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI'); |
|
1553 | - // demoted to NOTICE from DEBUG so javascript is not corrupted |
|
1554 | - elgg_log("Page {$uri} generated in $time seconds", 'INFO'); |
|
1555 | - } catch (Exception $e) { |
|
1556 | - $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. '; |
|
1557 | - $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})"; |
|
1558 | - error_log($message); |
|
1559 | - error_log("Exception trace stack: {$e->getTraceAsString()}"); |
|
1560 | - } |
|
1551 | + $time = (float) (microtime(true) - $GLOBALS['START_MICROTIME']); |
|
1552 | + $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI'); |
|
1553 | + // demoted to NOTICE from DEBUG so javascript is not corrupted |
|
1554 | + elgg_log("Page {$uri} generated in $time seconds", 'INFO'); |
|
1555 | + } catch (Exception $e) { |
|
1556 | + $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. '; |
|
1557 | + $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})"; |
|
1558 | + error_log($message); |
|
1559 | + error_log("Exception trace stack: {$e->getTraceAsString()}"); |
|
1560 | + } |
|
1561 | 1561 | |
1562 | - // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657 |
|
1563 | - session_write_close(); |
|
1562 | + // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657 |
|
1563 | + session_write_close(); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | /** |
@@ -1577,71 +1577,71 @@ discard block |
||
1577 | 1577 | * @access private |
1578 | 1578 | */ |
1579 | 1579 | function _elgg_ajax_page_handler($segments) { |
1580 | - elgg_ajax_gatekeeper(); |
|
1581 | - |
|
1582 | - if (count($segments) < 2) { |
|
1583 | - return false; |
|
1584 | - } |
|
1585 | - |
|
1586 | - if ($segments[0] === 'view' || $segments[0] === 'form') { |
|
1587 | - if ($segments[0] === 'view') { |
|
1588 | - // ignore 'view/' |
|
1589 | - $view = implode('/', array_slice($segments, 1)); |
|
1590 | - } else { |
|
1591 | - // form views start with "forms", not "form" |
|
1592 | - $view = 'forms/' . implode('/', array_slice($segments, 1)); |
|
1593 | - } |
|
1594 | - |
|
1595 | - $ajax_api = _elgg_services()->ajax; |
|
1596 | - $allowed_views = $ajax_api->getViews(); |
|
1580 | + elgg_ajax_gatekeeper(); |
|
1581 | + |
|
1582 | + if (count($segments) < 2) { |
|
1583 | + return false; |
|
1584 | + } |
|
1585 | + |
|
1586 | + if ($segments[0] === 'view' || $segments[0] === 'form') { |
|
1587 | + if ($segments[0] === 'view') { |
|
1588 | + // ignore 'view/' |
|
1589 | + $view = implode('/', array_slice($segments, 1)); |
|
1590 | + } else { |
|
1591 | + // form views start with "forms", not "form" |
|
1592 | + $view = 'forms/' . implode('/', array_slice($segments, 1)); |
|
1593 | + } |
|
1594 | + |
|
1595 | + $ajax_api = _elgg_services()->ajax; |
|
1596 | + $allowed_views = $ajax_api->getViews(); |
|
1597 | 1597 | |
1598 | - // cacheable views are always allowed |
|
1599 | - if (!in_array($view, $allowed_views) && !_elgg_services()->views->isCacheableView($view)) { |
|
1600 | - return elgg_error_response("Ajax view '$view' was not registered", REFERRER, ELGG_HTTP_FORBIDDEN); |
|
1601 | - } |
|
1602 | - |
|
1603 | - // pull out GET parameters through filter |
|
1604 | - $vars = []; |
|
1605 | - foreach (_elgg_services()->request->query->keys() as $name) { |
|
1606 | - $vars[$name] = get_input($name); |
|
1607 | - } |
|
1608 | - |
|
1609 | - if (isset($vars['guid'])) { |
|
1610 | - $vars['entity'] = get_entity($vars['guid']); |
|
1611 | - } |
|
1612 | - |
|
1613 | - $content_type = ''; |
|
1614 | - if ($segments[0] === 'view') { |
|
1615 | - $output = elgg_view($view, $vars); |
|
1616 | - |
|
1617 | - // Try to guess the mime-type |
|
1618 | - switch ($segments[1]) { |
|
1619 | - case "js": |
|
1620 | - $content_type = 'text/javascript;charset=utf-8'; |
|
1621 | - break; |
|
1622 | - case "css": |
|
1623 | - $content_type = 'text/css;charset=utf-8'; |
|
1624 | - break; |
|
1625 | - default : |
|
1626 | - if (_elgg_services()->views->isCacheableView($view)) { |
|
1627 | - $file = _elgg_services()->views->findViewFile($view, elgg_get_viewtype()); |
|
1628 | - $content_type = (new \Elgg\Filesystem\MimeTypeDetector())->getType($file, 'text/html'); |
|
1629 | - } |
|
1630 | - break; |
|
1631 | - } |
|
1632 | - } else { |
|
1633 | - $action = implode('/', array_slice($segments, 1)); |
|
1634 | - $output = elgg_view_form($action, [], $vars); |
|
1635 | - } |
|
1636 | - |
|
1637 | - if ($content_type) { |
|
1638 | - elgg_set_http_header("Content-Type: $content_type"); |
|
1639 | - } |
|
1598 | + // cacheable views are always allowed |
|
1599 | + if (!in_array($view, $allowed_views) && !_elgg_services()->views->isCacheableView($view)) { |
|
1600 | + return elgg_error_response("Ajax view '$view' was not registered", REFERRER, ELGG_HTTP_FORBIDDEN); |
|
1601 | + } |
|
1602 | + |
|
1603 | + // pull out GET parameters through filter |
|
1604 | + $vars = []; |
|
1605 | + foreach (_elgg_services()->request->query->keys() as $name) { |
|
1606 | + $vars[$name] = get_input($name); |
|
1607 | + } |
|
1608 | + |
|
1609 | + if (isset($vars['guid'])) { |
|
1610 | + $vars['entity'] = get_entity($vars['guid']); |
|
1611 | + } |
|
1612 | + |
|
1613 | + $content_type = ''; |
|
1614 | + if ($segments[0] === 'view') { |
|
1615 | + $output = elgg_view($view, $vars); |
|
1616 | + |
|
1617 | + // Try to guess the mime-type |
|
1618 | + switch ($segments[1]) { |
|
1619 | + case "js": |
|
1620 | + $content_type = 'text/javascript;charset=utf-8'; |
|
1621 | + break; |
|
1622 | + case "css": |
|
1623 | + $content_type = 'text/css;charset=utf-8'; |
|
1624 | + break; |
|
1625 | + default : |
|
1626 | + if (_elgg_services()->views->isCacheableView($view)) { |
|
1627 | + $file = _elgg_services()->views->findViewFile($view, elgg_get_viewtype()); |
|
1628 | + $content_type = (new \Elgg\Filesystem\MimeTypeDetector())->getType($file, 'text/html'); |
|
1629 | + } |
|
1630 | + break; |
|
1631 | + } |
|
1632 | + } else { |
|
1633 | + $action = implode('/', array_slice($segments, 1)); |
|
1634 | + $output = elgg_view_form($action, [], $vars); |
|
1635 | + } |
|
1636 | + |
|
1637 | + if ($content_type) { |
|
1638 | + elgg_set_http_header("Content-Type: $content_type"); |
|
1639 | + } |
|
1640 | 1640 | |
1641 | - return elgg_ok_response($output); |
|
1642 | - } |
|
1641 | + return elgg_ok_response($output); |
|
1642 | + } |
|
1643 | 1643 | |
1644 | - return false; |
|
1644 | + return false; |
|
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | /** |
@@ -1653,16 +1653,16 @@ discard block |
||
1653 | 1653 | * @since 1.10 |
1654 | 1654 | */ |
1655 | 1655 | function _elgg_favicon_page_handler($segments) { |
1656 | - header("HTTP/1.1 404 Not Found", true, 404); |
|
1656 | + header("HTTP/1.1 404 Not Found", true, 404); |
|
1657 | 1657 | |
1658 | - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1659 | - header("Pragma: public", true); |
|
1660 | - header("Cache-Control: public", true); |
|
1658 | + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+1 week")), true); |
|
1659 | + header("Pragma: public", true); |
|
1660 | + header("Cache-Control: public", true); |
|
1661 | 1661 | |
1662 | - header('Content-Type: image/x-icon'); |
|
1663 | - echo elgg_view('graphics/favicon.ico'); |
|
1662 | + header('Content-Type: image/x-icon'); |
|
1663 | + echo elgg_view('graphics/favicon.ico'); |
|
1664 | 1664 | |
1665 | - return true; |
|
1665 | + return true; |
|
1666 | 1666 | } |
1667 | 1667 | |
1668 | 1668 | /** |
@@ -1677,18 +1677,18 @@ discard block |
||
1677 | 1677 | * @access private |
1678 | 1678 | */ |
1679 | 1679 | function _elgg_sql_reverse_order_by_clause($order_by) { |
1680 | - $order_by = strtolower($order_by); |
|
1680 | + $order_by = strtolower($order_by); |
|
1681 | 1681 | |
1682 | - if (strpos($order_by, ' asc') !== false) { |
|
1683 | - $return = str_replace(' asc', ' desc', $order_by); |
|
1684 | - } elseif (strpos($order_by, ' desc') !== false) { |
|
1685 | - $return = str_replace(' desc', ' asc', $order_by); |
|
1686 | - } else { |
|
1687 | - // no order specified, so default to desc since mysql defaults to asc |
|
1688 | - $return = $order_by . ' desc'; |
|
1689 | - } |
|
1682 | + if (strpos($order_by, ' asc') !== false) { |
|
1683 | + $return = str_replace(' asc', ' desc', $order_by); |
|
1684 | + } elseif (strpos($order_by, ' desc') !== false) { |
|
1685 | + $return = str_replace(' desc', ' asc', $order_by); |
|
1686 | + } else { |
|
1687 | + // no order specified, so default to desc since mysql defaults to asc |
|
1688 | + $return = $order_by . ' desc'; |
|
1689 | + } |
|
1690 | 1690 | |
1691 | - return $return; |
|
1691 | + return $return; |
|
1692 | 1692 | } |
1693 | 1693 | |
1694 | 1694 | /** |
@@ -1703,8 +1703,8 @@ discard block |
||
1703 | 1703 | * @access private |
1704 | 1704 | */ |
1705 | 1705 | function elgg_batch_enable_callback($object) { |
1706 | - // our db functions return the number of rows affected... |
|
1707 | - return $object->enable() ? true : false; |
|
1706 | + // our db functions return the number of rows affected... |
|
1707 | + return $object->enable() ? true : false; |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | 1710 | /** |
@@ -1717,8 +1717,8 @@ discard block |
||
1717 | 1717 | * @access private |
1718 | 1718 | */ |
1719 | 1719 | function elgg_batch_disable_callback($object) { |
1720 | - // our db functions return the number of rows affected... |
|
1721 | - return $object->disable() ? true : false; |
|
1720 | + // our db functions return the number of rows affected... |
|
1721 | + return $object->disable() ? true : false; |
|
1722 | 1722 | } |
1723 | 1723 | |
1724 | 1724 | /** |
@@ -1731,8 +1731,8 @@ discard block |
||
1731 | 1731 | * @access private |
1732 | 1732 | */ |
1733 | 1733 | function elgg_batch_delete_callback($object) { |
1734 | - // our db functions return the number of rows affected... |
|
1735 | - return $object->delete() ? true : false; |
|
1734 | + // our db functions return the number of rows affected... |
|
1735 | + return $object->delete() ? true : false; |
|
1736 | 1736 | } |
1737 | 1737 | |
1738 | 1738 | /** |
@@ -1745,50 +1745,50 @@ discard block |
||
1745 | 1745 | * @access private |
1746 | 1746 | */ |
1747 | 1747 | function _elgg_is_valid_options_for_batch_operation($options, $type) { |
1748 | - if (!$options || !is_array($options)) { |
|
1749 | - return false; |
|
1750 | - } |
|
1748 | + if (!$options || !is_array($options)) { |
|
1749 | + return false; |
|
1750 | + } |
|
1751 | 1751 | |
1752 | - // at least one of these is required. |
|
1753 | - $required = [ |
|
1754 | - // generic restraints |
|
1755 | - 'guid', 'guids' |
|
1756 | - ]; |
|
1752 | + // at least one of these is required. |
|
1753 | + $required = [ |
|
1754 | + // generic restraints |
|
1755 | + 'guid', 'guids' |
|
1756 | + ]; |
|
1757 | 1757 | |
1758 | - switch ($type) { |
|
1759 | - case 'metadata': |
|
1760 | - $metadata_required = [ |
|
1761 | - 'metadata_owner_guid', 'metadata_owner_guids', |
|
1762 | - 'metadata_name', 'metadata_names', |
|
1763 | - 'metadata_value', 'metadata_values' |
|
1764 | - ]; |
|
1758 | + switch ($type) { |
|
1759 | + case 'metadata': |
|
1760 | + $metadata_required = [ |
|
1761 | + 'metadata_owner_guid', 'metadata_owner_guids', |
|
1762 | + 'metadata_name', 'metadata_names', |
|
1763 | + 'metadata_value', 'metadata_values' |
|
1764 | + ]; |
|
1765 | 1765 | |
1766 | - $required = array_merge($required, $metadata_required); |
|
1767 | - break; |
|
1766 | + $required = array_merge($required, $metadata_required); |
|
1767 | + break; |
|
1768 | 1768 | |
1769 | - case 'annotations': |
|
1770 | - case 'annotation': |
|
1771 | - $annotations_required = [ |
|
1772 | - 'annotation_owner_guid', 'annotation_owner_guids', |
|
1773 | - 'annotation_name', 'annotation_names', |
|
1774 | - 'annotation_value', 'annotation_values' |
|
1775 | - ]; |
|
1769 | + case 'annotations': |
|
1770 | + case 'annotation': |
|
1771 | + $annotations_required = [ |
|
1772 | + 'annotation_owner_guid', 'annotation_owner_guids', |
|
1773 | + 'annotation_name', 'annotation_names', |
|
1774 | + 'annotation_value', 'annotation_values' |
|
1775 | + ]; |
|
1776 | 1776 | |
1777 | - $required = array_merge($required, $annotations_required); |
|
1778 | - break; |
|
1777 | + $required = array_merge($required, $annotations_required); |
|
1778 | + break; |
|
1779 | 1779 | |
1780 | - default: |
|
1781 | - return false; |
|
1782 | - } |
|
1780 | + default: |
|
1781 | + return false; |
|
1782 | + } |
|
1783 | 1783 | |
1784 | - foreach ($required as $key) { |
|
1785 | - // check that it exists and is something. |
|
1786 | - if (isset($options[$key]) && $options[$key]) { |
|
1787 | - return true; |
|
1788 | - } |
|
1789 | - } |
|
1784 | + foreach ($required as $key) { |
|
1785 | + // check that it exists and is something. |
|
1786 | + if (isset($options[$key]) && $options[$key]) { |
|
1787 | + return true; |
|
1788 | + } |
|
1789 | + } |
|
1790 | 1790 | |
1791 | - return false; |
|
1791 | + return false; |
|
1792 | 1792 | } |
1793 | 1793 | |
1794 | 1794 | /** |
@@ -1798,7 +1798,7 @@ discard block |
||
1798 | 1798 | * @access private |
1799 | 1799 | */ |
1800 | 1800 | function _elgg_walled_garden_index() { |
1801 | - return elgg_ok_response(elgg_view_resource('walled_garden')); |
|
1801 | + return elgg_ok_response(elgg_view_resource('walled_garden')); |
|
1802 | 1802 | } |
1803 | 1803 | |
1804 | 1804 | /** |
@@ -1815,26 +1815,26 @@ discard block |
||
1815 | 1815 | * @access private |
1816 | 1816 | */ |
1817 | 1817 | function _elgg_walled_garden_init() { |
1818 | - if (!elgg_get_config('walled_garden')) { |
|
1819 | - return; |
|
1820 | - } |
|
1818 | + if (!elgg_get_config('walled_garden')) { |
|
1819 | + return; |
|
1820 | + } |
|
1821 | 1821 | |
1822 | - elgg_register_css('elgg.walled_garden', elgg_get_simplecache_url('walled_garden.css')); |
|
1822 | + elgg_register_css('elgg.walled_garden', elgg_get_simplecache_url('walled_garden.css')); |
|
1823 | 1823 | |
1824 | - elgg_register_plugin_hook_handler('register', 'menu:walled_garden', '_elgg_walled_garden_menu'); |
|
1824 | + elgg_register_plugin_hook_handler('register', 'menu:walled_garden', '_elgg_walled_garden_menu'); |
|
1825 | 1825 | |
1826 | - elgg_register_page_handler('walled_garden', '_elgg_walled_garden_ajax_handler'); |
|
1826 | + elgg_register_page_handler('walled_garden', '_elgg_walled_garden_ajax_handler'); |
|
1827 | 1827 | |
1828 | - if (elgg_get_config('default_access') == ACCESS_PUBLIC) { |
|
1829 | - elgg_set_config('default_access', ACCESS_LOGGED_IN); |
|
1830 | - } |
|
1828 | + if (elgg_get_config('default_access') == ACCESS_PUBLIC) { |
|
1829 | + elgg_set_config('default_access', ACCESS_LOGGED_IN); |
|
1830 | + } |
|
1831 | 1831 | |
1832 | - elgg_register_plugin_hook_handler('access:collections:write', 'all', '_elgg_walled_garden_remove_public_access', 9999); |
|
1832 | + elgg_register_plugin_hook_handler('access:collections:write', 'all', '_elgg_walled_garden_remove_public_access', 9999); |
|
1833 | 1833 | |
1834 | - if (!elgg_is_logged_in()) { |
|
1835 | - // override the front page |
|
1836 | - elgg_register_page_handler('', '_elgg_walled_garden_index'); |
|
1837 | - } |
|
1834 | + if (!elgg_is_logged_in()) { |
|
1835 | + // override the front page |
|
1836 | + elgg_register_page_handler('', '_elgg_walled_garden_index'); |
|
1837 | + } |
|
1838 | 1838 | } |
1839 | 1839 | |
1840 | 1840 | /** |
@@ -1851,18 +1851,18 @@ discard block |
||
1851 | 1851 | */ |
1852 | 1852 | function _elgg_walled_garden_menu($hook, $type, $return_value, $params) { |
1853 | 1853 | |
1854 | - if (current_page_url() === elgg_get_site_url()) { |
|
1855 | - return; |
|
1856 | - } |
|
1854 | + if (current_page_url() === elgg_get_site_url()) { |
|
1855 | + return; |
|
1856 | + } |
|
1857 | 1857 | |
1858 | - $return_value[] = \ElggMenuItem::factory([ |
|
1859 | - 'name' => 'home', |
|
1860 | - 'href' => '/', |
|
1861 | - 'text' => elgg_echo('walled_garden:home'), |
|
1862 | - 'priority' => 10, |
|
1863 | - ]); |
|
1858 | + $return_value[] = \ElggMenuItem::factory([ |
|
1859 | + 'name' => 'home', |
|
1860 | + 'href' => '/', |
|
1861 | + 'text' => elgg_echo('walled_garden:home'), |
|
1862 | + 'priority' => 10, |
|
1863 | + ]); |
|
1864 | 1864 | |
1865 | - return $return_value; |
|
1865 | + return $return_value; |
|
1866 | 1866 | } |
1867 | 1867 | |
1868 | 1868 | /** |
@@ -1875,10 +1875,10 @@ discard block |
||
1875 | 1875 | * @access private |
1876 | 1876 | */ |
1877 | 1877 | function _elgg_walled_garden_remove_public_access($hook, $type, $accesses) { |
1878 | - if (isset($accesses[ACCESS_PUBLIC])) { |
|
1879 | - unset($accesses[ACCESS_PUBLIC]); |
|
1880 | - } |
|
1881 | - return $accesses; |
|
1878 | + if (isset($accesses[ACCESS_PUBLIC])) { |
|
1879 | + unset($accesses[ACCESS_PUBLIC]); |
|
1880 | + } |
|
1881 | + return $accesses; |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | 1884 | /** |
@@ -1891,36 +1891,36 @@ discard block |
||
1891 | 1891 | * @access private |
1892 | 1892 | */ |
1893 | 1893 | function _elgg_init() { |
1894 | - elgg_register_action('entity/delete'); |
|
1895 | - elgg_register_action('comment/save'); |
|
1896 | - elgg_register_action('comment/delete'); |
|
1894 | + elgg_register_action('entity/delete'); |
|
1895 | + elgg_register_action('comment/save'); |
|
1896 | + elgg_register_action('comment/delete'); |
|
1897 | 1897 | |
1898 | - elgg_register_page_handler('ajax', '_elgg_ajax_page_handler'); |
|
1899 | - elgg_register_page_handler('favicon.ico', '_elgg_favicon_page_handler'); |
|
1898 | + elgg_register_page_handler('ajax', '_elgg_ajax_page_handler'); |
|
1899 | + elgg_register_page_handler('favicon.ico', '_elgg_favicon_page_handler'); |
|
1900 | 1900 | |
1901 | - elgg_register_page_handler('manifest.json', function() { |
|
1902 | - $site = elgg_get_site_entity(); |
|
1903 | - $resource = new \Elgg\Http\WebAppManifestResource($site); |
|
1904 | - header('Content-Type: application/json;charset=utf-8'); |
|
1905 | - echo json_encode($resource->get()); |
|
1906 | - return true; |
|
1907 | - }); |
|
1901 | + elgg_register_page_handler('manifest.json', function() { |
|
1902 | + $site = elgg_get_site_entity(); |
|
1903 | + $resource = new \Elgg\Http\WebAppManifestResource($site); |
|
1904 | + header('Content-Type: application/json;charset=utf-8'); |
|
1905 | + echo json_encode($resource->get()); |
|
1906 | + return true; |
|
1907 | + }); |
|
1908 | 1908 | |
1909 | - elgg_register_plugin_hook_handler('head', 'page', function($hook, $type, array $result) { |
|
1910 | - $result['links']['manifest'] = [ |
|
1911 | - 'rel' => 'manifest', |
|
1912 | - 'href' => elgg_normalize_url('/manifest.json'), |
|
1913 | - ]; |
|
1909 | + elgg_register_plugin_hook_handler('head', 'page', function($hook, $type, array $result) { |
|
1910 | + $result['links']['manifest'] = [ |
|
1911 | + 'rel' => 'manifest', |
|
1912 | + 'href' => elgg_normalize_url('/manifest.json'), |
|
1913 | + ]; |
|
1914 | 1914 | |
1915 | - return $result; |
|
1916 | - }); |
|
1915 | + return $result; |
|
1916 | + }); |
|
1917 | 1917 | |
1918 | - if (_elgg_services()->config->getVolatile('enable_profiling')) { |
|
1919 | - /** |
|
1920 | - * @see \Elgg\Profiler::handlePageOutput |
|
1921 | - */ |
|
1922 | - elgg_register_plugin_hook_handler('output', 'page', [\Elgg\Profiler::class, 'handlePageOutput'], 999); |
|
1923 | - } |
|
1918 | + if (_elgg_services()->config->getVolatile('enable_profiling')) { |
|
1919 | + /** |
|
1920 | + * @see \Elgg\Profiler::handlePageOutput |
|
1921 | + */ |
|
1922 | + elgg_register_plugin_hook_handler('output', 'page', [\Elgg\Profiler::class, 'handlePageOutput'], 999); |
|
1923 | + } |
|
1924 | 1924 | } |
1925 | 1925 | |
1926 | 1926 | /** |
@@ -1936,12 +1936,12 @@ discard block |
||
1936 | 1936 | * @access private |
1937 | 1937 | */ |
1938 | 1938 | function _elgg_api_test($hook, $type, $value, $params) { |
1939 | - global $CONFIG; |
|
1940 | - $value[] = $CONFIG->path . 'engine/tests/ElggTravisInstallTest.php'; |
|
1941 | - $value[] = $CONFIG->path . 'engine/tests/ElggCoreHelpersTest.php'; |
|
1942 | - $value[] = $CONFIG->path . 'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1943 | - $value[] = $CONFIG->path . 'engine/tests/ElggBatchTest.php'; |
|
1944 | - return $value; |
|
1939 | + global $CONFIG; |
|
1940 | + $value[] = $CONFIG->path . 'engine/tests/ElggTravisInstallTest.php'; |
|
1941 | + $value[] = $CONFIG->path . 'engine/tests/ElggCoreHelpersTest.php'; |
|
1942 | + $value[] = $CONFIG->path . 'engine/tests/ElggCoreRegressionBugsTest.php'; |
|
1943 | + $value[] = $CONFIG->path . 'engine/tests/ElggBatchTest.php'; |
|
1944 | + return $value; |
|
1945 | 1945 | } |
1946 | 1946 | |
1947 | 1947 | /**#@+ |
@@ -2066,12 +2066,12 @@ discard block |
||
2066 | 2066 | define('ELGG_JSON_ENCODING', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT); |
2067 | 2067 | |
2068 | 2068 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
2069 | - $events->registerHandler('cache:flush', 'system', function () { |
|
2070 | - _elgg_services()->boot->invalidateCache(); |
|
2071 | - }); |
|
2069 | + $events->registerHandler('cache:flush', 'system', function () { |
|
2070 | + _elgg_services()->boot->invalidateCache(); |
|
2071 | + }); |
|
2072 | 2072 | |
2073 | - $events->registerHandler('init', 'system', '_elgg_init'); |
|
2074 | - $events->registerHandler('init', 'system', '_elgg_walled_garden_init', 1000); |
|
2073 | + $events->registerHandler('init', 'system', '_elgg_init'); |
|
2074 | + $events->registerHandler('init', 'system', '_elgg_walled_garden_init', 1000); |
|
2075 | 2075 | |
2076 | - $hooks->registerHandler('unit_test', 'system', '_elgg_api_test'); |
|
2076 | + $hooks->registerHandler('unit_test', 'system', '_elgg_api_test'); |
|
2077 | 2077 | }; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * Save the plugin object. Make sure required values exist. |
94 | 94 | * |
95 | 95 | * @see \ElggObject::save() |
96 | - * @return bool |
|
96 | + * @return boolean|null |
|
97 | 97 | */ |
98 | 98 | public function save() { |
99 | 99 | // own by the current site so users can be deleted without affecting plugins |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Sets the location of this plugin. |
182 | 182 | * |
183 | 183 | * @param string $id The path to the plugin's dir. |
184 | - * @return bool |
|
184 | + * @return string |
|
185 | 185 | */ |
186 | 186 | public function setID($id) { |
187 | 187 | return $this->attributes['title'] = $id; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | /** |
221 | 221 | * Sets the priority of the plugin |
222 | 222 | * |
223 | - * @param mixed $priority The priority to set. One of +1, -1, first, last, or a number. |
|
223 | + * @param string $priority The priority to set. One of +1, -1, first, last, or a number. |
|
224 | 224 | * If given a number, this will displace all plugins at that number |
225 | 225 | * and set their priorities +1 |
226 | 226 | * @return bool |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | * |
387 | 387 | * @param string $name The setting name to remove |
388 | 388 | * |
389 | - * @return bool |
|
389 | + * @return integer |
|
390 | 390 | */ |
391 | 391 | public function unsetSetting($name) { |
392 | 392 | return remove_private_setting($this->guid, $name); |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * @todo Should be a better way to do this without dropping to raw SQL. |
399 | 399 | * @todo If we could namespace the plugin settings this would be cleaner. |
400 | 400 | * @todo this shouldn't work because ps_prefix will be empty string |
401 | - * @return bool |
|
401 | + * @return integer |
|
402 | 402 | */ |
403 | 403 | public function unsetAllSettings() { |
404 | 404 | _elgg_services()->pluginSettingsCache->clear($this->guid); |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | * @param string $value The setting value |
494 | 494 | * @param int $user_guid The user GUID |
495 | 495 | * |
496 | - * @return mixed The new setting ID or false |
|
496 | + * @return boolean The new setting ID or false |
|
497 | 497 | */ |
498 | 498 | public function setUserSetting($name, $value, $user_guid = 0) { |
499 | 499 | $user_guid = (int) $user_guid; |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @todo fix that |
561 | 561 | * |
562 | 562 | * @param int $user_guid The user GUID to remove user settings. |
563 | - * @return bool |
|
563 | + * @return integer |
|
564 | 564 | */ |
565 | 565 | public function unsetAllUserSettings($user_guid) { |
566 | 566 | $db = $this->getDatabase(); |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * Use {@link removeAllUserSettings()} if you just want to remove |
580 | 580 | * settings for a single user. |
581 | 581 | * |
582 | - * @return bool |
|
582 | + * @return integer |
|
583 | 583 | */ |
584 | 584 | public function unsetAllUsersSettings() { |
585 | 585 | $db = $this->getDatabase(); |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | * Start the plugin. |
813 | 813 | * |
814 | 814 | * @param int $flags Start flags for the plugin. See the constants in lib/plugins.php for details. |
815 | - * @return true |
|
815 | + * @return boolean |
|
816 | 816 | * @throws PluginException |
817 | 817 | */ |
818 | 818 | public function start($flags) { |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | * Registers the plugin's languages |
1041 | 1041 | * |
1042 | 1042 | * @throws PluginException |
1043 | - * @return true |
|
1043 | + * @return boolean |
|
1044 | 1044 | */ |
1045 | 1045 | protected function registerLanguages() { |
1046 | 1046 | return _elgg_services()->translator->registerPluginTranslations($this->path); |
@@ -1050,7 +1050,7 @@ discard block |
||
1050 | 1050 | * Registers the plugin's classes |
1051 | 1051 | * |
1052 | 1052 | * @throws PluginException |
1053 | - * @return true |
|
1053 | + * @return boolean |
|
1054 | 1054 | */ |
1055 | 1055 | protected function registerClasses() { |
1056 | 1056 | $classes_path = "$this->path/classes"; |
@@ -12,1214 +12,1214 @@ |
||
12 | 12 | * @subpackage Plugins.Settings |
13 | 13 | */ |
14 | 14 | class ElggPlugin extends \ElggObject { |
15 | - private $package; |
|
16 | - private $manifest; |
|
17 | - |
|
18 | - /** |
|
19 | - * Data from static config file. null if not yet read. |
|
20 | - * |
|
21 | - * @var array|null |
|
22 | - */ |
|
23 | - private $static_config; |
|
24 | - |
|
25 | - private $path; |
|
26 | - private $errorMsg = ''; |
|
27 | - |
|
28 | - /** |
|
29 | - * Set subtype to 'plugin' |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - protected function initializeAttributes() { |
|
34 | - parent::initializeAttributes(); |
|
35 | - |
|
36 | - $this->attributes['subtype'] = "plugin"; |
|
37 | - |
|
38 | - // plugins must be public. |
|
39 | - $this->access_id = ACCESS_PUBLIC; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Creates a new plugin from path |
|
44 | - * |
|
45 | - * @note Internal: also supports database objects |
|
46 | - * |
|
47 | - * @warning Unlike other \ElggEntity objects, you cannot null instantiate |
|
48 | - * \ElggPlugin. You must provide the path to the plugin directory. |
|
49 | - * |
|
50 | - * @param string $path The absolute path of the plugin |
|
51 | - * |
|
52 | - * @throws PluginException |
|
53 | - */ |
|
54 | - public function __construct($path) { |
|
55 | - if (!$path) { |
|
56 | - throw new \PluginException("ElggPlugin cannot be null instantiated. You must pass a full path."); |
|
57 | - } |
|
58 | - |
|
59 | - if (is_object($path)) { |
|
60 | - // database object |
|
61 | - parent::__construct($path); |
|
62 | - $this->path = _elgg_services()->config->getPluginsPath() . $this->getID(); |
|
63 | - _elgg_cache_plugin_by_id($this); |
|
64 | - return; |
|
65 | - } |
|
66 | - |
|
67 | - if (is_numeric($path)) { |
|
68 | - // guid |
|
69 | - // @todo plugins with directory names of '12345' |
|
70 | - throw new \InvalidArgumentException('$path cannot be a GUID'); |
|
71 | - } |
|
72 | - |
|
73 | - $this->initializeAttributes(); |
|
74 | - |
|
75 | - // path checking is done in the package |
|
76 | - $path = sanitise_filepath($path); |
|
77 | - $this->path = $path; |
|
78 | - $path_parts = explode('/', rtrim($path, '/')); |
|
79 | - $plugin_id = array_pop($path_parts); |
|
80 | - $this->title = $plugin_id; |
|
81 | - |
|
82 | - // check if we're loading an existing plugin |
|
83 | - $existing_plugin = elgg_get_plugin_from_id($plugin_id); |
|
84 | - |
|
85 | - if ($existing_plugin) { |
|
86 | - $this->load($existing_plugin->guid); |
|
87 | - } |
|
88 | - |
|
89 | - _elgg_cache_plugin_by_id($this); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Save the plugin object. Make sure required values exist. |
|
94 | - * |
|
95 | - * @see \ElggObject::save() |
|
96 | - * @return bool |
|
97 | - */ |
|
98 | - public function save() { |
|
99 | - // own by the current site so users can be deleted without affecting plugins |
|
100 | - $site = elgg_get_site_entity(); |
|
101 | - $this->attributes['owner_guid'] = $site->guid; |
|
102 | - $this->attributes['container_guid'] = $site->guid; |
|
15 | + private $package; |
|
16 | + private $manifest; |
|
17 | + |
|
18 | + /** |
|
19 | + * Data from static config file. null if not yet read. |
|
20 | + * |
|
21 | + * @var array|null |
|
22 | + */ |
|
23 | + private $static_config; |
|
24 | + |
|
25 | + private $path; |
|
26 | + private $errorMsg = ''; |
|
27 | + |
|
28 | + /** |
|
29 | + * Set subtype to 'plugin' |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + protected function initializeAttributes() { |
|
34 | + parent::initializeAttributes(); |
|
35 | + |
|
36 | + $this->attributes['subtype'] = "plugin"; |
|
37 | + |
|
38 | + // plugins must be public. |
|
39 | + $this->access_id = ACCESS_PUBLIC; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Creates a new plugin from path |
|
44 | + * |
|
45 | + * @note Internal: also supports database objects |
|
46 | + * |
|
47 | + * @warning Unlike other \ElggEntity objects, you cannot null instantiate |
|
48 | + * \ElggPlugin. You must provide the path to the plugin directory. |
|
49 | + * |
|
50 | + * @param string $path The absolute path of the plugin |
|
51 | + * |
|
52 | + * @throws PluginException |
|
53 | + */ |
|
54 | + public function __construct($path) { |
|
55 | + if (!$path) { |
|
56 | + throw new \PluginException("ElggPlugin cannot be null instantiated. You must pass a full path."); |
|
57 | + } |
|
58 | + |
|
59 | + if (is_object($path)) { |
|
60 | + // database object |
|
61 | + parent::__construct($path); |
|
62 | + $this->path = _elgg_services()->config->getPluginsPath() . $this->getID(); |
|
63 | + _elgg_cache_plugin_by_id($this); |
|
64 | + return; |
|
65 | + } |
|
66 | + |
|
67 | + if (is_numeric($path)) { |
|
68 | + // guid |
|
69 | + // @todo plugins with directory names of '12345' |
|
70 | + throw new \InvalidArgumentException('$path cannot be a GUID'); |
|
71 | + } |
|
72 | + |
|
73 | + $this->initializeAttributes(); |
|
74 | + |
|
75 | + // path checking is done in the package |
|
76 | + $path = sanitise_filepath($path); |
|
77 | + $this->path = $path; |
|
78 | + $path_parts = explode('/', rtrim($path, '/')); |
|
79 | + $plugin_id = array_pop($path_parts); |
|
80 | + $this->title = $plugin_id; |
|
81 | + |
|
82 | + // check if we're loading an existing plugin |
|
83 | + $existing_plugin = elgg_get_plugin_from_id($plugin_id); |
|
84 | + |
|
85 | + if ($existing_plugin) { |
|
86 | + $this->load($existing_plugin->guid); |
|
87 | + } |
|
88 | + |
|
89 | + _elgg_cache_plugin_by_id($this); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Save the plugin object. Make sure required values exist. |
|
94 | + * |
|
95 | + * @see \ElggObject::save() |
|
96 | + * @return bool |
|
97 | + */ |
|
98 | + public function save() { |
|
99 | + // own by the current site so users can be deleted without affecting plugins |
|
100 | + $site = elgg_get_site_entity(); |
|
101 | + $this->attributes['owner_guid'] = $site->guid; |
|
102 | + $this->attributes['container_guid'] = $site->guid; |
|
103 | 103 | |
104 | - if (parent::save()) { |
|
105 | - // make sure we have a priority |
|
106 | - $priority = $this->getPriority(); |
|
107 | - if ($priority === false || $priority === null) { |
|
108 | - return $this->setPriority('last'); |
|
109 | - } |
|
110 | - } else { |
|
111 | - return false; |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - // Plugin ID and path |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns the ID (dir name) of this plugin |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getID() { |
|
124 | - return $this->title; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the manifest's name if available, otherwise the ID. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - * @since 1.8.1 |
|
132 | - */ |
|
133 | - public function getFriendlyName() { |
|
134 | - $manifest = $this->getManifest(); |
|
135 | - if ($manifest) { |
|
136 | - return $manifest->getName(); |
|
137 | - } |
|
138 | - |
|
139 | - return $this->getID(); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Returns the plugin's full path with trailing slash. |
|
144 | - * |
|
145 | - * @return string |
|
146 | - */ |
|
147 | - public function getPath() { |
|
148 | - return sanitise_filepath($this->path); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Get a value from the plugins's static config file. |
|
153 | - * |
|
154 | - * @note If the system cache is on, Elgg APIs should not call this on every request. |
|
155 | - * |
|
156 | - * @param string $key Config key |
|
157 | - * @param mixed $default Value returned if missing |
|
158 | - * |
|
159 | - * @return mixed |
|
160 | - * @throws PluginException |
|
161 | - * @access private |
|
162 | - * @internal For Elgg internal use only |
|
163 | - */ |
|
164 | - public function getStaticConfig($key, $default = null) { |
|
165 | - if ($this->static_config === null) { |
|
166 | - $this->static_config = []; |
|
167 | - |
|
168 | - if ($this->canReadFile(ElggPluginPackage::STATIC_CONFIG_FILENAME)) { |
|
169 | - $this->static_config = $this->includeFile(ElggPluginPackage::STATIC_CONFIG_FILENAME); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - if (array_key_exists($key, $this->static_config)) { |
|
174 | - return $this->static_config[$key]; |
|
175 | - } else { |
|
176 | - return $default; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Sets the location of this plugin. |
|
182 | - * |
|
183 | - * @param string $id The path to the plugin's dir. |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function setID($id) { |
|
187 | - return $this->attributes['title'] = $id; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Returns an array of available markdown files for this plugin |
|
192 | - * |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - public function getAvailableTextFiles() { |
|
196 | - $filenames = $this->getPackage()->getTextFilenames(); |
|
197 | - |
|
198 | - $files = []; |
|
199 | - foreach ($filenames as $filename) { |
|
200 | - if ($this->canReadFile($filename)) { |
|
201 | - $files[$filename] = "$this->path/$filename"; |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - return $files; |
|
206 | - } |
|
207 | - |
|
208 | - // Load Priority |
|
209 | - |
|
210 | - /** |
|
211 | - * Gets the plugin's load priority. |
|
212 | - * |
|
213 | - * @return int |
|
214 | - */ |
|
215 | - public function getPriority() { |
|
216 | - $name = _elgg_namespace_plugin_private_setting('internal', 'priority'); |
|
217 | - return $this->$name; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Sets the priority of the plugin |
|
222 | - * |
|
223 | - * @param mixed $priority The priority to set. One of +1, -1, first, last, or a number. |
|
224 | - * If given a number, this will displace all plugins at that number |
|
225 | - * and set their priorities +1 |
|
226 | - * @return bool |
|
227 | - */ |
|
228 | - public function setPriority($priority) { |
|
229 | - if (!$this->guid) { |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - $db = $this->getDatabase(); |
|
234 | - $name = _elgg_namespace_plugin_private_setting('internal', 'priority'); |
|
235 | - // if no priority assume a priority of 1 |
|
236 | - $old_priority = (int) $this->getPriority(); |
|
237 | - $old_priority = (!$old_priority) ? 1 : $old_priority; |
|
238 | - $max_priority = _elgg_get_max_plugin_priority(); |
|
239 | - |
|
240 | - // can't use switch here because it's not strict and |
|
241 | - // php evaluates +1 == 1 |
|
242 | - if ($priority === '+1') { |
|
243 | - $priority = $old_priority + 1; |
|
244 | - } elseif ($priority === '-1') { |
|
245 | - $priority = $old_priority - 1; |
|
246 | - } elseif ($priority === 'first') { |
|
247 | - $priority = 1; |
|
248 | - } elseif ($priority === 'last') { |
|
249 | - $priority = $max_priority; |
|
250 | - } |
|
251 | - |
|
252 | - // should be a number by now |
|
253 | - if ($priority > 0) { |
|
254 | - if (!is_numeric($priority)) { |
|
255 | - return false; |
|
256 | - } |
|
257 | - |
|
258 | - // there's nothing above the max. |
|
259 | - if ($priority > $max_priority) { |
|
260 | - $priority = $max_priority; |
|
261 | - } |
|
262 | - |
|
263 | - // there's nothing below 1. |
|
264 | - if ($priority < 1) { |
|
265 | - $priority = 1; |
|
266 | - } |
|
267 | - |
|
268 | - if ($priority > $old_priority) { |
|
269 | - $op = '-'; |
|
270 | - $where = "CAST(value as unsigned) BETWEEN $old_priority AND $priority"; |
|
271 | - } else { |
|
272 | - $op = '+'; |
|
273 | - $where = "CAST(value as unsigned) BETWEEN $priority AND $old_priority"; |
|
274 | - } |
|
275 | - |
|
276 | - // displace the ones affected by this change |
|
277 | - $q = "UPDATE {$db->prefix}private_settings |
|
104 | + if (parent::save()) { |
|
105 | + // make sure we have a priority |
|
106 | + $priority = $this->getPriority(); |
|
107 | + if ($priority === false || $priority === null) { |
|
108 | + return $this->setPriority('last'); |
|
109 | + } |
|
110 | + } else { |
|
111 | + return false; |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + // Plugin ID and path |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns the ID (dir name) of this plugin |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getID() { |
|
124 | + return $this->title; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the manifest's name if available, otherwise the ID. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + * @since 1.8.1 |
|
132 | + */ |
|
133 | + public function getFriendlyName() { |
|
134 | + $manifest = $this->getManifest(); |
|
135 | + if ($manifest) { |
|
136 | + return $manifest->getName(); |
|
137 | + } |
|
138 | + |
|
139 | + return $this->getID(); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Returns the plugin's full path with trailing slash. |
|
144 | + * |
|
145 | + * @return string |
|
146 | + */ |
|
147 | + public function getPath() { |
|
148 | + return sanitise_filepath($this->path); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Get a value from the plugins's static config file. |
|
153 | + * |
|
154 | + * @note If the system cache is on, Elgg APIs should not call this on every request. |
|
155 | + * |
|
156 | + * @param string $key Config key |
|
157 | + * @param mixed $default Value returned if missing |
|
158 | + * |
|
159 | + * @return mixed |
|
160 | + * @throws PluginException |
|
161 | + * @access private |
|
162 | + * @internal For Elgg internal use only |
|
163 | + */ |
|
164 | + public function getStaticConfig($key, $default = null) { |
|
165 | + if ($this->static_config === null) { |
|
166 | + $this->static_config = []; |
|
167 | + |
|
168 | + if ($this->canReadFile(ElggPluginPackage::STATIC_CONFIG_FILENAME)) { |
|
169 | + $this->static_config = $this->includeFile(ElggPluginPackage::STATIC_CONFIG_FILENAME); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + if (array_key_exists($key, $this->static_config)) { |
|
174 | + return $this->static_config[$key]; |
|
175 | + } else { |
|
176 | + return $default; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Sets the location of this plugin. |
|
182 | + * |
|
183 | + * @param string $id The path to the plugin's dir. |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function setID($id) { |
|
187 | + return $this->attributes['title'] = $id; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Returns an array of available markdown files for this plugin |
|
192 | + * |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + public function getAvailableTextFiles() { |
|
196 | + $filenames = $this->getPackage()->getTextFilenames(); |
|
197 | + |
|
198 | + $files = []; |
|
199 | + foreach ($filenames as $filename) { |
|
200 | + if ($this->canReadFile($filename)) { |
|
201 | + $files[$filename] = "$this->path/$filename"; |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + return $files; |
|
206 | + } |
|
207 | + |
|
208 | + // Load Priority |
|
209 | + |
|
210 | + /** |
|
211 | + * Gets the plugin's load priority. |
|
212 | + * |
|
213 | + * @return int |
|
214 | + */ |
|
215 | + public function getPriority() { |
|
216 | + $name = _elgg_namespace_plugin_private_setting('internal', 'priority'); |
|
217 | + return $this->$name; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Sets the priority of the plugin |
|
222 | + * |
|
223 | + * @param mixed $priority The priority to set. One of +1, -1, first, last, or a number. |
|
224 | + * If given a number, this will displace all plugins at that number |
|
225 | + * and set their priorities +1 |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | + public function setPriority($priority) { |
|
229 | + if (!$this->guid) { |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + $db = $this->getDatabase(); |
|
234 | + $name = _elgg_namespace_plugin_private_setting('internal', 'priority'); |
|
235 | + // if no priority assume a priority of 1 |
|
236 | + $old_priority = (int) $this->getPriority(); |
|
237 | + $old_priority = (!$old_priority) ? 1 : $old_priority; |
|
238 | + $max_priority = _elgg_get_max_plugin_priority(); |
|
239 | + |
|
240 | + // can't use switch here because it's not strict and |
|
241 | + // php evaluates +1 == 1 |
|
242 | + if ($priority === '+1') { |
|
243 | + $priority = $old_priority + 1; |
|
244 | + } elseif ($priority === '-1') { |
|
245 | + $priority = $old_priority - 1; |
|
246 | + } elseif ($priority === 'first') { |
|
247 | + $priority = 1; |
|
248 | + } elseif ($priority === 'last') { |
|
249 | + $priority = $max_priority; |
|
250 | + } |
|
251 | + |
|
252 | + // should be a number by now |
|
253 | + if ($priority > 0) { |
|
254 | + if (!is_numeric($priority)) { |
|
255 | + return false; |
|
256 | + } |
|
257 | + |
|
258 | + // there's nothing above the max. |
|
259 | + if ($priority > $max_priority) { |
|
260 | + $priority = $max_priority; |
|
261 | + } |
|
262 | + |
|
263 | + // there's nothing below 1. |
|
264 | + if ($priority < 1) { |
|
265 | + $priority = 1; |
|
266 | + } |
|
267 | + |
|
268 | + if ($priority > $old_priority) { |
|
269 | + $op = '-'; |
|
270 | + $where = "CAST(value as unsigned) BETWEEN $old_priority AND $priority"; |
|
271 | + } else { |
|
272 | + $op = '+'; |
|
273 | + $where = "CAST(value as unsigned) BETWEEN $priority AND $old_priority"; |
|
274 | + } |
|
275 | + |
|
276 | + // displace the ones affected by this change |
|
277 | + $q = "UPDATE {$db->prefix}private_settings |
|
278 | 278 | SET value = CAST(value as unsigned) $op 1 |
279 | 279 | WHERE entity_guid != $this->guid |
280 | 280 | AND name = '$name' |
281 | 281 | AND $where"; |
282 | 282 | |
283 | - if (!$db->updateData($q)) { |
|
284 | - return false; |
|
285 | - } |
|
286 | - |
|
287 | - // set this priority |
|
288 | - if ($this->setPrivateSetting($name, $priority)) { |
|
289 | - return true; |
|
290 | - } else { |
|
291 | - return false; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - return false; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - // Plugin settings |
|
300 | - |
|
301 | - /** |
|
302 | - * Returns a plugin setting |
|
303 | - * |
|
304 | - * @param string $name The setting name |
|
305 | - * @param mixed $default The default value to return if none is set |
|
306 | - * @return mixed |
|
307 | - */ |
|
308 | - public function getSetting($name, $default = null) { |
|
309 | - $values = $this->getAllSettings(); |
|
310 | - |
|
311 | - return elgg_extract($name, $values, $default); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Returns an array of all settings saved for this plugin. |
|
316 | - * |
|
317 | - * @note Unlike user settings, plugin settings are not namespaced. |
|
318 | - * |
|
319 | - * @return array An array of key/value pairs. |
|
320 | - */ |
|
321 | - public function getAllSettings() { |
|
283 | + if (!$db->updateData($q)) { |
|
284 | + return false; |
|
285 | + } |
|
286 | + |
|
287 | + // set this priority |
|
288 | + if ($this->setPrivateSetting($name, $priority)) { |
|
289 | + return true; |
|
290 | + } else { |
|
291 | + return false; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + return false; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + // Plugin settings |
|
300 | + |
|
301 | + /** |
|
302 | + * Returns a plugin setting |
|
303 | + * |
|
304 | + * @param string $name The setting name |
|
305 | + * @param mixed $default The default value to return if none is set |
|
306 | + * @return mixed |
|
307 | + */ |
|
308 | + public function getSetting($name, $default = null) { |
|
309 | + $values = $this->getAllSettings(); |
|
310 | + |
|
311 | + return elgg_extract($name, $values, $default); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Returns an array of all settings saved for this plugin. |
|
316 | + * |
|
317 | + * @note Unlike user settings, plugin settings are not namespaced. |
|
318 | + * |
|
319 | + * @return array An array of key/value pairs. |
|
320 | + */ |
|
321 | + public function getAllSettings() { |
|
322 | 322 | |
323 | - $defaults = $this->getStaticConfig('settings', []); |
|
324 | - $values = _elgg_services()->pluginSettingsCache->getAll($this->guid); |
|
323 | + $defaults = $this->getStaticConfig('settings', []); |
|
324 | + $values = _elgg_services()->pluginSettingsCache->getAll($this->guid); |
|
325 | 325 | |
326 | - if ($values !== null) { |
|
327 | - return array_merge($defaults, $values); |
|
328 | - } |
|
326 | + if ($values !== null) { |
|
327 | + return array_merge($defaults, $values); |
|
328 | + } |
|
329 | 329 | |
330 | - if (!$this->guid) { |
|
331 | - return false; |
|
332 | - } |
|
330 | + if (!$this->guid) { |
|
331 | + return false; |
|
332 | + } |
|
333 | 333 | |
334 | - $db_prefix = _elgg_services()->config->get('dbprefix'); |
|
335 | - // need to remove all namespaced private settings. |
|
336 | - $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
337 | - $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID()); |
|
334 | + $db_prefix = _elgg_services()->config->get('dbprefix'); |
|
335 | + // need to remove all namespaced private settings. |
|
336 | + $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
337 | + $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID()); |
|
338 | 338 | |
339 | - // Get private settings for user |
|
340 | - $q = "SELECT * FROM {$db_prefix}private_settings |
|
339 | + // Get private settings for user |
|
340 | + $q = "SELECT * FROM {$db_prefix}private_settings |
|
341 | 341 | WHERE entity_guid = $this->guid |
342 | 342 | AND name NOT LIKE '$us_prefix%' |
343 | 343 | AND name NOT LIKE '$is_prefix%'"; |
344 | 344 | |
345 | - $private_settings = $this->getDatabase()->getData($q); |
|
346 | - |
|
347 | - $return = []; |
|
348 | - |
|
349 | - if ($private_settings) { |
|
350 | - foreach ($private_settings as $setting) { |
|
351 | - $return[$setting->name] = $setting->value; |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - return array_merge($defaults, $return); |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Set a plugin setting for the plugin |
|
360 | - * |
|
361 | - * @todo This will only work once the plugin has a GUID. |
|
362 | - * |
|
363 | - * @param string $name The name to set |
|
364 | - * @param string $value The value to set |
|
365 | - * |
|
366 | - * @return bool |
|
367 | - */ |
|
368 | - public function setSetting($name, $value) { |
|
369 | - if (!$this->guid) { |
|
370 | - return false; |
|
371 | - } |
|
345 | + $private_settings = $this->getDatabase()->getData($q); |
|
346 | + |
|
347 | + $return = []; |
|
348 | + |
|
349 | + if ($private_settings) { |
|
350 | + foreach ($private_settings as $setting) { |
|
351 | + $return[$setting->name] = $setting->value; |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + return array_merge($defaults, $return); |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Set a plugin setting for the plugin |
|
360 | + * |
|
361 | + * @todo This will only work once the plugin has a GUID. |
|
362 | + * |
|
363 | + * @param string $name The name to set |
|
364 | + * @param string $value The value to set |
|
365 | + * |
|
366 | + * @return bool |
|
367 | + */ |
|
368 | + public function setSetting($name, $value) { |
|
369 | + if (!$this->guid) { |
|
370 | + return false; |
|
371 | + } |
|
372 | 372 | |
373 | - // Hook to validate setting |
|
374 | - $value = elgg_trigger_plugin_hook('setting', 'plugin', [ |
|
375 | - 'plugin_id' => $this->getID(), |
|
376 | - 'plugin' => $this, |
|
377 | - 'name' => $name, |
|
378 | - 'value' => $value, |
|
379 | - ], $value); |
|
373 | + // Hook to validate setting |
|
374 | + $value = elgg_trigger_plugin_hook('setting', 'plugin', [ |
|
375 | + 'plugin_id' => $this->getID(), |
|
376 | + 'plugin' => $this, |
|
377 | + 'name' => $name, |
|
378 | + 'value' => $value, |
|
379 | + ], $value); |
|
380 | 380 | |
381 | - return $this->setPrivateSetting($name, $value); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Removes a plugin setting name and value. |
|
386 | - * |
|
387 | - * @param string $name The setting name to remove |
|
388 | - * |
|
389 | - * @return bool |
|
390 | - */ |
|
391 | - public function unsetSetting($name) { |
|
392 | - return remove_private_setting($this->guid, $name); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Removes all settings for this plugin. |
|
397 | - * |
|
398 | - * @todo Should be a better way to do this without dropping to raw SQL. |
|
399 | - * @todo If we could namespace the plugin settings this would be cleaner. |
|
400 | - * @todo this shouldn't work because ps_prefix will be empty string |
|
401 | - * @return bool |
|
402 | - */ |
|
403 | - public function unsetAllSettings() { |
|
404 | - _elgg_services()->pluginSettingsCache->clear($this->guid); |
|
405 | - _elgg_services()->boot->invalidateCache(); |
|
406 | - |
|
407 | - $db = $this->getDatabase(); |
|
408 | - $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
409 | - $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID()); |
|
410 | - |
|
411 | - $q = "DELETE FROM {$db->prefix}private_settings |
|
381 | + return $this->setPrivateSetting($name, $value); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Removes a plugin setting name and value. |
|
386 | + * |
|
387 | + * @param string $name The setting name to remove |
|
388 | + * |
|
389 | + * @return bool |
|
390 | + */ |
|
391 | + public function unsetSetting($name) { |
|
392 | + return remove_private_setting($this->guid, $name); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Removes all settings for this plugin. |
|
397 | + * |
|
398 | + * @todo Should be a better way to do this without dropping to raw SQL. |
|
399 | + * @todo If we could namespace the plugin settings this would be cleaner. |
|
400 | + * @todo this shouldn't work because ps_prefix will be empty string |
|
401 | + * @return bool |
|
402 | + */ |
|
403 | + public function unsetAllSettings() { |
|
404 | + _elgg_services()->pluginSettingsCache->clear($this->guid); |
|
405 | + _elgg_services()->boot->invalidateCache(); |
|
406 | + |
|
407 | + $db = $this->getDatabase(); |
|
408 | + $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
409 | + $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID()); |
|
410 | + |
|
411 | + $q = "DELETE FROM {$db->prefix}private_settings |
|
412 | 412 | WHERE entity_guid = $this->guid |
413 | 413 | AND name NOT LIKE '$us_prefix%' |
414 | 414 | AND name NOT LIKE '$is_prefix%'"; |
415 | 415 | |
416 | - return $db->deleteData($q); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - // User settings |
|
421 | - |
|
422 | - /** |
|
423 | - * Returns a user's setting for this plugin |
|
424 | - * |
|
425 | - * @param string $name The setting name |
|
426 | - * @param int $user_guid The user GUID |
|
427 | - * @param mixed $default The default value to return if none is set |
|
428 | - * |
|
429 | - * @return mixed The setting string value, the default value or false if there is no user |
|
430 | - */ |
|
431 | - public function getUserSetting($name, $user_guid = 0, $default = null) { |
|
432 | - $values = $this->getAllUserSettings($user_guid); |
|
433 | - if ($values === false) { |
|
434 | - return false; |
|
435 | - } |
|
416 | + return $db->deleteData($q); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + // User settings |
|
421 | + |
|
422 | + /** |
|
423 | + * Returns a user's setting for this plugin |
|
424 | + * |
|
425 | + * @param string $name The setting name |
|
426 | + * @param int $user_guid The user GUID |
|
427 | + * @param mixed $default The default value to return if none is set |
|
428 | + * |
|
429 | + * @return mixed The setting string value, the default value or false if there is no user |
|
430 | + */ |
|
431 | + public function getUserSetting($name, $user_guid = 0, $default = null) { |
|
432 | + $values = $this->getAllUserSettings($user_guid); |
|
433 | + if ($values === false) { |
|
434 | + return false; |
|
435 | + } |
|
436 | 436 | |
437 | - return elgg_extract($name, $values, $default); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Returns an array of all user settings saved for this plugin for the user. |
|
442 | - * |
|
443 | - * @note Plugin settings are saved with a prefix. This removes that prefix. |
|
444 | - * |
|
445 | - * @param int $user_guid The user GUID. Defaults to logged in. |
|
446 | - * @return array An array of key/value pairs. |
|
447 | - */ |
|
448 | - public function getAllUserSettings($user_guid = 0) { |
|
449 | - $user_guid = (int) $user_guid; |
|
450 | - |
|
451 | - if ($user_guid) { |
|
452 | - $user = get_entity($user_guid); |
|
453 | - } else { |
|
454 | - $user = _elgg_services()->session->getLoggedInUser(); |
|
455 | - } |
|
456 | - |
|
457 | - if (!($user instanceof \ElggUser)) { |
|
458 | - return false; |
|
459 | - } |
|
460 | - |
|
461 | - $defaults = $this->getStaticConfig('user_settings', []); |
|
437 | + return elgg_extract($name, $values, $default); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Returns an array of all user settings saved for this plugin for the user. |
|
442 | + * |
|
443 | + * @note Plugin settings are saved with a prefix. This removes that prefix. |
|
444 | + * |
|
445 | + * @param int $user_guid The user GUID. Defaults to logged in. |
|
446 | + * @return array An array of key/value pairs. |
|
447 | + */ |
|
448 | + public function getAllUserSettings($user_guid = 0) { |
|
449 | + $user_guid = (int) $user_guid; |
|
450 | + |
|
451 | + if ($user_guid) { |
|
452 | + $user = get_entity($user_guid); |
|
453 | + } else { |
|
454 | + $user = _elgg_services()->session->getLoggedInUser(); |
|
455 | + } |
|
456 | + |
|
457 | + if (!($user instanceof \ElggUser)) { |
|
458 | + return false; |
|
459 | + } |
|
460 | + |
|
461 | + $defaults = $this->getStaticConfig('user_settings', []); |
|
462 | 462 | |
463 | - $db_prefix = _elgg_services()->config->get('dbprefix'); |
|
464 | - // send an empty name so we just get the first part of the namespace |
|
465 | - $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
466 | - $ps_prefix_len = strlen($ps_prefix); |
|
463 | + $db_prefix = _elgg_services()->config->get('dbprefix'); |
|
464 | + // send an empty name so we just get the first part of the namespace |
|
465 | + $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
466 | + $ps_prefix_len = strlen($ps_prefix); |
|
467 | 467 | |
468 | - // Get private settings for user |
|
469 | - $q = "SELECT * FROM {$db_prefix}private_settings |
|
468 | + // Get private settings for user |
|
469 | + $q = "SELECT * FROM {$db_prefix}private_settings |
|
470 | 470 | WHERE entity_guid = {$user->guid} |
471 | 471 | AND name LIKE '$ps_prefix%'"; |
472 | 472 | |
473 | - $private_settings = $this->getDatabase()->getData($q); |
|
474 | - |
|
475 | - $return = []; |
|
476 | - |
|
477 | - if ($private_settings) { |
|
478 | - foreach ($private_settings as $setting) { |
|
479 | - $name = substr($setting->name, $ps_prefix_len); |
|
480 | - $value = $setting->value; |
|
481 | - |
|
482 | - $return[$name] = $value; |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - return array_merge($defaults, $return); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Sets a user setting for a plugin |
|
491 | - * |
|
492 | - * @param string $name The setting name |
|
493 | - * @param string $value The setting value |
|
494 | - * @param int $user_guid The user GUID |
|
495 | - * |
|
496 | - * @return mixed The new setting ID or false |
|
497 | - */ |
|
498 | - public function setUserSetting($name, $value, $user_guid = 0) { |
|
499 | - $user_guid = (int) $user_guid; |
|
500 | - |
|
501 | - if ($user_guid) { |
|
502 | - $user = get_entity($user_guid); |
|
503 | - } else { |
|
504 | - $user = _elgg_services()->session->getLoggedInUser(); |
|
505 | - } |
|
506 | - |
|
507 | - if (!($user instanceof \ElggUser)) { |
|
508 | - return false; |
|
509 | - } |
|
510 | - |
|
511 | - // Hook to validate setting |
|
512 | - // note: this doesn't pass the namespaced name |
|
513 | - $value = _elgg_services()->hooks->trigger('usersetting', 'plugin', [ |
|
514 | - 'user' => $user, |
|
515 | - 'plugin' => $this, |
|
516 | - 'plugin_id' => $this->getID(), |
|
517 | - 'name' => $name, |
|
518 | - 'value' => $value |
|
519 | - ], $value); |
|
520 | - |
|
521 | - // set the namespaced name. |
|
522 | - $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID()); |
|
523 | - |
|
524 | - return set_private_setting($user->guid, $name, $value); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Removes a user setting name and value. |
|
529 | - * |
|
530 | - * @param string $name The user setting name |
|
531 | - * @param int $user_guid The user GUID |
|
532 | - * @return bool |
|
533 | - */ |
|
534 | - public function unsetUserSetting($name, $user_guid = 0) { |
|
535 | - $user_guid = (int) $user_guid; |
|
536 | - |
|
537 | - if ($user_guid) { |
|
538 | - $user = get_entity($user_guid); |
|
539 | - } else { |
|
540 | - $user = _elgg_services()->session->getLoggedInUser(); |
|
541 | - } |
|
542 | - |
|
543 | - if (!($user instanceof \ElggUser)) { |
|
544 | - return false; |
|
545 | - } |
|
546 | - |
|
547 | - // set the namespaced name. |
|
548 | - $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID()); |
|
549 | - |
|
550 | - return remove_private_setting($user->guid, $name); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Removes all User Settings for this plugin for a particular user |
|
555 | - * |
|
556 | - * Use {@link removeAllUsersSettings()} to remove all user |
|
557 | - * settings for all users. (Note the plural 'Users'.) |
|
558 | - * |
|
559 | - * @warning 0 does not equal logged in user for this method! |
|
560 | - * @todo fix that |
|
561 | - * |
|
562 | - * @param int $user_guid The user GUID to remove user settings. |
|
563 | - * @return bool |
|
564 | - */ |
|
565 | - public function unsetAllUserSettings($user_guid) { |
|
566 | - $db = $this->getDatabase(); |
|
567 | - $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
568 | - |
|
569 | - $q = "DELETE FROM {$db->prefix}private_settings |
|
473 | + $private_settings = $this->getDatabase()->getData($q); |
|
474 | + |
|
475 | + $return = []; |
|
476 | + |
|
477 | + if ($private_settings) { |
|
478 | + foreach ($private_settings as $setting) { |
|
479 | + $name = substr($setting->name, $ps_prefix_len); |
|
480 | + $value = $setting->value; |
|
481 | + |
|
482 | + $return[$name] = $value; |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + return array_merge($defaults, $return); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Sets a user setting for a plugin |
|
491 | + * |
|
492 | + * @param string $name The setting name |
|
493 | + * @param string $value The setting value |
|
494 | + * @param int $user_guid The user GUID |
|
495 | + * |
|
496 | + * @return mixed The new setting ID or false |
|
497 | + */ |
|
498 | + public function setUserSetting($name, $value, $user_guid = 0) { |
|
499 | + $user_guid = (int) $user_guid; |
|
500 | + |
|
501 | + if ($user_guid) { |
|
502 | + $user = get_entity($user_guid); |
|
503 | + } else { |
|
504 | + $user = _elgg_services()->session->getLoggedInUser(); |
|
505 | + } |
|
506 | + |
|
507 | + if (!($user instanceof \ElggUser)) { |
|
508 | + return false; |
|
509 | + } |
|
510 | + |
|
511 | + // Hook to validate setting |
|
512 | + // note: this doesn't pass the namespaced name |
|
513 | + $value = _elgg_services()->hooks->trigger('usersetting', 'plugin', [ |
|
514 | + 'user' => $user, |
|
515 | + 'plugin' => $this, |
|
516 | + 'plugin_id' => $this->getID(), |
|
517 | + 'name' => $name, |
|
518 | + 'value' => $value |
|
519 | + ], $value); |
|
520 | + |
|
521 | + // set the namespaced name. |
|
522 | + $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID()); |
|
523 | + |
|
524 | + return set_private_setting($user->guid, $name, $value); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Removes a user setting name and value. |
|
529 | + * |
|
530 | + * @param string $name The user setting name |
|
531 | + * @param int $user_guid The user GUID |
|
532 | + * @return bool |
|
533 | + */ |
|
534 | + public function unsetUserSetting($name, $user_guid = 0) { |
|
535 | + $user_guid = (int) $user_guid; |
|
536 | + |
|
537 | + if ($user_guid) { |
|
538 | + $user = get_entity($user_guid); |
|
539 | + } else { |
|
540 | + $user = _elgg_services()->session->getLoggedInUser(); |
|
541 | + } |
|
542 | + |
|
543 | + if (!($user instanceof \ElggUser)) { |
|
544 | + return false; |
|
545 | + } |
|
546 | + |
|
547 | + // set the namespaced name. |
|
548 | + $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID()); |
|
549 | + |
|
550 | + return remove_private_setting($user->guid, $name); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Removes all User Settings for this plugin for a particular user |
|
555 | + * |
|
556 | + * Use {@link removeAllUsersSettings()} to remove all user |
|
557 | + * settings for all users. (Note the plural 'Users'.) |
|
558 | + * |
|
559 | + * @warning 0 does not equal logged in user for this method! |
|
560 | + * @todo fix that |
|
561 | + * |
|
562 | + * @param int $user_guid The user GUID to remove user settings. |
|
563 | + * @return bool |
|
564 | + */ |
|
565 | + public function unsetAllUserSettings($user_guid) { |
|
566 | + $db = $this->getDatabase(); |
|
567 | + $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
568 | + |
|
569 | + $q = "DELETE FROM {$db->prefix}private_settings |
|
570 | 570 | WHERE entity_guid = $user_guid |
571 | 571 | AND name LIKE '$ps_prefix%'"; |
572 | 572 | |
573 | - return $db->deleteData($q); |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Removes this plugin's user settings for all users. |
|
578 | - * |
|
579 | - * Use {@link removeAllUserSettings()} if you just want to remove |
|
580 | - * settings for a single user. |
|
581 | - * |
|
582 | - * @return bool |
|
583 | - */ |
|
584 | - public function unsetAllUsersSettings() { |
|
585 | - $db = $this->getDatabase(); |
|
586 | - $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
587 | - |
|
588 | - $q = "DELETE FROM {$db->prefix}private_settings |
|
573 | + return $db->deleteData($q); |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Removes this plugin's user settings for all users. |
|
578 | + * |
|
579 | + * Use {@link removeAllUserSettings()} if you just want to remove |
|
580 | + * settings for a single user. |
|
581 | + * |
|
582 | + * @return bool |
|
583 | + */ |
|
584 | + public function unsetAllUsersSettings() { |
|
585 | + $db = $this->getDatabase(); |
|
586 | + $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); |
|
587 | + |
|
588 | + $q = "DELETE FROM {$db->prefix}private_settings |
|
589 | 589 | WHERE name LIKE '$ps_prefix%'"; |
590 | 590 | |
591 | - return $db->deleteData($q); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - // validation |
|
596 | - |
|
597 | - /** |
|
598 | - * Returns if the plugin is complete, meaning has all required files |
|
599 | - * and Elgg can read them and they make sense. |
|
600 | - * |
|
601 | - * @todo bad name? This could be confused with isValid() from \ElggPluginPackage. |
|
602 | - * |
|
603 | - * @return bool |
|
604 | - */ |
|
605 | - public function isValid() { |
|
606 | - if (!$this->getID()) { |
|
607 | - $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:MissingID', [$this->guid]); |
|
608 | - return false; |
|
609 | - } |
|
610 | - |
|
611 | - if (!$this->getPackage() instanceof \ElggPluginPackage) { |
|
612 | - $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:NoPluginPackagePackage', [$this->getID(), $this->guid]); |
|
613 | - return false; |
|
614 | - } |
|
615 | - |
|
616 | - if (!$this->getPackage()->isValid()) { |
|
617 | - $this->errorMsg = $this->getPackage()->getError(); |
|
618 | - return false; |
|
619 | - } |
|
620 | - |
|
621 | - return true; |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Is this plugin active? |
|
626 | - * |
|
627 | - * @return bool |
|
628 | - */ |
|
629 | - public function isActive() { |
|
630 | - if (!$this->guid) { |
|
631 | - return false; |
|
632 | - } |
|
633 | - |
|
634 | - $site = elgg_get_site_entity(); |
|
635 | - |
|
636 | - if (!($site instanceof \ElggSite)) { |
|
637 | - return false; |
|
638 | - } |
|
639 | - |
|
640 | - return check_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Checks if this plugin can be activated on the current |
|
645 | - * Elgg installation. |
|
646 | - * |
|
647 | - * @return bool |
|
648 | - */ |
|
649 | - public function canActivate() { |
|
650 | - if ($this->isActive()) { |
|
651 | - return false; |
|
652 | - } |
|
653 | - |
|
654 | - if ($this->getPackage()) { |
|
655 | - $result = $this->getPackage()->isValid() && $this->getPackage()->checkDependencies(); |
|
656 | - if (!$result) { |
|
657 | - $this->errorMsg = $this->getPackage()->getError(); |
|
658 | - } |
|
659 | - |
|
660 | - return $result; |
|
661 | - } |
|
662 | - |
|
663 | - return false; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - // activating and deactivating |
|
668 | - |
|
669 | - /** |
|
670 | - * Actives the plugin for the current site. |
|
671 | - * |
|
672 | - * @return bool |
|
673 | - */ |
|
674 | - public function activate() { |
|
675 | - if ($this->isActive()) { |
|
676 | - return false; |
|
677 | - } |
|
678 | - |
|
679 | - if (!$this->canActivate()) { |
|
680 | - return false; |
|
681 | - } |
|
682 | - |
|
683 | - // Check this before setting status because the file could potentially throw |
|
684 | - if (!$this->isStaticConfigValid()) { |
|
685 | - return false; |
|
686 | - } |
|
687 | - |
|
688 | - if (!$this->setStatus(true)) { |
|
689 | - return false; |
|
690 | - } |
|
691 | - |
|
692 | - // perform tasks and emit events |
|
693 | - // emit an event. returning false will make this not be activated. |
|
694 | - // we need to do this after it's been fully activated |
|
695 | - // or the deactivate will be confused. |
|
696 | - $params = [ |
|
697 | - 'plugin_id' => $this->getID(), |
|
698 | - 'plugin_entity' => $this, |
|
699 | - ]; |
|
700 | - |
|
701 | - $return = _elgg_services()->events->trigger('activate', 'plugin', $params); |
|
702 | - |
|
703 | - // if there are any on_enable functions, start the plugin now and run them |
|
704 | - // Note: this will not run re-run the init hooks! |
|
705 | - if ($return) { |
|
706 | - $this->activateEntities(); |
|
591 | + return $db->deleteData($q); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + // validation |
|
596 | + |
|
597 | + /** |
|
598 | + * Returns if the plugin is complete, meaning has all required files |
|
599 | + * and Elgg can read them and they make sense. |
|
600 | + * |
|
601 | + * @todo bad name? This could be confused with isValid() from \ElggPluginPackage. |
|
602 | + * |
|
603 | + * @return bool |
|
604 | + */ |
|
605 | + public function isValid() { |
|
606 | + if (!$this->getID()) { |
|
607 | + $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:MissingID', [$this->guid]); |
|
608 | + return false; |
|
609 | + } |
|
610 | + |
|
611 | + if (!$this->getPackage() instanceof \ElggPluginPackage) { |
|
612 | + $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:NoPluginPackagePackage', [$this->getID(), $this->guid]); |
|
613 | + return false; |
|
614 | + } |
|
615 | + |
|
616 | + if (!$this->getPackage()->isValid()) { |
|
617 | + $this->errorMsg = $this->getPackage()->getError(); |
|
618 | + return false; |
|
619 | + } |
|
620 | + |
|
621 | + return true; |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Is this plugin active? |
|
626 | + * |
|
627 | + * @return bool |
|
628 | + */ |
|
629 | + public function isActive() { |
|
630 | + if (!$this->guid) { |
|
631 | + return false; |
|
632 | + } |
|
633 | + |
|
634 | + $site = elgg_get_site_entity(); |
|
635 | + |
|
636 | + if (!($site instanceof \ElggSite)) { |
|
637 | + return false; |
|
638 | + } |
|
639 | + |
|
640 | + return check_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Checks if this plugin can be activated on the current |
|
645 | + * Elgg installation. |
|
646 | + * |
|
647 | + * @return bool |
|
648 | + */ |
|
649 | + public function canActivate() { |
|
650 | + if ($this->isActive()) { |
|
651 | + return false; |
|
652 | + } |
|
653 | + |
|
654 | + if ($this->getPackage()) { |
|
655 | + $result = $this->getPackage()->isValid() && $this->getPackage()->checkDependencies(); |
|
656 | + if (!$result) { |
|
657 | + $this->errorMsg = $this->getPackage()->getError(); |
|
658 | + } |
|
659 | + |
|
660 | + return $result; |
|
661 | + } |
|
662 | + |
|
663 | + return false; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + // activating and deactivating |
|
668 | + |
|
669 | + /** |
|
670 | + * Actives the plugin for the current site. |
|
671 | + * |
|
672 | + * @return bool |
|
673 | + */ |
|
674 | + public function activate() { |
|
675 | + if ($this->isActive()) { |
|
676 | + return false; |
|
677 | + } |
|
678 | + |
|
679 | + if (!$this->canActivate()) { |
|
680 | + return false; |
|
681 | + } |
|
682 | + |
|
683 | + // Check this before setting status because the file could potentially throw |
|
684 | + if (!$this->isStaticConfigValid()) { |
|
685 | + return false; |
|
686 | + } |
|
687 | + |
|
688 | + if (!$this->setStatus(true)) { |
|
689 | + return false; |
|
690 | + } |
|
691 | + |
|
692 | + // perform tasks and emit events |
|
693 | + // emit an event. returning false will make this not be activated. |
|
694 | + // we need to do this after it's been fully activated |
|
695 | + // or the deactivate will be confused. |
|
696 | + $params = [ |
|
697 | + 'plugin_id' => $this->getID(), |
|
698 | + 'plugin_entity' => $this, |
|
699 | + ]; |
|
700 | + |
|
701 | + $return = _elgg_services()->events->trigger('activate', 'plugin', $params); |
|
702 | + |
|
703 | + // if there are any on_enable functions, start the plugin now and run them |
|
704 | + // Note: this will not run re-run the init hooks! |
|
705 | + if ($return) { |
|
706 | + $this->activateEntities(); |
|
707 | 707 | |
708 | - if ($this->canReadFile('activate.php')) { |
|
709 | - $flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES | |
|
710 | - ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS | ELGG_PLUGIN_REGISTER_WIDGETS | ELGG_PLUGIN_REGISTER_ACTIONS; |
|
711 | - |
|
712 | - $this->start($flags); |
|
713 | - |
|
714 | - $return = $this->includeFile('activate.php'); |
|
715 | - } |
|
716 | - } |
|
717 | - |
|
718 | - if ($return === false) { |
|
719 | - $this->deactivate(); |
|
720 | - } |
|
721 | - |
|
722 | - return $return; |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * Checks if this plugin can be deactivated on the current |
|
727 | - * Elgg installation. Validates that this plugin has no |
|
728 | - * active dependants. |
|
729 | - * |
|
730 | - * @return bool |
|
731 | - */ |
|
732 | - public function canDeactivate() { |
|
733 | - if (!$this->isActive()) { |
|
734 | - return false; |
|
735 | - } |
|
736 | - |
|
737 | - $dependents = []; |
|
738 | - |
|
739 | - $active_plugins = elgg_get_plugins(); |
|
740 | - |
|
741 | - foreach ($active_plugins as $plugin) { |
|
742 | - $manifest = $plugin->getManifest(); |
|
743 | - if (!$manifest) { |
|
744 | - return true; |
|
745 | - } |
|
746 | - $requires = $manifest->getRequires(); |
|
747 | - |
|
748 | - foreach ($requires as $required) { |
|
749 | - if ($required['type'] == 'plugin' && $required['name'] == $this->getID()) { |
|
750 | - // there are active dependents |
|
751 | - $dependents[$manifest->getPluginID()] = $plugin; |
|
752 | - } |
|
753 | - } |
|
754 | - } |
|
755 | - |
|
756 | - if (!empty($dependents)) { |
|
757 | - $list = array_map(function(\ElggPlugin $plugin) { |
|
758 | - $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getManifest()->getID()); |
|
759 | - return elgg_view('output/url', [ |
|
760 | - 'text' => $plugin->getManifest()->getName(), |
|
761 | - 'href' => "#$css_id", |
|
762 | - ]); |
|
763 | - }, $dependents); |
|
764 | - $name = $this->getManifest()->getName(); |
|
765 | - $list = implode(', ', $list); |
|
766 | - $this->errorMsg = elgg_echo('ElggPlugin:Dependencies:ActiveDependent', [$name, $list]); |
|
767 | - return false; |
|
768 | - } |
|
769 | - |
|
770 | - return true; |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Deactivates the plugin. |
|
775 | - * |
|
776 | - * @return bool |
|
777 | - */ |
|
778 | - public function deactivate() { |
|
779 | - if (!$this->isActive()) { |
|
780 | - return false; |
|
781 | - } |
|
782 | - |
|
783 | - if (!$this->canDeactivate()) { |
|
784 | - return false; |
|
785 | - } |
|
708 | + if ($this->canReadFile('activate.php')) { |
|
709 | + $flags = ELGG_PLUGIN_INCLUDE_START | ELGG_PLUGIN_REGISTER_CLASSES | |
|
710 | + ELGG_PLUGIN_REGISTER_LANGUAGES | ELGG_PLUGIN_REGISTER_VIEWS | ELGG_PLUGIN_REGISTER_WIDGETS | ELGG_PLUGIN_REGISTER_ACTIONS; |
|
711 | + |
|
712 | + $this->start($flags); |
|
713 | + |
|
714 | + $return = $this->includeFile('activate.php'); |
|
715 | + } |
|
716 | + } |
|
717 | + |
|
718 | + if ($return === false) { |
|
719 | + $this->deactivate(); |
|
720 | + } |
|
721 | + |
|
722 | + return $return; |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * Checks if this plugin can be deactivated on the current |
|
727 | + * Elgg installation. Validates that this plugin has no |
|
728 | + * active dependants. |
|
729 | + * |
|
730 | + * @return bool |
|
731 | + */ |
|
732 | + public function canDeactivate() { |
|
733 | + if (!$this->isActive()) { |
|
734 | + return false; |
|
735 | + } |
|
736 | + |
|
737 | + $dependents = []; |
|
738 | + |
|
739 | + $active_plugins = elgg_get_plugins(); |
|
740 | + |
|
741 | + foreach ($active_plugins as $plugin) { |
|
742 | + $manifest = $plugin->getManifest(); |
|
743 | + if (!$manifest) { |
|
744 | + return true; |
|
745 | + } |
|
746 | + $requires = $manifest->getRequires(); |
|
747 | + |
|
748 | + foreach ($requires as $required) { |
|
749 | + if ($required['type'] == 'plugin' && $required['name'] == $this->getID()) { |
|
750 | + // there are active dependents |
|
751 | + $dependents[$manifest->getPluginID()] = $plugin; |
|
752 | + } |
|
753 | + } |
|
754 | + } |
|
755 | + |
|
756 | + if (!empty($dependents)) { |
|
757 | + $list = array_map(function(\ElggPlugin $plugin) { |
|
758 | + $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getManifest()->getID()); |
|
759 | + return elgg_view('output/url', [ |
|
760 | + 'text' => $plugin->getManifest()->getName(), |
|
761 | + 'href' => "#$css_id", |
|
762 | + ]); |
|
763 | + }, $dependents); |
|
764 | + $name = $this->getManifest()->getName(); |
|
765 | + $list = implode(', ', $list); |
|
766 | + $this->errorMsg = elgg_echo('ElggPlugin:Dependencies:ActiveDependent', [$name, $list]); |
|
767 | + return false; |
|
768 | + } |
|
769 | + |
|
770 | + return true; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Deactivates the plugin. |
|
775 | + * |
|
776 | + * @return bool |
|
777 | + */ |
|
778 | + public function deactivate() { |
|
779 | + if (!$this->isActive()) { |
|
780 | + return false; |
|
781 | + } |
|
782 | + |
|
783 | + if (!$this->canDeactivate()) { |
|
784 | + return false; |
|
785 | + } |
|
786 | 786 | |
787 | - // emit an event. returning false will cause this to not be deactivated. |
|
788 | - $params = [ |
|
789 | - 'plugin_id' => $this->getID(), |
|
790 | - 'plugin_entity' => $this, |
|
791 | - ]; |
|
792 | - |
|
793 | - $return = _elgg_services()->events->trigger('deactivate', 'plugin', $params); |
|
794 | - |
|
795 | - // run any deactivate code |
|
796 | - if ($return) { |
|
797 | - if ($this->canReadFile('deactivate.php')) { |
|
798 | - $return = $this->includeFile('deactivate.php'); |
|
799 | - } |
|
787 | + // emit an event. returning false will cause this to not be deactivated. |
|
788 | + $params = [ |
|
789 | + 'plugin_id' => $this->getID(), |
|
790 | + 'plugin_entity' => $this, |
|
791 | + ]; |
|
792 | + |
|
793 | + $return = _elgg_services()->events->trigger('deactivate', 'plugin', $params); |
|
794 | + |
|
795 | + // run any deactivate code |
|
796 | + if ($return) { |
|
797 | + if ($this->canReadFile('deactivate.php')) { |
|
798 | + $return = $this->includeFile('deactivate.php'); |
|
799 | + } |
|
800 | 800 | |
801 | - $this->deactivateEntities(); |
|
802 | - } |
|
803 | - |
|
804 | - if ($return === false) { |
|
805 | - return false; |
|
806 | - } else { |
|
807 | - return $this->setStatus(false); |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Start the plugin. |
|
813 | - * |
|
814 | - * @param int $flags Start flags for the plugin. See the constants in lib/plugins.php for details. |
|
815 | - * @return true |
|
816 | - * @throws PluginException |
|
817 | - */ |
|
818 | - public function start($flags) { |
|
819 | - |
|
820 | - // include classes |
|
821 | - if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) { |
|
822 | - $this->registerClasses(); |
|
801 | + $this->deactivateEntities(); |
|
802 | + } |
|
803 | + |
|
804 | + if ($return === false) { |
|
805 | + return false; |
|
806 | + } else { |
|
807 | + return $this->setStatus(false); |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Start the plugin. |
|
813 | + * |
|
814 | + * @param int $flags Start flags for the plugin. See the constants in lib/plugins.php for details. |
|
815 | + * @return true |
|
816 | + * @throws PluginException |
|
817 | + */ |
|
818 | + public function start($flags) { |
|
819 | + |
|
820 | + // include classes |
|
821 | + if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) { |
|
822 | + $this->registerClasses(); |
|
823 | 823 | |
824 | - $autoload_file = 'vendor/autoload.php'; |
|
825 | - if ($this->canReadFile($autoload_file)) { |
|
826 | - require_once "{$this->path}/{$autoload_file}"; |
|
827 | - } |
|
828 | - } |
|
829 | - |
|
830 | - // include languages |
|
831 | - if ($flags & ELGG_PLUGIN_REGISTER_LANGUAGES) { |
|
832 | - // should be loaded before the first function that touches the static config (elgg-plugin.php) |
|
833 | - // so translations can be used... for example in registering widgets |
|
834 | - $this->registerLanguages(); |
|
835 | - } |
|
824 | + $autoload_file = 'vendor/autoload.php'; |
|
825 | + if ($this->canReadFile($autoload_file)) { |
|
826 | + require_once "{$this->path}/{$autoload_file}"; |
|
827 | + } |
|
828 | + } |
|
829 | + |
|
830 | + // include languages |
|
831 | + if ($flags & ELGG_PLUGIN_REGISTER_LANGUAGES) { |
|
832 | + // should be loaded before the first function that touches the static config (elgg-plugin.php) |
|
833 | + // so translations can be used... for example in registering widgets |
|
834 | + $this->registerLanguages(); |
|
835 | + } |
|
836 | 836 | |
837 | - // include start file if it exists |
|
838 | - if ($flags & ELGG_PLUGIN_INCLUDE_START) { |
|
839 | - if ($this->canReadFile('start.php')) { |
|
840 | - $this->includeFile('start.php'); |
|
841 | - } |
|
837 | + // include start file if it exists |
|
838 | + if ($flags & ELGG_PLUGIN_INCLUDE_START) { |
|
839 | + if ($this->canReadFile('start.php')) { |
|
840 | + $this->includeFile('start.php'); |
|
841 | + } |
|
842 | 842 | |
843 | - $this->registerEntities(); |
|
844 | - } |
|
843 | + $this->registerEntities(); |
|
844 | + } |
|
845 | 845 | |
846 | - // include views |
|
847 | - if ($flags & ELGG_PLUGIN_REGISTER_VIEWS) { |
|
848 | - $this->registerViews(); |
|
849 | - } |
|
850 | - |
|
851 | - // include actions |
|
852 | - if ($flags & ELGG_PLUGIN_REGISTER_ACTIONS) { |
|
853 | - $this->registerActions(); |
|
854 | - } |
|
855 | - |
|
856 | - // include widgets |
|
857 | - if ($flags & ELGG_PLUGIN_REGISTER_WIDGETS) { |
|
858 | - // should load after views because those are used during registration |
|
859 | - $this->registerWidgets(); |
|
860 | - } |
|
861 | - |
|
862 | - return true; |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Includes one of the plugins files |
|
867 | - * |
|
868 | - * @param string $filename The name of the file |
|
869 | - * |
|
870 | - * @throws PluginException |
|
871 | - * @return mixed The return value of the included file (or 1 if there is none) |
|
872 | - */ |
|
873 | - protected function includeFile($filename) { |
|
874 | - $filepath = "$this->path/$filename"; |
|
875 | - |
|
876 | - if (!$this->canReadFile($filename)) { |
|
877 | - $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:CannotIncludeFile', |
|
878 | - [$filename, $this->getID(), $this->guid, $this->path]); |
|
879 | - throw new \PluginException($msg); |
|
880 | - } |
|
881 | - |
|
882 | - try { |
|
883 | - $ret = include $filepath; |
|
884 | - } catch (Exception $e) { |
|
885 | - $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:IncludeFileThrew', |
|
886 | - [$filename, $this->getID(), $this->guid, $this->path]); |
|
887 | - throw new \PluginException($msg, 0, $e); |
|
888 | - } |
|
889 | - |
|
890 | - return $ret; |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * Checks whether a plugin file with the given name exists |
|
895 | - * |
|
896 | - * @param string $filename The name of the file |
|
897 | - * @return bool |
|
898 | - */ |
|
899 | - protected function canReadFile($filename) { |
|
900 | - $path = "{$this->path}/$filename"; |
|
901 | - return is_file($path) && is_readable($path); |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * If a static config file is present, is it a serializable array? |
|
906 | - * |
|
907 | - * @return bool |
|
908 | - * @throws PluginException |
|
909 | - */ |
|
910 | - private function isStaticConfigValid() { |
|
911 | - if (!$this->canReadFile(ElggPluginPackage::STATIC_CONFIG_FILENAME)) { |
|
912 | - return true; |
|
913 | - } |
|
914 | - |
|
915 | - ob_start(); |
|
916 | - $value = $this->includeFile(ElggPluginPackage::STATIC_CONFIG_FILENAME); |
|
917 | - if (ob_get_clean() !== '') { |
|
918 | - $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:ConfigSentOutput'); |
|
919 | - return false; |
|
920 | - } |
|
921 | - |
|
922 | - // make sure can serialize |
|
923 | - $value = @unserialize(serialize($value)); |
|
924 | - if (!is_array($value)) { |
|
925 | - $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:BadConfigFormat'); |
|
926 | - return false; |
|
927 | - } |
|
928 | - |
|
929 | - return true; |
|
930 | - } |
|
931 | - |
|
932 | - /** |
|
933 | - * Registers the plugin's views |
|
934 | - * |
|
935 | - * @throws PluginException |
|
936 | - * @return void |
|
937 | - */ |
|
938 | - protected function registerViews() { |
|
939 | - $views = _elgg_services()->views; |
|
940 | - |
|
941 | - // Declared views first |
|
942 | - $file = "{$this->path}/views.php"; |
|
943 | - if (is_file($file)) { |
|
944 | - $spec = Includer::includeFile($file); |
|
945 | - if (is_array($spec)) { |
|
946 | - $views->mergeViewsSpec($spec); |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - $spec = $this->getStaticConfig('views'); |
|
951 | - if ($spec) { |
|
952 | - $views->mergeViewsSpec($spec); |
|
953 | - } |
|
954 | - |
|
955 | - // Allow /views directory files to override |
|
956 | - if (!$views->registerPluginViews($this->path, $failed_dir)) { |
|
957 | - $key = 'ElggPlugin:Exception:CannotRegisterViews'; |
|
958 | - $args = [$this->getID(), $this->guid, $failed_dir]; |
|
959 | - $msg = _elgg_services()->translator->translate($key, $args); |
|
960 | - throw new \PluginException($msg); |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - /** |
|
965 | - * Registers the plugin's entities |
|
966 | - * |
|
967 | - * @return void |
|
968 | - */ |
|
969 | - protected function registerEntities() { |
|
970 | - |
|
971 | - $spec = (array) $this->getStaticConfig('entities', []); |
|
972 | - if (empty($spec)) { |
|
973 | - return; |
|
974 | - } |
|
846 | + // include views |
|
847 | + if ($flags & ELGG_PLUGIN_REGISTER_VIEWS) { |
|
848 | + $this->registerViews(); |
|
849 | + } |
|
850 | + |
|
851 | + // include actions |
|
852 | + if ($flags & ELGG_PLUGIN_REGISTER_ACTIONS) { |
|
853 | + $this->registerActions(); |
|
854 | + } |
|
855 | + |
|
856 | + // include widgets |
|
857 | + if ($flags & ELGG_PLUGIN_REGISTER_WIDGETS) { |
|
858 | + // should load after views because those are used during registration |
|
859 | + $this->registerWidgets(); |
|
860 | + } |
|
861 | + |
|
862 | + return true; |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Includes one of the plugins files |
|
867 | + * |
|
868 | + * @param string $filename The name of the file |
|
869 | + * |
|
870 | + * @throws PluginException |
|
871 | + * @return mixed The return value of the included file (or 1 if there is none) |
|
872 | + */ |
|
873 | + protected function includeFile($filename) { |
|
874 | + $filepath = "$this->path/$filename"; |
|
875 | + |
|
876 | + if (!$this->canReadFile($filename)) { |
|
877 | + $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:CannotIncludeFile', |
|
878 | + [$filename, $this->getID(), $this->guid, $this->path]); |
|
879 | + throw new \PluginException($msg); |
|
880 | + } |
|
881 | + |
|
882 | + try { |
|
883 | + $ret = include $filepath; |
|
884 | + } catch (Exception $e) { |
|
885 | + $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:IncludeFileThrew', |
|
886 | + [$filename, $this->getID(), $this->guid, $this->path]); |
|
887 | + throw new \PluginException($msg, 0, $e); |
|
888 | + } |
|
889 | + |
|
890 | + return $ret; |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * Checks whether a plugin file with the given name exists |
|
895 | + * |
|
896 | + * @param string $filename The name of the file |
|
897 | + * @return bool |
|
898 | + */ |
|
899 | + protected function canReadFile($filename) { |
|
900 | + $path = "{$this->path}/$filename"; |
|
901 | + return is_file($path) && is_readable($path); |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * If a static config file is present, is it a serializable array? |
|
906 | + * |
|
907 | + * @return bool |
|
908 | + * @throws PluginException |
|
909 | + */ |
|
910 | + private function isStaticConfigValid() { |
|
911 | + if (!$this->canReadFile(ElggPluginPackage::STATIC_CONFIG_FILENAME)) { |
|
912 | + return true; |
|
913 | + } |
|
914 | + |
|
915 | + ob_start(); |
|
916 | + $value = $this->includeFile(ElggPluginPackage::STATIC_CONFIG_FILENAME); |
|
917 | + if (ob_get_clean() !== '') { |
|
918 | + $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:ConfigSentOutput'); |
|
919 | + return false; |
|
920 | + } |
|
921 | + |
|
922 | + // make sure can serialize |
|
923 | + $value = @unserialize(serialize($value)); |
|
924 | + if (!is_array($value)) { |
|
925 | + $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:BadConfigFormat'); |
|
926 | + return false; |
|
927 | + } |
|
928 | + |
|
929 | + return true; |
|
930 | + } |
|
931 | + |
|
932 | + /** |
|
933 | + * Registers the plugin's views |
|
934 | + * |
|
935 | + * @throws PluginException |
|
936 | + * @return void |
|
937 | + */ |
|
938 | + protected function registerViews() { |
|
939 | + $views = _elgg_services()->views; |
|
940 | + |
|
941 | + // Declared views first |
|
942 | + $file = "{$this->path}/views.php"; |
|
943 | + if (is_file($file)) { |
|
944 | + $spec = Includer::includeFile($file); |
|
945 | + if (is_array($spec)) { |
|
946 | + $views->mergeViewsSpec($spec); |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + $spec = $this->getStaticConfig('views'); |
|
951 | + if ($spec) { |
|
952 | + $views->mergeViewsSpec($spec); |
|
953 | + } |
|
954 | + |
|
955 | + // Allow /views directory files to override |
|
956 | + if (!$views->registerPluginViews($this->path, $failed_dir)) { |
|
957 | + $key = 'ElggPlugin:Exception:CannotRegisterViews'; |
|
958 | + $args = [$this->getID(), $this->guid, $failed_dir]; |
|
959 | + $msg = _elgg_services()->translator->translate($key, $args); |
|
960 | + throw new \PluginException($msg); |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + /** |
|
965 | + * Registers the plugin's entities |
|
966 | + * |
|
967 | + * @return void |
|
968 | + */ |
|
969 | + protected function registerEntities() { |
|
970 | + |
|
971 | + $spec = (array) $this->getStaticConfig('entities', []); |
|
972 | + if (empty($spec)) { |
|
973 | + return; |
|
974 | + } |
|
975 | 975 | |
976 | - foreach ($spec as $entity) { |
|
977 | - if (isset($entity['type'], $entity['subtype'], $entity['searchable']) && $entity['searchable']) { |
|
978 | - elgg_register_entity_type($entity['type'], $entity['subtype']); |
|
979 | - } |
|
980 | - } |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Registers the plugin's actions provided in the plugin config file |
|
985 | - * |
|
986 | - * @throws PluginException |
|
987 | - * @return void |
|
988 | - */ |
|
989 | - protected function registerActions() { |
|
990 | - $actions = _elgg_services()->actions; |
|
991 | - |
|
992 | - $spec = (array) $this->getStaticConfig('actions', []); |
|
976 | + foreach ($spec as $entity) { |
|
977 | + if (isset($entity['type'], $entity['subtype'], $entity['searchable']) && $entity['searchable']) { |
|
978 | + elgg_register_entity_type($entity['type'], $entity['subtype']); |
|
979 | + } |
|
980 | + } |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Registers the plugin's actions provided in the plugin config file |
|
985 | + * |
|
986 | + * @throws PluginException |
|
987 | + * @return void |
|
988 | + */ |
|
989 | + protected function registerActions() { |
|
990 | + $actions = _elgg_services()->actions; |
|
991 | + |
|
992 | + $spec = (array) $this->getStaticConfig('actions', []); |
|
993 | 993 | |
994 | - foreach ($spec as $action => $action_spec) { |
|
995 | - if (!is_array($action_spec)) { |
|
996 | - continue; |
|
997 | - } |
|
994 | + foreach ($spec as $action => $action_spec) { |
|
995 | + if (!is_array($action_spec)) { |
|
996 | + continue; |
|
997 | + } |
|
998 | 998 | |
999 | - $options = [ |
|
1000 | - 'access' => 'logged_in', |
|
1001 | - 'filename' => '', // assuming core action is registered |
|
1002 | - ]; |
|
999 | + $options = [ |
|
1000 | + 'access' => 'logged_in', |
|
1001 | + 'filename' => '', // assuming core action is registered |
|
1002 | + ]; |
|
1003 | 1003 | |
1004 | - $options = array_merge($options, $action_spec); |
|
1004 | + $options = array_merge($options, $action_spec); |
|
1005 | 1005 | |
1006 | - $filename = "{$this->getPath()}actions/{$action}.php"; |
|
1007 | - if (file_exists($filename)) { |
|
1008 | - $options['filename'] = $filename; |
|
1009 | - } |
|
1006 | + $filename = "{$this->getPath()}actions/{$action}.php"; |
|
1007 | + if (file_exists($filename)) { |
|
1008 | + $options['filename'] = $filename; |
|
1009 | + } |
|
1010 | 1010 | |
1011 | - $actions->register($action, $options['filename'], $options['access']); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * Registers the plugin's widgets provided in the plugin config file |
|
1017 | - * |
|
1018 | - * @throws PluginException |
|
1019 | - * @return void |
|
1020 | - */ |
|
1021 | - protected function registerWidgets() { |
|
1022 | - $widgets = _elgg_services()->widgets; |
|
1011 | + $actions->register($action, $options['filename'], $options['access']); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * Registers the plugin's widgets provided in the plugin config file |
|
1017 | + * |
|
1018 | + * @throws PluginException |
|
1019 | + * @return void |
|
1020 | + */ |
|
1021 | + protected function registerWidgets() { |
|
1022 | + $widgets = _elgg_services()->widgets; |
|
1023 | 1023 | |
1024 | - $spec = (array) $this->getStaticConfig('widgets', []); |
|
1025 | - foreach ($spec as $widget_id => $widget_definition) { |
|
1026 | - if (!is_array($widget_definition)) { |
|
1027 | - continue; |
|
1028 | - } |
|
1029 | - if (!isset($widget_definition['id'])) { |
|
1030 | - $widget_definition['id'] = $widget_id; |
|
1031 | - } |
|
1024 | + $spec = (array) $this->getStaticConfig('widgets', []); |
|
1025 | + foreach ($spec as $widget_id => $widget_definition) { |
|
1026 | + if (!is_array($widget_definition)) { |
|
1027 | + continue; |
|
1028 | + } |
|
1029 | + if (!isset($widget_definition['id'])) { |
|
1030 | + $widget_definition['id'] = $widget_id; |
|
1031 | + } |
|
1032 | 1032 | |
1033 | - $definition = \Elgg\WidgetDefinition::factory($widget_definition); |
|
1033 | + $definition = \Elgg\WidgetDefinition::factory($widget_definition); |
|
1034 | 1034 | |
1035 | - $widgets->registerType($definition); |
|
1036 | - } |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Registers the plugin's languages |
|
1041 | - * |
|
1042 | - * @throws PluginException |
|
1043 | - * @return true |
|
1044 | - */ |
|
1045 | - protected function registerLanguages() { |
|
1046 | - return _elgg_services()->translator->registerPluginTranslations($this->path); |
|
1047 | - } |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Registers the plugin's classes |
|
1051 | - * |
|
1052 | - * @throws PluginException |
|
1053 | - * @return true |
|
1054 | - */ |
|
1055 | - protected function registerClasses() { |
|
1056 | - $classes_path = "$this->path/classes"; |
|
1057 | - |
|
1058 | - if (is_dir($classes_path)) { |
|
1059 | - _elgg_services()->autoloadManager->addClasses($classes_path); |
|
1060 | - } |
|
1061 | - |
|
1062 | - return true; |
|
1063 | - } |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * Activates the plugin's entities |
|
1067 | - * |
|
1068 | - * @return void |
|
1069 | - */ |
|
1070 | - protected function activateEntities() { |
|
1071 | - $spec = (array) $this->getStaticConfig('entities', []); |
|
1072 | - if (empty($spec)) { |
|
1073 | - return; |
|
1074 | - } |
|
1035 | + $widgets->registerType($definition); |
|
1036 | + } |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Registers the plugin's languages |
|
1041 | + * |
|
1042 | + * @throws PluginException |
|
1043 | + * @return true |
|
1044 | + */ |
|
1045 | + protected function registerLanguages() { |
|
1046 | + return _elgg_services()->translator->registerPluginTranslations($this->path); |
|
1047 | + } |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Registers the plugin's classes |
|
1051 | + * |
|
1052 | + * @throws PluginException |
|
1053 | + * @return true |
|
1054 | + */ |
|
1055 | + protected function registerClasses() { |
|
1056 | + $classes_path = "$this->path/classes"; |
|
1057 | + |
|
1058 | + if (is_dir($classes_path)) { |
|
1059 | + _elgg_services()->autoloadManager->addClasses($classes_path); |
|
1060 | + } |
|
1061 | + |
|
1062 | + return true; |
|
1063 | + } |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * Activates the plugin's entities |
|
1067 | + * |
|
1068 | + * @return void |
|
1069 | + */ |
|
1070 | + protected function activateEntities() { |
|
1071 | + $spec = (array) $this->getStaticConfig('entities', []); |
|
1072 | + if (empty($spec)) { |
|
1073 | + return; |
|
1074 | + } |
|
1075 | 1075 | |
1076 | - foreach ($spec as $entity) { |
|
1077 | - if (isset($entity['type'], $entity['subtype'], $entity['class'])) { |
|
1078 | - if (get_subtype_id($entity['type'], $entity['subtype'])) { |
|
1079 | - update_subtype($entity['type'], $entity['subtype'], $entity['class']); |
|
1080 | - } else { |
|
1081 | - add_subtype($entity['type'], $entity['subtype'], $entity['class']); |
|
1082 | - } |
|
1083 | - } |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Deactivates the plugin's entities |
|
1089 | - * |
|
1090 | - * @return void |
|
1091 | - */ |
|
1092 | - protected function deactivateEntities() { |
|
1093 | - $spec = (array) $this->getStaticConfig('entities', []); |
|
1094 | - if (empty($spec)) { |
|
1095 | - return; |
|
1096 | - } |
|
1076 | + foreach ($spec as $entity) { |
|
1077 | + if (isset($entity['type'], $entity['subtype'], $entity['class'])) { |
|
1078 | + if (get_subtype_id($entity['type'], $entity['subtype'])) { |
|
1079 | + update_subtype($entity['type'], $entity['subtype'], $entity['class']); |
|
1080 | + } else { |
|
1081 | + add_subtype($entity['type'], $entity['subtype'], $entity['class']); |
|
1082 | + } |
|
1083 | + } |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Deactivates the plugin's entities |
|
1089 | + * |
|
1090 | + * @return void |
|
1091 | + */ |
|
1092 | + protected function deactivateEntities() { |
|
1093 | + $spec = (array) $this->getStaticConfig('entities', []); |
|
1094 | + if (empty($spec)) { |
|
1095 | + return; |
|
1096 | + } |
|
1097 | 1097 | |
1098 | - foreach ($spec as $entity) { |
|
1099 | - if (isset($entity['type'], $entity['subtype'], $entity['class'])) { |
|
1100 | - update_subtype($entity['type'], $entity['subtype']); |
|
1101 | - } |
|
1102 | - } |
|
1103 | - } |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * Get an attribute or private setting value |
|
1107 | - * |
|
1108 | - * @param string $name Name of the attribute or private setting |
|
1109 | - * @return mixed |
|
1110 | - */ |
|
1111 | - public function __get($name) { |
|
1112 | - // See if its in our base attribute |
|
1113 | - if (array_key_exists($name, $this->attributes)) { |
|
1114 | - return $this->attributes[$name]; |
|
1115 | - } |
|
1116 | - |
|
1117 | - $result = $this->getPrivateSetting($name); |
|
1118 | - if ($result !== null) { |
|
1119 | - return $result; |
|
1120 | - } |
|
1121 | - $defaults = $this->getStaticConfig('settings', []); |
|
1122 | - return elgg_extract($name, $defaults, $result); |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * Set a value as private setting or attribute. |
|
1127 | - * |
|
1128 | - * Attributes include title and description. |
|
1129 | - * |
|
1130 | - * @param string $name Name of the attribute or private_setting |
|
1131 | - * @param mixed $value Value to be set |
|
1132 | - * @return void |
|
1133 | - */ |
|
1134 | - public function __set($name, $value) { |
|
1135 | - if (array_key_exists($name, $this->attributes)) { |
|
1136 | - // Check that we're not trying to change the guid! |
|
1137 | - if ((array_key_exists('guid', $this->attributes)) && ($name == 'guid')) { |
|
1138 | - return; |
|
1139 | - } |
|
1140 | - |
|
1141 | - $this->attributes[$name] = $value; |
|
1142 | - } else { |
|
1143 | - // to make sure we trigger the correct hooks |
|
1144 | - $this->setSetting($name, $value); |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Sets the plugin to active or inactive. |
|
1150 | - * |
|
1151 | - * @param bool $active Set to active or inactive |
|
1152 | - * |
|
1153 | - * @return bool |
|
1154 | - */ |
|
1155 | - private function setStatus($active) { |
|
1156 | - if (!$this->guid) { |
|
1157 | - return false; |
|
1158 | - } |
|
1159 | - |
|
1160 | - $site = elgg_get_site_entity(); |
|
1161 | - if ($active) { |
|
1162 | - $result = add_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
1163 | - } else { |
|
1164 | - $result = remove_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
1165 | - } |
|
1166 | - |
|
1167 | - _elgg_invalidate_plugins_provides_cache(); |
|
1168 | - _elgg_services()->boot->invalidateCache(); |
|
1169 | - |
|
1170 | - return $result; |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * Returns the last error message registered. |
|
1175 | - * |
|
1176 | - * @return string|null |
|
1177 | - */ |
|
1178 | - public function getError() { |
|
1179 | - return $this->errorMsg; |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Returns this plugin's \ElggPluginManifest object |
|
1184 | - * |
|
1185 | - * @return \ElggPluginManifest|null |
|
1186 | - */ |
|
1187 | - public function getManifest() { |
|
1188 | - if ($this->manifest instanceof \ElggPluginManifest) { |
|
1189 | - return $this->manifest; |
|
1190 | - } |
|
1191 | - |
|
1192 | - try { |
|
1193 | - $package = $this->getPackage(); |
|
1194 | - if (!$package) { |
|
1195 | - throw new \Exception('Package cannot be loaded'); |
|
1196 | - } |
|
1197 | - $this->manifest = $package->getManifest(); |
|
1198 | - } catch (Exception $e) { |
|
1199 | - _elgg_services()->logger->warn("Failed to load manifest for plugin $this->guid. " . $e->getMessage()); |
|
1200 | - $this->errorMsg = $e->getmessage(); |
|
1201 | - } |
|
1202 | - |
|
1203 | - return $this->manifest; |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Returns this plugin's \ElggPluginPackage object |
|
1208 | - * |
|
1209 | - * @return \ElggPluginPackage|null |
|
1210 | - */ |
|
1211 | - public function getPackage() { |
|
1212 | - if ($this->package instanceof \ElggPluginPackage) { |
|
1213 | - return $this->package; |
|
1214 | - } |
|
1215 | - |
|
1216 | - try { |
|
1217 | - $this->package = new \ElggPluginPackage($this->path, false); |
|
1218 | - } catch (Exception $e) { |
|
1219 | - _elgg_services()->logger->warn("Failed to load package for $this->guid. " . $e->getMessage()); |
|
1220 | - $this->errorMsg = $e->getmessage(); |
|
1221 | - } |
|
1222 | - |
|
1223 | - return $this->package; |
|
1224 | - } |
|
1098 | + foreach ($spec as $entity) { |
|
1099 | + if (isset($entity['type'], $entity['subtype'], $entity['class'])) { |
|
1100 | + update_subtype($entity['type'], $entity['subtype']); |
|
1101 | + } |
|
1102 | + } |
|
1103 | + } |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * Get an attribute or private setting value |
|
1107 | + * |
|
1108 | + * @param string $name Name of the attribute or private setting |
|
1109 | + * @return mixed |
|
1110 | + */ |
|
1111 | + public function __get($name) { |
|
1112 | + // See if its in our base attribute |
|
1113 | + if (array_key_exists($name, $this->attributes)) { |
|
1114 | + return $this->attributes[$name]; |
|
1115 | + } |
|
1116 | + |
|
1117 | + $result = $this->getPrivateSetting($name); |
|
1118 | + if ($result !== null) { |
|
1119 | + return $result; |
|
1120 | + } |
|
1121 | + $defaults = $this->getStaticConfig('settings', []); |
|
1122 | + return elgg_extract($name, $defaults, $result); |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * Set a value as private setting or attribute. |
|
1127 | + * |
|
1128 | + * Attributes include title and description. |
|
1129 | + * |
|
1130 | + * @param string $name Name of the attribute or private_setting |
|
1131 | + * @param mixed $value Value to be set |
|
1132 | + * @return void |
|
1133 | + */ |
|
1134 | + public function __set($name, $value) { |
|
1135 | + if (array_key_exists($name, $this->attributes)) { |
|
1136 | + // Check that we're not trying to change the guid! |
|
1137 | + if ((array_key_exists('guid', $this->attributes)) && ($name == 'guid')) { |
|
1138 | + return; |
|
1139 | + } |
|
1140 | + |
|
1141 | + $this->attributes[$name] = $value; |
|
1142 | + } else { |
|
1143 | + // to make sure we trigger the correct hooks |
|
1144 | + $this->setSetting($name, $value); |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Sets the plugin to active or inactive. |
|
1150 | + * |
|
1151 | + * @param bool $active Set to active or inactive |
|
1152 | + * |
|
1153 | + * @return bool |
|
1154 | + */ |
|
1155 | + private function setStatus($active) { |
|
1156 | + if (!$this->guid) { |
|
1157 | + return false; |
|
1158 | + } |
|
1159 | + |
|
1160 | + $site = elgg_get_site_entity(); |
|
1161 | + if ($active) { |
|
1162 | + $result = add_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
1163 | + } else { |
|
1164 | + $result = remove_entity_relationship($this->guid, 'active_plugin', $site->guid); |
|
1165 | + } |
|
1166 | + |
|
1167 | + _elgg_invalidate_plugins_provides_cache(); |
|
1168 | + _elgg_services()->boot->invalidateCache(); |
|
1169 | + |
|
1170 | + return $result; |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * Returns the last error message registered. |
|
1175 | + * |
|
1176 | + * @return string|null |
|
1177 | + */ |
|
1178 | + public function getError() { |
|
1179 | + return $this->errorMsg; |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Returns this plugin's \ElggPluginManifest object |
|
1184 | + * |
|
1185 | + * @return \ElggPluginManifest|null |
|
1186 | + */ |
|
1187 | + public function getManifest() { |
|
1188 | + if ($this->manifest instanceof \ElggPluginManifest) { |
|
1189 | + return $this->manifest; |
|
1190 | + } |
|
1191 | + |
|
1192 | + try { |
|
1193 | + $package = $this->getPackage(); |
|
1194 | + if (!$package) { |
|
1195 | + throw new \Exception('Package cannot be loaded'); |
|
1196 | + } |
|
1197 | + $this->manifest = $package->getManifest(); |
|
1198 | + } catch (Exception $e) { |
|
1199 | + _elgg_services()->logger->warn("Failed to load manifest for plugin $this->guid. " . $e->getMessage()); |
|
1200 | + $this->errorMsg = $e->getmessage(); |
|
1201 | + } |
|
1202 | + |
|
1203 | + return $this->manifest; |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Returns this plugin's \ElggPluginPackage object |
|
1208 | + * |
|
1209 | + * @return \ElggPluginPackage|null |
|
1210 | + */ |
|
1211 | + public function getPackage() { |
|
1212 | + if ($this->package instanceof \ElggPluginPackage) { |
|
1213 | + return $this->package; |
|
1214 | + } |
|
1215 | + |
|
1216 | + try { |
|
1217 | + $this->package = new \ElggPluginPackage($this->path, false); |
|
1218 | + } catch (Exception $e) { |
|
1219 | + _elgg_services()->logger->warn("Failed to load package for $this->guid. " . $e->getMessage()); |
|
1220 | + $this->errorMsg = $e->getmessage(); |
|
1221 | + } |
|
1222 | + |
|
1223 | + return $this->package; |
|
1224 | + } |
|
1225 | 1225 | } |