Completed
Push — master ( 267cf1...68e811 )
by cam
01:09
created
ecrire/src/Texte/Collecteur/AbstractCollecteur.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -154,8 +154,7 @@
 block discarded – undo
154 154
 				if ($c = base64_decode($base64, true)) {
155 155
 					$texte = substr_replace($texte, $c, $p, $end + 2 - $p);
156 156
 					$pos = $p + strlen($c);
157
-				}
158
-				else {
157
+				} else {
159 158
 					$pos = $end;
160 159
 				}
161 160
 			}
Please login to merge, or discard this patch.
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -12,286 +12,286 @@
 block discarded – undo
12 12
 namespace Spip\Texte\Collecteur;
13 13
 
14 14
 abstract class AbstractCollecteur {
15
-	protected static string $markPrefix = 'COLLECT';
16
-	protected string $markId;
17
-
18
-	public static array $listeBalisesBloc = [
19
-		'address', 'applet', 'article', 'aside',
20
-		'blockquote', 'button',
21
-		'center',
22
-		'dl', 'dt', 'dd', 'div',
23
-		'fieldset', 'figure', 'figcaption', 'footer', 'form',
24
-		'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'hgroup', 'head', 'header',
25
-		'iframe',
26
-		'li',
27
-		'map', 'marquee',
28
-		'nav', 'noscript',
29
-		'object', 'ol',
30
-		'pre',
31
-		'section',
32
-		'table', 'tr', 'td', 'th', 'tbody', 'foot', 'textarea',
33
-		'ul',
34
-		'script', 'style'
35
-	];
36
-
37
-	/**
38
-	 * Collecteur générique des occurences d'une preg dans un texte avec leurs positions et longueur
39
-	 * @param string $texte
40
-	 *   texte à analyser pour la collecte
41
-	 * @param string $if_chars
42
-	 *   caractere(s) à tester avant de tenter la preg
43
-	 * @param string $start_with
44
-	 *   caractere(s) par lesquels commencent l'expression recherchée (permet de démarrer la preg à la prochaine occurence de cette chaine)
45
-	 * @param string $preg
46
-	 *   preg utilisée pour la collecte
47
-	 * @param int $max_items
48
-	 *   pour limiter le nombre de preg collectée (pour la detection simple de présence par exemple)
49
-	 * @return array
50
-	 */
51
-	protected static function collecteur(string $texte, string $if_chars, string $start_with, string $preg, int $max_items = 0): array {
52
-
53
-		$collection = [];
54
-		$pos = 0;
55
-		while (
56
-			(!$if_chars || str_contains($texte, $if_chars))
57
-			&& ($next = ($start_with ? strpos($texte, $start_with, $pos) : $pos)) !== false
58
-			&& preg_match($preg, $texte, $r, PREG_OFFSET_CAPTURE, $next)
59
-		) {
60
-			$found_pos = $r[0][1];
61
-			$found_length = strlen($r[0][0]);
62
-			$match = [
63
-				'raw' => $r[0][0],
64
-				'match' => array_column($r, 0),
65
-				'pos' => $found_pos,
66
-				'length' => $found_length
67
-			];
68
-
69
-			$collection[] = $match;
70
-
71
-			if ($max_items && count($collection) === $max_items) {
72
-				break;
73
-			}
74
-
75
-			$pos = $match['pos'] + $match['length'];
76
-		}
77
-
78
-		return $collection;
79
-	}
80
-
81
-	/**
82
-	 * Sanitizer une collection d'occurences
83
-	 */
84
-	protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
85
-		foreach ($collection as &$c) {
86
-			$c['raw'] = $sanitize_callback($c['raw']);
87
-		}
88
-
89
-		return $collection;
90
-	}
91
-
92
-	/**
93
-	 * @return array
94
-	 */
95
-	public function collecter(string $texte, array $options = []): array {
96
-		return [];
97
-	}
98
-
99
-	public function detecter($texte): bool {
100
-		if (!empty($this->markId) && str_contains((string) $texte, $this->markId)) {
101
-			return true;
102
-		}
103
-		return !empty($this->collecter($texte, ['detecter_presence' => true]));
104
-	}
105
-
106
-	/**
107
-	 * Echapper les occurences de la collecte par un texte neutre du point de vue HTML
108
-	 *
109
-	 * @see retablir()
110
-	 * @param string $texte
111
-	 * @param array $options
112
-	 *   string $sanitize_callback
113
-	 * @return array
114
-	 *   texte, marqueur utilise pour echapper les modeles
115
-	 */
116
-	public function echapper(string $texte, array $options = []): string {
117
-		if (!function_exists('creer_uniqid')) {
118
-			include_spip('inc/acces');
119
-		}
120
-
121
-		$collection = $this->collecter($texte, $options);
122
-		if (!empty($options['sanitize_callback']) && is_callable($options['sanitize_callback'])) {
123
-			$collection = $this->sanitizer_collection($collection, $options['sanitize_callback']);
124
-		}
125
-
126
-		if ($collection !== []) {
127
-			if (empty($this->markId)) {
128
-				// generer un marqueur qui n'existe pas dans le texte
129
-				do {
130
-					$this->markId = substr(md5(uniqid(static::class, 1)), 0, 7);
131
-					$this->markId = '@|' . static::$markPrefix . $this->markId . '|';
132
-				} while (str_contains($texte, $this->markId));
133
-			}
134
-
135
-			$offset_pos = 0;
136
-			foreach ($collection as $c) {
137
-				$rempl = $this->markId . base64_encode((string) $c['raw']) . '|@';
138
-				$texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']);
139
-				$offset_pos += strlen($rempl) - $c['length'];
140
-			}
141
-		}
142
-
143
-		return $texte;
144
-	}
145
-
146
-
147
-	/**
148
-	 * Retablir les occurences échappées précédemment
149
-	 *
150
-	 * @see echapper()
151
-	 */
152
-	function retablir(string $texte): string {
153
-
154
-		if (!empty($this->markId)) {
155
-			$lm = strlen($this->markId);
156
-			$pos = 0;
157
-			while (
158
-				($p = strpos($texte, $this->markId, $pos)) !== false
159
-				&& ($end = strpos($texte, '|@', $p + $lm))
160
-			) {
161
-				$base64 = substr($texte, $p + $lm, $end - ($p + $lm));
162
-				if ($c = base64_decode($base64, true)) {
163
-					$texte = substr_replace($texte, $c, $p, $end + 2 - $p);
164
-					$pos = $p + strlen($c);
165
-				}
166
-				else {
167
-					$pos = $end;
168
-				}
169
-			}
170
-		}
171
-
172
-		return $texte;
173
-	}
174
-
175
-	/**
176
-	 * Detecter si un texte contient des balises bloc ou non
177
-	 */
178
-	public static function echappementTexteContientBaliseBloc(string $texte): bool {
179
-		static $pregBalisesBloc;
180
-
181
-		if ($pregBalisesBloc === null) {
182
-			$pregBalisesBloc = ',</?(' . implode('|', static::$listeBalisesBloc) . ')[>[:space:]],iS';
183
-		}
184
-		return (str_contains($texte, '<') && preg_match($pregBalisesBloc, $texte)) ? true : false;
185
-	}
186
-
187
-	/**
188
-	 * Creer un bloc base64 correspondant a $texte ; au besoin en marquant
189
-	 * une $source differente ;
190
-	 * si $isBloc n'est pas fourni, le script detecte automagiquement si ce qu'on
191
-	 * echappe est un div ou un span
192
-	 */
193
-	public static function echappementHtmlBase64(string $texte, string $source = '', ?bool $isBloc = null, array $attributs = []): string {
194
-
195
-		if ($texte === '') {
196
-			return '';
197
-		}
198
-
199
-		// Tester si on echappe en span ou en div
200
-		$isBloc ??= self::echappementTexteContientBaliseBloc($texte);
201
-		$tag = $isBloc ? 'div' : 'span';
202
-		$atts = '';
203
-		if (!empty($attributs)) {
204
-			if (!function_exists('attribut_html')) {
205
-				include_spip('inc/filtres');
206
-			}
207
-			foreach ($attributs as $k => $v) {
208
-				$atts .= " $k=\"" . \attribut_html($v) . '"';
209
-			}
210
-		}
211
-
212
-		// Decouper en morceaux, base64 a des probleme selon la taille de la pile
213
-		$taille = 30000;
214
-		$return = '';
215
-		for ($i = 0; $i < strlen($texte); $i += $taille) {
216
-			// Convertir en base64 et cacher dans un attribut
217
-			// utiliser les " pour eviter le re-encodage de ' et &#8217
218
-			$base64 = base64_encode(substr($texte, $i, $taille));
219
-			$return .= "<$tag class=\"base64$source\" title=\"$base64\"{$atts}></$tag>";
220
-		}
221
-
222
-		return $return;
223
-	}
224
-
225
-
226
-	/**
227
-	 * Rétablir les contenus échappés dans un texte en <(div|span) class="base64..."></(div|span)>
228
-	 * Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
229
-	 * par propre() : exemple dans multi et dans typo()
230
-	 *
231
-	 * @see echappementHtmlBase64()
232
-	 */
233
-	public static function retablir_depuisHtmlBase64(string $texte, string $source = '', string $filtre = ''): string {
234
-		if (str_contains($texte, "base64$source")) {
235
-			# spip_log(spip_htmlspecialchars($texte));  ## pour les curieux
236
-			$max_prof = 5;
237
-			$encore = true;
238
-			while ($encore && str_contains($texte, 'base64' . $source) && $max_prof--) {
239
-				$encore = false;
240
-				foreach (['span', 'div'] as $tag) {
241
-					$htmlTagCollecteur = new HtmlTag(
242
-						$tag,
243
-						"@<{$tag}\s(class=['\"]base64{$source}['\"]\stitle=['\"]([^'\">]*)['\"][^>]*?)(/?)>\s*</{$tag}>@isS",
244
-						''
245
-					);
246
-					$collection = $htmlTagCollecteur->collecter($texte);
247
-					if (!empty($collection)) {
248
-						$collection = array_reverse($collection);
249
-						foreach ($collection as $c) {
250
-							$title = $c['match'][2];
251
-							if ($title && ($rempl = base64_decode($title, true))) {
252
-								$encore = true;
253
-								// recherche d'attributs supplementaires
254
-								$at = [];
255
-								foreach (['lang', 'dir'] as $attr) {
256
-									if ($a = extraire_attribut($c['match'][0], $attr)) {
257
-										$at[$attr] = $a;
258
-									}
259
-								}
260
-								if ($at) {
261
-									$rempl = "<$tag>$rempl</$tag>";
262
-									foreach ($at as $attr => $a) {
263
-										$rempl = inserer_attribut($rempl, $attr, $a);
264
-									}
265
-								}
266
-								if ($filtre) {
267
-									$rempl = $filtre($rempl);
268
-								}
269
-								$texte = substr_replace($texte, $rempl, $c['pos'], $c['length']);
270
-							}
271
-						}
272
-					}
273
-				}
274
-			}
275
-		}
276
-		return $texte;
277
-	}
278
-
279
-	/**
280
-	 * @param callable|null $callback_function
281
-	 */
282
-	public function echapper_enHtmlBase64(string $texte, string $source = '', $callback_function = null, array $callback_options = []): string {
283
-		$collection = $this->collecter($texte);
284
-		if (!empty($collection)) {
285
-			$collection = array_reverse($collection);
286
-			foreach ($collection as $c) {
287
-				$echap = $c['raw'];
288
-				if ($callback_function) {
289
-					$echap = $callback_function($c, $callback_options);
290
-				}
291
-				$echap = self::echappementHtmlBase64($echap, $source);
292
-				$texte = substr_replace($texte, $echap, $c['pos'], $c['length']);
293
-			}
294
-		}
295
-		return $texte;
296
-	}
15
+    protected static string $markPrefix = 'COLLECT';
16
+    protected string $markId;
17
+
18
+    public static array $listeBalisesBloc = [
19
+        'address', 'applet', 'article', 'aside',
20
+        'blockquote', 'button',
21
+        'center',
22
+        'dl', 'dt', 'dd', 'div',
23
+        'fieldset', 'figure', 'figcaption', 'footer', 'form',
24
+        'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'hgroup', 'head', 'header',
25
+        'iframe',
26
+        'li',
27
+        'map', 'marquee',
28
+        'nav', 'noscript',
29
+        'object', 'ol',
30
+        'pre',
31
+        'section',
32
+        'table', 'tr', 'td', 'th', 'tbody', 'foot', 'textarea',
33
+        'ul',
34
+        'script', 'style'
35
+    ];
36
+
37
+    /**
38
+     * Collecteur générique des occurences d'une preg dans un texte avec leurs positions et longueur
39
+     * @param string $texte
40
+     *   texte à analyser pour la collecte
41
+     * @param string $if_chars
42
+     *   caractere(s) à tester avant de tenter la preg
43
+     * @param string $start_with
44
+     *   caractere(s) par lesquels commencent l'expression recherchée (permet de démarrer la preg à la prochaine occurence de cette chaine)
45
+     * @param string $preg
46
+     *   preg utilisée pour la collecte
47
+     * @param int $max_items
48
+     *   pour limiter le nombre de preg collectée (pour la detection simple de présence par exemple)
49
+     * @return array
50
+     */
51
+    protected static function collecteur(string $texte, string $if_chars, string $start_with, string $preg, int $max_items = 0): array {
52
+
53
+        $collection = [];
54
+        $pos = 0;
55
+        while (
56
+            (!$if_chars || str_contains($texte, $if_chars))
57
+            && ($next = ($start_with ? strpos($texte, $start_with, $pos) : $pos)) !== false
58
+            && preg_match($preg, $texte, $r, PREG_OFFSET_CAPTURE, $next)
59
+        ) {
60
+            $found_pos = $r[0][1];
61
+            $found_length = strlen($r[0][0]);
62
+            $match = [
63
+                'raw' => $r[0][0],
64
+                'match' => array_column($r, 0),
65
+                'pos' => $found_pos,
66
+                'length' => $found_length
67
+            ];
68
+
69
+            $collection[] = $match;
70
+
71
+            if ($max_items && count($collection) === $max_items) {
72
+                break;
73
+            }
74
+
75
+            $pos = $match['pos'] + $match['length'];
76
+        }
77
+
78
+        return $collection;
79
+    }
80
+
81
+    /**
82
+     * Sanitizer une collection d'occurences
83
+     */
84
+    protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
85
+        foreach ($collection as &$c) {
86
+            $c['raw'] = $sanitize_callback($c['raw']);
87
+        }
88
+
89
+        return $collection;
90
+    }
91
+
92
+    /**
93
+     * @return array
94
+     */
95
+    public function collecter(string $texte, array $options = []): array {
96
+        return [];
97
+    }
98
+
99
+    public function detecter($texte): bool {
100
+        if (!empty($this->markId) && str_contains((string) $texte, $this->markId)) {
101
+            return true;
102
+        }
103
+        return !empty($this->collecter($texte, ['detecter_presence' => true]));
104
+    }
105
+
106
+    /**
107
+     * Echapper les occurences de la collecte par un texte neutre du point de vue HTML
108
+     *
109
+     * @see retablir()
110
+     * @param string $texte
111
+     * @param array $options
112
+     *   string $sanitize_callback
113
+     * @return array
114
+     *   texte, marqueur utilise pour echapper les modeles
115
+     */
116
+    public function echapper(string $texte, array $options = []): string {
117
+        if (!function_exists('creer_uniqid')) {
118
+            include_spip('inc/acces');
119
+        }
120
+
121
+        $collection = $this->collecter($texte, $options);
122
+        if (!empty($options['sanitize_callback']) && is_callable($options['sanitize_callback'])) {
123
+            $collection = $this->sanitizer_collection($collection, $options['sanitize_callback']);
124
+        }
125
+
126
+        if ($collection !== []) {
127
+            if (empty($this->markId)) {
128
+                // generer un marqueur qui n'existe pas dans le texte
129
+                do {
130
+                    $this->markId = substr(md5(uniqid(static::class, 1)), 0, 7);
131
+                    $this->markId = '@|' . static::$markPrefix . $this->markId . '|';
132
+                } while (str_contains($texte, $this->markId));
133
+            }
134
+
135
+            $offset_pos = 0;
136
+            foreach ($collection as $c) {
137
+                $rempl = $this->markId . base64_encode((string) $c['raw']) . '|@';
138
+                $texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']);
139
+                $offset_pos += strlen($rempl) - $c['length'];
140
+            }
141
+        }
142
+
143
+        return $texte;
144
+    }
145
+
146
+
147
+    /**
148
+     * Retablir les occurences échappées précédemment
149
+     *
150
+     * @see echapper()
151
+     */
152
+    function retablir(string $texte): string {
153
+
154
+        if (!empty($this->markId)) {
155
+            $lm = strlen($this->markId);
156
+            $pos = 0;
157
+            while (
158
+                ($p = strpos($texte, $this->markId, $pos)) !== false
159
+                && ($end = strpos($texte, '|@', $p + $lm))
160
+            ) {
161
+                $base64 = substr($texte, $p + $lm, $end - ($p + $lm));
162
+                if ($c = base64_decode($base64, true)) {
163
+                    $texte = substr_replace($texte, $c, $p, $end + 2 - $p);
164
+                    $pos = $p + strlen($c);
165
+                }
166
+                else {
167
+                    $pos = $end;
168
+                }
169
+            }
170
+        }
171
+
172
+        return $texte;
173
+    }
174
+
175
+    /**
176
+     * Detecter si un texte contient des balises bloc ou non
177
+     */
178
+    public static function echappementTexteContientBaliseBloc(string $texte): bool {
179
+        static $pregBalisesBloc;
180
+
181
+        if ($pregBalisesBloc === null) {
182
+            $pregBalisesBloc = ',</?(' . implode('|', static::$listeBalisesBloc) . ')[>[:space:]],iS';
183
+        }
184
+        return (str_contains($texte, '<') && preg_match($pregBalisesBloc, $texte)) ? true : false;
185
+    }
186
+
187
+    /**
188
+     * Creer un bloc base64 correspondant a $texte ; au besoin en marquant
189
+     * une $source differente ;
190
+     * si $isBloc n'est pas fourni, le script detecte automagiquement si ce qu'on
191
+     * echappe est un div ou un span
192
+     */
193
+    public static function echappementHtmlBase64(string $texte, string $source = '', ?bool $isBloc = null, array $attributs = []): string {
194
+
195
+        if ($texte === '') {
196
+            return '';
197
+        }
198
+
199
+        // Tester si on echappe en span ou en div
200
+        $isBloc ??= self::echappementTexteContientBaliseBloc($texte);
201
+        $tag = $isBloc ? 'div' : 'span';
202
+        $atts = '';
203
+        if (!empty($attributs)) {
204
+            if (!function_exists('attribut_html')) {
205
+                include_spip('inc/filtres');
206
+            }
207
+            foreach ($attributs as $k => $v) {
208
+                $atts .= " $k=\"" . \attribut_html($v) . '"';
209
+            }
210
+        }
211
+
212
+        // Decouper en morceaux, base64 a des probleme selon la taille de la pile
213
+        $taille = 30000;
214
+        $return = '';
215
+        for ($i = 0; $i < strlen($texte); $i += $taille) {
216
+            // Convertir en base64 et cacher dans un attribut
217
+            // utiliser les " pour eviter le re-encodage de ' et &#8217
218
+            $base64 = base64_encode(substr($texte, $i, $taille));
219
+            $return .= "<$tag class=\"base64$source\" title=\"$base64\"{$atts}></$tag>";
220
+        }
221
+
222
+        return $return;
223
+    }
224
+
225
+
226
+    /**
227
+     * Rétablir les contenus échappés dans un texte en <(div|span) class="base64..."></(div|span)>
228
+     * Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
229
+     * par propre() : exemple dans multi et dans typo()
230
+     *
231
+     * @see echappementHtmlBase64()
232
+     */
233
+    public static function retablir_depuisHtmlBase64(string $texte, string $source = '', string $filtre = ''): string {
234
+        if (str_contains($texte, "base64$source")) {
235
+            # spip_log(spip_htmlspecialchars($texte));  ## pour les curieux
236
+            $max_prof = 5;
237
+            $encore = true;
238
+            while ($encore && str_contains($texte, 'base64' . $source) && $max_prof--) {
239
+                $encore = false;
240
+                foreach (['span', 'div'] as $tag) {
241
+                    $htmlTagCollecteur = new HtmlTag(
242
+                        $tag,
243
+                        "@<{$tag}\s(class=['\"]base64{$source}['\"]\stitle=['\"]([^'\">]*)['\"][^>]*?)(/?)>\s*</{$tag}>@isS",
244
+                        ''
245
+                    );
246
+                    $collection = $htmlTagCollecteur->collecter($texte);
247
+                    if (!empty($collection)) {
248
+                        $collection = array_reverse($collection);
249
+                        foreach ($collection as $c) {
250
+                            $title = $c['match'][2];
251
+                            if ($title && ($rempl = base64_decode($title, true))) {
252
+                                $encore = true;
253
+                                // recherche d'attributs supplementaires
254
+                                $at = [];
255
+                                foreach (['lang', 'dir'] as $attr) {
256
+                                    if ($a = extraire_attribut($c['match'][0], $attr)) {
257
+                                        $at[$attr] = $a;
258
+                                    }
259
+                                }
260
+                                if ($at) {
261
+                                    $rempl = "<$tag>$rempl</$tag>";
262
+                                    foreach ($at as $attr => $a) {
263
+                                        $rempl = inserer_attribut($rempl, $attr, $a);
264
+                                    }
265
+                                }
266
+                                if ($filtre) {
267
+                                    $rempl = $filtre($rempl);
268
+                                }
269
+                                $texte = substr_replace($texte, $rempl, $c['pos'], $c['length']);
270
+                            }
271
+                        }
272
+                    }
273
+                }
274
+            }
275
+        }
276
+        return $texte;
277
+    }
278
+
279
+    /**
280
+     * @param callable|null $callback_function
281
+     */
282
+    public function echapper_enHtmlBase64(string $texte, string $source = '', $callback_function = null, array $callback_options = []): string {
283
+        $collection = $this->collecter($texte);
284
+        if (!empty($collection)) {
285
+            $collection = array_reverse($collection);
286
+            foreach ($collection as $c) {
287
+                $echap = $c['raw'];
288
+                if ($callback_function) {
289
+                    $echap = $callback_function($c, $callback_options);
290
+                }
291
+                $echap = self::echappementHtmlBase64($echap, $source);
292
+                $texte = substr_replace($texte, $echap, $c['pos'], $c['length']);
293
+            }
294
+        }
295
+        return $texte;
296
+    }
297 297
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
 				// generer un marqueur qui n'existe pas dans le texte
