Completed
Push — master ( da25a8...72d0e2 )
by cam
01:32
created
ecrire/inc/pipelines_ecrire.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Pipelines
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 
@@ -34,40 +34,40 @@  discard block
 block discarded – undo
34 34
  * @return string          Contenu complété des scripts javascripts, dont jQuery
35 35
  **/
36 36
 function f_jQuery_prive($texte) {
37
-	$x = '';
38
-	$jquery_plugins = pipeline(
39
-		'jquery_plugins',
40
-		[
41
-			'prive/javascript/jquery.js',
42
-			'prive/javascript/jquery.form.js',
43
-			'prive/javascript/jquery.autosave.js',
44
-			'prive/javascript/jquery.placeholder-label.js',
45
-			'prive/javascript/ajaxCallback.js',
46
-			'prive/javascript/js.cookie.js',
47
-			'prive/javascript/spip_barre.js',
48
-		]
49
-	);
50
-	foreach (array_unique($jquery_plugins) as $script) {
51
-		$script = supprimer_timestamp($script);
52
-		if (
53
-			(str_starts_with($script, _DIR_VAR) and file_exists($script))
54
-			or $script = find_in_path($script)
55
-		) {
56
-			$script = timestamp($script);
57
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
58
-		}
59
-	}
60
-	// inserer avant le premier script externe ou a la fin
61
-	if (
62
-		preg_match(',<script[^><]*src=,', $texte, $match)
63
-		and $p = strpos($texte, (string) $match[0])
64
-	) {
65
-		$texte = substr_replace($texte, $x, $p, 0);
66
-	} else {
67
-		$texte .= $x;
68
-	}
37
+    $x = '';
38
+    $jquery_plugins = pipeline(
39
+        'jquery_plugins',
40
+        [
41
+            'prive/javascript/jquery.js',
42
+            'prive/javascript/jquery.form.js',
43
+            'prive/javascript/jquery.autosave.js',
44
+            'prive/javascript/jquery.placeholder-label.js',
45
+            'prive/javascript/ajaxCallback.js',
46
+            'prive/javascript/js.cookie.js',
47
+            'prive/javascript/spip_barre.js',
48
+        ]
49
+    );
50
+    foreach (array_unique($jquery_plugins) as $script) {
51
+        $script = supprimer_timestamp($script);
52
+        if (
53
+            (str_starts_with($script, _DIR_VAR) and file_exists($script))
54
+            or $script = find_in_path($script)
55
+        ) {
56
+            $script = timestamp($script);
57
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
58
+        }
59
+    }
60
+    // inserer avant le premier script externe ou a la fin
61
+    if (
62
+        preg_match(',<script[^><]*src=,', $texte, $match)
63
+        and $p = strpos($texte, (string) $match[0])
64
+    ) {
65
+        $texte = substr_replace($texte, $x, $p, 0);
66
+    } else {
67
+        $texte .= $x;
68
+    }
69 69
 
70
-	return $texte;
70
+    return $texte;
71 71
 }
72 72
 
73 73
 
@@ -80,42 +80,42 @@  discard block
 block discarded – undo
80 80
  * @return string
81 81
  */
82 82
 function affichage_final_prive_title_auto($texte) {
83
-	if (
84
-		strpos($texte, '<title>') === false
85
-		and
86
-		(preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
87
-			or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
88
-		and $match = textebrut(trim($match[1]))
89
-		and ($p = strpos($texte, '<head>')) !== false
90
-	) {
91
-		if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
92
-			$nom_site_spip = _T('info_mon_site_spip');
93
-		}
83
+    if (
84
+        strpos($texte, '<title>') === false
85
+        and
86
+        (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
87
+            or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
88
+        and $match = textebrut(trim($match[1]))
89
+        and ($p = strpos($texte, '<head>')) !== false
90
+    ) {
91
+        if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
92
+            $nom_site_spip = _T('info_mon_site_spip');
93
+        }
94 94
 
95
-		$titre = '<title>['
96
-			. $nom_site_spip
97
-			. '] ' . $match
98
-			. '</title>';
95
+        $titre = '<title>['
96
+            . $nom_site_spip
97
+            . '] ' . $match
98
+            . '</title>';
99 99
 
100
-		$texte = substr_replace($texte, $titre, $p + 6, 0);
101
-	}
100
+        $texte = substr_replace($texte, $titre, $p + 6, 0);
101
+    }
102 102
 
103
-	return $texte;
103
+    return $texte;
104 104
 }
