Dotclear

source: plugins/emailNotification/behaviors.php @ 2077

Revision 2077, 3.7 KB checked in by Moe, 14 years ago (diff)

Email notification :

  • added link to edit comment in the email
  • updated french localization
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2008 Olivier Meunier and contributors
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK ------------------------------------
12
13class notificationBehaviors
14{
15     public static function adminUserForm(&$core)
16     {
17          global $user_options;
18         
19          $notify_comments = !empty($user_options['notify_comments']) ? $user_options['notify_comments'] : '0';
20         
21          $opt = array(
22               __('never') => '0',
23               __('my entries') => 'mine',
24               __('all entries') => 'all'
25          );
26         
27          echo
28          '<fieldset><legend>'.__('Email notification').'</legend>'.
29          '<p><label class="classic">'.
30          __('Notify new comments by email:').' '.
31          form::combo('notify_comments',$opt,$notify_comments).
32         
33          '</label></p>'.
34          '</fieldset>';
35     }
36     
37     public static function adminBeforeUserUpdate(&$cur,$user_id='')
38     {
39          $cur->user_options['notify_comments'] = $_POST['notify_comments'];
40     }
41     
42     public static function publicAfterCommentCreate(&$cur,$comment_id)
43     {
44          # We don't want notification for spam
45          if ($cur->comment_status == -2) {
46               return;
47          }
48         
49          global $core;
50         
51          # Information on comment author and post author
52          $rs = $core->auth->sudo(array($core->blog,'getComments'), array('comment_id'=>$comment_id));
53         
54          if ($rs->isEmpty()) {
55               return;
56          }
57         
58          # Information on blog users
59          $strReq =
60          'SELECT U.user_id, user_email, user_options '.
61          'FROM '.$core->blog->prefix.'user U JOIN '.$core->blog->prefix.'permissions P ON U.user_id = P.user_id '.
62          "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
63          'UNION '.
64          'SELECT user_id, user_email, user_options '.
65          'FROM '.$core->blog->prefix.'user '.
66          'WHERE user_super = 1 ';
67         
68          $users = $core->con->select($strReq);
69         
70          # Create notify list
71          $ulist = array();
72          while ($users->fetch()) {
73               if (!$users->user_email) {
74                    continue;
75               }
76               
77               $notification_pref = self::notificationPref(rsExtUser::options($users));
78               
79               if ($notification_pref == 'all'
80               || ($notification_pref == 'mine' && $users->user_id == $rs->user_id) )
81               {
82                    $ulist[$users->user_id] = $users->user_email;
83               }
84          }
85         
86          if (count($ulist) > 0)
87          {
88               # Author of the post wants to be notified by mail
89               $headers = array(
90                    'Reply-To: '.$rs->comment_email,
91                    'Content-Type: text/plain; charset=UTF-8;',
92                    'X-Mailer: Dotclear',
93                    'X-Blog-Id: '.mail::B64Header($core->blog->id),
94                    'X-Blog-Name: '.mail::B64Header($core->blog->name),
95                    'X-Blog-Url: '.mail::B64Header($core->blog->url)
96               );
97               
98               $subject = '['.$core->blog->name.'] '.sprintf(__('"%s" - New comment'),$rs->post_title);
99               $subject = mail::B64Header($subject);
100               
101               $msg = preg_replace('%</p>\s*<p>%msu',"\n\n",$rs->comment_content);
102               $msg = html::clean($msg);
103               
104               $msg .= "\n\n-- \n".
105               sprintf(__('Blog: %s'),$core->blog->name)."\n".
106               sprintf(__('Entry: %s <%s>'),$rs->post_title,$rs->getPostURL())."\n".
107               sprintf(__('Comment by: %s <%s>'),$rs->comment_author,$rs->comment_email)."\n".
108               sprintf(__('Website: %s'),$rs->getAuthorURL())."\n".
109               sprintf(__('Edit this comment: <%s>'),DC_ADMIN_URL.
110                    ((substr(DC_ADMIN_URL,-1) != '/') ? '/' : '').
111                    'comment.php?id='.$cur->comment_id.
112                    '&switchblog='.$core->blog->id)."\n".
113               __('You must log in on the backend before clicking on this link to go directly to the comment.');
114               
115               $msg = __('You received a new comment on your blog:')."\n\n".$msg;
116               
117               foreach ($ulist as $email) {
118                    $h = array_merge(array('From: '.$email),$headers);
119                    mail::sendMail($email,$subject,$msg,$h);
120               }
121          }
122     }
123     
124     protected static function notificationPref($o)
125     {
126          if (is_array($o) && isset($o['notify_comments'])) {
127               return $o['notify_comments'];
128          }
129          return null;
130     }
131}
132?>
Note: See TracBrowser for help on using the repository browser.

Sites map