Elgg  Version 6.3
mute.php
Go to the documentation of this file.
1 <?php
6 $entity_guid = (int) get_input('entity_guid');
7 $recipient_guid = (int) get_input('recipient_guid');
9 
10 $muted_settings = (array) get_input('mute', []);
11 $hmac_token = get_input('hmac_token');
12 
13 if (empty($entity_guid) || empty($recipient) || empty($muted_settings) || empty($hmac_token)) {
14  return elgg_error_response(elgg_echo('error:missing_data'));
15 }
16 
17 // hmac to ensure no data was changed between the page and the action
19  'entity_guid' => $entity_guid,
20  'recipient_guid' => $recipient_guid,
21  'mute_guids' => array_keys($muted_settings),
22 ]);
23 
24 if (!$hmac->matchesToken($hmac_token)) {
25  return elgg_error_response(elgg_echo('actionunauthorized'));
26 }
27 
29  foreach ($muted_settings as $guid => $setting) {
31  if (!$entity instanceof \ElggEntity) {
32  continue;
33  }
34 
35  if ($entity->hasMutedNotifications($recipient_guid) === (bool) $setting) {
36  // no change in status
37  continue;
38  }
39 
40  if ((bool) $setting) {
41  // mute
42  $entity->muteNotifications($recipient_guid);
43  } else {
44  // unmute
45  $entity->unmuteNotifications($recipient_guid);
46  }
47  }
48 });
49 
50 return elgg_ok_response('', elgg_echo('notifications:mute:save:success'), elgg_get_site_url());
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
$entity
Definition: mute.php:12
$entity_guid
Handle muting notifications about an entity.
Definition: mute.php:6
$muted_settings
Definition: mute.php:10
$recipient_guid
Definition: mute.php:7
if(empty($entity_guid)||empty($recipient)||empty($muted_settings)||empty($hmac_token)) $hmac
Definition: mute.php:18
$recipient
Definition: mute.php:8
$hmac_token
Definition: mute.php:11
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
Definition: elgglib.php:290
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:68
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:57
elgg_ok_response($content='', string|array $message='', ?string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_error_response(string|array $message='', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.