Completed
Push — master ( e68145...07e863 )
by cam
01:46
created
ecrire/inc/modeles.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // traite les modeles (dans la fonction typo), en remplacant
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
 // mais on renvoie les params (pour l'indexation par le moteur de recherche)
23 23
 
24 24
 define(
25
-	'_PREG_MODELE',
26
-	'(<([a-z_-]{3,})' # <modele
27
-	. '\s*([0-9]*)\s*' # id
28
-	. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
29
-	. '\s*/?' . '>)' # fin du modele >
25
+    '_PREG_MODELE',
26
+    '(<([a-z_-]{3,})' # <modele
27
+    . '\s*([0-9]*)\s*' # id
28
+    . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
29
+    . '\s*/?' . '>)' # fin du modele >
30 30
 );
31 31
 
32 32
 define(
33
-	'_RACCOURCI_MODELE',
34
-	_PREG_MODELE
35
-	. '\s*(<\/a>)?' # eventuel </a>
33
+    '_RACCOURCI_MODELE',
34
+    _PREG_MODELE
35
+    . '\s*(<\/a>)?' # eventuel </a>
36 36
 );
37 37
 
38 38
 define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
@@ -46,63 +46,63 @@  discard block
 block discarded – undo
46 46
  */
47 47
 function modeles_collecter($texte, bool $collecter_liens = true) {
48 48
 
49
-	$modeles = [];
50
-	// detecter les modeles (rapide)
51
-	if (
52
-		strpos($texte, '<') !== false
53
-		and preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
54
-	) {
55
-		$pos = 0;
56
-		// Recuperer l'appel complet (y compris un eventuel lien)
57
-		foreach ($matches as $match) {
58
-			$a = strpos($texte, (string)$match[0], $pos);
59
-
60
-			if (preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs)) {
61
-				// s'assurer qu'il y a toujours un 5e arg, eventuellement vide
62
-				while (count($regs) < 6) {
63
-					$regs[] = '';
64
-				}
65
-
66
-				[, $mod, $type, $id, $params, $fermeture_lien] = $regs;
67
-
68
-				if (
69
-					$collecter_liens
70
-					and $fermeture_lien
71
-					and $before = substr($texte, $pos, $a - $pos)
72
-					and stripos($before, '<a') !== false
73
-					and preg_match('/<a\s[^<>]*>\s*$/i', $before, $r)
74
-				) {
75
-					$lien = [
76
-						'href' => extraire_attribut($r[0], 'href'),
77
-						'class' => extraire_attribut($r[0], 'class'),
78
-						'mime' => extraire_attribut($r[0], 'type'),
79
-						'title' => extraire_attribut($r[0], 'title'),
80
-						'hreflang' => extraire_attribut($r[0], 'hreflang')
81
-					];
82
-					$n = strlen($r[0]);
83
-					$a -= $n;
84
-					$longueur = $n + strlen($regs[0]);
85
-				} else {
86
-					$lien = false;
87
-					$longueur = strlen($mod);
88
-				}
89
-
90
-				$modele = [
91
-					'modele' => $mod,
92
-					'pos' => $a,
93
-					'length' => $longueur,
94
-					'type' => $type,
95
-					'id' => $id,
96
-					'params' => $params,
97
-					'lien' => $lien,
98
-				];
99
-
100
-				$modeles[] = $modele;
101
-			}
102
-			$pos = $a + strlen((string)$match[0]);
103
-		}
104
-	}
105
-	return $modeles;
49
+    $modeles = [];
50
+    // detecter les modeles (rapide)
51
+    if (
52
+        strpos($texte, '<') !== false
53
+        and preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
54
+    ) {
55
+        $pos = 0;
56
+        // Recuperer l'appel complet (y compris un eventuel lien)
57
+        foreach ($matches as $match) {
58
+            $a = strpos($texte, (string)$match[0], $pos);
59
+
60
+            if (preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs)) {
61
+                // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
62
+                while (count($regs) < 6) {
63
+                    $regs[] = '';
64
+                }
65
+
66
+                [, $mod, $type, $id, $params, $fermeture_lien] = $regs;
67
+
68
+                if (
69
+                    $collecter_liens
70
+                    and $fermeture_lien
71
+                    and $before = substr($texte, $pos, $a - $pos)
72
+                    and stripos($before, '<a') !== false
73
+                    and preg_match('/<a\s[^<>]*>\s*$/i', $before, $r)
74
+                ) {
75
+                    $lien = [
76
+                        'href' => extraire_attribut($r[0], 'href'),
77
+                        'class' => extraire_attribut($r[0], 'class'),
78
+                        'mime' => extraire_attribut($r[0], 'type'),
79
+                        'title' => extraire_attribut($r[0], 'title'),
80
+                        'hreflang' => extraire_attribut($r[0], 'hreflang')
81
+                    ];
82
+                    $n = strlen($r[0]);
83
+                    $a -= $n;
84
+                    $longueur = $n + strlen($regs[0]);
85
+                } else {
86
+                    $lien = false;
87
+                    $longueur = strlen($mod);
88
+                }
89
+
90
+                $modele = [
91
+                    'modele' => $mod,
92
+                    'pos' => $a,
93
+                    'length' => $longueur,
94
+                    'type' => $type,
95
+                    'id' => $id,
96
+                    'params' => $params,
97
+                    'lien' => $lien,
98
+                ];
99
+
100
+                $modeles[] = $modele;
101
+            }
102
+            $pos = $a + strlen((string)$match[0]);
103
+        }
104
+    }
105
+    return $modeles;
106 106
 }
107 107
 
108 108
 /**
@@ -116,24 +116,24 @@  discard block
 block discarded – undo
116 116
  */
117 117
 function modeles_echapper_raccourcis($texte, bool $collecter_liens = false) {
118 118
 
119
-	$modeles = modeles_collecter($texte, $collecter_liens);
120
-	$markid = '';
121
-	if (!empty($modeles)) {
122
-		// generer un marqueur qui n'est pas dans le texte
123
-		do {
124
-			$markid = substr(md5(creer_uniqid()), 0, 7);
125
-			$markid = "@|MODELE$markid|";
126
-		} while (strpos($texte, $markid) !== false);
127
-
128
-		$offset_pos = 0;
129
-		foreach ($modeles as $m) {
130
-			$rempl = $markid . base64_encode($m['modele']) . '|@';
131
-			$texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']);
132
-			$offset_pos += strlen($rempl) - $m['length'];
133
-		}
134
-	}
135
-
136
-	return [$texte, $markid];
119
+    $modeles = modeles_collecter($texte, $collecter_liens);
120
+    $markid = '';
121
+    if (!empty($modeles)) {
122
+        // generer un marqueur qui n'est pas dans le texte
123
+        do {
124
+            $markid = substr(md5(creer_uniqid()), 0, 7);
125
+            $markid = "@|MODELE$markid|";
126
+        } while (strpos($texte, $markid) !== false);
127
+
128
+        $offset_pos = 0;
129
+        foreach ($modeles as $m) {
130
+            $rempl = $markid . base64_encode($m['modele']) . '|@';
131
+            $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']);
132
+            $offset_pos += strlen($rempl) - $m['length'];
133
+        }
134
+    }
135
+
136
+    return [$texte, $markid];
137 137
 }
138 138
 
139 139
 /**
@@ -146,24 +146,24 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function modele_retablir_raccourcis_echappes(string $texte, string $markid) {
148 148
 
149
-	if ($markid) {
150
-		$pos = 0;
151
-		while (
152
-			($p = strpos($texte, $markid, $pos)) !== false
153
-			and $end = strpos($texte, '|@', $p + 16)
154
-		) {
155
-			$base64 = substr($texte, $p + 16, $end - ($p + 16));
156
-			if ($modele = base64_decode($base64, true)) {
157
-				$texte = substr_replace($texte, $modele, $p, $end + 2 - $p);
158
-				$pos = $p + strlen($modele);
159
-			}
160
-			else {
161
-				$pos = $end;
162
-			}
163
-		}
164
-	}
165
-
166
-	return $texte;
149
+    if ($markid) {
150
+        $pos = 0;
151
+        while (
152
+            ($p = strpos($texte, $markid, $pos)) !== false
153
+            and $end = strpos($texte, '|@', $p + 16)
154
+        ) {
155
+            $base64 = substr($texte, $p + 16, $end - ($p + 16));
156
+            if ($modele = base64_decode($base64, true)) {
157
+                $texte = substr_replace($texte, $modele, $p, $end + 2 - $p);
158
+                $pos = $p + strlen($modele);
159
+            }
160
+            else {
161
+                $pos = $end;
162
+            }
163
+        }
164
+    }
165
+
166
+    return $texte;
167 167
 }
168 168
 
169 169
 
@@ -178,82 +178,82 @@  discard block
 block discarded – undo
178 178
  * @return string
179 179
  */
180 180
 function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', ?string $markidliens = null, $env = []) {
