Completed
Push — master ( ee2ef7...7a30fe )
by cam
04:09
created
ecrire/inc/cvt_autosave.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 /**
24 24
  * Nettoyer les échappements
25 25
  *
26
- * @param $val
26
+ * @param string $val
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 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
 /**
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
30
-	return stripslashes(urldecode($val));
30
+    return stripslashes(urldecode($val));
31 31
 }
32 32
 
33 33
 /**
@@ -38,42 +38,42 @@  discard block
 block discarded – undo
38 38
  * @return array
39 39
  */
40 40
 function cvtautosave_formulaire_charger($flux) {
41
-	if (is_array($flux['data'])
42
-		and isset($flux['data']['_autosave_id'])
43
-		and $cle_autosave = $flux['data']['_autosave_id']
44
-	) {
41
+    if (is_array($flux['data'])
42
+        and isset($flux['data']['_autosave_id'])
43
+        and $cle_autosave = $flux['data']['_autosave_id']
44
+    ) {
45 45
 
46
-		$form = $flux['args']['form'];
47
-		$je_suis_poste = $flux['args']['je_suis_poste'];
46
+        $form = $flux['args']['form'];
47
+        $je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49
-		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
49
+        $cle_autosave = serialize($cle_autosave);
50
+        $cle_autosave = $form . "_" . md5($cle_autosave);
51 51
 
52
-		// si on a un backup en session et qu'on est au premier chargement, non poste
53
-		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
-			and !$je_suis_poste
56
-		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
-			foreach ($vars as $key => $val) {
59
-				if (isset($flux['data'][$key])) {
60
-					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
-						$val));
62
-				}
63
-			}
64
-		}
52
+        // si on a un backup en session et qu'on est au premier chargement, non poste
53
+        // on restitue les donnees
54
+        if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
+            and !$je_suis_poste
56
+        ) {
57
+            parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
+            foreach ($vars as $key => $val) {
59
+                if (isset($flux['data'][$key])) {
60
+                    $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
+                        $val));
62
+                }
63
+            }
64
+        }
65 65
 
66
-		/**
67
-		 * Envoyer le input hidden et le bout de js qui l'utilisera
68
-		 */
69
-		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
-			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
66
+        /**
67
+         * Envoyer le input hidden et le bout de js qui l'utilisera
68
+         */
69
+        $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
+            . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71 71
 		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74
-	}
74
+    }
75 75
 
76
-	return $flux;
76
+    return $flux;
77 77
 }
78 78
 
79 79
 /**
@@ -87,33 +87,33 @@  discard block
 block discarded – undo
87 87
  * @return array
88 88
  */
89 89
 function cvtautosave_formulaire_traiter($flux) {
90
-	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
-	// on elimine les donnees de la session
92
-	if ($cle_autosave = _request('autosave')) {
93
-		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
95
-	}
90
+    // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
+    // on elimine les donnees de la session
92
+    if ($cle_autosave = _request('autosave')) {
93
+        include_spip('inc/session');
94
+        session_set('session_autosave_' . $cle_autosave, null);
95
+    }
96 96
 
97
-	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
-		// delai par defaut avant purge d'un backup de form : 72H
99
-		if (!defined('_AUTOSAVE_GB_DELAY')) {
100
-			define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
-		}
102
-		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
-		// purger aussi toutes les vieilles autosave
104
-		$session = $GLOBALS['visiteur_session'];
105
-		foreach ($session as $k => $v) {
106
-			if (strncmp($k, 'session_autosave_', 17) == 0) {
107
-				$timestamp = 0;
108
-				if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
-					$timestamp = intval($m[1]);
110
-				}
111
-				if ($timestamp < $time_too_old) {
112
-					session_set($k, null);
113
-				}
114
-			}
115
-		}
116
-	}
97
+    if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
+        // delai par defaut avant purge d'un backup de form : 72H
99
+        if (!defined('_AUTOSAVE_GB_DELAY')) {
100
+            define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
+        }
102
+        $time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
+        // purger aussi toutes les vieilles autosave
104
+        $session = $GLOBALS['visiteur_session'];
105
+        foreach ($session as $k => $v) {
106
+            if (strncmp($k, 'session_autosave_', 17) == 0) {
107
+                $timestamp = 0;
108
+                if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
+                    $timestamp = intval($m[1]);
110
+                }
111
+                if ($timestamp < $time_too_old) {
112
+                    session_set($k, null);
113
+                }
114
+            }
115
+        }
116
+    }
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 		$je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49 49
 		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
50
+		$cle_autosave = $form."_".md5($cle_autosave);
51 51
 
52 52
 		// si on a un backup en session et qu'on est au premier chargement, non poste
53 53
 		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
54
+		if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
55 55
 			and !$je_suis_poste
56 56
 		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
57
+			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
58 58
 			foreach ($vars as $key => $val) {
59 59
 				if (isset($flux['data'][$key])) {
60 60
 					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 */
69 69
 		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70 70
 			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71
-		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
71
+		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74 74
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	// on elimine les donnees de la session
92 92
 	if ($cle_autosave = _request('autosave')) {
93 93
 		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
94
+		session_set('session_autosave_'.$cle_autosave, null);
95 95
 	}
96 96
 
97 97
 	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
Please login to merge, or discard this patch.
ecrire/inc/distant.php 4 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
  *   permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG)
65 65
  * @param int $taille_max
66 66
  *   taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE
67
- * @return bool|string
67
+ * @return string|false
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible
247 247
  *
248 248
  * @param string $url_idn
249
- * @return array|string
249
+ * @return string|boolean
250 250
  */
251 251
 function url_to_ascii($url_idn) {
252 252
 
@@ -642,13 +642,13 @@  discard block
 block discarded – undo
642 642
  *
643 643
  * @param string $url
644 644
  *     URL de la page à récupérer
645
- * @param bool|null|string $trans
645
+ * @param boolean $trans
646 646
  *     - chaîne longue : c'est un nom de fichier (nom pour sa copie locale)
647 647
  *     - true : demande d'encodage/charset
648 648
  *     - null : ne retourner que les headers
649 649
  * @param string $get
650 650
  *     Type de requête HTTP à faire (HEAD, GET ou POST)
651
- * @param int|bool $taille_max
651
+ * @param integer $taille_max
652 652
  *     Arrêter le contenu au-delà (0 = seulement les entetes ==> requête HEAD).
653 653
  *     Par defaut taille_max = 1Mo.
654 654
  * @param string|array $datas
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  *
775 775
  * @param resource $handle
776 776
  * @param int|bool $if_modified_since
777
- * @return bool|array
777
+ * @return string
778 778
  *   int status
779 779
  *   string headers
780 780
  *   int last_modified
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
  *   donnees postees
1252 1252
  * @param string $vers
1253 1253
  *   version HTTP
1254
- * @param int|string $date
1254
+ * @param string $date
1255 1255
  *   timestamp pour entente If-Modified-Since
1256
- * @return bool|resource
1256
+ * @return string
1257 1257
  *   false|int si echec
1258 1258
  *   resource socket vers l'url demandee
1259 1259
  */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1256,8 +1256,9 @@
 block discarded – undo
1256 1256
 	$http_noproxy = " $http_noproxy ";
1257 1257
 	$domain = $host;
1258 1258
 	// si le domaine exact www.example.org est dans les exceptions
1259
-	if (strpos($http_noproxy, " $domain ") !== false)
1260
-		return '';
1259
+	if (strpos($http_noproxy, " $domain ") !== false) {
1260
+			return '';
1261
+	}
1261 1262
 
1262 1263
 	while (strpos($domain, '.') !== false) {
1263 1264
 		$domain = explode('.', $domain);
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32 32
 	define('_INC_DISTANT_MAX_SIZE', 2097152);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38
-define('_REGEXP_COPIE_LOCALE', ',' 	.
38
+define('_REGEXP_COPIE_LOCALE', ','.
39 39
 	preg_replace(
40 40
 		'@^https?:@',
41 41
 		'https?:',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// si c'est la protection de soi-meme, retourner le path
72 72
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
73
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
74 74
 
75 75
 		return @file_exists($source) ? $source : false;
76 76
 	}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		return false;
91 91
 	}
92 92
 
93
-	$localrac = _DIR_RACINE . $local;
93
+	$localrac = _DIR_RACINE.$local;
94 94
 	$t = ($mode == 'force') ? false : @file_exists($localrac);
95 95
 
96 96
 	// test d'existence du fichier
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116 116
 		);
117 117
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE);
119 119
 		}
120 120
 		if (!$res['length']) {
121 121
 			// si $t c'est sans doute juste un not-modified-since
122 122
 			return $t ? $local : false;
123 123
 		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
124
+		spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant');
125 125
 
126 126
 		// pour une eventuelle indexation
127 127
 		pipeline(
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
156
+	if (!function_exists('protocole_verifier')) {
157 157
 		include_spip('inc/filtres_mini');
158 158
 	}
159 159
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 	
164 164
 	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
165
+	if (!$parsed_url or empty($parsed_url['host'])) {
166 166
 		return false;
167 167
 	}
168 168
 
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 			}
204 204
 		}
205 205
 		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
206
+			$parts = array_map('intval', explode('.', $ip));
207 207
 			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
208
+			  or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1])
209
+			  or (192 === $parts[0] && 168 === $parts[1])
210 210
 			) {
211 211
 				return false;
212 212
 			}
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
221
+	if ($port === 80 or $port === 443 or $port === 8080) {
222 222
 		return $url;
223 223
 	}
224 224
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				}
286 286
 			}
287 287
 			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
288
+				$boundary = substr(md5(rand().'spip'), 0, 8);
289 289
 			}
290 290
 		}
291 291
 
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 			}
314 314
 		} else {
315 315
 			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
316
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
317 317
 			$chaine = array();
318 318
 			if (is_array($donnees)) {
319 319
 				foreach ($donnees as $cle => $valeur) {
320 320
 					if (is_array($valeur)) {
321 321
 						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
322
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
323 323
 						}
324 324
 					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
325
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
326 326
 					}
327 327
 				}
328 328
 				$chaine = implode('&', $chaine);
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	if (!empty($options['datas'])) {
424 424
 		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425 425
 		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
426
+			$head .= 'Content-Length: '.strlen($postdata);
427 427
 		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
428
+		$options['datas'] = $head."\r\n\r\n".$postdata;
429 429
 		if (strlen($postdata)) {
430 430
 			$options['methode'] = 'POST';
431 431
 		}
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435 435
 	$url = preg_replace(',^feed://,i', 'http://', $url);
436 436
 	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
437
+		$url = 'http://'.$url;
438 438
 	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
439
+		$url = 'http:'.$url;
440 440
 	}
441 441
 
442 442
 	$url = url_to_ascii($url);
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		$options['if_modified_since']
466 466
 	);
467 467
 	if (!$handle) {
468
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
468
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
469 469
 
470 470
 		return false;
471 471
 	}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 					'status' => 200,
495 495
 				);
496 496
 			} else {
497
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
497
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
498 498
 				return false;
499 499
 			}
500 500
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 
507 507
 			return recuperer_url($url, $options);
508 508
 		} elseif ($res['status'] !== 200) {
509
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
509
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
510 510
 		}
511 511
 		$result['status'] = $res['status'];
512 512
 		if (isset($res['headers'])) {
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 	$gz = false;
533 533
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
534
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
535 535
 	}
536 536
 
537 537
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 	$sig['url'] = $url;
618 618
 
619 619
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
620
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
621 621
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
622 622
 	$cache = "$sub$cache";
623 623
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		return false;
727 727
 	}
728 728
 	if ($get_headers) {
729
-		return $res['headers'] . "\n" . $res['page'];
729
+		return $res['headers']."\n".$res['page'];
730 730
 	}
731 731
 
732 732
 	return $res['page'];
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 	$fp = false;
831 831
 	if ($fichier) {
832 832
 		include_spip('inc/acces');
833
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
834 834
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
835 835
 		if (!$fp and file_exists($fichier)) {
836 836
 			return filesize($fichier);
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 	}
890 890
 	$result['status'] = intval($r[1]);
891 891
 	while ($s = trim(fgets($handle, 16384))) {
892
-		$result['headers'][] = $s . "\n";
892
+		$result['headers'][] = $s."\n";
893 893
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
894 894
 		list(, $d, $v) = $r;
895 895
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -972,13 +972,13 @@  discard block
 block discarded – undo
972 972
 
973 973
 	// on se place tout le temps comme si on etait a la racine
974 974
 	if (_DIR_RACINE) {
975
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
976 976
 	}
977 977
 
978 978
 	$m = md5($source);
979 979
 
980 980
 	return $d
981
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
982 982
 	. substr($m, 0, 4)
983 983
 	. ".$extension";
984 984
 }
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 	// Si c'est deja local pas de souci
1002 1002
 	if (!tester_url_absolue($source)) {
1003 1003
 		if (_DIR_RACINE) {
1004
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
1005 1005
 		}
1006 1006
 
1007 1007
 		return $source;
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 	if ($ext
1019 1019
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1020 1020
 		and $f = nom_fichier_copie_locale($source, $ext)
1021
-		and file_exists(_DIR_RACINE . $f)
1021
+		and file_exists(_DIR_RACINE.$f)
1022 1022
 	) {
1023 1023
 		return $f;
1024 1024
 	}
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 
1027 1027
 	// Si c'est deja dans la table des documents,
1028 1028
 	// ramener le nom de sa copie potentielle
1029
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
1030 1030
 
1031 1031
 	if ($ext) {
1032 1032
 		return nom_fichier_copie_locale($source, $ext);
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
 
1038 1038
 	$ext = $path_parts ? $path_parts['extension'] : '';
1039 1039
 
1040
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1041 1041
 		$f = nom_fichier_copie_locale($source, $ext);
1042
-		if (file_exists(_DIR_RACINE . $f)) {
1042
+		if (file_exists(_DIR_RACINE.$f)) {
1043 1043
 			return $f;
1044 1044
 		}
1045 1045
 	}
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 	// Ping  pour voir si son extension est connue et autorisee
1048 1048
 	// avec mise en cache du resultat du ping
1049 1049
 
1050
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
1051 1051
 	if (!@file_exists($cache)
1052 1052
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1053 1053
 		or _request('var_mode') == 'recalcul'
@@ -1056,10 +1056,10 @@  discard block
 block discarded – undo
1056 1056
 		ecrire_fichier($cache, serialize($path_parts));
1057 1057
 	}
1058 1058
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1059
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1060 1060
 		return nom_fichier_copie_locale($source, $ext);
1061 1061
 	}
1062
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1062
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
1063 1063
 }
1064 1064
 
1065 1065
 
@@ -1124,19 +1124,19 @@  discard block
 block discarded – undo
1124 1124
 			if (!$t
1125 1125
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1126 1126
 			) {
1127
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1128 1128
 			}
1129 1129
 			if (!$t
1130 1130
 				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1131 1131
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1132 1132
 			) {
1133
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1134 1134
 			}
1135 1135
 		}
1136 1136
 
1137 1137
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1138 1138
 		if (!$t) {
1139
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
+			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1140 1140
 		}
1141 1141
 
1142 1142
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1146,11 +1146,11 @@  discard block
 block discarded – undo
1146 1146
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1147 1147
 		) {
1148 1148
 			# eviter xxx.3 => 3gp (> SPIP 3)
1149
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1150 1150
 		}
1151 1151
 
1152 1152
 		if ($t) {
1153
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1153
+			spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1154 1154
 			$a['extension'] = $t['extension'];
1155 1155
 		} else {
1156 1156
 			# par defaut on retombe sur '.bin' si c'est autorise
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
 		} else {
1193 1193
 			if ($a['body']) {
1194 1194
 				$a['extension'] = $extension;
1195
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1195
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1196 1196
 				ecrire_fichier($a['fichier'], $a['body']);
1197 1197
 				$size_image = @spip_getimagesize($a['fichier']);
1198 1198
 				$a['largeur'] = intval($size_image[0]);
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
 		}
1318 1318
 	} else {
1319 1319
 		$scheme = $t['scheme'];
1320
-		$noproxy = $scheme . '://';
1320
+		$noproxy = $scheme.'://';
1321 1321
 	}
1322 1322
 	if (isset($t['user'])) {
1323 1323
 		$user = array($t['user'], $t['pass']);
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 	}
1332 1332
 
1333 1333
 	if (!empty($t['query'])) {
1334
-		$path .= '?' . $t['query'];
1334
+		$path .= '?'.$t['query'];
1335 1335
 	}
1336 1336
 
1337 1337
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1404,20 +1404,20 @@  discard block
 block discarded – undo
1404 1404
 	$proxy_user = '';
1405 1405
 	$http_proxy = need_proxy($host);
1406 1406
 	if ($user) {
1407
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1407
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1408 1408
 	}
1409 1409
 
1410 1410
 	$connect = '';
1411 1411
 	if ($http_proxy) {
1412
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1413
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1414
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1412
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) {
1413
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1414
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1415 1415
 				. "Host: $path_host\r\n"
1416 1416
 				. "Proxy-Connection: Keep-Alive\r\n";
1417 1417
 		} else {
1418
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1418
+			$path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://")
1419 1419
 				. (!$user ? '' : "$user@")
1420
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1420
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1421 1421
 		}
1422 1422
 		$t2 = @parse_url($http_proxy);
1423 1423
 		$first_host = $t2['host'];
@@ -1425,10 +1425,10 @@  discard block
 block discarded – undo
1425 1425
 			$port = 80;
1426 1426
 		}
1427 1427
 		if ($t2['user']) {
1428
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1428
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1429 1429
 		}
1430 1430
 	} else {
1431
-		$first_host = $noproxy . $host;
1431
+		$first_host = $noproxy.$host;
1432 1432
 	}
1433 1433
 
1434 1434
 	if ($connect) {
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 		);
1454 1454
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1455 1455
 		if (!$f) {
1456
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1456
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1457 1457
 			return $errno;
1458 1458
 		}
1459 1459
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 			or !count($res = explode(' ', $res))
1466 1466
 			or $res[1] !== '200'
1467 1467
 		) {
1468
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1468
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1469 1469
 			fclose($f);
1470 1470
 
1471 1471
 			return false;
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1483 1483
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1484 1484
 		if (!$f) {
1485
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1485
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1486 1486
 
1487 1487
 			return $errno;
1488 1488
 		}
@@ -1492,16 +1492,16 @@  discard block
 block discarded – undo
1492 1492
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1493 1493
 
1494 1494
 	$host_port = $host;
1495
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1495
+	if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) {
1496 1496
 		$host_port .= ":$port";
1497 1497
 	}
1498 1498
 	$req = "$method $path $vers\r\n"
1499 1499
 		. "Host: $host_port\r\n"
1500
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1501
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1500
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1501
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1502 1502
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1503
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1504
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1503
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1504
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1505 1505
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1506 1506
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1507 1507
 
Please login to merge, or discard this patch.
Indentation   +1077 added lines, -1077 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2097152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2097152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		(isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,77 +68,77 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode == 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode == 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local == $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode == 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
-		}
120
-		if (!$res['length']) {
121
-			// si $t c'est sans doute juste un not-modified-since
122
-			return $t ? $local : false;
123
-		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
-
126
-		// pour une eventuelle indexation
127
-		pipeline(
128
-			'post_edition',
129
-			array(
130
-				'args' => array(
131
-					'operation' => 'copie_locale',
132
-					'source' => $source,
133
-					'fichier' => $local,
134
-					'http_res' => $res['length'],
135
-				),
136
-				'data' => null
137
-			)
138
-		);
139
-	}
140
-
141
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode == 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode == 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local == $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode == 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
+        }
120
+        if (!$res['length']) {
121
+            // si $t c'est sans doute juste un not-modified-since
122
+            return $t ? $local : false;
123
+        }
124
+        spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
+
126
+        // pour une eventuelle indexation
127
+        pipeline(
128
+            'post_edition',
129
+            array(
130
+                'args' => array(
131
+                    'operation' => 'copie_locale',
132
+                    'source' => $source,
133
+                    'fichier' => $local,
134
+                    'http_res' => $res['length'],
135
+                ),
136
+                'data' => null
137
+            )
138
+        );
139
+    }
140
+
141
+    return $local;
142 142
 }
143 143
 
144 144
 /**
@@ -153,88 +153,88 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
157
-		include_spip('inc/filtres_mini');
158
-	}
156
+    if (!function_exists('protocole_verifier')){
157
+        include_spip('inc/filtres_mini');
158
+    }
159 159
 
160
-	if (!protocole_verifier($url, array('http', 'https'))) {
161
-		return false;
162
-	}
160
+    if (!protocole_verifier($url, array('http', 'https'))) {
161
+        return false;
162
+    }
163 163
 	
164
-	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
166
-		return false;
167
-	}
168
-
169
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
-		return false;
171
-	}
172
-
173
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
-		return false;
175
-	}
176
-
177
-	if (!is_array($known_hosts)) {
178
-		$known_hosts = array($known_hosts);
179
-	}
180
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
-	$known_hosts[] = url_de_base();
182
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
-
184
-	$is_known_host = false;
185
-	foreach ($known_hosts as $known_host) {
186
-		$parse_known = parse_url($known_host);
187
-		if ($parse_known
188
-		  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
-			$is_known_host = true;
190
-			break;
191
-		}
192
-	}
193
-
194
-	if (!$is_known_host) {
195
-		$host = trim($parsed_url['host'], '.');
196
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
-			$ip = $host;
198
-		} else {
199
-			$ip = gethostbyname($host);
200
-			if ($ip === $host) {
201
-				// Error condition for gethostbyname()
202
-				$ip = false;
203
-			}
204
-		}
205
-		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
207
-			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
210
-			) {
211
-				return false;
212
-			}
213
-		}
214
-	}
215
-
216
-	if (empty($parsed_url['port'])) {
217
-		return $url;
218
-	}
219
-
220
-	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
222
-		return $url;
223
-	}
224
-
225
-	if ($is_known_host) {
226
-		foreach ($known_hosts as $known_host) {
227
-			$parse_known = parse_url($known_host);
228
-			if ($parse_known
229
-				and !empty($parse_known['port'])
230
-			  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
-			  and $parse_known['port'] == $port) {
232
-				return $url;
233
-			}
234
-		}
235
-	}
236
-
237
-	return false;
164
+    $parsed_url = parse_url($url);
165
+    if (!$parsed_url or empty($parsed_url['host']) ) {
166
+        return false;
167
+    }
168
+
169
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
+        return false;
171
+    }
172
+
173
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
+        return false;
175
+    }
176
+
177
+    if (!is_array($known_hosts)) {
178
+        $known_hosts = array($known_hosts);
179
+    }
180
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
+    $known_hosts[] = url_de_base();
182
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
+
184
+    $is_known_host = false;
185
+    foreach ($known_hosts as $known_host) {
186
+        $parse_known = parse_url($known_host);
187
+        if ($parse_known
188
+          and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
+            $is_known_host = true;
190
+            break;
191
+        }
192
+    }
193
+
194
+    if (!$is_known_host) {
195
+        $host = trim($parsed_url['host'], '.');
196
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
+            $ip = $host;
198
+        } else {
199
+            $ip = gethostbyname($host);
200
+            if ($ip === $host) {
201
+                // Error condition for gethostbyname()
202
+                $ip = false;
203
+            }
204
+        }
205
+        if ($ip) {
206
+            $parts = array_map('intval', explode( '.', $ip ));
207
+            if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
+              or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
+              or ( 192 === $parts[0] && 168 === $parts[1] )
210
+            ) {
211
+                return false;
212
+            }
213
+        }
214
+    }
215
+
216
+    if (empty($parsed_url['port'])) {
217
+        return $url;
218
+    }
219
+
220
+    $port = $parsed_url['port'];
221
+    if ($port === 80  or $port === 443  or $port === 8080) {
222
+        return $url;
223
+    }
224
+
225
+    if ($is_known_host) {
226
+        foreach ($known_hosts as $known_host) {
227
+            $parse_known = parse_url($known_host);
228
+            if ($parse_known
229
+                and !empty($parse_known['port'])
230
+              and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
+              and $parse_known['port'] == $port) {
232
+                return $url;
233
+            }
234
+        }
235
+    }
236
+
237
+    return false;
238 238
 }
239 239
 
240 240
 /**
@@ -253,86 +253,86 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function prepare_donnees_post($donnees, $boundary = '') {
255 255
 
256
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
-	// pour un appel soap par exemple
258
-	// l'entete est separe des donnees par un double retour a la ligne
259
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
-	if (is_string($donnees) && strlen($donnees)) {
261
-		$entete = '';
262
-		// on repasse tous les \r\n et \r en simples \n
263
-		$donnees = str_replace("\r\n", "\n", $donnees);
264
-		$donnees = str_replace("\r", "\n", $donnees);
265
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
-		$p = strpos($donnees, "\n\n");
267
-		if ($p !== false) {
268
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
-			$donnees = substr($donnees, $p + 2);
270
-		}
271
-		$chaine = str_replace("\n", "\r\n", $donnees);
272
-	} else {
273
-		/* boundary automatique */
274
-		// Si on a plus de 500 octects de donnees, on "boundarise"
275
-		if ($boundary === '') {
276
-			$taille = 0;
277
-			foreach ($donnees as $cle => $valeur) {
278
-				if (is_array($valeur)) {
279
-					foreach ($valeur as $val2) {
280
-						$taille += strlen($val2);
281
-					}
282
-				} else {
283
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
284
-					$taille += strlen($valeur);
285
-				}
286
-			}
287
-			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
289
-			}
290
-		}
291
-
292
-		if (is_string($boundary) and strlen($boundary)) {
293
-			// fabrique une chaine HTTP pour un POST avec boundary
294
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
-			$chaine = '';
296
-			if (is_array($donnees)) {
297
-				foreach ($donnees as $cle => $valeur) {
298
-					if (is_array($valeur)) {
299
-						foreach ($valeur as $val2) {
300
-							$chaine .= "\r\n--$boundary\r\n";
301
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
-							$chaine .= "\r\n";
303
-							$chaine .= $val2;
304
-						}
305
-					} else {
306
-						$chaine .= "\r\n--$boundary\r\n";
307
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
-						$chaine .= "\r\n";
309
-						$chaine .= $valeur;
310
-					}
311
-				}
312
-				$chaine .= "\r\n--$boundary\r\n";
313
-			}
314
-		} else {
315
-			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
-			$chaine = array();
318
-			if (is_array($donnees)) {
319
-				foreach ($donnees as $cle => $valeur) {
320
-					if (is_array($valeur)) {
321
-						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
-						}
324
-					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
-					}
327
-				}
328
-				$chaine = implode('&', $chaine);
329
-			} else {
330
-				$chaine = $donnees;
331
-			}
332
-		}
333
-	}
334
-
335
-	return array($entete, $chaine);
256
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
+    // pour un appel soap par exemple
258
+    // l'entete est separe des donnees par un double retour a la ligne
259
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
+    if (is_string($donnees) && strlen($donnees)) {
261
+        $entete = '';
262
+        // on repasse tous les \r\n et \r en simples \n
263
+        $donnees = str_replace("\r\n", "\n", $donnees);
264
+        $donnees = str_replace("\r", "\n", $donnees);
265
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
+        $p = strpos($donnees, "\n\n");
267
+        if ($p !== false) {
268
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
+            $donnees = substr($donnees, $p + 2);
270
+        }
271
+        $chaine = str_replace("\n", "\r\n", $donnees);
272
+    } else {
273
+        /* boundary automatique */
274
+        // Si on a plus de 500 octects de donnees, on "boundarise"
275
+        if ($boundary === '') {
276
+            $taille = 0;
277
+            foreach ($donnees as $cle => $valeur) {
278
+                if (is_array($valeur)) {
279
+                    foreach ($valeur as $val2) {
280
+                        $taille += strlen($val2);
281
+                    }
282
+                } else {
283
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
284
+                    $taille += strlen($valeur);
285
+                }
286
+            }
287
+            if ($taille > 500) {
288
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
289
+            }
290
+        }
291
+
292
+        if (is_string($boundary) and strlen($boundary)) {
293
+            // fabrique une chaine HTTP pour un POST avec boundary
294
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
+            $chaine = '';
296
+            if (is_array($donnees)) {
297
+                foreach ($donnees as $cle => $valeur) {
298
+                    if (is_array($valeur)) {
299
+                        foreach ($valeur as $val2) {
300
+                            $chaine .= "\r\n--$boundary\r\n";
301
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
+                            $chaine .= "\r\n";
303
+                            $chaine .= $val2;
304
+                        }
305
+                    } else {
306
+                        $chaine .= "\r\n--$boundary\r\n";
307
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
+                        $chaine .= "\r\n";
309
+                        $chaine .= $valeur;
310
+                    }
311
+                }
312
+                $chaine .= "\r\n--$boundary\r\n";
313
+            }
314
+        } else {
315
+            // fabrique une chaine HTTP simple pour un POST
316
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
+            $chaine = array();
318
+            if (is_array($donnees)) {
319
+                foreach ($donnees as $cle => $valeur) {
320
+                    if (is_array($valeur)) {
321
+                        foreach ($valeur as $val2) {
322
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
+                        }
324
+                    } else {
325
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
+                    }
327
+                }
328
+                $chaine = implode('&', $chaine);
329
+            } else {
330
+                $chaine = $donnees;
331
+            }
332
+        }
333
+    }
334
+
335
+    return array($entete, $chaine);
336 336
 }
337 337
 
338 338
 /**
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
  */
347 347
 function url_to_ascii($url_idn) {
348 348
 
349
-	if ($parts = parse_url($url_idn)) {
350
-		$host = $parts['host'];
351
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
-			include_spip('inc/idna_convert.class');
353
-			$IDN = new idna_convert();
354
-			$host_ascii = $IDN->encode($host);
355
-			$url_idn = explode($host, $url_idn, 2);
356
-			$url_idn = implode($host_ascii, $url_idn);
357
-		}
358
-		// et on urlencode les char utf si besoin dans le path
359
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
360
-	}
361
-
362
-	return $url_idn;
349
+    if ($parts = parse_url($url_idn)) {
350
+        $host = $parts['host'];
351
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
+            include_spip('inc/idna_convert.class');
353
+            $IDN = new idna_convert();
354
+            $host_ascii = $IDN->encode($host);
355
+            $url_idn = explode($host, $url_idn, 2);
356
+            $url_idn = implode($host_ascii, $url_idn);
357
+        }
358
+        // et on urlencode les char utf si besoin dans le path
359
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
360
+    }
361
+
362
+    return $url_idn;
363 363
 }
364 364
 
365 365
 /**
@@ -398,176 +398,176 @@  discard block
 block discarded – undo
398 398
  *     string file : nom du fichier si enregistre dans un fichier
399 399
  */
400 400
 function recuperer_url($url, $options = array()) {
401
-	$default = array(
402
-		'transcoder' => false,
403
-		'methode' => 'GET',
404
-		'taille_max' => null,
405
-		'datas' => '',
406
-		'boundary' => '',
407
-		'refuser_gz' => false,
408
-		'if_modified_since' => '',
409
-		'uri_referer' => '',
410
-		'file' => '',
411
-		'follow_location' => 10,
412
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
413
-	);
414
-	$options = array_merge($default, $options);
415
-	// copier directement dans un fichier ?
416
-	$copy = $options['file'];
417
-
418
-	if ($options['methode'] == 'HEAD') {
419
-		$options['taille_max'] = 0;
420
-	}
421
-	if (is_null($options['taille_max'])) {
422
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
423
-	}
424
-
425
-	if (!empty($options['datas'])) {
426
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
427
-		if (stripos($head, 'Content-Length:') === false) {
428
-			$head .= 'Content-Length: ' . strlen($postdata);
429
-		}
430
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
431
-		if (strlen($postdata)) {
432
-			$options['methode'] = 'POST';
433
-		}
434
-	}
435
-
436
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
437
-	$url = preg_replace(',^feed://,i', 'http://', $url);
438
-	if (!tester_url_absolue($url)) {
439
-		$url = 'http://' . $url;
440
-	} elseif (strncmp($url, '//', 2) == 0) {
441
-		$url = 'http:' . $url;
442
-	}
443
-
444
-	$url = url_to_ascii($url);
445
-
446
-	$result = array(
447
-		'status' => 0,
448
-		'headers' => '',
449
-		'page' => '',
450
-		'length' => 0,
451
-		'last_modified' => '',
452
-		'location' => '',
453
-		'url' => $url
454
-	);
455
-
456
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
457
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
458
-
459
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
460
-	list($handle, $fopen) = init_http(
461
-		$options['methode'],
462
-		$url,
463
-		$refuser_gz,
464
-		$options['uri_referer'],
465
-		$options['datas'],
466
-		$options['version_http'],
467
-		$options['if_modified_since']
468
-	);
469
-	if (!$handle) {
470
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
471
-
472
-		return false;
473
-	}
474
-
475
-	// Sauf en fopen, envoyer le flux d'entree
476
-	// et recuperer les en-tetes de reponses
477
-	if (!$fopen) {
478
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
479
-		if (!$res) {
480
-			fclose($handle);
481
-			$t = @parse_url($url);
482
-			$host = $t['host'];
483
-			// Chinoisierie inexplicable pour contrer
484
-			// les actions liberticides de l'empire du milieu
485
-			if (!need_proxy($host)
486
-				and $res = @file_get_contents($url)
487
-			) {
488
-				$result['length'] = strlen($res);
489
-				if ($copy) {
490
-					ecrire_fichier($copy, $res);
491
-					$result['file'] = $copy;
492
-				} else {
493
-					$result['page'] = $res;
494
-				}
495
-				$res = array(
496
-					'status' => 200,
497
-				);
498
-			} else {
499
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
500
-				return false;
501
-			}
502
-		} elseif ($res['location'] and $options['follow_location']) {
503
-			$options['follow_location']--;
504
-			fclose($handle);
505
-			include_spip('inc/filtres');
506
-			$url = suivre_lien($url, $res['location']);
507
-			spip_log("recuperer_url recommence sur $url", 'distant');
508
-
509
-			return recuperer_url($url, $options);
510
-		} elseif ($res['status'] !== 200) {
511
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
512
-		}
513
-		$result['status'] = $res['status'];
514
-		if (isset($res['headers'])) {
515
-			$result['headers'] = $res['headers'];
516
-		}
517
-		if (isset($res['last_modified'])) {
518
-			$result['last_modified'] = $res['last_modified'];
519
-		}
520
-		if (isset($res['location'])) {
521
-			$result['location'] = $res['location'];
522
-		}
523
-	}
524
-
525
-	// on ne veut que les entetes
526
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
527
-		return $result;
528
-	}
529
-
530
-
531
-	// s'il faut deballer, le faire via un fichier temporaire
532
-	// sinon la memoire explose pour les gros flux
533
-
534
-	$gz = false;
535
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
536
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
537
-	}
538
-
539
-	// si on a pas deja recuperer le contenu par une methode detournee
540
-	if (!$result['length']) {
541
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
542
-		fclose($handle);
543
-		if ($copy) {
544
-			$result['length'] = $res;
545
-			$result['file'] = $copy;
546
-		} elseif ($res) {
547
-			$result['page'] = &$res;
548
-			$result['length'] = strlen($result['page']);
549
-		}
550
-		if (!$result['status']) {
551
-			$result['status'] = 200; // on a reussi, donc !
552
-		}
553
-	}
554
-	if (!$result['page']) {
555
-		return $result;
556
-	}
557
-
558
-	// Decompresser au besoin
559
-	if ($gz) {
560
-		$result['page'] = implode('', gzfile($gz));
561
-		supprimer_fichier($gz);
562
-	}
563
-
564
-	// Faut-il l'importer dans notre charset local ?
565
-	if ($options['transcoder']) {
566
-		include_spip('inc/charsets');
567
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
568
-	}
569
-
570
-	return $result;
401
+    $default = array(
402
+        'transcoder' => false,
403
+        'methode' => 'GET',
404
+        'taille_max' => null,
405
+        'datas' => '',
406
+        'boundary' => '',
407
+        'refuser_gz' => false,
408
+        'if_modified_since' => '',
409
+        'uri_referer' => '',
410
+        'file' => '',
411
+        'follow_location' => 10,
412
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
413
+    );
414
+    $options = array_merge($default, $options);
415
+    // copier directement dans un fichier ?
416
+    $copy = $options['file'];
417
+
418
+    if ($options['methode'] == 'HEAD') {
419
+        $options['taille_max'] = 0;
420
+    }
421
+    if (is_null($options['taille_max'])) {
422
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
423
+    }
424
+
425
+    if (!empty($options['datas'])) {
426
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
427
+        if (stripos($head, 'Content-Length:') === false) {
428
+            $head .= 'Content-Length: ' . strlen($postdata);
429
+        }
430
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
431
+        if (strlen($postdata)) {
432
+            $options['methode'] = 'POST';
433
+        }
434
+    }
435
+
436
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
437
+    $url = preg_replace(',^feed://,i', 'http://', $url);
438
+    if (!tester_url_absolue($url)) {
439
+        $url = 'http://' . $url;
440
+    } elseif (strncmp($url, '//', 2) == 0) {
441
+        $url = 'http:' . $url;
442
+    }
443
+
444
+    $url = url_to_ascii($url);
445
+
446
+    $result = array(
447
+        'status' => 0,
448
+        'headers' => '',
449
+        'page' => '',
450
+        'length' => 0,
451
+        'last_modified' => '',
452
+        'location' => '',
453
+        'url' => $url
454
+    );
455
+
456
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
457
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
458
+
459
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
460
+    list($handle, $fopen) = init_http(
461
+        $options['methode'],
462
+        $url,
463
+        $refuser_gz,
464
+        $options['uri_referer'],
465
+        $options['datas'],
466
+        $options['version_http'],
467
+        $options['if_modified_since']
468
+    );
469
+    if (!$handle) {
470
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
471
+
472
+        return false;
473
+    }
474
+
475
+    // Sauf en fopen, envoyer le flux d'entree
476
+    // et recuperer les en-tetes de reponses
477
+    if (!$fopen) {
478
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
479
+        if (!$res) {
480
+            fclose($handle);
481
+            $t = @parse_url($url);
482
+            $host = $t['host'];
483
+            // Chinoisierie inexplicable pour contrer
484
+            // les actions liberticides de l'empire du milieu
485
+            if (!need_proxy($host)
486
+                and $res = @file_get_contents($url)
487
+            ) {
488
+                $result['length'] = strlen($res);
489
+                if ($copy) {
490
+                    ecrire_fichier($copy, $res);
491
+                    $result['file'] = $copy;
492
+                } else {
493
+                    $result['page'] = $res;
494
+                }
495
+                $res = array(
496
+                    'status' => 200,
497
+                );
498
+            } else {
499
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
500
+                return false;
501
+            }
502
+        } elseif ($res['location'] and $options['follow_location']) {
503
+            $options['follow_location']--;
504
+            fclose($handle);
505
+            include_spip('inc/filtres');
506
+            $url = suivre_lien($url, $res['location']);
507
+            spip_log("recuperer_url recommence sur $url", 'distant');
508
+
509
+            return recuperer_url($url, $options);
510
+        } elseif ($res['status'] !== 200) {
511
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
512
+        }
513
+        $result['status'] = $res['status'];
514
+        if (isset($res['headers'])) {
515
+            $result['headers'] = $res['headers'];
516
+        }
517
+        if (isset($res['last_modified'])) {
518
+            $result['last_modified'] = $res['last_modified'];
519
+        }
520
+        if (isset($res['location'])) {
521
+            $result['location'] = $res['location'];
522
+        }
523
+    }
524
+
525
+    // on ne veut que les entetes
526
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
527
+        return $result;
528
+    }
529
+
530
+
531
+    // s'il faut deballer, le faire via un fichier temporaire
532
+    // sinon la memoire explose pour les gros flux
533
+
534
+    $gz = false;
535
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
536
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
537
+    }
538
+
539
+    // si on a pas deja recuperer le contenu par une methode detournee
540
+    if (!$result['length']) {
541
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
542
+        fclose($handle);
543
+        if ($copy) {
544
+            $result['length'] = $res;
545
+            $result['file'] = $copy;
546
+        } elseif ($res) {
547
+            $result['page'] = &$res;
548
+            $result['length'] = strlen($result['page']);
549
+        }
550
+        if (!$result['status']) {
551
+            $result['status'] = 200; // on a reussi, donc !
552
+        }
553
+    }
554
+    if (!$result['page']) {
555
+        return $result;
556
+    }
557
+
558
+    // Decompresser au besoin
559
+    if ($gz) {
560
+        $result['page'] = implode('', gzfile($gz));
561
+        supprimer_fichier($gz);
562
+    }
563
+
564
+    // Faut-il l'importer dans notre charset local ?
565
+    if ($options['transcoder']) {
566
+        include_spip('inc/charsets');
567
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
568
+    }
569
+
570
+    return $result;
571 571
 }
