@@ -532,7 +532,7 @@ |
||
532 | 532 | * @param string[] $value Test files |
533 | 533 | * @param array $params Hook params |
534 | 534 | * |
535 | - * @return array |
|
535 | + * @return string[] |
|
536 | 536 | */ |
537 | 537 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
538 | 538 | $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | function current_page_url() { |
68 | 68 | $url = parse_url(elgg_get_site_url()); |
69 | 69 | |
70 | - $page = $url['scheme'] . "://" . $url['host']; |
|
70 | + $page = $url['scheme']."://".$url['host']; |
|
71 | 71 | |
72 | 72 | if (isset($url['port']) && $url['port']) { |
73 | - $page .= ":" . $url['port']; |
|
73 | + $page .= ":".$url['port']; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $page = trim($page, "/"); |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | 'input_name' => $input_name, |
281 | 281 | ]), |
282 | 282 | ]; |
283 | - $results[$entity->name . rand(1, 100)] = $result; |
|
283 | + $results[$entity->name.rand(1, 100)] = $result; |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | break; |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | 'url' => $entity->getURL(), |
328 | 328 | ]; |
329 | 329 | |
330 | - $results[$entity->name . rand(1, 100)] = $result; |
|
330 | + $results[$entity->name.rand(1, 100)] = $result; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | break; |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | 'input_name' => $input_name, |
374 | 374 | ]), |
375 | 375 | ]; |
376 | - $results[$entity->name . rand(1, 100)] = $result; |
|
376 | + $results[$entity->name.rand(1, 100)] = $result; |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | break; |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
480 | 480 | 'border-bottom', 'border-left', 'border-right', |
481 | 481 | 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
482 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
482 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
483 | 483 | ]; |
484 | 484 | |
485 | 485 | $params = ['tag' => $element]; |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @return array |
536 | 536 | */ |
537 | 537 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
538 | - $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
538 | + $value[] = Paths::elgg().'engine/tests/ElggHtmLawedTest.php'; |
|
539 | 539 | return $value; |
540 | 540 | } |
541 | 541 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return mixed |
28 | 28 | */ |
29 | 29 | function get_input($variable, $default = null, $filter_result = true) { |
30 | - return _elgg_services()->input->get($variable, $default, $filter_result); |
|
30 | + return _elgg_services()->input->get($variable, $default, $filter_result); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return void |
42 | 42 | */ |
43 | 43 | function set_input($variable, $value) { |
44 | - _elgg_services()->input->set($variable, $value); |
|
44 | + _elgg_services()->input->set($variable, $value); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @since 3.0 |
55 | 55 | */ |
56 | 56 | function elgg_get_title_input($variable = 'title', $default = '') { |
57 | - $raw_input = get_input($variable, $default, false); |
|
58 | - return htmlspecialchars($raw_input, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
57 | + $raw_input = get_input($variable, $default, false); |
|
58 | + return htmlspecialchars($raw_input, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @return mixed The filtered result - everything will be strings |
68 | 68 | */ |
69 | 69 | function filter_tags($var) { |
70 | - return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
70 | + return elgg_trigger_plugin_hook('validate', 'input', null, $var); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | * @return string The current page URL. |
80 | 80 | */ |
81 | 81 | function current_page_url() { |
82 | - $url = parse_url(elgg_get_site_url()); |
|
82 | + $url = parse_url(elgg_get_site_url()); |
|
83 | 83 | |
84 | - $page = $url['scheme'] . "://" . $url['host']; |
|
84 | + $page = $url['scheme'] . "://" . $url['host']; |
|
85 | 85 | |
86 | - if (isset($url['port']) && $url['port']) { |
|
87 | - $page .= ":" . $url['port']; |
|
88 | - } |
|
86 | + if (isset($url['port']) && $url['port']) { |
|
87 | + $page .= ":" . $url['port']; |
|
88 | + } |
|
89 | 89 | |
90 | - $page = trim($page, "/"); |
|
90 | + $page = trim($page, "/"); |
|
91 | 91 | |
92 | - $page .= _elgg_services()->request->getRequestUri(); |
|
92 | + $page .= _elgg_services()->request->getRequestUri(); |
|
93 | 93 | |
94 | - return $page; |
|
94 | + return $page; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return bool |
103 | 103 | */ |
104 | 104 | function is_email_address($address) { |
105 | - return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
105 | + return filter_var($address, FILTER_VALIDATE_EMAIL) === $address; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @since 1.8.0 |
118 | 118 | */ |
119 | 119 | function elgg_make_sticky_form($form_name) { |
120 | - _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
120 | + _elgg_services()->stickyForms->makeStickyForm($form_name); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @since 1.8.0 |
134 | 134 | */ |
135 | 135 | function elgg_clear_sticky_form($form_name) { |
136 | - _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
136 | + _elgg_services()->stickyForms->clearStickyForm($form_name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @since 1.8.0 |
146 | 146 | */ |
147 | 147 | function elgg_is_sticky_form($form_name) { |
148 | - return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
148 | + return _elgg_services()->stickyForms->isStickyForm($form_name); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @since 1.8.0 |
163 | 163 | */ |
164 | 164 | function elgg_get_sticky_value($form_name, $variable = '', $default = null, $filter_result = true) { |
165 | - return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
165 | + return _elgg_services()->stickyForms->getStickyValue($form_name, $variable, $default, $filter_result); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @since 1.8.0 |
176 | 176 | */ |
177 | 177 | function elgg_get_sticky_values($form_name, $filter_result = true) { |
178 | - return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
178 | + return _elgg_services()->stickyForms->getStickyValues($form_name, $filter_result); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 1.8.0 |
189 | 189 | */ |
190 | 190 | function elgg_clear_sticky_value($form_name, $variable) { |
191 | - _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
191 | + _elgg_services()->stickyForms->clearStickyValue($form_name, $variable); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -209,201 +209,201 @@ discard block |
||
209 | 209 | * @access private |
210 | 210 | */ |
211 | 211 | function input_livesearch_page_handler($page) { |
212 | - $dbprefix = _elgg_config()->dbprefix; |
|
213 | - |
|
214 | - // only return results to logged in users. |
|
215 | - if (!$user = elgg_get_logged_in_user_entity()) { |
|
216 | - exit; |
|
217 | - } |
|
218 | - |
|
219 | - if (!$q = get_input('term', get_input('q'))) { |
|
220 | - exit; |
|
221 | - } |
|
222 | - |
|
223 | - $input_name = get_input('name', 'members'); |
|
224 | - |
|
225 | - $q = sanitise_string($q); |
|
226 | - |
|
227 | - // replace mysql vars with escaped strings |
|
228 | - $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
229 | - |
|
230 | - $match_on = get_input('match_on', 'all'); |
|
231 | - |
|
232 | - if (!is_array($match_on)) { |
|
233 | - $match_on = [$match_on]; |
|
234 | - } |
|
235 | - |
|
236 | - // all = users and groups |
|
237 | - if (in_array('all', $match_on)) { |
|
238 | - $match_on = ['users', 'groups']; |
|
239 | - } |
|
240 | - |
|
241 | - $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
242 | - if (get_input('match_owner', false)) { |
|
243 | - $owner_guid = $user->getGUID(); |
|
244 | - } |
|
245 | - |
|
246 | - $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
247 | - |
|
248 | - // grab a list of entities and send them in json. |
|
249 | - $results = []; |
|
250 | - foreach ($match_on as $match_type) { |
|
251 | - switch ($match_type) { |
|
252 | - case 'users': |
|
253 | - $options = [ |
|
254 | - 'type' => 'user', |
|
255 | - 'limit' => $limit, |
|
256 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
257 | - 'wheres' => [ |
|
258 | - "ue.banned = 'no'", |
|
259 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
260 | - ] |
|
261 | - ]; |
|
212 | + $dbprefix = _elgg_config()->dbprefix; |
|
213 | + |
|
214 | + // only return results to logged in users. |
|
215 | + if (!$user = elgg_get_logged_in_user_entity()) { |
|
216 | + exit; |
|
217 | + } |
|
218 | + |
|
219 | + if (!$q = get_input('term', get_input('q'))) { |
|
220 | + exit; |
|
221 | + } |
|
222 | + |
|
223 | + $input_name = get_input('name', 'members'); |
|
224 | + |
|
225 | + $q = sanitise_string($q); |
|
226 | + |
|
227 | + // replace mysql vars with escaped strings |
|
228 | + $q = str_replace(['_', '%'], ['\_', '\%'], $q); |
|
229 | + |
|
230 | + $match_on = get_input('match_on', 'all'); |
|
231 | + |
|
232 | + if (!is_array($match_on)) { |
|
233 | + $match_on = [$match_on]; |
|
234 | + } |
|
235 | + |
|
236 | + // all = users and groups |
|
237 | + if (in_array('all', $match_on)) { |
|
238 | + $match_on = ['users', 'groups']; |
|
239 | + } |
|
240 | + |
|
241 | + $owner_guid = ELGG_ENTITIES_ANY_VALUE; |
|
242 | + if (get_input('match_owner', false)) { |
|
243 | + $owner_guid = $user->getGUID(); |
|
244 | + } |
|
245 | + |
|
246 | + $limit = sanitise_int(get_input('limit', _elgg_config()->default_limit)); |
|
247 | + |
|
248 | + // grab a list of entities and send them in json. |
|
249 | + $results = []; |
|
250 | + foreach ($match_on as $match_type) { |
|
251 | + switch ($match_type) { |
|
252 | + case 'users': |
|
253 | + $options = [ |
|
254 | + 'type' => 'user', |
|
255 | + 'limit' => $limit, |
|
256 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
257 | + 'wheres' => [ |
|
258 | + "ue.banned = 'no'", |
|
259 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
260 | + ] |
|
261 | + ]; |
|
262 | 262 | |
263 | - $entities = elgg_get_entities($options); |
|
264 | - if (!empty($entities)) { |
|
265 | - foreach ($entities as $entity) { |
|
266 | - if (in_array('groups', $match_on)) { |
|
267 | - $value = $entity->guid; |
|
268 | - } else { |
|
269 | - $value = $entity->username; |
|
270 | - } |
|
271 | - |
|
272 | - $output = elgg_view_list_item($entity, [ |
|
273 | - 'use_hover' => false, |
|
274 | - 'use_link' => false, |
|
275 | - 'class' => 'elgg-autocomplete-item', |
|
276 | - 'title' => $entity->name, // Default title would be a link |
|
277 | - ]); |
|
278 | - |
|
279 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
280 | - 'use_hover' => false, |
|
281 | - ]); |
|
282 | - |
|
283 | - $result = [ |
|
284 | - 'type' => 'user', |
|
285 | - 'name' => $entity->name, |
|
286 | - 'desc' => $entity->username, |
|
287 | - 'guid' => $entity->guid, |
|
288 | - 'label' => $output, |
|
289 | - 'value' => $value, |
|
290 | - 'icon' => $icon, |
|
291 | - 'url' => $entity->getURL(), |
|
292 | - 'html' => elgg_view('input/userpicker/item', [ |
|
293 | - 'entity' => $entity, |
|
294 | - 'input_name' => $input_name, |
|
295 | - ]), |
|
296 | - ]; |
|
297 | - $results[$entity->name . rand(1, 100)] = $result; |
|
298 | - } |
|
299 | - } |
|
300 | - break; |
|
301 | - |
|
302 | - case 'groups': |
|
303 | - // don't return results if groups aren't enabled. |
|
304 | - if (!elgg_is_active_plugin('groups')) { |
|
305 | - continue; |
|
306 | - } |
|
263 | + $entities = elgg_get_entities($options); |
|
264 | + if (!empty($entities)) { |
|
265 | + foreach ($entities as $entity) { |
|
266 | + if (in_array('groups', $match_on)) { |
|
267 | + $value = $entity->guid; |
|
268 | + } else { |
|
269 | + $value = $entity->username; |
|
270 | + } |
|
271 | + |
|
272 | + $output = elgg_view_list_item($entity, [ |
|
273 | + 'use_hover' => false, |
|
274 | + 'use_link' => false, |
|
275 | + 'class' => 'elgg-autocomplete-item', |
|
276 | + 'title' => $entity->name, // Default title would be a link |
|
277 | + ]); |
|
278 | + |
|
279 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
280 | + 'use_hover' => false, |
|
281 | + ]); |
|
282 | + |
|
283 | + $result = [ |
|
284 | + 'type' => 'user', |
|
285 | + 'name' => $entity->name, |
|
286 | + 'desc' => $entity->username, |
|
287 | + 'guid' => $entity->guid, |
|
288 | + 'label' => $output, |
|
289 | + 'value' => $value, |
|
290 | + 'icon' => $icon, |
|
291 | + 'url' => $entity->getURL(), |
|
292 | + 'html' => elgg_view('input/userpicker/item', [ |
|
293 | + 'entity' => $entity, |
|
294 | + 'input_name' => $input_name, |
|
295 | + ]), |
|
296 | + ]; |
|
297 | + $results[$entity->name . rand(1, 100)] = $result; |
|
298 | + } |
|
299 | + } |
|
300 | + break; |
|
301 | + |
|
302 | + case 'groups': |
|
303 | + // don't return results if groups aren't enabled. |
|
304 | + if (!elgg_is_active_plugin('groups')) { |
|
305 | + continue; |
|
306 | + } |
|
307 | 307 | |
308 | - $options = [ |
|
309 | - 'type' => 'group', |
|
310 | - 'limit' => $limit, |
|
311 | - 'owner_guid' => $owner_guid, |
|
312 | - 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
313 | - 'wheres' => [ |
|
314 | - "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
315 | - ] |
|
316 | - ]; |
|
308 | + $options = [ |
|
309 | + 'type' => 'group', |
|
310 | + 'limit' => $limit, |
|
311 | + 'owner_guid' => $owner_guid, |
|
312 | + 'joins' => ["JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"], |
|
313 | + 'wheres' => [ |
|
314 | + "(ge.name LIKE '$q%' OR ge.name LIKE '% $q%' OR ge.description LIKE '% $q%')" |
|
315 | + ] |
|
316 | + ]; |
|
317 | 317 | |
318 | - $entities = elgg_get_entities($options); |
|
319 | - if (!empty($entities)) { |
|
320 | - foreach ($entities as $entity) { |
|
321 | - $output = elgg_view_list_item($entity, [ |
|
322 | - 'use_hover' => false, |
|
323 | - 'class' => 'elgg-autocomplete-item', |
|
324 | - 'full_view' => false, |
|
325 | - 'href' => false, |
|
326 | - 'title' => $entity->name, // Default title would be a link |
|
327 | - ]); |
|
328 | - |
|
329 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
330 | - 'use_hover' => false, |
|
331 | - ]); |
|
332 | - |
|
333 | - $result = [ |
|
334 | - 'type' => 'group', |
|
335 | - 'name' => $entity->name, |
|
336 | - 'desc' => strip_tags($entity->description), |
|
337 | - 'guid' => $entity->guid, |
|
338 | - 'label' => $output, |
|
339 | - 'value' => $entity->guid, |
|
340 | - 'icon' => $icon, |
|
341 | - 'url' => $entity->getURL(), |
|
342 | - ]; |
|
343 | - |
|
344 | - $results[$entity->name . rand(1, 100)] = $result; |
|
345 | - } |
|
346 | - } |
|
347 | - break; |
|
348 | - |
|
349 | - case 'friends': |
|
350 | - $options = [ |
|
351 | - 'type' => 'user', |
|
352 | - 'limit' => $limit, |
|
353 | - 'relationship' => 'friend', |
|
354 | - 'relationship_guid' => $user->getGUID(), |
|
355 | - 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
356 | - 'wheres' => [ |
|
357 | - "ue.banned = 'no'", |
|
358 | - "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
359 | - ] |
|
360 | - ]; |
|
318 | + $entities = elgg_get_entities($options); |
|
319 | + if (!empty($entities)) { |
|
320 | + foreach ($entities as $entity) { |
|
321 | + $output = elgg_view_list_item($entity, [ |
|
322 | + 'use_hover' => false, |
|
323 | + 'class' => 'elgg-autocomplete-item', |
|
324 | + 'full_view' => false, |
|
325 | + 'href' => false, |
|
326 | + 'title' => $entity->name, // Default title would be a link |
|
327 | + ]); |
|
328 | + |
|
329 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
330 | + 'use_hover' => false, |
|
331 | + ]); |
|
332 | + |
|
333 | + $result = [ |
|
334 | + 'type' => 'group', |
|
335 | + 'name' => $entity->name, |
|
336 | + 'desc' => strip_tags($entity->description), |
|
337 | + 'guid' => $entity->guid, |
|
338 | + 'label' => $output, |
|
339 | + 'value' => $entity->guid, |
|
340 | + 'icon' => $icon, |
|
341 | + 'url' => $entity->getURL(), |
|
342 | + ]; |
|
343 | + |
|
344 | + $results[$entity->name . rand(1, 100)] = $result; |
|
345 | + } |
|
346 | + } |
|
347 | + break; |
|
348 | + |
|
349 | + case 'friends': |
|
350 | + $options = [ |
|
351 | + 'type' => 'user', |
|
352 | + 'limit' => $limit, |
|
353 | + 'relationship' => 'friend', |
|
354 | + 'relationship_guid' => $user->getGUID(), |
|
355 | + 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], |
|
356 | + 'wheres' => [ |
|
357 | + "ue.banned = 'no'", |
|
358 | + "(ue.name LIKE '$q%' OR ue.name LIKE '% $q%' OR ue.username LIKE '$q%')" |
|
359 | + ] |
|
360 | + ]; |
|
361 | 361 | |
362 | - $entities = elgg_get_entities_from_relationship($options); |
|
363 | - if (!empty($entities)) { |
|
364 | - foreach ($entities as $entity) { |
|
365 | - $output = elgg_view_list_item($entity, [ |
|
366 | - 'use_hover' => false, |
|
367 | - 'use_link' => false, |
|
368 | - 'class' => 'elgg-autocomplete-item', |
|
369 | - 'title' => $entity->name, // Default title would be a link |
|
370 | - ]); |
|
371 | - |
|
372 | - $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
373 | - 'use_hover' => false, |
|
374 | - ]); |
|
375 | - |
|
376 | - $result = [ |
|
377 | - 'type' => 'user', |
|
378 | - 'name' => $entity->name, |
|
379 | - 'desc' => $entity->username, |
|
380 | - 'guid' => $entity->guid, |
|
381 | - 'label' => $output, |
|
382 | - 'value' => $entity->username, |
|
383 | - 'icon' => $icon, |
|
384 | - 'url' => $entity->getURL(), |
|
385 | - 'html' => elgg_view('input/userpicker/item', [ |
|
386 | - 'entity' => $entity, |
|
387 | - 'input_name' => $input_name, |
|
388 | - ]), |
|
389 | - ]; |
|
390 | - $results[$entity->name . rand(1, 100)] = $result; |
|
391 | - } |
|
392 | - } |
|
393 | - break; |
|
394 | - |
|
395 | - default: |
|
396 | - header("HTTP/1.0 400 Bad Request", true); |
|
397 | - echo "livesearch: unknown match_on of $match_type"; |
|
398 | - exit; |
|
399 | - break; |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - ksort($results); |
|
404 | - header("Content-Type: application/json;charset=utf-8"); |
|
405 | - echo json_encode(array_values($results)); |
|
406 | - exit; |
|
362 | + $entities = elgg_get_entities_from_relationship($options); |
|
363 | + if (!empty($entities)) { |
|
364 | + foreach ($entities as $entity) { |
|
365 | + $output = elgg_view_list_item($entity, [ |
|
366 | + 'use_hover' => false, |
|
367 | + 'use_link' => false, |
|
368 | + 'class' => 'elgg-autocomplete-item', |
|
369 | + 'title' => $entity->name, // Default title would be a link |
|
370 | + ]); |
|
371 | + |
|
372 | + $icon = elgg_view_entity_icon($entity, 'tiny', [ |
|
373 | + 'use_hover' => false, |
|
374 | + ]); |
|
375 | + |
|
376 | + $result = [ |
|
377 | + 'type' => 'user', |
|
378 | + 'name' => $entity->name, |
|
379 | + 'desc' => $entity->username, |
|
380 | + 'guid' => $entity->guid, |
|
381 | + 'label' => $output, |
|
382 | + 'value' => $entity->username, |
|
383 | + 'icon' => $icon, |
|
384 | + 'url' => $entity->getURL(), |
|
385 | + 'html' => elgg_view('input/userpicker/item', [ |
|
386 | + 'entity' => $entity, |
|
387 | + 'input_name' => $input_name, |
|
388 | + ]), |
|
389 | + ]; |
|
390 | + $results[$entity->name . rand(1, 100)] = $result; |
|
391 | + } |
|
392 | + } |
|
393 | + break; |
|
394 | + |
|
395 | + default: |
|
396 | + header("HTTP/1.0 400 Bad Request", true); |
|
397 | + echo "livesearch: unknown match_on of $match_type"; |
|
398 | + exit; |
|
399 | + break; |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + ksort($results); |
|
404 | + header("Content-Type: application/json;charset=utf-8"); |
|
405 | + echo json_encode(array_values($results)); |
|
406 | + exit; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -425,38 +425,38 @@ discard block |
||
425 | 425 | * @return mixed |
426 | 426 | */ |
427 | 427 | function _elgg_htmlawed_filter_tags($hook, $type, $result, $params = null) { |
428 | - $var = $result; |
|
429 | - |
|
430 | - $config = [ |
|
431 | - // seems to handle about everything we need. |
|
432 | - 'safe' => true, |
|
433 | - |
|
434 | - // remove comments/CDATA instead of converting to text |
|
435 | - 'comment' => 1, |
|
436 | - 'cdata' => 1, |
|
437 | - |
|
438 | - 'deny_attribute' => 'class, on*', |
|
439 | - 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
440 | - |
|
441 | - 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
442 | - // apparent this doesn't work. |
|
443 | - // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
444 | - ]; |
|
445 | - |
|
446 | - // add nofollow to all links on output |
|
447 | - if (!elgg_in_context('input')) { |
|
448 | - $config['anti_link_spam'] = ['/./', '']; |
|
449 | - } |
|
450 | - |
|
451 | - $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
452 | - $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
453 | - |
|
454 | - if (!is_array($var)) { |
|
455 | - return Htmlawed::filter($var, $config, $spec); |
|
456 | - } else { |
|
457 | - array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
458 | - return $var; |
|
459 | - } |
|
428 | + $var = $result; |
|
429 | + |
|
430 | + $config = [ |
|
431 | + // seems to handle about everything we need. |
|
432 | + 'safe' => true, |
|
433 | + |
|
434 | + // remove comments/CDATA instead of converting to text |
|
435 | + 'comment' => 1, |
|
436 | + 'cdata' => 1, |
|
437 | + |
|
438 | + 'deny_attribute' => 'class, on*', |
|
439 | + 'hook_tag' => '_elgg_htmlawed_tag_post_processor', |
|
440 | + |
|
441 | + 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto', |
|
442 | + // apparent this doesn't work. |
|
443 | + // 'style:color,cursor,text-align,font-size,font-weight,font-style,border,margin,padding,float' |
|
444 | + ]; |
|
445 | + |
|
446 | + // add nofollow to all links on output |
|
447 | + if (!elgg_in_context('input')) { |
|
448 | + $config['anti_link_spam'] = ['/./', '']; |
|
449 | + } |
|
450 | + |
|
451 | + $config = elgg_trigger_plugin_hook('config', 'htmlawed', null, $config); |
|
452 | + $spec = elgg_trigger_plugin_hook('spec', 'htmlawed', null, ''); |
|
453 | + |
|
454 | + if (!is_array($var)) { |
|
455 | + return Htmlawed::filter($var, $config, $spec); |
|
456 | + } else { |
|
457 | + array_walk_recursive($var, '_elgg_htmLawedArray', [$config, $spec]); |
|
458 | + return $var; |
|
459 | + } |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | // @codingStandardsIgnoreStart |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | * wrapper function for htmlawed for handling arrays |
465 | 465 | */ |
466 | 466 | function _elgg_htmLawedArray(&$v, $k, $config_spec) { |
467 | - list ($config, $spec) = $config_spec; |
|
468 | - $v = Htmlawed::filter($v, $config, $spec); |
|
467 | + list ($config, $spec) = $config_spec; |
|
468 | + $v = Htmlawed::filter($v, $config, $spec); |
|
469 | 469 | } |
470 | 470 | // @codingStandardsIgnoreEnd |
471 | 471 | |
@@ -482,60 +482,60 @@ discard block |
||
482 | 482 | * @return string |
483 | 483 | */ |
484 | 484 | function _elgg_htmlawed_tag_post_processor($element, $attributes = false) { |
485 | - if ($attributes === false) { |
|
486 | - // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
487 | - return "</${element}>"; |
|
488 | - } |
|
489 | - |
|
490 | - // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
491 | - $allowed_styles = [ |
|
492 | - 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
493 | - 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
494 | - 'border-bottom', 'border-left', 'border-right', |
|
495 | - 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
496 | - 'margin-right', 'padding', 'float', 'text-decoration' |
|
497 | - ]; |
|
498 | - |
|
499 | - $params = ['tag' => $element]; |
|
500 | - $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
501 | - |
|
502 | - // must return something. |
|
503 | - $string = ''; |
|
504 | - |
|
505 | - foreach ($attributes as $attr => $value) { |
|
506 | - if ($attr == 'style') { |
|
507 | - $styles = explode(';', $value); |
|
508 | - |
|
509 | - $style_str = ''; |
|
510 | - foreach ($styles as $style) { |
|
511 | - if (!trim($style)) { |
|
512 | - continue; |
|
513 | - } |
|
514 | - list($style_attr, $style_value) = explode(':', trim($style)); |
|
515 | - $style_attr = trim($style_attr); |
|
516 | - $style_value = trim($style_value); |
|
517 | - |
|
518 | - if (in_array($style_attr, $allowed_styles)) { |
|
519 | - $style_str .= "$style_attr: $style_value; "; |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - if ($style_str) { |
|
524 | - $style_str = trim($style_str); |
|
525 | - $string .= " style=\"$style_str\""; |
|
526 | - } |
|
527 | - } else { |
|
528 | - $string .= " $attr=\"$value\""; |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
533 | - if ($string = trim($string)) { |
|
534 | - $string = " $string"; |
|
535 | - } |
|
536 | - |
|
537 | - $r = "<$element$string>"; |
|
538 | - return $r; |
|
485 | + if ($attributes === false) { |
|
486 | + // This is a closing tag. Prevent further processing to avoid inserting a duplicate tag |
|
487 | + return "</${element}>"; |
|
488 | + } |
|
489 | + |
|
490 | + // this list should be coordinated with the WYSIWYG editor used (tinymce, ckeditor, etc.) |
|
491 | + $allowed_styles = [ |
|
492 | + 'color', 'cursor', 'text-align', 'vertical-align', 'font-size', |
|
493 | + 'font-weight', 'font-style', 'border', 'border-top', 'background-color', |
|
494 | + 'border-bottom', 'border-left', 'border-right', |
|
495 | + 'margin', 'margin-top', 'margin-bottom', 'margin-left', |
|
496 | + 'margin-right', 'padding', 'float', 'text-decoration' |
|
497 | + ]; |
|
498 | + |
|
499 | + $params = ['tag' => $element]; |
|
500 | + $allowed_styles = elgg_trigger_plugin_hook('allowed_styles', 'htmlawed', $params, $allowed_styles); |
|
501 | + |
|
502 | + // must return something. |
|
503 | + $string = ''; |
|
504 | + |
|
505 | + foreach ($attributes as $attr => $value) { |
|
506 | + if ($attr == 'style') { |
|
507 | + $styles = explode(';', $value); |
|
508 | + |
|
509 | + $style_str = ''; |
|
510 | + foreach ($styles as $style) { |
|
511 | + if (!trim($style)) { |
|
512 | + continue; |
|
513 | + } |
|
514 | + list($style_attr, $style_value) = explode(':', trim($style)); |
|
515 | + $style_attr = trim($style_attr); |
|
516 | + $style_value = trim($style_value); |
|
517 | + |
|
518 | + if (in_array($style_attr, $allowed_styles)) { |
|
519 | + $style_str .= "$style_attr: $style_value; "; |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + if ($style_str) { |
|
524 | + $style_str = trim($style_str); |
|
525 | + $string .= " style=\"$style_str\""; |
|
526 | + } |
|
527 | + } else { |
|
528 | + $string .= " $attr=\"$value\""; |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + // Some WYSIWYG editors do not like tags like <p > so only add a space if needed. |
|
533 | + if ($string = trim($string)) { |
|
534 | + $string = " $string"; |
|
535 | + } |
|
536 | + |
|
537 | + $r = "<$element$string>"; |
|
538 | + return $r; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @return array |
550 | 550 | */ |
551 | 551 | function _elgg_htmlawed_test($hook, $type, $value, $params) { |
552 | - $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
553 | - return $value; |
|
552 | + $value[] = Paths::elgg() . 'engine/tests/ElggHtmLawedTest.php'; |
|
553 | + return $value; |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -565,13 +565,13 @@ discard block |
||
565 | 565 | */ |
566 | 566 | function _elgg_disable_password_autocomplete($hook, $type, $return_value, $params) { |
567 | 567 | |
568 | - if (!_elgg_config()->security_disable_password_autocomplete) { |
|
569 | - return; |
|
570 | - } |
|
568 | + if (!_elgg_config()->security_disable_password_autocomplete) { |
|
569 | + return; |
|
570 | + } |
|
571 | 571 | |
572 | - $return_value['autocomplete'] = 'off'; |
|
572 | + $return_value['autocomplete'] = 'off'; |
|
573 | 573 | |
574 | - return $return_value; |
|
574 | + return $return_value; |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | * @access private |
582 | 582 | */ |
583 | 583 | function _elgg_input_init() { |
584 | - // register an endpoint for live search / autocomplete. |
|
585 | - elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
584 | + // register an endpoint for live search / autocomplete. |
|
585 | + elgg_register_page_handler('livesearch', 'input_livesearch_page_handler'); |
|
586 | 586 | |
587 | - elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
587 | + elgg_register_plugin_hook_handler('validate', 'input', '_elgg_htmlawed_filter_tags', 1); |
|
588 | 588 | |
589 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
589 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_htmlawed_test'); |
|
590 | 590 | |
591 | - elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
591 | + elgg_register_plugin_hook_handler('view_vars', 'input/password', '_elgg_disable_password_autocomplete'); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
595 | 595 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
596 | 596 | */ |
597 | 597 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
598 | - $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
598 | + $events->registerHandler('init', 'system', '_elgg_input_init'); |
|
599 | 599 | }; |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param bool $allow_multiple_emails Allow the same email address to be |
293 | 293 | * registered multiple times? |
294 | 294 | * |
295 | - * @return int|false The new user's GUID; false on failure |
|
295 | + * @return integer The new user's GUID; false on failure |
|
296 | 296 | * @throws RegistrationException |
297 | 297 | */ |
298 | 298 | function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | /** |
415 | 415 | * Sets the last action time of the given user to right now. |
416 | 416 | * |
417 | - * @param ElggUser|int $user The user or GUID |
|
417 | + * @param ElggUser $user The user or GUID |
|
418 | 418 | * @return void |
419 | 419 | */ |
420 | 420 | function set_last_action($user) { |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | * /avatar/edit/<username> |
696 | 696 | * |
697 | 697 | * @param array $page |
698 | - * @return bool |
|
698 | + * @return boolean|null |
|
699 | 699 | * @access private |
700 | 700 | */ |
701 | 701 | function elgg_avatar_page_handler($page) { |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | // Blacklist for bad characters (partially nicked from mediawiki) |
207 | - $blacklist = '/[' . |
|
208 | - '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | - '\x{00a0}' . // non-breaking space |
|
210 | - '\x{2000}-\x{200f}' . // various whitespace |
|
211 | - '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | - '\x{3000}' . // ideographic space |
|
213 | - '\x{e000}-\x{f8ff}' . // private use |
|
207 | + $blacklist = '/['. |
|
208 | + '\x{0080}-\x{009f}'.// iso-8859-1 control chars |
|
209 | + '\x{00a0}'.// non-breaking space |
|
210 | + '\x{2000}-\x{200f}'.// various whitespace |
|
211 | + '\x{2028}-\x{202f}'.// breaks and control chars |
|
212 | + '\x{3000}'.// ideographic space |
|
213 | + '\x{e000}-\x{f8ff}'.// private use |
|
214 | 214 | ']/u'; |
215 | 215 | |
216 | 216 | if (preg_match($blacklist, $username)) { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | function elgg_get_registration_url(array $query = [], $fragment = '') { |
394 | 394 | $url = elgg_normalize_url('register'); |
395 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
395 | + $url = elgg_http_add_url_query_elements($url, $query).$fragment; |
|
396 | 396 | return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
397 | 397 | } |
398 | 398 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | function elgg_get_login_url(array $query = [], $fragment = '') { |
409 | 409 | $url = elgg_normalize_url('login'); |
410 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
410 | + $url = elgg_http_add_url_query_elements($url, $query).$fragment; |
|
411 | 411 | return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
412 | 412 | } |
413 | 413 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | 'text' => elgg_echo('avatar:edit'), |
498 | 498 | 'icon' => 'image', |
499 | 499 | 'href' => "avatar/edit/$user->username", |
500 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
500 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid) ? 'action' : 'admin', |
|
501 | 501 | ]); |
502 | 502 | } |
503 | 503 | |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | |
679 | 679 | $return[] = \ElggMenuItem::factory([ |
680 | 680 | 'name' => 'account', |
681 | - 'text' => elgg_echo('account') . $toggle, |
|
681 | + 'text' => elgg_echo('account').$toggle, |
|
682 | 682 | 'href' => $href, |
683 | 683 | 'priority' => 800, |
684 | 684 | 'section' => 'alt', |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @access private |
922 | 922 | */ |
923 | 923 | function users_test($hook, $type, $value, $params) { |
924 | - $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
924 | + $value[] = Paths::elgg()."engine/tests/ElggUserTest.php"; |
|
925 | 925 | return $value; |
926 | 926 | } |
927 | 927 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @return bool Depending on success |
18 | 18 | */ |
19 | 19 | function disable_user_entities($owner_guid) { |
20 | - return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
20 | + return _elgg_services()->usersTable->disableEntities($owner_guid); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return bool |
30 | 30 | */ |
31 | 31 | function ban_user($user_guid, $reason = "") { |
32 | - return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
32 | + return _elgg_services()->usersTable->ban($user_guid, $reason); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @return bool |
41 | 41 | */ |
42 | 42 | function unban_user($user_guid) { |
43 | - return _elgg_services()->usersTable->unban($user_guid); |
|
43 | + return _elgg_services()->usersTable->unban($user_guid); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return bool |
52 | 52 | */ |
53 | 53 | function make_user_admin($user_guid) { |
54 | - return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
54 | + return _elgg_services()->usersTable->makeAdmin($user_guid); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return bool |
63 | 63 | */ |
64 | 64 | function remove_user_admin($user_guid) { |
65 | - return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
65 | + return _elgg_services()->usersTable->removeAdmin($user_guid); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return \ElggUser|false |
76 | 76 | */ |
77 | 77 | function get_user($guid) { |
78 | - return _elgg_services()->entityTable->get($guid, 'user'); |
|
78 | + return _elgg_services()->entityTable->get($guid, 'user'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return \ElggUser|false Depending on success |
87 | 87 | */ |
88 | 88 | function get_user_by_username($username) { |
89 | - return _elgg_services()->usersTable->getByUsername($username); |
|
89 | + return _elgg_services()->usersTable->getByUsername($username); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return \ElggUser |
98 | 98 | */ |
99 | 99 | function get_user_by_code($hash) { |
100 | - return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
100 | + return _elgg_services()->persistentLogin->getUserFromHash($hash); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return array |
109 | 109 | */ |
110 | 110 | function get_user_by_email($email) { |
111 | - return _elgg_services()->usersTable->getByEmail($email); |
|
111 | + return _elgg_services()->usersTable->getByEmail($email); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return \ElggUser[]|int |
125 | 125 | */ |
126 | 126 | function find_active_users(array $options = []) { |
127 | - return _elgg_services()->usersTable->findActive($options); |
|
127 | + return _elgg_services()->usersTable->findActive($options); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @return bool |
136 | 136 | */ |
137 | 137 | function send_new_password_request($user_guid) { |
138 | - return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
138 | + return _elgg_services()->passwords->sendNewPasswordRequest($user_guid); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return bool |
150 | 150 | */ |
151 | 151 | function force_user_password_reset($user_guid, $password) { |
152 | - return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
152 | + return _elgg_services()->passwords->forcePasswordReset($user_guid, $password); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @return bool True on success |
163 | 163 | */ |
164 | 164 | function execute_new_password_request($user_guid, $conf_code, $password = null) { |
165 | - return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
165 | + return _elgg_services()->passwords->executeNewPasswordReset($user_guid, $conf_code, $password); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return string |
172 | 172 | */ |
173 | 173 | function generate_random_cleartext_password() { |
174 | - return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
174 | + return _elgg_services()->crypto->getRandomString(12, \ElggCrypto::CHARS_PASSWORD); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -185,57 +185,57 @@ discard block |
||
185 | 185 | * @throws RegistrationException on invalid |
186 | 186 | */ |
187 | 187 | function validate_username($username) { |
188 | - $config = _elgg_config(); |
|
189 | - |
|
190 | - // Basic, check length |
|
191 | - if (!isset($config->minusername)) { |
|
192 | - $config->minusername = 4; |
|
193 | - } |
|
194 | - |
|
195 | - if (strlen($username) < $config->minusername) { |
|
196 | - $msg = elgg_echo('registration:usernametooshort', [$config->minusername]); |
|
197 | - throw new \RegistrationException($msg); |
|
198 | - } |
|
199 | - |
|
200 | - // username in the database has a limit of 128 characters |
|
201 | - if (strlen($username) > 128) { |
|
202 | - $msg = elgg_echo('registration:usernametoolong', [128]); |
|
203 | - throw new \RegistrationException($msg); |
|
204 | - } |
|
205 | - |
|
206 | - // Blacklist for bad characters (partially nicked from mediawiki) |
|
207 | - $blacklist = '/[' . |
|
208 | - '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | - '\x{00a0}' . // non-breaking space |
|
210 | - '\x{2000}-\x{200f}' . // various whitespace |
|
211 | - '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | - '\x{3000}' . // ideographic space |
|
213 | - '\x{e000}-\x{f8ff}' . // private use |
|
214 | - ']/u'; |
|
215 | - |
|
216 | - if (preg_match($blacklist, $username)) { |
|
217 | - // @todo error message needs work |
|
218 | - throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
219 | - } |
|
220 | - |
|
221 | - // Belts and braces |
|
222 | - // @todo Tidy into main unicode |
|
223 | - $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
224 | - |
|
225 | - $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
226 | - ['blacklist' => $blacklist2], $blacklist2); |
|
227 | - |
|
228 | - for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
229 | - if (strpos($username, $blacklist2[$n]) !== false) { |
|
230 | - $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
231 | - $msg = htmlspecialchars($msg, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
232 | - throw new \RegistrationException($msg); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - $result = true; |
|
237 | - return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
238 | - ['username' => $username], $result); |
|
188 | + $config = _elgg_config(); |
|
189 | + |
|
190 | + // Basic, check length |
|
191 | + if (!isset($config->minusername)) { |
|
192 | + $config->minusername = 4; |
|
193 | + } |
|
194 | + |
|
195 | + if (strlen($username) < $config->minusername) { |
|
196 | + $msg = elgg_echo('registration:usernametooshort', [$config->minusername]); |
|
197 | + throw new \RegistrationException($msg); |
|
198 | + } |
|
199 | + |
|
200 | + // username in the database has a limit of 128 characters |
|
201 | + if (strlen($username) > 128) { |
|
202 | + $msg = elgg_echo('registration:usernametoolong', [128]); |
|
203 | + throw new \RegistrationException($msg); |
|
204 | + } |
|
205 | + |
|
206 | + // Blacklist for bad characters (partially nicked from mediawiki) |
|
207 | + $blacklist = '/[' . |
|
208 | + '\x{0080}-\x{009f}' . // iso-8859-1 control chars |
|
209 | + '\x{00a0}' . // non-breaking space |
|
210 | + '\x{2000}-\x{200f}' . // various whitespace |
|
211 | + '\x{2028}-\x{202f}' . // breaks and control chars |
|
212 | + '\x{3000}' . // ideographic space |
|
213 | + '\x{e000}-\x{f8ff}' . // private use |
|
214 | + ']/u'; |
|
215 | + |
|
216 | + if (preg_match($blacklist, $username)) { |
|
217 | + // @todo error message needs work |
|
218 | + throw new \RegistrationException(elgg_echo('registration:invalidchars')); |
|
219 | + } |
|
220 | + |
|
221 | + // Belts and braces |
|
222 | + // @todo Tidy into main unicode |
|
223 | + $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@+='; |
|
224 | + |
|
225 | + $blacklist2 = elgg_trigger_plugin_hook('username:character_blacklist', 'user', |
|
226 | + ['blacklist' => $blacklist2], $blacklist2); |
|
227 | + |
|
228 | + for ($n = 0; $n < strlen($blacklist2); $n++) { |
|
229 | + if (strpos($username, $blacklist2[$n]) !== false) { |
|
230 | + $msg = elgg_echo('registration:invalidchars', [$blacklist2[$n], $blacklist2]); |
|
231 | + $msg = htmlspecialchars($msg, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
232 | + throw new \RegistrationException($msg); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + $result = true; |
|
237 | + return elgg_trigger_plugin_hook('registeruser:validate:username', 'all', |
|
238 | + ['username' => $username], $result); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -247,20 +247,20 @@ discard block |
||
247 | 247 | * @throws RegistrationException on invalid |
248 | 248 | */ |
249 | 249 | function validate_password($password) { |
250 | - $config = _elgg_config(); |
|
250 | + $config = _elgg_config(); |
|
251 | 251 | |
252 | - if (!isset($config->min_password_length)) { |
|
253 | - $config->min_password_length = 6; |
|
254 | - } |
|
252 | + if (!isset($config->min_password_length)) { |
|
253 | + $config->min_password_length = 6; |
|
254 | + } |
|
255 | 255 | |
256 | - if (strlen($password) < $config->min_password_length) { |
|
257 | - $msg = elgg_echo('registration:passwordtooshort', [$config->min_password_length]); |
|
258 | - throw new \RegistrationException($msg); |
|
259 | - } |
|
256 | + if (strlen($password) < $config->min_password_length) { |
|
257 | + $msg = elgg_echo('registration:passwordtooshort', [$config->min_password_length]); |
|
258 | + throw new \RegistrationException($msg); |
|
259 | + } |
|
260 | 260 | |
261 | - $result = true; |
|
262 | - return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
263 | - ['password' => $password], $result); |
|
261 | + $result = true; |
|
262 | + return elgg_trigger_plugin_hook('registeruser:validate:password', 'all', |
|
263 | + ['password' => $password], $result); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | * @return bool |
273 | 273 | */ |
274 | 274 | function validate_email_address($address) { |
275 | - if (!is_email_address($address)) { |
|
276 | - throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
277 | - } |
|
275 | + if (!is_email_address($address)) { |
|
276 | + throw new \RegistrationException(elgg_echo('registration:notemail')); |
|
277 | + } |
|
278 | 278 | |
279 | - // Got here, so lets try a hook (defaulting to ok) |
|
280 | - $result = true; |
|
281 | - return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
282 | - ['email' => $address], $result); |
|
279 | + // Got here, so lets try a hook (defaulting to ok) |
|
280 | + $result = true; |
|
281 | + return elgg_trigger_plugin_hook('registeruser:validate:email', 'all', |
|
282 | + ['email' => $address], $result); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @throws RegistrationException |
297 | 297 | */ |
298 | 298 | function register_user($username, $password, $name, $email, $allow_multiple_emails = false) { |
299 | - return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
299 | + return _elgg_services()->usersTable->register($username, $password, $name, $email, $allow_multiple_emails); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @see elgg_validate_invite_code |
309 | 309 | */ |
310 | 310 | function generate_invite_code($username) { |
311 | - return _elgg_services()->usersTable->generateInviteCode($username); |
|
311 | + return _elgg_services()->usersTable->generateInviteCode($username); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @since 1.10 |
323 | 323 | */ |
324 | 324 | function elgg_validate_invite_code($username, $code) { |
325 | - return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
325 | + return _elgg_services()->usersTable->validateInviteCode($username, $code); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @since 1.8.0 |
336 | 336 | */ |
337 | 337 | function elgg_set_user_validation_status($user_guid, $status, $method = '') { |
338 | - return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
338 | + return _elgg_services()->usersTable->setValidationStatus($user_guid, $status, $method); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @since 1.8.0 |
347 | 347 | */ |
348 | 348 | function elgg_get_user_validation_status($user_guid) { |
349 | - return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
349 | + return _elgg_services()->usersTable->getValidationStatus($user_guid); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -360,24 +360,24 @@ discard block |
||
360 | 360 | */ |
361 | 361 | function elgg_user_account_page_handler($page_elements, $handler) { |
362 | 362 | |
363 | - switch ($handler) { |
|
364 | - case 'login': |
|
365 | - echo elgg_view_resource("account/login"); |
|
366 | - break; |
|
367 | - case 'forgotpassword': |
|
368 | - echo elgg_view_resource("account/forgotten_password"); |
|
369 | - break; |
|
370 | - case 'changepassword': |
|
371 | - echo elgg_view_resource("account/change_password"); |
|
372 | - break; |
|
373 | - case 'register': |
|
374 | - echo elgg_view_resource("account/register"); |
|
375 | - break; |
|
376 | - default: |
|
377 | - return false; |
|
378 | - } |
|
363 | + switch ($handler) { |
|
364 | + case 'login': |
|
365 | + echo elgg_view_resource("account/login"); |
|
366 | + break; |
|
367 | + case 'forgotpassword': |
|
368 | + echo elgg_view_resource("account/forgotten_password"); |
|
369 | + break; |
|
370 | + case 'changepassword': |
|
371 | + echo elgg_view_resource("account/change_password"); |
|
372 | + break; |
|
373 | + case 'register': |
|
374 | + echo elgg_view_resource("account/register"); |
|
375 | + break; |
|
376 | + default: |
|
377 | + return false; |
|
378 | + } |
|
379 | 379 | |
380 | - return true; |
|
380 | + return true; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | * @return string |
392 | 392 | */ |
393 | 393 | function elgg_get_registration_url(array $query = [], $fragment = '') { |
394 | - $url = elgg_normalize_url('register'); |
|
395 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
396 | - return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
394 | + $url = elgg_normalize_url('register'); |
|
395 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
396 | + return elgg_trigger_plugin_hook('registration_url', 'site', $query, $url); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -406,9 +406,9 @@ discard block |
||
406 | 406 | * @return string |
407 | 407 | */ |
408 | 408 | function elgg_get_login_url(array $query = [], $fragment = '') { |
409 | - $url = elgg_normalize_url('login'); |
|
410 | - $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
411 | - return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
409 | + $url = elgg_normalize_url('login'); |
|
410 | + $url = elgg_http_add_url_query_elements($url, $query) . $fragment; |
|
411 | + return elgg_trigger_plugin_hook('login_url', 'site', $query, $url); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -418,16 +418,16 @@ discard block |
||
418 | 418 | * @return void |
419 | 419 | */ |
420 | 420 | function set_last_action($user) { |
421 | - if (!$user) { |
|
422 | - return; |
|
423 | - } |
|
424 | - if (!$user instanceof ElggUser) { |
|
425 | - $user = get_user($user); |
|
426 | - } |
|
427 | - if (!$user) { |
|
428 | - return; |
|
429 | - } |
|
430 | - _elgg_services()->usersTable->setLastAction($user); |
|
421 | + if (!$user) { |
|
422 | + return; |
|
423 | + } |
|
424 | + if (!$user instanceof ElggUser) { |
|
425 | + $user = get_user($user); |
|
426 | + } |
|
427 | + if (!$user) { |
|
428 | + return; |
|
429 | + } |
|
430 | + _elgg_services()->usersTable->setLastAction($user); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | * @return void |
438 | 438 | */ |
439 | 439 | function set_last_login($user_guid) { |
440 | - $user = get_user($user_guid); |
|
441 | - if (!$user) { |
|
442 | - return; |
|
443 | - } |
|
444 | - _elgg_services()->usersTable->setLastLogin($user); |
|
440 | + $user = get_user($user_guid); |
|
441 | + if (!$user) { |
|
442 | + return; |
|
443 | + } |
|
444 | + _elgg_services()->usersTable->setLastLogin($user); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -456,23 +456,23 @@ discard block |
||
456 | 456 | * @access private |
457 | 457 | */ |
458 | 458 | function user_avatar_hook($hook, $type, $return, $params) { |
459 | - $user = elgg_extract('entity', $params); |
|
460 | - $size = elgg_extract('size', $params, 'medium'); |
|
459 | + $user = elgg_extract('entity', $params); |
|
460 | + $size = elgg_extract('size', $params, 'medium'); |
|
461 | 461 | |
462 | - if (!$user instanceof ElggUser) { |
|
463 | - return; |
|
464 | - } |
|
462 | + if (!$user instanceof ElggUser) { |
|
463 | + return; |
|
464 | + } |
|
465 | 465 | |
466 | - if (_elgg_config()->walled_garden) { |
|
467 | - return; |
|
468 | - } |
|
466 | + if (_elgg_config()->walled_garden) { |
|
467 | + return; |
|
468 | + } |
|
469 | 469 | |
470 | - if (!$user->hasIcon($size, 'icon')) { |
|
471 | - return; |
|
472 | - } |
|
470 | + if (!$user->hasIcon($size, 'icon')) { |
|
471 | + return; |
|
472 | + } |
|
473 | 473 | |
474 | - $icon = $user->getIcon($size, 'icon'); |
|
475 | - return elgg_get_inline_url($icon, false); |
|
474 | + $icon = $user->getIcon($size, 'icon'); |
|
475 | + return elgg_get_inline_url($icon, false); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -480,104 +480,104 @@ discard block |
||
480 | 480 | * @access private |
481 | 481 | */ |
482 | 482 | function elgg_user_hover_menu($hook, $type, $return, $params) { |
483 | - $user = elgg_extract('entity', $params); |
|
484 | - /* @var \ElggUser $user */ |
|
485 | - |
|
486 | - if (!$user instanceof \ElggUser) { |
|
487 | - return; |
|
488 | - } |
|
489 | - |
|
490 | - if (!elgg_is_logged_in()) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - if ($user->canEdit()) { |
|
495 | - $return[] = ElggMenuItem::factory([ |
|
496 | - 'name' => 'avatar:edit', |
|
497 | - 'text' => elgg_echo('avatar:edit'), |
|
498 | - 'icon' => 'image', |
|
499 | - 'href' => "avatar/edit/$user->username", |
|
500 | - 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
501 | - ]); |
|
502 | - } |
|
503 | - |
|
504 | - // prevent admins from banning or deleting themselves |
|
505 | - if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
506 | - return $return; |
|
507 | - } |
|
508 | - |
|
509 | - if (!elgg_is_admin_logged_in()) { |
|
510 | - return $return; |
|
511 | - } |
|
512 | - |
|
513 | - // following items are admin only |
|
514 | - if (!$user->isBanned()) { |
|
515 | - $return[] = ElggMenuItem::factory([ |
|
516 | - 'name' => 'ban', |
|
517 | - 'text' => elgg_echo('ban'), |
|
518 | - 'icon' => 'ban', |
|
519 | - 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
520 | - 'confirm' => true, |
|
521 | - 'section' => 'admin', |
|
522 | - ]); |
|
523 | - } else { |
|
524 | - $return[] = ElggMenuItem::factory([ |
|
525 | - 'name' => 'unban', |
|
526 | - 'text' => elgg_echo('unban'), |
|
527 | - 'icon' => 'ban', |
|
528 | - 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
529 | - 'confirm' => true, |
|
530 | - 'section' => 'admin', |
|
531 | - ]); |
|
532 | - } |
|
533 | - |
|
534 | - $return[] = ElggMenuItem::factory([ |
|
535 | - 'name' => 'delete', |
|
536 | - 'text' => elgg_echo('delete'), |
|
537 | - 'icon' => 'delete', |
|
538 | - 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
539 | - 'confirm' => true, |
|
540 | - 'section' => 'admin', |
|
541 | - ]); |
|
542 | - |
|
543 | - $return[] = ElggMenuItem::factory([ |
|
544 | - 'name' => 'resetpassword', |
|
545 | - 'text' => elgg_echo('resetpassword'), |
|
546 | - 'icon' => 'refresh', |
|
547 | - 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
548 | - 'confirm' => true, |
|
549 | - 'section' => 'admin', |
|
550 | - ]); |
|
551 | - |
|
552 | - if (!$user->isAdmin()) { |
|
553 | - $return[] = ElggMenuItem::factory([ |
|
554 | - 'name' => 'makeadmin', |
|
555 | - 'text' => elgg_echo('makeadmin'), |
|
556 | - 'icon' => 'level-up', |
|
557 | - 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
558 | - 'confirm' => true, |
|
559 | - 'section' => 'admin', |
|
560 | - ]); |
|
561 | - } else { |
|
562 | - $return[] = ElggMenuItem::factory([ |
|
563 | - 'name' => 'removeadmin', |
|
564 | - 'text' => elgg_echo('removeadmin'), |
|
565 | - 'icon' => 'level-down', |
|
566 | - 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
567 | - 'confirm' => true, |
|
568 | - 'section' => 'admin', |
|
569 | - ]); |
|
570 | - } |
|
571 | - |
|
572 | - $return[] = ElggMenuItem::factory([ |
|
573 | - 'name' => 'settings:edit', |
|
574 | - 'text' => elgg_echo('settings:edit'), |
|
575 | - 'icon' => 'cogs', |
|
576 | - 'href' => "settings/user/$user->username", |
|
577 | - 'section' => 'admin', |
|
578 | - ]); |
|
579 | - |
|
580 | - return $return; |
|
483 | + $user = elgg_extract('entity', $params); |
|
484 | + /* @var \ElggUser $user */ |
|
485 | + |
|
486 | + if (!$user instanceof \ElggUser) { |
|
487 | + return; |
|
488 | + } |
|
489 | + |
|
490 | + if (!elgg_is_logged_in()) { |
|
491 | + return; |
|
492 | + } |
|
493 | + |
|
494 | + if ($user->canEdit()) { |
|
495 | + $return[] = ElggMenuItem::factory([ |
|
496 | + 'name' => 'avatar:edit', |
|
497 | + 'text' => elgg_echo('avatar:edit'), |
|
498 | + 'icon' => 'image', |
|
499 | + 'href' => "avatar/edit/$user->username", |
|
500 | + 'section' => (elgg_get_logged_in_user_guid() == $user->guid)? 'action' : 'admin', |
|
501 | + ]); |
|
502 | + } |
|
503 | + |
|
504 | + // prevent admins from banning or deleting themselves |
|
505 | + if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
506 | + return $return; |
|
507 | + } |
|
508 | + |
|
509 | + if (!elgg_is_admin_logged_in()) { |
|
510 | + return $return; |
|
511 | + } |
|
512 | + |
|
513 | + // following items are admin only |
|
514 | + if (!$user->isBanned()) { |
|
515 | + $return[] = ElggMenuItem::factory([ |
|
516 | + 'name' => 'ban', |
|
517 | + 'text' => elgg_echo('ban'), |
|
518 | + 'icon' => 'ban', |
|
519 | + 'href' => "action/admin/user/ban?guid={$user->guid}", |
|
520 | + 'confirm' => true, |
|
521 | + 'section' => 'admin', |
|
522 | + ]); |
|
523 | + } else { |
|
524 | + $return[] = ElggMenuItem::factory([ |
|
525 | + 'name' => 'unban', |
|
526 | + 'text' => elgg_echo('unban'), |
|
527 | + 'icon' => 'ban', |
|
528 | + 'href' => "action/admin/user/unban?guid={$user->guid}", |
|
529 | + 'confirm' => true, |
|
530 | + 'section' => 'admin', |
|
531 | + ]); |
|
532 | + } |
|
533 | + |
|
534 | + $return[] = ElggMenuItem::factory([ |
|
535 | + 'name' => 'delete', |
|
536 | + 'text' => elgg_echo('delete'), |
|
537 | + 'icon' => 'delete', |
|
538 | + 'href' => "action/admin/user/delete?guid={$user->guid}", |
|
539 | + 'confirm' => true, |
|
540 | + 'section' => 'admin', |
|
541 | + ]); |
|
542 | + |
|
543 | + $return[] = ElggMenuItem::factory([ |
|
544 | + 'name' => 'resetpassword', |
|
545 | + 'text' => elgg_echo('resetpassword'), |
|
546 | + 'icon' => 'refresh', |
|
547 | + 'href' => "action/admin/user/resetpassword?guid={$user->guid}", |
|
548 | + 'confirm' => true, |
|
549 | + 'section' => 'admin', |
|
550 | + ]); |
|
551 | + |
|
552 | + if (!$user->isAdmin()) { |
|
553 | + $return[] = ElggMenuItem::factory([ |
|
554 | + 'name' => 'makeadmin', |
|
555 | + 'text' => elgg_echo('makeadmin'), |
|
556 | + 'icon' => 'level-up', |
|
557 | + 'href' => "action/admin/user/makeadmin?guid={$user->guid}", |
|
558 | + 'confirm' => true, |
|
559 | + 'section' => 'admin', |
|
560 | + ]); |
|
561 | + } else { |
|
562 | + $return[] = ElggMenuItem::factory([ |
|
563 | + 'name' => 'removeadmin', |
|
564 | + 'text' => elgg_echo('removeadmin'), |
|
565 | + 'icon' => 'level-down', |
|
566 | + 'href' => "action/admin/user/removeadmin?guid={$user->guid}", |
|
567 | + 'confirm' => true, |
|
568 | + 'section' => 'admin', |
|
569 | + ]); |
|
570 | + } |
|
571 | + |
|
572 | + $return[] = ElggMenuItem::factory([ |
|
573 | + 'name' => 'settings:edit', |
|
574 | + 'text' => elgg_echo('settings:edit'), |
|
575 | + 'icon' => 'cogs', |
|
576 | + 'href' => "settings/user/$user->username", |
|
577 | + 'section' => 'admin', |
|
578 | + ]); |
|
579 | + |
|
580 | + return $return; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -590,15 +590,15 @@ discard block |
||
590 | 590 | * @access private |
591 | 591 | */ |
592 | 592 | function elgg_avatar_page_handler($page) { |
593 | - $user = get_user_by_username(elgg_extract(1, $page)); |
|
594 | - if ($user) { |
|
595 | - elgg_set_page_owner_guid($user->getGUID()); |
|
596 | - } |
|
593 | + $user = get_user_by_username(elgg_extract(1, $page)); |
|
594 | + if ($user) { |
|
595 | + elgg_set_page_owner_guid($user->getGUID()); |
|
596 | + } |
|
597 | 597 | |
598 | - if ($page[0] == 'edit') { |
|
599 | - echo elgg_view_resource("avatar/edit"); |
|
600 | - return true; |
|
601 | - } |
|
598 | + if ($page[0] == 'edit') { |
|
599 | + echo elgg_view_resource("avatar/edit"); |
|
600 | + return true; |
|
601 | + } |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | * @access private |
612 | 612 | */ |
613 | 613 | function _elgg_user_page_handler($page) { |
614 | - echo elgg_view_resource('user/view', [ |
|
615 | - 'guid' => (int) elgg_extract(1, $page), |
|
616 | - ]); |
|
617 | - return true; |
|
614 | + echo elgg_view_resource('user/view', [ |
|
615 | + 'guid' => (int) elgg_extract(1, $page), |
|
616 | + ]); |
|
617 | + return true; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -633,20 +633,20 @@ discard block |
||
633 | 633 | */ |
634 | 634 | function _elgg_user_page_menu($hook, $type, $return, $params) { |
635 | 635 | |
636 | - $owner = elgg_get_page_owner_entity(); |
|
637 | - if (!$owner) { |
|
638 | - return; |
|
639 | - } |
|
636 | + $owner = elgg_get_page_owner_entity(); |
|
637 | + if (!$owner) { |
|
638 | + return; |
|
639 | + } |
|
640 | 640 | |
641 | - $return[] = \ElggMenuItem::factory([ |
|
642 | - 'name' => 'edit_avatar', |
|
643 | - 'href' => "avatar/edit/{$owner->username}", |
|
644 | - 'text' => elgg_echo('avatar:edit'), |
|
645 | - 'section' => '1_profile', |
|
646 | - 'contexts' => ['settings'], |
|
647 | - ]); |
|
641 | + $return[] = \ElggMenuItem::factory([ |
|
642 | + 'name' => 'edit_avatar', |
|
643 | + 'href' => "avatar/edit/{$owner->username}", |
|
644 | + 'text' => elgg_echo('avatar:edit'), |
|
645 | + 'section' => '1_profile', |
|
646 | + 'contexts' => ['settings'], |
|
647 | + ]); |
|
648 | 648 | |
649 | - return $return; |
|
649 | + return $return; |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
@@ -665,68 +665,68 @@ discard block |
||
665 | 665 | */ |
666 | 666 | function _elgg_user_topbar_menu($hook, $type, $return, $params) { |
667 | 667 | |
668 | - $viewer = elgg_get_logged_in_user_entity(); |
|
669 | - if (!$viewer) { |
|
670 | - return; |
|
671 | - } |
|
672 | - |
|
673 | - $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
674 | - $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
675 | - |
|
676 | - // If JS fails here, allow easy access to place where they can upgrade/flush caches |
|
677 | - $href = elgg_is_admin_logged_in() ? 'admin' : '#'; |
|
678 | - |
|
679 | - $return[] = \ElggMenuItem::factory([ |
|
680 | - 'name' => 'account', |
|
681 | - 'text' => elgg_echo('account') . $toggle, |
|
682 | - 'href' => $href, |
|
683 | - 'priority' => 800, |
|
684 | - 'section' => 'alt', |
|
685 | - 'child_menu' => [ |
|
686 | - 'display' => 'dropdown', |
|
687 | - 'class' => 'elgg-topbar-child-menu', |
|
688 | - 'data-position' => json_encode([ |
|
689 | - 'at' => 'right+10px bottom', |
|
690 | - 'my' => 'right top', |
|
691 | - 'collision' => 'fit fit', |
|
692 | - ]), |
|
693 | - ], |
|
694 | - ]); |
|
695 | - |
|
696 | - $return[] = \ElggMenuItem::factory([ |
|
697 | - 'name' => 'usersettings', |
|
698 | - 'parent_name' => 'account', |
|
699 | - 'href' => "settings/user/{$viewer->username}", |
|
700 | - 'text' => elgg_echo('settings'), |
|
701 | - 'icon' => 'cogs', |
|
702 | - 'priority' => 300, |
|
703 | - 'section' => 'alt', |
|
704 | - ]); |
|
705 | - |
|
706 | - if ($viewer->isAdmin()) { |
|
707 | - $return[] = \ElggMenuItem::factory([ |
|
708 | - 'name' => 'administration', |
|
709 | - 'parent_name' => 'account', |
|
710 | - 'href' => 'admin', |
|
711 | - 'text' => elgg_echo('admin'), |
|
712 | - 'icon' => 'tasks', |
|
713 | - 'priority' => 800, |
|
714 | - 'section' => 'alt', |
|
715 | - ]); |
|
716 | - } |
|
717 | - |
|
718 | - $return[] = \ElggMenuItem::factory([ |
|
719 | - 'name' => 'logout', |
|
720 | - 'parent_name' => 'account', |
|
721 | - 'href' => 'action/logout', |
|
722 | - 'text' => elgg_echo('logout'), |
|
723 | - 'icon' => 'sign-out', |
|
724 | - 'is_action' => true, |
|
725 | - 'priority' => 900, |
|
726 | - 'section' => 'alt', |
|
727 | - ]); |
|
728 | - |
|
729 | - return $return; |
|
668 | + $viewer = elgg_get_logged_in_user_entity(); |
|
669 | + if (!$viewer) { |
|
670 | + return; |
|
671 | + } |
|
672 | + |
|
673 | + $toggle = elgg_view_icon('chevron-down', ['class' => 'elgg-state-closed']); |
|
674 | + $toggle .= elgg_view_icon('chevron-up', ['class' => 'elgg-state-opened']); |
|
675 | + |
|
676 | + // If JS fails here, allow easy access to place where they can upgrade/flush caches |
|
677 | + $href = elgg_is_admin_logged_in() ? 'admin' : '#'; |
|
678 | + |
|
679 | + $return[] = \ElggMenuItem::factory([ |
|
680 | + 'name' => 'account', |
|
681 | + 'text' => elgg_echo('account') . $toggle, |
|
682 | + 'href' => $href, |
|
683 | + 'priority' => 800, |
|
684 | + 'section' => 'alt', |
|
685 | + 'child_menu' => [ |
|
686 | + 'display' => 'dropdown', |
|
687 | + 'class' => 'elgg-topbar-child-menu', |
|
688 | + 'data-position' => json_encode([ |
|
689 | + 'at' => 'right+10px bottom', |
|
690 | + 'my' => 'right top', |
|
691 | + 'collision' => 'fit fit', |
|
692 | + ]), |
|
693 | + ], |
|
694 | + ]); |
|
695 | + |
|
696 | + $return[] = \ElggMenuItem::factory([ |
|
697 | + 'name' => 'usersettings', |
|
698 | + 'parent_name' => 'account', |
|
699 | + 'href' => "settings/user/{$viewer->username}", |
|
700 | + 'text' => elgg_echo('settings'), |
|
701 | + 'icon' => 'cogs', |
|
702 | + 'priority' => 300, |
|
703 | + 'section' => 'alt', |
|
704 | + ]); |
|
705 | + |
|
706 | + if ($viewer->isAdmin()) { |
|
707 | + $return[] = \ElggMenuItem::factory([ |
|
708 | + 'name' => 'administration', |
|
709 | + 'parent_name' => 'account', |
|
710 | + 'href' => 'admin', |
|
711 | + 'text' => elgg_echo('admin'), |
|
712 | + 'icon' => 'tasks', |
|
713 | + 'priority' => 800, |
|
714 | + 'section' => 'alt', |
|
715 | + ]); |
|
716 | + } |
|
717 | + |
|
718 | + $return[] = \ElggMenuItem::factory([ |
|
719 | + 'name' => 'logout', |
|
720 | + 'parent_name' => 'account', |
|
721 | + 'href' => 'action/logout', |
|
722 | + 'text' => elgg_echo('logout'), |
|
723 | + 'icon' => 'sign-out', |
|
724 | + 'is_action' => true, |
|
725 | + 'priority' => 900, |
|
726 | + 'section' => 'alt', |
|
727 | + ]); |
|
728 | + |
|
729 | + return $return; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
@@ -740,13 +740,13 @@ discard block |
||
740 | 740 | */ |
741 | 741 | function _elgg_user_set_icon_file($hook, $type, $icon, $params) { |
742 | 742 | |
743 | - $entity = elgg_extract('entity', $params); |
|
744 | - $size = elgg_extract('size', $params, 'medium'); |
|
743 | + $entity = elgg_extract('entity', $params); |
|
744 | + $size = elgg_extract('size', $params, 'medium'); |
|
745 | 745 | |
746 | - $icon->owner_guid = $entity->guid; |
|
747 | - $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
746 | + $icon->owner_guid = $entity->guid; |
|
747 | + $icon->setFilename("profile/{$entity->guid}{$size}.jpg"); |
|
748 | 748 | |
749 | - return $icon; |
|
749 | + return $icon; |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -761,27 +761,27 @@ discard block |
||
761 | 761 | */ |
762 | 762 | function _elgg_user_get_subscriber_unban_action($hook, $type, $return_value, $params) { |
763 | 763 | |
764 | - if (!_elgg_config()->security_notify_user_ban) { |
|
765 | - return; |
|
766 | - } |
|
764 | + if (!_elgg_config()->security_notify_user_ban) { |
|
765 | + return; |
|
766 | + } |
|
767 | 767 | |
768 | - $event = elgg_extract('event', $params); |
|
769 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
770 | - return; |
|
771 | - } |
|
768 | + $event = elgg_extract('event', $params); |
|
769 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
770 | + return; |
|
771 | + } |
|
772 | 772 | |
773 | - if ($event->getAction() !== 'unban') { |
|
774 | - return; |
|
775 | - } |
|
773 | + if ($event->getAction() !== 'unban') { |
|
774 | + return; |
|
775 | + } |
|
776 | 776 | |
777 | - $user = $event->getObject(); |
|
778 | - if (!($user instanceof \ElggUser)) { |
|
779 | - return; |
|
780 | - } |
|
777 | + $user = $event->getObject(); |
|
778 | + if (!($user instanceof \ElggUser)) { |
|
779 | + return; |
|
780 | + } |
|
781 | 781 | |
782 | - $return_value[$user->getGUID()] = ['email']; |
|
782 | + $return_value[$user->getGUID()] = ['email']; |
|
783 | 783 | |
784 | - return $return_value; |
|
784 | + return $return_value; |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -797,30 +797,30 @@ discard block |
||
797 | 797 | */ |
798 | 798 | function _elgg_user_ban_notification($event, $type, $user) { |
799 | 799 | |
800 | - if (!_elgg_config()->security_notify_user_ban) { |
|
801 | - return; |
|
802 | - } |
|
800 | + if (!_elgg_config()->security_notify_user_ban) { |
|
801 | + return; |
|
802 | + } |
|
803 | 803 | |
804 | - if (!($user instanceof \ElggUser)) { |
|
805 | - return; |
|
806 | - } |
|
804 | + if (!($user instanceof \ElggUser)) { |
|
805 | + return; |
|
806 | + } |
|
807 | 807 | |
808 | - $site = elgg_get_site_entity(); |
|
809 | - $language = $user->getLanguage(); |
|
808 | + $site = elgg_get_site_entity(); |
|
809 | + $language = $user->getLanguage(); |
|
810 | 810 | |
811 | - $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
812 | - $body = elgg_echo('user:notification:ban:body', [ |
|
813 | - $user->name, |
|
814 | - $site->name, |
|
815 | - $site->getURL(), |
|
816 | - ], $language); |
|
811 | + $subject = elgg_echo('user:notification:ban:subject', [$site->name], $language); |
|
812 | + $body = elgg_echo('user:notification:ban:body', [ |
|
813 | + $user->name, |
|
814 | + $site->name, |
|
815 | + $site->getURL(), |
|
816 | + ], $language); |
|
817 | 817 | |
818 | - $params = [ |
|
819 | - 'action' => 'ban', |
|
820 | - 'object' => $user, |
|
821 | - ]; |
|
818 | + $params = [ |
|
819 | + 'action' => 'ban', |
|
820 | + 'object' => $user, |
|
821 | + ]; |
|
822 | 822 | |
823 | - notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
823 | + notify_user($user->getGUID(), $site->getGUID(), $subject, $body, $params, ['email']); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -835,34 +835,34 @@ discard block |
||
835 | 835 | */ |
836 | 836 | function _elgg_user_prepare_unban_notification($hook, $type, $return_value, $params) { |
837 | 837 | |
838 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
839 | - return; |
|
840 | - } |
|
838 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
839 | + return; |
|
840 | + } |
|
841 | 841 | |
842 | - $recipient = elgg_extract('recipient', $params); |
|
843 | - $object = elgg_extract('object', $params); |
|
844 | - $language = elgg_extract('language', $params); |
|
842 | + $recipient = elgg_extract('recipient', $params); |
|
843 | + $object = elgg_extract('object', $params); |
|
844 | + $language = elgg_extract('language', $params); |
|
845 | 845 | |
846 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
847 | - return; |
|
848 | - } |
|
846 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser)) { |
|
847 | + return; |
|
848 | + } |
|
849 | 849 | |
850 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
851 | - return; |
|
852 | - } |
|
850 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
851 | + return; |
|
852 | + } |
|
853 | 853 | |
854 | - $site = elgg_get_site_entity(); |
|
854 | + $site = elgg_get_site_entity(); |
|
855 | 855 | |
856 | - $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
857 | - $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
858 | - $recipient->name, |
|
859 | - $site->name, |
|
860 | - $site->getURL(), |
|
861 | - ], $language); |
|
856 | + $return_value->subject = elgg_echo('user:notification:unban:subject', [$site->name], $language); |
|
857 | + $return_value->body = elgg_echo('user:notification:unban:body', [ |
|
858 | + $recipient->name, |
|
859 | + $site->name, |
|
860 | + $site->getURL(), |
|
861 | + ], $language); |
|
862 | 862 | |
863 | - $return_value->url = $recipient->getURL(); |
|
863 | + $return_value->url = $recipient->getURL(); |
|
864 | 864 | |
865 | - return $return_value; |
|
865 | + return $return_value; |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
@@ -873,39 +873,39 @@ discard block |
||
873 | 873 | */ |
874 | 874 | function users_init() { |
875 | 875 | |
876 | - elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
877 | - elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
878 | - elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
879 | - elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
880 | - elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
881 | - elgg_register_page_handler('user', '_elgg_user_page_handler'); |
|
876 | + elgg_register_page_handler('register', 'elgg_user_account_page_handler'); |
|
877 | + elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); |
|
878 | + elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler'); |
|
879 | + elgg_register_page_handler('login', 'elgg_user_account_page_handler'); |
|
880 | + elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); |
|
881 | + elgg_register_page_handler('user', '_elgg_user_page_handler'); |
|
882 | 882 | |
883 | - elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
884 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
885 | - elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
883 | + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu'); |
|
884 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_user_page_menu'); |
|
885 | + elgg_register_plugin_hook_handler('register', 'menu:topbar', '_elgg_user_topbar_menu'); |
|
886 | 886 | |
887 | - elgg_register_action('login', '', 'public'); |
|
888 | - elgg_register_action('logout'); |
|
889 | - elgg_register_action('register', '', 'public'); |
|
890 | - elgg_register_action('useradd', '', 'admin'); |
|
891 | - elgg_register_action('avatar/upload'); |
|
892 | - elgg_register_action('avatar/crop'); |
|
893 | - elgg_register_action('avatar/remove'); |
|
887 | + elgg_register_action('login', '', 'public'); |
|
888 | + elgg_register_action('logout'); |
|
889 | + elgg_register_action('register', '', 'public'); |
|
890 | + elgg_register_action('useradd', '', 'admin'); |
|
891 | + elgg_register_action('avatar/upload'); |
|
892 | + elgg_register_action('avatar/crop'); |
|
893 | + elgg_register_action('avatar/remove'); |
|
894 | 894 | |
895 | - elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
895 | + elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); |
|
896 | 896 | |
897 | - elgg_register_action('user/changepassword', '', 'public'); |
|
898 | - elgg_register_action('user/requestnewpassword', '', 'public'); |
|
897 | + elgg_register_action('user/changepassword', '', 'public'); |
|
898 | + elgg_register_action('user/requestnewpassword', '', 'public'); |
|
899 | 899 | |
900 | - // Register the user type |
|
901 | - elgg_register_entity_type('user', ''); |
|
900 | + // Register the user type |
|
901 | + elgg_register_entity_type('user', ''); |
|
902 | 902 | |
903 | - elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
903 | + elgg_register_plugin_hook_handler('entity:icon:file', 'user', '_elgg_user_set_icon_file'); |
|
904 | 904 | |
905 | - elgg_register_notification_event('user', '', ['unban']); |
|
906 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
907 | - elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
908 | - elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
905 | + elgg_register_notification_event('user', '', ['unban']); |
|
906 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_user_get_subscriber_ban_action'); |
|
907 | + elgg_register_event_handler('ban', 'user', '_elgg_user_ban_notification'); |
|
908 | + elgg_register_plugin_hook_handler('prepare', 'notification:unban:user:', '_elgg_user_prepare_unban_notification'); |
|
909 | 909 | |
910 | 910 | } |
911 | 911 | |
@@ -921,14 +921,14 @@ discard block |
||
921 | 921 | * @access private |
922 | 922 | */ |
923 | 923 | function users_test($hook, $type, $value, $params) { |
924 | - $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
925 | - return $value; |
|
924 | + $value[] = Paths::elgg() . "engine/tests/ElggUserTest.php"; |
|
925 | + return $value; |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
929 | 929 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
930 | 930 | */ |
931 | 931 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
932 | - $events->registerHandler('init', 'system', 'users_init', 0); |
|
933 | - $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
932 | + $events->registerHandler('init', 'system', 'users_init', 0); |
|
933 | + $hooks->registerHandler('unit_test', 'system', 'users_test'); |
|
934 | 934 | }; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | if ($level !== false) { |
86 | 86 | $this->level = $level; |
87 | 87 | } else { |
88 | - $this->warn(__METHOD__ .": invalid level ignored."); |
|
88 | + $this->warn(__METHOD__.": invalid level ignored."); |
|
89 | 89 | } |
90 | 90 | return; |
91 | 91 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (isset(self::$levels[$level])) { |
94 | 94 | $this->level = $level; |
95 | 95 | } else { |
96 | - $this->warn(__METHOD__ .": invalid level ignored."); |
|
96 | + $this->warn(__METHOD__.": invalid level ignored."); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 |
@@ -14,284 +14,284 @@ |
||
14 | 14 | */ |
15 | 15 | class Logger { |
16 | 16 | |
17 | - const OFF = 0; |
|
18 | - const ERROR = 400; |
|
19 | - const WARNING = 300; |
|
20 | - const NOTICE = 250; |
|
21 | - const INFO = 200; |
|
22 | - |
|
23 | - protected static $levels = [ |
|
24 | - 0 => 'OFF', |
|
25 | - 200 => 'INFO', |
|
26 | - 250 => 'NOTICE', |
|
27 | - 300 => 'WARNING', |
|
28 | - 400 => 'ERROR', |
|
29 | - ]; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var int The logging level |
|
33 | - */ |
|
34 | - protected $level = self::ERROR; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var bool Display to user? |
|
38 | - */ |
|
39 | - protected $display = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var PluginHooksService |
|
43 | - */ |
|
44 | - protected $hooks; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var Context |
|
48 | - */ |
|
49 | - private $context; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - private $disabled_stack; |
|
55 | - |
|
56 | - /** |
|
57 | - * Constructor |
|
58 | - * |
|
59 | - * @param PluginHooksService $hooks Hooks service |
|
60 | - * @param Context $context Context service |
|
61 | - */ |
|
62 | - public function __construct(PluginHooksService $hooks, Context $context) { |
|
63 | - $this->hooks = $hooks; |
|
64 | - $this->context = $context; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Set the logging level |
|
69 | - * |
|
70 | - * @param int $level The logging level |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function setLevel($level) { |
|
74 | - if (!$level) { |
|
75 | - // 0 or empty string |
|
76 | - $this->level = self::OFF; |
|
77 | - return; |
|
78 | - } |
|
79 | - |
|
80 | - // @todo Elgg has used string constants for logging levels |
|
81 | - if (is_string($level)) { |
|
82 | - $level = strtoupper($level); |
|
83 | - $level = array_search($level, self::$levels); |
|
84 | - |
|
85 | - if ($level !== false) { |
|
86 | - $this->level = $level; |
|
87 | - } else { |
|
88 | - $this->warn(__METHOD__ .": invalid level ignored."); |
|
89 | - } |
|
90 | - return; |
|
91 | - } |
|
92 | - |
|
93 | - if (isset(self::$levels[$level])) { |
|
94 | - $this->level = $level; |
|
95 | - } else { |
|
96 | - $this->warn(__METHOD__ .": invalid level ignored."); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get the current logging level |
|
102 | - * |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getLevel() { |
|
106 | - return $this->level; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Set whether the logging should be displayed to the user |
|
111 | - * |
|
112 | - * Whether data is actually displayed to the user depends on this setting |
|
113 | - * and other factors such as whether we are generating a JavaScript or CSS |
|
114 | - * file. |
|
115 | - * |
|
116 | - * @param bool $display Whether to display logging |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function setDisplay($display) { |
|
120 | - $this->display = $display; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Add a message to the log |
|
125 | - * |
|
126 | - * @param string $message The message to log |
|
127 | - * @param int $level The logging level |
|
128 | - * @return bool Whether the messages was logged |
|
129 | - */ |
|
130 | - public function log($message, $level = self::NOTICE) { |
|
131 | - if ($this->disabled_stack) { |
|
132 | - // capture to top of stack |
|
133 | - end($this->disabled_stack); |
|
134 | - $key = key($this->disabled_stack); |
|
135 | - $this->disabled_stack[$key][] = [ |
|
136 | - 'message' => $message, |
|
137 | - 'level' => $level, |
|
138 | - ]; |
|
139 | - } |
|
140 | - |
|
141 | - if ($this->level == self::OFF || $level < $this->level) { |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - if (!array_key_exists($level, self::$levels)) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - |
|
149 | - // when capturing, still use consistent return value |
|
150 | - if ($this->disabled_stack) { |
|
151 | - return true; |
|
152 | - } |
|
153 | - |
|
154 | - $levelString = self::$levels[$level]; |
|
155 | - |
|
156 | - // notices and below never displayed to user |
|
157 | - $display = $this->display && $level > self::NOTICE; |
|
158 | - |
|
159 | - $this->process("$levelString: $message", $display, $level); |
|
160 | - |
|
161 | - return true; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Log message at the ERROR level |
|
166 | - * |
|
167 | - * @param string $message The message to log |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function error($message) { |
|
171 | - return $this->log($message, self::ERROR); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Log message at the WARNING level |
|
176 | - * |
|
177 | - * @param string $message The message to log |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function warn($message) { |
|
181 | - return $this->log($message, self::WARNING); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Log message at the NOTICE level |
|
186 | - * |
|
187 | - * @param string $message The message to log |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function notice($message) { |
|
191 | - return $this->log($message, self::NOTICE); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Log message at the INFO level |
|
196 | - * |
|
197 | - * @param string $message The message to log |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function info($message) { |
|
201 | - return $this->log($message, self::INFO); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Dump data to log or screen |
|
206 | - * |
|
207 | - * @param mixed $data The data to log |
|
208 | - * @param bool $display Whether to include this in the HTML page |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function dump($data, $display = true) { |
|
212 | - $this->process($data, $display, self::ERROR); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Process logging data |
|
217 | - * |
|
218 | - * @param mixed $data The data to process |
|
219 | - * @param bool $display Whether to display the data to the user. Otherwise log it. |
|
220 | - * @param int $level The logging level for this data |
|
221 | - * @return void |
|
222 | - */ |
|
223 | - protected function process($data, $display, $level) { |
|
17 | + const OFF = 0; |
|
18 | + const ERROR = 400; |
|
19 | + const WARNING = 300; |
|
20 | + const NOTICE = 250; |
|
21 | + const INFO = 200; |
|
22 | + |
|
23 | + protected static $levels = [ |
|
24 | + 0 => 'OFF', |
|
25 | + 200 => 'INFO', |
|
26 | + 250 => 'NOTICE', |
|
27 | + 300 => 'WARNING', |
|
28 | + 400 => 'ERROR', |
|
29 | + ]; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var int The logging level |
|
33 | + */ |
|
34 | + protected $level = self::ERROR; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var bool Display to user? |
|
38 | + */ |
|
39 | + protected $display = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var PluginHooksService |
|
43 | + */ |
|
44 | + protected $hooks; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var Context |
|
48 | + */ |
|
49 | + private $context; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + private $disabled_stack; |
|
55 | + |
|
56 | + /** |
|
57 | + * Constructor |
|
58 | + * |
|
59 | + * @param PluginHooksService $hooks Hooks service |
|
60 | + * @param Context $context Context service |
|
61 | + */ |
|
62 | + public function __construct(PluginHooksService $hooks, Context $context) { |
|
63 | + $this->hooks = $hooks; |
|
64 | + $this->context = $context; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Set the logging level |
|
69 | + * |
|
70 | + * @param int $level The logging level |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function setLevel($level) { |
|
74 | + if (!$level) { |
|
75 | + // 0 or empty string |
|
76 | + $this->level = self::OFF; |
|
77 | + return; |
|
78 | + } |
|
79 | + |
|
80 | + // @todo Elgg has used string constants for logging levels |
|
81 | + if (is_string($level)) { |
|
82 | + $level = strtoupper($level); |
|
83 | + $level = array_search($level, self::$levels); |
|
84 | + |
|
85 | + if ($level !== false) { |
|
86 | + $this->level = $level; |
|
87 | + } else { |
|
88 | + $this->warn(__METHOD__ .": invalid level ignored."); |
|
89 | + } |
|
90 | + return; |
|
91 | + } |
|
92 | + |
|
93 | + if (isset(self::$levels[$level])) { |
|
94 | + $this->level = $level; |
|
95 | + } else { |
|
96 | + $this->warn(__METHOD__ .": invalid level ignored."); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get the current logging level |
|
102 | + * |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getLevel() { |
|
106 | + return $this->level; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Set whether the logging should be displayed to the user |
|
111 | + * |
|
112 | + * Whether data is actually displayed to the user depends on this setting |
|
113 | + * and other factors such as whether we are generating a JavaScript or CSS |
|
114 | + * file. |
|
115 | + * |
|
116 | + * @param bool $display Whether to display logging |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function setDisplay($display) { |
|
120 | + $this->display = $display; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Add a message to the log |
|
125 | + * |
|
126 | + * @param string $message The message to log |
|
127 | + * @param int $level The logging level |
|
128 | + * @return bool Whether the messages was logged |
|
129 | + */ |
|
130 | + public function log($message, $level = self::NOTICE) { |
|
131 | + if ($this->disabled_stack) { |
|
132 | + // capture to top of stack |
|
133 | + end($this->disabled_stack); |
|
134 | + $key = key($this->disabled_stack); |
|
135 | + $this->disabled_stack[$key][] = [ |
|
136 | + 'message' => $message, |
|
137 | + 'level' => $level, |
|
138 | + ]; |
|
139 | + } |
|
140 | + |
|
141 | + if ($this->level == self::OFF || $level < $this->level) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + if (!array_key_exists($level, self::$levels)) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + |
|
149 | + // when capturing, still use consistent return value |
|
150 | + if ($this->disabled_stack) { |
|
151 | + return true; |
|
152 | + } |
|
153 | + |
|
154 | + $levelString = self::$levels[$level]; |
|
155 | + |
|
156 | + // notices and below never displayed to user |
|
157 | + $display = $this->display && $level > self::NOTICE; |
|
158 | + |
|
159 | + $this->process("$levelString: $message", $display, $level); |
|
160 | + |
|
161 | + return true; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Log message at the ERROR level |
|
166 | + * |
|
167 | + * @param string $message The message to log |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + public function error($message) { |
|
171 | + return $this->log($message, self::ERROR); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Log message at the WARNING level |
|
176 | + * |
|
177 | + * @param string $message The message to log |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function warn($message) { |
|
181 | + return $this->log($message, self::WARNING); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Log message at the NOTICE level |
|
186 | + * |
|
187 | + * @param string $message The message to log |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function notice($message) { |
|
191 | + return $this->log($message, self::NOTICE); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Log message at the INFO level |
|
196 | + * |
|
197 | + * @param string $message The message to log |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function info($message) { |
|
201 | + return $this->log($message, self::INFO); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Dump data to log or screen |
|
206 | + * |
|
207 | + * @param mixed $data The data to log |
|
208 | + * @param bool $display Whether to include this in the HTML page |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function dump($data, $display = true) { |
|
212 | + $this->process($data, $display, self::ERROR); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Process logging data |
|
217 | + * |
|
218 | + * @param mixed $data The data to process |
|
219 | + * @param bool $display Whether to display the data to the user. Otherwise log it. |
|
220 | + * @param int $level The logging level for this data |
|
221 | + * @return void |
|
222 | + */ |
|
223 | + protected function process($data, $display, $level) { |
|
224 | 224 | |
225 | - // plugin can return false to stop the default logging method |
|
226 | - $params = [ |
|
227 | - 'level' => $level, |
|
228 | - 'msg' => $data, |
|
229 | - 'display' => $display, |
|
230 | - 'to_screen' => $display, |
|
231 | - ]; |
|
232 | - |
|
233 | - if (!$this->hooks->trigger('debug', 'log', $params, true)) { |
|
234 | - return; |
|
235 | - } |
|
236 | - |
|
237 | - // Do not want to write to JS or CSS pages |
|
238 | - if ($this->context->contains('js') || $this->context->contains('css')) { |
|
239 | - $display = false; |
|
240 | - } |
|
241 | - |
|
242 | - // don't display in simplecache requests |
|
243 | - $path = substr(current_page_url(), strlen(elgg_get_site_url())); |
|
244 | - if (preg_match('~^(cache|action|serve-file)/~', $path)) { |
|
245 | - $display = false; |
|
246 | - } |
|
247 | - |
|
248 | - if ($display == true) { |
|
249 | - echo '<pre class="elgg-logger-data">'; |
|
250 | - echo htmlspecialchars(print_r($data, true), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
251 | - echo '</pre>'; |
|
252 | - } |
|
225 | + // plugin can return false to stop the default logging method |
|
226 | + $params = [ |
|
227 | + 'level' => $level, |
|
228 | + 'msg' => $data, |
|
229 | + 'display' => $display, |
|
230 | + 'to_screen' => $display, |
|
231 | + ]; |
|
232 | + |
|
233 | + if (!$this->hooks->trigger('debug', 'log', $params, true)) { |
|
234 | + return; |
|
235 | + } |
|
236 | + |
|
237 | + // Do not want to write to JS or CSS pages |
|
238 | + if ($this->context->contains('js') || $this->context->contains('css')) { |
|
239 | + $display = false; |
|
240 | + } |
|
241 | + |
|
242 | + // don't display in simplecache requests |
|
243 | + $path = substr(current_page_url(), strlen(elgg_get_site_url())); |
|
244 | + if (preg_match('~^(cache|action|serve-file)/~', $path)) { |
|
245 | + $display = false; |
|
246 | + } |
|
247 | + |
|
248 | + if ($display == true) { |
|
249 | + echo '<pre class="elgg-logger-data">'; |
|
250 | + echo htmlspecialchars(print_r($data, true), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
|
251 | + echo '</pre>'; |
|
252 | + } |
|
253 | 253 | |
254 | - error_log(print_r($data, true)); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Temporarily disable logging and capture logs (before tests) |
|
259 | - * |
|
260 | - * Call disable() before your tests and enable() after. enable() will return a list of |
|
261 | - * calls to log() (and helper methods) that were not acted upon. |
|
262 | - * |
|
263 | - * @note This behaves like a stack. You must call enable() for each disable() call. |
|
264 | - * |
|
265 | - * @return void |
|
266 | - * @see enable |
|
267 | - * @access private |
|
268 | - * @internal |
|
269 | - */ |
|
270 | - public function disable() { |
|
271 | - $this->disabled_stack[] = []; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Restore logging and get record of log calls (after tests) |
|
276 | - * |
|
277 | - * @return array |
|
278 | - * @see disable |
|
279 | - * @access private |
|
280 | - * @internal |
|
281 | - */ |
|
282 | - public function enable() { |
|
283 | - return array_pop($this->disabled_stack); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Reset the hooks service for this instance (testing) |
|
288 | - * |
|
289 | - * @return void |
|
290 | - * @access private |
|
291 | - * @internal |
|
292 | - */ |
|
293 | - public function setHooks(PluginHooksService $hooks) { |
|
294 | - $this->hooks = $hooks; |
|
295 | - } |
|
254 | + error_log(print_r($data, true)); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Temporarily disable logging and capture logs (before tests) |
|
259 | + * |
|
260 | + * Call disable() before your tests and enable() after. enable() will return a list of |
|
261 | + * calls to log() (and helper methods) that were not acted upon. |
|
262 | + * |
|
263 | + * @note This behaves like a stack. You must call enable() for each disable() call. |
|
264 | + * |
|
265 | + * @return void |
|
266 | + * @see enable |
|
267 | + * @access private |
|
268 | + * @internal |
|
269 | + */ |
|
270 | + public function disable() { |
|
271 | + $this->disabled_stack[] = []; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Restore logging and get record of log calls (after tests) |
|
276 | + * |
|
277 | + * @return array |
|
278 | + * @see disable |
|
279 | + * @access private |
|
280 | + * @internal |
|
281 | + */ |
|
282 | + public function enable() { |
|
283 | + return array_pop($this->disabled_stack); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Reset the hooks service for this instance (testing) |
|
288 | + * |
|
289 | + * @return void |
|
290 | + * @access private |
|
291 | + * @internal |
|
292 | + */ |
|
293 | + public function setHooks(PluginHooksService $hooks) { |
|
294 | + $this->hooks = $hooks; |
|
295 | + } |
|
296 | 296 | } |
297 | 297 |
@@ -8,14 +8,14 @@ discard block |
||
8 | 8 | $variables = elgg_get_config('pages'); |
9 | 9 | $input = []; |
10 | 10 | foreach ($variables as $name => $type) { |
11 | - if ($name == 'title') { |
|
12 | - $input[$name] = elgg_get_title_input(); |
|
13 | - } else { |
|
14 | - $input[$name] = get_input($name); |
|
15 | - } |
|
16 | - if ($type == 'tags') { |
|
17 | - $input[$name] = string_to_tag_array($input[$name]); |
|
18 | - } |
|
11 | + if ($name == 'title') { |
|
12 | + $input[$name] = elgg_get_title_input(); |
|
13 | + } else { |
|
14 | + $input[$name] = get_input($name); |
|
15 | + } |
|
16 | + if ($type == 'tags') { |
|
17 | + $input[$name] = string_to_tag_array($input[$name]); |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | // Get guids |
@@ -26,78 +26,78 @@ discard block |
||
26 | 26 | elgg_make_sticky_form('page'); |
27 | 27 | |
28 | 28 | if (!$input['title']) { |
29 | - register_error(elgg_echo('pages:error:no_title')); |
|
30 | - forward(REFERER); |
|
29 | + register_error(elgg_echo('pages:error:no_title')); |
|
30 | + forward(REFERER); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | if ($page_guid) { |
34 | - $page = get_entity($page_guid); |
|
35 | - if (!pages_is_page($page) || !$page->canEdit()) { |
|
36 | - register_error(elgg_echo('pages:cantedit')); |
|
37 | - forward(REFERER); |
|
38 | - } |
|
39 | - $new_page = false; |
|
34 | + $page = get_entity($page_guid); |
|
35 | + if (!pages_is_page($page) || !$page->canEdit()) { |
|
36 | + register_error(elgg_echo('pages:cantedit')); |
|
37 | + forward(REFERER); |
|
38 | + } |
|
39 | + $new_page = false; |
|
40 | 40 | } else { |
41 | - $page = new ElggObject(); |
|
42 | - if ($parent_guid) { |
|
43 | - $page->subtype = 'page'; |
|
44 | - } else { |
|
45 | - $page->subtype = 'page_top'; |
|
46 | - } |
|
47 | - $new_page = true; |
|
41 | + $page = new ElggObject(); |
|
42 | + if ($parent_guid) { |
|
43 | + $page->subtype = 'page'; |
|
44 | + } else { |
|
45 | + $page->subtype = 'page_top'; |
|
46 | + } |
|
47 | + $new_page = true; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | if (sizeof($input) > 0) { |
51 | - // don't change access if not an owner/admin |
|
52 | - $user = elgg_get_logged_in_user_entity(); |
|
53 | - $can_change_access = true; |
|
51 | + // don't change access if not an owner/admin |
|
52 | + $user = elgg_get_logged_in_user_entity(); |
|
53 | + $can_change_access = true; |
|
54 | 54 | |
55 | - if ($user && $page) { |
|
56 | - $can_change_access = $user->isAdmin() || $user->getGUID() == $page->owner_guid; |
|
57 | - } |
|
55 | + if ($user && $page) { |
|
56 | + $can_change_access = $user->isAdmin() || $user->getGUID() == $page->owner_guid; |
|
57 | + } |
|
58 | 58 | |
59 | - foreach ($input as $name => $value) { |
|
60 | - if (($name == 'access_id' || $name == 'write_access_id') && !$can_change_access) { |
|
61 | - continue; |
|
62 | - } |
|
63 | - if ($name == 'parent_guid') { |
|
64 | - continue; |
|
65 | - } |
|
66 | - |
|
67 | - $page->$name = $value; |
|
68 | - } |
|
59 | + foreach ($input as $name => $value) { |
|
60 | + if (($name == 'access_id' || $name == 'write_access_id') && !$can_change_access) { |
|
61 | + continue; |
|
62 | + } |
|
63 | + if ($name == 'parent_guid') { |
|
64 | + continue; |
|
65 | + } |
|
66 | + |
|
67 | + $page->$name = $value; |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // need to add check to make sure user can write to container |
72 | 72 | $page->container_guid = $container_guid; |
73 | 73 | |
74 | 74 | if ($parent_guid && $parent_guid != $page_guid) { |
75 | - // Check if parent isn't below the page in the tree |
|
76 | - if ($page_guid) { |
|
77 | - $tree_page = get_entity($parent_guid); |
|
78 | - while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) { |
|
79 | - $tree_page = get_entity($tree_page->parent_guid); |
|
80 | - } |
|
81 | - // If is below, bring all child elements forward |
|
82 | - if ($page_guid == $tree_page->guid) { |
|
83 | - $previous_parent = $page->parent_guid; |
|
84 | - |
|
85 | - $children = new ElggBatch('elgg_get_entities_from_metadata', [ |
|
86 | - 'metadata_name' => 'parent_guid', |
|
87 | - 'metadata_value' => $page->guid, |
|
88 | - 'limit' => 0, |
|
89 | - ]); |
|
90 | - foreach ($children as $child) { |
|
91 | - $child->parent_guid = $previous_parent; |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - $page->parent_guid = $parent_guid; |
|
75 | + // Check if parent isn't below the page in the tree |
|
76 | + if ($page_guid) { |
|
77 | + $tree_page = get_entity($parent_guid); |
|
78 | + while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) { |
|
79 | + $tree_page = get_entity($tree_page->parent_guid); |
|
80 | + } |
|
81 | + // If is below, bring all child elements forward |
|
82 | + if ($page_guid == $tree_page->guid) { |
|
83 | + $previous_parent = $page->parent_guid; |
|
84 | + |
|
85 | + $children = new ElggBatch('elgg_get_entities_from_metadata', [ |
|
86 | + 'metadata_name' => 'parent_guid', |
|
87 | + 'metadata_value' => $page->guid, |
|
88 | + 'limit' => 0, |
|
89 | + ]); |
|
90 | + foreach ($children as $child) { |
|
91 | + $child->parent_guid = $previous_parent; |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + $page->parent_guid = $parent_guid; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | if (!$page->save()) { |
99 | - register_error(elgg_echo('pages:notsaved')); |
|
100 | - forward(REFERER); |
|
99 | + register_error(elgg_echo('pages:notsaved')); |
|
100 | + forward(REFERER); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | elgg_clear_sticky_form('page'); |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | system_message(elgg_echo('pages:saved')); |
109 | 109 | |
110 | 110 | if ($new_page) { |
111 | - elgg_create_river_item([ |
|
112 | - 'view' => 'river/object/page/create', |
|
113 | - 'action_type' => 'create', |
|
114 | - 'subject_guid' => elgg_get_logged_in_user_guid(), |
|
115 | - 'object_guid' => $page->guid, |
|
116 | - ]); |
|
111 | + elgg_create_river_item([ |
|
112 | + 'view' => 'river/object/page/create', |
|
113 | + 'action_type' => 'create', |
|
114 | + 'subject_guid' => elgg_get_logged_in_user_guid(), |
|
115 | + 'object_guid' => $page->guid, |
|
116 | + ]); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | forward($page->getURL()); |
@@ -13,33 +13,33 @@ discard block |
||
13 | 13 | // Get group fields |
14 | 14 | $input = []; |
15 | 15 | foreach (elgg_get_config('group') as $shortname => $valuetype) { |
16 | - $value = get_input($shortname); |
|
17 | - |
|
18 | - if ($value === null) { |
|
19 | - // only submitted fields should be updated |
|
20 | - continue; |
|
21 | - } |
|
22 | - |
|
23 | - $input[$shortname] = $value; |
|
24 | - |
|
25 | - // @todo treat profile fields as unescaped: don't filter, encode on output |
|
26 | - if (is_array($input[$shortname])) { |
|
27 | - array_walk_recursive($input[$shortname], function (&$v) { |
|
28 | - $v = elgg_html_decode($v); |
|
29 | - }); |
|
30 | - } else { |
|
31 | - $input[$shortname] = elgg_html_decode($input[$shortname]); |
|
32 | - } |
|
33 | - |
|
34 | - if ($valuetype == 'tags') { |
|
35 | - $input[$shortname] = string_to_tag_array($input[$shortname]); |
|
36 | - } |
|
16 | + $value = get_input($shortname); |
|
17 | + |
|
18 | + if ($value === null) { |
|
19 | + // only submitted fields should be updated |
|
20 | + continue; |
|
21 | + } |
|
22 | + |
|
23 | + $input[$shortname] = $value; |
|
24 | + |
|
25 | + // @todo treat profile fields as unescaped: don't filter, encode on output |
|
26 | + if (is_array($input[$shortname])) { |
|
27 | + array_walk_recursive($input[$shortname], function (&$v) { |
|
28 | + $v = elgg_html_decode($v); |
|
29 | + }); |
|
30 | + } else { |
|
31 | + $input[$shortname] = elgg_html_decode($input[$shortname]); |
|
32 | + } |
|
33 | + |
|
34 | + if ($valuetype == 'tags') { |
|
35 | + $input[$shortname] = string_to_tag_array($input[$shortname]); |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // only set if submitted |
40 | 40 | $name = elgg_get_title_input('name', null); |
41 | 41 | if ($name !== null) { |
42 | - $input['name'] = $name; |
|
42 | + $input['name'] = $name; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $user = elgg_get_logged_in_user_entity(); |
@@ -47,78 +47,78 @@ discard block |
||
47 | 47 | $group_guid = (int) get_input('group_guid'); |
48 | 48 | |
49 | 49 | if ($group_guid) { |
50 | - $is_new_group = false; |
|
51 | - $group = get_entity($group_guid); |
|
52 | - if (!$group instanceof ElggGroup || !$group->canEdit()) { |
|
53 | - $error = elgg_echo('groups:cantedit'); |
|
54 | - return elgg_error_response($error); |
|
55 | - } |
|
50 | + $is_new_group = false; |
|
51 | + $group = get_entity($group_guid); |
|
52 | + if (!$group instanceof ElggGroup || !$group->canEdit()) { |
|
53 | + $error = elgg_echo('groups:cantedit'); |
|
54 | + return elgg_error_response($error); |
|
55 | + } |
|
56 | 56 | } else { |
57 | - if (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) { |
|
58 | - $error = elgg_echo('groups:cantcreate'); |
|
59 | - return elgg_error_response($error); |
|
60 | - } |
|
57 | + if (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !$user->isAdmin()) { |
|
58 | + $error = elgg_echo('groups:cantcreate'); |
|
59 | + return elgg_error_response($error); |
|
60 | + } |
|
61 | 61 | |
62 | - $container_guid = get_input('container_guid', $user->guid); |
|
63 | - $container = get_entity($container_guid); |
|
62 | + $container_guid = get_input('container_guid', $user->guid); |
|
63 | + $container = get_entity($container_guid); |
|
64 | 64 | |
65 | - if (!$container || !$container->canWriteToContainer($user->guid, 'group')) { |
|
66 | - $error = elgg_echo('groups:cantcreate'); |
|
67 | - return elgg_error_response($error); |
|
68 | - } |
|
65 | + if (!$container || !$container->canWriteToContainer($user->guid, 'group')) { |
|
66 | + $error = elgg_echo('groups:cantcreate'); |
|
67 | + return elgg_error_response($error); |
|
68 | + } |
|
69 | 69 | |
70 | - $is_new_group = true; |
|
71 | - $group = new ElggGroup(); |
|
72 | - $group->container_guid = $container->guid; |
|
70 | + $is_new_group = true; |
|
71 | + $group = new ElggGroup(); |
|
72 | + $group->container_guid = $container->guid; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Assume we can edit or this is a new group |
76 | 76 | foreach ($input as $shortname => $value) { |
77 | - if ($value === '' && !in_array($shortname, ['name', 'description'])) { |
|
78 | - // The group profile displays all profile fields that have a value. |
|
79 | - // We don't want to display fields with empty string value, so we |
|
80 | - // remove the metadata completely. |
|
81 | - $group->deleteMetadata($shortname); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - $group->$shortname = $value; |
|
77 | + if ($value === '' && !in_array($shortname, ['name', 'description'])) { |
|
78 | + // The group profile displays all profile fields that have a value. |
|
79 | + // We don't want to display fields with empty string value, so we |
|
80 | + // remove the metadata completely. |
|
81 | + $group->deleteMetadata($shortname); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + $group->$shortname = $value; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Validate create |
89 | 89 | if (!$group->name) { |
90 | - return elgg_error_response(elgg_echo('groups:notitle')); |
|
90 | + return elgg_error_response(elgg_echo('groups:notitle')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Set group tool options (only pass along saved entities) |
94 | 94 | $tool_entity = !$is_new_group ? $group : null; |
95 | 95 | $tool_options = groups_get_group_tool_options($tool_entity); |
96 | 96 | if ($tool_options) { |
97 | - foreach ($tool_options as $group_option) { |
|
98 | - $option_toggle_name = $group_option->name . "_enable"; |
|
99 | - $option_default = $group_option->default_on ? 'yes' : 'no'; |
|
100 | - $value = get_input($option_toggle_name); |
|
101 | - |
|
102 | - // if already has option set, don't change if no submission |
|
103 | - if ($group->$option_toggle_name && $value === null) { |
|
104 | - continue; |
|
105 | - } |
|
106 | - |
|
107 | - $group->$option_toggle_name = $value ? $value : $option_default; |
|
108 | - } |
|
97 | + foreach ($tool_options as $group_option) { |
|
98 | + $option_toggle_name = $group_option->name . "_enable"; |
|
99 | + $option_default = $group_option->default_on ? 'yes' : 'no'; |
|
100 | + $value = get_input($option_toggle_name); |
|
101 | + |
|
102 | + // if already has option set, don't change if no submission |
|
103 | + if ($group->$option_toggle_name && $value === null) { |
|
104 | + continue; |
|
105 | + } |
|
106 | + |
|
107 | + $group->$option_toggle_name = $value ? $value : $option_default; |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Group membership - should these be treated with same constants as access permissions? |
112 | 112 | $value = get_input('membership'); |
113 | 113 | if ($group->membership === null || $value !== null) { |
114 | - $is_public_membership = ($value == ACCESS_PUBLIC); |
|
115 | - $group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE; |
|
114 | + $is_public_membership = ($value == ACCESS_PUBLIC); |
|
115 | + $group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $group->setContentAccessMode((string) get_input('content_access_mode')); |
119 | 119 | |
120 | 120 | if ($is_new_group) { |
121 | - $group->access_id = ACCESS_PUBLIC; |
|
121 | + $group->access_id = ACCESS_PUBLIC; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $old_owner_guid = $is_new_group ? 0 : $group->owner_guid; |
@@ -127,24 +127,24 @@ discard block |
||
127 | 127 | $new_owner_guid = ($value === null) ? $old_owner_guid : (int) $value; |
128 | 128 | |
129 | 129 | if (!$is_new_group && $new_owner_guid && $new_owner_guid != $old_owner_guid) { |
130 | - // verify new owner is member and old owner/admin is logged in |
|
131 | - if ($group->isMember(get_user($new_owner_guid)) && ($old_owner_guid == $user->guid || $user->isAdmin())) { |
|
132 | - $group->owner_guid = $new_owner_guid; |
|
133 | - if ($group->container_guid == $old_owner_guid) { |
|
134 | - // Even though this action defaults container_guid to the logged in user guid, |
|
135 | - // the group may have initially been created with a custom script that assigned |
|
136 | - // a different container entity. We want to make sure we preserve the original |
|
137 | - // container if it the group is not contained by the original owner. |
|
138 | - $group->container_guid = $new_owner_guid; |
|
139 | - } |
|
140 | - } |
|
130 | + // verify new owner is member and old owner/admin is logged in |
|
131 | + if ($group->isMember(get_user($new_owner_guid)) && ($old_owner_guid == $user->guid || $user->isAdmin())) { |
|
132 | + $group->owner_guid = $new_owner_guid; |
|
133 | + if ($group->container_guid == $old_owner_guid) { |
|
134 | + // Even though this action defaults container_guid to the logged in user guid, |
|
135 | + // the group may have initially been created with a custom script that assigned |
|
136 | + // a different container entity. We want to make sure we preserve the original |
|
137 | + // container if it the group is not contained by the original owner. |
|
138 | + $group->container_guid = $new_owner_guid; |
|
139 | + } |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | if ($is_new_group) { |
144 | - // if new group, we need to save so group acl gets set in event handler |
|
145 | - if (!$group->save()) { |
|
146 | - return elgg_error_response(elgg_echo('groups:save_error')); |
|
147 | - } |
|
144 | + // if new group, we need to save so group acl gets set in event handler |
|
145 | + if (!$group->save()) { |
|
146 | + return elgg_error_response(elgg_echo('groups:save_error')); |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // Invisible group support |
@@ -152,26 +152,26 @@ discard block |
||
152 | 152 | // is an odd requirement and should be removed. Either the acl creation happens |
153 | 153 | // in the action or the visibility moves to a plugin hook |
154 | 154 | if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') { |
155 | - $value = get_input('vis'); |
|
156 | - if ($is_new_group || $value !== null) { |
|
157 | - $visibility = (int) $value; |
|
158 | - |
|
159 | - if ($visibility == ACCESS_PRIVATE) { |
|
160 | - // Make this group visible only to group members. We need to use |
|
161 | - // ACCESS_PRIVATE on the form and convert it to group_acl here |
|
162 | - // because new groups do not have acl until they have been saved once. |
|
163 | - $visibility = $group->group_acl; |
|
164 | - |
|
165 | - // Force all new group content to be available only to members |
|
166 | - $group->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY); |
|
167 | - } |
|
168 | - |
|
169 | - $group->access_id = $visibility; |
|
170 | - } |
|
155 | + $value = get_input('vis'); |
|
156 | + if ($is_new_group || $value !== null) { |
|
157 | + $visibility = (int) $value; |
|
158 | + |
|
159 | + if ($visibility == ACCESS_PRIVATE) { |
|
160 | + // Make this group visible only to group members. We need to use |
|
161 | + // ACCESS_PRIVATE on the form and convert it to group_acl here |
|
162 | + // because new groups do not have acl until they have been saved once. |
|
163 | + $visibility = $group->group_acl; |
|
164 | + |
|
165 | + // Force all new group content to be available only to members |
|
166 | + $group->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY); |
|
167 | + } |
|
168 | + |
|
169 | + $group->access_id = $visibility; |
|
170 | + } |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | if (!$group->save()) { |
174 | - return elgg_error_response(elgg_echo('groups:save_error')); |
|
174 | + return elgg_error_response(elgg_echo('groups:save_error')); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // group saved so clear sticky form |
@@ -179,21 +179,21 @@ discard block |
||
179 | 179 | |
180 | 180 | // group creator needs to be member of new group and river entry created |
181 | 181 | if ($is_new_group) { |
182 | - // @todo this should not be necessary... |
|
183 | - elgg_set_page_owner_guid($group->guid); |
|
184 | - |
|
185 | - $group->join($user); |
|
186 | - elgg_create_river_item([ |
|
187 | - 'view' => 'river/group/create', |
|
188 | - 'action_type' => 'create', |
|
189 | - 'subject_guid' => $user->guid, |
|
190 | - 'object_guid' => $group->guid, |
|
191 | - ]); |
|
182 | + // @todo this should not be necessary... |
|
183 | + elgg_set_page_owner_guid($group->guid); |
|
184 | + |
|
185 | + $group->join($user); |
|
186 | + elgg_create_river_item([ |
|
187 | + 'view' => 'river/group/create', |
|
188 | + 'action_type' => 'create', |
|
189 | + 'subject_guid' => $user->guid, |
|
190 | + 'object_guid' => $group->guid, |
|
191 | + ]); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $group->saveIconFromUploadedFile('icon'); |
195 | 195 | |
196 | 196 | $data = [ |
197 | - 'entity' => $group, |
|
197 | + 'entity' => $group, |
|
198 | 198 | ]; |
199 | 199 | return elgg_ok_response($data, elgg_echo('groups:saved'), $group->getURL()); |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | $refresh_url = elgg_http_add_url_query_elements(elgg_get_site_url() . 'upgrade.php', [ |
14 | - 'upgrade' => 'upgrade', |
|
15 | - 'forward' => elgg_extract('forward', $vars, '/admin') |
|
14 | + 'upgrade' => 'upgrade', |
|
15 | + 'forward' => elgg_extract('forward', $vars, '/admin') |
|
16 | 16 | ]); |
17 | 17 | |
18 | 18 | if (elgg_get_config('security_protect_upgrade')) { |
19 | - // sign the url in order to get past the protection |
|
20 | - $refresh_url = elgg_http_get_signed_url($refresh_url); |
|
19 | + // sign the url in order to get past the protection |
|
20 | + $refresh_url = elgg_http_get_signed_url($refresh_url); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | // render content before head so that JavaScript and CSS can be loaded. See #4032 |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | |
26 | 26 | $head = elgg_view('page/elements/head', $vars['head']); |
27 | 27 | $head .= elgg_format_element([ |
28 | - '#tag_name' => 'meta', |
|
29 | - '#options' => ['is_xml' => true], |
|
30 | - 'http-equiv' => 'refresh', |
|
31 | - 'content' => '1;url=' . $refresh_url, |
|
28 | + '#tag_name' => 'meta', |
|
29 | + '#options' => ['is_xml' => true], |
|
30 | + 'http-equiv' => 'refresh', |
|
31 | + 'content' => '1;url=' . $refresh_url, |
|
32 | 32 | ]); |
33 | 33 | |
34 | 34 | echo elgg_view("page/elements/html", ["head" => $head, "body" => $body]); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @uses $var['forward'] A relative path to forward to after upgrade. Defaults to /admin |
11 | 11 | */ |
12 | 12 | |
13 | -$refresh_url = elgg_http_add_url_query_elements(elgg_get_site_url() . 'upgrade.php', [ |
|
13 | +$refresh_url = elgg_http_add_url_query_elements(elgg_get_site_url().'upgrade.php', [ |
|
14 | 14 | 'upgrade' => 'upgrade', |
15 | 15 | 'forward' => elgg_extract('forward', $vars, '/admin') |
16 | 16 | ]); |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | // render content before head so that JavaScript and CSS can be loaded. See #4032 |
24 | -$body = "<div style='margin-top:200px'>" . elgg_view('graphics/ajax_loader', ['hidden' => false]) . "</div>"; |
|
24 | +$body = "<div style='margin-top:200px'>".elgg_view('graphics/ajax_loader', ['hidden' => false])."</div>"; |
|
25 | 25 | |
26 | 26 | $head = elgg_view('page/elements/head', $vars['head']); |
27 | 27 | $head .= elgg_format_element([ |
28 | 28 | '#tag_name' => 'meta', |
29 | 29 | '#options' => ['is_xml' => true], |
30 | 30 | 'http-equiv' => 'refresh', |
31 | - 'content' => '1;url=' . $refresh_url, |
|
31 | + 'content' => '1;url='.$refresh_url, |
|
32 | 32 | ]); |
33 | 33 | |
34 | 34 | echo elgg_view("page/elements/html", ["head" => $head, "body" => $body]); |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * When this happens, a hidden input is created to return the GUID in the array with the form |
19 | 19 | */ |
20 | 20 | if (empty($vars['name'])) { |
21 | - $vars['name'] = 'members'; |
|
21 | + $vars['name'] = 'members'; |
|
22 | 22 | } |
23 | 23 | $name = $vars['name']; |
24 | 24 | |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | $limit = (int) elgg_extract('limit', $vars, 0); |
30 | 30 | |
31 | 31 | $attrs = [ |
32 | - 'class' => 'elgg-user-picker', |
|
33 | - 'data-limit' => $limit, |
|
34 | - 'data-name' => $name, |
|
35 | - 'data-handler' => $handler, |
|
32 | + 'class' => 'elgg-user-picker', |
|
33 | + 'data-limit' => $limit, |
|
34 | + 'data-name' => $name, |
|
35 | + 'data-handler' => $handler, |
|
36 | 36 | ]; |
37 | 37 | |
38 | 38 | ?> |
@@ -40,25 +40,25 @@ discard block |
||
40 | 40 | <input type="text" class="elgg-input-user-picker" size="30"/> |
41 | 41 | <?php echo elgg_view('input/hidden', ['name' => $vars['name']]); ?> |
42 | 42 | <?php |
43 | - if (!elgg_extract('only_friends', $vars, false)) { |
|
44 | - ?> |
|
43 | + if (!elgg_extract('only_friends', $vars, false)) { |
|
44 | + ?> |
|
45 | 45 | <input type="checkbox" name="match_on" value="true" /> |
46 | 46 | <label><?php echo elgg_echo('userpicker:only_friends'); ?></label> |
47 | 47 | <?php |
48 | - } |
|
49 | - ?> |
|
48 | + } |
|
49 | + ?> |
|
50 | 50 | <ul class="elgg-list elgg-user-picker-list"> |
51 | 51 | <?php |
52 | - foreach ($guids as $guid) { |
|
53 | - $entity = get_entity($guid); |
|
54 | - if ($entity) { |
|
55 | - echo elgg_view('input/userpicker/item', [ |
|
56 | - 'entity' => $entity, |
|
57 | - 'input_name' => $vars['name'], |
|
58 | - ]); |
|
59 | - } |
|
60 | - } |
|
61 | - ?> |
|
52 | + foreach ($guids as $guid) { |
|
53 | + $entity = get_entity($guid); |
|
54 | + if ($entity) { |
|
55 | + echo elgg_view('input/userpicker/item', [ |
|
56 | + 'entity' => $entity, |
|
57 | + 'input_name' => $vars['name'], |
|
58 | + ]); |
|
59 | + } |
|
60 | + } |
|
61 | + ?> |
|
62 | 62 | </ul> |
63 | 63 | </div> |
64 | 64 | <script> |
@@ -11,9 +11,9 @@ |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | if (!empty($vars['value'])) { |
14 | - echo elgg_view('output/url', [ |
|
15 | - 'href' => 'mailto:' . $vars['value'], |
|
16 | - 'text' => $vars['value'], |
|
17 | - 'encode_text' => true, |
|
18 | - ]); |
|
14 | + echo elgg_view('output/url', [ |
|
15 | + 'href' => 'mailto:' . $vars['value'], |
|
16 | + 'text' => $vars['value'], |
|
17 | + 'encode_text' => true, |
|
18 | + ]); |
|
19 | 19 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | if (!empty($vars['value'])) { |
14 | 14 | echo elgg_view('output/url', [ |
15 | - 'href' => 'mailto:' . $vars['value'], |
|
15 | + 'href' => 'mailto:'.$vars['value'], |
|
16 | 16 | 'text' => $vars['value'], |
17 | 17 | 'encode_text' => true, |
18 | 18 | ]); |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | function parse_urls($text) { |
18 | 18 | |
19 | - $linkify = new \Misd\Linkify\Linkify(); |
|
19 | + $linkify = new \Misd\Linkify\Linkify(); |
|
20 | 20 | |
21 | - return $linkify->processUrls($text, ['attr' => ['rel' => 'nofollow']]); |
|
21 | + return $linkify->processUrls($text, ['attr' => ['rel' => 'nofollow']]); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @since 2.3 |
32 | 32 | */ |
33 | 33 | function elgg_parse_emails($text) { |
34 | - $linkify = new \Misd\Linkify\Linkify(); |
|
34 | + $linkify = new \Misd\Linkify\Linkify(); |
|
35 | 35 | |
36 | - return $linkify->processEmails($text, ['attr' => ['rel' => 'nofollow']]); |
|
36 | + return $linkify->processEmails($text, ['attr' => ['rel' => 'nofollow']]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return string |
45 | 45 | **/ |
46 | 46 | function elgg_autop($string) { |
47 | - try { |
|
48 | - return _elgg_services()->autoP->process($string); |
|
49 | - } catch (\RuntimeException $e) { |
|
50 | - _elgg_services()->logger->warn('ElggAutoP failed to process the string: ' . $e->getMessage()); |
|
51 | - return $string; |
|
52 | - } |
|
47 | + try { |
|
48 | + return _elgg_services()->autoP->process($string); |
|
49 | + } catch (\RuntimeException $e) { |
|
50 | + _elgg_services()->logger->warn('ElggAutoP failed to process the string: ' . $e->getMessage()); |
|
51 | + return $string; |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | * @since 1.7.2 |
66 | 66 | */ |
67 | 67 | function elgg_get_excerpt($text, $num_chars = 250) { |
68 | - $view = 'output/excerpt'; |
|
69 | - $vars = [ |
|
70 | - 'text' => $text, |
|
71 | - 'num_chars' => $num_chars, |
|
72 | - ]; |
|
73 | - $viewtype = elgg_view_exists($view) ? '' : 'default'; |
|
74 | - |
|
75 | - return _elgg_view_under_viewtype($view, $vars, $viewtype); |
|
68 | + $view = 'output/excerpt'; |
|
69 | + $vars = [ |
|
70 | + 'text' => $text, |
|
71 | + 'num_chars' => $num_chars, |
|
72 | + ]; |
|
73 | + $viewtype = elgg_view_exists($view) ? '' : 'default'; |
|
74 | + |
|
75 | + return _elgg_view_under_viewtype($view, $vars, $viewtype); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | * @since 1.9.0 |
87 | 87 | */ |
88 | 88 | function elgg_format_bytes($size, $precision = 2) { |
89 | - if (!$size || $size < 0) { |
|
90 | - return false; |
|
91 | - } |
|
89 | + if (!$size || $size < 0) { |
|
90 | + return false; |
|
91 | + } |
|
92 | 92 | |
93 | - $base = log($size) / log(1024); |
|
94 | - $suffixes = ['B', 'kB', 'MB', 'GB', 'TB']; |
|
93 | + $base = log($size) / log(1024); |
|
94 | + $suffixes = ['B', 'kB', 'MB', 'GB', 'TB']; |
|
95 | 95 | |
96 | - return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)]; |
|
96 | + return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)]; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -120,52 +120,52 @@ discard block |
||
120 | 120 | * @return string |
121 | 121 | */ |
122 | 122 | function elgg_format_attributes(array $attrs = []) { |
123 | - if (!is_array($attrs) || empty($attrs)) { |
|
124 | - return ''; |
|
125 | - } |
|
123 | + if (!is_array($attrs) || empty($attrs)) { |
|
124 | + return ''; |
|
125 | + } |
|
126 | 126 | |
127 | - $attributes = []; |
|
127 | + $attributes = []; |
|
128 | 128 | |
129 | - foreach ($attrs as $attr => $val) { |
|
130 | - if (0 !== strpos($attr, 'data-') && false !== strpos($attr, '_')) { |
|
131 | - // this is probably a view $vars variable not meant for output |
|
132 | - continue; |
|
133 | - } |
|
129 | + foreach ($attrs as $attr => $val) { |
|
130 | + if (0 !== strpos($attr, 'data-') && false !== strpos($attr, '_')) { |
|
131 | + // this is probably a view $vars variable not meant for output |
|
132 | + continue; |
|
133 | + } |
|
134 | 134 | |
135 | - $attr = strtolower($attr); |
|
135 | + $attr = strtolower($attr); |
|
136 | 136 | |
137 | - if (!isset($val) || $val === false) { |
|
138 | - continue; |
|
139 | - } |
|
137 | + if (!isset($val) || $val === false) { |
|
138 | + continue; |
|
139 | + } |
|
140 | 140 | |
141 | - if ($val === true) { |
|
142 | - $val = $attr; //e.g. checked => true ==> checked="checked" |
|
143 | - } |
|
141 | + if ($val === true) { |
|
142 | + $val = $attr; //e.g. checked => true ==> checked="checked" |
|
143 | + } |
|
144 | 144 | |
145 | - if (is_scalar($val)) { |
|
146 | - $val = [$val]; |
|
147 | - } |
|
145 | + if (is_scalar($val)) { |
|
146 | + $val = [$val]; |
|
147 | + } |
|
148 | 148 | |
149 | - if (!is_array($val)) { |
|
150 | - continue; |
|
151 | - } |
|
149 | + if (!is_array($val)) { |
|
150 | + continue; |
|
151 | + } |
|
152 | 152 | |
153 | - // Check if array contains non-scalar values and bail if so |
|
154 | - $filtered_val = array_filter($val, function($e) { |
|
155 | - return is_scalar($e); |
|
156 | - }); |
|
153 | + // Check if array contains non-scalar values and bail if so |
|
154 | + $filtered_val = array_filter($val, function($e) { |
|
155 | + return is_scalar($e); |
|
156 | + }); |
|
157 | 157 | |
158 | - if (count($val) != count($filtered_val)) { |
|
159 | - continue; |
|
160 | - } |
|
158 | + if (count($val) != count($filtered_val)) { |
|
159 | + continue; |
|
160 | + } |
|
161 | 161 | |
162 | - $val = implode(' ', $val); |
|
162 | + $val = implode(' ', $val); |
|
163 | 163 | |
164 | - $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8', false); |
|
165 | - $attributes[] = "$attr=\"$val\""; |
|
166 | - } |
|
164 | + $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8', false); |
|
165 | + $attributes[] = "$attr=\"$val\""; |
|
166 | + } |
|
167 | 167 | |
168 | - return implode(' ', $attributes); |
|
168 | + return implode(' ', $attributes); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -199,60 +199,60 @@ discard block |
||
199 | 199 | * @since 1.9.0 |
200 | 200 | */ |
201 | 201 | function elgg_format_element($tag_name, array $attributes = [], $text = '', array $options = []) { |
202 | - if (is_array($tag_name)) { |
|
203 | - $args = $tag_name; |
|
204 | - |
|
205 | - if ($attributes !== [] || $text !== '' || $options !== []) { |
|
206 | - throw new \InvalidArgumentException('If $tag_name is an array, the other arguments must not be set'); |
|
207 | - } |
|
208 | - |
|
209 | - if (isset($args['#tag_name'])) { |
|
210 | - $tag_name = $args['#tag_name']; |
|
211 | - } |
|
212 | - if (isset($args['#text'])) { |
|
213 | - $text = $args['#text']; |
|
214 | - } |
|
215 | - if (isset($args['#options'])) { |
|
216 | - $options = $args['#options']; |
|
217 | - } |
|
218 | - |
|
219 | - unset($args['#tag_name'], $args['#text'], $args['#options']); |
|
220 | - $attributes = $args; |
|
221 | - } |
|
222 | - |
|
223 | - if (!is_string($tag_name) || $tag_name === '') { |
|
224 | - throw new \InvalidArgumentException('$tag_name is required'); |
|
225 | - } |
|
226 | - |
|
227 | - if (isset($options['is_void'])) { |
|
228 | - $is_void = $options['is_void']; |
|
229 | - } else { |
|
230 | - // from http://www.w3.org/TR/html-markup/syntax.html#syntax-elements |
|
231 | - $is_void = in_array(strtolower($tag_name), [ |
|
232 | - 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', |
|
233 | - 'meta', 'param', 'source', 'track', 'wbr' |
|
234 | - ]); |
|
235 | - } |
|
236 | - |
|
237 | - if (!empty($options['encode_text'])) { |
|
238 | - $double_encode = empty($options['double_encode']) ? false : true; |
|
239 | - $text = htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $double_encode); |
|
240 | - } |
|
241 | - |
|
242 | - if ($attributes) { |
|
243 | - $attrs = elgg_format_attributes($attributes); |
|
244 | - if ($attrs !== '') { |
|
245 | - $attrs = " $attrs"; |
|
246 | - } |
|
247 | - } else { |
|
248 | - $attrs = ''; |
|
249 | - } |
|
250 | - |
|
251 | - if ($is_void) { |
|
252 | - return empty($options['is_xml']) ? "<{$tag_name}{$attrs}>" : "<{$tag_name}{$attrs} />"; |
|
253 | - } else { |
|
254 | - return "<{$tag_name}{$attrs}>$text</$tag_name>"; |
|
255 | - } |
|
202 | + if (is_array($tag_name)) { |
|
203 | + $args = $tag_name; |
|
204 | + |
|
205 | + if ($attributes !== [] || $text !== '' || $options !== []) { |
|
206 | + throw new \InvalidArgumentException('If $tag_name is an array, the other arguments must not be set'); |
|
207 | + } |
|
208 | + |
|
209 | + if (isset($args['#tag_name'])) { |
|
210 | + $tag_name = $args['#tag_name']; |
|
211 | + } |
|
212 | + if (isset($args['#text'])) { |
|
213 | + $text = $args['#text']; |
|
214 | + } |
|
215 | + if (isset($args['#options'])) { |
|
216 | + $options = $args['#options']; |
|
217 | + } |
|
218 | + |
|
219 | + unset($args['#tag_name'], $args['#text'], $args['#options']); |
|
220 | + $attributes = $args; |
|
221 | + } |
|
222 | + |
|
223 | + if (!is_string($tag_name) || $tag_name === '') { |
|
224 | + throw new \InvalidArgumentException('$tag_name is required'); |
|
225 | + } |
|
226 | + |
|
227 | + if (isset($options['is_void'])) { |
|
228 | + $is_void = $options['is_void']; |
|
229 | + } else { |
|
230 | + // from http://www.w3.org/TR/html-markup/syntax.html#syntax-elements |
|
231 | + $is_void = in_array(strtolower($tag_name), [ |
|
232 | + 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', |
|
233 | + 'meta', 'param', 'source', 'track', 'wbr' |
|
234 | + ]); |
|
235 | + } |
|
236 | + |
|
237 | + if (!empty($options['encode_text'])) { |
|
238 | + $double_encode = empty($options['double_encode']) ? false : true; |
|
239 | + $text = htmlspecialchars($text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $double_encode); |
|
240 | + } |
|
241 | + |
|
242 | + if ($attributes) { |
|
243 | + $attrs = elgg_format_attributes($attributes); |
|
244 | + if ($attrs !== '') { |
|
245 | + $attrs = " $attrs"; |
|
246 | + } |
|
247 | + } else { |
|
248 | + $attrs = ''; |
|
249 | + } |
|
250 | + |
|
251 | + if ($is_void) { |
|
252 | + return empty($options['is_xml']) ? "<{$tag_name}{$attrs}>" : "<{$tag_name}{$attrs} />"; |
|
253 | + } else { |
|
254 | + return "<{$tag_name}{$attrs}>$text</$tag_name>"; |
|
255 | + } |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -270,40 +270,40 @@ discard block |
||
270 | 270 | * @return string The absolute URL |
271 | 271 | */ |
272 | 272 | function elgg_normalize_url($url) { |
273 | - $url = str_replace(' ', '%20', $url); |
|
274 | - |
|
275 | - if (_elgg_sane_validate_url($url)) { |
|
276 | - return $url; |
|
277 | - } |
|
278 | - |
|
279 | - if (preg_match("#^([a-z]+)\\:#", $url, $m)) { |
|
280 | - // we don't let http/https: URLs fail filter_var(), but anything else starting with a protocol |
|
281 | - // is OK |
|
282 | - if ($m[1] !== 'http' && $m[1] !== 'https') { |
|
283 | - return $url; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - if (preg_match("#^(\\#|\\?|//)#", $url)) { |
|
288 | - // starts with '//' (protocol-relative link), query, or fragment |
|
289 | - return $url; |
|
290 | - } |
|
291 | - |
|
292 | - if (preg_match("#^[^/]*\\.php(\\?.*)?$#", $url)) { |
|
293 | - // root PHP scripts: 'install.php', 'install.php?step=step'. We don't want to confuse these |
|
294 | - // for domain names. |
|
295 | - return elgg_get_site_url() . $url; |
|
296 | - } |
|
297 | - |
|
298 | - if (preg_match("#^[^/?]*\\.#", $url)) { |
|
299 | - // URLs starting with domain: 'example.com', 'example.com/subpage' |
|
300 | - return "http://$url"; |
|
301 | - } |
|
302 | - |
|
303 | - // 'page/handler', 'mod/plugin/file.php' |
|
304 | - // trim off any leading / because the site URL is stored |
|
305 | - // with a trailing / |
|
306 | - return elgg_get_site_url() . ltrim($url, '/'); |
|
273 | + $url = str_replace(' ', '%20', $url); |
|
274 | + |
|
275 | + if (_elgg_sane_validate_url($url)) { |
|
276 | + return $url; |
|
277 | + } |
|
278 | + |
|
279 | + if (preg_match("#^([a-z]+)\\:#", $url, $m)) { |
|
280 | + // we don't let http/https: URLs fail filter_var(), but anything else starting with a protocol |
|
281 | + // is OK |
|
282 | + if ($m[1] !== 'http' && $m[1] !== 'https') { |
|
283 | + return $url; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + if (preg_match("#^(\\#|\\?|//)#", $url)) { |
|
288 | + // starts with '//' (protocol-relative link), query, or fragment |
|
289 | + return $url; |
|
290 | + } |
|
291 | + |
|
292 | + if (preg_match("#^[^/]*\\.php(\\?.*)?$#", $url)) { |
|
293 | + // root PHP scripts: 'install.php', 'install.php?step=step'. We don't want to confuse these |
|
294 | + // for domain names. |
|
295 | + return elgg_get_site_url() . $url; |
|
296 | + } |
|
297 | + |
|
298 | + if (preg_match("#^[^/?]*\\.#", $url)) { |
|
299 | + // URLs starting with domain: 'example.com', 'example.com/subpage' |
|
300 | + return "http://$url"; |
|
301 | + } |
|
302 | + |
|
303 | + // 'page/handler', 'mod/plugin/file.php' |
|
304 | + // trim off any leading / because the site URL is stored |
|
305 | + // with a trailing / |
|
306 | + return elgg_get_site_url() . ltrim($url, '/'); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -316,16 +316,16 @@ discard block |
||
316 | 316 | * @since 3.0.0 |
317 | 317 | */ |
318 | 318 | function elgg_normalize_site_url($unsafe_url) { |
319 | - if (!is_string($unsafe_url)) { |
|
320 | - return false; |
|
321 | - } |
|
319 | + if (!is_string($unsafe_url)) { |
|
320 | + return false; |
|
321 | + } |
|
322 | 322 | |
323 | - $unsafe_url = elgg_normalize_url($unsafe_url); |
|
324 | - if (0 === strpos($unsafe_url, elgg_get_site_url())) { |
|
325 | - return $unsafe_url; |
|
326 | - } |
|
323 | + $unsafe_url = elgg_normalize_url($unsafe_url); |
|
324 | + if (0 === strpos($unsafe_url, elgg_get_site_url())) { |
|
325 | + return $unsafe_url; |
|
326 | + } |
|
327 | 327 | |
328 | - return false; |
|
328 | + return false; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -338,19 +338,19 @@ discard block |
||
338 | 338 | */ |
339 | 339 | function elgg_get_friendly_title($title) { |
340 | 340 | |
341 | - // return a URL friendly title to short circuit normal title formatting |
|
342 | - $params = ['title' => $title]; |
|
343 | - $result = elgg_trigger_plugin_hook('format', 'friendly:title', $params, null); |
|
344 | - if ($result) { |
|
345 | - return $result; |
|
346 | - } |
|
341 | + // return a URL friendly title to short circuit normal title formatting |
|
342 | + $params = ['title' => $title]; |
|
343 | + $result = elgg_trigger_plugin_hook('format', 'friendly:title', $params, null); |
|
344 | + if ($result) { |
|
345 | + return $result; |
|
346 | + } |
|
347 | 347 | |
348 | - // titles are often stored HTML encoded |
|
349 | - $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); |
|
348 | + // titles are often stored HTML encoded |
|
349 | + $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); |
|
350 | 350 | |
351 | - $title = \Elgg\Translit::urlize($title); |
|
351 | + $title = \Elgg\Translit::urlize($title); |
|
352 | 352 | |
353 | - return $title; |
|
353 | + return $title; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -366,46 +366,46 @@ discard block |
||
366 | 366 | */ |
367 | 367 | function elgg_get_friendly_time($time, $current_time = null) { |
368 | 368 | |
369 | - if (!$current_time) { |
|
370 | - $current_time = time(); |
|
371 | - } |
|
372 | - |
|
373 | - // return a time string to short circuit normal time formatting |
|
374 | - $params = ['time' => $time, 'current_time' => $current_time]; |
|
375 | - $result = elgg_trigger_plugin_hook('format', 'friendly:time', $params, null); |
|
376 | - if ($result) { |
|
377 | - return $result; |
|
378 | - } |
|
379 | - |
|
380 | - $diff = abs((int) $current_time - (int) $time); |
|
381 | - |
|
382 | - $minute = 60; |
|
383 | - $hour = $minute * 60; |
|
384 | - $day = $hour * 24; |
|
385 | - |
|
386 | - if ($diff < $minute) { |
|
387 | - return elgg_echo("friendlytime:justnow"); |
|
388 | - } |
|
369 | + if (!$current_time) { |
|
370 | + $current_time = time(); |
|
371 | + } |
|
372 | + |
|
373 | + // return a time string to short circuit normal time formatting |
|
374 | + $params = ['time' => $time, 'current_time' => $current_time]; |
|
375 | + $result = elgg_trigger_plugin_hook('format', 'friendly:time', $params, null); |
|
376 | + if ($result) { |
|
377 | + return $result; |
|
378 | + } |
|
379 | + |
|
380 | + $diff = abs((int) $current_time - (int) $time); |
|
381 | + |
|
382 | + $minute = 60; |
|
383 | + $hour = $minute * 60; |
|
384 | + $day = $hour * 24; |
|
385 | + |
|
386 | + if ($diff < $minute) { |
|
387 | + return elgg_echo("friendlytime:justnow"); |
|
388 | + } |
|
389 | 389 | |
390 | - if ($diff < $hour) { |
|
391 | - $granularity = ':minutes'; |
|
392 | - $diff = round($diff / $minute); |
|
393 | - } else if ($diff < $day) { |
|
394 | - $granularity = ':hours'; |
|
395 | - $diff = round($diff / $hour); |
|
396 | - } else { |
|
397 | - $granularity = ':days'; |
|
398 | - $diff = round($diff / $day); |
|
399 | - } |
|
400 | - |
|
401 | - if ($diff == 0) { |
|
402 | - $diff = 1; |
|
403 | - } |
|
390 | + if ($diff < $hour) { |
|
391 | + $granularity = ':minutes'; |
|
392 | + $diff = round($diff / $minute); |
|
393 | + } else if ($diff < $day) { |
|
394 | + $granularity = ':hours'; |
|
395 | + $diff = round($diff / $hour); |
|
396 | + } else { |
|
397 | + $granularity = ':days'; |
|
398 | + $diff = round($diff / $day); |
|
399 | + } |
|
400 | + |
|
401 | + if ($diff == 0) { |
|
402 | + $diff = 1; |
|
403 | + } |
|
404 | 404 | |
405 | - $future = ((int) $current_time - (int) $time < 0) ? ':future' : ''; |
|
406 | - $singular = ($diff == 1) ? ':singular' : ''; |
|
405 | + $future = ((int) $current_time - (int) $time < 0) ? ':future' : ''; |
|
406 | + $singular = ($diff == 1) ? ':singular' : ''; |
|
407 | 407 | |
408 | - return elgg_echo("friendlytime{$future}{$granularity}{$singular}", [$diff]); |
|
408 | + return elgg_echo("friendlytime{$future}{$granularity}{$singular}", [$diff]); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -415,44 +415,44 @@ discard block |
||
415 | 415 | * @return string |
416 | 416 | */ |
417 | 417 | function elgg_get_friendly_upload_error($error_code) { |
418 | - switch ($error_code) { |
|
419 | - case UPLOAD_ERR_OK: |
|
420 | - return ''; |
|
418 | + switch ($error_code) { |
|
419 | + case UPLOAD_ERR_OK: |
|
420 | + return ''; |
|
421 | 421 | |
422 | - case UPLOAD_ERR_INI_SIZE: |
|
423 | - $key = 'ini_size'; |
|
424 | - break; |
|
422 | + case UPLOAD_ERR_INI_SIZE: |
|
423 | + $key = 'ini_size'; |
|
424 | + break; |
|
425 | 425 | |
426 | - case UPLOAD_ERR_FORM_SIZE: |
|
427 | - $key = 'form_size'; |
|
428 | - break; |
|
426 | + case UPLOAD_ERR_FORM_SIZE: |
|
427 | + $key = 'form_size'; |
|
428 | + break; |
|
429 | 429 | |
430 | - case UPLOAD_ERR_PARTIAL: |
|
431 | - $key = 'partial'; |
|
432 | - break; |
|
430 | + case UPLOAD_ERR_PARTIAL: |
|
431 | + $key = 'partial'; |
|
432 | + break; |
|
433 | 433 | |
434 | - case UPLOAD_ERR_NO_FILE: |
|
435 | - $key = 'no_file'; |
|
436 | - break; |
|
434 | + case UPLOAD_ERR_NO_FILE: |
|
435 | + $key = 'no_file'; |
|
436 | + break; |
|
437 | 437 | |
438 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
439 | - $key = 'no_tmp_dir'; |
|
440 | - break; |
|
438 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
439 | + $key = 'no_tmp_dir'; |
|
440 | + break; |
|
441 | 441 | |
442 | - case UPLOAD_ERR_CANT_WRITE: |
|
443 | - $key = 'cant_write'; |
|
444 | - break; |
|
442 | + case UPLOAD_ERR_CANT_WRITE: |
|
443 | + $key = 'cant_write'; |
|
444 | + break; |
|
445 | 445 | |
446 | - case UPLOAD_ERR_EXTENSION: |
|
447 | - $key = 'extension'; |
|
448 | - break; |
|
446 | + case UPLOAD_ERR_EXTENSION: |
|
447 | + $key = 'extension'; |
|
448 | + break; |
|
449 | 449 | |
450 | - default: |
|
451 | - $key = 'unknown'; |
|
452 | - break; |
|
453 | - } |
|
450 | + default: |
|
451 | + $key = 'unknown'; |
|
452 | + break; |
|
453 | + } |
|
454 | 454 | |
455 | - return elgg_echo("upload:error:$key"); |
|
455 | + return elgg_echo("upload:error:$key"); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | |
@@ -467,13 +467,13 @@ discard block |
||
467 | 467 | * @return string String run through strip_tags() and any plugin hooks. |
468 | 468 | */ |
469 | 469 | function elgg_strip_tags($string, $allowable_tags = null) { |
470 | - $params['original_string'] = $string; |
|
471 | - $params['allowable_tags'] = $allowable_tags; |
|
470 | + $params['original_string'] = $string; |
|
471 | + $params['allowable_tags'] = $allowable_tags; |
|
472 | 472 | |
473 | - $string = strip_tags($string, $allowable_tags); |
|
474 | - $string = elgg_trigger_plugin_hook('format', 'strip_tags', $params, $string); |
|
473 | + $string = strip_tags($string, $allowable_tags); |
|
474 | + $string = elgg_trigger_plugin_hook('format', 'strip_tags', $params, $string); |
|
475 | 475 | |
476 | - return $string; |
|
476 | + return $string; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -504,18 +504,18 @@ discard block |
||
504 | 504 | * @license Released under dual-license GPL2/MIT by explicit permission of Pádraic Brady |
505 | 505 | */ |
506 | 506 | function elgg_html_decode($string) { |
507 | - $string = str_replace( |
|
508 | - ['>', '<', '&', '"', '''], |
|
509 | - ['&gt;', '&lt;', '&amp;', '&quot;', '&#039;'], |
|
510 | - $string |
|
511 | - ); |
|
512 | - $string = html_entity_decode($string, ENT_NOQUOTES, 'UTF-8'); |
|
513 | - $string = str_replace( |
|
514 | - ['&gt;', '&lt;', '&amp;', '&quot;', '&#039;'], |
|
515 | - ['>', '<', '&', '"', '''], |
|
516 | - $string |
|
517 | - ); |
|
518 | - return $string; |
|
507 | + $string = str_replace( |
|
508 | + ['>', '<', '&', '"', '''], |
|
509 | + ['&gt;', '&lt;', '&amp;', '&quot;', '&#039;'], |
|
510 | + $string |
|
511 | + ); |
|
512 | + $string = html_entity_decode($string, ENT_NOQUOTES, 'UTF-8'); |
|
513 | + $string = str_replace( |
|
514 | + ['&gt;', '&lt;', '&amp;', '&quot;', '&#039;'], |
|
515 | + ['>', '<', '&', '"', '''], |
|
516 | + $string |
|
517 | + ); |
|
518 | + return $string; |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -527,14 +527,14 @@ discard block |
||
527 | 527 | * @access private |
528 | 528 | */ |
529 | 529 | function _elgg_get_display_query($string) { |
530 | - //encode <,>,&, quotes and characters above 127 |
|
531 | - if (function_exists('mb_convert_encoding')) { |
|
532 | - $display_query = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8'); |
|
533 | - } else { |
|
534 | - // if no mbstring extension, we just strip characters |
|
535 | - $display_query = preg_replace("/[^\x01-\x7F]/", "", $string); |
|
536 | - } |
|
537 | - return htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); |
|
530 | + //encode <,>,&, quotes and characters above 127 |
|
531 | + if (function_exists('mb_convert_encoding')) { |
|
532 | + $display_query = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8'); |
|
533 | + } else { |
|
534 | + // if no mbstring extension, we just strip characters |
|
535 | + $display_query = preg_replace("/[^\x01-\x7F]/", "", $string); |
|
536 | + } |
|
537 | + return htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -545,25 +545,25 @@ discard block |
||
545 | 545 | * @access private |
546 | 546 | */ |
547 | 547 | function _elgg_sane_validate_url($url) { |
548 | - // based on http://php.net/manual/en/function.filter-var.php#104160 |
|
549 | - $res = filter_var($url, FILTER_VALIDATE_URL); |
|
550 | - if ($res) { |
|
551 | - return $res; |
|
552 | - } |
|
553 | - |
|
554 | - // Check if it has unicode chars. |
|
555 | - $l = elgg_strlen($url); |
|
556 | - if (strlen($url) == $l) { |
|
557 | - return $res; |
|
558 | - } |
|
559 | - |
|
560 | - // Replace wide chars by “X”. |
|
561 | - $s = ''; |
|
562 | - for ($i = 0; $i < $l; ++$i) { |
|
563 | - $ch = elgg_substr($url, $i, 1); |
|
564 | - $s .= (strlen($ch) > 1) ? 'X' : $ch; |
|
565 | - } |
|
566 | - |
|
567 | - // Re-check now. |
|
568 | - return filter_var($s, FILTER_VALIDATE_URL) ? $url : false; |
|
548 | + // based on http://php.net/manual/en/function.filter-var.php#104160 |
|
549 | + $res = filter_var($url, FILTER_VALIDATE_URL); |
|
550 | + if ($res) { |
|
551 | + return $res; |
|
552 | + } |
|
553 | + |
|
554 | + // Check if it has unicode chars. |
|
555 | + $l = elgg_strlen($url); |
|
556 | + if (strlen($url) == $l) { |
|
557 | + return $res; |
|
558 | + } |
|
559 | + |
|
560 | + // Replace wide chars by “X”. |
|
561 | + $s = ''; |
|
562 | + for ($i = 0; $i < $l; ++$i) { |
|
563 | + $ch = elgg_substr($url, $i, 1); |
|
564 | + $s .= (strlen($ch) > 1) ? 'X' : $ch; |
|
565 | + } |
|
566 | + |
|
567 | + // Re-check now. |
|
568 | + return filter_var($s, FILTER_VALIDATE_URL) ? $url : false; |
|
569 | 569 | } |