@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,77 +237,77 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - if ($excep) { |
|
| 258 | - $joker = false; // indiquer a l'appelant |
|
| 259 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | - } // pas d'alias. Le champ existe t'il ? |
|
| 261 | - else { |
|
| 262 | - // le champ est réellement présent, on le prend. |
|
| 263 | - if (isset($desc['field'][$nom_champ])) { |
|
| 264 | - $t = $boucles[$idb]->id_table; |
|
| 265 | - $joker = false; // indiquer a l'appelant |
|
| 266 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | - } |
|
| 268 | - // Tous les champs sont-ils acceptés ? |
|
| 269 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | - elseif ( |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + if ($excep) { |
|
| 258 | + $joker = false; // indiquer a l'appelant |
|
| 259 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | + } // pas d'alias. Le champ existe t'il ? |
|
| 261 | + else { |
|
| 262 | + // le champ est réellement présent, on le prend. |
|
| 263 | + if (isset($desc['field'][$nom_champ])) { |
|
| 264 | + $t = $boucles[$idb]->id_table; |
|
| 265 | + $joker = false; // indiquer a l'appelant |
|
| 266 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | + } |
|
| 268 | + // Tous les champs sont-ils acceptés ? |
|
| 269 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | + elseif ( |
|
| 274 | 274 | /*$joker AND */ |
| 275 | - isset($desc['field']['*']) |
|
| 276 | - ) { |
|
| 277 | - $joker = true; // indiquer a l'appelant |
|
| 278 | - return [$nom_champ, $nom_champ]; |
|
| 279 | - } |
|
| 280 | - // pas d'alias, pas de champ, pas de joker... |
|
| 281 | - // tenter via une jointure... |
|
| 282 | - else { |
|
| 283 | - $joker = false; // indiquer a l'appelant |
|
| 284 | - // regarder si le champ est deja dans une jointure existante |
|
| 285 | - // sinon, si il y a des joitures explicites, la construire |
|
| 286 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | - // mais est-ce ce qu'on veut ? |
|
| 291 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($t) { |
|
| 298 | - // si on a trouvé une jointure possible, on fait comme |
|
| 299 | - // si c'était une exception pour le champ demandé |
|
| 300 | - return index_exception( |
|
| 301 | - $boucles[$idb], |
|
| 302 | - $desc, |
|
| 303 | - $nom_champ, |
|
| 304 | - [$t[1]['id_table'], reset($t[2])] |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return ['', '']; |
|
| 309 | - } |
|
| 310 | - } |
|
| 275 | + isset($desc['field']['*']) |
|
| 276 | + ) { |
|
| 277 | + $joker = true; // indiquer a l'appelant |
|
| 278 | + return [$nom_champ, $nom_champ]; |
|
| 279 | + } |
|
| 280 | + // pas d'alias, pas de champ, pas de joker... |
|
| 281 | + // tenter via une jointure... |
|
| 282 | + else { |
|
| 283 | + $joker = false; // indiquer a l'appelant |
|
| 284 | + // regarder si le champ est deja dans une jointure existante |
|
| 285 | + // sinon, si il y a des joitures explicites, la construire |
|
| 286 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | + // mais est-ce ce qu'on veut ? |
|
| 291 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($t) { |
|
| 298 | + // si on a trouvé une jointure possible, on fait comme |
|
| 299 | + // si c'était une exception pour le champ demandé |
|
| 300 | + return index_exception( |
|
| 301 | + $boucles[$idb], |
|
| 302 | + $desc, |
|
| 303 | + $nom_champ, |
|
| 304 | + [$t[1]['id_table'], reset($t[2])] |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return ['', '']; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -335,52 +335,52 @@ discard block |
||
| 335 | 335 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 336 | 336 | **/ |
| 337 | 337 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 338 | - static $trouver_table; |
|
| 339 | - if (!$trouver_table) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - if (is_array($excep)) { |
|
| 344 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | - $t = null; |
|
| 346 | - if (count($excep) == 3) { |
|
| 347 | - $index_exception_derogatoire = array_pop($excep); |
|
| 348 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | - } |
|
| 350 | - if ($t == null) { |
|
| 351 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | - if (!$j) { |
|
| 355 | - return ['', '']; |
|
| 356 | - } |
|
| 357 | - $e = $j['table']; |
|
| 358 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | - $k = $j['key']['PRIMARY KEY']; |
|
| 360 | - if (strpos($k, ',')) { |
|
| 361 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | - if (!in_array($k, $l)) { |
|
| 364 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | - |
|
| 366 | - return ['', '']; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | - fabrique_jointures($boucle, [$k]); |
|
| 371 | - $t = array_search($e, $boucle->from); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } else { |
|
| 375 | - $t = $boucle->id_table; |
|
| 376 | - } |
|
| 377 | - // demander a SQL de gerer le synonyme |
|
| 378 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | - if ($excep != $nom_champ) { |
|
| 380 | - $excep .= ' AS ' . $nom_champ; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return ["$t.$excep", $nom_champ]; |
|
| 338 | + static $trouver_table; |
|
| 339 | + if (!$trouver_table) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + if (is_array($excep)) { |
|
| 344 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | + $t = null; |
|
| 346 | + if (count($excep) == 3) { |
|
| 347 | + $index_exception_derogatoire = array_pop($excep); |
|
| 348 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | + } |
|
| 350 | + if ($t == null) { |
|
| 351 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | + if (!$j) { |
|
| 355 | + return ['', '']; |
|
| 356 | + } |
|
| 357 | + $e = $j['table']; |
|
| 358 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | + $k = $j['key']['PRIMARY KEY']; |
|
| 360 | + if (strpos($k, ',')) { |
|
| 361 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | + if (!in_array($k, $l)) { |
|
| 364 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | + |
|
| 366 | + return ['', '']; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | + fabrique_jointures($boucle, [$k]); |
|
| 371 | + $t = array_search($e, $boucle->from); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } else { |
|
| 375 | + $t = $boucle->id_table; |
|
| 376 | + } |
|
| 377 | + // demander a SQL de gerer le synonyme |
|
| 378 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | + if ($excep != $nom_champ) { |
|
| 380 | + $excep .= ' AS ' . $nom_champ; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return ["$t.$excep", $nom_champ]; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * Code PHP pour retrouver le champ |
| 406 | 406 | */ |
| 407 | 407 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 408 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 408 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 426 | 426 | **/ |
| 427 | 427 | function calculer_champ($p) { |
| 428 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 428 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 429 | 429 | |
| 430 | - return applique_filtres($p); |
|
| 430 | + return applique_filtres($p); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_balise(string $nom, \Champ $p): \Champ { |
| 466 | 466 | |
| 467 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | - $p->balise_calculee = true; |
|
| 470 | - $res = $f($p); |
|
| 471 | - if ($res !== null and is_object($res)) { |
|
| 472 | - return $res; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Certaines des balises comportant un _ sont generiques |
|
| 477 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | - $res = $balise_generique['fonction_generique']($p); |
|
| 479 | - if ($res !== null and is_object($res)) { |
|
| 480 | - return $res; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | - |
|
| 486 | - return $f($nom, $p); |
|
| 467 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | + $p->balise_calculee = true; |
|
| 470 | + $res = $f($p); |
|
| 471 | + if ($res !== null and is_object($res)) { |
|
| 472 | + return $res; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Certaines des balises comportant un _ sont generiques |
|
| 477 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | + $res = $balise_generique['fonction_generique']($p); |
|
| 479 | + if ($res !== null and is_object($res)) { |
|
| 480 | + return $res; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | + |
|
| 486 | + return $f($nom, $p); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -511,37 +511,37 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 513 | 513 | |
| 514 | - // ca pourrait etre un champ SQL homonyme, |
|
| 515 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | - |
|
| 517 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | - $code = addslashes($p->fonctions[0][1]); |
|
| 521 | - $p->code .= " . '$code'"; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | - if (strpos($nom, 'ID_') === 0) { |
|
| 526 | - $p->interdire_scripts = false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | - // SI le champ SQL n'est pas trouve |
|
| 531 | - // ET si la balise a une forme de couleur |
|
| 532 | - // ET s'il n'y a ni filtre ni etoile |
|
| 533 | - // ALORS retourner la couleur. |
|
| 534 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | - if ( |
|
| 536 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | - and !$p->etoile |
|
| 538 | - and !$p->fonctions |
|
| 539 | - ) { |
|
| 540 | - $p->code = "'#$nom'"; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return $p; |
|
| 514 | + // ca pourrait etre un champ SQL homonyme, |
|
| 515 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | + |
|
| 517 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | + $code = addslashes($p->fonctions[0][1]); |
|
| 521 | + $p->code .= " . '$code'"; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | + if (strpos($nom, 'ID_') === 0) { |
|
| 526 | + $p->interdire_scripts = false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | + // SI le champ SQL n'est pas trouve |
|
| 531 | + // ET si la balise a une forme de couleur |
|
| 532 | + // ET s'il n'y a ni filtre ni etoile |
|
| 533 | + // ALORS retourner la couleur. |
|
| 534 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | + if ( |
|
| 536 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | + and !$p->etoile |
|
| 538 | + and !$p->fonctions |
|
| 539 | + ) { |
|
| 540 | + $p->code = "'#$nom'"; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -584,39 +584,39 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 586 | 586 | |
| 587 | - if (!balise_distante_interdite($p)) { |
|
| 588 | - $p->code = "''"; |
|
| 589 | - |
|
| 590 | - return $p; |
|
| 591 | - } |
|
| 592 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | - $p->fonctions = null; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if ($p->param and ($c = $p->param[0])) { |
|
| 599 | - // liste d'arguments commence toujours par la chaine vide |
|
| 600 | - array_shift($c); |
|
| 601 | - // construire la liste d'arguments comme pour un filtre |
|
| 602 | - $param = compose_filtres_args($p, $c, ','); |
|
| 603 | - } else { |
|
| 604 | - $param = ''; |
|
| 605 | - } |
|
| 606 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | - |
|
| 608 | - $p->code = sprintf( |
|
| 609 | - CODE_EXECUTER_BALISE, |
|
| 610 | - $nom, |
|
| 611 | - join(',', $collecte), |
|
| 612 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | - memoriser_contexte_compil($p), |
|
| 614 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | - ); |
|
| 616 | - |
|
| 617 | - $p->interdire_scripts = false; |
|
| 618 | - |
|
| 619 | - return $p; |
|
| 587 | + if (!balise_distante_interdite($p)) { |
|
| 588 | + $p->code = "''"; |
|
| 589 | + |
|
| 590 | + return $p; |
|
| 591 | + } |
|
| 592 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | + $p->fonctions = null; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if ($p->param and ($c = $p->param[0])) { |
|
| 599 | + // liste d'arguments commence toujours par la chaine vide |
|
| 600 | + array_shift($c); |
|
| 601 | + // construire la liste d'arguments comme pour un filtre |
|
| 602 | + $param = compose_filtres_args($p, $c, ','); |
|
| 603 | + } else { |
|
| 604 | + $param = ''; |
|
| 605 | + } |
|
| 606 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | + |
|
| 608 | + $p->code = sprintf( |
|
| 609 | + CODE_EXECUTER_BALISE, |
|
| 610 | + $nom, |
|
| 611 | + join(',', $collecte), |
|
| 612 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | + memoriser_contexte_compil($p), |
|
| 614 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | + ); |
|
| 616 | + |
|
| 617 | + $p->interdire_scripts = false; |
|
| 618 | + |
|
| 619 | + return $p; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | |
@@ -646,17 +646,17 @@ discard block |
||
| 646 | 646 | * Liste des codes PHP d'éxecution des balises collectées |
| 647 | 647 | **/ |
| 648 | 648 | function collecter_balise_dynamique(array $l, \Champ &$p, string $nom): array { |
| 649 | - $args = []; |
|
| 650 | - foreach ($l as $c) { |
|
| 651 | - if ($c === null) { |
|
| 652 | - $args[] = 'null'; |
|
| 653 | - } else { |
|
| 654 | - $x = calculer_balise($c, $p); |
|
| 655 | - $args[] = $x->code; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - return $args; |
|
| 649 | + $args = []; |
|
| 650 | + foreach ($l as $c) { |
|
| 651 | + if ($c === null) { |
|
| 652 | + $args[] = 'null'; |
|
| 653 | + } else { |
|
| 654 | + $x = calculer_balise($c, $p); |
|
| 655 | + $args[] = $x->code; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + return $args; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | |
@@ -671,22 +671,22 @@ discard block |
||
| 671 | 671 | * Nom de la connexion |
| 672 | 672 | **/ |
| 673 | 673 | function trouver_nom_serveur_distant($p) { |
| 674 | - $nom = $p->id_boucle; |
|
| 675 | - if ( |
|
| 676 | - $nom |
|
| 677 | - and isset($p->boucles[$nom]) |
|
| 678 | - ) { |
|
| 679 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 680 | - if ( |
|
| 681 | - strlen($s) |
|
| 682 | - and strlen($serveur = strtolower($s)) |
|
| 683 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 684 | - ) { |
|
| 685 | - return $serveur; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return ''; |
|
| 674 | + $nom = $p->id_boucle; |
|
| 675 | + if ( |
|
| 676 | + $nom |
|
| 677 | + and isset($p->boucles[$nom]) |
|
| 678 | + ) { |
|
| 679 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 680 | + if ( |
|
| 681 | + strlen($s) |
|
| 682 | + and strlen($serveur = strtolower($s)) |
|
| 683 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 684 | + ) { |
|
| 685 | + return $serveur; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return ''; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | |
@@ -710,15 +710,15 @@ discard block |
||
| 710 | 710 | * - false : La balise est interdite car le serveur est distant |
| 711 | 711 | **/ |
| 712 | 712 | function balise_distante_interdite($p) { |
| 713 | - $nom = $p->id_boucle; |
|
| 713 | + $nom = $p->id_boucle; |
|
| 714 | 714 | |
| 715 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 716 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 715 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 716 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 717 | 717 | |
| 718 | - return false; |
|
| 719 | - } |
|
| 718 | + return false; |
|
| 719 | + } |
|
| 720 | 720 | |
| 721 | - return true; |
|
| 721 | + return true; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | |
@@ -729,84 +729,84 @@ discard block |
||
| 729 | 729 | // https://code.spip.net/@champs_traitements |
| 730 | 730 | function champs_traitements($p) { |
| 731 | 731 | |
| 732 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 733 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 734 | - } else { |
|
| 735 | - // quand on utilise un traitement catch-all * |
|
| 736 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 737 | - // leur propre securite |
|
| 738 | - if (!$p->balise_calculee) { |
|
| 739 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 740 | - } else { |
|
| 741 | - $ps = false; |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - if (is_array($ps)) { |
|
| 746 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 747 | - $idb = index_boucle($p); |
|
| 748 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 749 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 750 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 754 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 755 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 756 | - |
|
| 757 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 758 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 759 | - $type_alias = $type_requete; |
|
| 760 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 761 | - } else { |
|
| 762 | - $type_alias = false; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 766 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 767 | - $ps = $ps[$table_sql]; |
|
| 768 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 769 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 770 | - $ps = $ps[$type_requete]; |
|
| 771 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 772 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 773 | - $ps = $ps[$type_alias]; |
|
| 774 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 775 | - elseif (isset($ps[0])) { |
|
| 776 | - $ps = $ps[0]; |
|
| 777 | - } else { |
|
| 778 | - $ps = false; |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - if (!$ps) { |
|
| 783 | - return $p->code; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 787 | - // ou si in INCLURE contient {doublons} |
|
| 788 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 789 | - // dans les filtres propre() ou typo() |
|
| 790 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 791 | - |
|
| 792 | - if ( |
|
| 793 | - isset($p->descr['documents']) |
|
| 794 | - and |
|
| 795 | - $p->descr['documents'] |
|
| 796 | - and ( |
|
| 797 | - (strpos($ps, 'propre') !== false) |
|
| 798 | - or |
|
| 799 | - (strpos($ps, 'typo') !== false) |
|
| 800 | - ) |
|
| 801 | - ) { |
|
| 802 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 806 | - // dans la declaration des traitements des champs sensibles |
|
| 807 | - |
|
| 808 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 809 | - return str_replace('%s', $p->code, $ps); |
|
| 732 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 733 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 734 | + } else { |
|
| 735 | + // quand on utilise un traitement catch-all * |
|
| 736 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 737 | + // leur propre securite |
|
| 738 | + if (!$p->balise_calculee) { |
|
| 739 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 740 | + } else { |
|
| 741 | + $ps = false; |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + if (is_array($ps)) { |
|
| 746 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 747 | + $idb = index_boucle($p); |
|
| 748 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 749 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 750 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 754 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 755 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 756 | + |
|
| 757 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 758 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 759 | + $type_alias = $type_requete; |
|
| 760 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 761 | + } else { |
|
| 762 | + $type_alias = false; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 766 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 767 | + $ps = $ps[$table_sql]; |
|
| 768 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 769 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 770 | + $ps = $ps[$type_requete]; |
|
| 771 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 772 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 773 | + $ps = $ps[$type_alias]; |
|
| 774 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 775 | + elseif (isset($ps[0])) { |
|
| 776 | + $ps = $ps[0]; |
|
| 777 | + } else { |
|
| 778 | + $ps = false; |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + if (!$ps) { |
|
| 783 | + return $p->code; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 787 | + // ou si in INCLURE contient {doublons} |
|
| 788 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 789 | + // dans les filtres propre() ou typo() |
|
| 790 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 791 | + |
|
| 792 | + if ( |
|
| 793 | + isset($p->descr['documents']) |
|
| 794 | + and |
|
| 795 | + $p->descr['documents'] |
|
| 796 | + and ( |
|
| 797 | + (strpos($ps, 'propre') !== false) |
|
| 798 | + or |
|
| 799 | + (strpos($ps, 'typo') !== false) |
|
| 800 | + ) |
|
| 801 | + ) { |
|
| 802 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 806 | + // dans la declaration des traitements des champs sensibles |
|
| 807 | + |
|
| 808 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 809 | + return str_replace('%s', $p->code, $ps); |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | |
@@ -819,112 +819,112 @@ discard block |
||
| 819 | 819 | // https://code.spip.net/@applique_filtres |
| 820 | 820 | function applique_filtres($p) { |
| 821 | 821 | |
| 822 | - // Traitements standards (cf. supra) |
|
| 823 | - if ($p->etoile == '') { |
|
| 824 | - $code = champs_traitements($p); |
|
| 825 | - } else { |
|
| 826 | - $code = $p->code; |
|
| 827 | - } |
|
| 822 | + // Traitements standards (cf. supra) |
|
| 823 | + if ($p->etoile == '') { |
|
| 824 | + $code = champs_traitements($p); |
|
| 825 | + } else { |
|
| 826 | + $code = $p->code; |
|
| 827 | + } |
|
| 828 | 828 | |
| 829 | - // Appliquer les filtres perso |
|
| 830 | - if ($p->param) { |
|
| 831 | - $code = compose_filtres($p, $code); |
|
| 832 | - } |
|
| 829 | + // Appliquer les filtres perso |
|
| 830 | + if ($p->param) { |
|
| 831 | + $code = compose_filtres($p, $code); |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 835 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 836 | - if (isset($p->descr['session'])) { |
|
| 837 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 838 | - } |
|
| 834 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 835 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 836 | + if (isset($p->descr['session'])) { |
|
| 837 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 840 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 841 | 841 | |
| 842 | - return $code; |
|
| 842 | + return $code; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 846 | 846 | // https://code.spip.net/@compose_filtres |
| 847 | 847 | function compose_filtres(&$p, $code) { |
| 848 | 848 | |
| 849 | - $image_miette = false; |
|
| 850 | - foreach ($p->param as $filtre) { |
|
| 851 | - $fonc = array_shift($filtre); |
|
| 852 | - if (!$fonc) { |
|
| 853 | - continue; |
|
| 854 | - } // normalement qu'au premier tour. |
|
| 855 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 856 | - if ($image_miette and !$is_filtre_image) { |
|
| 857 | - // il faut graver maintenant car apres le filtre en cours |
|
| 858 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 859 | - $code = "filtrer('image_graver', $code)"; |
|
| 860 | - $image_miette = false; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // recuperer les arguments du filtre, |
|
| 864 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 865 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 866 | - if ($fonc !== '?') { |
|
| 867 | - $sep = ','; |
|
| 868 | - } else { |
|
| 869 | - $sep = ':'; |
|
| 870 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 871 | - if ($countfiltre != 2) { |
|
| 872 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 873 | - $countfiltre = 2; |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 877 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 878 | - if ($logique) { |
|
| 879 | - $code = $logique; |
|
| 880 | - } else { |
|
| 881 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 882 | - if ($is_filtre_image) { |
|
| 883 | - $image_miette = true; |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - } |
|
| 887 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 888 | - if ($image_miette) { |
|
| 889 | - $code = "filtrer('image_graver',$code)"; |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - return $code; |
|
| 849 | + $image_miette = false; |
|
| 850 | + foreach ($p->param as $filtre) { |
|
| 851 | + $fonc = array_shift($filtre); |
|
| 852 | + if (!$fonc) { |
|
| 853 | + continue; |
|
| 854 | + } // normalement qu'au premier tour. |
|
| 855 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 856 | + if ($image_miette and !$is_filtre_image) { |
|
| 857 | + // il faut graver maintenant car apres le filtre en cours |
|
| 858 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 859 | + $code = "filtrer('image_graver', $code)"; |
|
| 860 | + $image_miette = false; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // recuperer les arguments du filtre, |
|
| 864 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 865 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 866 | + if ($fonc !== '?') { |
|
| 867 | + $sep = ','; |
|
| 868 | + } else { |
|
| 869 | + $sep = ':'; |
|
| 870 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 871 | + if ($countfiltre != 2) { |
|
| 872 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 873 | + $countfiltre = 2; |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 877 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 878 | + if ($logique) { |
|
| 879 | + $code = $logique; |
|
| 880 | + } else { |
|
| 881 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 882 | + if ($is_filtre_image) { |
|
| 883 | + $image_miette = true; |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + } |
|
| 887 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 888 | + if ($image_miette) { |
|
| 889 | + $code = "filtrer('image_graver',$code)"; |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + return $code; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 896 | 896 | // et comparateurs |
| 897 | 897 | function filtre_logique($fonc, $code, $arg) { |
| 898 | 898 | |
| 899 | - switch (true) { |
|
| 900 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 901 | - return "($code $fonc $arg)"; |
|
| 902 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 903 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 904 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 905 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 906 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 907 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 908 | - case ($fonc == 'sinon'): |
|
| 909 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 910 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 911 | - return "(($code) ?'' :' ')"; |
|
| 912 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 913 | - return "(($code) ?' ' :'')"; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - return ''; |
|
| 899 | + switch (true) { |
|
| 900 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 901 | + return "($code $fonc $arg)"; |
|
| 902 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 903 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 904 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 905 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 906 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 907 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 908 | + case ($fonc == 'sinon'): |
|
| 909 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 910 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 911 | + return "(($code) ?'' :' ')"; |
|
| 912 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 913 | + return "(($code) ?' ' :'')"; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + return ''; |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | // https://code.spip.net/@compose_filtres_args |
| 920 | 920 | function compose_filtres_args($p, $args, $sep) { |
| 921 | - $arglist = ''; |
|
| 922 | - foreach ($args as $arg) { |
|
| 923 | - $arglist .= $sep . |
|
| 924 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 925 | - } |
|
| 921 | + $arglist = ''; |
|
| 922 | + foreach ($args as $arg) { |
|
| 923 | + $arglist .= $sep . |
|
| 924 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | - return $arglist; |
|
| 927 | + return $arglist; |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | |
@@ -942,15 +942,15 @@ discard block |
||
| 942 | 942 | **/ |
| 943 | 943 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 944 | 944 | |
| 945 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 946 | - if ($boucles[$idb]->externe) { |
|
| 947 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 948 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 949 | - // on ignore le defaut fourni dans ce cas |
|
| 950 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 951 | - } |
|
| 945 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 946 | + if ($boucles[$idb]->externe) { |
|
| 947 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 948 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 949 | + // on ignore le defaut fourni dans ce cas |
|
| 950 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 951 | + } |
|
| 952 | 952 | |
| 953 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 953 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | // |
@@ -965,30 +965,30 @@ discard block |
||
| 965 | 965 | |
| 966 | 966 | // https://code.spip.net/@rindex_pile |
| 967 | 967 | function rindex_pile($p, $champ, $motif) { |
| 968 | - $n = 0; |
|
| 969 | - $b = $p->id_boucle; |
|
| 970 | - $p->code = ''; |
|
| 971 | - while ($b != '') { |
|
| 972 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 973 | - if ($critere->op == $motif) { |
|
| 974 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 975 | - "]['$champ']"; |
|
| 976 | - $b = ''; |
|
| 977 | - break 2; |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - $n++; |
|
| 981 | - $b = $p->boucles[$b]->id_parent; |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 985 | - if (!$p->code) { |
|
| 986 | - $p->code = "''"; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - $p->interdire_scripts = false; |
|
| 990 | - |
|
| 991 | - return $p; |
|
| 968 | + $n = 0; |
|
| 969 | + $b = $p->id_boucle; |
|
| 970 | + $p->code = ''; |
|
| 971 | + while ($b != '') { |
|
| 972 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 973 | + if ($critere->op == $motif) { |
|
| 974 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 975 | + "]['$champ']"; |
|
| 976 | + $b = ''; |
|
| 977 | + break 2; |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + $n++; |
|
| 981 | + $b = $p->boucles[$b]->id_parent; |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 985 | + if (!$p->code) { |
|
| 986 | + $p->code = "''"; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + $p->interdire_scripts = false; |
|
| 990 | + |
|
| 991 | + return $p; |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 999 | 999 | */ |
| 1000 | 1000 | function zbug_presenter_champ($p, $champ = '') { |
| 1001 | - $balise = $champ ?: $p->nom_champ; |
|
| 1002 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1003 | - return "#{$explicite}{$balise}"; |
|
| 1001 | + $balise = $champ ?: $p->nom_champ; |
|
| 1002 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1003 | + return "#{$explicite}{$balise}"; |
|
| 1004 | 1004 | } |
@@ -11,164 +11,164 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect |
|
| 19 | - if (strpos($redirect, '%') !== false) { |
|
| 20 | - $r2 = urldecode($redirect); |
|
| 21 | - if (($r3 = securiser_redirect_action($r2)) !== $r2) { |
|
| 22 | - return $r3; |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - if ( |
|
| 26 | - (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 27 | - and !defined('_AUTORISER_ACTION_ABS_REDIRECT') |
|
| 28 | - ) { |
|
| 29 | - // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 30 | - // c'est encore le plus simple |
|
| 31 | - $base = $GLOBALS['meta']['adresse_site'] . '/'; |
|
| 32 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 33 | - return $redirect; |
|
| 34 | - } |
|
| 35 | - $base = url_de_base(); |
|
| 36 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 37 | - return $redirect; |
|
| 38 | - } |
|
| 18 | + // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect |
|
| 19 | + if (strpos($redirect, '%') !== false) { |
|
| 20 | + $r2 = urldecode($redirect); |
|
| 21 | + if (($r3 = securiser_redirect_action($r2)) !== $r2) { |
|
| 22 | + return $r3; |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + if ( |
|
| 26 | + (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 27 | + and !defined('_AUTORISER_ACTION_ABS_REDIRECT') |
|
| 28 | + ) { |
|
| 29 | + // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 30 | + // c'est encore le plus simple |
|
| 31 | + $base = $GLOBALS['meta']['adresse_site'] . '/'; |
|
| 32 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 33 | + return $redirect; |
|
| 34 | + } |
|
| 35 | + $base = url_de_base(); |
|
| 36 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 37 | + return $redirect; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return ''; |
|
| 41 | - } |
|
| 40 | + return ''; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $redirect; |
|
| 43 | + return $redirect; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // https://code.spip.net/@traiter_appels_actions |
| 47 | 47 | function traiter_appels_actions() { |
| 48 | - // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 49 | - if ($action = _request('action')) { |
|
| 50 | - include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 51 | - include_spip('inc/autoriser'); |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - include_spip('inc/actions'); |
|
| 54 | - // des actions peuvent appeler _T |
|
| 55 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 56 | - include_spip('inc/lang'); |
|
| 57 | - utiliser_langue_visiteur(); |
|
| 58 | - } |
|
| 59 | - // si l'action est provoque par un hit {ajax} |
|
| 60 | - // il faut transmettre l'env ajax au redirect |
|
| 61 | - // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 62 | - if ( |
|
| 63 | - ($v = _request('var_ajax')) |
|
| 64 | - and ($v !== 'form') |
|
| 65 | - and ($args = _request('var_ajax_env')) |
|
| 66 | - and ($url = _request('redirect')) |
|
| 67 | - ) { |
|
| 68 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 69 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 70 | - set_request('redirect', $url); |
|
| 71 | - } else { |
|
| 72 | - if (_request('redirect')) { |
|
| 73 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $var_f = charger_fonction($action, 'action'); |
|
| 77 | - $var_f(); |
|
| 78 | - if (!isset($GLOBALS['redirect'])) { |
|
| 79 | - $GLOBALS['redirect'] = _request('redirect') ?? ''; |
|
| 80 | - if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 81 | - $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 82 | - } |
|
| 83 | - $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 84 | - } |
|
| 85 | - if ($url = $GLOBALS['redirect']) { |
|
| 86 | - // si l'action est provoque par un hit {ajax} |
|
| 87 | - // il faut transmettre l'env ajax au redirect |
|
| 88 | - // qui a pu etre defini par l'action |
|
| 89 | - if ( |
|
| 90 | - ($v = _request('var_ajax')) |
|
| 91 | - and ($v !== 'form') |
|
| 92 | - and ($args = _request('var_ajax_env')) |
|
| 93 | - ) { |
|
| 94 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 95 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 96 | - // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 97 | - $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 98 | - } |
|
| 99 | - $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 100 | - redirige_par_entete($url); |
|
| 101 | - } |
|
| 48 | + // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 49 | + if ($action = _request('action')) { |
|
| 50 | + include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 51 | + include_spip('inc/autoriser'); |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + include_spip('inc/actions'); |
|
| 54 | + // des actions peuvent appeler _T |
|
| 55 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 56 | + include_spip('inc/lang'); |
|
| 57 | + utiliser_langue_visiteur(); |
|
| 58 | + } |
|
| 59 | + // si l'action est provoque par un hit {ajax} |
|
| 60 | + // il faut transmettre l'env ajax au redirect |
|
| 61 | + // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 62 | + if ( |
|
| 63 | + ($v = _request('var_ajax')) |
|
| 64 | + and ($v !== 'form') |
|
| 65 | + and ($args = _request('var_ajax_env')) |
|
| 66 | + and ($url = _request('redirect')) |
|
| 67 | + ) { |
|
| 68 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 69 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 70 | + set_request('redirect', $url); |
|
| 71 | + } else { |
|
| 72 | + if (_request('redirect')) { |
|
| 73 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $var_f = charger_fonction($action, 'action'); |
|
| 77 | + $var_f(); |
|
| 78 | + if (!isset($GLOBALS['redirect'])) { |
|
| 79 | + $GLOBALS['redirect'] = _request('redirect') ?? ''; |
|
| 80 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
| 81 | + $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 82 | + } |
|
| 83 | + $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 84 | + } |
|
| 85 | + if ($url = $GLOBALS['redirect']) { |
|
| 86 | + // si l'action est provoque par un hit {ajax} |
|
| 87 | + // il faut transmettre l'env ajax au redirect |
|
| 88 | + // qui a pu etre defini par l'action |
|
| 89 | + if ( |
|
| 90 | + ($v = _request('var_ajax')) |
|
| 91 | + and ($v !== 'form') |
|
| 92 | + and ($args = _request('var_ajax_env')) |
|
| 93 | + ) { |
|
| 94 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 95 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 96 | + // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 97 | + $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 98 | + } |
|
| 99 | + $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 100 | + redirige_par_entete($url); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0 |
|
| 104 | - // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment) |
|
| 105 | - if ( |
|
| 106 | - !headers_sent() |
|
| 107 | - and !ob_get_length() |
|
| 108 | - ) { |
|
| 109 | - http_status(204); |
|
| 110 | - } // No Content |
|
| 111 | - return true; |
|
| 112 | - } |
|
| 103 | + // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0 |
|
| 104 | + // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment) |
|
| 105 | + if ( |
|
| 106 | + !headers_sent() |
|
| 107 | + and !ob_get_length() |
|
| 108 | + ) { |
|
| 109 | + http_status(204); |
|
| 110 | + } // No Content |
|
| 111 | + return true; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // https://code.spip.net/@refuser_traiter_formulaire_ajax |
| 119 | 119 | function refuser_traiter_formulaire_ajax() { |
| 120 | - if ( |
|
| 121 | - $v = _request('var_ajax') |
|
| 122 | - and $v == 'form' |
|
| 123 | - and $form = _request('formulaire_action') |
|
| 124 | - and $args = _request('formulaire_action_args') |
|
| 125 | - and decoder_contexte_ajax($args, $form) !== false |
|
| 126 | - ) { |
|
| 127 | - // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 128 | - // mais traiter ne veut pas |
|
| 129 | - // on le dit a la page qui va resumbit |
|
| 130 | - // sans ajax |
|
| 131 | - include_spip('inc/actions'); |
|
| 132 | - ajax_retour('noajax', false); |
|
| 133 | - exit; |
|
| 134 | - } |
|
| 120 | + if ( |
|
| 121 | + $v = _request('var_ajax') |
|
| 122 | + and $v == 'form' |
|
| 123 | + and $form = _request('formulaire_action') |
|
| 124 | + and $args = _request('formulaire_action_args') |
|
| 125 | + and decoder_contexte_ajax($args, $form) !== false |
|
| 126 | + ) { |
|
| 127 | + // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 128 | + // mais traiter ne veut pas |
|
| 129 | + // on le dit a la page qui va resumbit |
|
| 130 | + // sans ajax |
|
| 131 | + include_spip('inc/actions'); |
|
| 132 | + ajax_retour('noajax', false); |
|
| 133 | + exit; |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // https://code.spip.net/@traiter_appels_inclusions_ajax |
| 138 | 138 | function traiter_appels_inclusions_ajax() { |
| 139 | - // traiter les appels de bloc ajax (ex: pagination) |
|
| 140 | - if ( |
|
| 141 | - $v = _request('var_ajax') |
|
| 142 | - and $v !== 'form' |
|
| 143 | - and $args = _request('var_ajax_env') |
|
| 144 | - ) { |
|
| 145 | - include_spip('inc/filtres'); |
|
| 146 | - include_spip('inc/actions'); |
|
| 147 | - if ( |
|
| 148 | - $args = decoder_contexte_ajax($args) |
|
| 149 | - and $fond = $args['fond'] |
|
| 150 | - ) { |
|
| 151 | - include_spip('public/assembler'); |
|
| 152 | - $contexte = calculer_contexte(); |
|
| 153 | - $contexte = array_merge($args, $contexte); |
|
| 154 | - $page = recuperer_fond($fond, $contexte, ['trim' => false]); |
|
| 155 | - $texte = $page; |
|
| 156 | - if ($ancre = _request('var_ajax_ancre')) { |
|
| 157 | - // pas n'importe quoi quand meme dans la variable ! |
|
| 158 | - $ancre = str_replace(['<', '"', "'"], ['<', '"', ''], $ancre); |
|
| 159 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - include_spip('inc/headers'); |
|
| 163 | - http_response_code(400); |
|
| 164 | - $texte = _L('signature ajax bloc incorrecte'); |
|
| 165 | - } |
|
| 166 | - ajax_retour($texte, false); |
|
| 139 | + // traiter les appels de bloc ajax (ex: pagination) |
|
| 140 | + if ( |
|
| 141 | + $v = _request('var_ajax') |
|
| 142 | + and $v !== 'form' |
|
| 143 | + and $args = _request('var_ajax_env') |
|
| 144 | + ) { |
|
| 145 | + include_spip('inc/filtres'); |
|
| 146 | + include_spip('inc/actions'); |
|
| 147 | + if ( |
|
| 148 | + $args = decoder_contexte_ajax($args) |
|
| 149 | + and $fond = $args['fond'] |
|
| 150 | + ) { |
|
| 151 | + include_spip('public/assembler'); |
|
| 152 | + $contexte = calculer_contexte(); |
|
| 153 | + $contexte = array_merge($args, $contexte); |
|
| 154 | + $page = recuperer_fond($fond, $contexte, ['trim' => false]); |
|
| 155 | + $texte = $page; |
|
| 156 | + if ($ancre = _request('var_ajax_ancre')) { |
|
| 157 | + // pas n'importe quoi quand meme dans la variable ! |
|
| 158 | + $ancre = str_replace(['<', '"', "'"], ['<', '"', ''], $ancre); |
|
| 159 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + include_spip('inc/headers'); |
|
| 163 | + http_response_code(400); |
|
| 164 | + $texte = _L('signature ajax bloc incorrecte'); |
|
| 165 | + } |
|
| 166 | + ajax_retour($texte, false); |
|
| 167 | 167 | |
| 168 | - return true; // on a fini le hit |
|
| 169 | - } |
|
| 168 | + return true; // on a fini le hit |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - return false; |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter |
@@ -177,173 +177,173 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | // https://code.spip.net/@traiter_formulaires_dynamiques |
| 179 | 179 | function traiter_formulaires_dynamiques($get = false) { |
| 180 | - static $post = []; |
|
| 181 | - static $done = false; |
|
| 180 | + static $post = []; |
|
| 181 | + static $done = false; |
|
| 182 | 182 | |
| 183 | - if ($get) { |
|
| 184 | - return $post; |
|
| 185 | - } |
|
| 186 | - if ($done) { |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 189 | - $done = true; |
|
| 183 | + if ($get) { |
|
| 184 | + return $post; |
|
| 185 | + } |
|
| 186 | + if ($done) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | + $done = true; |
|
| 190 | 190 | |
| 191 | - if ( |
|
| 192 | - !($form = _request('formulaire_action') |
|
| 193 | - and $args = _request('formulaire_action_args')) |
|
| 194 | - ) { |
|
| 195 | - return false; |
|
| 196 | - } // le hit peut continuer normalement |
|
| 191 | + if ( |
|
| 192 | + !($form = _request('formulaire_action') |
|
| 193 | + and $args = _request('formulaire_action_args')) |
|
| 194 | + ) { |
|
| 195 | + return false; |
|
| 196 | + } // le hit peut continuer normalement |
|
| 197 | 197 | |
| 198 | - // verifier que le post est licite (du meme auteur ou d'une session anonyme) |
|
| 199 | - $sign = _request('formulaire_action_sign'); |
|
| 200 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 201 | - if (empty($sign)) { |
|
| 202 | - spip_log("signature ajax form incorrecte : $form (formulaire non signe mais on a une session)", 'formulaires' . _LOG_ERREUR); |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 206 | - $secu = $securiser_action($form, $args, '', -1); |
|
| 207 | - if ($sign !== $secu['hash']) { |
|
| 208 | - spip_log("signature ajax form incorrecte : $form (formulaire signe mais ne correspond pas a la session)", 'formulaires' . _LOG_ERREUR); |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - else { |
|
| 213 | - if (!empty($sign)) { |
|
| 214 | - spip_log("signature ajax form incorrecte : $form (formulaire signe mais pas de session)", 'formulaires' . _LOG_ERREUR); |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - } |
|
| 198 | + // verifier que le post est licite (du meme auteur ou d'une session anonyme) |
|
| 199 | + $sign = _request('formulaire_action_sign'); |
|
| 200 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 201 | + if (empty($sign)) { |
|
| 202 | + spip_log("signature ajax form incorrecte : $form (formulaire non signe mais on a une session)", 'formulaires' . _LOG_ERREUR); |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 206 | + $secu = $securiser_action($form, $args, '', -1); |
|
| 207 | + if ($sign !== $secu['hash']) { |
|
| 208 | + spip_log("signature ajax form incorrecte : $form (formulaire signe mais ne correspond pas a la session)", 'formulaires' . _LOG_ERREUR); |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + else { |
|
| 213 | + if (!empty($sign)) { |
|
| 214 | + spip_log("signature ajax form incorrecte : $form (formulaire signe mais pas de session)", 'formulaires' . _LOG_ERREUR); |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - include_spip('inc/filtres'); |
|
| 220 | - if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 221 | - spip_log("signature ajax form incorrecte : $form (encodage corrompu)", 'formulaires' . _LOG_ERREUR); |
|
| 219 | + include_spip('inc/filtres'); |
|
| 220 | + if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 221 | + spip_log("signature ajax form incorrecte : $form (encodage corrompu)", 'formulaires' . _LOG_ERREUR); |
|
| 222 | 222 | |
| 223 | - return false; // continuons le hit comme si de rien etait |
|
| 224 | - } else { |
|
| 225 | - include_spip('inc/lang'); |
|
| 226 | - // sauvegarder la lang en cours |
|
| 227 | - $old_lang = $GLOBALS['spip_lang']; |
|
| 228 | - // changer la langue avec celle qui a cours dans le formulaire |
|
| 229 | - // on la depile de $args car c'est un argument implicite masque |
|
| 230 | - changer_langue(array_shift($args)); |
|
| 223 | + return false; // continuons le hit comme si de rien etait |
|
| 224 | + } else { |
|
| 225 | + include_spip('inc/lang'); |
|
| 226 | + // sauvegarder la lang en cours |
|
| 227 | + $old_lang = $GLOBALS['spip_lang']; |
|
| 228 | + // changer la langue avec celle qui a cours dans le formulaire |
|
| 229 | + // on la depile de $args car c'est un argument implicite masque |
|
| 230 | + changer_langue(array_shift($args)); |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 234 | - include_fichiers_fonctions(); |
|
| 235 | - // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 236 | - include_spip('base/abstract_sql'); |
|
| 233 | + // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 234 | + include_fichiers_fonctions(); |
|
| 235 | + // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 236 | + include_spip('base/abstract_sql'); |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 240 | - * mais avant l'appel de la fonction de vérification. |
|
| 241 | - */ |
|
| 242 | - pipeline( |
|
| 243 | - 'formulaire_receptionner', |
|
| 244 | - [ |
|
| 245 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 246 | - 'data' => null, |
|
| 247 | - ] |
|
| 248 | - ); |
|
| 238 | + /** |
|
| 239 | + * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 240 | + * mais avant l'appel de la fonction de vérification. |
|
| 241 | + */ |
|
| 242 | + pipeline( |
|
| 243 | + 'formulaire_receptionner', |
|
| 244 | + [ |
|
| 245 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 246 | + 'data' => null, |
|
| 247 | + ] |
|
| 248 | + ); |
|
| 249 | 249 | |
| 250 | - $verifier = charger_fonction('verifier', "formulaires/$form/", true); |
|
| 251 | - $post["erreurs_$form"] = pipeline( |
|
| 252 | - 'formulaire_verifier', |
|
| 253 | - [ |
|
| 254 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 255 | - 'data' => $verifier ? call_user_func_array($verifier, $args) : [] |
|
| 256 | - ] |
|
| 257 | - ); |
|
| 258 | - // prise en charge CVT multi etape si besoin |
|
| 259 | - if (_request('cvtm_prev_post')) { |
|
| 260 | - include_spip('inc/cvt_multietapes'); |
|
| 261 | - $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 262 | - ['form' => $form, 'args' => $args], |
|
| 263 | - $post["erreurs_$form"] |
|
| 264 | - ); |
|
| 265 | - } |
|
| 250 | + $verifier = charger_fonction('verifier', "formulaires/$form/", true); |
|
| 251 | + $post["erreurs_$form"] = pipeline( |
|
| 252 | + 'formulaire_verifier', |
|
| 253 | + [ |
|
| 254 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 255 | + 'data' => $verifier ? call_user_func_array($verifier, $args) : [] |
|
| 256 | + ] |
|
| 257 | + ); |
|
| 258 | + // prise en charge CVT multi etape si besoin |
|
| 259 | + if (_request('cvtm_prev_post')) { |
|
| 260 | + include_spip('inc/cvt_multietapes'); |
|
| 261 | + $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 262 | + ['form' => $form, 'args' => $args], |
|
| 263 | + $post["erreurs_$form"] |
|
| 264 | + ); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 268 | - if ((isset($post["erreurs_$form"]) and is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 269 | - $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel( |
|
| 270 | - is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0, |
|
| 271 | - 'avis_1_erreur_saisie', |
|
| 272 | - 'avis_nb_erreurs_saisie' |
|
| 273 | - ); |
|
| 274 | - } |
|
| 267 | + // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 268 | + if ((isset($post["erreurs_$form"]) and is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 269 | + $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel( |
|
| 270 | + is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0, |
|
| 271 | + 'avis_1_erreur_saisie', |
|
| 272 | + 'avis_nb_erreurs_saisie' |
|
| 273 | + ); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - // si on ne demandait qu'une verif json |
|
| 277 | - if (_request('formulaire_action_verifier_json')) { |
|
| 278 | - include_spip('inc/json'); |
|
| 279 | - include_spip('inc/actions'); |
|
| 280 | - ajax_retour(json_encode($post["erreurs_$form"], JSON_THROW_ON_ERROR), 'text/plain'); |
|
| 276 | + // si on ne demandait qu'une verif json |
|
| 277 | + if (_request('formulaire_action_verifier_json')) { |
|
| 278 | + include_spip('inc/json'); |
|
| 279 | + include_spip('inc/actions'); |
|
| 280 | + ajax_retour(json_encode($post["erreurs_$form"], JSON_THROW_ON_ERROR), 'text/plain'); |
|
| 281 | 281 | |
| 282 | - return true; // on a fini le hit |
|
| 283 | - } |
|
| 284 | - $retour = ''; |
|
| 285 | - if (isset($post["erreurs_$form"]) and ((is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) == 0)) { |
|
| 286 | - $rev = ''; |
|
| 287 | - if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) { |
|
| 288 | - $rev = call_user_func_array($traiter, $args); |
|
| 289 | - } |
|
| 282 | + return true; // on a fini le hit |
|
| 283 | + } |
|
| 284 | + $retour = ''; |
|
| 285 | + if (isset($post["erreurs_$form"]) and ((is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) == 0)) { |
|
| 286 | + $rev = ''; |
|
| 287 | + if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) { |
|
| 288 | + $rev = call_user_func_array($traiter, $args); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - $rev = pipeline( |
|
| 292 | - 'formulaire_traiter', |
|
| 293 | - [ |
|
| 294 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 295 | - 'data' => $rev |
|
| 296 | - ] |
|
| 297 | - ); |
|
| 298 | - // le retour de traiter est |
|
| 299 | - // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 300 | - // il permet le pipelinage, en particulier |
|
| 301 | - // en y passant l'id de l'objet cree/modifie |
|
| 302 | - // si message_erreur est present, on considere que le traitement a echoue |
|
| 303 | - $post["message_ok_$form"] = ''; |
|
| 304 | - // on peut avoir message_ok et message_erreur |
|
| 305 | - if (isset($rev['message_ok'])) { |
|
| 306 | - $post["message_ok_$form"] = $rev['message_ok']; |
|
| 307 | - } |
|
| 291 | + $rev = pipeline( |
|
| 292 | + 'formulaire_traiter', |
|
| 293 | + [ |
|
| 294 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 295 | + 'data' => $rev |
|
| 296 | + ] |
|
| 297 | + ); |
|
| 298 | + // le retour de traiter est |
|
| 299 | + // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 300 | + // il permet le pipelinage, en particulier |
|
| 301 | + // en y passant l'id de l'objet cree/modifie |
|
| 302 | + // si message_erreur est present, on considere que le traitement a echoue |
|
| 303 | + $post["message_ok_$form"] = ''; |
|
| 304 | + // on peut avoir message_ok et message_erreur |
|
| 305 | + if (isset($rev['message_ok'])) { |
|
| 306 | + $post["message_ok_$form"] = $rev['message_ok']; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - // verifier si traiter n'a pas echoue avec une erreur : |
|
| 310 | - if (isset($rev['message_erreur'])) { |
|
| 311 | - $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur']; |
|
| 312 | - // si il y a une erreur on ne redirige pas |
|
| 313 | - } else { |
|
| 314 | - // sinon faire ce qu'il faut : |
|
| 315 | - if (isset($rev['editable'])) { |
|
| 316 | - $post["editable_$form"] = $rev['editable']; |
|
| 317 | - } |
|
| 318 | - // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 319 | - // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 320 | - if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 321 | - include_spip('inc/headers'); |
|
| 322 | - [$masque, $message] = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 323 | - $post["message_ok_$form"] .= $message; |
|
| 324 | - $retour .= $masque; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 329 | - if (_request('var_ajax')) { |
|
| 330 | - if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 331 | - include_spip('inc/actions'); |
|
| 332 | - include_spip('public/assembler'); |
|
| 333 | - array_unshift($args, $form); |
|
| 334 | - $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 335 | - // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 336 | - // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 337 | - // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 338 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 339 | - ajax_retour($retour, false); |
|
| 309 | + // verifier si traiter n'a pas echoue avec une erreur : |
|
| 310 | + if (isset($rev['message_erreur'])) { |
|
| 311 | + $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur']; |
|
| 312 | + // si il y a une erreur on ne redirige pas |
|
| 313 | + } else { |
|
| 314 | + // sinon faire ce qu'il faut : |
|
| 315 | + if (isset($rev['editable'])) { |
|
| 316 | + $post["editable_$form"] = $rev['editable']; |
|
| 317 | + } |
|
| 318 | + // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 319 | + // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 320 | + if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 321 | + include_spip('inc/headers'); |
|
| 322 | + [$masque, $message] = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 323 | + $post["message_ok_$form"] .= $message; |
|
| 324 | + $retour .= $masque; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 329 | + if (_request('var_ajax')) { |
|
| 330 | + if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 331 | + include_spip('inc/actions'); |
|
| 332 | + include_spip('public/assembler'); |
|
| 333 | + array_unshift($args, $form); |
|
| 334 | + $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 335 | + // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 336 | + // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 337 | + // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 338 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 339 | + ajax_retour($retour, false); |
|
| 340 | 340 | |
| 341 | - return true; // on a fini le hit |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - // restaurer la lang en cours |
|
| 345 | - changer_langue($old_lang); |
|
| 346 | - } |
|
| 341 | + return true; // on a fini le hit |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + // restaurer la lang en cours |
|
| 345 | + changer_langue($old_lang); |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - return false; // le hit peut continuer normalement |
|
| 348 | + return false; // le hit peut continuer normalement |
|
| 349 | 349 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -48,69 +48,69 @@ discard block |
||
| 48 | 48 | * Nom de la fonction, ou false. |
| 49 | 49 | */ |
| 50 | 50 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 51 | - static $echecs = []; |
|
| 52 | - |
|
| 53 | - if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | - $dossier .= '/'; |
|
| 55 | - } |
|
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | - |
|
| 58 | - if (function_exists($f)) { |
|
| 59 | - return $f; |
|
| 60 | - } |
|
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 62 | - return $g; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (isset($echecs[$f])) { |
|
| 66 | - return $echecs[$f]; |
|
| 67 | - } |
|
| 68 | - // Sinon charger le fichier de declaration si plausible |
|
| 69 | - |
|
| 70 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | - if ($continue) { |
|
| 72 | - return false; |
|
| 73 | - } //appel interne, on passe |
|
| 74 | - include_spip('inc/minipres'); |
|
| 75 | - echo minipres(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // passer en minuscules (cf les balises de formulaires) |
|
| 80 | - // et inclure le fichier |
|
| 81 | - if ($nom === null) { |
|
| 82 | - dd(debug_backtrace()); |
|
| 83 | - } |
|
| 84 | - if ( |
|
| 85 | - !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 86 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 87 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 88 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 89 | - ) { |
|
| 90 | - include_spip(substr($dossier, 0, -1)); |
|
| 91 | - } |
|
| 92 | - if (function_exists($f)) { |
|
| 93 | - return $f; |
|
| 94 | - } |
|
| 95 | - if (function_exists($g)) { |
|
| 96 | - return $g; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ($continue) { |
|
| 100 | - return $echecs[$f] = false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Echec : message d'erreur |
|
| 104 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 105 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 106 | - |
|
| 107 | - include_spip('inc/minipres'); |
|
| 108 | - echo minipres( |
|
| 109 | - _T('forum_titre_erreur'), |
|
| 110 | - _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 111 | - ['all_inline' => true,'status' => 404] |
|
| 112 | - ); |
|
| 113 | - exit; |
|
| 51 | + static $echecs = []; |
|
| 52 | + |
|
| 53 | + if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | + $dossier .= '/'; |
|
| 55 | + } |
|
| 56 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | + |
|
| 58 | + if (function_exists($f)) { |
|
| 59 | + return $f; |
|
| 60 | + } |
|
| 61 | + if (function_exists($g = $f . '_dist')) { |
|
| 62 | + return $g; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (isset($echecs[$f])) { |
|
| 66 | + return $echecs[$f]; |
|
| 67 | + } |
|
| 68 | + // Sinon charger le fichier de declaration si plausible |
|
| 69 | + |
|
| 70 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | + if ($continue) { |
|
| 72 | + return false; |
|
| 73 | + } //appel interne, on passe |
|
| 74 | + include_spip('inc/minipres'); |
|
| 75 | + echo minipres(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // passer en minuscules (cf les balises de formulaires) |
|
| 80 | + // et inclure le fichier |
|
| 81 | + if ($nom === null) { |
|
| 82 | + dd(debug_backtrace()); |
|
| 83 | + } |
|
| 84 | + if ( |
|
| 85 | + !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 86 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 87 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 88 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 89 | + ) { |
|
| 90 | + include_spip(substr($dossier, 0, -1)); |
|
| 91 | + } |
|
| 92 | + if (function_exists($f)) { |
|
| 93 | + return $f; |
|
| 94 | + } |
|
| 95 | + if (function_exists($g)) { |
|
| 96 | + return $g; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ($continue) { |
|
| 100 | + return $echecs[$f] = false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Echec : message d'erreur |
|
| 104 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 105 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 106 | + |
|
| 107 | + include_spip('inc/minipres'); |
|
| 108 | + echo minipres( |
|
| 109 | + _T('forum_titre_erreur'), |
|
| 110 | + _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 111 | + ['all_inline' => true,'status' => 404] |
|
| 112 | + ); |
|
| 113 | + exit; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,17 +120,17 @@ discard block |
||
| 120 | 120 | * @return bool |
| 121 | 121 | */ |
| 122 | 122 | function include_once_check($file) { |
| 123 | - if (file_exists($file)) { |
|
| 124 | - include_once $file; |
|
| 123 | + if (file_exists($file)) { |
|
| 124 | + include_once $file; |
|
| 125 | 125 | |
| 126 | - return true; |
|
| 127 | - } |
|
| 128 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 129 | - $crash = ($crash ?: []); |
|
| 130 | - $crash[$file] = true; |
|
| 131 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 126 | + return true; |
|
| 127 | + } |
|
| 128 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 129 | + $crash = ($crash ?: []); |
|
| 130 | + $crash[$file] = true; |
|
| 131 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 132 | 132 | |
| 133 | - return false; |
|
| 133 | + return false; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * - string : chemin du fichier trouvé |
| 155 | 155 | **/ |
| 156 | 156 | function include_spip($f, $include = true) { |
| 157 | - return find_in_path($f . '.php', '', $include); |
|
| 157 | + return find_in_path($f . '.php', '', $include); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * - string : chemin du fichier trouvé |
| 175 | 175 | **/ |
| 176 | 176 | function require_spip($f) { |
| 177 | - return find_in_path($f . '.php', '', 'required'); |
|
| 177 | + return find_in_path($f . '.php', '', 'required'); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -183,27 +183,27 @@ discard block |
||
| 183 | 183 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 184 | 184 | */ |
| 185 | 185 | function include_fichiers_fonctions() { |
| 186 | - static $done = false; |
|
| 187 | - if (!$done) { |
|
| 188 | - include_spip('inc/lang'); |
|
| 189 | - |
|
| 190 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 191 | - // donc il faut l'inclure "en globals" |
|
| 192 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 193 | - global $dossier_squelettes; |
|
| 194 | - include_once(_ROOT_CWD . $f); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 198 | - // chargement optimise precompile |
|
| 199 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 200 | - } |
|
| 201 | - if (test_espace_prive()) { |
|
| 202 | - include_spip('inc/filtres_ecrire'); |
|
| 203 | - } |
|
| 204 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 205 | - $done = true; |
|
| 206 | - } |
|
| 186 | + static $done = false; |
|
| 187 | + if (!$done) { |
|
| 188 | + include_spip('inc/lang'); |
|
| 189 | + |
|
| 190 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 191 | + // donc il faut l'inclure "en globals" |
|
| 192 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 193 | + global $dossier_squelettes; |
|
| 194 | + include_once(_ROOT_CWD . $f); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 198 | + // chargement optimise precompile |
|
| 199 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 200 | + } |
|
| 201 | + if (test_espace_prive()) { |
|
| 202 | + include_spip('inc/filtres_ecrire'); |
|
| 203 | + } |
|
| 204 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 205 | + $done = true; |
|
| 206 | + } |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -229,23 +229,23 @@ discard block |
||
| 229 | 229 | * Les paramètres du pipeline modifiés |
| 230 | 230 | **/ |
| 231 | 231 | function minipipe($fonc, &$val) { |
| 232 | - // fonction |
|
| 233 | - if (function_exists($fonc)) { |
|
| 234 | - $val = call_user_func($fonc, $val); |
|
| 235 | - } // Class::Methode |
|
| 236 | - else { |
|
| 237 | - if ( |
|
| 238 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 239 | - and $methode = [$regs[1], $regs[2]] |
|
| 240 | - and is_callable($methode) |
|
| 241 | - ) { |
|
| 242 | - $val = call_user_func($methode, $val); |
|
| 243 | - } else { |
|
| 244 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $val; |
|
| 232 | + // fonction |
|
| 233 | + if (function_exists($fonc)) { |
|
| 234 | + $val = call_user_func($fonc, $val); |
|
| 235 | + } // Class::Methode |
|
| 236 | + else { |
|
| 237 | + if ( |
|
| 238 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 239 | + and $methode = [$regs[1], $regs[2]] |
|
| 240 | + and is_callable($methode) |
|
| 241 | + ) { |
|
| 242 | + $val = call_user_func($methode, $val); |
|
| 243 | + } else { |
|
| 244 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $val; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -276,46 +276,46 @@ discard block |
||
| 276 | 276 | * Résultat |
| 277 | 277 | */ |
| 278 | 278 | function pipeline($action, $val = null) { |
| 279 | - static $charger; |
|
| 280 | - |
|
| 281 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 282 | - if (!$charger) { |
|
| 283 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 284 | - include_spip('inc/plugin'); |
|
| 285 | - // generer les fichiers php precompiles |
|
| 286 | - // de chargement des plugins et des pipelines |
|
| 287 | - actualise_plugins_actifs(); |
|
| 288 | - if (!($ok = @is_readable($charger))) { |
|
| 289 | - spip_log("fichier $charger pas cree"); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if ($ok) { |
|
| 294 | - include_once $charger; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // appliquer notre fonction si elle existe |
|
| 299 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 300 | - if (function_exists($fonc)) { |
|
| 301 | - $val = $fonc($val); |
|
| 302 | - } // plantage ? |
|
| 303 | - else { |
|
| 304 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // si le flux est une table avec 2 cle args&data |
|
| 308 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 309 | - // array_key_exists pour php 4.1.0 |
|
| 310 | - if ( |
|
| 311 | - is_array($val) |
|
| 312 | - and count($val) == 2 |
|
| 313 | - and (array_key_exists('data', $val)) |
|
| 314 | - ) { |
|
| 315 | - $val = $val['data']; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - return $val; |
|
| 279 | + static $charger; |
|
| 280 | + |
|
| 281 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 282 | + if (!$charger) { |
|
| 283 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 284 | + include_spip('inc/plugin'); |
|
| 285 | + // generer les fichiers php precompiles |
|
| 286 | + // de chargement des plugins et des pipelines |
|
| 287 | + actualise_plugins_actifs(); |
|
| 288 | + if (!($ok = @is_readable($charger))) { |
|
| 289 | + spip_log("fichier $charger pas cree"); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if ($ok) { |
|
| 294 | + include_once $charger; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // appliquer notre fonction si elle existe |
|
| 299 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 300 | + if (function_exists($fonc)) { |
|
| 301 | + $val = $fonc($val); |
|
| 302 | + } // plantage ? |
|
| 303 | + else { |
|
| 304 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // si le flux est une table avec 2 cle args&data |
|
| 308 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 309 | + // array_key_exists pour php 4.1.0 |
|
| 310 | + if ( |
|
| 311 | + is_array($val) |
|
| 312 | + and count($val) == 2 |
|
| 313 | + and (array_key_exists('data', $val)) |
|
| 314 | + ) { |
|
| 315 | + $val = $val['data']; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + return $val; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -359,38 +359,38 @@ discard block |
||
| 359 | 359 | * paramètre est planté pour cause de compatibilité ascendante. |
| 360 | 360 | */ |
| 361 | 361 | function spip_log($message = null, $name = null) { |
| 362 | - static $pre = []; |
|
| 363 | - static $log; |
|
| 364 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 365 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 366 | - $logname = null; |
|
| 367 | - } |
|
| 368 | - if (!isset($regs[2])) { |
|
| 369 | - $niveau = _LOG_INFO; |
|
| 370 | - } |
|
| 371 | - else { |
|
| 372 | - $niveau = intval($regs[2]); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 376 | - if (!$pre) { |
|
| 377 | - $pre = [ |
|
| 378 | - _LOG_HS => 'HS:', |
|
| 379 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 380 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 381 | - _LOG_ERREUR => 'ERREUR:', |
|
| 382 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 383 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 384 | - _LOG_INFO => 'info:', |
|
| 385 | - _LOG_DEBUG => 'debug:' |
|
| 386 | - ]; |
|
| 387 | - $log = charger_fonction('log', 'inc'); |
|
| 388 | - } |
|
| 389 | - if (!is_string($message)) { |
|
| 390 | - $message = print_r($message, true); |
|
| 391 | - } |
|
| 392 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 393 | - } |
|
| 362 | + static $pre = []; |
|
| 363 | + static $log; |
|
| 364 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 365 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 366 | + $logname = null; |
|
| 367 | + } |
|
| 368 | + if (!isset($regs[2])) { |
|
| 369 | + $niveau = _LOG_INFO; |
|
| 370 | + } |
|
| 371 | + else { |
|
| 372 | + $niveau = intval($regs[2]); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 376 | + if (!$pre) { |
|
| 377 | + $pre = [ |
|
| 378 | + _LOG_HS => 'HS:', |
|
| 379 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 380 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 381 | + _LOG_ERREUR => 'ERREUR:', |
|
| 382 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 383 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 384 | + _LOG_INFO => 'info:', |
|
| 385 | + _LOG_DEBUG => 'debug:' |
|
| 386 | + ]; |
|
| 387 | + $log = charger_fonction('log', 'inc'); |
|
| 388 | + } |
|
| 389 | + if (!is_string($message)) { |
|
| 390 | + $message = print_r($message, true); |
|
| 391 | + } |
|
| 392 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 393 | + } |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -401,8 +401,8 @@ discard block |
||
| 401 | 401 | * @param array $opt Tableau d'options |
| 402 | 402 | **/ |
| 403 | 403 | function journal($phrase, $opt = []) { |
| 404 | - $journal = charger_fonction('journal', 'inc'); |
|
| 405 | - $journal($phrase, $opt); |
|
| 404 | + $journal = charger_fonction('journal', 'inc'); |
|
| 405 | + $journal($phrase, $opt); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -421,37 +421,37 @@ discard block |
||
| 421 | 421 | **/ |
| 422 | 422 | function _request($var, $c = false) { |
| 423 | 423 | |
| 424 | - if (is_array($c)) { |
|
| 425 | - return $c[$var] ?? null; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - if (isset($_GET[$var])) { |
|
| 429 | - $a = $_GET[$var]; |
|
| 430 | - } elseif (isset($_POST[$var])) { |
|
| 431 | - $a = $_POST[$var]; |
|
| 432 | - } else { |
|
| 433 | - return null; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // Si on est en ajax et en POST tout a ete encode |
|
| 437 | - // via encodeURIComponent, il faut donc repasser |
|
| 438 | - // dans le charset local... |
|
| 439 | - if ( |
|
| 440 | - defined('_AJAX') |
|
| 441 | - and _AJAX |
|
| 442 | - and isset($GLOBALS['meta']['charset']) |
|
| 443 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 444 | - and is_string($a) |
|
| 445 | - // check rapide mais pas fiable |
|
| 446 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 447 | - // check fiable |
|
| 448 | - and include_spip('inc/charsets') |
|
| 449 | - and is_utf8($a) |
|
| 450 | - ) { |
|
| 451 | - return importer_charset($a, 'utf-8'); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $a; |
|
| 424 | + if (is_array($c)) { |
|
| 425 | + return $c[$var] ?? null; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + if (isset($_GET[$var])) { |
|
| 429 | + $a = $_GET[$var]; |
|
| 430 | + } elseif (isset($_POST[$var])) { |
|
| 431 | + $a = $_POST[$var]; |
|
| 432 | + } else { |
|
| 433 | + return null; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // Si on est en ajax et en POST tout a ete encode |
|
| 437 | + // via encodeURIComponent, il faut donc repasser |
|
| 438 | + // dans le charset local... |
|
| 439 | + if ( |
|
| 440 | + defined('_AJAX') |
|
| 441 | + and _AJAX |
|
| 442 | + and isset($GLOBALS['meta']['charset']) |
|
| 443 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 444 | + and is_string($a) |
|
| 445 | + // check rapide mais pas fiable |
|
| 446 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 447 | + // check fiable |
|
| 448 | + and include_spip('inc/charsets') |
|
| 449 | + and is_utf8($a) |
|
| 450 | + ) { |
|
| 451 | + return importer_charset($a, 'utf-8'); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $a; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -469,22 +469,22 @@ discard block |
||
| 469 | 469 | * - false sinon |
| 470 | 470 | **/ |
| 471 | 471 | function set_request($var, $val = null, $c = false) { |
| 472 | - if (is_array($c)) { |
|
| 473 | - unset($c[$var]); |
|
| 474 | - if ($val !== null) { |
|
| 475 | - $c[$var] = $val; |
|
| 476 | - } |
|
| 472 | + if (is_array($c)) { |
|
| 473 | + unset($c[$var]); |
|
| 474 | + if ($val !== null) { |
|
| 475 | + $c[$var] = $val; |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - return $c; |
|
| 479 | - } |
|
| 478 | + return $c; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - unset($_GET[$var]); |
|
| 482 | - unset($_POST[$var]); |
|
| 483 | - if ($val !== null) { |
|
| 484 | - $_GET[$var] = $val; |
|
| 485 | - } |
|
| 481 | + unset($_GET[$var]); |
|
| 482 | + unset($_POST[$var]); |
|
| 483 | + if ($val !== null) { |
|
| 484 | + $_GET[$var] = $val; |
|
| 485 | + } |
|
| 486 | 486 | |
| 487 | - return false; # n'affecte pas $c |
|
| 487 | + return false; # n'affecte pas $c |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -504,25 +504,25 @@ discard block |
||
| 504 | 504 | * @return array|mixed|string |
| 505 | 505 | */ |
| 506 | 506 | function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') { |
| 507 | - if (is_array($value)) { |
|
| 508 | - if ($key == '*') { |
|
| 509 | - $key = array_keys($value); |
|
| 510 | - } |
|
| 511 | - if (!is_array($key)) { |
|
| 512 | - $key = [$key]; |
|
| 513 | - } |
|
| 514 | - foreach ($key as $k) { |
|
| 515 | - if (!empty($value[$k])) { |
|
| 516 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - return $value; |
|
| 520 | - } |
|
| 521 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 522 | - if (!empty($value) and $value == _request($key)) { |
|
| 523 | - $value = $sanitize_function($value); |
|
| 524 | - } |
|
| 525 | - return $value; |
|
| 507 | + if (is_array($value)) { |
|
| 508 | + if ($key == '*') { |
|
| 509 | + $key = array_keys($value); |
|
| 510 | + } |
|
| 511 | + if (!is_array($key)) { |
|
| 512 | + $key = [$key]; |
|
| 513 | + } |
|
| 514 | + foreach ($key as $k) { |
|
| 515 | + if (!empty($value[$k])) { |
|
| 516 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + return $value; |
|
| 520 | + } |
|
| 521 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 522 | + if (!empty($value) and $value == _request($key)) { |
|
| 523 | + $value = $sanitize_function($value); |
|
| 524 | + } |
|
| 525 | + return $value; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -530,23 +530,22 @@ discard block |
||
| 530 | 530 | * |
| 531 | 531 | * On est sur le web, on exclut certains protocoles, |
| 532 | 532 | * notamment 'file://', 'php://' et d'autres… |
| 533 | - |
|
| 534 | 533 | * @param string $url |
| 535 | 534 | * @return bool |
| 536 | 535 | */ |
| 537 | 536 | function tester_url_absolue($url) { |
| 538 | - $url = trim($url); |
|
| 539 | - if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 540 | - if ( |
|
| 541 | - isset($m[1]) |
|
| 542 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 543 | - and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 544 | - ) { |
|
| 545 | - return false; |
|
| 546 | - } |
|
| 547 | - return true; |
|
| 548 | - } |
|
| 549 | - return false; |
|
| 537 | + $url = trim($url); |
|
| 538 | + if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 539 | + if ( |
|
| 540 | + isset($m[1]) |
|
| 541 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 542 | + and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 543 | + ) { |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + return false; |
|
| 550 | 549 | } |
| 551 | 550 | |
| 552 | 551 | /** |
@@ -568,95 +567,95 @@ discard block |
||
| 568 | 567 | * @return string URL |
| 569 | 568 | */ |
| 570 | 569 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 571 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 572 | - if (strpos($c, '|') !== false and is_null($v)) { |
|
| 573 | - return null; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - // lever l'#ancre |
|
| 577 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 578 | - $url = $r[1]; |
|
| 579 | - $ancre = $r[2]; |
|
| 580 | - } else { |
|
| 581 | - $ancre = ''; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - // eclater |
|
| 585 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 586 | - |
|
| 587 | - // recuperer la base |
|
| 588 | - $a = array_shift($url); |
|
| 589 | - if (!$a) { |
|
| 590 | - $a = './'; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 594 | - $ajouts = array_flip(explode('|', $c)); |
|
| 595 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 596 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 597 | - $v_read = null; |
|
| 598 | - // lire les variables et agir |
|
| 599 | - foreach ($url as $n => $val) { |
|
| 600 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 601 | - $r = array_pad($r, 3, null); |
|
| 602 | - if ($v === null) { |
|
| 603 | - // c'est un tableau, on memorise les valeurs |
|
| 604 | - if (substr($r[1], -2) == '[]') { |
|
| 605 | - if (!$v_read) { |
|
| 606 | - $v_read = []; |
|
| 607 | - } |
|
| 608 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 609 | - } // c'est un scalaire, on retourne direct |
|
| 610 | - else { |
|
| 611 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 612 | - } |
|
| 613 | - } // suppression |
|
| 614 | - elseif (!$testv) { |
|
| 615 | - unset($url[$n]); |
|
| 616 | - } |
|
| 617 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 618 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 619 | - elseif (substr($r[1], -2) != '[]') { |
|
| 620 | - $url[$n] = $r[1] . '=' . $u; |
|
| 621 | - unset($ajouts[$r[1]]); |
|
| 622 | - } |
|
| 623 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 624 | - // départ, on remplira à l'étape suivante |
|
| 625 | - else { |
|
| 626 | - unset($url[$n]); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - // traiter les parametres pas encore trouves |
|
| 632 | - if ( |
|
| 633 | - $v === null |
|
| 634 | - and $args = func_get_args() |
|
| 635 | - and count($args) == 2 |
|
| 636 | - ) { |
|
| 637 | - return $v_read; // rien trouve ou un tableau |
|
| 638 | - } elseif ($testv) { |
|
| 639 | - foreach ($ajouts as $k => $n) { |
|
| 640 | - if (!is_array($v)) { |
|
| 641 | - $url[] = $k . '=' . $u; |
|
| 642 | - } else { |
|
| 643 | - $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 644 | - foreach ($v as $w) { |
|
| 645 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // eliminer les vides |
|
| 652 | - $url = array_filter($url); |
|
| 653 | - |
|
| 654 | - // recomposer l'adresse |
|
| 655 | - if ($url) { |
|
| 656 | - $a .= '?' . join($sep, $url); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - return $a . $ancre; |
|
| 570 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 571 | + if (strpos($c, '|') !== false and is_null($v)) { |
|
| 572 | + return null; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + // lever l'#ancre |
|
| 576 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 577 | + $url = $r[1]; |
|
| 578 | + $ancre = $r[2]; |
|
| 579 | + } else { |
|
| 580 | + $ancre = ''; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + // eclater |
|
| 584 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 585 | + |
|
| 586 | + // recuperer la base |
|
| 587 | + $a = array_shift($url); |
|
| 588 | + if (!$a) { |
|
| 589 | + $a = './'; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 593 | + $ajouts = array_flip(explode('|', $c)); |
|
| 594 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 595 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 596 | + $v_read = null; |
|
| 597 | + // lire les variables et agir |
|
| 598 | + foreach ($url as $n => $val) { |
|
| 599 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 600 | + $r = array_pad($r, 3, null); |
|
| 601 | + if ($v === null) { |
|
| 602 | + // c'est un tableau, on memorise les valeurs |
|
| 603 | + if (substr($r[1], -2) == '[]') { |
|
| 604 | + if (!$v_read) { |
|
| 605 | + $v_read = []; |
|
| 606 | + } |
|
| 607 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 608 | + } // c'est un scalaire, on retourne direct |
|
| 609 | + else { |
|
| 610 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 611 | + } |
|
| 612 | + } // suppression |
|
| 613 | + elseif (!$testv) { |
|
| 614 | + unset($url[$n]); |
|
| 615 | + } |
|
| 616 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 617 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 618 | + elseif (substr($r[1], -2) != '[]') { |
|
| 619 | + $url[$n] = $r[1] . '=' . $u; |
|
| 620 | + unset($ajouts[$r[1]]); |
|
| 621 | + } |
|
| 622 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 623 | + // départ, on remplira à l'étape suivante |
|
| 624 | + else { |
|
| 625 | + unset($url[$n]); |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // traiter les parametres pas encore trouves |
|
| 631 | + if ( |
|
| 632 | + $v === null |
|
| 633 | + and $args = func_get_args() |
|
| 634 | + and count($args) == 2 |
|
| 635 | + ) { |
|
| 636 | + return $v_read; // rien trouve ou un tableau |
|
| 637 | + } elseif ($testv) { |
|
| 638 | + foreach ($ajouts as $k => $n) { |
|
| 639 | + if (!is_array($v)) { |
|
| 640 | + $url[] = $k . '=' . $u; |
|
| 641 | + } else { |
|
| 642 | + $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 643 | + foreach ($v as $w) { |
|
| 644 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + // eliminer les vides |
|
| 651 | + $url = array_filter($url); |
|
| 652 | + |
|
| 653 | + // recomposer l'adresse |
|
| 654 | + if ($url) { |
|
| 655 | + $a .= '?' . join($sep, $url); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + return $a . $ancre; |
|
| 660 | 659 | } |
| 661 | 660 | |
| 662 | 661 | /** |
@@ -674,21 +673,21 @@ discard block |
||
| 674 | 673 | * @return string |
| 675 | 674 | */ |
| 676 | 675 | function ancre_url($url, $ancre) { |
| 677 | - // lever l'#ancre |
|
| 678 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 679 | - $url = $r[1]; |
|
| 680 | - } |
|
| 681 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 682 | - if (!function_exists('translitteration')) { |
|
| 683 | - include_spip('inc/charsets'); |
|
| 684 | - } |
|
| 685 | - $ancre = preg_replace( |
|
| 686 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 687 | - ['', '-'], |
|
| 688 | - translitteration($ancre) |
|
| 689 | - ); |
|
| 690 | - } |
|
| 691 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 676 | + // lever l'#ancre |
|
| 677 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 678 | + $url = $r[1]; |
|
| 679 | + } |
|
| 680 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 681 | + if (!function_exists('translitteration')) { |
|
| 682 | + include_spip('inc/charsets'); |
|
| 683 | + } |
|
| 684 | + $ancre = preg_replace( |
|
| 685 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 686 | + ['', '-'], |
|
| 687 | + translitteration($ancre) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 692 | 691 | } |
| 693 | 692 | |
| 694 | 693 | /** |
@@ -698,16 +697,16 @@ discard block |
||
| 698 | 697 | * @return string |
| 699 | 698 | */ |
| 700 | 699 | function nettoyer_uri($reset = null) { |
| 701 | - static $done = false; |
|
| 702 | - static $propre = ''; |
|
| 703 | - if (!is_null($reset)) { |
|
| 704 | - return $propre = $reset; |
|
| 705 | - } |
|
| 706 | - if ($done) { |
|
| 707 | - return $propre; |
|
| 708 | - } |
|
| 709 | - $done = true; |
|
| 710 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 700 | + static $done = false; |
|
| 701 | + static $propre = ''; |
|
| 702 | + if (!is_null($reset)) { |
|
| 703 | + return $propre = $reset; |
|
| 704 | + } |
|
| 705 | + if ($done) { |
|
| 706 | + return $propre; |
|
| 707 | + } |
|
| 708 | + $done = true; |
|
| 709 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 711 | 710 | } |
| 712 | 711 | |
| 713 | 712 | /** |
@@ -719,16 +718,16 @@ discard block |
||
| 719 | 718 | * @return string |
| 720 | 719 | */ |
| 721 | 720 | function nettoyer_uri_var($request_uri) { |
| 722 | - $uri1 = $request_uri; |
|
| 723 | - do { |
|
| 724 | - $uri = $uri1; |
|
| 725 | - $uri1 = preg_replace( |
|
| 726 | - ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 727 | - '\1', |
|
| 728 | - $uri |
|
| 729 | - ); |
|
| 730 | - } while ($uri <> $uri1); |
|
| 731 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 721 | + $uri1 = $request_uri; |
|
| 722 | + do { |
|
| 723 | + $uri = $uri1; |
|
| 724 | + $uri1 = preg_replace( |
|
| 725 | + ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 726 | + '\1', |
|
| 727 | + $uri |
|
| 728 | + ); |
|
| 729 | + } while ($uri <> $uri1); |
|
| 730 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 732 | 731 | } |
| 733 | 732 | |
| 734 | 733 | |
@@ -742,48 +741,48 @@ discard block |
||
| 742 | 741 | * URL vers soi-même |
| 743 | 742 | **/ |
| 744 | 743 | function self($amp = '&', $root = false) { |
| 745 | - $url = nettoyer_uri(); |
|
| 746 | - if ( |
|
| 747 | - !$root |
|
| 748 | - and ( |
|
| 749 | - // si pas de profondeur on peut tronquer |
|
| 750 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 751 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 752 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 753 | - ) { |
|
| 754 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 755 | - } |
|
| 756 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 757 | - foreach ($_POST as $v => $c) { |
|
| 758 | - if (substr($v, 0, 3) == 'id_') { |
|
| 759 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - // supprimer les variables sans interet |
|
| 764 | - if (test_espace_prive()) { |
|
| 765 | - $url = preg_replace(',([?&])(' |
|
| 766 | - . 'lang|show_docs|' |
|
| 767 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 768 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 769 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // eviter les hacks |
|
| 773 | - include_spip('inc/filtres_mini'); |
|
| 774 | - $url = spip_htmlspecialchars($url); |
|
| 775 | - |
|
| 776 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 777 | - |
|
| 778 | - // & ? |
|
| 779 | - if ($amp != '&') { |
|
| 780 | - $url = str_replace('&', $amp, $url); |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - // Si ca demarre par ? ou vide, donner './' |
|
| 784 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 785 | - |
|
| 786 | - return $url; |
|
| 744 | + $url = nettoyer_uri(); |
|
| 745 | + if ( |
|
| 746 | + !$root |
|
| 747 | + and ( |
|
| 748 | + // si pas de profondeur on peut tronquer |
|
| 749 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 750 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 751 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 752 | + ) { |
|
| 753 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 754 | + } |
|
| 755 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 756 | + foreach ($_POST as $v => $c) { |
|
| 757 | + if (substr($v, 0, 3) == 'id_') { |
|
| 758 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // supprimer les variables sans interet |
|
| 763 | + if (test_espace_prive()) { |
|
| 764 | + $url = preg_replace(',([?&])(' |
|
| 765 | + . 'lang|show_docs|' |
|
| 766 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 767 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 768 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + // eviter les hacks |
|
| 772 | + include_spip('inc/filtres_mini'); |
|
| 773 | + $url = spip_htmlspecialchars($url); |
|
| 774 | + |
|
| 775 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 776 | + |
|
| 777 | + // & ? |
|
| 778 | + if ($amp != '&') { |
|
| 779 | + $url = str_replace('&', $amp, $url); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + // Si ca demarre par ? ou vide, donner './' |
|
| 783 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 784 | + |
|
| 785 | + return $url; |
|
| 787 | 786 | } |
| 788 | 787 | |
| 789 | 788 | |
@@ -794,7 +793,7 @@ discard block |
||
| 794 | 793 | * true si c'est le cas, false sinon. |
| 795 | 794 | */ |
| 796 | 795 | function test_espace_prive() { |
| 797 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 796 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 798 | 797 | } |
| 799 | 798 | |
| 800 | 799 | /** |
@@ -804,7 +803,7 @@ discard block |
||
| 804 | 803 | * @return bool |
| 805 | 804 | */ |
| 806 | 805 | function test_plugin_actif($plugin) { |
| 807 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 806 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 808 | 807 | } |
| 809 | 808 | |
| 810 | 809 | /** |
@@ -835,52 +834,52 @@ discard block |
||
| 835 | 834 | * Texte |
| 836 | 835 | */ |
| 837 | 836 | function _T($texte, $args = [], $options = []) { |
| 838 | - static $traduire = false; |
|
| 839 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 840 | - if ($options) { |
|
| 841 | - // support de l'ancien argument $class |
|
| 842 | - if (is_string($options)) { |
|
| 843 | - $options = ['class' => $options]; |
|
| 844 | - } |
|
| 845 | - $o = array_merge($o, $options); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - if (!$traduire) { |
|
| 849 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 850 | - include_spip('inc/lang'); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - // On peut passer explicitement la langue dans le tableau |
|
| 854 | - // On utilise le même nom de variable que la globale |
|
| 855 | - if (isset($args['spip_lang'])) { |
|
| 856 | - $lang = $args['spip_lang']; |
|
| 857 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 858 | - unset($args['spip_lang']); |
|
| 859 | - } // Sinon on prend la langue du contexte |
|
| 860 | - else { |
|
| 861 | - $lang = $GLOBALS['spip_lang']; |
|
| 862 | - } |
|
| 863 | - $text = $traduire($texte, $lang); |
|
| 864 | - |
|
| 865 | - if ($text === null || !strlen($text)) { |
|
| 866 | - if (!$o['force']) { |
|
| 867 | - return ''; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - $text = $texte; |
|
| 871 | - |
|
| 872 | - // pour les chaines non traduites, assurer un service minimum |
|
| 873 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 874 | - $n = strpos($text, ':'); |
|
| 875 | - if ($n !== false) { |
|
| 876 | - $text = substr($text, $n + 1); |
|
| 877 | - } |
|
| 878 | - $text = str_replace('_', ' ', $text); |
|
| 879 | - } |
|
| 880 | - $o['class'] = null; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - return _L($text, $args, $o); |
|
| 837 | + static $traduire = false; |
|
| 838 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 839 | + if ($options) { |
|
| 840 | + // support de l'ancien argument $class |
|
| 841 | + if (is_string($options)) { |
|
| 842 | + $options = ['class' => $options]; |
|
| 843 | + } |
|
| 844 | + $o = array_merge($o, $options); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + if (!$traduire) { |
|
| 848 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 849 | + include_spip('inc/lang'); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + // On peut passer explicitement la langue dans le tableau |
|
| 853 | + // On utilise le même nom de variable que la globale |
|
| 854 | + if (isset($args['spip_lang'])) { |
|
| 855 | + $lang = $args['spip_lang']; |
|
| 856 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 857 | + unset($args['spip_lang']); |
|
| 858 | + } // Sinon on prend la langue du contexte |
|
| 859 | + else { |
|
| 860 | + $lang = $GLOBALS['spip_lang']; |
|
| 861 | + } |
|
| 862 | + $text = $traduire($texte, $lang); |
|
| 863 | + |
|
| 864 | + if ($text === null || !strlen($text)) { |
|
| 865 | + if (!$o['force']) { |
|
| 866 | + return ''; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + $text = $texte; |
|
| 870 | + |
|
| 871 | + // pour les chaines non traduites, assurer un service minimum |
|
| 872 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 873 | + $n = strpos($text, ':'); |
|
| 874 | + if ($n !== false) { |
|
| 875 | + $text = substr($text, $n + 1); |
|
| 876 | + } |
|
| 877 | + $text = str_replace('_', ' ', $text); |
|
| 878 | + } |
|
| 879 | + $o['class'] = null; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + return _L($text, $args, $o); |
|
| 884 | 883 | } |
| 885 | 884 | |
| 886 | 885 | |
@@ -907,53 +906,53 @@ discard block |
||
| 907 | 906 | * Texte |
| 908 | 907 | */ |
| 909 | 908 | function _L($text, $args = [], $options = []) { |
| 910 | - $f = $text; |
|
| 911 | - $defaut_options = [ |
|
| 912 | - 'class' => null, |
|
| 913 | - 'sanitize' => true, |
|
| 914 | - ]; |
|
| 915 | - // support de l'ancien argument $class |
|
| 916 | - if ($options and is_string($options)) { |
|
| 917 | - $options = ['class' => $options]; |
|
| 918 | - } |
|
| 919 | - if (is_array($options)) { |
|
| 920 | - $options += $defaut_options; |
|
| 921 | - } else { |
|
| 922 | - $options = $defaut_options; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - if (is_array($args) and count($args)) { |
|
| 926 | - if (!function_exists('interdire_scripts')) { |
|
| 927 | - include_spip('inc/texte'); |
|
| 928 | - } |
|
| 929 | - if (!function_exists('echapper_html_suspect')) { |
|
| 930 | - include_spip('inc/texte_mini'); |
|
| 931 | - } |
|
| 932 | - foreach ($args as $name => $value) { |
|
| 933 | - if (strpos($text, (string) "@$name@") !== false) { |
|
| 934 | - if ($options['sanitize']) { |
|
| 935 | - $value = echapper_html_suspect($value); |
|
| 936 | - $value = interdire_scripts($value, -1); |
|
| 937 | - } |
|
| 938 | - if (!empty($options['class'])) { |
|
| 939 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 940 | - } |
|
| 941 | - $text = str_replace("@$name@", $value, $text); |
|
| 942 | - unset($args[$name]); |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 946 | - // (chaines de langues pas a jour) |
|
| 947 | - if ($args) { |
|
| 948 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 953 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 954 | - } else { |
|
| 955 | - return $text; |
|
| 956 | - } |
|
| 909 | + $f = $text; |
|
| 910 | + $defaut_options = [ |
|
| 911 | + 'class' => null, |
|
| 912 | + 'sanitize' => true, |
|
| 913 | + ]; |
|
| 914 | + // support de l'ancien argument $class |
|
| 915 | + if ($options and is_string($options)) { |
|
| 916 | + $options = ['class' => $options]; |
|
| 917 | + } |
|
| 918 | + if (is_array($options)) { |
|
| 919 | + $options += $defaut_options; |
|
| 920 | + } else { |
|
| 921 | + $options = $defaut_options; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + if (is_array($args) and count($args)) { |
|
| 925 | + if (!function_exists('interdire_scripts')) { |
|
| 926 | + include_spip('inc/texte'); |
|
| 927 | + } |
|
| 928 | + if (!function_exists('echapper_html_suspect')) { |
|
| 929 | + include_spip('inc/texte_mini'); |
|
| 930 | + } |
|
| 931 | + foreach ($args as $name => $value) { |
|
| 932 | + if (strpos($text, (string) "@$name@") !== false) { |
|
| 933 | + if ($options['sanitize']) { |
|
| 934 | + $value = echapper_html_suspect($value); |
|
| 935 | + $value = interdire_scripts($value, -1); |
|
| 936 | + } |
|
| 937 | + if (!empty($options['class'])) { |
|
| 938 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 939 | + } |
|
| 940 | + $text = str_replace("@$name@", $value, $text); |
|
| 941 | + unset($args[$name]); |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 945 | + // (chaines de langues pas a jour) |
|
| 946 | + if ($args) { |
|
| 947 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 952 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 953 | + } else { |
|
| 954 | + return $text; |
|
| 955 | + } |
|
| 957 | 956 | } |
| 958 | 957 | |
| 959 | 958 | |
@@ -967,13 +966,13 @@ discard block |
||
| 967 | 966 | * @return string |
| 968 | 967 | */ |
| 969 | 968 | function joli_repertoire($rep) { |
| 970 | - $a = substr($rep, 0, 1); |
|
| 971 | - if ($a <> '.' and $a <> '/') { |
|
| 972 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 973 | - } |
|
| 974 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 969 | + $a = substr($rep, 0, 1); |
|
| 970 | + if ($a <> '.' and $a <> '/') { |
|
| 971 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 972 | + } |
|
| 973 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 975 | 974 | |
| 976 | - return $rep; |
|
| 975 | + return $rep; |
|
| 977 | 976 | } |
| 978 | 977 | |
| 979 | 978 | |
@@ -998,33 +997,33 @@ discard block |
||
| 998 | 997 | * @return float|int|string|void |
| 999 | 998 | */ |
| 1000 | 999 | function spip_timer($t = 'rien', $raw = false) { |
| 1001 | - static $time; |
|
| 1002 | - $a = time(); |
|
| 1003 | - $b = microtime(); |
|
| 1004 | - // microtime peut contenir les microsecondes et le temps |
|
| 1005 | - $b = explode(' ', $b); |
|
| 1006 | - if (count($b) == 2) { |
|
| 1007 | - $a = end($b); |
|
| 1008 | - } // plus precis ! |
|
| 1009 | - $b = reset($b); |
|
| 1010 | - if (!isset($time[$t])) { |
|
| 1011 | - $time[$t] = $a + $b; |
|
| 1012 | - } else { |
|
| 1013 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1014 | - unset($time[$t]); |
|
| 1000 | + static $time; |
|
| 1001 | + $a = time(); |
|
| 1002 | + $b = microtime(); |
|
| 1003 | + // microtime peut contenir les microsecondes et le temps |
|
| 1004 | + $b = explode(' ', $b); |
|
| 1005 | + if (count($b) == 2) { |
|
| 1006 | + $a = end($b); |
|
| 1007 | + } // plus precis ! |
|
| 1008 | + $b = reset($b); |
|
| 1009 | + if (!isset($time[$t])) { |
|
| 1010 | + $time[$t] = $a + $b; |
|
| 1011 | + } else { |
|
| 1012 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 1013 | + unset($time[$t]); |
|
| 1015 | 1014 | # echo "'$p'";exit; |
| 1016 | - if ($raw) { |
|
| 1017 | - return $p; |
|
| 1018 | - } |
|
| 1019 | - if ($p < 1000) { |
|
| 1020 | - $s = ''; |
|
| 1021 | - } else { |
|
| 1022 | - $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1023 | - $p -= ($x * 1000); |
|
| 1024 | - } |
|
| 1015 | + if ($raw) { |
|
| 1016 | + return $p; |
|
| 1017 | + } |
|
| 1018 | + if ($p < 1000) { |
|
| 1019 | + $s = ''; |
|
| 1020 | + } else { |
|
| 1021 | + $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1022 | + $p -= ($x * 1000); |
|
| 1023 | + } |
|
| 1025 | 1024 | |
| 1026 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1027 | - } |
|
| 1025 | + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1026 | + } |
|
| 1028 | 1027 | } |
| 1029 | 1028 | |
| 1030 | 1029 | |
@@ -1032,21 +1031,21 @@ discard block |
||
| 1032 | 1031 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1033 | 1032 | // https://code.spip.net/@spip_touch |
| 1034 | 1033 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1035 | - if ($duree) { |
|
| 1036 | - clearstatcache(); |
|
| 1037 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1038 | - return false; |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - if ($touch !== false) { |
|
| 1042 | - if (!@touch($fichier)) { |
|
| 1043 | - spip_unlink($fichier); |
|
| 1044 | - @touch($fichier); |
|
| 1045 | - }; |
|
| 1046 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1047 | - } |
|
| 1034 | + if ($duree) { |
|
| 1035 | + clearstatcache(); |
|
| 1036 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1037 | + return false; |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + if ($touch !== false) { |
|
| 1041 | + if (!@touch($fichier)) { |
|
| 1042 | + spip_unlink($fichier); |
|
| 1043 | + @touch($fichier); |
|
| 1044 | + }; |
|
| 1045 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1046 | + } |
|
| 1048 | 1047 | |
| 1049 | - return true; |
|
| 1048 | + return true; |
|
| 1050 | 1049 | } |
| 1051 | 1050 | |
| 1052 | 1051 | |
@@ -1057,11 +1056,11 @@ discard block |
||
| 1057 | 1056 | * @uses cron() |
| 1058 | 1057 | **/ |
| 1059 | 1058 | function action_cron() { |
| 1060 | - include_spip('inc/headers'); |
|
| 1061 | - http_response_code(204); // No Content |
|
| 1062 | - header('Connection: close'); |
|
| 1063 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1064 | - cron(); |
|
| 1059 | + include_spip('inc/headers'); |
|
| 1060 | + http_response_code(204); // No Content |
|
| 1061 | + header('Connection: close'); |
|
| 1062 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1063 | + cron(); |
|
| 1065 | 1064 | } |
| 1066 | 1065 | |
| 1067 | 1066 | /** |
@@ -1077,26 +1076,26 @@ discard block |
||
| 1077 | 1076 | * True si la tache a pu être effectuée |
| 1078 | 1077 | */ |
| 1079 | 1078 | function cron($taches = [], $taches_old = []) { |
| 1080 | - // si pas en mode cron force, laisser tomber. |
|
| 1081 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1082 | - return false; |
|
| 1083 | - } |
|
| 1084 | - if (!is_array($taches)) { |
|
| 1085 | - $taches = $taches_old; |
|
| 1086 | - } // compat anciens appels |
|
| 1087 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1088 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1089 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1090 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1091 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1092 | - return false; |
|
| 1093 | - } |
|
| 1094 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1095 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1096 | - return $genie($taches); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - return false; |
|
| 1079 | + // si pas en mode cron force, laisser tomber. |
|
| 1080 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1081 | + return false; |
|
| 1082 | + } |
|
| 1083 | + if (!is_array($taches)) { |
|
| 1084 | + $taches = $taches_old; |
|
| 1085 | + } // compat anciens appels |
|
| 1086 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1087 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1088 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1089 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1090 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1091 | + return false; |
|
| 1092 | + } |
|
| 1093 | + spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1094 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1095 | + return $genie($taches); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + return false; |
|
| 1100 | 1099 | } |
| 1101 | 1100 | |
| 1102 | 1101 | /** |
@@ -1128,17 +1127,17 @@ discard block |
||
| 1128 | 1127 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1129 | 1128 | */ |
| 1130 | 1129 | function job_queue_add( |
| 1131 | - $function, |
|
| 1132 | - $description, |
|
| 1133 | - $arguments = [], |
|
| 1134 | - $file = '', |
|
| 1135 | - $no_duplicate = false, |
|
| 1136 | - $time = 0, |
|
| 1137 | - $priority = 0 |
|
| 1130 | + $function, |
|
| 1131 | + $description, |
|
| 1132 | + $arguments = [], |
|
| 1133 | + $file = '', |
|
| 1134 | + $no_duplicate = false, |
|
| 1135 | + $time = 0, |
|
| 1136 | + $priority = 0 |
|
| 1138 | 1137 | ) { |
| 1139 | - include_spip('inc/queue'); |
|
| 1138 | + include_spip('inc/queue'); |
|
| 1140 | 1139 | |
| 1141 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1140 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1142 | 1141 | } |
| 1143 | 1142 | |
| 1144 | 1143 | /** |
@@ -1149,9 +1148,9 @@ discard block |
||
| 1149 | 1148 | * @return bool |
| 1150 | 1149 | */ |
| 1151 | 1150 | function job_queue_remove($id_job) { |
| 1152 | - include_spip('inc/queue'); |
|
| 1151 | + include_spip('inc/queue'); |
|
| 1153 | 1152 | |
| 1154 | - return queue_remove_job($id_job); |
|
| 1153 | + return queue_remove_job($id_job); |
|
| 1155 | 1154 | } |
| 1156 | 1155 | |
| 1157 | 1156 | /** |
@@ -1164,9 +1163,9 @@ discard block |
||
| 1164 | 1163 | * or an array of simple array to link multiples objet in one time |
| 1165 | 1164 | */ |
| 1166 | 1165 | function job_queue_link($id_job, $objets) { |
| 1167 | - include_spip('inc/queue'); |
|
| 1166 | + include_spip('inc/queue'); |
|
| 1168 | 1167 | |
| 1169 | - return queue_link_job($id_job, $objets); |
|
| 1168 | + return queue_link_job($id_job, $objets); |
|
| 1170 | 1169 | } |
| 1171 | 1170 | |
| 1172 | 1171 | |
@@ -1186,36 +1185,36 @@ discard block |
||
| 1186 | 1185 | * - `null` si la queue n'est pas encore initialisée |
| 1187 | 1186 | */ |
| 1188 | 1187 | function queue_sleep_time_to_next_job($force = null) { |
| 1189 | - static $queue_next_job_time = -1; |
|
| 1190 | - if ($force === true) { |
|
| 1191 | - $queue_next_job_time = -1; |
|
| 1192 | - } elseif ($force) { |
|
| 1193 | - $queue_next_job_time = $force; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - if ($queue_next_job_time == -1) { |
|
| 1197 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1198 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1199 | - } |
|
| 1200 | - // utiliser un cache memoire si dispo |
|
| 1201 | - if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1202 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1203 | - } else { |
|
| 1204 | - $queue_next_job_time = null; |
|
| 1205 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1206 | - $queue_next_job_time = intval($contenu); |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - if (is_null($queue_next_job_time)) { |
|
| 1212 | - return null; |
|
| 1213 | - } |
|
| 1214 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1215 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1188 | + static $queue_next_job_time = -1; |
|
| 1189 | + if ($force === true) { |
|
| 1190 | + $queue_next_job_time = -1; |
|
| 1191 | + } elseif ($force) { |
|
| 1192 | + $queue_next_job_time = $force; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + if ($queue_next_job_time == -1) { |
|
| 1196 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1197 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1198 | + } |
|
| 1199 | + // utiliser un cache memoire si dispo |
|
| 1200 | + if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1201 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1202 | + } else { |
|
| 1203 | + $queue_next_job_time = null; |
|
| 1204 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1205 | + $queue_next_job_time = intval($contenu); |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + if (is_null($queue_next_job_time)) { |
|
| 1211 | + return null; |
|
| 1212 | + } |
|
| 1213 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1214 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1219 | 1218 | } |
| 1220 | 1219 | |
| 1221 | 1220 | |
@@ -1227,11 +1226,11 @@ discard block |
||
| 1227 | 1226 | * @return string |
| 1228 | 1227 | */ |
| 1229 | 1228 | function quote_amp($u) { |
| 1230 | - return preg_replace( |
|
| 1231 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1232 | - '&', |
|
| 1233 | - $u |
|
| 1234 | - ); |
|
| 1229 | + return preg_replace( |
|
| 1230 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1231 | + '&', |
|
| 1232 | + $u |
|
| 1233 | + ); |
|
| 1235 | 1234 | } |
| 1236 | 1235 | |
| 1237 | 1236 | |
@@ -1254,27 +1253,27 @@ discard block |
||
| 1254 | 1253 | * Balise HTML `<script>` et son contenu |
| 1255 | 1254 | **/ |
| 1256 | 1255 | function http_script($script, $src = '', $noscript = '') { |
| 1257 | - static $done = []; |
|
| 1256 | + static $done = []; |
|
| 1258 | 1257 | |
| 1259 | - if ($src && !isset($done[$src])) { |
|
| 1260 | - $done[$src] = true; |
|
| 1261 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1262 | - $src = " src='$src'"; |
|
| 1263 | - } else { |
|
| 1264 | - $src = ''; |
|
| 1265 | - } |
|
| 1266 | - if ($script) { |
|
| 1267 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1268 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1269 | - '/*]]>*/'); |
|
| 1270 | - } |
|
| 1271 | - if ($noscript) { |
|
| 1272 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1273 | - } |
|
| 1258 | + if ($src && !isset($done[$src])) { |
|
| 1259 | + $done[$src] = true; |
|
| 1260 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1261 | + $src = " src='$src'"; |
|
| 1262 | + } else { |
|
| 1263 | + $src = ''; |
|
| 1264 | + } |
|
| 1265 | + if ($script) { |
|
| 1266 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1267 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1268 | + '/*]]>*/'); |
|
| 1269 | + } |
|
| 1270 | + if ($noscript) { |
|
| 1271 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1272 | + } |
|
| 1274 | 1273 | |
| 1275 | - return ($src or $script or $noscript) |
|
| 1276 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1277 | - : ''; |
|
| 1274 | + return ($src or $script or $noscript) |
|
| 1275 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1276 | + : ''; |
|
| 1278 | 1277 | } |
| 1279 | 1278 | |
| 1280 | 1279 | |
@@ -1309,7 +1308,7 @@ discard block |
||
| 1309 | 1308 | * Texte échappé |
| 1310 | 1309 | **/ |
| 1311 | 1310 | function texte_script(string $texte): string { |
| 1312 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1311 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1313 | 1312 | } |
| 1314 | 1313 | |
| 1315 | 1314 | |
@@ -1346,68 +1345,68 @@ discard block |
||
| 1346 | 1345 | * Liste des chemins, par ordre de priorité. |
| 1347 | 1346 | **/ |
| 1348 | 1347 | function _chemin($dir_path = null) { |
| 1349 | - static $path_base = null; |
|
| 1350 | - static $path_full = null; |
|
| 1351 | - if ($path_base == null) { |
|
| 1352 | - // Chemin standard depuis l'espace public |
|
| 1353 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1354 | - _DIR_RACINE . ':' . |
|
| 1355 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1356 | - _DIR_RACINE . 'prive/:' . |
|
| 1357 | - _DIR_RESTREINT; |
|
| 1358 | - // Ajouter squelettes/ |
|
| 1359 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1360 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1361 | - } |
|
| 1362 | - foreach (explode(':', $path) as $dir) { |
|
| 1363 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1364 | - $dir .= '/'; |
|
| 1365 | - } |
|
| 1366 | - $path_base[] = $dir; |
|
| 1367 | - } |
|
| 1368 | - $path_full = $path_base; |
|
| 1369 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1370 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1371 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1372 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1376 | - } |
|
| 1377 | - if ($dir_path === null) { |
|
| 1378 | - return $path_full; |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1382 | - $tete = ''; |
|
| 1383 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1384 | - $tete = array_shift($path_base); |
|
| 1385 | - } |
|
| 1386 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1387 | - $dirs = array_reverse($dirs); |
|
| 1388 | - foreach ($dirs as $dir_path) { |
|
| 1389 | - if (substr($dir_path, -1) != '/') { |
|
| 1390 | - $dir_path .= '/'; |
|
| 1391 | - } |
|
| 1392 | - if (!in_array($dir_path, $path_base)) { |
|
| 1393 | - array_unshift($path_base, $dir_path); |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - if (strlen($tete)) { |
|
| 1397 | - array_unshift($path_base, $tete); |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - $path_full = $path_base; |
|
| 1401 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1402 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1403 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1404 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1405 | - } |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1409 | - |
|
| 1410 | - return $path_full; |
|
| 1348 | + static $path_base = null; |
|
| 1349 | + static $path_full = null; |
|
| 1350 | + if ($path_base == null) { |
|
| 1351 | + // Chemin standard depuis l'espace public |
|
| 1352 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1353 | + _DIR_RACINE . ':' . |
|
| 1354 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1355 | + _DIR_RACINE . 'prive/:' . |
|
| 1356 | + _DIR_RESTREINT; |
|
| 1357 | + // Ajouter squelettes/ |
|
| 1358 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1359 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1360 | + } |
|
| 1361 | + foreach (explode(':', $path) as $dir) { |
|
| 1362 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1363 | + $dir .= '/'; |
|
| 1364 | + } |
|
| 1365 | + $path_base[] = $dir; |
|
| 1366 | + } |
|
| 1367 | + $path_full = $path_base; |
|
| 1368 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1369 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1370 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1371 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1375 | + } |
|
| 1376 | + if ($dir_path === null) { |
|
| 1377 | + return $path_full; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1381 | + $tete = ''; |
|
| 1382 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1383 | + $tete = array_shift($path_base); |
|
| 1384 | + } |
|
| 1385 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1386 | + $dirs = array_reverse($dirs); |
|
| 1387 | + foreach ($dirs as $dir_path) { |
|
| 1388 | + if (substr($dir_path, -1) != '/') { |
|
| 1389 | + $dir_path .= '/'; |
|
| 1390 | + } |
|
| 1391 | + if (!in_array($dir_path, $path_base)) { |
|
| 1392 | + array_unshift($path_base, $dir_path); |
|
| 1393 | + } |
|
| 1394 | + } |
|
| 1395 | + if (strlen($tete)) { |
|
| 1396 | + array_unshift($path_base, $tete); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + $path_full = $path_base; |
|
| 1400 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1401 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1402 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1403 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1408 | + |
|
| 1409 | + return $path_full; |
|
| 1411 | 1410 | } |
| 1412 | 1411 | |
| 1413 | 1412 | /** |
@@ -1420,78 +1419,78 @@ discard block |
||
| 1420 | 1419 | * @return array Liste de chemins |
| 1421 | 1420 | **/ |
| 1422 | 1421 | function creer_chemin() { |
| 1423 | - $path_a = _chemin(); |
|
| 1424 | - static $c = ''; |
|
| 1422 | + $path_a = _chemin(); |
|
| 1423 | + static $c = ''; |
|
| 1425 | 1424 | |
| 1426 | - // on calcule le chemin si le dossier skel a change |
|
| 1427 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1428 | - // assurer le non plantage lors de la montee de version : |
|
| 1429 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1430 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1431 | - } |
|
| 1425 | + // on calcule le chemin si le dossier skel a change |
|
| 1426 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1427 | + // assurer le non plantage lors de la montee de version : |
|
| 1428 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1429 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1430 | + } |
|
| 1432 | 1431 | |
| 1433 | - return $path_a; |
|
| 1432 | + return $path_a; |
|
| 1434 | 1433 | } |
| 1435 | 1434 | |
| 1436 | 1435 | |
| 1437 | 1436 | function lister_themes_prives() { |
| 1438 | - static $themes = null; |
|
| 1439 | - if (is_null($themes)) { |
|
| 1440 | - // si pas encore definie |
|
| 1441 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1442 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1443 | - } |
|
| 1444 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 1445 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1446 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1447 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1448 | - } else { |
|
| 1449 | - $prefs = []; |
|
| 1450 | - } |
|
| 1451 | - if (is_string($prefs)) { |
|
| 1452 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1453 | - } |
|
| 1454 | - if ( |
|
| 1455 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1456 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1457 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1458 | - ) { |
|
| 1459 | - array_unshift($themes, $theme); |
|
| 1460 | - } // placer le theme choisi en tete |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - return $themes; |
|
| 1437 | + static $themes = null; |
|
| 1438 | + if (is_null($themes)) { |
|
| 1439 | + // si pas encore definie |
|
| 1440 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1441 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1442 | + } |
|
| 1443 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 1444 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1445 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1446 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1447 | + } else { |
|
| 1448 | + $prefs = []; |
|
| 1449 | + } |
|
| 1450 | + if (is_string($prefs)) { |
|
| 1451 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1452 | + } |
|
| 1453 | + if ( |
|
| 1454 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1455 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1456 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1457 | + ) { |
|
| 1458 | + array_unshift($themes, $theme); |
|
| 1459 | + } // placer le theme choisi en tete |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + return $themes; |
|
| 1464 | 1463 | } |
| 1465 | 1464 | |
| 1466 | 1465 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1467 | - static $themefiles = []; |
|
| 1468 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1469 | - return $themefiles["$subdir$file"]; |
|
| 1470 | - } |
|
| 1471 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1472 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1473 | - if ( |
|
| 1474 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1475 | - and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1476 | - and $f = find_in_theme("$file_svg_generique") |
|
| 1477 | - ) { |
|
| 1478 | - if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1479 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1480 | - } |
|
| 1481 | - else { |
|
| 1482 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1483 | - } |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - $themes = lister_themes_prives(); |
|
| 1487 | - foreach ($themes as $theme) { |
|
| 1488 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1489 | - return $themefiles["$subdir$file"] = $f; |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1493 | - |
|
| 1494 | - return $themefiles["$subdir$file"] = ''; |
|
| 1466 | + static $themefiles = []; |
|
| 1467 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1468 | + return $themefiles["$subdir$file"]; |
|
| 1469 | + } |
|
| 1470 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1471 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1472 | + if ( |
|
| 1473 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1474 | + and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1475 | + and $f = find_in_theme("$file_svg_generique") |
|
| 1476 | + ) { |
|
| 1477 | + if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1478 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1479 | + } |
|
| 1480 | + else { |
|
| 1481 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1482 | + } |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + $themes = lister_themes_prives(); |
|
| 1486 | + foreach ($themes as $theme) { |
|
| 1487 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1488 | + return $themefiles["$subdir$file"] = $f; |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1492 | + |
|
| 1493 | + return $themefiles["$subdir$file"] = ''; |
|
| 1495 | 1494 | } |
| 1496 | 1495 | |
| 1497 | 1496 | |
@@ -1515,31 +1514,31 @@ discard block |
||
| 1515 | 1514 | * sinon chaîne vide. |
| 1516 | 1515 | **/ |
| 1517 | 1516 | function chemin_image($icone) { |
| 1518 | - static $icone_renommer; |
|
| 1519 | - if ($p = strpos($icone, '?')) { |
|
| 1520 | - $icone = substr($icone, 0, $p); |
|
| 1521 | - } |
|
| 1522 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1523 | - if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1524 | - return $icone; |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1528 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1529 | - return $f; |
|
| 1530 | - } |
|
| 1531 | - // sinon passer par le module de renommage |
|
| 1532 | - if (is_null($icone_renommer)) { |
|
| 1533 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1534 | - } |
|
| 1535 | - if ($icone_renommer) { |
|
| 1536 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1537 | - if (file_exists($icone)) { |
|
| 1538 | - return $icone; |
|
| 1539 | - } |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1517 | + static $icone_renommer; |
|
| 1518 | + if ($p = strpos($icone, '?')) { |
|
| 1519 | + $icone = substr($icone, 0, $p); |
|
| 1520 | + } |
|
| 1521 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1522 | + if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1523 | + return $icone; |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1527 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1528 | + return $f; |
|
| 1529 | + } |
|
| 1530 | + // sinon passer par le module de renommage |
|
| 1531 | + if (is_null($icone_renommer)) { |
|
| 1532 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1533 | + } |
|
| 1534 | + if ($icone_renommer) { |
|
| 1535 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1536 | + if (file_exists($icone)) { |
|
| 1537 | + return $icone; |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1543 | 1542 | } |
| 1544 | 1543 | |
| 1545 | 1544 | // |
@@ -1577,128 +1576,128 @@ discard block |
||
| 1577 | 1576 | * - false : fichier introuvable |
| 1578 | 1577 | **/ |
| 1579 | 1578 | function find_in_path($file, $dirname = '', $include = false) { |
| 1580 | - static $dirs = []; |
|
| 1581 | - static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1582 | - static $c = ''; |
|
| 1583 | - |
|
| 1584 | - if (!$file and !strlen($file)) { |
|
| 1585 | - return false; |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - // on calcule le chemin si le dossier skel a change |
|
| 1589 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1590 | - // assurer le non plantage lors de la montee de version : |
|
| 1591 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1592 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1596 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1597 | - return false; |
|
| 1598 | - } |
|
| 1599 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1600 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1601 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - $a = strrpos($file, '/'); |
|
| 1608 | - if ($a !== false) { |
|
| 1609 | - $dirname .= substr($file, 0, ++$a); |
|
| 1610 | - $file = substr($file, $a); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - foreach (creer_chemin() as $dir) { |
|
| 1614 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1615 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1616 | - } |
|
| 1617 | - if ($dirs[$a]) { |
|
| 1618 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1619 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1620 | - include_once _ROOT_CWD . $a; |
|
| 1621 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1622 | - } |
|
| 1623 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1624 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1625 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1626 | - return $a; |
|
| 1627 | - } |
|
| 1628 | - define('_SAUVER_CHEMIN', true); |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1632 | - } |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - if ($include) { |
|
| 1637 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1638 | - if ($include === 'required') { |
|
| 1639 | - echo '<pre>', |
|
| 1640 | - '<strong>Erreur Fatale</strong><br />'; |
|
| 1641 | - if (function_exists('debug_print_backtrace')) { |
|
| 1642 | - echo debug_print_backtrace(); |
|
| 1643 | - } |
|
| 1644 | - echo '</pre>'; |
|
| 1645 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1646 | - } |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1650 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1651 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1652 | - return false; |
|
| 1653 | - } |
|
| 1654 | - define('_SAUVER_CHEMIN', true); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1579 | + static $dirs = []; |
|
| 1580 | + static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1581 | + static $c = ''; |
|
| 1582 | + |
|
| 1583 | + if (!$file and !strlen($file)) { |
|
| 1584 | + return false; |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + // on calcule le chemin si le dossier skel a change |
|
| 1588 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1589 | + // assurer le non plantage lors de la montee de version : |
|
| 1590 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1591 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1595 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1596 | + return false; |
|
| 1597 | + } |
|
| 1598 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1599 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1600 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + $a = strrpos($file, '/'); |
|
| 1607 | + if ($a !== false) { |
|
| 1608 | + $dirname .= substr($file, 0, ++$a); |
|
| 1609 | + $file = substr($file, $a); |
|
| 1610 | + } |
|
| 1611 | + |
|
| 1612 | + foreach (creer_chemin() as $dir) { |
|
| 1613 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1614 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1615 | + } |
|
| 1616 | + if ($dirs[$a]) { |
|
| 1617 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1618 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1619 | + include_once _ROOT_CWD . $a; |
|
| 1620 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1621 | + } |
|
| 1622 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1623 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1624 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1625 | + return $a; |
|
| 1626 | + } |
|
| 1627 | + define('_SAUVER_CHEMIN', true); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1631 | + } |
|
| 1632 | + } |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + if ($include) { |
|
| 1636 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1637 | + if ($include === 'required') { |
|
| 1638 | + echo '<pre>', |
|
| 1639 | + '<strong>Erreur Fatale</strong><br />'; |
|
| 1640 | + if (function_exists('debug_print_backtrace')) { |
|
| 1641 | + echo debug_print_backtrace(); |
|
| 1642 | + } |
|
| 1643 | + echo '</pre>'; |
|
| 1644 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1645 | + } |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1649 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1650 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1651 | + return false; |
|
| 1652 | + } |
|
| 1653 | + define('_SAUVER_CHEMIN', true); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1658 | 1657 | } |
| 1659 | 1658 | |
| 1660 | 1659 | function clear_path_cache() { |
| 1661 | - $GLOBALS['path_files'] = []; |
|
| 1662 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1660 | + $GLOBALS['path_files'] = []; |
|
| 1661 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1663 | 1662 | } |
| 1664 | 1663 | |
| 1665 | 1664 | function load_path_cache() { |
| 1666 | - // charger le path des plugins |
|
| 1667 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1668 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1669 | - } |
|
| 1670 | - $GLOBALS['path_files'] = []; |
|
| 1671 | - // si le visiteur est admin, |
|
| 1672 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1673 | - if ( |
|
| 1674 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1675 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1676 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1677 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1678 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1679 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1680 | - !_request('var_mode') |
|
| 1681 | - ) { |
|
| 1682 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1683 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1684 | - // mais si semble corrompu on relit avec un verrou |
|
| 1685 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1686 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1687 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1688 | - $GLOBALS['path_files'] = []; |
|
| 1689 | - } |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1692 | - } |
|
| 1665 | + // charger le path des plugins |
|
| 1666 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1667 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1668 | + } |
|
| 1669 | + $GLOBALS['path_files'] = []; |
|
| 1670 | + // si le visiteur est admin, |
|
| 1671 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1672 | + if ( |
|
| 1673 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1674 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1675 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1676 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1677 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1678 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1679 | + !_request('var_mode') |
|
| 1680 | + ) { |
|
| 1681 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1682 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1683 | + // mais si semble corrompu on relit avec un verrou |
|
| 1684 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1685 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1686 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1687 | + $GLOBALS['path_files'] = []; |
|
| 1688 | + } |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1693 | 1692 | } |
| 1694 | 1693 | |
| 1695 | 1694 | function save_path_cache() { |
| 1696 | - if ( |
|
| 1697 | - defined('_SAUVER_CHEMIN') |
|
| 1698 | - and _SAUVER_CHEMIN |
|
| 1699 | - ) { |
|
| 1700 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1701 | - } |
|
| 1695 | + if ( |
|
| 1696 | + defined('_SAUVER_CHEMIN') |
|
| 1697 | + and _SAUVER_CHEMIN |
|
| 1698 | + ) { |
|
| 1699 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1700 | + } |
|
| 1702 | 1701 | } |
| 1703 | 1702 | |
| 1704 | 1703 | |
@@ -1718,33 +1717,33 @@ discard block |
||
| 1718 | 1717 | * @return array |
| 1719 | 1718 | */ |
| 1720 | 1719 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1721 | - $liste_fichiers = []; |
|
| 1722 | - $maxfiles = 10000; |
|
| 1723 | - |
|
| 1724 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1725 | - // on a pas encore inclus flock.php |
|
| 1726 | - if (!function_exists('preg_files')) { |
|
| 1727 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - // Parcourir le chemin |
|
| 1731 | - foreach (creer_chemin() as $d) { |
|
| 1732 | - $f = $d . $dir; |
|
| 1733 | - if (@is_dir($f)) { |
|
| 1734 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1735 | - foreach ($liste as $chemin) { |
|
| 1736 | - $nom = basename($chemin); |
|
| 1737 | - // ne prendre que les fichiers pas deja trouves |
|
| 1738 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1739 | - // les autres sont donc masques |
|
| 1740 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1741 | - $liste_fichiers[$nom] = $chemin; |
|
| 1742 | - } |
|
| 1743 | - } |
|
| 1744 | - } |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - return $liste_fichiers; |
|
| 1720 | + $liste_fichiers = []; |
|
| 1721 | + $maxfiles = 10000; |
|
| 1722 | + |
|
| 1723 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1724 | + // on a pas encore inclus flock.php |
|
| 1725 | + if (!function_exists('preg_files')) { |
|
| 1726 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + // Parcourir le chemin |
|
| 1730 | + foreach (creer_chemin() as $d) { |
|
| 1731 | + $f = $d . $dir; |
|
| 1732 | + if (@is_dir($f)) { |
|
| 1733 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1734 | + foreach ($liste as $chemin) { |
|
| 1735 | + $nom = basename($chemin); |
|
| 1736 | + // ne prendre que les fichiers pas deja trouves |
|
| 1737 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1738 | + // les autres sont donc masques |
|
| 1739 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1740 | + $liste_fichiers[$nom] = $chemin; |
|
| 1741 | + } |
|
| 1742 | + } |
|
| 1743 | + } |
|
| 1744 | + } |
|
| 1745 | + |
|
| 1746 | + return $liste_fichiers; |
|
| 1748 | 1747 | } |
| 1749 | 1748 | |
| 1750 | 1749 | /** |
@@ -1756,17 +1755,17 @@ discard block |
||
| 1756 | 1755 | * @return bool |
| 1757 | 1756 | */ |
| 1758 | 1757 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1759 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 1758 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 1760 | 1759 | |
| 1761 | - if (in_array($nom, $autsanscookie)) { |
|
| 1762 | - if (test_espace_prive()) { |
|
| 1763 | - include_spip('base/connect_sql'); |
|
| 1764 | - if (!$strict or !spip_connect()) { |
|
| 1765 | - return true; |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - } |
|
| 1769 | - return false; |
|
| 1760 | + if (in_array($nom, $autsanscookie)) { |
|
| 1761 | + if (test_espace_prive()) { |
|
| 1762 | + include_spip('base/connect_sql'); |
|
| 1763 | + if (!$strict or !spip_connect()) { |
|
| 1764 | + return true; |
|
| 1765 | + } |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + return false; |
|
| 1770 | 1769 | } |
| 1771 | 1770 | |
| 1772 | 1771 | /** |
@@ -1792,96 +1791,96 @@ discard block |
||
| 1792 | 1791 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip) |
| 1793 | 1792 | */ |
| 1794 | 1793 | function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1795 | - if ($public === null) { |
|
| 1796 | - $public = !test_espace_prive(); |
|
| 1797 | - } |
|
| 1798 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1799 | - |
|
| 1800 | - if (!$public) { |
|
| 1801 | - if (!$entite) { |
|
| 1802 | - return ''; |
|
| 1803 | - } |
|
| 1804 | - if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1805 | - include_spip('inc/urls'); |
|
| 1806 | - } |
|
| 1807 | - $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1808 | - } else { |
|
| 1809 | - if ($type === null) { |
|
| 1810 | - $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - $f = charger_fonction($type, 'urls', true); |
|
| 1814 | - // se rabattre sur les urls page si les urls perso non dispo |
|
| 1815 | - if (!$f) { |
|
| 1816 | - $f = charger_fonction('page', 'urls', true); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1820 | - // sinon on veut effectuer le passage id ==> URL |
|
| 1821 | - if (!$entite) { |
|
| 1822 | - return $f; |
|
| 1823 | - } |
|
| 1824 | - |
|
| 1825 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1826 | - // base distante |
|
| 1827 | - if ( |
|
| 1828 | - is_string($public) |
|
| 1829 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1830 | - ) { |
|
| 1831 | - $f = $g; |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1835 | - } |
|
| 1836 | - if ($res) { |
|
| 1837 | - return $res; |
|
| 1838 | - } |
|
| 1839 | - // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1840 | - if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1841 | - if (!function_exists($f .= '_dist')) { |
|
| 1842 | - $f = ''; |
|
| 1843 | - } |
|
| 1844 | - } |
|
| 1845 | - if ($f) { |
|
| 1846 | - $url = $f($id, $args, $ancre); |
|
| 1847 | - if (strlen($args)) { |
|
| 1848 | - $url .= strstr($url, '?') |
|
| 1849 | - ? '&' . $args |
|
| 1850 | - : '?' . $args; |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - return $url; |
|
| 1854 | - } |
|
| 1855 | - // On a ete gentil mais la .... |
|
| 1856 | - spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1857 | - |
|
| 1858 | - return ''; |
|
| 1794 | + if ($public === null) { |
|
| 1795 | + $public = !test_espace_prive(); |
|
| 1796 | + } |
|
| 1797 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1798 | + |
|
| 1799 | + if (!$public) { |
|
| 1800 | + if (!$entite) { |
|
| 1801 | + return ''; |
|
| 1802 | + } |
|
| 1803 | + if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1804 | + include_spip('inc/urls'); |
|
| 1805 | + } |
|
| 1806 | + $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1807 | + } else { |
|
| 1808 | + if ($type === null) { |
|
| 1809 | + $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + $f = charger_fonction($type, 'urls', true); |
|
| 1813 | + // se rabattre sur les urls page si les urls perso non dispo |
|
| 1814 | + if (!$f) { |
|
| 1815 | + $f = charger_fonction('page', 'urls', true); |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1819 | + // sinon on veut effectuer le passage id ==> URL |
|
| 1820 | + if (!$entite) { |
|
| 1821 | + return $f; |
|
| 1822 | + } |
|
| 1823 | + |
|
| 1824 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1825 | + // base distante |
|
| 1826 | + if ( |
|
| 1827 | + is_string($public) |
|
| 1828 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1829 | + ) { |
|
| 1830 | + $f = $g; |
|
| 1831 | + } |
|
| 1832 | + |
|
| 1833 | + $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1834 | + } |
|
| 1835 | + if ($res) { |
|
| 1836 | + return $res; |
|
| 1837 | + } |
|
| 1838 | + // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1839 | + if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1840 | + if (!function_exists($f .= '_dist')) { |
|
| 1841 | + $f = ''; |
|
| 1842 | + } |
|
| 1843 | + } |
|
| 1844 | + if ($f) { |
|
| 1845 | + $url = $f($id, $args, $ancre); |
|
| 1846 | + if (strlen($args)) { |
|
| 1847 | + $url .= strstr($url, '?') |
|
| 1848 | + ? '&' . $args |
|
| 1849 | + : '?' . $args; |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + return $url; |
|
| 1853 | + } |
|
| 1854 | + // On a ete gentil mais la .... |
|
| 1855 | + spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1856 | + |
|
| 1857 | + return ''; |
|
| 1859 | 1858 | } |
| 1860 | 1859 | |
| 1861 | 1860 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1862 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1863 | - $url = generer_url_ecrire($exec, $args); |
|
| 1864 | - if (intval($id)) { |
|
| 1865 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1866 | - } else { |
|
| 1867 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1868 | - } |
|
| 1869 | - if ($ancre) { |
|
| 1870 | - $url = ancre_url($url, $ancre); |
|
| 1871 | - } |
|
| 1861 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1862 | + $url = generer_url_ecrire($exec, $args); |
|
| 1863 | + if (intval($id)) { |
|
| 1864 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1865 | + } else { |
|
| 1866 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1867 | + } |
|
| 1868 | + if ($ancre) { |
|
| 1869 | + $url = ancre_url($url, $ancre); |
|
| 1870 | + } |
|
| 1872 | 1871 | |
| 1873 | - return $url; |
|
| 1872 | + return $url; |
|
| 1874 | 1873 | } |
| 1875 | 1874 | |
| 1876 | 1875 | // https://code.spip.net/@urls_connect_dist |
| 1877 | 1876 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1878 | - include_spip('base/connect_sql'); |
|
| 1879 | - $id_type = id_table_objet($entite, $public); |
|
| 1877 | + include_spip('base/connect_sql'); |
|
| 1878 | + $id_type = id_table_objet($entite, $public); |
|
| 1880 | 1879 | |
| 1881 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1882 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1883 | - . (!$args ? '' : "&$args") |
|
| 1884 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1880 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1881 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1882 | + . (!$args ? '' : "&$args") |
|
| 1883 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1885 | 1884 | } |
| 1886 | 1885 | |
| 1887 | 1886 | |
@@ -1892,32 +1891,32 @@ discard block |
||
| 1892 | 1891 | * @return string |
| 1893 | 1892 | */ |
| 1894 | 1893 | function urlencode_1738($url) { |
| 1895 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1896 | - $uri = ''; |
|
| 1897 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1898 | - if (ord($a = $url[$i]) > 127) { |
|
| 1899 | - $a = rawurlencode($a); |
|
| 1900 | - } |
|
| 1901 | - $uri .= $a; |
|
| 1902 | - } |
|
| 1903 | - $url = $uri; |
|
| 1904 | - } |
|
| 1894 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1895 | + $uri = ''; |
|
| 1896 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1897 | + if (ord($a = $url[$i]) > 127) { |
|
| 1898 | + $a = rawurlencode($a); |
|
| 1899 | + } |
|
| 1900 | + $uri .= $a; |
|
| 1901 | + } |
|
| 1902 | + $url = $uri; |
|
| 1903 | + } |
|
| 1905 | 1904 | |
| 1906 | - return quote_amp($url); |
|
| 1905 | + return quote_amp($url); |
|
| 1907 | 1906 | } |
| 1908 | 1907 | |
| 1909 | 1908 | // https://code.spip.net/@generer_url_entite_absolue |
| 1910 | 1909 | function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) { |
| 1911 | - if (!$connect) { |
|
| 1912 | - $connect = true; |
|
| 1913 | - } |
|
| 1914 | - $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1915 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1916 | - include_spip('inc/filtres_mini'); |
|
| 1917 | - $h = url_absolue($h); |
|
| 1918 | - } |
|
| 1910 | + if (!$connect) { |
|
| 1911 | + $connect = true; |
|
| 1912 | + } |
|
| 1913 | + $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1914 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1915 | + include_spip('inc/filtres_mini'); |
|
| 1916 | + $h = url_absolue($h); |
|
| 1917 | + } |
|
| 1919 | 1918 | |
| 1920 | - return $h; |
|
| 1919 | + return $h; |
|
| 1921 | 1920 | } |
| 1922 | 1921 | |
| 1923 | 1922 | |
@@ -1933,11 +1932,11 @@ discard block |
||
| 1933 | 1932 | * true si la valeur est considérée active ; false sinon. |
| 1934 | 1933 | **/ |
| 1935 | 1934 | function test_valeur_serveur($truc) { |
| 1936 | - if (!$truc) { |
|
| 1937 | - return false; |
|
| 1938 | - } |
|
| 1935 | + if (!$truc) { |
|
| 1936 | + return false; |
|
| 1937 | + } |
|
| 1939 | 1938 | |
| 1940 | - return (strtolower($truc) !== 'off'); |
|
| 1939 | + return (strtolower($truc) !== 'off'); |
|
| 1941 | 1940 | } |
| 1942 | 1941 | |
| 1943 | 1942 | // |
@@ -1965,82 +1964,82 @@ discard block |
||
| 1965 | 1964 | */ |
| 1966 | 1965 | function url_de_base($profondeur = null) { |
| 1967 | 1966 | |
| 1968 | - static $url = []; |
|
| 1969 | - if (is_array($profondeur)) { |
|
| 1970 | - return $url = $profondeur; |
|
| 1971 | - } |
|
| 1972 | - if ($profondeur === false) { |
|
| 1973 | - return $url; |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - if (is_null($profondeur)) { |
|
| 1977 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - if (isset($url[$profondeur])) { |
|
| 1981 | - return $url[$profondeur]; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - $http = 'http'; |
|
| 1985 | - |
|
| 1986 | - if ( |
|
| 1987 | - isset($_SERVER['SCRIPT_URI']) |
|
| 1988 | - and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 1989 | - ) { |
|
| 1990 | - $http = 'https'; |
|
| 1991 | - } elseif ( |
|
| 1992 | - isset($_SERVER['HTTPS']) |
|
| 1993 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1994 | - ) { |
|
| 1995 | - $http = 'https'; |
|
| 1996 | - } |
|
| 1997 | - |
|
| 1998 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 1999 | - $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 2000 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2001 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2002 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 2003 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2004 | - $http = $scheme; |
|
| 2005 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 2006 | - } |
|
| 2007 | - } |
|
| 2008 | - if ( |
|
| 2009 | - isset($_SERVER['SERVER_PORT']) |
|
| 2010 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 2011 | - and strpos($host, ':') == false |
|
| 2012 | - ) { |
|
| 2013 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2014 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 2015 | - } |
|
| 2016 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2017 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2018 | - } |
|
| 2019 | - if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2020 | - $host .= ":$port"; |
|
| 2021 | - } |
|
| 2022 | - if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2023 | - $host .= ":$port"; |
|
| 2024 | - } |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2028 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2029 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2030 | - } else { |
|
| 2031 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2032 | - if ( |
|
| 2033 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2034 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2035 | - ) { |
|
| 2036 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2037 | - } |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2042 | - |
|
| 2043 | - return $url[$profondeur]; |
|
| 1967 | + static $url = []; |
|
| 1968 | + if (is_array($profondeur)) { |
|
| 1969 | + return $url = $profondeur; |
|
| 1970 | + } |
|
| 1971 | + if ($profondeur === false) { |
|
| 1972 | + return $url; |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + if (is_null($profondeur)) { |
|
| 1976 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 1977 | + } |
|
| 1978 | + |
|
| 1979 | + if (isset($url[$profondeur])) { |
|
| 1980 | + return $url[$profondeur]; |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + $http = 'http'; |
|
| 1984 | + |
|
| 1985 | + if ( |
|
| 1986 | + isset($_SERVER['SCRIPT_URI']) |
|
| 1987 | + and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 1988 | + ) { |
|
| 1989 | + $http = 'https'; |
|
| 1990 | + } elseif ( |
|
| 1991 | + isset($_SERVER['HTTPS']) |
|
| 1992 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1993 | + ) { |
|
| 1994 | + $http = 'https'; |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 1998 | + $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 1999 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2000 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2001 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 2002 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2003 | + $http = $scheme; |
|
| 2004 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 2005 | + } |
|
| 2006 | + } |
|
| 2007 | + if ( |
|
| 2008 | + isset($_SERVER['SERVER_PORT']) |
|
| 2009 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 2010 | + and strpos($host, ':') == false |
|
| 2011 | + ) { |
|
| 2012 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2013 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 2014 | + } |
|
| 2015 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2016 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2017 | + } |
|
| 2018 | + if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2019 | + $host .= ":$port"; |
|
| 2020 | + } |
|
| 2021 | + if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2022 | + $host .= ":$port"; |
|
| 2023 | + } |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2027 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2028 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2029 | + } else { |
|
| 2030 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2031 | + if ( |
|
| 2032 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2033 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2034 | + ) { |
|
| 2035 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2036 | + } |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2041 | + |
|
| 2042 | + return $url[$profondeur]; |
|
| 2044 | 2043 | } |
| 2045 | 2044 | |
| 2046 | 2045 | /** |
@@ -2053,26 +2052,26 @@ discard block |
||
| 2053 | 2052 | * @return string |
| 2054 | 2053 | */ |
| 2055 | 2054 | function url_de_($http, $host, $request, $prof = 0) { |
| 2056 | - $prof = max($prof, 0); |
|
| 2055 | + $prof = max($prof, 0); |
|
| 2057 | 2056 | |
| 2058 | - $myself = ltrim($request, '/'); |
|
| 2059 | - # supprimer la chaine de GET |
|
| 2060 | - [$myself] = explode('?', $myself); |
|
| 2061 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2062 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2063 | - if (strpos($myself, '://') !== false) { |
|
| 2064 | - $myself = explode('://', $myself); |
|
| 2065 | - array_shift($myself); |
|
| 2066 | - $myself = implode('://', $myself); |
|
| 2067 | - $myself = explode('/', $myself); |
|
| 2068 | - array_shift($myself); |
|
| 2069 | - $myself = implode('/', $myself); |
|
| 2070 | - } |
|
| 2071 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2057 | + $myself = ltrim($request, '/'); |
|
| 2058 | + # supprimer la chaine de GET |
|
| 2059 | + [$myself] = explode('?', $myself); |
|
| 2060 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2061 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2062 | + if (strpos($myself, '://') !== false) { |
|
| 2063 | + $myself = explode('://', $myself); |
|
| 2064 | + array_shift($myself); |
|
| 2065 | + $myself = implode('://', $myself); |
|
| 2066 | + $myself = explode('/', $myself); |
|
| 2067 | + array_shift($myself); |
|
| 2068 | + $myself = implode('/', $myself); |
|
| 2069 | + } |
|
| 2070 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2072 | 2071 | |
| 2073 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2072 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2074 | 2073 | |
| 2075 | - return $url; |
|
| 2074 | + return $url; |
|
| 2076 | 2075 | } |
| 2077 | 2076 | |
| 2078 | 2077 | |
@@ -2107,25 +2106,25 @@ discard block |
||
| 2107 | 2106 | * @return string URL |
| 2108 | 2107 | **/ |
| 2109 | 2108 | function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) { |
| 2110 | - if (!$rel) { |
|
| 2111 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2112 | - } else { |
|
| 2113 | - if (!is_string($rel)) { |
|
| 2114 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2115 | - } |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2119 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2120 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2121 | - } elseif ($args) { |
|
| 2122 | - $args = "?$args"; |
|
| 2123 | - } |
|
| 2124 | - if ($ancre) { |
|
| 2125 | - $args .= "#$ancre"; |
|
| 2126 | - } |
|
| 2127 | - |
|
| 2128 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2109 | + if (!$rel) { |
|
| 2110 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2111 | + } else { |
|
| 2112 | + if (!is_string($rel)) { |
|
| 2113 | + $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2114 | + } |
|
| 2115 | + } |
|
| 2116 | + |
|
| 2117 | + [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2118 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2119 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2120 | + } elseif ($args) { |
|
| 2121 | + $args = "?$args"; |
|
| 2122 | + } |
|
| 2123 | + if ($ancre) { |
|
| 2124 | + $args .= "#$ancre"; |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2129 | 2128 | } |
| 2130 | 2129 | |
| 2131 | 2130 | // |
@@ -2147,15 +2146,15 @@ discard block |
||
| 2147 | 2146 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2148 | 2147 | **/ |
| 2149 | 2148 | function get_spip_script($default = '') { |
| 2150 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2151 | - return 'spip.php'; |
|
| 2152 | - } |
|
| 2153 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2154 | - if (_SPIP_SCRIPT) { |
|
| 2155 | - return _SPIP_SCRIPT; |
|
| 2156 | - } else { |
|
| 2157 | - return $default; |
|
| 2158 | - } |
|
| 2149 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2150 | + return 'spip.php'; |
|
| 2151 | + } |
|
| 2152 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2153 | + if (_SPIP_SCRIPT) { |
|
| 2154 | + return _SPIP_SCRIPT; |
|
| 2155 | + } else { |
|
| 2156 | + return $default; |
|
| 2157 | + } |
|
| 2159 | 2158 | } |
| 2160 | 2159 | |
| 2161 | 2160 | /** |
@@ -2184,39 +2183,39 @@ discard block |
||
| 2184 | 2183 | * @return string URL |
| 2185 | 2184 | **/ |
| 2186 | 2185 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 2187 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2188 | - // standardiser vers la nouvelle API |
|
| 2189 | - |
|
| 2190 | - if (!$action) { |
|
| 2191 | - $action = get_spip_script(); |
|
| 2192 | - } |
|
| 2193 | - if ($script) { |
|
| 2194 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2195 | - } |
|
| 2196 | - |
|
| 2197 | - if ($args) { |
|
| 2198 | - if (is_array($args)) { |
|
| 2199 | - $r = ''; |
|
| 2200 | - foreach ($args as $k => $v) { |
|
| 2201 | - $r .= '&' . $k . '=' . $v; |
|
| 2202 | - } |
|
| 2203 | - $args = substr($r, 1); |
|
| 2204 | - } |
|
| 2205 | - $action .= |
|
| 2206 | - (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2207 | - } |
|
| 2208 | - if (!$no_entities) { |
|
| 2209 | - $action = quote_amp($action); |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2213 | - return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2186 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2187 | + // standardiser vers la nouvelle API |
|
| 2188 | + |
|
| 2189 | + if (!$action) { |
|
| 2190 | + $action = get_spip_script(); |
|
| 2191 | + } |
|
| 2192 | + if ($script) { |
|
| 2193 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2194 | + } |
|
| 2195 | + |
|
| 2196 | + if ($args) { |
|
| 2197 | + if (is_array($args)) { |
|
| 2198 | + $r = ''; |
|
| 2199 | + foreach ($args as $k => $v) { |
|
| 2200 | + $r .= '&' . $k . '=' . $v; |
|
| 2201 | + } |
|
| 2202 | + $args = substr($r, 1); |
|
| 2203 | + } |
|
| 2204 | + $action .= |
|
| 2205 | + (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2206 | + } |
|
| 2207 | + if (!$no_entities) { |
|
| 2208 | + $action = quote_amp($action); |
|
| 2209 | + } |
|
| 2210 | + |
|
| 2211 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2212 | + return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2214 | 2213 | } |
| 2215 | 2214 | |
| 2216 | 2215 | // https://code.spip.net/@generer_url_prive |
| 2217 | 2216 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2218 | 2217 | |
| 2219 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2218 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2220 | 2219 | } |
| 2221 | 2220 | |
| 2222 | 2221 | // Pour les formulaires en methode POST, |
@@ -2241,19 +2240,19 @@ discard block |
||
| 2241 | 2240 | **/ |
| 2242 | 2241 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2243 | 2242 | |
| 2244 | - $script1 = explode('&', $script); |
|
| 2245 | - $script1 = reset($script1); |
|
| 2243 | + $script1 = explode('&', $script); |
|
| 2244 | + $script1 = reset($script1); |
|
| 2246 | 2245 | |
| 2247 | - return "<form action='" |
|
| 2248 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2249 | - . "' " |
|
| 2250 | - . ($atts ?: " method='post'") |
|
| 2251 | - . "><div>\n" |
|
| 2252 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2253 | - . $corps |
|
| 2254 | - . (!$submit ? '' : |
|
| 2255 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2256 | - . "</div></form>\n"; |
|
| 2246 | + return "<form action='" |
|
| 2247 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2248 | + . "' " |
|
| 2249 | + . ($atts ?: " method='post'") |
|
| 2250 | + . "><div>\n" |
|
| 2251 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2252 | + . $corps |
|
| 2253 | + . (!$submit ? '' : |
|
| 2254 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2255 | + . "</div></form>\n"; |
|
| 2257 | 2256 | } |
| 2258 | 2257 | |
| 2259 | 2258 | /** |
@@ -2270,22 +2269,22 @@ discard block |
||
| 2270 | 2269 | * @return string |
| 2271 | 2270 | */ |
| 2272 | 2271 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2273 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2274 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2275 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2276 | - $h = (_DIR_RACINE and !$public) |
|
| 2277 | - ? generer_url_ecrire(_request('exec')) |
|
| 2278 | - : generer_url_public(); |
|
| 2272 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2273 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2274 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2275 | + $h = (_DIR_RACINE and !$public) |
|
| 2276 | + ? generer_url_ecrire(_request('exec')) |
|
| 2277 | + : generer_url_public(); |
|
| 2279 | 2278 | |
| 2280 | - return "\n<form action='" . |
|
| 2281 | - $h . |
|
| 2282 | - "'" . |
|
| 2283 | - $atts . |
|
| 2284 | - ">\n" . |
|
| 2285 | - '<div>' . |
|
| 2286 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2287 | - $corps . |
|
| 2288 | - '</div></form>'; |
|
| 2279 | + return "\n<form action='" . |
|
| 2280 | + $h . |
|
| 2281 | + "'" . |
|
| 2282 | + $atts . |
|
| 2283 | + ">\n" . |
|
| 2284 | + '<div>' . |
|
| 2285 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2286 | + $corps . |
|
| 2287 | + '</div></form>'; |
|
| 2289 | 2288 | } |
| 2290 | 2289 | |
| 2291 | 2290 | /** |
@@ -2304,22 +2303,22 @@ discard block |
||
| 2304 | 2303 | * URL |
| 2305 | 2304 | */ |
| 2306 | 2305 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 2307 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2308 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2309 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2310 | - $url = (_DIR_RACINE and !$public) |
|
| 2311 | - ? generer_url_ecrire(_request('exec')) |
|
| 2312 | - : generer_url_public('', '', false, false); |
|
| 2313 | - $url = parametre_url($url, 'action', $script); |
|
| 2314 | - if ($args) { |
|
| 2315 | - $url .= quote_amp('&' . $args); |
|
| 2316 | - } |
|
| 2306 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2307 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2308 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2309 | + $url = (_DIR_RACINE and !$public) |
|
| 2310 | + ? generer_url_ecrire(_request('exec')) |
|
| 2311 | + : generer_url_public('', '', false, false); |
|
| 2312 | + $url = parametre_url($url, 'action', $script); |
|
| 2313 | + if ($args) { |
|
| 2314 | + $url .= quote_amp('&' . $args); |
|
| 2315 | + } |
|
| 2317 | 2316 | |
| 2318 | - if ($no_entities) { |
|
| 2319 | - $url = str_replace('&', '&', $url); |
|
| 2320 | - } |
|
| 2317 | + if ($no_entities) { |
|
| 2318 | + $url = str_replace('&', '&', $url); |
|
| 2319 | + } |
|
| 2321 | 2320 | |
| 2322 | - return $url; |
|
| 2321 | + return $url; |
|
| 2323 | 2322 | } |
| 2324 | 2323 | |
| 2325 | 2324 | |
@@ -2332,8 +2331,8 @@ discard block |
||
| 2332 | 2331 | * @param string $ta Répertoire temporaire accessible |
| 2333 | 2332 | */ |
| 2334 | 2333 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2335 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2336 | - spip_initialisation_suite(); |
|
| 2334 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2335 | + spip_initialisation_suite(); |
|
| 2337 | 2336 | } |
| 2338 | 2337 | |
| 2339 | 2338 | /** |
@@ -2353,322 +2352,322 @@ discard block |
||
| 2353 | 2352 | * @param string $ta Répertoire temporaire accessible |
| 2354 | 2353 | */ |
| 2355 | 2354 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2356 | - static $too_late = 0; |
|
| 2357 | - if ($too_late++) { |
|
| 2358 | - return; |
|
| 2359 | - } |
|
| 2360 | - |
|
| 2361 | - // Declaration des repertoires |
|
| 2362 | - |
|
| 2363 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2364 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2365 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2369 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2370 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2371 | - } |
|
| 2372 | - |
|
| 2373 | - // le nom du repertoire des librairies |
|
| 2374 | - if (!defined('_DIR_LIB')) { |
|
| 2375 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2376 | - } |
|
| 2377 | - |
|
| 2378 | - if (!defined('_DIR_IMG')) { |
|
| 2379 | - define('_DIR_IMG', $pa); |
|
| 2380 | - } |
|
| 2381 | - if (!defined('_DIR_LOGOS')) { |
|
| 2382 | - define('_DIR_LOGOS', $pa); |
|
| 2383 | - } |
|
| 2384 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2385 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2386 | - } |
|
| 2387 | - |
|
| 2388 | - if (!defined('_DIR_DUMP')) { |
|
| 2389 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2390 | - } |
|
| 2391 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2392 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2393 | - } |
|
| 2394 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2395 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2396 | - } |
|
| 2397 | - if (!defined('_DIR_CACHE')) { |
|
| 2398 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2399 | - } |
|
| 2400 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2401 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2402 | - } |
|
| 2403 | - if (!defined('_DIR_SKELS')) { |
|
| 2404 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2405 | - } |
|
| 2406 | - if (!defined('_DIR_AIDE')) { |
|
| 2407 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2408 | - } |
|
| 2409 | - if (!defined('_DIR_TMP')) { |
|
| 2410 | - define('_DIR_TMP', $ti); |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - if (!defined('_DIR_VAR')) { |
|
| 2414 | - define('_DIR_VAR', $ta); |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - if (!defined('_DIR_ETC')) { |
|
| 2418 | - define('_DIR_ETC', $pi); |
|
| 2419 | - } |
|
| 2420 | - if (!defined('_DIR_CONNECT')) { |
|
| 2421 | - define('_DIR_CONNECT', $pi); |
|
| 2422 | - } |
|
| 2423 | - if (!defined('_DIR_CHMOD')) { |
|
| 2424 | - define('_DIR_CHMOD', $pi); |
|
| 2425 | - } |
|
| 2426 | - |
|
| 2427 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 2428 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2429 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2430 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2431 | - } |
|
| 2432 | - |
|
| 2433 | - // Declaration des fichiers |
|
| 2434 | - |
|
| 2435 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2436 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2437 | - } |
|
| 2438 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2439 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2440 | - } |
|
| 2441 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2442 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2443 | - } |
|
| 2444 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2445 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2446 | - } |
|
| 2447 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2448 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2449 | - } |
|
| 2450 | - |
|
| 2451 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2452 | - if (!defined('_FILE_META')) { |
|
| 2453 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2454 | - } |
|
| 2455 | - if (!defined('_DIR_LOG')) { |
|
| 2456 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2457 | - } |
|
| 2458 | - if (!defined('_FILE_LOG')) { |
|
| 2459 | - define('_FILE_LOG', 'spip'); |
|
| 2460 | - } |
|
| 2461 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2462 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2463 | - } |
|
| 2464 | - |
|
| 2465 | - // Le fichier de connexion a la base de donnees |
|
| 2466 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2467 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2468 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2469 | - } |
|
| 2470 | - if (!defined('_FILE_CONNECT')) { |
|
| 2471 | - define( |
|
| 2472 | - '_FILE_CONNECT', |
|
| 2473 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2474 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2475 | - : false)) |
|
| 2476 | - ); |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - // Le fichier de reglages des droits |
|
| 2480 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2481 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2482 | - } |
|
| 2483 | - if (!defined('_FILE_CHMOD')) { |
|
| 2484 | - define( |
|
| 2485 | - '_FILE_CHMOD', |
|
| 2486 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2487 | - : false) |
|
| 2488 | - ); |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - if (!defined('_FILE_LDAP')) { |
|
| 2492 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2496 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2497 | - } |
|
| 2498 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2499 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2500 | - } |
|
| 2501 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2502 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2503 | - } |
|
| 2504 | - |
|
| 2505 | - // Definition des droits d'acces en ecriture |
|
| 2506 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2507 | - include_once _FILE_CHMOD; |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - // Se mefier des fichiers mal remplis! |
|
| 2511 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2512 | - define('_SPIP_CHMOD', 0777); |
|
| 2513 | - } |
|
| 2514 | - |
|
| 2515 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2516 | - /** Le charset par défaut lors de l'installation */ |
|
| 2517 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2518 | - } |
|
| 2519 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2520 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2521 | - } |
|
| 2522 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2523 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2524 | - } |
|
| 2525 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2526 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - // La taille des Log |
|
| 2530 | - if (!defined('_MAX_LOG')) { |
|
| 2531 | - define('_MAX_LOG', 100); |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2535 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2536 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2537 | - if (!defined('_OS_SERVEUR')) { |
|
| 2538 | - define('_OS_SERVEUR', 'windows'); |
|
| 2539 | - } |
|
| 2540 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2541 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2542 | - } // utiliser le flock php |
|
| 2543 | - } else { |
|
| 2544 | - if (!defined('_OS_SERVEUR')) { |
|
| 2545 | - define('_OS_SERVEUR', ''); |
|
| 2546 | - } |
|
| 2547 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2548 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2549 | - } // utiliser le flock php |
|
| 2550 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - // Langue par defaut |
|
| 2554 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2555 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - // |
|
| 2559 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2560 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2561 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2562 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2563 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2564 | - |
|
| 2565 | - // charger tout de suite le path et son cache |
|
| 2566 | - load_path_cache(); |
|
| 2567 | - |
|
| 2568 | - // *********** traiter les variables ************ |
|
| 2569 | - |
|
| 2570 | - // |
|
| 2571 | - // Securite |
|
| 2572 | - // |
|
| 2573 | - |
|
| 2574 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2575 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2576 | - die(); |
|
| 2577 | - } |
|
| 2578 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2579 | - spip_desinfecte($_GET); |
|
| 2580 | - spip_desinfecte($_POST); |
|
| 2581 | - spip_desinfecte($_COOKIE); |
|
| 2582 | - spip_desinfecte($_REQUEST); |
|
| 2583 | - |
|
| 2584 | - // appliquer le cookie_prefix |
|
| 2585 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2586 | - include_spip('inc/cookie'); |
|
| 2587 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2588 | - } |
|
| 2589 | - |
|
| 2590 | - // |
|
| 2591 | - // Capacites php (en fonction de la version) |
|
| 2592 | - // |
|
| 2593 | - $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2594 | - && function_exists('ini_get') |
|
| 2595 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2596 | - $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2597 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2598 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2599 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2600 | - |
|
| 2601 | - |
|
| 2602 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2603 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2604 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2605 | - } else { |
|
| 2606 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2607 | - if ( |
|
| 2608 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2609 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2610 | - ) { |
|
| 2611 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2612 | - } |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2616 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2617 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2618 | - } |
|
| 2619 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2620 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2621 | - } |
|
| 2622 | - |
|
| 2623 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2624 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2625 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2626 | - $inc_meta(); |
|
| 2627 | - |
|
| 2628 | - // nombre de repertoires depuis la racine |
|
| 2629 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2630 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2631 | - // le calcul est faux) |
|
| 2632 | - if (!_DIR_RESTREINT) { |
|
| 2633 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2634 | - } else { |
|
| 2635 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2636 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2637 | - if ( |
|
| 2638 | - !$uri_ref |
|
| 2639 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2640 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2641 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2642 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2643 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2644 | - ) { |
|
| 2645 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2646 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2647 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2648 | - } else { |
|
| 2649 | - $uri_ref = ''; |
|
| 2650 | - } |
|
| 2651 | - } |
|
| 2652 | - if (!$uri or !$uri_ref) { |
|
| 2653 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2654 | - } else { |
|
| 2655 | - $GLOBALS['profondeur_url'] = max( |
|
| 2656 | - 0, |
|
| 2657 | - substr_count($uri[0], '/') |
|
| 2658 | - - substr_count($uri_ref, '/') |
|
| 2659 | - ); |
|
| 2660 | - } |
|
| 2661 | - } |
|
| 2662 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2663 | - if (_FILE_CONNECT) { |
|
| 2664 | - if ( |
|
| 2665 | - verifier_visiteur() == '0minirezo' |
|
| 2666 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2667 | - and !isset($_COOKIE['spip_admin']) |
|
| 2668 | - ) { |
|
| 2669 | - clear_path_cache(); |
|
| 2670 | - } |
|
| 2671 | - } |
|
| 2355 | + static $too_late = 0; |
|
| 2356 | + if ($too_late++) { |
|
| 2357 | + return; |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + // Declaration des repertoires |
|
| 2361 | + |
|
| 2362 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2363 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2364 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2368 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2369 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + // le nom du repertoire des librairies |
|
| 2373 | + if (!defined('_DIR_LIB')) { |
|
| 2374 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2375 | + } |
|
| 2376 | + |
|
| 2377 | + if (!defined('_DIR_IMG')) { |
|
| 2378 | + define('_DIR_IMG', $pa); |
|
| 2379 | + } |
|
| 2380 | + if (!defined('_DIR_LOGOS')) { |
|
| 2381 | + define('_DIR_LOGOS', $pa); |
|
| 2382 | + } |
|
| 2383 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2384 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2385 | + } |
|
| 2386 | + |
|
| 2387 | + if (!defined('_DIR_DUMP')) { |
|
| 2388 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2389 | + } |
|
| 2390 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2391 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2392 | + } |
|
| 2393 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2394 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2395 | + } |
|
| 2396 | + if (!defined('_DIR_CACHE')) { |
|
| 2397 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2398 | + } |
|
| 2399 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2400 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2401 | + } |
|
| 2402 | + if (!defined('_DIR_SKELS')) { |
|
| 2403 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2404 | + } |
|
| 2405 | + if (!defined('_DIR_AIDE')) { |
|
| 2406 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2407 | + } |
|
| 2408 | + if (!defined('_DIR_TMP')) { |
|
| 2409 | + define('_DIR_TMP', $ti); |
|
| 2410 | + } |
|
| 2411 | + |
|
| 2412 | + if (!defined('_DIR_VAR')) { |
|
| 2413 | + define('_DIR_VAR', $ta); |
|
| 2414 | + } |
|
| 2415 | + |
|
| 2416 | + if (!defined('_DIR_ETC')) { |
|
| 2417 | + define('_DIR_ETC', $pi); |
|
| 2418 | + } |
|
| 2419 | + if (!defined('_DIR_CONNECT')) { |
|
| 2420 | + define('_DIR_CONNECT', $pi); |
|
| 2421 | + } |
|
| 2422 | + if (!defined('_DIR_CHMOD')) { |
|
| 2423 | + define('_DIR_CHMOD', $pi); |
|
| 2424 | + } |
|
| 2425 | + |
|
| 2426 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2427 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2428 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2429 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2430 | + } |
|
| 2431 | + |
|
| 2432 | + // Declaration des fichiers |
|
| 2433 | + |
|
| 2434 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2435 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2436 | + } |
|
| 2437 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2438 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2439 | + } |
|
| 2440 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2441 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2442 | + } |
|
| 2443 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2444 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2445 | + } |
|
| 2446 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2447 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2451 | + if (!defined('_FILE_META')) { |
|
| 2452 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2453 | + } |
|
| 2454 | + if (!defined('_DIR_LOG')) { |
|
| 2455 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2456 | + } |
|
| 2457 | + if (!defined('_FILE_LOG')) { |
|
| 2458 | + define('_FILE_LOG', 'spip'); |
|
| 2459 | + } |
|
| 2460 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2461 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2462 | + } |
|
| 2463 | + |
|
| 2464 | + // Le fichier de connexion a la base de donnees |
|
| 2465 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2466 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2467 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2468 | + } |
|
| 2469 | + if (!defined('_FILE_CONNECT')) { |
|
| 2470 | + define( |
|
| 2471 | + '_FILE_CONNECT', |
|
| 2472 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2473 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2474 | + : false)) |
|
| 2475 | + ); |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + // Le fichier de reglages des droits |
|
| 2479 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2480 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2481 | + } |
|
| 2482 | + if (!defined('_FILE_CHMOD')) { |
|
| 2483 | + define( |
|
| 2484 | + '_FILE_CHMOD', |
|
| 2485 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2486 | + : false) |
|
| 2487 | + ); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + if (!defined('_FILE_LDAP')) { |
|
| 2491 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2492 | + } |
|
| 2493 | + |
|
| 2494 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2495 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2496 | + } |
|
| 2497 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2498 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2499 | + } |
|
| 2500 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2501 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2502 | + } |
|
| 2503 | + |
|
| 2504 | + // Definition des droits d'acces en ecriture |
|
| 2505 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2506 | + include_once _FILE_CHMOD; |
|
| 2507 | + } |
|
| 2508 | + |
|
| 2509 | + // Se mefier des fichiers mal remplis! |
|
| 2510 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2511 | + define('_SPIP_CHMOD', 0777); |
|
| 2512 | + } |
|
| 2513 | + |
|
| 2514 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2515 | + /** Le charset par défaut lors de l'installation */ |
|
| 2516 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2517 | + } |
|
| 2518 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2519 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2520 | + } |
|
| 2521 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2522 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2523 | + } |
|
| 2524 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2525 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2526 | + } |
|
| 2527 | + |
|
| 2528 | + // La taille des Log |
|
| 2529 | + if (!defined('_MAX_LOG')) { |
|
| 2530 | + define('_MAX_LOG', 100); |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2534 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2535 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2536 | + if (!defined('_OS_SERVEUR')) { |
|
| 2537 | + define('_OS_SERVEUR', 'windows'); |
|
| 2538 | + } |
|
| 2539 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2540 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2541 | + } // utiliser le flock php |
|
| 2542 | + } else { |
|
| 2543 | + if (!defined('_OS_SERVEUR')) { |
|
| 2544 | + define('_OS_SERVEUR', ''); |
|
| 2545 | + } |
|
| 2546 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2547 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2548 | + } // utiliser le flock php |
|
| 2549 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + // Langue par defaut |
|
| 2553 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2554 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2555 | + } |
|
| 2556 | + |
|
| 2557 | + // |
|
| 2558 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2559 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2560 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2561 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2562 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2563 | + |
|
| 2564 | + // charger tout de suite le path et son cache |
|
| 2565 | + load_path_cache(); |
|
| 2566 | + |
|
| 2567 | + // *********** traiter les variables ************ |
|
| 2568 | + |
|
| 2569 | + // |
|
| 2570 | + // Securite |
|
| 2571 | + // |
|
| 2572 | + |
|
| 2573 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2574 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2575 | + die(); |
|
| 2576 | + } |
|
| 2577 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2578 | + spip_desinfecte($_GET); |
|
| 2579 | + spip_desinfecte($_POST); |
|
| 2580 | + spip_desinfecte($_COOKIE); |
|
| 2581 | + spip_desinfecte($_REQUEST); |
|
| 2582 | + |
|
| 2583 | + // appliquer le cookie_prefix |
|
| 2584 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2585 | + include_spip('inc/cookie'); |
|
| 2586 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + // |
|
| 2590 | + // Capacites php (en fonction de la version) |
|
| 2591 | + // |
|
| 2592 | + $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2593 | + && function_exists('ini_get') |
|
| 2594 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2595 | + $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2596 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2597 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2598 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2602 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2603 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2604 | + } else { |
|
| 2605 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2606 | + if ( |
|
| 2607 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2608 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2609 | + ) { |
|
| 2610 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2611 | + } |
|
| 2612 | + } |
|
| 2613 | + |
|
| 2614 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2615 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2616 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2617 | + } |
|
| 2618 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2619 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2623 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2624 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2625 | + $inc_meta(); |
|
| 2626 | + |
|
| 2627 | + // nombre de repertoires depuis la racine |
|
| 2628 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2629 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2630 | + // le calcul est faux) |
|
| 2631 | + if (!_DIR_RESTREINT) { |
|
| 2632 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2633 | + } else { |
|
| 2634 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2635 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2636 | + if ( |
|
| 2637 | + !$uri_ref |
|
| 2638 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2639 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2640 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2641 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2642 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2643 | + ) { |
|
| 2644 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2645 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2646 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2647 | + } else { |
|
| 2648 | + $uri_ref = ''; |
|
| 2649 | + } |
|
| 2650 | + } |
|
| 2651 | + if (!$uri or !$uri_ref) { |
|
| 2652 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2653 | + } else { |
|
| 2654 | + $GLOBALS['profondeur_url'] = max( |
|
| 2655 | + 0, |
|
| 2656 | + substr_count($uri[0], '/') |
|
| 2657 | + - substr_count($uri_ref, '/') |
|
| 2658 | + ); |
|
| 2659 | + } |
|
| 2660 | + } |
|
| 2661 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2662 | + if (_FILE_CONNECT) { |
|
| 2663 | + if ( |
|
| 2664 | + verifier_visiteur() == '0minirezo' |
|
| 2665 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2666 | + and !isset($_COOKIE['spip_admin']) |
|
| 2667 | + ) { |
|
| 2668 | + clear_path_cache(); |
|
| 2669 | + } |
|
| 2670 | + } |
|
| 2672 | 2671 | } |
| 2673 | 2672 | |
| 2674 | 2673 | /** |
@@ -2677,190 +2676,190 @@ discard block |
||
| 2677 | 2676 | * |
| 2678 | 2677 | */ |
| 2679 | 2678 | function spip_initialisation_suite() { |
| 2680 | - static $too_late = 0; |
|
| 2681 | - if ($too_late++) { |
|
| 2682 | - return; |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - // taille mini des login |
|
| 2686 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2687 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2688 | - } |
|
| 2689 | - |
|
| 2690 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2691 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2692 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2693 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2694 | - |
|
| 2695 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2696 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2697 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2698 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2699 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2700 | - |
|
| 2701 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2702 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2703 | - } |
|
| 2704 | - |
|
| 2705 | - // largeur maximale des images dans l'administration |
|
| 2706 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2707 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2708 | - } |
|
| 2709 | - |
|
| 2710 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2711 | - if (!defined('_IMG_QUALITE')) { |
|
| 2712 | - define('_IMG_QUALITE', 85); |
|
| 2713 | - } # valeur par defaut |
|
| 2714 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2715 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2716 | - } # surcharge pour la lib GD |
|
| 2717 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2718 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2719 | - } # surcharge pour imagick en ligne de commande |
|
| 2720 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2721 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2722 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2723 | - } # surcharge pour imagick en PHP |
|
| 2724 | - |
|
| 2725 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2726 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2727 | - } // poids en octet |
|
| 2728 | - |
|
| 2729 | - // qq chaines standard |
|
| 2730 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2731 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2732 | - } |
|
| 2733 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2734 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2735 | - } |
|
| 2736 | - if (!defined('_SPIP_DUMP')) { |
|
| 2737 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2738 | - } |
|
| 2739 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2740 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2741 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2742 | - } |
|
| 2743 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2744 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2745 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2746 | - } |
|
| 2747 | - |
|
| 2748 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2749 | - /** |
|
| 2750 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2751 | - * @var int Nombre de caractères */ |
|
| 2752 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2756 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2757 | - } |
|
| 2758 | - |
|
| 2759 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2760 | - /** Définit le doctype de l’espace privé */ |
|
| 2761 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2762 | - } |
|
| 2763 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2764 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2765 | - define( |
|
| 2766 | - '_DOCTYPE_AIDE', |
|
| 2767 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2768 | - ); |
|
| 2769 | - } |
|
| 2770 | - |
|
| 2771 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2772 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2773 | - * le script de l'espace public, alias index.php */ |
|
| 2774 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2775 | - } |
|
| 2776 | - if (!defined('_SPIP_PAGE')) { |
|
| 2777 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2778 | - define('_SPIP_PAGE', 'page'); |
|
| 2779 | - } |
|
| 2780 | - |
|
| 2781 | - // le script de l'espace prive |
|
| 2782 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2783 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2784 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2785 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2786 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2787 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2788 | - } else { |
|
| 2789 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2790 | - } |
|
| 2791 | - } |
|
| 2792 | - |
|
| 2793 | - |
|
| 2794 | - if (!defined('_SPIP_AJAX')) { |
|
| 2795 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2796 | - ? 1 |
|
| 2797 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2798 | - } |
|
| 2799 | - |
|
| 2800 | - // La requete est-elle en ajax ? |
|
| 2801 | - if (!defined('_AJAX')) { |
|
| 2802 | - define( |
|
| 2803 | - '_AJAX', |
|
| 2804 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2805 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2806 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2807 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2808 | - ) |
|
| 2809 | - and 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 |
|
| 2810 | - ); |
|
| 2811 | - } |
|
| 2812 | - |
|
| 2813 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2814 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2815 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2816 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2817 | - define( |
|
| 2818 | - '_IMG_GD_MAX_PIXELS', |
|
| 2819 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2820 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2821 | - : 0 |
|
| 2822 | - ); |
|
| 2823 | - } |
|
| 2824 | - |
|
| 2825 | - if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2826 | - define('_MEMORY_LIMIT_MIN', 16); |
|
| 2827 | - } // en Mo |
|
| 2828 | - // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2829 | - // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2830 | - // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2831 | - if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2832 | - if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2833 | - $unit = strtolower(substr($memory, -1)); |
|
| 2834 | - $memory = substr($memory, 0, -1); |
|
| 2835 | - switch ($unit) { |
|
| 2836 | - // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2837 | - case 'g': |
|
| 2838 | - $memory *= 1024; |
|
| 2839 | - case 'm': |
|
| 2840 | - $memory *= 1024; |
|
| 2841 | - case 'k': |
|
| 2842 | - $memory *= 1024; |
|
| 2843 | - } |
|
| 2844 | - if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2845 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2846 | - if (trim(ini_get('memory_limit')) != $m) { |
|
| 2847 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2848 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2849 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2850 | - } |
|
| 2851 | - } |
|
| 2852 | - } else { |
|
| 2853 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2854 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2855 | - } |
|
| 2856 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2857 | - } |
|
| 2858 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2859 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2860 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2861 | - } |
|
| 2862 | - |
|
| 2863 | - init_var_mode(); |
|
| 2679 | + static $too_late = 0; |
|
| 2680 | + if ($too_late++) { |
|
| 2681 | + return; |
|
| 2682 | + } |
|
| 2683 | + |
|
| 2684 | + // taille mini des login |
|
| 2685 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2686 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2690 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2691 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2692 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2693 | + |
|
| 2694 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2695 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2696 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2697 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2698 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2699 | + |
|
| 2700 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2701 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + // largeur maximale des images dans l'administration |
|
| 2705 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2706 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2710 | + if (!defined('_IMG_QUALITE')) { |
|
| 2711 | + define('_IMG_QUALITE', 85); |
|
| 2712 | + } # valeur par defaut |
|
| 2713 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2714 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2715 | + } # surcharge pour la lib GD |
|
| 2716 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2717 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2718 | + } # surcharge pour imagick en ligne de commande |
|
| 2719 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2720 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2721 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2722 | + } # surcharge pour imagick en PHP |
|
| 2723 | + |
|
| 2724 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2725 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2726 | + } // poids en octet |
|
| 2727 | + |
|
| 2728 | + // qq chaines standard |
|
| 2729 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2730 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2731 | + } |
|
| 2732 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2733 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2734 | + } |
|
| 2735 | + if (!defined('_SPIP_DUMP')) { |
|
| 2736 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2737 | + } |
|
| 2738 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2739 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2740 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2741 | + } |
|
| 2742 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2743 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2744 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2745 | + } |
|
| 2746 | + |
|
| 2747 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2748 | + /** |
|
| 2749 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2750 | + * @var int Nombre de caractères */ |
|
| 2751 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2752 | + } |
|
| 2753 | + |
|
| 2754 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2755 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2756 | + } |
|
| 2757 | + |
|
| 2758 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2759 | + /** Définit le doctype de l’espace privé */ |
|
| 2760 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2761 | + } |
|
| 2762 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2763 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2764 | + define( |
|
| 2765 | + '_DOCTYPE_AIDE', |
|
| 2766 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2767 | + ); |
|
| 2768 | + } |
|
| 2769 | + |
|
| 2770 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2771 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2772 | + * le script de l'espace public, alias index.php */ |
|
| 2773 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2774 | + } |
|
| 2775 | + if (!defined('_SPIP_PAGE')) { |
|
| 2776 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2777 | + define('_SPIP_PAGE', 'page'); |
|
| 2778 | + } |
|
| 2779 | + |
|
| 2780 | + // le script de l'espace prive |
|
| 2781 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2782 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2783 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2784 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2785 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2786 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2787 | + } else { |
|
| 2788 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2789 | + } |
|
| 2790 | + } |
|
| 2791 | + |
|
| 2792 | + |
|
| 2793 | + if (!defined('_SPIP_AJAX')) { |
|
| 2794 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2795 | + ? 1 |
|
| 2796 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2797 | + } |
|
| 2798 | + |
|
| 2799 | + // La requete est-elle en ajax ? |
|
| 2800 | + if (!defined('_AJAX')) { |
|
| 2801 | + define( |
|
| 2802 | + '_AJAX', |
|
| 2803 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2804 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2805 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2806 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2807 | + ) |
|
| 2808 | + and 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 |
|
| 2809 | + ); |
|
| 2810 | + } |
|
| 2811 | + |
|
| 2812 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2813 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2814 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2815 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2816 | + define( |
|
| 2817 | + '_IMG_GD_MAX_PIXELS', |
|
| 2818 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2819 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2820 | + : 0 |
|
| 2821 | + ); |
|
| 2822 | + } |
|
| 2823 | + |
|
| 2824 | + if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2825 | + define('_MEMORY_LIMIT_MIN', 16); |
|
| 2826 | + } // en Mo |
|
| 2827 | + // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2828 | + // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2829 | + // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2830 | + if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2831 | + if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2832 | + $unit = strtolower(substr($memory, -1)); |
|
| 2833 | + $memory = substr($memory, 0, -1); |
|
| 2834 | + switch ($unit) { |
|
| 2835 | + // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2836 | + case 'g': |
|
| 2837 | + $memory *= 1024; |
|
| 2838 | + case 'm': |
|
| 2839 | + $memory *= 1024; |
|
| 2840 | + case 'k': |
|
| 2841 | + $memory *= 1024; |
|
| 2842 | + } |
|
| 2843 | + if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2844 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2845 | + if (trim(ini_get('memory_limit')) != $m) { |
|
| 2846 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2847 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2848 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2849 | + } |
|
| 2850 | + } |
|
| 2851 | + } else { |
|
| 2852 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2853 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2854 | + } |
|
| 2855 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2856 | + } |
|
| 2857 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2858 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2859 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2860 | + } |
|
| 2861 | + |
|
| 2862 | + init_var_mode(); |
|
| 2864 | 2863 | } |
| 2865 | 2864 | |
| 2866 | 2865 | /** |
@@ -2894,136 +2893,136 @@ discard block |
||
| 2894 | 2893 | * ` var_mode` (calcul ou recalcul). |
| 2895 | 2894 | */ |
| 2896 | 2895 | function init_var_mode() { |
| 2897 | - static $done = false; |
|
| 2898 | - if (!$done) { |
|
| 2899 | - if (isset($_GET['var_mode'])) { |
|
| 2900 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 2901 | - // tout le monde peut calcul/recalcul |
|
| 2902 | - if (!defined('_VAR_MODE')) { |
|
| 2903 | - if (in_array('recalcul', $var_mode)) { |
|
| 2904 | - define('_VAR_MODE', 'recalcul'); |
|
| 2905 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 2906 | - define('_VAR_MODE', 'calcul'); |
|
| 2907 | - } |
|
| 2908 | - } |
|
| 2909 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 2910 | - if ($var_mode) { |
|
| 2911 | - include_spip('inc/autoriser'); |
|
| 2912 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2913 | - if ( |
|
| 2914 | - autoriser( |
|
| 2915 | - ($_GET['var_mode'] == 'preview') |
|
| 2916 | - ? 'previsualiser' |
|
| 2917 | - : 'debug' |
|
| 2918 | - ) |
|
| 2919 | - ) { |
|
| 2920 | - if (in_array('traduction', $var_mode)) { |
|
| 2921 | - // forcer le calcul pour passer dans traduire |
|
| 2922 | - if (!defined('_VAR_MODE')) { |
|
| 2923 | - define('_VAR_MODE', 'calcul'); |
|
| 2924 | - } |
|
| 2925 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2926 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2927 | - define('_VAR_NOCACHE', true); |
|
| 2928 | - } |
|
| 2929 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 2930 | - } |
|
| 2931 | - if (in_array('preview', $var_mode)) { |
|
| 2932 | - // basculer sur les criteres de preview dans les boucles |
|
| 2933 | - if (!defined('_VAR_PREVIEW')) { |
|
| 2934 | - define('_VAR_PREVIEW', true); |
|
| 2935 | - } |
|
| 2936 | - // forcer le calcul |
|
| 2937 | - if (!defined('_VAR_MODE')) { |
|
| 2938 | - define('_VAR_MODE', 'calcul'); |
|
| 2939 | - } |
|
| 2940 | - // et ne pas enregistrer de cache |
|
| 2941 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2942 | - define('_VAR_NOCACHE', true); |
|
| 2943 | - } |
|
| 2944 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 2945 | - } |
|
| 2946 | - if (in_array('inclure', $var_mode)) { |
|
| 2947 | - // forcer le compilo et ignorer les caches existants |
|
| 2948 | - if (!defined('_VAR_MODE')) { |
|
| 2949 | - define('_VAR_MODE', 'calcul'); |
|
| 2950 | - } |
|
| 2951 | - if (!defined('_VAR_INCLURE')) { |
|
| 2952 | - define('_VAR_INCLURE', true); |
|
| 2953 | - } |
|
| 2954 | - // et ne pas enregistrer de cache |
|
| 2955 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2956 | - define('_VAR_NOCACHE', true); |
|
| 2957 | - } |
|
| 2958 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 2959 | - } |
|
| 2960 | - if (in_array('urls', $var_mode)) { |
|
| 2961 | - // forcer le compilo et ignorer les caches existants |
|
| 2962 | - if (!defined('_VAR_MODE')) { |
|
| 2963 | - define('_VAR_MODE', 'calcul'); |
|
| 2964 | - } |
|
| 2965 | - if (!defined('_VAR_URLS')) { |
|
| 2966 | - define('_VAR_URLS', true); |
|
| 2967 | - } |
|
| 2968 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 2969 | - } |
|
| 2970 | - if (in_array('images', $var_mode)) { |
|
| 2971 | - // forcer le compilo et ignorer les caches existants |
|
| 2972 | - if (!defined('_VAR_MODE')) { |
|
| 2973 | - define('_VAR_MODE', 'calcul'); |
|
| 2974 | - } |
|
| 2975 | - // indiquer qu'on doit recalculer les images |
|
| 2976 | - if (!defined('_VAR_IMAGES')) { |
|
| 2977 | - define('_VAR_IMAGES', true); |
|
| 2978 | - } |
|
| 2979 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 2980 | - } |
|
| 2981 | - if (in_array('debug', $var_mode)) { |
|
| 2982 | - if (!defined('_VAR_MODE')) { |
|
| 2983 | - define('_VAR_MODE', 'debug'); |
|
| 2984 | - } |
|
| 2985 | - // et ne pas enregistrer de cache |
|
| 2986 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2987 | - define('_VAR_NOCACHE', true); |
|
| 2988 | - } |
|
| 2989 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 2990 | - } |
|
| 2991 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2992 | - define('_VAR_MODE', reset($var_mode)); |
|
| 2993 | - } |
|
| 2994 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2995 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2996 | - . ' ' . _VAR_MODE); |
|
| 2997 | - } |
|
| 2998 | - } // pas autorise ? |
|
| 2999 | - else { |
|
| 3000 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3001 | - if ( |
|
| 3002 | - !$GLOBALS['visiteur_session'] |
|
| 3003 | - and !empty($_SERVER['HTTP_HOST']) |
|
| 3004 | - and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3005 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3006 | - ) { |
|
| 3007 | - $self = self('&', true); |
|
| 3008 | - if (strpos($self, 'page=login') === false) { |
|
| 3009 | - include_spip('inc/headers'); |
|
| 3010 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3011 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3012 | - } |
|
| 3013 | - } |
|
| 3014 | - // sinon tant pis |
|
| 3015 | - } |
|
| 3016 | - } |
|
| 3017 | - } |
|
| 3018 | - if (!defined('_VAR_MODE')) { |
|
| 3019 | - /** |
|
| 3020 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 3021 | - * @see init_var_mode() |
|
| 3022 | - */ |
|
| 3023 | - define('_VAR_MODE', false); |
|
| 3024 | - } |
|
| 3025 | - $done = true; |
|
| 3026 | - } |
|
| 2896 | + static $done = false; |
|
| 2897 | + if (!$done) { |
|
| 2898 | + if (isset($_GET['var_mode'])) { |
|
| 2899 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 2900 | + // tout le monde peut calcul/recalcul |
|
| 2901 | + if (!defined('_VAR_MODE')) { |
|
| 2902 | + if (in_array('recalcul', $var_mode)) { |
|
| 2903 | + define('_VAR_MODE', 'recalcul'); |
|
| 2904 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 2905 | + define('_VAR_MODE', 'calcul'); |
|
| 2906 | + } |
|
| 2907 | + } |
|
| 2908 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 2909 | + if ($var_mode) { |
|
| 2910 | + include_spip('inc/autoriser'); |
|
| 2911 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2912 | + if ( |
|
| 2913 | + autoriser( |
|
| 2914 | + ($_GET['var_mode'] == 'preview') |
|
| 2915 | + ? 'previsualiser' |
|
| 2916 | + : 'debug' |
|
| 2917 | + ) |
|
| 2918 | + ) { |
|
| 2919 | + if (in_array('traduction', $var_mode)) { |
|
| 2920 | + // forcer le calcul pour passer dans traduire |
|
| 2921 | + if (!defined('_VAR_MODE')) { |
|
| 2922 | + define('_VAR_MODE', 'calcul'); |
|
| 2923 | + } |
|
| 2924 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2925 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2926 | + define('_VAR_NOCACHE', true); |
|
| 2927 | + } |
|
| 2928 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 2929 | + } |
|
| 2930 | + if (in_array('preview', $var_mode)) { |
|
| 2931 | + // basculer sur les criteres de preview dans les boucles |
|
| 2932 | + if (!defined('_VAR_PREVIEW')) { |
|
| 2933 | + define('_VAR_PREVIEW', true); |
|
| 2934 | + } |
|
| 2935 | + // forcer le calcul |
|
| 2936 | + if (!defined('_VAR_MODE')) { |
|
| 2937 | + define('_VAR_MODE', 'calcul'); |
|
| 2938 | + } |
|
| 2939 | + // et ne pas enregistrer de cache |
|
| 2940 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2941 | + define('_VAR_NOCACHE', true); |
|
| 2942 | + } |
|
| 2943 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 2944 | + } |
|
| 2945 | + if (in_array('inclure', $var_mode)) { |
|
| 2946 | + // forcer le compilo et ignorer les caches existants |
|
| 2947 | + if (!defined('_VAR_MODE')) { |
|
| 2948 | + define('_VAR_MODE', 'calcul'); |
|
| 2949 | + } |
|
| 2950 | + if (!defined('_VAR_INCLURE')) { |
|
| 2951 | + define('_VAR_INCLURE', true); |
|
| 2952 | + } |
|
| 2953 | + // et ne pas enregistrer de cache |
|
| 2954 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2955 | + define('_VAR_NOCACHE', true); |
|
| 2956 | + } |
|
| 2957 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 2958 | + } |
|
| 2959 | + if (in_array('urls', $var_mode)) { |
|
| 2960 | + // forcer le compilo et ignorer les caches existants |
|
| 2961 | + if (!defined('_VAR_MODE')) { |
|
| 2962 | + define('_VAR_MODE', 'calcul'); |
|
| 2963 | + } |
|
| 2964 | + if (!defined('_VAR_URLS')) { |
|
| 2965 | + define('_VAR_URLS', true); |
|
| 2966 | + } |
|
| 2967 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 2968 | + } |
|
| 2969 | + if (in_array('images', $var_mode)) { |
|
| 2970 | + // forcer le compilo et ignorer les caches existants |
|
| 2971 | + if (!defined('_VAR_MODE')) { |
|
| 2972 | + define('_VAR_MODE', 'calcul'); |
|
| 2973 | + } |
|
| 2974 | + // indiquer qu'on doit recalculer les images |
|
| 2975 | + if (!defined('_VAR_IMAGES')) { |
|
| 2976 | + define('_VAR_IMAGES', true); |
|
| 2977 | + } |
|
| 2978 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 2979 | + } |
|
| 2980 | + if (in_array('debug', $var_mode)) { |
|
| 2981 | + if (!defined('_VAR_MODE')) { |
|
| 2982 | + define('_VAR_MODE', 'debug'); |
|
| 2983 | + } |
|
| 2984 | + // et ne pas enregistrer de cache |
|
| 2985 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2986 | + define('_VAR_NOCACHE', true); |
|
| 2987 | + } |
|
| 2988 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 2989 | + } |
|
| 2990 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2991 | + define('_VAR_MODE', reset($var_mode)); |
|
| 2992 | + } |
|
| 2993 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2994 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2995 | + . ' ' . _VAR_MODE); |
|
| 2996 | + } |
|
| 2997 | + } // pas autorise ? |
|
| 2998 | + else { |
|
| 2999 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3000 | + if ( |
|
| 3001 | + !$GLOBALS['visiteur_session'] |
|
| 3002 | + and !empty($_SERVER['HTTP_HOST']) |
|
| 3003 | + and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3004 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3005 | + ) { |
|
| 3006 | + $self = self('&', true); |
|
| 3007 | + if (strpos($self, 'page=login') === false) { |
|
| 3008 | + include_spip('inc/headers'); |
|
| 3009 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3010 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3011 | + } |
|
| 3012 | + } |
|
| 3013 | + // sinon tant pis |
|
| 3014 | + } |
|
| 3015 | + } |
|
| 3016 | + } |
|
| 3017 | + if (!defined('_VAR_MODE')) { |
|
| 3018 | + /** |
|
| 3019 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 3020 | + * @see init_var_mode() |
|
| 3021 | + */ |
|
| 3022 | + define('_VAR_MODE', false); |
|
| 3023 | + } |
|
| 3024 | + $done = true; |
|
| 3025 | + } |
|
| 3027 | 3026 | } |
| 3028 | 3027 | |
| 3029 | 3028 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
@@ -3031,84 +3030,84 @@ discard block |
||
| 3031 | 3030 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 3032 | 3031 | // https://code.spip.net/@spip_desinfecte |
| 3033 | 3032 | function spip_desinfecte(&$t, $deep = true) { |
| 3034 | - foreach ($t as $key => $val) { |
|
| 3035 | - if (is_string($t[$key])) { |
|
| 3036 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3037 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3038 | - else { |
|
| 3039 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3040 | - spip_desinfecte($t[$key], $deep); |
|
| 3041 | - } |
|
| 3042 | - } |
|
| 3043 | - } |
|
| 3033 | + foreach ($t as $key => $val) { |
|
| 3034 | + if (is_string($t[$key])) { |
|
| 3035 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3036 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3037 | + else { |
|
| 3038 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3039 | + spip_desinfecte($t[$key], $deep); |
|
| 3040 | + } |
|
| 3041 | + } |
|
| 3042 | + } |
|
| 3044 | 3043 | } |
| 3045 | 3044 | |
| 3046 | 3045 | // retourne le statut du visiteur s'il s'annonce |
| 3047 | 3046 | |
| 3048 | 3047 | // https://code.spip.net/@verifier_visiteur |
| 3049 | 3048 | function verifier_visiteur() { |
| 3050 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 3051 | - // il faut forcer l'init si ce n'est fait |
|
| 3052 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3053 | - // certaines constantes |
|
| 3054 | - @spip_initialisation_core( |
|
| 3055 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3056 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3057 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3058 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3059 | - ); |
|
| 3060 | - |
|
| 3061 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3062 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3063 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3064 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3065 | - $variables_session = ['session_nom', 'session_email']; |
|
| 3066 | - foreach ($variables_session as $var) { |
|
| 3067 | - if (_request($var) !== null) { |
|
| 3068 | - $init = true; |
|
| 3069 | - break; |
|
| 3070 | - } |
|
| 3071 | - } |
|
| 3072 | - if (isset($init)) { |
|
| 3073 | - #@spip_initialisation_suite(); |
|
| 3074 | - $session = charger_fonction('session', 'inc'); |
|
| 3075 | - $session(); |
|
| 3076 | - include_spip('inc/texte'); |
|
| 3077 | - foreach ($variables_session as $var) { |
|
| 3078 | - if (($a = _request($var)) !== null) { |
|
| 3079 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3080 | - } |
|
| 3081 | - } |
|
| 3082 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3083 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3084 | - } |
|
| 3085 | - $session($GLOBALS['visiteur_session']); |
|
| 3086 | - |
|
| 3087 | - return 0; |
|
| 3088 | - } |
|
| 3089 | - |
|
| 3090 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3091 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3092 | - $session = charger_fonction('session', 'inc'); |
|
| 3093 | - if ($session()) { |
|
| 3094 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3095 | - } |
|
| 3096 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3097 | - include_spip('inc/auth'); |
|
| 3098 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3099 | - } |
|
| 3100 | - if ($h) { |
|
| 3101 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3102 | - |
|
| 3103 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3104 | - } |
|
| 3105 | - } |
|
| 3106 | - |
|
| 3107 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3108 | - include_spip('inc/lang'); |
|
| 3109 | - utiliser_langue_visiteur(); |
|
| 3110 | - |
|
| 3111 | - return false; |
|
| 3049 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 3050 | + // il faut forcer l'init si ce n'est fait |
|
| 3051 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3052 | + // certaines constantes |
|
| 3053 | + @spip_initialisation_core( |
|
| 3054 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3055 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3056 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3057 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3058 | + ); |
|
| 3059 | + |
|
| 3060 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3061 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3062 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3063 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3064 | + $variables_session = ['session_nom', 'session_email']; |
|
| 3065 | + foreach ($variables_session as $var) { |
|
| 3066 | + if (_request($var) !== null) { |
|
| 3067 | + $init = true; |
|
| 3068 | + break; |
|
| 3069 | + } |
|
| 3070 | + } |
|
| 3071 | + if (isset($init)) { |
|
| 3072 | + #@spip_initialisation_suite(); |
|
| 3073 | + $session = charger_fonction('session', 'inc'); |
|
| 3074 | + $session(); |
|
| 3075 | + include_spip('inc/texte'); |
|
| 3076 | + foreach ($variables_session as $var) { |
|
| 3077 | + if (($a = _request($var)) !== null) { |
|
| 3078 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3079 | + } |
|
| 3080 | + } |
|
| 3081 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3082 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3083 | + } |
|
| 3084 | + $session($GLOBALS['visiteur_session']); |
|
| 3085 | + |
|
| 3086 | + return 0; |
|
| 3087 | + } |
|
| 3088 | + |
|
| 3089 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3090 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3091 | + $session = charger_fonction('session', 'inc'); |
|
| 3092 | + if ($session()) { |
|
| 3093 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3094 | + } |
|
| 3095 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3096 | + include_spip('inc/auth'); |
|
| 3097 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3098 | + } |
|
| 3099 | + if ($h) { |
|
| 3100 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3101 | + |
|
| 3102 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3103 | + } |
|
| 3104 | + } |
|
| 3105 | + |
|
| 3106 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3107 | + include_spip('inc/lang'); |
|
| 3108 | + utiliser_langue_visiteur(); |
|
| 3109 | + |
|
| 3110 | + return false; |
|
| 3112 | 3111 | } |
| 3113 | 3112 | |
| 3114 | 3113 | |
@@ -3131,21 +3130,21 @@ discard block |
||
| 3131 | 3130 | * - string Langue utilisée. |
| 3132 | 3131 | **/ |
| 3133 | 3132 | function lang_select($lang = null) { |
| 3134 | - static $pile_langues = []; |
|
| 3135 | - if (!function_exists('changer_langue')) { |
|
| 3136 | - include_spip('inc/lang'); |
|
| 3137 | - } |
|
| 3138 | - if ($lang === null) { |
|
| 3139 | - $lang = array_pop($pile_langues); |
|
| 3140 | - } else { |
|
| 3141 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3142 | - } |
|
| 3143 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3144 | - return $lang; |
|
| 3145 | - } |
|
| 3146 | - changer_langue($lang); |
|
| 3133 | + static $pile_langues = []; |
|
| 3134 | + if (!function_exists('changer_langue')) { |
|
| 3135 | + include_spip('inc/lang'); |
|
| 3136 | + } |
|
| 3137 | + if ($lang === null) { |
|
| 3138 | + $lang = array_pop($pile_langues); |
|
| 3139 | + } else { |
|
| 3140 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3141 | + } |
|
| 3142 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3143 | + return $lang; |
|
| 3144 | + } |
|
| 3145 | + changer_langue($lang); |
|
| 3147 | 3146 | |
| 3148 | - return $lang; |
|
| 3147 | + return $lang; |
|
| 3149 | 3148 | } |
| 3150 | 3149 | |
| 3151 | 3150 | /** |
@@ -3162,20 +3161,20 @@ discard block |
||
| 3162 | 3161 | * Identifiant de la session |
| 3163 | 3162 | **/ |
| 3164 | 3163 | function spip_session($force = false) { |
| 3165 | - static $session; |
|
| 3166 | - if ($force or !isset($session)) { |
|
| 3167 | - $s = pipeline( |
|
| 3168 | - 'definir_session', |
|
| 3169 | - $GLOBALS['visiteur_session'] |
|
| 3170 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3171 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3172 | - : '' |
|
| 3173 | - ); |
|
| 3174 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3175 | - } |
|
| 3164 | + static $session; |
|
| 3165 | + if ($force or !isset($session)) { |
|
| 3166 | + $s = pipeline( |
|
| 3167 | + 'definir_session', |
|
| 3168 | + $GLOBALS['visiteur_session'] |
|
| 3169 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3170 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3171 | + : '' |
|
| 3172 | + ); |
|
| 3173 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3174 | + } |
|
| 3176 | 3175 | |
| 3177 | - #spip_log('session: '.$session); |
|
| 3178 | - return $session; |
|
| 3176 | + #spip_log('session: '.$session); |
|
| 3177 | + return $session; |
|
| 3179 | 3178 | } |
| 3180 | 3179 | |
| 3181 | 3180 | |
@@ -3194,9 +3193,9 @@ discard block |
||
| 3194 | 3193 | * Lien sur une icone d'aide |
| 3195 | 3194 | **/ |
| 3196 | 3195 | function aider($aide = '', $distante = false) { |
| 3197 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3196 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3198 | 3197 | |
| 3199 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3198 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3200 | 3199 | } |
| 3201 | 3200 | |
| 3202 | 3201 | /** |
@@ -3206,24 +3205,24 @@ discard block |
||
| 3206 | 3205 | */ |
| 3207 | 3206 | function exec_info_dist() { |
| 3208 | 3207 | |
| 3209 | - include_spip('inc/autoriser'); |
|
| 3210 | - if (autoriser('phpinfos')) { |
|
| 3211 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3212 | - $cookies_backup = []; |
|
| 3213 | - foreach ($cookies_masques as $k) { |
|
| 3214 | - if (!empty($_COOKIE[$k])) { |
|
| 3215 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3216 | - $_COOKIE[$k] = '******************************'; |
|
| 3217 | - } |
|
| 3218 | - } |
|
| 3219 | - phpinfo(); |
|
| 3220 | - foreach ($cookies_backup as $k => $v) { |
|
| 3221 | - $_COOKIE[$k] = $v; |
|
| 3222 | - } |
|
| 3223 | - } else { |
|
| 3224 | - include_spip('inc/filtres'); |
|
| 3225 | - sinon_interdire_acces(); |
|
| 3226 | - } |
|
| 3208 | + include_spip('inc/autoriser'); |
|
| 3209 | + if (autoriser('phpinfos')) { |
|
| 3210 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3211 | + $cookies_backup = []; |
|
| 3212 | + foreach ($cookies_masques as $k) { |
|
| 3213 | + if (!empty($_COOKIE[$k])) { |
|
| 3214 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3215 | + $_COOKIE[$k] = '******************************'; |
|
| 3216 | + } |
|
| 3217 | + } |
|
| 3218 | + phpinfo(); |
|
| 3219 | + foreach ($cookies_backup as $k => $v) { |
|
| 3220 | + $_COOKIE[$k] = $v; |
|
| 3221 | + } |
|
| 3222 | + } else { |
|
| 3223 | + include_spip('inc/filtres'); |
|
| 3224 | + sinon_interdire_acces(); |
|
| 3225 | + } |
|
| 3227 | 3226 | } |
| 3228 | 3227 | |
| 3229 | 3228 | /** |
@@ -3243,13 +3242,13 @@ discard block |
||
| 3243 | 3242 | * - string si $message à false. |
| 3244 | 3243 | **/ |
| 3245 | 3244 | function erreur_squelette($message = '', $lieu = '') { |
| 3246 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3247 | - if (is_array($lieu)) { |
|
| 3248 | - include_spip('public/compiler'); |
|
| 3249 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3250 | - } |
|
| 3245 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3246 | + if (is_array($lieu)) { |
|
| 3247 | + include_spip('public/compiler'); |
|
| 3248 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3249 | + } |
|
| 3251 | 3250 | |
| 3252 | - return $debusquer($message, $lieu); |
|
| 3251 | + return $debusquer($message, $lieu); |
|
| 3253 | 3252 | } |
| 3254 | 3253 | |
| 3255 | 3254 | /** |
@@ -3286,108 +3285,108 @@ discard block |
||
| 3286 | 3285 | * - ou tableau d'information sur le squelette. |
| 3287 | 3286 | */ |
| 3288 | 3287 | function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') { |
| 3289 | - if (!function_exists('evaluer_fond')) { |
|
| 3290 | - include_spip('public/assembler'); |
|
| 3291 | - } |
|
| 3292 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3293 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3294 | - if (!is_array($options)) { |
|
| 3295 | - $options = ['trim' => $options]; |
|
| 3296 | - } |
|
| 3297 | - if (!isset($options['trim'])) { |
|
| 3298 | - $options['trim'] = true; |
|
| 3299 | - } |
|
| 3300 | - |
|
| 3301 | - if (isset($contexte['connect'])) { |
|
| 3302 | - $connect = $contexte['connect']; |
|
| 3303 | - unset($contexte['connect']); |
|
| 3304 | - } |
|
| 3305 | - |
|
| 3306 | - $texte = ''; |
|
| 3307 | - $pages = []; |
|
| 3308 | - $lang_select = ''; |
|
| 3309 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3310 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3311 | - if (!isset($contexte['lang'])) { |
|
| 3312 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3313 | - } |
|
| 3314 | - |
|
| 3315 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3316 | - $lang_select = lang_select($contexte['lang']); |
|
| 3317 | - } |
|
| 3318 | - } |
|
| 3319 | - |
|
| 3320 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3321 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3322 | - } |
|
| 3323 | - |
|
| 3324 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3325 | - |
|
| 3326 | - // fix #4235 |
|
| 3327 | - $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3328 | - |
|
| 3329 | - |
|
| 3330 | - foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3331 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3332 | - |
|
| 3333 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3334 | - if ($page === '') { |
|
| 3335 | - $c = $options['compil'] ?? ''; |
|
| 3336 | - $a = ['fichier' => $f]; |
|
| 3337 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3338 | - erreur_squelette($erreur, $c); |
|
| 3339 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3340 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3341 | - } |
|
| 3342 | - |
|
| 3343 | - $page = pipeline('recuperer_fond', [ |
|
| 3344 | - 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3345 | - 'data' => $page |
|
| 3346 | - ]); |
|
| 3347 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3348 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3349 | - include_spip('inc/filtres'); |
|
| 3350 | - } |
|
| 3351 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3352 | - array_merge( |
|
| 3353 | - $contexte, |
|
| 3354 | - ['fond' => $f], |
|
| 3355 | - ($connect ? ['connect' => $connect] : []) |
|
| 3356 | - ), |
|
| 3357 | - '', |
|
| 3358 | - $page['texte'], |
|
| 3359 | - $options['ajax'] |
|
| 3360 | - ); |
|
| 3361 | - } |
|
| 3362 | - |
|
| 3363 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3364 | - $pages[] = $page; |
|
| 3365 | - } else { |
|
| 3366 | - $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3367 | - } |
|
| 3368 | - |
|
| 3369 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3370 | - if (isset($page['invalideurs']['session'])) { |
|
| 3371 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3372 | - } |
|
| 3373 | - } |
|
| 3374 | - |
|
| 3375 | - // restaurer le sessionnement du contexte appelant, |
|
| 3376 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3377 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3378 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3379 | - } |
|
| 3380 | - |
|
| 3381 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3382 | - |
|
| 3383 | - if ($lang_select) { |
|
| 3384 | - lang_select(); |
|
| 3385 | - } |
|
| 3386 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3387 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3388 | - } else { |
|
| 3389 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3390 | - } |
|
| 3288 | + if (!function_exists('evaluer_fond')) { |
|
| 3289 | + include_spip('public/assembler'); |
|
| 3290 | + } |
|
| 3291 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3292 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3293 | + if (!is_array($options)) { |
|
| 3294 | + $options = ['trim' => $options]; |
|
| 3295 | + } |
|
| 3296 | + if (!isset($options['trim'])) { |
|
| 3297 | + $options['trim'] = true; |
|
| 3298 | + } |
|
| 3299 | + |
|
| 3300 | + if (isset($contexte['connect'])) { |
|
| 3301 | + $connect = $contexte['connect']; |
|
| 3302 | + unset($contexte['connect']); |
|
| 3303 | + } |
|
| 3304 | + |
|
| 3305 | + $texte = ''; |
|
| 3306 | + $pages = []; |
|
| 3307 | + $lang_select = ''; |
|
| 3308 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3309 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3310 | + if (!isset($contexte['lang'])) { |
|
| 3311 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3312 | + } |
|
| 3313 | + |
|
| 3314 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3315 | + $lang_select = lang_select($contexte['lang']); |
|
| 3316 | + } |
|
| 3317 | + } |
|
| 3318 | + |
|
| 3319 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3320 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3321 | + } |
|
| 3322 | + |
|
| 3323 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3324 | + |
|
| 3325 | + // fix #4235 |
|
| 3326 | + $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3327 | + |
|
| 3328 | + |
|
| 3329 | + foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3330 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3331 | + |
|
| 3332 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3333 | + if ($page === '') { |
|
| 3334 | + $c = $options['compil'] ?? ''; |
|
| 3335 | + $a = ['fichier' => $f]; |
|
| 3336 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3337 | + erreur_squelette($erreur, $c); |
|
| 3338 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3339 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3340 | + } |
|
| 3341 | + |
|
| 3342 | + $page = pipeline('recuperer_fond', [ |
|
| 3343 | + 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3344 | + 'data' => $page |
|
| 3345 | + ]); |
|
| 3346 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3347 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3348 | + include_spip('inc/filtres'); |
|
| 3349 | + } |
|
| 3350 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3351 | + array_merge( |
|
| 3352 | + $contexte, |
|
| 3353 | + ['fond' => $f], |
|
| 3354 | + ($connect ? ['connect' => $connect] : []) |
|
| 3355 | + ), |
|
| 3356 | + '', |
|
| 3357 | + $page['texte'], |
|
| 3358 | + $options['ajax'] |
|
| 3359 | + ); |
|
| 3360 | + } |
|
| 3361 | + |
|
| 3362 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3363 | + $pages[] = $page; |
|
| 3364 | + } else { |
|
| 3365 | + $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3366 | + } |
|
| 3367 | + |
|
| 3368 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3369 | + if (isset($page['invalideurs']['session'])) { |
|
| 3370 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3371 | + } |
|
| 3372 | + } |
|
| 3373 | + |
|
| 3374 | + // restaurer le sessionnement du contexte appelant, |
|
| 3375 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3376 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3377 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3378 | + } |
|
| 3379 | + |
|
| 3380 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3381 | + |
|
| 3382 | + if ($lang_select) { |
|
| 3383 | + lang_select(); |
|
| 3384 | + } |
|
| 3385 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3386 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3387 | + } else { |
|
| 3388 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3389 | + } |
|
| 3391 | 3390 | } |
| 3392 | 3391 | |
| 3393 | 3392 | /** |
@@ -3397,7 +3396,7 @@ discard block |
||
| 3397 | 3396 | * @return string |
| 3398 | 3397 | */ |
| 3399 | 3398 | function trouve_modele($nom) { |
| 3400 | - return trouver_fond($nom, 'modeles/'); |
|
| 3399 | + return trouver_fond($nom, 'modeles/'); |
|
| 3401 | 3400 | } |
| 3402 | 3401 | |
| 3403 | 3402 | /** |
@@ -3413,21 +3412,21 @@ discard block |
||
| 3413 | 3412 | * @return array|string |
| 3414 | 3413 | */ |
| 3415 | 3414 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3416 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3417 | - if (!$pathinfo) { |
|
| 3418 | - return $f; |
|
| 3419 | - } |
|
| 3420 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3421 | - $p = pathinfo($f); |
|
| 3422 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3423 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3424 | - } |
|
| 3425 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3426 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3427 | - } |
|
| 3428 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3415 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3416 | + if (!$pathinfo) { |
|
| 3417 | + return $f; |
|
| 3418 | + } |
|
| 3419 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3420 | + $p = pathinfo($f); |
|
| 3421 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3422 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3423 | + } |
|
| 3424 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3425 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3426 | + } |
|
| 3427 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3429 | 3428 | |
| 3430 | - return $p; |
|
| 3429 | + return $p; |
|
| 3431 | 3430 | } |
| 3432 | 3431 | |
| 3433 | 3432 | /** |
@@ -3447,21 +3446,21 @@ discard block |
||
| 3447 | 3446 | * Nom de l'exec, sinon chaîne vide. |
| 3448 | 3447 | **/ |
| 3449 | 3448 | function tester_url_ecrire($nom) { |
| 3450 | - static $exec = []; |
|
| 3451 | - if (isset($exec[$nom])) { |
|
| 3452 | - return $exec[$nom]; |
|
| 3453 | - } |
|
| 3454 | - // tester si c'est une page en squelette |
|
| 3455 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3456 | - return $exec[$nom] = 'fond'; |
|
| 3457 | - } // echafaudage d'un fond ! |
|
| 3458 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3459 | - return $exec[$nom] = 'fond'; |
|
| 3460 | - } |
|
| 3461 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3462 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3463 | - // et des define intrusifs potentiels |
|
| 3464 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3449 | + static $exec = []; |
|
| 3450 | + if (isset($exec[$nom])) { |
|
| 3451 | + return $exec[$nom]; |
|
| 3452 | + } |
|
| 3453 | + // tester si c'est une page en squelette |
|
| 3454 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3455 | + return $exec[$nom] = 'fond'; |
|
| 3456 | + } // echafaudage d'un fond ! |
|
| 3457 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3458 | + return $exec[$nom] = 'fond'; |
|
| 3459 | + } |
|
| 3460 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3461 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3462 | + // et des define intrusifs potentiels |
|
| 3463 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3465 | 3464 | } |
| 3466 | 3465 | |
| 3467 | 3466 | /** |
@@ -3471,8 +3470,8 @@ discard block |
||
| 3471 | 3470 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3472 | 3471 | **/ |
| 3473 | 3472 | function html5_permis() { |
| 3474 | - return (!defined('_VERSION_HTML') |
|
| 3475 | - or _VERSION_HTML !== 'html4'); |
|
| 3473 | + return (!defined('_VERSION_HTML') |
|
| 3474 | + or _VERSION_HTML !== 'html4'); |
|
| 3476 | 3475 | } |
| 3477 | 3476 | |
| 3478 | 3477 | /** |
@@ -3482,30 +3481,30 @@ discard block |
||
| 3482 | 3481 | * @return array |
| 3483 | 3482 | */ |
| 3484 | 3483 | function formats_image_acceptables($gd = null, $svg_allowed = true) { |
| 3485 | - $formats = null; |
|
| 3486 | - if (!is_null($gd)) { |
|
| 3487 | - $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3488 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3489 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3490 | - $formats = explode(',', $formats); |
|
| 3491 | - $formats = array_filter($formats); |
|
| 3492 | - $formats = array_map('trim', $formats); |
|
| 3493 | - } |
|
| 3494 | - } |
|
| 3495 | - if (is_null($formats)) { |
|
| 3496 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3497 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3498 | - } |
|
| 3499 | - |
|
| 3500 | - if ($svg_allowed) { |
|
| 3501 | - if (!in_array('svg', $formats)) { |
|
| 3502 | - $formats[] = 'svg'; |
|
| 3503 | - } |
|
| 3504 | - } |
|
| 3505 | - else { |
|
| 3506 | - $formats = array_diff($formats, ['svg']); |
|
| 3507 | - } |
|
| 3508 | - return $formats; |
|
| 3484 | + $formats = null; |
|
| 3485 | + if (!is_null($gd)) { |
|
| 3486 | + $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3487 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3488 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3489 | + $formats = explode(',', $formats); |
|
| 3490 | + $formats = array_filter($formats); |
|
| 3491 | + $formats = array_map('trim', $formats); |
|
| 3492 | + } |
|
| 3493 | + } |
|
| 3494 | + if (is_null($formats)) { |
|
| 3495 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3496 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3497 | + } |
|
| 3498 | + |
|
| 3499 | + if ($svg_allowed) { |
|
| 3500 | + if (!in_array('svg', $formats)) { |
|
| 3501 | + $formats[] = 'svg'; |
|
| 3502 | + } |
|
| 3503 | + } |
|
| 3504 | + else { |
|
| 3505 | + $formats = array_diff($formats, ['svg']); |
|
| 3506 | + } |
|
| 3507 | + return $formats; |
|
| 3509 | 3508 | } |
| 3510 | 3509 | |
| 3511 | 3510 | /** |
@@ -3514,20 +3513,20 @@ discard block |
||
| 3514 | 3513 | * @return array|bool |
| 3515 | 3514 | */ |
| 3516 | 3515 | function spip_getimagesize($fichier) { |
| 3517 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3518 | - include_spip('inc/svg'); |
|
| 3519 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3520 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3521 | - $imagesize = [ |
|
| 3522 | - $width, |
|
| 3523 | - $height, |
|
| 3524 | - IMAGETYPE_SVG, |
|
| 3525 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3526 | - 'mime' => 'image/svg+xml' |
|
| 3527 | - ]; |
|
| 3528 | - } |
|
| 3529 | - } |
|
| 3530 | - return $imagesize; |
|
| 3516 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3517 | + include_spip('inc/svg'); |
|
| 3518 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3519 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3520 | + $imagesize = [ |
|
| 3521 | + $width, |
|
| 3522 | + $height, |
|
| 3523 | + IMAGETYPE_SVG, |
|
| 3524 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3525 | + 'mime' => 'image/svg+xml' |
|
| 3526 | + ]; |
|
| 3527 | + } |
|
| 3528 | + } |
|
| 3529 | + return $imagesize; |
|
| 3531 | 3530 | } |
| 3532 | 3531 | |
| 3533 | 3532 | /** |
@@ -3541,19 +3540,19 @@ discard block |
||
| 3541 | 3540 | * @param string $statut |
| 3542 | 3541 | */ |
| 3543 | 3542 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3544 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3545 | - if ( |
|
| 3546 | - !$alertes |
|
| 3547 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3548 | - ) { |
|
| 3549 | - $alertes = []; |
|
| 3550 | - } |
|
| 3543 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3544 | + if ( |
|
| 3545 | + !$alertes |
|
| 3546 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3547 | + ) { |
|
| 3548 | + $alertes = []; |
|
| 3549 | + } |
|
| 3551 | 3550 | |
| 3552 | - if (!isset($alertes[$statut])) { |
|
| 3553 | - $alertes[$statut] = []; |
|
| 3554 | - } |
|
| 3555 | - $alertes[$statut][$nom] = $message; |
|
| 3556 | - ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3551 | + if (!isset($alertes[$statut])) { |
|
| 3552 | + $alertes[$statut] = []; |
|
| 3553 | + } |
|
| 3554 | + $alertes[$statut][$nom] = $message; |
|
| 3555 | + ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3557 | 3556 | } |
| 3558 | 3557 | |
| 3559 | 3558 | /** |
@@ -3567,10 +3566,10 @@ discard block |
||
| 3567 | 3566 | * @return string|string[] |
| 3568 | 3567 | */ |
| 3569 | 3568 | function spip_sanitize_classname($classes) { |
| 3570 | - if (is_array($classes)) { |
|
| 3571 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3572 | - } |
|
| 3573 | - return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3569 | + if (is_array($classes)) { |
|
| 3570 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3571 | + } |
|
| 3572 | + return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3574 | 3573 | } |
| 3575 | 3574 | |
| 3576 | 3575 | |
@@ -3595,32 +3594,32 @@ discard block |
||
| 3595 | 3594 | * Avec operateur : bool. |
| 3596 | 3595 | **/ |
| 3597 | 3596 | function spip_version_compare($v1, $v2, $op = null) { |
| 3598 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3599 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3600 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3601 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3602 | - |
|
| 3603 | - $v1 = explode('.', $v1); |
|
| 3604 | - $v2 = explode('.', $v2); |
|
| 3605 | - // $v1 est toujours une version, donc sans etoile |
|
| 3606 | - while (count($v1) < count($v2)) { |
|
| 3607 | - $v1[] = '0'; |
|
| 3608 | - } |
|
| 3609 | - |
|
| 3610 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3611 | - $etoile = false; |
|
| 3612 | - foreach ($v1 as $k => $v) { |
|
| 3613 | - if (!isset($v2[$k])) { |
|
| 3614 | - $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3615 | - } else { |
|
| 3616 | - if ($v2[$k] == '*') { |
|
| 3617 | - $etoile = true; |
|
| 3618 | - $v2[$k] = $v; |
|
| 3619 | - } |
|
| 3620 | - } |
|
| 3621 | - } |
|
| 3622 | - $v1 = implode('.', $v1); |
|
| 3623 | - $v2 = implode('.', $v2); |
|
| 3624 | - |
|
| 3625 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3597 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3598 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3599 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3600 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3601 | + |
|
| 3602 | + $v1 = explode('.', $v1); |
|
| 3603 | + $v2 = explode('.', $v2); |
|
| 3604 | + // $v1 est toujours une version, donc sans etoile |
|
| 3605 | + while (count($v1) < count($v2)) { |
|
| 3606 | + $v1[] = '0'; |
|
| 3607 | + } |
|
| 3608 | + |
|
| 3609 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3610 | + $etoile = false; |
|
| 3611 | + foreach ($v1 as $k => $v) { |
|
| 3612 | + if (!isset($v2[$k])) { |
|
| 3613 | + $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3614 | + } else { |
|
| 3615 | + if ($v2[$k] == '*') { |
|
| 3616 | + $etoile = true; |
|
| 3617 | + $v2[$k] = $v; |
|
| 3618 | + } |
|
| 3619 | + } |
|
| 3620 | + } |
|
| 3621 | + $v1 = implode('.', $v1); |
|
| 3622 | + $v2 = implode('.', $v2); |
|
| 3623 | + |
|
| 3624 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3626 | 3625 | } |