Elgg  Version 3.0
deprecated-2.3.php
Go to the documentation of this file.
1 <?php
2 
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;
59 }
60 
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 
85  elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated and will be removed', '2.3');
87  $input = array_shift($inputs);
88  if (!$input || !$input->isValid()) {
89  return false;
90  }
91  return file_get_contents($input->getPathname());
92 }
93 
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 
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 
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 
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);
236  if ($entity) {
237  $result = $entity->updateLastAction($posted);
238  }
240  return $result;
241 }
242 
252 
253  elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated by ElggUser::getNotificationSettings()', '2.3');
254 
255  if ((int) $user_guid == 0) {
257  }
258 
260  if (!$user instanceof \ElggUser) {
261  return false;
262  }
263 
264  return (object) $user->getNotificationSettings();
265 }
266 
278  elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated by ElggUser::setNotificationSetting()', '2.3');
279 
280  if (!$user_guid) {
282  }
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 
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 
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 
388 function sanitize_string($string) {
389  return _elgg_services()->db->sanitizeString($string);
390 }
391 
401 function sanitise_string($string) {
402  return _elgg_services()->db->sanitizeString($string);
403 }
404 
415 function sanitize_int($int, $signed = true) {
416  return _elgg_services()->db->sanitizeInt($int, $signed);
417 }
418 
429 function sanitise_int($int, $signed = true) {
430  return sanitize_int($int, $signed);
431 }
ajax_forward_hook($hook, $type, $forward_url, $params)
Catch calls to forward() in ajax request and force an exit.
if(!$entity->delete()) $forward_url
Definition: delete.php:30
if(!array_key_exists($filename, $text_files)) $file
$params
Saves global plugin settings.
Definition: save.php:13
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1395
elgg_view_resource($name, array $vars=[])
Render a resource view.
Definition: views.php:423
get_image_resize_parameters($width, $height, array $params=[])
Calculate the parameters for resizing an image.
const ELGG_HTTP_OK
Definition: constants.php:60
elgg_error_page_handler($hook, $type, $result, $params)
Serve an error page.
sanitize_int($int, $signed=true)
Sanitizes an integer for database use.
$guid
Removes an admin notice.
$type
Definition: delete.php:21
catch(LoginException $e) if($request->isXhr()) $output
Definition: login.php:56
elgg_get_uploaded_files($input_name)
Returns an array of uploaded file objects regardless of upload status/errors.
Definition: filestore.php:384
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square=false, $x1=0, $y1=0, $x2=0, $y2=0, $upscale=false)
Gets the jpeg contents of the resized version of an already uploaded image (Returns false if the file...
$user_guid
Validate a user.
Definition: validate.php:6
get_uploaded_file($input_name)
Get the contents of an uploaded file.
$input_type
Helper view that can be used to filter vars for all input views.
Definition: input.php:6
sanitize_string($string)
Sanitizes a string for use in a query.
if(!$entity instanceof ElggEntity) $input_name
Definition: default.php:14
$entity
Definition: reset.php:8
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:52
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:786
$user
Definition: ban.php:7
elgg echo
Translates a string.
Definition: languages.js:43
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:841
get_user_notification_settings($user_guid=0)
Get the notification settings for a given user.
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
sanitise_string($string)
Alias of sanitize_string.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
update_entity_last_action($guid, $posted=null)
Update the last_action column in the entities table for $guid.
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
$posted
Definition: comment.php:64
get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square=false, $upscale=false)
Gets the jpeg contents of the resized version of an uploaded image (Returns false if the uploaded fil...
$value
Definition: debugging.php:7
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:391
$input
Form field view.
Definition: field.php:13
$vars['type']
Definition: save.php:11
elgg_save_resized_image($source, $destination=null, array $params=[])
Crops and resizes an image.
Definition: filestore.php:66
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
sanitise_int($int, $signed=true)
Alias of sanitize_int.
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:127
elgg_view_input($input_type, array $vars=[])
Renders a form field.
set_user_notification_setting($user_guid, $method, $value)
Set a user notification pref.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:39
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87
ajax_action_hook()
Buffer all output echo&#39;d directly in the action for inclusion in the returned JSON.