Completed
Push — master ( 6c9939...4ccfda )
by cam
01:06
created
config/ecran_securite.php 1 patch
Indentation   +424 added lines, -424 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
  * Test utilisateur
16 16
  */
17 17
 if (isset($_GET['test_ecran_securite'])) {
18
-	$ecran_securite_raison = 'test ' . _ECRAN_SECURITE;
18
+    $ecran_securite_raison = 'test ' . _ECRAN_SECURITE;
19 19
 }
20 20
 
21 21
 if (file_exists($f = __DIR__ . DIRECTORY_SEPARATOR  . 'ecran_securite_options.php')) {
22
-	include ($f);
22
+    include ($f);
23 23
 }
24 24
 
25 25
 /*
@@ -29,222 +29,222 @@  discard block
 block discarded – undo
29 29
  * le load depasse ECRAN_SECURITE_LOAD)
30 30
  */
31 31
 if (!defined('_IS_BOT') and isset($_GET['var_isbot'])) {
32
-	define('_IS_BOT', $_GET['var_isbot'] ? true : false);
32
+    define('_IS_BOT', $_GET['var_isbot'] ? true : false);
33 33
 }
34 34
 
35 35
 /*
36 36
  * Détecteur de robot d'indexation
37 37
  */
38 38
 if (!defined('_IS_BOT')) {
39
-	define(
40
-		'_IS_BOT',
41
-		isset($_SERVER['HTTP_USER_AGENT'])
42
-			and preg_match(
43
-				','
44
-					. implode('|', array(
45
-						// mots generiques
46
-						'bot',
47
-						'slurp',
48
-						'crawler',
49
-						'crwlr',
50
-						'java',
51
-						'monitoring',
52
-						'spider',
53
-						'webvac',
54
-						'yandex',
55
-						'MSIE 6\.0', // botnet 99,9% du temps
56
-						// UA plus cibles
57
-						'200please',
58
-						'80legs',
59
-						'a6-indexer',
60
-						'aboundex',
61
-						'accoona',
62
-						'acrylicapps',
63
-						'addthis',
64
-						'adressendeutschland',
65
-						'alexa',
66
-						'altavista',
67
-						'analyticsseo',
68
-						'antennapod',
69
-						'arachnys',
70
-						'archive',
71
-						'argclrint',
72
-						'aspseek',
73
-						'baidu',
74
-						'begunadvertising',
75
-						'bing',
76
-						'bloglines',
77
-						'buck',
78
-						'browsershots',
79
-						'bubing',
80
-						'butterfly',
81
-						'changedetection',
82
-						'charlotte',
83
-						'chilkat',
84
-						'china',
85
-						'coccoc',
86
-						'crowsnest',
87
-						'dataminr',
88
-						'daumoa',
89
-						'dlvr\.it',
90
-						'dlweb',
91
-						'drupal',
92
-						'ec2linkfinder',
93
-						'eset\.com',
94
-						'estyle',
95
-						'exalead',
96
-						'ezooms',
97
-						'facebookexternalhit',
98
-						'facebookplatform',
99
-						'fairshare',
100
-						'feedfetcher',
101
-						'feedfetcher-google',
102
-						'feedly',
103
-						'fetch',
104
-						'flipboardproxy',
105
-						'genieo',
106
-						'google',
107
-						'go-http-client',
108
-						'grapeshot',
109
-						'hatena-useragent',
110
-						'head',
111
-						'hosttracker',
112
-						'hubspot',
113
-						'ia_archiver',
114
-						'ichiro',
115
-						'iltrovatore-setaccio',
116
-						'immediatenet',
117
-						'ina',
118
-						'inoreader',
119
-						'infegyatlas',
120
-						'infohelfer',
121
-						'instapaper',
122
-						'jabse',
123
-						'james',
124
-						'jersey',
125
-						'kumkie',
126
-						'linkdex',
127
-						'linkfluence',
128
-						'linkwalker',
129
-						'litefinder',
130
-						'loadimpactpageanalyzer',
131
-						'ltx71',
132
-						'luminate',
133
-						'lycos',
134
-						'lycosa',
135
-						'mediapartners-google',
136
-						'msai',
137
-						'myapp',
138
-						'nativehost',
139
-						'najdi',
140
-						'netcraftsurveyagent',
141
-						'netestate',
142
-						'netseer',
143
-						'netnewswire',
144
-						'newspaper',
145
-						'newsblur',
146
-						'nuhk',
147
-						'nuzzel',
148
-						'okhttp',
149
-						'otmedia',
150
-						'owlin',
151
-						'owncloud',
152
-						'panscient',
153
-						'paper\.li',
154
-						'parsijoo',
155
-						'protopage',
156
-						'plukkie',
157
-						'proximic',
158
-						'pubsub',
159
-						'python',
160
-						'qirina',
161
-						'qoshe',
162
-						'qualidator',
163
-						'qwantify',
164
-						'rambler',
165
-						'readability',
166
-						'ruby',
167
-						'sbsearch',
168
-						'scoop\.it',
169
-						'scooter',
170
-						'scoutjet',
171
-						'scrapy',
172
-						'scrubby',
173
-						'scrubbybloglines',
174
-						'shareaholic',
175
-						'shopwiki',
176
-						'simplepie',
177
-						'sistrix',
178
-						'sitechecker',
179
-						'siteexplorer',
180
-						'snapshot',
181
-						'sogou',
182
-						'special_archiver',
183
-						'speedy',
184
-						'spinn3r',
185
-						'spreadtrum',
186
-						'steeler',
187
-						'subscriber',
188
-						'suma',
189
-						'superdownloads',
190
-						'svenska-webbsido',
191
-						'teoma',
192
-						'the knowledge AI',
193
-						'thumbshots',
194
-						'tineye',
195
-						'traackr',
196
-						'trendiction',
197
-						'trendsmap',
198
-						'tweetedtimes',
199
-						'tweetmeme',
200
-						'universalfeedparser',
201
-						'uaslinkchecker',
202
-						'undrip',
203
-						'unwindfetchor',
204
-						'upday',
205
-						'vedma',
206
-						'vkshare',
207
-						'vm',
208
-						'wch',
209
-						'webalta',
210
-						'webcookies',
211
-						'webparser',
212
-						'webthumbnail',
213
-						'wesee',
214
-						'wise-guys',
215
-						'woko',
216
-						'wordpress',
217
-						'wotbox',
218
-						'y!j-bri',
219
-						'y!j-bro',
220
-						'y!j-brw',
221
-						'y!j-bsc',
222
-						'yahoo',
223
-						'yahoo!',
224
-						'yahooysmcm',
225
-						'ymobactus',
226
-						'yats',
227
-						'yeti',
228
-						'zeerch'
229
-					)) . ',i',
230
-				(string)$_SERVER['HTTP_USER_AGENT']
231
-			)
232
-	);
39
+    define(
40
+        '_IS_BOT',
41
+        isset($_SERVER['HTTP_USER_AGENT'])
42
+            and preg_match(
43
+                ','
44
+                    . implode('|', array(
45
+                        // mots generiques
46
+                        'bot',
47
+                        'slurp',
48
+                        'crawler',
49
+                        'crwlr',
50
+                        'java',
51
+                        'monitoring',
52
+                        'spider',
53
+                        'webvac',
54
+                        'yandex',
55
+                        'MSIE 6\.0', // botnet 99,9% du temps
56
+                        // UA plus cibles
57
+                        '200please',
58
+                        '80legs',
59
+                        'a6-indexer',
60
+                        'aboundex',
61
+                        'accoona',
62
+                        'acrylicapps',
63
+                        'addthis',
64
+                        'adressendeutschland',
65
+                        'alexa',
66
+                        'altavista',
67
+                        'analyticsseo',
68
+                        'antennapod',
69
+                        'arachnys',
70
+                        'archive',
71
+                        'argclrint',
72
+                        'aspseek',
73
+                        'baidu',
74
+                        'begunadvertising',
75
+                        'bing',
76
+                        'bloglines',
77
+                        'buck',
78
+                        'browsershots',
79
+                        'bubing',
80
+                        'butterfly',
81
+                        'changedetection',
82
+                        'charlotte',
83
+                        'chilkat',
84
+                        'china',
85
+                        'coccoc',
86
+                        'crowsnest',
87
+                        'dataminr',
88
+                        'daumoa',
89
+                        'dlvr\.it',
90
+                        'dlweb',
91
+                        'drupal',
92
+                        'ec2linkfinder',
93
+                        'eset\.com',
94
+                        'estyle',
95
+                        'exalead',
96
+                        'ezooms',
97
+                        'facebookexternalhit',
98
+                        'facebookplatform',
99
+                        'fairshare',
100
+                        'feedfetcher',
101
+                        'feedfetcher-google',
102
+                        'feedly',
103
+                        'fetch',
104
+                        'flipboardproxy',
105
+                        'genieo',
106
+                        'google',
107
+                        'go-http-client',
108
+                        'grapeshot',
109
+                        'hatena-useragent',
110
+                        'head',
111
+                        'hosttracker',
112
+                        'hubspot',
113
+                        'ia_archiver',
114
+                        'ichiro',
115
+                        'iltrovatore-setaccio',
116
+                        'immediatenet',
117
+                        'ina',
118
+                        'inoreader',
119
+                        'infegyatlas',
120
+                        'infohelfer',
121
+                        'instapaper',
122
+                        'jabse',
123
+                        'james',
124
+                        'jersey',
125
+                        'kumkie',
126
+                        'linkdex',
127
+                        'linkfluence',
128
+                        'linkwalker',
129
+                        'litefinder',
130
+                        'loadimpactpageanalyzer',
131
+                        'ltx71',
132
+                        'luminate',
133
+                        'lycos',
134
+                        'lycosa',
135
+                        'mediapartners-google',
136
+                        'msai',
137
+                        'myapp',
138
+                        'nativehost',
139
+                        'najdi',
140
+                        'netcraftsurveyagent',
141
+                        'netestate',
142
+                        'netseer',
143
+                        'netnewswire',
144
+                        'newspaper',
145
+                        'newsblur',
146
+                        'nuhk',
147
+                        'nuzzel',
148
+                        'okhttp',
149
+                        'otmedia',
150
+                        'owlin',
151
+                        'owncloud',
152
+                        'panscient',
153
+                        'paper\.li',
154
+                        'parsijoo',
155
+                        'protopage',
156
+                        'plukkie',
157
+                        'proximic',
158
+                        'pubsub',
159
+                        'python',
160
+                        'qirina',
161
+                        'qoshe',
162
+                        'qualidator',
163
+                        'qwantify',
164
+                        'rambler',
165
+                        'readability',
166
+                        'ruby',
167
+                        'sbsearch',
168
+                        'scoop\.it',
169
+                        'scooter',
170
+                        'scoutjet',
171
+                        'scrapy',
172
+                        'scrubby',
173
+                        'scrubbybloglines',
174
+                        'shareaholic',
175
+                        'shopwiki',
176
+                        'simplepie',
177
+                        'sistrix',
178
+                        'sitechecker',
179
+                        'siteexplorer',
180
+                        'snapshot',
181
+                        'sogou',
182
+                        'special_archiver',
183
+                        'speedy',
184
+                        'spinn3r',
185
+                        'spreadtrum',
186
+                        'steeler',
187
+                        'subscriber',
188
+                        'suma',
189
+                        'superdownloads',
190
+                        'svenska-webbsido',
191
+                        'teoma',
192
+                        'the knowledge AI',
193
+                        'thumbshots',
194
+                        'tineye',
195
+                        'traackr',
196
+                        'trendiction',
197
+                        'trendsmap',
198
+                        'tweetedtimes',
199
+                        'tweetmeme',
200
+                        'universalfeedparser',
201
+                        'uaslinkchecker',
202
+                        'undrip',
203
+                        'unwindfetchor',
204
+                        'upday',
205
+                        'vedma',
206
+                        'vkshare',
207
+                        'vm',
208
+                        'wch',
209
+                        'webalta',
210
+                        'webcookies',
211
+                        'webparser',
212
+                        'webthumbnail',
213
+                        'wesee',
214
+                        'wise-guys',
215
+                        'woko',
216
+                        'wordpress',
217
+                        'wotbox',
218
+                        'y!j-bri',
219
+                        'y!j-bro',
220
+                        'y!j-brw',
221
+                        'y!j-bsc',
222
+                        'yahoo',
223
+                        'yahoo!',
224
+                        'yahooysmcm',
225
+                        'ymobactus',
226
+                        'yats',
227
+                        'yeti',
228
+                        'zeerch'
229
+                    )) . ',i',
230
+                (string)$_SERVER['HTTP_USER_AGENT']
231
+            )
232
+    );
233 233
 }
234 234
 if (!defined('_IS_BOT_FRIEND')) {
235
-	define(
236
-		'_IS_BOT_FRIEND',
237
-		isset($_SERVER['HTTP_USER_AGENT'])
238
-			and preg_match(
239
-				',' . implode('|', array(
240
-					'facebookexternalhit',
241
-					'twitterbot',
242
-					'flipboardproxy',
243
-					'wordpress'
244
-				)) . ',i',
245
-				(string)$_SERVER['HTTP_USER_AGENT']
246
-			)
247
-	);
235
+    define(
236
+        '_IS_BOT_FRIEND',
237
+        isset($_SERVER['HTTP_USER_AGENT'])
238
+            and preg_match(
239
+                ',' . implode('|', array(
240
+                    'facebookexternalhit',
241
+                    'twitterbot',
242
+                    'flipboardproxy',
243
+                    'wordpress'
244
+                )) . ',i',
245
+                (string)$_SERVER['HTTP_USER_AGENT']
246
+            )
247
+    );
248 248
 }
249 249
 
250 250
 /*
@@ -256,28 +256,28 @@  discard block
 block discarded – undo
256 256
  */
257 257
 $_exceptions = array('id_table', 'id_base', 'id_parent', 'id_article_pdf');
258 258
 foreach ($_GET as $var => $val) {
259
-	if (
260
-		$_GET[$var] and strncmp($var, "id_", 3) == 0
261
-		and !in_array($var, $_exceptions)
262
-	) {
263
-		$_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]);
264
-	}
259
+    if (
260
+        $_GET[$var] and strncmp($var, "id_", 3) == 0
261
+        and !in_array($var, $_exceptions)
262
+    ) {
263
+        $_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]);
264
+    }
265 265
 }
266 266
 foreach ($_POST as $var => $val) {
267
-	if (
268
-		$_POST[$var] and strncmp($var, "id_", 3) == 0
269
-		and !in_array($var, $_exceptions)
270
-	) {
271
-		$_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]);
272
-	}
267
+    if (
268
+        $_POST[$var] and strncmp($var, "id_", 3) == 0
269
+        and !in_array($var, $_exceptions)
270
+    ) {
271
+        $_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]);
272
+    }
273 273
 }
274 274
 foreach ($GLOBALS as $var => $val) {
275
-	if (
276
-		$GLOBALS[$var] and strncmp($var, "id_", 3) == 0
277
-		and !in_array($var, $_exceptions)
278
-	) {
279
-		$GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]);
280
-	}
275
+    if (
276
+        $GLOBALS[$var] and strncmp($var, "id_", 3) == 0
277
+        and !in_array($var, $_exceptions)
278
+    ) {
279
+        $GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]);
280
+    }
281 281
 }
282 282
 
283 283
 /*
@@ -290,116 +290,116 @@  discard block
 block discarded – undo
290 290
  * Contrôle de quelques variables (XSS)
291 291
  */
292 292
 foreach (array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) {
293
-	if (isset($_GET[$var])) {
294
-		$_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
295
-	}
296
-	if (isset($_POST[$var])) {
297
-		$_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
298
-	}
293
+    if (isset($_GET[$var])) {
294
+        $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]);
295
+    }
296
+    if (isset($_POST[$var])) {
297
+        $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]);
298
+    }
299 299
 }
300 300
 
301 301
 /*
302 302
  * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x)
303 303
  */
304 304
 if (isset($_SERVER['REQUEST_URI'])) {
305
-	if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) {
306
-		$file = addslashes((string)$_GET['file']);
307
-	}
305
+    if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) {
306
+        $file = addslashes((string)$_GET['file']);
307
+    }
308 308
 }
309 309
 
310 310
 /*
311 311
  * Pas d'inscription abusive
312 312
  */
313 313
 if (
314
-	isset($_REQUEST['mode']) and isset($_REQUEST['page'])
315
-	and !in_array($_REQUEST['mode'], array("6forum", "1comite"))
316
-	and $_REQUEST['page'] == "identifiants"
314
+    isset($_REQUEST['mode']) and isset($_REQUEST['page'])
315
+    and !in_array($_REQUEST['mode'], array("6forum", "1comite"))
316
+    and $_REQUEST['page'] == "identifiants"
317 317
 ) {
318
-	$ecran_securite_raison = "identifiants";
318
+    $ecran_securite_raison = "identifiants";
319 319
 }
320 320
 
321 321
 /*
322 322
  * Agenda joue à l'injection php
323 323
  */
324 324
 if (
325
-	isset($_REQUEST['partie_cal'])
326
-	and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])
325
+    isset($_REQUEST['partie_cal'])
326
+    and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal'])
327 327
 ) {
328
-	$ecran_securite_raison = "partie_cal";
328
+    $ecran_securite_raison = "partie_cal";
329 329
 }
330 330
 if (
331
-	isset($_REQUEST['echelle'])
332
-	and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])
331
+    isset($_REQUEST['echelle'])
332
+    and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle'])
333 333
 ) {
334
-	$ecran_securite_raison = "echelle";
334
+    $ecran_securite_raison = "echelle";
335 335
 }
336 336
 
337 337
 /*
338 338
  * Espace privé
339 339
  */
340 340
 if (
341
-	isset($_REQUEST['exec'])
342
-	and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])
341
+    isset($_REQUEST['exec'])
342
+    and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec'])
343 343
 ) {
344
-	$ecran_securite_raison = "exec";
344
+    $ecran_securite_raison = "exec";
345 345
 }
346 346
 if (
347
-	isset($_REQUEST['cherche_auteur'])
348
-	and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])
347
+    isset($_REQUEST['cherche_auteur'])
348
+    and preg_match(',[<],', (string)$_REQUEST['cherche_auteur'])
349 349
 ) {
350
-	$ecran_securite_raison = "cherche_auteur";
350
+    $ecran_securite_raison = "cherche_auteur";
351 351
 }
352 352
 if (
353
-	isset($_REQUEST['exec'])
354
-	and $_REQUEST['exec'] == 'auteurs'
355
-	and isset($_REQUEST['recherche'])
356
-	and preg_match(',[<],', (string)$_REQUEST['recherche'])
353
+    isset($_REQUEST['exec'])
354
+    and $_REQUEST['exec'] == 'auteurs'
355
+    and isset($_REQUEST['recherche'])
356
+    and preg_match(',[<],', (string)$_REQUEST['recherche'])
357 357
 ) {
358
-	$ecran_securite_raison = "recherche";
358
+    $ecran_securite_raison = "recherche";
359 359
 }
360 360
 if (
361
-	isset($_REQUEST['exec'])
362
-	and $_REQUEST['exec'] == 'info_plugin'
363
-	and isset($_REQUEST['plugin'])
364
-	and preg_match(',[<],', (string)$_REQUEST['plugin'])
361
+    isset($_REQUEST['exec'])
362
+    and $_REQUEST['exec'] == 'info_plugin'
363
+    and isset($_REQUEST['plugin'])
364
+    and preg_match(',[<],', (string)$_REQUEST['plugin'])
365 365
 ) {
366
-	$ecran_securite_raison = "plugin";
366
+    $ecran_securite_raison = "plugin";
367 367
 }
368 368
 if (
369
-	isset($_REQUEST['exec'])
370
-	and $_REQUEST['exec'] == 'puce_statut'
371
-	and isset($_REQUEST['id'])
372
-	and !intval($_REQUEST['id'])
369
+    isset($_REQUEST['exec'])
370
+    and $_REQUEST['exec'] == 'puce_statut'
371
+    and isset($_REQUEST['id'])
372
+    and !intval($_REQUEST['id'])
373 373
 ) {
374
-	$ecran_securite_raison = "puce_statut";
374
+    $ecran_securite_raison = "puce_statut";
375 375
 }
376 376
 if (
377
-	isset($_REQUEST['action'])
378
-	and $_REQUEST['action'] == 'configurer'
377
+    isset($_REQUEST['action'])
378
+    and $_REQUEST['action'] == 'configurer'
379 379
 ) {
380
-	if (
381
-		@file_exists('inc_version.php')
382
-		or @file_exists('ecrire/inc_version.php')
383
-	) {
384
-		function action_configurer() {
385
-			include_spip('inc/autoriser');
386
-			if (!autoriser('configurer', _request('configuration'))) {
387
-				include_spip('inc/minipres');
388
-				echo minipres(_T('info_acces_interdit'));
389
-				exit;
390
-			}
391
-			require _DIR_RESTREINT . 'action/configurer.php';
392
-			action_configurer_dist();
393
-		}
394
-	}
380
+    if (
381
+        @file_exists('inc_version.php')
382
+        or @file_exists('ecrire/inc_version.php')
383
+    ) {
384
+        function action_configurer() {
385
+            include_spip('inc/autoriser');
386
+            if (!autoriser('configurer', _request('configuration'))) {
387
+                include_spip('inc/minipres');
388
+                echo minipres(_T('info_acces_interdit'));
389
+                exit;
390
+            }
391
+            require _DIR_RESTREINT . 'action/configurer.php';
392
+            action_configurer_dist();
393
+        }
394
+    }
395 395
 }
