Build carnet notification email using PlMailer wiki capability.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 5 Nov 2007 22:26:05 +0000 (23:26 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 5 Nov 2007 22:26:05 +0000 (23:26 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
bin/cron/notifs.send.php
classes/plmailer.php
configs/mails.conf
templates/carnet/mail.notif.tpl [new file with mode: 0644]

index 0f9f216..9ffed23 100755 (executable)
@@ -26,70 +26,14 @@ require_once("../../include/notifs.inc.php");
 
 $all = new AllNotifs();
 
-foreach($all->_data as $u) {
-    $week   = date("W - Y");
-
-    $text =  "  ".($u['sexe'] ? 'Chère' : 'Cher')." {$u['prenom']},\n\n"
-          .  "  Voici les événements survenus dans la semaine écoulée,\n"
-          .  "et depuis ta dernière visite sur le site.\n\n"
-          .  "Tu trouveras les mêmes informations sur la page :\n"
-          .  "    https://www.polytechnique.org/carnet/panel\n\n"
-          .  "------------------------------------------------------------------------\n\n";
-
-    $html  = <<<EOF
-<html>
-  <head>
-    <title>Notifications de la semaine $week</title>
-  </head>
-  <body>
-    <p>Voici les événements survenus dans la semaine écoulée, et depuis ta dernière visite sur le site.</p>
-    <p>Tu trouveras les mêmes informations sur <a href='https://www.polytechnique.org/carnet/panel'>cette page</a></p>
-EOF;
-
-    foreach($u['data'] as $cid=>$d) {
-        $text .= "  {$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :\n\n";
-        $html .= "<h1 style='font-size: 120%'>{$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :</h1>\n<ul>\n";
-
-        foreach($d as $promo=>$x) {
-            require_once('../../plugins/modifier.date_format.php');
-            $date  = smarty_modifier_date_format($x['date'], '%d %b %Y');
-            $text .= "    - (X{$x['promo']}) {$x['prenom']} {$x['nom']} le $date\n";
-            $text .= "      https://www.polytechnique.org/profile/private/{$x['bestalias']}\n\n";
-            $html .= "<li>(X{$x['promo']}) <a href='https://www.polytechnique.org/profile/private/{$x['bestalias']}'>{$x['prenom']} {$x['nom']}</a> le $date</li>\n";
-        }
-        $text .= "\n";
-        $html .= "</ul>\n";
-    }
-
-    $text .= "-- \n"
-           . "L'équipe de Polytechnique.org\n\n"
-           . "------------------------------------------------------------------------\n\n"
-           . "Tu recois ce mail car tu as activé la notification automatique \n"
-           . "par mail des événements que tu surveilles.\n\n"
-           . "Tu peux changer cette option sur :\n"
-           . "    https://www.polytechnique.org/carnet/notifs";
-    $html .= <<<EOF
-    <hr />
-    <p>L'équipe de Polytechnique.org</p>
-    <br />
-    <p>
-    Tu recois ce mail car tu as activé la notification automatique par mail des événements que tu surveilles.
-    </p>
-    <p>Tu peux changer cette option sur la <a href="https://www.polytechnique.org/carnet/notifs">page
-    de configuration des notifications</a>
-    </p>
-  </body>
-</html>
-EOF;
-
-    global $globals;
-    $mailer = new PlMailer();
-    $mailer->setFrom('Carnet Polytechnicien <support_carnet@' . $globals->mail->domain . '>');
-    $mailer->addTo("\"{$u['prenom']} {$u['nom']}\" <{$u['bestalias']}@" . $globals->mail->domain . '>');
-    $mailer->setSubject("Notifications de la semaine $week");
-    $mailer->setTxtBody($text);
-    if ($u['mail_fmt'] == 'html') { $mailer->setHtmlBody($html); }
-    $mailer->send();
+$mailer = new PlMailer('carnet/mail.notif.tpl');
+foreach ($all->_data as $u) {
+    $mailer = new PlMailer('carnet/mail.notif.tpl');
+    $mailer->assign('u', $u);
+    $mailer->assign('week', date("W - Y"));
+    $mailer->assign('cats', $all->_cats);
+    $mailer->addTo('"' . $u['prenom'] . ' ' . $u['nom'] . '" <' . $u['bestalias'] . '@polytechnique.org>');
+    $mailer->send($u['mail_fmt'] == 'html');
 }
 
 XDB::execute("DELETE FROM  watch_profile
index b654dda..0f8c0fe 100644 (file)
@@ -279,7 +279,7 @@ class PlMailer extends Mail_Mime {
             error_reporting($level);
         }
         if ($this->wiki) {
-            $this->setTxtBody(MiniWiki::WikiToText($this->wiki, true, 0, 78));
+            $this->setTxtBody(MiniWiki::WikiToText($this->wiki, false, 0, 78));
             if ($with_html) {
                 $this->setHtmlBody('<html><body>' . MiniWiki::WikiToHtml($this->wiki, true) . '</body></html>');
             }
index aabd444..48c3dc6 100644 (file)
@@ -44,3 +44,6 @@ from="Gestion des paiements" <support@polytechnique.org>
 
 [test_email]
 from="Polytechnique.org" <support@polytechnique.org>
+
+[carnet]
+from="Carnet Polytechnicien <support_carnet@polytechnique.org>"
diff --git a/templates/carnet/mail.notif.tpl b/templates/carnet/mail.notif.tpl
new file mode 100644 (file)
index 0000000..7f8384e
--- /dev/null
@@ -0,0 +1,53 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{config_load file="mails.conf" section="carnet"}
+{if $mail_part eq 'head'}
+{from full=#from#}
+{subject text="Notifications de la semaine `$week`"}
+{if isset(#replyto#)}{add_header name='Reply-To' value=#replyto#}{/if}
+{if isset(#retpath#)}{add_header name='Return-Path' value=#retpath#}{/if}
+{elseif $mail_part eq 'wiki'}
+{if $u.sexe}Chère{else}Cher{/if} {$u.prenom},
+
+Voici les événements survenus dans la semaine écoulée, et depuis ta dernière visite sur le site.
+
+Tu trouveras les mêmes informations sur [[https://www.polytechnique.org/carnet/panel|cette page]].
+
+{foreach from=$u.data key=cid item=d}
+
+!{if $d|@count eq 1}{$cats[$cid].mail_sg}{else}{$cats[$cid].mail}{/if} :
+
+{foreach from=$d key=promo item=x}
+* (X{$x.promo}), le {$x.date|date_format:"%d %b %Y"}, [[https://www.polytechnique.org/profile/private/{$x.bestalias}|{$x.prenom} {$x.nom}]]
+{/foreach}
+
+{/foreach}
+-- 
+L'Équipe de Polytechnique.org
+
+'''''Note :'''''  Tu reçois ce mail ce mail car tu as activé la notification automatique par mail des événements que tu surveilles.\\
+Tu peux changer cette options sur la [[https://www.polytechnique.org/carnet/notifs|page de configuration des notifications]].
+
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}