Completed
Push — master ( d593dc...91e0b1 )
by cam
01:24
created
ecrire/inc/presentation.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Presentation
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/presentation_mini');
@@ -32,141 +32,141 @@  discard block
 block discarded – undo
32 32
 
33 33
 // https://code.spip.net/@debut_cadre
34 34
 function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) {
35
-	$style_mapping = [
36
-		'r' => 'simple',
37
-		'e' => 'raccourcis',
38
-		'couleur' => 'basic highlight',
39
-		'couleur-foncee' => 'basic highlight',
40
-		'trait-couleur' => 'important',
41
-		'alerte' => 'notice',
42
-		'info' => 'info',
43
-		'sous_rub' => 'simple sous-rub'
44
-	];
45
-	$style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
-	$c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
-	$class = $c . ($class ? " $class" : '');
48
-	if (!$padding) {
49
-		$class .= ($class ? ' ' : '') . 'no-padding';
50
-	}
51
-
52
-	//($id?"id='$id' ":"")
53
-	if (strlen($icone) > 1) {
54
-		if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
-			list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
-		}
57
-		$size = 24;
58
-		if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
-			$size = $match[1];
60
-		}
61
-		if ($fonction) {
62
-			// 2 images pour composer l'icone : le fond (article) en background,
63
-			// la fonction (new) en image
64
-			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
-				http_style_background($fond, 'no-repeat center center', $size));
66
-		} else {
67
-			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
-		}
69
-		$titre = $icone . $titre;
70
-	}
71
-
72
-	return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
35
+    $style_mapping = [
36
+        'r' => 'simple',
37
+        'e' => 'raccourcis',
38
+        'couleur' => 'basic highlight',
39
+        'couleur-foncee' => 'basic highlight',
40
+        'trait-couleur' => 'important',
41
+        'alerte' => 'notice',
42
+        'info' => 'info',
43
+        'sous_rub' => 'simple sous-rub'
44
+    ];
45
+    $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
+    $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
+    $class = $c . ($class ? " $class" : '');
48
+    if (!$padding) {
49
+        $class .= ($class ? ' ' : '') . 'no-padding';
50
+    }
51
+
52
+    //($id?"id='$id' ":"")
53
+    if (strlen($icone) > 1) {
54
+        if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
+            list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
+        }
57
+        $size = 24;
58
+        if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
+            $size = $match[1];
60
+        }
61
+        if ($fonction) {
62
+            // 2 images pour composer l'icone : le fond (article) en background,
63
+            // la fonction (new) en image
64
+            $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
+                http_style_background($fond, 'no-repeat center center', $size));
66
+        } else {
67
+            $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
+        }
69
+        $titre = $icone . $titre;
70
+    }
71
+
72
+    return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
73 73
 }
74 74
 
75 75
 // https://code.spip.net/@fin_cadre
76 76
 function fin_cadre() {
77
- return boite_fermer();
77
+    return boite_fermer();
78 78
 }
79 79
 
80 80
 
81 81
 function debut_cadre_relief(
82
-	$icone = '',
83
-	$dummy = '',
84
-	$fonction = '',
85
-	$titre = '',
86
-	$id = '',
87
-	$class = ''
82
+    $icone = '',
83
+    $dummy = '',
84
+    $fonction = '',
85
+    $titre = '',
86
+    $id = '',
87
+    $class = ''
88 88
 ) {
89
-	return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
89
+    return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
90 90
 }
91 91
 
92 92
 function fin_cadre_relief() {
93
- return fin_cadre('r');
93
+    return fin_cadre('r');
94 94
 }
95 95
 
96 96
 function debut_cadre_enfonce(
97
-	$icone = '',
98
-	$dummy = '',
99
-	$fonction = '',
100
-	$titre = '',
101
-	$id = '',
102
-	$class = ''
97
+    $icone = '',
98
+    $dummy = '',
99
+    $fonction = '',
100
+    $titre = '',
101
+    $id = '',
102
+    $class = ''
103 103
 ) {
104
-	return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
104
+    return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
105 105
 }
106 106
 
107 107
 function fin_cadre_enfonce() {
108
- return fin_cadre('e');
108
+    return fin_cadre('e');
109 109
 }
110 110
 
111 111
 function debut_cadre_sous_rub(
112
-	$icone = '',
113
-	$dummy = '',
114
-	$fonction = '',
115
-	$titre = '',
116
-	$id = '',
117
-	$class = ''
112
+    $icone = '',
113
+    $dummy = '',
114
+    $fonction = '',
115
+    $titre = '',
116
+    $id = '',
117
+    $class = ''
118 118
 ) {
119
-	return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
119
+    return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
120 120
 }
121 121
 
122 122
 function fin_cadre_sous_rub() {
123
- return fin_cadre('sous_rub');
123
+    return fin_cadre('sous_rub');
124 124
 }
125 125
 
126 126
 function debut_cadre_couleur(
127
-	$icone = '',
128
-	$dummy = '',
129
-	$fonction = '',
130
-	$titre = '',
131
-	$id = '',
132
-	$class = ''
127
+    $icone = '',
128
+    $dummy = '',
129
+    $fonction = '',
130
+    $titre = '',
131
+    $id = '',
132
+    $class = ''
133 133
 ) {
134
-	return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
134
+    return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
135 135
 }
136 136
 
137 137
 function fin_cadre_couleur() {
138
- return fin_cadre('couleur');
138
+    return fin_cadre('couleur');
139 139
 }
140 140
 
141 141
 function debut_cadre_trait_couleur(
142
-	$icone = '',
143
-	$dummy = '',
144
-	$fonction = '',
145
-	$titre = '',
146
-	$id = '',
147
-	$class = ''
142
+    $icone = '',
143
+    $dummy = '',
144
+    $fonction = '',
145
+    $titre = '',
146
+    $id = '',
147
+    $class = ''
148 148
 ) {
149
-	return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
149
+    return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
150 150
 }
151 151
 
152 152
 function fin_cadre_trait_couleur() {
153
- return fin_cadre('trait-couleur');
153
+    return fin_cadre('trait-couleur');
154 154
 }
155 155
 
156 156
 function debut_boite_alerte() {
157
- return debut_cadre('alerte', '', '', '', '', '');
157
+    return debut_cadre('alerte', '', '', '', '', '');
158 158
 }
159 159
 
160 160
 function fin_boite_alerte() {
161
- return fin_cadre('alerte');
161
+    return fin_cadre('alerte');
162 162
 }
163 163
 
164 164
 function debut_boite_info() {
165
- return debut_cadre('info', '', '', '', '', '');
165
+    return debut_cadre('info', '', '', '', '', '');
166 166
 }
167 167
 
168 168
 function fin_boite_info() {
169
- return fin_cadre('info');
169
+    return fin_cadre('info');
170 170
 }
171 171
 
172 172
 /**
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
  * @return string Code PHP.
178 178
  **/
179 179
 function gros_titre(
180
-	$titre,
181
-	$ze_logo = ''
180
+    $titre,
181
+    $ze_logo = ''
182 182
 ) {
183
-	return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
183
+    return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
184 184
 }
185 185
 
186 186
 // La boite des raccourcis
187 187
 // Se place a droite si l'ecran est en mode panoramique.
188 188
 // https://code.spip.net/@bloc_des_raccourcis
189 189
 function bloc_des_raccourcis($bloc) {
190
-	return creer_colonne_droite()
191
-	. boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
190
+    return creer_colonne_droite()
191
+    . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
192 192
 }
193 193
 
194 194
 //
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 // https://code.spip.net/@debut_onglet
200 200
 // @param string $sous_classe	prend la valeur second pour definir les onglet de deuxieme niveau
201 201
 function debut_onglet($classe = 'barre_onglet') {
202
- return "<div class = '$classe clearfix'><ul>\n";
202
+    return "<div class = '$classe clearfix'><ul>\n";
203 203
 }
204 204
 
205 205
 // https://code.spip.net/@fin_onglet
206 206
 function fin_onglet() {
207
- return "</ul></div>\n";
207
+    return "</ul></div>\n";
208 208
 }
209 209
 
210 210
 // https://code.spip.net/@onglet
211 211
 function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') {
212
-	return '<li>'
213
-	. ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
-	. lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
-	. '</li>';
212
+    return '<li>'
213
+    . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
+    . lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
+    . '</li>';
216 216
 }
217 217
 
218 218
 /**
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
  *     Code HTML du lien
245 245
  **/
246 246
 function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') {
247
-	// cas d'ajax_action_auteur: faut defaire le boulot
248
-	// (il faudrait fusionner avec le cas $javascript)
249
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
-		list($x, $lien, $atts, $texte) = $r;
251
-		$javascript .= $atts;
252
-	}
253
-
254
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
247
+    // cas d'ajax_action_auteur: faut defaire le boulot
248
+    // (il faudrait fusionner avec le cas $javascript)
249
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
+        list($x, $lien, $atts, $texte) = $r;
251
+        $javascript .= $atts;
252
+    }
253
+
254
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
255 255
 }
256 256
 
257 257
 /**
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
  *     Code HTML du lien
277 277
  **/
278 278
 function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') {
279
-	$retour = '';
280
-	// cas d'ajax_action_auteur: faut defaire le boulot
281
-	// (il faudrait fusionner avec le cas $javascript)
282
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
-		list($x, $lien, $atts, $texte) = $r;
284
-		$javascript .= $atts;
285
-	}
279
+    $retour = '';
280
+    // cas d'ajax_action_auteur: faut defaire le boulot
281
+    // (il faudrait fusionner avec le cas $javascript)
282
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
+        list($x, $lien, $atts, $texte) = $r;
284
+        $javascript .= $atts;
285
+    }
286 286
 
287
-	$retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
287
+    $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
288 288
 
289
-	return $retour;
289
+    return $retour;
290 290
 }
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,127 +49,127 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = [],
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = [],
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = [];
60
-	$delai_fraicheur = min(
61
-		_DELAI_CACHE_resultats,
62
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
-	);
64
-
65
-	// si recherche n'est pas dans le contexte, on va prendre en globals
66
-	// ca permet de faire des inclure simple.
67
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
-		$recherche = $GLOBALS['recherche'];
69
-	}
70
-
71
-	// traiter le cas {recherche?}
72
-	if ($cond and !strlen($recherche)) {
73
-		return [
74
-			'0 as points' /* as points */, /* where */
75
-			''
76
-		];
77
-	}
78
-
79
-
80
-	$rechercher = false;
81
-
82
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
-	if (!isset($cache[$serveur][$table][$recherche])) {
84
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
-		$hash = substr(md5($recherche . $table), 0, 16);
86
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
-		$row = sql_fetsel(
88
-			'recherche',
89
-			'spip_resultats AS resultats',
90
-			$where . " AND $where_resultat_recent",
91
-			'',
92
-			'',
93
-			'0,1'
94
-		);
95
-		if (
96
-			!$row
97
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
-		) {
99
-			$rechercher = true;
100
-		}
101
-	}
102
-
103
-	// si on n'a pas encore traite les donnees dans une boucle precedente
104
-	if ($rechercher) {
105
-		//$tables = liste_des_champs();
106
-		$x = objet_type($table);
107
-		$points = recherche_en_base(
108
-			$recherche,
109
-			$x,
110
-			[
111
-				'score' => true,
112
-				'toutvoir' => true,
113
-				'jointures' => true
114
-			],
115
-			$serveur
116
-		);
117
-		// pas de résultat, pas de point
118
-		$points = isset($points[$x]) ? $points[$x] : [];
119
-
120
-		// permettre aux plugins de modifier le resultat
121
-		$points = pipeline('prepare_recherche', [
122
-			'args' => [
123
-				'type' => $x,
124
-				'recherche' => $recherche,
125
-				'serveur' => $serveur,
126
-				'modificateurs' => $modificateurs
127
-			],
128
-			'data' => $points
129
-		]);
130
-
131
-		// supprimer les anciens resultats de cette recherche
132
-		// et les resultats trop vieux avec une marge
133
-		// pas de AS resultats dans un delete (mysql)
134
-		$whered = str_replace(
135
-			['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
-			['recherche', 'table_objet', 'serveur'],
137
-			$where
138
-		);
139
-
140
-		sql_delete(
141
-			'spip_resultats',
142
-			"NOT($where_resultat_recent) OR ($whered)"
143
-		);
144
-
145
-		// inserer les resultats dans la table de cache des resultats
146
-		if (count($points)) {
147
-			$tab_couples = [];
148
-			foreach ($points as $id => $p) {
149
-				$tab_couples[] = [
150
-					'recherche' => $hash,
151
-					'id' => $id,
152
-					'points' => $p['score'],
153
-					'table_objet' => $table,
154
-					'serveur' => $hash_serv,
155
-				];
156
-			}
157
-			sql_insertq_multi('spip_resultats', $tab_couples, []);
158
-		}
159
-	}
160
-
161
-	if (!isset($cache[$serveur][$table][$recherche])) {
162
-		if (!$serveur) {
163
-			$cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
-		} else {
165
-			if (sql_countsel('spip_resultats as resultats', $where)) {
166
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
-			}
168
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
-		}
170
-	}
171
-
172
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = [];
60
+    $delai_fraicheur = min(
61
+        _DELAI_CACHE_resultats,
62
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
+    );
64
+
65
+    // si recherche n'est pas dans le contexte, on va prendre en globals
66
+    // ca permet de faire des inclure simple.
67
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
+        $recherche = $GLOBALS['recherche'];
69
+    }
70
+
71
+    // traiter le cas {recherche?}
72
+    if ($cond and !strlen($recherche)) {
73
+        return [
74
+            '0 as points' /* as points */, /* where */
75
+            ''
76
+        ];
77
+    }
78
+
79
+
80
+    $rechercher = false;
81
+
82
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
+    if (!isset($cache[$serveur][$table][$recherche])) {
84
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
+        $hash = substr(md5($recherche . $table), 0, 16);
86
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
+        $row = sql_fetsel(
88
+            'recherche',
89
+            'spip_resultats AS resultats',
90
+            $where . " AND $where_resultat_recent",
91
+            '',
92
+            '',
93
+            '0,1'
94
+        );
95
+        if (
96
+            !$row
97
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
+        ) {
99
+            $rechercher = true;
100
+        }
101
+    }
102
+
103
+    // si on n'a pas encore traite les donnees dans une boucle precedente
104
+    if ($rechercher) {
105
+        //$tables = liste_des_champs();
106
+        $x = objet_type($table);
107
+        $points = recherche_en_base(
108
+            $recherche,
109
+            $x,
110
+            [
111
+                'score' => true,
112
+                'toutvoir' => true,
113
+                'jointures' => true
114
+            ],
115
+            $serveur
116
+        );
117
+        // pas de résultat, pas de point
118
+        $points = isset($points[$x]) ? $points[$x] : [];
119
+
120
+        // permettre aux plugins de modifier le resultat
121
+        $points = pipeline('prepare_recherche', [
122
+            'args' => [
123
+                'type' => $x,
124
+                'recherche' => $recherche,
125
+                'serveur' => $serveur,
126
+                'modificateurs' => $modificateurs
127
+            ],
128
+            'data' => $points
129
+        ]);
130
+
131
+        // supprimer les anciens resultats de cette recherche
132
+        // et les resultats trop vieux avec une marge
133
+        // pas de AS resultats dans un delete (mysql)
134
+        $whered = str_replace(
135
+            ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
+            ['recherche', 'table_objet', 'serveur'],
137
+            $where
138
+        );
139
+
140
+        sql_delete(
141
+            'spip_resultats',
142
+            "NOT($where_resultat_recent) OR ($whered)"
143
+        );
144
+
145
+        // inserer les resultats dans la table de cache des resultats
146
+        if (count($points)) {
147
+            $tab_couples = [];
148
+            foreach ($points as $id => $p) {
149
+                $tab_couples[] = [
150
+                    'recherche' => $hash,
151
+                    'id' => $id,
152
+                    'points' => $p['score'],
153
+                    'table_objet' => $table,
154
+                    'serveur' => $hash_serv,
155
+                ];
156
+            }
157
+            sql_insertq_multi('spip_resultats', $tab_couples, []);
158
+        }
159
+    }
160
+
161
+    if (!isset($cache[$serveur][$table][$recherche])) {
162
+        if (!$serveur) {
163
+            $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
+        } else {
165
+            if (sql_countsel('spip_resultats as resultats', $where)) {
166
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
+            }
168
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
+        }
170
+    }
171
+
172
+    return $cache[$serveur][$table][$recherche];
173 173
 }
