Completed
Pull Request — master (#39)
by
unknown
06:05
created
ecrire/base/dump.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -311,7 +311,7 @@
 block discarded – undo
311 311
  * peut etre utilise pour l'import depuis xml,
312 312
  * ou la copie de base a base (mysql<->sqlite par exemple)
313 313
  *
314
- * @param array $tables
314
+ * @param string[] $tables
315 315
  * @param array $exclure_tables
316 316
  * @param string $serveur
317 317
  */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -326,14 +326,15 @@
 block discarded – undo
326 326
 				$connecte = false;
327 327
 			}
328 328
 		}
329
-		if ($connecte)
330
-			# on ajoute les liaisons en premier
329
+		if ($connecte) {
330
+					# on ajoute les liaisons en premier
331 331
 			# si une restauration est interrompue,
332 332
 			# cela se verra mieux si il manque des objets
333 333
 			# que des liens
334 334
 		{
335 335
 			array_unshift($tables_for_dump, $link_table);
336 336
 		}
337
+		}
337 338
 	}
338 339
 
339 340
 	return array($tables_for_dump, $tables_for_link);
Please login to merge, or discard this patch.
Indentation   +490 added lines, -490 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 define('_VERSION_ARCHIVE', '1.3');
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 // NB: Ce fichier peut ajouter des tables (old-style)
30 30
 // donc il faut l'inclure "en globals"
31 31
 if ($f = find_in_path('mes_fonctions.php')) {
32
-	global $dossier_squelettes;
33
-	@include_once(_ROOT_CWD . $f);
32
+    global $dossier_squelettes;
33
+    @include_once(_ROOT_CWD . $f);
34 34
 }
35 35
 
36 36
 if (@is_readable(_CACHE_PLUGINS_FCT)) {
37
-	// chargement optimise precompile
38
-	include_once(_CACHE_PLUGINS_FCT);
37
+    // chargement optimise precompile
38
+    include_once(_CACHE_PLUGINS_FCT);
39 39
 }
40 40
 
41 41
 /**
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  * @return string
49 49
  **/
50 50
 function base_dump_meta_name($rub) {
51
-	return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']);
51
+    return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']);
52 52
 }
53 53
 
54 54
 /**
@@ -63,15 +63,15 @@  discard block
 block discarded – undo
63 63
  * @return string
64 64
  **/
65 65
 function base_dump_dir($meta) {
66
-	include_spip('inc/documents');
67
-	// determine upload va aussi initialiser l'index "restreint"
68
-	$maindir = determine_upload();
69
-	if (!$GLOBALS['visiteur_session']['restreint']) {
70
-		$maindir = _DIR_DUMP;
71
-	}
72
-	$dir = sous_repertoire($maindir, $meta);
73
-
74
-	return $dir;
66
+    include_spip('inc/documents');
67
+    // determine upload va aussi initialiser l'index "restreint"
68
+    $maindir = determine_upload();
69
+    if (!$GLOBALS['visiteur_session']['restreint']) {
70
+        $maindir = _DIR_DUMP;
71
+    }
72
+    $dir = sous_repertoire($maindir, $meta);
73
+
74
+    return $dir;
75 75
 }
76 76
 
77 77
 /**
@@ -85,28 +85,28 @@  discard block
 block discarded – undo
85 85
  * @return array
86 86
  */
87 87
 function base_lister_toutes_tables(
88
-	$serveur = '',
89
-	$tables = array(),
90
-	$exclude = array(),
91
-	$affiche_vrai_prefixe = false
88
+    $serveur = '',
89
+    $tables = array(),
90
+    $exclude = array(),
91
+    $affiche_vrai_prefixe = false
92 92
 ) {
93
-	spip_connect($serveur);
94
-	$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
95
-	$prefixe = $connexion['prefixe'];
96
-
97
-	$p = '/^' . $prefixe . '/';
98
-	$res = $tables;
99
-	foreach (sql_alltable(null, $serveur) as $t) {
100
-		if (preg_match($p, $t)) {
101
-			$t1 = preg_replace($p, 'spip', $t);
102
-			if (!in_array($t1, $tables) and !in_array($t1, $exclude)) {
103
-				$res[] = ($affiche_vrai_prefixe ? $t : $t1);
104
-			}
105
-		}
106
-	}
107
-	sort($res);
108
-
109
-	return $res;
93
+    spip_connect($serveur);
94
+    $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
95
+    $prefixe = $connexion['prefixe'];
96
+
97
+    $p = '/^' . $prefixe . '/';
98
+    $res = $tables;
99
+    foreach (sql_alltable(null, $serveur) as $t) {
100
+        if (preg_match($p, $t)) {
101
+            $t1 = preg_replace($p, 'spip', $t);
102
+            if (!in_array($t1, $tables) and !in_array($t1, $exclude)) {
103
+                $res[] = ($affiche_vrai_prefixe ? $t : $t1);
104
+            }
105
+        }
106
+    }
107
+    sort($res);
108
+
109
+    return $res;
110 110
 }
111 111
 
112 112
 /**
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
  * @return string
117 117
  */
118 118
 function base_prefixe_tables($serveur = '') {
119
-	spip_connect($serveur);
120
-	$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
121
-	$prefixe = $connexion['prefixe'];
119
+    spip_connect($serveur);
120
+    $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
121
+    $prefixe = $connexion['prefixe'];
122 122
 
123
-	return $prefixe;
123
+    return $prefixe;
124 124
 }
125 125
 
126 126
 
@@ -135,29 +135,29 @@  discard block
 block discarded – undo
135 135
  * @return array
136 136
  */
137 137
 function base_saisie_tables($name, $tables, $exclude = array(), $post = null, $serveur = '') {
138
-	include_spip('inc/filtres');
139
-	$res = array();
140
-	foreach ($tables as $k => $t) {
141
-		// par defaut tout est coche sauf les tables dans $exclude
142
-		if (is_null($post)) {
143
-			$check = (in_array($t, $exclude) ? false : true);
144
-		} // mais si on a poste une selection, la reprendre
145
-		else {
146
-			$check = in_array($t, $post);
147
-		}
148
-
149
-		$res[$k] = "<input type='checkbox' value='$t' name='$name"
150
-			. "[]' id='$name$k'"
151
-			. ($check ? " checked='checked'" : '')
152
-			. "/>\n"
153
-			. "<label for='$name$k'>$t</label>"
154
-			. " ("
155
-			. sinon(singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'),
156
-				_T('dump:aucune_donnee'))
157
-			. ")";
158
-	}
159
-
160
-	return $res;
138
+    include_spip('inc/filtres');
139
+    $res = array();
140
+    foreach ($tables as $k => $t) {
141
+        // par defaut tout est coche sauf les tables dans $exclude
142
+        if (is_null($post)) {
143
+            $check = (in_array($t, $exclude) ? false : true);
144
+        } // mais si on a poste une selection, la reprendre
145
+        else {
146
+            $check = in_array($t, $post);
147
+        }
148
+
149
+        $res[$k] = "<input type='checkbox' value='$t' name='$name"
150
+            . "[]' id='$name$k'"
151
+            . ($check ? " checked='checked'" : '')
152
+            . "/>\n"
153
+            . "<label for='$name$k'>$t</label>"
154
+            . " ("
155
+            . sinon(singulier_ou_pluriel(sql_countsel($t, '', '', '', $serveur), 'dump:une_donnee', 'dump:nb_donnees'),
156
+                _T('dump:aucune_donnee'))
157
+            . ")";
158
+    }
159
+
160
+    return $res;
161 161
 }
162 162
 
163 163
 
@@ -169,27 +169,27 @@  discard block
 block discarded – undo
169 169
  * @return array
170 170
  */
171 171
 function lister_tables_noexport() {
172
-	// par defaut tout est exporte sauf les tables ci-dessous
173
-	static $EXPORT_tables_noexport = null;
174
-	if (!is_null($EXPORT_tables_noexport)) {
175
-		return $EXPORT_tables_noexport;
176
-	}
177
-
178
-	$EXPORT_tables_noexport = array(
179
-		'spip_caches', // plugin invalideur
180
-		'spip_resultats', // resultats de recherche ... c'est un cache !
181
-		'spip_test', // c'est un test !
182
-		#'spip_referers',
183
-		#'spip_referers_articles',
184
-		#'spip_visites',
185
-		#'spip_visites_articles',
186
-		#'spip_versions',
187
-		#'spip_versions_fragments'
188
-	);
189
-
190
-	$EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport);
191
-
192
-	return $EXPORT_tables_noexport;
172
+    // par defaut tout est exporte sauf les tables ci-dessous
173
+    static $EXPORT_tables_noexport = null;
174
+    if (!is_null($EXPORT_tables_noexport)) {
175
+        return $EXPORT_tables_noexport;
176
+    }
177
+
178
+    $EXPORT_tables_noexport = array(
179
+        'spip_caches', // plugin invalideur
180
+        'spip_resultats', // resultats de recherche ... c'est un cache !
181
+        'spip_test', // c'est un test !
182
+        #'spip_referers',
183
+        #'spip_referers_articles',
184
+        #'spip_visites',
185
+        #'spip_visites_articles',
186
+        #'spip_versions',
187
+        #'spip_versions_fragments'
188
+    );
189
+
190
+    $EXPORT_tables_noexport = pipeline('lister_tables_noexport', $EXPORT_tables_noexport);
191
+
192
+    return $EXPORT_tables_noexport;
193 193
 }
194 194
 
195 195
 /**
@@ -200,25 +200,25 @@  discard block
 block discarded – undo
200 200
  * @return array
201 201
  */
202 202
 function lister_tables_noimport() {
203
-	static $IMPORT_tables_noimport = null;
204
-	if (!is_null($IMPORT_tables_noimport)) {
205
-		return $IMPORT_tables_noimport;
206
-	}
207
-
208
-	$IMPORT_tables_noimport = array();
209
-	// par defaut tout est importe sauf les tables ci-dessous
210
-	// possibiliter de definir cela tables via la meta
211
-	// compatibilite
212
-	if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) {
213
-		$IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']);
214
-		if (!is_array($IMPORT_tables_noimport)) {
215
-			include_spip('inc/meta');
216
-			effacer_meta('IMPORT_tables_noimport');
217
-		}
218
-	}
219
-	$IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport);
220
-
221
-	return $IMPORT_tables_noimport;
203
+    static $IMPORT_tables_noimport = null;
204
+    if (!is_null($IMPORT_tables_noimport)) {
205
+        return $IMPORT_tables_noimport;
206
+    }
207
+
208
+    $IMPORT_tables_noimport = array();
209
+    // par defaut tout est importe sauf les tables ci-dessous
210
+    // possibiliter de definir cela tables via la meta
211
+    // compatibilite
212
+    if (isset($GLOBALS['meta']['IMPORT_tables_noimport'])) {
213
+        $IMPORT_tables_noimport = unserialize($GLOBALS['meta']['IMPORT_tables_noimport']);
214
+        if (!is_array($IMPORT_tables_noimport)) {
215
+            include_spip('inc/meta');
216
+            effacer_meta('IMPORT_tables_noimport');
217
+        }
218
+    }
219
+    $IMPORT_tables_noimport = pipeline('lister_tables_noimport', $IMPORT_tables_noimport);
220
+
221
+    return $IMPORT_tables_noimport;
222 222
 }
223 223
 
224 224
 
@@ -230,23 +230,23 @@  discard block
 block discarded – undo
230 230
  * @return array
231 231
  */
232 232
 function lister_tables_noerase() {
233
-	static $IMPORT_tables_noerase = null;
234
-	if (!is_null($IMPORT_tables_noerase)) {
235
-		return $IMPORT_tables_noerase;
236
-	}
237
-
238
-	$IMPORT_tables_noerase = array(
239
-		'spip_meta',
240
-		// par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump
241
-		// et le cas echeant, un bouton dans l'admin permet de les vider a la main...
242
-		'spip_referers',
243
-		'spip_referers_articles',
244
-		'spip_visites',
245
-		'spip_visites_articles'
246
-	);
247
-	$IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase);
248
-
249
-	return $IMPORT_tables_noerase;
233
+    static $IMPORT_tables_noerase = null;
234
+    if (!is_null($IMPORT_tables_noerase)) {
235
+        return $IMPORT_tables_noerase;
236
+    }
237
+
238
+    $IMPORT_tables_noerase = array(
239
+        'spip_meta',
240
+        // par defaut on ne vide pas les stats, car elles ne figurent pas dans les dump
241
+        // et le cas echeant, un bouton dans l'admin permet de les vider a la main...
242
+        'spip_referers',
243
+        'spip_referers_articles',
244
+        'spip_visites',
245
+        'spip_visites_articles'
246
+    );
247
+    $IMPORT_tables_noerase = pipeline('lister_tables_noerase', $IMPORT_tables_noerase);
248
+
249
+    return $IMPORT_tables_noerase;
250 250
 }
251 251
 
252 252
 
@@ -260,83 +260,83 @@  discard block
 block discarded – undo
260 260
  * @return array
261 261
  */
262 262
 function base_liste_table_for_dump($exclude_tables = array()) {
263
-	$tables_for_dump = array();
264
-	$tables_pointees = array();
265
-	$tables = array();
266
-	$tables_principales = $GLOBALS['tables_principales'];
267
-	$tables_auxiliaires = $GLOBALS['tables_auxiliaires'];
268
-	$tables_jointures = $GLOBALS['tables_jointures'];
269
-
270
-	if (include_spip('base/objets')
271
-		and function_exists('lister_tables_objets_sql')
272
-	) {
273
-		$tables = lister_tables_objets_sql();
274
-		foreach ($tables as $t => $infos) {
275
-			if ($infos['principale'] and !isset($tables_principales[$t])) {
276
-				$tables_principales[$t] = true;
277
-			}
278
-			if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) {
279
-				$tables_auxiliaires[$t] = true;
280
-			}
281
-			if (count($infos['tables_jointures'])) {
282
-				$tables_jointures[$t] = array_merge(isset($tables_jointures[$t]) ? $tables_jointures[$t] : array(),
283
-					$infos['tables_jointures']);
284
-			}
285
-		}
286
-	}
287
-
288
-	// on construit un index des tables de liens
289
-	// pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees
290
-	$tables_for_link = array();
291
-	foreach ($tables_jointures as $table => $liste_relations) {
292
-		if (is_array($liste_relations)) {
293
-			$nom = $table;
294
-			if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) {
295
-				$nom = "spip_$table";
296
-			}
297
-			if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) {
298
-				foreach ($liste_relations as $link_table) {
299
-					if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) {
300
-						$tables_for_link[$link_table][] = $nom;
301
-					} else {
302
-						if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) {
303
-							$tables_for_link["spip_$link_table"][] = $nom;
304
-						}
305
-					}
306
-				}
307
-			}
308
-		}
309
-	}
310
-
311
-	$liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables));
312
-	foreach ($liste_tables as $table) {
313
-		//		$name = preg_replace("{^spip_}","",$table);
314
-		if (!isset($tables_pointees[$table])
315
-			&& !in_array($table, $exclude_tables)
316
-			&& !isset($tables_for_link[$table])
317
-		) {
318
-			$tables_for_dump[] = $table;
319
-			$tables_pointees[$table] = 1;
320
-		}
321
-	}
322
-	foreach ($tables_for_link as $link_table => $liste) {
323
-		$connecte = true;
324
-		foreach ($liste as $connect_table) {
325
-			if (!in_array($connect_table, $tables_for_dump)) {
326
-				$connecte = false;
327
-			}
328
-		}
329
-		if ($connecte)
330
-			# on ajoute les liaisons en premier
331
-			# si une restauration est interrompue,
332
-			# cela se verra mieux si il manque des objets
333
-			# que des liens
334
-		{
335
-			array_unshift($tables_for_dump, $link_table);
336
-		}
337
-	}
338
-
339
-	return array($tables_for_dump, $tables_for_link);
263
+    $tables_for_dump = array();
264
+    $tables_pointees = array();
265
+    $tables = array();
266
+    $tables_principales = $GLOBALS['tables_principales'];
267
+    $tables_auxiliaires = $GLOBALS['tables_auxiliaires'];
268
+    $tables_jointures = $GLOBALS['tables_jointures'];
269
+
270
+    if (include_spip('base/objets')
271
+        and function_exists('lister_tables_objets_sql')
272
+    ) {
273
+        $tables = lister_tables_objets_sql();
274
+        foreach ($tables as $t => $infos) {
275
+            if ($infos['principale'] and !isset($tables_principales[$t])) {
276
+                $tables_principales[$t] = true;
277
+            }
278
+            if (!$infos['principale'] and !isset($tables_auxiliaires[$t])) {
279
+                $tables_auxiliaires[$t] = true;
280
+            }
281
+            if (count($infos['tables_jointures'])) {
282
+                $tables_jointures[$t] = array_merge(isset($tables_jointures[$t]) ? $tables_jointures[$t] : array(),
283
+                    $infos['tables_jointures']);
284
+            }
285
+        }
286
+    }
287
+
288
+    // on construit un index des tables de liens
289
+    // pour les ajouter SI les deux tables qu'ils connectent sont sauvegardees
290
+    $tables_for_link = array();
291
+    foreach ($tables_jointures as $table => $liste_relations) {
292
+        if (is_array($liste_relations)) {
293
+            $nom = $table;
294
+            if (!isset($tables_auxiliaires[$nom]) && !isset($tables_principales[$nom])) {
295
+                $nom = "spip_$table";
296
+            }
297
+            if (isset($tables_auxiliaires[$nom]) || isset($tables_principales[$nom])) {
298
+                foreach ($liste_relations as $link_table) {
299
+                    if (isset($tables_auxiliaires[$link_table])/*||isset($tables_principales[$link_table])*/) {
300
+                        $tables_for_link[$link_table][] = $nom;
301
+                    } else {
302
+                        if (isset($tables_auxiliaires["spip_$link_table"])/*||isset($tables_principales["spip_$link_table"])*/) {
303
+                            $tables_for_link["spip_$link_table"][] = $nom;
304
+                        }
305
+                    }
306
+                }
307
+            }
308
+        }
309
+    }
310
+
311
+    $liste_tables = array_merge(array_keys($tables_principales), array_keys($tables_auxiliaires), array_keys($tables));
312
+    foreach ($liste_tables as $table) {
313
+        //		$name = preg_replace("{^spip_}","",$table);
314
+        if (!isset($tables_pointees[$table])
315
+            && !in_array($table, $exclude_tables)
316
+            && !isset($tables_for_link[$table])
317
+        ) {
318
+            $tables_for_dump[] = $table;
319
+            $tables_pointees[$table] = 1;
320
+        }
321
+    }
322
+    foreach ($tables_for_link as $link_table => $liste) {
323
+        $connecte = true;
324
+        foreach ($liste as $connect_table) {
325
+            if (!in_array($connect_table, $tables_for_dump)) {
326
+                $connecte = false;
327
+            }
328
+        }
329
+        if ($connecte)
330
+            # on ajoute les liaisons en premier
331
+            # si une restauration est interrompue,
332
+            # cela se verra mieux si il manque des objets
333
+            # que des liens
334
+        {
335
+            array_unshift($tables_for_dump, $link_table);
336
+        }
337
+    }
338
+
339
+    return array($tables_for_dump, $tables_for_link);
340 340
 }
341 341
 
342 342
 /**
@@ -351,34 +351,34 @@  discard block
 block discarded – undo
351 351
  * @param string $serveur
352 352
  */
353 353
 function base_vider_tables_destination_copie($tables, $exclure_tables = array(), $serveur = '') {
354
-	$trouver_table = charger_fonction('trouver_table', 'base');
355
-
356
-	spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables),
357
-		'base.' . _LOG_INFO_IMPORTANTE);
358
-	foreach ($tables as $table) {
359
-		if (!in_array($table, $exclure_tables)) {
360
-			// sur le serveur principal, il ne faut pas supprimer l'auteur loge !
361
-			if (($table != 'spip_auteurs') or $serveur != '') {
362
-				// regarder si il y a au moins un champ impt='non'
363
-				$desc = $trouver_table($table, $serveur);
364
-				if (isset($desc['field']['impt'])) {
365
-					sql_delete($table, "impt='oui'", $serveur);
366
-				} else {
367
-					sql_delete($table, "", $serveur);
368
-				}
369
-			}
370
-		}
371
-	}
372
-
373
-	// sur le serveur principal, il ne faut pas supprimer l'auteur loge !
374
-	// Bidouille pour garder l'acces admin actuel pendant toute la restauration
375
-	if ($serveur == ''
376
-		and in_array('spip_auteurs', $tables)
377
-		and !in_array('spip_auteurs', $exclure_tables)
378
-	) {
379
-		base_conserver_copieur(true, $serveur);
380
-		sql_delete("spip_auteurs", "id_auteur>0", $serveur);
381
-	}
354
+    $trouver_table = charger_fonction('trouver_table', 'base');
355
+
356
+    spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables),
357
+        'base.' . _LOG_INFO_IMPORTANTE);
358
+    foreach ($tables as $table) {
359
+        if (!in_array($table, $exclure_tables)) {
360
+            // sur le serveur principal, il ne faut pas supprimer l'auteur loge !
361
+            if (($table != 'spip_auteurs') or $serveur != '') {
362
+                // regarder si il y a au moins un champ impt='non'
363
+                $desc = $trouver_table($table, $serveur);
364
+                if (isset($desc['field']['impt'])) {
365
+                    sql_delete($table, "impt='oui'", $serveur);
366
+                } else {
367
+                    sql_delete($table, "", $serveur);
368
+                }
369
+            }
370
+        }
371
+    }
372
+
373
+    // sur le serveur principal, il ne faut pas supprimer l'auteur loge !
374
+    // Bidouille pour garder l'acces admin actuel pendant toute la restauration
375
+    if ($serveur == ''
376
+        and in_array('spip_auteurs', $tables)
377
+        and !in_array('spip_auteurs', $exclure_tables)
378
+    ) {
379
+        base_conserver_copieur(true, $serveur);
380
+        sql_delete("spip_auteurs", "id_auteur>0", $serveur);
381
+    }
382 382
 }
383 383
 
384 384
 /**
@@ -389,21 +389,21 @@  discard block
 block discarded – undo
389 389
  * @return void
390 390
  */
391 391
 function base_conserver_copieur($move = true, $serveur = '') {
392
-	// s'asurer qu'on a pas deja fait la manip !
393
-	if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) {
394
-		spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'",
395
-			'dump.' . _LOG_INFO_IMPORTANTE);
396
-		sql_delete("spip_auteurs", "id_auteur<0", $serveur);
397
-		if ($move) {
398
-			sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']),
399
-				"id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur);
400
-		} else {
401
-			$row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '',
402
-				$serveur);
403
-			$row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur'];
404
-			sql_insertq('spip_auteurs', $row, array(), $serveur);
405
-		}
406
-	}
392
+    // s'asurer qu'on a pas deja fait la manip !
393
+    if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) {
394
+        spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'",
395
+            'dump.' . _LOG_INFO_IMPORTANTE);
396
+        sql_delete("spip_auteurs", "id_auteur<0", $serveur);
397
+        if ($move) {
398
+            sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']),
399
+                "id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur);
400
+        } else {
401
+            $row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '',
402
+                $serveur);
403
+            $row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur'];
404
+            sql_insertq('spip_auteurs', $row, array(), $serveur);
405
+        }
406
+    }
407 407
 }
408 408
 
409 409
 /**
@@ -418,19 +418,19 @@  discard block
 block discarded – undo
418 418
  * @param string $serveur
419 419
  */
420 420
 function base_detruire_copieur_si_besoin($serveur = '') {
421
-	// rien a faire si ce n'est pas le serveur principal !
422
-	if ($serveur == '') {
423
-		if (sql_countsel("spip_auteurs", "id_auteur>0")) {
424
-			spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
425
-			sql_delete("spip_auteurs", "id_auteur<0", $serveur);
426
-		} else {
427
-			spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)",
428
-				'dump.' . _LOG_INFO_IMPORTANTE);
429
-			sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0");
430
-		}
431
-	} else {
432
-		spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
433
-	}
421
+    // rien a faire si ce n'est pas le serveur principal !
422
+    if ($serveur == '') {
423
+        if (sql_countsel("spip_auteurs", "id_auteur>0")) {
424
+            spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
425
+            sql_delete("spip_auteurs", "id_auteur<0", $serveur);
426
+        } else {
427
+            spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)",
428
+                'dump.' . _LOG_INFO_IMPORTANTE);
429
+            sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0");
430
+        }
431
+    } else {
432
+        spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
433
+    }
434 434
 }
435 435
 
436 436
 /**
@@ -445,40 +445,40 @@  discard block
 block discarded – undo
445 445
  * @return array
446 446
  */
447 447
 function base_preparer_table_dest($table, $desc, $serveur_dest, $init = false) {
448
-	$upgrade = false;
449
-	// si la table existe et qu'on est a l'init, la dropper
450
-	if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) {
451
-		if ($serveur_dest == '' and in_array($table, array('spip_meta', 'spip_auteurs'))) {
452
-			// ne pas dropper auteurs et meta sur le serveur principal
453
-			// faire un simple upgrade a la place
454
-			// pour ajouter les champs manquants
455
-			$upgrade = true;
456
-			// coherence avec le drop sur les autres tables
457
-			base_vider_tables_destination_copie(array($table), array(), $serveur_dest);
458
-			if ($table == 'spip_meta') {
459
-				// virer les version base qui vont venir avec l'import
460
-				sql_delete($table, "nom like '%_base_version'", $serveur_dest);
461
-				// hum casse la base si pas version_installee a l'import ...
462
-				sql_delete($table, "nom='version_installee'", $serveur_dest);
463
-			}
464
-		} else {
465
-			sql_drop_table($table, '', $serveur_dest);
466
-			spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
467
-		}
468
-		$desc_dest = false;
469
-	}
470
-	// si la table n'existe pas dans la destination, la creer a l'identique !
471
-	if (!$desc_dest) {
472
-		spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
473
-		include_spip('base/create');
474
-		creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest);
475
-		$desc_dest = sql_showtable($table, true, $serveur_dest);
476
-	}
477
-	if (!$desc_dest) {
478
-		spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR);
479
-	}
480
-
481
-	return $desc_dest;
448
+    $upgrade = false;
449
+    // si la table existe et qu'on est a l'init, la dropper
450
+    if ($desc_dest = sql_showtable($table, true, $serveur_dest) and $init) {
451
+        if ($serveur_dest == '' and in_array($table, array('spip_meta', 'spip_auteurs'))) {
452
+            // ne pas dropper auteurs et meta sur le serveur principal
453
+            // faire un simple upgrade a la place
454
+            // pour ajouter les champs manquants
455
+            $upgrade = true;
456
+            // coherence avec le drop sur les autres tables
457
+            base_vider_tables_destination_copie(array($table), array(), $serveur_dest);
458
+            if ($table == 'spip_meta') {
459
+                // virer les version base qui vont venir avec l'import
460
+                sql_delete($table, "nom like '%_base_version'", $serveur_dest);
461
+                // hum casse la base si pas version_installee a l'import ...
462
+                sql_delete($table, "nom='version_installee'", $serveur_dest);
463
+            }
464
+        } else {
465
+            sql_drop_table($table, '', $serveur_dest);
466
+            spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
467
+        }
468
+        $desc_dest = false;
469
+    }
470
+    // si la table n'existe pas dans la destination, la creer a l'identique !
471
+    if (!$desc_dest) {
472
+        spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
473
+        include_spip('base/create');
474
+        creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest);
475
+        $desc_dest = sql_showtable($table, true, $serveur_dest);
476
+    }
477
+    if (!$desc_dest) {
478
+        spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR);
479
+    }
480
+
481
+    return $desc_dest;
482 482
 }
483 483
 
484 484
 /**
@@ -524,186 +524,186 @@  discard block
 block discarded – undo
524 524
  */
525 525
 function base_copier_tables($status_file, $tables, $serveur_source, $serveur_dest, $options = array()) {
526 526
 
527
-	$callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : '';
528
-	$max_time = isset($options['max_time']) ? $options['max_time'] : 0;
529
-	$drop_source = isset($options['drop_source']) ? $options['drop_source'] : false;
530
-	$no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : array();
531
-	$where = isset($options['where']) ? $options['where'] : array();
532
-	$fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie';
533
-	$desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : array();
534
-	$racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base');
535
-	$data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024);
536
-
537
-	spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'",
538
-		'dump.' . _LOG_INFO_IMPORTANTE);
539
-
540
-	if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) {
541
-		spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
542
-
543
-		return true; // echec mais on a fini, donc true
544
-	}
545
-	if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) {
546
-		spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
547
-
548
-		return true; // echec mais on a fini, donc true
549
-	}
550
-
551
-	if (!lire_fichier($status_file, $status)
552
-		or !$status = unserialize($status)
553
-	) {
554
-		$status = array();
555
-	}
556
-	$status['etape'] = 'basecopie';
557
-
558
-	// puis relister les tables a importer
559
-	// et les vider si besoin, au moment du premier passage ici
560
-	$initialisation_copie = (!isset($status["dump_status_copie"])) ? 0 : $status["dump_status_copie"];
561
-
562
-	// si init pas encore faite, vider les tables du serveur destination
563
-	if (!$initialisation_copie) {
564
-		if (!$vider_tables_destination_copie = charger_fonction('vider_tables_destination_copie', $racine_fonctions,
565
-			true)
566
-		) {
567
-			spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon",
568
-				'dump.' . _LOG_INFO_IMPORTANTE);
569
-
570
-			return true; // echec mais on a fini, donc true
571
-		}
572
-		$vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest);
573
-		$status["dump_status_copie"] = 'ok';
574
-		ecrire_fichier($status_file, serialize($status));
575
-	}
576
-
577
-	// les tables auteurs et meta doivent etre copiees en dernier !
578
-	if (in_array('spip_auteurs', $tables)) {
579
-		$tables = array_diff($tables, array('spip_auteurs'));
580
-		$tables[] = 'spip_auteurs';
581
-	}
582
-	if (in_array('spip_meta', $tables)) {
583
-		$tables = array_diff($tables, array('spip_meta'));
584
-		$tables[] = 'spip_meta';
585
-	}
586
-	spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO);
587
-
588
-	$trouver_table = charger_fonction('trouver_table', 'base');
589
-
590
-	foreach ($tables as $table) {
591
-		// si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin
592
-		// sinon chercher la vraie table
593
-		$desc_source = false;
594
-		if (strncmp($table, "spip_", 5) == 0) {
595
-			$desc_source = $trouver_table(preg_replace(",^spip_,", "", $table), $serveur_source, true);
596
-		}
597
-		if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) {
598
-			$desc_source = $trouver_table($table, $serveur_source, false);
599
-		}
600
-
601
-		// verifier que la table est presente dans la base source
602
-		if ($desc_source) {
603
-			// $status['tables_copiees'][$table] contient l'avancement
604
-			// de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...)
605
-			if (!isset($status['tables_copiees'][$table])) {
606
-				$status['tables_copiees'][$table] = 0;
607
-			}
608
-
609
-			if (is_numeric($status['tables_copiees'][$table])
610
-				and $status['tables_copiees'][$table] >= 0
611
-				and $desc_dest = $preparer_table_dest(
612
-					$table,
613
-					isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source,
614
-					$serveur_dest,
615
-					$status['tables_copiees'][$table] == 0)
616
-			) {
617
-				if ($callback_progression) {
618
-					$callback_progression($status['tables_copiees'][$table], 0, $table);
619
-				}
620
-				while (true) {
621
-					$n = intval($status['tables_copiees'][$table]);
622
-					// on copie par lot de 400
623
-					$res = sql_select('*', $table, isset($where[$table]) ? $where[$table] : '', '', '', "$n,400", '',
624
-						$serveur_source);
625
-					while ($row = sql_fetch($res, $serveur_source)) {
626
-						$rows = array($row);
627
-						// lire un groupe de donnees si demande en option
628
-						// (permet un envoi par lot vers la destination)
629
-						if ($data_pool > 0) {
630
-							$s = strlen(serialize($row));
631
-							while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) {
632
-								$s += strlen(serialize($row));
633
-								$rows[] = $row;
634
-							}
635
-						}
636
-						// si l'enregistrement est deja en base, ca fera un echec ou un doublon
637
-						// mais si ca renvoie false c'est une erreur fatale => abandon
638
-						if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) {
639
-							// forcer la sortie, charge a l'appelant de gerer l'echec
640
-							spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR);
641
-							$status['errors'][] = "Erreur fatale  lors de la copie de la table $table";
642
-							ecrire_fichier($status_file, serialize($status));
643
-
644
-							// copie finie
645
-							return true;
646
-						}
647
-						$status['tables_copiees'][$table] += count($rows);
648
-						if ($max_time and time() > $max_time) {
649
-							break;
650
-						}
651
-					}
652
-					if ($n == $status['tables_copiees'][$table]) {
653
-						break;
654
-					}
655
-					spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE);
656
-					if ($callback_progression) {
657
-						$callback_progression($status['tables_copiees'][$table], 0, $table);
658
-					}
659
-					ecrire_fichier($status_file, serialize($status));
660
-					if ($max_time and time() > $max_time) {
661
-						return false;
662
-					} // on a pas fini, mais le temps imparti est ecoule
663
-				}
664
-				if ($drop_source) {
665
-					sql_drop_table($table, '', $serveur_source);
666
-					spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE);
667
-				}
668
-				$status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero");
669
-				ecrire_fichier($status_file, serialize($status));
670
-				spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO);
671
-				if ($callback_progression) {
672
-					$callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table);
673
-				}
674
-			} else {
675
-				if ($status['tables_copiees'][$table] < 0) {
676
-					spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO);
677
-				}
678
-				if ($callback_progression) {
679
-					$callback_progression(0, $status['tables_copiees'][$table],
680
-						"$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : ""));
681
-				}
682
-			}
683
-		} else {
684
-			$status['errors'][] = "Impossible de lire la description de la table $table";
685
-			ecrire_fichier($status_file, serialize($status));
686
-			spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR);
687
-		}
688
-	}
689
-
690
-	// si le nombre de tables envoyees n'est pas egal au nombre de tables demandees
691
-	// abandonner
692
-	if (count($status['tables_copiees']) < count($tables)) {
693
-		spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables),
694
-			"dump." . _LOG_ERREUR);
695
-		$status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables);
696
-		ecrire_fichier($status_file, serialize($status));
697
-	}
698
-
699
-	if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) {
700
-		$detruire_copieur_si_besoin($serveur_dest);
701
-	} else {
702
-		spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE);
703
-	}
704
-
705
-	// OK, copie complete
706
-	return true;
527
+    $callback_progression = isset($options['callback_progression']) ? $options['callback_progression'] : '';
528
+    $max_time = isset($options['max_time']) ? $options['max_time'] : 0;
529
+    $drop_source = isset($options['drop_source']) ? $options['drop_source'] : false;
530
+    $no_erase_dest = isset($options['no_erase_dest']) ? $options['no_erase_dest'] : array();
531
+    $where = isset($options['where']) ? $options['where'] : array();
532
+    $fonction_base_inserer = isset($options['fonction_base_inserer']) ? $options['fonction_base_inserer'] : 'inserer_copie';
533
+    $desc_tables_dest = isset($options['desc_tables_dest']) ? $options['desc_tables_dest'] : array();
534
+    $racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base');
535
+    $data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024);
536
+
537
+    spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'",
538
+        'dump.' . _LOG_INFO_IMPORTANTE);
539
+
540
+    if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) {
541
+        spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
542
+
543
+        return true; // echec mais on a fini, donc true
544
+    }
545
+    if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) {
546
+        spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
547
+
548
+        return true; // echec mais on a fini, donc true
549
+    }
550
+
551
+    if (!lire_fichier($status_file, $status)
552
+        or !$status = unserialize($status)
553
+    ) {
554
+        $status = array();
555
+    }
556
+    $status['etape'] = 'basecopie';
557
+
558
+    // puis relister les tables a importer
559
+    // et les vider si besoin, au moment du premier passage ici
560
+    $initialisation_copie = (!isset($status["dump_status_copie"])) ? 0 : $status["dump_status_copie"];
561
+
562
+    // si init pas encore faite, vider les tables du serveur destination
563
+    if (!$initialisation_copie) {
564
+        if (!$vider_tables_destination_copie = charger_fonction('vider_tables_destination_copie', $racine_fonctions,
565
+            true)
566
+        ) {
567
+            spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon",
568
+                'dump.' . _LOG_INFO_IMPORTANTE);
569
+
570
+            return true; // echec mais on a fini, donc true
571
+        }
572
+        $vider_tables_destination_copie($tables, $no_erase_dest, $serveur_dest);
573
+        $status["dump_status_copie"] = 'ok';
574
+        ecrire_fichier($status_file, serialize($status));
575
+    }
576
+
577
+    // les tables auteurs et meta doivent etre copiees en dernier !
578
+    if (in_array('spip_auteurs', $tables)) {
579
+        $tables = array_diff($tables, array('spip_auteurs'));
580
+        $tables[] = 'spip_auteurs';
581
+    }
582
+    if (in_array('spip_meta', $tables)) {
583
+        $tables = array_diff($tables, array('spip_meta'));
584
+        $tables[] = 'spip_meta';
585
+    }
586
+    spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO);
587
+
588
+    $trouver_table = charger_fonction('trouver_table', 'base');
589
+
590
+    foreach ($tables as $table) {
591
+        // si table commence par spip_ c'est une table SPIP, renommer le prefixe si besoin
592
+        // sinon chercher la vraie table
593
+        $desc_source = false;
594
+        if (strncmp($table, "spip_", 5) == 0) {
595
+            $desc_source = $trouver_table(preg_replace(",^spip_,", "", $table), $serveur_source, true);
596
+        }
597
+        if (!$desc_source or !isset($desc_source['exist']) or !$desc_source['exist']) {
598
+            $desc_source = $trouver_table($table, $serveur_source, false);
599
+        }
600
+
601
+        // verifier que la table est presente dans la base source
602
+        if ($desc_source) {
603
+            // $status['tables_copiees'][$table] contient l'avancement
604
+            // de la copie pour la $table : 0 a N et -N quand elle est finie (-1 si vide et finie...)
605
+            if (!isset($status['tables_copiees'][$table])) {
606
+                $status['tables_copiees'][$table] = 0;
607
+            }
608
+
609
+            if (is_numeric($status['tables_copiees'][$table])
610
+                and $status['tables_copiees'][$table] >= 0
611
+                and $desc_dest = $preparer_table_dest(
612
+                    $table,
613
+                    isset($desc_tables_dest[$table]) ? $desc_tables_dest[$table] : $desc_source,
614
+                    $serveur_dest,
615
+                    $status['tables_copiees'][$table] == 0)
616
+            ) {
617
+                if ($callback_progression) {
618
+                    $callback_progression($status['tables_copiees'][$table], 0, $table);
619
+                }
620
+                while (true) {
621
+                    $n = intval($status['tables_copiees'][$table]);
622
+                    // on copie par lot de 400
623
+                    $res = sql_select('*', $table, isset($where[$table]) ? $where[$table] : '', '', '', "$n,400", '',
624
+                        $serveur_source);
625
+                    while ($row = sql_fetch($res, $serveur_source)) {
626
+                        $rows = array($row);
627
+                        // lire un groupe de donnees si demande en option
628
+                        // (permet un envoi par lot vers la destination)
629
+                        if ($data_pool > 0) {
630
+                            $s = strlen(serialize($row));
631
+                            while ($s < $data_pool and $row = sql_fetch($res, $serveur_source)) {
632
+                                $s += strlen(serialize($row));
633
+                                $rows[] = $row;
634
+                            }
635
+                        }
636
+                        // si l'enregistrement est deja en base, ca fera un echec ou un doublon
637
+                        // mais si ca renvoie false c'est une erreur fatale => abandon
638
+                        if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) {
639
+                            // forcer la sortie, charge a l'appelant de gerer l'echec
640
+                            spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR);
641
+                            $status['errors'][] = "Erreur fatale  lors de la copie de la table $table";
642
+                            ecrire_fichier($status_file, serialize($status));
643
+
644
+                            // copie finie
645
+                            return true;
646
+                        }
647
+                        $status['tables_copiees'][$table] += count($rows);
648
+                        if ($max_time and time() > $max_time) {
649
+                            break;
650
+                        }
651
+                    }
652
+                    if ($n == $status['tables_copiees'][$table]) {
653
+                        break;
654
+                    }
655
+                    spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE);
656
+                    if ($callback_progression) {
657
+                        $callback_progression($status['tables_copiees'][$table], 0, $table);
658
+                    }
659
+                    ecrire_fichier($status_file, serialize($status));
660
+                    if ($max_time and time() > $max_time) {
661
+                        return false;
662
+                    } // on a pas fini, mais le temps imparti est ecoule
663
+                }
664
+                if ($drop_source) {
665
+                    sql_drop_table($table, '', $serveur_source);
666
+                    spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE);
667
+                }
668
+                $status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero");
669
+                ecrire_fichier($status_file, serialize($status));
670
+                spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO);
671
+                if ($callback_progression) {
672
+                    $callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table);
673
+                }
674
+            } else {
675
+                if ($status['tables_copiees'][$table] < 0) {
676
+                    spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO);
677
+                }
678
+                if ($callback_progression) {
679
+                    $callback_progression(0, $status['tables_copiees'][$table],
680
+                        "$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : ""));
681
+                }
682
+            }
683
+        } else {
684
+            $status['errors'][] = "Impossible de lire la description de la table $table";
685
+            ecrire_fichier($status_file, serialize($status));
686
+            spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR);
687
+        }
688
+    }
689
+
690
+    // si le nombre de tables envoyees n'est pas egal au nombre de tables demandees
691
+    // abandonner
692
+    if (count($status['tables_copiees']) < count($tables)) {
693
+        spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables),
694
+            "dump." . _LOG_ERREUR);
695
+        $status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables);
696
+        ecrire_fichier($status_file, serialize($status));
697
+    }
698
+
699
+    if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) {
700
+        $detruire_copieur_si_besoin($serveur_dest);
701
+    } else {
702
+        spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE);
703
+    }
704
+
705
+    // OK, copie complete
706
+    return true;
707 707
 }