396 396
 if (
397
-	isset($_REQUEST['action'])
398
-	and $_REQUEST['action'] == 'ordonner_liens_documents'
399
-	and isset($_REQUEST['ordre'])
400
-	and is_string($_REQUEST['ordre'])
397
+    isset($_REQUEST['action'])
398
+    and $_REQUEST['action'] == 'ordonner_liens_documents'
399
+    and isset($_REQUEST['ordre'])
400
+    and is_string($_REQUEST['ordre'])
401 401
 ) {
402
-	$ecran_securite_raison = "ordre a la chaine";
402
+    $ecran_securite_raison = "ordre a la chaine";
403 403
 }
404 404
 
405 405
 
@@ -407,29 +407,29 @@  discard block
 block discarded – undo
407 407
  * Bloque les requêtes contenant %00 (manipulation d'include)
408 408
  */
409 409
 if (strpos(
410
-	(function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc())
411
-		? stripslashes(serialize($_REQUEST))
412
-		: serialize($_REQUEST),
413
-	chr(0)
410
+    (function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc())
411
+        ? stripslashes(serialize($_REQUEST))
412
+        : serialize($_REQUEST),
413
+    chr(0)
414 414
 ) !== false) {
415
-	$ecran_securite_raison = "%00";
415
+    $ecran_securite_raison = "%00";
416 416
 }
417 417
 
418 418
 /*
419 419
  * Bloque les requêtes fond=formulaire_
420 420
  */
421 421
 if (
422
-	isset($_REQUEST['fond'])
423
-	and preg_match(',^formulaire_,i', $_REQUEST['fond'])
422
+    isset($_REQUEST['fond'])
423
+    and preg_match(',^formulaire_,i', $_REQUEST['fond'])
424 424
 ) {
425
-	$ecran_securite_raison = "fond=formulaire_";
425
+    $ecran_securite_raison = "fond=formulaire_";
426 426
 }
427 427
 
428 428
 /*
429 429
  * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php)
430 430
  */
431 431
 if (isset($_REQUEST['GLOBALS'])) {
432
-	$ecran_securite_raison = "GLOBALS[GLOBALS]";
432
+    $ecran_securite_raison = "GLOBALS[GLOBALS]";
433 433
 }
434 434
 
435 435
 /*
@@ -438,14 +438,14 @@  discard block
 block discarded – undo
438 438
  * les paginations entremélées
439 439
  */
440 440
 if (_IS_BOT) {
441
-	if (
442
-		(isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type']))
443
-		or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI']))
444
-		or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_'))
445
-		or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI']))
446
-	) {
447
-		$ecran_securite_raison = "robot agenda/double pagination";
448
-	}
441
+    if (
442
+        (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type']))
443
+        or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI']))
444
+        or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_'))
445
+        or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI']))
446
+    ) {
447
+        $ecran_securite_raison = "robot agenda/double pagination";
448
+    }
449 449
 }
450 450
 
451 451
 /*
@@ -453,82 +453,82 @@  discard block
 block discarded – undo
453 453
  * Bloque un XSS sur une page inexistante
454 454
  */
455 455
 if (isset($_REQUEST['page'])) {
456
-	if ($_REQUEST['page'] == 'test_cfg') {
457
-		$ecran_securite_raison = "test_cfg";
458
-	}
459
-	if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) {
460
-		$ecran_securite_raison = "xsspage";
461
-	}
462
-	if (
463
-		$_REQUEST['page'] == '404'
464
-		and isset($_REQUEST['erreur'])
465
-	) {
466
-		$ecran_securite_raison = "xss404";
467
-	}
456
+    if ($_REQUEST['page'] == 'test_cfg') {
457
+        $ecran_securite_raison = "test_cfg";
458
+    }
459
+    if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) {
460
+        $ecran_securite_raison = "xsspage";
461
+    }
462
+    if (
463
+        $_REQUEST['page'] == '404'
464
+        and isset($_REQUEST['erreur'])
465
+    ) {
466
+        $ecran_securite_raison = "xss404";
467
+    }
468 468
 }
469 469
 
470 470
 /*
471 471
  * XSS par array
472 472
  */
473 473
 foreach (array('var_login') as $var) {
474
-	if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) {
475
-		$ecran_securite_raison = "xss " . $var;
476
-	}
474
+    if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) {
475
+        $ecran_securite_raison = "xss " . $var;
476
+    }
477 477
 }
478 478
 
479 479
 /*
480 480
  * Parade antivirale contre un cheval de troie
481 481
  */
482 482
 if (!function_exists('tmp_lkojfghx')) {
483
-	function tmp_lkojfghx() {}
484
-	function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) {
485
-		// si jamais on est arrivé ici sur une erreur php
486
-		// et qu'un autre gestionnaire d'erreur est défini, l'appeller
487
-		if ($b && $GLOBALS['tmp_xhgfjokl']) {
488
-			call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
489
-		}
490
-	}
483
+    function tmp_lkojfghx() {}
484
+    function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) {
485
+        // si jamais on est arrivé ici sur une erreur php
486
+        // et qu'un autre gestionnaire d'erreur est défini, l'appeller
487
+        if ($b && $GLOBALS['tmp_xhgfjokl']) {
488
+            call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d);
489
+        }
490
+    }
491 491
 }
492 492
 if (isset($_POST['tmp_lkojfghx3'])) {
493
-	$ecran_securite_raison = "gumblar";
493
+    $ecran_securite_raison = "gumblar";
494 494
 }
495 495
 
496 496
 /*
497 497
  * Outils XML mal sécurisés < 2.0.9
498 498
  */
499 499
 if (isset($_REQUEST['transformer_xml'])) {
500
-	$ecran_securite_raison = "transformer_xml";
500
+    $ecran_securite_raison = "transformer_xml";
501 501
 }
502 502
 
503 503
 /*
504 504
  * Outils XML mal sécurisés again
505 505
  */
506 506
 if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec'] == 'valider_xml') {
507
-	$url = trim($_REQUEST['var_url']);
508
-	if (
509
-		strncmp($url, '/', 1) == 0
510
-		or (($p = strpos($url, '..')) !== false and strpos($url, '..', $p + 3) !== false)
511
-		or (($p = strpos($url, '..')) !== false and strpos($url, 'IMG', $p + 3) !== false)
512
-		or (strpos($url, '://') !== false or strpos($url, ':\\') !== false)
513
-	) {
514
-		$ecran_securite_raison = 'URL interdite pour var_url';
515
-	}
507
+    $url = trim($_REQUEST['var_url']);
508
+    if (
509
+        strncmp($url, '/', 1) == 0
510
+        or (($p = strpos($url, '..')) !== false and strpos($url, '..', $p + 3) !== false)
511
+        or (($p = strpos($url, '..')) !== false and strpos($url, 'IMG', $p + 3) !== false)
512
+        or (strpos($url, '://') !== false or strpos($url, ':\\') !== false)
513
+    ) {
514
+        $ecran_securite_raison = 'URL interdite pour var_url';
515
+    }
516 516
 }
517 517
 
518 518
 /*
519 519
  * Sauvegarde mal securisée < 2.0.9
520 520
  */
521 521
 if (
522
-	isset($_REQUEST['nom_sauvegarde'])
523
-	and strstr((string)$_REQUEST['nom_sauvegarde'], '/')
522
+    isset($_REQUEST['nom_sauvegarde'])
523
+    and strstr((string)$_REQUEST['nom_sauvegarde'], '/')
524 524
 ) {
525
-	$ecran_securite_raison = 'nom_sauvegarde manipulee';
525
+    $ecran_securite_raison = 'nom_sauvegarde manipulee';
526 526
 }
527 527
 if (
528
-	isset($_REQUEST['znom_sauvegarde'])
529
-	and strstr((string)$_REQUEST['znom_sauvegarde'], '/')
528
+    isset($_REQUEST['znom_sauvegarde'])
529
+    and strstr((string)$_REQUEST['znom_sauvegarde'], '/')
530 530
 ) {
531
-	$ecran_securite_raison = 'znom_sauvegarde manipulee';
531
+    $ecran_securite_raison = 'znom_sauvegarde manipulee';
532 532
 }
533 533
 
534 534
 
@@ -537,57 +537,57 @@  discard block
 block discarded – undo
537 537
  * on vérifie 'page' pour ne pas bloquer ... drupal
538 538
  */
539 539
 if (
540
-	isset($_REQUEST['op']) and isset($_REQUEST['page'])
541
-	and $_REQUEST['op'] !== preg_replace('/[^\\-\w]/', '', $_REQUEST['op'])
540
+    isset($_REQUEST['op']) and isset($_REQUEST['page'])
541
+    and $_REQUEST['op'] !== preg_replace('/[^\\-\w]/', '', $_REQUEST['op'])
542 542
 ) {
543
-	$ecran_securite_raison = 'op';
543
+    $ecran_securite_raison = 'op';
544 544
 }
545 545
 
546 546
 /*
547 547
  * Forms & Table ne se méfiait pas assez des uploads de fichiers
548 548
  */
549 549
 if (count($_FILES)) {
550
-	foreach ($_FILES as $k => $v) {
551
-		if (
552
-			preg_match(',^fichier_\d+$,', $k)
553
-			and preg_match(',\.php,i', $v['name'])
554
-		) {
555
-			unset($_FILES[$k]);
556
-		}
557
-	}
550
+    foreach ($_FILES as $k => $v) {
551
+        if (
552
+            preg_match(',^fichier_\d+$,', $k)
553
+            and preg_match(',\.php,i', $v['name'])
554
+        ) {
555
+            unset($_FILES[$k]);
556
+        }
557
+    }
558 558
 }
559 559
 /*
560 560
  * et Contact trop laxiste avec une variable externe
561 561
  * on bloque pas le post pour eviter de perdre des donnees mais on unset la variable et c'est tout
562 562
  */
563 563
 if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']) {
564
-	unset($_REQUEST['pj_enregistrees_nom']);
565
-	unset($_GET['pj_enregistrees_nom']);
566
-	unset($_POST['pj_enregistrees_nom']);
564
+    unset($_REQUEST['pj_enregistrees_nom']);
565
+    unset($_GET['pj_enregistrees_nom']);
566
+    unset($_POST['pj_enregistrees_nom']);
567 567
 }
568 568
 
569 569
 /*
570 570
  * reinstall=oui un peu trop permissif
571 571
  */
572 572
 if (
573
-	isset($_REQUEST['reinstall'])
574
-	and $_REQUEST['reinstall'] == 'oui'
573
+    isset($_REQUEST['reinstall'])
574
+    and $_REQUEST['reinstall'] == 'oui'
575 575
 ) {
576
-	$ecran_securite_raison = 'reinstall=oui';
576
+    $ecran_securite_raison = 'reinstall=oui';
577 577
 }
578 578
 
579 579
 /*
580 580
  * Pas d'action pendant l'install
581 581
  */
582 582
 if (isset($_REQUEST['exec']) and $_REQUEST['exec'] === 'install' and isset($_REQUEST['action'])) {
583
-	$ecran_securite_raison = 'install&action impossibles';
583
+    $ecran_securite_raison = 'install&action impossibles';
584 584
 }
585 585
 
586 586
 /*
587 587
  * Échappement xss referer
588 588
  */
589 589
 if (isset($_SERVER['HTTP_REFERER'])) {
590
-	$_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##');
590
+    $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##');
591 591
 }
592 592
 
593 593
 
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
  * Echappement HTTP_X_FORWARDED_HOST
596 596
  */
597 597
 if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
598
-	$_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________');
598
+    $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________');
599 599
 }
600 600
 
601 601
 
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
  * Pas d'erreur dans l'erreur
604 604
  */
605 605
 if (isset($_REQUEST['var_erreur']) and isset($_REQUEST['page']) and $_REQUEST['page'] === 'login') {
606
-	if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>')) {
607
-		$ecran_securite_raison = 'var_erreur incorrecte';
608
-	}
606
+    if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>')) {
607
+        $ecran_securite_raison = 'var_erreur incorrecte';
608
+    }
609 609
 }
610 610
 
611 611
 
@@ -613,53 +613,53 @@  discard block
 block discarded – undo
613 613
  * Réinjection des clés en html dans l'admin r19561
614 614
  */
615 615
 if (
616
-	(isset($_SERVER['REQUEST_URI']) and strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false)
617
-	or isset($_REQUEST['var_memotri'])
616
+    (isset($_SERVER['REQUEST_URI']) and strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false)
617
+    or isset($_REQUEST['var_memotri'])
618 618
 ) {
619
-	$zzzz = implode("", array_keys($_REQUEST));
620
-	if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) {
621
-		$ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
622
-	}
619
+    $zzzz = implode("", array_keys($_REQUEST));
620
+    if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) {
621
+        $ecran_securite_raison = 'Cle incorrecte en $_REQUEST';
622
+    }
623 623
 }
624 624
 
625 625
 /*
626 626
  * Injection par connect
627 627
  */
628 628
 if (
629
-	isset($_REQUEST['connect'])
630
-	// cas qui permettent de sortir d'un commentaire PHP
631
-	and (
632
-		strpos($_REQUEST['connect'], "?") !== false
633
-		or strpos($_REQUEST['connect'], "<") !== false
634
-		or strpos($_REQUEST['connect'], ">") !== false
635
-		or strpos($_REQUEST['connect'], "\n") !== false
636
-		or strpos($_REQUEST['connect'], "\r") !== false
637
-	)
629
+    isset($_REQUEST['connect'])
630
+    // cas qui permettent de sortir d'un commentaire PHP
631
+    and (
632
+        strpos($_REQUEST['connect'], "?") !== false
633
+        or strpos($_REQUEST['connect'], "<") !== false
634
+        or strpos($_REQUEST['connect'], ">") !== false
635
+        or strpos($_REQUEST['connect'], "\n") !== false
636
+        or strpos($_REQUEST['connect'], "\r") !== false
637
+    )
638 638
 ) {
639
-	$ecran_securite_raison = "malformed connect argument";
639
+    $ecran_securite_raison = "malformed connect argument";
640 640
 }
641 641
 
642 642
 /*
643 643
  * S'il y a une raison de mourir, mourons
644 644
  */
645 645
 if (isset($ecran_securite_raison)) {
646
-	header("HTTP/1.0 403 Forbidden");
647
-	header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
648
-	header("Cache-Control: no-cache, must-revalidate");
649
-	header("Pragma: no-cache");
650
-	header("Content-Type: text/html");
651
-	header("Connection: close");
652
-	die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>");
646
+    header("HTTP/1.0 403 Forbidden");
647
+    header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
648
+    header("Cache-Control: no-cache, must-revalidate");
649
+    header("Pragma: no-cache");
650
+    header("Content-Type: text/html");
651
+    header("Connection: close");
652
+    die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>");
653 653
 }
654 654
 
655 655
 /*
656 656
  * Un filtre filtrer_entites securise
657 657
  */
658 658
 if (!function_exists('filtre_filtrer_entites_dist')) {
659
-	function filtre_filtrer_entites_dist($t) {
660
-		include_spip('inc/texte');
661
-		return interdire_scripts(filtrer_entites($t));
662
-	}
659
+    function filtre_filtrer_entites_dist($t) {
660
+        include_spip('inc/texte');
661
+        return interdire_scripts(filtrer_entites($t));
662
+    }
663 663
 }
664 664
 
665 665
 
@@ -673,35 +673,35 @@  discard block
 block discarded – undo
673 673
  * Bloque les bots quand le load déborde
674 674
  */
675 675
 if (!defined('_ECRAN_SECURITE_LOAD')) {
676
-	define('_ECRAN_SECURITE_LOAD', 4);
676
+    define('_ECRAN_SECURITE_LOAD', 4);
677 677
 }
678 678
 
