@@ -33,7 +33,7 @@ |
||
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'); |
@@ -12,439 +12,439 @@ |
||
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 | } |
@@ -105,6 +105,7 @@ |
||
105 | 105 | |
106 | 106 | /** |
107 | 107 | * {@inheritdoc} |
108 | + * @return string |
|
108 | 109 | */ |
109 | 110 | public function getClientIp() { |
110 | 111 | $ip = parent::getClientIp(); |
@@ -2,7 +2,6 @@ |
||
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. |
@@ -11,166 +11,166 @@ |
||
11 | 11 | */ |
12 | 12 | class Request extends SymfonyRequest { |
13 | 13 | |
14 | - const REWRITE_TEST_TOKEN = '__testing_rewrite'; |
|
15 | - const REWRITE_TEST_OUTPUT = 'success'; |
|
16 | - |
|
17 | - /** |
|
18 | - * Get the Elgg URL segments |
|
19 | - * |
|
20 | - * @param bool $raw If true, the segments will not be HTML escaped |
|
21 | - * |
|
22 | - * @return string[] |
|
23 | - */ |
|
24 | - public function getUrlSegments($raw = false) { |
|
25 | - $path = trim($this->getElggPath(), '/'); |
|
26 | - if (!$raw) { |
|
27 | - $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8'); |
|
28 | - } |
|
29 | - if (!$path) { |
|
30 | - return []; |
|
31 | - } |
|
32 | - |
|
33 | - return explode('/', $path); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Get a cloned request with new Elgg URL segments |
|
38 | - * |
|
39 | - * @param string[] $segments URL segments |
|
40 | - * |
|
41 | - * @return Request |
|
42 | - */ |
|
43 | - public function setUrlSegments(array $segments) { |
|
44 | - $base_path = trim($this->getBasePath(), '/'); |
|
45 | - $server = $this->server->all(); |
|
46 | - $server['REQUEST_URI'] = "$base_path/" . implode('/', $segments); |
|
47 | - |
|
48 | - return $this->duplicate(null, null, null, null, null, $server); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Get first Elgg URL segment |
|
53 | - * |
|
54 | - * @see \Elgg\Http\Request::getUrlSegments() |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getFirstUrlSegment() { |
|
59 | - $segments = $this->getUrlSegments(); |
|
60 | - if ($segments) { |
|
61 | - return array_shift($segments); |
|
62 | - } else { |
|
63 | - return ''; |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Get the Request URI minus querystring |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getElggPath() { |
|
73 | - if (php_sapi_name() === 'cli-server') { |
|
74 | - $path = $this->getRequestUri(); |
|
75 | - } else { |
|
76 | - $path = $this->getPathInfo(); |
|
77 | - } |
|
78 | - return preg_replace('~(\?.*)$~', '', $path); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function getClientIp() { |
|
85 | - $ip = parent::getClientIp(); |
|
86 | - |
|
87 | - if ($ip == $this->server->get('REMOTE_ADDR')) { |
|
88 | - // try one more |
|
89 | - $ip_addresses = $this->server->get('HTTP_X_REAL_IP'); |
|
90 | - if ($ip_addresses) { |
|
91 | - $ip_addresses = explode(',', $ip_addresses); |
|
92 | - return array_pop($ip_addresses); |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return $ip; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * {@inheritdoc} |
|
101 | - */ |
|
102 | - public function isXmlHttpRequest() { |
|
103 | - return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest' |
|
104 | - || $this->query->get('X-Requested-With') === 'XMLHttpRequest' |
|
105 | - || $this->request->get('X-Requested-With') === 'XMLHttpRequest'); |
|
106 | - // GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735 |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Sniff the Elgg site URL with trailing slash |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function sniffElggUrl() { |
|
115 | - $base_url = $this->getBaseUrl(); |
|
116 | - |
|
117 | - // baseURL may end with the PHP script |
|
118 | - if ('.php' === substr($base_url, -4)) { |
|
119 | - $base_url = dirname($base_url); |
|
120 | - } |
|
121 | - |
|
122 | - return rtrim($this->getSchemeAndHttpHost() . $base_url, '/') . '/'; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Is the request for checking URL rewriting? |
|
127 | - * |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - public function isRewriteCheck() { |
|
131 | - if ($this->getPathInfo() !== ('/' . self::REWRITE_TEST_TOKEN)) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - |
|
135 | - if (!$this->get(self::REWRITE_TEST_TOKEN)) { |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - return true; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Is PHP running the CLI server front controller |
|
144 | - * |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function isCliServer() { |
|
148 | - return php_sapi_name() === 'cli-server'; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Is the request pointing to a file that the CLI server can handle? |
|
153 | - * |
|
154 | - * @param string $root Root directory |
|
155 | - * |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - public function isCliServable($root) { |
|
159 | - $file = rtrim($root, '\\/') . $this->getElggPath(); |
|
160 | - if (!is_file($file)) { |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - // http://php.net/manual/en/features.commandline.webserver.php |
|
165 | - $extensions = ".3gp, .apk, .avi, .bmp, .css, .csv, .doc, .docx, .flac, .gif, .gz, .gzip, .htm, .html, .ics, .jpe, .jpeg, .jpg, .js, .kml, .kmz, .m4a, .mov, .mp3, .mp4, .mpeg, .mpg, .odp, .ods, .odt, .oga, .ogg, .ogv, .pdf, .pdf, .png, .pps, .pptx, .qt, .svg, .swf, .tar, .text, .tif, .txt, .wav, .webm, .wmv, .xls, .xlsx, .xml, .xsl, .xsd, and .zip"; |
|
166 | - |
|
167 | - // The CLI server routes ALL requests here (even existing files), so we have to check for these. |
|
168 | - $ext = pathinfo($file, PATHINFO_EXTENSION); |
|
169 | - if (!$ext) { |
|
170 | - return false; |
|
171 | - } |
|
172 | - |
|
173 | - $ext = preg_quote($ext, '~'); |
|
174 | - return (bool) preg_match("~\\.{$ext}[,$]~", $extensions); |
|
175 | - } |
|
14 | + const REWRITE_TEST_TOKEN = '__testing_rewrite'; |
|
15 | + const REWRITE_TEST_OUTPUT = 'success'; |
|
16 | + |
|
17 | + /** |
|
18 | + * Get the Elgg URL segments |
|
19 | + * |
|
20 | + * @param bool $raw If true, the segments will not be HTML escaped |
|
21 | + * |
|
22 | + * @return string[] |
|
23 | + */ |
|
24 | + public function getUrlSegments($raw = false) { |
|
25 | + $path = trim($this->getElggPath(), '/'); |
|
26 | + if (!$raw) { |
|
27 | + $path = htmlspecialchars($path, ENT_QUOTES, 'UTF-8'); |
|
28 | + } |
|
29 | + if (!$path) { |
|
30 | + return []; |
|
31 | + } |
|
32 | + |
|
33 | + return explode('/', $path); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Get a cloned request with new Elgg URL segments |
|
38 | + * |
|
39 | + * @param string[] $segments URL segments |
|
40 | + * |
|
41 | + * @return Request |
|
42 | + */ |
|
43 | + public function setUrlSegments(array $segments) { |
|
44 | + $base_path = trim($this->getBasePath(), '/'); |
|
45 | + $server = $this->server->all(); |
|
46 | + $server['REQUEST_URI'] = "$base_path/" . implode('/', $segments); |
|
47 | + |
|
48 | + return $this->duplicate(null, null, null, null, null, $server); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Get first Elgg URL segment |
|
53 | + * |
|
54 | + * @see \Elgg\Http\Request::getUrlSegments() |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getFirstUrlSegment() { |
|
59 | + $segments = $this->getUrlSegments(); |
|
60 | + if ($segments) { |
|
61 | + return array_shift($segments); |
|
62 | + } else { |
|
63 | + return ''; |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Get the Request URI minus querystring |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getElggPath() { |
|
73 | + if (php_sapi_name() === 'cli-server') { |
|
74 | + $path = $this->getRequestUri(); |
|
75 | + } else { |
|
76 | + $path = $this->getPathInfo(); |
|
77 | + } |
|
78 | + return preg_replace('~(\?.*)$~', '', $path); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function getClientIp() { |
|
85 | + $ip = parent::getClientIp(); |
|
86 | + |
|
87 | + if ($ip == $this->server->get('REMOTE_ADDR')) { |
|
88 | + // try one more |
|
89 | + $ip_addresses = $this->server->get('HTTP_X_REAL_IP'); |
|
90 | + if ($ip_addresses) { |
|
91 | + $ip_addresses = explode(',', $ip_addresses); |
|
92 | + return array_pop($ip_addresses); |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return $ip; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * {@inheritdoc} |
|
101 | + */ |
|
102 | + public function isXmlHttpRequest() { |
|
103 | + return (strtolower($this->headers->get('X-Requested-With')) === 'xmlhttprequest' |
|
104 | + || $this->query->get('X-Requested-With') === 'XMLHttpRequest' |
|
105 | + || $this->request->get('X-Requested-With') === 'XMLHttpRequest'); |
|
106 | + // GET/POST check is necessary for jQuery.form and other iframe-based "ajax". #8735 |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Sniff the Elgg site URL with trailing slash |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function sniffElggUrl() { |
|
115 | + $base_url = $this->getBaseUrl(); |
|
116 | + |
|
117 | + // baseURL may end with the PHP script |
|
118 | + if ('.php' === substr($base_url, -4)) { |
|
119 | + $base_url = dirname($base_url); |
|
120 | + } |
|
121 | + |
|
122 | + return rtrim($this->getSchemeAndHttpHost() . $base_url, '/') . '/'; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Is the request for checking URL rewriting? |
|
127 | + * |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + public function isRewriteCheck() { |
|
131 | + if ($this->getPathInfo() !== ('/' . self::REWRITE_TEST_TOKEN)) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + |
|
135 | + if (!$this->get(self::REWRITE_TEST_TOKEN)) { |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + return true; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Is PHP running the CLI server front controller |
|
144 | + * |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function isCliServer() { |
|
148 | + return php_sapi_name() === 'cli-server'; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Is the request pointing to a file that the CLI server can handle? |
|
153 | + * |
|
154 | + * @param string $root Root directory |
|
155 | + * |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + public function isCliServable($root) { |
|
159 | + $file = rtrim($root, '\\/') . $this->getElggPath(); |
|
160 | + if (!is_file($file)) { |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + // http://php.net/manual/en/features.commandline.webserver.php |
|
165 | + $extensions = ".3gp, .apk, .avi, .bmp, .css, .csv, .doc, .docx, .flac, .gif, .gz, .gzip, .htm, .html, .ics, .jpe, .jpeg, .jpg, .js, .kml, .kmz, .m4a, .mov, .mp3, .mp4, .mpeg, .mpg, .odp, .ods, .odt, .oga, .ogg, .ogv, .pdf, .pdf, .png, .pps, .pptx, .qt, .svg, .swf, .tar, .text, .tif, .txt, .wav, .webm, .wmv, .xls, .xlsx, .xml, .xsl, .xsd, and .zip"; |
|
166 | + |
|
167 | + // The CLI server routes ALL requests here (even existing files), so we have to check for these. |
|
168 | + $ext = pathinfo($file, PATHINFO_EXTENSION); |
|
169 | + if (!$ext) { |
|
170 | + return false; |
|
171 | + } |
|
172 | + |
|
173 | + $ext = preg_quote($ext, '~'); |
|
174 | + return (bool) preg_match("~\\.{$ext}[,$]~", $extensions); |
|
175 | + } |
|
176 | 176 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public function setUrlSegments(array $segments) { |
44 | 44 | $base_path = trim($this->getBasePath(), '/'); |
45 | 45 | $server = $this->server->all(); |
46 | - $server['REQUEST_URI'] = "$base_path/" . implode('/', $segments); |
|
46 | + $server['REQUEST_URI'] = "$base_path/".implode('/', $segments); |
|
47 | 47 | |
48 | 48 | return $this->duplicate(null, null, null, null, null, $server); |
49 | 49 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $base_url = dirname($base_url); |
120 | 120 | } |
121 | 121 | |
122 | - return rtrim($this->getSchemeAndHttpHost() . $base_url, '/') . '/'; |
|
122 | + return rtrim($this->getSchemeAndHttpHost().$base_url, '/').'/'; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return bool |
129 | 129 | */ |
130 | 130 | public function isRewriteCheck() { |
131 | - if ($this->getPathInfo() !== ('/' . self::REWRITE_TEST_TOKEN)) { |
|
131 | + if ($this->getPathInfo() !== ('/'.self::REWRITE_TEST_TOKEN)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @return bool |
157 | 157 | */ |
158 | 158 | public function isCliServable($root) { |
159 | - $file = rtrim($root, '\\/') . $this->getElggPath(); |
|
159 | + $file = rtrim($root, '\\/').$this->getElggPath(); |
|
160 | 160 | if (!is_file($file)) { |
161 | 161 | return false; |
162 | 162 | } |
@@ -174,7 +174,7 @@ |
||
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. |
@@ -450,7 +450,7 @@ |
||
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 = array_merge($this->options, ['count' => true]); |
@@ -72,389 +72,389 @@ |
||
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_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 = array_merge($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_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 = array_merge($this->options, ['count' => true]); |
|
457 | + |
|
458 | + return call_user_func($this->getter, $options); |
|
459 | + } |
|
460 | 460 | } |
@@ -285,7 +285,7 @@ |
||
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); |
@@ -7,220 +7,220 @@ |
||
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 | } |
@@ -7,8 +7,8 @@ |
||
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 |
@@ -142,7 +142,7 @@ discard block |
||
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 |
||
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'); |
@@ -187,7 +187,7 @@ |
||
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 { |
@@ -17,712 +17,712 @@ |
||
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 | - 'invitefriends', |
|
402 | - 'legacy_urls', |
|
403 | - 'likes', |
|
404 | - 'logbrowser', |
|
405 | - 'login_as', |
|
406 | - 'logrotate', |
|
407 | - 'members', |
|
408 | - 'messageboard', |
|
409 | - 'messages', |
|
410 | - 'notifications', |
|
411 | - 'pages', |
|
412 | - 'profile', |
|
413 | - 'reportedcontent', |
|
414 | - 'search', |
|
415 | - 'site_notifications', |
|
416 | - 'tagcloud', |
|
417 | - 'thewire', |
|
418 | - 'uservalidationbyemail', |
|
419 | - 'web_services', |
|
420 | - ]; |
|
421 | - |
|
422 | - $cats = $this->parser->getAttribute('category'); |
|
423 | - |
|
424 | - if (!$cats) { |
|
425 | - $cats = []; |
|
426 | - } |
|
427 | - |
|
428 | - if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) { |
|
429 | - unset($cats[array_search('bundled', $cats)]); |
|
430 | - } |
|
431 | - |
|
432 | - return $cats; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Return the screenshots listed. |
|
437 | - * |
|
438 | - * @return array |
|
439 | - */ |
|
440 | - public function getScreenshots() { |
|
441 | - $ss = $this->parser->getAttribute('screenshot'); |
|
442 | - |
|
443 | - if (!$ss) { |
|
444 | - $ss = []; |
|
445 | - } |
|
446 | - |
|
447 | - $normalized = []; |
|
448 | - foreach ($ss as $s) { |
|
449 | - $normalized[] = $this->buildStruct($this->screenshotStruct, $s); |
|
450 | - } |
|
451 | - |
|
452 | - return $normalized; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Return the contributors listed. |
|
457 | - * |
|
458 | - * @return array |
|
459 | - */ |
|
460 | - public function getContributors() { |
|
461 | - $ss = $this->parser->getAttribute('contributor'); |
|
462 | - |
|
463 | - if (!$ss) { |
|
464 | - $ss = []; |
|
465 | - } |
|
466 | - |
|
467 | - $normalized = []; |
|
468 | - foreach ($ss as $s) { |
|
469 | - $normalized[] = $this->buildStruct($this->contributorStruct, $s); |
|
470 | - } |
|
471 | - |
|
472 | - return $normalized; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Return the list of provides by this plugin. |
|
477 | - * |
|
478 | - * @return array |
|
479 | - */ |
|
480 | - public function getProvides() { |
|
481 | - // normalize for 1.7 |
|
482 | - if ($this->getApiVersion() < 1.8) { |
|
483 | - $provides = []; |
|
484 | - } else { |
|
485 | - $provides = $this->parser->getAttribute('provides'); |
|
486 | - } |
|
487 | - |
|
488 | - if (!$provides) { |
|
489 | - $provides = []; |
|
490 | - } |
|
491 | - |
|
492 | - // always provide ourself if we can |
|
493 | - if ($this->pluginID) { |
|
494 | - $provides[] = [ |
|
495 | - 'type' => 'plugin', |
|
496 | - 'name' => $this->getPluginID(), |
|
497 | - 'version' => $this->getVersion() |
|
498 | - ]; |
|
499 | - } |
|
500 | - |
|
501 | - $normalized = []; |
|
502 | - foreach ($provides as $provide) { |
|
503 | - $normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide); |
|
504 | - } |
|
505 | - |
|
506 | - return $normalized; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Returns the dependencies listed. |
|
511 | - * |
|
512 | - * @return array |
|
513 | - */ |
|
514 | - public function getRequires() { |
|
515 | - $reqs = $this->parser->getAttribute('requires'); |
|
516 | - |
|
517 | - if (!$reqs) { |
|
518 | - $reqs = []; |
|
519 | - } |
|
520 | - |
|
521 | - $normalized = []; |
|
522 | - foreach ($reqs as $req) { |
|
523 | - $normalized[] = $this->normalizeDep($req); |
|
524 | - } |
|
525 | - |
|
526 | - return $normalized; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Returns the suggests elements. |
|
531 | - * |
|
532 | - * @return array |
|
533 | - */ |
|
534 | - public function getSuggests() { |
|
535 | - $suggests = $this->parser->getAttribute('suggests'); |
|
536 | - |
|
537 | - if (!$suggests) { |
|
538 | - $suggests = []; |
|
539 | - } |
|
540 | - |
|
541 | - $normalized = []; |
|
542 | - foreach ($suggests as $suggest) { |
|
543 | - $normalized[] = $this->normalizeDep($suggest); |
|
544 | - } |
|
545 | - |
|
546 | - return $normalized; |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * Normalizes a dependency array using the defined structs. |
|
551 | - * Can be used with either requires or suggests. |
|
552 | - * |
|
553 | - * @param array $dep A dependency array. |
|
554 | - * @return array The normalized deps array. |
|
555 | - */ |
|
556 | - private function normalizeDep($dep) { |
|
557 | - switch ($dep['type']) { |
|
558 | - case 'elgg_release': |
|
559 | - $struct = $this->depsStructElgg; |
|
560 | - break; |
|
561 | - |
|
562 | - case 'plugin': |
|
563 | - $struct = $this->depsStructPlugin; |
|
564 | - break; |
|
565 | - |
|
566 | - case 'priority': |
|
567 | - $struct = $this->depsStructPriority; |
|
568 | - break; |
|
569 | - |
|
570 | - case 'php_version': |
|
571 | - $struct = $this->depsStructPhpVersion; |
|
572 | - break; |
|
573 | - |
|
574 | - case 'php_extension': |
|
575 | - $struct = $this->depsStructPhpExtension; |
|
576 | - break; |
|
577 | - |
|
578 | - case 'php_ini': |
|
579 | - $struct = $this->depsStructPhpIni; |
|
580 | - |
|
581 | - // also normalize boolean values |
|
582 | - if (isset($dep['value'])) { |
|
583 | - switch (strtolower($dep['value'])) { |
|
584 | - case 'yes': |
|
585 | - case 'true': |
|
586 | - case 'on': |
|
587 | - case 1: |
|
588 | - $dep['value'] = 1; |
|
589 | - break; |
|
590 | - |
|
591 | - case 'no': |
|
592 | - case 'false': |
|
593 | - case 'off': |
|
594 | - case 0: |
|
595 | - case '': |
|
596 | - $dep['value'] = 0; |
|
597 | - break; |
|
598 | - } |
|
599 | - } |
|
600 | - break; |
|
601 | - default: |
|
602 | - // unrecognized so we just return the raw dependency |
|
603 | - return $dep; |
|
604 | - } |
|
605 | - |
|
606 | - // @todo $struct may not have been defined... |
|
607 | - $normalized_dep = $this->buildStruct($struct, $dep); |
|
608 | - |
|
609 | - // normalize comparison operators |
|
610 | - if (isset($normalized_dep['comparison'])) { |
|
611 | - switch ($normalized_dep['comparison']) { |
|
612 | - case '<': |
|
613 | - $normalized_dep['comparison'] = 'lt'; |
|
614 | - break; |
|
615 | - |
|
616 | - case '<=': |
|
617 | - $normalized_dep['comparison'] = 'le'; |
|
618 | - break; |
|
619 | - |
|
620 | - case '>': |
|
621 | - $normalized_dep['comparison'] = 'gt'; |
|
622 | - break; |
|
623 | - |
|
624 | - case '>=': |
|
625 | - $normalized_dep['comparison'] = 'ge'; |
|
626 | - break; |
|
627 | - |
|
628 | - case '==': |
|
629 | - case 'eq': |
|
630 | - $normalized_dep['comparison'] = '='; |
|
631 | - break; |
|
632 | - |
|
633 | - case '<>': |
|
634 | - case 'ne': |
|
635 | - $normalized_dep['comparison'] = '!='; |
|
636 | - break; |
|
637 | - } |
|
638 | - } |
|
639 | - |
|
640 | - return $normalized_dep; |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Returns the conflicts listed |
|
645 | - * |
|
646 | - * @return array |
|
647 | - */ |
|
648 | - public function getConflicts() { |
|
649 | - // normalize for 1.7 |
|
650 | - if ($this->getApiVersion() < 1.8) { |
|
651 | - $conflicts = []; |
|
652 | - } else { |
|
653 | - $conflicts = $this->parser->getAttribute('conflicts'); |
|
654 | - } |
|
655 | - |
|
656 | - if (!$conflicts) { |
|
657 | - $conflicts = []; |
|
658 | - } |
|
659 | - |
|
660 | - $normalized = []; |
|
661 | - |
|
662 | - foreach ($conflicts as $conflict) { |
|
663 | - $normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict); |
|
664 | - } |
|
665 | - |
|
666 | - return $normalized; |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Should this plugin be activated when Elgg is installed |
|
671 | - * |
|
672 | - * @return bool |
|
673 | - */ |
|
674 | - public function getActivateOnInstall() { |
|
675 | - $activate = $this->parser->getAttribute('activate_on_install'); |
|
676 | - switch (strtolower($activate)) { |
|
677 | - case 'yes': |
|
678 | - case 'true': |
|
679 | - case 'on': |
|
680 | - case 1: |
|
681 | - return true; |
|
682 | - |
|
683 | - case 'no': |
|
684 | - case 'false': |
|
685 | - case 'off': |
|
686 | - case 0: |
|
687 | - case '': |
|
688 | - return false; |
|
689 | - } |
|
690 | - } |
|
691 | - |
|
692 | - /** |
|
693 | - * Normalizes an array into the structure specified |
|
694 | - * |
|
695 | - * @param array $struct The struct to normalize $element to. |
|
696 | - * @param array $array The array |
|
697 | - * |
|
698 | - * @return array |
|
699 | - */ |
|
700 | - protected function buildStruct(array $struct, array $array) { |
|
701 | - $return = []; |
|
702 | - |
|
703 | - foreach ($struct as $index => $default) { |
|
704 | - $return[$index] = elgg_extract($index, $array, $default); |
|
705 | - } |
|
706 | - |
|
707 | - return $return; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Returns a category's friendly name. This can be localized by |
|
712 | - * defining the string 'admin:plugins:category:<category>'. If no |
|
713 | - * localization is found, returns the category with _ and - converted to ' ' |
|
714 | - * and then ucwords()'d. |
|
715 | - * |
|
716 | - * @param string $category The category as defined in the manifest. |
|
717 | - * @return string A human-readable category |
|
718 | - */ |
|
719 | - static public function getFriendlyCategory($category) { |
|
720 | - $cat_raw_string = "admin:plugins:category:$category"; |
|
721 | - if (_elgg_services()->translator->languageKeyExists($cat_raw_string)) { |
|
722 | - return _elgg_services()->translator->translate($cat_raw_string); |
|
723 | - } |
|
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 | + 'invitefriends', |
|
402 | + 'legacy_urls', |
|
403 | + 'likes', |
|
404 | + 'logbrowser', |
|
405 | + 'login_as', |
|
406 | + 'logrotate', |
|
407 | + 'members', |
|
408 | + 'messageboard', |
|
409 | + 'messages', |
|
410 | + 'notifications', |
|
411 | + 'pages', |
|
412 | + 'profile', |
|
413 | + 'reportedcontent', |
|
414 | + 'search', |
|
415 | + 'site_notifications', |
|
416 | + 'tagcloud', |
|
417 | + 'thewire', |
|
418 | + 'uservalidationbyemail', |
|
419 | + 'web_services', |
|
420 | + ]; |
|
421 | + |
|
422 | + $cats = $this->parser->getAttribute('category'); |
|
423 | + |
|
424 | + if (!$cats) { |
|
425 | + $cats = []; |
|
426 | + } |
|
427 | + |
|
428 | + if (in_array('bundled', $cats) && !in_array($this->getPluginID(), $bundled_plugins)) { |
|
429 | + unset($cats[array_search('bundled', $cats)]); |
|
430 | + } |
|
431 | + |
|
432 | + return $cats; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Return the screenshots listed. |
|
437 | + * |
|
438 | + * @return array |
|
439 | + */ |
|
440 | + public function getScreenshots() { |
|
441 | + $ss = $this->parser->getAttribute('screenshot'); |
|
442 | + |
|
443 | + if (!$ss) { |
|
444 | + $ss = []; |
|
445 | + } |
|
446 | + |
|
447 | + $normalized = []; |
|
448 | + foreach ($ss as $s) { |
|
449 | + $normalized[] = $this->buildStruct($this->screenshotStruct, $s); |
|
450 | + } |
|
451 | + |
|
452 | + return $normalized; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Return the contributors listed. |
|
457 | + * |
|
458 | + * @return array |
|
459 | + */ |
|
460 | + public function getContributors() { |
|
461 | + $ss = $this->parser->getAttribute('contributor'); |
|
462 | + |
|
463 | + if (!$ss) { |
|
464 | + $ss = []; |
|
465 | + } |
|
466 | + |
|
467 | + $normalized = []; |
|
468 | + foreach ($ss as $s) { |
|
469 | + $normalized[] = $this->buildStruct($this->contributorStruct, $s); |
|
470 | + } |
|
471 | + |
|
472 | + return $normalized; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Return the list of provides by this plugin. |
|
477 | + * |
|
478 | + * @return array |
|
479 | + */ |
|
480 | + public function getProvides() { |
|
481 | + // normalize for 1.7 |
|
482 | + if ($this->getApiVersion() < 1.8) { |
|
483 | + $provides = []; |
|
484 | + } else { |
|
485 | + $provides = $this->parser->getAttribute('provides'); |
|
486 | + } |
|
487 | + |
|
488 | + if (!$provides) { |
|
489 | + $provides = []; |
|
490 | + } |
|
491 | + |
|
492 | + // always provide ourself if we can |
|
493 | + if ($this->pluginID) { |
|
494 | + $provides[] = [ |
|
495 | + 'type' => 'plugin', |
|
496 | + 'name' => $this->getPluginID(), |
|
497 | + 'version' => $this->getVersion() |
|
498 | + ]; |
|
499 | + } |
|
500 | + |
|
501 | + $normalized = []; |
|
502 | + foreach ($provides as $provide) { |
|
503 | + $normalized[] = $this->buildStruct($this->depsProvidesStruct, $provide); |
|
504 | + } |
|
505 | + |
|
506 | + return $normalized; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Returns the dependencies listed. |
|
511 | + * |
|
512 | + * @return array |
|
513 | + */ |
|
514 | + public function getRequires() { |
|
515 | + $reqs = $this->parser->getAttribute('requires'); |
|
516 | + |
|
517 | + if (!$reqs) { |
|
518 | + $reqs = []; |
|
519 | + } |
|
520 | + |
|
521 | + $normalized = []; |
|
522 | + foreach ($reqs as $req) { |
|
523 | + $normalized[] = $this->normalizeDep($req); |
|
524 | + } |
|
525 | + |
|
526 | + return $normalized; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Returns the suggests elements. |
|
531 | + * |
|
532 | + * @return array |
|
533 | + */ |
|
534 | + public function getSuggests() { |
|
535 | + $suggests = $this->parser->getAttribute('suggests'); |
|
536 | + |
|
537 | + if (!$suggests) { |
|
538 | + $suggests = []; |
|
539 | + } |
|
540 | + |
|
541 | + $normalized = []; |
|
542 | + foreach ($suggests as $suggest) { |
|
543 | + $normalized[] = $this->normalizeDep($suggest); |
|
544 | + } |
|
545 | + |
|
546 | + return $normalized; |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * Normalizes a dependency array using the defined structs. |
|
551 | + * Can be used with either requires or suggests. |
|
552 | + * |
|
553 | + * @param array $dep A dependency array. |
|
554 | + * @return array The normalized deps array. |
|
555 | + */ |
|
556 | + private function normalizeDep($dep) { |
|
557 | + switch ($dep['type']) { |
|
558 | + case 'elgg_release': |
|
559 | + $struct = $this->depsStructElgg; |
|
560 | + break; |
|
561 | + |
|
562 | + case 'plugin': |
|
563 | + $struct = $this->depsStructPlugin; |
|
564 | + break; |
|
565 | + |
|
566 | + case 'priority': |
|
567 | + $struct = $this->depsStructPriority; |
|
568 | + break; |
|
569 | + |
|
570 | + case 'php_version': |
|
571 | + $struct = $this->depsStructPhpVersion; |
|
572 | + break; |
|
573 | + |
|
574 | + case 'php_extension': |
|
575 | + $struct = $this->depsStructPhpExtension; |
|
576 | + break; |
|
577 | + |
|
578 | + case 'php_ini': |
|
579 | + $struct = $this->depsStructPhpIni; |
|
580 | + |
|
581 | + // also normalize boolean values |
|
582 | + if (isset($dep['value'])) { |
|
583 | + switch (strtolower($dep['value'])) { |
|
584 | + case 'yes': |
|
585 | + case 'true': |
|
586 | + case 'on': |
|
587 | + case 1: |
|
588 | + $dep['value'] = 1; |
|
589 | + break; |
|
590 | + |
|
591 | + case 'no': |
|
592 | + case 'false': |
|
593 | + case 'off': |
|
594 | + case 0: |
|
595 | + case '': |
|
596 | + $dep['value'] = 0; |
|
597 | + break; |
|
598 | + } |
|
599 | + } |
|
600 | + break; |
|
601 | + default: |
|
602 | + // unrecognized so we just return the raw dependency |
|
603 | + return $dep; |
|
604 | + } |
|
605 | + |
|
606 | + // @todo $struct may not have been defined... |
|
607 | + $normalized_dep = $this->buildStruct($struct, $dep); |
|
608 | + |
|
609 | + // normalize comparison operators |
|
610 | + if (isset($normalized_dep['comparison'])) { |
|
611 | + switch ($normalized_dep['comparison']) { |
|
612 | + case '<': |
|
613 | + $normalized_dep['comparison'] = 'lt'; |
|
614 | + break; |
|
615 | + |
|
616 | + case '<=': |
|
617 | + $normalized_dep['comparison'] = 'le'; |
|
618 | + break; |
|
619 | + |
|
620 | + case '>': |
|
621 | + $normalized_dep['comparison'] = 'gt'; |
|
622 | + break; |
|
623 | + |
|
624 | + case '>=': |
|
625 | + $normalized_dep['comparison'] = 'ge'; |
|
626 | + break; |
|
627 | + |
|
628 | + case '==': |
|
629 | + case 'eq': |
|
630 | + $normalized_dep['comparison'] = '='; |
|
631 | + break; |
|
632 | + |
|
633 | + case '<>': |
|
634 | + case 'ne': |
|
635 | + $normalized_dep['comparison'] = '!='; |
|
636 | + break; |
|
637 | + } |
|
638 | + } |
|
639 | + |
|
640 | + return $normalized_dep; |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Returns the conflicts listed |
|
645 | + * |
|
646 | + * @return array |
|
647 | + */ |
|
648 | + public function getConflicts() { |
|
649 | + // normalize for 1.7 |
|
650 | + if ($this->getApiVersion() < 1.8) { |
|
651 | + $conflicts = []; |
|
652 | + } else { |
|
653 | + $conflicts = $this->parser->getAttribute('conflicts'); |
|
654 | + } |
|
655 | + |
|
656 | + if (!$conflicts) { |
|
657 | + $conflicts = []; |
|
658 | + } |
|
659 | + |
|
660 | + $normalized = []; |
|
661 | + |
|
662 | + foreach ($conflicts as $conflict) { |
|
663 | + $normalized[] = $this->buildStruct($this->depsConflictsStruct, $conflict); |
|
664 | + } |
|
665 | + |
|
666 | + return $normalized; |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Should this plugin be activated when Elgg is installed |
|
671 | + * |
|
672 | + * @return bool |
|
673 | + */ |
|
674 | + public function getActivateOnInstall() { |
|
675 | + $activate = $this->parser->getAttribute('activate_on_install'); |
|
676 | + switch (strtolower($activate)) { |
|
677 | + case 'yes': |
|
678 | + case 'true': |
|
679 | + case 'on': |
|
680 | + case 1: |
|
681 | + return true; |
|
682 | + |
|
683 | + case 'no': |
|
684 | + case 'false': |
|
685 | + case 'off': |
|
686 | + case 0: |
|
687 | + case '': |
|
688 | + return false; |
|
689 | + } |
|
690 | + } |
|
691 | + |
|
692 | + /** |
|
693 | + * Normalizes an array into the structure specified |
|
694 | + * |
|
695 | + * @param array $struct The struct to normalize $element to. |
|
696 | + * @param array $array The array |
|
697 | + * |
|
698 | + * @return array |
|
699 | + */ |
|
700 | + protected function buildStruct(array $struct, array $array) { |
|
701 | + $return = []; |
|
702 | + |
|
703 | + foreach ($struct as $index => $default) { |
|
704 | + $return[$index] = elgg_extract($index, $array, $default); |
|
705 | + } |
|
706 | + |
|
707 | + return $return; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Returns a category's friendly name. This can be localized by |
|
712 | + * defining the string 'admin:plugins:category:<category>'. If no |
|
713 | + * localization is found, returns the category with _ and - converted to ' ' |
|
714 | + * and then ucwords()'d. |
|
715 | + * |
|
716 | + * @param string $category The category as defined in the manifest. |
|
717 | + * @return string A human-readable category |
|
718 | + */ |
|
719 | + static public function getFriendlyCategory($category) { |
|
720 | + $cat_raw_string = "admin:plugins:category:$category"; |
|
721 | + if (_elgg_services()->translator->languageKeyExists($cat_raw_string)) { |
|
722 | + return _elgg_services()->translator->translate($cat_raw_string); |
|
723 | + } |
|
724 | 724 | |
725 | - $category = str_replace(['-', '_'], ' ', $category); |
|
726 | - return ucwords($category); |
|
727 | - } |
|
725 | + $category = str_replace(['-', '_'], ' ', $category); |
|
726 | + return ucwords($category); |
|
727 | + } |
|
728 | 728 | } |
@@ -231,7 +231,7 @@ discard block |
||
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 |
||
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); |
@@ -93,274 +93,274 @@ |
||
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 | } |
@@ -552,7 +552,7 @@ discard block |
||
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 |
||
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 | */ |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @see elgg_get_ignore_access() |
45 | 45 | */ |
46 | 46 | function elgg_set_ignore_access($ignore = true) { |
47 | - return _elgg_services()->session->setIgnoreAccess($ignore); |
|
47 | + return _elgg_services()->session->setIgnoreAccess($ignore); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @see elgg_set_ignore_access() |
56 | 56 | */ |
57 | 57 | function elgg_get_ignore_access() { |
58 | - return _elgg_services()->session->getIgnoreAccess(); |
|
58 | + return _elgg_services()->session->getIgnoreAccess(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @access private |
75 | 75 | */ |
76 | 76 | function get_access_list($user_guid = 0, $ignored = 0, $flush = false) { |
77 | - return _elgg_services()->accessCollections->getAccessList($user_guid, $flush); |
|
77 | + return _elgg_services()->accessCollections->getAccessList($user_guid, $flush); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return array An array of access collections ids |
104 | 104 | */ |
105 | 105 | function get_access_array($user_guid = 0, $ignored = 0, $flush = false) { |
106 | - return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush); |
|
106 | + return _elgg_services()->accessCollections->getAccessArray($user_guid, $flush); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -119,26 +119,26 @@ discard block |
||
119 | 119 | * @return int default access id (see ACCESS defines in elgglib.php) |
120 | 120 | */ |
121 | 121 | function get_default_access(ElggUser $user = null, array $input_params = []) { |
122 | - // site default access |
|
123 | - $default_access = _elgg_config()->default_access; |
|
124 | - |
|
125 | - // user default access if enabled |
|
126 | - if (_elgg_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); |
|
122 | + // site default access |
|
123 | + $default_access = _elgg_config()->default_access; |
|
124 | + |
|
125 | + // user default access if enabled |
|
126 | + if (_elgg_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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | /** |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | * @return void |
533 | 533 | */ |
534 | 534 | function access_init() { |
535 | - _elgg_services()->accessCollections->markInitComplete(); |
|
535 | + _elgg_services()->accessCollections->markInitComplete(); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -556,29 +556,29 @@ discard block |
||
556 | 556 | * @access private |
557 | 557 | */ |
558 | 558 | function elgg_override_permissions($hook, $type, $value, $params) { |
559 | - $user = elgg_extract('user', $params); |
|
560 | - if ($user) { |
|
561 | - $user_guid = $user->guid; |
|
562 | - } else { |
|
563 | - $user_guid = _elgg_services()->session->getLoggedInUserGuid(); |
|
564 | - } |
|
565 | - |
|
566 | - // don't do this so ignore access still works with no one logged in |
|
567 | - //if (!$user instanceof \ElggUser) { |
|
568 | - // return false; |
|
569 | - //} |
|
570 | - // check for admin |
|
571 | - if ($user_guid && elgg_is_admin_user($user_guid)) { |
|
572 | - return true; |
|
573 | - } |
|
574 | - |
|
575 | - // check access overrides |
|
576 | - if (elgg_check_access_overrides($user_guid)) { |
|
577 | - return true; |
|
578 | - } |
|
579 | - |
|
580 | - // consult other hooks |
|
581 | - return null; |
|
559 | + $user = elgg_extract('user', $params); |
|
560 | + if ($user) { |
|
561 | + $user_guid = $user->guid; |
|
562 | + } else { |
|
563 | + $user_guid = _elgg_services()->session->getLoggedInUserGuid(); |
|
564 | + } |
|
565 | + |
|
566 | + // don't do this so ignore access still works with no one logged in |
|
567 | + //if (!$user instanceof \ElggUser) { |
|
568 | + // return false; |
|
569 | + //} |
|
570 | + // check for admin |
|
571 | + if ($user_guid && elgg_is_admin_user($user_guid)) { |
|
572 | + return true; |
|
573 | + } |
|
574 | + |
|
575 | + // check access overrides |
|
576 | + if (elgg_check_access_overrides($user_guid)) { |
|
577 | + return true; |
|
578 | + } |
|
579 | + |
|
580 | + // consult other hooks |
|
581 | + return null; |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -593,22 +593,22 @@ discard block |
||
593 | 593 | * @access private |
594 | 594 | */ |
595 | 595 | function access_test($hook, $type, $value, $params) { |
596 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessCollectionsTest.php'; |
|
597 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessSQLTest.php'; |
|
598 | - return $value; |
|
596 | + $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessCollectionsTest.php'; |
|
597 | + $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessSQLTest.php'; |
|
598 | + return $value; |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
602 | 602 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
603 | 603 | */ |
604 | 604 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
605 | - // Tell the access functions the system has booted, plugins are loaded, |
|
606 | - // and the user is logged in so it can start caching |
|
607 | - $events->registerHandler('ready', 'system', 'access_init'); |
|
605 | + // Tell the access functions the system has booted, plugins are loaded, |
|
606 | + // and the user is logged in so it can start caching |
|
607 | + $events->registerHandler('ready', 'system', 'access_init'); |
|
608 | 608 | |
609 | - // For overrided permissions |
|
610 | - $hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions', 600); |
|
611 | - $hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions', 600); |
|
609 | + // For overrided permissions |
|
610 | + $hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions', 600); |
|
611 | + $hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions', 600); |
|
612 | 612 | |
613 | - $hooks->registerHandler('unit_test', 'system', 'access_test'); |
|
613 | + $hooks->registerHandler('unit_test', 'system', 'access_test'); |
|
614 | 614 | }; |
@@ -593,8 +593,8 @@ |
||
593 | 593 | * @access private |
594 | 594 | */ |
595 | 595 | function access_test($hook, $type, $value, $params) { |
596 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessCollectionsTest.php'; |
|
597 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreAccessSQLTest.php'; |
|
596 | + $value[] = Paths::elgg().'engine/tests/ElggCoreAccessCollectionsTest.php'; |
|
597 | + $value[] = Paths::elgg().'engine/tests/ElggCoreAccessSQLTest.php'; |
|
598 | 598 | return $value; |
599 | 599 | } |
600 | 600 |
@@ -806,7 +806,7 @@ |
||
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) { |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | foreach ($active_plugins as $plugin) { |
547 | 547 | $plugin_id = $plugin->getID(); |
548 | 548 | |
549 | - if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) { |
|
549 | + if (!elgg_view_exists("plugins/{$plugin_id}/settings")) { |
|
550 | 550 | continue; |
551 | 551 | } |
552 | 552 | $plugin_name = $plugin->getDisplayName(); |
@@ -624,10 +624,10 @@ discard block |
||
624 | 624 | forward('', '404'); |
625 | 625 | } |
626 | 626 | } else { |
627 | - $view = 'admin/' . implode('/', $page); |
|
627 | + $view = 'admin/'.implode('/', $page); |
|
628 | 628 | $title = elgg_echo("admin:{$page[0]}"); |
629 | 629 | if (count($page) > 1) { |
630 | - $title .= ' : ' . elgg_echo('admin:' . implode(':', $page)); |
|
630 | + $title .= ' : '.elgg_echo('admin:'.implode(':', $page)); |
|
631 | 631 | } |
632 | 632 | } |
633 | 633 |
@@ -29,27 +29,27 @@ discard block |
||
29 | 29 | * @since 1.8.0 |
30 | 30 | */ |
31 | 31 | function elgg_get_admins(array $options = []) { |
32 | - $config = _elgg_config(); |
|
33 | - |
|
34 | - if (isset($options['joins'])) { |
|
35 | - if (!is_array($options['joins'])) { |
|
36 | - $options['joins'] = [$options['joins']]; |
|
37 | - } |
|
38 | - $options['joins'][] = "join {$config->dbprefix}users_entity u on e.guid=u.guid"; |
|
39 | - } else { |
|
40 | - $options['joins'] = ["join {$config->dbprefix}users_entity u on e.guid=u.guid"]; |
|
41 | - } |
|
42 | - |
|
43 | - if (isset($options['wheres'])) { |
|
44 | - if (!is_array($options['wheres'])) { |
|
45 | - $options['wheres'] = [$options['wheres']]; |
|
46 | - } |
|
47 | - $options['wheres'][] = "u.admin = 'yes'"; |
|
48 | - } else { |
|
49 | - $options['wheres'][] = "u.admin = 'yes'"; |
|
50 | - } |
|
51 | - |
|
52 | - return elgg_get_entities($options); |
|
32 | + $config = _elgg_config(); |
|
33 | + |
|
34 | + if (isset($options['joins'])) { |
|
35 | + if (!is_array($options['joins'])) { |
|
36 | + $options['joins'] = [$options['joins']]; |
|
37 | + } |
|
38 | + $options['joins'][] = "join {$config->dbprefix}users_entity u on e.guid=u.guid"; |
|
39 | + } else { |
|
40 | + $options['joins'] = ["join {$config->dbprefix}users_entity u on e.guid=u.guid"]; |
|
41 | + } |
|
42 | + |
|
43 | + if (isset($options['wheres'])) { |
|
44 | + if (!is_array($options['wheres'])) { |
|
45 | + $options['wheres'] = [$options['wheres']]; |
|
46 | + } |
|
47 | + $options['wheres'][] = "u.admin = 'yes'"; |
|
48 | + } else { |
|
49 | + $options['wheres'][] = "u.admin = 'yes'"; |
|
50 | + } |
|
51 | + |
|
52 | + return elgg_get_entities($options); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @since 1.8.0 |
70 | 70 | */ |
71 | 71 | function elgg_add_admin_notice($id, $message) { |
72 | - return _elgg_services()->adminNotices->add($id, $message); |
|
72 | + return _elgg_services()->adminNotices->add($id, $message); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @since 1.8.0 |
82 | 82 | */ |
83 | 83 | function elgg_delete_admin_notice($id) { |
84 | - return _elgg_services()->adminNotices->delete($id); |
|
84 | + return _elgg_services()->adminNotices->delete($id); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @since 1.8.0 |
94 | 94 | */ |
95 | 95 | function elgg_get_admin_notices(array $options = []) { |
96 | - return _elgg_services()->adminNotices->find($options); |
|
96 | + return _elgg_services()->adminNotices->find($options); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @since 1.8.0 |
106 | 106 | */ |
107 | 107 | function elgg_admin_notice_exists($id) { |
108 | - return _elgg_services()->adminNotices->exists($id); |
|
108 | + return _elgg_services()->adminNotices->exists($id); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | * @access private |
118 | 118 | */ |
119 | 119 | function _elgg_create_notice_of_pending_upgrade($event, $type, $object) { |
120 | - if ($object instanceof \ElggUpgrade) { |
|
121 | - // Link to the Upgrades section |
|
122 | - $link = elgg_view('output/url', [ |
|
123 | - 'href' => 'admin/upgrades', |
|
124 | - 'text' => elgg_echo('admin:view_upgrades'), |
|
125 | - ]); |
|
120 | + if ($object instanceof \ElggUpgrade) { |
|
121 | + // Link to the Upgrades section |
|
122 | + $link = elgg_view('output/url', [ |
|
123 | + 'href' => 'admin/upgrades', |
|
124 | + 'text' => elgg_echo('admin:view_upgrades'), |
|
125 | + ]); |
|
126 | 126 | |
127 | - $message = elgg_echo('admin:pending_upgrades'); |
|
127 | + $message = elgg_echo('admin:pending_upgrades'); |
|
128 | 128 | |
129 | - elgg_add_admin_notice('pending_upgrades', "$message $link"); |
|
130 | - } |
|
129 | + elgg_add_admin_notice('pending_upgrades', "$message $link"); |
|
130 | + } |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,85 +137,85 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function _elgg_admin_init() { |
139 | 139 | |
140 | - elgg_register_css('elgg.admin', elgg_get_simplecache_url('admin.css')); |
|
140 | + elgg_register_css('elgg.admin', elgg_get_simplecache_url('admin.css')); |
|
141 | 141 | |
142 | - elgg_extend_view('admin.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
142 | + elgg_extend_view('admin.css', 'lightbox/elgg-colorbox-theme/colorbox.css'); |
|
143 | 143 | |
144 | - elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu'); |
|
145 | - elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu'); |
|
146 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu'); |
|
147 | - elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu_plugin_settings'); |
|
148 | - |
|
149 | - // maintenance mode |
|
150 | - if (elgg_get_config('elgg_maintenance_mode', null)) { |
|
151 | - elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600); |
|
152 | - elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600); |
|
153 | - elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css')); |
|
154 | - |
|
155 | - elgg_register_menu_item('topbar', [ |
|
156 | - 'name' => 'maintenance_mode', |
|
157 | - 'href' => 'admin/configure_utilities/maintenance', |
|
158 | - 'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'), |
|
159 | - 'priority' => 900, |
|
160 | - ]); |
|
161 | - } |
|
162 | - |
|
163 | - elgg_register_action('admin/user/ban', '', 'admin'); |
|
164 | - elgg_register_action('admin/user/unban', '', 'admin'); |
|
165 | - elgg_register_action('admin/user/delete', '', 'admin'); |
|
166 | - elgg_register_action('admin/user/resetpassword', '', 'admin'); |
|
167 | - elgg_register_action('admin/user/makeadmin', '', 'admin'); |
|
168 | - elgg_register_action('admin/user/removeadmin', '', 'admin'); |
|
169 | - |
|
170 | - elgg_register_action('admin/site/update_basic', '', 'admin'); |
|
171 | - elgg_register_action('admin/site/update_advanced', '', 'admin'); |
|
172 | - elgg_register_action('admin/site/flush_cache', '', 'admin'); |
|
173 | - elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); |
|
174 | - elgg_register_action('admin/site/set_robots', '', 'admin'); |
|
175 | - elgg_register_action('admin/site/set_maintenance_mode', '', 'admin'); |
|
176 | - |
|
177 | - elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin'); |
|
178 | - elgg_register_action('admin/site/regenerate_secret', '', 'admin'); |
|
179 | - elgg_register_action('admin/upgrade', '', 'admin'); |
|
180 | - |
|
181 | - elgg_register_action('admin/menu/save', '', 'admin'); |
|
182 | - |
|
183 | - elgg_register_action('admin/delete_admin_notice', '', 'admin'); |
|
144 | + elgg_register_plugin_hook_handler('register', 'menu:admin_header', '_elgg_admin_header_menu'); |
|
145 | + elgg_register_plugin_hook_handler('register', 'menu:admin_footer', '_elgg_admin_footer_menu'); |
|
146 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu'); |
|
147 | + elgg_register_plugin_hook_handler('register', 'menu:page', '_elgg_admin_page_menu_plugin_settings'); |
|
148 | + |
|
149 | + // maintenance mode |
|
150 | + if (elgg_get_config('elgg_maintenance_mode', null)) { |
|
151 | + elgg_register_plugin_hook_handler('route', 'all', '_elgg_admin_maintenance_handler', 600); |
|
152 | + elgg_register_plugin_hook_handler('action', 'all', '_elgg_admin_maintenance_action_check', 600); |
|
153 | + elgg_register_css('maintenance', elgg_get_simplecache_url('maintenance.css')); |
|
154 | + |
|
155 | + elgg_register_menu_item('topbar', [ |
|
156 | + 'name' => 'maintenance_mode', |
|
157 | + 'href' => 'admin/configure_utilities/maintenance', |
|
158 | + 'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'), |
|
159 | + 'priority' => 900, |
|
160 | + ]); |
|
161 | + } |
|
162 | + |
|
163 | + elgg_register_action('admin/user/ban', '', 'admin'); |
|
164 | + elgg_register_action('admin/user/unban', '', 'admin'); |
|
165 | + elgg_register_action('admin/user/delete', '', 'admin'); |
|
166 | + elgg_register_action('admin/user/resetpassword', '', 'admin'); |
|
167 | + elgg_register_action('admin/user/makeadmin', '', 'admin'); |
|
168 | + elgg_register_action('admin/user/removeadmin', '', 'admin'); |
|
169 | + |
|
170 | + elgg_register_action('admin/site/update_basic', '', 'admin'); |
|
171 | + elgg_register_action('admin/site/update_advanced', '', 'admin'); |
|
172 | + elgg_register_action('admin/site/flush_cache', '', 'admin'); |
|
173 | + elgg_register_action('admin/site/unlock_upgrade', '', 'admin'); |
|
174 | + elgg_register_action('admin/site/set_robots', '', 'admin'); |
|
175 | + elgg_register_action('admin/site/set_maintenance_mode', '', 'admin'); |
|
176 | + |
|
177 | + elgg_register_action('admin/upgrades/upgrade_database_guid_columns', '', 'admin'); |
|
178 | + elgg_register_action('admin/site/regenerate_secret', '', 'admin'); |
|
179 | + elgg_register_action('admin/upgrade', '', 'admin'); |
|
180 | + |
|
181 | + elgg_register_action('admin/menu/save', '', 'admin'); |
|
182 | + |
|
183 | + elgg_register_action('admin/delete_admin_notice', '', 'admin'); |
|
184 | 184 | |
185 | - elgg_register_action('admin/security/settings', '', 'admin'); |
|
186 | - |
|
187 | - elgg_register_simplecache_view('admin.css'); |
|
188 | - |
|
189 | - // widgets |
|
190 | - $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status']; |
|
191 | - foreach ($widgets as $widget) { |
|
192 | - elgg_register_widget_type( |
|
193 | - $widget, |
|
194 | - elgg_echo("admin:widget:$widget"), |
|
195 | - elgg_echo("admin:widget:$widget:help"), |
|
196 | - ['admin'] |
|
197 | - ); |
|
198 | - } |
|
199 | - |
|
200 | - // automatic adding of widgets for admin |
|
201 | - elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets'); |
|
185 | + elgg_register_action('admin/security/settings', '', 'admin'); |
|
186 | + |
|
187 | + elgg_register_simplecache_view('admin.css'); |
|
188 | + |
|
189 | + // widgets |
|
190 | + $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'control_panel', 'cron_status']; |
|
191 | + foreach ($widgets as $widget) { |
|
192 | + elgg_register_widget_type( |
|
193 | + $widget, |
|
194 | + elgg_echo("admin:widget:$widget"), |
|
195 | + elgg_echo("admin:widget:$widget:help"), |
|
196 | + ['admin'] |
|
197 | + ); |
|
198 | + } |
|
199 | + |
|
200 | + // automatic adding of widgets for admin |
|
201 | + elgg_register_event_handler('make_admin', 'user', '_elgg_add_admin_widgets'); |
|
202 | 202 | |
203 | - elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']); |
|
204 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action'); |
|
205 | - elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action'); |
|
206 | - elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin'); |
|
207 | - elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin'); |
|
208 | - elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin'); |
|
209 | - elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin'); |
|
203 | + elgg_register_notification_event('user', '', ['make_admin', 'remove_admin']); |
|
204 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_admin_subscribers_admin_action'); |
|
205 | + elgg_register_plugin_hook_handler('get', 'subscriptions', '_elgg_admin_get_user_subscriber_admin_action'); |
|
206 | + elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_admin_notification_make_admin'); |
|
207 | + elgg_register_plugin_hook_handler('prepare', 'notification:make_admin:user:', '_elgg_admin_prepare_user_notification_make_admin'); |
|
208 | + elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_admin_notification_remove_admin'); |
|
209 | + elgg_register_plugin_hook_handler('prepare', 'notification:remove_admin:user:', '_elgg_admin_prepare_user_notification_remove_admin'); |
|
210 | 210 | |
211 | - // Add notice about pending upgrades |
|
212 | - elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade'); |
|
213 | - |
|
214 | - elgg_register_page_handler('admin', '_elgg_admin_page_handler'); |
|
215 | - elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler'); |
|
216 | - elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler'); |
|
217 | - elgg_register_page_handler('phpinfo', '_elgg_phpinfo_page_handler'); |
|
218 | - elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update'); |
|
211 | + // Add notice about pending upgrades |
|
212 | + elgg_register_event_handler('create', 'object', '_elgg_create_notice_of_pending_upgrade'); |
|
213 | + |
|
214 | + elgg_register_page_handler('admin', '_elgg_admin_page_handler'); |
|
215 | + elgg_register_page_handler('admin_plugin_text_file', '_elgg_admin_markdown_page_handler'); |
|
216 | + elgg_register_page_handler('robots.txt', '_elgg_robots_page_handler'); |
|
217 | + elgg_register_page_handler('phpinfo', '_elgg_phpinfo_page_handler'); |
|
218 | + elgg_register_page_handler('admin_plugins_refresh', '_elgg_ajax_plugins_update'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | * @return Elgg\Http\OkResponse |
226 | 226 | */ |
227 | 227 | function _elgg_ajax_plugins_update() { |
228 | - elgg_admin_gatekeeper(); |
|
229 | - elgg_set_context('admin'); |
|
228 | + elgg_admin_gatekeeper(); |
|
229 | + elgg_set_context('admin'); |
|
230 | 230 | |
231 | - return elgg_ok_response([ |
|
232 | - 'list' => elgg_view('admin/plugins', ['list_only' => true]), |
|
233 | - 'sidebar' => elgg_view('admin/sidebar'), |
|
234 | - ]); |
|
231 | + return elgg_ok_response([ |
|
232 | + 'list' => elgg_view('admin/plugins', ['list_only' => true]), |
|
233 | + 'sidebar' => elgg_view('admin/sidebar'), |
|
234 | + ]); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -248,52 +248,52 @@ discard block |
||
248 | 248 | * @since 3.0 |
249 | 249 | */ |
250 | 250 | function _elgg_admin_header_menu($hook, $type, $return, $params) { |
251 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
252 | - return; |
|
253 | - } |
|
254 | - |
|
255 | - $admin = elgg_get_logged_in_user_entity(); |
|
256 | - |
|
257 | - $admin_icon = elgg_view_entity_icon($admin, 'tiny'); |
|
258 | - $admin_link = elgg_view('output/url', [ |
|
259 | - 'href' => $admin->getURL(), |
|
260 | - 'text' => $admin->name, |
|
261 | - ]); |
|
262 | - |
|
263 | - $return[] = \ElggMenuItem::factory([ |
|
264 | - 'name' => 'admin_profile', |
|
265 | - 'href' => false, |
|
266 | - 'text' => "$admin_link $admin_icon", |
|
267 | - 'priority' => 1000, |
|
268 | - ]); |
|
269 | - |
|
270 | - $return[] = \ElggMenuItem::factory([ |
|
271 | - 'name' => 'admin_logout', |
|
272 | - 'href' => 'action/logout', |
|
273 | - 'text' => elgg_echo('logout'), |
|
274 | - 'is_trusted' => true, |
|
275 | - 'priority' => 900, |
|
276 | - ]); |
|
277 | - |
|
278 | - $return[] = \ElggMenuItem::factory([ |
|
279 | - 'name' => 'view_site', |
|
280 | - 'href' => elgg_get_site_url(), |
|
281 | - 'text' => elgg_echo('admin:view_site'), |
|
282 | - 'is_trusted' => true, |
|
283 | - 'priority' => 800, |
|
284 | - ]); |
|
285 | - |
|
286 | - if (elgg_get_config('elgg_maintenance_mode')) { |
|
287 | - $return[] = \ElggMenuItem::factory([ |
|
288 | - 'name' => 'maintenance', |
|
289 | - 'href' => 'admin/configure_utilities/maintenance', |
|
290 | - 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
291 | - 'link_class' => 'elgg-maintenance-mode-warning', |
|
292 | - 'priority' => 700, |
|
293 | - ]); |
|
294 | - } |
|
251 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
252 | + return; |
|
253 | + } |
|
254 | + |
|
255 | + $admin = elgg_get_logged_in_user_entity(); |
|
256 | + |
|
257 | + $admin_icon = elgg_view_entity_icon($admin, 'tiny'); |
|
258 | + $admin_link = elgg_view('output/url', [ |
|
259 | + 'href' => $admin->getURL(), |
|
260 | + 'text' => $admin->name, |
|
261 | + ]); |
|
262 | + |
|
263 | + $return[] = \ElggMenuItem::factory([ |
|
264 | + 'name' => 'admin_profile', |
|
265 | + 'href' => false, |
|
266 | + 'text' => "$admin_link $admin_icon", |
|
267 | + 'priority' => 1000, |
|
268 | + ]); |
|
269 | + |
|
270 | + $return[] = \ElggMenuItem::factory([ |
|
271 | + 'name' => 'admin_logout', |
|
272 | + 'href' => 'action/logout', |
|
273 | + 'text' => elgg_echo('logout'), |
|
274 | + 'is_trusted' => true, |
|
275 | + 'priority' => 900, |
|
276 | + ]); |
|
277 | + |
|
278 | + $return[] = \ElggMenuItem::factory([ |
|
279 | + 'name' => 'view_site', |
|
280 | + 'href' => elgg_get_site_url(), |
|
281 | + 'text' => elgg_echo('admin:view_site'), |
|
282 | + 'is_trusted' => true, |
|
283 | + 'priority' => 800, |
|
284 | + ]); |
|
285 | + |
|
286 | + if (elgg_get_config('elgg_maintenance_mode')) { |
|
287 | + $return[] = \ElggMenuItem::factory([ |
|
288 | + 'name' => 'maintenance', |
|
289 | + 'href' => 'admin/configure_utilities/maintenance', |
|
290 | + 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
291 | + 'link_class' => 'elgg-maintenance-mode-warning', |
|
292 | + 'priority' => 700, |
|
293 | + ]); |
|
294 | + } |
|
295 | 295 | |
296 | - return $return; |
|
296 | + return $return; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -310,35 +310,35 @@ discard block |
||
310 | 310 | * @since 3.0 |
311 | 311 | */ |
312 | 312 | function _elgg_admin_footer_menu($hook, $type, $return, $params) { |
313 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
314 | - return; |
|
315 | - } |
|
316 | - |
|
317 | - $return[] = \ElggMenuItem::factory([ |
|
318 | - 'name' => 'faq', |
|
319 | - 'text' => elgg_echo('admin:footer:faq'), |
|
320 | - 'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html', |
|
321 | - ]); |
|
322 | - |
|
323 | - $return[] = \ElggMenuItem::factory([ |
|
324 | - 'name' => 'manual', |
|
325 | - 'text' => elgg_echo('admin:footer:manual'), |
|
326 | - 'href' => 'http://learn.elgg.org/en/stable/admin/index.html', |
|
327 | - ]); |
|
328 | - |
|
329 | - $return[] = \ElggMenuItem::factory([ |
|
330 | - 'name' => 'community_forums', |
|
331 | - 'text' => elgg_echo('admin:footer:community_forums'), |
|
332 | - 'href' => 'http://elgg.org/groups/all/', |
|
333 | - ]); |
|
334 | - |
|
335 | - $return[] = \ElggMenuItem::factory([ |
|
336 | - 'name' => 'blog', |
|
337 | - 'text' => elgg_echo('admin:footer:blog'), |
|
338 | - 'href' => 'https://elgg.org/blog/all', |
|
339 | - ]); |
|
313 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
314 | + return; |
|
315 | + } |
|
316 | + |
|
317 | + $return[] = \ElggMenuItem::factory([ |
|
318 | + 'name' => 'faq', |
|
319 | + 'text' => elgg_echo('admin:footer:faq'), |
|
320 | + 'href' => 'http://learn.elgg.org/en/stable/appendix/faqs.html', |
|
321 | + ]); |
|
322 | + |
|
323 | + $return[] = \ElggMenuItem::factory([ |
|
324 | + 'name' => 'manual', |
|
325 | + 'text' => elgg_echo('admin:footer:manual'), |
|
326 | + 'href' => 'http://learn.elgg.org/en/stable/admin/index.html', |
|
327 | + ]); |
|
328 | + |
|
329 | + $return[] = \ElggMenuItem::factory([ |
|
330 | + 'name' => 'community_forums', |
|
331 | + 'text' => elgg_echo('admin:footer:community_forums'), |
|
332 | + 'href' => 'http://elgg.org/groups/all/', |
|
333 | + ]); |
|
334 | + |
|
335 | + $return[] = \ElggMenuItem::factory([ |
|
336 | + 'name' => 'blog', |
|
337 | + 'text' => elgg_echo('admin:footer:blog'), |
|
338 | + 'href' => 'https://elgg.org/blog/all', |
|
339 | + ]); |
|
340 | 340 | |
341 | - return $return; |
|
341 | + return $return; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -354,148 +354,148 @@ discard block |
||
354 | 354 | * @since 3.0 |
355 | 355 | */ |
356 | 356 | function _elgg_admin_page_menu(\Elgg\Hook $hook) { |
357 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
358 | - return; |
|
359 | - } |
|
357 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
358 | + return; |
|
359 | + } |
|
360 | 360 | |
361 | - $return = $hook->getValue(); |
|
362 | - |
|
363 | - // administer |
|
364 | - $return[] = \ElggMenuItem::factory([ |
|
365 | - 'name' => 'dashboard', |
|
366 | - 'href' => 'admin', |
|
367 | - 'text' => elgg_echo('admin:dashboard'), |
|
368 | - 'priority' => 10, |
|
369 | - 'section' => 'administer', |
|
370 | - ]); |
|
361 | + $return = $hook->getValue(); |
|
362 | + |
|
363 | + // administer |
|
364 | + $return[] = \ElggMenuItem::factory([ |
|
365 | + 'name' => 'dashboard', |
|
366 | + 'href' => 'admin', |
|
367 | + 'text' => elgg_echo('admin:dashboard'), |
|
368 | + 'priority' => 10, |
|
369 | + 'section' => 'administer', |
|
370 | + ]); |
|
371 | 371 | |
372 | - $return[] = \ElggMenuItem::factory([ |
|
373 | - 'name' => 'plugins', |
|
374 | - 'href' => 'admin/plugins', |
|
375 | - 'text' => elgg_echo('admin:plugins'), |
|
376 | - 'priority' => 30, |
|
377 | - 'section' => 'administer', |
|
378 | - ]); |
|
379 | - |
|
380 | - $return[] = \ElggMenuItem::factory([ |
|
381 | - 'name' => 'users', |
|
382 | - 'text' => elgg_echo('admin:users'), |
|
383 | - 'priority' => 40, |
|
384 | - 'section' => 'administer', |
|
385 | - ]); |
|
386 | - $return[] = \ElggMenuItem::factory([ |
|
387 | - 'name' => 'users:online', |
|
388 | - 'text' => elgg_echo('admin:users:online'), |
|
389 | - 'href' => 'admin/users/online', |
|
390 | - 'priority' => 10, |
|
391 | - 'section' => 'administer', |
|
392 | - 'parent_name' => 'users', |
|
393 | - ]); |
|
394 | - $return[] = \ElggMenuItem::factory([ |
|
395 | - 'name' => 'users:admins', |
|
396 | - 'text' => elgg_echo('admin:users:admins'), |
|
397 | - 'href' => 'admin/users/admins', |
|
398 | - 'priority' => 20, |
|
399 | - 'section' => 'administer', |
|
400 | - 'parent_name' => 'users', |
|
401 | - ]); |
|
402 | - $return[] = \ElggMenuItem::factory([ |
|
403 | - 'name' => 'users:newest', |
|
404 | - 'text' => elgg_echo('admin:users:newest'), |
|
405 | - 'href' => 'admin/users/newest', |
|
406 | - 'priority' => 30, |
|
407 | - 'section' => 'administer', |
|
408 | - 'parent_name' => 'users', |
|
409 | - ]); |
|
410 | - $return[] = \ElggMenuItem::factory([ |
|
411 | - 'name' => 'users:add', |
|
412 | - 'text' => elgg_echo('admin:users:add'), |
|
413 | - 'href' => 'admin/users/add', |
|
414 | - 'priority' => 40, |
|
415 | - 'section' => 'administer', |
|
416 | - 'parent_name' => 'users', |
|
417 | - ]); |
|
418 | - $return[] = \ElggMenuItem::factory([ |
|
419 | - 'name' => 'upgrades', |
|
420 | - 'href' => 'admin/upgrades', |
|
421 | - 'text' => elgg_echo('admin:upgrades'), |
|
422 | - 'priority' => 600, |
|
423 | - 'section' => 'administer', |
|
424 | - ]); |
|
372 | + $return[] = \ElggMenuItem::factory([ |
|
373 | + 'name' => 'plugins', |
|
374 | + 'href' => 'admin/plugins', |
|
375 | + 'text' => elgg_echo('admin:plugins'), |
|
376 | + 'priority' => 30, |
|
377 | + 'section' => 'administer', |
|
378 | + ]); |
|
379 | + |
|
380 | + $return[] = \ElggMenuItem::factory([ |
|
381 | + 'name' => 'users', |
|
382 | + 'text' => elgg_echo('admin:users'), |
|
383 | + 'priority' => 40, |
|
384 | + 'section' => 'administer', |
|
385 | + ]); |
|
386 | + $return[] = \ElggMenuItem::factory([ |
|
387 | + 'name' => 'users:online', |
|
388 | + 'text' => elgg_echo('admin:users:online'), |
|
389 | + 'href' => 'admin/users/online', |
|
390 | + 'priority' => 10, |
|
391 | + 'section' => 'administer', |
|
392 | + 'parent_name' => 'users', |
|
393 | + ]); |
|
394 | + $return[] = \ElggMenuItem::factory([ |
|
395 | + 'name' => 'users:admins', |
|
396 | + 'text' => elgg_echo('admin:users:admins'), |
|
397 | + 'href' => 'admin/users/admins', |
|
398 | + 'priority' => 20, |
|
399 | + 'section' => 'administer', |
|
400 | + 'parent_name' => 'users', |
|
401 | + ]); |
|
402 | + $return[] = \ElggMenuItem::factory([ |
|
403 | + 'name' => 'users:newest', |
|
404 | + 'text' => elgg_echo('admin:users:newest'), |
|
405 | + 'href' => 'admin/users/newest', |
|
406 | + 'priority' => 30, |
|
407 | + 'section' => 'administer', |
|
408 | + 'parent_name' => 'users', |
|
409 | + ]); |
|
410 | + $return[] = \ElggMenuItem::factory([ |
|
411 | + 'name' => 'users:add', |
|
412 | + 'text' => elgg_echo('admin:users:add'), |
|
413 | + 'href' => 'admin/users/add', |
|
414 | + 'priority' => 40, |
|
415 | + 'section' => 'administer', |
|
416 | + 'parent_name' => 'users', |
|
417 | + ]); |
|
418 | + $return[] = \ElggMenuItem::factory([ |
|
419 | + 'name' => 'upgrades', |
|
420 | + 'href' => 'admin/upgrades', |
|
421 | + 'text' => elgg_echo('admin:upgrades'), |
|
422 | + 'priority' => 600, |
|
423 | + 'section' => 'administer', |
|
424 | + ]); |
|
425 | 425 | |
426 | - $return[] = \ElggMenuItem::factory([ |
|
427 | - 'name' => 'administer_utilities', |
|
428 | - 'text' => elgg_echo('admin:administer_utilities'), |
|
429 | - 'priority' => 50, |
|
430 | - 'section' => 'administer', |
|
431 | - ]); |
|
426 | + $return[] = \ElggMenuItem::factory([ |
|
427 | + 'name' => 'administer_utilities', |
|
428 | + 'text' => elgg_echo('admin:administer_utilities'), |
|
429 | + 'priority' => 50, |
|
430 | + 'section' => 'administer', |
|
431 | + ]); |
|
432 | 432 | |
433 | - // configure |
|
434 | - $return[] = \ElggMenuItem::factory([ |
|
435 | - 'name' => 'settings:basic', |
|
436 | - 'href' => 'admin/settings/basic', |
|
437 | - 'text' => elgg_echo('admin:settings:basic'), |
|
438 | - 'priority' => 10, |
|
439 | - 'section' => 'configure', |
|
440 | - ]); |
|
441 | - $return[] = \ElggMenuItem::factory([ |
|
442 | - 'name' => 'settings:advanced', |
|
443 | - 'href' => 'admin/settings/advanced', |
|
444 | - 'text' => elgg_echo('admin:settings:advanced'), |
|
445 | - 'priority' => 20, |
|
446 | - 'section' => 'configure', |
|
447 | - ]); |
|
448 | - $return[] = \ElggMenuItem::factory([ |
|
449 | - 'name' => 'security', |
|
450 | - 'href' => 'admin/security', |
|
451 | - 'text' => elgg_echo('admin:security'), |
|
452 | - 'priority' => 30, |
|
453 | - 'section' => 'configure', |
|
454 | - ]); |
|
455 | - |
|
456 | - $return[] = \ElggMenuItem::factory([ |
|
457 | - 'name' => 'configure_utilities', |
|
458 | - 'text' => elgg_echo('admin:configure_utilities'), |
|
459 | - 'priority' => 600, |
|
460 | - 'section' => 'configure', |
|
461 | - ]); |
|
462 | - $return[] = \ElggMenuItem::factory([ |
|
463 | - 'name' => 'configure_utilities:maintenance', |
|
464 | - 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
465 | - 'href' => 'admin/configure_utilities/maintenance', |
|
466 | - 'section' => 'configure', |
|
467 | - 'parent_name' => 'configure_utilities', |
|
468 | - ]); |
|
469 | - $return[] = \ElggMenuItem::factory([ |
|
470 | - 'name' => 'configure_utilities:menu_items', |
|
471 | - 'text' => elgg_echo('admin:configure_utilities:menu_items'), |
|
472 | - 'href' => 'admin/configure_utilities/menu_items', |
|
473 | - 'section' => 'configure', |
|
474 | - 'parent_name' => 'configure_utilities', |
|
475 | - ]); |
|
476 | - $return[] = \ElggMenuItem::factory([ |
|
477 | - 'name' => 'configure_utilities:robots', |
|
478 | - 'text' => elgg_echo('admin:configure_utilities:robots'), |
|
479 | - 'href' => 'admin/configure_utilities/robots', |
|
480 | - 'section' => 'configure', |
|
481 | - 'parent_name' => 'configure_utilities', |
|
482 | - ]); |
|
433 | + // configure |
|
434 | + $return[] = \ElggMenuItem::factory([ |
|
435 | + 'name' => 'settings:basic', |
|
436 | + 'href' => 'admin/settings/basic', |
|
437 | + 'text' => elgg_echo('admin:settings:basic'), |
|
438 | + 'priority' => 10, |
|
439 | + 'section' => 'configure', |
|
440 | + ]); |
|
441 | + $return[] = \ElggMenuItem::factory([ |
|
442 | + 'name' => 'settings:advanced', |
|
443 | + 'href' => 'admin/settings/advanced', |
|
444 | + 'text' => elgg_echo('admin:settings:advanced'), |
|
445 | + 'priority' => 20, |
|
446 | + 'section' => 'configure', |
|
447 | + ]); |
|
448 | + $return[] = \ElggMenuItem::factory([ |
|
449 | + 'name' => 'security', |
|
450 | + 'href' => 'admin/security', |
|
451 | + 'text' => elgg_echo('admin:security'), |
|
452 | + 'priority' => 30, |
|
453 | + 'section' => 'configure', |
|
454 | + ]); |
|
455 | + |
|
456 | + $return[] = \ElggMenuItem::factory([ |
|
457 | + 'name' => 'configure_utilities', |
|
458 | + 'text' => elgg_echo('admin:configure_utilities'), |
|
459 | + 'priority' => 600, |
|
460 | + 'section' => 'configure', |
|
461 | + ]); |
|
462 | + $return[] = \ElggMenuItem::factory([ |
|
463 | + 'name' => 'configure_utilities:maintenance', |
|
464 | + 'text' => elgg_echo('admin:configure_utilities:maintenance'), |
|
465 | + 'href' => 'admin/configure_utilities/maintenance', |
|
466 | + 'section' => 'configure', |
|
467 | + 'parent_name' => 'configure_utilities', |
|
468 | + ]); |
|
469 | + $return[] = \ElggMenuItem::factory([ |
|
470 | + 'name' => 'configure_utilities:menu_items', |
|
471 | + 'text' => elgg_echo('admin:configure_utilities:menu_items'), |
|
472 | + 'href' => 'admin/configure_utilities/menu_items', |
|
473 | + 'section' => 'configure', |
|
474 | + 'parent_name' => 'configure_utilities', |
|
475 | + ]); |
|
476 | + $return[] = \ElggMenuItem::factory([ |
|
477 | + 'name' => 'configure_utilities:robots', |
|
478 | + 'text' => elgg_echo('admin:configure_utilities:robots'), |
|
479 | + 'href' => 'admin/configure_utilities/robots', |
|
480 | + 'section' => 'configure', |
|
481 | + 'parent_name' => 'configure_utilities', |
|
482 | + ]); |
|
483 | 483 | |
484 | - // information |
|
485 | - $return[] = \ElggMenuItem::factory([ |
|
486 | - 'name' => 'statistics', |
|
487 | - 'href' => 'admin/statistics', |
|
488 | - 'text' => elgg_echo('admin:statistics'), |
|
489 | - 'section' => 'information', |
|
490 | - ]); |
|
491 | - $return[] = \ElggMenuItem::factory([ |
|
492 | - 'name' => 'server', |
|
493 | - 'href' => 'admin/server', |
|
494 | - 'text' => elgg_echo('admin:server'), |
|
495 | - 'section' => 'information', |
|
496 | - ]); |
|
484 | + // information |
|
485 | + $return[] = \ElggMenuItem::factory([ |
|
486 | + 'name' => 'statistics', |
|
487 | + 'href' => 'admin/statistics', |
|
488 | + 'text' => elgg_echo('admin:statistics'), |
|
489 | + 'section' => 'information', |
|
490 | + ]); |
|
491 | + $return[] = \ElggMenuItem::factory([ |
|
492 | + 'name' => 'server', |
|
493 | + 'href' => 'admin/server', |
|
494 | + 'text' => elgg_echo('admin:server'), |
|
495 | + 'section' => 'information', |
|
496 | + ]); |
|
497 | 497 | |
498 | - return $return; |
|
498 | + return $return; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -511,56 +511,56 @@ discard block |
||
511 | 511 | * @since 3.0 |
512 | 512 | */ |
513 | 513 | function _elgg_admin_page_menu_plugin_settings(\Elgg\Hook $hook) { |
514 | - if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
515 | - return; |
|
516 | - } |
|
514 | + if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) { |
|
515 | + return; |
|
516 | + } |
|
517 | 517 | |
518 | - // plugin settings |
|
519 | - $active_plugins = elgg_get_plugins('active'); |
|
520 | - if (!$active_plugins) { |
|
521 | - // nothing added because no items |
|
522 | - return; |
|
523 | - } |
|
518 | + // plugin settings |
|
519 | + $active_plugins = elgg_get_plugins('active'); |
|
520 | + if (!$active_plugins) { |
|
521 | + // nothing added because no items |
|
522 | + return; |
|
523 | + } |
|
524 | 524 | |
525 | - $plugins_with_settings = []; |
|
525 | + $plugins_with_settings = []; |
|
526 | 526 | |
527 | - foreach ($active_plugins as $plugin) { |
|
528 | - $plugin_id = $plugin->getID(); |
|
527 | + foreach ($active_plugins as $plugin) { |
|
528 | + $plugin_id = $plugin->getID(); |
|
529 | 529 | |
530 | - if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) { |
|
531 | - continue; |
|
532 | - } |
|
533 | - $plugin_name = $plugin->getDisplayName(); |
|
534 | - $plugins_with_settings[$plugin_name] = [ |
|
535 | - 'name' => $plugin_id, |
|
536 | - 'href' => "admin/plugin_settings/$plugin_id", |
|
537 | - 'text' => $plugin_name, |
|
538 | - 'parent_name' => 'plugin_settings', |
|
539 | - 'section' => 'configure', |
|
540 | - ]; |
|
541 | - } |
|
530 | + if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) { |
|
531 | + continue; |
|
532 | + } |
|
533 | + $plugin_name = $plugin->getDisplayName(); |
|
534 | + $plugins_with_settings[$plugin_name] = [ |
|
535 | + 'name' => $plugin_id, |
|
536 | + 'href' => "admin/plugin_settings/$plugin_id", |
|
537 | + 'text' => $plugin_name, |
|
538 | + 'parent_name' => 'plugin_settings', |
|
539 | + 'section' => 'configure', |
|
540 | + ]; |
|
541 | + } |
|
542 | 542 | |
543 | - if (empty($plugins_with_settings)) { |
|
544 | - return; |
|
545 | - } |
|
543 | + if (empty($plugins_with_settings)) { |
|
544 | + return; |
|
545 | + } |
|
546 | 546 | |
547 | - $return = $hook->getValue(); |
|
547 | + $return = $hook->getValue(); |
|
548 | 548 | |
549 | - $return[] = \ElggMenuItem::factory([ |
|
550 | - 'name' => 'plugin_settings', |
|
551 | - 'text' => elgg_echo('admin:plugin_settings'), |
|
552 | - 'section' => 'configure', |
|
553 | - ]); |
|
549 | + $return[] = \ElggMenuItem::factory([ |
|
550 | + 'name' => 'plugin_settings', |
|
551 | + 'text' => elgg_echo('admin:plugin_settings'), |
|
552 | + 'section' => 'configure', |
|
553 | + ]); |
|
554 | 554 | |
555 | - ksort($plugins_with_settings); |
|
556 | - $priority = 0; |
|
557 | - foreach ($plugins_with_settings as $plugin_item) { |
|
558 | - $priority += 10; |
|
559 | - $plugin_item['priority'] = $priority; |
|
560 | - $return[] = \ElggMenuItem::factory($plugin_item); |
|
561 | - } |
|
555 | + ksort($plugins_with_settings); |
|
556 | + $priority = 0; |
|
557 | + foreach ($plugins_with_settings as $plugin_item) { |
|
558 | + $priority += 10; |
|
559 | + $plugin_item['priority'] = $priority; |
|
560 | + $return[] = \ElggMenuItem::factory($plugin_item); |
|
561 | + } |
|
562 | 562 | |
563 | - return $return; |
|
563 | + return $return; |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -572,53 +572,53 @@ discard block |
||
572 | 572 | * @access private |
573 | 573 | */ |
574 | 574 | function _elgg_admin_page_handler($page) { |
575 | - elgg_admin_gatekeeper(); |
|
576 | - elgg_set_context('admin'); |
|
577 | - |
|
578 | - elgg_unregister_css('elgg'); |
|
579 | - elgg_require_js('elgg/admin'); |
|
580 | - |
|
581 | - // default to dashboard |
|
582 | - if (!isset($page[0]) || empty($page[0])) { |
|
583 | - $page = ['dashboard']; |
|
584 | - } |
|
585 | - |
|
586 | - // was going to fix this in the page_handler() function but |
|
587 | - // it's commented to explicitly return a string if there's a trailing / |
|
588 | - if (empty($page[count($page) - 1])) { |
|
589 | - array_pop($page); |
|
590 | - } |
|
591 | - |
|
592 | - $vars = ['page' => $page]; |
|
593 | - |
|
594 | - // special page for plugin settings since we create the form for them |
|
595 | - if ($page[0] == 'plugin_settings') { |
|
596 | - if (isset($page[1]) && (elgg_view_exists("plugins/{$page[1]}/settings"))) { |
|
597 | - $view = 'admin/plugin_settings'; |
|
598 | - $plugin = elgg_get_plugin_from_id($page[1]); |
|
599 | - $vars['plugin'] = $plugin; |
|
600 | - |
|
601 | - $title = elgg_echo("admin:{$page[0]}"); |
|
602 | - } else { |
|
603 | - forward('', '404'); |
|
604 | - } |
|
605 | - } else { |
|
606 | - $view = 'admin/' . implode('/', $page); |
|
607 | - $title = elgg_echo("admin:{$page[0]}"); |
|
608 | - if (count($page) > 1) { |
|
609 | - $title .= ' : ' . elgg_echo('admin:' . implode(':', $page)); |
|
610 | - } |
|
611 | - } |
|
612 | - |
|
613 | - // gets content and prevents direct access to 'components' views |
|
614 | - if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) { |
|
615 | - $title = elgg_echo('admin:unknown_section'); |
|
616 | - $content = elgg_echo('admin:unknown_section'); |
|
617 | - } |
|
618 | - |
|
619 | - $body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]); |
|
620 | - echo elgg_view_page($title, $body, 'admin'); |
|
621 | - return true; |
|
575 | + elgg_admin_gatekeeper(); |
|
576 | + elgg_set_context('admin'); |
|
577 | + |
|
578 | + elgg_unregister_css('elgg'); |
|
579 | + elgg_require_js('elgg/admin'); |
|
580 | + |
|
581 | + // default to dashboard |
|
582 | + if (!isset($page[0]) || empty($page[0])) { |
|
583 | + $page = ['dashboard']; |
|
584 | + } |
|
585 | + |
|
586 | + // was going to fix this in the page_handler() function but |
|
587 | + // it's commented to explicitly return a string if there's a trailing / |
|
588 | + if (empty($page[count($page) - 1])) { |
|
589 | + array_pop($page); |
|
590 | + } |
|
591 | + |
|
592 | + $vars = ['page' => $page]; |
|
593 | + |
|
594 | + // special page for plugin settings since we create the form for them |
|
595 | + if ($page[0] == 'plugin_settings') { |
|
596 | + if (isset($page[1]) && (elgg_view_exists("plugins/{$page[1]}/settings"))) { |
|
597 | + $view = 'admin/plugin_settings'; |
|
598 | + $plugin = elgg_get_plugin_from_id($page[1]); |
|
599 | + $vars['plugin'] = $plugin; |
|
600 | + |
|
601 | + $title = elgg_echo("admin:{$page[0]}"); |
|
602 | + } else { |
|
603 | + forward('', '404'); |
|
604 | + } |
|
605 | + } else { |
|
606 | + $view = 'admin/' . implode('/', $page); |
|
607 | + $title = elgg_echo("admin:{$page[0]}"); |
|
608 | + if (count($page) > 1) { |
|
609 | + $title .= ' : ' . elgg_echo('admin:' . implode(':', $page)); |
|
610 | + } |
|
611 | + } |
|
612 | + |
|
613 | + // gets content and prevents direct access to 'components' views |
|
614 | + if ($page[0] == 'components' || !($content = elgg_view($view, $vars))) { |
|
615 | + $title = elgg_echo('admin:unknown_section'); |
|
616 | + $content = elgg_echo('admin:unknown_section'); |
|
617 | + } |
|
618 | + |
|
619 | + $body = elgg_view_layout('admin', ['content' => $content, 'title' => $title]); |
|
620 | + echo elgg_view_page($title, $body, 'admin'); |
|
621 | + return true; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -638,13 +638,13 @@ discard block |
||
638 | 638 | * @access private |
639 | 639 | */ |
640 | 640 | function _elgg_admin_markdown_page_handler($pages) { |
641 | - elgg_set_context('admin'); |
|
641 | + elgg_set_context('admin'); |
|
642 | 642 | |
643 | - echo elgg_view_resource('admin/plugin_text_file', [ |
|
644 | - 'plugin_id' => elgg_extract(0, $pages), |
|
645 | - 'filename' => elgg_extract(1, $pages), |
|
646 | - ]); |
|
647 | - return true; |
|
643 | + echo elgg_view_resource('admin/plugin_text_file', [ |
|
644 | + 'plugin_id' => elgg_extract(0, $pages), |
|
645 | + 'filename' => elgg_extract(1, $pages), |
|
646 | + ]); |
|
647 | + return true; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -653,8 +653,8 @@ discard block |
||
653 | 653 | * @access private |
654 | 654 | */ |
655 | 655 | function _elgg_robots_page_handler() { |
656 | - echo elgg_view_resource('robots.txt'); |
|
657 | - return true; |
|
656 | + echo elgg_view_resource('robots.txt'); |
|
657 | + return true; |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | * @access private |
664 | 664 | */ |
665 | 665 | function _elgg_phpinfo_page_handler() { |
666 | - echo elgg_view_resource('phpinfo'); |
|
667 | - return true; |
|
666 | + echo elgg_view_resource('phpinfo'); |
|
667 | + return true; |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | /** |
@@ -676,20 +676,20 @@ discard block |
||
676 | 676 | * @access private |
677 | 677 | */ |
678 | 678 | function _elgg_admin_maintenance_allow_url($current_url) { |
679 | - $site_path = preg_replace('~^https?~', '', elgg_get_site_url()); |
|
680 | - $current_path = preg_replace('~^https?~', '', $current_url); |
|
681 | - if (0 === strpos($current_path, $site_path)) { |
|
682 | - $current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path)); |
|
683 | - } else { |
|
684 | - $current_path = false; |
|
685 | - } |
|
686 | - |
|
687 | - // allow plugins to control access for specific URLs/paths |
|
688 | - $params = [ |
|
689 | - 'current_path' => $current_path, |
|
690 | - 'current_url' => $current_url, |
|
691 | - ]; |
|
692 | - return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false); |
|
679 | + $site_path = preg_replace('~^https?~', '', elgg_get_site_url()); |
|
680 | + $current_path = preg_replace('~^https?~', '', $current_url); |
|
681 | + if (0 === strpos($current_path, $site_path)) { |
|
682 | + $current_path = ($current_path === $site_path) ? '' : substr($current_path, strlen($site_path)); |
|
683 | + } else { |
|
684 | + $current_path = false; |
|
685 | + } |
|
686 | + |
|
687 | + // allow plugins to control access for specific URLs/paths |
|
688 | + $params = [ |
|
689 | + 'current_path' => $current_path, |
|
690 | + 'current_url' => $current_url, |
|
691 | + ]; |
|
692 | + return (bool) elgg_trigger_plugin_hook('maintenance:allow', 'url', $params, false); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | /** |
@@ -698,23 +698,23 @@ discard block |
||
698 | 698 | * @access private |
699 | 699 | */ |
700 | 700 | function _elgg_admin_maintenance_handler($hook, $type, $info) { |
701 | - if (elgg_is_admin_logged_in()) { |
|
702 | - return; |
|
703 | - } |
|
701 | + if (elgg_is_admin_logged_in()) { |
|
702 | + return; |
|
703 | + } |
|
704 | 704 | |
705 | - if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') { |
|
706 | - return; |
|
707 | - } |
|
705 | + if ($info['identifier'] == 'action' && $info['segments'][0] == 'login') { |
|
706 | + return; |
|
707 | + } |
|
708 | 708 | |
709 | - if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
710 | - return; |
|
711 | - } |
|
709 | + if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
710 | + return; |
|
711 | + } |
|
712 | 712 | |
713 | - elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup'); |
|
713 | + elgg_unregister_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup'); |
|
714 | 714 | |
715 | - echo elgg_view_resource('maintenance'); |
|
715 | + echo elgg_view_resource('maintenance'); |
|
716 | 716 | |
717 | - return false; |
|
717 | + return false; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -727,34 +727,34 @@ discard block |
||
727 | 727 | * @return bool |
728 | 728 | */ |
729 | 729 | function _elgg_admin_maintenance_action_check($hook, $type) { |
730 | - if (elgg_is_admin_logged_in()) { |
|
731 | - return true; |
|
732 | - } |
|
730 | + if (elgg_is_admin_logged_in()) { |
|
731 | + return true; |
|
732 | + } |
|
733 | 733 | |
734 | - if ($type == 'login') { |
|
735 | - $username = get_input('username'); |
|
734 | + if ($type == 'login') { |
|
735 | + $username = get_input('username'); |
|
736 | 736 | |
737 | - $user = get_user_by_username($username); |
|
737 | + $user = get_user_by_username($username); |
|
738 | 738 | |
739 | - if (!$user) { |
|
740 | - $users = get_user_by_email($username); |
|
741 | - if ($users) { |
|
742 | - $user = $users[0]; |
|
743 | - } |
|
744 | - } |
|
739 | + if (!$user) { |
|
740 | + $users = get_user_by_email($username); |
|
741 | + if ($users) { |
|
742 | + $user = $users[0]; |
|
743 | + } |
|
744 | + } |
|
745 | 745 | |
746 | - if ($user && $user->isAdmin()) { |
|
747 | - return true; |
|
748 | - } |
|
749 | - } |
|
746 | + if ($user && $user->isAdmin()) { |
|
747 | + return true; |
|
748 | + } |
|
749 | + } |
|
750 | 750 | |
751 | - if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
752 | - return true; |
|
753 | - } |
|
751 | + if (_elgg_admin_maintenance_allow_url(current_page_url())) { |
|
752 | + return true; |
|
753 | + } |
|
754 | 754 | |
755 | - register_error(elgg_echo('actionunauthorized')); |
|
755 | + register_error(elgg_echo('actionunauthorized')); |
|
756 | 756 | |
757 | - return false; |
|
757 | + return false; |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
@@ -768,30 +768,30 @@ discard block |
||
768 | 768 | * @access private |
769 | 769 | */ |
770 | 770 | function _elgg_add_admin_widgets($event, $type, $user) { |
771 | - elgg_set_ignore_access(true); |
|
772 | - |
|
773 | - // check if the user already has widgets |
|
774 | - if (elgg_get_widgets($user->getGUID(), 'admin')) { |
|
775 | - return true; |
|
776 | - } |
|
777 | - |
|
778 | - // In the form column => array of handlers in order, top to bottom |
|
779 | - $adminWidgets = [ |
|
780 | - 1 => ['control_panel', 'admin_welcome'], |
|
781 | - 2 => ['online_users', 'new_users', 'content_stats'], |
|
782 | - ]; |
|
783 | - |
|
784 | - foreach ($adminWidgets as $column => $handlers) { |
|
785 | - foreach ($handlers as $position => $handler) { |
|
786 | - $guid = elgg_create_widget($user->getGUID(), $handler, 'admin'); |
|
787 | - if ($guid) { |
|
788 | - $widget = get_entity($guid); |
|
789 | - /* @var \ElggWidget $widget */ |
|
790 | - $widget->move($column, $position); |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - elgg_set_ignore_access(false); |
|
771 | + elgg_set_ignore_access(true); |
|
772 | + |
|
773 | + // check if the user already has widgets |
|
774 | + if (elgg_get_widgets($user->getGUID(), 'admin')) { |
|
775 | + return true; |
|
776 | + } |
|
777 | + |
|
778 | + // In the form column => array of handlers in order, top to bottom |
|
779 | + $adminWidgets = [ |
|
780 | + 1 => ['control_panel', 'admin_welcome'], |
|
781 | + 2 => ['online_users', 'new_users', 'content_stats'], |
|
782 | + ]; |
|
783 | + |
|
784 | + foreach ($adminWidgets as $column => $handlers) { |
|
785 | + foreach ($handlers as $position => $handler) { |
|
786 | + $guid = elgg_create_widget($user->getGUID(), $handler, 'admin'); |
|
787 | + if ($guid) { |
|
788 | + $widget = get_entity($guid); |
|
789 | + /* @var \ElggWidget $widget */ |
|
790 | + $widget->move($column, $position); |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + elgg_set_ignore_access(false); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | /** |
@@ -806,39 +806,39 @@ discard block |
||
806 | 806 | */ |
807 | 807 | function _elgg_admin_get_admin_subscribers_admin_action($hook, $type, $return_value, $params) { |
808 | 808 | |
809 | - if (!_elgg_config()->security_notify_admins) { |
|
810 | - return; |
|
811 | - } |
|
809 | + if (!_elgg_config()->security_notify_admins) { |
|
810 | + return; |
|
811 | + } |
|
812 | 812 | |
813 | - $event = elgg_extract('event', $params); |
|
814 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
815 | - return; |
|
816 | - } |
|
813 | + $event = elgg_extract('event', $params); |
|
814 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
815 | + return; |
|
816 | + } |
|
817 | 817 | |
818 | - if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
819 | - return; |
|
820 | - } |
|
818 | + if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
819 | + return; |
|
820 | + } |
|
821 | 821 | |
822 | - $user = $event->getObject(); |
|
823 | - if (!($user instanceof \ElggUser)) { |
|
824 | - return; |
|
825 | - } |
|
822 | + $user = $event->getObject(); |
|
823 | + if (!($user instanceof \ElggUser)) { |
|
824 | + return; |
|
825 | + } |
|
826 | 826 | |
827 | - /* @var $admin_batch \Elgg\BatchResult */ |
|
828 | - $admin_batch = elgg_get_admins([ |
|
829 | - 'limit' => false, |
|
830 | - 'wheres' => [ |
|
831 | - "e.guid <> {$user->getGUID()}", |
|
832 | - ], |
|
833 | - 'batch' => true, |
|
834 | - ]); |
|
827 | + /* @var $admin_batch \Elgg\BatchResult */ |
|
828 | + $admin_batch = elgg_get_admins([ |
|
829 | + 'limit' => false, |
|
830 | + 'wheres' => [ |
|
831 | + "e.guid <> {$user->getGUID()}", |
|
832 | + ], |
|
833 | + 'batch' => true, |
|
834 | + ]); |
|
835 | 835 | |
836 | - /* @var $admin \ElggUser */ |
|
837 | - foreach ($admin_batch as $admin) { |
|
838 | - $return_value[$admin->getGUID()] = ['email']; |
|
839 | - } |
|
836 | + /* @var $admin \ElggUser */ |
|
837 | + foreach ($admin_batch as $admin) { |
|
838 | + $return_value[$admin->getGUID()] = ['email']; |
|
839 | + } |
|
840 | 840 | |
841 | - return $return_value; |
|
841 | + return $return_value; |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -853,39 +853,39 @@ discard block |
||
853 | 853 | */ |
854 | 854 | function _elgg_admin_prepare_admin_notification_make_admin($hook, $type, $return_value, $params) { |
855 | 855 | |
856 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
857 | - return; |
|
858 | - } |
|
856 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
857 | + return; |
|
858 | + } |
|
859 | 859 | |
860 | - $recipient = elgg_extract('recipient', $params); |
|
861 | - $object = elgg_extract('object', $params); |
|
862 | - $actor = elgg_extract('sender', $params); |
|
863 | - $language = elgg_extract('language', $params); |
|
860 | + $recipient = elgg_extract('recipient', $params); |
|
861 | + $object = elgg_extract('object', $params); |
|
862 | + $actor = elgg_extract('sender', $params); |
|
863 | + $language = elgg_extract('language', $params); |
|
864 | 864 | |
865 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
866 | - return; |
|
867 | - } |
|
865 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
866 | + return; |
|
867 | + } |
|
868 | 868 | |
869 | - if ($recipient->getGUID() === $object->getGUID()) { |
|
870 | - // recipient is the user being acted on, this is handled elsewhere |
|
871 | - return; |
|
872 | - } |
|
869 | + if ($recipient->getGUID() === $object->getGUID()) { |
|
870 | + // recipient is the user being acted on, this is handled elsewhere |
|
871 | + return; |
|
872 | + } |
|
873 | 873 | |
874 | - $site = elgg_get_site_entity(); |
|
874 | + $site = elgg_get_site_entity(); |
|
875 | 875 | |
876 | - $return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language); |
|
877 | - $return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [ |
|
878 | - $recipient->name, |
|
879 | - $actor->name, |
|
880 | - $object->name, |
|
881 | - $site->name, |
|
882 | - $object->getURL(), |
|
883 | - $site->getURL(), |
|
884 | - ], $language); |
|
885 | - |
|
886 | - $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
876 | + $return_value->subject = elgg_echo('admin:notification:make_admin:admin:subject', [$site->name], $language); |
|
877 | + $return_value->body = elgg_echo('admin:notification:make_admin:admin:body', [ |
|
878 | + $recipient->name, |
|
879 | + $actor->name, |
|
880 | + $object->name, |
|
881 | + $site->name, |
|
882 | + $object->getURL(), |
|
883 | + $site->getURL(), |
|
884 | + ], $language); |
|
885 | + |
|
886 | + $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
887 | 887 | |
888 | - return $return_value; |
|
888 | + return $return_value; |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -900,39 +900,39 @@ discard block |
||
900 | 900 | */ |
901 | 901 | function _elgg_admin_prepare_admin_notification_remove_admin($hook, $type, $return_value, $params) { |
902 | 902 | |
903 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
904 | - return; |
|
905 | - } |
|
903 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
904 | + return; |
|
905 | + } |
|
906 | 906 | |
907 | - $recipient = elgg_extract('recipient', $params); |
|
908 | - $object = elgg_extract('object', $params); |
|
909 | - $actor = elgg_extract('sender', $params); |
|
910 | - $language = elgg_extract('language', $params); |
|
907 | + $recipient = elgg_extract('recipient', $params); |
|
908 | + $object = elgg_extract('object', $params); |
|
909 | + $actor = elgg_extract('sender', $params); |
|
910 | + $language = elgg_extract('language', $params); |
|
911 | 911 | |
912 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
913 | - return; |
|
914 | - } |
|
912 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
913 | + return; |
|
914 | + } |
|
915 | 915 | |
916 | - if ($recipient->getGUID() === $object->getGUID()) { |
|
917 | - // recipient is the user being acted on, this is handled elsewhere |
|
918 | - return; |
|
919 | - } |
|
916 | + if ($recipient->getGUID() === $object->getGUID()) { |
|
917 | + // recipient is the user being acted on, this is handled elsewhere |
|
918 | + return; |
|
919 | + } |
|
920 | 920 | |
921 | - $site = elgg_get_site_entity(); |
|
921 | + $site = elgg_get_site_entity(); |
|
922 | 922 | |
923 | - $return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language); |
|
924 | - $return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [ |
|
925 | - $recipient->name, |
|
926 | - $actor->name, |
|
927 | - $object->name, |
|
928 | - $site->name, |
|
929 | - $object->getURL(), |
|
930 | - $site->getURL(), |
|
931 | - ], $language); |
|
932 | - |
|
933 | - $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
923 | + $return_value->subject = elgg_echo('admin:notification:remove_admin:admin:subject', [$site->name], $language); |
|
924 | + $return_value->body = elgg_echo('admin:notification:remove_admin:admin:body', [ |
|
925 | + $recipient->name, |
|
926 | + $actor->name, |
|
927 | + $object->name, |
|
928 | + $site->name, |
|
929 | + $object->getURL(), |
|
930 | + $site->getURL(), |
|
931 | + ], $language); |
|
932 | + |
|
933 | + $return_value->url = elgg_normalize_url('admin/users/admins'); |
|
934 | 934 | |
935 | - return $return_value; |
|
935 | + return $return_value; |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -947,27 +947,27 @@ discard block |
||
947 | 947 | */ |
948 | 948 | function _elgg_admin_get_user_subscriber_admin_action($hook, $type, $return_value, $params) { |
949 | 949 | |
950 | - if (!_elgg_config()->security_notify_user_admin) { |
|
951 | - return; |
|
952 | - } |
|
950 | + if (!_elgg_config()->security_notify_user_admin) { |
|
951 | + return; |
|
952 | + } |
|
953 | 953 | |
954 | - $event = elgg_extract('event', $params); |
|
955 | - if (!($event instanceof \Elgg\Notifications\Event)) { |
|
956 | - return; |
|
957 | - } |
|
954 | + $event = elgg_extract('event', $params); |
|
955 | + if (!($event instanceof \Elgg\Notifications\Event)) { |
|
956 | + return; |
|
957 | + } |
|
958 | 958 | |
959 | - if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
960 | - return; |
|
961 | - } |
|
959 | + if (!in_array($event->getAction(), ['make_admin', 'remove_admin'])) { |
|
960 | + return; |
|
961 | + } |
|
962 | 962 | |
963 | - $user = $event->getObject(); |
|
964 | - if (!($user instanceof \ElggUser)) { |
|
965 | - return; |
|
966 | - } |
|
963 | + $user = $event->getObject(); |
|
964 | + if (!($user instanceof \ElggUser)) { |
|
965 | + return; |
|
966 | + } |
|
967 | 967 | |
968 | - $return_value[$user->getGUID()] = ['email']; |
|
968 | + $return_value[$user->getGUID()] = ['email']; |
|
969 | 969 | |
970 | - return $return_value; |
|
970 | + return $return_value; |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
@@ -982,37 +982,37 @@ discard block |
||
982 | 982 | */ |
983 | 983 | function _elgg_admin_prepare_user_notification_make_admin($hook, $type, $return_value, $params) { |
984 | 984 | |
985 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
986 | - return; |
|
987 | - } |
|
985 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
986 | + return; |
|
987 | + } |
|
988 | 988 | |
989 | - $recipient = elgg_extract('recipient', $params); |
|
990 | - $object = elgg_extract('object', $params); |
|
991 | - $actor = elgg_extract('sender', $params); |
|
992 | - $language = elgg_extract('language', $params); |
|
989 | + $recipient = elgg_extract('recipient', $params); |
|
990 | + $object = elgg_extract('object', $params); |
|
991 | + $actor = elgg_extract('sender', $params); |
|
992 | + $language = elgg_extract('language', $params); |
|
993 | 993 | |
994 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
995 | - return; |
|
996 | - } |
|
994 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
995 | + return; |
|
996 | + } |
|
997 | 997 | |
998 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
999 | - // recipient is some other user, this is handled elsewhere |
|
1000 | - return; |
|
1001 | - } |
|
998 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
999 | + // recipient is some other user, this is handled elsewhere |
|
1000 | + return; |
|
1001 | + } |
|
1002 | 1002 | |
1003 | - $site = elgg_get_site_entity(); |
|
1003 | + $site = elgg_get_site_entity(); |
|
1004 | 1004 | |
1005 | - $return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language); |
|
1006 | - $return_value->body = elgg_echo('admin:notification:make_admin:user:body', [ |
|
1007 | - $recipient->name, |
|
1008 | - $actor->name, |
|
1009 | - $site->name, |
|
1010 | - $site->getURL(), |
|
1011 | - ], $language); |
|
1012 | - |
|
1013 | - $return_value->url = elgg_normalize_url('admin'); |
|
1005 | + $return_value->subject = elgg_echo('admin:notification:make_admin:user:subject', [$site->name], $language); |
|
1006 | + $return_value->body = elgg_echo('admin:notification:make_admin:user:body', [ |
|
1007 | + $recipient->name, |
|
1008 | + $actor->name, |
|
1009 | + $site->name, |
|
1010 | + $site->getURL(), |
|
1011 | + ], $language); |
|
1012 | + |
|
1013 | + $return_value->url = elgg_normalize_url('admin'); |
|
1014 | 1014 | |
1015 | - return $return_value; |
|
1015 | + return $return_value; |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
@@ -1027,42 +1027,42 @@ discard block |
||
1027 | 1027 | */ |
1028 | 1028 | function _elgg_admin_prepare_user_notification_remove_admin($hook, $type, $return_value, $params) { |
1029 | 1029 | |
1030 | - if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
1031 | - return; |
|
1032 | - } |
|
1030 | + if (!($return_value instanceof \Elgg\Notifications\Notification)) { |
|
1031 | + return; |
|
1032 | + } |
|
1033 | 1033 | |
1034 | - $recipient = elgg_extract('recipient', $params); |
|
1035 | - $object = elgg_extract('object', $params); |
|
1036 | - $actor = elgg_extract('sender', $params); |
|
1037 | - $language = elgg_extract('language', $params); |
|
1034 | + $recipient = elgg_extract('recipient', $params); |
|
1035 | + $object = elgg_extract('object', $params); |
|
1036 | + $actor = elgg_extract('sender', $params); |
|
1037 | + $language = elgg_extract('language', $params); |
|
1038 | 1038 | |
1039 | - if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
1040 | - return; |
|
1041 | - } |
|
1039 | + if (!($recipient instanceof ElggUser) || !($object instanceof ElggUser) || !($actor instanceof ElggUser)) { |
|
1040 | + return; |
|
1041 | + } |
|
1042 | 1042 | |
1043 | - if ($recipient->getGUID() !== $object->getGUID()) { |
|
1044 | - // recipient is some other user, this is handled elsewhere |
|
1045 | - return; |
|
1046 | - } |
|
1043 | + if ($recipient->getGUID() !== $object->getGUID()) { |
|
1044 | + // recipient is some other user, this is handled elsewhere |
|
1045 | + return; |
|
1046 | + } |
|
1047 | 1047 | |
1048 | - $site = elgg_get_site_entity(); |
|
1048 | + $site = elgg_get_site_entity(); |
|
1049 | 1049 | |
1050 | - $return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language); |
|
1051 | - $return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [ |
|
1052 | - $recipient->name, |
|
1053 | - $actor->name, |
|
1054 | - $site->name, |
|
1055 | - $site->getURL(), |
|
1056 | - ], $language); |
|
1057 | - |
|
1058 | - $return_value->url = false; |
|
1050 | + $return_value->subject = elgg_echo('admin:notification:remove_admin:user:subject', [$site->name], $language); |
|
1051 | + $return_value->body = elgg_echo('admin:notification:remove_admin:user:body', [ |
|
1052 | + $recipient->name, |
|
1053 | + $actor->name, |
|
1054 | + $site->name, |
|
1055 | + $site->getURL(), |
|
1056 | + ], $language); |
|
1057 | + |
|
1058 | + $return_value->url = false; |
|
1059 | 1059 | |
1060 | - return $return_value; |
|
1060 | + return $return_value; |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** |
1064 | 1064 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
1065 | 1065 | */ |
1066 | 1066 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
1067 | - $events->registerHandler('init', 'system', '_elgg_admin_init'); |
|
1067 | + $events->registerHandler('init', 'system', '_elgg_admin_init'); |
|
1068 | 1068 | }; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param int $id The id of the annotation object being retrieved. |
33 | 33 | * |
34 | - * @return \ElggAnnotation|false |
|
34 | + * @return ElggExtender |
|
35 | 35 | */ |
36 | 36 | function elgg_get_annotation_from_id($id) { |
37 | 37 | return _elgg_services()->annotations->get($id); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @param string $hook |
330 | 330 | * @param string $type |
331 | 331 | * @param array $tests |
332 | - * @return array |
|
332 | + * @return string[] |
|
333 | 333 | * @access private |
334 | 334 | */ |
335 | 335 | function _elgg_annotations_test($hook, $type, $tests) { |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | * @access private |
19 | 19 | */ |
20 | 20 | function row_to_elggannotation($row) { |
21 | - if (!($row instanceof \stdClass)) { |
|
22 | - // @todo should throw in this case? |
|
23 | - return $row; |
|
24 | - } |
|
21 | + if (!($row instanceof \stdClass)) { |
|
22 | + // @todo should throw in this case? |
|
23 | + return $row; |
|
24 | + } |
|
25 | 25 | |
26 | - return new \ElggAnnotation($row); |
|
26 | + return new \ElggAnnotation($row); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @return \ElggAnnotation|false |
37 | 37 | */ |
38 | 38 | function elgg_get_annotation_from_id($id) { |
39 | - return _elgg_services()->annotations->get($id); |
|
39 | + return _elgg_services()->annotations->get($id); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return bool |
47 | 47 | */ |
48 | 48 | function elgg_delete_annotation_by_id($id) { |
49 | - return _elgg_services()->annotations->delete($id); |
|
49 | + return _elgg_services()->annotations->delete($id); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * @return int|bool id on success or false on failure |
63 | 63 | */ |
64 | 64 | function create_annotation($entity_guid, $name, $value, $value_type = '', |
65 | - $owner_guid = 0, $access_id = ACCESS_PRIVATE) { |
|
66 | - return _elgg_services()->annotations->create( |
|
67 | - $entity_guid, $name, $value, $value_type, $owner_guid, $access_id); |
|
65 | + $owner_guid = 0, $access_id = ACCESS_PRIVATE) { |
|
66 | + return _elgg_services()->annotations->create( |
|
67 | + $entity_guid, $name, $value, $value_type, $owner_guid, $access_id); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | */ |
82 | 82 | function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id) { |
83 | - return _elgg_services()->annotations->update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id); |
|
83 | + return _elgg_services()->annotations->update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @since 1.8.0 |
114 | 114 | */ |
115 | 115 | function elgg_get_annotations(array $options = []) { |
116 | - return _elgg_services()->annotations->find($options); |
|
116 | + return _elgg_services()->annotations->find($options); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | * @since 1.8.0 |
127 | 127 | */ |
128 | 128 | function elgg_list_annotations($options) { |
129 | - $defaults = [ |
|
130 | - 'limit' => 25, |
|
131 | - 'offset' => (int) max(get_input('annoff', 0), 0), |
|
132 | - 'no_results' => '', |
|
133 | - ]; |
|
129 | + $defaults = [ |
|
130 | + 'limit' => 25, |
|
131 | + 'offset' => (int) max(get_input('annoff', 0), 0), |
|
132 | + 'no_results' => '', |
|
133 | + ]; |
|
134 | 134 | |
135 | - $options = array_merge($defaults, $options); |
|
135 | + $options = array_merge($defaults, $options); |
|
136 | 136 | |
137 | - return elgg_list_entities($options, 'elgg_get_annotations', 'elgg_view_annotation_list'); |
|
137 | + return elgg_list_entities($options, 'elgg_get_annotations', 'elgg_view_annotation_list'); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @since 1.8.0 |
150 | 150 | */ |
151 | 151 | function elgg_delete_annotations(array $options) { |
152 | - return _elgg_services()->annotations->deleteAll($options); |
|
152 | + return _elgg_services()->annotations->deleteAll($options); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @since 1.8.0 |
163 | 163 | */ |
164 | 164 | function elgg_disable_annotations(array $options) { |
165 | - return _elgg_services()->annotations->disableAll($options); |
|
165 | + return _elgg_services()->annotations->disableAll($options); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @since 1.8.0 |
179 | 179 | */ |
180 | 180 | function elgg_enable_annotations(array $options) { |
181 | - return _elgg_services()->annotations->enableAll($options); |
|
181 | + return _elgg_services()->annotations->enableAll($options); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @since 1.7.0 |
219 | 219 | */ |
220 | 220 | function elgg_get_entities_from_annotations(array $options = []) { |
221 | - return _elgg_services()->annotations->getEntities($options); |
|
221 | + return _elgg_services()->annotations->getEntities($options); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | */ |
234 | 234 | function elgg_list_entities_from_annotations($options = []) { |
235 | - return elgg_list_entities($options, 'elgg_get_entities_from_annotations'); |
|
235 | + return elgg_list_entities($options, 'elgg_get_entities_from_annotations'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @see elgg_get_entities_from_annotations() |
269 | 269 | */ |
270 | 270 | function elgg_get_entities_from_annotation_calculation($options) { |
271 | - return _elgg_services()->annotations->getEntitiesFromCalculation($options); |
|
271 | + return _elgg_services()->annotations->getEntitiesFromCalculation($options); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | * @return string |
282 | 282 | */ |
283 | 283 | function elgg_list_entities_from_annotation_calculation($options) { |
284 | - $defaults = [ |
|
285 | - 'calculation' => 'sum', |
|
286 | - 'order_by' => 'annotation_calculation desc' |
|
287 | - ]; |
|
288 | - $options = array_merge($defaults, $options); |
|
284 | + $defaults = [ |
|
285 | + 'calculation' => 'sum', |
|
286 | + 'order_by' => 'annotation_calculation desc' |
|
287 | + ]; |
|
288 | + $options = array_merge($defaults, $options); |
|
289 | 289 | |
290 | - return elgg_list_entities($options, 'elgg_get_entities_from_annotation_calculation'); |
|
290 | + return elgg_list_entities($options, 'elgg_get_entities_from_annotation_calculation'); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @since 1.8.0 |
302 | 302 | */ |
303 | 303 | function elgg_annotation_exists($entity_guid, $annotation_type, $owner_guid = null) { |
304 | - return _elgg_services()->annotations->exists($entity_guid, $annotation_type, $owner_guid); |
|
304 | + return _elgg_services()->annotations->exists($entity_guid, $annotation_type, $owner_guid); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -315,14 +315,14 @@ discard block |
||
315 | 315 | * @access private |
316 | 316 | */ |
317 | 317 | function _elgg_set_comment_url($hook, $type, $url, $params) { |
318 | - $annotation = $params['extender']; |
|
319 | - /* @var \ElggExtender $annotation */ |
|
320 | - if ($annotation->getSubtype() == 'generic_comment') { |
|
321 | - $entity = $annotation->getEntity(); |
|
322 | - if ($entity) { |
|
323 | - return $entity->getURL() . '#item-annotation-' . $annotation->id; |
|
324 | - } |
|
325 | - } |
|
318 | + $annotation = $params['extender']; |
|
319 | + /* @var \ElggExtender $annotation */ |
|
320 | + if ($annotation->getSubtype() == 'generic_comment') { |
|
321 | + $entity = $annotation->getEntity(); |
|
322 | + if ($entity) { |
|
323 | + return $entity->getURL() . '#item-annotation-' . $annotation->id; |
|
324 | + } |
|
325 | + } |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | * @access private |
336 | 336 | */ |
337 | 337 | function _elgg_annotations_test($hook, $type, $tests) { |
338 | - $tests[] = Paths::project() . 'engine/tests/ElggCoreAnnotationAPITest.php'; |
|
339 | - return $tests; |
|
338 | + $tests[] = Paths::project() . 'engine/tests/ElggCoreAnnotationAPITest.php'; |
|
339 | + return $tests; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -344,13 +344,13 @@ discard block |
||
344 | 344 | * @access private |
345 | 345 | */ |
346 | 346 | function _elgg_annotations_init() { |
347 | - elgg_register_plugin_hook_handler('extender:url', 'annotation', '_elgg_set_comment_url'); |
|
348 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_annotations_test'); |
|
347 | + elgg_register_plugin_hook_handler('extender:url', 'annotation', '_elgg_set_comment_url'); |
|
348 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_annotations_test'); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | 352 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
353 | 353 | */ |
354 | 354 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
355 | - $events->registerHandler('init', 'system', '_elgg_annotations_init'); |
|
355 | + $events->registerHandler('init', 'system', '_elgg_annotations_init'); |
|
356 | 356 | }; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | if ($annotation->getSubtype() == 'generic_comment') { |
321 | 321 | $entity = $annotation->getEntity(); |
322 | 322 | if ($entity) { |
323 | - return $entity->getURL() . '#item-annotation-' . $annotation->id; |
|
323 | + return $entity->getURL().'#item-annotation-'.$annotation->id; |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * @access private |
336 | 336 | */ |
337 | 337 | function _elgg_annotations_test($hook, $type, $tests) { |
338 | - $tests[] = Paths::project() . 'engine/tests/ElggCoreAnnotationAPITest.php'; |
|
338 | + $tests[] = Paths::project().'engine/tests/ElggCoreAnnotationAPITest.php'; |
|
339 | 339 | return $tests; |
340 | 340 | } |
341 | 341 |