[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / forum / inc / email_notification_forum.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined("_ECRIRE_INC_VERSION")) {
14 return;
15 }
16
17 /**
18 * Construitre l'email personalise de notification d'un forum
19 *
20 * @param array $t
21 * @param string $email
22 * @param array $contexte
23 * @return string
24 */
25 function inc_email_notification_forum_dist($t, $email, $contexte = array()) {
26 static $contextes_store = array();
27
28 if (!isset($contextes_store[$t['id_forum']])) {
29 $url = '';
30 $id_forum = $t['id_forum'];
31
32 if ($t['statut'] == 'prive') # forum prive
33 {
34 if ($t['id_objet']) {
35 $url = generer_url_entite($t['id_objet'], $t['objet'], '', 'forum' . $id_forum, false);
36 }
37 } else {
38 if ($t['statut'] == 'privrac') # forum general
39 {
40 $url = generer_url_ecrire('forum') . '#forum' . $id_forum;
41 } else {
42 if ($t['statut'] == 'privadm') # forum des admins
43 {
44 $url = generer_url_ecrire('forum', 'quoi=admin') . '#forum' . $id_forum;
45 } else {
46 if ($t['statut'] == 'publie') # forum publie
47 {
48 $url = generer_url_entite($id_forum, 'forum', '', 'forum' . $id_forum, true);
49 } else # forum modere, spam, poubelle direct ....
50 {
51 $url = generer_url_ecrire('controler_forum', "debut_id_forum=" . $id_forum);
52 }
53 }
54 }
55 }
56
57 if (!$url) {
58 spip_log("forum $id_forum sans referent", 'notifications');
59 $url = './';
60 }
61 if ($t['id_objet']) {
62 include_spip('inc/filtres');
63 $t['titre_source'] = generer_info_entite($t['id_objet'], $t['objet'], 'titre');
64 }
65
66 $t['url'] = $url;
67
68 // detecter les url des liens du forum
69 // pour la moderation (permet de reperer les SPAMS avec des liens caches)
70 // il faut appliquer le traitement de raccourci car sinon on rate des liens sous forme [->..] utilises par les spammeurs !
71 include_spip("public/interfaces");
72 $table_objet = "forum";
73
74 $links = array();
75 foreach ($t as $champ => $v) {
76 $champ = strtoupper($champ);
77 $traitement = (isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : null);
78 if (is_array($traitement)
79 and (isset($traitement[$table_objet]) or isset($traitement[0]))
80 ) {
81 $traitement = $traitement[isset($traitement[$table_objet]) ? $table_objet : 0];
82 $traitement = str_replace('%s', "'" . texte_script($v) . "'", $traitement);
83 eval("\$v = $traitement;");
84 }
85
86 $links = $links + extraire_balises($v, 'a');
87 }
88 $links = extraire_attribut($links, 'href');
89 $links = implode("\n", $links);
90 $t['liens'] = $links;
91
92 $contextes_store[$t['id_forum']] = $t;
93 }
94
95 $fond = "notifications/forum_poste";
96 if (isset($contexte['fond'])) {
97 $fond = $contexte['fond'];
98 unset($contexte['fond']);
99 }
100 $t = array_merge($contextes_store[$t['id_forum']], $contexte);
101 // Rechercher eventuellement la langue du destinataire
102 if (null !== ($l = sql_getfetsel('lang', 'spip_auteurs', "email=" . sql_quote($email)))) {
103 $l = lang_select($l);
104 }
105
106 $parauteur = (strlen($t['auteur']) <= 2) ? '' :
107 (" " . _T('forum_par_auteur', array(
108 'auteur' => $t['auteur']
109 )
110 ) .
111 ($t['email_auteur'] ? ' <' . $t['email_auteur'] . '>' : ''));
112
113 $titre = textebrut(typo($t['titre_source']));
114 if ($titre) {
115 $forum_poste_par = _T(
116 $t['objet'] == 'article' ? 'forum:forum_poste_par' : 'forum:forum_poste_par_generique',
117 array('parauteur' => $parauteur, 'titre' => $titre, 'objet' => $t['objet'])
118 );
119 } else {
120 $forum_poste_par = _T('forum:forum_poste_par_court', array('parauteur' => $parauteur));
121 }
122
123 $t['par_auteur'] = $forum_poste_par;
124
125 $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
126 $corps = recuperer_fond($fond, $t);
127
128 if ($l) {
129 lang_select();
130 }
131
132 return $corps;
133 }