572 572
 
573 573
 /**
@@ -583,72 +583,72 @@  discard block
 block discarded – undo
583 583
  * @return array|bool|mixed
584 584
  */
585 585
 function recuperer_url_cache($url, $options = array()) {
586
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
587
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
588
-	}
589
-	$default = array(
590
-		'transcoder' => false,
591
-		'methode' => 'GET',
592
-		'taille_max' => null,
593
-		'datas' => '',
594
-		'boundary' => '',
595
-		'refuser_gz' => false,
596
-		'if_modified_since' => '',
597
-		'uri_referer' => '',
598
-		'file' => '',
599
-		'follow_location' => 10,
600
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
601
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
602
-	);
603
-	$options = array_merge($default, $options);
604
-
605
-	// cas ou il n'est pas possible de cacher
606
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
607
-		return recuperer_url($url, $options);
608
-	}
609
-
610
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
611
-	static $errors = array();
612
-	if (isset($errors[$url])) {
613
-		return $errors[$url];
614
-	}
615
-
616
-	$sig = $options;
617
-	unset($sig['if_modified_since']);
618
-	unset($sig['delai_cache']);
619
-	$sig['url'] = $url;
620
-
621
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
622
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
623
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
624
-	$cache = "$sub$cache";
625
-
626
-	$res = false;
627
-	$is_cached = file_exists($cache);
628
-	if ($is_cached
629
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
630
-	) {
631
-		lire_fichier($cache, $res);
632
-		if ($res = unserialize($res)) {
633
-			// mettre le last_modified et le status=304 ?
634
-		}
635
-	}
636
-	if (!$res) {
637
-		$res = recuperer_url($url, $options);
638
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
639
-		if (!$res) {
640
-			if ($is_cached) {
641
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
642
-				lire_fichier($cache, $res);
643
-				$res = unserialize($res);
644
-			}
645
-
646
-			return $errors[$url] = $res;
647
-		}
648
-		ecrire_fichier($cache, serialize($res));
649
-	}
650
-
651
-	return $res;
586
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
587
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
588
+    }
589
+    $default = array(
590
+        'transcoder' => false,
591
+        'methode' => 'GET',
592
+        'taille_max' => null,
593
+        'datas' => '',
594
+        'boundary' => '',
595
+        'refuser_gz' => false,
596
+        'if_modified_since' => '',
597
+        'uri_referer' => '',
598
+        'file' => '',
599
+        'follow_location' => 10,
600
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
601
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
602
+    );
603
+    $options = array_merge($default, $options);
604
+
605
+    // cas ou il n'est pas possible de cacher
606
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
607
+        return recuperer_url($url, $options);
608
+    }
609
+
610
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
611
+    static $errors = array();
612
+    if (isset($errors[$url])) {
613
+        return $errors[$url];
614
+    }
615
+
616
+    $sig = $options;
617
+    unset($sig['if_modified_since']);
618
+    unset($sig['delai_cache']);
619
+    $sig['url'] = $url;
620
+
621
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
622
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
623
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
624
+    $cache = "$sub$cache";
625
+
626
+    $res = false;
627
+    $is_cached = file_exists($cache);
628
+    if ($is_cached
629
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
630
+    ) {
631
+        lire_fichier($cache, $res);
632
+        if ($res = unserialize($res)) {
633
+            // mettre le last_modified et le status=304 ?
634
+        }
635
+    }
636
+    if (!$res) {
637
+        $res = recuperer_url($url, $options);
638
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
639
+        if (!$res) {
640
+            if ($is_cached) {
641
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
642
+                lire_fichier($cache, $res);
643
+                $res = unserialize($res);
644
+            }
645
+
646
+            return $errors[$url] = $res;
647
+        }
648
+        ecrire_fichier($cache, serialize($res));
649
+    }
650
+
651
+    return $res;
652 652
 }
653 653
 
654 654
 /**
@@ -686,52 +686,52 @@  discard block
 block discarded – undo
686 686
  *     - false si la page n'a pu être récupérée (status different de 200)
687 687
  **/
688 688
 function recuperer_page(
689
-	$url,
690
-	$trans = false,
691
-	$get_headers = false,
692
-	$taille_max = null,
693
-	$datas = '',
694
-	$boundary = '',
695
-	$refuser_gz = false,
696
-	$date_verif = '',
697
-	$uri_referer = ''
689
+    $url,
690
+    $trans = false,
691
+    $get_headers = false,
692
+    $taille_max = null,
693
+    $datas = '',
694
+    $boundary = '',
695
+    $refuser_gz = false,
696
+    $date_verif = '',
697
+    $uri_referer = ''
698 698
 ) {
699
-	// $copy = copier le fichier ?
700
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
701
-
702
-	if (!is_null($taille_max) and ($taille_max == 0)) {
703
-		$get = 'HEAD';
704
-	} else {
705
-		$get = 'GET';
706
-	}
707
-
708
-	$options = array(
709
-		'transcoder' => $trans === true,
710
-		'methode' => $get,
711
-		'datas' => $datas,
712
-		'boundary' => $boundary,
713
-		'refuser_gz' => $refuser_gz,
714
-		'if_modified_since' => $date_verif,
715
-		'uri_referer' => $uri_referer,
716
-		'file' => $copy ? $trans : '',
717
-		'follow_location' => 10,
718
-	);
719
-	if (!is_null($taille_max)) {
720
-		$options['taille_max'] = $taille_max;
721
-	}
722
-	// dix tentatives maximum en cas d'entetes 301...
723
-	$res = recuperer_url($url, $options);
724
-	if (!$res) {
725
-		return false;
726
-	}
727
-	if ($res['status'] !== 200) {
728
-		return false;
729
-	}
730
-	if ($get_headers) {
731
-		return $res['headers'] . "\n" . $res['page'];
732
-	}
733
-
734
-	return $res['page'];
699
+    // $copy = copier le fichier ?
700
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
701
+
702
+    if (!is_null($taille_max) and ($taille_max == 0)) {
703
+        $get = 'HEAD';
704
+    } else {
705
+        $get = 'GET';
706
+    }
707
+
708
+    $options = array(
709
+        'transcoder' => $trans === true,
710
+        'methode' => $get,
711
+        'datas' => $datas,
712
+        'boundary' => $boundary,
713
+        'refuser_gz' => $refuser_gz,
714
+        'if_modified_since' => $date_verif,
715
+        'uri_referer' => $uri_referer,
716
+        'file' => $copy ? $trans : '',
717
+        'follow_location' => 10,
718
+    );
719
+    if (!is_null($taille_max)) {
720
+        $options['taille_max'] = $taille_max;
721
+    }
722
+    // dix tentatives maximum en cas d'entetes 301...
723
+    $res = recuperer_url($url, $options);
724
+    if (!$res) {
725
+        return false;
726
+    }
727
+    if ($res['status'] !== 200) {
728
+        return false;
729
+    }
730
+    if ($get_headers) {
731
+        return $res['headers'] . "\n" . $res['page'];
732
+    }
733
+
734
+    return $res['page'];
735 735
 }
736 736
 
737 737
 
@@ -768,48 +768,48 @@  discard block
 block discarded – undo
768 768
  *     - false sinon
769 769
  **/
770 770
 function recuperer_lapage(
771
-	$url,
772
-	$trans = false,
773
-	$get = 'GET',
774
-	$taille_max = 1048576,
775
-	$datas = '',
776
-	$refuser_gz = false,
777
-	$date_verif = '',
778
-	$uri_referer = ''
771
+    $url,
772
+    $trans = false,
773
+    $get = 'GET',
774
+    $taille_max = 1048576,
775
+    $datas = '',
776
+    $refuser_gz = false,
777
+    $date_verif = '',
778
+    $uri_referer = ''
779 779
 ) {
780
-	// $copy = copier le fichier ?
781
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
782
-
783
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
784
-	// en memoire refuser gz
785
-	if ($copy) {
786
-		$refuser_gz = true;
787
-	}
788
-
789
-	$options = array(
790
-		'transcoder' => $trans === true,
791
-		'methode' => $get,
792
-		'datas' => $datas,
793
-		'refuser_gz' => $refuser_gz,
794
-		'if_modified_since' => $date_verif,
795
-		'uri_referer' => $uri_referer,
796
-		'file' => $copy ? $trans : '',
797
-		'follow_location' => false,
798
-	);
799
-	if (!is_null($taille_max)) {
800
-		$options['taille_max'] = $taille_max;
801
-	}
802
-	// dix tentatives maximum en cas d'entetes 301...
803
-	$res = recuperer_url($url, $options);
804
-
805
-	if (!$res) {
806
-		return false;
807
-	}
808
-	if ($res['status'] !== 200) {
809
-		return false;
810
-	}
811
-
812
-	return array($res['headers'], $res['page']);
780
+    // $copy = copier le fichier ?
781
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
782
+
783
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
784
+    // en memoire refuser gz
785
+    if ($copy) {
786
+        $refuser_gz = true;
787
+    }
788
+
789
+    $options = array(
790
+        'transcoder' => $trans === true,
791
+        'methode' => $get,
792
+        'datas' => $datas,
793
+        'refuser_gz' => $refuser_gz,
794
+        'if_modified_since' => $date_verif,
795
+        'uri_referer' => $uri_referer,
796
+        'file' => $copy ? $trans : '',
797
+        'follow_location' => false,
798
+    );
799
+    if (!is_null($taille_max)) {
800
+        $options['taille_max'] = $taille_max;
801
+    }
802
+    // dix tentatives maximum en cas d'entetes 301...
803
+    $res = recuperer_url($url, $options);
804
+
805
+    if (!$res) {
806
+        return false;
807
+    }
808
+    if ($res['status'] !== 200) {
809
+        return false;
810
+    }
811
+
812
+    return array($res['headers'], $res['page']);
813 813
 }
814 814
 
815 815
 /**
@@ -827,41 +827,41 @@  discard block
 block discarded – undo
827 827
  *   string contenu de la resource
828 828
  */
829 829
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
830
-	$taille = 0;
831
-	$result = '';
832
-	$fp = false;
833
-	if ($fichier) {
834
-		include_spip('inc/acces');
835
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
836
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
837
-		if (!$fp and file_exists($fichier)) {
838
-			return filesize($fichier);
839
-		}
840
-		if (!$fp) {
841
-			return false;
842
-		}
843
-		$result = 0; // on renvoie la taille du fichier
844
-	}
845
-	while (!feof($handle) and $taille < $taille_max) {
846
-		$res = fread($handle, 16384);
847
-		$taille += strlen($res);
848
-		if ($fp) {
849
-			fwrite($fp, $res);
850
-			$result = $taille;
851
-		} else {
852
-			$result .= $res;
853
-		}
854
-	}
855
-	if ($fp) {
856
-		spip_fclose_unlock($fp);
857
-		spip_unlink($fichier);
858
-		@rename($tmpfile, $fichier);
859
-		if (!file_exists($fichier)) {
860
-			return false;
861
-		}
862
-	}
863
-
864
-	return $result;
830
+    $taille = 0;
831
+    $result = '';
832
+    $fp = false;
833
+    if ($fichier) {
834
+        include_spip('inc/acces');
835
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
836
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
837
+        if (!$fp and file_exists($fichier)) {
838
+            return filesize($fichier);
839
+        }
840
+        if (!$fp) {
841
+            return false;
842
+        }
843
+        $result = 0; // on renvoie la taille du fichier
844
+    }
845
+    while (!feof($handle) and $taille < $taille_max) {
846
+        $res = fread($handle, 16384);
847
+        $taille += strlen($res);
848
+        if ($fp) {
849
+            fwrite($fp, $res);
850
+            $result = $taille;
851
+        } else {
852
+            $result .= $res;
853
+        }
854
+    }
855
+    if ($fp) {
856
+        spip_fclose_unlock($fp);
857
+        spip_unlink($fichier);
858
+        @rename($tmpfile, $fichier);
859
+        if (!file_exists($fichier)) {
860
+            return false;
861
+        }
862
+    }
863
+
864
+    return $result;
865 865
 }
866 866
 
867 867
 /**
@@ -883,34 +883,34 @@  discard block
 block discarded – undo
883 883
  *   string location
884 884
  */
885 885
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
886
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
887
-
888
-	$s = @trim(fgets($handle, 16384));
889
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
890
-		return false;
891
-	}
892
-	$result['status'] = intval($r[1]);
893
-	while ($s = trim(fgets($handle, 16384))) {
894
-		$result['headers'][] = $s . "\n";
895
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
896
-		list(, $d, $v) = $r;
897
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
898
-			$result['location'] = $v;
899
-		} elseif ($d == 'Last-Modified') {
900
-			$result['last_modified'] = strtotime($v);
901
-		}
902
-	}
903
-	if ($if_modified_since
904
-		and $result['last_modified']
905
-		and $if_modified_since > $result['last_modified']
906
-		and $result['status'] == 200
907
-	) {
908
-		$result['status'] = 304;
909
-	}
910
-
911
-	$result['headers'] = implode('', $result['headers']);
912
-
913
-	return $result;
886
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
887
+
888
+    $s = @trim(fgets($handle, 16384));
889
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
890
+        return false;
891
+    }
892
+    $result['status'] = intval($r[1]);
893
+    while ($s = trim(fgets($handle, 16384))) {
894
+        $result['headers'][] = $s . "\n";
895
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
896
+        list(, $d, $v) = $r;
897
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
898
+            $result['location'] = $v;
899
+        } elseif ($d == 'Last-Modified') {
900
+            $result['last_modified'] = strtotime($v);
901
+        }
902
+    }
903
+    if ($if_modified_since
904
+        and $result['last_modified']
905
+        and $if_modified_since > $result['last_modified']
906
+        and $result['status'] == 200
907
+    ) {
908
+        $result['status'] = 304;
909
+    }
910
+
911
+    $result['headers'] = implode('', $result['headers']);
912
+
913
+    return $result;
914 914
 }
915 915
 
916 916
 /**
@@ -932,20 +932,20 @@  discard block
 block discarded – undo
932 932
  *     - le tableau des entetes dans tous les autres cas
933 933
  **/
934 934
 function recuperer_entetes($f, $date_verif = '') {
935
-	//Cas ou la page distante n'a pas bouge depuis
936
-	//la derniere visite
937
-	$res = recuperer_entetes_complets($f, $date_verif);
938
-	if (!$res) {
939
-		return false;
940
-	}
941
-	if ($res['location']) {
942
-		return $res['location'];
943
-	}
944
-	if ($res['status'] != 200) {
945
-		return $res['status'];
946
-	}
947
-
948
-	return explode("\n", $res['headers']);
935
+    //Cas ou la page distante n'a pas bouge depuis
936
+    //la derniere visite
937
+    $res = recuperer_entetes_complets($f, $date_verif);
938
+    if (!$res) {
939
+        return false;
940
+    }
941
+    if ($res['location']) {
942
+        return $res['location'];
943
+    }
944
+    if ($res['status'] != 200) {
945
+        return $res['status'];
946
+    }
947
+
948
+    return explode("\n", $res['headers']);
949 949
 }
950 950
 
951 951
 /**
@@ -967,22 +967,22 @@  discard block
 block discarded – undo
967 967
  *     Nom du fichier pour copie locale
968 968
  **/
969 969
 function nom_fichier_copie_locale($source, $extension) {
970
-	include_spip('inc/documents');
970
+    include_spip('inc/documents');
971 971
 
972
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
973
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
972
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
973
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
974 974
 
975
-	// on se place tout le temps comme si on etait a la racine
976
-	if (_DIR_RACINE) {
977
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
978
-	}
975
+    // on se place tout le temps comme si on etait a la racine
976
+    if (_DIR_RACINE) {
977
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
978
+    }
979 979
 
980
-	$m = md5($source);
980
+    $m = md5($source);
981 981
 
982
-	return $d
983
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
984
-	. substr($m, 0, 4)
985
-	. ".$extension";
982
+    return $d
983
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
984
+    . substr($m, 0, 4)
985
+    . ".$extension";
986 986
 }
987 987
 
988 988
 /**
@@ -1000,68 +1000,68 @@  discard block
 block discarded – undo
1000 1000
  *      Nom du fichier calculé
1001 1001
  **/
1002 1002
 function fichier_copie_locale($source) {
1003
-	// Si c'est deja local pas de souci
1004
-	if (!tester_url_absolue($source)) {
1005
-		if (_DIR_RACINE) {
1006
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1007
-		}
1008
-
1009
-		return $source;
1010
-	}
1011
-
1012
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1013
-	// a deja ete copie en local avec cette extension
1014
-	// dans ce cas elle est fiable, pas la peine de requeter en base
1015
-	$path_parts = pathinfo($source);
1016
-	if (!isset($path_parts['extension'])) {
1017
-		$path_parts['extension'] = '';
1018
-	}
1019
-	$ext = $path_parts ? $path_parts['extension'] : '';
1020
-	if ($ext
1021
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1022
-		and $f = nom_fichier_copie_locale($source, $ext)
1023
-		and file_exists(_DIR_RACINE . $f)
1024
-	) {
1025
-		return $f;
1026
-	}
1027
-
1028
-
1029
-	// Si c'est deja dans la table des documents,
1030
-	// ramener le nom de sa copie potentielle
1031
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1032
-
1033
-	if ($ext) {
1034
-		return nom_fichier_copie_locale($source, $ext);
1035
-	}
1036
-
1037
-	// voir si l'extension indiquee dans le nom du fichier est ok
1038
-	// et si il n'aurait pas deja ete rapatrie
1039
-
1040
-	$ext = $path_parts ? $path_parts['extension'] : '';
1041
-
1042
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1043
-		$f = nom_fichier_copie_locale($source, $ext);
1044
-		if (file_exists(_DIR_RACINE . $f)) {
1045
-			return $f;
1046
-		}
1047
-	}
1048
-
1049
-	// Ping  pour voir si son extension est connue et autorisee
1050
-	// avec mise en cache du resultat du ping
1051
-
1052
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1053
-	if (!@file_exists($cache)
1054
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1055
-		or _request('var_mode') == 'recalcul'
1056
-	) {
1057
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1058
-		ecrire_fichier($cache, serialize($path_parts));
1059
-	}
1060
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1061
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1062
-		return nom_fichier_copie_locale($source, $ext);
1063
-	}
1064
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1003
+    // Si c'est deja local pas de souci
1004
+    if (!tester_url_absolue($source)) {
1005
+        if (_DIR_RACINE) {
1006
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1007
+        }
1008
+
1009
+        return $source;
1010
+    }
1011
+
1012
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1013
+    // a deja ete copie en local avec cette extension
1014
+    // dans ce cas elle est fiable, pas la peine de requeter en base
1015
+    $path_parts = pathinfo($source);
1016
+    if (!isset($path_parts['extension'])) {
1017
+        $path_parts['extension'] = '';
1018
+    }
1019
+    $ext = $path_parts ? $path_parts['extension'] : '';
1020
+    if ($ext
1021
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1022
+        and $f = nom_fichier_copie_locale($source, $ext)
1023
+        and file_exists(_DIR_RACINE . $f)
1024
+    ) {
1025
+        return $f;
1026
+    }
1027
+
1028
+
1029
+    // Si c'est deja dans la table des documents,
1030
+    // ramener le nom de sa copie potentielle
1031
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1032
+
1033
+    if ($ext) {
1034
+        return nom_fichier_copie_locale($source, $ext);
1035
+    }
1036
+
1037
+    // voir si l'extension indiquee dans le nom du fichier est ok
1038
+    // et si il n'aurait pas deja ete rapatrie
1039
+
1040
+    $ext = $path_parts ? $path_parts['extension'] : '';
1041
+
1042
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1043
+        $f = nom_fichier_copie_locale($source, $ext);
1044
+        if (file_exists(_DIR_RACINE . $f)) {
1045
+            return $f;
1046
+        }
1047
+    }
1048
+
1049
+    // Ping  pour voir si son extension est connue et autorisee
1050
+    // avec mise en cache du resultat du ping
1051
+
1052
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1053
+    if (!@file_exists($cache)
1054
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1055
+        or _request('var_mode') == 'recalcul'
1056
+    ) {
1057
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1058
+        ecrire_fichier($cache, serialize($path_parts));
1059
+    }
1060
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1061
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1062
+        return nom_fichier_copie_locale($source, $ext);
1063
+    }
1064
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1065 1065
 }
1066 1066
 
1067 1067
 
@@ -1089,144 +1089,144 @@  discard block
 block discarded – undo
1089 1089
  **/
1090 1090
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1091 1091
 
1092
-	// pas la peine de perdre son temps
1093
-	if (!tester_url_absolue($source)) {
1094
-		return false;
1095
-	}
1096
-
1097
-	# charger les alias des types mime
1098
-	include_spip('base/typedoc');
1099
-
1100
-	$a = array();
1101
-	$mime_type = '';
1102
-	// On va directement charger le debut des images et des fichiers html,
1103
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1104
-	// ca echoue l'utilisateur devra les entrer...
1105
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1106
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1107
-
1108
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1109
-			$mime_type = (trim($regs[1]));
1110
-		} else {
1111
-			$mime_type = '';
1112
-		} // inconnu
1113
-
1114
-		// Appliquer les alias
1115
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1116
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1117
-		}
1118
-
1119
-		// Si on a un mime-type insignifiant
1120
-		// text/plain,application/octet-stream ou vide
1121
-		// c'est peut-etre que le serveur ne sait pas
1122
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1123
-		// ou le Content-Disposition: attachment; filename=...
1124
-		$t = null;
1125
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1126
-			if (!$t
1127
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1128
-			) {
1129
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1130
-			}
1131
-			if (!$t
1132
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1133
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1134
-			) {
1135
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1136
-			}
1137
-		}
1138
-
1139
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1140
-		if (!$t) {
1141
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1142
-		}
1143
-
1144
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1145
-		// On essaie de nouveau avec l'extension
1146
-		if (!$t
1147
-			and $mime_type != 'text/plain'
1148
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1149
-		) {
1150
-			# eviter xxx.3 => 3gp (> SPIP 3)
1151
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1152
-		}
1153
-
1154
-		if ($t) {
1155
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1156
-			$a['extension'] = $t['extension'];
1157
-		} else {
1158
-			# par defaut on retombe sur '.bin' si c'est autorise
1159
-			spip_log("mime-type $mime_type inconnu", 'distant');
1160
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1161
-			if (!$t) {
1162
-				return false;
1163
-			}
1164
-			$a['extension'] = $t['extension'];
1165
-		}
1166
-
1167
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1168
-			$a['taille'] = intval($regs[1]);
1169
-		}
1170
-	}
1171
-
1172
-	// Echec avec HEAD, on tente avec GET
1173
-	if (!$a and !$max) {
1174
-		spip_log("tenter GET $source", 'distant');
1175
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1176
-	}
1177
-
1178
-	// si on a rien trouve pas la peine d'insister
1179
-	if (!$a) {
1180
-		return false;
1181
-	}
1182
-
1183
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1184
-	// recharger le document en GET et recuperer des donnees supplementaires...
1185
-	include_spip('inc/filtres_images_lib_mini');
1186
-	if (strpos($mime_type, "image/") === 0
1187
-	  and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1188
-		if ($max == 0
1189
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1190
-			and in_array($extension, formats_image_acceptables())
1191
-			and $charger_si_petite_image
1192
-		) {
1193
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1194
-		} else {
1195
-			if ($a['body']) {
1196
-				$a['extension'] = $extension;
1197
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1198
-				ecrire_fichier($a['fichier'], $a['body']);
1199
-				$size_image = @spip_getimagesize($a['fichier']);
1200
-				$a['largeur'] = intval($size_image[0]);
1201
-				$a['hauteur'] = intval($size_image[1]);
1202
-				$a['type_image'] = true;
1203
-			}
1204
-		}
1205
-	}
1206
-
1207
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1208
-	// ce sera mieux que 0x0
1209
-	// Flash is dead!
1210
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1211
-		and empty($a['largeur'])
1212
-	) {
1213
-		$a['largeur'] = 425;
1214
-		$a['hauteur'] = 350;
1215
-	}
1216
-
1217
-	if ($mime_type == 'text/html') {
1218
-		include_spip('inc/filtres');
1219
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1220
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1221
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1222
-		}
1223
-		if (!isset($a['taille']) or !$a['taille']) {
1224
-			$a['taille'] = strlen($page); # a peu pres
1225
-		}
1226
-	}
1227
-	$a['mime_type'] = $mime_type;
1228
-
1229
-	return $a;
1092
+    // pas la peine de perdre son temps
1093
+    if (!tester_url_absolue($source)) {
1094
+        return false;
1095
+    }
1096
+
1097
+    # charger les alias des types mime
1098
+    include_spip('base/typedoc');
1099
+
1100
+    $a = array();
1101
+    $mime_type = '';
1102
+    // On va directement charger le debut des images et des fichiers html,
1103
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1104
+    // ca echoue l'utilisateur devra les entrer...
1105
+    if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1106
+        list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1107
+
1108
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1109
+            $mime_type = (trim($regs[1]));
1110
+        } else {
1111
+            $mime_type = '';
1112
+        } // inconnu
1113
+
1114
+        // Appliquer les alias
1115
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1116
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1117
+        }
1118
+
1119
+        // Si on a un mime-type insignifiant
1120
+        // text/plain,application/octet-stream ou vide
1121
+        // c'est peut-etre que le serveur ne sait pas
1122
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1123
+        // ou le Content-Disposition: attachment; filename=...
1124
+        $t = null;
1125
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1126
+            if (!$t
1127
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1128
+            ) {
1129
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1130
+            }
1131
+            if (!$t
1132
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1133
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1134
+            ) {
1135
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1136
+            }
1137
+        }
1138
+
1139
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1140
+        if (!$t) {
1141
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1142
+        }
1143
+
1144
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1145
+        // On essaie de nouveau avec l'extension
1146
+        if (!$t
1147
+            and $mime_type != 'text/plain'
1148
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1149
+        ) {
1150
+            # eviter xxx.3 => 3gp (> SPIP 3)
1151
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1152
+        }
1153
+
1154
+        if ($t) {
1155
+            spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1156
+            $a['extension'] = $t['extension'];
1157
+        } else {
1158
+            # par defaut on retombe sur '.bin' si c'est autorise
1159
+            spip_log("mime-type $mime_type inconnu", 'distant');
1160
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1161
+            if (!$t) {
1162
+                return false;
1163
+            }
1164
+            $a['extension'] = $t['extension'];
1165
+        }
1166
+
1167
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1168
+            $a['taille'] = intval($regs[1]);
1169
+        }
1170
+    }
1171
+
1172
+    // Echec avec HEAD, on tente avec GET
1173
+    if (!$a and !$max) {
1174
+        spip_log("tenter GET $source", 'distant');
1175
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1176
+    }
1177
+
1178
+    // si on a rien trouve pas la peine d'insister
1179
+    if (!$a) {
1180
+        return false;
1181
+    }
1182
+
1183
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1184
+    // recharger le document en GET et recuperer des donnees supplementaires...
1185
+    include_spip('inc/filtres_images_lib_mini');
1186
+    if (strpos($mime_type, "image/") === 0
1187
+      and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1188
+        if ($max == 0
1189
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1190
+            and in_array($extension, formats_image_acceptables())
1191
+            and $charger_si_petite_image
1192
+        ) {
1193
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1194
+        } else {
1195
+            if ($a['body']) {
1196
+                $a['extension'] = $extension;
1197
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1198
+                ecrire_fichier($a['fichier'], $a['body']);
1199
+                $size_image = @spip_getimagesize($a['fichier']);
1200
+                $a['largeur'] = intval($size_image[0]);
1201
+                $a['hauteur'] = intval($size_image[1]);
1202
+                $a['type_image'] = true;
1203
+            }
1204
+        }
1205
+    }
1206
+
1207
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1208
+    // ce sera mieux que 0x0
1209
+    // Flash is dead!
1210
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1211
+        and empty($a['largeur'])
1212
+    ) {
1213
+        $a['largeur'] = 425;
1214
+        $a['hauteur'] = 350;
1215
+    }
1216
+
1217
+    if ($mime_type == 'text/html') {
1218
+        include_spip('inc/filtres');
1219
+        $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1220
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1221
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1222
+        }
1223
+        if (!isset($a['taille']) or !$a['taille']) {
1224
+            $a['taille'] = strlen($page); # a peu pres
1225
+        }
1226
+    }
1227
+    $a['mime_type'] = $mime_type;
1228
+
1229
+    return $a;
1230 1230
 }
1231 1231
 
1232 1232
 
@@ -1242,45 +1242,45 @@  discard block
 block discarded – undo
1242 1242
  * @return string
1243 1243
  */
1244 1244
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1245
-	if (is_null($http_proxy)) {
1246
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1247
-	}
1248
-	// rien a faire si pas de proxy :)
1249
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1250
-		return '';
1251
-	}
1252
-
1253
-	if (is_null($http_noproxy)) {
1254
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1255
-	}
1256
-	// si pas d'exception, on retourne le proxy
1257
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1258
-		return $http_proxy;
1259
-	}
1260
-
1261
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1262
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1263
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1264
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1265
-	$http_noproxy = " $http_noproxy ";
1266
-	$domain = $host;
1267
-	// si le domaine exact www.example.org est dans les exceptions
1268
-	if (strpos($http_noproxy, " $domain ") !== false)
1269
-		return '';
1270
-
1271
-	while (strpos($domain, '.') !== false) {
1272
-		$domain = explode('.', $domain);
1273
-		array_shift($domain);
1274
-		$domain = implode('.', $domain);
1275
-
1276
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1277
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1278
-			return '';
1279
-		}
1280
-	}
1281
-
1282
-	// ok c'est pas une exception
1283
-	return $http_proxy;
1245
+    if (is_null($http_proxy)) {
1246
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1247
+    }
1248
+    // rien a faire si pas de proxy :)
1249
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1250
+        return '';
1251
+    }
1252
+
1253
+    if (is_null($http_noproxy)) {
1254
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1255
+    }
1256
+    // si pas d'exception, on retourne le proxy
1257
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1258
+        return $http_proxy;
1259
+    }
1260
+
1261
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1262
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1263
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1264
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1265
+    $http_noproxy = " $http_noproxy ";
1266
+    $domain = $host;
1267
+    // si le domaine exact www.example.org est dans les exceptions
1268
+    if (strpos($http_noproxy, " $domain ") !== false)
1269
+        return '';
1270
+
1271
+    while (strpos($domain, '.') !== false) {
1272
+        $domain = explode('.', $domain);
1273
+        array_shift($domain);
1274
+        $domain = implode('.', $domain);
1275
+
1276
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1277
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1278
+            return '';
1279
+        }
1280
+    }
1281
+
1282
+    // ok c'est pas une exception
1283
+    return $http_proxy;
1284 1284
 }
1285 1285
 
1286 1286
 
@@ -1303,58 +1303,58 @@  discard block
 block discarded – undo
1303 1303
  * @return array
1304 1304
  */
1305 1305
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1306
-	$user = $via_proxy = $proxy_user = '';
1307
-	$fopen = false;
1308
-
1309
-	$t = @parse_url($url);
1310
-	$host = $t['host'];
1311
-	if ($t['scheme'] == 'http') {
1312
-		$scheme = 'http';
1313
-		$noproxy = '';
1314
-	} elseif ($t['scheme'] == 'https') {
1315
-		$scheme = 'ssl';
1316
-		$noproxy = 'ssl://';
1317
-		if (!isset($t['port']) || !($port = $t['port'])) {
1318
-			$t['port'] = 443;
1319
-		}
1320
-	} else {
1321
-		$scheme = $t['scheme'];
1322
-		$noproxy = $scheme . '://';
1323
-	}
1324
-	if (isset($t['user'])) {
1325
-		$user = array($t['user'], $t['pass']);
1326
-	}
1327
-
1328
-	if (!isset($t['port']) || !($port = $t['port'])) {
1329
-		$port = 80;
1330
-	}
1331
-	if (!isset($t['path']) || !($path = $t['path'])) {
1332
-		$path = '/';
1333
-	}
1334
-
1335
-	if (!empty($t['query'])) {
1336
-		$path .= '?' . $t['query'];
1337
-	}
1338
-
1339
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1340
-	if (!$f or !is_resource($f)) {
1341
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1342
-		// ce qui correspond a $f===110
1343
-		if ($f !== 110
1344
-			and !need_proxy($host)
1345
-			and !_request('tester_proxy')
1346
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1347
-		) {
1348
-			$f = @fopen($url, 'rb');
1349
-			spip_log("connexion vers $url par simple fopen", 'distant');
1350
-			$fopen = true;
1351
-		} else {
1352
-			// echec total
1353
-			$f = false;
1354
-		}
1355
-	}
1356
-
1357
-	return array($f, $fopen);
1306
+    $user = $via_proxy = $proxy_user = '';
1307
+    $fopen = false;
1308
+
1309
+    $t = @parse_url($url);
1310
+    $host = $t['host'];
1311
+    if ($t['scheme'] == 'http') {
1312
+        $scheme = 'http';
1313
+        $noproxy = '';
1314
+    } elseif ($t['scheme'] == 'https') {
1315
+        $scheme = 'ssl';
1316
+        $noproxy = 'ssl://';
1317
+        if (!isset($t['port']) || !($port = $t['port'])) {
1318
+            $t['port'] = 443;
1319
+        }
1320
+    } else {
1321
+        $scheme = $t['scheme'];
1322
+        $noproxy = $scheme . '://';
1323
+    }
1324
+    if (isset($t['user'])) {
1325
+        $user = array($t['user'], $t['pass']);
1326
+    }
1327
+
1328
+    if (!isset($t['port']) || !($port = $t['port'])) {
1329
+        $port = 80;
1330
+    }
1331
+    if (!isset($t['path']) || !($path = $t['path'])) {
1332
+        $path = '/';
1333
+    }
1334
+
1335
+    if (!empty($t['query'])) {
1336
+        $path .= '?' . $t['query'];
1337
+    }
1338
+
1339
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1340
+    if (!$f or !is_resource($f)) {
1341
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1342
+        // ce qui correspond a $f===110
1343
+        if ($f !== 110
1344
+            and !need_proxy($host)
1345
+            and !_request('tester_proxy')
1346
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1347
+        ) {
1348
+            $f = @fopen($url, 'rb');
1349
+            spip_log("connexion vers $url par simple fopen", 'distant');
1350
+            $fopen = true;
1351
+        } else {
1352
+            // echec total
1353
+            $f = false;
1354
+        }
1355
+    }
1356
+
1357
+    return array($f, $fopen);
1358 1358
 }
1359 1359
 
1360 1360
 /**
@@ -1389,127 +1389,127 @@  discard block
 block discarded – undo
1389 1389
  *   resource socket vers l'url demandee
1390 1390
  */
