Completed
Push — master ( 350a8b...37aa61 )
by cam
01:39
created
ecrire/inc/plonger.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -10,111 +10,111 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 include_spip('inc/texte');
17 17
 
18 18
 function inc_plonger_dist($id_rubrique, $idom = '', $list = [], $col = 1, $exclu = 0, $do = 'aff') {
19 19
 
20
-	if ($list) {
21
-		$id_rubrique = $list[$col - 1];
22
-	}
20
+    if ($list) {
21
+        $id_rubrique = $list[$col - 1];
22
+    }
23 23
 
24
-	$ret = '';
24
+    $ret = '';
25 25
 
26
-	# recherche les filles et petites-filles de la rubrique donnee
27
-	# en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on
28
-	# deplace une rubrique, on peut la deplacer partout a partir de la
29
-	# racine... sauf vers elle-meme ou sa propre branche)
30
-	$ordre = [];
31
-	$rub = [];
26
+    # recherche les filles et petites-filles de la rubrique donnee
27
+    # en excluant une eventuelle rubrique interdite (par exemple, lorsqu'on
28
+    # deplace une rubrique, on peut la deplacer partout a partir de la
29
+    # racine... sauf vers elle-meme ou sa propre branche)
30
+    $ordre = [];
31
+    $rub = [];
32 32
 
33
-	$res = sql_select(
34
-		'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
35
-		'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
36
-		'rub1.id_parent = ' . sql_quote($id_rubrique) . '
33
+    $res = sql_select(
34
+        'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
35
+        'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
36
+        'rub1.id_parent = ' . sql_quote($id_rubrique) . '
37 37
 			AND rub1.id_rubrique!=' . sql_quote($exclu) . '
38 38
 			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')',
39
-		'',
40
-		'0+rub1.titre,rub1.titre'
41
-	);
39
+        '',
40
+        '0+rub1.titre,rub1.titre'
41
+    );
42 42
 
43
-	while ($row = sql_fetch($res)) {
44
-		if (autoriser('voir', 'rubrique', $row['id_rubrique'])) {
45
-			$rub[$row['id_rubrique']]['enfants'] = $row['id_enfant'];
46
-			if ($row['id_parent'] == $id_rubrique) {
47
-				$t = trim((string) typo(supprimer_numero($row['titre'])));
48
-				if ($row['langue_choisie'] != 'oui') {
49
-					$t .= ' <small title="'
50
-						. traduire_nom_langue($row['lang'])
51
-						. '">[' . $row['lang'] . ']</small>';
52
-				}
53
-				$ordre[$row['id_rubrique']] = $t;
54
-			}
55
-		}
56
-	}
57
-	$next = $list[$col] ?? 0;
58
-	if ($ordre) {
59
-		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
60
-		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
61
-		$args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
43
+    while ($row = sql_fetch($res)) {
44
+        if (autoriser('voir', 'rubrique', $row['id_rubrique'])) {
45
+            $rub[$row['id_rubrique']]['enfants'] = $row['id_enfant'];
46
+            if ($row['id_parent'] == $id_rubrique) {
47
+                $t = trim((string) typo(supprimer_numero($row['titre'])));
48
+                if ($row['langue_choisie'] != 'oui') {
49
+                    $t .= ' <small title="'
50
+                        . traduire_nom_langue($row['lang'])
51
+                        . '">[' . $row['lang'] . ']</small>';
52
+                }
53
+                $ordre[$row['id_rubrique']] = $t;
54
+            }
55
+        }
56
+    }
57
+    $next = $list[$col] ?? 0;
58
+    if ($ordre) {
59
+        $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
60
+        $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
61
+        $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
62 62
 
63
-		foreach ($ordre as $id => $titrebrut) {
64
-			$titre = supprimer_numero($titrebrut);
63
+        foreach ($ordre as $id => $titrebrut) {
64
+            $titre = supprimer_numero($titrebrut);
65 65
 
66
-			$classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
67
-			if (isset($rub[$id]['enfants'])) {
68
-				$classe2 = " class='rub-ouverte'";
69
-				$url = "\nhref='$rec&amp;id=$id'";
70
-			} else {
71
-				$classe2 = $url = '';
72
-				$url = "\nhref='javascript:void(0)'";
73
-			}
66
+            $classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
67
+            if (isset($rub[$id]['enfants'])) {
68
+                $classe2 = " class='rub-ouverte'";
69
+                $url = "\nhref='$rec&amp;id=$id'";
70
+            } else {
71
+                $classe2 = $url = '';
72
+                $url = "\nhref='javascript:void(0)'";
73
+            }
74 74
 
75
-			$js_func = $do . '_selection_titre';
76
-			$click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
77
-				. (is_array($list) ? "aff_selection_provisoire($id,$args)" : ' false')
75
+            $js_func = $do . '_selection_titre';
76
+            $click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
77
+                . (is_array($list) ? "aff_selection_provisoire($id,$args)" : ' false')
78 78
 # ce lien provoque la selection (directe) de la rubrique cliquee
79 79
 # et l'affichage de son titre dans le bandeau
80
-				. "\"\nondblclick=\""
81
-				. "$js_func(this."
82
-				. 'firstChild.nodeValue,'
83
-				. $id
84
-				. ",'selection_rubrique','id_parent');"
85
-				. "\nreturn aff_selection_provisoire($id,$args);"
86
-				. '"';
80
+                . "\"\nondblclick=\""
81
+                . "$js_func(this."
82
+                . 'firstChild.nodeValue,'
83
+                . $id
84
+                . ",'selection_rubrique','id_parent');"
85
+                . "\nreturn aff_selection_provisoire($id,$args);"
86
+                . '"';
87 87
 
88
-			$ret .= "<div class='"
89
-				. (($id == $next) ? 'item on' : 'item')
90
-				. "'><div class='"
91
-				. $classe1
92
-				. "'><div$classe2><a"
93
-				. $url
94
-				. $click
95
-				. '>'
96
-				. $titre
97
-				. '</a></div></div></div>';
98
-		}
99
-	}
88
+            $ret .= "<div class='"
89
+                . (($id == $next) ? 'item on' : 'item')
90
+                . "'><div class='"
91
+                . $classe1
92
+                . "'><div$classe2><a"
93
+                . $url
94
+                . $click
95
+                . '>'
96
+                . $titre
97
+                . '</a></div></div></div>';
98
+        }
99
+    }
100 100
 
101
-	$idom2 = $idom . '_col_' . ($col + 1);
102
-	$left = ($col * 250);
101
+    $idom2 = $idom . '_col_' . ($col + 1);
102
+    $left = ($col * 250);
103 103
 
104
-	return http_img_pack(
105
-		'loader.svg',
106
-		'',
107
-		"class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
108
-		. ($left - 30)
109
-		. "px; top: 2px; z-index: 2;' id='img_$idom2'"
110
-	)
111
-	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
112
-	. ($left - 250)
113
-	. "px;'>"
114
-	. $ret
115
-	. "\n</div>\n<div id='$idom2'>"
116
-	. ($next
117
-		? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu)
118
-		: '')
119
-	. "\n</div>";
104
+    return http_img_pack(
105
+        'loader.svg',
106
+        '',
107
+        "class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
108
+        . ($left - 30)
109
+        . "px; top: 2px; z-index: 2;' id='img_$idom2'"
110
+    )
111
+    . "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
112
+    . ($left - 250)
113
+    . "px;'>"
114
+    . $ret
115
+    . "\n</div>\n<div id='$idom2'>"
116
+    . ($next
117
+        ? inc_plonger_dist($id_rubrique, $idom, $list, $col + 1, $exclu)
118
+        : '')
119
+    . "\n</div>";
120 120
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 	$res = sql_select(
34 34
 		'rub1.id_rubrique, rub1.titre, rub1.id_parent, rub1.lang, rub1.langue_choisie, rub2.id_rubrique AS id_enfant',
35 35
 		'spip_rubriques AS rub1 LEFT JOIN spip_rubriques AS rub2 ON (rub1.id_rubrique = rub2.id_parent)',
36
-		'rub1.id_parent = ' . sql_quote($id_rubrique) . '
37
-			AND rub1.id_rubrique!=' . sql_quote($exclu) . '
38
-			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu) . ')',
36
+		'rub1.id_parent = '.sql_quote($id_rubrique).'
37
+			AND rub1.id_rubrique!=' . sql_quote($exclu).'
38
+			AND (rub2.id_rubrique IS NULL OR rub2.id_rubrique!=' . sql_quote($exclu).')',
39 39
 		'',
40 40
 		'0+rub1.titre,rub1.titre'
41 41
 	);
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 				if ($row['langue_choisie'] != 'oui') {
49 49
 					$t .= ' <small title="'
50 50
 						. traduire_nom_langue($row['lang'])
51
-						. '">[' . $row['lang'] . ']</small>';
51
+						. '">['.$row['lang'].']</small>';
52 52
 				}
53 53
 				$ordre[$row['id_rubrique']] = $t;
54 54
 			}
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
 	}
57 57
 	$next = $list[$col] ?? 0;
58 58
 	if ($ordre) {
59
-		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1));
59
+		$rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=".($col + 1));
60 60
 		$info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id=");
61
-		$args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event";
61
+		$args = "'$idom',this,$col,'".$GLOBALS['spip_lang_left']."','$info',event";
62 62
 
63 63
 		foreach ($ordre as $id => $titrebrut) {
64 64
 			$titre = supprimer_numero($titrebrut);
65 65
 
66
-			$classe1 = 'petit-item ' . ($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
66
+			$classe1 = 'petit-item '.($id_rubrique ? 'petite-rubrique' : 'petit-secteur');
67 67
 			if (isset($rub[$id]['enfants'])) {
68 68
 				$classe2 = " class='rub-ouverte'";
69 69
 				$url = "\nhref='$rec&amp;id=$id'";
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				$url = "\nhref='javascript:void(0)'";
73 73
 			}
74 74
 
75
-			$js_func = $do . '_selection_titre';
75
+			$js_func = $do.'_selection_titre';
76 76
 			$click = "\nonclick=\"changerhighlight(this.parentNode.parentNode.parentNode);\nreturn "
77 77
 				. (is_array($list) ? "aff_selection_provisoire($id,$args)" : ' false')
78 78
 # ce lien provoque la selection (directe) de la rubrique cliquee
@@ -98,17 +98,17 @@  discard block
 block discarded – undo
98 98
 		}
99 99
 	}
100 100
 
101
-	$idom2 = $idom . '_col_' . ($col + 1);
101
+	$idom2 = $idom.'_col_'.($col + 1);
102 102
 	$left = ($col * 250);
103 103
 
104 104
 	return http_img_pack(
105 105
 		'loader.svg',
106 106
 		'',
107
-		"class='loader' style='visibility: hidden; position: absolute; " . $GLOBALS['spip_lang_left'] . ': '
107
+		"class='loader' style='visibility: hidden; position: absolute; ".$GLOBALS['spip_lang_left'].': '
108 108
 		. ($left - 30)
109 109
 		. "px; top: 2px; z-index: 2;' id='img_$idom2'"
110 110
 	)
111
-	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; " . $GLOBALS['spip_lang_left'] . ': '
111
+	. "<div style='width: 250px; height: 100%; overflow: auto; position: absolute; top: 0px; ".$GLOBALS['spip_lang_left'].': '
112 112
 	. ($left - 250)
113 113
 	. "px;'>"
114 114
 	. $ret
Please login to merge, or discard this patch.
ecrire/inc/acces.php 2 patches
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -30,41 +30,41 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
34
-
35
-	mt_srand($seed);
36
-	$s = '';
37
-	$pass = '';
38
-	for ($i = 0; $i < $longueur; $i++) {
39
-		if (!$s) {
40
-			$s = random_int(0, mt_getrandmax());
41
-			if (!$s) {
42
-				$s = random_int(0, mt_getrandmax());
43
-			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
45
-		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
47
-		$x = $r['r'] & 63;
48
-		if ($x < 10) {
49
-			$x = chr($x + 48);
50
-		} else {
51
-			if ($x < 36) {
52
-				$x = chr($x + 55);
53
-			} else {
54
-				if ($x < 62) {
55
-					$x = chr($x + 61);
56
-				} else {
57
-					$x = $x == 63 ? '/' : '.';
58
-				}
59
-			}
60
-		}
61
-		$pass .= $x;
62
-		$s = substr($s, 2);
63
-	}
64
-	$pass = preg_replace('@[./]@', 'a', $pass);
65
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
66
-
67
-	return preg_replace('@[0O]@', 'o', $pass);
33
+    $seed = (int)round(((float)microtime() + 1) * time());
34
+
35
+    mt_srand($seed);
36
+    $s = '';
37
+    $pass = '';
38
+    for ($i = 0; $i < $longueur; $i++) {
39
+        if (!$s) {
40
+            $s = random_int(0, mt_getrandmax());
41
+            if (!$s) {
42
+                $s = random_int(0, mt_getrandmax());
43
+            }
44
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
45
+        }
46
+        $r = unpack('Cr', pack('H2', $s . $s));
47
+        $x = $r['r'] & 63;
48
+        if ($x < 10) {
49
+            $x = chr($x + 48);
50
+        } else {
51
+            if ($x < 36) {
52
+                $x = chr($x + 55);
53
+            } else {
54
+                if ($x < 62) {
55
+                    $x = chr($x + 61);
56
+                } else {
57
+                    $x = $x == 63 ? '/' : '.';
58
+                }
59
+            }
60
+        }
61
+        $pass .= $x;
62
+        $s = substr($s, 2);
63
+    }
64
+    $pass = preg_replace('@[./]@', 'a', $pass);
65
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
66
+
67
+    return preg_replace('@[0O]@', 'o', $pass);
68 68
 }
69 69
 
70 70
 /**
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
  * @return string Identifiant
74 74
  */
75 75
 function creer_uniqid() {
76
-	static $seeded;
76
+    static $seeded;
77 77
 
78
-	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
80
-		mt_srand($seed);
81
-		$seeded = true;
82
-	}
78
+    if (!$seeded) {
79
+        $seed = (int)round(((float)microtime() + 1) * time());
80
+        mt_srand($seed);
81
+        $seeded = true;
82
+    }
83 83
 
84
-	$s = random_int(0, mt_getrandmax());
85
-	if (!$s) {
86
-		$s = random_int(0, mt_getrandmax());
87
-	}
84
+    $s = random_int(0, mt_getrandmax());
85
+    if (!$s) {
86
+        $s = random_int(0, mt_getrandmax());
87
+    }
88 88
 
89
-	return uniqid($s, 1);
89
+    return uniqid($s, 1);
90 90
 }
91 91
 
92 92
 /**
@@ -100,42 +100,42 @@  discard block
 block discarded – undo
100 100
  * @return string Retourne l'alea éphemère actuel au passage
101 101
  */
