Completed
Push — master ( 8ce9c8...350a8b )
by cam
01:02
created
ecrire/charsets/translit.php 1 patch
Indentation   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -9,384 +9,384 @@
 block discarded – undo
9 9
 
10 10
 $GLOBALS['CHARSET']['translit'] = [
11 11
 // latin [fausse plage]
12
-	128 => 'EUR',
13
-	131 => 'f',
14
-	140 => 'OE',
15
-	147 => '\'\'',
16
-	148 => '\'\'',
17
-	153 => '(TM)',
18
-	156 => 'oe',
19
-	159 => 'Y',
12
+    128 => 'EUR',
13
+    131 => 'f',
14
+    140 => 'OE',
15
+    147 => '\'\'',
16
+    148 => '\'\'',
17
+    153 => '(TM)',
18
+    156 => 'oe',
19
+    159 => 'Y',
20 20
 
21 21
 // latin [legal]
22
-	160 => ' ',
23
-	161 => '!',
24
-	162 => 'c',
25
-	163 => 'L',
26
-	164 => 'O',
27
-	165 => 'yen',
28
-	166 => '|',
29
-	167 => 'p',
30
-	169 => '(c)',
31
-	171 => '<<',
32
-	172 => '-',
33
-	173 => '-',
34
-	174 => '(R)',
35
-	176 => 'o',
36
-	177 => '+-',
37
-	181 => 'mu',
38
-	182 => 'p',
39
-	183 => '.',
40
-	186 => 'o ',
41
-	187 => '>>',
42
-	191 => '?',
43
-	192 => 'A',
44
-	193 => 'A',
45
-	194 => 'A',
46
-	195 => 'A',
47
-	196 => 'A',
48
-	197 => 'A',
49
-	198 => 'AE',
50
-	199 => 'C',
51
-	200 => 'E',
52
-	201 => 'E',
53
-	202 => 'E',
54
-	203 => 'E',
55
-	204 => 'I',
56
-	205 => 'I',
57
-	206 => 'I',
58
-	207 => 'I',
59
-	209 => 'N',
60
-	210 => 'O',
61
-	211 => 'O',
62
-	212 => 'O',
63
-	213 => 'O',
64
-	214 => 'O',
65
-	216 => 'O',
66
-	217 => 'U',
67
-	218 => 'U',
68
-	219 => 'U',
69
-	220 => 'U',
70
-	223 => 'ss',
71
-	224 => 'a',
72
-	225 => 'a',
73
-	226 => 'a',
74
-	227 => 'a',
75
-	228 => 'a',
76
-	229 => 'a',
77
-	230 => 'ae',
78
-	231 => 'c',
79
-	232 => 'e',
80
-	233 => 'e',
81
-	234 => 'e',
82
-	235 => 'e',
83
-	236 => 'i',
84
-	237 => 'i',
85
-	238 => 'i',
86
-	239 => 'i',
87
-	241 => 'n',
88
-	242 => 'o',
89
-	243 => 'o',
90
-	244 => 'o',
91
-	245 => 'o',
92
-	246 => 'o',
93
-	248 => 'o',
94
-	249 => 'u',
95
-	250 => 'u',
96
-	251 => 'u',
97
-	252 => 'u',
98
-	255 => 'y',
22
+    160 => ' ',
23
+    161 => '!',
24
+    162 => 'c',
25
+    163 => 'L',
26
+    164 => 'O',
27
+    165 => 'yen',
28
+    166 => '|',
29
+    167 => 'p',
30
+    169 => '(c)',
31
+    171 => '<<',
32
+    172 => '-',
33
+    173 => '-',
34
+    174 => '(R)',
35
+    176 => 'o',
36
+    177 => '+-',
37
+    181 => 'mu',
38
+    182 => 'p',
39
+    183 => '.',
40
+    186 => 'o ',
41
+    187 => '>>',
42
+    191 => '?',
43
+    192 => 'A',
44
+    193 => 'A',
45
+    194 => 'A',
46
+    195 => 'A',
47
+    196 => 'A',
48
+    197 => 'A',
49
+    198 => 'AE',
50
+    199 => 'C',
51
+    200 => 'E',
52
+    201 => 'E',
53
+    202 => 'E',
54
+    203 => 'E',
55
+    204 => 'I',
56
+    205 => 'I',
57
+    206 => 'I',
58
+    207 => 'I',
59
+    209 => 'N',
60
+    210 => 'O',
61
+    211 => 'O',
62
+    212 => 'O',
63
+    213 => 'O',
64
+    214 => 'O',
65
+    216 => 'O',
66
+    217 => 'U',
67
+    218 => 'U',
68
+    219 => 'U',
69
+    220 => 'U',
70
+    223 => 'ss',
71
+    224 => 'a',
72
+    225 => 'a',
73
+    226 => 'a',
74
+    227 => 'a',
75
+    228 => 'a',
76
+    229 => 'a',
77
+    230 => 'ae',
78
+    231 => 'c',
79
+    232 => 'e',
80
+    233 => 'e',
81
+    234 => 'e',
82
+    235 => 'e',
83
+    236 => 'i',
84
+    237 => 'i',
85
+    238 => 'i',
86
+    239 => 'i',
87
+    241 => 'n',
88
+    242 => 'o',
89
+    243 => 'o',
90
+    244 => 'o',
91
+    245 => 'o',
92
+    246 => 'o',
93
+    248 => 'o',
94
+    249 => 'u',
95
+    250 => 'u',
96
+    251 => 'u',
97
+    252 => 'u',
98
+    255 => 'y',
99 99
 
100 100
 // turc
101
-	286 => 'G',
102
-	287 => 'g',
103
-	304 => 'I',
104
-	305 => 'i',
101
+    286 => 'G',
102
+    287 => 'g',
103
+    304 => 'I',
104
+    305 => 'i',
105 105
 
106 106
 // esperanto
107
-	264 => 'Cx',
108
-	265 => 'cx',
109
-	284 => 'Gx',
110
-	285 => 'gx',
111
-	292 => 'Hx',
112
-	293 => 'hx',
113
-	308 => 'Jx',
114
-	309 => 'jx',
115
-	348 => 'Sx',
116
-	349 => 'sx',
117
-	364 => 'Ux',
118
-	365 => 'ux',
107
+    264 => 'Cx',
108
+    265 => 'cx',
109
+    284 => 'Gx',
110
+    285 => 'gx',
111
+    292 => 'Hx',
112
+    293 => 'hx',
113
+    308 => 'Jx',
114
+    309 => 'jx',
115
+    348 => 'Sx',
116
+    349 => 'sx',
117
+    364 => 'Ux',
118
+    365 => 'ux',
119 119
 
120 120
 
121 121
 // latin2 [Czech]
122
-	283 => 'e',
123
-	353 => 's',
124
-	269 => 'c',
125
-	345 => 'r',
126
-	382 => 'z',
127
-	367 => 'u',
128
-	328 => 'n',
129
-	357 => 't',
130
-	271 => 'd',
131
-	449 => 'o',
132
-	282 => 'E',
133
-	352 => 'S',
134
-	268 => 'C',
135
-	344 => 'R',
136
-	381 => 'Z',
137
-	366 => 'U',
138
-	327 => 'N',
139
-	356 => 'T',
140
-	270 => 'D',
141
-	467 => 'O',
122
+    283 => 'e',
123
+    353 => 's',
124
+    269 => 'c',
125
+    345 => 'r',
126
+    382 => 'z',
127
+    367 => 'u',
128
+    328 => 'n',
129
+    357 => 't',
130
+    271 => 'd',
131
+    449 => 'o',
132
+    282 => 'E',
133
+    352 => 'S',
134
+    268 => 'C',
135
+    344 => 'R',
136
+    381 => 'Z',
137
+    366 => 'U',
138
+    327 => 'N',
139
+    356 => 'T',
140
+    270 => 'D',
141
+    467 => 'O',
142 142
 
143 143
 // francais
144
-	338 => 'OE',
145
-	339 => 'oe',
146
-	376 => 'Y',
147
-	402 => 'f',
144
+    338 => 'OE',
145
+    339 => 'oe',
146
+    376 => 'Y',
147
+    402 => 'f',
148 148
 
149 149
 //polskie
150
-	260 => 'A',
151
-	261 => 'a',
152
-	262 => 'C',
153
-	263 => 'c',
154
-	280 => 'E',
155
-	281 => 'e',
156
-	321 => 'L',
157
-	322 => 'l',
158
-	323 => 'N',
159
-	324 => 'n',
160
-	346 => 'S',
161
-	347 => 's',
162
-	377 => 'Z',
163
-	378 => 'z',
164
-	379 => 'Z',
165
-	380 => 'z',
150
+    260 => 'A',
151
+    261 => 'a',
152
+    262 => 'C',
153
+    263 => 'c',
154
+    280 => 'E',
155
+    281 => 'e',
156
+    321 => 'L',
157
+    322 => 'l',
158
+    323 => 'N',
159
+    324 => 'n',
160
+    346 => 'S',
161
+    347 => 's',
162
+    377 => 'Z',
163
+    378 => 'z',
164
+    379 => 'Z',
165
+    380 => 'z',
166 166
 
167 167
 //roumain
168
-	258 => 'A',
169
-	259 => 'a',
170
-	354 => 'T',
171
-	355 => 't',
168
+    258 => 'A',
169
+    259 => 'a',
170
+    354 => 'T',
171
+    355 => 't',
172 172
 
173 173
 //turc & roumain
174
-	350 => 'S',
175
-	351 => 's',
174
+    350 => 'S',
175
+    351 => 's',
176 176
 
177 177
 // cyrillique
178
-	1026 => 'D%',
179
-	1027 => 'G%',
180
-	8218 => '\'',
181
-	1107 => 'g%',
182
-	8222 => '"',
183
-	8230 => '...',
184
-	8224 => '/-',
185
-	8225 => '/=',
186
-	8364 => 'EUR',
187
-	8240 => '0/00',
188
-	1033 => 'LJ',
189
-	8249 => '<',
190
-	1034 => 'NJ',
191
-	1036 => 'KJ',
192
-	1035 => 'Ts',
193
-	1039 => 'DZ',
194
-	1106 => 'd%',
195
-	8216 => '`',
196
-	8217 => '\'',
197
-	8220 => '"',
198
-	8221 => '"',
199
-	8226 => ' o ',
200
-	8211 => '-',
201
-	8212 => '~',
202
-	8482 => '(TM)',
203
-	1113 => 'lj',
204
-	8250 => '>',
205
-	1114 => 'nj',
206
-	1116 => 'kj',
207
-	1115 => 'ts',
208
-	1119 => 'dz',
209
-	1038 => 'V%',
210
-	1118 => 'v%',
211
-	1032 => 'J%',
212
-	1168 => 'G3',
213
-	1025 => 'IO',
214
-	1028 => 'IE',
215
-	1031 => 'YI',
216
-	1030 => 'II',
217
-	1110 => 'ii',
218
-	1169 => 'g3',
219
-	1105 => 'io',
220
-	8470 => 'No.',
221
-	1108 => 'ie',
222
-	1112 => 'j%',
223
-	1029 => 'DS',
224
-	1109 => 'ds',
225
-	1111 => 'yi',
226
-	1040 => 'A',
227
-	1041 => 'B',
228
-	1042 => 'V',
229
-	1043 => 'G',
230
-	1044 => 'D',
231
-	1045 => 'E',
232
-	1046 => 'ZH',
233
-	1047 => 'Z',
234
-	1048 => 'I',
235
-	1049 => 'J',
236
-	1050 => 'K',
237
-	1051 => 'L',
238
-	1052 => 'M',
239
-	1053 => 'N',
240
-	1054 => 'O',
241
-	1055 => 'P',
242
-	1056 => 'R',
243
-	1057 => 'S',
244
-	1058 => 'T',
245
-	1059 => 'U',
246
-	1060 => 'F',
247
-	1061 => 'H',
248
-	1062 => 'C',
249
-	1063 => 'CH',
250
-	1064 => 'SH',
251
-	1065 => 'SCH',
252
-	1066 => '"',
253
-	1067 => 'Y',
254
-	1068 => '\'',
255
-	1069 => '`E',
256
-	1070 => 'YU',
257
-	1071 => 'YA',
258
-	1072 => 'a',
259
-	1073 => 'b',
260
-	1074 => 'v',
261
-	1075 => 'g',
262
-	1076 => 'd',
263
-	1077 => 'e',
264
-	1078 => 'zh',
265
-	1079 => 'z',
266
-	1080 => 'i',
267
-	1081 => 'j',
268
-	1082 => 'k',
269
-	1083 => 'l',
270
-	1084 => 'm',
271
-	1085 => 'n',
272
-	1086 => 'o',
273
-	1087 => 'p',
274
-	1088 => 'r',
275
-	1089 => 's',
276
-	1090 => 't',
277
-	1091 => 'u',
278
-	1092 => 'f',
279
-	1093 => 'h',
280
-	1094 => 'c',
281
-	1095 => 'ch',
282
-	1096 => 'sh',
283
-	1097 => 'sch',
284
-	1098 => '"',
285
-	1099 => 'y',
286
-	1100 => '\'',
287
-	1101 => '`e',
288
-	1102 => 'yu',
289
-	1103 => 'ya',
178
+    1026 => 'D%',
179
+    1027 => 'G%',
180
+    8218 => '\'',
181
+    1107 => 'g%',
182
+    8222 => '"',
183
+    8230 => '...',
184
+    8224 => '/-',
185
+    8225 => '/=',
186
+    8364 => 'EUR',
187
+    8240 => '0/00',
188
+    1033 => 'LJ',
189
+    8249 => '<',
190
+    1034 => 'NJ',
191
+    1036 => 'KJ',
192
+    1035 => 'Ts',
193
+    1039 => 'DZ',
194
+    1106 => 'd%',
195
+    8216 => '`',
196
+    8217 => '\'',
197
+    8220 => '"',
198
+    8221 => '"',
199
+    8226 => ' o ',
200
+    8211 => '-',
201
+    8212 => '~',
202
+    8482 => '(TM)',
203
+    1113 => 'lj',
204
+    8250 => '>',
205
+    1114 => 'nj',
206
+    1116 => 'kj',
207
+    1115 => 'ts',
208
+    1119 => 'dz',
209
+    1038 => 'V%',
210
+    1118 => 'v%',
211
+    1032 => 'J%',
212
+    1168 => 'G3',
213
+    1025 => 'IO',
214
+    1028 => 'IE',
215
+    1031 => 'YI',
216
+    1030 => 'II',
217
+    1110 => 'ii',
218
+    1169 => 'g3',
219
+    1105 => 'io',
220
+    8470 => 'No.',
221
+    1108 => 'ie',
222
+    1112 => 'j%',
223
+    1029 => 'DS',
224
+    1109 => 'ds',
225
+    1111 => 'yi',
226
+    1040 => 'A',
227
+    1041 => 'B',
228
+    1042 => 'V',
229
+    1043 => 'G',
230
+    1044 => 'D',
231
+    1045 => 'E',
232
+    1046 => 'ZH',
233
+    1047 => 'Z',
234
+    1048 => 'I',
235
+    1049 => 'J',
236
+    1050 => 'K',
237
+    1051 => 'L',
238
+    1052 => 'M',
239
+    1053 => 'N',
240
+    1054 => 'O',
241
+    1055 => 'P',
242
+    1056 => 'R',
243
+    1057 => 'S',
244
+    1058 => 'T',
245
+    1059 => 'U',
246
+    1060 => 'F',
247
+    1061 => 'H',
248
+    1062 => 'C',
249
+    1063 => 'CH',
250
+    1064 => 'SH',
251
+    1065 => 'SCH',
252
+    1066 => '"',
253
+    1067 => 'Y',
254
+    1068 => '\'',
255
+    1069 => '`E',
256
+    1070 => 'YU',
257
+    1071 => 'YA',
258
+    1072 => 'a',
259
+    1073 => 'b',
260
+    1074 => 'v',
261
+    1075 => 'g',
262
+    1076 => 'd',
263
+    1077 => 'e',
264
+    1078 => 'zh',
265
+    1079 => 'z',
266
+    1080 => 'i',
267
+    1081 => 'j',
268
+    1082 => 'k',
269
+    1083 => 'l',
270
+    1084 => 'm',
271
+    1085 => 'n',
272
+    1086 => 'o',
273
+    1087 => 'p',
274
+    1088 => 'r',
275
+    1089 => 's',
276
+    1090 => 't',
277
+    1091 => 'u',
278
+    1092 => 'f',
279
+    1093 => 'h',
280
+    1094 => 'c',
281
+    1095 => 'ch',
282
+    1096 => 'sh',
283
+    1097 => 'sch',
284
+    1098 => '"',
285
+    1099 => 'y',
286
+    1100 => '\'',
287
+    1101 => '`e',
288
+    1102 => 'yu',
289
+    1103 => 'ya',
290 290
 
291 291
 // vietnamien en translitteration de base
292
-	7843 => 'a',
293
-	7841 => 'a',
294
-	7845 => 'a',
295
-	7847 => 'a',
296
-	7849 => 'a',
297
-	7851 => 'a',
298
-	7853 => 'a',
299
-	7855 => 'a',
300
-	7857 => 'a',
301
-	7859 => 'a',
302
-	7861 => 'a',
303
-	7863 => 'a',
304
-	7842 => 'A',
305
-	7840 => 'A',
306
-	7844 => 'A',
307
-	7846 => 'A',
308
-	7848 => 'A',
309
-	7850 => 'A',
310
-	7852 => 'A',
311
-	7854 => 'A',
312
-	7856 => 'A',
313
-	7858 => 'A',
314
-	7860 => 'A',
315
-	7862 => 'A',
316
-	7867 => 'e',
317
-	7869 => 'e',
318
-	7865 => 'e',
319
-	7871 => 'e',
320
-	7873 => 'e',
321
-	7875 => 'e',
322
-	7877 => 'e',
323
-	7879 => 'e',
324
-	7866 => 'E',
325
-	7868 => 'E',
326
-	7864 => 'E',
327
-	7870 => 'E',
328
-	7872 => 'E',
329
-	7874 => 'E',
330
-	7876 => 'E',
331
-	7878 => 'E',
332
-	7881 => 'i',
333
-	7883 => 'i',
334
-	7880 => 'I',
335
-	7882 => 'I',
336
-	7887 => 'o',
337
-	7885 => 'o',
338
-	7889 => 'o',
339
-	7891 => 'o',
340
-	7893 => 'o',
341
-	7895 => 'o',
342
-	7897 => 'o',
343
-	417 => 'o',
344
-	7899 => 'o',
345
-	7901 => 'o',
346
-	7903 => 'o',
347
-	7905 => 'o',
348
-	7907 => 'o',
349
-	7886 => 'O',
350
-	7884 => 'O',
351
-	7888 => 'O',
352
-	7890 => 'O',
353
-	7892 => 'O',
354
-	7894 => 'O',
355
-	7896 => 'O',
356
-	416 => 'O',
357
-	7898 => 'O',
358
-	7900 => 'O',
359
-	7902 => 'O',
360
-	7904 => 'O',
361
-	7906 => 'O',
362
-	7911 => 'u',
363
-	361 => 'u',
364
-	7909 => 'u',
365
-	432 => 'u',
366
-	7913 => 'u',
367
-	7915 => 'u',
368
-	7917 => 'u',
369
-	7919 => 'u',
370
-	7921 => 'u',
371
-	7910 => 'U',
372
-	360 => 'U',
373
-	7908 => 'U',
374
-	431 => 'U',
375
-	7912 => 'U',
376
-	7914 => 'U',
377
-	7916 => 'U',
378
-	7918 => 'U',
379
-	7920 => 'U',
380
-	253 => 'y',
381
-	7923 => 'y',
382
-	7927 => 'y',
383
-	7929 => 'y',
384
-	7925 => 'y',
385
-	221 => 'Y',
386
-	7922 => 'Y',
387
-	7926 => 'Y',
388
-	7928 => 'Y',
389
-	7924 => 'Y',
390
-	273 => 'd'
292
+    7843 => 'a',
293
+    7841 => 'a',
294
+    7845 => 'a',
295
+    7847 => 'a',
296
+    7849 => 'a',
297
+    7851 => 'a',
298
+    7853 => 'a',
299
+    7855 => 'a',
300
+    7857 => 'a',
301
+    7859 => 'a',
302
+    7861 => 'a',
303
+    7863 => 'a',
304
+    7842 => 'A',
305
+    7840 => 'A',
306
+    7844 => 'A',
307
+    7846 => 'A',
308
+    7848 => 'A',
309
+    7850 => 'A',
310
+    7852 => 'A',
311
+    7854 => 'A',
312
+    7856 => 'A',
313
+    7858 => 'A',
314
+    7860 => 'A',
315
+    7862 => 'A',
316
+    7867 => 'e',
317
+    7869 => 'e',
318
+    7865 => 'e',
319
+    7871 => 'e',
320
+    7873 => 'e',
321
+    7875 => 'e',
322
+    7877 => 'e',
323
+    7879 => 'e',
324
+    7866 => 'E',
325
+    7868 => 'E',
326
+    7864 => 'E',
327
+    7870 => 'E',
328
+    7872 => 'E',
329
+    7874 => 'E',
330
+    7876 => 'E',
331
+    7878 => 'E',
332
+    7881 => 'i',
333
+    7883 => 'i',
334
+    7880 => 'I',
335
+    7882 => 'I',
336
+    7887 => 'o',
337
+    7885 => 'o',
338
+    7889 => 'o',
339
+    7891 => 'o',
340
+    7893 => 'o',
341
+    7895 => 'o',
342
+    7897 => 'o',
343
+    417 => 'o',
344
+    7899 => 'o',
345
+    7901 => 'o',
346
+    7903 => 'o',
347
+    7905 => 'o',
348
+    7907 => 'o',
349
+    7886 => 'O',
350
+    7884 => 'O',
351
+    7888 => 'O',
352
+    7890 => 'O',
353
+    7892 => 'O',
354
+    7894 => 'O',
355
+    7896 => 'O',
356
+    416 => 'O',
357
+    7898 => 'O',
358
+    7900 => 'O',
359
+    7902 => 'O',
360
+    7904 => 'O',
361
+    7906 => 'O',
362
+    7911 => 'u',
363
+    361 => 'u',
364
+    7909 => 'u',
365
+    432 => 'u',
366
+    7913 => 'u',
367
+    7915 => 'u',
368
+    7917 => 'u',
369
+    7919 => 'u',
370
+    7921 => 'u',
371
+    7910 => 'U',
372
+    360 => 'U',
373
+    7908 => 'U',
374
+    431 => 'U',
375
+    7912 => 'U',
376
+    7914 => 'U',
377
+    7916 => 'U',
378
+    7918 => 'U',
379
+    7920 => 'U',
380
+    253 => 'y',
381
+    7923 => 'y',
382
+    7927 => 'y',
383
+    7929 => 'y',
384
+    7925 => 'y',
385
+    221 => 'Y',
386
+    7922 => 'Y',
387
+    7926 => 'Y',
388
+    7928 => 'Y',
389
+    7924 => 'Y',
390
+    273 => 'd'
391 391
 
392 392
 ];
Please login to merge, or discard this patch.
ecrire/lang/public_de.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -4,123 +4,123 @@
 block discarded – undo
4 4
 // ** ne pas modifier le fichier **
5 5
 
6 6
 if (!defined('_ECRIRE_INC_VERSION')) {
7
-	return;
7
+    return;
8 8
 }
9 9
 
10 10
 $GLOBALS[$GLOBALS['idx_lang']] = array(
11 11
 
12
-	// A
13
-	'accueil_site' => 'Startseite',
14
-	'article' => 'Artikel',
15
-	'articles' => 'Artikel',
16
-	'articles_auteur' => 'Artikel dieses Autors',
17
-	'articles_populaires' => 'Die beliebtesten Artikel',
18
-	'articles_rubrique' => 'Artikel dieser Rubrik',
19
-	'aucun_article' => 'Unter dieser Adresse gibt es keinen Artikel.',
20
-	'aucun_auteur' => 'Unter dieser Adresse gibt es keinen Autor.',
21
-	'aucun_site' => 'Unter dieser Adresse gibt es keien Website.',
22
-	'aucune_breve' => 'Unter dieser Adresse gibt es keine Meldung.',
23
-	'aucune_rubrique' => 'Unter dieser Adresse gibt es keine Rubrik.',
24
-	'auteur' => 'Autor',
25
-	'autres' => 'Andere',
26
-	'autres_breves' => 'Weitere Meldungen.',
27
-	'autres_groupes_mots_clefs' => 'Weitere Schlagwortgruppen',
28
-	'autres_sites' => 'Weitere Websites',
29
-
30
-	// B
31
-	'bonjour' => 'Hallo',
32
-
33
-	// C
34
-	'commenter_site' => 'Website kommentieren',
35
-	'contact' => 'Kontakt',
36
-	'copie_document_impossible' => 'Dokument kann nicht kopiert werden',
37
-
38
-	// D
39
-	'date' => 'Datum',
40
-	'dernier_ajout' => 'Neuester Eintrag',
41
-	'dernieres_breves' => 'Neue Meldungen',
42
-	'derniers_articles' => 'Neueste Artikel',
43
-	'derniers_commentaires' => 'Neueste Kommentare',
44
-	'derniers_messages_forum' => 'Neue Forumsbeiträge',
45
-
46
-	// E
47
-	'edition_mode_texte' => 'Im Textmodus bearbeiten ',
48
-	'en_reponse' => 'Antwort auf:',
49
-	'en_resume' => 'Als Zusammenfassung',
50
-	'envoyer_message' => 'Nachricht senden',
51
-	'espace_prive' => 'Redaktion',
52
-
53
-	// F
54
-	'formats_acceptes' => 'Akzeptierte Formate: @formats@.',
55
-
56
-	// H
57
-	'hierarchie_site' => 'Baumstruktur der Website',
58
-
59
-	// J
60
-	'jours' => 'Tage',
61
-
62
-	// L
63
-	'lien_connecter' => 'Login',
64
-
65
-	// M
66
-	'meme_auteur' => 'Vom gleichen Autor',
67
-	'meme_rubrique' => 'In der gleichen Rubrik',
68
-	'memes_auteurs' => 'Von den gleichen Autoren',
69
-	'message' => 'Nachricht',
70
-	'messages_forum' => 'Nachrichten',
71
-	'messages_recents' => 'Neue Forumsbeiträge',
72
-	'mots_clef' => 'Schlagwort',
73
-	'mots_clefs' => 'Schlagworte',
74
-	'mots_clefs_meme_groupe' => 'Schlagworte der gleichen Kategorie',
75
-
76
-	// N
77
-	'navigation' => 'Navigation',
78
-	'nom' => 'Name',
79
-	'nouveautes' => 'Neuigkeiten',
80
-	'nouveautes_web' => 'Neues im WWW',
81
-	'nouveaux_articles' => 'Neue Artikel',
82
-	'nouvelles_breves' => 'Neue Meldungen',
83
-
84
-	// P
85
-	'page_precedente' => 'vorige Seite',
86
-	'page_suivante' => 'nächste Seite',
87
-	'par_auteur' => 'von ',
88
-	'participer_site' => 'Sie können bei dieser Website mitmachen, wenn Sie sich anmelden. Sie erhalten sofort eine E-Mail mit den Zugangsdaten zum Redaktionssystem.',
89
-	'plan_site' => 'Sitemap',
90
-	'popularite' => 'Beliebtheit',
91
-	'poster_message' => 'Nachricht senden',
92
-	'proposer_site' => 'Sie können in dieser Rubrik eine Seite vorschlagen :',
93
-
94
-	// R
95
-	'repondre_article' => 'auf diesen Artikel antworten',
96
-	'repondre_breve' => 'auf diese Meldung antworten',
97
-	'resultats_recherche' => 'Suchergebnis(se)',
98
-	'retour_debut_forums' => 'Zurück zum Beginn des Forums',
99
-	'rss_abonnement' => 'Kopieren Sie die folgende URL in Ihren Feedreader:',
100
-	'rss_abonnement_titre' => 'Abonnieren',
101
-	'rss_abonnement_titre_page' => 'Abonnieren von',
102
-	'rss_explication' => 'Ein RSS-Feed sammelt Informationen über die Aktualisierungen einer Website. Er liefert den Inhalt von Einträgen oder Kommentaren oder einen Auszug daraus sowie einen Link zu den Vollversionen und einige andere Informationen. Der Feed ist dazu gedacht, von einem RSS-Aggregator (Feedreader) gelesen zu werden',
103
-	'rss_explication_titre' => 'Was ist ein RSS-Feed ?',
104
-	'rubrique' => 'Rubrik',
105
-	'rubriques' => 'Rubriken',
106
-
107
-	// S
108
-	'signatures_petition' => 'Unterschrift',
109
-	'site_realise_avec_spip' => 'Realisiert mit SPIP',
110
-	'sites_web' => 'Websites',
111
-	'sous_rubriques' => 'Unterrubriken',
112
-	'spam' => 'SPAM',
113
-	'suite' => 'weiter',
114
-	'sur_web' => 'Im WWW',
115
-	'syndiquer_rubrique' => 'Diese Rubrik per RSS einbinden',
116
-	'syndiquer_site' => 'Die ganze Website mit RSS einbinden',
117
-
118
-	// T
119
-	'texte_lettre_information' => 'Dies ist der Newsletter der Website ',
120
-	'texte_lettre_information_2' => 'Diese Mail informiert über die Neuerscheinungen der letzten',
121
-
122
-	// V
123
-	'ver_imprimer' => 'Druckversion',
124
-	'voir_en_ligne' => 'Online ansehen',
125
-	'voir_squelette' => 'Layoutvorlage dieser Seite ansehen'
12
+    // A
13
+    'accueil_site' => 'Startseite',
14
+    'article' => 'Artikel',
15
+    'articles' => 'Artikel',
16
+    'articles_auteur' => 'Artikel dieses Autors',
17
+    'articles_populaires' => 'Die beliebtesten Artikel',
18
+    'articles_rubrique' => 'Artikel dieser Rubrik',
19
+    'aucun_article' => 'Unter dieser Adresse gibt es keinen Artikel.',
20
+    'aucun_auteur' => 'Unter dieser Adresse gibt es keinen Autor.',
21
+    'aucun_site' => 'Unter dieser Adresse gibt es keien Website.',
22
+    'aucune_breve' => 'Unter dieser Adresse gibt es keine Meldung.',
23
+    'aucune_rubrique' => 'Unter dieser Adresse gibt es keine Rubrik.',
24
+    'auteur' => 'Autor',
25
+    'autres' => 'Andere',
26
+    'autres_breves' => 'Weitere Meldungen.',
27
+    'autres_groupes_mots_clefs' => 'Weitere Schlagwortgruppen',
28
+    'autres_sites' => 'Weitere Websites',
29
+
30
+    // B
31
+    'bonjour' => 'Hallo',
32
+
33
+    // C
34
+    'commenter_site' => 'Website kommentieren',
35
+    'contact' => 'Kontakt',
36
+    'copie_document_impossible' => 'Dokument kann nicht kopiert werden',
37
+
38
+    // D
39
+    'date' => 'Datum',
40
+    'dernier_ajout' => 'Neuester Eintrag',
41
+    'dernieres_breves' => 'Neue Meldungen',
42
+    'derniers_articles' => 'Neueste Artikel',
43
+    'derniers_commentaires' => 'Neueste Kommentare',
44
+    'derniers_messages_forum' => 'Neue Forumsbeiträge',
45
+
46
+    // E
47
+    'edition_mode_texte' => 'Im Textmodus bearbeiten ',
48
+    'en_reponse' => 'Antwort auf:',
49
+    'en_resume' => 'Als Zusammenfassung',
50
+    'envoyer_message' => 'Nachricht senden',
51
+    'espace_prive' => 'Redaktion',
52
+
53
+    // F
54
+    'formats_acceptes' => 'Akzeptierte Formate: @formats@.',
55
+
56
+    // H
57
+    'hierarchie_site' => 'Baumstruktur der Website',
58
+
59
+    // J
60
+    'jours' => 'Tage',
61
+
62
+    // L
63
+    'lien_connecter' => 'Login',
64
+
65
+    // M
66
+    'meme_auteur' => 'Vom gleichen Autor',
67
+    'meme_rubrique' => 'In der gleichen Rubrik',
68
+    'memes_auteurs' => 'Von den gleichen Autoren',
69
+    'message' => 'Nachricht',
70
+    'messages_forum' => 'Nachrichten',
71
+    'messages_recents' => 'Neue Forumsbeiträge',
72
+    'mots_clef' => 'Schlagwort',
73
+    'mots_clefs' => 'Schlagworte',
74
+    'mots_clefs_meme_groupe' => 'Schlagworte der gleichen Kategorie',
75
+
76
+    // N
77
+    'navigation' => 'Navigation',
78
+    'nom' => 'Name',
79
+    'nouveautes' => 'Neuigkeiten',
80
+    'nouveautes_web' => 'Neues im WWW',
81
+    'nouveaux_articles' => 'Neue Artikel',
82
+    'nouvelles_breves' => 'Neue Meldungen',
83
+
84
+    // P
85
+    'page_precedente' => 'vorige Seite',
86
+    'page_suivante' => 'nächste Seite',
87
+    'par_auteur' => 'von ',
88
+    'participer_site' => 'Sie können bei dieser Website mitmachen, wenn Sie sich anmelden. Sie erhalten sofort eine E-Mail mit den Zugangsdaten zum Redaktionssystem.',
89
+    'plan_site' => 'Sitemap',
90
+    'popularite' => 'Beliebtheit',
91
+    'poster_message' => 'Nachricht senden',
92
+    'proposer_site' => 'Sie können in dieser Rubrik eine Seite vorschlagen :',
93
+
94
+    // R
95
+    'repondre_article' => 'auf diesen Artikel antworten',
96
+    'repondre_breve' => 'auf diese Meldung antworten',
97
+    'resultats_recherche' => 'Suchergebnis(se)',
98
+    'retour_debut_forums' => 'Zurück zum Beginn des Forums',
99
+    'rss_abonnement' => 'Kopieren Sie die folgende URL in Ihren Feedreader:',
100
+    'rss_abonnement_titre' => 'Abonnieren',
101
+    'rss_abonnement_titre_page' => 'Abonnieren von',
102
+    'rss_explication' => 'Ein RSS-Feed sammelt Informationen über die Aktualisierungen einer Website. Er liefert den Inhalt von Einträgen oder Kommentaren oder einen Auszug daraus sowie einen Link zu den Vollversionen und einige andere Informationen. Der Feed ist dazu gedacht, von einem RSS-Aggregator (Feedreader) gelesen zu werden',
103
+    'rss_explication_titre' => 'Was ist ein RSS-Feed ?',
104
+    'rubrique' => 'Rubrik',
105
+    'rubriques' => 'Rubriken',
106
+
107
+    // S
108
+    'signatures_petition' => 'Unterschrift',
109
+    'site_realise_avec_spip' => 'Realisiert mit SPIP',
110
+    'sites_web' => 'Websites',
111
+    'sous_rubriques' => 'Unterrubriken',
112
+    'spam' => 'SPAM',
113
+    'suite' => 'weiter',
114
+    'sur_web' => 'Im WWW',
115
+    'syndiquer_rubrique' => 'Diese Rubrik per RSS einbinden',
116
+    'syndiquer_site' => 'Die ganze Website mit RSS einbinden',
117
+
118
+    // T
119
+    'texte_lettre_information' => 'Dies ist der Newsletter der Website ',
120
+    'texte_lettre_information_2' => 'Diese Mail informiert über die Neuerscheinungen der letzten',
121
+
122
+    // V
123
+    'ver_imprimer' => 'Druckversion',
124
+    'voir_en_ligne' => 'Online ansehen',
125
+    'voir_squelette' => 'Layoutvorlage dieser Seite ansehen'
126 126
 );
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Password.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
38 38
 			return password_verify($pass_poivre, $password_hash);
