Elgg  Version 4.3
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_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:46
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
$entity
Definition: mute.php:12
$show_success
Definition: mute.php:10
if(!$entity->muteNotifications($user->guid)) $success_keys
Definition: mute.php:28
canEdit($user_guid=0)
Can a user edit this entity?
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$forward_url
Definition: mute.php:9
if(!$user instanceof\ElggUser||!$user->canEdit()) $display_name
Definition: mute.php:22
$entity_guid
Handle muting notifications about an entity.
Definition: mute.php:6
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
$message
Definition: mute.php:34
if(!$entity instanceof\ElggEntity) $user
Definition: mute.php:17
elgg_error_response($message= '', $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_ok_response($content= '', $message= '', $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34
$user_guid
Definition: mute.php:7
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69