102 102
 function charger_aleas() {
103
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
-		include_spip('base/abstract_sql');
105
-		$aleas = sql_allfetsel(
106
-			['nom', 'valeur'],
107
-			'spip_meta',
108
-			sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
-			'',
110
-			'',
111
-			'',
112
-			'',
113
-			'',
114
-			'continue'
115
-		);
116
-		if ($aleas) {
117
-			foreach ($aleas as $a) {
118
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
-			}
120
-			return $GLOBALS['meta']['alea_ephemere'];
121
-		} else {
122
-			spip_log('aleas indisponibles', 'session');
123
-			return '';
124
-		}
125
-	}
126
-	return $GLOBALS['meta']['alea_ephemere'];
103
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
+        include_spip('base/abstract_sql');
105
+        $aleas = sql_allfetsel(
106
+            ['nom', 'valeur'],
107
+            'spip_meta',
108
+            sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
+            '',
110
+            '',
111
+            '',
112
+            '',
113
+            '',
114
+            'continue'
115
+        );
116
+        if ($aleas) {
117
+            foreach ($aleas as $a) {
118
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
+            }
120
+            return $GLOBALS['meta']['alea_ephemere'];
121
+        } else {
122
+            spip_log('aleas indisponibles', 'session');
123
+            return '';
124
+        }
125
+    }
126
+    return $GLOBALS['meta']['alea_ephemere'];
127 127
 }
128 128
 
129 129
 /**
130 130
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
131 131
  **/
132 132
 function renouvelle_alea() {
133
-	charger_aleas();
134
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
-	ecrire_meta('alea_ephemere_date', time(), 'non');
138
-	spip_log("renouvellement de l'alea_ephemere");
133
+    charger_aleas();
134
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
+    ecrire_meta('alea_ephemere_date', time(), 'non');
138
+    spip_log("renouvellement de l'alea_ephemere");
139 139
 }
140 140
 
141 141
 
@@ -155,21 +155,21 @@  discard block
 block discarded – undo
155 155
  *     Clé de sécurité.
156 156
  **/
157 157
 function low_sec($id_auteur) {
158
-	// Pas d'id_auteur : low_sec
159
-	if (!$id_auteur = (int) $id_auteur) {
160
-		include_spip('inc/config');
161
-		if (!$low_sec = lire_config('low_sec')) {
162
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
-		}
164
-	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
-		if (!$low_sec) {
167
-			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
-		}
170
-	}
171
-
172
-	return $low_sec;
158
+    // Pas d'id_auteur : low_sec
159
+    if (!$id_auteur = (int) $id_auteur) {
160
+        include_spip('inc/config');
161
+        if (!$low_sec = lire_config('low_sec')) {
162
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
+        }
164
+    } else {
165
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
+        if (!$low_sec) {
167
+            $low_sec = creer_pass_aleatoire();
168
+            sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
+        }
170
+    }
171
+
172
+    return $low_sec;
173 173
 }
174 174
 
175 175
 
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
  * @filtre
203 203
  */
204 204
 function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') {
205
-	if ($op) {
206
-		$dir .= " $op $args";
207
-	}
205
+    if ($op) {
206
+        $dir .= " $op $args";
207
+    }
208 208
 
209
-	return verifier_low_sec($id_auteur, $cle, $dir);
209
+    return verifier_low_sec($id_auteur, $cle, $dir);
210 210
 }
211 211
 
212 212
 /**
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217
-	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
-	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
217
+    $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
+    $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
+    $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
220 220
 
221
-	return generer_url_api($script, $path, $args, $no_entities = false, $public);
221
+    return generer_url_api($script, $path, $args, $no_entities = false, $public);
222 222
 }
223 223
 
224 224
 
@@ -236,27 +236,27 @@  discard block
 block discarded – undo
236 236
  * @deprecated 4.1
237 237
  */
238 238
 function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') {
239
-	$a = $b = '';
240
-	foreach ($args as $val => $var) {
241
-		if ($var) {
242
-			if ($val != 'statut') {
243
-				$a .= ':' . $val . '-' . $var;
244
-			}
245
-			$b .= $val . '=' . $var . '&';
246
-		}
247
-	}
248
-	$a = substr($a, 1);
249
-	$id = (int) @$GLOBALS['connect_id_auteur'];
250
-
251
-	return $b
252
-	. 'op='
253
-	. $op
254
-	. '&id='
255
-	. $id
256
-	. '&cle='
257
-	. afficher_low_sec($id, "$mime $op $a")
258
-	. ($a ? "&args=$a" : '')
259
-	. ($lang ? "&lang=$lang" : '');
239
+    $a = $b = '';
240
+    foreach ($args as $val => $var) {
241
+        if ($var) {
242
+            if ($val != 'statut') {
243
+                $a .= ':' . $val . '-' . $var;
244
+            }
245
+            $b .= $val . '=' . $var . '&';
246
+        }
247
+    }
248
+    $a = substr($a, 1);
249
+    $id = (int) @$GLOBALS['connect_id_auteur'];
250
+
251
+    return $b
252
+    . 'op='
253
+    . $op
254
+    . '&id='
255
+    . $id
256
+    . '&cle='
257
+    . afficher_low_sec($id, "$mime $op $a")
258
+    . ($a ? "&args=$a" : '')
259
+    . ($lang ? "&lang=$lang" : '');
260 260
 }
261 261
 
262 262
 /**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
  *     Clé
273 273
  **/
274 274
 function afficher_low_sec($id_auteur, $action = '') {
275
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
275
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
276 276
 }
277 277
 
278 278
 /**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
  *     true si les clés corresponde, false sinon
291 291
  **/
292 292
 function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') {
293
-	return ($cle == afficher_low_sec($id_auteur, $action));
293
+    return ($cle == afficher_low_sec($id_auteur, $action));
294 294
 }
295 295
 
296 296
 /**
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
  *     Identifiant de l'auteur
301 301
  **/
302 302
 function effacer_low_sec($id_auteur) {
303
-	if (!$id_auteur = (int) $id_auteur) {
304
-		return;
305
-	} // jamais trop prudent ;)
306
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
303
+    if (!$id_auteur = (int) $id_auteur) {
304
+        return;
305
+    } // jamais trop prudent ;)
306
+    sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
307 307
 }
308 308
 
309 309
 
@@ -321,29 +321,29 @@  discard block
 block discarded – undo
321 321
  *     - void sinon.
322 322
  **/
323 323
 function ecrire_acces() {
324
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
325
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
326
-
327
-	// Cette variable de configuration peut etre posee par un plugin
328
-	// par exemple acces_restreint ;
329
-	// si .htaccess existe, outrepasser spip_meta
330
-	if (
331
-		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
332
-	) {
333
-		spip_unlink($htpasswd);
334
-		spip_unlink($htpasswd . '-admin');
335
-		return;
336
-	}
337
-
338
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
339
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
340
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
341
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
342
-	if (include_spip('auth/ldap') && auth_ldap_connect()) {
343
-		return;
344
-	}
345
-
346
-	generer_htpasswd_files($htpasswd, "$htpasswd-admin");
324
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
325
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
326
+
327
+    // Cette variable de configuration peut etre posee par un plugin
328
+    // par exemple acces_restreint ;
329
+    // si .htaccess existe, outrepasser spip_meta
330
+    if (
331
+        (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
332
+    ) {
333
+        spip_unlink($htpasswd);
334
+        spip_unlink($htpasswd . '-admin');
335
+        return;
336
+    }
337
+
338
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
339
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
340
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
341
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
342
+    if (include_spip('auth/ldap') && auth_ldap_connect()) {
343
+        return;
344
+    }
345
+
346
+    generer_htpasswd_files($htpasswd, "$htpasswd-admin");
347 347
 }
348 348
 
349 349
 /**
@@ -352,29 +352,29 @@  discard block
 block discarded – undo
352 352
  * @param $htpasswd_admin
353 353
  */
354 354
 function generer_htpasswd_files($htpasswd, $htpasswd_admin) {
355
-	if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
356
-		$generer_htpasswd($htpasswd, $htpasswd_admin);
357
-	}
358
-
359
-	$pwd_all = ''; // login:htpass pour tous
360
-	$pwd_admin = ''; // login:htpass pour les admins
361
-
362
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
363
-	while ($row = sql_fetch($res)) {
364
-		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
365
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
366
-			$pwd_all .= $ligne;
367
-			if ($row['statut'] == '0minirezo') {
368
-				$pwd_admin .= $ligne;
369
-			}
370
-		}
371
-	}
372
-
373
-	if ($pwd_all) {
374
-		ecrire_fichier($htpasswd, $pwd_all);
375
-		ecrire_fichier($htpasswd_admin, $pwd_admin);
376
-		spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
377
-	}
355
+    if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
356
+        $generer_htpasswd($htpasswd, $htpasswd_admin);
357
+    }
358
+
359
+    $pwd_all = ''; // login:htpass pour tous
360
+    $pwd_admin = ''; // login:htpass pour les admins
361
+
362
+    $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
363
+    while ($row = sql_fetch($res)) {
364
+        if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
365
+            $ligne = $row['login'] . ':' . $row['htpass'] . "\n";
366
+            $pwd_all .= $ligne;
367
+            if ($row['statut'] == '0minirezo') {
368
+                $pwd_admin .= $ligne;
369
+            }
370
+        }
371
+    }
372
+
373
+    if ($pwd_all) {
374
+        ecrire_fichier($htpasswd, $pwd_all);
375
+        ecrire_fichier($htpasswd_admin, $pwd_admin);
376
+        spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
377
+    }
378 378
 }
379 379
 
380 380
 /**
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
  *  La chaîne hachée si fonction crypt présente, rien sinon.
389 389
  */
390 390
 function generer_htpass(#[\SensitiveParameter] $pass) {
391
-	if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
392
-		return $generer_htpass($pass);
393
-	}
391
+    if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
392
+        return $generer_htpass($pass);
393
+    }
394 394
 
395
-	return '';
395
+    return '';
396 396
 }
397 397
 
398 398
 /**
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
  * @return boolean
406 406
  */
407 407
 function verifier_htaccess($rep, $force = false) {
408
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
409
-	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
410
-		return true;
411
-	}
412
-
413
-	// directive deny compatible Apache 2.0+
414
-	$deny =
415
-		'# Deny all requests from Apache 2.4+.
408
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
409
+    if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
410
+        return true;
411
+    }
412
+
413
+    // directive deny compatible Apache 2.0+
414
+    $deny =
415
+        '# Deny all requests from Apache 2.4+.
416 416
 <IfModule mod_authz_core.c>
417 417
   Require all denied
418 418
 </IfModule>
@@ -421,30 +421,30 @@  discard block
 block discarded – undo
421 421
   Deny from all
422 422
 </IfModule>
423 423
 ';
424
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
425
-	if (
426
-		function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
427
-	) {
428
-		$deny = "deny from all\n";
429
-	}
430
-
431
-	if ($ht = @fopen($htaccess, 'w')) {
432
-		fwrite($ht, $deny);
433
-		fclose($ht);
434
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
435
-		$t = rtrim($rep, '/') . '/.ok';
436
-		if ($ht = @fopen($t, 'w')) {
437
-			@fclose($ht);
438
-			include_spip('inc/distant');
439
-			$t = substr($t, strlen(_DIR_RACINE));
440
-			$t = url_de_base() . $t;
441
-			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
442
-			$ht = ($ht['status'] ?? null) === 403;
443
-		}
444
-	}
445
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
446
-
447
-	return $ht;
424
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
425
+    if (
426
+        function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
427
+    ) {
428
+        $deny = "deny from all\n";
429
+    }
430
+
431
+    if ($ht = @fopen($htaccess, 'w')) {
432
+        fwrite($ht, $deny);
433
+        fclose($ht);
434
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
435
+        $t = rtrim($rep, '/') . '/.ok';
436
+        if ($ht = @fopen($t, 'w')) {
437
+            @fclose($ht);
438
+            include_spip('inc/distant');
439
+            $t = substr($t, strlen(_DIR_RACINE));
440
+            $t = url_de_base() . $t;
441
+            $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
442
+            $ht = ($ht['status'] ?? null) === 403;
443
+        }
444
+    }
445
+    spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
446
+
447
+    return $ht;
448 448
 }
449 449
 
450 450
 /**
@@ -462,20 +462,20 @@  discard block
 block discarded – undo
462 462
  *         Valeur de la configuration `creer_htaccess`
463 463
  */
464 464
 function gerer_htaccess() {
465
-	// Cette variable de configuration peut etre posee par un plugin
466
-	// par exemple acces_restreint
467
-	$f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
468
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
469
-	$dirs[] = ['extension' => 'distant'];
470
-	foreach ($dirs as $e) {
471
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
472
-			if ($f) {
473
-				verifier_htaccess($dir);
474
-			} else {
475
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
476
-			}
477
-		}
478
-	}
479
-
480
-	return $GLOBALS['meta']['creer_htaccess'] ?? '';
465
+    // Cette variable de configuration peut etre posee par un plugin
466
+    // par exemple acces_restreint
467
+    $f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
468
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
469
+    $dirs[] = ['extension' => 'distant'];
470
+    foreach ($dirs as $e) {
471
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
472
+            if ($f) {
473
+                verifier_htaccess($dir);
474
+            } else {
475
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
476
+            }
477
+        }
478
+    }
479
+
480
+    return $GLOBALS['meta']['creer_htaccess'] ?? '';
481 481
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
33
+	$seed = (int) round(((float) microtime() + 1) * time());
34 34
 
35 35
 	mt_srand($seed);
36 36
 	$s = '';
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 			if (!$s) {
42 42
 				$s = random_int(0, mt_getrandmax());
43 43
 			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
44
+			$s = substr(md5(uniqid($s).$sel), 0, 16);
45 45
 		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
46
+		$r = unpack('Cr', pack('H2', $s.$s));
47 47
 		$x = $r['r'] & 63;
48 48
 		if ($x < 10) {
49 49
 			$x = chr($x + 48);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	static $seeded;
77 77
 
78 78
 	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
79
+		$seed = (int) round(((float) microtime() + 1) * time());
80 80
 		mt_srand($seed);
81 81
 		$seeded = true;
82 82
 	}
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163 163
 		}
164 164
 	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
165
+		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.(int) $id_auteur);
166 166
 		if (!$low_sec) {
167 167
 			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
168
+			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.(int) $id_auteur);
169 169
 		}
170 170
 	}
171 171
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217 217
 	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218 218
 	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
219
+	$path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : '');
220 220
 
221 221
 	return generer_url_api($script, $path, $args, $no_entities = false, $public);
222 222
 }
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 	foreach ($args as $val => $var) {
241 241
 		if ($var) {
242 242
 			if ($val != 'statut') {
243
-				$a .= ':' . $val . '-' . $var;
243
+				$a .= ':'.$val.'-'.$var;
244 244
 			}
245
-			$b .= $val . '=' . $var . '&';
245
+			$b .= $val.'='.$var.'&';
246 246
 		}
247 247
 	}
248 248
 	$a = substr($a, 1);
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
  *     Clé
273 273
  **/
274 274
 function afficher_low_sec($id_auteur, $action = '') {
275
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
275
+	return substr(md5($action.low_sec($id_auteur)), 0, 8);
276 276
 }
277 277
 
278 278
 /**
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	if (!$id_auteur = (int) $id_auteur) {
304 304
 		return;
305 305
 	} // jamais trop prudent ;)
306
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
306
+	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.(int) $id_auteur);
307 307
 }
308 308
 
309 309
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
  *     - void sinon.
322 322
  **/
323 323
 function ecrire_acces() {
324
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
325
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
324
+	$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
325
+	$htpasswd = _DIR_TMP._AUTH_USER_FILE;
326 326
 
327 327
 	// Cette variable de configuration peut etre posee par un plugin
328 328
 	// par exemple acces_restreint ;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
332 332
 	) {
333 333
 		spip_unlink($htpasswd);
334
-		spip_unlink($htpasswd . '-admin');
334
+		spip_unlink($htpasswd.'-admin');
335 335
 		return;
336 336
 	}