708 708
 
709 709
 /**
@@ -717,27 +717,27 @@  discard block
 block discarded – undo
717 717
  */
718 718
 function base_inserer_copie($table, $rows, $desc_dest, $serveur_dest) {
719 719
 
720
-	// verifier le nombre d'insertion
721
-	$nb1 = sql_countsel($table, '', '', '', $serveur_dest);
722
-	// si l'enregistrement est deja en base, ca fera un echec ou un doublon
723
-	$r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest);
724
-	$nb = sql_countsel($table, '', '', '', $serveur_dest);
725
-	if ($nb - $nb1 < count($rows)) {
726
-		spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1",
727
-			"dump" . _LOG_INFO_IMPORTANTE);
728
-		foreach ($rows as $row) {
729
-			// si l'enregistrement est deja en base, ca fera un echec ou un doublon
730
-			$r = sql_insertq($table, $row, $desc_dest, $serveur_dest);
731
-		}
732
-		// on reverifie le total
733
-		$r = 0;
734
-		$nb = sql_countsel($table, '', '', '', $serveur_dest);
735
-		if ($nb - $nb1 < count($rows)) {
736
-			spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1",
737
-				"dump" . _LOG_ERREUR);
738
-			$r = false;
739
-		}
740
-	}
741
-
742
-	return $r;
720
+    // verifier le nombre d'insertion
721
+    $nb1 = sql_countsel($table, '', '', '', $serveur_dest);
722
+    // si l'enregistrement est deja en base, ca fera un echec ou un doublon
723
+    $r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest);
724
+    $nb = sql_countsel($table, '', '', '', $serveur_dest);
725
+    if ($nb - $nb1 < count($rows)) {
726
+        spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1",
727
+            "dump" . _LOG_INFO_IMPORTANTE);
728
+        foreach ($rows as $row) {
729
+            // si l'enregistrement est deja en base, ca fera un echec ou un doublon
730
+            $r = sql_insertq($table, $row, $desc_dest, $serveur_dest);
731
+        }
732
+        // on reverifie le total
733
+        $r = 0;
734
+        $nb = sql_countsel($table, '', '', '', $serveur_dest);
735
+        if ($nb - $nb1 < count($rows)) {
736
+            spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1",
737
+                "dump" . _LOG_ERREUR);
738
+            $r = false;
739
+        }
740
+    }
741
+
742
+    return $r;
743 743
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 // donc il faut l'inclure "en globals"
31 31
 if ($f = find_in_path('mes_fonctions.php')) {
32 32
 	global $dossier_squelettes;
33
-	@include_once(_ROOT_CWD . $f);
33
+	@include_once(_ROOT_CWD.$f);
34 34
 }
35 35
 
36 36
 if (@is_readable(_CACHE_PLUGINS_FCT)) {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  * @return string
49 49
  **/
50 50
 function base_dump_meta_name($rub) {
51
-	return $meta = "status_dump_{$rub}_" . abs($GLOBALS['visiteur_session']['id_auteur']);
51
+	return $meta = "status_dump_{$rub}_".abs($GLOBALS['visiteur_session']['id_auteur']);
52 52
 }
53 53
 
54 54
 /**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
95 95
 	$prefixe = $connexion['prefixe'];
96 96
 
97
-	$p = '/^' . $prefixe . '/';
97
+	$p = '/^'.$prefixe.'/';
98 98
 	$res = $tables;
99 99
 	foreach (sql_alltable(null, $serveur) as $t) {
100 100
 		if (preg_match($p, $t)) {
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 function base_vider_tables_destination_copie($tables, $exclure_tables = array(), $serveur = '') {
354 354
 	$trouver_table = charger_fonction('trouver_table', 'base');
355 355
 
356
-	spip_log('Vider ' . count($tables) . " tables sur serveur '$serveur' : " . join(', ', $tables),
357
-		'base.' . _LOG_INFO_IMPORTANTE);
356
+	spip_log('Vider '.count($tables)." tables sur serveur '$serveur' : ".join(', ', $tables),
357
+		'base.'._LOG_INFO_IMPORTANTE);
358 358
 	foreach ($tables as $table) {
359 359
 		if (!in_array($table, $exclure_tables)) {
360 360
 			// sur le serveur principal, il ne faut pas supprimer l'auteur loge !
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 function base_conserver_copieur($move = true, $serveur = '') {
392 392
 	// s'asurer qu'on a pas deja fait la manip !
393 393
 	if ($GLOBALS['visiteur_session']['id_auteur'] > 0 and sql_countsel("spip_auteurs", "id_auteur>0")) {
394
-		spip_log('Conserver copieur dans id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'] . " pour le serveur '$serveur'",
395
-			'dump.' . _LOG_INFO_IMPORTANTE);
394
+		spip_log('Conserver copieur dans id_auteur='.$GLOBALS['visiteur_session']['id_auteur']." pour le serveur '$serveur'",
395
+			'dump.'._LOG_INFO_IMPORTANTE);
396 396
 		sql_delete("spip_auteurs", "id_auteur<0", $serveur);
397 397
 		if ($move) {
398 398
 			sql_updateq('spip_auteurs', array('id_auteur' => -$GLOBALS['visiteur_session']['id_auteur']),
399
-				"id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur);
399
+				"id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur']), array(), $serveur);
400 400
 		} else {
401
-			$row = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $GLOBALS['visiteur_session']['id_auteur'], '', '', '', '',
401
+			$row = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$GLOBALS['visiteur_session']['id_auteur'], '', '', '', '',
402 402
 				$serveur);
403 403
 			$row['id_auteur'] = -$GLOBALS['visiteur_session']['id_auteur'];
404 404
 			sql_insertq('spip_auteurs', $row, array(), $serveur);
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 	// rien a faire si ce n'est pas le serveur principal !
422 422
 	if ($serveur == '') {
423 423
 		if (sql_countsel("spip_auteurs", "id_auteur>0")) {
424
-			spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
424
+			spip_log("Detruire copieur id_auteur<0 pour le serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE);
425 425
 			sql_delete("spip_auteurs", "id_auteur<0", $serveur);
426 426
 		} else {
427 427
 			spip_log("Restaurer copieur id_auteur<0 pour le serveur '$serveur' (aucun autre auteur en base)",
428
-				'dump.' . _LOG_INFO_IMPORTANTE);
428
+				'dump.'._LOG_INFO_IMPORTANTE);
429 429
 			sql_update('spip_auteurs', array('id_auteur' => '-id_auteur'), "id_auteur<0");
430 430
 		}
431 431
 	} else {
432
-		spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.' . _LOG_INFO_IMPORTANTE);
432
+		spip_log("Pas de destruction copieur sur serveur '$serveur'", 'dump.'._LOG_INFO_IMPORTANTE);
433 433
 	}
434 434
 }
435 435
 
@@ -463,19 +463,19 @@  discard block
 block discarded – undo
463 463
 			}
464 464
 		} else {
465 465
 			sql_drop_table($table, '', $serveur_dest);
466
-			spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
466
+			spip_log("drop table '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE);
467 467
 		}
468 468
 		$desc_dest = false;
469 469
 	}
470 470
 	// si la table n'existe pas dans la destination, la creer a l'identique !
471 471
 	if (!$desc_dest) {
472
-		spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.' . _LOG_INFO_IMPORTANTE);
472
+		spip_log("creation '$table' sur serveur '$serveur_dest'", 'dump.'._LOG_INFO_IMPORTANTE);
473 473
 		include_spip('base/create');
474 474
 		creer_ou_upgrader_table($table, $desc, 'auto', $upgrade, $serveur_dest);
475 475
 		$desc_dest = sql_showtable($table, true, $serveur_dest);
476 476
 	}
477 477
 	if (!$desc_dest) {
478
-		spip_log("Erreur creation '$table' sur serveur '$serveur_dest'" . var_export($desc, 1), 'dump.' . _LOG_ERREUR);
478
+		spip_log("Erreur creation '$table' sur serveur '$serveur_dest'".var_export($desc, 1), 'dump.'._LOG_ERREUR);
479 479
 	}
480 480
 
481 481
 	return $desc_dest;
@@ -534,16 +534,16 @@  discard block
 block discarded – undo
534 534
 	$racine_fonctions = (isset($options['racine_fonctions_dest']) ? $options['racine_fonctions_dest'] : 'base');
535 535
 	$data_pool = (isset($options['data_pool']) ? $options['data_pool'] : 50 * 1024);
536 536
 
537
-	spip_log("Copier " . count($tables) . " tables de '$serveur_source' vers '$serveur_dest'",
538
-		'dump.' . _LOG_INFO_IMPORTANTE);
537
+	spip_log("Copier ".count($tables)." tables de '$serveur_source' vers '$serveur_dest'",
538
+		'dump.'._LOG_INFO_IMPORTANTE);
539 539
 
540 540
 	if (!$inserer_copie = charger_fonction($fonction_base_inserer, $racine_fonctions, true)) {
541
-		spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
541
+		spip_log("Fonction '{$racine_fonctions}_$fonction_base_inserer' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE);
542 542
 
543 543
 		return true; // echec mais on a fini, donc true
544 544
 	}
545 545
 	if (!$preparer_table_dest = charger_fonction('preparer_table_dest', $racine_fonctions, true)) {
546
-		spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.' . _LOG_INFO_IMPORTANTE);
546
+		spip_log("Fonction '{$racine_fonctions}_$preparer_table_dest' inconnue. Abandon", 'dump.'._LOG_INFO_IMPORTANTE);
547 547
 
548 548
 		return true; // echec mais on a fini, donc true
549 549
 	}
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 			true)
566 566
 		) {
567 567
 			spip_log("Fonction '{$racine_fonctions}_vider_tables_destination_copie' inconnue. Abandon",
568
-				'dump.' . _LOG_INFO_IMPORTANTE);
568
+				'dump.'._LOG_INFO_IMPORTANTE);
569 569
 
570 570
 			return true; // echec mais on a fini, donc true
571 571
 		}
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		$tables = array_diff($tables, array('spip_meta'));
584 584
 		$tables[] = 'spip_meta';
585 585
 	}
586
-	spip_log("Tables a copier :" . implode(", ", $tables), 'dump.' . _LOG_INFO);
586
+	spip_log("Tables a copier :".implode(", ", $tables), 'dump.'._LOG_INFO);
587 587
 
588 588
 	$trouver_table = charger_fonction('trouver_table', 'base');
589 589
 
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 						// mais si ca renvoie false c'est une erreur fatale => abandon
638 638
 						if ($inserer_copie($table, $rows, $desc_dest, $serveur_dest) === false) {
639 639
 							// forcer la sortie, charge a l'appelant de gerer l'echec
640
-							spip_log("Erreur fatale dans $inserer_copie table $table", "dump" . _LOG_ERREUR);
640
+							spip_log("Erreur fatale dans $inserer_copie table $table", "dump"._LOG_ERREUR);
641 641
 							$status['errors'][] = "Erreur fatale  lors de la copie de la table $table";
642 642
 							ecrire_fichier($status_file, serialize($status));
643 643
 
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 					if ($n == $status['tables_copiees'][$table]) {
653 653
 						break;
654 654
 					}
655
-					spip_log("recopie $table " . $status['tables_copiees'][$table], 'dump.' . _LOG_INFO_IMPORTANTE);
655
+					spip_log("recopie $table ".$status['tables_copiees'][$table], 'dump.'._LOG_INFO_IMPORTANTE);
656 656
 					if ($callback_progression) {
657 657
 						$callback_progression($status['tables_copiees'][$table], 0, $table);
658 658
 					}
@@ -663,43 +663,43 @@  discard block
 block discarded – undo
663 663
 				}
664 664
 				if ($drop_source) {
665 665
 					sql_drop_table($table, '', $serveur_source);
666
-					spip_log("drop $table sur serveur source '$serveur_source'", 'dump.' . _LOG_INFO_IMPORTANTE);
666
+					spip_log("drop $table sur serveur source '$serveur_source'", 'dump.'._LOG_INFO_IMPORTANTE);
667 667
 				}
668 668
 				$status['tables_copiees'][$table] = ($status['tables_copiees'][$table] ? -$status['tables_copiees'][$table] : "zero");
669 669
 				ecrire_fichier($status_file, serialize($status));
670
-				spip_log("tables_recopiees " . implode(',', array_keys($status['tables_copiees'])), 'dump.' . _LOG_INFO);
670
+				spip_log("tables_recopiees ".implode(',', array_keys($status['tables_copiees'])), 'dump.'._LOG_INFO);
671 671
 				if ($callback_progression) {
672 672
 					$callback_progression($status['tables_copiees'][$table], $status['tables_copiees'][$table], $table);
673 673
 				}
674 674
 			} else {
675 675
 				if ($status['tables_copiees'][$table] < 0) {
676
-					spip_log("Table $table deja copiee : " . $status['tables_copiees'][$table], "dump." . _LOG_INFO);
676
+					spip_log("Table $table deja copiee : ".$status['tables_copiees'][$table], "dump."._LOG_INFO);
677 677
 				}
678 678
 				if ($callback_progression) {
679 679
 					$callback_progression(0, $status['tables_copiees'][$table],
680
-						"$table" . ((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : ""));
680
+						"$table".((is_numeric($status['tables_copiees'][$table]) and $status['tables_copiees'][$table] >= 0) ? "[Echec]" : ""));
681 681
 				}
682 682
 			}
683 683
 		} else {
684 684
 			$status['errors'][] = "Impossible de lire la description de la table $table";
685 685
 			ecrire_fichier($status_file, serialize($status));
686
-			spip_log("Impossible de lire la description de la table $table", "dump." . _LOG_ERREUR);
686
+			spip_log("Impossible de lire la description de la table $table", "dump."._LOG_ERREUR);
687 687
 		}
688 688
 	}
689 689
 
690 690
 	// si le nombre de tables envoyees n'est pas egal au nombre de tables demandees
691 691
 	// abandonner
692 692
 	if (count($status['tables_copiees']) < count($tables)) {
693
-		spip_log("Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables),
694
-			"dump." . _LOG_ERREUR);
695
-		$status['errors'][] = "Nombre de tables copiees incorrect : " . count($status['tables_copiees']) . "/" . count($tables);
693
+		spip_log("Nombre de tables copiees incorrect : ".count($status['tables_copiees'])."/".count($tables),
694
+			"dump."._LOG_ERREUR);
695
+		$status['errors'][] = "Nombre de tables copiees incorrect : ".count($status['tables_copiees'])."/".count($tables);
696 696
 		ecrire_fichier($status_file, serialize($status));
697 697
 	}
698 698
 
699 699
 	if ($detruire_copieur_si_besoin = charger_fonction('detruire_copieur_si_besoin', $racine_fonctions, true)) {
700 700
 		$detruire_copieur_si_besoin($serveur_dest);
701 701
 	} else {
702
-		spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.' . _LOG_INFO_IMPORTANTE);
702
+		spip_log("Fonction '{$racine_fonctions}_detruire_copieur_si_besoin' inconnue.", 'dump.'._LOG_INFO_IMPORTANTE);
703 703
 	}
704 704
 
705 705
 	// OK, copie complete
@@ -723,8 +723,8 @@  discard block
 block discarded – undo
723 723
 	$r = sql_insertq_multi($table, $rows, $desc_dest, $serveur_dest);
724 724
 	$nb = sql_countsel($table, '', '', '', $serveur_dest);
725 725
 	if ($nb - $nb1 < count($rows)) {
726
-		spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . ". On retente 1 par 1",
727
-			"dump" . _LOG_INFO_IMPORTANTE);
726
+		spip_log("base_inserer_copie : ".($nb - $nb1)." insertions au lieu de ".count($rows).". On retente 1 par 1",
727
+			"dump"._LOG_INFO_IMPORTANTE);
728 728
 		foreach ($rows as $row) {
729 729
 			// si l'enregistrement est deja en base, ca fera un echec ou un doublon
730 730
 			$r = sql_insertq($table, $row, $desc_dest, $serveur_dest);
@@ -733,8 +733,8 @@  discard block
 block discarded – undo
733 733
 		$r = 0;
734 734
 		$nb = sql_countsel($table, '', '', '', $serveur_dest);
735 735
 		if ($nb - $nb1 < count($rows)) {
736
-			spip_log("base_inserer_copie : " . ($nb - $nb1) . " insertions au lieu de " . count($rows) . " apres insertion 1 par 1",
737
-				"dump" . _LOG_ERREUR);
736
+			spip_log("base_inserer_copie : ".($nb - $nb1)." insertions au lieu de ".count($rows)." apres insertion 1 par 1",
737
+				"dump"._LOG_ERREUR);
738 738
 			$r = false;
739 739
 		}
740 740
 	}
Please login to merge, or discard this patch.
ecrire/inc/cookie.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
  *     Chemin sur lequel le cookie sera disponible
36 36
  * @param string $domain
37 37
  *     Domaine à partir duquel le cookie est disponible
38
- * @param bool $secure
38
+ * @param string|boolean $secure
39 39
  *     cookie sécurisé ou non ?
40 40
  * @return bool
41 41
  *     true si le cookie a été posé, false sinon.
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
  *     true si le cookie a été posé, false sinon.
44 44
  **/
45 45
 function spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') {
46
-	// liste des cookies en httponly (a passer en define si besoin)
47
-	$httponly = in_array($name, explode(' ', 'spip_session'));
48
-
49
-	$name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name);
50
-	if ($path == 'AUTO') {
51
-		$path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base());
52
-	}
53
-	if (!$domain and defined('_COOKIE_DOMAIN')) {
54
-		$domain = _COOKIE_DOMAIN;
55
-	}
56
-
57
-	#spip_log("cookie('$name', '$value', '$expire', '$path', '$domain', '$secure', '$httponly'");
58
-
59
-	$a =
60
-		$httponly ?
61
-			@setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
62
-			: ($secure ?
63
-			@setcookie($name, $value, $expire, $path, $domain, $secure)
64
-			: ($domain ?
65
-				@setcookie($name, $value, $expire, $path, $domain)
66
-				: ($path ?
67
-					@setcookie($name, $value, $expire, $path)
68
-					: ($expire ?
69
-						@setcookie($name, $value, $expire)
70
-						:
71
-						@setcookie($name, $value)
72
-					))));
73
-
74
-	spip_cookie_envoye(true);
75
-
76
-	return $a;
46
+    // liste des cookies en httponly (a passer en define si besoin)
47
+    $httponly = in_array($name, explode(' ', 'spip_session'));
48
+
49
+    $name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name);
50
+    if ($path == 'AUTO') {
51
+        $path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base());
52
+    }
53
+    if (!$domain and defined('_COOKIE_DOMAIN')) {
54
+        $domain = _COOKIE_DOMAIN;
55
+    }
56
+
57
+    #spip_log("cookie('$name', '$value', '$expire', '$path', '$domain', '$secure', '$httponly'");
58
+
59
+    $a =
60
+        $httponly ?
61
+            @setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
62
+            : ($secure ?
63
+            @setcookie($name, $value, $expire, $path, $domain, $secure)
64
+            : ($domain ?
65
+                @setcookie($name, $value, $expire, $path, $domain)
66
+                : ($path ?
67
+                    @setcookie($name, $value, $expire, $path)
68
+                    : ($expire ?
69
+                        @setcookie($name, $value, $expire)
70
+                        :
71
+                        @setcookie($name, $value)
72
+                    ))));
73
+
74
+    spip_cookie_envoye(true);
75
+
76
+    return $a;
77 77
 }
78 78
 
79 79
 /**
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
  * @return bool
90 90
  **/
91 91
 function spip_cookie_envoye($set = '') {
92
-	static $envoye = false;
93
-	if ($set) {
94
-		$envoye = true;
95
-	}
92
+    static $envoye = false;
93
+    if ($set) {
94
+        $envoye = true;
95
+    }
96 96
 
97
-	return $envoye;
97
+    return $envoye;
98 98
 }
99 99
 
100 100
 /**
@@ -113,21 +113,21 @@  discard block
 block discarded – undo
113 113
  *     Préfixe des cookies de SPIP
114 114
  **/
115 115
 function recuperer_cookies_spip($cookie_prefix) {
116
-	$prefix_long = strlen($cookie_prefix);
117
-
118
-	foreach ($_COOKIE as $name => $value) {
119
-		if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
120
-			unset($_COOKIE[$name]);
121
-			unset($GLOBALS[$name]);
122
-		}
123
-	}
124
-	foreach ($_COOKIE as $name => $value) {
125
-		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
126
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
127
-			$_COOKIE[$spipname] = $value;
128
-			$GLOBALS[$spipname] = $value;
129
-		}
130
-	}
116
+    $prefix_long = strlen($cookie_prefix);
117
+
118
+    foreach ($_COOKIE as $name => $value) {
119
+        if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
120
+            unset($_COOKIE[$name]);
121
+            unset($GLOBALS[$name]);
122
+        }
123
+    }
124
+    foreach ($_COOKIE as $name => $value) {
125
+        if (substr($name, 0, $prefix_long) == $cookie_prefix) {
126
+            $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
127
+            $_COOKIE[$spipname] = $value;
128
+            $GLOBALS[$spipname] = $value;
129
+        }
130
+    }
131 131
 
132 132
 }
133 133
 
@@ -147,18 +147,18 @@  discard block
 block discarded – undo
147 147
  *
148 148
  **/
149 149
 function exec_test_ajax_dist() {
150
-	switch (_request('js')) {
151
-		// on est appele par <noscript>
152
-		case -1:
153
-			spip_setcookie('spip_accepte_ajax', -1);
154
-			include_spip('inc/headers');
155
-			redirige_par_entete(chemin_image('puce-orange-anim.gif'));
156
-			break;
157
-
158
-		// ou par ajax
159
-		case 1:
160
-		default:
161
-			spip_setcookie('spip_accepte_ajax', 1);
162
-			break;
163
-	}
150
+    switch (_request('js')) {
151
+        // on est appele par <noscript>
152
+        case -1:
153
+            spip_setcookie('spip_accepte_ajax', -1);
154
+            include_spip('inc/headers');
155
+            redirige_par_entete(chemin_image('puce-orange-anim.gif'));
156
+            break;
157
+
158
+        // ou par ajax
159
+        case 1:
160
+        default:
161
+            spip_setcookie('spip_accepte_ajax', 1);
162
+            break;
163
+    }
164 164
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	// liste des cookies en httponly (a passer en define si besoin)
47 47
 	$httponly = in_array($name, explode(' ', 'spip_session'));
48 48
 
49
-	$name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'] . '_', $name);
49
+	$name = preg_replace('/^spip_/', $GLOBALS['cookie_prefix'].'_', $name);
50 50
 	if ($path == 'AUTO') {
51 51
 		$path = defined('_COOKIE_PATH') ? _COOKIE_PATH : preg_replace(',^\w+://[^/]*,', '', url_de_base());
52 52
 	}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	}
124 124
 	foreach ($_COOKIE as $name => $value) {
125 125
 		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
126
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
126
+			$spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name);
127 127
 			$_COOKIE[$spipname] = $value;
128 128
 			$GLOBALS[$spipname] = $value;
129 129
 		}
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
  *     Couples champ/valeur à modifier
84 84
  * @param string $serveur
85 85
  *     Nom du connecteur à la base de données
86
- * @return bool|string
86
+ * @return string|false
87 87
  *     - false  : Aucune modification, aucun champ n'est à modifier
88 88
  *     - chaîne vide : Vide si tout s'est bien passé
89 89
  *     - chaîne : Texte d'un message d'erreur
Please login to merge, or discard this patch.
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
  *     Tableau des champs et valeurs collectées
40 40
  */
41 41
 function collecter_requests($white_list, $black_list = array(), $set = null, $tous = false) {
42
-	$c = $set;
43
-	if (!$c) {
44
-		$c = array();
45
-		foreach ($white_list as $champ) {
46
-			// on ne collecte que les champs reellement envoyes par defaut.
47
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
-			$val = _request($champ);
49
-			if ($tous or $val !== null) {
50
-				$c[$champ] = $val;
51
-			}
52
-		}
53
-		// on ajoute toujours la lang en saisie possible
54
-		// meme si pas prevu au depart pour l'objet concerne
55
-		if ($l = _request('changer_lang')) {
56
-			$c['lang'] = $l;
57
-		}
58
-	}
59
-	foreach ($black_list as $champ) {
60
-		unset($c[$champ]);
61
-	}
62
-
63
-	return $c;
42
+    $c = $set;
43
+    if (!$c) {
44
+        $c = array();
45
+        foreach ($white_list as $champ) {
46
+            // on ne collecte que les champs reellement envoyes par defaut.
47
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
+            $val = _request($champ);
49
+            if ($tous or $val !== null) {
50
+                $c[$champ] = $val;
51
+            }
52
+        }
53
+        // on ajoute toujours la lang en saisie possible
54
+        // meme si pas prevu au depart pour l'objet concerne
55
+        if ($l = _request('changer_lang')) {
56
+            $c['lang'] = $l;
57
+        }
58
+    }
59
+    foreach ($black_list as $champ) {
60
+        unset($c[$champ]);
61
+    }
62
+
63
+    return $c;
64 64
 }
65 65
 
66 66
 /**
@@ -97,208 +97,208 @@  discard block
 block discarded – undo
97 97
  *     - chaîne : Texte d'un message d'erreur
98 98
  */
99 99
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
100
-	if (!$id_objet = intval($id_objet)) {
101
-		spip_log('Erreur $id_objet non defini', 'warn');
102
-
103
-		return _T('erreur_technique_enregistrement_impossible');
104
-	}
105
-
106
-	include_spip('inc/filtres');
107
-
108
-	$table_objet = table_objet($objet, $serveur);
109
-	$spip_table_objet = table_objet_sql($objet, $serveur);
110
-	$id_table_objet = id_table_objet($objet, $serveur);
111
-	$trouver_table = charger_fonction('trouver_table', 'base');
112
-	$desc = $trouver_table($spip_table_objet, $serveur);
113
-
114
-	// Appels incomplets (sans $c)
115
-	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
-
118
-		return _T('erreur_technique_enregistrement_impossible');
119
-	}
120
-
121
-	// Securite : certaines variables ne sont jamais acceptees ici
122
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
123
-	// il faut passer par instituer_XX()
124
-	// TODO: faut-il passer ces variables interdites
125
-	// dans un fichier de description separe ?
126
-	unset($c['statut']);
127
-	unset($c['id_parent']);
128
-	unset($c['id_rubrique']);
129
-	unset($c['id_secteur']);
130
-
131
-	// Gerer les champs non vides
132
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
-		foreach ($options['nonvide'] as $champ => $sinon) {
134
-			if (isset($c[$champ]) and $c[$champ] === '') {
135
-				$c[$champ] = $sinon;
136
-			}
137
-		}
138
-	}
139
-
140
-
141
-	// N'accepter que les champs qui existent
142
-	// TODO: ici aussi on peut valider les contenus
143
-	// en fonction du type
144
-	$champs = array();
145
-	foreach ($desc['field'] as $champ => $ignore) {
146
-		if (isset($c[$champ])) {
147
-			$champs[$champ] = $c[$champ];
148
-		}
149
-	}
150
-
151
-	// Nettoyer les valeurs
152
-	$champs = array_map('corriger_caracteres', $champs);
153
-
154
-	// Envoyer aux plugins
155
-	$champs = pipeline('pre_edition',
156
-		array(
157
-			'args' => array(
158
-				'table' => $spip_table_objet, // compatibilite
159
-				'table_objet' => $table_objet,
160
-				'spip_table_objet' => $spip_table_objet,
161
-				'type' => $objet,
162
-				'id_objet' => $id_objet,
163
-				'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
164
-				'serveur' => $serveur,
165
-				'action' => isset($options['action']) ? $options['action'] : 'modifier'
166
-			),
167
-			'data' => $champs
168
-		)
169
-	);
170
-
171
-	if (!$champs) {
172
-		return false;
173
-	}
174
-
175
-
176
-	// marquer le fait que l'objet est travaille par toto a telle date
177
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
178
-		include_spip('inc/drapeau_edition');
179
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
180
-	}
181
-
182
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
183
-	include_spip('inc/editer');
184
-	if (!isset($options['data']) or is_null($options['data'])){
185
-		$options['data'] = &$_POST;
186
-	}
187
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
188
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
189
-	// et gere l'interface
190
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
191
-	if ($conflits) {
192
-		return _T('titre_conflit_edition');
193
-	}
194
-
195
-	if ($champs) {
196
-		// cas particulier de la langue : passer par instituer_langue_objet
197
-		if (isset($champs['lang'])) {
198
-			if ($changer_lang = $champs['lang']) {
199
-				$id_rubrique = 0;
200
-				if (isset($desc['field']['id_rubrique'])) {
201
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
202
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
203
-				}
204
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
205
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
206
-			}
207
-			// on laisse 'lang' dans $champs,
208
-			// ca permet de passer dans le pipeline post_edition et de journaliser
209
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
210
-			// deja pris en compte
211
-		}
212
-
213
-		// la modif peut avoir lieu
214
-
215
-		// faut-il ajouter date_modif ?
216
-		if (isset($options['date_modif']) and $options['date_modif']
217
-			and !isset($champs[$options['date_modif']])
218
-		) {
219
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
220
-		}
221
-
222
-		// allez on commit la modif
223
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
224
-
225
-		// on verifie si elle est bien passee
226
-		$moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(),
227
-			'', array(), $serveur);
228
-		// si difference entre les champs, reperer les champs mal enregistres
229
-		if ($moof != $champs) {
230
-			$liste = array();
231
-			foreach ($moof as $k => $v) {
232
-				if ($v !== $champs[$k]
233
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
234
-					and (!is_numeric($v) or intval($v) != intval($champs[$k]))
235
-				) {
236
-					$liste[] = $k;
237
-					$conflits[$k]['post'] = $champs[$k];
238
-					$conflits[$k]['save'] = $v;
239
-
240
-					// cas specifique MySQL+emoji : si l'un est la
241
-					// conversion utf8_noplanes de l'autre alors c'est OK
242
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
243
-						include_spip('inc/charsets');
244
-						if ($v == utf8_noplanes($champs[$k])) {
245
-							array_pop($liste);
246
-						}
247
-					}
248
-				}
249
-			}
250
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
251
-			// c'est un cas exceptionnel
252
-			if (count($liste)) {
253
-				spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
254
-					'modifier.' . _LOG_CRITIQUE);
255
-
256
-				return _T('erreur_technique_enregistrement_champs',
257
-					array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"));
258
-			}
259
-		}
260
-
261
-		// Invalider les caches
262
-		if (isset($options['invalideur']) and $options['invalideur']) {
263
-			include_spip('inc/invalideur');
264
-			if (is_array($options['invalideur'])) {
265
-				array_map('suivre_invalideur', $options['invalideur']);
266
-			} else {
267
-				suivre_invalideur($options['invalideur']);
268
-			}
269
-		}
270
-
271
-		// Notifications, gestion des revisions...
272
-		// en standard, appelle |nouvelle_revision ci-dessous
273
-		pipeline('post_edition',
274
-			array(
275
-				'args' => array(
276
-					'table' => $spip_table_objet,
277
-					'table_objet' => $table_objet,
278
-					'spip_table_objet' => $spip_table_objet,
279
-					'type' => $objet,
280
-					'id_objet' => $id_objet,
281
-					'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ?
282
-					'serveur' => $serveur,
283
-					'action' => isset($options['action']) ? $options['action'] : 'modifier'
284
-				),
285
-				'data' => $champs
286
-			)
287
-		);
288
-	}
289
-
290
-	// journaliser l'affaire
291
-	// message a affiner :-)
292
-	include_spip('inc/filtres_mini');
293
-	$qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
294
-	journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join('+',
295
-			array_diff(array_keys($champs), array('date_modif'))) . ')'), array(
296
-		'faire' => 'modifier',
297
-		'quoi' => $objet,
298
-		'id' => $id_objet
299
-	));
300
-
301
-	return '';
100
+    if (!$id_objet = intval($id_objet)) {
101
+        spip_log('Erreur $id_objet non defini', 'warn');
102
+
103
+        return _T('erreur_technique_enregistrement_impossible');
104
+    }
105
+
106
+    include_spip('inc/filtres');
107
+
108
+    $table_objet = table_objet($objet, $serveur);
109
+    $spip_table_objet = table_objet_sql($objet, $serveur);
110
+    $id_table_objet = id_table_objet($objet, $serveur);
111
+    $trouver_table = charger_fonction('trouver_table', 'base');
112
+    $desc = $trouver_table($spip_table_objet, $serveur);
113
+
114
+    // Appels incomplets (sans $c)
115
+    if (!is_array($c)) {
116
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
+
118
+        return _T('erreur_technique_enregistrement_impossible');
119
+    }
120
+
121
+    // Securite : certaines variables ne sont jamais acceptees ici
122
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
123
+    // il faut passer par instituer_XX()
124
+    // TODO: faut-il passer ces variables interdites
125
+    // dans un fichier de description separe ?
126
+    unset($c['statut']);
127
+    unset($c['id_parent']);
128
+    unset($c['id_rubrique']);
129
+    unset($c['id_secteur']);
130
+
131
+    // Gerer les champs non vides
132
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
+        foreach ($options['nonvide'] as $champ => $sinon) {
134
+            if (isset($c[$champ]) and $c[$champ] === '') {
135
+                $c[$champ] = $sinon;
136
+            }
137
+        }
138
+    }
139
+
140
+
141
+    // N'accepter que les champs qui existent
142
+    // TODO: ici aussi on peut valider les contenus
143
+    // en fonction du type
144
+    $champs = array();
145
+    foreach ($desc['field'] as $champ => $ignore) {
146
+        if (isset($c[$champ])) {
147
+            $champs[$champ] = $c[$champ];
148
+        }
149
+    }
150
+
151
+    // Nettoyer les valeurs
152
+    $champs = array_map('corriger_caracteres', $champs);
153
+
154
+    // Envoyer aux plugins
155
+    $champs = pipeline('pre_edition',
156
+        array(
157
+            'args' => array(
158
+                'table' => $spip_table_objet, // compatibilite
159
+                'table_objet' => $table_objet,
160
+                'spip_table_objet' => $spip_table_objet,
161
+                'type' => $objet,
162
+                'id_objet' => $id_objet,
163
+                'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
164
+                'serveur' => $serveur,
165
+                'action' => isset($options['action']) ? $options['action'] : 'modifier'
166
+            ),
167
+            'data' => $champs
168
+        )
169
+    );
170
+
171
+    if (!$champs) {
172
+        return false;
173
+    }
174
+
175
+
176
+    // marquer le fait que l'objet est travaille par toto a telle date
177
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
178
+        include_spip('inc/drapeau_edition');
179
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
180
+    }
181
+
182
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
183
+    include_spip('inc/editer');
184
+    if (!isset($options['data']) or is_null($options['data'])){
185
+        $options['data'] = &$_POST;
186
+    }
187
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
188
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
189
+    // et gere l'interface
190
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
191
+    if ($conflits) {
192
+        return _T('titre_conflit_edition');
193
+    }
194
+
195
+    if ($champs) {
196
+        // cas particulier de la langue : passer par instituer_langue_objet
197
+        if (isset($champs['lang'])) {
198
+            if ($changer_lang = $champs['lang']) {
199
+                $id_rubrique = 0;
200
+                if (isset($desc['field']['id_rubrique'])) {
201
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
202
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
203
+                }
204
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
205
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
206
+            }
207
+            // on laisse 'lang' dans $champs,
208
+            // ca permet de passer dans le pipeline post_edition et de journaliser
209
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
210
+            // deja pris en compte
211
+        }
212
+
213
+        // la modif peut avoir lieu
214
+
215
+        // faut-il ajouter date_modif ?
216
+        if (isset($options['date_modif']) and $options['date_modif']
217
+            and !isset($champs[$options['date_modif']])
218
+        ) {
219
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
220
+        }
221
+
222
+        // allez on commit la modif
223
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
224
+
225
+        // on verifie si elle est bien passee
226
+        $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(),
227
+            '', array(), $serveur);
228
+        // si difference entre les champs, reperer les champs mal enregistres
229
+        if ($moof != $champs) {
230
+            $liste = array();
231
+            foreach ($moof as $k => $v) {
232
+                if ($v !== $champs[$k]
233
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
234
+                    and (!is_numeric($v) or intval($v) != intval($champs[$k]))
235
+                ) {
236
+                    $liste[] = $k;
237
+                    $conflits[$k]['post'] = $champs[$k];
238
+                    $conflits[$k]['save'] = $v;
239
+
240
+                    // cas specifique MySQL+emoji : si l'un est la
241
+                    // conversion utf8_noplanes de l'autre alors c'est OK
242
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
243
+                        include_spip('inc/charsets');
244
+                        if ($v == utf8_noplanes($champs[$k])) {
245
+                            array_pop($liste);
246
+                        }
247
+                    }
248
+                }
249
+            }
250
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
251
+            // c'est un cas exceptionnel
252
+            if (count($liste)) {
253
+                spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
254
+                    'modifier.' . _LOG_CRITIQUE);
255
+
256
+                return _T('erreur_technique_enregistrement_champs',
257
+                    array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"));
258
+            }
259
+        }
260
+
261
+        // Invalider les caches
262
+        if (isset($options['invalideur']) and $options['invalideur']) {
263
+            include_spip('inc/invalideur');
264
+            if (is_array($options['invalideur'])) {
265
+                array_map('suivre_invalideur', $options['invalideur']);
266
+            } else {
267
+                suivre_invalideur($options['invalideur']);
268
+            }
269
+        }
270
+
271
+        // Notifications, gestion des revisions...
272
+        // en standard, appelle |nouvelle_revision ci-dessous
273
+        pipeline('post_edition',
274
+            array(
275
+                'args' => array(
276
+                    'table' => $spip_table_objet,
277
+                    'table_objet' => $table_objet,
278
+                    'spip_table_objet' => $spip_table_objet,
279
+                    'type' => $objet,
280
+                    'id_objet' => $id_objet,
281
+                    'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ?
282
+                    'serveur' => $serveur,
283
+                    'action' => isset($options['action']) ? $options['action'] : 'modifier'
284
+                ),
285
+                'data' => $champs
286
+            )
287
+        );
288
+    }
289
+
290
+    // journaliser l'affaire
291
+    // message a affiner :-)
292
+    include_spip('inc/filtres_mini');
293
+    $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
294
+    journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join('+',
295
+            array_diff(array_keys($champs), array('date_modif'))) . ')'), array(
296
+        'faire' => 'modifier',
297
+        'quoi' => $objet,
298
+        'id' => $id_objet
299
+    ));
300
+
301
+    return '';
302 302
 }
