Elgg  Version master
mute.php
Go to the documentation of this file.
1 <?php
6 $entity_guid = (int) get_input('guid');
8 
9 $forward_url = get_input('forward_url');
10 $show_success = (bool) get_input('show_success', true);
11 
13 if (!$entity instanceof \ElggEntity) {
14  return elgg_error_response(elgg_echo('error:missing_data'));
15 }
16 
18 if (!$user instanceof \ElggUser || !$user->canEdit()) {
19  return elgg_error_response(elgg_echo('actionunauthorized'));
20 }
21 
22 $display_name = $entity->getDisplayName() ?: elgg_echo('item');
23 
24 if (!$entity->muteNotifications($user->guid)) {
25  return elgg_error_response(elgg_echo('entity:mute:fail', [$display_name]));
26 }
27 
29  "entity:mute:{$entity->type}:{$entity->subtype}:success",
30  "entity:mute:{$entity->type}:success",
31  'entity:mute:success',
32 ];
33 
34 $message = '';
35 if ($show_success) {
36  foreach ($success_keys as $success_key) {
37  if (elgg_language_key_exists($success_key)) {
38  $message = elgg_echo($success_key, [$display_name]);
39  break;
40  }
41  }
42 }
43 
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
$show_success
Definition: mute.php:10
if(!$entity->muteNotifications($user->guid)) $success_keys
Definition: mute.php:28
$forward_url
Definition: mute.php:9
if(!$user instanceof\ElggUser||!$user->canEdit()) $display_name
Definition: mute.php:22
canEdit(int $user_guid=0)
Can a user edit this entity?
Definition: ElggEntity.php:397
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
$entity_guid
Handle muting notifications about an entity.
Definition: mute.php:6
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
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.
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
$message
Definition: mute.php:34
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
if(!$entity instanceof\ElggEntity) $user
Definition: mute.php:17
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34
$user_guid
Definition: mute.php:7