From: Ludovic CHEVALIER
Date: Wed, 12 Mar 2014 09:05:19 +0000 (+0100)
Subject: [PLUGINS] ~formidable 1.3.6 --> 1.9.1
X-Git-Tag: v3.3.0~115
X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/%20?a=commitdiff_plain;h=3b34d0137e672387909494967123983d45db1ffd;p=lhc%2Fweb%2Fwww.git
[PLUGINS] ~formidable 1.3.6 --> 1.9.1
---
diff --git a/www/plugins/facteur/classes/facteur.php b/www/plugins/facteur/classes/facteur.php
index ca3edab2..daedf1e2 100755
--- a/www/plugins/facteur/classes/facteur.php
+++ b/www/plugins/facteur/classes/facteur.php
@@ -89,13 +89,15 @@ class Facteur extends PHPMailer {
$this->AddCustomHeader("Errors-To: ".$this->Sender);
}
- if (!empty($options['cc'])) {
- $this->AddCC( $options['cc'] );
- }
- if (!empty($options['bcc'])) {
- $this->AddBCC( $options['bcc'] );
+ if (!defined('_TEST_EMAIL_DEST')){
+ if (!empty($options['cc'])) {
+ $this->AddCC( $options['cc'] );
+ }
+ if (!empty($options['bcc'])) {
+ $this->AddBCC( $options['bcc'] );
+ }
}
-
+
if (isset($options['smtp']) AND $options['smtp'] == 'oui') {
$this->Mailer = 'smtp';
$this->Host = $options['smtp_host'];
@@ -141,94 +143,15 @@ class Facteur extends PHPMailer {
}
/*
- * Transforme du HTML en texte brut, mais proprement, c'est-Ã -dire en essayant
- * de garder les titrages, les listes, etc
+ * Transforme du HTML en texte brut, mais proprement
+ * utilise le filtre facteur_mail_html2text
+ * @uses facteur_mail_html2text()
*
* @param string $html Le HTML Ã transformer
* @return string Retourne un texte brut formaté correctement
*/
function html2text($html){
- // On remplace tous les sauts de lignes par un espace
- $html = str_replace("\n", ' ', $html);
-
- // Supprimer tous les liens internes
- $texte = preg_replace("/\]*>(.*?)<\/a>/ims", "\\2", $html);
-
- // Supprime feuille style
- $texte = preg_replace(";;i", "", $texte);
-
- // Remplace tous les liens
- $texte = preg_replace("/\]*href=['\"](.*?)['\"][^>]*>(.*?)<\/a>/ims", "\\2 (\\1)", $texte);
-
- // Les titres
- $texte = preg_replace(";]*>;i", "\n= ", $texte);
- $texte = str_replace("
", " =\n\n", $texte);
- $texte = preg_replace(";]*>;i", "\n== ", $texte);
- $texte = str_replace("
", " ==\n\n", $texte);
- $texte = preg_replace(";]*>;i", "\n=== ", $texte);
- $texte = str_replace("
", " ===\n\n", $texte);
-
- // Une fin de liste
- $texte = preg_replace(";(u|o)l>;i", "\n\n", $texte);
-
- // Une saut de ligne *après* le paragraphe
- $texte = preg_replace(";]*>;i", "\n", $texte);
- $texte = preg_replace(";
;i", "\n\n", $texte);
- // Les sauts de ligne interne
- $texte = preg_replace(";
]*>;i", "\n", $texte);
-
- //$texte = str_replace('
', "\n".'-', $texte);
- $texte = preg_replace (';]*>;i', "\n".'- ', $texte);
-
-
- // accentuation du gras
- // texte -> **texte**
- $texte = preg_replace (';]*>;i','**' ,$texte);
- $texte = str_replace ('','**' ,$texte);
-
- // accentuation du gras
- // texte -> **texte**
- $texte = preg_replace (';]*>;i','**' ,$texte);
- $texte = str_replace ('','**' ,$texte);
-
-
- // accentuation de l'italique
- // texte -> *texte*
- $texte = preg_replace (';]*>;i','/' ,$texte);
- $texte = str_replace ('','*' ,$texte);
-
- // accentuation de l'italique
- // texte -> *texte*
- $texte = preg_replace (';]*>;i','/' ,$texte);
- $texte = str_replace ('','*' ,$texte);
-
- $texte = str_replace('œ', 'oe', $texte);
- $texte = str_replace(" ", " ", $texte);
- $texte = filtrer_entites($texte);
-
- // On supprime toutes les balises restantes
- $texte = supprimer_tags($texte);
-
- $texte = str_replace("\x0B", "", $texte);
- $texte = str_replace("\t", "", $texte) ;
- $texte = preg_replace(";[ ]{3,};", "", $texte);
-
- // espace en debut de ligne
- $texte = preg_replace("/(\r\n|\n|\r)[ ]+/", "\n", $texte);
-
- //marche po
- // Bring down number of empty lines to 4 max
- $texte = preg_replace("/(\r\n|\n|\r){3,}/m", "\n\n", $texte);
-
- //saut de lignes en debut de texte
- $texte = preg_replace("/^(\r\n|\n|\r)*/", "\n\n", $texte);
- //saut de lignes en debut ou fin de texte
- $texte = preg_replace("/(\r\n|\n|\r)*$/", "\n\n", $texte);
-
- // Faire des lignes de 75 caracteres maximum
- //$texte = wordwrap($texte);
-
- return $texte;
+ return facteur_mail_html2text($html);
}
/**
diff --git a/www/plugins/facteur/emails/texte.html b/www/plugins/facteur/emails/texte.html
index cb7fccf4..e8ed065b 100644
--- a/www/plugins/facteur/emails/texte.html
+++ b/www/plugins/facteur/emails/texte.html
@@ -89,7 +89,7 @@
style="color:#A39F9A !important;font-family: Verdana, Geneva, sans-serif; !important;font-size:90% !important;font-weight:normal !important;font-style:normal !important;text-decoration:none !important;vertical-align:top !important;text-align:left !important;">
- — Envoyé par #NOM_SITE_SPIP
+ — #SET{site,#NOM_SITE_SPIP}<:facteur:email_envoye_par{site=#GET{site}}:>
diff --git a/www/plugins/facteur/facteur_fonctions.php b/www/plugins/facteur/facteur_fonctions.php
index 3abf19a9..9c09ca43 100755
--- a/www/plugins/facteur/facteur_fonctions.php
+++ b/www/plugins/facteur/facteur_fonctions.php
@@ -286,4 +286,102 @@ function facteur_nl2br_si_pas_autobr($texte){
return (_AUTOBR?$texte:nl2br($texte));
}
+/**
+ * Transformer un mail HTML en mail Texte proprement :
+ * - les tableaux de mise en page sont utilisés pour structurer le mail texte
+ * - le reste du HTML est markdownifie car c'est un format texte lisible et conventionnel
+ *
+ * @param string $html
+ * @return string
+ */
+function facteur_mail_html2text($html){
+ // nettoyer les balises de mise en page html
+ $html = preg_replace(",(td|th)>,Uims","
",$html);
+ $html = preg_replace(",(table)>,Uims","@@@hr@@@",$html);
+ $html = preg_replace(",?(html|body|table|td|th|tbody|thead|center|article|section|span)[^>]*>,Uims","\n\n",$html);
+
+ // commentaires html et conditionnels
+ $html = preg_replace(",,Uims","\n",$html);
+ $html = preg_replace(",,Uims","\n",$html);
+
+ $html = preg_replace(",<(/?)(div|tr|caption)([^>]*>),Uims","<\\1p>",$html);
+ $html = preg_replace(",(\s*)+,ims","
",$html);
+ $html = preg_replace(",
\s*
,ims","
",$html);
+ $html = preg_replace(",\s*
,ims","",$html);
+ $html = preg_replace(",(\s*(@@@hr@@@)?\s*)+,ims","\\2",$html);
+ $html = preg_replace(",(\s*
),ims","",$html);
+
+ // succession @@@hr@@@
et
@@@hr@@@
+ $html = preg_replace(",@@@hr@@@\s*(<[^>]*>\s*)?
]*>,ims","@@@hr@@@\n",$html);
+ $html = preg_replace(",
]*>\s*(<[^>]*>\s*)?@@@hr@@@,ims","\n@@@hr@@@",$html);
+
+ $html = preg_replace(",,Uims","\n\\1\n
",$html);
+
+ // vider le contenu de qqunes :
+ $html = preg_replace(",]*>.*,Uims","\n",$html);
+
+ // Liens :
+ // Nettoyage des liens des notes de bas de page
+ $html = preg_replace("@([0-9]+)@", "\\3", $html);
+ // Supprimer tous les liens internes
+ $html = preg_replace("/\]*>(.*?)<\/a>/ims","\\2", $html);
+ // Remplace tous les liens
+ preg_match_all("/\]*>(.*?)<\/a>/ims", $html,$matches,PREG_SET_ORDER);
+ $prelinks = $postlinks = array();
+ foreach ($matches as $k => $match){
+ $link = "@@@link$k@@@";
+ $url = str_replace("&","&",$match[1]);
+ if ($match[2]==$match[1] OR $match[2]==$url){
+ // si le texte est l'url :
+ $prelinks[$match[0]] = "$link";
+ }
+ else {
+ // texte + url
+ $prelinks[$match[0]] = $match[2] . " ($link)";
+ }
+ $postlinks[$link] = $url;
+ }
+ $html = str_replace(array_keys($prelinks), array_values($prelinks),$html);
+
+ // les images par leur alt ?
+ // au moins les puces
+ $html = preg_replace(',]*alt="-"[^>]*>,Uims','-',$html);
+ // les autres
+ $html = preg_replace(',]*alt=[\'"]([^\'"]*)[\'"][^>]*>,Uims',"\\1",$html);
+ // on vire celles sans alt
+ $html = preg_replace(",?(img)[^>]*>,Uims","\n",$html);
+
+ // espaces
+ $html = str_replace(" "," ",$html);
+ $html = preg_replace(",\s+,ims","
",$html);
+
+ #return $html;
+ include_spip("lib/markdownify/markdownify");
+ $parser = new Markdownify('inline',false,false);
+ $texte = $parser->parseString($html);
+
+ $texte = str_replace(array_keys($postlinks), array_values($postlinks),$texte);
+
+
+ // trim et sauts de ligne en trop ou pas assez
+ $texte = trim($texte);
+ $texte = str_replace("
\n","\n",$texte);
+ $texte = preg_replace(",(@@@hr@@@\s*)+\Z,ims","",$texte);
+ $texte = preg_replace(",(@@@hr@@@\s*\n)+,ims","\n\n\n".str_pad("-",75,"-")."\n\n\n",$texte);
+ $texte = preg_replace(",(\n#+\s),ims","\n\n\\1",$texte);
+ $texte = preg_replace(",(\n\s*)(\n\s*)+(\n)+,ims","\n\n\n",$texte);
+
+
+ //
et
restants
+ $texte = str_replace(array("","
"),array("",""),$texte);
+
+ // entites restantes ? (dans du code...)
+ include_spip('inc/charsets');
+ $texte = unicode2charset($texte);
+ $texte = str_replace(array(''', '"'),array("'",'"'), $texte);
+
+
+ // Faire des lignes de 75 caracteres maximum
+ return trim(wordwrap($texte));
+}
?>
diff --git a/www/plugins/facteur/facteur_pipelines.php b/www/plugins/facteur/facteur_pipelines.php
new file mode 100644
index 00000000..2bdbdce4
--- /dev/null
+++ b/www/plugins/facteur/facteur_pipelines.php
@@ -0,0 +1,33 @@
+ 0)){
+ $ajout = ''._T('facteur:message_identite_email').'
';
+ $flux['data'] = preg_replace(",(]*class=[\"']editer editer_email_webmaster.*>)(.*