Completed
Push — master ( b6bfef...9c0450 )
by cam
08:45 queued 01:56
created
ecrire/inc/notifications.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
33 33
  */
34 34
 function inc_notifications_dist($quoi, $id = 0, $options = array()) {
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', array('args' => array('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', array('args' => array('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,14 +56,14 @@  discard block
 block discarded – undo
56 56
  * @param array $exclure
57 57
  */
58 58
 function notifications_nettoyer_emails(&$emails, $exclure = array()) {
59
-	// filtrer et unifier
60
-	$emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails))));
61
-	if ($exclure and count($exclure)) {
62
-		// nettoyer les exclusions d'abord
63
-		notifications_nettoyer_emails($exclure);
64
-		// faire un diff
65
-		$emails = array_diff($emails, $exclure);
66
-	}
59
+    // filtrer et unifier
60
+    $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails))));
61
+    if ($exclure and count($exclure)) {
62
+        // nettoyer les exclusions d'abord
63
+        notifications_nettoyer_emails($exclure);
64
+        // faire un diff
65
+        $emails = array_diff($emails, $exclure);
66
+    }
67 67
 }
68 68
 
69 69
 /**
@@ -78,86 +78,86 @@  discard block
 block discarded – undo
78 78
  * @param string $headers
79 79
  */