337 337
 
@@ -359,10 +359,10 @@  discard block
 block discarded – undo
359 359
 	$pwd_all = ''; // login:htpass pour tous
360 360
 	$pwd_admin = ''; // login:htpass pour les admins
361 361
 
362
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
362
+	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
363 363
 	while ($row = sql_fetch($res)) {
364 364
 		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
365
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
365
+			$ligne = $row['login'].':'.$row['htpass']."\n";
366 366
 			$pwd_all .= $ligne;
367 367
 			if ($row['statut'] == '0minirezo') {
368 368
 				$pwd_admin .= $ligne;
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
  * @return boolean
406 406
  */
407 407
 function verifier_htaccess($rep, $force = false) {
408
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
408
+	$htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME;
409 409
 	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
410 410
 		return true;
411 411
 	}
@@ -432,17 +432,17 @@  discard block
 block discarded – undo
432 432
 		fwrite($ht, $deny);
433 433
 		fclose($ht);
434 434
 		@chmod($htaccess, _SPIP_CHMOD & 0666);
435
-		$t = rtrim($rep, '/') . '/.ok';
435
+		$t = rtrim($rep, '/').'/.ok';
436 436
 		if ($ht = @fopen($t, 'w')) {
437 437
 			@fclose($ht);
438 438
 			include_spip('inc/distant');
439 439
 			$t = substr($t, strlen(_DIR_RACINE));
440
-			$t = url_de_base() . $t;
440
+			$t = url_de_base().$t;
441 441
 			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
442 442
 			$ht = ($ht['status'] ?? null) === 403;
443 443
 		}
444 444
 	}
445
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
445
+	spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee'));
446 446
 
447 447
 	return $ht;
448 448
 }
@@ -468,11 +468,11 @@  discard block
 block discarded – undo
468 468
 	$dirs = sql_allfetsel('extension', 'spip_types_documents');
469 469
 	$dirs[] = ['extension' => 'distant'];
470 470
 	foreach ($dirs as $e) {
471
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
471
+		if (is_dir($dir = _DIR_IMG.$e['extension'])) {
472 472
 			if ($f) {
473 473
 				verifier_htaccess($dir);
474 474
 			} else {
475
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
475
+				spip_unlink($dir.'/'._ACCESS_FILE_NAME);
476 476
 			}
477 477
 		}
478 478
 	}
Please login to merge, or discard this patch.
ecrire/inc/filtres_mime.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  **/
22 22
 
23 23
 if (!defined('_ECRIRE_INC_VERSION')) {
24
-	return;
24
+    return;
25 25
 }
26 26
 include_spip('inc/filtres');
27 27
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * @return string Rien.
39 39
  **/
40 40
 function filtre_image_dist($t) {
41
-	return '';
41
+    return '';
42 42
 }
43 43
 
44 44
 /**
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
  * @return string Rien.
52 52
  **/
53 53
 function filtre_audio_dist($t) {
54
-	return '';
54
+    return '';
55 55
 }
56 56
 
57 57
 /**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
  * @return string Rien.
65 65
  **/
66 66
 function filtre_video_dist($t) {
67
-	return '';
67
+    return '';
68 68
 }
69 69
 
70 70
 /**
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
  * @return string Rien.
78 78
  **/
79 79
 function filtre_application_dist($t) {
80
-	return '';
80
+    return '';
81 81
 }
82 82
 
83 83
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
  * @return string Rien.
91 91
  **/
92 92
 function filtre_message_dist($t) {
93
-	return '';
93
+    return '';
94 94
 }
95 95
 
96 96
 /**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
  * @return string Rien.
104 104
  **/
105 105
 function filtre_multipart_dist($t) {
106
-	return '';
106
+    return '';
107 107
 }
108 108
 
109 109
 /**
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
  * @return string Contenu échappé.
117 117
  **/
118 118
 function filtre_text_dist($t) {
119
-	static $t1 = ['&', '<', '>'];
120
-	static $t2 = ['&amp;', '&lt;', '&gt;'];
119
+    static $t1 = ['&', '<', '>'];
120
+    static $t2 = ['&amp;', '&lt;', '&gt;'];
121 121
 
122
-	return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>';
122
+    return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>';
123 123
 }
124 124
 
125 125
 /**
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
  *     Tableau (formaté en SPIP)
135 135
  **/
136 136
 function filtre_text_csv_dist($t) {
137
-	include_spip('inc/csv');
138
-	[$entete, $lignes, $caption] = analyse_csv($t);
139
-	foreach ($lignes as &$l) {
140
-		$l = implode('|', $l);
141
-	}
142
-	$corps = implode("\n", $lignes) . "\n";
143
-	$corps = $caption .
144
-		"\n|{{" .
145
-		implode('}}|{{', $entete) .
146
-		'}}|' .
147
-		"\n|" .
148
-		str_replace("\n", "|\n|", $corps);
149
-	include_spip('inc/texte');
150
-
151
-	return propre($corps);
137
+    include_spip('inc/csv');
138
+    [$entete, $lignes, $caption] = analyse_csv($t);
139
+    foreach ($lignes as &$l) {
140
+        $l = implode('|', $l);
141
+    }
142
+    $corps = implode("\n", $lignes) . "\n";
143
+    $corps = $caption .
144
+        "\n|{{" .
145
+        implode('}}|{{', $entete) .
146
+        '}}|' .
147
+        "\n|" .
148
+        str_replace("\n", "|\n|", $corps);
149
+    include_spip('inc/texte');
150
+
151
+    return propre($corps);
152 152
 }
153 153
 
154 154
 /**
@@ -162,33 +162,33 @@  discard block
 block discarded – undo
162 162
  * @return string Code html sécurisé ou texte échappé
163 163
  **/
164 164
 function filtre_text_html_dist($t) {
165
-	if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) {
166
-		return appliquer_filtre($t, 'text/plain');
167
-	}
168
-
169
-	[, $h, $t] = $r;
170
-
171
-	$style = '';
172
-	// recuperer les styles internes
173
-	if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) {
174
-		$style = implode("\n", $r[1]);
175
-	}
176
-	// ... et externes
177
-
178
-	include_spip('inc/distant');
179
-	if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) {
180
-		foreach ($r[0] as $l) {
181
-			preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m);
182
-			$page = recuperer_url($m[1]);
183
-			$page = $page['page'] ?? '';
184
-			$style .= "\n/* $l */\n"
185
-				. str_replace('<', '', (string) $page);
186
-		}
187
-	}
188
-	// Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ?
189
-	$t = safehtml(preg_replace(',<script.*?</script>,is', '', $t));
190
-
191
-	return ($style ? "\n<style>" . $style . '</style>' : '') . $t;
165
+    if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) {
166
+        return appliquer_filtre($t, 'text/plain');
167
+    }
168
+
169
+    [, $h, $t] = $r;
170
+
171
+    $style = '';
172
+    // recuperer les styles internes
173
+    if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) {
174
+        $style = implode("\n", $r[1]);
175
+    }
176
+    // ... et externes
177
+
178
+    include_spip('inc/distant');
179
+    if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) {
180
+        foreach ($r[0] as $l) {
181
+            preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m);
182
+            $page = recuperer_url($m[1]);
183
+            $page = $page['page'] ?? '';
184
+            $style .= "\n/* $l */\n"
185
+                . str_replace('<', '', (string) $page);
186
+        }
187
+    }
188
+    // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ?
189
+    $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t));
190
+
191
+    return ($style ? "\n<style>" . $style . '</style>' : '') . $t;
192 192
 }
193 193
 
194 194
 /**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
  * @return string Code HTML des balises `<param>`
202 202
  **/
203 203
 function filtre_audio_x_pn_realaudio($id) {
204
-	return "
204
+    return "
205 205
 	<param name='controls' value='PositionSlider' />
206 206
 	<param name='controls' value='ImageWindow' />
207 207
 	<param name='controls' value='PlayButton' />
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 2 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -34,195 +34,195 @@  discard block
 block discarded – undo
34 34
  * @return array Couples (type d'objet => Couples (champ => score))
35 35
  */
36 36
 function liste_des_champs() {
37
-	static $liste = null;
38
-	if (is_null($liste)) {
39
-		$liste = [];
40
-		// recuperer les tables_objets_sql declarees
41
-		include_spip('base/objets');
42
-		$tables_objets = lister_tables_objets_sql();
43
-		foreach ($tables_objets as $t => $infos) {
44
-			if ($infos['rechercher_champs']) {
45
-				$liste[$infos['type']] = $infos['rechercher_champs'];
46
-			}
47
-		}
48
-		// puis passer dans le pipeline
49
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
50
-	}
51
-
52
-	return $liste;
37
+    static $liste = null;
38
+    if (is_null($liste)) {
39
+        $liste = [];
40
+        // recuperer les tables_objets_sql declarees
41
+        include_spip('base/objets');
42
+        $tables_objets = lister_tables_objets_sql();
43
+        foreach ($tables_objets as $t => $infos) {
44
+            if ($infos['rechercher_champs']) {
45
+                $liste[$infos['type']] = $infos['rechercher_champs'];
46
+            }
47
+        }
48
+        // puis passer dans le pipeline
49
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
50
+    }
51
+
52
+    return $liste;
53 53
 }
54 54
 
55 55
 
56 56
 // Recherche des auteurs et mots-cles associes
57 57
 // en ne regardant que le titre ou le nom
58 58
 function liste_des_jointures() {
59
-	static $liste = null;
60
-	if (is_null($liste)) {
61
-		$liste = [];
62
-		// recuperer les tables_objets_sql declarees
63
-		include_spip('base/objets');
64
-		$tables_objets = lister_tables_objets_sql();
65
-		foreach ($tables_objets as $t => $infos) {
66
-			if ($infos['rechercher_jointures']) {
67
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
68
-			}
69
-		}
70
-		// puis passer dans le pipeline
71
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
72
-	}
73
-
74
-	return $liste;
59
+    static $liste = null;
60
+    if (is_null($liste)) {
61
+        $liste = [];
62
+        // recuperer les tables_objets_sql declarees
63
+        include_spip('base/objets');
64
+        $tables_objets = lister_tables_objets_sql();
65
+        foreach ($tables_objets as $t => $infos) {
66
+            if ($infos['rechercher_jointures']) {
67
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
68
+            }
69
+        }
70
+        // puis passer dans le pipeline
71
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
72
+    }
73
+
74
+    return $liste;
75 75
 }
76 76
 
77 77
 function expression_recherche($recherche, $options) {
78
-	// ne calculer qu'une seule fois l'expression par hit
79
-	// (meme si utilisee dans plusieurs boucles)
80
-	static $expression = [];
81
-	$key = serialize([$recherche, $options['preg_flags']]);
82
-	if (isset($expression[$key])) {
83
-		return $expression[$key];
84
-	}
85
-
86
-	$u = $GLOBALS['meta']['pcre_u'];
87
-	if ($u && !str_contains((string) $options['preg_flags'], (string) $u)) {
88
-		$options['preg_flags'] .= $u;
89
-	}
90
-	include_spip('inc/charsets');
91
-	$recherche = trim((string) $recherche);
92
-
93
-	// retirer les + de +truc et les * de truc*
94
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
-
97
-	$is_preg = false;
98
-	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
-		// c'est une preg
100
-		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
102
-		$is_preg = true;
103
-	} else {
104
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
-		// 'une', 'des' ...)
107
-
108
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
-
111
-		// les expressions entre " " sont un mot a chercher tel quel
112
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
113
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
-			foreach ($matches as $match) {
115
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
116
-				$word = trim($word, '"');
117
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
118
-			}
119
-		}
120
-
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
-			$is_preg = true;
123
-
124
-			$recherche_inter = '|';
125
-			$recherche_mots = explode(' ', $recherche_mod);
126
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
-			$petits_mots = true;
128
-			foreach ($recherche_mots as $mot) {
129
-				if (strlen($mot) >= $min_long) {
130
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
132
-					$petits_mots = false;
133
-				}
134
-			}
135
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
-
137
-			// mais on cherche quand même l'expression complète, même si elle
138
-			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
-			if (!$recherche || $petits_mots) {
141
-				$recherche = preg_quote($recherche_org);
142
-			}
143
-			$recherche_trans = translitteration($recherche);
144
-		}
145
-
146
-		$preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
147
-	}
148
-
149
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
-	// ou si l'expression reguliere est invalide
151
-	if (!$is_preg || @preg_match($preg, '') === false) {
152
-		$methode = 'LIKE';
153
-		$u = $GLOBALS['meta']['pcre_u'];
154
-
155
-		// echapper les % et _
156
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
-
158
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
-		$recherche = preg_quote($recherche, '/');
160
-		$recherche_trans = translitteration($recherche);
161
-		$recherche_mod = $recherche_trans;
162
-
163
-		// les expressions entre " " sont un mot a chercher tel quel
164
-		// -> on remplace les espaces par un _ et on enleve les guillemets
165
-		// corriger le like dans le $q
166
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
-			foreach ($matches as $match) {
168
-				$word = preg_replace(',\s+,Uims', '_', $match);
169
-				$word = trim($word, '"');
170
-				$q = str_replace($match, $word, $q);
171
-			}
172
-		}
173
-		// corriger la regexp
174
-		if (preg_match(',["][^"]+["],Uims', (string) $recherche_mod, $matches)) {
175
-			foreach ($matches as $match) {
176
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
177
-				$word = trim($word, '"');
178
-				$recherche_mod = str_replace($match, $word, (string) $recherche_mod);
179
-			}
180
-		}
181
-		$q = sql_quote(
182
-			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
184
-			. '%'
185
-		);
186
-
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
188
-	} else {
189
-		$methode = 'REGEXP';
190
-		$q = sql_quote(trim($recherche, '/'));
191
-	}
192
-
193
-	// tous les caracteres transliterables de $q sont remplaces par un joker
194
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
-	$q_t = $q;
196
-	for ($i = 0; $i < spip_strlen($q); $i++) {
197
-		$char = spip_substr($q, $i, 1);
198
-		if (
199
-			!is_ascii($char)
200
-			&& ($char_t = translitteration($char))
201
-			&& $char_t !== $char
202
-		) {
203
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
-			// mais c'est un pis aller cf #4354
205
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', (string) $q_t);
206
-		}
207
-	}
208
-
209
-	$q = $q_t;
210
-
211
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
-	// les plus frequents qui peuvent etre accentues
213
-	// (oui c'est tres dicustable...)
214
-	if (
215
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
-		&& str_starts_with((string) $GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
-	) {
218
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
-		// si il reste au moins un char significatif...
220
-		if (preg_match(",[^'%_.],", $q_t)) {
221
-			$q = $q_t;
222
-		}
223
-	}
224
-
225
-	return $expression[$key] = [$methode, $q, $preg];
78
+    // ne calculer qu'une seule fois l'expression par hit
79
+    // (meme si utilisee dans plusieurs boucles)
80
+    static $expression = [];
81
+    $key = serialize([$recherche, $options['preg_flags']]);
82
+    if (isset($expression[$key])) {
83
+        return $expression[$key];
84
+    }
85
+
86
+    $u = $GLOBALS['meta']['pcre_u'];
87
+    if ($u && !str_contains((string) $options['preg_flags'], (string) $u)) {
88
+        $options['preg_flags'] .= $u;
89
+    }
90
+    include_spip('inc/charsets');
91
+    $recherche = trim((string) $recherche);
92
+
93
+    // retirer les + de +truc et les * de truc*
94
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
95
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
96
+
97
+    $is_preg = false;
98
+    if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99
+        // c'est une preg
100
+        $recherche_trans = translitteration($recherche);
101
+        $preg = $recherche_trans . $options['preg_flags'];
102
+        $is_preg = true;
103
+    } else {
104
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
105
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
106
+        // 'une', 'des' ...)
107
+
108
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
109
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
110
+
111
+        // les expressions entre " " sont un mot a chercher tel quel
112
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
113
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
114
+            foreach ($matches as $match) {
115
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
116
+                $word = trim($word, '"');
117
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
118
+            }
119
+        }
120
+
121
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
122
+            $is_preg = true;
123
+
124
+            $recherche_inter = '|';
125
+            $recherche_mots = explode(' ', $recherche_mod);
126
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
127
+            $petits_mots = true;
128
+            foreach ($recherche_mots as $mot) {
129
+                if (strlen($mot) >= $min_long) {
130
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
+                    $recherche_inter .= preg_quote($mot) . ' ';
132
+                    $petits_mots = false;
133
+                }
134
+            }
135
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
136
+
137
+            // mais on cherche quand même l'expression complète, même si elle
138
+            // comporte des mots de moins de quatre lettres
139
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
140
+            if (!$recherche || $petits_mots) {
141
+                $recherche = preg_quote($recherche_org);
142
+            }
143
+            $recherche_trans = translitteration($recherche);
144
+        }
145
+
146
+        $preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
147
+    }
148
+
149
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
150
+    // ou si l'expression reguliere est invalide
151
+    if (!$is_preg || @preg_match($preg, '') === false) {
152
+        $methode = 'LIKE';
153
+        $u = $GLOBALS['meta']['pcre_u'];
154
+
155
+        // echapper les % et _
156
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
157
+
158
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
159
+        $recherche = preg_quote($recherche, '/');
160
+        $recherche_trans = translitteration($recherche);
161
+        $recherche_mod = $recherche_trans;
162
+
163
+        // les expressions entre " " sont un mot a chercher tel quel
164
+        // -> on remplace les espaces par un _ et on enleve les guillemets
165
+        // corriger le like dans le $q
166
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
167
+            foreach ($matches as $match) {
168
+                $word = preg_replace(',\s+,Uims', '_', $match);
169
+                $word = trim($word, '"');
170
+                $q = str_replace($match, $word, $q);
171
+            }
172
+        }
173
+        // corriger la regexp
174
+        if (preg_match(',["][^"]+["],Uims', (string) $recherche_mod, $matches)) {
175
+            foreach ($matches as $match) {
176
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
177
+                $word = trim($word, '"');
178
+                $recherche_mod = str_replace($match, $word, (string) $recherche_mod);
179
+            }
180
+        }
181
+        $q = sql_quote(
182
+            '%'
183
+            . preg_replace(',\s+,' . $u, '%', $q)
184
+            . '%'
185
+        );
186
+
187
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
188
+    } else {
189
+        $methode = 'REGEXP';
190
+        $q = sql_quote(trim($recherche, '/'));
191
+    }
192
+
193
+    // tous les caracteres transliterables de $q sont remplaces par un joker
194
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
195
+    $q_t = $q;
196
+    for ($i = 0; $i < spip_strlen($q); $i++) {
197
+        $char = spip_substr($q, $i, 1);
198
+        if (
199
+            !is_ascii($char)
200
+            && ($char_t = translitteration($char))
201
+            && $char_t !== $char
202
+        ) {
203
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
204
+            // mais c'est un pis aller cf #4354
205
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', (string) $q_t);
206
+        }
207
+    }
208
+
209
+    $q = $q_t;
210
+
211
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
212
+    // les plus frequents qui peuvent etre accentues
213
+    // (oui c'est tres dicustable...)
214
+    if (
215
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
216
+        && str_starts_with((string) $GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite')
217
+    ) {
218
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
219
+        // si il reste au moins un char significatif...
220
+        if (preg_match(",[^'%_.],", $q_t)) {
221
+            $q = $q_t;
222
+        }
223
+    }
224
+
225
+    return $expression[$key] = [$methode, $q, $preg];
226 226
 }