181
-	// preserver la compatibilite : true = recherche des documents
182
-	if ($doublons === true) {
183
-		$doublons = ['documents' => ['doc', 'emb', 'img']];
184
-	}
185
-
186
-	$modeles = modeles_collecter($texte, true);
187
-	if (!empty($modeles)) {
188
-		include_spip('public/assembler');
189
-		$wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
190
-
191
-		$offset_pos = 0;
192
-		foreach ($modeles as $m) {
193
-			// calculer le modele
194
-			# hack indexation
195
-			if ($doublons) {
196
-				$texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']);
197
-			} # version normale
198
-			else {
199
-				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
200
-				// dans les parametres, plutot que les liens echappes
201
-				$params = $m['params'];
202
-				if (!is_null($markidliens)) {
203
-					$params = liens_retablir_raccourcis_echappes($params, $markidliens);
204
-				}
205
-
206
-				$modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env);
207
-
208
-				// en cas d'echec,
209
-				// si l'objet demande a une url,
210
-				// creer un petit encadre vers elle
211
-				if ($modele === false) {
212
-					$modele = $m['modele'];
213
-
214
-					if (!is_null($markidliens)) {
215
-						$modele = liens_retablir_raccourcis_echappes($modele, $markidliens);
216
-					}
217
-
218
-					$contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]);
219
-
220
-					if (!empty($m['lien'])) {
221
-						# un eventuel guillemet (") sera reechappe par #ENV
222
-						$contexte['lien'] = str_replace('&quot;', '"', $m['lien']['href']);
223
-						$contexte['lien_class'] = $m['lien']['class'];
224
-						$contexte['lien_mime'] = $m['lien']['mime'];
225
-						$contexte['lien_title'] = $m['lien']['title'];
226
-						$contexte['lien_hreflang'] = $m['lien']['hreflang'];
227
-					}
228
-
229
-					$modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? '');
230
-				}
231
-
232
-				// le remplacer dans le texte
233
-				if ($modele !== false) {
234
-					$modele = protege_js_modeles($modele);
235
-
236
-					if ($wrap_embed_html) {
237
-						$modele = $wrap_embed_html($m['modele'], $modele);
238
-					}
239
-
240
-					$rempl = code_echappement($modele, $echap);
241
-					$texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']);
242
-					$offset_pos += strlen($rempl) - $m['length'];
243
-				}
244
-			}
245
-
246
-			// hack pour tout l'espace prive
247
-			if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) {
248
-				$type = strtolower($m['type']);
249
-				foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) {
250
-					if (in_array($type, $modeles)) {
251
-						$GLOBALS["doublons_{$quoi}_inclus"][] = $m['id'];
252
-					}
253
-				}
254
-			}
255
-		}
256
-	}
257
-
258
-	return $texte;
181
+    // preserver la compatibilite : true = recherche des documents
182
+    if ($doublons === true) {
183
+        $doublons = ['documents' => ['doc', 'emb', 'img']];
184
+    }
185
+
186
+    $modeles = modeles_collecter($texte, true);
187
+    if (!empty($modeles)) {
188
+        include_spip('public/assembler');
189
+        $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
190
+
191
+        $offset_pos = 0;
192
+        foreach ($modeles as $m) {
193
+            // calculer le modele
194
+            # hack indexation
195
+            if ($doublons) {
196
+                $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']);
197
+            } # version normale
198
+            else {
199
+                // si un tableau de liens a ete passe, reinjecter le contenu d'origine
200
+                // dans les parametres, plutot que les liens echappes
201
+                $params = $m['params'];
202
+                if (!is_null($markidliens)) {
203
+                    $params = liens_retablir_raccourcis_echappes($params, $markidliens);
204
+                }
205
+
206
+                $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env);
207
+
208
+                // en cas d'echec,
209
+                // si l'objet demande a une url,
210
+                // creer un petit encadre vers elle
211
+                if ($modele === false) {
212
+                    $modele = $m['modele'];
213
+
214
+                    if (!is_null($markidliens)) {
215
+                        $modele = liens_retablir_raccourcis_echappes($modele, $markidliens);
216
+                    }
217
+
218
+                    $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]);
219
+
220
+                    if (!empty($m['lien'])) {
221
+                        # un eventuel guillemet (") sera reechappe par #ENV
222
+                        $contexte['lien'] = str_replace('&quot;', '"', $m['lien']['href']);
223
+                        $contexte['lien_class'] = $m['lien']['class'];
224
+                        $contexte['lien_mime'] = $m['lien']['mime'];
225
+                        $contexte['lien_title'] = $m['lien']['title'];
226
+                        $contexte['lien_hreflang'] = $m['lien']['hreflang'];
227
+                    }
228
+
229
+                    $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? '');
230
+                }
231
+
232
+                // le remplacer dans le texte
233
+                if ($modele !== false) {
234
+                    $modele = protege_js_modeles($modele);
235
+
236
+                    if ($wrap_embed_html) {
237
+                        $modele = $wrap_embed_html($m['modele'], $modele);
238
+                    }
239
+
240
+                    $rempl = code_echappement($modele, $echap);
241
+                    $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']);
242
+                    $offset_pos += strlen($rempl) - $m['length'];
243
+                }
244
+            }
245
+
246
+            // hack pour tout l'espace prive
247
+            if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) {
248
+                $type = strtolower($m['type']);
249
+                foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) {
250
+                    if (in_array($type, $modeles)) {
251
+                        $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id'];
252
+                    }
253
+                }
254
+            }
255
+        }
256
+    }
257
+
258
+    return $texte;
259 259
 }
Please login to merge, or discard this patch.
ecrire/inc/texte_mini.php 3 patches
Indentation   +466 added lines, -466 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/filtres');
23 23
 include_spip('inc/lang');
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function definir_puce() {
41 41
 
42
-	// Attention au sens, qui n'est pas defini de la meme facon dans
43
-	// l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
-	// celle du texte) et public (spip_lang est la langue du texte)
45
-	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
42
+    // Attention au sens, qui n'est pas defini de la meme facon dans
43
+    // l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
+    // celle du texte) et public (spip_lang est la langue du texte)
45
+    $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
-	if ($dir == 'rtl') {
49
-		$p .= '_rtl';
50
-	}
47
+    $p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
+    if ($dir == 'rtl') {
49
+        $p .= '_rtl';
50
+    }
51 51
 
52
-	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
-	}
52
+    if (!isset($GLOBALS[$p])) {
53
+        $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
+    }
55 55
 
56
-	return $GLOBALS[$p];
56
+    return $GLOBALS[$p];
57 57
 }
58 58
 
59 59
 
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 // dont on souhaite qu'ils provoquent un saut de paragraphe
62 62
 
63 63
 if (!defined('_BALISES_BLOCS')) {
64
-	define(
65
-		'_BALISES_BLOCS',
66
-		'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
67
-	);
64
+    define(
65
+        '_BALISES_BLOCS',
66
+        'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
67
+    );
68 68
 }
69 69
 
70 70
 if (!defined('_BALISES_BLOCS_REGEXP')) {
71
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
71
+    define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
72 72
 }
73 73
 
74 74
 //
@@ -79,106 +79,106 @@  discard block
 block discarded – undo
79 79
 // une $source differente ; le script detecte automagiquement si ce qu'on
80 80
 // echappe est un div ou un span
81 81
 function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) {
82
-	if (!strlen($rempl)) {
83
-		return '';
84
-	}
85
-
86
-	// Tester si on echappe en span ou en div
87
-	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
88
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
89
-	}
90
-
91
-	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
92
-	$taille = 30000;
93
-	$return = '';
94
-	for ($i = 0; $i < strlen($rempl); $i += $taille) {
95
-		// Convertir en base64 et cacher dans un attribut
96
-		// utiliser les " pour eviter le re-encodage de ' et &#8217
97
-		$base64 = base64_encode(substr($rempl, $i, $taille));
98
-		$return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
99
-	}
100
-
101
-	return $return;
82
+    if (!strlen($rempl)) {
83
+        return '';
84
+    }
85
+
86
+    // Tester si on echappe en span ou en div
87
+    if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
88
+        $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
89
+    }
90
+
91
+    // Decouper en morceaux, base64 a des probleme selon la taille de la pile
92
+    $taille = 30000;
93
+    $return = '';
94
+    for ($i = 0; $i < strlen($rempl); $i += $taille) {
95
+        // Convertir en base64 et cacher dans un attribut
96
+        // utiliser les " pour eviter le re-encodage de ' et &#8217
97
+        $base64 = base64_encode(substr($rempl, $i, $taille));
98
+        $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
99
+    }
100
+
101
+    return $return;
102 102
 }
103 103
 
104 104
 
105 105
 // Echapper les <html>...</ html>
106 106
 function traiter_echap_html_dist($regs, $options = []) {
107
-	return $regs[3];
107
+    return $regs[3];
108 108
 }
109 109
 
110 110
 // Echapper les <pre>...</ pre>
111 111
 function traiter_echap_pre_dist($regs, $options = []) {
112
-	// echapper les <code> dans <pre>
113
-	$pre = $regs[3];
114
-
115
-	// echapper les < dans <code>
116
-	// on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
117
-	if (
118
-		strpos($pre, '<') !== false
119
-		and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
120
-	) {
121
-		foreach ($matches as $m) {
122
-			if ($m[1] === 'code') {
123
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
124
-				$pre = str_replace($m[0], $code, $pre);
125
-			}
126
-		}
127
-	}
128
-	return "<pre>$pre</pre>";
112
+    // echapper les <code> dans <pre>
113
+    $pre = $regs[3];
114
+
115
+    // echapper les < dans <code>
116
+    // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
117
+    if (
118
+        strpos($pre, '<') !== false
119
+        and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
120
+    ) {
121
+        foreach ($matches as $m) {
122
+            if ($m[1] === 'code') {
123
+                $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
124
+                $pre = str_replace($m[0], $code, $pre);
125
+            }
126
+        }
127
+    }
128
+    return "<pre>$pre</pre>";
129 129
 }
130 130
 
131 131
 // Echapper les <code>...</ code>
132 132
 function traiter_echap_code_dist($regs, $options = []) {
133
-	[, , $att, $corps] = $regs;
134
-	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
135
-
136
-	// ne pas mettre le <div...> s'il n'y a qu'une ligne
137
-	if (is_int(strpos($echap, "\n"))) {
138
-		// supprimer les sauts de ligne debut/fin
139
-		// (mais pas les espaces => ascii art).
140
-		$echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap);
141
-		$echap = nl2br($echap);
142
-		$echap = "<div style='text-align: left;' "
143
-			. "class='spip_code' dir='ltr'><code$att>"
144
-			. $echap . '</code></div>';
145
-	} else {
146
-		$echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>';
147
-	}
148
-
149
-	$echap = str_replace("\t", '&nbsp; &nbsp; &nbsp; &nbsp; ', $echap);
150
-	$echap = str_replace('  ', ' &nbsp;', $echap);
151
-
152
-	return $echap;
133
+    [, , $att, $corps] = $regs;
134
+    $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
135
+
136
+    // ne pas mettre le <div...> s'il n'y a qu'une ligne
137
+    if (is_int(strpos($echap, "\n"))) {
138
+        // supprimer les sauts de ligne debut/fin
139
+        // (mais pas les espaces => ascii art).
140
+        $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap);
141
+        $echap = nl2br($echap);
142
+        $echap = "<div style='text-align: left;' "
143
+            . "class='spip_code' dir='ltr'><code$att>"
144
+            . $echap . '</code></div>';
145
+    } else {
146
+        $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>';
147
+    }
148
+
149
+    $echap = str_replace("\t", '&nbsp; &nbsp; &nbsp; &nbsp; ', $echap);
150
+    $echap = str_replace('  ', ' &nbsp;', $echap);
151
+
152
+    return $echap;
153 153
 }
154 154
 
155 155
 // Echapper les <cadre>...</ cadre> aka <frame>...</ frame>
156 156
 function traiter_echap_cadre_dist($regs, $options = []) {
157
-	$echap = trim(entites_html($regs[3]));
158
-	// compter les lignes un peu plus finement qu'avec les \n
159
-	$lignes = explode("\n", trim($echap));
160
-	$n = 0;
161
-	foreach ($lignes as $l) {
162
-		$n += floor(strlen($l) / 60) + 1;
163
-	}
164
-	$n = max($n, 2);
165
-	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
166
-
167
-	return $echap;
157
+    $echap = trim(entites_html($regs[3]));
158
+    // compter les lignes un peu plus finement qu'avec les \n
159
+    $lignes = explode("\n", trim($echap));
160
+    $n = 0;
161
+    foreach ($lignes as $l) {
162
+        $n += floor(strlen($l) / 60) + 1;
163
+    }
164
+    $n = max($n, 2);
165
+    $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
166
+
167
+    return $echap;
168 168
 }
169 169
 
170 170
 function traiter_echap_frame_dist($regs, $options = []) {
171
-	return traiter_echap_cadre_dist($regs);
171
+    return traiter_echap_cadre_dist($regs);
172 172
 }
173 173
 
174 174
 function traiter_echap_script_dist($regs, $options = []) {
175
-	// rendre joli (et inactif) si c'est un script language=php
176
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
177
-		return highlight_string($regs[0], true);
178
-	}
175
+    // rendre joli (et inactif) si c'est un script language=php
176
+    if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
177
+        return highlight_string($regs[0], true);
178
+    }
179 179
 
180
-	// Cas normal : le script passe tel quel
181
-	return $regs[0];
180
+    // Cas normal : le script passe tel quel
181
+    return $regs[0];
182 182
 }
183 183
 
184 184
 define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS');
@@ -197,73 +197,73 @@  discard block
 block discarded – undo
197 197
  * @return string|string[]
198 198
  */
