Elgg  Version master
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 ]);
22 
23 if (!$hmac->matchesToken($hmac_token)) {
24  return elgg_error_response(elgg_echo('actionunauthorized'));
25 }
26 
28  foreach ($muted_settings as $guid => $setting) {
30  if (!$entity instanceof \ElggEntity) {
31  continue;
32  }
33 
34  if ($entity->hasMutedNotifications($recipient_guid) === (bool) $setting) {
35  // no change in status
36  continue;
37  }
38 
39  if ((bool) $setting) {
40  // mute
41  $entity->muteNotifications($recipient_guid);
42  } else {
43  // unmute
44  $entity->unmuteNotifications($recipient_guid);
45  }
46  }
47 });
48 
49 return elgg_ok_response('', elgg_echo('notifications:mute:save:success'), elgg_get_site_url());
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:304
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.
$entity
Definition: mute.php:12
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
$muted_settings
Definition: mute.php:10
$entity_guid
Handle muting notifications about an entity.
Definition: mute.php:6
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
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.
if(empty($entity_guid)||empty($recipient)||empty($muted_settings)||empty($hmac_token)) $hmac
Definition: mute.php:18
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
$hmac_token
Definition: mute.php:11
$recipient_guid
Definition: mute.php:7
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:56
$recipient
Definition: mute.php:8
$guid
Reset an ElggUpgrade.
Definition: reset.php:6