Skip to content

Commit

Permalink
Releasing notification_messages plugin for Elgg 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Facyla committed Oct 29, 2018
1 parent 759c5d4 commit 9e635af
Show file tree
Hide file tree
Showing 8 changed files with 1,242 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# notification_messages
Notification messages plugin for Elgg
# Notification messages plugin for Elgg

This plugins provides useful subjects for email messages, when new content is created, and replies or comments are made. It uses html_email_handler with object:notifications hook activated, and/or advanced_notifications plugin enabled.

Notes :
* This plugin is inspired by former plugin notification_messages for Elgg 1.6 (discontinued due to API changes)
* Developped after an initial PR on html_email_handler to add a hook to change subject
* (same as notify:entity:message core hook, but for subjects)
* Used hook is implemented in advanced_notifications (by Coldtrick) / and this html_email_handler version
* Also built after careful reading of notification_subjects by Matt Backet (but missing blog support)


HISTORY :
0.3 : 20140326.. - Forum replies and generic_comment support

0.2 : 201403.. - First functionnal version (new objects)

0.1 : 20140317 - Initial version

74 changes: 74 additions & 0 deletions actions/comments/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Elgg add comment action
*
* @package Elgg.Core
* @subpackage Comments
*/

$entity_guid = (int) get_input('entity_guid');
$comment_text = get_input('generic_comment');

if (empty($comment_text)) {
register_error(elgg_echo("generic_comment:blank"));
forward(REFERER);
}

// Let's see if we can get an entity with the specified GUID
$entity = get_entity($entity_guid);
if (!$entity) {
register_error(elgg_echo("generic_comment:notfound"));
forward(REFERER);
}

$user = elgg_get_logged_in_user_entity();

$annotation = create_annotation($entity->guid, 'generic_comment', $comment_text, "", $user->guid, $entity->access_id);

// tell user annotation posted
if (!$annotation) {
register_error(elgg_echo("generic_comment:failure"));
forward(REFERER);
}


// Always notify if poster is not owner
$notify = false;
if ($entity->owner_guid != $user->guid) {
$notify = true;
} else {
$notify = notification_messages_notify_owner();
}


if ($notify) {
// Build more explicit subject
$default_subject = elgg_echo('generic_comment:email:subject');
$subject = notification_messages_build_subject($entity);
if (empty($subject)) { $subject = $default_subject; }
// Build message content (no change compared to core action)
$message = elgg_echo('generic_comment:email:body', array(
$entity->title,
$user->name,
$comment_text,
$entity->getURL(),
$user->name,
$user->getURL(),
));
// Trigger a hook to enable integration with other plugins
$hook_message = elgg_trigger_plugin_hook('notify:annotation:message', 'comment', array('entity' => $entity, 'to_entity' => $user), $message);
// Failsafe backup if hook as returned empty content but not false (= stop)
if (!empty($hook_message) && ($hook_message !== false)) { $message = $hook_message; }

// Send notifications
notify_user($entity->owner_guid, $user->guid, $subject, $message);
}

system_message(elgg_echo("generic_comment:posted"));

//add to river
add_to_river('river/annotation/generic_comment/create', 'comment', $user->guid, $entity->guid, "", 0, $annotation);

// Forward to the page the action occurred on
forward(REFERER);

50 changes: 50 additions & 0 deletions actions/messages/send.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Send a message action
*
* @package ElggMessages
*/

$subject = strip_tags(get_input('subject'));
$body = get_input('body');
$recipient_guid = get_input('recipient_guid');
$sender_guid = get_input('sender_guid', false);
if (!$sender_guid) { $sender_guid = elgg_get_logged_in_user_guid(); }

elgg_make_sticky_form('messages');

//$reply = get_input('reply',0); // this is the guid of the message replying to

if (!$recipient_guid) {
register_error(elgg_echo("messages:user:blank"));
forward("messages/compose");
}

$user = get_user($recipient_guid);
if (!$user) {
register_error(elgg_echo("messages:user:nonexist"));
forward("messages/compose");
}

// Make sure the message field, send to field and title are not blank
if (!$body || !$subject) {
register_error(elgg_echo("messages:blank"));
forward("messages/compose");
}