199 199
 function echappe_html(
200
-	$letexte,
201
-	$source = '',
202
-	$no_transform = false,
203
-	$preg = '',
204
-	$callback_prefix = '',
205
-	$callback_options = []
200
+    $letexte,
201
+    $source = '',
202
+    $no_transform = false,
203
+    $preg = '',
204
+    $callback_prefix = '',
205
+    $callback_options = []
206 206
 ) {
207
-	if (!is_string($letexte) or !strlen($letexte)) {
208
-		return $letexte;
209
-	}
210
-
211
-	if (
212
-		($preg or strpos($letexte, '<') !== false)
213
-		and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
214
-	) {
215
-		foreach ($matches as $regs) {
216
-			// echappements tels quels ?
217
-			if ($no_transform) {
218
-				$echap = $regs[0];
219
-			} // sinon les traiter selon le cas
220
-			else {
221
-				$callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
222
-				if (
223
-					function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
224
-					or function_exists($f = $f . '_dist')
225
-					or ($callback_secure_prefix and (
226
-						function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
227
-						or function_exists($f = $f . '_dist')
228
-					))
229
-				) {
230
-					$echap = $f($regs, $callback_options);
231
-				}
232
-			}
233
-
234
-			$p = strpos($letexte, (string) $regs[0]);
235
-			$letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
236
-		}
237
-	}
238
-
239
-	if ($no_transform) {
240
-		return $letexte;
241
-	}
242
-
243
-	// Echapper le php pour faire joli (ici, c'est pas pour la securite)
244
-	// seulement si on a echappe les <script>
245
-	// (derogatoire car on ne peut pas faire passer < ? ... ? >
246
-	// dans une callback autonommee
247
-	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
248
-		if (
249
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
250
-				',<[?].*($|[?]>),UisS',
251
-				$letexte,
252
-				$matches,
253
-				PREG_SET_ORDER
254
-			)
255
-		) {
256
-			foreach ($matches as $regs) {
257
-				$letexte = str_replace(
258
-					$regs[0],
259
-					code_echappement(highlight_string($regs[0], true), $source),
260
-					$letexte
261
-				);
262
-			}
263
-		}
264
-	}
265
-
266
-	return $letexte;
207
+    if (!is_string($letexte) or !strlen($letexte)) {
208
+        return $letexte;
209
+    }
210
+
211
+    if (
212
+        ($preg or strpos($letexte, '<') !== false)
213
+        and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
214
+    ) {
215
+        foreach ($matches as $regs) {
216
+            // echappements tels quels ?
217
+            if ($no_transform) {
218
+                $echap = $regs[0];
219
+            } // sinon les traiter selon le cas
220
+            else {
221
+                $callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
222
+                if (
223
+                    function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
224
+                    or function_exists($f = $f . '_dist')
225
+                    or ($callback_secure_prefix and (
226
+                        function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
227
+                        or function_exists($f = $f . '_dist')
228
+                    ))
229
+                ) {
230
+                    $echap = $f($regs, $callback_options);
231
+                }
232
+            }
233
+
234
+            $p = strpos($letexte, (string) $regs[0]);
235
+            $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
236
+        }
237
+    }
238
+
239
+    if ($no_transform) {
240
+        return $letexte;
241
+    }
242
+
243
+    // Echapper le php pour faire joli (ici, c'est pas pour la securite)
244
+    // seulement si on a echappe les <script>
245
+    // (derogatoire car on ne peut pas faire passer < ? ... ? >
246
+    // dans une callback autonommee
247
+    if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
248
+        if (
249
+            strpos($letexte, '<' . '?') !== false and preg_match_all(
250
+                ',<[?].*($|[?]>),UisS',
251
+                $letexte,
252
+                $matches,
253
+                PREG_SET_ORDER
254
+            )
255
+        ) {
256
+            foreach ($matches as $regs) {
257
+                $letexte = str_replace(
258
+                    $regs[0],
259
+                    code_echappement(highlight_string($regs[0], true), $source),
260
+                    $letexte
261
+                );
262
+            }
263
+        }
264
+    }
265
+
266
+    return $letexte;
267 267
 }
268 268
 
269 269
 //
@@ -271,57 +271,57 @@  discard block
 block discarded – undo
271 271
 // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
272 272
 // par propre() : exemple dans multi et dans typo()
273 273
 function echappe_retour($letexte, $source = '', $filtre = '') {
274
-	if (strpos($letexte, (string) "base64$source")) {
275
-		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
276
-		$max_prof = 5;
277
-		while (
278
-			strpos($letexte, '<') !== false
279
-			and
280
-			preg_match_all(
281
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
282
-				$letexte,
283
-				$regs,
284
-				PREG_SET_ORDER
285
-			)
286
-			and $max_prof--
287
-		) {
288
-			foreach ($regs as $reg) {
289
-				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
290
-				// recherche d'attributs supplementaires
291
-				$at = [];
292
-				foreach (['lang', 'dir'] as $attr) {
293
-					if ($a = extraire_attribut($reg[0], $attr)) {
294
-						$at[$attr] = $a;
295
-					}
296
-				}
297
-				if ($at) {
298
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
299
-					foreach ($at as $attr => $a) {
300
-						$rempl = inserer_attribut($rempl, $attr, $a);
301
-					}
302
-				}
303
-				if ($filtre) {
304
-					$rempl = $filtre($rempl);
305
-				}
306
-				$letexte = str_replace($reg[0], $rempl, $letexte);
307
-			}
308
-		}
309
-	}
310
-
311
-	return $letexte;
274
+    if (strpos($letexte, (string) "base64$source")) {
275
+        # spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
276
+        $max_prof = 5;
277
+        while (
278
+            strpos($letexte, '<') !== false
279
+            and
280
+            preg_match_all(
281
+                ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
282
+                $letexte,
283
+                $regs,
284
+                PREG_SET_ORDER
285
+            )
286
+            and $max_prof--
287
+        ) {
288
+            foreach ($regs as $reg) {
289
+                $rempl = base64_decode(extraire_attribut($reg[0], 'title'));
290
+                // recherche d'attributs supplementaires
291
+                $at = [];
292
+                foreach (['lang', 'dir'] as $attr) {
293
+                    if ($a = extraire_attribut($reg[0], $attr)) {
294
+                        $at[$attr] = $a;
295
+                    }
296
+                }
297
+                if ($at) {
298
+                    $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
299
+                    foreach ($at as $attr => $a) {
300
+                        $rempl = inserer_attribut($rempl, $attr, $a);
301
+                    }
302
+                }
303
+                if ($filtre) {
304
+                    $rempl = $filtre($rempl);
305
+                }
306
+                $letexte = str_replace($reg[0], $rempl, $letexte);
307
+            }
308
+        }
309
+    }
310
+
311
+    return $letexte;
312 312
 }
313 313
 
314 314
 // Reinserer le javascript de confiance (venant des modeles)
315 315
 
316 316
 function echappe_retour_modeles($letexte, $interdire_scripts = false) {
317
-	$letexte = echappe_retour($letexte);
317
+    $letexte = echappe_retour($letexte);
318 318
 
319
-	// Dans les appels directs hors squelette, securiser aussi ici
320
-	if ($interdire_scripts) {
321
-		$letexte = interdire_scripts($letexte);
322
-	}
319
+    // Dans les appels directs hors squelette, securiser aussi ici
320
+    if ($interdire_scripts) {
321
+        $letexte = interdire_scripts($letexte);
322
+    }
323 323
 
324
-	return trim($letexte);
324
+    return trim($letexte);
325 325
 }
326 326
 
327 327
 
@@ -349,131 +349,131 @@  discard block
 block discarded – undo
349 349
  *     Texte coupé
350 350
  **/
351 351
 function couper($texte, $taille = 50, $suite = null) {
352
-	if (!($length = strlen($texte)) or $taille <= 0) {
353
-		return '';
354
-	}
355
-	$offset = 400 + 2 * $taille;
356
-	while (
357
-		$offset < $length
358
-		and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
359
-	) {
360
-		$offset = 2 * $offset;
361
-	}
362
-	if (
363
-		$offset < $length
364
-		&& ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
365
-	) {
366
-		$p_tag_fermant = strpos($texte, '>', $offset);
367
-		if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
368
-			$offset = $p_tag_fermant + 1;
369
-		} // prolonger la coupe jusqu'au tag fermant suivant eventuel
370
-	}
371
-	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
372
-
373
-	if (!function_exists('nettoyer_raccourcis_typo')) {
374
-		include_spip('inc/lien');
375
-	}
376
-	$texte = nettoyer_raccourcis_typo($texte);
377
-
378
-	// balises de sauts de ligne et paragraphe
379
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
380
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
381
-
382
-	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
383
-	$texte = str_replace("\n\n", "\r", $texte);
384
-
385
-	// supprimer les tags
386
-	$texte = supprimer_tags($texte);
387
-	$texte = trim(str_replace("\n", ' ', $texte));
388
-	$texte .= "\n";  // marquer la fin
389
-
390
-	// corriger la longueur de coupe
391
-	// en fonction de la presence de caracteres utf
392
-	if ($GLOBALS['meta']['charset'] == 'utf-8') {
393
-		$long = charset2unicode($texte);
394
-		$long = spip_substr($long, 0, max($taille, 1));
395
-		$nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
396
-		$taille += $nbcharutf;
397
-	}
398
-
399
-
400
-	// couper au mot precedent
401
-	$long = spip_substr($texte, 0, max($taille - 4, 1));
402
-	$u = $GLOBALS['meta']['pcre_u'];
403
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
404
-	if (is_null($suite)) {
405
-		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
406
-	}
407
-	$points = $suite;
408
-
409
-	// trop court ? ne pas faire de (...)
410
-	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
411
-		$points = '';
412
-		$long = spip_substr($texte, 0, $taille);
413
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
414
-		// encore trop court ? couper au caractere
415
-		if (spip_strlen($texte) < 0.75 * $taille) {
416
-			$texte = $long;
417
-		}
418
-	} else {
419
-		$texte = $court;
420
-	}
421
-
422
-	if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
423
-	$points = '';
424
-	}
425
-
426
-	// remettre les paragraphes
427
-	$texte = preg_replace("/\r+/", "\n\n", $texte);
428
-
429
-	// supprimer l'eventuelle entite finale mal coupee
430
-	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
431
-
432
-	return quote_amp(trim($texte)) . $points;
352
+    if (!($length = strlen($texte)) or $taille <= 0) {
353
+        return '';
354
+    }
355
+    $offset = 400 + 2 * $taille;
356
+    while (
357
+        $offset < $length
358
+        and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
359
+    ) {
360
+        $offset = 2 * $offset;
361
+    }
362
+    if (
363
+        $offset < $length
364
+        && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
365
+    ) {
366
+        $p_tag_fermant = strpos($texte, '>', $offset);
367
+        if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
368
+            $offset = $p_tag_fermant + 1;
369
+        } // prolonger la coupe jusqu'au tag fermant suivant eventuel
370
+    }
371
+    $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
372
+
373
+    if (!function_exists('nettoyer_raccourcis_typo')) {
374
+        include_spip('inc/lien');
375
+    }
376
+    $texte = nettoyer_raccourcis_typo($texte);
377
+
378
+    // balises de sauts de ligne et paragraphe
379
+    $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
380
+    $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
381
+
382
+    // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
383
+    $texte = str_replace("\n\n", "\r", $texte);
384
+
385
+    // supprimer les tags
386
+    $texte = supprimer_tags($texte);
387
+    $texte = trim(str_replace("\n", ' ', $texte));
388
+    $texte .= "\n";  // marquer la fin
389
+
390
+    // corriger la longueur de coupe
391
+    // en fonction de la presence de caracteres utf
392
+    if ($GLOBALS['meta']['charset'] == 'utf-8') {
393
+        $long = charset2unicode($texte);
394
+        $long = spip_substr($long, 0, max($taille, 1));
395
+        $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
396
+        $taille += $nbcharutf;
397
+    }
398
+
399
+
400
+    // couper au mot precedent
401
+    $long = spip_substr($texte, 0, max($taille - 4, 1));
402
+    $u = $GLOBALS['meta']['pcre_u'];
403
+    $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
404
+    if (is_null($suite)) {
405
+        $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
406
+    }
407
+    $points = $suite;
408
+
409
+    // trop court ? ne pas faire de (...)
410
+    if (spip_strlen($court) < max(0.75 * $taille, 2)) {
411
+        $points = '';
412
+        $long = spip_substr($texte, 0, $taille);
413
+        $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
414
+        // encore trop court ? couper au caractere
415
+        if (spip_strlen($texte) < 0.75 * $taille) {
416
+            $texte = $long;
417
+        }
418
+    } else {
419
+        $texte = $court;
420
+    }
421
+
422
+    if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
423
+    $points = '';
424
+    }
425
+
426
+    // remettre les paragraphes
427
+    $texte = preg_replace("/\r+/", "\n\n", $texte);
428
+
429
+    // supprimer l'eventuelle entite finale mal coupee
430
+    $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
431
+
432
+    return quote_amp(trim($texte)) . $points;
433 433
 }
