/** * Get the subscribers for a new group which needs admin approval * * @param string $hook the name of the hook * @param string $type the type of the hook * @param \Elgg\Notifications\Notification $return_value current return value * @param array $params supplied params * * @return void|\Elgg\Notifications\Notification */ public static function prepareAdminApprovalMessage($hook, $type, $return_value, $params) { if (!$return_value instanceof \Elgg\Notifications\Notification) { return; } $actor = $return_value->getSender(); $recipient = $return_value->getRecipient(); $language = elgg_extract('language', $params); $event = elgg_extract('event', $params); if (!$event instanceof \Elgg\Notifications\Event) { return; } $group = $event->getObject(); if (!$group instanceof \ElggGroup) { return; } $return_value->subject = elgg_echo('group_tools:group:admin_approve:admin:subject', [$group->name], $language); $return_value->summary = elgg_echo('group_tools:group:admin_approve:admin:summary', [$group->name], $language); $return_value->body = elgg_echo('group_tools:group:admin_approve:admin:message', [$recipient->name, $actor->name, $group->name, $group->getURL(), elgg_normalize_url('admin/groups/admin_approval')], $language); return $return_value; }
/** * Make the tag tools notification * * @param string $hook the name of the hook * @param string $type the type of the hook * @param \Elgg\Notifications\Notification $return_value current return value * @param array $params supplied params * * @return void|\Elgg\Notifications\Notification */ public static function prepareMessage($hook, $type, $return_value, $params) { if (!self::validateNotificationEvent($params)) { return; } $recipient = $return_value->getRecipient(); $method = elgg_extract('method', $params); $relationship = elgg_extract('object', $params); $language = elgg_extract('language', $params); $entity = get_entity($relationship->guid_two); $sending_tags = tag_tools_get_unsent_tags($entity); $tag = []; foreach ($sending_tags as $sending_tag) { if (!tag_tools_is_user_following_tag($sending_tag, $recipient->getGUID())) { // user is not following this tag continue; } if (!tag_tools_check_user_tag_notification_method($sending_tag, $method, $recipient->getGUID())) { continue; } $tag[] = $sending_tag; } $tag = implode(', ', $tag); // is this a new entity of an update on an existing $time_diff = (int) $entity->time_updated - (int) $entity->time_created; if ($time_diff < 60) { // new entity $return_value->subject = elgg_echo('tag_tools:notification:follow:subject', [$tag], $language); $return_value->summary = elgg_echo('tag_tools:notification:follow:summary', [$tag], $language); $return_value->body = elgg_echo('tag_tools:notification:follow:message', [$tag, $entity->getURL()], $language); } else { // updated entity $return_value->subject = elgg_echo('tag_tools:notification:follow:update:subject', [$tag], $language); $return_value->summary = elgg_echo('tag_tools:notification:follow:update:summary', [$tag], $language); $return_value->body = elgg_echo('tag_tools:notification:follow:update:message', [$tag, $entity->getURL()], $language); } return $return_value; }
/** * Get the notification body using a pre-Elgg 1.9 plugin hook * * @param \Elgg\Notifications\Notification $notification Notification * @param \Elgg\Notifications\Event $event Event * @param string $method Method * @return \Elgg\Notifications\Notification */ protected function getDeprecatedNotificationBody(\Elgg\Notifications\Notification $notification, \Elgg\Notifications\Event $event, $method) { $entity = $event->getObject(); $params = array('entity' => $entity, 'to_entity' => $notification->getRecipient(), 'method' => $method); $subject = $this->getDeprecatedNotificationSubject($entity->getType(), $entity->getSubtype()); $string = $subject . ": " . $entity->getURL(); $body = $this->hooks->trigger('notify:entity:message', $entity->getType(), $params, $string); if ($subject) { $notification->subject = $subject; $notification->body = $body; } return $notification; }
/** * Formats notifications that have defined template * * @param string $hook "format" * @param string $type "notification" * @param \Elgg\Notifications\Notification $notification Notification * @param array $params Hook params * @return \Elgg\Notifications\Notification */ function notifications_editor_format_notification($hook, $type, $notification, $params) { $language = $notification->language; if (empty($notification->params['template'])) { return; } $template = notifications_editor_get_template_entity($notification->params['template'], $language); if (!$template) { return; } $event = elgg_extract('event', $params); if ($event instanceof \Elgg\Notifications\Event) { $action = $event->getAction(); $actor = $event->getActor(); $object = $event->getObject(); if ($object instanceof ElggEntity) { $target = $object->getContainerEntity(); } else { if ($object instanceof ElggRelationship) { $target = array('subject' => get_entity($object->guid_one), 'object' => get_entity($object->guid_two)); } else { if ($object instanceof ElggAnnotation) { $target = $object->getEntity(); } } } } $template_params = array('action' => $action, 'actor' => $actor, 'object' => $object, 'target' => $target, 'recipient' => $notification->getRecipient(), 'sender' => $notification->getSender(), 'language' => $language, 'site' => elgg_get_site_entity(), 'params' => $notification->params); elgg_push_context('widgets'); if ($template->subject) { $notification->subject = mustache()->render($template->subject, $template_params); } if ($template->body) { $notification->body = mustache()->render($template->body, $template_params); } if ($template->summary) { $notification->summary = mustache()->render($template->summary, $template_params); } elgg_pop_context(); return $notification; }