679 679
 if (
680
-	defined('_ECRAN_SECURITE_LOAD')
681
-	and _ECRAN_SECURITE_LOAD > 0
682
-	and _IS_BOT
683
-	and !_IS_BOT_FRIEND
684
-	and $_SERVER['REQUEST_METHOD'] === 'GET'
685
-	and (
686
-		(function_exists('sys_getloadavg')
687
-			and $load = sys_getloadavg()
688
-			and is_array($load)
689
-			and $load = array_shift($load))
690
-		or
691
-		(@is_readable('/proc/loadavg')
692
-			and $load = file_get_contents('/proc/loadavg')
693
-			and $load = floatval($load))
694
-	)
695
-	and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite
696
-	and random_int(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD
680
+    defined('_ECRAN_SECURITE_LOAD')
681
+    and _ECRAN_SECURITE_LOAD > 0
682
+    and _IS_BOT
683
+    and !_IS_BOT_FRIEND
684
+    and $_SERVER['REQUEST_METHOD'] === 'GET'
685
+    and (
686
+        (function_exists('sys_getloadavg')
687
+            and $load = sys_getloadavg()
688
+            and is_array($load)
689
+            and $load = array_shift($load))
690
+        or
691
+        (@is_readable('/proc/loadavg')
692
+            and $load = file_get_contents('/proc/loadavg')
693
+            and $load = floatval($load))
694
+    )
695
+    and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite
696
+    and random_int(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD
697 697
 ) {
698
-	//https://webmasters.stackexchange.com/questions/65674/should-i-return-a-429-or-503-status-code-to-a-bot
699
-	header("HTTP/1.0 429 Too Many Requests");
700
-	header("Retry-After: 300");
701
-	header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
702
-	header("Cache-Control: no-cache, must-revalidate");
703
-	header("Pragma: no-cache");
704
-	header("Content-Type: text/html");
705
-	header("Connection: close");
706
-	die("<html><title>Status 429: Too Many Requests</title><body><h1>Status 429</h1><p>Too Many Requests (try again soon)</p></body></html>");
698
+    //https://webmasters.stackexchange.com/questions/65674/should-i-return-a-429-or-503-status-code-to-a-bot
699
+    header("HTTP/1.0 429 Too Many Requests");
700
+    header("Retry-After: 300");
701
+    header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
702
+    header("Cache-Control: no-cache, must-revalidate");
703
+    header("Pragma: no-cache");
704
+    header("Content-Type: text/html");
705
+    header("Connection: close");
706
+    die("<html><title>Status 429: Too Many Requests</title><body><h1>Status 429</h1><p>Too Many Requests (try again soon)</p></body></html>");
707 707
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 2 patches
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  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('_DATA_SOURCE_MAX_SIZE')) {
24
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
24
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
25 25
 }
26 26
 
27 27
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
  *     Description de la boucle complétée des champs
43 43
  */
44 44
 function iterateur_DATA_dist($b) {
45
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
46
-	$b->show = [
47
-		'field' => [
48
-			'cle' => 'STRING',
49
-			'valeur' => 'STRING',
50
-			'*' => 'ALL' // Champ joker *
51
-		]
52
-	];
53
-	$b->select[] = '.valeur';
54
-
55
-	return $b;
45
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
46
+    $b->show = [
47
+        'field' => [
48
+            'cle' => 'STRING',
49
+            'valeur' => 'STRING',
50
+            '*' => 'ALL' // Champ joker *
51
+        ]
52
+    ];
53
+    $b->select[] = '.valeur';
54
+
55
+    return $b;
56 56
 }
57 57
 
58 58
 
@@ -62,522 +62,522 @@  discard block
 block discarded – undo
62 62
  * Pour itérer sur des données quelconques (transformables en tableau)
63 63
  */
64 64
 class IterateurDATA implements Iterator {
65
-	/**
66
-	 * tableau de donnees
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $tableau = [];
71
-
72
-	/**
73
-	 * Conditions de filtrage
74
-	 * ie criteres de selection
75
-	 *
76
-	 * @var array
77
-	 */
78
-	protected $filtre = [];
79
-
80
-
81
-	/**
82
-	 * Cle courante
83
-	 *
84
-	 * @var null
85
-	 */
86
-	protected $cle = null;
87
-
88
-	/**
89
-	 * Valeur courante
90
-	 *
91
-	 * @var null
92
-	 */
93
-	protected $valeur = null;
94
-
95
-	/**
96
-	 * Erreur presente ?
97
-	 *
98
-	 * @var bool
99
-	 **/
100
-	public $err = false;
101
-
102
-	/**
103
-	 * Calcul du total des elements
104
-	 *
105
-	 * @var int|null
106
-	 **/
107
-	public $total = null;
108
-
109
-	/**
110
-	 * Constructeur
111
-	 *
112
-	 * @param  $command
113
-	 * @param array $info
114
-	 */
115
-	public function __construct($command, $info = []) {
116
-		$this->type = 'DATA';
117
-		$this->command = $command;
118
-		$this->info = $info;
119
-
120
-		$this->select($command);
121
-	}
122
-
123
-	/**
124
-	 * Revenir au depart
125
-	 *
126
-	 * @return void
127
-	 */
128
-	public function rewind() : void {
129
-		reset($this->tableau);
130
-		$this->cle = array_key_first($this->tableau);
131
-		$this->valeur = current($this->tableau);
132
-		next($this->tableau);
133
-	}
134
-
135
-	/**
136
-	 * Déclarer les critères exceptions
137
-	 *
138
-	 * @return array
139
-	 */
140
-	public function exception_des_criteres() {
141
-		return ['tableau'];
142
-	}
143
-
144
-	/**
145
-	 * Récupérer depuis le cache si possible
146
-	 *
147
-	 * @param string $cle
148
-	 * @return mixed
149
-	 */
150
-	protected function cache_get($cle) {
151
-		if (!$cle) {
152
-			return;
153
-		}
154
-		# utiliser memoization si dispo
155
-		if (!function_exists('cache_get')) {
156
-			return;
157
-		}
158
-
159
-		return cache_get($cle);
160
-	}
161
-
162
-	/**
163
-	 * Stocker en cache si possible
164
-	 *
165
-	 * @param string $cle
166
-	 * @param int $ttl
167
-	 * @param null|mixed $valeur
168
-	 * @return bool
169
-	 */
170
-	protected function cache_set($cle, $ttl, $valeur = null) {
171
-		if (!$cle) {
172
-			return;
173
-		}
174
-		if (is_null($valeur)) {
175
-			$valeur = $this->tableau;
176
-		}
177
-		# utiliser memoization si dispo
178
-		if (!function_exists('cache_set')) {
179
-			return;
180
-		}
181
-
182
-		return cache_set(
183
-			$cle,
184
-			[
185
-				'data' => $valeur,
186
-				'time' => time(),
187
-				'ttl' => $ttl
188
-			],
189
-			3600 + $ttl
190
-		);
191
-		# conserver le cache 1h de plus que la validite demandee,
192
-		# pour le cas ou le serveur distant ne reponde plus
193
-	}
194
-
195
-	/**
196
-	 * Aller chercher les données de la boucle DATA
197
-	 *
198
-	 * @throws Exception
199
-	 * @param array $command
200
-	 * @return void
201
-	 */
202
-	protected function select($command) {
203
-
204
-		// l'iterateur DATA peut etre appele en passant (data:type)
205
-		// le type se retrouve dans la commande 'from'
206
-		// dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
207
-		if (isset($this->command['from'][0])) {
208
-			if (isset($this->command['source']) and is_array($this->command['source'])) {
209
-				array_unshift($this->command['source'], $this->command['sourcemode']);
210
-			}
211
-			$this->command['sourcemode'] = $this->command['from'][0];
212
-		}
213
-
214
-		// cherchons differents moyens de creer le tableau de donnees
215
-		// les commandes connues pour l'iterateur DATA
216
-		// sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
217
-
218
-		// {source format, [URL], [arg2]...}
219
-		if (
220
-			isset($this->command['source'])
221
-			and isset($this->command['sourcemode'])
222
-		) {
223
-			$this->select_source();
224
-		}
225
-
226
-		// Critere {liste X1, X2, X3}
227
-		if (isset($this->command['liste'])) {
228
-			$this->select_liste();
229
-		}
230
-		if (isset($this->command['enum'])) {
231
-			$this->select_enum();
232
-		}
233
-
234
-		// Si a ce stade on n'a pas de table, il y a un bug
235
-		if (!is_array($this->tableau)) {
236
-			$this->err = true;
237
-			spip_log('erreur datasource ' . var_export($command, true));
238
-		}
239
-
240
-		// {datapath query.results}
241
-		// extraire le chemin "query.results" du tableau de donnees
242
-		if (
243
-			!$this->err
244
-			and isset($this->command['datapath'])
245
-			and is_array($this->command['datapath'])
246
-		) {
247
-			$this->select_datapath();
248
-		}
249
-
250
-		// tri {par x}
251
-		if ($this->command['orderby']) {
252
-			$this->select_orderby();
253
-		}
254
-
255
-		// grouper les resultats {fusion /x/y/z} ;
256
-		if ($this->command['groupby']) {
257
-			$this->select_groupby();
258
-		}
259
-
260
-		$this->rewind();
261
-		#var_dump($this->tableau);
262
-	}
263
-
264
-
265
-	/**
266
-	 * Aller chercher les donnees de la boucle DATA
267
-	 * depuis une source
268
-	 * {source format, [URL], [arg2]...}
269
-	 */
270
-	protected function select_source() {
271
-		# un peu crado : avant de charger le cache il faut charger
272
-		# les class indispensables, sinon PHP ne saura pas gerer
273
-		# l'objet en cache ; cf plugins/icalendar
274
-		# perf : pas de fonction table_to_array ! (table est deja un array)
275
-		if (
276
-			isset($this->command['sourcemode'])
277
-			and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278
-		) {
279
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
280
-		}
281
-
282
-		# le premier argument peut etre un array, une URL etc.
283
-		$src = $this->command['source'][0];
284
-
285
-		# avons-nous un cache dispo ?
286
-		$cle = null;
287
-		if (is_string($src)) {
288
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
289
-		}
290
-
291
-		$cache = $this->cache_get($cle);
292
-		if (isset($this->command['datacache'])) {
293
-			$ttl = intval($this->command['datacache']);
294
-		}
295
-		if (
296
-			$cache
297
-			and ($cache['time'] + ($ttl ?? $cache['ttl'])
298
-				> time())
299
-			and !(_request('var_mode') === 'recalcul'
300
-				and include_spip('inc/autoriser')
301
-				and autoriser('recalcul')
302
-			)
303
-		) {
304
-			$this->tableau = $cache['data'];
305
-		} else {
306
-			try {
307
-				if (
308
-					isset($this->command['sourcemode'])
309
-					and in_array(
310
-						$this->command['sourcemode'],
311
-						['table', 'array', 'tableau']
312
-					)
313
-				) {
314
-					if (
315
-						is_array($a = $src)
316
-						or (is_string($a)
317
-							and $a = str_replace('&quot;', '"', $a) # fragile!
318
-							and is_array($a = @unserialize($a)))
319
-					) {
320
-						$this->tableau = $a;
321
-					}
322
-				} else {
323
-					$data = $src;
324
-					if (is_string($src)) {
325
-						if (tester_url_absolue($src)) {
326
-							include_spip('inc/distant');
327
-							$data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
328
-							$data = $data['page'] ?? '';
329
-							if (!$data) {
330
-								throw new Exception('404');
331
-							}
332
-							if (!isset($ttl)) {
333
-								$ttl = 24 * 3600;
334
-							}
335
-						} elseif (@is_dir($src)) {
336
-							$data = $src;
337
-						} elseif (@is_readable($src) && @is_file($src)) {
338
-							$data = spip_file_get_contents($src);
339
-						}
340
-						if (!isset($ttl)) {
341
-							$ttl = 10;
342
-						}
343
-					}
344
-
345
-					if (
346
-						!$this->err
347
-						and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
348
-					) {
349
-						$args = $this->command['source'];
350
-						$args[0] = $data;
351
-						if (is_array($a = $data_to_array(...$args))) {
352
-							$this->tableau = $a;
353
-						}
354
-					}
355
-				}
356
-
357
-				if (!is_array($this->tableau)) {
358
-					$this->err = true;
359
-				}
360
-
361
-				if (!$this->err and isset($ttl) and $ttl > 0) {
362
-					$this->cache_set($cle, $ttl);
363
-				}
364
-			} catch (Exception $e) {
365
-				$e = $e->getMessage();
366
-				$err = sprintf(
367
-					"[%s, %s] $e",
368
-					$src,
369
-					$this->command['sourcemode']
370
-				);
371
-				erreur_squelette([$err, []]);
372
-				$this->err = true;
373
-			}
374
-		}
375
-
376
-		# en cas d'erreur, utiliser le cache si encore dispo
377
-		if (
378
-			$this->err
379
-			and $cache
380
-		) {
381
-			$this->tableau = $cache['data'];
382
-			$this->err = false;
383
-		}
384
-	}
385
-
386
-
387
-	/**
388
-	 * Retourne un tableau donne depuis un critère liste
389
-	 *
390
-	 * Critère `{liste X1, X2, X3}`
391
-	 *
392
-	 * @see critere_DATA_liste_dist()
393
-	 *
394
-	 **/
395
-	protected function select_liste() {
396
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
397
-		if (!isset($this->command['liste'][1])) {
398
-			if (!is_array($this->command['liste'][0])) {
399
-				$this->command['liste'] = explode(',', $this->command['liste'][0]);
400
-			} else {
401
-				$this->command['liste'] = $this->command['liste'][0];
402
-			}
403
-		}
404
-		$this->tableau = $this->command['liste'];
405
-	}
406
-
407
-	/**
408
-	 * Retourne un tableau donne depuis un critere liste
409
-	 * Critere {enum Xmin, Xmax}
410
-	 *
411
-	 **/
412
-	protected function select_enum() {
413
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
414
-		if (!isset($this->command['enum'][1])) {
415
-			if (!is_array($this->command['enum'][0])) {
416
-				$this->command['enum'] = explode(',', $this->command['enum'][0]);
417
-			} else {
418
-				$this->command['enum'] = $this->command['enum'][0];
419
-			}
420
-		}
421
-		if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) {
422
-			$enum = range(
423
-				array_shift($this->command['enum']),
424
-				array_shift($this->command['enum']),
425
-				array_shift($this->command['enum'])
426
-			);
427
-		} else {
428
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
429
-		}
430
-		$this->tableau = $enum;
431
-	}
432
-
433
-
434
-	/**
435
-	 * extraire le chemin "query.results" du tableau de donnees
436
-	 * {datapath query.results}
437
-	 *
438
-	 **/
439
-	protected function select_datapath() {
440
-		$base = reset($this->command['datapath']);
441
-		if (strlen($base = ltrim(trim($base), '/'))) {
442
-			$this->tableau = table_valeur($this->tableau, $base);
443
-			if (!is_array($this->tableau)) {
444
-				$this->tableau = [];
445
-				$this->err = true;
446
-				spip_log("datapath '$base' absent");
447
-			}
448
-		}
449
-	}
450
-
451
-	/**
452
-	 * Ordonner les resultats
453
-	 * {par x}
454
-	 *
455
-	 **/
456
-	protected function select_orderby() {
457
-		$sortfunc = '';
458
-		$aleas = 0;
459
-		foreach ($this->command['orderby'] as $tri) {
460
-			// virer le / initial pour les criteres de la forme {par /xx}
461
-			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
462
-				$r = array_pad($r, 3, null);
463
-
464
-				// tri par cle
465
-				if ($r[1] == 'cle') {
466
-					if (isset($r[2]) and $r[2]) {
467
-						krsort($this->tableau);
468
-					} else {
469
-						ksort($this->tableau);
470
-					}
471
-				} # {par hasard}
472
-				else {
473
-					if ($r[1] == 'hasard') {
474
-						$k = array_keys($this->tableau);
475
-						shuffle($k);
476
-						$v = [];
477
-						foreach ($k as $cle) {
478
-							$v[$cle] = $this->tableau[$cle];
479
-						}
480
-						$this->tableau = $v;
481
-					} else {
482
-						# {par valeur}
483
-						if ($r[1] == 'valeur') {
484
-							$tv = '%s';
485
-						} # {par valeur/xx/yy} ??
486
-						else {
487
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
488
-						}
489
-						$sortfunc .= '
65
+    /**
66
+     * tableau de donnees
67
+     *
68
+     * @var array
69
+     */
70
+    protected $tableau = [];
71
+
72
+    /**
73
+     * Conditions de filtrage
74
+     * ie criteres de selection
75
+     *
76
+     * @var array
77
+     */
78
+    protected $filtre = [];
79
+
80
+
81
+    /**
82
+     * Cle courante
83
+     *
84
+     * @var null
85
+     */
86
+    protected $cle = null;
87
+
88
+    /**
89
+     * Valeur courante
90
+     *
91
+     * @var null
92
+     */
93
+    protected $valeur = null;
94
+
95
+    /**
96
+     * Erreur presente ?
97
+     *
98
+     * @var bool
99
+     **/
100
+    public $err = false;
101
+
102
+    /**
103
+     * Calcul du total des elements
104
+     *
105
+     * @var int|null
106
+     **/
107
+    public $total = null;
108
+
109
+    /**
110
+     * Constructeur
111
+     *
112
+     * @param  $command
113
+     * @param array $info
114
+     */
115
+    public function __construct($command, $info = []) {
116
+        $this->type = 'DATA';
117
+        $this->command = $command;
118
+        $this->info = $info;
119
+
120
+        $this->select($command);
121
+    }
122
+
123
+    /**
124
+     * Revenir au depart
125
+     *
126
+     * @return void
127
+     */
128
+    public function rewind() : void {
129
+        reset($this->tableau);
130
+        $this->cle = array_key_first($this->tableau);
131
+        $this->valeur = current($this->tableau);
132
+        next($this->tableau);
133
+    }
134
+
135
+    /**
136
+     * Déclarer les critères exceptions
137
+     *
138
+     * @return array
139
+     */
140
+    public function exception_des_criteres() {
141
+        return ['tableau'];
142
+    }
143
+
144
+    /**
145
+     * Récupérer depuis le cache si possible
146
+     *
147
+     * @param string $cle
148
+     * @return mixed
149
+     */
150
+    protected function cache_get($cle) {
151
+        if (!$cle) {
152
+            return;
153
+        }
154
+        # utiliser memoization si dispo
155
+        if (!function_exists('cache_get')) {
156
+            return;
157
+        }
158
+
159
+        return cache_get($cle);
160
+    }
161
+
162
+    /**
163
+     * Stocker en cache si possible
164
+     *
165
+     * @param string $cle
166
+     * @param int $ttl
167
+     * @param null|mixed $valeur
168
+     * @return bool
169
+     */
170
+    protected function cache_set($cle, $ttl, $valeur = null) {
171
+        if (!$cle) {
172
+            return;
173
+        }
174
+        if (is_null($valeur)) {
175
+            $valeur = $this->tableau;
176
+        }
177
+        # utiliser memoization si dispo
178
+        if (!function_exists('cache_set')) {
179
+            return;
180
+        }
181
+
182
+        return cache_set(
183
+            $cle,
184
+            [
185
+                'data' => $valeur,
186
+                'time' => time(),
187
+                'ttl' => $ttl
188
+            ],
189
+            3600 + $ttl
190
+        );
191
+        # conserver le cache 1h de plus que la validite demandee,
192
+        # pour le cas ou le serveur distant ne reponde plus
193
+    }
194
+
195
+    /**
196
+     * Aller chercher les données de la boucle DATA
197
+     *
198
+     * @throws Exception
199
+     * @param array $command
200
+     * @return void
201
+     */
202
+    protected function select($command) {
203
+
204
+        // l'iterateur DATA peut etre appele en passant (data:type)
205
+        // le type se retrouve dans la commande 'from'
206
+        // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
207
+        if (isset($this->command['from'][0])) {
208
+            if (isset($this->command['source']) and is_array($this->command['source'])) {
209
+                array_unshift($this->command['source'], $this->command['sourcemode']);
210
+            }
211
+            $this->command['sourcemode'] = $this->command['from'][0];
212
+        }
213
+
214
+        // cherchons differents moyens de creer le tableau de donnees
215
+        // les commandes connues pour l'iterateur DATA
216
+        // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
217
+
218
+        // {source format, [URL], [arg2]...}
219
+        if (
220
+            isset($this->command['source'])
221
+            and isset($this->command['sourcemode'])
222
+        ) {
223
+            $this->select_source();
224
+        }
225
+
226
+        // Critere {liste X1, X2, X3}
227
+        if (isset($this->command['liste'])) {
228
+            $this->select_liste();
229
+        }
230
+        if (isset($this->command['enum'])) {
231
+            $this->select_enum();
232
+        }
233
+
234
+        // Si a ce stade on n'a pas de table, il y a un bug
235
+        if (!is_array($this->tableau)) {
236
+            $this->err = true;
237
+            spip_log('erreur datasource ' . var_export($command, true));
238
+        }
239
+
240
+        // {datapath query.results}
241
+        // extraire le chemin "query.results" du tableau de donnees
242
+        if (
243
+            !$this->err
244
+            and isset($this->command['datapath'])
245
+            and is_array($this->command['datapath'])
246
+        ) {
247
+            $this->select_datapath();
248
+        }
249
+
250
+        // tri {par x}
251
+        if ($this->command['orderby']) {
252
+            $this->select_orderby();
253
+        }
254
+
255
+        // grouper les resultats {fusion /x/y/z} ;
256
+        if ($this->command['groupby']) {
257
+            $this->select_groupby();
258
+        }
259
+
260
+        $this->rewind();
261
+        #var_dump($this->tableau);
262
+    }
263
+
264
+
265
+    /**
266
+     * Aller chercher les donnees de la boucle DATA
267
+     * depuis une source
268
+     * {source format, [URL], [arg2]...}
269
+     */
270
+    protected function select_source() {
271
+        # un peu crado : avant de charger le cache il faut charger
272
+        # les class indispensables, sinon PHP ne saura pas gerer
273
+        # l'objet en cache ; cf plugins/icalendar
274
+        # perf : pas de fonction table_to_array ! (table est deja un array)
275
+        if (
276
+            isset($this->command['sourcemode'])
277
+            and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278
+        ) {
279
+            charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
280
+        }
281
+
282
+        # le premier argument peut etre un array, une URL etc.
283
+        $src = $this->command['source'][0];
284
+
285
+        # avons-nous un cache dispo ?
286
+        $cle = null;
287
+        if (is_string($src)) {
288
+            $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
289
+        }
290
+
291
+        $cache = $this->cache_get($cle);
292
+        if (isset($this->command['datacache'])) {
293
+            $ttl = intval($this->command['datacache']);
294
+        }
295
+        if (
296
+            $cache
297
+            and ($cache['time'] + ($ttl ?? $cache['ttl'])
298
+                > time())
299
+            and !(_request('var_mode') === 'recalcul'
300
+                and include_spip('inc/autoriser')
301
+                and autoriser('recalcul')
302
+            )
303
+        ) {
304
+            $this->tableau = $cache['data'];
305
+        } else {
306
+            try {
307
+                if (
308
+                    isset($this->command['sourcemode'])
309
+                    and in_array(
310
+                        $this->command['sourcemode'],
311
+                        ['table', 'array', 'tableau']
312
+                    )
313
+                ) {
314
+                    if (
315
+                        is_array($a = $src)
316
+                        or (is_string($a)
317
+                            and $a = str_replace('&quot;', '"', $a) # fragile!
318
+                            and is_array($a = @unserialize($a)))
319
+                    ) {
320
+                        $this->tableau = $a;
321
+                    }
322
+                } else {
323
+                    $data = $src;
324
+                    if (is_string($src)) {
325
+                        if (tester_url_absolue($src)) {
326
+                            include_spip('inc/distant');
327
+                            $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
328
+                            $data = $data['page'] ?? '';
329
+                            if (!$data) {
330
+                                throw new Exception('404');
331
+                            }
332
+                            if (!isset($ttl)) {
333
+                                $ttl = 24 * 3600;
334
+                            }
335
+                        } elseif (@is_dir($src)) {
336
+                            $data = $src;
337
+                        } elseif (@is_readable($src) && @is_file($src)) {
338
+                            $data = spip_file_get_contents($src);
339
+                        }
340
+                        if (!isset($ttl)) {
341
+                            $ttl = 10;
342
+                        }
343
+                    }
344
+
345
+                    if (
346
+                        !$this->err
347
+                        and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
348
+                    ) {
349
+                        $args = $this->command['source'];
350
+                        $args[0] = $data;
351
+                        if (is_array($a = $data_to_array(...$args))) {
352
+                            $this->tableau = $a;
353
+                        }
354
+                    }
355
+                }
356
+
357
+                if (!is_array($this->tableau)) {
358
+                    $this->err = true;
359
+                }
360
+
361
+                if (!$this->err and isset($ttl) and $ttl > 0) {
362
+                    $this->cache_set($cle, $ttl);
363
+                }
364
+            } catch (Exception $e) {
365
+                $e = $e->getMessage();
366
+                $err = sprintf(
367
+                    "[%s, %s] $e",
368
+                    $src,
369
+                    $this->command['sourcemode']
370
+                );
371
+                erreur_squelette([$err, []]);
372
+                $this->err = true;
373
+            }
374
+        }
375
+
376
+        # en cas d'erreur, utiliser le cache si encore dispo
377
+        if (
378
+            $this->err
379
+            and $cache
380
+        ) {
381
+            $this->tableau = $cache['data'];
382
+            $this->err = false;
383
+        }
384
+    }
385
+
386
+
387
+    /**
388
+     * Retourne un tableau donne depuis un critère liste
389
+     *
390
+     * Critère `{liste X1, X2, X3}`
391
+     *
392
+     * @see critere_DATA_liste_dist()
393
+     *
394
+     **/
395
+    protected function select_liste() {
396
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
397
+        if (!isset($this->command['liste'][1])) {
398
+            if (!is_array($this->command['liste'][0])) {
399
+                $this->command['liste'] = explode(',', $this->command['liste'][0]);
400
+            } else {
401
+                $this->command['liste'] = $this->command['liste'][0];
402
+            }
403
+        }
404
+        $this->tableau = $this->command['liste'];
405
+    }
406
+
407
+    /**
408
+     * Retourne un tableau donne depuis un critere liste
409
+     * Critere {enum Xmin, Xmax}
410
+     *
411
+     **/
412
+    protected function select_enum() {
413
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
414
+        if (!isset($this->command['enum'][1])) {
415
+            if (!is_array($this->command['enum'][0])) {
416
+                $this->command['enum'] = explode(',', $this->command['enum'][0]);
417
+            } else {
418
+                $this->command['enum'] = $this->command['enum'][0];
419
+            }
420
+        }
421
+        if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) {
422
+            $enum = range(
423
+                array_shift($this->command['enum']),
424
+                array_shift($this->command['enum']),
425
+                array_shift($this->command['enum'])
426
+            );
427
+        } else {
428
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
429
+        }
430
+        $this->tableau = $enum;
431
+    }
432
+
433
+
434
+    /**
435
+     * extraire le chemin "query.results" du tableau de donnees
436
+     * {datapath query.results}
437
+     *
438
+     **/
439
+    protected function select_datapath() {
440
+        $base = reset($this->command['datapath']);
441
+        if (strlen($base = ltrim(trim($base), '/'))) {
442
+            $this->tableau = table_valeur($this->tableau, $base);
443
+            if (!is_array($this->tableau)) {
444
+                $this->tableau = [];
445
+                $this->err = true;
446
+                spip_log("datapath '$base' absent");
447
+            }
448
+        }
449
+    }
450
+
451
+    /**
452
+     * Ordonner les resultats
453
+     * {par x}
454
+     *
455
+     **/
456
+    protected function select_orderby() {
457
+        $sortfunc = '';
458
+        $aleas = 0;
459
+        foreach ($this->command['orderby'] as $tri) {
460
+            // virer le / initial pour les criteres de la forme {par /xx}
461
+            if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
462
+                $r = array_pad($r, 3, null);
463
+
464
+                // tri par cle
465
+                if ($r[1] == 'cle') {
466
+                    if (isset($r[2]) and $r[2]) {
467
+                        krsort($this->tableau);
468
+                    } else {
469
+                        ksort($this->tableau);
470
+                    }
471
+                } # {par hasard}
472
+                else {
473
+                    if ($r[1] == 'hasard') {
474
+                        $k = array_keys($this->tableau);
475
+                        shuffle($k);
476
+                        $v = [];
477
+                        foreach ($k as $cle) {
478
+                            $v[$cle] = $this->tableau[$cle];
479
+                        }
480
+                        $this->tableau = $v;
481
+                    } else {
482
+                        # {par valeur}
483
+                        if ($r[1] == 'valeur') {
484
+                            $tv = '%s';
485
+                        } # {par valeur/xx/yy} ??
486
+                        else {
487
+                            $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
488
+                        }
489
+                        $sortfunc .= '
490 490
 					$a = ' . sprintf($tv, '$aa') . ';
491 491
 					$b = ' . sprintf($tv, '$bb') . ';
492 492
 					if ($a <> $b)
493 493
 						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
494
-					}
495
-				}
496
-			}
497
-		}
498
-
499
-		if ($sortfunc) {
500
-			$sortfunc .= "\n return 0;";
501
-			uasort($this->tableau, fn($aa, $bb) => eval($sortfunc));
502
-		}
503
-	}
504
-
505
-
506
-	/**
507
-	 * Grouper les resultats
508
-	 * {fusion /x/y/z}
509
-	 *
510
-	 **/
511
-	protected function select_groupby() {
512
-		// virer le / initial pour les criteres de la forme {fusion /xx}
513
-		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
514
-			$vu = [];
515
-			foreach ($this->tableau as $k => $v) {
516
-				$val = table_valeur($v, $fusion);
517
-				if (isset($vu[$val])) {
518
-					unset($this->tableau[$k]);
519
-				} else {
520
-					$vu[$val] = true;
521
-				}
522
-			}
523
-		}
524
-	}
525
-
526
-
527
-	/**
528
-	 * L'iterateur est-il encore valide ?
529
-	 *
530
-	 * @return bool
531
-	 */
532
-	public function valid(): bool {
533
-		return !is_null($this->cle);
534
-	}
535
-
536
-	/**
537
-	 * Retourner la valeur
538
-	 *
539
-	 * @return mixed
540
-	 */
541
-	#[\ReturnTypeWillChange]
542
-	public function current() {
543
-		return $this->valeur;
544
-	}
545
-
546
-	/**
547
-	 * Retourner la cle
548
-	 *
549
-	 * @return mixed
550
-	 */
551
-	#[\ReturnTypeWillChange]
552
-	public function key() {
553
-		return $this->cle;
554
-	}
555
-
556
-	/**
557
-	 * Passer a la valeur suivante
558
-	 *
559
-	 * @return void
560
-	 */
561
-	public function next() : void {
562
-		if ($this->valid()) {
563
-			$this->cle = key($this->tableau);
564
-			$this->valeur = current($this->tableau);
565
-			next($this->tableau);
566
-		}
567
-	}
568
-
569
-	/**
570
-	 * Compter le nombre total de resultats
571
-	 *
572
-	 * @return int
573
-	 */
574
-	public function count() {
575
-		if (is_null($this->total)) {
576
-			$this->total = count($this->tableau);
577
-		}
578
-
579
-		return $this->total;
580
-	}
494
+                    }
495
+                }
496
+            }
497
+        }
498
+
499
+        if ($sortfunc) {
500
+            $sortfunc .= "\n return 0;";
501
+            uasort($this->tableau, fn($aa, $bb) => eval($sortfunc));
502
+        }
503
+    }
504
+
505
+
506
+    /**
507
+     * Grouper les resultats
508
+     * {fusion /x/y/z}
509
+     *
510
+     **/
511
+    protected function select_groupby() {
512
+        // virer le / initial pour les criteres de la forme {fusion /xx}
513
+        if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
514
+            $vu = [];
515
+            foreach ($this->tableau as $k => $v) {
516
+                $val = table_valeur($v, $fusion);
517
+                if (isset($vu[$val])) {
518
+                    unset($this->tableau[$k]);
519
+                } else {
520
+                    $vu[$val] = true;
521
+                }
522
+            }
523
+        }
524
+    }
525
+
526
+
527
+    /**
528
+     * L'iterateur est-il encore valide ?
529
+     *
530
+     * @return bool
531
+     */
532
+    public function valid(): bool {
533
+        return !is_null($this->cle);
534
+    }
535
+
536
+    /**
537
+     * Retourner la valeur
538
+     *
539
+     * @return mixed
540
+     */
541
+    #[\ReturnTypeWillChange]
542
+    public function current() {
543
+        return $this->valeur;
544
+    }
545
+
546
+    /**
547
+     * Retourner la cle
548
+     *
549
+     * @return mixed
550
+     */
551
+    #[\ReturnTypeWillChange]
552
+    public function key() {
553
+        return $this->cle;
554
+    }
555
+
556
+    /**
557
+     * Passer a la valeur suivante
558
+     *
559
+     * @return void
560
+     */
561
+    public function next() : void {
562
+        if ($this->valid()) {
563
+            $this->cle = key($this->tableau);
564
+            $this->valeur = current($this->tableau);
565
+            next($this->tableau);
566
+        }
567
+    }
568
+
569
+    /**
570
+     * Compter le nombre total de resultats
571
+     *
572
+     * @return int
573
+     */
574
+    public function count() {
575
+        if (is_null($this->total)) {
576
+            $this->total = count($this->tableau);
577
+        }
578
+
579
+        return $this->total;
580
+    }
581 581
 }
