From: x2003bruneau Date: Thu, 22 Mar 2007 21:45:41 +0000 (+0000) Subject: Add wiki support for PlMailer and use it on emails/send and %grp/mail X-Git-Tag: xorg/0.9.14~187 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=5b21237dd71df96849421c33d87298f15709d0d9;p=platal.git Add wiki support for PlMailer and use it on emails/send and %grp/mail git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1599 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/classes/miniwiki.php b/classes/miniwiki.php index d17f097..7de524a 100644 --- a/classes/miniwiki.php +++ b/classes/miniwiki.php @@ -36,14 +36,14 @@ class MiniWiki // '_subscript_' MiniWiki::Markup(7, "/'_(.*?)_'/",'$1','$1'); // {+ underline +} - MiniWiki::Markup(8, "/{+(.*?)+}/",'$1','_$1_'); + MiniWiki::Markup(8, "/\\{\\+(.*?)\\+\\}/",'$1','_$1_'); // {- strikeout -} - MiniWiki::Markup(9, "/{-(.*?)-}/",'$1','-$1-'); + MiniWiki::Markup(9, "/\\{-(.*?)-\\}/",'$1','-$1-'); // [+ big +] [++ bigger ++] [+++ even bigger +++] ... - MiniWiki::Markup(10, '/\\[(([-+])+)(.*?)\\1\\]/e',"'$3'", "'$3'"); + MiniWiki::Markup(10, "/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'"); // -----
- MiniWiki::Markup(11, '/(\n|^)----+/s', '$1
', '$1----'."\n"); + MiniWiki::Markup(11, "/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n"); // titles MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1$3'", "'$1$3'"); @@ -140,4 +140,6 @@ class MiniWiki }; MiniWiki::init(); + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/classes/plmailer.php b/classes/plmailer.php index d220ad7..b65d257 100644 --- a/classes/plmailer.php +++ b/classes/plmailer.php @@ -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) diff --git a/modules/email.php b/modules/email.php index 5f0428b..f40ce86 100644 --- a/modules/email.php +++ b/modules/email.php @@ -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); diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index e44b1ba..9098db8 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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(); } diff --git a/modules/xnetgrp/mail.inc.php b/modules/xnetgrp/mail.inc.php index b6574c5..a56719f 100644 --- a/modules/xnetgrp/mail.inc.php +++ b/modules/xnetgrp/mail.inc.php @@ -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; } } diff --git a/templates/admin/mail_intervention.tpl b/templates/admin/mail_intervention.tpl index 7c22f45..c1526bf 100644 --- a/templates/admin/mail_intervention.tpl +++ b/templates/admin/mail_intervention.tpl @@ -20,11 +20,12 @@ {* *} {**************************************************************************} -{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: *} diff --git a/templates/axletter/letter.tpl b/templates/axletter/letter.tpl index 92d712b..2cc51d1 100644 --- a/templates/axletter/letter.tpl +++ b/templates/axletter/letter.tpl @@ -20,14 +20,14 @@ {* *} {**************************************************************************} -{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}
 {/if}
 ====================================================================
@@ -49,7 +49,7 @@ ne plus recevoir : [https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}]
 {if !$is_mail}
 
{/if} -{else} +{elseif $mail_part eq 'html'} {if $is_mail} diff --git a/templates/emails/broken.mail.tpl b/templates/emails/broken.mail.tpl index c9c0c51..a68a43f 100644 --- a/templates/emails/broken.mail.tpl +++ b/templates/emails/broken.mail.tpl @@ -20,10 +20,11 @@ {* *} {**************************************************************************} -{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 diff --git a/templates/emails/send.tpl b/templates/emails/send.tpl index b51ab1b..5229288 100644 --- a/templates/emails/send.tpl +++ b/templates/emails/send.tpl @@ -198,7 +198,11 @@
Sujet :  -
Ne mets que du texte dans le contenu, pas de tags HTML
+
+ Tu peux utiliser des marqueurs wiki pour formatter ton texte.
+ + coche cette case pour envoyer le mail en texte brut, sans formattage +