@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Notifications |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function inc_notifications_dist($quoi, $id = 0, $options = []) { |
| 35 | 35 | |
| 36 | - // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | - // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | - pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 36 | + // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | + // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | + pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 39 | 39 | |
| 40 | - if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | - spip_log("$notification($quoi,$id" |
|
| 42 | - . ($options ? ',' . serialize($options) : '') |
|
| 43 | - . ')', 'notifications'); |
|
| 44 | - $notification($quoi, $id, $options); |
|
| 45 | - } |
|
| 40 | + if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | + spip_log("$notification($quoi,$id" |
|
| 42 | + . ($options ? ',' . serialize($options) : '') |
|
| 43 | + . ')', 'notifications'); |
|
| 44 | + $notification($quoi, $id, $options); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -56,15 +56,15 @@ discard block |
||
| 56 | 56 | * @param array $exclure |
| 57 | 57 | */ |
| 58 | 58 | function notifications_nettoyer_emails(&$emails, $exclure = []) { |
| 59 | - // filtrer et unifier |
|
| 60 | - include_spip('inc/filtres'); |
|
| 61 | - $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 62 | - if ($exclure and count($exclure)) { |
|
| 63 | - // nettoyer les exclusions d'abord |
|
| 64 | - notifications_nettoyer_emails($exclure); |
|
| 65 | - // faire un diff |
|
| 66 | - $emails = array_diff($emails, $exclure); |
|
| 67 | - } |
|
| 59 | + // filtrer et unifier |
|
| 60 | + include_spip('inc/filtres'); |
|
| 61 | + $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 62 | + if ($exclure and count($exclure)) { |
|
| 63 | + // nettoyer les exclusions d'abord |
|
| 64 | + notifications_nettoyer_emails($exclure); |
|
| 65 | + // faire un diff |
|
| 66 | + $emails = array_diff($emails, $exclure); |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -79,90 +79,90 @@ discard block |
||
| 79 | 79 | * @param string $headers |
| 80 | 80 | */ |
| 81 | 81 | function notifications_envoyer_mails($emails, $texte, $sujet = '', $from = '', $headers = '') { |
| 82 | - // rien a faire si pas de texte ! |
|
| 83 | - if (!strlen($texte)) { |
|
| 84 | - return; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 88 | - if (!is_array($emails)) { |
|
| 89 | - $emails = explode(',', $emails); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - notifications_nettoyer_emails($emails); |
|
| 93 | - |
|
| 94 | - // tester si le mail est deja en html |
|
| 95 | - if ( |
|
| 96 | - strpos($texte, '<') !== false // eviter les tests suivants si possible |
|
| 97 | - and $ttrim = trim($texte) |
|
| 98 | - and substr($ttrim, 0, 1) == '<' |
|
| 99 | - and substr($ttrim, -1, 1) == '>' |
|
| 100 | - and stripos($ttrim, '</html>') !== false |
|
| 101 | - ) { |
|
| 102 | - if (!strlen($sujet)) { |
|
| 103 | - // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 104 | - if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 105 | - $sujet = $m[1]; |
|
| 106 | - } else { |
|
| 107 | - // fallback, on prend le body si on le trouve |
|
| 108 | - if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 109 | - $ttrim = $m[1]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // et on extrait la premiere ligne de vrai texte... |
|
| 113 | - // nettoyer le html et les retours chariots |
|
| 114 | - $ttrim = textebrut($ttrim); |
|
| 115 | - $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 116 | - $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 117 | - // decouper |
|
| 118 | - $ttrim = explode("\n", trim($ttrim)); |
|
| 119 | - // extraire la premiere ligne de texte brut |
|
| 120 | - $sujet = array_shift($ttrim); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // si besoin on ajoute le content-type dans les headers |
|
| 125 | - if (stripos($headers, 'Content-Type') === false) { |
|
| 126 | - $headers .= "Content-Type: text/html\n"; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // si le sujet est vide, extraire la premiere ligne du corps |
|
| 131 | - // du mail qui est donc du texte |
|
| 132 | - if (!strlen($sujet)) { |
|
| 133 | - // nettoyer un peu les retours chariots |
|
| 134 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 135 | - $texte = str_replace("\r", "\n", $texte); |
|
| 136 | - // decouper |
|
| 137 | - $texte = explode("\n", trim($texte)); |
|
| 138 | - // extraire la premiere ligne |
|
| 139 | - $sujet = array_shift($texte); |
|
| 140 | - $texte = trim(implode("\n", $texte)); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 144 | - foreach ($emails as $email) { |
|
| 145 | - // passer dans un pipeline qui permet un ajout eventuel |
|
| 146 | - // (url de suivi des notifications par exemple) |
|
| 147 | - $envoi = pipeline( |
|
| 148 | - 'notifications_envoyer_mails', |
|
| 149 | - [ |
|
| 150 | - 'email' => $email, |
|
| 151 | - 'sujet' => $sujet, |
|
| 152 | - 'texte' => $texte, |
|
| 153 | - 'from' => $from, |
|
| 154 | - 'headers' => $headers, |
|
| 155 | - ] |
|
| 156 | - ); |
|
| 157 | - $email = $envoi['email']; |
|
| 158 | - |
|
| 159 | - job_queue_add( |
|
| 160 | - 'envoyer_mail', |
|
| 161 | - ">$email : " . $envoi['sujet'], |
|
| 162 | - [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 163 | - 'inc/' |
|
| 164 | - ); |
|
| 165 | - } |
|
| 82 | + // rien a faire si pas de texte ! |
|
| 83 | + if (!strlen($texte)) { |
|
| 84 | + return; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 88 | + if (!is_array($emails)) { |
|
| 89 | + $emails = explode(',', $emails); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + notifications_nettoyer_emails($emails); |
|
| 93 | + |
|
| 94 | + // tester si le mail est deja en html |
|
| 95 | + if ( |
|
| 96 | + strpos($texte, '<') !== false // eviter les tests suivants si possible |
|
| 97 | + and $ttrim = trim($texte) |
|
| 98 | + and substr($ttrim, 0, 1) == '<' |
|
| 99 | + and substr($ttrim, -1, 1) == '>' |
|
| 100 | + and stripos($ttrim, '</html>') !== false |
|
| 101 | + ) { |
|
| 102 | + if (!strlen($sujet)) { |
|
| 103 | + // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 104 | + if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 105 | + $sujet = $m[1]; |
|
| 106 | + } else { |
|
| 107 | + // fallback, on prend le body si on le trouve |
|
| 108 | + if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 109 | + $ttrim = $m[1]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // et on extrait la premiere ligne de vrai texte... |
|
| 113 | + // nettoyer le html et les retours chariots |
|
| 114 | + $ttrim = textebrut($ttrim); |
|
| 115 | + $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 116 | + $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 117 | + // decouper |
|
| 118 | + $ttrim = explode("\n", trim($ttrim)); |
|
| 119 | + // extraire la premiere ligne de texte brut |
|
| 120 | + $sujet = array_shift($ttrim); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // si besoin on ajoute le content-type dans les headers |
|
| 125 | + if (stripos($headers, 'Content-Type') === false) { |
|
| 126 | + $headers .= "Content-Type: text/html\n"; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // si le sujet est vide, extraire la premiere ligne du corps |
|
| 131 | + // du mail qui est donc du texte |
|
| 132 | + if (!strlen($sujet)) { |
|
| 133 | + // nettoyer un peu les retours chariots |
|
| 134 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 135 | + $texte = str_replace("\r", "\n", $texte); |
|
| 136 | + // decouper |
|
| 137 | + $texte = explode("\n", trim($texte)); |
|
| 138 | + // extraire la premiere ligne |
|
| 139 | + $sujet = array_shift($texte); |
|
| 140 | + $texte = trim(implode("\n", $texte)); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 144 | + foreach ($emails as $email) { |
|
| 145 | + // passer dans un pipeline qui permet un ajout eventuel |
|
| 146 | + // (url de suivi des notifications par exemple) |
|
| 147 | + $envoi = pipeline( |
|
| 148 | + 'notifications_envoyer_mails', |
|
| 149 | + [ |
|
| 150 | + 'email' => $email, |
|
| 151 | + 'sujet' => $sujet, |
|
| 152 | + 'texte' => $texte, |
|
| 153 | + 'from' => $from, |
|
| 154 | + 'headers' => $headers, |
|
| 155 | + ] |
|
| 156 | + ); |
|
| 157 | + $email = $envoi['email']; |
|
| 158 | + |
|
| 159 | + job_queue_add( |
|
| 160 | + 'envoyer_mail', |
|
| 161 | + ">$email : " . $envoi['sujet'], |
|
| 162 | + [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 163 | + 'inc/' |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | 180 | function email_notification_objet($id_objet, $type_objet, $modele) { |
| 181 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 182 | - $id_type = id_table_objet($type_objet); |
|
| 181 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 182 | + $id_type = id_table_objet($type_objet); |
|
| 183 | 183 | |
| 184 | - return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 184 | + return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @return string |
| 197 | 197 | */ |
| 198 | 198 | function email_notification_article($id_article, $modele) { |
| 199 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 199 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 200 | 200 | |
| 201 | - return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 201 | + return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 202 | 202 | } |