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