174 174
 
175 175
 
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
  * @return array
186 186
  */
187 187
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
188
-	# calculer le {id_article IN()} et le {... as points}
189
-	if (!count($rows)) {
190
-		return ["''", '0=1'];
191
-	} else {
192
-		$listes_ids = [];
193
-		$select = '0';
194
-		foreach ($rows as $r) {
195
-			$listes_ids[$r['points']][] = $r['id'];
196
-		}
197
-
198
-		foreach ($listes_ids as $p => $ids) {
199
-			$select .= "+$p*(" .
200
-				sql_in("$table.$primary", $ids, '', $serveur)
201
-				. ') ';
202
-		}
203
-
204
-		return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
-	}
188
+    # calculer le {id_article IN()} et le {... as points}
189
+    if (!count($rows)) {
190
+        return ["''", '0=1'];
191
+    } else {
192
+        $listes_ids = [];
193
+        $select = '0';
194
+        foreach ($rows as $r) {
195
+            $listes_ids[$r['points']][] = $r['id'];
196
+        }
197
+
198
+        foreach ($listes_ids as $p => $ids) {
199
+            $select .= "+$p*(" .
200
+                sql_in("$table.$primary", $ids, '', $serveur)
201
+                . ') ';
202
+        }
203
+
204
+        return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
+    }
206 206
 }
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/charsets');
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function exporter_csv_champ($champ) {
35
-	#$champ = str_replace("\r", "\n", $champ);
36
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
-	#$champ = str_replace("\n", ", ", $champ);
38
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
-	$champ = str_replace('"', '""', $champ);
35
+    #$champ = str_replace("\r", "\n", $champ);
36
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
+    #$champ = str_replace("\n", ", ", $champ);
38
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
+    $champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+    return '"' . $champ . '"';
42 42
 }
43 43
 
44 44
 /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
  * @return string
56 56
  */
57 57
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, $callback = null) {
58
-	if ($callback) {
59
-		$ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
-	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
-	if ($importer_charset) {
63
-		$output = str_replace('’', '\'', $output);
64
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
-	}
66
-	return $output;
58
+    if ($callback) {
59
+        $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
+    }
61
+    $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
+    if ($importer_charset) {
63
+        $output = str_replace('’', '\'', $output);
64
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
+    }
66
+    return $output;
67 67
 }
68 68
 
69 69
 /**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
  * @return string
76 76
  */
77 77
 function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
78
-	return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
78
+    return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
79 79
 }
80 80
 
81 81
 /**
@@ -101,101 +101,101 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
103 103
 
104
-	// support ancienne syntaxe
105
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
-	if (is_string($options)) {
107
-		$args = func_get_args();
108
-		$options = [];
109
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
-			if (!empty($args[$k])) {
111
-				$options[$option] = $args[$k];
112
-			}
113
-		}
114
-	}
115
-
116
-	$default_options = [
117
-		'delim' => ', ',
118
-		'entetes' => null,
119
-		'envoyer' => true,
120
-		'charset' => null,
121
-		'callback' => null,
122
-	];
123
-	$options = array_merge($default_options, $options);
124
-
125
-	$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
-
127
-	if ($options['delim'] == 'TAB') {
128
-		$options['delim'] = "\t";
129
-	}
130
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
131
-		$options['delim'] = ',';
132
-	}
133
-
134
-	$charset = $GLOBALS['meta']['charset'];
135
-	$importer_charset = null;
136
-	if ($options['delim'] == ',') {
137
-		$extension = 'csv';
138
-	} else {
139
-		$extension = 'xls';
140
-		# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
-		$charset = 'iso-8859-1';
142
-	}
143
-	// mais si une option charset est explicite, elle a la priorite
144
-	if (!empty($options['charset'])) {
145
-		$charset = $options['charset'];
146
-	}
147
-
148
-	$importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
-
150
-	$filename = "$filename.$extension";
151
-
152
-	$output = '';
153
-	$nb = 0;
154
-	if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
-	}
157
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
-	$nb++;
159
-
160
-	if ($options['envoyer']) {
161
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
-		header("Content-Type: text/comma-separated-values; charset=$charset");
163
-		header("Content-Disposition: $disposition; filename=$filename");
164
-
165
-		// Vider tous les tampons
166
-		$level = @ob_get_level();
167
-		while ($level--) {
168
-			@ob_end_flush();
169
-		}
170
-	}
171
-
172
-	// si envoyer=='attachment' on passe par un fichier temporaire
173
-	// sinon on ecrit directement sur stdout
174
-	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
-		$fichier = 'php://output';
176
-	}
177
-	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
-	}
180
-
181
-	$fp = fopen($fichier, 'w');
182
-	$length = fwrite($fp, $output);
183
-
184
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
-		$length += fwrite($fp, $output);
187
-		$nb++;
188
-	}
189
-	fclose($fp);
190
-
191
-	if ($options['envoyer']) {
192
-		if ($options['envoyer'] === 'attachment') {
193
-			header("Content-Length: $length");
194
-			readfile($fichier);
195
-		}
196
-		// si on a envoye inline, c'est deja tout bon
197
-		exit;
198
-	}
199
-
200
-	return $fichier;
104
+    // support ancienne syntaxe
105
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
+    if (is_string($options)) {
107
+        $args = func_get_args();
108
+        $options = [];
109
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
+            if (!empty($args[$k])) {
111
+                $options[$option] = $args[$k];
112
+            }
113
+        }
114
+    }
115
+
116
+    $default_options = [
117
+        'delim' => ', ',
118
+        'entetes' => null,
119
+        'envoyer' => true,
120
+        'charset' => null,
121
+        'callback' => null,
122
+    ];
123
+    $options = array_merge($default_options, $options);
124
+
125
+    $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
+
127
+    if ($options['delim'] == 'TAB') {
128
+        $options['delim'] = "\t";
129
+    }
130
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
131
+        $options['delim'] = ',';
132
+    }
133
+
134
+    $charset = $GLOBALS['meta']['charset'];
135
+    $importer_charset = null;
136
+    if ($options['delim'] == ',') {
137
+        $extension = 'csv';
138
+    } else {
139
+        $extension = 'xls';
140
+        # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
+        $charset = 'iso-8859-1';
142
+    }
143
+    // mais si une option charset est explicite, elle a la priorite
144
+    if (!empty($options['charset'])) {
145
+        $charset = $options['charset'];
146
+    }
147
+
148
+    $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
+
150
+    $filename = "$filename.$extension";
151
+
152
+    $output = '';
153
+    $nb = 0;
154
+    if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
+    }
157
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
+    $nb++;
159
+
160
+    if ($options['envoyer']) {
161
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
+        header("Content-Type: text/comma-separated-values; charset=$charset");
163
+        header("Content-Disposition: $disposition; filename=$filename");
164
+
165
+        // Vider tous les tampons
166
+        $level = @ob_get_level();
167
+        while ($level--) {
168
+            @ob_end_flush();
169
+        }
170
+    }
171
+
172
+    // si envoyer=='attachment' on passe par un fichier temporaire
173
+    // sinon on ecrit directement sur stdout
174
+    if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
+        $fichier = 'php://output';
176
+    }
177
+    else {
178
+    $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
+    }
180
+
181
+    $fp = fopen($fichier, 'w');
182
+    $length = fwrite($fp, $output);
183
+
184
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
+        $length += fwrite($fp, $output);
187
+        $nb++;
188
+    }
189
+    fclose($fp);
190
+
191
+    if ($options['envoyer']) {
192
+        if ($options['envoyer'] === 'attachment') {
193
+            header("Content-Length: $length");
194
+            readfile($fichier);
195
+        }
196
+        // si on a envoye inline, c'est deja tout bon
197
+        exit;
198
+    }
199
+
200
+    return $fichier;
201 201
 }
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
@@ -58,176 +58,176 @@  discard block
 block discarded – undo
58 58
 // en ne regardant que le titre ou le nom
59 59
 // https://code.spip.net/@liste_des_jointures
60 60
 function liste_des_jointures() {
61
-	static $liste = null;
62
-	if (is_null($liste)) {
63
-		$liste = [];
64
-		// recuperer les tables_objets_sql declarees
65
-		include_spip('base/objets');
66
-		$tables_objets = lister_tables_objets_sql();
67
-		foreach ($tables_objets as $t => $infos) {
68
-			if ($infos['rechercher_jointures']) {
69
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
70
-			}
71
-		}
72
-		// puis passer dans le pipeline
73
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
74
-	}
75
-
76
-	return $liste;
61
+    static $liste = null;
62
+    if (is_null($liste)) {
63
+        $liste = [];
64
+        // recuperer les tables_objets_sql declarees
65
+        include_spip('base/objets');
66
+        $tables_objets = lister_tables_objets_sql();
67
+        foreach ($tables_objets as $t => $infos) {
68
+            if ($infos['rechercher_jointures']) {
69
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
70
+            }
71
+        }
72
+        // puis passer dans le pipeline
73
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
74
+    }
75
+
76
+    return $liste;
77 77
 }
78 78
 
79 79
 function expression_recherche($recherche, $options) {
80
-	// ne calculer qu'une seule fois l'expression par hit
81
-	// (meme si utilisee dans plusieurs boucles)
82
-	static $expression = [];
83
-	$key = serialize([$recherche, $options['preg_flags']]);
84
-	if (isset($expression[$key])) {
85
-		return $expression[$key];
86
-	}
87
-
88
-	$u = $GLOBALS['meta']['pcre_u'];
89
-	if ($u and strpos($options['preg_flags'], $u) === false) {
90
-		$options['preg_flags'] .= $u;
91
-	}
92
-	include_spip('inc/charsets');
93
-	$recherche = trim($recherche);
94
-
95
-	// retirer les + de +truc et les * de truc*
96
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
-
99
-	$is_preg = false;
100
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
-		// c'est une preg
102
-		$recherche_trans = translitteration($recherche);
103
-		$preg = $recherche_trans . $options['preg_flags'];
104
-		$is_preg = true;
105
-	} else {
106
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
-		// 'une', 'des' ...)
109
-
110
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
-
113
-		// les expressions entre " " sont un mot a chercher tel quel
114
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
115
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
-			foreach ($matches as $match) {
117
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
118
-				$word = trim($word, '"');
119
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
120
-			}
121
-		}
122
-
123
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
-			$is_preg = true;
125
-
126
-			$recherche_inter = '|';
127
-			$recherche_mots = explode(' ', $recherche_mod);
128
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
-			$petits_mots = true;
130
-			foreach ($recherche_mots as $mot) {
131
-				if (strlen($mot) >= $min_long) {
132
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
-					$recherche_inter .= preg_quote($mot) . ' ';
134
-					$petits_mots = false;
135
-				}
136
-			}
137
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
-
139
-			// mais on cherche quand même l'expression complète, même si elle
140
-			// comporte des mots de moins de quatre lettres
141
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
-			if (!$recherche or $petits_mots) {
143
-				$recherche = preg_quote($recherche_org);
144
-			}
145
-			$recherche_trans = translitteration($recherche);
146
-		}
147
-
148
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
-	}
150
-
151
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
-	// ou si l'expression reguliere est invalide
153
-	if (
154
-		!$is_preg
155
-		or (@preg_match($preg, '') === false)
156
-	) {
157
-		$methode = 'LIKE';
158
-		$u = $GLOBALS['meta']['pcre_u'];
159
-
160
-		// echapper les % et _
161
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
-
163
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
164
-		$recherche = preg_quote($recherche, '/');
165
-		$recherche_trans = translitteration($recherche);
166
-		$recherche_mod = $recherche_trans;
167
-
168
-		// les expressions entre " " sont un mot a chercher tel quel
169
-		// -> on remplace les espaces par un _ et on enleve les guillemets
170
-		// corriger le like dans le $q
171
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
-			foreach ($matches as $match) {
173
-				$word = preg_replace(',\s+,Uims', '_', $match);
174
-				$word = trim($word, '"');
175
-				$q = str_replace($match, $word, $q);
176
-			}
177
-		}
178
-		// corriger la regexp
179
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
-			foreach ($matches as $match) {
181
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
182
-				$word = trim($word, '"');
183
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
184
-			}
185
-		}
186
-		$q = sql_quote(
187
-			'%'
188
-			. preg_replace(',\s+,' . $u, '%', $q)
189
-			. '%'
190
-		);
191
-
192
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
-	} else {
194
-		$methode = 'REGEXP';
195
-		$q = sql_quote(trim($recherche, '/'));
196
-	}
197
-
198
-	// tous les caracteres transliterables de $q sont remplaces par un joker
199
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
-	$q_t = $q;
201
-	for ($i = 0; $i < spip_strlen($q); $i++) {
202
-		$char = spip_substr($q, $i, 1);
203
-		if (
204
-			!is_ascii($char)
205
-			and $char_t = translitteration($char)
206
-			and $char_t !== $char
207
-		) {
208
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
-			// mais c'est un pis aller cf #4354
210
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
-		}
212
-	}
213
-
214
-	$q = $q_t;
215
-
216
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
-	// les plus frequents qui peuvent etre accentues
218
-	// (oui c'est tres dicustable...)
219
-	if (
220
-		isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
-	) {
223
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
-		// si il reste au moins un char significatif...
225
-		if (preg_match(",[^'%_.],", $q_t)) {
226
-			$q = $q_t;
227
-		}
228
-	}
229
-
230
-	return $expression[$key] = [$methode, $q, $preg];
80
+    // ne calculer qu'une seule fois l'expression par hit
81
+    // (meme si utilisee dans plusieurs boucles)
82
+    static $expression = [];
83
+    $key = serialize([$recherche, $options['preg_flags']]);
84
+    if (isset($expression[$key])) {
85
+        return $expression[$key];
86
+    }
87
+
88
+    $u = $GLOBALS['meta']['pcre_u'];
89
+    if ($u and strpos($options['preg_flags'], $u) === false) {
90
+        $options['preg_flags'] .= $u;
91
+    }
92
+    include_spip('inc/charsets');
93
+    $recherche = trim($recherche);
94
+
95
+    // retirer les + de +truc et les * de truc*
96
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
+
99
+    $is_preg = false;
100
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
+        // c'est une preg
102
+        $recherche_trans = translitteration($recherche);
103
+        $preg = $recherche_trans . $options['preg_flags'];
104
+        $is_preg = true;
105
+    } else {
106
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
+        // 'une', 'des' ...)
109
+
110
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
+
113
+        // les expressions entre " " sont un mot a chercher tel quel
114
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
115
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
+            foreach ($matches as $match) {
117
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
118
+                $word = trim($word, '"');
119
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
120
+            }
121
+        }
122
+
123
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
+            $is_preg = true;
125
+
126
+            $recherche_inter = '|';
127
+            $recherche_mots = explode(' ', $recherche_mod);
128
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
+            $petits_mots = true;
130
+            foreach ($recherche_mots as $mot) {
131
+                if (strlen($mot) >= $min_long) {
132
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
+                    $recherche_inter .= preg_quote($mot) . ' ';
134
+                    $petits_mots = false;
135
+                }
136
+            }
137
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
+
139
+            // mais on cherche quand même l'expression complète, même si elle
140
+            // comporte des mots de moins de quatre lettres
141
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
+            if (!$recherche or $petits_mots) {
143
+                $recherche = preg_quote($recherche_org);
144
+            }
145
+            $recherche_trans = translitteration($recherche);
146
+        }
147
+
148
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
+    }
150
+
151
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
+    // ou si l'expression reguliere est invalide
153
+    if (
154
+        !$is_preg
155
+        or (@preg_match($preg, '') === false)
156
+    ) {
157
+        $methode = 'LIKE';
158
+        $u = $GLOBALS['meta']['pcre_u'];
159
+
160
+        // echapper les % et _
161
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
+
163
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
164
+        $recherche = preg_quote($recherche, '/');
165
+        $recherche_trans = translitteration($recherche);
166
+        $recherche_mod = $recherche_trans;
167
+
168
+        // les expressions entre " " sont un mot a chercher tel quel
169
+        // -> on remplace les espaces par un _ et on enleve les guillemets
170
+        // corriger le like dans le $q
171
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
+            foreach ($matches as $match) {
173
+                $word = preg_replace(',\s+,Uims', '_', $match);
174
+                $word = trim($word, '"');
175
+                $q = str_replace($match, $word, $q);
176
+            }
177
+        }
178
+        // corriger la regexp
179
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
+            foreach ($matches as $match) {
181
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
182
+                $word = trim($word, '"');
183
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
184
+            }
185
+        }
186
+        $q = sql_quote(
187
+            '%'
188
+            . preg_replace(',\s+,' . $u, '%', $q)
189
+            . '%'
190
+        );
191
+
192
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
+    } else {
194
+        $methode = 'REGEXP';
195
+        $q = sql_quote(trim($recherche, '/'));
196
+    }
197
+
198
+    // tous les caracteres transliterables de $q sont remplaces par un joker
199
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
+    $q_t = $q;
201
+    for ($i = 0; $i < spip_strlen($q); $i++) {
202
+        $char = spip_substr($q, $i, 1);
203
+        if (
204
+            !is_ascii($char)
205
+            and $char_t = translitteration($char)
206
+            and $char_t !== $char
207
+        ) {
208
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
+            // mais c'est un pis aller cf #4354
210
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
+        }
212
+    }
213
+
214
+    $q = $q_t;
215
+
216
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
+    // les plus frequents qui peuvent etre accentues
218
+    // (oui c'est tres dicustable...)
219
+    if (
220
+        isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
+    ) {
223
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
+        // si il reste au moins un char significatif...
225
+        if (preg_match(",[^'%_.],", $q_t)) {
226
+            $q = $q_t;
227
+        }
228
+    }
229
+
230
+    return $expression[$key] = [$methode, $q, $preg];
231 231
 }
232 232
 
233 233
 
@@ -254,143 +254,143 @@  discard block
 block discarded – undo
254 254
  * @return array
255 255
  */
