[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_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")) return;
14
15 /**
16 * Construitre l'email personalise de notification d'un forum
17 *
18 * @param array $t
19 * @param string $email
20 * @param array $contexte
21 * @return string
22 */
23 function inc_email_notification_forum_dist ($t, $email, $contexte=array()) {
24 static $contextes_store = array();
25
26 if(!isset($contextes_store[$t['id_forum']])){
27 $url = '';
28 $id_forum = $t['id_forum'];
29
30 if ($t['statut'] == 'prive') # forum prive
31 {
32 if ($t['id_objet'])
33 $url = generer_url_entite($t['id_objet'], $t['objet'], '', 'forum'.$id_forum, false);
34 }
35 else if ($t['statut'] == 'privrac') # forum general
36 {
37 $url = generer_url_ecrire('forum').'#forum'.$id_forum;
38 }
39 else if ($t['statut'] == 'privadm') # forum des admins
40 {
41 $url = generer_url_ecrire('forum','quoi=admin').'#forum'.$id_forum;
42 }
43 else if ($t['statut'] == 'publie') # forum publie
44 {
45 $url = generer_url_entite($id_forum, 'forum', '', 'forum'.$id_forum, true);
46 }
47 else # forum modere, spam, poubelle direct ....
48 {
49 $url = generer_url_ecrire('controler_forum', "debut_id_forum=".$id_forum);
50 }
51
52 if (!$url) {
53 spip_log("forum $id_forum sans referent",'notifications');
54 $url = './';
55 }
56 if ($t['id_objet']) {
57 include_spip('inc/filtres');
58 $t['titre_source'] = generer_info_entite($t['id_objet'], $t['objet'], 'titre');
59 }
60
61 $t['url'] = $url;
62
63 // detecter les url des liens du forum
64 // pour la moderation (permet de reperer les SPAMS avec des liens caches)
65 // il faut appliquer le traitement de raccourci car sinon on rate des liens sous forme [->..] utilises par les spammeurs !
66 include_spip("public/interfaces");
67 $table_objet = "forum";
68
69 $links = array();
70 foreach ($t as $champ=>$v){
71 $champ = strtoupper($champ);
72 $traitement = (isset($GLOBALS['table_des_traitements'][$champ])?$GLOBALS['table_des_traitements'][$champ]:null);
73 if (is_array($traitement)
74 AND (isset($traitement[$table_objet]) OR isset($traitement[0]))){
75 $traitement = $traitement[isset($traitement[$table_objet]) ? $table_objet : 0];
76 $traitement = str_replace('%s', "'".texte_script($v)."'", $traitement);
77 eval("\$v = $traitement;");
78 }
79
80 $links = $links + extraire_balises($v,'a');
81 }
82 $links = extraire_attribut($links,'href');
83 $links = implode("\n",$links);
84 $t['liens'] = $links;
85
86 $contextes_store[$t['id_forum']] = $t;
87 }
88
89 $fond = "notifications/forum_poste";
90 if (isset($contexte['fond'])){
91 $fond = $contexte['fond'];
92 unset($contexte['fond']);
93 }
94 $t = array_merge($contextes_store[$t['id_forum']],$contexte);
95 // Rechercher eventuellement la langue du destinataire
96 if (NULL !== ($l = sql_getfetsel('lang', 'spip_auteurs', "email=" . sql_quote($email))))
97 $l = lang_select($l);
98
99 $parauteur = (strlen($t['auteur']) <= 2) ? '' :
100 (" " ._T('forum_par_auteur', array(
101 'auteur' => $t['auteur'])
102 ) .
103 ($t['email_auteur'] ? ' <' . $t['email_auteur'] . '>' : ''));
104
105 $titre = textebrut(typo($t['titre_source']));
106 if ($titre){
107 $forum_poste_par = _T(
108 $t['objet']=='article'?'forum:forum_poste_par':'forum:forum_poste_par_generique',
109 array('parauteur' => $parauteur, 'titre' => $titre, 'objet'=>$t['objet'])
110 );
111 }
112 else
113 $forum_poste_par = _T('forum:forum_poste_par_court',array('parauteur' => $parauteur));
114
115 $t['par_auteur'] = $forum_poste_par;
116
117 $envoyer_mail = charger_fonction('envoyer_mail','inc'); // pour nettoyer_titre_email
118 $corps = recuperer_fond($fond,$t);
119
120 if ($l)
121 lang_select();
122
123 return $corps;
124 }