Completed
Push — master ( 23b00d...aa8d19 )
by Steve
10:04 queued 37s
created
engine/classes/Elgg/Database/Annotations.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 *
34 34
 	 * @param int $id The id of the annotation object being retrieved.
35 35
 	 *
36
-	 * @return \ElggAnnotation|false
36
+	 * @return \ElggExtender
37 37
 	 */
38 38
 	function get($id) {
39 39
 		return _elgg_get_metastring_based_object_from_id($id, 'annotation');
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -12,439 +12,439 @@
 block discarded – undo
12 12
  */
13 13
 class Annotations {
14 14
 
15
-	use \Elgg\TimeUsing;
15
+    use \Elgg\TimeUsing;
16 16
 	
17
-	/**
18
-	 * @var \Elgg\Database
19
-	 */
20
-	protected $db;
17
+    /**
18
+     * @var \Elgg\Database
19
+     */
20
+    protected $db;
21 21
 
22
-	/**
23
-	 * @var \ElggSession
24
-	 */
25
-	protected $session;
22
+    /**
23
+     * @var \ElggSession
24
+     */
25
+    protected $session;
26 26
 
27
-	/**
28
-	 * @var \Elgg\EventsService
29
-	 */
30
-	protected $events;
27
+    /**
28
+     * @var \Elgg\EventsService
29
+     */
30
+    protected $events;
31 31
 
32
-	/**
33
-	 * Constructor
34
-	 *
35
-	 * @param \Elgg\Database      $db      Database
36
-	 * @param \ElggSession        $session Session
37
-	 * @param \Elgg\EventsService $events  Events
38
-	 */
39
-	public function __construct(\Elgg\Database $db, \ElggSession $session, \Elgg\EventsService $events) {
40
-		$this->db = $db;
41
-		$this->session = $session;
42
-		$this->events = $events;
43
-	}
32
+    /**
33
+     * Constructor
34
+     *
35
+     * @param \Elgg\Database      $db      Database
36
+     * @param \ElggSession        $session Session
37
+     * @param \Elgg\EventsService $events  Events
38
+     */
39
+    public function __construct(\Elgg\Database $db, \ElggSession $session, \Elgg\EventsService $events) {
40
+        $this->db = $db;
41
+        $this->session = $session;
42
+        $this->events = $events;
43
+    }
44 44
 
45
-	/**
46
-	 * Get a specific annotation by its id.
47
-	 * If you want multiple annotation objects, use
48
-	 * {@link elgg_get_annotations()}.
49
-	 *
50
-	 * @param int $id The id of the annotation object being retrieved.
51
-	 *
52
-	 * @return \ElggAnnotation|false
53
-	 */
54
-	function get($id) {
55
-		return _elgg_get_metastring_based_object_from_id($id, 'annotation');
56
-	}
57
-	
58
-	/**
59
-	 * Deletes an annotation using its ID.
60
-	 *
61
-	 * @param int $id The annotation ID to delete.
62
-	 * @return bool
63
-	 */
64
-	function delete($id) {
65
-		$annotation = $this->get($id);
66
-		if (!$annotation) {
67
-			return false;
68
-		}
69
-		return $annotation->delete();
70
-	}
71
-	
72
-	/**
73
-	 * Create a new annotation.
74
-	 *
75
-	 * @param int    $entity_guid GUID of entity to be annotated
76
-	 * @param string $name        Name of annotation
77
-	 * @param string $value       Value of annotation
78
-	 * @param string $value_type  Type of value (default is auto detection)
79
-	 * @param int    $owner_guid  Owner of annotation (default is logged in user)
80
-	 * @param int    $access_id   Access level of annotation
81
-	 *
82
-	 * @return int|bool id on success or false on failure
83
-	 */
84
-	function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) {
45
+    /**
46
+     * Get a specific annotation by its id.
47
+     * If you want multiple annotation objects, use
48
+     * {@link elgg_get_annotations()}.
49
+     *
50
+     * @param int $id The id of the annotation object being retrieved.
51
+     *
52
+     * @return \ElggAnnotation|false
53
+     */
54
+    function get($id) {
55
+        return _elgg_get_metastring_based_object_from_id($id, 'annotation');
56
+    }
57
+	
58
+    /**
59
+     * Deletes an annotation using its ID.
60
+     *
61
+     * @param int $id The annotation ID to delete.
62
+     * @return bool
63
+     */
64
+    function delete($id) {
65
+        $annotation = $this->get($id);
66
+        if (!$annotation) {
67
+            return false;
68
+        }
69
+        return $annotation->delete();
70
+    }
71
+	
72
+    /**
73
+     * Create a new annotation.
74
+     *
75
+     * @param int    $entity_guid GUID of entity to be annotated
76
+     * @param string $name        Name of annotation
77
+     * @param string $value       Value of annotation
78
+     * @param string $value_type  Type of value (default is auto detection)
79
+     * @param int    $owner_guid  Owner of annotation (default is logged in user)
80
+     * @param int    $access_id   Access level of annotation
81
+     *
82
+     * @return int|bool id on success or false on failure
83
+     */
84
+    function create($entity_guid, $name, $value, $value_type = '', $owner_guid = 0, $access_id = ACCESS_PRIVATE) {
85 85
 		
86
-		$result = false;
86
+        $result = false;
87 87
 	
88
-		$entity_guid = (int) $entity_guid;
89
-		$value_type = \ElggExtender::detectValueType($value, $value_type);
88
+        $entity_guid = (int) $entity_guid;
89
+        $value_type = \ElggExtender::detectValueType($value, $value_type);
90 90
 
91
-		$owner_guid = (int) $owner_guid;
92
-		if ($owner_guid == 0) {
93
-			$owner_guid = $this->session->getLoggedInUserGuid();
94
-		}
91
+        $owner_guid = (int) $owner_guid;
92
+        if ($owner_guid == 0) {
93
+            $owner_guid = $this->session->getLoggedInUserGuid();
94
+        }
95 95
 	
96
-		$access_id = (int) $access_id;
96
+        $access_id = (int) $access_id;
97 97
 		
98
-		// @todo we don't check that the entity is loaded which means the user may
99
-		// not have access to the entity
100
-		$entity = get_entity($entity_guid);
98
+        // @todo we don't check that the entity is loaded which means the user may
99
+        // not have access to the entity
100
+        $entity = get_entity($entity_guid);
101 101
 	
102
-		if ($this->events->trigger('annotate', $entity->type, $entity)) {
103
-			$sql = "INSERT INTO {$this->db->prefix}annotations
102
+        if ($this->events->trigger('annotate', $entity->type, $entity)) {
103
+            $sql = "INSERT INTO {$this->db->prefix}annotations
104 104
 				(entity_guid, name, value, value_type, owner_guid, time_created, access_id)
105 105
 				VALUES
106 106
 				(:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
107 107
 	
108
-			$result = $this->db->insertData($sql, [
109
-				':entity_guid' => $entity_guid,
110
-				':name' => $name,
111
-				':value' => $value,
112
-				':value_type' => $value_type,
113
-				':owner_guid' => $owner_guid,
114
-				':time_created' => $this->getCurrentTime()->getTimestamp(),
115
-				':access_id' => $access_id,
116
-			]);
108
+            $result = $this->db->insertData($sql, [
109
+                ':entity_guid' => $entity_guid,
110
+                ':name' => $name,
111
+                ':value' => $value,
112
+                ':value_type' => $value_type,
113
+                ':owner_guid' => $owner_guid,
114
+                ':time_created' => $this->getCurrentTime()->getTimestamp(),
115
+                ':access_id' => $access_id,
116
+            ]);
117 117
 				
118
-			if ($result !== false) {
119
-				$obj = elgg_get_annotation_from_id($result);
120
-				if ($this->events->trigger('create', 'annotation', $obj)) {
121
-					return $result;
122
-				} else {
123
-					// plugin returned false to reject annotation
124
-					elgg_delete_annotation_by_id($result);
125
-					return false;
126
-				}
127
-			}
128
-		}
129
-	
130
-		return $result;
131
-	}
132
-	
133
-	/**
134
-	 * Update an annotation.
135
-	 *
136
-	 * @param int    $annotation_id Annotation ID
137
-	 * @param string $name          Name of annotation
138
-	 * @param string $value         Value of annotation
139
-	 * @param string $value_type    Type of value
140
-	 * @param int    $owner_guid    Owner of annotation
141
-	 * @param int    $access_id     Access level of annotation
142
-	 *
143
-	 * @return bool
144
-	 */
145
-	function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id) {
118
+            if ($result !== false) {
119
+                $obj = elgg_get_annotation_from_id($result);
120
+                if ($this->events->trigger('create', 'annotation', $obj)) {
121
+                    return $result;
122
+                } else {
123
+                    // plugin returned false to reject annotation
124
+                    elgg_delete_annotation_by_id($result);
125
+                    return false;
126
+                }
127
+            }
128
+        }
129
+	
130
+        return $result;
131
+    }
132
+	
133
+    /**
134
+     * Update an annotation.
135
+     *
136
+     * @param int    $annotation_id Annotation ID
137
+     * @param string $name          Name of annotation
138
+     * @param string $value         Value of annotation
139
+     * @param string $value_type    Type of value
140
+     * @param int    $owner_guid    Owner of annotation
141
+     * @param int    $access_id     Access level of annotation
142
+     *
143
+     * @return bool
144
+     */
145
+    function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id) {
146 146
 
147
-		$annotation_id = (int) $annotation_id;
147
+        $annotation_id = (int) $annotation_id;
148 148
 	
149
-		$annotation = $this->get($annotation_id);
150
-		if (!$annotation) {
151
-			return false;
152
-		}
153
-		if (!$annotation->canEdit()) {
154
-			return false;
155
-		}
149
+        $annotation = $this->get($annotation_id);
150
+        if (!$annotation) {
151
+            return false;
152
+        }
153
+        if (!$annotation->canEdit()) {
154
+            return false;
155
+        }
156 156
 	
157
-		$name = trim($name);
158
-		$value_type = \ElggExtender::detectValueType($value, $value_type);
157
+        $name = trim($name);
158
+        $value_type = \ElggExtender::detectValueType($value, $value_type);
159 159
 	
160
-		$owner_guid = (int) $owner_guid;
161
-		if ($owner_guid == 0) {
162
-			$owner_guid = $this->session->getLoggedInUserGuid();
163
-		}
160
+        $owner_guid = (int) $owner_guid;
161
+        if ($owner_guid == 0) {
162
+            $owner_guid = $this->session->getLoggedInUserGuid();
163
+        }
164 164
 	
165
-		$access_id = (int) $access_id;
165
+        $access_id = (int) $access_id;
166 166
 				
167
-		$sql = "UPDATE {$this->db->prefix}annotations
167
+        $sql = "UPDATE {$this->db->prefix}annotations
168 168
 			(name, value, value_type, access_id, owner_guid)
169 169
 			VALUES
170 170
 			(:name, :value, :value_type, :access_id, :owner_guid)
171 171
 			WHERE id = :annotation_id";
172 172
 
173
-		$result = $this->db->updateData($sql, false, [
174
-			':name' => $name,
175
-			':value' => $value,
176
-			':value_type' => $value_type,
177
-			':access_id' => $access_id,
178
-			':owner_guid' => $owner_guid,
179
-			':annotation_id' => $annotation_id,
180
-		]);
173
+        $result = $this->db->updateData($sql, false, [
174
+            ':name' => $name,
175
+            ':value' => $value,
176
+            ':value_type' => $value_type,
177
+            ':access_id' => $access_id,
178
+            ':owner_guid' => $owner_guid,
179
+            ':annotation_id' => $annotation_id,
180
+        ]);
181 181
 			
182
-		if ($result !== false) {
183
-			// @todo add plugin hook that sends old and new annotation information before db access
184
-			$obj = $this->get($annotation_id);
185
-			$this->events->trigger('update', 'annotation', $obj);
186
-		}
187
-	
188
-		return $result;
189
-	}
190
-	
191
-	/**
192
-	 * Returns annotations.  Accepts all elgg_get_entities() options for entity
193
-	 * restraints.
194
-	 *
195
-	 * @see elgg_get_entities
196
-	 *
197
-	 * @param array $options Array in format:
198
-	 *
199
-	 * annotation_names              => null|ARR Annotation names
200
-	 * annotation_values             => null|ARR Annotation values
201
-	 * annotation_ids                => null|ARR annotation ids
202
-	 * annotation_case_sensitive     => BOOL Overall Case sensitive
203
-	 * annotation_owner_guids        => null|ARR guids for annotation owners
204
-	 * annotation_created_time_lower => INT Lower limit for created time.
205
-	 * annotation_created_time_upper => INT Upper limit for created time.
206
-	 * annotation_calculation        => STR Perform the MySQL function on the annotation values returned.
207
-	 *                                   Do not confuse this "annotation_calculation" option with the
208
-	 *                                   "calculation" option to elgg_get_entities_from_annotation_calculation().
209
-	 *                                   The "annotation_calculation" option causes this function to
210
-	 *                                   return the result of performing a mathematical calculation on
211
-	 *                                   all annotations that match the query instead of \ElggAnnotation
212
-	 *                                   objects.
213
-	 *                                   See the docs for elgg_get_entities_from_annotation_calculation()
214
-	 *                                   for the proper use of the "calculation" option.
215
-	 *
216
-	 *
217
-	 * @return \ElggAnnotation[]|mixed
218
-	 */
219
-	function find(array $options = []) {
182
+        if ($result !== false) {
183
+            // @todo add plugin hook that sends old and new annotation information before db access
184
+            $obj = $this->get($annotation_id);
185
+            $this->events->trigger('update', 'annotation', $obj);
186
+        }
187
+	
188
+        return $result;
189
+    }
190
+	
191
+    /**
192
+     * Returns annotations.  Accepts all elgg_get_entities() options for entity
193
+     * restraints.
194
+     *
195
+     * @see elgg_get_entities
196
+     *
197
+     * @param array $options Array in format:
198
+     *
199
+     * annotation_names              => null|ARR Annotation names
200
+     * annotation_values             => null|ARR Annotation values
201
+     * annotation_ids                => null|ARR annotation ids
202
+     * annotation_case_sensitive     => BOOL Overall Case sensitive
203
+     * annotation_owner_guids        => null|ARR guids for annotation owners
204
+     * annotation_created_time_lower => INT Lower limit for created time.
205
+     * annotation_created_time_upper => INT Upper limit for created time.
206
+     * annotation_calculation        => STR Perform the MySQL function on the annotation values returned.
207
+     *                                   Do not confuse this "annotation_calculation" option with the
208
+     *                                   "calculation" option to elgg_get_entities_from_annotation_calculation().
209
+     *                                   The "annotation_calculation" option causes this function to
210
+     *                                   return the result of performing a mathematical calculation on
211
+     *                                   all annotations that match the query instead of \ElggAnnotation
212
+     *                                   objects.
213
+     *                                   See the docs for elgg_get_entities_from_annotation_calculation()
214
+     *                                   for the proper use of the "calculation" option.
215
+     *
216
+     *
217
+     * @return \ElggAnnotation[]|mixed
218
+     */
219
+    function find(array $options = []) {
220 220
 
221
-		// support shortcut of 'count' => true for 'annotation_calculation' => 'count'
222
-		if (isset($options['count']) && $options['count']) {
223
-			$options['annotation_calculation'] = 'count';
224
-			unset($options['count']);
225
-		}
221
+        // support shortcut of 'count' => true for 'annotation_calculation' => 'count'
222
+        if (isset($options['count']) && $options['count']) {
223
+            $options['annotation_calculation'] = 'count';
224
+            unset($options['count']);
225
+        }
226 226
 		
227
-		$options['metastring_type'] = 'annotations';
228
-		return _elgg_get_metastring_based_objects($options);
229
-	}
230
-	
231
-	/**
232
-	 * Deletes annotations based on $options.
233
-	 *
234
-	 * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
235
-	 *          This requires at least one constraint: annotation_owner_guid(s),
236
-	 *          annotation_name(s), annotation_value(s), or guid(s) must be set.
237
-	 *
238
-	 * @param array $options An options array. {@link elgg_get_annotations()}
239
-	 * @return bool|null true on success, false on failure, null if no annotations to delete.
240
-	 */
241
-	function deleteAll(array $options) {
242
-		if (!_elgg_is_valid_options_for_batch_operation($options, 'annotation')) {
243
-			return false;
244
-		}
245
-	
246
-		$options['metastring_type'] = 'annotations';
247
-		return _elgg_batch_metastring_based_objects($options, 'elgg_batch_delete_callback', false);
248
-	}
249
-	
250
-	/**
251
-	 * Disables annotations based on $options.
252
-	 *
253
-	 * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
254
-	 *
255
-	 * @param array $options An options array. {@link elgg_get_annotations()}
256
-	 * @return bool|null true on success, false on failure, null if no annotations disabled.
257
-	 */
258
-	function disableAll(array $options) {
259
-		if (!_elgg_is_valid_options_for_batch_operation($options, 'annotation')) {
260
-			return false;
261
-		}
227
+        $options['metastring_type'] = 'annotations';
228
+        return _elgg_get_metastring_based_objects($options);
229
+    }
230
+	
231
+    /**
232
+     * Deletes annotations based on $options.
233
+     *
234
+     * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
235
+     *          This requires at least one constraint: annotation_owner_guid(s),
236
+     *          annotation_name(s), annotation_value(s), or guid(s) must be set.
237
+     *
238
+     * @param array $options An options array. {@link elgg_get_annotations()}
239
+     * @return bool|null true on success, false on failure, null if no annotations to delete.
240
+     */
241
+    function deleteAll(array $options) {
242
+        if (!_elgg_is_valid_options_for_batch_operation($options, 'annotation')) {
243
+            return false;
244
+        }
245
+	
246
+        $options['metastring_type'] = 'annotations';
247
+        return _elgg_batch_metastring_based_objects($options, 'elgg_batch_delete_callback', false);
248
+    }
249
+	
250
+    /**
251
+     * Disables annotations based on $options.
252
+     *
253
+     * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
254
+     *
255
+     * @param array $options An options array. {@link elgg_get_annotations()}
256
+     * @return bool|null true on success, false on failure, null if no annotations disabled.
257
+     */
258
+    function disableAll(array $options) {
259
+        if (!_elgg_is_valid_options_for_batch_operation($options, 'annotation')) {
260
+            return false;
261
+        }
262 262
 		
263
-		// if we can see hidden (disabled) we need to use the offset
264
-		// otherwise we risk an infinite loop if there are more than 50
265
-		$inc_offset = access_get_show_hidden_status();
266
-	
267
-		$options['metastring_type'] = 'annotations';
268
-		return _elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback', $inc_offset);
269
-	}
270
-	
271
-	/**
272
-	 * Enables annotations based on $options.
273
-	 *
274
-	 * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
275
-	 *
276
-	 * @warning In order to enable annotations, you must first use
277
-	 * {@link access_show_hidden_entities()}.
278
-	 *
279
-	 * @param array $options An options array. {@link elgg_get_annotations()}
280
-	 * @return bool|null true on success, false on failure, null if no metadata enabled.
281
-	 */
282
-	function enableAll(array $options) {
283
-		if (!$options || !is_array($options)) {
284
-			return false;
285
-		}
286
-	
287
-		$options['metastring_type'] = 'annotations';
288
-		return _elgg_batch_metastring_based_objects($options, 'elgg_batch_enable_callback');
289
-	}
290
-	
291
-	/**
292
-	 * Returns entities based upon annotations.  Also accepts all options available
293
-	 * to elgg_get_entities() and elgg_get_entities_from_metadata().
294
-	 *
295
-	 * @see elgg_get_entities
296
-	 * @see elgg_get_entities_from_metadata
297
-	 *
298
-	 * @param array $options Array in format:
299
-	 *
300
-	 * 	annotation_names => null|ARR annotations names
301
-	 *
302
-	 * 	annotation_values => null|ARR annotations values
303
-	 *
304
-	 * 	annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
305
-	 * 	'operator' => '=', 'case_sensitive' => true) entries.
306
-	 * 	Currently if multiple values are sent via an array (value => array('value1', 'value2')
307
-	 * 	the pair's operator will be forced to "IN".
308
-	 *
309
-	 * 	annotation_name_value_pairs_operator => null|STR The operator to use for combining
310
-	 *  (name = value) OPERATOR (name = value); default AND
311
-	 *
312
-	 * 	annotation_case_sensitive => BOOL Overall Case sensitive
313
-	 *
314
-	 *  order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
315
-	 *  'as' => text|integer),
316
-	 *
317
-	 *  Also supports array('name' => 'annotation_text1')
318
-	 *
319
-	 *  annotation_owner_guids => null|ARR guids for annotaiton owners
320
-	 *
321
-	 * @return mixed If count, int. If not count, array. false on errors.
322
-	 */
323
-	function getEntities(array $options = []) {
324
-		$defaults = [
325
-			'annotation_names'                      => ELGG_ENTITIES_ANY_VALUE,
326
-			'annotation_values'                     => ELGG_ENTITIES_ANY_VALUE,
327
-			'annotation_name_value_pairs'           => ELGG_ENTITIES_ANY_VALUE,
263
+        // if we can see hidden (disabled) we need to use the offset
264
+        // otherwise we risk an infinite loop if there are more than 50
265
+        $inc_offset = access_get_show_hidden_status();
266
+	
267
+        $options['metastring_type'] = 'annotations';
268
+        return _elgg_batch_metastring_based_objects($options, 'elgg_batch_disable_callback', $inc_offset);
269
+    }
270
+	
271
+    /**
272
+     * Enables annotations based on $options.
273
+     *
274
+     * @warning Unlike elgg_get_annotations() this will not accept an empty options array!
275
+     *
276
+     * @warning In order to enable annotations, you must first use
277
+     * {@link access_show_hidden_entities()}.
278
+     *
279
+     * @param array $options An options array. {@link elgg_get_annotations()}
280
+     * @return bool|null true on success, false on failure, null if no metadata enabled.
281
+     */
282
+    function enableAll(array $options) {
283
+        if (!$options || !is_array($options)) {
284
+            return false;
285
+        }
286
+	
287
+        $options['metastring_type'] = 'annotations';
288
+        return _elgg_batch_metastring_based_objects($options, 'elgg_batch_enable_callback');
289
+    }
290
+	
291
+    /**
292
+     * Returns entities based upon annotations.  Also accepts all options available
293
+     * to elgg_get_entities() and elgg_get_entities_from_metadata().
294
+     *
295
+     * @see elgg_get_entities
296
+     * @see elgg_get_entities_from_metadata
297
+     *
298
+     * @param array $options Array in format:
299
+     *
300
+     * 	annotation_names => null|ARR annotations names
301
+     *
302
+     * 	annotation_values => null|ARR annotations values
303
+     *
304
+     * 	annotation_name_value_pairs => null|ARR (name = 'name', value => 'value',
305
+     * 	'operator' => '=', 'case_sensitive' => true) entries.
306
+     * 	Currently if multiple values are sent via an array (value => array('value1', 'value2')
307
+     * 	the pair's operator will be forced to "IN".
308
+     *
309
+     * 	annotation_name_value_pairs_operator => null|STR The operator to use for combining
310
+     *  (name = value) OPERATOR (name = value); default AND
311
+     *
312
+     * 	annotation_case_sensitive => BOOL Overall Case sensitive
313
+     *
314
+     *  order_by_annotation => null|ARR (array('name' => 'annotation_text1', 'direction' => ASC|DESC,
315
+     *  'as' => text|integer),
316
+     *
317
+     *  Also supports array('name' => 'annotation_text1')
318
+     *
319
+     *  annotation_owner_guids => null|ARR guids for annotaiton owners
320
+     *
321
+     * @return mixed If count, int. If not count, array. false on errors.
322
+     */
323
+    function getEntities(array $options = []) {
324
+        $defaults = [
325
+            'annotation_names'                      => ELGG_ENTITIES_ANY_VALUE,
326
+            'annotation_values'                     => ELGG_ENTITIES_ANY_VALUE,
327
+            'annotation_name_value_pairs'           => ELGG_ENTITIES_ANY_VALUE,
328 328
 
329
-			'annotation_name_value_pairs_operator'  => 'AND',
330
-			'annotation_case_sensitive'             => true,
331
-			'order_by_annotation'                   => [],
329
+            'annotation_name_value_pairs_operator'  => 'AND',
330
+            'annotation_case_sensitive'             => true,
331
+            'order_by_annotation'                   => [],
332 332
 
333
-			'annotation_created_time_lower'         => ELGG_ENTITIES_ANY_VALUE,
334
-			'annotation_created_time_upper'         => ELGG_ENTITIES_ANY_VALUE,
335
-			'annotation_owner_guids'                => ELGG_ENTITIES_ANY_VALUE,
336
-		];
333
+            'annotation_created_time_lower'         => ELGG_ENTITIES_ANY_VALUE,
334
+            'annotation_created_time_upper'         => ELGG_ENTITIES_ANY_VALUE,
335
+            'annotation_owner_guids'                => ELGG_ENTITIES_ANY_VALUE,
336
+        ];
337 337
 	
338
-		$options = array_merge($defaults, $options);
338
+        $options = array_merge($defaults, $options);
339 339
 	
340
-		$singulars = ['annotation_name', 'annotation_value', 'annotation_name_value_pair', 'annotation_owner_guid'];
340
+        $singulars = ['annotation_name', 'annotation_value', 'annotation_name_value_pair', 'annotation_owner_guid'];
341 341
 	
342
-		$options = _elgg_normalize_plural_options_array($options, $singulars);
343
-		$options = _elgg_entities_get_metastrings_options('annotation', $options);
342
+        $options = _elgg_normalize_plural_options_array($options, $singulars);
343
+        $options = _elgg_entities_get_metastrings_options('annotation', $options);
344 344
 	
345
-		if (!$options) {
346
-			return false;
347
-		}
345
+        if (!$options) {
346
+            return false;
347
+        }
348 348
 		
349
-		$time_wheres = _elgg_get_entity_time_where_sql('n_table', $options['annotation_created_time_upper'],
350
-			$options['annotation_created_time_lower']);
349
+        $time_wheres = _elgg_get_entity_time_where_sql('n_table', $options['annotation_created_time_upper'],
350
+            $options['annotation_created_time_lower']);
351 351
 
352
-		if ($time_wheres) {
353
-			$options['wheres'][] = $time_wheres;
354
-		}
355
-	
356
-		return elgg_get_entities_from_metadata($options);
357
-	}
358
-	
359
-	/**
360
-	 * Get entities ordered by a mathematical calculation on annotation values
361
-	 *
362
-	 * @tip Note that this function uses { @link elgg_get_annotations() } to return a list of entities ordered by a mathematical
363
-	 * calculation on annotation values, and { @link elgg_get_entities_from_annotations() } to return a count of entities
364
-	 * if $options['count'] is set to a truthy value
365
-	 *
366
-	 * @param array $options An options array:
367
-	 * 	'calculation'            => The calculation to use. Must be a valid MySQL function.
368
-	 *                              Defaults to sum.  Result selected as 'annotation_calculation'.
369
-	 *                              Don't confuse this "calculation" option with the
370
-	 *                              "annotation_calculation" option to elgg_get_annotations().
371
-	 *                              This "calculation" option is applied to each entity's set of
372
-	 *                              annotations and is selected as annotation_calculation for that row.
373
-	 *                              See the docs for elgg_get_annotations() for proper use of the
374
-	 *                              "annotation_calculation" option.
375
-	 *	'order_by'               => The order for the sorting. Defaults to 'annotation_calculation desc'.
376
-	 *	'annotation_names'       => The names of annotations on the entity.
377
-	 *	'annotation_values'	     => The values of annotations on the entity.
378
-	 *
379
-	 * 	'metadata_names'         => The name of metadata on the entity.
380
-	 * 	'metadata_values'        => The value of metadata on the entitiy.
381
-	 * 	'callback'               => Callback function to pass each row through.
382
-	 *                              @tip This function is different from other ege* functions,
383
-	 *                              as it uses a metastring-based getter function { @link elgg_get_annotations() },
384
-	 *                              therefore the callback function should be a derivative of { @link entity_row_to_elggstar() }
385
-	 *                              and not of { @link row_to_annotation() }
386
-	 *
387
-	 * @return \ElggEntity[]|int An array or a count of entities
388
-	 * @see elgg_get_annotations()
389
-	 * @see elgg_get_entities_from_annotations()
390
-	 */
391
-	function getEntitiesFromCalculation($options) {
352
+        if ($time_wheres) {
353
+            $options['wheres'][] = $time_wheres;
354
+        }
355
+	
356
+        return elgg_get_entities_from_metadata($options);
357
+    }
358
+	
359
+    /**
360
+     * Get entities ordered by a mathematical calculation on annotation values
361
+     *
362
+     * @tip Note that this function uses { @link elgg_get_annotations() } to return a list of entities ordered by a mathematical
363
+     * calculation on annotation values, and { @link elgg_get_entities_from_annotations() } to return a count of entities
364
+     * if $options['count'] is set to a truthy value
365
+     *
366
+     * @param array $options An options array:
367
+     * 	'calculation'            => The calculation to use. Must be a valid MySQL function.
368
+     *                              Defaults to sum.  Result selected as 'annotation_calculation'.
369
+     *                              Don't confuse this "calculation" option with the
370
+     *                              "annotation_calculation" option to elgg_get_annotations().
371
+     *                              This "calculation" option is applied to each entity's set of
372
+     *                              annotations and is selected as annotation_calculation for that row.
373
+     *                              See the docs for elgg_get_annotations() for proper use of the
374
+     *                              "annotation_calculation" option.
375
+     *	'order_by'               => The order for the sorting. Defaults to 'annotation_calculation desc'.
376
+     *	'annotation_names'       => The names of annotations on the entity.
377
+     *	'annotation_values'	     => The values of annotations on the entity.
378
+     *
379
+     * 	'metadata_names'         => The name of metadata on the entity.
380
+     * 	'metadata_values'        => The value of metadata on the entitiy.
381
+     * 	'callback'               => Callback function to pass each row through.
382
+     *                              @tip This function is different from other ege* functions,
383
+     *                              as it uses a metastring-based getter function { @link elgg_get_annotations() },
384
+     *                              therefore the callback function should be a derivative of { @link entity_row_to_elggstar() }
385
+     *                              and not of { @link row_to_annotation() }
386
+     *
387
+     * @return \ElggEntity[]|int An array or a count of entities
388
+     * @see elgg_get_annotations()
389
+     * @see elgg_get_entities_from_annotations()
390
+     */
391
+    function getEntitiesFromCalculation($options) {
392 392
 		
393
-		if (isset($options['count']) && $options['count']) {
394
-			return elgg_get_entities_from_annotations($options);
395
-		}
393
+        if (isset($options['count']) && $options['count']) {
394
+            return elgg_get_entities_from_annotations($options);
395
+        }
396 396
 		
397
-		$db_prefix = $this->db->prefix;
398
-		$defaults = [
399
-			'calculation' => 'sum',
400
-			'order_by' => 'annotation_calculation desc'
401
-		];
397
+        $db_prefix = $this->db->prefix;
398
+        $defaults = [
399
+            'calculation' => 'sum',
400
+            'order_by' => 'annotation_calculation desc'
401
+        ];
402 402
 	
403
-		$options = array_merge($defaults, $options);
403
+        $options = array_merge($defaults, $options);
404 404
 	
405
-		$function = sanitize_string(elgg_extract('calculation', $options, 'sum', false));
405
+        $function = sanitize_string(elgg_extract('calculation', $options, 'sum', false));
406 406
 	
407
-		// you must cast this as an int or it sorts wrong.
408
-		$options['selects'][] = 'e.*';
409
-		$options['selects'][] = "$function(CAST(n_table.value AS signed)) AS annotation_calculation";
407
+        // you must cast this as an int or it sorts wrong.
408
+        $options['selects'][] = 'e.*';
409
+        $options['selects'][] = "$function(CAST(n_table.value AS signed)) AS annotation_calculation";
410 410
 	
411
-		// don't need access control because it's taken care of by elgg_get_annotations.
412
-		$options['group_by'] = 'n_table.entity_guid';
411
+        // don't need access control because it's taken care of by elgg_get_annotations.
412
+        $options['group_by'] = 'n_table.entity_guid';
413 413
 
414
-		// do not default to a callback function used in elgg_get_annotation()
415
-		if (!isset($options['callback'])) {
416
-			$options['callback'] = 'entity_row_to_elggstar';
417
-		}
414
+        // do not default to a callback function used in elgg_get_annotation()
415
+        if (!isset($options['callback'])) {
416
+            $options['callback'] = 'entity_row_to_elggstar';
417
+        }
418 418
 
419
-		return elgg_get_annotations($options);
420
-	}
421
-	
422
-	/**
423
-	 * Check to see if a user has already created an annotation on an object
424
-	 *
425
-	 * @param int    $entity_guid     Entity guid
426
-	 * @param string $annotation_type Type of annotation
427
-	 * @param int    $owner_guid      Defaults to logged in user.
428
-	 *
429
-	 * @return bool
430
-	 */
431
-	function exists($entity_guid, $annotation_type, $owner_guid = null) {
432
-	
433
-		if (!$owner_guid && !($owner_guid = $this->session->getLoggedInUserGuid())) {
434
-			return false;
435
-		}
419
+        return elgg_get_annotations($options);
420
+    }
421
+	
422
+    /**
423
+     * Check to see if a user has already created an annotation on an object
424
+     *
425
+     * @param int    $entity_guid     Entity guid
426
+     * @param string $annotation_type Type of annotation
427
+     * @param int    $owner_guid      Defaults to logged in user.
428
+     *
429
+     * @return bool
430
+     */
431
+    function exists($entity_guid, $annotation_type, $owner_guid = null) {
432
+	
433
+        if (!$owner_guid && !($owner_guid = $this->session->getLoggedInUserGuid())) {
434
+            return false;
435
+        }
436 436
 		
437
-		$sql = "SELECT id FROM {$this->db->prefix}annotations
437
+        $sql = "SELECT id FROM {$this->db->prefix}annotations
438 438
 				WHERE owner_guid = :owner_guid
439 439
 				AND entity_guid = :entity_guid
440 440
 				AND name = :annotation_type";
441 441
 
442
-		$result = $this->db->getDataRow($sql, null, [
443
-			':owner_guid' => (int) $owner_guid,
444
-			':entity_guid' => (int) $entity_guid,
445
-			':annotation_type' => $annotation_type,
446
-		]);
447
-	
448
-		return (bool) $result;
449
-	}
442
+        $result = $this->db->getDataRow($sql, null, [
443
+            ':owner_guid' => (int) $owner_guid,
444
+            ':entity_guid' => (int) $entity_guid,
445
+            ':annotation_type' => $annotation_type,
446
+        ]);
447
+	
448
+        return (bool) $result;
449
+    }
450 450
 }