256 256
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
257
-	include_spip('base/abstract_sql');
258
-
259
-	if (!is_array($tables)) {
260
-		$liste = liste_des_champs();
261
-
262
-		if (
263
-			is_string($tables)
264
-			and $tables != ''
265
-		) {
266
-			$toutes = [];
267
-			foreach (explode(',', $tables) as $t) {
268
-				$t = trim($t);
269
-				if (isset($liste[$t])) {
270
-					$toutes[$t] = $liste[$t];
271
-				}
272
-			}
273
-			$tables = $toutes;
274
-			unset($toutes);
275
-		} else {
276
-			$tables = $liste;
277
-		}
278
-	}
279
-
280
-	if (!strlen($recherche) or !count($tables)) {
281
-		return [];
282
-	}
283
-
284
-	include_spip('inc/autoriser');
285
-
286
-	// options par defaut
287
-	$options = array_merge(
288
-		[
289
-		'preg_flags' => 'UimsS',
290
-		'toutvoir' => false,
291
-		'champs' => false,
292
-		'score' => false,
293
-		'matches' => false,
294
-		'jointures' => false,
295
-		'serveur' => $serveur
296
-		],
297
-		$options
298
-	);
299
-
300
-	$results = [];
301
-
302
-	// Utiliser l'iterateur (DATA:recherche)
303
-	// pour recuperer les couples (id_objet, score)
304
-	// Le resultat est au format {
305
-	//      id1 = { 'score' => x, attrs => { } },
306
-	//      id2 = { 'score' => x, attrs => { } },
307
-	// }
308
-
309
-	include_spip('inc/recherche_to_array');
310
-
311
-	foreach ($tables as $table => $champs) {
312
-		# lock via memoization, si dispo
313
-		if (function_exists('cache_lock')) {
314
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
-		}
316
-
317
-		spip_timer('rech');
318
-
319
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
320
-		$to_array = charger_fonction('recherche_to_array', 'inc');
321
-		$results[$table] = $to_array(
322
-			$recherche,
323
-			array_merge($options, ['table' => $table, 'champs' => $champs])
324
-		);
325
-		##var_dump($results[$table]);
326
-
327
-
328
-		spip_log(
329
-			"recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
-			'recherche'
331
-		);
332
-
333
-		if (isset($lock)) {
334
-			cache_unlock($lock);
335
-		}
336
-	}
337
-
338
-	return $results;
257
+    include_spip('base/abstract_sql');
258
+
259
+    if (!is_array($tables)) {
260
+        $liste = liste_des_champs();
261
+
262
+        if (
263
+            is_string($tables)
264
+            and $tables != ''
265
+        ) {
266
+            $toutes = [];
267
+            foreach (explode(',', $tables) as $t) {
268
+                $t = trim($t);
269
+                if (isset($liste[$t])) {
270
+                    $toutes[$t] = $liste[$t];
271
+                }
272
+            }
273
+            $tables = $toutes;
274
+            unset($toutes);
275
+        } else {
276
+            $tables = $liste;
277
+        }
278
+    }
279
+
280
+    if (!strlen($recherche) or !count($tables)) {
281
+        return [];
282
+    }
283
+
284
+    include_spip('inc/autoriser');
285
+
286
+    // options par defaut
287
+    $options = array_merge(
288
+        [
289
+        'preg_flags' => 'UimsS',
290
+        'toutvoir' => false,
291
+        'champs' => false,
292
+        'score' => false,
293
+        'matches' => false,
294
+        'jointures' => false,
295
+        'serveur' => $serveur
296
+        ],
297
+        $options
298
+    );
299
+
300
+    $results = [];
301
+
302
+    // Utiliser l'iterateur (DATA:recherche)
303
+    // pour recuperer les couples (id_objet, score)
304
+    // Le resultat est au format {
305
+    //      id1 = { 'score' => x, attrs => { } },
306
+    //      id2 = { 'score' => x, attrs => { } },
307
+    // }
308
+
309
+    include_spip('inc/recherche_to_array');
310
+
311
+    foreach ($tables as $table => $champs) {
312
+        # lock via memoization, si dispo
313
+        if (function_exists('cache_lock')) {
314
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
+        }
316
+
317
+        spip_timer('rech');
318
+
319
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
320
+        $to_array = charger_fonction('recherche_to_array', 'inc');
321
+        $results[$table] = $to_array(
322
+            $recherche,
323
+            array_merge($options, ['table' => $table, 'champs' => $champs])
324
+        );
325
+        ##var_dump($results[$table]);
326
+
327
+
328
+        spip_log(
329
+            "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
+            'recherche'
331
+        );
332
+
333
+        if (isset($lock)) {
334
+            cache_unlock($lock);
335
+        }
336
+    }
337
+
338
+    return $results;
339 339
 }
340 340
 
341 341
 
342 342
 // Effectue une recherche sur toutes les tables de la base de donnees
343 343
 // https://code.spip.net/@remplace_en_base
344 344
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
345
-	include_spip('inc/modifier');
346
-
347
-	// options par defaut
348
-	$options = array_merge(
349
-		[
350
-		'preg_flags' => 'UimsS',
351
-		'toutmodifier' => false
352
-		],
353
-		$options
354
-	);
355
-	$options['champs'] = true;
356
-
357
-
358
-	if (!is_array($tables)) {
359
-		$tables = liste_des_champs();
360
-	}
361
-
362
-	$results = recherche_en_base($recherche, $tables, $options);
363
-
364
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
-
366
-	foreach ($results as $table => $r) {
367
-		$_id_table = id_table_objet($table);
368
-		foreach ($r as $id => $x) {
369
-			if (
370
-				$options['toutmodifier']
371
-				or autoriser('modifier', $table, $id)
372
-			) {
373
-				$modifs = [];
374
-				foreach ($x['champs'] as $key => $val) {
375
-					if ($key == $_id_table) {
376
-						continue;
377
-					}
378
-					$repl = preg_replace($preg, $remplace, $val);
379
-					if ($repl <> $val) {
380
-						$modifs[$key] = $repl;
381
-					}
382
-				}
383
-				if ($modifs) {
384
-					objet_modifier_champs(
385
-						$table,
386
-						$id,
387
-						[
388
-							'champs' => array_keys($modifs),
389
-						],
390
-						$modifs
391
-					);
392
-				}
393
-			}
394
-		}
395
-	}
345
+    include_spip('inc/modifier');
346
+
347
+    // options par defaut
348
+    $options = array_merge(
349
+        [
350
+        'preg_flags' => 'UimsS',
351
+        'toutmodifier' => false
352
+        ],
353
+        $options
354
+    );
355
+    $options['champs'] = true;
356
+
357
+
358
+    if (!is_array($tables)) {
359
+        $tables = liste_des_champs();
360
+    }
361
+
362
+    $results = recherche_en_base($recherche, $tables, $options);
363
+
364
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
+
366
+    foreach ($results as $table => $r) {
367
+        $_id_table = id_table_objet($table);
368
+        foreach ($r as $id => $x) {
369
+            if (
370
+                $options['toutmodifier']
371
+                or autoriser('modifier', $table, $id)
372
+            ) {
373
+                $modifs = [];
374
+                foreach ($x['champs'] as $key => $val) {
375
+                    if ($key == $_id_table) {
376
+                        continue;
377
+                    }
378
+                    $repl = preg_replace($preg, $remplace, $val);
379
+                    if ($repl <> $val) {
380
+                        $modifs[$key] = $repl;
381
+                    }
382
+                }
383
+                if ($modifs) {
384
+                    objet_modifier_champs(
385
+                        $table,
386
+                        $id,
387
+                        [
388
+                            'champs' => array_keys($modifs),
389
+                        ],
390
+                        $modifs
391
+                    );
392
+                }
393
+            }
394
+        }
395
+    }
396 396
 }
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 1 patch
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
  *     Tableau des champs et valeurs collectées
40 40
  */
41 41
 function collecter_requests($white_list, $black_list = [], $set = null, $tous = false) {
42
-	$c = $set;
43
-	if (!$c) {
44
-		$c = [];
45
-		foreach ($white_list as $champ) {
46
-			// on ne collecte que les champs reellement envoyes par defaut.
47
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
-			$val = _request($champ);
49
-			if ($tous or $val !== null) {
50
-				$c[$champ] = $val;
51
-			}
52
-		}
53
-		// on ajoute toujours la lang en saisie possible
54
-		// meme si pas prevu au depart pour l'objet concerne
55
-		if ($l = _request('changer_lang')) {
56
-			$c['lang'] = $l;
57
-		}
58
-	}
59
-	foreach ($black_list as $champ) {
60
-		unset($c[$champ]);
61
-	}
62
-
63
-	return $c;
42
+    $c = $set;
43
+    if (!$c) {
44
+        $c = [];
45
+        foreach ($white_list as $champ) {
46
+            // on ne collecte que les champs reellement envoyes par defaut.
47
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
+            $val = _request($champ);
49
+            if ($tous or $val !== null) {
50
+                $c[$champ] = $val;
51
+            }
52
+        }
53
+        // on ajoute toujours la lang en saisie possible
54
+        // meme si pas prevu au depart pour l'objet concerne
55
+        if ($l = _request('changer_lang')) {
56
+            $c['lang'] = $l;
57
+        }
58
+    }
59
+    foreach ($black_list as $champ) {
60
+        unset($c[$champ]);
61
+    }
62
+
63
+    return $c;
64 64
 }
65 65
 
66 66
 /**
@@ -97,229 +97,229 @@  discard block
 block discarded – undo
97 97
  *     - chaîne : Texte d'un message d'erreur
98 98
  */
