Add wiki support for PlMailer and use it on emails/send and %grp/mail
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 22 Mar 2007 21:45:41 +0000 (21:45 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 22 Mar 2007 21:45:41 +0000 (21:45 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1599 839d8a87-29fc-0310-9880-83ba4fa771e5

16 files changed:
classes/miniwiki.php
classes/plmailer.php
modules/email.php
modules/xnetgrp.php
modules/xnetgrp/mail.inc.php
templates/admin/mail_intervention.tpl
templates/axletter/letter.tpl
templates/emails/broken.mail.tpl
templates/emails/send.tpl
templates/mails/forums.promo.tpl
templates/mails/listes.promo.tpl
templates/marketing/mail.relance.tpl
templates/newsletter/nl.tpl
templates/register/inscription.reussie.tpl
templates/register/inscrire.mail.tpl
templates/xnetgrp/mail.tpl

index d17f097..7de524a 100644 (file)
@@ -36,14 +36,14 @@ class MiniWiki
         // '_subscript_'
         MiniWiki::Markup(7, "/'_(.*?)_'/",'<sub>$1</sub>','$1');
         // {+ underline +}
-        MiniWiki::Markup(8, "/{+(.*?)+}/",'<ins>$1</ins>','_$1_');
+        MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'<ins>$1</ins>','_$1_');
         // {- strikeout -}
-        MiniWiki::Markup(9, "/{-(.*?)-}/",'<del>$1</del>','-$1-');
+        MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'<del>$1</del>','-$1-');
         // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
-        MiniWiki::Markup(10, '/\\[(([-+])+)(.*?)\\1\\]/e',"'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'");
+        MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'");
         
         // ----- <hr/>
-        MiniWiki::Markup(11, '/(\n|^)----+/s', '$1<hr/>', '$1----'."\n");
+        MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1<hr/>', '$1-- '."\n");
         // titles
         MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'", "'$1$3'");
         
@@ -140,4 +140,6 @@ class MiniWiki
 };
 
 MiniWiki::init();
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index d220ad7..b65d257 100644 (file)
@@ -59,9 +59,9 @@ class PlMail extends Smarty
         return $plmail;
     }
 
-    public function run($html)
+    public function run($version)
     {
-        $this->assign('html_version', $html);
+        $this->assign('mail_part', $version);
         $text = $this->fetch($this->tpl);
         return $text;
     }