Please login to merge, or discard this patch.
engine/classes/Elgg/Database/SiteSecret.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
 	 *
29 29
 	 * Note: Old secrets were hex encoded.
30 30
 	 *
31
-	 * @return mixed The site secret hash or false
31
+	 * @return string|false The site secret hash or false
32 32
 	 * @access private
33 33
 	 */
34 34
 	function init() {
Please login to merge, or discard this patch.
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -23,116 +23,116 @@
 block discarded – undo
23 23
  */
24 24
 class SiteSecret {
25 25
 
26
-	const CONFIG_KEY = '__site_secret__';
26
+    const CONFIG_KEY = '__site_secret__';
27 27
 
28
-	/**
29
-	 * @var ElggConfig
30
-	 */
31
-	private $config;
28
+    /**
29
+     * @var ElggConfig
30
+     */
31
+    private $config;
32 32
 
33
-	/**
34
-	 * Constructor
35
-	 *
36
-	 * @param ElggConfig $config Config service
37
-	 */
38
-	public function __construct(ElggConfig $config) {
39
-		$this->config = $config;
40
-	}
33
+    /**
34
+     * Constructor
35
+     *
36
+     * @param ElggConfig $config Config service
37
+     */
38
+    public function __construct(ElggConfig $config) {
39
+        $this->config = $config;
40
+    }
41 41
 
42
-	/**
43
-	 * @var string
44
-	 */
45
-	private $test_secret = '';
42
+    /**
43
+     * @var string
44
+     */
45
+    private $test_secret = '';
46 46
 
47
-	/**
48
-	 * Set a secret to be used in testing
49
-	 *
50
-	 * @param string $secret Testing site secret. 32 alphanums starting with "z"
51
-	 * @return void
52
-	 */
53
-	public function setTestingSecret($secret) {
54
-		$this->test_secret = $secret;
55
-	}
47
+    /**
48
+     * Set a secret to be used in testing
49
+     *
50
+     * @param string $secret Testing site secret. 32 alphanums starting with "z"
51
+     * @return void
52
+     */
53
+    public function setTestingSecret($secret) {
54
+        $this->test_secret = $secret;
55
+    }
56 56
 
57
-	/**
58
-	 * Initialise the site secret (32 bytes: "z" to indicate format + 186-bit key in Base64 URL).
59
-	 *
60
-	 * Used during installation and saves as a config.
61
-	 *
62
-	 * Note: Old secrets were hex encoded.
63
-	 *
64
-	 * @return mixed The site secret hash or false
65
-	 * @access private
66
-	 */
67
-	function init() {
68
-		$secret = 'z' . _elgg_services()->crypto->getRandomString(31);
57
+    /**
58
+     * Initialise the site secret (32 bytes: "z" to indicate format + 186-bit key in Base64 URL).
59
+     *
60
+     * Used during installation and saves as a config.
61
+     *
62
+     * Note: Old secrets were hex encoded.
63
+     *
64
+     * @return mixed The site secret hash or false
65
+     * @access private
66
+     */
67
+    function init() {
68
+        $secret = 'z' . _elgg_services()->crypto->getRandomString(31);
69 69
 
70
-		if ($this->config->save(self::CONFIG_KEY, $secret)) {
71
-			return $secret;
72
-		}
70
+        if ($this->config->save(self::CONFIG_KEY, $secret)) {
71
+            return $secret;
72
+        }
73 73
 
74
-		return false;
75
-	}
74
+        return false;
75
+    }
76 76
 
77
-	/**
78
-	 * Returns the site secret.
79
-	 *
80
-	 * Used to generate difficult to guess hashes for sessions and action tokens.
81
-	 *
82
-	 * @param bool $raw If true, a binary key will be returned
83
-	 *
84
-	 * @return string Site secret.
85
-	 * @access private
86
-	 */
87
-	function get($raw = false) {
88
-		if ($this->test_secret) {
89
-			$secret = $this->test_secret;
90
-		} else {
91
-			$secret = $this->config->get(self::CONFIG_KEY);
92
-		}
93
-		if (!$secret) {
94
-			$secret = $this->init();
95
-		}
77
+    /**
78
+     * Returns the site secret.
79
+     *
80
+     * Used to generate difficult to guess hashes for sessions and action tokens.
81
+     *
82
+     * @param bool $raw If true, a binary key will be returned
83
+     *
84
+     * @return string Site secret.
85
+     * @access private
86
+     */
87
+    function get($raw = false) {
88
+        if ($this->test_secret) {
89
+            $secret = $this->test_secret;
90
+        } else {
91
+            $secret = $this->config->get(self::CONFIG_KEY);
92
+        }
93
+        if (!$secret) {
94
+            $secret = $this->init();
95
+        }
96 96
 
97
-		if ($raw) {
98
-			// try to return binary key
99
-			if ($secret[0] === 'z') {
100
-				// new keys are "z" + base64URL
101
-				$base64 = strtr(substr($secret, 1), '-_', '+/');
102
-				$key = base64_decode($base64);
103
-				if ($key !== false) {
104
-					// on failure, at least return string key :/
105
-					return $key;
106
-				}
107
-			} else {
108
-				// old keys are hex
109
-				return hex2bin($secret);
110
-			}
111
-		}
97
+        if ($raw) {
98
+            // try to return binary key
99
+            if ($secret[0] === 'z') {
100
+                // new keys are "z" + base64URL
101
+                $base64 = strtr(substr($secret, 1), '-_', '+/');
102
+                $key = base64_decode($base64);
103
+                if ($key !== false) {
104
+                    // on failure, at least return string key :/
105
+                    return $key;
106
+                }
107
+            } else {
108
+                // old keys are hex
109
+                return hex2bin($secret);
110
+            }
111
+        }
112 112
 
113
-		return $secret;
114
-	}
113
+        return $secret;
114
+    }
115 115
 
116
-	/**
117
-	 * Get the strength of the site secret
118
-	 *
119
-	 * If "weak" or "moderate" is returned, this assumes we're running on the same system that created
120
-	 * the key.
121
-	 *
122
-	 * @return string "strong", "moderate", or "weak"
123
-	 * @access private
124
-	 */
125
-	function getStrength() {
126
-		$secret = $this->get();
127
-		if ($secret[0] !== 'z') {
128
-			$rand_max = getrandmax();
129
-			if ($rand_max < pow(2, 16)) {
130
-				return 'weak';
131
-			}
132
-			if ($rand_max < pow(2, 32)) {
133
-				return 'moderate';
134
-			}
135
-		}
136
-		return 'strong';
137
-	}
116
+    /**
117
+     * Get the strength of the site secret
118
+     *
119
+     * If "weak" or "moderate" is returned, this assumes we're running on the same system that created
120
+     * the key.
121
+     *
122
+     * @return string "strong", "moderate", or "weak"
123
+     * @access private
124
+     */
125
+    function getStrength() {
126
+        $secret = $this->get();
127
+        if ($secret[0] !== 'z') {
128
+            $rand_max = getrandmax();
129
+            if ($rand_max < pow(2, 16)) {
130
+                return 'weak';
131
+            }
132
+            if ($rand_max < pow(2, 32)) {
133
+                return 'moderate';
134
+            }
135
+        }
136
+        return 'strong';
137
+    }
138 138
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 	 * @access private
66 66
 	 */
67 67
 	function init() {
68
-		$secret = 'z' . _elgg_services()->crypto->getRandomString(31);
68
+		$secret = 'z'._elgg_services()->crypto->getRandomString(31);
69 69
 
70 70
 		if ($this->config->save(self::CONFIG_KEY, $secret)) {
71 71
 			return $secret;
Please login to merge, or discard this patch.
engine/classes/Elgg/Http/Request.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -105,6 +105,7 @@
 block discarded – undo
105 105
 
106 106
 	/**
107 107
 	 * {@inheritdoc}
108
+	 * @return string
108 109
 	 */
109 110
 	public function getClientIp() {
110 111
 		$ip = parent::getClientIp();
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 namespace Elgg\Http;
3 3
 
4 4
 use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
5
-use Elgg\Application;
6 5
 
7 6
 /**
8 7
  * Elgg HTTP request.
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -11,81 +11,81 @@
 block discarded – undo
11 11
  */
12 12
 class Request extends SymfonyRequest {
13 13
 
14
-	/**
15
-	 * Get the Elgg URL segments
16
-	 *
17
-	 * @param bool $raw If true, the segments will not be HTML escaped
18
-	 *
19
-	 * @return string[]
20
-	 */
21
-	public function getUrlSegments($raw = false) {
22
-		$path = trim($this->getPathInfo(), '/');
23
-		if (!$raw) {
24
-			$path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
25
-		}
26
-		if (!$path) {
27
-			return [];
28
-		}
14
+    /**
15
+     * Get the Elgg URL segments
16
+     *
17
+     * @param bool $raw If true, the segments will not be HTML escaped
18
+     *
19
+     * @return string[]
20
+     */
21
+    public function getUrlSegments($raw = false) {
22
+        $path = trim($this->getPathInfo(), '/');
23
+        if (!$raw) {
24
+            $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
25
+        }
26
+        if (!$path) {
27
+            return [];
28
+        }
29 29
 
30
-		return explode('/', $path);
31
-	}
30
+        return explode('/', $path);
31
+    }
32 32
 
33
-	/**
34
-	 * Get a cloned request with new Elgg URL segments
35
-	 *
36
-	 * @param string[] $segments URL segments
37
-	 *
38
-	 * @return Request
39
-	 */
40
-	public function setUrlSegments(array $segments) {
41
-		$base_path = trim($this->getBasePath(), '/');
42
-		$server = $this->server->all();
43
-		$server['REQUEST_URI'] = "$base_path/" . implode('/', $segments);
33
+    /**
34
+     * Get a cloned request with new Elgg URL segments
35
+     *
36
+     * @param string[] $segments URL segments
37
+     *
38
+     * @return Request
39
+     */
40
+    public function setUrlSegments(array $segments) {
41
+        $base_path = trim($this->getBasePath(), '/');
42
+        $server = $this->server->all();
43
+        $server['REQUEST_URI'] = "$base_path/" . implode('/', $segments);
44 44
 
45
-		return $this->duplicate(null, null, null, null, null, $server);
46
-	}
45
+        return $this->duplicate(null, null, null, null, null, $server);
46
+    }
47 47
 
48
-	/**
49
-	 * Get first Elgg URL segment
50
-	 *
51
-	 * @see \Elgg\Http\Request::getUrlSegments()
52
-	 *
53
-	 * @return string
54
-	 */
55
-	public function getFirstUrlSegment() {
56
-		$segments = $this->getUrlSegments();
57
-		if ($segments) {
58
-			return array_shift($segments);
59
-		} else {
60
-			return '';
61
-		}
62
-	}
48
+    /**
49
+     * Get first Elgg URL segment
50
+     *
51
+     * @see \Elgg\Http\Request::getUrlSegments()
52
+     *
53
+     * @return string
54
+     */
55
+    public function getFirstUrlSegment() {
56
+        $segments = $this->getUrlSegments();
57
+        if ($segments) {
58
+            return array_shift($segments);
59
+        } else {
60
+            return '';
61
+        }
62
+    }
63 63
 
64
-	/**
65
-	 * {@inheritdoc}
66
-	 */
67
-	public function getClientIp() {
68
-		$ip = parent::getClientIp();
64
+    /**
65
+     * {@inheritdoc}
66
+     */
67
+    public function getClientIp() {
68
+        $ip = parent::getClientIp();
69 69
 
70
-		if ($ip == $this->server->get('REMOTE_ADDR')) {
71
-			// try one more
72
-			$ip_addresses = $this->server->get('HTTP_X_REAL_IP');
73
-			if ($ip_addresses) {
74
-				$ip_addresses = explode(',', $ip_addresses);
75
-				return array_pop($ip_addresses);
76
-			}
77
-		}
70
+        if ($ip == $this->server->get('REMOTE_ADDR')) {
71
+            // try one more
72
+            $ip_addresses = $this->server->get('HTTP_X_REAL_IP');
73
+            if ($ip_addresses) {
74
+                $ip_addresses = explode(',', $ip_addresses);
75
+                return array_pop($ip_addresses);
76
+            }
77
+        }
78 78
 
79
-		return $ip;
80
-	}
79
+        return $ip;
80
+    }
81 81
 
82
-	/**
83
-	 * {@inheritdoc}
84
-	 */
85
-	public function isXmlHttpRequest() {
86
-		return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest'
87
-			|| $this->query->get('X-Requested-With') === 'XMLHttpRequest'
88
-			|| $this->request->get('X-Requested-With') === 'XMLHttpRequest');
89
-		// GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735
90
-	}
82
+    /**
83
+     * {@inheritdoc}
84
+     */
85
+    public function isXmlHttpRequest() {
86
+        return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest'
87
+            || $this->query->get('X-Requested-With') === 'XMLHttpRequest'
88
+            || $this->request->get('X-Requested-With') === 'XMLHttpRequest');
89
+        // GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735
90
+    }
91 91
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 	public function setUrlSegments(array $segments) {
41 41
 		$base_path = trim($this->getBasePath(), '/');
42 42
 		$server = $this->server->all();
43
-		$server['REQUEST_URI'] = "$base_path/" . implode('/', $segments);
43
+		$server['REQUEST_URI'] = "$base_path/".implode('/', $segments);
44 44
 
45 45
 		return $this->duplicate(null, null, null, null, null, $server);
46 46
 	}
Please login to merge, or discard this patch.
engine/classes/ElggBatch.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@
 block discarded – undo
174 174
 	 * @param array  $options    The options array to pass to the getter function. If limit is
175 175
 	 *                           not set, 10 is used as the default. In most cases that is not
176 176
 	 *                           what you want.
177
-	 * @param mixed  $callback   An optional callback function that all results will be passed
177
+	 * @param null|string  $callback   An optional callback function that all results will be passed
178 178
 	 *                           to upon load.  The callback needs to accept $result, $getter,
179 179
 	 *                           $options.
180 180
 	 * @param int    $chunk_size The number of entities to pull in before requesting more.
Please login to merge, or discard this patch.
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -72,389 +72,389 @@
 block discarded – undo
72 72
  */
73 73
 class ElggBatch implements BatchResult {
74 74
 
75
-	/**
76
-	 * The objects to iterate over.
77
-	 *
78
-	 * @var array
79
-	 */
80
-	private $results = [];
81
-
82
-	/**
83
-	 * The function used to get results.
84
-	 *
85
-	 * @var callable
86
-	 */
87
-	private $getter = null;
88
-
89
-	/**
90
-	 * The given $options to alter and pass to the getter.
91
-	 *
92
-	 * @var array
93
-	 */
94
-	private $options = [];
95
-
96
-	/**
97
-	 * The number of results to grab at a time.
98
-	 *
99
-	 * @var int
100
-	 */
101
-	private $chunkSize = 25;
102
-
103
-	/**
104
-	 * A callback function to pass results through.
105
-	 *
106
-	 * @var callable
107
-	 */
108
-	private $callback = null;
109
-
110
-	/**
111
-	 * Start after this many results.
112
-	 *
113
-	 * @var int
114
-	 */
115
-	private $offset = 0;
116
-
117
-	/**
118
-	 * Stop after this many results.
119
-	 *
120
-	 * @var int
121
-	 */
122
-	private $limit = 0;
123
-
124
-	/**
125
-	 * Number of processed results.
126
-	 *
127
-	 * @var int
128
-	 */
129
-	private $retrievedResults = 0;
130
-
131
-	/**
132
-	 * The index of the current result within the current chunk
133
-	 *
134
-	 * @var int
135
-	 */
136
-	private $resultIndex = 0;
137
-
138
-	/**
139
-	 * The index of the current chunk
140
-	 *
141
-	 * @var int
142
-	 */
143
-	private $chunkIndex = 0;
144
-
145
-	/**
146
-	 * The number of results iterated through
147
-	 *
148
-	 * @var int
149
-	 */
150
-	private $processedResults = 0;
151
-
152
-	/**
153
-	 * Is the getter a valid callback
154
-	 *
155
-	 * @var bool
156
-	 */
157
-	private $validGetter = null;
158
-
159
-	/**
160
-	 * The result of running all entities through the callback function.
161
-	 *
162
-	 * @var mixed
163
-	 */
164
-	public $callbackResult = null;
165
-
166
-	/**
167
-	 * If false, offset will not be incremented. This is used for callbacks/loops that delete.
168
-	 *
169
-	 * @var bool
170
-	 */
171
-	private $incrementOffset = true;
172
-
173
-	/**
174
-	 * Entities that could not be instantiated during a fetch
175
-	 *
176
-	 * @var \stdClass[]
177
-	 */
178
-	private $incompleteEntities = [];
179
-
180
-	/**
181
-	 * Total number of incomplete entities fetched
182
-	 *
183
-	 * @var int
184
-	 */
185
-	private $totalIncompletes = 0;
186
-
187
-	/**
188
-	 * Batches operations on any elgg_get_*() or compatible function that supports
189
-	 * an options array.
190
-	 *
191
-	 * Instead of returning all objects in memory, it goes through $chunk_size
192
-	 * objects, then requests more from the server.  This avoids OOM errors.
193
-	 *
194
-	 * @param string $getter     The function used to get objects.  Usually
195
-	 *                           an elgg_get_*() function, but can be any valid PHP callback.
196
-	 * @param array  $options    The options array to pass to the getter function. If limit is
197
-	 *                           not set, 10 is used as the default. In most cases that is not
198
-	 *                           what you want.
199
-	 * @param mixed  $callback   An optional callback function that all results will be passed
200
-	 *                           to upon load.  The callback needs to accept $result, $getter,
201
-	 *                           $options.
202
-	 * @param int    $chunk_size The number of entities to pull in before requesting more.
203
-	 *                           You have to balance this between running out of memory in PHP
204
-	 *                           and hitting the db server too often.
205
-	 * @param bool   $inc_offset Increment the offset on each fetch. This must be false for
206
-	 *                           callbacks that delete rows. You can set this after the
207
-	 *                           object is created with {@link \ElggBatch::setIncrementOffset()}.
208
-	 */
209
-	public function __construct($getter, $options, $callback = null, $chunk_size = 25,
210
-			$inc_offset = true) {
75
+    /**
76
+     * The objects to iterate over.
77
+     *
78
+     * @var array
79
+     */
80
+    private $results = [];
81
+
82
+    /**
83
+     * The function used to get results.
84
+     *
85
+     * @var callable
86
+     */
87
+    private $getter = null;
88
+
89
+    /**
90
+     * The given $options to alter and pass to the getter.
91
+     *
92
+     * @var array
93
+     */
94
+    private $options = [];
95
+
96
+    /**
97
+     * The number of results to grab at a time.
98
+     *
99
+     * @var int
100
+     */
101
+    private $chunkSize = 25;
102
+
103
+    /**
104
+     * A callback function to pass results through.
105
+     *
106
+     * @var callable
107
+     */
108
+    private $callback = null;
109
+
110
+    /**
111
+     * Start after this many results.
112
+     *
113
+     * @var int
114
+     */
115
+    private $offset = 0;
116
+
117
+    /**
118
+     * Stop after this many results.
119
+     *
120
+     * @var int
121
+     */
122
+    private $limit = 0;
123
+
124
+    /**
125
+     * Number of processed results.
126
+     *
127
+     * @var int
128
+     */
129
+    private $retrievedResults = 0;
130
+
131
+    /**
132
+     * The index of the current result within the current chunk
133
+     *
134
+     * @var int
135
+     */
136
+    private $resultIndex = 0;
137
+
138
+    /**
139
+     * The index of the current chunk
140
+     *
141
+     * @var int
142
+     */
143
+    private $chunkIndex = 0;
144
+
145
+    /**
146
+     * The number of results iterated through
147
+     *
148
+     * @var int
149
+     */
150
+    private $processedResults = 0;
151
+
152
+    /**
153
+     * Is the getter a valid callback
154
+     *
155
+     * @var bool
156
+     */
157
+    private $validGetter = null;
158
+
159
+    /**
160
+     * The result of running all entities through the callback function.
161
+     *
162
+     * @var mixed
163
+     */
164
+    public $callbackResult = null;
165
+
166
+    /**
167
+     * If false, offset will not be incremented. This is used for callbacks/loops that delete.
168
+     *
169
+     * @var bool
170
+     */
171
+    private $incrementOffset = true;
172
+
173
+    /**
174
+     * Entities that could not be instantiated during a fetch
175
+     *
176
+     * @var \stdClass[]
177
+     */
178
+    private $incompleteEntities = [];
179
+
180
+    /**
181
+     * Total number of incomplete entities fetched
182
+     *
183
+     * @var int
184
+     */
185
+    private $totalIncompletes = 0;
186
+
187
+    /**
188
+     * Batches operations on any elgg_get_*() or compatible function that supports
189
+     * an options array.
190
+     *
191
+     * Instead of returning all objects in memory, it goes through $chunk_size
192
+     * objects, then requests more from the server.  This avoids OOM errors.
193
+     *
194
+     * @param string $getter     The function used to get objects.  Usually
195
+     *                           an elgg_get_*() function, but can be any valid PHP callback.
196
+     * @param array  $options    The options array to pass to the getter function. If limit is
197
+     *                           not set, 10 is used as the default. In most cases that is not
198
+     *                           what you want.
199
+     * @param mixed  $callback   An optional callback function that all results will be passed
200
+     *                           to upon load.  The callback needs to accept $result, $getter,
201
+     *                           $options.
202
+     * @param int    $chunk_size The number of entities to pull in before requesting more.
203
+     *                           You have to balance this between running out of memory in PHP
204
+     *                           and hitting the db server too often.
205
+     * @param bool   $inc_offset Increment the offset on each fetch. This must be false for
206
+     *                           callbacks that delete rows. You can set this after the
207
+     *                           object is created with {@link \ElggBatch::setIncrementOffset()}.
208
+     */
209
+    public function __construct($getter, $options, $callback = null, $chunk_size = 25,
210
+            $inc_offset = true) {
211 211
 		
212
-		$this->getter = $getter;
213
-		$this->options = $options;
214
-		$this->callback = $callback;
215
-		$this->chunkSize = $chunk_size;
216
-		$this->setIncrementOffset($inc_offset);
217
-
218
-		if ($this->chunkSize <= 0) {
219
-			$this->chunkSize = 25;
220
-		}
221
-
222
-		// store these so we can compare later
223
-		$this->offset = elgg_extract('offset', $options, 0);
224
-		$this->limit = elgg_extract('limit', $options, elgg_get_config('default_limit'));
225
-
226
-		// if passed a callback, create a new \ElggBatch with the same options
227
-		// and pass each to the callback.
228
-		if ($callback && is_callable($callback)) {
229
-			$batch = new \ElggBatch($getter, $options, null, $chunk_size, $inc_offset);
230
-
231
-			$all_results = null;
232
-
233
-			foreach ($batch as $result) {
234
-				$result = call_user_func($callback, $result, $getter, $options);
235
-
236
-				if (!isset($all_results)) {
237
-					if ($result === true || $result === false || $result === null) {
238
-						$all_results = $result;
239
-					} else {
240
-						$all_results = [];
241
-					}
242
-				}
243
-
244
-				if (($result === true || $result === false || $result === null) && !is_array($all_results)) {
245
-					$all_results = $result && $all_results;
246
-				} else {
247
-					$all_results[] = $result;
248
-				}
249
-			}
250
-
251
-			$this->callbackResult = $all_results;
252
-		}
253
-	}
254
-
255
-	/**
256
-	 * Tell the process that an entity was incomplete during a fetch
257
-	 *
258
-	 * @param \stdClass $row
259
-	 *
260
-	 * @access private
261
-	 */
262
-	public function reportIncompleteEntity(\stdClass $row) {
263
-		$this->incompleteEntities[] = $row;
264
-	}
265
-
266
-	/**
267
-	 * Fetches the next chunk of results
268
-	 *
269
-	 * @return bool
270
-	 */
271
-	private function getNextResultsChunk() {
272
-
273
-		// always reset results.
274
-		$this->results = [];
275
-
276
-		if (!isset($this->validGetter)) {
277
-			$this->validGetter = is_callable($this->getter);
278
-		}
279
-
280
-		if (!$this->validGetter) {
281
-			return false;
282
-		}
283
-
284
-		$limit = $this->chunkSize;
285
-
286
-		// if someone passed limit = 0 they want everything.
287
-		if ($this->limit != 0) {
288
-			if ($this->retrievedResults >= $this->limit) {
289
-				return false;
290
-			}
291
-
292
-			// if original limit < chunk size, set limit to original limit
293
-			// else if the number of results we'll fetch if greater than the original limit
294
-			if ($this->limit < $this->chunkSize) {
295
-				$limit = $this->limit;
296
-			} elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
297
-				// set the limit to the number of results remaining in the original limit
298
-				$limit = $this->limit - $this->retrievedResults;
299
-			}
300
-		}
301
-
302
-		if ($this->incrementOffset) {
303
-			$offset = $this->offset + $this->retrievedResults;
304
-		} else {
305
-			$offset = $this->offset + $this->totalIncompletes;
306
-		}
307
-
308
-		$current_options = [
309
-			'limit' => $limit,
310
-			'offset' => $offset,
311
-			'__ElggBatch' => $this,
312
-		];
313
-
314
-		$options = array_merge($this->options, $current_options);
315
-
316
-		$this->incompleteEntities = [];
317
-		$this->results = call_user_func($this->getter, $options);
318
-
319
-		// batch result sets tend to be large; we don't want to cache these.
320
-		_elgg_services()->db->disableQueryCache();
321
-
322
-		$num_results = count($this->results);
323
-		$num_incomplete = count($this->incompleteEntities);
324
-
325
-		$this->totalIncompletes += $num_incomplete;
326
-
327
-		if ($this->incompleteEntities) {
328
-			// pad the front of the results with nulls representing the incompletes
329
-			array_splice($this->results, 0, 0, array_pad([], $num_incomplete, null));
330
-			// ...and skip past them
331
-			reset($this->results);
332
-			for ($i = 0; $i < $num_incomplete; $i++) {
333
-				next($this->results);
334
-			}
335
-		}
336
-
337
-		if ($this->results) {
338
-			$this->chunkIndex++;
339
-
340
-			// let the system know we've jumped past the nulls
341
-			$this->resultIndex = $num_incomplete;
342
-
343
-			$this->retrievedResults += ($num_results + $num_incomplete);
344
-			if ($num_results == 0) {
345
-				// This fetch was *all* incompletes! We need to fetch until we can either
346
-				// offer at least one row to iterate over, or give up.
347
-				return $this->getNextResultsChunk();
348
-			}
349
-			_elgg_services()->db->enableQueryCache();
350
-			return true;
351
-		} else {
352
-			_elgg_services()->db->enableQueryCache();
353
-			return false;
354
-		}
355
-	}
356
-
357
-	/**
358
-	 * Increment the offset from the original options array? Setting to
359
-	 * false is required for callbacks that delete rows.
360
-	 *
361
-	 * @param bool $increment Set to false when deleting data
362
-	 * @return void
363
-	 */
364
-	public function setIncrementOffset($increment = true) {
365
-		$this->incrementOffset = (bool) $increment;
366
-	}
367
-
368
-	/**
369
-	 * Implements Iterator
370
-	 */
371
-
372
-	/**
373
-	 * {@inheritdoc}
374
-	 */
375
-	public function rewind() {
376
-		$this->resultIndex = 0;
377
-		$this->retrievedResults = 0;
378
-		$this->processedResults = 0;
379
-
380
-		// only grab results if we haven't yet or we're crossing chunks
381
-		if ($this->chunkIndex == 0 || $this->limit > $this->chunkSize) {
382
-			$this->chunkIndex = 0;
383
-			$this->getNextResultsChunk();
384
-		}
385
-	}
386
-
387
-	/**
388
-	 * {@inheritdoc}
389
-	 */
390
-	public function current() {
391
-		return current($this->results);
392
-	}
393
-
394
-	/**
395
-	 * {@inheritdoc}
396
-	 */
397
-	public function key() {
398
-		return $this->processedResults;
399
-	}
400
-
401
-	/**
402
-	 * {@inheritdoc}
403
-	 */
404
-	public function next() {
405
-		// if we'll be at the end.
406
-		if (($this->processedResults + 1) >= $this->limit && $this->limit > 0) {
407
-			$this->results = [];
408
-			return false;
409
-		}
410
-
411
-		// if we'll need new results.
412
-		if (($this->resultIndex + 1) >= $this->chunkSize) {
413
-			if (!$this->getNextResultsChunk()) {
414
-				$this->results = [];
415
-				return false;
416
-			}
417
-
418
-			$result = current($this->results);
419
-		} else {
420
-			// the function above resets the indexes, so only inc if not
421
-			// getting new set
422
-			$this->resultIndex++;
423
-			$result = next($this->results);
424
-		}
425
-
426
-		$this->processedResults++;
427
-		return $result;
428
-	}
429
-
430
-	/**
431
-	 * {@inheritdoc}
432
-	 */
433
-	public function valid() {
434
-		if (!is_array($this->results)) {
435
-			return false;
436
-		}
437
-		$key = key($this->results);
438
-		return ($key !== null && $key !== false);
439
-	}
440
-
441
-	/**
442
-	 * Count the total results available at this moment.
443
-	 *
444
-	 * As this performs a separate query, the count returned may not match the number of results you can
445
-	 * fetch via iteration on a very active DB.
446
-	 *
447
-	 * @see Countable::count()
448
-	 * @return int
449
-	 */
450
-	public function count() {
451
-		if (!is_callable($this->getter)) {
452
-			$inspector = new \Elgg\Debug\Inspector();
453
-			throw new RuntimeException("Getter is not callable: " . $inspector->describeCallable($this->getter));
454
-		}
455
-
456
-		$options = $this->options + ['count' => true];
457
-
458
-		return call_user_func($this->getter, $options);
459
-	}
212
+        $this->getter = $getter;
213
+        $this->options = $options;
214
+        $this->callback = $callback;
215
+        $this->chunkSize = $chunk_size;
216
+        $this->setIncrementOffset($inc_offset);
217
+
218
+        if ($this->chunkSize <= 0) {
219
+            $this->chunkSize = 25;
220
+        }
221
+
222
+        // store these so we can compare later
223
+        $this->offset = elgg_extract('offset', $options, 0);
224
+        $this->limit = elgg_extract('limit', $options, elgg_get_config('default_limit'));
225
+
226
+        // if passed a callback, create a new \ElggBatch with the same options
227
+        // and pass each to the callback.
228
+        if ($callback && is_callable($callback)) {
229
+            $batch = new \ElggBatch($getter, $options, null, $chunk_size, $inc_offset);
230
+
231
+            $all_results = null;
232
+
233
+            foreach ($batch as $result) {
234
+                $result = call_user_func($callback, $result, $getter, $options);
235
+
236
+                if (!isset($all_results)) {
237
+                    if ($result === true || $result === false || $result === null) {
238
+                        $all_results = $result;
239
+                    } else {
240
+                        $all_results = [];
241
+                    }
242
+                }
243
+
244
+                if (($result === true || $result === false || $result === null) && !is_array($all_results)) {
245
+                    $all_results = $result && $all_results;
246
+                } else {
247
+                    $all_results[] = $result;
248
+                }
249
+            }
250
+
251
+            $this->callbackResult = $all_results;
252
+        }
253
+    }
254
+
255
+    /**
256
+     * Tell the process that an entity was incomplete during a fetch
257
+     *
258
+     * @param \stdClass $row
259
+     *
260
+     * @access private
261
+     */
262
+    public function reportIncompleteEntity(\stdClass $row) {
263
+        $this->incompleteEntities[] = $row;
264
+    }
265
+
266
+    /**
267
+     * Fetches the next chunk of results
268
+     *
269
+     * @return bool
270
+     */
271
+    private function getNextResultsChunk() {
272
+
273
+        // always reset results.
274
+        $this->results = [];
275
+
276
+        if (!isset($this->validGetter)) {
277
+            $this->validGetter = is_callable($this->getter);
278
+        }
279
+
280
+        if (!$this->validGetter) {
281
+            return false;
282
+        }
283
+
284
+        $limit = $this->chunkSize;
285
+
286
+        // if someone passed limit = 0 they want everything.
287
+        if ($this->limit != 0) {
288
+            if ($this->retrievedResults >= $this->limit) {
289
+                return false;
290
+            }
291
+
292
+            // if original limit < chunk size, set limit to original limit
293
+            // else if the number of results we'll fetch if greater than the original limit
294
+            if ($this->limit < $this->chunkSize) {
295
+                $limit = $this->limit;
296
+            } elseif ($this->retrievedResults + $this->chunkSize > $this->limit) {
297
+                // set the limit to the number of results remaining in the original limit
298
+                $limit = $this->limit - $this->retrievedResults;
299
+            }
300
+        }
301
+
302
+        if ($this->incrementOffset) {
303
+            $offset = $this->offset + $this->retrievedResults;
304
+        } else {
305
+            $offset = $this->offset + $this->totalIncompletes;
306
+        }
307
+
308
+        $current_options = [
309
+            'limit' => $limit,
310
+            'offset' => $offset,
311
+            '__ElggBatch' => $this,
312
+        ];
313
+
314
+        $options = array_merge($this->options, $current_options);
315
+
316
+        $this->incompleteEntities = [];
317
+        $this->results = call_user_func($this->getter, $options);
318
+
319
+        // batch result sets tend to be large; we don't want to cache these.
320
+        _elgg_services()->db->disableQueryCache();
321
+
322
+        $num_results = count($this->results);
323
+        $num_incomplete = count($this->incompleteEntities);
324
+
325
+        $this->totalIncompletes += $num_incomplete;
326
+
327
+        if ($this->incompleteEntities) {
328
+            // pad the front of the results with nulls representing the incompletes
329
+            array_splice($this->results, 0, 0, array_pad([], $num_incomplete, null));
330
+            // ...and skip past them
331
+            reset($this->results);
332
+            for ($i = 0; $i < $num_incomplete; $i++) {
333
+                next($this->results);
334
+            }
335
+        }
336
+
337
+        if ($this->results) {
338
+            $this->chunkIndex++;
339
+
340
+            // let the system know we've jumped past the nulls
341
+            $this->resultIndex = $num_incomplete;
342
+
343
+            $this->retrievedResults += ($num_results + $num_incomplete);
344
+            if ($num_results == 0) {
345
+                // This fetch was *all* incompletes! We need to fetch until we can either
346
+                // offer at least one row to iterate over, or give up.
347
+                return $this->getNextResultsChunk();
348
+            }
349
+            _elgg_services()->db->enableQueryCache();
350
+            return true;
351
+        } else {
352
+            _elgg_services()->db->enableQueryCache();
353
+            return false;
354
+        }
355
+    }
356
+
357
+    /**
358
+     * Increment the offset from the original options array? Setting to
359
+     * false is required for callbacks that delete rows.
360
+     *
361
+     * @param bool $increment Set to false when deleting data
362
+     * @return void
363
+     */
364
+    public function setIncrementOffset($increment = true) {
365
+        $this->incrementOffset = (bool) $increment;
366
+    }
367
+
368
+    /**
369
+     * Implements Iterator
370
+     */
371
+
372
+    /**
373
+     * {@inheritdoc}
374
+     */
375
+    public function rewind() {
376
+        $this->resultIndex = 0;
377
+        $this->retrievedResults = 0;
378
+        $this->processedResults = 0;
379
+
380
+        // only grab results if we haven't yet or we're crossing chunks
381
+        if ($this->chunkIndex == 0 || $this->limit > $this->chunkSize) {
382
+            $this->chunkIndex = 0;
383
+            $this->getNextResultsChunk();
384
+        }
385
+    }
386
+
387
+    /**
388
+     * {@inheritdoc}
389
+     */
390
+    public function current() {
391
+        return current($this->results);
392
+    }
393
+
394
+    /**
395
+     * {@inheritdoc}
396
+     */
397
+    public function key() {
398
+        return $this->processedResults;
399
+    }
400
+
401
+    /**
402
+     * {@inheritdoc}
403
+     */
404
+    public function next() {
405
+        // if we'll be at the end.
406
+        if (($this->processedResults + 1) >= $this->limit && $this->limit > 0) {
407
+            $this->results = [];
408
+            return false;
409
+        }
410
+
411
+        // if we'll need new results.
412
+        if (($this->resultIndex + 1) >= $this->chunkSize) {
413
+            if (!$this->getNextResultsChunk()) {
414
+                $this->results = [];
415
+                return false;
416
+            }
417
+
418
+            $result = current($this->results);
419
+        } else {
420
+            // the function above resets the indexes, so only inc if not
421
+            // getting new set
422
+            $this->resultIndex++;
423
+            $result = next($this->results);
424
+        }
425
+
426
+        $this->processedResults++;
427
+        return $result;
428
+    }
429
+
430
+    /**
431
+     * {@inheritdoc}
432
+     */
433
+    public function valid() {
434
+        if (!is_array($this->results)) {
435
+            return false;
436
+        }
437
+        $key = key($this->results);
438
+        return ($key !== null && $key !== false);
439
+    }
440
+
441
+    /**
442
+     * Count the total results available at this moment.
443
+     *
444
+     * As this performs a separate query, the count returned may not match the number of results you can
445
+     * fetch via iteration on a very active DB.
446
+     *
447
+     * @see Countable::count()
448
+     * @return int
449
+     */
450
+    public function count() {
451
+        if (!is_callable($this->getter)) {
452
+            $inspector = new \Elgg\Debug\Inspector();
453
+            throw new RuntimeException("Getter is not callable: " . $inspector->describeCallable($this->getter));
454
+        }
455
+
456
+        $options = $this->options + ['count' => true];
457
+
458
+        return call_user_func($this->getter, $options);
459
+    }
460 460
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 	public function count() {
451 451
 		if (!is_callable($this->getter)) {
452 452
 			$inspector = new \Elgg\Debug\Inspector();
453
-			throw new RuntimeException("Getter is not callable: " . $inspector->describeCallable($this->getter));
453
+			throw new RuntimeException("Getter is not callable: ".$inspector->describeCallable($this->getter));
454 454
 		}
455 455
 
456 456
 		$options = $this->options + ['count' => true];
Please login to merge, or discard this patch.
engine/classes/ElggData.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -285,7 +285,7 @@
 block discarded – undo
285 285
 	 *
286 286
 	 * @param int $offset Offset
287 287
 	 *
288
-	 * @return int
288
+	 * @return boolean
289 289
 	 */
290 290
 	public function offsetExists($offset) {
291 291
 		return array_key_exists($offset, $this->attributes);
Please login to merge, or discard this patch.
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -7,220 +7,220 @@
 block discarded – undo
7 7
  * @subpackage DataModel
8 8
  */
9 9
 abstract class ElggData implements
10
-	Loggable,    // Can events related to this object class be logged
11
-	Iterator,    // Override foreach behaviour
12
-	\ArrayAccess // Override for array access
10
+    Loggable,    // Can events related to this object class be logged
11
+    Iterator,    // Override foreach behaviour
12
+    \ArrayAccess // Override for array access
13 13
 {
14 14
 
15
-	use \Elgg\TimeUsing;
15
+    use \Elgg\TimeUsing;
16 16
 	
17
-	/**
18
-	 * The main attributes of an entity.
19
-	 * Holds attributes to save to database
20
-	 * Blank entries for all database fields should be created by the constructor.
21
-	 * Subclasses should add to this in their constructors.
22
-	 * Any field not appearing in this will be viewed as metadata
23
-	 */
24
-	protected $attributes = [];
25
-
26
-	/**
27
-	 * Initialize the attributes array.
28
-	 *
29
-	 * This is vital to distinguish between metadata and base parameters.
30
-	 *
31
-	 * @return void
32
-	 */
33
-	protected function initializeAttributes() {
34
-		// Create attributes array if not already created
35
-		if (!is_array($this->attributes)) {
36
-			$this->attributes = [];
37
-		}
38
-
39
-		$this->attributes['time_created'] = null;
40
-	}
41
-
42
-	/**
43
-	 * Provides a pointer to the database object.
44
-	 *
45
-	 * @return \Elgg\Database The database where this data is (will be) stored.
46
-	 */
47
-	protected function getDatabase() {
48
-		return _elgg_services()->db;
49
-	}
50
-
51
-	/**
52
-	 * Test if property is set either as an attribute or metadata.
53
-	 *
54
-	 * @tip Use isset($entity->property)
55
-	 *
56
-	 * @param string $name The name of the attribute or metadata.
57
-	 *
58
-	 * @return bool
59
-	 */
60
-	public function __isset($name) {
61
-		return $this->$name !== null;
62
-	}
63
-
64
-	/**
65
-	 * Get a URL for this object
66
-	 *
67
-	 * @return string
68
-	 */
69
-	abstract public function getURL();
70
-
71
-	/**
72
-	 * Save this data to the appropriate database table.
73
-	 *
74
-	 * @return bool
75
-	 */
76
-	abstract public function save();
17
+    /**
18
+     * The main attributes of an entity.
19
+     * Holds attributes to save to database
20
+     * Blank entries for all database fields should be created by the constructor.
21
+     * Subclasses should add to this in their constructors.
22
+     * Any field not appearing in this will be viewed as metadata
23
+     */
24
+    protected $attributes = [];
25
+
26
+    /**
27
+     * Initialize the attributes array.
28
+     *
29
+     * This is vital to distinguish between metadata and base parameters.
30
+     *
31
+     * @return void
32
+     */
33
+    protected function initializeAttributes() {
34
+        // Create attributes array if not already created
35
+        if (!is_array($this->attributes)) {
36
+            $this->attributes = [];
37
+        }
38
+
39
+        $this->attributes['time_created'] = null;
40
+    }
41
+
42
+    /**
43
+     * Provides a pointer to the database object.
44
+     *
45
+     * @return \Elgg\Database The database where this data is (will be) stored.
46
+     */
47
+    protected function getDatabase() {
48
+        return _elgg_services()->db;
49
+    }
50
+
51
+    /**
52
+     * Test if property is set either as an attribute or metadata.
53
+     *
54
+     * @tip Use isset($entity->property)
55
+     *
56
+     * @param string $name The name of the attribute or metadata.
57
+     *
58
+     * @return bool
59
+     */
60
+    public function __isset($name) {
61
+        return $this->$name !== null;
62
+    }
63
+
64
+    /**
65
+     * Get a URL for this object
66
+     *
67
+     * @return string
68
+     */
69
+    abstract public function getURL();
70
+
71
+    /**
72
+     * Save this data to the appropriate database table.
73
+     *
74
+     * @return bool
75
+     */
76
+    abstract public function save();
77 77
 	
78
-	/**
79
-	 * Delete this data.
80
-	 *
81
-	 * @return bool
82
-	 */
83
-	abstract public function delete();
84
-
85
-	/**
86
-	 * Returns the UNIX epoch time that this entity was created
87
-	 *
88
-	 * @return int UNIX epoch time
89
-	 */
90
-	public function getTimeCreated() {
91
-		return $this->time_created;
92
-	}
93
-
94
-	/**
95
-	 * Get a plain old object copy for public consumption
96
-	 *
97
-	 * @return \stdClass
98
-	 */
99
-	abstract public function toObject();
100
-
101
-	/*
78
+    /**
79
+     * Delete this data.
80
+     *
81
+     * @return bool
82
+     */
83
+    abstract public function delete();
84
+
85
+    /**
86
+     * Returns the UNIX epoch time that this entity was created
87
+     *
88
+     * @return int UNIX epoch time
89
+     */
90
+    public function getTimeCreated() {
91
+        return $this->time_created;
92
+    }
93
+
94
+    /**
95
+     * Get a plain old object copy for public consumption
96
+     *
97
+     * @return \stdClass
98
+     */
99
+    abstract public function toObject();
100
+
101
+    /*
102 102
 	 * ITERATOR INTERFACE
103 103
 	 */
104 104
 
105
-	protected $valid = false;
106
-
107
-	/**
108
-	 * Iterator interface
109
-	 *
110
-	 * @see Iterator::rewind()
111
-	 *
112
-	 * @return void
113
-	 */
114
-	public function rewind() {
115
-		$this->valid = (false !== reset($this->attributes));
116
-	}
117
-
118
-	/**
119
-	 * Iterator interface
120
-	 *
121
-	 * @see Iterator::current()
122
-	 *
123
-	 * @return mixed
124
-	 */
125
-	public function current() {
126
-		return current($this->attributes);
127
-	}
128
-
129
-	/**
130
-	 * Iterator interface
131
-	 *
132
-	 * @see Iterator::key()
133
-	 *
134
-	 * @return string
135
-	 */
136
-	public function key() {
137
-		return key($this->attributes);
138
-	}
139
-
140
-	/**
141
-	 * Iterator interface
142
-	 *
143
-	 * @see Iterator::next()
144
-	 *
145
-	 * @return void
146
-	 */
147
-	public function next() {
148
-		$this->valid = (false !== next($this->attributes));
149
-	}
150
-
151
-	/**
152
-	 * Iterator interface
153
-	 *
154
-	 * @see Iterator::valid()
155
-	 *
156
-	 * @return bool
157
-	 */
158
-	public function valid() {
159
-		return $this->valid;
160
-	}
161
-
162
-	/*
105
+    protected $valid = false;
106
+
107
+    /**
108
+     * Iterator interface
109
+     *
110
+     * @see Iterator::rewind()
111
+     *
112
+     * @return void
113
+     */
114
+    public function rewind() {
115
+        $this->valid = (false !== reset($this->attributes));
116
+    }
117
+
118
+    /**
119
+     * Iterator interface
120
+     *
121
+     * @see Iterator::current()
122
+     *
123
+     * @return mixed
124
+     */
125
+    public function current() {
126
+        return current($this->attributes);
127
+    }
128
+
129
+    /**
130
+     * Iterator interface
131
+     *
132
+     * @see Iterator::key()
133
+     *
134
+     * @return string
135
+     */
136
+    public function key() {
137
+        return key($this->attributes);
138
+    }
139
+
140
+    /**
141
+     * Iterator interface
142
+     *
143
+     * @see Iterator::next()
144
+     *
145
+     * @return void
146
+     */
147
+    public function next() {
148
+        $this->valid = (false !== next($this->attributes));
149
+    }
150
+
151
+    /**
152
+     * Iterator interface
153
+     *
154
+     * @see Iterator::valid()
155
+     *
156
+     * @return bool
157
+     */
158
+    public function valid() {
159
+        return $this->valid;
160
+    }
161
+
162
+    /*
163 163
 	 * ARRAY ACCESS INTERFACE
164 164
 	 */
165 165
 
166
-	/**
167
-	 * Array access interface
168
-	 *
169
-	 * @see \ArrayAccess::offsetSet()
170
-	 *
171
-	 * @param mixed $key   Name
172
-	 * @param mixed $value Value
173
-	 *
174
-	 * @return void
175
-	 */
176
-	public function offsetSet($key, $value) {
177
-		if (array_key_exists($key, $this->attributes)) {
178
-			$this->attributes[$key] = $value;
179
-		}
180
-	}
181
-
182
-	/**
183
-	 * Array access interface
184
-	 *
185
-	 * @see \ArrayAccess::offsetGet()
186
-	 *
187
-	 * @param mixed $key Name
188
-	 *
189
-	 * @return mixed
190
-	 */
191
-	public function offsetGet($key) {
192
-		if (array_key_exists($key, $this->attributes)) {
193
-			return $this->attributes[$key];
194
-		}
195
-		return null;
196
-	}
197
-
198
-	/**
199
-	 * Array access interface
200
-	 *
201
-	 * @see \ArrayAccess::offsetUnset()
202
-	 *
203
-	 * @param mixed $key Name
204
-	 *
205
-	 * @return void
206
-	 */
207
-	public function offsetUnset($key) {
208
-		if (array_key_exists($key, $this->attributes)) {
209
-			// Full unsetting is dangerous for our objects
210
-			$this->attributes[$key] = "";
211
-		}
212
-	}
213
-
214
-	/**
215
-	 * Array access interface
216
-	 *
217
-	 * @see \ArrayAccess::offsetExists()
218
-	 *
219
-	 * @param int $offset Offset
220
-	 *
221
-	 * @return int
222
-	 */
223
-	public function offsetExists($offset) {
224
-		return array_key_exists($offset, $this->attributes);
225
-	}
166
+    /**
167
+     * Array access interface
168
+     *
169
+     * @see \ArrayAccess::offsetSet()
170
+     *
171
+     * @param mixed $key   Name
172
+     * @param mixed $value Value
173
+     *
174
+     * @return void
175
+     */
176
+    public function offsetSet($key, $value) {
177
+        if (array_key_exists($key, $this->attributes)) {
178
+            $this->attributes[$key] = $value;
179
+        }
180
+    }
181
+
182
+    /**
183
+     * Array access interface
184
+     *
185
+     * @see \ArrayAccess::offsetGet()
186
+     *
187
+     * @param mixed $key Name
188
+     *
189
+     * @return mixed
190
+     */
191
+    public function offsetGet($key) {
192
+        if (array_key_exists($key, $this->attributes)) {
193
+            return $this->attributes[$key];
194
+        }
195
+        return null;
196
+    }
197
+
198
+    /**
199
+     * Array access interface
200
+     *
201
+     * @see \ArrayAccess::offsetUnset()
202
+     *
203
+     * @param mixed $key Name
204
+     *
205
+     * @return void
206
+     */
207
+    public function offsetUnset($key) {
208
+        if (array_key_exists($key, $this->attributes)) {
209
+            // Full unsetting is dangerous for our objects
210
+            $this->attributes[$key] = "";
211
+        }
212
+    }
213
+
214
+    /**
215
+     * Array access interface
216
+     *
217
+     * @see \ArrayAccess::offsetExists()
218
+     *
219
+     * @param int $offset Offset
220
+     *
221
+     * @return int
222
+     */
223
+    public function offsetExists($offset) {
224
+        return array_key_exists($offset, $this->attributes);
225
+    }
226 226
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
  * @subpackage DataModel
8 8
  */
9 9
 abstract class ElggData implements
10
-	Loggable,    // Can events related to this object class be logged
11
-	Iterator,    // Override foreach behaviour
10
+	Loggable, // Can events related to this object class be logged
11
+	Iterator, // Override foreach behaviour
12 12
 	\ArrayAccess // Override for array access
13 13
 {
14 14
 
Please login to merge, or discard this patch.
engine/classes/ElggPluginManifest.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	/**
143 143
 	 * Load a manifest file, XmlElement or path to manifest.xml file
144 144
 	 *
145
-	 * @param mixed  $manifest  A string, XmlElement, or path of a manifest file.
145
+	 * @param string  $manifest  A string, XmlElement, or path of a manifest file.
146 146
 	 * @param string $plugin_id Optional ID of the owning plugin. Used to
147 147
 	 *                          fill in some values automatically.
148 148
 	 *
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 	/**
688 688
 	 * Should this plugin be activated when Elgg is installed
689 689
 	 *
690
-	 *  @return bool
690
+	 *  @return boolean|null
691 691
 	 */
692 692
 	public function getActivateOnInstall() {
693 693
 		$activate = $this->parser->getAttribute('activate_on_install');
Please login to merge, or discard this patch.
Indentation   +704 added lines, -704 removed lines patch added patch discarded remove patch
@@ -17,714 +17,714 @@
 block discarded – undo
17 17
  */
18 18
 class ElggPluginManifest {
19 19
 
20
-	/**
21
-	 * The parser object
22
-	 *
23
-	 * @var \ElggPluginManifestParser18
24
-	 */
25
-	protected $parser;
26
-
27
-	/**
28
-	 * The root for plugin manifest namespaces.
29
-	 * This is in the format http://www.elgg.org/plugin_manifest/<version>
30
-	 */
31
-	protected $namespace_root = 'http://www.elgg.org/plugin_manifest/';
32
-
33
-	/**
34
-	 * The expected structure of a plugins requires element
35
-	 */
36
-	private $depsStructPlugin = [
37
-		'type' => '',
38
-		'name' => '',
39
-		'version' => '',
40
-		'comparison' => 'ge'
41
-	];
42
-
43
-	/**
44
-	 * The expected structure of a priority element
45
-	 */
46
-	private $depsStructPriority = [
47
-		'type' => '',
48
-		'priority' => '',
49
-		'plugin' => ''
50
-	];
51
-
52
-	/*
20
+    /**
21
+     * The parser object
22
+     *
23
+     * @var \ElggPluginManifestParser18
24
+     */
25
+    protected $parser;
26
+
27
+    /**
28
+     * The root for plugin manifest namespaces.
29
+     * This is in the format http://www.elgg.org/plugin_manifest/<version>
30
+     */
31
+    protected $namespace_root = 'http://www.elgg.org/plugin_manifest/';
32
+
33
+    /**
34
+     * The expected structure of a plugins requires element
35
+     */
36
+    private $depsStructPlugin = [
37
+        'type' => '',
38
+        'name' => '',
39
+        'version' => '',
40
+        'comparison' => 'ge'
41
+    ];
42
+
43
+    /**
44
+     * The expected structure of a priority element
45
+     */
46
+    private $depsStructPriority = [
47
+        'type' => '',
48
+        'priority' => '',
49
+        'plugin' => ''
50
+    ];
51
+
52
+    /*
53 53
 	 * The expected structure of elgg_release requires element
54 54
 	 */
55
-	private $depsStructElgg = [
56
-		'type' => '',
57
-		'version' => '',
58
-		'comparison' => 'ge'
59
-	];
60
-
61
-	/**
62
-	 * The expected structure of a requires php_version dependency element
63
-	 */
64
-	private $depsStructPhpVersion = [
65
-		'type' => '',
66
-		'version' => '',
67
-		'comparison' => 'ge'
68
-	];
69
-
70
-	/**
71
-	 * The expected structure of a requires php_ini dependency element
72
-	 */
73
-	private $depsStructPhpIni = [
74
-		'type' => '',
75
-		'name' => '',
76
-		'value' => '',
77
-		'comparison' => '='
78
-	];
79
-
80
-	/**
81
-	 * The expected structure of a requires php_extension dependency element
82
-	 */
83
-	private $depsStructPhpExtension = [
84
-		'type' => '',
85
-		'name' => '',
86
-		'version' => '',
87
-		'comparison' => '='
88
-	];
89
-
90
-	/**
91
-	 * The expected structure of a conflicts depedency element
92
-	 */
93
-	private $depsConflictsStruct = [
94
-		'type' => '',
95
-		'name' => '',
96
-		'version' => '',
97
-		'comparison' => '='
98
-	];
99
-
100
-	/**
101
-	 * The expected structure of a provides dependency element.
102
-	 */
103
-	private $depsProvidesStruct = [
104
-		'type' => '',
105
-		'name' => '',
106
-		'version' => ''
107
-	];
108
-
109
-	/**
110
-	 * The expected structure of a screenshot element
111
-	 */
112
-	private $screenshotStruct = [
113
-		'description' => '',
114
-		'path' => ''
115
-	];
116
-
117
-	/**
118
-	 * The expected structure of a contributor element
119
-	 */
120
-	private $contributorStruct = [
121
-		'name' => '',
122
-		'email' => '',
123
-		'website' => '',
124
-		'username' => '',
125
-		'description' => '',
126
-	];
127
-
128
-	/**
129
-	 * The API version of the manifest.
130
-	 *
131
-	 * @var int
132
-	 */
133
-	protected $apiVersion;
134
-
135
-	/**
136
-	 * The optional plugin id this manifest belongs to.
137
-	 *
138
-	 * @var string
139
-	 */
140
-	protected $pluginID;
141
-
142
-	/**
143
-	 * Load a manifest file, XmlElement or path to manifest.xml file
144
-	 *
145
-	 * @param mixed  $manifest  A string, XmlElement, or path of a manifest file.
146
-	 * @param string $plugin_id Optional ID of the owning plugin. Used to
147
-	 *                          fill in some values automatically.
148
-	 *
149
-	 * @throws PluginException
150
-	 */
151
-	public function __construct($manifest, $plugin_id = null) {
152
-		if ($plugin_id) {
153
-			$this->pluginID = $plugin_id;
154
-		}
155
-
156
-		// see if we need to construct the xml object.
157
-		if ($manifest instanceof \ElggXMLElement) {
158
-			$manifest_obj = $manifest;
159
-		} else {
160
-			$raw_xml = '';
161
-			if (substr(trim($manifest), 0, 1) == '<') {
162
-				// this is a string
163
-				$raw_xml = $manifest;
164
-			} elseif (is_file($manifest)) {
165
-				// this is a file
166
-				$raw_xml = file_get_contents($manifest);
167
-			}
168
-			if ($raw_xml) {
169
-				$manifest_obj = new \ElggXMLElement($raw_xml);
170
-			} else {
171
-				$manifest_obj = null;
172
-			}
173
-		}
174
-
175
-		if (!$manifest_obj) {
176
-			throw new \PluginException(_elgg_services()->translator->translate('PluginException:InvalidManifest',
177
-						[$this->getPluginID()]));
178
-		}
179
-
180
-		// set manifest api version
181
-		if (isset($manifest_obj->attributes['xmlns'])) {
182
-			$namespace = $manifest_obj->attributes['xmlns'];
183
-			$version = str_replace($this->namespace_root, '', $namespace);
184
-		} else {
185
-			$version = 1.7;
186
-		}
187
-
188
-		$this->apiVersion = $version;
189
-
190
-		$parser_class_name = '\ElggPluginManifestParser' . str_replace('.', '', $this->apiVersion);
191
-
192
-		// @todo currently the autoloader freaks out if a class doesn't exist.
193
-		try {
194
-			$class_exists = class_exists($parser_class_name);
195
-		} catch (Exception $e) {
196
-			$class_exists = false;
197
-		}
198
-
199
-		if ($class_exists) {
200
-			$this->parser = new $parser_class_name($manifest_obj, $this);
201
-		} else {
202
-			throw new \PluginException(_elgg_services()->translator->translate('PluginException:NoAvailableParser',
203
-							[$this->apiVersion, $this->getPluginID()]));
204
-		}
205
-
206
-		if (!$this->parser->parse()) {
207
-			throw new \PluginException(_elgg_services()->translator->translate('PluginException:ParserError',
208
-						[$this->apiVersion, $this->getPluginID()]));
209
-		}
210
-	}
211
-
212
-	/**
213
-	 * Returns the API version in use.
214
-	 *
215
-	 * @return int
216
-	 */
217
-	public function getApiVersion() {
218
-		return $this->apiVersion;
219
-	}
220
-
221
-	/**
222
-	 * Returns the plugin ID.
223
-	 *
224
-	 * @return string
225
-	 */
226
-	public function getPluginID() {
227
-		if ($this->pluginID) {
228
-			return $this->pluginID;
229
-		} else {
230
-			return _elgg_services()->translator->translate('unknown');
231
-		}
232
-	}
233
-
234
-	/**
235
-	 * Returns the manifest array.
236
-	 *
237
-	 * Used for backward compatibility.  Specific
238
-	 * methods should be called instead.
239
-	 *
240
-	 * @return array
241
-	 */
242
-	public function getManifest() {
243
-		return $this->parser->getManifest();
244
-	}
245
-
246
-	/***************************************
55
+    private $depsStructElgg = [
56
+        'type' => '',
57
+        'version' => '',
58
+        'comparison' => 'ge'
59
+    ];
60
+
61
+    /**
62
+     * The expected structure of a requires php_version dependency element
63
+     */
64
+    private $depsStructPhpVersion = [
65
+        'type' => '',
66
+        'version' => '',
67
+        'comparison' => 'ge'
68
+    ];
69
+
70
+    /**
71
+     * The expected structure of a requires php_ini dependency element
72
+     */
73
+    private $depsStructPhpIni = [
74
+        'type' => '',
75
+        'name' => '',
76
+        'value' => '',
77
+        'comparison' => '='
78
+    ];
79
+
80
+    /**
81
+     * The expected structure of a requires php_extension dependency element
82
+     */
83
+    private $depsStructPhpExtension = [
84
+        'type' => '',
85
+        'name' => '',
86
+        'version' => '',
87
+        'comparison' => '='
88
+    ];
89
+
90
+    /**
91
+     * The expected structure of a conflicts depedency element
92
+     */
93
+    private $depsConflictsStruct = [
94
+        'type' => '',
95
+        'name' => '',
96
+        'version' => '',
97
+        'comparison' => '='
98
+    ];
99
+
100
+    /**
101
+     * The expected structure of a provides dependency element.
102
+     */
103
+    private $depsProvidesStruct = [
104
+        'type' => '',
105
+        'name' => '',
106
+        'version' => ''
107
+    ];
108
+
109
+    /**
110
+     * The expected structure of a screenshot element
111
+     */
112
+    private $screenshotStruct = [
113
+        'description' => '',
114
+        'path' => ''
115
+    ];
116
+
117
+    /**
118
+     * The expected structure of a contributor element
119
+     */
120
+    private $contributorStruct = [
121
+        'name' => '',
122
+        'email' => '',
123
+        'website' => '',
124
+        'username' => '',
125
+        'description' => '',
126
+    ];
127
+
128
+    /**
129
+     * The API version of the manifest.
130
+     *
131
+     * @var int
132
+     */
133
+    protected $apiVersion;
134
+
135
+    /**
136
+     * The optional plugin id this manifest belongs to.
137
+     *
138
+     * @var string
139
+     */
140
+    protected $pluginID;
141
+
142
+    /**
143
+     * Load a manifest file, XmlElement or path to manifest.xml file
144
+     *
145
+     * @param mixed  $manifest  A string, XmlElement, or path of a manifest file.
146
+     * @param string $plugin_id Optional ID of the owning plugin. Used to
147
+     *                          fill in some values automatically.
148
+     *
149
+     * @throws PluginException
150
+     */
151
+    public function __construct($manifest, $plugin_id = null) {
152
+        if ($plugin_id) {
153
+            $this->pluginID = $plugin_id;
154
+        }
155
+
156
+        // see if we need to construct the xml object.
157
+        if ($manifest instanceof \ElggXMLElement) {
158
+            $manifest_obj = $manifest;
159
+        } else {
160
+            $raw_xml = '';
161
+            if (substr(trim($manifest), 0, 1) == '<') {
162
+                // this is a string
163
+                $raw_xml = $manifest;
164
+            } elseif (is_file($manifest)) {
165
+                // this is a file
166
+                $raw_xml = file_get_contents($manifest);
167
+            }
168
+            if ($raw_xml) {
169
+                $manifest_obj = new \ElggXMLElement($raw_xml);
170
+            } else {
171
+                $manifest_obj = null;
172
+            }
173
+        }
174
+
175
+        if (!$manifest_obj) {
176
+            throw new \PluginException(_elgg_services()->translator->translate('PluginException:InvalidManifest',
177
+                        [$this->getPluginID()]));
178
+        }
179
+
180
+        // set manifest api version
181
+        if (isset($manifest_obj->attributes['xmlns'])) {
182
+            $namespace = $manifest_obj->attributes['xmlns'];
183
+            $version = str_replace($this->namespace_root, '', $namespace);
184
+        } else {
185
+            $version = 1.7;
186
+        }
187
+
188
+        $this->apiVersion = $version;
189
+
190
+        $parser_class_name = '\ElggPluginManifestParser' . str_replace('.', '', $this->apiVersion);
191
+
192
+        // @todo currently the autoloader freaks out if a class doesn't exist.
193
+        try {
194
+            $class_exists = class_exists($parser_class_name);
195
+        } catch (Exception $e) {
196
+            $class_exists = false;
197
+        }
198
+
199
+        if ($class_exists) {
200
+            $this->parser = new $parser_class_name($manifest_obj, $this);
201
+        } else {
202
+            throw new \PluginException(_elgg_services()->translator->translate('PluginException:NoAvailableParser',
203
+                            [$this->apiVersion, $this->getPluginID()]));
204
+        }
205
+
206
+        if (!$this->parser->parse()) {
207
+            throw new \PluginException(_elgg_services()->translator->translate('PluginException:ParserError',
208
+                        [$this->apiVersion, $this->getPluginID()]));
209
+        }
210
+    }
211
+
212
+    /**
213
+     * Returns the API version in use.
214
+     *
215
+     * @return int
216
+     */
217
+    public function getApiVersion() {
218
+        return $this->apiVersion;
219
+    }
220
+
221
+    /**
222
+     * Returns the plugin ID.
223
+     *
224
+     * @return string
225
+     */
226
+    public function getPluginID() {
227
+        if ($this->pluginID) {
228
+            return $this->pluginID;
229
+        } else {
230
+            return _elgg_services()->translator->translate('unknown');
231
+        }
232
+    }
233
+
234
+    /**
235
+     * Returns the manifest array.
236
+     *
237
+     * Used for backward compatibility.  Specific
238
+     * methods should be called instead.
239
+     *
240
+     * @return array
241
+     */
242
+    public function getManifest() {
243
+        return $this->parser->getManifest();
244
+    }
245
+
246
+    /***************************************
247 247
 	 * Parsed and Normalized Manifest Data *
248 248
 	 ***************************************/
249 249
 
250
-	/**
251
-	 * Returns the plugin name
252
-	 *
253
-	 * @return string
254
-	 */
255
-	public function getName() {
256
-		$name = $this->parser->getAttribute('name');
257
-
258
-		if (!$name && $this->pluginID) {
259
-			$name = ucwords(str_replace('_', ' ', $this->pluginID));
260
-		}
261
-
262
-		return $name;
263
-	}
264
-
265
-	/**
266
-	 * Return the plugin ID required by the author. If getPluginID() does
267
-	 * not match this, the plugin should not be started.
268
-	 *
269
-	 * @return string empty string if not empty/not defined
270
-	 */
271
-	public function getID() {
272
-		return trim((string) $this->parser->getAttribute('id'));
273
-	}
274
-
275
-
276
-	/**
277
-	 * Return the description
278
-	 *
279
-	 * @return string
280
-	 */
281
-	public function getDescription() {
282
-		return $this->parser->getAttribute('description');
283
-	}
284
-
285
-	/**
286
-	 * Return the short description
287
-	 *
288
-	 * @return string
289
-	 */
290
-	public function getBlurb() {
291
-		$blurb = $this->parser->getAttribute('blurb');
292
-
293
-		if (!$blurb) {
294
-			$blurb = elgg_get_excerpt($this->getDescription());
295
-		}
296
-
297
-		return $blurb;
298
-	}
299
-
300
-	/**
301
-	 * Returns the license
302
-	 *
303
-	 * @return string
304
-	 */
305
-	public function getLicense() {
306
-		// license vs licence.  Use license.
307
-		$en_us = $this->parser->getAttribute('license');
308
-		if ($en_us) {
309
-			return $en_us;
310
-		} else {
311
-			return $this->parser->getAttribute('licence');
312
-		}
313
-	}
314
-
315
-	/**
316
-	 * Returns the repository url
317
-	 *
318
-	 * @return string
319
-	 */
320
-	public function getRepositoryURL() {
321
-		return $this->parser->getAttribute('repository');
322
-	}
323
-
324
-	/**
325
-	 * Returns the bug tracker page
326
-	 *
327
-	 * @return string
328
-	 */
329
-	public function getBugTrackerURL() {
330
-		return $this->parser->getAttribute('bugtracker');
331
-	}
332
-
333
-	/**
334
-	 * Returns the donations page
335
-	 *
336
-	 * @return string
337
-	 */
338
-	public function getDonationsPageURL() {
339
-		return $this->parser->getAttribute('donations');
340
-	}
341
-
342
-	/**
343
-	 * Returns the version of the plugin.
344
-	 *
345
-	 * @return float
346
-	 */
347
-	public function getVersion() {
348
-		return $this->parser->getAttribute('version');
349
-	}
350
-
351
-	/**
352
-	 * Returns the plugin author.
353
-	 *
354
-	 * @return string
355
-	 */
356
-	public function getAuthor() {
357
-		return $this->parser->getAttribute('author');
358
-	}
359
-
360
-	/**
361
-	 * Return the copyright
362
-	 *
363
-	 * @return string
364
-	 */
365
-	public function getCopyright() {
366
-		return $this->parser->getAttribute('copyright');
367
-	}
368
-
369
-	/**
370
-	 * Return the website
371
-	 *
372
-	 * @return string
373
-	 */
374
-	public function getWebsite() {
375
-		return $this->parser->getAttribute('website');
376
-	}
377
-
378
-	/**
379
-	 * Return the categories listed for this plugin
380
-	 *
381
-	 * @return array
382
-	 */
383
-	public function getCategories() {
384
-		$bundled_plugins = [
385
-			'activity',
386
-			'blog',
387
-			'bookmarks',
388
-			'ckeditor',
389
-			'custom_index',
390
-			'dashboard',
391
-			'developers',
392
-			'diagnostics',
393
-			'discussions',
394
-			'embed',
395
-			'externalpages',
396
-			'file',
397
-			'friends',
398
-			'friends_collections',
399
-			'garbagecollector',
400
-			'groups',
401
-			'htmlawed',
402
-			'invitefriends',
403
-			'legacy_urls',
404
-			'likes',
405
-			'logbrowser',
406
-			'login_as',
407
-			'logrotate',
408
-			'members',
409
-			'messageboard',
410
-			'messages',
411
-			'notifications',
412
-			'pages',
413
-			'profile',
414
-			'reportedcontent',
415
-			'search',
416
-			'site_notifications',
417
-			'tagcloud',
418
-			'thewire',
419
-			'twitter_api',
420
-			'uservalidationbyemail',
421
-			'web_services',
422
-		];
423
-
424
-		$cats = $this->parser->getAttribute('category');
425
-
426
-		if (!$cats) {
427
-			$cats = [];
428
-		}
429
-
430
-		if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) {
431
-			unset($cats[array_search('bundled', $cats)]);
432
-		}
433
-
434
-		return $cats;
435
-	}
436
-
437
-	/**
438
-	 * Return the screenshots listed.
439
-	 *
440
-	 * @return array
441
-	 */
442
-	public function getScreenshots() {
443
-		$ss = $this->parser->getAttribute('screenshot');
444
-
445
-		if (!$ss) {
446
-			$ss = [];
447
-		}
448
-
449
-		$normalized = [];
450
-		foreach ($ss as $s) {
451
-			$normalized[] = $this->buildStruct($this->screenshotStruct, $s);
452
-		}
453
-
454
-		return $normalized;
455
-	}
456
-
457
-	/**
458
-	 * Return the contributors listed.
459
-	 *
460
-	 * @return array
461
-	 */
462
-	public function getContributors() {
463
-		$ss = $this->parser->getAttribute('contributor');
464
-
465
-		if (!$ss) {
466
-			$ss = [];
467
-		}
468
-
469
-		$normalized = [];
470
-		foreach ($ss as $s) {
471
-			$normalized[] = $this->buildStruct($this->contributorStruct, $s);
472
-		}
473
-
474
-		return $normalized;
475
-	}
476
-
477
-	/**
478
-	 * Return the list of provides by this plugin.
479
-	 *
480
-	 * @return array
481
-	 */
482
-	public function getProvides() {
483
-		// normalize for 1.7
484
-		if ($this->getApiVersion() < 1.8) {
485
-			$provides = [];
486
-		} else {
487
-			$provides = $this->parser->getAttribute('provides');
488
-		}
489
-
490
-		if (!$provides) {
491
-			$provides = [];
492
-		}
493
-
494
-		// always provide ourself if we can
495
-		if ($this->pluginID) {
496
-			$provides[] = [
497
-				'type' => 'plugin',
498
-				'name' => $this->getPluginID(),
499
-				'version' => $this->getVersion()
500
-			];
501
-		}
502
-
503
-		$normalized = [];
504
-		foreach ($provides as $provide) {
505
-			$normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide);
506
-		}
507
-
508
-		return $normalized;
509
-	}
510
-
511
-	/**
512
-	 * Returns the dependencies listed.
513
-	 *
514
-	 * @return array
515
-	 */
516
-	public function getRequires() {
517
-		$reqs = $this->parser->getAttribute('requires');
518
-
519
-		if (!$reqs) {
520
-			$reqs = [];
521
-		}
522
-
523
-		$normalized = [];
524
-		foreach ($reqs as $req) {
525
-			$normalized[] = $this->normalizeDep($req);
526
-		}
527
-
528
-		return $normalized;
529
-	}
530
-
531
-	/**
532
-	 * Returns the suggests elements.
533
-	 *
534
-	 * @return array
535
-	 */
536
-	public function getSuggests() {
537
-		$suggests = $this->parser->getAttribute('suggests');
538
-
539
-		if (!$suggests) {
540
-			$suggests = [];
541
-		}
542
-
543
-		$normalized = [];
544
-		foreach ($suggests as $suggest) {
545
-			$normalized[] = $this->normalizeDep($suggest);
546
-		}
547
-
548
-		return $normalized;
549
-	}
550
-
551
-	/**
552
-	 * Normalizes a dependency array using the defined structs.
553
-	 * Can be used with either requires or suggests.
554
-	 *
555
-	 * @param array $dep A dependency array.
556
-	 * @return array The normalized deps array.
557
-	 */
558
-	private function normalizeDep($dep) {
559
-		switch ($dep['type']) {
560
-			case 'elgg_release':
561
-				$struct = $this->depsStructElgg;
562
-				break;
563
-
564
-			case 'plugin':
565
-				$struct = $this->depsStructPlugin;
566
-				break;
567
-
568
-			case 'priority':
569
-				$struct = $this->depsStructPriority;
570
-				break;
571
-
572
-			case 'php_version':
573
-				$struct = $this->depsStructPhpVersion;
574
-				break;
575
-
576
-			case 'php_extension':
577
-				$struct = $this->depsStructPhpExtension;
578
-				break;
579
-
580
-			case 'php_ini':
581
-				$struct = $this->depsStructPhpIni;
582
-
583
-				// also normalize boolean values
584
-				if (isset($dep['value'])) {
585
-					switch (strtolower($dep['value'])) {
586
-						case 'yes':
587
-						case 'true':
588
-						case 'on':
589
-						case 1:
590
-							$dep['value'] = 1;
591
-							break;
592
-
593
-						case 'no':
594
-						case 'false':
595
-						case 'off':
596
-						case 0:
597
-						case '':
598
-							$dep['value'] = 0;
599
-							break;
600
-					}
601
-				}
602
-				break;
603
-			default:
604
-				// unrecognized so we just return the raw dependency
605
-				return $dep;
606
-		}
607
-
608
-		// @todo $struct may not have been defined...
609
-		$normalized_dep = $this->buildStruct($struct, $dep);
610
-
611
-		// normalize comparison operators
612
-		if (isset($normalized_dep['comparison'])) {
613
-			switch ($normalized_dep['comparison']) {
614
-				case '<':
615
-					$normalized_dep['comparison'] = 'lt';
616
-					break;
617
-
618
-				case '<=':
619
-					$normalized_dep['comparison'] = 'le';
620
-					break;
621
-
622
-				case '>':
623
-					$normalized_dep['comparison'] = 'gt';
624
-					break;
625
-
626
-				case '>=':
627
-					$normalized_dep['comparison'] = 'ge';
628
-					break;
629
-
630
-				case '==':
631
-				case 'eq':
632
-					$normalized_dep['comparison'] = '=';
633
-					break;
634
-
635
-				case '<>':
636
-				case 'ne':
637
-					$normalized_dep['comparison'] = '!=';
638
-					break;
639
-			}
640
-		}
641
-
642
-		return $normalized_dep;
643
-	}
644
-
645
-	/**
646
-	 * Returns the conflicts listed
647
-	 *
648
-	 * @return array
649
-	 */
650
-	public function getConflicts() {
651
-		// normalize for 1.7
652
-		if ($this->getApiVersion() < 1.8) {
653
-			$conflicts = [];
654
-		} else {
655
-			$conflicts = $this->parser->getAttribute('conflicts');
656
-		}
657
-
658
-		if (!$conflicts) {
659
-			$conflicts = [];
660
-		}
661
-
662
-		$normalized = [];
663
-
664
-		foreach ($conflicts as $conflict) {
665
-			$normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict);
666
-		}
667
-
668
-		return $normalized;
669
-	}
670
-
671
-	/**
672
-	 * Should this plugin be activated when Elgg is installed
673
-	 *
674
-	 *  @return bool
675
-	 */
676
-	public function getActivateOnInstall() {
677
-		$activate = $this->parser->getAttribute('activate_on_install');
678
-		switch (strtolower($activate)) {
679
-			case 'yes':
680
-			case 'true':
681
-			case 'on':
682
-			case 1:
683
-				return true;
684
-
685
-			case 'no':
686
-			case 'false':
687
-			case 'off':
688
-			case 0:
689
-			case '':
690
-				return false;
691
-		}
692
-	}
693
-
694
-	/**
695
-	 * Normalizes an array into the structure specified
696
-	 *
697
-	 * @param array $struct The struct to normalize $element to.
698
-	 * @param array $array  The array
699
-	 *
700
-	 * @return array
701
-	 */
702
-	protected function buildStruct(array $struct, array $array) {
703
-		$return = [];
704
-
705
-		foreach ($struct as $index => $default) {
706
-			$return[$index] = elgg_extract($index, $array, $default);
707
-		}
708
-
709
-		return $return;
710
-	}
711
-
712
-	/**
713
-	 * Returns a category's friendly name. This can be localized by
714
-	 * defining the string 'admin:plugins:category:<category>'. If no
715
-	 * localization is found, returns the category with _ and - converted to ' '
716
-	 * and then ucwords()'d.
717
-	 *
718
-	 * @param string $category The category as defined in the manifest.
719
-	 * @return string A human-readable category
720
-	 */
721
-	static public function getFriendlyCategory($category) {
722
-		$cat_raw_string = "admin:plugins:category:$category";
723
-		if (_elgg_services()->translator->languageKeyExists($cat_raw_string)) {
724
-			return _elgg_services()->translator->translate($cat_raw_string);
725
-		}
250
+    /**
251
+     * Returns the plugin name
252
+     *
253
+     * @return string
254
+     */
255
+    public function getName() {
256
+        $name = $this->parser->getAttribute('name');
257
+
258
+        if (!$name && $this->pluginID) {
259
+            $name = ucwords(str_replace('_', ' ', $this->pluginID));
260
+        }
261
+
262
+        return $name;
263
+    }
264
+
265
+    /**
266
+     * Return the plugin ID required by the author. If getPluginID() does
267
+     * not match this, the plugin should not be started.
268
+     *
269
+     * @return string empty string if not empty/not defined
270
+     */
271
+    public function getID() {
272
+        return trim((string) $this->parser->getAttribute('id'));
273
+    }
274
+
275
+
276
+    /**
277
+     * Return the description
278
+     *
279
+     * @return string
280
+     */
281
+    public function getDescription() {
282
+        return $this->parser->getAttribute('description');
283
+    }
284
+
285
+    /**
286
+     * Return the short description
287
+     *
288
+     * @return string
289
+     */
290
+    public function getBlurb() {
291
+        $blurb = $this->parser->getAttribute('blurb');
292
+
293
+        if (!$blurb) {
294
+            $blurb = elgg_get_excerpt($this->getDescription());
295
+        }
296
+
297
+        return $blurb;
298
+    }
299
+
300
+    /**
301
+     * Returns the license
302
+     *
303
+     * @return string
304
+     */
305
+    public function getLicense() {
306
+        // license vs licence.  Use license.
307
+        $en_us = $this->parser->getAttribute('license');
308
+        if ($en_us) {
309
+            return $en_us;
310
+        } else {
311
+            return $this->parser->getAttribute('licence');
312
+        }
313
+    }
314
+
315
+    /**
316
+     * Returns the repository url
317
+     *
318
+     * @return string
319
+     */
320
+    public function getRepositoryURL() {
321
+        return $this->parser->getAttribute('repository');
322
+    }
323
+
324
+    /**
325
+     * Returns the bug tracker page
326
+     *
327
+     * @return string
328
+     */
329
+    public function getBugTrackerURL() {
330
+        return $this->parser->getAttribute('bugtracker');
331
+    }
332
+
333
+    /**
334
+     * Returns the donations page
335
+     *
336
+     * @return string
337
+     */
338
+    public function getDonationsPageURL() {
339
+        return $this->parser->getAttribute('donations');
340
+    }
341
+
342
+    /**
343
+     * Returns the version of the plugin.
344
+     *
345
+     * @return float
346
+     */
347
+    public function getVersion() {
348
+        return $this->parser->getAttribute('version');
349
+    }
350
+
351
+    /**
352
+     * Returns the plugin author.
353
+     *
354
+     * @return string
355
+     */
356
+    public function getAuthor() {
357
+        return $this->parser->getAttribute('author');
358
+    }
359
+
360
+    /**
361
+     * Return the copyright
362
+     *
363
+     * @return string
364
+     */
365
+    public function getCopyright() {
366
+        return $this->parser->getAttribute('copyright');
367
+    }
368
+
369
+    /**
370
+     * Return the website
371
+     *
372
+     * @return string
373
+     */
374
+    public function getWebsite() {
375
+        return $this->parser->getAttribute('website');
376
+    }
377
+
378
+    /**
379
+     * Return the categories listed for this plugin
380
+     *
381
+     * @return array
382
+     */
383
+    public function getCategories() {
384
+        $bundled_plugins = [
385
+            'activity',
386
+            'blog',
387
+            'bookmarks',
388
+            'ckeditor',
389
+            'custom_index',
390
+            'dashboard',
391
+            'developers',
392
+            'diagnostics',
393
+            'discussions',
394
+            'embed',
395
+            'externalpages',
396
+            'file',
397
+            'friends',
398
+            'friends_collections',
399
+            'garbagecollector',
400
+            'groups',
401
+            'htmlawed',
402
+            'invitefriends',
403
+            'legacy_urls',
404
+            'likes',
405
+            'logbrowser',
406
+            'login_as',
407
+            'logrotate',
408
+            'members',
409
+            'messageboard',
410
+            'messages',
411
+            'notifications',
412
+            'pages',
413
+            'profile',
414
+            'reportedcontent',
415
+            'search',
416
+            'site_notifications',
417
+            'tagcloud',
418
+            'thewire',
419
+            'twitter_api',
420
+            'uservalidationbyemail',
421
+            'web_services',
422
+        ];
423
+
424
+        $cats = $this->parser->getAttribute('category');
425
+
426
+        if (!$cats) {
427
+            $cats = [];
428
+        }
429
+
430
+        if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) {
431
+            unset($cats[array_search('bundled', $cats)]);
432
+        }
433
+
434
+        return $cats;
435
+    }
436
+
437
+    /**
438
+     * Return the screenshots listed.
439
+     *
440
+     * @return array
441
+     */
442
+    public function getScreenshots() {
443
+        $ss = $this->parser->getAttribute('screenshot');
444
+
445
+        if (!$ss) {
446
+            $ss = [];
447
+        }
448
+
449
+        $normalized = [];
450
+        foreach ($ss as $s) {
451
+            $normalized[] = $this->buildStruct($this->screenshotStruct, $s);
452
+        }
453
+
454
+        return $normalized;
455
+    }
456
+
457
+    /**
458
+     * Return the contributors listed.
459
+     *
460
+     * @return array
461
+     */
462
+    public function getContributors() {
463
+        $ss = $this->parser->getAttribute('contributor');
464
+
465
+        if (!$ss) {
466
+            $ss = [];
467
+        }
468
+
469
+        $normalized = [];
470
+        foreach ($ss as $s) {
471
+            $normalized[] = $this->buildStruct($this->contributorStruct, $s);
472
+        }
473
+
474
+        return $normalized;
475
+    }
476
+
477
+    /**
478
+     * Return the list of provides by this plugin.
479
+     *
480
+     * @return array
481
+     */
482
+    public function getProvides() {
483
+        // normalize for 1.7
484
+        if ($this->getApiVersion() < 1.8) {
485
+            $provides = [];
486
+        } else {
487
+            $provides = $this->parser->getAttribute('provides');
488
+        }
489
+
490
+        if (!$provides) {
491
+            $provides = [];
492
+        }
493
+
494
+        // always provide ourself if we can
495
+        if ($this->pluginID) {
496
+            $provides[] = [
497
+                'type' => 'plugin',
498
+                'name' => $this->getPluginID(),
499
+                'version' => $this->getVersion()
500
+            ];
501
+        }
502
+
503
+        $normalized = [];
504
+        foreach ($provides as $provide) {
505
+            $normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide);
506
+        }
507
+
508
+        return $normalized;
509
+    }
510
+
511
+    /**
512
+     * Returns the dependencies listed.
513
+     *
514
+     * @return array
515
+     */
516
+    public function getRequires() {
517
+        $reqs = $this->parser->getAttribute('requires');
518
+
519
+        if (!$reqs) {
520
+            $reqs = [];
521
+        }
522
+
523
+        $normalized = [];
524
+        foreach ($reqs as $req) {
525
+            $normalized[] = $this->normalizeDep($req);
526
+        }
527
+
528
+        return $normalized;
529
+    }
530
+
531
+    /**
532
+     * Returns the suggests elements.
533
+     *
534
+     * @return array
535
+     */
536
+    public function getSuggests() {
537
+        $suggests = $this->parser->getAttribute('suggests');
538
+
539
+        if (!$suggests) {
540
+            $suggests = [];
541
+        }
542
+
543
+        $normalized = [];
544
+        foreach ($suggests as $suggest) {
545
+            $normalized[] = $this->normalizeDep($suggest);
546
+        }
547
+
548
+        return $normalized;
549
+    }
550
+
551
+    /**
552
+     * Normalizes a dependency array using the defined structs.
553
+     * Can be used with either requires or suggests.
554
+     *
555
+     * @param array $dep A dependency array.
556
+     * @return array The normalized deps array.
557
+     */
558
+    private function normalizeDep($dep) {
559
+        switch ($dep['type']) {
560
+            case 'elgg_release':
561
+                $struct = $this->depsStructElgg;
562
+                break;
563
+
564
+            case 'plugin':
565
+                $struct = $this->depsStructPlugin;
566
+                break;
567
+
568
+            case 'priority':
569
+                $struct = $this->depsStructPriority;
570
+                break;
571
+
572
+            case 'php_version':
573
+                $struct = $this->depsStructPhpVersion;
574
+                break;
575
+
576
+            case 'php_extension':
577
+                $struct = $this->depsStructPhpExtension;
578
+                break;
579
+
580
+            case 'php_ini':
581
+                $struct = $this->depsStructPhpIni;
582
+
583
+                // also normalize boolean values
584
+                if (isset($dep['value'])) {
585
+                    switch (strtolower($dep['value'])) {
586
+                        case 'yes':
587
+                        case 'true':
588
+                        case 'on':
589
+                        case 1:
590
+                            $dep['value'] = 1;
591
+                            break;
592
+
593
+                        case 'no':
594
+                        case 'false':
595
+                        case 'off':
596
+                        case 0:
597
+                        case '':
598
+                            $dep['value'] = 0;
599
+                            break;
600
+                    }
601
+                }
602
+                break;
603
+            default:
604
+                // unrecognized so we just return the raw dependency
605
+                return $dep;
606
+        }
607
+
608
+        // @todo $struct may not have been defined...
609
+        $normalized_dep = $this->buildStruct($struct, $dep);
610
+
611
+        // normalize comparison operators
612
+        if (isset($normalized_dep['comparison'])) {
613
+            switch ($normalized_dep['comparison']) {
614
+                case '<':
615
+                    $normalized_dep['comparison'] = 'lt';
616
+                    break;
617
+
618
+                case '<=':
619
+                    $normalized_dep['comparison'] = 'le';
620
+                    break;
621
+
622
+                case '>':
623
+                    $normalized_dep['comparison'] = 'gt';
624
+                    break;
625
+
626
+                case '>=':
627
+                    $normalized_dep['comparison'] = 'ge';
628
+                    break;
629
+
630
+                case '==':
631
+                case 'eq':
632
+                    $normalized_dep['comparison'] = '=';
633
+                    break;
634
+
635
+                case '<>':
636
+                case 'ne':
637
+                    $normalized_dep['comparison'] = '!=';
638
+                    break;
639
+            }
640
+        }
641
+
642
+        return $normalized_dep;
643
+    }
644
+
645
+    /**
646
+     * Returns the conflicts listed
647
+     *
648
+     * @return array
649
+     */
650
+    public function getConflicts() {
651
+        // normalize for 1.7
652
+        if ($this->getApiVersion() < 1.8) {
653
+            $conflicts = [];
654
+        } else {
655
+            $conflicts = $this->parser->getAttribute('conflicts');
656
+        }
657
+
658
+        if (!$conflicts) {
659
+            $conflicts = [];
660
+        }
661
+
662
+        $normalized = [];
663
+
664
+        foreach ($conflicts as $conflict) {
665
+            $normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict);
666
+        }
667
+
668
+        return $normalized;
669
+    }
670
+
671
+    /**
672
+     * Should this plugin be activated when Elgg is installed
673
+     *
674
+     *  @return bool
675
+     */
676
+    public function getActivateOnInstall() {
677
+        $activate = $this->parser->getAttribute('activate_on_install');
678
+        switch (strtolower($activate)) {
679
+            case 'yes':
680
+            case 'true':
681
+            case 'on':
682
+            case 1:
683
+                return true;
684
+
685
+            case 'no':
686
+            case 'false':
687
+            case 'off':
688
+            case 0:
689
+            case '':
690
+                return false;
691
+        }
692
+    }
693
+
694
+    /**
695
+     * Normalizes an array into the structure specified
696
+     *
697
+     * @param array $struct The struct to normalize $element to.
698
+     * @param array $array  The array
699
+     *
700
+     * @return array
701
+     */
702
+    protected function buildStruct(array $struct, array $array) {
703
+        $return = [];
704
+
705
+        foreach ($struct as $index => $default) {
706
+            $return[$index] = elgg_extract($index, $array, $default);
707
+        }
708
+
709
+        return $return;
710
+    }
711
+
712
+    /**
713
+     * Returns a category's friendly name. This can be localized by
714
+     * defining the string 'admin:plugins:category:<category>'. If no
715
+     * localization is found, returns the category with _ and - converted to ' '
716
+     * and then ucwords()'d.
717
+     *
718
+     * @param string $category The category as defined in the manifest.
719
+     * @return string A human-readable category
720
+     */
721
+    static public function getFriendlyCategory($category) {
722
+        $cat_raw_string = "admin:plugins:category:$category";
723
+        if (_elgg_services()->translator->languageKeyExists($cat_raw_string)) {
724
+            return _elgg_services()->translator->translate($cat_raw_string);
725
+        }
726 726
 		
727
-		$category = str_replace(['-', '_'], ' ', $category);
728
-		return ucwords($category);
729
-	}
727
+        $category = str_replace(['-', '_'], ' ', $category);
728
+        return ucwords($category);
729
+    }
730 730
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -187,7 +187,7 @@
 block discarded – undo
187 187
 
188 188
 		$this->apiVersion = $version;
189 189
 
190
-		$parser_class_name = '\ElggPluginManifestParser' . str_replace('.', '', $this->apiVersion);
190
+		$parser_class_name = '\ElggPluginManifestParser'.str_replace('.', '', $this->apiVersion);
191 191
 
192 192
 		// @todo currently the autoloader freaks out if a class doesn't exist.
193 193
 		try {
Please login to merge, or discard this patch.
engine/classes/ElggPriorityList.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	/**
232 232
 	 * Sort the elements if they haven't been sorted yet.
233 233
 	 *
234
-	 * @return bool
234
+	 * @return boolean|null
235 235
 	 */
236 236
 	private function sortIfUnsorted() {
237 237
 		if (!$this->sorted) {
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @param mixed $element The element to check for.
264 264
 	 * @param bool  $strict  Use strict checking?
265
-	 * @return mixed False if the element doesn't exists, the priority if it does.
265
+	 * @return integer False if the element doesn't exists, the priority if it does.
266 266
 	 */
267 267
 	public function getPriority($element, $strict = false) {
268 268
 		return array_search($element, $this->elements, $strict);
Please login to merge, or discard this patch.
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -93,274 +93,274 @@
 block discarded – undo
93 93
  * @subpackage Helpers
94 94
  */
95 95
 class ElggPriorityList
96
-	implements \Iterator, \Countable {
96
+    implements \Iterator, \Countable {
97 97
 
98
-	/**
99
-	 * The list of elements
100
-	 *
101
-	 * @var array
102
-	 */
103
-	private $elements = [];
98
+    /**
99
+     * The list of elements
100
+     *
101
+     * @var array
102
+     */
103
+    private $elements = [];
104 104
 
105
-	/**
106
-	 * Create a new priority list.
107
-	 *
108
-	 * @param array $elements An optional array of priorities => element
109
-	 */
110
-	public function __construct(array $elements = []) {
111
-		if ($elements) {
112
-			foreach ($elements as $priority => $element) {
113
-				$this->add($element, $priority);
114
-			}
115
-		}
116
-	}
105
+    /**
106
+     * Create a new priority list.
107
+     *
108
+     * @param array $elements An optional array of priorities => element
109
+     */
110
+    public function __construct(array $elements = []) {
111
+        if ($elements) {
112
+            foreach ($elements as $priority => $element) {
113
+                $this->add($element, $priority);
114
+            }
115
+        }
116
+    }
117 117
 
118
-	/**
119
-	 * Adds an element to the list.
120
-	 *
121
-	 * @warning This returns the priority at which the element was added, which can be 0. Use
122
-	 *          !== false to check for success.
123
-	 *
124
-	 * @param mixed $element  The element to add to the list.
125
-	 * @param mixed $priority Priority to add the element. In priority collisions, the original element
126
-	 *                        maintains its priority and the new element is to the next available
127
-	 *                        slot, taking into consideration all previously registered elements.
128
-	 *                        Negative elements are accepted.
129
-	 * @param bool  $exact    unused
130
-	 * @return int            The priority of the added element.
131
-	 * @todo remove $exact or implement it. Note we use variable name strict below.
132
-	 */
133
-	public function add($element, $priority = null, $exact = false) {
134
-		if ($priority !== null && !is_numeric($priority)) {
135
-			return false;
136
-		} else {
137
-			$priority = $this->getNextPriority($priority);
138
-		}
118
+    /**
119
+     * Adds an element to the list.
120
+     *
121
+     * @warning This returns the priority at which the element was added, which can be 0. Use
122
+     *          !== false to check for success.
123
+     *
124
+     * @param mixed $element  The element to add to the list.
125
+     * @param mixed $priority Priority to add the element. In priority collisions, the original element
126
+     *                        maintains its priority and the new element is to the next available
127
+     *                        slot, taking into consideration all previously registered elements.
128
+     *                        Negative elements are accepted.
129
+     * @param bool  $exact    unused
130
+     * @return int            The priority of the added element.
131
+     * @todo remove $exact or implement it. Note we use variable name strict below.
132
+     */
133
+    public function add($element, $priority = null, $exact = false) {
134
+        if ($priority !== null && !is_numeric($priority)) {
135
+            return false;
136
+        } else {
137
+            $priority = $this->getNextPriority($priority);
138
+        }
139 139
 
140
-		$this->elements[$priority] = $element;
141
-		$this->sorted = false;
142
-		return $priority;
143
-	}
140
+        $this->elements[$priority] = $element;
141
+        $this->sorted = false;
142
+        return $priority;
143
+    }
144 144
 
145
-	/**
146
-	 * Removes an element from the list.
147
-	 *
148
-	 * @warning The element must have the same attributes / values. If using $strict, it must have
149
-	 *          the same types. array(10) will fail in strict against array('10') (str vs int).
150
-	 *
151
-	 * @param mixed $element The element to remove from the list
152
-	 * @param bool  $strict  Whether to check the type of the element match
153
-	 * @return bool
154
-	 */
155
-	public function remove($element, $strict = false) {
156
-		$index = array_search($element, $this->elements, $strict);
157
-		if ($index !== false) {
158
-			unset($this->elements[$index]);
159
-			return true;
160
-		} else {
161
-			return false;
162
-		}
163
-	}
145
+    /**
146
+     * Removes an element from the list.
147
+     *
148
+     * @warning The element must have the same attributes / values. If using $strict, it must have
149
+     *          the same types. array(10) will fail in strict against array('10') (str vs int).
150
+     *
151
+     * @param mixed $element The element to remove from the list
152
+     * @param bool  $strict  Whether to check the type of the element match
153
+     * @return bool
154
+     */
155
+    public function remove($element, $strict = false) {
156
+        $index = array_search($element, $this->elements, $strict);
157
+        if ($index !== false) {
158
+            unset($this->elements[$index]);
159
+            return true;
160
+        } else {
161
+            return false;
162
+        }
163
+    }
164 164
 
165
-	/**
166
-	 * Move an existing element to a new priority.
167
-	 *
168
-	 * @param mixed $element      The element to move
169
-	 * @param int   $new_priority The new priority for the element
170
-	 * @param bool  $strict       Whether to check the type of the element match
171
-	 * @return bool
172
-	 */
173
-	public function move($element, $new_priority, $strict = false) {
174
-		$new_priority = (int) $new_priority;
165
+    /**
166
+     * Move an existing element to a new priority.
167
+     *
168
+     * @param mixed $element      The element to move
169
+     * @param int   $new_priority The new priority for the element
170
+     * @param bool  $strict       Whether to check the type of the element match
171
+     * @return bool
172
+     */
173
+    public function move($element, $new_priority, $strict = false) {
174
+        $new_priority = (int) $new_priority;
175 175
 		
176
-		$current_priority = $this->getPriority($element, $strict);
177
-		if ($current_priority === false) {
178
-			return false;
179
-		}
176
+        $current_priority = $this->getPriority($element, $strict);
177
+        if ($current_priority === false) {
178
+            return false;
179
+        }
180 180
 
181
-		if ($current_priority == $new_priority) {
182
-			return true;
183
-		}
181
+        if ($current_priority == $new_priority) {
182
+            return true;
183
+        }
184 184
 
185
-		// move the actual element so strict operations still work
186
-		$element = $this->getElement($current_priority);
187
-		unset($this->elements[$current_priority]);
188
-		return $this->add($element, $new_priority);
189
-	}
185
+        // move the actual element so strict operations still work
186
+        $element = $this->getElement($current_priority);
187
+        unset($this->elements[$current_priority]);
188
+        return $this->add($element, $new_priority);
189
+    }
190 190
 
191
-	/**
192
-	 * Returns the elements
193
-	 *
194
-	 * @return array
195
-	 */
196
-	public function getElements() {
197
-		$this->sortIfUnsorted();
198
-		return $this->elements;
199
-	}
191
+    /**
192
+     * Returns the elements
193
+     *
194
+     * @return array
195
+     */
196
+    public function getElements() {
197
+        $this->sortIfUnsorted();
198
+        return $this->elements;
199
+    }
200 200
 
201
-	/**
202
-	 * Sort the elements optionally by a callback function.
203
-	 *
204
-	 * If no user function is provided the elements are sorted by priority registered.
205
-	 *
206
-	 * The callback function should accept the array of elements as the first
207
-	 * argument and should return a sorted array.
208
-	 *
209
-	 * This function can be called multiple times.
210
-	 *
211
-	 * @param callback $callback The callback for sorting. Numeric sorting is the default.
212
-	 * @return bool
213
-	 */
214
-	public function sort($callback = null) {
215
-		if (!$callback) {
216
-			ksort($this->elements, SORT_NUMERIC);
217
-		} else {
218
-			$sorted = call_user_func($callback, $this->elements);
201
+    /**
202
+     * Sort the elements optionally by a callback function.
203
+     *
204
+     * If no user function is provided the elements are sorted by priority registered.
205
+     *
206
+     * The callback function should accept the array of elements as the first
207
+     * argument and should return a sorted array.
208
+     *
209
+     * This function can be called multiple times.
210
+     *
211
+     * @param callback $callback The callback for sorting. Numeric sorting is the default.
212
+     * @return bool
213
+     */
214
+    public function sort($callback = null) {
215
+        if (!$callback) {
216
+            ksort($this->elements, SORT_NUMERIC);
217
+        } else {
218
+            $sorted = call_user_func($callback, $this->elements);
219 219
 
220
-			if (!$sorted) {
221
-				return false;
222
-			}
220
+            if (!$sorted) {
221
+                return false;
222
+            }
223 223
 
224
-			$this->elements = $sorted;
225
-		}
224
+            $this->elements = $sorted;
225
+        }
226 226
 		
227
-		$this->sorted = true;
228
-		return true;
229
-	}
227
+        $this->sorted = true;
228
+        return true;
229
+    }
230 230
 
231
-	/**
232
-	 * Sort the elements if they haven't been sorted yet.
233
-	 *
234
-	 * @return bool
235
-	 */
236
-	private function sortIfUnsorted() {
237
-		if (!$this->sorted) {
238
-			return $this->sort();
239
-		}
240
-	}
231
+    /**
232
+     * Sort the elements if they haven't been sorted yet.
233
+     *
234
+     * @return bool
235
+     */
236
+    private function sortIfUnsorted() {
237
+        if (!$this->sorted) {
238
+            return $this->sort();
239
+        }
240
+    }
241 241
 
242
-	/**
243
-	 * Returns the next priority available.
244
-	 *
245
-	 * @param int $near Make the priority as close to $near as possible.
246
-	 * @return int
247
-	 */
248
-	public function getNextPriority($near = 0) {
249
-		$near = (int) $near;
242
+    /**
243
+     * Returns the next priority available.
244
+     *
245
+     * @param int $near Make the priority as close to $near as possible.
246
+     * @return int
247
+     */
248
+    public function getNextPriority($near = 0) {
249
+        $near = (int) $near;
250 250
 		
251
-		while (array_key_exists($near, $this->elements)) {
252
-			$near++;
253
-		}
251
+        while (array_key_exists($near, $this->elements)) {
252
+            $near++;
253
+        }
254 254
 
255
-		return $near;
256
-	}
255
+        return $near;
256
+    }
257 257
 
258
-	/**
259
-	 * Returns the priority of an element if it exists in the list.
260
-	 *
261
-	 * @warning This can return 0 if the element's priority is 0.
262
-	 *
263
-	 * @param mixed $element The element to check for.
264
-	 * @param bool  $strict  Use strict checking?
265
-	 * @return mixed False if the element doesn't exists, the priority if it does.
266
-	 */
267
-	public function getPriority($element, $strict = false) {
268
-		return array_search($element, $this->elements, $strict);
269
-	}
258
+    /**
259
+     * Returns the priority of an element if it exists in the list.
260
+     *
261
+     * @warning This can return 0 if the element's priority is 0.
262
+     *
263
+     * @param mixed $element The element to check for.
264
+     * @param bool  $strict  Use strict checking?
265
+     * @return mixed False if the element doesn't exists, the priority if it does.
266
+     */
267
+    public function getPriority($element, $strict = false) {
268
+        return array_search($element, $this->elements, $strict);
269
+    }
270 270
 
271
-	/**
272
-	 * Returns the element at $priority.
273
-	 *
274
-	 * @param int $priority The priority
275
-	 * @return mixed The element or false on fail.
276
-	 */
277
-	public function getElement($priority) {
278
-		return (isset($this->elements[$priority])) ? $this->elements[$priority] : false;
279
-	}
271
+    /**
272
+     * Returns the element at $priority.
273
+     *
274
+     * @param int $priority The priority
275
+     * @return mixed The element or false on fail.
276
+     */
277
+    public function getElement($priority) {
278
+        return (isset($this->elements[$priority])) ? $this->elements[$priority] : false;
279
+    }
280 280
 
281
-	/**
282
-	 * Returns if the list contains $element.
283
-	 *
284
-	 * @param mixed $element The element to check.
285
-	 * @param bool  $strict  Use strict checking?
286
-	 * @return bool
287
-	 */
288
-	public function contains($element, $strict = false) {
289
-		return $this->getPriority($element, $strict) !== false;
290
-	}
281
+    /**
282
+     * Returns if the list contains $element.
283
+     *
284
+     * @param mixed $element The element to check.
285
+     * @param bool  $strict  Use strict checking?
286
+     * @return bool
287
+     */
288
+    public function contains($element, $strict = false) {
289
+        return $this->getPriority($element, $strict) !== false;
290
+    }
291 291
 
292 292
 	
293
-	/**********************
293
+    /**********************
294 294
 	 * Interface methods *
295 295
 	 **********************/
296 296
 
297
-	/**
298
-	 * Iterator
299
-	 */
297
+    /**
298
+     * Iterator
299
+     */
300 300
 
301
-	/**
302
-	 * PHP Iterator Interface
303
-	 *
304
-	 * @see Iterator::rewind()
305
-	 * @return void
306
-	 */
307
-	public function rewind() {
308
-		$this->sortIfUnsorted();
309
-		return reset($this->elements);
310
-	}
301
+    /**
302
+     * PHP Iterator Interface
303
+     *
304
+     * @see Iterator::rewind()
305
+     * @return void
306
+     */
307
+    public function rewind() {
308
+        $this->sortIfUnsorted();
309
+        return reset($this->elements);
310
+    }
311 311
 
312
-	/**
313
-	 * PHP Iterator Interface
314
-	 *
315
-	 * @see Iterator::current()
316
-	 * @return mixed
317
-	 */
318
-	public function current() {
319
-		$this->sortIfUnsorted();
320
-		return current($this->elements);
321
-	}
312
+    /**
313
+     * PHP Iterator Interface
314
+     *
315
+     * @see Iterator::current()
316
+     * @return mixed
317
+     */
318
+    public function current() {
319
+        $this->sortIfUnsorted();
320
+        return current($this->elements);
321
+    }
322 322
 
323
-	/**
324
-	 * PHP Iterator Interface
325
-	 *
326
-	 * @see Iterator::key()
327
-	 * @return int
328
-	 */
329
-	public function key() {
330
-		$this->sortIfUnsorted();
331
-		return key($this->elements);
332
-	}
323
+    /**
324
+     * PHP Iterator Interface
325
+     *
326
+     * @see Iterator::key()
327
+     * @return int
328
+     */
329
+    public function key() {
330
+        $this->sortIfUnsorted();
331
+        return key($this->elements);
332
+    }
333 333
 
334
-	/**
335
-	 * PHP Iterator Interface
336
-	 *
337
-	 * @see Iterator::next()
338
-	 * @return mixed
339
-	 */
340
-	public function next() {
341
-		$this->sortIfUnsorted();
342
-		return next($this->elements);
343
-	}
334
+    /**
335
+     * PHP Iterator Interface
336
+     *
337
+     * @see Iterator::next()
338
+     * @return mixed
339
+     */
340
+    public function next() {
341
+        $this->sortIfUnsorted();
342
+        return next($this->elements);
343
+    }
344 344
 
345
-	/**
346
-	 * PHP Iterator Interface
347
-	 *
348
-	 * @see Iterator::valid()
349
-	 * @return bool
350
-	 */
351
-	public function valid() {
352
-		$this->sortIfUnsorted();
353
-		$key = key($this->elements);
354
-		return ($key !== null && $key !== false);
355
-	}
345
+    /**
346
+     * PHP Iterator Interface
347
+     *
348
+     * @see Iterator::valid()
349
+     * @return bool
350
+     */
351
+    public function valid() {
352
+        $this->sortIfUnsorted();
353
+        $key = key($this->elements);
354
+        return ($key !== null && $key !== false);
355
+    }
356 356
 
357
-	/**
358
-	 * Countable interface
359
-	 *
360
-	 * @see Countable::count()
361
-	 * @return int
362
-	 */
363
-	public function count() {
364
-		return count($this->elements);
365
-	}
357
+    /**
358
+     * Countable interface
359
+     *
360
+     * @see Countable::count()
361
+     * @return int
362
+     */
363
+    public function count() {
364
+        return count($this->elements);
365
+    }
366 366
 }
Please login to merge, or discard this patch.
engine/lib/access.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
  * @param string $type
553 553
  * @param bool $value
554 554
  * @param array $params
555
- * @return true|null
555
+ * @return boolean|null
556 556
  * @access private
557 557
  */
558 558
 function elgg_override_permissions($hook, $type, $value, $params) {
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
  * @param string $type
590 590
  * @param array $value
591 591
  * @param array $params
592
- * @return array
592
+ * @return string[]
593 593
  *
594 594
  * @access private
595 595
  */
Please login to merge, or discard this patch.
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
  * @see elgg_get_ignore_access()
43 43
  */
44 44
 function elgg_set_ignore_access($ignore = true) {
45
-	return _elgg_services()->session->setIgnoreAccess($ignore);
45
+    return _elgg_services()->session->setIgnoreAccess($ignore);
46 46
 }
47 47
 
48 48
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @see elgg_set_ignore_access()
54 54
  */
55 55
 function elgg_get_ignore_access() {
56
-	return _elgg_services()->session->getIgnoreAccess();
56
+    return _elgg_services()->session->getIgnoreAccess();
57 57
 }
58 58
 
59 59
 /**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
  * @access private
73 73
  */
74 74
 function get_access_list($user_guid = 0, $ignored = 0, $flush = false) {
75
-	return _elgg_services()->accessCollections->getAccessList($user_guid, $flush);
75
+    return _elgg_services()->accessCollections->getAccessList($user_guid, $flush);
76 76
 }
77 77
 
78 78
 /**
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
  * @return array An array of access collections ids
102 102
  */
103 103
 function get_access_array($user_guid = 0, $ignored = 0, $flush = false) {
104
-	return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush);
104
+    return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush);
105 105
 }
106 106
 
107 107
 /**
@@ -117,28 +117,28 @@  discard block
 block discarded – undo
117 117
  * @return int default access id (see ACCESS defines in elgglib.php)
118 118
  */
119 119
 function get_default_access(ElggUser $user = null, array $input_params = []) {
120
-	global $CONFIG;
121
-
122
-	// site default access
123
-	$default_access = $CONFIG->default_access;
124
-
125
-	// user default access if enabled
126
-	if ($CONFIG->allow_user_default_access) {
127
-		$user = $user ? $user : _elgg_services()->session->getLoggedInUser();
128
-		if ($user) {
129
-			$user_access = $user->getPrivateSetting('elgg_default_access');
130
-			if ($user_access !== null) {
131
-				$default_access = $user_access;
132
-			}
133
-		}
134
-	}
135
-
136
-	$params = [
137
-		'user' => $user,
138
-		'default_access' => $default_access,
139
-		'input_params' => $input_params,
140
-	];
141
-	return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access);
120
+    global $CONFIG;
121
+
122
+    // site default access
123
+    $default_access = $CONFIG->default_access;
124
+
125
+    // user default access if enabled
126
+    if ($CONFIG->allow_user_default_access) {
127
+        $user = $user ? $user : _elgg_services()->session->getLoggedInUser();
128
+        if ($user) {
129
+            $user_access = $user->getPrivateSetting('elgg_default_access');
130
+            if ($user_access !== null) {
131
+                $default_access = $user_access;
132
+            }
133
+        }
134
+    }
135
+
136
+    $params = [
137
+        'user' => $user,
138
+        'default_access' => $default_access,
139
+        'input_params' => $input_params,
140
+    ];
141
+    return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access);
142 142
 }
143 143
 
144 144
 /**
@@ -157,10 +157,10 @@  discard block
 block discarded – undo
157 157
  * @return bool
158 158
  */
159 159
 function access_show_hidden_entities($show_hidden) {
160
-	global $ENTITY_SHOW_HIDDEN_OVERRIDE;
161
-	$current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE;
162
-	$ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
163
-	return $current_value;
160
+    global $ENTITY_SHOW_HIDDEN_OVERRIDE;
161
+    $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE;
162
+    $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
163
+    return $current_value;
164 164
 }
165 165
 
166 166
 /**
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
  * @return bool
170 170
  */
171 171
 function access_get_show_hidden_status() {
172
-	global $ENTITY_SHOW_HIDDEN_OVERRIDE;
173
-	return $ENTITY_SHOW_HIDDEN_OVERRIDE;
172
+    global $ENTITY_SHOW_HIDDEN_OVERRIDE;
173
+    return $ENTITY_SHOW_HIDDEN_OVERRIDE;
174 174
 }
175 175
 
176 176
 /**
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
  * @access private
214 214
  */
215 215
 function _elgg_get_access_where_sql(array $options = []) {
216
-	return _elgg_services()->accessCollections->getWhereSql($options);
216
+    return _elgg_services()->accessCollections->getWhereSql($options);
217 217
 }
218 218
 
219 219
 /**
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
  * @return bool
237 237
  */
238 238
 function has_access_to_entity($entity, $user = null) {
239
-	return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user);
239
+    return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user);
240 240
 }
241 241
 
242 242
 /**
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
  * @return array List of access permissions
267 267
  */
268 268
 function get_write_access_array($user_guid = 0, $ignored = 0, $flush = false, array $input_params = []) {
269
-	return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $flush, $input_params);
269
+    return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $flush, $input_params);
270 270
 }
271 271
 
272 272
 /**
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
  * @return bool
285 285
  */
286 286
 function can_edit_access_collection($collection_id, $user_guid = null) {
287
-	return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid);
287
+    return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid);
288 288
 }