303 303
 
304 304
 /**
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
  *     false sinon (erreur ou aucun champ modifié)
324 324
  */
325 325
 function modifier_contenu($type, $id, $options, $c = null, $serveur = '') {
326
-	$res = objet_modifier_champs($type, $id, $options, $c, $serveur);
326
+    $res = objet_modifier_champs($type, $id, $options, $c, $serveur);
327 327
 
328
-	return ($res === '' ? true : false);
328
+    return ($res === '' ? true : false);
329 329
 }
330 330
 
331 331
 /**
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
  * @return mixed|string
347 347
  */
348 348
 function revision_objet($objet, $id_objet, $c = null) {
349
-	$objet = objet_type($objet); // securite
350
-	include_spip('action/editer_objet');
349
+    $objet = objet_type($objet); // securite
350
+    include_spip('action/editer_objet');
351 351
 
352
-	return objet_modifier($objet, $id_objet, $c);
352
+    return objet_modifier($objet, $id_objet, $c);
353 353
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 	// Appels incomplets (sans $c)
115 115
 	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
116
+		spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c');
117 117
 
118 118
 		return _T('erreur_technique_enregistrement_impossible');
119 119
 	}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
 	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
183 183
 	include_spip('inc/editer');
184
-	if (!isset($options['data']) or is_null($options['data'])){
184
+	if (!isset($options['data']) or is_null($options['data'])) {
185 185
 		$options['data'] = &$_POST;
186 186
 	}
187 187
 	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 				$id_rubrique = 0;
200 200
 				if (isset($desc['field']['id_rubrique'])) {
201 201
 					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
202
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
202
+					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet));
203 203
 				}
204 204
 				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
205 205
 				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
@@ -220,10 +220,10 @@  discard block
 block discarded – undo
220 220
 		}
221 221
 
222 222
 		// allez on commit la modif
223
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
223
+		sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), $serveur);
224 224
 
225 225
 		// on verifie si elle est bien passee
226
-		$moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(),
226
+		$moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=".intval($id_objet), array(), array(),
227 227
 			'', array(), $serveur);
228 228
 		// si difference entre les champs, reperer les champs mal enregistres
229 229
 		if ($moof != $champs) {
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
 			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
251 251
 			// c'est un cas exceptionnel
252 252
 			if (count($liste)) {
253
-				spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
254
-					'modifier.' . _LOG_CRITIQUE);
253
+				spip_log("Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true),
254
+					'modifier.'._LOG_CRITIQUE);
255 255
 
256 256
 				return _T('erreur_technique_enregistrement_champs',
257
-					array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"));
257
+					array('champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"));
258 258
 			}
259 259
 		}
260 260
 
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 	// message a affiner :-)
292 292
 	include_spip('inc/filtres_mini');
293 293
 	$qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
294
-	journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join('+',
295
-			array_diff(array_keys($champs), array('date_modif'))) . ')'), array(
294
+	journal(_L($qui.' a &#233;dit&#233; l&#8217;'.$objet.' '.$id_objet.' ('.join('+',
295
+			array_diff(array_keys($champs), array('date_modif'))).')'), array(
296 296
 		'faire' => 'modifier',
297 297
 		'quoi' => $objet,
298 298
 		'id' => $id_objet
Please login to merge, or discard this patch.
ecrire/auth/sha256.inc.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 
329 329
 		/** Array split
330 330
 		 *
331
-		 * @param array $a
331
+		 * @param integer[] $a
332 332
 		 * @param int $n
333 333
 		 * @return array
334 334
 		 **/
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 		/**
353 353
 		 * Process and return the hash.
354 354
 		 *
355
-		 * @param $str Input string to hash
355
+		 * @param string $str Input string to hash
356 356
 		 * @param $ig_func Option param to ignore checking for php > 5.1.2
357 357
 		 * @return string Hexadecimal representation of the message digest
358 358
 		 */
Please login to merge, or discard this patch.
Indentation   +500 added lines, -500 removed lines patch added patch discarded remove patch
@@ -68,482 +68,482 @@  discard block
 block discarded – undo
68 68
  * @package SPIP\Core\Authentification\Sha256
69 69
  */
70 70
 if (!class_exists('nanoSha2')) {
71
-	/**
72
-	 * Classe de calcul d'un SHA
73
-	 */
74
-	class nanoSha2 {
75
-		// php 4 - 5 compatable class properties
76
-		/** Le résultat doit être passé en majuscule ?
77
-		 *
78
-		 * @var bool
79
-		 */
80
-		var $toUpper;
81
-		/** 32 ou 64 bits ?
82
-		 *
83
-		 * @var int
84
-		 */
85
-		var $platform;
86
-		/** bytes par caractères */
87
-		var $bytesString = 16;
88
-
89
-		/**
90
-		 * Constructor
91
-		 *
92
-		 * @param bool $toUpper
93
-		 */
94
-		function __construct($toUpper = false) {
95
-			// Determine if the caller wants upper case or not.
96
-			$this->toUpper = is_bool($toUpper)
97
-				? $toUpper
98
-				: ((defined('_NANO_SHA2_UPPER')) ? true : false);
99
-
100
-			// Deteremine if the system is 32 or 64 bit.
101
-			$tmpInt = (int)4294967295;
102
-			$this->platform = ($tmpInt > 0) ? 64 : 32;
103
-		}
104
-
105
-		/**
106
-		 * Here are the bitwise and functions as defined in FIPS180-2 Standard
107
-		 *
108
-		 * @param int $x
109
-		 * @param int $y
110
-		 * @param int $n
111
-		 * @return int
112
-		 */
113
-		function addmod2n($x, $y, $n = 4294967296)      // Z = (X + Y) mod 2^32
114
-		{
115
-			$mask = 0x80000000;
116
-
117
-			if ($x < 0) {
118
-				$x &= 0x7FFFFFFF;
119
-				$x = (float)$x+$mask;
120
-			}
121
-
122
-			if ($y < 0) {
123
-				$y &= 0x7FFFFFFF;
124
-				$y = (float)$y+$mask;
125
-			}
126
-
127
-			$r = $x+$y;
128
-
129
-			if ($r >= $n) {
130
-				while ($r >= $n) {
131
-					$r -= $n;
132
-				}
133
-			}
134
-
135
-			return (int)$r;
136
-		}
137
-
138
-		/**
139
-		 * Logical bitwise right shift (PHP default is arithmetic shift)
140
-		 *
141
-		 * @param int $x
142
-		 * @param int $n
143
-		 * return int
144
-		 */
145
-		function SHR($x, $n)        // x >> n
146
-		{
147
-			if ($n >= 32) {      // impose some limits to keep it 32-bit
148
-				return (int)0;
149
-			}
150
-
151
-			if ($n <= 0) {
152
-				return (int)$x;
153
-			}
154
-
155
-			$mask = 0x40000000;
156
-
157
-			if ($x < 0) {
158
-				$x &= 0x7FFFFFFF;
159
-				$mask = $mask >> ($n-1);
160
-
161
-				return ($x >> $n) | $mask;
162
-			}
163
-
164
-			return (int)$x >> (int)$n;
165
-		}
166
-
167
-		/** ROTR
168
-		 *
169
-		 * @param int $x
170
-		 * @param int $n
171
-		 * @return int
172
-		 */
173
-		function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); }
174
-
175
-		/** Ch
176
-		 *
177
-		 * @param int $x
178
-		 * @param int $y
179
-		 * @param int $z
180
-		 * @return int
181
-		 */
182
-		function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); }
183
-
184
-		/** Maj
185
-		 *
186
-		 * @param int $x
187
-		 * @param int $y
188
-		 * @param int $z
189
-		 * @return int
190
-		 */
191
-		function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); }
192
-
193
-		/** Sigma0
194
-		 *
195
-		 * @param int $x
196
-		 * @return int
197
-		 */
198
-		function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); }
199
-
200
-		/** Sigma1
201
-		 *
202
-		 * @param int $x
203
-		 * @return int
204
-		 */
205
-		function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); }
206
-
207
-		/** Sigma_0
208
-		 *
209
-		 * @param int $x
210
-		 * @return int
211
-		 */
212
-		function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); }
213
-
214
-		/** Sigma_1
215
-		 *
216
-		 * @param int $x
217
-		 * @return int
218
-		 */
219
-		function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); }
220
-
221
-		/** String 2 ord UTF8
222
-		 *
223
-		 * @param string $s
224
-		 * @param int $byteSize
225
-		 * @return array
226
-		 **/
227
-		function string2ordUTF8($s, &$byteSize) {
228
-			$chars = array();
229
-			// par defaut sur 8bits
230
-			$byteSize = 8;
231
-			$i = 0;
232
-			while ($i < strlen($s)) {
233
-				$chars[] = $this->ordUTF8($s, $i, $bytes);
234
-				$i += $bytes;
235
-				// mais si un char necessite 16bits, on passe tout sur 16
236
-				// sinon on ne concorde pas avec le lecture de la chaine en js
237
-				// et le sha256 js
238
-				if ($bytes > 1) {
239
-					$byteSize = 16;
240
-				}
241
-			}
242
-
243
-			return $chars;
244
-		}
245
-
246
-		/** Ord UTF8
247
-		 *
248
-		 * @param string $c
249
-		 * @param int $index
250
-		 * @param int $bytes
251
-		 * @return unknown
252
-		 **/
253
-		function ordUTF8($c, $index = 0, &$bytes) {
254
-			$len = strlen($c);
255
-			$bytes = 0;
256
-
257
-			if ($index >= $len) {
258
-				return false;
259
-			}
260
-
261
-			$h = ord($c{$index});
262
-
263
-			if ($h <= 0x7F) {
264
-				$bytes = 1;
265
-
266
-				return $h;
267
-			} else {
268
-				if ($h < 0xC2) {
269
-					// pas utf mais renvoyer quand meme ce qu'on a
270
-					$bytes = 1;
271
-
272
-					return $h;
273
-				} else {
274
-					if ($h <= 0xDF && $index < $len-1) {
275
-						$bytes = 2;
276
-
277
-						return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F);
278
-					} else {
279
-						if ($h <= 0xEF && $index < $len-2) {
280
-							$bytes = 3;
281
-
282
-							return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6
283
-							| (ord($c{$index+2}) & 0x3F);
284
-						} else {
285
-							if ($h <= 0xF4 && $index < $len-3) {
286
-								$bytes = 4;
287
-
288
-								return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12
289
-								| (ord($c{$index+2}) & 0x3F) << 6
290
-								| (ord($c{$index+3}) & 0x3F);
291
-							} else {
292
-								// pas utf mais renvoyer quand meme ce qu'on a
293
-								$bytes = 1;
294
-
295
-								return $h;
296
-							}
297
-						}
298
-					}
299
-				}
300
-			}
301
-		}
302
-
303
-		/** String 2 bin int
304
-		 *
305
-		 * @param string $str
306
-		 * @param int $npad
307
-		 * @return int[]
308
-		 **/
309
-		function string2binint($str, $npad = 512) {
310
-			$bin = array();
311
-			$ords = $this->string2ordUTF8($str, $this->bytesString);
312
-			$npad = $npad/$this->bytesString;
313
-			$length = count($ords);
314
-			$ords[] = 0x80; // append the "1" bit followed by 7 0's
315
-			$pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString;
316
-			$ords = array_pad($ords, $pad, 0);
317
-			$mask = (1 << $this->bytesString)-1;
318
-			for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) {
319
-				if (!isset($bin[$i >> 5])) {
320
-					$bin[$i >> 5] = 0;
321
-				} // pour eviter des notices.
322
-				$bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32);
323
-			}
324
-			$bin[] = $length*$this->bytesString;
325
-
326
-			return $bin;
327
-		}
328
-
329
-		/** Array split
330
-		 *
331
-		 * @param array $a
332
-		 * @param int $n
333
-		 * @return array
334
-		 **/
335
-		function array_split($a, $n) {
336
-			$split = array();
337
-			while (count($a) > $n) {
338
-				$s = array();
339
-				for ($i = 0; $i < $n; $i++) {
340
-					$s[] = array_shift($a);
341
-				}
342
-				$split[] = $s;
343
-			}
344
-			if (count($a)) {
345
-				$a = array_pad($a, $n, 0);
346
-				$split[] = $a;
347
-			}
348
-
349
-			return $split;
350
-		}
351
-
352
-		/**
353
-		 * Process and return the hash.
354
-		 *
355
-		 * @param $str Input string to hash
356
-		 * @param $ig_func Option param to ignore checking for php > 5.1.2
357
-		 * @return string Hexadecimal representation of the message digest
358
-		 */
359
-		function hash($str, $ig_func = true) {
360
-			unset($binStr);     // binary representation of input string
361
-			unset($hexStr);     // 256-bit message digest in readable hex format
362
-
363
-			// check for php's internal sha256 function, ignore if ig_func==true
364
-			if ($ig_func == false) {
365
-				if (version_compare(PHP_VERSION, '5.1.2', '>=') AND !defined('_NO_HASH_DEFINED')) {
366
-					return hash("sha256", $str, false);
367
-				} else {
368
-					if (function_exists('mhash') && defined('MHASH_SHA256')) {
369
-						return base64_encode(bin2hex(mhash(MHASH_SHA256, $str)));
370
-					}
371
-				}
372
-			}
373
-
374
-			/*
71
+    /**
72
+     * Classe de calcul d'un SHA
73
+     */
74
+    class nanoSha2 {
75
+        // php 4 - 5 compatable class properties
76
+        /** Le résultat doit être passé en majuscule ?
77
+         *
78
+         * @var bool
79
+         */
80
+        var $toUpper;
81
+        /** 32 ou 64 bits ?
82
+         *
83
+         * @var int
84
+         */
85
+        var $platform;
86
+        /** bytes par caractères */
87
+        var $bytesString = 16;
88
+
89
+        /**
90
+         * Constructor
91
+         *
92
+         * @param bool $toUpper
93
+         */
94
+        function __construct($toUpper = false) {
95
+            // Determine if the caller wants upper case or not.
96
+            $this->toUpper = is_bool($toUpper)
97
+                ? $toUpper
98
+                : ((defined('_NANO_SHA2_UPPER')) ? true : false);
99
+
100
+            // Deteremine if the system is 32 or 64 bit.
101
+            $tmpInt = (int)4294967295;
102
+            $this->platform = ($tmpInt > 0) ? 64 : 32;
103
+        }
104
+
105
+        /**
106
+         * Here are the bitwise and functions as defined in FIPS180-2 Standard
107
+         *
108
+         * @param int $x
109
+         * @param int $y
110
+         * @param int $n
111
+         * @return int
112
+         */
113
+        function addmod2n($x, $y, $n = 4294967296)      // Z = (X + Y) mod 2^32
114
+        {
115
+            $mask = 0x80000000;
116
+
117
+            if ($x < 0) {
118
+                $x &= 0x7FFFFFFF;
119
+                $x = (float)$x+$mask;
120
+            }
121
+
122
+            if ($y < 0) {
123
+                $y &= 0x7FFFFFFF;
124
+                $y = (float)$y+$mask;
125
+            }
126
+
127
+            $r = $x+$y;
128
+
129
+            if ($r >= $n) {
130
+                while ($r >= $n) {
131
+                    $r -= $n;
132
+                }
133
+            }
134
+
135
+            return (int)$r;
136
+        }
137
+
138
+        /**
139
+         * Logical bitwise right shift (PHP default is arithmetic shift)
140
+         *
141
+         * @param int $x
142
+         * @param int $n
143
+         * return int
144
+         */
145
+        function SHR($x, $n)        // x >> n
146
+        {
147
+            if ($n >= 32) {      // impose some limits to keep it 32-bit
148
+                return (int)0;
149
+            }
150
+
151
+            if ($n <= 0) {
152
+                return (int)$x;
153
+            }
154
+
155
+            $mask = 0x40000000;
156
+
157
+            if ($x < 0) {
158
+                $x &= 0x7FFFFFFF;
159
+                $mask = $mask >> ($n-1);
160
+
161
+                return ($x >> $n) | $mask;
162
+            }
163
+
164
+            return (int)$x >> (int)$n;
165
+        }
166
+
167
+        /** ROTR
168
+         *
169
+         * @param int $x
170
+         * @param int $n
171
+         * @return int
172
+         */
173
+        function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); }
174
+
175
+        /** Ch
176
+         *
177
+         * @param int $x
178
+         * @param int $y
179
+         * @param int $z
180
+         * @return int
181
+         */
182
+        function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); }
183
+
184
+        /** Maj
185
+         *
186
+         * @param int $x
187
+         * @param int $y
188
+         * @param int $z
189
+         * @return int
190
+         */
191
+        function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); }
192
+
193
+        /** Sigma0
194
+         *
195
+         * @param int $x
196
+         * @return int
197
+         */
198
+        function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); }
199
+
200
+        /** Sigma1
201
+         *
202
+         * @param int $x
203
+         * @return int
204
+         */
205
+        function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); }
206
+
207
+        /** Sigma_0
208
+         *
209
+         * @param int $x
210
+         * @return int
211
+         */
212
+        function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); }
213
+
214
+        /** Sigma_1
215
+         *
216
+         * @param int $x
217
+         * @return int
218
+         */
219
+        function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); }
220
+
221
+        /** String 2 ord UTF8
222
+         *
223
+         * @param string $s
224
+         * @param int $byteSize
225
+         * @return array
226
+         **/
227
+        function string2ordUTF8($s, &$byteSize) {
228
+            $chars = array();
229
+            // par defaut sur 8bits
230
+            $byteSize = 8;
231
+            $i = 0;
232
+            while ($i < strlen($s)) {
233
+                $chars[] = $this->ordUTF8($s, $i, $bytes);
234
+                $i += $bytes;
235
+                // mais si un char necessite 16bits, on passe tout sur 16
236
+                // sinon on ne concorde pas avec le lecture de la chaine en js
237
+                // et le sha256 js
238
+                if ($bytes > 1) {
239
+                    $byteSize = 16;
240
+                }
241
+            }
242
+
243
+            return $chars;
244
+        }
245
+
246
+        /** Ord UTF8
247
+         *
248
+         * @param string $c
249
+         * @param int $index
250
+         * @param int $bytes
251
+         * @return unknown
252
+         **/
253
+        function ordUTF8($c, $index = 0, &$bytes) {
254
+            $len = strlen($c);
255
+            $bytes = 0;
256
+
257
+            if ($index >= $len) {
258
+                return false;
259
+            }
260
+
261
+            $h = ord($c{$index});
262
+
263
+            if ($h <= 0x7F) {
264
+                $bytes = 1;
265
+
266
+                return $h;
267
+            } else {
268
+                if ($h < 0xC2) {
269
+                    // pas utf mais renvoyer quand meme ce qu'on a
270
+                    $bytes = 1;
271
+
272
+                    return $h;
273
+                } else {
274
+                    if ($h <= 0xDF && $index < $len-1) {
275
+                        $bytes = 2;
276
+
277
+                        return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F);
278
+                    } else {
279
+                        if ($h <= 0xEF && $index < $len-2) {
280
+                            $bytes = 3;
281
+
282
+                            return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6
283
+                            | (ord($c{$index+2}) & 0x3F);
284
+                        } else {
285
+                            if ($h <= 0xF4 && $index < $len-3) {
286
+                                $bytes = 4;
287
+
288
+                                return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12
289
+                                | (ord($c{$index+2}) & 0x3F) << 6
290
+                                | (ord($c{$index+3}) & 0x3F);
291
+                            } else {
292
+                                // pas utf mais renvoyer quand meme ce qu'on a
293
+                                $bytes = 1;
294
+
295
+                                return $h;
296
+                            }
297
+                        }
298
+                    }
299
+                }
300
+            }
301
+        }
302
+
303
+        /** String 2 bin int
304
+         *
305
+         * @param string $str
306
+         * @param int $npad
307
+         * @return int[]
308
+         **/
309
+        function string2binint($str, $npad = 512) {
310
+            $bin = array();
311
+            $ords = $this->string2ordUTF8($str, $this->bytesString);
312
+            $npad = $npad/$this->bytesString;
313
+            $length = count($ords);
314
+            $ords[] = 0x80; // append the "1" bit followed by 7 0's
315
+            $pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString;
316
+            $ords = array_pad($ords, $pad, 0);
317
+            $mask = (1 << $this->bytesString)-1;
318
+            for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) {
319
+                if (!isset($bin[$i >> 5])) {
320
+                    $bin[$i >> 5] = 0;
321
+                } // pour eviter des notices.
322
+                $bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32);
323
+            }
324
+            $bin[] = $length*$this->bytesString;
325
+
326
+            return $bin;
327
+        }
328
+
329
+        /** Array split
330
+         *
331
+         * @param array $a
332
+         * @param int $n
333
+         * @return array
334
+         **/
335
+        function array_split($a, $n) {
336
+            $split = array();
337
+            while (count($a) > $n) {
338
+                $s = array();
339
+                for ($i = 0; $i < $n; $i++) {
340
+                    $s[] = array_shift($a);
341
+                }
342
+                $split[] = $s;
343
+            }
344
+            if (count($a)) {
345
+                $a = array_pad($a, $n, 0);
346
+                $split[] = $a;
347
+            }
348
+
349
+            return $split;
350
+        }
351
+
352
+        /**
353
+         * Process and return the hash.
354
+         *
355
+         * @param $str Input string to hash
356
+         * @param $ig_func Option param to ignore checking for php > 5.1.2
357
+         * @return string Hexadecimal representation of the message digest
358
+         */
359
+        function hash($str, $ig_func = true) {
360
+            unset($binStr);     // binary representation of input string
361
+            unset($hexStr);     // 256-bit message digest in readable hex format
362
+
363
+            // check for php's internal sha256 function, ignore if ig_func==true
364
+            if ($ig_func == false) {
365
+                if (version_compare(PHP_VERSION, '5.1.2', '>=') AND !defined('_NO_HASH_DEFINED')) {
366
+                    return hash("sha256", $str, false);
367
+                } else {
368
+                    if (function_exists('mhash') && defined('MHASH_SHA256')) {
369
+                        return base64_encode(bin2hex(mhash(MHASH_SHA256, $str)));
370
+                    }
371
+                }
372
+            }
373
+
374
+            /*
375 375
 			 * SHA-256 Constants
376 376
 			 *  Sequence of sixty-four constant 32-bit words representing the
377 377
 			 *  first thirty-two bits of the fractional parts of the cube roots
378 378
 			 *  of the first sixtyfour prime numbers.
379 379
 			 */
380
-			$K = array(
381
-				(int)0x428a2f98,
382
-				(int)0x71374491,
383
-				(int)0xb5c0fbcf,
384
-				(int)0xe9b5dba5,
385
-				(int)0x3956c25b,
386
-				(int)0x59f111f1,
387
-				(int)0x923f82a4,
388
-				(int)0xab1c5ed5,
389
-				(int)0xd807aa98,
390
-				(int)0x12835b01,
391
-				(int)0x243185be,
392
-				(int)0x550c7dc3,
393
-				(int)0x72be5d74,
394
-				(int)0x80deb1fe,
395
-				(int)0x9bdc06a7,
396
-				(int)0xc19bf174,
397
-				(int)0xe49b69c1,
398
-				(int)0xefbe4786,
399
-				(int)0x0fc19dc6,
400
-				(int)0x240ca1cc,
401
-				(int)0x2de92c6f,
402
-				(int)0x4a7484aa,
403
-				(int)0x5cb0a9dc,
404
-				(int)0x76f988da,
405
-				(int)0x983e5152,
406
-				(int)0xa831c66d,
407
-				(int)0xb00327c8,
408
-				(int)0xbf597fc7,
409
-				(int)0xc6e00bf3,
410
-				(int)0xd5a79147,
411
-				(int)0x06ca6351,
412
-				(int)0x14292967,
413
-				(int)0x27b70a85,
414
-				(int)0x2e1b2138,
415
-				(int)0x4d2c6dfc,
416
-				(int)0x53380d13,
417
-				(int)0x650a7354,
418
-				(int)0x766a0abb,
419
-				(int)0x81c2c92e,
420
-				(int)0x92722c85,
421
-				(int)0xa2bfe8a1,
422
-				(int)0xa81a664b,
423
-				(int)0xc24b8b70,
424
-				(int)0xc76c51a3,
425
-				(int)0xd192e819,
426
-				(int)0xd6990624,
427
-				(int)0xf40e3585,
428
-				(int)0x106aa070,
429
-				(int)0x19a4c116,
430
-				(int)0x1e376c08,
431
-				(int)0x2748774c,
432
-				(int)0x34b0bcb5,
433
-				(int)0x391c0cb3,
434
-				(int)0x4ed8aa4a,
435
-				(int)0x5b9cca4f,
436
-				(int)0x682e6ff3,
437
-				(int)0x748f82ee,
438
-				(int)0x78a5636f,
439
-				(int)0x84c87814,
440
-				(int)0x8cc70208,
441
-				(int)0x90befffa,
442
-				(int)0xa4506ceb,
443
-				(int)0xbef9a3f7,
444
-				(int)0xc67178f2
445
-			);
446
-
447
-			// Pre-processing: Padding the string
448
-			$binStr = $this->string2binint($str, 512);
449
-
450
-			// Parsing the Padded Message (Break into N 512-bit blocks)
451
-			$M = $this->array_split($binStr, 16);
452
-
453
-			// Set the initial hash values
454
-			$h[0] = (int)0x6a09e667;
455
-			$h[1] = (int)0xbb67ae85;
456
-			$h[2] = (int)0x3c6ef372;
457
-			$h[3] = (int)0xa54ff53a;
458
-			$h[4] = (int)0x510e527f;
459
-			$h[5] = (int)0x9b05688c;
460
-			$h[6] = (int)0x1f83d9ab;
461
-			$h[7] = (int)0x5be0cd19;
462
-
463
-			// loop through message blocks and compute hash. ( For i=1 to N : )
464
-			$N = count($M);
465
-			for ($i = 0; $i < $N; $i++) {
466
-				// Break input block into 16 32bit words (message schedule prep)
467
-				$MI = $M[$i];
468
-
469
-				// Initialize working variables
470
-				$_a = (int)$h[0];
471
-				$_b = (int)$h[1];
472
-				$_c = (int)$h[2];
473
-				$_d = (int)$h[3];
474
-				$_e = (int)$h[4];
475
-				$_f = (int)$h[5];
476
-				$_g = (int)$h[6];
477
-				$_h = (int)$h[7];
478
-				unset($_s0);
479
-				unset($_s1);
480
-				unset($_T1);
481
-				unset($_T2);
482
-				$W = array();
483
-
484
-				// Compute the hash and update
485
-				for ($t = 0; $t < 16; $t++) {
486
-					// Prepare the first 16 message schedule values as we loop
487
-					$W[$t] = $MI[$t];
488
-
489
-					// Compute hash
490
-					$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)),
491
-						$this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]);
492
-					$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
493
-
494
-					// Update working variables
495
-					$_h = $_g;
496
-					$_g = $_f;
497
-					$_f = $_e;
498
-					$_e = $this->addmod2n($_d, $_T1);
499
-					$_d = $_c;
500
-					$_c = $_b;
501
-					$_b = $_a;
502
-					$_a = $this->addmod2n($_T1, $_T2);
503
-				}
504
-
505
-				for (; $t < 64; $t++) {
506
-					// Continue building the message schedule as we loop
507
-					$_s0 = $W[($t+1) & 0x0F];
508
-					$_s0 = $this->sigma_0($_s0);
509
-					$_s1 = $W[($t+14) & 0x0F];
510
-					$_s1 = $this->sigma_1($_s1);
511
-
512
-					$W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]);
513
-
514
-					// Compute hash
515
-					$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)),
516
-						$this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t & 0xF]);
517
-					$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
518
-
519
-					// Update working variables
520
-					$_h = $_g;
521
-					$_g = $_f;
522
-					$_f = $_e;
523
-					$_e = $this->addmod2n($_d, $_T1);
524
-					$_d = $_c;
525
-					$_c = $_b;
526
-					$_b = $_a;
527
-					$_a = $this->addmod2n($_T1, $_T2);
528
-				}
529
-
530
-				$h[0] = $this->addmod2n($h[0], $_a);
531
-				$h[1] = $this->addmod2n($h[1], $_b);
532
-				$h[2] = $this->addmod2n($h[2], $_c);
533
-				$h[3] = $this->addmod2n($h[3], $_d);
534
-				$h[4] = $this->addmod2n($h[4], $_e);
535
-				$h[5] = $this->addmod2n($h[5], $_f);
536
-				$h[6] = $this->addmod2n($h[6], $_g);
537
-				$h[7] = $this->addmod2n($h[7], $_h);
538
-			}
539
-
540
-			// Convert the 32-bit words into human readable hexadecimal format.
541
-			$hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]);
542
-
543
-			return ($this->toUpper) ? strtoupper($hexStr) : $hexStr;
544
-		}
545
-
546
-	}
380
+            $K = array(
381
+                (int)0x428a2f98,
382
+                (int)0x71374491,
383
+                (int)0xb5c0fbcf,
384
+                (int)0xe9b5dba5,
385
+                (int)0x3956c25b,
386
+                (int)0x59f111f1,
387
+                (int)0x923f82a4,
388
+                (int)0xab1c5ed5,
389
+                (int)0xd807aa98,
390
+                (int)0x12835b01,
391
+                (int)0x243185be,
392
+                (int)0x550c7dc3,
393
+                (int)0x72be5d74,
394
+                (int)0x80deb1fe,
395
+                (int)0x9bdc06a7,
396
+                (int)0xc19bf174,
397
+                (int)0xe49b69c1,
398
+                (int)0xefbe4786,
399
+                (int)0x0fc19dc6,
400
+                (int)0x240ca1cc,
401
+                (int)0x2de92c6f,
402
+                (int)0x4a7484aa,
403
+                (int)0x5cb0a9dc,
404
+                (int)0x76f988da,
405
+                (int)0x983e5152,
406
+                (int)0xa831c66d,
407
+                (int)0xb00327c8,
408
+                (int)0xbf597fc7,
409
+                (int)0xc6e00bf3,
410
+                (int)0xd5a79147,
411
+                (int)0x06ca6351,
412
+                (int)0x14292967,
413
+                (int)0x27b70a85,
414
+                (int)0x2e1b2138,
415
+                (int)0x4d2c6dfc,
416
+                (int)0x53380d13,
417
+                (int)0x650a7354,
418
+                (int)0x766a0abb,
419
+                (int)0x81c2c92e,
420
+                (int)0x92722c85,
421
+                (int)0xa2bfe8a1,
422
+                (int)0xa81a664b,
423
+                (int)0xc24b8b70,
424
+                (int)0xc76c51a3,
425
+                (int)0xd192e819,
426
+                (int)0xd6990624,
427
+                (int)0xf40e3585,
428
+                (int)0x106aa070,
429
+                (int)0x19a4c116,
430
+                (int)0x1e376c08,
431
+                (int)0x2748774c,
432
+                (int)0x34b0bcb5,
433
+                (int)0x391c0cb3,
434
+                (int)0x4ed8aa4a,
435
+                (int)0x5b9cca4f,
436
+                (int)0x682e6ff3,
437
+                (int)0x748f82ee,
438
+                (int)0x78a5636f,
439
+                (int)0x84c87814,
440
+                (int)0x8cc70208,
441
+                (int)0x90befffa,
442
+                (int)0xa4506ceb,
443
+                (int)0xbef9a3f7,
444
+                (int)0xc67178f2
445
+            );
446
+
447
+            // Pre-processing: Padding the string
448
+            $binStr = $this->string2binint($str, 512);
449
+
450
+            // Parsing the Padded Message (Break into N 512-bit blocks)
451
+            $M = $this->array_split($binStr, 16);
452
+
453
+            // Set the initial hash values
454
+            $h[0] = (int)0x6a09e667;
455
+            $h[1] = (int)0xbb67ae85;
456
+            $h[2] = (int)0x3c6ef372;
457
+            $h[3] = (int)0xa54ff53a;
458
+            $h[4] = (int)0x510e527f;
459
+            $h[5] = (int)0x9b05688c;
460
+            $h[6] = (int)0x1f83d9ab;
461
+            $h[7] = (int)0x5be0cd19;
462
+
463
+            // loop through message blocks and compute hash. ( For i=1 to N : )
464
+            $N = count($M);
465
+            for ($i = 0; $i < $N; $i++) {
466
+                // Break input block into 16 32bit words (message schedule prep)
467
+                $MI = $M[$i];
468
+
469
+                // Initialize working variables
470
+                $_a = (int)$h[0];
471
+                $_b = (int)$h[1];
472
+                $_c = (int)$h[2];
473
+                $_d = (int)$h[3];
474
+                $_e = (int)$h[4];
475
+                $_f = (int)$h[5];
476
+                $_g = (int)$h[6];
477
+                $_h = (int)$h[7];
478
+                unset($_s0);
479
+                unset($_s1);
480
+                unset($_T1);
481
+                unset($_T2);
482
+                $W = array();
483
+
484
+                // Compute the hash and update
485
+                for ($t = 0; $t < 16; $t++) {
486
+                    // Prepare the first 16 message schedule values as we loop
487
+                    $W[$t] = $MI[$t];
488
+
489
+                    // Compute hash
490
+                    $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)),
491
+                        $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]);
492
+                    $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
493
+
494
+                    // Update working variables
495
+                    $_h = $_g;
496
+                    $_g = $_f;
497
+                    $_f = $_e;
498
+                    $_e = $this->addmod2n($_d, $_T1);
499
+                    $_d = $_c;
500
+                    $_c = $_b;
501
+                    $_b = $_a;
502
+                    $_a = $this->addmod2n($_T1, $_T2);
503
+                }
504
+
505
+                for (; $t < 64; $t++) {
506
+                    // Continue building the message schedule as we loop
507
+                    $_s0 = $W[($t+1) & 0x0F];
508
+                    $_s0 = $this->sigma_0($_s0);
509
+                    $_s1 = $W[($t+14) & 0x0F];
510
+                    $_s1 = $this->sigma_1($_s1);
511
+
512
+                    $W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]);
513
+
514
+                    // Compute hash
515
+                    $_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)),
516
+                        $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t & 0xF]);
517
+                    $_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
518
+
519
+                    // Update working variables
520
+                    $_h = $_g;
521
+                    $_g = $_f;
522
+                    $_f = $_e;
523
+                    $_e = $this->addmod2n($_d, $_T1);
524
+                    $_d = $_c;
525
+                    $_c = $_b;
526
+                    $_b = $_a;
527
+                    $_a = $this->addmod2n($_T1, $_T2);
528
+                }
529
+
530
+                $h[0] = $this->addmod2n($h[0], $_a);
531
+                $h[1] = $this->addmod2n($h[1], $_b);
532
+                $h[2] = $this->addmod2n($h[2], $_c);
533
+                $h[3] = $this->addmod2n($h[3], $_d);
534
+                $h[4] = $this->addmod2n($h[4], $_e);
535
+                $h[5] = $this->addmod2n($h[5], $_f);
536
+                $h[6] = $this->addmod2n($h[6], $_g);
537
+                $h[7] = $this->addmod2n($h[7], $_h);
538
+            }
539
+
540
+            // Convert the 32-bit words into human readable hexadecimal format.
541
+            $hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]);
542
+
543
+            return ($this->toUpper) ? strtoupper($hexStr) : $hexStr;
544
+        }
545
+
546
+    }
547 547
 }
548 548
 
549 549
 /**
@@ -562,42 +562,42 @@  discard block
 block discarded – undo
562 562
  * @return string Le SHA de la chaîne
563 563
  */
564 564
 function _nano_sha256($str, $ig_func = true) {
565
-	$obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
565
+    $obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
566 566
 
567
-	return $obj->hash($str, $ig_func);
567
+    return $obj->hash($str, $ig_func);
568 568
 }
569 569
 
570 570
 // 2009-07-23: Added check for function as the Suhosin plugin adds this routine.
571 571
 if (!function_exists('sha256')) {
572
-	/**
573
-	 * Calcul du SHA256
574
-	 *
575
-	 * @param string $str Chaîne dont on veut calculer le SHA
576
-	 * @param bool $ig_func
577
-	 * @return string Le SHA de la chaîne
578
-	 */
579
-	function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); }
572
+    /**
573
+     * Calcul du SHA256
574
+     *
575
+     * @param string $str Chaîne dont on veut calculer le SHA
576
+     * @param bool $ig_func
577
+     * @return string Le SHA de la chaîne
578
+     */
579
+    function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); }
580 580
 }
581 581
 
582 582
 // support to give php4 the hash() routine which abstracts this code.