99 99
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
100
-	if (!$id_objet = intval($id_objet)) {
101
-		spip_log('Erreur $id_objet non defini', 'warn');
102
-
103
-		return _T('erreur_technique_enregistrement_impossible');
104
-	}
105
-
106
-	include_spip('inc/filtres');
107
-
108
-	$table_objet = table_objet($objet, $serveur);
109
-	$spip_table_objet = table_objet_sql($objet, $serveur);
110
-	$id_table_objet = id_table_objet($objet, $serveur);
111
-	$trouver_table = charger_fonction('trouver_table', 'base');
112
-	$desc = $trouver_table($spip_table_objet, $serveur);
113
-
114
-	// Appels incomplets (sans $c)
115
-	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
-
118
-		return _T('erreur_technique_enregistrement_impossible');
119
-	}
120
-
121
-	// Securite : certaines variables ne sont jamais acceptees ici
122
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
123
-	// il faut passer par instituer_XX()
124
-	// TODO: faut-il passer ces variables interdites
125
-	// dans un fichier de description separe ?
126
-	unset($c['statut']);
127
-	unset($c['id_parent']);
128
-	unset($c['id_rubrique']);
129
-	unset($c['id_secteur']);
130
-
131
-	// Gerer les champs non vides
132
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
-		foreach ($options['nonvide'] as $champ => $sinon) {
134
-			if (isset($c[$champ]) and $c[$champ] === '') {
135
-				$c[$champ] = $sinon;
136
-			}
137
-		}
138
-	}
139
-
140
-
141
-	// N'accepter que les champs qui existent
142
-	// TODO: ici aussi on peut valider les contenus
143
-	// en fonction du type
144
-	$champs = [];
145
-	foreach ($desc['field'] as $champ => $ignore) {
146
-		if (isset($c[$champ])) {
147
-			$champs[$champ] = $c[$champ];
148
-		}
149
-	}
150
-
151
-	// Nettoyer les valeurs
152
-	$champs = array_map('corriger_caracteres', $champs);
153
-
154
-	// Envoyer aux plugins
155
-	$champs = pipeline(
156
-		'pre_edition',
157
-		[
158
-			'args' => [
159
-				'table' => $spip_table_objet, // compatibilite
160
-				'table_objet' => $table_objet,
161
-				'spip_table_objet' => $spip_table_objet,
162
-				'desc' => $desc,
163
-				'type' => $objet,
164
-				'id_objet' => $id_objet,
165
-				'data' => isset($options['data']) ? $options['data'] : null,
166
-				'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
167
-				'serveur' => $serveur,
168
-				'action' => isset($options['action']) ? $options['action'] : 'modifier'
169
-			],
170
-			'data' => $champs
171
-		]
172
-	);
173
-
174
-	if (!$champs) {
175
-		return false;
176
-	}
177
-
178
-
179
-	// marquer le fait que l'objet est travaille par toto a telle date
180
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
181
-		include_spip('inc/drapeau_edition');
182
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
-	}
184
-
185
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
-	include_spip('inc/editer');
187
-	if (!isset($options['data']) or is_null($options['data'])) {
188
-		$options['data'] = &$_POST;
189
-	}
190
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
-	// et gere l'interface
193
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
-	if ($conflits) {
195
-		return _T('titre_conflit_edition');
196
-	}
197
-
198
-	if ($champs) {
199
-		// cas particulier de la langue : passer par instituer_langue_objet
200
-		if (isset($champs['lang'])) {
201
-			if ($changer_lang = $champs['lang']) {
202
-				$id_rubrique = 0;
203
-				if (isset($desc['field']['id_rubrique'])) {
204
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
206
-				}
207
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
-			}
210
-			// on laisse 'lang' dans $champs,
211
-			// ca permet de passer dans le pipeline post_edition et de journaliser
212
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
-			// deja pris en compte
214
-		}
215
-
216
-		// la modif peut avoir lieu
217
-
218
-		// faut-il ajouter date_modif ?
219
-		if (
220
-			isset($options['date_modif']) and $options['date_modif']
221
-			and !isset($champs[$options['date_modif']])
222
-		) {
223
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
224
-		}
225
-
226
-		// allez on commit la modif
227
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
228
-
229
-		// on verifie si elle est bien passee
230
-		$moof = sql_fetsel(
231
-			array_keys($champs),
232
-			$spip_table_objet,
233
-			"$id_table_objet=" . intval($id_objet),
234
-			[],
235
-			[],
236
-			'',
237
-			[],
238
-			$serveur
239
-		);
240
-		// si difference entre les champs, reperer les champs mal enregistres
241
-		if ($moof != $champs) {
242
-			$liste = [];
243
-			foreach ($moof as $k => $v) {
244
-				if (
245
-					$v !== $champs[$k]
246
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
247
-					and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
248
-					// ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
249
-					and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
250
-				) {
251
-					$liste[] = $k;
252
-					$conflits[$k]['post'] = $champs[$k];
253
-					$conflits[$k]['save'] = $v;
254
-
255
-					// cas specifique MySQL+emoji : si l'un est la
256
-					// conversion utf8_noplanes de l'autre alors c'est OK
257
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
258
-						include_spip('inc/charsets');
259
-						if ($v == utf8_noplanes($champs[$k])) {
260
-							array_pop($liste);
261
-						}
262
-					}
263
-				}
264
-			}
265
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
266
-			// c'est un cas exceptionnel
267
-			if (count($liste)) {
268
-				spip_log(
269
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
270
-					'modifier.' . _LOG_CRITIQUE
271
-				);
272
-
273
-				return _T(
274
-					'erreur_technique_enregistrement_champs',
275
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
276
-				);
277
-			}
278
-		}
279
-
280
-		// Invalider les caches
281
-		if (isset($options['invalideur']) and $options['invalideur']) {
282
-			include_spip('inc/invalideur');
283
-			if (is_array($options['invalideur'])) {
284
-				array_map('suivre_invalideur', $options['invalideur']);
285
-			} else {
286
-				suivre_invalideur($options['invalideur']);
287
-			}
288
-		}
289
-
290
-		// Notifications, gestion des revisions...
291
-		// en standard, appelle |nouvelle_revision ci-dessous
292
-		pipeline(
293
-			'post_edition',
294
-			[
295
-				'args' => [
296
-					'table' => $spip_table_objet,
297
-					'table_objet' => $table_objet,
298
-					'spip_table_objet' => $spip_table_objet,
299
-					'desc' => $desc,
300
-					'type' => $objet,
301
-					'id_objet' => $id_objet,
302
-					'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] kesako ?
303
-					'serveur' => $serveur,
304
-					'action' => isset($options['action']) ? $options['action'] : 'modifier'
305
-				],
306
-				'data' => $champs
307
-			]
308
-		);
309
-	}
310
-
311
-	// journaliser l'affaire
312
-	// message a affiner :-)
313
-	include_spip('inc/filtres_mini');
314
-	$qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
315
-	journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join(
316
-		'+',
317
-		array_diff(array_keys($champs), ['date_modif'])
318
-	) . ')'), [
319
-		'faire' => 'modifier',
320
-		'quoi' => $objet,
321
-		'id' => $id_objet
322
-	]);
323
-
324
-	return '';
100
+    if (!$id_objet = intval($id_objet)) {
101
+        spip_log('Erreur $id_objet non defini', 'warn');
102
+
103
+        return _T('erreur_technique_enregistrement_impossible');
104
+    }
105
+
106
+    include_spip('inc/filtres');
107
+
108
+    $table_objet = table_objet($objet, $serveur);
109
+    $spip_table_objet = table_objet_sql($objet, $serveur);
110
+    $id_table_objet = id_table_objet($objet, $serveur);
111
+    $trouver_table = charger_fonction('trouver_table', 'base');
112
+    $desc = $trouver_table($spip_table_objet, $serveur);
113
+
114
+    // Appels incomplets (sans $c)
115
+    if (!is_array($c)) {
116
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
+
118
+        return _T('erreur_technique_enregistrement_impossible');
119
+    }
120
+
121
+    // Securite : certaines variables ne sont jamais acceptees ici
122
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
123
+    // il faut passer par instituer_XX()
124
+    // TODO: faut-il passer ces variables interdites
125
+    // dans un fichier de description separe ?
126
+    unset($c['statut']);
127
+    unset($c['id_parent']);
128
+    unset($c['id_rubrique']);
129
+    unset($c['id_secteur']);
130
+
131
+    // Gerer les champs non vides
132
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
+        foreach ($options['nonvide'] as $champ => $sinon) {
134
+            if (isset($c[$champ]) and $c[$champ] === '') {
135
+                $c[$champ] = $sinon;
136
+            }
137
+        }
138
+    }
139
+
140
+
141
+    // N'accepter que les champs qui existent
142
+    // TODO: ici aussi on peut valider les contenus
143
+    // en fonction du type
144
+    $champs = [];
145
+    foreach ($desc['field'] as $champ => $ignore) {
146
+        if (isset($c[$champ])) {
147
+            $champs[$champ] = $c[$champ];
148
+        }
149
+    }
150
+
151
+    // Nettoyer les valeurs
152
+    $champs = array_map('corriger_caracteres', $champs);
153
+
154
+    // Envoyer aux plugins
155
+    $champs = pipeline(
156
+        'pre_edition',
157
+        [
158
+            'args' => [
159
+                'table' => $spip_table_objet, // compatibilite
160
+                'table_objet' => $table_objet,
161
+                'spip_table_objet' => $spip_table_objet,
162
+                'desc' => $desc,
163
+                'type' => $objet,
164
+                'id_objet' => $id_objet,
165
+                'data' => isset($options['data']) ? $options['data'] : null,
166
+                'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
167
+                'serveur' => $serveur,
168
+                'action' => isset($options['action']) ? $options['action'] : 'modifier'
169
+            ],
170
+            'data' => $champs
171
+        ]
172
+    );
173
+
174
+    if (!$champs) {
175
+        return false;
176
+    }
177
+
178
+
179
+    // marquer le fait que l'objet est travaille par toto a telle date
180
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
181
+        include_spip('inc/drapeau_edition');
182
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
+    }
184
+
185
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
+    include_spip('inc/editer');
187
+    if (!isset($options['data']) or is_null($options['data'])) {
188
+        $options['data'] = &$_POST;
189
+    }
190
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
+    // et gere l'interface
193
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
+    if ($conflits) {
195
+        return _T('titre_conflit_edition');
196
+    }
197
+
198
+    if ($champs) {
199
+        // cas particulier de la langue : passer par instituer_langue_objet
200
+        if (isset($champs['lang'])) {
201
+            if ($changer_lang = $champs['lang']) {
202
+                $id_rubrique = 0;
203
+                if (isset($desc['field']['id_rubrique'])) {
204
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
206
+                }
207
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
+            }
210
+            // on laisse 'lang' dans $champs,
211
+            // ca permet de passer dans le pipeline post_edition et de journaliser
212
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
+            // deja pris en compte
214
+        }
215
+
216
+        // la modif peut avoir lieu
217
+
218
+        // faut-il ajouter date_modif ?
219
+        if (
220
+            isset($options['date_modif']) and $options['date_modif']
221
+            and !isset($champs[$options['date_modif']])
222
+        ) {
223
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
224
+        }
225
+
226
+        // allez on commit la modif
227
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
228
+
229
+        // on verifie si elle est bien passee
230
+        $moof = sql_fetsel(
231
+            array_keys($champs),
232
+            $spip_table_objet,
233
+            "$id_table_objet=" . intval($id_objet),
234
+            [],
235
+            [],
236
+            '',
237
+            [],
238
+            $serveur
239
+        );
240
+        // si difference entre les champs, reperer les champs mal enregistres
241
+        if ($moof != $champs) {
242
+            $liste = [];
243
+            foreach ($moof as $k => $v) {
244
+                if (
245
+                    $v !== $champs[$k]
246
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
247
+                    and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
248
+                    // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
249
+                    and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
250
+                ) {
251
+                    $liste[] = $k;
252
+                    $conflits[$k]['post'] = $champs[$k];
253
+                    $conflits[$k]['save'] = $v;
254
+
255
+                    // cas specifique MySQL+emoji : si l'un est la
256
+                    // conversion utf8_noplanes de l'autre alors c'est OK
257
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
258
+                        include_spip('inc/charsets');
259
+                        if ($v == utf8_noplanes($champs[$k])) {
260
+                            array_pop($liste);
261
+                        }
262
+                    }
263
+                }
264
+            }
265
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
266
+            // c'est un cas exceptionnel
267
+            if (count($liste)) {
268
+                spip_log(
269
+                    "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
270
+                    'modifier.' . _LOG_CRITIQUE
271
+                );
272
+
273
+                return _T(
274
+                    'erreur_technique_enregistrement_champs',
275
+                    ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
276
+                );
277
+            }
278
+        }
279
+
280
+        // Invalider les caches
281
+        if (isset($options['invalideur']) and $options['invalideur']) {
282
+            include_spip('inc/invalideur');
283
+            if (is_array($options['invalideur'])) {
284
+                array_map('suivre_invalideur', $options['invalideur']);
285
+            } else {
286
+                suivre_invalideur($options['invalideur']);
287
+            }
288
+        }
289
+
290
+        // Notifications, gestion des revisions...
291
+        // en standard, appelle |nouvelle_revision ci-dessous
292
+        pipeline(
293
+            'post_edition',
294
+            [
295
+                'args' => [
296
+                    'table' => $spip_table_objet,
297
+                    'table_objet' => $table_objet,
298
+                    'spip_table_objet' => $spip_table_objet,
299
+                    'desc' => $desc,
300
+                    'type' => $objet,
301
+                    'id_objet' => $id_objet,
302
+                    'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] kesako ?
303
+                    'serveur' => $serveur,
304
+                    'action' => isset($options['action']) ? $options['action'] : 'modifier'
305
+                ],
306
+                'data' => $champs
307
+            ]
308
+        );
309
+    }
310
+
311
+    // journaliser l'affaire
312
+    // message a affiner :-)
313
+    include_spip('inc/filtres_mini');
314
+    $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
315
+    journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join(
316
+        '+',
317
+        array_diff(array_keys($champs), ['date_modif'])
318
+    ) . ')'), [
319
+        'faire' => 'modifier',
320
+        'quoi' => $objet,
321
+        'id' => $id_objet
322
+    ]);
323
+
324
+    return '';
325 325
 }