289 289
 
290 290
 /**
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
  * @see delete_access_collection()
307 307
  */
308 308
 function create_access_collection($name, $owner_guid = 0) {
309
-	return _elgg_services()->accessCollections->create($name, $owner_guid);
309
+    return _elgg_services()->accessCollections->create($name, $owner_guid);
310 310
 }
311 311
 
312 312
 /**
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
  * @see remove_user_from_access_collection()
327 327
  */
328 328
 function update_access_collection($collection_id, $members) {
329
-	return _elgg_services()->accessCollections->update($collection_id, $members);
329
+    return _elgg_services()->accessCollections->update($collection_id, $members);
330 330
 }
331 331
 
332 332
 /**
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
  * @see update_access_collection()
340 340
  */
341 341
 function delete_access_collection($collection_id) {
342
-	return _elgg_services()->accessCollections->delete($collection_id);
342
+    return _elgg_services()->accessCollections->delete($collection_id);
343 343
 }
344 344
 
345 345
 /**
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
  * @return ElggAccessCollection|false
356 356
  */
357 357
 function get_access_collection($collection_id) {
358
-	return _elgg_services()->accessCollections->get($collection_id);
358
+    return _elgg_services()->accessCollections->get($collection_id);
359 359
 }
360 360
 
361 361
 /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
  * @see remove_user_from_access_collection()