39 39
 		}
40
-		spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
40
+		spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer'._LOG_INFO_IMPORTANTE);
41 41
 		return false;
42 42
 	}
43 43
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
60 60
 			return password_hash($pass_poivre, PASSWORD_DEFAULT);
61 61
 		}
62
-		spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
62
+		spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer'._LOG_INFO_IMPORTANTE);
63 63
 		return null;
64 64
 	}
65 65
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -13,49 +13,49 @@
 block discarded – undo
13 13
 
14 14
 /** Vérification et hachage de mot de passe */
15 15
 class Password {
16
-	/**
17
-	 * verifier qu'un mot de passe en clair est correct a l'aide de son hash
18
-	 *
19
-	 * Le mot de passe est poivre via la cle secret_des_auth
20
-	 */
21
-	public static function verifier(
22
-		#[\SensitiveParameter]
23
-		string $password_clair,
24
-		#[\SensitiveParameter]
25
-		string $password_hash,
26
-		#[\SensitiveParameter]
27
-		?string $key = null
28
-	): bool {
29
-		$key ??= self::getDefaultKey();
30
-		if ($key) {
31
-			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
32
-			return password_verify($pass_poivre, $password_hash);
33
-		}
34
-		spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
35
-		return false;
36
-	}
16
+    /**
17
+     * verifier qu'un mot de passe en clair est correct a l'aide de son hash
18
+     *
19
+     * Le mot de passe est poivre via la cle secret_des_auth
20
+     */
21
+    public static function verifier(
22
+        #[\SensitiveParameter]
23
+        string $password_clair,
24
+        #[\SensitiveParameter]
25
+        string $password_hash,
26
+        #[\SensitiveParameter]
27
+        ?string $key = null
28
+    ): bool {
29
+        $key ??= self::getDefaultKey();
30
+        if ($key) {
31
+            $pass_poivre = hash_hmac('sha256', $password_clair, $key);
32
+            return password_verify($pass_poivre, $password_hash);
33
+        }
34
+        spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
35
+        return false;
36
+    }
37 37
 
38
-	/**
39
-	 * Calculer un hash salé du mot de passe
40
-	 */
41
-	public static function hacher(
42
-		#[\SensitiveParameter]
43
-		string $password_clair,
44
-		#[\SensitiveParameter]
45
-		?string $key = null
46
-	): ?string {
47
-		$key ??= self::getDefaultKey();
48
-		// ne pas fournir un hash errone si la cle nous manque
49
-		if ($key) {
50
-			$pass_poivre = hash_hmac('sha256', $password_clair, $key);
51
-			return password_hash($pass_poivre, PASSWORD_DEFAULT);
52
-		}
53
-		spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
54
-		return null;
55
-	}
38
+    /**
39
+     * Calculer un hash salé du mot de passe
40
+     */
41
+    public static function hacher(
42
+        #[\SensitiveParameter]
43
+        string $password_clair,
44
+        #[\SensitiveParameter]
45
+        ?string $key = null
46
+    ): ?string {
47
+        $key ??= self::getDefaultKey();
48
+        // ne pas fournir un hash errone si la cle nous manque
49
+        if ($key) {
50
+            $pass_poivre = hash_hmac('sha256', $password_clair, $key);
51
+            return password_hash($pass_poivre, PASSWORD_DEFAULT);
52
+        }
53
+        spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE);
54
+        return null;
55
+    }
56 56
 
57
-	private static function getDefaultKey(): ?string {
58
-		$keys = SpipCles::instance();
59
-		return $keys->getSecretAuth();
60
-	}
57
+    private static function getDefaultKey(): ?string {
58
+        $keys = SpipCles::instance();
59
+        return $keys->getSecretAuth();
60
+    }
61 61
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Cles.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 	public function generate(string $name): string {
31 31
 		$key = Chiffrement::keygen();
32 32
 		$this->keys[$name] = $key;
33
-		spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
33
+		spip_log("Création de la cle $name", 'chiffrer'._LOG_INFO_IMPORTANTE);
34 34
 		return $key;
35 35
 	}
36 36
 
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,46 +13,46 @@
 block discarded – undo
13 13
 
14 14
 /** Conteneur de clés (chiffrement, authentification) */
15 15
 class Cles implements \Countable /* , ContainerInterface */ {
16
-	public function __construct(private array $keys) {
17
-	}
18
-
19
-	public function has(string $name): bool {
20
-		return array_key_exists($name, $this->keys);
21
-	}
22
-
23
-	public function get(string $name): ?string {
24
-		return $this->keys[$name] ?? null;
25
-	}
26
-
27
-	public function generate(string $name): string {
28
-		$key = Chiffrement::keygen();
29
-		$this->keys[$name] = $key;
30
-		spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
31
-		return $key;
32
-	}
33
-
34
-	public function set(
35
-		string $name,
36
-		#[\SensitiveParameter]
37
-		string $key
38
-	): void {
39
-		$this->keys[$name] = $key;
40
-	}
41
-
42
-	public function delete(string $name): bool {
43
-		if (isset($this->keys[$name])) {
44
-			unset($this->keys[$name]);
45
-			return true;
46
-		};
47
-		return false;
48
-	}
49
-
50
-	public function count(): int {
51
-		return count($this->keys);
52
-	}
53
-
54
-	public function toJson(): string {
55
-		$json = array_map('base64_encode', $this->keys);
56
-		return \json_encode($json);
57
-	}
16
+    public function __construct(private array $keys) {
17
+    }
18
+
19
+    public function has(string $name): bool {
20
+        return array_key_exists($name, $this->keys);
21
+    }
22
+
23
+    public function get(string $name): ?string {
24
+        return $this->keys[$name] ?? null;
25
+    }
26
+
27
+    public function generate(string $name): string {
28
+        $key = Chiffrement::keygen();
29
+        $this->keys[$name] = $key;
30
+        spip_log("Création de la cle $name", 'chiffrer' . _LOG_INFO_IMPORTANTE);
31
+        return $key;
32
+    }
33
+
34
+    public function set(
35
+        string $name,
36
+        #[\SensitiveParameter]
37
+        string $key
38
+    ): void {
39
+        $this->keys[$name] = $key;
40
+    }
41
+
42
+    public function delete(string $name): bool {
43
+        if (isset($this->keys[$name])) {
44
+            unset($this->keys[$name]);
45
+            return true;
46
+        };
47
+        return false;
48
+    }
49
+
50
+    public function count(): int {
51
+        return count($this->keys);
52
+    }
53
+
54
+    public function toJson(): string {
55
+        $json = array_map('base64_encode', $this->keys);
56
+        return \json_encode($json);
57
+    }
58 58
 }
Please login to merge, or discard this patch.
ecrire/inc/queue.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Queue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 define('_JQ_SCHEDULED', 1);
@@ -50,103 +50,103 @@  discard block
 block discarded – undo
50 50
  *  id of job
51 51
  */
52 52
 function queue_add_job(
53
-	$function,
54
-	$description,
55
-	$arguments = [],
56
-	$file = '',
57
-	$no_duplicate = false,
58
-	$time = 0,
59
-	$priority = 0
53
+    $function,
54
+    $description,
55
+    $arguments = [],
56
+    $file = '',
57
+    $no_duplicate = false,
58
+    $time = 0,
59
+    $priority = 0
60 60
 ) {
61
-	include_spip('base/abstract_sql');
62
-
63
-	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
-	if (defined('_GENIE_SYNDIC_NOW')) {
65
-		$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
-	}
67
-
68
-	// serialiser les arguments
69
-	$arguments = serialize($arguments);
70
-	$md5args = md5($arguments);
71
-
72
-	// si pas de date programee, des que possible
73
-	$duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
-	if (!$time) {
75
-		$time = time();
76
-		$duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
-	}
78
-	$date = date('Y-m-d H:i:s', $time);
79
-
80
-	$set_job = [
81
-		'fonction' => $function,
82
-		'descriptif' => $description,
83
-		'args' => $arguments,
84
-		'md5args' => $md5args,
85
-		'inclure' => $file,
86
-		'priorite' => max(-10, min(10, intval($priority))),
87
-		'date' => $date,
88
-		'status' => _JQ_SCHEDULED,
89
-	];
90
-	// si option ne pas dupliquer, regarder si la fonction existe deja
91
-	// avec les memes args et file
92
-	if (
93
-		$no_duplicate
94
-		and
95
-		$id_job = sql_getfetsel(
96
-			'id_job',
97
-			'spip_jobs',
98
-			$duplicate_where =
99
-				$duplicate_where . 'fonction=' . sql_quote($function)
100
-				. (($no_duplicate === 'function_only') ? '' :
101
-			' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
-		)
103
-	) {
104
-		return $id_job;
105
-	}
106
-
107
-	$id_job = sql_insertq('spip_jobs', $set_job);
108
-	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
-	// avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
-	// doit s'effacer
111
-	if (
112
-		$no_duplicate
113
-		and
114
-		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
-	) {
116
-		sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
-
118
-		return $id_prev;
119
-	}
120
-
121
-	// verifier la non duplication qui peut etre problematique en cas de concurence
122
-	// il faut dans ce cas que seul le dernier ajoute se supprime !
123
-
124
-	// une option de debug pour verifier que les arguments en base sont bons
125
-	// ie cas d'un char non acceptables sur certains type de champs
126
-	// qui coupe la valeur
127
-	if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
-		if ($args !== $arguments) {
130
-			spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
-				$arguments,
132
-				true
133
-			), 'queue');
134
-		}
135
-	}
136
-
137
-	if ($id_job) {
138
-		queue_update_next_job_time($time);
139
-	}
140
-	// si la mise en file d'attente du job echoue,
141
-	// il ne faut pas perdre l'execution de la fonction
142
-	// on la lance immediatement, c'est un fallback
143
-	// sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
-	elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
-		$set_job['id_job'] = 0;
146
-		queue_start_job($set_job);
147
-	}
148
-
149
-	return $id_job;
61
+    include_spip('base/abstract_sql');
62
+
63
+    // cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
+    if (defined('_GENIE_SYNDIC_NOW')) {
65
+        $arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
+    }
67
+
68
+    // serialiser les arguments
69
+    $arguments = serialize($arguments);
70
+    $md5args = md5($arguments);
71
+
72
+    // si pas de date programee, des que possible
73
+    $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
+    if (!$time) {
75
+        $time = time();
76
+        $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
+    }
78
+    $date = date('Y-m-d H:i:s', $time);
79
+
80
+    $set_job = [
81
+        'fonction' => $function,
82
+        'descriptif' => $description,
83
+        'args' => $arguments,
84
+        'md5args' => $md5args,
85
+        'inclure' => $file,
86
+        'priorite' => max(-10, min(10, intval($priority))),
87
+        'date' => $date,
88
+        'status' => _JQ_SCHEDULED,
89
+    ];
90
+    // si option ne pas dupliquer, regarder si la fonction existe deja
91
+    // avec les memes args et file
92
+    if (
93
+        $no_duplicate
94
+        and
95
+        $id_job = sql_getfetsel(
96
+            'id_job',
97
+            'spip_jobs',
98
+            $duplicate_where =
99
+                $duplicate_where . 'fonction=' . sql_quote($function)
100
+                . (($no_duplicate === 'function_only') ? '' :
101
+            ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
+        )
103
+    ) {
104
+        return $id_job;
105
+    }
106
+
107
+    $id_job = sql_insertq('spip_jobs', $set_job);
108
+    // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
+    // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
+    // doit s'effacer
111
+    if (
112
+        $no_duplicate
113
+        and
114
+        $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
+    ) {
116
+        sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
+
118
+        return $id_prev;
119
+    }
120
+
121
+    // verifier la non duplication qui peut etre problematique en cas de concurence
122
+    // il faut dans ce cas que seul le dernier ajoute se supprime !
123
+
124
+    // une option de debug pour verifier que les arguments en base sont bons
125
+    // ie cas d'un char non acceptables sur certains type de champs
126
+    // qui coupe la valeur
127
+    if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
+        $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
+        if ($args !== $arguments) {
130
+            spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
+                $arguments,
132
+                true
133
+            ), 'queue');
134
+        }
135
+    }
136
+
137
+    if ($id_job) {
138
+        queue_update_next_job_time($time);
139
+    }
140
+    // si la mise en file d'attente du job echoue,
141
+    // il ne faut pas perdre l'execution de la fonction
142
+    // on la lance immediatement, c'est un fallback
143
+    // sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
+    elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
+        $set_job['id_job'] = 0;
146
+        queue_start_job($set_job);
147
+    }
148
+
149
+    return $id_job;
150 150
 }
151 151
 
152 152
 /**
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
  * @return void
156 156
  */
157 157
 function queue_purger() {
158
-	include_spip('base/abstract_sql');
159
-	sql_delete('spip_jobs');
160
-	sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
-	include_spip('inc/genie');
162
-	genie_queue_watch_dist();
158
+    include_spip('base/abstract_sql');
159
+    sql_delete('spip_jobs');
160
+    sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
+    include_spip('inc/genie');
162
+    genie_queue_watch_dist();
163 163
 }
164 164
 
165 165
 /**
@@ -170,25 +170,25 @@  discard block
 block discarded – undo
170 170
  * @return int|bool
171 171
  */
172 172
 function queue_remove_job($id_job) {
173
-	include_spip('base/abstract_sql');
174
-
175
-	if (
176
-		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
-		and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
-	) {
179
-		queue_unlink_job($id_job);
180
-		// est-ce une tache cron qu'il faut relancer ?
181
-		if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
-			// relancer avec les nouveaux arguments de temps
183
-			include_spip('inc/genie');
184
-			// relancer avec la periode prevue
185
-			queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
-		}
187
-		queue_update_next_job_time();
188
-		return $res;
189
-	}
190
-
191
-	return false;
173
+    include_spip('base/abstract_sql');
174
+
175
+    if (
176
+        $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
+        and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
+    ) {
179
+        queue_unlink_job($id_job);
180
+        // est-ce une tache cron qu'il faut relancer ?
181
+        if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
+            // relancer avec les nouveaux arguments de temps
183
+            include_spip('inc/genie');
184
+            // relancer avec la periode prevue
185
+            queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
+        }
187
+        queue_update_next_job_time();
188
+        return $res;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 /**
@@ -201,18 +201,18 @@  discard block
 block discarded – undo
201 201
  *  ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois
202 202
  */
203 203
 function queue_link_job($id_job, $objets) {
204
-	include_spip('base/abstract_sql');
205
-
206
-	if (is_array($objets) and count($objets)) {
207
-		if (is_array(reset($objets))) {
208
-			foreach ($objets as $k => $o) {
209
-				$objets[$k]['id_job'] = $id_job;
210
-			}
211
-			sql_insertq_multi('spip_jobs_liens', $objets);
212
-		} else {
213
-			sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
214
-		}
215
-	}
204
+    include_spip('base/abstract_sql');
205
+
206
+    if (is_array($objets) and count($objets)) {
207
+        if (is_array(reset($objets))) {
208
+            foreach ($objets as $k => $o) {
209
+                $objets[$k]['id_job'] = $id_job;
210
+            }
211
+            sql_insertq_multi('spip_jobs_liens', $objets);
212
+        } else {
213
+            sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
214
+        }
215
+    }
216 216
 }
217 217
 
218 218
 /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
  *  resultat du sql_delete
225 225
  */
226 226
 function queue_unlink_job($id_job) {
227
-	return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
227
+    return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
228 228
 }
229 229
 
230 230
 /**
@@ -237,36 +237,36 @@  discard block
 block discarded – undo
237 237
  */
238 238
 function queue_start_job($row) {
239 239
 
240
-	// deserialiser les arguments
241
-	$args = unserialize($row['args']);
242
-	if (!is_array($args)) {
243
-		spip_log('arguments job errones ' . var_export($row, true), 'queue');
244
-		$args = [];
245
-	}
246
-
247
-	$fonction = $row['fonction'];
248
-	if (strlen($inclure = trim($row['inclure']))) {
249
-		if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
250
-			$f = charger_fonction($fonction, rtrim($inclure, '/'), false);
251
-			if ($f) {
252
-				$fonction = $f;
253
-			}
254
-		} else {
255
-			include_spip($inclure);
256
-		}
257
-	}
258
-
259
-	if (!function_exists($fonction)) {
260
-		spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
261
-
262
-		return false;
263
-	}
264
-
265
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
266
-	$res = $fonction(...$args);
267
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
268
-
269
-	return $res;
240
+    // deserialiser les arguments
241
+    $args = unserialize($row['args']);
242
+    if (!is_array($args)) {
243
+        spip_log('arguments job errones ' . var_export($row, true), 'queue');
244
+        $args = [];
245
+    }
246
+
247
+    $fonction = $row['fonction'];
248
+    if (strlen($inclure = trim($row['inclure']))) {
249
+        if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
250
+            $f = charger_fonction($fonction, rtrim($inclure, '/'), false);
251
+            if ($f) {
252
+                $fonction = $f;
253
+            }
254
+        } else {
255
+            include_spip($inclure);
256
+        }
257
+    }
258
+
259
+    if (!function_exists($fonction)) {
260
+        spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
261
+
262
+        return false;
263
+    }
264
+
265
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
266
+    $res = $fonction(...$args);
267
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
268
+
269
+    return $res;
270 270
 }
271 271
 
272 272
 /**
@@ -293,89 +293,89 @@  discard block
 block discarded – undo
293 293
  *     - true : une planification a été faite.
294 294
  */
295 295
 function queue_schedule($force_jobs = null) {
296
-	$time = time();
297
-	if (defined('_DEBUG_BLOCK_QUEUE')) {
298
-		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
299
-
300
-		return;
301
-	}
302
-
303
-	// rien a faire si le prochain job est encore dans le futur
304
-	if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
305
-		spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
306
-
307
-		return;
308
-	}
309
-
310
-	include_spip('base/abstract_sql');
311
-	// on ne peut rien faire si pas de connexion SQL
312
-	if (!spip_connect()) {
313
-		return false;
314
-	}
315
-
316
-	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
317
-		$max_time = ini_get('max_execution_time') / 2;
318
-		// valeur conservatrice si on a pas reussi a lire le max_execution_time
319
-		if (!$max_time) {
320
-			$max_time = 5;
321
-		}
322
-		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
323
-	}
324
-	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
325
-
326
-	spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
327
-
328
-	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
329
-		define('_JQ_MAX_JOBS_EXECUTE', 200);
330
-	}
331
-	$nbj = 0;
332
-	// attraper les jobs
333
-	// dont la date est passee (echus en attente),
334
-	// par ordre :
335
-	//	- de priorite
336
-	//	- de date
337
-	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
338
-	// pour qu'il ne bloque pas les autres jobs en attente
339
-	if (is_array($force_jobs) and count($force_jobs)) {
340
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
341
-	} else {
342
-		$now = date('Y-m-d H:i:s', $time);
343
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
344
-	}
345
-
346
-	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
347
-	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
348
-	do {
349
-		if ($row = array_shift($res)) {
350
-			$nbj++;
351
-			// il faut un verrou, a base de sql_delete
352
-			if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
353
-				#spip_log("JQ schedule job ".$nbj." OK",'jq');
354
-				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
355
-				$row['status'] = _JQ_PENDING;
356
-				$row['date'] = date('Y-m-d H:i:s', $time);
357
-				sql_insertq('spip_jobs', $row);
358
-
359
-				// on a la main sur le job :
360
-				// l'executer
361
-				$result = queue_start_job($row);
362
-
363
-				$time = time();
364
-				queue_close_job($row, $time, $result);
365
-			}
366
-		}
367
-		spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
368
-	} while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
369
-	spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
370
-
371
-	if ($row = array_shift($res)) {
372
-		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
373
-		spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
374
-	} else {
375
-		queue_update_next_job_time();
376
-	}
377
-
378
-	return true;
296
+    $time = time();
297
+    if (defined('_DEBUG_BLOCK_QUEUE')) {
298
+        spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
299
+
300
+        return;
301
+    }
302
+
303
+    // rien a faire si le prochain job est encore dans le futur
304
+    if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
305
+        spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
306
+
307
+        return;
308
+    }
309
+
310
+    include_spip('base/abstract_sql');
311
+    // on ne peut rien faire si pas de connexion SQL
312
+    if (!spip_connect()) {
313
+        return false;
314
+    }
315
+
316
+    if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
317
+        $max_time = ini_get('max_execution_time') / 2;
318
+        // valeur conservatrice si on a pas reussi a lire le max_execution_time
319
+        if (!$max_time) {
320
+            $max_time = 5;
321
+        }
322
+        define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
323
+    }
324
+    $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
325
+
326
+    spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
327
+
328
+    if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
329
+        define('_JQ_MAX_JOBS_EXECUTE', 200);
330
+    }
331
+    $nbj = 0;
332
+    // attraper les jobs
333
+    // dont la date est passee (echus en attente),
334
+    // par ordre :
335
+    //	- de priorite
336
+    //	- de date
337
+    // lorsqu'un job cron n'a pas fini, sa priorite est descendue
338
+    // pour qu'il ne bloque pas les autres jobs en attente
339
+    if (is_array($force_jobs) and count($force_jobs)) {
340
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
341
+    } else {
342
+        $now = date('Y-m-d H:i:s', $time);
343
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
344
+    }
345
+
346
+    register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
347
+    $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
348
+    do {
349
+        if ($row = array_shift($res)) {
350
+            $nbj++;
351
+            // il faut un verrou, a base de sql_delete
352
+            if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
353
+                #spip_log("JQ schedule job ".$nbj." OK",'jq');
354
+                // on reinsert dans la base aussitot avec un status=_JQ_PENDING
355
+                $row['status'] = _JQ_PENDING;
356
+                $row['date'] = date('Y-m-d H:i:s', $time);
357
+                sql_insertq('spip_jobs', $row);
358
+
359
+                // on a la main sur le job :
360
+                // l'executer
361
+                $result = queue_start_job($row);
362
+
363
+                $time = time();
364
+                queue_close_job($row, $time, $result);
365
+            }
366
+        }
367
+        spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
368
+    } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
369
+    spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
370
+
371
+    if ($row = array_shift($res)) {
372
+        queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
373
+        spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
374
+    } else {
375
+        queue_update_next_job_time();
376
+    }
377
+
378
+    return true;
379 379
 }
380 380
 
381 381
 /**
@@ -393,21 +393,21 @@  discard block
 block discarded – undo
393 393
  * @param int $result
394 394
  */
395 395
 function queue_close_job(&$row, $time, $result = 0) {
396
-	// est-ce une tache cron qu'il faut relancer ?
397
-	if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
398
-		// relancer avec les nouveaux arguments de temps
399
-		include_spip('inc/genie');
400
-		if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
401
-		queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
402
-		} else // relancer avec la periode prevue
403
-		{
404
-			queue_genie_replan_job($row['fonction'], $periode, $time);
405
-		}
406
-	}
407
-	// purger ses liens eventuels avec des objets
408
-	sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
409
-	// supprimer le job fini
410
-	sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
396
+    // est-ce une tache cron qu'il faut relancer ?
397
+    if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
398
+        // relancer avec les nouveaux arguments de temps
399
+        include_spip('inc/genie');
400
+        if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
401
+        queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
402
+        } else // relancer avec la periode prevue
403
+        {
404
+            queue_genie_replan_job($row['fonction'], $periode, $time);
405
+        }
406
+    }
407
+    // purger ses liens eventuels avec des objets
408
+    sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
409
+    // supprimer le job fini
410
+    sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
411 411
 }
412 412
 
413 413
 /**
@@ -417,10 +417,10 @@  discard block
 block discarded – undo
417 417
  * @uses queue_update_next_job_time()
418 418
  */