582 582
 
583 583
 /*
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
  * @return array
592 592
  */
593 593
 function inc_file_to_array_dist($data) {
594
-	return preg_split('/\r?\n/', $data);
594
+    return preg_split('/\r?\n/', $data);
595 595
 }
596 596
 
597 597
 /**
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
  * @return array
601 601
  */
602 602
 function inc_plugins_to_array_dist() {
603
-	include_spip('inc/plugin');
603
+    include_spip('inc/plugin');
604 604
 
605
-	return liste_chemin_plugin_actifs();
605
+    return liste_chemin_plugin_actifs();
606 606
 }
607 607
 
608 608
 /**
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
  * @return array
613 613
  */
614 614
 function inc_xml_to_array_dist($data) {
615
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
615
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
616 616
 }
617 617
 
618 618
 /**
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
  *
625 625
  */
626 626
 function inc_object_to_array($object) {
627
-	if (!is_object($object) && !is_array($object)) {
628
-		return $object;
629
-	}
630
-	if (is_object($object)) {
631
-		$object = get_object_vars($object);
632
-	}
633
-
634
-	return array_map('inc_object_to_array', $object);
627
+    if (!is_object($object) && !is_array($object)) {
628
+        return $object;
629
+    }
630
+    if (is_object($object)) {
631
+        $object = get_object_vars($object);
632
+    }
633
+
634
+    return array_map('inc_object_to_array', $object);
635 635
 }
636 636
 
637 637
 /**
@@ -641,20 +641,20 @@  discard block
 block discarded – undo
641 641
  * @return array|bool
642 642
  */
643 643
 function inc_sql_to_array_dist($data) {
644
-	# sortir le connecteur de $data
645
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
-	$serveur = (string)$v[1];
647
-	$req = trim($v[2]);
648
-	if ($s = sql_query($req, $serveur)) {
649
-		$r = [];
650
-		while ($t = sql_fetch($s)) {
651
-			$r[] = $t;
652
-		}
653
-
654
-		return $r;
655
-	}
656
-
657
-	return false;
644
+    # sortir le connecteur de $data
645
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
+    $serveur = (string)$v[1];
647
+    $req = trim($v[2]);
648
+    if ($s = sql_query($req, $serveur)) {
649
+        $r = [];
650
+        while ($t = sql_fetch($s)) {
651
+            $r[] = $t;
652
+        }
653
+
654
+        return $r;
655
+    }
656
+
657
+    return false;
658 658
 }
659 659
 
660 660
 /**
@@ -664,13 +664,13 @@  discard block
 block discarded – undo
664 664
  * @return array|bool
665 665
  */
666 666
 function inc_json_to_array_dist($data) {
667
-	try {
668
-		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
669
-	} catch (JsonException $e) {
670
-		$json = null;
671
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
672
-	}
673
-	return is_array($json) ? (array) $json : [];
667
+    try {
668
+        $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
669
+    } catch (JsonException $e) {
670
+        $json = null;
671
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
672
+    }
673
+    return is_array($json) ? (array) $json : [];
674 674
 }
675 675
 
676 676
 /**
@@ -680,30 +680,30 @@  discard block
 block discarded – undo
680 680
  * @return array|bool
681 681
  */
682 682
 function inc_csv_to_array_dist($data) {
683
-	include_spip('inc/csv');
684
-	[$entete, $csv] = analyse_csv($data);
685
-	array_unshift($csv, $entete);
686
-
687
-	include_spip('inc/charsets');
688
-	$i = 1;
689
-	foreach ($entete as $k => $v) {
690
-		if (trim($v) == '') {
691
-			$v = 'col' . $i;
692
-		} // reperer des eventuelles cases vides
693
-		if (is_numeric($v) and $v < 0) {
694
-			$v = '__' . $v;
695
-		} // ne pas risquer d'ecraser une cle numerique
696
-		if (is_numeric($v)) {
697
-			$v = '_' . $v;
698
-		} // ne pas risquer d'ecraser une cle numerique
699
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
700
-		foreach ($csv as &$item) {
701
-			$item[$v] = &$item[$k];
702
-		}
703
-		$i++;
704
-	}
705
-
706
-	return $csv;
683
+    include_spip('inc/csv');
684
+    [$entete, $csv] = analyse_csv($data);
685
+    array_unshift($csv, $entete);
686
+
687
+    include_spip('inc/charsets');
688
+    $i = 1;
689
+    foreach ($entete as $k => $v) {
690
+        if (trim($v) == '') {
691
+            $v = 'col' . $i;
692
+        } // reperer des eventuelles cases vides
693
+        if (is_numeric($v) and $v < 0) {
694
+            $v = '__' . $v;
695
+        } // ne pas risquer d'ecraser une cle numerique
696
+        if (is_numeric($v)) {
697
+            $v = '_' . $v;
698
+        } // ne pas risquer d'ecraser une cle numerique
699
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
700
+        foreach ($csv as &$item) {
701
+            $item[$v] = &$item[$k];
702
+        }
703
+        $i++;
704
+    }
705
+
706
+    return $csv;
707 707
 }
708 708
 
709 709
 /**
@@ -713,13 +713,13 @@  discard block
 block discarded – undo
713 713
  * @return array|bool
714 714
  */
715 715
 function inc_rss_to_array_dist($data) {
716
-	$tableau = null;
717
-	include_spip('inc/syndic');
718
-	if (is_array($rss = analyser_backend($data))) {
719
-		$tableau = $rss;
720
-	}
716
+    $tableau = null;
717
+    include_spip('inc/syndic');
718
+    if (is_array($rss = analyser_backend($data))) {
719
+        $tableau = $rss;
720
+    }
721 721
 
722
-	return $tableau;
722
+    return $tableau;
723 723
 }
724 724
 
725 725
 /**
@@ -729,9 +729,9 @@  discard block
 block discarded – undo
729 729
  * @return array|bool
730 730
  */
731 731
 function inc_atom_to_array_dist($data) {
732
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
732
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
733 733
 
734
-	return $rss_to_array($data);
734
+    return $rss_to_array($data);
735 735
 }
736 736
 
737 737
 /**
@@ -742,12 +742,12 @@  discard block
 block discarded – undo
742 742
  * @return array|bool
743 743
  */
744 744
 function inc_glob_to_array_dist($data) {
745
-	$a = glob(
746
-		$data,
747
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
748
-	);
745
+    $a = glob(
746
+        $data,
747
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
748
+    );
749 749
 
750
-	return $a ?: [];
750
+    return $a ?: [];
751 751
 }
752 752
 
753 753
 /**
@@ -758,14 +758,14 @@  discard block
 block discarded – undo
758 758
  * @throws Exception
759 759
  */
760 760
 function inc_yaml_to_array_dist($data) {
761
-	include_spip('inc/yaml-mini');
762
-	if (!function_exists('yaml_decode')) {
763
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
761
+    include_spip('inc/yaml-mini');
762
+    if (!function_exists('yaml_decode')) {
763
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
764 764
 
765
-		return false;
766
-	}
765
+        return false;
766
+    }
767 767
 
768
-	return yaml_decode($data);
768
+    return yaml_decode($data);
769 769
 }
770 770
 
771 771
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
  * @return array|bool
781 781
  */
782 782
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
783
-	return (array)preg_files($dir, $regexp, $limit);
783
+    return (array)preg_files($dir, $regexp, $limit);
784 784
 }
785 785
 
786 786
 /**
@@ -792,23 +792,23 @@  discard block
 block discarded – undo
792 792
  * @return array|bool
793 793
  */
794 794
 function inc_ls_to_array_dist($data) {
795
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
796
-	$a = $glob_to_array($data);
797
-	foreach ($a as &$v) {
798
-		$b = (array)@stat($v);
799
-		foreach ($b as $k => $ignore) {
800
-			if (is_numeric($k)) {
801
-				unset($b[$k]);
802
-			}
803
-		}
804
-		$b['file'] = preg_replace('`/$`', '', $v) ;
805
-		$v = array_merge(
806
-			pathinfo($v),
807
-			$b
808
-		);
809
-	}
810
-
811
-	return $a;
795
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
796
+    $a = $glob_to_array($data);
797
+    foreach ($a as &$v) {
798
+        $b = (array)@stat($v);
799
+        foreach ($b as $k => $ignore) {
800
+            if (is_numeric($k)) {
801
+                unset($b[$k]);
802
+            }
803
+        }
804
+        $b['file'] = preg_replace('`/$`', '', $v) ;
805
+        $v = array_merge(
806
+            pathinfo($v),
807
+            $b
808
+        );
809
+    }
810
+
811
+    return $a;
812 812
 }
813 813
 
814 814
 /**
@@ -818,25 +818,25 @@  discard block
 block discarded – undo
818 818
  * @return array|bool
819 819
  */
820 820
 function XMLObjectToArray($object) {
821
-	$xml_array = [];
822
-	for ($object->rewind(); $object->valid(); $object->next()) {
823
-		if (array_key_exists($key = $object->key(), $xml_array)) {
824
-			$key .= '-' . uniqid();
825
-		}
826
-		$vars = get_object_vars($object->current());
827
-		if (isset($vars['@attributes'])) {
828
-			foreach ($vars['@attributes'] as $k => $v) {
829
-				$xml_array[$key][$k] = $v;
830
-			}
831
-		}
832
-		if ($object->hasChildren()) {
833
-			$xml_array[$key][] = XMLObjectToArray(
834
-				$object->current()
835
-			);
836
-		} else {
837
-			$xml_array[$key][] = strval($object->current());
838
-		}
839
-	}
840
-
841
-	return $xml_array;
821
+    $xml_array = [];
822
+    for ($object->rewind(); $object->valid(); $object->next()) {
823
+        if (array_key_exists($key = $object->key(), $xml_array)) {
824
+            $key .= '-' . uniqid();
825
+        }
826
+        $vars = get_object_vars($object->current());
827
+        if (isset($vars['@attributes'])) {
828
+            foreach ($vars['@attributes'] as $k => $v) {
829
+                $xml_array[$key][$k] = $v;
830
+            }
831
+        }
832
+        if ($object->hasChildren()) {
833
+            $xml_array[$key][] = XMLObjectToArray(
834
+                $object->current()
835
+            );
836
+        } else {
837
+            $xml_array[$key][] = strval($object->current());
838
+        }
839
+    }
840
+
841
+    return $xml_array;
842 842
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		// Si a ce stade on n'a pas de table, il y a un bug
235 235
 		if (!is_array($this->tableau)) {
236 236
 			$this->err = true;
237
-			spip_log('erreur datasource ' . var_export($command, true));
237
+			spip_log('erreur datasource '.var_export($command, true));
238 238
 		}
239 239
 
240 240
 		// {datapath query.results}
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			isset($this->command['sourcemode'])
277 277
 			and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau'])
278 278
 		) {
279
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
279
+			charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true);
280 280
 		}
281 281
 
282 282
 		# le premier argument peut etre un array, une URL etc.
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		# avons-nous un cache dispo ?
286 286
 		$cle = null;
287 287
 		if (is_string($src)) {
288
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
288
+			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true));
289 289
 		}
290 290
 
291 291
 		$cache = $this->cache_get($cle);
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
 					if (
346 346
 						!$this->err
347
-						and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
347
+						and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true)
348 348
 					) {
349 349
 						$args = $this->command['source'];
350 350
 						$args[0] = $data;
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
 							$tv = '%s';
485 485
 						} # {par valeur/xx/yy} ??
486 486
 						else {
487
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
487
+							$tv = 'table_valeur(%s, '.var_export($r[1], true).')';
488 488
 						}
489 489
 						$sortfunc .= '
490
-					$a = ' . sprintf($tv, '$aa') . ';
491
-					$b = ' . sprintf($tv, '$bb') . ';
490
+					$a = ' . sprintf($tv, '$aa').';
491
+					$b = ' . sprintf($tv, '$bb').';
492 492
 					if ($a <> $b)
493
-						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
493
+						return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;';
494 494
 					}
495 495
 				}
496 496
 			}
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 function inc_sql_to_array_dist($data) {
644 644
 	# sortir le connecteur de $data
645 645
 	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
646
-	$serveur = (string)$v[1];
646
+	$serveur = (string) $v[1];
647 647
 	$req = trim($v[2]);
648 648
 	if ($s = sql_query($req, $serveur)) {
649 649
 		$r = [];
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
 		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
669 669
 	} catch (JsonException $e) {
670 670
 		$json = null;
671
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
671
+		spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO);
672 672
 	}
673 673
 	return is_array($json) ? (array) $json : [];
674 674
 }
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
 	$i = 1;