Please login to merge, or discard this patch.
ecrire/inc/svg.php 1 patch
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('IMG_SVG')) {
24
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG', 128);
26
-	define('IMAGETYPE_SVG', 19);
24
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
+    define('IMG_SVG', 128);
26
+    define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
29 29
 /**
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41 41
 function svg_charger($fichier, $maxlen = null) {
42
-	if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
-		$image = explode(';', $fichier, 2);
44
-		$image = end($image);
45
-		if (strpos($image, 'base64,') === 0) {
46
-			$image = base64_decode(substr($image, 7));
47
-		}
48
-		if (strpos($image, '<svg') !== false) {
49
-			return $image;
50
-		}
51
-		// encodage inconnu ou autre format d'image ?
52
-		return false;
53
-	}
54
-	// c'est peut etre deja une image svg ?
55
-	if (strpos($fichier, '<svg') !== false) {
56
-		return $fichier;
57
-	}
58
-	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
60
-		if (!file_exists($fichier)) {
61
-			return false;
62
-		}
63
-	}
64
-	if (is_null($maxlen)) {
65
-		$image = file_get_contents($fichier);
66
-	}
67
-	else {
68
-		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69
-	}
70
-	// est-ce bien une image svg ?
71
-	if (strpos($image, '<svg') !== false) {
72
-		return $image;
73
-	}
74
-	return false;
42
+    if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
+        $image = explode(';', $fichier, 2);
44
+        $image = end($image);
45
+        if (strpos($image, 'base64,') === 0) {
46
+            $image = base64_decode(substr($image, 7));
47
+        }
48
+        if (strpos($image, '<svg') !== false) {
49
+            return $image;
50
+        }
51
+        // encodage inconnu ou autre format d'image ?
52
+        return false;
53
+    }
54
+    // c'est peut etre deja une image svg ?
55
+    if (strpos($fichier, '<svg') !== false) {
56
+        return $fichier;
57
+    }
58
+    if (!file_exists($fichier)) {
59
+        $fichier  = supprimer_timestamp($fichier);
60
+        if (!file_exists($fichier)) {
61
+            return false;
62
+        }
63
+    }
64
+    if (is_null($maxlen)) {
65
+        $image = file_get_contents($fichier);
66
+    }
67
+    else {
68
+        $image = file_get_contents($fichier, false, null, 0, $maxlen);
69
+    }
70
+    // est-ce bien une image svg ?
71
+    if (strpos($image, '<svg') !== false) {
72
+        return $image;
73
+    }
74
+    return false;
75 75
 }
76 76
 
77 77
 /**
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
  * @return array|bool
81 81
  */
82 82
 function svg_lire_balise_svg($fichier) {
83
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
-		return false;
85
-	}
86
-
87
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
-		$pe = stripos($debut_fichier, '>', $ps);
89
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
-
91
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
-			if (!function_exists('extraire_attribut')) {
93
-				include_spip('inc/filtres');
94
-			}
95
-			$attributs = [];
96
-			foreach ($matches[1] as $att) {
97
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
98
-			}
99
-
100
-			return [$balise_svg, $attributs];
101
-		}
102
-	}
103
-
104
-	return false;
83
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
+        return false;
85
+    }
86
+
87
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
+        $pe = stripos($debut_fichier, '>', $ps);
89
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
+
91
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
+            if (!function_exists('extraire_attribut')) {
93
+                include_spip('inc/filtres');
94
+            }
95
+            $attributs = [];
96
+            foreach ($matches[1] as $att) {
97
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
98
+            }
99
+
100
+            return [$balise_svg, $attributs];
101
+        }
102
+    }
103
+
104
+    return false;
105 105
 }
106 106
 
107 107
 /**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function svg_lire_attributs($img) {
113 113
 
114
-	if ($svg_infos = svg_lire_balise_svg($img)) {
115
-		list($balise_svg, $attributs) = $svg_infos;
116
-		return $attributs;
117
-	}
114
+    if ($svg_infos = svg_lire_balise_svg($img)) {
115
+        list($balise_svg, $attributs) = $svg_infos;
116
+        return $attributs;
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -126,38 +126,38 @@  discard block
 block discarded – undo
126 126
  * @return bool|float|int
127 127
  */
128 128
 function svg_dimension_to_pixels($dimension, $precision = 2) {
129
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
-		switch (strtolower($m[2])) {
131
-			case '%':
132
-				// on ne sait pas faire :(
133
-				return false;
134
-				break;
135
-			case 'em':
136
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
137
-				break;
138
-			case 'ex':
139
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
140
-				break;
141
-			case 'pc':
142
-				return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
-				break;
144
-			case 'cm':
145
-				return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
-				break;
147
-			case 'mm':
148
-				return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
-				break;
150
-			case 'in':
151
-				return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
-				break;
153
-			case 'px':
154
-			case 'pt':
155
-			default:
156
-				return $m[1];
157
-				break;
158
-		}
159
-	}
160
-	return false;
129
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
+        switch (strtolower($m[2])) {
131
+            case '%':
132
+                // on ne sait pas faire :(
133
+                return false;
134
+                break;
135
+            case 'em':
136
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
137
+                break;
138
+            case 'ex':
139
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
140
+                break;
141
+            case 'pc':
142
+                return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
+                break;
144
+            case 'cm':
145
+                return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
+                break;
147
+            case 'mm':
148
+                return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
+                break;
150
+            case 'in':
151
+                return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
+                break;
153
+            case 'px':
154
+            case 'pt':
155
+            default:
156
+                return $m[1];
157
+                break;
158
+        }
159
+    }
160
+    return false;
161 161
 }
162 162
 
163 163
 /**
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171
-	$new_balise_svg = '<svg';
172
-	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
-	}
175
-	$new_balise_svg .= '>';
176
-
177
-	$p = strpos($svg, $old_balise_svg);
178
-	$svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
-	return $svg;
171
+    $new_balise_svg = '<svg';
172
+    foreach ($attributs as $k => $v) {
173
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
+    }
175
+    $new_balise_svg .= '>';
176
+
177
+    $p = strpos($svg, $old_balise_svg);
178
+    $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
+    return $svg;
180 180
 }
181 181
 
182 182
 /**
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191
-	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
195
-		$p = stripos($svg, '<svg');
196
-		$p = strpos($svg, '>', $p);
197
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
198
-	}
199
-	return $svg;
191
+    if ($start === false or $start === 'end') {
192
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
+    }
194
+    else {
195
+        $p = stripos($svg, '<svg');
196
+        $p = strpos($svg, '>', $p);
197
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
198
+    }
199
+    return $svg;
200 200
 }
201 201
 
202 202
 /**
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
  * @return string
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
-	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
217
-	$svg = svg_insert_shapes($svg, '</g>', false);
218
-	return $svg;
212
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
+    $g = "<g clip-path=\"url(#$id)\">";
216
+    $svg = svg_insert_shapes($svg, $clippath . $g);
217
+    $svg = svg_insert_shapes($svg, '</g>', false);
218
+    return $svg;
219 219
 }
220 220
 
221 221
 /**
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
  * @return bool|string
227 227
  */
228 228
 function svg_redimensionner($img, $new_width, $new_height) {
229
-	if (
230
-		$svg = svg_charger($img)
231
-		and $svg_infos = svg_lire_balise_svg($svg)
232
-	) {
233
-		list($balise_svg, $attributs) = $svg_infos;
234
-		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
-		}
237
-		$attributs['width'] = strval($new_width);
238
-		$attributs['height'] = strval($new_height);
239
-
240
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
-		return $svg;
242
-	}
243
-
244
-	return $img;
229
+    if (
230
+        $svg = svg_charger($img)
231
+        and $svg_infos = svg_lire_balise_svg($svg)
232
+    ) {
233
+        list($balise_svg, $attributs) = $svg_infos;
234
+        if (!isset($attributs['viewBox'])) {
235
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
+        }
237
+        $attributs['width'] = strval($new_width);
238
+        $attributs['height'] = strval($new_height);
239
+
240
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
+        return $svg;
242
+    }
243
+
244
+    return $img;
245 245
 }
246 246
 
247 247
 /**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
  * @return string
251 251
  */
252 252
 function svg_couleur_to_hexa($couleur) {
253
-	if (strpos($couleur, 'rgb(') === 0) {
254
-		$c = explode(',', substr($couleur, 4));
255
-		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
258
-		$couleur = couleur_html_to_hex($couleur);
259
-	}
260
-	$couleur = '#' . ltrim($couleur, '#');
261
-	return $couleur;
253
+    if (strpos($couleur, 'rgb(') === 0) {
254
+        $c = explode(',', substr($couleur, 4));
255
+        $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
+    }
257
+    else {
258
+        $couleur = couleur_html_to_hex($couleur);
259
+    }
260
+    $couleur = '#' . ltrim($couleur, '#');
261
+    return $couleur;
262 262
 }
263 263
 
264 264
 /**
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
  * @return array
268 268
  */
269 269
 function svg_couleur_to_rgb($couleur) {
270
-	if (strpos($couleur, 'rgb(') === 0) {
271
-		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
-	}
274
-	return _couleur_hex_to_dec($couleur);
270
+    if (strpos($couleur, 'rgb(') === 0) {
271
+        $c = explode(',', substr($couleur, 4));
272
+        return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
+    }
274
+    return _couleur_hex_to_dec($couleur);
275 275
 }
276 276
 
277 277
 
@@ -281,70 +281,70 @@  discard block
 block discarded – undo
281 281
  * @return array
282 282
  */
283 283
 function svg_getimagesize_from_attr($attributs) {
284
-	$width = 350; // default width
285
-	$height = 150; // default height
286
-
287
-	$viewBox = "0 0 $width $height";
288
-	if (isset($attributs['viewBox'])) {
289
-		$viewBox = $attributs['viewBox'];
290
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
-	}
292
-	// et on la convertit en px
293
-	$viewBox = explode(' ', $viewBox);
294
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
-	if (!$viewBox[2]) {
296
-		$viewBox[2] = $width;
297
-	}
298
-	if (!$viewBox[3]) {
299
-		$viewBox[3] = $height;
300
-	}
301
-
302
-	$coeff = 1;
303
-	if (
304
-		isset($attributs['width'])
305
-		and $w = svg_dimension_to_pixels($attributs['width'])
306
-	) {
307
-		$width = $w;
308
-	}
309
-	else {
310
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
-		$width = $viewBox[2];
312
-		if ($width < 1) {
313
-			$coeff = max($coeff, 1000);
314
-		}
315
-		elseif ($width < 10) {
316
-			$coeff = max($coeff, 100);
317
-		}
318
-		elseif ($width < 100) {
319
-			$coeff = max($coeff, 10);
320
-		}
321
-	}
322
-	if (
323
-		isset($attributs['height'])
324
-		and $h = svg_dimension_to_pixels($attributs['height'])
325
-	) {
326
-		$height = $h;
327
-	}
328
-	else {
329
-		$height = $viewBox[3];
330
-		if ($height < 1) {
331
-			$coeff = max($coeff, 1000);
332
-		}
333
-		elseif ($height < 10) {
334
-			$coeff = max($coeff, 100);
335
-		}
336
-		elseif ($height < 100) {
337
-			$coeff = max($coeff, 10);
338
-		}
339
-	}
340
-
341
-	// arrondir le width et height en pixel in fine
342
-	$width = round($coeff * $width);
343
-	$height = round($coeff * $height);
344
-
345
-	$viewBox = implode(' ', $viewBox);
346
-
347
-	return [$width, $height, $viewBox];
284
+    $width = 350; // default width
285
+    $height = 150; // default height
286
+
287
+    $viewBox = "0 0 $width $height";
288
+    if (isset($attributs['viewBox'])) {
289
+        $viewBox = $attributs['viewBox'];
290
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
+    }
292
+    // et on la convertit en px
293
+    $viewBox = explode(' ', $viewBox);
294
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
+    if (!$viewBox[2]) {
296
+        $viewBox[2] = $width;
297
+    }
298
+    if (!$viewBox[3]) {
299
+        $viewBox[3] = $height;
300
+    }
301
+
302
+    $coeff = 1;
303
+    if (
304
+        isset($attributs['width'])
305
+        and $w = svg_dimension_to_pixels($attributs['width'])
306
+    ) {
307
+        $width = $w;
308
+    }
309
+    else {
310
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
+        $width = $viewBox[2];
312
+        if ($width < 1) {
313
+            $coeff = max($coeff, 1000);
314
+        }
315
+        elseif ($width < 10) {
316
+            $coeff = max($coeff, 100);
317
+        }
318
+        elseif ($width < 100) {
319
+            $coeff = max($coeff, 10);
320
+        }
321
+    }
322
+    if (
323
+        isset($attributs['height'])
324
+        and $h = svg_dimension_to_pixels($attributs['height'])
325
+    ) {
326
+        $height = $h;
327
+    }
328
+    else {
329
+        $height = $viewBox[3];
330
+        if ($height < 1) {
331
+            $coeff = max($coeff, 1000);
332
+        }
333
+        elseif ($height < 10) {
334
+            $coeff = max($coeff, 100);
335
+        }
336
+        elseif ($height < 100) {
337
+            $coeff = max($coeff, 10);
338
+        }
339
+    }
340
+
341
+    // arrondir le width et height en pixel in fine
342
+    $width = round($coeff * $width);
343
+    $height = round($coeff * $height);
344
+
345
+    $viewBox = implode(' ', $viewBox);
346
+
347
+    return [$width, $height, $viewBox];
348 348
 }
349 349
 
350 350
 /**
@@ -360,25 +360,25 @@  discard block
 block discarded – undo
360 360
  * @return string
361 361
  */
362 362
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
363
-	if (
364
-		$svg = svg_charger($img)
365
-		and $svg_infos = svg_lire_balise_svg($svg)
366
-	) {
367
-		list($balise_svg, $attributs) = $svg_infos;
363
+    if (
364
+        $svg = svg_charger($img)
365
+        and $svg_infos = svg_lire_balise_svg($svg)
366
+    ) {
367
+        list($balise_svg, $attributs) = $svg_infos;
368 368
 
369
-		list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
369
+        list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
370 370
 
371
-		if ($force_width_and_height) {
372
-			$attributs['width'] = $width;
373
-			$attributs['height'] = $height;
374
-		}
371
+        if ($force_width_and_height) {
372
+            $attributs['width'] = $width;
373
+            $attributs['height'] = $height;
374
+        }
375 375
 
376
-		$attributs['viewBox'] = $viewBox;
376
+        $attributs['viewBox'] = $viewBox;
377 377
 
378
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
-		return $svg;
380
-	}
381
-	return $img;
378
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
+        return $svg;
380
+    }
381
+    return $img;
382 382
 }
383 383
 
384 384
 /**
@@ -387,12 +387,12 @@  discard block
 block discarded – undo
387 387
  * @return array|mixed
388 388
  */