419 419
 function queue_error_handler() {
420
-	// se remettre dans le bon dossier, car Apache le change parfois (toujours?)
421
-	chdir(_ROOT_CWD);
420
+    // se remettre dans le bon dossier, car Apache le change parfois (toujours?)
421
+    chdir(_ROOT_CWD);
422 422
 
423
-	queue_update_next_job_time();
423
+    queue_update_next_job_time();
424 424
 }
425 425
 
426 426
 
@@ -437,18 +437,18 @@  discard block
 block discarded – undo
437 437
  *     Périodicité de la tâche en secondes, si tâche périodique, sinon false.
438 438
  */
439 439
 function queue_is_cron_job($function, $inclure) {
440
-	static $taches = null;
441
-	if (strncmp($inclure, 'genie/', 6) == 0) {
442
-		if (is_null($taches)) {
443
-			include_spip('inc/genie');
444
-			$taches = taches_generales();
445
-		}
446
-		if (isset($taches[$function])) {
447
-			return $taches[$function];
448
-		}
449
-	}
450
-
451
-	return false;
440
+    static $taches = null;
441
+    if (strncmp($inclure, 'genie/', 6) == 0) {
442
+        if (is_null($taches)) {
443
+            include_spip('inc/genie');
444
+            $taches = taches_generales();
445
+        }
446
+        if (isset($taches[$function])) {
447
+            return $taches[$function];
448
+        }
449
+    }
450
+
451
+    return false;
452 452
 }
453 453
 
454 454
 /**
@@ -462,62 +462,62 @@  discard block
 block discarded – undo
462 462
  *  temps de la tache ajoutee ou 0 pour ASAP
463 463
  */
464 464
 function queue_update_next_job_time($next_time = null) {
465
-	static $nb_jobs_scheduled = null;
466
-	static $deja_la = false;
467
-	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
468
-	static $next = null;
469
-	// queue_close_job peut etre reentrant ici
470
-	if ($deja_la) {
471
-		return;
472
-	}
473
-	$deja_la = true;
474
-
475
-	include_spip('base/abstract_sql');
476
-	$time = time();
477
-
478
-	// traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
479
-	// pour cause de timeout ou autre erreur fatale
480
-	$res = sql_allfetsel(
481
-		'*',
482
-		'spip_jobs',
483
-		'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
484
-	);
485
-	if (is_array($res)) {
486
-		foreach ($res as $row) {
487
-			queue_close_job($row, $time);
488
-			spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
489
-		}
490
-	}
491
-
492
-	// chercher la date du prochain job si pas connu
493
-	if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
494
-		$date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
495
-		$next = strtotime($date);
496
-	}
497
-	if (!is_null($next_time)) {
498
-		if (is_null($next) or $next > $next_time) {
499
-			$next = $next_time;
500
-		}
501
-	}
502
-
503
-	if ($next) {
504
-		if (is_null($nb_jobs_scheduled)) {
505
-			$nb_jobs_scheduled = sql_countsel(
506
-				'spip_jobs',
507
-				'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
508
-			);
509
-		} elseif ($next <= $time) {
510
-			$nb_jobs_scheduled++;
511
-		}
512
-		// si trop de jobs en attente, on force la purge en fin de hit
513
-		// pour assurer le coup
514
-		if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
515
-			define('_DIRECT_CRON_FORCE', true);
516
-		}
517
-	}
518
-
519
-	queue_set_next_job_time($next);
520
-	$deja_la = false;
465
+    static $nb_jobs_scheduled = null;
466
+    static $deja_la = false;
467
+    // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
468
+    static $next = null;
469
+    // queue_close_job peut etre reentrant ici
470
+    if ($deja_la) {
471
+        return;
472
+    }
473
+    $deja_la = true;
474
+
475
+    include_spip('base/abstract_sql');
476
+    $time = time();
477
+
478
+    // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
479
+    // pour cause de timeout ou autre erreur fatale
480
+    $res = sql_allfetsel(
481
+        '*',
482
+        'spip_jobs',
483
+        'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
484
+    );
485
+    if (is_array($res)) {
486
+        foreach ($res as $row) {
487
+            queue_close_job($row, $time);
488
+            spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
489
+        }
490
+    }
491
+
492
+    // chercher la date du prochain job si pas connu
493
+    if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
494
+        $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
495
+        $next = strtotime($date);
496
+    }
497
+    if (!is_null($next_time)) {
498
+        if (is_null($next) or $next > $next_time) {
499
+            $next = $next_time;
500
+        }
501
+    }
502
+
503
+    if ($next) {
504
+        if (is_null($nb_jobs_scheduled)) {
505
+            $nb_jobs_scheduled = sql_countsel(
506
+                'spip_jobs',
507
+                'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
508
+            );
509
+        } elseif ($next <= $time) {
510
+            $nb_jobs_scheduled++;
511
+        }
512
+        // si trop de jobs en attente, on force la purge en fin de hit
513
+        // pour assurer le coup
514
+        if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
515
+            define('_DIRECT_CRON_FORCE', true);
516
+        }
517
+    }
518
+
519
+    queue_set_next_job_time($next);
520
+    $deja_la = false;
521 521
 }
522 522
 
523 523
 
@@ -528,26 +528,26 @@  discard block
 block discarded – undo
528 528
  */
529 529
 function queue_set_next_job_time($next) {
530 530
 
531
-	// utiliser le temps courant reel plutot que temps de la requete ici
532
-	$time = time();
533
-
534
-	// toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
535
-	// et ne mettre a jour que si il y a un interet a le faire
536
-	// permet ausis d'initialiser le nom de fichier a coup sur
537
-	$curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
538
-	if (
539
-		($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
540
-		or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
541
-	) {
542
-		if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
543
-			cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
544
-		} else {
545
-			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
546
-		}
547
-		queue_sleep_time_to_next_job($next);
548
-	}
549
-
550
-	return queue_sleep_time_to_next_job();
531
+    // utiliser le temps courant reel plutot que temps de la requete ici
532
+    $time = time();
533
+
534
+    // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
535
+    // et ne mettre a jour que si il y a un interet a le faire
536
+    // permet ausis d'initialiser le nom de fichier a coup sur
537
+    $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
538
+    if (
539
+        ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
540
+        or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
541
+    ) {
542
+        if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
543
+            cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
544
+        } else {
545
+            ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
546
+        }
547
+        queue_sleep_time_to_next_job($next);
548
+    }
549
+
550
+    return queue_sleep_time_to_next_job();
551 551
 }
552 552
 
553 553
 /**
@@ -564,60 +564,60 @@  discard block
 block discarded – undo
564 564
  * @return string
565 565
  */
566 566
 function queue_affichage_cron() {
567
-	$texte = '';
568
-
569
-	$time_to_next = queue_sleep_time_to_next_job();
570
-	// rien a faire si le prochain job est encore dans le futur
571
-	if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
572
-		return $texte;
573
-	}
574
-
575
-	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
576
-	if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
577
-		return $texte;
578
-	}
579
-
580
-	@touch($lock);
581
-
582
-	// il y a des taches en attentes
583
-	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
584
-	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
585
-	$urgent = false;
586
-	if ($time_to_next < -300) {
587
-		$urgent = true;
588
-	}
589
-
590
-	$url_cron = generer_url_action('cron', '', false, true);
591
-
592
-	if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
593
-		if (queue_lancer_url_http_async($url_cron) and !$urgent) {
594
-			return $texte;
595
-		}
596
-	}
597
-
598
-	// si deja force, on retourne sans rien
599
-	if (defined('_DIRECT_CRON_FORCE')) {
600
-		return $texte;
601
-	}
602
-
603
-	// si c'est un bot
604
-	// inutile de faire un appel par image background,
605
-	// on force un appel direct en fin de hit
606
-	if ((defined('_IS_BOT') and _IS_BOT)) {
607
-		define('_DIRECT_CRON_FORCE', true);
608
-
609
-		return $texte;
610
-	}
611
-
612
-	if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
613
-		// en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
614
-		$url_cron = generer_url_action('cron');
615
-		$texte = '<!-- SPIP-CRON -->'
616
-		  . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
617
-		  . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
618
-	}
619
-
620
-	return $texte;
567
+    $texte = '';
568
+
569
+    $time_to_next = queue_sleep_time_to_next_job();
570
+    // rien a faire si le prochain job est encore dans le futur
571
+    if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
572
+        return $texte;
573
+    }
574
+
575
+    // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
576
+    if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
577
+        return $texte;
578
+    }
579
+
580
+    @touch($lock);
581
+
582
+    // il y a des taches en attentes
583
+    // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
584
+    // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
585
+    $urgent = false;
586
+    if ($time_to_next < -300) {
587
+        $urgent = true;
588
+    }
589
+
590
+    $url_cron = generer_url_action('cron', '', false, true);
591
+
592
+    if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
593
+        if (queue_lancer_url_http_async($url_cron) and !$urgent) {
594
+            return $texte;
595
+        }
596
+    }
597
+
598
+    // si deja force, on retourne sans rien
599
+    if (defined('_DIRECT_CRON_FORCE')) {
600
+        return $texte;
601
+    }
602
+
603
+    // si c'est un bot
604
+    // inutile de faire un appel par image background,
605
+    // on force un appel direct en fin de hit
606
+    if ((defined('_IS_BOT') and _IS_BOT)) {
607
+        define('_DIRECT_CRON_FORCE', true);
608
+
609
+        return $texte;
610
+    }
611
+
612
+    if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
613
+        // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
614
+        $url_cron = generer_url_action('cron');
615
+        $texte = '<!-- SPIP-CRON -->'
616
+            . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
617
+            . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
618
+    }
619
+
620
+    return $texte;
621 621
 }
622 622
 
623 623
 /**
@@ -626,73 +626,73 @@  discard block
 block discarded – undo
626 626
  * @return bool : true si l'url a pu être appelée en asynchrone, false sinon
627 627
  */
628 628
 function queue_lancer_url_http_async($url_cron) {
629
-	// methode la plus rapide :
630
-	// Si fsockopen est possible, on lance le cron via un socket en asynchrone
631
-	// si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
632
-	// car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
633
-	// mais on renvoie false direct
634
-	if (function_exists('fsockopen')) {
635
-		$parts = parse_url($url_cron);
636
-
637
-		switch ($parts['scheme']) {
638
-			case 'https':
639
-				$scheme = 'ssl://';
640
-				$port = 443;
641
-				break;
642
-			case 'http':
643
-			default:
644
-				$scheme = '';
645
-				$port = 80;
646
-		}
647
-		$fp = @fsockopen(
648
-			$scheme . $parts['host'],
649
-			$parts['port'] ?? $port,
650
-			$errno,
651
-			$errstr,
652
-			1
653
-		);
654
-
655
-		if ($fp) {
656
-			$host_sent = $parts['host'];
657
-			if (isset($parts['port']) and $parts['port'] !== $port) {
658
-				$host_sent .= ':' . $parts['port'];
659
-			}
660
-			$timeout = 200; // ms
661
-			stream_set_timeout($fp, 0, $timeout * 1000);
662
-			$query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
663
-			$out = 'GET ' . $query . " HTTP/1.1\r\n";
664
-			$out .= 'Host: ' . $host_sent . "\r\n";
665
-			$out .= "Connection: Close\r\n\r\n";
666
-			fwrite($fp, $out);
667
-			spip_timer('read');
668
-			$t = 0;
669
-			// on lit la reponse si possible pour fermer proprement la connexion
670
-			// avec un timeout total de 200ms pour ne pas se bloquer
671
-			while (!feof($fp) and $t < $timeout) {
672
-				@fgets($fp, 1024);
673
-				$t += spip_timer('read', true);
674
-				spip_timer('read');
675
-			}
676
-			fclose($fp);
677
-			return true;
678
-		}
679
-	}
680
-	// si fsockopen n'est pas dispo on essaye cURL :
681
-	// lancer le cron par un cURL asynchrone si cURL est present
682
-	elseif (function_exists('curl_init')) {
683
-		//setting the curl parameters.
684
-		$ch = curl_init($url_cron);
685
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
686
-		// cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
687
-		curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
688
-		// valeur mini pour que la requete soit lancee
689
-		curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
690
-		// lancer
691
-		curl_exec($ch);
692
-		// fermer
693
-		curl_close($ch);
694
-		return true;
695
-	}
696
-
697
-	return false;
629
+    // methode la plus rapide :
630
+    // Si fsockopen est possible, on lance le cron via un socket en asynchrone
631
+    // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
632
+    // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
633
+    // mais on renvoie false direct
634
+    if (function_exists('fsockopen')) {
635
+        $parts = parse_url($url_cron);
636
+
637
+        switch ($parts['scheme']) {
638
+            case 'https':
639
+                $scheme = 'ssl://';
640
+                $port = 443;
641
+                break;
642
+            case 'http':
643
+            default:
644
+                $scheme = '';
645
+                $port = 80;
646
+        }
647
+        $fp = @fsockopen(
648
+            $scheme . $parts['host'],
649
+            $parts['port'] ?? $port,
650
+            $errno,
651
+            $errstr,
652
+            1
653
+        );
654
+
655
+        if ($fp) {
656
+            $host_sent = $parts['host'];
657
+            if (isset($parts['port']) and $parts['port'] !== $port) {
658
+                $host_sent .= ':' . $parts['port'];
659
+            }
660
+            $timeout = 200; // ms
661
+            stream_set_timeout($fp, 0, $timeout * 1000);
662
+            $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
663
+            $out = 'GET ' . $query . " HTTP/1.1\r\n";
664
+            $out .= 'Host: ' . $host_sent . "\r\n";
665
+            $out .= "Connection: Close\r\n\r\n";
666
+            fwrite($fp, $out);
667
+            spip_timer('read');
668
+            $t = 0;
669
+            // on lit la reponse si possible pour fermer proprement la connexion
670
+            // avec un timeout total de 200ms pour ne pas se bloquer
671
+            while (!feof($fp) and $t < $timeout) {
672
+                @fgets($fp, 1024);
673
+                $t += spip_timer('read', true);
674
+                spip_timer('read');
675
+            }
676
+            fclose($fp);
677
+            return true;
678
+        }
679
+    }
680
+    // si fsockopen n'est pas dispo on essaye cURL :
681
+    // lancer le cron par un cURL asynchrone si cURL est present
682
+    elseif (function_exists('curl_init')) {
683
+        //setting the curl parameters.
684
+        $ch = curl_init($url_cron);
685
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
686
+        // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
687
+        curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
688
+        // valeur mini pour que la requete soit lancee
689
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
690
+        // lancer
691
+        curl_exec($ch);
692
+        // fermer
693
+        curl_close($ch);
694
+        return true;
695
+    }
696
+
697
+    return false;
698 698
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -38 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	$md5args = md5($arguments);
71 71
 
72 72
 	// si pas de date programee, des que possible
73
-	$duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
73
+	$duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND ';
74 74
 	if (!$time) {
75 75
 		$time = time();
76 76
 		$duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
@@ -96,9 +96,8 @@  discard block
 block discarded – undo
96 96
 			'id_job',
97 97
 			'spip_jobs',
98 98
 			$duplicate_where =
99
-				$duplicate_where . 'fonction=' . sql_quote($function)
100
-				. (($no_duplicate === 'function_only') ? '' :
101
-			' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
99
+				$duplicate_where.'fonction='.sql_quote($function)
100
+				. (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file))
102 101
 		)
103 102
 	) {
104 103
 		return $id_job;
@@ -111,9 +110,9 @@  discard block
 block discarded – undo
111 110
 	if (
112 111
 		$no_duplicate
113 112
 		and
114
-		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
113
+		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<'.intval($id_job)." AND $duplicate_where")
115 114
 	) {
116
-		sql_delete('spip_jobs', 'id_job=' . intval($id_job));
115
+		sql_delete('spip_jobs', 'id_job='.intval($id_job));
117 116
 
118 117
 		return $id_prev;
119 118
 	}
@@ -125,9 +124,9 @@  discard block
 block discarded – undo
125 124
 	// ie cas d'un char non acceptables sur certains type de champs
126 125
 	// qui coupe la valeur
127 126
 	if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
127
+		$args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job));
129 128
 		if ($args !== $arguments) {
130
-			spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
129
+			spip_log('arguments job errones / longueur '.strlen($args).' vs '.strlen($arguments).' / valeur : '.var_export(
131 130
 				$arguments,
132 131
 				true
133 132
 			), 'queue');
@@ -157,7 +156,7 @@  discard block
 block discarded – undo
157 156
 function queue_purger() {
158 157
 	include_spip('base/abstract_sql');
159 158
 	sql_delete('spip_jobs');
160
-	sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
159
+	sql_delete('spip_jobs_liens', 'id_job NOT IN ('.sql_get_select('id_job', 'spip_jobs').')');
161 160
 	include_spip('inc/genie');
162 161
 	genie_queue_watch_dist();
163 162
 }
@@ -173,8 +172,8 @@  discard block
 block discarded – undo
173 172
 	include_spip('base/abstract_sql');
174 173
 
175 174
 	if (
176
-		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
-		and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
175
+		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job))
176
+		and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job))
178 177
 	) {
179 178
 		queue_unlink_job($id_job);
180 179
 		// est-ce une tache cron qu'il faut relancer ?
@@ -224,7 +223,7 @@  discard block
 block discarded – undo
224 223
  *  resultat du sql_delete
225 224
  */
226 225
 function queue_unlink_job($id_job) {
227
-	return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
226
+	return sql_delete('spip_jobs_liens', 'id_job='.intval($id_job));
228 227
 }
229 228
 
230 229
 /**
@@ -240,7 +239,7 @@  discard block
 block discarded – undo
240 239
 	// deserialiser les arguments
241 240
 	$args = unserialize($row['args']);
242 241
 	if (!is_array($args)) {
243
-		spip_log('arguments job errones ' . var_export($row, true), 'queue');
242
+		spip_log('arguments job errones '.var_export($row, true), 'queue');
244 243
 		$args = [];
245 244
 	}
246 245
 
@@ -257,14 +256,14 @@  discard block
 block discarded – undo
257 256
 	}
258 257
 
259 258
 	if (!function_exists($fonction)) {
260
-		spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
259
+		spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue');
261 260
 
262 261
 		return false;
263 262
 	}
264 263
 
265
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
264
+	spip_log('queue ['.$row['id_job']."]: $fonction() start", 'queue');
266 265
 	$res = $fonction(...$args);
267
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
266
+	spip_log('queue ['.$row['id_job']."]: $fonction() end", 'queue');
268 267
 
269 268
 	return $res;
270 269
 }
@@ -295,14 +294,14 @@  discard block
 block discarded – undo
295 294
 function queue_schedule($force_jobs = null) {
296 295
 	$time = time();
297 296
 	if (defined('_DEBUG_BLOCK_QUEUE')) {
298
-		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
297
+		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq'._LOG_DEBUG);
299 298
 
300 299
 		return;
301 300
 	}
302 301
 
303 302
 	// rien a faire si le prochain job est encore dans le futur
304 303
 	if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
305
-		spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
304
+		spip_log('queue_sleep_time_to_next_job', 'jq'._LOG_DEBUG);
306 305
 
307 306
 		return;
308 307
 	}
@@ -323,7 +322,7 @@  discard block
 block discarded – undo
323 322
 	}
324 323
 	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
325 324
 
326
-	spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
325
+	spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG);
327 326
 
328 327
 	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
329 328
 		define('_JQ_MAX_JOBS_EXECUTE', 200);
@@ -337,19 +336,19 @@  discard block
 block discarded – undo
337 336
 	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
338 337
 	// pour qu'il ne bloque pas les autres jobs en attente
339 338
 	if (is_array($force_jobs) and count($force_jobs)) {
340
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
339
+		$cond = 'status='.intval(_JQ_SCHEDULED).' AND '.sql_in('id_job', $force_jobs);
341 340
 	} else {
342 341
 		$now = date('Y-m-d H:i:s', $time);
343
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
342
+		$cond = 'status='.intval(_JQ_SCHEDULED).' AND date<='.sql_quote($now);
344 343
 	}
345 344
 
346 345
 	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
347
-	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
346
+	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1));
348 347
 	do {
349 348
 		if ($row = array_shift($res)) {
350 349
 			$nbj++;
351 350
 			// il faut un verrou, a base de sql_delete
352
-			if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
351
+			if (sql_delete('spip_jobs', 'id_job='.intval($row['id_job']).' AND status='.intval(_JQ_SCHEDULED))) {
353 352
 				#spip_log("JQ schedule job ".$nbj." OK",'jq');
354 353
 				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
355 354
 				$row['status'] = _JQ_PENDING;
@@ -364,13 +363,13 @@  discard block
 block discarded – undo
364 363
 				queue_close_job($row, $time, $result);
365 364
 			}
366 365
 		}
367
-		spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
366
+		spip_log('JQ schedule job end time '.$time, 'jq'._LOG_DEBUG);
368 367
 	} while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
369
-	spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
368
+	spip_log('JQ schedule end time '.time(), 'jq'._LOG_DEBUG);
370 369
 
371 370
 	if ($row = array_shift($res)) {
372 371
 		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
373
-		spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
372
+		spip_log('JQ encore !', 'jq'._LOG_DEBUG);
374 373
 	} else {
375 374
 		queue_update_next_job_time();
376 375
 	}
@@ -405,9 +404,9 @@  discard block
 block discarded – undo
405 404
 		}
406 405
 	}
407 406
 	// purger ses liens eventuels avec des objets
408
-	sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
407
+	sql_delete('spip_jobs_liens', 'id_job='.intval($row['id_job']));
409 408
 	// supprimer le job fini
410
-	sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
409
+	sql_delete('spip_jobs', 'id_job='.intval($row['id_job']));
411 410
 }
412 411
 
413 412
 /**
@@ -480,18 +479,18 @@  discard block
 block discarded – undo
480 479
 	$res = sql_allfetsel(
481 480
 		'*',
482 481
 		'spip_jobs',
483
-		'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
482
+		'status='.intval(_JQ_PENDING).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time - 180))
484 483
 	);
485 484
 	if (is_array($res)) {
486 485
 		foreach ($res as $row) {
487 486
 			queue_close_job($row, $time);
488
-			spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
487
+			spip_log('queue_close_job car _JQ_PENDING depuis +180s : '.print_r($row, 1), 'job_mort'._LOG_ERREUR);
489 488
 		}
490 489
 	}
491 490
 
492 491
 	// chercher la date du prochain job si pas connu
493 492
 	if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
494
-		$date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
493
+		$date = sql_getfetsel('date', 'spip_jobs', 'status='.intval(_JQ_SCHEDULED), '', 'date', '0,1');
495 494
 		$next = strtotime($date);
496 495
 	}
497 496
 	if (!is_null($next_time)) {
@@ -504,7 +503,7 @@  discard block
 block discarded – undo
504 503
 		if (is_null($nb_jobs_scheduled)) {
505 504
 			$nb_jobs_scheduled = sql_countsel(
506 505
 				'spip_jobs',
507
-				'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
506
+				'status='.intval(_JQ_SCHEDULED).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time))
508 507
 			);
509 508
 		} elseif ($next <= $time) {
510 509
 			$nb_jobs_scheduled++;
@@ -573,7 +572,7 @@  discard block
 block discarded – undo
573 572
 	}
574 573
 
575 574
 	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
576
-	if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
575
+	if (file_exists($lock = _DIR_TMP.'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
577 576
 		return $texte;
578 577
 	}
579 578
 
@@ -645,7 +644,7 @@  discard block
 block discarded – undo
645 644
 				$port = 80;
646 645
 		}
647 646
 		$fp = @fsockopen(
648
-			$scheme . $parts['host'],
647
+			$scheme.$parts['host'],
649 648
 			$parts['port'] ?? $port,
650 649
 			$errno,
651 650
 			$errstr,
@@ -655,13 +654,13 @@  discard block
 block discarded – undo
655 654
 		if ($fp) {
656 655
 			$host_sent = $parts['host'];
657 656
 			if (isset($parts['port']) and $parts['port'] !== $port) {
658
-				$host_sent .= ':' . $parts['port'];
657
+				$host_sent .= ':'.$parts['port'];
659 658
 			}
660 659
 			$timeout = 200; // ms
661 660
 			stream_set_timeout($fp, 0, $timeout * 1000);
662
-			$query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
663
-			$out = 'GET ' . $query . " HTTP/1.1\r\n";
664
-			$out .= 'Host: ' . $host_sent . "\r\n";
661
+			$query = $parts['path'].($parts['query'] ? '?'.$parts['query'] : '');
662
+			$out = 'GET '.$query." HTTP/1.1\r\n";
663
+			$out .= 'Host: '.$host_sent."\r\n";
665 664
 			$out .= "Connection: Close\r\n\r\n";
666 665
 			fwrite($fp, $out);
667 666
 			spip_timer('read');
Please login to merge, or discard this patch.
ecrire/install/etape_ldap2.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,8 +39,7 @@
 block discarded – undo
39 39
 		} else {
40 40
 			$tls = true;
41 41
 		}
42
-	}
43
-	else {
42
+	} else {
44 43
 		$tls_ldap == 'non';
45 44
 	}
46 45
 
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -10,88 +10,88 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 function install_etape_ldap2_dist() {
17
-	$minipage = new Spip\Afficher\Minipage\Installation();
18
-	echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']);
19
-
20
-	$adresse_ldap = _request('adresse_ldap');
21
-
22
-	$port_ldap = _request('port_ldap');
23
-
24
-	$tls_ldap = _request('tls_ldap');
25
-
26
-	$protocole_ldap = _request('protocole_ldap');
27
-
28
-	$login_ldap = _request('login_ldap');
29
-
30
-	$pass_ldap = _request('pass_ldap');
31
-
32
-	$port_ldap = (int) $port_ldap;
33
-
34
-	$tls = false;
35
-
36
-	if ($tls_ldap == 'oui') {
37
-		if ($port_ldap == 636) {
38
-			$adresse_ldap = "ldaps://$adresse_ldap";
39
-		} else {
40
-			$tls = true;
41
-		}
42
-	}
43
-	else {
44
-		$tls_ldap == 'non';
45
-	}
46
-
47
-	// Verifions que l'adresse demandee est valide
48
-	$adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
-
50
-	$ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
-	$erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
-
53
-	if ($ldap_link) {
54
-		if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
-			$protocole_ldap = 2;
56
-			ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
-		}
58
-		if ($tls && !ldap_start_tls($ldap_link)) {
59
-			$erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
60
-				. ' ' . spip_htmlspecialchars($adresse_ldap)
61
-				. ', ' . spip_htmlspecialchars($port_ldap) . ')';
62
-			$ldap_link = false;
63
-		}
64
-		if ($ldap_link) {
65
-			$ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
66
-			$erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
67
-				. "', '" . spip_htmlspecialchars($login_ldap)
68
-				. "', '" . spip_htmlspecialchars($pass_ldap)
69
-				. "'): " . spip_htmlspecialchars($adresse_ldap)
70
-				. ', ' . spip_htmlspecialchars($port_ldap);
71
-		}
72
-	}
73
-
74
-	if ($ldap_link) {
75
-		echo info_etape(
76
-			_T('titre_connexion_ldap'),
77
-			info_progression_etape(2, 'etape_ldap', 'install/')
78
-		),  _T('info_connexion_ldap_ok');
79
-		echo generer_form_ecrire('install', (
80
-			"\n<input type='hidden' name='etape' value='ldap3' />"
81
-			. "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
82
-			. "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
83
-			. "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
84
-			. "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
85
-			. "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
86
-			. "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
87
-			. bouton_suivant()));
88
-	} else {
89
-		echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
90
-			"<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
91
-			'<p>' . _T('avis_connexion_ldap_echec_2') .
92
-			"<br />\n" . _T('avis_connexion_ldap_echec_3') .
93
-			'<br /><br />' . $erreur . '<b> ?</b></p></div>';
94
-	}
95
-
96
-	echo $minipage->installFinPage();
17
+    $minipage = new Spip\Afficher\Minipage\Installation();
18
+    echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']);
19
+
20
+    $adresse_ldap = _request('adresse_ldap');
21
+
22
+    $port_ldap = _request('port_ldap');
23
+
24
+    $tls_ldap = _request('tls_ldap');
25
+
26
+    $protocole_ldap = _request('protocole_ldap');
27
+
28
+    $login_ldap = _request('login_ldap');
29
+
30
+    $pass_ldap = _request('pass_ldap');
31
+
32
+    $port_ldap = (int) $port_ldap;
33
+
34
+    $tls = false;
35
+
36
+    if ($tls_ldap == 'oui') {
37
+        if ($port_ldap == 636) {
38
+            $adresse_ldap = "ldaps://$adresse_ldap";
39
+        } else {
40
+            $tls = true;
41
+        }
42
+    }
43
+    else {
44
+        $tls_ldap == 'non';
45
+    }
46
+
47
+    // Verifions que l'adresse demandee est valide
48
+    $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49
+
50
+    $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
+    $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
52
+
53
+    if ($ldap_link) {
54
+        if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
55
+            $protocole_ldap = 2;
56
+            ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57
+        }
58
+        if ($tls && !ldap_start_tls($ldap_link)) {
59
+            $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
60
+                . ' ' . spip_htmlspecialchars($adresse_ldap)
61
+                . ', ' . spip_htmlspecialchars($port_ldap) . ')';
62
+            $ldap_link = false;
63
+        }
64
+        if ($ldap_link) {
65
+            $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
66
+            $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
67
+                . "', '" . spip_htmlspecialchars($login_ldap)
68
+                . "', '" . spip_htmlspecialchars($pass_ldap)
69
+                . "'): " . spip_htmlspecialchars($adresse_ldap)
70
+                . ', ' . spip_htmlspecialchars($port_ldap);
71
+        }
72
+    }
73
+
74
+    if ($ldap_link) {
75
+        echo info_etape(
76
+            _T('titre_connexion_ldap'),
77
+            info_progression_etape(2, 'etape_ldap', 'install/')
78
+        ),  _T('info_connexion_ldap_ok');
79
+        echo generer_form_ecrire('install', (
80
+            "\n<input type='hidden' name='etape' value='ldap3' />"
81
+            . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
82
+            . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
83
+            . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
84
+            . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
85
+            . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
86
+            . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
87
+            . bouton_suivant()));
88
+    } else {
89
+        echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
90
+            "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
91
+            '<p>' . _T('avis_connexion_ldap_echec_2') .
92
+            "<br />\n" . _T('avis_connexion_ldap_echec_3') .
93
+            '<br /><br />' . $erreur . '<b> ?</b></p></div>';
94
+    }
95
+
96
+    echo $minipage->installFinPage();
97 97
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	$adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: '';
49 49
 
50 50
 	$ldap_link = ldap_connect($adresse_ldap, $port_ldap);
51
-	$erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')';
51
+	$erreur = 'ldap_connect('.spip_htmlspecialchars($adresse_ldap).', '.spip_htmlspecialchars($port_ldap).')';
52 52
 
53 53
 	if ($ldap_link) {
54 54
 		if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) {
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
 			ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap);
57 57
 		}
58 58
 		if ($tls && !ldap_start_tls($ldap_link)) {
59
-			$erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link)
60
-				. ' ' . spip_htmlspecialchars($adresse_ldap)
61
-				. ', ' . spip_htmlspecialchars($port_ldap) . ')';
59
+			$erreur = 'ldap_start_tls('.spip_htmlspecialchars($ldap_link)
60
+				. ' '.spip_htmlspecialchars($adresse_ldap)
61
+				. ', '.spip_htmlspecialchars($port_ldap).')';
62 62
 			$ldap_link = false;
63 63
 		}
64 64
 		if ($ldap_link) {
65 65
 			$ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap);
66
-			$erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link)
67
-				. "', '" . spip_htmlspecialchars($login_ldap)
68
-				. "', '" . spip_htmlspecialchars($pass_ldap)
69
-				. "'): " . spip_htmlspecialchars($adresse_ldap)
70
-				. ', ' . spip_htmlspecialchars($port_ldap);
66
+			$erreur = "ldap_bind('".spip_htmlspecialchars($ldap_link)
67
+				. "', '".spip_htmlspecialchars($login_ldap)
68
+				. "', '".spip_htmlspecialchars($pass_ldap)
69
+				. "'): ".spip_htmlspecialchars($adresse_ldap)
70
+				. ', '.spip_htmlspecialchars($port_ldap);
71 71
 		}
72 72
 	}
73 73
 
@@ -75,22 +75,22 @@  discard block
 block discarded – undo
75 75
 		echo info_etape(
76 76
 			_T('titre_connexion_ldap'),
77 77
 			info_progression_etape(2, 'etape_ldap', 'install/')
78
-		),  _T('info_connexion_ldap_ok');
78
+		), _T('info_connexion_ldap_ok');
79 79
 		echo generer_form_ecrire('install', (
80 80
 			"\n<input type='hidden' name='etape' value='ldap3' />"
81
-			. "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />'
82
-			. "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />'
83
-			. "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />'
84
-			. "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />'
85
-			. "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />'
86
-			. "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />'
81
+			. "\n<input type='hidden' name='adresse_ldap' value=\"".spip_htmlspecialchars($adresse_ldap).'" />'
82
+			. "\n<input type='hidden' name='port_ldap' value=\"".spip_htmlspecialchars($port_ldap).'" />'
83
+			. "\n<input type='hidden' name='login_ldap' value=\"".spip_htmlspecialchars($login_ldap).'" />'
84
+			. "\n<input type='hidden' name='pass_ldap' value=\"".spip_htmlspecialchars($pass_ldap).'" />'
85
+			. "\n<input type='hidden' name='protocole_ldap' value=\"".spip_htmlspecialchars($protocole_ldap).'" />'
86
+			. "\n<input type='hidden' name='tls_ldap' value=\"".spip_htmlspecialchars($tls_ldap).'" />'
87 87
 			. bouton_suivant()));
88 88
 	} else {
89 89
 		echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true),
90
-			"<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>',
91
-			'<p>' . _T('avis_connexion_ldap_echec_2') .
92
-			"<br />\n" . _T('avis_connexion_ldap_echec_3') .
93
-			'<br /><br />' . $erreur . '<b> ?</b></p></div>';
90
+			"<div class='error'><p>"._T('avis_connexion_ldap_echec_1').'</p>',
91
+			'<p>'._T('avis_connexion_ldap_echec_2').
92
+			"<br />\n"._T('avis_connexion_ldap_echec_3').
93
+			'<br /><br />'.$erreur.'<b> ?</b></p></div>';
94 94
 	}
95 95
 
96 96
 	echo $minipage->installFinPage();
Please login to merge, or discard this patch.
ecrire/inc/distant.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
122 122
 			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
123 123
 			@unlink($localrac_tmp);
124
-		}
125
-		else {
124
+		} else {
126 125
 			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
127 126
 		}
128 127
 		if (!$res or !$res['length']) {
@@ -240,8 +239,7 @@  discard block
 block discarded – undo
240 239
 						break;
241 240
 					}
242 241
 				}
243
-			}
244
-			else {
242
+			} else {
245 243
 				$ip = false;
246 244
 			}
247 245
 		}
Please login to merge, or discard this patch.
Indentation   +1087 added lines, -1087 removed lines patch added patch discarded remove patch
@@ -17,32 +17,32 @@  discard block
 block discarded – undo
17 17
  * @package SPIP\Core\Distant
18 18
  **/
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
24
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
25 25
 }