689 689
 	foreach ($entete as $k => $v) {
690 690
 		if (trim($v) == '') {
691
-			$v = 'col' . $i;
691
+			$v = 'col'.$i;
692 692
 		} // reperer des eventuelles cases vides
693 693
 		if (is_numeric($v) and $v < 0) {
694
-			$v = '__' . $v;
694
+			$v = '__'.$v;
695 695
 		} // ne pas risquer d'ecraser une cle numerique
696 696
 		if (is_numeric($v)) {
697
-			$v = '_' . $v;
697
+			$v = '_'.$v;
698 698
 		} // ne pas risquer d'ecraser une cle numerique
699 699
 		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
700 700
 		foreach ($csv as &$item) {
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
  * @return array|bool
781 781
  */
782 782
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
783
-	return (array)preg_files($dir, $regexp, $limit);
783
+	return (array) preg_files($dir, $regexp, $limit);
784 784
 }
785 785
 
786 786
 /**
@@ -795,13 +795,13 @@  discard block
 block discarded – undo
795 795
 	$glob_to_array = charger_fonction('glob_to_array', 'inc');
796 796
 	$a = $glob_to_array($data);
797 797
 	foreach ($a as &$v) {
798
-		$b = (array)@stat($v);
798
+		$b = (array) @stat($v);
799 799
 		foreach ($b as $k => $ignore) {
800 800
 			if (is_numeric($k)) {
801 801
 				unset($b[$k]);
802 802
 			}
803 803
 		}
804
-		$b['file'] = preg_replace('`/$`', '', $v) ;
804
+		$b['file'] = preg_replace('`/$`', '', $v);
805 805
 		$v = array_merge(
806 806
 			pathinfo($v),
807 807
 			$b
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 	$xml_array = [];
822 822
 	for ($object->rewind(); $object->valid(); $object->next()) {
823 823
 		if (array_key_exists($key = $object->key(), $xml_array)) {
824
-			$key .= '-' . uniqid();
824
+			$key .= '-'.uniqid();
825 825
 		}
826 826
 		$vars = get_object_vars($object->current());
827 827
 		if (isset($vars['@attributes'])) {
Please login to merge, or discard this patch.
ecrire/plugins/verifie_conformite.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/xml');
@@ -19,218 +19,218 @@  discard block
 block discarded – undo
19 19
 
20 20
 // https://code.spip.net/@plugin_verifie_conformite
21 21
 function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS) {
22
-	$needs = null;
23
-	$compat_spip = null;
24
-	$uses = null;
25
-	$paths = null;
26
-	$trads = null;
27
-	static $etats = ['dev', 'experimental', 'test', 'stable'];
22
+    $needs = null;
23
+    $compat_spip = null;
24
+    $uses = null;
25
+    $paths = null;
26
+    $trads = null;
27
+    static $etats = ['dev', 'experimental', 'test', 'stable'];
28 28
 
29
-	$matches = [];
30
-	$silence = false;
31
-	$p = null;
32
-	// chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
33
-	if ($n = spip_xml_match_nodes(',^plugin(\s|$),', $arbre, $matches)) {
34
-		// version de SPIP
35
-		$vspip = $GLOBALS['spip_version_branche'];
36
-		foreach ($matches as $tag => $sous) {
37
-			[$tagname, $atts] = spip_xml_decompose_tag($tag);
38
-			if ($tagname == 'plugin' and is_array($sous)) {
39
-				// On rajoute la condition sur $n :
40
-				// -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
41
-				//    un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
42
-				//    de la meme facon.
43
-				if (
44
-					!isset($atts['spip'])
45
-					or $n == 1
46
-					or plugin_version_compatible($atts['spip'], $vspip, 'spip')
47
-				) {
48
-					// on prend la derniere declaration avec ce nom
49
-					$p = end($sous);
50
-					$compat_spip = $atts['spip'] ?? '';
51
-				}
52
-			}
53
-		}
54
-	}
55
-	if (is_null($p)) {
56
-		$arbre = ['erreur' => [_T('erreur_plugin_tag_plugin_absent') . " : $plug"]];
57
-		$silence = true;
58
-	} else {
59
-		$arbre = $p;
60
-	}
61
-	if (!is_array($arbre)) {
62
-		$arbre = [];
63
-	}
64
-	// verification de la conformite du plugin avec quelques
65
-	// precautions elementaires
66
-	if (!isset($arbre['nom'])) {
67
-		if (!$silence) {
68
-			$arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
69
-		}
70
-		$arbre['nom'] = [''];
71
-	}
72
-	if (!isset($arbre['version'])) {
73
-		if (!$silence) {
74
-			$arbre['erreur'][] = _T('erreur_plugin_version_manquant');
75
-		}
76
-		$arbre['version'] = [''];
77
-	}
78
-	if (!isset($arbre['prefix'])) {
79
-		if (!$silence) {
80
-			$arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
81
-		}
82
-		$arbre['prefix'] = [''];
83
-	} else {
84
-		$prefix = trim(end($arbre['prefix']));
85
-		if (strtoupper($prefix) == 'SPIP' and $plug != './') {
86
-			$arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
87
-		}
88
-		if (isset($arbre['etat'])) {
89
-			$etat = trim(end($arbre['etat']));
90
-			if (!in_array($etat, $etats)) {
91
-				$arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'";
92
-			}
93
-		}
94
-		if (isset($arbre['options'])) {
95
-			foreach ($arbre['options'] as $optfile) {
96
-				$optfile = trim($optfile);
97
-				if (!@is_readable($dir_plugins . "$plug/$optfile")) {
98
-					if (!$silence) {
99
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
100
-					}
101
-				}
102
-			}
103
-		}
104
-		if (isset($arbre['fonctions'])) {
105
-			foreach ($arbre['fonctions'] as $optfile) {
106
-				$optfile = trim($optfile);
107
-				if (!@is_readable($dir_plugins . "$plug/$optfile")) {
108
-					if (!$silence) {
109
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
110
-					}
111
-				}
112
-			}
113
-		}
114
-		$fonctions = [];
115
-		if (isset($arbre['fonctions'])) {
116
-			$fonctions = $arbre['fonctions'];
117
-		}
118
-		$liste_methodes_reservees = [
119
-			'__construct',
120
-			'__destruct',
121
-			'plugin',
122
-			'install',
123
-			'uninstall',
124
-			strtolower($prefix)
125
-		];
29
+    $matches = [];
30
+    $silence = false;
31
+    $p = null;
32
+    // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
33
+    if ($n = spip_xml_match_nodes(',^plugin(\s|$),', $arbre, $matches)) {
34
+        // version de SPIP
35
+        $vspip = $GLOBALS['spip_version_branche'];
36
+        foreach ($matches as $tag => $sous) {
37
+            [$tagname, $atts] = spip_xml_decompose_tag($tag);
38
+            if ($tagname == 'plugin' and is_array($sous)) {
39
+                // On rajoute la condition sur $n :
40
+                // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
41
+                //    un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
42
+                //    de la meme facon.
43
+                if (
44
+                    !isset($atts['spip'])
45
+                    or $n == 1
46
+                    or plugin_version_compatible($atts['spip'], $vspip, 'spip')
47
+                ) {
48
+                    // on prend la derniere declaration avec ce nom
49
+                    $p = end($sous);
50
+                    $compat_spip = $atts['spip'] ?? '';
51
+                }
52
+            }
53
+        }
54
+    }
55
+    if (is_null($p)) {
56
+        $arbre = ['erreur' => [_T('erreur_plugin_tag_plugin_absent') . " : $plug"]];
57
+        $silence = true;
58
+    } else {
59
+        $arbre = $p;
60
+    }
61
+    if (!is_array($arbre)) {
62
+        $arbre = [];
63
+    }
64
+    // verification de la conformite du plugin avec quelques
65
+    // precautions elementaires
66
+    if (!isset($arbre['nom'])) {
67
+        if (!$silence) {
68
+            $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
69
+        }
70
+        $arbre['nom'] = [''];
71
+    }
72
+    if (!isset($arbre['version'])) {
73
+        if (!$silence) {
74
+            $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
75
+        }
76
+        $arbre['version'] = [''];
77
+    }
78
+    if (!isset($arbre['prefix'])) {
79
+        if (!$silence) {
80
+            $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
81
+        }
82
+        $arbre['prefix'] = [''];
83
+    } else {
84
+        $prefix = trim(end($arbre['prefix']));
85
+        if (strtoupper($prefix) == 'SPIP' and $plug != './') {
86
+            $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
87
+        }
88
+        if (isset($arbre['etat'])) {
89
+            $etat = trim(end($arbre['etat']));
90
+            if (!in_array($etat, $etats)) {
91
+                $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'";
92
+            }
93
+        }
94
+        if (isset($arbre['options'])) {
95
+            foreach ($arbre['options'] as $optfile) {
96
+                $optfile = trim($optfile);
97
+                if (!@is_readable($dir_plugins . "$plug/$optfile")) {
98
+                    if (!$silence) {
99
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
100
+                    }
101
+                }
102
+            }
103
+        }
104
+        if (isset($arbre['fonctions'])) {
105
+            foreach ($arbre['fonctions'] as $optfile) {
106
+                $optfile = trim($optfile);
107
+                if (!@is_readable($dir_plugins . "$plug/$optfile")) {
108
+                    if (!$silence) {
109
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
110
+                    }
111
+                }
112
+            }
113
+        }
114
+        $fonctions = [];
115
+        if (isset($arbre['fonctions'])) {
116
+            $fonctions = $arbre['fonctions'];
117
+        }
118
+        $liste_methodes_reservees = [
119
+            '__construct',
120
+            '__destruct',
121
+            'plugin',
122
+            'install',
123
+            'uninstall',
124
+            strtolower($prefix)
125
+        ];
126 126
 
127
-		$extraire_pipelines = charger_fonction('extraire_pipelines', 'plugins');
128
-		$arbre['pipeline'] = $extraire_pipelines($arbre);
129
-		foreach ($arbre['pipeline'] as $pipe) {
130
-			if (!isset($pipe['nom'])) {
131
-				if (!$silence) {
132
-					$arbre['erreur'][] = _T('erreur_plugin_nom_pipeline_non_defini');
133
-				}
134
-			}
135
-			if (isset($pipe['action'])) {
136
-				$action = $pipe['action'];
137
-			} else {
138
-				$action = $pipe['nom'];
139
-			}
140
-			// verif que la methode a un nom autorise
141
-			if (in_array(strtolower($action), $liste_methodes_reservees)) {
142
-				if (!$silence) {
143
-					$arbre['erreur'][] = _T('erreur_plugin_nom_fonction_interdit') . " : $action";
144
-				}
145
-			}
146
-			if (isset($pipe['inclure'])) {
147
-				$inclure = $dir_plugins . "$plug/" . $pipe['inclure'];
148
-				if (!@is_readable($inclure)) {
149
-					if (!$silence) {
150
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure";
151
-					}
152
-				}
153
-			}
154
-		}
155
-		$necessite = [];
156
-		$spip_trouve = false;
157
-		if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
158
-			foreach (array_keys($needs) as $tag) {
159
-				[$tag, $att] = spip_xml_decompose_tag($tag);
160
-				if (!isset($att['id'])) {
161
-					if (!$silence) {
162
-						$arbre['erreur'][] = _T(
163
-							'erreur_plugin_attribut_balise_manquant',
164
-							['attribut' => 'id', 'balise' => $att]
165
-						);
166
-					}
167
-				} else {
168
-					$necessite[] = $att;
169
-				}
170
-				if (strtolower($att['id']) == 'spip') {
171
-					$spip_trouve = true;
172
-				}
173
-			}
174
-		}
175
-		if ($compat_spip and !$spip_trouve) {
176
-			$necessite[] = ['id' => 'spip', 'version' => $compat_spip];
177
-		}
178
-		$arbre['necessite'] = $necessite;
179
-		$utilise = [];
180
-		if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
181
-			foreach (array_keys($uses) as $tag) {
182
-				[$tag, $att] = spip_xml_decompose_tag($tag);
183
-				if (!isset($att['id'])) {
184
-					if (!$silence) {
185
-						$arbre['erreur'][] = _T(
186
-							'erreur_plugin_attribut_balise_manquant',
187
-							['attribut' => 'id', 'balise' => $att]
188
-						);
189
-					}
190
-				} else {
191
-					$utilise[] = $att;
192
-				}
193
-			}
194
-		}
195
-		$arbre['utilise'] = $utilise;
196
-		$procure = [];
197
-		if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
198
-			foreach (array_keys($uses) as $tag) {
199
-				[$tag, $att] = spip_xml_decompose_tag($tag);
200
-				$procure[] = $att;
201
-			}
202
-		}
203
-		$arbre['procure'] = $procure;
204
-		$path = [];
205
-		if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
206
-			foreach (array_keys($paths) as $tag) {
207
-				[$tag, $att] = spip_xml_decompose_tag($tag);
208
-				$att['path'] = $att['dir']; // ancienne syntaxe
209
-				$path[] = $att;
210
-			}
211
-		} else {
212
-			$path = [['dir' => '']];
213
-		} // initialiser par defaut
214
-		$arbre['path'] = $path;
215
-		// exposer les noisettes
216
-		if (isset($arbre['noisette'])) {
217
-			foreach ($arbre['noisette'] as $k => $nut) {
218
-				$nut = preg_replace(',[.]html$,uims', '', trim($nut));
219
-				$arbre['noisette'][$k] = $nut;
220
-				if (!@is_readable($dir_plugins . "$plug/$nut.html")) {
221
-					if (!$silence) {
222
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut";
223
-					}
224
-				}
225
-			}
226
-		}
227
-		$traduire = [];
228
-		if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
229
-			foreach (array_keys($trads) as $tag) {
230
-				[$tag, $att] = spip_xml_decompose_tag($tag);
231
-				$traduire[] = $att;
232
-			}
233
-		}
234
-		$arbre['traduire'] = $traduire;
235
-	}
127
+        $extraire_pipelines = charger_fonction('extraire_pipelines', 'plugins');
128
+        $arbre['pipeline'] = $extraire_pipelines($arbre);
129
+        foreach ($arbre['pipeline'] as $pipe) {
130
+            if (!isset($pipe['nom'])) {
131
+                if (!$silence) {
132
+                    $arbre['erreur'][] = _T('erreur_plugin_nom_pipeline_non_defini');
133
+                }
134
+            }
135
+            if (isset($pipe['action'])) {
136
+                $action = $pipe['action'];
137
+            } else {
138
+                $action = $pipe['nom'];
139
+            }
140
+            // verif que la methode a un nom autorise
141
+            if (in_array(strtolower($action), $liste_methodes_reservees)) {
142
+                if (!$silence) {
143
+                    $arbre['erreur'][] = _T('erreur_plugin_nom_fonction_interdit') . " : $action";
144
+                }
145
+            }
146
+            if (isset($pipe['inclure'])) {
147
+                $inclure = $dir_plugins . "$plug/" . $pipe['inclure'];
148
+                if (!@is_readable($inclure)) {
149
+                    if (!$silence) {
150
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure";
151
+                    }
152
+                }
153
+            }
154
+        }
155
+        $necessite = [];
156
+        $spip_trouve = false;
157
+        if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
158
+            foreach (array_keys($needs) as $tag) {
159
+                [$tag, $att] = spip_xml_decompose_tag($tag);
160
+                if (!isset($att['id'])) {
161
+                    if (!$silence) {
162
+                        $arbre['erreur'][] = _T(
163
+                            'erreur_plugin_attribut_balise_manquant',
164
+                            ['attribut' => 'id', 'balise' => $att]
165
+                        );
166
+                    }
167
+                } else {
168
+                    $necessite[] = $att;
169
+                }
170
+                if (strtolower($att['id']) == 'spip') {
171
+                    $spip_trouve = true;
172
+                }
173
+            }
174
+        }
175
+        if ($compat_spip and !$spip_trouve) {
176
+            $necessite[] = ['id' => 'spip', 'version' => $compat_spip];
177
+        }
178
+        $arbre['necessite'] = $necessite;
179
+        $utilise = [];
180
+        if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
181
+            foreach (array_keys($uses) as $tag) {
182
+                [$tag, $att] = spip_xml_decompose_tag($tag);
183
+                if (!isset($att['id'])) {
184
+                    if (!$silence) {
185
+                        $arbre['erreur'][] = _T(
186
+                            'erreur_plugin_attribut_balise_manquant',
187
+                            ['attribut' => 'id', 'balise' => $att]
188
+                        );
189
+                    }
190
+                } else {
191
+                    $utilise[] = $att;
192
+                }
193
+            }
194
+        }
195
+        $arbre['utilise'] = $utilise;
196
+        $procure = [];
197
+        if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
198
+            foreach (array_keys($uses) as $tag) {
199
+                [$tag, $att] = spip_xml_decompose_tag($tag);
200
+                $procure[] = $att;
201
+            }
202
+        }
203
+        $arbre['procure'] = $procure;
204
+        $path = [];
205
+        if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
206
+            foreach (array_keys($paths) as $tag) {
207
+                [$tag, $att] = spip_xml_decompose_tag($tag);
208
+                $att['path'] = $att['dir']; // ancienne syntaxe
209
+                $path[] = $att;
210
+            }
211
+        } else {
212
+            $path = [['dir' => '']];
213
+        } // initialiser par defaut
214
+        $arbre['path'] = $path;
215
+        // exposer les noisettes
216
+        if (isset($arbre['noisette'])) {
217
+            foreach ($arbre['noisette'] as $k => $nut) {
218
+                $nut = preg_replace(',[.]html$,uims', '', trim($nut));
219
+                $arbre['noisette'][$k] = $nut;
220
+                if (!@is_readable($dir_plugins . "$plug/$nut.html")) {
221
+                    if (!$silence) {
222
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut";
223
+                    }
224
+                }
225
+            }
226
+        }
227
+        $traduire = [];
228
+        if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
229
+            foreach (array_keys($trads) as $tag) {
230
+                [$tag, $att] = spip_xml_decompose_tag($tag);
231
+                $traduire[] = $att;
232
+            }
233
+        }
234
+        $arbre['traduire'] = $traduire;
235
+    }
236 236
 }
Please login to merge, or discard this patch.
ecrire/plugins/get_infos.php 1 patch
Indentation   +101 added lines, -101 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
 /**
@@ -33,110 +33,110 @@  discard block
 block discarded – undo
33 33
  * @return array
34 34
  */
35 35
 function plugins_get_infos_dist($plug = false, $reload = false, $dir = _DIR_PLUGINS, $clean_old = false) {
36
-	$contenu = null;
37
-	$res = null;
38
-	static $cache = '';
39
-	static $filecache = '';
40
-
41
-	if ($cache === '') {
42
-		$filecache = _DIR_TMP . 'plugin_xml_cache.gz';
43
-		if (is_file($filecache)) {
44
-			lire_fichier($filecache, $contenu);
45
-			$cache = unserialize($contenu);
46
-		}
47
-		if (!is_array($cache)) {
48
-			$cache = [];
49
-		}
50
-	}
51
-
52
-	if (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') {
53
-		$reload = true;
54
-	}
55
-
56
-	if ($plug === false) {
57
-		ecrire_fichier($filecache, serialize($cache));
58
-
59
-		return $cache;
60
-	} elseif (is_string($plug)) {
61
-		$res = plugins_get_infos_un($plug, $reload, $dir, $cache);
62
-	} elseif (is_array($plug)) {
63
-		$res = false;
64
-		if (!$reload) {
65
-			$reload = -1;
66
-		}
67
-		foreach ($plug as $nom) {
68
-			$res |= plugins_get_infos_un($nom, $reload, $dir, $cache);
69
-		}
70
-
71
-		// Nettoyer le cache des vieux plugins qui ne sont plus la
72
-		if ($clean_old and isset($cache[$dir]) and is_countable($cache[$dir]) ? count($cache[$dir]) : 0) {
73
-			foreach (array_keys($cache[$dir]) as $p) {
74
-				if (!in_array($p, $plug)) {
75
-					unset($cache[$dir][$p]);
76
-				}
77
-			}
78
-		}
79
-	}
80
-	if ($res) {
81
-		ecrire_fichier($filecache, serialize($cache));
82
-	}
83
-	if (!isset($cache[$dir])) {
84
-		return [];
85
-	}
86
-	if (is_string($plug)) {
87
-		return $cache[$dir][$plug] ?? [];
88
-	} else {
89
-		return $cache[$dir];
90
-	}
36
+    $contenu = null;
37
+    $res = null;
38
+    static $cache = '';
39
+    static $filecache = '';
40
+
41
+    if ($cache === '') {
42
+        $filecache = _DIR_TMP . 'plugin_xml_cache.gz';
43
+        if (is_file($filecache)) {
44
+            lire_fichier($filecache, $contenu);
45
+            $cache = unserialize($contenu);
46
+        }
47
+        if (!is_array($cache)) {
48
+            $cache = [];
49
+        }
50
+    }
51
+
52
+    if (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') {
53
+        $reload = true;
54
+    }
55
+
56
+    if ($plug === false) {
57
+        ecrire_fichier($filecache, serialize($cache));
58
+
59
+        return $cache;
60
+    } elseif (is_string($plug)) {
61
+        $res = plugins_get_infos_un($plug, $reload, $dir, $cache);
62
+    } elseif (is_array($plug)) {
63
+        $res = false;
64
+        if (!$reload) {
65
+            $reload = -1;
66
+        }
67
+        foreach ($plug as $nom) {
68
+            $res |= plugins_get_infos_un($nom, $reload, $dir, $cache);
69
+        }
70
+
71
+        // Nettoyer le cache des vieux plugins qui ne sont plus la
72
+        if ($clean_old and isset($cache[$dir]) and is_countable($cache[$dir]) ? count($cache[$dir]) : 0) {
73
+            foreach (array_keys($cache[$dir]) as $p) {
74
+                if (!in_array($p, $plug)) {
75
+                    unset($cache[$dir][$p]);
76
+                }
77
+            }
78
+        }
79
+    }
80
+    if ($res) {
81
+        ecrire_fichier($filecache, serialize($cache));
82
+    }
83
+    if (!isset($cache[$dir])) {
84
+        return [];
85
+    }
86
+    if (is_string($plug)) {
87
+        return $cache[$dir][$plug] ?? [];
88
+    } else {
89
+        return $cache[$dir];
90
+    }
91 91
 }
92 92
 
93 93
 
94 94
 function plugins_get_infos_un($plug, $reload, $dir, &$cache) {
95
-	if (!is_readable($file = "$dir$plug/paquet.xml")) {
96
-		return false;
97
-	}
98
-	$time = intval(@filemtime($file));
99
-	if ($time < 0) {
100
-		return false;
101
-	}
102
-	$md5 = md5_file($file);
103
-
104
-	$pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => ''];
105
-
106
-	// si le cache est valide
107
-	if (
108
-		(intval($reload) <= 0)
109
-		and ($time > 0)
110
-		and ($time <= $pcache['filemtime'])
111
-		and $md5 == $pcache['md5_file']
112
-	) {
113
-		return false;
114
-	}
115
-
116
-	// si on arrive pas a lire le fichier, se contenter du cache
117
-	if (!($texte = spip_file_get_contents($file))) {
118
-		return false;
119
-	}
120
-
121
-	$f = charger_fonction('infos_paquet', 'plugins');
122
-	$ret = $f($texte, $plug, $dir);
123
-	$ret['filemtime'] = $time;
124
-	$ret['md5_file'] = $md5;
125
-	// Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent
126
-	// utiliser un necessite php. SPIP procure donc la version php courante du serveur.
127
-	// chaque librairie php est aussi procurée, par exemple 'php:curl'.
128
-	if (isset($ret['prefix']) and $ret['prefix'] == 'spip') {
129
-		$ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()];
130
-		foreach (get_loaded_extensions() as $ext) {
131
-			$ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)];
132
-		}
133
-	}
134
-	$diff = ($ret != $pcache);
135
-
136
-	if ($diff) {
137
-		$cache[$dir][$plug] = $ret;
95
+    if (!is_readable($file = "$dir$plug/paquet.xml")) {
96
+        return false;
97
+    }
98
+    $time = intval(@filemtime($file));
99
+    if ($time < 0) {
100
+        return false;
101
+    }
102
+    $md5 = md5_file($file);
103
+
104
+    $pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => ''];
105
+
106
+    // si le cache est valide
107
+    if (
108
+        (intval($reload) <= 0)
109
+        and ($time > 0)
110
+        and ($time <= $pcache['filemtime'])
111
+        and $md5 == $pcache['md5_file']
112
+    ) {
113
+        return false;
114
+    }
115
+
116
+    // si on arrive pas a lire le fichier, se contenter du cache
117
+    if (!($texte = spip_file_get_contents($file))) {
118
+        return false;
119
+    }
120
+
121
+    $f = charger_fonction('infos_paquet', 'plugins');
122
+    $ret = $f($texte, $plug, $dir);
123
+    $ret['filemtime'] = $time;
124
+    $ret['md5_file'] = $md5;
125
+    // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent
126
+    // utiliser un necessite php. SPIP procure donc la version php courante du serveur.
127
+    // chaque librairie php est aussi procurée, par exemple 'php:curl'.
128
+    if (isset($ret['prefix']) and $ret['prefix'] == 'spip') {
129
+        $ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()];
130
+        foreach (get_loaded_extensions() as $ext) {
131
+            $ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)];
132
+        }
133
+    }
134
+    $diff = ($ret != $pcache);
135
+
136
+    if ($diff) {
137
+        $cache[$dir][$plug] = $ret;
138 138
 #       echo count($cache[$dir]), $dir,$plug, " $reloadc<br>";
139
-	}
139
+    }
140 140
 