583 583
 if (!function_exists('hash')) {
584
-	define('_NO_HASH_DEFINED', true);
585
-	/**
586
-	 * Retourne le calcul d'un hachage d'une chaîne (pour PHP4)
587
-	 *
588
-	 * @param string $algo Nom de l'algorythme de hachage
589
-	 * @param string $data Chaîne à hacher
590
-	 * @return string|bool
591
-	 *     Hash de la chaîne
592
-	 *     False si pas d'algo trouvé
593
-	 */
594
-	function hash($algo, $data) {
595
-		if (empty($algo) || !is_string($algo) || !is_string($data)) {
596
-			return false;
597
-		}
598
-
599
-		if (function_exists($algo)) {
600
-			return $algo($data);
601
-		}
602
-	}
584
+    define('_NO_HASH_DEFINED', true);
585
+    /**
586
+     * Retourne le calcul d'un hachage d'une chaîne (pour PHP4)
587
+     *
588
+     * @param string $algo Nom de l'algorythme de hachage
589
+     * @param string $data Chaîne à hacher
590
+     * @return string|bool
591
+     *     Hash de la chaîne
592
+     *     False si pas d'algo trouvé
593
+     */
594
+    function hash($algo, $data) {
595
+        if (empty($algo) || !is_string($algo) || !is_string($data)) {
596
+            return false;
597
+        }
598
+
599
+        if (function_exists($algo)) {
600
+            return $algo($data);
601
+        }
602
+    }
603 603
 }
604 604
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 				: ((defined('_NANO_SHA2_UPPER')) ? true : false);
99 99
 
100 100
 			// Deteremine if the system is 32 or 64 bit.
101
-			$tmpInt = (int)4294967295;
101
+			$tmpInt = (int) 4294967295;
102 102
 			$this->platform = ($tmpInt > 0) ? 64 : 32;
103 103
 		}
104 104
 
@@ -116,15 +116,15 @@  discard block
 block discarded – undo
116 116
 
117 117
 			if ($x < 0) {
118 118
 				$x &= 0x7FFFFFFF;
119
-				$x = (float)$x+$mask;
119
+				$x = (float) $x + $mask;
120 120
 			}
121 121
 
122 122
 			if ($y < 0) {
123 123
 				$y &= 0x7FFFFFFF;
124
-				$y = (float)$y+$mask;
124
+				$y = (float) $y + $mask;
125 125
 			}
126 126
 
127
-			$r = $x+$y;
127
+			$r = $x + $y;
128 128
 
129 129
 			if ($r >= $n) {
130 130
 				while ($r >= $n) {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 				}
133 133
 			}
134 134
 
135
-			return (int)$r;
135
+			return (int) $r;
136 136
 		}
137 137
 
138 138
 		/**
@@ -145,23 +145,23 @@  discard block
 block discarded – undo
145 145
 		function SHR($x, $n)        // x >> n
146 146
 		{
147 147
 			if ($n >= 32) {      // impose some limits to keep it 32-bit
148
-				return (int)0;
148
+				return (int) 0;
149 149
 			}
150 150
 
151 151
 			if ($n <= 0) {
152
-				return (int)$x;
152
+				return (int) $x;
153 153
 			}
154 154
 
155 155
 			$mask = 0x40000000;
156 156
 
157 157
 			if ($x < 0) {
158 158
 				$x &= 0x7FFFFFFF;
159
-				$mask = $mask >> ($n-1);
159
+				$mask = $mask >> ($n - 1);
160 160
 
161 161
 				return ($x >> $n) | $mask;
162 162
 			}
163 163
 
164
-			return (int)$x >> (int)$n;
164
+			return (int) $x >> (int) $n;
165 165
 		}
166 166
 
167 167
 		/** ROTR
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		 * @param int $n
171 171
 		 * @return int
172 172
 		 */
173
-		function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); }
173
+		function ROTR($x, $n) { return (int) (($this->SHR($x, $n) | ($x << (32 - $n)) & 0xFFFFFFFF)); }
174 174
 
175 175
 		/** Ch
176 176
 		 *
@@ -195,28 +195,28 @@  discard block
 block discarded – undo
195 195
 		 * @param int $x
196 196
 		 * @return int
197 197
 		 */
198
-		function Sigma0($x) { return (int)($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); }
198
+		function Sigma0($x) { return (int) ($this->ROTR($x, 2) ^ $this->ROTR($x, 13) ^ $this->ROTR($x, 22)); }
199 199
 
200 200
 		/** Sigma1
201 201
 		 *
202 202
 		 * @param int $x
203 203
 		 * @return int
204 204
 		 */
205
-		function Sigma1($x) { return (int)($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); }
205
+		function Sigma1($x) { return (int) ($this->ROTR($x, 6) ^ $this->ROTR($x, 11) ^ $this->ROTR($x, 25)); }
206 206
 
207 207
 		/** Sigma_0
208 208
 		 *
209 209
 		 * @param int $x
210 210
 		 * @return int
211 211
 		 */
212
-		function sigma_0($x) { return (int)($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); }
212
+		function sigma_0($x) { return (int) ($this->ROTR($x, 7) ^ $this->ROTR($x, 18) ^ $this->SHR($x, 3)); }
213 213
 
214 214
 		/** Sigma_1
215 215
 		 *
216 216
 		 * @param int $x
217 217
 		 * @return int
218 218
 		 */
219
-		function sigma_1($x) { return (int)($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); }
219
+		function sigma_1($x) { return (int) ($this->ROTR($x, 17) ^ $this->ROTR($x, 19) ^ $this->SHR($x, 10)); }
220 220
 
221 221
 		/** String 2 ord UTF8
222 222
 		 *
@@ -271,23 +271,23 @@  discard block
 block discarded – undo
271 271
 
272 272
 					return $h;
273 273
 				} else {
274
-					if ($h <= 0xDF && $index < $len-1) {
274
+					if ($h <= 0xDF && $index < $len - 1) {
275 275
 						$bytes = 2;
276 276
 
277
-						return ($h & 0x1F) << 6 | (ord($c{$index+1}) & 0x3F);
277
+						return ($h & 0x1F) << 6 | (ord($c{$index + 1}) & 0x3F);
278 278
 					} else {
279
-						if ($h <= 0xEF && $index < $len-2) {
279
+						if ($h <= 0xEF && $index < $len - 2) {
280 280
 							$bytes = 3;
281 281
 
282
-							return ($h & 0x0F) << 12 | (ord($c{$index+1}) & 0x3F) << 6
283
-							| (ord($c{$index+2}) & 0x3F);
282
+							return ($h & 0x0F) << 12 | (ord($c{$index + 1}) & 0x3F) << 6
283
+							| (ord($c{$index + 2}) & 0x3F);
284 284
 						} else {
285
-							if ($h <= 0xF4 && $index < $len-3) {
285
+							if ($h <= 0xF4 && $index < $len - 3) {
286 286
 								$bytes = 4;
287 287
 
288
-								return ($h & 0x0F) << 18 | (ord($c{$index+1}) & 0x3F) << 12
289
-								| (ord($c{$index+2}) & 0x3F) << 6
290
-								| (ord($c{$index+3}) & 0x3F);
288
+								return ($h & 0x0F) << 18 | (ord($c{$index + 1}) & 0x3F) << 12
289
+								| (ord($c{$index + 2}) & 0x3F) << 6
290
+								| (ord($c{$index + 3}) & 0x3F);
291 291
 							} else {
292 292
 								// pas utf mais renvoyer quand meme ce qu'on a
293 293
 								$bytes = 1;
@@ -309,19 +309,19 @@  discard block
 block discarded – undo
309 309
 		function string2binint($str, $npad = 512) {
310 310
 			$bin = array();
311 311
 			$ords = $this->string2ordUTF8($str, $this->bytesString);
312
-			$npad = $npad/$this->bytesString;
312
+			$npad = $npad / $this->bytesString;
313 313
 			$length = count($ords);
314 314
 			$ords[] = 0x80; // append the "1" bit followed by 7 0's
315
-			$pad = ceil(($length+1+32/$this->bytesString)/$npad)*$npad-32/$this->bytesString;
315
+			$pad = ceil(($length + 1 + 32 / $this->bytesString) / $npad) * $npad - 32 / $this->bytesString;
316 316
 			$ords = array_pad($ords, $pad, 0);
317
-			$mask = (1 << $this->bytesString)-1;
318
-			for ($i = 0; $i < count($ords)*$this->bytesString; $i += $this->bytesString) {
317
+			$mask = (1 << $this->bytesString) - 1;
318
+			for ($i = 0; $i < count($ords) * $this->bytesString; $i += $this->bytesString) {
319 319
 				if (!isset($bin[$i >> 5])) {
320 320
 					$bin[$i >> 5] = 0;
321 321
 				} // pour eviter des notices.
322
-				$bin[$i >> 5] |= ($ords[$i/$this->bytesString] & $mask) << (24-$i%32);
322
+				$bin[$i >> 5] |= ($ords[$i / $this->bytesString] & $mask) << (24 - $i % 32);
323 323
 			}
324
-			$bin[] = $length*$this->bytesString;
324
+			$bin[] = $length * $this->bytesString;
325 325
 
326 326
 			return $bin;
327 327
 		}
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 		 * @return string Hexadecimal representation of the message digest
358 358
 		 */
359 359
 		function hash($str, $ig_func = true) {
360
-			unset($binStr);     // binary representation of input string
361
-			unset($hexStr);     // 256-bit message digest in readable hex format
360
+			unset($binStr); // binary representation of input string
361
+			unset($hexStr); // 256-bit message digest in readable hex format
362 362
 
363 363
 			// check for php's internal sha256 function, ignore if ig_func==true
364 364
 			if ($ig_func == false) {
@@ -378,70 +378,70 @@  discard block
 block discarded – undo
378 378
 			 *  of the first sixtyfour prime numbers.
379 379
 			 */
380 380
 			$K = array(
381
-				(int)0x428a2f98,
382
-				(int)0x71374491,
383
-				(int)0xb5c0fbcf,
384
-				(int)0xe9b5dba5,
385
-				(int)0x3956c25b,
386
-				(int)0x59f111f1,
387
-				(int)0x923f82a4,
388
-				(int)0xab1c5ed5,
389
-				(int)0xd807aa98,
390
-				(int)0x12835b01,
391
-				(int)0x243185be,
392
-				(int)0x550c7dc3,
393
-				(int)0x72be5d74,
394
-				(int)0x80deb1fe,
395
-				(int)0x9bdc06a7,
396
-				(int)0xc19bf174,
397
-				(int)0xe49b69c1,
398
-				(int)0xefbe4786,
399
-				(int)0x0fc19dc6,
400
-				(int)0x240ca1cc,
401
-				(int)0x2de92c6f,
402
-				(int)0x4a7484aa,
403
-				(int)0x5cb0a9dc,
404
-				(int)0x76f988da,
405
-				(int)0x983e5152,
406
-				(int)0xa831c66d,
407
-				(int)0xb00327c8,
408
-				(int)0xbf597fc7,
409
-				(int)0xc6e00bf3,
410
-				(int)0xd5a79147,
411
-				(int)0x06ca6351,
412
-				(int)0x14292967,
413
-				(int)0x27b70a85,
414
-				(int)0x2e1b2138,
415
-				(int)0x4d2c6dfc,
416
-				(int)0x53380d13,
417
-				(int)0x650a7354,
418
-				(int)0x766a0abb,
419
-				(int)0x81c2c92e,
420
-				(int)0x92722c85,
421
-				(int)0xa2bfe8a1,
422
-				(int)0xa81a664b,
423
-				(int)0xc24b8b70,
424
-				(int)0xc76c51a3,
425
-				(int)0xd192e819,
426
-				(int)0xd6990624,
427
-				(int)0xf40e3585,
428
-				(int)0x106aa070,
429
-				(int)0x19a4c116,
430
-				(int)0x1e376c08,
431
-				(int)0x2748774c,
432
-				(int)0x34b0bcb5,
433
-				(int)0x391c0cb3,
434
-				(int)0x4ed8aa4a,
435
-				(int)0x5b9cca4f,
436
-				(int)0x682e6ff3,
437
-				(int)0x748f82ee,
438
-				(int)0x78a5636f,
439
-				(int)0x84c87814,
440
-				(int)0x8cc70208,
441
-				(int)0x90befffa,
442
-				(int)0xa4506ceb,
443
-				(int)0xbef9a3f7,
444
-				(int)0xc67178f2
381
+				(int) 0x428a2f98,
382
+				(int) 0x71374491,
383
+				(int) 0xb5c0fbcf,
384
+				(int) 0xe9b5dba5,
385
+				(int) 0x3956c25b,
386
+				(int) 0x59f111f1,
387
+				(int) 0x923f82a4,
388
+				(int) 0xab1c5ed5,
389
+				(int) 0xd807aa98,
390
+				(int) 0x12835b01,
391
+				(int) 0x243185be,
392
+				(int) 0x550c7dc3,
393
+				(int) 0x72be5d74,
394
+				(int) 0x80deb1fe,
395
+				(int) 0x9bdc06a7,
396
+				(int) 0xc19bf174,
397
+				(int) 0xe49b69c1,
398
+				(int) 0xefbe4786,
399
+				(int) 0x0fc19dc6,
400
+				(int) 0x240ca1cc,
401
+				(int) 0x2de92c6f,
402
+				(int) 0x4a7484aa,
403
+				(int) 0x5cb0a9dc,
404
+				(int) 0x76f988da,
405
+				(int) 0x983e5152,
406
+				(int) 0xa831c66d,
407
+				(int) 0xb00327c8,
408
+				(int) 0xbf597fc7,
409
+				(int) 0xc6e00bf3,
410
+				(int) 0xd5a79147,
411
+				(int) 0x06ca6351,
412
+				(int) 0x14292967,
413
+				(int) 0x27b70a85,
414
+				(int) 0x2e1b2138,
415
+				(int) 0x4d2c6dfc,
416
+				(int) 0x53380d13,
417
+				(int) 0x650a7354,
418
+				(int) 0x766a0abb,
419
+				(int) 0x81c2c92e,
420
+				(int) 0x92722c85,
421
+				(int) 0xa2bfe8a1,
422
+				(int) 0xa81a664b,
423
+				(int) 0xc24b8b70,
424
+				(int) 0xc76c51a3,
425
+				(int) 0xd192e819,
426
+				(int) 0xd6990624,
427
+				(int) 0xf40e3585,
428
+				(int) 0x106aa070,
429
+				(int) 0x19a4c116,
430
+				(int) 0x1e376c08,
431
+				(int) 0x2748774c,
432
+				(int) 0x34b0bcb5,
433
+				(int) 0x391c0cb3,
434
+				(int) 0x4ed8aa4a,
435
+				(int) 0x5b9cca4f,
436
+				(int) 0x682e6ff3,
437
+				(int) 0x748f82ee,
438
+				(int) 0x78a5636f,
439
+				(int) 0x84c87814,
440
+				(int) 0x8cc70208,
441
+				(int) 0x90befffa,
442
+				(int) 0xa4506ceb,
443
+				(int) 0xbef9a3f7,
444
+				(int) 0xc67178f2
445 445
 			);
446 446
 
447 447
 			// Pre-processing: Padding the string
@@ -451,14 +451,14 @@  discard block
 block discarded – undo
451 451
 			$M = $this->array_split($binStr, 16);
452 452
 
453 453
 			// Set the initial hash values
454
-			$h[0] = (int)0x6a09e667;
455
-			$h[1] = (int)0xbb67ae85;
456
-			$h[2] = (int)0x3c6ef372;
457
-			$h[3] = (int)0xa54ff53a;
458
-			$h[4] = (int)0x510e527f;
459
-			$h[5] = (int)0x9b05688c;
460
-			$h[6] = (int)0x1f83d9ab;
461
-			$h[7] = (int)0x5be0cd19;
454
+			$h[0] = (int) 0x6a09e667;
455
+			$h[1] = (int) 0xbb67ae85;
456
+			$h[2] = (int) 0x3c6ef372;
457
+			$h[3] = (int) 0xa54ff53a;
458
+			$h[4] = (int) 0x510e527f;
459
+			$h[5] = (int) 0x9b05688c;
460
+			$h[6] = (int) 0x1f83d9ab;
461
+			$h[7] = (int) 0x5be0cd19;
462 462
 
463 463
 			// loop through message blocks and compute hash. ( For i=1 to N : )
464 464
 			$N = count($M);
@@ -467,14 +467,14 @@  discard block
 block discarded – undo
467 467
 				$MI = $M[$i];
468 468
 
469 469
 				// Initialize working variables
470
-				$_a = (int)$h[0];
471
-				$_b = (int)$h[1];
472
-				$_c = (int)$h[2];
473
-				$_d = (int)$h[3];
474
-				$_e = (int)$h[4];
475
-				$_f = (int)$h[5];
476
-				$_g = (int)$h[6];
477
-				$_h = (int)$h[7];
470
+				$_a = (int) $h[0];
471
+				$_b = (int) $h[1];
472
+				$_c = (int) $h[2];
473
+				$_d = (int) $h[3];
474
+				$_e = (int) $h[4];
475
+				$_f = (int) $h[5];
476
+				$_g = (int) $h[6];
477
+				$_h = (int) $h[7];
478 478
 				unset($_s0);
479 479
 				unset($_s1);
480 480
 				unset($_T1);
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
 
505 505
 				for (; $t < 64; $t++) {
506 506
 					// Continue building the message schedule as we loop
507
-					$_s0 = $W[($t+1) & 0x0F];
507
+					$_s0 = $W[($t + 1) & 0x0F];
508 508
 					$_s0 = $this->sigma_0($_s0);
509
-					$_s1 = $W[($t+14) & 0x0F];
509
+					$_s1 = $W[($t + 14) & 0x0F];
510 510
 					$_s1 = $this->sigma_1($_s1);
511 511
 
512
-					$W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t+9) & 0x0F]);
512
+					$W[$t & 0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t & 0xF], $_s0), $_s1), $W[($t + 9) & 0x0F]);
513 513
 
514 514
 					// Compute hash
515 515
 					$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)),
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
  *
84 84
  * @param bool|string $stat
85 85
  *     true, false ou le statut déjà défini si traitements enchaînés.
86
- * @return bool
86
+ * @return false|null
87 87
  *     true si il faut supprimer le fichier temporaire ; false sinon.
88 88
  */
89 89
 function statut_effacer_images_temporaires($stat) {
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
  *
555 555
  * @uses statut_effacer_images_temporaires()
556 556
  *
557
- * @param ressource $img
557
+ * @param resource $img
558 558
  *     Une ressource de type Image GD.
559 559
  * @param array $valeurs
560 560
  *     Un tableau des informations (tailles, traitement, path...) accompagnant
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	/**
1401 1401
 	 * Transforme une ressource GD en image au format ICO
1402 1402
 	 *
1403
-	 * @param array $gd_image_array
1403
+	 * @param Ressource[] $gd_image_array
1404 1404
 	 *     Tableau de ressources d'images GD
1405 1405
 	 * @return string
1406 1406
 	 *     Image au format ICO
Please login to merge, or discard this patch.
Indentation   +1082 added lines, -1082 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 include_spip('inc/filtres'); // par precaution
25 25
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
  *     Le code de la couleur en hexadécimal.
38 38
  */
39 39
 function _couleur_dec_to_hex($red, $green, $blue) {
40
-	$red = dechex($red);
41
-	$green = dechex($green);
42
-	$blue = dechex($blue);
43
-
44
-	if (strlen($red) == 1) {
45
-		$red = "0" . $red;
46
-	}
47
-	if (strlen($green) == 1) {
48
-		$green = "0" . $green;
49
-	}
50
-	if (strlen($blue) == 1) {
51
-		$blue = "0" . $blue;
52
-	}
53
-
54
-	return "$red$green$blue";
40
+    $red = dechex($red);
41
+    $green = dechex($green);
42
+    $blue = dechex($blue);
43
+
44
+    if (strlen($red) == 1) {
45
+        $red = "0" . $red;
46
+    }
47
+    if (strlen($green) == 1) {
48
+        $green = "0" . $green;
49
+    }
50
+    if (strlen($blue) == 1) {
51
+        $blue = "0" . $blue;
52
+    }
53
+
54
+    return "$red$green$blue";
55 55
 }
56 56
 
57 57
 /**
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
  *     Un tableau des 3 éléments : rouge, vert, bleu.
64 64
  */
65 65
 function _couleur_hex_to_dec($couleur) {
66
-	$couleur = couleur_html_to_hex($couleur);
67
-	$couleur = preg_replace(",^#,", "", $couleur);
68
-	$retour["red"] = hexdec(substr($couleur, 0, 2));
69
-	$retour["green"] = hexdec(substr($couleur, 2, 2));
70
-	$retour["blue"] = hexdec(substr($couleur, 4, 2));
66
+    $couleur = couleur_html_to_hex($couleur);
67
+    $couleur = preg_replace(",^#,", "", $couleur);
68
+    $retour["red"] = hexdec(substr($couleur, 0, 2));
69
+    $retour["green"] = hexdec(substr($couleur, 2, 2));
70
+    $retour["blue"] = hexdec(substr($couleur, 4, 2));
71 71
 
72
-	return $retour;
72
+    return $retour;
73 73
 }
74 74
 
75 75
 
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
  *     true si il faut supprimer le fichier temporaire ; false sinon.
88 88
  */
89 89
 function statut_effacer_images_temporaires($stat) {
90
-	static $statut = false; // par defaut on grave toute les images
91
-	if ($stat === 'get') {
92
-		return $statut;
93
-	}
94
-	$statut = $stat ? true : false;
90
+    static $statut = false; // par defaut on grave toute les images
91
+    if ($stat === 'get') {
92
+        return $statut;
93
+    }
94
+    $statut = $stat ? true : false;
95 95
 }
96 96
 
97 97
 
@@ -137,215 +137,215 @@  discard block
 block discarded – undo
137 137
  *     - array : tableau décrivant de l'image
138 138
  */
139 139
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false) {
140
-	static $images_recalcul = array();
141
-	if (strlen($img) == 0) {
142
-		return false;
143
-	}
144
-
145
-	$source = trim(extraire_attribut($img, 'src'));
146
-	if (strlen($source) < 1) {
147
-		$source = $img;
148
-		$img = "<img src='$source' />";
149
-	} # gerer img src="data:....base64"
150
-	elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
151
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
152
-		if (!file_exists($local)) {
153
-			ecrire_fichier($local, base64_decode($regs[2]));
154
-		}
155
-		$source = $local;
156
-		$img = inserer_attribut($img, 'src', $source);
157
-		# eviter les mauvaises surprises lors de conversions de format
158
-		$img = inserer_attribut($img, 'width', '');
159
-		$img = inserer_attribut($img, 'height', '');
160
-	}
161
-
162
-	// les protocoles web prennent au moins 3 lettres
163
-	if (tester_url_absolue($source)) {
164
-		include_spip('inc/distant');
165
-		$fichier = _DIR_RACINE . copie_locale($source);
166
-		if (!$fichier) {
167
-			return "";
168
-		}
169
-	} else {
170
-		// enlever le timestamp eventuel
171
-		if (strpos($source, "?") !== false) {
172
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
173
-		}
174
-		if (strpos($source, "?") !== false
175
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
176
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
177
-		) {
178
-			$source = $f;
179
-		}
180
-		$fichier = $source;
181
-	}
182
-
183
-	$terminaison_dest = "";
184
-	if ($terminaison = _image_trouver_extension($fichier)) {
185
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
186
-	}
187
-
188
-	if ($forcer_format !== false) {
189
-		$terminaison_dest = $forcer_format;
190
-	}
191
-
192
-	if (!$terminaison_dest) {
193
-		return false;
194
-	}
195
-
196
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
197
-	$fichier_dest = $nom_fichier;
198
-	if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
199
-		or @file_exists($f = $fichier)
200
-	) {
201
-		// on passe la balise img a taille image qui exraira les attributs si possible
202
-		// au lieu de faire un acces disque sur le fichier
203
-		list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
204
-		$date_src = @filemtime($f);
205
-	} elseif (@file_exists($f = "$fichier.src")
206
-		and lire_fichier($f, $valeurs)
207
-		and $valeurs = unserialize($valeurs)
208
-		and isset($valeurs["hauteur_dest"])
209
-		and isset($valeurs["largeur_dest"])
210
-	) {
211
-		$ret["hauteur"] = $valeurs["hauteur_dest"];
212
-		$ret["largeur"] = $valeurs["largeur_dest"];
213
-		$date_src = $valeurs["date"];
214
-	} // pas de fichier source par la
215
-	else {
216
-		return false;
217
-	}
218
-
219
-	// pas de taille mesurable
220
-	if (!($ret["hauteur"] or $ret["largeur"])) {
221
-		return false;
222
-	}
223
-
224
-	// les images calculees dependent du chemin du fichier source
225
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
226
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
227
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
228
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
229
-	// alors que ca concerne peu de site au final
230
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
231
-	$identifiant = $fichier;
232
-
233
-	// cas general :
234
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
235
-	// cas particulier de reduire :
236
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
237
-	$cache = "cache-gd2";
238
-	if (substr($effet, 0, 7) == 'reduire') {
239
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
240
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
241
-		$ret['largeur_dest'] = $destWidth;
242
-		$ret['hauteur_dest'] = $destHeight;
243
-		$effet = "L{$destWidth}xH$destHeight";
244
-		$cache = "cache-vignettes";
245
-		$fichier_dest = basename($fichier_dest);
246
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
247
-			// on garde la terminaison initiale car image simplement copiee
248
-			// et on postfixe son nom avec un md5 du path
249
-			$terminaison_dest = $terminaison;
250
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
251
-		} else {
252
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
253
-		}
254
-		$cache = sous_repertoire(_DIR_VAR, $cache);
255
-		$cache = sous_repertoire($cache, $effet);
256
-		# cherche un cache existant
257
-		/*foreach (array('gif','jpg','png') as $fmt)
140
+    static $images_recalcul = array();
141
+    if (strlen($img) == 0) {
142
+        return false;
143
+    }
144
+
145
+    $source = trim(extraire_attribut($img, 'src'));
146
+    if (strlen($source) < 1) {
147
+        $source = $img;
148
+        $img = "<img src='$source' />";
149
+    } # gerer img src="data:....base64"
150
+    elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
151
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
152
+        if (!file_exists($local)) {
153
+            ecrire_fichier($local, base64_decode($regs[2]));
154
+        }
155
+        $source = $local;
156
+        $img = inserer_attribut($img, 'src', $source);
157
+        # eviter les mauvaises surprises lors de conversions de format
158
+        $img = inserer_attribut($img, 'width', '');
159
+        $img = inserer_attribut($img, 'height', '');
160
+    }
161
+
162
+    // les protocoles web prennent au moins 3 lettres
163
+    if (tester_url_absolue($source)) {
164
+        include_spip('inc/distant');
165
+        $fichier = _DIR_RACINE . copie_locale($source);
166
+        if (!$fichier) {
167
+            return "";
168
+        }
169
+    } else {
170
+        // enlever le timestamp eventuel
171
+        if (strpos($source, "?") !== false) {
172
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
173
+        }
174
+        if (strpos($source, "?") !== false
175
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
176
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
177
+        ) {
178
+            $source = $f;
179
+        }
180
+        $fichier = $source;
181
+    }
182
+
183
+    $terminaison_dest = "";
184
+    if ($terminaison = _image_trouver_extension($fichier)) {
185
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
186
+    }
187
+
188
+    if ($forcer_format !== false) {
189
+        $terminaison_dest = $forcer_format;
190
+    }
191
+
192
+    if (!$terminaison_dest) {
193
+        return false;
194
+    }
195
+
196
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
197
+    $fichier_dest = $nom_fichier;
198
+    if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
199
+        or @file_exists($f = $fichier)
200
+    ) {
201
+        // on passe la balise img a taille image qui exraira les attributs si possible
202
+        // au lieu de faire un acces disque sur le fichier
203
+        list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
204
+        $date_src = @filemtime($f);
205
+    } elseif (@file_exists($f = "$fichier.src")
206
+        and lire_fichier($f, $valeurs)
207
+        and $valeurs = unserialize($valeurs)
208
+        and isset($valeurs["hauteur_dest"])
209
+        and isset($valeurs["largeur_dest"])
210
+    ) {
211
+        $ret["hauteur"] = $valeurs["hauteur_dest"];
212
+        $ret["largeur"] = $valeurs["largeur_dest"];
213
+        $date_src = $valeurs["date"];
214
+    } // pas de fichier source par la
215
+    else {
216
+        return false;
217
+    }
218
+
219
+    // pas de taille mesurable
220
+    if (!($ret["hauteur"] or $ret["largeur"])) {
221
+        return false;
222
+    }
223
+
224
+    // les images calculees dependent du chemin du fichier source
225
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
226
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
227
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
228
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
229
+    // alors que ca concerne peu de site au final
230
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
231
+    $identifiant = $fichier;
232
+
233
+    // cas general :
234
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
235
+    // cas particulier de reduire :
236
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
237
+    $cache = "cache-gd2";
238
+    if (substr($effet, 0, 7) == 'reduire') {
239
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
240
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
241
+        $ret['largeur_dest'] = $destWidth;
242
+        $ret['hauteur_dest'] = $destHeight;
243
+        $effet = "L{$destWidth}xH$destHeight";
244
+        $cache = "cache-vignettes";
245
+        $fichier_dest = basename($fichier_dest);
246
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
247
+            // on garde la terminaison initiale car image simplement copiee
248
+            // et on postfixe son nom avec un md5 du path
249
+            $terminaison_dest = $terminaison;
250
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
251
+        } else {
252
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
253
+        }
254
+        $cache = sous_repertoire(_DIR_VAR, $cache);
255
+        $cache = sous_repertoire($cache, $effet);
256
+        # cherche un cache existant
257
+        /*foreach (array('gif','jpg','png') as $fmt)
258 258
 			if (@file_exists($cache . $fichier_dest . '.' . $fmt)) {
259 259
 				$terminaison_dest = $fmt;
260 260
 			}*/
261
-	} else {
262
-		$fichier_dest = md5("$identifiant-$effet");
263
-		$cache = sous_repertoire(_DIR_VAR, $cache);
264
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
265
-		$fichier_dest = substr($fichier_dest, 2);
266
-	}
267
-
268
-	$fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
269
-
270
-	$GLOBALS["images_calculees"][] = $fichier_dest;
271
-
272
-	$creer = true;
273
-	// si recalcul des images demande, recalculer chaque image une fois
274
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
275
-		$images_recalcul[$fichier_dest] = true;
276
-	} else {
277
-		if (@file_exists($f = $fichier_dest)) {
278
-			if (filemtime($f) >= $date_src) {
279
-				$creer = false;
280
-			}
281
-		} else {
282
-			if (@file_exists($f = "$fichier_dest.src")
283
-				and lire_fichier($f, $valeurs)
284
-				and $valeurs = unserialize($valeurs)
285
-				and $valeurs["date"] >= $date_src
286
-			) {
287
-				$creer = false;
288
-			}
289
-		}
290
-	}
291
-	if ($creer) {
292
-		if (!@file_exists($fichier)) {
293
-			if (!@file_exists("$fichier.src")) {
294
-				spip_log("Image absente : $fichier");
295
-
296
-				return false;
297
-			}
298
-			# on reconstruit l'image source absente a partir de la chaine des .src
299
-			reconstruire_image_intermediaire($fichier);
300
-		}
301
-	}
302
-
303
-	if ($creer) {
304
-		spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
305
-			"images" . _LOG_DEBUG);
306
-	}
307
-
308
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
309
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
310
-	$ret["fichier"] = $fichier;
311
-	$ret["fonction_image"] = "_image_image" . $terminaison_dest;
312
-	$ret["fichier_dest"] = $fichier_dest;
313
-	$ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
314
-	$ret["format_dest"] = $terminaison_dest;
315
-	$ret["date_src"] = $date_src;
316
-	$ret["creer"] = $creer;
317
-	$ret["class"] = extraire_attribut($img, 'class');
318
-	$ret["alt"] = extraire_attribut($img, 'alt');
319
-	$ret["style"] = extraire_attribut($img, 'style');
320
-	$ret["tag"] = $img;
321
-	if ($fonction_creation) {
322
-		$ret["reconstruction"] = $fonction_creation;
323
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
324
-		# cas de image_reduire qui finalement ne reduit pas l'image source
325
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
326
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
327
-	}
328
-
329
-	$ret = pipeline('image_preparer_filtre', array(
330
-			'args' => array(
331
-				'img' => $img,
332
-				'effet' => $effet,
333
-				'forcer_format' => $forcer_format,
334
-				'fonction_creation' => $fonction_creation,
335
-				'find_in_path' => $find_in_path,
336
-			),
337
-			'data' => $ret
338
-		)
339
-	);
340
-
341
-	// une globale pour le debug en cas de crash memoire
342
-	$GLOBALS["derniere_image_calculee"] = $ret;
343
-
344
-	if (!function_exists($ret["fonction_imagecreatefrom"])) {
345
-		return false;
346
-	}
347
-
348
-	return $ret;
261
+    } else {
262
+        $fichier_dest = md5("$identifiant-$effet");
263
+        $cache = sous_repertoire(_DIR_VAR, $cache);
264
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
265
+        $fichier_dest = substr($fichier_dest, 2);
266
+    }
267
+
268
+    $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
269
+
270
+    $GLOBALS["images_calculees"][] = $fichier_dest;
271
+
272
+    $creer = true;
273
+    // si recalcul des images demande, recalculer chaque image une fois
274
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
275
+        $images_recalcul[$fichier_dest] = true;
276
+    } else {
277
+        if (@file_exists($f = $fichier_dest)) {
278
+            if (filemtime($f) >= $date_src) {
279
+                $creer = false;
280
+            }
281
+        } else {
282
+            if (@file_exists($f = "$fichier_dest.src")
283
+                and lire_fichier($f, $valeurs)
284
+                and $valeurs = unserialize($valeurs)
285
+                and $valeurs["date"] >= $date_src
286
+            ) {
287
+                $creer = false;
288
+            }
289
+        }
290
+    }
291
+    if ($creer) {
292
+        if (!@file_exists($fichier)) {
293
+            if (!@file_exists("$fichier.src")) {
294
+                spip_log("Image absente : $fichier");
295
+
296
+                return false;
297
+            }
298
+            # on reconstruit l'image source absente a partir de la chaine des .src
299
+            reconstruire_image_intermediaire($fichier);
300
+        }
301
+    }
302
+
303
+    if ($creer) {
304
+        spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
305
+            "images" . _LOG_DEBUG);
306
+    }
307
+
308
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
309
+    $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
310
+    $ret["fichier"] = $fichier;
311
+    $ret["fonction_image"] = "_image_image" . $terminaison_dest;
312
+    $ret["fichier_dest"] = $fichier_dest;
313
+    $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
314
+    $ret["format_dest"] = $terminaison_dest;
315
+    $ret["date_src"] = $date_src;
316
+    $ret["creer"] = $creer;
317
+    $ret["class"] = extraire_attribut($img, 'class');
318
+    $ret["alt"] = extraire_attribut($img, 'alt');
319
+    $ret["style"] = extraire_attribut($img, 'style');
320
+    $ret["tag"] = $img;
321
+    if ($fonction_creation) {
322
+        $ret["reconstruction"] = $fonction_creation;
323
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
324
+        # cas de image_reduire qui finalement ne reduit pas l'image source
325
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
326
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
327
+    }
328
+
329
+    $ret = pipeline('image_preparer_filtre', array(
330
+            'args' => array(
331
+                'img' => $img,
332
+                'effet' => $effet,
333
+                'forcer_format' => $forcer_format,
334
+                'fonction_creation' => $fonction_creation,
335
+                'find_in_path' => $find_in_path,
336
+            ),
337
+            'data' => $ret
338
+        )
339
+    );
340
+
341
+    // une globale pour le debug en cas de crash memoire
342
+    $GLOBALS["derniere_image_calculee"] = $ret;
343
+
344
+    if (!function_exists($ret["fonction_imagecreatefrom"])) {
345
+        return false;
346
+    }
347
+
348
+    return $ret;
349 349
 }
350 350
 
351 351
 /**
@@ -354,11 +354,11 @@  discard block
 block discarded – undo
354 354
  * @return string
355 355
  */
356 356
 function _image_trouver_extension($path) {
357
-	if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $path, $regs)) {
358
-		$terminaison = strtolower($regs[1]);
359
-		return $terminaison;
360
-	}
361
-	return '';
357
+    if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $path, $regs)) {
358
+        $terminaison = strtolower($regs[1]);
359
+        return $terminaison;
360
+    }
361
+    return '';
362 362
 }
363 363
 
364 364
 /**
@@ -369,51 +369,51 @@  discard block
 block discarded – undo
369 369
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
370 370
  */
371 371
 function _image_trouver_extension_pertinente($path) {
372
-	$path = supprimer_timestamp($path);
373
-	$terminaison = _image_trouver_extension($path);
374
-	if ($terminaison == 'jpg') {
375
-		$terminaison = 'jpeg';
376
-	}
377
-
378
-	if (!file_exists($path)) {
379
-		return $terminaison;
380
-	}
381
-
382
-	if (!$info = @getimagesize($path)) {
383
-		return $terminaison;
384
-	}
385
-
386
-	$mime = image_type_to_mime_type($info[2]);
387
-
388
-	switch (strtolower($mime)) {
389
-		case 'image/png':
390
-		case 'image/x-png':
391
-			$_terminaison = 'png';
392
-			break;
393
-
394
-		case 'image/jpg':
395
-		case 'image/jpeg':
396
-		case 'image/pjpeg':
397
-			$_terminaison = 'jpeg';
398
-			break;
399
-
400
-		case 'image/gif':
401
-			$_terminaison = 'gif';
402
-			break;
403
-
404
-		case 'image/webp':
405
-		case 'image/x-webp':
406
-			$_terminaison = 'webp';
407
-			break;
408
-
409
-		default:
410
-			$_terminaison = '';
411
-	}
412
-	if ($_terminaison !== $terminaison) {
413
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
414
-		$terminaison = $_terminaison;
415
-	}
416
-	return $terminaison;
372
+    $path = supprimer_timestamp($path);
373
+    $terminaison = _image_trouver_extension($path);
374
+    if ($terminaison == 'jpg') {
375
+        $terminaison = 'jpeg';
376
+    }
377
+
378
+    if (!file_exists($path)) {
379
+        return $terminaison;
380
+    }
381
+
382
+    if (!$info = @getimagesize($path)) {
383
+        return $terminaison;
384
+    }
385
+
386
+    $mime = image_type_to_mime_type($info[2]);
387
+
388
+    switch (strtolower($mime)) {
389
+        case 'image/png':
390
+        case 'image/x-png':
391
+            $_terminaison = 'png';
392
+            break;
393
+
394
+        case 'image/jpg':
395
+        case 'image/jpeg':
396
+        case 'image/pjpeg':
397
+            $_terminaison = 'jpeg';
398
+            break;
399
+
400
+        case 'image/gif':
401
+            $_terminaison = 'gif';
402
+            break;
403
+
404
+        case 'image/webp':
405
+        case 'image/x-webp':
406
+            $_terminaison = 'webp';
407
+            break;
408
+
409
+        default:
410
+            $_terminaison = '';
411
+    }
412
+    if ($_terminaison !== $terminaison) {
413
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
414
+        $terminaison = $_terminaison;
415
+    }
416
+    return $terminaison;
417 417
 }