26 26
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
27
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
28 28
 }
29 29
 if (!defined('_INC_DISTANT_USER_AGENT')) {
30
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
31 31
 }
32 32
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
33
-	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
33
+    define('_INC_DISTANT_MAX_SIZE', 2_097_152);
34 34
 }
35 35
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
36
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
37 37
 }
38 38
 
39 39
 define('_REGEXP_COPIE_LOCALE', ',' 	.
40
-	preg_replace(
41
-		'@^https?:@',
42
-		'https?:',
43
-		($GLOBALS['meta']['adresse_site'] ?? '')
44
-	)
45
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
40
+    preg_replace(
41
+        '@^https?:@',
42
+        'https?:',
43
+        ($GLOBALS['meta']['adresse_site'] ?? '')
44
+    )
45
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
46 46
 
47 47
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
48 48
 
@@ -71,107 +71,107 @@  discard block
 block discarded – undo
71 71
  */
72 72
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) {
73 73
 
74
-	// si c'est la protection de soi-meme, retourner le path
75
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
77
-
78
-		return @file_exists($source) ? $source : false;
79
-	}
80
-
81
-	if (is_null($local)) {
82
-		$local = fichier_copie_locale($source);
83
-	} else {
84
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
85
-			$local = substr($local, strlen(_DIR_RACINE));
86
-		}
87
-	}
88
-
89
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
90
-	// par exemple un fichier qui ne figure pas dans nos documents ;
91
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
92
-	if (!$local) {
93
-		return false;
94
-	}
95
-
96
-	$localrac = _DIR_RACINE . $local;
97
-	$t = ($mode === 'force') ? false : @file_exists($localrac);
98
-
99
-	// test d'existence du fichier
100
-	if ($mode === 'test') {
101
-		return $t ? $local : '';
102
-	}
103
-
104
-	// sinon voir si on doit/peut le telecharger
105
-	if ($local === $source or !tester_url_absolue($source)) {
106
-		return $t ? $local : '';
107
-	}
108
-
109
-	if ($mode === 'modif' or !$t) {
110
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
111
-		// et des eventuelles recuperations concurantes
112
-		include_spip('inc/acces');
113
-		if (!$taille_max) {
114
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
115
-		}
116
-		$localrac_tmp = $localrac . '.tmp';
117
-		$res = recuperer_url(
118
-			$source,
119
-			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120
-		);
121
-
122
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
124
-			@unlink($localrac_tmp);
125
-		}
126
-		else {
127
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
128
-		}
129
-		if (!$res or !$res['length']) {
130
-			// si $t c'est sans doute juste un not-modified-since
131
-			return $t ? $local : false;
132
-		}
133
-
134
-		// si option valider url, verifions que l'URL finale est acceptable
135
-		if (
136
-			$callback_valider_url
137
-			and is_callable($callback_valider_url)
138
-			and !$callback_valider_url($res['url'])
139
-		) {
140
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
141
-			@unlink($localrac_tmp);
142
-			return $t ? $local : false;
143
-		}
144
-
145
-		// on peut renommer le fichier tmp
146
-		@rename($localrac_tmp, $localrac);
147
-
148
-		// si on retrouve l'extension
149
-		if (
150
-			!empty($res['headers'])
151
-			and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
152
-		) {
153
-			if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
154
-				$sanitizer($localrac);
155
-			}
156
-		}
157
-
158
-		// pour une eventuelle indexation
159
-		pipeline(
160
-			'post_edition',
161
-			[
162
-				'args' => [
163
-					'operation' => 'copie_locale',
164
-					'source' => $source,
165
-					'fichier' => $local,
166
-					'http_res' => $res['length'],
167
-					'url' => $res['url'],
168
-				],
169
-				'data' => null
170
-			]
171
-		);
172
-	}
173
-
174
-	return $local;
74
+    // si c'est la protection de soi-meme, retourner le path
75
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
77
+
78
+        return @file_exists($source) ? $source : false;
79
+    }
80
+
81
+    if (is_null($local)) {
82
+        $local = fichier_copie_locale($source);
83
+    } else {
84
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
85
+            $local = substr($local, strlen(_DIR_RACINE));
86
+        }
87
+    }
88
+
89
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
90
+    // par exemple un fichier qui ne figure pas dans nos documents ;
91
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
92
+    if (!$local) {
93
+        return false;
94
+    }
95
+
96
+    $localrac = _DIR_RACINE . $local;
97
+    $t = ($mode === 'force') ? false : @file_exists($localrac);
98
+
99
+    // test d'existence du fichier
100
+    if ($mode === 'test') {
101
+        return $t ? $local : '';
102
+    }
103
+
104
+    // sinon voir si on doit/peut le telecharger
105
+    if ($local === $source or !tester_url_absolue($source)) {
106
+        return $t ? $local : '';
107
+    }
108
+
109
+    if ($mode === 'modif' or !$t) {
110
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
111
+        // et des eventuelles recuperations concurantes
112
+        include_spip('inc/acces');
113
+        if (!$taille_max) {
114
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
115
+        }
116
+        $localrac_tmp = $localrac . '.tmp';
117
+        $res = recuperer_url(
118
+            $source,
119
+            ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120
+        );
121
+
122
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
+            spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
124
+            @unlink($localrac_tmp);
125
+        }
126
+        else {
127
+            spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
128
+        }
129
+        if (!$res or !$res['length']) {
130
+            // si $t c'est sans doute juste un not-modified-since
131
+            return $t ? $local : false;
132
+        }
133
+
134
+        // si option valider url, verifions que l'URL finale est acceptable
135
+        if (
136
+            $callback_valider_url
137
+            and is_callable($callback_valider_url)
138
+            and !$callback_valider_url($res['url'])
139
+        ) {
140
+            spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
141
+            @unlink($localrac_tmp);
142
+            return $t ? $local : false;
143
+        }
144
+
145
+        // on peut renommer le fichier tmp
146
+        @rename($localrac_tmp, $localrac);
147
+
148
+        // si on retrouve l'extension
149
+        if (
150
+            !empty($res['headers'])
151
+            and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
152
+        ) {
153
+            if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
154
+                $sanitizer($localrac);
155
+            }
156
+        }
157
+
158
+        // pour une eventuelle indexation
159
+        pipeline(
160
+            'post_edition',
161
+            [
162
+                'args' => [
163
+                    'operation' => 'copie_locale',
164
+                    'source' => $source,
165
+                    'fichier' => $local,
166
+                    'http_res' => $res['length'],
167
+                    'url' => $res['url'],
168
+                ],
169
+                'data' => null
170
+            ]
171
+        );
172
+    }
173
+
174
+    return $local;
175 175
 }
176 176
 
177 177
 /**
@@ -186,99 +186,99 @@  discard block
 block discarded – undo
186 186
  *   url ou false en cas d'echec
187 187
  */
188 188
 function valider_url_distante($url, $known_hosts = []) {
189
-	if (!function_exists('protocole_verifier')) {
190
-		include_spip('inc/filtres_mini');
191
-	}
192
-
193
-	if (!protocole_verifier($url, ['http', 'https'])) {
194
-		return false;
195
-	}
196
-
197
-	$parsed_url = parse_url($url);
198
-	if (!$parsed_url or empty($parsed_url['host'])) {
199
-		return false;
200
-	}
201
-
202
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
203
-		return false;
204
-	}
205
-
206
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
207
-		return false;
208
-	}
209
-
210
-	if (!is_array($known_hosts)) {
211
-		$known_hosts = [$known_hosts];
212
-	}
213
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
214
-	$known_hosts[] = url_de_base();
215
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
216
-
217
-	$is_known_host = false;
218
-	foreach ($known_hosts as $known_host) {
219
-		$parse_known = parse_url($known_host);
220
-		if (
221
-			$parse_known
222
-			and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
223
-		) {
224
-			$is_known_host = true;
225
-			break;
226
-		}
227
-	}
228
-
229
-	if (!$is_known_host) {
230
-		$host = trim($parsed_url['host'], '.');
231
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
232
-			$ip = gethostbyname($host);
233
-			if ($ip === $host) {
234
-				// Error condition for gethostbyname()
235
-				$ip = false;
236
-			}
237
-			if ($records = dns_get_record($host)) {
238
-				foreach ($records as $record) {
239
-					// il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
240
-					// se fasse sur la meme IP
241
-					if ($record['ttl'] < 10) {
242
-						$ip = false;
243
-						break;
244
-					}
245
-				}
246
-			}
247
-			else {
248
-				$ip = false;
249
-			}
250
-		}
251
-		if ($ip) {
252
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253
-				return false;
254
-			}
255
-		}
256
-	}
257
-
258
-	if (empty($parsed_url['port'])) {
259
-		return $url;
260
-	}
261
-
262
-	$port = $parsed_url['port'];
263
-	if ($port === 80  or $port === 443  or $port === 8080) {
264
-		return $url;
265
-	}
266
-
267
-	if ($is_known_host) {
268
-		foreach ($known_hosts as $known_host) {
269
-			$parse_known = parse_url($known_host);
270
-			if (
271
-				$parse_known
272
-				and !empty($parse_known['port'])
273
-				and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
274
-				and $parse_known['port'] == $port
275
-			) {
276
-				return $url;
277
-			}
278
-		}
279
-	}
280
-
281
-	return false;
189
+    if (!function_exists('protocole_verifier')) {
190
+        include_spip('inc/filtres_mini');
191
+    }
192
+
193
+    if (!protocole_verifier($url, ['http', 'https'])) {
194
+        return false;
195
+    }
196
+
197
+    $parsed_url = parse_url($url);
198
+    if (!$parsed_url or empty($parsed_url['host'])) {
199
+        return false;
200
+    }
201
+
202
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
203
+        return false;
204
+    }
205
+
206
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
207
+        return false;
208
+    }
209
+
210
+    if (!is_array($known_hosts)) {
211
+        $known_hosts = [$known_hosts];
212
+    }
213
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
214
+    $known_hosts[] = url_de_base();
215
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
216
+
217
+    $is_known_host = false;
218
+    foreach ($known_hosts as $known_host) {
219
+        $parse_known = parse_url($known_host);
220
+        if (
221
+            $parse_known
222
+            and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
223
+        ) {
224
+            $is_known_host = true;
225
+            break;
226
+        }
227
+    }
228
+
229
+    if (!$is_known_host) {
230
+        $host = trim($parsed_url['host'], '.');
231
+        if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
232
+            $ip = gethostbyname($host);
233
+            if ($ip === $host) {
234
+                // Error condition for gethostbyname()
235
+                $ip = false;
236
+            }
237
+            if ($records = dns_get_record($host)) {
238
+                foreach ($records as $record) {
239
+                    // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
240
+                    // se fasse sur la meme IP
241
+                    if ($record['ttl'] < 10) {
242
+                        $ip = false;
243
+                        break;
244
+                    }
245
+                }
246
+            }
247
+            else {
248
+                $ip = false;
249
+            }
250
+        }
251
+        if ($ip) {
252
+            if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253
+                return false;
254
+            }
255
+        }
256
+    }
257
+
258
+    if (empty($parsed_url['port'])) {
259
+        return $url;
260
+    }
261
+
262
+    $port = $parsed_url['port'];
263
+    if ($port === 80  or $port === 443  or $port === 8080) {
264
+        return $url;
265
+    }
266
+
267
+    if ($is_known_host) {
268
+        foreach ($known_hosts as $known_host) {
269
+            $parse_known = parse_url($known_host);
270
+            if (
271
+                $parse_known
272
+                and !empty($parse_known['port'])
273
+                and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
274
+                and $parse_known['port'] == $port
275
+            ) {
276
+                return $url;
277
+            }
278
+        }
279
+    }
280
+
281
+    return false;
282 282
 }
283 283
 
284 284
 /**
@@ -298,86 +298,86 @@  discard block
 block discarded – undo
298 298
  */
299 299
 function prepare_donnees_post($donnees, $boundary = '') {
300 300
 
301
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
302
-	// pour un appel soap par exemple
303
-	// l'entete est separe des donnees par un double retour a la ligne
304
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
305
-	if (is_string($donnees) && strlen($donnees)) {
306
-		$entete = '';
307
-		// on repasse tous les \r\n et \r en simples \n
308
-		$donnees = str_replace("\r\n", "\n", $donnees);
309
-		$donnees = str_replace("\r", "\n", $donnees);
310
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
311
-		$p = strpos($donnees, "\n\n");
312
-		if ($p !== false) {
313
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
314
-			$donnees = substr($donnees, $p + 2);
315
-		}
316
-		$chaine = str_replace("\n", "\r\n", $donnees);
317
-	} else {
318
-		/* boundary automatique */
319
-		// Si on a plus de 500 octects de donnees, on "boundarise"
320
-		if ($boundary === '') {
321
-			$taille = 0;
322
-			foreach ($donnees as $cle => $valeur) {
323
-				if (is_array($valeur)) {
324
-					foreach ($valeur as $val2) {
325
-						$taille += strlen($val2);
326
-					}
327
-				} else {
328
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
329
-					$taille += strlen($valeur);
330
-				}
331
-			}
332
-			if ($taille > 500) {
333
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
334
-			}
335
-		}
336
-
337
-		if (is_string($boundary) and strlen($boundary)) {
338
-			// fabrique une chaine HTTP pour un POST avec boundary
339
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
340
-			$chaine = '';
341
-			if (is_array($donnees)) {
342
-				foreach ($donnees as $cle => $valeur) {
343
-					if (is_array($valeur)) {
344
-						foreach ($valeur as $val2) {
345
-							$chaine .= "\r\n--$boundary\r\n";
346
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
347
-							$chaine .= "\r\n";
348
-							$chaine .= $val2;
349
-						}
350
-					} else {
351
-						$chaine .= "\r\n--$boundary\r\n";
352
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
353
-						$chaine .= "\r\n";
354
-						$chaine .= $valeur;
355
-					}
356
-				}
357
-				$chaine .= "\r\n--$boundary\r\n";
358
-			}
359
-		} else {
360
-			// fabrique une chaine HTTP simple pour un POST
361
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
362
-			$chaine = [];
363
-			if (is_array($donnees)) {
364
-				foreach ($donnees as $cle => $valeur) {
365
-					if (is_array($valeur)) {
366
-						foreach ($valeur as $val2) {
367
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
368
-						}
369
-					} else {
370
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
371
-					}
372
-				}
373
-				$chaine = implode('&', $chaine);
374
-			} else {
375
-				$chaine = $donnees;
376
-			}
377
-		}
378
-	}
379
-
380
-	return [$entete, $chaine];
301
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
302
+    // pour un appel soap par exemple
303
+    // l'entete est separe des donnees par un double retour a la ligne
304
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
305
+    if (is_string($donnees) && strlen($donnees)) {
306
+        $entete = '';
307
+        // on repasse tous les \r\n et \r en simples \n
308
+        $donnees = str_replace("\r\n", "\n", $donnees);
309
+        $donnees = str_replace("\r", "\n", $donnees);
310
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
311
+        $p = strpos($donnees, "\n\n");
312
+        if ($p !== false) {
313
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
314
+            $donnees = substr($donnees, $p + 2);
315
+        }
316
+        $chaine = str_replace("\n", "\r\n", $donnees);
317
+    } else {
318
+        /* boundary automatique */
319
+        // Si on a plus de 500 octects de donnees, on "boundarise"
320
+        if ($boundary === '') {
321
+            $taille = 0;
322
+            foreach ($donnees as $cle => $valeur) {
323
+                if (is_array($valeur)) {
324
+                    foreach ($valeur as $val2) {
325
+                        $taille += strlen($val2);
326
+                    }
327
+                } else {
328
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
329
+                    $taille += strlen($valeur);
330
+                }
331
+            }
332
+            if ($taille > 500) {
333
+                $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
334
+            }
335
+        }
336
+
337
+        if (is_string($boundary) and strlen($boundary)) {
338
+            // fabrique une chaine HTTP pour un POST avec boundary
339
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
340
+            $chaine = '';
341
+            if (is_array($donnees)) {
342
+                foreach ($donnees as $cle => $valeur) {
343
+                    if (is_array($valeur)) {
344
+                        foreach ($valeur as $val2) {
345
+                            $chaine .= "\r\n--$boundary\r\n";
346
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
347
+                            $chaine .= "\r\n";
348
+                            $chaine .= $val2;
349
+                        }
350
+                    } else {
351
+                        $chaine .= "\r\n--$boundary\r\n";
352
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
353
+                        $chaine .= "\r\n";
354
+                        $chaine .= $valeur;
355
+                    }
356
+                }
357
+                $chaine .= "\r\n--$boundary\r\n";
358
+            }
359
+        } else {
360
+            // fabrique une chaine HTTP simple pour un POST
361
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
362
+            $chaine = [];
363
+            if (is_array($donnees)) {
364
+                foreach ($donnees as $cle => $valeur) {
365
+                    if (is_array($valeur)) {
366
+                        foreach ($valeur as $val2) {
367
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
368
+                        }
369
+                    } else {
370
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
371
+                    }
372
+                }
373
+                $chaine = implode('&', $chaine);
374
+            } else {
375
+                $chaine = $donnees;
376
+            }
377
+        }
378
+    }
379
+
380
+    return [$entete, $chaine];
381 381
 }
382 382
 
383 383
 /**
@@ -388,19 +388,19 @@  discard block
 block discarded – undo
388 388
  */
389 389
 function url_to_ascii($url_idn) {
390 390
 
391
-	if ($parts = parse_url($url_idn)) {
392
-		$host = $parts['host'];
393
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
394
-			$converter = new ToIdn();
395
-			$host_ascii = $converter->convert($host);
396
-			$url_idn = explode($host, $url_idn, 2);
397
-			$url_idn = implode($host_ascii, $url_idn);
398
-		}
399
-		// et on urlencode les char utf si besoin dans le path
400
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
401
-	}
402
-
403
-	return $url_idn;
391
+    if ($parts = parse_url($url_idn)) {
392
+        $host = $parts['host'];
393
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
394
+            $converter = new ToIdn();
395
+            $host_ascii = $converter->convert($host);
396
+            $url_idn = explode($host, $url_idn, 2);
397
+            $url_idn = implode($host_ascii, $url_idn);
398
+        }
399
+        // et on urlencode les char utf si besoin dans le path
400
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
401
+    }
402
+
403
+    return $url_idn;
404 404
 }
405 405
 
406 406
 /**
@@ -441,209 +441,209 @@  discard block
 block discarded – undo
441 441
  *     string file : nom du fichier si enregistre dans un fichier
442 442
  */