141
-	return $diff;
141
+    return $diff;
142 142
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_repertoires.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -11,68 +11,68 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // https://code.spip.net/@affiche_arbre_plugins
18 18
 function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) {
19
-	$ligne_plug = charger_fonction('afficher_plugin', 'plugins');
20
-	$racine = basename(_DIR_PLUGINS);
21
-	$init_dir = $current_dir = '';
22
-	// liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
23
-	// des qu'un path est deja note deplie on s'arrete
24
-	$deplie = [$racine => true];
25
-	$fast_liste_plugins_actifs = [];
26
-	foreach ($liste_plugins_actifs as $key => $plug) {
27
-		$chemin_plug = chemin_plug($racine, $plug);
28
-		$fast_liste_plugins_actifs[$chemin_plug] = true;
29
-		$dir = dirname($chemin_plug);
30
-		$maxiter = 100;
31
-		while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) {
32
-			$deplie[$dir] = true;
33
-			$dir = dirname($dir);
34
-		}
35
-	}
19
+    $ligne_plug = charger_fonction('afficher_plugin', 'plugins');
20
+    $racine = basename(_DIR_PLUGINS);
21
+    $init_dir = $current_dir = '';
22
+    // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
23
+    // des qu'un path est deja note deplie on s'arrete
24
+    $deplie = [$racine => true];
25
+    $fast_liste_plugins_actifs = [];
26
+    foreach ($liste_plugins_actifs as $key => $plug) {
27
+        $chemin_plug = chemin_plug($racine, $plug);
28
+        $fast_liste_plugins_actifs[$chemin_plug] = true;
29
+        $dir = dirname($chemin_plug);
30
+        $maxiter = 100;
31
+        while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) {
32
+            $deplie[$dir] = true;
33
+            $dir = dirname($dir);
34
+        }
35
+    }
36 36
 
37
-	// index repertoires --> plugin
38
-	$dir_index = [];
39
-	foreach ($liste_plugins as $key => $plug) {
40
-		$liste_plugins[$key] = chemin_plug($racine, $plug);
41
-		$dir_index[dirname($liste_plugins[$key])][] = $key;
42
-	}
37
+    // index repertoires --> plugin
38
+    $dir_index = [];
39
+    foreach ($liste_plugins as $key => $plug) {
40
+        $liste_plugins[$key] = chemin_plug($racine, $plug);
41
+        $dir_index[dirname($liste_plugins[$key])][] = $key;
42
+    }
43 43
 
44
-	$visible = @isset($deplie[$current_dir]);
45
-	$maxiter = 1000;
44
+    $visible = @isset($deplie[$current_dir]);
45
+    $maxiter = 1000;
46 46
 
47
-	$res = '';
48
-	while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
49
-		// le rep suivant
50
-		$dir = dirname(reset($liste_plugins));
51
-		if ($dir != $current_dir) {
52
-			$res .= tree_open_close_dir($current_dir, $dir, $deplie);
53
-		}
47
+    $res = '';
48
+    while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
49
+        // le rep suivant
50
+        $dir = dirname(reset($liste_plugins));
51
+        if ($dir != $current_dir) {
52
+            $res .= tree_open_close_dir($current_dir, $dir, $deplie);
53
+        }
54 54
 
55
-		// d'abord tous les plugins du rep courant
56
-		if (isset($dir_index[$current_dir])) {
57
-			foreach ($dir_index[$current_dir] as $key) {
58
-				$plug = $liste_plugins[$key];
59
-				$actif = @isset($fast_liste_plugins_actifs[$plug]);
60
-				$id = substr(md5($plug), 0, 16);
61
-				$res .= $ligne_plug(
62
-					$url_page,
63
-					str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
64
-					$actif,
65
-					'menu-entree'
66
-				) . "\n";
67
-				unset($liste_plugins[$key]);
68
-			}
69
-		}
70
-	}
71
-	$res .= tree_open_close_dir($current_dir, $init_dir, true);
55
+        // d'abord tous les plugins du rep courant
56
+        if (isset($dir_index[$current_dir])) {
57
+            foreach ($dir_index[$current_dir] as $key) {
58
+                $plug = $liste_plugins[$key];
59
+                $actif = @isset($fast_liste_plugins_actifs[$plug]);
60
+                $id = substr(md5($plug), 0, 16);
61
+                $res .= $ligne_plug(
62
+                    $url_page,
63
+                    str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
64
+                    $actif,
65
+                    'menu-entree'
66
+                ) . "\n";
67
+                unset($liste_plugins[$key]);
68
+            }
69
+        }
70
+    }
71
+    $res .= tree_open_close_dir($current_dir, $init_dir, true);
72 72
 
73
-	return "<ul class='menu-liste plugins'>"
74
-	. $res
75
-	. '</ul>';
73
+    return "<ul class='menu-liste plugins'>"
74
+    . $res
75
+    . '</ul>';
76 76
 }
77 77
 
78 78
 
@@ -80,44 +80,44 @@  discard block
 block discarded – undo
80 80
 // une fonction pour aider...
81 81
 // https://code.spip.net/@chemin_plug
82 82
 function chemin_plug($racine, $plug) {
83
-	return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
83
+    return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
84 84
 }
85 85
 
86 86
 // https://code.spip.net/@tree_open_close_dir
87 87
 function tree_open_close_dir(&$current, $target, $deplie = []) {
88
-	if ($current == $target) {
89
-		return '';
90
-	}
91
-	$tcur = explode('/', $current);
92
-	$ttarg = explode('/', $target);
93
-	$tcom = [];
94
-	$output = '';
95
-	// la partie commune
96
-	while (reset($tcur) == reset($ttarg)) {
97
-		$tcom[] = array_shift($tcur);
98
-		array_shift($ttarg);
99
-	}
100
-	// fermer les repertoires courant jusqu'au point de fork
101
-	while ($close = array_pop($tcur)) {
102
-		$output .= "</ul>\n";
103
-		$output .= fin_block();
104
-		$output .= "</li>\n";
105
-	}
106
-	$chemin = '';
107
-	if (count($tcom)) {
108
-		$chemin .= implode('/', $tcom) . '/';
109
-	}
110
-	// ouvrir les repertoires jusqu'a la cible
111
-	while ($open = array_shift($ttarg)) {
112
-		$visible = @isset($deplie[$chemin . $open]);
113
-		$chemin .= $open . '/';
114
-		$output .= '<li>';
115
-		$output .= bouton_block_depliable($chemin, $visible);
116
-		$output .= debut_block_depliable($visible);
88
+    if ($current == $target) {
89
+        return '';
90
+    }
91
+    $tcur = explode('/', $current);
92
+    $ttarg = explode('/', $target);
93
+    $tcom = [];
94
+    $output = '';
95
+    // la partie commune
96
+    while (reset($tcur) == reset($ttarg)) {
97
+        $tcom[] = array_shift($tcur);
98
+        array_shift($ttarg);
99
+    }
100
+    // fermer les repertoires courant jusqu'au point de fork
101
+    while ($close = array_pop($tcur)) {
102
+        $output .= "</ul>\n";
103
+        $output .= fin_block();
104
+        $output .= "</li>\n";
105
+    }
106
+    $chemin = '';
107
+    if (count($tcom)) {
108
+        $chemin .= implode('/', $tcom) . '/';
109
+    }
110
+    // ouvrir les repertoires jusqu'a la cible
111
+    while ($open = array_shift($ttarg)) {
112
+        $visible = @isset($deplie[$chemin . $open]);
113
+        $chemin .= $open . '/';
114
+        $output .= '<li>';
115
+        $output .= bouton_block_depliable($chemin, $visible);
116
+        $output .= debut_block_depliable($visible);
117 117
 
118
-		$output .= "<ul>\n";
119
-	}
120
-	$current = $target;
118
+        $output .= "<ul>\n";
119
+    }
120
+    $current = $target;
121 121
 
122
-	return $output;
122
+    return $output;
123 123
 }
Please login to merge, or discard this patch.
ecrire/plugins/extraire_pipelines.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 
@@ -21,28 +21,28 @@  discard block
 block discarded – undo
21 21
  * @param array $arbre
22 22
  */
23 23
 function plugins_extraire_pipelines_dist(&$arbre) {
24
-	$pipes = null;
25
-	$tag = null;
26
-	$pipeline = [];
27
-	if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) {
28
-		foreach ($pipes as $tag => $p) {
29
-			if (!is_array($p[0])) {
30
-				[$tag, $att] = spip_xml_decompose_tag($tag);
31
-				$pipeline[] = $att;
32
-			} else {
33
-				foreach ($p as $pipe) {
34
-					$att = [];
35
-					if (is_array($pipe)) {
36
-						foreach ($pipe as $k => $t) {
37
-							$att[$k] = trim(end($t));
38
-						}
39
-					}
40
-					$pipeline[] = $att;
41
-				}
42
-			}
43
-		}
44
-		unset($arbre[$tag]);
45
-	}
24
+    $pipes = null;
25
+    $tag = null;
26
+    $pipeline = [];
27
+    if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) {
28
+        foreach ($pipes as $tag => $p) {
29
+            if (!is_array($p[0])) {
30
+                [$tag, $att] = spip_xml_decompose_tag($tag);
31
+                $pipeline[] = $att;
32
+            } else {
33
+                foreach ($p as $pipe) {
34
+                    $att = [];
35
+                    if (is_array($pipe)) {
36
+                        foreach ($pipe as $k => $t) {
37
+                            $att[$k] = trim(end($t));
38
+                        }
39
+                    }
40
+                    $pipeline[] = $att;
41
+                }
42
+            }
43
+        }
44
+        unset($arbre[$tag]);
45
+    }
46 46
 
47
-	return $pipeline;
47
+    return $pipeline;
48 48
 }
Please login to merge, or discard this patch.
ecrire/plugins/infos_paquet.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -25,64 +25,64 @@  discard block
 block discarded – undo
25 25
  * @return array
26 26
  */
27 27
 function plugins_infos_paquet($desc, $plug = '', $dir_plugins = _DIR_PLUGINS) {
28
-	static $process = [ // tableau constant
29
-		'debut' => 'paquet_debutElement',
30
-		'fin' => 'paquet_finElement',
31
-		'text' => 'paquet_textElement'
32
-	];
33
-
34
-	$valider_xml = charger_fonction('valider', 'xml');
35
-	$vxml = $valider_xml($desc, false, $process, 'paquet.dtd', 'utf-8');
36
-	if (!$vxml->err) {
37
-		// On veut toutes les variantes selon la version de SPIP
38
-		if (!$plug) {
39
-			return $vxml->versions;
40
-		}
41
-
42
-		// compatibilite avec l'existant:
43
-		$tree = $vxml->versions['0'];
44
-
45
-		// l'arbre renvoie parfois un tag vide... etrange. Pas la peine de garder ca.
46
-		if (isset($tree['']) and !strlen($tree[''])) {
47
-			unset($tree['']);
48
-		}
49
-
50
-		$tree['slogan'] = $tree['prefix'] . '_slogan';
51
-		$tree['description'] = $tree['prefix'] . '_description';
52
-		paquet_readable_files($tree, "$dir_plugins$plug/");
53
-		if (!$tree['chemin']) {
54
-			$tree['chemin'] = [];
55
-		}
56
-
57
-		// On verifie qu'il existe des balises spip qu'il faudrait rajouter dans
58
-		// la structure d'infos du paquet en fonction de la version spip courante
59
-		if ((is_countable($vxml->versions) ? count($vxml->versions) : 0) > 1) {
60
-			$vspip = $GLOBALS['spip_version_branche'];
61
-			foreach ($vxml->versions as $_compatibilite => $_version) {
62
-				if (
63
-					($_version['balise'] == 'spip')
64
-					and (plugin_version_compatible($_compatibilite, $vspip, 'spip'))
65
-				) {
66
-					// on merge les sous-balises de la balise spip compatible avec celles de la
67
-					// balise paquet
68
-					foreach ($_version as $_index => $_balise) {
69
-						if ($_index and $_index != 'balise') {
70
-							$tree[$_index] = array_merge($tree[$_index], $_balise);
71
-						}
72
-					}
73
-				}
74
-			}
75
-		}
76
-
77
-		return $tree;
78
-	}
79
-
80
-	// Prendre les messages d'erreur sans les numeros de lignes
81
-	$msg = array_column($vxml->err, 0);
82
-	$t = _T('plugins_erreur', ['plugins' => $plug]);
83
-	array_unshift($msg, $t . " <ul class='erreur_xml'><li>" . reset($msg) . '</li></ul>');
84
-
85
-	return ['erreur' => $msg];
28
+    static $process = [ // tableau constant
29
+        'debut' => 'paquet_debutElement',
30
+        'fin' => 'paquet_finElement',
31
+        'text' => 'paquet_textElement'
32
+    ];
33
+
34
+    $valider_xml = charger_fonction('valider', 'xml');
35
+    $vxml = $valider_xml($desc, false, $process, 'paquet.dtd', 'utf-8');
36
+    if (!$vxml->err) {
37
+        // On veut toutes les variantes selon la version de SPIP
38
+        if (!$plug) {
39
+            return $vxml->versions;
40
+        }
41
+
42
+        // compatibilite avec l'existant:
43
+        $tree = $vxml->versions['0'];
44
+
45
+        // l'arbre renvoie parfois un tag vide... etrange. Pas la peine de garder ca.
46
+        if (isset($tree['']) and !strlen($tree[''])) {
47
+            unset($tree['']);
48
+        }
49
+
50
+        $tree['slogan'] = $tree['prefix'] . '_slogan';
51
+        $tree['description'] = $tree['prefix'] . '_description';
52
+        paquet_readable_files($tree, "$dir_plugins$plug/");
53
+        if (!$tree['chemin']) {
54
+            $tree['chemin'] = [];
55
+        }
56
+
57
+        // On verifie qu'il existe des balises spip qu'il faudrait rajouter dans
58
+        // la structure d'infos du paquet en fonction de la version spip courante
59
+        if ((is_countable($vxml->versions) ? count($vxml->versions) : 0) > 1) {
60
+            $vspip = $GLOBALS['spip_version_branche'];
61
+            foreach ($vxml->versions as $_compatibilite => $_version) {
62
+                if (
63
+                    ($_version['balise'] == 'spip')
64
+                    and (plugin_version_compatible($_compatibilite, $vspip, 'spip'))
65
+                ) {
66
+                    // on merge les sous-balises de la balise spip compatible avec celles de la
67
+                    // balise paquet
68
+                    foreach ($_version as $_index => $_balise) {
69
+                        if ($_index and $_index != 'balise') {
70
+                            $tree[$_index] = array_merge($tree[$_index], $_balise);
71
+                        }
72
+                    }
73
+                }
74
+            }
75
+        }
76
+
77
+        return $tree;
78
+    }
79
+
80
+    // Prendre les messages d'erreur sans les numeros de lignes
81
+    $msg = array_column($vxml->err, 0);
82
+    $t = _T('plugins_erreur', ['plugins' => $plug]);
83
+    array_unshift($msg, $t . " <ul class='erreur_xml'><li>" . reset($msg) . '</li></ul>');
84
+
85
+    return ['erreur' => $msg];
86 86
 }
87 87
 
88 88
 /**
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
  * @return void
95 95
  */
96 96
 function paquet_readable_files(&$tree, $dir) {
97
-	$prefix = strtolower($tree['prefix']);
97
+    $prefix = strtolower($tree['prefix']);
98 98
 
99
-	$tree['options'] = (is_readable($dir . $f = ($prefix . '_options.php'))) ? [$f] : [];
100
-	$tree['fonctions'] = (is_readable($dir . $f = ($prefix . '_fonctions.php'))) ? [$f] : [];
101
-	$tree['install'] = (is_readable($dir . $f = ($prefix . '_administrations.php'))) ? [$f] : [];
99
+    $tree['options'] = (is_readable($dir . $f = ($prefix . '_options.php'))) ? [$f] : [];
100
+    $tree['fonctions'] = (is_readable($dir . $f = ($prefix . '_fonctions.php'))) ? [$f] : [];
101
+    $tree['install'] = (is_readable($dir . $f = ($prefix . '_administrations.php'))) ? [$f] : [];
102 102
 }
103 103
 
104 104
 /**
@@ -115,35 +115,35 @@  discard block
 block discarded – undo
115 115
  * @param array $attrs
116 116
  */