389 389
 function svg_extract_couleurs($img) {
390
-	if ($svg = svg_charger($img)) {
391
-		if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
392
-			return $matches[0];
393
-		}
394
-	}
395
-	return [];
390
+    if ($svg = svg_charger($img)) {
391
+        if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) {
392
+            return $matches[0];
393
+        }
394
+    }
395
+    return [];
396 396
 }
397 397
 
398 398
 /**
@@ -403,58 +403,58 @@  discard block
 block discarded – undo
403 403
  * @return bool|string
404 404
  */
405 405
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
406
-	if (
407
-		$svg = svg_force_viewBox_px($img)
408
-		and $svg_infos = svg_lire_balise_svg($svg)
409
-	) {
410
-		list($balise_svg, $attributs) = $svg_infos;
411
-		$viewBox = explode(' ', $attributs['viewBox']);
412
-
413
-		$viewport_w = $new_width;
414
-		$viewport_h = $new_height;
415
-		$viewport_ox = $offset_width;
416
-		$viewport_oy = $offset_height;
417
-
418
-		// si on a un width/height qui rescale, il faut rescaler
419
-		if (
420
-			isset($attributs['width'])
421
-			and $w = svg_dimension_to_pixels($attributs['width'])
422
-			and isset($attributs['height'])
423
-			and $h = svg_dimension_to_pixels($attributs['height'])
424
-		) {
425
-			$xscale = $viewBox[2] / $w;
426
-			$viewport_w = round($viewport_w * $xscale, 2);
427
-			$viewport_ox = round($viewport_ox * $xscale, 2);
428
-			$yscale = $viewBox[3] / $h;
429
-			$viewport_h = round($viewport_h * $yscale, 2);
430
-			$viewport_oy = round($viewport_oy * $yscale, 2);
431
-		}
432
-
433
-		if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
-		}
436
-
437
-		// maintenant on redefinit la viewBox
438
-		$viewBox[0] += $viewport_ox;
439
-		$viewBox[1] += $viewport_oy;
440
-		$viewBox[2] = $viewport_w;
441
-		$viewBox[3] = $viewport_h;
442
-
443
-		$attributs['viewBox'] = implode(' ', $viewBox);
444
-		$attributs['width'] = strval($new_width);
445
-		$attributs['height'] = strval($new_height);
446
-
447
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
-
449
-		// ajouter un background
450
-		if ($background_color and $background_color !== 'transparent') {
451
-			$svg = svg_ajouter_background($svg, $background_color);
452
-		}
453
-
454
-		return $svg;
455
-	}
456
-
457
-	return $img;
406
+    if (
407
+        $svg = svg_force_viewBox_px($img)
408
+        and $svg_infos = svg_lire_balise_svg($svg)
409
+    ) {
410
+        list($balise_svg, $attributs) = $svg_infos;
411
+        $viewBox = explode(' ', $attributs['viewBox']);
412
+
413
+        $viewport_w = $new_width;
414
+        $viewport_h = $new_height;
415
+        $viewport_ox = $offset_width;
416
+        $viewport_oy = $offset_height;
417
+
418
+        // si on a un width/height qui rescale, il faut rescaler
419
+        if (
420
+            isset($attributs['width'])
421
+            and $w = svg_dimension_to_pixels($attributs['width'])
422
+            and isset($attributs['height'])
423
+            and $h = svg_dimension_to_pixels($attributs['height'])
424
+        ) {
425
+            $xscale = $viewBox[2] / $w;
426
+            $viewport_w = round($viewport_w * $xscale, 2);
427
+            $viewport_ox = round($viewport_ox * $xscale, 2);
428
+            $yscale = $viewBox[3] / $h;
429
+            $viewport_h = round($viewport_h * $yscale, 2);
430
+            $viewport_oy = round($viewport_oy * $yscale, 2);
431
+        }
432
+
433
+        if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
+        }
436
+
437
+        // maintenant on redefinit la viewBox
438
+        $viewBox[0] += $viewport_ox;
439
+        $viewBox[1] += $viewport_oy;
440
+        $viewBox[2] = $viewport_w;
441
+        $viewBox[3] = $viewport_h;
442
+
443
+        $attributs['viewBox'] = implode(' ', $viewBox);
444
+        $attributs['width'] = strval($new_width);
445
+        $attributs['height'] = strval($new_height);
446
+
447
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
+
449
+        // ajouter un background
450
+        if ($background_color and $background_color !== 'transparent') {
451
+            $svg = svg_ajouter_background($svg, $background_color);
452
+        }
453
+
454
+        return $svg;
455
+    }
456
+
457
+    return $img;
458 458
 }
459 459
 
460 460
 /**
@@ -464,26 +464,26 @@  discard block
 block discarded – undo
464 464
  * @return bool|string
465 465
  */
466 466
 function svg_ajouter_background($img, $background_color) {
467
-	if (
468
-		$svg = svg_charger($img)
469
-		and $svg_infos = svg_lire_balise_svg($svg)
470
-	) {
471
-		if ($background_color and $background_color !== 'transparent') {
472
-			list($balise_svg, $attributs) = $svg_infos;
473
-
474
-			$background_color = svg_couleur_to_hexa($background_color);
475
-			if (isset($attributs['viewBox'])) {
476
-				$viewBox = explode(' ', $attributs['viewBox']);
477
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
-			}
479
-			else {
480
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
-			}
482
-			$svg = svg_insert_shapes($svg, $rect);
483
-		}
484
-		return $svg;
485
-	}
486
-	return $img;
467
+    if (
468
+        $svg = svg_charger($img)
469
+        and $svg_infos = svg_lire_balise_svg($svg)
470
+    ) {
471
+        if ($background_color and $background_color !== 'transparent') {
472
+            list($balise_svg, $attributs) = $svg_infos;
473
+
474
+            $background_color = svg_couleur_to_hexa($background_color);
475
+            if (isset($attributs['viewBox'])) {
476
+                $viewBox = explode(' ', $attributs['viewBox']);
477
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
+            }
479
+            else {
480
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
+            }
482
+            $svg = svg_insert_shapes($svg, $rect);
483
+        }
484
+        return $svg;
485
+    }
486
+    return $img;
487 487
 }
488 488
 
489 489
 
@@ -494,26 +494,26 @@  discard block
 block discarded – undo
494 494
  * @return bool|string
495 495
  */
496 496
 function svg_ajouter_voile($img, $background_color, $opacity) {
497
-	if (
498
-		$svg = svg_charger($img)
499
-		and $svg_infos = svg_lire_balise_svg($svg)
500
-	) {
501
-		if ($background_color and $background_color !== 'transparent') {
502
-			list($balise_svg, $attributs) = $svg_infos;
503
-
504
-			$background_color = svg_couleur_to_hexa($background_color);
505
-			if (isset($attributs['viewBox'])) {
506
-				$viewBox = explode(' ', $attributs['viewBox']);
507
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
-			}
509
-			else {
510
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
-			}
512
-			$svg = svg_insert_shapes($svg, $rect, false);
513
-		}
514
-		return $svg;
515
-	}
516
-	return $img;
497
+    if (
498
+        $svg = svg_charger($img)
499
+        and $svg_infos = svg_lire_balise_svg($svg)
500
+    ) {
501
+        if ($background_color and $background_color !== 'transparent') {
502
+            list($balise_svg, $attributs) = $svg_infos;
503
+
504
+            $background_color = svg_couleur_to_hexa($background_color);
505
+            if (isset($attributs['viewBox'])) {
506
+                $viewBox = explode(' ', $attributs['viewBox']);
507
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
+            }
509
+            else {
510
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
+            }
512
+            $svg = svg_insert_shapes($svg, $rect, false);
513
+        }
514
+        return $svg;
515
+    }
516
+    return $img;
517 517
 }
518 518
 
519 519
 
@@ -524,27 +524,27 @@  discard block
 block discarded – undo
524 524
  * @return bool|string
525 525
  */
526 526
 function svg_transformer($img, $attributs) {
527
-	if (
528
-		$svg = svg_charger($img)
529
-		and $svg_infos = svg_lire_balise_svg($svg)
530
-	) {
531
-		if ($attributs) {
532
-			list($balise_svg, ) = $svg_infos;
533
-			$g = '<g';
534
-			foreach ($attributs as $k => $v) {
535
-				if (strlen($v)) {
536
-					$g .= " $k=\"" . attribut_html($v) . '"';
537
-				}
538
-			}
539
-			if (strlen($g) > 2) {
540
-				$g .= '>';
541
-				$svg = svg_insert_shapes($svg, $g);
542
-				$svg = svg_insert_shapes($svg, '</g>', false);
543
-			}
544
-		}
545
-		return $svg;
546
-	}
547
-	return $img;
527
+    if (
528
+        $svg = svg_charger($img)
529
+        and $svg_infos = svg_lire_balise_svg($svg)
530
+    ) {
531
+        if ($attributs) {
532
+            list($balise_svg, ) = $svg_infos;
533
+            $g = '<g';
534
+            foreach ($attributs as $k => $v) {
535
+                if (strlen($v)) {
536
+                    $g .= " $k=\"" . attribut_html($v) . '"';
537
+                }
538
+            }
539
+            if (strlen($g) > 2) {
540
+                $g .= '>';
541
+                $svg = svg_insert_shapes($svg, $g);
542
+                $svg = svg_insert_shapes($svg, '</g>', false);
543
+            }
544
+        }
545
+        return $svg;
546
+    }
547
+    return $img;
548 548
 }
549 549
 
550 550
 /**
@@ -555,21 +555,21 @@  discard block
 block discarded – undo
555 555
  * @return bool|string
556 556
  */
557 557
 function svg_apply_filter($img, $filter_def) {
558
-	if (
559
-		$svg = svg_charger($img)
560
-		and $svg_infos = svg_lire_balise_svg($svg)
561
-	) {
562
-		if ($filter_def) {
563
-			list($balise_svg, ) = $svg_infos;
564
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
-			$g = "<g filter=\"url(#$filter_id)\">";
567
-			$svg = svg_insert_shapes($svg, $filter . $g);
568
-			$svg = svg_insert_shapes($svg, '</g>', false);
569
-		}
570
-		return $svg;
571
-	}
572
-	return $img;
558
+    if (
559
+        $svg = svg_charger($img)
560
+        and $svg_infos = svg_lire_balise_svg($svg)
561
+    ) {
562
+        if ($filter_def) {
563
+            list($balise_svg, ) = $svg_infos;
564
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
+            $g = "<g filter=\"url(#$filter_id)\">";
567
+            $svg = svg_insert_shapes($svg, $filter . $g);
568
+            $svg = svg_insert_shapes($svg, '</g>', false);
569
+        }
570
+        return $svg;
571
+    }
572
+    return $img;
573 573
 }
574 574
 
575 575
 /**
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
  * @return string
580 580
  */
581 581
 function svg_filter_blur($img, $blur_width) {
582
-	$blur_width = intval($blur_width);
583
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
582
+    $blur_width = intval($blur_width);
583
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
584 584
 }
585 585
 
586 586
 /**
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
  * @return bool|string
591 591
  */
592 592
 function svg_filter_grayscale($img, $intensity) {
593
-	$value = round(1.0 - $intensity, 2);
594
-	//$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
595
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
-	return svg_apply_filter($img, $filter);
593
+    $value = round(1.0 - $intensity, 2);
594
+    //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
595
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
+    return svg_apply_filter($img, $filter);
597 597
 }
598 598
 
599 599
 /**
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
  * @return bool|string
604 604
  */
605 605
 function svg_filter_sepia($img, $intensity) {
606
-	$filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
607
-	return svg_apply_filter($img, $filter);
606
+    $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
607
+    return svg_apply_filter($img, $filter);
608 608
 }
609 609
 
610 610
 /**
@@ -614,31 +614,31 @@  discard block
 block discarded – undo
614 614
  * @return bool|string
615 615
  */
616 616
 function svg_flip($img, $HorV) {
617
-	if (
618
-		$svg = svg_force_viewBox_px($img)
619
-		and $svg_infos = svg_lire_balise_svg($svg)
620
-	) {
621
-		list($balise_svg, $atts) = $svg_infos;
622
-		$viewBox = explode(' ', $atts['viewBox']);
623
-
624
-		if (!in_array($HorV, ['h', 'H'])) {
625
-			$transform = 'scale(-1,1)';
626
-
627
-			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
-			$mx = -$x;
629
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
630
-		}
631
-		else {
632
-			$transform = 'scale(1,-1)';
633
-
634
-			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
-			$my = -$y;
636
-			$transform = "translate(0, $y) $transform translate(0, $my)";
637
-		}
638
-		$svg = svg_transformer($svg, ['transform' => $transform]);
639
-		return $svg;
640
-	}
641
-	return $img;
617
+    if (
618
+        $svg = svg_force_viewBox_px($img)
619
+        and $svg_infos = svg_lire_balise_svg($svg)
620
+    ) {
621
+        list($balise_svg, $atts) = $svg_infos;
622
+        $viewBox = explode(' ', $atts['viewBox']);
623
+
624
+        if (!in_array($HorV, ['h', 'H'])) {
625
+            $transform = 'scale(-1,1)';
626
+
627
+            $x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
+            $mx = -$x;
629
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
630
+        }
631
+        else {
632
+            $transform = 'scale(1,-1)';
633
+
634
+            $y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
+            $my = -$y;
636
+            $transform = "translate(0, $y) $transform translate(0, $my)";
637
+        }
638
+        $svg = svg_transformer($svg, ['transform' => $transform]);
639
+        return $svg;
640
+    }
641
+    return $img;
642 642
 }
643 643
 
644 644
 /**
@@ -652,20 +652,20 @@  discard block
 block discarded – undo
652 652
  * @return bool|string
653 653
  */
654 654
 function svg_rotate($img, $angle, $center_x, $center_y) {
655
-	if (
656
-		$svg = svg_force_viewBox_px($img)
657
-		and $svg_infos = svg_lire_balise_svg($svg)
658
-	) {
659
-		list($balise_svg, $atts) = $svg_infos;
660
-		$viewBox = explode(' ', $atts['viewBox']);
661
-
662
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
-		$svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
-
666
-		return $svg;
667
-	}
668
-	return $img;
655
+    if (
656
+        $svg = svg_force_viewBox_px($img)
657
+        and $svg_infos = svg_lire_balise_svg($svg)
658
+    ) {
659
+        list($balise_svg, $atts) = $svg_infos;
660
+        $viewBox = explode(' ', $atts['viewBox']);
661
+
662
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
+        $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
+
666
+        return $svg;
667
+    }
668
+    return $img;
669 669
 }
670 670
 
671 671
 /**
@@ -677,41 +677,41 @@  discard block
 block discarded – undo
677 677
  * @return bool|mixed|string
678 678
  */
