@@ -106,7 +106,7 @@ |
||
106 | 106 | * @param string $type Hook type |
107 | 107 | * @param array $value Array of unit test locations |
108 | 108 | * |
109 | - * @return array |
|
109 | + * @return string[] |
|
110 | 110 | * @access private |
111 | 111 | */ |
112 | 112 | function _elgg_groups_test($hook, $type, $value) { |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | * @access private |
20 | 20 | */ |
21 | 21 | function get_group_entity_as_row($guid) { |
22 | - $guid = (int) $guid; |
|
22 | + $guid = (int) $guid; |
|
23 | 23 | |
24 | - $prefix = _elgg_config()->dbprefix; |
|
25 | - return get_data_row("SELECT * from {$prefix}groups_entity where guid=$guid"); |
|
24 | + $prefix = _elgg_config()->dbprefix; |
|
25 | + return get_data_row("SELECT * from {$prefix}groups_entity where guid=$guid"); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * @since 1.5.0 |
39 | 39 | */ |
40 | 40 | function add_group_tool_option($name, $label, $default_on = true) { |
41 | - $options = _elgg_config()->group_tool_options; |
|
42 | - if (!$options) { |
|
43 | - $options = []; |
|
44 | - } |
|
45 | - $options[] = (object) [ |
|
46 | - 'name' => $name, |
|
47 | - 'label' => $label, |
|
48 | - 'default_on' => $default_on, |
|
49 | - ]; |
|
50 | - _elgg_config()->group_tool_options = $options; |
|
41 | + $options = _elgg_config()->group_tool_options; |
|
42 | + if (!$options) { |
|
43 | + $options = []; |
|
44 | + } |
|
45 | + $options[] = (object) [ |
|
46 | + 'name' => $name, |
|
47 | + 'label' => $label, |
|
48 | + 'default_on' => $default_on, |
|
49 | + ]; |
|
50 | + _elgg_config()->group_tool_options = $options; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | * @since 1.7.5 |
62 | 62 | */ |
63 | 63 | function remove_group_tool_option($name) { |
64 | - $options = _elgg_config()->group_tool_options; |
|
65 | - if (!is_array($options)) { |
|
66 | - return; |
|
67 | - } |
|
64 | + $options = _elgg_config()->group_tool_options; |
|
65 | + if (!is_array($options)) { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - foreach ($options as $i => $option) { |
|
70 | - if ($option->name == $name) { |
|
71 | - unset($options[$i]); |
|
72 | - } |
|
73 | - } |
|
69 | + foreach ($options as $i => $option) { |
|
70 | + if ($option->name == $name) { |
|
71 | + unset($options[$i]); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - _elgg_config()->group_tool_options = $options; |
|
75 | + _elgg_config()->group_tool_options = $options; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | * @access private |
87 | 87 | */ |
88 | 88 | function _elgg_groups_container_override($hook, $type, $result, $params) { |
89 | - $container = $params['container']; |
|
90 | - $user = $params['user']; |
|
91 | - if (elgg_instanceof($container, 'group') && $user) { |
|
92 | - /* @var \ElggGroup $container */ |
|
93 | - if ($container->isMember($user)) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - } |
|
89 | + $container = $params['container']; |
|
90 | + $user = $params['user']; |
|
91 | + if (elgg_instanceof($container, 'group') && $user) { |
|
92 | + /* @var \ElggGroup $container */ |
|
93 | + if ($container->isMember($user)) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $result; |
|
98 | + return $result; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @access private |
110 | 110 | */ |
111 | 111 | function _elgg_groups_test($hook, $type, $value) { |
112 | - $value[] = Paths::elgg() . 'engine/tests/ElggGroupTest.php'; |
|
113 | - return $value; |
|
112 | + $value[] = Paths::elgg() . 'engine/tests/ElggGroupTest.php'; |
|
113 | + return $value; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | * @access private |
119 | 119 | */ |
120 | 120 | function _elgg_groups_init() { |
121 | - elgg_register_plugin_hook_handler('container_permissions_check', 'all', '_elgg_groups_container_override'); |
|
122 | - elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_groups_test'); |
|
121 | + elgg_register_plugin_hook_handler('container_permissions_check', 'all', '_elgg_groups_container_override'); |
|
122 | + elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_groups_test'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
127 | 127 | */ |
128 | 128 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
129 | - $events->registerHandler('init', 'system', '_elgg_groups_init'); |
|
129 | + $events->registerHandler('init', 'system', '_elgg_groups_init'); |
|
130 | 130 | }; |
@@ -109,7 +109,7 @@ |
||
109 | 109 | * @access private |
110 | 110 | */ |
111 | 111 | function _elgg_groups_test($hook, $type, $value) { |
112 | - $value[] = Paths::elgg() . 'engine/tests/ElggGroupTest.php'; |
|
112 | + $value[] = Paths::elgg().'engine/tests/ElggGroupTest.php'; |
|
113 | 113 | return $value; |
114 | 114 | } |
115 | 115 |
@@ -741,7 +741,7 @@ |
||
741 | 741 | * @param string $type system |
742 | 742 | * @param array $value Array of other tests |
743 | 743 | * |
744 | - * @return array |
|
744 | + * @return string[] |
|
745 | 745 | * @access private |
746 | 746 | */ |
747 | 747 | function _elgg_metastrings_test($hook, $type, $value) { |
@@ -45,262 +45,262 @@ discard block |
||
45 | 45 | * @access private |
46 | 46 | */ |
47 | 47 | function _elgg_get_metastring_based_objects($options) { |
48 | - $options = _elgg_normalize_metastrings_options($options); |
|
49 | - |
|
50 | - switch ($options['metastring_type']) { |
|
51 | - case 'metadata': |
|
52 | - $type = 'metadata'; |
|
53 | - $callback = 'row_to_elggmetadata'; |
|
54 | - break; |
|
55 | - |
|
56 | - case 'annotations': |
|
57 | - case 'annotation': |
|
58 | - $type = 'annotations'; |
|
59 | - $callback = 'row_to_elggannotation'; |
|
60 | - break; |
|
61 | - |
|
62 | - default: |
|
63 | - return false; |
|
64 | - } |
|
65 | - |
|
66 | - $defaults = [ |
|
67 | - // entities |
|
68 | - 'types' => ELGG_ENTITIES_ANY_VALUE, |
|
69 | - 'subtypes' => ELGG_ENTITIES_ANY_VALUE, |
|
70 | - 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, |
|
71 | - |
|
72 | - 'guids' => ELGG_ENTITIES_ANY_VALUE, |
|
73 | - 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
74 | - 'container_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
75 | - |
|
76 | - 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
77 | - 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
78 | - 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
79 | - 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
80 | - |
|
81 | - // options are normalized to the plural in case we ever add support for them. |
|
82 | - 'metastring_names' => ELGG_ENTITIES_ANY_VALUE, |
|
83 | - 'metastring_values' => ELGG_ENTITIES_ANY_VALUE, |
|
84 | - |
|
85 | - 'metastring_case_sensitive' => true, |
|
86 | - 'metastring_calculation' => ELGG_ENTITIES_NO_VALUE, |
|
87 | - |
|
88 | - 'metastring_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
89 | - 'metastring_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
90 | - |
|
91 | - 'metastring_owner_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
48 | + $options = _elgg_normalize_metastrings_options($options); |
|
49 | + |
|
50 | + switch ($options['metastring_type']) { |
|
51 | + case 'metadata': |
|
52 | + $type = 'metadata'; |
|
53 | + $callback = 'row_to_elggmetadata'; |
|
54 | + break; |
|
55 | + |
|
56 | + case 'annotations': |
|
57 | + case 'annotation': |
|
58 | + $type = 'annotations'; |
|
59 | + $callback = 'row_to_elggannotation'; |
|
60 | + break; |
|
61 | + |
|
62 | + default: |
|
63 | + return false; |
|
64 | + } |
|
65 | + |
|
66 | + $defaults = [ |
|
67 | + // entities |
|
68 | + 'types' => ELGG_ENTITIES_ANY_VALUE, |
|
69 | + 'subtypes' => ELGG_ENTITIES_ANY_VALUE, |
|
70 | + 'type_subtype_pairs' => ELGG_ENTITIES_ANY_VALUE, |
|
71 | + |
|
72 | + 'guids' => ELGG_ENTITIES_ANY_VALUE, |
|
73 | + 'owner_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
74 | + 'container_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
75 | + |
|
76 | + 'modified_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
77 | + 'modified_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
78 | + 'created_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
79 | + 'created_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
80 | + |
|
81 | + // options are normalized to the plural in case we ever add support for them. |
|
82 | + 'metastring_names' => ELGG_ENTITIES_ANY_VALUE, |
|
83 | + 'metastring_values' => ELGG_ENTITIES_ANY_VALUE, |
|
84 | + |
|
85 | + 'metastring_case_sensitive' => true, |
|
86 | + 'metastring_calculation' => ELGG_ENTITIES_NO_VALUE, |
|
87 | + |
|
88 | + 'metastring_created_time_lower' => ELGG_ENTITIES_ANY_VALUE, |
|
89 | + 'metastring_created_time_upper' => ELGG_ENTITIES_ANY_VALUE, |
|
90 | + |
|
91 | + 'metastring_owner_guids' => ELGG_ENTITIES_ANY_VALUE, |
|
92 | 92 | |
93 | - 'metastring_ids' => ELGG_ENTITIES_ANY_VALUE, |
|
94 | - |
|
95 | - // sql |
|
96 | - 'order_by' => 'n_table.time_created ASC, n_table.id ASC', |
|
97 | - 'limit' => _elgg_config()->default_limit, |
|
98 | - 'offset' => 0, |
|
99 | - 'count' => false, |
|
100 | - 'selects' => [], |
|
101 | - 'wheres' => [], |
|
102 | - 'joins' => [], |
|
103 | - |
|
104 | - 'distinct' => true, |
|
105 | - 'preload_owners' => false, |
|
106 | - 'callback' => $callback, |
|
93 | + 'metastring_ids' => ELGG_ENTITIES_ANY_VALUE, |
|
94 | + |
|
95 | + // sql |
|
96 | + 'order_by' => 'n_table.time_created ASC, n_table.id ASC', |
|
97 | + 'limit' => _elgg_config()->default_limit, |
|
98 | + 'offset' => 0, |
|
99 | + 'count' => false, |
|
100 | + 'selects' => [], |
|
101 | + 'wheres' => [], |
|
102 | + 'joins' => [], |
|
103 | + |
|
104 | + 'distinct' => true, |
|
105 | + 'preload_owners' => false, |
|
106 | + 'callback' => $callback, |
|
107 | 107 | |
108 | - 'batch' => false, |
|
109 | - 'batch_inc_offset' => true, |
|
110 | - 'batch_size' => 25, |
|
111 | - ]; |
|
112 | - |
|
113 | - $options = array_merge($defaults, $options); |
|
114 | - |
|
115 | - if ($options['batch'] && !$options['count']) { |
|
116 | - $batch_size = $options['batch_size']; |
|
117 | - $batch_inc_offset = $options['batch_inc_offset']; |
|
118 | - |
|
119 | - // clean batch keys from $options. |
|
120 | - unset($options['batch'], $options['batch_size'], $options['batch_inc_offset']); |
|
121 | - |
|
122 | - return new \ElggBatch('_elgg_get_metastring_based_objects', $options, null, $batch_size, $batch_inc_offset); |
|
123 | - } |
|
124 | - |
|
125 | - // can't use helper function with type_subtype_pair because |
|
126 | - // it's already an array...just need to merge it |
|
127 | - if (isset($options['type_subtype_pair'])) { |
|
128 | - if (isset($options['type_subtype_pairs'])) { |
|
129 | - $options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'], |
|
130 | - $options['type_subtype_pair']); |
|
131 | - } else { |
|
132 | - $options['type_subtype_pairs'] = $options['type_subtype_pair']; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - $singulars = [ |
|
137 | - 'type', 'subtype', 'type_subtype_pair', |
|
138 | - 'guid', 'owner_guid', 'container_guid', |
|
139 | - 'metastring_name', 'metastring_value', |
|
140 | - 'metastring_owner_guid', 'metastring_id', |
|
141 | - 'select', 'where', 'join' |
|
142 | - ]; |
|
143 | - |
|
144 | - $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
145 | - |
|
146 | - if (!$options) { |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - $db_prefix = _elgg_config()->dbprefix; |
|
151 | - |
|
152 | - // evaluate where clauses |
|
153 | - if (!is_array($options['wheres'])) { |
|
154 | - $options['wheres'] = [$options['wheres']]; |
|
155 | - } |
|
156 | - |
|
157 | - $wheres = $options['wheres']; |
|
158 | - |
|
159 | - // entities |
|
160 | - $wheres[] = _elgg_services()->entityTable->getEntityTypeSubtypeWhereSql('e', $options['types'], |
|
161 | - $options['subtypes'], $options['type_subtype_pairs']); |
|
162 | - |
|
163 | - $wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']); |
|
164 | - $wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']); |
|
165 | - $wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']); |
|
166 | - |
|
167 | - $wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], |
|
168 | - $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']); |
|
169 | - |
|
170 | - |
|
171 | - $wheres[] = _elgg_get_entity_time_where_sql('n_table', $options['metastring_created_time_upper'], |
|
172 | - $options['metastring_created_time_lower'], null, null); |
|
173 | - |
|
174 | - $wheres[] = _elgg_get_guid_based_where_sql('n_table.owner_guid', |
|
175 | - $options['metastring_owner_guids']); |
|
176 | - |
|
177 | - // see if any functions failed |
|
178 | - // remove empty strings on successful functions |
|
179 | - foreach ($wheres as $i => $where) { |
|
180 | - if ($where === false) { |
|
181 | - return false; |
|
182 | - } elseif (empty($where)) { |
|
183 | - unset($wheres[$i]); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // remove identical where clauses |
|
188 | - $wheres = array_unique($wheres); |
|
189 | - |
|
190 | - // evaluate join clauses |
|
191 | - if (!is_array($options['joins'])) { |
|
192 | - $options['joins'] = [$options['joins']]; |
|
193 | - } |
|
194 | - |
|
195 | - $joins = []; |
|
196 | - $joins[] = "JOIN {$db_prefix}entities e ON n_table.entity_guid = e.guid"; |
|
197 | - |
|
198 | - // evaluate selects |
|
199 | - if (!is_array($options['selects'])) { |
|
200 | - $options['selects'] = [$options['selects']]; |
|
201 | - } |
|
202 | - |
|
203 | - $selects = $options['selects']; |
|
204 | - |
|
205 | - // add optional joins |
|
206 | - $joins = array_merge($joins, $options['joins']); |
|
207 | - |
|
208 | - // metastrings |
|
209 | - $metastring_clauses = _elgg_get_metastring_sql('n_table', $options['metastring_names'], |
|
210 | - $options['metastring_values'], null, $options['metastring_ids'], |
|
211 | - $options['metastring_case_sensitive'], $type); |
|
212 | - |
|
213 | - if ($metastring_clauses) { |
|
214 | - $wheres = array_merge($wheres, $metastring_clauses['wheres']); |
|
215 | - $joins = array_merge($joins, $metastring_clauses['joins']); |
|
216 | - } else { |
|
217 | - if ($type === 'annotations') { |
|
218 | - $wheres[] = _elgg_get_access_where_sql([ |
|
219 | - 'table_alias' => 'n_table', |
|
220 | - 'guid_column' => 'entity_guid', |
|
221 | - ]); |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - $distinct = $options['distinct'] ? "DISTINCT " : ""; |
|
226 | - |
|
227 | - if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) { |
|
228 | - $selects = array_unique($selects); |
|
229 | - // evalutate selects |
|
230 | - $select_str = ''; |
|
231 | - if ($selects) { |
|
232 | - foreach ($selects as $select) { |
|
233 | - $select_str .= ", $select"; |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - $query = "SELECT $distinct n_table.*{$select_str} FROM {$db_prefix}$type n_table"; |
|
238 | - } elseif ($options['count']) { |
|
239 | - // count is over the entities |
|
240 | - $query = "SELECT count($distinct e.guid) as calculation FROM {$db_prefix}$type n_table"; |
|
241 | - } else { |
|
242 | - $query = "SELECT {$options['metastring_calculation']}(n_table.value) as calculation FROM {$db_prefix}$type n_table"; |
|
243 | - } |
|
244 | - |
|
245 | - foreach ($joins as $i => $join) { |
|
246 | - if ($join === false) { |
|
247 | - return false; |
|
248 | - } elseif (empty($join)) { |
|
249 | - unset($joins[$i]); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - // remove identical join clauses |
|
254 | - $joins = array_unique($joins); |
|
255 | - |
|
256 | - // add joins |
|
257 | - foreach ($joins as $j) { |
|
258 | - $query .= " $j "; |
|
259 | - } |
|
260 | - |
|
261 | - // add wheres |
|
262 | - $query .= ' WHERE '; |
|
263 | - |
|
264 | - foreach ($wheres as $w) { |
|
265 | - $query .= " $w AND "; |
|
266 | - } |
|
267 | - |
|
268 | - // Add access controls |
|
269 | - $query .= _elgg_get_access_where_sql(['table_alias' => 'e']); |
|
270 | - |
|
271 | - // reverse order by |
|
272 | - if (isset($options['reverse_order_by']) && $options['reverse_order_by']) { |
|
273 | - $options['order_by'] = _elgg_sql_reverse_order_by_clause($options['order_by']); |
|
274 | - } |
|
275 | - |
|
276 | - if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) { |
|
277 | - if (isset($options['group_by'])) { |
|
278 | - $options['group_by'] = sanitise_string($options['group_by']); |
|
279 | - $query .= " GROUP BY {$options['group_by']}"; |
|
280 | - } |
|
281 | - |
|
282 | - if (isset($options['order_by']) && $options['order_by']) { |
|
283 | - $options['order_by'] = sanitise_string($options['order_by']); |
|
284 | - $query .= " ORDER BY {$options['order_by']}, n_table.id"; |
|
285 | - } |
|
286 | - |
|
287 | - if ($options['limit']) { |
|
288 | - $limit = sanitise_int($options['limit']); |
|
289 | - $offset = sanitise_int($options['offset'], false); |
|
290 | - $query .= " LIMIT $offset, $limit"; |
|
291 | - } |
|
292 | - |
|
293 | - $dt = get_data($query, $options['callback']); |
|
294 | - |
|
295 | - if ($options['preload_owners'] && is_array($dt) && count($dt) > 1) { |
|
296 | - _elgg_services()->entityPreloader->preload($dt, ['owner_guid']); |
|
297 | - } |
|
298 | - |
|
299 | - return $dt; |
|
300 | - } else { |
|
301 | - $result = get_data_row($query); |
|
302 | - return $result->calculation; |
|
303 | - } |
|
108 | + 'batch' => false, |
|
109 | + 'batch_inc_offset' => true, |
|
110 | + 'batch_size' => 25, |
|
111 | + ]; |
|
112 | + |
|
113 | + $options = array_merge($defaults, $options); |
|
114 | + |
|
115 | + if ($options['batch'] && !$options['count']) { |
|
116 | + $batch_size = $options['batch_size']; |
|
117 | + $batch_inc_offset = $options['batch_inc_offset']; |
|
118 | + |
|
119 | + // clean batch keys from $options. |
|
120 | + unset($options['batch'], $options['batch_size'], $options['batch_inc_offset']); |
|
121 | + |
|
122 | + return new \ElggBatch('_elgg_get_metastring_based_objects', $options, null, $batch_size, $batch_inc_offset); |
|
123 | + } |
|
124 | + |
|
125 | + // can't use helper function with type_subtype_pair because |
|
126 | + // it's already an array...just need to merge it |
|
127 | + if (isset($options['type_subtype_pair'])) { |
|
128 | + if (isset($options['type_subtype_pairs'])) { |
|
129 | + $options['type_subtype_pairs'] = array_merge($options['type_subtype_pairs'], |
|
130 | + $options['type_subtype_pair']); |
|
131 | + } else { |
|
132 | + $options['type_subtype_pairs'] = $options['type_subtype_pair']; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + $singulars = [ |
|
137 | + 'type', 'subtype', 'type_subtype_pair', |
|
138 | + 'guid', 'owner_guid', 'container_guid', |
|
139 | + 'metastring_name', 'metastring_value', |
|
140 | + 'metastring_owner_guid', 'metastring_id', |
|
141 | + 'select', 'where', 'join' |
|
142 | + ]; |
|
143 | + |
|
144 | + $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
145 | + |
|
146 | + if (!$options) { |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + $db_prefix = _elgg_config()->dbprefix; |
|
151 | + |
|
152 | + // evaluate where clauses |
|
153 | + if (!is_array($options['wheres'])) { |
|
154 | + $options['wheres'] = [$options['wheres']]; |
|
155 | + } |
|
156 | + |
|
157 | + $wheres = $options['wheres']; |
|
158 | + |
|
159 | + // entities |
|
160 | + $wheres[] = _elgg_services()->entityTable->getEntityTypeSubtypeWhereSql('e', $options['types'], |
|
161 | + $options['subtypes'], $options['type_subtype_pairs']); |
|
162 | + |
|
163 | + $wheres[] = _elgg_get_guid_based_where_sql('e.guid', $options['guids']); |
|
164 | + $wheres[] = _elgg_get_guid_based_where_sql('e.owner_guid', $options['owner_guids']); |
|
165 | + $wheres[] = _elgg_get_guid_based_where_sql('e.container_guid', $options['container_guids']); |
|
166 | + |
|
167 | + $wheres[] = _elgg_get_entity_time_where_sql('e', $options['created_time_upper'], |
|
168 | + $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']); |
|
169 | + |
|
170 | + |
|
171 | + $wheres[] = _elgg_get_entity_time_where_sql('n_table', $options['metastring_created_time_upper'], |
|
172 | + $options['metastring_created_time_lower'], null, null); |
|
173 | + |
|
174 | + $wheres[] = _elgg_get_guid_based_where_sql('n_table.owner_guid', |
|
175 | + $options['metastring_owner_guids']); |
|
176 | + |
|
177 | + // see if any functions failed |
|
178 | + // remove empty strings on successful functions |
|
179 | + foreach ($wheres as $i => $where) { |
|
180 | + if ($where === false) { |
|
181 | + return false; |
|
182 | + } elseif (empty($where)) { |
|
183 | + unset($wheres[$i]); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // remove identical where clauses |
|
188 | + $wheres = array_unique($wheres); |
|
189 | + |
|
190 | + // evaluate join clauses |
|
191 | + if (!is_array($options['joins'])) { |
|
192 | + $options['joins'] = [$options['joins']]; |
|
193 | + } |
|
194 | + |
|
195 | + $joins = []; |
|
196 | + $joins[] = "JOIN {$db_prefix}entities e ON n_table.entity_guid = e.guid"; |
|
197 | + |
|
198 | + // evaluate selects |
|
199 | + if (!is_array($options['selects'])) { |
|
200 | + $options['selects'] = [$options['selects']]; |
|
201 | + } |
|
202 | + |
|
203 | + $selects = $options['selects']; |
|
204 | + |
|
205 | + // add optional joins |
|
206 | + $joins = array_merge($joins, $options['joins']); |
|
207 | + |
|
208 | + // metastrings |
|
209 | + $metastring_clauses = _elgg_get_metastring_sql('n_table', $options['metastring_names'], |
|
210 | + $options['metastring_values'], null, $options['metastring_ids'], |
|
211 | + $options['metastring_case_sensitive'], $type); |
|
212 | + |
|
213 | + if ($metastring_clauses) { |
|
214 | + $wheres = array_merge($wheres, $metastring_clauses['wheres']); |
|
215 | + $joins = array_merge($joins, $metastring_clauses['joins']); |
|
216 | + } else { |
|
217 | + if ($type === 'annotations') { |
|
218 | + $wheres[] = _elgg_get_access_where_sql([ |
|
219 | + 'table_alias' => 'n_table', |
|
220 | + 'guid_column' => 'entity_guid', |
|
221 | + ]); |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + $distinct = $options['distinct'] ? "DISTINCT " : ""; |
|
226 | + |
|
227 | + if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) { |
|
228 | + $selects = array_unique($selects); |
|
229 | + // evalutate selects |
|
230 | + $select_str = ''; |
|
231 | + if ($selects) { |
|
232 | + foreach ($selects as $select) { |
|
233 | + $select_str .= ", $select"; |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + $query = "SELECT $distinct n_table.*{$select_str} FROM {$db_prefix}$type n_table"; |
|
238 | + } elseif ($options['count']) { |
|
239 | + // count is over the entities |
|
240 | + $query = "SELECT count($distinct e.guid) as calculation FROM {$db_prefix}$type n_table"; |
|
241 | + } else { |
|
242 | + $query = "SELECT {$options['metastring_calculation']}(n_table.value) as calculation FROM {$db_prefix}$type n_table"; |
|
243 | + } |
|
244 | + |
|
245 | + foreach ($joins as $i => $join) { |
|
246 | + if ($join === false) { |
|
247 | + return false; |
|
248 | + } elseif (empty($join)) { |
|
249 | + unset($joins[$i]); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + // remove identical join clauses |
|
254 | + $joins = array_unique($joins); |
|
255 | + |
|
256 | + // add joins |
|
257 | + foreach ($joins as $j) { |
|
258 | + $query .= " $j "; |
|
259 | + } |
|
260 | + |
|
261 | + // add wheres |
|
262 | + $query .= ' WHERE '; |
|
263 | + |
|
264 | + foreach ($wheres as $w) { |
|
265 | + $query .= " $w AND "; |
|
266 | + } |
|
267 | + |
|
268 | + // Add access controls |
|
269 | + $query .= _elgg_get_access_where_sql(['table_alias' => 'e']); |
|
270 | + |
|
271 | + // reverse order by |
|
272 | + if (isset($options['reverse_order_by']) && $options['reverse_order_by']) { |
|
273 | + $options['order_by'] = _elgg_sql_reverse_order_by_clause($options['order_by']); |
|
274 | + } |
|
275 | + |
|
276 | + if ($options['metastring_calculation'] === ELGG_ENTITIES_NO_VALUE && !$options['count']) { |
|
277 | + if (isset($options['group_by'])) { |
|
278 | + $options['group_by'] = sanitise_string($options['group_by']); |
|
279 | + $query .= " GROUP BY {$options['group_by']}"; |
|
280 | + } |
|
281 | + |
|
282 | + if (isset($options['order_by']) && $options['order_by']) { |
|
283 | + $options['order_by'] = sanitise_string($options['order_by']); |
|
284 | + $query .= " ORDER BY {$options['order_by']}, n_table.id"; |
|
285 | + } |
|
286 | + |
|
287 | + if ($options['limit']) { |
|
288 | + $limit = sanitise_int($options['limit']); |
|
289 | + $offset = sanitise_int($options['offset'], false); |
|
290 | + $query .= " LIMIT $offset, $limit"; |
|
291 | + } |
|
292 | + |
|
293 | + $dt = get_data($query, $options['callback']); |
|
294 | + |
|
295 | + if ($options['preload_owners'] && is_array($dt) && count($dt) > 1) { |
|
296 | + _elgg_services()->entityPreloader->preload($dt, ['owner_guid']); |
|
297 | + } |
|
298 | + |
|
299 | + return $dt; |
|
300 | + } else { |
|
301 | + $result = get_data_row($query); |
|
302 | + return $result->calculation; |
|
303 | + } |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -320,105 +320,105 @@ discard block |
||
320 | 320 | * @access private |
321 | 321 | */ |
322 | 322 | function _elgg_get_metastring_sql($table, $names = null, $values = null, |
323 | - $pairs = null, $ids = null, $case_sensitive = false, $type = null) { |
|
324 | - |
|
325 | - if ($type !== 'metadata' && $type !== 'annotations') { |
|
326 | - throw new \InvalidArgumentException('$type must be "metadata" or "annotations"'); |
|
327 | - } |
|
328 | - |
|
329 | - if ((!$names && $names !== 0) |
|
330 | - && (!$values && $values !== 0) |
|
331 | - && !$ids |
|
332 | - && (!$pairs && $pairs !== 0)) { |
|
333 | - return []; |
|
334 | - } |
|
335 | - |
|
336 | - $db_prefix = _elgg_config()->dbprefix; |
|
337 | - |
|
338 | - // binary forces byte-to-byte comparision of strings, making |
|
339 | - // it case- and diacritical-mark- sensitive. |
|
340 | - // only supported on values. |
|
341 | - $binary = ($case_sensitive) ? ' BINARY ' : ''; |
|
342 | - |
|
343 | - $return = [ |
|
344 | - 'joins' => [], |
|
345 | - 'wheres' => [] |
|
346 | - ]; |
|
347 | - |
|
348 | - $wheres = []; |
|
349 | - |
|
350 | - // get names wheres and joins |
|
351 | - $names_where = ''; |
|
352 | - if ($names !== null) { |
|
353 | - if (!is_array($names)) { |
|
354 | - $names = [$names]; |
|
355 | - } |
|
356 | - |
|
357 | - $sanitised_names = []; |
|
358 | - foreach ($names as $name) { |
|
359 | - // normalise to 0. |
|
360 | - if (!$name) { |
|
361 | - $name = '0'; |
|
362 | - } |
|
363 | - $sanitised_names[] = '\'' . sanitise_string($name) . '\''; |
|
364 | - } |
|
365 | - |
|
366 | - if ($names_str = implode(',', $sanitised_names)) { |
|
367 | - $names_where = "($table.name IN ($names_str))"; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - // get values wheres and joins |
|
372 | - $values_where = ''; |
|
373 | - if ($values !== null) { |
|
374 | - if (!is_array($values)) { |
|
375 | - $values = [$values]; |
|
376 | - } |
|
377 | - |
|
378 | - $sanitised_values = []; |
|
379 | - foreach ($values as $value) { |
|
380 | - // normalize to 0 |
|
381 | - if (!$value) { |
|
382 | - $value = 0; |
|
383 | - } |
|
384 | - $sanitised_values[] = '\'' . sanitise_string($value) . '\''; |
|
385 | - } |
|
386 | - |
|
387 | - if ($values_str = implode(',', $sanitised_values)) { |
|
388 | - $values_where = "({$binary}$table.value IN ($values_str))"; |
|
389 | - } |
|
390 | - } |
|
323 | + $pairs = null, $ids = null, $case_sensitive = false, $type = null) { |
|
324 | + |
|
325 | + if ($type !== 'metadata' && $type !== 'annotations') { |
|
326 | + throw new \InvalidArgumentException('$type must be "metadata" or "annotations"'); |
|
327 | + } |
|
328 | + |
|
329 | + if ((!$names && $names !== 0) |
|
330 | + && (!$values && $values !== 0) |
|
331 | + && !$ids |
|
332 | + && (!$pairs && $pairs !== 0)) { |
|
333 | + return []; |
|
334 | + } |
|
335 | + |
|
336 | + $db_prefix = _elgg_config()->dbprefix; |
|
337 | + |
|
338 | + // binary forces byte-to-byte comparision of strings, making |
|
339 | + // it case- and diacritical-mark- sensitive. |
|
340 | + // only supported on values. |
|
341 | + $binary = ($case_sensitive) ? ' BINARY ' : ''; |
|
342 | + |
|
343 | + $return = [ |
|
344 | + 'joins' => [], |
|
345 | + 'wheres' => [] |
|
346 | + ]; |
|
347 | + |
|
348 | + $wheres = []; |
|
349 | + |
|
350 | + // get names wheres and joins |
|
351 | + $names_where = ''; |
|
352 | + if ($names !== null) { |
|
353 | + if (!is_array($names)) { |
|
354 | + $names = [$names]; |
|
355 | + } |
|
356 | + |
|
357 | + $sanitised_names = []; |
|
358 | + foreach ($names as $name) { |
|
359 | + // normalise to 0. |
|
360 | + if (!$name) { |
|
361 | + $name = '0'; |
|
362 | + } |
|
363 | + $sanitised_names[] = '\'' . sanitise_string($name) . '\''; |
|
364 | + } |
|
365 | + |
|
366 | + if ($names_str = implode(',', $sanitised_names)) { |
|
367 | + $names_where = "($table.name IN ($names_str))"; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + // get values wheres and joins |
|
372 | + $values_where = ''; |
|
373 | + if ($values !== null) { |
|
374 | + if (!is_array($values)) { |
|
375 | + $values = [$values]; |
|
376 | + } |
|
377 | + |
|
378 | + $sanitised_values = []; |
|
379 | + foreach ($values as $value) { |
|
380 | + // normalize to 0 |
|
381 | + if (!$value) { |
|
382 | + $value = 0; |
|
383 | + } |
|
384 | + $sanitised_values[] = '\'' . sanitise_string($value) . '\''; |
|
385 | + } |
|
386 | + |
|
387 | + if ($values_str = implode(',', $sanitised_values)) { |
|
388 | + $values_where = "({$binary}$table.value IN ($values_str))"; |
|
389 | + } |
|
390 | + } |
|
391 | 391 | |
392 | - if ($ids !== null) { |
|
393 | - if (!is_array($ids)) { |
|
394 | - $ids = [$ids]; |
|
395 | - } |
|
396 | - $ids_str = implode(',', $ids); |
|
397 | - if ($ids_str) { |
|
398 | - $wheres[] = "n_table.id IN ($ids_str)"; |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - if ($names_where && $values_where) { |
|
403 | - $wheres[] = "($names_where AND $values_where)"; |
|
404 | - } elseif ($names_where) { |
|
405 | - $wheres[] = $names_where; |
|
406 | - } elseif ($values_where) { |
|
407 | - $wheres[] = $values_where; |
|
408 | - } |
|
409 | - |
|
410 | - if ($type === 'annotations') { |
|
411 | - $wheres[] = _elgg_get_access_where_sql([ |
|
412 | - 'table_alias' => $table, |
|
413 | - 'guid_column' => 'entity_guid', |
|
414 | - ]); |
|
415 | - } |
|
416 | - |
|
417 | - if ($where = implode(' AND ', $wheres)) { |
|
418 | - $return['wheres'][] = "($where)"; |
|
419 | - } |
|
420 | - |
|
421 | - return $return; |
|
392 | + if ($ids !== null) { |
|
393 | + if (!is_array($ids)) { |
|
394 | + $ids = [$ids]; |
|
395 | + } |
|
396 | + $ids_str = implode(',', $ids); |
|
397 | + if ($ids_str) { |
|
398 | + $wheres[] = "n_table.id IN ($ids_str)"; |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + if ($names_where && $values_where) { |
|
403 | + $wheres[] = "($names_where AND $values_where)"; |
|
404 | + } elseif ($names_where) { |
|
405 | + $wheres[] = $names_where; |
|
406 | + } elseif ($values_where) { |
|
407 | + $wheres[] = $values_where; |
|
408 | + } |
|
409 | + |
|
410 | + if ($type === 'annotations') { |
|
411 | + $wheres[] = _elgg_get_access_where_sql([ |
|
412 | + 'table_alias' => $table, |
|
413 | + 'guid_column' => 'entity_guid', |
|
414 | + ]); |
|
415 | + } |
|
416 | + |
|
417 | + if ($where = implode(' AND ', $wheres)) { |
|
418 | + $return['wheres'][] = "($where)"; |
|
419 | + } |
|
420 | + |
|
421 | + return $return; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
@@ -430,41 +430,41 @@ discard block |
||
430 | 430 | */ |
431 | 431 | function _elgg_normalize_metastrings_options(array $options = []) { |
432 | 432 | |
433 | - // support either metastrings_type or metastring_type |
|
434 | - // because I've made this mistake many times and hunting it down is a pain... |
|
435 | - $type = elgg_extract('metastring_type', $options, null); |
|
436 | - $type = elgg_extract('metastrings_type', $options, $type); |
|
437 | - |
|
438 | - $options['metastring_type'] = $type; |
|
439 | - |
|
440 | - // support annotation_ and annotations_ because they're way too easy to confuse |
|
441 | - $prefixes = ['metadata_', 'annotation_', 'annotations_']; |
|
442 | - |
|
443 | - // map the metadata_* options to metastring_* options |
|
444 | - $map = [ |
|
445 | - 'names' => 'metastring_names', |
|
446 | - 'values' => 'metastring_values', |
|
447 | - 'case_sensitive' => 'metastring_case_sensitive', |
|
448 | - 'owner_guids' => 'metastring_owner_guids', |
|
449 | - 'created_time_lower' => 'metastring_created_time_lower', |
|
450 | - 'created_time_upper' => 'metastring_created_time_upper', |
|
451 | - 'calculation' => 'metastring_calculation', |
|
452 | - 'ids' => 'metastring_ids', |
|
453 | - ]; |
|
454 | - |
|
455 | - foreach ($prefixes as $prefix) { |
|
456 | - $singulars = ["{$prefix}name", "{$prefix}value", "{$prefix}owner_guid", "{$prefix}id"]; |
|
457 | - $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
458 | - |
|
459 | - foreach ($map as $specific => $normalized) { |
|
460 | - $key = $prefix . $specific; |
|
461 | - if (isset($options[$key])) { |
|
462 | - $options[$normalized] = $options[$key]; |
|
463 | - } |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - return $options; |
|
433 | + // support either metastrings_type or metastring_type |
|
434 | + // because I've made this mistake many times and hunting it down is a pain... |
|
435 | + $type = elgg_extract('metastring_type', $options, null); |
|
436 | + $type = elgg_extract('metastrings_type', $options, $type); |
|
437 | + |
|
438 | + $options['metastring_type'] = $type; |
|
439 | + |
|
440 | + // support annotation_ and annotations_ because they're way too easy to confuse |
|
441 | + $prefixes = ['metadata_', 'annotation_', 'annotations_']; |
|
442 | + |
|
443 | + // map the metadata_* options to metastring_* options |
|
444 | + $map = [ |
|
445 | + 'names' => 'metastring_names', |
|
446 | + 'values' => 'metastring_values', |
|
447 | + 'case_sensitive' => 'metastring_case_sensitive', |
|
448 | + 'owner_guids' => 'metastring_owner_guids', |
|
449 | + 'created_time_lower' => 'metastring_created_time_lower', |
|
450 | + 'created_time_upper' => 'metastring_created_time_upper', |
|
451 | + 'calculation' => 'metastring_calculation', |
|
452 | + 'ids' => 'metastring_ids', |
|
453 | + ]; |
|
454 | + |
|
455 | + foreach ($prefixes as $prefix) { |
|
456 | + $singulars = ["{$prefix}name", "{$prefix}value", "{$prefix}owner_guid", "{$prefix}id"]; |
|
457 | + $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
458 | + |
|
459 | + foreach ($map as $specific => $normalized) { |
|
460 | + $key = $prefix . $specific; |
|
461 | + if (isset($options[$key])) { |
|
462 | + $options[$normalized] = $options[$key]; |
|
463 | + } |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + return $options; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -482,48 +482,48 @@ discard block |
||
482 | 482 | * @access private |
483 | 483 | */ |
484 | 484 | function _elgg_set_metastring_based_object_enabled_by_id($id, $enabled, $type) { |
485 | - $id = (int) $id; |
|
486 | - $db_prefix = _elgg_config()->dbprefix; |
|
487 | - |
|
488 | - $object = _elgg_get_metastring_based_object_from_id($id, $type); |
|
489 | - |
|
490 | - switch ($type) { |
|
491 | - case 'annotation': |
|
492 | - case 'annotations': |
|
493 | - $type = 'annotation'; |
|
494 | - $table = "{$db_prefix}annotations"; |
|
495 | - break; |
|
496 | - |
|
497 | - case 'metadata': |
|
498 | - $table = "{$db_prefix}metadata"; |
|
499 | - break; |
|
500 | - } |
|
501 | - |
|
502 | - if ($enabled === 'yes' || $enabled === 1 || $enabled === true) { |
|
503 | - $enabled = 'yes'; |
|
504 | - $event = 'enable'; |
|
505 | - } elseif ($enabled === 'no' || $enabled === 0 || $enabled === false) { |
|
506 | - $enabled = 'no'; |
|
507 | - $event = 'disable'; |
|
508 | - } else { |
|
509 | - return false; |
|
510 | - } |
|
511 | - |
|
512 | - $return = false; |
|
513 | - |
|
514 | - if ($object) { |
|
515 | - // don't set it if it's already set. |
|
516 | - if ($object->enabled == $enabled) { |
|
517 | - $return = false; |
|
518 | - } elseif ($object->canEdit() && (elgg_trigger_event($event, $type, $object))) { |
|
519 | - $return = update_data("UPDATE $table SET enabled = :enabled where id = :id", [ |
|
520 | - ':enabled' => $enabled, |
|
521 | - ':id' => $id, |
|
522 | - ]); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - return $return; |
|
485 | + $id = (int) $id; |
|
486 | + $db_prefix = _elgg_config()->dbprefix; |
|
487 | + |
|
488 | + $object = _elgg_get_metastring_based_object_from_id($id, $type); |
|
489 | + |
|
490 | + switch ($type) { |
|
491 | + case 'annotation': |
|
492 | + case 'annotations': |
|
493 | + $type = 'annotation'; |
|
494 | + $table = "{$db_prefix}annotations"; |
|
495 | + break; |
|
496 | + |
|
497 | + case 'metadata': |
|
498 | + $table = "{$db_prefix}metadata"; |
|
499 | + break; |
|
500 | + } |
|
501 | + |
|
502 | + if ($enabled === 'yes' || $enabled === 1 || $enabled === true) { |
|
503 | + $enabled = 'yes'; |
|
504 | + $event = 'enable'; |
|
505 | + } elseif ($enabled === 'no' || $enabled === 0 || $enabled === false) { |
|
506 | + $enabled = 'no'; |
|
507 | + $event = 'disable'; |
|
508 | + } else { |
|
509 | + return false; |
|
510 | + } |
|
511 | + |
|
512 | + $return = false; |
|
513 | + |
|
514 | + if ($object) { |
|
515 | + // don't set it if it's already set. |
|
516 | + if ($object->enabled == $enabled) { |
|
517 | + $return = false; |
|
518 | + } elseif ($object->canEdit() && (elgg_trigger_event($event, $type, $object))) { |
|
519 | + $return = update_data("UPDATE $table SET enabled = :enabled where id = :id", [ |
|
520 | + ':enabled' => $enabled, |
|
521 | + ':id' => $id, |
|
522 | + ]); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + return $return; |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -542,12 +542,12 @@ discard block |
||
542 | 542 | * @access private |
543 | 543 | */ |
544 | 544 | function _elgg_batch_metastring_based_objects(array $options, $callback, $inc_offset = true) { |
545 | - if (!$options || !is_array($options)) { |
|
546 | - return false; |
|
547 | - } |
|
545 | + if (!$options || !is_array($options)) { |
|
546 | + return false; |
|
547 | + } |
|
548 | 548 | |
549 | - $batch = new \ElggBatch('_elgg_get_metastring_based_objects', $options, $callback, 50, $inc_offset); |
|
550 | - return $batch->callbackResult; |
|
549 | + $batch = new \ElggBatch('_elgg_get_metastring_based_objects', $options, $callback, 50, $inc_offset); |
|
550 | + return $batch->callbackResult; |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -559,23 +559,23 @@ discard block |
||
559 | 559 | * @access private |
560 | 560 | */ |
561 | 561 | function _elgg_get_metastring_based_object_from_id($id, $type) { |
562 | - $id = (int) $id; |
|
563 | - if (!$id) { |
|
564 | - return false; |
|
565 | - } |
|
562 | + $id = (int) $id; |
|
563 | + if (!$id) { |
|
564 | + return false; |
|
565 | + } |
|
566 | 566 | |
567 | - $options = [ |
|
568 | - 'metastring_type' => $type, |
|
569 | - 'metastring_id' => $id, |
|
570 | - ]; |
|
567 | + $options = [ |
|
568 | + 'metastring_type' => $type, |
|
569 | + 'metastring_id' => $id, |
|
570 | + ]; |
|
571 | 571 | |
572 | - $obj = _elgg_get_metastring_based_objects($options); |
|
572 | + $obj = _elgg_get_metastring_based_objects($options); |
|
573 | 573 | |
574 | - if ($obj && count($obj) == 1) { |
|
575 | - return $obj[0]; |
|
576 | - } |
|
574 | + if ($obj && count($obj) == 1) { |
|
575 | + return $obj[0]; |
|
576 | + } |
|
577 | 577 | |
578 | - return false; |
|
578 | + return false; |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -587,38 +587,38 @@ discard block |
||
587 | 587 | * @access private |
588 | 588 | */ |
589 | 589 | function _elgg_delete_metastring_based_object_by_id($id, $type) { |
590 | - $id = (int) $id; |
|
591 | - $db_prefix = _elgg_config()->dbprefix; |
|
592 | - |
|
593 | - switch ($type) { |
|
594 | - case 'annotations': |
|
595 | - case 'annotation': |
|
596 | - $table = $db_prefix . 'annotations'; |
|
597 | - $type = 'annotation'; |
|
598 | - break; |
|
599 | - |
|
600 | - case 'metadata': |
|
601 | - $table = $db_prefix . 'metadata'; |
|
602 | - $type = 'metadata'; |
|
603 | - break; |
|
604 | - |
|
605 | - default: |
|
606 | - return false; |
|
607 | - } |
|
608 | - |
|
609 | - $obj = _elgg_get_metastring_based_object_from_id($id, $type); |
|
610 | - |
|
611 | - if ($obj) { |
|
612 | - if ($obj->canEdit()) { |
|
613 | - if (elgg_trigger_event('delete', $type, $obj)) { |
|
614 | - return (bool) delete_data("DELETE FROM $table WHERE id = :id", [ |
|
615 | - ':id' => $id, |
|
616 | - ]); |
|
617 | - } |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - return false; |
|
590 | + $id = (int) $id; |
|
591 | + $db_prefix = _elgg_config()->dbprefix; |
|
592 | + |
|
593 | + switch ($type) { |
|
594 | + case 'annotations': |
|
595 | + case 'annotation': |
|
596 | + $table = $db_prefix . 'annotations'; |
|
597 | + $type = 'annotation'; |
|
598 | + break; |
|
599 | + |
|
600 | + case 'metadata': |
|
601 | + $table = $db_prefix . 'metadata'; |
|
602 | + $type = 'metadata'; |
|
603 | + break; |
|
604 | + |
|
605 | + default: |
|
606 | + return false; |
|
607 | + } |
|
608 | + |
|
609 | + $obj = _elgg_get_metastring_based_object_from_id($id, $type); |
|
610 | + |
|
611 | + if ($obj) { |
|
612 | + if ($obj->canEdit()) { |
|
613 | + if (elgg_trigger_event('delete', $type, $obj)) { |
|
614 | + return (bool) delete_data("DELETE FROM $table WHERE id = :id", [ |
|
615 | + ':id' => $id, |
|
616 | + ]); |
|
617 | + } |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + return false; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -631,54 +631,54 @@ discard block |
||
631 | 631 | * @access private |
632 | 632 | */ |
633 | 633 | function _elgg_entities_get_metastrings_options($type, $options) { |
634 | - $valid_types = ['metadata', 'annotation']; |
|
635 | - if (!in_array($type, $valid_types)) { |
|
636 | - return false; |
|
637 | - } |
|
638 | - |
|
639 | - // the options for annotations are singular (annotation_name) but the table |
|
640 | - // is plural (elgg_annotations) so rewrite for the table name. |
|
641 | - $n_table = ($type == 'annotation') ? 'annotations' : $type; |
|
642 | - |
|
643 | - $singulars = ["{$type}_name", "{$type}_value", |
|
644 | - "{$type}_name_value_pair", "{$type}_owner_guid"]; |
|
645 | - $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
646 | - |
|
647 | - $clauses = _elgg_get_entity_metadata_where_sql('e', $n_table, $options["{$type}_names"], |
|
648 | - $options["{$type}_values"], $options["{$type}_name_value_pairs"], |
|
649 | - $options["{$type}_name_value_pairs_operator"], $options["{$type}_case_sensitive"], |
|
650 | - $options["order_by_{$type}"], $options["{$type}_owner_guids"]); |
|
651 | - |
|
652 | - if ($clauses) { |
|
653 | - // merge wheres to pass to elgg_get_entities() |
|
654 | - if (isset($options['wheres']) && !is_array($options['wheres'])) { |
|
655 | - $options['wheres'] = [$options['wheres']]; |
|
656 | - } elseif (!isset($options['wheres'])) { |
|
657 | - $options['wheres'] = []; |
|
658 | - } |
|
659 | - |
|
660 | - $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']); |
|
661 | - |
|
662 | - // merge joins to pass to elgg_get_entities() |
|
663 | - if (isset($options['joins']) && !is_array($options['joins'])) { |
|
664 | - $options['joins'] = [$options['joins']]; |
|
665 | - } elseif (!isset($options['joins'])) { |
|
666 | - $options['joins'] = []; |
|
667 | - } |
|
668 | - |
|
669 | - $options['joins'] = array_merge($options['joins'], $clauses['joins']); |
|
670 | - |
|
671 | - if ($clauses['orders']) { |
|
672 | - $order_by_metadata = implode(", ", $clauses['orders']); |
|
673 | - if (isset($options['order_by']) && $options['order_by']) { |
|
674 | - $options['order_by'] = "$order_by_metadata, {$options['order_by']}"; |
|
675 | - } else { |
|
676 | - $options['order_by'] = "$order_by_metadata, e.time_created DESC"; |
|
677 | - } |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - return $options; |
|
634 | + $valid_types = ['metadata', 'annotation']; |
|
635 | + if (!in_array($type, $valid_types)) { |
|
636 | + return false; |
|
637 | + } |
|
638 | + |
|
639 | + // the options for annotations are singular (annotation_name) but the table |
|
640 | + // is plural (elgg_annotations) so rewrite for the table name. |
|
641 | + $n_table = ($type == 'annotation') ? 'annotations' : $type; |
|
642 | + |
|
643 | + $singulars = ["{$type}_name", "{$type}_value", |
|
644 | + "{$type}_name_value_pair", "{$type}_owner_guid"]; |
|
645 | + $options = _elgg_normalize_plural_options_array($options, $singulars); |
|
646 | + |
|
647 | + $clauses = _elgg_get_entity_metadata_where_sql('e', $n_table, $options["{$type}_names"], |
|
648 | + $options["{$type}_values"], $options["{$type}_name_value_pairs"], |
|
649 | + $options["{$type}_name_value_pairs_operator"], $options["{$type}_case_sensitive"], |
|
650 | + $options["order_by_{$type}"], $options["{$type}_owner_guids"]); |
|
651 | + |
|
652 | + if ($clauses) { |
|
653 | + // merge wheres to pass to elgg_get_entities() |
|
654 | + if (isset($options['wheres']) && !is_array($options['wheres'])) { |
|
655 | + $options['wheres'] = [$options['wheres']]; |
|
656 | + } elseif (!isset($options['wheres'])) { |
|
657 | + $options['wheres'] = []; |
|
658 | + } |
|
659 | + |
|
660 | + $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']); |
|
661 | + |
|
662 | + // merge joins to pass to elgg_get_entities() |
|
663 | + if (isset($options['joins']) && !is_array($options['joins'])) { |
|
664 | + $options['joins'] = [$options['joins']]; |
|
665 | + } elseif (!isset($options['joins'])) { |
|
666 | + $options['joins'] = []; |
|
667 | + } |
|
668 | + |
|
669 | + $options['joins'] = array_merge($options['joins'], $clauses['joins']); |
|
670 | + |
|
671 | + if ($clauses['orders']) { |
|
672 | + $order_by_metadata = implode(", ", $clauses['orders']); |
|
673 | + if (isset($options['order_by']) && $options['order_by']) { |
|
674 | + $options['order_by'] = "$order_by_metadata, {$options['order_by']}"; |
|
675 | + } else { |
|
676 | + $options['order_by'] = "$order_by_metadata, e.time_created DESC"; |
|
677 | + } |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + return $options; |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -692,13 +692,13 @@ discard block |
||
692 | 692 | * @access private |
693 | 693 | */ |
694 | 694 | function _elgg_metastrings_test($hook, $type, $value) { |
695 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreMetastringsTest.php'; |
|
696 | - return $value; |
|
695 | + $value[] = Paths::elgg() . 'engine/tests/ElggCoreMetastringsTest.php'; |
|
696 | + return $value; |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
700 | 700 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
701 | 701 | */ |
702 | 702 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
703 | - $hooks->registerHandler('unit_test', 'system', '_elgg_metastrings_test'); |
|
703 | + $hooks->registerHandler('unit_test', 'system', '_elgg_metastrings_test'); |
|
704 | 704 | }; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | // only supported on values. |
341 | 341 | $binary = ($case_sensitive) ? ' BINARY ' : ''; |
342 | 342 | |
343 | - $return = [ |
|
343 | + $return = [ |
|
344 | 344 | 'joins' => [], |
345 | 345 | 'wheres' => [] |
346 | 346 | ]; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | if (!$name) { |
361 | 361 | $name = '0'; |
362 | 362 | } |
363 | - $sanitised_names[] = '\'' . sanitise_string($name) . '\''; |
|
363 | + $sanitised_names[] = '\''.sanitise_string($name).'\''; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | if ($names_str = implode(',', $sanitised_names)) { |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | if (!$value) { |
382 | 382 | $value = 0; |
383 | 383 | } |
384 | - $sanitised_values[] = '\'' . sanitise_string($value) . '\''; |
|
384 | + $sanitised_values[] = '\''.sanitise_string($value).'\''; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | if ($values_str = implode(',', $sanitised_values)) { |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | $options = _elgg_normalize_plural_options_array($options, $singulars); |
458 | 458 | |
459 | 459 | foreach ($map as $specific => $normalized) { |
460 | - $key = $prefix . $specific; |
|
460 | + $key = $prefix.$specific; |
|
461 | 461 | if (isset($options[$key])) { |
462 | 462 | $options[$normalized] = $options[$key]; |
463 | 463 | } |
@@ -593,12 +593,12 @@ discard block |
||
593 | 593 | switch ($type) { |
594 | 594 | case 'annotations': |
595 | 595 | case 'annotation': |
596 | - $table = $db_prefix . 'annotations'; |
|
596 | + $table = $db_prefix.'annotations'; |
|
597 | 597 | $type = 'annotation'; |
598 | 598 | break; |
599 | 599 | |
600 | 600 | case 'metadata': |
601 | - $table = $db_prefix . 'metadata'; |
|
601 | + $table = $db_prefix.'metadata'; |
|
602 | 602 | $type = 'metadata'; |
603 | 603 | break; |
604 | 604 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | * @access private |
693 | 693 | */ |
694 | 694 | function _elgg_metastrings_test($hook, $type, $value) { |
695 | - $value[] = Paths::elgg() . 'engine/tests/ElggCoreMetastringsTest.php'; |
|
695 | + $value[] = Paths::elgg().'engine/tests/ElggCoreMetastringsTest.php'; |
|
696 | 696 | return $value; |
697 | 697 | } |
698 | 698 |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $username The username |
131 | 131 | * @param string $password The password |
132 | 132 | * |
133 | - * @return true|string True or an error message on failure |
|
133 | + * @return string|boolean True or an error message on failure |
|
134 | 134 | * @access private |
135 | 135 | */ |
136 | 136 | function elgg_authenticate($username, $password) { |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * @param \ElggUser $user A valid Elgg user object |
315 | 315 | * @param boolean $persistent Should this be a persistent login? |
316 | 316 | * |
317 | - * @return true or throws exception |
|
317 | + * @return boolean or throws exception |
|
318 | 318 | * @throws LoginException |
319 | 319 | */ |
320 | 320 | function login(\ElggUser $user, $persistent = false) { |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @since 1.9 |
19 | 19 | */ |
20 | 20 | function elgg_get_session() { |
21 | - return _elgg_services()->session; |
|
21 | + return _elgg_services()->session; |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return \ElggUser|null |
28 | 28 | */ |
29 | 29 | function elgg_get_logged_in_user_entity() { |
30 | - return _elgg_services()->session->getLoggedInUser(); |
|
30 | + return _elgg_services()->session->getLoggedInUser(); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @return int |
38 | 38 | */ |
39 | 39 | function elgg_get_logged_in_user_guid() { |
40 | - return _elgg_services()->session->getLoggedInUserGuid(); |
|
40 | + return _elgg_services()->session->getLoggedInUserGuid(); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return bool |
47 | 47 | */ |
48 | 48 | function elgg_is_logged_in() { |
49 | - return _elgg_services()->session->isLoggedIn(); |
|
49 | + return _elgg_services()->session->isLoggedIn(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @return bool |
56 | 56 | */ |
57 | 57 | function elgg_is_admin_logged_in() { |
58 | - return _elgg_services()->session->isAdminLoggedIn(); |
|
58 | + return _elgg_services()->session->isAdminLoggedIn(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -70,28 +70,28 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function elgg_is_admin_user($user_guid) { |
72 | 72 | |
73 | - $user_guid = (int) $user_guid; |
|
73 | + $user_guid = (int) $user_guid; |
|
74 | 74 | |
75 | - $current_user = elgg_get_logged_in_user_entity(); |
|
76 | - if ($current_user && $current_user->guid == $user_guid) { |
|
77 | - return $current_user->isAdmin(); |
|
78 | - } |
|
75 | + $current_user = elgg_get_logged_in_user_entity(); |
|
76 | + if ($current_user && $current_user->guid == $user_guid) { |
|
77 | + return $current_user->isAdmin(); |
|
78 | + } |
|
79 | 79 | |
80 | - // cannot use magic metadata here because of recursion |
|
81 | - $dbprefix = _elgg_config()->dbprefix; |
|
82 | - $query = "SELECT 1 FROM {$dbprefix}users_entity as e |
|
80 | + // cannot use magic metadata here because of recursion |
|
81 | + $dbprefix = _elgg_config()->dbprefix; |
|
82 | + $query = "SELECT 1 FROM {$dbprefix}users_entity as e |
|
83 | 83 | WHERE ( |
84 | 84 | e.guid = {$user_guid} |
85 | 85 | AND e.admin = 'yes' |
86 | 86 | )"; |
87 | 87 | |
88 | - // normalizing the results from get_data() |
|
89 | - // See #1242 |
|
90 | - $info = get_data($query); |
|
91 | - if (!((is_array($info) && count($info) < 1) || $info === false)) { |
|
92 | - return true; |
|
93 | - } |
|
94 | - return false; |
|
88 | + // normalizing the results from get_data() |
|
89 | + // See #1242 |
|
90 | + $info = get_data($query); |
|
91 | + if (!((is_array($info) && count($info) < 1) || $info === false)) { |
|
92 | + return true; |
|
93 | + } |
|
94 | + return false; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | * @access private |
111 | 111 | */ |
112 | 112 | function elgg_authenticate($username, $password) { |
113 | - $pam = new \ElggPAM('user'); |
|
114 | - $credentials = ['username' => $username, 'password' => $password]; |
|
115 | - $result = $pam->authenticate($credentials); |
|
116 | - if (!$result) { |
|
117 | - return $pam->getFailureMessage(); |
|
118 | - } |
|
119 | - return true; |
|
113 | + $pam = new \ElggPAM('user'); |
|
114 | + $credentials = ['username' => $username, 'password' => $password]; |
|
115 | + $result = $pam->authenticate($credentials); |
|
116 | + if (!$result) { |
|
117 | + return $pam->getFailureMessage(); |
|
118 | + } |
|
119 | + return true; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -133,33 +133,33 @@ discard block |
||
133 | 133 | */ |
134 | 134 | function pam_auth_userpass(array $credentials = []) { |
135 | 135 | |
136 | - if (!isset($credentials['username']) || !isset($credentials['password'])) { |
|
137 | - return false; |
|
138 | - } |
|
136 | + if (!isset($credentials['username']) || !isset($credentials['password'])) { |
|
137 | + return false; |
|
138 | + } |
|
139 | 139 | |
140 | - $user = get_user_by_username($credentials['username']); |
|
141 | - if (!$user) { |
|
142 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:UsernameFailure')); |
|
143 | - } |
|
140 | + $user = get_user_by_username($credentials['username']); |
|
141 | + if (!$user) { |
|
142 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:UsernameFailure')); |
|
143 | + } |
|
144 | 144 | |
145 | - $password_svc = _elgg_services()->passwords; |
|
146 | - $password = $credentials['password']; |
|
147 | - $hash = $user->password_hash; |
|
145 | + $password_svc = _elgg_services()->passwords; |
|
146 | + $password = $credentials['password']; |
|
147 | + $hash = $user->password_hash; |
|
148 | 148 | |
149 | - if (check_rate_limit_exceeded($user->guid)) { |
|
150 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:AccountLocked')); |
|
151 | - } |
|
149 | + if (check_rate_limit_exceeded($user->guid)) { |
|
150 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:AccountLocked')); |
|
151 | + } |
|
152 | 152 | |
153 | - if (!$password_svc->verify($password, $hash)) { |
|
154 | - log_login_failure($user->guid); |
|
155 | - throw new \LoginException(_elgg_services()->translator->translate('LoginException:PasswordFailure')); |
|
156 | - } |
|
153 | + if (!$password_svc->verify($password, $hash)) { |
|
154 | + log_login_failure($user->guid); |
|
155 | + throw new \LoginException(_elgg_services()->translator->translate('LoginException:PasswordFailure')); |
|
156 | + } |
|
157 | 157 | |
158 | - if ($password_svc->needsRehash($hash)) { |
|
159 | - $password_svc->forcePasswordReset($user, $password); |
|
160 | - } |
|
158 | + if ($password_svc->needsRehash($hash)) { |
|
159 | + $password_svc->forcePasswordReset($user, $password); |
|
160 | + } |
|
161 | 161 | |
162 | - return true; |
|
162 | + return true; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | function log_login_failure($user_guid) { |
173 | - $user_guid = (int) $user_guid; |
|
174 | - $user = get_entity($user_guid); |
|
173 | + $user_guid = (int) $user_guid; |
|
174 | + $user = get_entity($user_guid); |
|
175 | 175 | |
176 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
177 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
178 | - $fails++; |
|
176 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
177 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
178 | + $fails++; |
|
179 | 179 | |
180 | - $user->setPrivateSetting("login_failures", $fails); |
|
181 | - $user->setPrivateSetting("login_failure_$fails", time()); |
|
182 | - return true; |
|
183 | - } |
|
180 | + $user->setPrivateSetting("login_failures", $fails); |
|
181 | + $user->setPrivateSetting("login_failure_$fails", time()); |
|
182 | + return true; |
|
183 | + } |
|
184 | 184 | |
185 | - return false; |
|
185 | + return false; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -193,27 +193,27 @@ discard block |
||
193 | 193 | * @return bool true on success (success = user has no logged failed attempts) |
194 | 194 | */ |
195 | 195 | function reset_login_failure_count($user_guid) { |
196 | - $user_guid = (int) $user_guid; |
|
197 | - $user = get_entity($user_guid); |
|
196 | + $user_guid = (int) $user_guid; |
|
197 | + $user = get_entity($user_guid); |
|
198 | 198 | |
199 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
200 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
199 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
200 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
201 | 201 | |
202 | - if ($fails) { |
|
203 | - for ($n = 1; $n <= $fails; $n++) { |
|
204 | - $user->removePrivateSetting("login_failure_$n"); |
|
205 | - } |
|
202 | + if ($fails) { |
|
203 | + for ($n = 1; $n <= $fails; $n++) { |
|
204 | + $user->removePrivateSetting("login_failure_$n"); |
|
205 | + } |
|
206 | 206 | |
207 | - $user->removePrivateSetting("login_failures"); |
|
207 | + $user->removePrivateSetting("login_failures"); |
|
208 | 208 | |
209 | - return true; |
|
210 | - } |
|
209 | + return true; |
|
210 | + } |
|
211 | 211 | |
212 | - // nothing to reset |
|
213 | - return true; |
|
214 | - } |
|
212 | + // nothing to reset |
|
213 | + return true; |
|
214 | + } |
|
215 | 215 | |
216 | - return false; |
|
216 | + return false; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -224,31 +224,31 @@ discard block |
||
224 | 224 | * @return bool on exceeded limit. |
225 | 225 | */ |
226 | 226 | function check_rate_limit_exceeded($user_guid) { |
227 | - // 5 failures in 5 minutes causes temporary block on logins |
|
228 | - $limit = 5; |
|
229 | - $user_guid = (int) $user_guid; |
|
230 | - $user = get_entity($user_guid); |
|
231 | - |
|
232 | - if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
233 | - $fails = (int) $user->getPrivateSetting("login_failures"); |
|
234 | - if ($fails >= $limit) { |
|
235 | - $cnt = 0; |
|
236 | - $time = time(); |
|
237 | - for ($n = $fails; $n > 0; $n--) { |
|
238 | - $f = $user->getPrivateSetting("login_failure_$n"); |
|
239 | - if ($f > $time - (60 * 5)) { |
|
240 | - $cnt++; |
|
241 | - } |
|
242 | - |
|
243 | - if ($cnt == $limit) { |
|
244 | - // Limit reached |
|
245 | - return true; |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - return false; |
|
227 | + // 5 failures in 5 minutes causes temporary block on logins |
|
228 | + $limit = 5; |
|
229 | + $user_guid = (int) $user_guid; |
|
230 | + $user = get_entity($user_guid); |
|
231 | + |
|
232 | + if (($user_guid) && ($user) && ($user instanceof \ElggUser)) { |
|
233 | + $fails = (int) $user->getPrivateSetting("login_failures"); |
|
234 | + if ($fails >= $limit) { |
|
235 | + $cnt = 0; |
|
236 | + $time = time(); |
|
237 | + for ($n = $fails; $n > 0; $n--) { |
|
238 | + $f = $user->getPrivateSetting("login_failure_$n"); |
|
239 | + if ($f > $time - (60 * 5)) { |
|
240 | + $cnt++; |
|
241 | + } |
|
242 | + |
|
243 | + if ($cnt == $limit) { |
|
244 | + // Limit reached |
|
245 | + return true; |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + return false; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | * @since 1.9 |
262 | 262 | */ |
263 | 263 | function elgg_set_cookie(\ElggCookie $cookie) { |
264 | - if (elgg_trigger_event('init:cookie', $cookie->name, $cookie)) { |
|
265 | - return setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, |
|
266 | - $cookie->domain, $cookie->secure, $cookie->httpOnly); |
|
267 | - } |
|
268 | - return false; |
|
264 | + if (elgg_trigger_event('init:cookie', $cookie->name, $cookie)) { |
|
265 | + return setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, |
|
266 | + $cookie->domain, $cookie->secure, $cookie->httpOnly); |
|
267 | + } |
|
268 | + return false; |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -281,35 +281,35 @@ discard block |
||
281 | 281 | * @throws LoginException |
282 | 282 | */ |
283 | 283 | function login(\ElggUser $user, $persistent = false) { |
284 | - if ($user->isBanned()) { |
|
285 | - throw new \LoginException(elgg_echo('LoginException:BannedUser')); |
|
286 | - } |
|
284 | + if ($user->isBanned()) { |
|
285 | + throw new \LoginException(elgg_echo('LoginException:BannedUser')); |
|
286 | + } |
|
287 | 287 | |
288 | - $session = _elgg_services()->session; |
|
288 | + $session = _elgg_services()->session; |
|
289 | 289 | |
290 | - // give plugins a chance to reject the login of this user (no user in session!) |
|
291 | - if (!elgg_trigger_before_event('login', 'user', $user)) { |
|
292 | - throw new \LoginException(elgg_echo('LoginException:Unknown')); |
|
293 | - } |
|
290 | + // give plugins a chance to reject the login of this user (no user in session!) |
|
291 | + if (!elgg_trigger_before_event('login', 'user', $user)) { |
|
292 | + throw new \LoginException(elgg_echo('LoginException:Unknown')); |
|
293 | + } |
|
294 | 294 | |
295 | - // #5933: set logged in user early so code in login event will be able to |
|
296 | - // use elgg_get_logged_in_user_entity(). |
|
297 | - $session->setLoggedInUser($user); |
|
295 | + // #5933: set logged in user early so code in login event will be able to |
|
296 | + // use elgg_get_logged_in_user_entity(). |
|
297 | + $session->setLoggedInUser($user); |
|
298 | 298 | |
299 | - // if remember me checked, set cookie with token and store hash(token) for user |
|
300 | - if ($persistent) { |
|
301 | - _elgg_services()->persistentLogin->makeLoginPersistent($user); |
|
302 | - } |
|
299 | + // if remember me checked, set cookie with token and store hash(token) for user |
|
300 | + if ($persistent) { |
|
301 | + _elgg_services()->persistentLogin->makeLoginPersistent($user); |
|
302 | + } |
|
303 | 303 | |
304 | - // User's privilege has been elevated, so change the session id (prevents session fixation) |
|
305 | - $session->migrate(); |
|
304 | + // User's privilege has been elevated, so change the session id (prevents session fixation) |
|
305 | + $session->migrate(); |
|
306 | 306 | |
307 | - set_last_login($user->guid); |
|
308 | - reset_login_failure_count($user->guid); |
|
307 | + set_last_login($user->guid); |
|
308 | + reset_login_failure_count($user->guid); |
|
309 | 309 | |
310 | - elgg_trigger_after_event('login', 'user', $user); |
|
310 | + elgg_trigger_after_event('login', 'user', $user); |
|
311 | 311 | |
312 | - return true; |
|
312 | + return true; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -318,26 +318,26 @@ discard block |
||
318 | 318 | * @return bool |
319 | 319 | */ |
320 | 320 | function logout() { |
321 | - $session = _elgg_services()->session; |
|
322 | - $user = $session->getLoggedInUser(); |
|
323 | - if (!$user) { |
|
324 | - return false; |
|
325 | - } |
|
321 | + $session = _elgg_services()->session; |
|
322 | + $user = $session->getLoggedInUser(); |
|
323 | + if (!$user) { |
|
324 | + return false; |
|
325 | + } |
|
326 | 326 | |
327 | - if (!elgg_trigger_before_event('logout', 'user', $user)) { |
|
328 | - return false; |
|
329 | - } |
|
327 | + if (!elgg_trigger_before_event('logout', 'user', $user)) { |
|
328 | + return false; |
|
329 | + } |
|
330 | 330 | |
331 | - _elgg_services()->persistentLogin->removePersistentLogin(); |
|
331 | + _elgg_services()->persistentLogin->removePersistentLogin(); |
|
332 | 332 | |
333 | - // pass along any messages into new session |
|
334 | - $old_msg = $session->get(SystemMessagesService::SESSION_KEY, []); |
|
335 | - $session->invalidate(); |
|
336 | - $session->set(SystemMessagesService::SESSION_KEY, $old_msg); |
|
333 | + // pass along any messages into new session |
|
334 | + $old_msg = $session->get(SystemMessagesService::SESSION_KEY, []); |
|
335 | + $session->invalidate(); |
|
336 | + $session->set(SystemMessagesService::SESSION_KEY, $old_msg); |
|
337 | 337 | |
338 | - elgg_trigger_after_event('logout', 'user', $user); |
|
338 | + elgg_trigger_after_event('logout', 'user', $user); |
|
339 | 339 | |
340 | - return true; |
|
340 | + return true; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -349,44 +349,44 @@ discard block |
||
349 | 349 | * @access private |
350 | 350 | */ |
351 | 351 | function _elgg_session_boot(ServiceProvider $services) { |
352 | - $services->timer->begin([__FUNCTION__]); |
|
353 | - |
|
354 | - $session = $services->session; |
|
355 | - $session->start(); |
|
356 | - |
|
357 | - // test whether we have a user session |
|
358 | - if ($session->has('guid')) { |
|
359 | - /** @var ElggUser $user */ |
|
360 | - $user = $services->entityTable->get($session->get('guid'), 'user'); |
|
361 | - if (!$user) { |
|
362 | - // OMG user has been deleted. |
|
363 | - $session->invalidate(); |
|
364 | - forward(''); |
|
365 | - } |
|
366 | - |
|
367 | - $services->persistentLogin->replaceLegacyToken($user); |
|
368 | - } else { |
|
369 | - $user = $services->persistentLogin->bootSession(); |
|
370 | - } |
|
371 | - |
|
372 | - if ($user) { |
|
373 | - $session->setLoggedInUser($user); |
|
374 | - set_last_action($user); |
|
375 | - |
|
376 | - // logout a user with open session who has been banned |
|
377 | - if ($user->isBanned()) { |
|
378 | - logout(); |
|
379 | - return false; |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - $services->timer->end([__FUNCTION__]); |
|
384 | - return true; |
|
352 | + $services->timer->begin([__FUNCTION__]); |
|
353 | + |
|
354 | + $session = $services->session; |
|
355 | + $session->start(); |
|
356 | + |
|
357 | + // test whether we have a user session |
|
358 | + if ($session->has('guid')) { |
|
359 | + /** @var ElggUser $user */ |
|
360 | + $user = $services->entityTable->get($session->get('guid'), 'user'); |
|
361 | + if (!$user) { |
|
362 | + // OMG user has been deleted. |
|
363 | + $session->invalidate(); |
|
364 | + forward(''); |
|
365 | + } |
|
366 | + |
|
367 | + $services->persistentLogin->replaceLegacyToken($user); |
|
368 | + } else { |
|
369 | + $user = $services->persistentLogin->bootSession(); |
|
370 | + } |
|
371 | + |
|
372 | + if ($user) { |
|
373 | + $session->setLoggedInUser($user); |
|
374 | + set_last_action($user); |
|
375 | + |
|
376 | + // logout a user with open session who has been banned |
|
377 | + if ($user->isBanned()) { |
|
378 | + logout(); |
|
379 | + return false; |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + $services->timer->end([__FUNCTION__]); |
|
384 | + return true; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
388 | 388 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
389 | 389 | */ |
390 | 390 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
391 | - register_pam_handler('pam_auth_userpass'); |
|
391 | + register_pam_handler('pam_auth_userpass'); |
|
392 | 392 | }; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * @param string $object_type Object type |
299 | 299 | * @param Loggable $object Object to log |
300 | 300 | * |
301 | - * @return true |
|
301 | + * @return boolean |
|
302 | 302 | */ |
303 | 303 | function system_log_default_logger($event, $object_type, $object) { |
304 | 304 | system_log($object['object'], $object['event']); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * @param String $object_type Type of object |
315 | 315 | * @param Loggable $object Object to log |
316 | 316 | * |
317 | - * @return true |
|
317 | + * @return boolean |
|
318 | 318 | * @access private |
319 | 319 | */ |
320 | 320 | function system_log_listener($event, $object_type, $object) { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if (is_int($by_user)) { |
60 | 60 | $where[] = "performed_by_guid=$by_user"; |
61 | 61 | } else if (is_array($by_user)) { |
62 | - $where [] = "performed_by_guid in (" . implode(",", $by_user) . ")"; |
|
62 | + $where [] = "performed_by_guid in (".implode(",", $by_user).")"; |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | if ($event != "") { |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | if ($timebefore) { |
79 | - $where[] = "time_created < " . ((int) $timebefore); |
|
79 | + $where[] = "time_created < ".((int) $timebefore); |
|
80 | 80 | } |
81 | 81 | if ($timeafter) { |
82 | - $where[] = "time_created > " . ((int) $timeafter); |
|
82 | + $where[] = "time_created > ".((int) $timeafter); |
|
83 | 83 | } |
84 | 84 | if ($object_id) { |
85 | - $where[] = "object_id = " . ((int) $object_id); |
|
85 | + $where[] = "object_id = ".((int) $object_id); |
|
86 | 86 | } |
87 | 87 | if ($ip_address) { |
88 | 88 | $where[] = "ip_address = '$ip_address'"; |
@@ -28,90 +28,90 @@ discard block |
||
28 | 28 | * @return mixed |
29 | 29 | */ |
30 | 30 | function get_system_log($by_user = "", $event = "", $class = "", $type = "", $subtype = "", $limit = null, |
31 | - $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $object_id = 0, |
|
32 | - $ip_address = "") { |
|
33 | - |
|
34 | - $by_user_orig = $by_user; |
|
35 | - if (is_array($by_user) && sizeof($by_user) > 0) { |
|
36 | - foreach ($by_user as $key => $val) { |
|
37 | - $by_user[$key] = (int) $val; |
|
38 | - } |
|
39 | - } else { |
|
40 | - $by_user = (int) $by_user; |
|
41 | - } |
|
31 | + $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $object_id = 0, |
|
32 | + $ip_address = "") { |
|
33 | + |
|
34 | + $by_user_orig = $by_user; |
|
35 | + if (is_array($by_user) && sizeof($by_user) > 0) { |
|
36 | + foreach ($by_user as $key => $val) { |
|
37 | + $by_user[$key] = (int) $val; |
|
38 | + } |
|
39 | + } else { |
|
40 | + $by_user = (int) $by_user; |
|
41 | + } |
|
42 | 42 | |
43 | - $event = sanitise_string($event); |
|
44 | - $class = sanitise_string($class); |
|
45 | - $type = sanitise_string($type); |
|
46 | - $subtype = sanitise_string($subtype); |
|
47 | - $ip_address = sanitise_string($ip_address); |
|
48 | - if ($limit === null) { |
|
49 | - $limit = _elgg_config()->default_limit; |
|
50 | - } |
|
51 | - $limit = (int) $limit; |
|
52 | - $offset = (int) $offset; |
|
53 | - |
|
54 | - $where = []; |
|
55 | - |
|
56 | - if ($by_user_orig !== "" && $by_user_orig !== false && $by_user_orig !== null) { |
|
57 | - if (is_int($by_user)) { |
|
58 | - $where[] = "performed_by_guid=$by_user"; |
|
59 | - } else if (is_array($by_user)) { |
|
60 | - $where [] = "performed_by_guid in (" . implode(",", $by_user) . ")"; |
|
61 | - } |
|
62 | - } |
|
63 | - if ($event != "") { |
|
64 | - $where[] = "event='$event'"; |
|
65 | - } |
|
66 | - if ($class !== "") { |
|
67 | - $where[] = "object_class='$class'"; |
|
68 | - } |
|
69 | - if ($type != "") { |
|
70 | - $where[] = "object_type='$type'"; |
|
71 | - } |
|
72 | - if ($subtype !== "") { |
|
73 | - $where[] = "object_subtype='$subtype'"; |
|
74 | - } |
|
75 | - |
|
76 | - if ($timebefore) { |
|
77 | - $where[] = "time_created < " . ((int) $timebefore); |
|
78 | - } |
|
79 | - if ($timeafter) { |
|
80 | - $where[] = "time_created > " . ((int) $timeafter); |
|
81 | - } |
|
82 | - if ($object_id) { |
|
83 | - $where[] = "object_id = " . ((int) $object_id); |
|
84 | - } |
|
85 | - if ($ip_address) { |
|
86 | - $where[] = "ip_address = '$ip_address'"; |
|
87 | - } |
|
88 | - |
|
89 | - $select = "*"; |
|
90 | - if ($count) { |
|
91 | - $select = "count(*) as count"; |
|
92 | - } |
|
93 | - |
|
94 | - $prefix = _elgg_config()->dbprefix; |
|
95 | - $query = "SELECT $select from {$prefix}system_log where 1 "; |
|
96 | - foreach ($where as $w) { |
|
97 | - $query .= " and $w"; |
|
98 | - } |
|
99 | - |
|
100 | - if (!$count) { |
|
101 | - $query .= " order by time_created desc"; |
|
102 | - $query .= " limit $offset, $limit"; // Add order and limit |
|
103 | - } |
|
104 | - |
|
105 | - if ($count) { |
|
106 | - $numrows = get_data_row($query); |
|
107 | - if ($numrows) { |
|
108 | - return $numrows->count; |
|
109 | - } |
|
110 | - } else { |
|
111 | - return get_data($query); |
|
112 | - } |
|
113 | - |
|
114 | - return false; |
|
43 | + $event = sanitise_string($event); |
|
44 | + $class = sanitise_string($class); |
|
45 | + $type = sanitise_string($type); |
|
46 | + $subtype = sanitise_string($subtype); |
|
47 | + $ip_address = sanitise_string($ip_address); |
|
48 | + if ($limit === null) { |
|
49 | + $limit = _elgg_config()->default_limit; |
|
50 | + } |
|
51 | + $limit = (int) $limit; |
|
52 | + $offset = (int) $offset; |
|
53 | + |
|
54 | + $where = []; |
|
55 | + |
|
56 | + if ($by_user_orig !== "" && $by_user_orig !== false && $by_user_orig !== null) { |
|
57 | + if (is_int($by_user)) { |
|
58 | + $where[] = "performed_by_guid=$by_user"; |
|
59 | + } else if (is_array($by_user)) { |
|
60 | + $where [] = "performed_by_guid in (" . implode(",", $by_user) . ")"; |
|
61 | + } |
|
62 | + } |
|
63 | + if ($event != "") { |
|
64 | + $where[] = "event='$event'"; |
|
65 | + } |
|
66 | + if ($class !== "") { |
|
67 | + $where[] = "object_class='$class'"; |
|
68 | + } |
|
69 | + if ($type != "") { |
|
70 | + $where[] = "object_type='$type'"; |
|
71 | + } |
|
72 | + if ($subtype !== "") { |
|
73 | + $where[] = "object_subtype='$subtype'"; |
|
74 | + } |
|
75 | + |
|
76 | + if ($timebefore) { |
|
77 | + $where[] = "time_created < " . ((int) $timebefore); |
|
78 | + } |
|
79 | + if ($timeafter) { |
|
80 | + $where[] = "time_created > " . ((int) $timeafter); |
|
81 | + } |
|
82 | + if ($object_id) { |
|
83 | + $where[] = "object_id = " . ((int) $object_id); |
|
84 | + } |
|
85 | + if ($ip_address) { |
|
86 | + $where[] = "ip_address = '$ip_address'"; |
|
87 | + } |
|
88 | + |
|
89 | + $select = "*"; |
|
90 | + if ($count) { |
|
91 | + $select = "count(*) as count"; |
|
92 | + } |
|
93 | + |
|
94 | + $prefix = _elgg_config()->dbprefix; |
|
95 | + $query = "SELECT $select from {$prefix}system_log where 1 "; |
|
96 | + foreach ($where as $w) { |
|
97 | + $query .= " and $w"; |
|
98 | + } |
|
99 | + |
|
100 | + if (!$count) { |
|
101 | + $query .= " order by time_created desc"; |
|
102 | + $query .= " limit $offset, $limit"; // Add order and limit |
|
103 | + } |
|
104 | + |
|
105 | + if ($count) { |
|
106 | + $numrows = get_data_row($query); |
|
107 | + if ($numrows) { |
|
108 | + return $numrows->count; |
|
109 | + } |
|
110 | + } else { |
|
111 | + return get_data($query); |
|
112 | + } |
|
113 | + |
|
114 | + return false; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | * @return mixed |
123 | 123 | */ |
124 | 124 | function get_log_entry($entry_id) { |
125 | - $entry_id = (int) $entry_id; |
|
125 | + $entry_id = (int) $entry_id; |
|
126 | 126 | |
127 | - $prefix = _elgg_config()->dbprefix; |
|
128 | - return get_data_row("SELECT * from {$prefix}system_log where id=$entry_id"); |
|
127 | + $prefix = _elgg_config()->dbprefix; |
|
128 | + return get_data_row("SELECT * from {$prefix}system_log where id=$entry_id"); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -136,45 +136,45 @@ discard block |
||
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | 138 | function get_object_from_log_entry($entry) { |
139 | - if (is_numeric($entry)) { |
|
140 | - $entry = get_log_entry($entry); |
|
141 | - if (!$entry) { |
|
142 | - return false; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - $class = $entry->object_class; |
|
147 | - $id = $entry->object_id; |
|
148 | - |
|
149 | - if (!class_exists($class)) { |
|
150 | - // failed autoload |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - $getters = [ |
|
155 | - 'ElggAnnotation' => 'elgg_get_annotation_from_id', |
|
156 | - 'ElggMetadata' => 'elgg_get_metadata_from_id', |
|
157 | - 'ElggRelationship' => 'get_relationship', |
|
158 | - ]; |
|
159 | - |
|
160 | - if (isset($getters[$class]) && is_callable($getters[$class])) { |
|
161 | - $object = call_user_func($getters[$class], $id); |
|
162 | - } elseif (preg_match('~^Elgg[A-Z]~', $class)) { |
|
163 | - $object = get_entity($id); |
|
164 | - } else { |
|
165 | - // surround with try/catch because object could be disabled |
|
166 | - try { |
|
167 | - $object = new $class($entry->object_id); |
|
168 | - return $object; |
|
169 | - } catch (Exception $e) { |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - if (!is_object($object) || get_class($object) !== $class) { |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - return $object; |
|
139 | + if (is_numeric($entry)) { |
|
140 | + $entry = get_log_entry($entry); |
|
141 | + if (!$entry) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + $class = $entry->object_class; |
|
147 | + $id = $entry->object_id; |
|
148 | + |
|
149 | + if (!class_exists($class)) { |
|
150 | + // failed autoload |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + $getters = [ |
|
155 | + 'ElggAnnotation' => 'elgg_get_annotation_from_id', |
|
156 | + 'ElggMetadata' => 'elgg_get_metadata_from_id', |
|
157 | + 'ElggRelationship' => 'get_relationship', |
|
158 | + ]; |
|
159 | + |
|
160 | + if (isset($getters[$class]) && is_callable($getters[$class])) { |
|
161 | + $object = call_user_func($getters[$class], $id); |
|
162 | + } elseif (preg_match('~^Elgg[A-Z]~', $class)) { |
|
163 | + $object = get_entity($id); |
|
164 | + } else { |
|
165 | + // surround with try/catch because object could be disabled |
|
166 | + try { |
|
167 | + $object = new $class($entry->object_id); |
|
168 | + return $object; |
|
169 | + } catch (Exception $e) { |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + if (!is_object($object) || get_class($object) !== $class) { |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + return $object; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -187,68 +187,68 @@ discard block |
||
187 | 187 | * @return void |
188 | 188 | */ |
189 | 189 | function system_log($object, $event) { |
190 | - static $log_cache; |
|
191 | - static $cache_size = 0; |
|
192 | - |
|
193 | - if ($object instanceof Loggable) { |
|
194 | - /* @var \ElggEntity|\ElggExtender $object */ |
|
195 | - if (_elgg_config()->version < 2012012000) { |
|
196 | - // this is a site that doesn't have the ip_address column yet |
|
197 | - return; |
|
198 | - } |
|
199 | - |
|
200 | - // reset cache if it has grown too large |
|
201 | - if (!is_array($log_cache) || $cache_size > 500) { |
|
202 | - $log_cache = []; |
|
203 | - $cache_size = 0; |
|
204 | - } |
|
205 | - |
|
206 | - // Has loggable interface, extract the necessary information and store |
|
207 | - $object_id = (int) $object->getSystemLogID(); |
|
208 | - $object_class = get_class($object); |
|
209 | - $object_type = $object->getType(); |
|
210 | - $object_subtype = $object->getSubtype(); |
|
211 | - $event = sanitise_string($event); |
|
212 | - $time = time(); |
|
213 | - $ip_address = sanitize_string(_elgg_services()->request->getClientIp()); |
|
214 | - if (!$ip_address) { |
|
215 | - $ip_address = '0.0.0.0'; |
|
216 | - } |
|
217 | - $performed_by = elgg_get_logged_in_user_guid(); |
|
218 | - |
|
219 | - if (isset($object->access_id)) { |
|
220 | - $access_id = $object->access_id; |
|
221 | - } else { |
|
222 | - $access_id = ACCESS_PUBLIC; |
|
223 | - } |
|
224 | - if (isset($object->enabled)) { |
|
225 | - $enabled = $object->enabled; |
|
226 | - } else { |
|
227 | - $enabled = 'yes'; |
|
228 | - } |
|
229 | - |
|
230 | - if (isset($object->owner_guid)) { |
|
231 | - $owner_guid = $object->owner_guid; |
|
232 | - } else { |
|
233 | - $owner_guid = 0; |
|
234 | - } |
|
235 | - |
|
236 | - // Create log if we haven't already created it |
|
237 | - if (!isset($log_cache[$time][$object_id][$event])) { |
|
238 | - $prefix = _elgg_config()->dbprefix; |
|
239 | - $query = "INSERT into {$prefix}system_log |
|
190 | + static $log_cache; |
|
191 | + static $cache_size = 0; |
|
192 | + |
|
193 | + if ($object instanceof Loggable) { |
|
194 | + /* @var \ElggEntity|\ElggExtender $object */ |
|
195 | + if (_elgg_config()->version < 2012012000) { |
|
196 | + // this is a site that doesn't have the ip_address column yet |
|
197 | + return; |
|
198 | + } |
|
199 | + |
|
200 | + // reset cache if it has grown too large |
|
201 | + if (!is_array($log_cache) || $cache_size > 500) { |
|
202 | + $log_cache = []; |
|
203 | + $cache_size = 0; |
|
204 | + } |
|
205 | + |
|
206 | + // Has loggable interface, extract the necessary information and store |
|
207 | + $object_id = (int) $object->getSystemLogID(); |
|
208 | + $object_class = get_class($object); |
|
209 | + $object_type = $object->getType(); |
|
210 | + $object_subtype = $object->getSubtype(); |
|
211 | + $event = sanitise_string($event); |
|
212 | + $time = time(); |
|
213 | + $ip_address = sanitize_string(_elgg_services()->request->getClientIp()); |
|
214 | + if (!$ip_address) { |
|
215 | + $ip_address = '0.0.0.0'; |
|
216 | + } |
|
217 | + $performed_by = elgg_get_logged_in_user_guid(); |
|
218 | + |
|
219 | + if (isset($object->access_id)) { |
|
220 | + $access_id = $object->access_id; |
|
221 | + } else { |
|
222 | + $access_id = ACCESS_PUBLIC; |
|
223 | + } |
|
224 | + if (isset($object->enabled)) { |
|
225 | + $enabled = $object->enabled; |
|
226 | + } else { |
|
227 | + $enabled = 'yes'; |
|
228 | + } |
|
229 | + |
|
230 | + if (isset($object->owner_guid)) { |
|
231 | + $owner_guid = $object->owner_guid; |
|
232 | + } else { |
|
233 | + $owner_guid = 0; |
|
234 | + } |
|
235 | + |
|
236 | + // Create log if we haven't already created it |
|
237 | + if (!isset($log_cache[$time][$object_id][$event])) { |
|
238 | + $prefix = _elgg_config()->dbprefix; |
|
239 | + $query = "INSERT into {$prefix}system_log |
|
240 | 240 | (object_id, object_class, object_type, object_subtype, event, |
241 | 241 | performed_by_guid, owner_guid, access_id, enabled, time_created, ip_address) |
242 | 242 | VALUES |
243 | 243 | ('$object_id','$object_class','$object_type', '$object_subtype', '$event', |
244 | 244 | $performed_by, $owner_guid, $access_id, '$enabled', '$time', '$ip_address')"; |
245 | 245 | |
246 | - execute_delayed_write_query($query); |
|
246 | + execute_delayed_write_query($query); |
|
247 | 247 | |
248 | - $log_cache[$time][$object_id][$event] = true; |
|
249 | - $cache_size += 1; |
|
250 | - } |
|
251 | - } |
|
248 | + $log_cache[$time][$object_id][$event] = true; |
|
249 | + $cache_size += 1; |
|
250 | + } |
|
251 | + } |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -259,32 +259,32 @@ discard block |
||
259 | 259 | * @return bool |
260 | 260 | */ |
261 | 261 | function archive_log($offset = 0) { |
262 | - $offset = (int) $offset; |
|
263 | - $now = time(); // Take a snapshot of now |
|
264 | - $prefix = _elgg_config()->dbprefix; |
|
262 | + $offset = (int) $offset; |
|
263 | + $now = time(); // Take a snapshot of now |
|
264 | + $prefix = _elgg_config()->dbprefix; |
|
265 | 265 | |
266 | - $ts = $now - $offset; |
|
266 | + $ts = $now - $offset; |
|
267 | 267 | |
268 | - // create table |
|
269 | - $query = "CREATE TABLE {$prefix}system_log_$now as |
|
268 | + // create table |
|
269 | + $query = "CREATE TABLE {$prefix}system_log_$now as |
|
270 | 270 | SELECT * from {$prefix}system_log WHERE time_created<$ts"; |
271 | 271 | |
272 | - if (!update_data($query)) { |
|
273 | - return false; |
|
274 | - } |
|
272 | + if (!update_data($query)) { |
|
273 | + return false; |
|
274 | + } |
|
275 | 275 | |
276 | - // delete |
|
277 | - // Don't delete on time since we are running in a concurrent environment |
|
278 | - if (delete_data("DELETE from {$prefix}system_log WHERE time_created<$ts") === false) { |
|
279 | - return false; |
|
280 | - } |
|
276 | + // delete |
|
277 | + // Don't delete on time since we are running in a concurrent environment |
|
278 | + if (delete_data("DELETE from {$prefix}system_log WHERE time_created<$ts") === false) { |
|
279 | + return false; |
|
280 | + } |
|
281 | 281 | |
282 | - // alter table to engine |
|
283 | - if (!update_data("ALTER TABLE {$prefix}system_log_$now engine=archive")) { |
|
284 | - return false; |
|
285 | - } |
|
282 | + // alter table to engine |
|
283 | + if (!update_data("ALTER TABLE {$prefix}system_log_$now engine=archive")) { |
|
284 | + return false; |
|
285 | + } |
|
286 | 286 | |
287 | - return true; |
|
287 | + return true; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * @return true |
298 | 298 | */ |
299 | 299 | function system_log_default_logger($event, $object_type, $object) { |
300 | - system_log($object['object'], $object['event']); |
|
300 | + system_log($object['object'], $object['event']); |
|
301 | 301 | |
302 | - return true; |
|
302 | + return true; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -314,20 +314,20 @@ discard block |
||
314 | 314 | * @access private |
315 | 315 | */ |
316 | 316 | function system_log_listener($event, $object_type, $object) { |
317 | - if (($object_type != 'systemlog') && ($event != 'log')) { |
|
318 | - elgg_trigger_event('log', 'systemlog', ['object' => $object, 'event' => $event]); |
|
319 | - } |
|
317 | + if (($object_type != 'systemlog') && ($event != 'log')) { |
|
318 | + elgg_trigger_event('log', 'systemlog', ['object' => $object, 'event' => $event]); |
|
319 | + } |
|
320 | 320 | |
321 | - return true; |
|
321 | + return true; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | 325 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
326 | 326 | */ |
327 | 327 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
328 | - /** Register event to listen to all events **/ |
|
329 | - $events->registerHandler('all', 'all', 'system_log_listener', 400); |
|
328 | + /** Register event to listen to all events **/ |
|
329 | + $events->registerHandler('all', 'all', 'system_log_listener', 400); |
|
330 | 330 | |
331 | - /** Register a default system log handler */ |
|
332 | - $events->registerHandler('log', 'systemlog', 'system_log_default_logger', 999); |
|
331 | + /** Register a default system log handler */ |
|
332 | + $events->registerHandler('log', 'systemlog', 'system_log_default_logger', 999); |
|
333 | 333 | }; |
@@ -167,7 +167,7 @@ |
||
167 | 167 | * @param string $directory Directory to look in |
168 | 168 | * @param array $exceptions Array of filenames to ignore |
169 | 169 | * @param array $list Array of files to append to |
170 | - * @param mixed $extensions Array of extensions to allow, NULL for all. Use a dot: array('.php'). |
|
170 | + * @param string[] $extensions Array of extensions to allow, NULL for all. Use a dot: array('.php'). |
|
171 | 171 | * |
172 | 172 | * @return array Filenames in $directory, in the form $directory/filename. |
173 | 173 | */ |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | |
11 | 11 | // only allow from the command line. |
12 | 12 | if (php_sapi_name() != 'cli') { |
13 | - die('Upgrades can only be created from the command line.'); |
|
13 | + die('Upgrades can only be created from the command line.'); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | if (count($argv) < 2) { |
17 | - elgg_create_upgrade_show_usage('No upgrade name.'); |
|
17 | + elgg_create_upgrade_show_usage('No upgrade name.'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | $name = $argv[1]; |
21 | 21 | |
22 | 22 | if (strlen($name) > 24) { |
23 | - elgg_create_upgrade_show_usage('Upgrade names cannot be longer than 24 characters.'); |
|
23 | + elgg_create_upgrade_show_usage('Upgrade names cannot be longer than 24 characters.'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | require_once '../../../version.php'; |
@@ -39,38 +39,38 @@ discard block |
||
39 | 39 | sort($files); |
40 | 40 | |
41 | 41 | foreach ($files as $filename) { |
42 | - $filename = basename($filename); |
|
43 | - $date = (int)substr($filename, 0, 8); |
|
44 | - $inc = (int)substr($filename, 8, 2); |
|
45 | - |
|
46 | - if ($upgrade_date == $date) { |
|
47 | - if ($inc >= $upgrade_inc) { |
|
48 | - $upgrade_inc = $inc + 1; |
|
49 | - } |
|
50 | - } |
|
42 | + $filename = basename($filename); |
|
43 | + $date = (int)substr($filename, 0, 8); |
|
44 | + $inc = (int)substr($filename, 8, 2); |
|
45 | + |
|
46 | + if ($upgrade_date == $date) { |
|
47 | + if ($inc >= $upgrade_inc) { |
|
48 | + $upgrade_inc = $inc + 1; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // zero-pad |
54 | 54 | // if there are more than 10 upgrades in a day, someone needs talking to. |
55 | 55 | if ($upgrade_inc < 10) { |
56 | - $upgrade_inc = "0$upgrade_inc"; |
|
56 | + $upgrade_inc = "0$upgrade_inc"; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $upgrade_version = $upgrade_date . $upgrade_inc; |
60 | 60 | |
61 | 61 | // make filename |
62 | 62 | if (substr($release, 0, 3) == '1.7') { |
63 | - // 1.7 upgrades are YYYYMMDDXX |
|
64 | - $upgrade_name = $upgrade_version . '.php'; |
|
63 | + // 1.7 upgrades are YYYYMMDDXX |
|
64 | + $upgrade_name = $upgrade_version . '.php'; |
|
65 | 65 | } else { |
66 | - // 1.8+ upgrades are YYYYMMDDXX-release-friendly_name-rnd |
|
67 | - $upgrade_name = $upgrade_version . "-$upgrade_release-$name-$upgrade_rnd.php"; |
|
66 | + // 1.8+ upgrades are YYYYMMDDXX-release-friendly_name-rnd |
|
67 | + $upgrade_name = $upgrade_version . "-$upgrade_release-$name-$upgrade_rnd.php"; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $upgrade_file = $upgrade_path . '/' . $upgrade_name; |
71 | 71 | |
72 | 72 | if (is_file($upgrade_file)) { |
73 | - elgg_create_upgrade_show_usage("Upgrade file $upgrade_file already exists. This script has failed you."); |
|
73 | + elgg_create_upgrade_show_usage("Upgrade file $upgrade_file already exists. This script has failed you."); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $upgrade_code = <<<___UPGRADE |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | $h = fopen($upgrade_file, 'wb'); |
90 | 90 | |
91 | 91 | if (!$h) { |
92 | - die("Could not open file $upgrade_file"); |
|
92 | + die("Could not open file $upgrade_file"); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | if (!fwrite($h, $upgrade_code)) { |
96 | - die("Could not write to $upgrade_file"); |
|
96 | + die("Could not write to $upgrade_file"); |
|
97 | 97 | } else { |
98 | - elgg_set_version_dot_php_version($upgrade_version); |
|
99 | - echo <<<___MSG |
|
98 | + elgg_set_version_dot_php_version($upgrade_version); |
|
99 | + echo <<<___MSG |
|
100 | 100 | |
101 | 101 | Created upgrade file and updated version.php. |
102 | 102 | |
@@ -115,26 +115,26 @@ discard block |
||
115 | 115 | * @return boolean |
116 | 116 | */ |
117 | 117 | function elgg_set_version_dot_php_version($version) { |
118 | - $file = '../../../version.php'; |
|
119 | - $h = fopen($file, 'r+b'); |
|
118 | + $file = '../../../version.php'; |
|
119 | + $h = fopen($file, 'r+b'); |
|
120 | 120 | |
121 | - if (!$h) { |
|
122 | - return false; |
|
123 | - } |
|
121 | + if (!$h) { |
|
122 | + return false; |
|
123 | + } |
|
124 | 124 | |
125 | - $out = ''; |
|
125 | + $out = ''; |
|
126 | 126 | |
127 | - while (($line = fgets($h)) !== false) { |
|
128 | - $find = "/\\\$version[ ]?=[ ]?[0-9]{10};/"; |
|
129 | - $replace = "\$version = $version;"; |
|
130 | - $out .= preg_replace($find, $replace, $line); |
|
131 | - } |
|
127 | + while (($line = fgets($h)) !== false) { |
|
128 | + $find = "/\\\$version[ ]?=[ ]?[0-9]{10};/"; |
|
129 | + $replace = "\$version = $version;"; |
|
130 | + $out .= preg_replace($find, $replace, $line); |
|
131 | + } |
|
132 | 132 | |
133 | - rewind($h); |
|
133 | + rewind($h); |
|
134 | 134 | |
135 | - fwrite($h, $out); |
|
136 | - fclose($h); |
|
137 | - return true; |
|
135 | + fwrite($h, $out); |
|
136 | + fclose($h); |
|
137 | + return true; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return void |
145 | 145 | */ |
146 | 146 | function elgg_create_upgrade_show_usage($msg = '') { |
147 | - $text = <<<___MSG |
|
147 | + $text = <<<___MSG |
|
148 | 148 | $msg |
149 | 149 | |
150 | 150 | Example: |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | ___MSG; |
154 | 154 | |
155 | - die($text); |
|
155 | + die($text); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -174,25 +174,25 @@ discard block |
||
174 | 174 | function elgg_get_file_list($directory, $exceptions = array(), $list = array(), |
175 | 175 | $extensions = NULL) { |
176 | 176 | |
177 | - $directory = sanitise_filepath($directory); |
|
178 | - if ($handle = opendir($directory)) { |
|
179 | - while (($file = readdir($handle)) !== FALSE) { |
|
180 | - if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
181 | - continue; |
|
182 | - } |
|
183 | - |
|
184 | - if (is_array($extensions)) { |
|
185 | - if (in_array(strrchr($file, '.'), $extensions)) { |
|
186 | - $list[] = $directory . $file; |
|
187 | - } |
|
188 | - } else { |
|
189 | - $list[] = $directory . $file; |
|
190 | - } |
|
191 | - } |
|
192 | - closedir($handle); |
|
193 | - } |
|
194 | - |
|
195 | - return $list; |
|
177 | + $directory = sanitise_filepath($directory); |
|
178 | + if ($handle = opendir($directory)) { |
|
179 | + while (($file = readdir($handle)) !== FALSE) { |
|
180 | + if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
181 | + continue; |
|
182 | + } |
|
183 | + |
|
184 | + if (is_array($extensions)) { |
|
185 | + if (in_array(strrchr($file, '.'), $extensions)) { |
|
186 | + $list[] = $directory . $file; |
|
187 | + } |
|
188 | + } else { |
|
189 | + $list[] = $directory . $file; |
|
190 | + } |
|
191 | + } |
|
192 | + closedir($handle); |
|
193 | + } |
|
194 | + |
|
195 | + return $list; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -204,20 +204,20 @@ discard block |
||
204 | 204 | * @return string |
205 | 205 | */ |
206 | 206 | function sanitise_filepath($path, $append_slash = TRUE) { |
207 | - // Convert to correct UNIX paths |
|
208 | - $path = str_replace('\\', '/', $path); |
|
209 | - $path = str_replace('../', '/', $path); |
|
210 | - // replace // with / except when preceeded by : |
|
211 | - $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
212 | - |
|
213 | - // Sort trailing slash |
|
214 | - $path = trim($path); |
|
215 | - // rtrim defaults plus / |
|
216 | - $path = rtrim($path, " \n\t\0\x0B/"); |
|
217 | - |
|
218 | - if ($append_slash) { |
|
219 | - $path = $path . '/'; |
|
220 | - } |
|
221 | - |
|
222 | - return $path; |
|
207 | + // Convert to correct UNIX paths |
|
208 | + $path = str_replace('\\', '/', $path); |
|
209 | + $path = str_replace('../', '/', $path); |
|
210 | + // replace // with / except when preceeded by : |
|
211 | + $path = preg_replace("/([^:])\/\//", "$1/", $path); |
|
212 | + |
|
213 | + // Sort trailing slash |
|
214 | + $path = trim($path); |
|
215 | + // rtrim defaults plus / |
|
216 | + $path = rtrim($path, " \n\t\0\x0B/"); |
|
217 | + |
|
218 | + if ($append_slash) { |
|
219 | + $path = $path . '/'; |
|
220 | + } |
|
221 | + |
|
222 | + return $path; |
|
223 | 223 | } |
224 | 224 | \ No newline at end of file |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | |
41 | 41 | foreach ($files as $filename) { |
42 | 42 | $filename = basename($filename); |
43 | - $date = (int)substr($filename, 0, 8); |
|
44 | - $inc = (int)substr($filename, 8, 2); |
|
43 | + $date = (int) substr($filename, 0, 8); |
|
44 | + $inc = (int) substr($filename, 8, 2); |
|
45 | 45 | |
46 | 46 | if ($upgrade_date == $date) { |
47 | 47 | if ($inc >= $upgrade_inc) { |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | $upgrade_inc = "0$upgrade_inc"; |
57 | 57 | } |
58 | 58 | |
59 | -$upgrade_version = $upgrade_date . $upgrade_inc; |
|
59 | +$upgrade_version = $upgrade_date.$upgrade_inc; |
|
60 | 60 | |
61 | 61 | // make filename |
62 | 62 | if (substr($release, 0, 3) == '1.7') { |
63 | 63 | // 1.7 upgrades are YYYYMMDDXX |
64 | - $upgrade_name = $upgrade_version . '.php'; |
|
64 | + $upgrade_name = $upgrade_version.'.php'; |
|
65 | 65 | } else { |
66 | 66 | // 1.8+ upgrades are YYYYMMDDXX-release-friendly_name-rnd |
67 | - $upgrade_name = $upgrade_version . "-$upgrade_release-$name-$upgrade_rnd.php"; |
|
67 | + $upgrade_name = $upgrade_version."-$upgrade_release-$name-$upgrade_rnd.php"; |
|
68 | 68 | } |
69 | 69 | |
70 | -$upgrade_file = $upgrade_path . '/' . $upgrade_name; |
|
70 | +$upgrade_file = $upgrade_path.'/'.$upgrade_name; |
|
71 | 71 | |
72 | 72 | if (is_file($upgrade_file)) { |
73 | 73 | elgg_create_upgrade_show_usage("Upgrade file $upgrade_file already exists. This script has failed you."); |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | $directory = sanitise_filepath($directory); |
178 | 178 | if ($handle = opendir($directory)) { |
179 | 179 | while (($file = readdir($handle)) !== FALSE) { |
180 | - if (!is_file($directory . $file) || in_array($file, $exceptions)) { |
|
180 | + if (!is_file($directory.$file) || in_array($file, $exceptions)) { |
|
181 | 181 | continue; |
182 | 182 | } |
183 | 183 | |
184 | 184 | if (is_array($extensions)) { |
185 | 185 | if (in_array(strrchr($file, '.'), $extensions)) { |
186 | - $list[] = $directory . $file; |
|
186 | + $list[] = $directory.$file; |
|
187 | 187 | } |
188 | 188 | } else { |
189 | - $list[] = $directory . $file; |
|
189 | + $list[] = $directory.$file; |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | closedir($handle); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $path = rtrim($path, " \n\t\0\x0B/"); |
217 | 217 | |
218 | 218 | if ($append_slash) { |
219 | - $path = $path . '/'; |
|
219 | + $path = $path.'/'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | return $path; |
@@ -298,6 +298,9 @@ |
||
298 | 298 | return elgg_view('file/typecloud', $params); |
299 | 299 | } |
300 | 300 | |
301 | +/** |
|
302 | + * @param boolean $friends |
|
303 | + */ |
|
301 | 304 | function file_type_cloud_get_url($type, $friends) { |
302 | 305 | $url = elgg_get_site_url() . 'file/search?subtype=file'; |
303 | 306 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | function file_init() { |
14 | 14 | |
15 | 15 | // register a library of helper functions |
16 | - elgg_register_library('elgg:file', __DIR__ . '/lib/file.php'); |
|
16 | + elgg_register_library('elgg:file', __DIR__.'/lib/file.php'); |
|
17 | 17 | |
18 | 18 | // Site navigation |
19 | 19 | $item = new ElggMenuItem('file', elgg_echo('file'), 'file/all'); |
@@ -286,10 +286,10 @@ discard block |
||
286 | 286 | } |
287 | 287 | |
288 | 288 | function file_type_cloud_get_url($type, $friends) { |
289 | - $url = elgg_get_site_url() . 'file/search?subtype=file'; |
|
289 | + $url = elgg_get_site_url().'file/search?subtype=file'; |
|
290 | 290 | |
291 | 291 | if ($type->tag != "all") { |
292 | - $url .= "&md_type=simpletype&tag=" . urlencode($type->tag); |
|
292 | + $url .= "&md_type=simpletype&tag=".urlencode($type->tag); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | if ($friends) { |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | if (elgg_get_page_owner_guid()) { |
304 | - $url .= "&page_owner=" . elgg_get_page_owner_guid(); |
|
304 | + $url .= "&page_owner=".elgg_get_page_owner_guid(); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | return $url; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $entity = $params['entity']; |
321 | 321 | if (elgg_instanceof($entity, 'object', 'file')) { |
322 | 322 | $title = elgg_get_friendly_title($entity->title); |
323 | - return "file/view/" . $entity->getGUID() . "/" . $title; |
|
323 | + return "file/view/".$entity->getGUID()."/".$title; |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 |
@@ -12,75 +12,75 @@ discard block |
||
12 | 12 | */ |
13 | 13 | function file_init() { |
14 | 14 | |
15 | - // register a library of helper functions |
|
16 | - elgg_register_library('elgg:file', __DIR__ . '/lib/file.php'); |
|
17 | - |
|
18 | - // Site navigation |
|
19 | - $item = new ElggMenuItem('file', elgg_echo('file'), 'file/all'); |
|
20 | - elgg_register_menu_item('site', $item); |
|
21 | - |
|
22 | - // Extend CSS |
|
23 | - elgg_extend_view('elgg.css', 'file/css'); |
|
24 | - |
|
25 | - // add enclosure to rss item |
|
26 | - elgg_extend_view('extensions/item', 'file/enclosure'); |
|
27 | - |
|
28 | - // extend group main page |
|
29 | - elgg_extend_view('groups/tool_latest', 'file/group_module'); |
|
30 | - |
|
31 | - // Register a page handler, so we can have nice URLs |
|
32 | - elgg_register_page_handler('file', 'file_page_handler'); |
|
33 | - |
|
34 | - // Register URL handlers for files |
|
35 | - elgg_register_plugin_hook_handler('entity:url', 'object', 'file_set_url'); |
|
36 | - elgg_register_plugin_hook_handler('entity:icon:url', 'object', 'file_set_icon_url'); |
|
37 | - |
|
38 | - // Register for notifications |
|
39 | - elgg_register_notification_event('object', 'file', ['create']); |
|
40 | - elgg_register_plugin_hook_handler('prepare', 'notification:create:object:file', 'file_prepare_notification'); |
|
41 | - |
|
42 | - // add the group files tool option |
|
43 | - add_group_tool_option('file', elgg_echo('groups:enablefiles'), true); |
|
44 | - |
|
45 | - // add a file link to owner blocks |
|
46 | - elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu'); |
|
47 | - |
|
48 | - // cleanup thumbnails on delete. high priority because we want to try to make sure the |
|
49 | - // deletion will actually occur before we go through with this. |
|
50 | - elgg_register_event_handler('delete', 'object', 'file_handle_object_delete', 999); |
|
51 | - |
|
52 | - // embed support |
|
53 | - $item = ElggMenuItem::factory([ |
|
54 | - 'name' => 'file', |
|
55 | - 'text' => elgg_echo('file'), |
|
56 | - 'priority' => 10, |
|
57 | - 'data' => [ |
|
58 | - 'options' => [ |
|
59 | - 'type' => 'object', |
|
60 | - 'subtype' => 'file', |
|
61 | - ], |
|
62 | - ], |
|
63 | - ]); |
|
64 | - elgg_register_menu_item('embed', $item); |
|
65 | - |
|
66 | - $item = ElggMenuItem::factory([ |
|
67 | - 'name' => 'file_upload', |
|
68 | - 'text' => elgg_echo('file:upload'), |
|
69 | - 'priority' => 100, |
|
70 | - 'data' => [ |
|
71 | - 'view' => 'embed/file_upload/content', |
|
72 | - ], |
|
73 | - ]); |
|
74 | - |
|
75 | - elgg_register_menu_item('embed', $item); |
|
76 | - |
|
77 | - elgg_extend_view('theme_sandbox/icons', 'file/theme_sandbox/icons/files'); |
|
78 | - |
|
79 | - // allow to be liked |
|
80 | - elgg_register_plugin_hook_handler('likes:is_likable', 'object:file', 'Elgg\Values::getTrue'); |
|
81 | - |
|
82 | - elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', 'file_set_custom_icon_sizes'); |
|
83 | - elgg_register_plugin_hook_handler('entity:icon:file', 'object', 'file_set_icon_file'); |
|
15 | + // register a library of helper functions |
|
16 | + elgg_register_library('elgg:file', __DIR__ . '/lib/file.php'); |
|
17 | + |
|
18 | + // Site navigation |
|
19 | + $item = new ElggMenuItem('file', elgg_echo('file'), 'file/all'); |
|
20 | + elgg_register_menu_item('site', $item); |
|
21 | + |
|
22 | + // Extend CSS |
|
23 | + elgg_extend_view('elgg.css', 'file/css'); |
|
24 | + |
|
25 | + // add enclosure to rss item |
|
26 | + elgg_extend_view('extensions/item', 'file/enclosure'); |
|
27 | + |
|
28 | + // extend group main page |
|
29 | + elgg_extend_view('groups/tool_latest', 'file/group_module'); |
|
30 | + |
|
31 | + // Register a page handler, so we can have nice URLs |
|
32 | + elgg_register_page_handler('file', 'file_page_handler'); |
|
33 | + |
|
34 | + // Register URL handlers for files |
|
35 | + elgg_register_plugin_hook_handler('entity:url', 'object', 'file_set_url'); |
|
36 | + elgg_register_plugin_hook_handler('entity:icon:url', 'object', 'file_set_icon_url'); |
|
37 | + |
|
38 | + // Register for notifications |
|
39 | + elgg_register_notification_event('object', 'file', ['create']); |
|
40 | + elgg_register_plugin_hook_handler('prepare', 'notification:create:object:file', 'file_prepare_notification'); |
|
41 | + |
|
42 | + // add the group files tool option |
|
43 | + add_group_tool_option('file', elgg_echo('groups:enablefiles'), true); |
|
44 | + |
|
45 | + // add a file link to owner blocks |
|
46 | + elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu'); |
|
47 | + |
|
48 | + // cleanup thumbnails on delete. high priority because we want to try to make sure the |
|
49 | + // deletion will actually occur before we go through with this. |
|
50 | + elgg_register_event_handler('delete', 'object', 'file_handle_object_delete', 999); |
|
51 | + |
|
52 | + // embed support |
|
53 | + $item = ElggMenuItem::factory([ |
|
54 | + 'name' => 'file', |
|
55 | + 'text' => elgg_echo('file'), |
|
56 | + 'priority' => 10, |
|
57 | + 'data' => [ |
|
58 | + 'options' => [ |
|
59 | + 'type' => 'object', |
|
60 | + 'subtype' => 'file', |
|
61 | + ], |
|
62 | + ], |
|
63 | + ]); |
|
64 | + elgg_register_menu_item('embed', $item); |
|
65 | + |
|
66 | + $item = ElggMenuItem::factory([ |
|
67 | + 'name' => 'file_upload', |
|
68 | + 'text' => elgg_echo('file:upload'), |
|
69 | + 'priority' => 100, |
|
70 | + 'data' => [ |
|
71 | + 'view' => 'embed/file_upload/content', |
|
72 | + ], |
|
73 | + ]); |
|
74 | + |
|
75 | + elgg_register_menu_item('embed', $item); |
|
76 | + |
|
77 | + elgg_extend_view('theme_sandbox/icons', 'file/theme_sandbox/icons/files'); |
|
78 | + |
|
79 | + // allow to be liked |
|
80 | + elgg_register_plugin_hook_handler('likes:is_likable', 'object:file', 'Elgg\Values::getTrue'); |
|
81 | + |
|
82 | + elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', 'file_set_custom_icon_sizes'); |
|
83 | + elgg_register_plugin_hook_handler('entity:icon:file', 'object', 'file_set_icon_file'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -101,49 +101,49 @@ discard block |
||
101 | 101 | */ |
102 | 102 | function file_page_handler($page) { |
103 | 103 | |
104 | - if (!isset($page[0])) { |
|
105 | - $page[0] = 'all'; |
|
106 | - } |
|
107 | - |
|
108 | - $page_type = $page[0]; |
|
109 | - switch ($page_type) { |
|
110 | - case 'owner': |
|
111 | - file_register_toggle(); |
|
112 | - echo elgg_view_resource('file/owner'); |
|
113 | - break; |
|
114 | - case 'friends': |
|
115 | - file_register_toggle(); |
|
116 | - echo elgg_view_resource('file/friends'); |
|
117 | - break; |
|
118 | - case 'view': |
|
119 | - echo elgg_view_resource('file/view', [ |
|
120 | - 'guid' => $page[1], |
|
121 | - ]); |
|
122 | - break; |
|
123 | - case 'add': |
|
124 | - echo elgg_view_resource('file/upload'); |
|
125 | - break; |
|
126 | - case 'edit': |
|
127 | - echo elgg_view_resource('file/edit', [ |
|
128 | - 'guid' => $page[1], |
|
129 | - ]); |
|
130 | - break; |
|
131 | - case 'search': |
|
132 | - file_register_toggle(); |
|
133 | - echo elgg_view_resource('file/search'); |
|
134 | - break; |
|
135 | - case 'group': |
|
136 | - file_register_toggle(); |
|
137 | - echo elgg_view_resource('file/owner'); |
|
138 | - break; |
|
139 | - case 'all': |
|
140 | - file_register_toggle(); |
|
141 | - echo elgg_view_resource('file/all'); |
|
142 | - break; |
|
143 | - default: |
|
144 | - return false; |
|
145 | - } |
|
146 | - return true; |
|
104 | + if (!isset($page[0])) { |
|
105 | + $page[0] = 'all'; |
|
106 | + } |
|
107 | + |
|
108 | + $page_type = $page[0]; |
|
109 | + switch ($page_type) { |
|
110 | + case 'owner': |
|
111 | + file_register_toggle(); |
|
112 | + echo elgg_view_resource('file/owner'); |
|
113 | + break; |
|
114 | + case 'friends': |
|
115 | + file_register_toggle(); |
|
116 | + echo elgg_view_resource('file/friends'); |
|
117 | + break; |
|
118 | + case 'view': |
|
119 | + echo elgg_view_resource('file/view', [ |
|
120 | + 'guid' => $page[1], |
|
121 | + ]); |
|
122 | + break; |
|
123 | + case 'add': |
|
124 | + echo elgg_view_resource('file/upload'); |
|
125 | + break; |
|
126 | + case 'edit': |
|
127 | + echo elgg_view_resource('file/edit', [ |
|
128 | + 'guid' => $page[1], |
|
129 | + ]); |
|
130 | + break; |
|
131 | + case 'search': |
|
132 | + file_register_toggle(); |
|
133 | + echo elgg_view_resource('file/search'); |
|
134 | + break; |
|
135 | + case 'group': |
|
136 | + file_register_toggle(); |
|
137 | + echo elgg_view_resource('file/owner'); |
|
138 | + break; |
|
139 | + case 'all': |
|
140 | + file_register_toggle(); |
|
141 | + echo elgg_view_resource('file/all'); |
|
142 | + break; |
|
143 | + default: |
|
144 | + return false; |
|
145 | + } |
|
146 | + return true; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,23 +151,23 @@ discard block |
||
151 | 151 | */ |
152 | 152 | function file_register_toggle() { |
153 | 153 | |
154 | - if (get_input('list_type', 'list') == 'list') { |
|
155 | - $list_type = 'gallery'; |
|
156 | - $icon = elgg_view_icon('grid'); |
|
157 | - } else { |
|
158 | - $list_type = 'list'; |
|
159 | - $icon = elgg_view_icon('list'); |
|
160 | - } |
|
154 | + if (get_input('list_type', 'list') == 'list') { |
|
155 | + $list_type = 'gallery'; |
|
156 | + $icon = elgg_view_icon('grid'); |
|
157 | + } else { |
|
158 | + $list_type = 'list'; |
|
159 | + $icon = elgg_view_icon('list'); |
|
160 | + } |
|
161 | 161 | |
162 | - $url = elgg_http_add_url_query_elements(current_page_url(), ['list_type' => $list_type]); |
|
162 | + $url = elgg_http_add_url_query_elements(current_page_url(), ['list_type' => $list_type]); |
|
163 | 163 | |
164 | - elgg_register_menu_item('filter:file', [ |
|
165 | - 'name' => 'file_list', |
|
166 | - 'text' => $icon, |
|
167 | - 'href' => $url, |
|
168 | - 'title' => elgg_echo("file:list:$list_type"), |
|
169 | - 'priority' => 1000, |
|
170 | - ]); |
|
164 | + elgg_register_menu_item('filter:file', [ |
|
165 | + 'name' => 'file_list', |
|
166 | + 'text' => $icon, |
|
167 | + 'href' => $url, |
|
168 | + 'title' => elgg_echo("file:list:$list_type"), |
|
169 | + 'priority' => 1000, |
|
170 | + ]); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -180,44 +180,44 @@ discard block |
||
180 | 180 | * @return Elgg\Notifications\Notification |
181 | 181 | */ |
182 | 182 | function file_prepare_notification($hook, $type, $notification, $params) { |
183 | - $entity = $params['event']->getObject(); |
|
184 | - $owner = $params['event']->getActor(); |
|
185 | - $recipient = $params['recipient']; |
|
186 | - $language = $params['language']; |
|
187 | - $method = $params['method']; |
|
188 | - |
|
189 | - $descr = $entity->description; |
|
190 | - $title = $entity->title; |
|
191 | - |
|
192 | - $notification->subject = elgg_echo('file:notify:subject', [$entity->title], $language); |
|
193 | - $notification->body = elgg_echo('file:notify:body', [ |
|
194 | - $owner->name, |
|
195 | - $title, |
|
196 | - $descr, |
|
197 | - $entity->getURL() |
|
198 | - ], $language); |
|
199 | - $notification->summary = elgg_echo('file:notify:summary', [$entity->title], $language); |
|
200 | - $notification->url = $entity->getURL(); |
|
201 | - return $notification; |
|
183 | + $entity = $params['event']->getObject(); |
|
184 | + $owner = $params['event']->getActor(); |
|
185 | + $recipient = $params['recipient']; |
|
186 | + $language = $params['language']; |
|
187 | + $method = $params['method']; |
|
188 | + |
|
189 | + $descr = $entity->description; |
|
190 | + $title = $entity->title; |
|
191 | + |
|
192 | + $notification->subject = elgg_echo('file:notify:subject', [$entity->title], $language); |
|
193 | + $notification->body = elgg_echo('file:notify:body', [ |
|
194 | + $owner->name, |
|
195 | + $title, |
|
196 | + $descr, |
|
197 | + $entity->getURL() |
|
198 | + ], $language); |
|
199 | + $notification->summary = elgg_echo('file:notify:summary', [$entity->title], $language); |
|
200 | + $notification->url = $entity->getURL(); |
|
201 | + return $notification; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | 205 | * Add a menu item to the user ownerblock |
206 | 206 | */ |
207 | 207 | function file_owner_block_menu($hook, $type, $return, $params) { |
208 | - if (elgg_instanceof($params['entity'], 'user')) { |
|
209 | - $url = "file/owner/{$params['entity']->username}"; |
|
210 | - $item = new ElggMenuItem('file', elgg_echo('file'), $url); |
|
211 | - $return[] = $item; |
|
212 | - } else { |
|
213 | - if ($params['entity']->file_enable != "no") { |
|
214 | - $url = "file/group/{$params['entity']->guid}/all"; |
|
215 | - $item = new ElggMenuItem('file', elgg_echo('file:group'), $url); |
|
216 | - $return[] = $item; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - return $return; |
|
208 | + if (elgg_instanceof($params['entity'], 'user')) { |
|
209 | + $url = "file/owner/{$params['entity']->username}"; |
|
210 | + $item = new ElggMenuItem('file', elgg_echo('file'), $url); |
|
211 | + $return[] = $item; |
|
212 | + } else { |
|
213 | + if ($params['entity']->file_enable != "no") { |
|
214 | + $url = "file/group/{$params['entity']->guid}/all"; |
|
215 | + $item = new ElggMenuItem('file', elgg_echo('file:group'), $url); |
|
216 | + $return[] = $item; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + return $return; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,80 +230,80 @@ discard block |
||
230 | 230 | */ |
231 | 231 | function file_get_type_cloud($container_guid = "", $friends = false) { |
232 | 232 | |
233 | - $container_guids = $container_guid; |
|
234 | - $container = get_entity($container_guid); |
|
235 | - |
|
236 | - if ($friends && $container) { |
|
237 | - // tags interface does not support pulling tags on friends' content so |
|
238 | - // we need to grab all friends |
|
239 | - $friend_entities = $container->getFriends(['limit' => 0]); |
|
240 | - if ($friend_entities) { |
|
241 | - $friend_guids = []; |
|
242 | - foreach ($friend_entities as $friend) { |
|
243 | - $friend_guids[] = $friend->getGUID(); |
|
244 | - } |
|
245 | - } |
|
246 | - $container_guids = $friend_guids; |
|
247 | - } |
|
248 | - |
|
249 | - elgg_register_tag_metadata_name('simpletype'); |
|
250 | - $options = [ |
|
251 | - 'type' => 'object', |
|
252 | - 'subtype' => 'file', |
|
253 | - 'container_guids' => $container_guids, |
|
254 | - 'threshold' => 0, |
|
255 | - 'limit' => 10, |
|
256 | - 'tag_names' => ['simpletype'] |
|
257 | - ]; |
|
258 | - $types = elgg_get_tags($options); |
|
259 | - |
|
260 | - if ($types) { |
|
261 | - $all = new stdClass; |
|
262 | - $all->tag = 'all'; |
|
263 | - elgg_register_menu_item('page', [ |
|
264 | - 'name' => 'file:all', |
|
265 | - 'text' => elgg_echo('all'), |
|
266 | - 'href' => file_type_cloud_get_url($all, $friends), |
|
267 | - ]); |
|
233 | + $container_guids = $container_guid; |
|
234 | + $container = get_entity($container_guid); |
|
235 | + |
|
236 | + if ($friends && $container) { |
|
237 | + // tags interface does not support pulling tags on friends' content so |
|
238 | + // we need to grab all friends |
|
239 | + $friend_entities = $container->getFriends(['limit' => 0]); |
|
240 | + if ($friend_entities) { |
|
241 | + $friend_guids = []; |
|
242 | + foreach ($friend_entities as $friend) { |
|
243 | + $friend_guids[] = $friend->getGUID(); |
|
244 | + } |
|
245 | + } |
|
246 | + $container_guids = $friend_guids; |
|
247 | + } |
|
248 | + |
|
249 | + elgg_register_tag_metadata_name('simpletype'); |
|
250 | + $options = [ |
|
251 | + 'type' => 'object', |
|
252 | + 'subtype' => 'file', |
|
253 | + 'container_guids' => $container_guids, |
|
254 | + 'threshold' => 0, |
|
255 | + 'limit' => 10, |
|
256 | + 'tag_names' => ['simpletype'] |
|
257 | + ]; |
|
258 | + $types = elgg_get_tags($options); |
|
259 | + |
|
260 | + if ($types) { |
|
261 | + $all = new stdClass; |
|
262 | + $all->tag = 'all'; |
|
263 | + elgg_register_menu_item('page', [ |
|
264 | + 'name' => 'file:all', |
|
265 | + 'text' => elgg_echo('all'), |
|
266 | + 'href' => file_type_cloud_get_url($all, $friends), |
|
267 | + ]); |
|
268 | 268 | |
269 | - foreach ($types as $type) { |
|
270 | - elgg_register_menu_item('page', [ |
|
271 | - 'name' => "file:$type->tag", |
|
272 | - 'text' => elgg_echo("file:type:$type->tag"), |
|
273 | - 'href' => file_type_cloud_get_url($type, $friends), |
|
274 | - ]); |
|
275 | - } |
|
276 | - } |
|
269 | + foreach ($types as $type) { |
|
270 | + elgg_register_menu_item('page', [ |
|
271 | + 'name' => "file:$type->tag", |
|
272 | + 'text' => elgg_echo("file:type:$type->tag"), |
|
273 | + 'href' => file_type_cloud_get_url($type, $friends), |
|
274 | + ]); |
|
275 | + } |
|
276 | + } |
|
277 | 277 | |
278 | - // returning the view is needed for BC |
|
279 | - $params = [ |
|
280 | - 'friends' => $friends, |
|
281 | - 'types' => $types, |
|
282 | - ]; |
|
278 | + // returning the view is needed for BC |
|
279 | + $params = [ |
|
280 | + 'friends' => $friends, |
|
281 | + 'types' => $types, |
|
282 | + ]; |
|
283 | 283 | |
284 | - return elgg_view('file/typecloud', $params); |
|
284 | + return elgg_view('file/typecloud', $params); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | function file_type_cloud_get_url($type, $friends) { |
288 | - $url = elgg_get_site_url() . 'file/search?subtype=file'; |
|
288 | + $url = elgg_get_site_url() . 'file/search?subtype=file'; |
|
289 | 289 | |
290 | - if ($type->tag != "all") { |
|
291 | - $url .= "&md_type=simpletype&tag=" . urlencode($type->tag); |
|
292 | - } |
|
290 | + if ($type->tag != "all") { |
|
291 | + $url .= "&md_type=simpletype&tag=" . urlencode($type->tag); |
|
292 | + } |
|
293 | 293 | |
294 | - if ($friends) { |
|
295 | - $url .= "&friends=$friends"; |
|
296 | - } |
|
294 | + if ($friends) { |
|
295 | + $url .= "&friends=$friends"; |
|
296 | + } |
|
297 | 297 | |
298 | - if ($type->tag == "image") { |
|
299 | - $url .= "&list_type=gallery"; |
|
300 | - } |
|
298 | + if ($type->tag == "image") { |
|
299 | + $url .= "&list_type=gallery"; |
|
300 | + } |
|
301 | 301 | |
302 | - if (elgg_get_page_owner_guid()) { |
|
303 | - $url .= "&page_owner=" . elgg_get_page_owner_guid(); |
|
304 | - } |
|
302 | + if (elgg_get_page_owner_guid()) { |
|
303 | + $url .= "&page_owner=" . elgg_get_page_owner_guid(); |
|
304 | + } |
|
305 | 305 | |
306 | - return $url; |
|
306 | + return $url; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -316,11 +316,11 @@ discard block |
||
316 | 316 | * @return string File URL |
317 | 317 | */ |
318 | 318 | function file_set_url($hook, $type, $url, $params) { |
319 | - $entity = $params['entity']; |
|
320 | - if (elgg_instanceof($entity, 'object', 'file')) { |
|
321 | - $title = elgg_get_friendly_title($entity->title); |
|
322 | - return "file/view/" . $entity->getGUID() . "/" . $title; |
|
323 | - } |
|
319 | + $entity = $params['entity']; |
|
320 | + if (elgg_instanceof($entity, 'object', 'file')) { |
|
321 | + $title = elgg_get_friendly_title($entity->title); |
|
322 | + return "file/view/" . $entity->getGUID() . "/" . $title; |
|
323 | + } |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -335,66 +335,66 @@ discard block |
||
335 | 335 | * @return string Relative URL |
336 | 336 | */ |
337 | 337 | function file_set_icon_url($hook, $type, $url, $params) { |
338 | - $file = $params['entity']; |
|
339 | - $size = elgg_extract('size', $params, 'large'); |
|
340 | - if (elgg_instanceof($file, 'object', 'file')) { |
|
341 | - // thumbnails get first priority |
|
342 | - $thumbnail = $file->getIcon($size); |
|
343 | - $thumb_url = $thumbnail->getInlineURL(true); |
|
344 | - if ($thumb_url) { |
|
345 | - return $thumb_url; |
|
346 | - } |
|
347 | - |
|
348 | - $mapping = [ |
|
349 | - 'application/excel' => 'excel', |
|
350 | - 'application/msword' => 'word', |
|
351 | - 'application/ogg' => 'music', |
|
352 | - 'application/pdf' => 'pdf', |
|
353 | - 'application/powerpoint' => 'ppt', |
|
354 | - 'application/vnd.ms-excel' => 'excel', |
|
355 | - 'application/vnd.ms-powerpoint' => 'ppt', |
|
356 | - 'application/vnd.oasis.opendocument.text' => 'openoffice', |
|
357 | - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word', |
|
358 | - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel', |
|
359 | - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ppt', |
|
360 | - 'application/x-gzip' => 'archive', |
|
361 | - 'application/x-rar-compressed' => 'archive', |
|
362 | - 'application/x-stuffit' => 'archive', |
|
363 | - 'application/zip' => 'archive', |
|
364 | - 'text/directory' => 'vcard', |
|
365 | - 'text/v-card' => 'vcard', |
|
366 | - 'application' => 'application', |
|
367 | - 'audio' => 'music', |
|
368 | - 'text' => 'text', |
|
369 | - 'video' => 'video', |
|
370 | - ]; |
|
371 | - |
|
372 | - $mime = $file->getMimeType(); |
|
373 | - if ($mime) { |
|
374 | - $base_type = substr($mime, 0, strpos($mime, '/')); |
|
375 | - } else { |
|
376 | - $mime = 'none'; |
|
377 | - $base_type = 'none'; |
|
378 | - } |
|
379 | - |
|
380 | - if (isset($mapping[$mime])) { |
|
381 | - $type = $mapping[$mime]; |
|
382 | - } elseif (isset($mapping[$base_type])) { |
|
383 | - $type = $mapping[$base_type]; |
|
384 | - } else { |
|
385 | - $type = 'general'; |
|
386 | - } |
|
387 | - |
|
388 | - if ($size == 'large') { |
|
389 | - $ext = '_lrg'; |
|
390 | - } else { |
|
391 | - $ext = ''; |
|
392 | - } |
|
393 | - |
|
394 | - $url = elgg_get_simplecache_url("file/icons/{$type}{$ext}.gif"); |
|
395 | - $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url); |
|
396 | - return $url; |
|
397 | - } |
|
338 | + $file = $params['entity']; |
|
339 | + $size = elgg_extract('size', $params, 'large'); |
|
340 | + if (elgg_instanceof($file, 'object', 'file')) { |
|
341 | + // thumbnails get first priority |
|
342 | + $thumbnail = $file->getIcon($size); |
|
343 | + $thumb_url = $thumbnail->getInlineURL(true); |
|
344 | + if ($thumb_url) { |
|
345 | + return $thumb_url; |
|
346 | + } |
|
347 | + |
|
348 | + $mapping = [ |
|
349 | + 'application/excel' => 'excel', |
|
350 | + 'application/msword' => 'word', |
|
351 | + 'application/ogg' => 'music', |
|
352 | + 'application/pdf' => 'pdf', |
|
353 | + 'application/powerpoint' => 'ppt', |
|
354 | + 'application/vnd.ms-excel' => 'excel', |
|
355 | + 'application/vnd.ms-powerpoint' => 'ppt', |
|
356 | + 'application/vnd.oasis.opendocument.text' => 'openoffice', |
|
357 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word', |
|
358 | + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel', |
|
359 | + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ppt', |
|
360 | + 'application/x-gzip' => 'archive', |
|
361 | + 'application/x-rar-compressed' => 'archive', |
|
362 | + 'application/x-stuffit' => 'archive', |
|
363 | + 'application/zip' => 'archive', |
|
364 | + 'text/directory' => 'vcard', |
|
365 | + 'text/v-card' => 'vcard', |
|
366 | + 'application' => 'application', |
|
367 | + 'audio' => 'music', |
|
368 | + 'text' => 'text', |
|
369 | + 'video' => 'video', |
|
370 | + ]; |
|
371 | + |
|
372 | + $mime = $file->getMimeType(); |
|
373 | + if ($mime) { |
|
374 | + $base_type = substr($mime, 0, strpos($mime, '/')); |
|
375 | + } else { |
|
376 | + $mime = 'none'; |
|
377 | + $base_type = 'none'; |
|
378 | + } |
|
379 | + |
|
380 | + if (isset($mapping[$mime])) { |
|
381 | + $type = $mapping[$mime]; |
|
382 | + } elseif (isset($mapping[$base_type])) { |
|
383 | + $type = $mapping[$base_type]; |
|
384 | + } else { |
|
385 | + $type = 'general'; |
|
386 | + } |
|
387 | + |
|
388 | + if ($size == 'large') { |
|
389 | + $ext = '_lrg'; |
|
390 | + } else { |
|
391 | + $ext = ''; |
|
392 | + } |
|
393 | + |
|
394 | + $url = elgg_get_simplecache_url("file/icons/{$type}{$ext}.gif"); |
|
395 | + $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url); |
|
396 | + return $url; |
|
397 | + } |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | * @return void |
407 | 407 | */ |
408 | 408 | function file_handle_object_delete($event, $type, ElggObject $file) { |
409 | - if (!$file instanceof ElggFile) { |
|
410 | - return; |
|
411 | - } |
|
412 | - if (!$file->guid) { |
|
413 | - // this is an ElggFile used as temporary API |
|
414 | - return; |
|
415 | - } |
|
416 | - |
|
417 | - $file->deleteIcon(); |
|
409 | + if (!$file instanceof ElggFile) { |
|
410 | + return; |
|
411 | + } |
|
412 | + if (!$file->guid) { |
|
413 | + // this is an ElggFile used as temporary API |
|
414 | + return; |
|
415 | + } |
|
416 | + |
|
417 | + $file->deleteIcon(); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -428,30 +428,30 @@ discard block |
||
428 | 428 | */ |
429 | 429 | function file_set_custom_icon_sizes($hook, $type, $return, $params) { |
430 | 430 | |
431 | - $entity_subtype = elgg_extract('entity_subtype', $params); |
|
432 | - if ($entity_subtype !== 'file') { |
|
433 | - return; |
|
434 | - } |
|
435 | - |
|
436 | - return [ |
|
437 | - 'small' => [ |
|
438 | - 'w' => 60, |
|
439 | - 'h' => 60, |
|
440 | - 'square' => true, |
|
441 | - 'upscale' => true, |
|
442 | - ], |
|
443 | - 'medium' => [ |
|
444 | - 'w' => 153, |
|
445 | - 'h' => 153, |
|
446 | - 'square' => true, |
|
447 | - 'upscale' => true, |
|
448 | - ], |
|
449 | - 'large' => [ |
|
450 | - 'w' => 600, |
|
451 | - 'h' => 600, |
|
452 | - 'upscale' => false, |
|
453 | - ], |
|
454 | - ]; |
|
431 | + $entity_subtype = elgg_extract('entity_subtype', $params); |
|
432 | + if ($entity_subtype !== 'file') { |
|
433 | + return; |
|
434 | + } |
|
435 | + |
|
436 | + return [ |
|
437 | + 'small' => [ |
|
438 | + 'w' => 60, |
|
439 | + 'h' => 60, |
|
440 | + 'square' => true, |
|
441 | + 'upscale' => true, |
|
442 | + ], |
|
443 | + 'medium' => [ |
|
444 | + 'w' => 153, |
|
445 | + 'h' => 153, |
|
446 | + 'square' => true, |
|
447 | + 'upscale' => true, |
|
448 | + ], |
|
449 | + 'large' => [ |
|
450 | + 'w' => 600, |
|
451 | + 'h' => 600, |
|
452 | + 'upscale' => false, |
|
453 | + ], |
|
454 | + ]; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -465,42 +465,42 @@ discard block |
||
465 | 465 | */ |
466 | 466 | function file_set_icon_file($hook, $type, $icon, $params) { |
467 | 467 | |
468 | - $entity = elgg_extract('entity', $params); |
|
469 | - $size = elgg_extract('size', $params, 'large'); |
|
468 | + $entity = elgg_extract('entity', $params); |
|
469 | + $size = elgg_extract('size', $params, 'large'); |
|
470 | 470 | |
471 | - if (!elgg_instanceof($entity, 'object', 'file')) { |
|
472 | - return; |
|
473 | - } |
|
471 | + if (!elgg_instanceof($entity, 'object', 'file')) { |
|
472 | + return; |
|
473 | + } |
|
474 | 474 | |
475 | - switch ($size) { |
|
476 | - case 'small' : |
|
477 | - $filename_prefix = 'thumb'; |
|
478 | - $metadata_name = 'thumbnail'; |
|
479 | - break; |
|
480 | - |
|
481 | - case 'medium' : |
|
482 | - $filename_prefix = 'smallthumb'; |
|
483 | - $metadata_name = 'smallthumb'; |
|
484 | - break; |
|
485 | - |
|
486 | - case 'large' : |
|
487 | - $filename_prefix = 'largethumb'; |
|
488 | - $metadata_name = 'largethumb'; |
|
489 | - break; |
|
490 | - |
|
491 | - default : |
|
492 | - $filename_prefix = "{$size}thumb"; |
|
493 | - $metadata_name = $filename_prefix; |
|
494 | - break; |
|
495 | - } |
|
496 | - |
|
497 | - $icon->owner_guid = $entity->owner_guid; |
|
498 | - if (isset($entity->$metadata_name)) { |
|
499 | - $icon->setFilename($entity->$metadata_name); |
|
500 | - } else { |
|
501 | - $filename = pathinfo($entity->getFilenameOnFilestore(), PATHINFO_FILENAME); |
|
502 | - $filename = "file/{$filename_prefix}{$filename}.jpg"; |
|
503 | - $icon->setFilename($filename); |
|
504 | - } |
|
505 | - return $icon; |
|
475 | + switch ($size) { |
|
476 | + case 'small' : |
|
477 | + $filename_prefix = 'thumb'; |
|
478 | + $metadata_name = 'thumbnail'; |
|
479 | + break; |
|
480 | + |
|
481 | + case 'medium' : |
|
482 | + $filename_prefix = 'smallthumb'; |
|
483 | + $metadata_name = 'smallthumb'; |
|
484 | + break; |
|
485 | + |
|
486 | + case 'large' : |
|
487 | + $filename_prefix = 'largethumb'; |
|
488 | + $metadata_name = 'largethumb'; |
|
489 | + break; |
|
490 | + |
|
491 | + default : |
|
492 | + $filename_prefix = "{$size}thumb"; |
|
493 | + $metadata_name = $filename_prefix; |
|
494 | + break; |
|
495 | + } |
|
496 | + |
|
497 | + $icon->owner_guid = $entity->owner_guid; |
|
498 | + if (isset($entity->$metadata_name)) { |
|
499 | + $icon->setFilename($entity->$metadata_name); |
|
500 | + } else { |
|
501 | + $filename = pathinfo($entity->getFilenameOnFilestore(), PATHINFO_FILENAME); |
|
502 | + $filename = "file/{$filename_prefix}{$filename}.jpg"; |
|
503 | + $icon->setFilename($filename); |
|
504 | + } |
|
505 | + return $icon; |
|
506 | 506 | } |
@@ -470,7 +470,7 @@ |
||
470 | 470 | * @param string $return_value |
471 | 471 | * @param array $params |
472 | 472 | * |
473 | - * @return array |
|
473 | + * @return string |
|
474 | 474 | */ |
475 | 475 | function messages_ecml_views_hook($hook, $entity_type, $return_value, $params) { |
476 | 476 | $return_value['messages/messages'] = elgg_echo('messages'); |
@@ -8,50 +8,50 @@ discard block |
||
8 | 8 | |
9 | 9 | function messages_init() { |
10 | 10 | |
11 | - // add page menu items |
|
12 | - if (elgg_is_logged_in()) { |
|
13 | - elgg_register_menu_item('page', [ |
|
14 | - 'name' => 'messages:inbox', |
|
15 | - 'text' => elgg_echo('messages:inbox'), |
|
16 | - 'href' => "messages/inbox/" . elgg_get_logged_in_user_entity()->username, |
|
17 | - 'context' => 'messages', |
|
18 | - ]); |
|
11 | + // add page menu items |
|
12 | + if (elgg_is_logged_in()) { |
|
13 | + elgg_register_menu_item('page', [ |
|
14 | + 'name' => 'messages:inbox', |
|
15 | + 'text' => elgg_echo('messages:inbox'), |
|
16 | + 'href' => "messages/inbox/" . elgg_get_logged_in_user_entity()->username, |
|
17 | + 'context' => 'messages', |
|
18 | + ]); |
|
19 | 19 | |
20 | - elgg_register_menu_item('page', [ |
|
21 | - 'name' => 'messages:sentmessages', |
|
22 | - 'text' => elgg_echo('messages:sentmessages'), |
|
23 | - 'href' => "messages/sent/" . elgg_get_logged_in_user_entity()->username, |
|
24 | - 'context' => 'messages', |
|
25 | - ]); |
|
26 | - } |
|
27 | - |
|
28 | - // Extend system CSS with our own styles, which are defined in the messages/css view |
|
29 | - elgg_extend_view('elgg.css', 'messages/css'); |
|
30 | - elgg_extend_view('elgg.js', 'messages/js'); |
|
20 | + elgg_register_menu_item('page', [ |
|
21 | + 'name' => 'messages:sentmessages', |
|
22 | + 'text' => elgg_echo('messages:sentmessages'), |
|
23 | + 'href' => "messages/sent/" . elgg_get_logged_in_user_entity()->username, |
|
24 | + 'context' => 'messages', |
|
25 | + ]); |
|
26 | + } |
|
27 | + |
|
28 | + // Extend system CSS with our own styles, which are defined in the messages/css view |
|
29 | + elgg_extend_view('elgg.css', 'messages/css'); |
|
30 | + elgg_extend_view('elgg.js', 'messages/js'); |
|
31 | 31 | |
32 | - // Register a page handler, so we can have nice URLs |
|
33 | - elgg_register_page_handler('messages', 'messages_page_handler'); |
|
32 | + // Register a page handler, so we can have nice URLs |
|
33 | + elgg_register_page_handler('messages', 'messages_page_handler'); |
|
34 | 34 | |
35 | - // Register a URL handler |
|
36 | - elgg_register_plugin_hook_handler('entity:url', 'object', 'messages_set_url'); |
|
35 | + // Register a URL handler |
|
36 | + elgg_register_plugin_hook_handler('entity:url', 'object', 'messages_set_url'); |
|
37 | 37 | |
38 | - // Extend avatar hover menu |
|
39 | - elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'messages_user_hover_menu'); |
|
38 | + // Extend avatar hover menu |
|
39 | + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'messages_user_hover_menu'); |
|
40 | 40 | |
41 | - // delete messages sent by a user when user is deleted |
|
42 | - elgg_register_event_handler('delete', 'user', 'messages_purge'); |
|
41 | + // delete messages sent by a user when user is deleted |
|
42 | + elgg_register_event_handler('delete', 'user', 'messages_purge'); |
|
43 | 43 | |
44 | - // ecml |
|
45 | - elgg_register_plugin_hook_handler('get_views', 'ecml', 'messages_ecml_views_hook'); |
|
44 | + // ecml |
|
45 | + elgg_register_plugin_hook_handler('get_views', 'ecml', 'messages_ecml_views_hook'); |
|
46 | 46 | |
47 | - // permission overrides |
|
48 | - elgg_register_plugin_hook_handler('permissions_check:metadata', 'object', 'messages_can_edit_metadata'); |
|
49 | - elgg_register_plugin_hook_handler('permissions_check', 'object', 'messages_can_edit'); |
|
50 | - elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'messages_can_edit_container'); |
|
47 | + // permission overrides |
|
48 | + elgg_register_plugin_hook_handler('permissions_check:metadata', 'object', 'messages_can_edit_metadata'); |
|
49 | + elgg_register_plugin_hook_handler('permissions_check', 'object', 'messages_can_edit'); |
|
50 | + elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'messages_can_edit_container'); |
|
51 | 51 | |
52 | - // Topbar menu. We assume this menu will render *after* a message is rendered. If a refactor/plugin |
|
53 | - // causes it to render first, the unread count notification will not update until the next page. |
|
54 | - elgg_register_plugin_hook_handler('register', 'menu:topbar', 'messages_register_topbar'); |
|
52 | + // Topbar menu. We assume this menu will render *after* a message is rendered. If a refactor/plugin |
|
53 | + // causes it to render first, the unread count notification will not update until the next page. |
|
54 | + elgg_register_plugin_hook_handler('register', 'menu:topbar', 'messages_register_topbar'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -62,49 +62,49 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function messages_page_handler($page) { |
64 | 64 | |
65 | - elgg_gatekeeper(); |
|
66 | - |
|
67 | - elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username); |
|
68 | - |
|
69 | - if (!isset($page[0])) { |
|
70 | - $page[0] = 'inbox'; |
|
71 | - } |
|
72 | - |
|
73 | - // Support the old inbox url /messages/<username>, but only if it matches the logged in user. |
|
74 | - // Otherwise having a username like "read" on the system could confuse this function. |
|
75 | - if ($current_user->username === $page[0]) { |
|
76 | - $page[1] = $page[0]; |
|
77 | - $page[0] = 'inbox'; |
|
78 | - } |
|
79 | - |
|
80 | - if (!isset($page[1])) { |
|
81 | - $page[1] = $current_user->username; |
|
82 | - } |
|
83 | - |
|
84 | - switch ($page[0]) { |
|
85 | - case 'inbox': |
|
86 | - echo elgg_view_resource('messages/inbox', [ |
|
87 | - 'username' => $page[1], |
|
88 | - ]); |
|
89 | - break; |
|
90 | - case 'sent': |
|
91 | - echo elgg_view_resource('messages/sent', [ |
|
92 | - 'username' => $page[1], |
|
93 | - ]); |
|
94 | - break; |
|
95 | - case 'read': |
|
96 | - echo elgg_view_resource('messages/read', [ |
|
97 | - 'guid' => $page[1], |
|
98 | - ]); |
|
99 | - break; |
|
100 | - case 'compose': |
|
101 | - case 'add': |
|
102 | - echo elgg_view_resource('messages/send'); |
|
103 | - break; |
|
104 | - default: |
|
105 | - return false; |
|
106 | - } |
|
107 | - return true; |
|
65 | + elgg_gatekeeper(); |
|
66 | + |
|
67 | + elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username); |
|
68 | + |
|
69 | + if (!isset($page[0])) { |
|
70 | + $page[0] = 'inbox'; |
|
71 | + } |
|
72 | + |
|
73 | + // Support the old inbox url /messages/<username>, but only if it matches the logged in user. |
|
74 | + // Otherwise having a username like "read" on the system could confuse this function. |
|
75 | + if ($current_user->username === $page[0]) { |
|
76 | + $page[1] = $page[0]; |
|
77 | + $page[0] = 'inbox'; |
|
78 | + } |
|
79 | + |
|
80 | + if (!isset($page[1])) { |
|
81 | + $page[1] = $current_user->username; |
|
82 | + } |
|
83 | + |
|
84 | + switch ($page[0]) { |
|
85 | + case 'inbox': |
|
86 | + echo elgg_view_resource('messages/inbox', [ |
|
87 | + 'username' => $page[1], |
|
88 | + ]); |
|
89 | + break; |
|
90 | + case 'sent': |
|
91 | + echo elgg_view_resource('messages/sent', [ |
|
92 | + 'username' => $page[1], |
|
93 | + ]); |
|
94 | + break; |
|
95 | + case 'read': |
|
96 | + echo elgg_view_resource('messages/read', [ |
|
97 | + 'guid' => $page[1], |
|
98 | + ]); |
|
99 | + break; |
|
100 | + case 'compose': |
|
101 | + case 'add': |
|
102 | + echo elgg_view_resource('messages/send'); |
|
103 | + break; |
|
104 | + default: |
|
105 | + return false; |
|
106 | + } |
|
107 | + return true; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -117,31 +117,31 @@ discard block |
||
117 | 117 | * @return array |
118 | 118 | */ |
119 | 119 | function messages_register_topbar($hook, $type, $items, $params) { |
120 | - if (!elgg_is_logged_in()) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - $user = elgg_get_logged_in_user_entity(); |
|
125 | - |
|
126 | - $text = elgg_echo('messages'); |
|
127 | - $title = $text; |
|
128 | - |
|
129 | - $num_messages = (int) messages_count_unread(); |
|
130 | - if ($num_messages) { |
|
131 | - $title .= " (" . elgg_echo("messages:unreadcount", [$num_messages]) . ")"; |
|
132 | - } |
|
133 | - |
|
134 | - $items[] = ElggMenuItem::factory([ |
|
135 | - 'name' => 'messages', |
|
136 | - 'href' => "messages/inbox/$user->username", |
|
137 | - 'text' => $text, |
|
138 | - 'priority' => 600, |
|
139 | - 'title' => $title, |
|
140 | - 'icon' => 'mail', |
|
141 | - 'badge' => $num_messages ? $num_messages : null, |
|
142 | - ]); |
|
143 | - |
|
144 | - return $items; |
|
120 | + if (!elgg_is_logged_in()) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + $user = elgg_get_logged_in_user_entity(); |
|
125 | + |
|
126 | + $text = elgg_echo('messages'); |
|
127 | + $title = $text; |
|
128 | + |
|
129 | + $num_messages = (int) messages_count_unread(); |
|
130 | + if ($num_messages) { |
|
131 | + $title .= " (" . elgg_echo("messages:unreadcount", [$num_messages]) . ")"; |
|
132 | + } |
|
133 | + |
|
134 | + $items[] = ElggMenuItem::factory([ |
|
135 | + 'name' => 'messages', |
|
136 | + 'href' => "messages/inbox/$user->username", |
|
137 | + 'text' => $text, |
|
138 | + 'priority' => 600, |
|
139 | + 'title' => $title, |
|
140 | + 'icon' => 'mail', |
|
141 | + 'badge' => $num_messages ? $num_messages : null, |
|
142 | + ]); |
|
143 | + |
|
144 | + return $items; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | */ |
151 | 151 | function messages_can_edit_metadata($hook_name, $entity_type, $return_value, $parameters) { |
152 | 152 | |
153 | - global $messagesendflag; |
|
153 | + global $messagesendflag; |
|
154 | 154 | |
155 | - if ($messagesendflag !== 1) { |
|
156 | - return; |
|
157 | - } |
|
155 | + if ($messagesendflag !== 1) { |
|
156 | + return; |
|
157 | + } |
|
158 | 158 | |
159 | - $entity = elgg_extract('entity', $parameters); |
|
160 | - if ($entity->getSubtype() == 'messages') { |
|
161 | - return true; |
|
162 | - } |
|
159 | + $entity = elgg_extract('entity', $parameters); |
|
160 | + if ($entity->getSubtype() == 'messages') { |
|
161 | + return true; |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,30 +168,30 @@ discard block |
||
168 | 168 | */ |
169 | 169 | function messages_can_edit($hook_name, $entity_type, $return_value, $parameters) { |
170 | 170 | |
171 | - global $messagesendflag; |
|
171 | + global $messagesendflag; |
|
172 | 172 | |
173 | - if ($messagesendflag !== 1) { |
|
174 | - return; |
|
175 | - } |
|
173 | + if ($messagesendflag !== 1) { |
|
174 | + return; |
|
175 | + } |
|
176 | 176 | |
177 | - $entity = elgg_extract('entity', $parameters); |
|
178 | - if ($entity->getSubtype() == 'messages') { |
|
179 | - return true; |
|
180 | - } |
|
177 | + $entity = elgg_extract('entity', $parameters); |
|
178 | + if ($entity->getSubtype() == 'messages') { |
|
179 | + return true; |
|
180 | + } |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Prevent messages from generating a notification |
185 | 185 | */ |
186 | 186 | function messages_notification_msg($hook_name, $entity_type, $return_value, $params) { |
187 | - $entity = elgg_extract('entity', $params); |
|
188 | - if (!$entity instanceof ElggEntity) { |
|
189 | - return; |
|
190 | - } |
|
187 | + $entity = elgg_extract('entity', $params); |
|
188 | + if (!$entity instanceof ElggEntity) { |
|
189 | + return; |
|
190 | + } |
|
191 | 191 | |
192 | - if ($entity->getSubtype() == 'messages') { |
|
193 | - return false; |
|
194 | - } |
|
192 | + if ($entity->getSubtype() == 'messages') { |
|
193 | + return false; |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | */ |
201 | 201 | function messages_can_edit_container($hook_name, $entity_type, $return_value, $parameters) { |
202 | 202 | |
203 | - global $messagesendflag; |
|
203 | + global $messagesendflag; |
|
204 | 204 | |
205 | - if ($messagesendflag == 1) { |
|
206 | - return true; |
|
207 | - } |
|
205 | + if ($messagesendflag == 1) { |
|
206 | + return true; |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -221,104 +221,104 @@ discard block |
||
221 | 221 | */ |
222 | 222 | function messages_send($subject, $body, $recipient_guid, $sender_guid = 0, $original_msg_guid = 0, $notify = true, $add_to_sent = true) { |
223 | 223 | |
224 | - // @todo remove globals |
|
225 | - global $messagesendflag; |
|
226 | - $messagesendflag = 1; |
|
227 | - |
|
228 | - // @todo remove globals |
|
229 | - global $messages_pm; |
|
230 | - if ($notify) { |
|
231 | - $messages_pm = 1; |
|
232 | - } else { |
|
233 | - $messages_pm = 0; |
|
234 | - } |
|
235 | - |
|
236 | - // If $sender_guid == 0, set to current user |
|
237 | - if ($sender_guid == 0) { |
|
238 | - $sender_guid = (int) elgg_get_logged_in_user_guid(); |
|
239 | - } |
|
240 | - |
|
241 | - // Initialise 2 new ElggObject |
|
242 | - $message_to = new ElggObject(); |
|
243 | - $message_sent = new ElggObject(); |
|
244 | - |
|
245 | - $message_to->subtype = "messages"; |
|
246 | - $message_sent->subtype = "messages"; |
|
247 | - |
|
248 | - $message_to->owner_guid = $recipient_guid; |
|
249 | - $message_to->container_guid = $recipient_guid; |
|
250 | - $message_sent->owner_guid = $sender_guid; |
|
251 | - $message_sent->container_guid = $sender_guid; |
|
252 | - |
|
253 | - $message_to->access_id = ACCESS_PUBLIC; |
|
254 | - $message_sent->access_id = ACCESS_PUBLIC; |
|
255 | - |
|
256 | - $message_to->title = $subject; |
|
257 | - $message_to->description = $body; |
|
258 | - |
|
259 | - $message_sent->title = $subject; |
|
260 | - $message_sent->description = $body; |
|
261 | - |
|
262 | - $message_to->toId = $recipient_guid; // the user receiving the message |
|
263 | - $message_to->fromId = $sender_guid; // the user receiving the message |
|
264 | - $message_to->readYet = 0; // this is a toggle between 0 / 1 (1 = read) |
|
265 | - $message_to->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag |
|
266 | - $message_to->hiddenTo = 0; // this is used when a user deletes a message in their inbox |
|
267 | - |
|
268 | - $message_sent->toId = $recipient_guid; // the user receiving the message |
|
269 | - $message_sent->fromId = $sender_guid; // the user receiving the message |
|
270 | - $message_sent->readYet = 0; // this is a toggle between 0 / 1 (1 = read) |
|
271 | - $message_sent->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag |
|
272 | - $message_sent->hiddenTo = 0; // this is used when a user deletes a message in their inbox |
|
273 | - |
|
274 | - // Save the copy of the message that goes to the recipient |
|
275 | - $success = $message_to->save(); |
|
276 | - |
|
277 | - // Save the copy of the message that goes to the sender |
|
278 | - if ($add_to_sent) { |
|
279 | - $message_sent->save(); |
|
280 | - } |
|
281 | - |
|
282 | - $message_to->access_id = ACCESS_PRIVATE; |
|
283 | - $message_to->save(); |
|
284 | - |
|
285 | - if ($add_to_sent) { |
|
286 | - $message_sent->access_id = ACCESS_PRIVATE; |
|
287 | - $message_sent->save(); |
|
288 | - } |
|
289 | - |
|
290 | - // if the new message is a reply then create a relationship link between the new message |
|
291 | - // and the message it is in reply to |
|
292 | - if ($original_msg_guid && $success) { |
|
293 | - add_entity_relationship($message_sent->guid, "reply", $original_msg_guid); |
|
294 | - } |
|
295 | - |
|
296 | - $message_contents = strip_tags($body); |
|
297 | - if (($recipient_guid != elgg_get_logged_in_user_guid()) && $notify) { |
|
298 | - $recipient = get_user($recipient_guid); |
|
299 | - $sender = get_user($sender_guid); |
|
224 | + // @todo remove globals |
|
225 | + global $messagesendflag; |
|
226 | + $messagesendflag = 1; |
|
227 | + |
|
228 | + // @todo remove globals |
|
229 | + global $messages_pm; |
|
230 | + if ($notify) { |
|
231 | + $messages_pm = 1; |
|
232 | + } else { |
|
233 | + $messages_pm = 0; |
|
234 | + } |
|
235 | + |
|
236 | + // If $sender_guid == 0, set to current user |
|
237 | + if ($sender_guid == 0) { |
|
238 | + $sender_guid = (int) elgg_get_logged_in_user_guid(); |
|
239 | + } |
|
240 | + |
|
241 | + // Initialise 2 new ElggObject |
|
242 | + $message_to = new ElggObject(); |
|
243 | + $message_sent = new ElggObject(); |
|
244 | + |
|
245 | + $message_to->subtype = "messages"; |
|
246 | + $message_sent->subtype = "messages"; |
|
247 | + |
|
248 | + $message_to->owner_guid = $recipient_guid; |
|
249 | + $message_to->container_guid = $recipient_guid; |
|
250 | + $message_sent->owner_guid = $sender_guid; |
|
251 | + $message_sent->container_guid = $sender_guid; |
|
252 | + |
|
253 | + $message_to->access_id = ACCESS_PUBLIC; |
|
254 | + $message_sent->access_id = ACCESS_PUBLIC; |
|
255 | + |
|
256 | + $message_to->title = $subject; |
|
257 | + $message_to->description = $body; |
|
258 | + |
|
259 | + $message_sent->title = $subject; |
|
260 | + $message_sent->description = $body; |
|
261 | + |
|
262 | + $message_to->toId = $recipient_guid; // the user receiving the message |
|
263 | + $message_to->fromId = $sender_guid; // the user receiving the message |
|
264 | + $message_to->readYet = 0; // this is a toggle between 0 / 1 (1 = read) |
|
265 | + $message_to->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag |
|
266 | + $message_to->hiddenTo = 0; // this is used when a user deletes a message in their inbox |
|
267 | + |
|
268 | + $message_sent->toId = $recipient_guid; // the user receiving the message |
|
269 | + $message_sent->fromId = $sender_guid; // the user receiving the message |
|
270 | + $message_sent->readYet = 0; // this is a toggle between 0 / 1 (1 = read) |
|
271 | + $message_sent->hiddenFrom = 0; // this is used when a user deletes a message in their sentbox, it is a flag |
|
272 | + $message_sent->hiddenTo = 0; // this is used when a user deletes a message in their inbox |
|
273 | + |
|
274 | + // Save the copy of the message that goes to the recipient |
|
275 | + $success = $message_to->save(); |
|
276 | + |
|
277 | + // Save the copy of the message that goes to the sender |
|
278 | + if ($add_to_sent) { |
|
279 | + $message_sent->save(); |
|
280 | + } |
|
281 | + |
|
282 | + $message_to->access_id = ACCESS_PRIVATE; |
|
283 | + $message_to->save(); |
|
284 | + |
|
285 | + if ($add_to_sent) { |
|
286 | + $message_sent->access_id = ACCESS_PRIVATE; |
|
287 | + $message_sent->save(); |
|
288 | + } |
|
289 | + |
|
290 | + // if the new message is a reply then create a relationship link between the new message |
|
291 | + // and the message it is in reply to |
|
292 | + if ($original_msg_guid && $success) { |
|
293 | + add_entity_relationship($message_sent->guid, "reply", $original_msg_guid); |
|
294 | + } |
|
295 | + |
|
296 | + $message_contents = strip_tags($body); |
|
297 | + if (($recipient_guid != elgg_get_logged_in_user_guid()) && $notify) { |
|
298 | + $recipient = get_user($recipient_guid); |
|
299 | + $sender = get_user($sender_guid); |
|
300 | 300 | |
301 | - $subject = elgg_echo('messages:email:subject', [], $recipient->language); |
|
302 | - $body = elgg_echo('messages:email:body', [ |
|
303 | - $sender->name, |
|
304 | - $message_contents, |
|
305 | - elgg_get_site_url() . "messages/inbox/" . $recipient->username, |
|
306 | - $sender->name, |
|
307 | - elgg_get_site_url() . "messages/compose?send_to=" . $sender_guid |
|
308 | - ], |
|
309 | - $recipient->language |
|
310 | - ); |
|
311 | - |
|
312 | - $params = [ |
|
313 | - 'object' => $message_to, |
|
314 | - 'action' => 'send', |
|
315 | - 'url' => $message_to->getURL(), |
|
316 | - ]; |
|
317 | - notify_user($recipient_guid, $sender_guid, $subject, $body, $params); |
|
318 | - } |
|
319 | - |
|
320 | - $messagesendflag = 0; |
|
321 | - return $success; |
|
301 | + $subject = elgg_echo('messages:email:subject', [], $recipient->language); |
|
302 | + $body = elgg_echo('messages:email:body', [ |
|
303 | + $sender->name, |
|
304 | + $message_contents, |
|
305 | + elgg_get_site_url() . "messages/inbox/" . $recipient->username, |
|
306 | + $sender->name, |
|
307 | + elgg_get_site_url() . "messages/compose?send_to=" . $sender_guid |
|
308 | + ], |
|
309 | + $recipient->language |
|
310 | + ); |
|
311 | + |
|
312 | + $params = [ |
|
313 | + 'object' => $message_to, |
|
314 | + 'action' => 'send', |
|
315 | + 'url' => $message_to->getURL(), |
|
316 | + ]; |
|
317 | + notify_user($recipient_guid, $sender_guid, $subject, $body, $params); |
|
318 | + } |
|
319 | + |
|
320 | + $messagesendflag = 0; |
|
321 | + return $success; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -331,10 +331,10 @@ discard block |
||
331 | 331 | * @return string |
332 | 332 | */ |
333 | 333 | function messages_set_url($hook, $type, $url, $params) { |
334 | - $entity = $params['entity']; |
|
335 | - if (elgg_instanceof($entity, 'object', 'messages')) { |
|
336 | - return 'messages/read/' . $entity->getGUID(); |
|
337 | - } |
|
334 | + $entity = $params['entity']; |
|
335 | + if (elgg_instanceof($entity, 'object', 'messages')) { |
|
336 | + return 'messages/read/' . $entity->getGUID(); |
|
337 | + } |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -349,18 +349,18 @@ discard block |
||
349 | 349 | * @since 1.9 |
350 | 350 | */ |
351 | 351 | function messages_get_unread($user_guid = 0, $limit = null, $offset = 0, $count = false) { |
352 | - return elgg_get_entities_from_metadata([ |
|
353 | - 'metadata_name_value_pairs' => [ |
|
354 | - 'toId' => $user_guid, |
|
355 | - 'readYet' => 0, |
|
356 | - 'msg' => 1, |
|
357 | - ], |
|
358 | - 'owner_guid' => $user_guid ?: elgg_get_logged_in_user_guid(), |
|
359 | - 'limit' => $limit ?: elgg_get_config('default_limit'), |
|
360 | - 'offset' => $offset, |
|
361 | - 'count' => $count, |
|
362 | - 'distinct' => false, |
|
363 | - ]); |
|
352 | + return elgg_get_entities_from_metadata([ |
|
353 | + 'metadata_name_value_pairs' => [ |
|
354 | + 'toId' => $user_guid, |
|
355 | + 'readYet' => 0, |
|
356 | + 'msg' => 1, |
|
357 | + ], |
|
358 | + 'owner_guid' => $user_guid ?: elgg_get_logged_in_user_guid(), |
|
359 | + 'limit' => $limit ?: elgg_get_config('default_limit'), |
|
360 | + 'offset' => $offset, |
|
361 | + 'count' => $count, |
|
362 | + 'distinct' => false, |
|
363 | + ]); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @return int |
372 | 372 | */ |
373 | 373 | function messages_count_unread($user_guid = 0) { |
374 | - return messages_get_unread($user_guid, 10, 0, true); |
|
374 | + return messages_get_unread($user_guid, 10, 0, true); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -381,47 +381,47 @@ discard block |
||
381 | 381 | */ |
382 | 382 | function messages_prepare_form_vars($recipient_guid = 0) { |
383 | 383 | |
384 | - $recipients = []; |
|
385 | - $recipient = get_user($recipient_guid); |
|
386 | - if (!empty($recipient)) { |
|
387 | - $recipients[] = $recipient->getGUID(); |
|
388 | - } |
|
384 | + $recipients = []; |
|
385 | + $recipient = get_user($recipient_guid); |
|
386 | + if (!empty($recipient)) { |
|
387 | + $recipients[] = $recipient->getGUID(); |
|
388 | + } |
|
389 | 389 | |
390 | - // input names => defaults |
|
391 | - $values = [ |
|
392 | - 'subject' => elgg_get_sticky_value('messages', 'subject', ''), |
|
393 | - 'body' => elgg_get_sticky_value('messages', 'body', ''), |
|
394 | - 'recipients' => elgg_get_sticky_value('messages', 'recipients', $recipients), |
|
395 | - ]; |
|
390 | + // input names => defaults |
|
391 | + $values = [ |
|
392 | + 'subject' => elgg_get_sticky_value('messages', 'subject', ''), |
|
393 | + 'body' => elgg_get_sticky_value('messages', 'body', ''), |
|
394 | + 'recipients' => elgg_get_sticky_value('messages', 'recipients', $recipients), |
|
395 | + ]; |
|
396 | 396 | |
397 | - elgg_clear_sticky_form('messages'); |
|
397 | + elgg_clear_sticky_form('messages'); |
|
398 | 398 | |
399 | - return $values; |
|
399 | + return $values; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
403 | 403 | * Add to the user hover menu |
404 | 404 | */ |
405 | 405 | function messages_user_hover_menu($hook, $type, $return, $params) { |
406 | - $user = $params['entity']; |
|
406 | + $user = $params['entity']; |
|
407 | 407 | |
408 | - if (!elgg_is_logged_in()) { |
|
409 | - return; |
|
410 | - } |
|
408 | + if (!elgg_is_logged_in()) { |
|
409 | + return; |
|
410 | + } |
|
411 | 411 | |
412 | - if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
413 | - return; |
|
414 | - } |
|
412 | + if (elgg_get_logged_in_user_guid() == $user->guid) { |
|
413 | + return; |
|
414 | + } |
|
415 | 415 | |
416 | - $return[] = ElggMenuItem::factory([ |
|
417 | - 'name' => 'send', |
|
418 | - 'text' => elgg_echo('messages:sendmessage'), |
|
419 | - 'icon' => 'mail', |
|
420 | - 'href' => "messages/compose?send_to={$user->guid}", |
|
421 | - 'section' => 'action', |
|
422 | - ]); |
|
423 | - |
|
424 | - return $return; |
|
416 | + $return[] = ElggMenuItem::factory([ |
|
417 | + 'name' => 'send', |
|
418 | + 'text' => elgg_echo('messages:sendmessage'), |
|
419 | + 'icon' => 'mail', |
|
420 | + 'href' => "messages/compose?send_to={$user->guid}", |
|
421 | + 'section' => 'action', |
|
422 | + ]); |
|
423 | + |
|
424 | + return $return; |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -433,28 +433,28 @@ discard block |
||
433 | 433 | */ |
434 | 434 | function messages_purge($event, $type, $user) { |
435 | 435 | |
436 | - if (!$user->getGUID()) { |
|
437 | - return; |
|
438 | - } |
|
439 | - |
|
440 | - // make sure we delete them all |
|
441 | - $entity_disable_override = access_show_hidden_entities(true); |
|
442 | - $ia = elgg_set_ignore_access(true); |
|
443 | - |
|
444 | - $options = [ |
|
445 | - 'type' => 'object', |
|
446 | - 'subtype' => 'messages', |
|
447 | - 'metadata_name' => 'fromId', |
|
448 | - 'metadata_value' => $user->getGUID(), |
|
449 | - 'limit' => 0, |
|
450 | - ]; |
|
451 | - $batch = new ElggBatch('elgg_get_entities_from_metadata', $options); |
|
452 | - foreach ($batch as $e) { |
|
453 | - $e->delete(); |
|
454 | - } |
|
455 | - |
|
456 | - elgg_set_ignore_access($ia); |
|
457 | - access_show_hidden_entities($entity_disable_override); |
|
436 | + if (!$user->getGUID()) { |
|
437 | + return; |
|
438 | + } |
|
439 | + |
|
440 | + // make sure we delete them all |
|
441 | + $entity_disable_override = access_show_hidden_entities(true); |
|
442 | + $ia = elgg_set_ignore_access(true); |
|
443 | + |
|
444 | + $options = [ |
|
445 | + 'type' => 'object', |
|
446 | + 'subtype' => 'messages', |
|
447 | + 'metadata_name' => 'fromId', |
|
448 | + 'metadata_value' => $user->getGUID(), |
|
449 | + 'limit' => 0, |
|
450 | + ]; |
|
451 | + $batch = new ElggBatch('elgg_get_entities_from_metadata', $options); |
|
452 | + foreach ($batch as $e) { |
|
453 | + $e->delete(); |
|
454 | + } |
|
455 | + |
|
456 | + elgg_set_ignore_access($ia); |
|
457 | + access_show_hidden_entities($entity_disable_override); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @return array |
469 | 469 | */ |
470 | 470 | function messages_ecml_views_hook($hook, $entity_type, $return_value, $params) { |
471 | - $return_value['messages/messages'] = elgg_echo('messages'); |
|
471 | + $return_value['messages/messages'] = elgg_echo('messages'); |
|
472 | 472 | |
473 | - return $return_value; |
|
473 | + return $return_value; |
|
474 | 474 | } |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | elgg_register_menu_item('page', [ |
14 | 14 | 'name' => 'messages:inbox', |
15 | 15 | 'text' => elgg_echo('messages:inbox'), |
16 | - 'href' => "messages/inbox/" . elgg_get_logged_in_user_entity()->username, |
|
16 | + 'href' => "messages/inbox/".elgg_get_logged_in_user_entity()->username, |
|
17 | 17 | 'context' => 'messages', |
18 | 18 | ]); |
19 | 19 | |
20 | 20 | elgg_register_menu_item('page', [ |
21 | 21 | 'name' => 'messages:sentmessages', |
22 | 22 | 'text' => elgg_echo('messages:sentmessages'), |
23 | - 'href' => "messages/sent/" . elgg_get_logged_in_user_entity()->username, |
|
23 | + 'href' => "messages/sent/".elgg_get_logged_in_user_entity()->username, |
|
24 | 24 | 'context' => 'messages', |
25 | 25 | ]); |
26 | 26 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | elgg_gatekeeper(); |
66 | 66 | |
67 | - elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/' . $current_user->username); |
|
67 | + elgg_push_breadcrumb(elgg_echo('messages'), 'messages/inbox/'.$current_user->username); |
|
68 | 68 | |
69 | 69 | if (!isset($page[0])) { |
70 | 70 | $page[0] = 'inbox'; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $num_messages = (int) messages_count_unread(); |
130 | 130 | if ($num_messages) { |
131 | - $title .= " (" . elgg_echo("messages:unreadcount", [$num_messages]) . ")"; |
|
131 | + $title .= " (".elgg_echo("messages:unreadcount", [$num_messages]).")"; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | $items[] = ElggMenuItem::factory([ |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | $body = elgg_echo('messages:email:body', [ |
303 | 303 | $sender->name, |
304 | 304 | $message_contents, |
305 | - elgg_get_site_url() . "messages/inbox/" . $recipient->username, |
|
305 | + elgg_get_site_url()."messages/inbox/".$recipient->username, |
|
306 | 306 | $sender->name, |
307 | - elgg_get_site_url() . "messages/compose?send_to=" . $sender_guid |
|
307 | + elgg_get_site_url()."messages/compose?send_to=".$sender_guid |
|
308 | 308 | ], |
309 | 309 | $recipient->language |
310 | 310 | ); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | function messages_set_url($hook, $type, $url, $params) { |
334 | 334 | $entity = $params['entity']; |
335 | 335 | if (elgg_instanceof($entity, 'object', 'messages')) { |
336 | - return 'messages/read/' . $entity->getGUID(); |
|
336 | + return 'messages/read/'.$entity->getGUID(); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 |
@@ -358,7 +358,7 @@ |
||
358 | 358 | * @param string $type Hook type |
359 | 359 | * @param array $value Array of custom search types |
360 | 360 | * @param array $params Search parameters |
361 | - * @return array |
|
361 | + * @return string[] |
|
362 | 362 | */ |
363 | 363 | function search_custom_types_tags_hook($hook, $type, $value, $params) { |
364 | 364 | $value[] = 'tags'; |
@@ -17,46 +17,46 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function search_objects_hook($hook, $type, $value, $params) { |
19 | 19 | |
20 | - $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
21 | - $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
20 | + $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
21 | + $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
22 | 22 | |
23 | - $db_prefix = elgg_get_config('dbprefix'); |
|
23 | + $db_prefix = elgg_get_config('dbprefix'); |
|
24 | 24 | |
25 | - $join = "JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"; |
|
26 | - array_unshift($params['joins'], $join); |
|
25 | + $join = "JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid"; |
|
26 | + array_unshift($params['joins'], $join); |
|
27 | 27 | |
28 | - $fields = ['title', 'description']; |
|
29 | - $where = search_get_where_sql('oe', $fields, $params); |
|
30 | - $params['wheres'][] = $where; |
|
28 | + $fields = ['title', 'description']; |
|
29 | + $where = search_get_where_sql('oe', $fields, $params); |
|
30 | + $params['wheres'][] = $where; |
|
31 | 31 | |
32 | - $params['count'] = true; |
|
33 | - $count = elgg_get_entities($params); |
|
32 | + $params['count'] = true; |
|
33 | + $count = elgg_get_entities($params); |
|
34 | 34 | |
35 | - // no need to continue if nothing here. |
|
36 | - if (!$count) { |
|
37 | - return ['entities' => [], 'count' => $count]; |
|
38 | - } |
|
35 | + // no need to continue if nothing here. |
|
36 | + if (!$count) { |
|
37 | + return ['entities' => [], 'count' => $count]; |
|
38 | + } |
|
39 | 39 | |
40 | - $params['count'] = false; |
|
41 | - if (isset($params['sort']) || !isset($params['order_by'])) { |
|
42 | - $params['order_by'] = search_get_order_by_sql('e', 'oe', $params['sort'], $params['order']); |
|
43 | - } |
|
44 | - $params['preload_owners'] = true; |
|
45 | - $entities = elgg_get_entities($params); |
|
46 | - |
|
47 | - // add the volatile data for why these entities have been returned. |
|
48 | - foreach ($entities as $entity) { |
|
49 | - $title = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $params['query']); |
|
50 | - $entity->setVolatileData('search_matched_title', $title); |
|
51 | - |
|
52 | - $desc = search_get_highlighted_relevant_substrings($entity->description, $params['query']); |
|
53 | - $entity->setVolatileData('search_matched_description', $desc); |
|
54 | - } |
|
55 | - |
|
56 | - return [ |
|
57 | - 'entities' => $entities, |
|
58 | - 'count' => $count, |
|
59 | - ]; |
|
40 | + $params['count'] = false; |
|
41 | + if (isset($params['sort']) || !isset($params['order_by'])) { |
|
42 | + $params['order_by'] = search_get_order_by_sql('e', 'oe', $params['sort'], $params['order']); |
|
43 | + } |
|
44 | + $params['preload_owners'] = true; |
|
45 | + $entities = elgg_get_entities($params); |
|
46 | + |
|
47 | + // add the volatile data for why these entities have been returned. |
|
48 | + foreach ($entities as $entity) { |
|
49 | + $title = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $params['query']); |
|
50 | + $entity->setVolatileData('search_matched_title', $title); |
|
51 | + |
|
52 | + $desc = search_get_highlighted_relevant_substrings($entity->description, $params['query']); |
|
53 | + $entity->setVolatileData('search_matched_description', $desc); |
|
54 | + } |
|
55 | + |
|
56 | + return [ |
|
57 | + 'entities' => $entities, |
|
58 | + 'count' => $count, |
|
59 | + ]; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -70,47 +70,47 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function search_groups_hook($hook, $type, $value, $params) { |
72 | 72 | |
73 | - $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
74 | - $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
73 | + $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
74 | + $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
75 | 75 | |
76 | - $db_prefix = elgg_get_config('dbprefix'); |
|
76 | + $db_prefix = elgg_get_config('dbprefix'); |
|
77 | 77 | |
78 | - $query = sanitise_string($params['query']); |
|
78 | + $query = sanitise_string($params['query']); |
|
79 | 79 | |
80 | - $join = "JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid"; |
|
81 | - array_unshift($params['joins'], $join); |
|
80 | + $join = "JOIN {$db_prefix}groups_entity ge ON e.guid = ge.guid"; |
|
81 | + array_unshift($params['joins'], $join); |
|
82 | 82 | |
83 | - $fields = ['name', 'description']; |
|
84 | - $where = search_get_where_sql('ge', $fields, $params); |
|
85 | - $params['wheres'][] = $where; |
|
83 | + $fields = ['name', 'description']; |
|
84 | + $where = search_get_where_sql('ge', $fields, $params); |
|
85 | + $params['wheres'][] = $where; |
|
86 | 86 | |
87 | - $params['count'] = true; |
|
88 | - $count = elgg_get_entities($params); |
|
87 | + $params['count'] = true; |
|
88 | + $count = elgg_get_entities($params); |
|
89 | 89 | |
90 | - // no need to continue if nothing here. |
|
91 | - if (!$count) { |
|
92 | - return ['entities' => [], 'count' => $count]; |
|
93 | - } |
|
90 | + // no need to continue if nothing here. |
|
91 | + if (!$count) { |
|
92 | + return ['entities' => [], 'count' => $count]; |
|
93 | + } |
|
94 | 94 | |
95 | - $params['count'] = false; |
|
96 | - if (isset($params['sort']) || !isset($params['order_by'])) { |
|
97 | - $params['order_by'] = search_get_order_by_sql('e', 'ge', $params['sort'], $params['order']); |
|
98 | - } |
|
99 | - $entities = elgg_get_entities($params); |
|
100 | - |
|
101 | - // add the volatile data for why these entities have been returned. |
|
102 | - foreach ($entities as $entity) { |
|
103 | - $name = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $query); |
|
104 | - $entity->setVolatileData('search_matched_title', $name); |
|
105 | - |
|
106 | - $description = search_get_highlighted_relevant_substrings($entity->description, $query); |
|
107 | - $entity->setVolatileData('search_matched_description', $description); |
|
108 | - } |
|
109 | - |
|
110 | - return [ |
|
111 | - 'entities' => $entities, |
|
112 | - 'count' => $count, |
|
113 | - ]; |
|
95 | + $params['count'] = false; |
|
96 | + if (isset($params['sort']) || !isset($params['order_by'])) { |
|
97 | + $params['order_by'] = search_get_order_by_sql('e', 'ge', $params['sort'], $params['order']); |
|
98 | + } |
|
99 | + $entities = elgg_get_entities($params); |
|
100 | + |
|
101 | + // add the volatile data for why these entities have been returned. |
|
102 | + foreach ($entities as $entity) { |
|
103 | + $name = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $query); |
|
104 | + $entity->setVolatileData('search_matched_title', $name); |
|
105 | + |
|
106 | + $description = search_get_highlighted_relevant_substrings($entity->description, $query); |
|
107 | + $entity->setVolatileData('search_matched_description', $description); |
|
108 | + } |
|
109 | + |
|
110 | + return [ |
|
111 | + 'entities' => $entities, |
|
112 | + 'count' => $count, |
|
113 | + ]; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -126,101 +126,101 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function search_users_hook($hook, $type, $value, $params) { |
128 | 128 | |
129 | - $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
130 | - $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
129 | + $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
130 | + $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
131 | 131 | |
132 | - $db_prefix = elgg_get_config('dbprefix'); |
|
132 | + $db_prefix = elgg_get_config('dbprefix'); |
|
133 | 133 | |
134 | - $query = sanitise_string($params['query']); |
|
134 | + $query = sanitise_string($params['query']); |
|
135 | 135 | |
136 | - $join = "JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid"; |
|
137 | - array_unshift($params['joins'], $join); |
|
136 | + $join = "JOIN {$db_prefix}users_entity ue ON e.guid = ue.guid"; |
|
137 | + array_unshift($params['joins'], $join); |
|
138 | 138 | |
139 | - // username and display name |
|
140 | - $fields = ['username', 'name']; |
|
141 | - $where = search_get_where_sql('ue', $fields, $params); |
|
139 | + // username and display name |
|
140 | + $fields = ['username', 'name']; |
|
141 | + $where = search_get_where_sql('ue', $fields, $params); |
|
142 | 142 | |
143 | - // profile fields |
|
144 | - $profile_fields = array_keys(elgg_get_config('profile_fields')); |
|
143 | + // profile fields |
|
144 | + $profile_fields = array_keys(elgg_get_config('profile_fields')); |
|
145 | 145 | |
146 | - if (!empty($profile_fields)) { |
|
147 | - $params['joins'][] = "JOIN {$db_prefix}annotations an on e.guid = an.entity_guid"; |
|
146 | + if (!empty($profile_fields)) { |
|
147 | + $params['joins'][] = "JOIN {$db_prefix}annotations an on e.guid = an.entity_guid"; |
|
148 | 148 | |
149 | - // get the where clauses for the annotation names |
|
150 | - // can't use egef_annotations() because the n_table join comes too late. |
|
151 | - $clauses = _elgg_entities_get_metastrings_options('annotation', [ |
|
152 | - 'annotation_names' => $profile_fields, |
|
153 | - |
|
154 | - // avoid notices |
|
155 | - 'annotation_values' => null, |
|
156 | - 'annotation_name_value_pairs' => null, |
|
157 | - 'annotation_name_value_pairs_operator' => null, |
|
158 | - 'annotation_case_sensitive' => null, |
|
159 | - 'order_by_annotation' => null, |
|
160 | - 'annotation_owner_guids' => null, |
|
161 | - ]); |
|
162 | - |
|
163 | - $params['joins'] = array_merge($clauses['joins'], $params['joins']); |
|
164 | - $md_where = "(({$clauses['wheres'][0]}) AND md.value LIKE '%$query%')"; |
|
149 | + // get the where clauses for the annotation names |
|
150 | + // can't use egef_annotations() because the n_table join comes too late. |
|
151 | + $clauses = _elgg_entities_get_metastrings_options('annotation', [ |
|
152 | + 'annotation_names' => $profile_fields, |
|
153 | + |
|
154 | + // avoid notices |
|
155 | + 'annotation_values' => null, |
|
156 | + 'annotation_name_value_pairs' => null, |
|
157 | + 'annotation_name_value_pairs_operator' => null, |
|
158 | + 'annotation_case_sensitive' => null, |
|
159 | + 'order_by_annotation' => null, |
|
160 | + 'annotation_owner_guids' => null, |
|
161 | + ]); |
|
162 | + |
|
163 | + $params['joins'] = array_merge($clauses['joins'], $params['joins']); |
|
164 | + $md_where = "(({$clauses['wheres'][0]}) AND md.value LIKE '%$query%')"; |
|
165 | 165 | |
166 | - $params['wheres'][] = "(($where) OR ($md_where))"; |
|
167 | - } else { |
|
168 | - $params['wheres'][] = "$where"; |
|
169 | - } |
|
170 | - |
|
171 | - $params['count'] = true; |
|
172 | - $count = elgg_get_entities($params); |
|
173 | - |
|
174 | - // no need to continue if nothing here. |
|
175 | - if (!$count) { |
|
176 | - return ['entities' => [], 'count' => $count]; |
|
177 | - } |
|
166 | + $params['wheres'][] = "(($where) OR ($md_where))"; |
|
167 | + } else { |
|
168 | + $params['wheres'][] = "$where"; |
|
169 | + } |
|
170 | + |
|
171 | + $params['count'] = true; |
|
172 | + $count = elgg_get_entities($params); |
|
173 | + |
|
174 | + // no need to continue if nothing here. |
|
175 | + if (!$count) { |
|
176 | + return ['entities' => [], 'count' => $count]; |
|
177 | + } |
|
178 | 178 | |
179 | - $params['count'] = false; |
|
180 | - if (isset($params['sort']) || !isset($params['order_by'])) { |
|
181 | - $params['order_by'] = search_get_order_by_sql('e', 'ue', $params['sort'], $params['order']); |
|
182 | - } |
|
183 | - $entities = elgg_get_entities($params); |
|
184 | - /* @var ElggUser[] $entities */ |
|
185 | - |
|
186 | - // add the volatile data for why these entities have been returned. |
|
187 | - foreach ($entities as $entity) { |
|
188 | - $title = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $query); |
|
189 | - |
|
190 | - // include the username if it matches but the display name doesn't. |
|
191 | - if (false !== strpos($entity->username, $query)) { |
|
192 | - $username = search_get_highlighted_relevant_substrings($entity->username, $query); |
|
193 | - $title .= " ($username)"; |
|
194 | - } |
|
195 | - |
|
196 | - $entity->setVolatileData('search_matched_title', $title); |
|
197 | - |
|
198 | - if (!empty($profile_fields)) { |
|
199 | - $matched = ''; |
|
200 | - foreach ($profile_fields as $shortname) { |
|
201 | - $annotations = $entity->getAnnotations([ |
|
202 | - 'annotation_names' => "profile:$shortname", |
|
203 | - 'limit' => false, |
|
204 | - ]); |
|
205 | - $values = array_map(function (ElggAnnotation $a) { |
|
206 | - return $a->value; |
|
207 | - }, $annotations); |
|
208 | - foreach ($values as $text) { |
|
209 | - if (stristr($text, $query)) { |
|
210 | - $matched .= elgg_echo("profile:{$shortname}") . ': ' |
|
211 | - . search_get_highlighted_relevant_substrings($text, $query); |
|
212 | - } |
|
213 | - } |
|
214 | - } |
|
179 | + $params['count'] = false; |
|
180 | + if (isset($params['sort']) || !isset($params['order_by'])) { |
|
181 | + $params['order_by'] = search_get_order_by_sql('e', 'ue', $params['sort'], $params['order']); |
|
182 | + } |
|
183 | + $entities = elgg_get_entities($params); |
|
184 | + /* @var ElggUser[] $entities */ |
|
185 | + |
|
186 | + // add the volatile data for why these entities have been returned. |
|
187 | + foreach ($entities as $entity) { |
|
188 | + $title = search_get_highlighted_relevant_substrings($entity->getDisplayName(), $query); |
|
189 | + |
|
190 | + // include the username if it matches but the display name doesn't. |
|
191 | + if (false !== strpos($entity->username, $query)) { |
|
192 | + $username = search_get_highlighted_relevant_substrings($entity->username, $query); |
|
193 | + $title .= " ($username)"; |
|
194 | + } |
|
195 | + |
|
196 | + $entity->setVolatileData('search_matched_title', $title); |
|
197 | + |
|
198 | + if (!empty($profile_fields)) { |
|
199 | + $matched = ''; |
|
200 | + foreach ($profile_fields as $shortname) { |
|
201 | + $annotations = $entity->getAnnotations([ |
|
202 | + 'annotation_names' => "profile:$shortname", |
|
203 | + 'limit' => false, |
|
204 | + ]); |
|
205 | + $values = array_map(function (ElggAnnotation $a) { |
|
206 | + return $a->value; |
|
207 | + }, $annotations); |
|
208 | + foreach ($values as $text) { |
|
209 | + if (stristr($text, $query)) { |
|
210 | + $matched .= elgg_echo("profile:{$shortname}") . ': ' |
|
211 | + . search_get_highlighted_relevant_substrings($text, $query); |
|
212 | + } |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - $entity->setVolatileData('search_matched_description', $matched); |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - return [ |
|
221 | - 'entities' => $entities, |
|
222 | - 'count' => $count, |
|
223 | - ]; |
|
216 | + $entity->setVolatileData('search_matched_description', $matched); |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + return [ |
|
221 | + 'entities' => $entities, |
|
222 | + 'count' => $count, |
|
223 | + ]; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -234,108 +234,108 @@ discard block |
||
234 | 234 | */ |
235 | 235 | function search_tags_hook($hook, $type, $value, $params) { |
236 | 236 | |
237 | - $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
238 | - $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
239 | - |
|
240 | - $db_prefix = elgg_get_config('dbprefix'); |
|
241 | - |
|
242 | - $valid_tag_names = elgg_get_registered_tag_metadata_names(); |
|
243 | - |
|
244 | - // @todo will need to split this up to support searching multiple tags at once. |
|
245 | - $query = sanitise_string($params['query']); |
|
246 | - |
|
247 | - // if passed a tag metadata name, only search on that tag name. |
|
248 | - // tag_name isn't included in the params because it's specific to |
|
249 | - // tag searches. |
|
250 | - if ($tag_names = get_input('tag_names')) { |
|
251 | - if (is_array($tag_names)) { |
|
252 | - $search_tag_names = $tag_names; |
|
253 | - } else { |
|
254 | - $search_tag_names = [$tag_names]; |
|
255 | - } |
|
256 | - |
|
257 | - // check these are valid to avoid arbitrary metadata searches. |
|
258 | - foreach ($search_tag_names as $i => $tag_name) { |
|
259 | - if (!in_array($tag_name, $valid_tag_names)) { |
|
260 | - unset($search_tag_names[$i]); |
|
261 | - } |
|
262 | - } |
|
263 | - } else { |
|
264 | - $search_tag_names = $valid_tag_names; |
|
265 | - } |
|
266 | - |
|
267 | - if (!$search_tag_names) { |
|
268 | - return ['entities' => [], 'count' => $count]; |
|
269 | - } |
|
270 | - |
|
271 | - // don't use elgg_get_entities_from_metadata() here because of |
|
272 | - // performance issues. since we don't care what matches at this point |
|
273 | - // use an IN clause to grab everything that matches at once and sort |
|
274 | - // out the matches later. |
|
275 | - $params['joins'][] = "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid"; |
|
276 | - |
|
277 | - $access = _elgg_get_access_where_sql([ |
|
278 | - 'table_alias' => 'md', |
|
279 | - 'guid_column' => 'entity_guid', |
|
280 | - ]); |
|
281 | - $sanitised_tags = []; |
|
282 | - |
|
283 | - foreach ($search_tag_names as $tag) { |
|
284 | - $sanitised_tags[] = '"' . sanitise_string($tag) . '"'; |
|
285 | - } |
|
286 | - |
|
287 | - $tags_in = implode(',', $sanitised_tags); |
|
288 | - |
|
289 | - $params['wheres'][] = "(md.name IN ($tags_in) AND md.value = '$query' AND $access)"; |
|
290 | - |
|
291 | - $params['count'] = true; |
|
292 | - $count = elgg_get_entities($params); |
|
293 | - |
|
294 | - // no need to continue if nothing here. |
|
295 | - if (!$count) { |
|
296 | - return ['entities' => [], 'count' => $count]; |
|
297 | - } |
|
237 | + $params['joins'] = (array) elgg_extract('joins', $params, []); |
|
238 | + $params['wheres'] = (array) elgg_extract('wheres', $params, []); |
|
239 | + |
|
240 | + $db_prefix = elgg_get_config('dbprefix'); |
|
241 | + |
|
242 | + $valid_tag_names = elgg_get_registered_tag_metadata_names(); |
|
243 | + |
|
244 | + // @todo will need to split this up to support searching multiple tags at once. |
|
245 | + $query = sanitise_string($params['query']); |
|
246 | + |
|
247 | + // if passed a tag metadata name, only search on that tag name. |
|
248 | + // tag_name isn't included in the params because it's specific to |
|
249 | + // tag searches. |
|
250 | + if ($tag_names = get_input('tag_names')) { |
|
251 | + if (is_array($tag_names)) { |
|
252 | + $search_tag_names = $tag_names; |
|
253 | + } else { |
|
254 | + $search_tag_names = [$tag_names]; |
|
255 | + } |
|
256 | + |
|
257 | + // check these are valid to avoid arbitrary metadata searches. |
|
258 | + foreach ($search_tag_names as $i => $tag_name) { |
|
259 | + if (!in_array($tag_name, $valid_tag_names)) { |
|
260 | + unset($search_tag_names[$i]); |
|
261 | + } |
|
262 | + } |
|
263 | + } else { |
|
264 | + $search_tag_names = $valid_tag_names; |
|
265 | + } |
|
266 | + |
|
267 | + if (!$search_tag_names) { |
|
268 | + return ['entities' => [], 'count' => $count]; |
|
269 | + } |
|
270 | + |
|
271 | + // don't use elgg_get_entities_from_metadata() here because of |
|
272 | + // performance issues. since we don't care what matches at this point |
|
273 | + // use an IN clause to grab everything that matches at once and sort |
|
274 | + // out the matches later. |
|
275 | + $params['joins'][] = "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid"; |
|
276 | + |
|
277 | + $access = _elgg_get_access_where_sql([ |
|
278 | + 'table_alias' => 'md', |
|
279 | + 'guid_column' => 'entity_guid', |
|
280 | + ]); |
|
281 | + $sanitised_tags = []; |
|
282 | + |
|
283 | + foreach ($search_tag_names as $tag) { |
|
284 | + $sanitised_tags[] = '"' . sanitise_string($tag) . '"'; |
|
285 | + } |
|
286 | + |
|
287 | + $tags_in = implode(',', $sanitised_tags); |
|
288 | + |
|
289 | + $params['wheres'][] = "(md.name IN ($tags_in) AND md.value = '$query' AND $access)"; |
|
290 | + |
|
291 | + $params['count'] = true; |
|
292 | + $count = elgg_get_entities($params); |
|
293 | + |
|
294 | + // no need to continue if nothing here. |
|
295 | + if (!$count) { |
|
296 | + return ['entities' => [], 'count' => $count]; |
|
297 | + } |
|
298 | 298 | |
299 | - $params['count'] = false; |
|
300 | - if (isset($params['sort']) || !isset($params['order_by'])) { |
|
301 | - $params['order_by'] = search_get_order_by_sql('e', null, $params['sort'], $params['order']); |
|
302 | - } |
|
303 | - $entities = elgg_get_entities($params); |
|
304 | - |
|
305 | - // add the volatile data for why these entities have been returned. |
|
306 | - foreach ($entities as $entity) { |
|
307 | - $matched_tags_strs = []; |
|
308 | - |
|
309 | - // get tags for each tag name requested to find which ones matched. |
|
310 | - foreach ($search_tag_names as $tag_name) { |
|
311 | - $tags = $entity->getTags($tag_name); |
|
312 | - |
|
313 | - // @todo make one long tag string and run this through the highlight |
|
314 | - // function. This might be confusing as it could chop off |
|
315 | - // the tag labels. |
|
316 | - if (in_array(strtolower($query), array_map('strtolower', $tags))) { |
|
317 | - if (is_array($tags)) { |
|
318 | - $tag_name_str = elgg_echo("tag_names:$tag_name"); |
|
319 | - $matched_tags_strs[] = "$tag_name_str: " . implode(', ', $tags); |
|
320 | - } |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - $title_str = elgg_get_excerpt($entity->getDisplayName(), 300); |
|
325 | - $desc_str = elgg_get_excerpt($entity->description, 300); |
|
299 | + $params['count'] = false; |
|
300 | + if (isset($params['sort']) || !isset($params['order_by'])) { |
|
301 | + $params['order_by'] = search_get_order_by_sql('e', null, $params['sort'], $params['order']); |
|
302 | + } |
|
303 | + $entities = elgg_get_entities($params); |
|
304 | + |
|
305 | + // add the volatile data for why these entities have been returned. |
|
306 | + foreach ($entities as $entity) { |
|
307 | + $matched_tags_strs = []; |
|
308 | + |
|
309 | + // get tags for each tag name requested to find which ones matched. |
|
310 | + foreach ($search_tag_names as $tag_name) { |
|
311 | + $tags = $entity->getTags($tag_name); |
|
312 | + |
|
313 | + // @todo make one long tag string and run this through the highlight |
|
314 | + // function. This might be confusing as it could chop off |
|
315 | + // the tag labels. |
|
316 | + if (in_array(strtolower($query), array_map('strtolower', $tags))) { |
|
317 | + if (is_array($tags)) { |
|
318 | + $tag_name_str = elgg_echo("tag_names:$tag_name"); |
|
319 | + $matched_tags_strs[] = "$tag_name_str: " . implode(', ', $tags); |
|
320 | + } |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + $title_str = elgg_get_excerpt($entity->getDisplayName(), 300); |
|
325 | + $desc_str = elgg_get_excerpt($entity->description, 300); |
|
326 | 326 | |
327 | - $tags_str = implode('. ', $matched_tags_strs); |
|
328 | - $tags_str = search_get_highlighted_relevant_substrings($tags_str, $params['query'], 30, 300, true); |
|
329 | - |
|
330 | - $entity->setVolatileData('search_matched_title', $title_str); |
|
331 | - $entity->setVolatileData('search_matched_description', $desc_str); |
|
332 | - $entity->setVolatileData('search_matched_extra', $tags_str); |
|
333 | - } |
|
334 | - |
|
335 | - return [ |
|
336 | - 'entities' => $entities, |
|
337 | - 'count' => $count, |
|
338 | - ]; |
|
327 | + $tags_str = implode('. ', $matched_tags_strs); |
|
328 | + $tags_str = search_get_highlighted_relevant_substrings($tags_str, $params['query'], 30, 300, true); |
|
329 | + |
|
330 | + $entity->setVolatileData('search_matched_title', $title_str); |
|
331 | + $entity->setVolatileData('search_matched_description', $desc_str); |
|
332 | + $entity->setVolatileData('search_matched_extra', $tags_str); |
|
333 | + } |
|
334 | + |
|
335 | + return [ |
|
336 | + 'entities' => $entities, |
|
337 | + 'count' => $count, |
|
338 | + ]; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -348,6 +348,6 @@ discard block |
||
348 | 348 | * @return array |
349 | 349 | */ |
350 | 350 | function search_custom_types_tags_hook($hook, $type, $value, $params) { |
351 | - $value[] = 'tags'; |
|
352 | - return $value; |
|
351 | + $value[] = 'tags'; |
|
352 | + return $value; |
|
353 | 353 | } |
@@ -202,12 +202,12 @@ discard block |
||
202 | 202 | 'annotation_names' => "profile:$shortname", |
203 | 203 | 'limit' => false, |
204 | 204 | ]); |
205 | - $values = array_map(function (ElggAnnotation $a) { |
|
205 | + $values = array_map(function(ElggAnnotation $a) { |
|
206 | 206 | return $a->value; |
207 | 207 | }, $annotations); |
208 | 208 | foreach ($values as $text) { |
209 | 209 | if (stristr($text, $query)) { |
210 | - $matched .= elgg_echo("profile:{$shortname}") . ': ' |
|
210 | + $matched .= elgg_echo("profile:{$shortname}").': ' |
|
211 | 211 | . search_get_highlighted_relevant_substrings($text, $query); |
212 | 212 | } |
213 | 213 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $sanitised_tags = []; |
282 | 282 | |
283 | 283 | foreach ($search_tag_names as $tag) { |
284 | - $sanitised_tags[] = '"' . sanitise_string($tag) . '"'; |
|
284 | + $sanitised_tags[] = '"'.sanitise_string($tag).'"'; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $tags_in = implode(',', $sanitised_tags); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | if (in_array(strtolower($query), array_map('strtolower', $tags))) { |
317 | 317 | if (is_array($tags)) { |
318 | 318 | $tag_name_str = elgg_echo("tag_names:$tag_name"); |
319 | - $matched_tags_strs[] = "$tag_name_str: " . implode(', ', $tags); |
|
319 | + $matched_tags_strs[] = "$tag_name_str: ".implode(', ', $tags); |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | * |
77 | 77 | * Not currently implemented in this cache type. |
78 | 78 | * |
79 | - * @return true |
|
79 | + * @return boolean |
|
80 | 80 | */ |
81 | 81 | public function clear() { |
82 | 82 | return true; |
@@ -7,89 +7,89 @@ |
||
7 | 7 | * @subpackage HMAC |
8 | 8 | */ |
9 | 9 | class ElggHMACCache extends ElggCache { |
10 | - /** |
|
11 | - * Set the Elgg cache. |
|
12 | - * |
|
13 | - * @param int $max_age Maximum age in seconds, 0 if no limit. |
|
14 | - */ |
|
15 | - function __construct($max_age = 0) { |
|
16 | - $this->setVariable("max_age", $max_age); |
|
17 | - } |
|
10 | + /** |
|
11 | + * Set the Elgg cache. |
|
12 | + * |
|
13 | + * @param int $max_age Maximum age in seconds, 0 if no limit. |
|
14 | + */ |
|
15 | + function __construct($max_age = 0) { |
|
16 | + $this->setVariable("max_age", $max_age); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Save a key |
|
21 | - * |
|
22 | - * @param string $key Name |
|
23 | - * @param string $data Value |
|
24 | - * |
|
25 | - * @return boolean |
|
26 | - */ |
|
27 | - public function save($key, $data) { |
|
28 | - $dbprefix = elgg_get_config('dbprefix'); |
|
29 | - $key = sanitise_string($key); |
|
30 | - $time = time(); |
|
19 | + /** |
|
20 | + * Save a key |
|
21 | + * |
|
22 | + * @param string $key Name |
|
23 | + * @param string $data Value |
|
24 | + * |
|
25 | + * @return boolean |
|
26 | + */ |
|
27 | + public function save($key, $data) { |
|
28 | + $dbprefix = elgg_get_config('dbprefix'); |
|
29 | + $key = sanitise_string($key); |
|
30 | + $time = time(); |
|
31 | 31 | |
32 | - $query = "INSERT into {$dbprefix}hmac_cache (hmac, ts) VALUES ('$key', '$time')"; |
|
33 | - return insert_data($query); |
|
34 | - } |
|
32 | + $query = "INSERT into {$dbprefix}hmac_cache (hmac, ts) VALUES ('$key', '$time')"; |
|
33 | + return insert_data($query); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Load a key |
|
38 | - * |
|
39 | - * @param string $key Name |
|
40 | - * @param int $offset Offset |
|
41 | - * @param int $limit Limit |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function load($key, $offset = 0, $limit = null) { |
|
46 | - $dbprefix = elgg_get_config('dbprefix'); |
|
47 | - $key = sanitise_string($key); |
|
36 | + /** |
|
37 | + * Load a key |
|
38 | + * |
|
39 | + * @param string $key Name |
|
40 | + * @param int $offset Offset |
|
41 | + * @param int $limit Limit |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function load($key, $offset = 0, $limit = null) { |
|
46 | + $dbprefix = elgg_get_config('dbprefix'); |
|
47 | + $key = sanitise_string($key); |
|
48 | 48 | |
49 | - $row = get_data_row("SELECT * from {$dbprefix}hmac_cache where hmac='$key'"); |
|
50 | - if ($row) { |
|
51 | - return $row->hmac; |
|
52 | - } |
|
49 | + $row = get_data_row("SELECT * from {$dbprefix}hmac_cache where hmac='$key'"); |
|
50 | + if ($row) { |
|
51 | + return $row->hmac; |
|
52 | + } |
|
53 | 53 | |
54 | - return false; |
|
55 | - } |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Invalidate a given key. |
|
59 | - * |
|
60 | - * @param string $key Name |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function delete($key) { |
|
65 | - $dbprefix = elgg_get_config('dbprefix'); |
|
66 | - $key = sanitise_string($key); |
|
57 | + /** |
|
58 | + * Invalidate a given key. |
|
59 | + * |
|
60 | + * @param string $key Name |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function delete($key) { |
|
65 | + $dbprefix = elgg_get_config('dbprefix'); |
|
66 | + $key = sanitise_string($key); |
|
67 | 67 | |
68 | - return delete_data("DELETE from {$dbprefix}hmac_cache where hmac='$key'"); |
|
69 | - } |
|
68 | + return delete_data("DELETE from {$dbprefix}hmac_cache where hmac='$key'"); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Clear out all the contents of the cache. |
|
73 | - * |
|
74 | - * Not currently implemented in this cache type. |
|
75 | - * |
|
76 | - * @return true |
|
77 | - */ |
|
78 | - public function clear() { |
|
79 | - return true; |
|
80 | - } |
|
71 | + /** |
|
72 | + * Clear out all the contents of the cache. |
|
73 | + * |
|
74 | + * Not currently implemented in this cache type. |
|
75 | + * |
|
76 | + * @return true |
|
77 | + */ |
|
78 | + public function clear() { |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Clean out old stuff. |
|
84 | - * |
|
85 | - */ |
|
86 | - public function __destruct() { |
|
87 | - $dbprefix = elgg_get_config('dbprefix'); |
|
88 | - $time = time(); |
|
89 | - $age = (int) $this->getVariable("max_age"); |
|
82 | + /** |
|
83 | + * Clean out old stuff. |
|
84 | + * |
|
85 | + */ |
|
86 | + public function __destruct() { |
|
87 | + $dbprefix = elgg_get_config('dbprefix'); |
|
88 | + $time = time(); |
|
89 | + $age = (int) $this->getVariable("max_age"); |
|
90 | 90 | |
91 | - $expires = $time - $age; |
|
91 | + $expires = $time - $age; |
|
92 | 92 | |
93 | - delete_data("DELETE from {$dbprefix}hmac_cache where ts<$expires"); |
|
94 | - } |
|
93 | + delete_data("DELETE from {$dbprefix}hmac_cache where ts<$expires"); |
|
94 | + } |
|
95 | 95 | } |