434 434
 
435 435
 
436 436
 function protege_js_modeles($t) {
437
-	if (isset($GLOBALS['visiteur_session'])) {
438
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
439
-			if (!defined('_PROTEGE_JS_MODELES')) {
440
-				include_spip('inc/acces');
441
-				define('_PROTEGE_JS_MODELES', creer_uniqid());
442
-			}
443
-			foreach ($r as $regs) {
444
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
445
-			}
446
-		}
447
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
448
-			if (!defined('_PROTEGE_PHP_MODELES')) {
449
-				include_spip('inc/acces');
450
-				define('_PROTEGE_PHP_MODELES', creer_uniqid());
451
-			}
452
-			foreach ($r as $regs) {
453
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
454
-			}
455
-		}
456
-	}
457
-
458
-	return $t;
437
+    if (isset($GLOBALS['visiteur_session'])) {
438
+        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
439
+            if (!defined('_PROTEGE_JS_MODELES')) {
440
+                include_spip('inc/acces');
441
+                define('_PROTEGE_JS_MODELES', creer_uniqid());
442
+            }
443
+            foreach ($r as $regs) {
444
+                $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
445
+            }
446
+        }
447
+        if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
448
+            if (!defined('_PROTEGE_PHP_MODELES')) {
449
+                include_spip('inc/acces');
450
+                define('_PROTEGE_PHP_MODELES', creer_uniqid());
451
+            }
452
+            foreach ($r as $regs) {
453
+                $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
454
+            }
455
+        }
456
+    }
457
+
458
+    return $t;
459 459
 }
460 460
 
461 461
 
462 462
 function echapper_faux_tags($letexte) {
463
-	if (strpos($letexte, '<') === false) {
464
-		return $letexte;
465
-	}
466
-	$textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
467
-
468
-	$letexte = '';
469
-	while (is_countable($textMatches) ? count($textMatches) : 0) {
470
-		// un texte a echapper
471
-		$letexte .= str_replace('<', '&lt;', array_shift($textMatches));
472
-		// un tag html qui a servit a faite le split
473
-		$letexte .= array_shift($textMatches);
474
-	}
475
-
476
-	return $letexte;
463
+    if (strpos($letexte, '<') === false) {
464
+        return $letexte;
465
+    }
466
+    $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
467
+
468
+    $letexte = '';
469
+    while (is_countable($textMatches) ? count($textMatches) : 0) {
470
+        // un texte a echapper
471
+        $letexte .= str_replace('<', '&lt;', array_shift($textMatches));
472
+        // un tag html qui a servit a faite le split
473
+        $letexte .= array_shift($textMatches);
474
+    }
475
+
476
+    return $letexte;
477 477
 }
478 478
 
479 479
 /**
@@ -493,104 +493,104 @@  discard block
 block discarded – undo
493 493
  * @return string
494 494
  */
495 495
 function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) {
496
-	static $echapper_html_suspect;
497
-	if (!$texte or !is_string($texte)) {
498
-		return $texte;
499
-	}
500
-
501
-	if (!isset($echapper_html_suspect)) {
502
-		$echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
503
-	}
504
-	// si fonction personalisee, on delegue
505
-	if ($echapper_html_suspect) {
506
-		// on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
507
-		$args = [$texte, $options];
508
-		if ($connect or !empty($env)) {
509
-			$args[] = $connect;
510
-		}
511
-		if (!empty($env)) {
512
-			$args[] = $env;
513
-		}
514
-		return $echapper_html_suspect(...$args);
515
-	}
516
-
517
-	if (is_bool($options)) {
518
-		$options = ['strict' => $options];
519
-	}
520
-	$strict = $options['strict'] ?? true;
521
-
522
-	// pas de balise html ou pas d'attribut sur les balises ? c'est OK
523
-	if (
524
-		strpos($texte, '<') === false
525
-		or strpos($texte, '=') === false
526
-	) {
527
-		return $texte;
528
-	}
529
-
530
-	// dans le prive, on veut afficher tout echappé pour la moderation
531
-	if (!isset($env['espace_prive'])) {
532
-		// conserver le comportement historique en cas d'appel court sans env
533
-		$env['espace_prive'] = test_espace_prive();
534
-	}
535
-	if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
536
-
537
-		// quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
538
-		// car sinon on declenche sur les modeles ou ressources
539
-		if (
540
-			!$strict and
541
-			(strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
542
-		) {
543
-			return $texte;
544
-		}
545
-
546
-		[$texte, $markidmodeles] = modeles_echapper_raccourcis($texte, false);
547
-		$texte = echappe_js($texte);
548
-
549
-		$texte_to_check = $texte;
550
-		// si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
551
-		// car un raccourci peut etre utilisé pour faire un lien malin
552
-		// et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
553
-		if (!empty($options['expanser_liens'])) {
554
-			$texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
555
-		}
556
-		if (!is_html_safe($texte_to_check)) {
557
-			$texte = $options['texte_source_affiche'] ?? $texte;
558
-			$texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
559
-			$texte = str_replace('<', '&lt;', $texte);
560
-			$texte = str_replace('&lt;tt>', '<tt>', $texte);
561
-			$texte = str_replace('&lt;/tt>', '</tt>', $texte);
562
-			if (!function_exists('attribut_html')) {
563
-				include_spip('inc/filtres');
564
-			}
565
-			if (!empty($options['wrap_suspect'])) {
566
-				$texte = wrap($texte, $options['wrap_suspect']);
567
-			}
568
-			$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
569
-		}
570
-		$texte = modele_retablir_raccourcis_echappes($texte, $markidmodeles);
571
-	}
572
-
573
-	// si on est là dans le public c'est le mode parano
574
-	// on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
575
-	else {
576
-		$markidmodeles = $markidliens = null;
577
-		if (!empty($options['expanser_liens'])) {
578
-			$texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
579
-		}
580
-		else {
581
-			[$texte, $markidliens] = liens_echapper_raccourcis($texte, 'safehtml');
582
-			[$texte, $markidmodeles] = modeles_echapper_raccourcis($texte, false);
583
-		}
584
-		$texte = safehtml($texte);
585
-		if ($markidmodeles) {
586
-			$texte = modele_retablir_raccourcis_echappes($texte, $markidmodeles);
587
-		}
588
-		if ($markidliens) {
589
-			$texte = liens_retablir_raccourcis_echappes($texte, $markidliens);
590
-		}
591
-	}
592
-
593
-	return $texte;
496
+    static $echapper_html_suspect;
497
+    if (!$texte or !is_string($texte)) {
498
+        return $texte;
499
+    }
500
+
501
+    if (!isset($echapper_html_suspect)) {
502
+        $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
503
+    }
504
+    // si fonction personalisee, on delegue
505
+    if ($echapper_html_suspect) {
506
+        // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
507
+        $args = [$texte, $options];
508
+        if ($connect or !empty($env)) {
509
+            $args[] = $connect;
510
+        }
511
+        if (!empty($env)) {
512
+            $args[] = $env;
513
+        }
514
+        return $echapper_html_suspect(...$args);
515
+    }
516
+
517
+    if (is_bool($options)) {
518
+        $options = ['strict' => $options];
519
+    }
520
+    $strict = $options['strict'] ?? true;
521
+
522
+    // pas de balise html ou pas d'attribut sur les balises ? c'est OK
523
+    if (
524
+        strpos($texte, '<') === false
525
+        or strpos($texte, '=') === false
526
+    ) {
527
+        return $texte;
528
+    }
529
+
530
+    // dans le prive, on veut afficher tout echappé pour la moderation
531
+    if (!isset($env['espace_prive'])) {
532
+        // conserver le comportement historique en cas d'appel court sans env
533
+        $env['espace_prive'] = test_espace_prive();
534
+    }
535
+    if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
536
+
537
+        // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
538
+        // car sinon on declenche sur les modeles ou ressources
539
+        if (
540
+            !$strict and
541
+            (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
542
+        ) {
543
+            return $texte;
544
+        }
545
+
546
+        [$texte, $markidmodeles] = modeles_echapper_raccourcis($texte, false);
547
+        $texte = echappe_js($texte);
548
+
549
+        $texte_to_check = $texte;
550
+        // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
551
+        // car un raccourci peut etre utilisé pour faire un lien malin
552
+        // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
553
+        if (!empty($options['expanser_liens'])) {
554
+            $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
555
+        }
556
+        if (!is_html_safe($texte_to_check)) {
557
+            $texte = $options['texte_source_affiche'] ?? $texte;
558
+            $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
559
+            $texte = str_replace('<', '&lt;', $texte);
560
+            $texte = str_replace('&lt;tt>', '<tt>', $texte);
561
+            $texte = str_replace('&lt;/tt>', '</tt>', $texte);
562
+            if (!function_exists('attribut_html')) {
563
+                include_spip('inc/filtres');
564
+            }
565
+            if (!empty($options['wrap_suspect'])) {
566
+                $texte = wrap($texte, $options['wrap_suspect']);
567
+            }
568
+            $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
569
+        }
570
+        $texte = modele_retablir_raccourcis_echappes($texte, $markidmodeles);
571
+    }
572
+
573
+    // si on est là dans le public c'est le mode parano
574
+    // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
575
+    else {
576
+        $markidmodeles = $markidliens = null;
577
+        if (!empty($options['expanser_liens'])) {
578
+            $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
579
+        }
580
+        else {
581
+            [$texte, $markidliens] = liens_echapper_raccourcis($texte, 'safehtml');
582
+            [$texte, $markidmodeles] = modeles_echapper_raccourcis($texte, false);
583
+        }
584
+        $texte = safehtml($texte);
585
+        if ($markidmodeles) {
586
+            $texte = modele_retablir_raccourcis_echappes($texte, $markidmodeles);
587
+        }
588
+        if ($markidliens) {
589
+            $texte = liens_retablir_raccourcis_echappes($texte, $markidliens);
590
+        }
591
+    }
592
+
593
+    return $texte;
594 594
 }
595 595
 
596 596
 
@@ -611,30 +611,30 @@  discard block
 block discarded – undo
611 611
  *      Texte sécurisé
612 612
  **/