679 679
 function svg_filtrer_couleurs($img, $callback_filter) {
680
-	if (
681
-		$svg = svg_force_viewBox_px($img)
682
-		and $colors = svg_extract_couleurs($svg)
683
-	) {
684
-		$colors = array_unique($colors);
685
-
686
-		$short = [];
687
-		$long = [];
688
-		while (count($colors)) {
689
-			$c = array_shift($colors);
690
-			if (strlen($c) == 4) {
691
-				$short[] = $c;
692
-			}
693
-			else {
694
-				$long[] = $c;
695
-			}
696
-		}
697
-
698
-		$colors = array_merge($long, $short);
699
-		$new_colors = [];
700
-		$colors = array_flip($colors);
701
-		foreach ($colors as $c => $k) {
702
-			$colors[$c] = "@@@COLOR$$k$@@@";
703
-		}
704
-
705
-
706
-		foreach ($colors as $original => $replace) {
707
-			$new = svg_couleur_to_hexa($original);
708
-			$new_colors[$replace] = $callback_filter($new);
709
-		}
710
-
711
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
-		$svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
-
714
-		return $svg;
715
-	}
716
-	return $img;
680
+    if (
681
+        $svg = svg_force_viewBox_px($img)
682
+        and $colors = svg_extract_couleurs($svg)
683
+    ) {
684
+        $colors = array_unique($colors);
685
+
686
+        $short = [];
687
+        $long = [];
688
+        while (count($colors)) {
689
+            $c = array_shift($colors);
690
+            if (strlen($c) == 4) {
691
+                $short[] = $c;
692
+            }
693
+            else {
694
+                $long[] = $c;
695
+            }
696
+        }
697
+
698
+        $colors = array_merge($long, $short);
699
+        $new_colors = [];
700
+        $colors = array_flip($colors);
701
+        foreach ($colors as $c => $k) {
702
+            $colors[$c] = "@@@COLOR$$k$@@@";
703
+        }
704
+
705
+
706
+        foreach ($colors as $original => $replace) {
707
+            $new = svg_couleur_to_hexa($original);
708
+            $new_colors[$replace] = $callback_filter($new);
709
+        }
710
+
711
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
+        $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
+
714
+        return $svg;
715
+    }
716
+    return $img;
717 717
 }
Please login to merge, or discard this patch.
ecrire/inc/lister_objets.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
  *     Code HTML de la liste
41 41
  */
42 42
 function inc_lister_objets_dist($vue, $contexte = [], $force = false) {
43
-	$res = ''; // debug
44
-	if (!is_array($contexte)) {
45
-		return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
-	}
43
+    $res = ''; // debug
44
+    if (!is_array($contexte)) {
45
+        return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
+    }
47 47
 
48
-	$fond = "prive/objets/liste/$vue";
49
-	if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
-		// traiter les cas particuliers
51
-		include_spip('base/connect_sql');
52
-		$vue = table_objet($vue);
53
-		$fond = "prive/objets/liste/$vue";
54
-		if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
-			return _L("vue $vue introuvable pour lister les objets");
56
-		}
57
-	}
48
+    $fond = "prive/objets/liste/$vue";
49
+    if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
+        // traiter les cas particuliers
51
+        include_spip('base/connect_sql');
52
+        $vue = table_objet($vue);
53
+        $fond = "prive/objets/liste/$vue";
54
+        if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
+            return _L("vue $vue introuvable pour lister les objets");
56
+        }
57
+    }
58 58
 
59 59
 
60
-	$contexte['sinon'] = ($force ? $contexte['titre'] : '');
60
+    $contexte['sinon'] = ($force ? $contexte['titre'] : '');
61 61
 
62
-	$res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
-	if (_request('var_liste')) {
64
-		echo var_export($contexte, true);
65
-	}
62
+    $res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
+    if (_request('var_liste')) {
64
+        echo var_export($contexte, true);
65
+    }
66 66
 
67
-	return $res;
67
+    return $res;
68 68
 }
Please login to merge, or discard this patch.
ecrire/inc/lang.php 1 patch
Indentation   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Langue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -39,36 +39,36 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function changer_langue($lang, $liste_langues = null) {
41 41
 
42
-	if (is_null($liste_langues)) {
43
-		$liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue'];
44
-	}
45
-	else {
46
-		if (is_array($liste_langues)) {
47
-			$liste_langues = implode(',', $liste_langues);
48
-		}
49
-	}
50
-	$liste_langues = ',' . $liste_langues . ',';
51
-
52
-	// Si la langue demandee n'existe pas, on essaie d'autres variantes
53
-	// Exemple : 'pt-br' => 'pt_br' => 'pt'
54
-	$lang = str_replace('-', '_', trim($lang));
55
-	if (!$lang) {
56
-		return false;
57
-	}
58
-
59
-	if (
60
-		strpos($liste_langues, ",$lang,") !== false
61
-		or ($lang = preg_replace(',_.*,', '', $lang)
62
-			and strpos($liste_langues, ",$lang,") !== false)
63
-	) {
64
-		$GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
65
-		$GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
66
-		$GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
67
-
68
-		return $GLOBALS['spip_lang'] = $lang;
69
-	} else {
70
-		return false;
71
-	}
42
+    if (is_null($liste_langues)) {
43
+        $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue'];
44
+    }
45
+    else {
46
+        if (is_array($liste_langues)) {
47
+            $liste_langues = implode(',', $liste_langues);
48
+        }
49
+    }
50
+    $liste_langues = ',' . $liste_langues . ',';
51
+
52
+    // Si la langue demandee n'existe pas, on essaie d'autres variantes
53
+    // Exemple : 'pt-br' => 'pt_br' => 'pt'
54
+    $lang = str_replace('-', '_', trim($lang));
55
+    if (!$lang) {
56
+        return false;
57
+    }
58
+
59
+    if (
60
+        strpos($liste_langues, ",$lang,") !== false
61
+        or ($lang = preg_replace(',_.*,', '', $lang)
62
+            and strpos($liste_langues, ",$lang,") !== false)
63
+    ) {
64
+        $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
65
+        $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
66
+        $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
67
+
68
+        return $GLOBALS['spip_lang'] = $lang;
69
+    } else {
70
+        return false;
71
+    }
72 72
 }
73 73
 
74 74
 //
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
82 82
 
83 83
 function choisir_traduction($trads, $lang = '') {
84
-	$k = approcher_langue($trads, $lang);
84
+    $k = approcher_langue($trads, $lang);
85 85
 
86
-	return $k ? $trads[$k] : array_shift($trads);
86
+    return $k ? $trads[$k] : array_shift($trads);
87 87
 }
88 88
 
89 89
 // retourne son 2e argument si c'est un index du premier
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 // la langue X etant consideree comme une approche de X_Y
92 92
 function approcher_langue($trads, $lang = '') {
93 93
 
94
-	if (!$lang) {
95
-		$lang = $GLOBALS['spip_lang'];
96
-	}
97
-
98
-	if (isset($trads[$lang])) {
99
-		return $lang;
100
-	} // cas des langues xx_yy
101
-	else {
102
-		$r = explode('_', $lang);
103
-		if (isset($trads[$r[0]])) {
104
-			return $r[0];
105
-		}
106
-	}
107
-
108
-	return '';
94
+    if (!$lang) {
95
+        $lang = $GLOBALS['spip_lang'];
96
+    }
97
+
98
+    if (isset($trads[$lang])) {
99
+        return $lang;
100
+    } // cas des langues xx_yy
101
+    else {
102
+        $r = explode('_', $lang);
103
+        if (isset($trads[$r[0]])) {
104
+            return $r[0];
105
+        }
106
+    }
107
+
108
+    return '';
109 109
 }
110 110
 
111 111
 /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
  *     Nom de la langue, sinon son code.
121 121
  **/
122 122
 function traduire_nom_langue($lang) {
123
-	include_spip('inc/lang_liste');
124
-	include_spip('inc/charsets');
123
+    include_spip('inc/lang_liste');
124
+    include_spip('inc/charsets');
125 125
 
126
-	return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
126
+    return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
127 127
 }
128 128
 
129 129
 //
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
138 138
 // https://code.spip.net/@lang_dir
139 139
 function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') {
140
-	static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
140
+    static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
141 141
 
142
-	return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
143
-		$gaucher : $droitier;
142
+    return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
143
+        $gaucher : $droitier;
144 144
 }
145 145
 
146 146
 // typo francaise ou anglaise ?
@@ -150,32 +150,32 @@  discard block
 block discarded – undo
150 150
 
151 151
 // https://code.spip.net/@lang_typo
152 152
 function lang_typo($lang = '') {
153
-	if (!$lang) {
154
-		$lang = isset($GLOBALS['lang_objet'])
155
-			? $GLOBALS['lang_objet']
156
-			: $GLOBALS['spip_lang'];
157
-	}
158
-	if (
159
-		$lang == 'eo'
160
-		or $lang == 'fr'
161
-		or strncmp($lang, 'fr_', 3) == 0
162
-		or $lang == 'cpf'
163
-	) {
164
-		return 'fr';
165
-	} else {
166
-		return 'en';
167
-	}
153
+    if (!$lang) {
154
+        $lang = isset($GLOBALS['lang_objet'])
155
+            ? $GLOBALS['lang_objet']
156
+            : $GLOBALS['spip_lang'];
157
+    }
158
+    if (
159
+        $lang == 'eo'
160
+        or $lang == 'fr'
161
+        or strncmp($lang, 'fr_', 3) == 0
162
+        or $lang == 'cpf'
163
+    ) {
164
+        return 'fr';
165
+    } else {
166
+        return 'en';
167
+    }
168 168
 }
169 169
 
170 170
 // gestion de la globale $lang_objet pour que les textes soient affiches
171 171
 // avec les memes typo et direction dans l'espace prive que dans le public
172 172
 // https://code.spip.net/@changer_typo
173 173
 function changer_typo($lang = '') {
174
-	if ($lang) {
175
-		$GLOBALS['lang_objet'] = $lang;
176
-	} else {
177
-		unset($GLOBALS['lang_objet']);
178
-	}
174
+    if ($lang) {
175
+        $GLOBALS['lang_objet'] = $lang;
176
+    } else {
177
+        unset($GLOBALS['lang_objet']);
178
+    }
179 179
 }
180 180
 
181 181
 //
@@ -186,59 +186,59 @@  discard block
 block discarded – undo
186 186
 //
187 187
 // https://code.spip.net/@menu_langues
188 188
 function menu_langues($nom_select, $default = '') {
189
-	include_spip('inc/actions');
190
-
191
-	$langues = liste_options_langues($nom_select);
192
-	$ret = '';
193
-	if (!count($langues)) {
194
-		return '';
195
-	}
196
-
197
-	if (!$default) {
198
-		$default = $GLOBALS['spip_lang'];
199
-	}
200
-	foreach ($langues as $l) {
201
-		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
202
-		$ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
203
-	}
204
-
205
-	if (!test_espace_prive()) {
206
-		$cible = self();
207
-		$base = '';
208
-	} else {
209
-		$cible = self();
210
-		$base = spip_connect() ? 'base' : '';
211
-	}
212
-
213
-	$change = ' onchange="this.parentNode.parentNode.submit()"';
214
-
215
-	return generer_action_auteur(
216
-		'converser',
217
-		$base,
218
-		$cible,
219
-		(select_langues($nom_select, $change, $ret)
220
-			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
221
-		" method='post'"
222
-	);
189
+    include_spip('inc/actions');
190
+
191
+    $langues = liste_options_langues($nom_select);
192
+    $ret = '';
193
+    if (!count($langues)) {
194
+        return '';
195
+    }
196
+
197
+    if (!$default) {
198
+        $default = $GLOBALS['spip_lang'];
199
+    }
200
+    foreach ($langues as $l) {
201
+        $selected = ($l == $default) ? ' selected=\'selected\'' : '';
202
+        $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
203
+    }
204
+
205
+    if (!test_espace_prive()) {
206
+        $cible = self();
207
+        $base = '';
208
+    } else {
209
+        $cible = self();
210
+        $base = spip_connect() ? 'base' : '';
211
+    }
212
+
213
+    $change = ' onchange="this.parentNode.parentNode.submit()"';
214
+
215
+    return generer_action_auteur(
216
+        'converser',
217
+        $base,
218
+        $cible,
219
+        (select_langues($nom_select, $change, $ret)
220
+            . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
221
+        " method='post'"
222
+    );
223 223
 }
224 224
 
225 225
 // https://code.spip.net/@select_langues
226 226
 function select_langues($nom_select, $change, $options, $label = '') {
227
-	static $cpt = 0;
228
-	$id = 'menu_langues' . $cpt++;
229
-
230
-	return
231
-		"<label for='$id'>" . ($label ? $label : _T('info_langues')) . '</label> ' .
232
-		"<select name='$nom_select' id='$id' "
233
-		. ((!test_espace_prive()) ?
234
-			("class='forml menu_langues'") :
235
-			(($nom_select == 'var_lang_ecrire') ?
236
-				("class='lang_ecrire'") :
237
-				"class='fondl'"))
238
-		. $change
239
-		. ">\n"
240
-		. $options
241
-		. '</select>';
227
+    static $cpt = 0;
228
+    $id = 'menu_langues' . $cpt++;
229
+
230
+    return
231
+        "<label for='$id'>" . ($label ? $label : _T('info_langues')) . '</label> ' .
232
+        "<select name='$nom_select' id='$id' "
233
+        . ((!test_espace_prive()) ?
234
+            ("class='forml menu_langues'") :
235
+            (($nom_select == 'var_lang_ecrire') ?
236
+                ("class='lang_ecrire'") :
237
+                "class='fondl'"))
238
+        . $change
239
+        . ">\n"
240
+        . $options
241
+        . '</select>';
242 242
 }
243 243
 
244 244
 /**
@@ -260,34 +260,34 @@  discard block
 block discarded – undo
260 260
  */
261 261
 function liste_options_langues($nom_select) {
262 262
 
263
-	switch ($nom_select) {
264
-		# #MENU_LANG
265
-		case 'var_lang':
266
-			# menu de changement de la langue d'un article
267
-			# les langues selectionnees dans la configuration "multilinguisme"
268
-		case 'changer_lang':
269
-			$langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
270
-			break;
271
-		# menu de l'interface (privee, installation et panneau de login)
272
-		# les langues presentes sous forme de fichiers de langue
273
-		# on force la relecture du repertoire des langues pour etre synchrone.
274
-		case 'var_lang_ecrire':
275
-		default:
276
-			$GLOBALS['meta']['langues_proposees'] = '';
277
-			init_langues();
278
-			$langues = explode(',', $GLOBALS['meta']['langues_proposees']);
279
-			break;
263
+    switch ($nom_select) {
264
+        # #MENU_LANG
265
+        case 'var_lang':
266
+            # menu de changement de la langue d'un article
267
+            # les langues selectionnees dans la configuration "multilinguisme"
268
+        case 'changer_lang':
269
+            $langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
270
+            break;
271
+        # menu de l'interface (privee, installation et panneau de login)
272
+        # les langues presentes sous forme de fichiers de langue
273
+        # on force la relecture du repertoire des langues pour etre synchrone.
274
+        case 'var_lang_ecrire':
275
+        default:
276
+            $GLOBALS['meta']['langues_proposees'] = '';
277
+            init_langues();
278
+            $langues = explode(',', $GLOBALS['meta']['langues_proposees']);
279
+            break;
280 280
 
281 281
 # dernier choix possible : toutes les langues = langues_proposees
282 282
 # + langues_multilingues ; mais, ne sert pas
283 283
 #			$langues = explode(',', $GLOBALS['all_langs']);
284
-	}
285
-	if (count($langues) <= 1) {
286
-		return [];
287
-	}
288
-	sort($langues);
284
+    }
285
+    if (count($langues) <= 1) {
286
+        return [];
287
+    }
288
+    sort($langues);
289 289
 
290
-	return $langues;
290
+    return $langues;
291 291
 }
292 292
 
293 293
 
@@ -302,39 +302,39 @@  discard block
 block discarded – undo
302 302
  **/
303 303
 function verifier_lang_url() {
304 304
 
305
-	// quelle langue est demandee ?
306
-	$lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
307
-	if (isset($_COOKIE['spip_lang_ecrire'])) {
308
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
309
-	}
310
-	if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
311
-		$lang_demandee = $_COOKIE['spip_lang'];
312
-	}
313
-	if (isset($_GET['lang'])) {
314
-		$lang_demandee = $_GET['lang'];
315
-	}
316
-
317
-	// Renvoyer si besoin (et si la langue demandee existe)
318
-	if (
319
-		$GLOBALS['spip_lang'] != $lang_demandee
320
-		and changer_langue($lang_demandee)
321
-		and $lang_demandee != @$_GET['lang']
322
-	) {
323
-		$destination = parametre_url(self(), 'lang', $lang_demandee, '&');
324
-		// ici on a besoin des var_truc
325
-		foreach ($_GET as $var => $val) {
326
-			if (!strncmp('var_', $var, 4)) {
327
-				$destination = parametre_url($destination, $var, $val, '&');
328
-			}
329
-		}
330
-		include_spip('inc/headers');
331
-		redirige_par_entete($destination);
332
-	}
333
-
334
-	// Subtilite : si la langue demandee par cookie est la bonne
335
-	// alors on fait comme si $lang etait passee dans l'URL
336
-	// (pour criteres {lang}).
337
-	$GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
305
+    // quelle langue est demandee ?
306
+    $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
307
+    if (isset($_COOKIE['spip_lang_ecrire'])) {
308
+        $lang_demandee = $_COOKIE['spip_lang_ecrire'];
309
+    }
310
+    if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
311
+        $lang_demandee = $_COOKIE['spip_lang'];
312
+    }
313
+    if (isset($_GET['lang'])) {
314
+        $lang_demandee = $_GET['lang'];
315
+    }
316
+
317
+    // Renvoyer si besoin (et si la langue demandee existe)
318
+    if (
319
+        $GLOBALS['spip_lang'] != $lang_demandee
320
+        and changer_langue($lang_demandee)
321
+        and $lang_demandee != @$_GET['lang']
322
+    ) {
323
+        $destination = parametre_url(self(), 'lang', $lang_demandee, '&');
324
+        // ici on a besoin des var_truc
325
+        foreach ($_GET as $var => $val) {
326
+            if (!strncmp('var_', $var, 4)) {
327
+                $destination = parametre_url($destination, $var, $val, '&');
328
+            }
329
+        }
330
+        include_spip('inc/headers');
331
+        redirige_par_entete($destination);
332
+    }
333
+
334
+    // Subtilite : si la langue demandee par cookie est la bonne
335
+    // alors on fait comme si $lang etait passee dans l'URL
336
+    // (pour criteres {lang}).
337
+    $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
338 338
 }