418 418
 
419 419
 /**
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
  *     Une ressource de type Image GD.
429 429
  */
430 430
 function _imagecreatefromjpeg($filename) {
431
-	$img = @imagecreatefromjpeg($filename);
432
-	if (!$img) {
433
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
434
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
435
-		$img = imagecreate(10, 10);
436
-	}
437
-
438
-	return $img;
431
+    $img = @imagecreatefromjpeg($filename);
432
+    if (!$img) {
433
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
434
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
435
+        $img = imagecreate(10, 10);
436
+    }
437
+
438
+    return $img;
439 439
 }
440 440
 
441 441
 /**
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
  *     Une ressource de type Image GD.
451 451
  */
452 452
 function _imagecreatefrompng($filename) {
453
-	$img = @imagecreatefrompng($filename);
454
-	if (!$img) {
455
-		spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
456
-		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
457
-		$img = imagecreate(10, 10);
458
-	}
459
-
460
-	return $img;
453
+    $img = @imagecreatefrompng($filename);
454
+    if (!$img) {
455
+        spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
456
+        erreur_squelette("Erreur lecture imagecreatefrompng $filename");
457
+        $img = imagecreate(10, 10);
458
+    }
459
+
460
+    return $img;
461 461
 }
462 462
 
463 463
 /**
@@ -472,14 +472,14 @@  discard block
 block discarded – undo
472 472
  *     Une ressource de type Image GD.
473 473
  */
474 474
 function _imagecreatefromgif($filename) {
475
-	$img = @imagecreatefromgif($filename);
476
-	if (!$img) {
477
-		spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
478
-		erreur_squelette("Erreur lecture imagecreatefromgif $filename");
479
-		$img = imagecreate(10, 10);
480
-	}
481
-
482
-	return $img;
475
+    $img = @imagecreatefromgif($filename);
476
+    if (!$img) {
477
+        spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
478
+        erreur_squelette("Erreur lecture imagecreatefromgif $filename");
479
+        $img = imagecreate(10, 10);
480
+    }
481
+
482
+    return $img;
483 483
 }
484 484
 
485 485
 /**
@@ -497,24 +497,24 @@  discard block
 block discarded – undo
497 497
  *     - true si une image est bien retournée.
498 498
  */
499 499
 function _image_imagepng($img, $fichier) {
500
-	if (!function_exists('imagepng')) {
501
-		return false;
502
-	}
503
-	$tmp = $fichier . ".tmp";
504
-	$ret = imagepng($img, $tmp);
505
-	if (file_exists($tmp)) {
506
-		$taille_test = getimagesize($tmp);
507
-		if ($taille_test[0] < 1) {
508
-			return false;
509
-		}
510
-
511
-		spip_unlink($fichier); // le fichier peut deja exister
512
-		@rename($tmp, $fichier);
513
-
514
-		return $ret;
515
-	}
516
-
517
-	return false;
500
+    if (!function_exists('imagepng')) {
501
+        return false;
502
+    }
503
+    $tmp = $fichier . ".tmp";
504
+    $ret = imagepng($img, $tmp);
505
+    if (file_exists($tmp)) {
506
+        $taille_test = getimagesize($tmp);
507
+        if ($taille_test[0] < 1) {
508
+            return false;
509
+        }
510
+
511
+        spip_unlink($fichier); // le fichier peut deja exister
512
+        @rename($tmp, $fichier);
513
+
514
+        return $ret;
515
+    }
516
+
517
+    return false;
518 518
 }
519 519
 
520 520
 /**
@@ -532,24 +532,24 @@  discard block
 block discarded – undo
532 532
  *     - true si une image est bien retournée.
533 533
  */
534 534
 function _image_imagegif($img, $fichier) {
535
-	if (!function_exists('imagegif')) {
536
-		return false;
537
-	}
538
-	$tmp = $fichier . ".tmp";
539
-	$ret = imagegif($img, $tmp);
540
-	if (file_exists($tmp)) {
541
-		$taille_test = getimagesize($tmp);
542
-		if ($taille_test[0] < 1) {
543
-			return false;
544
-		}
545
-
546
-		spip_unlink($fichier); // le fichier peut deja exister
547
-		@rename($tmp, $fichier);
548
-
549
-		return $ret;
550
-	}
551
-
552
-	return false;
535
+    if (!function_exists('imagegif')) {
536
+        return false;
537
+    }
538
+    $tmp = $fichier . ".tmp";
539
+    $ret = imagegif($img, $tmp);
540
+    if (file_exists($tmp)) {
541
+        $taille_test = getimagesize($tmp);
542
+        if ($taille_test[0] < 1) {
543
+            return false;
544
+        }
545
+
546
+        spip_unlink($fichier); // le fichier peut deja exister
547
+        @rename($tmp, $fichier);
548
+
549
+        return $ret;
550
+    }
551
+
552
+    return false;
553 553
 }
554 554
 
555 555
 /**
@@ -572,29 +572,29 @@  discard block
 block discarded – undo
572 572
  *     - true si une image est bien retournée.
573 573
  */
574 574
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
575
-	if (!function_exists('imagejpeg')) {
576
-		return false;
577
-	}
578
-	$tmp = $fichier . ".tmp";
575
+    if (!function_exists('imagejpeg')) {
576
+        return false;
577
+    }
578
+    $tmp = $fichier . ".tmp";
579 579
 
580
-	// Enable interlancing
581
-	imageinterlace($img, true);
580
+    // Enable interlancing
581
+    imageinterlace($img, true);
582 582
 
583
-	$ret = imagejpeg($img, $tmp, $qualite);
583
+    $ret = imagejpeg($img, $tmp, $qualite);
584 584
 
585
-	if (file_exists($tmp)) {
586
-		$taille_test = getimagesize($tmp);
587
-		if ($taille_test[0] < 1) {
588
-			return false;
589
-		}
585
+    if (file_exists($tmp)) {
586
+        $taille_test = getimagesize($tmp);
587
+        if ($taille_test[0] < 1) {
588
+            return false;
589
+        }
590 590
 
591
-		spip_unlink($fichier); // le fichier peut deja exister
592
-		@rename($tmp, $fichier);
591
+        spip_unlink($fichier); // le fichier peut deja exister
592
+        @rename($tmp, $fichier);
593 593
 
594
-		return $ret;
595
-	}
594
+        return $ret;
595
+    }
596 596
 
597
-	return false;
597
+    return false;
598 598
 }
599 599
 
600 600
 /**
@@ -612,9 +612,9 @@  discard block
 block discarded – undo
612 612
  *     true si le fichier a bien été créé ; false sinon.
613 613
  */
614 614
 function _image_imageico($img, $fichier) {
615
-	$gd_image_array = array($img);
615
+    $gd_image_array = array($img);
616 616
 
617
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
617
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
618 618
 }
619 619
 
620 620
 /**
@@ -641,27 +641,27 @@  discard block
 block discarded – undo
641 641
  *     - false sinon.
642 642
  */
643 643
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
644
-	$fonction = "_image_image" . $valeurs['format_dest'];
645
-	$ret = false;
646
-	#un flag pour reperer les images gravees
647
-	$lock =
648
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
649
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
650
-	if (
651
-		function_exists($fonction)
652
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
653
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
654
-		&& !$lock
655
-	) {
656
-		if (@file_exists($valeurs['fichier_dest'])) {
657
-			// dans tous les cas mettre a jour la taille de l'image finale
658
-			list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
659
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
660
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
661
-		}
662
-	}
663
-
664
-	return $ret;
644
+    $fonction = "_image_image" . $valeurs['format_dest'];
645
+    $ret = false;
646
+    #un flag pour reperer les images gravees
647
+    $lock =
648
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
649
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
650
+    if (
651
+        function_exists($fonction)
652
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
653
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
654
+        && !$lock
655
+    ) {
656
+        if (@file_exists($valeurs['fichier_dest'])) {
657
+            // dans tous les cas mettre a jour la taille de l'image finale
658
+            list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
659
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
660
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
661
+        }
662
+    }
663
+
664
+    return $ret;
665 665
 }
666 666
 
667 667
 /**
@@ -674,26 +674,26 @@  discard block
 block discarded – undo
674 674
  *     Chemin vers le fichier manquant
675 675
  **/
676 676
 function reconstruire_image_intermediaire($fichier_manquant) {
677
-	$reconstruire = array();
678
-	$fichier = $fichier_manquant;
679
-	while (strpos($fichier,"://")===false
680
-		and !@file_exists($fichier)
681
-		and lire_fichier($src = "$fichier.src", $source)
682
-		and $valeurs = unserialize($source)
683
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
684
-	) {
685
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
686
-		$reconstruire[] = $valeurs['reconstruction'];
687
-	}
688
-	while (count($reconstruire)) {
689
-		$r = array_pop($reconstruire);
690
-		$fonction = $r[0];
691
-		$args = $r[1];
692
-		call_user_func_array($fonction, $args);
693
-	}
694
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
695
-	// mais l'on peut nettoyer les miettes de sa creation
696
-	ramasse_miettes($fichier_manquant);
677
+    $reconstruire = array();
678
+    $fichier = $fichier_manquant;
679
+    while (strpos($fichier,"://")===false
680
+        and !@file_exists($fichier)
681
+        and lire_fichier($src = "$fichier.src", $source)
682
+        and $valeurs = unserialize($source)
683
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
684
+    ) {
685
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
686
+        $reconstruire[] = $valeurs['reconstruction'];
687
+    }
688
+    while (count($reconstruire)) {
689
+        $r = array_pop($reconstruire);
690
+        $fonction = $r[0];
691
+        $args = $r[1];
692
+        call_user_func_array($fonction, $args);
693
+    }
694
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
695
+    // mais l'on peut nettoyer les miettes de sa creation
696
+    ramasse_miettes($fichier_manquant);
697 697
 }
698 698
 
699 699
 /**
@@ -713,25 +713,25 @@  discard block
 block discarded – undo
713 713
  *     Chemin du fichier d'image calculé
714 714
  **/
715 715
 function ramasse_miettes($fichier) {
716
-	if (strpos($fichier,"://")!==false
717
-		or !lire_fichier($src = "$fichier.src", $source)
718
-		or !$valeurs = unserialize($source)
719
-	) {
720
-		return;
721
-	}
722
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
723
-	while (
724
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
725
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
726
-		and (lire_fichier($src = "$fichier.src",
727
-			$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
728
-		and ($valeurs = unserialize($source))  # et valide
729
-	) {
730
-		# on efface le fichier
731
-		spip_unlink($fichier);
732
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
733
-		#spip_unlink($src);
734
-	}
716
+    if (strpos($fichier,"://")!==false
717
+        or !lire_fichier($src = "$fichier.src", $source)
718
+        or !$valeurs = unserialize($source)
719
+    ) {
720
+        return;
721
+    }
722
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
723
+    while (
724
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
725
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
726
+        and (lire_fichier($src = "$fichier.src",
727
+            $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
728
+        and ($valeurs = unserialize($source))  # et valide
729
+    ) {
730
+        # on efface le fichier
731
+        spip_unlink($fichier);
732
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
733
+        #spip_unlink($src);
734
+    }
735 735
 }
736 736
 
737 737
 
@@ -756,71 +756,71 @@  discard block
 block discarded – undo
756 756
  *     Code HTML de l'image
757 757
  **/
758 758
 function image_graver($img) {
759
-	// appeler le filtre post_image_filtrer qui permet de faire
760
-	// des traitements auto a la fin d'une serie de filtres
761
-	$img = pipeline('post_image_filtrer', $img);
762
-
763
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
764
-	if (($p = strpos($fichier, '?')) !== false) {
765
-		$fichier = substr($fichier, 0, $p);
766
-	}
767
-	if (strlen($fichier) < 1) {
768
-		$fichier = $img;
769
-	}
770
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
771
-	# et qu'il ne s'agit pas d'une URL
772
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
773
-		reconstruire_image_intermediaire($fichier);
774
-	}
775
-	ramasse_miettes($fichier);
776
-
777
-	// ajouter le timestamp si besoin
778
-	if (strpos($fichier_ori, "?") === false) {
779
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
780
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
781
-	}
782
-
783
-	return $img;
759
+    // appeler le filtre post_image_filtrer qui permet de faire
760
+    // des traitements auto a la fin d'une serie de filtres
761
+    $img = pipeline('post_image_filtrer', $img);
762
+
763
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
764
+    if (($p = strpos($fichier, '?')) !== false) {
765
+        $fichier = substr($fichier, 0, $p);
766
+    }
767
+    if (strlen($fichier) < 1) {
768
+        $fichier = $img;
769
+    }
770
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
771
+    # et qu'il ne s'agit pas d'une URL
772
+    if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
773
+        reconstruire_image_intermediaire($fichier);
774
+    }
775
+    ramasse_miettes($fichier);
776
+
777
+    // ajouter le timestamp si besoin
778
+    if (strpos($fichier_ori, "?") === false) {
779
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
780
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
781
+    }
782
+
783
+    return $img;
784 784
 }
785 785
 
786 786
 
787 787
 if (!function_exists("imagepalettetotruecolor")) {
788
-	/**
789
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
790
-	 *
791
-	 * @note Pour compatibilité avec PHP < 5.5
792
-	 *
793
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
794
-	 *
795
-	 * @param ressource $img
796
-	 * @return bool
797
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
798
-	 *     - false si la transformation ne peut être faite.
799
-	 **/
800
-	function imagepalettetotruecolor(&$img) {
801
-		if (!$img or !function_exists('imagecreatetruecolor')) {
802
-			return false;
803
-		} elseif (!imageistruecolor($img)) {
804
-			$w = imagesx($img);
805
-			$h = imagesy($img);
806
-			$img1 = imagecreatetruecolor($w, $h);
807
-			//Conserver la transparence si possible
808
-			if (function_exists('ImageCopyResampled')) {
809
-				if (function_exists("imageAntiAlias")) {
810
-					imageAntiAlias($img1, true);
811
-				}
812
-				@imagealphablending($img1, false);
813
-				@imagesavealpha($img1, true);
814
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
815
-			} else {
816
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
817
-			}
818
-
819
-			$img = $img1;
820
-		}
821
-
822
-		return true;
823
-	}
788
+    /**
789
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
790
+     *
791
+     * @note Pour compatibilité avec PHP < 5.5
792
+     *
793
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
794
+     *
795
+     * @param ressource $img
796
+     * @return bool
797
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
798
+     *     - false si la transformation ne peut être faite.
799
+     **/
800
+    function imagepalettetotruecolor(&$img) {
801
+        if (!$img or !function_exists('imagecreatetruecolor')) {
802
+            return false;
803
+        } elseif (!imageistruecolor($img)) {
804
+            $w = imagesx($img);
805
+            $h = imagesy($img);
806
+            $img1 = imagecreatetruecolor($w, $h);
807
+            //Conserver la transparence si possible
808
+            if (function_exists('ImageCopyResampled')) {
809
+                if (function_exists("imageAntiAlias")) {
810
+                    imageAntiAlias($img1, true);
811
+                }
812
+                @imagealphablending($img1, false);
813
+                @imagesavealpha($img1, true);
814
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
815
+            } else {
816
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
817
+            }
818
+
819
+            $img = $img1;
820
+        }
821
+
822
+        return true;
823
+    }
824 824
 }
825 825
 
826 826
 /**
@@ -847,32 +847,32 @@  discard block
 block discarded – undo
847 847
  *     Code html modifié de la balise.
848 848
  **/
849 849
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
850
-	if ($style === false) {
851
-		$style = extraire_attribut($tag, 'style');
852
-	}
853
-
854
-	// enlever le width et height du style
855
-	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
856
-	if ($style and $style{0} == ';') {
857
-		$style = substr($style, 1);
858
-	}
859
-
860
-	// mettre des attributs de width et height sur les images, 
861
-	// ca accelere le rendu du navigateur
862
-	// ca permet aux navigateurs de reserver la bonne taille 
863
-	// quand on a desactive l'affichage des images.
864
-	$tag = inserer_attribut($tag, 'width', $width);
865
-	$tag = inserer_attribut($tag, 'height', $height);
866
-
867
-	// attributs deprecies. Transformer en CSS
868
-	if ($espace = extraire_attribut($tag, 'hspace')) {
869
-		$style = "margin:${espace}px;" . $style;
870
-		$tag = inserer_attribut($tag, 'hspace', '');
871
-	}
872
-
873
-	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
874
-
875
-	return $tag;
850
+    if ($style === false) {
851
+        $style = extraire_attribut($tag, 'style');
852
+    }
853
+
854
+    // enlever le width et height du style
855
+    $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
856
+    if ($style and $style{0} == ';') {
857
+        $style = substr($style, 1);
858
+    }
859
+
860
+    // mettre des attributs de width et height sur les images, 
861
+    // ca accelere le rendu du navigateur
862
+    // ca permet aux navigateurs de reserver la bonne taille 
863
+    // quand on a desactive l'affichage des images.
864
+    $tag = inserer_attribut($tag, 'width', $width);
865
+    $tag = inserer_attribut($tag, 'height', $height);
866
+
867
+    // attributs deprecies. Transformer en CSS
868
+    if ($espace = extraire_attribut($tag, 'hspace')) {
869
+        $style = "margin:${espace}px;" . $style;
870
+        $tag = inserer_attribut($tag, 'hspace', '');
871
+    }
872
+
873
+    $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
874
+
875
+    return $tag;
876 876
 }
877 877
 
878 878
 
@@ -898,71 +898,71 @@  discard block
 block discarded – undo
898 898
  *     Retourne le code HTML de l'image
899 899
  **/
900 900
 function _image_ecrire_tag($valeurs, $surcharge = array()) {
901
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
902
-
903
-	// fermer les tags img pas bien fermes;
904
-	$tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
905
-
906
-	// le style
907
-	$style = $valeurs['style'];
908
-	if (isset($surcharge['style'])) {
909
-		$style = $surcharge['style'];
910
-		unset($surcharge['style']);
911
-	}
912
-
913
-	// traiter specifiquement la largeur et la hauteur
914
-	$width = $valeurs['largeur'];
915
-	if (isset($surcharge['width'])) {
916
-		$width = $surcharge['width'];
917
-		unset($surcharge['width']);
918
-	}
919
-	$height = $valeurs['hauteur'];
920
-	if (isset($surcharge['height'])) {
921
-		$height = $surcharge['height'];
922
-		unset($surcharge['height']);
923
-	}
924
-
925
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
926
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
927
-	// on remplace toute les ref a src dans le tag
928
-	$src = extraire_attribut($tag, 'src');
929
-	if (isset($surcharge['src'])) {
930
-		$tag = str_replace($src, $surcharge['src'], $tag);
931
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
932
-		// pas garanti comme methode, mais mieux que rien
933
-		if (strpos($src, '&') !== false) {
934
-			$tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
935
-		}
936
-		$src = $surcharge['src'];
937
-		unset($surcharge['src']);
938
-	}
939
-
940
-	$class = $valeurs['class'];
941
-	if (isset($surcharge['class'])) {
942
-		$class = $surcharge['class'];
943
-		unset($surcharge['class']);
944
-	}
945
-	if (strlen($class)) {
946
-		$tag = inserer_attribut($tag, 'class', $class);
947
-	}
948
-
949
-	if (count($surcharge)) {
950
-		foreach ($surcharge as $attribut => $valeur) {
951
-			$tag = inserer_attribut($tag, $attribut, $valeur);
952
-		}
953
-	}
954
-
955
-	$tag = pipeline('image_ecrire_tag_finir',
956
-		array(
957
-			'args' => array(
958
-				'valeurs' => $valeurs,
959
-				'surcharge' => $surcharge,
960
-			),
961
-			'data' => $tag
962
-		)
963
-	);
964
-
965
-	return $tag;
901
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
902
+
903
+    // fermer les tags img pas bien fermes;
904
+    $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
905
+
906
+    // le style
907
+    $style = $valeurs['style'];
908
+    if (isset($surcharge['style'])) {
909
+        $style = $surcharge['style'];
910
+        unset($surcharge['style']);
911
+    }
912
+
913
+    // traiter specifiquement la largeur et la hauteur
914
+    $width = $valeurs['largeur'];
915
+    if (isset($surcharge['width'])) {
916
+        $width = $surcharge['width'];
917
+        unset($surcharge['width']);
918
+    }
919
+    $height = $valeurs['hauteur'];
920
+    if (isset($surcharge['height'])) {
921
+        $height = $surcharge['height'];
922
+        unset($surcharge['height']);
923
+    }
924
+
925
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
926
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
927
+    // on remplace toute les ref a src dans le tag
928
+    $src = extraire_attribut($tag, 'src');
929
+    if (isset($surcharge['src'])) {
930
+        $tag = str_replace($src, $surcharge['src'], $tag);
931
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
932
+        // pas garanti comme methode, mais mieux que rien
933
+        if (strpos($src, '&') !== false) {
934
+            $tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
935
+        }
936
+        $src = $surcharge['src'];
937
+        unset($surcharge['src']);
938
+    }
939
+
940
+    $class = $valeurs['class'];
941
+    if (isset($surcharge['class'])) {
942
+        $class = $surcharge['class'];
943
+        unset($surcharge['class']);
944
+    }
945
+    if (strlen($class)) {
946
+        $tag = inserer_attribut($tag, 'class', $class);
947
+    }
948
+
949
+    if (count($surcharge)) {
950
+        foreach ($surcharge as $attribut => $valeur) {
951
+            $tag = inserer_attribut($tag, $attribut, $valeur);
952
+        }
953
+    }
954
+
955
+    $tag = pipeline('image_ecrire_tag_finir',
956
+        array(
957
+            'args' => array(
958
+                'valeurs' => $valeurs,
959
+                'surcharge' => $surcharge,
960
+            ),
961
+            'data' => $tag
962
+        )
963
+    );
964
+
965
+    return $tag;
966 966
 }
967 967
 
968 968
 /**
@@ -985,236 +985,236 @@  discard block
 block discarded – undo
985 985
  *     Description de l'image, sinon null.
986 986
  **/
987 987
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
988
-	// ordre de preference des formats graphiques pour creer les vignettes
989
-	// le premier format disponible, selon la methode demandee, est utilise
990
-	$image = $valeurs['fichier'];
991
-	$format = $valeurs['format_source'];
992
-	$destdir = dirname($valeurs['fichier_dest']);
993
-	$destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
994
-
995
-	$format_sortie = $valeurs['format_dest'];
996
-
997
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
998
-		$process = $GLOBALS['meta']['image_process'];
999
-	}
1000
-
1001
-	// liste des formats qu'on sait lire
1002
-	$img = isset($GLOBALS['meta']['formats_graphiques'])
1003
-		? (strpos($GLOBALS['meta']['formats_graphiques'], $format) !== false)
1004
-		: false;
1005
-
1006
-	// si le doc n'est pas une image, refuser
1007
-	if (!$force and !$img) {
1008
-		return;
1009
-	}
1010
-	$destination = "$destdir/$destfile";
1011
-
1012
-	// calculer la taille
1013
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1014
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1015
-			list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1016
-		}
1017
-	} elseif ($process == 'convert' or $process == 'imagick') {
1018
-		$destWidth = $maxWidth;
1019
-		$destHeight = $maxHeight;
1020
-	} else {
1021
-		spip_log("echec $process sur $image");
1022
-
1023
-		return;
1024
-	}
1025
-
1026
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1027
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1028
-		$vignette = $destination . '.' . $format;
1029
-		@copy($image, $vignette);
1030
-	} // imagemagick en ligne de commande
1031
-	elseif ($process == 'convert') {
1032
-		if (!defined('_CONVERT_COMMAND')) {
1033
-			define('_CONVERT_COMMAND', 'convert');
1034
-		} // Securite : mes_options.php peut preciser le chemin absolu
1035
-		if (!defined('_RESIZE_COMMAND')) {
1036
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1037
-		}
1038
-		$vignette = $destination . "." . $format_sortie;
1039
-		$commande = str_replace(
1040
-			array('%x', '%y', '%src', '%dest'),
1041
-			array(
1042
-				$destWidth,
1043
-				$destHeight,
1044
-				escapeshellcmd($image),
1045
-				escapeshellcmd($vignette)
1046
-			),
1047
-			_RESIZE_COMMAND);
1048
-		spip_log($commande);
1049
-		exec($commande);
1050
-		if (!@file_exists($vignette)) {
1051
-			spip_log("echec convert sur $vignette");
1052
-
1053
-			return;  // echec commande
1054
-		}
1055
-	} // php5 imagemagick
1056
-	elseif ($process == 'imagick') {
1057
-		$vignette = "$destination." . $format_sortie;
1058
-
1059
-		if (!class_exists('Imagick')) {
1060
-			spip_log("Classe Imagick absente !", _LOG_ERREUR);
1061
-
1062
-			return;
1063
-		}
1064
-		$imagick = new Imagick();
1065
-		$imagick->readImage($image);
1066
-		$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1067
-			1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1068
-		$imagick->writeImage($vignette);
1069
-
1070
-		if (!@file_exists($vignette)) {
1071
-			spip_log("echec imagick sur $vignette");
1072
-
1073
-			return;
1074
-		}
1075
-	} // netpbm
1076
-	elseif ($process == "netpbm") {
1077
-		if (!defined('_PNMSCALE_COMMAND')) {
1078
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1079
-		} // Securite : mes_options.php peut preciser le chemin absolu
1080
-		if (_PNMSCALE_COMMAND == '') {
1081
-			return;
1082
-		}
1083
-		$vignette = $destination . "." . $format_sortie;
1084
-		$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1085
-		if ($format == "jpg") {
1086
-
1087
-			$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1088
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1089
-			if (!($s = @filesize($vignette))) {
1090
-				spip_unlink($vignette);
1091
-			}
1092
-			if (!@file_exists($vignette)) {
1093
-				spip_log("echec netpbm-jpg sur $vignette");
1094
-
1095
-				return;
1096
-			}
1097
-		} else {
1098
-			if ($format == "gif") {
1099
-				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1100
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1101
-				if (!($s = @filesize($vignette))) {
1102
-					spip_unlink($vignette);
1103
-				}
1104
-				if (!@file_exists($vignette)) {
1105
-					spip_log("echec netpbm-gif sur $vignette");
1106
-
1107
-					return;
1108
-				}
1109
-			} else {
1110
-				if ($format == "png") {
1111
-					$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1112
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1113
-					if (!($s = @filesize($vignette))) {
1114
-						spip_unlink($vignette);
1115
-					}
1116
-					if (!@file_exists($vignette)) {
1117
-						spip_log("echec netpbm-png sur $vignette");
1118
-
1119
-						return;
1120
-					}
1121
-				}
1122
-			}
1123
-		}
1124
-	} // gd ou gd2
1125
-	elseif ($process == 'gd1' or $process == 'gd2') {
1126
-		if (!function_exists('gd_info')) {
1127
-			spip_log("Librairie GD absente !", _LOG_ERREUR);
1128
-
1129
-			return;
1130
-		}
1131
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1132
-			spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1133
-
1134
-			return;
1135
-		}
1136
-		$destFormat = $format_sortie;
1137
-		if (!$destFormat) {
1138
-			spip_log("pas de format pour $image");
1139
-
1140
-			return;
1141
-		}
1142
-
1143
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1144
-		if (!function_exists($fonction_imagecreatefrom)) {
1145
-			return '';
1146
-		}
1147
-		$srcImage = @$fonction_imagecreatefrom($image);
1148
-		if (!$srcImage) {
1149
-			spip_log("echec gd1/gd2");
1150
-
1151
-			return;
1152
-		}
1153
-
1154
-		// Initialisation de l'image destination
1155
-		$destImage = null;
1156
-		if ($process == 'gd2' and $destFormat != "gif") {
1157
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1158
-		}
1159
-		if (!$destImage) {
1160
-			$destImage = ImageCreate($destWidth, $destHeight);
1161
-		}
1162
-
1163
-		// Recopie de l'image d'origine avec adaptation de la taille 
1164
-		$ok = false;
1165
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1166
-			if ($format == "gif") {
1167
-				// Si un GIF est transparent, 
1168
-				// fabriquer un PNG transparent  
1169
-				$transp = imagecolortransparent($srcImage);
1170
-				if ($transp > 0) {
1171
-					$destFormat = "png";
1172
-				}
1173
-			}
1174
-			if ($destFormat == "png") {
1175
-				// Conserver la transparence 
1176
-				if (function_exists("imageAntiAlias")) {
1177
-					imageAntiAlias($destImage, true);
1178
-				}
1179
-				@imagealphablending($destImage, false);
1180
-				@imagesavealpha($destImage, true);
1181
-			}
1182
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1183
-		}
1184
-		if (!$ok) {
1185
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1186
-		}
1187
-
1188
-		// Sauvegarde de l'image destination
1189
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1190
-		$valeurs['format_dest'] = $format = $destFormat;
1191
-		_image_gd_output($destImage, $valeurs);
1192
-
1193
-		if ($srcImage) {
1194
-			ImageDestroy($srcImage);
1195
-		}
1196
-		ImageDestroy($destImage);
1197
-	}
1198
-
1199
-	$size = @getimagesize($vignette);
1200
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1201
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1202
-	if ($size[0] < 1) {
1203
-		$size[0] = $destWidth;
1204
-	}
1205
-	if ($size[1] < 1) {
1206
-		$size[1] = $destHeight;
1207
-	}
1208
-
1209
-	$retour['width'] = $largeur = $size[0];
1210
-	$retour['height'] = $hauteur = $size[1];
1211
-
1212
-	$retour['fichier'] = $vignette;
1213
-	$retour['format'] = $format;
1214
-	$retour['date'] = @filemtime($vignette);
1215
-
1216
-	// renvoyer l'image
1217
-	return $retour;
988
+    // ordre de preference des formats graphiques pour creer les vignettes
989
+    // le premier format disponible, selon la methode demandee, est utilise
990
+    $image = $valeurs['fichier'];
991
+    $format = $valeurs['format_source'];
992
+    $destdir = dirname($valeurs['fichier_dest']);
993
+    $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
994
+
995
+    $format_sortie = $valeurs['format_dest'];
996
+
997
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
998
+        $process = $GLOBALS['meta']['image_process'];
999
+    }
1000
+
1001
+    // liste des formats qu'on sait lire
1002
+    $img = isset($GLOBALS['meta']['formats_graphiques'])
1003
+        ? (strpos($GLOBALS['meta']['formats_graphiques'], $format) !== false)
1004
+        : false;
1005
+
1006
+    // si le doc n'est pas une image, refuser
1007
+    if (!$force and !$img) {
1008
+        return;
1009
+    }
1010
+    $destination = "$destdir/$destfile";
1011
+
1012
+    // calculer la taille
1013
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1014
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1015
+            list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1016
+        }
1017
+    } elseif ($process == 'convert' or $process == 'imagick') {
1018
+        $destWidth = $maxWidth;
1019
+        $destHeight = $maxHeight;
1020
+    } else {
1021
+        spip_log("echec $process sur $image");
1022
+
1023
+        return;
1024
+    }
1025
+
1026
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1027
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1028
+        $vignette = $destination . '.' . $format;
1029
+        @copy($image, $vignette);
1030
+    } // imagemagick en ligne de commande
1031
+    elseif ($process == 'convert') {
1032
+        if (!defined('_CONVERT_COMMAND')) {
1033
+            define('_CONVERT_COMMAND', 'convert');
1034
+        } // Securite : mes_options.php peut preciser le chemin absolu
1035
+        if (!defined('_RESIZE_COMMAND')) {
1036
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1037
+        }
1038
+        $vignette = $destination . "." . $format_sortie;
1039
+        $commande = str_replace(
1040
+            array('%x', '%y', '%src', '%dest'),
1041
+            array(
1042
+                $destWidth,
1043
+                $destHeight,
1044
+                escapeshellcmd($image),
1045
+                escapeshellcmd($vignette)
1046
+            ),
1047
+            _RESIZE_COMMAND);
1048
+        spip_log($commande);
1049
+        exec($commande);
1050
+        if (!@file_exists($vignette)) {
1051
+            spip_log("echec convert sur $vignette");
1052
+
1053
+            return;  // echec commande
1054
+        }
1055
+    } // php5 imagemagick
1056
+    elseif ($process == 'imagick') {
1057
+        $vignette = "$destination." . $format_sortie;
1058
+
1059
+        if (!class_exists('Imagick')) {
1060
+            spip_log("Classe Imagick absente !", _LOG_ERREUR);
1061
+
1062
+            return;
1063
+        }
1064
+        $imagick = new Imagick();
1065
+        $imagick->readImage($image);
1066
+        $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1067
+            1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1068
+        $imagick->writeImage($vignette);
1069
+
1070
+        if (!@file_exists($vignette)) {
1071
+            spip_log("echec imagick sur $vignette");
1072
+
1073
+            return;
1074
+        }
1075
+    } // netpbm
1076
+    elseif ($process == "netpbm") {
1077
+        if (!defined('_PNMSCALE_COMMAND')) {
1078
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1079
+        } // Securite : mes_options.php peut preciser le chemin absolu
1080
+        if (_PNMSCALE_COMMAND == '') {
1081
+            return;
1082
+        }
1083
+        $vignette = $destination . "." . $format_sortie;
1084
+        $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1085
+        if ($format == "jpg") {
1086
+
1087
+            $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1088
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1089
+            if (!($s = @filesize($vignette))) {
1090
+                spip_unlink($vignette);
1091
+            }
1092
+            if (!@file_exists($vignette)) {
1093
+                spip_log("echec netpbm-jpg sur $vignette");
1094
+
1095
+                return;
1096
+            }
1097
+        } else {
1098
+            if ($format == "gif") {
1099
+                $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1100
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1101
+                if (!($s = @filesize($vignette))) {
1102
+                    spip_unlink($vignette);
1103
+                }
1104
+                if (!@file_exists($vignette)) {
1105
+                    spip_log("echec netpbm-gif sur $vignette");
1106
+
1107
+                    return;
1108
+                }
1109
+            } else {
1110
+                if ($format == "png") {
1111
+                    $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1112
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1113
+                    if (!($s = @filesize($vignette))) {
1114
+                        spip_unlink($vignette);
1115
+                    }
1116
+                    if (!@file_exists($vignette)) {
1117
+                        spip_log("echec netpbm-png sur $vignette");
1118
+
1119
+                        return;
1120
+                    }
1121
+                }
1122
+            }
1123
+        }
1124
+    } // gd ou gd2
1125
+    elseif ($process == 'gd1' or $process == 'gd2') {
1126
+        if (!function_exists('gd_info')) {
1127
+            spip_log("Librairie GD absente !", _LOG_ERREUR);
1128
+
1129
+            return;
1130
+        }
1131
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1132
+            spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1133
+
1134
+            return;
1135
+        }
1136
+        $destFormat = $format_sortie;
1137
+        if (!$destFormat) {
1138
+            spip_log("pas de format pour $image");
1139
+
1140
+            return;
1141
+        }
1142
+
1143
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1144
+        if (!function_exists($fonction_imagecreatefrom)) {
1145
+            return '';
1146
+        }
1147
+        $srcImage = @$fonction_imagecreatefrom($image);
1148
+        if (!$srcImage) {
1149
+            spip_log("echec gd1/gd2");
1150
+
1151
+            return;
1152
+        }
1153
+
1154
+        // Initialisation de l'image destination
1155
+        $destImage = null;
1156
+        if ($process == 'gd2' and $destFormat != "gif") {
1157
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1158
+        }
1159
+        if (!$destImage) {
1160
+            $destImage = ImageCreate($destWidth, $destHeight);
1161
+        }
1162
+
1163
+        // Recopie de l'image d'origine avec adaptation de la taille 
1164
+        $ok = false;
1165
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1166
+            if ($format == "gif") {
1167
+                // Si un GIF est transparent, 
1168
+                // fabriquer un PNG transparent  
1169
+                $transp = imagecolortransparent($srcImage);
1170
+                if ($transp > 0) {
1171
+                    $destFormat = "png";
1172
+                }
1173
+            }
1174
+            if ($destFormat == "png") {
1175
+                // Conserver la transparence 
1176
+                if (function_exists("imageAntiAlias")) {
1177
+                    imageAntiAlias($destImage, true);
1178
+                }
1179
+                @imagealphablending($destImage, false);
1180
+                @imagesavealpha($destImage, true);
1181
+            }
1182
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1183
+        }
1184
+        if (!$ok) {
1185
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1186
+        }
1187
+
1188
+        // Sauvegarde de l'image destination
1189
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1190
+        $valeurs['format_dest'] = $format = $destFormat;
1191
+        _image_gd_output($destImage, $valeurs);
1192
+
1193
+        if ($srcImage) {
1194
+            ImageDestroy($srcImage);
1195
+        }
1196
+        ImageDestroy($destImage);
1197
+    }
1198
+
1199
+    $size = @getimagesize($vignette);
1200
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1201
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1202
+    if ($size[0] < 1) {
1203
+        $size[0] = $destWidth;
1204
+    }
1205
+    if ($size[1] < 1) {
1206
+        $size[1] = $destHeight;
1207
+    }
1208
+
1209
+    $retour['width'] = $largeur = $size[0];
1210
+    $retour['height'] = $hauteur = $size[1];
1211
+
1212
+    $retour['fichier'] = $vignette;
1213
+    $retour['format'] = $format;
1214
+    $retour['date'] = @filemtime($vignette);
1215
+
1216
+    // renvoyer l'image
1217
+    return $retour;
1218 1218
 }
1219 1219
 
1220 1220
 /**
@@ -1234,25 +1234,25 @@  discard block
 block discarded – undo
1234 1234
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1235 1235
  **/
1236 1236
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1237
-	$ratioWidth = $srcWidth / $maxWidth;
1238
-	$ratioHeight = $srcHeight / $maxHeight;
1239
-
1240
-	if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1241
-		$destWidth = $srcWidth;
1242
-		$destHeight = $srcHeight;
1243
-	} elseif ($ratioWidth < $ratioHeight) {
1244
-		$destWidth = $srcWidth / $ratioHeight;
1245
-		$destHeight = $maxHeight;
1246
-	} else {
1247
-		$destWidth = $maxWidth;
1248
-		$destHeight = $srcHeight / $ratioWidth;
1249
-	}
1250
-
1251
-	return array(
1252
-		ceil($destWidth),
1253
-		ceil($destHeight),
1254
-		max($ratioWidth, $ratioHeight)
1255
-	);
1237
+    $ratioWidth = $srcWidth / $maxWidth;
1238
+    $ratioHeight = $srcHeight / $maxHeight;
1239
+
1240
+    if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1241
+        $destWidth = $srcWidth;
1242
+        $destHeight = $srcHeight;
1243
+    } elseif ($ratioWidth < $ratioHeight) {
1244
+        $destWidth = $srcWidth / $ratioHeight;
1245
+        $destHeight = $maxHeight;
1246
+    } else {
1247
+        $destWidth = $maxWidth;
1248
+        $destHeight = $srcHeight / $ratioWidth;
1249
+    }
1250
+
1251
+    return array(
1252
+        ceil($destWidth),
1253
+        ceil($destHeight),
1254
+        max($ratioWidth, $ratioHeight)
1255
+    );
1256 1256
 }