// Otherwise, 'send' the message
//$result = messages_send($subject, $body, $recipient_guid, 0, $reply);
$result = notification_messages_send($subject, $body, $recipient_guid, $sender_guid, $reply);

// Save 'send' the message
if (!$result) {
register_error(elgg_echo("messages:error"));
forward("messages/compose");
}

elgg_clear_sticky_form('messages');

system_message(elgg_echo("messages:posted"));

forward('messages/inbox/' . elgg_get_logged_in_user_entity()->username);

58 changes: 58 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/** Elgg notification_messages plugin language
* @author Florian DANIEL - Facyla
* @copyright Florian DANIEL - Facyla 2014
* @link http://id.facyla.net/
*/

$english = array(

'notification_messages' => "Notification messages",

// Actions
'notification_messages:create' => "has published",
'notification_messages:delete' => "has deleted",
'notification_messages:update' => "has updated",

// Settings
'notification_messages:settings:objects' => "Subject for new content (registered objects)",
'notification_messages:settings:details' => "By activating detailed notification messages for each of these content types, you can replace the default mail title by a more meaningful subject, composed in this form: [Publication type Group or member name] Content title<br />This facilitates the identification of conversations by email clients.",
'notification_messages:object:subtype' => "Object type",
'notification_messages:setting' => "Setting",
'notification_messages:subject:default' => "Default subject",
'notification_messages:subject:allow' => "Improved subject",
'notification_messages:subject:deny' => "Blocked (no notification at all)",
'notification_messages:message:default' => "Default message",
'notification_messages:message:allow' => "Improved message",
'notification_messages:settings:group_topic_post' => "Enable for group topic replies",
'notification_messages:settings:comments' => "Subject for comments",
'notification_messages:settings:messages' => "Messages",
'notification_messages:settings:comments:details' => "If you have enabled this plugin, you probably wish to enable this setting, so all comments will use the same subject as the new content.",
'notification_messages:settings:generic_comment' => "Enable for all generic comments",
'notification_messages:settings:notify_user' => "Notify also comment author ?",
'notification_messages:settings:notify_user:details' => "By default, the comment author is not notified. You can change thios behaviour, which can be particularly useful when using email reply.",
'notification_messages:settings:notify_user:comment_tracker' => "When comment_tracker plugin is enabled, this setting is not available and should be set directly in comment_tracker plugin settings.",
'notification_messages:settings:expert' => "Expert",

// Notification message content
'notification_messages:settings:objects:message' => "Notification messages content",
'notification_messages:message:default:blog' => "By default, blog notification messages contains only the extract.",

// Notification subject
'notification_messages:objects:subject' => "[%s | %s] %s",
'notification_messages:objects:subject:nocontainer' => "[%s] %s",
'notification_messages:untitled' => "(untitled)",
// Messages
'notification_messages:email:subject' => "[%s] Message from %s : %s",

// Object:notifications hook control
'notification_messages:settings:object_notifications_hook' => "Enable the hook on object:notifications",
'notification_messages:settings:object_notifications_hook:subtext' => "This hook lets other plugins easily add attachments and other parameters to notify_user, and therefor to emails, the same way messages can be changed. Caution because the use of this hook can break other notification plugins processes -at least advanced_notifications- because it handles the sending process, and replies \"true\" to the hook, which blocks the process when the hook is triggered.<br />If you don't know what to choose, leave on default.",

'notification_messages:settings:messages_send' => "Use HTML in direct messages",
'notification_messages:settings:messages_send:subtext' => "By default, direct messages sent by the platform via email are using plain text. This setting doesn't strip HTML tags before sending direct messages by email",

);

add_translation("en", $english);

59 changes: 59 additions & 0 deletions languages/fr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/** Elgg notification_messages plugin language
* @author Florian DANIEL - Facyla
* @copyright Florian DANIEL - Facyla 2014
* @link http://id.facyla.net/
*/

