コード例 #1
0
/**
 * 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;
}
コード例 #2
0
<?php

elgg_admin_gatekeeper();
elgg_push_breadcrumb(elgg_echo('notifications'), '/notifications');
elgg_push_breadcrumb(elgg_echo('notifications:editor'), '/notifications/editor');
elgg_push_breadcrumb(elgg_echo('notifications:editor:edit'));
$template = get_input('template');
$language = get_input('language');
if (!$template || !$language) {
    forward('', '400');
}
$form = 'notifications/editor/edit';
if (elgg_is_sticky_form($form)) {
    $sticky = elgg_get_sticky_values($form);
    if (is_array($sticky)) {
        $vars = array_merge($vars, $sticky);
    }
    elgg_clear_sticky_form($form);
}
$languages = get_installed_translations();
$vars['template'] = $template;
$vars['language'] = $language;
$vars['entity'] = notifications_editor_get_template_entity($template, $language);
$title = $vars['entity']->getDisplayName();
$form = elgg_view_form($form, array(), $vars);
$content = elgg_view_module('info', $string, $form);
$layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'filter' => false));
echo elgg_view_page($title, $layout);