From 0d624b5ef5b900eea2cf5210b219dc4810fd20af Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Mon, 5 Nov 2007 23:26:05 +0100 Subject: [PATCH] Build carnet notification email using PlMailer wiki capability. Signed-off-by: Florent Bruneau --- bin/cron/notifs.send.php | 72 +++++------------------------------------ classes/plmailer.php | 2 +- configs/mails.conf | 3 ++ templates/carnet/mail.notif.tpl | 53 ++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 templates/carnet/mail.notif.tpl diff --git a/bin/cron/notifs.send.php b/bin/cron/notifs.send.php index 0f9f216..9ffed23 100755 --- a/bin/cron/notifs.send.php +++ b/bin/cron/notifs.send.php @@ -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 = << - - Notifications de la semaine $week - - -

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 cette page

-EOF; - - foreach($u['data'] as $cid=>$d) { - $text .= " {$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :\n\n"; - $html .= "

{$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :

\n
    \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 .= "
  • (X{$x['promo']}) {$x['prenom']} {$x['nom']} le $date
  • \n"; - } - $text .= "\n"; - $html .= "
\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 .= << -

L'équipe de Polytechnique.org

-
-

- Tu recois ce mail car tu as activé la notification automatique par mail des événements que tu surveilles. -

-

Tu peux changer cette option sur la page - de configuration des notifications -

- - -EOF; - - global $globals; - $mailer = new PlMailer(); - $mailer->setFrom('Carnet Polytechnicien 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 diff --git a/classes/plmailer.php b/classes/plmailer.php index b654dda..0f8c0fe 100644 --- a/classes/plmailer.php +++ b/classes/plmailer.php @@ -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('' . MiniWiki::WikiToHtml($this->wiki, true) . ''); } diff --git a/configs/mails.conf b/configs/mails.conf index aabd444..48c3dc6 100644 --- a/configs/mails.conf +++ b/configs/mails.conf @@ -44,3 +44,6 @@ from="Gestion des paiements" [test_email] from="Polytechnique.org" + +[carnet] +from="Carnet Polytechnicien " diff --git a/templates/carnet/mail.notif.tpl b/templates/carnet/mail.notif.tpl new file mode 100644 index 0000000..7f8384e --- /dev/null +++ b/templates/carnet/mail.notif.tpl @@ -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: *} -- 2.1.4