105 105
 
106 106
 
107 107
 // Fonction standard pour le pipeline 'boite_infos'
108 108
 function f_boite_infos($flux) {
109
-	$args = $flux['args'];
110
-	$type = $args['type'];
111
-	unset($args['row']);
112
-	if (!trouver_fond($type, 'prive/objets/infos/')) {
113
-		$type = 'objet';
114
-	}
115
-	$args['espace_prive'] = 1;
116
-	$flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
109
+    $args = $flux['args'];
110
+    $type = $args['type'];
111
+    unset($args['row']);
112
+    if (!trouver_fond($type, 'prive/objets/infos/')) {
113
+        $type = 'objet';
114
+    }
115
+    $args['espace_prive'] = 1;
116
+    $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
120 120
 
121 121
 
@@ -134,97 +134,97 @@  discard block
 block discarded – undo
134 134
  * @return array Données du pipeline
135 135
  */
136 136
 function f_afficher_blocs_ecrire($flux) {
137
-	static $o = [];
138
-	if (is_string($fond = $flux['args']['fond'])) {
139
-		$exec = $flux['args']['contexte']['exec'] ?? _request('exec');
140
-		if (!isset($o[$exec])) {
141
-			$o[$exec] = trouver_objet_exec($exec);
142
-		}
143
-		// cas particulier
144
-		if ($exec == 'infos_perso') {
145
-			$flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
-		}
147
-		$typepage = ($flux['args']['contexte']['type-page'] ?? $exec);
148
-		if ($fond == "prive/squelettes/navigation/$typepage") {
149
-			$flux['data']['texte'] = pipeline(
150
-				'affiche_gauche',
151
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
-			);
153
-		} elseif ($fond == "prive/squelettes/extra/$typepage") {
154
-			include_spip('inc/presentation_mini');
155
-			$flux['data']['texte'] = pipeline(
156
-				'affiche_droite',
157
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
-			) . liste_objets_bloques(
159
-				$exec,
160
-				$flux['args']['contexte']
161
-			);
162
-		} elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
-			// id non defini sur les formulaire de nouveaux objets
164
-			$id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
-			$flux['data']['texte'] = pipeline(
166
-				'affiche_hierarchie',
167
-				['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
-			);
169
-		} elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
-			// Préparation du marqueur affiche_milieu
171
-			// Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
-			$est_page_objet = !empty($o[$exec]['type']);
173
-			$est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
-			$encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
-			$flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
-				$flux['data']['texte'],
177
-				'<!--affiche_milieu-->',
178
-				'<div id=["\']wysiwyg',
179
-				$encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
-				$encapsuler_milieu ? '</div>' : ''
181
-			);
182
-			if (
183
-				$o[$exec]
184
-				and $objet = $o[$exec]['type']
185
-				and $o[$exec]['edition'] == false
186
-				and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
-				and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
-			) {
189
-				// inserer le formulaire de traduction
190
-				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
-					'prive/objets/editer/traductions',
192
-					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
-				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
-					'args' => [
196
-						'contexte' => $flux['args']['contexte'],
197
-						'type' => $objet,
198
-						'id' => $id
199
-					],
200
-					'data' => $flux['data']['texte']
201
-				]);
202
-			}
203
-			$flux['data']['texte'] = pipeline(
204
-				'affiche_milieu',
205
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
-			);
207
-		} elseif ($fond == 'prive/squelettes/inclure/pied') {
208
-			$flux['data']['texte'] = pipeline(
209
-				'affiche_pied',
210
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
-			);
212
-		} elseif (
213
-			strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
-			and $objet = basename($fond)
215
-			and $objet == substr($fond, 21)
216
-			and isset($o[$objet])
217
-			and $o[$objet]
218
-		) {
219
-			$id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
-			$flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
-				'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
-				'data' => $flux['data']['texte']
223
-			]);
224
-		}
225
-	}
137
+    static $o = [];
138
+    if (is_string($fond = $flux['args']['fond'])) {
139
+        $exec = $flux['args']['contexte']['exec'] ?? _request('exec');
140
+        if (!isset($o[$exec])) {
141
+            $o[$exec] = trouver_objet_exec($exec);
142
+        }
143
+        // cas particulier
144
+        if ($exec == 'infos_perso') {
145
+            $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
+        }
147
+        $typepage = ($flux['args']['contexte']['type-page'] ?? $exec);
148
+        if ($fond == "prive/squelettes/navigation/$typepage") {
149
+            $flux['data']['texte'] = pipeline(
150
+                'affiche_gauche',
151
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
+            );
153
+        } elseif ($fond == "prive/squelettes/extra/$typepage") {
154
+            include_spip('inc/presentation_mini');
155
+            $flux['data']['texte'] = pipeline(
156
+                'affiche_droite',
157
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
+            ) . liste_objets_bloques(
159
+                $exec,
160
+                $flux['args']['contexte']
161
+            );
162
+        } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
+            // id non defini sur les formulaire de nouveaux objets
164
+            $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
+            $flux['data']['texte'] = pipeline(
166
+                'affiche_hierarchie',
167
+                ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
+            );
169
+        } elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
+            // Préparation du marqueur affiche_milieu
171
+            // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
+            $est_page_objet = !empty($o[$exec]['type']);
173
+            $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
+            $encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
+            $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
+                $flux['data']['texte'],
177
+                '<!--affiche_milieu-->',
178
+                '<div id=["\']wysiwyg',
179
+                $encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
+                $encapsuler_milieu ? '</div>' : ''
181
+            );
182
+            if (
183
+                $o[$exec]
184
+                and $objet = $o[$exec]['type']
185
+                and $o[$exec]['edition'] == false
186
+                and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
+                and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
+            ) {
189
+                // inserer le formulaire de traduction
190
+                $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
+                    'prive/objets/editer/traductions',
192
+                    ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
+                ) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
+                $flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
+                    'args' => [
196
+                        'contexte' => $flux['args']['contexte'],
197
+                        'type' => $objet,
198
+                        'id' => $id
199
+                    ],
200
+                    'data' => $flux['data']['texte']
201
+                ]);
202
+            }
203
+            $flux['data']['texte'] = pipeline(
204
+                'affiche_milieu',
205
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
+            );
207
+        } elseif ($fond == 'prive/squelettes/inclure/pied') {
208
+            $flux['data']['texte'] = pipeline(
209
+                'affiche_pied',
210
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
+            );
212
+        } elseif (
213
+            strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
+            and $objet = basename($fond)
215
+            and $objet == substr($fond, 21)
216
+            and isset($o[$objet])
217
+            and $o[$objet]
218
+        ) {
219
+            $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
+            $flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
+                'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
+                'data' => $flux['data']['texte']
223
+            ]);
224
+        }
225
+    }
226 226
 