443 443
 function recuperer_url($url, $options = []) {
444
-	// Conserve la mémoire de la méthode fournit éventuellement
445
-	$methode_demandee = $options['methode'] ?? '';
446
-	$default = [
447
-		'transcoder' => false,
448
-		'methode' => 'GET',
449
-		'taille_max' => null,
450
-		'headers' => [],
451
-		'datas' => '',
452
-		'boundary' => '',
453
-		'refuser_gz' => false,
454
-		'if_modified_since' => '',
455
-		'uri_referer' => '',
456
-		'file' => '',
457
-		'follow_location' => 10,
458
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
459
-	];
460
-	$options = array_merge($default, $options);
461
-	// copier directement dans un fichier ?
462
-	$copy = $options['file'];
463
-
464
-	if ($options['methode'] == 'HEAD') {
465
-		$options['taille_max'] = 0;
466
-	}
467
-	if (is_null($options['taille_max'])) {
468
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469
-	}
470
-
471
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
472
-
473
-	// Ajout des en-têtes spécifiques si besoin
474
-	$formatted_data = '';
475
-	if (!empty($options['headers'])) {
476
-		foreach ($options['headers'] as $champ => $valeur) {
477
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
478
-		}
479
-	}
480
-
481
-	if (!empty($options['datas'])) {
482
-		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483
-		$head .= $formatted_data;
484
-		if (stripos($head, 'Content-Length:') === false) {
485
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
486
-		}
487
-		$formatted_data = $head . "\r\n" . $postdata;
488
-		if (
489
-			strlen($postdata)
490
-			and !$methode_demandee
491
-		) {
492
-			$options['methode'] = 'POST';
493
-		}
494
-	} elseif ($formatted_data) {
495
-		$formatted_data .= "\r\n";
496
-	}
497
-
498
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499
-	$url = preg_replace(',^feed://,i', 'http://', $url);
500
-	if (!tester_url_absolue($url)) {
501
-		$url = 'http://' . $url;
502
-	} elseif (strncmp($url, '//', 2) == 0) {
503
-		$url = 'http:' . $url;
504
-	}
505
-
506
-	$url = url_to_ascii($url);
507
-
508
-	$result = [
509
-		'status' => 0,
510
-		'headers' => '',
511
-		'page' => '',
512
-		'length' => 0,
513
-		'last_modified' => '',
514
-		'location' => '',
515
-		'url' => $url
516
-	];
517
-
518
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
519
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
520
-
521
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
522
-	[$handle, $fopen] = init_http(
523
-		$options['methode'],
524
-		$url,
525
-		$refuser_gz,
526
-		$options['uri_referer'],
527
-		$formatted_data,
528
-		$options['version_http'],
529
-		$options['if_modified_since']
530
-	);
531
-	if (!$handle) {
532
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
533
-
534
-		return false;
535
-	}
536
-
537
-	// Sauf en fopen, envoyer le flux d'entree
538
-	// et recuperer les en-tetes de reponses
539
-	if (!$fopen) {
540
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
541
-		if (!$res) {
542
-			fclose($handle);
543
-			$t = @parse_url($url);
544
-			$host = $t['host'];
545
-			// Chinoisierie inexplicable pour contrer
546
-			// les actions liberticides de l'empire du milieu
547
-			if (
548
-				!need_proxy($host)
549
-				and $res = @file_get_contents($url)
550
-			) {
551
-				$result['length'] = strlen($res);
552
-				if ($copy) {
553
-					ecrire_fichier($copy, $res);
554
-					$result['file'] = $copy;
555
-				} else {
556
-					$result['page'] = $res;
557
-				}
558
-				$res = [
559
-					'status' => 200,
560
-				];
561
-			} else {
562
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
563
-				return false;
564
-			}
565
-		} elseif ($res['location'] and $options['follow_location']) {
566
-			$options['follow_location']--;
567
-			fclose($handle);
568
-			include_spip('inc/filtres');
569
-			$url = suivre_lien($url, $res['location']);
570
-
571
-			// une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
572
-			if ($options['methode'] !== 'GET') {
573
-				if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
574
-					$options['methode'] = 'GET';
575
-					$options['datas'] = '';
576
-				}
577
-			}
578
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
579
-
580
-			return recuperer_url($url, $options);
581
-		} elseif ($res['status'] !== 200) {
582
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
583
-		}
584
-		$result['status'] = $res['status'];
585
-		if (isset($res['headers'])) {
586
-			$result['headers'] = $res['headers'];
587
-		}
588
-		if (isset($res['last_modified'])) {
589
-			$result['last_modified'] = $res['last_modified'];
590
-		}
591
-		if (isset($res['location'])) {
592
-			$result['location'] = $res['location'];
593
-		}
594
-	}
595
-
596
-	// on ne veut que les entetes
597
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
599
-		return $result;
600
-	}
601
-
602
-
603
-	// s'il faut deballer, le faire via un fichier temporaire
604
-	// sinon la memoire explose pour les gros flux
605
-
606
-	$gz = false;
607
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
609
-	}
610
-
611
-	// si on a pas deja recuperer le contenu par une methode detournee
612
-	if (!$result['length']) {
613
-		$res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
614
-		fclose($handle);
615
-		if ($copy) {
616
-			$result['length'] = $res;
617
-			$result['file'] = $copy;
618
-		} elseif ($res) {
619
-			$result['page'] = &$res;
620
-			$result['length'] = strlen($result['page']);
621
-		}
622
-		if (!$result['status']) {
623
-			$result['status'] = 200; // on a reussi, donc !
624
-		}
625
-	}
626
-	if (!$result['page']) {
627
-		return $result;
628
-	}
629
-
630
-	// Decompresser au besoin
631
-	if ($gz) {
632
-		$result['page'] = implode('', gzfile($gz));
633
-		supprimer_fichier($gz);
634
-	}
635
-
636
-	// Faut-il l'importer dans notre charset local ?
637
-	if ($options['transcoder']) {
638
-		include_spip('inc/charsets');
639
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
640
-	}
641
-
642
-	$trace = json_decode(json_encode($result), true);
643
-	$trace['page'] = '...';
644
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
645
-
646
-	return $result;
444
+    // Conserve la mémoire de la méthode fournit éventuellement
445
+    $methode_demandee = $options['methode'] ?? '';
446
+    $default = [
447
+        'transcoder' => false,
448
+        'methode' => 'GET',
449
+        'taille_max' => null,
450
+        'headers' => [],
451
+        'datas' => '',
452
+        'boundary' => '',
453
+        'refuser_gz' => false,
454
+        'if_modified_since' => '',
455
+        'uri_referer' => '',
456
+        'file' => '',
457
+        'follow_location' => 10,
458
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
459
+    ];
460
+    $options = array_merge($default, $options);
461
+    // copier directement dans un fichier ?
462
+    $copy = $options['file'];
463
+
464
+    if ($options['methode'] == 'HEAD') {
465
+        $options['taille_max'] = 0;
466
+    }
467
+    if (is_null($options['taille_max'])) {
468
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469
+    }
470
+
471
+    spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
472
+
473
+    // Ajout des en-têtes spécifiques si besoin
474
+    $formatted_data = '';
475
+    if (!empty($options['headers'])) {
476
+        foreach ($options['headers'] as $champ => $valeur) {
477
+            $formatted_data .= $champ . ': ' . $valeur . "\r\n";
478
+        }
479
+    }
480
+
481
+    if (!empty($options['datas'])) {
482
+        [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483
+        $head .= $formatted_data;
484
+        if (stripos($head, 'Content-Length:') === false) {
485
+            $head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
486
+        }
487
+        $formatted_data = $head . "\r\n" . $postdata;
488
+        if (
489
+            strlen($postdata)
490
+            and !$methode_demandee
491
+        ) {
492
+            $options['methode'] = 'POST';
493
+        }
494
+    } elseif ($formatted_data) {
495
+        $formatted_data .= "\r\n";
496
+    }
497
+
498
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499
+    $url = preg_replace(',^feed://,i', 'http://', $url);
500
+    if (!tester_url_absolue($url)) {
501
+        $url = 'http://' . $url;
502
+    } elseif (strncmp($url, '//', 2) == 0) {
503
+        $url = 'http:' . $url;
504
+    }
505
+
506
+    $url = url_to_ascii($url);
507
+
508
+    $result = [
509
+        'status' => 0,
510
+        'headers' => '',
511
+        'page' => '',
512
+        'length' => 0,
513
+        'last_modified' => '',
514
+        'location' => '',
515
+        'url' => $url
516
+    ];
517
+
518
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
519
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
520
+
521
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
522
+    [$handle, $fopen] = init_http(
523
+        $options['methode'],
524
+        $url,
525
+        $refuser_gz,
526
+        $options['uri_referer'],
527
+        $formatted_data,
528
+        $options['version_http'],
529
+        $options['if_modified_since']
530
+    );
531
+    if (!$handle) {
532
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
533
+
534
+        return false;
535
+    }
536
+
537
+    // Sauf en fopen, envoyer le flux d'entree
538
+    // et recuperer les en-tetes de reponses
539
+    if (!$fopen) {
540
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
541
+        if (!$res) {
542
+            fclose($handle);
543
+            $t = @parse_url($url);
544
+            $host = $t['host'];
545
+            // Chinoisierie inexplicable pour contrer
546
+            // les actions liberticides de l'empire du milieu
547
+            if (
548
+                !need_proxy($host)
549
+                and $res = @file_get_contents($url)
550
+            ) {
551
+                $result['length'] = strlen($res);
552
+                if ($copy) {
553
+                    ecrire_fichier($copy, $res);
554
+                    $result['file'] = $copy;
555
+                } else {
556
+                    $result['page'] = $res;
557
+                }
558
+                $res = [
559
+                    'status' => 200,
560
+                ];
561
+            } else {
562
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
563
+                return false;
564
+            }
565
+        } elseif ($res['location'] and $options['follow_location']) {
566
+            $options['follow_location']--;
567
+            fclose($handle);
568
+            include_spip('inc/filtres');
569
+            $url = suivre_lien($url, $res['location']);
570
+
571
+            // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
572
+            if ($options['methode'] !== 'GET') {
573
+                if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
574
+                    $options['methode'] = 'GET';
575
+                    $options['datas'] = '';
576
+                }
577
+            }
578
+            spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
579
+
580
+            return recuperer_url($url, $options);
581
+        } elseif ($res['status'] !== 200) {
582
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
583
+        }
584
+        $result['status'] = $res['status'];
585
+        if (isset($res['headers'])) {
586
+            $result['headers'] = $res['headers'];
587
+        }
588
+        if (isset($res['last_modified'])) {
589
+            $result['last_modified'] = $res['last_modified'];
590
+        }
591
+        if (isset($res['location'])) {
592
+            $result['location'] = $res['location'];
593
+        }
594
+    }
595
+
596
+    // on ne veut que les entetes
597
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
+        spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
599
+        return $result;
600
+    }
601
+
602
+
603
+    // s'il faut deballer, le faire via un fichier temporaire
604
+    // sinon la memoire explose pour les gros flux
605
+
606
+    $gz = false;
607
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
+        $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
609
+    }
610
+
611
+    // si on a pas deja recuperer le contenu par une methode detournee
612
+    if (!$result['length']) {
613
+        $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
614
+        fclose($handle);
615
+        if ($copy) {
616
+            $result['length'] = $res;
617
+            $result['file'] = $copy;
618
+        } elseif ($res) {
619
+            $result['page'] = &$res;
620
+            $result['length'] = strlen($result['page']);
621
+        }
622
+        if (!$result['status']) {
623
+            $result['status'] = 200; // on a reussi, donc !
624
+        }
625
+    }
626
+    if (!$result['page']) {
627
+        return $result;
628
+    }
629
+
630
+    // Decompresser au besoin
631
+    if ($gz) {
632
+        $result['page'] = implode('', gzfile($gz));
633
+        supprimer_fichier($gz);
634
+    }
635
+
636
+    // Faut-il l'importer dans notre charset local ?
637
+    if ($options['transcoder']) {
638
+        include_spip('inc/charsets');
639
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
640
+    }
641
+
642
+    $trace = json_decode(json_encode($result), true);
643
+    $trace['page'] = '...';
644
+    spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
645
+
646
+    return $result;
647 647
 }
648 648
 
649 649
 /**
@@ -659,73 +659,73 @@  discard block
 block discarded – undo
659 659
  * @return array|bool|mixed
660 660
  */
661 661
 function recuperer_url_cache($url, $options = []) {
662
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
663
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
664
-	}
665
-	$default = [
666
-		'transcoder' => false,
667
-		'methode' => 'GET',
668
-		'taille_max' => null,
669
-		'datas' => '',
670
-		'boundary' => '',
671
-		'refuser_gz' => false,
672
-		'if_modified_since' => '',
673
-		'uri_referer' => '',
674
-		'file' => '',
675
-		'follow_location' => 10,
676
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
677
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
678
-	];
679
-	$options = array_merge($default, $options);
680
-
681
-	// cas ou il n'est pas possible de cacher
682
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
683
-		return recuperer_url($url, $options);
684
-	}
685
-
686
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
687
-	static $errors = [];
688
-	if (isset($errors[$url])) {
689
-		return $errors[$url];
690
-	}
691
-
692
-	$sig = $options;
693
-	unset($sig['if_modified_since']);
694
-	unset($sig['delai_cache']);
695
-	$sig['url'] = $url;
696
-
697
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
698
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
699
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
700
-	$cache = "$sub$cache";
701
-
702
-	$res = false;
703
-	$is_cached = file_exists($cache);
704
-	if (
705
-		$is_cached
706
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
707
-	) {
708
-		lire_fichier($cache, $res);
709
-		if ($res = unserialize($res)) {
710
-			// mettre le last_modified et le status=304 ?
711
-		}
712
-	}
713
-	if (!$res) {
714
-		$res = recuperer_url($url, $options);
715
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
716
-		if (!$res) {
717
-			if ($is_cached) {
718
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
719
-				lire_fichier($cache, $res);
720
-				$res = unserialize($res);
721
-			}
722
-
723
-			return $errors[$url] = $res;
724
-		}
725
-		ecrire_fichier($cache, serialize($res));
726
-	}
727
-
728
-	return $res;
662
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
663
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
664
+    }
665
+    $default = [
666
+        'transcoder' => false,
667
+        'methode' => 'GET',
668
+        'taille_max' => null,
669
+        'datas' => '',
670
+        'boundary' => '',
671
+        'refuser_gz' => false,
672
+        'if_modified_since' => '',
673
+        'uri_referer' => '',
674
+        'file' => '',
675
+        'follow_location' => 10,
676
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
677
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
678
+    ];
679
+    $options = array_merge($default, $options);
680
+
681
+    // cas ou il n'est pas possible de cacher
682
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
683
+        return recuperer_url($url, $options);
684
+    }
685
+
686
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
687
+    static $errors = [];
688
+    if (isset($errors[$url])) {
689
+        return $errors[$url];
690
+    }
691
+
692
+    $sig = $options;
693
+    unset($sig['if_modified_since']);
694
+    unset($sig['delai_cache']);
695
+    $sig['url'] = $url;
696
+
697
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
698
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
699
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
700
+    $cache = "$sub$cache";
701
+
702
+    $res = false;
703
+    $is_cached = file_exists($cache);
704
+    if (
705
+        $is_cached
706
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
707
+    ) {
708
+        lire_fichier($cache, $res);
709
+        if ($res = unserialize($res)) {
710
+            // mettre le last_modified et le status=304 ?
711
+        }
712
+    }
713
+    if (!$res) {
714
+        $res = recuperer_url($url, $options);
715
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
716
+        if (!$res) {
717
+            if ($is_cached) {
718
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
719
+                lire_fichier($cache, $res);
720
+                $res = unserialize($res);
721
+            }
722
+
723
+            return $errors[$url] = $res;
724
+        }
725
+        ecrire_fichier($cache, serialize($res));
726
+    }
727
+
728
+    return $res;
729 729
 }
730 730
 
731 731
 /**
@@ -743,42 +743,42 @@  discard block
 block discarded – undo
743 743
  *   string contenu de la resource
744 744
  */
745 745
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
746
-	$tmpfile = null;
747
-	$taille = 0;
748
-	$result = '';
749
-	$fp = false;
750
-	if ($fichier) {
751
-		include_spip('inc/acces');
752
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
753
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754
-		if (!$fp and file_exists($fichier)) {
755
-			return filesize($fichier);
756
-		}
757
-		if (!$fp) {
758
-			return false;
759
-		}
760
-		$result = 0; // on renvoie la taille du fichier
761
-	}
762
-	while (!feof($handle) and $taille < $taille_max) {
763
-		$res = fread($handle, 16384);
764
-		$taille += strlen($res);
765
-		if ($fp) {
766
-			fwrite($fp, $res);
767
-			$result = $taille;
768
-		} else {
769
-			$result .= $res;
770
-		}
771
-	}
772
-	if ($fp) {
773
-		spip_fclose_unlock($fp);
774
-		spip_unlink($fichier);
775
-		@rename($tmpfile, $fichier);
776
-		if (!file_exists($fichier)) {
777
-			return false;
778
-		}
779
-	}
780
-
781
-	return $result;
746
+    $tmpfile = null;
747
+    $taille = 0;
748
+    $result = '';
749
+    $fp = false;
750
+    if ($fichier) {
751
+        include_spip('inc/acces');
752
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
753
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754
+        if (!$fp and file_exists($fichier)) {
755
+            return filesize($fichier);
756
+        }
757
+        if (!$fp) {
758
+            return false;
759
+        }
760
+        $result = 0; // on renvoie la taille du fichier
761
+    }
762
+    while (!feof($handle) and $taille < $taille_max) {
763
+        $res = fread($handle, 16384);
764
+        $taille += strlen($res);
765
+        if ($fp) {
766
+            fwrite($fp, $res);
767
+            $result = $taille;
768
+        } else {
769
+            $result .= $res;
770
+        }
771
+    }
772
+    if ($fp) {
773
+        spip_fclose_unlock($fp);
774
+        spip_unlink($fichier);
775
+        @rename($tmpfile, $fichier);
776
+        if (!file_exists($fichier)) {
777
+            return false;
778
+        }
779
+    }
780
+
781
+    return $result;
782 782
 }
783 783
 
784 784
 /**
@@ -800,35 +800,35 @@  discard block
 block discarded – undo
800 800
  *   string location
801 801
  */
802 802
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
803
-	$result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
804
-
805
-	$s = @trim(fgets($handle, 16384));
806
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
807
-		return false;
808
-	}
809
-	$result['status'] = intval($r[1]);
810
-	while ($s = trim(fgets($handle, 16384))) {
811
-		$result['headers'][] = $s . "\n";
812
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813
-		[, $d, $v] = $r;
814
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
815
-			$result['location'] = $v;
816
-		} elseif ($d == 'Last-Modified') {
817
-			$result['last_modified'] = strtotime($v);
818
-		}
819
-	}
820
-	if (
821
-		$if_modified_since
822
-		and $result['last_modified']
823
-		and $if_modified_since > $result['last_modified']
824
-		and $result['status'] == 200
825
-	) {
826
-		$result['status'] = 304;
827
-	}
828
-
829
-	$result['headers'] = implode('', $result['headers']);
830
-
831
-	return $result;
803
+    $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
804
+
805
+    $s = @trim(fgets($handle, 16384));
806
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
807
+        return false;
808
+    }
809
+    $result['status'] = intval($r[1]);
810
+    while ($s = trim(fgets($handle, 16384))) {
811
+        $result['headers'][] = $s . "\n";
812
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813
+        [, $d, $v] = $r;
814
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
815
+            $result['location'] = $v;
816
+        } elseif ($d == 'Last-Modified') {
817
+            $result['last_modified'] = strtotime($v);
818
+        }
819
+    }
820
+    if (
821
+        $if_modified_since
822
+        and $result['last_modified']
823
+        and $if_modified_since > $result['last_modified']
824
+        and $result['status'] == 200
825
+    ) {
826
+        $result['status'] = 304;
827
+    }
828
+
829
+    $result['headers'] = implode('', $result['headers']);
830
+
831
+    return $result;
832 832
 }
833 833
 
834 834
 /**
@@ -850,22 +850,22 @@  discard block
 block discarded – undo
850 850
  *     Nom du fichier pour copie locale
851 851
  **/
852 852
 function nom_fichier_copie_locale($source, $extension) {
853
-	include_spip('inc/documents');
853
+    include_spip('inc/documents');
854 854
 
855
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
856
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
855
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
856
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
857 857
 
858
-	// on se place tout le temps comme si on etait a la racine
859
-	if (_DIR_RACINE) {
860
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
861
-	}
858
+    // on se place tout le temps comme si on etait a la racine
859
+    if (_DIR_RACINE) {
860
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
861
+    }
862 862
 
863
-	$m = md5($source);
863
+    $m = md5($source);
864 864
 
865
-	return $d
866
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
867
-	. substr($m, 0, 4)
868
-	. ".$extension";
865
+    return $d
866
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
867
+    . substr($m, 0, 4)
868
+    . ".$extension";
869 869
 }
870 870
 
871 871
 /**
@@ -884,72 +884,72 @@  discard block
 block discarded – undo
884 884
  *      - null: Copie locale impossible
885 885
  **/
886 886
 function fichier_copie_locale($source) {
887
-	// Si c'est deja local pas de souci
888
-	if (!tester_url_absolue($source)) {
889
-		if (_DIR_RACINE) {
890
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
891
-		}
892
-
893
-		return $source;
894
-	}
895
-
896
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
897
-	// a deja ete copie en local avec cette extension
898
-	// dans ce cas elle est fiable, pas la peine de requeter en base
899
-	$path_parts = pathinfo($source);
900
-	if (!isset($path_parts['extension'])) {
901
-		$path_parts['extension'] = '';
902
-	}
903
-	$ext = $path_parts ? $path_parts['extension'] : '';
904
-	if (
905
-		$ext
906
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907
-		and $f = nom_fichier_copie_locale($source, $ext)
908
-		and file_exists(_DIR_RACINE . $f)
909
-	) {
910
-		return $f;
911
-	}
912
-
913
-
914
-	// Si c'est deja dans la table des documents,
915
-	// ramener le nom de sa copie potentielle
916
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
917
-
918
-	if ($ext) {
919
-		return nom_fichier_copie_locale($source, $ext);
920
-	}
921
-
922
-	// voir si l'extension indiquee dans le nom du fichier est ok
923
-	// et si il n'aurait pas deja ete rapatrie
924
-
925
-	$ext = $path_parts ? $path_parts['extension'] : '';
926
-
927
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
928
-		$f = nom_fichier_copie_locale($source, $ext);
929
-		if (file_exists(_DIR_RACINE . $f)) {
930
-			return $f;
931
-		}
932
-	}
933
-
934
-	// Ping  pour voir si son extension est connue et autorisee
935
-	// avec mise en cache du resultat du ping
936
-
937
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
938
-	if (
939
-		!@file_exists($cache)
940
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
941
-		or _request('var_mode') === 'recalcul'
942
-	) {
943
-		$path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]);
944
-		ecrire_fichier($cache, serialize($path_parts));
945
-	}
946
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
948
-		return nom_fichier_copie_locale($source, $ext);
949
-	}
950
-
951
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
952
-	return null;
887
+    // Si c'est deja local pas de souci
888
+    if (!tester_url_absolue($source)) {
889
+        if (_DIR_RACINE) {
890
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
891
+        }
892
+
893
+        return $source;
894
+    }
895
+
896
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
897
+    // a deja ete copie en local avec cette extension
898
+    // dans ce cas elle est fiable, pas la peine de requeter en base
899
+    $path_parts = pathinfo($source);
900
+    if (!isset($path_parts['extension'])) {
901
+        $path_parts['extension'] = '';
902
+    }
903
+    $ext = $path_parts ? $path_parts['extension'] : '';
904
+    if (
905
+        $ext
906
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907
+        and $f = nom_fichier_copie_locale($source, $ext)
908
+        and file_exists(_DIR_RACINE . $f)
909
+    ) {
910
+        return $f;
911
+    }
912
+
913
+
914
+    // Si c'est deja dans la table des documents,
915
+    // ramener le nom de sa copie potentielle
916
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
917
+
918
+    if ($ext) {
919
+        return nom_fichier_copie_locale($source, $ext);
920
+    }
921
+
922
+    // voir si l'extension indiquee dans le nom du fichier est ok
923
+    // et si il n'aurait pas deja ete rapatrie
924
+
925
+    $ext = $path_parts ? $path_parts['extension'] : '';
926
+
927
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
928
+        $f = nom_fichier_copie_locale($source, $ext);
929
+        if (file_exists(_DIR_RACINE . $f)) {
930
+            return $f;
931
+        }
932
+    }
933
+
934
+    // Ping  pour voir si son extension est connue et autorisee
935
+    // avec mise en cache du resultat du ping
936
+
937
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
938
+    if (
939
+        !@file_exists($cache)
940
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
941
+        or _request('var_mode') === 'recalcul'
942
+    ) {
943
+        $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]);
944
+        ecrire_fichier($cache, serialize($path_parts));
945
+    }
946
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
948
+        return nom_fichier_copie_locale($source, $ext);
949
+    }
950
+
951
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
952
+    return null;
953 953
 }
954 954
 
955 955
 
@@ -978,110 +978,110 @@  discard block
 block discarded – undo
978 978
  **/
979 979
 function recuperer_infos_distantes($source, $options = []) {
980 980
 
981
-	// pas la peine de perdre son temps
982
-	if (!tester_url_absolue($source)) {
983
-		return false;
984
-	}
985
-
986
-	$taille_max = $options['taille_max'] ?? 0;
987
-	$charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
988
-	$callback_valider_url = $options['callback_valider_url'] ?? null;
989
-
990
-	# charger les alias des types mime
991
-	include_spip('base/typedoc');
992
-
993
-	$a = [];
994
-	$mime_type = '';
995
-	// On va directement charger le debut des images et des fichiers html,
996
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
997
-	// ca echoue l'utilisateur devra les entrer...
998
-	$reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
999
-	if (
1000
-		$callback_valider_url
1001
-		and is_callable($callback_valider_url)
1002
-		and !$callback_valider_url($reponse['url'])
1003
-	) {
1004
-		return false;
1005
-	}
1006
-	$headers = $reponse['headers'] ?? '';
1007
-	$a['body'] = $reponse['page'] ?? '';
1008
-	if ($headers) {
1009
-		if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1010
-			return false;
1011
-		}
1012
-
1013
-		$a['extension'] = $extension;
1014
-
1015
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1016
-			$a['taille'] = intval($regs[1]);
1017
-		}
1018
-	}
1019
-
1020
-	// Echec avec HEAD, on tente avec GET
1021
-	if (!$a and !$taille_max) {
1022
-		spip_log("tenter GET $source", 'distant');
1023
-		$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1024
-		$a = recuperer_infos_distantes($source, $options);
1025
-	}
1026
-
1027
-	// si on a rien trouve pas la peine d'insister
1028
-	if (!$a) {
1029
-		return false;
1030
-	}
1031
-
1032
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1033
-	// recharger le document en GET et recuperer des donnees supplementaires...
1034
-	include_spip('inc/filtres_images_lib_mini');
1035
-	if (
1036
-		strpos($mime_type, 'image/') === 0
1037
-		and $extension = _image_trouver_extension_depuis_mime($mime_type)
1038
-	) {
1039
-		if (
1040
-			$taille_max == 0
1041
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1042
-			and in_array($extension, formats_image_acceptables())
1043
-			and $charger_si_petite_image
1044
-		) {
1045
-			$options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1046
-			$a = recuperer_infos_distantes($source, $options);
1047
-		} else {
1048
-			if ($a['body']) {
1049
-				$a['extension'] = $extension;
1050
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1051
-				ecrire_fichier($a['fichier'], $a['body']);
1052
-				$size_image = @spip_getimagesize($a['fichier']);
1053
-				$a['largeur'] = intval($size_image[0]);
1054
-				$a['hauteur'] = intval($size_image[1]);
1055
-				$a['type_image'] = true;
1056
-			}
1057
-		}
1058
-	}
1059
-
1060
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1061
-	// ce sera mieux que 0x0
1062
-	// Flash is dead!
1063
-	if (
1064
-		$a and isset($a['extension']) and $a['extension'] == 'swf'
1065
-		and empty($a['largeur'])
1066
-	) {
1067
-		$a['largeur'] = 425;
1068
-		$a['hauteur'] = 350;
1069
-	}
1070
-
1071
-	if ($mime_type == 'text/html') {
1072
-		include_spip('inc/filtres');
1073
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1074
-		$page = $page['page'] ?? '';
1075
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1076
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1077
-		}
1078
-		if (!isset($a['taille']) or !$a['taille']) {
1079
-			$a['taille'] = strlen($page); # a peu pres
1080
-		}
1081
-	}
1082
-	$a['mime_type'] = $mime_type;
1083
-
1084
-	return $a;
981
+    // pas la peine de perdre son temps
982
+    if (!tester_url_absolue($source)) {
983
+        return false;
984
+    }
985
+
986
+    $taille_max = $options['taille_max'] ?? 0;
987
+    $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true);
988
+    $callback_valider_url = $options['callback_valider_url'] ?? null;
989
+
990
+    # charger les alias des types mime
991
+    include_spip('base/typedoc');
992
+
993
+    $a = [];
994
+    $mime_type = '';
995
+    // On va directement charger le debut des images et des fichiers html,
996
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
997
+    // ca echoue l'utilisateur devra les entrer...
998
+    $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]);
999
+    if (
1000
+        $callback_valider_url
1001
+        and is_callable($callback_valider_url)
1002
+        and !$callback_valider_url($reponse['url'])
1003
+    ) {
1004
+        return false;
1005
+    }
1006
+    $headers = $reponse['headers'] ?? '';
1007
+    $a['body'] = $reponse['page'] ?? '';
1008
+    if ($headers) {
1009
+        if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
1010
+            return false;
1011
+        }
1012
+
1013
+        $a['extension'] = $extension;
1014
+
1015
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1016
+            $a['taille'] = intval($regs[1]);
1017
+        }
1018
+    }
1019
+
1020
+    // Echec avec HEAD, on tente avec GET
1021
+    if (!$a and !$taille_max) {
1022
+        spip_log("tenter GET $source", 'distant');
1023
+        $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1024
+        $a = recuperer_infos_distantes($source, $options);
1025
+    }
1026
+
1027
+    // si on a rien trouve pas la peine d'insister
1028
+    if (!$a) {
1029
+        return false;
1030
+    }
1031
+
1032
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1033
+    // recharger le document en GET et recuperer des donnees supplementaires...
1034
+    include_spip('inc/filtres_images_lib_mini');
1035
+    if (
1036
+        strpos($mime_type, 'image/') === 0
1037
+        and $extension = _image_trouver_extension_depuis_mime($mime_type)
1038
+    ) {
1039
+        if (
1040
+            $taille_max == 0
1041
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1042
+            and in_array($extension, formats_image_acceptables())
1043
+            and $charger_si_petite_image
1044
+        ) {
1045
+            $options['taille_max'] = _INC_DISTANT_MAX_SIZE;
1046
+            $a = recuperer_infos_distantes($source, $options);
1047
+        } else {
1048
+            if ($a['body']) {
1049
+                $a['extension'] = $extension;
1050
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1051
+                ecrire_fichier($a['fichier'], $a['body']);
1052
+                $size_image = @spip_getimagesize($a['fichier']);
1053
+                $a['largeur'] = intval($size_image[0]);
1054
+                $a['hauteur'] = intval($size_image[1]);
1055
+                $a['type_image'] = true;
1056
+            }
1057
+        }
1058
+    }
1059
+
1060
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1061
+    // ce sera mieux que 0x0
1062
+    // Flash is dead!
1063
+    if (
1064
+        $a and isset($a['extension']) and $a['extension'] == 'swf'
1065
+        and empty($a['largeur'])
1066
+    ) {
1067
+        $a['largeur'] = 425;
1068
+        $a['hauteur'] = 350;
1069
+    }
1070
+
1071
+    if ($mime_type == 'text/html') {
1072
+        include_spip('inc/filtres');
1073
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1074
+        $page = $page['page'] ?? '';
1075
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1076
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1077
+        }
1078
+        if (!isset($a['taille']) or !$a['taille']) {
1079
+            $a['taille'] = strlen($page); # a peu pres
1080
+        }
1081
+    }
1082
+    $a['mime_type'] = $mime_type;
1083
+
1084
+    return $a;
1085 1085
 }
1086 1086
 
1087 1087
 /**
@@ -1090,70 +1090,70 @@  discard block
 block discarded – undo
1090 1090
  * @return false|mixed
1091 1091
  */
1092 1092
 function distant_trouver_extension_selon_headers($source, $headers) {
1093
-	if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1094
-		$mime_type = (trim($regs[1]));
1095
-	} else {
1096
-		$mime_type = '';
1097
-	} // inconnu
1098
-
1099
-	// Appliquer les alias
1100
-	while (isset($GLOBALS['mime_alias'][$mime_type])) {
1101
-		$mime_type = $GLOBALS['mime_alias'][$mime_type];
1102
-	}
1103
-
1104
-	// pour corriger_extension()
1105
-	include_spip('inc/documents');
1106
-
1107
-	// Si on a un mime-type insignifiant
1108
-	// text/plain,application/octet-stream ou vide
1109
-	// c'est peut-etre que le serveur ne sait pas
1110
-	// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1111
-	// ou le Content-Disposition: attachment; filename=...
1112
-	$t = null;
1113
-	if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1114
-		if (
1115
-			!$t
1116
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117
-		) {
1118
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1119
-		}
1120
-		if (
1121
-			!$t
1122
-			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124
-		) {
1125
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1126
-		}
1127
-	}
1128
-
1129
-	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130
-	if (!$t) {
1131
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1132
-	}
1133
-
1134
-	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1135
-	// On essaie de nouveau avec l'extension
1136
-	if (
1137
-		!$t
1138
-		and $mime_type != 'text/plain'
1139
-		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140
-	) {
1141
-		# eviter xxx.3 => 3gp (> SPIP 3)
1142
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1143
-	}
1144
-
1145
-	if ($t) {
1146
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1147
-		return $t['extension'];
1148
-	} else {
1149
-		# par defaut on retombe sur '.bin' si c'est autorise
1150
-		spip_log("mime-type $mime_type inconnu", 'distant');
1151
-		$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1152
-		if (!$t) {
1153
-			return false;
1154
-		}
1155
-		return $t['extension'];
1156
-	}
1093
+    if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1094
+        $mime_type = (trim($regs[1]));
1095
+    } else {
1096
+        $mime_type = '';
1097
+    } // inconnu
1098
+
1099
+    // Appliquer les alias
1100
+    while (isset($GLOBALS['mime_alias'][$mime_type])) {
1101
+        $mime_type = $GLOBALS['mime_alias'][$mime_type];
1102
+    }
1103
+
1104
+    // pour corriger_extension()
1105
+    include_spip('inc/documents');
1106
+
1107
+    // Si on a un mime-type insignifiant
1108
+    // text/plain,application/octet-stream ou vide
1109
+    // c'est peut-etre que le serveur ne sait pas
1110
+    // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1111
+    // ou le Content-Disposition: attachment; filename=...
1112
+    $t = null;
1113
+    if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1114
+        if (
1115
+            !$t
1116
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117
+        ) {
1118
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1119
+        }
1120
+        if (
1121
+            !$t
1122
+            and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124
+        ) {
1125
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1126
+        }
1127
+    }
1128
+
1129
+    // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130
+    if (!$t) {
1131
+        $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1132
+    }
1133
+
1134
+    // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1135
+    // On essaie de nouveau avec l'extension
1136
+    if (
1137
+        !$t
1138
+        and $mime_type != 'text/plain'
1139
+        and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140
+    ) {
1141
+        # eviter xxx.3 => 3gp (> SPIP 3)
1142
+        $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1143
+    }
1144
+
1145
+    if ($t) {
1146
+        spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1147
+        return $t['extension'];
1148
+    } else {
1149
+        # par defaut on retombe sur '.bin' si c'est autorise
1150
+        spip_log("mime-type $mime_type inconnu", 'distant');
1151
+        $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1152
+        if (!$t) {
1153
+            return false;
1154
+        }
1155
+        return $t['extension'];
1156
+    }
1157 1157
 }
