From 8e1528fa4cb5cabf250536ab10592e37256e17b7 Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis
Date: Wed, 7 Dec 2022 23:01:33 +0100
Subject: [PATCH] first commit from emailNotification 1.1
---
_admin.php | 18 +++++
_define.php | 27 ++++++++
_prepend.php | 14 ++++
_public.php | 14 ++++
behaviors.php | 153 ++++++++++++++++++++++++++++++++++++++++++
locales/_pot/main.pot | 76 +++++++++++++++++++++
locales/fr/main.po | 66 ++++++++++++++++++
7 files changed, 368 insertions(+)
create mode 100644 _admin.php
create mode 100644 _define.php
create mode 100644 _prepend.php
create mode 100644 _public.php
create mode 100644 behaviors.php
create mode 100644 locales/_pot/main.pot
create mode 100644 locales/fr/main.po
diff --git a/_admin.php b/_admin.php
new file mode 100644
index 0000000..19fa149
--- /dev/null
+++ b/_admin.php
@@ -0,0 +1,18 @@
+addBehavior('adminPreferencesForm',array('notificationBehaviors','adminUserForm'));
+$core->addBehavior('adminUserForm',array('notificationBehaviors','adminUserForm')); // user.php
+
+$core->addBehavior('adminBeforeUserUpdate',array('notificationBehaviors','adminBeforeUserUpdate'));
+$core->addBehavior('adminBeforeUserOptionsUpdate',array('notificationBehaviors','adminBeforeUserUpdate')); //preferences.php
diff --git a/_define.php b/_define.php
new file mode 100644
index 0000000..e152c55
--- /dev/null
+++ b/_define.php
@@ -0,0 +1,27 @@
+registerModule(
+ /* Name */ "Email notification",
+ /* Description*/ "Email notification",
+ /* Author */ "Olivier Meunier",
+ /* Version */ '1.1',
+ /* Properties */
+ array(
+ 'permissions' => 'usage,contentadmin',
+ 'type' => 'plugin',
+ 'dc_min' => '2.6',
+ 'support' => 'http://forum.dotclear.org/viewforum.php?id=16',
+ 'details' => 'http://plugins.dotaddict.org/dc2/details/emailNotification'
+ )
+);
diff --git a/_prepend.php b/_prepend.php
new file mode 100644
index 0000000..6b90bbe
--- /dev/null
+++ b/_prepend.php
@@ -0,0 +1,14 @@
+addBehavior('publicAfterCommentCreate',array('notificationBehaviors','publicAfterCommentCreate'));
diff --git a/behaviors.php b/behaviors.php
new file mode 100644
index 0000000..1b5a86c
--- /dev/null
+++ b/behaviors.php
@@ -0,0 +1,153 @@
+ '0',
+ __('My entries') => 'mine',
+ __('All entries') => 'all'
+ );
+
+ echo
+ ''.__('Email notification').'
'.
+ '
'.
+ '
';
+ }
+
+ public static function adminBeforeUserUpdate($cur,$user_id='')
+ {
+ $cur->user_options['notify_comments'] = $_POST['notify_comments'];
+ }
+
+ public static function publicAfterCommentCreate($cur,$comment_id)
+ {
+ # We don't want notification for spam
+ if ($cur->comment_status == -2) {
+ return;
+ }
+
+ global $core;
+
+ # Information on comment author and post author
+ $rs = $core->auth->sudo(array($core->blog,'getComments'), array('comment_id'=>$comment_id));
+
+ if ($rs->isEmpty()) {
+ return;
+ }
+
+ # Information on blog users
+ $strReq =
+ 'SELECT U.user_id, user_email, user_options '.
+ 'FROM '.$core->blog->prefix.'user U JOIN '.$core->blog->prefix.'permissions P ON U.user_id = P.user_id '.
+ "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
+ 'UNION '.
+ 'SELECT user_id, user_email, user_options '.
+ 'FROM '.$core->blog->prefix.'user '.
+ 'WHERE user_super = 1 ';
+
+ $users = $core->con->select($strReq);
+
+ # Create notify list
+ $ulist = array();
+ while ($users->fetch()) {
+ if (!$users->user_email) {
+ continue;
+ }
+
+ $notification_pref = self::notificationPref(rsExtUser::options($users));
+
+ if ($notification_pref == 'all'
+ || ($notification_pref == 'mine' && $users->user_id == $rs->user_id) )
+ {
+ $ulist[$users->user_id] = $users->user_email;
+ }
+ }
+
+ if (count($ulist) > 0)
+ {
+ # Author of the post wants to be notified by mail
+ $headers = array(
+ 'Reply-To: '.$rs->comment_email,
+ 'Content-Type: text/plain; charset=UTF-8;',
+ 'X-Mailer: Dotclear',
+ 'X-Blog-Id: '.mail::B64Header($core->blog->id),
+ 'X-Blog-Name: '.mail::B64Header($core->blog->name),
+ 'X-Blog-Url: '.mail::B64Header($core->blog->url)
+ );
+
+ $subject = '['.$core->blog->name.'] '.sprintf(__('"%s" - New comment'),$rs->post_title);
+ $subject = mail::B64Header($subject);
+
+ $msg = preg_replace('%
\s*%msu',"\n\n",$rs->comment_content);
+ $msg = html::clean($msg);
+ $msg = html_entity_decode($msg);
+
+ if ($cur->comment_status == 1)
+ {
+ $status = __('published');
+ }
+ elseif ($cur->comment_status == 0)
+ {
+ $status = __('unpublished');
+ }
+ elseif ($cur->comment_status == -1)
+ {
+ $status = __('pending');
+ }
+ else
+ {
+ # unknown status
+ $status = $cur->comment_status;
+ }
+
+ $msg .= "\n\n-- \n".
+ sprintf(__('Blog: %s'),$core->blog->name)."\n".
+ sprintf(__('Entry: %s <%s>'),$rs->post_title,$rs->getPostURL())."\n".
+ sprintf(__('Comment by: %s <%s>'),$rs->comment_author,$rs->comment_email)."\n".
+ sprintf(__('Website: %s'),$rs->getAuthorURL())."\n".
+ sprintf(__('Comment status: %s'),$status)."\n".
+ sprintf(__('Edit this comment: <%s>'),DC_ADMIN_URL.
+ ((substr(DC_ADMIN_URL,-1) != '/') ? '/' : '').
+ 'comment.php?id='.$cur->comment_id.
+ '&switchblog='.$core->blog->id)."\n".
+ __('You must log in on the backend before clicking on this link to go directly to the comment.');
+
+ $msg = __('You received a new comment on your blog:')."\n\n".$msg;
+
+ # --BEHAVIOR-- emailNotificationAppendToEmail
+ $msg .= $core->callBehavior('emailNotificationAppendToEmail',$cur);
+
+ foreach ($ulist as $email) {
+ $h = array_merge(array('From: '.$email),$headers);
+ mail::sendMail($email,$subject,$msg,$h);
+ }
+ }
+ }
+
+ protected static function notificationPref($o)
+ {
+ if (is_array($o) && isset($o['notify_comments'])) {
+ return $o['notify_comments'];
+ }
+ return null;
+ }
+}
diff --git a/locales/_pot/main.pot b/locales/_pot/main.pot
new file mode 100644
index 0000000..9cb6d05
--- /dev/null
+++ b/locales/_pot/main.pot
@@ -0,0 +1,76 @@
+# SOME DESCRIPTIVE TITLE.
+# This file is put in the public domain.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Dotclear 2 emailNotification module\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2015-07-10 07:59+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ../hg-plugins/emailNotification//behaviors.php:24
+msgid "My entries"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:25
+msgid "All entries"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:29
+msgid "Email notification"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:30
+msgid "Notify new comments by email:"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:97
+#, php-format
+msgid "\"%s\" - New comment"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:123
+#, php-format
+msgid "Blog: %s"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:124
+#, php-format
+msgid "Entry: %s <%s>"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:125
+#, php-format
+msgid "Comment by: %s <%s>"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:126
+#, php-format
+msgid "Website: %s"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:127
+#, php-format
+msgid "Comment status: %s"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:128
+#, php-format
+msgid "Edit this comment: <%s>"
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:132
+msgid "You must log in on the backend before clicking on this link to go directly to the comment."
+msgstr ""
+
+#: ../hg-plugins/emailNotification//behaviors.php:134
+msgid "You received a new comment on your blog:"
+msgstr ""
diff --git a/locales/fr/main.po b/locales/fr/main.po
new file mode 100644
index 0000000..8ad97b7
--- /dev/null
+++ b/locales/fr/main.po
@@ -0,0 +1,66 @@
+# SOME DESCRIPTIVE TITLE.
+# This file is put in the public domain.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: Dotclear 2 emailNotification module\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2015-07-10 07:59+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Never"
+msgstr "Jamais"
+
+msgid "My entries"
+msgstr "Mes billets"
+
+msgid "All entries"
+msgstr "Tous les billets"
+
+msgid "Email notification"
+msgstr "Notification par e-mail"
+
+msgid "Notify new comments by email:"
+msgstr "Avertir des nouveaux commentaires par e-mail :"
+
+#, php-format
+msgid "\"%s\" - New comment"
+msgstr "\"%s\" - Nouveau commentaire"
+
+#, php-format
+msgid "Blog: %s"
+msgstr "Blog : %s"
+
+#, php-format
+msgid "Entry: %s <%s>"
+msgstr "Billet : %s <%s>"
+
+#, php-format
+msgid "Comment by: %s <%s>"
+msgstr "Commentaire par : %s <%s>"
+
+#, php-format
+msgid "Website: %s"
+msgstr "Site web : %s"
+
+#, php-format
+msgid "Comment status: %s"
+msgstr "Statut du commentaire : %s"
+
+#, php-format
+msgid "Edit this comment: <%s>"
+msgstr "Modifier ce commentaire : %s"
+
+msgid "You must log in on the backend before clicking on this link to go directly to the comment."
+msgstr "Vous devez vous enregistrer sur l'interface d'administration avant de cliquer sur ce lien pour aller directement sur ce commentaire."
+
+msgid "You received a new comment on your blog:"
+msgstr "Vous avez reçu un nouveau commentaire sur votre blog :"