227
-	return $flux;
227
+    return $flux;
228 228
 }
229 229
 
230 230
 /**
@@ -252,36 +252,36 @@  discard block
 block discarded – undo
252 252
  */
253 253
 function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string {
254 254
 
255
-	if ($texte) {
256
-		$encapsuler = (($ouvrir and $fermer) ? true : false);
257
-		$marqueur_pos = strpos($texte, $marqueur);
258
-		$full_marqueur = "$ouvrir$marqueur$fermer";
255
+    if ($texte) {
256
+        $encapsuler = (($ouvrir and $fermer) ? true : false);
257
+        $marqueur_pos = strpos($texte, $marqueur);
258
+        $full_marqueur = "$ouvrir$marqueur$fermer";
259 259
 
260
-		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
-		if ($marqueur_pos  === false) {
262
-			$texte = preg_replace(
263
-				",$inserer_avant,",
264
-				"$full_marqueur\\0",
265
-				$texte
266
-			);
267
-		// Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
-		// Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
-		// Il ne faut donc aucun espace blanc en trop.
270
-		} elseif (
271
-			$marqueur_pos !== false
272
-			and $encapsuler
273
-			and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
-		) {
275
-			$texte = substr_replace(
276
-				$texte,
277
-				$full_marqueur,
278
-				$marqueur_pos,
279
-				strlen($marqueur)
280
-			);
281
-		}
282
-	}
260
+        // Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
+        if ($marqueur_pos  === false) {
262
+            $texte = preg_replace(
263
+                ",$inserer_avant,",
264
+                "$full_marqueur\\0",
265
+                $texte
266
+            );
267
+        // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
+        // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
+        // Il ne faut donc aucun espace blanc en trop.
270
+        } elseif (
271
+            $marqueur_pos !== false
272
+            and $encapsuler
273
+            and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
+        ) {
275
+            $texte = substr_replace(
276
+                $texte,
277
+                $full_marqueur,
278
+                $marqueur_pos,
279
+                strlen($marqueur)
280
+            );
281
+        }
282
+    }
283 283
 
284
-	return $texte;
284
+    return $texte;
285 285
 }