227 227
 
228 228
 
@@ -249,136 +249,136 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
252
-	include_spip('base/abstract_sql');
253
-
254
-	if (!is_array($tables)) {
255
-		$liste = liste_des_champs();
256
-
257
-		if (is_string($tables) && $tables != '') {
258
-			$toutes = [];
259
-			foreach (explode(',', $tables) as $t) {
260
-				$t = trim($t);
261
-				if (isset($liste[$t])) {
262
-					$toutes[$t] = $liste[$t];
263
-				}
264
-			}
265
-			$tables = $toutes;
266
-			unset($toutes);
267
-		} else {
268
-			$tables = $liste;
269
-		}
270
-	}
271
-
272
-	if (!strlen($recherche) || $tables === []) {
273
-		return [];
274
-	}
275
-
276
-	include_spip('inc/autoriser');
277
-
278
-	// options par defaut
279
-	$options = array_merge(
280
-		[
281
-		'preg_flags' => 'UimsS',
282
-		'toutvoir' => false,
283
-		'champs' => false,
284
-		'score' => false,
285
-		'matches' => false,
286
-		'jointures' => false,
287
-		'serveur' => $serveur
288
-		],
289
-		$options
290
-	);
291
-
292
-	$results = [];
293
-
294
-	// Utiliser l'iterateur (DATA:recherche)
295
-	// pour recuperer les couples (id_objet, score)
296
-	// Le resultat est au format {
297
-	//      id1 = { 'score' => x, attrs => { } },
298
-	//      id2 = { 'score' => x, attrs => { } },
299
-	// }
300
-
301
-	include_spip('inc/recherche_to_array');
302
-
303
-	foreach ($tables as $table => $champs) {
304
-		# lock via memoization, si dispo
305
-		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
-		}
308
-
309
-		spip_timer('rech');
310
-
311
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
312
-		$to_array = charger_fonction('recherche_to_array', 'inc');
313
-		$results[$table] = $to_array(
314
-			$recherche,
315
-			array_merge($options, ['table' => $table, 'champs' => $champs])
316
-		);
317
-		##var_dump($results[$table]);
318
-
319
-
320
-		spip_log(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
-			'recherche'
323
-		);
324
-
325
-		if (isset($lock)) {
326
-			cache_unlock($lock);
327
-		}
328
-	}
329
-
330
-	return $results;
252
+    include_spip('base/abstract_sql');
253
+
254
+    if (!is_array($tables)) {
255
+        $liste = liste_des_champs();
256
+
257
+        if (is_string($tables) && $tables != '') {
258
+            $toutes = [];
259
+            foreach (explode(',', $tables) as $t) {
260
+                $t = trim($t);
261
+                if (isset($liste[$t])) {
262
+                    $toutes[$t] = $liste[$t];
263
+                }
264
+            }
265
+            $tables = $toutes;
266
+            unset($toutes);
267
+        } else {
268
+            $tables = $liste;
269
+        }
270
+    }
271
+
272
+    if (!strlen($recherche) || $tables === []) {
273
+        return [];
274
+    }
275
+
276
+    include_spip('inc/autoriser');
277
+
278
+    // options par defaut
279
+    $options = array_merge(
280
+        [
281
+        'preg_flags' => 'UimsS',
282
+        'toutvoir' => false,
283
+        'champs' => false,
284
+        'score' => false,
285
+        'matches' => false,
286
+        'jointures' => false,
287
+        'serveur' => $serveur
288
+        ],
289
+        $options
290
+    );
291
+
292
+    $results = [];
293
+
294
+    // Utiliser l'iterateur (DATA:recherche)
295
+    // pour recuperer les couples (id_objet, score)
296
+    // Le resultat est au format {
297
+    //      id1 = { 'score' => x, attrs => { } },
298
+    //      id2 = { 'score' => x, attrs => { } },
299
+    // }
300
+
301
+    include_spip('inc/recherche_to_array');
302
+
303
+    foreach ($tables as $table => $champs) {
304
+        # lock via memoization, si dispo
305
+        if (function_exists('cache_lock')) {
306
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
307
+        }
308
+
309
+        spip_timer('rech');
310
+
311
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
312
+        $to_array = charger_fonction('recherche_to_array', 'inc');
313
+        $results[$table] = $to_array(
314
+            $recherche,
315
+            array_merge($options, ['table' => $table, 'champs' => $champs])
316
+        );
317
+        ##var_dump($results[$table]);
318
+
319
+
320
+        spip_log(
321
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
322
+            'recherche'
323
+        );
324
+
325
+        if (isset($lock)) {
326
+            cache_unlock($lock);
327
+        }
328
+    }
329
+
330
+    return $results;
331 331
 }
332 332
 
333 333
 
334 334
 // Effectue une recherche sur toutes les tables de la base de donnees
335 335
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
336
-	include_spip('inc/modifier');
337
-
338
-	// options par defaut
339
-	$options = array_merge(
340
-		[
341
-		'preg_flags' => 'UimsS',
342
-		'toutmodifier' => false
343
-		],
344
-		$options
345
-	);
346
-	$options['champs'] = true;
347
-
348
-
349
-	if (!is_array($tables)) {
350
-		$tables = liste_des_champs();
351
-	}
352
-
353
-	$results = recherche_en_base($recherche, $tables, $options);
354
-
355
-	$preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
356
-
357
-	foreach ($results as $table => $r) {
358
-		$_id_table = id_table_objet($table);
359
-		foreach ($r as $id => $x) {
360
-			if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
361
-				$modifs = [];
362
-				foreach ($x['champs'] as $key => $val) {
363
-					if ($key == $_id_table) {
364
-						continue;
365
-					}
366
-					$repl = preg_replace($preg, (string) $remplace, (string) $val);
367
-					if ($repl != $val) {
368
-						$modifs[$key] = $repl;
369
-					}
370
-				}
371
-				if ($modifs) {
372
-					objet_modifier_champs(
373
-						$table,
374
-						$id,
375
-						[
376
-							'champs' => array_keys($modifs),
377
-						],
378
-						$modifs
379
-					);
380
-				}
381
-			}
382
-		}
383
-	}
336
+    include_spip('inc/modifier');
337
+
338
+    // options par defaut
339
+    $options = array_merge(
340
+        [
341
+        'preg_flags' => 'UimsS',
342
+        'toutmodifier' => false
343
+        ],
344
+        $options
345
+    );
346
+    $options['champs'] = true;
347
+
348
+
349
+    if (!is_array($tables)) {
350
+        $tables = liste_des_champs();
351
+    }
352
+
353
+    $results = recherche_en_base($recherche, $tables, $options);
354
+
355
+    $preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
356
+
357
+    foreach ($results as $table => $r) {
358
+        $_id_table = id_table_objet($table);
359
+        foreach ($r as $id => $x) {
360
+            if ($options['toutmodifier'] || autoriser('modifier', $table, $id)) {
361
+                $modifs = [];
362
+                foreach ($x['champs'] as $key => $val) {
363
+                    if ($key == $_id_table) {
364
+                        continue;
365
+                    }
366
+                    $repl = preg_replace($preg, (string) $remplace, (string) $val);
367
+                    if ($repl != $val) {
368
+                        $modifs[$key] = $repl;
369
+                    }
370
+                }
371
+                if ($modifs) {
372
+                    objet_modifier_champs(
373
+                        $table,
374
+                        $id,
375
+                        [
376
+                            'champs' => array_keys($modifs),
377
+                        ],
378
+                        $modifs
379
+                    );
380
+                }
381
+            }
382
+        }
383
+    }
384 384
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	if (str_starts_with($recherche, '/') && str_ends_with($recherche, '/') && strlen($recherche) > 2) {
99 99
 		// c'est une preg
100 100
 		$recherche_trans = translitteration($recherche);
101
-		$preg = $recherche_trans . $options['preg_flags'];
101
+		$preg = $recherche_trans.$options['preg_flags'];
102 102
 		$is_preg = true;
103 103
 	} else {
104 104
 		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 			}
119 119
 		}
120 120
 
121
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
121
+		if (preg_match(',\s+,'.$u, $recherche_mod)) {
122 122
 			$is_preg = true;
123 123
 
124 124
 			$recherche_inter = '|';
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 			foreach ($recherche_mots as $mot) {
129 129
 				if (strlen($mot) >= $min_long) {
130 130
 					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
131
-					$recherche_inter .= preg_quote($mot) . ' ';
131
+					$recherche_inter .= preg_quote($mot).' ';
132 132
 					$petits_mots = false;
133 133
 				}
134 134
 			}
@@ -136,14 +136,14 @@  discard block
 block discarded – undo
136 136
 
137 137
 			// mais on cherche quand même l'expression complète, même si elle
138 138
 			// comporte des mots de moins de quatre lettres
139
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
139
+			$recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
140 140
 			if (!$recherche || $petits_mots) {
141 141
 				$recherche = preg_quote($recherche_org);
142 142
 			}
143 143
 			$recherche_trans = translitteration($recherche);
144 144
 		}
145 145
 
146
-		$preg = '/' . str_replace('/', '\\/', (string) $recherche_trans) . '/' . $options['preg_flags'];
146
+		$preg = '/'.str_replace('/', '\\/', (string) $recherche_trans).'/'.$options['preg_flags'];
147 147
 	}
148 148
 
149 149
 	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 		$q = sql_quote(
182 182
 			'%'
183
-			. preg_replace(',\s+,' . $u, '%', $q)
183
+			. preg_replace(',\s+,'.$u, '%', $q)
184 184
 			. '%'
185 185
 		);
186 186
 
