1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * Catch calls to forward() in ajax request and force an exit. |
||||
5 | * |
||||
6 | * Forces response is json of the following form: |
||||
7 | * <pre> |
||||
8 | * { |
||||
9 | * "current_url": "the.url.we/were/coming/from", |
||||
10 | * "forward_url": "the.url.we/were/going/to", |
||||
11 | * "system_messages": { |
||||
12 | * "messages": ["msg1", "msg2", ...], |
||||
13 | * "errors": ["err1", "err2", ...] |
||||
14 | * }, |
||||
15 | * "status": -1 //or 0 for success if there are no error messages present |
||||
16 | * } |
||||
17 | * </pre> |
||||
18 | * where "system_messages" is all message registers at the point of forwarding |
||||
19 | * |
||||
20 | * @internal registered for the 'forward', 'all' plugin hook |
||||
21 | * |
||||
22 | * @param string $hook |
||||
23 | * @param string $type |
||||
24 | * @param string $forward_url |
||||
25 | * @param array $params |
||||
26 | * @return void |
||||
27 | * @access private |
||||
28 | * @deprecated 2.3 |
||||
29 | */ |
||||
30 | function ajax_forward_hook($hook, $type, $forward_url, $params) { |
||||
2 ignored issues
–
show
The parameter
$params is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||
31 | elgg_deprecated_notice(__FUNCTION__ . ' is deprecated and is no longer used as a plugin hook handler', '2.3'); |
||||
32 | |||||
33 | if (!elgg_is_xhr()) { |
||||
34 | return; |
||||
35 | } |
||||
36 | |||||
37 | // grab any data echo'd in the action |
||||
38 | $output = ob_get_clean(); |
||||
39 | |||||
40 | if ($type == 'walled_garden' || $type == 'csrf') { |
||||
41 | $type = '403'; |
||||
42 | } |
||||
43 | |||||
44 | $status_code = (int) $type; |
||||
45 | if ($status_code < 100 || ($status_code > 299 && $status_code < 400) || $status_code > 599) { |
||||
46 | // We only want to preserve OK and error codes |
||||
47 | // Redirect responses should be converted to OK responses as this is an XHR request |
||||
48 | $status_code = ELGG_HTTP_OK; |
||||
49 | } |
||||
50 | |||||
51 | $response = elgg_ok_response($output, '', $forward_url, $status_code); |
||||
52 | |||||
53 | $headers = $response->getHeaders(); |
||||
54 | $headers['Content-Type'] = 'application/json; charset=UTF-8'; |
||||
55 | $response->setHeaders($headers); |
||||
56 | |||||
57 | _elgg_services()->responseFactory->respond($response); |
||||
58 | exit; |
||||
1 ignored issue
–
show
|
|||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * Buffer all output echo'd directly in the action for inclusion in the returned JSON. |
||||
63 | * @return void |
||||
64 | * @access private |
||||
65 | * @deprecated 2.3 |
||||
66 | */ |
||||
67 | function ajax_action_hook() { |
||||
68 | elgg_deprecated_notice(__FUNCTION__ . ' is deprecated and is no longer used as a plugin hook handler', '2.3'); |
||||
69 | |||||
70 | if (elgg_is_xhr()) { |
||||
71 | ob_start(); |
||||
72 | } |
||||
73 | } |
||||
74 | |||||
75 | /** |
||||
76 | * Get the contents of an uploaded file. |
||||
77 | * (Returns false if there was an issue.) |
||||
78 | * |
||||
79 | * @param string $input_name The name of the file input field on the submission form |
||||
80 | * |
||||
81 | * @return mixed|false The contents of the file, or false on failure. |
||||
82 | * @deprecated 2.3 |
||||
83 | */ |
||||
84 | function get_uploaded_file($input_name) { |
||||
85 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated and will be removed', '2.3'); |
||||
86 | $inputs = elgg_get_uploaded_files($input_name); |
||||
87 | $input = array_shift($inputs); |
||||
88 | if (!$input || !$input->isValid()) { |
||||
89 | return false; |
||||
90 | } |
||||
91 | return file_get_contents($input->getPathname()); |
||||
92 | } |
||||
93 | |||||
94 | /** |
||||
95 | * Gets the jpeg contents of the resized version of an uploaded image |
||||
96 | * (Returns false if the uploaded file was not an image) |
||||
97 | * |
||||
98 | * @param string $input_name The name of the file input field on the submission form |
||||
99 | * @param int $maxwidth The maximum width of the resized image |
||||
100 | * @param int $maxheight The maximum height of the resized image |
||||
101 | * @param bool $square If set to true, will take the smallest |
||||
102 | * of maxwidth and maxheight and use it to set the |
||||
103 | * dimensions on all size; the image will be cropped. |
||||
104 | * @param bool $upscale Resize images smaller than $maxwidth x $maxheight? |
||||
105 | * |
||||
106 | * @return false|mixed The contents of the resized image, or false on failure |
||||
107 | * @deprecated 2.3 |
||||
108 | */ |
||||
109 | function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, |
||||
110 | $square = false, $upscale = false) { |
||||
111 | |||||
112 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use elgg_save_resized_image()', '2.3'); |
||||
113 | |||||
114 | $file = _elgg_services()->request->getFile($input_name); |
||||
115 | if (empty($file)) { |
||||
116 | return false; |
||||
117 | } |
||||
118 | |||||
119 | return get_resized_image_from_existing_file($file->getPathname(), $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale); |
||||
120 | } |
||||
121 | |||||
122 | /** |
||||
123 | * Gets the jpeg contents of the resized version of an already uploaded image |
||||
124 | * (Returns false if the file was not an image) |
||||
125 | * |
||||
126 | * @param string $input_name The name of the file on the disk |
||||
127 | * @param int $maxwidth The desired width of the resized image |
||||
128 | * @param int $maxheight The desired height of the resized image |
||||
129 | * @param bool $square If set to true, takes the smallest of maxwidth and |
||||
130 | * maxheight and use it to set the dimensions on the new image. |
||||
131 | * If no crop parameters are set, the largest square that fits |
||||
132 | * in the image centered will be used for the resize. If square, |
||||
133 | * the crop must be a square region. |
||||
134 | * @param int $x1 x coordinate for top, left corner |
||||
135 | * @param int $y1 y coordinate for top, left corner |
||||
136 | * @param int $x2 x coordinate for bottom, right corner |
||||
137 | * @param int $y2 y coordinate for bottom, right corner |
||||
138 | * @param bool $upscale Resize images smaller than $maxwidth x $maxheight? |
||||
139 | * |
||||
140 | * @return false|mixed The contents of the resized image, or false on failure |
||||
141 | * @deprecated 2.3 |
||||
142 | */ |
||||
143 | function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, |
||||
144 | $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0, $upscale = false) { |
||||
145 | |||||
146 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use elgg_save_resized_image()', '2.3'); |
||||
147 | |||||
148 | if (!is_readable($input_name)) { |
||||
149 | return false; |
||||
150 | } |
||||
151 | |||||
152 | // we will write resized image to a temporary file and then delete it |
||||
153 | // need to add a valid image extension otherwise resizing fails |
||||
154 | $tmp_filename = tempnam(sys_get_temp_dir(), 'icon_resize'); |
||||
155 | |||||
156 | $params = [ |
||||
157 | 'w' => $maxwidth, |
||||
158 | 'h' => $maxheight, |
||||
159 | 'x1' => $x1, |
||||
160 | 'y1' => $y1, |
||||
161 | 'x2' => $x2, |
||||
162 | 'y2' => $y2, |
||||
163 | 'square' => $square, |
||||
164 | 'upscale' => $upscale, |
||||
165 | ]; |
||||
166 | |||||
167 | $image_bytes = false; |
||||
168 | if (elgg_save_resized_image($input_name, $tmp_filename, $params)) { |
||||
169 | $image_bytes = file_get_contents($tmp_filename); |
||||
170 | } |
||||
171 | |||||
172 | unlink($tmp_filename); |
||||
173 | |||||
174 | return $image_bytes; |
||||
175 | } |
||||
176 | |||||
177 | /** |
||||
178 | * Calculate the parameters for resizing an image |
||||
179 | * |
||||
180 | * @param int $width Natural width of the image |
||||
181 | * @param int $height Natural height of the image |
||||
182 | * @param array $params Resize parameters |
||||
183 | * - 'maxwidth' maximum width of the resized image |
||||
184 | * - 'maxheight' maximum height of the resized image |
||||
185 | * - 'upscale' allow upscaling |
||||
186 | * - 'square' constrain to a square |
||||
187 | * - 'x1', 'y1', 'x2', 'y2' cropping coordinates |
||||
188 | * |
||||
189 | * @return array|false |
||||
190 | * @since 1.7.2 |
||||
191 | * @deprecated 2.3 |
||||
192 | */ |
||||
193 | function get_image_resize_parameters($width, $height, array $params = []) { |
||||
194 | |||||
195 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated and will be removed from public API', '2.3'); |
||||
196 | |||||
197 | try { |
||||
198 | $params['w'] = elgg_extract('maxwidth', $params); |
||||
199 | $params['h'] = elgg_extract('maxheight', $params); |
||||
200 | unset($params['maxwidth']); |
||||
201 | unset($params['maxheight']); |
||||
202 | $params = _elgg_services()->imageService->normalizeResizeParameters($width, $height, $params); |
||||
203 | return [ |
||||
204 | 'newwidth' => $params['w'], |
||||
205 | 'newheight' => $params['h'], |
||||
206 | 'selectionwidth' => $params['x2'] - $params['x1'], |
||||
207 | 'selectionheight' => $params['y2'] - $params['y1'], |
||||
208 | 'xoffset' => $params['x1'], |
||||
209 | 'yoffset' => $params['y1'], |
||||
210 | ]; |
||||
211 | } catch (\LogicException $ex) { |
||||
212 | elgg_log($ex->getMessage(), 'ERROR'); |
||||
213 | return false; |
||||
214 | } |
||||
215 | } |
||||
216 | |||||
217 | /** |
||||
218 | * Update the last_action column in the entities table for $guid. |
||||
219 | * |
||||
220 | * @warning This is different to time_updated. Time_updated is automatically set, |
||||
221 | * while last_action is only set when explicitly called. |
||||
222 | * |
||||
223 | * @param int $guid Entity annotation|relationship action carried out on |
||||
224 | * @param int $posted Timestamp of last action |
||||
225 | * |
||||
226 | * @return int|false Timestamp or false on failure |
||||
227 | * @access private |
||||
228 | * @deprecated 2.3 |
||||
229 | */ |
||||
230 | function update_entity_last_action($guid, $posted = null) { |
||||
231 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Refrain from updating last action timestamp manually', '2.3'); |
||||
232 | |||||
233 | $result = false; |
||||
234 | $ia = elgg_set_ignore_access(true); |
||||
235 | $entity = get_entity($guid); |
||||
236 | if ($entity) { |
||||
237 | $result = $entity->updateLastAction($posted); |
||||
238 | } |
||||
239 | elgg_set_ignore_access($ia); |
||||
240 | return $result; |
||||
241 | } |
||||
242 | |||||
243 | /** |
||||
244 | * Get the notification settings for a given user. |
||||
245 | * |
||||
246 | * @param int $user_guid The user id |
||||
247 | * |
||||
248 | * @return \stdClass|false |
||||
249 | * @deprecated 2.3 |
||||
250 | */ |
||||
251 | function get_user_notification_settings($user_guid = 0) { |
||||
252 | |||||
253 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated by ElggUser::getNotificationSettings()', '2.3'); |
||||
254 | |||||
255 | if ((int) $user_guid == 0) { |
||||
256 | $user_guid = elgg_get_logged_in_user_guid(); |
||||
257 | } |
||||
258 | |||||
259 | $user = get_entity($user_guid); |
||||
260 | if (!$user instanceof \ElggUser) { |
||||
261 | return false; |
||||
262 | } |
||||
263 | |||||
264 | return (object) $user->getNotificationSettings(); |
||||
265 | } |
||||
266 | |||||
267 | /** |
||||
268 | * Set a user notification pref. |
||||
269 | * |
||||
270 | * @param int $user_guid The user id. |
||||
271 | * @param string $method The delivery method (eg. email) |
||||
272 | * @param bool $value On(true) or off(false). |
||||
273 | * |
||||
274 | * @return bool |
||||
275 | * @deprecated 2.3 |
||||
276 | */ |
||||
277 | function set_user_notification_setting($user_guid, $method, $value) { |
||||
278 | elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated by ElggUser::setNotificationSetting()', '2.3'); |
||||
279 | |||||
280 | if (!$user_guid) { |
||||
281 | $user_guid = elgg_get_logged_in_user_guid(); |
||||
282 | } |
||||
283 | $user = get_entity($user_guid); |
||||
284 | if (!$user instanceof \ElggUser) { |
||||
285 | return false; |
||||
286 | } |
||||
287 | |||||
288 | if (is_string($value)) { |
||||
289 | $value = strtolower($value); |
||||
290 | } |
||||
291 | if ($value == 'yes' || $value == 'on' || $value == 'enabled') { |
||||
292 | $value = true; |
||||
293 | } else if ($value == 'no' || $value == 'off' || $value == 'disabled') { |
||||
294 | $value = false; |
||||
295 | } |
||||
296 | |||||
297 | return $user->setNotificationSetting($method, (bool) $value); |
||||
298 | } |
||||
299 | |||||
300 | /** |
||||
301 | * Serve an error page |
||||
302 | * |
||||
303 | * This is registered by Elgg for the 'forward', '404' plugin hook. It can |
||||
304 | * registered for other hooks by plugins or called directly to display an |
||||
305 | * error page. |
||||
306 | * |
||||
307 | * @param string $hook The name of the hook |
||||
308 | * @param string $type Http error code |
||||
309 | * @param bool $result The current value of the hook |
||||
310 | * @param array $params Parameters related to the hook |
||||
311 | * @return void |
||||
312 | * @deprecated 2.3 |
||||
313 | */ |
||||
314 | function elgg_error_page_handler($hook, $type, $result, $params) { |
||||
315 | elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Error pages are drawn by resource views without "forward" hook.', '2.3'); |
||||
316 | |||||
317 | // This draws an error page, and sometimes there's another 40* forward() call made during that process. |
||||
318 | // We want to allow the 2nd call to pass through, but draw the appropriate page for the first call. |
||||
319 | |||||
320 | static $vars; |
||||
321 | if ($vars === null) { |
||||
322 | // keep first vars for error page |
||||
323 | $vars = [ |
||||
324 | 'type' => $type, |
||||
325 | 'params' => $params, |
||||
326 | ]; |
||||
327 | } |
||||
328 | |||||
329 | static $calls = 0; |
||||
330 | $calls++; |
||||
331 | if ($calls < 3) { |
||||
332 | echo elgg_view_resource('error', $vars); |
||||
333 | exit; |
||||
334 | } |
||||
335 | |||||
336 | // uh oh, may be infinite loop |
||||
337 | register_error(elgg_echo('error:404:content')); |
||||
338 | header('Location: ' . elgg_get_site_url()); |
||||
339 | exit; |
||||
340 | } |
||||
341 | |||||
342 | /** |
||||
343 | * Renders a form field |
||||
344 | * |
||||
345 | * @param string $input_type Input type, used to generate an input view ("input/$input_type") |
||||
346 | * @param array $vars Fields and input vars. |
||||
347 | * Field vars contain both field and input params. 'label', 'help', |
||||
348 | * and 'field_class' params will not be passed on to the input view. |
||||
349 | * Others, including 'required' and 'id', will be available to the |
||||
350 | * input view. Both 'label' and 'help' params accept HTML, and |
||||
351 | * will be printed unescaped within their wrapper element. |
||||
352 | * @return string |
||||
353 | * |
||||
354 | * @since 2.1 |
||||
355 | * @deprecated 2.3 Use elgg_view_field() |
||||
356 | */ |
||||
357 | function elgg_view_input($input_type, array $vars = []) { |
||||
358 | |||||
359 | elgg_deprecated_notice(__FUNCTION__ . '() is deprecated. Use elgg_view_field()', '2.3'); |
||||
360 | |||||
361 | $vars['#type'] = $input_type; |
||||
362 | |||||
363 | if (isset($vars['label']) && $input_type !== 'checkbox') { |
||||
364 | $vars['#label'] = $vars['label']; |
||||
365 | unset($vars['label']); |
||||
366 | } |
||||
367 | if (isset($vars['help'])) { |
||||
368 | $vars['#help'] = $vars['help']; |
||||
369 | unset($vars['help']); |
||||
370 | } |
||||
371 | if (isset($vars['field_class'])) { |
||||
372 | $vars['#class'] = $vars['field_class']; |
||||
373 | unset($vars['field_class']); |
||||
374 | } |
||||
375 | |||||
376 | return elgg_view_field($vars); |
||||
377 | } |
||||
378 | |||||
379 | /** |
||||
380 | * Sanitizes a string for use in a query |
||||
381 | * |
||||
382 | * @see Elgg\Database::sanitizeString |
||||
383 | * |
||||
384 | * @param string $string The string to sanitize |
||||
385 | * @return string |
||||
386 | * @deprecated Use query parameters where possible |
||||
387 | */ |
||||
388 | function sanitize_string($string) { |
||||
389 | return _elgg_services()->db->sanitizeString($string); |
||||
390 | } |
||||
391 | |||||
392 | /** |
||||
393 | * Alias of sanitize_string |
||||
394 | * |
||||
395 | * @see Elgg\Database::sanitizeString |
||||
396 | * |
||||
397 | * @param string $string The string to sanitize |
||||
398 | * @return string |
||||
399 | * @deprecated Use query parameters where possible |
||||
400 | */ |
||||
401 | function sanitise_string($string) { |
||||
402 | return _elgg_services()->db->sanitizeString($string); |
||||
403 | } |
||||
404 | |||||
405 | /** |
||||
406 | * Sanitizes an integer for database use. |
||||
407 | * |
||||
408 | * @see Elgg\Database::sanitizeInt |
||||
409 | * |
||||
410 | * @param int $int Value to be sanitized |
||||
411 | * @param bool $signed Whether negative values should be allowed (true) |
||||
412 | * @return int |
||||
413 | * @deprecated Use query parameters where possible |
||||
414 | */ |
||||
415 | function sanitize_int($int, $signed = true) { |
||||
416 | return _elgg_services()->db->sanitizeInt($int, $signed); |
||||
417 | } |
||||
418 | |||||
419 | /** |
||||
420 | * Alias of sanitize_int |
||||
421 | * |
||||
422 | * @see sanitize_int |
||||
423 | * |
||||
424 | * @param int $int Value to be sanitized |
||||
425 | * @param bool $signed Whether negative values should be allowed (true) |
||||
426 | * @return int |
||||
427 | * @deprecated Use query parameters where possible |
||||
428 | */ |
||||
429 | function sanitise_int($int, $signed = true) { |
||||
430 | return sanitize_int($int, $signed); |
||||
431 | } |
||||
432 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.