613 613
 function safehtml($t) {
614
-	static $safehtml;
615
-
616
-	if (!$t or !is_string($t)) {
617
-		return $t;
618
-	}
619
-	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
620
-	if (strpos($t, '<') === false) {
621
-		return str_replace("\x00", '', $t);
622
-	}
623
-
624
-	if (!function_exists('interdire_scripts')) {
625
-		include_spip('inc/texte');
626
-	}
627
-	$t = interdire_scripts($t); // jolifier le php
628
-	$t = echappe_js($t);
629
-
630
-	if (!isset($safehtml)) {
631
-		$safehtml = charger_fonction('safehtml', 'inc', true);
632
-	}
633
-	if ($safehtml) {
634
-		$t = $safehtml($t);
635
-	}
636
-
637
-	return interdire_scripts($t); // interdire le php (2 precautions)
614
+    static $safehtml;
615
+
616
+    if (!$t or !is_string($t)) {
617
+        return $t;
618
+    }
619
+    # attention safehtml nettoie deux ou trois caracteres de plus. A voir
620
+    if (strpos($t, '<') === false) {
621
+        return str_replace("\x00", '', $t);
622
+    }
623
+
624
+    if (!function_exists('interdire_scripts')) {
625
+        include_spip('inc/texte');
626
+    }
627
+    $t = interdire_scripts($t); // jolifier le php
628
+    $t = echappe_js($t);
629
+
630
+    if (!isset($safehtml)) {
631
+        $safehtml = charger_fonction('safehtml', 'inc', true);
632
+    }
633
+    if ($safehtml) {
634
+        $t = $safehtml($t);
635
+    }
636
+
637
+    return interdire_scripts($t); // interdire le php (2 precautions)
638 638
 }
639 639
 
640 640
 
@@ -642,20 +642,20 @@  discard block
 block discarded – undo
642 642
  * Detecter si un texte est "safe" ie non modifie significativement par safehtml()
643 643
  */
644 644
 function is_html_safe(string $texte): bool {
645
-	if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
646
-		return $is_html_safe($texte);
647
-	}
648
-
649
-	// simplifier les retour ligne pour etre certain de ce que l'on compare
650
-	$texte = str_replace("\r\n", "\n", $texte);
651
-	// safehtml reduit aussi potentiellement les &nbsp;
652
-	$texte = str_replace("&nbsp;", " ", $texte);
653
-	$texte_safe = safehtml($texte);
654
-
655
-	// on teste sur strlen car safehtml supprime le contenu dangereux
656
-	// mais il peut aussi changer des ' en " sur les attributs html,
657
-	// donc un test d'egalite est trop strict
658
-	return strlen($texte_safe) === strlen($texte);
645
+    if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
646
+        return $is_html_safe($texte);
647
+    }
648
+
649
+    // simplifier les retour ligne pour etre certain de ce que l'on compare
650
+    $texte = str_replace("\r\n", "\n", $texte);
651
+    // safehtml reduit aussi potentiellement les &nbsp;
652
+    $texte = str_replace("&nbsp;", " ", $texte);
653
+    $texte_safe = safehtml($texte);
654
+
655
+    // on teste sur strlen car safehtml supprime le contenu dangereux
656
+    // mais il peut aussi changer des ' en " sur les attributs html,
657
+    // donc un test d'egalite est trop strict
658
+    return strlen($texte_safe) === strlen($texte);
659 659
 }
660 660
 
661 661
 /**
@@ -676,13 +676,13 @@  discard block
 block discarded – undo
676 676
  *     Texte sans les modèles d'image
677 677
  **/
678 678
 function supprime_img($letexte, $message = null) {
679
-	if ($message === null) {
680
-		$message = '(' . _T('img_indisponible') . ')';
681
-	}
682
-
683
-	return preg_replace(
684
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
685
-		$message,
686
-		$letexte
687
-	);
679
+    if ($message === null) {
680
+        $message = '(' . _T('img_indisponible') . ')';
681
+    }
682
+
683
+    return preg_replace(
684
+        ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
685
+        $message,
686
+        $letexte
687
+    );
688 688
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	// celle du texte) et public (spip_lang est la langue du texte)
45 45
 	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
47
+	$p = 'puce'.(test_espace_prive() ? '_prive' : '');
48 48
 	if ($dir == 'rtl') {
49 49
 		$p .= '_rtl';
50 50
 	}
51 51
 
52 52
 	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
53
+		$GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>';
54 54
 	}
55 55
 
56 56
 	return $GLOBALS[$p];
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 }
69 69
 
70 70
 if (!defined('_BALISES_BLOCS_REGEXP')) {
71
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
71
+	define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS');
72 72
 }
73 73
 
74 74
 //
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
 	// Tester si on echappe en span ou en div
87 87
 	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
88
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
88
+		$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
89 89
 	}
90 90
 
91 91
 	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	) {
121 121
 		foreach ($matches as $m) {
122 122
 			if ($m[1] === 'code') {
123
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
123
+				$code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>';
124 124
 				$pre = str_replace($m[0], $code, $pre);
125 125
 			}
126 126
 		}
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 // Echapper les <code>...</ code>
132 132
 function traiter_echap_code_dist($regs, $options = []) {
133
-	[, , $att, $corps] = $regs;
133
+	[,, $att, $corps] = $regs;
134 134
 	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
135 135
 
136 136
 	// ne pas mettre le <div...> s'il n'y a qu'une ligne
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 		$echap = nl2br($echap);
142 142
 		$echap = "<div style='text-align: left;' "
143 143
 			. "class='spip_code' dir='ltr'><code$att>"
144
-			. $echap . '</code></div>';
144
+			. $echap.'</code></div>';
145 145
 	} else {
146
-		$echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>';
146
+		$echap = "<code$att class='spip_code' dir='ltr'>".$echap.'</code>';
147 147
 	}
148 148
 
149 149
 	$echap = str_replace("\t", '&nbsp; &nbsp; &nbsp; &nbsp; ', $echap);
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
 			else {
221 221
 				$callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
222 222
 				if (
223
-					function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
224
-					or function_exists($f = $f . '_dist')
223
+					function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1]))
224
+					or function_exists($f = $f.'_dist')
225 225
 					or ($callback_secure_prefix and (
226
-						function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
227
-						or function_exists($f = $f . '_dist')
226
+						function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1]))
227
+						or function_exists($f = $f.'_dist')
228 228
 					))
229 229
 				) {
230 230
 					$echap = $f($regs, $callback_options);
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 	// dans une callback autonommee
247 247
 	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
248 248
 		if (
249
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
249
+			strpos($letexte, '<'.'?') !== false and preg_match_all(
250 250
 				',<[?].*($|[?]>),UisS',
251 251
 				$letexte,
252 252
 				$matches,
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 			strpos($letexte, '<') !== false
279 279
 			and
280 280
 			preg_match_all(
281
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
281
+				',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
282 282
 				$letexte,
283 283
 				$regs,
284 284
 				PREG_SET_ORDER
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 					}
296 296
 				}
297 297
 				if ($at) {
298
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
298
+					$rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
299 299
 					foreach ($at as $attr => $a) {
300 300
 						$rempl = inserer_attribut($rempl, $attr, $a);
301 301
 					}
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	$texte = nettoyer_raccourcis_typo($texte);
377 377
 
378 378
 	// balises de sauts de ligne et paragraphe
379
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
380
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
379
+	$texte = preg_replace('/<p( [^>]*)?'.'>/', "\r", $texte);
380
+	$texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte);
381 381
 
382 382
 	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
383 383
 	$texte = str_replace("\n\n", "\r", $texte);
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 	// supprimer les tags
386 386
 	$texte = supprimer_tags($texte);
387 387
 	$texte = trim(str_replace("\n", ' ', $texte));
388
-	$texte .= "\n";  // marquer la fin
388
+	$texte .= "\n"; // marquer la fin
389 389
 
390 390
 	// corriger la longueur de coupe
391 391
 	// en fonction de la presence de caracteres utf
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	// couper au mot precedent
401 401
 	$long = spip_substr($texte, 0, max($taille - 4, 1));
402 402
 	$u = $GLOBALS['meta']['pcre_u'];
403
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
403
+	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
404 404
 	if (is_null($suite)) {
405 405
 		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
406 406
 	}
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
411 411
 		$points = '';
412 412
 		$long = spip_substr($texte, 0, $taille);
413
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
413
+		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
414 414
 		// encore trop court ? couper au caractere
415 415
 		if (spip_strlen($texte) < 0.75 * $taille) {
416 416
 			$texte = $long;
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 	// supprimer l'eventuelle entite finale mal coupee
430 430
 	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
431 431
 
432
-	return quote_amp(trim($texte)) . $points;
432
+	return quote_amp(trim($texte)).$points;
433 433
 }
434 434
 
435 435
 
@@ -441,16 +441,16 @@  discard block
 block discarded – undo
441 441
 				define('_PROTEGE_JS_MODELES', creer_uniqid());
442 442
 			}
443 443
 			foreach ($r as $regs) {
444
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
444
+				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t);
445 445
 			}
446 446
 		}
447
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
447
+		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) {
448 448
 			if (!defined('_PROTEGE_PHP_MODELES')) {
449 449
 				include_spip('inc/acces');
450 450
 				define('_PROTEGE_PHP_MODELES', creer_uniqid());
451 451
 			}
452 452
 			foreach ($r as $regs) {
453
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
453
+				$t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t);
454 454
 			}
455 455
 		}
456 456
 	}
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 			if (!empty($options['wrap_suspect'])) {
566 566
 				$texte = wrap($texte, $options['wrap_suspect']);
567 567
 			}
568
-			$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
568
+			$texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte;
569 569
 		}
570 570
 		$texte = modele_retablir_raccourcis_echappes($texte, $markidmodeles);
571 571
 	}
@@ -677,11 +677,11 @@  discard block
 block discarded – undo
677 677
  **/