187
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim((string) $recherche_mod)) . '/' . $options['preg_flags'];
187
+		$preg = '/'.preg_replace(',\s+,'.$u, '.+', trim((string) $recherche_mod)).'/'.$options['preg_flags'];
188 188
 	} else {
189 189
 		$methode = 'REGEXP';
190 190
 		$q = sql_quote(trim($recherche, '/'));
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	foreach ($tables as $table => $champs) {
304 304
 		# lock via memoization, si dispo
305 305
 		if (function_exists('cache_lock')) {
306
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
306
+			cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche);
307 307
 		}
308 308
 
309 309
 		spip_timer('rech');
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 
319 319
 
320 320
 		spip_log(
321
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
321
+			"recherche $table ($recherche) : ".(is_countable($results[$table]) ? count($results[$table]) : 0).' resultats '.spip_timer('rech'),
322 322
 			'recherche'
323 323
 		);
324 324
 
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 
353 353
 	$results = recherche_en_base($recherche, $tables, $options);
354 354
 
355
-	$preg = '/' . str_replace('/', '\\/', (string) $recherche) . '/' . $options['preg_flags'];
355
+	$preg = '/'.str_replace('/', '\\/', (string) $recherche).'/'.$options['preg_flags'];
356 356
 
357 357
 	foreach ($results as $table => $r) {
358 358
 		$_id_table = id_table_objet($table);
Please login to merge, or discard this patch.
ecrire/inc/icone_renommer.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -10,71 +10,71 @@
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 include_spip('inc/boutons');
17 17
 include_spip('base/objets');
18 18
 
19 19
 function inc_icone_renommer_dist($fond, $fonction) {
20
-	$size = 24;
21
-	if (
22
-		preg_match('/(?:-(\d{1,3}))?([.](gif|png|svg))?$/i', (string) $fond, $match)
23
-		&& (isset($match[0]) && $match[0] || isset($match[1]) && $match[1])
24
-	) {
25
-		if (isset($match[1]) && $match[1]) {
26
-			$size = $match[1];
27
-		}
28
-		$type = substr((string) $fond, 0, -strlen($match[0]));
29
-		if (!isset($match[2]) || !$match[2]) {
30
-			$fond .= '.png';
31
-		}
32
-	} else {
33
-		$type = $fond;
34
-		$fond .= '.png';
35
-	}
20
+    $size = 24;
21
+    if (
22
+        preg_match('/(?:-(\d{1,3}))?([.](gif|png|svg))?$/i', (string) $fond, $match)
23
+        && (isset($match[0]) && $match[0] || isset($match[1]) && $match[1])
24
+    ) {
25
+        if (isset($match[1]) && $match[1]) {
26
+            $size = $match[1];
27
+        }
28
+        $type = substr((string) $fond, 0, -strlen($match[0]));
29
+        if (!isset($match[2]) || !$match[2]) {
30
+            $fond .= '.png';
31
+        }
32
+    } else {
33
+        $type = $fond;
34
+        $fond .= '.png';
35
+    }
36 36
 
37
-	$rtl = false;
38
-	if (preg_match(',[-_]rtl$,i', (string) $type, $match)) {
39
-		$rtl = true;
40
-		$type = substr((string) $type, 0, -strlen($match[0]));
41
-	}
37
+    $rtl = false;
38
+    if (preg_match(',[-_]rtl$,i', (string) $type, $match)) {
39
+        $rtl = true;
40
+        $type = substr((string) $type, 0, -strlen($match[0]));
41
+    }
42 42
 
43
-	// objet_type garde invariant tout ce qui ne commence par par id_, spip_
44
-	// et ne finit pas par un s, sauf si c'est une exception declaree
45
-	$type = objet_type($type, false);
43
+    // objet_type garde invariant tout ce qui ne commence par par id_, spip_
44
+    // et ne finit pas par un s, sauf si c'est une exception declaree
45
+    $type = objet_type($type, false);
46 46
 
47
-	$dir = 'images/';
48
-	$f = "$type-$size.png";
49
-	if ($icone = find_in_theme($dir . $f)) {
50
-		$dir = dirname((string) $icone);
51
-		$fond = $icone;
47
+    $dir = 'images/';
48
+    $f = "$type-$size.png";
49
+    if ($icone = find_in_theme($dir . $f)) {
50
+        $dir = dirname((string) $icone);
51
+        $fond = $icone;
52 52
 
53
-		if (
54
-			$rtl
55
-			&& ($fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename((string) $icone)))
56
-			&& file_exists($fr)
57
-		) {
58
-			$fond = $fr;
59
-		}
53
+        if (
54
+            $rtl
55
+            && ($fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename((string) $icone)))
56
+            && file_exists($fr)
57
+        ) {
58
+            $fond = $fr;
59
+        }
60 60
 
61
-		$action = $fonction;
62
-		if ($action == 'supprimer.gif') {
63
-			$action = 'del';
64
-		} elseif ($action == 'creer.gif') {
65
-			$action = 'new';
66
-		} elseif ($action == 'edit.gif') {
67
-			$action = 'edit';
68
-		}
61
+        $action = $fonction;
62
+        if ($action == 'supprimer.gif') {
63
+            $action = 'del';
64
+        } elseif ($action == 'creer.gif') {
65
+            $action = 'new';
66
+        } elseif ($action == 'edit.gif') {
67
+            $action = 'edit';
68
+        }
69 69
 
70
-		$fonction = '';
71
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
72
-			$fonction = $action;
73
-		}
70
+        $fonction = '';
71
+        if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
72
+            $fonction = $action;
73
+        }
74 74
 
75
-		// c'est bon !
76
-		return [$fond, $fonction];
77
-	}
75
+        // c'est bon !
76
+        return [$fond, $fonction];
77
+    }
78 78
 
79
-	return [$fond, $fonction];
79
+    return [$fond, $fonction];
80 80
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 
47 47
 	$dir = 'images/';
48 48
 	$f = "$type-$size.png";
49
-	if ($icone = find_in_theme($dir . $f)) {
49
+	if ($icone = find_in_theme($dir.$f)) {
50 50
 		$dir = dirname((string) $icone);
51 51
 		$fond = $icone;
52 52
 
53 53
 		if (
54 54
 			$rtl
55
-			&& ($fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename((string) $icone)))
55
+			&& ($fr = $dir.'/'.str_replace("$type-", "$type-rtl-", basename((string) $icone)))
56 56
 			&& file_exists($fr)
57 57
 		) {
58 58
 			$fond = $fr;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		}
69 69
 
70 70
 		$fonction = '';
71
-		if (in_array($action, ['add','del', 'new', 'edit', 'config'])) {
71
+		if (in_array($action, ['add', 'del', 'new', 'edit', 'config'])) {
72 72
 			$fonction = $action;
73 73
 		}
74 74
 
Please login to merge, or discard this patch.
ecrire/inc/auth.php 2 patches
Indentation   +442 added lines, -442 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('base/abstract_sql');
@@ -34,33 +34,33 @@  discard block
 block discarded – undo
34 34
  *  - une chaîne vide si autorisation à pénétrer dans l'espace privé.
35 35
  */
36 36
 function inc_auth_dist() {
37
-	$row = auth_mode();
37
+    $row = auth_mode();
38 38
 
39
-	if ($row) {
40
-		return auth_init_droits($row);
41
-	}
39
+    if ($row) {
40
+        return auth_init_droits($row);
41
+    }
42 42
 
43
-	if (!$GLOBALS['connect_login']) {
44
-		return auth_a_loger();
45
-	}
43
+    if (!$GLOBALS['connect_login']) {
44
+        return auth_a_loger();
45
+    }
46 46
 
47
-	// Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
48
-	// C'est soit parce que la base est inutilisable,
49
-	// soit parce que la table des auteurs a changee (restauration etc)
50
-	// Pas la peine d'insister.
51
-	// Renvoyer le nom fautif et une URL de remise a zero
47
+    // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui
48
+    // C'est soit parce que la base est inutilisable,
49
+    // soit parce que la table des auteurs a changee (restauration etc)
50
+    // Pas la peine d'insister.
51
+    // Renvoyer le nom fautif et une URL de remise a zero
52 52
 
53
-	if (spip_connect()) {
54
-		return [
55
-			'login' => $GLOBALS['connect_login'],
56
-			'site' => generer_url_public('', 'action=logout&amp;logout=prive')
57
-		];
58
-	}
53
+    if (spip_connect()) {
54
+        return [
55
+            'login' => $GLOBALS['connect_login'],
56
+            'site' => generer_url_public('', 'action=logout&amp;logout=prive')
57
+        ];
58
+    }
59 59
 
60
-	$n = (int) sql_errno();
61
-	spip_log("Erreur base de donnees $n " . sql_error());
60
+    $n = (int) sql_errno();
61
+    spip_log("Erreur base de donnees $n " . sql_error());
62 62
 
63
-	return $n ?: 1;
63
+    return $n ?: 1;
64 64
 }
65 65
 
66 66
 /**
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
  */
70 70
 function auth_controler_password_auteur_connecte(#[\SensitiveParameter] string $password): bool {
71 71
 
72
-	if (
73
-		empty($GLOBALS['visiteur_session']['id_auteur'])
74
-		|| empty($GLOBALS['visiteur_session']['login'])
75
-	) {
76
-		return false;
77
-	}
72
+    if (
73
+        empty($GLOBALS['visiteur_session']['id_auteur'])
74
+        || empty($GLOBALS['visiteur_session']['login'])
75
+    ) {
76
+        return false;
77
+    }
78 78
 
79
-	$auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
80
-	return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'];
79
+    $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true);
80
+    return is_array($auth) && $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'];
81 81
 }
82 82
 
83 83
 /**
@@ -89,47 +89,47 @@  discard block
 block discarded – undo
89 89
  * @return array|string
90 90
  */
91 91
 function auth_echec($raison) {
92
-	include_spip('inc/minipres');
93
-	include_spip('inc/headers');
94
-	// pas authentifie. Pourquoi ?
95
-	if (is_string($raison)) {
96
-		// redirection vers une page d'authentification
97
-		// on ne revient pas de cette fonction
98
-		// sauf si pb de header
99
-		$raison = redirige_formulaire($raison);
100
-	} elseif (is_int($raison)) {
101
-		// erreur SQL a afficher
102
-		$raison = minipres(
103
-			_T('info_travaux_titre'),
104
-			_T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
105
-		);
106
-	} elseif (@$raison['statut']) {
107
-		// un simple visiteur n'a pas acces a l'espace prive
108
-		spip_log('connexion refusee a ' . @$raison['id_auteur']);
109
-		$est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110
-		$raison = minipres(
111
-			_T('avis_erreur_connexion'),
112
-			_T('avis_erreur_visiteur')
113
-				// Lien vers le site public
114
-				. '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
115
-				// Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
-				. ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
117
-		);
118
-	} else {
119
-		// auteur en fin de droits ...
120
-		$h = $raison['site'];
121
-		$raison = minipres(
122
-			_T('avis_erreur_connexion'),
123
-			'<br /><br /><p>'
124
-			. _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
125
-			. " <a href='$h'>"
126
-			. _T('texte_inc_auth_2')
127
-			. '</a>'
128
-			. _T('texte_inc_auth_3')
129
-		);
130
-	}
131
-
132
-	return $raison;
92
+    include_spip('inc/minipres');
93
+    include_spip('inc/headers');
94
+    // pas authentifie. Pourquoi ?
95
+    if (is_string($raison)) {
96
+        // redirection vers une page d'authentification
97
+        // on ne revient pas de cette fonction
98
+        // sauf si pb de header
99
+        $raison = redirige_formulaire($raison);
100
+    } elseif (is_int($raison)) {
101
+        // erreur SQL a afficher
102
+        $raison = minipres(
103
+            _T('info_travaux_titre'),
104
+            _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
105
+        );
106
+    } elseif (@$raison['statut']) {
107
+        // un simple visiteur n'a pas acces a l'espace prive
108
+        spip_log('connexion refusee a ' . @$raison['id_auteur']);
109
+        $est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110
+        $raison = minipres(
111
+            _T('avis_erreur_connexion'),
112
+            _T('avis_erreur_visiteur')
113
+                // Lien vers le site public
114
+                . '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
115
+                // Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
+                . ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
117
+        );
118
+    } else {
119
+        // auteur en fin de droits ...
120
+        $h = $raison['site'];
121
+        $raison = minipres(
122
+            _T('avis_erreur_connexion'),
123
+            '<br /><br /><p>'
124
+            . _T('texte_inc_auth_1', ['auth_login' => $raison['login']])
125
+            . " <a href='$h'>"
126
+            . _T('texte_inc_auth_2')
127
+            . '</a>'
128
+            . _T('texte_inc_auth_3')
129
+        );
130
+    }
131
+
132
+    return $raison;
133 133
 }
134 134
 
135 135
 /**
@@ -139,79 +139,79 @@  discard block
 block discarded – undo
139 139
  * @return array|bool|string
140 140
  */
141 141
 function auth_mode() {
142
-	//
143
-	// Initialiser variables (eviter hacks par URL)
144
-	//
145
-	$GLOBALS['connect_login'] = '';
146
-	$id_auteur = null;
147
-	$GLOBALS['auth_can_disconnect'] = false;
148
-
149
-	//
150
-	// Recuperer les donnees d'identification
151
-	//
152
-	include_spip('inc/session');
153
-	// Session valide en cours ?
154
-	if (isset($_COOKIE['spip_session'])) {
155
-		$session = charger_fonction('session', 'inc');
156
-		if (
157
-			($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration
158
-		) {
159
-			$GLOBALS['auth_can_disconnect'] = true;
160
-			$GLOBALS['connect_login'] = session_get('login');
161
-		} else {
162
-			unset($_COOKIE['spip_session']);
163
-		}
164
-	}
165
-
166
-	// Essayer auth http si significatif
167
-	// (ignorer les login d'intranet independants de spip)
168
-	if (!$GLOBALS['ignore_auth_http']) {
169
-		if (
170
-			isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
171
-				&& ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
172
-			// Si auth http differtente de basic, PHP_AUTH_PW
173
-			// est indisponible mais tentons quand meme pour
174
-			// autocreation via LDAP
175
-			|| isset($_SERVER['REMOTE_USER'])
176
-				&& ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
177
-		) {
178
-			if (!$id_auteur) {
179
-				$_SERVER['PHP_AUTH_PW'] = '';
180
-				$GLOBALS['auth_can_disconnect'] = true;
181
-				$GLOBALS['visiteur_session'] = $r;
182
-				$GLOBALS['connect_login'] = session_get('login');
183
-				$id_auteur = $r['id_auteur'];
184
-			} else {
185
-				// cas de la session en plus de PHP_AUTH
186
-				/*				  if ($id_auteur != $r['id_auteur']){
142
+    //
143
+    // Initialiser variables (eviter hacks par URL)
144
+    //
145
+    $GLOBALS['connect_login'] = '';
146
+    $id_auteur = null;
147
+    $GLOBALS['auth_can_disconnect'] = false;
148
+
149
+    //
150
+    // Recuperer les donnees d'identification
151
+    //
152
+    include_spip('inc/session');
153
+    // Session valide en cours ?
154
+    if (isset($_COOKIE['spip_session'])) {
155
+        $session = charger_fonction('session', 'inc');
156
+        if (
157
+            ($id_auteur = $session()) || $id_auteur === 0 // reprise sur restauration
158
+        ) {
159
+            $GLOBALS['auth_can_disconnect'] = true;
160
+            $GLOBALS['connect_login'] = session_get('login');
161
+        } else {
162
+            unset($_COOKIE['spip_session']);
163
+        }
164
+    }
165
+
166
+    // Essayer auth http si significatif
167
+    // (ignorer les login d'intranet independants de spip)
168
+    if (!$GLOBALS['ignore_auth_http']) {
169
+        if (
170
+            isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])
171
+                && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
172
+            // Si auth http differtente de basic, PHP_AUTH_PW
173
+            // est indisponible mais tentons quand meme pour
174
+            // autocreation via LDAP
175
+            || isset($_SERVER['REMOTE_USER'])
176
+                && ($r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], ''))
177
+        ) {
178
+            if (!$id_auteur) {
179
+                $_SERVER['PHP_AUTH_PW'] = '';
180
+                $GLOBALS['auth_can_disconnect'] = true;
181
+                $GLOBALS['visiteur_session'] = $r;
182
+                $GLOBALS['connect_login'] = session_get('login');
183
+                $id_auteur = $r['id_auteur'];
184
+            } else {
185
+                // cas de la session en plus de PHP_AUTH
186
+                /*				  if ($id_auteur != $r['id_auteur']){
187 187
 					spip_log("vol de session $id_auteur" . join(', ', $r));
188 188
 				unset($_COOKIE['spip_session']);
189 189
 				$id_auteur = '';
190 190
 				} */
191
-			}
192
-		} else {
193
-			// Authentification .htaccess old style, car .htaccess semble
194
-			// souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
195
-			if (isset($_SERVER['REMOTE_USER'])) {
196
-				$GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
197
-			}
198
-		}
199
-	}
200
-
201
-	$where = (is_numeric($id_auteur)
202
-		/*AND $id_auteur>0*/ // reprise lors des restaurations
203
-	) ?
204
-		"id_auteur=$id_auteur" :
205
-		(strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206
-
207
-	if (!$where) {
208
-		return '';
209
-	}
210
-
211
-	// Trouver les autres infos dans la table auteurs.
212
-	// le champ 'quand' est utilise par l'agenda
213
-
214
-	return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
191
+            }
192
+        } else {
193
+            // Authentification .htaccess old style, car .htaccess semble
194
+            // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW
195
+            if (isset($_SERVER['REMOTE_USER'])) {
196
+                $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER'];
197
+            }
198
+        }
199
+    }
200
+
201
+    $where = (is_numeric($id_auteur)
202
+        /*AND $id_auteur>0*/ // reprise lors des restaurations
203
+    ) ?
204
+        "id_auteur=$id_auteur" :
205
+        (strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206
+
207
+    if (!$where) {
208
+        return '';
209
+    }
210
+
211
+    // Trouver les autres infos dans la table auteurs.
212
+    // le champ 'quand' est utilise par l'agenda
213
+
214
+    return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'");
215 215
 }
216 216
 
217 217
 /**
@@ -229,85 +229,85 @@  discard block
 block discarded – undo
229 229
  */
230 230
 function auth_init_droits($row) {
231 231
 
232
-	include_spip('inc/autoriser');
233
-	if (!autoriser('loger', '', 0, $row)) {
234
-		return false;
235
-	}
236
-
237
-
238
-	if ($row['statut'] == 'nouveau') {
239
-		include_spip('action/inscrire_auteur');
240
-		$row = confirmer_statut_inscription($row);
241
-	}
242
-
243
-	$GLOBALS['connect_id_auteur'] = $row['id_auteur'];
244
-	$GLOBALS['connect_login'] = $row['login'];
245
-	$GLOBALS['connect_statut'] = $row['statut'];
246
-
247
-	$GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row);
248
-
249
-	// au cas ou : ne pas memoriser les champs sensibles
250
-	unset($GLOBALS['visiteur_session']['pass']);
251
-	unset($GLOBALS['visiteur_session']['htpass']);
252
-	unset($GLOBALS['visiteur_session']['alea_actuel']);
253
-	unset($GLOBALS['visiteur_session']['alea_futur']);
254
-	unset($GLOBALS['visiteur_session']['ldap_password']);
255
-
256
-	// creer la session au besoin
257
-	if (!isset($_COOKIE['spip_session'])) {
258
-		$session = charger_fonction('session', 'inc');
259
-		$spip_session = $session($row);
260
-	}
261
-
262
-	// reinjecter les preferences_auteur apres le reset de spip_session
263
-	// car utilisees au retour par auth_loger()
264
-	$r = @unserialize($row['prefs']);
265
-	$GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
266
-	// si prefs pas definies, les definir par defaut
267
-	if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
268
-		$GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
269
-		$GLOBALS['visiteur_session']['prefs']['display'] = 2;
270
-		$GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
271
-	}
272
-
273
-	$GLOBALS['visiteur_session'] = pipeline(
274
-		'preparer_visiteur_session',
275
-		['args' => ['row' => $row],
276
-		'data' => $GLOBALS['visiteur_session']]
277
-	);
278
-
279
-	// Etablir les droits selon le codage attendu
280
-	// dans ecrire/index.php ecrire/prive.php
281
-
282
-	// Pas autorise a acceder a ecrire ? renvoyer le tableau
283
-	// A noter : le premier appel a autoriser() a le bon gout
284
-	// d'initialiser $GLOBALS['visiteur_session']['restreint'],
285
-	// qui ne figure pas dans le fichier de session
286
-
287
-	if (!autoriser('ecrire')) {
288
-		return $row;
289
-	}
290
-
291
-	// autoriser('ecrire') ne laisse passer que les Admin et les Redac
292
-
293
-	auth_trace($row);
294
-
295
-	// Administrateurs
296
-	if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
297
-		if (
298
-			isset($GLOBALS['visiteur_session']['restreint'])
299
-			&& is_array($GLOBALS['visiteur_session']['restreint'])
300
-		) {
301
-			$GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
302
-		}
303
-		if ($GLOBALS['connect_statut'] == '0minirezo') {
304
-			$GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
305
-		}
306
-	}
307
-
308
-	// Pour les redacteurs, inc_version a fait l'initialisation minimale
309
-
310
-	return ''; // i.e. pas de pb.
232
+    include_spip('inc/autoriser');
233
+    if (!autoriser('loger', '', 0, $row)) {
234
+        return false;
235
+    }
236
+
237
+
238
+    if ($row['statut'] == 'nouveau') {
239
+        include_spip('action/inscrire_auteur');
240
+        $row = confirmer_statut_inscription($row);
241
+    }
242
+
243
+    $GLOBALS['connect_id_auteur'] = $row['id_auteur'];
244
+    $GLOBALS['connect_login'] = $row['login'];
245
+    $GLOBALS['connect_statut'] = $row['statut'];
246
+
247
+    $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row);
248
+
249
+    // au cas ou : ne pas memoriser les champs sensibles
250
+    unset($GLOBALS['visiteur_session']['pass']);
251
+    unset($GLOBALS['visiteur_session']['htpass']);
252
+    unset($GLOBALS['visiteur_session']['alea_actuel']);
253
+    unset($GLOBALS['visiteur_session']['alea_futur']);
254
+    unset($GLOBALS['visiteur_session']['ldap_password']);
255
+
256
+    // creer la session au besoin
257
+    if (!isset($_COOKIE['spip_session'])) {
258
+        $session = charger_fonction('session', 'inc');
259
+        $spip_session = $session($row);
260
+    }
261
+
262
+    // reinjecter les preferences_auteur apres le reset de spip_session
263
+    // car utilisees au retour par auth_loger()
264
+    $r = @unserialize($row['prefs']);
265
+    $GLOBALS['visiteur_session']['prefs'] = ($r ?: []);
266
+    // si prefs pas definies, les definir par defaut
267
+    if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) {
268
+        $GLOBALS['visiteur_session']['prefs']['couleur'] = 2;
269
+        $GLOBALS['visiteur_session']['prefs']['display'] = 2;
270
+        $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones';
271
+    }
272
+
273
+    $GLOBALS['visiteur_session'] = pipeline(
274
+        'preparer_visiteur_session',
275
+        ['args' => ['row' => $row],
276
+        'data' => $GLOBALS['visiteur_session']]
277
+    );
278
+
279
+    // Etablir les droits selon le codage attendu
280
+    // dans ecrire/index.php ecrire/prive.php
281
+
282
+    // Pas autorise a acceder a ecrire ? renvoyer le tableau
283
+    // A noter : le premier appel a autoriser() a le bon gout
284
+    // d'initialiser $GLOBALS['visiteur_session']['restreint'],
285
+    // qui ne figure pas dans le fichier de session
286
+
287
+    if (!autoriser('ecrire')) {
288
+        return $row;
289
+    }
290
+
291
+    // autoriser('ecrire') ne laisse passer que les Admin et les Redac
292
+
293
+    auth_trace($row);
294
+
295
+    // Administrateurs
296
+    if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) {
297
+        if (
298
+            isset($GLOBALS['visiteur_session']['restreint'])
299
+            && is_array($GLOBALS['visiteur_session']['restreint'])
300
+        ) {
301
+            $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint'];
302
+        }
303
+        if ($GLOBALS['connect_statut'] == '0minirezo') {
304
+            $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique'];
305
+        }
306
+    }
307
+
308
+    // Pour les redacteurs, inc_version a fait l'initialisation minimale
309
+
310
+    return ''; // i.e. pas de pb.
311 311
 }