117 117
 function paquet_debutElement($phraseur, $name, $attrs) {
118
-	xml_debutElement($phraseur, $name, $attrs);
119
-	if ($phraseur->err) {
120
-		return;
121
-	}
122
-	if (($name == 'paquet') or ($name == 'spip')) {
123
-		if ($name == 'spip') {
124
-			$n = $attrs['compatibilite'];
125
-			$attrs = [];
126
-		} else {
127
-			$n = '0';
128
-			$phraseur->contenu['paquet'] = $attrs;
129
-			$attrs['menu'] = [];
130
-			$attrs['chemin'] = [];
131
-			$attrs['necessite'] = [];
132
-			$attrs['lib'] = [];
133
-			$attrs['onglet'] = [];
134
-			$attrs['procure'] = [];
135
-			$attrs['pipeline'] = [];
136
-			$attrs['utilise'] = [];
137
-			$attrs['style'] = [];
138
-			$attrs['script'] = [];
139
-			$attrs['genie'] = [];
140
-		}
141
-		$phraseur->contenu['compatible'] = $n;
142
-		$phraseur->versions[$phraseur->contenu['compatible']] = $attrs;
143
-	} else {
144
-		$phraseur->versions[$phraseur->contenu['compatible']][$name][0] = $attrs;
145
-	}
146
-	$phraseur->versions[$phraseur->contenu['compatible']][''] = '';
118
+    xml_debutElement($phraseur, $name, $attrs);
119
+    if ($phraseur->err) {
120
+        return;
121
+    }
122
+    if (($name == 'paquet') or ($name == 'spip')) {
123
+        if ($name == 'spip') {
124
+            $n = $attrs['compatibilite'];
125
+            $attrs = [];
126
+        } else {
127
+            $n = '0';
128
+            $phraseur->contenu['paquet'] = $attrs;
129
+            $attrs['menu'] = [];
130
+            $attrs['chemin'] = [];
131
+            $attrs['necessite'] = [];
132
+            $attrs['lib'] = [];
133
+            $attrs['onglet'] = [];
134
+            $attrs['procure'] = [];
135
+            $attrs['pipeline'] = [];
136
+            $attrs['utilise'] = [];
137
+            $attrs['style'] = [];
138
+            $attrs['script'] = [];
139
+            $attrs['genie'] = [];
140
+        }
141
+        $phraseur->contenu['compatible'] = $n;
142
+        $phraseur->versions[$phraseur->contenu['compatible']] = $attrs;
143
+    } else {
144
+        $phraseur->versions[$phraseur->contenu['compatible']][$name][0] = $attrs;
145
+    }
146
+    $phraseur->versions[$phraseur->contenu['compatible']][''] = '';
147 147
 }
148 148
 
149 149
 /**
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
  * @param string $data
156 156
  */
157 157
 function paquet_textElement($phraseur, $data) {
158
-	xml_textElement($phraseur, $data);
159
-	if ($phraseur->err or !(trim($data))) {
160
-		return;
161
-	}
162
-	$phraseur->versions[$phraseur->contenu['compatible']][''] .= $data;
158
+    xml_textElement($phraseur, $data);
159
+    if ($phraseur->err or !(trim($data))) {
160
+        return;
161
+    }
162
+    $phraseur->versions[$phraseur->contenu['compatible']][''] .= $data;
163 163
 }
164 164
 
165 165
 /**
@@ -171,32 +171,32 @@  discard block
 block discarded – undo
171 171
  * @param string $name
172 172
  */
173 173
 function paquet_finElement($phraseur, $name) {
174
-	if ($phraseur->err) {
175
-		return;
176
-	}
177
-	$n = $phraseur->contenu['compatible'];
178
-
179
-	if (isset($phraseur->versions[$n][$name][0]) and is_array($phraseur->versions[$n][$name][0])) {
180
-		$attrs = $phraseur->versions[$n][$name][0];
181
-		unset($phraseur->versions[$n][$name][0]);
182
-	} else {
183
-		$attrs = [];
184
-	}
185
-
186
-	$texte = trim($phraseur->versions[$n]['']);
187
-	$phraseur->versions[$n][''] = '';
188
-
189
-	$f = 'info_paquet_' . $name;
190
-	if (function_exists($f)) {
191
-		$f($phraseur, $attrs, $texte);
192
-	} elseif (!$attrs) {
193
-		$phraseur->versions[$n][$name] = $texte;
194
-	} else {
195
-		// Traitement generique. Si $attrs['nom'] n'existe pas, ce n'est pas normal ici
196
-		$phraseur->versions[$n][$name][$attrs['nom']] = $attrs;
197
-		#	  echo("<br>pour $name $n " . $attrs['nom']); var_dump($phraseur->versions[$n]);
198
-	}
199
-	xml_finElement($phraseur, $name, $attrs);
174
+    if ($phraseur->err) {
175
+        return;
176
+    }
177
+    $n = $phraseur->contenu['compatible'];
178
+
179
+    if (isset($phraseur->versions[$n][$name][0]) and is_array($phraseur->versions[$n][$name][0])) {
180
+        $attrs = $phraseur->versions[$n][$name][0];
181
+        unset($phraseur->versions[$n][$name][0]);
182
+    } else {
183
+        $attrs = [];
184
+    }
185
+
186
+    $texte = trim($phraseur->versions[$n]['']);
187
+    $phraseur->versions[$n][''] = '';
188
+
189
+    $f = 'info_paquet_' . $name;
190
+    if (function_exists($f)) {
191
+        $f($phraseur, $attrs, $texte);
192
+    } elseif (!$attrs) {
193
+        $phraseur->versions[$n][$name] = $texte;
194
+    } else {
195
+        // Traitement generique. Si $attrs['nom'] n'existe pas, ce n'est pas normal ici
196
+        $phraseur->versions[$n][$name][$attrs['nom']] = $attrs;
197
+        #	  echo("<br>pour $name $n " . $attrs['nom']); var_dump($phraseur->versions[$n]);
198
+    }
199
+    xml_finElement($phraseur, $name, $attrs);
200 200
 }
201 201
 
202 202
 /**
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
  * @param string $texte
209 209
  */
210 210
 function info_paquet_licence($phraseur, $attrs, $texte) {
211
-	if (isset($attrs['lien'])) {
212
-		$lien = $attrs['lien'];
213
-	} else {
214
-		$lien = '';
215
-	}
216
-	$n = $phraseur->contenu['compatible'];
217
-	$phraseur->versions[$n]['licence'][] = ['nom' => $texte, 'url' => $lien];
211
+    if (isset($attrs['lien'])) {
212
+        $lien = $attrs['lien'];
213
+    } else {
214
+        $lien = '';
215
+    }
216
+    $n = $phraseur->contenu['compatible'];
217
+    $phraseur->versions[$n]['licence'][] = ['nom' => $texte, 'url' => $lien];
218 218
 }
219 219
 
220 220
 /**
@@ -226,14 +226,14 @@  discard block
 block discarded – undo
226 226
  * @param string $texte
227 227
  */
228 228
 function info_paquet_chemin($phraseur, $attrs, $texte) {
229
-	$n = $phraseur->contenu['compatible'];
230
-	if (isset($attrs['path'])) {
231
-		if (isset($attrs['type'])) {
232
-			$phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path'], 'type' => $attrs['type']];
233
-		} else {
234
-			$phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path']];
235
-		}
236
-	}
229
+    $n = $phraseur->contenu['compatible'];
230
+    if (isset($attrs['path'])) {
231
+        if (isset($attrs['type'])) {
232
+            $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path'], 'type' => $attrs['type']];
233
+        } else {
234
+            $phraseur->versions[$n]['chemin'][] = ['path' => $attrs['path']];
235
+        }
236
+    }
237 237
 }
238 238
 
239 239
 
@@ -247,24 +247,24 @@  discard block
 block discarded – undo
247 247
  * @param string $texte
248 248
  */
249 249
 function info_paquet_auteur($phraseur, $attrs, $texte) {
250
-	#  echo 'auteur ', $texte;  var_dump($attrs);
251
-	if (isset($attrs['mail'])) {
252
-		if (strpos($attrs['mail'], '@')) {
253
-			$attrs['mail'] = str_replace('@', ' AT ', $attrs['mail']);
254
-		}
255
-		$mail = $attrs['mail'];
256
-	} else {
257
-		$mail = '';
258
-	}
259
-
260
-	if (isset($attrs['lien'])) {
261
-		$lien = $attrs['lien'];
262
-	} else {
263
-		$lien = '';
264
-	}
265
-
266
-	$n = $phraseur->contenu['compatible'];
267
-	$phraseur->versions[$n]['auteur'][] = ['nom' => $texte, 'url' => $lien, 'mail' => $mail];
250
+    #  echo 'auteur ', $texte;  var_dump($attrs);
251
+    if (isset($attrs['mail'])) {
252
+        if (strpos($attrs['mail'], '@')) {
253
+            $attrs['mail'] = str_replace('@', ' AT ', $attrs['mail']);
254
+        }
255
+        $mail = $attrs['mail'];
256
+    } else {
257
+        $mail = '';
258
+    }
259
+
260
+    if (isset($attrs['lien'])) {
261
+        $lien = $attrs['lien'];
262
+    } else {
263
+        $lien = '';
264
+    }
265
+
266
+    $n = $phraseur->contenu['compatible'];
267
+    $phraseur->versions[$n]['auteur'][] = ['nom' => $texte, 'url' => $lien, 'mail' => $mail];
268 268
 }
269 269
 
270 270
 /**
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function info_paquet_credit($phraseur, $attrs, $texte) {
279 279
 
280
-	if (isset($attrs['lien'])) {
281
-		$lien = $attrs['lien'];
282
-	} else {
283
-		$lien = '';
284
-	}
280
+    if (isset($attrs['lien'])) {
281
+        $lien = $attrs['lien'];
282
+    } else {
283
+        $lien = '';
284
+    }
285 285
 
286
-	$n = $phraseur->contenu['compatible'];
287
-	$phraseur->versions[$n]['credit'][] = ['nom' => $texte, 'url' => $lien];
286
+    $n = $phraseur->contenu['compatible'];
287
+    $phraseur->versions[$n]['credit'][] = ['nom' => $texte, 'url' => $lien];
288 288
 }
289 289
 
290 290
 /**
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
  * @param string $texte
297 297
  */
298 298
 function info_paquet_copyright($phraseur, $attrs, $texte) {
299
-	$n = $phraseur->contenu['compatible'];
300
-	$phraseur->versions[$n]['copyright'][] = $texte;
299
+    $n = $phraseur->contenu['compatible'];
300
+    $phraseur->versions[$n]['copyright'][] = $texte;
301 301
 }
302 302
 
303 303
 /**
@@ -309,9 +309,9 @@  discard block
 block discarded – undo
309 309
  * @param string $texte
310 310
  */
311 311
 function info_paquet_paquet($phraseur, $attrs, $texte) {
312
-	$n = 0;
313
-	$phraseur->versions[$n]['dtd'] = 'paquet';
314
-	$phraseur->versions[$n]['balise'] = 'paquet';
312
+    $n = 0;
313
+    $phraseur->versions[$n]['dtd'] = 'paquet';
314
+    $phraseur->versions[$n]['balise'] = 'paquet';
315 315
 }
316 316
 
317 317
 /**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
  * @param string $texte
324 324
  **/
325 325
 function info_paquet_traduire($phraseur, $attrs, $texte) {
326
-	$n = $phraseur->contenu['compatible'];
327
-	$phraseur->versions[$n]['traduire'][] = $attrs;
326
+    $n = $phraseur->contenu['compatible'];
327
+    $phraseur->versions[$n]['traduire'][] = $attrs;
328 328
 }
329 329
 
330 330
 /**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
  * @param string $texte
337 337
  */
338 338
 function info_paquet_spip($phraseur, $attrs, $texte) {
339
-	$n = $phraseur->contenu['compatible'];
340
-	$phraseur->versions[$n]['balise'] = 'spip';
339
+    $n = $phraseur->contenu['compatible'];
340
+    $phraseur->versions[$n]['balise'] = 'spip';
341 341
 }
342 342
 
343 343
 
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
  * @param string $texte
350 350
  */
351 351
 function info_paquet_pipeline($phraseur, $attrs, $texte) {
352
-	$n = $phraseur->contenu['compatible'];
353
-	$phraseur->versions[$n]['pipeline'][] = $attrs;
352
+    $n = $phraseur->contenu['compatible'];
353
+    $phraseur->versions[$n]['pipeline'][] = $attrs;
354 354
 }
355 355
 
356 356
 
@@ -363,23 +363,23 @@  discard block
 block discarded – undo
363 363
  * @param string $texte
364 364
  */
365 365
 function info_paquet_style($phraseur, $attrs, $texte) {
366
-	$lien = $chemin = $type = $media = '';
367
-
368
-	include_spip('inc/utils');
369
-	if (tester_url_absolue($attrs['source'])) {
370
-		$lien = $attrs['source'];
371
-	} else {
372
-		$chemin = $attrs['source'];
373
-	}
374
-	if (isset($attrs['type'])) {
375
-		$type = $attrs['type'];
376
-	}
377
-	if (isset($attrs['media'])) {
378
-		$media = $attrs['media'];
379
-	}
380
-
381
-	$n = $phraseur->contenu['compatible'];
382
-	$phraseur->versions[$n]['style'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type, 'media' => $media];
366
+    $lien = $chemin = $type = $media = '';
367
+
368
+    include_spip('inc/utils');
369
+    if (tester_url_absolue($attrs['source'])) {
370
+        $lien = $attrs['source'];
371
+    } else {
372
+        $chemin = $attrs['source'];
373
+    }
374
+    if (isset($attrs['type'])) {
375
+        $type = $attrs['type'];
376
+    }
377
+    if (isset($attrs['media'])) {
378
+        $media = $attrs['media'];
379
+    }
380
+
381
+    $n = $phraseur->contenu['compatible'];
382
+    $phraseur->versions[$n]['style'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type, 'media' => $media];
383 383
 }
384 384
 
385 385
 
@@ -392,20 +392,20 @@  discard block
 block discarded – undo
392 392
  * @param string $texte
393 393
  */
394 394
 function info_paquet_script($phraseur, $attrs, $texte) {
395
-	$lien = $chemin = $type = $media = '';
396
-
397
-	include_spip('inc/utils');
398
-	if (tester_url_absolue($attrs['source'])) {
399
-		$lien = $attrs['source'];
400
-	} else {
401
-		$chemin = $attrs['source'];
402
-	}
403
-	if (isset($attrs['type'])) {
404
-		$type = $attrs['type'];
405
-	}
406
-
407
-	$n = $phraseur->contenu['compatible'];
408
-	$phraseur->versions[$n]['script'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type];
395
+    $lien = $chemin = $type = $media = '';
396
+
397
+    include_spip('inc/utils');
398
+    if (tester_url_absolue($attrs['source'])) {
399
+        $lien = $attrs['source'];
400
+    } else {
401
+        $chemin = $attrs['source'];
402
+    }
403
+    if (isset($attrs['type'])) {
404
+        $type = $attrs['type'];
405
+    }
406
+
407
+    $n = $phraseur->contenu['compatible'];
408
+    $phraseur->versions[$n]['script'][] = ['url' => $lien, 'path' => $chemin, 'type' => $type];
409 409
 }
410 410
 
411 411
 /**
@@ -416,6 +416,6 @@  discard block
 block discarded – undo
416 416
  * @param string $texte
417 417
  */
418 418
 function info_paquet_genie($phraseur, $attrs, $texte) {
419
-	$n = $phraseur->contenu['compatible'];
420
-	$phraseur->versions[$n]['genie'][] = $attrs;
419
+    $n = $phraseur->contenu['compatible'];
420
+    $phraseur->versions[$n]['genie'][] = $attrs;
421 421
 }
Please login to merge, or discard this patch.
ecrire/plugins/extraire_boutons.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -21,31 +21,31 @@  discard block
 block discarded – undo
21 21
  * @return <type>
22 22
  */
23 23
 function plugins_extraire_boutons_dist($arbre) {
24
-	$les_boutons = null;
25
-	$ret = ['bouton' => [], 'onglet' => []];
26
-	// recuperer les boutons et onglets si necessaire
27
-	spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons);
28
-	if (is_array($les_boutons) && count($les_boutons)) {
29
-		$ret['bouton'] = [];
30
-		$ret['onglet'] = [];
31
-		foreach ($les_boutons as $bouton => $val) {
32
-			$bouton = spip_xml_decompose_tag($bouton);
33
-			$type = reset($bouton);
34
-			$bouton = end($bouton);
35
-			if (isset($bouton['id'])) {
36
-				$id = $bouton['id'];
37
-				$val = reset($val);
38
-				if (is_array($val)) {
39
-					$ret[$type][$id]['parent'] = $bouton['parent'] ?? '';
40
-					$ret[$type][$id]['position'] = $bouton['position'] ?? '';
41
-					$ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : '';
42
-					$ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : '';
43
-					$ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : '';
44
-					$ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : '';
45
-				}
46
-			}
47
-		}
48
-	}
24
+    $les_boutons = null;
25
+    $ret = ['bouton' => [], 'onglet' => []];
26
+    // recuperer les boutons et onglets si necessaire
27
+    spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons);
28
+    if (is_array($les_boutons) && count($les_boutons)) {
29
+        $ret['bouton'] = [];
30
+        $ret['onglet'] = [];
31
+        foreach ($les_boutons as $bouton => $val) {
32
+            $bouton = spip_xml_decompose_tag($bouton);
33
+            $type = reset($bouton);
34
+            $bouton = end($bouton);
35
+            if (isset($bouton['id'])) {
36
+                $id = $bouton['id'];
37
+                $val = reset($val);
38
+                if (is_array($val)) {
39
+                    $ret[$type][$id]['parent'] = $bouton['parent'] ?? '';
40
+                    $ret[$type][$id]['position'] = $bouton['position'] ?? '';
41
+                    $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : '';
42
+                    $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : '';
43
+                    $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : '';
44
+                    $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : '';
45
+                }
46
+            }
47
+        }
48
+    }
49 49
 
50
-	return $ret;
50
+    return $ret;
51 51
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_plugin.php 1 patch
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/charsets');
23 23
 include_spip('inc/texte');
@@ -25,214 +25,214 @@  discard block
 block discarded – undo
25 25
 
26 26
 // https://code.spip.net/@ligne_plug
