| [ Index ] |
|
Code source de SPIP 1.9.2c |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2007 * 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 // La fonction de notification de base, qui dispatche le travail 17 // http://doc.spip.org/@inc_notifications_dist 18 function inc_notifications_dist($quoi, $id=0, $options=array()) { 19 if (function_exists($f = 'notifications_'.$quoi) 20 OR function_exists($f = $f.'_dist')) { 21 spip_log("$f($quoi,$id" 22 .($options?",".serialize($options):"") 23 .")"); 24 $f($quoi, $id, $options); 25 } 26 } 27 28 // Fonction appelee par divers pipelines 29 // http://doc.spip.org/@notifications_instituerarticle_dist 30 function notifications_instituerarticle_dist($quoi, $id_article, $options) { 31 32 // ne devrait jamais se produire 33 if ($options['statut'] == $options['statut_ancien']) { 34 spip_log("statut inchange"); 35 return; 36 } 37 38 include_spip('inc/lang'); 39 include_spip('inc/texte'); 40 include_spip('inc/mail'); 41 42 if ($options['statut'] == 'publie') 43 notifier_publication_article($id_article); 44 45 if ($options['statut'] == 'prop' AND $options['statut_ancien'] != 'publie') 46 notifier_proposition_article($id_article); 47 } 48 49 50 // http://doc.spip.org/@extrait_article 51 function extrait_article($row) { 52 include_spip('inc/texte'); 53 54 $id_article = $row['id_article']; 55 $titre = nettoyer_titre_email($row['titre']); 56 $chapo = $row['chapo']; 57 $texte = $row['texte']; 58 $date = $row['date']; 59 $statut = $row['statut']; 60 61 $les_auteurs = ""; 62 $result_auteurs = spip_query("SELECT nom FROM spip_auteurs AS auteurs, spip_auteurs_articles AS lien WHERE lien.id_article=$id_article AND auteurs.id_auteur=lien.id_auteur"); 63 64 while ($row = spip_fetch_array($result_auteurs)) { 65 if ($les_auteurs) $les_auteurs .= ', '; 66 $les_auteurs .= trim(supprimer_tags(typo($row['nom']))); 67 } 68 69 $extrait = "** $titre **\n"; 70 if ($les_auteurs) $extrait .= _T('info_les_auteurs_1', array('les_auteurs' => $les_auteurs)); 71 if ($statut == 'publie') $extrait .= " "._T('date_fmt_nomjour_date', array('nomjour'=>nom_jour($date), 'date'=>affdate($date))); 72 $extrait .= "\n\n".textebrut(propre(couper_intro("$chapo<p>$texte", 700)))."\n\n"; 73 return $extrait; 74 } 75 76 77 // http://doc.spip.org/@notifier_publication_article 78 function notifier_publication_article($id_article) { 79 $adresse_suivi = $GLOBALS['meta']["adresse_suivi"]; 80 $nom_site_spip = nettoyer_titre_email($GLOBALS['meta']["nom_site"]); 81 $suivi_edito = $GLOBALS['meta']["suivi_edito"]; 82 83 if ($suivi_edito == "oui") { 84 $result = spip_query("SELECT * FROM spip_articles WHERE id_article = $id_article"); 85 86 if ($row = spip_fetch_array($result)) { 87 88 // selectionne langue 89 $lang_utilisateur = $GLOBALS['spip_lang']; 90 changer_langue($row['lang']); 91 92 // URL de l'article 93 charger_generer_url(); 94 $url = url_absolue(generer_url_article($id_article, true)); 95 96 $titre = nettoyer_titre_email($row['titre']); 97 98 $sujet = _T('info_publie_1', array('nom_site_spip' => $nom_site_spip, 'titre' => $titre)); 99 $courr = _T('info_publie_2')."\n\n"; 100 101 $nom = $GLOBALS['auteur_session']['nom']; 102 $nom = trim(supprimer_tags(typo($nom))); 103 $courr .= _T('info_publie_01', array('titre' => $titre, 'connect_nom' => $nom)) 104 . "\n\n" 105 . extrait_article($row) 106 . "-> " . $url 107 . "\n"; 108 envoyer_mail($adresse_suivi, $sujet, $courr); 109 110 // reinstalle la langue utilisateur (au cas ou) 111 changer_langue($lang_utilisateur); 112 } 113 } 114 } 115 116 // http://doc.spip.org/@notifier_proposition_article 117 function notifier_proposition_article($id_article) { 118 $adresse_suivi = $GLOBALS['meta']["adresse_suivi"]; 119 $nom_site_spip = nettoyer_titre_email($GLOBALS['meta']["nom_site"]); 120 $suivi_edito = $GLOBALS['meta']["suivi_edito"]; 121 122 if ($suivi_edito == "oui") { 123 $row = spip_fetch_array(spip_query("SELECT * FROM spip_articles WHERE id_article = $id_article")); 124 if ($row) { 125 126 $lang_utilisateur = $GLOBALS['spip_lang']; 127 changer_langue($row['lang']); 128 129 $titre = nettoyer_titre_email($row['titre']); 130 131 $sujet = _T('info_propose_1', array('nom_site_spip' => $nom_site_spip, 'titre' => $titre)); 132 envoyer_mail($adresse_suivi, 133 $sujet, 134 _T('info_propose_2') 135 ."\n\n" 136 . _T('info_propose_3', array('titre' => $titre)) 137 ."\n" 138 . _T('info_propose_4') 139 ."\n" 140 . _T('info_propose_5') 141 ."\n" 142 . generer_url_ecrire("articles", "id_article=$id_article", true) 143 . "\n\n\n" 144 . extrait_article($row) 145 ); 146 changer_langue($lang_utilisateur); 147 } 148 } 149 } 150 151 // http://doc.spip.org/@email_notification_forum 152 function email_notification_forum ($t, $email) { 153 154 // Rechercher eventuellement la langue du destinataire 155 if ($l = spip_fetch_array(spip_query("SELECT lang FROM spip_auteurs WHERE email=" . _q($email)))) 156 lang_select($l['lang']); 157 158 159 charger_generer_url(); 160 161 if ($t['statut'] == 'prop') # forum modere 162 $url = generer_url_ecrire('controle_forum', "debut_id_forum=".$t['id_forum']); 163 else if (function_exists('generer_url_forum')) 164 $url = generer_url_forum($t['id_forum']); 165 else { 166 spip_log('inc-urls personnalise : ajoutez generer_url_forum() !'); 167 if ($t['id_article']) 168 $url = generer_url_article($t['id_article']).'#'.$t['id_forum']; 169 else 170 $url = './'; 171 } 172 173 if ($t['id_article']) { 174 $article = spip_fetch_array(spip_query("SELECT titre FROM spip_articles WHERE id_article="._q($t['id_article']))); 175 $titre = textebrut(typo($article['titre'])); 176 } 177 178 $sujet = "[" . 179 entites_html(textebrut(typo($GLOBALS['meta']["nom_site"]))) . 180 "] ["._T('forum_forum')."] ".typo($t['titre']); 181 182 $parauteur = (strlen($t['auteur']) <= 2) ? '' : 183 (" " ._T('forum_par_auteur', array( 184 'auteur' => $t['auteur']) 185 ) . 186 ($t['email_auteur'] ? ' <' . $t['email_auteur'] . '>' : '')); 187 188 // TODO: squelettiser 189 $corps = _T('form_forum_message_auto') . 190 "\n\n" . 191 _T('forum_poste_par', array('parauteur' => $parauteur, 192 'titre' => $titre)). 193 "\n\n" 194 . (($t['statut'] == 'publie') ? _T('forum_ne_repondez_pas')."\n" : '') 195 . url_absolue($url) 196 . "\n\n\n** ".textebrut(typo($t['titre'])) 197 ."\n\n* ".textebrut(propre($t['texte'])) 198 . "\n\n".$t['nom_site']."\n".$t['url_site']."\n"; 199 200 if ($l) 201 lang_dselect(); 202 203 return array('subject' => $sujet, 'body' => $corps); 204 } 205 206 207 // cette notification s'execute quand on valide un message 'prop'ose, 208 // dans ecrire/inc/forum_insert.php ; ici on va notifier ceux qui ne l'ont 209 // pas ete a la notification forumposte (sachant que les deux peuvent se 210 // suivre si le forum est valide directement ('pos' ou 'abo') 211 // http://doc.spip.org/@notifications_forumvalide_dist 212 function notifications_forumvalide_dist($quoi, $id_forum) { 213 $s = spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum)); 214 if (!$t = spip_fetch_array($s)) 215 return; 216 217 include_spip('inc/texte'); 218 include_spip('inc/filtres'); 219 include_spip('inc/mail'); 220 include_spip('inc/autoriser'); 221 222 223 // Qui va-t-on prevenir ? 224 $tous = array(); 225 $pasmoi = array(); 226 227 // 1. Les auteurs de l'article ; si c'est un article, ceux qui n'ont 228 // pas le droit de le moderer (les autres l'ont recu plus tot) 229 if ($t['id_article'] 230 AND $GLOBALS['meta']['prevenir_auteurs'] == 'oui') { 231 $result = spip_query("SELECT auteurs.* FROM spip_auteurs AS auteurs, spip_auteurs_articles AS lien WHERE lien.id_article="._q($t['id_article'])." AND auteurs.id_auteur=lien.id_auteur"); 232 233 while ($qui = spip_fetch_array($result)) { 234 if (!autoriser('modererforum', 'article', $t['id_article'], $qui['id_auteur'])) 235 $tous[] = $qui['email']; 236 else 237 $pasmoi[] = $qui['email']; 238 239 } 240 } 241 242 // 2. Tous les participants a ce *thread* (desactive pour l'instant) 243 // TODO: proposer une case a cocher ou un lien dans le message 244 // pour se retirer d'un troll (hack: replacer @ par % dans l'email) 245 if (defined('_SUIVI_FORUM_THREAD') 246 AND _SUIVI_FORUM_THREAD) { 247 $s = spip_query("SELECT DISTINCT(email_auteur) FROM spip_forum WHERE id_thread=".$t['id_thread']." AND email_auteur != ''"); 248 while ($r = spip_fetch_array($s)) 249 $tous[] = $r['email_auteur']; 250 } 251 252 253 // 3. Tous les auteurs des messages qui precedent (desactive egalement) 254 // (possibilite exclusive de la possibilite precedente) 255 // TODO: est-ce utile, par rapport au thread ? 256 else if (defined('_SUIVI_FORUMS_REPONSES') 257 AND _SUIVI_FORUMS_REPONSES 258 AND $t['statut'] == 'publie') { 259 $id_parent = $id_forum; 260 while ($r = spip_fetch_array(spip_query("SELECT email_auteur, id_parent FROM spip_forum WHERE id_forum=$id_parent AND statut='publie'"))) { 261 $tous[] = $r['email_auteur']; 262 $id_parent = $r['id_parent']; 263 } 264 } 265 266 // Nettoyer le tableau 267 // Ne pas ecrire au posteur du message, ni au moderateur qui active le mail, 268 // ni aux auteurs deja notifies precedemment 269 $destinataires = array(); 270 foreach ($tous as $m) { 271 if ($m = email_valide($m) 272 AND $m != trim($t['email_auteur']) 273 AND $m != $GLOBALS['auteur_session']['email'] 274 AND !in_array($m, $pasmoi)) 275 $destinataires[$m]++; 276 } 277 278 // 279 // Envoyer les emails 280 // 281 foreach (array_keys($destinataires) as $email) { 282 $msg = email_notification_forum($t, $email); 283 envoyer_mail($email, $msg['subject'], $msg['body']); 284 } 285 } 286 287 288 // http://doc.spip.org/@notifications_forumposte_dist 289 function notifications_forumposte_dist($quoi, $id_forum) { 290 $s = spip_query("SELECT * FROM spip_forum WHERE id_forum="._q($id_forum)); 291 if (!$t = spip_fetch_array($s)) 292 return; 293 294 include_spip('inc/texte'); 295 include_spip('inc/filtres'); 296 include_spip('inc/mail'); 297 include_spip('inc/autoriser'); 298 299 300 // Qui va-t-on prevenir ? 301 $tous = array(); 302 303 // 1. Les auteurs de l'article (si c'est un article), mais 304 // seulement s'ils ont le droit de le moderer (les autres seront 305 // avertis par la notifications_forumvalide). 306 if ($t['id_article'] 307 AND $GLOBALS['meta']['prevenir_auteurs'] == 'oui') { 308 $result = spip_query("SELECT auteurs.* FROM spip_auteurs AS auteurs, spip_auteurs_articles AS lien WHERE lien.id_article="._q($t['id_article'])." AND auteurs.id_auteur=lien.id_auteur"); 309 310 while ($qui = spip_fetch_array($result)) { 311 if (autoriser('modererforum', 'article', $t['id_article'], $qui['id_auteur'])) 312 $tous[] = $qui['email']; 313 } 314 } 315 316 // 2. Les moderateurs definis par mes_options 317 // TODO: a passer en meta 318 // define('_MODERATEURS_FORUM', 'email1,email2,email3'); 319 if (defined('_MODERATEURS_FORUM')) 320 foreach (explode(',', _SPIP_MODERATEURS_FORUM) as $m) { 321 $tous[] = $m; 322 } 323 324 325 // Nettoyer le tableau 326 // Ne pas ecrire au posteur du message ! 327 $destinataires = array(); 328 foreach ($tous as $m) { 329 if ($m = email_valide($m) 330 AND $m != trim($t['email_auteur'])) 331 $destinataires[$m]++; 332 } 333 334 // 335 // Envoyer les emails 336 // 337 foreach (array_keys($destinataires) as $email) { 338 $msg = email_notification_forum($t, $email); 339 envoyer_mail($email, $msg['subject'], $msg['body']); 340 } 341 342 // Notifier les autres si le forum est valide 343 if ($t['statut'] == 'publie') { 344 $notifications = charger_fonction('notifications', 'inc'); 345 $notifications('forumvalide', $id_forum); 346 } 347 } 348 349 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 10:20:27 2007 | par Balluche grâce à PHPXref 0.7 |
|