$french = array(

'notification_messages' => "Message de notification",

// Actions
'notification_messages:create' => "a publié",
'notification_messages:delete' => "a supprimé",
'notification_messages:update' => "a mis à jour",

// Settings
'notification_messages:settings:objects' => "Sujet des nouvelles publications (objets)",
'notification_messages:settings:details' => "En activant les messages de notification détaillés pour chacun des types de contenus suivants, vous pouvez remplacer le titre du mail par défaut par un titre explicite composé sous la forme : [Type de publication Nom du groupe ou du membre] Titre du contenu<br />Cette forme facilite également l'identification de conversations par les messageries.",
'notification_messages:object:subtype' => "Type d'objet",
'notification_messages:setting' => "Réglage",
'notification_messages:subject:default' => "Sujet par défaut",
'notification_messages:subject:allow' => "Sujet amélioré",
'notification_messages:subject:deny' => "Bloqué (pas de notification)",
'notification_messages:message:default' => "Message par défaut",
'notification_messages:message:allow' => "Message amélioré",
'notification_messages:settings:group_topic_post' => "Activer pour les réponses dans les forums",
'notification_messages:settings:comments' => "Sujet des commentaires",
'notification_messages:settings:messages' => "Messages",
'notification_messages:settings:comments:details' => "Si vous avez activé ce plugin, vous souhaitez probablement activer ce réglage, de manière à utiliser le même titre pour les commentaires que pour les nouvelles publications.",
'notification_messages:settings:generic_comment' => "Activer pour les commentaires génériques",
'notification_messages:settings:notify_user' => "Notifier également l'auteur des commentaires ?",
'notification_messages:settings:notify_user:details' => "Par défaut l'auteur d'un commentaire n'est pas notifié. Vous pouvez choisir de le notifier également, ce qui est particulièrement utile si vous utilisez des réponses par email.",
'notification_messages:settings:notify_user:comment_tracker' => "Lorsque le plugin comment_tracker est utilisé, un réglage identique est proposé, ce réglage n'est pas disponible et doit être modifié directement dans la configuration de comment_tracker.",
'notification_messages:settings:expert' => "Expert",

// Notification message content
'notification_messages:settings:objects:message' => "Contenu des messages de notification",
'notification_messages:message:default:blog' => "Par défaut les messages de notification des blogs ne contiennent que l'extrait.",

// Notification subject
'notification_messages:objects:subject' => "[%s | %s] %s",
'notification_messages:objects:subject:nocontainer' => "[%s] %s",
'notification_messages:untitled' => "(sans titre)",
// Messages
'notification_messages:email:subject' => "[%s] Message de %s : %s",


// Object:notifications hook control
'notification_messages:settings:object_notifications_hook' => "Activer le hook sur object:notifications",
'notification_messages:settings:object_notifications_hook:subtext' => "Ce hook permet à d'autres plugins d'ajouter facilement des pièces jointes aux emails envoyés, de la même manière qu'ils peuvent modifier le contenu des messages. Attention car il peut causer des problèmes de compatibilité dans certains cas, en bloquant l'utilisation du hook par d'autres plugins -notamment advanced_notifications- car il prend en charge le processus d'envoi et répond donc \"true\" au hook.<br />Si vous ne savez pas quoi faire, laissez le réglage par défaut.",

'notification_messages:settings:messages_send' => "Envoyer les messages directs en HTML",
'notification_messages:settings:messages_send:subtext' => "Par défaut, les messages direct envoyés par la messagerie interne sont envoyés par email en texte seulement. Ce réglage permet de conserver la mise en forme HTML de ces messages.",

);

add_translation("fr", $french);

40 changes: 40 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
<name>Notification messages : meaningful emails</name>
<author>Florian DANIEL</author>
<version>0.3</version>
<blurb>Replaces default notifications subjects by meaningful ones</blurb>
<description>This plugins provides useful subjects for email messages, when new content is created, and replies or comments are made. It uses html_email_handler with object:notifications hook activated, and/or advanced_notifications plugin enabled.</description>
<website>https://facyla.fr/</website>
<copyright>(C) Florian DANIEL aka Facyla 2014</copyright>
<license>GNU Public License version 2</license>

<requires>
<type>elgg_release</type>
<version>1.8.14</version>
</requires>

<suggests>
<type>plugin</type>
<name>html_email_handler</name>
</suggests>

<requires>
<type>priority</type>
<priority>after</priority>
<plugin>comment_tracker</plugin>
</requires>

<conflicts>
<type>plugin</type>
<name>notification_subjects</name>
</conflicts>

<category>email</category>
<category>notification</category>

<activate_on_install>false</activate_on_install>

</plugin_manifest>


Loading

0 comments on commit 9e635af

Please sign in to comment.