@@ -147,6 +147,7 @@ class PlMailer extends Mail_Mime {
     private $mail;
     private $page    = null;
     private $charset;
+    private $wiki    = null;
 
     function __construct($tpl = null, $charset = "UTF-8")
     {
@@ -251,20 +252,36 @@ class PlMailer extends Mail_Mime {
             $this->page->register_function($var, $callback);
         }
     }
+
+    public function setWikiBody($wiki)
+    {
+        $this->wiki = $wiki;
+    }
     
     private function processPage($with_html = true)
     {
         $level = error_reporting(0);
         if (!is_null($this->page)) {
-            $this->setTxtBody($this->page->run(false));
-            if ($with_html) {
-                $html = trim($this->page->run(true));
-                if (!empty($html)) {
-                    $this->setHtmlBody($html);
+            $level = error_reporting(0);
+            $this->page->run('head'); // process page headers
+            $this->wiki = trim($this->page->run('wiki')); // get wiki
+            if (!$this->wiki) {
+                $this->setTxtBody($this->page->run('text'));
+                if ($with_html) {
+                    $html = trim($this->page->run('html'));
+                    if (!empty($html)) {
+                        $this->setHtmlBody($html);
+                    }
                 }
             }
+            error_reporting($level);
+        }
+        if ($this->wiki) {
+            $this->setTxtBody(MiniWiki::WikiToText($this->wiki, true, 0, 78));
+            if ($with_html) {
+                $this->setHtmlBody(MiniWiki::WikiToHtml($this->wiki, true));
+            }
         }
-        error_reporting($level);
     }
 
     public function send($with_html = true)
index 5f0428b..f40ce86 100644 (file)
@@ -351,7 +351,11 @@ class EmailModule extends PLModule
                 foreach ($files as $name=>&$upload) {
                     $mymail->addUploadAttachment($upload, $name);
                 }
-                $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
+                if (Env::v('nowiki')) {
+                    $mymail->setTxtBody(wordwrap($txt, 78, "\n"));
+                } else {
+                    $mymail->setWikiBody($txt);
+                }
                 if ($mymail->send()) {
                     $page->trig("Ton mail a bien été envoyé.");
                     $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain);
index e44b1ba..9098db8 100644 (file)
@@ -302,7 +302,7 @@ class XnetGrpModule extends PLModule
             require_once dirname(__FILE__) . '/xnetgrp/mail.inc.php';
             $tos = get_all_redirects($mbr,  $mls, $mmlist);
             $upload = PlUpload::get($_FILES['uploaded'], S::v('forlife'), 'xnet.emails', true);
-            send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
+            send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']);
             if ($upload) {
                 $upload->rm();
             }
index b6574c5..a56719f 100644 (file)
@@ -76,7 +76,7 @@ function get_all_redirects($membres, $mls, &$client)
 // }}}
 // {{{ _send_xnet_mail
 
-function _send_xnet_mail($user, $body, $mailer, $replyto = null)
+function _send_xnet_mail($user, $body, $wiki, $mailer, $replyto = null)
 {
     $cher = isset($user['sexe']) ? ($user['sexe'] ? 'Chère' : 'Cher') : 'Cher(e)';
     $nom  = isset($user['nom']) ? $user['nom'] : "";
@@ -92,14 +92,18 @@ function _send_xnet_mail($user, $body, $mailer, $replyto = null)
     if ($replyto) {
         $mailer->addHeader('Reply-To', $replyto);
     }
-    $mailer->setTxtBody(wordwrap($text, 72));
+    if ($wiki) {
+        $mailer->setWikiBody($text);
+    } else {
+        $mailer->setTxtBody(wordwrap($text, 72));
+    }
     $mailer->send();
 }
 
 // }}}
 // {{{ send_xnet_mails
 
-function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $upload = null, $name = null)
+function send_xnet_mails($from, $sujet, $body, $wiki, $tos, $replyto = null, $upload = null, $name = null)
 {
     global $globals;
     $sent = array();
@@ -113,7 +117,7 @@ function send_xnet_mails($from, $sujet, $body, $tos, $replyto = null, $upload =
 
     foreach ($tos as $user) {
         if ($sent[$user['email']]) continue;
-        _send_xnet_mail($user, $body, $mailer, $replyto);
+        _send_xnet_mail($user, $body, $wiki, $mailer, $replyto);
         $sent[$user['email']] = true;
     }
 }
index 7c22f45..c1526bf 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if !$html_version}
 {config_load file="mails.conf" section="intervention_admin"}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {to addr=#to#}
 {subject text="INTERVENTION de $user"}
+{elseif $mail_part eq 'text'}
 {$query|regex_replace:"/[ \t]+/":" "}
 {/if}
 {* vim:set et sw=2 sts=2 sws=2: *}
index 92d712b..2cc51d1 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if !$html_version}
-{if $is_mail}
 {config_load file="mails.conf" section="mails_ax"}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {subject text=$am->title(true)}
 {if isset(#replyto#)}{add_header name='Reply-To' value=#replyto#}{/if}
 {if isset(#retpath#)}{add_header name='Return-Path' value=#retpath#}{/if}
-{else}
+{elseif $mail_part eq 'text'}
+{if !$is_mail}
 <pre style="width : 72ex; margin: auto">
 {/if}
 ====================================================================
@@ -49,7 +49,7 @@ ne plus recevoir : [https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}]
 {if !$is_mail}
 </pre>
 {/if}
-{else}
+{elseif $mail_part eq 'html'}
 {if $is_mail}
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
index c9c0c51..a68a43f 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if !$html_version}
 {config_load file="mails.conf" section="emails_broken"}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {subject text=#subject#}
+{elseif $mail_part eq 'text'}
 Bonjour !
 
   Nous t'écrivons car lors de l'envoi de la lettre d'information mensuelle
index b51ab1b..5229288 100644 (file)
 
   <fieldset>
     <legend>Sujet&nbsp;:&nbsp;<input type='text' name='sujet' size='60' value="{$smarty.request.sujet}" /></legend>
-    <div class="center">Ne mets que du texte dans le contenu, pas de tags HTML</div>
+    <div class="center">
+      Tu peux utiliser des marqueurs <em>wiki</em> pour formatter ton texte.<br />
+      <small><input type="checkbox" name="nowiki" value="1" {if $smarty.request.nowiki}checked="checked"{/if} />
+      coche cette case pour envoyer le mail en texte brut, sans formattage</small>
+    </div>
     <textarea name='contenu' rows="30" cols="75">
 {$smarty.request.contenu}
 {if !$smarty.request.contenu}
index a341bbc..10d88eb 100644 (file)
 {**************************************************************************}
 
 {config_load file="mails.conf" section="forums_promo"}
-{if !$html_version}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {to addr=#to#}
 {subject text="Création du forum promo $promo"}
+{elseif $mail_part eq 'text'}
 
 Création du forum promo {$promo} à faire !
 (+ de 20% d'inscrits)
 {/if}
+
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 271fa47..c502b20 100644 (file)
 {**************************************************************************}
 
 {config_load file="mails.conf" section="listes_promo"}
-{if !$html_version}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {to addr=#to#}
 {subject text="Création de la liste promo $promo"}
+{elseif $mail_part eq 'text'}
 
 Création de la liste promo {$promo} à faire !
 {/if}
index 9210e43..70be6c8 100644 (file)
 {**************************************************************************}
 
 {config_load file="mails.conf" section="marketing_relance"}
-{if !$html_version}
+{if $mail_part eq 'head'}
 {subject text="$subj"}
 {from full=#from#}
 {to addr="$lemail"}
+{elseif $mail_part eq 'text'}
 Bonjour,
 
 Il y a quelques temps, le {$fdate}, tu as commencé ton inscription à Polytechnique.org ! Tu n'as toutefois pas tout à fait terminé cette inscription, aussi nous nous permettons de te renvoyer cet email pour te rappeler tes paramètres de connexion, au cas où tu souhaiterais terminer cette inscription, et accéder à l'ensemble des services que nous offrons aux {$nbdix} Polytechniciens déjà inscrits (email à vie, annuaire en ligne, etc...).
index e1e496f..fbb887d 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if !$html_version}
-{if $is_mail}
 {config_load file="mails.conf" section="newsletter"}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {subject text=$nl->title(true)}
 {if isset(#replyto#)}{add_header name='Reply-To' value=#replyto#}{/if}
 {if isset(#retpath#)}{add_header name='Return-Path' value=#retpath#}{/if}
-{else}
+{elseif $mail_part eq 'html'}
+{if !$is_mail}
 <pre style="width : 72ex; margin: auto">
 {/if}
 ====================================================================
@@ -67,7 +67,7 @@ ne plus recevoir : [https://www.polytechnique.org/nl/out]
 {if !$is_mail}
 </pre>
 {/if}
-{else}
+{elseif $mail_part eq 'html'}
 {if $is_mail}
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
index 554f29f..0590d19 100644 (file)
 {**************************************************************************}
 
 {config_load file="mails.conf" section="inscription"}
-{if !$html_version}
+{if $mail_part eq 'head'}
 {from full=#from#}
 {to addr="$forlife@polytechnique.org"}
 {subject text="Bienvenue parmi les X sur le web !"}
+{elseif $mail_par eq 'text'}
 
-{$prenom}, félicitations pour ton inscription :o))
+{$prenom}, félicitations pour ton inscription !
 
 N'oublie pas de changer ton mot de passe sur le site. C'est très important
 si tu veux garder accès au site et ton e-mail en fonction.
index e04286b..43106d1 100644 (file)
 {**************************************************************************}
 
 {config_load file="mails.conf" section="inscrire"}
-{if !$html_version}
+{if $mail_part eq 'head'}
 {subject text="$subj"}
 {from full=#from#}
 {to addr="$lemail"}
+{elseif $mail_part eq 'text'}
 Bonjour,
 
 Ton inscription sur Polytechnique.org est presque terminée, un clic sur le lien ci-dessous et c'est fini.
index d100809..80be54f 100644 (file)
@@ -89,6 +89,12 @@ masculin ou féminin, par son prénom, ou son nom.
       <td><input type="text" name="sujet" value="{$smarty.request.sujet|default:"remplir le sujet ..."}" size=55 maxlength=70></td>
     </tr>
     <tr>
+      <td colspan="2" class="smaller">
+        <input type="checkbox" name="wiki" value="1" checked="1" />
+        activer la syntaxe wiki pour le formattage du message
+      </td>
+    </tr>
+    <tr>
       <td colspan="2" class="center">
         <textarea name="body" cols="72" rows="25">
 {if $smarty.request.body}