1391 1391
 function lance_requete(
1392
-	$method,
1393
-	$scheme,
1394
-	$user,
1395
-	$host,
1396
-	$path,
1397
-	$port,
1398
-	$noproxy,
1399
-	$refuse_gz = false,
1400
-	$referer = '',
1401
-	$datas = '',
1402
-	$vers = 'HTTP/1.0',
1403
-	$date = ''
1392
+    $method,
1393
+    $scheme,
1394
+    $user,
1395
+    $host,
1396
+    $path,
1397
+    $port,
1398
+    $noproxy,
1399
+    $refuse_gz = false,
1400
+    $referer = '',
1401
+    $datas = '',
1402
+    $vers = 'HTTP/1.0',
1403
+    $date = ''
1404 1404
 ) {
1405 1405
 
1406
-	$proxy_user = '';
1407
-	$http_proxy = need_proxy($host);
1408
-	if ($user) {
1409
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1410
-	}
1411
-
1412
-	$connect = '';
1413
-	if ($http_proxy) {
1414
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1415
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1416
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1417
-				. "Host: $path_host\r\n"
1418
-				. "Proxy-Connection: Keep-Alive\r\n";
1419
-		} else {
1420
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1421
-				. (!$user ? '' : "$user@")
1422
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1423
-		}
1424
-		$t2 = @parse_url($http_proxy);
1425
-		$first_host = $t2['host'];
1426
-		if (!($port = $t2['port'])) {
1427
-			$port = 80;
1428
-		}
1429
-		if ($t2['user']) {
1430
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1431
-		}
1432
-	} else {
1433
-		$first_host = $noproxy . $host;
1434
-	}
1435
-
1436
-	if ($connect) {
1437
-		$streamContext = stream_context_create(array(
1438
-			'ssl' => array(
1439
-				'verify_peer' => false,
1440
-				'allow_self_signed' => true,
1441
-				'SNI_enabled' => true,
1442
-				'peer_name' => $host,
1443
-			)
1444
-		));
1445
-		if (version_compare(phpversion(), '5.6', '<')) {
1446
-			stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1447
-		}
1448
-		$f = @stream_socket_client(
1449
-			"tcp://$first_host:$port",
1450
-			$errno,
1451
-			$errstr,
1452
-			_INC_DISTANT_CONNECT_TIMEOUT,
1453
-			STREAM_CLIENT_CONNECT,
1454
-			$streamContext
1455
-		);
1456
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1457
-		if (!$f) {
1458
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1459
-			return $errno;
1460
-		}
1461
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1462
-
1463
-		fputs($f, $connect);
1464
-		fputs($f, "\r\n");
1465
-		$res = fread($f, 1024);
1466
-		if (!$res
1467
-			or !count($res = explode(' ', $res))
1468
-			or $res[1] !== '200'
1469
-		) {
1470
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1471
-			fclose($f);
1472
-
1473
-			return false;
1474
-		}
1475
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1476
-		stream_set_blocking($f, true);
1477
-		// envoyer le handshake
1478
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1479
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1480
-	} else {
1481
-		$ntry = 3;
1482
-		do {
1483
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1484
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1485
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1486
-		if (!$f) {
1487
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1488
-
1489
-			return $errno;
1490
-		}
1491
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1492
-	}
1493
-
1494
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1495
-
1496
-	$host_port = $host;
1497
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1498
-		$host_port .= ":$port";
1499
-	}
1500
-	$req = "$method $path $vers\r\n"
1501
-		. "Host: $host_port\r\n"
1502
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1503
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1504
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1505
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1506
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1507
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1508
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1406
+    $proxy_user = '';
1407
+    $http_proxy = need_proxy($host);
1408
+    if ($user) {
1409
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1410
+    }
1411
+
1412
+    $connect = '';
1413
+    if ($http_proxy) {
1414
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1415
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1416
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1417
+                . "Host: $path_host\r\n"
1418
+                . "Proxy-Connection: Keep-Alive\r\n";
1419
+        } else {
1420
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1421
+                . (!$user ? '' : "$user@")
1422
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1423
+        }
1424
+        $t2 = @parse_url($http_proxy);
1425
+        $first_host = $t2['host'];
1426
+        if (!($port = $t2['port'])) {
1427
+            $port = 80;
1428
+        }
1429
+        if ($t2['user']) {
1430
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1431
+        }
1432
+    } else {
1433
+        $first_host = $noproxy . $host;
1434
+    }
1435
+
1436
+    if ($connect) {
1437
+        $streamContext = stream_context_create(array(
1438
+            'ssl' => array(
1439
+                'verify_peer' => false,
1440
+                'allow_self_signed' => true,
1441
+                'SNI_enabled' => true,
1442
+                'peer_name' => $host,
1443
+            )
1444
+        ));
1445
+        if (version_compare(phpversion(), '5.6', '<')) {
1446
+            stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1447
+        }
1448
+        $f = @stream_socket_client(
1449
+            "tcp://$first_host:$port",
1450
+            $errno,
1451
+            $errstr,
1452
+            _INC_DISTANT_CONNECT_TIMEOUT,
1453
+            STREAM_CLIENT_CONNECT,
1454
+            $streamContext
1455
+        );
1456
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1457
+        if (!$f) {
1458
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1459
+            return $errno;
1460
+        }
1461
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1462
+
1463
+        fputs($f, $connect);
1464
+        fputs($f, "\r\n");
1465
+        $res = fread($f, 1024);
1466
+        if (!$res
1467
+            or !count($res = explode(' ', $res))
1468
+            or $res[1] !== '200'
1469
+        ) {
1470
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1471
+            fclose($f);
1472
+
1473
+            return false;
1474
+        }
1475
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1476
+        stream_set_blocking($f, true);
1477
+        // envoyer le handshake
1478
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1479
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1480
+    } else {
1481
+        $ntry = 3;
1482
+        do {
1483
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1484
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1485
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1486
+        if (!$f) {
1487
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1488
+
1489
+            return $errno;
1490
+        }
1491
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1492
+    }
1493
+
1494
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1495
+
1496
+    $host_port = $host;
1497
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1498
+        $host_port .= ":$port";
1499
+    }
1500
+    $req = "$method $path $vers\r\n"
1501
+        . "Host: $host_port\r\n"
1502
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1503
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1504
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1505
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1506
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1507
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1508
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1509 1509
 
1510 1510
 #	spip_log("Requete\n$req", 'distant');
1511
-	fputs($f, $req);
1512
-	fputs($f, $datas ? $datas : "\r\n");
1511
+    fputs($f, $req);
1512
+    fputs($f, $datas ? $datas : "\r\n");
1513 1513
 
1514
-	return $f;
1514
+    return $f;
1515 1515
 }
Please login to merge, or discard this patch.
ecrire/inc/editer.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
  * utile pour les textes > 32ko
315 315
  *
316 316
  * @param  string $texte
317
- * @return array
317
+ * @return string[]
318 318
  */
319 319
 function coupe_trop_long($texte) {
320 320
 	$aider = charger_fonction('aider', 'inc');
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
  *
348 348
  * @param string $texte
349 349
  * @param string $att_text
350
- * @return array
350
+ * @return string[]
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353 353
 	if ((strlen($texte) < 29 * 1024)
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 /**
374 374
  * auto-renseigner le titre si il n'existe pas
375 375
  *
376
- * @param $champ_titre
377
- * @param $champs_contenu
376
+ * @param string $champ_titre
377
+ * @param string[] $champs_contenu
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
Please login to merge, or discard this patch.
Indentation   +474 added lines, -474 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = array(),
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = array(),
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = array();
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = array();
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) {
135
-	$erreurs = array();
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = array();
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -198,133 +198,133 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = array(),
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = array(),
208
+    $hidden = ''
209 209
 ) {
210 210
 
211
-	$table_objet = table_objet($type);
212
-	$table_objet_sql = table_objet_sql($type);
213
-	$id_table_objet = id_table_objet($type);
214
-
215
-	// on accepte pas une fonction de config inconnue si elle vient d'un modele
216
-	if ($config_fonc
217
-	  and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
-	  and $config_fonc !== $table_objet . '_edit_config') {
219
-		if ($args = test_formulaire_inclus_par_modele()
220
-		  and in_array($config_fonc, $args)) {
221
-			$config_fonc = '';
222
-		}
223
-	}
224
-
225
-	$new = !is_numeric($id);
226
-	$lang_default = '';
227
-	// Appel direct dans un squelette
228
-	if (!$row) {
229
-		if (!$new or $lier_trad) {
230
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
231
-				$row = $select($id, $id_parent, $lier_trad);
232
-				// si on a une fonction precharger, elle pu faire un reglage de langue
233
-				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234
-			} else {
235
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
236
-			}
237
-			if (!$new) {
238
-				$md5 = controles_md5($row);
239
-			}
240
-		}
241
-		if (!$row) {
242
-			$row = array();
243
-			$trouver_table = charger_fonction('trouver_table', 'base');
244
-			if ($desc = $trouver_table($table_objet)) {
245
-				foreach ($desc['field'] as $k => $v) {
246
-					$row[$k] = '';
247
-				}
248
-			}
249
-		}
250
-	}
251
-
252
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
253
-	// (et donc: pas de lien de traduction)
254
-	$id = ($new or $lier_trad)
255
-		? 'oui'
256
-		: $row[$id_table_objet];
257
-	$row[$id_table_objet] = $id;
258
-
259
-	$contexte = $row;
260
-	if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
261
-		if (!isset($contexte['id_parent'])) {
262
-			unset($contexte['id_rubrique']);
263
-		}
264
-		$contexte['id_parent'] = $id_parent;
265
-	} elseif (!isset($contexte['id_parent'])) {
266
-		// id_rubrique dans id_parent si possible
267
-		if (isset($contexte['id_rubrique'])) {
268
-			$contexte['id_parent'] = $contexte['id_rubrique'];
269
-			unset($contexte['id_rubrique']);
270
-		} else {
271
-			$contexte['id_parent'] = '';
272
-		}
273
-		if (!$contexte['id_parent']
274
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
275
-		) {
276
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
277
-		}
278
-	}
279
-
280
-	$config = array();
281
-	if ($config_fonc) {
282
-		$contexte['config'] = $config = $config_fonc($contexte);
283
-		if (!$lang_default) {
284
-			$lang_default = $config['langue'];
285
-		}
286
-	}
287
-	$config = $config + array(
288
-		'lignes' => 0,
289
-		'langue' => '',
290
-	);
291
-
292
-	$att_text = " class='textarea' "
293
-		. " rows='"
294
-		. ($config['lignes'] + 15)
295
-		. "' cols='40'";
296
-	if (isset($contexte['texte'])) {
297
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
298
-	}
299
-
300
-	// on veut conserver la langue de l'interface ;
301
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
302
-	// voudrait l'exploiter
303
-	if (isset($contexte['lang'])) {
304
-		$contexte['langue'] = $contexte['lang'];
305
-		unset($contexte['lang']);
306
-	}
307
-
308
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
-		(!$lier_trad ? '' :
310
-			("\n<input type='hidden' name='lier_trad' value='" .
311
-				$lier_trad .
312
-				"' />" .
313
-				"\n<input type='hidden' name='changer_lang' value='" .
314
-				$lang_default .
315
-				"' />"))
316
-		. $hidden
317
-		. (isset($md5) ? $md5 : '');
318
-
319
-	// preciser que le formulaire doit passer dans un pipeline
320
-	$contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
321
-
322
-	// preciser que le formulaire doit etre securise auteur/action
323
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
324
-	// on le garde pour compat
325
-	$contexte['_action'] = array("editer_$type", $id);
326
-
327
-	return $contexte;
211
+    $table_objet = table_objet($type);
212
+    $table_objet_sql = table_objet_sql($type);
213
+    $id_table_objet = id_table_objet($type);
214
+
215
+    // on accepte pas une fonction de config inconnue si elle vient d'un modele
216
+    if ($config_fonc
217
+      and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
+      and $config_fonc !== $table_objet . '_edit_config') {
219
+        if ($args = test_formulaire_inclus_par_modele()
220
+          and in_array($config_fonc, $args)) {
221
+            $config_fonc = '';
222
+        }
223
+    }
224
+
225
+    $new = !is_numeric($id);
226
+    $lang_default = '';
227
+    // Appel direct dans un squelette
228
+    if (!$row) {
229
+        if (!$new or $lier_trad) {
230
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
231
+                $row = $select($id, $id_parent, $lier_trad);
232
+                // si on a une fonction precharger, elle pu faire un reglage de langue
233
+                $lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234
+            } else {
235
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
236
+            }
237
+            if (!$new) {
238
+                $md5 = controles_md5($row);
239
+            }
240
+        }
241
+        if (!$row) {
242
+            $row = array();
243
+            $trouver_table = charger_fonction('trouver_table', 'base');
244
+            if ($desc = $trouver_table($table_objet)) {
245
+                foreach ($desc['field'] as $k => $v) {
246
+                    $row[$k] = '';
247
+                }
248
+            }
249
+        }
250
+    }
251
+
252
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
253
+    // (et donc: pas de lien de traduction)
254
+    $id = ($new or $lier_trad)
255
+        ? 'oui'
256
+        : $row[$id_table_objet];
257
+    $row[$id_table_objet] = $id;
258
+
259
+    $contexte = $row;
260
+    if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
261
+        if (!isset($contexte['id_parent'])) {
262
+            unset($contexte['id_rubrique']);
263
+        }
264
+        $contexte['id_parent'] = $id_parent;
265
+    } elseif (!isset($contexte['id_parent'])) {
266
+        // id_rubrique dans id_parent si possible
267
+        if (isset($contexte['id_rubrique'])) {
268
+            $contexte['id_parent'] = $contexte['id_rubrique'];
269
+            unset($contexte['id_rubrique']);
270
+        } else {
271
+            $contexte['id_parent'] = '';
272
+        }
273
+        if (!$contexte['id_parent']
274
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
275
+        ) {
276
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
277
+        }
278
+    }
279
+
280
+    $config = array();
281
+    if ($config_fonc) {
282
+        $contexte['config'] = $config = $config_fonc($contexte);
283
+        if (!$lang_default) {
284
+            $lang_default = $config['langue'];
285
+        }
286
+    }
287
+    $config = $config + array(
288
+        'lignes' => 0,
289
+        'langue' => '',
290
+    );
291
+
292
+    $att_text = " class='textarea' "
293
+        . " rows='"
294
+        . ($config['lignes'] + 15)
295
+        . "' cols='40'";
296
+    if (isset($contexte['texte'])) {
297
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
298
+    }
299
+
300
+    // on veut conserver la langue de l'interface ;
301
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
302
+    // voudrait l'exploiter
303
+    if (isset($contexte['lang'])) {
304
+        $contexte['langue'] = $contexte['lang'];
305
+        unset($contexte['lang']);
306
+    }
307
+
308
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
+        (!$lier_trad ? '' :
310
+            ("\n<input type='hidden' name='lier_trad' value='" .
311
+                $lier_trad .
312
+                "' />" .
313
+                "\n<input type='hidden' name='changer_lang' value='" .
314
+                $lang_default .
315
+                "' />"))
316
+        . $hidden
317
+        . (isset($md5) ? $md5 : '');
318
+
319
+    // preciser que le formulaire doit passer dans un pipeline
320
+    $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
321
+
322
+    // preciser que le formulaire doit etre securise auteur/action
323
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
324
+    // on le garde pour compat
325
+    $contexte['_action'] = array("editer_$type", $id);
326
+
327
+    return $contexte;
328 328
 }
329 329
 
330 330
 /**
@@ -335,29 +335,29 @@  discard block
 block discarded – undo
335 335
  * @return array
336 336
  */
337 337
 function coupe_trop_long($texte) {
338
-	$aider = charger_fonction('aider', 'inc');
339
-	if (strlen($texte) > 28 * 1024) {
340
-		$texte = str_replace("\r\n", "\n", $texte);
341
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
342
-		if ($pos > 0 and $pos < 32 * 1024) {
343
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
344
-			$suite = substr($texte, $pos + 2);
345
-		} else {
346
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
347
-			if (!($pos > 0 and $pos < 32 * 1024)) {
348
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
349
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
350
-			} else {
351
-				$decalage = 1;
352
-			}
353
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
354
-			$suite = substr($texte, $pos + $decalage);
355
-		}
356
-
357
-		return (array($debut, $suite));
358
-	} else {
359
-		return (array($texte, ''));
360
-	}
338
+    $aider = charger_fonction('aider', 'inc');
339
+    if (strlen($texte) > 28 * 1024) {
340
+        $texte = str_replace("\r\n", "\n", $texte);
341
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
342
+        if ($pos > 0 and $pos < 32 * 1024) {
343
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
344
+            $suite = substr($texte, $pos + 2);
345
+        } else {
346
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
347
+            if (!($pos > 0 and $pos < 32 * 1024)) {
348
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
349
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
350
+            } else {
351
+                $decalage = 1;
352
+            }
353
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
354
+            $suite = substr($texte, $pos + $decalage);
355
+        }
356
+
357
+        return (array($debut, $suite));
358
+    } else {
359
+        return (array($texte, ''));
360
+    }
361 361
 }
362 362
 
363 363
 /**
@@ -368,24 +368,24 @@  discard block
 block discarded – undo
368 368
  * @return array
369 369
  */
370 370
 function editer_texte_recolle($texte, $att_text) {
371
-	if ((strlen($texte) < 29 * 1024)
372
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
373
-	) {
374
-		return array($texte, '');
375
-	}
376
-
377
-	include_spip('inc/barre');
378
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
379
-	$nombre = 0;
380
-
381
-	while (strlen($texte) > 29 * 1024) {
382
-		$nombre++;
383
-		list($texte1, $texte) = coupe_trop_long($texte);
384
-		$textes_supplement .= '<br />' .
385
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
386
-	}
387
-
388
-	return array($texte, $textes_supplement);
371
+    if ((strlen($texte) < 29 * 1024)
372
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
373
+    ) {
374
+        return array($texte, '');
375
+    }
376
+
377
+    include_spip('inc/barre');
378
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
379
+    $nombre = 0;
380
+
381
+    while (strlen($texte) > 29 * 1024) {
382
+        $nombre++;
383
+        list($texte1, $texte) = coupe_trop_long($texte);
384
+        $textes_supplement .= '<br />' .
385
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
386
+    }
387
+
388
+    return array($texte, $textes_supplement);
389 389
 }
390 390
 
391 391
 /**
@@ -396,17 +396,17 @@  discard block
 block discarded – undo
396 396
  * @param int $longueur
397 397
  */
398 398
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
399
-	if (!_request($champ_titre)) {
400
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
401
-		if (!is_null($longueur)) {
402
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
403
-		} else {
404
-			$t = $titrer_contenu($champs_contenu);
405
-		}
406
-		if ($t) {
407
-			set_request($champ_titre, $t);
408
-		}
409
-	}
399
+    if (!_request($champ_titre)) {
400
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
401
+        if (!is_null($longueur)) {
402
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
403
+        } else {
404
+            $t = $titrer_contenu($champs_contenu);
405
+        }
406
+        if ($t) {
407
+            set_request($champ_titre, $t);
408
+        }
409
+    }
410 410
 }
411 411
 
412 412
 /**
@@ -426,20 +426,20 @@  discard block
 block discarded – undo
426 426
  * @return string
427 427
  */
428 428
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
429
-	// trouver un champ texte non vide
430
-	$t = '';
431
-	foreach ($champs_contenu as $champ) {
432
-		if ($t = _request($champ, $c)) {
433
-			break;
434
-		}
435
-	}
436
-
437
-	if ($t) {
438
-		include_spip('inc/texte_mini');
439
-		$t = couper($t, $longueur, '...');
440
-	}
441
-
442
-	return $t;
429
+    // trouver un champ texte non vide
430
+    $t = '';
431
+    foreach ($champs_contenu as $champ) {
432
+        if ($t = _request($champ, $c)) {
433
+            break;
434
+        }
435
+    }
436
+
437
+    if ($t) {
438
+        include_spip('inc/texte_mini');
439
+        $t = couper($t, $longueur, '...');
440
+    }
441
+
442
+    return $t;
443 443
 }
444 444
 
445 445
 /**
@@ -462,30 +462,30 @@  discard block
 block discarded – undo
462 462
  *      - array sinon couples ('$prefixe$colonne => md5)
463 463
  **/
464 464
 function controles_md5($data, $prefixe = 'ctr_', $format = 'html') {
465
-	if (!is_array($data)) {
466
-		return false;
467
-	}
468
-
469
-	$ctr = array();
470
-	foreach ($data as $key => $val) {
471
-		$m = md5($val);
472
-		$k = $prefixe . $key;
473
-
474
-		switch ($format) {
475
-			case 'html':
476
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
477
-				break;
478
-			default:
479
-				$ctr[$k] = $m;
480
-				break;
481
-		}
482
-	}
483
-
484
-	if ($format == 'html') {
485
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
486
-	} else {
487
-		return $ctr;
488
-	}
465
+    if (!is_array($data)) {
466
+        return false;
467
+    }
468
+
469
+    $ctr = array();
470
+    foreach ($data as $key => $val) {
471
+        $m = md5($val);
472
+        $k = $prefixe . $key;
473
+
474
+        switch ($format) {
475
+            case 'html':
476
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
477
+                break;
478
+            default:
479
+                $ctr[$k] = $m;
480
+                break;
481
+        }
482
+    }
483
+
484
+    if ($format == 'html') {
485
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
486
+    } else {
487
+        return $ctr;
488
+    }
489 489
 }
490 490
 
491 491
 /**
@@ -524,79 +524,79 @@  discard block
 block discarded – undo
524 524
  *     - post : le contenu posté
525 525
  **/
526 526
 function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') {
527
-	include_spip('inc/filtres');
528
-
529
-	$table_objet = table_objet($type);
530
-	$spip_table_objet = table_objet_sql($type);
531
-	$trouver_table = charger_fonction('trouver_table', 'base');
532
-	$desc = $trouver_table($table_objet, $serveur);
533
-
534
-	// Appels incomplets (sans $c)
535
-	if (!is_array($c)) {
536
-		foreach ($desc['field'] as $champ => $ignore) {
537
-			if (_request($champ)) {
538
-				$c[$champ] = _request($champ);
539
-			}
540
-		}
541
-	}
542
-
543
-	// Securite : certaines variables ne sont jamais acceptees ici
544
-	// car elles ne relevent pas de autoriser(article, modifier) ;
545
-	// il faut passer par instituer_XX()
546
-	// TODO: faut-il passer ces variables interdites
547
-	// dans un fichier de description separe ?
548
-	unset($c['statut']);
549
-	unset($c['id_parent']);
550
-	unset($c['id_rubrique']);
551
-	unset($c['id_secteur']);
552
-
553
-	// Gerer les champs non vides
554
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
555
-		foreach ($options['nonvide'] as $champ => $sinon) {
556
-			if ($c[$champ] === '') {
557
-				$c[$champ] = $sinon;
558
-			}
559
-		}
560
-	}
561
-
562
-	// N'accepter que les champs qui existent
563
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
564
-	$champs = array();
565
-	foreach ($desc['field'] as $champ => $ignore) {
566
-		if (isset($c[$champ])) {
567
-			$champs[$champ] = $c[$champ];
568
-		}
569
-	}
570
-
571
-	// Nettoyer les valeurs
572
-	$champs = array_map('corriger_caracteres', $champs);
573
-
574
-	// Envoyer aux plugins
575
-	$champs = pipeline(
576
-		'pre_edition',
577
-		array(
578
-			'args' => array(
579
-				'table' => $spip_table_objet, // compatibilite
580
-				'table_objet' => $table_objet,
581
-				'spip_table_objet' => $spip_table_objet,
582
-				'type' => $type,
583
-				'id_objet' => $id,
584
-				'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
585
-				'action' => 'controler',
586
-				'serveur' => $serveur,
587
-			),
588
-			'data' => $champs
589
-		)
590
-	);
591
-
592
-	if (!$champs) {
593
-		return false;
594
-	}
595
-
596
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
597
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
598
-
599
-	return $conflits;
527
+    include_spip('inc/filtres');
528
+
529
+    $table_objet = table_objet($type);
530
+    $spip_table_objet = table_objet_sql($type);
531
+    $trouver_table = charger_fonction('trouver_table', 'base');
532
+    $desc = $trouver_table($table_objet, $serveur);
533
+
534
+    // Appels incomplets (sans $c)
535
+    if (!is_array($c)) {
536
+        foreach ($desc['field'] as $champ => $ignore) {
537
+            if (_request($champ)) {
538
+                $c[$champ] = _request($champ);
539
+            }
540
+        }
541
+    }
542
+
543
+    // Securite : certaines variables ne sont jamais acceptees ici
544
+    // car elles ne relevent pas de autoriser(article, modifier) ;
545
+    // il faut passer par instituer_XX()
546
+    // TODO: faut-il passer ces variables interdites
547
+    // dans un fichier de description separe ?
548
+    unset($c['statut']);
549
+    unset($c['id_parent']);
550
+    unset($c['id_rubrique']);
551
+    unset($c['id_secteur']);
552
+
553
+    // Gerer les champs non vides
554
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
555
+        foreach ($options['nonvide'] as $champ => $sinon) {
556
+            if ($c[$champ] === '') {
557
+                $c[$champ] = $sinon;
558
+            }
559
+        }
560
+    }
561
+
562
+    // N'accepter que les champs qui existent
563
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
564
+    $champs = array();
565
+    foreach ($desc['field'] as $champ => $ignore) {
566
+        if (isset($c[$champ])) {
567
+            $champs[$champ] = $c[$champ];
568
+        }
569
+    }
570
+
571
+    // Nettoyer les valeurs
572
+    $champs = array_map('corriger_caracteres', $champs);
573
+
574
+    // Envoyer aux plugins
575
+    $champs = pipeline(
576
+        'pre_edition',
577
+        array(
578
+            'args' => array(
579
+                'table' => $spip_table_objet, // compatibilite
580
+                'table_objet' => $table_objet,
581
+                'spip_table_objet' => $spip_table_objet,
582
+                'type' => $type,
583
+                'id_objet' => $id,
584
+                'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
585
+                'action' => 'controler',
586
+                'serveur' => $serveur,
587
+            ),
588
+            'data' => $champs
589
+        )
590
+    );
591
+
592
+    if (!$champs) {
593
+        return false;
594
+    }
595
+
596
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
597
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
598
+
599
+    return $conflits;
600 600
 }
601 601
 
602 602
 
@@ -626,63 +626,63 @@  discard block
 block discarded – undo
626 626
  *     - post : le contenu posté
627 627
  **/
628 628
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
629
-	$spip_table_objet = table_objet_sql($type);
630
-	$id_table_objet = id_table_objet($type);
631
-
632
-	// Controle des MD5 envoyes
633
-	// On elimine les donnees non modifiees par le formulaire (mais
634
-	// potentiellement modifiees entre temps par un autre utilisateur)
635
-	foreach ($champs as $key => $val) {
636
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
637
-			if (is_scalar($val) and $m == md5($val)) {
638
-				unset($champs[$key]);
639
-			}
640
-		}
641
-	}
642
-	if (!$champs) {
643
-		return;
644
-	}
645
-
646
-	// On veut savoir si notre modif va avoir un impact
647
-	// par rapport aux donnees contenues dans la base
648
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
649
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
650
-	$intact = true;
651
-	foreach ($champs as $ch => $val) {
652
-		$intact &= ($s[$ch] == $val);
653
-	}
654
-	if ($intact) {
655
-		return;
656
-	}
657
-
658
-	// Detection de conflits :
659
-	// On verifie si notre modif ne provient pas d'un formulaire
660
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
661
-	// on compare a ce qui est dans la base, et on bloque en cas
662
-	// de conflit.
663
-	$ctrh = $ctrq = $conflits = array();
664
-	foreach (array_keys($champs) as $key) {
665
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
666
-			$ctrh[$key] = $m;
667
-			$ctrq[] = $key;
668
-		}
669
-	}
670
-	if ($ctrq) {
671
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
672
-		foreach ($ctrh as $key => $m) {
673
-			if ($m != md5($ctrq[$key])
674
-				and $champs[$key] !== $ctrq[$key]
675
-			) {
676
-				$conflits[$key] = array(
677
-					'base' => $ctrq[$key],
678
-					'post' => $champs[$key]
679
-				);
680
-				unset($champs[$key]); # stocker quand meme les modifs ?
681
-			}
682
-		}
683
-	}
684
-
685
-	return $conflits;
629
+    $spip_table_objet = table_objet_sql($type);
630
+    $id_table_objet = id_table_objet($type);
631
+
632
+    // Controle des MD5 envoyes
633
+    // On elimine les donnees non modifiees par le formulaire (mais
634
+    // potentiellement modifiees entre temps par un autre utilisateur)
635
+    foreach ($champs as $key => $val) {
636
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
637
+            if (is_scalar($val) and $m == md5($val)) {
638
+                unset($champs[$key]);
639
+            }
640
+        }
641
+    }
642
+    if (!$champs) {
643
+        return;
644
+    }
645
+
646
+    // On veut savoir si notre modif va avoir un impact
647
+    // par rapport aux donnees contenues dans la base
648
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
649
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
650
+    $intact = true;
651
+    foreach ($champs as $ch => $val) {
652
+        $intact &= ($s[$ch] == $val);
653
+    }
654
+    if ($intact) {
655
+        return;
656
+    }
657
+
658
+    // Detection de conflits :
659
+    // On verifie si notre modif ne provient pas d'un formulaire
660
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
661
+    // on compare a ce qui est dans la base, et on bloque en cas
662
+    // de conflit.
663
+    $ctrh = $ctrq = $conflits = array();
664
+    foreach (array_keys($champs) as $key) {
665
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
666
+            $ctrh[$key] = $m;
667
+            $ctrq[] = $key;
668
+        }
669
+    }
670
+    if ($ctrq) {
671
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
672
+        foreach ($ctrh as $key => $m) {
673
+            if ($m != md5($ctrq[$key])
674
+                and $champs[$key] !== $ctrq[$key]
675
+            ) {
676
+                $conflits[$key] = array(
677
+                    'base' => $ctrq[$key],
678
+                    'post' => $champs[$key]
679
+                );
680
+                unset($champs[$key]); # stocker quand meme les modifs ?
681
+            }
682
+        }
683
+    }
684
+
685
+    return $conflits;
686 686
 }
687 687
 
688 688
 /**
@@ -694,11 +694,11 @@  discard block
 block discarded – undo
694 694
  * @return string
695 695
  */
696 696
 function display_conflit_champ($x) {
697
-	if (strstr($x, "\n") or strlen($x) > 80) {
698
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
699
-	} else {
700
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
701
-	}
697
+    if (strstr($x, "\n") or strlen($x) > 80) {
698
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
699
+    } else {
700
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
701
+    }
702 702
 }
703 703
 
704 704
 /**
@@ -716,57 +716,57 @@  discard block
 block discarded – undo
716 716
  * @return string
717 717
  */
718 718
 function signaler_conflits_edition($conflits, $redirect = '') {
719
-	include_spip('inc/minipres');
720
-	include_spip('inc/revisions');
721
-	include_spip('afficher_diff/champ');
722
-	include_spip('inc/suivi_versions');
723
-	include_spip('inc/diff');
724
-	$diffs = array();
725
-	foreach ($conflits as $champ => $a) {
726
-		// probleme de stockage ou conflit d'edition ?
727
-		$base = isset($a['save']) ? $a['save'] : $a['base'];
728
-
729
-		$diff = new Diff(new DiffTexte);
730
-		$n = preparer_diff($a['post']);
731
-		$o = preparer_diff($base);
732
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
733
-
734
-		$titre = isset($a['save']) ? _L(
735
-			'Echec lors de l\'enregistrement du champ @champ@',
736
-			array('champ' => $champ)
737
-		) : $champ;
738
-
739
-		$diffs[] = "<h2>$titre</h2>\n"
740
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
741
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
742
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
743
-			. display_conflit_champ($a['post'])
744
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
745
-			. display_conflit_champ($base);
746
-	}
747
-
748
-	if ($redirect) {
749
-		$id = uniqid(rand());
750
-		$redirect = "<form action='$redirect' method='get'
719
+    include_spip('inc/minipres');
720
+    include_spip('inc/revisions');
721
+    include_spip('afficher_diff/champ');
722
+    include_spip('inc/suivi_versions');
723
+    include_spip('inc/diff');
724
+    $diffs = array();
725
+    foreach ($conflits as $champ => $a) {
726
+        // probleme de stockage ou conflit d'edition ?
727
+        $base = isset($a['save']) ? $a['save'] : $a['base'];
728
+
729
+        $diff = new Diff(new DiffTexte);
730
+        $n = preparer_diff($a['post']);
731
+        $o = preparer_diff($base);
732
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
733
+
734
+        $titre = isset($a['save']) ? _L(
735
+            'Echec lors de l\'enregistrement du champ @champ@',
736
+            array('champ' => $champ)
737
+        ) : $champ;
738
+
739
+        $diffs[] = "<h2>$titre</h2>\n"
740
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
741
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
742
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
743
+            . display_conflit_champ($a['post'])
744
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
745
+            . display_conflit_champ($base);
746
+    }
747
+
748
+    if ($redirect) {
749
+        $id = uniqid(rand());
750
+        $redirect = "<form action='$redirect' method='get'
751 751
 			id='$id'
752 752
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
753
-			. form_hidden($redirect)
754
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
753
+            . form_hidden($redirect)
754
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
755 755
 		</form>\n";
756 756
 
757
-		// pour les documents, on est probablement en ajax : il faut ajaxer
758
-		if (_AJAX) {
759
-			$redirect .= '<script type="text/javascript">'
760
-				. 'setTimeout(function(){$("#' . $id . '")
757
+        // pour les documents, on est probablement en ajax : il faut ajaxer
758
+        if (_AJAX) {
759
+            $redirect .= '<script type="text/javascript">'
760
+                . 'setTimeout(function(){$("#' . $id . '")
761 761
 			.ajaxForm({target:$("#' . $id . '").parent()});
762 762
 			}, 200);'
763
-				. "</script>\n";
764
-		}
765
-	}
763
+                . "</script>\n";
764
+        }
765
+    }
766 766
 
