hypejunction/notifications_editor

该包已被废弃,不再维护。未建议替代包。

Elgg 通知编辑器

1.0.0 2016-01-30 20:09 UTC

This package is auto-updated.

Last update: 2020-01-29 03:35:02 UTC


README

Elgg 2.0

功能

  • 使用 Mustache 构建的可编辑 HTML 通知模板
  • 模板中灵活使用对象和变量
  • 发送带有自定义模板的即时通知的选项

Interface

订阅通知

插件将自动捕获所有已注册的通知事件(发送订阅通知的事件)。插件将首先尝试定位与通知的主题、摘要和正文相对应的视图,如果找到,则使用模板视图。管理员有权编辑模板,在这种情况下,将创建一个新的模板对象并将其存储在数据库中。

通知视图存储在: /views/default/notifications/$action/$object_type/$object_subtype/$part.$language.html,其中 $action 是触发通知事件的动作,$object_typeobjectgroupusersiteannotationrelationship$object_subtype 是实体子类型、注释名称或关系名称,$partsubjectsummarybody$language 是收件人的语言

自定义(即时)通知

为此,您的交付方法处理程序需要触发 'format','notification' 钩子,并将通知对象作为返回值传递。对于电子邮件交付方法,启用 notifications_html_handler 插件。

// enable templates for notifier
elgg_register_plugin_hook_handler('send', 'notification:notifier', 'notifier_notification_send');
function notifier_notification_send($hook, $type, $result, $params) {
	$notification = $params['notification'];
	$notification = elgg_trigger_plugin_hook('format', 'notification', $params, $notification);

	// continue with logic
}

您可以通过传递带有通知参数的模板名称来使用模板发送即时通知

notify_user($to, $from, '', '', array(
	'template' => 'my_template',
	'my_param' => $param,
));

然后您可以编辑您的模板,并按如下方式引用您的参数

// in notifications/my_template/body.en.html
This is my template with {{params.my_param}}!

要使模板可供管理员编辑,请注册它们

elgg_register_plugin_hook_handler('get_templates', 'notifications', function($h, $t, $r) {
	$r[] = 'my_template';
	return $r;
}

以下是如何使用自定义模板发送通知的示例。

假设我们想通知用户他们的账户已创建

notify_user($recipient->guid, $site->guid, '', '', array(
	'template' => 'useradd',
	'actor' => elgg_get_logged_in_user_entity(),
	'password' => '123456789',
));
// in /views/default/notifications/useradd/body.en.html
Dear {{recipient.name}},

{{#actor}}
	{{actor.name}} has created an account for you at <a href="{{site.getURL}}">{{site.name}}</a>.
{{/actor}}
{{^actor}}
	A use raccount has been created for you at <a href="{{site.getURL}}">{{site.name}}</a>.
{{/actor}}

Your login credentials are as follows:

Username: {{recipient.username}}
Password: {{params.password}}

Once you have logged in, we highly recommend that you change your password.
You can do so in your <a href="{{site.getURL}}settings/user/{{recipient.username}}">account settings</a>.

<a href="{{site.getURL}}login" class="elgg-button">Login</a>

属性

模板中可用的属性

有关三向操作符和循环的信息,请参阅 mustache 参考

在所有通知中可用

<tbody>

	<tr>

		<td>**{{sender.name}}**</td>

		<td>Name of the sender</td>

	</tr>

	<tr>

		<td>**{{sender.getURL}}**</td>

		<td>URL of the sender's profile</td>

	</tr>

	<tr>

		<td>**{{sender.XXX}}**</td>

		<td>Any metadata or method attached to the sender object (e.g. {{sender.language}})</td>

	</tr>

	<tr>

		<td>**{{recipient.name}}**</td>

		<td>Name of the recipient</td>

	</tr>

	<tr>

		<td>**{{recipient.getURL}}**</td>

		<td>URL of the recipients's profile</td>

	</tr>

	<tr>

		<td>**{{recipient.XXX}}**</td>

		<td>Any metadata or method attached to the recipient object (e.g. {{recipient.first_name}})</td>

	</tr>

	<tr>

		<td>**{{language}}**</td>

		<td>Language of the recipient</td>

	</tr>

	<tr>

		<td>**{{site.name}}**</td>

		<td>Name of the site</td>

	</tr>

	<tr>

		<td>**{{site.getURL}}**</td>

		<td>URL of the site (with the trailing slash)</td>

	</tr>

	<tr>

		<td>**{{params.XXX}}**</td>

		<td>Additional params passed to the notification object. The actual available values depend on the notification</td>

	</tr>

</tbody>

在订阅通知中可用

<tbody>

	<tr>

		<td>**{{action}}**</td>

		<td>Action name that triggered the subscription notification event</td>

	</tr>

	<tr>

		<td>**{{actor.name}}**</td>

		<td>Name of the actor (a user performing an action)</td>

	</tr>

	<tr>

		<td>**{{actor.getURL}}**</td>

		<td>URL of the actor's profile</td>

	</tr>

	<tr>

		<td>**{{actor.XXX}}**</td>

		<td>Any metadata or method attached to the actor object (e.g. {{actor.language}})</td>

	</tr>

	<tr>

		<td>**{{object.XXX}}**</td>

		<td>Depending on the event, an object is either an entity, or an annotation, or a relationship. Available properties may vary depending on that.</td>

	</tr>

	<tr>

		<td>**{{target.XXX}}**</td>

		<td>Target of the event: For events that involve Elgg entities, the target is the container entity, e.g. if object is a blog, the target is either a user or group For events that involve annotations, the target is an entity that that annotation is made on For events that involve relationships, the target is an object with subject and object properties, where subject represents the subject of the relationship and object represents the object of the relationship</td>

	</tr>

</tbody>