312 312
 
313 313
 /**
@@ -316,23 +316,23 @@  discard block
 block discarded – undo
316 316
  * @return string
317 317
  */
318 318
 function auth_a_loger() {
319
-	$redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
320
-
321
-	// un echec au "bonjour" (login initial) quand le statut est
322
-	// inconnu signale sans doute un probleme de cookies
323
-	if (isset($_GET['bonjour'])) {
324
-		$redirect = parametre_url(
325
-			$redirect,
326
-			'var_erreur',
327
-			(isset($GLOBALS['visiteur_session']['statut'])
328
-				? 'statut'
329
-				: 'cookie'
330
-			),
331
-			'&'
332
-		);
333
-	}
334
-
335
-	return $redirect;
319
+    $redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
320
+
321
+    // un echec au "bonjour" (login initial) quand le statut est
322
+    // inconnu signale sans doute un probleme de cookies
323
+    if (isset($_GET['bonjour'])) {
324
+        $redirect = parametre_url(
325
+            $redirect,
326
+            'var_erreur',
327
+            (isset($GLOBALS['visiteur_session']['statut'])
328
+                ? 'statut'
329
+                : 'cookie'
330
+            ),
331
+            '&'
332
+        );
333
+    }
334
+
335
+    return $redirect;
336 336
 }
337 337
 
338 338
 /**
@@ -344,19 +344,19 @@  discard block
 block discarded – undo
344 344
  * @param null|string $date
345 345
  */
346 346
 function auth_trace($row, $date = null) {
347
-	// Indiquer la connexion. A la minute pres ca suffit.
348
-	if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
349
-		$connect_quand = strtotime((string) $connect_quand);
350
-	}
347
+    // Indiquer la connexion. A la minute pres ca suffit.
348
+    if (!is_numeric($connect_quand = $row['quand'] ?? '')) {
349
+        $connect_quand = strtotime((string) $connect_quand);
350
+    }
351 351
 
352
-	$date ??= date('Y-m-d H:i:s');
352
+    $date ??= date('Y-m-d H:i:s');
353 353
 
354
-	if (abs(strtotime($date) - $connect_quand) >= 60) {
355
-		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
356
-		$row['en_ligne'] = $date;
357
-	}
354
+    if (abs(strtotime($date) - $connect_quand) >= 60) {
355
+        sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
356
+        $row['en_ligne'] = $date;
357
+    }
358 358
 
359
-	pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
359
+    pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]);
360 360
 }
361 361
 
362 362
 
@@ -382,27 +382,27 @@  discard block
 block discarded – undo
382 382
  * @return mixed
383 383
  */
384 384
 function auth_administrer($fonction, $args, mixed $defaut = false) {
385
-	$auth_methode = array_shift($args);
386
-	$auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
387
-	if (
388
-		($auth = charger_fonction($auth_methode, 'auth', true))
389
-		&& function_exists($f = "auth_{$auth_methode}_$fonction")
390
-	) {
391
-		$res = $f(...$args);
392
-	} else {
393
-		$res = $defaut;
394
-	}
395
-	return pipeline(
396
-		'auth_administrer',
397
-		[
398
-			'args' => [
399
-				'fonction' => $fonction,
400
-				'methode' => $auth_methode,
401
-				'args' => $args
402
-			],
403
-			'data' => $res
404
-		]
405
-	);
385
+    $auth_methode = array_shift($args);
386
+    $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou
387
+    if (
388
+        ($auth = charger_fonction($auth_methode, 'auth', true))
389
+        && function_exists($f = "auth_{$auth_methode}_$fonction")
390
+    ) {
391
+        $res = $f(...$args);
392
+    } else {
393
+        $res = $defaut;
394
+    }
395
+    return pipeline(
396
+        'auth_administrer',
397
+        [
398
+            'args' => [
399
+                'fonction' => $fonction,
400
+                'methode' => $auth_methode,
401
+                'args' => $args
402
+            ],
403
+            'data' => $res
404
+        ]
405
+    );
406 406
 }
407 407
 
408 408
 /**
@@ -412,11 +412,11 @@  discard block
 block discarded – undo
412 412
  * @return array
413 413
  */
414 414
 function auth_formulaire_login($flux) {
415
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
416
-		$flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
417
-	}
415
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
416
+        $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux);
417
+    }
418 418
 
419
-	return $flux;
419
+    return $flux;
420 420
 }
421 421
 
422 422
 
@@ -430,19 +430,19 @@  discard block
 block discarded – undo
430 430
  * @return string/bool
431 431
  */
432 432
 function auth_retrouver_login($login, $serveur = '') {
433
-	if (!spip_connect($serveur)) {
434
-		include_spip('inc/minipres');
435
-		echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
436
-		exit;
437
-	}
438
-
439
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
440
-		if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
441
-			return $auteur;
442
-		}
443
-	}
444
-
445
-	return false;
433
+    if (!spip_connect($serveur)) {
434
+        include_spip('inc/minipres');
435
+        echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'));
436
+        exit;
437
+    }
438
+
439
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
440
+        if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) {
441
+            return $auteur;
442
+        }
443
+    }
444
+
445
+    return false;
446 446
 }
447 447
 
448 448
 /**
@@ -457,34 +457,34 @@  discard block
 block discarded – undo
457 457
  * @return array
458 458
  */
459 459
 function auth_informer_login($login, $serveur = '') {
460
-	if (
461
-		!$login
462
-		|| !($login_base = auth_retrouver_login($login, $serveur))
463
-		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
464
-	) {
465
-		// generer de fausses infos, mais credibles, pour eviter une attaque
466
-		// https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
467
-
468
-		$row = [
469
-			'login' => $login,
470
-			'cnx' => '0',
471
-			'logo' => '',
472
-		];
473
-
474
-		return $row;
475
-	}
476
-
477
-	$prefs = @unserialize($row['prefs']);
478
-	$infos = [
479
-		'id_auteur' => $row['id_auteur'],
480
-		'login' => $row['login'],
481
-		'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0',
482
-		'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
483
-	];
484
-
485
-	verifier_visiteur();
486
-
487
-	return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
460
+    if (
461
+        !$login
462
+        || !($login_base = auth_retrouver_login($login, $serveur))
463
+        || !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
464
+    ) {
465
+        // generer de fausses infos, mais credibles, pour eviter une attaque
466
+        // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
467
+
468
+        $row = [
469
+            'login' => $login,
470
+            'cnx' => '0',
471
+            'logo' => '',
472
+        ];
473
+
474
+        return $row;
475
+    }
476
+
477
+    $prefs = @unserialize($row['prefs']);
478
+    $infos = [
479
+        'id_auteur' => $row['id_auteur'],
480
+        'login' => $row['login'],
481
+        'cnx' => (isset($prefs['cnx']) && $prefs['cnx'] === 'perma') ? '1' : '0',
482
+        'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row),
483
+    ];
484
+
485
+    verifier_visiteur();
486
+
487
+    return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos);
488 488
 }
489 489
 
490 490
 
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
  * @return mixed
499 499
  */