1257 1257
 
1258 1258
 /**
@@ -1272,25 +1272,25 @@  discard block
 block discarded – undo
1272 1272
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1273 1273
  **/
1274 1274
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1275
-	$ratioWidth = $srcWidth / $maxWidth;
1276
-	$ratioHeight = $srcHeight / $maxHeight;
1277
-
1278
-	if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1279
-		$destWidth = $srcWidth;
1280
-		$destHeight = $srcHeight;
1281
-	} elseif ($ratioWidth > $ratioHeight) {
1282
-		$destWidth = $srcWidth / $ratioHeight;
1283
-		$destHeight = $maxHeight;
1284
-	} else {
1285
-		$destWidth = $maxWidth;
1286
-		$destHeight = $srcHeight / $ratioWidth;
1287
-	}
1288
-
1289
-	return array(
1290
-		ceil($destWidth),
1291
-		ceil($destHeight),
1292
-		min($ratioWidth, $ratioHeight)
1293
-	);
1275
+    $ratioWidth = $srcWidth / $maxWidth;
1276
+    $ratioHeight = $srcHeight / $maxHeight;
1277
+
1278
+    if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1279
+        $destWidth = $srcWidth;
1280
+        $destHeight = $srcHeight;
1281
+    } elseif ($ratioWidth > $ratioHeight) {
1282
+        $destWidth = $srcWidth / $ratioHeight;
1283
+        $destHeight = $maxHeight;
1284
+    } else {
1285
+        $destWidth = $maxWidth;
1286
+        $destHeight = $srcHeight / $ratioWidth;
1287
+    }
1288
+
1289
+    return array(
1290
+        ceil($destWidth),
1291
+        ceil($destHeight),
1292
+        min($ratioWidth, $ratioHeight)
1293
+    );
1294 1294
 }
1295 1295
 
1296 1296
 
@@ -1323,106 +1323,106 @@  discard block
 block discarded – undo
1323 1323
  *     Code HTML de la balise img produite
1324 1324
  **/
1325 1325
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1326
-	$image = false;
1327
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1328
-		$process = $GLOBALS['meta']['image_process'];
1329
-	}
1330
-	# determiner le format de sortie
1331
-	$format_sortie = false; // le choix par defaut sera bon
1332
-	if ($process == "netpbm") {
1333
-		$format_sortie = "jpg";
1334
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1335
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
1336
-
1337
-		// on verifie que l'extension choisie est bonne (en principe oui)
1338
-		$gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]);
1339
-		if (is_array($image)
1340
-			and (!in_array($image['format_dest'], $gd_formats)
1341
-				or ($image['format_dest'] == 'gif' and !function_exists('ImageGif'))
1342
-			)
1343
-		) {
1344
-			if ($image['format_source'] == 'jpg') {
1345
-				$formats_sortie = array('jpg', 'png', 'gif');
1346
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1347
-			{
1348
-				$formats_sortie = array('png', 'jpg', 'gif');
1349
-			}
1350
-			// Choisir le format destination
1351
-			// - on sauve de preference en JPEG (meilleure compression)
1352
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1353
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1354
-			# pas *ecrire*
1355
-			$format_sortie = "";
1356
-			foreach ($formats_sortie as $fmt) {
1357
-				if (in_array($fmt, $gd_formats)) {
1358
-					if ($fmt <> "gif" or function_exists('ImageGif')) {
1359
-						$format_sortie = $fmt;
1360
-					}
1361
-					break;
1362
-				}
1363
-			}
1364
-			$image = false;
1365
-		}
1366
-	}
1367
-
1368
-	if (!is_array($image)) {
1369
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
1370
-	}
1371
-
1372
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1373
-		spip_log("image_reduire_src:pas de version locale de $img");
1374
-		// on peut resizer en mode html si on dispose des elements
1375
-		if ($srcw = extraire_attribut($img, 'width')
1376
-			and $srch = extraire_attribut($img, 'height')
1377
-		) {
1378
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1379
-
1380
-			return _image_tag_changer_taille($img, $w, $h);
1381
-		}
1382
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1383
-		// sous la forme style='max-width: NNpx;'
1384
-		return inserer_attribut($img, 'style',
1385
-			"max-width: ${taille}px; max-height: ${taille_y}px");
1386
-	}
1387
-
1388
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1389
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1390
-		if ($image['creer']) {
1391
-			@copy($image['fichier'], $image['fichier_dest']);
1392
-		}
1393
-
1394
-		return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1395
-	}
1396
-
1397
-	if ($image['creer'] == false && !$force) {
1398
-		return _image_ecrire_tag($image,
1399
-			array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1400
-	}
1401
-
1402
-	if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) {
1403
-		$destWidth = $image['largeur_dest'];
1404
-		$destHeight = $image['hauteur_dest'];
1405
-		$logo = $image['fichier'];
1406
-		$date = $image["date_src"];
1407
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1408
-
1409
-		if ($preview && $preview['fichier']) {
1410
-			$logo = $preview['fichier'];
1411
-			$destWidth = $preview['width'];
1412
-			$destHeight = $preview['height'];
1413
-			$date = $preview['date'];
1414
-		}
1415
-		// dans l'espace prive mettre un timestamp sur l'adresse 
1416
-		// de l'image, de facon a tromper le cache du navigateur
1417
-		// quand on fait supprimer/reuploader un logo
1418
-		// (pas de filemtime si SAFE MODE)
1419
-		$date = test_espace_prive() ? ('?' . $date) : '';
1420
-
1421
-		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1422
-	} else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1423
-	{
1424
-		return $img;
1425
-	}
1326
+    $image = false;
1327
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1328
+        $process = $GLOBALS['meta']['image_process'];
1329
+    }
1330
+    # determiner le format de sortie
1331
+    $format_sortie = false; // le choix par defaut sera bon
1332
+    if ($process == "netpbm") {
1333
+        $format_sortie = "jpg";
1334
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1335
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
1336
+
1337
+        // on verifie que l'extension choisie est bonne (en principe oui)
1338
+        $gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]);
1339
+        if (is_array($image)
1340
+            and (!in_array($image['format_dest'], $gd_formats)
1341
+                or ($image['format_dest'] == 'gif' and !function_exists('ImageGif'))
1342
+            )
1343
+        ) {
1344
+            if ($image['format_source'] == 'jpg') {
1345
+                $formats_sortie = array('jpg', 'png', 'gif');
1346
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1347
+            {
1348
+                $formats_sortie = array('png', 'jpg', 'gif');
1349
+            }
1350
+            // Choisir le format destination
1351
+            // - on sauve de preference en JPEG (meilleure compression)
1352
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1353
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1354
+            # pas *ecrire*
1355
+            $format_sortie = "";
1356
+            foreach ($formats_sortie as $fmt) {
1357
+                if (in_array($fmt, $gd_formats)) {
1358
+                    if ($fmt <> "gif" or function_exists('ImageGif')) {
1359
+                        $format_sortie = $fmt;
1360
+                    }
1361
+                    break;
1362
+                }
1363
+            }
1364
+            $image = false;
1365
+        }
1366
+    }
1367
+
1368
+    if (!is_array($image)) {
1369
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
1370
+    }
1371
+
1372
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1373
+        spip_log("image_reduire_src:pas de version locale de $img");
1374
+        // on peut resizer en mode html si on dispose des elements
1375
+        if ($srcw = extraire_attribut($img, 'width')
1376
+            and $srch = extraire_attribut($img, 'height')
1377
+        ) {
1378
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1379
+
1380
+            return _image_tag_changer_taille($img, $w, $h);
1381
+        }
1382
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1383
+        // sous la forme style='max-width: NNpx;'
1384
+        return inserer_attribut($img, 'style',
1385
+            "max-width: ${taille}px; max-height: ${taille_y}px");
1386
+    }
1387
+
1388
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1389
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1390
+        if ($image['creer']) {
1391
+            @copy($image['fichier'], $image['fichier_dest']);
1392
+        }
1393
+
1394
+        return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1395
+    }
1396
+
1397
+    if ($image['creer'] == false && !$force) {
1398
+        return _image_ecrire_tag($image,
1399
+            array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1400
+    }
1401
+
1402
+    if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) {
1403
+        $destWidth = $image['largeur_dest'];
1404
+        $destHeight = $image['hauteur_dest'];
1405
+        $logo = $image['fichier'];
1406
+        $date = $image["date_src"];
1407
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1408
+
1409
+        if ($preview && $preview['fichier']) {
1410
+            $logo = $preview['fichier'];
1411
+            $destWidth = $preview['width'];
1412
+            $destHeight = $preview['height'];
1413
+            $date = $preview['date'];
1414
+        }
1415
+        // dans l'espace prive mettre un timestamp sur l'adresse 
1416
+        // de l'image, de facon a tromper le cache du navigateur
1417
+        // quand on fait supprimer/reuploader un logo
1418
+        // (pas de filemtime si SAFE MODE)
1419
+        $date = test_espace_prive() ? ('?' . $date) : '';
1420
+
1421
+        return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1422
+    } else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1423
+    {
1424
+        return $img;
1425
+    }
1426 1426
 }
1427 1427
 
1428 1428
 /**
@@ -1437,145 +1437,145 @@  discard block
 block discarded – undo
1437 1437
  */
1438 1438
 class phpthumb_functions {
1439 1439
 
1440
-	/**
1441
-	 * Retourne la couleur d'un pixel dans une image
1442
-	 *
1443
-	 * @param ressource $img
1444
-	 * @param int $x
1445
-	 * @param int $y
1446
-	 * @return array|bool
1447
-	 */
1448
-	public static function GetPixelColor(&$img, $x, $y) {
1449
-		if (!is_resource($img)) {
1450
-			return false;
1451
-		}
1452
-
1453
-		return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1454
-	}
1455
-
1456
-	/**
1457
-	 * Retourne un nombre dans une représentation en Little Endian
1458
-	 *
1459
-	 * @param int $number
1460
-	 * @param int $minbytes
1461
-	 * @return string
1462
-	 */
1463
-	public static function LittleEndian2String($number, $minbytes = 1) {
1464
-		$intstring = '';
1465
-		while ($number > 0) {
1466
-			$intstring = $intstring . chr($number & 255);
1467
-			$number >>= 8;
1468
-		}
1469
-
1470
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1471
-	}
1472
-
1473
-	/**
1474
-	 * Transforme une ressource GD en image au format ICO
1475
-	 *
1476
-	 * @param array $gd_image_array
1477
-	 *     Tableau de ressources d'images GD
1478
-	 * @return string
1479
-	 *     Image au format ICO
1480
-	 */
1481
-	public static function GD2ICOstring(&$gd_image_array) {
1482
-		foreach ($gd_image_array as $key => $gd_image) {
1483
-
1484
-			$ImageWidths[$key] = ImageSX($gd_image);
1485
-			$ImageHeights[$key] = ImageSY($gd_image);
1486
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1487
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1488
-
1489
-			$icXOR[$key] = '';
1490
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1491
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1492
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1493
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1494
-					$r = $argb['red'];
1495
-					$g = $argb['green'];
1496
-					$b = $argb['blue'];
1497
-
1498
-					if ($bpp[$key] == 32) {
1499
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1500
-					} elseif ($bpp[$key] == 24) {
1501
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1502
-					}
1503
-
1504
-					if ($a < 128) {
1505
-						@$icANDmask[$key][$y] .= '1';
1506
-					} else {
1507
-						@$icANDmask[$key][$y] .= '0';
1508
-					}
1509
-				}
1510
-				// mask bits are 32-bit aligned per scanline
1511
-				while (strlen($icANDmask[$key][$y]) % 32) {
1512
-					$icANDmask[$key][$y] .= '0';
1513
-				}
1514
-			}
1515
-			$icAND[$key] = '';
1516
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1517
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1518
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1519
-				}
1520
-			}
1521
-
1522
-		}
1523
-
1524
-		foreach ($gd_image_array as $key => $gd_image) {
1525
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1526
-
1527
-			// BITMAPINFOHEADER - 40 bytes
1528
-			$BitmapInfoHeader[$key] = '';
1529
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1530
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1531
-			// The biHeight member specifies the combined
1532
-			// height of the XOR and AND masks.
1533
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1534
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1535
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1536
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1537
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1538
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1539
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1540
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1541
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1542
-		}
1543
-
1544
-
1545
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1546
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1547
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1548
-
1549
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1550
-		foreach ($gd_image_array as $key => $gd_image) {
1551
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1552
-
1553
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1554
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1555
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1556
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1557
-
1558
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1559
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1560
-
1561
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1562
-			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1563
-				4);     // dwBytesInRes;	// How many bytes in this resource?
1564
-
1565
-			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1566
-				4);    // dwImageOffset;   // Where in the file is this image?
1567
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1568
-			$dwImageOffset += strlen($icXOR[$key]);
1569
-			$dwImageOffset += strlen($icAND[$key]);
1570
-		}
1571
-
1572
-		foreach ($gd_image_array as $key => $gd_image) {
1573
-			$icondata .= $BitmapInfoHeader[$key];
1574
-			$icondata .= $icXOR[$key];
1575
-			$icondata .= $icAND[$key];
1576
-		}
1577
-
1578
-		return $icondata;
1579
-	}
1440
+    /**
1441
+     * Retourne la couleur d'un pixel dans une image
1442
+     *
1443
+     * @param ressource $img
1444
+     * @param int $x
1445
+     * @param int $y
1446
+     * @return array|bool
1447
+     */
1448
+    public static function GetPixelColor(&$img, $x, $y) {
1449
+        if (!is_resource($img)) {
1450
+            return false;
1451
+        }
1452
+
1453
+        return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1454
+    }
1455
+
1456
+    /**
1457
+     * Retourne un nombre dans une représentation en Little Endian
1458
+     *
1459
+     * @param int $number
1460
+     * @param int $minbytes
1461
+     * @return string
1462
+     */
1463
+    public static function LittleEndian2String($number, $minbytes = 1) {
1464
+        $intstring = '';
1465
+        while ($number > 0) {
1466
+            $intstring = $intstring . chr($number & 255);
1467
+            $number >>= 8;
1468
+        }
1469
+
1470
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1471
+    }
1472
+
1473
+    /**
1474
+     * Transforme une ressource GD en image au format ICO
1475
+     *
1476
+     * @param array $gd_image_array
1477
+     *     Tableau de ressources d'images GD
1478
+     * @return string
1479
+     *     Image au format ICO
1480
+     */
1481
+    public static function GD2ICOstring(&$gd_image_array) {
1482
+        foreach ($gd_image_array as $key => $gd_image) {
1483
+
1484
+            $ImageWidths[$key] = ImageSX($gd_image);
1485
+            $ImageHeights[$key] = ImageSY($gd_image);
1486
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1487
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1488
+
1489
+            $icXOR[$key] = '';
1490
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1491
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1492
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1493
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1494
+                    $r = $argb['red'];
1495
+                    $g = $argb['green'];
1496
+                    $b = $argb['blue'];
1497
+
1498
+                    if ($bpp[$key] == 32) {
1499
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1500
+                    } elseif ($bpp[$key] == 24) {
1501
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1502
+                    }
1503
+
1504
+                    if ($a < 128) {
1505
+                        @$icANDmask[$key][$y] .= '1';
1506
+                    } else {
1507
+                        @$icANDmask[$key][$y] .= '0';
1508
+                    }
1509
+                }
1510
+                // mask bits are 32-bit aligned per scanline
1511
+                while (strlen($icANDmask[$key][$y]) % 32) {
1512
+                    $icANDmask[$key][$y] .= '0';
1513
+                }
1514
+            }
1515
+            $icAND[$key] = '';
1516
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1517
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1518
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1519
+                }
1520
+            }
1521
+
1522
+        }
1523
+
1524
+        foreach ($gd_image_array as $key => $gd_image) {
1525
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1526
+
1527
+            // BITMAPINFOHEADER - 40 bytes
1528
+            $BitmapInfoHeader[$key] = '';
1529
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1530
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1531
+            // The biHeight member specifies the combined
1532
+            // height of the XOR and AND masks.
1533
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1534
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1535
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1536
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1537
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1538
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1539
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1540
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1541
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1542
+        }
1543
+
1544
+
1545
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1546
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1547
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1548
+
1549
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1550
+        foreach ($gd_image_array as $key => $gd_image) {
1551
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1552
+
1553
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1554
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1555
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1556
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1557
+
1558
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1559
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1560
+
1561
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1562
+            $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1563
+                4);     // dwBytesInRes;	// How many bytes in this resource?
1564
+
1565
+            $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1566
+                4);    // dwImageOffset;   // Where in the file is this image?
1567
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1568
+            $dwImageOffset += strlen($icXOR[$key]);
1569
+            $dwImageOffset += strlen($icAND[$key]);
1570
+        }
1571
+
1572
+        foreach ($gd_image_array as $key => $gd_image) {
1573
+            $icondata .= $BitmapInfoHeader[$key];
1574
+            $icondata .= $icXOR[$key];
1575
+            $icondata .= $icAND[$key];
1576
+        }
1577
+
1578
+        return $icondata;
1579
+    }
1580 1580
 
1581 1581
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -42,13 +42,13 @@  discard block
 block discarded – undo
42 42
 	$blue = dechex($blue);
43 43
 
44 44
 	if (strlen($red) == 1) {
45
-		$red = "0" . $red;
45
+		$red = "0".$red;
46 46
 	}
47 47
 	if (strlen($green) == 1) {
48
-		$green = "0" . $green;
48
+		$green = "0".$green;
49 49
 	}
50 50
 	if (strlen($blue) == 1) {
51
-		$blue = "0" . $blue;
51
+		$blue = "0".$blue;
52 52
 	}
53 53
 
54 54
 	return "$red$green$blue";
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		$img = "<img src='$source' />";
149 149
 	} # gerer img src="data:....base64"
150 150
 	elseif (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
151
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
151
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
152 152
 		if (!file_exists($local)) {
153 153
 			ecrire_fichier($local, base64_decode($regs[2]));
154 154
 		}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	// les protocoles web prennent au moins 3 lettres
163 163
 	if (tester_url_absolue($source)) {
164 164
 		include_spip('inc/distant');
165
-		$fichier = _DIR_RACINE . copie_locale($source);
165
+		$fichier = _DIR_RACINE.copie_locale($source);
166 166
 		if (!$fichier) {
167 167
 			return "";
168 168
 		}
@@ -247,9 +247,9 @@  discard block
 block discarded – undo
247 247
 			// on garde la terminaison initiale car image simplement copiee
248 248
 			// et on postfixe son nom avec un md5 du path
249 249
 			$terminaison_dest = $terminaison;
250
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
250
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
251 251
 		} else {
252
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
252
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
253 253
 		}
254 254
 		$cache = sous_repertoire(_DIR_VAR, $cache);
255 255
 		$cache = sous_repertoire($cache, $effet);
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		$fichier_dest = substr($fichier_dest, 2);
266 266
 	}
267 267
 
268
-	$fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
268
+	$fichier_dest = $cache.$fichier_dest.".".$terminaison_dest;
269 269
 
270 270
 	$GLOBALS["images_calculees"][] = $fichier_dest;
271 271
 
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 	}
302 302
 
303 303
 	if ($creer) {
304
-		spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
305
-			"images" . _LOG_DEBUG);
304
+		spip_log("filtre image ".($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
305
+			"images"._LOG_DEBUG);
306 306
 	}
307 307
 
308 308
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
309
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
309
+	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
310 310
 	$ret["fichier"] = $fichier;
311
-	$ret["fonction_image"] = "_image_image" . $terminaison_dest;
311
+	$ret["fonction_image"] = "_image_image".$terminaison_dest;
312 312
 	$ret["fichier_dest"] = $fichier_dest;
313 313
 	$ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
314 314
 	$ret["format_dest"] = $terminaison_dest;
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 			$_terminaison = '';
411 411
 	}
412 412
 	if ($_terminaison !== $terminaison) {
413
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
413
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images."._LOG_INFO_IMPORTANTE);
414 414
 		$terminaison = $_terminaison;
415 415
 	}
416 416
 	return $terminaison;
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	if (!function_exists('imagepng')) {
501 501
 		return false;
502 502
 	}
503
-	$tmp = $fichier . ".tmp";
503
+	$tmp = $fichier.".tmp";
504 504
 	$ret = imagepng($img, $tmp);
505 505
 	if (file_exists($tmp)) {
506 506
 		$taille_test = getimagesize($tmp);
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 	if (!function_exists('imagegif')) {
536 536
 		return false;
537 537
 	}
538
-	$tmp = $fichier . ".tmp";
538
+	$tmp = $fichier.".tmp";
539 539
 	$ret = imagegif($img, $tmp);
540 540
 	if (file_exists($tmp)) {
541 541
 		$taille_test = getimagesize($tmp);
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
 	if (!function_exists('imagejpeg')) {
576 576
 		return false;
577 577
 	}
578
-	$tmp = $fichier . ".tmp";
578
+	$tmp = $fichier.".tmp";
579 579
 
580 580
 	// Enable interlancing
581 581
 	imageinterlace($img, true);
@@ -641,12 +641,12 @@  discard block
 block discarded – undo
641 641
  *     - false sinon.
642 642
  */
643 643
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
644
-	$fonction = "_image_image" . $valeurs['format_dest'];
644
+	$fonction = "_image_image".$valeurs['format_dest'];
645 645
 	$ret = false;
646 646
 	#un flag pour reperer les images gravees
647 647
 	$lock =
648 648
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
649
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
649
+	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'));
650 650
 	if (
651 651
 		function_exists($fonction)
652 652
 		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 			// dans tous les cas mettre a jour la taille de l'image finale
658 658
 			list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
659 659
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
660
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
660
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
661 661
 		}
662 662
 	}
663 663
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 function reconstruire_image_intermediaire($fichier_manquant) {
677 677
 	$reconstruire = array();
678 678
 	$fichier = $fichier_manquant;
679
-	while (strpos($fichier,"://")===false
679
+	while (strpos($fichier, "://") === false
680 680
 		and !@file_exists($fichier)
681 681
 		and lire_fichier($src = "$fichier.src", $source)
682 682
 		and $valeurs = unserialize($source)
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
  *     Chemin du fichier d'image calculé
714 714
  **/
715 715
 function ramasse_miettes($fichier) {
716
-	if (strpos($fichier,"://")!==false
716
+	if (strpos($fichier, "://") !== false
717 717
 		or !lire_fichier($src = "$fichier.src", $source)
718 718
 		or !$valeurs = unserialize($source)
719 719
 	) {
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	}
770 770
 	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
771 771
 	# et qu'il ne s'agit pas d'une URL
772
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
772
+	if (strpos($fichier, "://") === false and !@file_exists($fichier)) {
773 773
 		reconstruire_image_intermediaire($fichier);
774 774
 	}
775 775
 	ramasse_miettes($fichier);
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 
867 867
 	// attributs deprecies. Transformer en CSS
868 868
 	if ($espace = extraire_attribut($tag, 'hspace')) {
869
-		$style = "margin:${espace}px;" . $style;
869
+		$style = "margin:${espace}px;".$style;
870 870
 		$tag = inserer_attribut($tag, 'hspace', '');
871 871
 	}
872 872
 
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 	$image = $valeurs['fichier'];
991 991
 	$format = $valeurs['format_source'];
992 992
 	$destdir = dirname($valeurs['fichier_dest']);
993
-	$destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
993
+	$destfile = basename($valeurs['fichier_dest'], ".".$valeurs["format_dest"]);
994 994
 
995 995
 	$format_sortie = $valeurs['format_dest'];
996 996
 
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 
1026 1026
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1027 1027
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1028
-		$vignette = $destination . '.' . $format;
1028
+		$vignette = $destination.'.'.$format;
1029 1029
 		@copy($image, $vignette);
1030 1030
 	} // imagemagick en ligne de commande
1031 1031
 	elseif ($process == 'convert') {
@@ -1033,9 +1033,9 @@  discard block
 block discarded – undo
1033 1033
 			define('_CONVERT_COMMAND', 'convert');
1034 1034
 		} // Securite : mes_options.php peut preciser le chemin absolu
1035 1035
 		if (!defined('_RESIZE_COMMAND')) {
1036
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1036
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1037 1037
 		}
1038
-		$vignette = $destination . "." . $format_sortie;
1038
+		$vignette = $destination.".".$format_sortie;
1039 1039
 		$commande = str_replace(
1040 1040
 			array('%x', '%y', '%src', '%dest'),
1041 1041
 			array(
@@ -1050,11 +1050,11 @@  discard block
 block discarded – undo
1050 1050
 		if (!@file_exists($vignette)) {
1051 1051
 			spip_log("echec convert sur $vignette");
1052 1052
 
1053
-			return;  // echec commande
1053
+			return; // echec commande
1054 1054
 		}
1055 1055
 	} // php5 imagemagick
1056 1056
 	elseif ($process == 'imagick') {
1057
-		$vignette = "$destination." . $format_sortie;
1057
+		$vignette = "$destination.".$format_sortie;
1058 1058
 
1059 1059
 		if (!class_exists('Imagick')) {
1060 1060
 			spip_log("Classe Imagick absente !", _LOG_ERREUR);
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 		$imagick = new Imagick();
1065 1065
 		$imagick->readImage($image);
1066 1066
 		$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1067
-			1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1067
+			1); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1068 1068
 		$imagick->writeImage($vignette);
1069 1069
 
1070 1070
 		if (!@file_exists($vignette)) {
@@ -1080,12 +1080,12 @@  discard block
 block discarded – undo
1080 1080
 		if (_PNMSCALE_COMMAND == '') {
1081 1081
 			return;
1082 1082
 		}
1083
-		$vignette = $destination . "." . $format_sortie;
1083
+		$vignette = $destination.".".$format_sortie;
1084 1084
 		$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1085 1085
 		if ($format == "jpg") {
1086 1086
 
1087 1087
 			$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1088
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1088
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1089 1089
 			if (!($s = @filesize($vignette))) {
1090 1090
 				spip_unlink($vignette);
1091 1091
 			}
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 		} else {
1098 1098
 			if ($format == "gif") {
1099 1099
 				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1100
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1100
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1101 1101
 				if (!($s = @filesize($vignette))) {
1102 1102
 					spip_unlink($vignette);
1103 1103
 				}
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 			} else {
1110 1110
 				if ($format == "png") {
1111 1111
 					$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1112
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1112
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1113 1113
 					if (!($s = @filesize($vignette))) {
1114 1114
 						spip_unlink($vignette);
1115 1115
 					}
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
 			return;
1130 1130
 		}
1131 1131
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1132
-			spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1132
+			spip_log("vignette gd1/gd2 impossible : ".$srcWidth * $srcHeight."pixels");
1133 1133
 
1134 1134
 			return;
1135 1135
 		}
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
 		// de l'image, de facon a tromper le cache du navigateur
1417 1417
 		// quand on fait supprimer/reuploader un logo
1418 1418
 		// (pas de filemtime si SAFE MODE)
1419
-		$date = test_espace_prive() ? ('?' . $date) : '';
1419
+		$date = test_espace_prive() ? ('?'.$date) : '';
1420 1420
 
1421 1421
 		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1422 1422
 	} else # SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 	public static function LittleEndian2String($number, $minbytes = 1) {
1464 1464
 		$intstring = '';
1465 1465
 		while ($number > 0) {
1466
-			$intstring = $intstring . chr($number & 255);
1466
+			$intstring = $intstring.chr($number & 255);
1467 1467
 			$number >>= 8;
1468 1468
 		}
1469 1469
 
@@ -1496,9 +1496,9 @@  discard block
 block discarded – undo
1496 1496
 					$b = $argb['blue'];
1497 1497
 
1498 1498
 					if ($bpp[$key] == 32) {
1499
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1499
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1500 1500
 					} elseif ($bpp[$key] == 24) {
1501
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1501
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1502 1502
 					}
1503 1503
 
1504 1504
 					if ($a < 128) {
@@ -1526,44 +1526,44 @@  discard block
 block discarded – undo
1526 1526
 
1527 1527
 			// BITMAPINFOHEADER - 40 bytes
1528 1528
 			$BitmapInfoHeader[$key] = '';
1529
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1530
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1529
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1530
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1531 1531
 			// The biHeight member specifies the combined
1532 1532
 			// height of the XOR and AND masks.
1533 1533
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1534
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1535
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1536
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1537
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1538
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1539
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1540
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1541
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1534
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1535
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1536
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1537
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1538
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1539
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1540
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1541
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1542 1542
 		}
1543 1543
 
1544 1544
 
1545
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1546
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1547
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1545
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1546
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1547
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1548 1548
 
1549 1549
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1550 1550
 		foreach ($gd_image_array as $key => $gd_image) {
1551 1551
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1552 1552
 
1553
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1554
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1555
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1556
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1553
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1554
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1555
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1556
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1557 1557
 
1558
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1559
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1558
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1559
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1560 1560
 
1561 1561
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1562 1562
 			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1563
-				4);     // dwBytesInRes;	// How many bytes in this resource?
1563
+				4); // dwBytesInRes;	// How many bytes in this resource?
1564 1564
 
1565 1565
 			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1566
-				4);    // dwImageOffset;   // Where in the file is this image?
1566
+				4); // dwImageOffset;   // Where in the file is this image?
1567 1567
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1568 1568
 			$dwImageOffset += strlen($icXOR[$key]);
1569 1569
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_mini.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@
 block discarded – undo
122 122
  * @param int $height_max
123 123
  *    Hauteur minimale de l'image à traiter (10000 par défaut)
124 124
  * @return
125
- *    Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas
125
+ string    Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas
126 126
  */
127 127
 function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) {
128 128
 	if (!$img) {
Please login to merge, or discard this patch.
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres_images_lib_mini'); // par precaution
24 24
 
@@ -31,161 +31,161 @@  discard block
 block discarded – undo
31 31
  *    Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé
32 32
  */
33 33
 function couleur_html_to_hex($couleur) {
34
-	$couleurs_html = array(
35
-		'aliceblue' => 'F0F8FF',
36
-		'antiquewhite' => 'FAEBD7',
37
-		'aqua' => '00FFFF',
38
-		'aquamarine' => '7FFFD4',
39
-		'azure' => 'F0FFFF',
40
-		'beige' => 'F5F5DC',
41
-		'bisque' => 'FFE4C4',
42
-		'black' => '000000',
43
-		'blanchedalmond' => 'FFEBCD',
44
-		'blue' => '0000FF',
45
-		'blueviolet' => '8A2BE2',
46
-		'brown' => 'A52A2A',
47
-		'burlywood' => 'DEB887',
48
-		'cadetblue' => '5F9EA0',
49
-		'chartreuse' => '7FFF00',
50
-		'chocolate' => 'D2691E',
51
-		'coral' => 'FF7F50',
52
-		'cornflowerblue' => '6495ED',
53
-		'cornsilk' => 'FFF8DC',
54
-		'crimson' => 'DC143C',
55
-		'cyan' => '00FFFF',
56
-		'darkblue' => '00008B',
57
-		'darkcyan' => '008B8B',
58
-		'darkgoldenrod' => 'B8860B',
59
-		'darkgray' => 'A9A9A9',
60
-		'darkgreen' => '006400',
61
-		'darkgrey' => 'A9A9A9',
62
-		'darkkhaki' => 'BDB76B',
63
-		'darkmagenta' => '8B008B',
64
-		'darkolivegreen' => '556B2F',
65
-		'darkorange' => 'FF8C00',
66
-		'darkorchid' => '9932CC',
67
-		'darkred' => '8B0000',
68
-		'darksalmon' => 'E9967A',
69
-		'darkseagreen' => '8FBC8F',
70
-		'darkslateblue' => '483D8B',
71
-		'darkslategray' => '2F4F4F',
72
-		'darkslategrey' => '2F4F4F',
73
-		'darkturquoise' => '00CED1',
74
-		'darkviolet' => '9400D3',
75
-		'deeppink' => 'FF1493',
76
-		'deepskyblue' => '00BFFF',
77
-		'dimgray' => '696969',
78
-		'dimgrey' => '696969',
79
-		'dodgerblue' => '1E90FF',
80
-		'firebrick' => 'B22222',
81
-		'floralwhite' => 'FFFAF0',
82
-		'forestgreen' => '228B22',
83
-		'fuchsia' => 'FF00FF',
84
-		'gainsboro' => 'DCDCDC',
85
-		'ghostwhite' => 'F8F8FF',
86
-		'gold' => 'FFD700',
87
-		'goldenrod' => 'DAA520',
88
-		'gray' => '808080',
89
-		'green' => '008000',
90
-		'greenyellow' => 'ADFF2F',
91
-		'grey' => '808080',
92
-		'honeydew' => 'F0FFF0',
93
-		'hotpink' => 'FF69B4',
94
-		'indianred' => 'CD5C5C',
95
-		'indigo' => '4B0082',
96
-		'ivory' => 'FFFFF0',
97
-		'khaki' => 'F0E68C',
98
-		'lavender' => 'E6E6FA',
99
-		'lavenderblush' => 'FFF0F5',
100
-		'lawngreen' => '7CFC00',
101
-		'lemonchiffon' => 'FFFACD',
102
-		'lightblue' => 'ADD8E6',
103
-		'lightcoral' => 'F08080',
104
-		'lightcyan' => 'E0FFFF',
105
-		'lightgoldenrodyellow' => 'FAFAD2',
106
-		'lightgray' => 'D3D3D3',
107
-		'lightgreen' => '90EE90',
108
-		'lightgrey' => 'D3D3D3',
109
-		'lightpink' => 'FFB6C1',
110
-		'lightsalmon' => 'FFA07A',
111
-		'lightseagreen' => '20B2AA',
112
-		'lightskyblue' => '87CEFA',
113
-		'lightslategray' => '778899',
114
-		'lightslategrey' => '778899',
115
-		'lightsteelblue' => 'B0C4DE',
116
-		'lightyellow' => 'FFFFE0',
117
-		'lime' => '00FF00',
118
-		'limegreen' => '32CD32',
119
-		'linen' => 'FAF0E6',
120
-		'magenta' => 'FF00FF',
121
-		'maroon' => '800000',
122
-		'mediumaquamarine' => '66CDAA',
123
-		'mediumblue' => '0000CD',
124
-		'mediumorchid' => 'BA55D3',
125
-		'mediumpurple' => '9370DB',
126
-		'mediumseagreen' => '3CB371',
127
-		'mediumslateblue' => '7B68EE',
128
-		'mediumspringgreen' => '00FA9A',
129
-		'mediumturquoise' => '48D1CC',
130
-		'mediumvioletred' => 'C71585',
131
-		'midnightblue' => '191970',
132
-		'mintcream' => 'F5FFFA',
133
-		'mistyrose' => 'FFE4E1',
134
-		'moccasin' => 'FFE4B5',
135
-		'navajowhite' => 'FFDEAD',
136
-		'navy' => '000080',
137
-		'oldlace' => 'FDF5E6',
138
-		'olive' => '808000',
139
-		'olivedrab' => '6B8E23',
140
-		'orange' => 'FFA500',
141
-		'orangered' => 'FF4500',
142
-		'orchid' => 'DA70D6',
143
-		'palegoldenrod' => 'EEE8AA',
144
-		'palegreen' => '98FB98',
145
-		'paleturquoise' => 'AFEEEE',
146
-		'palevioletred' => 'DB7093',
147
-		'papayawhip' => 'FFEFD5',
148
-		'peachpuff' => 'FFDAB9',
149
-		'peru' => 'CD853F',
150
-		'pink' => 'FFC0CB',
151
-		'plum' => 'DDA0DD',
152
-		'powderblue' => 'B0E0E6',
153
-		'purple' => '800080',
154
-		'rebeccapurple' => '663399',
155
-		'red' => 'FF0000',
156
-		'rosybrown' => 'BC8F8F',
157
-		'royalblue' => '4169E1',
158
-		'saddlebrown' => '8B4513',
159
-		'salmon' => 'FA8072',
160
-		'sandybrown' => 'F4A460',
161
-		'seagreen' => '2E8B57',
162
-		'seashell' => 'FFF5EE',
163
-		'sienna' => 'A0522D',
164
-		'silver' => 'C0C0C0',
165
-		'skyblue' => '87CEEB',
166
-		'slateblue' => '6A5ACD',
167
-		'slategray' => '708090',
168
-		'slategrey' => '708090',
169
-		'snow' => 'FFFAFA',
170
-		'springgreen' => '00FF7F',
171
-		'steelblue' => '4682B4',
172
-		'tan' => 'D2B48C',
173
-		'teal' => '008080',
174
-		'thistle' => 'D8BFD8',
175
-		'tomato' => 'FF6347',
176
-		'turquoise' => '40E0D0',
177
-		'violet' => 'EE82EE',
178
-		'wheat' => 'F5DEB3',
179
-		'white' => 'FFFFFF',
180
-		'whitesmoke' => 'F5F5F5',
181
-		'yellow' => 'FFFF00',
182
-		'yellowgreen' => '9ACD32',
183
-	);
184
-	if (isset($couleurs_html[$lc = strtolower($couleur)])) {
185
-		return $couleurs_html[$lc];
186
-	}
187
-
188
-	return $couleur;
34
+    $couleurs_html = array(
35
+        'aliceblue' => 'F0F8FF',
36
+        'antiquewhite' => 'FAEBD7',
37
+        'aqua' => '00FFFF',
38
+        'aquamarine' => '7FFFD4',
39
+        'azure' => 'F0FFFF',
40
+        'beige' => 'F5F5DC',
41
+        'bisque' => 'FFE4C4',
42
+        'black' => '000000',
43
+        'blanchedalmond' => 'FFEBCD',
44
+        'blue' => '0000FF',
45
+        'blueviolet' => '8A2BE2',
46
+        'brown' => 'A52A2A',
47
+        'burlywood' => 'DEB887',
48
+        'cadetblue' => '5F9EA0',
49
+        'chartreuse' => '7FFF00',
50
+        'chocolate' => 'D2691E',
51
+        'coral' => 'FF7F50',
52
+        'cornflowerblue' => '6495ED',
53
+        'cornsilk' => 'FFF8DC',
54
+        'crimson' => 'DC143C',
55
+        'cyan' => '00FFFF',
56
+        'darkblue' => '00008B',
57
+        'darkcyan' => '008B8B',
58
+        'darkgoldenrod' => 'B8860B',
59
+        'darkgray' => 'A9A9A9',
60
+        'darkgreen' => '006400',
61
+        'darkgrey' => 'A9A9A9',
62
+        'darkkhaki' => 'BDB76B',
63
+        'darkmagenta' => '8B008B',
64
+        'darkolivegreen' => '556B2F',
65
+        'darkorange' => 'FF8C00',
66
+        'darkorchid' => '9932CC',
67
+        'darkred' => '8B0000',
68
+        'darksalmon' => 'E9967A',
69
+        'darkseagreen' => '8FBC8F',
70
+        'darkslateblue' => '483D8B',
71
+        'darkslategray' => '2F4F4F',
72
+        'darkslategrey' => '2F4F4F',
73
+        'darkturquoise' => '00CED1',
74
+        'darkviolet' => '9400D3',
75
+        'deeppink' => 'FF1493',
76
+        'deepskyblue' => '00BFFF',
77
+        'dimgray' => '696969',
78
+        'dimgrey' => '696969',
79
+        'dodgerblue' => '1E90FF',
80
+        'firebrick' => 'B22222',
81
+        'floralwhite' => 'FFFAF0',
82
+        'forestgreen' => '228B22',
83
+        'fuchsia' => 'FF00FF',
84
+        'gainsboro' => 'DCDCDC',
85
+        'ghostwhite' => 'F8F8FF',
86
+        'gold' => 'FFD700',
87
+        'goldenrod' => 'DAA520',
88
+        'gray' => '808080',
89
+        'green' => '008000',
90
+        'greenyellow' => 'ADFF2F',
91
+        'grey' => '808080',
92
+        'honeydew' => 'F0FFF0',
93
+        'hotpink' => 'FF69B4',
94
+        'indianred' => 'CD5C5C',
95
+        'indigo' => '4B0082',
96
+        'ivory' => 'FFFFF0',
97
+        'khaki' => 'F0E68C',
98
+        'lavender' => 'E6E6FA',
99
+        'lavenderblush' => 'FFF0F5',
100
+        'lawngreen' => '7CFC00',
101
+        'lemonchiffon' => 'FFFACD',
102
+        'lightblue' => 'ADD8E6',
103
+        'lightcoral' => 'F08080',
104
+        'lightcyan' => 'E0FFFF',
105
+        'lightgoldenrodyellow' => 'FAFAD2',
106
+        'lightgray' => 'D3D3D3',
107
+        'lightgreen' => '90EE90',
108
+        'lightgrey' => 'D3D3D3',
109
+        'lightpink' => 'FFB6C1',
110
+        'lightsalmon' => 'FFA07A',
111
+        'lightseagreen' => '20B2AA',
112
+        'lightskyblue' => '87CEFA',
113
+        'lightslategray' => '778899',
114
+        'lightslategrey' => '778899',
115
+        'lightsteelblue' => 'B0C4DE',
116
+        'lightyellow' => 'FFFFE0',
117
+        'lime' => '00FF00',
118
+        'limegreen' => '32CD32',
119
+        'linen' => 'FAF0E6',
120
+        'magenta' => 'FF00FF',
121
+        'maroon' => '800000',
122
+        'mediumaquamarine' => '66CDAA',
123
+        'mediumblue' => '0000CD',
124
+        'mediumorchid' => 'BA55D3',
125
+        'mediumpurple' => '9370DB',
126
+        'mediumseagreen' => '3CB371',
127
+        'mediumslateblue' => '7B68EE',
128
+        'mediumspringgreen' => '00FA9A',
129
+        'mediumturquoise' => '48D1CC',
130
+        'mediumvioletred' => 'C71585',
131
+        'midnightblue' => '191970',
132
+        'mintcream' => 'F5FFFA',
133
+        'mistyrose' => 'FFE4E1',
134
+        'moccasin' => 'FFE4B5',
135
+        'navajowhite' => 'FFDEAD',
136
+        'navy' => '000080',
137
+        'oldlace' => 'FDF5E6',
138
+        'olive' => '808000',
139
+        'olivedrab' => '6B8E23',
140
+        'orange' => 'FFA500',
141
+        'orangered' => 'FF4500',
142
+        'orchid' => 'DA70D6',
143
+        'palegoldenrod' => 'EEE8AA',
144
+        'palegreen' => '98FB98',
145
+        'paleturquoise' => 'AFEEEE',
146
+        'palevioletred' => 'DB7093',
147
+        'papayawhip' => 'FFEFD5',
148
+        'peachpuff' => 'FFDAB9',
149
+        'peru' => 'CD853F',
150
+        'pink' => 'FFC0CB',
151
+        'plum' => 'DDA0DD',
152
+        'powderblue' => 'B0E0E6',
153
+        'purple' => '800080',
154
+        'rebeccapurple' => '663399',
155
+        'red' => 'FF0000',
156
+        'rosybrown' => 'BC8F8F',
157
+        'royalblue' => '4169E1',
158
+        'saddlebrown' => '8B4513',
159
+        'salmon' => 'FA8072',
160
+        'sandybrown' => 'F4A460',
161
+        'seagreen' => '2E8B57',
162
+        'seashell' => 'FFF5EE',
163
+        'sienna' => 'A0522D',
164
+        'silver' => 'C0C0C0',
165
+        'skyblue' => '87CEEB',
166
+        'slateblue' => '6A5ACD',
167
+        'slategray' => '708090',
168
+        'slategrey' => '708090',
169
+        'snow' => 'FFFAFA',
170
+        'springgreen' => '00FF7F',
171
+        'steelblue' => '4682B4',
172
+        'tan' => 'D2B48C',
173
+        'teal' => '008080',
174
+        'thistle' => 'D8BFD8',
175
+        'tomato' => 'FF6347',
176
+        'turquoise' => '40E0D0',
177
+        'violet' => 'EE82EE',
178
+        'wheat' => 'F5DEB3',
179
+        'white' => 'FFFFFF',
180
+        'whitesmoke' => 'F5F5F5',
181
+        'yellow' => 'FFFF00',
182
+        'yellowgreen' => '9ACD32',
183
+    );
184
+    if (isset($couleurs_html[$lc = strtolower($couleur)])) {
185
+        return $couleurs_html[$lc];
186
+    }
187
+
188
+    return $couleur;
189 189
 }
190 190
 
191 191
 /**
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
  *    Code hexadécimal de la couleur plus foncée
202 202
  */
203 203
 function couleur_foncer($couleur, $coeff = 0.5) {
204
-	$couleurs = _couleur_hex_to_dec($couleur);
204
+    $couleurs = _couleur_hex_to_dec($couleur);
205 205
 
206
-	$red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
207
-	$green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
208
-	$blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
206
+    $red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
207
+    $green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
208
+    $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
209 209
 
210
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
210
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
211 211
 
212
-	return $couleur;
212
+    return $couleur;
213 213
 }
214 214
 
215 215
 /**
@@ -225,15 +225,15 @@  discard block
 block discarded – undo
225 225
  *    Code hexadécimal de la couleur éclaircie
226 226
  */
227 227
 function couleur_eclaircir($couleur, $coeff = 0.5) {
228
-	$couleurs = _couleur_hex_to_dec($couleur);
228
+    $couleurs = _couleur_hex_to_dec($couleur);
229 229
 
230
-	$red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
231
-	$green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
232
-	$blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
230
+    $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
231
+    $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
232
+    $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
233 233
 
234
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
234
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
235 235
 
236
-	return $couleur;
236
+    return $couleur;
237 237
 }
238 238
 
239 239
 /**
@@ -256,28 +256,28 @@  discard block
 block discarded – undo
256 256
  *    Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas
257 257
  */
258 258
 function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) {
259
-	if (!$img) {
260
-		return $img;
261
-	}
262
-	list($h, $l) = taille_image($img);
263
-	$select = true;
264
-	if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
265
-		$select = false;
266
-	}
267
-
268
-	$class = extraire_attribut($img, 'class');
269
-	$p = strpos($class, 'filtre_inactif');
270
-	if (($select == false) and ($p === false)) {
271
-		$class .= ' filtre_inactif';
272
-		$img = inserer_attribut($img, 'class', $class);
273
-	}
274
-	if (($select == true) and ($p !== false)) {
275
-		// no_image_filtrer : historique, a virer
276
-		$class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
277
-		$img = inserer_attribut($img, 'class', $class);
278
-	}
279
-
280
-	return $img;
259
+    if (!$img) {
260
+        return $img;
261
+    }
262
+    list($h, $l) = taille_image($img);
263
+    $select = true;
264
+    if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
265
+        $select = false;
266
+    }
267
+
268
+    $class = extraire_attribut($img, 'class');
269
+    $p = strpos($class, 'filtre_inactif');
270
+    if (($select == false) and ($p === false)) {
271
+        $class .= ' filtre_inactif';
272
+        $img = inserer_attribut($img, 'class', $class);
273
+    }
274
+    if (($select == true) and ($p !== false)) {
275
+        // no_image_filtrer : historique, a virer
276
+        $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
277
+        $img = inserer_attribut($img, 'class', $class);
278
+    }
279
+
280
+    return $img;
281 281
 }
282 282
 
283 283
 /**
@@ -325,38 +325,38 @@  discard block
 block discarded – undo
325 325
  *     Code HTML de l'image ou du texte.
326 326
  **/
327 327
 function image_passe_partout(
328
-	$img,
329
-	$taille_x = -1,
330
-	$taille_y = -1,
331
-	$force = false,
332
-	$cherche_image = false,
333
-	$process = 'AUTO'
328
+    $img,
329
+    $taille_x = -1,
330
+    $taille_y = -1,
331
+    $force = false,
332
+    $cherche_image = false,
333
+    $process = 'AUTO'
334 334
 ) {
335
-	if (!$img) {
336
-		return '';
337
-	}
338
-	list($hauteur, $largeur) = taille_image($img);
339
-	if ($taille_x == -1) {
340
-		$taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150;
341
-	}
342
-	if ($taille_y == -1) {
343
-		$taille_y = $taille_x;
344
-	}
345
-
346
-	if ($taille_x == 0 and $taille_y > 0) {
347
-		$taille_x = 1;
348
-	} # {0,300} -> c'est 300 qui compte
349
-	elseif ($taille_x > 0 and $taille_y == 0) {
350
-		$taille_y = 1;
351
-	} # {300,0} -> c'est 300 qui compte
352
-	elseif ($taille_x == 0 and $taille_y == 0) {
353
-		return '';
354
-	}
355
-
356
-	list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y);
357
-	$fonction = array('image_passe_partout', func_get_args());
358
-
359
-	return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
335
+    if (!$img) {
336
+        return '';
337
+    }
338
+    list($hauteur, $largeur) = taille_image($img);
339
+    if ($taille_x == -1) {
340
+        $taille_x = isset($GLOBALS['meta']['taille_preview']) ? $GLOBALS['meta']['taille_preview'] : 150;
341
+    }
342
+    if ($taille_y == -1) {
343
+        $taille_y = $taille_x;
344
+    }
345
+
346
+    if ($taille_x == 0 and $taille_y > 0) {
347
+        $taille_x = 1;
348
+    } # {0,300} -> c'est 300 qui compte
349
+    elseif ($taille_x > 0 and $taille_y == 0) {
350
+        $taille_y = 1;
351
+    } # {300,0} -> c'est 300 qui compte
352
+    elseif ($taille_x == 0 and $taille_y == 0) {
353
+        return '';
354
+    }
355
+
356
+    list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur, $hauteur, $taille_x, $taille_y);
357
+    $fonction = array('image_passe_partout', func_get_args());
358
+
359
+    return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
360 360
 }
361 361
 
362 362
 /**
@@ -399,28 +399,28 @@  discard block
 block discarded – undo
399 399
  *     Code HTML de l'image ou du texte.
400 400
  **/
401 401
 function image_reduire($img, $taille = -1, $taille_y = -1, $force = false, $cherche_image = false, $process = 'AUTO') {
402
-	// Determiner la taille x,y maxi
403
-	// prendre le reglage de previsu par defaut
404
-	if ($taille == -1) {
405
-		$taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) ? intval($GLOBALS['meta']['taille_preview']) : 150;
406
-	}
407
-	if ($taille_y == -1) {
408
-		$taille_y = $taille;
409
-	}
410
-
411
-	if ($taille == 0 and $taille_y > 0) {
412
-		$taille = 10000;
413
-	} # {0,300} -> c'est 300 qui compte
414
-	elseif ($taille > 0 and $taille_y == 0) {
415
-		$taille_y = 10000;
416
-	} # {300,0} -> c'est 300 qui compte
417
-	elseif ($taille == 0 and $taille_y == 0) {
418
-		return '';
419
-	}
420
-
421
-	$fonction = array('image_reduire', func_get_args());
422
-
423
-	return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
402
+    // Determiner la taille x,y maxi
403
+    // prendre le reglage de previsu par defaut
404
+    if ($taille == -1) {
405
+        $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) ? intval($GLOBALS['meta']['taille_preview']) : 150;
406
+    }
407
+    if ($taille_y == -1) {
408
+        $taille_y = $taille;
409
+    }
410
+
411
+    if ($taille == 0 and $taille_y > 0) {
412
+        $taille = 10000;
413
+    } # {0,300} -> c'est 300 qui compte
414
+    elseif ($taille > 0 and $taille_y == 0) {
415
+        $taille_y = 10000;
416
+    } # {300,0} -> c'est 300 qui compte
417
+    elseif ($taille == 0 and $taille_y == 0) {
418
+        return '';
419
+    }
420
+
421
+    $fonction = array('image_reduire', func_get_args());
422
+
423
+    return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
424 424
 }