27 27
 function plugins_afficher_plugin_dist(
28
-	$url_page,
29
-	$plug_file,
30
-	$checked,
31
-	$actif,
32
-	$expose = false,
33
-	$class_li = 'item',
34
-	$dir_plugins = _DIR_PLUGINS
28
+    $url_page,
29
+    $plug_file,
30
+    $checked,
31
+    $actif,
32
+    $expose = false,
33
+    $class_li = 'item',
34
+    $dir_plugins = _DIR_PLUGINS
35 35
 ) {
36 36
 
37
-	static $id_input = 0;
38
-	static $versions = [];
39
-
40
-	$force_reload = (_request('var_mode') == 'recalcul');
41
-	$get_infos = charger_fonction('get_infos', 'plugins');
42
-	$info = $get_infos($plug_file, $force_reload, $dir_plugins);
43
-	$prefix = $info['prefix'];
44
-	$cfg = '';
45
-	$checkable = ($dir_plugins !== _DIR_PLUGINS_DIST);
46
-	$nom = plugin_nom($info, $dir_plugins, $plug_file);
47
-	$erreur = '';
48
-
49
-	if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
50
-		$info['slogan'] = _T('plugin_info_non_compatible_spip');
51
-		$erreur = http_img_pack(
52
-			'plugin-dis-32.png',
53
-			_T('plugin_info_non_compatible_spip'),
54
-			" class='picto_err'",
55
-			_T('plugin_info_non_compatible_spip')
56
-		);
57
-		$class_li .= ' disabled';
58
-		$checkable = false;
59
-	} elseif (isset($info['erreur'])) {
60
-		$class_li .= ' error';
61
-		$erreur = http_img_pack(
62
-			'plugin-err-32.png',
63
-			_T('plugin_info_erreur_xml'),
64
-			" class='picto_err'",
65
-			_T('plugin_info_erreur_xml')
66
-		)
67
-			. "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
68
-		$checkable = false;
69
-	} elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) {
70
-		$class_li .= ' error';
71
-		$erreur = http_img_pack(
72
-			'plugin-err-32.png',
73
-			_T('plugin_impossible_activer', ['plugin' => $nom]),
74
-			" class='picto_err'",
75
-			_T('plugin_impossible_activer', ['plugin' => $nom])
76
-		)
77
-			. "<div class='erreur'>" . implode(
78
-				'<br />',
79
-				$GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]
80
-			) . '</div>';
81
-	} else {
82
-		$cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : '';
83
-		if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) {
84
-			//$info['slogan'] = _T('plugin_info_non_compatible_spip');
85
-			$erreur = http_img_pack(
86
-				'plugin-dis-32.png',
87
-				_T('plugin_info_non_compatible_spip'),
88
-				" class='picto_err picto_compat_forcee'",
89
-				_L('Version incompatible : compatibilité forcée')
90
-			);
91
-		}
92
-	}
93
-
94
-	// numerotons les occurrences d'un meme prefix
95
-	$versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : '';
96
-
97
-	$class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : '');
98
-
99
-	return "<li id='$prefix$id' class='$class_li'>"
100
-	. ((!$checkable and !$checked)
101
-		? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked))
102
-	. plugin_resume($info, $dir_plugins, $plug_file, $url_page)
103
-	. $cfg
104
-	. $erreur
105
-	. (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file))
106
-		? plugin_desintalle($plug_file, $nom, $dir_plugins) : '')
107
-	. "<div class='details'>" // pour l'ajax de exec/info_plugin
108
-	. (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins))
109
-	. '</div>'
110
-	. '</li>';
37
+    static $id_input = 0;
38
+    static $versions = [];
39
+
40
+    $force_reload = (_request('var_mode') == 'recalcul');
41
+    $get_infos = charger_fonction('get_infos', 'plugins');
42
+    $info = $get_infos($plug_file, $force_reload, $dir_plugins);
43
+    $prefix = $info['prefix'];
44
+    $cfg = '';
45
+    $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST);
46
+    $nom = plugin_nom($info, $dir_plugins, $plug_file);
47
+    $erreur = '';
48
+
49
+    if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
50
+        $info['slogan'] = _T('plugin_info_non_compatible_spip');
51
+        $erreur = http_img_pack(
52
+            'plugin-dis-32.png',
53
+            _T('plugin_info_non_compatible_spip'),
54
+            " class='picto_err'",
55
+            _T('plugin_info_non_compatible_spip')
56
+        );
57
+        $class_li .= ' disabled';
58
+        $checkable = false;
59
+    } elseif (isset($info['erreur'])) {
60
+        $class_li .= ' error';
61
+        $erreur = http_img_pack(
62
+            'plugin-err-32.png',
63
+            _T('plugin_info_erreur_xml'),
64
+            " class='picto_err'",
65
+            _T('plugin_info_erreur_xml')
66
+        )
67
+            . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
68
+        $checkable = false;
69
+    } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) {
70
+        $class_li .= ' error';
71
+        $erreur = http_img_pack(
72
+            'plugin-err-32.png',
73
+            _T('plugin_impossible_activer', ['plugin' => $nom]),
74
+            " class='picto_err'",
75
+            _T('plugin_impossible_activer', ['plugin' => $nom])
76
+        )
77
+            . "<div class='erreur'>" . implode(
78
+                '<br />',
79
+                $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]
80
+            ) . '</div>';
81
+    } else {
82
+        $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : '';
83
+        if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) {
84
+            //$info['slogan'] = _T('plugin_info_non_compatible_spip');
85
+            $erreur = http_img_pack(
86
+                'plugin-dis-32.png',
87
+                _T('plugin_info_non_compatible_spip'),
88
+                " class='picto_err picto_compat_forcee'",
89
+                _L('Version incompatible : compatibilité forcée')
90
+            );
91
+        }
92
+    }
93
+
94
+    // numerotons les occurrences d'un meme prefix
95
+    $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : '';
96
+
97
+    $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : '');
98
+
99
+    return "<li id='$prefix$id' class='$class_li'>"
100
+    . ((!$checkable and !$checked)
101
+        ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked))
102
+    . plugin_resume($info, $dir_plugins, $plug_file, $url_page)
103
+    . $cfg
104
+    . $erreur
105
+    . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file))
106
+        ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '')
107
+    . "<div class='details'>" // pour l'ajax de exec/info_plugin
108
+    . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins))
109
+    . '</div>'
110
+    . '</li>';
111 111
 }
112 112
 
113 113
 function plugin_bouton_config($nom, $infos, $dir) {
114
-	// la verification se base sur le filesystem
115
-	// il faut donc n'utiliser que des minuscules, par convention
116
-	$prefix = strtolower($infos['prefix']);
117
-	// si paquet.xml fournit un squelette, le prendre
118
-	if (isset($infos['config']) and $infos['config']) {
119
-		return recuperer_fond(
120
-			"$dir$nom/" . $infos['config'],
121
-			[
122
-				'script' => 'configurer_' . $prefix,
123
-				'nom' => $nom
124
-			]
125
-		);
126
-	}
127
-
128
-	// si le plugin CFG est la, l'essayer
129
-	if (defined('_DIR_PLUGIN_CFG')) {
130
-		if (include_spip('inc/cfg')) { // test CFG version >= 1.0.5
131
-		if ($cfg = icone_lien_cfg("$dir$nom", 'cfg')) {
132
-				return "<div class='cfg_link'>$cfg</div>";
133
-		}
134
-		}
135
-	}
136
-
137
-	// sinon prendre le squelette std sur le nom std
138
-	return recuperer_fond(
139
-		'prive/squelettes/inclure/cfg',
140
-		[
141
-			'script' => 'configurer_' . $prefix,
142
-			'nom' => $nom
143
-		]
144
-	);
114
+    // la verification se base sur le filesystem
115
+    // il faut donc n'utiliser que des minuscules, par convention
116
+    $prefix = strtolower($infos['prefix']);
117
+    // si paquet.xml fournit un squelette, le prendre
118
+    if (isset($infos['config']) and $infos['config']) {
119
+        return recuperer_fond(
120
+            "$dir$nom/" . $infos['config'],
121
+            [
122
+                'script' => 'configurer_' . $prefix,
123
+                'nom' => $nom
124
+            ]
125
+        );
126
+    }
127
+
128
+    // si le plugin CFG est la, l'essayer
129
+    if (defined('_DIR_PLUGIN_CFG')) {
130
+        if (include_spip('inc/cfg')) { // test CFG version >= 1.0.5
131
+        if ($cfg = icone_lien_cfg("$dir$nom", 'cfg')) {
132
+                return "<div class='cfg_link'>$cfg</div>";
133
+        }
134
+        }
135
+    }
136
+
137
+    // sinon prendre le squelette std sur le nom std
138
+    return recuperer_fond(
139
+        'prive/squelettes/inclure/cfg',
140
+        [
141
+            'script' => 'configurer_' . $prefix,
142
+            'nom' => $nom
143
+        ]
144
+    );
145 145
 }
146 146
 
147 147
 // checkbox pour activer ou desactiver
148 148
 // si ce n'est pas une extension
149 149
 
150 150
 function plugin_checkbox($id_input, $file, $actif) {
151
-	$name = substr(md5($file), 0, 16);
152
-
153
-	return "<div class='check'>\n"
154
-	. "<input type='checkbox' name='s$name' id='label_$id_input'"
155
-	. ($actif ? " checked='checked'" : '')
156
-	. " class='checkbox'  value='O' />"
157
-	. "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>'
158
-	. '</div>';
151
+    $name = substr(md5($file), 0, 16);
152
+
153
+    return "<div class='check'>\n"
154
+    . "<input type='checkbox' name='s$name' id='label_$id_input'"
155
+    . ($actif ? " checked='checked'" : '')
156
+    . " class='checkbox'  value='O' />"
157
+    . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>'
158
+    . '</div>';
159 159
 }
160 160
 
161 161
 function plugin_nom($info, $dir_plugins, $plug_file) {
162
-	$prefix = $info['prefix'];
163
-	$dir = "$dir_plugins$plug_file";
164
-	// Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom"
165
-	if ($info['dtd'] == 'paquet') {
166
-		$nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix");
167
-		if (!$nom) {
168
-			$nom = typo($info['nom']);
169
-		}
170
-	} else {
171
-		$nom = typo(attribut_html($info['nom']));
172
-	}
173
-
174
-	return trim($nom);
162
+    $prefix = $info['prefix'];
163
+    $dir = "$dir_plugins$plug_file";
164
+    // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom"
165
+    if ($info['dtd'] == 'paquet') {
166
+        $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix");
167
+        if (!$nom) {
168
+            $nom = typo($info['nom']);
169
+        }
170
+    } else {
171
+        $nom = typo(attribut_html($info['nom']));
172
+    }
173
+
174
+    return trim($nom);
175 175
 }
176 176
 
177 177
 // Cartouche Resume
178 178
 function plugin_resume($info, $dir_plugins, $plug_file, $url_page) {
179
-	$prefix = $info['prefix'];
180
-	$dir = "$dir_plugins$plug_file";
181
-	$slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix"));
182
-	// une seule ligne dans le slogan : couper si besoin
183
-	if (($p = strpos($slogan, '<br />')) !== false) {
184
-		$slogan = substr($slogan, 0, $p);
185
-	}
186
-	// couper par securite
187
-	$slogan = couper($slogan, 80);
188
-
189
-	$nom = plugin_nom($info, $dir_plugins, $plug_file);
190
-
191
-	$url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE)));
192
-
193
-	$icon_class = 'icon';
194
-	$img = '';
195
-	if (isset($info['logo']) and $i = trim($info['logo'])) {
196
-		$img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]);
197
-		if (!extraire_attribut($img, 'src')) {
198
-			$img = '';
199
-		}
200
-	}
201
-	if (!$img) {
202
-		$img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'");
203
-		$icon_class .= ' no-logo';
204
-	}
205
-
206
-	$i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>";
207
-
208
-	return "<div class='resume'>"
209
-	. "<h3><a href='$url' rel='info'>"
210
-	. $nom
211
-	. '</a></h3>'
212
-	. " <span class='version'>" . $info['version'] . '</span>'
213
-	. " <span class='etat'> - "
214
-	. plugin_etat_en_clair($info['etat'])
215
-	. '</span>'
216
-	. "<div class='short'>" . $slogan . '</div>'
217
-	. $i
218
-	. '</div>';
179
+    $prefix = $info['prefix'];
180
+    $dir = "$dir_plugins$plug_file";
181
+    $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix"));
182
+    // une seule ligne dans le slogan : couper si besoin
183
+    if (($p = strpos($slogan, '<br />')) !== false) {
184
+        $slogan = substr($slogan, 0, $p);
185
+    }
186
+    // couper par securite
187
+    $slogan = couper($slogan, 80);
188
+
189
+    $nom = plugin_nom($info, $dir_plugins, $plug_file);
190
+
191
+    $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE)));
192
+
193
+    $icon_class = 'icon';
194
+    $img = '';
195
+    if (isset($info['logo']) and $i = trim($info['logo'])) {
196
+        $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]);
197
+        if (!extraire_attribut($img, 'src')) {
198
+            $img = '';
199
+        }
200
+    }
201
+    if (!$img) {
202
+        $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'");
203
+        $icon_class .= ' no-logo';
204
+    }
205
+
206
+    $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>";
207
+
208
+    return "<div class='resume'>"
209
+    . "<h3><a href='$url' rel='info'>"
210
+    . $nom
211
+    . '</a></h3>'
212
+    . " <span class='version'>" . $info['version'] . '</span>'
213
+    . " <span class='etat'> - "
214
+    . plugin_etat_en_clair($info['etat'])
215
+    . '</span>'
216
+    . "<div class='short'>" . $slogan . '</div>'
217
+    . $i
218
+    . '</div>';
219 219
 }
220 220
 
221 221
 function plugin_desintalle($plug_file, $nom, $dir_plugins = null) {
222
-	if (!$dir_plugins) {
223
-		$dir_plugins = _DIR_PLUGINS;
224
-	}
222
+    if (!$dir_plugins) {
223
+        $dir_plugins = _DIR_PLUGINS;
224
+    }
225 225
 
226
-	$action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin');
227
-	$text = _T('bouton_desinstaller');
228
-	$text2 = _T('info_desinstaller_plugin');
229
-	$file = basename($plug_file);
226
+    $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin');
227
+    $text = _T('bouton_desinstaller');
228
+    $text2 = _T('info_desinstaller_plugin');
229
+    $file = basename($plug_file);
230 230
 
231
-	return "<div class='actions'>[" .
232
-	"<a href='$action'
231
+    return "<div class='actions'>[" .
232
+    "<a href='$action'
233 233
 		onclick='return confirm(\"$text $nom ?\\n$text2\")'>"
234
-	. $text
235
-	. '</a>]</div>';
234
+    . $text
235
+    . '</a>]</div>';
236 236
 }
237 237
 
238 238
 /**
@@ -246,147 +246,147 @@  discard block
 block discarded – undo
246 246
  *     Traduction de l'état dans la langue en cours
247 247
  **/
248 248
 function plugin_etat_en_clair($etat) {
249
-	if (!in_array($etat, ['stable', 'test', 'experimental'])) {
250
-		$etat = 'developpement';
251
-	}
249
+    if (!in_array($etat, ['stable', 'test', 'experimental'])) {
250
+        $etat = 'developpement';
251
+    }
252 252
 
253
-	return _T('plugin_etat_' . $etat);
253
+    return _T('plugin_etat_' . $etat);
254 254
 }
255 255
 
256 256
 // https://code.spip.net/@plugin_propre
257 257
 function plugin_propre($texte, $module = '', $propre = 'propre') {
258
-	// retirer le retour a la racine du module, car le find_in_path se fait depuis la racine
259
-	if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
260
-		$module = substr($module, strlen(_DIR_RACINE));
261
-	}
262
-	if (preg_match('|^\w+_[\w_]+$|', $texte)) {
263
-		$texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]);
264
-	}
265
-
266
-	return $propre($texte);
258
+    // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine
259
+    if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
260
+        $module = substr($module, strlen(_DIR_RACINE));
261
+    }
262
+    if (preg_match('|^\w+_[\w_]+$|', $texte)) {
263
+        $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]);
264
+    }
265
+
266
+    return $propre($texte);
267 267
 }
268 268
 
269 269
 function plugin_typo($texte, $module = '') {
270
-	return plugin_propre($texte, $module, 'typo');
270
+    return plugin_propre($texte, $module, 'typo');
271 271
 }
272 272
 
273 273
 
274 274
 // https://code.spip.net/@affiche_bloc_plugin
275 275
 function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) {
276
-	$log = null;
277
-	if (!$dir_plugins) {
278
-		$dir_plugins = _DIR_PLUGINS;
279
-	}
280
-
281
-	$prefix = $info['prefix'];
282
-	$dir = "$dir_plugins$plug_file/lang/paquet-$prefix";
283
-
284
-	$s = '';
285
-	// TODO: le traiter_multi ici n'est pas beau
286
-	// cf. description du plugin/_stable_/ortho/plugin.xml
287
-	// concerne les anciens plugin.xml donc on devrait plus en avoir besoin
288
-	$description = '';
289
-	if (isset($info['description'])) {
290
-		$description = plugin_propre($info['description'], $dir);
291
-	}
292
-
293
-	if (
294
-		isset($info['documentation'])
295
-		and $lien = $info['documentation']
296
-	) {
297
-		$description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>';
298
-	}
299
-	$s .= "<dd class='desc'>" . $description . "</dd>\n";
300
-
301
-	if (isset($info['auteur'])) {
302
-		if (is_array($info['auteur'])) {
303
-			$a = formater_credits($info['auteur'], ', ');
304
-		} // pour compat mais ne doit plus arriver
305
-		else {
306
-			$a = trim($info['auteur']);
307
-		}
308
-		if ($a) {
309
-			$s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre(
310
-				$a,
311
-				$dir
312
-			)) . "</dd>\n";
313
-		}
314
-	}
315
-
316
-	if (isset($info['credit'])) {
317
-		if ($a = formater_credits($info['credit'], ', ')) {
318
-			$s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre(
319
-				$a,
320
-				$dir
321
-			)) . "</dd>\n";
322
-		}
323
-	}
324
-
325
-	if (isset($info['licence'])) {
326
-		if (is_array($info['licence'])) {
327
-			$a = formater_credits($info['licence'], ', ');
328
-		} // pour compat mais ne doit plus arriver
329
-		else {
330
-			$a = trim($info['licence']);
331
-		}
332
-		if ($a) {
333
-			$s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre(
334
-				$a,
335
-				$dir
336
-			)) . "</dd>\n";
337
-		}
338
-	}
339
-
340
-	$s = "<dl class='description'>$s</dl>";
341
-
342
-	//
343
-	// Ajouter les infos techniques
344
-	//
345
-	$infotech = [];
346
-
347
-	$version = '<dt>' . _T('version') . '</dt><dd>' . $info['version'];
348
-	// Version VCS
349
-	if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) {
350
-		$version .= ' ' . $vcs;
351
-	}
352
-	$version .= '</dd>';
353
-	$infotech[] = $version;
354
-	$infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>';
355
-	// source zip le cas echeant
356
-	$infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log)
357
-		and preg_match(',^source:(.*)$,m', $log, $r))
358
-		? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>'
359
-		: '';
360
-
361
-	$infotech[] = !$info['necessite'] ? '' :
362
-		('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(
363
-			' ',
364
-			array_map('array_shift', $info['necessite'])
365
-		) . '</dd>');
366
-
367
-	$s .= "<dl class='tech'>"
368
-		. join('', $infotech)
369
-		. '</dl>';
370
-
371
-
372
-	return $s;
276
+    $log = null;
277
+    if (!$dir_plugins) {
278
+        $dir_plugins = _DIR_PLUGINS;
279
+    }
280
+
281
+    $prefix = $info['prefix'];
282
+    $dir = "$dir_plugins$plug_file/lang/paquet-$prefix";
283
+
284
+    $s = '';
285
+    // TODO: le traiter_multi ici n'est pas beau
286
+    // cf. description du plugin/_stable_/ortho/plugin.xml
287
+    // concerne les anciens plugin.xml donc on devrait plus en avoir besoin
288
+    $description = '';
289
+    if (isset($info['description'])) {
290
+        $description = plugin_propre($info['description'], $dir);
291
+    }
292
+
293
+    if (
294
+        isset($info['documentation'])
295
+        and $lien = $info['documentation']
296
+    ) {
297
+        $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>';
298
+    }
299
+    $s .= "<dd class='desc'>" . $description . "</dd>\n";
300
+
301
+    if (isset($info['auteur'])) {
302
+        if (is_array($info['auteur'])) {
303
+            $a = formater_credits($info['auteur'], ', ');
304
+        } // pour compat mais ne doit plus arriver
305
+        else {
306
+            $a = trim($info['auteur']);
307
+        }
308
+        if ($a) {
309
+            $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre(
310
+                $a,
311
+                $dir
312
+            )) . "</dd>\n";
313
+        }
314
+    }
315
+
316
+    if (isset($info['credit'])) {
317
+        if ($a = formater_credits($info['credit'], ', ')) {
318
+            $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre(
319
+                $a,
320
+                $dir
321
+            )) . "</dd>\n";
322
+        }
323
+    }
324
+
325
+    if (isset($info['licence'])) {
326
+        if (is_array($info['licence'])) {
327
+            $a = formater_credits($info['licence'], ', ');
328
+        } // pour compat mais ne doit plus arriver
329
+        else {
330
+            $a = trim($info['licence']);
331
+        }
332
+        if ($a) {
333
+            $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre(
334
+                $a,
335
+                $dir
336
+            )) . "</dd>\n";
337
+        }
338
+    }
339
+
340
+    $s = "<dl class='description'>$s</dl>";
341
+
342
+    //
343
+    // Ajouter les infos techniques
344
+    //
345
+    $infotech = [];
346
+
347
+    $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version'];
348
+    // Version VCS
349
+    if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) {
350
+        $version .= ' ' . $vcs;
351
+    }
352
+    $version .= '</dd>';
353
+    $infotech[] = $version;
354
+    $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>';
355
+    // source zip le cas echeant
356
+    $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log)
357
+        and preg_match(',^source:(.*)$,m', $log, $r))
358
+        ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>'
359
+        : '';
360
+
361
+    $infotech[] = !$info['necessite'] ? '' :
362
+        ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(
363
+            ' ',
364
+            array_map('array_shift', $info['necessite'])
365
+        ) . '</dd>');
366
+
367
+    $s .= "<dl class='tech'>"
368
+        . join('', $infotech)
369
+        . '</dl>';
370
+
371
+
372
+    return $s;
373 373
 }
374 374
 
375 375
 function formater_credits($infos, $sep = ', ') {
376
-	$texte = '';
377
-
378
-	foreach ($infos as $_credit) {
379
-		if ($texte) {
380
-			$texte .= $sep;
381
-		}
382
-		// Si le credit en cours n'est pas un array c'est donc un copyright
383
-		$texte .=
384
-			(!is_array($_credit))
385
-				? PtoBR(propre($_credit))
386
-				: ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') .
387
-				$_credit['nom'] .
388
-				($_credit['url'] ? '</a>' : '');
389
-	}
390
-
391
-	return $texte;
376
+    $texte = '';
377
+
378
+    foreach ($infos as $_credit) {
379
+        if ($texte) {
380
+            $texte .= $sep;
381
+        }
382
+        // Si le credit en cours n'est pas un array c'est donc un copyright
383
+        $texte .=
384
+            (!is_array($_credit))
385
+                ? PtoBR(propre($_credit))
386
+                : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') .
387
+                $_credit['nom'] .
388
+                ($_credit['url'] ? '</a>' : '');
389
+    }
390
+
391
+    return $texte;
392 392
 }
Please login to merge, or discard this patch.