767
-	echo minipres(
768
-		_T('titre_conflit_edition'),
769
-		'<style>
767
+    echo minipres(
768
+        _T('titre_conflit_edition'),
769
+        '<style>
770 770
 .diff-para-deplace { background: #e8e8ff; }
771 771
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
772 772
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -777,12 +777,12 @@  discard block
 block discarded – undo
777 777
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
778 778
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
779 779
 </style>'
780
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
781
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
782
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
783
-		. join("\n", $diffs)
784
-		. "</div>\n"
785
-
786
-		. $redirect
787
-	);
780
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
781
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
782
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
783
+        . join("\n", $diffs)
784
+        . "</div>\n"
785
+
786
+        . $redirect
787
+    );
788 788
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -35 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	// on accepte pas une fonction de config inconnue si elle vient d'un modele
216 216
 	if ($config_fonc
217 217
 	  and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
-	  and $config_fonc !== $table_objet . '_edit_config') {
218
+	  and $config_fonc !== $table_objet.'_edit_config') {
219 219
 		if ($args = test_formulaire_inclus_par_modele()
220 220
 		  and in_array($config_fonc, $args)) {
221 221
 			$config_fonc = '';
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	// Appel direct dans un squelette
228 228
 	if (!$row) {
229 229
 		if (!$new or $lier_trad) {
230
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
230
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
231 231
 				$row = $select($id, $id_parent, $lier_trad);
232 232
 				// si on a une fonction precharger, elle pu faire un reglage de langue
233 233
 				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234 234
 			} else {
235
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
235
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
236 236
 			}
237 237
 			if (!$new) {
238 238
 				$md5 = controles_md5($row);
@@ -305,13 +305,12 @@  discard block
 block discarded – undo
305 305
 		unset($contexte['lang']);
306 306
 	}
307 307
 
308
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
-		(!$lier_trad ? '' :
310
-			("\n<input type='hidden' name='lier_trad' value='" .
311
-				$lier_trad .
312
-				"' />" .
313
-				"\n<input type='hidden' name='changer_lang' value='" .
314
-				$lang_default .
308
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
309
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
310
+				$lier_trad.
311
+				"' />".
312
+				"\n<input type='hidden' name='changer_lang' value='".
313
+				$lang_default.
315 314
 				"' />"))
316 315
 		. $hidden
317 316
 		. (isset($md5) ? $md5 : '');
@@ -338,14 +337,14 @@  discard block
 block discarded – undo
338 337
 	$aider = charger_fonction('aider', 'inc');
339 338
 	if (strlen($texte) > 28 * 1024) {
340 339
 		$texte = str_replace("\r\n", "\n", $texte);
341
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
340
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
342 341
 		if ($pos > 0 and $pos < 32 * 1024) {
343
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
342
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
344 343
 			$suite = substr($texte, $pos + 2);
345 344
 		} else {
346
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
345
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
347 346
 			if (!($pos > 0 and $pos < 32 * 1024)) {
348
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
347
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
349 348
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
350 349
 			} else {
351 350
 				$decalage = 1;
@@ -375,13 +374,13 @@  discard block
 block discarded – undo
375 374
 	}
376 375
 
377 376
 	include_spip('inc/barre');
378
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
377
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
379 378
 	$nombre = 0;
380 379
 
381 380
 	while (strlen($texte) > 29 * 1024) {
382 381
 		$nombre++;
383 382
 		list($texte1, $texte) = coupe_trop_long($texte);
384
-		$textes_supplement .= '<br />' .
383
+		$textes_supplement .= '<br />'.
385 384
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
386 385
 	}
387 386
 
@@ -469,7 +468,7 @@  discard block
 block discarded – undo
469 468
 	$ctr = array();
470 469
 	foreach ($data as $key => $val) {
471 470
 		$m = md5($val);
472
-		$k = $prefixe . $key;
471
+		$k = $prefixe.$key;
473 472
 
474 473
 		switch ($format) {
475 474
 			case 'html':
@@ -482,7 +481,7 @@  discard block
 block discarded – undo
482 481
 	}
483 482
 
484 483
 	if ($format == 'html') {
485
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
484
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
486 485
 	} else {
487 486
 		return $ctr;
488 487
 	}
@@ -633,7 +632,7 @@  discard block
 block discarded – undo
633 632
 	// On elimine les donnees non modifiees par le formulaire (mais
634 633
 	// potentiellement modifiees entre temps par un autre utilisateur)
635 634
 	foreach ($champs as $key => $val) {
636
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
635
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
637 636
 			if (is_scalar($val) and $m == md5($val)) {
638 637
 				unset($champs[$key]);
639 638
 			}
@@ -662,7 +661,7 @@  discard block
 block discarded – undo
662 661
 	// de conflit.
663 662
 	$ctrh = $ctrq = $conflits = array();
664 663
 	foreach (array_keys($champs) as $key) {
665
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
664
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
666 665
 			$ctrh[$key] = $m;
667 666
 			$ctrq[] = $key;
668 667
 		}
@@ -695,9 +694,9 @@  discard block
 block discarded – undo
695 694
  */
696 695
 function display_conflit_champ($x) {
697 696
 	if (strstr($x, "\n") or strlen($x) > 80) {
698
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
697
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
699 698
 	} else {
700
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
699
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
701 700
 	}
702 701
 }
703 702
 
@@ -737,11 +736,11 @@  discard block
 block discarded – undo
737 736
 		) : $champ;
738 737
 
739 738
 		$diffs[] = "<h2>$titre</h2>\n"
740
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
741
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
742
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
739
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
740
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
741
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
743 742
 			. display_conflit_champ($a['post'])
744
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
743
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
745 744
 			. display_conflit_champ($base);
746 745
 	}
747 746
 
@@ -749,16 +748,16 @@  discard block
 block discarded – undo
749 748
 		$id = uniqid(rand());
750 749
 		$redirect = "<form action='$redirect' method='get'
751 750
 			id='$id'
752
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
751
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
753 752
 			. form_hidden($redirect)
754
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
753
+			. "<input type='submit' value='"._T('icone_retour')."' />
755 754
 		</form>\n";
756 755
 
757 756
 		// pour les documents, on est probablement en ajax : il faut ajaxer
758 757
 		if (_AJAX) {
759 758
 			$redirect .= '<script type="text/javascript">'
760
-				. 'setTimeout(function(){$("#' . $id . '")
761
-			.ajaxForm({target:$("#' . $id . '").parent()});
759
+				. 'setTimeout(function(){$("#'.$id.'")
760
+			.ajaxForm({target:$("#' . $id.'").parent()});
762 761
 			}, 200);'
763 762
 				. "</script>\n";
764 763
 		}
@@ -777,9 +776,9 @@  discard block
 block discarded – undo
777 776
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
778 777
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
779 778
 </style>'
780
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
781
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
782
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
779
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
780
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
781
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
783 782
 		. join("\n", $diffs)
784 783
 		. "</div>\n"
785 784
 
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -187,7 +187,7 @@
 block discarded – undo
187 187
  * @param string $to
188 188
  * @param string $texte
189 189
  * @param string $parts
190
- * @return array
190
+ * @return string[]
191 191
  */
192 192
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
193 193
 	$charset = $GLOBALS['meta']['charset'];
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136 136
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
137
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')';
138 138
 	}
139 139
 
140 140
 	// nettoyer les &eacute; &#8217, &emdash; etc...
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		if (!_TEST_EMAIL_DEST) {
172 172
 			return false;
173 173
 		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
174
+			$texte = "Dest : $destinataire\r\n".$texte;
175 175
 			$destinataire = _TEST_EMAIL_DEST;
176 176
 		}
177 177
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
196 196
 	if (strpos($headers, 'Content-Type: ') === false) {
197 197
 		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
198
+			"Content-Type: text/plain;charset=\"$charset\";\n".
199 199
 			"Content-Transfer-Encoding: 8bit\n";
200 200
 	} else {
201 201
 		$type = '';
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
 
204 204
 	// calculer un identifiant unique
205 205
 	preg_match('/@\S+/', $from, $domain);
206
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
206
+	$uniq = rand().'_'.md5($to.$texte).$domain[0];
207 207
 
208 208
 	// Si multi-part, s'en servir comme borne ...
209 209
 	if ($parts) {
210
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
210
+		$texte = "--$uniq\n$type\n".$texte."\n";
211 211
 		foreach ($parts as $part) {
212
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
212
+			$n = strlen($part[1]).($part[0] ? "\n" : '');
213 213
 			$e = join("\n", $part[0]);
214
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
215 215
 		}
216 216
 		$texte .= "\n\n--$uniq--\n";
217 217
 		// Si boundary n'est pas entre guillemets,
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 	// .. et s'en servir pour plaire a SpamAssassin
223 223
 
224
-	$mid = 'Message-Id: <' . $uniq . '>';
224
+	$mid = 'Message-Id: <'.$uniq.'>';
225 225
 
226 226
 	// indispensable pour les sites qui collent d'office From: serveur-http
227 227
 	// sauf si deja mis par l'envoyeur
Please login to merge, or discard this patch.
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Mail
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function nettoyer_titre_email($titre) {
35
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
36 36
 }
37 37
 
38 38
 /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function nettoyer_caracteres_mail($t) {
50 50
 
51
-	$t = filtrer_entites($t);
51
+    $t = filtrer_entites($t);
52 52
 
53
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
-		$t = str_replace(
55
-			array('&#8217;', '&#8220;', '&#8221;'),
56
-			array("'", '"', '"'),
57
-			$t
58
-		);
59
-	}
53
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
+        $t = str_replace(
55
+            array('&#8217;', '&#8220;', '&#8221;'),
56
+            array("'", '"', '"'),
57
+            $t
58
+        );
59
+    }
60 60
 
61
-	$t = str_replace(
62
-		array('&mdash;', '&endash;'),
63
-		array('--', '-'),
64
-		$t
65
-	);
61
+    $t = str_replace(
62
+        array('&mdash;', '&endash;'),
63
+        array('--', '-'),
64
+        $t
65
+    );
66 66
 
67
-	return $t;
67
+    return $t;
68 68
 }
69 69
 
70 70
 /**
@@ -97,86 +97,86 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
99 99
 
100
-	if (!email_valide($destinataire)) {
101
-		return false;
102
-	}
103
-	if ($destinataire == _T('info_mail_fournisseur')) {
104
-		return false;
105
-	} // tres fort
106
-
107
-	// Fournir si possible un Message-Id: conforme au RFC1036,
108
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
-
110
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
111
-	if (!email_valide($email_envoi)) {
112
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
-		$email_envoi = $destinataire;
114
-	}
115
-
116
-	$parts = '';
117
-	if (is_array($corps)) {
118
-		$texte = $corps['texte'];
119
-		$from = (isset($corps['from']) ? $corps['from'] : $from);
120
-		$headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
-		if (is_array($headers)) {
122
-			$headers = implode("\n", $headers);
123
-		}
124
-		if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
-		}
127
-	} else {
128
-		$texte = $corps;
129
-	}
130
-
131
-	if (!$from) {
132
-		$from = $email_envoi;
133
-	}
134
-
135
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
-	}
139
-
140
-	// nettoyer les &eacute; &#8217, &emdash; etc...
141
-	// les 'cliquer ici' etc sont a eviter;  voir:
142
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
-	$texte = nettoyer_caracteres_mail($texte);
144
-	$sujet = nettoyer_caracteres_mail($sujet);
145
-
146
-	// encoder le sujet si possible selon la RFC
147
-	if (init_mb_string()) {
148
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
-		$charset = $GLOBALS['meta']['charset'];
151
-		mb_internal_encoding($charset);
152
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
-		mb_internal_encoding('utf-8');
154
-	}
155
-
156
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
-		$texte = wordwrap($texte);
158
-	}
159
-
160
-	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
-
162
-	if (_OS_SERVEUR == 'windows') {
163
-		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
-		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
-	}
167
-
168
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
-	// mode TEST : forcer l'email
170
-	if (defined('_TEST_EMAIL_DEST')) {
171
-		if (!_TEST_EMAIL_DEST) {
172
-			return false;
173
-		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
175
-			$destinataire = _TEST_EMAIL_DEST;
176
-		}
177
-	}
178
-
179
-	return @mail($destinataire, $sujet, $texte, $headers);
100
+    if (!email_valide($destinataire)) {
101
+        return false;
102
+    }
103
+    if ($destinataire == _T('info_mail_fournisseur')) {
104
+        return false;
105
+    } // tres fort
106
+
107
+    // Fournir si possible un Message-Id: conforme au RFC1036,
108
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
+
110
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
111
+    if (!email_valide($email_envoi)) {
112
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
+        $email_envoi = $destinataire;
114
+    }
115
+
116
+    $parts = '';
117
+    if (is_array($corps)) {
118
+        $texte = $corps['texte'];
119
+        $from = (isset($corps['from']) ? $corps['from'] : $from);
120
+        $headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
+        if (is_array($headers)) {
122
+            $headers = implode("\n", $headers);
123
+        }
124
+        if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
+        }
127
+    } else {
128
+        $texte = $corps;
129
+    }
130
+
131
+    if (!$from) {
132
+        $from = $email_envoi;
133
+    }
134
+
135
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
+    }
139
+
140
+    // nettoyer les &eacute; &#8217, &emdash; etc...
141
+    // les 'cliquer ici' etc sont a eviter;  voir:
142
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
+    $texte = nettoyer_caracteres_mail($texte);
144
+    $sujet = nettoyer_caracteres_mail($sujet);
145
+
146
+    // encoder le sujet si possible selon la RFC
147
+    if (init_mb_string()) {
148
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
+        $charset = $GLOBALS['meta']['charset'];
151
+        mb_internal_encoding($charset);
152
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
+        mb_internal_encoding('utf-8');
154
+    }
155
+
156
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
+        $texte = wordwrap($texte);
158
+    }
159
+
160
+    list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
+
162
+    if (_OS_SERVEUR == 'windows') {
163
+        $texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
+        $headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
+    }
167
+
168
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
+    // mode TEST : forcer l'email
170
+    if (defined('_TEST_EMAIL_DEST')) {
171
+        if (!_TEST_EMAIL_DEST) {
172
+            return false;
173
+        } else {
174
+            $texte = "Dest : $destinataire\r\n" . $texte;
175
+            $destinataire = _TEST_EMAIL_DEST;
176
+        }
177
+    }
178
+
179
+    return @mail($destinataire, $sujet, $texte, $headers);
180 180
 }
181 181
 
182 182
 /**
@@ -190,52 +190,52 @@  discard block
 block discarded – undo
190 190
  * @return array
191 191
  */
192 192
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
193
-	$charset = $GLOBALS['meta']['charset'];
194
-
195
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
196
-	if (strpos($headers, 'Content-Type: ') === false) {
197
-		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
199
-			"Content-Transfer-Encoding: 8bit\n";
200
-	} else {
201
-		$type = '';
202
-	}
203
-
204
-	// calculer un identifiant unique
205
-	preg_match('/@\S+/', $from, $domain);
206
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
207
-
208
-	// Si multi-part, s'en servir comme borne ...
209
-	if ($parts) {
210
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
211
-		foreach ($parts as $part) {
212
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
213
-			$e = join("\n", $part[0]);
214
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
215
-		}
216
-		$texte .= "\n\n--$uniq--\n";
217
-		// Si boundary n'est pas entre guillemets,
218
-		// elle est comprise mais le charset est ignoree !
219
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
220
-	}
221
-
222
-	// .. et s'en servir pour plaire a SpamAssassin
223
-
224
-	$mid = 'Message-Id: <' . $uniq . '>';
225
-
226
-	// indispensable pour les sites qui collent d'office From: serveur-http
227
-	// sauf si deja mis par l'envoyeur
228
-	$rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
229
-
230
-	// Nettoyer les en-tetes envoyees
231
-	// Ajouter le \n final
232
-	if (strlen($headers = trim($headers))) {
233
-		$headers .= "\n";
234
-	}
235
-
236
-	// Et mentionner l'indeboulonable nomenclature ratee
237
-
238
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
239
-
240
-	return array($headers, $texte);
193
+    $charset = $GLOBALS['meta']['charset'];
194
+
195
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
196
+    if (strpos($headers, 'Content-Type: ') === false) {
197
+        $type =
198
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
199
+            "Content-Transfer-Encoding: 8bit\n";
200
+    } else {
201
+        $type = '';
202
+    }
203
+
204
+    // calculer un identifiant unique
205
+    preg_match('/@\S+/', $from, $domain);
206
+    $uniq = rand() . '_' . md5($to . $texte) . $domain[0];
207
+
208
+    // Si multi-part, s'en servir comme borne ...
209
+    if ($parts) {
210
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
211
+        foreach ($parts as $part) {
212
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
213
+            $e = join("\n", $part[0]);
214
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
215
+        }
216
+        $texte .= "\n\n--$uniq--\n";
217
+        // Si boundary n'est pas entre guillemets,
218
+        // elle est comprise mais le charset est ignoree !
219
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
220
+    }
221
+
222
+    // .. et s'en servir pour plaire a SpamAssassin
223
+
224
+    $mid = 'Message-Id: <' . $uniq . '>';
225
+
226
+    // indispensable pour les sites qui collent d'office From: serveur-http
227
+    // sauf si deja mis par l'envoyeur
228
+    $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
229
+
230
+    // Nettoyer les en-tetes envoyees
231
+    // Ajouter le \n final
232
+    if (strlen($headers = trim($headers))) {
233
+        $headers .= "\n";
234
+    }
235
+
236
+    // Et mentionner l'indeboulonable nomenclature ratee
237
+
238
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
239
+
240
+    return array($headers, $texte);
241 241
 }
Please login to merge, or discard this patch.
ecrire/inc/plugin.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -623,11 +623,11 @@
 block discarded – undo
623 623
  * 
624 624
  * @param $liste
625 625
  *    Liste de description des plugins
626
- * @param $nom
626
+ * @param string $nom
627 627
  *    Le plugin donc on cherche la presence
628 628
  * @param $intervalle
629 629
  *    L'éventuelle intervalle de compatibilité de la dépendance. ex: [1.1.0;]
630
- * @param $balise
630
+ * @param string $balise
631 631
  *    Permet de définir si on teste un utilise ou un nécessite
632 632
  * @return string.
633 633
  *    Vide si ok,
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 /** l'adresse du repertoire de telechargement et de decompactage des plugins */
24 24
 if (!defined('_DIR_PLUGINS_AUTO')) {
25
-	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
25
+	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/');
26 26
 }
27 27
 
28 28
 #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins.
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				if ($dir) {
371 371
 					$dir .= "/";
372 372
 				}
373
-				$dir .= "procure:" . $procure['nom'];
373
+				$dir .= "procure:".$procure['nom'];
374 374
 
375 375
 				$procure['etat'] = '?';
376 376
 				$procure['dir_type'] = $resume['dir_type'];
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 		$plug = $resume['dir'];
552 552
 		$k = $infos[$dir_type][$plug];
553 553
 
554
-		$plug = constant($dir_type) . $plug;
554
+		$plug = constant($dir_type).$plug;
555 555
 		if (!isset($msg[$p])) {
556 556
 			if (isset($resume['erreur']) and $resume['erreur']) {
557 557
 				$msg[$p] = array($resume['erreur']);
@@ -594,10 +594,10 @@  discard block
 block discarded – undo
594 594
 		$list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595 595
 	} elseif (!$raw) {
596 596
 		foreach ($list as $plug => $msg) {
597
-			$list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
-				. "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
597
+			$list[$plug] = "<li>"._T('plugin_impossible_activer', array('plugin' => $plug))
598
+				. "<ul><li>".implode("</li><li>", $msg)."</li></ul></li>";
599 599
 		}
600
-		$list = "<ul>" . join("\n", $list) . "</ul>";
600
+		$list = "<ul>".join("\n", $list)."</ul>";
601 601
 	}
602 602
 	if ($raz) {
603 603
 		effacer_meta('plugin_erreur_activation');
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
 			if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709 709
 				return _T("plugin_${balise}_${type}", array(
710 710
 					'plugin' => $nom,
711
-					'version' => ' &ge; ' . $minimum
711
+					'version' => ' &ge; '.$minimum
712 712
 				));
713 713
 			}
714 714
 			if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715 715
 				return _T("plugin_${balise}_${type}", array(
716 716
 					'plugin' => $nom,
717
-					'version' => ' &gt; ' . $minimum
717
+					'version' => ' &gt; '.$minimum
718 718
 				));
719 719
 			}
720 720
 		}
@@ -723,13 +723,13 @@  discard block
 block discarded – undo
723 723
 			if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724 724
 				return _T("plugin_${balise}_${type}", array(
725 725
 					'plugin' => $nom,
726
-					'version' => ' &le; ' . $maximum
726
+					'version' => ' &le; '.$maximum
727 727
 				));
728 728
 			}
729 729
 			if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730 730
 				return _T("plugin_${balise}_plugin", array(
731 731
 					'plugin' => $nom,
732
-					'version' => ' &lt; ' . $maximum
732
+					'version' => ' &lt; '.$maximum
733 733
 				));
734 734
 			}
735 735
 		}
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 		include_spip('inc/charger_plugin');
749 749
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
750 750
 	}*/
751
-	return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
751
+	return _T('plugin_necessite_lib', array('lib' => $lib))." <a href='$url'>$url</a>";
752 752
 }
753 753
 
754 754
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	foreach ($plugin_valides as $p => $resume) {
848 848
 		// Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849 849
 		if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
-			$header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
850
+			$header[] = $p.($resume['version'] ? "(".$resume['version'].")" : "");
851 851
 		}
852 852
 		if ($resume['dir']) {
853 853
 			foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
@@ -871,10 +871,10 @@  discard block
 block discarded – undo
871 871
 	ecrire_meta('plugin_attente', serialize($liste));
872 872
 	$header = strtolower(implode(",", $header));
873 873
 	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
-		ecrire_fichier(_DIR_VAR . "config.txt",
875
-			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
874
+		ecrire_fichier(_DIR_VAR."config.txt",
875
+			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP").' '.$GLOBALS['spip_version_affichee']." @ www.spip.net + ".$header);
876 876
 	} else {
877
-		@unlink(_DIR_VAR . "config.txt");
877
+		@unlink(_DIR_VAR."config.txt");
878 878
 	}
879 879
 	// generer charger_plugins_chemin.php
880 880
 	plugins_precompile_chemin($plugin_valides, $ordre);
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 			// definir le plugin, donc le path avant l'include du fichier options
926 926
 			// permet de faire des include_spip pour attraper un inc_ du plugin
927 927
 
928
-			$dir = $dir_type . ".'" . $plug . "/'";
928
+			$dir = $dir_type.".'".$plug."/'";
929 929
 
930 930
 			$prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931 931
 			if (
@@ -945,13 +945,13 @@  discard block
 block discarded – undo
945 945
 							$dir = '';
946 946
 						}
947 947
 						if (strlen($dir)) {
948
-							$dir = rtrim($dir, '/') . '/';
948
+							$dir = rtrim($dir, '/').'/';
949 949
 						}
950 950
 						if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
-							$chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
951
+							$chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
952 952
 						}
953 953
 						if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
-							$chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
954
+							$chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
955 955
 						}
956 956
 					}
957 957
 				}
@@ -959,9 +959,9 @@  discard block
 block discarded – undo
959 959
 		}
960 960
 	}
961 961
 	if (count($chemins)) {
962
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
-				array_reverse($chemins['public'])) . ")));\n"
964
-			. "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
962
+		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',',
963
+				array_reverse($chemins['public'])).")));\n"
964
+			. "else _chemin(implode(':',array(".implode(',', array_reverse($chemins['prive'])).")));\n";
965 965
 	}
966 966
 
967 967
 	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 					and strpos($dir, ":") === false // exclure le cas des procure:
1010 1010
 					and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011 1011
 				) {
1012
-					if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1012
+					if (is_readable("$dir$plug/".($file = $info['prefix']."_".$charge.".php"))) {
1013 1013
 						$info[$charge] = array($file);
1014 1014
 					}
1015 1015
 				}
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 						) {
1026 1026
 							unset($info[$charge][$k]);
1027 1027
 						} else {
1028
-							$_file = $root_dir_type . ".'$plug/$file'";
1028
+							$_file = $root_dir_type.".'$plug/$file'";
1029 1029
 							$contenu[$charge] .= "include_once_check($_file);\n";
1030 1030
 						}
1031 1031
 					}
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 		}
1036 1036
 	}
1037 1037
 
1038
-	$contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1038
+	$contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options'];
1039 1039
 	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040 1040
 		. plugin_ongletbouton("onglets_plugins", $onglets);
1041 1041
 
@@ -1070,12 +1070,12 @@  discard block
 block discarded – undo
1070 1070
 		define("_UPDATED_$nom", $val);
1071 1071
 		define("_UPDATED_md5_$nom", $md5);
1072 1072
 	}
1073
-	$val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1073
+	$val = "unserialize('".str_replace("'", "\'", $val)."')";
1074 1074
 
1075 1075
 	return
1076 1076
 		"if (!function_exists('$nom')) {\n"
1077 1077
 		. "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
-		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1078
+		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n"
1079 1079
 		. "}\n";
1080 1080
 }
1081 1081
 
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 	if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099 1099
 		include_once(_CACHE_PLUGINS_OPT);
1100 1100
 	} else {
1101
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1101
+		spip_log("pipelines desactives: impossible de produire "._CACHE_PLUGINS_OPT);
1102 1102
 	}
1103 1103
 }
1104 1104
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 			$dir_type = $plugin_valides[$p]['dir_type'];
1136 1136
 			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137 1137
 			$plug = $plugin_valides[$p]['dir'];
1138
-			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1138
+			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix']."_");
1139 1139
 			if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140 1140
 				foreach ($info['pipeline'] as $pipe) {
1141 1141
 					$nom = $pipe['nom'];
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 						}
1166 1166
 						if (isset($pipe['inclure'])) {
1167 1167
 							$GLOBALS['spip_matrice']["$prefix$action"] =
1168
-								"$root_dir_type:$plug/" . $pipe['inclure'];
1168
+								"$root_dir_type:$plug/".$pipe['inclure'];
1169 1169
 						}
1170 1170
 					}
1171 1171
 				}
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
 					$prepend_code['taches_generales_cron'] = "";
1176 1176
 				}
1177 1177
 				foreach ($info['genie'] as $genie) {
1178
-					$nom = $prefix . $genie['nom'];
1178
+					$nom = $prefix.$genie['nom'];
1179 1179
 					$periode = max(60, intval($genie['periode']));
1180 1180
 					if (charger_fonction($nom, "genie", true)) {
1181 1181
 						$prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
@@ -1193,13 +1193,13 @@  discard block
 block discarded – undo
1193 1193
 				}
1194 1194
 				foreach ($info['style'] as $style) {
1195 1195
 					if (isset($style['path']) and $style['path']) {
1196
-						$code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1196
+						$code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) ";
1197 1197
 					} else {
1198
-						$code = "if (\$f='" . addslashes($style['url']) . "') ";
1198
+						$code = "if (\$f='".addslashes($style['url'])."') ";
1199 1199
 					}
1200 1200
 					$code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201 1201
 					if (isset($style['media']) and strlen($style['media'])) {
1202
-						$code .= " media=\"" . addslashes($style['media']) . "\"";
1202
+						$code .= " media=\"".addslashes($style['media'])."\"";
1203 1203
 					}
1204 1204
 					$code .= "/>';\n";
1205 1205
 					if ($style['type'] != 'prive') {
@@ -1219,9 +1219,9 @@  discard block
 block discarded – undo
1219 1219
 			if (isset($info['script']) and count($info['script'])) {
1220 1220
 				foreach ($info['script'] as $script) {
1221 1221
 					if (isset($script['path']) and $script['path']) {
1222
-						$code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1222
+						$code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) ";
1223 1223
 					} else {
1224
-						$code = "if (\$f='" . addslashes($script['url']) . "') ";
1224
+						$code = "if (\$f='".addslashes($script['url'])."') ";
1225 1225
 					}
1226 1226
 					$code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227 1227
 					if ($script['type'] != 'prive') {
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 		// Eclater le pipeline en filtres et appliquer chaque filtre
1287 1287
 		foreach ($pipe as $fonc) {
1288 1288
 			$fonc = trim($fonc);
1289
-			$s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1289
+			$s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n";
1290 1290
 			if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291 1291
 				$file = $GLOBALS['spip_matrice'][$fonc];
1292 1292
 				$file = "'$file'";
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 					if (defined($root_dir)) {
1298 1298
 						$dir = $root_dir;
1299 1299
 					}
1300
-					$file = str_replace($regs[0], "'." . $dir . ".'", $file);
1300
+					$file = str_replace($regs[0], "'.".$dir.".'", $file);
1301 1301
 					$file = str_replace("''.", "", $file);
1302 1302
 					$file = str_replace(constant($dir), '', $file);
1303 1303
 				}
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		$content .= "// Pipeline $action \n"
1311 1311
 			. "function execute_pipeline_$action(&\$val){\n"
1312 1312
 			. $s_inc
1313
-			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1313
+			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '')
1314 1314
 			. $s_call
1315 1315
 			. "return \$val;\n}\n";
1316 1316
 	}
@@ -1394,18 +1394,18 @@  discard block
 block discarded – undo
1394 1394
 		$GLOBALS['fichier_php_compile_recent'] = 0;
1395 1395
 	}
1396 1396
 
1397
-	$contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1397
+	$contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>';
1398 1398
 	// si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399 1399
 	// si pas de modif on ne touche pas au fichier initial
1400 1400
 	if (file_exists($nom)) {
1401 1401
 		if (substr($nom, -4) == '.php') {
1402
-			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1402
+			$fichier_tmp = substr($nom, 0, -4).'.tmp.php';
1403 1403
 		}
1404 1404
 		else {
1405
-			$fichier_tmp = $nom . '.tmp';
1405
+			$fichier_tmp = $nom.'.tmp';
1406 1406
 		}
1407 1407
 		file_put_contents($fichier_tmp, $contenu);
1408
-		if(md5_file($nom) == md5_file($fichier_tmp)) {
1408
+		if (md5_file($nom) == md5_file($fichier_tmp)) {
1409 1409
 			$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410 1410
 			@unlink($fichier_tmp);
1411 1411
 			return;
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -555,11 +555,9 @@  discard block
 block discarded – undo
555 555
 		if (!isset($msg[$p])) {
556 556
 			if (isset($resume['erreur']) and $resume['erreur']) {
557 557
 				$msg[$p] = array($resume['erreur']);
558
-			}
559
-			elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
558
+			} elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560 559
 				$msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
-			}
562
-			elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
560
+			} elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563 561
 				$msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564 562
 			}
565 563
 		} else {
@@ -1154,10 +1152,12 @@  discard block
 block discarded – undo
1154 1152
 					}
1155 1153
 					$nom = $nomlower;
1156 1154
 					// une action vide est une declaration qui ne doit pas etre compilee !
1157
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1155
+					if (!isset($GLOBALS['spip_pipeline'][$nom])) {
1156
+					    // creer le pipeline eventuel
1158 1157
 					{
1159 1158
 						$GLOBALS['spip_pipeline'][$nom] = "";
1160 1159
 					}
1160
+					}
1161 1161
 					if ($action) {
1162 1162
 						if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163 1163
 							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
@@ -1400,8 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	if (file_exists($nom)) {
1401 1401
 		if (substr($nom, -4) == '.php') {
1402 1402
 			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
-		}
1404
-		else {
1403
+		} else {
1405 1404
 			$fichier_tmp = $nom . '.tmp';
1406 1405
 		}
1407 1406
 		file_put_contents($fichier_tmp, $contenu);
Please login to merge, or discard this patch.
Indentation   +913 added lines, -913 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
 /** l'adresse du repertoire de telechargement et de decompactage des plugins */
24 24
 if (!defined('_DIR_PLUGINS_AUTO')) {
25
-	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
25
+    define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
26 26
 }
27 27
 
28 28
 #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins.
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
  * @return array
48 48
 **/
49 49
 function liste_plugin_files($dir_plugins = null) {
50
-	static $plugin_files = array();
51
-	if (is_null($dir_plugins)) {
52
-		$dir_plugins = _DIR_PLUGINS;
53
-	}
54
-	if (!isset($plugin_files[$dir_plugins])
55
-		or count($plugin_files[$dir_plugins]) == 0
56
-	) {
57
-		$plugin_files[$dir_plugins] = array();
58
-		foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
59
-			$plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins));
60
-		}
61
-
62
-		sort($plugin_files[$dir_plugins]);
63
-		// et on lit le XML de tous les plugins pour le mettre en cache
64
-		// et en profiter pour nettoyer ceux qui n'existent plus du cache
65
-		$get_infos = charger_fonction('get_infos', 'plugins');
66
-		$get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true);
67
-	}
68
-
69
-	return $plugin_files[$dir_plugins];
50
+    static $plugin_files = array();
51
+    if (is_null($dir_plugins)) {
52
+        $dir_plugins = _DIR_PLUGINS;
53
+    }
54
+    if (!isset($plugin_files[$dir_plugins])
55
+        or count($plugin_files[$dir_plugins]) == 0
56
+    ) {
57
+        $plugin_files[$dir_plugins] = array();
58
+        foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
59
+            $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins));
60
+        }
61
+
62
+        sort($plugin_files[$dir_plugins]);
63
+        // et on lit le XML de tous les plugins pour le mettre en cache
64
+        // et en profiter pour nettoyer ceux qui n'existent plus du cache
65
+        $get_infos = charger_fonction('get_infos', 'plugins');
66
+        $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true);
67
+    }
68
+
69
+    return $plugin_files[$dir_plugins];
70 70
 }
71 71
 
72 72
 /**
@@ -82,44 +82,44 @@  discard block
 block discarded – undo
82 82
  *     Liste complète des répeertoires
83 83
 **/
84 84
 function fast_find_plugin_dirs($dir, $max_prof = 100) {
85
-	$fichiers = array();
86
-	// revenir au repertoire racine si on a recu dossier/truc
87
-	// pour regarder dossier/truc/ ne pas oublier le / final
88
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
89
-	if ($dir == '') {
90
-		$dir = '.';
91
-	}
92
-
93
-	if (!is_dir($dir)) {
94
-		return $fichiers;
95
-	}
96
-	if (is_plugin_dir($dir, '')) {
97
-		$fichiers[] = $dir;
98
-
99
-		return $fichiers;
100
-	}
101
-	if ($max_prof <= 0) {
102
-		return $fichiers;
103
-	}
104
-
105
-	$subdirs = array();
106
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
107
-		while (($f = readdir($d)) !== false) {
108
-			if ($f[0] != '.' # ignorer . .. .svn etc
109
-				and $f != 'CVS'
110
-				and is_dir($f = "$dir/$f")
111
-			) {
112
-				$subdirs[] = $f;
113
-			}
114
-		}
115
-		closedir($d);
116
-	}
117
-
118
-	foreach ($subdirs as $d) {
119
-		$fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1));
120
-	}
121
-
122
-	return $fichiers;
85
+    $fichiers = array();
86
+    // revenir au repertoire racine si on a recu dossier/truc
87
+    // pour regarder dossier/truc/ ne pas oublier le / final
88
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
89
+    if ($dir == '') {
90
+        $dir = '.';
91
+    }
92
+
93
+    if (!is_dir($dir)) {
94
+        return $fichiers;
95
+    }
96
+    if (is_plugin_dir($dir, '')) {
97
+        $fichiers[] = $dir;
98
+
99
+        return $fichiers;
100
+    }
101
+    if ($max_prof <= 0) {
102
+        return $fichiers;
103
+    }
104
+
105
+    $subdirs = array();
106
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
107
+        while (($f = readdir($d)) !== false) {
108
+            if ($f[0] != '.' # ignorer . .. .svn etc
109
+                and $f != 'CVS'
110
+                and is_dir($f = "$dir/$f")
111
+            ) {
112
+                $subdirs[] = $f;
113
+            }
114
+        }
115
+        closedir($d);
116
+    }
117
+
118
+    foreach ($subdirs as $d) {
119
+        $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1));
120
+    }
121
+
122
+    return $fichiers;
123 123
 }
124 124
 
125 125
 /**
@@ -140,27 +140,27 @@  discard block
 block discarded – undo
140 140
 **/
141 141
 function is_plugin_dir($dir, $dir_plugins = null) {
142 142
 
143
-	if (is_array($dir)) {
144
-		foreach ($dir as $k => $d) {
145
-			if (!is_plugin_dir($d, $dir_plugins)) {
146
-				unset($dir[$k]);
147
-			}
148
-		}
149
-
150
-		return $dir;
151
-	}
152
-	if (is_null($dir_plugins)) {
153
-		$dir_plugins = _DIR_PLUGINS;
154
-	}
155
-	$search = array("$dir_plugins$dir/paquet.xml");
156
-
157
-	foreach ($search as $s) {
158
-		if (file_exists($s)) {
159
-			return $dir;
160
-		}
161
-	}
162
-
163
-	return '';
143
+    if (is_array($dir)) {
144
+        foreach ($dir as $k => $d) {
145
+            if (!is_plugin_dir($d, $dir_plugins)) {
146
+                unset($dir[$k]);
147
+            }
148
+        }
149
+
150
+        return $dir;
151
+    }
152
+    if (is_null($dir_plugins)) {
153
+        $dir_plugins = _DIR_PLUGINS;
154
+    }
155
+    $search = array("$dir_plugins$dir/paquet.xml");
156
+
157
+    foreach ($search as $s) {
158
+        if (file_exists($s)) {
159
+            return $dir;
160
+        }
161
+    }
162
+
163
+    return '';
164 164
 }
165 165
 
166 166
 /** Regexp d'extraction des informations d'un intervalle de compatibilité */
@@ -187,51 +187,51 @@  discard block
 block discarded – undo
187 187
  **/
188 188
 function plugin_version_compatible($intervalle, $version, $avec_quoi = '') {
189 189
 
190
-	if (!strlen($intervalle)) {
191
-		return true;
192
-	}
193
-	if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
194
-		return false;
195
-	}
196
-	// Extraction des bornes et traitement de * pour la borne sup :
197
-	// -- on autorise uniquement les ecritures 3.0.*, 3.*
198
-	$minimum = $regs[1];
199
-	$maximum = $regs[2];
200
-
201
-	//  si une version SPIP de compatibilité a été définie (dans
202
-	//  mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0');
203
-	//  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
204
-	//  avec la version de SPIP (ne nuit donc pas aux tests de necessite
205
-	//  entre plugins)
206
-	if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) {
207
-		if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) {
208
-			return true;
209
-		}
210
-		// si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version
211
-		// cas du plugin qui n'est compatible qu'avec cette nouvelle version
212
-	}
213
-
214
-	$minimum_inc = $intervalle[0] == "[";
215
-	$maximum_inc = substr($intervalle, -1) == "]";
216
-
217
-	if (strlen($minimum)) {
218
-		if ($minimum_inc and spip_version_compare($version, $minimum, '<')) {
219
-			return false;
220
-		}
221
-		if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) {
222
-			return false;
223
-		}
224
-	}
225
-	if (strlen($maximum)) {
226
-		if ($maximum_inc and spip_version_compare($version, $maximum, '>')) {
227
-			return false;
228
-		}
229
-		if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) {
230
-			return false;
231
-		}
232
-	}
233
-
234
-	return true;
190
+    if (!strlen($intervalle)) {
191
+        return true;
192
+    }
193
+    if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
194
+        return false;
195
+    }
196
+    // Extraction des bornes et traitement de * pour la borne sup :
197
+    // -- on autorise uniquement les ecritures 3.0.*, 3.*
198
+    $minimum = $regs[1];
199
+    $maximum = $regs[2];
200
+
201
+    //  si une version SPIP de compatibilité a été définie (dans
202
+    //  mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0');
203
+    //  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
204
+    //  avec la version de SPIP (ne nuit donc pas aux tests de necessite
205
+    //  entre plugins)
206
+    if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) {
207
+        if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) {
208
+            return true;
209
+        }
210
+        // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version
211
+        // cas du plugin qui n'est compatible qu'avec cette nouvelle version
212
+    }
213
+
214
+    $minimum_inc = $intervalle[0] == "[";
215
+    $maximum_inc = substr($intervalle, -1) == "]";
216
+
217
+    if (strlen($minimum)) {
218
+        if ($minimum_inc and spip_version_compare($version, $minimum, '<')) {
219
+            return false;
220
+        }
221
+        if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) {
222
+            return false;
223
+        }
224
+    }
225
+    if (strlen($maximum)) {
226
+        if ($maximum_inc and spip_version_compare($version, $maximum, '>')) {
227
+            return false;
228
+        }
229
+        if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) {
230
+            return false;
231
+        }
232
+    }
233
+
234
+    return true;
235 235
 }
236 236
 
237 237
 /**
@@ -248,62 +248,62 @@  discard block
 block discarded – undo
248 248
  * @return array
249 249
  */