372 372
  */
373 373
 function add_user_to_access_collection($user_guid, $collection_id) {
374
-	return _elgg_services()->accessCollections->addUser($user_guid, $collection_id);
374
+    return _elgg_services()->accessCollections->addUser($user_guid, $collection_id);
375 375
 }
376 376
 
377 377
 /**
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
  * @see remove_user_from_access_collection()
388 388
  */
389 389
 function remove_user_from_access_collection($user_guid, $collection_id) {
390
-	return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id);
390
+    return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id);
391 391
 }
392 392
 
393 393
 /**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
  * @return \ElggAccessCollection[]|false
401 401
  */
402 402
 function get_user_access_collections($owner_guid) {
403
-	return _elgg_services()->accessCollections->getEntityCollections($owner_guid);
403
+    return _elgg_services()->accessCollections->getEntityCollections($owner_guid);
404 404
 }
405 405
 
406 406
 /**
@@ -414,21 +414,21 @@  discard block
 block discarded – undo
414 414
  * @see add_user_to_access_collection()
415 415
  */
416 416
 function get_members_of_access_collection($collection_id, $guids_only = false, array $options = []) {
417
-	if (!isset($options['limit'])) {
418
-		$options['limit'] = 0;
419
-	}
420
-
421
-	if (!$guids_only) {
422
-		return _elgg_services()->accessCollections->getMembers($collection_id, $options);
423
-	}
424
-
425
-	$guids = [];
426
-	$options['callback'] = false;
427
-	$rows = _elgg_services()->accessCollections->getMembers($collection_id, $options);
428
-	foreach ($rows as $row) {
429
-		$guids[] = $row->guid;
430
-	}
431
-	return $guids;
417
+    if (!isset($options['limit'])) {
418
+        $options['limit'] = 0;
419
+    }
420
+
421
+    if (!$guids_only) {
422
+        return _elgg_services()->accessCollections->getMembers($collection_id, $options);
423
+    }
424
+
425
+    $guids = [];
426
+    $options['callback'] = false;
427
+    $rows = _elgg_services()->accessCollections->getMembers($collection_id, $options);
428
+    foreach ($rows as $row) {
429
+        $guids[] = $row->guid;
430
+    }
431
+    return $guids;
432 432
 }