1158 1158
 
1159 1159
 /**
@@ -1169,45 +1169,45 @@  discard block
 block discarded – undo
1169 1169
  */
1170 1170
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1171 1171
 
1172
-	$http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1173
-
1174
-	// rien a faire si pas de proxy :)
1175
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1176
-		return '';
1177
-	}
1178
-
1179
-	if (is_null($http_noproxy)) {
1180
-		$http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1181
-	}
1182
-	// si pas d'exception, on retourne le proxy
1183
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1184
-		return $http_proxy;
1185
-	}
1186
-
1187
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1188
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1189
-	$http_noproxy = str_replace("\n", ' ', $http_noproxy);
1190
-	$http_noproxy = str_replace("\r", ' ', $http_noproxy);
1191
-	$http_noproxy = " $http_noproxy ";
1192
-	$domain = $host;
1193
-	// si le domaine exact www.example.org est dans les exceptions
1194
-	if (strpos($http_noproxy, (string) " $domain ") !== false) {
1195
-		return '';
1196
-	}
1197
-
1198
-	while (strpos($domain, '.') !== false) {
1199
-		$domain = explode('.', $domain);
1200
-		array_shift($domain);
1201
-		$domain = implode('.', $domain);
1202
-
1203
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1204
-		if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1205
-			return '';
1206
-		}
1207
-	}
1208
-
1209
-	// ok c'est pas une exception
1210
-	return $http_proxy;
1172
+    $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1173
+
1174
+    // rien a faire si pas de proxy :)
1175
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1176
+        return '';
1177
+    }
1178
+
1179
+    if (is_null($http_noproxy)) {
1180
+        $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1181
+    }
1182
+    // si pas d'exception, on retourne le proxy
1183
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1184
+        return $http_proxy;
1185
+    }
1186
+
1187
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1188
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1189
+    $http_noproxy = str_replace("\n", ' ', $http_noproxy);
1190
+    $http_noproxy = str_replace("\r", ' ', $http_noproxy);
1191
+    $http_noproxy = " $http_noproxy ";
1192
+    $domain = $host;
1193
+    // si le domaine exact www.example.org est dans les exceptions
1194
+    if (strpos($http_noproxy, (string) " $domain ") !== false) {
1195
+        return '';
1196
+    }
1197
+
1198
+    while (strpos($domain, '.') !== false) {
1199
+        $domain = explode('.', $domain);
1200
+        array_shift($domain);
1201
+        $domain = implode('.', $domain);
1202
+
1203
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1204
+        if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1205
+            return '';
1206
+        }
1207
+    }
1208
+
1209
+    // ok c'est pas une exception
1210
+    return $http_proxy;
1211 1211
 }
1212 1212
 
1213 1213
 
@@ -1230,59 +1230,59 @@  discard block
 block discarded – undo
1230 1230
  * @return array
1231 1231
  */
1232 1232
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1233
-	$user = $via_proxy = $proxy_user = '';
1234
-	$fopen = false;
1235
-
1236
-	$t = @parse_url($url);
1237
-	$host = $t['host'];
1238
-	if ($t['scheme'] == 'http') {
1239
-		$scheme = 'http';
1240
-		$noproxy = '';
1241
-	} elseif ($t['scheme'] == 'https') {
1242
-		$scheme = 'ssl';
1243
-		$noproxy = 'ssl://';
1244
-		if (!isset($t['port']) || !($port = $t['port'])) {
1245
-			$t['port'] = 443;
1246
-		}
1247
-	} else {
1248
-		$scheme = $t['scheme'];
1249
-		$noproxy = $scheme . '://';
1250
-	}
1251
-	if (isset($t['user'])) {
1252
-		$user = [$t['user'], $t['pass']];
1253
-	}
1254
-
1255
-	if (!isset($t['port']) || !($port = $t['port'])) {
1256
-		$port = 80;
1257
-	}
1258
-	if (!isset($t['path']) || !($path = $t['path'])) {
1259
-		$path = '/';
1260
-	}
1261
-
1262
-	if (!empty($t['query'])) {
1263
-		$path .= '?' . $t['query'];
1264
-	}
1265
-
1266
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1267
-	if (!$f or !is_resource($f)) {
1268
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1269
-		// ce qui correspond a $f===110
1270
-		if (
1271
-			$f !== 110
1272
-			and !need_proxy($host)
1273
-			and !_request('tester_proxy')
1274
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1275
-		) {
1276
-			$f = @fopen($url, 'rb');
1277
-			spip_log("connexion vers $url par simple fopen", 'distant');
1278
-			$fopen = true;
1279
-		} else {
1280
-			// echec total
1281
-			$f = false;
1282
-		}
1283
-	}
1284
-
1285
-	return [$f, $fopen];
1233
+    $user = $via_proxy = $proxy_user = '';
1234
+    $fopen = false;
1235
+
1236
+    $t = @parse_url($url);
1237
+    $host = $t['host'];
1238
+    if ($t['scheme'] == 'http') {
1239
+        $scheme = 'http';
1240
+        $noproxy = '';
1241
+    } elseif ($t['scheme'] == 'https') {
1242
+        $scheme = 'ssl';
1243
+        $noproxy = 'ssl://';
1244
+        if (!isset($t['port']) || !($port = $t['port'])) {
1245
+            $t['port'] = 443;
1246
+        }
1247
+    } else {
1248
+        $scheme = $t['scheme'];
1249
+        $noproxy = $scheme . '://';
1250
+    }
1251
+    if (isset($t['user'])) {
1252
+        $user = [$t['user'], $t['pass']];
1253
+    }
1254
+
1255
+    if (!isset($t['port']) || !($port = $t['port'])) {
1256
+        $port = 80;
1257
+    }
1258
+    if (!isset($t['path']) || !($path = $t['path'])) {
1259
+        $path = '/';
1260
+    }
1261
+
1262
+    if (!empty($t['query'])) {
1263
+        $path .= '?' . $t['query'];
1264
+    }
1265
+
1266
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1267
+    if (!$f or !is_resource($f)) {
1268
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1269
+        // ce qui correspond a $f===110
1270
+        if (
1271
+            $f !== 110
1272
+            and !need_proxy($host)
1273
+            and !_request('tester_proxy')
1274
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1275
+        ) {
1276
+            $f = @fopen($url, 'rb');
1277
+            spip_log("connexion vers $url par simple fopen", 'distant');
1278
+            $fopen = true;
1279
+        } else {
1280
+            // echec total
1281
+            $f = false;
1282
+        }
1283
+    }
1284
+
1285
+    return [$f, $fopen];
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1317,124 +1317,124 @@  discard block
 block discarded – undo
1317 1317
  *   resource socket vers l'url demandee
1318 1318
  */
1319 1319
 function lance_requete(
1320
-	$method,
1321
-	$scheme,
1322
-	$user,
1323
-	$host,
1324
-	$path,
1325
-	$port,
1326
-	$noproxy,
1327
-	$refuse_gz = false,
1328
-	$referer = '',
1329
-	$datas = '',
1330
-	$vers = 'HTTP/1.0',
1331
-	$date = ''
1320
+    $method,
1321
+    $scheme,
1322
+    $user,
1323
+    $host,
1324
+    $path,
1325
+    $port,
1326
+    $noproxy,
1327
+    $refuse_gz = false,
1328
+    $referer = '',
1329
+    $datas = '',
1330
+    $vers = 'HTTP/1.0',
1331
+    $date = ''
1332 1332
 ) {
1333 1333
 
1334
-	$proxy_user = '';
1335
-	$http_proxy = need_proxy($host);
1336
-	if ($user) {
1337
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1338
-	}
1339
-
1340
-	$connect = '';
1341
-	if ($http_proxy) {
1342
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1343
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1344
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1345
-				. "Host: $path_host\r\n"
1346
-				. "Proxy-Connection: Keep-Alive\r\n";
1347
-		} else {
1348
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1349
-				. (!$user ? '' : "$user@")
1350
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1351
-		}
1352
-		$t2 = @parse_url($http_proxy);
1353
-		$first_host = $t2['host'];
1354
-		$first_port = ($t2['port'] ?? null) ?: 80;
1355
-		if ($t2['user'] ?? null) {
1356
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1357
-		}
1358
-	} else {
1359
-		$first_host = $noproxy . $host;
1360
-		$first_port = $port;
1361
-	}
1362
-
1363
-	if ($connect) {
1364
-		$streamContext = stream_context_create([
1365
-			'ssl' => [
1366
-				'verify_peer' => false,
1367
-				'allow_self_signed' => true,
1368
-				'SNI_enabled' => true,
1369
-				'peer_name' => $host,
1370
-			]
1371
-		]);
1372
-		$f = @stream_socket_client(
1373
-			"tcp://$first_host:$first_port",
1374
-			$errno,
1375
-			$errstr,
1376
-			_INC_DISTANT_CONNECT_TIMEOUT,
1377
-			STREAM_CLIENT_CONNECT,
1378
-			$streamContext
1379
-		);
1380
-		spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381
-		if (!$f) {
1382
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1383
-			return $errno;
1384
-		}
1385
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1386
-
1387
-		fputs($f, $connect);
1388
-		fputs($f, "\r\n");
1389
-		$res = fread($f, 1024);
1390
-		if (
1391
-			!$res
1392
-			or !count($res = explode(' ', $res))
1393
-			or $res[1] !== '200'
1394
-		) {
1395
-			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1396
-			fclose($f);
1397
-
1398
-			return false;
1399
-		}
1400
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1401
-		stream_set_blocking($f, true);
1402
-		// envoyer le handshake
1403
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1404
-		spip_log("OK CONNECT sur $first_host:$first_port", 'connect');
1405
-	} else {
1406
-		$ntry = 3;
1407
-		do {
1408
-			$f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1409
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410
-		spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411
-		if (!$f) {
1412
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1413
-
1414
-			return $errno;
1415
-		}
1416
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1417
-	}
1418
-
1419
-	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1420
-
1421
-	$host_port = $host;
1422
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1423
-		$host_port .= ":$port";
1424
-	}
1425
-	$req = "$method $path $vers\r\n"
1426
-		. "Host: $host_port\r\n"
1427
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1429
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1430
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1432
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1334
+    $proxy_user = '';
1335
+    $http_proxy = need_proxy($host);
1336
+    if ($user) {
1337
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1338
+    }
1339
+
1340
+    $connect = '';
1341
+    if ($http_proxy) {
1342
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1343
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1344
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1345
+                . "Host: $path_host\r\n"
1346
+                . "Proxy-Connection: Keep-Alive\r\n";
1347
+        } else {
1348
+            $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1349
+                . (!$user ? '' : "$user@")
1350
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1351
+        }
1352
+        $t2 = @parse_url($http_proxy);
1353
+        $first_host = $t2['host'];
1354
+        $first_port = ($t2['port'] ?? null) ?: 80;
1355
+        if ($t2['user'] ?? null) {
1356
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1357
+        }
1358
+    } else {
1359
+        $first_host = $noproxy . $host;
1360
+        $first_port = $port;
1361
+    }
1362
+
1363
+    if ($connect) {
1364
+        $streamContext = stream_context_create([
1365
+            'ssl' => [
1366
+                'verify_peer' => false,
1367
+                'allow_self_signed' => true,
1368
+                'SNI_enabled' => true,
1369
+                'peer_name' => $host,
1370
+            ]
1371
+        ]);
1372
+        $f = @stream_socket_client(
1373
+            "tcp://$first_host:$first_port",
1374
+            $errno,
1375
+            $errstr,
1376
+            _INC_DISTANT_CONNECT_TIMEOUT,
1377
+            STREAM_CLIENT_CONNECT,
1378
+            $streamContext
1379
+        );
1380
+        spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381
+        if (!$f) {
1382
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1383
+            return $errno;
1384
+        }
1385
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1386
+
1387
+        fputs($f, $connect);
1388
+        fputs($f, "\r\n");
1389
+        $res = fread($f, 1024);
1390
+        if (
1391
+            !$res
1392
+            or !count($res = explode(' ', $res))
1393
+            or $res[1] !== '200'
1394
+        ) {
1395
+            spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1396
+            fclose($f);
1397
+
1398
+            return false;
1399
+        }
1400
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1401
+        stream_set_blocking($f, true);
1402
+        // envoyer le handshake
1403
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1404
+        spip_log("OK CONNECT sur $first_host:$first_port", 'connect');
1405
+    } else {
1406
+        $ntry = 3;
1407
+        do {
1408
+            $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1409
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410
+        spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411
+        if (!$f) {
1412
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1413
+
1414
+            return $errno;
1415
+        }
1416
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1417
+    }
1418
+
1419
+    $site = $GLOBALS['meta']['adresse_site'] ?? '';
1420
+
1421
+    $host_port = $host;
1422
+    if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1423
+        $host_port .= ":$port";
1424
+    }
1425
+    $req = "$method $path $vers\r\n"
1426
+        . "Host: $host_port\r\n"
1427
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1429
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1430
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1432
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1434 1434
 
1435 1435
 #	spip_log("Requete\n$req", 'distant');
1436
-	fputs($f, $req);
1437
-	fputs($f, $datas ?: "\r\n");
1436
+    fputs($f, $req);
1437
+    fputs($f, $datas ?: "\r\n");
1438 1438
 
1439
-	return $f;
1439
+    return $f;
1440 1440
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
28 28
 }
29 29
 if (!defined('_INC_DISTANT_USER_AGENT')) {
30
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
31 31
 }
32 32
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
33 33
 	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
37 37
 }
38 38
 
39
-define('_REGEXP_COPIE_LOCALE', ',' 	.
39
+define('_REGEXP_COPIE_LOCALE', ','.
40 40
 	preg_replace(
41 41
 		'@^https?:@',
42 42
 		'https?:',
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
 	// si c'est la protection de soi-meme, retourner le path
75 75
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
76
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
76
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
77 77
 
78 78
 		return @file_exists($source) ? $source : false;
79 79
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		return false;
94 94
 	}
95 95
 
96
-	$localrac = _DIR_RACINE . $local;
96
+	$localrac = _DIR_RACINE.$local;
97 97
 	$t = ($mode === 'force') ? false : @file_exists($localrac);
98 98
 
99 99
 	// test d'existence du fichier
@@ -113,18 +113,18 @@  discard block
 block discarded – undo
113 113
 		if (!$taille_max) {
114 114
 			$taille_max = _COPIE_LOCALE_MAX_SIZE;
115 115
 		}
116
-		$localrac_tmp = $localrac . '.tmp';
116
+		$localrac_tmp = $localrac.'.tmp';
117 117
 		$res = recuperer_url(
118 118
 			$source,
119 119
 			['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
120 120
 		);
121 121
 
122 122
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
123
-			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
123
+			spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE);
124 124
 			@unlink($localrac_tmp);
125 125
 		}
126 126
 		else {
127
-			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
127
+			spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille ".$res['length'].' status '.$res['status'], 'distant');
128 128
 		}
129 129
 		if (!$res or !$res['length']) {
130 130
 			// si $t c'est sans doute juste un not-modified-since
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			and is_callable($callback_valider_url)
138 138
 			and !$callback_valider_url($res['url'])
139 139
 		) {
140
-			spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE);
140
+			spip_log('copie_locale : url finale '.$res['url']." non valide, on refuse le fichier $localrac_tmp", 'distant'._LOG_INFO_IMPORTANTE);
141 141
 			@unlink($localrac_tmp);
142 142
 			return $t ? $local : false;
143 143
 		}
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
 	if (!$is_known_host) {
230 230
 		$host = trim($parsed_url['host'], '.');
231
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
231
+		if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) {
232 232
 			$ip = gethostbyname($host);
233 233
 			if ($ip === $host) {
234 234
 				// Error condition for gethostbyname()
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			}
250 250
 		}
251 251
 		if ($ip) {
252
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
252
+			if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
253 253
 				return false;
254 254
 			}
255 255
 		}
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	}
261 261
 
262 262
 	$port = $parsed_url['port'];
263
-	if ($port === 80  or $port === 443  or $port === 8080) {
263
+	if ($port === 80 or $port === 443 or $port === 8080) {
264 264
 		return $url;
265 265
 	}
266 266
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 				}
331 331
 			}
332 332
 			if ($taille > 500) {
333
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
333
+				$boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8);
334 334
 			}
335 335
 		}
336 336
 
@@ -358,16 +358,16 @@  discard block
 block discarded – undo
358 358
 			}
359 359
 		} else {
360 360
 			// fabrique une chaine HTTP simple pour un POST
361
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
361
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
362 362
 			$chaine = [];
363 363
 			if (is_array($donnees)) {
364 364
 				foreach ($donnees as $cle => $valeur) {
365 365
 					if (is_array($valeur)) {
366 366
 						foreach ($valeur as $val2) {
367
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
367
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
368 368
 						}
369 369
 					} else {
370
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
370
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
371 371
 					}
372 372
 				}
373 373
 				$chaine = implode('&', $chaine);
@@ -468,13 +468,13 @@  discard block
 block discarded – undo
468 468
 		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
469 469
 	}
470 470
 
471
-	spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
471
+	spip_log('recuperer_url '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
472 472
 
473 473
 	// Ajout des en-têtes spécifiques si besoin
474 474
 	$formatted_data = '';
475 475
 	if (!empty($options['headers'])) {
476 476
 		foreach ($options['headers'] as $champ => $valeur) {
477
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
477
+			$formatted_data .= $champ.': '.$valeur."\r\n";
478 478
 		}
479 479
 	}
480 480
 
@@ -482,9 +482,9 @@  discard block
 block discarded – undo
482 482
 		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
483 483
 		$head .= $formatted_data;
484 484
 		if (stripos($head, 'Content-Length:') === false) {
485
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
485
+			$head .= 'Content-Length: '.strlen($postdata)."\r\n";
486 486
 		}
487
-		$formatted_data = $head . "\r\n" . $postdata;
487
+		$formatted_data = $head."\r\n".$postdata;
488 488
 		if (
489 489
 			strlen($postdata)
490 490
 			and !$methode_demandee
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
499 499
 	$url = preg_replace(',^feed://,i', 'http://', $url);
500 500
 	if (!tester_url_absolue($url)) {
501
-		$url = 'http://' . $url;
501
+		$url = 'http://'.$url;
502 502
 	} elseif (strncmp($url, '//', 2) == 0) {
503
-		$url = 'http:' . $url;
503
+		$url = 'http:'.$url;
504 504
 	}
505 505
 
506 506
 	$url = url_to_ascii($url);
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 		$options['if_modified_since']
530 530
 	);
531 531
 	if (!$handle) {
532
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
532
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
533 533
 
534 534
 		return false;
535 535
 	}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 					'status' => 200,
560 560
 				];
561 561
 			} else {
562
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
562
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
563 563
 				return false;
564 564
 			}
565 565
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 					$options['datas'] = '';
576 576
 				}
577 577
 			}
578
-			spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG);
578
+			spip_log('recuperer_url recommence '.$options['methode']." sur $url", 'distant'._LOG_DEBUG);
579 579
 
580 580
 			return recuperer_url($url, $options);
581 581
 		} elseif ($res['status'] !== 200) {
582
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
582
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
583 583
 		}
584 584
 		$result['status'] = $res['status'];
585 585
 		if (isset($res['headers'])) {
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
 
596 596
 	// on ne veut que les entetes
597 597
 	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
598
-		spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
598
+		spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG);
599 599
 		return $result;
600 600
 	}
601 601
 
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
 	$gz = false;
607 607
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
608
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
608
+		$gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz');
609 609
 	}
610 610
 
611 611
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 
642 642
 	$trace = json_decode(json_encode($result), true);
643 643
 	$trace['page'] = '...';
644
-	spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
644
+	spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG);
645 645
 
646 646
 	return $result;
647 647
 }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	$sig['url'] = $url;
696 696
 
697 697
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
698
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
698
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
699 699
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
700 700
 	$cache = "$sub$cache";
701 701
 
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	$fp = false;
750 750
 	if ($fichier) {
751 751
 		include_spip('inc/acces');
752
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
752
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
753 753
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
754 754
 		if (!$fp and file_exists($fichier)) {
755 755
 			return filesize($fichier);
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	}
809 809
 	$result['status'] = intval($r[1]);
810 810
 	while ($s = trim(fgets($handle, 16384))) {
811
-		$result['headers'][] = $s . "\n";
811
+		$result['headers'][] = $s."\n";
812 812
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
813 813
 		[, $d, $v] = $r;
814 814
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -857,13 +857,13 @@  discard block
 block discarded – undo
857 857
 
858 858
 	// on se place tout le temps comme si on etait a la racine
859 859
 	if (_DIR_RACINE) {
860
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
860
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
861 861
 	}
862 862
 
863 863
 	$m = md5($source);
864 864
 
865 865
 	return $d
866
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
866
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
867 867
 	. substr($m, 0, 4)
868 868
 	. ".$extension";
869 869
 }
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	// Si c'est deja local pas de souci
888 888
 	if (!tester_url_absolue($source)) {
889 889
 		if (_DIR_RACINE) {
890
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
890
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
891 891
 		}
892 892
 
893 893
 		return $source;
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
 		$ext
906 906
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
907 907
 		and $f = nom_fichier_copie_locale($source, $ext)
908
-		and file_exists(_DIR_RACINE . $f)
908
+		and file_exists(_DIR_RACINE.$f)
909 909
 	) {
910 910
 		return $f;
911 911
 	}
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
 
914 914
 	// Si c'est deja dans la table des documents,
915 915
 	// ramener le nom de sa copie potentielle
916
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
916
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
917 917
 
918 918
 	if ($ext) {
919 919
 		return nom_fichier_copie_locale($source, $ext);
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 
925 925
 	$ext = $path_parts ? $path_parts['extension'] : '';
926 926
 
927
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
927
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
928 928
 		$f = nom_fichier_copie_locale($source, $ext);
929
-		if (file_exists(_DIR_RACINE . $f)) {
929
+		if (file_exists(_DIR_RACINE.$f)) {
930 930
 			return $f;
931 931
 		}
932 932
 	}
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	// Ping  pour voir si son extension est connue et autorisee
935 935
 	// avec mise en cache du resultat du ping
936 936
 
937
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
937
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
938 938
 	if (
939 939
 		!@file_exists($cache)
940 940
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
@@ -944,11 +944,11 @@  discard block
 block discarded – undo
944 944
 		ecrire_fichier($cache, serialize($path_parts));
945 945
 	}
946 946
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
947
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
947
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
948 948
 		return nom_fichier_copie_locale($source, $ext);
949 949
 	}
950 950
 
951
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
951
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
952 952
 	return null;
953 953
 }
954 954
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 		} else {
1048 1048
 			if ($a['body']) {
1049 1049
 				$a['extension'] = $extension;
1050
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1050
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1051 1051
 				ecrire_fichier($a['fichier'], $a['body']);
1052 1052
 				$size_image = @spip_getimagesize($a['fichier']);
1053 1053
 				$a['largeur'] = intval($size_image[0]);
@@ -1115,20 +1115,20 @@  discard block
 block discarded – undo
1115 1115
 			!$t
1116 1116
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1117 1117
 		) {
1118
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1118
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1119 1119
 		}
1120 1120
 		if (
1121 1121
 			!$t
1122 1122
 			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1123 1123
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1124 1124
 		) {
1125
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1125
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1126 1126
 		}
1127 1127
 	}
1128 1128
 
1129 1129
 	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1130 1130
 	if (!$t) {
1131
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1131
+		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1132 1132
 	}
1133 1133
 
1134 1134
 	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1139,11 +1139,11 @@  discard block
 block discarded – undo
1139 1139
 		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1140 1140
 	) {
1141 1141
 		# eviter xxx.3 => 3gp (> SPIP 3)
1142
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1142
+		$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1143 1143
 	}
1144 1144
 
1145 1145
 	if ($t) {
1146
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1146
+		spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1147 1147
 		return $t['extension'];
1148 1148
 	} else {
1149 1149
 		# par defaut on retombe sur '.bin' si c'est autorise
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
 		}
1247 1247
 	} else {
1248 1248
 		$scheme = $t['scheme'];
1249
-		$noproxy = $scheme . '://';
1249
+		$noproxy = $scheme.'://';
1250 1250
 	}
1251 1251
 	if (isset($t['user'])) {
1252 1252
 		$user = [$t['user'], $t['pass']];
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 	}
1261 1261
 
1262 1262
 	if (!empty($t['query'])) {
1263
-		$path .= '?' . $t['query'];
1263
+		$path .= '?'.$t['query'];
1264 1264
 	}
1265 1265
 
1266 1266
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1334,29 +1334,29 @@  discard block
 block discarded – undo
1334 1334
 	$proxy_user = '';
1335 1335
 	$http_proxy = need_proxy($host);
1336 1336
 	if ($user) {
1337
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1337
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1338 1338
 	}
1339 1339
 
1340 1340
 	$connect = '';
1341 1341
 	if ($http_proxy) {
1342
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1343
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1344
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1342
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) {
1343
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1344
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1345 1345
 				. "Host: $path_host\r\n"
1346 1346
 				. "Proxy-Connection: Keep-Alive\r\n";
1347 1347
 		} else {
1348
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1348
+			$path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://")
1349 1349
 				. (!$user ? '' : "$user@")
1350
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1350
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1351 1351
 		}
1352 1352
 		$t2 = @parse_url($http_proxy);
1353 1353
 		$first_host = $t2['host'];
1354 1354
 		$first_port = ($t2['port'] ?? null) ?: 80;
1355 1355
 		if ($t2['user'] ?? null) {
1356
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1356
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1357 1357
 		}
1358 1358
 	} else {
1359
-		$first_host = $noproxy . $host;
1359
+		$first_host = $noproxy.$host;
1360 1360
 		$first_port = $port;
1361 1361
 	}
1362 1362
 
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
 		);
1380 1380
 		spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect');
1381 1381
 		if (!$f) {
1382
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1382
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1383 1383
 			return $errno;
1384 1384
 		}
1385 1385
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
 			or !count($res = explode(' ', $res))
1393 1393
 			or $res[1] !== '200'
1394 1394
 		) {
1395
-			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE);
1395
+			spip_log("Echec CONNECT sur $first_host:$first_port", 'connect'._LOG_INFO_IMPORTANTE);
1396 1396
 			fclose($f);
1397 1397
 
1398 1398
 			return false;
@@ -1409,7 +1409,7 @@  discard block
 block discarded – undo
1409 1409
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1410 1410
 		spip_log("Recuperer $path sur $first_host:$first_port par $f");
1411 1411
 		if (!$f) {
1412
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1412
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1413 1413
 
1414 1414
 			return $errno;
1415 1415
 		}
@@ -1419,16 +1419,16 @@  discard block
 block discarded – undo
1419 1419
 	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1420 1420
 
1421 1421
 	$host_port = $host;
1422
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1422
+	if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) {
1423 1423
 		$host_port .= ":$port";
1424 1424
 	}
1425 1425
 	$req = "$method $path $vers\r\n"
1426 1426
 		. "Host: $host_port\r\n"
1427
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1428
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1427
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1428
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1429 1429
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1430
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1431
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1430
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1431
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1432 1432
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1433 1433
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1434 1434
 
Please login to merge, or discard this patch.
ecrire/action/editer_rubrique.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			$id_rubrique,
151 151
 			[
152 152
 			'data' => $set,
153
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
153
+			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique').' '._T('info_numero_abbreviation').$id_rubrique]
154 154
 			],
155 155
 			$c