500 500
 function auth_identifier_login($login, #[\SensitiveParameter] $password, $serveur = '', bool $phpauth = false) {
501
-	$erreur = '';
502
-	foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
503
-		if ($auth = charger_fonction($methode, 'auth', true)) {
504
-			$auteur = $auth($login, $password, $serveur, $phpauth);
505
-			if (is_array($auteur) && count($auteur)) {
506
-				spip_log("connexion de $login par methode $methode");
507
-				$auteur['auth'] = $methode;
508
-				return $auteur;
509
-			} elseif (is_string($auteur)) {
510
-				$erreur .= "$auteur ";
511
-			}
512
-		}
513
-	}
514
-
515
-	return $erreur;
501
+    $erreur = '';
502
+    foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
503
+        if ($auth = charger_fonction($methode, 'auth', true)) {
504
+            $auteur = $auth($login, $password, $serveur, $phpauth);
505
+            if (is_array($auteur) && count($auteur)) {
506
+                spip_log("connexion de $login par methode $methode");
507
+                $auteur['auth'] = $methode;
508
+                return $auteur;
509
+            } elseif (is_string($auteur)) {
510
+                $erreur .= "$auteur ";
511
+            }
512
+        }
513
+    }
514
+
515
+    return $erreur;
516 516
 }
517 517
 
518 518
 /**
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
  * @return string
527 527
  */
528 528
 function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') {
529
-	$securiser_action = charger_fonction('securiser_action', 'inc');
530
-	return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
529
+    $securiser_action = charger_fonction('securiser_action', 'inc');
530
+    return $securiser_action('auth', "$auth_methode/$login", $redirect, true);
531 531
 }
532 532
 
533 533
 /**
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
  * @return mixed
542 542
  */
543 543
 function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') {
544
-	$args = func_get_args();
545
-	return auth_administrer('terminer_identifier_login', $args);
544
+    $args = func_get_args();
545
+    return auth_administrer('terminer_identifier_login', $args);
546 546
 }
547 547
 
548 548
 /**
@@ -552,29 +552,29 @@  discard block
 block discarded – undo
552 552
  * @return bool
553 553
  */
554 554
 function auth_loger($auteur) {
555
-	if (!is_array($auteur) || $auteur === []) {
556
-		return false;
557
-	}
558
-
559
-	// initialiser et poser le cookie de session
560
-	unset($_COOKIE['spip_session']);
561
-	if (auth_init_droits($auteur) === false) {
562
-		return false;
563
-	}
564
-
565
-	// initialiser les prefs
566
-	$p = $GLOBALS['visiteur_session']['prefs'];
567
-	$p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : '';
568
-
569
-	sql_updateq(
570
-		'spip_auteurs',
571
-		['prefs' => serialize($p)],
572
-		'id_auteur=' . (int) $auteur['id_auteur']
573
-	);
574
-
575
-	//  bloquer ici le visiteur qui tente d'abuser de ses droits
576
-	verifier_visiteur();
577
-	return true;
555
+    if (!is_array($auteur) || $auteur === []) {
556
+        return false;
557
+    }
558
+
559
+    // initialiser et poser le cookie de session
560
+    unset($_COOKIE['spip_session']);
561
+    if (auth_init_droits($auteur) === false) {
562
+        return false;
563
+    }
564
+
565
+    // initialiser les prefs
566
+    $p = $GLOBALS['visiteur_session']['prefs'];
567
+    $p['cnx'] = (isset($auteur['cookie']) && $auteur['cookie'] == 'oui') ? 'perma' : '';
568
+
569
+    sql_updateq(
570
+        'spip_auteurs',
571
+        ['prefs' => serialize($p)],
572
+        'id_auteur=' . (int) $auteur['id_auteur']
573
+    );
574
+
575
+    //  bloquer ici le visiteur qui tente d'abuser de ses droits
576
+    verifier_visiteur();
577
+    return true;
578 578
 }
579 579
 
580 580
 /**
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
  * return void
585 585
  **/
586 586
 function auth_deloger() {
587
-	$logout = charger_fonction('logout', 'action');
588
-	$logout();
587
+    $logout = charger_fonction('logout', 'action');
588
+    $logout();
589 589
 }
590 590
 
591 591
 /**
@@ -599,8 +599,8 @@  discard block
 block discarded – undo
599 599
  * @return bool
600 600
  */
601 601
 function auth_autoriser_modifier_login($auth_methode, $serveur = '') {
602
-	$args = func_get_args();
603
-	return auth_administrer('autoriser_modifier_login', $args);
602
+    $args = func_get_args();
603
+    return auth_administrer('autoriser_modifier_login', $args);
604 604
 }
605 605
 
606 606
 /**
@@ -615,8 +615,8 @@  discard block
 block discarded – undo
615 615
  *  message d'erreur ou chaine vide si pas d'erreur
616 616
  */
617 617
 function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') {
618
-	$args = func_get_args();
619
-	return auth_administrer('verifier_login', $args, '');
618
+    $args = func_get_args();
619
+    return auth_administrer('verifier_login', $args, '');
620 620
 }
621 621
 
622 622
 /**
@@ -629,8 +629,8 @@  discard block
 block discarded – undo
629 629
  * @return bool
630 630
  */
631 631
 function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') {
632
-	$args = func_get_args();
633
-	return auth_administrer('modifier_login', $args);
632
+    $args = func_get_args();
633
+    return auth_administrer('modifier_login', $args);
634 634
 }
635 635
 
636 636
 /**
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
  *  succès ou échec
646 646
  */
647 647
 function auth_autoriser_modifier_pass($auth_methode, $serveur = '') {
648
-	$args = func_get_args();
649
-	return auth_administrer('autoriser_modifier_pass', $args);
648
+    $args = func_get_args();
649
+    return auth_administrer('autoriser_modifier_pass', $args);
650 650
 }
651 651
 
652 652
 /**
@@ -662,8 +662,8 @@  discard block
 block discarded – undo
662 662
  *  message d'erreur ou chaine vide si pas d'erreur
663 663
  */
664 664
 function auth_verifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') {
665
-	$args = func_get_args();
666
-	return auth_administrer('verifier_pass', $args, '');
665
+    $args = func_get_args();
666
+    return auth_administrer('verifier_pass', $args, '');
667 667
 }
668 668
 
669 669
 /**
@@ -679,8 +679,8 @@  discard block
 block discarded – undo
679 679
  *  succes ou echec
680 680
  */
681 681
 function auth_modifier_pass($auth_methode, $login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') {
682
-	$args = func_get_args();
683
-	return auth_administrer('modifier_pass', $args);
682
+    $args = func_get_args();
683
+    return auth_administrer('modifier_pass', $args);
684 684
 }
685 685
 
686 686
 /**
@@ -696,24 +696,24 @@  discard block
 block discarded – undo
696 696
  * @return void
697 697
  */
698 698
 function auth_synchroniser_distant(
699
-	$auth_methode = true,
700
-	$id_auteur = 0,
701
-	$champs = [],
702
-	$options = [],
703
-	$serveur = ''
699
+    $auth_methode = true,
700
+    $id_auteur = 0,
701
+    $champs = [],
702
+    $options = [],
703
+    $serveur = ''
704 704
 ) {
705
-	$args = func_get_args();
706
-	if ($auth_methode === true || isset($options['all']) && $options['all'] == true) {
707
-		$options['all'] = true; // ajouter une option all=>true pour chaque auth
708
-		$args = [true, $id_auteur, $champs, $options, $serveur];
709
-		foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
710
-			array_shift($args);
711
-			array_unshift($args, $methode);
712
-			auth_administrer('synchroniser_distant', $args);
713
-		}
714
-	} else {
715
-		auth_administrer('synchroniser_distant', $args);
716
-	}
705
+    $args = func_get_args();
706
+    if ($auth_methode === true || isset($options['all']) && $options['all'] == true) {
707
+        $options['all'] = true; // ajouter une option all=>true pour chaque auth
708
+        $args = [true, $id_auteur, $champs, $options, $serveur];
709
+        foreach ($GLOBALS['liste_des_authentifications'] as $methode) {
710
+            array_shift($args);
711
+            array_unshift($args, $methode);
712
+            auth_administrer('synchroniser_distant', $args);
713
+        }
714
+    } else {
715
+        auth_administrer('synchroniser_distant', $args);
716
+    }
717 717
 }
718 718
 
719 719
 
@@ -726,46 +726,46 @@  discard block
 block discarded – undo
726 726
  * @return array|bool
727 727
  */
728 728
 function lire_php_auth($login, #[\SensitiveParameter] $pw, $serveur = '') {
729
-	if (
730
-		!$login
731
-		|| !$login_base = auth_retrouver_login($login, $serveur)
732
-	) {
733
-		return false;
734
-	}
735
-
736
-	$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
737
-
738
-	if (!$row) {
739
-		if (
740
-			include_spip('inc/auth')
741
-			&& auth_ldap_connect($serveur)
742
-			&& ($auth_ldap = charger_fonction('ldap', 'auth', true))
743
-		) {
744
-			return $auth_ldap($login_base, $pw, $serveur, true);
745
-		}
746
-
747
-		return false;
748
-	}
749
-
750
-	// si pas de source definie
751
-	// ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER
752
-	if (
753
-		!($auth_methode = $row['source'])
754
-		|| !($auth = charger_fonction($auth_methode, 'auth', true))
755
-	) {
756
-		$auth = charger_fonction('spip', 'auth', true);
757
-	}
758
-
759
-	$auteur = '';
760
-	if ($auth) {
761
-		$auteur = $auth($login, $pw, $serveur, true);
762
-	}
763
-	// verifier que ce n'est pas un message d'erreur
764
-	if (is_array($auteur) && count($auteur)) {
765
-		return $auteur;
766
-	}
767
-
768
-	return false;
729
+    if (
730
+        !$login
731
+        || !$login_base = auth_retrouver_login($login, $serveur)
732
+    ) {
733
+        return false;
734
+    }
735
+
736
+    $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
737
+
738
+    if (!$row) {
739
+        if (
740
+            include_spip('inc/auth')
741
+            && auth_ldap_connect($serveur)
742
+            && ($auth_ldap = charger_fonction('ldap', 'auth', true))
743
+        ) {
744
+            return $auth_ldap($login_base, $pw, $serveur, true);
745
+        }
746
+
747
+        return false;
748
+    }
749
+
750
+    // si pas de source definie
751
+    // ou auth/xxx introuvable, utiliser 'spip' ou autre et avec le login passé par PHP_AUTH_USER
752
+    if (
753
+        !($auth_methode = $row['source'])
754
+        || !($auth = charger_fonction($auth_methode, 'auth', true))
755
+    ) {
756
+        $auth = charger_fonction('spip', 'auth', true);
757
+    }
758
+
759
+    $auteur = '';
760
+    if ($auth) {
761
+        $auteur = $auth($login, $pw, $serveur, true);
762
+    }
763
+    // verifier que ce n'est pas un message d'erreur
764
+    if (is_array($auteur) && count($auteur)) {
765
+        return $auteur;
766
+    }
767
+
768
+    return false;
769 769
 }
770 770
 
771 771
 /**
@@ -781,21 +781,21 @@  discard block
 block discarded – undo
781 781
  * @param string $lien
782 782
  */
783 783
 function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') {
784
-	@Header('WWW-Authenticate: Basic realm="espace prive"');
785
-	@Header('HTTP/1.0 401 Unauthorized');
786
-	$corps = '';
787
-	$public = generer_url_public();
788
-	$ecrire = generer_url_ecrire();
789
-	$retour = $retour ?: _T('icone_retour');
790
-	$corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
791
-	if ($url) {
792
-		$corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
793
-	}
794
-
795
-	if ($lien) {
796
-		$corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
797
-	}
798
-	include_spip('inc/minipres');
799
-	echo minipres($pb, $corps);
800
-	exit;
784
+    @Header('WWW-Authenticate: Basic realm="espace prive"');
785
+    @Header('HTTP/1.0 401 Unauthorized');
786
+    $corps = '';
787
+    $public = generer_url_public();
788
+    $ecrire = generer_url_ecrire();
789
+    $retour = $retour ?: _T('icone_retour');
790
+    $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
791
+    if ($url) {
792
+        $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
793
+    }
794
+
795
+    if ($lien) {
796
+        $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
797
+    }
798
+    include_spip('inc/minipres');
799
+    echo minipres($pb, $corps);
800
+    exit;
801 801
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -15 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	}
59 59
 
60 60
 	$n = (int) sql_errno();
61
-	spip_log("Erreur base de donnees $n " . sql_error());
61
+	spip_log("Erreur base de donnees $n ".sql_error());
62 62
 
63 63
 	return $n ?: 1;
64 64
 }
@@ -101,19 +101,19 @@  discard block
 block discarded – undo
101 101
 		// erreur SQL a afficher
102 102
 		$raison = minipres(
103 103
 			_T('info_travaux_titre'),
104
-			_T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>'
104
+			_T('titre_probleme_technique').'<p><tt>'.sql_errno().' '.sql_error().'</tt></p>'
105 105
 		);
106 106
 	} elseif (@$raison['statut']) {
107 107
 		// un simple visiteur n'a pas acces a l'espace prive
108
-		spip_log('connexion refusee a ' . @$raison['id_auteur']);
108
+		spip_log('connexion refusee a '.@$raison['id_auteur']);
109 109
 		$est_connecte = (!empty($GLOBALS['visiteur_session']['login']) && !empty($GLOBALS['visiteur_session']['statut'])); // idem test balise #URL_LOGOUT
110 110
 		$raison = minipres(
111 111
 			_T('avis_erreur_connexion'),
112 112
 			_T('avis_erreur_visiteur')
113 113
 				// Lien vers le site public
114
-				. '<br /><a href="' . url_de_base() . '">' . _T('login_retour_public') . '</a>'
114
+				. '<br /><a href="'.url_de_base().'">'._T('login_retour_public').'</a>'
115 115
 				// Si la personne est connectée, lien de déconnexion ramenant vers la page de login
116
-				. ($est_connecte ? ' | <a href="' . generer_url_public('', 'action=logout&amp;logout=prive') . '">' . _T('icone_deconnecter') . '</a>' : '')
116
+				. ($est_connecte ? ' | <a href="'.generer_url_public('', 'action=logout&amp;logout=prive').'">'._T('icone_deconnecter').'</a>' : '')
117 117
 		);
118 118
 	} else {
119 119
 		// auteur en fin de droits ...
@@ -201,8 +201,7 @@  discard block
 block discarded – undo
201 201
 	$where = (is_numeric($id_auteur)
202 202
 		/*AND $id_auteur>0*/ // reprise lors des restaurations
203 203
 	) ?
204
-		"id_auteur=$id_auteur" :
205
-		(strlen((string) $GLOBALS['connect_login']) ? 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text') : '');
204
+		"id_auteur=$id_auteur" : (strlen((string) $GLOBALS['connect_login']) ? 'login='.sql_quote($GLOBALS['connect_login'], '', 'text') : '');
206 205
 
207 206
 	if (!$where) {
208 207
 		return '';
@@ -244,7 +243,7 @@  discard block
 block discarded – undo
244 243
 	$GLOBALS['connect_login'] = $row['login'];
245 244
 	$GLOBALS['connect_statut'] = $row['statut'];
246 245
 
247
-	$GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row);
246
+	$GLOBALS['visiteur_session'] = array_merge((array) $GLOBALS['visiteur_session'], $row);
248 247
 
249 248
 	// au cas ou : ne pas memoriser les champs sensibles
250 249
 	unset($GLOBALS['visiteur_session']['pass']);
@@ -316,7 +315,7 @@  discard block
 block discarded – undo
316 315
  * @return string
317 316
  */
318 317
 function auth_a_loger() {
319
-	$redirect = generer_url_public('login', 'url=' . rawurlencode((string) self('&', true)), true);
318
+	$redirect = generer_url_public('login', 'url='.rawurlencode((string) self('&', true)), true);
320 319
 
321 320
 	// un echec au "bonjour" (login initial) quand le statut est
322 321
 	// inconnu signale sans doute un probleme de cookies
@@ -352,7 +351,7 @@  discard block
 block discarded – undo
352 351
 	$date ??= date('Y-m-d H:i:s');
353 352
 
354 353
 	if (abs(strtotime($date) - $connect_quand) >= 60) {
355
-		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . (int) $row['id_auteur']);
354
+		sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur='.(int) $row['id_auteur']);
356 355
 		$row['en_ligne'] = $date;
357 356
 	}
358 357
 
@@ -460,7 +459,7 @@  discard block
 block discarded – undo
460 459
 	if (
461 460
 		!$login
462 461
 		|| !($login_base = auth_retrouver_login($login, $serveur))
463
-		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
462
+		|| !($row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur))
464 463
 	) {
465 464
 		// generer de fausses infos, mais credibles, pour eviter une attaque
466 465
 		// https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691
@@ -569,7 +568,7 @@  discard block
 block discarded – undo
569 568
 	sql_updateq(
570 569
 		'spip_auteurs',
571 570
 		['prefs' => serialize($p)],
572
-		'id_auteur=' . (int) $auteur['id_auteur']
571
+		'id_auteur='.(int) $auteur['id_auteur']
573 572
 	);
574 573
 
575 574
 	//  bloquer ici le visiteur qui tente d'abuser de ses droits
@@ -733,7 +732,7 @@  discard block
 block discarded – undo
733 732
 		return false;
734 733
 	}
735 734
 
736
-	$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
735
+	$row = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur);
737 736
 