425 425
 
426 426
 
@@ -439,20 +439,20 @@  discard block
 block discarded – undo
439 439
  *     Code HTML de l'image ou du texte.
440 440
  **/
441 441
 function image_reduire_par($img, $val = 1, $force = false) {
442
-	list($hauteur, $largeur) = taille_image($img);
442
+    list($hauteur, $largeur) = taille_image($img);
443 443
 
444
-	$l = round($largeur / $val);
445
-	$h = round($hauteur / $val);
444
+    $l = round($largeur / $val);
445
+    $h = round($hauteur / $val);
446 446
 
447
-	if ($l > $h) {
448
-		$h = 0;
449
-	} else {
450
-		$l = 0;
451
-	}
447
+    if ($l > $h) {
448
+        $h = 0;
449
+    } else {
450
+        $l = 0;
451
+    }
452 452
 
453
-	$img = image_reduire($img, $l, $h, $force);
453
+    $img = image_reduire($img, $l, $h, $force);
454 454
 
455
-	return $img;
455
+    return $img;
456 456
 }
457 457
 
458 458
 /**
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
  *      Couleur en écriture hexadécimale.
474 474
 **/
475 475
 function filtre_couleur_saturation_dist($couleur, $val) {
476
-	if (function_exists('couleur_saturation')) {
477
-		return couleur_saturation($couleur, $val);
478
-	}
479
-	return $couleur;
476
+    if (function_exists('couleur_saturation')) {
477
+        return couleur_saturation($couleur, $val);
478
+    }
479
+    return $couleur;
480 480
 }
481 481
 
482 482
 /**
@@ -497,8 +497,8 @@  discard block
 block discarded – undo
497 497
  *      Couleur en écriture hexadécimale.
498 498
 **/
499 499
 function filtre_couleur_luminance_dist($couleur, $val) {
500
-	if (function_exists('couleur_luminance')) {
501
-		return couleur_luminance($couleur, $val);
502
-	}
503
-	return $couleur;
500
+    if (function_exists('couleur_luminance')) {
501
+        return couleur_luminance($couleur, $val);
502
+    }
503
+    return $couleur;
504 504
 }
Please login to merge, or discard this patch.
ecrire/inc/flock.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -644,7 +644,7 @@
 block discarded – undo
644 644
  *
645 645
  * @param string $dir
646 646
  *     Répertoire à parcourir
647
- * @param int|string $pattern
647
+ * @param integer $pattern
648 648
  *     Expression régulière pour trouver des fichiers, tel que `[.]lock$`
649 649
  * @param int $maxfiles
650 650
  *     Nombre de fichiers maximums retournés
Please login to merge, or discard this patch.
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_TEST_FILE_EXISTS')) {
24
-	/** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
-	define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
24
+    /** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
+    define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
26 26
 }
27 27
 
28 28
 #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille)
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
31 31
 
32 32
 if (_SPIP_LOCK_MODE == 2) {
33
-	include_spip('inc/nfslock');
33
+    include_spip('inc/nfslock');
34 34
 }
35 35
 
36 36
 $GLOBALS['liste_verrous'] = array();
@@ -53,24 +53,24 @@  discard block
 block discarded – undo
53 53
  *     Ressource sur le fichier ouvert, sinon false.
54 54
  **/
55 55
 function spip_fopen_lock($fichier, $mode, $verrou) {
56
-	if (_SPIP_LOCK_MODE == 1) {
57
-		if ($fl = @fopen($fichier, $mode)) {
58
-			// verrou
59
-			@flock($fl, $verrou);
60
-		}
61
-
62
-		return $fl;
63
-	} elseif (_SPIP_LOCK_MODE == 2) {
64
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
-			$GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou);
66
-
67
-			return $fl;
68
-		} else {
69
-			return false;
70
-		}
71
-	}
72
-
73
-	return @fopen($fichier, $mode);
56
+    if (_SPIP_LOCK_MODE == 1) {
57
+        if ($fl = @fopen($fichier, $mode)) {
58
+            // verrou
59
+            @flock($fl, $verrou);
60
+        }
61
+
62
+        return $fl;
63
+    } elseif (_SPIP_LOCK_MODE == 2) {
64
+        if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
+            $GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou);
66
+
67
+            return $fl;
68
+        } else {
69
+            return false;
70
+        }
71
+    }
72
+
73
+    return @fopen($fichier, $mode);
74 74
 }
75 75
 
76 76
 /**
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
  *     true si succès, false sinon.
86 86
  **/
87 87
 function spip_fclose_unlock($handle) {
88
-	if (_SPIP_LOCK_MODE == 1) {
89
-		@flock($handle, LOCK_UN);
90
-	} elseif (_SPIP_LOCK_MODE == 2) {
91
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
-		unset($GLOBALS['liste_verrous'][$handle]);
93
-	}
94
-
95
-	return @fclose($handle);
88
+    if (_SPIP_LOCK_MODE == 1) {
89
+        @flock($handle, LOCK_UN);
90
+    } elseif (_SPIP_LOCK_MODE == 2) {
91
+        spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
+        unset($GLOBALS['liste_verrous'][$handle]);
93
+    }
94
+
95
+    return @fclose($handle);
96 96
 }
97 97
 
98 98
 
@@ -106,23 +106,23 @@  discard block
 block discarded – undo
106 106
  *     Contenu du fichier
107 107
  **/
108 108
 function spip_file_get_contents($fichier) {
109
-	if (substr($fichier, -3) != '.gz') {
110
-		if (function_exists('file_get_contents')) {
111
-			// quand on est sous windows on ne sait pas si file_get_contents marche
112
-			// on essaye : si ca retourne du contenu alors c'est bon
113
-			// sinon on fait un file() pour avoir le coeur net
114
-			$contenu = @file_get_contents($fichier);
115
-			if (!$contenu and _OS_SERVEUR == 'windows') {
116
-				$contenu = @file($fichier);
117
-			}
118
-		} else {
119
-			$contenu = @file($fichier);
120
-		}
121
-	} else {
122
-		$contenu = @gzfile($fichier);
123
-	}
124
-
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
109
+    if (substr($fichier, -3) != '.gz') {
110
+        if (function_exists('file_get_contents')) {
111
+            // quand on est sous windows on ne sait pas si file_get_contents marche
112
+            // on essaye : si ca retourne du contenu alors c'est bon
113
+            // sinon on fait un file() pour avoir le coeur net
114
+            $contenu = @file_get_contents($fichier);
115
+            if (!$contenu and _OS_SERVEUR == 'windows') {
116
+                $contenu = @file($fichier);
117
+            }
118
+        } else {
119
+            $contenu = @file($fichier);
120
+        }
121
+    } else {
122
+        $contenu = @gzfile($fichier);
123
+    }
124
+
125
+    return is_array($contenu) ? join('', $contenu) : (string)$contenu;
126 126
 }
127 127
 
128 128
 
@@ -147,48 +147,48 @@  discard block
 block discarded – undo
147 147
  *     true si l'opération a réussie, false sinon.
148 148
  **/
149 149
 function lire_fichier($fichier, &$contenu, $options = array()) {
150
-	$contenu = '';
151
-	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
-	// economisons donc les acces disque, sauf chez free qui rale pour un rien
153
-	if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
-		return false;
155
-	}
156
-
157
-	#spip_timer('lire_fichier');
158
-
159
-	// pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
-	if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
-		// lire le fichier avant tout
162
-		$contenu = spip_file_get_contents($fichier);
163
-
164
-		// le fichier a-t-il ete supprime par le locker ?
165
-		// on ne verifie que si la tentative de lecture a echoue
166
-		// pour discriminer un contenu vide d'un fichier absent
167
-		// et eviter un acces disque
168
-		if (!$contenu and !@file_exists($fichier)) {
169
-			spip_fclose_unlock($fl);
170
-
171
-			return false;
172
-		}
173
-
174
-		// liberer le verrou
175
-		spip_fclose_unlock($fl);
176
-
177
-		// Verifications
178
-		$ok = true;
179
-		if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
181
-		}
182
-
183
-		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
-		if (!$ok) {
185
-			spip_log("echec lecture $fichier");
186
-		}
187
-
188
-		return $ok;
189
-	}
190
-
191
-	return false;
150
+    $contenu = '';
151
+    // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
+    // economisons donc les acces disque, sauf chez free qui rale pour un rien
153
+    if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
+        return false;
155
+    }
156
+
157
+    #spip_timer('lire_fichier');
158
+
159
+    // pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
+    if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
+        // lire le fichier avant tout
162
+        $contenu = spip_file_get_contents($fichier);
163
+
164
+        // le fichier a-t-il ete supprime par le locker ?
165
+        // on ne verifie que si la tentative de lecture a echoue
166
+        // pour discriminer un contenu vide d'un fichier absent
167
+        // et eviter un acces disque
168
+        if (!$contenu and !@file_exists($fichier)) {
169
+            spip_fclose_unlock($fl);
170
+
171
+            return false;
172
+        }
173
+
174
+        // liberer le verrou
175
+        spip_fclose_unlock($fl);
176
+
177
+        // Verifications
178
+        $ok = true;
179
+        if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
+            $ok &= (preg_match(",[?]>\n?$,", $contenu));
181
+        }
182
+
183
+        #spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
+        if (!$ok) {
185
+            spip_log("echec lecture $fichier");
186
+        }
187
+
188
+        return $ok;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 
@@ -216,85 +216,85 @@  discard block
 block discarded – undo
216 216
  **/
217 217
 function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) {
218 218
 
219
-	#spip_timer('ecrire_fichier');
220
-
221
-	// verrouiller le fichier destination
222
-	if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
-		// ecrire les donnees, compressees le cas echeant
224
-		// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
-		// de le recreer si le locker qui nous precede l'avait supprime...)
226
-		if (substr($fichier, -3) == '.gz') {
227
-			$contenu = gzencode($contenu);
228
-		}
229
-		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
-		// pour etre sur d'avoir une operation atomique
231
-		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
-		// sauf sous wintruc ou ca ne marche pas
233
-		$ok = false;
234
-		if ($truncate and _OS_SERVEUR != 'windows') {
235
-			if (!function_exists('creer_uniqid')) {
236
-				include_spip('inc/acces');
237
-			}
238
-			$id = creer_uniqid();
239
-			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
-				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
-				$ok = ($s == $a);
243
-				spip_fclose_unlock($fp2);
244
-				spip_fclose_unlock($fp);
245
-				// unlink direct et pas spip_unlink car on avait deja le verrou
246
-				// a priori pas besoin car rename ecrase la cible
247
-				// @unlink($fichier);
248
-				// le rename aussitot, atomique quand on est pas sous windows
249
-				// au pire on arrive en second en cas de concourance, et le rename echoue
250
-				// --> on a la version de l'autre process qui doit etre identique
251
-				@rename("$fichier.$id", $fichier);
252
-				// precaution en cas d'echec du rename
253
-				if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
-					@unlink("$fichier.$id");
255
-				}
256
-				if ($ok) {
257
-					$ok = file_exists($fichier);
258
-				}
259
-			} else // echec mais penser a fermer ..
260
-			{
261
-				spip_fclose_unlock($fp);
262
-			}
263
-		}
264
-		// sinon ou si methode precedente a echoueee
265
-		// on se rabat sur la methode ancienne
266
-		if (!$ok) {
267
-			// ici on est en ajout ou sous windows, cas desespere
268
-			if ($truncate) {
269
-				@ftruncate($fp, 0);
270
-			}
271
-			$s = @fputs($fp, $contenu, $a = strlen($contenu));
272
-
273
-			$ok = ($s == $a);
274
-			spip_fclose_unlock($fp);
275
-		}
276
-
277
-		// liberer le verrou et fermer le fichier
278
-		@chmod($fichier, _SPIP_CHMOD & 0666);
279
-		if ($ok) {
280
-			if (strpos($fichier, ".php") !== false) {
281
-				spip_clear_opcode_cache(realpath($fichier));
282
-			}
283
-
284
-			return $ok;
285
-		}
286
-	}
287
-
288
-	if (!$ignorer_echec) {
289
-		include_spip('inc/autoriser');
290
-		if (autoriser('chargerftp')) {
291
-			raler_fichier($fichier);
292
-		}
293
-		spip_unlink($fichier);
294
-	}
295
-	spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
-
297
-	return false;
219
+    #spip_timer('ecrire_fichier');
220
+
221
+    // verrouiller le fichier destination
222
+    if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
+        // ecrire les donnees, compressees le cas echeant
224
+        // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
+        // de le recreer si le locker qui nous precede l'avait supprime...)
226
+        if (substr($fichier, -3) == '.gz') {
227
+            $contenu = gzencode($contenu);
228
+        }
229
+        // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
+        // pour etre sur d'avoir une operation atomique
231
+        // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
+        // sauf sous wintruc ou ca ne marche pas
233
+        $ok = false;
234
+        if ($truncate and _OS_SERVEUR != 'windows') {
235
+            if (!function_exists('creer_uniqid')) {
236
+                include_spip('inc/acces');
237
+            }
238
+            $id = creer_uniqid();
239
+            // on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
+            if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
+                $s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
+                $ok = ($s == $a);
243
+                spip_fclose_unlock($fp2);
244
+                spip_fclose_unlock($fp);
245
+                // unlink direct et pas spip_unlink car on avait deja le verrou
246
+                // a priori pas besoin car rename ecrase la cible
247
+                // @unlink($fichier);
248
+                // le rename aussitot, atomique quand on est pas sous windows
249
+                // au pire on arrive en second en cas de concourance, et le rename echoue
250
+                // --> on a la version de l'autre process qui doit etre identique
251
+                @rename("$fichier.$id", $fichier);
252
+                // precaution en cas d'echec du rename
253
+                if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
+                    @unlink("$fichier.$id");
255
+                }
256
+                if ($ok) {
257
+                    $ok = file_exists($fichier);
258
+                }
259
+            } else // echec mais penser a fermer ..
260
+            {
261
+                spip_fclose_unlock($fp);
262
+            }
263
+        }
264
+        // sinon ou si methode precedente a echoueee
265
+        // on se rabat sur la methode ancienne
266
+        if (!$ok) {
267
+            // ici on est en ajout ou sous windows, cas desespere
268
+            if ($truncate) {
269
+                @ftruncate($fp, 0);
270
+            }
271
+            $s = @fputs($fp, $contenu, $a = strlen($contenu));
272
+
273
+            $ok = ($s == $a);
274
+            spip_fclose_unlock($fp);
275
+        }
276
+
277
+        // liberer le verrou et fermer le fichier
278
+        @chmod($fichier, _SPIP_CHMOD & 0666);
279
+        if ($ok) {
280
+            if (strpos($fichier, ".php") !== false) {
281
+                spip_clear_opcode_cache(realpath($fichier));
282
+            }
283
+
284
+            return $ok;
285
+        }
286
+    }
287
+
288
+    if (!$ignorer_echec) {
289
+        include_spip('inc/autoriser');
290
+        if (autoriser('chargerftp')) {
291
+            raler_fichier($fichier);
292
+        }
293
+        spip_unlink($fichier);
294
+    }
295
+    spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
+
297
+    return false;
298 298
 }
299 299
 
300 300
 /**
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
314 314
  *     Écriture avec troncation ?
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317
-	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
-	}
320
-	$contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
317
+    if (substr($fichier, -4) !== '.php') {
318
+        spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
+    }
320
+    $contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
321 321
 
322
-	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
322
+    return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
324 324
 
325 325
 /**
@@ -339,11 +339,11 @@  discard block
 block discarded – undo
339 339
  *     true si l'opération a réussie, false sinon.
340 340
  */
341 341
 function lire_fichier_securise($fichier, &$contenu, $options = array()) {
342
-	if ($res = lire_fichier($fichier, $contenu, $options)) {
343
-		$contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n"));
344
-	}
342
+    if ($res = lire_fichier($fichier, $contenu, $options)) {
343
+        $contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n"));
344
+    }
345 345
 
346
-	return $res;
346
+    return $res;
347 347
 }
348 348
 
349 349
 /**
@@ -358,20 +358,20 @@  discard block
 block discarded – undo
358 358
  *     Chemin du fichier
359 359
  **/
360 360
 function raler_fichier($fichier) {
361
-	include_spip('inc/minipres');
362
-	$dir = dirname($fichier);
363
-	http_status(401);
364
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
365
-		. _T('texte_inc_meta_1', array('fichier' => $fichier))
366
-		. " <a href='"
367
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
368
-		. "'>"
369
-		. _T('texte_inc_meta_2')
370
-		. "</a> "
371
-		. _T('texte_inc_meta_3',
372
-			array('repertoire' => joli_repertoire($dir)))
373
-		. "</h4>\n");
374
-	exit;
361
+    include_spip('inc/minipres');
362
+    $dir = dirname($fichier);
363
+    http_status(401);
364
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
365
+        . _T('texte_inc_meta_1', array('fichier' => $fichier))
366
+        . " <a href='"
367
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
368
+        . "'>"
369
+        . _T('texte_inc_meta_2')
370
+        . "</a> "
371
+        . _T('texte_inc_meta_3',
372
+            array('repertoire' => joli_repertoire($dir)))
373
+        . "</h4>\n");
374
+    exit;
375 375
 }
376 376
 
377 377
 
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
  *     - true si récent, false sinon
387 387
  */
388 388
 function jeune_fichier($fichier, $n) {
389
-	if (!file_exists($fichier)) {
390
-		return false;
391
-	}
392
-	if (!$c = @filemtime($fichier)) {
393
-		return false;
394
-	}
395
-
396
-	return (time() - $n <= $c);
389
+    if (!file_exists($fichier)) {
390
+        return false;
391
+    }
392
+    if (!$c = @filemtime($fichier)) {
393
+        return false;
394
+    }
395
+
396
+    return (time() - $n <= $c);
397 397
 }
398 398
 
399 399
 /**
@@ -409,22 +409,22 @@  discard block
 block discarded – undo
409 409
  *     - void sinon
410 410
  */
411 411
 function supprimer_fichier($fichier, $lock = true) {
412
-	if (!@file_exists($fichier)) {
413
-		return true;
414
-	}
415
-
416
-	if ($lock) {
417
-		// verrouiller le fichier destination
418
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
419
-			return false;
420
-		}
421
-
422
-		// liberer le verrou
423
-		spip_fclose_unlock($fp);
424
-	}
425
-
426
-	// supprimer
427
-	return @unlink($fichier);
412
+    if (!@file_exists($fichier)) {
413
+        return true;
414
+    }
415
+
416
+    if ($lock) {
417
+        // verrouiller le fichier destination
418
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
419
+            return false;
420
+        }
421
+
422
+        // liberer le verrou
423
+        spip_fclose_unlock($fp);
424
+    }
425
+
426
+    // supprimer
427
+    return @unlink($fichier);
428 428
 }
429 429
 
430 430
 /**
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
  *     Chemin du fichier
435 435
  */
436 436
 function spip_unlink($f) {
437
-	if (!is_dir($f)) {
438
-		supprimer_fichier($f, false);
439
-	} else {
440
-		@unlink("$f/.ok");
441
-		@rmdir($f);
442
-	}
437
+    if (!is_dir($f)) {
438
+        supprimer_fichier($f, false);
439
+    } else {
440
+        @unlink("$f/.ok");
441
+        @rmdir($f);
442
+    }
443 443
 }
444 444
 
445 445
 /**
@@ -453,23 +453,23 @@  discard block
 block discarded – undo
453 453
  *   The absolute path of the PHP file to invalidate.
454 454
  */
455 455
 function spip_clear_opcode_cache($filepath) {
456
-	clearstatcache(true, $filepath);
457
-
458
-	// Zend OPcache
459
-	if (function_exists('opcache_invalidate')) {
460
-		$invalidate = @opcache_invalidate($filepath, true);
461
-		// si l'invalidation a echoue lever un flag
462
-		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
463
-			define('_spip_attend_invalidation_opcode_cache',true);
464
-		}
465
-	}
466
-	// APC.
467
-	if (function_exists('apc_delete_file')) {
468
-		// apc_delete_file() throws a PHP warning in case the specified file was
469
-		// not compiled yet.
470
-		// @see http://php.net/apc-delete-file
471
-		@apc_delete_file($filepath);
472
-	}
456
+    clearstatcache(true, $filepath);
457
+
458
+    // Zend OPcache
459
+    if (function_exists('opcache_invalidate')) {
460
+        $invalidate = @opcache_invalidate($filepath, true);
461
+        // si l'invalidation a echoue lever un flag
462
+        if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
463
+            define('_spip_attend_invalidation_opcode_cache',true);
464
+        }
465
+    }
466
+    // APC.
467
+    if (function_exists('apc_delete_file')) {
468
+        // apc_delete_file() throws a PHP warning in case the specified file was
469
+        // not compiled yet.
470
+        // @see http://php.net/apc-delete-file
471
+        @apc_delete_file($filepath);
472
+    }
473 473
 }
474 474
 
475 475
 /**
@@ -492,24 +492,24 @@  discard block
 block discarded – undo
492 492
  *
493 493
  */
494 494
 function spip_attend_invalidation_opcode_cache($timestamp = null) {
495
-	if (function_exists('opcache_get_configuration')
496
-		and @ini_get('opcache.enable')
497
-		and @ini_get('opcache.validate_timestamps')
498
-		and $duree = @ini_get('opcache.revalidate_freq')
499
-		and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
500
-	) {
501
-		$wait = $duree + 1;
502
-		if ($timestamp) {
503
-			$wait -= (time() - $timestamp);
504
-			if ($wait<0) {
505
-				$wait = 0;
506
-			}
507
-		}
508
-		spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
509
-		if ($wait) {
510
-			sleep($duree + 1);
511
-		}
512
-	}
495
+    if (function_exists('opcache_get_configuration')
496
+        and @ini_get('opcache.enable')
497
+        and @ini_get('opcache.validate_timestamps')
498
+        and $duree = @ini_get('opcache.revalidate_freq')
499
+        and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
500
+    ) {
501
+        $wait = $duree + 1;
502
+        if ($timestamp) {
503
+            $wait -= (time() - $timestamp);
504
+            if ($wait<0) {
505
+                $wait = 0;
506
+            }
507
+        }
508
+        spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
509
+        if ($wait) {
510
+            sleep($duree + 1);
511
+        }
512
+    }
513 513
 }
514 514
 
515 515
 
@@ -522,26 +522,26 @@  discard block
 block discarded – undo
522 522
  * @return bool Suppression reussie.
523 523
  */
524 524
 function supprimer_repertoire($dir) {
525
-	if (!file_exists($dir)) {
526
-		return true;
527
-	}
528
-	if (!is_dir($dir) || is_link($dir)) {
529
-		return @unlink($dir);
530
-	}
531
-
532
-	foreach (scandir($dir) as $item) {
533
-		if ($item == '.' || $item == '..') {
534
-			continue;
535
-		}
536
-		if (!supprimer_repertoire($dir . "/" . $item)) {
537
-			@chmod($dir . "/" . $item, 0777);
538
-			if (!supprimer_repertoire($dir . "/" . $item)) {
539
-				return false;
540
-			}
541
-		};
542
-	}
543
-
544
-	return @rmdir($dir);
525
+    if (!file_exists($dir)) {
526
+        return true;
527
+    }
528
+    if (!is_dir($dir) || is_link($dir)) {
529
+        return @unlink($dir);
530
+    }
531
+
532
+    foreach (scandir($dir) as $item) {
533
+        if ($item == '.' || $item == '..') {
534
+            continue;
535
+        }
536
+        if (!supprimer_repertoire($dir . "/" . $item)) {
537
+            @chmod($dir . "/" . $item, 0777);
538
+            if (!supprimer_repertoire($dir . "/" . $item)) {
539
+                return false;
540
+            }
541
+        };
542
+    }
543
+
544
+    return @rmdir($dir);
545 545
 }
546 546
 
547 547
 
@@ -570,57 +570,57 @@  discard block
 block discarded – undo
570 570
  *     Chemin du répertoire créé.
571 571
  **/
572 572
 function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
573
-	static $dirs = array();
574
-
575
-	$base = str_replace("//", "/", $base);
576
-
577
-	# suppr le dernier caractere si c'est un /
578
-	$base = rtrim($base, '/');
579
-
580
-	if (!strlen($subdir)) {
581
-		$n = strrpos($base, "/");
582
-		if ($n === false) {
583
-			return $nobase ? '' : ($base . '/');
584
-		}
585
-		$subdir = substr($base, $n + 1);
586
-		$base = substr($base, 0, $n + 1);
587
-	} else {
588
-		$base .= '/';
589
-		$subdir = str_replace("/", "", $subdir);
590
-	}
591
-
592
-	$baseaff = $nobase ? '' : $base;
593
-	if (isset($dirs[$base . $subdir])) {
594
-		return $baseaff . $dirs[$base . $subdir];
595
-	}
596
-
597
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
598
-
599
-	if (file_exists("$path/.ok")) {
600
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
601
-	}
602
-
603
-	@mkdir($path, _SPIP_CHMOD);
604
-	@chmod($path, _SPIP_CHMOD);
605
-
606
-	if (is_dir($path) && is_writable($path)) {
607
-		@touch("$path/.ok");
608
-		spip_log("creation $base$subdir/");
609
-
610
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
611
-	}
612
-
613
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
614
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
615
-	spip_log("echec creation $base${subdir}");
616
-	if ($tantpis) {
617
-		return '';
618
-	}
619
-	if (!_DIR_RESTREINT) {
620
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
621
-	}
622
-	$base .= $subdir;
623
-	raler_fichier($base . '/.ok');
573
+    static $dirs = array();
574
+
575
+    $base = str_replace("//", "/", $base);
576
+
577
+    # suppr le dernier caractere si c'est un /
578
+    $base = rtrim($base, '/');
579
+
580
+    if (!strlen($subdir)) {
581
+        $n = strrpos($base, "/");
582
+        if ($n === false) {
583
+            return $nobase ? '' : ($base . '/');
584
+        }
585
+        $subdir = substr($base, $n + 1);
586
+        $base = substr($base, 0, $n + 1);
587
+    } else {
588
+        $base .= '/';
589
+        $subdir = str_replace("/", "", $subdir);
590
+    }
591
+
592
+    $baseaff = $nobase ? '' : $base;
593
+    if (isset($dirs[$base . $subdir])) {
594
+        return $baseaff . $dirs[$base . $subdir];
595
+    }
596
+
597
+    $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
598
+
599
+    if (file_exists("$path/.ok")) {
600
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
601
+    }
602
+
603
+    @mkdir($path, _SPIP_CHMOD);
604
+    @chmod($path, _SPIP_CHMOD);
605
+
606
+    if (is_dir($path) && is_writable($path)) {
607
+        @touch("$path/.ok");
608
+        spip_log("creation $base$subdir/");
609
+
610
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
611
+    }
612
+
613
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
614
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
615
+    spip_log("echec creation $base${subdir}");
616
+    if ($tantpis) {
617
+        return '';
618
+    }
619
+    if (!_DIR_RESTREINT) {
620
+        $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
621
+    }
622
+    $base .= $subdir;
623
+    raler_fichier($base . '/.ok');
624 624
 }