250 250
 function liste_plugin_valides($liste_plug, $force = false) {
251
-	$liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
252
-	$get_infos = charger_fonction('get_infos', 'plugins');
253
-	$infos = array(
254
-		// lister les extensions qui sont automatiquement actives
255
-		'_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
256
-		'_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
257
-	);
258
-
259
-	// creer une premiere liste non ordonnee mais qui ne retient
260
-	// que les plugins valides, et dans leur derniere version en cas de doublon
261
-	$infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
262
-	$infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
263
-	$infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
264
-	$liste_non_classee = array(
265
-		'SPIP' => array(
266
-			'nom' => 'SPIP',
267
-			'etat' => 'stable',
268
-			'version' => $GLOBALS['spip_version_branche'],
269
-			'dir_type' => '_DIR_RESTREINT',
270
-			'dir' => '',
271
-		)
272
-	);
273
-
274
-	$invalides = array();
275
-	foreach ($liste_ext as $plug) {
276
-		if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) {
277
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
278
-		}
279
-	}
280
-	foreach ($liste_plug as $plug) {
281
-		if (isset($infos['_DIR_PLUGINS'][$plug])) {
282
-			$r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
283
-			if (is_array($r)) {
284
-				$invalides = array_merge($invalides, $r);
285
-			}
286
-		}
287
-	}
288
-
289
-	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) {
290
-		$infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
291
-		foreach ($liste_plug as $plug) {
292
-			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) {
293
-				$r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
294
-				if (is_array($r)) {
295
-					$invalides = array_merge($invalides, $r);
296
-				}
297
-			}
298
-		}
299
-	}
300
-
301
-	plugin_fixer_procure($liste_non_classee, $infos);
302
-
303
-	// les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide)
304
-	$invalides = array_diff_key($invalides, $liste_non_classee);
305
-
306
-	return array($infos, $liste_non_classee, $invalides);
251
+    $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
252
+    $get_infos = charger_fonction('get_infos', 'plugins');
253
+    $infos = array(
254
+        // lister les extensions qui sont automatiquement actives
255
+        '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
256
+        '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
257
+    );
258
+
259
+    // creer une premiere liste non ordonnee mais qui ne retient
260
+    // que les plugins valides, et dans leur derniere version en cas de doublon
261
+    $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
262
+    $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
263
+    $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
264
+    $liste_non_classee = array(
265
+        'SPIP' => array(
266
+            'nom' => 'SPIP',
267
+            'etat' => 'stable',
268
+            'version' => $GLOBALS['spip_version_branche'],
269
+            'dir_type' => '_DIR_RESTREINT',
270
+            'dir' => '',
271
+        )
272
+    );
273
+
274
+    $invalides = array();
275
+    foreach ($liste_ext as $plug) {
276
+        if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) {
277
+            plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
278
+        }
279
+    }
280
+    foreach ($liste_plug as $plug) {
281
+        if (isset($infos['_DIR_PLUGINS'][$plug])) {
282
+            $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
283
+            if (is_array($r)) {
284
+                $invalides = array_merge($invalides, $r);
285
+            }
286
+        }
287
+    }
288
+
289
+    if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) {
290
+        $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
291
+        foreach ($liste_plug as $plug) {
292
+            if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) {
293
+                $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
294
+                if (is_array($r)) {
295
+                    $invalides = array_merge($invalides, $r);
296
+                }
297
+            }
298
+        }
299
+    }
300
+
301
+    plugin_fixer_procure($liste_non_classee, $infos);
302
+
303
+    // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide)
304
+    $invalides = array_diff_key($invalides, $liste_non_classee);
305
+
306
+    return array($infos, $liste_non_classee, $invalides);
307 307
 }
308 308
 
309 309
 /**
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
  *   array description short si on ne le retient pas (pour memorisation dans une table des erreurs)
324 324
  */
325 325
 function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) {
326
-	$i = $infos[$dir_type][$plug];
327
-	$p = strtoupper($i['prefix']);
328
-	$short_desc = array(
329
-		'nom' => $i['nom'],
330
-		'etat' => $i['etat'],
331
-		'version' => $i['version'],
332
-		'dir' => $plug,
333
-		'dir_type' => $dir_type
334
-	);
335
-	if (isset($i['erreur']) and $i['erreur']) {
336
-		$short_desc['erreur'] = $i['erreur'];
337
-		return array($p=>$short_desc);
338
-	}
339
-	if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
340
-		return array($p=>$short_desc);
341
-	}
342
-	if (!isset($liste[$p])
343
-		or spip_version_compare($i['version'], $liste[$p]['version'], '>')
344
-	) {
345
-		$liste[$p] = $short_desc;
346
-	}
347
-	// ok le plugin etait deja dans la liste ou on a choisi une version plus recente
348
-	return $p;
326
+    $i = $infos[$dir_type][$plug];
327
+    $p = strtoupper($i['prefix']);
328
+    $short_desc = array(
329
+        'nom' => $i['nom'],
330
+        'etat' => $i['etat'],
331
+        'version' => $i['version'],
332
+        'dir' => $plug,
333
+        'dir_type' => $dir_type
334
+    );
335
+    if (isset($i['erreur']) and $i['erreur']) {
336
+        $short_desc['erreur'] = $i['erreur'];
337
+        return array($p=>$short_desc);
338
+    }
339
+    if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
340
+        return array($p=>$short_desc);
341
+    }
342
+    if (!isset($liste[$p])
343
+        or spip_version_compare($i['version'], $liste[$p]['version'], '>')
344
+    ) {
345
+        $liste[$p] = $short_desc;
346
+    }
347
+    // ok le plugin etait deja dans la liste ou on a choisi une version plus recente
348
+    return $p;
349 349
 }
350 350
 
351 351
 /**
@@ -361,46 +361,46 @@  discard block
 block discarded – undo
361 361
  * @param array $infos
362 362
  */
363 363
 function plugin_fixer_procure(&$liste, &$infos) {
364
-	foreach ($liste as $p => $resume) {
365
-		$i = $infos[$resume['dir_type']][$resume['dir']];
366
-		if (isset($i['procure']) and $i['procure']) {
367
-			foreach ($i['procure'] as $procure) {
368
-				$p = strtoupper($procure['nom']);
369
-				$dir = $resume['dir'];
370
-				if ($dir) {
371
-					$dir .= "/";
372
-				}
373
-				$dir .= "procure:" . $procure['nom'];
374
-
375
-				$procure['etat'] = '?';
376
-				$procure['dir_type'] = $resume['dir_type'];
377
-				$procure['dir'] = $dir;
378
-
379
-				// si ce plugin n'est pas deja procure, ou dans une version plus ancienne
380
-				// on ajoute cette version a la liste
381
-				if (!isset($liste[$p])
382
-					or spip_version_compare($procure['version'], $liste[$p]['version'], '>')
383
-				) {
384
-					$liste[$p] = $procure;
385
-
386
-					// on fournit une information minimale pour ne pas perturber la compilation
387
-					$infos[$resume['dir_type']][$dir] = array(
388
-						'prefix' => $procure['nom'],
389
-						'nom' => $procure['nom'],
390
-						'etat' => $procure['etat'],
391
-						'version' => $procure['version'],
392
-						'chemin' => array(),
393
-						'necessite' => array(),
394
-						'utilise' => array(),
395
-						'lib' => array(),
396
-						'menu' => array(),
397
-						'onglet' => array(),
398
-						'procure' => array(),
399
-					);
400
-				}
401
-			}
402
-		}
403
-	}
364
+    foreach ($liste as $p => $resume) {
365
+        $i = $infos[$resume['dir_type']][$resume['dir']];
366
+        if (isset($i['procure']) and $i['procure']) {
367
+            foreach ($i['procure'] as $procure) {
368
+                $p = strtoupper($procure['nom']);
369
+                $dir = $resume['dir'];
370
+                if ($dir) {
371
+                    $dir .= "/";
372
+                }
373
+                $dir .= "procure:" . $procure['nom'];
374
+
375
+                $procure['etat'] = '?';
376
+                $procure['dir_type'] = $resume['dir_type'];
377
+                $procure['dir'] = $dir;
378
+
379
+                // si ce plugin n'est pas deja procure, ou dans une version plus ancienne
380
+                // on ajoute cette version a la liste
381
+                if (!isset($liste[$p])
382
+                    or spip_version_compare($procure['version'], $liste[$p]['version'], '>')
383
+                ) {
384
+                    $liste[$p] = $procure;
385
+
386
+                    // on fournit une information minimale pour ne pas perturber la compilation
387
+                    $infos[$resume['dir_type']][$dir] = array(
388
+                        'prefix' => $procure['nom'],
389
+                        'nom' => $procure['nom'],
390
+                        'etat' => $procure['etat'],
391
+                        'version' => $procure['version'],
392
+                        'chemin' => array(),
393
+                        'necessite' => array(),
394
+                        'utilise' => array(),
395
+                        'lib' => array(),
396
+                        'menu' => array(),
397
+                        'onglet' => array(),
398
+                        'procure' => array(),
399
+                    );
400
+                }
401
+            }
402
+        }
403
+    }
404 404
 }
405 405
 
406 406
 /**
@@ -414,19 +414,19 @@  discard block
 block discarded – undo
414 414
  * @return array
415 415
  */
416 416
 function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) {
417
-	foreach ($liste as $prefix => $infos) {
418
-		if (!$dir_plugins
419
-			or (
420
-				defined($infos['dir_type'])
421
-				and constant($infos['dir_type']) == $dir_plugins)
422
-		) {
423
-			$liste[$prefix] = $infos['dir'];
424
-		} else {
425
-			unset($liste[$prefix]);
426
-		}
427
-	}
428
-
429
-	return $liste;
417
+    foreach ($liste as $prefix => $infos) {
418
+        if (!$dir_plugins
419
+            or (
420
+                defined($infos['dir_type'])
421
+                and constant($infos['dir_type']) == $dir_plugins)
422
+        ) {
423
+            $liste[$prefix] = $infos['dir'];
424
+        } else {
425
+            unset($liste[$prefix]);
426
+        }
427
+    }
428
+
429
+    return $liste;
430 430
 }
431 431
 
432 432
 /**
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
  * @return array
442 442
  */
443 443
 function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) {
444
-	include_spip('plugins/installer');
444
+    include_spip('plugins/installer');
445 445
 
446
-	return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
446
+    return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
447 447
 }
448 448
 
449 449
 /**
@@ -474,53 +474,53 @@  discard block
 block discarded – undo
474 474
  *                qui n'ont pas satisfait leurs dépendances
475 475
 **/
476 476
 function plugin_trier($infos, $liste_non_classee) {
477
-	$toute_la_liste = $liste_non_classee;
478
-	$liste = $ordre = array();
479
-	$count = 0;
480
-
481
-	while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
482
-		#echo "tour::";var_dump($liste_non_classee);
483
-		$count = $c;
484
-		foreach ($liste_non_classee as $p => $resume) {
485
-			$plug = $resume['dir'];
486
-			$dir_type = $resume['dir_type'];
487
-			$info1 = $infos[$dir_type][$plug];
488
-			// si des plugins sont necessaires,
489
-			// on ne peut inserer qu'apres eux
490
-			foreach ($info1['necessite'] as $need) {
491
-				$nom = strtoupper($need['nom']);
492
-				$compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
493
-				if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) {
494
-					$info1 = false;
495
-					break;
496
-				}
497
-			}
498
-			if (!$info1) {
499
-				continue;
500
-			}
501
-			// idem si des plugins sont utiles,
502
-			// sauf si ils sont de toute facon absents de la liste
503
-			foreach ($info1['utilise'] as $need) {
504
-				$nom = strtoupper($need['nom']);
505
-				$compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
506
-				if (isset($toute_la_liste[$nom])) {
507
-					if (!isset($liste[$nom]) or
508
-						!plugin_version_compatible($compat, $liste[$nom]['version'])
509
-					) {
510
-						$info1 = false;
511
-						break;
512
-					}
513
-				}
514
-			}
515
-			if ($info1) {
516
-				$ordre[$p] = $info1;
517
-				$liste[$p] = $liste_non_classee[$p];
518
-				unset($liste_non_classee[$p]);
519
-			}
520
-		}
521
-	}
522
-
523
-	return array($liste, $ordre, $liste_non_classee);
477
+    $toute_la_liste = $liste_non_classee;
478
+    $liste = $ordre = array();
479
+    $count = 0;
480
+
481
+    while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
482
+        #echo "tour::";var_dump($liste_non_classee);
483
+        $count = $c;
484
+        foreach ($liste_non_classee as $p => $resume) {
485
+            $plug = $resume['dir'];
486
+            $dir_type = $resume['dir_type'];
487
+            $info1 = $infos[$dir_type][$plug];
488
+            // si des plugins sont necessaires,
489
+            // on ne peut inserer qu'apres eux
490
+            foreach ($info1['necessite'] as $need) {
491
+                $nom = strtoupper($need['nom']);
492
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
493
+                if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) {
494
+                    $info1 = false;
495
+                    break;
496
+                }
497
+            }
498
+            if (!$info1) {
499
+                continue;
500
+            }
501
+            // idem si des plugins sont utiles,
502
+            // sauf si ils sont de toute facon absents de la liste
503
+            foreach ($info1['utilise'] as $need) {
504
+                $nom = strtoupper($need['nom']);
505
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
506
+                if (isset($toute_la_liste[$nom])) {
507
+                    if (!isset($liste[$nom]) or
508
+                        !plugin_version_compatible($compat, $liste[$nom]['version'])
509
+                    ) {
510
+                        $info1 = false;
511
+                        break;
512
+                    }
513
+                }
514
+            }
515
+            if ($info1) {
516
+                $ordre[$p] = $info1;
517
+                $liste[$p] = $liste_non_classee[$p];
518
+                unset($liste_non_classee[$p]);
519
+            }
520
+        }
521
+    }
522
+
523
+    return array($liste, $ordre, $liste_non_classee);
524 524
 }
525 525
 
526 526
 /**
@@ -537,40 +537,40 @@  discard block
 block discarded – undo
537 537
  *     Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent
538 538
 **/
539 539
 function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array()) {
540
-	static $erreurs = array();
541
-
542
-	if (!is_array($liste)) {
543
-		$liste = array();
544
-	}
545
-
546
-	// les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste
547
-	$liste = array_diff_key($liste, $liste_non_classee);
548
-
549
-	foreach ($liste_non_classee as $p => $resume) {
550
-		$dir_type = $resume['dir_type'];
551
-		$plug = $resume['dir'];
552
-		$k = $infos[$dir_type][$plug];
553
-
554
-		$plug = constant($dir_type) . $plug;
555
-		if (!isset($msg[$p])) {
556
-			if (isset($resume['erreur']) and $resume['erreur']) {
557
-				$msg[$p] = array($resume['erreur']);
558
-			}
559
-			elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560
-				$msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
-			}
562
-			elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563
-				$msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564
-			}
565
-		} else {
566
-			foreach ($msg[$p] as $c => $l) {
567
-				$msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
568
-			}
569
-		}
570
-		$erreurs[$plug] = $msg[$p];
571
-	}
572
-
573
-	ecrire_meta('plugin_erreur_activation', serialize($erreurs));
540
+    static $erreurs = array();
541
+
542
+    if (!is_array($liste)) {
543
+        $liste = array();
544
+    }
545
+
546
+    // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste
547
+    $liste = array_diff_key($liste, $liste_non_classee);
548
+
549
+    foreach ($liste_non_classee as $p => $resume) {
550
+        $dir_type = $resume['dir_type'];
551
+        $plug = $resume['dir'];
552
+        $k = $infos[$dir_type][$plug];
553
+
554
+        $plug = constant($dir_type) . $plug;
555
+        if (!isset($msg[$p])) {
556
+            if (isset($resume['erreur']) and $resume['erreur']) {
557
+                $msg[$p] = array($resume['erreur']);
558
+            }
559
+            elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560
+                $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
+            }
562
+            elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563
+                $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564
+            }
565
+        } else {
566
+            foreach ($msg[$p] as $c => $l) {
567
+                $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
568
+            }
569
+        }
570
+        $erreurs[$plug] = $msg[$p];
571
+    }
572
+
573
+    ecrire_meta('plugin_erreur_activation', serialize($erreurs));
574 574
 }
575 575
 
576 576
 /**
@@ -585,25 +585,25 @@  discard block
 block discarded – undo
585 585
  *     - Liste des erreurs ou code HTML des erreurs
586 586
 **/
587 587
 function plugin_donne_erreurs($raw = false, $raz = true) {
588
-	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) {
589
-		return $raw ? array() : '';
590
-	}
591
-	$list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
592
-	// Compat ancienne version
593
-	if (!$list) {
594
-		$list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595
-	} elseif (!$raw) {
596
-		foreach ($list as $plug => $msg) {
597
-			$list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
-				. "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
599
-		}
600
-		$list = "<ul>" . join("\n", $list) . "</ul>";
601
-	}
602
-	if ($raz) {
603
-		effacer_meta('plugin_erreur_activation');
604
-	}
605
-
606
-	return $list;
588
+    if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) {
589
+        return $raw ? array() : '';
590
+    }
591
+    $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
592
+    // Compat ancienne version
593
+    if (!$list) {
594
+        $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595
+    } elseif (!$raw) {
596
+        foreach ($list as $plug => $msg) {
597
+            $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
+                . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
599
+        }
600
+        $list = "<ul>" . join("\n", $list) . "</ul>";
601
+    }
602
+    if ($raz) {
603
+        effacer_meta('plugin_erreur_activation');
604
+    }
605
+
606
+    return $list;
607 607
 }
608 608
 
609 609
 /**
@@ -623,21 +623,21 @@  discard block
 block discarded – undo
623 623
  *
624 624
  **/
625 625
 function plugin_necessite($n, $liste, $balise = 'necessite') {
626
-	$msg = array();
627
-	foreach ($n as $need) {
628
-		$id = strtoupper($need['nom']);
629
-		$r = plugin_controler_necessite(
630
-			$liste, 
631
-			$id, 
632
-			isset($need['compatibilite']) ? $need['compatibilite'] : '', 
633
-			$balise
634
-		);
635
-		if ($r) {
636
-			$msg[] = $r;
637
-		}
638
-	}
639
-
640
-	return $msg;
626
+    $msg = array();
627
+    foreach ($n as $need) {
628
+        $id = strtoupper($need['nom']);
629
+        $r = plugin_controler_necessite(
630
+            $liste, 
631
+            $id, 
632
+            isset($need['compatibilite']) ? $need['compatibilite'] : '', 
633
+            $balise
634
+        );
635
+        if ($r) {
636
+            $msg[] = $r;
637
+        }
638
+    }
639
+
640
+    return $msg;
641 641
 }
642 642
 
643 643
 /**
@@ -659,16 +659,16 @@  discard block
 block discarded – undo
659 659
  *    Message d'erreur lorsque la dépendance est absente.
660 660
  **/
661 661
 function plugin_controler_necessite($liste, $nom, $intervalle, $balise) {
662
-	if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) {
663
-		return '';
664
-	}
665
-
666
-	return plugin_message_incompatibilite(
667
-		$intervalle, 
668
-		(isset($liste[$nom]) ? $liste[$nom]['version'] : ""), 
669
-		$nom, 
670
-		$balise
671
-	);
662
+    if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) {
663
+        return '';
664
+    }
665
+
666
+    return plugin_message_incompatibilite(
667
+        $intervalle, 
668
+        (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), 
669
+        $nom, 
670
+        $balise
671
+    );
672 672
 }
673 673
 
674 674
 /**
@@ -685,70 +685,70 @@  discard block
 block discarded – undo
685 685
  */
686 686
 function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) {
687 687
 
688
-	// prendre en compte les erreurs de dépendances à PHP
689
-	// ou à une extension PHP avec des messages d'erreurs dédiés.
690
-	$type = 'plugin';
691
-	if ($nom === 'SPIP') {
692
-		$type = 'spip';
693
-	} elseif ($nom === 'PHP') {
694
-		$type = 'php';
695
-	} elseif (strncmp($nom, 'PHP:', 4) === 0) {
696
-		$type = 'extension_php';
697
-		list(,$nom) = explode(':', $nom, 2);
698
-	}
699
-
700
-	if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
701
-		$minimum = $regs[1];
702
-		$maximum = $regs[2];
703
-
704
-		$minimum_inclus = $intervalle[0] == "[";
705
-		$maximum_inclus = substr($intervalle, -1) == "]";
706
-
707
-		if (strlen($minimum)) {
708
-			if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709
-				return _T("plugin_${balise}_${type}", array(
710
-					'plugin' => $nom,
711
-					'version' => ' &ge; ' . $minimum
712
-				));
713
-			}
714
-			if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715
-				return _T("plugin_${balise}_${type}", array(
716
-					'plugin' => $nom,
717
-					'version' => ' &gt; ' . $minimum
718
-				));
719
-			}
720
-		}
721
-
722
-		if (strlen($maximum)) {
723
-			if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724
-				return _T("plugin_${balise}_${type}", array(
725
-					'plugin' => $nom,
726
-					'version' => ' &le; ' . $maximum
727
-				));
728
-			}
729
-			if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730
-				return _T("plugin_${balise}_plugin", array(
731
-					'plugin' => $nom,
732
-					'version' => ' &lt; ' . $maximum
733
-				));
734
-			}
735
-		}
736
-	}
737
-
738
-	// note : il ne peut pas y avoir d'erreur sur
739
-	// - un 'utilise' sans version.
740
-	// - un 'php' sans version.
741
-	return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom));
688
+    // prendre en compte les erreurs de dépendances à PHP
689
+    // ou à une extension PHP avec des messages d'erreurs dédiés.
690
+    $type = 'plugin';
691
+    if ($nom === 'SPIP') {
692
+        $type = 'spip';
693
+    } elseif ($nom === 'PHP') {
694
+        $type = 'php';
695
+    } elseif (strncmp($nom, 'PHP:', 4) === 0) {
696
+        $type = 'extension_php';
697
+        list(,$nom) = explode(':', $nom, 2);
698
+    }
699
+
700
+    if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
701
+        $minimum = $regs[1];
702
+        $maximum = $regs[2];
703
+
704
+        $minimum_inclus = $intervalle[0] == "[";
705
+        $maximum_inclus = substr($intervalle, -1) == "]";
706
+
707
+        if (strlen($minimum)) {
708
+            if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709
+                return _T("plugin_${balise}_${type}", array(
710
+                    'plugin' => $nom,
711
+                    'version' => ' &ge; ' . $minimum
712
+                ));
713
+            }
714
+            if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715
+                return _T("plugin_${balise}_${type}", array(
716
+                    'plugin' => $nom,
717
+                    'version' => ' &gt; ' . $minimum
718
+                ));
719
+            }
720
+        }
721
+
722
+        if (strlen($maximum)) {
723
+            if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724
+                return _T("plugin_${balise}_${type}", array(
725
+                    'plugin' => $nom,
726
+                    'version' => ' &le; ' . $maximum
727
+                ));
728
+            }
729
+            if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730
+                return _T("plugin_${balise}_plugin", array(
731
+                    'plugin' => $nom,
732
+                    'version' => ' &lt; ' . $maximum
733
+                ));
734
+            }
735
+        }
736
+    }
737
+
738
+    // note : il ne peut pas y avoir d'erreur sur
739
+    // - un 'utilise' sans version.
740
+    // - un 'php' sans version.
741
+    return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom));
742 742
 }
743 743
 
744 744
 
745 745
 function plugin_controler_lib($lib, $url) {
746
-	/* Feature sortie du core, voir STP
746
+    /* Feature sortie du core, voir STP
747 747
 	 * if ($url) {
748 748
 		include_spip('inc/charger_plugin');
749 749
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
750 750
 	}*/
751
-	return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
751
+    return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
752 752
 }
753 753
 
754 754
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
  *     true si il y a eu des modifications sur la liste des plugins actifs, false sinon
764 764
  **/
765 765
 function actualise_plugins_actifs($pipe_recherche = false) {
766
-	return ecrire_plugin_actifs('', $pipe_recherche, 'force');
766
+    return ecrire_plugin_actifs('', $pipe_recherche, 'force');
767 767
 }
768 768
 
769 769
 
@@ -790,113 +790,113 @@  discard block
 block discarded – undo
790 790
  **/
791 791
 function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') {
792 792
 
793
-	// creer le repertoire cache/ si necessaire ! (installation notamment)
794
-	$cache = sous_repertoire(_DIR_CACHE, '', false, true);
795
-
796
-	// Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore.
797
-	if (!$cache and !spip_connect()) {
798
-		return false;
799
-	}
800
-
801
-	if ($operation != 'raz') {
802
-		$plugin_valides = liste_chemin_plugin_actifs();
803
-		$plugin_valides = is_plugin_dir($plugin_valides);
804
-		if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
805
-			$plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
806
-			$plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL);
807
-			$plugin_valides = array_merge($plugin_valides, $plugin_valides_supp);
808
-		}
809
-		// si des plugins sont en attentes (coches mais impossible a activer)
810
-		// on les reinjecte ici
811
-		if (isset($GLOBALS['meta']['plugin_attente'])
812
-			and $a = unserialize($GLOBALS['meta']['plugin_attente'])
813
-		) {
814
-			$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
815
-		}
816
-
817
-		if ($operation == 'ajoute') {
818
-			$plugin = array_merge($plugin_valides, $plugin);
819
-		} elseif ($operation == 'enleve') {
820
-			$plugin = array_diff($plugin_valides, $plugin);
821
-		} else {
822
-			$plugin = $plugin_valides;
823
-		}
824
-	}
825
-	$actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : '';
826
-
827
-	// si une fonction de gestion de dependances existe, l'appeler ici
828
-	if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) {
829
-		$plugin = $ajouter_dependances($plugin);
830
-	}
831
-
832
-	// recharger le xml des plugins a activer
833
-	// on force le reload ici, meme si le fichier xml n'a pas change
834
-	// pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
835
-	// pourra etre evite quand on ne supportera plus les plugin.xml
836
-	// en deplacant la detection de ces fichiers dans la compilation ci dessous
837
-	list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true);
838
-	// trouver l'ordre d'activation
839
-	list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste);
840
-	if ($invalides or $reste) {
841
-		plugins_erreurs(array_merge($invalides, $reste), $liste, $infos);
842
-	}
843
-
844
-	// Ignorer les plugins necessitant une lib absente
845
-	// et preparer la meta d'entete Http
846
-	$err = $msg = $header = array();
847
-	foreach ($plugin_valides as $p => $resume) {
848
-		// Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849
-		if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
-			$header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
851
-		}
852
-		if ($resume['dir']) {
853
-			foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
854
-				if (!find_in_path($l['nom'], 'lib/')) {
855
-					$err[$p] = $resume;
856
-					$msg[$p][] = $l;
857
-					unset($plugin_valides[$p]);
858
-				}
859
-			}
860
-		}
861
-	}
862
-	if ($err) {
863
-		plugins_erreurs($err, '', $infos, $msg);
864
-	}
865
-
866
-	if (isset($GLOBALS['meta']['message_crash_plugins'])) {
867
-		effacer_meta('message_crash_plugins');
868
-	}
869
-	ecrire_meta('plugin', serialize($plugin_valides));
870
-	$liste = array_diff_key($liste, $plugin_valides);
871
-	ecrire_meta('plugin_attente', serialize($liste));
872
-	$header = strtolower(implode(",", $header));
873
-	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
-		ecrire_fichier(_DIR_VAR . "config.txt",
875
-			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
876
-	} else {
877
-		@unlink(_DIR_VAR . "config.txt");
878
-	}
879
-	// generer charger_plugins_chemin.php
880
-	plugins_precompile_chemin($plugin_valides, $ordre);
881
-	// generer les fichiers
882
-	// - charger_plugins_options.php
883
-	// - charger_plugins_fonctions.php
884
-	plugins_precompile_xxxtions($plugin_valides, $ordre);
885
-	// charger les chemins des plugins et les fichiers d'options 
886
-	// (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins)
887
-	plugins_amorcer_plugins_actifs();
888
-	// mise a jour de la matrice des pipelines
889
-	$prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
890
-	// generer le fichier _CACHE_PIPELINE
891
-	pipeline_precompile($prepend_code);
892
-
893
-	if (spip_connect()) {
894
-		// lancer et initialiser les nouveaux crons !
895
-		include_spip('inc/genie');
896
-		genie_queue_watch_dist();
897
-	}
898
-
899
-	return ($GLOBALS['meta']['plugin'] != $actifs_avant);
793
+    // creer le repertoire cache/ si necessaire ! (installation notamment)
794
+    $cache = sous_repertoire(_DIR_CACHE, '', false, true);
795
+
796
+    // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore.
797
+    if (!$cache and !spip_connect()) {
798
+        return false;
799
+    }
800
+
801
+    if ($operation != 'raz') {
802
+        $plugin_valides = liste_chemin_plugin_actifs();
803
+        $plugin_valides = is_plugin_dir($plugin_valides);
804
+        if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
805
+            $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
806
+            $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL);
807
+            $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp);
808
+        }
809
+        // si des plugins sont en attentes (coches mais impossible a activer)
810
+        // on les reinjecte ici
811
+        if (isset($GLOBALS['meta']['plugin_attente'])
812
+            and $a = unserialize($GLOBALS['meta']['plugin_attente'])
813
+        ) {
814
+            $plugin_valides = $plugin_valides + liste_chemin_plugin($a);
815
+        }
816
+
817
+        if ($operation == 'ajoute') {
818
+            $plugin = array_merge($plugin_valides, $plugin);
819
+        } elseif ($operation == 'enleve') {
820
+            $plugin = array_diff($plugin_valides, $plugin);
821
+        } else {
822
+            $plugin = $plugin_valides;
823
+        }
824
+    }
825
+    $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : '';
826
+
827
+    // si une fonction de gestion de dependances existe, l'appeler ici
828
+    if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) {
829
+        $plugin = $ajouter_dependances($plugin);
830
+    }
831
+
832
+    // recharger le xml des plugins a activer
833
+    // on force le reload ici, meme si le fichier xml n'a pas change
834
+    // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
835
+    // pourra etre evite quand on ne supportera plus les plugin.xml
836
+    // en deplacant la detection de ces fichiers dans la compilation ci dessous
837
+    list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true);
838
+    // trouver l'ordre d'activation
839
+    list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste);
840
+    if ($invalides or $reste) {
841
+        plugins_erreurs(array_merge($invalides, $reste), $liste, $infos);
842
+    }
843
+
844
+    // Ignorer les plugins necessitant une lib absente
845
+    // et preparer la meta d'entete Http
846
+    $err = $msg = $header = array();
847
+    foreach ($plugin_valides as $p => $resume) {
848
+        // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849
+        if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
+            $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
851
+        }
852
+        if ($resume['dir']) {
853
+            foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
854
+                if (!find_in_path($l['nom'], 'lib/')) {
855
+                    $err[$p] = $resume;
856
+                    $msg[$p][] = $l;
857
+                    unset($plugin_valides[$p]);
858
+                }
859
+            }
860
+        }
861
+    }
862
+    if ($err) {
863
+        plugins_erreurs($err, '', $infos, $msg);
864
+    }
865
+
866
+    if (isset($GLOBALS['meta']['message_crash_plugins'])) {
867
+        effacer_meta('message_crash_plugins');
868
+    }
869
+    ecrire_meta('plugin', serialize($plugin_valides));
870
+    $liste = array_diff_key($liste, $plugin_valides);
871
+    ecrire_meta('plugin_attente', serialize($liste));
872
+    $header = strtolower(implode(",", $header));
873
+    if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
+        ecrire_fichier(_DIR_VAR . "config.txt",
875
+            (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
876
+    } else {
877
+        @unlink(_DIR_VAR . "config.txt");
878
+    }
879
+    // generer charger_plugins_chemin.php
880
+    plugins_precompile_chemin($plugin_valides, $ordre);
881
+    // generer les fichiers
882
+    // - charger_plugins_options.php
883
+    // - charger_plugins_fonctions.php
884
+    plugins_precompile_xxxtions($plugin_valides, $ordre);
885
+    // charger les chemins des plugins et les fichiers d'options 
886
+    // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins)
887
+    plugins_amorcer_plugins_actifs();
888
+    // mise a jour de la matrice des pipelines
889
+    $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
890
+    // generer le fichier _CACHE_PIPELINE
891
+    pipeline_precompile($prepend_code);
892
+
893
+    if (spip_connect()) {
894
+        // lancer et initialiser les nouveaux crons !
895
+        include_spip('inc/genie');
896
+        genie_queue_watch_dist();
897
+    }
898
+
899
+    return ($GLOBALS['meta']['plugin'] != $actifs_avant);
900 900
 }
901 901
 
902 902
 /**
@@ -915,56 +915,56 @@  discard block
 block discarded – undo
915 915
  *     Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances
916 916
 **/
917 917
 function plugins_precompile_chemin($plugin_valides, $ordre) {
918
-	$chemins = array();
919
-	$contenu = "";
920
-	foreach ($ordre as $p => $info) {
921
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
922
-		if (isset($plugin_valides[$p])) {
923
-			$dir_type = $plugin_valides[$p]['dir_type'];
924
-			$plug = $plugin_valides[$p]['dir'];
925
-			// definir le plugin, donc le path avant l'include du fichier options
926
-			// permet de faire des include_spip pour attraper un inc_ du plugin
927
-
928
-			$dir = $dir_type . ".'" . $plug . "/'";
929
-
930
-			$prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931
-			if (
932
-				$prefix !== "SPIP"
933
-				and strpos($dir, ":") === false // exclure le cas des procure:
934
-			) {
935
-				$contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
936
-				foreach ($info['chemin'] as $chemin) {
937
-					if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'],
938
-							$GLOBALS['spip_version_branche'], 'spip')
939
-					) {
940
-						$dir = $chemin['path'];
941
-						if (strlen($dir) and $dir[0] == "/") {
942
-							$dir = substr($dir, 1);
943
-						}
944
-						if (strlen($dir) and $dir == "./") {
945
-							$dir = '';
946
-						}
947
-						if (strlen($dir)) {
948
-							$dir = rtrim($dir, '/') . '/';
949
-						}
950
-						if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
-							$chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
952
-						}
953
-						if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
-							$chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
955
-						}
956
-					}
957
-				}
958
-			}
959
-		}
960
-	}
961
-	if (count($chemins)) {
962
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
-				array_reverse($chemins['public'])) . ")));\n"
964
-			. "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
965
-	}
966
-
967
-	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
918
+    $chemins = array();
919
+    $contenu = "";
920
+    foreach ($ordre as $p => $info) {
921
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
922
+        if (isset($plugin_valides[$p])) {
923
+            $dir_type = $plugin_valides[$p]['dir_type'];
924
+            $plug = $plugin_valides[$p]['dir'];
925
+            // definir le plugin, donc le path avant l'include du fichier options
926
+            // permet de faire des include_spip pour attraper un inc_ du plugin
927
+
928
+            $dir = $dir_type . ".'" . $plug . "/'";
929
+
930
+            $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931
+            if (
932
+                $prefix !== "SPIP"
933
+                and strpos($dir, ":") === false // exclure le cas des procure:
934
+            ) {
935
+                $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
936
+                foreach ($info['chemin'] as $chemin) {
937
+                    if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'],
938
+                            $GLOBALS['spip_version_branche'], 'spip')
939
+                    ) {
940
+                        $dir = $chemin['path'];
941
+                        if (strlen($dir) and $dir[0] == "/") {
942
+                            $dir = substr($dir, 1);
943
+                        }
944
+                        if (strlen($dir) and $dir == "./") {
945
+                            $dir = '';
946
+                        }
947
+                        if (strlen($dir)) {
948
+                            $dir = rtrim($dir, '/') . '/';
949
+                        }
950
+                        if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
+                            $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
952
+                        }
953
+                        if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
+                            $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
955
+                        }
956
+                    }
957
+                }
958
+            }
959
+        }
960
+    }
961
+    if (count($chemins)) {
962
+        $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
+                array_reverse($chemins['public'])) . ")));\n"
964
+            . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
965
+    }
966
+
967
+    ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
968 968
 }
969 969
 
970 970
 /**
@@ -982,65 +982,65 @@  discard block
 block discarded – undo
982 982
  *     Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances
983 983
 **/
984 984
 function plugins_precompile_xxxtions($plugin_valides, $ordre) {
985
-	$contenu = array('options' => '', 'fonctions' => '');
986
-	$boutons = array();
987
-	$onglets = array();
988
-	$sign = "";
989
-
990
-	foreach ($ordre as $p => $info) {
991
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
992
-		if (isset($plugin_valides[$p])) {
993
-			$dir_type = $plugin_valides[$p]['dir_type'];
994
-			$plug = $plugin_valides[$p]['dir'];
995
-			$dir = constant($dir_type);
996
-			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
997
-			if ($info['menu']) {
998
-				$boutons = array_merge($boutons, $info['menu']);
999
-			}
1000
-			if ($info['onglet']) {
1001
-				$onglets = array_merge($onglets, $info['onglet']);
1002
-			}
1003
-			foreach ($contenu as $charge => $v) {
1004
-				// si pas declare/detecte a la lecture du paquet.xml,
1005
-				// detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
1006
-				// donc ni sa relecture, ni sa detection
1007
-				if (!isset($info[$charge])
1008
-					and $dir // exclure le cas du plugin "SPIP"
1009
-					and strpos($dir, ":") === false // exclure le cas des procure:
1010
-					and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011
-				) {
1012
-					if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1013
-						$info[$charge] = array($file);
1014
-					}
1015
-				}
1016
-				if (isset($info[$charge])) {
1017
-					$files = $info[$charge];
1018
-					foreach ($files as $k => $file) {
1019
-						// on genere un if file_exists devant chaque include
1020
-						// pour pouvoir garder le meme niveau d'erreur general
1021
-						$file = trim($file);
1022
-						if (!is_readable("$dir$plug/$file")
1023
-							// uniquement pour les paquet.xml
1024
-							and file_exists("$dir$plug/paquet.xml")
1025
-						) {
1026
-							unset($info[$charge][$k]);
1027
-						} else {
1028
-							$_file = $root_dir_type . ".'$plug/$file'";
1029
-							$contenu[$charge] .= "include_once_check($_file);\n";
1030
-						}
1031
-					}
1032
-				}
1033
-			}
1034
-			$sign .= md5(serialize($info));
1035
-		}
1036
-	}
1037
-
1038
-	$contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1039
-	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040
-		. plugin_ongletbouton("onglets_plugins", $onglets);
1041
-
1042
-	ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
1043
-	ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
985
+    $contenu = array('options' => '', 'fonctions' => '');
986
+    $boutons = array();
987
+    $onglets = array();
988
+    $sign = "";
989
+
990
+    foreach ($ordre as $p => $info) {
991
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
992
+        if (isset($plugin_valides[$p])) {
993
+            $dir_type = $plugin_valides[$p]['dir_type'];
994
+            $plug = $plugin_valides[$p]['dir'];
995
+            $dir = constant($dir_type);
996
+            $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
997
+            if ($info['menu']) {
998
+                $boutons = array_merge($boutons, $info['menu']);
999
+            }
1000
+            if ($info['onglet']) {
1001
+                $onglets = array_merge($onglets, $info['onglet']);
1002
+            }
1003
+            foreach ($contenu as $charge => $v) {
1004
+                // si pas declare/detecte a la lecture du paquet.xml,
1005
+                // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
1006
+                // donc ni sa relecture, ni sa detection
1007
+                if (!isset($info[$charge])
1008
+                    and $dir // exclure le cas du plugin "SPIP"
1009
+                    and strpos($dir, ":") === false // exclure le cas des procure:
1010
+                    and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011
+                ) {
1012
+                    if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1013
+                        $info[$charge] = array($file);
1014
+                    }
1015
+                }
1016
+                if (isset($info[$charge])) {
1017
+                    $files = $info[$charge];
1018
+                    foreach ($files as $k => $file) {
1019
+                        // on genere un if file_exists devant chaque include
1020
+                        // pour pouvoir garder le meme niveau d'erreur general
1021
+                        $file = trim($file);
1022
+                        if (!is_readable("$dir$plug/$file")
1023
+                            // uniquement pour les paquet.xml
1024
+                            and file_exists("$dir$plug/paquet.xml")
1025
+                        ) {
1026
+                            unset($info[$charge][$k]);
1027
+                        } else {
1028
+                            $_file = $root_dir_type . ".'$plug/$file'";
1029
+                            $contenu[$charge] .= "include_once_check($_file);\n";
1030
+                        }
1031
+                    }
1032
+                }
1033
+            }
1034
+            $sign .= md5(serialize($info));
1035
+        }
1036
+    }
1037
+
1038
+    $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1039
+    $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040
+        . plugin_ongletbouton("onglets_plugins", $onglets);
1041
+
1042
+    ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
1043
+    ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
1044 1044
 }
