Elgg  Version master
mute.php
Go to the documentation of this file.
1 <?php
10 $entity = elgg_extract('entity', $vars);
11 $recipient = elgg_extract('recipient', $vars);
12 if (!$entity instanceof \ElggEntity || !$recipient instanceof \ElggUser) {
13  return;
14 }
15 
16 $get_language_key = function(\ElggEntity $entity, string $default_postfix) {
17  $keys = [
18  "notifications:mute:{$entity->type}:{$entity->subtype}",
19  "notifications:mute:{$entity->type}",
20  "notifications:mute:{$default_postfix}",
21  ];
22 
23  foreach ($keys as $key) {
24  if (elgg_language_key_exists($key)) {
25  return $key;
26  }
27  }
28 };
29 
32 
33 if ($entity instanceof \ElggComment) {
34  $commented_entity = $entity->getContainerEntity();
35  $mute_guids[] = $commented_entity->guid;
36 
38  '#type' => 'checkbox',
39  '#label' => elgg_echo($get_language_key($commented_entity, 'entity'), [$commented_entity->getDisplayName()]),
40  'name' => "mute[{$commented_entity->guid}]",
41  'value' => 1,
42  'switch' => true,
43  'checked' => $commented_entity->hasMutedNotifications($recipient->guid),
44  ]);
45 } elseif (!elgg_is_empty($entity->getDisplayName())) {
46  $mute_guids[] = $entity->guid;
47 
49  '#type' => 'checkbox',
50  '#label' => elgg_echo($get_language_key($entity, 'entity'), [$entity->getDisplayName()]),
51  'name' => "mute[{$entity->guid}]",
52  'value' => 1,
53  'switch' => true,
54  'checked' => $entity->hasMutedNotifications($recipient->guid),
55  ]);
56 }
57 
58 $container = ($entity instanceof ElggComment) ? $entity->getContainerEntity()->getContainerEntity() : $entity->getContainerEntity();
59 if (($container instanceof \ElggGroup || $container instanceof \ElggUser) && !in_array($container->guid, $mute_guids)) {
60  $mute_guids[] = $container->guid;
61 
63  '#type' => 'checkbox',
64  '#label' => elgg_echo($get_language_key($container, 'container'), [$container->getDisplayName()]),
65  'name' => "mute[{$container->guid}]",
66  'value' => 1,
67  'switch' => true,
68  'checked' => $container->hasMutedNotifications($recipient->guid),
69  ]);
70 }
71 
72 $owner = $entity->getOwnerEntity();
73 if (($owner instanceof \ElggGroup || $owner instanceof \ElggUser) && !in_array($owner->guid, $mute_guids)) {
74  $mute_guids[] = $owner->guid;
75 
77  '#type' => 'checkbox',
78  '#label' => elgg_echo($get_language_key($owner, 'owner'), [$owner->getDisplayName()]),
79  'name' => "mute[{$owner->guid}]",
80  'value' => 1,
81  'switch' => true,
82  'checked' => $owner->hasMutedNotifications($recipient->guid),
83  ]);
84 }
85 
87 if (($actor instanceof \ElggGroup || $actor instanceof \ElggUser) && !in_array($actor->guid, $mute_guids)) {
88  $mute_guids[] = $actor->guid;
89 
91  '#type' => 'checkbox',
92  '#label' => elgg_echo($get_language_key($actor, 'actor'), [$actor->getDisplayName()]),
93  'name' => "mute[{$actor->guid}]",
94  'value' => 1,
95  'switch' => true,
96  'checked' => $actor->hasMutedNotifications($recipient->guid),
97  ]);
98 }
99 
100 if (empty($checkboxes)) {
101  // no content to show
102  return;
103 }
104 
105 echo elgg_view_field([
106  '#type' => 'hidden',
107  'name' => 'entity_guid',
108  'value' => $entity->guid,
109 ]);
110 
111 echo elgg_view_field([
112  '#type' => 'hidden',
113  'name' => 'recipient_guid',
114  'value' => $recipient->guid,
115 ]);
116 
117 // protect form from manipulation between requests
119  'entity_guid' => $entity->guid,
120  'recipient_guid' => $recipient->guid,
121 ]);
122 echo elgg_view_field([
123  '#type' => 'hidden',
124  'name' => 'hmac_token',
125  'value' => $hmac->getToken(),
126 ]);
127 
128 echo elgg_view('output/longtext', [
129  'value' => elgg_echo('notifications:mute:description'),
130 ]);
131 
132 echo $checkboxes;
133 
135  '#type' => 'submit',
136  'text' => elgg_echo('save'),
137 ]);
138 
$footer
Definition: mute.php:134
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1112
if(($container instanceof\ElggGroup||$container instanceof\ElggUser)&&!in_array($container->guid, $mute_guids)) $owner
Definition: mute.php:72
$checkboxes
Definition: mute.php:30
getOwnerEntity()
Gets the that owns this entity.
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:86
$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
$keys
Definition: access.php:31
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
elgg_set_form_footer(string $footer= '')
Sets form footer and defers its rendering until the form view and extensions have been rendered...
Definition: views.php:1046
if(empty($entity_guid)||empty($recipient)||empty($muted_settings)||empty($hmac_token)) $hmac
Definition: mute.php:18
$mute_guids
Definition: mute.php:31
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if(!$entity instanceof\ElggEntity||!$recipient instanceof\ElggUser) $get_language_key
Definition: mute.php:16
getDisplayName()
{}
Definition: ElggObject.php:38
$vars
Definition: theme.php:5
getContainerEntity()
Get the container entity for this object.
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:56
$recipient
Definition: mute.php:8
if($entity instanceof\ElggComment) elseif(!elgg_is_empty($entity->getDisplayName())) $container
Definition: mute.php:58
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:314