625 625
 
626 626
 
@@ -653,51 +653,51 @@  discard block
 block discarded – undo
653 653
  *     Chemins des fichiers trouvés.
654 654
  **/
655 655
 function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) {
656
-	$nbfiles = 0;
657
-	if ($pattern == -1) {
658
-		$pattern = "^$dir";
659
-	}
660
-	$fichiers = array();
661
-	// revenir au repertoire racine si on a recu dossier/truc
662
-	// pour regarder dossier/truc/ ne pas oublier le / final
663
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
664
-	if ($dir == '') {
665
-		$dir = '.';
666
-	}
667
-
668
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
669
-		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
670
-			if ($f[0] != '.' # ignorer . .. .svn etc
671
-				and $f != 'CVS'
672
-				and $f != 'remove.txt'
673
-				and is_readable($f = "$dir/$f")
674
-			) {
675
-				if (is_file($f)) {
676
-					if (preg_match(";$pattern;iS", $f)) {
677
-						$fichiers[] = $f;
678
-						$nbfiles++;
679
-					}
680
-				} else {
681
-					if (is_dir($f) and is_array($recurs)) {
682
-						$rp = @realpath($f);
683
-						if (!is_string($rp) or !strlen($rp)) {
684
-							$rp = $f;
685
-						} # realpath n'est peut etre pas autorise
686
-						if (!isset($recurs[$rp])) {
687
-							$recurs[$rp] = true;
688
-							$beginning = $fichiers;
689
-							$end = preg_files("$f/", $pattern,
690
-								$maxfiles - $nbfiles, $recurs);
691
-							$fichiers = array_merge((array)$beginning, (array)$end);
692
-							$nbfiles = count($fichiers);
693
-						}
694
-					}
695
-				}
696
-			}
697
-		}
698
-		closedir($d);
699
-	}
700
-	sort($fichiers);
701
-
702
-	return $fichiers;
656
+    $nbfiles = 0;
657
+    if ($pattern == -1) {
658
+        $pattern = "^$dir";
659
+    }
660
+    $fichiers = array();
661
+    // revenir au repertoire racine si on a recu dossier/truc
662
+    // pour regarder dossier/truc/ ne pas oublier le / final
663
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
664
+    if ($dir == '') {
665
+        $dir = '.';
666
+    }
667
+
668
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
669
+        while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
670
+            if ($f[0] != '.' # ignorer . .. .svn etc
671
+                and $f != 'CVS'
672
+                and $f != 'remove.txt'
673
+                and is_readable($f = "$dir/$f")
674
+            ) {
675
+                if (is_file($f)) {
676
+                    if (preg_match(";$pattern;iS", $f)) {
677
+                        $fichiers[] = $f;
678
+                        $nbfiles++;
679
+                    }
680
+                } else {
681
+                    if (is_dir($f) and is_array($recurs)) {
682
+                        $rp = @realpath($f);
683
+                        if (!is_string($rp) or !strlen($rp)) {
684
+                            $rp = $f;
685
+                        } # realpath n'est peut etre pas autorise
686
+                        if (!isset($recurs[$rp])) {
687
+                            $recurs[$rp] = true;
688
+                            $beginning = $fichiers;
689
+                            $end = preg_files("$f/", $pattern,
690
+                                $maxfiles - $nbfiles, $recurs);
691
+                            $fichiers = array_merge((array)$beginning, (array)$end);
692
+                            $nbfiles = count($fichiers);
693
+                        }
694
+                    }
695
+                }
696
+            }
697
+        }
698
+        closedir($d);
699
+    }
700
+    sort($fichiers);
701
+
702
+    return $fichiers;
703 703
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		$contenu = @gzfile($fichier);
123 123
 	}
124 124
 
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
125
+	return is_array($contenu) ? join('', $contenu) : (string) $contenu;
126 126
 }
127 127
 
128 128
 
@@ -315,9 +315,9 @@  discard block
 block discarded – undo
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317 317
 	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
318
+		spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
319 319
 	}
320
-	$contenu = "<" . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
320
+	$contenu = "<"."?php die ('Acces interdit'); ?".">\n".$contenu;
321 321
 
322 322
 	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
  */
341 341
 function lire_fichier_securise($fichier, &$contenu, $options = array()) {
342 342
 	if ($res = lire_fichier($fichier, $contenu, $options)) {
343
-		$contenu = substr($contenu, strlen("<" . "?php die ('Acces interdit'); ?" . ">\n"));
343
+		$contenu = substr($contenu, strlen("<"."?php die ('Acces interdit'); ?".">\n"));
344 344
 	}
345 345
 
346 346
 	return $res;
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		$invalidate = @opcache_invalidate($filepath, true);
461 461
 		// si l'invalidation a echoue lever un flag
462 462
 		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
463
-			define('_spip_attend_invalidation_opcode_cache',true);
463
+			define('_spip_attend_invalidation_opcode_cache', true);
464 464
 		}
465 465
 	}
466 466
 	// APC.
@@ -501,11 +501,11 @@  discard block
 block discarded – undo
501 501
 		$wait = $duree + 1;
502 502
 		if ($timestamp) {
503 503
 			$wait -= (time() - $timestamp);
504
-			if ($wait<0) {
504
+			if ($wait < 0) {
505 505
 				$wait = 0;
506 506
 			}
507 507
 		}
508
-		spip_log('Probleme de configuration opcache.revalidate_freq '. $duree .'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
508
+		spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
509 509
 		if ($wait) {
510 510
 			sleep($duree + 1);
511 511
 		}
@@ -533,9 +533,9 @@  discard block
 block discarded – undo
533 533
 		if ($item == '.' || $item == '..') {
534 534
 			continue;
535 535
 		}
536
-		if (!supprimer_repertoire($dir . "/" . $item)) {
537
-			@chmod($dir . "/" . $item, 0777);
538
-			if (!supprimer_repertoire($dir . "/" . $item)) {
536
+		if (!supprimer_repertoire($dir."/".$item)) {
537
+			@chmod($dir."/".$item, 0777);
538
+			if (!supprimer_repertoire($dir."/".$item)) {
539 539
 				return false;
540 540
 			}
541 541
 		};
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	if (!strlen($subdir)) {
581 581
 		$n = strrpos($base, "/");
582 582
 		if ($n === false) {
583
-			return $nobase ? '' : ($base . '/');
583
+			return $nobase ? '' : ($base.'/');
584 584
 		}
585 585
 		$subdir = substr($base, $n + 1);
586 586
 		$base = substr($base, 0, $n + 1);
@@ -590,14 +590,14 @@  discard block
 block discarded – undo
590 590
 	}
591 591
 
592 592
 	$baseaff = $nobase ? '' : $base;
593
-	if (isset($dirs[$base . $subdir])) {
594
-		return $baseaff . $dirs[$base . $subdir];
593
+	if (isset($dirs[$base.$subdir])) {
594
+		return $baseaff.$dirs[$base.$subdir];
595 595
 	}
596 596
 
597
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
597
+	$path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
598 598
 
599 599
 	if (file_exists("$path/.ok")) {
600
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
600
+		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
601 601
 	}
602 602
 
603 603
 	@mkdir($path, _SPIP_CHMOD);
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 		@touch("$path/.ok");
608 608
 		spip_log("creation $base$subdir/");
609 609
 
610
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
610
+		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
611 611
 	}
612 612
 
613 613
 	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
@@ -617,10 +617,10 @@  discard block
 block discarded – undo
617 617
 		return '';
618 618
 	}
619 619
 	if (!_DIR_RESTREINT) {
620
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
620
+		$base = preg_replace(',^'._DIR_RACINE.',', '', $base);
621 621
 	}
622 622
 	$base .= $subdir;
623
-	raler_fichier($base . '/.ok');
623
+	raler_fichier($base.'/.ok');
624 624
 }
625 625
 
626 626
 
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 							$beginning = $fichiers;
689 689
 							$end = preg_files("$f/", $pattern,
690 690
 								$maxfiles - $nbfiles, $recurs);
691
-							$fichiers = array_merge((array)$beginning, (array)$end);
691
+							$fichiers = array_merge((array) $beginning, (array) $end);
692 692
 							$nbfiles = count($fichiers);
693 693
 						}
694 694
 					}
Please login to merge, or discard this patch.
ecrire/inc/importer_csv.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * Importer le charset d'une ligne
33 33
  *
34 34
  * @param string $texte
35
- * @return array
35
+ * @return string
36 36
  */
37 37
 function importer_csv_importcharset($texte) {
38 38
 	// le plus frequent, en particulier avec les trucs de ms@@@
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
  * @param string $delim
67 67
  * @param string $enclos
68 68
  * @param int $len
69
- * @return array
69
+ * @return boolean
70 70
  */
71 71
 function inc_importer_csv_dist($file, $head = false, $delim = ", ", $enclos = '"', $len = 10000) {
72 72
 	$return = false;
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/charsets');
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
  * @return array
36 36
  */
37 37
 function importer_csv_importcharset($texte) {
38
-	// le plus frequent, en particulier avec les trucs de ms@@@
39
-	$charset_source = 'iso-8859-1';
40
-	// mais open-office sait faire mieux, donc mefiance !
41
-	if (is_utf8($texte)) {
42
-		$charset_source = 'utf-8';
43
-	}
38
+    // le plus frequent, en particulier avec les trucs de ms@@@
39
+    $charset_source = 'iso-8859-1';
40
+    // mais open-office sait faire mieux, donc mefiance !
41
+    if (is_utf8($texte)) {
42
+        $charset_source = 'utf-8';
43
+    }
44 44
 
45
-	return importer_charset($texte, $charset_source);
45
+    return importer_charset($texte, $charset_source);
46 46
 }
47 47
 
48 48
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string
54 54
  */
55 55
 function importer_csv_nettoie_key($key) {
56
-	return translitteration($key);
56
+    return translitteration($key);
57 57
 }
58 58
 
59 59
 /**
@@ -69,47 +69,47 @@  discard block
 block discarded – undo
69 69
  * @return array
70 70
  */
71 71
 function inc_importer_csv_dist($file, $head = false, $delim = ", ", $enclos = '"', $len = 10000) {
72
-	$return = false;
73
-	if (@file_exists($file)
74
-		and $handle = fopen($file, "r")
75
-	) {
76
-		if ($head) {
77
-			$header = fgetcsv($handle, $len, $delim, $enclos);
78
-			if ($header) {
79
-				$header = array_map('importer_csv_importcharset', $header);
80
-				$header = array_map('importer_csv_nettoie_key', $header);
81
-				$header_type = array();
82
-				foreach ($header as $heading) {
83
-					if (!isset($header_type[$heading])) {
84
-						$header_type[$heading] = "scalar";
85
-					} else {
86
-						$header_type[$heading] = "array";
87
-					}
88
-				}
89
-			}
90
-		}
91
-		while (($data = fgetcsv($handle, $len, $delim, $enclos)) !== false) {
92
-			$data = array_map('importer_csv_importcharset', $data);
93
-			if ($head and isset($header)) {
94
-				$row = array();
95
-				foreach ($header as $key => $heading) {
96
-					if ($header_type[$heading] == "array") {
97
-						if (!isset($row[$heading])) {
98
-							$row[$heading] = array();
99
-						}
100
-						if (isset($data[$key]) and strlen($data[$key])) {
101
-							$row[$heading][] = $data[$key];
102
-						}
103
-					} else {
104
-						$row[$heading] = (isset($data[$key])) ? $data[$key] : '';
105
-					}
106
-				}
107
-				$return[] = $row;
108
-			} else {
109
-				$return[] = $data;
110
-			}
111
-		}
112
-	}
72
+    $return = false;
73
+    if (@file_exists($file)
74
+        and $handle = fopen($file, "r")
75
+    ) {
76
+        if ($head) {
77
+            $header = fgetcsv($handle, $len, $delim, $enclos);
78
+            if ($header) {
79
+                $header = array_map('importer_csv_importcharset', $header);
80
+                $header = array_map('importer_csv_nettoie_key', $header);
81
+                $header_type = array();
82
+                foreach ($header as $heading) {
83
+                    if (!isset($header_type[$heading])) {
84
+                        $header_type[$heading] = "scalar";
85
+                    } else {
86
+                        $header_type[$heading] = "array";
87
+                    }
88
+                }
89
+            }
90
+        }
91
+        while (($data = fgetcsv($handle, $len, $delim, $enclos)) !== false) {
92
+            $data = array_map('importer_csv_importcharset', $data);
93
+            if ($head and isset($header)) {
94
+                $row = array();
95
+                foreach ($header as $key => $heading) {
96
+                    if ($header_type[$heading] == "array") {
97
+                        if (!isset($row[$heading])) {
98
+                            $row[$heading] = array();
99
+                        }
100
+                        if (isset($data[$key]) and strlen($data[$key])) {
101
+                            $row[$heading][] = $data[$key];
102
+                        }
103
+                    } else {
104
+                        $row[$heading] = (isset($data[$key])) ? $data[$key] : '';
105
+                    }
106
+                }
107
+                $return[] = $row;
108
+            } else {
109
+                $return[] = $data;
110
+            }
111
+        }
112
+    }
113 113
 
114
-	return $return;
114
+    return $return;
115 115
 }
Please login to merge, or discard this patch.
ecrire/inc/lang.php 3 patches
Doc Comments   +11 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  *
32 32
  * @param string $lang
33 33
  *     La langue à utiliser
34
- * @return string|bool
34
+ * @return false|string
35 35
  *     string : La langue qui a été utilisée si trouvée
36 36
  *     false : aucune langue ne correspondait à la demande
37 37
  **/
@@ -80,6 +80,9 @@  discard block
 block discarded – undo
80 80
 // retourne son 2e argument si c'est un index du premier
81 81
 // ou un index approchant sinon et si possible, 
82 82
 // la langue X etant consideree comme une approche de X_Y
83
+/**
84
+ * @return string
85
+ */
83 86
 function approcher_langue($trads, $lang = '') {
84 87
 
85 88
 	if (!$lang) {
@@ -175,6 +178,9 @@  discard block
 block discarded – undo
175 178
 // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax
176 179
 // 
177 180
 // http://code.spip.net/@menu_langues
181
+/**
182
+ * @param string $nom_select
183
+ */
178 184
 function menu_langues($nom_select, $default = '') {
179 185
 	include_spip('inc/actions');
180 186
 
@@ -209,6 +215,10 @@  discard block
 block discarded – undo
209 215
 }
210 216
 
211 217
 // http://code.spip.net/@select_langues
218
+/**
219
+ * @param string $change
220
+ * @param string $options
221
+ */
212 222
 function select_langues($nom_select, $change, $options, $label = "") {
213 223
 	static $cpt = 0;
214 224
 	$id = "menu_langues" . $cpt++;
Please login to merge, or discard this patch.
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Langue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -37,29 +37,29 @@  discard block
 block discarded – undo
37 37
  **/
38 38
 function changer_langue($lang) {
39 39
 
40
-	$liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
-		. ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
42
-
43
-	// Si la langue demandee n'existe pas, on essaie d'autres variantes
44
-	// Exemple : 'pt-br' => 'pt_br' => 'pt'
45
-	$lang = str_replace('-', '_', trim($lang));
46
-	if (!$lang) {
47
-		return false;
48
-	}
49
-
50
-	if (strpos($liste_langues, ",$lang,") !== false
51
-		or ($lang = preg_replace(',_.*,', '', $lang)
52
-			and strpos($liste_langues, ",$lang,") !== false)
53
-	) {
54
-
55
-		$GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
56
-		$GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
57
-		$GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
58
-
59
-		return $GLOBALS['spip_lang'] = $lang;
60
-	} else {
61
-		return false;
62
-	}
40
+    $liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
+        . ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
42
+
43
+    // Si la langue demandee n'existe pas, on essaie d'autres variantes
44
+    // Exemple : 'pt-br' => 'pt_br' => 'pt'
45
+    $lang = str_replace('-', '_', trim($lang));
46
+    if (!$lang) {
47
+        return false;
48
+    }
49
+
50
+    if (strpos($liste_langues, ",$lang,") !== false
51
+        or ($lang = preg_replace(',_.*,', '', $lang)
52
+            and strpos($liste_langues, ",$lang,") !== false)
53
+    ) {
54
+
55
+        $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
56
+        $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
57
+        $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
58
+
59
+        return $GLOBALS['spip_lang'] = $lang;
60
+    } else {
61
+        return false;
62
+    }
63 63
 }
64 64
 
65 65
 //
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
73 73
 
74 74
 function choisir_traduction($trads, $lang = '') {
75
-	$k = approcher_langue($trads, $lang);
75
+    $k = approcher_langue($trads, $lang);
76 76
 
77
-	return $k ? $trads[$k] : array_shift($trads);
77
+    return $k ? $trads[$k] : array_shift($trads);
78 78
 }
79 79
 
80 80
 // retourne son 2e argument si c'est un index du premier
@@ -82,21 +82,21 @@  discard block
 block discarded – undo
82 82
 // la langue X etant consideree comme une approche de X_Y
83 83
 function approcher_langue($trads, $lang = '') {
84 84
 
85
-	if (!$lang) {
86
-		$lang = $GLOBALS['spip_lang'];
87
-	}
88
-
89
-	if (isset($trads[$lang])) {
90
-		return $lang;
91
-	} // cas des langues xx_yy
92
-	else {
93
-		$r = explode('_', $lang);
94
-		if (isset($trads[$r[0]])) {
95
-			return $r[0];
96
-		}
97
-	}
98
-
99
-	return '';
85
+    if (!$lang) {
86
+        $lang = $GLOBALS['spip_lang'];
87
+    }
88
+
89
+    if (isset($trads[$lang])) {
90
+        return $lang;
91
+    } // cas des langues xx_yy
92
+    else {
93
+        $r = explode('_', $lang);
94
+        if (isset($trads[$r[0]])) {
95
+            return $r[0];
96
+        }
97
+    }
98
+
99
+    return '';
100 100
 }
101 101
 
102 102
 /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
  *     Nom de la langue, sinon son code.
112 112
  **/
113 113
 function traduire_nom_langue($lang) {
114
-	include_spip('inc/lang_liste');
115
-	include_spip('inc/charsets');
114
+    include_spip('inc/lang_liste');
115
+    include_spip('inc/charsets');
116 116
 
117
-	return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
117
+    return html2unicode(isset($GLOBALS['codes_langues'][$lang]) ? $GLOBALS['codes_langues'][$lang] : $lang);
118 118
 }
119 119
 
120 120
 //
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
129 129
 // http://code.spip.net/@lang_dir
130 130
 function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') {
131
-	static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi');
131
+    static $lang_rtl = array('ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi');
132 132
 
133
-	return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
134
-		$gaucher : $droitier;
133
+    return in_array(($lang ? $lang : $GLOBALS['spip_lang']), $lang_rtl) ?
134
+        $gaucher : $droitier;
135 135
 }
136 136
 
137 137
 // typo francaise ou anglaise ?
@@ -141,31 +141,31 @@  discard block
 block discarded – undo
141 141
 
142 142
 // http://code.spip.net/@lang_typo
143 143
 function lang_typo($lang = '') {
144
-	if (!$lang) {
145
-		$lang = isset($GLOBALS['lang_objet'])
146
-			? $GLOBALS['lang_objet']
147
-			: $GLOBALS['spip_lang'];
148
-	}
149
-	if ($lang == 'eo'
150
-		or $lang == 'fr'
151
-		or strncmp($lang, 'fr_', 3) == 0
152
-		or $lang == 'cpf'
153
-	) {
154
-		return 'fr';
155
-	} else {
156
-		return 'en';
157
-	}
144
+    if (!$lang) {
145
+        $lang = isset($GLOBALS['lang_objet'])
146
+            ? $GLOBALS['lang_objet']
147
+            : $GLOBALS['spip_lang'];
148
+    }
149
+    if ($lang == 'eo'
150
+        or $lang == 'fr'
151
+        or strncmp($lang, 'fr_', 3) == 0
152
+        or $lang == 'cpf'
153
+    ) {
154
+        return 'fr';
155
+    } else {
156
+        return 'en';
157
+    }
158 158
 }
159 159
 
160 160
 // gestion de la globale $lang_objet pour que les textes soient affiches
161 161
 // avec les memes typo et direction dans l'espace prive que dans le public
162 162
 // http://code.spip.net/@changer_typo
163 163
 function changer_typo($lang = '') {
164
-	if ($lang) {
165
-		$GLOBALS['lang_objet'] = $lang;
166
-	} else {
167
-		unset($GLOBALS['lang_objet']);
168
-	}
164
+    if ($lang) {
165
+        $GLOBALS['lang_objet'] = $lang;
166
+    } else {
167
+        unset($GLOBALS['lang_objet']);
168
+    }
169 169
 }
170 170
 
171 171
 //
@@ -176,55 +176,55 @@  discard block
 block discarded – undo
176 176
 // 
177 177
 // http://code.spip.net/@menu_langues
178 178
 function menu_langues($nom_select, $default = '') {
179
-	include_spip('inc/actions');
180
-
181
-	$langues = liste_options_langues($nom_select);
182
-	$ret = "";
183
-	if (!count($langues)) {
184
-		return '';
185
-	}
186
-
187
-	if (!$default) {
188
-		$default = $GLOBALS['spip_lang'];
189
-	}
190
-	foreach ($langues as $l) {
191
-		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
192
-		$ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n";
193
-	}
194
-
195
-	if (!test_espace_prive()) {
196
-		$cible = self();
197
-		$base = '';
198
-	} else {
199
-		$cible = self();
200
-		$base = spip_connect() ? 'base' : '';
201
-	}
202
-
203
-	$change = ' onchange="this.parentNode.parentNode.submit()"';
204
-
205
-	return generer_action_auteur('converser', $base, $cible,
206
-		(select_langues($nom_select, $change, $ret)
207
-			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
208
-		" method='post'");
179
+    include_spip('inc/actions');
180
+
181
+    $langues = liste_options_langues($nom_select);
182
+    $ret = "";
183
+    if (!count($langues)) {
184
+        return '';
185
+    }
186
+
187
+    if (!$default) {
188
+        $default = $GLOBALS['spip_lang'];
189
+    }
190
+    foreach ($langues as $l) {
191
+        $selected = ($l == $default) ? ' selected=\'selected\'' : '';
192
+        $ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n";
193
+    }
194
+
195
+    if (!test_espace_prive()) {
196
+        $cible = self();
197
+        $base = '';
198
+    } else {
199
+        $cible = self();
200
+        $base = spip_connect() ? 'base' : '';
201
+    }
202
+
203
+    $change = ' onchange="this.parentNode.parentNode.submit()"';
204
+
205
+    return generer_action_auteur('converser', $base, $cible,
206
+        (select_langues($nom_select, $change, $ret)
207
+            . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
208
+        " method='post'");
209 209
 }
210 210
 
211 211
 // http://code.spip.net/@select_langues
212 212
 function select_langues($nom_select, $change, $options, $label = "") {
213
-	static $cpt = 0;
214
-	$id = "menu_langues" . $cpt++;
215
-
216
-	return
217
-		"<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " .
218
-		"<select name='$nom_select' id='$id' "
219
-		. ((!test_espace_prive()) ?
220
-			("class='forml menu_langues'") :
221
-			(($nom_select == 'var_lang_ecrire') ?
222
-				("class='lang_ecrire'") :
223
-				"class='fondl'"))
224
-		. $change
225
-		. ">\n"
226
-		. $options
227
-		. "</select>";
213
+    static $cpt = 0;
214
+    $id = "menu_langues" . $cpt++;
215
+
216
+    return
217
+        "<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " .
218
+        "<select name='$nom_select' id='$id' "
219
+        . ((!test_espace_prive()) ?
220
+            ("class='forml menu_langues'") :
221
+            (($nom_select == 'var_lang_ecrire') ?
222
+                ("class='lang_ecrire'") :
223
+                "class='fondl'"))
224
+        . $change
225
+        . ">\n"
226
+        . $options
227
+        . "</select>";
228 228
 }
229 229
 
230 230
 /**
@@ -246,34 +246,34 @@  discard block
 block discarded – undo
246 246
  */
247 247
 function liste_options_langues($nom_select) {
248 248
 
249
-	switch ($nom_select) {
250
-		# #MENU_LANG
251
-		case 'var_lang':
252
-			# menu de changement de la langue d'un article
253
-			# les langues selectionnees dans la configuration "multilinguisme"
254
-		case 'changer_lang':
255
-			$langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
256
-			break;
257
-		# menu de l'interface (privee, installation et panneau de login)
258
-		# les langues presentes sous forme de fichiers de langue
259
-		# on force la relecture du repertoire des langues pour etre synchrone.
260
-		case 'var_lang_ecrire':
261
-		default:
262
-			$GLOBALS['meta']['langues_proposees'] = '';
263
-			init_langues();
264
-			$langues = explode(',', $GLOBALS['meta']['langues_proposees']);
265
-			break;
249
+    switch ($nom_select) {
250
+        # #MENU_LANG
251
+        case 'var_lang':
252
+            # menu de changement de la langue d'un article
253
+            # les langues selectionnees dans la configuration "multilinguisme"
254
+        case 'changer_lang':
255
+            $langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
256
+            break;
257
+        # menu de l'interface (privee, installation et panneau de login)
258
+        # les langues presentes sous forme de fichiers de langue
259
+        # on force la relecture du repertoire des langues pour etre synchrone.
260
+        case 'var_lang_ecrire':
261
+        default:
262
+            $GLOBALS['meta']['langues_proposees'] = '';
263
+            init_langues();
264
+            $langues = explode(',', $GLOBALS['meta']['langues_proposees']);
265
+            break;
266 266
 
267 267
 # dernier choix possible : toutes les langues = langues_proposees 
268 268
 # + langues_multilingues ; mais, ne sert pas
269 269
 #			$langues = explode(',', $GLOBALS['all_langs']);
270
-	}
271
-	if (count($langues) <= 1) {
272
-		return array();
273
-	}
274
-	sort($langues);
270
+    }
271
+    if (count($langues) <= 1) {
272
+        return array();
273
+    }
274
+    sort($langues);
275 275
 
276
-	return $langues;
276
+    return $langues;
277 277
 }
278 278
 
279 279
 
@@ -288,38 +288,38 @@  discard block
 block discarded – undo
288 288
  **/
289 289
 function verifier_lang_url() {
290 290
 
291
-	// quelle langue est demandee ?
292
-	$lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
293
-	if (isset($_COOKIE['spip_lang_ecrire'])) {
294
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
295
-	}
296
-	if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
297
-		$lang_demandee = $_COOKIE['spip_lang'];
298
-	}
299
-	if (isset($_GET['lang'])) {
300
-		$lang_demandee = $_GET['lang'];
301
-	}
302
-
303
-	// Renvoyer si besoin (et si la langue demandee existe)
304
-	if ($GLOBALS['spip_lang'] != $lang_demandee
305
-		and changer_langue($lang_demandee)
306
-		and $lang_demandee != @$_GET['lang']
307
-	) {
308
-		$destination = parametre_url(self(), 'lang', $lang_demandee, '&');
309
-		// ici on a besoin des var_truc
310
-		foreach ($_GET as $var => $val) {
311
-			if (!strncmp('var_', $var, 4)) {
312
-				$destination = parametre_url($destination, $var, $val, '&');
313
-			}
314
-		}
315
-		include_spip('inc/headers');
316
-		redirige_par_entete($destination);
317
-	}
318
-
319
-	// Subtilite : si la langue demandee par cookie est la bonne
320
-	// alors on fait comme si $lang etait passee dans l'URL
321
-	// (pour criteres {lang}).
322
-	$GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
291
+    // quelle langue est demandee ?
292
+    $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
293
+    if (isset($_COOKIE['spip_lang_ecrire'])) {
294
+        $lang_demandee = $_COOKIE['spip_lang_ecrire'];
295
+    }
296
+    if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
297
+        $lang_demandee = $_COOKIE['spip_lang'];
298
+    }
299
+    if (isset($_GET['lang'])) {
300
+        $lang_demandee = $_GET['lang'];
301
+    }
302
+
303
+    // Renvoyer si besoin (et si la langue demandee existe)
304
+    if ($GLOBALS['spip_lang'] != $lang_demandee
305
+        and changer_langue($lang_demandee)
306
+        and $lang_demandee != @$_GET['lang']
307
+    ) {
308
+        $destination = parametre_url(self(), 'lang', $lang_demandee, '&');
309
+        // ici on a besoin des var_truc
310
+        foreach ($_GET as $var => $val) {
311
+            if (!strncmp('var_', $var, 4)) {
312
+                $destination = parametre_url($destination, $var, $val, '&');
313
+            }
314
+        }
315
+        include_spip('inc/headers');
316
+        redirige_par_entete($destination);
317
+    }
318
+
319
+    // Subtilite : si la langue demandee par cookie est la bonne
320
+    // alors on fait comme si $lang etait passee dans l'URL
321
+    // (pour criteres {lang}).
322
+    $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
323 323
 }
324 324
 
325 325
 
@@ -335,21 +335,21 @@  discard block
 block discarded – undo
335 335
  *     La langue sélectionnée
336 336
  **/
337 337
 function utiliser_langue_site() {
338
-	// s'il existe une langue du site (en gros tout le temps en théorie)
339
-	if (isset($GLOBALS['meta']['langue_site'])
340
-		// et si spip_langue est pas encore définie (ce que va faire changer_langue())
341
-		// ou qu'elle n'est pas identique à la langue du site
342
-		and (!isset($GLOBALS['spip_lang'])
343
-			or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
344
-	) {
345
-		return changer_langue($GLOBALS['meta']['langue_site']);//@:install
346
-	}
347
-	// en theorie là, la globale est définie, sinon c'est un problème.
348
-	if (!isset($GLOBALS['spip_lang'])) {
349
-		spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR);
350
-	}
351
-
352
-	return $GLOBALS['spip_lang'];
338
+    // s'il existe une langue du site (en gros tout le temps en théorie)
339
+    if (isset($GLOBALS['meta']['langue_site'])
340
+        // et si spip_langue est pas encore définie (ce que va faire changer_langue())
341
+        // ou qu'elle n'est pas identique à la langue du site
342
+        and (!isset($GLOBALS['spip_lang'])
343
+            or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
344
+    ) {
345
+        return changer_langue($GLOBALS['meta']['langue_site']);//@:install
346
+    }
347
+    // en theorie là, la globale est définie, sinon c'est un problème.
348
+    if (!isset($GLOBALS['spip_lang'])) {
349
+        spip_log("La globale spip_lang est indéfinie dans utiliser_langue_site() !", _LOG_ERREUR);
350
+    }
351
+
352
+    return $GLOBALS['spip_lang'];
353 353
 }
354 354
 
355 355
 /**
@@ -366,30 +366,30 @@  discard block
 block discarded – undo
366 366
  **/
367 367
 function utiliser_langue_visiteur() {
368 368
 
369
-	$l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
370
-	if (isset($_COOKIE[$l])) {
371
-		if (changer_langue($l = $_COOKIE[$l])) {
372
-			return $l;
373
-		}
374
-	}
375
-
376
-	if (isset($GLOBALS['visiteur_session']['lang'])) {
377
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang'])) {
378
-			return $l;
379
-		}
380
-	}
381
-
382
-	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
383
-		foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
384
-			if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
385
-				if (changer_langue($l = strtolower($r[1]))) {
386
-					return $l;
387
-				}
388
-			}
389
-		}
390
-	}
391
-
392
-	return utiliser_langue_site();
369
+    $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
370
+    if (isset($_COOKIE[$l])) {
371
+        if (changer_langue($l = $_COOKIE[$l])) {
372
+            return $l;
373
+        }
374
+    }
375
+
376
+    if (isset($GLOBALS['visiteur_session']['lang'])) {
377
+        if (changer_langue($l = $GLOBALS['visiteur_session']['lang'])) {
378
+            return $l;
379
+        }
380
+    }
381
+
382
+    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
383
+        foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
384
+            if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
385
+                if (changer_langue($l = strtolower($r[1]))) {
386
+                    return $l;
387
+                }
388
+            }
389
+        }
390
+    }
391
+
392
+    return utiliser_langue_site();
393 393
 }
394 394
 
395 395
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
  * @return int
400 400
  */
401 401
 function match_langue($chaine) {
402
-	return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
402
+    return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
403 403
 }
404 404
 
405 405
 /**
@@ -417,36 +417,36 @@  discard block
 block discarded – undo
417 417
  **/
418 418
 function init_langues() {
419 419
 
420
-	// liste des langues dans les meta, sauf a l'install
421
-	$all_langs = @$GLOBALS['meta']['langues_proposees'];
422
-
423
-	$tout = array();
424
-	if (!$all_langs) {
425
-		// trouver tous les modules lang/spip_xx.php
426
-		$modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$");
427
-		foreach ($modules as $name => $path) {
428
-			if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
429
-				if (match_langue($regs[1])) {
430
-					$tout[] = $regs[1];
431
-				}
432
-			}
433
-		}
434
-		sort($tout);
435
-		$tout = join(',', $tout);
436
-		// Si les langues n'ont pas change, ne rien faire
437
-		if ($tout != $all_langs) {
438
-			$GLOBALS['meta']['langues_proposees'] = $tout;
439
-			include_spip('inc/meta');
440
-			ecrire_meta('langues_proposees', $tout);
441
-		}
442
-	}
443
-	if (!isset($GLOBALS['meta']['langue_site'])) {
444
-		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
445
-		$GLOBALS['meta']['langue_site'] = $tout =
446
-			(!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false))
447
-				? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
448
-		ecrire_meta('langue_site', $tout);
449
-	}
420
+    // liste des langues dans les meta, sauf a l'install
421
+    $all_langs = @$GLOBALS['meta']['langues_proposees'];
422
+
423
+    $tout = array();
424
+    if (!$all_langs) {
425
+        // trouver tous les modules lang/spip_xx.php
426
+        $modules = find_all_in_path("lang/", "/spip_([a-z_]+)\.php$");
427
+        foreach ($modules as $name => $path) {
428
+            if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
429
+                if (match_langue($regs[1])) {
430
+                    $tout[] = $regs[1];
431
+                }
432
+            }
433
+        }
434
+        sort($tout);
435
+        $tout = join(',', $tout);
436
+        // Si les langues n'ont pas change, ne rien faire
437
+        if ($tout != $all_langs) {
438
+            $GLOBALS['meta']['langues_proposees'] = $tout;
439
+            include_spip('inc/meta');
440
+            ecrire_meta('langues_proposees', $tout);
441
+        }
442
+    }
443
+    if (!isset($GLOBALS['meta']['langue_site'])) {
444
+        // Initialisation : le francais si dispo, sinon la premiere langue trouvee
445
+        $GLOBALS['meta']['langue_site'] = $tout =
446
+            (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false))
447
+                ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
448
+        ecrire_meta('langue_site', $tout);
449
+    }
450 450
 }
451 451
 
452 452
 /**
@@ -460,10 +460,10 @@  discard block
 block discarded – undo
460 460
  *     Code html de la balise <html>
461 461
  **/
462 462
 function html_lang_attributes() {
463
-	$lang = $GLOBALS['spip_lang'];
464
-	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
463
+    $lang = $GLOBALS['spip_lang'];
464
+    $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
465 465
 
466
-	return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
466
+    return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
467 467
 }
468 468
 
469 469
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
  * @return string
478 478
  */
479 479
 function aide_lang_dir($spip_lang, $spip_lang_rtl) {
480
-	return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
480
+    return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
481 481
 }
482 482
 
483 483
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -12 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
  **/
38 38
 function changer_langue($lang) {
39 39
 
40
-	$liste_langues = ',' . @$GLOBALS['meta']['langues_proposees']
41
-		. ',' . @$GLOBALS['meta']['langues_multilingue'] . ',';
40
+	$liste_langues = ','.@$GLOBALS['meta']['langues_proposees']
41
+		. ','.@$GLOBALS['meta']['langues_multilingue'].',';
42 42
 
43 43
 	// Si la langue demandee n'existe pas, on essaie d'autres variantes
44 44
 	// Exemple : 'pt-br' => 'pt_br' => 'pt'
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	}
190 190
 	foreach ($langues as $l) {
191 191
 		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
192
-		$ret .= "<option value='$l'$selected>[" . $l . "] " . traduire_nom_langue($l) . "</option>\n";
192
+		$ret .= "<option value='$l'$selected>[".$l."] ".traduire_nom_langue($l)."</option>\n";
193 193
 	}
194 194
 
195 195
 	if (!test_espace_prive()) {
@@ -204,23 +204,21 @@  discard block
 block discarded – undo
204 204
 
205 205
 	return generer_action_auteur('converser', $base, $cible,
206 206
 		(select_langues($nom_select, $change, $ret)
207
-			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
207
+			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"),
208 208
 		" method='post'");
209 209
 }
210 210
 
211 211
 // http://code.spip.net/@select_langues
212 212
 function select_langues($nom_select, $change, $options, $label = "") {
213 213
 	static $cpt = 0;
214
-	$id = "menu_langues" . $cpt++;
214
+	$id = "menu_langues".$cpt++;
215 215
 
216 216
 	return
217
-		"<label for='$id'>" . ($label ? $label : _T('info_langues')) . "</label> " .
217
+		"<label for='$id'>".($label ? $label : _T('info_langues'))."</label> ".
218 218
 		"<select name='$nom_select' id='$id' "
219 219
 		. ((!test_espace_prive()) ?
220
-			("class='forml menu_langues'") :
221
-			(($nom_select == 'var_lang_ecrire') ?
222
-				("class='lang_ecrire'") :
223
-				"class='fondl'"))
220
+			("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ?
221
+				("class='lang_ecrire'") : "class='fondl'"))
224 222
 		. $change
225 223
 		. ">\n"
226 224
 		. $options
@@ -342,7 +340,7 @@  discard block
 block discarded – undo
342 340
 		and (!isset($GLOBALS['spip_lang'])
343 341
 			or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
344 342
 	) {
345
-		return changer_langue($GLOBALS['meta']['langue_site']);//@:install
343
+		return changer_langue($GLOBALS['meta']['langue_site']); //@:install
346 344
 	}
347 345
 	// en theorie là, la globale est définie, sinon c'est un problème.
348 346
 	if (!isset($GLOBALS['spip_lang'])) {
@@ -443,7 +441,7 @@  discard block
 block discarded – undo
443 441
 	if (!isset($GLOBALS['meta']['langue_site'])) {
444 442
 		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
445 443
 		$GLOBALS['meta']['langue_site'] = $tout =
446
-			(!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', ",$all_langs,") !== false))
444
+			(!$all_langs or (strpos(','._LANGUE_PAR_DEFAUT.',', ",$all_langs,") !== false))
447 445
 				? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
448 446
 		ecrire_meta('langue_site', $tout);
449 447
 	}
Please login to merge, or discard this patch.