1045 1045
 
1046 1046
 /**
@@ -1059,24 +1059,24 @@  discard block
 block discarded – undo
1059 1059
  * @return string Code php
1060 1060
  */
1061 1061
 function plugin_ongletbouton($nom, $val) {
1062
-	if (!$val) {
1063
-		$val = array();
1064
-	}
1065
-
1066
-	$val = serialize($val);
1067
-	$md5 = md5($val);
1068
-
1069
-	if (!defined("_UPDATED_$nom")) {
1070
-		define("_UPDATED_$nom", $val);
1071
-		define("_UPDATED_md5_$nom", $md5);
1072
-	}
1073
-	$val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1074
-
1075
-	return
1076
-		"if (!function_exists('$nom')) {\n"
1077
-		. "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
-		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1079
-		. "}\n";
1062
+    if (!$val) {
1063
+        $val = array();
1064
+    }
1065
+
1066
+    $val = serialize($val);
1067
+    $md5 = md5($val);
1068
+
1069
+    if (!defined("_UPDATED_$nom")) {
1070
+        define("_UPDATED_$nom", $val);
1071
+        define("_UPDATED_md5_$nom", $md5);
1072
+    }
1073
+    $val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1074
+
1075
+    return
1076
+        "if (!function_exists('$nom')) {\n"
1077
+        . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
+        . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1079
+        . "}\n";
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1091,15 +1091,15 @@  discard block
 block discarded – undo
1091 1091
 **/
1092 1092
 function plugins_amorcer_plugins_actifs() {
1093 1093
 
1094
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1095
-		include_once(_CACHE_PLUGINS_PATH);
1096
-	} 
1094
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1095
+        include_once(_CACHE_PLUGINS_PATH);
1096
+    } 
1097 1097
 
1098
-	if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099
-		include_once(_CACHE_PLUGINS_OPT);
1100
-	} else {
1101
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1102
-	}
1098
+    if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099
+        include_once(_CACHE_PLUGINS_OPT);
1100
+    } else {
1101
+        spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1102
+    }
1103 1103
 }
1104 1104
 
1105 1105
 /**
@@ -1122,136 +1122,136 @@  discard block
 block discarded – undo
1122 1122
  *     Couples (nom du pipeline => Code PHP à insérer au début du pipeline)
1123 1123
 **/
1124 1124
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) {
1125
-	static $liste_pipe_manquants = array();
1126
-	if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) {
1127
-		$liste_pipe_manquants[] = $pipe_recherche;
1128
-	}
1129
-
1130
-	$prepend_code = array();
1131
-
1132
-	foreach ($ordre as $p => $info) {
1133
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
1134
-		if (isset($plugin_valides[$p])) {
1135
-			$dir_type = $plugin_valides[$p]['dir_type'];
1136
-			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137
-			$plug = $plugin_valides[$p]['dir'];
1138
-			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1139
-			if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140
-				foreach ($info['pipeline'] as $pipe) {
1141
-					$nom = $pipe['nom'];
1142
-					if (isset($pipe['action'])) {
1143
-						$action = $pipe['action'];
1144
-					} else {
1145
-						$action = $nom;
1146
-					}
1147
-					$nomlower = strtolower($nom);
1148
-					if ($nomlower != $nom
1149
-						and isset($GLOBALS['spip_pipeline'][$nom])
1150
-						and !isset($GLOBALS['spip_pipeline'][$nomlower])
1151
-					) {
1152
-						$GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
1153
-						unset($GLOBALS['spip_pipeline'][$nom]);
1154
-					}
1155
-					$nom = $nomlower;
1156
-					// une action vide est une declaration qui ne doit pas etre compilee !
1157
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1158
-					{
1159
-						$GLOBALS['spip_pipeline'][$nom] = "";
1160
-					}
1161
-					if ($action) {
1162
-						if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163
-							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
1164
-								$GLOBALS['spip_pipeline'][$nom], 1);
1165
-						}
1166
-						if (isset($pipe['inclure'])) {
1167
-							$GLOBALS['spip_matrice']["$prefix$action"] =
1168
-								"$root_dir_type:$plug/" . $pipe['inclure'];
1169
-						}
1170
-					}
1171
-				}
1172
-			}
1173
-			if (isset($info['genie']) and count($info['genie'])) {
1174
-				if (!isset($prepend_code['taches_generales_cron'])) {
1175
-					$prepend_code['taches_generales_cron'] = "";
1176
-				}
1177
-				foreach ($info['genie'] as $genie) {
1178
-					$nom = $prefix . $genie['nom'];
1179
-					$periode = max(60, intval($genie['periode']));
1180
-					if (charger_fonction($nom, "genie", true)) {
1181
-						$prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
1182
-					} else {
1183
-						spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR);
1184
-					}
1185
-				}
1186
-			}
1187
-			if (isset($info['style']) and count($info['style'])) {
1188
-				if (!isset($prepend_code['insert_head_css'])) {
1189
-					$prepend_code['insert_head_css'] = "";
1190
-				}
1191
-				if (!isset($prepend_code['header_prive_css'])) {
1192
-					$prepend_code['header_prive_css'] = "";
1193
-				}
1194
-				foreach ($info['style'] as $style) {
1195
-					if (isset($style['path']) and $style['path']) {
1196
-						$code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1197
-					} else {
1198
-						$code = "if (\$f='" . addslashes($style['url']) . "') ";
1199
-					}
1200
-					$code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201
-					if (isset($style['media']) and strlen($style['media'])) {
1202
-						$code .= " media=\"" . addslashes($style['media']) . "\"";
1203
-					}
1204
-					$code .= "/>';\n";
1205
-					if ($style['type'] != 'prive') {
1206
-						$prepend_code['insert_head_css'] .= $code;
1207
-					}
1208
-					if ($style['type'] != 'public') {
1209
-						$prepend_code['header_prive_css'] .= $code;
1210
-					}
1211
-				}
1212
-			}
1213
-			if (!isset($prepend_code['insert_head'])) {
1214
-				$prepend_code['insert_head'] = "";
1215
-			}
1216
-			if (!isset($prepend_code['header_prive'])) {
1217
-				$prepend_code['header_prive'] = "";
1218
-			}
1219
-			if (isset($info['script']) and count($info['script'])) {
1220
-				foreach ($info['script'] as $script) {
1221
-					if (isset($script['path']) and $script['path']) {
1222
-						$code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1223
-					} else {
1224
-						$code = "if (\$f='" . addslashes($script['url']) . "') ";
1225
-					}
1226
-					$code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227
-					if ($script['type'] != 'prive') {
1228
-						$prepend_code['insert_head'] .= $code;
1229
-					}
1230
-					if ($script['type'] != 'public') {
1231
-						$prepend_code['header_prive'] .= $code;
1232
-					}
1233
-				}
1234
-			}
1235
-		}
1236
-	}
1237
-
1238
-	$prepend_code['insert_head'] =
1239
-		"include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n"
1240
-		. "\$val = minipipe('f_jQuery', \$val);\n"
1241
-		. $prepend_code['insert_head'];
1242
-	$prepend_code['header_prive'] =
1243
-		"include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n"
1244
-		. "\$val = minipipe('f_jQuery_prive', \$val);\n"
1245
-		. $prepend_code['header_prive'];
1246
-
1247
-	// on ajoute les pipe qui ont ete recenses manquants
1248
-	foreach ($liste_pipe_manquants as $add_pipe) {
1249
-		if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) {
1250
-			$GLOBALS['spip_pipeline'][$add_pipe] = '';
1251
-		}
1252
-	}
1253
-
1254
-	return $prepend_code;
1125
+    static $liste_pipe_manquants = array();
1126
+    if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) {
1127
+        $liste_pipe_manquants[] = $pipe_recherche;
1128
+    }
1129
+
1130
+    $prepend_code = array();
1131
+
1132
+    foreach ($ordre as $p => $info) {
1133
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
1134
+        if (isset($plugin_valides[$p])) {
1135
+            $dir_type = $plugin_valides[$p]['dir_type'];
1136
+            $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137
+            $plug = $plugin_valides[$p]['dir'];
1138
+            $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1139
+            if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140
+                foreach ($info['pipeline'] as $pipe) {
1141
+                    $nom = $pipe['nom'];
1142
+                    if (isset($pipe['action'])) {
1143
+                        $action = $pipe['action'];
1144
+                    } else {
1145
+                        $action = $nom;
1146
+                    }
1147
+                    $nomlower = strtolower($nom);
1148
+                    if ($nomlower != $nom
1149
+                        and isset($GLOBALS['spip_pipeline'][$nom])
1150
+                        and !isset($GLOBALS['spip_pipeline'][$nomlower])
1151
+                    ) {
1152
+                        $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
1153
+                        unset($GLOBALS['spip_pipeline'][$nom]);
1154
+                    }
1155
+                    $nom = $nomlower;
1156
+                    // une action vide est une declaration qui ne doit pas etre compilee !
1157
+                    if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1158
+                    {
1159
+                        $GLOBALS['spip_pipeline'][$nom] = "";
1160
+                    }
1161
+                    if ($action) {
1162
+                        if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163
+                            $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
1164
+                                $GLOBALS['spip_pipeline'][$nom], 1);
1165
+                        }
1166
+                        if (isset($pipe['inclure'])) {
1167
+                            $GLOBALS['spip_matrice']["$prefix$action"] =
1168
+                                "$root_dir_type:$plug/" . $pipe['inclure'];
1169
+                        }
1170
+                    }
1171
+                }
1172
+            }
1173
+            if (isset($info['genie']) and count($info['genie'])) {
1174
+                if (!isset($prepend_code['taches_generales_cron'])) {
1175
+                    $prepend_code['taches_generales_cron'] = "";
1176
+                }
1177
+                foreach ($info['genie'] as $genie) {
1178
+                    $nom = $prefix . $genie['nom'];
1179
+                    $periode = max(60, intval($genie['periode']));
1180
+                    if (charger_fonction($nom, "genie", true)) {
1181
+                        $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
1182
+                    } else {
1183
+                        spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR);
1184
+                    }
1185
+                }
1186
+            }
1187
+            if (isset($info['style']) and count($info['style'])) {
1188
+                if (!isset($prepend_code['insert_head_css'])) {
1189
+                    $prepend_code['insert_head_css'] = "";
1190
+                }
1191
+                if (!isset($prepend_code['header_prive_css'])) {
1192
+                    $prepend_code['header_prive_css'] = "";
1193
+                }
1194
+                foreach ($info['style'] as $style) {
1195
+                    if (isset($style['path']) and $style['path']) {
1196
+                        $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1197
+                    } else {
1198
+                        $code = "if (\$f='" . addslashes($style['url']) . "') ";
1199
+                    }
1200
+                    $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201
+                    if (isset($style['media']) and strlen($style['media'])) {
1202
+                        $code .= " media=\"" . addslashes($style['media']) . "\"";
1203
+                    }
1204
+                    $code .= "/>';\n";
1205
+                    if ($style['type'] != 'prive') {
1206
+                        $prepend_code['insert_head_css'] .= $code;
1207
+                    }
1208
+                    if ($style['type'] != 'public') {
1209
+                        $prepend_code['header_prive_css'] .= $code;
1210
+                    }
1211
+                }
1212
+            }
1213
+            if (!isset($prepend_code['insert_head'])) {
1214
+                $prepend_code['insert_head'] = "";
1215
+            }
1216
+            if (!isset($prepend_code['header_prive'])) {
1217
+                $prepend_code['header_prive'] = "";
1218
+            }
1219
+            if (isset($info['script']) and count($info['script'])) {
1220
+                foreach ($info['script'] as $script) {
1221
+                    if (isset($script['path']) and $script['path']) {
1222
+                        $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1223
+                    } else {
1224
+                        $code = "if (\$f='" . addslashes($script['url']) . "') ";
1225
+                    }
1226
+                    $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227
+                    if ($script['type'] != 'prive') {
1228
+                        $prepend_code['insert_head'] .= $code;
1229
+                    }
1230
+                    if ($script['type'] != 'public') {
1231
+                        $prepend_code['header_prive'] .= $code;
1232
+                    }
1233
+                }
1234
+            }
1235
+        }
1236
+    }
1237
+
1238
+    $prepend_code['insert_head'] =
1239
+        "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n"
1240
+        . "\$val = minipipe('f_jQuery', \$val);\n"
1241
+        . $prepend_code['insert_head'];
1242
+    $prepend_code['header_prive'] =
1243
+        "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n"
1244
+        . "\$val = minipipe('f_jQuery_prive', \$val);\n"
1245
+        . $prepend_code['header_prive'];
1246
+
1247
+    // on ajoute les pipe qui ont ete recenses manquants
1248
+    foreach ($liste_pipe_manquants as $add_pipe) {
1249
+        if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) {
1250
+            $GLOBALS['spip_pipeline'][$add_pipe] = '';
1251
+        }
1252
+    }
1253
+
1254
+    return $prepend_code;
1255 1255
 }
1256 1256
 
1257 1257
 /**
@@ -1278,44 +1278,44 @@  discard block
 block discarded – undo
1278 1278
 **/
1279 1279
 function pipeline_precompile($prepend_code = array()) {
1280 1280
 
1281
-	$content = "";
1282
-	foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) {
1283
-		$s_inc = "";
1284
-		$s_call = "";
1285
-		$pipe = array_filter(explode('|', $pipeline));
1286
-		// Eclater le pipeline en filtres et appliquer chaque filtre
1287
-		foreach ($pipe as $fonc) {
1288
-			$fonc = trim($fonc);
1289
-			$s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1290
-			if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291
-				$file = $GLOBALS['spip_matrice'][$fonc];
1292
-				$file = "'$file'";
1293
-				// si un _DIR_XXX: est dans la chaine, on extrait la constante
1294
-				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) {
1295
-					$dir = $regs[1];
1296
-					$root_dir = str_replace('_DIR_', '_ROOT_', $dir);
1297
-					if (defined($root_dir)) {
1298
-						$dir = $root_dir;
1299
-					}
1300
-					$file = str_replace($regs[0], "'." . $dir . ".'", $file);
1301
-					$file = str_replace("''.", "", $file);
1302
-					$file = str_replace(constant($dir), '', $file);
1303
-				}
1304
-				$s_inc .= "include_once_check($file);\n";
1305
-			}
1306
-		}
1307
-		if (strlen($s_inc)) {
1308
-			$s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
1309
-		}
1310
-		$content .= "// Pipeline $action \n"
1311
-			. "function execute_pipeline_$action(&\$val){\n"
1312
-			. $s_inc
1313
-			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1314
-			. $s_call
1315
-			. "return \$val;\n}\n";
1316
-	}
1317
-	ecrire_fichier_php(_CACHE_PIPELINES, $content);
1318
-	clear_path_cache();
1281
+    $content = "";
1282
+    foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) {
1283
+        $s_inc = "";
1284
+        $s_call = "";
1285
+        $pipe = array_filter(explode('|', $pipeline));
1286
+        // Eclater le pipeline en filtres et appliquer chaque filtre
1287
+        foreach ($pipe as $fonc) {
1288
+            $fonc = trim($fonc);
1289
+            $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1290
+            if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291
+                $file = $GLOBALS['spip_matrice'][$fonc];
1292
+                $file = "'$file'";
1293
+                // si un _DIR_XXX: est dans la chaine, on extrait la constante
1294
+                if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) {
1295
+                    $dir = $regs[1];
1296
+                    $root_dir = str_replace('_DIR_', '_ROOT_', $dir);
1297
+                    if (defined($root_dir)) {
1298
+                        $dir = $root_dir;
1299
+                    }
1300
+                    $file = str_replace($regs[0], "'." . $dir . ".'", $file);
1301
+                    $file = str_replace("''.", "", $file);
1302
+                    $file = str_replace(constant($dir), '', $file);
1303
+                }
1304
+                $s_inc .= "include_once_check($file);\n";
1305
+            }
1306
+        }
1307
+        if (strlen($s_inc)) {
1308
+            $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
1309
+        }
1310
+        $content .= "// Pipeline $action \n"
1311
+            . "function execute_pipeline_$action(&\$val){\n"
1312
+            . $s_inc
1313
+            . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1314
+            . $s_call
1315
+            . "return \$val;\n}\n";
1316
+    }
1317
+    ecrire_fichier_php(_CACHE_PIPELINES, $content);
1318
+    clear_path_cache();
1319 1319
 }
1320 1320
 
1321 1321
 
@@ -1328,12 +1328,12 @@  discard block
 block discarded – undo
1328 1328
  *     true si le plugin est actif, false sinon
1329 1329
 **/
1330 1330
 function plugin_est_installe($plug_path) {
1331
-	$plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array();
1332
-	if (!$plugin_installes) {
1333
-		return false;
1334
-	}
1331
+    $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array();
1332
+    if (!$plugin_installes) {
1333
+        return false;
1334
+    }
1335 1335
 
1336
-	return in_array($plug_path, $plugin_installes);
1336
+    return in_array($plug_path, $plugin_installes);
1337 1337
 }
1338 1338
 
1339 1339
 
@@ -1346,37 +1346,37 @@  discard block
 block discarded – undo
1346 1346
  * @uses plugins_installer_dist()
1347 1347
  **/
1348 1348
 function plugin_installes_meta() {
1349
-	if (isset($GLOBALS['fichier_php_compile_recent'])) {
1350
-		// attendre eventuellement l'invalidation du cache opcode
1351
-		spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
1352
-	}
1353
-
1354
-	$installer_plugins = charger_fonction('installer', 'plugins');
1355
-	$meta_plug_installes = array();
1356
-	foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) {
1357
-		if ($plug = $resume['dir']) {
1358
-			$infos = $installer_plugins($plug, 'install', $resume['dir_type']);
1359
-			if ($infos) {
1360
-				if (!is_array($infos) or $infos['install_test'][0]) {
1361
-					$meta_plug_installes[] = $plug;
1362
-				}
1363
-				if (is_array($infos)) {
1364
-					list($ok, $trace) = $infos['install_test'];
1365
-					include_spip('inc/filtres_boites');
1366
-					echo "<div class='install-plugins svp_retour'>"
1367
-						. boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))),
1368
-							($ok ? 'success' : 'error'))
1369
-						. $trace
1370
-						. "<div class='result'>"
1371
-						. ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
1372
-						. "</div>"
1373
-						. boite_fermer()
1374
-						. "</div>";
1375
-				}
1376
-			}
1377
-		}
1378
-	}
1379
-	ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non');
1349
+    if (isset($GLOBALS['fichier_php_compile_recent'])) {
1350
+        // attendre eventuellement l'invalidation du cache opcode
1351
+        spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
1352
+    }
1353
+
1354
+    $installer_plugins = charger_fonction('installer', 'plugins');
1355
+    $meta_plug_installes = array();
1356
+    foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) {
1357
+        if ($plug = $resume['dir']) {
1358
+            $infos = $installer_plugins($plug, 'install', $resume['dir_type']);
1359
+            if ($infos) {
1360
+                if (!is_array($infos) or $infos['install_test'][0]) {
1361
+                    $meta_plug_installes[] = $plug;
1362
+                }
1363
+                if (is_array($infos)) {
1364
+                    list($ok, $trace) = $infos['install_test'];
1365
+                    include_spip('inc/filtres_boites');
1366
+                    echo "<div class='install-plugins svp_retour'>"
1367
+                        . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))),
1368
+                            ($ok ? 'success' : 'error'))
1369
+                        . $trace
1370
+                        . "<div class='result'>"
1371
+                        . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
1372
+                        . "</div>"
1373
+                        . boite_fermer()
1374
+                        . "</div>";
1375
+                }
1376
+            }
1377
+        }
1378
+    }
1379
+    ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non');
1380 1380
 }
1381 1381
 
1382 1382
 /**
@@ -1390,29 +1390,29 @@  discard block
 block discarded – undo
1390 1390
  *     Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante
1391 1391
 **/
1392 1392
 function ecrire_fichier_php($nom, $contenu, $comment = '') {
1393
-	if (!isset($GLOBALS['fichier_php_compile_recent'])) {
1394
-		$GLOBALS['fichier_php_compile_recent'] = 0;
1395
-	}
1396
-
1397
-	$contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1398
-	// si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399
-	// si pas de modif on ne touche pas au fichier initial
1400
-	if (file_exists($nom)) {
1401
-		if (substr($nom, -4) == '.php') {
1402
-			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
-		}
1404
-		else {
1405
-			$fichier_tmp = $nom . '.tmp';
1406
-		}
1407
-		file_put_contents($fichier_tmp, $contenu);
1408
-		if(md5_file($nom) == md5_file($fichier_tmp)) {
1409
-			$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410
-			@unlink($fichier_tmp);
1411
-			return;
1412
-		}
1413
-		@unlink($fichier_tmp);
1414
-	}
1415
-	ecrire_fichier($nom, $contenu);
1416
-	$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1417
-	spip_clear_opcode_cache(realpath($nom));
1393
+    if (!isset($GLOBALS['fichier_php_compile_recent'])) {
1394
+        $GLOBALS['fichier_php_compile_recent'] = 0;
1395
+    }
1396
+
1397
+    $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1398
+    // si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399
+    // si pas de modif on ne touche pas au fichier initial
1400
+    if (file_exists($nom)) {
1401
+        if (substr($nom, -4) == '.php') {
1402
+            $fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
+        }
1404
+        else {
1405
+            $fichier_tmp = $nom . '.tmp';
1406
+        }
1407
+        file_put_contents($fichier_tmp, $contenu);
1408
+        if(md5_file($nom) == md5_file($fichier_tmp)) {
1409
+            $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410
+            @unlink($fichier_tmp);
1411
+            return;
1412
+        }
1413
+        @unlink($fichier_tmp);
1414
+    }
1415
+    ecrire_fichier($nom, $contenu);
1416
+    $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1417
+    spip_clear_opcode_cache(realpath($nom));
1418 1418
 }
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@
 block discarded – undo
165 165
  * @param string $primary
166 166
  * @param array $rows
167 167
  * @param string $serveur
168
- * @return array
168
+ * @return string[]
169 169
  */
170 170
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
171 171
 	# calculer le {id_article IN()} et le {... as points}
Please login to merge, or discard this patch.
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,111 +49,111 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = array(),
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = array(),
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = array();
60
-	$delai_fraicheur = min(_DELAI_CACHE_resultats,
61
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
-
63
-	// si recherche n'est pas dans le contexte, on va prendre en globals
64
-	// ca permet de faire des inclure simple.
65
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
-		$recherche = $GLOBALS['recherche'];
67
-	}
68
-
69
-	// traiter le cas {recherche?}
70
-	if ($cond and !strlen($recherche)) {
71
-		return array(
72
-			"0 as points" /* as points */, /* where */
73
-			''
74
-		);
75
-	}
76
-
77
-
78
-	$rechercher = false;
79
-
80
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
-	if (!isset($cache[$serveur][$table][$recherche])) {
82
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
-		$hash = substr(md5($recherche . $table), 0, 16);
84
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
-		$row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
-			$where . " AND $where_resultat_recent", '', '', '0,1');
87
-		if (!$row
88
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
-		) {
90
-			$rechercher = true;
91
-		}
92
-	}
93
-
94
-	// si on n'a pas encore traite les donnees dans une boucle precedente
95
-	if ($rechercher) {
96
-		//$tables = liste_des_champs();
97
-		$x = objet_type($table);
98
-		$points = recherche_en_base($recherche,
99
-			$x,
100
-			array(
101
-				'score' => true,
102
-				'toutvoir' => true,
103
-				'jointures' => true
104
-			),
105
-			$serveur);
106
-		// pas de résultat, pas de point
107
-		$points = isset($points[$x]) ? $points[$x] : array();
108
-
109
-		// permettre aux plugins de modifier le resultat
110
-		$points = pipeline('prepare_recherche', array(
111
-			'args' => array(
112
-				'type' => $x,
113
-				'recherche' => $recherche,
114
-				'serveur' => $serveur,
115
-				'modificateurs' => $modificateurs
116
-			),
117
-			'data' => $points
118
-		));
119
-
120
-		// supprimer les anciens resultats de cette recherche
121
-		// et les resultats trop vieux avec une marge
122
-		// pas de AS resultats dans un delete (mysql)
123
-		$whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
-			array("recherche", "table_objet", "serveur"), $where);
125
-
126
-		sql_delete('spip_resultats',
127
-			"NOT($where_resultat_recent) OR ($whered)");
128
-
129
-		// inserer les resultats dans la table de cache des resultats
130
-		if (count($points)) {
131
-			$tab_couples = array();
132
-			foreach ($points as $id => $p) {
133
-				$tab_couples[] = array(
134
-					'recherche' => $hash,
135
-					'id' => $id,
136
-					'points' => $p['score'],
137
-					'table_objet' => $table,
138
-					'serveur' => $hash_serv,
139
-				);
140
-			}
141
-			sql_insertq_multi('spip_resultats', $tab_couples, array());
142
-		}
143
-	}
144
-
145
-	if (!isset($cache[$serveur][$table][$recherche])) {
146
-		if (!$serveur) {
147
-			$cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
-		} else {
149
-			if (sql_countsel('spip_resultats as resultats', $where)) {
150
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
-			}
152
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
-		}
154
-	}
155
-
156
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = array();
60
+    $delai_fraicheur = min(_DELAI_CACHE_resultats,
61
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
+
63
+    // si recherche n'est pas dans le contexte, on va prendre en globals
64
+    // ca permet de faire des inclure simple.
65
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
+        $recherche = $GLOBALS['recherche'];
67
+    }
68
+
69
+    // traiter le cas {recherche?}
70
+    if ($cond and !strlen($recherche)) {
71
+        return array(
72
+            "0 as points" /* as points */, /* where */
73
+            ''
74
+        );
75
+    }
76
+
77
+
78
+    $rechercher = false;
79
+
80
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
+    if (!isset($cache[$serveur][$table][$recherche])) {
82
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
+        $hash = substr(md5($recherche . $table), 0, 16);
84
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
+        $row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
+            $where . " AND $where_resultat_recent", '', '', '0,1');
87
+        if (!$row
88
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
+        ) {
90
+            $rechercher = true;
91
+        }
92
+    }
93
+
94
+    // si on n'a pas encore traite les donnees dans une boucle precedente
95
+    if ($rechercher) {
96
+        //$tables = liste_des_champs();
97
+        $x = objet_type($table);
98
+        $points = recherche_en_base($recherche,
99
+            $x,
100
+            array(
101
+                'score' => true,
102
+                'toutvoir' => true,
103
+                'jointures' => true
104
+            ),
105
+            $serveur);
106
+        // pas de résultat, pas de point
107
+        $points = isset($points[$x]) ? $points[$x] : array();
108
+
109
+        // permettre aux plugins de modifier le resultat
110
+        $points = pipeline('prepare_recherche', array(
111
+            'args' => array(
112
+                'type' => $x,
113
+                'recherche' => $recherche,
114
+                'serveur' => $serveur,
115
+                'modificateurs' => $modificateurs
116
+            ),
117
+            'data' => $points
118
+        ));
119
+
120
+        // supprimer les anciens resultats de cette recherche
121
+        // et les resultats trop vieux avec une marge
122
+        // pas de AS resultats dans un delete (mysql)
123
+        $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
+            array("recherche", "table_objet", "serveur"), $where);
125
+
126
+        sql_delete('spip_resultats',
127
+            "NOT($where_resultat_recent) OR ($whered)");
128
+
129
+        // inserer les resultats dans la table de cache des resultats
130
+        if (count($points)) {
131
+            $tab_couples = array();
132
+            foreach ($points as $id => $p) {
133
+                $tab_couples[] = array(
134
+                    'recherche' => $hash,
135
+                    'id' => $id,
136
+                    'points' => $p['score'],
137
+                    'table_objet' => $table,
138
+                    'serveur' => $hash_serv,
139
+                );
140
+            }
141
+            sql_insertq_multi('spip_resultats', $tab_couples, array());
142
+        }
143
+    }
144
+
145
+    if (!isset($cache[$serveur][$table][$recherche])) {
146
+        if (!$serveur) {
147
+            $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
+        } else {
149
+            if (sql_countsel('spip_resultats as resultats', $where)) {
150
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
+            }
152
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
+        }
154
+    }
155
+
156
+    return $cache[$serveur][$table][$recherche];
157 157
 }
158 158
 
159 159
 
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
  * @return array
170 170
  */
171 171
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
172
-	# calculer le {id_article IN()} et le {... as points}
173
-	if (!count($rows)) {
174
-		return array("''", "0=1");
175
-	} else {
176
-		$listes_ids = array();
177
-		$select = '0';
178
-		foreach ($rows as $r) {
179
-			$listes_ids[$r['points']][] = $r['id'];
180
-		}
181
-
182
-		foreach ($listes_ids as $p => $ids) {
183
-			$select .= "+$p*(" .
184
-				sql_in("$table.$primary", $ids, '', $serveur)
185
-				. ") ";
186
-		}
187
-
188
-		return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
-	}
172
+    # calculer le {id_article IN()} et le {... as points}
173
+    if (!count($rows)) {
174
+        return array("''", "0=1");
175
+    } else {
176
+        $listes_ids = array();
177
+        $select = '0';
178
+        foreach ($rows as $r) {
179
+            $listes_ids[$r['points']][] = $r['id'];
180
+        }
181
+
182
+        foreach ($listes_ids as $p => $ids) {
183
+            $select .= "+$p*(" .
184
+                sql_in("$table.$primary", $ids, '', $serveur)
185
+                . ") ";
186
+        }
187
+
188
+        return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
+    }
190 190
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81 81
 	if (!isset($cache[$serveur][$table][$recherche])) {
82 82
 		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
-		$hash = substr(md5($recherche . $table), 0, 16);
84
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
83
+		$hash = substr(md5($recherche.$table), 0, 16);
84
+		$where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')";
85 85
 		$row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
-			$where . " AND $where_resultat_recent", '', '', '0,1');
86
+			$where." AND $where_resultat_recent", '', '', '0,1');
87 87
 		if (!$row
88 88
 			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89 89
 		) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 
182 182
 		foreach ($listes_ids as $p => $ids) {
183
-			$select .= "+$p*(" .
183
+			$select .= "+$p*(".
184 184
 				sql_in("$table.$primary", $ids, '', $serveur)
185 185
 				. ") ";
186 186
 		}
Please login to merge, or discard this patch.
ecrire/inc/rubriques.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  *     Ancien statut de la rubrique
51 51
  * @param bool $postdate
52 52
  *     true pour recalculer aussi la date du prochain article post-daté
53
- * @return bool
53
+ * @return boolean|null
54 54
  *     true si le statut change effectivement
55 55
  **/
56 56
 function calculer_rubriques_if($id_rubrique, $modifs, $statut_ancien = '', $postdate = false) {
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * de la rubrique parente lorsque langue_choisie est différent de oui,
425 425
  * et les corrige.
426 426
  *
427
- * @return bool
427
+ * @return boolean|string
428 428
  *     true si un changement a eu lieu
429 429
  **/
430 430
 function calculer_langues_rubriques_etape() {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,10 +78,12 @@
 block discarded – undo
78 78
 		}
79 79
 	}
80 80
 
81
-	if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
81
+	if ($neuf) {
82
+	    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
82 83
 	{
83 84
 		ecrire_meta("date_calcul_rubriques", date("U"));
84 85
 	}
86
+	}
85 87
 
86 88
 	$langues = calculer_langues_utilisees();
87 89
 	ecrire_meta('langues_utilisees', $langues);
Please login to merge, or discard this patch.
Indentation   +498 added lines, -498 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
 
@@ -54,37 +54,37 @@  discard block
 block discarded – undo
54 54
  *     true si le statut change effectivement
55 55
  **/
56 56
 function calculer_rubriques_if($id_rubrique, $modifs, $statut_ancien = '', $postdate = false) {
57
-	$neuf = false;
58
-	if ($statut_ancien == 'publie') {
59
-		if (isset($modifs['statut'])
60
-			or isset($modifs['id_rubrique'])
61
-			or ($postdate and strtotime($postdate) > time())
62
-		) {
63
-			$neuf |= depublier_branche_rubrique_if($id_rubrique);
64
-		}
65
-		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
66
-		if ($postdate) {
67
-			calculer_prochain_postdate(true);
68
-			$neuf |= (strtotime($postdate) <= time()); // par securite
69
-		} elseif (isset($modifs['id_rubrique'])) {
70
-			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
71
-		}
72
-	} elseif (isset($modifs['statut']) and $modifs['statut'] == 'publie') {
73
-		if ($postdate) {
74
-			calculer_prochain_postdate(true);
75
-			$neuf |= (strtotime($postdate) <= time()); // par securite
76
-		} else {
77
-			$neuf |= publier_branche_rubrique($id_rubrique);
78
-		}
79
-	}
80
-
81
-	if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
82
-	{
83
-		ecrire_meta("date_calcul_rubriques", date("U"));
84
-	}
85
-
86
-	$langues = calculer_langues_utilisees();
87
-	ecrire_meta('langues_utilisees', $langues);
57
+    $neuf = false;
58
+    if ($statut_ancien == 'publie') {
59
+        if (isset($modifs['statut'])
60
+            or isset($modifs['id_rubrique'])
61
+            or ($postdate and strtotime($postdate) > time())
62
+        ) {
63
+            $neuf |= depublier_branche_rubrique_if($id_rubrique);
64
+        }
65
+        // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
66
+        if ($postdate) {
67
+            calculer_prochain_postdate(true);
68
+            $neuf |= (strtotime($postdate) <= time()); // par securite
69
+        } elseif (isset($modifs['id_rubrique'])) {
70
+            $neuf |= publier_branche_rubrique($modifs['id_rubrique']);
71
+        }
72
+    } elseif (isset($modifs['statut']) and $modifs['statut'] == 'publie') {
73
+        if ($postdate) {
74
+            calculer_prochain_postdate(true);
75
+            $neuf |= (strtotime($postdate) <= time()); // par securite
76
+        } else {
77
+            $neuf |= publier_branche_rubrique($id_rubrique);
78
+        }
79
+    }
80
+
81
+    if ($neuf) // Sauver la date de la derniere mise a jour (pour menu_rubriques)
82
+    {
83
+        ecrire_meta("date_calcul_rubriques", date("U"));
84
+    }
85
+
86
+    $langues = calculer_langues_utilisees();
87
+    ecrire_meta('langues_utilisees', $langues);
88 88
 }
89 89
 
90 90
 
@@ -102,19 +102,19 @@  discard block
 block discarded – undo
102 102
  *     true si le statut change effectivement
103 103
  */
104 104
 function publier_branche_rubrique($id_rubrique) {
105
-	$id_pred = $id_rubrique;
106
-	while (true) {
107
-		sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
108
-			"id_rubrique=" . intval($id_rubrique));
109
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
110
-		if (!$id_parent) {
111
-			break;
112
-		}
113
-		$id_rubrique = $id_parent;
114
-	}
105
+    $id_pred = $id_rubrique;
106
+    while (true) {
107
+        sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
108
+            "id_rubrique=" . intval($id_rubrique));
109
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
110
+        if (!$id_parent) {
111
+            break;
112
+        }
113
+        $id_rubrique = $id_parent;
114
+    }
115 115
 
116 116
 #	spip_log(" publier_branche_rubrique($id_rubrique $id_pred");
117
-	return $id_pred != $id_rubrique;
117
+    return $id_pred != $id_rubrique;
118 118
 }
119 119
 
120 120
 /**
@@ -132,21 +132,21 @@  discard block
 block discarded – undo
132 132
  *     true si le statut change effectivement
133 133
  */
134 134
 function depublier_branche_rubrique_if($id_rubrique) {
135
-	$date = date('Y-m-d H:i:s'); // figer la date
135
+    $date = date('Y-m-d H:i:s'); // figer la date
136 136
 
137
-	#	spip_log("depublier_branche_rubrique($id_rubrique ?");
138
-	$id_pred = $id_rubrique;
139
-	while ($id_pred) {
137
+    #	spip_log("depublier_branche_rubrique($id_rubrique ?");
138
+    $id_pred = $id_rubrique;
139
+    while ($id_pred) {
140 140
 
141
-		if (!depublier_rubrique_if($id_pred, $date)) {
142
-			return $id_pred != $id_rubrique;
143
-		}
144
-		// passer au parent si on a depublie
145
-		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
146
-		$id_pred = $r['id_parent'];
147
-	}
141
+        if (!depublier_rubrique_if($id_pred, $date)) {
142
+            return $id_pred != $id_rubrique;
143
+        }
144
+        // passer au parent si on a depublie
145
+        $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
146
+        $id_pred = $r['id_parent'];
147
+    }
148 148
 
149
-	return $id_pred != $id_rubrique;
149
+    return $id_pred != $id_rubrique;
150 150
 }