678 678
 function supprime_img($letexte, $message = null) {
679 679
 	if ($message === null) {
680
-		$message = '(' . _T('img_indisponible') . ')';
680
+		$message = '('._T('img_indisponible').')';
681 681
 	}
682 682
 
683 683
 	return preg_replace(
684
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
684
+		',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
685 685
 		$message,
686 686
 		$letexte
687 687
 	);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -576,8 +576,7 @@
 block discarded – undo
576 576
 		$markidmodeles = $markidliens = null;
577 577
 		if (!empty($options['expanser_liens'])) {
578 578
 			$texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
579
-		}
580
-		else {
579
+		} else {
581 580
 			[$texte, $markidliens] = liens_echapper_raccourcis($texte, 'safehtml');
582 581
 			[$texte, $markidmodeles] = modeles_echapper_raccourcis($texte, false);
583 582
 		}
Please login to merge, or discard this patch.
ecrire/inc/liens.php 3 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 
@@ -30,70 +30,70 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function liens_collecter(string $texte, ?string $sanitize_callback = null): array {
32 32
 
33
-	$liens = [];
34
-	$pos = 0;
35
-
36
-	if (strpos($texte, '->') !== false) {
37
-
38
-		$desechappe_crochets = false;
39
-		// si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer
40
-		if (strpos($texte, '\[') !== false or strpos($texte, '\]') !== false) {
41
-			$texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte);
42
-			$desechappe_crochets = true;
43
-		}
44
-
45
-		while (strpos($texte, '->', $pos) !== false
46
-		  and preg_match(_RACCOURCI_LIEN, $texte, $match, PREG_OFFSET_CAPTURE, $pos)) {
47
-
48
-			$href = end($match);
49
-			$href = $href[0];
50
-			$lien = [
51
-				'lien' => $match[0][0],
52
-				'pos' => $match[0][1],
53
-				'length' => strlen($match[0][0]),
54
-				'texte' => $match[1][0],
55
-				'href' => $href,
56
-				'ouvrant' => $match[3][0] ?? '',
57
-			];
58
-
59
-			// la mise en lien automatique est passee par la a tort !
60
-			// corrigeons pour eviter d'avoir un <a...> dans un href...
61
-			if (strncmp($href, '<a', 2) == 0) {
62
-				$href = extraire_attribut($href, 'href');
63
-				// remplacons dans la source qui peut etre reinjectee dans les arguments
64
-				// d'un modele
65
-				$lien['lien'] = str_replace($lien['href'], $href, $lien['lien']);
66
-				// et prenons le href comme la vraie url a linker
67
-				$lien['href'] = $href;
68
-			}
69
-
70
-			if ($desechappe_crochets and strpos($lien['lien'], "\x1") !== false) {
71
-				$lien['lien'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['lien']);
72
-				$lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['texte']);
73
-				$lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['href']);
74
-			}
75
-
76
-			if ($sanitize_callback) {
77
-				$t = $sanitize_callback($lien['texte']);
78
-				if ($t !== $lien['texte']) {
79
-					$lien['lien'] = str_replace($lien['texte'], $t, $lien['lien']);
80
-					$lien['texte'] = $t;
81
-				}
82
-				$href = $sanitize_callback($lien['href']);
83
-				if ($href !== $lien['href']) {
84
-					$lien['lien'] = str_replace($lien['href'], $href, $lien['lien']);
85
-					$lien['href'] = $href;
86
-				}
87
-			}
88
-
89
-			$liens[] = $lien;
90
-
91
-			$pos = $lien['pos'] + $lien['length'];
92
-		}
93
-
94
-	}
95
-
96
-	return $liens;
33
+    $liens = [];
34
+    $pos = 0;
35
+
36
+    if (strpos($texte, '->') !== false) {
37
+
38
+        $desechappe_crochets = false;
39
+        // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer
40
+        if (strpos($texte, '\[') !== false or strpos($texte, '\]') !== false) {
41
+            $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte);
42
+            $desechappe_crochets = true;
43
+        }
44
+
45
+        while (strpos($texte, '->', $pos) !== false
46
+          and preg_match(_RACCOURCI_LIEN, $texte, $match, PREG_OFFSET_CAPTURE, $pos)) {
47
+
48
+            $href = end($match);
49
+            $href = $href[0];
50
+            $lien = [
51
+                'lien' => $match[0][0],
52
+                'pos' => $match[0][1],
53
+                'length' => strlen($match[0][0]),
54
+                'texte' => $match[1][0],
55
+                'href' => $href,
56
+                'ouvrant' => $match[3][0] ?? '',
57
+            ];
58
+
59
+            // la mise en lien automatique est passee par la a tort !
60
+            // corrigeons pour eviter d'avoir un <a...> dans un href...
61
+            if (strncmp($href, '<a', 2) == 0) {
62
+                $href = extraire_attribut($href, 'href');
63
+                // remplacons dans la source qui peut etre reinjectee dans les arguments
64
+                // d'un modele
65
+                $lien['lien'] = str_replace($lien['href'], $href, $lien['lien']);
66
+                // et prenons le href comme la vraie url a linker
67
+                $lien['href'] = $href;
68
+            }
69
+
70
+            if ($desechappe_crochets and strpos($lien['lien'], "\x1") !== false) {
71
+                $lien['lien'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['lien']);
72
+                $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['texte']);
73
+                $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['href']);
74
+            }
75
+
76
+            if ($sanitize_callback) {
77
+                $t = $sanitize_callback($lien['texte']);
78
+                if ($t !== $lien['texte']) {
79
+                    $lien['lien'] = str_replace($lien['texte'], $t, $lien['lien']);
80
+                    $lien['texte'] = $t;
81
+                }
82
+                $href = $sanitize_callback($lien['href']);
83
+                if ($href !== $lien['href']) {
84
+                    $lien['lien'] = str_replace($lien['href'], $href, $lien['lien']);
85
+                    $lien['href'] = $href;
86
+                }
87
+            }
88
+
89
+            $liens[] = $lien;
90
+
91
+            $pos = $lien['pos'] + $lien['length'];
92
+        }
93
+
94
+    }
95
+
96
+    return $liens;
97 97
 }
98 98
 
99 99
 /**
@@ -106,28 +106,28 @@  discard block
 block discarded – undo
106 106
  *   texte, marqueur utilise pour echapper les modeles
107 107
  */
108 108
 function liens_echapper_raccourcis(string $texte, ?string $sanitize_callback = null): array {
109
-	if (!function_exists('creer_uniqid')) {
110
-		include_spip('inc/acces');
111
-	}
112
-
113
-	$liens = liens_collecter($texte, $sanitize_callback);
114
-	$markid = '';
115
-	if (!empty($liens)) {
116
-		// generer un marqueur qui n'est pas dans le texte
117
-		do {
118
-			$markid = substr(md5(creer_uniqid()), 0, 7);
119
-			$markid = "@|LIEN$markid|";
120
-		} while (strpos($texte, $markid) !== false);
121
-
122
-		$offset_pos = 0;
123
-		foreach ($liens as $l) {
124
-			$rempl = $markid . base64_encode($l['lien']) . '|@';
125
-			$texte = substr_replace($texte, $rempl, $l['pos'] + $offset_pos, $l['length']);
126
-			$offset_pos += strlen($rempl) - $l['length'];
127
-		}
128
-	}
129
-
130
-	return [$texte, $markid];
109
+    if (!function_exists('creer_uniqid')) {
110
+        include_spip('inc/acces');
111
+    }
112
+
113
+    $liens = liens_collecter($texte, $sanitize_callback);
114
+    $markid = '';
115
+    if (!empty($liens)) {
116
+        // generer un marqueur qui n'est pas dans le texte
117
+        do {
118
+            $markid = substr(md5(creer_uniqid()), 0, 7);
119
+            $markid = "@|LIEN$markid|";
120
+        } while (strpos($texte, $markid) !== false);
121
+
122
+        $offset_pos = 0;
123
+        foreach ($liens as $l) {
124
+            $rempl = $markid . base64_encode($l['lien']) . '|@';
125
+            $texte = substr_replace($texte, $rempl, $l['pos'] + $offset_pos, $l['length']);
126
+            $offset_pos += strlen($rempl) - $l['length'];
127
+        }
128
+    }
129
+
130
+    return [$texte, $markid];
131 131
 }
132 132
 
133 133
 /**
@@ -140,23 +140,23 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function liens_retablir_raccourcis_echappes(string $texte, string $markid): string {
142 142
 
143
-	if ($markid) {
144
-		$lm = strlen($markid);
145
-		$pos = 0;
146
-		while (
147
-			($p = strpos($texte, $markid, $pos)) !== false
148
-			and $end = strpos($texte, '|@', $p + $lm)
149
-		) {
150
-			$base64 = substr($texte, $p + $lm, $end - ($p + $lm));
151
-			if ($c = base64_decode($base64, true)) {
152
-				$texte = substr_replace($texte, $c, $p, $end + 2 - $p);
153
-				$pos = $p + strlen($c);
154
-			}
155
-			else {
156
-				$pos = $end;
157
-			}
158
-		}
159
-	}
160
-
161
-	return $texte;
143
+    if ($markid) {
144
+        $lm = strlen($markid);
145
+        $pos = 0;
146
+        while (
147
+            ($p = strpos($texte, $markid, $pos)) !== false
148
+            and $end = strpos($texte, '|@', $p + $lm)
149
+        ) {
150
+            $base64 = substr($texte, $p + $lm, $end - ($p + $lm));
151
+            if ($c = base64_decode($base64, true)) {
152
+                $texte = substr_replace($texte, $c, $p, $end + 2 - $p);
153
+                $pos = $p + strlen($c);
154
+            }
155
+            else {
156
+                $pos = $end;
157
+            }
158
+        }
159
+    }
160
+
161
+    return $texte;
162 162
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 
122 122
 		$offset_pos = 0;
123 123
 		foreach ($liens as $l) {
124
-			$rempl = $markid . base64_encode($l['lien']) . '|@';
124
+			$rempl = $markid.base64_encode($l['lien']).'|@';
125 125
 			$texte = substr_replace($texte, $rempl, $l['pos'] + $offset_pos, $l['length']);
126 126
 			$offset_pos += strlen($rempl) - $l['length'];
127 127
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -151,8 +151,7 @@
 block discarded – undo
151 151
 			if ($c = base64_decode($base64, true)) {
152 152
 				$texte = substr_replace($texte, $c, $p, $end + 2 - $p);
153 153
 				$pos = $p + strlen($c);
154
-			}
155
-			else {
154
+			} else {
156 155
 				$pos = $end;
157 156
 			}
158 157
 		}
Please login to merge, or discard this patch.
ecrire/inc/lien.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('base/abstract_sql');
@@ -37,42 +37,42 @@  discard block
 block discarded – undo
37 37
  * @return string
38 38
  */
39 39
 function inc_lien_dist(
40
-	$lien,
41
-	$texte = '',
42
-	$class = '',
43
-	$title = '',
44
-	$hlang = '',
45
-	$rel = '',
46
-	string $connect = '',
47
-	$env = []
40
+    $lien,
41
+    $texte = '',
42
+    $class = '',
43
+    $title = '',
44
+    $hlang = '',
45
+    $rel = '',
46
+    string $connect = '',
47
+    $env = []
48 48
 ) {
49
-	return $lien;
49
+    return $lien;
50 50
 }
51 51
 
52 52
 function expanser_liens($t, string $connect = '', $env = []) {
53 53
 
54
-	$t = pipeline('pre_liens', $t);
54
+    $t = pipeline('pre_liens', $t);
55 55
 
56
-	// on passe a traiter_modeles la liste des liens reperes pour lui permettre
57
-	// de remettre le texte d'origine dans les parametres du modele
58
-	$t = traiter_modeles($t, false, false, $connect);
56
+    // on passe a traiter_modeles la liste des liens reperes pour lui permettre
57
+    // de remettre le texte d'origine dans les parametres du modele
58
+    $t = traiter_modeles($t, false, false, $connect);
59 59
 
60
-	return $t;
60
+    return $t;
61 61
 }
62 62
 
63 63
 // Meme analyse mais pour eliminer les liens
64 64
 // et ne laisser que leur titre, a expliciter si ce n'est fait
65 65
 function nettoyer_raccourcis_typo($texte, string $connect = '') {
66
-	return $texte;
66
+    return $texte;
67 67
 }
68 68
 
69 69
 // Repere dans la partie texte d'un raccourci [texte->...]
70 70
 // la langue et la bulle eventuelles
71 71
 function traiter_raccourci_lien_atts($texte) {
72
-	$bulle = '';
73
-	$hlang = '';
72
+    $bulle = '';
73
+    $hlang = '';
74 74
 
75
-	return [trim($texte), $bulle, $hlang];
75
+    return [trim($texte), $bulle, $hlang];
76 76
 }
77 77
 
78 78
 define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/');
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
  * @return string
89 89
  */
90 90
 function virtuel_redirige($virtuel, $url = false) {
91
-	return $virtuel;
91
+    return $virtuel;
92 92
 }
93 93
 
94 94
 // Cherche un lien du type [->raccourci 123]
@@ -101,62 +101,62 @@  discard block
 block discarded – undo
101 101
 // 'url':   seulement U  (i.e. generer_url_RACCOURCI)
102 102
 
103 103
 function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
104
-	$r = traiter_lien_implicite($ref, $texte, $pour, $connect);
104
+    $r = traiter_lien_implicite($ref, $texte, $pour, $connect);
105 105
 
106
-	return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
106
+    return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
107 107
 }
108 108
 
109 109
 define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
110 110
 