156 156
 		)
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 				)
255 255
 			) {
256 256
 				if ($s['statut'] != 'prepa') {
257
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
257
+					spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']);
258 258
 				}
259 259
 			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
260 260
 				$statut_ancien = $s['statut'];
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Rubriques\Edition
16 16
  */
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/rubriques');
@@ -37,34 +37,34 @@  discard block
 block discarded – undo
37 37
  */
38 38
 function action_editer_rubrique_dist($arg = null) {
39 39
 
40
-	if (is_null($arg)) {
41
-		$securiser_action = charger_fonction('securiser_action', 'inc');
42
-		$arg = $securiser_action();
43
-	}
44
-
45
-	if (!$id_rubrique = intval($arg)) {
46
-		if ($arg != 'oui') {
47
-			include_spip('inc/headers');
48
-			redirige_url_ecrire();
49
-		}
50
-		$id_rubrique = rubrique_inserer(_request('id_parent'));
51
-	}
52
-
53
-	$err = rubrique_modifier($id_rubrique);
54
-
55
-	if (_request('redirect')) {
56
-		$redirect = parametre_url(
57
-			urldecode(_request('redirect')),
58
-			'id_rubrique',
59
-			$id_rubrique,
60
-			'&'
61
-		);
62
-
63
-		include_spip('inc/headers');
64
-		redirige_par_entete($redirect);
65
-	}
66
-
67
-	return [$id_rubrique, $err];
40
+    if (is_null($arg)) {
41
+        $securiser_action = charger_fonction('securiser_action', 'inc');
42
+        $arg = $securiser_action();
43
+    }
44
+
45
+    if (!$id_rubrique = intval($arg)) {
46
+        if ($arg != 'oui') {
47
+            include_spip('inc/headers');
48
+            redirige_url_ecrire();
49
+        }
50
+        $id_rubrique = rubrique_inserer(_request('id_parent'));
51
+    }
52
+
53
+    $err = rubrique_modifier($id_rubrique);
54
+
55
+    if (_request('redirect')) {
56
+        $redirect = parametre_url(
57
+            urldecode(_request('redirect')),
58
+            'id_rubrique',
59
+            $id_rubrique,
60
+            '&'
61
+        );
62
+
63
+        include_spip('inc/headers');
64
+        redirige_par_entete($redirect);
65
+    }
66
+
67
+    return [$id_rubrique, $err];
68 68
 }
69 69
 
70 70
 
@@ -79,64 +79,64 @@  discard block
 block discarded – undo
79 79
  *     Identifiant de la rubrique crée
80 80
  */
81 81
 function rubrique_inserer($id_parent, $set = null) {
82
-	$champs = [
83
-		'titre' => _T('item_nouvelle_rubrique'),
84
-		'id_parent' => intval($id_parent),
85
-		'statut' => 'prepa'
86
-	];
87
-
88
-	if ($set) {
89
-		$champs = array_merge($champs, $set);
90
-	}
91
-
92
-	// Envoyer aux plugins
93
-	$champs = pipeline(
94
-		'pre_insertion',
95
-		[
96
-			'args' => [
97
-				'table' => 'spip_rubriques',
98
-			],
99
-			'data' => $champs
100
-		]
101
-	);
102
-
103
-	$id_rubrique = sql_insertq('spip_rubriques', $champs);
104
-	pipeline(
105
-		'post_insertion',
106
-		[
107
-			'args' => [
108
-				'table' => 'spip_rubriques',
109
-				'id_objet' => $id_rubrique
110
-			],
111
-			'data' => $champs
112
-		]
113
-	);
114
-	propager_les_secteurs();
115
-	calculer_langues_rubriques();
116
-
117
-	// Appeler une notification
118
-	if ($notifications = charger_fonction('notifications', 'inc')) {
119
-		$notifications(
120
-			'rubrique_inserer',
121
-			$id_rubrique,
122
-			[
123
-				'id_parent' => $id_parent,
124
-				'champs' => $champs,
125
-			]
126
-		);
127
-		$notifications(
128
-			'objet_inserer',
129
-			$id_rubrique,
130
-			[
131
-				'objet' => 'rubrique',
132
-				'id_objet' => $id_rubrique,
133
-				'id_parent' => $id_parent,
134
-				'champs' => $champs,
135
-			]
136
-		);
137
-	}
138
-
139
-	return $id_rubrique;
82
+    $champs = [
83
+        'titre' => _T('item_nouvelle_rubrique'),
84
+        'id_parent' => intval($id_parent),
85
+        'statut' => 'prepa'
86
+    ];
87
+
88
+    if ($set) {
89
+        $champs = array_merge($champs, $set);
90
+    }
91
+
92
+    // Envoyer aux plugins
93
+    $champs = pipeline(
94
+        'pre_insertion',
95
+        [
96
+            'args' => [
97
+                'table' => 'spip_rubriques',
98
+            ],
99
+            'data' => $champs
100
+        ]
101
+    );
102
+
103
+    $id_rubrique = sql_insertq('spip_rubriques', $champs);
104
+    pipeline(
105
+        'post_insertion',
106
+        [
107
+            'args' => [
108
+                'table' => 'spip_rubriques',
109
+                'id_objet' => $id_rubrique
110
+            ],
111
+            'data' => $champs
112
+        ]
113
+    );
114
+    propager_les_secteurs();
115
+    calculer_langues_rubriques();
116
+
117
+    // Appeler une notification
118
+    if ($notifications = charger_fonction('notifications', 'inc')) {
119
+        $notifications(
120
+            'rubrique_inserer',
121
+            $id_rubrique,
122
+            [
123
+                'id_parent' => $id_parent,
124
+                'champs' => $champs,
125
+            ]
126
+        );
127
+        $notifications(
128
+            'objet_inserer',
129
+            $id_rubrique,
130
+            [
131
+                'objet' => 'rubrique',
132
+                'id_objet' => $id_rubrique,
133
+                'id_parent' => $id_parent,
134
+                'champs' => $champs,
135
+            ]
136
+        );
137
+    }
138
+
139
+    return $id_rubrique;
140 140
 }
141 141
 
142 142
 /**
@@ -152,46 +152,46 @@  discard block
 block discarded – undo
152 152
  *     - chaîne : texte d'un message d'erreur
153 153
  */
154 154
 function rubrique_modifier($id_rubrique, $set = null) {
155
-	include_spip('inc/autoriser');
156
-	include_spip('inc/filtres');
157
-
158
-	include_spip('inc/modifier');
159
-	$c = collecter_requests(
160
-		// include list
161
-		objet_info('rubrique', 'champs_editables'),
162
-		// exclude list
163
-		['id_parent', 'confirme_deplace'],
164
-		// donnees eventuellement fournies
165
-		$set
166
-	);
167
-
168
-	if (
169
-		$err = objet_modifier_champs(
170
-			'rubrique',
171
-			$id_rubrique,
172
-			[
173
-			'data' => $set,
174
-			'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
175
-			],
176
-			$c
177
-		)
178
-	) {
179
-		return $err;
180
-	}
181
-
182
-	$c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
183
-	// Deplacer la rubrique
184
-	if (isset($c['id_parent'])) {
185
-		$err = rubrique_instituer($id_rubrique, $c);
186
-	}
187
-
188
-	// invalider les caches marques de cette rubrique
189
-	include_spip('inc/invalideur');
190
-	suivre_invalideur("id='rubrique/$id_rubrique'");
191
-	// et celui de menu_rubriques
192
-	effacer_meta('date_calcul_rubriques');
193
-
194
-	return $err;
155
+    include_spip('inc/autoriser');
156
+    include_spip('inc/filtres');
157
+
158
+    include_spip('inc/modifier');
159
+    $c = collecter_requests(
160
+        // include list
161
+        objet_info('rubrique', 'champs_editables'),
162
+        // exclude list
163
+        ['id_parent', 'confirme_deplace'],
164
+        // donnees eventuellement fournies
165
+        $set
166
+    );
167
+
168
+    if (
169
+        $err = objet_modifier_champs(
170
+            'rubrique',
171
+            $id_rubrique,
172
+            [
173
+            'data' => $set,
174
+            'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique]
175
+            ],
176
+            $c
177
+        )
178
+    ) {
179
+        return $err;
180
+    }
181
+
182
+    $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set);
183
+    // Deplacer la rubrique
184
+    if (isset($c['id_parent'])) {
185
+        $err = rubrique_instituer($id_rubrique, $c);
186
+    }
187
+
188
+    // invalider les caches marques de cette rubrique
189
+    include_spip('inc/invalideur');
190
+    suivre_invalideur("id='rubrique/$id_rubrique'");
191
+    // et celui de menu_rubriques
192
+    effacer_meta('date_calcul_rubriques');
193
+
194
+    return $err;
195 195
 }
196 196
 
197 197
 /**
@@ -214,29 +214,29 @@  discard block
 block discarded – undo
214 214
  *     false si la confirmation du déplacement n'est pas présente
215 215
  */
216 216
 function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) {
217
-	if (!sql_table_exists('spip_breves')) {
218
-		return true;
219
-	}
220
-
221
-	if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
222
-		return true;
223
-	}
224
-
225
-	if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
226
-		return false;
227
-	}
228
-
229
-	if (
230
-		$id_secteur = sql_getfetsel(
231
-			'id_secteur',
232
-			'spip_rubriques',
233
-			"id_rubrique=$id_parent"
234
-		)
235
-	) {
236
-		sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
237
-	}
238
-
239
-	return true;
217
+    if (!sql_table_exists('spip_breves')) {
218
+        return true;
219
+    }
220
+
221
+    if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) {
222
+        return true;
223
+    }
224
+
225
+    if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') {
226
+        return false;
227
+    }
228
+
229
+    if (
230
+        $id_secteur = sql_getfetsel(
231
+            'id_secteur',
232
+            'spip_rubriques',
233
+            "id_rubrique=$id_parent"
234
+        )
235
+    ) {
236
+        sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique");
237
+    }
238
+
239
+    return true;
240 240
 }
241 241
 
242 242
 
@@ -258,72 +258,72 @@  discard block
 block discarded – undo
258 258
  *     Chaîne : texte du message d'erreur
259 259
  */
260 260
 function rubrique_instituer($id_rubrique, $c) {
261
-	// traitement de la rubrique parente
262
-	// interdiction de deplacer vers ou a partir d'une rubrique
263
-	// qu'on n'administre pas.
264
-
265
-	if (null !== ($id_parent = $c['id_parent'])) {
266
-		$id_parent = intval($id_parent);
267
-		$filles = calcul_branche_in($id_rubrique);
268
-		if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
269
-			spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
270
-		} else {
271
-			$s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
272
-			$old_parent = $s['id_parent'];
273
-
274
-			if (
275
-				!($id_parent != $old_parent
276
-				and autoriser('publierdans', 'rubrique', $id_parent)
277
-				and autoriser('creerrubriquedans', 'rubrique', $id_parent)
278
-				and autoriser('publierdans', 'rubrique', $old_parent)
279
-				)
280
-			) {
281
-				if ($s['statut'] != 'prepa') {
282
-					spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
283
-				}
284
-			} elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
285
-				$statut_ancien = $s['statut'];
286
-				sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
287
-
288
-
289
-				propager_les_secteurs();
290
-
291
-				// Deplacement d'une rubrique publiee ==> chgt general de leur statut
292
-				if ($statut_ancien == 'publie') {
293
-					calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
294
-				}
295
-				// Creation ou deplacement d'une rubrique non publiee
296
-				// invalider le cache de leur menu
297
-				elseif (!$statut_ancien || $old_parent != $id_parent) {
298
-					effacer_meta('date_calcul_rubriques');
299
-				}
300
-
301
-				calculer_langues_rubriques();
302
-
303
-				// Appeler une notification
304
-				if ($notifications = charger_fonction('notifications', 'inc')) {
305
-					$notifications(
306
-						'rubrique_instituer',
307
-						$id_rubrique,
308
-						[
309
-							'statut_ancien' => $statut_ancien,
310
-							'id_parent_ancien' => $old_parent,
311
-						]
312
-					);
313
-					$notifications(
314
-						'objet_instituer',
315
-						$id_rubrique,
316
-						[
317
-							'objet' => 'rubrique',
318
-							'id_objet' => $id_rubrique,
319
-							'statut_ancien' => $statut_ancien,
320
-							'id_parent_ancien' => $old_parent,
321
-						]
322
-					);
323
-				}
324
-			}
325
-		}
326
-	}
327
-
328
-	return ''; // pas d'erreur
261
+    // traitement de la rubrique parente
262
+    // interdiction de deplacer vers ou a partir d'une rubrique
263
+    // qu'on n'administre pas.
264
+
265
+    if (null !== ($id_parent = $c['id_parent'])) {
266
+        $id_parent = intval($id_parent);
267
+        $filles = calcul_branche_in($id_rubrique);
268
+        if (strpos(",$id_parent,", (string) ",$filles,") !== false) {
269
+            spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent");
270
+        } else {
271
+            $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
272
+            $old_parent = $s['id_parent'];
273
+
274
+            if (
275
+                !($id_parent != $old_parent
276
+                and autoriser('publierdans', 'rubrique', $id_parent)
277
+                and autoriser('creerrubriquedans', 'rubrique', $id_parent)
278
+                and autoriser('publierdans', 'rubrique', $old_parent)
279
+                )
280
+            ) {
281
+                if ($s['statut'] != 'prepa') {
282
+                    spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']);
283
+                }
284
+            } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) {
285
+                $statut_ancien = $s['statut'];
286
+                sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique");
287
+
288
+
289
+                propager_les_secteurs();
290
+
291
+                // Deplacement d'une rubrique publiee ==> chgt general de leur statut
292
+                if ($statut_ancien == 'publie') {
293
+                    calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]);
294
+                }
295
+                // Creation ou deplacement d'une rubrique non publiee
296
+                // invalider le cache de leur menu
297
+                elseif (!$statut_ancien || $old_parent != $id_parent) {
298
+                    effacer_meta('date_calcul_rubriques');
299
+                }
300
+
301
+                calculer_langues_rubriques();
302
+
303
+                // Appeler une notification
304
+                if ($notifications = charger_fonction('notifications', 'inc')) {
305
+                    $notifications(
306
+                        'rubrique_instituer',
307
+                        $id_rubrique,
308
+                        [
309
+                            'statut_ancien' => $statut_ancien,
310
+                            'id_parent_ancien' => $old_parent,
311
+                        ]
312
+                    );
313
+                    $notifications(
314
+                        'objet_instituer',
315
+                        $id_rubrique,
316
+                        [
317
+                            'objet' => 'rubrique',
318
+                            'id_objet' => $id_rubrique,
319
+                            'statut_ancien' => $statut_ancien,
320
+                            'id_parent_ancien' => $old_parent,
321
+                        ]
322
+                    );
323
+                }
324
+            }
325
+        }
326
+    }
327
+
328
+    return ''; // pas d'erreur
329 329
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 function extraire_date($texte): string {
40 40
 	// format = 2001-08
41 41
 	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
+		return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01';
43 43
 	}
44 44
 	return '';
45 45
 }
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 		}
71 71
 		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72 72
 			$regs = array_pad($regs, 4, null); // eviter notice php
73
-			$date = $regs[1] . '-00-00' . $regs[3];
73
+			$date = $regs[1].'-00-00'.$regs[3];
74 74
 		} else {
75 75
 			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76 76
 				$regs = array_pad($regs, 4, null); // eviter notice php
77
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
77
+				$date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3];
78 78
 			} else {
79 79
 				$date = date('Y-m-d H:i:s', strtotime($date));
80 80
 			}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	$letexte ??= '';
102 102
 	if (
103 103
 		!$verif_format_date
104
-		or (in_array(strlen($letexte), [10,19]) and
104
+		or (in_array(strlen($letexte), [10, 19]) and
105 105
 			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106 106
 	) {
107 107
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
@@ -388,17 +388,17 @@  discard block
 block discarded – undo
388 388
 	if ($decal > 3600 * 24 * 30) {
389 389
 		$mois = floor($decal / (3600 * 24 * 30));
390 390
 		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
391
+			$delai = "$mois "._T('date_un_mois');
392 392
 		} else {
393
-			$delai = "$mois " . _T('date_mois');
393
+			$delai = "$mois "._T('date_mois');
394 394
 		}
395 395
 	} else {
396 396
 		if ($decal > 3600 * 24 * 7) {
397 397
 			$semaines = floor($decal / (3600 * 24 * 7));
398 398
 			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
399
+				$delai = "$semaines "._T('date_une_semaine');
400 400
 			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
401
+				$delai = "$semaines "._T('date_semaines');
402 402
 			}
403 403
 		} else {
404 404
 			if ($decal > 3600 * 24) {
@@ -406,30 +406,30 @@  discard block
 block discarded – undo
406 406
 				if ($jours < 2) {
407 407
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408 408
 				} else {
409
-					$delai = "$jours " . _T('date_jours');
409
+					$delai = "$jours "._T('date_jours');
410 410
 				}
411 411
 			} else {
412 412
 				if ($decal >= 3600) {
413 413
 					$heures = floor($decal / 3600);
414 414
 					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
415
+						$delai = "$heures "._T('date_une_heure');
416 416
 					} else {
417
-						$delai = "$heures " . _T('date_heures');
417
+						$delai = "$heures "._T('date_heures');
418 418
 					}
419 419
 				} else {
420 420
 					if ($decal >= 60) {
421 421
 						$minutes = floor($decal / 60);
422 422
 						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
423
+							$delai = "$minutes "._T('date_une_minute');
424 424
 						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
425
+							$delai = "$minutes "._T('date_minutes');
426 426
 						}
427 427
 					} else {
428 428
 						$secondes = ceil($decal);
429 429
 						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
430
+							$delai = "$secondes "._T('date_une_seconde');
431 431
 						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
432
+							$delai = "$secondes "._T('date_secondes');
433 433
 						}
434 434
 					}
435 435
 				}
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		$njour = 0;
523 523
 	} else {
524 524
 		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
525
+		if ($jourth = _T('date_jnum'.$jour)) {
526 526
 			$jour = $jourth;
527 527
 		}
528 528
 	}
@@ -530,10 +530,10 @@  discard block
 block discarded – undo
530 530
 	$mois = intval($mois);
531 531
 	if ($mois > 0 and $mois < 13) {
532 532
 		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
533
+		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : '');
534
+		$nommois = _T('date_mois_'.$mois.$param);
535 535
 		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
536
+			$jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]);
537 537
 		} else {
538 538
 			$jourmois = $nommois;
539 539
 		}
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 	}
544 544
 
545 545
 	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
546
+		$annee = -$annee.' '._T('date_avant_jc');
547 547
 		$avjc = true;
548 548
 	} else {
549 549
 		$avjc = false;
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 				}
570 570
 			}
571 571
 			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
572
+				return $saison ? _T('date_saison_'.$saison) : '';
573 573
 			} else {
574 574
 				return $saison ? trim(_T(
575 575
 					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
576
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
577 577
 				)) : '';
578 578
 			}
579 579
 
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 			}
651 651
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652 652
 			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
653
+			$param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : '');
654 654
 
655
-			return _T('date_jour_' . $nom . $param);
655
+			return _T('date_jour_'.$nom.$param);
656 656
 
657 657
 		case 'mois_annee':
658 658
 			if ($avjc) {
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 	$dtstart = $dtend = $dtabbr = '';
1049 1049
 	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1050
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1051
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1052 1052
 		$dtabbr = '</abbr>';
1053 1053
 	}
1054 1054
 
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 			}
1097 1097
 		} else {
1098 1098
 			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1099
+				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1100 1100
 			} else {
1101 1101
 				$s = spip_ucfirst($s);
1102 1102
 			}
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120 1120
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121 1121
 			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1122
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1123
+			$date_fin = $dtend.$date_fin.$dtabbr;
1124 1124
 
1125 1125
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126 1126
 		} else {
@@ -1137,8 +1137,8 @@  discard block
 block discarded – undo
1137 1137
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138 1138
 			}
1139 1139
 
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1140
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1141
+			$date_fin = $dtend.$date_fin.$dtabbr;
1142 1142
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143 1143
 		}
1144 1144
 	}
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 		$d = date('Y-m-d');
1243 1243
 	}
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
 		$d = date('Y-m-d');
1263 1263
 	}
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+	return substr($d, 0, 4).substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
Please login to merge, or discard this patch.
Indentation   +590 added lines, -590 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Filtres
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
  *    Date au format SQL tel que `2008-04-01` sinon ''
37 37
  **/
38 38
 function extraire_date($texte): string {
39
-	// format = 2001-08
40
-	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
41
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
-	}
43
-	return '';
39
+    // format = 2001-08
40
+    if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
41
+        return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
42
+    }
43
+    return '';
44 44
 }
45 45
 
46 46
 
@@ -62,29 +62,29 @@  discard block
 block discarded – undo
62 62
  *     - une chaîne vide si la date est considérée nulle
63 63
  **/
64 64
 function normaliser_date($date, $forcer_jour = false): string {
65
-	$date = vider_date($date);
66
-	if ($date) {
67
-		if (preg_match('/^[0-9]{8,10}$/', $date)) {
68
-			$date = date('Y-m-d H:i:s', $date);
69
-		}
70
-		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
71
-			$regs = array_pad($regs, 4, null); // eviter notice php
72
-			$date = $regs[1] . '-00-00' . $regs[3];
73
-		} else {
74
-			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
75
-				$regs = array_pad($regs, 4, null); // eviter notice php
76
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
77
-			} else {
78
-				$date = date('Y-m-d H:i:s', strtotime($date));
79
-			}
80
-		}
81
-
82
-		if ($forcer_jour) {
83
-			$date = str_replace('-00', '-01', $date);
84
-		}
85
-	}
86
-
87
-	return $date;
65
+    $date = vider_date($date);
66
+    if ($date) {
67
+        if (preg_match('/^[0-9]{8,10}$/', $date)) {
68
+            $date = date('Y-m-d H:i:s', $date);
69
+        }
70
+        if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
71
+            $regs = array_pad($regs, 4, null); // eviter notice php
72
+            $date = $regs[1] . '-00-00' . $regs[3];
73
+        } else {
74
+            if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
75
+                $regs = array_pad($regs, 4, null); // eviter notice php
76
+                $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
77
+            } else {
78
+                $date = date('Y-m-d H:i:s', strtotime($date));
79
+            }
80
+        }
81
+
82
+        if ($forcer_jour) {
83
+            $date = str_replace('-00', '-01', $date);
84
+        }
85
+    }
86
+
87
+    return $date;
88 88
 }
89 89
 
90 90
 /**
@@ -97,23 +97,23 @@  discard block
 block discarded – undo
97 97
  *     - Une chaine vide
98 98
  **/
99 99
 function vider_date($letexte, $verif_format_date = false): string {
100
-	$letexte ??= '';
101
-	if (
102
-		!$verif_format_date
103
-		or (in_array(strlen($letexte), [10,19]) and
104
-			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
105
-	) {
106
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
107
-			return '';
108
-		}
109
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
110
-			return '';
111
-		}
112
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
113
-			return '';
114
-		}  // eviter le bug GMT-1
115
-	}
116
-	return $letexte;
100
+    $letexte ??= '';
101
+    if (
102
+        !$verif_format_date
103
+        or (in_array(strlen($letexte), [10,19]) and
104
+              preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
105
+    ) {
106
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
107
+            return '';
108
+        }
109
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
110
+            return '';
111
+        }
112
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
113
+            return '';
114
+        }  // eviter le bug GMT-1
115
+    }
116
+    return $letexte;
117 117
 }
118 118
 
119 119
 /**
@@ -129,17 +129,17 @@  discard block
 block discarded – undo
129 129
  **/
130 130
 function recup_heure($date): array {
131 131
 
132
-	if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) {
133
-		array_shift($elements);
134
-		if (!isset($elements[2])) {
135
-			$elements[2] = 0;
136
-		}
137
-		$heure = $elements;
138
-	} else {
139
-		$heure = [0, 0, 0];
140
-	}
141
-
142
-	return $heure;
132
+    if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) {
133
+        array_shift($elements);
134
+        if (!isset($elements[2])) {
135
+            $elements[2] = 0;
136
+        }
137
+        $heure = $elements;
138
+    } else {
139
+        $heure = [0, 0, 0];
140
+    }
141
+
142
+    return $heure;
143 143
 }
144 144
 
145 145
 /**
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
  * @return string heures, sinon 0
154 154
  **/
155 155
 function heures($numdate): string {
156
-	$heures = null;
157
-	$date_array = recup_heure($numdate);
158
-	if ($date_array) {
159
-		[$heures, $minutes, $secondes] = $date_array;
160
-	}
156
+    $heures = null;
157
+    $date_array = recup_heure($numdate);
158
+    if ($date_array) {
159
+        [$heures, $minutes, $secondes] = $date_array;
160
+    }
161 161
 
162
-	return $heures;
162
+    return $heures;
163 163
 }
164 164
 
165 165
 /**
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
  * @return string minutes, sinon 0
174 174
  **/
175 175
 function minutes($numdate): string {
176
-	$minutes = null;
177
-	$date_array = recup_heure($numdate);
178
-	if ($date_array) {
179
-		[$heures, $minutes, $secondes] = $date_array;
180
-	}
176
+    $minutes = null;
177
+    $date_array = recup_heure($numdate);
178
+    if ($date_array) {
179
+        [$heures, $minutes, $secondes] = $date_array;
180
+    }
181 181
 
182
-	return $minutes;
182
+    return $minutes;
183 183
 }
184 184
 
185 185
 /**
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
  * @return string secondes, sinon 0
194 194
  **/
195 195
 function secondes($numdate): string {
196
-	$secondes = null;
197
-	$date_array = recup_heure($numdate);
198
-	if ($date_array) {
199
-		[$heures, $minutes, $secondes] = $date_array;
200
-	}
196
+    $secondes = null;
197
+    $date_array = recup_heure($numdate);
198
+    if ($date_array) {
199
+        [$heures, $minutes, $secondes] = $date_array;
200
+    }
201 201
 
202
-	return $secondes;
202
+    return $secondes;
203 203
 }
204 204
 
205 205
 /**
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
  * @return string L'heure formatée dans la langue en cours.
219 219
  **/
220 220
 function heures_minutes($numdate, $forme = ''): string {
221
-	if ($forme !== 'abbr') {
222
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
-	} else {
224
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
225
-	}
221
+    if ($forme !== 'abbr') {
222
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
+    } else {
224
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
225
+    }
226 226
 }
227 227
 
228 228
 /**
@@ -247,57 +247,57 @@  discard block
 block discarded – undo
247 247
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
248 248
  **/
249 249
 function recup_date($numdate, $forcer_jour = true): array {
250
-	if (!$numdate) {
251
-		return [];
252
-	}
253
-	$heures = $minutes = $secondes = 0;
254
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
255
-		$jour = $regs[1];
256
-		$mois = $regs[2];
257
-		$annee = $regs[3];
258
-		if ($annee < 90) {
259
-			$annee = 2000 + $annee;
260
-		} elseif ($annee < 100) {
261
-			$annee = 1900 + $annee;
262
-		}
263
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
264
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
265
-		$annee = $regs[1];
266
-		$mois = $regs[2];
267
-		$jour = $regs[3];
268
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
269
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
270
-		$annee = $regs[1];
271
-		$mois = $regs[2];
272
-		$jour = '';
273
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
274
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
275
-		$annee = $regs[1];
276
-		$mois = $regs[2];
277
-		$jour = $regs[3];
278
-		$heures = $regs[4];
279
-		$minutes = $regs[5];
280
-		$secondes = $regs[6];
281
-	} else {
282
-		$annee = $mois = $jour = '';
283
-	}
284
-	if ($annee > 4000) {
285
-		$annee -= 9000;
286
-	}
287
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
288
-		$jour = substr($jour, 1);
289
-	}
290
-
291
-	if ($forcer_jour and $jour == '0') {
292
-		$jour = '1';
293
-	}
294
-	if ($forcer_jour and $mois == '0') {
295
-		$mois = '1';
296
-	}
297
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
298
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
299
-	}
300
-	return [];
250
+    if (!$numdate) {
251
+        return [];
252
+    }
253
+    $heures = $minutes = $secondes = 0;
254
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
255
+        $jour = $regs[1];
256
+        $mois = $regs[2];
257
+        $annee = $regs[3];
258
+        if ($annee < 90) {
259
+            $annee = 2000 + $annee;
260
+        } elseif ($annee < 100) {
261
+            $annee = 1900 + $annee;
262
+        }
263
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
264
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
265
+        $annee = $regs[1];
266
+        $mois = $regs[2];
267
+        $jour = $regs[3];
268
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
269
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
270
+        $annee = $regs[1];
271
+        $mois = $regs[2];
272
+        $jour = '';
273
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
274
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
275
+        $annee = $regs[1];
276
+        $mois = $regs[2];
277
+        $jour = $regs[3];
278
+        $heures = $regs[4];
279
+        $minutes = $regs[5];
280
+        $secondes = $regs[6];
281
+    } else {
282
+        $annee = $mois = $jour = '';
283
+    }
284
+    if ($annee > 4000) {
285
+        $annee -= 9000;
286
+    }
287
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
288
+        $jour = substr($jour, 1);
289
+    }
290
+
291
+    if ($forcer_jour and $jour == '0') {
292
+        $jour = '1';
293
+    }
294
+    if ($forcer_jour and $mois == '0') {
295
+        $mois = '1';
296
+    }
297
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
298
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
299
+    }
300
+    return [];
301 301
 }
302 302
 
303 303
 /**
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
  *     La date relative ou complète
325 325
  **/
326 326
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
327
-	return sinon(
328
-		date_relative($date, $decalage_maxi),
329
-		affdate_heure($date)
330
-	);
327
+    return sinon(
328
+        date_relative($date, $decalage_maxi),
329
+        affdate_heure($date)
330
+    );
331 331
 }
332 332
 
333 333
 /**
@@ -360,86 +360,86 @@  discard block
 block discarded – undo
360 360
  **/
361 361
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
362 362
 