151 151
 
152 152
 /**
@@ -163,57 +163,57 @@  discard block
 block discarded – undo
163 163
  *    true si la rubrique a été dépubliée
164 164
  */
165 165
 function depublier_rubrique_if($id_rubrique, $date = null) {
166
-	if (is_null($date)) {
167
-		$date = date('Y-m-d H:i:s');
168
-	}
169
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
170
-		" AND date <= " . sql_quote($date) : '';
171
-
172
-	if (!$id_rubrique = intval($id_rubrique)) {
173
-		return false;
174
-	}
175
-
176
-	// verifier qu'elle existe et est bien publiee
177
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
178
-	if (!$r or $r['statut'] !== 'publie') {
179
-		return false;
180
-	}
181
-
182
-	// On met le nombre de chaque type d'enfants dans un tableau
183
-	// Le type de l'objet est au pluriel
184
-	$compte = array(
185
-		'articles' => sql_countsel("spip_articles",
186
-			"id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
187
-		'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
188
-		'documents' => sql_countsel(
189
-			"spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
190
-			"L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
191
-	);
192
-
193
-	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
194
-	$compte = pipeline('objet_compte_enfants',
195
-		array(
196
-			'args' => array(
197
-				'objet' => 'rubrique',
198
-				'id_objet' => $id_rubrique,
199
-				'statut' => 'publie',
200
-				'date' => $date
201
-			),
202
-			'data' => $compte
203
-		)
204
-	);
205
-
206
-	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
207
-	foreach ($compte as $objet => $n) {
208
-		if ($n) {
209
-			return false;
210
-		}
211
-	}
212
-
213
-	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
166
+    if (is_null($date)) {
167
+        $date = date('Y-m-d H:i:s');
168
+    }
169
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
170
+        " AND date <= " . sql_quote($date) : '';
171
+
172
+    if (!$id_rubrique = intval($id_rubrique)) {
173
+        return false;
174
+    }
175
+
176
+    // verifier qu'elle existe et est bien publiee
177
+    $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
178
+    if (!$r or $r['statut'] !== 'publie') {
179
+        return false;
180
+    }
181
+
182
+    // On met le nombre de chaque type d'enfants dans un tableau
183
+    // Le type de l'objet est au pluriel
184
+    $compte = array(
185
+        'articles' => sql_countsel("spip_articles",
186
+            "id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
187
+        'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
188
+        'documents' => sql_countsel(
189
+            "spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
190
+            "L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
191
+    );
192
+
193
+    // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
194
+    $compte = pipeline('objet_compte_enfants',
195
+        array(
196
+            'args' => array(
197
+                'objet' => 'rubrique',
198
+                'id_objet' => $id_rubrique,
199
+                'statut' => 'publie',
200
+                'date' => $date
201
+            ),
202
+            'data' => $compte
203
+        )
204
+    );
205
+
206
+    // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
207
+    foreach ($compte as $objet => $n) {
208
+        if ($n) {
209
+            return false;
210
+        }
211
+    }
212
+
213
+    sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
214 214
 
215 215
 #		spip_log("depublier_rubrique $id_pred");
216
-	return true;
216
+    return true;
217 217
 }
218 218
 
219 219
 
@@ -236,18 +236,18 @@  discard block
 block discarded – undo
236 236
  **/
237 237
 function calculer_rubriques() {
238 238
 
239
-	calculer_rubriques_publiees();
239
+    calculer_rubriques_publiees();
240 240
 
241
-	// Apres chaque (de)publication 
242
-	// recalculer les langues utilisees sur le site
243
-	$langues = calculer_langues_utilisees();
244
-	ecrire_meta('langues_utilisees', $langues);
241
+    // Apres chaque (de)publication 
242
+    // recalculer les langues utilisees sur le site
243
+    $langues = calculer_langues_utilisees();
244
+    ecrire_meta('langues_utilisees', $langues);
245 245
 
246
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
247
-	ecrire_meta("date_calcul_rubriques", date("U"));
246
+    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
247
+    ecrire_meta("date_calcul_rubriques", date("U"));
248 248
 
249
-	// on calcule la date du prochain article post-date
250
-	calculer_prochain_postdate();
249
+    // on calcule la date du prochain article post-date
250
+    calculer_prochain_postdate();
251 251
 }
252 252
 
253 253
 
@@ -264,51 +264,51 @@  discard block
 block discarded – undo
264 264
  **/
265 265
 function calculer_rubriques_publiees() {
266 266
 
267
-	// Mettre les compteurs a zero
268
-	sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa'));
269
-
270
-	//
271
-	// Publier et dater les rubriques qui ont un article publie
272
-	//
273
-
274
-	// Afficher les articles post-dates ?
275
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
276
-		"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
277
-
278
-	$r = sql_select(
279
-		"R.id_rubrique AS id, max(A.date) AS date_h",
280
-		"spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique",
281
-		"A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
282
-	while ($row = sql_fetch($r)) {
283
-		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
284
-			"id_rubrique=" . intval($row['id']));
285
-	}
286
-
287
-	// point d'entree pour permettre a des plugins de gerer le statut
288
-	// autrement (par ex: toute rubrique est publiee des sa creation)
289
-	// Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
290
-	// c'est statut_tmp/date_tmp qu'il doit modifier
291
-	// [C'est un trigger... a renommer en trig_calculer_rubriques ?]
292
-	pipeline('calculer_rubriques', null);
293
-
294
-
295
-	// Les rubriques qui ont une rubrique fille plus recente
296
-	// on tourne tant que les donnees remontent vers la racine.
297
-	do {
298
-		$continuer = false;
299
-		$r = sql_select(
300
-			"R.id_rubrique AS id, max(SR.date_tmp) AS date_h",
301
-			"spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent",
302
-			"(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
303
-		while ($row = sql_fetch($r)) {
304
-			sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
305
-				"id_rubrique=" . intval($row['id']));
306
-			$continuer = true;
307
-		}
308
-	} while ($continuer);
309
-
310
-	// Enregistrement des modifs
311
-	sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp'));
267
+    // Mettre les compteurs a zero
268
+    sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa'));
269
+
270
+    //
271
+    // Publier et dater les rubriques qui ont un article publie
272
+    //
273
+
274
+    // Afficher les articles post-dates ?
275
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
276
+        "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
277
+
278
+    $r = sql_select(
279
+        "R.id_rubrique AS id, max(A.date) AS date_h",
280
+        "spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique",
281
+        "A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
282
+    while ($row = sql_fetch($r)) {
283
+        sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
284
+            "id_rubrique=" . intval($row['id']));
285
+    }
286
+
287
+    // point d'entree pour permettre a des plugins de gerer le statut
288
+    // autrement (par ex: toute rubrique est publiee des sa creation)
289
+    // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
290
+    // c'est statut_tmp/date_tmp qu'il doit modifier
291
+    // [C'est un trigger... a renommer en trig_calculer_rubriques ?]
292
+    pipeline('calculer_rubriques', null);
293
+
294
+
295
+    // Les rubriques qui ont une rubrique fille plus recente
296
+    // on tourne tant que les donnees remontent vers la racine.
297
+    do {
298
+        $continuer = false;
299
+        $r = sql_select(
300
+            "R.id_rubrique AS id, max(SR.date_tmp) AS date_h",
301
+            "spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent",
302
+            "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
303
+        while ($row = sql_fetch($r)) {
304
+            sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
305
+                "id_rubrique=" . intval($row['id']));
306
+            $continuer = true;
307
+        }
308
+    } while ($continuer);
309
+
310
+    // Enregistrement des modifs
311
+    sql_update('spip_rubriques', array('date' => 'date_tmp', 'statut' => 'statut_tmp'));
312 312
 }
313 313
 
314 314
 /**
@@ -323,99 +323,99 @@  discard block
 block discarded – undo
323 323
  * @return void
324 324
  **/
325 325
 function propager_les_secteurs() {
326
-	// Profondeur 0
327
-	// Toutes les rubriques racines sont de profondeur 0
328
-	// et fixer les id_secteur des rubriques racines
329
-	sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0");
330
-	// Toute rubrique non racine est de profondeur >0
331
-	sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0");
332
-
333
-	// securite : pas plus d'iteration que de rubriques dans la base
334
-	$maxiter = sql_countsel("spip_rubriques");
335
-
336
-	// reparer les rubriques qui n'ont pas l'id_secteur de leur parent
337
-	// on fait profondeur par profondeur
338
-
339
-	$prof = 0;
340
-	do {
341
-		$continuer = false;
342
-
343
-		// Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
344
-		// on fixe le profondeur $prof+1
345
-
346
-		// Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
347
-		// on teste A.profondeur > $prof+1 car :
348
-		// - toutes les rubriques de profondeur 0 à $prof sont bonnes
349
-		// - si A.profondeur = $prof+1 c'est bon
350
-		// - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
351
-		$maxiter2 = $maxiter;
352
-		while ($maxiter2--
353
-			and $rows = sql_allfetsel(
354
-				"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
355
-				"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
356
-				"R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
357
-				"", "R.id_secteur", "0,100")) {
358
-
359
-			$id_secteur = null;
360
-			$ids = array();
361
-			while ($row = array_shift($rows)) {
362
-				if ($row['id_secteur'] !== $id_secteur) {
363
-					if (count($ids)) {
364
-						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
365
-							sql_in('id_rubrique', $ids));
366
-					}
367
-					$id_secteur = $row['id_secteur'];
368
-					$ids = array();
369
-				}
370
-				$ids[] = $row['id'];
371
-			}
372
-			if (count($ids)) {
373
-				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
374
-					sql_in('id_rubrique', $ids));
375
-			}
376
-		}
377
-
378
-
379
-		// Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
380
-		$maxiter2 = $maxiter;
381
-		while ($maxiter2--
382
-			and $rows = sql_allfetsel(
383
-				"id_rubrique as id",
384
-				"spip_rubriques",
385
-				"profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
386
-					"spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
387
-			$rows = array_column($rows, 'id');
388
-			sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
389
-		}
390
-
391
-		// ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
392
-		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
393
-		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
394
-		// on arrete les frais
395
-		if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
396
-			$prof++;
397
-			$continuer = true;
398
-		}
399
-	} while ($continuer and $maxiter--);
400
-
401
-	// loger si la table des rubriques semble foireuse
402
-	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
403
-	if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
404
-		spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
405
-			_LOG_CRITIQUE);
406
-		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
407
-	}
408
-
409
-	// reparer les articles
410
-	$r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R",
411
-		"A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
412
-
413
-	while ($row = sql_fetch($r)) {
414
-		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
415
-	}
416
-
417
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
418
-	pipeline('trig_propager_les_secteurs', '');
326
+    // Profondeur 0
327
+    // Toutes les rubriques racines sont de profondeur 0
328
+    // et fixer les id_secteur des rubriques racines
329
+    sql_update('spip_rubriques', array('id_secteur' => 'id_rubrique', 'profondeur' => 0), "id_parent=0");
330
+    // Toute rubrique non racine est de profondeur >0
331
+    sql_updateq('spip_rubriques', array('profondeur' => 1), "id_parent<>0 AND profondeur=0");
332
+
333
+    // securite : pas plus d'iteration que de rubriques dans la base
334
+    $maxiter = sql_countsel("spip_rubriques");
335
+
336
+    // reparer les rubriques qui n'ont pas l'id_secteur de leur parent
337
+    // on fait profondeur par profondeur
338
+
339
+    $prof = 0;
340
+    do {
341
+        $continuer = false;
342
+
343
+        // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
344
+        // on fixe le profondeur $prof+1
345
+
346
+        // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
347
+        // on teste A.profondeur > $prof+1 car :
348
+        // - toutes les rubriques de profondeur 0 à $prof sont bonnes
349
+        // - si A.profondeur = $prof+1 c'est bon
350
+        // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
351
+        $maxiter2 = $maxiter;
352
+        while ($maxiter2--
353
+            and $rows = sql_allfetsel(
354
+                "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
355
+                "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
356
+                "R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
357
+                "", "R.id_secteur", "0,100")) {
358
+
359
+            $id_secteur = null;
360
+            $ids = array();
361
+            while ($row = array_shift($rows)) {
362
+                if ($row['id_secteur'] !== $id_secteur) {
363
+                    if (count($ids)) {
364
+                        sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
365
+                            sql_in('id_rubrique', $ids));
366
+                    }
367
+                    $id_secteur = $row['id_secteur'];
368
+                    $ids = array();
369
+                }
370
+                $ids[] = $row['id'];
371
+            }
372
+            if (count($ids)) {
373
+                sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1),
374
+                    sql_in('id_rubrique', $ids));
375
+            }
376
+        }
377
+
378
+
379
+        // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
380
+        $maxiter2 = $maxiter;
381
+        while ($maxiter2--
382
+            and $rows = sql_allfetsel(
383
+                "id_rubrique as id",
384
+                "spip_rubriques",
385
+                "profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
386
+                    "spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
387
+            $rows = array_column($rows, 'id');
388
+            sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
389
+        }
390
+
391
+        // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
392
+        // si pas de rubrique a profondeur $prof+1 pas la peine de continuer
393
+        // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
394
+        // on arrete les frais
395
+        if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
396
+            $prof++;
397
+            $continuer = true;
398
+        }
399
+    } while ($continuer and $maxiter--);
400
+
401
+    // loger si la table des rubriques semble foireuse
402
+    // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
403
+    if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
404
+        spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
405
+            _LOG_CRITIQUE);
406
+        sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
407
+    }
408
+
409
+    // reparer les articles
410
+    $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R",
411
+        "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
412
+
413
+    while ($row = sql_fetch($r)) {
414
+        sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
415
+    }
416
+
417
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
418
+    pipeline('trig_propager_les_secteurs', '');
419 419
 }
420 420
 
421 421
 
@@ -430,17 +430,17 @@  discard block
 block discarded – undo
430 430
  *     true si un changement a eu lieu
431 431
  **/
432 432
 function calculer_langues_rubriques_etape() {
433
-	$s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R",
434
-		"A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
433
+    $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R",
434
+        "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
435 435
 
436
-	$t = false;
437
-	while ($row = sql_fetch($s)) {
438
-		$id_rubrique = $row['id_rubrique'];
439
-		$t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
440
-			"id_rubrique=" . intval($id_rubrique));
441
-	}
436
+    $t = false;
437
+    while ($row = sql_fetch($s)) {
438
+        $id_rubrique = $row['id_rubrique'];
439
+        $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
440
+            "id_rubrique=" . intval($id_rubrique));
441
+    }
442 442
 
443
-	return $t;
443
+    return $t;
444 444
 }
445 445
 
446 446
 /**
@@ -460,30 +460,30 @@  discard block
 block discarded – undo
460 460
  **/
461 461
 function calculer_langues_rubriques() {
462 462
 
463
-	// rubriques (recursivite)
464
-	sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'),
465
-		"id_parent=0 AND langue_choisie != 'oui'");
466
-	while (calculer_langues_rubriques_etape()) {
467
-		;
468
-	}
469
-
470
-	// articles
471
-	$s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R",
472
-		"A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
473
-	while ($row = sql_fetch($s)) {
474
-		$id_article = $row['id_article'];
475
-		sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
476
-			"id_article=" . intval($id_article));
477
-	}
478
-
479
-	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
480
-
481
-		$langues = calculer_langues_utilisees();
482
-		ecrire_meta('langues_utilisees', $langues);
483
-	}
484
-
485
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
486
-	pipeline('trig_calculer_langues_rubriques', '');
463
+    // rubriques (recursivite)
464
+    sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'),
465
+        "id_parent=0 AND langue_choisie != 'oui'");
466
+    while (calculer_langues_rubriques_etape()) {
467
+        ;
468
+    }
469
+
470
+    // articles
471
+    $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R",
472
+        "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
473
+    while ($row = sql_fetch($s)) {
474
+        $id_article = $row['id_article'];
475
+        sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
476
+            "id_article=" . intval($id_article));
477
+    }
478
+
479
+    if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
480
+
481
+        $langues = calculer_langues_utilisees();
482
+        ecrire_meta('langues_utilisees', $langues);
483
+    }
484
+
485
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
486
+    pipeline('trig_calculer_langues_rubriques', '');
487 487
 }
488 488
 
489 489
 
@@ -500,77 +500,77 @@  discard block
 block discarded – undo
500 500
  *    Liste des langues utilisées séparées par des virgules
501 501
  **/
502 502
 function calculer_langues_utilisees($serveur = '') {
503
-	include_spip('public/interfaces');
504
-	include_spip('public/compiler');
505
-	include_spip('public/composer');
506
-	include_spip('public/phraser_html');
507
-	$langues = array();
508
-
509
-	$langues[$GLOBALS['meta']['langue_site']] = 1;
510
-
511
-	include_spip('base/objets');
512
-	$tables = lister_tables_objets_sql();
513
-	$trouver_table = charger_fonction('trouver_table', 'base');
514
-
515
-	foreach (array_keys($tables) as $t) {
516
-		$desc = $trouver_table($t, $serveur);
517
-		// c'est une table avec des langues
518
-		if ($desc['exist']
519
-			and isset($desc['field']['lang'])
520
-			and isset($desc['field']['langue_choisie'])
521
-		) {
522
-
523
-			$boucle = new Boucle();
524
-			$boucle->show = $desc;
525
-			$boucle->nom = 'calculer_langues_utilisees';
526
-			$boucle->id_boucle = $desc['table_objet'];
527
-			$boucle->id_table = $desc['table_objet'];
528
-			$boucle->sql_serveur = $serveur;
529
-			$boucle->select[] = "DISTINCT lang";
530
-			$boucle->from[$desc['table_objet']] = $t;
531
-			$boucle->separateur[] = ',';
532
-			$boucle->return = '$Pile[$SP][\'lang\']';
533
-			$boucle->iterateur = 'sql';
534
-
535
-			$boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php
536
-			$boucle->descr['sourcefile'] = 'internal';
537
-
538
-			$boucle = pipeline('pre_boucle', $boucle);
539
-
540
-			if (isset($desc['statut'])
541
-				and $desc['statut']
542
-			) {
543
-				$boucles = array(
544
-					'calculer_langues_utilisees' => $boucle,
545
-				);
546
-				// generer un nom de fonction "anonyme" unique
547
-				do {
548
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
549
-				} while (function_exists($functionname));
550
-				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
551
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
552
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
553
-				$res = '';
554
-				eval($code);
555
-				$res = explode(',', $res);
556
-				foreach ($res as $lang) {
557
-					$langues[$lang] = 1;
558
-				}
559
-			} else {
560
-				$res = sql_select(implode(',', $boucle->select), $boucle->from);
561
-				while ($row = sql_fetch($res)) {
562
-					$langues[$row['lang']] = 1;
563
-				}
564
-			}
565
-		}
566
-	}
567
-
568
-	$langues = array_filter(array_keys($langues));
569
-	sort($langues);
570
-	$langues = join(',', $langues);
571
-	spip_log("langues utilisees: $langues");
572
-
573
-	return $langues;
503
+    include_spip('public/interfaces');
504
+    include_spip('public/compiler');
505
+    include_spip('public/composer');
506
+    include_spip('public/phraser_html');
507
+    $langues = array();
508
+
509
+    $langues[$GLOBALS['meta']['langue_site']] = 1;
510
+
511
+    include_spip('base/objets');
512
+    $tables = lister_tables_objets_sql();
513
+    $trouver_table = charger_fonction('trouver_table', 'base');
514
+
515
+    foreach (array_keys($tables) as $t) {
516
+        $desc = $trouver_table($t, $serveur);
517
+        // c'est une table avec des langues
518
+        if ($desc['exist']
519
+            and isset($desc['field']['lang'])
520
+            and isset($desc['field']['langue_choisie'])
521
+        ) {
522
+
523
+            $boucle = new Boucle();
524
+            $boucle->show = $desc;
525
+            $boucle->nom = 'calculer_langues_utilisees';
526
+            $boucle->id_boucle = $desc['table_objet'];
527
+            $boucle->id_table = $desc['table_objet'];
528
+            $boucle->sql_serveur = $serveur;
529
+            $boucle->select[] = "DISTINCT lang";
530
+            $boucle->from[$desc['table_objet']] = $t;
531
+            $boucle->separateur[] = ',';
532
+            $boucle->return = '$Pile[$SP][\'lang\']';
533
+            $boucle->iterateur = 'sql';
534
+
535
+            $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php
536
+            $boucle->descr['sourcefile'] = 'internal';
537
+
538
+            $boucle = pipeline('pre_boucle', $boucle);
539
+
540
+            if (isset($desc['statut'])
541
+                and $desc['statut']
542
+            ) {
543
+                $boucles = array(
544
+                    'calculer_langues_utilisees' => $boucle,
545
+                );
546
+                // generer un nom de fonction "anonyme" unique
547
+                do {
548
+                    $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
549
+                } while (function_exists($functionname));
550
+                $code = calculer_boucle('calculer_langues_utilisees', $boucles);
551
+                $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
552
+                $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
553
+                $res = '';
554
+                eval($code);
555
+                $res = explode(',', $res);
556
+                foreach ($res as $lang) {
557
+                    $langues[$lang] = 1;
558
+                }
559
+            } else {
560
+                $res = sql_select(implode(',', $boucle->select), $boucle->from);
561
+                while ($row = sql_fetch($res)) {
562
+                    $langues[$row['lang']] = 1;
563
+                }
564
+            }
565
+        }
566
+    }
567
+
568
+    $langues = array_filter(array_keys($langues));
569
+    sort($langues);
570
+    $langues = join(',', $langues);
571
+    spip_log("langues utilisees: $langues");
572
+
573
+    return $langues;
574 574
 }
575 575
 
576 576
 /**
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
  *     incluant les rubriques noeuds et toutes leurs descendances
601 601
  */
602 602
 function calcul_branche_in($id) {
603
-	$calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
603
+    $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
604 604
 
605
-	return $calcul_branche_in($id);
605
+    return $calcul_branche_in($id);
606 606
 }
607 607
 
608 608
 /**
@@ -620,9 +620,9 @@  discard block
 block discarded – undo
620 620
  *     incluant les rubriques transmises et toutes leurs parentées
621 621
  */
622 622
 function calcul_hierarchie_in($id, $tout = true) {
623
-	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
623
+    $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
624 624
 
625
-	return $calcul_hierarchie_in($id, $tout);
625
+    return $calcul_hierarchie_in($id, $tout);
626 626
 }
627 627
 
628 628
 
@@ -643,38 +643,38 @@  discard block
 block discarded – undo
643 643
  *     incluant les rubriques noeuds et toutes leurs descendances
644 644
  */
645 645
 function inc_calcul_branche_in_dist($id) {
646
-	static $b = array();
647
-
648
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
649
-	if (!is_array($id)) {
650
-		$id = explode(',', $id);
651
-	}
652
-	$id = join(',', array_map('intval', $id));
653
-	if (isset($b[$id])) {
654
-		return $b[$id];
655
-	}
656
-
657
-	// Notre branche commence par la rubrique de depart
658
-	$branche = $r = $id;
659
-
660
-	// On ajoute une generation (les filles de la generation precedente)
661
-	// jusqu'a epuisement, en se protegeant des references circulaires
662
-	$maxiter = 10000;
663
-	while ($maxiter-- and $filles = sql_allfetsel(
664
-			'id_rubrique',
665
-			'spip_rubriques',
666
-			sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
667
-		)) {
668
-		$r = join(',', array_column($filles, 'id_rubrique'));
669
-		$branche .= ',' . $r;
670
-	}
671
-
672
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
673
-	if (strlen($branche) < 10000) {
674
-		$b[$id] = $branche;
675
-	}
676
-
677
-	return $branche;
646
+    static $b = array();
647
+
648
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
649
+    if (!is_array($id)) {
650
+        $id = explode(',', $id);
651
+    }
652
+    $id = join(',', array_map('intval', $id));
653
+    if (isset($b[$id])) {
654
+        return $b[$id];
655
+    }
656
+
657
+    // Notre branche commence par la rubrique de depart
658
+    $branche = $r = $id;
659
+
660
+    // On ajoute une generation (les filles de la generation precedente)
661
+    // jusqu'a epuisement, en se protegeant des references circulaires
662
+    $maxiter = 10000;
663
+    while ($maxiter-- and $filles = sql_allfetsel(
664
+            'id_rubrique',
665
+            'spip_rubriques',
666
+            sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
667
+        )) {
668
+        $r = join(',', array_column($filles, 'id_rubrique'));
669
+        $branche .= ',' . $r;
670
+    }
671
+
672
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
673
+    if (strlen($branche) < 10000) {
674
+        $b[$id] = $branche;
675
+    }
676
+
677
+    return $branche;
678 678
 }
679 679
 
680 680
 
@@ -696,43 +696,43 @@  discard block
 block discarded – undo
696 696
  *     incluant les rubriques transmises et toutes leurs parentées
697 697
  */
698 698
 function inc_calcul_hierarchie_in_dist($id, $tout = true) {
699
-	static $b = array();
700
-
701
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
702
-	if (!is_array($id)) {
703
-		$id = explode(',', $id);
704
-	}
705
-	$id = join(',', array_map('intval', $id));
706
-
707
-	if (isset($b[$id])) {
708
-		// Notre branche commence par la rubrique de depart si $tout=true
709
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
710
-	}
711
-
712
-	$hier = "";
713
-
714
-	// On ajoute une generation (les filles de la generation precedente)
715
-	// jusqu'a epuisement, en se protegeant des references circulaires
716
-	$ids_nouveaux_parents = $id;
717
-	$maxiter = 10000;
718
-	while ($maxiter-- and $parents = sql_allfetsel(
719
-			'id_parent',
720
-			'spip_rubriques',
721
-			sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
722
-		)) {
723
-		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
724
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
725
-	}
726
-
727
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
728
-	if (strlen($hier) < 10000) {
729
-		$b[$id] = $hier;
730
-	}
731
-
732
-	// Notre branche commence par la rubrique de depart si $tout=true
733
-	$hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
734
-
735
-	return $hier;
699
+    static $b = array();
700
+
701
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
702
+    if (!is_array($id)) {
703
+        $id = explode(',', $id);
704
+    }
705
+    $id = join(',', array_map('intval', $id));
706
+
707
+    if (isset($b[$id])) {
708
+        // Notre branche commence par la rubrique de depart si $tout=true
709
+        return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
710
+    }
711
+
712
+    $hier = "";
713
+
714
+    // On ajoute une generation (les filles de la generation precedente)
715
+    // jusqu'a epuisement, en se protegeant des references circulaires
716
+    $ids_nouveaux_parents = $id;
717
+    $maxiter = 10000;
718
+    while ($maxiter-- and $parents = sql_allfetsel(
719
+            'id_parent',
720
+            'spip_rubriques',
721
+            sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
722
+        )) {
723
+        $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
724
+        $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
725
+    }
726
+
727
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
728
+    if (strlen($hier) < 10000) {
729
+        $b[$id] = $hier;
730
+    }
731
+
732
+    // Notre branche commence par la rubrique de depart si $tout=true
733
+    $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
734
+
735
+    return $hier;
736 736
 }
737 737
 
738 738
 
@@ -750,38 +750,38 @@  discard block
 block discarded – undo
750 750
  * @return void
751 751
  **/
752 752
 function calculer_prochain_postdate($check = false) {
753
-	include_spip('base/abstract_sql');
754
-	if ($check) {
755
-		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
756
-			"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
757
-
758
-		$r = sql_select("DISTINCT A.id_rubrique AS id",
759
-			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
760
-			"R.statut != 'publie' AND A.statut='publie'$postdates");
761
-		while ($row = sql_fetch($r)) {
762
-			publier_branche_rubrique($row['id']);
763
-		}
764
-
765
-		pipeline('trig_calculer_prochain_postdate', '');
766
-	}
767
-
768
-	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
769
-		"1");
770
-
771
-	if ($t) {
772
-		$t = $t['date'];
773
-		if (!isset($GLOBALS['meta']['date_prochain_postdate'])
774
-			or $t <> $GLOBALS['meta']['date_prochain_postdate']
775
-		) {
776
-			ecrire_meta('date_prochain_postdate', strtotime($t));
777
-			ecrire_meta('derniere_modif', time());
778
-		}
779
-	} else {
780
-		effacer_meta('date_prochain_postdate');
781
-		ecrire_meta('derniere_modif', time());
782
-	}
783
-
784
-	spip_log("prochain postdate: $t");
753
+    include_spip('base/abstract_sql');
754
+    if ($check) {
755
+        $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
756
+            "AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
757
+
758
+        $r = sql_select("DISTINCT A.id_rubrique AS id",
759
+            "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
760
+            "R.statut != 'publie' AND A.statut='publie'$postdates");
761
+        while ($row = sql_fetch($r)) {
762
+            publier_branche_rubrique($row['id']);
763
+        }
764
+
765
+        pipeline('trig_calculer_prochain_postdate', '');
766
+    }
767
+
768
+    $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
769
+        "1");
770
+
771
+    if ($t) {
772
+        $t = $t['date'];
773
+        if (!isset($GLOBALS['meta']['date_prochain_postdate'])
774
+            or $t <> $GLOBALS['meta']['date_prochain_postdate']
775
+        ) {
776
+            ecrire_meta('date_prochain_postdate', strtotime($t));
777
+            ecrire_meta('derniere_modif', time());
778
+        }
779
+    } else {
780
+        effacer_meta('date_prochain_postdate');
781
+        ecrire_meta('derniere_modif', time());
782
+    }
783
+
784
+    spip_log("prochain postdate: $t");
785 785
 }
786 786
 
787 787
 /**
@@ -806,42 +806,42 @@  discard block
 block discarded – undo
806 806
  */
807 807
 function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') {
808 808
 
809
-	// eclater l'arborescence demandee
810
-	// echapper les </multi> et autres balises fermantes html
811
-	$titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre);
812
-	$arbo = explode('/', preg_replace(',^/,', '', $titre));
813
-	include_spip('base/abstract_sql');
814
-	foreach ($arbo as $titre) {
815
-		// retablir les </multi> et autres balises fermantes html
816
-		$titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
817
-		$r = sql_getfetsel("id_rubrique", "spip_rubriques",
818
-			"titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
819
-			$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
820
-		if ($r !== null) {
821
-			$id_parent = $r;
822
-		} else {
823
-			$id_rubrique = sql_insertq('spip_rubriques', array(
824
-					'titre' => $titre,
825
-					'id_parent' => $id_parent,
826
-					'statut' => 'prepa'
827
-				), $desc = array(), $serveur);
828
-			if ($id_parent > 0) {
829
-				$data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
830
-					$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
831
-				$id_secteur = $data['id_secteur'];
832
-				$lang = $data['lang'];
833
-			} else {
834
-				$id_secteur = $id_rubrique;
835
-				$lang = $GLOBALS['meta']['langue_site'];
836
-			}
837
-
838
-			sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
839
-				"id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
840
-
841
-			// pour la recursion
842
-			$id_parent = $id_rubrique;
843
-		}
844
-	}
845
-
846
-	return intval($id_parent);
809
+    // eclater l'arborescence demandee
810
+    // echapper les </multi> et autres balises fermantes html
811
+    $titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre);
812
+    $arbo = explode('/', preg_replace(',^/,', '', $titre));
813
+    include_spip('base/abstract_sql');
814
+    foreach ($arbo as $titre) {
815
+        // retablir les </multi> et autres balises fermantes html
816
+        $titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
817
+        $r = sql_getfetsel("id_rubrique", "spip_rubriques",
818
+            "titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
819
+            $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
820
+        if ($r !== null) {
821
+            $id_parent = $r;
822
+        } else {
823
+            $id_rubrique = sql_insertq('spip_rubriques', array(
824
+                    'titre' => $titre,
825
+                    'id_parent' => $id_parent,
826
+                    'statut' => 'prepa'
827
+                ), $desc = array(), $serveur);
828
+            if ($id_parent > 0) {
829
+                $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
830
+                    $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
831
+                $id_secteur = $data['id_secteur'];
832
+                $lang = $data['lang'];
833
+            } else {
834
+                $id_secteur = $id_rubrique;
835
+                $lang = $GLOBALS['meta']['langue_site'];
836
+            }
837
+
838
+            sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
839
+                "id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
840
+
841
+            // pour la recursion
842
+            $id_parent = $id_rubrique;
843
+        }
844
+    }
845
+
846
+    return intval($id_parent);
847 847
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	$id_pred = $id_rubrique;
106 106
 	while (true) {
107 107
 		sql_updateq('spip_rubriques', array('statut' => 'publie', 'date' => date('Y-m-d H:i:s')),
108
-			"id_rubrique=" . intval($id_rubrique));
109
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=" . intval($id_rubrique));
108
+			"id_rubrique=".intval($id_rubrique));
109
+		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=".intval($id_rubrique));
110 110
 		if (!$id_parent) {
111 111
 			break;
112 112
 		}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			return $id_pred != $id_rubrique;
143 143
 		}
144 144
 		// passer au parent si on a depublie
145
-		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=" . intval($id_pred));
145
+		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=".intval($id_pred));
146 146
 		$id_pred = $r['id_parent'];
147 147
 	}
148 148
 
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
 		$date = date('Y-m-d H:i:s');
168 168
 	}
169 169
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
170
-		" AND date <= " . sql_quote($date) : '';
170
+		" AND date <= ".sql_quote($date) : '';
171 171
 
172 172
 	if (!$id_rubrique = intval($id_rubrique)) {
173 173
 		return false;
174 174
 	}
175 175
 
176 176
 	// verifier qu'elle existe et est bien publiee
177
-	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=" . intval($id_rubrique));
177
+	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=".intval($id_rubrique));
178 178
 	if (!$r or $r['statut'] !== 'publie') {
179 179
 		return false;
180 180
 	}
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	// Le type de l'objet est au pluriel
184 184
 	$compte = array(
185 185
 		'articles' => sql_countsel("spip_articles",
186
-			"id_rubrique=" . intval($id_rubrique) . " AND statut='publie'$postdates"),
187
-		'rubriques' => sql_countsel("spip_rubriques", "id_parent=" . intval($id_rubrique) . " AND statut='publie'"),
186
+			"id_rubrique=".intval($id_rubrique)." AND statut='publie'$postdates"),
187
+		'rubriques' => sql_countsel("spip_rubriques", "id_parent=".intval($id_rubrique)." AND statut='publie'"),
188 188
 		'documents' => sql_countsel(
189 189
 			"spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document", 
190
-			"L.id_objet=" . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
190
+			"L.id_objet=".intval($id_rubrique)." AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') ")
191 191
 	);
192 192
 
193 193
 	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 	}
212 212
 
213
-	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=" . intval($id_rubrique));
213
+	sql_updateq("spip_rubriques", array("statut" => 'prepa'), "id_rubrique=".intval($id_rubrique));
214 214
 
215 215
 #		spip_log("depublier_rubrique $id_pred");
216 216
 	return true;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 	// Afficher les articles post-dates ?
275 275
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
276
-		"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
276
+		"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
277 277
 
278 278
 	$r = sql_select(
279 279
 		"R.id_rubrique AS id, max(A.date) AS date_h",
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		"A.date>R.date_tmp AND A.statut='publie' $postdates ", "R.id_rubrique");
282 282
 	while ($row = sql_fetch($r)) {
283 283
 		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']),
284
-			"id_rubrique=" . intval($row['id']));
284
+			"id_rubrique=".intval($row['id']));
285 285
 	}
286 286
 
287 287
 	// point d'entree pour permettre a des plugins de gerer le statut
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 			"(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", "R.id_rubrique");
303 303
 		while ($row = sql_fetch($r)) {
304 304
 			sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']),
305
-				"id_rubrique=" . intval($row['id']));
305
+				"id_rubrique=".intval($row['id']));
306 306
 			$continuer = true;
307 307
 		}
308 308
 	} while ($continuer);
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 			and $rows = sql_allfetsel(
354 354
 				"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
355 355
 				"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
356
-				"R.profondeur=" . intval($prof) . " AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
356
+				"R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
357 357
 				"", "R.id_secteur", "0,100")) {
358 358
 
359 359
 			$id_secteur = null;
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 			and $rows = sql_allfetsel(
383 383
 				"id_rubrique as id",
384 384
 				"spip_rubriques",
385
-				"profondeur=" . intval($prof + 1) . " AND id_parent NOT IN (" . sql_get_select("zzz.id_rubrique",
386
-					"spip_rubriques AS zzz", "zzz.profondeur=" . intval($prof)) . ")", '', '', '0,100')) {
385
+				"profondeur=".intval($prof + 1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique",
386
+					"spip_rubriques AS zzz", "zzz.profondeur=".intval($prof)).")", '', '', '0,100')) {
387 387
 			$rows = array_column($rows, 'id');
388 388
 			sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
389 389
 		}
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
393 393
 		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
394 394
 		// on arrete les frais
395
-		if (sql_countsel("spip_rubriques", "profondeur=" . intval($prof + 1))) {
395
+		if (sql_countsel("spip_rubriques", "profondeur=".intval($prof + 1))) {
396 396
 			$prof++;
397 397
 			$continuer = true;
398 398
 		}
@@ -400,10 +400,10 @@  discard block
 block discarded – undo
400 400
 
401 401
 	// loger si la table des rubriques semble foireuse
402 402
 	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
403
-	if (sql_countsel("spip_rubriques", "profondeur>" . intval($prof + 1))) {
404
-		spip_log("Les rubriques de profondeur>" . ($prof + 1) . " semblent suspectes (branches morte ou reference circulaire dans les parents)",
403
+	if (sql_countsel("spip_rubriques", "profondeur>".intval($prof + 1))) {
404
+		spip_log("Les rubriques de profondeur>".($prof + 1)." semblent suspectes (branches morte ou reference circulaire dans les parents)",
405 405
 			_LOG_CRITIQUE);
406
-		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>" . intval($prof + 1));
406
+		sql_update("spip_rubriques", array('id_secteur' => 0), "profondeur>".intval($prof + 1));
407 407
 	}
408 408
 
409 409
 	// reparer les articles
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 		"A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
412 412
 
413 413
 	while ($row = sql_fetch($r)) {
414
-		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=" . intval($row['id']));
414
+		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=".intval($row['id']));
415 415
 	}
416 416
 
417 417
 	// avertir les plugins qui peuvent faire leur mises a jour egalement
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	while ($row = sql_fetch($s)) {
438 438
 		$id_rubrique = $row['id_rubrique'];
439 439
 		$t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie' => 'non'),
440
-			"id_rubrique=" . intval($id_rubrique));
440
+			"id_rubrique=".intval($id_rubrique));
441 441
 	}
442 442
 
443 443
 	return $t;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	while ($row = sql_fetch($s)) {
474 474
 		$id_article = $row['id_article'];
475 475
 		sql_updateq('spip_articles', array("lang" => $row['lang'], 'langue_choisie' => 'non'),
476
-			"id_article=" . intval($id_article));
476
+			"id_article=".intval($id_article));
477 477
 	}