111 111
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
112
-	if (preg_match(_EXTRAIRE_LIEN, $ref)) {
113
-		return ($pour != 'tout') ? '' : ['', '', '', ''];
114
-	}
115
-
116
-	$lien = entites_html(trim($ref));
117
-
118
-	// Liens explicites
119
-	if (!$texte) {
120
-		$texte = str_replace('"', '', $lien);
121
-		// evite l'affichage de trops longues urls.
122
-		$lien_court = charger_fonction('lien_court', 'inc');
123
-		$texte = $lien_court($texte);
124
-		if ($echappe_typo) {
125
-			$texte = '<html>' . quote_amp($texte) . '</html>';
126
-		}
127
-	}
128
-
129
-	// petites corrections d'URL
130
-	if (preg_match('/^www\.[^@]+$/S', $lien)) {
131
-		$lien = 'http://' . $lien;
132
-	} else {
133
-		if (strpos($lien, '@') && email_valide($lien)) {
134
-			if (!$texte) {
135
-				$texte = $lien;
136
-			}
137
-			$lien = 'mailto:' . $lien;
138
-		}
139
-	}
140
-
141
-	if ($pour == 'url') {
142
-		return $lien;
143
-	}
144
-
145
-	if ($pour == 'titre') {
146
-		return $texte;
147
-	}
148
-
149
-	return ['url' => $lien, 'titre' => $texte];
112
+    if (preg_match(_EXTRAIRE_LIEN, $ref)) {
113
+        return ($pour != 'tout') ? '' : ['', '', '', ''];
114
+    }
115
+
116
+    $lien = entites_html(trim($ref));
117
+
118
+    // Liens explicites
119
+    if (!$texte) {
120
+        $texte = str_replace('"', '', $lien);
121
+        // evite l'affichage de trops longues urls.
122
+        $lien_court = charger_fonction('lien_court', 'inc');
123
+        $texte = $lien_court($texte);
124
+        if ($echappe_typo) {
125
+            $texte = '<html>' . quote_amp($texte) . '</html>';
126
+        }
127
+    }
128
+
129
+    // petites corrections d'URL
130
+    if (preg_match('/^www\.[^@]+$/S', $lien)) {
131
+        $lien = 'http://' . $lien;
132
+    } else {
133
+        if (strpos($lien, '@') && email_valide($lien)) {
134
+            if (!$texte) {
135
+                $texte = $lien;
136
+            }
137
+            $lien = 'mailto:' . $lien;
138
+        }
139
+    }
140
+
141
+    if ($pour == 'url') {
142
+        return $lien;
143
+    }
144
+
145
+    if ($pour == 'titre') {
146
+        return $texte;
147
+    }
148
+
149
+    return ['url' => $lien, 'titre' => $texte];
150 150
 }
151 151
 
152 152
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') {
153
-	if (function_exists($f = 'glossaire_' . $ancre)) {
154
-		$url = $f($texte, $id);
155
-	} else {
156
-		$url = glossaire_std($texte);
157
-	}
153
+    if (function_exists($f = 'glossaire_' . $ancre)) {
154
+        $url = $f($texte, $id);
155
+    } else {
156
+        $url = glossaire_std($texte);
157
+    }
158 158
 
159
-	return $url;
159
+    return $url;
160 160
 }
161 161
 
162 162
 /**
@@ -178,74 +178,74 @@  discard block
 block discarded – undo
178 178
  * @return array|bool|string
179 179
  */
180 180
 function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') {
181
-	$cible = $GLOBALS['lien_implicite_cible_public'] ?? null;
182
-	if (!($match = typer_raccourci($ref))) {
183
-		return false;
184
-	}
185
-
186
-	[$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
187
-
188
-	# attention dans le cas des sites le lien doit pointer non pas sur
189
-	# la page locale du site, mais directement sur le site lui-meme
190
-	$url = '';
191
-	if ($f = charger_fonction("implicite_$type", 'liens', true)) {
192
-		$url = $f($texte, $id, $type, $args, $ancre, $connect);
193
-	}
194
-
195
-	if (!$url) {
196
-		$url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
197
-	}
198
-
199
-	if (!$url) {
200
-		return false;
201
-	}
202
-
203
-	if (is_array($url)) {
204
-		[$type, $id] = array_pad($url, 2, null);
205
-		$url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
206
-	}
207
-
208
-	if ($pour === 'url') {
209
-		return $url;
210
-	}
211
-
212
-	$r = traiter_raccourci_titre($id, $type, $connect);
213
-	if ($r) {
214
-		$r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
215
-	}
216
-
217
-	if ($texte = trim($texte)) {
218
-		$r['titre'] = $texte;
219
-	}
220
-
221
-	if (!@$r['titre']) {
222
-		$r['titre'] = _T($type) . " $id";
223
-	}
224
-
225
-	if ($pour == 'titre') {
226
-		return $r['titre'];
227
-	}
228
-
229
-	$r['url'] = $url;
230
-
231
-	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
232
-	if (
233
-		$type == 'document'
234
-		and $mime = sql_getfetsel(
235
-			'mime_type',
236
-			'spip_types_documents',
237
-			'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
238
-			'',
239
-			'',
240
-			'',
241
-			'',
242
-			$connect
243
-		)
244
-	) {
245
-		$r['mime'] = $mime;
246
-	}
247
-
248
-	return $r;
181
+    $cible = $GLOBALS['lien_implicite_cible_public'] ?? null;
182
+    if (!($match = typer_raccourci($ref))) {
183
+        return false;
184
+    }
185
+
186
+    [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
187
+
188
+    # attention dans le cas des sites le lien doit pointer non pas sur
189
+    # la page locale du site, mais directement sur le site lui-meme
190
+    $url = '';
191
+    if ($f = charger_fonction("implicite_$type", 'liens', true)) {
192
+        $url = $f($texte, $id, $type, $args, $ancre, $connect);
193
+    }
194
+
195
+    if (!$url) {
196
+        $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
197
+    }
198
+
199
+    if (!$url) {
200
+        return false;
201
+    }
202
+
203
+    if (is_array($url)) {
204
+        [$type, $id] = array_pad($url, 2, null);
205
+        $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
206
+    }
207
+
208
+    if ($pour === 'url') {
209
+        return $url;
210
+    }
211
+
212
+    $r = traiter_raccourci_titre($id, $type, $connect);
213
+    if ($r) {
214
+        $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
215
+    }
216
+
217
+    if ($texte = trim($texte)) {
218
+        $r['titre'] = $texte;
219
+    }
220
+
221
+    if (!@$r['titre']) {
222
+        $r['titre'] = _T($type) . " $id";
223
+    }
224
+
225
+    if ($pour == 'titre') {
226
+        return $r['titre'];
227
+    }
228
+
229
+    $r['url'] = $url;
230
+
231
+    // dans le cas d'un lien vers un doc, ajouter le type='mime/type'
232
+    if (
233
+        $type == 'document'
234
+        and $mime = sql_getfetsel(
235
+            'mime_type',
236
+            'spip_types_documents',
237
+            'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
238
+            '',
239
+            '',
240
+            '',
241
+            '',
242
+            $connect
243
+        )
244
+    ) {
245
+        $r['mime'] = $mime;
246
+    }
247
+
248
+    return $r;
249 249
 }
250 250
 
251 251
 // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes
@@ -253,43 +253,43 @@  discard block
 block discarded – undo
253 253
 define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S');
254 254
 
255 255
 function typer_raccourci($lien) {
256
-	if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
257
-		return [];
258
-	}
259
-
260
-	$f = $match[1];
261
-	// valeur par defaut et alias historiques
262
-	if (!$f) {
263
-		$f = 'article';
264
-	} else {
265
-		if ($f == 'art') {
266
-			$f = 'article';
267
-		} else {
268
-			if ($f == 'br') {
269
-				$f = 'breve';
270
-			} else {
271
-				if ($f == 'rub') {
272
-					$f = 'rubrique';
273
-				} else {
274
-					if ($f == 'aut') {
275
-						$f = 'auteur';
276
-					} else {
277
-						if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
278
-							$f = 'document';
279
-						} else {
280
-							if (preg_match('/^br..?ve$/S', $f)) {
281
-								$f = 'breve'; # accents :(
282
-							}
283
-						}
284
-					}
285
-				}
286
-			}
287
-		}
288
-	}
289
-
290
-	$match[0] = $f;
291
-
292
-	return $match;
256
+    if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
257
+        return [];
258
+    }
259
+
260
+    $f = $match[1];
261
+    // valeur par defaut et alias historiques
262
+    if (!$f) {
263
+        $f = 'article';
264
+    } else {
265
+        if ($f == 'art') {
266
+            $f = 'article';
267
+        } else {
268
+            if ($f == 'br') {
269
+                $f = 'breve';
270
+            } else {
271
+                if ($f == 'rub') {
272
+                    $f = 'rubrique';
273
+                } else {
274
+                    if ($f == 'aut') {
275
+                        $f = 'auteur';
276
+                    } else {
277
+                        if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
278
+                            $f = 'document';
279
+                        } else {
280
+                            if (preg_match('/^br..?ve$/S', $f)) {
281
+                                $f = 'breve'; # accents :(
282
+                            }
283
+                        }
284
+                    }
285
+                }
286
+            }
287
+        }
288
+    }
289
+
290
+    $match[0] = $f;
291
+
292
+    return $match;
293 293
 }
294 294
 
295 295
 /**
@@ -304,44 +304,44 @@  discard block
 block discarded – undo
304 304
  * }
305 305
  **/
306 306
 function traiter_raccourci_titre($id, $type, $connect = null) {
307
-	$trouver_table = charger_fonction('trouver_table', 'base');
308
-	$desc = $trouver_table(table_objet($type));
307
+    $trouver_table = charger_fonction('trouver_table', 'base');
308
+    $desc = $trouver_table(table_objet($type));
309 309
 
310
-	if (!($desc and $s = $desc['titre'])) {
311
-		return [];
312
-	}
310
+    if (!($desc and $s = $desc['titre'])) {
311
+        return [];
312
+    }
313 313
 
314
-	$_id = $desc['key']['PRIMARY KEY'];
315
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
314
+    $_id = $desc['key']['PRIMARY KEY'];
315
+    $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
316 316
 
317
-	if (!$r) {
318
-		return [];
319
-	}
317
+    if (!$r) {
318
+        return [];
319
+    }
320 320
 
321
-	$r['titre'] = supprimer_numero($r['titre']);
321
+    $r['titre'] = supprimer_numero($r['titre']);
322 322
 
323
-	if (!$r['titre'] and !empty($r['surnom'])) {
324
-		$r['titre'] = $r['surnom'];
325
-	}
323
+    if (!$r['titre'] and !empty($r['surnom'])) {
324
+        $r['titre'] = $r['surnom'];
325
+    }
326 326
 
327
-	if (!isset($r['lang'])) {
328
-		$r['lang'] = '';
329
-	}
327
+    if (!isset($r['lang'])) {
328
+        $r['lang'] = '';
329
+    }
330 330
 
331
-	return $r;
331
+    return $r;
332 332
 }
333 333
 
334 334
 //
335 335
 // Raccourcis ancre [#ancre<-]
336 336
 //
337 337
 function traiter_raccourci_ancre($letexte) {
338
-	return $letexte;
338
+    return $letexte;
339 339
 }
340 340
 
341 341
 function traiter_raccourci_glossaire($texte) {
342
-	return $texte;
342
+    return $texte;
343 343
 }
344 344
 
345 345
 function glossaire_std($terme) {
346
-	return $terme;
346
+    return $terme;
347 347
 }
Please login to merge, or discard this patch.
ecrire/inc/idna_convert.class.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
     protected $_strict_mode = false;     // Behave strict or not
85 85
     protected $_idn_version = 2003;      // Can be either 2003 (old, default) or 2008
86 86
 
87
-	protected $slast;
87
+    protected $slast;
88 88
 