433 433
 
434 434
 /**
@@ -444,25 +444,25 @@  discard block
 block discarded – undo
444 444
  * @since 1.7.0
445 445
  */
446 446
 function elgg_get_entities_from_access_id(array $options = []) {
447
-	// restrict the resultset to access collection provided
448
-	if (!isset($options['access_id'])) {
449
-		return false;
450
-	}
451
-
452
-	// @todo add support for an array of collection_ids
453
-	$where = "e.access_id = '{$options['access_id']}'";
454
-	if (isset($options['wheres'])) {
455
-		if (is_array($options['wheres'])) {
456
-			$options['wheres'][] = $where;
457
-		} else {
458
-			$options['wheres'] = [$options['wheres'], $where];
459
-		}
460
-	} else {
461
-		$options['wheres'] = [$where];
462
-	}
463
-
464
-	// return entities with the desired options
465
-	return _elgg_services()->entityTable->getEntities($options);
447
+    // restrict the resultset to access collection provided
448
+    if (!isset($options['access_id'])) {
449
+        return false;
450
+    }
451
+
452
+    // @todo add support for an array of collection_ids
453
+    $where = "e.access_id = '{$options['access_id']}'";
454
+    if (isset($options['wheres'])) {
455
+        if (is_array($options['wheres'])) {
456
+            $options['wheres'][] = $where;
457
+        } else {
458
+            $options['wheres'] = [$options['wheres'], $where];
459
+        }
460
+    } else {
461
+        $options['wheres'] = [$where];
462
+    }
463
+
464
+    // return entities with the desired options
465
+    return _elgg_services()->entityTable->getEntities($options);
466 466
 }