286 286
 
287 287
 /**
@@ -292,23 +292,23 @@  discard block
 block discarded – undo
292 292
  * @return string
293 293
  */
294 294
 function f_queue_affiche_milieu($flux) {
295
-	$args = $flux['args'];
296
-	$res = '';
297
-	foreach ($args as $key => $arg) {
298
-		if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
-			$objet = preg_replace(',^id_,', '', $key);
300
-			$res .= recuperer_fond(
301
-				'modeles/object_jobs_list',
302
-				['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
-				['ajax' => true]
304
-			);
305
-		}
306
-	}
307
-	if ($res) {
308
-		$flux['data'] = $res . $flux['data'];
309
-	}
295
+    $args = $flux['args'];
296
+    $res = '';
297
+    foreach ($args as $key => $arg) {
298
+        if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
+            $objet = preg_replace(',^id_,', '', $key);
300
+            $res .= recuperer_fond(
301
+                'modeles/object_jobs_list',
302
+                ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
+                ['ajax' => true]
304
+            );
305
+        }
306
+    }
307
+    if ($res) {
308
+        $flux['data'] = $res . $flux['data'];
309
+    }
310 310
 
311
-	return $flux;
311
+    return $flux;
312 312
 }
313 313
 
314 314
 /**
@@ -322,39 +322,39 @@  discard block
 block discarded – undo
322 322
  * @return array|bool
323 323
  */
324 324
 function trouver_objet_exec(?string $exec) {
325
-	static $objet_exec = [];
326
-	if (!$exec) {
327
-		return false;
328
-	}
329
-	// cas particulier
330
-	if ($exec === 'infos_perso') {
331
-		$exec = 'auteur';
332
-		set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
-	}
334
-	if (!isset($objet_exec[$exec])) {
335
-		$objet_exec[$exec] = false;
336
-		$infos = lister_tables_objets_sql();
337
-		foreach ($infos as $t => $info) {
338
-			if ($exec === $info['url_edit'] and $info['editable']) {
339
-				return $objet_exec[$exec] = [
340
-					'edition' => $exec == $info['url_voir'] ? '' : true,
341
-					'table_objet_sql' => $t,
342
-					'table' => $info['table_objet'],
343
-					'type' => $info['type'],
344
-					'id_table_objet' => id_table_objet($info['type'])
345
-				];
346
-			}
347
-			if ($exec === $info['url_voir']) {
348
-				return $objet_exec[$exec] = [
349
-					'edition' => false,
350
-					'table_objet_sql' => $t,
351
-					'table' => $info['table_objet'],
352
-					'type' => $info['type'],
353
-					'id_table_objet' => id_table_objet($info['type'])
354
-				];
355
-			}
356
-		}
357
-	}
325
+    static $objet_exec = [];
326
+    if (!$exec) {
327
+        return false;
328
+    }
329
+    // cas particulier
330
+    if ($exec === 'infos_perso') {
331
+        $exec = 'auteur';
332
+        set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
+    }
334
+    if (!isset($objet_exec[$exec])) {
335
+        $objet_exec[$exec] = false;
336
+        $infos = lister_tables_objets_sql();
337
+        foreach ($infos as $t => $info) {
338
+            if ($exec === $info['url_edit'] and $info['editable']) {
339
+                return $objet_exec[$exec] = [
340
+                    'edition' => $exec == $info['url_voir'] ? '' : true,
341
+                    'table_objet_sql' => $t,
342
+                    'table' => $info['table_objet'],
343
+                    'type' => $info['type'],
344
+                    'id_table_objet' => id_table_objet($info['type'])
345
+                ];
346
+            }
347
+            if ($exec === $info['url_voir']) {
348
+                return $objet_exec[$exec] = [
349
+                    'edition' => false,
350
+                    'table_objet_sql' => $t,
351
+                    'table' => $info['table_objet'],
352
+                    'type' => $info['type'],
353
+                    'id_table_objet' => id_table_objet($info['type'])
354
+                ];
355
+            }
356
+        }
357
+    }
358 358
 
359
-	return $objet_exec[$exec];
359
+    return $objet_exec[$exec];
360 360
 }
Please login to merge, or discard this patch.