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' => 'switch',
39  '#label' => elgg_echo($get_language_key($commented_entity, 'entity'), [$commented_entity->getDisplayName()]),
40  'name' => "mute[{$commented_entity->guid}]",
41  'value' => $commented_entity->hasMutedNotifications($recipient->guid),
42  ]);
43 } elseif (!elgg_is_empty($entity->getDisplayName())) {
44  $mute_guids[] = $entity->guid;
45 
47  '#type' => 'switch',
48  '#label' => elgg_echo($get_language_key($entity, 'entity'), [$entity->getDisplayName()]),
49  'name' => "mute[{$entity->guid}]",
50  'value' => $entity->hasMutedNotifications($recipient->guid),
51  ]);
52 }
53 
54 $container = ($entity instanceof ElggComment) ? $entity->getContainerEntity()->getContainerEntity() : $entity->getContainerEntity();
55 if (($container instanceof \ElggGroup || $container instanceof \ElggUser) && !in_array($container->guid, $mute_guids)) {
56  $mute_guids[] = $container->guid;
57 
59  '#type' => 'switch',
60  '#label' => elgg_echo($get_language_key($container, 'container'), [$container->getDisplayName()]),
61  'name' => "mute[{$container->guid}]",
62  'value' => $container->hasMutedNotifications($recipient->guid),
63  ]);
64 }
65 
66 $owner = $entity->getOwnerEntity();
67 if (($owner instanceof \ElggGroup || $owner instanceof \ElggUser) && !in_array($owner->guid, $mute_guids)) {
68  $mute_guids[] = $owner->guid;
69 
71  '#type' => 'switch',
72  '#label' => elgg_echo($get_language_key($owner, 'owner'), [$owner->getDisplayName()]),
73  'name' => "mute[{$owner->guid}]",
74  'value' => $owner->hasMutedNotifications($recipient->guid),
75  ]);
76 }
77 
79 if (($actor instanceof \ElggGroup || $actor instanceof \ElggUser) && !in_array($actor->guid, $mute_guids)) {
80  $mute_guids[] = $actor->guid;
81 
83  '#type' => 'switch',
84  '#label' => elgg_echo($get_language_key($actor, 'actor'), [$actor->getDisplayName()]),
85  'name' => "mute[{$actor->guid}]",
86  'value' => $actor->hasMutedNotifications($recipient->guid),
87  ]);
88 }
89 
90 if (empty($checkboxes)) {
91  // no content to show
92  return;
93 }
94 
95 echo elgg_view_field([
96  '#type' => 'hidden',
97  'name' => 'entity_guid',
98  'value' => $entity->guid,
99 ]);
100 
101 echo elgg_view_field([
102  '#type' => 'hidden',
103  'name' => 'recipient_guid',
104  'value' => $recipient->guid,
105 ]);
106 
107 // protect form from manipulation between requests
109  'entity_guid' => $entity->guid,
110  'recipient_guid' => $recipient->guid,
111 ]);
112 echo elgg_view_field([
113  '#type' => 'hidden',
114  'name' => 'hmac_token',
115  'value' => $hmac->getToken(),
116 ]);
117 
118 echo elgg_view('output/longtext', [
119  'value' => elgg_echo('notifications:mute:description'),
120 ]);
121 
122 echo $checkboxes;
123 
125  '#type' => 'submit',
126  'text' => elgg_echo('save'),
127 ]);
128 
$footer
Definition: mute.php:124
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:66
$checkboxes
Definition: mute.php:30
getOwnerEntity()
Gets the that owns this entity.
Definition: ElggEntity.php:522
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:78
$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:41
$vars
Definition: theme.php:5
getContainerEntity()
Get the container entity for this object.
Definition: ElggEntity.php:552
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:54
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306