339 339
 
340 340
 
@@ -352,22 +352,22 @@  discard block
 block discarded – undo
352 352
  *     La langue sélectionnée
353 353
  **/
354 354
 function utiliser_langue_site($liste_langues = null) {
355
-	// s'il existe une langue du site (en gros tout le temps en théorie)
356
-	if (
357
-		isset($GLOBALS['meta']['langue_site'])
358
-		// et si spip_langue est pas encore définie (ce que va faire changer_langue())
359
-		// ou qu'elle n'est pas identique à la langue du site
360
-		and (!isset($GLOBALS['spip_lang'])
361
-			or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
362
-	) {
363
-		return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
364
-	}
365
-	// en theorie là, la globale est définie, sinon c'est un problème.
366
-	if (!isset($GLOBALS['spip_lang'])) {
367
-		spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
368
-	}
369
-
370
-	return $GLOBALS['spip_lang'];
355
+    // s'il existe une langue du site (en gros tout le temps en théorie)
356
+    if (
357
+        isset($GLOBALS['meta']['langue_site'])
358
+        // et si spip_langue est pas encore définie (ce que va faire changer_langue())
359
+        // ou qu'elle n'est pas identique à la langue du site
360
+        and (!isset($GLOBALS['spip_lang'])
361
+            or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
362
+    ) {
363
+        return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
364
+    }
365
+    // en theorie là, la globale est définie, sinon c'est un problème.
366
+    if (!isset($GLOBALS['spip_lang'])) {
367
+        spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
368
+    }
369
+
370
+    return $GLOBALS['spip_lang'];
371 371
 }
372 372
 
373 373
 /**
@@ -386,30 +386,30 @@  discard block
 block discarded – undo
386 386
  **/
387 387
 function utiliser_langue_visiteur($liste_langues = null) {
388 388
 
389
-	$l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
390
-	if (isset($_COOKIE[$l])) {
391
-		if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
392
-			return $l;
393
-		}
394
-	}
395
-
396
-	if (isset($GLOBALS['visiteur_session']['lang'])) {
397
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
398
-			return $l;
399
-		}
400
-	}
401
-
402
-	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
403
-		foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
404
-			if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
405
-				if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
406
-					return $l;
407
-				}
408
-			}
409
-		}
410
-	}
411
-
412
-	return utiliser_langue_site($liste_langues);
389
+    $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
390
+    if (isset($_COOKIE[$l])) {
391
+        if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
392
+            return $l;
393
+        }
394
+    }
395
+
396
+    if (isset($GLOBALS['visiteur_session']['lang'])) {
397
+        if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
398
+            return $l;
399
+        }
400
+    }
401
+
402
+    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
403
+        foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
404
+            if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
405
+                if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
406
+                    return $l;
407
+                }
408
+            }
409
+        }
410
+    }
411
+
412
+    return utiliser_langue_site($liste_langues);
413 413
 }
414 414
 
415 415
 
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
  * @return int
420 420
  */
421 421
 function match_langue($chaine) {
422
-	return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
422
+    return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
423 423
 }
424 424
 
425 425
 /**
@@ -437,36 +437,36 @@  discard block
 block discarded – undo
437 437
  **/
438 438
 function init_langues() {
439 439
 
440
-	// liste des langues dans les meta, sauf a l'install
441
-	$all_langs = @$GLOBALS['meta']['langues_proposees'];
442
-
443
-	$tout = [];
444
-	if (!$all_langs) {
445
-		// trouver tous les modules lang/spip_xx.php
446
-		$modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
447
-		foreach ($modules as $name => $path) {
448
-			if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
449
-				if (match_langue($regs[1])) {
450
-					$tout[] = $regs[1];
451
-				}
452
-			}
453
-		}
454
-		sort($tout);
455
-		$tout = join(',', $tout);
456
-		// Si les langues n'ont pas change, ne rien faire
457
-		if ($tout != $all_langs) {
458
-			$GLOBALS['meta']['langues_proposees'] = $tout;
459
-			include_spip('inc/meta');
460
-			ecrire_meta('langues_proposees', $tout);
461
-		}
462
-	}
463
-	if (!isset($GLOBALS['meta']['langue_site'])) {
464
-		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
465
-		$GLOBALS['meta']['langue_site'] = $tout =
466
-			(!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false))
467
-				? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
468
-		ecrire_meta('langue_site', $tout);
469
-	}
440
+    // liste des langues dans les meta, sauf a l'install
441
+    $all_langs = @$GLOBALS['meta']['langues_proposees'];
442
+
443
+    $tout = [];
444
+    if (!$all_langs) {
445
+        // trouver tous les modules lang/spip_xx.php
446
+        $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
447
+        foreach ($modules as $name => $path) {
448
+            if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
449
+                if (match_langue($regs[1])) {
450
+                    $tout[] = $regs[1];
451
+                }
452
+            }
453
+        }
454
+        sort($tout);
455
+        $tout = join(',', $tout);
456
+        // Si les langues n'ont pas change, ne rien faire
457
+        if ($tout != $all_langs) {
458
+            $GLOBALS['meta']['langues_proposees'] = $tout;
459
+            include_spip('inc/meta');
460
+            ecrire_meta('langues_proposees', $tout);
461
+        }
462
+    }
463
+    if (!isset($GLOBALS['meta']['langue_site'])) {
464
+        // Initialisation : le francais si dispo, sinon la premiere langue trouvee
465
+        $GLOBALS['meta']['langue_site'] = $tout =
466
+            (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false))
467
+                ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
468
+        ecrire_meta('langue_site', $tout);
469
+    }
470 470
 }
471 471
 
472 472
 /**
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
  *     Code html de la balise <html>
481 481
  **/
482 482
 function html_lang_attributes() {
483
-	$lang = $GLOBALS['spip_lang'];
484
-	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
483
+    $lang = $GLOBALS['spip_lang'];
484
+    $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
485 485
 
486
-	return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
486
+    return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
487 487
 }
488 488
 
489 489
 
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
  * @return string
498 498
  */
499 499
 function aide_lang_dir($spip_lang, $spip_lang_rtl) {
500
-	return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
500
+    return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
501 501
 }
502 502
 
503 503
 
Please login to merge, or discard this patch.
ecrire/inc/pipelines_ecrire.php 1 patch
Indentation   +226 added lines, -226 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
 
@@ -36,37 +36,37 @@  discard block
 block discarded – undo
36 36
  * @return string          Contenu complété des scripts javascripts, dont jQuery
37 37
  **/
38 38
 function f_jQuery_prive($texte) {
39
-	$x = '';
40
-	$jquery_plugins = pipeline(
41
-		'jquery_plugins',
42
-		[
43
-			'prive/javascript/jquery.js',
44
-			'prive/javascript/jquery.form.js',
45
-			'prive/javascript/jquery.autosave.js',
46
-			'prive/javascript/jquery.placeholder-label.js',
47
-			'prive/javascript/ajaxCallback.js',
48
-			'prive/javascript/js.cookie.js',
49
-			'prive/javascript/jquery.cookie.js',
50
-			'prive/javascript/spip_barre.js',
51
-		]
52
-	);
53
-	foreach (array_unique($jquery_plugins) as $script) {
54
-		if ($script = find_in_path(supprimer_timestamp($script))) {
55
-			$script = timestamp($script);
56
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
-		}
58
-	}
59
-	// inserer avant le premier script externe ou a la fin
60
-	if (
61
-		preg_match(',<script[^><]*src=,', $texte, $match)
62
-		and $p = strpos($texte, $match[0])
63
-	) {
64
-		$texte = substr_replace($texte, $x, $p, 0);
65
-	} else {
66
-		$texte .= $x;
67
-	}
39
+    $x = '';
40
+    $jquery_plugins = pipeline(
41
+        'jquery_plugins',
42
+        [
43
+            'prive/javascript/jquery.js',
44
+            'prive/javascript/jquery.form.js',
45
+            'prive/javascript/jquery.autosave.js',
46
+            'prive/javascript/jquery.placeholder-label.js',
47
+            'prive/javascript/ajaxCallback.js',
48
+            'prive/javascript/js.cookie.js',
49
+            'prive/javascript/jquery.cookie.js',
50
+            'prive/javascript/spip_barre.js',
51
+        ]
52
+    );
53
+    foreach (array_unique($jquery_plugins) as $script) {
54
+        if ($script = find_in_path(supprimer_timestamp($script))) {
55
+            $script = timestamp($script);
56
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
+        }
58
+    }
59
+    // inserer avant le premier script externe ou a la fin
60
+    if (
61
+        preg_match(',<script[^><]*src=,', $texte, $match)
62
+        and $p = strpos($texte, $match[0])
63
+    ) {
64
+        $texte = substr_replace($texte, $x, $p, 0);
65
+    } else {
66
+        $texte .= $x;
67
+    }
68 68
 
69
-	return $texte;
69
+    return $texte;
70 70
 }
71 71
 
72 72
 
@@ -79,43 +79,43 @@  discard block
 block discarded – undo
79 79
  * @return string
80 80
  */
81 81
 function affichage_final_prive_title_auto($texte) {
82
-	if (
83
-		strpos($texte, '<title>') === false
84
-		and
85
-		(preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
-			or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
-		and $match = textebrut(trim($match[1]))
88
-		and ($p = strpos($texte, '<head>')) !== false
89
-	) {
90
-		if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
-			$nom_site_spip = _T('info_mon_site_spip');
92
-		}
82
+    if (
83
+        strpos($texte, '<title>') === false
84
+        and
85
+        (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
+            or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
+        and $match = textebrut(trim($match[1]))
88
+        and ($p = strpos($texte, '<head>')) !== false
89
+    ) {
90
+        if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
+            $nom_site_spip = _T('info_mon_site_spip');
92
+        }
93 93
 
94
-		$titre = '<title>['
95
-			. $nom_site_spip
96
-			. '] ' . $match
97
-			. '</title>';
94
+        $titre = '<title>['
95
+            . $nom_site_spip
96
+            . '] ' . $match
97
+            . '</title>';
98 98
 
99
-		$texte = substr_replace($texte, $titre, $p + 6, 0);
100
-	}
99
+        $texte = substr_replace($texte, $titre, $p + 6, 0);
100
+    }
101 101
 
102
-	return $texte;
102
+    return $texte;
103 103
 }
104 104
 
105 105
 
106 106
 // Fonction standard pour le pipeline 'boite_infos'
107 107
 // https://code.spip.net/@f_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 = isset($flux['args']['contexte']['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 = (isset($flux['args']['contexte']['type-page']) ? $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 = isset($flux['args']['contexte']['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 = (isset($flux['args']['contexte']['type-page']) ? $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($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.