129 129
 				do {
130 130
 					$this->markId = substr(md5(uniqid(static::class, 1)), 0, 7);
131
-					$this->markId = '@|' . static::$markPrefix . $this->markId . '|';
131
+					$this->markId = '@|'.static::$markPrefix.$this->markId.'|';
132 132
 				} while (str_contains($texte, $this->markId));
133 133
 			}
134 134
 
135 135
 			$offset_pos = 0;
136 136
 			foreach ($collection as $c) {
137
-				$rempl = $this->markId . base64_encode((string) $c['raw']) . '|@';
137
+				$rempl = $this->markId.base64_encode((string) $c['raw']).'|@';
138 138
 				$texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']);
139 139
 				$offset_pos += strlen($rempl) - $c['length'];
140 140
 			}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		static $pregBalisesBloc;
180 180
 
181 181
 		if ($pregBalisesBloc === null) {
182
-			$pregBalisesBloc = ',</?(' . implode('|', static::$listeBalisesBloc) . ')[>[:space:]],iS';
182
+			$pregBalisesBloc = ',</?('.implode('|', static::$listeBalisesBloc).')[>[:space:]],iS';
183 183
 		}
184 184
 		return (str_contains($texte, '<') && preg_match($pregBalisesBloc, $texte)) ? true : false;