80 80
 function notifications_envoyer_mails($emails, $texte, $sujet = "", $from = "", $headers = "") {
81
-	// rien a faire si pas de texte !
82
-	if (!strlen($texte)) {
83
-		return;
84
-	}
85
-
86
-	// si on ne specifie qu'un email, le mettre dans un tableau
87
-	if (!is_array($emails)) {
88
-		$emails = explode(',', $emails);
89
-	}
90
-
91
-	notifications_nettoyer_emails($emails);
92
-
93
-	// tester si le mail est deja en html
94
-	if (strpos($texte, "<") !== false // eviter les tests suivants si possible
95
-		and $ttrim = trim($texte)
96
-		and substr($ttrim, 0, 1) == "<"
97
-		and substr($ttrim, -1, 1) == ">"
98
-		and stripos($ttrim, "</html>") !== false
99
-	) {
100
-
101
-		if (!strlen($sujet)) {
102
-			// dans ce cas on ruse un peu : extraire le sujet du title
103
-			if (preg_match(",<title>(.*)</title>,Uims", $texte, $m)) {
104
-				$sujet = $m[1];
105
-			} else {
106
-				// fallback, on prend le body si on le trouve
107
-				if (preg_match(",<body[^>]*>(.*)</body>,Uims", $texte, $m)) {
108
-					$ttrim = $m[1];
109
-				}
110
-
111
-				// et on extrait la premiere ligne de vrai texte...
112
-				// nettoyer le html et les retours chariots
113
-				$ttrim = textebrut($ttrim);
114
-				$ttrim = str_replace("\r\n", "\r", $ttrim);
115
-				$ttrim = str_replace("\r", "\n", $ttrim);
116
-				// decouper
117
-				$ttrim = explode("\n", trim($ttrim));
118
-				// extraire la premiere ligne de texte brut
119
-				$sujet = array_shift($ttrim);
120
-			}
121
-		}
122
-
123
-		// si besoin on ajoute le content-type dans les headers
124
-		if (stripos($headers, "Content-Type") === false) {
125
-			$headers .= "Content-Type: text/html\n";
126
-		}
127
-	}
128
-
129
-	// si le sujet est vide, extraire la premiere ligne du corps
130
-	// du mail qui est donc du texte
131
-	if (!strlen($sujet)) {
132
-		// nettoyer un peu les retours chariots
133
-		$texte = str_replace("\r\n", "\r", $texte);
134
-		$texte = str_replace("\r", "\n", $texte);
135
-		// decouper
136
-		$texte = explode("\n", trim($texte));
137
-		// extraire la premiere ligne
138
-		$sujet = array_shift($texte);
139
-		$texte = trim(implode("\n", $texte));
140
-	}
141
-
142
-	$envoyer_mail = charger_fonction('envoyer_mail', 'inc');
143
-	foreach ($emails as $email) {
144
-		// passer dans un pipeline qui permet un ajout eventuel
145
-		// (url de suivi des notifications par exemple)
146
-		$envoi = pipeline(
147
-			'notifications_envoyer_mails',
148
-			array(
149
-				'email' => $email,
150
-				'sujet' => $sujet,
151
-				'texte' => $texte,
152
-				'from' => $from,
153
-				'headers' => $headers,
154
-			)
155
-		);
156
-		$email = $envoi['email'];
157
-
158
-		job_queue_add('envoyer_mail', ">$email : " . $envoi['sujet'],
159
-			array($email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']), 'inc/');
160
-	}
81
+    // rien a faire si pas de texte !
82
+    if (!strlen($texte)) {
83
+        return;
84
+    }
85
+
86
+    // si on ne specifie qu'un email, le mettre dans un tableau
87
+    if (!is_array($emails)) {
88
+        $emails = explode(',', $emails);
89
+    }
90
+
91
+    notifications_nettoyer_emails($emails);
92
+
93
+    // tester si le mail est deja en html
94
+    if (strpos($texte, "<") !== false // eviter les tests suivants si possible
95
+        and $ttrim = trim($texte)
96
+        and substr($ttrim, 0, 1) == "<"
97
+        and substr($ttrim, -1, 1) == ">"
98
+        and stripos($ttrim, "</html>") !== false
99
+    ) {
100
+
101
+        if (!strlen($sujet)) {
102
+            // dans ce cas on ruse un peu : extraire le sujet du title
103
+            if (preg_match(",<title>(.*)</title>,Uims", $texte, $m)) {
104
+                $sujet = $m[1];
105
+            } else {
106
+                // fallback, on prend le body si on le trouve
107
+                if (preg_match(",<body[^>]*>(.*)</body>,Uims", $texte, $m)) {
108
+                    $ttrim = $m[1];
109
+                }
110
+
111
+                // et on extrait la premiere ligne de vrai texte...
112
+                // nettoyer le html et les retours chariots
113
+                $ttrim = textebrut($ttrim);
114
+                $ttrim = str_replace("\r\n", "\r", $ttrim);
115
+                $ttrim = str_replace("\r", "\n", $ttrim);
116
+                // decouper
117
+                $ttrim = explode("\n", trim($ttrim));
118
+                // extraire la premiere ligne de texte brut
119
+                $sujet = array_shift($ttrim);
120
+            }
121
+        }
122
+
123
+        // si besoin on ajoute le content-type dans les headers
124
+        if (stripos($headers, "Content-Type") === false) {
125
+            $headers .= "Content-Type: text/html\n";
126
+        }
127
+    }
128
+
129
+    // si le sujet est vide, extraire la premiere ligne du corps
130
+    // du mail qui est donc du texte
131
+    if (!strlen($sujet)) {
132
+        // nettoyer un peu les retours chariots
133
+        $texte = str_replace("\r\n", "\r", $texte);
134
+        $texte = str_replace("\r", "\n", $texte);
135
+        // decouper
136
+        $texte = explode("\n", trim($texte));
137
+        // extraire la premiere ligne
138
+        $sujet = array_shift($texte);
139
+        $texte = trim(implode("\n", $texte));
140
+    }
141
+
142
+    $envoyer_mail = charger_fonction('envoyer_mail', 'inc');
143
+    foreach ($emails as $email) {
144
+        // passer dans un pipeline qui permet un ajout eventuel
145
+        // (url de suivi des notifications par exemple)
146
+        $envoi = pipeline(
147
+            'notifications_envoyer_mails',
148
+            array(
149
+                'email' => $email,
150
+                'sujet' => $sujet,
151
+                'texte' => $texte,
152
+                'from' => $from,
153
+                'headers' => $headers,
154
+            )
155
+        );
156
+        $email = $envoi['email'];
157
+
158
+        job_queue_add('envoyer_mail', ">$email : " . $envoi['sujet'],
159
+            array($email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']), 'inc/');
160
+    }
161 161
 
162 162
 }
163 163
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
  * @return string
175 175
  */
176 176
 function email_notification_objet($id_objet, $type_objet, $modele) {
177
-	$envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
178
-	$id_type = id_table_objet($type_objet);
177
+    $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
178
+    $id_type = id_table_objet($type_objet);
179 179
 
180
-	return recuperer_fond($modele, array($id_type => $id_objet, "id" => $id_objet));
180
+    return recuperer_fond($modele, array($id_type => $id_objet, "id" => $id_objet));
181 181
 }
182 182
 
183 183
 /**
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
  * @return string
193 193
  */
194 194
 function email_notification_article($id_article, $modele) {
195
-	$envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
195
+    $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email
196 196
 
197
-	return recuperer_fond($modele, array('id_article' => $id_article));
197
+    return recuperer_fond($modele, array('id_article' => $id_article));
198 198
 }
199 199
 
200 200
 /**
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
  * @param int $id_article
205 205
  **/
206 206
 function notifier_publication_article($id_article) {
207
-	if ($GLOBALS['meta']["suivi_edito"] == "oui") {
208
-		$adresse_suivi = $GLOBALS['meta']["adresse_suivi"];
209
-		$texte = email_notification_article($id_article, "notifications/article_publie");
210
-		notifications_envoyer_mails($adresse_suivi, $texte);
211
-	}
207
+    if ($GLOBALS['meta']["suivi_edito"] == "oui") {
208
+        $adresse_suivi = $GLOBALS['meta']["adresse_suivi"];
209
+        $texte = email_notification_article($id_article, "notifications/article_publie");
210
+        notifications_envoyer_mails($adresse_suivi, $texte);
211
+    }
212 212
 }
213 213
 
214 214
 /**
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
  * @param int $id_article
219 219
  **/
220 220
 function notifier_proposition_article($id_article) {
221
-	if ($GLOBALS['meta']["suivi_edito"] == "oui") {
222
-		$adresse_suivi = $GLOBALS['meta']["adresse_suivi"];
223
-		$texte = email_notification_article($id_article, "notifications/article_propose");
224
-		notifications_envoyer_mails($adresse_suivi, $texte);
225
-	}
221
+    if ($GLOBALS['meta']["suivi_edito"] == "oui") {
222
+        $adresse_suivi = $GLOBALS['meta']["adresse_suivi"];
223
+        $texte = email_notification_article($id_article, "notifications/article_propose");
224
+        notifications_envoyer_mails($adresse_suivi, $texte);
225
+    }
226 226
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 	if ($notification = charger_fonction($quoi, 'notifications', true)) {
41 41
 		spip_log("$notification($quoi,$id"
42
-			. ($options ? "," . serialize($options) : "")
42
+			. ($options ? ",".serialize($options) : "")
43 43
 			. ")", 'notifications');
44 44
 		$notification($quoi, $id, $options);
45 45
 	}
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		);
156 156
 		$email = $envoi['email'];
157 157
 
158
-		job_queue_add('envoyer_mail', ">$email : " . $envoi['sujet'],
158
+		job_queue_add('envoyer_mail', ">$email : ".$envoi['sujet'],
159 159
 			array($email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']), 'inc/');
160 160
 	}
161 161
 
Please login to merge, or discard this patch.