467 467
 
468 468
 /**
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
  * @return string
477 477
  */
478 478
 function elgg_list_entities_from_access_id(array $options = []) {
479
-	return elgg_list_entities($options, 'elgg_get_entities_from_access_id');
479
+    return elgg_list_entities($options, 'elgg_get_entities_from_access_id');
480 480
 }
481 481
 
482 482
 /**
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
  * @since 1.7.0
497 497
  */
498 498
 function get_readable_access_level($entity_access_id) {
499
-	return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id);
499
+    return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id);
500 500
 }
501 501
 
502 502
 /**
@@ -515,13 +515,13 @@  discard block
 block discarded – undo
515 515
  * @todo should this be a private function?
516 516
  */
517 517
 function elgg_check_access_overrides($user_guid = 0) {
518
-	if (!$user_guid || $user_guid <= 0) {
519
-		$is_admin = false;
520
-	} else {
521
-		$is_admin = elgg_is_admin_user($user_guid);
522
-	}
518
+    if (!$user_guid || $user_guid <= 0) {
519
+        $is_admin = false;
520
+    } else {
521
+        $is_admin = elgg_is_admin_user($user_guid);
522
+    }
523 523
 
524
-	return ($is_admin || _elgg_services()->session->getIgnoreAccess());
524
+    return ($is_admin || _elgg_services()->session->getIgnoreAccess());
525 525
 }
526 526
 
527 527
 /**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
  * @return void
544 544
  */
545 545
 function access_init() {
546
-	global $init_finished;
547
-	$init_finished = true;
546
+    global $init_finished;
547
+    $init_finished = true;
548 548
 }
549 549
 
550 550
 /**
@@ -568,29 +568,29 @@  discard block
 block discarded – undo
568 568
  * @access private
569 569
  */
570 570
 function elgg_override_permissions($hook, $type, $value, $params) {
571
-	$user = elgg_extract('user', $params);
572
-	if ($user) {
573
-		$user_guid = $user->guid;
574
-	} else {
575
-		$user_guid = _elgg_services()->session->getLoggedInUserGuid();
576
-	}
577
-
578
-	// don't do this so ignore access still works with no one logged in
579
-	//if (!$user instanceof \ElggUser) {
580
-	//	return false;
581
-	//}
582
-	// check for admin
583
-	if ($user_guid && elgg_is_admin_user($user_guid)) {
584
-		return true;
585
-	}
586
-
587
-	// check access overrides
588
-	if (elgg_check_access_overrides($user_guid)) {
589
-		return true;
590
-	}
591
-
592
-	// consult other hooks
593
-	return null;
571
+    $user = elgg_extract('user', $params);
572
+    if ($user) {
573
+        $user_guid = $user->guid;
574
+    } else {
575
+        $user_guid = _elgg_services()->session->getLoggedInUserGuid();
576
+    }
577
+
578
+    // don't do this so ignore access still works with no one logged in
579
+    //if (!$user instanceof \ElggUser) {
580
+    //	return false;
581
+    //}
582
+    // check for admin
583
+    if ($user_guid && elgg_is_admin_user($user_guid)) {
584
+        return true;
585
+    }
586
+
587
+    // check access overrides
588
+    if (elgg_check_access_overrides($user_guid)) {
589
+        return true;
590
+    }
591
+
592
+    // consult other hooks
593
+    return null;
594 594
 }
595 595
 
596 596
 /**
@@ -605,20 +605,20 @@  discard block
 block discarded – undo
605 605
  * @access private
606 606
  */
607 607
 function access_test($hook, $type, $value, $params) {
608
-	global $CONFIG;
609
-	$value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
610
-	$value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
611
-	return $value;
608
+    global $CONFIG;
609
+    $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
610
+    $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
611
+    return $value;
612 612
 }
613 613
 
614 614
 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
615
-	// Tell the access functions the system has booted, plugins are loaded,
616
-	// and the user is logged in so it can start caching
617
-	$events->registerHandler('ready', 'system', 'access_init');
615
+    // Tell the access functions the system has booted, plugins are loaded,
616
+    // and the user is logged in so it can start caching
617
+    $events->registerHandler('ready', 'system', 'access_init');
618 618
 
619
-	// For overrided permissions
620
-	$hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions', 600);
621
-	$hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions', 600);
619
+    // For overrided permissions
620
+    $hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions', 600);
621
+    $hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions', 600);
622 622
 
623
-	$hooks->registerHandler('unit_test', 'system', 'access_test');
623
+    $hooks->registerHandler('unit_test', 'system', 'access_test');
624 624
 };
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -606,8 +606,8 @@
 block discarded – undo
606 606
  */
607 607
 function access_test($hook, $type, $value, $params) {
608 608
 	global $CONFIG;
609
-	$value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
610
-	$value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
609
+	$value[] = $CONFIG->path.'engine/tests/ElggCoreAccessCollectionsTest.php';
610
+	$value[] = $CONFIG->path.'engine/tests/ElggCoreAccessSQLTest.php';
611 611
 	return $value;
612 612
 }
613 613
 
Please login to merge, or discard this patch.
engine/lib/admin.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -806,7 +806,7 @@
 block discarded – undo
806 806
  * @param string $type
807 807
  * @param \ElggUser $user
808 808
  *
809
- * @return null|true
809
+ * @return boolean|null
810 810
  * @access private
811 811
  */