185 185
 	}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 				include_spip('inc/filtres');
206 206
 			}
207 207
 			foreach ($attributs as $k => $v) {
208
-				$atts .= " $k=\"" . \attribut_html($v) . '"';
208
+				$atts .= " $k=\"".\attribut_html($v).'"';
209 209
 			}
210 210
 		}
211 211
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 			# spip_log(spip_htmlspecialchars($texte));  ## pour les curieux
236 236
 			$max_prof = 5;
237 237
 			$encore = true;
238
-			while ($encore && str_contains($texte, 'base64' . $source) && $max_prof--) {
238
+			while ($encore && str_contains($texte, 'base64'.$source) && $max_prof--) {
239 239
 				$encore = false;
240 240
 				foreach (['span', 'div'] as $tag) {
241 241
 					$htmlTagCollecteur = new HtmlTag(
Please login to merge, or discard this patch.
ecrire/src/Texte/Collecteur/Idiomes.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
 				$offset_pos = 0;
108 108
 				foreach ($idiomes as $idiome) {
109 109
 
110
-					$cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine'];
110
+					$cle = ($idiome['module'] ? $idiome['module'].':' : '').$idiome['chaine'];
111 111
 					$desc = $traduire($cle, $lang, true);
112 112
 					$l = $desc->langue;
113 113
 
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -21,109 +21,109 @@
 block discarded – undo
21 21
  * Ne pas mettre de span@lang=fr si on est déjà en fr.
22 22
  */
23 23
 class Idiomes extends AbstractCollecteur {
24
-	protected static string $markPrefix = 'IDIOME';
25
-
26
-	/**
27
-	 * La preg pour découper et collecter les modèles
28
-	 * @var string
29
-	 */
30
-	protected string $preg_idiome;
31
-
32
-	public function __construct(?string $preg = null) {
33
-
34
-		$this->preg_idiome = ($preg ?: '@<:(?:([a-z0-9_]+):)?([a-z0-9_]+):>@isS');
35
-	}
36
-
37
-	/**
38
-	 * Sanitizer une collection d'occurences d'idiomes : on ne fait rien
39
-	 *
40
-	 * @param array $collection
41
-	 * @param string $sanitize_callback
42
-	 * @return array
43
-	 */
44
-	protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
45
-
46
-		return $collection;
47
-	}
48
-
49
-
50
-	/**
51
-	 * @param string $texte
52
-	 * @param array $options
53
-	 *   bool $collecter_liens
54
-	 * @return array
55
-	 */
56
-	public function collecter(string $texte, array $options = []): array {
57
-		if (!$texte) {
58
-			return [];
59
-		}
60
-
61
-		// collecter les matchs de la preg
62
-		$idiomes = static::collecteur($texte, '', '<:', $this->preg_idiome, empty($options['detecter_presence']) ? 0 : 1);
63
-
64
-		// si on veut seulement detecter la présence, on peut retourner tel quel
65
-		if (empty($options['detecter_presence'])) {
66
-			$pos_prev = 0;
67
-			foreach ($idiomes as $k => &$idiome) {
68
-				$idiome['module'] = $idiome['match'][1];
69
-				$idiome['chaine'] = $idiome['match'][2];
70
-			}
71
-		}
72
-
73
-		return $idiomes;
74
-	}
75
-
76
-	/**
77
-	 * Traiter les idiomes d'un texte
78
-	 *
79
-	 * @uses inc_traduire_dist()
80
-	 * @uses code_echappement()
81
-	 * @uses echappe_retour()
82
-	 *
83
-	 * @param string $texte
84
-	 * @param array $options
85
-	 *   ?string $lang
86
-	 *   ?bool echappe_span
87
-	 * @return string
88
-	 */
89
-	public function traiter(string $texte, array $options) {
90
-		static $traduire;
91
-		if ($texte) {
92
-			$idiomes = $this->collecter($texte);
93
-			if ($idiomes !== []) {
94
-				$lang = $options['lang'] ?? $GLOBALS['spip_lang'];
95
-				$echappe_span = $options['echappe_span'] ?? false;
96
-
97
-				if (is_null($traduire)) {
98
-					$traduire = charger_fonction('traduire', 'inc');
99
-					include_spip('inc/lang');
100
-				}
101
-
102
-				$offset_pos = 0;
103
-				foreach ($idiomes as $idiome) {
104
-					$cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine'];
105
-					$desc = $traduire($cle, $lang, true);
106
-					$l = $desc->langue;
107
-
108
-					// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
109
-					if (strlen($desc->texte ?? '')) {
110
-						$trad = self::echappementHtmlBase64($desc->texte, 'idiome');
111
-						if ($l !== $lang) {
112
-							$trad = str_replace("'", '"', (string) inserer_attribut($trad, 'lang', $l));
113
-						}
114
-						if (lang_dir($l) !== lang_dir($lang)) {
115
-							$trad = str_replace("'", '"', (string) inserer_attribut($trad, 'dir', lang_dir($l)));
116
-						}
117
-						if (!$echappe_span) {
118
-							$trad = self::retablir_depuisHtmlBase64($trad, 'idiome');
119
-						}
120
-						$texte = substr_replace($texte, (string) $trad, $idiome['pos'] + $offset_pos, $idiome['length']);
121
-						$offset_pos += strlen((string) $trad) - $idiome['length'];
122
-					}
123
-				}
124
-			}
125
-		}
126
-
127
-		return $texte;
128
-	}
24
+    protected static string $markPrefix = 'IDIOME';
25
+
26
+    /**
27
+     * La preg pour découper et collecter les modèles
28
+     * @var string
29
+     */
30
+    protected string $preg_idiome;
31
+
32
+    public function __construct(?string $preg = null) {
33
+
34
+        $this->preg_idiome = ($preg ?: '@<:(?:([a-z0-9_]+):)?([a-z0-9_]+):>@isS');
35
+    }
36
+
37
+    /**
38
+     * Sanitizer une collection d'occurences d'idiomes : on ne fait rien
39
+     *
40
+     * @param array $collection
41
+     * @param string $sanitize_callback
42
+     * @return array
43
+     */
44
+    protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
45
+
46
+        return $collection;
47
+    }
48
+
49
+
50
+    /**
51
+     * @param string $texte
52
+     * @param array $options
53
+     *   bool $collecter_liens
54
+     * @return array
55
+     */
56
+    public function collecter(string $texte, array $options = []): array {
57
+        if (!$texte) {
58
+            return [];
59
+        }
60
+
61
+        // collecter les matchs de la preg
62
+        $idiomes = static::collecteur($texte, '', '<:', $this->preg_idiome, empty($options['detecter_presence']) ? 0 : 1);
63
+
64
+        // si on veut seulement detecter la présence, on peut retourner tel quel
65
+        if (empty($options['detecter_presence'])) {
66
+            $pos_prev = 0;
67
+            foreach ($idiomes as $k => &$idiome) {
68
+                $idiome['module'] = $idiome['match'][1];
69
+                $idiome['chaine'] = $idiome['match'][2];
70
+            }
71
+        }
72
+
73
+        return $idiomes;
74
+    }
75
+
76
+    /**
77
+     * Traiter les idiomes d'un texte
78
+     *
79
+     * @uses inc_traduire_dist()
80
+     * @uses code_echappement()
81
+     * @uses echappe_retour()
82
+     *
83
+     * @param string $texte
84
+     * @param array $options
85
+     *   ?string $lang
86
+     *   ?bool echappe_span
87
+     * @return string
88
+     */
89
+    public function traiter(string $texte, array $options) {
90
+        static $traduire;
91
+        if ($texte) {
92
+            $idiomes = $this->collecter($texte);
93
+            if ($idiomes !== []) {
94
+                $lang = $options['lang'] ?? $GLOBALS['spip_lang'];
95
+                $echappe_span = $options['echappe_span'] ?? false;
96
+
97
+                if (is_null($traduire)) {
98
+                    $traduire = charger_fonction('traduire', 'inc');
99
+                    include_spip('inc/lang');
100
+                }
101
+
102
+                $offset_pos = 0;
103
+                foreach ($idiomes as $idiome) {
104
+                    $cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine'];
105
+                    $desc = $traduire($cle, $lang, true);
106
+                    $l = $desc->langue;
107
+
108
+                    // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
109
+                    if (strlen($desc->texte ?? '')) {
110
+                        $trad = self::echappementHtmlBase64($desc->texte, 'idiome');
111
+                        if ($l !== $lang) {
112
+                            $trad = str_replace("'", '"', (string) inserer_attribut($trad, 'lang', $l));
113
+                        }
114
+                        if (lang_dir($l) !== lang_dir($lang)) {
115
+                            $trad = str_replace("'", '"', (string) inserer_attribut($trad, 'dir', lang_dir($l)));
116
+                        }
117
+                        if (!$echappe_span) {
118
+                            $trad = self::retablir_depuisHtmlBase64($trad, 'idiome');
119
+                        }
120
+                        $texte = substr_replace($texte, (string) $trad, $idiome['pos'] + $offset_pos, $idiome['length']);
121
+                        $offset_pos += strlen((string) $trad) - $idiome['length'];
122
+                    }
123
+                }
124
+            }
125
+        }
126
+
127
+        return $texte;
128
+    }
129 129
 }
Please login to merge, or discard this patch.
ecrire/src/Texte/Collecteur/Modeles.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,11 +32,10 @@
 block discarded – undo
32 32
 
33 33
 	public function __construct(?string $preg = null) {
34 34
 
35
-		$this->preg_modele = ($preg ?:
36
-			'@<([a-z_-]{3,})' # <modele
35
+		$this->preg_modele = ($preg ?: '@<([a-z_-]{3,})' # <modele
37 36
 			. '\s*([0-9]*)\s*' # id
38 37
 			. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
39
-			. '\s*/?' . '>@isS' # fin du modele >
38
+			. '\s*/?'.'>@isS' # fin du modele >
40 39
 		);
41 40
 	}
42 41
 
Please login to merge, or discard this patch.
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -20,203 +20,203 @@
 block discarded – undo
20 20
  *    mais on renvoie les params (pour l'indexation par le moteur de recherche)
21 21
  */
22 22
 class Modeles extends AbstractCollecteur {
23
-	protected static string $markPrefix = 'MODELE';
24
-
25
-	/**
26
-	 * La preg pour découper et collecter les modèles
27
-	 * @var string
28
-	 */
29
-	protected string $preg_modele;
30
-
31
-	public function __construct(?string $preg = null) {
32
-
33
-		$this->preg_modele = ($preg ?:
34
-			'@<([a-z_-]{3,})' # <modele
35
-			. '\s*([0-9]*)\s*' # id
36
-			. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
37
-			. '\s*/?' . '>@isS' # fin du modele >
38
-		);
39
-	}
40
-
41
-	/**
42
-	 * Sanitizer une collection d'occurences de modèle : on ne fait rien
43
-	 *
44
-	 * @param array $collection
45
-	 * @param string $sanitize_callback
46
-	 * @return array
47
-	 */
48
-	protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
49
-
50
-		return $collection;
51
-	}
52
-
53
-	/**
54
-	 * @param string $texte
55
-	 * @param array $options
56
-	 *   bool $collecter_liens
57
-	 * @return array
58
-	 */
59
-	public function collecter(string $texte, array $options = []): array {
60
-		if (!$texte) {
61
-			return [];
62
-		}
63
-
64
-		// collecter les matchs de la preg
65
-		$modeles = static::collecteur($texte, '', '<', $this->preg_modele);
66
-
67
-		$pos_prev = 0;
68
-		foreach ($modeles as $k => &$modele) {
69
-			$pos = $modele['pos'];
70
-			$modele['type'] = $modele['match'][1];
71
-			$modele['id'] = $modele['match'][2] ?? '';
72
-			$modele['params'] = $modele['match'][3] ?? '';
73
-
74
-			$longueur = $modele['length'];
75
-			$end = $pos + $longueur;
76
-
77
-			// il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html
78
-			if (empty($modele['id']) && empty($modele['params'])) {
79
-				unset($modeles[$k]);
80
-				continue;
81
-			}
82
-
83
-			// si on veut seulement detecter la présence, on peut retourner tel quel
84
-			if (!empty($options['detecter_presence'])) {
85
-				break;
86
-			}
87
-
88
-			$modele['lien'] = false;
89
-			if (
90
-				!empty($options['collecter_liens'])
91
-				&& ($pos_fermeture_lien = stripos($texte, '</a>', $end))
92
-				&& !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end)))
93
-			) {
94
-				$pos_lien_ouvrant = stripos($texte, '<a', $pos_prev);
95
-				if (
96
-					$pos_lien_ouvrant !== false
97
-					&& $pos_lien_ouvrant < $pos
98
-					&& preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r)
99
-				) {
100
-					$modele['lien'] = [
101
-						'href' => extraire_attribut($r[0], 'href'),
102
-						'class' => extraire_attribut($r[0], 'class'),
103
-						'mime' => extraire_attribut($r[0], 'type'),
104
-						'title' => extraire_attribut($r[0], 'title'),
105
-						'hreflang' => extraire_attribut($r[0], 'hreflang')
106
-					];
107
-					$n = strlen($r[0]);
108
-					$pos -= $n;
109
-					$longueur = $pos_fermeture_lien - $pos + 4;
110
-					$end = $pos + $longueur;
111
-				}
112
-			}
113
-
114
-
115
-			$modele['pos'] = $pos;
116
-			$modele['length'] = $longueur;
117
-			$pos_prev = $end;
118
-		}
119
-
120
-		return $modeles;
121
-	}
122
-
123
-	/**
124
-	 * Traiter les modeles d'un texte
125
-	 * @param string $texte
126
-	 * @param array $options
127
-	 *   bool|array $doublons
128
-	 *   string $echap
129
-	 *   ?Spip\Texte\CollecteurLiens $collecteurLiens
130
-	 *   ?array $env
131
-	 *   ?string $connect
132
-	 * @return string
133
-	 */
134
-	public function traiter(string $texte, array $options) {
135
-		if ($texte) {
136
-			$doublons = $options['doublons'] ?? false;
137
-			$echap = $options['echap'] ?? '';
138
-			$collecteurLiens = $options['collecteurLiens'] ?? null;
139
-			$env = $options['env'] ?? [];
140
-			$connect = $options['connect'] ?? '';
141
-
142
-			// preserver la compatibilite : true = recherche des documents
143
-			if ($doublons === true) {
144
-				$doublons = ['documents' => ['doc', 'emb', 'img']];
145
-			}
146
-
147
-			$modeles = $this->collecter($texte, ['collecter_liens' => true]);
148
-			if ($modeles !== []) {
149
-				include_spip('public/assembler');
150
-				$wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
151
-
152
-				$offset_pos = 0;
153
-				foreach ($modeles as $m) {
154
-					// calculer le modele
155
-					# hack indexation
156
-					if ($doublons) {
157
-						$texte .= preg_replace(',[|][^|=]*,s', ' ', (string) $m['params']);
158
-					} # version normale
159
-					else {
160
-						// si un tableau de liens a ete passe, reinjecter le contenu d'origine
161
-						// dans les parametres, plutot que les liens echappes
162
-						$params = $m['params'];
163
-						if (!is_null($collecteurLiens)) {
164
-							$params = $collecteurLiens->retablir($params);
165
-						}
166
-
167
-						$modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env);
168
-
169
-						// en cas d'echec,
170
-						// si l'objet demande a une url,
171
-						// creer un petit encadre vers elle
172
-						if ($modele === false) {
173
-							$modele = $m['raw'];
174
-
175
-							if (!is_null($collecteurLiens)) {
176
-								$modele = $collecteurLiens->retablir($modele);
177
-							}
178
-
179
-							$contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]);
180
-
181
-							if (!empty($m['lien'])) {
182
-								# un eventuel guillemet (") sera reechappe par #ENV
183
-								$contexte['lien'] = str_replace('&quot;', '"', (string) $m['lien']['href']);
184
-								$contexte['lien_class'] = $m['lien']['class'];
185
-								$contexte['lien_mime'] = $m['lien']['mime'];
186
-								$contexte['lien_title'] = $m['lien']['title'];
187
-								$contexte['lien_hreflang'] = $m['lien']['hreflang'];
188
-							}
189
-
190
-							$modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? '');
191
-						}
192
-
193
-						// le remplacer dans le texte
194
-						if ($modele !== false) {
195
-							$modele = protege_js_modeles($modele);
196
-
197
-							if ($wrap_embed_html) {
198
-								$modele = $wrap_embed_html($m['raw'], $modele);
199
-							}
200
-
201
-							$rempl = self::echappementHtmlBase64($modele, $echap);
202
-							$texte = substr_replace($texte, (string) $rempl, $m['pos'] + $offset_pos, $m['length']);
203
-							$offset_pos += strlen((string) $rempl) - $m['length'];
204
-						}
205
-					}
206
-
207
-					// hack pour tout l'espace prive
208
-					if ((test_espace_prive() || $doublons) && !empty($m['id'])) {
209
-						$type = strtolower((string) $m['type']);
210
-						foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) {
211
-							if (in_array($type, $type_modeles)) {
212
-								$GLOBALS["doublons_{$quoi}_inclus"][] = $m['id'];
213
-							}
214
-						}
215
-					}
216
-				}
217
-			}
218
-		}
219
-
220
-		return $texte;
221
-	}
23
+    protected static string $markPrefix = 'MODELE';
24
+
25
+    /**
26
+     * La preg pour découper et collecter les modèles
27
+     * @var string
28
+     */
29
+    protected string $preg_modele;
30
+
31
+    public function __construct(?string $preg = null) {
32
+
33
+        $this->preg_modele = ($preg ?:
34
+            '@<([a-z_-]{3,})' # <modele
35
+            . '\s*([0-9]*)\s*' # id
36
+            . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
37
+            . '\s*/?' . '>@isS' # fin du modele >
38
+        );
39
+    }
40
+
41
+    /**
42
+     * Sanitizer une collection d'occurences de modèle : on ne fait rien
43
+     *
44
+     * @param array $collection
45
+     * @param string $sanitize_callback
46
+     * @return array
47
+     */
48
+    protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
49
+
50
+        return $collection;
51
+    }
52
+
53
+    /**
54
+     * @param string $texte
55
+     * @param array $options
56
+     *   bool $collecter_liens
57
+     * @return array
58
+     */
59
+    public function collecter(string $texte, array $options = []): array {
60
+        if (!$texte) {
61
+            return [];
62
+        }
63
+
64
+        // collecter les matchs de la preg
65
+        $modeles = static::collecteur($texte, '', '<', $this->preg_modele);
66
+
67
+        $pos_prev = 0;
68
+        foreach ($modeles as $k => &$modele) {
69
+            $pos = $modele['pos'];
70
+            $modele['type'] = $modele['match'][1];
71
+            $modele['id'] = $modele['match'][2] ?? '';
72
+            $modele['params'] = $modele['match'][3] ?? '';
73
+
74
+            $longueur = $modele['length'];
75
+            $end = $pos + $longueur;
76
+
77
+            // il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html
78
+            if (empty($modele['id']) && empty($modele['params'])) {
79
+                unset($modeles[$k]);
80
+                continue;
81
+            }
82
+
83
+            // si on veut seulement detecter la présence, on peut retourner tel quel
84
+            if (!empty($options['detecter_presence'])) {
85
+                break;
86
+            }
87
+
88
+            $modele['lien'] = false;
89
+            if (
90
+                !empty($options['collecter_liens'])
91
+                && ($pos_fermeture_lien = stripos($texte, '</a>', $end))
92
+                && !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end)))
93
+            ) {
94
+                $pos_lien_ouvrant = stripos($texte, '<a', $pos_prev);
95
+                if (
96
+                    $pos_lien_ouvrant !== false
97
+                    && $pos_lien_ouvrant < $pos
98
+                    && preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r)
99
+                ) {
100
+                    $modele['lien'] = [
101
+                        'href' => extraire_attribut($r[0], 'href'),
102
+                        'class' => extraire_attribut($r[0], 'class'),
103
+                        'mime' => extraire_attribut($r[0], 'type'),
104
+                        'title' => extraire_attribut($r[0], 'title'),
105
+                        'hreflang' => extraire_attribut($r[0], 'hreflang')
106
+                    ];
107
+                    $n = strlen($r[0]);
108
+                    $pos -= $n;
109
+                    $longueur = $pos_fermeture_lien - $pos + 4;
110
+                    $end = $pos + $longueur;
111
+                }
112
+            }
113
+
114
+
115
+            $modele['pos'] = $pos;
116
+            $modele['length'] = $longueur;
117
+            $pos_prev = $end;
118
+        }
119
+
120
+        return $modeles;
121
+    }
122
+
123
+    /**
124
+     * Traiter les modeles d'un texte
125
+     * @param string $texte
126
+     * @param array $options
127
+     *   bool|array $doublons
128
+     *   string $echap
129
+     *   ?Spip\Texte\CollecteurLiens $collecteurLiens
130
+     *   ?array $env
131
+     *   ?string $connect
132
+     * @return string
133
+     */
134
+    public function traiter(string $texte, array $options) {
135
+        if ($texte) {
136
+            $doublons = $options['doublons'] ?? false;
137
+            $echap = $options['echap'] ?? '';
138
+            $collecteurLiens = $options['collecteurLiens'] ?? null;
139
+            $env = $options['env'] ?? [];
140
+            $connect = $options['connect'] ?? '';
141
+
142
+            // preserver la compatibilite : true = recherche des documents
143
+            if ($doublons === true) {
144
+                $doublons = ['documents' => ['doc', 'emb', 'img']];
145
+            }
146
+
147
+            $modeles = $this->collecter($texte, ['collecter_liens' => true]);
148
+            if ($modeles !== []) {
149
+                include_spip('public/assembler');
150
+                $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
151
+
152
+                $offset_pos = 0;
153
+                foreach ($modeles as $m) {
154
+                    // calculer le modele
155
+                    # hack indexation
156
+                    if ($doublons) {
157
+                        $texte .= preg_replace(',[|][^|=]*,s', ' ', (string) $m['params']);
158
+                    } # version normale
159
+                    else {
160
+                        // si un tableau de liens a ete passe, reinjecter le contenu d'origine
161
+                        // dans les parametres, plutot que les liens echappes
162
+                        $params = $m['params'];
163
+                        if (!is_null($collecteurLiens)) {
164
+                            $params = $collecteurLiens->retablir($params);
165
+                        }
166
+
167
+                        $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env);
168
+
169
+                        // en cas d'echec,
170
+                        // si l'objet demande a une url,
171
+                        // creer un petit encadre vers elle
172
+                        if ($modele === false) {
173
+                            $modele = $m['raw'];
174
+
175
+                            if (!is_null($collecteurLiens)) {
176
+                                $modele = $collecteurLiens->retablir($modele);
177
+                            }
178
+
179
+                            $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]);
180
+
181
+                            if (!empty($m['lien'])) {
182
+                                # un eventuel guillemet (") sera reechappe par #ENV
183
+                                $contexte['lien'] = str_replace('&quot;', '"', (string) $m['lien']['href']);
184
+                                $contexte['lien_class'] = $m['lien']['class'];
185
+                                $contexte['lien_mime'] = $m['lien']['mime'];
186
+                                $contexte['lien_title'] = $m['lien']['title'];
187
+                                $contexte['lien_hreflang'] = $m['lien']['hreflang'];
188
+                            }
189
+
190
+                            $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? '');
191
+                        }
192
+
193
+                        // le remplacer dans le texte
194
+                        if ($modele !== false) {
195
+                            $modele = protege_js_modeles($modele);
196
+
197
+                            if ($wrap_embed_html) {
198
+                                $modele = $wrap_embed_html($m['raw'], $modele);
199
+                            }
200
+
201
+                            $rempl = self::echappementHtmlBase64($modele, $echap);
202
+                            $texte = substr_replace($texte, (string) $rempl, $m['pos'] + $offset_pos, $m['length']);
203
+                            $offset_pos += strlen((string) $rempl) - $m['length'];
204
+                        }
205
+                    }
206
+
207
+                    // hack pour tout l'espace prive
208
+                    if ((test_espace_prive() || $doublons) && !empty($m['id'])) {
209
+                        $type = strtolower((string) $m['type']);
210
+                        foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) {
211
+                            if (in_array($type, $type_modeles)) {
212
+                                $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id'];
213
+                            }
214
+                        }
215
+                    }
216
+                }
217
+            }
218
+        }
219
+
220
+        return $texte;
221
+    }
222 222
 }
