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