@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 35 | 35 | */ |
| 36 | 36 | function decompose_champ_id_objet($champ) { |
| 37 | - if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | - } |
|
| 37 | + if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $champ; |
|
| 41 | + return $champ; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 58 | 58 | */ |
| 59 | 59 | function trouver_champs_decomposes($champ, $desc): array { |
| 60 | - if ( |
|
| 61 | - !is_array($desc) |
|
| 62 | - || array_key_exists($champ, $desc['field']) |
|
| 63 | - ) { |
|
| 64 | - return [$champ]; |
|
| 65 | - } |
|
| 66 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | - array_pop($decompose); |
|
| 69 | - if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | - return $decompose; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$champ]; |
|
| 60 | + if ( |
|
| 61 | + !is_array($desc) |
|
| 62 | + || array_key_exists($champ, $desc['field']) |
|
| 63 | + ) { |
|
| 64 | + return [$champ]; |
|
| 65 | + } |
|
| 66 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | + array_pop($decompose); |
|
| 69 | + if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | + return $decompose; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$champ]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | * Alias de la table de jointure (Lx) |
| 102 | 102 | */ |
| 103 | 103 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 104 | - // les jointures minimales sont optimales : |
|
| 105 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | - $max = 1; |
|
| 108 | - $res = false; |
|
| 109 | - $milieu_exclus = ($col ?: []); |
|
| 110 | - while ($max <= $max_liens && !$res) { |
|
| 111 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | - $max++; |
|
| 113 | - } |
|
| 114 | - if (!$res) { |
|
| 115 | - return ''; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - [$nom, $desc] = $depart; |
|
| 119 | - |
|
| 120 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 104 | + // les jointures minimales sont optimales : |
|
| 105 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | + $max = 1; |
|
| 108 | + $res = false; |
|
| 109 | + $milieu_exclus = ($col ?: []); |
|
| 110 | + while ($max <= $max_liens && !$res) { |
|
| 111 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | + $max++; |
|
| 113 | + } |
|
| 114 | + if (!$res) { |
|
| 115 | + return ''; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + [$nom, $desc] = $depart; |
|
| 119 | + |
|
| 120 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -156,78 +156,78 @@ discard block |
||
| 156 | 156 | * Alias de la table de jointure (Lx) |
| 157 | 157 | */ |
| 158 | 158 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 159 | - $a = []; |
|
| 160 | - $j = null; |
|
| 161 | - $n = null; |
|
| 162 | - static $num = []; |
|
| 163 | - $id_table = ''; |
|
| 164 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | - foreach ($res as $cle => $r) { |
|
| 166 | - [$d, $a, $j] = $r; |
|
| 167 | - if (!$id_table) { |
|
| 168 | - $id_table = $d; |
|
| 169 | - } |
|
| 170 | - $n = ++$cpt; |
|
| 171 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | - [$j1, $j2, $obj, $type] = $j; |
|
| 173 | - // trouver de quel cote est (id_objet,objet) |
|
| 174 | - $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | - $boucle->where["JOIN-L$n"] = |
|
| 179 | - $echap ? |
|
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | - : |
|
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 183 | - $boucle->join["L$n"] = |
|
| 184 | - $echap ? |
|
| 185 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | - : |
|
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | - } else { |
|
| 189 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | - } |
|
| 191 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - // pas besoin de group by |
|
| 196 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | - // si une seule jointure et sur une table avec primary key formee |
|
| 198 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | - |
|
| 201 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // pas de group by |
|
| 206 | - // si une seule jointure |
|
| 207 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | - if ( |
|
| 209 | - !$pk |
|
| 210 | - && count($boucle->from) == 2 |
|
| 211 | - && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | - && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | - ) { |
|
| 214 | - $pk = true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | - if (!$pk) { |
|
| 220 | - foreach ($groups as $id_prim) { |
|
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 222 | - if (!in_array($id_field, $boucle->group)) { |
|
| 223 | - $boucle->group[] = $id_field; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $boucle->modificateur['lien'] = true; |
|
| 229 | - |
|
| 230 | - return "L$n"; |
|
| 159 | + $a = []; |
|
| 160 | + $j = null; |
|
| 161 | + $n = null; |
|
| 162 | + static $num = []; |
|
| 163 | + $id_table = ''; |
|
| 164 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | + foreach ($res as $cle => $r) { |
|
| 166 | + [$d, $a, $j] = $r; |
|
| 167 | + if (!$id_table) { |
|
| 168 | + $id_table = $d; |
|
| 169 | + } |
|
| 170 | + $n = ++$cpt; |
|
| 171 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | + [$j1, $j2, $obj, $type] = $j; |
|
| 173 | + // trouver de quel cote est (id_objet,objet) |
|
| 174 | + $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | + $boucle->where["JOIN-L$n"] = |
|
| 179 | + $echap ? |
|
| 180 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | + : |
|
| 182 | + ['=',"$obj",sql_quote($type)]; |
|
| 183 | + $boucle->join["L$n"] = |
|
| 184 | + $echap ? |
|
| 185 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | + : |
|
| 187 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | + } else { |
|
| 189 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | + } |
|
| 191 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + // pas besoin de group by |
|
| 196 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | + // si une seule jointure et sur une table avec primary key formee |
|
| 198 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | + |
|
| 201 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // pas de group by |
|
| 206 | + // si une seule jointure |
|
| 207 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | + if ( |
|
| 209 | + !$pk |
|
| 210 | + && count($boucle->from) == 2 |
|
| 211 | + && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | + && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | + ) { |
|
| 214 | + $pk = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | + if (!$pk) { |
|
| 220 | + foreach ($groups as $id_prim) { |
|
| 221 | + $id_field = $nom . '.' . $id_prim; |
|
| 222 | + if (!in_array($id_field, $boucle->group)) { |
|
| 223 | + $boucle->group[] = $id_field; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $boucle->modificateur['lien'] = true; |
|
| 229 | + |
|
| 230 | + return "L$n"; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,18 +242,18 @@ discard block |
||
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | 244 | function nogroupby_if($depart, $arrivee, $col) { |
| 245 | - if ( |
|
| 246 | - empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | - || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | - || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | - ) { |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | - if (is_array($col)) { |
|
| 254 | - $col = implode(', *', $col); |
|
| 255 | - } // cas id_objet, objet |
|
| 256 | - return (preg_match("/^$id_primary, *$col$/", (string) $pk) || preg_match("/^$col, *$id_primary$/", (string) $pk)); |
|
| 245 | + if ( |
|
| 246 | + empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | + || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | + || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | + ) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | + if (is_array($col)) { |
|
| 254 | + $col = implode(', *', $col); |
|
| 255 | + } // cas id_objet, objet |
|
| 256 | + return (preg_match("/^$id_primary, *$col$/", (string) $pk) || preg_match("/^$col, *$id_primary$/", (string) $pk)); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -271,46 +271,46 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 273 | 273 | |
| 274 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 274 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 275 | 275 | |
| 276 | - // si cle primaire demandee, la privilegier |
|
| 277 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | - } |
|
| 276 | + // si cle primaire demandee, la privilegier |
|
| 277 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // les champs declares explicitement pour les jointures |
|
| 282 | - if (isset($desc['join'])) { |
|
| 283 | - return $desc['join']; |
|
| 284 | - } |
|
| 285 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 281 | + // les champs declares explicitement pour les jointures |
|
| 282 | + if (isset($desc['join'])) { |
|
| 283 | + return $desc['join']; |
|
| 284 | + } |
|
| 285 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 286 | 286 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 287 | 287 | |
| 288 | - // si pas de cle, c'est fichu |
|
| 289 | - if (!isset($desc['key'])) { |
|
| 290 | - return []; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // si cle primaire |
|
| 294 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // ici on se rabat sur les cles secondaires, |
|
| 299 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | - |
|
| 303 | - $join = []; |
|
| 304 | - foreach ($desc['key'] as $v) { |
|
| 305 | - $join = split_key($v, $join); |
|
| 306 | - } |
|
| 307 | - foreach ($join as $k) { |
|
| 308 | - if (in_array($k, $nojoin)) { |
|
| 309 | - unset($join[$k]); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $join; |
|
| 288 | + // si pas de cle, c'est fichu |
|
| 289 | + if (!isset($desc['key'])) { |
|
| 290 | + return []; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // si cle primaire |
|
| 294 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // ici on se rabat sur les cles secondaires, |
|
| 299 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | + |
|
| 303 | + $join = []; |
|
| 304 | + foreach ($desc['key'] as $v) { |
|
| 305 | + $join = split_key($v, $join); |
|
| 306 | + } |
|
| 307 | + foreach ($join as $k) { |
|
| 308 | + if (in_array($k, $nojoin)) { |
|
| 309 | + unset($join[$k]); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $join; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | * @return array |
| 322 | 322 | */ |
| 323 | 323 | function split_key($v, $join = []) { |
| 324 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | - if (str_contains((string) $k, '(')) { |
|
| 326 | - $k = explode('(', (string) $k); |
|
| 327 | - $k = trim(reset($k)); |
|
| 328 | - } |
|
| 329 | - $join[$k] = $k; |
|
| 330 | - } |
|
| 331 | - return $join; |
|
| 324 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | + if (str_contains((string) $k, '(')) { |
|
| 326 | + $k = explode('(', (string) $k); |
|
| 327 | + $k = trim(reset($k)); |
|
| 328 | + } |
|
| 329 | + $join[$k] = $k; |
|
| 330 | + } |
|
| 331 | + return $join; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -351,134 +351,134 @@ discard block |
||
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | 353 | function calculer_chaine_jointures( |
| 354 | - &$boucle, |
|
| 355 | - $depart, |
|
| 356 | - $arrivee, |
|
| 357 | - $vu = [], |
|
| 358 | - $milieu_exclus = [], |
|
| 359 | - $max_liens = 5 |
|
| 354 | + &$boucle, |
|
| 355 | + $depart, |
|
| 356 | + $arrivee, |
|
| 357 | + $vu = [], |
|
| 358 | + $milieu_exclus = [], |
|
| 359 | + $max_liens = 5 |
|
| 360 | 360 | ) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_string($milieu_exclus)) { |
|
| 367 | - $milieu_exclus = [$milieu_exclus]; |
|
| 368 | - } |
|
| 369 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | - if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | - $milieu_exclus[] = 'objet'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - [$dnom, $ddesc] = $depart; |
|
| 376 | - [$anom, $adesc] = $arrivee; |
|
| 377 | - if ($vu === []) { |
|
| 378 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $akeys = []; |
|
| 383 | - foreach ($adesc['key'] as $k) { |
|
| 384 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | - $akeys = array_merge($akeys, preg_split('/,\s*/', (string) $k)); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | - |
|
| 391 | - // cles candidates au depart |
|
| 392 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | - // enlever les cles dde depart exclues par l'appel |
|
| 394 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | - |
|
| 396 | - $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | - |
|
| 398 | - if ($v) { |
|
| 399 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | - // id_objet,objet |
|
| 406 | - // si oui on la prend |
|
| 407 | - foreach ($akeys as $key) { |
|
| 408 | - $v = decompose_champ_id_objet($key); |
|
| 409 | - if (is_array($v)) { |
|
| 410 | - $objet = array_shift($v); // objet,'article' |
|
| 411 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } else { |
|
| 417 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | - // id_objet,objet a l'arrivee |
|
| 419 | - // si oui on la prend |
|
| 420 | - foreach ($keys as $key) { |
|
| 421 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | - $v = decompose_champ_id_objet($key); |
|
| 423 | - // id_objet,objet,'article' |
|
| 424 | - array_unshift($v, $key); |
|
| 425 | - // id_article,id_objet,objet,'article' |
|
| 426 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | - if ($max_liens <= 1) { |
|
| 432 | - return []; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // sinon essayer de passer par une autre table |
|
| 436 | - $new = $vu; |
|
| 437 | - foreach ($boucle->jointures as $v) { |
|
| 438 | - if ( |
|
| 439 | - $v |
|
| 440 | - && !in_array($v, $vu) |
|
| 441 | - && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | - && !in_array($def['table_sql'], $vu) |
|
| 443 | - ) { |
|
| 444 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | - // ie la cle de la jointure precedente |
|
| 446 | - $test_cles = $milieu_exclus; |
|
| 447 | - $new[] = $v; |
|
| 448 | - $max_iter = 50; // securite |
|
| 449 | - while ( |
|
| 450 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | - $boucle, |
|
| 452 | - $depart, |
|
| 453 | - [$v, $def], |
|
| 454 | - $vu, |
|
| 455 | - $test_cles, |
|
| 456 | - 1 |
|
| 457 | - )) && $max_iter-- |
|
| 458 | - ) { |
|
| 459 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | - $milieu = end($jointure_directe_possible); |
|
| 461 | - $exclure_fin = $milieu_exclus; |
|
| 462 | - if (is_string($milieu)) { |
|
| 463 | - $exclure_fin[] = $milieu; |
|
| 464 | - $test_cles[] = $milieu; |
|
| 465 | - } else { |
|
| 466 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | - } |
|
| 469 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | - if ($r) { |
|
| 473 | - array_unshift($r, $jointure_directe_possible); |
|
| 474 | - |
|
| 475 | - return $r; |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return []; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_string($milieu_exclus)) { |
|
| 367 | + $milieu_exclus = [$milieu_exclus]; |
|
| 368 | + } |
|
| 369 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | + if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | + $milieu_exclus[] = 'objet'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + [$dnom, $ddesc] = $depart; |
|
| 376 | + [$anom, $adesc] = $arrivee; |
|
| 377 | + if ($vu === []) { |
|
| 378 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $akeys = []; |
|
| 383 | + foreach ($adesc['key'] as $k) { |
|
| 384 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | + $akeys = array_merge($akeys, preg_split('/,\s*/', (string) $k)); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | + |
|
| 391 | + // cles candidates au depart |
|
| 392 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | + // enlever les cles dde depart exclues par l'appel |
|
| 394 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | + |
|
| 396 | + $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | + |
|
| 398 | + if ($v) { |
|
| 399 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | + // id_objet,objet |
|
| 406 | + // si oui on la prend |
|
| 407 | + foreach ($akeys as $key) { |
|
| 408 | + $v = decompose_champ_id_objet($key); |
|
| 409 | + if (is_array($v)) { |
|
| 410 | + $objet = array_shift($v); // objet,'article' |
|
| 411 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } else { |
|
| 417 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | + // id_objet,objet a l'arrivee |
|
| 419 | + // si oui on la prend |
|
| 420 | + foreach ($keys as $key) { |
|
| 421 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | + $v = decompose_champ_id_objet($key); |
|
| 423 | + // id_objet,objet,'article' |
|
| 424 | + array_unshift($v, $key); |
|
| 425 | + // id_article,id_objet,objet,'article' |
|
| 426 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | + if ($max_liens <= 1) { |
|
| 432 | + return []; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // sinon essayer de passer par une autre table |
|
| 436 | + $new = $vu; |
|
| 437 | + foreach ($boucle->jointures as $v) { |
|
| 438 | + if ( |
|
| 439 | + $v |
|
| 440 | + && !in_array($v, $vu) |
|
| 441 | + && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | + && !in_array($def['table_sql'], $vu) |
|
| 443 | + ) { |
|
| 444 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | + // ie la cle de la jointure precedente |
|
| 446 | + $test_cles = $milieu_exclus; |
|
| 447 | + $new[] = $v; |
|
| 448 | + $max_iter = 50; // securite |
|
| 449 | + while ( |
|
| 450 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | + $boucle, |
|
| 452 | + $depart, |
|
| 453 | + [$v, $def], |
|
| 454 | + $vu, |
|
| 455 | + $test_cles, |
|
| 456 | + 1 |
|
| 457 | + )) && $max_iter-- |
|
| 458 | + ) { |
|
| 459 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | + $milieu = end($jointure_directe_possible); |
|
| 461 | + $exclure_fin = $milieu_exclus; |
|
| 462 | + if (is_string($milieu)) { |
|
| 463 | + $exclure_fin[] = $milieu; |
|
| 464 | + $test_cles[] = $milieu; |
|
| 465 | + } else { |
|
| 466 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | + } |
|
| 469 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | + if ($r) { |
|
| 473 | + array_unshift($r, $jointure_directe_possible); |
|
| 474 | + |
|
| 475 | + return $r; |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return []; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -489,18 +489,18 @@ discard block |
||
| 489 | 489 | * @return array |
| 490 | 490 | */ |
| 491 | 491 | function trouver_cles_table($keys) { |
| 492 | - $res = []; |
|
| 493 | - foreach ($keys as $v) { |
|
| 494 | - if (!strpos((string) $v, ',')) { |
|
| 495 | - $res[$v] = 1; |
|
| 496 | - } else { |
|
| 497 | - foreach (preg_split('/\s*,\s*/', (string) $v) as $k) { |
|
| 498 | - $res[$k] = 1; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - return array_keys($res); |
|
| 492 | + $res = []; |
|
| 493 | + foreach ($keys as $v) { |
|
| 494 | + if (!strpos((string) $v, ',')) { |
|
| 495 | + $res[$v] = 1; |
|
| 496 | + } else { |
|
| 497 | + foreach (preg_split('/\s*,\s*/', (string) $v) as $k) { |
|
| 498 | + $res[$k] = 1; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + return array_keys($res); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -527,34 +527,34 @@ discard block |
||
| 527 | 527 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 528 | 528 | */ |
| 529 | 529 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 530 | - static $trouver_table = ''; |
|
| 531 | - if (!$trouver_table) { |
|
| 532 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - if (!is_array($cle)) { |
|
| 536 | - $cle = [$cle]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - foreach ($tables as $k => $table) { |
|
| 540 | - if ( |
|
| 541 | - $table |
|
| 542 | - && ($desc = $trouver_table($table, $connect)) |
|
| 543 | - && ( |
|
| 544 | - isset($desc['field']) |
|
| 545 | - && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | - && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - return [ |
|
| 550 | - 'desc' => $desc, |
|
| 551 | - 'table' => $desc['table'], |
|
| 552 | - 'alias' => $k, |
|
| 553 | - ]; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return false; |
|
| 530 | + static $trouver_table = ''; |
|
| 531 | + if (!$trouver_table) { |
|
| 532 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + if (!is_array($cle)) { |
|
| 536 | + $cle = [$cle]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + foreach ($tables as $k => $table) { |
|
| 540 | + if ( |
|
| 541 | + $table |
|
| 542 | + && ($desc = $trouver_table($table, $connect)) |
|
| 543 | + && ( |
|
| 544 | + isset($desc['field']) |
|
| 545 | + && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | + && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + return [ |
|
| 550 | + 'desc' => $desc, |
|
| 551 | + 'table' => $desc['table'], |
|
| 552 | + 'alias' => $k, |
|
| 553 | + ]; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return false; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -580,52 +580,52 @@ discard block |
||
| 580 | 580 | */ |
| 581 | 581 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 582 | 582 | |
| 583 | - // support de la recherche multi champ : |
|
| 584 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | - if (!is_array($cle)) { |
|
| 588 | - $cle = [$cle]; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // au premier coup, on essaye de decomposer, si possible |
|
| 596 | - if ( |
|
| 597 | - count($cle) == 1 |
|
| 598 | - && ($c = reset($cle)) |
|
| 599 | - && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | - ) { |
|
| 601 | - $desc = $boucle->show; |
|
| 602 | - |
|
| 603 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | - if (isset($desc['field'][$c])) { |
|
| 606 | - $cle = []; |
|
| 607 | - $cle[] = array_shift($decompose); // id_objet |
|
| 608 | - $cle[] = array_shift($decompose); // objet |
|
| 609 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | - } |
|
| 611 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | - else { |
|
| 615 | - $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | - foreach ($depart as $d) { |
|
| 617 | - $cle = []; |
|
| 618 | - $cle[] = array_shift($decompose); // id_objet |
|
| 619 | - $cle[] = array_shift($decompose); // objet |
|
| 620 | - $cle[] = $d; |
|
| 621 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | - return $ext; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - return ''; |
|
| 583 | + // support de la recherche multi champ : |
|
| 584 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | + if (!is_array($cle)) { |
|
| 588 | + $cle = [$cle]; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // au premier coup, on essaye de decomposer, si possible |
|
| 596 | + if ( |
|
| 597 | + count($cle) == 1 |
|
| 598 | + && ($c = reset($cle)) |
|
| 599 | + && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | + ) { |
|
| 601 | + $desc = $boucle->show; |
|
| 602 | + |
|
| 603 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | + if (isset($desc['field'][$c])) { |
|
| 606 | + $cle = []; |
|
| 607 | + $cle[] = array_shift($decompose); // id_objet |
|
| 608 | + $cle[] = array_shift($decompose); // objet |
|
| 609 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | + } |
|
| 611 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | + else { |
|
| 615 | + $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | + foreach ($depart as $d) { |
|
| 617 | + $cle = []; |
|
| 618 | + $cle[] = array_shift($decompose); // id_objet |
|
| 619 | + $cle[] = array_shift($decompose); // objet |
|
| 620 | + $cle[] = $d; |
|
| 621 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | + return $ext; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + return ''; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -657,21 +657,21 @@ discard block |
||
| 657 | 657 | * @return string |
| 658 | 658 | */ |
| 659 | 659 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 660 | - if ($jointures === false) { |
|
| 661 | - $jointures = $boucle->jointures; |
|
| 662 | - } |
|
| 663 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | - // mais pas poour construire la jointure ensuite |
|
| 665 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | - if ($arrivee) { |
|
| 667 | - $desc = $boucle->show; |
|
| 668 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | - if ($cle) { |
|
| 671 | - return $cle; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - spip_logger()->info("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | - |
|
| 676 | - return ''; |
|
| 660 | + if ($jointures === false) { |
|
| 661 | + $jointures = $boucle->jointures; |
|
| 662 | + } |
|
| 663 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | + // mais pas poour construire la jointure ensuite |
|
| 665 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | + if ($arrivee) { |
|
| 667 | + $desc = $boucle->show; |
|
| 668 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | + if ($cle) { |
|
| 671 | + return $cle; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + spip_logger()->info("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | + |
|
| 676 | + return ''; |
|
| 677 | 677 | } |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | require_once __DIR__ . '/bootstrap/config/initial.php'; |
| 26 | 26 | |
| 27 | 27 | // inclure l'ecran de securite si il n'a pas été inclus en prepend php |
| 28 | 28 | if ( |
| 29 | - !defined('_ECRAN_SECURITE') |
|
| 30 | - && @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 29 | + !defined('_ECRAN_SECURITE') |
|
| 30 | + && @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 31 | 31 | ) { |
| 32 | - include $f; |
|
| 32 | + include $f; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // et on peut lancer l'autoloader |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | // Definition personnelles eventuelles |
| 77 | 77 | |
| 78 | 78 | if (_FILE_OPTIONS) { |
| 79 | - include_once _FILE_OPTIONS; |
|
| 79 | + include_once _FILE_OPTIONS; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 83 | - /** Masquer les warning */ |
|
| 84 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 83 | + /** Masquer les warning */ |
|
| 84 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | ErrorHandler::setup(SPIP_ERREUR_REPORT); |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | // ===> on execute en neutralisant les messages d'erreur |
| 96 | 96 | |
| 97 | 97 | spip_initialisation_core( |
| 98 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 99 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 100 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 101 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 98 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 99 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 100 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 101 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | 104 | // chargement des plugins : doit arriver en dernier |
@@ -107,75 +107,75 @@ discard block |
||
| 107 | 107 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 108 | 108 | |
| 109 | 109 | if (@is_readable(_CACHE_PLUGINS_OPT) && @is_readable(_CACHE_PLUGINS_PATH)) { |
| 110 | - // chargement optimise precompile |
|
| 111 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 110 | + // chargement optimise precompile |
|
| 111 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 112 | 112 | } else { |
| 113 | - spip_initialisation_suite(); |
|
| 114 | - include_spip('inc/plugin'); |
|
| 115 | - // generer les fichiers php precompiles |
|
| 116 | - // de chargement des plugins et des pipelines |
|
| 117 | - actualise_plugins_actifs(); |
|
| 113 | + spip_initialisation_suite(); |
|
| 114 | + include_spip('inc/plugin'); |
|
| 115 | + // generer les fichiers php precompiles |
|
| 116 | + // de chargement des plugins et des pipelines |
|
| 117 | + actualise_plugins_actifs(); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Initialisations non critiques surchargeables par les plugins |
| 121 | 121 | spip_initialisation_suite(); |
| 122 | 122 | |
| 123 | 123 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 124 | - /** |
|
| 125 | - * Niveau maxi d'enregistrement des logs |
|
| 126 | - * @var LogLevel::* |
|
| 127 | - */ |
|
| 128 | - define('_LOG_FILTRE_GRAVITE', LogLevel::NOTICE); |
|
| 124 | + /** |
|
| 125 | + * Niveau maxi d'enregistrement des logs |
|
| 126 | + * @var LogLevel::* |
|
| 127 | + */ |
|
| 128 | + define('_LOG_FILTRE_GRAVITE', LogLevel::NOTICE); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 132 | - /** Activer des outils pour développeurs ? */ |
|
| 133 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 132 | + /** Activer des outils pour développeurs ? */ |
|
| 133 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 137 | 137 | if (test_espace_prive()) { |
| 138 | - include_spip('inc/autoriser'); |
|
| 138 | + include_spip('inc/autoriser'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // |
| 142 | 142 | // Installer Spip si pas installe... sauf si justement on est en train |
| 143 | 143 | // |
| 144 | 144 | if ( |
| 145 | - !(_FILE_CONNECT |
|
| 146 | - || autoriser_sans_cookie(_request('exec')) |
|
| 147 | - || _request('action') == 'cookie' |
|
| 148 | - || _request('action') == 'converser' |
|
| 149 | - || _request('action') == 'test_dirs') |
|
| 145 | + !(_FILE_CONNECT |
|
| 146 | + || autoriser_sans_cookie(_request('exec')) |
|
| 147 | + || _request('action') == 'cookie' |
|
| 148 | + || _request('action') == 'converser' |
|
| 149 | + || _request('action') == 'test_dirs') |
|
| 150 | 150 | ) { |
| 151 | - // Si on peut installer, on lance illico |
|
| 152 | - if (test_espace_prive()) { |
|
| 153 | - include_spip('inc/headers'); |
|
| 154 | - redirige_url_ecrire('install'); |
|
| 155 | - } else { |
|
| 156 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 157 | - include_spip('inc/lang'); |
|
| 158 | - utiliser_langue_visiteur(); |
|
| 159 | - include_spip('inc/minipres'); |
|
| 160 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 161 | - exit; |
|
| 162 | - } |
|
| 163 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 151 | + // Si on peut installer, on lance illico |
|
| 152 | + if (test_espace_prive()) { |
|
| 153 | + include_spip('inc/headers'); |
|
| 154 | + redirige_url_ecrire('install'); |
|
| 155 | + } else { |
|
| 156 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 157 | + include_spip('inc/lang'); |
|
| 158 | + utiliser_langue_visiteur(); |
|
| 159 | + include_spip('inc/minipres'); |
|
| 160 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 161 | + exit; |
|
| 162 | + } |
|
| 163 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // memoriser un tri sessionne eventuel |
| 167 | 167 | if ( |
| 168 | - isset($_REQUEST['var_memotri']) |
|
| 169 | - && ($t = $_REQUEST['var_memotri']) |
|
| 170 | - && (str_starts_with((string) $t, 'trisession') || str_starts_with((string) $t, 'senssession')) |
|
| 168 | + isset($_REQUEST['var_memotri']) |
|
| 169 | + && ($t = $_REQUEST['var_memotri']) |
|
| 170 | + && (str_starts_with((string) $t, 'trisession') || str_starts_with((string) $t, 'senssession')) |
|
| 171 | 171 | ) { |
| 172 | - if (!function_exists('session_set')) { |
|
| 173 | - include_spip('inc/session'); |
|
| 174 | - } |
|
| 175 | - $t = preg_replace(',\W,', '_', (string) $t); |
|
| 176 | - if ($v = _request($t)) { |
|
| 177 | - session_set($t, $v); |
|
| 178 | - } |
|
| 172 | + if (!function_exists('session_set')) { |
|
| 173 | + include_spip('inc/session'); |
|
| 174 | + } |
|
| 175 | + $t = preg_replace(',\W,', '_', (string) $t); |
|
| 176 | + if ($v = _request($t)) { |
|
| 177 | + session_set($t, $v); |
|
| 178 | + } |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -185,22 +185,22 @@ discard block |
||
| 185 | 185 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 186 | 186 | */ |
| 187 | 187 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 188 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 188 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 189 | 189 | } |
| 190 | 190 | if (!headers_sent() && _HEADER_COMPOSED_BY) { |
| 191 | - if (!defined('_HEADER_VARY')) { |
|
| 192 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 193 | - } |
|
| 194 | - if (_HEADER_VARY) { |
|
| 195 | - header(_HEADER_VARY); |
|
| 196 | - } |
|
| 197 | - if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 198 | - include_spip('inc/filtres_mini'); |
|
| 199 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 200 | - } else { |
|
| 201 | - // header minimal |
|
| 202 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 203 | - } |
|
| 191 | + if (!defined('_HEADER_VARY')) { |
|
| 192 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 193 | + } |
|
| 194 | + if (_HEADER_VARY) { |
|
| 195 | + header(_HEADER_VARY); |
|
| 196 | + } |
|
| 197 | + if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 198 | + include_spip('inc/filtres_mini'); |
|
| 199 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 200 | + } else { |
|
| 201 | + // header minimal |
|
| 202 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | define('_ECRIRE_INC_VERSION', '1'); |
| 15 | 15 | |
| 16 | 16 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 17 | - /** le nom du repertoire ecrire/ */ |
|
| 18 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 17 | + /** le nom du repertoire ecrire/ */ |
|
| 18 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** Chemin relatif pour aller dans ecrire |
@@ -36,26 +36,26 @@ discard block |
||
| 36 | 36 | # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas) |
| 37 | 37 | # mais on peut les mettre ailleurs et changer completement les noms |
| 38 | 38 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 39 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 40 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 39 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 40 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 41 | 41 | } |
| 42 | 42 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 43 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 44 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 43 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 44 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 45 | 45 | } |
| 46 | 46 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 47 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 48 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 47 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 48 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 49 | 49 | } |
| 50 | 50 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 51 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 52 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 51 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 52 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Icones |
| 56 | 56 | if (!defined('_NOM_IMG_PACK')) { |
| 57 | - /** Nom du dossier images */ |
|
| 58 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 57 | + /** Nom du dossier images */ |
|
| 58 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 59 | 59 | } |
| 60 | 60 | /** le chemin http (relatif) vers les images standard */ |
| 61 | 61 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | define('_ROOT_IMG_PACK', dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'prive' . DIRECTORY_SEPARATOR . _NOM_IMG_PACK); |
| 65 | 65 | |
| 66 | 66 | if (!defined('_JAVASCRIPT')) { |
| 67 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 68 | - // utilisable avec #CHEMIN et find_in_path |
|
| 69 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 67 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 68 | + // utilisable avec #CHEMIN et find_in_path |
|
| 69 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
@@ -74,67 +74,67 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | /** Le nom du fichier de personnalisation */ |
| 76 | 76 | if (!defined('_NOM_CONFIG')) { |
| 77 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 77 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Son emplacement absolu si on le trouve |
| 81 | 81 | if (@file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php')) { |
| 82 | - /** Emplacement absolu du fichier d'option */ |
|
| 83 | - define('_FILE_OPTIONS', $f); |
|
| 82 | + /** Emplacement absolu du fichier d'option */ |
|
| 83 | + define('_FILE_OPTIONS', $f); |
|
| 84 | 84 | } else { |
| 85 | - define('_FILE_OPTIONS', ''); |
|
| 85 | + define('_FILE_OPTIONS', ''); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | if (!defined('MODULES_IDIOMES')) { |
| 89 | - /** |
|
| 90 | - * Modules par défaut pour la traduction. |
|
| 91 | - * |
|
| 92 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 93 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 94 | - */ |
|
| 95 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 89 | + /** |
|
| 90 | + * Modules par défaut pour la traduction. |
|
| 91 | + * |
|
| 92 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 93 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 94 | + */ |
|
| 95 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | if (!defined('_IS_CLI')) { |
| 99 | - define( |
|
| 100 | - '_IS_CLI', |
|
| 101 | - !isset($_SERVER['HTTP_HOST']) |
|
| 102 | - && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 103 | - && !empty($_SERVER['argv']) |
|
| 104 | - && empty($_SERVER['REQUEST_METHOD']) |
|
| 105 | - ); |
|
| 99 | + define( |
|
| 100 | + '_IS_CLI', |
|
| 101 | + !isset($_SERVER['HTTP_HOST']) |
|
| 102 | + && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 103 | + && !empty($_SERVER['argv']) |
|
| 104 | + && empty($_SERVER['REQUEST_METHOD']) |
|
| 105 | + ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Definir les niveaux de log |
| 109 | 109 | if (!defined('_LOG_HS')) { |
| 110 | - /** @deprecated 5.0 Utiliser spip_logger()->emergency() */ |
|
| 111 | - define('_LOG_HS', 0); |
|
| 110 | + /** @deprecated 5.0 Utiliser spip_logger()->emergency() */ |
|
| 111 | + define('_LOG_HS', 0); |
|
| 112 | 112 | } |
| 113 | 113 | if (!defined('_LOG_ALERTE_ROUGE')) { |
| 114 | - /** @deprecated 5.0 Utiliser spip_logger()->alert() */ |
|
| 115 | - define('_LOG_ALERTE_ROUGE', 1); |
|
| 114 | + /** @deprecated 5.0 Utiliser spip_logger()->alert() */ |
|
| 115 | + define('_LOG_ALERTE_ROUGE', 1); |
|
| 116 | 116 | } |
| 117 | 117 | if (!defined('_LOG_CRITIQUE')) { |
| 118 | - /** @deprecated 5.0 Utiliser spip_logger()->critical() */ |
|
| 119 | - define('_LOG_CRITIQUE', 2); |
|
| 118 | + /** @deprecated 5.0 Utiliser spip_logger()->critical() */ |
|
| 119 | + define('_LOG_CRITIQUE', 2); |
|
| 120 | 120 | } |
| 121 | 121 | if (!defined('_LOG_ERREUR')) { |
| 122 | - /** @deprecated 5.0 Utiliser spip_logger()->error() */ |
|
| 123 | - define('_LOG_ERREUR', 3); |
|
| 122 | + /** @deprecated 5.0 Utiliser spip_logger()->error() */ |
|
| 123 | + define('_LOG_ERREUR', 3); |
|
| 124 | 124 | } |
| 125 | 125 | if (!defined('_LOG_AVERTISSEMENT')) { |
| 126 | - /** @deprecated 5.0 Utiliser spip_logger()->warning() */ |
|
| 127 | - define('_LOG_AVERTISSEMENT', 4); |
|
| 126 | + /** @deprecated 5.0 Utiliser spip_logger()->warning() */ |
|
| 127 | + define('_LOG_AVERTISSEMENT', 4); |
|
| 128 | 128 | } |
| 129 | 129 | if (!defined('_LOG_INFO_IMPORTANTE')) { |
| 130 | - /** @deprecated 5.0 Utiliser spip_logger()->notice() */ |
|
| 131 | - define('_LOG_INFO_IMPORTANTE', 5); |
|
| 130 | + /** @deprecated 5.0 Utiliser spip_logger()->notice() */ |
|
| 131 | + define('_LOG_INFO_IMPORTANTE', 5); |
|
| 132 | 132 | } |
| 133 | 133 | if (!defined('_LOG_INFO')) { |
| 134 | - /** @deprecated 5.0 Utiliser spip_logger()->info() */ |
|
| 135 | - define('_LOG_INFO', 6); |
|
| 134 | + /** @deprecated 5.0 Utiliser spip_logger()->info() */ |
|
| 135 | + define('_LOG_INFO', 6); |
|
| 136 | 136 | } |
| 137 | 137 | if (!defined('_LOG_DEBUG')) { |
| 138 | - /** @deprecated 5.0 Utiliser spip_logger()->debug() */ |
|
| 139 | - define('_LOG_DEBUG', 7); |
|
| 138 | + /** @deprecated 5.0 Utiliser spip_logger()->debug() */ |
|
| 139 | + define('_LOG_DEBUG', 7); |
|
| 140 | 140 | } |
@@ -28,52 +28,52 @@ discard block |
||
| 28 | 28 | * texte |
| 29 | 29 | */ |
| 30 | 30 | function _T($texte, $args = [], $options = []) { |
| 31 | - static $traduire = false; |
|
| 32 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 33 | - if ($options) { |
|
| 34 | - // support de l'ancien argument $class |
|
| 35 | - if (is_string($options)) { |
|
| 36 | - $options = ['class' => $options]; |
|
| 37 | - } |
|
| 38 | - $o = array_merge($o, $options); |
|
| 39 | - } |
|
| 31 | + static $traduire = false; |
|
| 32 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 33 | + if ($options) { |
|
| 34 | + // support de l'ancien argument $class |
|
| 35 | + if (is_string($options)) { |
|
| 36 | + $options = ['class' => $options]; |
|
| 37 | + } |
|
| 38 | + $o = array_merge($o, $options); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - if (!$traduire) { |
|
| 42 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 43 | - include_spip('inc/lang'); |
|
| 44 | - } |
|
| 41 | + if (!$traduire) { |
|
| 42 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 43 | + include_spip('inc/lang'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // On peut passer explicitement la langue dans le tableau |
|
| 47 | - // On utilise le même nom de variable que la globale |
|
| 48 | - if (isset($args['spip_lang'])) { |
|
| 49 | - $lang = $args['spip_lang']; |
|
| 50 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 51 | - unset($args['spip_lang']); |
|
| 52 | - } // Sinon on prend la langue du contexte |
|
| 53 | - else { |
|
| 54 | - $lang = $GLOBALS['spip_lang']; |
|
| 55 | - } |
|
| 56 | - $text = $traduire($texte, $lang); |
|
| 46 | + // On peut passer explicitement la langue dans le tableau |
|
| 47 | + // On utilise le même nom de variable que la globale |
|
| 48 | + if (isset($args['spip_lang'])) { |
|
| 49 | + $lang = $args['spip_lang']; |
|
| 50 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 51 | + unset($args['spip_lang']); |
|
| 52 | + } // Sinon on prend la langue du contexte |
|
| 53 | + else { |
|
| 54 | + $lang = $GLOBALS['spip_lang']; |
|
| 55 | + } |
|
| 56 | + $text = $traduire($texte, $lang); |
|
| 57 | 57 | |
| 58 | - if ($text === null || !strlen($text)) { |
|
| 59 | - if (!$o['force']) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 58 | + if ($text === null || !strlen($text)) { |
|
| 59 | + if (!$o['force']) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $text = $texte; |
|
| 63 | + $text = $texte; |
|
| 64 | 64 | |
| 65 | - // pour les chaines non traduites, assurer un service minimum |
|
| 66 | - if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') { |
|
| 67 | - $n = strpos($text, ':'); |
|
| 68 | - if ($n !== false) { |
|
| 69 | - $text = substr($text, $n + 1); |
|
| 70 | - } |
|
| 71 | - $text = str_replace('_', ' ', $text); |
|
| 72 | - } |
|
| 73 | - $o['class'] = null; |
|
| 74 | - } |
|
| 65 | + // pour les chaines non traduites, assurer un service minimum |
|
| 66 | + if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') { |
|
| 67 | + $n = strpos($text, ':'); |
|
| 68 | + if ($n !== false) { |
|
| 69 | + $text = substr($text, $n + 1); |
|
| 70 | + } |
|
| 71 | + $text = str_replace('_', ' ', $text); |
|
| 72 | + } |
|
| 73 | + $o['class'] = null; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return _L($text, $args, $o); |
|
| 76 | + return _L($text, $args, $o); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -100,53 +100,53 @@ discard block |
||
| 100 | 100 | * texte |
| 101 | 101 | */ |
| 102 | 102 | function _L($text, $args = [], $options = []) { |
| 103 | - $f = $text; |
|
| 104 | - $defaut_options = [ |
|
| 105 | - 'class' => null, |
|
| 106 | - 'sanitize' => true, |
|
| 107 | - ]; |
|
| 108 | - // support de l'ancien argument $class |
|
| 109 | - if ($options && is_string($options)) { |
|
| 110 | - $options = ['class' => $options]; |
|
| 111 | - } |
|
| 112 | - if (is_array($options)) { |
|
| 113 | - $options += $defaut_options; |
|
| 114 | - } else { |
|
| 115 | - $options = $defaut_options; |
|
| 116 | - } |
|
| 103 | + $f = $text; |
|
| 104 | + $defaut_options = [ |
|
| 105 | + 'class' => null, |
|
| 106 | + 'sanitize' => true, |
|
| 107 | + ]; |
|
| 108 | + // support de l'ancien argument $class |
|
| 109 | + if ($options && is_string($options)) { |
|
| 110 | + $options = ['class' => $options]; |
|
| 111 | + } |
|
| 112 | + if (is_array($options)) { |
|
| 113 | + $options += $defaut_options; |
|
| 114 | + } else { |
|
| 115 | + $options = $defaut_options; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - if (is_array($args) && count($args)) { |
|
| 119 | - if (!function_exists('interdire_scripts')) { |
|
| 120 | - include_spip('inc/texte'); |
|
| 121 | - } |
|
| 122 | - if (!function_exists('echapper_html_suspect')) { |
|
| 123 | - include_spip('inc/texte_mini'); |
|
| 124 | - } |
|
| 125 | - foreach ($args as $name => $value) { |
|
| 126 | - if (str_contains($text, (string) "@$name@")) { |
|
| 127 | - if ($options['sanitize']) { |
|
| 128 | - $value = echapper_html_suspect($value); |
|
| 129 | - $value = interdire_scripts($value, -1); |
|
| 130 | - } |
|
| 131 | - if (!empty($options['class'])) { |
|
| 132 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 133 | - } |
|
| 134 | - $text = str_replace("@$name@", (string) $value, (string) $text); |
|
| 135 | - unset($args[$name]); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 139 | - // (chaines de langues pas a jour) |
|
| 140 | - if ($args) { |
|
| 141 | - spip_logger()->debug("$f: variables inutilisees " . join(', ', array_keys($args))); |
|
| 142 | - } |
|
| 143 | - } |
|
| 118 | + if (is_array($args) && count($args)) { |
|
| 119 | + if (!function_exists('interdire_scripts')) { |
|
| 120 | + include_spip('inc/texte'); |
|
| 121 | + } |
|
| 122 | + if (!function_exists('echapper_html_suspect')) { |
|
| 123 | + include_spip('inc/texte_mini'); |
|
| 124 | + } |
|
| 125 | + foreach ($args as $name => $value) { |
|
| 126 | + if (str_contains($text, (string) "@$name@")) { |
|
| 127 | + if ($options['sanitize']) { |
|
| 128 | + $value = echapper_html_suspect($value); |
|
| 129 | + $value = interdire_scripts($value, -1); |
|
| 130 | + } |
|
| 131 | + if (!empty($options['class'])) { |
|
| 132 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 133 | + } |
|
| 134 | + $text = str_replace("@$name@", (string) $value, (string) $text); |
|
| 135 | + unset($args[$name]); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 139 | + // (chaines de langues pas a jour) |
|
| 140 | + if ($args) { |
|
| 141 | + spip_logger()->debug("$f: variables inutilisees " . join(', ', array_keys($args))); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) { |
|
| 146 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 147 | - } else { |
|
| 148 | - return $text; |
|
| 149 | - } |
|
| 145 | + if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) { |
|
| 146 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 147 | + } else { |
|
| 148 | + return $text; |
|
| 149 | + } |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -169,19 +169,19 @@ discard block |
||
| 169 | 169 | * - string Langue utilisée. |
| 170 | 170 | **/ |
| 171 | 171 | function lang_select($lang = null) { |
| 172 | - static $pile_langues = []; |
|
| 173 | - if (!function_exists('changer_langue')) { |
|
| 174 | - include_spip('inc/lang'); |
|
| 175 | - } |
|
| 176 | - if ($lang === null) { |
|
| 177 | - $lang = array_pop($pile_langues); |
|
| 178 | - } else { |
|
| 179 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 180 | - } |
|
| 181 | - if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) { |
|
| 182 | - return $lang; |
|
| 183 | - } |
|
| 184 | - changer_langue($lang); |
|
| 172 | + static $pile_langues = []; |
|
| 173 | + if (!function_exists('changer_langue')) { |
|
| 174 | + include_spip('inc/lang'); |
|
| 175 | + } |
|
| 176 | + if ($lang === null) { |
|
| 177 | + $lang = array_pop($pile_langues); |
|
| 178 | + } else { |
|
| 179 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 180 | + } |
|
| 181 | + if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) { |
|
| 182 | + return $lang; |
|
| 183 | + } |
|
| 184 | + changer_langue($lang); |
|
| 185 | 185 | |
| 186 | - return $lang; |
|
| 186 | + return $lang; |
|
| 187 | 187 | } |
@@ -27,71 +27,71 @@ discard block |
||
| 27 | 27 | * Nom de la fonction, ou false. |
| 28 | 28 | */ |
| 29 | 29 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 30 | - static $echecs = []; |
|
| 31 | - |
|
| 32 | - if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 33 | - $dossier .= '/'; |
|
| 34 | - } |
|
| 35 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 36 | - |
|
| 37 | - if (function_exists($f)) { |
|
| 38 | - return $f; |
|
| 39 | - } |
|
| 40 | - if (function_exists($g = $f . '_dist')) { |
|
| 41 | - return $g; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if (isset($echecs[$f])) { |
|
| 45 | - return $echecs[$f]; |
|
| 46 | - } |
|
| 47 | - // Sinon charger le fichier de declaration si plausible |
|
| 48 | - |
|
| 49 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 50 | - if ($continue) { |
|
| 51 | - return false; |
|
| 52 | - } //appel interne, on passe |
|
| 53 | - include_spip('inc/minipres'); |
|
| 54 | - echo minipres(); |
|
| 55 | - exit; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // passer en minuscules (cf les balises de formulaires) |
|
| 59 | - // et inclure le fichier |
|
| 60 | - if ( |
|
| 61 | - !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 62 | - && strlen(dirname($dossier)) |
|
| 63 | - && dirname($dossier) != '.' |
|
| 64 | - ) { |
|
| 65 | - include_spip(substr($dossier, 0, -1)); |
|
| 66 | - } |
|
| 67 | - if (function_exists($f)) { |
|
| 68 | - return $f; |
|
| 69 | - } |
|
| 70 | - if (function_exists($g)) { |
|
| 71 | - return $g; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($continue) { |
|
| 75 | - return $echecs[$f] = false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Echec : message d'erreur |
|
| 79 | - spip_logger()->info("fonction $nom ($f ou $g) indisponible" . |
|
| 80 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 81 | - |
|
| 82 | - include_spip('inc/minipres'); |
|
| 83 | - include_spip('inc/filtres_mini'); |
|
| 84 | - echo minipres( |
|
| 85 | - _T('forum_titre_erreur'), |
|
| 86 | - $inc ? |
|
| 87 | - _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 88 | - . '<br />' |
|
| 89 | - . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 90 | - : |
|
| 91 | - _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 92 | - ['all_inline' => true,'status' => 404] |
|
| 93 | - ); |
|
| 94 | - exit; |
|
| 30 | + static $echecs = []; |
|
| 31 | + |
|
| 32 | + if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 33 | + $dossier .= '/'; |
|
| 34 | + } |
|
| 35 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 36 | + |
|
| 37 | + if (function_exists($f)) { |
|
| 38 | + return $f; |
|
| 39 | + } |
|
| 40 | + if (function_exists($g = $f . '_dist')) { |
|
| 41 | + return $g; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if (isset($echecs[$f])) { |
|
| 45 | + return $echecs[$f]; |
|
| 46 | + } |
|
| 47 | + // Sinon charger le fichier de declaration si plausible |
|
| 48 | + |
|
| 49 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 50 | + if ($continue) { |
|
| 51 | + return false; |
|
| 52 | + } //appel interne, on passe |
|
| 53 | + include_spip('inc/minipres'); |
|
| 54 | + echo minipres(); |
|
| 55 | + exit; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // passer en minuscules (cf les balises de formulaires) |
|
| 59 | + // et inclure le fichier |
|
| 60 | + if ( |
|
| 61 | + !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 62 | + && strlen(dirname($dossier)) |
|
| 63 | + && dirname($dossier) != '.' |
|
| 64 | + ) { |
|
| 65 | + include_spip(substr($dossier, 0, -1)); |
|
| 66 | + } |
|
| 67 | + if (function_exists($f)) { |
|
| 68 | + return $f; |
|
| 69 | + } |
|
| 70 | + if (function_exists($g)) { |
|
| 71 | + return $g; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($continue) { |
|
| 75 | + return $echecs[$f] = false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Echec : message d'erreur |
|
| 79 | + spip_logger()->info("fonction $nom ($f ou $g) indisponible" . |
|
| 80 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 81 | + |
|
| 82 | + include_spip('inc/minipres'); |
|
| 83 | + include_spip('inc/filtres_mini'); |
|
| 84 | + echo minipres( |
|
| 85 | + _T('forum_titre_erreur'), |
|
| 86 | + $inc ? |
|
| 87 | + _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 88 | + . '<br />' |
|
| 89 | + . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 90 | + : |
|
| 91 | + _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 92 | + ['all_inline' => true,'status' => 404] |
|
| 93 | + ); |
|
| 94 | + exit; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | 103 | function include_once_check($file) { |
| 104 | - if (file_exists($file)) { |
|
| 105 | - include_once $file; |
|
| 104 | + if (file_exists($file)) { |
|
| 105 | + include_once $file; |
|
| 106 | 106 | |
| 107 | - return true; |
|
| 108 | - } |
|
| 109 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 110 | - $crash = ($crash ?: []); |
|
| 111 | - $crash[$file] = true; |
|
| 112 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 110 | + $crash = ($crash ?: []); |
|
| 111 | + $crash[$file] = true; |
|
| 112 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * - string : chemin du fichier trouvé |
| 136 | 136 | **/ |
| 137 | 137 | function include_spip($f, $include = true) { |
| 138 | - return find_in_path($f . '.php', '', $include); |
|
| 138 | + return find_in_path($f . '.php', '', $include); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * - string : chemin du fichier trouvé |
| 156 | 156 | **/ |
| 157 | 157 | function require_spip($f) { |
| 158 | - return find_in_path($f . '.php', '', 'required'); |
|
| 158 | + return find_in_path($f . '.php', '', 'required'); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
@@ -165,27 +165,27 @@ discard block |
||
| 165 | 165 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 166 | 166 | */ |
| 167 | 167 | function include_fichiers_fonctions() { |
| 168 | - static $done = false; |
|
| 169 | - if (!$done) { |
|
| 170 | - include_spip('inc/lang'); |
|
| 171 | - |
|
| 172 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 173 | - // donc il faut l'inclure "en globals" |
|
| 174 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 175 | - global $dossier_squelettes; |
|
| 176 | - include_once(_ROOT_CWD . $f); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 180 | - // chargement optimise precompile |
|
| 181 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 182 | - } |
|
| 183 | - if (test_espace_prive()) { |
|
| 184 | - include_spip('inc/filtres_ecrire'); |
|
| 185 | - } |
|
| 186 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 187 | - $done = true; |
|
| 188 | - } |
|
| 168 | + static $done = false; |
|
| 169 | + if (!$done) { |
|
| 170 | + include_spip('inc/lang'); |
|
| 171 | + |
|
| 172 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 173 | + // donc il faut l'inclure "en globals" |
|
| 174 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 175 | + global $dossier_squelettes; |
|
| 176 | + include_once(_ROOT_CWD . $f); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 180 | + // chargement optimise precompile |
|
| 181 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 182 | + } |
|
| 183 | + if (test_espace_prive()) { |
|
| 184 | + include_spip('inc/filtres_ecrire'); |
|
| 185 | + } |
|
| 186 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 187 | + $done = true; |
|
| 188 | + } |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -198,59 +198,59 @@ discard block |
||
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | 200 | function charger_fonction_url(string $quoi, string $type = '') { |
| 201 | - if ($type === 'defaut') { |
|
| 202 | - $objet = objet_type($quoi); |
|
| 203 | - if ( |
|
| 204 | - ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 205 | - || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 206 | - ) { |
|
| 207 | - return $f; |
|
| 208 | - } |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $url_type = $type; |
|
| 213 | - if (!$url_type) { |
|
| 214 | - $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // inclure le module d'url |
|
| 218 | - include_spip('urls/' . $url_type); |
|
| 219 | - |
|
| 220 | - switch ($quoi) { |
|
| 221 | - case 'page': |
|
| 222 | - if ( |
|
| 223 | - function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 224 | - || function_exists($f .= '_dist') |
|
| 225 | - // ou une fonction custom utilisateur independante du type d'url |
|
| 226 | - || function_exists($f = 'generer_url_page') |
|
| 227 | - || function_exists($f .= '_dist') |
|
| 228 | - ) { |
|
| 229 | - return $f; |
|
| 230 | - } |
|
| 231 | - // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 232 | - return ''; |
|
| 233 | - case 'objet': |
|
| 234 | - case 'decoder': |
|
| 235 | - default: |
|
| 236 | - $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 237 | - if ( |
|
| 238 | - function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 239 | - || function_exists($f .= '_dist') |
|
| 240 | - ) { |
|
| 241 | - return $f; |
|
| 242 | - } |
|
| 243 | - // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 244 | - // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 245 | - if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 246 | - return $f; |
|
| 247 | - } |
|
| 248 | - // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 249 | - if (!$type && $url_type !== 'page') { |
|
| 250 | - return charger_fonction_url($quoi, 'page'); |
|
| 251 | - } |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 201 | + if ($type === 'defaut') { |
|
| 202 | + $objet = objet_type($quoi); |
|
| 203 | + if ( |
|
| 204 | + ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 205 | + || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 206 | + ) { |
|
| 207 | + return $f; |
|
| 208 | + } |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $url_type = $type; |
|
| 213 | + if (!$url_type) { |
|
| 214 | + $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // inclure le module d'url |
|
| 218 | + include_spip('urls/' . $url_type); |
|
| 219 | + |
|
| 220 | + switch ($quoi) { |
|
| 221 | + case 'page': |
|
| 222 | + if ( |
|
| 223 | + function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 224 | + || function_exists($f .= '_dist') |
|
| 225 | + // ou une fonction custom utilisateur independante du type d'url |
|
| 226 | + || function_exists($f = 'generer_url_page') |
|
| 227 | + || function_exists($f .= '_dist') |
|
| 228 | + ) { |
|
| 229 | + return $f; |
|
| 230 | + } |
|
| 231 | + // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 232 | + return ''; |
|
| 233 | + case 'objet': |
|
| 234 | + case 'decoder': |
|
| 235 | + default: |
|
| 236 | + $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 237 | + if ( |
|
| 238 | + function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 239 | + || function_exists($f .= '_dist') |
|
| 240 | + ) { |
|
| 241 | + return $f; |
|
| 242 | + } |
|
| 243 | + // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 244 | + // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 245 | + if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 246 | + return $f; |
|
| 247 | + } |
|
| 248 | + // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 249 | + if (!$type && $url_type !== 'page') { |
|
| 250 | + return charger_fonction_url($quoi, 'page'); |
|
| 251 | + } |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | 263 | function trouve_modele($nom) { |
| 264 | - return trouver_fond($nom, 'modeles/'); |
|
| 264 | + return trouver_fond($nom, 'modeles/'); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -277,28 +277,28 @@ discard block |
||
| 277 | 277 | * @return array|string |
| 278 | 278 | */ |
| 279 | 279 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 280 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 281 | - if (!$pathinfo) { |
|
| 282 | - return $f; |
|
| 283 | - } |
|
| 284 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 285 | - if ($f === null) { |
|
| 286 | - return [ |
|
| 287 | - 'extension' => _EXTENSION_SQUELETTES, |
|
| 288 | - 'filename' => '', |
|
| 289 | - 'fond' => '' |
|
| 290 | - ]; |
|
| 291 | - } |
|
| 292 | - $p = pathinfo($f); |
|
| 293 | - if (!isset($p['extension']) || !$p['extension']) { |
|
| 294 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 295 | - } |
|
| 296 | - if (!isset($p['extension']) || !$p['filename']) { |
|
| 297 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 298 | - } |
|
| 299 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 300 | - |
|
| 301 | - return $p; |
|
| 280 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 281 | + if (!$pathinfo) { |
|
| 282 | + return $f; |
|
| 283 | + } |
|
| 284 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 285 | + if ($f === null) { |
|
| 286 | + return [ |
|
| 287 | + 'extension' => _EXTENSION_SQUELETTES, |
|
| 288 | + 'filename' => '', |
|
| 289 | + 'fond' => '' |
|
| 290 | + ]; |
|
| 291 | + } |
|
| 292 | + $p = pathinfo($f); |
|
| 293 | + if (!isset($p['extension']) || !$p['extension']) { |
|
| 294 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 295 | + } |
|
| 296 | + if (!isset($p['extension']) || !$p['filename']) { |
|
| 297 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 298 | + } |
|
| 299 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 300 | + |
|
| 301 | + return $p; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | * Lien sur une icone d'aide |
| 317 | 317 | **/ |
| 318 | 318 | function aider($aide = '', $distante = false) { |
| 319 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 319 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 320 | 320 | |
| 321 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 321 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -339,19 +339,19 @@ discard block |
||
| 339 | 339 | * Nom de l'exec, sinon chaîne vide. |
| 340 | 340 | **/ |
| 341 | 341 | function tester_url_ecrire($nom) { |
| 342 | - static $exec = []; |
|
| 343 | - if (isset($exec[$nom])) { |
|
| 344 | - return $exec[$nom]; |
|
| 345 | - } |
|
| 346 | - // tester si c'est une page en squelette |
|
| 347 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 348 | - return $exec[$nom] = 'fond'; |
|
| 349 | - } // echafaudage d'un fond ! |
|
| 350 | - elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 351 | - return $exec[$nom] = 'fond'; |
|
| 352 | - } |
|
| 353 | - // attention, il ne faut pas inclure l'exec ici |
|
| 354 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 355 | - // et des define intrusifs potentiels |
|
| 356 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 342 | + static $exec = []; |
|
| 343 | + if (isset($exec[$nom])) { |
|
| 344 | + return $exec[$nom]; |
|
| 345 | + } |
|
| 346 | + // tester si c'est une page en squelette |
|
| 347 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 348 | + return $exec[$nom] = 'fond'; |
|
| 349 | + } // echafaudage d'un fond ! |
|
| 350 | + elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 351 | + return $exec[$nom] = 'fond'; |
|
| 352 | + } |
|
| 353 | + // attention, il ne faut pas inclure l'exec ici |
|
| 354 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 355 | + // et des define intrusifs potentiels |
|
| 356 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 357 | 357 | } |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | * @param string $ta Répertoire temporaire accessible |
| 10 | 10 | */ |
| 11 | 11 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 12 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 13 | - spip_initialisation_suite(); |
|
| 12 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 13 | + spip_initialisation_suite(); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -30,313 +30,313 @@ discard block |
||
| 30 | 30 | * @param string $ta Répertoire temporaire accessible |
| 31 | 31 | */ |
| 32 | 32 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 33 | - static $too_late = 0; |
|
| 34 | - if ($too_late++) { |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Declaration des repertoires |
|
| 39 | - |
|
| 40 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 41 | - if (!defined('_DIR_PLUGINS')) { |
|
| 42 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 46 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 47 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // le nom du repertoire des librairies |
|
| 51 | - if (!defined('_DIR_LIB')) { |
|
| 52 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // répertoire des libs via Composer |
|
| 56 | - if (!defined('_DIR_VENDOR')) { |
|
| 57 | - define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!defined('_DIR_IMG')) { |
|
| 61 | - define('_DIR_IMG', $pa); |
|
| 62 | - } |
|
| 63 | - if (!defined('_DIR_LOGOS')) { |
|
| 64 | - define('_DIR_LOGOS', $pa); |
|
| 65 | - } |
|
| 66 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 67 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (!defined('_DIR_DUMP')) { |
|
| 71 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 72 | - } |
|
| 73 | - if (!defined('_DIR_SESSIONS')) { |
|
| 74 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 75 | - } |
|
| 76 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 77 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 78 | - } |
|
| 79 | - if (!defined('_DIR_CACHE')) { |
|
| 80 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 81 | - } |
|
| 82 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 83 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 84 | - } |
|
| 85 | - if (!defined('_DIR_SKELS')) { |
|
| 86 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 87 | - } |
|
| 88 | - if (!defined('_DIR_AIDE')) { |
|
| 89 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 90 | - } |
|
| 91 | - if (!defined('_DIR_TMP')) { |
|
| 92 | - define('_DIR_TMP', $ti); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (!defined('_DIR_VAR')) { |
|
| 96 | - define('_DIR_VAR', $ta); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if (!defined('_DIR_ETC')) { |
|
| 100 | - define('_DIR_ETC', $pi); |
|
| 101 | - } |
|
| 102 | - if (!defined('_DIR_CONNECT')) { |
|
| 103 | - define('_DIR_CONNECT', $pi); |
|
| 104 | - } |
|
| 105 | - if (!defined('_DIR_CHMOD')) { |
|
| 106 | - define('_DIR_CHMOD', $pi); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 110 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 111 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 112 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Declaration des fichiers |
|
| 116 | - |
|
| 117 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 118 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 119 | - } |
|
| 120 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 121 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 122 | - } |
|
| 123 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 124 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 125 | - } |
|
| 126 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 127 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 128 | - } |
|
| 129 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 130 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 134 | - if (!defined('_FILE_META')) { |
|
| 135 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 136 | - } |
|
| 137 | - if (!defined('_DIR_LOG')) { |
|
| 138 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 139 | - } |
|
| 140 | - if (!defined('_FILE_LOG')) { |
|
| 141 | - define('_FILE_LOG', 'spip'); |
|
| 142 | - } |
|
| 143 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 144 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // Le fichier de connexion a la base de donnees |
|
| 148 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 149 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 150 | - } |
|
| 151 | - if (!defined('_FILE_CONNECT')) { |
|
| 152 | - define( |
|
| 153 | - '_FILE_CONNECT', |
|
| 154 | - @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // Le fichier de reglages des droits |
|
| 159 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 160 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 161 | - } |
|
| 162 | - if (!defined('_FILE_CHMOD')) { |
|
| 163 | - define( |
|
| 164 | - '_FILE_CHMOD', |
|
| 165 | - @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (!defined('_FILE_LDAP')) { |
|
| 170 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 174 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 175 | - } |
|
| 176 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 177 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 178 | - } |
|
| 179 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 180 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Definition des droits d'acces en ecriture |
|
| 184 | - if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 185 | - include_once _FILE_CHMOD; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Se mefier des fichiers mal remplis! |
|
| 189 | - if (!defined('_SPIP_CHMOD')) { |
|
| 190 | - define('_SPIP_CHMOD', 0777); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 194 | - /** Le charset par défaut lors de l'installation */ |
|
| 195 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 196 | - } |
|
| 197 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 198 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins' . DIRECTORY_SEPARATOR); |
|
| 199 | - } |
|
| 200 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 201 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist' . DIRECTORY_SEPARATOR); |
|
| 202 | - } |
|
| 203 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 204 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // La taille des Log |
|
| 208 | - if (!defined('_MAX_LOG')) { |
|
| 209 | - define('_MAX_LOG', 100); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Sommes-nous dans l'empire du Mal ? |
|
| 213 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 214 | - if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 215 | - if (!defined('_OS_SERVEUR')) { |
|
| 216 | - define('_OS_SERVEUR', 'windows'); |
|
| 217 | - } |
|
| 218 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 219 | - define('_SPIP_LOCK_MODE', 1); |
|
| 220 | - } // utiliser le flock php |
|
| 221 | - } else { |
|
| 222 | - if (!defined('_OS_SERVEUR')) { |
|
| 223 | - define('_OS_SERVEUR', ''); |
|
| 224 | - } |
|
| 225 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 226 | - define('_SPIP_LOCK_MODE', 1); |
|
| 227 | - } // utiliser le flock php |
|
| 228 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Langue par defaut |
|
| 232 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 233 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // |
|
| 237 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 238 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 239 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 240 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 241 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 242 | - |
|
| 243 | - // charger le path des plugins |
|
| 244 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 245 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // *********** traiter les variables ************ |
|
| 249 | - |
|
| 250 | - // |
|
| 251 | - // Securite |
|
| 252 | - // |
|
| 253 | - |
|
| 254 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 255 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 256 | - die(); |
|
| 257 | - } |
|
| 258 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 259 | - spip_desinfecte($_GET); |
|
| 260 | - spip_desinfecte($_POST); |
|
| 261 | - spip_desinfecte($_COOKIE); |
|
| 262 | - spip_desinfecte($_REQUEST); |
|
| 263 | - |
|
| 264 | - // appliquer le cookie_prefix |
|
| 265 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 266 | - include_spip('inc/cookie'); |
|
| 267 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 271 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 272 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 273 | - } else { |
|
| 274 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 275 | - if ( |
|
| 276 | - !empty($_SERVER['QUERY_STRING']) |
|
| 277 | - && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 278 | - ) { |
|
| 279 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 284 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 285 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 286 | - } |
|
| 287 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 288 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 292 | - // charge aussi effacer_meta et ecrire_meta |
|
| 293 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 294 | - $inc_meta(); |
|
| 295 | - |
|
| 296 | - // nombre de repertoires depuis la racine |
|
| 297 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 298 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 299 | - // le calcul est faux) |
|
| 300 | - if (!_DIR_RESTREINT) { |
|
| 301 | - $GLOBALS['profondeur_url'] = 1; |
|
| 302 | - } else { |
|
| 303 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 304 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 305 | - if ( |
|
| 306 | - !$uri_ref |
|
| 307 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 308 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 309 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 310 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 311 | - || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 312 | - ) { |
|
| 313 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 314 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 315 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 316 | - } else { |
|
| 317 | - $uri_ref = ''; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - if (!$uri || !$uri_ref) { |
|
| 321 | - $GLOBALS['profondeur_url'] = 0; |
|
| 322 | - } else { |
|
| 323 | - $GLOBALS['profondeur_url'] = max( |
|
| 324 | - 0, |
|
| 325 | - substr_count($uri[0], '/') |
|
| 326 | - - substr_count($uri_ref, '/') |
|
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 331 | - if (_FILE_CONNECT) { |
|
| 332 | - if ( |
|
| 333 | - verifier_visiteur() == '0minirezo' |
|
| 334 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 335 | - && !isset($_COOKIE['spip_admin']) |
|
| 336 | - ) { |
|
| 337 | - clear_path_cache(); |
|
| 338 | - } |
|
| 339 | - } |
|
| 33 | + static $too_late = 0; |
|
| 34 | + if ($too_late++) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // Declaration des repertoires |
|
| 39 | + |
|
| 40 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 41 | + if (!defined('_DIR_PLUGINS')) { |
|
| 42 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 46 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 47 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // le nom du repertoire des librairies |
|
| 51 | + if (!defined('_DIR_LIB')) { |
|
| 52 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // répertoire des libs via Composer |
|
| 56 | + if (!defined('_DIR_VENDOR')) { |
|
| 57 | + define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!defined('_DIR_IMG')) { |
|
| 61 | + define('_DIR_IMG', $pa); |
|
| 62 | + } |
|
| 63 | + if (!defined('_DIR_LOGOS')) { |
|
| 64 | + define('_DIR_LOGOS', $pa); |
|
| 65 | + } |
|
| 66 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 67 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (!defined('_DIR_DUMP')) { |
|
| 71 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 72 | + } |
|
| 73 | + if (!defined('_DIR_SESSIONS')) { |
|
| 74 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 75 | + } |
|
| 76 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 77 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 78 | + } |
|
| 79 | + if (!defined('_DIR_CACHE')) { |
|
| 80 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 81 | + } |
|
| 82 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 83 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 84 | + } |
|
| 85 | + if (!defined('_DIR_SKELS')) { |
|
| 86 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 87 | + } |
|
| 88 | + if (!defined('_DIR_AIDE')) { |
|
| 89 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 90 | + } |
|
| 91 | + if (!defined('_DIR_TMP')) { |
|
| 92 | + define('_DIR_TMP', $ti); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (!defined('_DIR_VAR')) { |
|
| 96 | + define('_DIR_VAR', $ta); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if (!defined('_DIR_ETC')) { |
|
| 100 | + define('_DIR_ETC', $pi); |
|
| 101 | + } |
|
| 102 | + if (!defined('_DIR_CONNECT')) { |
|
| 103 | + define('_DIR_CONNECT', $pi); |
|
| 104 | + } |
|
| 105 | + if (!defined('_DIR_CHMOD')) { |
|
| 106 | + define('_DIR_CHMOD', $pi); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 110 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 111 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 112 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Declaration des fichiers |
|
| 116 | + |
|
| 117 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 118 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 119 | + } |
|
| 120 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 121 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 122 | + } |
|
| 123 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 124 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 125 | + } |
|
| 126 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 127 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 128 | + } |
|
| 129 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 130 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 134 | + if (!defined('_FILE_META')) { |
|
| 135 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 136 | + } |
|
| 137 | + if (!defined('_DIR_LOG')) { |
|
| 138 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 139 | + } |
|
| 140 | + if (!defined('_FILE_LOG')) { |
|
| 141 | + define('_FILE_LOG', 'spip'); |
|
| 142 | + } |
|
| 143 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 144 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // Le fichier de connexion a la base de donnees |
|
| 148 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 149 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 150 | + } |
|
| 151 | + if (!defined('_FILE_CONNECT')) { |
|
| 152 | + define( |
|
| 153 | + '_FILE_CONNECT', |
|
| 154 | + @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // Le fichier de reglages des droits |
|
| 159 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 160 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 161 | + } |
|
| 162 | + if (!defined('_FILE_CHMOD')) { |
|
| 163 | + define( |
|
| 164 | + '_FILE_CHMOD', |
|
| 165 | + @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (!defined('_FILE_LDAP')) { |
|
| 170 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 174 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 175 | + } |
|
| 176 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 177 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 178 | + } |
|
| 179 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 180 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Definition des droits d'acces en ecriture |
|
| 184 | + if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 185 | + include_once _FILE_CHMOD; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Se mefier des fichiers mal remplis! |
|
| 189 | + if (!defined('_SPIP_CHMOD')) { |
|
| 190 | + define('_SPIP_CHMOD', 0777); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 194 | + /** Le charset par défaut lors de l'installation */ |
|
| 195 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 196 | + } |
|
| 197 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 198 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins' . DIRECTORY_SEPARATOR); |
|
| 199 | + } |
|
| 200 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 201 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist' . DIRECTORY_SEPARATOR); |
|
| 202 | + } |
|
| 203 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 204 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // La taille des Log |
|
| 208 | + if (!defined('_MAX_LOG')) { |
|
| 209 | + define('_MAX_LOG', 100); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Sommes-nous dans l'empire du Mal ? |
|
| 213 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 214 | + if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 215 | + if (!defined('_OS_SERVEUR')) { |
|
| 216 | + define('_OS_SERVEUR', 'windows'); |
|
| 217 | + } |
|
| 218 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 219 | + define('_SPIP_LOCK_MODE', 1); |
|
| 220 | + } // utiliser le flock php |
|
| 221 | + } else { |
|
| 222 | + if (!defined('_OS_SERVEUR')) { |
|
| 223 | + define('_OS_SERVEUR', ''); |
|
| 224 | + } |
|
| 225 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 226 | + define('_SPIP_LOCK_MODE', 1); |
|
| 227 | + } // utiliser le flock php |
|
| 228 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Langue par defaut |
|
| 232 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 233 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // |
|
| 237 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 238 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 239 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 240 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 241 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 242 | + |
|
| 243 | + // charger le path des plugins |
|
| 244 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 245 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // *********** traiter les variables ************ |
|
| 249 | + |
|
| 250 | + // |
|
| 251 | + // Securite |
|
| 252 | + // |
|
| 253 | + |
|
| 254 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 255 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 256 | + die(); |
|
| 257 | + } |
|
| 258 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 259 | + spip_desinfecte($_GET); |
|
| 260 | + spip_desinfecte($_POST); |
|
| 261 | + spip_desinfecte($_COOKIE); |
|
| 262 | + spip_desinfecte($_REQUEST); |
|
| 263 | + |
|
| 264 | + // appliquer le cookie_prefix |
|
| 265 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 266 | + include_spip('inc/cookie'); |
|
| 267 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 271 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 272 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 273 | + } else { |
|
| 274 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 275 | + if ( |
|
| 276 | + !empty($_SERVER['QUERY_STRING']) |
|
| 277 | + && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 278 | + ) { |
|
| 279 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 284 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 285 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 286 | + } |
|
| 287 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 288 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 292 | + // charge aussi effacer_meta et ecrire_meta |
|
| 293 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 294 | + $inc_meta(); |
|
| 295 | + |
|
| 296 | + // nombre de repertoires depuis la racine |
|
| 297 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 298 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 299 | + // le calcul est faux) |
|
| 300 | + if (!_DIR_RESTREINT) { |
|
| 301 | + $GLOBALS['profondeur_url'] = 1; |
|
| 302 | + } else { |
|
| 303 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 304 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 305 | + if ( |
|
| 306 | + !$uri_ref |
|
| 307 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 308 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 309 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 310 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 311 | + || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 312 | + ) { |
|
| 313 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 314 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 315 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 316 | + } else { |
|
| 317 | + $uri_ref = ''; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + if (!$uri || !$uri_ref) { |
|
| 321 | + $GLOBALS['profondeur_url'] = 0; |
|
| 322 | + } else { |
|
| 323 | + $GLOBALS['profondeur_url'] = max( |
|
| 324 | + 0, |
|
| 325 | + substr_count($uri[0], '/') |
|
| 326 | + - substr_count($uri_ref, '/') |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 331 | + if (_FILE_CONNECT) { |
|
| 332 | + if ( |
|
| 333 | + verifier_visiteur() == '0minirezo' |
|
| 334 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 335 | + && !isset($_COOKIE['spip_admin']) |
|
| 336 | + ) { |
|
| 337 | + clear_path_cache(); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -345,158 +345,158 @@ discard block |
||
| 345 | 345 | * |
| 346 | 346 | */ |
| 347 | 347 | function spip_initialisation_suite() { |
| 348 | - static $too_late = 0; |
|
| 349 | - if ($too_late++) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // taille mini des login |
|
| 354 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 355 | - define('_LOGIN_TROP_COURT', 4); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 359 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 360 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 361 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 362 | - |
|
| 363 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 364 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 365 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 366 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 367 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 368 | - |
|
| 369 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 370 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // largeur maximale des images dans l'administration |
|
| 374 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 375 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 379 | - if (!defined('_IMG_QUALITE')) { |
|
| 380 | - define('_IMG_QUALITE', 85); |
|
| 381 | - } # valeur par defaut |
|
| 382 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 383 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 384 | - } # surcharge pour la lib GD |
|
| 385 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 386 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 387 | - } # surcharge pour imagick en ligne de commande |
|
| 388 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 389 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 390 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 391 | - } # surcharge pour imagick en PHP |
|
| 392 | - |
|
| 393 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 394 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 395 | - } // poids en octet |
|
| 396 | - |
|
| 397 | - // qq chaines standard |
|
| 398 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 399 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 400 | - } |
|
| 401 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 402 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 403 | - } |
|
| 404 | - if (!defined('_SPIP_DUMP')) { |
|
| 405 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 406 | - } |
|
| 407 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 408 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 409 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 410 | - } |
|
| 411 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 412 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 413 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 417 | - /** |
|
| 418 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 419 | - * @var int Nombre de caractères */ |
|
| 420 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 424 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 428 | - /** Définit le doctype de l’espace privé */ |
|
| 429 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 430 | - } |
|
| 431 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 432 | - /** Définit le doctype de l’aide en ligne */ |
|
| 433 | - define( |
|
| 434 | - '_DOCTYPE_AIDE', |
|
| 435 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 440 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 441 | - * le script de l'espace public, alias index.php */ |
|
| 442 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 443 | - } |
|
| 444 | - if (!defined('_SPIP_PAGE')) { |
|
| 445 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 446 | - define('_SPIP_PAGE', 'page'); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - // le script de l'espace prive |
|
| 450 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 451 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 452 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 453 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 454 | - if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 455 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 456 | - } else { |
|
| 457 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - if (!defined('_SPIP_AJAX')) { |
|
| 463 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 464 | - ? 1 |
|
| 465 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // La requete est-elle en ajax ? |
|
| 469 | - if (!defined('_AJAX')) { |
|
| 470 | - define( |
|
| 471 | - '_AJAX', |
|
| 472 | - ( |
|
| 473 | - isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 474 | - || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 475 | - || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 476 | - || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 477 | - ) |
|
| 478 | - && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 483 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 484 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 485 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 486 | - define( |
|
| 487 | - '_IMG_GD_MAX_PIXELS', |
|
| 488 | - (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 489 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 490 | - : 0 |
|
| 491 | - ); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Protocoles a normaliser dans les chaines de langues |
|
| 495 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 496 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - init_var_mode(); |
|
| 348 | + static $too_late = 0; |
|
| 349 | + if ($too_late++) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // taille mini des login |
|
| 354 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 355 | + define('_LOGIN_TROP_COURT', 4); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 359 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 360 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 361 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 362 | + |
|
| 363 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 364 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 365 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 366 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 367 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 368 | + |
|
| 369 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 370 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // largeur maximale des images dans l'administration |
|
| 374 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 375 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 379 | + if (!defined('_IMG_QUALITE')) { |
|
| 380 | + define('_IMG_QUALITE', 85); |
|
| 381 | + } # valeur par defaut |
|
| 382 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 383 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 384 | + } # surcharge pour la lib GD |
|
| 385 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 386 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 387 | + } # surcharge pour imagick en ligne de commande |
|
| 388 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 389 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 390 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 391 | + } # surcharge pour imagick en PHP |
|
| 392 | + |
|
| 393 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 394 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 395 | + } // poids en octet |
|
| 396 | + |
|
| 397 | + // qq chaines standard |
|
| 398 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 399 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 400 | + } |
|
| 401 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 402 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 403 | + } |
|
| 404 | + if (!defined('_SPIP_DUMP')) { |
|
| 405 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 406 | + } |
|
| 407 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 408 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 409 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 410 | + } |
|
| 411 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 412 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 413 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 417 | + /** |
|
| 418 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 419 | + * @var int Nombre de caractères */ |
|
| 420 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 424 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 428 | + /** Définit le doctype de l’espace privé */ |
|
| 429 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 430 | + } |
|
| 431 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 432 | + /** Définit le doctype de l’aide en ligne */ |
|
| 433 | + define( |
|
| 434 | + '_DOCTYPE_AIDE', |
|
| 435 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 440 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 441 | + * le script de l'espace public, alias index.php */ |
|
| 442 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 443 | + } |
|
| 444 | + if (!defined('_SPIP_PAGE')) { |
|
| 445 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 446 | + define('_SPIP_PAGE', 'page'); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + // le script de l'espace prive |
|
| 450 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 451 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 452 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 453 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 454 | + if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 455 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 456 | + } else { |
|
| 457 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + if (!defined('_SPIP_AJAX')) { |
|
| 463 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 464 | + ? 1 |
|
| 465 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // La requete est-elle en ajax ? |
|
| 469 | + if (!defined('_AJAX')) { |
|
| 470 | + define( |
|
| 471 | + '_AJAX', |
|
| 472 | + ( |
|
| 473 | + isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 474 | + || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 475 | + || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 476 | + || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 477 | + ) |
|
| 478 | + && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 483 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 484 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 485 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 486 | + define( |
|
| 487 | + '_IMG_GD_MAX_PIXELS', |
|
| 488 | + (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 489 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 490 | + : 0 |
|
| 491 | + ); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Protocoles a normaliser dans les chaines de langues |
|
| 495 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 496 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + init_var_mode(); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -530,133 +530,133 @@ discard block |
||
| 530 | 530 | * ` var_mode` (calcul ou recalcul). |
| 531 | 531 | */ |
| 532 | 532 | function init_var_mode() { |
| 533 | - static $done = false; |
|
| 534 | - if (!$done) { |
|
| 535 | - if (isset($_GET['var_mode'])) { |
|
| 536 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 537 | - // tout le monde peut calcul/recalcul |
|
| 538 | - if (!defined('_VAR_MODE')) { |
|
| 539 | - if (in_array('recalcul', $var_mode)) { |
|
| 540 | - define('_VAR_MODE', 'recalcul'); |
|
| 541 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 542 | - define('_VAR_MODE', 'calcul'); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 546 | - if ($var_mode) { |
|
| 547 | - include_spip('inc/autoriser'); |
|
| 548 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 549 | - if ( |
|
| 550 | - autoriser( |
|
| 551 | - ($_GET['var_mode'] == 'preview') |
|
| 552 | - ? 'previsualiser' |
|
| 553 | - : 'debug' |
|
| 554 | - ) |
|
| 555 | - ) { |
|
| 556 | - if (in_array('traduction', $var_mode)) { |
|
| 557 | - // forcer le calcul pour passer dans traduire |
|
| 558 | - if (!defined('_VAR_MODE')) { |
|
| 559 | - define('_VAR_MODE', 'calcul'); |
|
| 560 | - } |
|
| 561 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 562 | - if (!defined('_VAR_NOCACHE')) { |
|
| 563 | - define('_VAR_NOCACHE', true); |
|
| 564 | - } |
|
| 565 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 566 | - } |
|
| 567 | - if (in_array('preview', $var_mode)) { |
|
| 568 | - // basculer sur les criteres de preview dans les boucles |
|
| 569 | - if (!defined('_VAR_PREVIEW')) { |
|
| 570 | - define('_VAR_PREVIEW', true); |
|
| 571 | - } |
|
| 572 | - // forcer le calcul |
|
| 573 | - if (!defined('_VAR_MODE')) { |
|
| 574 | - define('_VAR_MODE', 'calcul'); |
|
| 575 | - } |
|
| 576 | - // et ne pas enregistrer de cache |
|
| 577 | - if (!defined('_VAR_NOCACHE')) { |
|
| 578 | - define('_VAR_NOCACHE', true); |
|
| 579 | - } |
|
| 580 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 581 | - } |
|
| 582 | - if (in_array('inclure', $var_mode)) { |
|
| 583 | - // forcer le compilo et ignorer les caches existants |
|
| 584 | - if (!defined('_VAR_MODE')) { |
|
| 585 | - define('_VAR_MODE', 'calcul'); |
|
| 586 | - } |
|
| 587 | - if (!defined('_VAR_INCLURE')) { |
|
| 588 | - define('_VAR_INCLURE', true); |
|
| 589 | - } |
|
| 590 | - // et ne pas enregistrer de cache |
|
| 591 | - if (!defined('_VAR_NOCACHE')) { |
|
| 592 | - define('_VAR_NOCACHE', true); |
|
| 593 | - } |
|
| 594 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 595 | - } |
|
| 596 | - if (in_array('urls', $var_mode)) { |
|
| 597 | - // forcer le compilo et ignorer les caches existants |
|
| 598 | - if (!defined('_VAR_MODE')) { |
|
| 599 | - define('_VAR_MODE', 'calcul'); |
|
| 600 | - } |
|
| 601 | - if (!defined('_VAR_URLS')) { |
|
| 602 | - define('_VAR_URLS', true); |
|
| 603 | - } |
|
| 604 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 605 | - } |
|
| 606 | - if (in_array('images', $var_mode)) { |
|
| 607 | - // forcer le compilo et ignorer les caches existants |
|
| 608 | - if (!defined('_VAR_MODE')) { |
|
| 609 | - define('_VAR_MODE', 'calcul'); |
|
| 610 | - } |
|
| 611 | - // indiquer qu'on doit recalculer les images |
|
| 612 | - if (!defined('_VAR_IMAGES')) { |
|
| 613 | - define('_VAR_IMAGES', true); |
|
| 614 | - } |
|
| 615 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 616 | - } |
|
| 617 | - if (in_array('debug', $var_mode)) { |
|
| 618 | - if (!defined('_VAR_MODE')) { |
|
| 619 | - define('_VAR_MODE', 'debug'); |
|
| 620 | - } |
|
| 621 | - // et ne pas enregistrer de cache |
|
| 622 | - if (!defined('_VAR_NOCACHE')) { |
|
| 623 | - define('_VAR_NOCACHE', true); |
|
| 624 | - } |
|
| 625 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 626 | - } |
|
| 627 | - if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 628 | - define('_VAR_MODE', reset($var_mode)); |
|
| 629 | - } |
|
| 630 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 631 | - spip_logger()->info($GLOBALS['visiteur_session']['nom'] . ' ' . _VAR_MODE); |
|
| 632 | - } |
|
| 633 | - } // pas autorise ? |
|
| 634 | - else { |
|
| 635 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 636 | - if ( |
|
| 637 | - !$GLOBALS['visiteur_session'] |
|
| 638 | - && !empty($_SERVER['HTTP_HOST']) |
|
| 639 | - && !empty($_SERVER['REQUEST_METHOD']) |
|
| 640 | - && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 641 | - ) { |
|
| 642 | - $self = self('&', true); |
|
| 643 | - if (!str_contains($self, 'page=login')) { |
|
| 644 | - include_spip('inc/headers'); |
|
| 645 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 646 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - // sinon tant pis |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - if (!defined('_VAR_MODE')) { |
|
| 654 | - /** |
|
| 655 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 656 | - * @see init_var_mode() |
|
| 657 | - */ |
|
| 658 | - define('_VAR_MODE', false); |
|
| 659 | - } |
|
| 660 | - $done = true; |
|
| 661 | - } |
|
| 533 | + static $done = false; |
|
| 534 | + if (!$done) { |
|
| 535 | + if (isset($_GET['var_mode'])) { |
|
| 536 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 537 | + // tout le monde peut calcul/recalcul |
|
| 538 | + if (!defined('_VAR_MODE')) { |
|
| 539 | + if (in_array('recalcul', $var_mode)) { |
|
| 540 | + define('_VAR_MODE', 'recalcul'); |
|
| 541 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 542 | + define('_VAR_MODE', 'calcul'); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 546 | + if ($var_mode) { |
|
| 547 | + include_spip('inc/autoriser'); |
|
| 548 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 549 | + if ( |
|
| 550 | + autoriser( |
|
| 551 | + ($_GET['var_mode'] == 'preview') |
|
| 552 | + ? 'previsualiser' |
|
| 553 | + : 'debug' |
|
| 554 | + ) |
|
| 555 | + ) { |
|
| 556 | + if (in_array('traduction', $var_mode)) { |
|
| 557 | + // forcer le calcul pour passer dans traduire |
|
| 558 | + if (!defined('_VAR_MODE')) { |
|
| 559 | + define('_VAR_MODE', 'calcul'); |
|
| 560 | + } |
|
| 561 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 562 | + if (!defined('_VAR_NOCACHE')) { |
|
| 563 | + define('_VAR_NOCACHE', true); |
|
| 564 | + } |
|
| 565 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 566 | + } |
|
| 567 | + if (in_array('preview', $var_mode)) { |
|
| 568 | + // basculer sur les criteres de preview dans les boucles |
|
| 569 | + if (!defined('_VAR_PREVIEW')) { |
|
| 570 | + define('_VAR_PREVIEW', true); |
|
| 571 | + } |
|
| 572 | + // forcer le calcul |
|
| 573 | + if (!defined('_VAR_MODE')) { |
|
| 574 | + define('_VAR_MODE', 'calcul'); |
|
| 575 | + } |
|
| 576 | + // et ne pas enregistrer de cache |
|
| 577 | + if (!defined('_VAR_NOCACHE')) { |
|
| 578 | + define('_VAR_NOCACHE', true); |
|
| 579 | + } |
|
| 580 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 581 | + } |
|
| 582 | + if (in_array('inclure', $var_mode)) { |
|
| 583 | + // forcer le compilo et ignorer les caches existants |
|
| 584 | + if (!defined('_VAR_MODE')) { |
|
| 585 | + define('_VAR_MODE', 'calcul'); |
|
| 586 | + } |
|
| 587 | + if (!defined('_VAR_INCLURE')) { |
|
| 588 | + define('_VAR_INCLURE', true); |
|
| 589 | + } |
|
| 590 | + // et ne pas enregistrer de cache |
|
| 591 | + if (!defined('_VAR_NOCACHE')) { |
|
| 592 | + define('_VAR_NOCACHE', true); |
|
| 593 | + } |
|
| 594 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 595 | + } |
|
| 596 | + if (in_array('urls', $var_mode)) { |
|
| 597 | + // forcer le compilo et ignorer les caches existants |
|
| 598 | + if (!defined('_VAR_MODE')) { |
|
| 599 | + define('_VAR_MODE', 'calcul'); |
|
| 600 | + } |
|
| 601 | + if (!defined('_VAR_URLS')) { |
|
| 602 | + define('_VAR_URLS', true); |
|
| 603 | + } |
|
| 604 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 605 | + } |
|
| 606 | + if (in_array('images', $var_mode)) { |
|
| 607 | + // forcer le compilo et ignorer les caches existants |
|
| 608 | + if (!defined('_VAR_MODE')) { |
|
| 609 | + define('_VAR_MODE', 'calcul'); |
|
| 610 | + } |
|
| 611 | + // indiquer qu'on doit recalculer les images |
|
| 612 | + if (!defined('_VAR_IMAGES')) { |
|
| 613 | + define('_VAR_IMAGES', true); |
|
| 614 | + } |
|
| 615 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 616 | + } |
|
| 617 | + if (in_array('debug', $var_mode)) { |
|
| 618 | + if (!defined('_VAR_MODE')) { |
|
| 619 | + define('_VAR_MODE', 'debug'); |
|
| 620 | + } |
|
| 621 | + // et ne pas enregistrer de cache |
|
| 622 | + if (!defined('_VAR_NOCACHE')) { |
|
| 623 | + define('_VAR_NOCACHE', true); |
|
| 624 | + } |
|
| 625 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 626 | + } |
|
| 627 | + if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 628 | + define('_VAR_MODE', reset($var_mode)); |
|
| 629 | + } |
|
| 630 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 631 | + spip_logger()->info($GLOBALS['visiteur_session']['nom'] . ' ' . _VAR_MODE); |
|
| 632 | + } |
|
| 633 | + } // pas autorise ? |
|
| 634 | + else { |
|
| 635 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 636 | + if ( |
|
| 637 | + !$GLOBALS['visiteur_session'] |
|
| 638 | + && !empty($_SERVER['HTTP_HOST']) |
|
| 639 | + && !empty($_SERVER['REQUEST_METHOD']) |
|
| 640 | + && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 641 | + ) { |
|
| 642 | + $self = self('&', true); |
|
| 643 | + if (!str_contains($self, 'page=login')) { |
|
| 644 | + include_spip('inc/headers'); |
|
| 645 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 646 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + // sinon tant pis |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + if (!defined('_VAR_MODE')) { |
|
| 654 | + /** |
|
| 655 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 656 | + * @see init_var_mode() |
|
| 657 | + */ |
|
| 658 | + define('_VAR_MODE', false); |
|
| 659 | + } |
|
| 660 | + $done = true; |
|
| 661 | + } |
|
| 662 | 662 | } |
@@ -24,23 +24,23 @@ discard block |
||
| 24 | 24 | * Les paramètres du pipeline modifiés |
| 25 | 25 | **/ |
| 26 | 26 | function minipipe($fonc, &$val) { |
| 27 | - // fonction |
|
| 28 | - if (function_exists($fonc)) { |
|
| 29 | - $val = $fonc($val); |
|
| 30 | - } // Class::Methode |
|
| 31 | - else { |
|
| 32 | - if ( |
|
| 33 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 34 | - && ($methode = [$regs[1], $regs[2]]) |
|
| 35 | - && is_callable($methode) |
|
| 36 | - ) { |
|
| 37 | - $val = $methode($val); |
|
| 38 | - } else { |
|
| 39 | - spip_logger()->info("Erreur - '$fonc' non definie !"); |
|
| 40 | - } |
|
| 41 | - } |
|
| 27 | + // fonction |
|
| 28 | + if (function_exists($fonc)) { |
|
| 29 | + $val = $fonc($val); |
|
| 30 | + } // Class::Methode |
|
| 31 | + else { |
|
| 32 | + if ( |
|
| 33 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 34 | + && ($methode = [$regs[1], $regs[2]]) |
|
| 35 | + && is_callable($methode) |
|
| 36 | + ) { |
|
| 37 | + $val = $methode($val); |
|
| 38 | + } else { |
|
| 39 | + spip_logger()->info("Erreur - '$fonc' non definie !"); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $val; |
|
| 43 | + return $val; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -71,44 +71,44 @@ discard block |
||
| 71 | 71 | * Résultat |
| 72 | 72 | */ |
| 73 | 73 | function pipeline($action, $val = null) { |
| 74 | - static $charger; |
|
| 74 | + static $charger; |
|
| 75 | 75 | |
| 76 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 77 | - if (!$charger) { |
|
| 78 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 79 | - include_spip('inc/plugin'); |
|
| 80 | - // generer les fichiers php precompiles |
|
| 81 | - // de chargement des plugins et des pipelines |
|
| 82 | - actualise_plugins_actifs(); |
|
| 83 | - if (!($ok = @is_readable($charger))) { |
|
| 84 | - spip_logger()->info("fichier $charger pas cree"); |
|
| 85 | - } |
|
| 86 | - } |
|
| 76 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 77 | + if (!$charger) { |
|
| 78 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 79 | + include_spip('inc/plugin'); |
|
| 80 | + // generer les fichiers php precompiles |
|
| 81 | + // de chargement des plugins et des pipelines |
|
| 82 | + actualise_plugins_actifs(); |
|
| 83 | + if (!($ok = @is_readable($charger))) { |
|
| 84 | + spip_logger()->info("fichier $charger pas cree"); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - if ($ok) { |
|
| 89 | - include_once $charger; |
|
| 90 | - } |
|
| 91 | - } |
|
| 88 | + if ($ok) { |
|
| 89 | + include_once $charger; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - // appliquer notre fonction si elle existe |
|
| 94 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 95 | - if (function_exists($fonc)) { |
|
| 96 | - $val = $fonc($val); |
|
| 97 | - } else { |
|
| 98 | - // plantage ? |
|
| 99 | - spip_logger()->error("fonction $fonc absente : pipeline desactive"); |
|
| 100 | - } |
|
| 93 | + // appliquer notre fonction si elle existe |
|
| 94 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 95 | + if (function_exists($fonc)) { |
|
| 96 | + $val = $fonc($val); |
|
| 97 | + } else { |
|
| 98 | + // plantage ? |
|
| 99 | + spip_logger()->error("fonction $fonc absente : pipeline desactive"); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - // si le flux est une table avec 2 cle args&data |
|
| 103 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 104 | - // array_key_exists pour php 4.1.0 |
|
| 105 | - if ( |
|
| 106 | - is_array($val) |
|
| 107 | - && count($val) == 2 |
|
| 108 | - && array_key_exists('data', $val) |
|
| 109 | - ) { |
|
| 110 | - $val = $val['data']; |
|
| 111 | - } |
|
| 102 | + // si le flux est une table avec 2 cle args&data |
|
| 103 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 104 | + // array_key_exists pour php 4.1.0 |
|
| 105 | + if ( |
|
| 106 | + is_array($val) |
|
| 107 | + && count($val) == 2 |
|
| 108 | + && array_key_exists('data', $val) |
|
| 109 | + ) { |
|
| 110 | + $val = $val['data']; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $val; |
|
| 113 | + return $val; |
|
| 114 | 114 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * true si c'est le cas, false sinon. |
| 8 | 8 | */ |
| 9 | 9 | function test_espace_prive() { |
| 10 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 10 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -19,17 +19,17 @@ discard block |
||
| 19 | 19 | * @return bool |
| 20 | 20 | */ |
| 21 | 21 | function autoriser_sans_cookie($nom, $strict = false) { |
| 22 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 22 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 23 | 23 | |
| 24 | - if (in_array($nom, $autsanscookie)) { |
|
| 25 | - if (test_espace_prive()) { |
|
| 26 | - include_spip('base/connect_sql'); |
|
| 27 | - if (!$strict || !spip_connect()) { |
|
| 28 | - return true; |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - return false; |
|
| 24 | + if (in_array($nom, $autsanscookie)) { |
|
| 25 | + if (test_espace_prive()) { |
|
| 26 | + include_spip('base/connect_sql'); |
|
| 27 | + if (!$strict || !spip_connect()) { |
|
| 28 | + return true; |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + return false; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -43,64 +43,64 @@ discard block |
||
| 43 | 43 | * @return string|0|false |
| 44 | 44 | **/ |
| 45 | 45 | function verifier_visiteur() { |
| 46 | - @spip_initialisation_core( |
|
| 47 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 48 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 49 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 50 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 51 | - ); |
|
| 46 | + @spip_initialisation_core( |
|
| 47 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 48 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 49 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 50 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 54 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 55 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 56 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 57 | - $variables_session = ['session_nom', 'session_email']; |
|
| 58 | - foreach ($variables_session as $var) { |
|
| 59 | - if (_request($var) !== null) { |
|
| 60 | - $init = true; |
|
| 61 | - break; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (isset($init)) { |
|
| 65 | - #@spip_initialisation_suite(); |
|
| 66 | - $session = charger_fonction('session', 'inc'); |
|
| 67 | - $session(); |
|
| 68 | - include_spip('inc/texte'); |
|
| 69 | - foreach ($variables_session as $var) { |
|
| 70 | - if (($a = _request($var)) !== null) { |
|
| 71 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 75 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 76 | - } |
|
| 77 | - $session($GLOBALS['visiteur_session']); |
|
| 53 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 54 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 55 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 56 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 57 | + $variables_session = ['session_nom', 'session_email']; |
|
| 58 | + foreach ($variables_session as $var) { |
|
| 59 | + if (_request($var) !== null) { |
|
| 60 | + $init = true; |
|
| 61 | + break; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (isset($init)) { |
|
| 65 | + #@spip_initialisation_suite(); |
|
| 66 | + $session = charger_fonction('session', 'inc'); |
|
| 67 | + $session(); |
|
| 68 | + include_spip('inc/texte'); |
|
| 69 | + foreach ($variables_session as $var) { |
|
| 70 | + if (($a = _request($var)) !== null) { |
|
| 71 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 75 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 76 | + } |
|
| 77 | + $session($GLOBALS['visiteur_session']); |
|
| 78 | 78 | |
| 79 | - return 0; |
|
| 80 | - } |
|
| 79 | + return 0; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']); |
|
| 83 | - if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 84 | - $session = charger_fonction('session', 'inc'); |
|
| 85 | - if ($session()) { |
|
| 86 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 87 | - } |
|
| 88 | - if ($h && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 89 | - include_spip('inc/auth'); |
|
| 90 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 91 | - } |
|
| 92 | - if ($h) { |
|
| 93 | - $GLOBALS['visiteur_session'] = $h; |
|
| 82 | + $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']); |
|
| 83 | + if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 84 | + $session = charger_fonction('session', 'inc'); |
|
| 85 | + if ($session()) { |
|
| 86 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 87 | + } |
|
| 88 | + if ($h && isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 89 | + include_spip('inc/auth'); |
|
| 90 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 91 | + } |
|
| 92 | + if ($h) { |
|
| 93 | + $GLOBALS['visiteur_session'] = $h; |
|
| 94 | 94 | |
| 95 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 95 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 100 | - include_spip('inc/lang'); |
|
| 101 | - utiliser_langue_visiteur(); |
|
| 99 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 100 | + include_spip('inc/lang'); |
|
| 101 | + utiliser_langue_visiteur(); |
|
| 102 | 102 | |
| 103 | - return false; |
|
| 103 | + return false; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | |
@@ -118,18 +118,18 @@ discard block |
||
| 118 | 118 | * Identifiant de la session |
| 119 | 119 | **/ |
| 120 | 120 | function spip_session($force = false) { |
| 121 | - static $session; |
|
| 122 | - if ($force || !isset($session)) { |
|
| 123 | - $s = ''; |
|
| 124 | - if (!empty($GLOBALS['visiteur_session'])) { |
|
| 125 | - include_spip('inc/session'); |
|
| 126 | - $cookie = lire_cookie_session(); |
|
| 127 | - $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: ''); |
|
| 128 | - } |
|
| 129 | - $s = pipeline('definir_session', $s); |
|
| 130 | - $session = ($s ? substr(md5($s), 0, 8) : ''); |
|
| 131 | - } |
|
| 121 | + static $session; |
|
| 122 | + if ($force || !isset($session)) { |
|
| 123 | + $s = ''; |
|
| 124 | + if (!empty($GLOBALS['visiteur_session'])) { |
|
| 125 | + include_spip('inc/session'); |
|
| 126 | + $cookie = lire_cookie_session(); |
|
| 127 | + $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: ''); |
|
| 128 | + } |
|
| 129 | + $s = pipeline('definir_session', $s); |
|
| 130 | + $session = ($s ? substr(md5($s), 0, 8) : ''); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - #spip_logger()->info('session: '.$session); |
|
| 134 | - return $session; |
|
| 133 | + #spip_logger()->info('session: '.$session); |
|
| 134 | + return $session; |
|
| 135 | 135 | } |
@@ -13,61 +13,61 @@ discard block |
||
| 13 | 13 | * @param null|array $add List of «plugins» directories to add |
| 14 | 14 | */ |
| 15 | 15 | function spip_paths( |
| 16 | - null|array $add = null, |
|
| 16 | + null|array $add = null, |
|
| 17 | 17 | ): AggregatorInterface { |
| 18 | - static $paths = null; |
|
| 19 | - static $last_dossier_squelettes = null; |
|
| 20 | - |
|
| 21 | - $dossier_squelettes = $GLOBALS['dossier_squelettes'] ?? null; |
|
| 22 | - |
|
| 23 | - if ($paths === null) { |
|
| 24 | - $paths = new GroupAggregator(Group::cases(), _ROOT_CWD); |
|
| 25 | - $paths = $paths->with(Group::App, [ |
|
| 26 | - _DIR_RACINE, |
|
| 27 | - _DIR_RACINE . 'squelettes-dist/', |
|
| 28 | - _DIR_RACINE . 'prive/', |
|
| 29 | - _DIR_RESTREINT, |
|
| 30 | - ]); |
|
| 31 | - |
|
| 32 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 33 | - $paths = $paths->with(Group::Templates, [_DIR_RACINE . 'squelettes']); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - if ($add !== null) { |
|
| 38 | - $paths = $paths->prepend(Group::Plugins, $add); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($last_dossier_squelettes !== $dossier_squelettes) { |
|
| 42 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 43 | - if ($dossier_squelettes !== '') { |
|
| 44 | - $ds = explode(':', $dossier_squelettes); |
|
| 45 | - foreach ($ds as $key => $directory) { |
|
| 46 | - if (!str_starts_with($directory, '/')) { |
|
| 47 | - $ds[$key] = _DIR_RACINE . $directory; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $paths = $paths->with(Group::ExtraTemplates, $ds); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $paths; |
|
| 18 | + static $paths = null; |
|
| 19 | + static $last_dossier_squelettes = null; |
|
| 20 | + |
|
| 21 | + $dossier_squelettes = $GLOBALS['dossier_squelettes'] ?? null; |
|
| 22 | + |
|
| 23 | + if ($paths === null) { |
|
| 24 | + $paths = new GroupAggregator(Group::cases(), _ROOT_CWD); |
|
| 25 | + $paths = $paths->with(Group::App, [ |
|
| 26 | + _DIR_RACINE, |
|
| 27 | + _DIR_RACINE . 'squelettes-dist/', |
|
| 28 | + _DIR_RACINE . 'prive/', |
|
| 29 | + _DIR_RESTREINT, |
|
| 30 | + ]); |
|
| 31 | + |
|
| 32 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 33 | + $paths = $paths->with(Group::Templates, [_DIR_RACINE . 'squelettes']); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + if ($add !== null) { |
|
| 38 | + $paths = $paths->prepend(Group::Plugins, $add); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($last_dossier_squelettes !== $dossier_squelettes) { |
|
| 42 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 43 | + if ($dossier_squelettes !== '') { |
|
| 44 | + $ds = explode(':', $dossier_squelettes); |
|
| 45 | + foreach ($ds as $key => $directory) { |
|
| 46 | + if (!str_starts_with($directory, '/')) { |
|
| 47 | + $ds[$key] = _DIR_RACINE . $directory; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $paths = $paths->with(Group::ExtraTemplates, $ds); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $paths; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function spip_paths_loader(): Loader { |
| 58 | - static $loaders = []; |
|
| 59 | - static $cache = null; |
|
| 58 | + static $loaders = []; |
|
| 59 | + static $cache = null; |
|
| 60 | 60 | |
| 61 | - if ($cache === null) { |
|
| 62 | - $cache = new FlatFilesystem('paths', Path::makeAbsolute(_DIR_CACHE, _ROOT_CWD)); |
|
| 63 | - if (_request('var_mode')) { |
|
| 64 | - $cache->clear(); |
|
| 65 | - } |
|
| 66 | - } |
|
| 61 | + if ($cache === null) { |
|
| 62 | + $cache = new FlatFilesystem('paths', Path::makeAbsolute(_DIR_CACHE, _ROOT_CWD)); |
|
| 63 | + if (_request('var_mode')) { |
|
| 64 | + $cache->clear(); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $paths = spip_paths(); |
|
| 68 | + $paths = spip_paths(); |
|
| 69 | 69 | |
| 70 | - return $loaders[$paths->getHash()] ??= new Loader($paths, $cache); |
|
| 70 | + return $loaders[$paths->getHash()] ??= new Loader($paths, $cache); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Liste des chemins, par ordre de priorité. |
| 103 | 103 | **/ |
| 104 | 104 | function _chemin(string|array|null $dir_path = null): array { |
| 105 | - if (is_array($dir_path) || (is_string($dir_path) && strlen($dir_path))) { |
|
| 106 | - spip_paths(add: is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 107 | - } |
|
| 105 | + if (is_array($dir_path) || (is_string($dir_path) && strlen($dir_path))) { |
|
| 106 | + spip_paths(add: is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return creer_chemin(); |
|
| 109 | + return creer_chemin(); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * @return array Liste de chemins |
| 116 | 116 | **/ |
| 117 | 117 | function creer_chemin(): array { |
| 118 | - $dirs = spip_paths()->getDirectories(); |
|
| 119 | - // canal historique: avec / sauf si '' |
|
| 120 | - return array_map(fn ($dir) => $dir === '' ? $dir : $dir . DIRECTORY_SEPARATOR, $dirs); |
|
| 118 | + $dirs = spip_paths()->getDirectories(); |
|
| 119 | + // canal historique: avec / sauf si '' |
|
| 120 | + return array_map(fn ($dir) => $dir === '' ? $dir : $dir . DIRECTORY_SEPARATOR, $dirs); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -128,61 +128,61 @@ discard block |
||
| 128 | 128 | * @return string[] Nom des thèmes. |
| 129 | 129 | */ |
| 130 | 130 | function lister_themes_prives(): array { |
| 131 | - static $themes = null; |
|
| 132 | - if (is_null($themes)) { |
|
| 133 | - // si pas encore definie |
|
| 134 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 135 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 136 | - } |
|
| 137 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 138 | - // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 139 | - // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 140 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 141 | - if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 142 | - $prefs = unserialize($prefs); |
|
| 143 | - } else { |
|
| 144 | - $prefs = []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 148 | - if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 149 | - // placer le theme choisi en tete |
|
| 150 | - array_unshift($themes, $theme); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $themes; |
|
| 131 | + static $themes = null; |
|
| 132 | + if (is_null($themes)) { |
|
| 133 | + // si pas encore definie |
|
| 134 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 135 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 136 | + } |
|
| 137 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 138 | + // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 139 | + // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 140 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 141 | + if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 142 | + $prefs = unserialize($prefs); |
|
| 143 | + } else { |
|
| 144 | + $prefs = []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 148 | + if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 149 | + // placer le theme choisi en tete |
|
| 150 | + array_unshift($themes, $theme); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $themes; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function find_in_theme($file, $subdir = '', $include = false) { |
| 158 | - static $themefiles = []; |
|
| 159 | - if (isset($themefiles["$subdir$file"])) { |
|
| 160 | - return $themefiles["$subdir$file"]; |
|
| 161 | - } |
|
| 162 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 163 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 164 | - if ( |
|
| 165 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 166 | - && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 167 | - && ($f = find_in_theme("$file_svg_generique")) |
|
| 168 | - ) { |
|
| 169 | - if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 170 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 171 | - } |
|
| 172 | - else { |
|
| 173 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $themes = lister_themes_prives(); |
|
| 178 | - foreach ($themes as $theme) { |
|
| 179 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 180 | - return $themefiles["$subdir$file"] = $f; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - spip_logger('theme')->info("$file introuvable dans le theme prive " . reset($themes)); |
|
| 184 | - |
|
| 185 | - return $themefiles["$subdir$file"] = ''; |
|
| 158 | + static $themefiles = []; |
|
| 159 | + if (isset($themefiles["$subdir$file"])) { |
|
| 160 | + return $themefiles["$subdir$file"]; |
|
| 161 | + } |
|
| 162 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 163 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 164 | + if ( |
|
| 165 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 166 | + && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 167 | + && ($f = find_in_theme("$file_svg_generique")) |
|
| 168 | + ) { |
|
| 169 | + if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 170 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 171 | + } |
|
| 172 | + else { |
|
| 173 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $themes = lister_themes_prives(); |
|
| 178 | + foreach ($themes as $theme) { |
|
| 179 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 180 | + return $themefiles["$subdir$file"] = $f; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + spip_logger('theme')->info("$file introuvable dans le theme prive " . reset($themes)); |
|
| 184 | + |
|
| 185 | + return $themefiles["$subdir$file"] = ''; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -206,31 +206,31 @@ discard block |
||
| 206 | 206 | * sinon chaîne vide. |
| 207 | 207 | **/ |
| 208 | 208 | function chemin_image($icone) { |
| 209 | - static $icone_renommer; |
|
| 210 | - if ($p = strpos($icone, '?')) { |
|
| 211 | - $icone = substr($icone, 0, $p); |
|
| 212 | - } |
|
| 213 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 214 | - if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 215 | - return $icone; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 219 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 220 | - return $f; |
|
| 221 | - } |
|
| 222 | - // sinon passer par le module de renommage |
|
| 223 | - if (is_null($icone_renommer)) { |
|
| 224 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 225 | - } |
|
| 226 | - if ($icone_renommer) { |
|
| 227 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 228 | - if (file_exists($icone)) { |
|
| 229 | - return $icone; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 209 | + static $icone_renommer; |
|
| 210 | + if ($p = strpos($icone, '?')) { |
|
| 211 | + $icone = substr($icone, 0, $p); |
|
| 212 | + } |
|
| 213 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 214 | + if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 215 | + return $icone; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 219 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 220 | + return $f; |
|
| 221 | + } |
|
| 222 | + // sinon passer par le module de renommage |
|
| 223 | + if (is_null($icone_renommer)) { |
|
| 224 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 225 | + } |
|
| 226 | + if ($icone_renommer) { |
|
| 227 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 228 | + if (file_exists($icone)) { |
|
| 229 | + return $icone; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -262,38 +262,38 @@ discard block |
||
| 262 | 262 | **/ |
| 263 | 263 | function find_in_path(string $file, string $dirname = '', bool|string $include = false): ?string { |
| 264 | 264 | |
| 265 | - $loader = spip_paths_loader(); |
|
| 265 | + $loader = spip_paths_loader(); |
|
| 266 | 266 | |
| 267 | - if ($dirname) { |
|
| 268 | - $file = rtrim($dirname, '/') . '/' . $file; |
|
| 269 | - } |
|
| 267 | + if ($dirname) { |
|
| 268 | + $file = rtrim($dirname, '/') . '/' . $file; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - $path = $loader->get($file); |
|
| 272 | - // find in path retourne des chemins relatif, si possible |
|
| 273 | - if ($path !== null && str_starts_with($path, _ROOT_RACINE)) { |
|
| 274 | - $path = _DIR_RACINE . substr($path, strlen(_ROOT_RACINE)); |
|
| 275 | - } |
|
| 271 | + $path = $loader->get($file); |
|
| 272 | + // find in path retourne des chemins relatif, si possible |
|
| 273 | + if ($path !== null && str_starts_with($path, _ROOT_RACINE)) { |
|
| 274 | + $path = _DIR_RACINE . substr($path, strlen(_ROOT_RACINE)); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - if ($include === false) { |
|
| 278 | - return $path; |
|
| 279 | - } |
|
| 277 | + if ($include === false) { |
|
| 278 | + return $path; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - if ($include === true) { |
|
| 282 | - if ($path === null) { |
|
| 283 | - return null; |
|
| 284 | - } |
|
| 285 | - return $loader->include($file) ? $path : null; |
|
| 286 | - } |
|
| 281 | + if ($include === true) { |
|
| 282 | + if ($path === null) { |
|
| 283 | + return null; |
|
| 284 | + } |
|
| 285 | + return $loader->include($file) ? $path : null; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if ($include === 'required') { |
|
| 289 | - return $loader->require($file) ? $path : null; |
|
| 290 | - } |
|
| 288 | + if ($include === 'required') { |
|
| 289 | + return $loader->require($file) ? $path : null; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - throw new \InvalidArgumentException(sprintf('$include argument with "%s" value is incorrect.', $include)); |
|
| 292 | + throw new \InvalidArgumentException(sprintf('$include argument with "%s" value is incorrect.', $include)); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | function clear_path_cache() { |
| 296 | - spip_paths_loader()->getCache()->clear(); |
|
| 296 | + spip_paths_loader()->getCache()->clear(); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | function load_path_cache() { |
@@ -320,31 +320,31 @@ discard block |
||
| 320 | 320 | * @return array |
| 321 | 321 | */ |
| 322 | 322 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 323 | - $liste_fichiers = []; |
|
| 324 | - $maxfiles = 10000; |
|
| 325 | - |
|
| 326 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 327 | - // on a pas encore inclus flock.php |
|
| 328 | - if (!function_exists('preg_files')) { |
|
| 329 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // Parcourir le chemin |
|
| 333 | - foreach (creer_chemin() as $d) { |
|
| 334 | - $f = $d . $dir; |
|
| 335 | - if (@is_dir($f)) { |
|
| 336 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 337 | - foreach ($liste as $chemin) { |
|
| 338 | - $nom = basename($chemin); |
|
| 339 | - // ne prendre que les fichiers pas deja trouves |
|
| 340 | - // car find_in_path prend le premier qu'il trouve, |
|
| 341 | - // les autres sont donc masques |
|
| 342 | - if (!isset($liste_fichiers[$nom])) { |
|
| 343 | - $liste_fichiers[$nom] = $chemin; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - return $liste_fichiers; |
|
| 323 | + $liste_fichiers = []; |
|
| 324 | + $maxfiles = 10000; |
|
| 325 | + |
|
| 326 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 327 | + // on a pas encore inclus flock.php |
|
| 328 | + if (!function_exists('preg_files')) { |
|
| 329 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // Parcourir le chemin |
|
| 333 | + foreach (creer_chemin() as $d) { |
|
| 334 | + $f = $d . $dir; |
|
| 335 | + if (@is_dir($f)) { |
|
| 336 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 337 | + foreach ($liste as $chemin) { |
|
| 338 | + $nom = basename($chemin); |
|
| 339 | + // ne prendre que les fichiers pas deja trouves |
|
| 340 | + // car find_in_path prend le premier qu'il trouve, |
|
| 341 | + // les autres sont donc masques |
|
| 342 | + if (!isset($liste_fichiers[$nom])) { |
|
| 343 | + $liste_fichiers[$nom] = $chemin; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + return $liste_fichiers; |
|
| 350 | 350 | } |