Please login to merge, or discard this patch.
ecrire/inc/liens.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,5 +11,5 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
Please login to merge, or discard this patch.
ecrire/iterateur/condition.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('iterateur/data');
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
  *     Description de la boucle complétée des champs
38 38
  */
39 39
 function iterateur_CONDITION_dist($b) {
40
-	$b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
-	$b->show = [
42
-		'field' => []
43
-	];
40
+    $b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
+    $b->show = [
42
+        'field' => []
43
+    ];
44 44
 
45
-	return $b;
45
+    return $b;
46 46
 }
Please login to merge, or discard this patch.
ecrire/iterateur/php.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
  *     Description de la boucle complétée des champs
39 39
  */
40 40
 function iterateur_php_dist($b, $iteratorName) {
41
-	$b->iterateur = $iteratorName; # designe la classe d'iterateur
42
-	$b->show = [
43
-		'field' => [
44
-			'cle' => 'STRING',
45
-			'valeur' => 'STRING',
46
-		]
47
-	];
48
-
49
-	foreach (get_class_methods($iteratorName) as $method) {
50
-		$b->show['field'][strtolower($method)] = 'METHOD';
51
-	}
52
-
53
-	return $b;
41
+    $b->iterateur = $iteratorName; # designe la classe d'iterateur
42
+    $b->show = [
43
+        'field' => [
44
+            'cle' => 'STRING',
45
+            'valeur' => 'STRING',
46
+        ]
47
+    ];
48
+
49
+    foreach (get_class_methods($iteratorName) as $method) {
50
+        $b->show['field'][strtolower($method)] = 'METHOD';
51
+    }
52
+
53
+    return $b;
54 54
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Iterateur/Condition.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@
 block discarded – undo
9 9
  */
10 10
 class Condition extends Data
11 11
 {
12
-	/**
13
-	 * Obtenir les données de la boucle CONDITION.
14
-	 *
15
-	 * @param array $command
16
-	 */
17
-	protected function select($command) {
18
-		$this->tableau = [0 => 1];
19
-	}
12
+    /**
13
+     * Obtenir les données de la boucle CONDITION.
14
+     *
15
+     * @param array $command
16
+     */
17
+    protected function select($command) {
18
+        $this->tableau = [0 => 1];
19
+    }
20 20
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Noeud/Inclure.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -7,63 +7,63 @@
 block discarded – undo
7 7
  **/
8 8
 class Inclure
9 9
 {
10
-	/** Type de noeud */
11
-	public string $type = 'include';
10
+    /** Type de noeud */
11
+    public string $type = 'include';
12 12
 
13
-	/**
14
-	 * Nom d'un fichier inclu
15
-	 *
16
-	 * - Objet Texte si inclusion d'un autre squelette
17
-	 * - chaîne si inclusion d'un fichier PHP directement
18
-	 *
19
-	 * @var string|Texte
20
-	 */
21
-	public $texte;
13
+    /**
14
+     * Nom d'un fichier inclu
15
+     *
16
+     * - Objet Texte si inclusion d'un autre squelette
17
+     * - chaîne si inclusion d'un fichier PHP directement
18
+     *
19
+     * @var string|Texte
20
+     */
21
+    public $texte;
22 22
 
23
-	/**
24
-	 * Inutilisé, propriété générique de l'AST
25
-	 *
26
-	 * @var string|array
27
-	 */
28
-	public $avant = '';
23
+    /**
24
+     * Inutilisé, propriété générique de l'AST
25
+     *
26
+     * @var string|array
27
+     */
28
+    public $avant = '';
29 29
 
30
-	/**
31
-	 * Inutilisé, propriété générique de l'AST
32
-	 *
33
-	 * @var string|array
34
-	 */
35
-	public $apres = '';
30
+    /**
31
+     * Inutilisé, propriété générique de l'AST
32
+     *
33
+     * @var string|array
34
+     */
35
+    public $apres = '';
36 36
 
37
-	/** Numéro de ligne dans le code source du squelette */
38
-	public int $ligne = 0;
37
+    /** Numéro de ligne dans le code source du squelette */
38
+    public int $ligne = 0;
39 39
 
40
-	/**
41
-	 * Valeurs des paramètres
42
-	 *
43
-	 * FIXME: type unique.
44
-	 * @var false|array
45
-	 *     - false: erreur de syntaxe
46
-	 */
47
-	public $param = [];
40
+    /**
41
+     * Valeurs des paramètres
42
+     *
43
+     * FIXME: type unique.
44
+     * @var false|array
45
+     *     - false: erreur de syntaxe
46
+     */
47
+    public $param = [];
48 48
 
49
-	/** Source des filtres (compatibilité) (?) */
50
-	public array $fonctions = [];
49
+    /** Source des filtres (compatibilité) (?) */
50
+    public array $fonctions = [];
51 51
 
52
-	/**
53
-	 * Description du squelette
54
-	 *
55
-	 * Sert pour la gestion d'erreur et la production de code dependant du contexte
56
-	 *
57
-	 * Peut contenir les index :
58
-	 *
59
-	 * - nom : Nom du fichier de cache
60
-	 * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
61
-	 * - sourcefile : Chemin du squelette
62
-	 * - squelette : Code du squelette
63
-	 * - id_mere : Identifiant de la boucle parente
64
-	 * - documents : Pour embed et img dans les textes
65
-	 * - session : Pour un cache sessionné par auteur
66
-	 * - niv : Niveau de tabulation
67
-	 */
68
-	public array $descr = [];
52
+    /**
53
+     * Description du squelette
54
+     *
55
+     * Sert pour la gestion d'erreur et la production de code dependant du contexte
56
+     *
57
+     * Peut contenir les index :
58
+     *
59
+     * - nom : Nom du fichier de cache
60
+     * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
61
+     * - sourcefile : Chemin du squelette
62
+     * - squelette : Code du squelette
63
+     * - id_mere : Identifiant de la boucle parente
64
+     * - documents : Pour embed et img dans les textes
65
+     * - session : Pour un cache sessionné par auteur
66
+     * - niv : Niveau de tabulation
67
+     */
68
+    public array $descr = [];
69 69
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Noeud/Texte.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,30 +7,30 @@
 block discarded – undo
7 7
  **/
8 8
 class Texte
9 9
 {
10
-	/** Type de noeud */
11
-	public string $type = 'texte';
10
+    /** Type de noeud */
11
+    public string $type = 'texte';
12 12
 
13
-	/** Le texte */
14
-	public string $texte;
13
+    /** Le texte */
14
+    public string $texte;
15 15
 
16
-	/**
17
-	 * Contenu avant le texte.
18
-	 *
19
-	 * Vide ou apostrophe simple ou double si le texte en était entouré
20
-	 *
21
-	 * @var string|array
22
-	 */
23
-	public $avant = '';
16
+    /**
17
+     * Contenu avant le texte.
18
+     *
19
+     * Vide ou apostrophe simple ou double si le texte en était entouré
20
+     *
21
+     * @var string|array
22
+     */
23
+    public $avant = '';
24 24
 
25
-	/**
26
-	 * Contenu après le texte.
27
-	 *
28
-	 * Vide ou apostrophe simple ou double si le texte en était entouré
29
-	 *
30
-	 * @var string|array
31
-	 */
32
-	public $apres = '';
25
+    /**
26
+     * Contenu après le texte.
27
+     *
28
+     * Vide ou apostrophe simple ou double si le texte en était entouré
29
+     *
30
+     * @var string|array
31
+     */
32
+    public $apres = '';
33 33
 
34
-	/** Numéro de ligne dans le code source du squelette */
35
-	public int $ligne = 0;
34
+    /** Numéro de ligne dans le code source du squelette */
35
+    public int $ligne = 0;
36 36
 }
Please login to merge, or discard this patch.