478 478
 
479 479
 	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
@@ -545,11 +545,11 @@  discard block
 block discarded – undo
545 545
 				);
546 546
 				// generer un nom de fonction "anonyme" unique
547 547
 				do {
548
-					$functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand();
548
+					$functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.rand();
549 549
 				} while (function_exists($functionname));
550 550
 				$code = calculer_boucle('calculer_langues_utilisees', $boucles);
551
-				$code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code;
552
-				$code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();';
551
+				$code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code;
552
+				$code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();';
553 553
 				$res = '';
554 554
 				eval($code);
555 555
 				$res = explode(',', $res);
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
 	while ($maxiter-- and $filles = sql_allfetsel(
664 664
 			'id_rubrique',
665 665
 			'spip_rubriques',
666
-			sql_in('id_parent', $r) . " AND " . sql_in('id_rubrique', $r, 'NOT')
666
+			sql_in('id_parent', $r)." AND ".sql_in('id_rubrique', $r, 'NOT')
667 667
 		)) {
668 668
 		$r = join(',', array_column($filles, 'id_rubrique'));
669
-		$branche .= ',' . $r;
669
+		$branche .= ','.$r;
670 670
 	}
671 671
 
672 672
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 
707 707
 	if (isset($b[$id])) {
708 708
 		// Notre branche commence par la rubrique de depart si $tout=true
709
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
709
+		return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id];
710 710
 	}
711 711
 
712 712
 	$hier = "";
@@ -718,10 +718,10 @@  discard block
 block discarded – undo
718 718
 	while ($maxiter-- and $parents = sql_allfetsel(
719 719
 			'id_parent',
720 720
 			'spip_rubriques',
721
-			sql_in('id_rubrique', $ids_nouveaux_parents) . " AND " . sql_in('id_parent', $hier, 'NOT')
721
+			sql_in('id_rubrique', $ids_nouveaux_parents)." AND ".sql_in('id_parent', $hier, 'NOT')
722 722
 		)) {
723 723
 		$ids_nouveaux_parents = join(',', array_column($parents, 'id_parent'));
724
-		$hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : '');
724
+		$hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : '');
725 725
 	}
726 726
 
727 727
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
 	include_spip('base/abstract_sql');
754 754
 	if ($check) {
755 755
 		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
756
-			"AND A.date <= " . sql_quote(date('Y-m-d H:i:s')) : '';
756
+			"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
757 757
 
758 758
 		$r = sql_select("DISTINCT A.id_rubrique AS id",
759 759
 			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique",
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 		pipeline('trig_calculer_prochain_postdate', '');
766 766
 	}
767 767
 
768
-	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), "", "date",
768
+	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date",
769 769
 		"1");
770 770
 
771 771
 	if ($t) {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 		// retablir les </multi> et autres balises fermantes html
816 816
 		$titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
817 817
 		$r = sql_getfetsel("id_rubrique", "spip_rubriques",
818
-			"titre = " . sql_quote($titre) . " AND id_parent=" . intval($id_parent),
818
+			"titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent),
819 819
 			$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
820 820
 		if ($r !== null) {
821 821
 			$id_parent = $r;
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 			}
837 837
 
838 838
 			sql_updateq('spip_rubriques', array('id_secteur' => $id_secteur, "lang" => $lang),
839
-				"id_rubrique=" . intval($id_rubrique), $desc = '', $serveur);
839
+				"id_rubrique=".intval($id_rubrique), $desc = '', $serveur);
840 840
 
841 841
 			// pour la recursion
842 842
 			$id_parent = $id_rubrique;
Please login to merge, or discard this patch.
ecrire/inc/texte.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 /**
32 32
  * Raccourcis dépendant du sens de la langue
33 33
  *
34
- * @return array Tablea ('','')
34
+ * @return string[] Tablea ('','')
35 35
  */
36 36
 function definir_raccourcis_alineas() {
37 37
 	return array('', '');
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
  * Ne fait rien ici. Voir plugin Textwheel
355 355
  *
356 356
  * @param string $letexte
357
- * @param null $forcer
357
+ * @param boolean|null $forcer
358 358
  * @return string
359 359
  */
360 360
 function paragrapher($letexte, $forcer = true) {
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/texte_mini');
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return array Tablea ('','')
35 35
  */
36 36
 function definir_raccourcis_alineas() {
37
-	return array('', '');
37
+    return array('', '');
38 38
 }
39 39
 
40 40
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  * @return string
48 48
  */
49 49
 function traiter_tableau($bloc) {
50
-	return $bloc;
50
+    return $bloc;
51 51
 }
52 52
 
53 53
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
  * @return string
62 62
  */
63 63
 function traiter_listes($texte) {
64
-	return $texte;
64
+    return $texte;
65 65
 }
66 66
 
67 67
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function traiter_raccourcis($letexte) {
79 79
 
80
-	// Appeler les fonctions de pre_traitement
81
-	$letexte = pipeline('pre_propre', $letexte);
80
+    // Appeler les fonctions de pre_traitement
81
+    $letexte = pipeline('pre_propre', $letexte);
82 82
 
83
-	// APPELER ICI UN PIPELINE traiter_raccourcis ?
84
-	// $letexte = pipeline('traiter_raccourcis', $letexte);
83
+    // APPELER ICI UN PIPELINE traiter_raccourcis ?
84
+    // $letexte = pipeline('traiter_raccourcis', $letexte);
85 85
 
86
-	// Appeler les fonctions de post-traitement
87
-	$letexte = pipeline('post_propre', $letexte);
86
+    // Appeler les fonctions de post-traitement
87
+    $letexte = pipeline('post_propre', $letexte);
88 88
 
89
-	return $letexte;
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /*************************************************************************************************************************
@@ -102,19 +102,19 @@  discard block
 block discarded – undo
102 102
  * @return string
103 103
  */
104 104
 function echappe_js($t, $class = ' class = "echappe-js"') {
105
-	foreach (array('script', 'iframe') as $tag) {
106
-		if (stripos($t, "<$tag") !== false
107
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
-		) {
109
-			foreach ($r as $regs) {
110
-				$t = str_replace($regs[0],
111
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
112
-					$t);
113
-			}
114
-		}
115
-	}
116
-
117
-	return $t;
105
+    foreach (array('script', 'iframe') as $tag) {
106
+        if (stripos($t, "<$tag") !== false
107
+            and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
108
+        ) {
109
+            foreach ($r as $regs) {
110
+                $t = str_replace($regs[0],
111
+                    "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
112
+                    $t);
113
+            }
114
+        }
115
+    }
116
+
117
+    return $t;
118 118
 }
119 119
 
120 120
 
@@ -143,55 +143,55 @@  discard block
 block discarded – undo
143 143
  *     Code protégé
144 144
  **/
145 145
 function interdire_scripts($arg, $mode_filtre=null) {
146
-	// on memorise le resultat sur les arguments non triviaux
147
-	static $dejavu = array();
148
-
149
-	// Attention, si ce n'est pas une chaine, laisser intact
150
-	if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
151
-		return $arg;
152
-	}
153
-
154
-	if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
155
-		$mode_filtre = $GLOBALS['filtrer_javascript'];
156
-	}
157
-
158
-	if (isset($dejavu[$mode_filtre][$arg])) {
159
-		return $dejavu[$mode_filtre][$arg];
160
-	}
161
-
162
-	// echapper les tags asp/php
163
-	$t = str_replace('<' . '%', '&lt;%', $arg);
164
-
165
-	// echapper le php
166
-	$t = str_replace('<' . '?', '&lt;?', $t);
167
-
168
-	// echapper le < script language=php >
169
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
170
-
171
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
172
-	switch ($mode_filtre) {
173
-		case 0:
174
-			if (!_DIR_RESTREINT) {
175
-				$t = echappe_js($t);
176
-			}
177
-			break;
178
-		case -1:
179
-			$t = echappe_js($t);
180
-			break;
181
-	}
182
-
183
-	// pas de <base href /> svp !
184
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
185
-
186
-	// Reinserer les echappements des modeles
187
-	if (defined('_PROTEGE_JS_MODELES')) {
188
-		$t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES);
189
-	}
190
-	if (defined('_PROTEGE_PHP_MODELES')) {
191
-		$t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES);
192
-	}
193
-
194
-	return $dejavu[$mode_filtre][$arg] = $t;
146
+    // on memorise le resultat sur les arguments non triviaux
147
+    static $dejavu = array();
148
+
149
+    // Attention, si ce n'est pas une chaine, laisser intact
150
+    if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
151
+        return $arg;
152
+    }
153
+
154
+    if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
155
+        $mode_filtre = $GLOBALS['filtrer_javascript'];
156
+    }
157
+
158
+    if (isset($dejavu[$mode_filtre][$arg])) {
159
+        return $dejavu[$mode_filtre][$arg];
160
+    }
161
+
162
+    // echapper les tags asp/php
163
+    $t = str_replace('<' . '%', '&lt;%', $arg);
164
+
165
+    // echapper le php
166
+    $t = str_replace('<' . '?', '&lt;?', $t);
167
+
168
+    // echapper le < script language=php >
169
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
170
+
171
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
172
+    switch ($mode_filtre) {
173
+        case 0:
174
+            if (!_DIR_RESTREINT) {
175
+                $t = echappe_js($t);
176
+            }
177
+            break;
178
+        case -1:
179
+            $t = echappe_js($t);
180
+            break;
181
+    }
182
+
183
+    // pas de <base href /> svp !
184
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
185
+
186
+    // Reinserer les echappements des modeles
187
+    if (defined('_PROTEGE_JS_MODELES')) {
188
+        $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES);
189
+    }
190
+    if (defined('_PROTEGE_PHP_MODELES')) {
191
+        $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES);
192
+    }
193
+
194
+    return $dejavu[$mode_filtre][$arg] = $t;
195 195
 }
196 196
 
197 197
 
@@ -220,64 +220,64 @@  discard block
 block discarded – undo
220 220
  *     Texte transformé
221 221
  **/
222 222
 function typo($letexte, $echapper = true, $connect = null, $env = array()) {
223
-	// Plus vite !
224
-	if (!$letexte) {
225
-		return $letexte;
226
-	}
227
-
228
-	// les appels directs a cette fonction depuis le php de l'espace
229
-	// prive etant historiquement ecrit sans argment $connect
230
-	// on utilise la presence de celui-ci pour distinguer les cas
231
-	// ou il faut passer interdire_script explicitement
232
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
233
-	// ne seront pas perturbes
234
-	$interdire_script = false;
235
-	if (is_null($connect)) {
236
-		$connect = '';
237
-		$interdire_script = true;
238
-		$env['espace_prive'] = test_espace_prive();
239
-	}
240
-
241
-	// Echapper les codes <html> etc
242
-	if ($echapper) {
243
-		$letexte = echappe_html($letexte, 'TYPO');
244
-	}
245
-
246
-	//
247
-	// Installer les modeles, notamment images et documents ;
248
-	//
249
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
250
-	// cf. inc/lien
251
-
252
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
253
-	if ($letexte != $mem) {
254
-		$echapper = true;
255
-	}
256
-	unset($mem);
257
-
258
-	$letexte = corriger_typo($letexte);
259
-	$letexte = echapper_faux_tags($letexte);
260
-
261
-	// reintegrer les echappements
262
-	if ($echapper) {
263
-		$letexte = echappe_retour($letexte, 'TYPO');
264
-	}
265
-
266
-	// Dans les appels directs hors squelette, securiser ici aussi
267
-	if ($interdire_script) {
268
-		$letexte = interdire_scripts($letexte);
269
-	}
270
-
271
-	// Dans l'espace prive on se mefie de tout contenu dangereux
272
-	// https://core.spip.net/issues/3371
273
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
274
-	// https://core.spip.net/issues/4166
275
-	if ($GLOBALS['filtrer_javascript'] == -1
276
-	  or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) {
277
-		$letexte = echapper_html_suspect($letexte);
278
-	}
279
-
280
-	return $letexte;
223
+    // Plus vite !
224
+    if (!$letexte) {
225
+        return $letexte;
226
+    }
227
+
228
+    // les appels directs a cette fonction depuis le php de l'espace
229
+    // prive etant historiquement ecrit sans argment $connect
230
+    // on utilise la presence de celui-ci pour distinguer les cas
231
+    // ou il faut passer interdire_script explicitement
232
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
233
+    // ne seront pas perturbes
234
+    $interdire_script = false;
235
+    if (is_null($connect)) {
236
+        $connect = '';
237
+        $interdire_script = true;
238
+        $env['espace_prive'] = test_espace_prive();
239
+    }
240
+
241
+    // Echapper les codes <html> etc
242
+    if ($echapper) {
243
+        $letexte = echappe_html($letexte, 'TYPO');
244
+    }
245
+
246
+    //
247
+    // Installer les modeles, notamment images et documents ;
248
+    //
249
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
250
+    // cf. inc/lien
251
+
252
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
253
+    if ($letexte != $mem) {
254
+        $echapper = true;
255
+    }
256
+    unset($mem);
257
+
258
+    $letexte = corriger_typo($letexte);
259
+    $letexte = echapper_faux_tags($letexte);
260
+
261
+    // reintegrer les echappements
262
+    if ($echapper) {
263
+        $letexte = echappe_retour($letexte, 'TYPO');
264
+    }
265
+
266
+    // Dans les appels directs hors squelette, securiser ici aussi
267
+    if ($interdire_script) {
268
+        $letexte = interdire_scripts($letexte);
269
+    }
270
+
271
+    // Dans l'espace prive on se mefie de tout contenu dangereux
272
+    // https://core.spip.net/issues/3371
273
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
274
+    // https://core.spip.net/issues/4166
275
+    if ($GLOBALS['filtrer_javascript'] == -1
276
+      or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) {
277
+        $letexte = echapper_html_suspect($letexte);
278
+    }
279
+
280
+    return $letexte;
281 281
 }
282 282
 
283 283
 // Correcteur typographique
@@ -302,57 +302,57 @@  discard block
 block discarded – undo
302 302
  */
303 303
 function corriger_typo($letexte, $lang = '') {
304 304
 
305
-	// Plus vite !
306
-	if (!$letexte) {
307
-		return $letexte;
308
-	}
309
-
310
-	$letexte = pipeline('pre_typo', $letexte);
311
-
312
-	// Caracteres de controle "illegaux"
313
-	$letexte = corriger_caracteres($letexte);
314
-
315
-	// Proteger les caracteres typographiques a l'interieur des tags html
316
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
317
-		foreach ($regs as $reg) {
318
-			$insert = $reg[0];
319
-			// hack: on transforme les caracteres a proteger en les remplacant
320
-			// par des caracteres "illegaux". (cf corriger_caracteres())
321
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
322
-			$letexte = str_replace($reg[0], $insert, $letexte);
323
-		}
324
-	}
325
-
326
-	// trouver les blocs idiomes et les traiter à part
327
-	$letexte = extraire_idiome($ei = $letexte, $lang, true);
328
-	$ei = ($ei !== $letexte);
329
-
330
-	// trouver les blocs multi et les traiter a part
331
-	$letexte = extraire_multi($em = $letexte, $lang, true);
332
-	$em = ($em !== $letexte);
333
-
334
-	// Charger & appliquer les fonctions de typographie
335
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
336
-	$letexte = $typographie($letexte);
337
-
338
-	// Les citations en une autre langue, s'il y a lieu
339
-	if ($em) {
340
-		$letexte = echappe_retour($letexte, 'multi');
341
-	}
342
-	if ($ei) {
343
-		$letexte = echappe_retour($letexte, 'idiome');
344
-	}
345
-
346
-	// Retablir les caracteres proteges
347
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
348
-
349
-	// pipeline
350
-	$letexte = pipeline('post_typo', $letexte);
351
-
352
-	# un message pour abs_url - on est passe en mode texte
353
-	$GLOBALS['mode_abs_url'] = 'texte';
354
-
355
-	return $letexte;
305
+    // Plus vite !
306
+    if (!$letexte) {
307
+        return $letexte;
308
+    }
309
+
310
+    $letexte = pipeline('pre_typo', $letexte);
311
+
312
+    // Caracteres de controle "illegaux"
313
+    $letexte = corriger_caracteres($letexte);
314
+
315
+    // Proteger les caracteres typographiques a l'interieur des tags html
316
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
317
+        foreach ($regs as $reg) {
318
+            $insert = $reg[0];
319
+            // hack: on transforme les caracteres a proteger en les remplacant
320
+            // par des caracteres "illegaux". (cf corriger_caracteres())
321
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
322
+            $letexte = str_replace($reg[0], $insert, $letexte);
323
+        }
324
+    }
325
+
326
+    // trouver les blocs idiomes et les traiter à part
327
+    $letexte = extraire_idiome($ei = $letexte, $lang, true);
328
+    $ei = ($ei !== $letexte);
329
+
330
+    // trouver les blocs multi et les traiter a part
331
+    $letexte = extraire_multi($em = $letexte, $lang, true);
332
+    $em = ($em !== $letexte);
333
+
334
+    // Charger & appliquer les fonctions de typographie
335
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
336
+    $letexte = $typographie($letexte);
337
+
338
+    // Les citations en une autre langue, s'il y a lieu
339
+    if ($em) {
340
+        $letexte = echappe_retour($letexte, 'multi');
341
+    }
342
+    if ($ei) {
343
+        $letexte = echappe_retour($letexte, 'idiome');
344
+    }
345
+
346
+    // Retablir les caracteres proteges
347
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
348
+
349
+    // pipeline
350
+    $letexte = pipeline('post_typo', $letexte);
351
+
352
+    # un message pour abs_url - on est passe en mode texte
353
+    $GLOBALS['mode_abs_url'] = 'texte';
354
+
355
+    return $letexte;
356 356
 }
357 357
 
358 358
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
  * @return string
369 369
  */
370 370
 function paragrapher($letexte, $forcer = true) {
371
-	return $letexte;
371
+    return $letexte;
372 372
 }
373 373
 
374 374
 /**
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
  * @return string Texte
381 381
  **/
382 382
 function traiter_retours_chariots($letexte) {
383
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
384
-	$letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
385
-	$letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
383
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
384
+    $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
385
+    $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
386 386
 
387
-	return $letexte;
387
+    return $letexte;
388 388
 }
389 389
 
390 390
 
@@ -410,37 +410,37 @@  discard block
 block discarded – undo
410 410
  *     Texte transformé
411 411
  **/
412 412
 function propre($t, $connect = null, $env = array()) {
413
-	// les appels directs a cette fonction depuis le php de l'espace
414
-	// prive etant historiquement ecrits sans argment $connect
415
-	// on utilise la presence de celui-ci pour distinguer les cas
416
-	// ou il faut passer interdire_script explicitement
417
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
418
-	// ne seront pas perturbes
419
-	$interdire_script = false;
420
-	if (is_null($connect)) {
421
-		$connect = '';
422
-		$interdire_script = true;
423
-	}
424
-
425
-	if (!$t) {
426
-		return strval($t);
427
-	}
428
-
429
-	// Dans l'espace prive on se mefie de tout contenu dangereux
430
-	// avant echappement des balises <html>
431
-	// https://core.spip.net/issues/3371
432
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
433
-	// https://core.spip.net/issues/4166
434
-	if ($interdire_script
435
-		or $GLOBALS['filtrer_javascript'] == -1
436
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)
437
-		or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) {
438
-		$t = echapper_html_suspect($t, false);
439
-	}
440
-	$t = echappe_html($t);
441
-	$t = expanser_liens($t, $connect, $env);
442
-	$t = traiter_raccourcis($t);
443
-	$t = echappe_retour_modeles($t, $interdire_script);
444
-
445
-	return $t;
413
+    // les appels directs a cette fonction depuis le php de l'espace
414
+    // prive etant historiquement ecrits sans argment $connect
415
+    // on utilise la presence de celui-ci pour distinguer les cas
416
+    // ou il faut passer interdire_script explicitement
417
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
418
+    // ne seront pas perturbes
419
+    $interdire_script = false;
420
+    if (is_null($connect)) {
421
+        $connect = '';
422
+        $interdire_script = true;
423
+    }
424
+
425
+    if (!$t) {
426
+        return strval($t);
427
+    }
428
+
429
+    // Dans l'espace prive on se mefie de tout contenu dangereux
430
+    // avant echappement des balises <html>
431
+    // https://core.spip.net/issues/3371
432
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
433
+    // https://core.spip.net/issues/4166
434
+    if ($interdire_script
435
+        or $GLOBALS['filtrer_javascript'] == -1
436
+        or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)
437
+        or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) {
438
+        $t = echapper_html_suspect($t, false);
439
+    }
440
+    $t = echappe_html($t);
441
+    $t = expanser_liens($t, $connect, $env);
442
+    $t = traiter_raccourcis($t);
443
+    $t = echappe_retour_modeles($t, $interdire_script);
444
+
445
+    return $t;
446 446
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 function echappe_js($t, $class = ' class = "echappe-js"') {
105 105
 	foreach (array('script', 'iframe') as $tag) {
106 106
 		if (stripos($t, "<$tag") !== false
107
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
107
+			and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER)
108 108
 		) {
109 109
 			foreach ($r as $regs) {
110 110
 				$t = str_replace($regs[0],
111
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
111
+					"<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
112 112
 					$t);
113 113
 			}
114 114
 		}
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
  * @return string
143 143
  *     Code protégé
144 144
  **/
145
-function interdire_scripts($arg, $mode_filtre=null) {
145
+function interdire_scripts($arg, $mode_filtre = null) {
146 146
 	// on memorise le resultat sur les arguments non triviaux
147 147
 	static $dejavu = array();
148 148
 
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
 	}
161 161
 
162 162
 	// echapper les tags asp/php
163
-	$t = str_replace('<' . '%', '&lt;%', $arg);
163
+	$t = str_replace('<'.'%', '&lt;%', $arg);
164 164
 
165 165
 	// echapper le php
166
-	$t = str_replace('<' . '?', '&lt;?', $t);
166
+	$t = str_replace('<'.'?', '&lt;?', $t);
167 167
 
168 168
 	// echapper le < script language=php >
169 169
 	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 
186 186
 	// Reinserer les echappements des modeles
187 187
 	if (defined('_PROTEGE_JS_MODELES')) {
188
-		$t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES);
188
+		$t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES);
189 189
 	}
190 190
 	if (defined('_PROTEGE_PHP_MODELES')) {
191
-		$t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES);
191
+		$t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES);
192 192
 	}
193 193
 
194 194
 	return $dejavu[$mode_filtre][$arg] = $t;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	// et aussi dans l'espace public si la globale filtrer_javascript = -1
274 274
 	// https://core.spip.net/issues/4166
275 275
 	if ($GLOBALS['filtrer_javascript'] == -1
276
-	  or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) {
276
+	  or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)) {
277 277
 		$letexte = echapper_html_suspect($letexte);
278 278
 	}
279 279
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 define('_TYPO_PROTEGER', "!':;?~%-");
285 285
 define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8");
286 286
 
287
-define('_TYPO_BALISE', ",</?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS");
287
+define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS");
288 288
 
289 289
 /**
290 290
  * Corrige la typographie
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 	// https://core.spip.net/issues/4166
434 434
 	if ($interdire_script
435 435
 		or $GLOBALS['filtrer_javascript'] == -1
436
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)
437
-		or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) {
436
+		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
437
+		or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)) {
438 438
 		$t = echapper_html_suspect($t, false);
439 439
 	}
440 440
 	$t = echappe_html($t);
Please login to merge, or discard this patch.
ecrire/inc/xml.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,7 @@
 block discarded – undo
245 245
  * @param array $matches
246 246
  *     Branches de l'arbre validant la rexgep
247 247
  * @param bool $init ?
248
- * @return bool
248
+ * @return integer
249 249
  *     false si aucun élément ne valide l'expression régulière, true sinon.
250 250
  **/
251 251
 function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@
 block discarded – undo
135 135
 				while (
136 136
 					$p !== false
137 137
 					and ($morceau = substr($txt, $d, $p - $d))
138
-					and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau,
138
+					and (($nopen += preg_match_all("{<".preg_quote($closing_tag)."(\s*>|\s[^>]*[^/>]>)}is", $morceau,
139 139
 							$matches, PREG_SET_ORDER)) > $nclose)
140 140
 				) {
141 141
 					$nclose++;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -154,9 +154,11 @@
 block discarded – undo
154 154
 			}
155 155
 			$content = substr($txt, 0, $p);
156 156
 			$txt = substr($txt, $p + $ncclos);
157
-			if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile
157
+			if ($profondeur == 0 or strpos($content, "<") === false) {
158
+			    // eviter une recursion si pas utile
158 159
 			{
159 160
 				$out[$tag][] = importer_charset($content, $charset);
161
+			}
160 162
 			}//$content;
161 163
 			else {
162 164
 				$out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
Please login to merge, or discard this patch.
Indentation   +154 added lines, -154 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
 
@@ -47,23 +47,23 @@  discard block
 block discarded – undo
47 47
  *     - false si l'arbre xml ne peut être créé ou est vide
48 48
  **/
49 49
 function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) {
50
-	$contenu = "";
51
-	if (tester_url_absolue($fichier)) {
52
-		include_spip('inc/distant');
53
-		$contenu = recuperer_page($fichier, false, false, $taille_max, $datas);
54
-	} else {
55
-		lire_fichier($fichier, $contenu);
56
-	}
57
-	$arbre = array();
58
-	if ($contenu) {
59
-		$arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
60
-	}
50
+    $contenu = "";
51
+    if (tester_url_absolue($fichier)) {
52
+        include_spip('inc/distant');
53
+        $contenu = recuperer_page($fichier, false, false, $taille_max, $datas);
54
+    } else {
55
+        lire_fichier($fichier, $contenu);
56
+    }
57
+    $arbre = array();
58
+    if ($contenu) {
59
+        $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
60
+    }
61 61
 
62
-	return count($arbre) ? $arbre : false;
62
+    return count($arbre) ? $arbre : false;
63 63
 }
64 64
 
65 65
 if (!defined('_SPIP_XML_TAG_SPLIT')) {
66
-	define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS");
66
+    define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS");
67 67
 }
68 68
 
69 69
 /**
@@ -82,151 +82,151 @@  discard block
 block discarded – undo
82 82
  *     - false si l'arbre xml ne peut être créé ou est vide
83 83
  **/
84 84
 function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) {
85
-	$out = array();
86
-	// enlever les commentaires
87
-	$charset = 'AUTO';
88
-	if ($clean === true) {
89
-		if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
90
-			$charset = $regs[2];
91
-		}
92
-		$texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
93
-		$texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
94
-		include_spip('inc/charsets');
95
-		$clean = $charset;
96
-		//$texte = importer_charset($texte,$charset);
97
-	}
98
-	if (is_string($clean)) {
99
-		$charset = $clean;
100
-	}
101
-	$txt = $texte;
85
+    $out = array();
86
+    // enlever les commentaires
87
+    $charset = 'AUTO';
88
+    if ($clean === true) {
89
+        if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
90
+            $charset = $regs[2];
91
+        }
92
+        $texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
93
+        $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
94
+        include_spip('inc/charsets');
95
+        $clean = $charset;
96
+        //$texte = importer_charset($texte,$charset);
97
+    }
98
+    if (is_string($clean)) {
99
+        $charset = $clean;
100
+    }
101
+    $txt = $texte;
102 102
 
103
-	// tant qu'il y a des tags
104
-	$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
105
-	while (count($chars) >= 2) {
106
-		// tag ouvrant
107
-		//$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
103
+    // tant qu'il y a des tags
104
+    $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
105
+    while (count($chars) >= 2) {
106
+        // tag ouvrant
107
+        //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
108 108
 
109
-		// $before doit etre vide ou des espaces uniquements!
110
-		$before = trim($chars[0]);
109
+        // $before doit etre vide ou des espaces uniquements!
110
+        $before = trim($chars[0]);
111 111
 
112
-		if (strlen($before) > 0) {
113
-			return importer_charset($texte, $charset);
114
-		}//$texte; // before non vide, donc on est dans du texte
112
+        if (strlen($before) > 0) {
113
+            return importer_charset($texte, $charset);
114
+        }//$texte; // before non vide, donc on est dans du texte
115 115
 
116
-		$tag = rtrim($chars[1]);
117
-		$txt = $chars[2];
116
+        $tag = rtrim($chars[1]);
117
+        $txt = $chars[2];
118 118
 
119
-		if (strncmp($tag, '![CDATA[', 8) == 0) {
120
-			return importer_charset($texte, $charset);
121
-		}//$texte;
122
-		if (substr($tag, -1) == '/') { // self closing tag
123
-			$tag = rtrim(substr($tag, 0, strlen($tag) - 1));
124
-			$out[$tag][] = "";
125
-		} else {
126
-			$closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
127
-			$closing_tag = reset($closing_tag);
128
-			// tag fermant
129
-			$ncclos = strlen("</$closing_tag>");
130
-			$p = strpos($txt, "</$closing_tag>");
131
-			if ($p !== false and (strpos($txt, "<") < $p)) {
132
-				$nclose = 0;
133
-				$nopen = 0;
134
-				$d = 0;
135
-				while (
136
-					$p !== false
137
-					and ($morceau = substr($txt, $d, $p - $d))
138
-					and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau,
139
-							$matches, PREG_SET_ORDER)) > $nclose)
140
-				) {
141
-					$nclose++;
142
-					$d = $p + $ncclos;
143
-					$p = strpos($txt, "</$closing_tag>", $d);
144
-				}
145
-			}
146
-			if ($p === false) {
147
-				if ($strict) {
148
-					$out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
119
+        if (strncmp($tag, '![CDATA[', 8) == 0) {
120
+            return importer_charset($texte, $charset);
121
+        }//$texte;
122
+        if (substr($tag, -1) == '/') { // self closing tag
123
+            $tag = rtrim(substr($tag, 0, strlen($tag) - 1));
124
+            $out[$tag][] = "";
125
+        } else {
126
+            $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
127
+            $closing_tag = reset($closing_tag);
128
+            // tag fermant
129
+            $ncclos = strlen("</$closing_tag>");
130
+            $p = strpos($txt, "</$closing_tag>");
131
+            if ($p !== false and (strpos($txt, "<") < $p)) {
132
+                $nclose = 0;
133
+                $nopen = 0;
134
+                $d = 0;
135
+                while (
136
+                    $p !== false
137
+                    and ($morceau = substr($txt, $d, $p - $d))
138
+                    and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau,
139
+                            $matches, PREG_SET_ORDER)) > $nclose)
140
+                ) {
141
+                    $nclose++;
142
+                    $d = $p + $ncclos;
143
+                    $p = strpos($txt, "</$closing_tag>", $d);
144
+                }
145
+            }
146
+            if ($p === false) {
147
+                if ($strict) {
148
+                    $out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
149 149
 
150
-					return $out;
151
-				} else {
152
-					return importer_charset($texte, $charset);
153
-				}//$texte // un tag qui constitue du texte a reporter dans $before
154
-			}
155
-			$content = substr($txt, 0, $p);
156
-			$txt = substr($txt, $p + $ncclos);
157
-			if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile
158
-			{
159
-				$out[$tag][] = importer_charset($content, $charset);
160
-			}//$content;
161
-			else {
162
-				$out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
163
-			}
164
-		}
165
-		$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
166
-	}
167
-	if (count($out) && (strlen(trim($txt)) == 0)) {
168
-		return $out;
169
-	} else {
170
-		return importer_charset($texte, $charset);
171
-	}//$texte;
150
+                    return $out;
151
+                } else {
152
+                    return importer_charset($texte, $charset);
153
+                }//$texte // un tag qui constitue du texte a reporter dans $before
154
+            }
155
+            $content = substr($txt, 0, $p);
156
+            $txt = substr($txt, $p + $ncclos);
157
+            if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile
158
+            {
159
+                $out[$tag][] = importer_charset($content, $charset);
160
+            }//$content;
161
+            else {
162
+                $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
163
+            }
164
+        }
165
+        $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
166
+    }
167
+    if (count($out) && (strlen(trim($txt)) == 0)) {
168
+        return $out;
169
+    } else {
170
+        return importer_charset($texte, $charset);
171
+    }//$texte;
172 172
 }
173 173
 
174 174
 // https://code.spip.net/@spip_xml_aplatit
175 175
 function spip_xml_aplatit($arbre, $separateur = " ") {
176
-	$s = "";
177
-	if (is_array($arbre)) {
178
-		foreach ($arbre as $tag => $feuille) {
179
-			if (is_array($feuille)) {
180
-				if ($tag !== intval($tag)) {
181
-					$f = spip_xml_aplatit($feuille, $separateur);
182
-					if (strlen($f)) {
183
-						$tagf = explode(" ", $tag);
184
-						$tagf = $tagf[0];
185
-						$s .= "<$tag>$f</$tagf>";
186
-					} else {
187
-						$s .= "<$tag />";
188
-					}
189
-				} else {
190
-					$s .= spip_xml_aplatit($feuille);
191
-				}
192
-				$s .= $separateur;
193
-			} else {
194
-				$s .= "$feuille$separateur";
195
-			}
196
-		}
197
-	}
176
+    $s = "";
177
+    if (is_array($arbre)) {
178
+        foreach ($arbre as $tag => $feuille) {
179
+            if (is_array($feuille)) {
180
+                if ($tag !== intval($tag)) {
181
+                    $f = spip_xml_aplatit($feuille, $separateur);
182
+                    if (strlen($f)) {
183
+                        $tagf = explode(" ", $tag);
184
+                        $tagf = $tagf[0];
185
+                        $s .= "<$tag>$f</$tagf>";
186
+                    } else {
187
+                        $s .= "<$tag />";
188
+                    }
189
+                } else {
190
+                    $s .= spip_xml_aplatit($feuille);
191
+                }
192
+                $s .= $separateur;
193
+            } else {
194
+                $s .= "$feuille$separateur";
195
+            }
196
+        }
197
+    }
198 198
 
199
-	return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
199
+    return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
200 200
 }
201 201
 
202 202
 // https://code.spip.net/@spip_xml_tagname
203 203
 function spip_xml_tagname($tag) {
204
-	if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
205
-		return $reg[1];
206
-	}
204
+    if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
205
+        return $reg[1];
206
+    }
207 207
 
208
-	return "";
208
+    return "";
209 209
 }
210 210
 
211 211
 // https://code.spip.net/@spip_xml_decompose_tag
212 212
 function spip_xml_decompose_tag($tag) {
213
-	$tagname = spip_xml_tagname($tag);
214
-	$liste = array();
215
-	$p = strpos($tag, ' ');
216
-	$tag = substr($tag, $p);
217
-	$p = strpos($tag, '=');
218
-	while ($p !== false) {
219
-		$attr = trim(substr($tag, 0, $p));
220
-		$tag = ltrim(substr($tag, $p + 1));
221
-		$quote = $tag[0];
222
-		$p = strpos($tag, $quote, 1);
223
-		$cont = substr($tag, 1, $p - 1);
224
-		$liste[$attr] = $cont;
225
-		$tag = substr($tag, $p + 1);
226
-		$p = strpos($tag, '=');
227
-	}
213
+    $tagname = spip_xml_tagname($tag);
214
+    $liste = array();
215
+    $p = strpos($tag, ' ');
216
+    $tag = substr($tag, $p);
217
+    $p = strpos($tag, '=');
218
+    while ($p !== false) {
219
+        $attr = trim(substr($tag, 0, $p));
220
+        $tag = ltrim(substr($tag, $p + 1));
221
+        $quote = $tag[0];
222
+        $p = strpos($tag, $quote, 1);
223
+        $cont = substr($tag, 1, $p - 1);
224
+        $liste[$attr] = $cont;
225
+        $tag = substr($tag, $p + 1);
226
+        $p = strpos($tag, '=');
227
+    }
228 228
 
229
-	return array($tagname, $liste);
229
+    return array($tagname, $liste);
230 230
 }
231 231
 
232 232
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  *     false si aucun élément ne valide l'expression régulière, true sinon.
250 250
  **/
251 251
 function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) {
252
-	if ($init) {
253
-		$matches = array();
254
-	}
255
-	if (is_array($arbre) && count($arbre)) {
256
-		foreach (array_keys($arbre) as $tag) {
257
-			if (preg_match($regexp, $tag)) {
258
-				$matches[$tag] = &$arbre[$tag];
259
-			}
260
-			if (is_array($arbre[$tag])) {
261
-				foreach (array_keys($arbre[$tag]) as $occurences) {
262
-					spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
-				}
264
-			}
265
-		}
266
-	}
252
+    if ($init) {
253
+        $matches = array();
254
+    }
255
+    if (is_array($arbre) && count($arbre)) {
256
+        foreach (array_keys($arbre) as $tag) {
257
+            if (preg_match($regexp, $tag)) {
258
+                $matches[$tag] = &$arbre[$tag];
259
+            }
260
+            if (is_array($arbre[$tag])) {
261
+                foreach (array_keys($arbre[$tag]) as $occurences) {
262
+                    spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
+                }
264
+            }
265
+        }
266
+    }
267 267
 
268
-	return (count($matches));
268
+    return (count($matches));
269 269
 }
Please login to merge, or discard this patch.