812 812
 function _elgg_add_admin_widgets($event, $type, $user) {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
 
489 489
 	foreach ($active_plugins as $plugin) {
490 490
 		$plugin_id = $plugin->getID();
491
-		$settings_view_old = 'settings/' . $plugin_id . '/edit';
492
-		$settings_view_new = 'plugins/' . $plugin_id . '/settings';
491
+		$settings_view_old = 'settings/'.$plugin_id.'/edit';
492
+		$settings_view_new = 'plugins/'.$plugin_id.'/settings';
493 493
 		if (elgg_view_exists($settings_view_new) || elgg_view_exists($settings_view_old)) {
494 494
 			elgg_register_menu_item('page', [
495 495
 				'name' => $plugin_id,
@@ -581,10 +581,10 @@  discard block
 block discarded – undo
581 581
 			forward('', '404');
582 582
 		}
583 583
 	} else {
584
-		$view = 'admin/' . implode('/', $page);
584
+		$view = 'admin/'.implode('/', $page);
585 585
 		$title = elgg_echo("admin:{$page[0]}");
586 586
 		if (count($page) > 1) {
587
-			$title .= ' : ' . elgg_echo('admin:' .  implode(':', $page));
587
+			$title .= ' : '.elgg_echo('admin:'.implode(':', $page));
588 588
 		}
589 589
 	}
590 590
 
Please login to merge, or discard this patch.
Indentation   +600 added lines, -600 removed lines patch added patch discarded remove patch
@@ -33,27 +33,27 @@  discard block
 block discarded – undo
33 33
  * @since 1.8.0
34 34
  */
35 35
 function elgg_get_admins(array $options = []) {
36
-	global $CONFIG;
37
-
38
-	if (isset($options['joins'])) {
39
-		if (!is_array($options['joins'])) {
40
-			$options['joins'] = [$options['joins']];
41
-		}
42
-		$options['joins'][] = "join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid";
43
-	} else {
44
-		$options['joins'] = ["join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid"];
45
-	}
46
-
47
-	if (isset($options['wheres'])) {
48
-		if (!is_array($options['wheres'])) {
49
-			$options['wheres'] = [$options['wheres']];
50
-		}
51
-		$options['wheres'][] = "u.admin = 'yes'";
52
-	} else {
53
-		$options['wheres'][] = "u.admin = 'yes'";
54
-	}
55
-
56
-	return elgg_get_entities($options);
36
+    global $CONFIG;
37
+
38
+    if (isset($options['joins'])) {
39
+        if (!is_array($options['joins'])) {
40
+            $options['joins'] = [$options['joins']];
41
+        }
42
+        $options['joins'][] = "join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid";
43
+    } else {
44
+        $options['joins'] = ["join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid"];
45
+    }
46
+
47
+    if (isset($options['wheres'])) {
48
+        if (!is_array($options['wheres'])) {
49
+            $options['wheres'] = [$options['wheres']];
50
+        }
51
+        $options['wheres'][] = "u.admin = 'yes'";
52
+    } else {
53
+        $options['wheres'][] = "u.admin = 'yes'";
54
+    }
55
+
56
+    return elgg_get_entities($options);
57 57
 }
58 58
 
59 59
 /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
  * @since 1.8.0
74 74
  */
75 75
 function elgg_add_admin_notice($id, $message) {
76
-	return _elgg_services()->adminNotices->add($id, $message);
76
+    return _elgg_services()->adminNotices->add($id, $message);
77 77
 }
78 78
 
79 79
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
  * @since 1.8.0
91 91
  */
92 92
 function elgg_delete_admin_notice($id) {
93
-	return _elgg_services()->adminNotices->delete($id);
93
+    return _elgg_services()->adminNotices->delete($id);
94 94
 }
95 95
 
96 96
 /**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
  * @since 1.8.0
103 103
  */
104 104
 function elgg_get_admin_notices(array $options = []) {
105
-	return _elgg_services()->adminNotices->find($options);
105
+    return _elgg_services()->adminNotices->find($options);
106 106
 }
107 107
 
108 108
 /**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
  * @since 1.8.0
115 115
  */
116 116
 function elgg_admin_notice_exists($id) {
117
-	return _elgg_services()->adminNotices->exists($id);
117
+    return _elgg_services()->adminNotices->exists($id);
118 118
 }
119 119
 
120 120
 /**
@@ -139,32 +139,32 @@  discard block
 block discarded – undo
139 139
  */
140 140
 function elgg_register_admin_menu_item($section, $menu_id, $parent_id = null, $priority = 100) {
141 141
 
142
-	// make sure parent is registered
143
-	if ($parent_id && !elgg_is_menu_item_registered('page', $parent_id)) {
144
-		elgg_register_admin_menu_item($section, $parent_id);
145
-	}
146
-
147
-	// in the admin section parents never have links
148
-	if ($parent_id) {
149
-		$href = "admin/$parent_id/$menu_id";
150
-	} else {
151
-		$href = null;
152
-	}
153
-
154
-	$name = $menu_id;
155
-	if ($parent_id) {
156
-		$name = "$parent_id:$name";
157
-	}
158
-
159
-	return elgg_register_menu_item('page', [
160
-		'name' => $name,
161
-		'href' => $href,
162
-		'text' => elgg_echo("admin:$name"),
163
-		'context' => 'admin',
164
-		'parent_name' => $parent_id,
165
-		'priority' => $priority,
166
-		'section' => $section
167
-	]);
142
+    // make sure parent is registered
143
+    if ($parent_id && !elgg_is_menu_item_registered('page', $parent_id)) {
144
+        elgg_register_admin_menu_item($section, $parent_id);
145
+    }
146
+
147
+    // in the admin section parents never have links
148
+    if ($parent_id) {
149
+        $href = "admin/$parent_id/$menu_id";
150
+    } else {
151
+        $href = null;
152
+    }
153
+
154
+    $name = $menu_id;
155
+    if ($parent_id) {
156
+        $name = "$parent_id:$name";
157
+    }
158
+
159
+    return elgg_register_menu_item('page', [
160
+        'name' => $name,
161
+        'href' => $href,
162
+        'text' => elgg_echo("admin:$name"),
163
+        'context' => 'admin',
164
+        'parent_name' => $parent_id,
165
+        'priority' => $priority,
166
+        'section' => $section
167
+    ]);
168 168
 }
169 169
 
170 170
 /**
@@ -176,17 +176,17 @@  discard block
 block discarded – undo
176 176
  * @access private
177 177
  */
178 178
 function _elgg_create_notice_of_pending_upgrade($event, $type, $object) {
179
-	if ($object instanceof \ElggUpgrade) {
180
-		// Link to the Upgrades section
181
-		$link = elgg_view('output/url', [
182
-			'href' => 'admin/upgrades',
183
-			'text' => elgg_echo('admin:view_upgrades'),
184
-		]);
179
+    if ($object instanceof \ElggUpgrade) {
180
+        // Link to the Upgrades section
181
+        $link = elgg_view('output/url', [
182
+            'href' => 'admin/upgrades',
183
+            'text' => elgg_echo('admin:view_upgrades'),
184
+        ]);
185 185
 
186
-		$message = elgg_echo('admin:pending_upgrades');
186
+        $message = elgg_echo('admin:pending_upgrades');
187 187
 
188
-		elgg_add_admin_notice('pending_upgrades', "$message $link");
189
-	}
188
+        elgg_add_admin_notice('pending_upgrades', "$message $link");
189
+    }
190 190
 }
191 191
 
192 192
 /**
@@ -196,158 +196,158 @@  discard block
 block discarded – undo
196 196
  */
197 197
 function _elgg_admin_init() {
198 198
 
199
-	$url = elgg_get_simplecache_url('admin.css');
200
-	elgg_register_css('elgg.admin', $url);
199
+    $url = elgg_get_simplecache_url('admin.css');
200
+    elgg_register_css('elgg.admin', $url);
201 201
 		
202
-	elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu');
203
-	elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu');
204
-
205
-	// maintenance mode
206
-	if (elgg_get_config('elgg_maintenance_mode', null)) {
207
-		elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600);
208
-		elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600);
209
-		elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css'));
210
-
211
-		elgg_register_menu_item('topbar', [
212
-			'name' => 'maintenance_mode',
213
-			'href' => 'admin/administer_utilities/maintenance',
214
-			'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'),
215
-			'priority' => 900,
216
-		]);
217
-	}
218
-
219
-	elgg_register_action('admin/user/ban', '', 'admin');
220
-	elgg_register_action('admin/user/unban', '', 'admin');
221
-	elgg_register_action('admin/user/delete', '', 'admin');
222
-	elgg_register_action('admin/user/resetpassword', '', 'admin');
223
-	elgg_register_action('admin/user/makeadmin', '', 'admin');
224
-	elgg_register_action('admin/user/removeadmin', '', 'admin');
225
-
226
-	elgg_register_action('admin/site/update_basic', '', 'admin');
227
-	elgg_register_action('admin/site/update_advanced', '', 'admin');
228
-	elgg_register_action('admin/site/flush_cache', '', 'admin');
229
-	elgg_register_action('admin/site/unlock_upgrade', '', 'admin');
230
-	elgg_register_action('admin/site/set_robots', '', 'admin');
231
-	elgg_register_action('admin/site/set_maintenance_mode', '', 'admin');
232
-
233
-	elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin');
234
-	elgg_register_action('admin/site/regenerate_secret', '', 'admin');
235
-	elgg_register_action('admin/upgrade', '', 'admin');
236
-
237
-	elgg_register_action('admin/menu/save', '', 'admin');
238
-
239
-	elgg_register_action('admin/delete_admin_notice', '', 'admin');
202
+    elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu');
203
+    elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu');
204
+
205
+    // maintenance mode
206
+    if (elgg_get_config('elgg_maintenance_mode', null)) {
207
+        elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600);
208
+        elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600);
209
+        elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css'));
210
+
211
+        elgg_register_menu_item('topbar', [
212
+            'name' => 'maintenance_mode',
213
+            'href' => 'admin/administer_utilities/maintenance',
214
+            'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'),
215
+            'priority' => 900,
216
+        ]);
217
+    }
218
+
219
+    elgg_register_action('admin/user/ban', '', 'admin');
220
+    elgg_register_action('admin/user/unban', '', 'admin');
221
+    elgg_register_action('admin/user/delete', '', 'admin');
222
+    elgg_register_action('admin/user/resetpassword', '', 'admin');
223
+    elgg_register_action('admin/user/makeadmin', '', 'admin');
224
+    elgg_register_action('admin/user/removeadmin', '', 'admin');
225
+
226
+    elgg_register_action('admin/site/update_basic', '', 'admin');
227
+    elgg_register_action('admin/site/update_advanced', '', 'admin');
228
+    elgg_register_action('admin/site/flush_cache', '', 'admin');
229
+    elgg_register_action('admin/site/unlock_upgrade', '', 'admin');
230
+    elgg_register_action('admin/site/set_robots', '', 'admin');
231
+    elgg_register_action('admin/site/set_maintenance_mode', '', 'admin');
232
+
233
+    elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin');
234
+    elgg_register_action('admin/site/regenerate_secret', '', 'admin');
235
+    elgg_register_action('admin/upgrade', '', 'admin');
236
+
237
+    elgg_register_action('admin/menu/save', '', 'admin');
238
+
239
+    elgg_register_action('admin/delete_admin_notice', '', 'admin');
240 240
 	
241
-	elgg_register_action('admin/security/settings', '', 'admin');
242
-
243
-	elgg_register_action('profile/fields/reset', '', 'admin');
244
-	elgg_register_action('profile/fields/add', '', 'admin');
245
-	elgg_register_action('profile/fields/edit', '', 'admin');
246
-	elgg_register_action('profile/fields/delete', '', 'admin');
247
-	elgg_register_action('profile/fields/reorder', '', 'admin');
248
-
249
-	elgg_register_simplecache_view('admin.css');
250
-
251
-	elgg_register_js('jquery.jeditable', elgg_get_simplecache_url('jquery.jeditable.js'));
252
-
253
-	// administer
254
-	// dashboard
255
-	elgg_register_menu_item('page', [
256
-		'name' => 'dashboard',
257
-		'href' => 'admin/dashboard',
258
-		'text' => elgg_echo('admin:dashboard'),
259
-		'context' => 'admin',
260
-		'priority' => 10,
261
-		'section' => 'administer'
262
-	]);
263
-	// statistics
264
-	elgg_register_admin_menu_item('administer', 'statistics', null, 20);
265
-	elgg_register_admin_menu_item('administer', 'overview', 'statistics');
266
-	elgg_register_admin_menu_item('administer', 'server', 'statistics');
267
-	//utilities
268
-	elgg_register_admin_menu_item('administer', 'maintenance', 'administer_utilities');
269
-	// security
270
-	elgg_register_admin_menu_item('administer', 'settings', 'administer_security');
271
-
272
-	// users
273
-	elgg_register_admin_menu_item('administer', 'users', null, 20);
274
-	elgg_register_admin_menu_item('administer', 'online', 'users', 10);
275
-	elgg_register_admin_menu_item('administer', 'admins', 'users', 20);
276
-	elgg_register_admin_menu_item('administer', 'newest', 'users', 30);
277
-	elgg_register_admin_menu_item('administer', 'add', 'users', 40);
278
-
279
-	// configure
280
-	// upgrades
281
-	elgg_register_menu_item('page', [
282
-		'name' => 'upgrades',
283
-		'href' => 'admin/upgrades',
284
-		'text' => elgg_echo('admin:upgrades'),
285
-		'context' => 'admin',
286
-		'priority' => 10,
287
-		'section' => 'configure'
288
-	]);
289
-
290
-	// plugins
291
-	elgg_register_menu_item('page', [
292
-		'name' => 'plugins',
293
-		'href' => 'admin/plugins',
294
-		'text' => elgg_echo('admin:plugins'),
295
-		'context' => 'admin',
296
-		'priority' => 75,
297
-		'section' => 'configure'
298
-	]);
299
-
300
-	// settings
301
-	elgg_register_admin_menu_item('configure', 'appearance', null, 50);
302
-	elgg_register_admin_menu_item('configure', 'settings', null, 100);
303
-	elgg_register_admin_menu_item('configure', 'basic', 'settings', 10);
304
-	elgg_register_admin_menu_item('configure', 'advanced', 'settings', 20);
305
-	// plugin settings are added in _elgg_admin_add_plugin_settings_menu() via the admin page handler
306
-	// for performance reasons.
307
-
308
-	// appearance
309
-	elgg_register_admin_menu_item('configure', 'menu_items', 'appearance', 30);
310
-	elgg_register_admin_menu_item('configure', 'profile_fields', 'appearance', 40);
311
-	// default widgets is added via an event handler elgg_default_widgets_init() in widgets.php
312
-	// because it requires additional setup.
313
-
314
-	// configure utilities
315
-	elgg_register_admin_menu_item('configure', 'robots', 'configure_utilities');
316
-
317
-	// we want plugin settings menu items to be sorted alphabetical
318
-	if (elgg_in_context('admin') && elgg_is_admin_logged_in()) {
319
-		elgg_register_plugin_hook_handler('prepare', 'menu:page', '_elgg_admin_sort_page_menu');
320
-	}
321
-
322
-	// widgets
323
-	$widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status'];
324
-	foreach ($widgets as $widget) {
325
-		elgg_register_widget_type(
326
-				$widget,
327
-				elgg_echo("admin:widget:$widget"),
328
-				elgg_echo("admin:widget:$widget:help"),
329
-				['admin']
330
-		);
331
-	}
332
-
333
-	// automatic adding of widgets for admin
334
-	elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets');
241
+    elgg_register_action('admin/security/settings', '', 'admin');
242
+
243
+    elgg_register_action('profile/fields/reset', '', 'admin');
244
+    elgg_register_action('profile/fields/add', '', 'admin');
245
+    elgg_register_action('profile/fields/edit', '', 'admin');
246
+    elgg_register_action('profile/fields/delete', '', 'admin');
247
+    elgg_register_action('profile/fields/reorder', '', 'admin');
248
+
249
+    elgg_register_simplecache_view('admin.css');
250
+
251
+    elgg_register_js('jquery.jeditable', elgg_get_simplecache_url('jquery.jeditable.js'));
252
+
253
+    // administer
254
+    // dashboard
255
+    elgg_register_menu_item('page', [
256
+        'name' => 'dashboard',
257
+        'href' => 'admin/dashboard',
258
+        'text' => elgg_echo('admin:dashboard'),
259
+        'context' => 'admin',
260
+        'priority' => 10,
261
+        'section' => 'administer'
262
+    ]);
263
+    // statistics
264
+    elgg_register_admin_menu_item('administer', 'statistics', null, 20);
265
+    elgg_register_admin_menu_item('administer', 'overview', 'statistics');
266
+    elgg_register_admin_menu_item('administer', 'server', 'statistics');
267
+    //utilities
268
+    elgg_register_admin_menu_item('administer', 'maintenance', 'administer_utilities');
269
+    // security
270
+    elgg_register_admin_menu_item('administer', 'settings', 'administer_security');
271
+
272
+    // users
273
+    elgg_register_admin_menu_item('administer', 'users', null, 20);
274
+    elgg_register_admin_menu_item('administer', 'online', 'users', 10);
275
+    elgg_register_admin_menu_item('administer', 'admins', 'users', 20);
276
+    elgg_register_admin_menu_item('administer', 'newest', 'users', 30);
277
+    elgg_register_admin_menu_item('administer', 'add', 'users', 40);
278
+
279
+    // configure
280
+    // upgrades
281
+    elgg_register_menu_item('page', [
282
+        'name' => 'upgrades',
283
+        'href' => 'admin/upgrades',
284
+        'text' => elgg_echo('admin:upgrades'),
285
+        'context' => 'admin',
286
+        'priority' => 10,
287
+        'section' => 'configure'
288
+    ]);
289
+
290
+    // plugins
291
+    elgg_register_menu_item('page', [
292
+        'name' => 'plugins',
293
+        'href' => 'admin/plugins',
294
+        'text' => elgg_echo('admin:plugins'),
295
+        'context' => 'admin',
296
+        'priority' => 75,
297
+        'section' => 'configure'
298
+    ]);
299
+
300
+    // settings
301
+    elgg_register_admin_menu_item('configure', 'appearance', null, 50);
302
+    elgg_register_admin_menu_item('configure', 'settings', null, 100);
303
+    elgg_register_admin_menu_item('configure', 'basic', 'settings', 10);
304
+    elgg_register_admin_menu_item('configure', 'advanced', 'settings', 20);
305
+    // plugin settings are added in _elgg_admin_add_plugin_settings_menu() via the admin page handler
306
+    // for performance reasons.
307
+
308
+    // appearance
309
+    elgg_register_admin_menu_item('configure', 'menu_items', 'appearance', 30);
310
+    elgg_register_admin_menu_item('configure', 'profile_fields', 'appearance', 40);
311
+    // default widgets is added via an event handler elgg_default_widgets_init() in widgets.php
312
+    // because it requires additional setup.
313
+
314
+    // configure utilities
315
+    elgg_register_admin_menu_item('configure', 'robots', 'configure_utilities');
316
+
317
+    // we want plugin settings menu items to be sorted alphabetical
318
+    if (elgg_in_context('admin') && elgg_is_admin_logged_in()) {
319
+        elgg_register_plugin_hook_handler('prepare', 'menu:page', '_elgg_admin_sort_page_menu');
320
+    }
321
+
322
+    // widgets
323
+    $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status'];
324
+    foreach ($widgets as $widget) {
325
+        elgg_register_widget_type(
326
+                $widget,
327
+                elgg_echo("admin:widget:$widget"),
328
+                elgg_echo("admin:widget:$widget:help"),
329
+                ['admin']
330
+        );
331
+    }
332
+
333
+    // automatic adding of widgets for admin
334
+    elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets');
335 335
 	
336
-	elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']);
337
-	elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action');
338
-	elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action');
339
-	elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin');
340
-	elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin');
341
-	elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin');
342
-	elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin');
336
+    elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']);
337
+    elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action');
338
+    elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action');
339
+    elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin');
340
+    elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin');
341
+    elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin');
342
+    elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin');
343 343
 	
344
-	// Add notice about pending upgrades
345
-	elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade');
344
+    // Add notice about pending upgrades
345
+    elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade');
346 346
 
347
-	elgg_register_page_handler('admin', '_elgg_admin_page_handler');
348
-	elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler');
349
-	elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler');
350
-	elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update');
347
+    elgg_register_page_handler('admin', '_elgg_admin_page_handler');
348
+    elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler');
349
+    elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler');
350
+    elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update');
351 351
 }
352 352
 
353 353
 /**
@@ -357,14 +357,14 @@  discard block
 block discarded – undo
357 357
  * @return Elgg\Http\OkResponse
358 358
  */
359 359
 function _elgg_ajax_plugins_update() {
360
-	elgg_admin_gatekeeper();
361
-	_elgg_admin_add_plugin_settings_menu();
362
-	elgg_set_context('admin');
363
-
364
-	return elgg_ok_response([
365
-		'list' => elgg_view('admin/plugins', ['list_only' => true]),
366
-		'sidebar' => elgg_view('admin/sidebar'),
367
-	]);
360
+    elgg_admin_gatekeeper();
361
+    _elgg_admin_add_plugin_settings_menu();
362
+    elgg_set_context('admin');
363
+
364
+    return elgg_ok_response([
365
+        'list' => elgg_view('admin/plugins', ['list_only' => true]),
366
+        'sidebar' => elgg_view('admin/sidebar'),
367
+    ]);
368 368
 }
369 369
 
370 370
 /**
@@ -381,46 +381,46 @@  discard block
 block discarded – undo
381 381
  * @since 3.0
382 382
  */
383 383
 function _elgg_admin_header_menu($hook, $type, $return, $params) {
384
-	if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
385
-		return;
386
-	}
387
-
388
-	$admin = elgg_get_logged_in_user_entity();
389
-
390
-	$return[] = \ElggMenuItem::factory([
391
-		'name' => 'admin_logout',
392
-		'href' => 'action/logout',
393
-		'text' => elgg_echo('logout'),
394
-		'is_trusted' => true,
395
-		'priority' => 1000,
396
-	]);
397
-
398
-	$return[] = \ElggMenuItem::factory([
399
-		'name' => 'view_site',
400
-		'href' => elgg_get_site_url(),
401
-		'text' => elgg_echo('admin:view_site'),
402
-		'is_trusted' => true,
403
-		'priority' => 900,
404
-	]);
405
-
406
-	$return[] = \ElggMenuItem::factory([
407
-		'name' => 'admin_profile',
408
-		'href' => false,
409
-		'text' => elgg_echo('admin:loggedin', [$admin->name]),
410
-		'priority' => 800,
411
-	]);
412
-
413
-	if (elgg_get_config('elgg_maintenance_mode', null)) {
414
-		$return[] = \ElggMenuItem::factory([
415
-			'name' => 'maintenance',
416
-			'href' => 'admin/administer_utilities/maintenance',
417
-			'text' => elgg_echo('admin:administer_utilities:maintenance'),
418
-			'link_class' => 'elgg-maintenance-mode-warning',
419
-			'priority' => 700,
420
-		]);
421
-	}
384
+    if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
385
+        return;
386
+    }
387
+
388
+    $admin = elgg_get_logged_in_user_entity();
389
+
390
+    $return[] = \ElggMenuItem::factory([
391
+        'name' => 'admin_logout',
392
+        'href' => 'action/logout',
393
+        'text' => elgg_echo('logout'),
394
+        'is_trusted' => true,
395
+        'priority' => 1000,
396
+    ]);
397
+
398
+    $return[] = \ElggMenuItem::factory([
399
+        'name' => 'view_site',
400
+        'href' => elgg_get_site_url(),
401
+        'text' => elgg_echo('admin:view_site'),
402
+        'is_trusted' => true,
403
+        'priority' => 900,
404
+    ]);
405
+
406
+    $return[] = \ElggMenuItem::factory([
407
+        'name' => 'admin_profile',
408
+        'href' => false,
409
+        'text' => elgg_echo('admin:loggedin', [$admin->name]),
410
+        'priority' => 800,
411
+    ]);
412
+
413
+    if (elgg_get_config('elgg_maintenance_mode', null)) {
414
+        $return[] = \ElggMenuItem::factory([
415
+            'name' => 'maintenance',
416
+            'href' => 'admin/administer_utilities/maintenance',
417
+            'text' => elgg_echo('admin:administer_utilities:maintenance'),
418
+            'link_class' => 'elgg-maintenance-mode-warning',
419
+            'priority' => 700,
420
+        ]);
421
+    }
422 422
 	
423
-	return $return;
423
+    return $return;
424 424
 }
425 425
 
426 426
 /**
@@ -437,35 +437,35 @@  discard block
 block discarded – undo
437 437
  * @since 3.0
438 438
  */
439 439
 function _elgg_admin_footer_menu($hook, $type, $return, $params) {
440
-	if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
441
-		return;
442
-	}
443
-
444
-	$return[] = \ElggMenuItem::factory([
445
-		'name' => 'faq',
446
-		'text' => elgg_echo('admin:footer:faq'),
447
-		'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html',
448
-	]);
449
-
450
-	$return[] = \ElggMenuItem::factory([
451
-		'name' => 'manual',
452
-		'text' => elgg_echo('admin:footer:manual'),
453
-		'href' => 'http://learn.elgg.org/en/stable/admin/index.html',
454
-	]);
455
-
456
-	$return[] = \ElggMenuItem::factory([
457
-		'name' => 'community_forums',
458
-		'text' => elgg_echo('admin:footer:community_forums'),
459
-		'href' => 'http://elgg.org/groups/all/',
460
-	]);
461
-
462
-	$return[] = \ElggMenuItem::factory([
463
-		'name' => 'blog',
464
-		'text' => elgg_echo('admin:footer:blog'),
465
-		'href' => 'https://elgg.org/blog/all',
466
-	]);
440
+    if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
441
+        return;
442
+    }
443
+
444
+    $return[] = \ElggMenuItem::factory([
445
+        'name' => 'faq',
446
+        'text' => elgg_echo('admin:footer:faq'),
447
+        'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html',
448
+    ]);
449
+
450
+    $return[] = \ElggMenuItem::factory([
451
+        'name' => 'manual',
452
+        'text' => elgg_echo('admin:footer:manual'),
453
+        'href' => 'http://learn.elgg.org/en/stable/admin/index.html',
454
+    ]);
455
+
456
+    $return[] = \ElggMenuItem::factory([
457
+        'name' => 'community_forums',
458
+        'text' => elgg_echo('admin:footer:community_forums'),
459
+        'href' => 'http://elgg.org/groups/all/',
460
+    ]);
461
+
462
+    $return[] = \ElggMenuItem::factory([
463
+        'name' => 'blog',
464
+        'text' => elgg_echo('admin:footer:blog'),
465
+        'href' => 'https://elgg.org/blog/all',
466
+    ]);
467 467
 	
468
-	return $return;
468
+    return $return;
469 469
 }
470 470
 
471 471
 /**
@@ -480,27 +480,27 @@  discard block
 block discarded – undo
480 480
  */
481 481
 function _elgg_admin_add_plugin_settings_menu() {
482 482
 
483
-	$active_plugins = elgg_get_plugins('active');
484
-	if (!$active_plugins) {
485
-		// nothing added because no items
486
-		return;
487
-	}
488
-
489
-	foreach ($active_plugins as $plugin) {
490
-		$plugin_id = $plugin->getID();
491
-		$settings_view_old = 'settings/' . $plugin_id . '/edit';
492
-		$settings_view_new = 'plugins/' . $plugin_id . '/settings';
493
-		if (elgg_view_exists($settings_view_new) || elgg_view_exists($settings_view_old)) {
494
-			elgg_register_menu_item('page', [
495
-				'name' => $plugin_id,
496
-				'href' => "admin/plugin_settings/$plugin_id",
497
-				'text' => $plugin->getManifest()->getName(),
498
-				'parent_name' => 'settings',
499
-				'context' => 'admin',
500
-				'section' => 'configure',
501
-			]);
502
-		}
503
-	}
483
+    $active_plugins = elgg_get_plugins('active');
484
+    if (!$active_plugins) {
485
+        // nothing added because no items
486
+        return;
487
+    }
488
+
489
+    foreach ($active_plugins as $plugin) {
490
+        $plugin_id = $plugin->getID();
491
+        $settings_view_old = 'settings/' . $plugin_id . '/edit';
492
+        $settings_view_new = 'plugins/' . $plugin_id . '/settings';
493
+        if (elgg_view_exists($settings_view_new) || elgg_view_exists($settings_view_old)) {
494
+            elgg_register_menu_item('page', [
495
+                'name' => $plugin_id,
496
+                'href' => "admin/plugin_settings/$plugin_id",
497
+                'text' => $plugin->getManifest()->getName(),
498
+                'parent_name' => 'settings',
499
+                'context' => 'admin',
500
+                'section' => 'configure',
501
+            ]);
502
+        }
503
+    }
504 504
 }