363
-	if (!$date) {
364
-		return '';
365
-	}
366
-
367
-	if (is_null($ref_date)) {
368
-		$ref_time = time();
369
-	} else {
370
-		$ref_time = strtotime($ref_date);
371
-	}
372
-
373
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
374
-
375
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
376
-		return '';
377
-	}
378
-
379
-	if ($decal < 0) {
380
-		$il_y_a = 'date_dans';
381
-		$decal = -1 * $decal;
382
-	} else {
383
-		$il_y_a = 'date_il_y_a';
384
-	}
385
-
386
-	if ($decal > 3600 * 24 * 30 * 6) {
387
-		return affdate_court($date);
388
-	}
389
-
390
-	if ($decal > 3600 * 24 * 30) {
391
-		$mois = floor($decal / (3600 * 24 * 30));
392
-		if ($mois < 2) {
393
-			$delai = "$mois " . _T('date_un_mois');
394
-		} else {
395
-			$delai = "$mois " . _T('date_mois');
396
-		}
397
-	} else {
398
-		if ($decal > 3600 * 24 * 7) {
399
-			$semaines = floor($decal / (3600 * 24 * 7));
400
-			if ($semaines < 2) {
401
-				$delai = "$semaines " . _T('date_une_semaine');
402
-			} else {
403
-				$delai = "$semaines " . _T('date_semaines');
404
-			}
405
-		} else {
406
-			if ($decal > 3600 * 24) {
407
-				$jours = floor($decal / (3600 * 24));
408
-				if ($jours < 2) {
409
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
410
-				} else {
411
-					$delai = "$jours " . _T('date_jours');
412
-				}
413
-			} else {
414
-				if ($decal >= 3600) {
415
-					$heures = floor($decal / 3600);
416
-					if ($heures < 2) {
417
-						$delai = "$heures " . _T('date_une_heure');
418
-					} else {
419
-						$delai = "$heures " . _T('date_heures');
420
-					}
421
-				} else {
422
-					if ($decal >= 60) {
423
-						$minutes = floor($decal / 60);
424
-						if ($minutes < 2) {
425
-							$delai = "$minutes " . _T('date_une_minute');
426
-						} else {
427
-							$delai = "$minutes " . _T('date_minutes');
428
-						}
429
-					} else {
430
-						$secondes = ceil($decal);
431
-						if ($secondes < 2) {
432
-							$delai = "$secondes " . _T('date_une_seconde');
433
-						} else {
434
-							$delai = "$secondes " . _T('date_secondes');
435
-						}
436
-					}
437
-				}
438
-			}
439
-		}
440
-	}
441
-
442
-	return _T($il_y_a, ['delai' => $delai]);
363
+    if (!$date) {
364
+        return '';
365
+    }
366
+
367
+    if (is_null($ref_date)) {
368
+        $ref_time = time();
369
+    } else {
370
+        $ref_time = strtotime($ref_date);
371
+    }
372
+
373
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
374
+
375
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
376
+        return '';
377
+    }
378
+
379
+    if ($decal < 0) {
380
+        $il_y_a = 'date_dans';
381
+        $decal = -1 * $decal;
382
+    } else {
383
+        $il_y_a = 'date_il_y_a';
384
+    }
385
+
386
+    if ($decal > 3600 * 24 * 30 * 6) {
387
+        return affdate_court($date);
388
+    }
389
+
390
+    if ($decal > 3600 * 24 * 30) {
391
+        $mois = floor($decal / (3600 * 24 * 30));
392
+        if ($mois < 2) {
393
+            $delai = "$mois " . _T('date_un_mois');
394
+        } else {
395
+            $delai = "$mois " . _T('date_mois');
396
+        }
397
+    } else {
398
+        if ($decal > 3600 * 24 * 7) {
399
+            $semaines = floor($decal / (3600 * 24 * 7));
400
+            if ($semaines < 2) {
401
+                $delai = "$semaines " . _T('date_une_semaine');
402
+            } else {
403
+                $delai = "$semaines " . _T('date_semaines');
404
+            }
405
+        } else {
406
+            if ($decal > 3600 * 24) {
407
+                $jours = floor($decal / (3600 * 24));
408
+                if ($jours < 2) {
409
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
410
+                } else {
411
+                    $delai = "$jours " . _T('date_jours');
412
+                }
413
+            } else {
414
+                if ($decal >= 3600) {
415
+                    $heures = floor($decal / 3600);
416
+                    if ($heures < 2) {
417
+                        $delai = "$heures " . _T('date_une_heure');
418
+                    } else {
419
+                        $delai = "$heures " . _T('date_heures');
420
+                    }
421
+                } else {
422
+                    if ($decal >= 60) {
423
+                        $minutes = floor($decal / 60);
424
+                        if ($minutes < 2) {
425
+                            $delai = "$minutes " . _T('date_une_minute');
426
+                        } else {
427
+                            $delai = "$minutes " . _T('date_minutes');
428
+                        }
429
+                    } else {
430
+                        $secondes = ceil($decal);
431
+                        if ($secondes < 2) {
432
+                            $delai = "$secondes " . _T('date_une_seconde');
433
+                        } else {
434
+                            $delai = "$secondes " . _T('date_secondes');
435
+                        }
436
+                    }
437
+                }
438
+            }
439
+        }
440
+    }
441
+
442
+    return _T($il_y_a, ['delai' => $delai]);
443 443
 }
444 444
 
445 445
 
@@ -465,32 +465,32 @@  discard block
 block discarded – undo
465 465
  **/
466 466
 function date_relativecourt($date, $decalage_maxi = 0): string {
467 467
 
468
-	if (!$date) {
469
-		return '';
470
-	}
471
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
472
-
473
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
474
-		return '';
475
-	}
476
-
477
-	if ($decal < -24 * 3600) {
478
-		$retour = date_relative($date, $decalage_maxi);
479
-	} elseif ($decal < 0) {
480
-		$retour = _T('date_demain');
481
-	} else {
482
-		if ($decal < (3600 * 24)) {
483
-			$retour = _T('date_aujourdhui');
484
-		} else {
485
-			if ($decal < (3600 * 24 * 2)) {
486
-				$retour = _T('date_hier');
487
-			} else {
488
-				$retour = date_relative($date, $decalage_maxi);
489
-			}
490
-		}
491
-	}
492
-
493
-	return $retour;
468
+    if (!$date) {
469
+        return '';
470
+    }
471
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
472
+
473
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
474
+        return '';
475
+    }
476
+
477
+    if ($decal < -24 * 3600) {
478
+        $retour = date_relative($date, $decalage_maxi);
479
+    } elseif ($decal < 0) {
480
+        $retour = _T('date_demain');
481
+    } else {
482
+        if ($decal < (3600 * 24)) {
483
+            $retour = _T('date_aujourdhui');
484
+        } else {
485
+            if ($decal < (3600 * 24 * 2)) {
486
+                $retour = _T('date_hier');
487
+            } else {
488
+                $retour = date_relative($date, $decalage_maxi);
489
+            }
490
+        }
491
+    }
492
+
493
+    return $retour;
494 494
 }
495 495
 
496 496
 /**
@@ -507,175 +507,175 @@  discard block
 block discarded – undo
507 507
  * @return string
508 508
  */
509 509
 function affdate_base($numdate, $vue, $options = []): string {
510
-	if (is_string($options)) {
511
-		$options = ['param' => $options];
512
-	}
513
-	$date_array = recup_date($numdate, false);
514
-	if (!$date_array) {
515
-		return '';
516
-	}
517
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
518
-
519
-	// 1er, 21st, etc.
520
-	$journum = $jour;
521
-
522
-	if ($jour == 0) {
523
-		$jour = '';
524
-		$njour = 0;
525
-	} else {
526
-		$njour = intval($jour);
527
-		if ($jourth = _T('date_jnum' . $jour)) {
528
-			$jour = $jourth;
529
-		}
530
-	}
531
-
532
-	$mois = intval($mois);
533
-	if ($mois > 0 and $mois < 13) {
534
-		/* Traiter le cas "abbr" pour les noms de mois */
535
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
536
-		$nommois = _T('date_mois_' . $mois . $param);
537
-		if ($jour) {
538
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
539
-		} else {
540
-			$jourmois = $nommois;
541
-		}
542
-	} else {
543
-		$nommois = '';
544
-		$jourmois = '';
545
-	}
546
-
547
-	if ($annee < 0) {
548
-		$annee = -$annee . ' ' . _T('date_avant_jc');
549
-		$avjc = true;
550
-	} else {
551
-		$avjc = false;
552
-	}
553
-
554
-	switch ($vue) {
555
-		case 'saison':
556
-		case 'saison_annee':
557
-			$saison = '';
558
-			if ($mois > 0) {
559
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
560
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
561
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
562
-				}
563
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
564
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
565
-				}
566
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
567
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
568
-				}
569
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
570
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
571
-				}
572
-			}
573
-			if ($vue == 'saison') {
574
-				return $saison ? _T('date_saison_' . $saison) : '';
575
-			} else {
576
-				return $saison ? trim(_T(
577
-					'date_fmt_saison_annee',
578
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
579
-				)) : '';
580
-			}
581
-
582
-		case 'court':
583
-			if ($avjc) {
584
-				return $annee;
585
-			}
586
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
587
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
588
-				return $annee;
589
-			}
590
-			if ($annee != $a) {
591
-				return _T(
592
-					'date_fmt_mois_annee',
593
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
594
-				);
595
-			}
596
-
597
-			return _T(
598
-				'date_fmt_jour_mois',
599
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
600
-			);
601
-
602
-		case 'jourcourt':
603
-			if ($avjc) {
604
-				return $annee;
605
-			}
606
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
607
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
608
-				return $annee;
609
-			}
610
-			if ($annee != $a) {
611
-				return _T(
612
-					'date_fmt_jour_mois_annee',
613
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
614
-				);
615
-			}
616
-
617
-			return _T(
618
-				'date_fmt_jour_mois',
619
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
620
-			);
621
-
622
-		case 'entier':
623
-			if ($avjc) {
624
-				return $annee;
625
-			}
626
-			if ($jour) {
627
-				return _T(
628
-					'date_fmt_jour_mois_annee',
629
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
630
-				);
631
-			} elseif ($mois) {
632
-				return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
633
-			} else {
634
-				return $annee;
635
-			}
636
-
637
-		case 'nom_mois':
638
-			return $nommois;
639
-
640
-		case 'mois':
641
-			return sprintf('%02s', $mois);
642
-
643
-		case 'jour':
644
-			return $jour;
645
-
646
-		case 'journum':
647
-			return $journum;
648
-
649
-		case 'nom_jour':
650
-			if (!$mois or !$njour) {
651
-				return '';
652
-			}
653
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
654
-			$nom = 1 + (int) date('w', $nom);
655
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
656
-
657
-			return _T('date_jour_' . $nom . $param);
658
-
659
-		case 'mois_annee':
660
-			if ($avjc) {
661
-				return $annee;
662
-			}
663
-
664
-			return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
665
-
666
-		case 'annee':
667
-			return $annee;
668
-
669
-		// Cas d'une vue non definie : retomber sur le format
670
-		// de date propose par http://www.php.net/date
671
-		default:
672
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
673
-			// il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
674
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
675
-				$time = strtotime($numdate);
676
-			}
677
-			return date($vue, $time);
678
-	}
510
+    if (is_string($options)) {
511
+        $options = ['param' => $options];
512
+    }
513
+    $date_array = recup_date($numdate, false);
514
+    if (!$date_array) {
515
+        return '';
516
+    }
517
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
518
+
519
+    // 1er, 21st, etc.
520
+    $journum = $jour;
521
+
522
+    if ($jour == 0) {
523
+        $jour = '';
524
+        $njour = 0;
525
+    } else {
526
+        $njour = intval($jour);
527
+        if ($jourth = _T('date_jnum' . $jour)) {
528
+            $jour = $jourth;
529
+        }
530
+    }
531
+
532
+    $mois = intval($mois);
533
+    if ($mois > 0 and $mois < 13) {
534
+        /* Traiter le cas "abbr" pour les noms de mois */
535
+        $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
536
+        $nommois = _T('date_mois_' . $mois . $param);
537
+        if ($jour) {
538
+            $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
539
+        } else {
540
+            $jourmois = $nommois;
541
+        }
542
+    } else {
543
+        $nommois = '';
544
+        $jourmois = '';
545
+    }
546
+
547
+    if ($annee < 0) {
548
+        $annee = -$annee . ' ' . _T('date_avant_jc');
549
+        $avjc = true;
550
+    } else {
551
+        $avjc = false;
552
+    }
553
+
554
+    switch ($vue) {
555
+        case 'saison':
556
+        case 'saison_annee':
557
+            $saison = '';
558
+            if ($mois > 0) {
559
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
560
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
561
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
562
+                }
563
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
564
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
565
+                }
566
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
567
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
568
+                }
569
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
570
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
571
+                }
572
+            }
573
+            if ($vue == 'saison') {
574
+                return $saison ? _T('date_saison_' . $saison) : '';
575
+            } else {
576
+                return $saison ? trim(_T(
577
+                    'date_fmt_saison_annee',
578
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
579
+                )) : '';
580
+            }
581
+
582
+        case 'court':
583
+            if ($avjc) {
584
+                return $annee;
585
+            }
586
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
587
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
588
+                return $annee;
589
+            }
590
+            if ($annee != $a) {
591
+                return _T(
592
+                    'date_fmt_mois_annee',
593
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
594
+                );
595
+            }
596
+
597
+            return _T(
598
+                'date_fmt_jour_mois',
599
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
600
+            );
601
+
602
+        case 'jourcourt':
603
+            if ($avjc) {
604
+                return $annee;
605
+            }
606
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
607
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
608
+                return $annee;
609
+            }
610
+            if ($annee != $a) {
611
+                return _T(
612
+                    'date_fmt_jour_mois_annee',
613
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
614
+                );
615
+            }
616
+
617
+            return _T(
618
+                'date_fmt_jour_mois',
619
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
620
+            );
621
+
622
+        case 'entier':
623
+            if ($avjc) {
624
+                return $annee;
625
+            }
626
+            if ($jour) {
627
+                return _T(
628
+                    'date_fmt_jour_mois_annee',
629
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
630
+                );
631
+            } elseif ($mois) {
632
+                return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
633
+            } else {
634
+                return $annee;
635
+            }
636
+
637
+        case 'nom_mois':
638
+            return $nommois;
639
+
640
+        case 'mois':
641
+            return sprintf('%02s', $mois);
642
+
643
+        case 'jour':
644
+            return $jour;
645
+
646
+        case 'journum':
647
+            return $journum;
648
+
649
+        case 'nom_jour':
650
+            if (!$mois or !$njour) {
651
+                return '';
652
+            }
653
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
654
+            $nom = 1 + (int) date('w', $nom);
655
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
656
+
657
+            return _T('date_jour_' . $nom . $param);
658
+
659
+        case 'mois_annee':
660
+            if ($avjc) {
661
+                return $annee;
662
+            }
663
+
664
+            return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
665
+
666
+        case 'annee':
667
+            return $annee;
668
+
669
+        // Cas d'une vue non definie : retomber sur le format
670
+        // de date propose par http://www.php.net/date
671
+        default:
672
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
673
+            // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
674
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
675
+                $time = strtotime($numdate);
676
+            }
677
+            return date($vue, $time);
678
+    }
679 679
 }
680 680
 
681 681
 
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
  *     Nom du jour
703 703
  **/
704 704
 function nom_jour($numdate, $forme = ''): string {
705
-	if (!($forme === 'abbr' or $forme === 'initiale')) {
706
-		$forme = '';
707
-	}
705
+    if (!($forme === 'abbr' or $forme === 'initiale')) {
706
+        $forme = '';
707
+    }
708 708
 
709
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
709
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
710 710
 }
711 711
 
712 712
 /**
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
  *     Numéro du jour
729 729
  **/
730 730
 function jour($numdate): string {
731
-	return affdate_base($numdate, 'jour');
731
+    return affdate_base($numdate, 'jour');
732 732
 }
733 733
 
734 734
 /**
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
  *     Numéro du jour
747 747
  **/
748 748
 function journum($numdate): string {
749
-	return affdate_base($numdate, 'journum');
749
+    return affdate_base($numdate, 'journum');
750 750
 }
751 751
 
752 752
 /**
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
  *     Numéro du mois (sur 2 chiffres)
765 765
  **/
766 766
 function mois($numdate): string {
767
-	return  affdate_base($numdate, 'mois');
767
+    return  affdate_base($numdate, 'mois');
768 768
 }
769 769
 
770 770
 /**
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
  *     Nom du mois
789 789
  **/
790 790
 function nom_mois($numdate, $forme = ''): string {
791
-	if (!($forme === 'abbr')) {
792
-		$forme = '';
793
-	}
791
+    if (!($forme === 'abbr')) {
792
+        $forme = '';
793
+    }
794 794
 
795
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
795
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
796 796
 }
797 797
 
798 798
 /**
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
  *     Année (sur 4 chiffres)
811 811
  **/
812 812
 function annee($numdate): string {
813
-	return affdate_base($numdate, 'annee');
813
+    return affdate_base($numdate, 'annee');
814 814
 }
815 815
 
816 816
 
@@ -840,11 +840,11 @@  discard block
 block discarded – undo
840 840
  *     La date formatée
841 841
  **/
842 842
 function saison($numdate, $hemisphere = 'nord'): string {
843
-	if ($hemisphere !== 'sud') {
844
-		$hemisphere = 'nord';
845
-	}
843
+    if ($hemisphere !== 'sud') {
844
+        $hemisphere = 'nord';
845
+    }
846 846
 
847
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
847
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
848 848
 }
849 849
 
850 850
 
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
  *     La date formatée
874 874
  **/
875 875
 function saison_annee($numdate, $hemisphere = 'nord'): string {
876
-	if ($hemisphere !== 'sud') {
877
-		$hemisphere = 'nord';
878
-	}
876
+    if ($hemisphere !== 'sud') {
877
+        $hemisphere = 'nord';
878
+    }
879 879
 
880
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
880
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
881 881
 }
882 882
 
883 883
 /**
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
  *     La date formatée
906 906
  **/
907 907
 function affdate($numdate, $format = 'entier'): string {
908
-	return affdate_base($numdate, $format);
908
+    return affdate_base($numdate, $format);
909 909
 }
910 910
 
911 911
 
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
  *     La date formatée
933 933
  **/
934 934
 function affdate_court($numdate, $annee_courante = null): string {
935
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
935
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
936 936
 }
937 937
 
938 938
 
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
  *     La date formatée
960 960
  **/
961 961
 function affdate_jourcourt($numdate, $annee_courante = null): string {
962
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
962
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
963 963
 }
964 964
 
965 965
 /**
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
  *     La date formatée
978 978
  **/
979 979
 function affdate_mois_annee($numdate): string {
980
-	return affdate_base($numdate, 'mois_annee');
980
+    return affdate_base($numdate, 'mois_annee');
981 981
 }
982 982
 
983 983
 /**
@@ -995,16 +995,16 @@  discard block
 block discarded – undo
995 995
  *     La date formatée, sinon ''
996 996
  **/
997 997
 function affdate_heure($numdate): string {
998
-	$date_array = recup_date($numdate);
999
-	if (!$date_array) {
1000
-		return '';
1001
-	}
1002
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1003
-
1004
-	return _T('date_fmt_jour_heure', [
1005
-		'jour' => affdate($numdate),
1006
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1007
-	]);
998
+    $date_array = recup_date($numdate);
999
+    if (!$date_array) {
1000
+        return '';
1001
+    }
1002
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1003
+
1004
+    return _T('date_fmt_jour_heure', [
1005
+        'jour' => affdate($numdate),
1006
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1007
+    ]);
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1036,117 +1036,117 @@  discard block
 block discarded – undo
1036 1036
  *     texte de la date
1037 1037
  */
1038 1038
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
1039
-	$abbr = $jour = '';
1040
-	$affdate = 'affdate_jourcourt';
1041
-	if (strpos($forme, 'abbr') !== false) {
1042
-		$abbr = 'abbr';
1043
-	}
1044
-	if (strpos($forme, 'annee') !== false) {
1045
-		$affdate = 'affdate';
1046
-	}
1047
-	if (strpos($forme, 'jour') !== false) {
1048
-		$jour = 'jour';
1049
-	}
1050
-
1051
-	$dtstart = $dtend = $dtabbr = '';
1052
-	if (strpos($forme, 'hcal') !== false) {
1053
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1054
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1055
-		$dtabbr = '</abbr>';
1056
-	}
1057
-
1058
-	$date_debut = strtotime($date_debut);
1059
-	$date_fin = strtotime($date_fin);
1060
-	$d = date('Y-m-d', $date_debut);
1061
-	$f = date('Y-m-d', $date_fin);
1062
-	$h = ($horaire === 'oui' or $horaire === true);
1063
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1064
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1065
-
1066
-	if ($d == $f) { // meme jour
1067
-		$nomjour = nom_jour($d, $abbr);
1068
-		$s = $affdate($d);
1069
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1070
-		if ($h) {
1071
-			if ($hd == $hf) {
1072
-				// Lundi 20 fevrier a 18h25
1073
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1074
-				$s = "$dtstart$s$dtabbr";
1075
-			} else {
1076
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1077
-				if ($dtabbr && $dtstart && $dtend) {
1078
-					$s = _T(
1079
-						'date_fmt_jour_heure_debut_fin_abbr',
1080
-						[
1081
-						'jour' => spip_ucfirst($s),
1082
-						'heure_debut' => $hd,
1083
-						'heure_fin' => $hf,
1084
-						'dtstart' => $dtstart,
1085
-						'dtend' => $dtend,
1086
-						'dtabbr' => $dtabbr
1087
-						],
1088
-						[
1089
-							'sanitize' => false
1090
-						]
1091
-					);
1092
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1093
-				else {
1094
-					$s = spip_ucfirst(_T(
1095
-						'date_fmt_jour_heure_debut_fin',
1096
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1097
-					));
1098
-				}
1099
-			}
1100
-		} else {
1101
-			if ($dtabbr && $dtstart) {
1102
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1103
-			} else {
1104
-				$s = spip_ucfirst($s);
1105
-			}
1106
-		}
1107
-	} else {
1108
-		if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1109
-			if (!$h) {
1110
-				$date_debut = jour($d);
1111
-			} else {
1112
-				$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1113
-			}
1114
-			$date_fin = $affdate($f);
1115
-			if ($jour) {
1116
-				$nomjour_debut = nom_jour($d, $abbr);
1117
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1118
-				$nomjour_fin = nom_jour($f, $abbr);
1119
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1120
-			}
1121
-			if ($h) {
1122
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1123
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1124
-			}
1125
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1126
-			$date_fin = $dtend . $date_fin . $dtabbr;
1127
-
1128
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1129
-		} else {
1130
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1131
-			$date_fin = $affdate($f);
1132
-			if ($jour) {
1133
-				$nomjour_debut = nom_jour($d, $abbr);
1134
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1135
-				$nomjour_fin = nom_jour($f, $abbr);
1136
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1137
-			}
1138
-			if ($h) {
1139
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1140
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1141
-			}
1142
-
1143
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1144
-			$date_fin = $dtend . $date_fin . $dtabbr;
1145
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1146
-		}
1147
-	}
1148
-
1149
-	return $s;
1039
+    $abbr = $jour = '';
1040
+    $affdate = 'affdate_jourcourt';
1041
+    if (strpos($forme, 'abbr') !== false) {
1042
+        $abbr = 'abbr';
1043
+    }
1044
+    if (strpos($forme, 'annee') !== false) {
1045
+        $affdate = 'affdate';
1046
+    }
1047
+    if (strpos($forme, 'jour') !== false) {
1048
+        $jour = 'jour';
1049
+    }
1050
+
1051
+    $dtstart = $dtend = $dtabbr = '';
1052
+    if (strpos($forme, 'hcal') !== false) {
1053
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1054
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1055
+        $dtabbr = '</abbr>';
1056
+    }
1057
+
1058
+    $date_debut = strtotime($date_debut);
1059
+    $date_fin = strtotime($date_fin);
1060
+    $d = date('Y-m-d', $date_debut);
1061
+    $f = date('Y-m-d', $date_fin);
1062
+    $h = ($horaire === 'oui' or $horaire === true);
1063
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1064
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1065
+
1066
+    if ($d == $f) { // meme jour
1067
+        $nomjour = nom_jour($d, $abbr);
1068
+        $s = $affdate($d);
1069
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1070
+        if ($h) {
1071
+            if ($hd == $hf) {
1072
+                // Lundi 20 fevrier a 18h25
1073
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1074
+                $s = "$dtstart$s$dtabbr";
1075
+            } else {
1076
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1077
+                if ($dtabbr && $dtstart && $dtend) {
1078
+                    $s = _T(
1079
+                        'date_fmt_jour_heure_debut_fin_abbr',
1080
+                        [
1081
+                        'jour' => spip_ucfirst($s),
1082
+                        'heure_debut' => $hd,
1083
+                        'heure_fin' => $hf,
1084
+                        'dtstart' => $dtstart,
1085
+                        'dtend' => $dtend,
1086
+                        'dtabbr' => $dtabbr
1087
+                        ],
1088
+                        [
1089
+                            'sanitize' => false
1090
+                        ]
1091
+                    );
1092
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1093
+                else {
1094
+                    $s = spip_ucfirst(_T(
1095
+                        'date_fmt_jour_heure_debut_fin',
1096
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1097
+                    ));
1098
+                }
1099
+            }
1100
+        } else {
1101
+            if ($dtabbr && $dtstart) {
1102
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1103
+            } else {
1104
+                $s = spip_ucfirst($s);
1105
+            }
1106
+        }
1107
+    } else {
1108
+        if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1109
+            if (!$h) {
1110
+                $date_debut = jour($d);
1111
+            } else {
1112
+                $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1113
+            }
1114
+            $date_fin = $affdate($f);
1115
+            if ($jour) {
1116
+                $nomjour_debut = nom_jour($d, $abbr);
1117
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1118
+                $nomjour_fin = nom_jour($f, $abbr);
1119
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1120
+            }
1121
+            if ($h) {
1122
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1123
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1124
+            }
1125
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1126
+            $date_fin = $dtend . $date_fin . $dtabbr;
1127
+
1128
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1129
+        } else {
1130
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1131
+            $date_fin = $affdate($f);
1132
+            if ($jour) {
1133
+                $nomjour_debut = nom_jour($d, $abbr);
1134
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1135
+                $nomjour_fin = nom_jour($f, $abbr);
1136
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1137
+            }
1138
+            if ($h) {
1139
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1140
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1141
+            }
1142
+
1143
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1144
+            $date_fin = $dtend . $date_fin . $dtabbr;
1145
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1146
+        }
1147
+    }
1148
+
1149
+    return $s;
1150 1150
 }
1151 1151
 
1152 1152
 /**
@@ -1167,10 +1167,10 @@  discard block
 block discarded – undo
1167 1167
  *     Date au format ical
1168 1168
  **/
1169 1169
 function date_ical($date, $addminutes = 0): string {
1170
-	[$heures, $minutes, $secondes] = recup_heure($date);
1171
-	[$annee, $mois, $jour] = recup_date($date);
1170
+    [$heures, $minutes, $secondes] = recup_heure($date);
1171
+    [$annee, $mois, $jour] = recup_date($date);
1172 1172
 
1173
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1173
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1174 1174
 }
1175 1175
 
1176 1176
 
@@ -1194,14 +1194,14 @@  discard block
 block discarded – undo
1194 1194
  *     La date formatée
1195 1195
  **/
1196 1196
 function date_iso($date_heure): string {
1197
-	$date = recup_date($date_heure);
1198
-	$annee = $date[0] ?? null;
1199
-	$mois = $date[1] ?? null;
1200
-	$jour = $date[2] ?? null;
1201
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1202
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1203
-
1204
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1197
+    $date = recup_date($date_heure);
1198
+    $annee = $date[0] ?? null;
1199
+    $mois = $date[1] ?? null;
1200
+    $jour = $date[2] ?? null;
1201
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1202
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1203
+
1204
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1205 1205
 }
1206 1206
 
1207 1207
 /**
@@ -1224,11 +1224,11 @@  discard block
 block discarded – undo
1224 1224
  *     La date formatée
1225 1225
  **/
1226 1226
 function date_822($date_heure): string {
1227
-	[$annee, $mois, $jour] = recup_date($date_heure);
1228
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1229
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1227
+    [$annee, $mois, $jour] = recup_date($date_heure);
1228
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1229
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1230 1230
 
1231
-	return date('r', $time);
1231
+    return date('r', $time);
1232 1232
 }
1233 1233
 
1234 1234
 /**
@@ -1244,11 +1244,11 @@  discard block
 block discarded – undo
1244 1244
  *     Date au format `Ymd`
1245 1245
  **/
1246 1246
 function date_anneemoisjour($d): string {
1247
-	if (!$d) {
1248
-		$d = date('Y-m-d');
1249
-	}
1247
+    if (!$d) {
1248
+        $d = date('Y-m-d');
1249
+    }
1250 1250
 
1251
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1251
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1252 1252
 }
1253 1253
 
1254 1254
 /**
@@ -1264,11 +1264,11 @@  discard block
 block discarded – undo
1264 1264
  *     Date au format `Ym`
1265 1265
  **/
1266 1266
 function date_anneemois($d): string {
1267
-	if (!$d) {
1268
-		$d = date('Y-m-d');
1269
-	}
1267
+    if (!$d) {
1268
+        $d = date('Y-m-d');
1269
+    }
1270 1270
 
1271
-	return substr($d, 0, 4) . substr($d, 5, 2);
1271
+    return substr($d, 0, 4) . substr($d, 5, 2);
1272 1272
 }
1273 1273
 
1274 1274
 /**
@@ -1284,13 +1284,13 @@  discard block
 block discarded – undo
1284 1284
  *     Date au lundi de la même semaine au format `Ymd`
1285 1285
  **/
1286 1286
 function date_debut_semaine($annee, $mois, $jour): string {
1287
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1288
-	if ($w_day == 0) {
1289
-		$w_day = 7;
1290
-	} // Gaffe: le dimanche est zero
1291
-	$debut = $jour - $w_day + 1;
1287
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1288
+    if ($w_day == 0) {
1289
+        $w_day = 7;
1290
+    } // Gaffe: le dimanche est zero
1291
+    $debut = $jour - $w_day + 1;
1292 1292
 
1293
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1293
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1294 1294
 }
1295 1295
 
1296 1296
 /**
@@ -1306,11 +1306,11 @@  discard block
 block discarded – undo
1306 1306
  *     Date au dimanche de la même semaine au format `Ymd`
1307 1307
  **/
1308 1308
 function date_fin_semaine($annee, $mois, $jour): string {
1309
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1310
-	if ($w_day == 0) {
1311
-		$w_day = 7;
1312
-	} // Gaffe: le dimanche est zero
1313
-	$debut = $jour - $w_day + 1;
1309
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1310
+    if ($w_day == 0) {
1311
+        $w_day = 7;
1312
+    } // Gaffe: le dimanche est zero
1313
+    $debut = $jour - $w_day + 1;
1314 1314
 
1315
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1315
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1316 1316
 }
Please login to merge, or discard this patch.