738 737
 	if (!$row) {
739 738
 		if (
@@ -789,11 +788,11 @@  discard block
 block discarded – undo
789 788
 	$retour = $retour ?: _T('icone_retour');
790 789
 	$corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] ";
791 790
 	if ($url) {
792
-		$corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]";
791
+		$corps .= "[<a href='".generer_url_action('cookie', "essai_auth_http=oui&$url")."'>$re</a>]";
793 792
 	}
794 793
 
795 794
 	if ($lien) {
796
-		$corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]';
795
+		$corps .= " [<a href='$ecrire'>"._T('login_espace_prive').'</a>]';
797 796
 	}
798 797
 	include_spip('inc/minipres');
799 798
 	echo minipres($pb, $corps);
Please login to merge, or discard this patch.
ecrire/inc/journal.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
  * @param array $opt
24 24
  */
25 25
 function inc_journal_dist($phrase, $opt = []) {
26
-	if (!strlen((string) $phrase)) {
27
-		return;
28
-	}
29
-	if ($opt) {
30
-		$phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
31
-	}
32
-	spip_log($phrase, 'journal');
26
+    if (!strlen((string) $phrase)) {
27
+        return;
28
+    }
29
+    if ($opt) {
30
+        $phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
31
+    }
32
+    spip_log($phrase, 'journal');
33 33
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 		return;
28 28
 	}
29 29
 	if ($opt) {
30
-		$phrase .= ' :: ' . str_replace("\n", ' ', implode(', ', $opt));
30
+		$phrase .= ' :: '.str_replace("\n", ' ', implode(', ', $opt));
31 31
 	}
32 32
 	spip_log($phrase, 'journal');
33 33
 }
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Mail
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/charsets');
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @return string
32 32
  */
33 33
 function nettoyer_titre_email($titre) {
34
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
34
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35 35
 }
36 36
 
37 37
 /**
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function nettoyer_caracteres_mail($t) {
49 49
 
50
-	$t = filtrer_entites($t);
51
-
52
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
-		$t = str_replace(
54
-			['&#8217;', '&#8220;', '&#8221;'],
55
-			["'", '"', '"'],
56
-			$t
57
-		);
58
-	}
59
-
60
-	return str_replace(
61
-		['&mdash;', '&endash;'],
62
-		['--', '-'],
63
-		$t
64
-	);
50
+    $t = filtrer_entites($t);
51
+
52
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
+        $t = str_replace(
54
+            ['&#8217;', '&#8220;', '&#8221;'],
55
+            ["'", '"', '"'],
56
+            $t
57
+        );
58
+    }
59
+
60
+    return str_replace(
61
+        ['&mdash;', '&endash;'],
62
+        ['--', '-'],
63
+        $t
64
+    );
65 65
 }
66 66
 
67 67
 /**
@@ -94,87 +94,87 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
96 96
 
97
-	if (!email_valide($destinataire)) {
98
-		return false;
99
-	}
100
-	if ($destinataire == _T('info_mail_fournisseur')) {
101
-		return false;
102
-	} // tres fort
103
-
104
-	// Fournir si possible un Message-Id: conforme au RFC1036,
105
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
-
107
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
108
-	if (!email_valide($email_envoi)) {
109
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
-		$email_envoi = $destinataire;
111
-	}
112
-
113
-	$parts = '';
114
-	if (is_array($corps)) {
115
-		$texte = $corps['texte'];
116
-		$from = ($corps['from'] ?? $from);
117
-		$headers = ($corps['headers'] ?? $headers);
118
-		if (is_array($headers)) {
119
-			$headers = implode("\n", $headers);
120
-		}
121
-		if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
-		}
124
-	} else {
125
-		$texte = $corps;
126
-	}
127
-
128
-	if (!$from) {
129
-		$from = $email_envoi;
130
-	}
131
-
132
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
-	}
136
-
137
-	// nettoyer les &eacute; &#8217, &emdash; etc...
138
-	// les 'cliquer ici' etc sont a eviter;  voir:
139
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
-	$texte = nettoyer_caracteres_mail($texte);
141
-	$sujet = nettoyer_caracteres_mail($sujet);
142
-
143
-	// encoder le sujet si possible selon la RFC
144
-	if (init_mb_string()) {
145
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
-		$charset = $GLOBALS['meta']['charset'];
148
-		mb_internal_encoding($charset);
149
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
-		mb_internal_encoding('utf-8');
151
-	}
152
-
153
-	$headers ??= '';
154
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
-		$texte = wordwrap($texte);
156
-	}
157
-
158
-	[$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
-
160
-	if (_OS_SERVEUR == 'windows') {
161
-		$texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
-		$headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
-	}
165
-
166
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
167
-	// mode TEST : forcer l'email
168
-	if (defined('_TEST_EMAIL_DEST')) {
169
-		if (!_TEST_EMAIL_DEST) {
170
-			return false;
171
-		} else {
172
-			$texte = "Dest : $destinataire\r\n" . $texte;
173
-			$destinataire = _TEST_EMAIL_DEST;
174
-		}
175
-	}
176
-
177
-	return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
97
+    if (!email_valide($destinataire)) {
98
+        return false;
99
+    }
100
+    if ($destinataire == _T('info_mail_fournisseur')) {
101
+        return false;
102
+    } // tres fort
103
+
104
+    // Fournir si possible un Message-Id: conforme au RFC1036,
105
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
+
107
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
108
+    if (!email_valide($email_envoi)) {
109
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
+        $email_envoi = $destinataire;
111
+    }
112
+
113
+    $parts = '';
114
+    if (is_array($corps)) {
115
+        $texte = $corps['texte'];
116
+        $from = ($corps['from'] ?? $from);
117
+        $headers = ($corps['headers'] ?? $headers);
118
+        if (is_array($headers)) {
119
+            $headers = implode("\n", $headers);
120
+        }
121
+        if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
+        }
124
+    } else {
125
+        $texte = $corps;
126
+    }
127
+
128
+    if (!$from) {
129
+        $from = $email_envoi;
130
+    }
131
+
132
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
+    }
136
+
137
+    // nettoyer les &eacute; &#8217, &emdash; etc...
138
+    // les 'cliquer ici' etc sont a eviter;  voir:
139
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
+    $texte = nettoyer_caracteres_mail($texte);
141
+    $sujet = nettoyer_caracteres_mail($sujet);
142
+
143
+    // encoder le sujet si possible selon la RFC
144
+    if (init_mb_string()) {
145
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
+        $charset = $GLOBALS['meta']['charset'];
148
+        mb_internal_encoding($charset);
149
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
+        mb_internal_encoding('utf-8');
151
+    }
152
+
153
+    $headers ??= '';
154
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
+        $texte = wordwrap($texte);
156
+    }
157
+
158
+    [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
+
160
+    if (_OS_SERVEUR == 'windows') {
161
+        $texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
+        $headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
+    }
165
+
166
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
167
+    // mode TEST : forcer l'email
168
+    if (defined('_TEST_EMAIL_DEST')) {
169
+        if (!_TEST_EMAIL_DEST) {
170
+            return false;
171
+        } else {
172
+            $texte = "Dest : $destinataire\r\n" . $texte;
173
+            $destinataire = _TEST_EMAIL_DEST;
174
+        }
175
+    }
176
+
177
+    return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
178 178
 }
179 179
 
180 180
 /**
@@ -188,53 +188,53 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
191
-	$charset = $GLOBALS['meta']['charset'];
192
-
193
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
194
-	if (!str_contains($headers, 'Content-Type: ')) {
195
-		$type =
196
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
197
-			"Content-Transfer-Encoding: 8bit\n";
198
-	} else {
199
-		$type = '';
200
-	}
201
-
202
-	// calculer un identifiant unique
203
-	// Marie Toto <[email protected]> => @toto.com
204
-	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
-
207
-	// Si multi-part, s'en servir comme borne ...
208
-	if ($parts) {
209
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
210
-		foreach ($parts as $part) {
211
-			$n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
-			$e = implode("\n", $part[0]);
213
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
-		}
215
-		$texte .= "\n\n--$uniq--\n";
216
-		// Si boundary n'est pas entre guillemets,
217
-		// elle est comprise mais le charset est ignoree !
218
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
-	}
220
-
221
-	// .. et s'en servir pour plaire a SpamAssassin
222
-
223
-	$mid = 'Message-Id: <' . $uniq . '>';
224
-
225
-	// indispensable pour les sites qui collent d'office From: serveur-http
226
-	// sauf si deja mis par l'envoyeur
227
-	$rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
-
229
-	// Nettoyer les en-tetes envoyees
230
-	// Ajouter le \n final
231
-	if (strlen($headers = trim($headers))) {
232
-		$headers .= "\n";
233
-	}
234
-
235
-	// Et mentionner l'indeboulonable nomenclature ratee
236
-
237
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
-
239
-	return [$headers, $texte];
191
+    $charset = $GLOBALS['meta']['charset'];
192
+
193
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
194
+    if (!str_contains($headers, 'Content-Type: ')) {
195
+        $type =
196
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
197
+            "Content-Transfer-Encoding: 8bit\n";
198
+    } else {
199
+        $type = '';
200
+    }
201
+
202
+    // calculer un identifiant unique
203
+    // Marie Toto <[email protected]> => @toto.com
204
+    $domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
+    $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
+
207
+    // Si multi-part, s'en servir comme borne ...
208
+    if ($parts) {
209
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
210
+        foreach ($parts as $part) {
211
+            $n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
+            $e = implode("\n", $part[0]);
213
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
+        }
215
+        $texte .= "\n\n--$uniq--\n";
216
+        // Si boundary n'est pas entre guillemets,
217
+        // elle est comprise mais le charset est ignoree !
218
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
+    }
220
+
221
+    // .. et s'en servir pour plaire a SpamAssassin
222
+
223
+    $mid = 'Message-Id: <' . $uniq . '>';
224
+
225
+    // indispensable pour les sites qui collent d'office From: serveur-http
226
+    // sauf si deja mis par l'envoyeur
227
+    $rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
+
229
+    // Nettoyer les en-tetes envoyees
230
+    // Ajouter le \n final
231
+    if (strlen($headers = trim($headers))) {
232
+        $headers .= "\n";
233
+    }
234
+
235
+    // Et mentionner l'indeboulonable nomenclature ratee
236
+
237
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
+
239
+    return [$headers, $texte];
240 240
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133 133
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
134
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))).')';
135 135
 	}
136 136
 
137 137
 	// nettoyer les &eacute; &#8217, &emdash; etc...
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		if (!_TEST_EMAIL_DEST) {
170 170
 			return false;
171 171
 		} else {
172
-			$texte = "Dest : $destinataire\r\n" . $texte;
172
+			$texte = "Dest : $destinataire\r\n".$texte;
173 173
 			$destinataire = _TEST_EMAIL_DEST;
174 174
 		}
175 175
 	}
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
194 194
 	if (!str_contains($headers, 'Content-Type: ')) {
195 195
 		$type =
196
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
196
+			"Content-Type: text/plain;charset=\"$charset\";\n".
197 197
 			"Content-Transfer-Encoding: 8bit\n";
198 198
 	} else {
199 199
 		$type = '';
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
 
202 202
 	// calculer un identifiant unique
203 203
 	// Marie Toto <[email protected]> => @toto.com
204
-	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
204
+	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-'.md5($from).'.org';
205
+	$uniq = random_int(0, mt_getrandmax()).'_'.md5($to.$texte).$domain;
206 206
 
207 207
 	// Si multi-part, s'en servir comme borne ...
208 208
 	if ($parts) {
209
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
209
+		$texte = "--$uniq\n$type\n".$texte."\n";
210 210
 		foreach ($parts as $part) {
211
-			$n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
211
+			$n = strlen((string) $part[1]).($part[0] ? "\n" : '');
212 212
 			$e = implode("\n", $part[0]);
213
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
213
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
214 214
 		}
215 215
 		$texte .= "\n\n--$uniq--\n";
216 216
 		// Si boundary n'est pas entre guillemets,
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 
221 221
 	// .. et s'en servir pour plaire a SpamAssassin
222 222
 
223
-	$mid = 'Message-Id: <' . $uniq . '>';
223
+	$mid = 'Message-Id: <'.$uniq.'>';
224 224
 
225 225
 	// indispensable pour les sites qui collent d'office From: serveur-http
226 226
 	// sauf si deja mis par l'envoyeur
Please login to merge, or discard this patch.
ecrire/inc/lien_court.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 /*
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
  * http://zoumzamzouilam/truc/chose/machin..."
22 22
  */
23 23
 function inc_lien_court($url) {
24
-	$long_url = defined('_MAX_LONG_URL') ? _MAX_LONG_URL : 40;
25
-	$coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
24
+    $long_url = defined('_MAX_LONG_URL') ? _MAX_LONG_URL : 40;
25
+    $coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
26 26
 
27
-	if (strlen((string) $url) > $long_url) {
28
-		$url = substr((string) $url, 0, $coupe_url) . '...';
29
-	}
27
+    if (strlen((string) $url) > $long_url) {
28
+        $url = substr((string) $url, 0, $coupe_url) . '...';
29
+    }
30 30
 
31
-	return $url;
31
+    return $url;
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 	$coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
26 26
 
27 27
 	if (strlen((string) $url) > $long_url) {
28
-		$url = substr((string) $url, 0, $coupe_url) . '...';
28
+		$url = substr((string) $url, 0, $coupe_url).'...';
29 29
 	}
30 30
 
31 31
 	return $url;
Please login to merge, or discard this patch.