505 505
 
506 506
 /**
@@ -516,25 +516,25 @@  discard block
 block discarded – undo
516 516
  * @access private
517 517
  */
518 518
 function _elgg_admin_sort_page_menu($hook, $type, $return, $params) {
519
-	$configure_items = $return['configure'];
520
-	if (is_array($configure_items)) {
521
-		/* @var \ElggMenuItem[] $configure_items */
522
-		foreach ($configure_items as $menu_item) {
523
-			if ($menu_item->getName() == 'settings') {
524
-				$settings = $menu_item;
525
-			}
526
-		}
527
-
528
-		if (!empty($settings) && $settings instanceof \ElggMenuItem) {
529
-			// keep the basic and advanced settings at the top
530
-			/* @var \ElggMenuItem $settings */
531
-			$children = $settings->getChildren();
532
-			$site_settings = array_splice($children, 0, 2);
533
-			usort($children, [\ElggMenuBuilder::class, 'compareByText']);
534
-			array_splice($children, 0, 0, $site_settings);
535
-			$settings->setChildren($children);
536
-		}
537
-	}
519
+    $configure_items = $return['configure'];
520
+    if (is_array($configure_items)) {
521
+        /* @var \ElggMenuItem[] $configure_items */
522
+        foreach ($configure_items as $menu_item) {
523
+            if ($menu_item->getName() == 'settings') {
524
+                $settings = $menu_item;
525
+            }
526
+        }
527
+
528
+        if (!empty($settings) && $settings instanceof \ElggMenuItem) {
529
+            // keep the basic and advanced settings at the top
530
+            /* @var \ElggMenuItem $settings */
531
+            $children = $settings->getChildren();
532
+            $site_settings = array_splice($children, 0, 2);
533
+            usort($children, [\ElggMenuBuilder::class, 'compareByText']);
534
+            array_splice($children, 0, 0, $site_settings);
535
+            $settings->setChildren($children);
536
+        }
537
+    }
538 538
 }
539 539
 
540 540
 /**
@@ -546,57 +546,57 @@  discard block
 block discarded – undo
546 546
  * @access private
547 547
  */
548 548
 function _elgg_admin_page_handler($page) {
549
-	elgg_admin_gatekeeper();
550
-	_elgg_admin_add_plugin_settings_menu();
551
-	elgg_set_context('admin');
552
-
553
-	elgg_unregister_css('elgg');
554
-	elgg_require_js('elgg/admin');
555
-
556
-	elgg_load_js('jquery.jeditable');
557
-
558
-	// default to dashboard
559
-	if (!isset($page[0]) || empty($page[0])) {
560
-		$page = ['dashboard'];
561
-	}
562
-
563
-	// was going to fix this in the page_handler() function but
564
-	// it's commented to explicitly return a string if there's a trailing /
565
-	if (empty($page[count($page) - 1])) {
566
-		array_pop($page);
567
-	}
568
-
569
-	$vars = ['page' => $page];
570
-
571
-	// special page for plugin settings since we create the form for them
572
-	if ($page[0] == 'plugin_settings') {
573
-		if (isset($page[1]) && (elgg_view_exists("settings/{$page[1]}/edit") ||
574
-				elgg_view_exists("plugins/{$page[1]}/settings"))) {
575
-			$view = 'admin/plugin_settings';
576
-			$plugin = elgg_get_plugin_from_id($page[1]);
577
-			$vars['plugin'] = $plugin;
578
-
579
-			$title = elgg_echo("admin:{$page[0]}");
580
-		} else {
581
-			forward('', '404');
582
-		}
583
-	} else {
584
-		$view = 'admin/' . implode('/', $page);
585
-		$title = elgg_echo("admin:{$page[0]}");
586
-		if (count($page) > 1) {
587
-			$title .= ' : ' . elgg_echo('admin:' .  implode(':', $page));
588
-		}
589
-	}
590
-
591
-	// gets content and prevents direct access to 'components' views
592
-	if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) {
593
-		$title = elgg_echo('admin:unknown_section');
594
-		$content = elgg_echo('admin:unknown_section');
595
-	}
596
-
597
-	$body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]);
598
-	echo elgg_view_page($title, $body, 'admin');
599
-	return true;
549
+    elgg_admin_gatekeeper();
550
+    _elgg_admin_add_plugin_settings_menu();
551
+    elgg_set_context('admin');
552
+
553
+    elgg_unregister_css('elgg');
554
+    elgg_require_js('elgg/admin');
555
+
556
+    elgg_load_js('jquery.jeditable');
557
+
558
+    // default to dashboard
559
+    if (!isset($page[0]) || empty($page[0])) {
560
+        $page = ['dashboard'];
561
+    }
562
+
563
+    // was going to fix this in the page_handler() function but
564
+    // it's commented to explicitly return a string if there's a trailing /
565
+    if (empty($page[count($page) - 1])) {
566
+        array_pop($page);
567
+    }
568
+
569
+    $vars = ['page' => $page];
570
+
571
+    // special page for plugin settings since we create the form for them
572
+    if ($page[0] == 'plugin_settings') {
573
+        if (isset($page[1]) && (elgg_view_exists("settings/{$page[1]}/edit") ||
574
+                elgg_view_exists("plugins/{$page[1]}/settings"))) {
575
+            $view = 'admin/plugin_settings';
576
+            $plugin = elgg_get_plugin_from_id($page[1]);
577
+            $vars['plugin'] = $plugin;
578
+
579
+            $title = elgg_echo("admin:{$page[0]}");
580
+        } else {
581
+            forward('', '404');
582
+        }
583
+    } else {
584
+        $view = 'admin/' . implode('/', $page);
585
+        $title = elgg_echo("admin:{$page[0]}");
586
+        if (count($page) > 1) {
587
+            $title .= ' : ' . elgg_echo('admin:' .  implode(':', $page));
588
+        }
589
+    }
590
+
591
+    // gets content and prevents direct access to 'components' views
592
+    if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) {
593
+        $title = elgg_echo('admin:unknown_section');
594
+        $content = elgg_echo('admin:unknown_section');
595
+    }
596
+
597
+    $body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]);
598
+    echo elgg_view_page($title, $body, 'admin');
599
+    return true;
600 600
 }
601 601
 
602 602
 /**
@@ -616,13 +616,13 @@  discard block
 block discarded – undo
616 616
  * @access private
617 617
  */
618 618
 function _elgg_admin_markdown_page_handler($pages) {
619
-	elgg_set_context('admin');
619
+    elgg_set_context('admin');
620 620
 
621
-	echo elgg_view_resource('admin/plugin_text_file', [
622
-		'plugin_id' => elgg_extract(0, $pages),
623
-		'filename' => elgg_extract(1, $pages),
624
-	]);
625
-	return true;
621
+    echo elgg_view_resource('admin/plugin_text_file', [
622
+        'plugin_id' => elgg_extract(0, $pages),
623
+        'filename' => elgg_extract(1, $pages),
624
+    ]);
625
+    return true;
626 626
 }
627 627
 
628 628
 /**
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
  * @access private
632 632
  */
633 633
 function _elgg_robots_page_handler() {
634
-	echo elgg_view_resource('robots.txt');
635
-	return true;
634
+    echo elgg_view_resource('robots.txt');
635
+    return true;
636 636
 }
637 637
 
638 638
 /**
@@ -644,20 +644,20 @@  discard block
 block discarded – undo
644 644
  * @access private
645 645
  */
646 646
 function _elgg_admin_maintenance_allow_url($current_url) {
647
-	$site_path = preg_replace('~^https?~', '', elgg_get_site_url());
648
-	$current_path = preg_replace('~^https?~', '', $current_url);
649
-	if (0 === strpos($current_path, $site_path)) {
650
-		$current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path));
651
-	} else {
652
-		$current_path = false;
653
-	}
654
-
655
-	// allow plugins to control access for specific URLs/paths
656
-	$params = [
657
-		'current_path' => $current_path,
658
-		'current_url' => $current_url,
659
-	];
660
-	return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false);
647
+    $site_path = preg_replace('~^https?~', '', elgg_get_site_url());
648
+    $current_path = preg_replace('~^https?~', '', $current_url);
649
+    if (0 === strpos($current_path, $site_path)) {
650
+        $current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path));
651
+    } else {
652
+        $current_path = false;
653
+    }
654
+
655
+    // allow plugins to control access for specific URLs/paths
656
+    $params = [
657
+        'current_path' => $current_path,
658
+        'current_url' => $current_url,
659
+    ];
660
+    return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false);
661 661
 }
662 662
 
663 663
 /**
@@ -666,23 +666,23 @@  discard block
 block discarded – undo
666 666
  * @access private
667 667
  */
668 668
 function _elgg_admin_maintenance_handler($hook, $type, $info) {
669
-	if (elgg_is_admin_logged_in()) {
670
-		return;
671
-	}
669
+    if (elgg_is_admin_logged_in()) {
670
+        return;
671
+    }
672 672
 
673
-	if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') {
674
-		return;
675
-	}
673
+    if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') {
674
+        return;
675
+    }
676 676
 
677
-	if (_elgg_admin_maintenance_allow_url(current_page_url())) {
678
-		return;
679
-	}
677
+    if (_elgg_admin_maintenance_allow_url(current_page_url())) {
678
+        return;
679
+    }
680 680
 
681
-	elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup');
681
+    elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup');
682 682
 
683
-	echo elgg_view_resource('maintenance');
683
+    echo elgg_view_resource('maintenance');
684 684
 
685
-	return false;
685
+    return false;
686 686
 }
687 687
 
688 688
 /**
@@ -695,34 +695,34 @@  discard block
 block discarded – undo
695 695
  * @return bool
696 696
  */
697 697
 function _elgg_admin_maintenance_action_check($hook, $type) {
698
-	if (elgg_is_admin_logged_in()) {
699
-		return true;
700
-	}
698
+    if (elgg_is_admin_logged_in()) {
699
+        return true;
700
+    }
701 701
 
702
-	if ($type == 'login') {
703
-		$username = get_input('username');
702
+    if ($type == 'login') {
703
+        $username = get_input('username');
704 704
 
705
-		$user = get_user_by_username($username);
705
+        $user = get_user_by_username($username);
706 706
 
707
-		if (!$user) {
708
-			$users = get_user_by_email($username);
709
-			if ($users) {
710
-				$user = $users[0];
711
-			}
712
-		}
707
+        if (!$user) {
708
+            $users = get_user_by_email($username);
709
+            if ($users) {
710
+                $user = $users[0];
711
+            }
712
+        }
713 713
 
714
-		if ($user && $user->isAdmin()) {
715
-			return true;
716
-		}
717
-	}
714
+        if ($user && $user->isAdmin()) {
715
+            return true;
716
+        }
717
+    }
718 718
 
719
-	if (_elgg_admin_maintenance_allow_url(current_page_url())) {
720
-		return true;
721
-	}
719
+    if (_elgg_admin_maintenance_allow_url(current_page_url())) {
720
+        return true;
721
+    }
722 722
 
723
-	register_error(elgg_echo('actionunauthorized'));
723
+    register_error(elgg_echo('actionunauthorized'));
724 724
 
725
-	return false;
725
+    return false;
726 726
 }
727 727
 
728 728
 /**
@@ -736,30 +736,30 @@  discard block
 block discarded – undo
736 736
  * @access private
737 737
  */
738 738
 function _elgg_add_admin_widgets($event, $type, $user) {
739
-	elgg_set_ignore_access(true);
740
-
741
-	// check if the user already has widgets
742
-	if (elgg_get_widgets($user->getGUID(), 'admin')) {
743
-		return true;
744
-	}
745
-
746
-	// In the form column => array of handlers in order, top to bottom
747
-	$adminWidgets = [
748
-		1 => ['control_panel', 'admin_welcome'],
749
-		2 => ['online_users', 'new_users', 'content_stats'],
750
-	];
751
-
752
-	foreach ($adminWidgets as $column => $handlers) {
753
-		foreach ($handlers as $position => $handler) {
754
-			$guid = elgg_create_widget($user->getGUID(), $handler, 'admin');
755
-			if ($guid) {
756
-				$widget = get_entity($guid);
757
-				/* @var \ElggWidget $widget */
758
-				$widget->move($column, $position);
759
-			}
760
-		}
761
-	}
762
-	elgg_set_ignore_access(false);
739
+    elgg_set_ignore_access(true);
740
+
741
+    // check if the user already has widgets
742
+    if (elgg_get_widgets($user->getGUID(), 'admin')) {
743
+        return true;
744
+    }
745
+
746
+    // In the form column => array of handlers in order, top to bottom
747
+    $adminWidgets = [
748
+        1 => ['control_panel', 'admin_welcome'],
749
+        2 => ['online_users', 'new_users', 'content_stats'],
750
+    ];
751
+
752
+    foreach ($adminWidgets as $column => $handlers) {
753
+        foreach ($handlers as $position => $handler) {
754
+            $guid = elgg_create_widget($user->getGUID(), $handler, 'admin');
755
+            if ($guid) {
756
+                $widget = get_entity($guid);
757
+                /* @var \ElggWidget $widget */
758
+                $widget->move($column, $position);
759
+            }
760
+        }
761
+    }
762
+    elgg_set_ignore_access(false);
763 763
 }
764 764
 
765 765
 /**
@@ -774,39 +774,39 @@  discard block
 block discarded – undo
774 774
  */
775 775
 function _elgg_admin_get_admin_subscribers_admin_action($hook, $type, $return_value, $params) {
776 776
 	
777
-	if (!elgg_get_config('security_notify_admins')) {
778
-		return;
779
-	}
777
+    if (!elgg_get_config('security_notify_admins')) {
778
+        return;
779
+    }
780 780
 	
781
-	$event = elgg_extract('event', $params);
782
-	if (!($event instanceof \Elgg\Notifications\Event)) {
783
-		return;
784
-	}
781
+    $event = elgg_extract('event', $params);
782
+    if (!($event instanceof \Elgg\Notifications\Event)) {
783
+        return;
784
+    }
785 785
 	
786
-	if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) {
787
-		return;
788
-	}
786
+    if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) {
787
+        return;
788
+    }
789 789
 	
790
-	$user = $event->getObject();
791
-	if (!($user instanceof \ElggUser)) {
792
-		return;
793
-	}
790
+    $user = $event->getObject();
791
+    if (!($user instanceof \ElggUser)) {
792
+        return;
793
+    }
794 794
 	
795
-	/* @var $admin_batch \Elgg\BatchResult */
796
-	$admin_batch = elgg_get_admins([
797
-		'limit' => false,
798
-		'wheres' => [
799
-			"e.guid <> {$user->getGUID()}",
800
-		],
801
-		'batch' => true,
802
-	]);
795
+    /* @var $admin_batch \Elgg\BatchResult */
796
+    $admin_batch = elgg_get_admins([
797
+        'limit' => false,
798
+        'wheres' => [
799
+            "e.guid <> {$user->getGUID()}",
800
+        ],
801
+        'batch' => true,
802
+    ]);
803 803
 	
804
-	/* @var $admin \ElggUser */
805
-	foreach ($admin_batch as $admin) {
806
-		$return_value[$admin->getGUID()] = ['email'];
807
-	}
804
+    /* @var $admin \ElggUser */
805
+    foreach ($admin_batch as $admin) {
806
+        $return_value[$admin->getGUID()] = ['email'];
807
+    }
808 808
 	
809
-	return $return_value;
809
+    return $return_value;
810 810
 }
811 811
 
812 812
 /**
@@ -821,39 +821,39 @@  discard block
 block discarded – undo
821 821
  */
822 822
 function _elgg_admin_prepare_admin_notification_make_admin($hook, $type, $return_value, $params) {
823 823
 	
824
-	if (!($return_value instanceof \Elgg\Notifications\Notification)) {
825
-		return;
826
-	}
824
+    if (!($return_value instanceof \Elgg\Notifications\Notification)) {
825
+        return;
826
+    }
827 827
 	
828
-	$recipient = elgg_extract('recipient', $params);
829
-	$object = elgg_extract('object', $params);
830
-	$actor = elgg_extract('sender', $params);
831
-	$language = elgg_extract('language', $params);
828
+    $recipient = elgg_extract('recipient', $params);
829
+    $object = elgg_extract('object', $params);
830
+    $actor = elgg_extract('sender', $params);
831
+    $language = elgg_extract('language', $params);
832 832
 	
833
-	if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
834
-		return;
835
-	}
833
+    if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
834
+        return;
835
+    }
836 836
 	
837
-	if ($recipient->getGUID() === $object->getGUID()) {
838
-		// recipient is the user being acted on, this is handled elsewhere
839
-		return;
840
-	}
837
+    if ($recipient->getGUID() === $object->getGUID()) {
838
+        // recipient is the user being acted on, this is handled elsewhere
839
+        return;
840
+    }
841 841
 	
842
-	$site = elgg_get_site_entity();
842
+    $site = elgg_get_site_entity();
843 843
 	
844
-	$return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language);
845
-	$return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [
846
-		$recipient->name,
847
-		$actor->name,
848
-		$object->name,
849
-		$site->name,
850
-		$object->getURL(),
851
-		$site->getURL(),
852
-	], $language);
853
-
854
-	$return_value->url = elgg_normalize_url('admin/users/admins');
844
+    $return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language);
845
+    $return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [
846
+        $recipient->name,
847
+        $actor->name,
848
+        $object->name,
849
+        $site->name,
850
+        $object->getURL(),
851
+        $site->getURL(),
852
+    ], $language);
853
+
854
+    $return_value->url = elgg_normalize_url('admin/users/admins');
855 855
 	
856
-	return $return_value;
856
+    return $return_value;
857 857
 }
858 858
 
859 859
 /**
@@ -868,39 +868,39 @@  discard block
 block discarded – undo
868 868
  */
869 869
 function _elgg_admin_prepare_admin_notification_remove_admin($hook, $type, $return_value, $params) {
870 870
 	
871
-	if (!($return_value instanceof \Elgg\Notifications\Notification)) {
872
-		return;
873
-	}
871
+    if (!($return_value instanceof \Elgg\Notifications\Notification)) {
872
+        return;
873
+    }
874 874
 	
875
-	$recipient = elgg_extract('recipient', $params);
876
-	$object = elgg_extract('object', $params);
877
-	$actor = elgg_extract('sender', $params);
878
-	$language = elgg_extract('language', $params);
875
+    $recipient = elgg_extract('recipient', $params);
876
+    $object = elgg_extract('object', $params);
877
+    $actor = elgg_extract('sender', $params);
878
+    $language = elgg_extract('language', $params);
879 879
 	
880
-	if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
881
-		return;
882
-	}
880
+    if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
881
+        return;
882
+    }
883 883
 	
884
-	if ($recipient->getGUID() === $object->getGUID()) {
885
-		// recipient is the user being acted on, this is handled elsewhere
886
-		return;
887
-	}
884
+    if ($recipient->getGUID() === $object->getGUID()) {
885
+        // recipient is the user being acted on, this is handled elsewhere
886
+        return;
887
+    }
888 888
 	
889
-	$site = elgg_get_site_entity();
889
+    $site = elgg_get_site_entity();
890 890
 	
891
-	$return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language);
892
-	$return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [
893
-		$recipient->name,
894
-		$actor->name,
895
-		$object->name,
896
-		$site->name,
897
-		$object->getURL(),
898
-		$site->getURL(),
899
-	], $language);
900
-
901
-	$return_value->url = elgg_normalize_url('admin/users/admins');
891
+    $return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language);
892
+    $return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [
893
+        $recipient->name,
894
+        $actor->name,
895
+        $object->name,
896
+        $site->name,
897
+        $object->getURL(),
898
+        $site->getURL(),
899
+    ], $language);
900
+
901
+    $return_value->url = elgg_normalize_url('admin/users/admins');
902 902
 	
903
-	return $return_value;
903
+    return $return_value;
904 904
 }
905 905
 
906 906
 /**
@@ -915,27 +915,27 @@  discard block
 block discarded – undo
915 915
  */
916 916
 function _elgg_admin_get_user_subscriber_admin_action($hook, $type, $return_value, $params) {
917 917
 	
918
-	if (!elgg_get_config('security_notify_user_admin')) {
919
-		return;
920
-	}
918
+    if (!elgg_get_config('security_notify_user_admin')) {
919
+        return;
920
+    }
921 921
 	
922
-	$event = elgg_extract('event', $params);
923
-	if (!($event instanceof \Elgg\Notifications\Event)) {
924
-		return;
925
-	}
922
+    $event = elgg_extract('event', $params);
923
+    if (!($event instanceof \Elgg\Notifications\Event)) {
924
+        return;
925
+    }
926 926
 	
927
-	if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) {
928
-		return;
929
-	}
927
+    if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) {
928
+        return;
929
+    }
930 930
 	
931
-	$user = $event->getObject();
932
-	if (!($user instanceof \ElggUser)) {
933
-		return;
934
-	}
931
+    $user = $event->getObject();
932
+    if (!($user instanceof \ElggUser)) {
933
+        return;
934
+    }
935 935
 	
936
-	$return_value[$user->getGUID()] = ['email'];
936
+    $return_value[$user->getGUID()] = ['email'];
937 937
 	
938
-	return $return_value;
938
+    return $return_value;
939 939
 }
940 940
 
941 941
 /**
@@ -950,37 +950,37 @@  discard block
 block discarded – undo
950 950
  */
951 951
 function _elgg_admin_prepare_user_notification_make_admin($hook, $type, $return_value, $params) {
952 952
 	
953
-	if (!($return_value instanceof \Elgg\Notifications\Notification)) {
954
-		return;
955
-	}
953
+    if (!($return_value instanceof \Elgg\Notifications\Notification)) {
954
+        return;
955
+    }
956 956
 	
957
-	$recipient = elgg_extract('recipient', $params);
958
-	$object = elgg_extract('object', $params);
959
-	$actor = elgg_extract('sender', $params);
960
-	$language = elgg_extract('language', $params);
957
+    $recipient = elgg_extract('recipient', $params);
958
+    $object = elgg_extract('object', $params);
959
+    $actor = elgg_extract('sender', $params);
960
+    $language = elgg_extract('language', $params);
961 961
 	
962
-	if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
963
-		return;
964
-	}
962
+    if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
963
+        return;
964
+    }
965 965
 	
966
-	if ($recipient->getGUID() !== $object->getGUID()) {
967
-		// recipient is some other user, this is handled elsewhere
968
-		return;
969
-	}
966
+    if ($recipient->getGUID() !== $object->getGUID()) {
967
+        // recipient is some other user, this is handled elsewhere
968
+        return;
969
+    }
970 970
 	
971
-	$site = elgg_get_site_entity();
971
+    $site = elgg_get_site_entity();
972 972
 	
973
-	$return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language);
974
-	$return_value->body = elgg_echo('admin:notification:make_admin:user:body', [
975
-		$recipient->name,
976
-		$actor->name,
977
-		$site->name,
978
-		$site->getURL(),
979
-	], $language);
980
-
981
-	$return_value->url = elgg_normalize_url('admin');
973
+    $return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language);
974
+    $return_value->body = elgg_echo('admin:notification:make_admin:user:body', [
975
+        $recipient->name,
976
+        $actor->name,
977
+        $site->name,
978
+        $site->getURL(),
979
+    ], $language);
980
+
981
+    $return_value->url = elgg_normalize_url('admin');
982 982
 	
983
-	return $return_value;
983
+    return $return_value;
984 984
 }
985 985
 
986 986
 /**
@@ -995,39 +995,39 @@  discard block
 block discarded – undo
995 995
  */
996 996
 function _elgg_admin_prepare_user_notification_remove_admin($hook, $type, $return_value, $params) {
997 997
 	
998
-	if (!($return_value instanceof \Elgg\Notifications\Notification)) {
999
-		return;
1000
-	}
998
+    if (!($return_value instanceof \Elgg\Notifications\Notification)) {
999
+        return;
1000
+    }
1001 1001
 	
1002
-	$recipient = elgg_extract('recipient', $params);
1003
-	$object = elgg_extract('object', $params);
1004
-	$actor = elgg_extract('sender', $params);
1005
-	$language = elgg_extract('language', $params);
1002
+    $recipient = elgg_extract('recipient', $params);
1003
+    $object = elgg_extract('object', $params);
1004
+    $actor = elgg_extract('sender', $params);
1005
+    $language = elgg_extract('language', $params);
1006 1006
 	
1007
-	if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
1008
-		return;
1009
-	}
1007
+    if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) {
1008
+        return;
1009
+    }
1010 1010
 	
1011
-	if ($recipient->getGUID() !== $object->getGUID()) {
1012
-		// recipient is some other user, this is handled elsewhere
1013
-		return;
1014
-	}
1011
+    if ($recipient->getGUID() !== $object->getGUID()) {
1012
+        // recipient is some other user, this is handled elsewhere
1013
+        return;
1014
+    }
1015 1015
 	
1016
-	$site = elgg_get_site_entity();
1016
+    $site = elgg_get_site_entity();
1017 1017
 	
1018
-	$return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language);
1019
-	$return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [
1020
-		$recipient->name,
1021
-		$actor->name,
1022
-		$site->name,
1023
-		$site->getURL(),
1024
-	], $language);
1025
-
1026
-	$return_value->url = false;
1018
+    $return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language);
1019
+    $return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [
1020
+        $recipient->name,
1021
+        $actor->name,
1022
+        $site->name,
1023
+        $site->getURL(),
1024
+    ], $language);
1025
+
1026
+    $return_value->url = false;
1027 1027
 	
1028
-	return $return_value;
1028
+    return $return_value;
1029 1029
 }
1030 1030
 
1031 1031
 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
1032
-	$events->registerHandler('init', 'system', '_elgg_admin_init');
1032
+    $events->registerHandler('init', 'system', '_elgg_admin_init');
1033 1033
 };
Please login to merge, or discard this patch.