89 89
     /**
90 90
      * the constructor
Please login to merge, or discard this patch.
Spacing   +43 added lines, -46 removed lines patch added patch discarded remove patch
@@ -73,16 +73,16 @@  discard block
 block discarded – undo
73 73
     protected $_lcount = 19;
74 74
     protected $_vcount = 21;
75 75
     protected $_tcount = 28;
76
-    protected $_ncount = 588;   // _vcount * _tcount
76
+    protected $_ncount = 588; // _vcount * _tcount
77 77
     protected $_scount = 11172; // _lcount * _tcount * _vcount
78 78
     protected $_error = false;
79 79
     protected static $_mb_string_overload = null;
80 80
     // See {@link set_paramter()} for details of how to change the following
81 81
     // settings from within your script / application
82
-    protected $_api_encoding = 'utf8';   // Default input charset is UTF-8
83
-    protected $_allow_overlong = false;  // Overlong UTF-8 encodings are forbidden
84
-    protected $_strict_mode = false;     // Behave strict or not
85
-    protected $_idn_version = 2003;      // Can be either 2003 (old, default) or 2008
82
+    protected $_api_encoding = 'utf8'; // Default input charset is UTF-8
83
+    protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden
84
+    protected $_strict_mode = false; // Behave strict or not
85
+    protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008
86 86
 
87 87
 	protected $slast;
88 88
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                             $this->_api_encoding = $v;
143 143
                             break;
144 144
                         default:
145
-                            $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
145
+                            $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
146 146
                             return false;
147 147
                     }
148 148
                     break;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                     if (in_array($v, array('2003', '2008'))) {
157 157
                         $this->_idn_version = $v;
158 158
                     } else {
159
-                        $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k);
159
+                        $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
160 160
                     }
161 161
                     break;
162 162
                 case 'encode_german_sz': // Deprecated
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
                     }
168 168
                     break;
169 169
                 default:
170
-                    $this->_error('Set Parameter: Unknown option ' . $k);
170
+                    $this->_error('Set Parameter: Unknown option '.$k);
171 171
                     return false;
172 172
             }
173 173
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
                 case 'ucs4_array':
191 191
                     break;
192 192
                 default:
193
-                    $this->_error('Unknown encoding ' . $one_time_encoding);
193
+                    $this->_error('Unknown encoding '.$one_time_encoding);
194 194
                     return false;
195 195
             }
196 196
         }
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             [$email_pref, $input] = explode('@', $input, 2);
209 209
             $arr = explode('.', $input);
210 210
             foreach ($arr as $k => $v) {
211
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
211
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
212 212
                     $conv = $this->_decode($v);
213 213
                     if ($conv) {
214 214
                         $arr[$k] = $conv;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
             $input = join('.', $arr);
219 219
             $arr = explode('.', $email_pref);
220 220
             foreach ($arr as $k => $v) {
221
-                if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) {
221
+                if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
222 222
                     $conv = $this->_decode($v);
223 223
                     if ($conv) {
224 224
                         $arr[$k] = $conv;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                 }
227 227
             }
228 228
             $email_pref = join('.', $arr);
229
-            $return = $email_pref . '@' . $input;
229
+            $return = $email_pref.'@'.$input;
230 230
         } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters)
231 231
             // No no in strict mode
232 232
             if ($this->_strict_mode) {
@@ -243,13 +243,13 @@  discard block
 block discarded – undo
243 243
                     }
244 244
                 }
245 245
                 $parsed['host'] = join('.', $arr);
246
-                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
247
-                        (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
246
+                $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
247
+                        (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
248 248
                         $parsed['host'].
249
-                        (empty($parsed['port']) ? '' : ':' . $parsed['port']).
249
+                        (empty($parsed['port']) ? '' : ':'.$parsed['port']).
250 250
                         (empty($parsed['path']) ? '' : $parsed['path']).
251
-                        (empty($parsed['query']) ? '' : '?' . $parsed['query']).
252
-                        (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
251
+                        (empty($parsed['query']) ? '' : '?'.$parsed['query']).
252
+                        (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
253 253
             } else { // parse_url seems to have failed, try without it
254 254
                 $arr = explode('.', $input);
255 255
                 foreach ($arr as $k => $v) {
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
         // The output is UTF-8 by default, other output formats need conversion here
268 268
         // If one time encoding is given, use this, else the objects property
269 269
         switch ($one_time_encoding ?: $this->_api_encoding) {
270
-            case 'utf8':        return $return; // break;
271
-            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));  // break;
270
+            case 'utf8' : return $return; // break;
271
+            case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break;
272 272
             case 'ucs4_array':  return $this->_utf8_to_ucs4($return); // break;
273 273
             default:            $this->_error('Unsupported output format'); return false;
274 274
         }
@@ -285,15 +285,14 @@  discard block
 block discarded – undo
285 285
         // Forcing conversion of input to UCS4 array
286 286
         // If one time encoding is given, use this, else the objects property
287 287
         switch ($one_time_encoding ?: $this->_api_encoding) {
288
-            case 'utf8':
289
-                $decoded = $this->_utf8_to_ucs4($decoded);
288
+            case 'utf8' : $decoded = $this->_utf8_to_ucs4($decoded);
290 289
                 break;
291 290
             case 'ucs4_string':
292 291
                 $decoded = $this->_ucs4_string_to_ucs4($decoded);
293 292
             case 'ucs4_array':
294 293
                 break;
295 294
             default:
296
-                $this->_error('Unsupported input format: ' . ($one_time_encoding ?: $this->_api_encoding));
295
+                $this->_error('Unsupported input format: '.($one_time_encoding ?: $this->_api_encoding));
297 296
                 return false;
298 297
         }
299 298
 
@@ -382,13 +381,13 @@  discard block
 block discarded – undo
382 381
             }
383 382
         }
384 383
         $parsed['host'] = join('.', $arr);
385
-        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
386
-                (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@').
384
+        $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')).
385
+                (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@').
387 386
                 $parsed['host'].
388
-                (empty($parsed['port']) ? '' : ':' . $parsed['port']).
387
+                (empty($parsed['port']) ? '' : ':'.$parsed['port']).
389 388
                 (empty($parsed['path']) ? '' : $parsed['path']).
390
-                (empty($parsed['query']) ? '' : '?' . $parsed['query']).
391
-                (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']);
389
+                (empty($parsed['query']) ? '' : '?'.$parsed['query']).
390
+                (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
392 391
         return $return;
393 392
     }
394 393
 
@@ -411,11 +410,11 @@  discard block
 block discarded – undo
411 410
     {
412 411
         $decoded = array();
413 412
         // find the Punycode prefix
414
-        if (!preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $encoded)) {
413
+        if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) {
415 414
             $this->_error('This is not a punycode string');
416 415
             return false;
417 416
         }
418
-        $encode_test = preg_replace('!^' . preg_quote($this->_punycode_prefix, '!') . '!', '', $encoded);
417
+        $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded);
419 418
         // If nothing left after removing the prefix, it is hopeless
420 419
         if (!$encode_test) {
421 420
             $this->_error('The given encoded string was empty');
@@ -441,8 +440,7 @@  discard block
 block discarded – undo
441 440
             for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) {
442 441
                 $digit = $this->_decode_digit($encoded[$enco_idx++]);
443 442
                 $idx += $digit * $w;
444
-                $t = ($k <= $bias) ? $this->_tmin :
445
-                        (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
443
+                $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
446 444
                 if ($digit < $t) {
447 445
                     break;
448 446
                 }
@@ -515,7 +513,7 @@  discard block
 block discarded – undo
515 513
             return $encoded; // All codepoints were basic ones
516 514
         }
517 515
         // Start with the prefix; copy it to output
518
-        $encoded = $this->_punycode_prefix . $encoded;
516
+        $encoded = $this->_punycode_prefix.$encoded;
519 517
         // If we have basic code points in output, add an hyphen to the end
520 518
         if ($codecount) {
521 519
             $encoded .= '-';
@@ -542,8 +540,7 @@  discard block
 block discarded – undo
542 540
                     $delta++;
543 541
                 } elseif ($decoded[$i] == $cur_code) {
544 542
                     for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) {
545
-                        $t = ($k <= $bias) ? $this->_tmin :
546
-                                (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
543
+                        $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
547 544
                         if ($q < $t) {
548 545
                             break;
549 546
                         }
@@ -630,12 +627,12 @@  discard block
 block discarded – undo
630 627
             }
631 628
             // Try to find prohibited input
632 629
             if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) {
633
-                $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
630
+                $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
634 631
                 return false;
635 632
             }
636 633
             foreach (self::$NP['prohibit_ranges'] as $range) {
637 634
                 if ($range[0] <= $v && $v <= $range[1]) {
638
-                    $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v));
635
+                    $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
639 636
                     return false;
640 637
                 }
641 638
             }
@@ -873,7 +870,7 @@  discard block
 block discarded – undo
873 870
                 $output[$out_len] = $v;
874 871
                 ++$out_len;
875 872
                 if ('add' == $mode) {
876
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
873
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
877 874
                     return false;
878 875
                 }
879 876
                 continue;
@@ -898,7 +895,7 @@  discard block
 block discarded – undo
898 895
                     $next_byte = 4;
899 896
                     $v = ($v - 252) << 30;
900 897
                 } else {
901
-                    $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k);
898
+                    $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k);
902 899
                     return false;
903 900
                 }
904 901
                 if ('add' == $mode) {
@@ -911,7 +908,7 @@  discard block
 block discarded – undo
911 908
                 if (!$this->_allow_overlong && $test == 'range') {
912 909
                     $test = 'none';
913 910
                     if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) {
914
-                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k);
911
+                        $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k);
915 912
                         return false;
916 913
                     }
917 914
                 }
@@ -920,7 +917,7 @@  discard block
 block discarded – undo
920 917
                     $output[($out_len - 1)] += $v;
921 918
                     --$next_byte;
922 919
                 } else {
923
-                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k);
920
+                    $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
924 921
                     return false;
925 922
                 }
926 923
                 if ($next_byte < 0) {
@@ -944,13 +941,13 @@  discard block
 block discarded – undo
944 941
             if ($v < 128) { // 7bit are transferred literally
945 942
                 $output .= chr($v);
946 943
             } elseif ($v < (1 << 11)) { // 2 bytes
947
-                $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
944
+                $output .= chr(192 + ($v >> 6)).chr(128 + ($v & 63));
948 945
             } elseif ($v < (1 << 16)) { // 3 bytes
949
-                $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
946
+                $output .= chr(224 + ($v >> 12)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
950 947
             } elseif ($v < (1 << 21)) { // 4 bytes
951
-                $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
948
+                $output .= chr(240 + ($v >> 18)).chr(128 + (($v >> 12) & 63)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63));
952 949
             } else {
953
-                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte ' . $k);
950
+                $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k);
954 951
                 return false;
955 952
             }
956 953
         }
@@ -969,7 +966,7 @@  discard block
 block discarded – undo
969 966
         // Take array values and split output to 4 bytes per value
970 967
         // The bit mask is 255, which reads &11111111
971 968
         foreach ($input as $v) {
972
-            $output .= chr(($v >> 24) & 255) . chr(($v >> 16) & 255) . chr(($v >> 8) & 255) . chr($v & 255);
969
+            $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
973 970
         }
974 971
         return $output;
975 972
     }
@@ -999,7 +996,7 @@  discard block
 block discarded – undo
999 996
                 $out_len++;
1000 997
                 $output[$out_len] = 0;
1001 998
             }
1002
-            $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4) ) );
999
+            $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4)));
1003 1000
         }
1004 1001
         return $output;
1005 1002
     }
Please login to merge, or discard this patch.