@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Compilateur\References |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | * - '' si une référence explicite incorrecte est envoyée |
| 45 | 45 | */ |
| 46 | 46 | function index_boucle($p) { |
| 47 | - if (strlen($p->nom_boucle)) { |
|
| 48 | - // retourne l’index explicite demandé s’il existe |
|
| 49 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 50 | - return $p->nom_boucle; |
|
| 51 | - } |
|
| 52 | - return ''; |
|
| 53 | - } |
|
| 54 | - return $p->id_boucle; |
|
| 47 | + if (strlen($p->nom_boucle)) { |
|
| 48 | + // retourne l’index explicite demandé s’il existe |
|
| 49 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 50 | + return $p->nom_boucle; |
|
| 51 | + } |
|
| 52 | + return ''; |
|
| 53 | + } |
|
| 54 | + return $p->id_boucle; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -74,17 +74,17 @@ discard block |
||
| 74 | 74 | * - '' si une référence explicite incorrecte est envoyée |
| 75 | 75 | */ |
| 76 | 76 | function index_boucle_mere($p) { |
| 77 | - if (strlen($p->nom_boucle)) { |
|
| 78 | - // retourne l’index explicite demandé s’il existe |
|
| 79 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 80 | - return $p->nom_boucle; |
|
| 81 | - } |
|
| 82 | - return ''; |
|
| 83 | - } |
|
| 84 | - if (!empty($p->descr['id_mere'])) { |
|
| 85 | - return $p->descr['id_mere']; |
|
| 86 | - } |
|
| 87 | - return ''; |
|
| 77 | + if (strlen($p->nom_boucle)) { |
|
| 78 | + // retourne l’index explicite demandé s’il existe |
|
| 79 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 80 | + return $p->nom_boucle; |
|
| 81 | + } |
|
| 82 | + return ''; |
|
| 83 | + } |
|
| 84 | + if (!empty($p->descr['id_mere'])) { |
|
| 85 | + return $p->descr['id_mere']; |
|
| 86 | + } |
|
| 87 | + return ''; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -118,74 +118,74 @@ discard block |
||
| 118 | 118 | * Code PHP pour obtenir le champ SQL |
| 119 | 119 | */ |
| 120 | 120 | function index_pile( |
| 121 | - $idb, |
|
| 122 | - $nom_champ, |
|
| 123 | - &$boucles, |
|
| 124 | - $explicite = '', |
|
| 125 | - $defaut = null, |
|
| 126 | - $remonte_pile = true, |
|
| 127 | - $select = true |
|
| 121 | + $idb, |
|
| 122 | + $nom_champ, |
|
| 123 | + &$boucles, |
|
| 124 | + $explicite = '', |
|
| 125 | + $defaut = null, |
|
| 126 | + $remonte_pile = true, |
|
| 127 | + $select = true |
|
| 128 | 128 | ) { |
| 129 | - if (!is_string($defaut)) { |
|
| 130 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $idb_origine = $idb; |
|
| 134 | - $nom_champ_origine = $nom_champ; |
|
| 135 | - |
|
| 136 | - $i = 0; |
|
| 137 | - if (strlen($explicite)) { |
|
| 138 | - // Recherche d'un champ dans un etage superieur |
|
| 139 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 140 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 141 | - $i++; |
|
| 142 | - $idb = $boucles[$idb]->id_parent; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 147 | - $nom_champ = strtolower($nom_champ); |
|
| 148 | - $conditionnel = []; |
|
| 149 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 150 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 151 | - while (isset($boucles[$idb])) { |
|
| 152 | - $joker = true; |
|
| 153 | - // modifie $joker si tous les champs sont autorisés. |
|
| 154 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 155 | - // $c = le nom du champ demandé |
|
| 156 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 157 | - if ($t) { |
|
| 158 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 159 | - $boucles[$idb]->select[] = $t; |
|
| 160 | - } |
|
| 161 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 162 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 163 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 164 | - if (!$joker) { |
|
| 165 | - return index_compose($conditionnel, $champ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 169 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 170 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 171 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 172 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ($remonte_pile) { |
|
| 176 | - # spip_log("On remonte vers $i"); |
|
| 177 | - // Sinon on remonte d'un cran |
|
| 178 | - $idb = $boucles[$idb]->id_parent; |
|
| 179 | - $i++; |
|
| 180 | - } else { |
|
| 181 | - $idb = null; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - # spip_log("Pas vu $nom_champ"); |
|
| 186 | - // esperons qu'il y sera |
|
| 187 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 188 | - return index_compose($conditionnel, $defaut); |
|
| 129 | + if (!is_string($defaut)) { |
|
| 130 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $idb_origine = $idb; |
|
| 134 | + $nom_champ_origine = $nom_champ; |
|
| 135 | + |
|
| 136 | + $i = 0; |
|
| 137 | + if (strlen($explicite)) { |
|
| 138 | + // Recherche d'un champ dans un etage superieur |
|
| 139 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 140 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 141 | + $i++; |
|
| 142 | + $idb = $boucles[$idb]->id_parent; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 147 | + $nom_champ = strtolower($nom_champ); |
|
| 148 | + $conditionnel = []; |
|
| 149 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 150 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 151 | + while (isset($boucles[$idb])) { |
|
| 152 | + $joker = true; |
|
| 153 | + // modifie $joker si tous les champs sont autorisés. |
|
| 154 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 155 | + // $c = le nom du champ demandé |
|
| 156 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 157 | + if ($t) { |
|
| 158 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 159 | + $boucles[$idb]->select[] = $t; |
|
| 160 | + } |
|
| 161 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 162 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 163 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 164 | + if (!$joker) { |
|
| 165 | + return index_compose($conditionnel, $champ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 169 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 170 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 171 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 172 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($remonte_pile) { |
|
| 176 | + # spip_log("On remonte vers $i"); |
|
| 177 | + // Sinon on remonte d'un cran |
|
| 178 | + $idb = $boucles[$idb]->id_parent; |
|
| 179 | + $i++; |
|
| 180 | + } else { |
|
| 181 | + $idb = null; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + # spip_log("Pas vu $nom_champ"); |
|
| 186 | + // esperons qu'il y sera |
|
| 187 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 188 | + return index_compose($conditionnel, $defaut); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | * @return string Code PHP complet de recherche d'un champ |
| 200 | 200 | */ |
| 201 | 201 | function index_compose($conditionnel, $defaut) { |
| 202 | - while ($c = array_pop($conditionnel)) { |
|
| 203 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 204 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 205 | - } |
|
| 202 | + while ($c = array_pop($conditionnel)) { |
|
| 203 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 204 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $defaut; |
|
| 207 | + return $defaut; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -240,97 +240,97 @@ discard block |
||
| 240 | 240 | **/ |
| 241 | 241 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 242 | 242 | |
| 243 | - $r = $boucles[$idb]->type_requete; |
|
| 244 | - // boucle recursive, c'est foutu... |
|
| 245 | - if ($r == TYPE_RECURSIF) { |
|
| 246 | - return []; |
|
| 247 | - } |
|
| 248 | - if (!$r) { |
|
| 249 | - $joker = false; // indiquer a l'appelant |
|
| 250 | - # continuer pour chercher l'erreur suivante |
|
| 251 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $desc = $boucles[$idb]->show; |
|
| 255 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 256 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 257 | - if ($excep) { |
|
| 258 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // il y a un alias connu pour ce champ |
|
| 262 | - if ($excep) { |
|
| 263 | - $joker = false; // indiquer a l'appelant |
|
| 264 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // le champ existe dans la table, on le prend. |
|
| 268 | - if (isset($desc['field'][$nom_champ])) { |
|
| 269 | - $t = $boucles[$idb]->id_table ?? ''; |
|
| 270 | - $joker = false; // indiquer a l'appelant |
|
| 271 | - // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 272 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Tous les champs sont-ils acceptés ? |
|
| 276 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 277 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 278 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 279 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 280 | - if ( |
|
| 281 | - /*$joker AND */ |
|
| 282 | - isset($desc['field']['*']) |
|
| 283 | - ) { |
|
| 284 | - $joker = true; // indiquer a l'appelant |
|
| 285 | - return [$nom_champ, $nom_champ]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - $joker = false; // indiquer a l'appelant |
|
| 289 | - |
|
| 290 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 291 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 292 | - [, $_table, $_nom_champ] = $r; |
|
| 293 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 294 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 295 | - return index_exception( |
|
| 296 | - $boucles[$idb], |
|
| 297 | - $desc, |
|
| 298 | - $_alias, |
|
| 299 | - [$_table, $_nom_champ] |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - return ['', '']; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // pas d'alias, pas de champ, pas de joker... |
|
| 306 | - // tenter via une jointure... |
|
| 307 | - |
|
| 308 | - // regarder si le champ est deja dans une jointure existante |
|
| 309 | - // sinon, si il y a des joitures explicites, la construire |
|
| 310 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 311 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 312 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 313 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 314 | - // mais est-ce ce qu'on veut ? |
|
| 315 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 316 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 317 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if ($t) { |
|
| 323 | - // si on a trouvé une jointure possible, on fait comme |
|
| 324 | - // si c'était une exception pour le champ demandé |
|
| 325 | - return index_exception( |
|
| 326 | - $boucles[$idb], |
|
| 327 | - $desc, |
|
| 328 | - $nom_champ, |
|
| 329 | - [$t[1]['id_table'], reset($t[2])] |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - return ['', '']; |
|
| 243 | + $r = $boucles[$idb]->type_requete; |
|
| 244 | + // boucle recursive, c'est foutu... |
|
| 245 | + if ($r == TYPE_RECURSIF) { |
|
| 246 | + return []; |
|
| 247 | + } |
|
| 248 | + if (!$r) { |
|
| 249 | + $joker = false; // indiquer a l'appelant |
|
| 250 | + # continuer pour chercher l'erreur suivante |
|
| 251 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $desc = $boucles[$idb]->show; |
|
| 255 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 256 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 257 | + if ($excep) { |
|
| 258 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // il y a un alias connu pour ce champ |
|
| 262 | + if ($excep) { |
|
| 263 | + $joker = false; // indiquer a l'appelant |
|
| 264 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // le champ existe dans la table, on le prend. |
|
| 268 | + if (isset($desc['field'][$nom_champ])) { |
|
| 269 | + $t = $boucles[$idb]->id_table ?? ''; |
|
| 270 | + $joker = false; // indiquer a l'appelant |
|
| 271 | + // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 272 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Tous les champs sont-ils acceptés ? |
|
| 276 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 277 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 278 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 279 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 280 | + if ( |
|
| 281 | + /*$joker AND */ |
|
| 282 | + isset($desc['field']['*']) |
|
| 283 | + ) { |
|
| 284 | + $joker = true; // indiquer a l'appelant |
|
| 285 | + return [$nom_champ, $nom_champ]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + $joker = false; // indiquer a l'appelant |
|
| 289 | + |
|
| 290 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 291 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 292 | + [, $_table, $_nom_champ] = $r; |
|
| 293 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 294 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 295 | + return index_exception( |
|
| 296 | + $boucles[$idb], |
|
| 297 | + $desc, |
|
| 298 | + $_alias, |
|
| 299 | + [$_table, $_nom_champ] |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + return ['', '']; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // pas d'alias, pas de champ, pas de joker... |
|
| 306 | + // tenter via une jointure... |
|
| 307 | + |
|
| 308 | + // regarder si le champ est deja dans une jointure existante |
|
| 309 | + // sinon, si il y a des joitures explicites, la construire |
|
| 310 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 311 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 312 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 313 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 314 | + // mais est-ce ce qu'on veut ? |
|
| 315 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 316 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 317 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if ($t) { |
|
| 323 | + // si on a trouvé une jointure possible, on fait comme |
|
| 324 | + // si c'était une exception pour le champ demandé |
|
| 325 | + return index_exception( |
|
| 326 | + $boucles[$idb], |
|
| 327 | + $desc, |
|
| 328 | + $nom_champ, |
|
| 329 | + [$t[1]['id_table'], reset($t[2])] |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + return ['', '']; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | |
@@ -358,52 +358,52 @@ discard block |
||
| 358 | 358 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 359 | 359 | **/ |
| 360 | 360 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_array($excep)) { |
|
| 367 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | - $t = null; |
|
| 369 | - if (count($excep) == 3) { |
|
| 370 | - $index_exception_derogatoire = array_pop($excep); |
|
| 371 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | - } |
|
| 373 | - if ($t == null) { |
|
| 374 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | - if (!$j) { |
|
| 378 | - return ['', '']; |
|
| 379 | - } |
|
| 380 | - $e = $j['table']; |
|
| 381 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | - $k = $j['key']['PRIMARY KEY']; |
|
| 383 | - if (strpos($k, ',')) { |
|
| 384 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | - if (!in_array($k, $l)) { |
|
| 387 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 388 | - |
|
| 389 | - return ['', '']; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | - fabrique_jointures($boucle, [$k]); |
|
| 394 | - $t = array_search($e, $boucle->from); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - $t = $boucle->id_table; |
|
| 399 | - } |
|
| 400 | - // demander a SQL de gerer le synonyme |
|
| 401 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | - if ($excep != $nom_champ) { |
|
| 403 | - $excep .= ' AS ' . $nom_champ; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return ["$t.$excep", $nom_champ]; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_array($excep)) { |
|
| 367 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | + $t = null; |
|
| 369 | + if (count($excep) == 3) { |
|
| 370 | + $index_exception_derogatoire = array_pop($excep); |
|
| 371 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | + } |
|
| 373 | + if ($t == null) { |
|
| 374 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | + if (!$j) { |
|
| 378 | + return ['', '']; |
|
| 379 | + } |
|
| 380 | + $e = $j['table']; |
|
| 381 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | + $k = $j['key']['PRIMARY KEY']; |
|
| 383 | + if (strpos($k, ',')) { |
|
| 384 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | + if (!in_array($k, $l)) { |
|
| 387 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 388 | + |
|
| 389 | + return ['', '']; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | + fabrique_jointures($boucle, [$k]); |
|
| 394 | + $t = array_search($e, $boucle->from); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + $t = $boucle->id_table; |
|
| 399 | + } |
|
| 400 | + // demander a SQL de gerer le synonyme |
|
| 401 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | + if ($excep != $nom_champ) { |
|
| 403 | + $excep .= ' AS ' . $nom_champ; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return ["$t.$excep", $nom_champ]; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * Code PHP pour retrouver le champ |
| 429 | 429 | */ |
| 430 | 430 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 431 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 431 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -448,9 +448,9 @@ discard block |
||
| 448 | 448 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 449 | 449 | **/ |
| 450 | 450 | function calculer_champ($p) { |
| 451 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 451 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 452 | 452 | |
| 453 | - return applique_filtres($p); |
|
| 453 | + return applique_filtres($p); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function calculer_balise(string $nom, Champ $p): Champ { |
| 489 | 489 | |
| 490 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | - $p->balise_calculee = true; |
|
| 493 | - $res = $f($p); |
|
| 494 | - if ($res !== null and is_object($res)) { |
|
| 495 | - return $res; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Certaines des balises comportant un _ sont generiques |
|
| 500 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | - $res = $balise_generique['fonction_generique']($p); |
|
| 502 | - if ($res !== null and is_object($res)) { |
|
| 503 | - return $res; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | - |
|
| 509 | - return $f($nom, $p); |
|
| 490 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | + $p->balise_calculee = true; |
|
| 493 | + $res = $f($p); |
|
| 494 | + if ($res !== null and is_object($res)) { |
|
| 495 | + return $res; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Certaines des balises comportant un _ sont generiques |
|
| 500 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | + $res = $balise_generique['fonction_generique']($p); |
|
| 502 | + if ($res !== null and is_object($res)) { |
|
| 503 | + return $res; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | + |
|
| 509 | + return $f($nom, $p); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | |
@@ -534,37 +534,37 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 536 | 536 | |
| 537 | - // ca pourrait etre un champ SQL homonyme, |
|
| 538 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | - |
|
| 540 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 543 | - $code = addslashes($p->fonctions[0][1]); |
|
| 544 | - $p->code .= " . '$code'"; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | - if (strpos($nom, 'ID_') === 0) { |
|
| 549 | - $p->interdire_scripts = false; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | - // SI le champ SQL n'est pas trouve |
|
| 554 | - // ET si la balise a une forme de couleur |
|
| 555 | - // ET s'il n'y a ni filtre ni etoile |
|
| 556 | - // ALORS retourner la couleur. |
|
| 557 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | - if ( |
|
| 559 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 560 | - and !$p->etoile |
|
| 561 | - and !$p->fonctions |
|
| 562 | - ) { |
|
| 563 | - $p->code = "'#$nom'"; |
|
| 564 | - $p->interdire_scripts = false; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - return $p; |
|
| 537 | + // ca pourrait etre un champ SQL homonyme, |
|
| 538 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | + |
|
| 540 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 543 | + $code = addslashes($p->fonctions[0][1]); |
|
| 544 | + $p->code .= " . '$code'"; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | + if (strpos($nom, 'ID_') === 0) { |
|
| 549 | + $p->interdire_scripts = false; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | + // SI le champ SQL n'est pas trouve |
|
| 554 | + // ET si la balise a une forme de couleur |
|
| 555 | + // ET s'il n'y a ni filtre ni etoile |
|
| 556 | + // ALORS retourner la couleur. |
|
| 557 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | + if ( |
|
| 559 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 560 | + and !$p->etoile |
|
| 561 | + and !$p->fonctions |
|
| 562 | + ) { |
|
| 563 | + $p->code = "'#$nom'"; |
|
| 564 | + $p->interdire_scripts = false; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + return $p; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -613,53 +613,53 @@ discard block |
||
| 613 | 613 | **/ |
| 614 | 614 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 615 | 615 | |
| 616 | - if (!balise_distante_interdite($p)) { |
|
| 617 | - $p->code = "''"; |
|
| 618 | - |
|
| 619 | - return $p; |
|
| 620 | - } |
|
| 621 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 622 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 623 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 624 | - $p->fonctions = []; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - if ($p->param and ($c = $p->param[0])) { |
|
| 628 | - // liste d'arguments commence toujours par la chaine vide |
|
| 629 | - array_shift($c); |
|
| 630 | - // construire la liste d'arguments comme pour un filtre |
|
| 631 | - $param = compose_filtres_args($p, $c, ','); |
|
| 632 | - } else { |
|
| 633 | - $param = ''; |
|
| 634 | - } |
|
| 635 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 636 | - |
|
| 637 | - $dans_un_modele = false; |
|
| 638 | - if (!empty($p->descr['sourcefile']) |
|
| 639 | - and $f = $p->descr['sourcefile'] |
|
| 640 | - and basename(dirname($f)) === 'modeles' |
|
| 641 | - ) { |
|
| 642 | - $dans_un_modele = true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - // un modele est toujours inséré en texte dans son contenant |
|
| 646 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 647 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 648 | - // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 649 | - // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 650 | - // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 651 | - $p->code = sprintf( |
|
| 652 | - $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 653 | - $nom, |
|
| 654 | - join(',', $collecte), |
|
| 655 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 656 | - memoriser_contexte_compil($p), |
|
| 657 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 658 | - ); |
|
| 659 | - |
|
| 660 | - $p->interdire_scripts = false; |
|
| 661 | - |
|
| 662 | - return $p; |
|
| 616 | + if (!balise_distante_interdite($p)) { |
|
| 617 | + $p->code = "''"; |
|
| 618 | + |
|
| 619 | + return $p; |
|
| 620 | + } |
|
| 621 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 622 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 623 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 624 | + $p->fonctions = []; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + if ($p->param and ($c = $p->param[0])) { |
|
| 628 | + // liste d'arguments commence toujours par la chaine vide |
|
| 629 | + array_shift($c); |
|
| 630 | + // construire la liste d'arguments comme pour un filtre |
|
| 631 | + $param = compose_filtres_args($p, $c, ','); |
|
| 632 | + } else { |
|
| 633 | + $param = ''; |
|
| 634 | + } |
|
| 635 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 636 | + |
|
| 637 | + $dans_un_modele = false; |
|
| 638 | + if (!empty($p->descr['sourcefile']) |
|
| 639 | + and $f = $p->descr['sourcefile'] |
|
| 640 | + and basename(dirname($f)) === 'modeles' |
|
| 641 | + ) { |
|
| 642 | + $dans_un_modele = true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + // un modele est toujours inséré en texte dans son contenant |
|
| 646 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 647 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 648 | + // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 649 | + // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 650 | + // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 651 | + $p->code = sprintf( |
|
| 652 | + $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 653 | + $nom, |
|
| 654 | + join(',', $collecte), |
|
| 655 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 656 | + memoriser_contexte_compil($p), |
|
| 657 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 658 | + ); |
|
| 659 | + |
|
| 660 | + $p->interdire_scripts = false; |
|
| 661 | + |
|
| 662 | + return $p; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -689,17 +689,17 @@ discard block |
||
| 689 | 689 | * Liste des codes PHP d'éxecution des balises collectées |
| 690 | 690 | **/ |
| 691 | 691 | function collecter_balise_dynamique(array $l, Champ &$p, string $nom): array { |
| 692 | - $args = []; |
|
| 693 | - foreach ($l as $c) { |
|
| 694 | - if ($c === null) { |
|
| 695 | - $args[] = 'null'; |
|
| 696 | - } else { |
|
| 697 | - $x = calculer_balise($c, $p); |
|
| 698 | - $args[] = $x->code; |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return $args; |
|
| 692 | + $args = []; |
|
| 693 | + foreach ($l as $c) { |
|
| 694 | + if ($c === null) { |
|
| 695 | + $args[] = 'null'; |
|
| 696 | + } else { |
|
| 697 | + $x = calculer_balise($c, $p); |
|
| 698 | + $args[] = $x->code; |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return $args; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | |
@@ -714,22 +714,22 @@ discard block |
||
| 714 | 714 | * Nom de la connexion |
| 715 | 715 | **/ |
| 716 | 716 | function trouver_nom_serveur_distant($p) { |
| 717 | - $nom = $p->id_boucle; |
|
| 718 | - if ( |
|
| 719 | - $nom |
|
| 720 | - and isset($p->boucles[$nom]) |
|
| 721 | - ) { |
|
| 722 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 723 | - if ( |
|
| 724 | - strlen($s) |
|
| 725 | - and strlen($serveur = strtolower($s)) |
|
| 726 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 727 | - ) { |
|
| 728 | - return $serveur; |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - return ''; |
|
| 717 | + $nom = $p->id_boucle; |
|
| 718 | + if ( |
|
| 719 | + $nom |
|
| 720 | + and isset($p->boucles[$nom]) |
|
| 721 | + ) { |
|
| 722 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 723 | + if ( |
|
| 724 | + strlen($s) |
|
| 725 | + and strlen($serveur = strtolower($s)) |
|
| 726 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 727 | + ) { |
|
| 728 | + return $serveur; |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + return ''; |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | |
@@ -753,15 +753,15 @@ discard block |
||
| 753 | 753 | * - false : La balise est interdite car le serveur est distant |
| 754 | 754 | **/ |
| 755 | 755 | function balise_distante_interdite($p) { |
| 756 | - $nom = $p->id_boucle; |
|
| 756 | + $nom = $p->id_boucle; |
|
| 757 | 757 | |
| 758 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 759 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 758 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 759 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 760 | 760 | |
| 761 | - return false; |
|
| 762 | - } |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - return true; |
|
| 764 | + return true; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
@@ -771,84 +771,84 @@ discard block |
||
| 771 | 771 | // |
| 772 | 772 | function champs_traitements($p) { |
| 773 | 773 | |
| 774 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 775 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 776 | - } else { |
|
| 777 | - // quand on utilise un traitement catch-all * |
|
| 778 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 779 | - // leur propre securite |
|
| 780 | - if (!$p->balise_calculee) { |
|
| 781 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 782 | - } else { |
|
| 783 | - $ps = false; |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - if (is_array($ps)) { |
|
| 788 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 789 | - $idb = index_boucle($p); |
|
| 790 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 791 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 792 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 796 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 797 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 798 | - |
|
| 799 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 800 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 801 | - $type_alias = $type_requete; |
|
| 802 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 803 | - } else { |
|
| 804 | - $type_alias = false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 808 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 809 | - $ps = $ps[$table_sql]; |
|
| 810 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 811 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 812 | - $ps = $ps[$type_requete]; |
|
| 813 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 814 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 815 | - $ps = $ps[$type_alias]; |
|
| 816 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 817 | - elseif (isset($ps[0])) { |
|
| 818 | - $ps = $ps[0]; |
|
| 819 | - } else { |
|
| 820 | - $ps = false; |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - if (!$ps) { |
|
| 825 | - return $p->code; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 829 | - // ou si in INCLURE contient {doublons} |
|
| 830 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 831 | - // dans les filtres propre() ou typo() |
|
| 832 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 833 | - |
|
| 834 | - if ( |
|
| 835 | - isset($p->descr['documents']) |
|
| 836 | - and |
|
| 837 | - $p->descr['documents'] |
|
| 838 | - and ( |
|
| 839 | - (strpos($ps, 'propre') !== false) |
|
| 840 | - or |
|
| 841 | - (strpos($ps, 'typo') !== false) |
|
| 842 | - ) |
|
| 843 | - ) { |
|
| 844 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 848 | - // dans la declaration des traitements des champs sensibles |
|
| 849 | - |
|
| 850 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 851 | - return str_replace('%s', $p->code, $ps); |
|
| 774 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 775 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 776 | + } else { |
|
| 777 | + // quand on utilise un traitement catch-all * |
|
| 778 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 779 | + // leur propre securite |
|
| 780 | + if (!$p->balise_calculee) { |
|
| 781 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 782 | + } else { |
|
| 783 | + $ps = false; |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + if (is_array($ps)) { |
|
| 788 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 789 | + $idb = index_boucle($p); |
|
| 790 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 791 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 792 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 796 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 797 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 798 | + |
|
| 799 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 800 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 801 | + $type_alias = $type_requete; |
|
| 802 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 803 | + } else { |
|
| 804 | + $type_alias = false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 808 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 809 | + $ps = $ps[$table_sql]; |
|
| 810 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 811 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 812 | + $ps = $ps[$type_requete]; |
|
| 813 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 814 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 815 | + $ps = $ps[$type_alias]; |
|
| 816 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 817 | + elseif (isset($ps[0])) { |
|
| 818 | + $ps = $ps[0]; |
|
| 819 | + } else { |
|
| 820 | + $ps = false; |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + if (!$ps) { |
|
| 825 | + return $p->code; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 829 | + // ou si in INCLURE contient {doublons} |
|
| 830 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 831 | + // dans les filtres propre() ou typo() |
|
| 832 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 833 | + |
|
| 834 | + if ( |
|
| 835 | + isset($p->descr['documents']) |
|
| 836 | + and |
|
| 837 | + $p->descr['documents'] |
|
| 838 | + and ( |
|
| 839 | + (strpos($ps, 'propre') !== false) |
|
| 840 | + or |
|
| 841 | + (strpos($ps, 'typo') !== false) |
|
| 842 | + ) |
|
| 843 | + ) { |
|
| 844 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 848 | + // dans la declaration des traitements des champs sensibles |
|
| 849 | + |
|
| 850 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 851 | + return str_replace('%s', $p->code, $ps); |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | |
@@ -860,110 +860,110 @@ discard block |
||
| 860 | 860 | // |
| 861 | 861 | function applique_filtres($p) { |
| 862 | 862 | |
| 863 | - // Traitements standards (cf. supra) |
|
| 864 | - if ($p->etoile == '') { |
|
| 865 | - $code = champs_traitements($p); |
|
| 866 | - } else { |
|
| 867 | - $code = $p->code; |
|
| 868 | - } |
|
| 863 | + // Traitements standards (cf. supra) |
|
| 864 | + if ($p->etoile == '') { |
|
| 865 | + $code = champs_traitements($p); |
|
| 866 | + } else { |
|
| 867 | + $code = $p->code; |
|
| 868 | + } |
|
| 869 | 869 | |
| 870 | - // Appliquer les filtres perso |
|
| 871 | - if ($p->param) { |
|
| 872 | - $code = compose_filtres($p, $code); |
|
| 873 | - } |
|
| 870 | + // Appliquer les filtres perso |
|
| 871 | + if ($p->param) { |
|
| 872 | + $code = compose_filtres($p, $code); |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 876 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 877 | - if (isset($p->descr['session'])) { |
|
| 878 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 879 | - } |
|
| 875 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 876 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 877 | + if (isset($p->descr['session'])) { |
|
| 878 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 881 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 882 | 882 | |
| 883 | - return $code; |
|
| 883 | + return $code; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 887 | 887 | function compose_filtres(&$p, $code) { |
| 888 | 888 | |
| 889 | - $image_miette = false; |
|
| 890 | - foreach ($p->param as $filtre) { |
|
| 891 | - $fonc = array_shift($filtre); |
|
| 892 | - if (!$fonc) { |
|
| 893 | - continue; |
|
| 894 | - } // normalement qu'au premier tour. |
|
| 895 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 896 | - if ($image_miette and !$is_filtre_image) { |
|
| 897 | - // il faut graver maintenant car apres le filtre en cours |
|
| 898 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 899 | - $code = "filtrer('image_graver', $code)"; |
|
| 900 | - $image_miette = false; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - // recuperer les arguments du filtre, |
|
| 904 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 905 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 906 | - if ($fonc !== '?') { |
|
| 907 | - $sep = ','; |
|
| 908 | - } else { |
|
| 909 | - $sep = ':'; |
|
| 910 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 911 | - if ($countfiltre != 2) { |
|
| 912 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 913 | - $countfiltre = 2; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 917 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 918 | - if ($logique) { |
|
| 919 | - $code = $logique; |
|
| 920 | - } else { |
|
| 921 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 922 | - if ($is_filtre_image) { |
|
| 923 | - $image_miette = true; |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - } |
|
| 927 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 928 | - if ($image_miette) { |
|
| 929 | - $code = "filtrer('image_graver',$code)"; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - return $code; |
|
| 889 | + $image_miette = false; |
|
| 890 | + foreach ($p->param as $filtre) { |
|
| 891 | + $fonc = array_shift($filtre); |
|
| 892 | + if (!$fonc) { |
|
| 893 | + continue; |
|
| 894 | + } // normalement qu'au premier tour. |
|
| 895 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 896 | + if ($image_miette and !$is_filtre_image) { |
|
| 897 | + // il faut graver maintenant car apres le filtre en cours |
|
| 898 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 899 | + $code = "filtrer('image_graver', $code)"; |
|
| 900 | + $image_miette = false; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + // recuperer les arguments du filtre, |
|
| 904 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 905 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 906 | + if ($fonc !== '?') { |
|
| 907 | + $sep = ','; |
|
| 908 | + } else { |
|
| 909 | + $sep = ':'; |
|
| 910 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 911 | + if ($countfiltre != 2) { |
|
| 912 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 913 | + $countfiltre = 2; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 917 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 918 | + if ($logique) { |
|
| 919 | + $code = $logique; |
|
| 920 | + } else { |
|
| 921 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 922 | + if ($is_filtre_image) { |
|
| 923 | + $image_miette = true; |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + } |
|
| 927 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 928 | + if ($image_miette) { |
|
| 929 | + $code = "filtrer('image_graver',$code)"; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + return $code; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 936 | 936 | // et comparateurs |
| 937 | 937 | function filtre_logique($fonc, $code, $arg) { |
| 938 | 938 | |
| 939 | - switch (true) { |
|
| 940 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 941 | - return "($code $fonc $arg)"; |
|
| 942 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 943 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 944 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 945 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 946 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 947 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 948 | - case ($fonc == 'sinon'): |
|
| 949 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 950 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 951 | - return "(($code) ?'' :' ')"; |
|
| 952 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 953 | - return "(($code) ?' ' :'')"; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return ''; |
|
| 939 | + switch (true) { |
|
| 940 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 941 | + return "($code $fonc $arg)"; |
|
| 942 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 943 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 944 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 945 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 946 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 947 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 948 | + case ($fonc == 'sinon'): |
|
| 949 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 950 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 951 | + return "(($code) ?'' :' ')"; |
|
| 952 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 953 | + return "(($code) ?' ' :'')"; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return ''; |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | function compose_filtres_args($p, $args, $sep) { |
| 960 | - $arglist = ''; |
|
| 961 | - foreach ($args as $arg) { |
|
| 962 | - $arglist .= $sep . |
|
| 963 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 964 | - } |
|
| 960 | + $arglist = ''; |
|
| 961 | + foreach ($args as $arg) { |
|
| 962 | + $arglist .= $sep . |
|
| 963 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - return $arglist; |
|
| 966 | + return $arglist; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | |
@@ -981,15 +981,15 @@ discard block |
||
| 981 | 981 | **/ |
| 982 | 982 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 983 | 983 | |
| 984 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 985 | - if ($boucles[$idb]->externe) { |
|
| 986 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 987 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 988 | - // on ignore le defaut fourni dans ce cas |
|
| 989 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 990 | - } |
|
| 984 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 985 | + if ($boucles[$idb]->externe) { |
|
| 986 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 987 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 988 | + // on ignore le defaut fourni dans ce cas |
|
| 989 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 992 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | // |
@@ -1003,30 +1003,30 @@ discard block |
||
| 1003 | 1003 | // |
| 1004 | 1004 | |
| 1005 | 1005 | function rindex_pile($p, $champ, $motif) { |
| 1006 | - $n = 0; |
|
| 1007 | - $b = $p->id_boucle; |
|
| 1008 | - $p->code = ''; |
|
| 1009 | - while ($b != '') { |
|
| 1010 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 1011 | - if ($critere->op == $motif) { |
|
| 1012 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 1013 | - "]['$champ']"; |
|
| 1014 | - $b = ''; |
|
| 1015 | - break 2; |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - $n++; |
|
| 1019 | - $b = $p->boucles[$b]->id_parent; |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1023 | - if (!$p->code) { |
|
| 1024 | - $p->code = "''"; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - $p->interdire_scripts = false; |
|
| 1028 | - |
|
| 1029 | - return $p; |
|
| 1006 | + $n = 0; |
|
| 1007 | + $b = $p->id_boucle; |
|
| 1008 | + $p->code = ''; |
|
| 1009 | + while ($b != '') { |
|
| 1010 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 1011 | + if ($critere->op == $motif) { |
|
| 1012 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 1013 | + "]['$champ']"; |
|
| 1014 | + $b = ''; |
|
| 1015 | + break 2; |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + $n++; |
|
| 1019 | + $b = $p->boucles[$b]->id_parent; |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1023 | + if (!$p->code) { |
|
| 1024 | + $p->code = "''"; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + $p->interdire_scripts = false; |
|
| 1028 | + |
|
| 1029 | + return $p; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | /** |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1037 | 1037 | */ |
| 1038 | 1038 | function zbug_presenter_champ($p, $champ = '') { |
| 1039 | - $balise = $champ ?: $p->nom_champ; |
|
| 1040 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1041 | - return "#{$explicite}{$balise}"; |
|
| 1039 | + $balise = $champ ?: $p->nom_champ; |
|
| 1040 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1041 | + return "#{$explicite}{$balise}"; |
|
| 1042 | 1042 | } |
@@ -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,90 +48,90 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function declarer_interfaces() { |
| 50 | 50 | |
| 51 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 52 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 53 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 54 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 55 | - |
|
| 56 | - // definition des statuts de publication |
|
| 57 | - $GLOBALS['table_statut'] = []; |
|
| 58 | - |
|
| 59 | - // |
|
| 60 | - // tableau des tables de jointures |
|
| 61 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 62 | - $GLOBALS['tables_jointures'] = []; |
|
| 63 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 64 | - |
|
| 65 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 66 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - if (!defined('_TRAITEMENT_TYPO')) { |
|
| 70 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 71 | - } |
|
| 72 | - if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 73 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 74 | - } |
|
| 75 | - if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 76 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 77 | - } |
|
| 78 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 79 | - $GLOBALS['table_des_traitements']['NOM_SITE']['auteurs'] = 'entites_html(%s)'; |
|
| 80 | - $GLOBALS['table_des_traitements']['NOM']['auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 81 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 82 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 83 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 84 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 85 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 86 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 87 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 88 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 89 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 90 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 91 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 92 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 93 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 94 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 95 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 96 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 97 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 98 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 99 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 100 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 101 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 102 | - |
|
| 103 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 104 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 105 | - // toujours securiser les DATA |
|
| 106 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 107 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 108 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 112 | - $interfaces = pipeline( |
|
| 113 | - 'declarer_tables_interfaces', |
|
| 114 | - [ |
|
| 115 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 116 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 117 | - 'table_date' => $GLOBALS['table_date'], |
|
| 118 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 119 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 120 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 121 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 122 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 123 | - ] |
|
| 124 | - ); |
|
| 125 | - if ($interfaces) { |
|
| 126 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 127 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 128 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 129 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 130 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 131 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 132 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 133 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 134 | - } |
|
| 51 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 52 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 53 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 54 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 55 | + |
|
| 56 | + // definition des statuts de publication |
|
| 57 | + $GLOBALS['table_statut'] = []; |
|
| 58 | + |
|
| 59 | + // |
|
| 60 | + // tableau des tables de jointures |
|
| 61 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 62 | + $GLOBALS['tables_jointures'] = []; |
|
| 63 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 64 | + |
|
| 65 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 66 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + if (!defined('_TRAITEMENT_TYPO')) { |
|
| 70 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 71 | + } |
|
| 72 | + if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 73 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 74 | + } |
|
| 75 | + if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 76 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 77 | + } |
|
| 78 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 79 | + $GLOBALS['table_des_traitements']['NOM_SITE']['auteurs'] = 'entites_html(%s)'; |
|
| 80 | + $GLOBALS['table_des_traitements']['NOM']['auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 81 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 82 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 83 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 84 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 85 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 86 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 87 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 88 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 89 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 90 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 91 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 92 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 93 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 94 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 95 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 96 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 97 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 98 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 99 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 100 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 101 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 102 | + |
|
| 103 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 104 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 105 | + // toujours securiser les DATA |
|
| 106 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 107 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 108 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 112 | + $interfaces = pipeline( |
|
| 113 | + 'declarer_tables_interfaces', |
|
| 114 | + [ |
|
| 115 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 116 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 117 | + 'table_date' => $GLOBALS['table_date'], |
|
| 118 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 119 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 120 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 121 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 122 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 123 | + ] |
|
| 124 | + ); |
|
| 125 | + if ($interfaces) { |
|
| 126 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 127 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 128 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 129 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 130 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 131 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 132 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 133 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | declarer_interfaces(); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -41,234 +41,234 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 43 | 43 | |
| 44 | - $skel = null; |
|
| 45 | - $boucle = null; |
|
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - eval("return true; $f ;"); |
|
| 96 | - } catch (\ParseError $e) { |
|
| 97 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | - erreur_squelette($msg, $boucle); |
|
| 100 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | - // mais prevenir que c'est mort |
|
| 102 | - $nom = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // contexte de compil inutile a present |
|
| 106 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | - $skel_code[$id] = $f; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $code = ''; |
|
| 111 | - if ($nom) { |
|
| 112 | - // Si le code est bon, concatener et mettre en cache |
|
| 113 | - if (function_exists($nom)) { |
|
| 114 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | - } else { |
|
| 116 | - // code semantiquement faux: bug du compilateur |
|
| 117 | - // $boucle est en fait ici la fct principale du squelette |
|
| 118 | - $msg = _T('zbug_erreur_compilation'); |
|
| 119 | - erreur_squelette($msg, $boucle); |
|
| 120 | - $nom = ''; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | - // Tracer ce qui vient d'etre compile |
|
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | - |
|
| 128 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | - if ( |
|
| 130 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | - and (_request('var_mode_objet') == $nom) |
|
| 132 | - and (_request('var_mode_affiche') == 'code') |
|
| 133 | - ) { |
|
| 134 | - erreur_squelette(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $nom ?: false; |
|
| 44 | + $skel = null; |
|
| 45 | + $boucle = null; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + eval("return true; $f ;"); |
|
| 96 | + } catch (\ParseError $e) { |
|
| 97 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + erreur_squelette($msg, $boucle); |
|
| 100 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | + // mais prevenir que c'est mort |
|
| 102 | + $nom = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // contexte de compil inutile a present |
|
| 106 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | + $skel_code[$id] = $f; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $code = ''; |
|
| 111 | + if ($nom) { |
|
| 112 | + // Si le code est bon, concatener et mettre en cache |
|
| 113 | + if (function_exists($nom)) { |
|
| 114 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | + } else { |
|
| 116 | + // code semantiquement faux: bug du compilateur |
|
| 117 | + // $boucle est en fait ici la fct principale du squelette |
|
| 118 | + $msg = _T('zbug_erreur_compilation'); |
|
| 119 | + erreur_squelette($msg, $boucle); |
|
| 120 | + $nom = ''; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | + // Tracer ce qui vient d'etre compile |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + |
|
| 128 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | + if ( |
|
| 130 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | + and (_request('var_mode_objet') == $nom) |
|
| 132 | + and (_request('var_mode_affiche') == 'code') |
|
| 133 | + ) { |
|
| 134 | + erreur_squelette(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $nom ?: false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - $code = null; |
|
| 144 | - // Le dernier index est '' (fonction principale) |
|
| 145 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | - if (CODE_COMMENTE) { |
|
| 147 | - $code = " |
|
| 143 | + $code = null; |
|
| 144 | + // Le dernier index est '' (fonction principale) |
|
| 145 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | + if (CODE_COMMENTE) { |
|
| 147 | + $code = " |
|
| 148 | 148 | /* |
| 149 | 149 | * Squelette : $sourcefile |
| 150 | 150 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 151 | 151 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 152 | 152 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 153 | 153 | */ '; |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | - ecrire_fichier($phpfile, $code); |
|
| 159 | - } |
|
| 156 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | + ecrire_fichier($phpfile, $code); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $code; |
|
| 161 | + return $code; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Le squelette compile est-il trop vieux ? |
| 165 | 165 | function squelette_obsolete($skel, $squelette) { |
| 166 | - static $date_change = null; |
|
| 167 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | - // par hit |
|
| 169 | - if (is_null($date_change)) { |
|
| 170 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | - $date_change = @filemtime($fonc); |
|
| 172 | - } # compatibilite |
|
| 173 | - if (defined('_FILE_OPTIONS')) { |
|
| 174 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return ( |
|
| 179 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | - or !@file_exists($skel) |
|
| 181 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | - > ($date = @filemtime($skel))) |
|
| 183 | - or ($date_change > $date) |
|
| 184 | - ); |
|
| 166 | + static $date_change = null; |
|
| 167 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | + // par hit |
|
| 169 | + if (is_null($date_change)) { |
|
| 170 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | + $date_change = @filemtime($fonc); |
|
| 172 | + } # compatibilite |
|
| 173 | + if (defined('_FILE_OPTIONS')) { |
|
| 174 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return ( |
|
| 179 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | + or !@file_exists($skel) |
|
| 181 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | + > ($date = @filemtime($skel))) |
|
| 183 | + or ($date_change > $date) |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - and preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - strpos($corps, '<' . '?') === false |
|
| 227 | - or |
|
| 228 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | - ) |
|
| 231 | - ? 'html' |
|
| 232 | - : 'php'; |
|
| 233 | - |
|
| 234 | - $skel = [ |
|
| 235 | - 'squelette' => $nom, |
|
| 236 | - 'source' => $source, |
|
| 237 | - 'process_ins' => $process_ins, |
|
| 238 | - 'invalideurs' => $cache, |
|
| 239 | - 'entetes' => $headers, |
|
| 240 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | - ]; |
|
| 242 | - |
|
| 243 | - // traiter #FILTRE{} et filtres |
|
| 244 | - if (!isset($filtres[$nom])) { |
|
| 245 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | - } |
|
| 247 | - $filtres_headers = []; |
|
| 248 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | - unset($headers['X-Spip-Filtre']); |
|
| 251 | - } |
|
| 252 | - if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | - include_spip('public/sandbox'); |
|
| 254 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | - |
|
| 256 | - if ($process_ins == 'html') { |
|
| 257 | - $skel['process_ins'] = ( |
|
| 258 | - strpos($corps, '<' . '?') === false |
|
| 259 | - or |
|
| 260 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | - ) |
|
| 263 | - ? 'html' |
|
| 264 | - : 'php'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $skel['entetes'] = $headers; |
|
| 269 | - $skel['texte'] = $corps; |
|
| 270 | - |
|
| 271 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + and preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + strpos($corps, '<' . '?') === false |
|
| 227 | + or |
|
| 228 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | + ) |
|
| 231 | + ? 'html' |
|
| 232 | + : 'php'; |
|
| 233 | + |
|
| 234 | + $skel = [ |
|
| 235 | + 'squelette' => $nom, |
|
| 236 | + 'source' => $source, |
|
| 237 | + 'process_ins' => $process_ins, |
|
| 238 | + 'invalideurs' => $cache, |
|
| 239 | + 'entetes' => $headers, |
|
| 240 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | + ]; |
|
| 242 | + |
|
| 243 | + // traiter #FILTRE{} et filtres |
|
| 244 | + if (!isset($filtres[$nom])) { |
|
| 245 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | + } |
|
| 247 | + $filtres_headers = []; |
|
| 248 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | + unset($headers['X-Spip-Filtre']); |
|
| 251 | + } |
|
| 252 | + if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | + include_spip('public/sandbox'); |
|
| 254 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | + |
|
| 256 | + if ($process_ins == 'html') { |
|
| 257 | + $skel['process_ins'] = ( |
|
| 258 | + strpos($corps, '<' . '?') === false |
|
| 259 | + or |
|
| 260 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | + ) |
|
| 263 | + ? 'html' |
|
| 264 | + : 'php'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $skel['entetes'] = $headers; |
|
| 269 | + $skel['texte'] = $corps; |
|
| 270 | + |
|
| 271 | + return $skel; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 283 | 283 | if ($lang_select) lang_select(); |
| 284 | 284 | ?' |
| 285 | - . '>'); |
|
| 285 | + . '>'); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | * Code PHP pour inclure le squelette de la balise dynamique |
| 303 | 303 | **/ |
| 304 | 304 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 305 | - if ( |
|
| 306 | - strncmp($file, '/', 1) !== 0 |
|
| 307 | - // pas de lien symbolique sous Windows |
|
| 308 | - and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | - ) { |
|
| 310 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $lang = $context_compil[4]; |
|
| 314 | - if (preg_match(',\W,', $lang)) { |
|
| 315 | - $lang = ''; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $args = array_map('argumenter_squelette', $args); |
|
| 319 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | - } |
|
| 322 | - $args = join(', ', $args); |
|
| 323 | - |
|
| 324 | - $r = sprintf( |
|
| 325 | - CODE_INCLURE_BALISE, |
|
| 326 | - $file, |
|
| 327 | - $lang, |
|
| 328 | - $nom, |
|
| 329 | - $args, |
|
| 330 | - join(', ', array_map('_q', $context_compil)) |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - return $r; |
|
| 305 | + if ( |
|
| 306 | + strncmp($file, '/', 1) !== 0 |
|
| 307 | + // pas de lien symbolique sous Windows |
|
| 308 | + and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | + ) { |
|
| 310 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $lang = $context_compil[4]; |
|
| 314 | + if (preg_match(',\W,', $lang)) { |
|
| 315 | + $lang = ''; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $args = array_map('argumenter_squelette', $args); |
|
| 319 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + } |
|
| 322 | + $args = join(', ', $args); |
|
| 323 | + |
|
| 324 | + $r = sprintf( |
|
| 325 | + CODE_INCLURE_BALISE, |
|
| 326 | + $file, |
|
| 327 | + $lang, |
|
| 328 | + $nom, |
|
| 329 | + $args, |
|
| 330 | + join(', ', array_map('_q', $context_compil)) |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + return $r; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | **/ |
| 349 | 349 | function argumenter_squelette($v) { |
| 350 | 350 | |
| 351 | - if (is_object($v)) { |
|
| 352 | - return var_export($v, true); |
|
| 353 | - } elseif (!is_array($v)) { |
|
| 354 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | - } else { |
|
| 356 | - $out = []; |
|
| 357 | - foreach ($v as $k => $val) { |
|
| 358 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | - } |
|
| 351 | + if (is_object($v)) { |
|
| 352 | + return var_export($v, true); |
|
| 353 | + } elseif (!is_array($v)) { |
|
| 354 | + return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + } else { |
|
| 356 | + $out = []; |
|
| 357 | + foreach ($v as $k => $val) { |
|
| 358 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | 380 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 381 | - if (test_espace_prive()) { |
|
| 382 | - return executer_balise_dynamique(...$args); |
|
| 383 | - } |
|
| 384 | - else { |
|
| 385 | - $str_args = base64_encode(serialize($args)); |
|
| 386 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | - } |
|
| 381 | + if (test_espace_prive()) { |
|
| 382 | + return executer_balise_dynamique(...$args); |
|
| 383 | + } |
|
| 384 | + else { |
|
| 385 | + $str_args = base64_encode(serialize($args)); |
|
| 386 | + return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -415,87 +415,87 @@ discard block |
||
| 415 | 415 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 416 | 416 | **/ |
| 417 | 417 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 418 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | - $nom_balise = $nom; |
|
| 420 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | - $nom_balise_generique = ''; |
|
| 422 | - |
|
| 423 | - $appel_php_depuis_modele = false; |
|
| 424 | - if ( |
|
| 425 | - is_array($context_compil) |
|
| 426 | - and !is_numeric($context_compil[3]) |
|
| 427 | - and empty($context_compil[0]) |
|
| 428 | - and empty($context_compil[1]) |
|
| 429 | - and empty($context_compil[2]) |
|
| 430 | - and empty($context_compil[3]) |
|
| 431 | - ) { |
|
| 432 | - $appel_php_depuis_modele = true; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | - // injecter en premier arg le nom de la balise |
|
| 439 | - array_unshift($args, $nom); |
|
| 440 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | - $nom_balise = $nom_balise_generique; |
|
| 443 | - } |
|
| 444 | - unset($balise_generique); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (!$fonction_balise) { |
|
| 448 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | - erreur_squelette($msg, $context_compil); |
|
| 450 | - |
|
| 451 | - return ''; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // retrouver le fichier qui a déclaré la fonction |
|
| 455 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | - |
|
| 466 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | - |
|
| 468 | - if (!is_array($r)) { |
|
| 469 | - return $r; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // verifier que la fonction dyn est la, |
|
| 473 | - // sinon se replier sur la generique si elle existe |
|
| 474 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | - if ( |
|
| 476 | - $balise_generique = chercher_balise_generique($nom) |
|
| 477 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | - ) { |
|
| 481 | - // et lui injecter en premier arg le nom de la balise |
|
| 482 | - array_unshift($r, $nom); |
|
| 483 | - $nom_balise = $nom_balise_generique; |
|
| 484 | - if (!_DIR_RESTREINT) { |
|
| 485 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | - } |
|
| 487 | - } else { |
|
| 488 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | - erreur_squelette($msg, $context_compil); |
|
| 490 | - |
|
| 491 | - return ''; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($appel_php_depuis_modele) { |
|
| 496 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | - } |
|
| 498 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 418 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | + $nom_balise = $nom; |
|
| 420 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | + $nom_balise_generique = ''; |
|
| 422 | + |
|
| 423 | + $appel_php_depuis_modele = false; |
|
| 424 | + if ( |
|
| 425 | + is_array($context_compil) |
|
| 426 | + and !is_numeric($context_compil[3]) |
|
| 427 | + and empty($context_compil[0]) |
|
| 428 | + and empty($context_compil[1]) |
|
| 429 | + and empty($context_compil[2]) |
|
| 430 | + and empty($context_compil[3]) |
|
| 431 | + ) { |
|
| 432 | + $appel_php_depuis_modele = true; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | + // injecter en premier arg le nom de la balise |
|
| 439 | + array_unshift($args, $nom); |
|
| 440 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | + $nom_balise = $nom_balise_generique; |
|
| 443 | + } |
|
| 444 | + unset($balise_generique); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (!$fonction_balise) { |
|
| 448 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | + erreur_squelette($msg, $context_compil); |
|
| 450 | + |
|
| 451 | + return ''; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // retrouver le fichier qui a déclaré la fonction |
|
| 455 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | + |
|
| 466 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | + |
|
| 468 | + if (!is_array($r)) { |
|
| 469 | + return $r; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // verifier que la fonction dyn est la, |
|
| 473 | + // sinon se replier sur la generique si elle existe |
|
| 474 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | + if ( |
|
| 476 | + $balise_generique = chercher_balise_generique($nom) |
|
| 477 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | + ) { |
|
| 481 | + // et lui injecter en premier arg le nom de la balise |
|
| 482 | + array_unshift($r, $nom); |
|
| 483 | + $nom_balise = $nom_balise_generique; |
|
| 484 | + if (!_DIR_RESTREINT) { |
|
| 485 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | + } |
|
| 487 | + } else { |
|
| 488 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | + erreur_squelette($msg, $context_compil); |
|
| 490 | + |
|
| 491 | + return ''; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($appel_php_depuis_modele) { |
|
| 496 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | + } |
|
| 498 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -510,23 +510,23 @@ discard block |
||
| 510 | 510 | * @return array|null |
| 511 | 511 | */ |
| 512 | 512 | function chercher_balise_generique($nom) { |
| 513 | - if (!str_contains($nom, '_')) { |
|
| 514 | - return null; |
|
| 515 | - } |
|
| 516 | - $nom_generique = $nom; |
|
| 517 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | - if ($fonction_generique) { |
|
| 521 | - return [ |
|
| 522 | - 'nom' => $nom, |
|
| 523 | - 'nom_generique' => $nom_generique, |
|
| 524 | - 'fonction_generique' => $fonction_generique, |
|
| 525 | - ]; |
|
| 526 | - } |
|
| 527 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | - } |
|
| 529 | - return null; |
|
| 513 | + if (!str_contains($nom, '_')) { |
|
| 514 | + return null; |
|
| 515 | + } |
|
| 516 | + $nom_generique = $nom; |
|
| 517 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | + if ($fonction_generique) { |
|
| 521 | + return [ |
|
| 522 | + 'nom' => $nom, |
|
| 523 | + 'nom_generique' => $nom_generique, |
|
| 524 | + 'fonction_generique' => $fonction_generique, |
|
| 525 | + ]; |
|
| 526 | + } |
|
| 527 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | + } |
|
| 529 | + return null; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | |
@@ -550,50 +550,50 @@ discard block |
||
| 550 | 550 | * @return null; |
| 551 | 551 | **/ |
| 552 | 552 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 553 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | - if ( |
|
| 555 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | - and $lang_select !== 'oui' |
|
| 557 | - ) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | - elseif (!strlen($lang)) { |
|
| 561 | - $lang = $GLOBALS['spip_lang']; |
|
| 562 | - } // Cas 3. l'objet est multilingue ! |
|
| 563 | - elseif ( |
|
| 564 | - $lang_select !== 'oui' |
|
| 565 | - and strlen($titre) > 10 |
|
| 566 | - and str_contains($titre, '<multi>') |
|
| 567 | - and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | - ) { |
|
| 569 | - $lang = $GLOBALS['spip_lang']; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | - lang_select($lang); |
|
| 574 | - |
|
| 575 | - return; |
|
| 553 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | + if ( |
|
| 555 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | + and $lang_select !== 'oui' |
|
| 557 | + ) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | + elseif (!strlen($lang)) { |
|
| 561 | + $lang = $GLOBALS['spip_lang']; |
|
| 562 | + } // Cas 3. l'objet est multilingue ! |
|
| 563 | + elseif ( |
|
| 564 | + $lang_select !== 'oui' |
|
| 565 | + and strlen($titre) > 10 |
|
| 566 | + and str_contains($titre, '<multi>') |
|
| 567 | + and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | + ) { |
|
| 569 | + $lang = $GLOBALS['spip_lang']; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | + lang_select($lang); |
|
| 574 | + |
|
| 575 | + return; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | // Si un tableau &doublons[articles] est passe en parametre, |
| 580 | 580 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 581 | 581 | function nettoyer_env_doublons($envd) { |
| 582 | - foreach ($envd as $table => $liste) { |
|
| 583 | - $n = ''; |
|
| 584 | - foreach (explode(',', $liste) as $val) { |
|
| 585 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | - $n .= ',' . $val; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - if (strlen($n)) { |
|
| 590 | - $envd[$table] = $n; |
|
| 591 | - } else { |
|
| 592 | - unset($envd[$table]); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $envd; |
|
| 582 | + foreach ($envd as $table => $liste) { |
|
| 583 | + $n = ''; |
|
| 584 | + foreach (explode(',', $liste) as $val) { |
|
| 585 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | + $n .= ',' . $val; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + if (strlen($n)) { |
|
| 590 | + $envd[$table] = $n; |
|
| 591 | + } else { |
|
| 592 | + unset($envd[$table]); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $envd; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -612,21 +612,21 @@ discard block |
||
| 612 | 612 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 613 | 613 | **/ |
| 614 | 614 | function match_self($w) { |
| 615 | - if (is_string($w)) { |
|
| 616 | - return false; |
|
| 617 | - } |
|
| 618 | - if (is_array($w)) { |
|
| 619 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | - return $w; |
|
| 621 | - } |
|
| 622 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | - if ($m = match_self($sw)) { |
|
| 624 | - return $m; |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - return false; |
|
| 615 | + if (is_string($w)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 618 | + if (is_array($w)) { |
|
| 619 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | + return $w; |
|
| 621 | + } |
|
| 622 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | + if ($m = match_self($sw)) { |
|
| 624 | + return $m; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + return false; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -642,16 +642,16 @@ discard block |
||
| 642 | 642 | * est remplacée par son code. |
| 643 | 643 | **/ |
| 644 | 644 | function remplace_sous_requete($w, $sousrequete) { |
| 645 | - if (is_array($w)) { |
|
| 646 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | - return $sousrequete; |
|
| 648 | - } |
|
| 649 | - foreach ($w as $k => $sw) { |
|
| 650 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $w; |
|
| 645 | + if (is_array($w)) { |
|
| 646 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | + return $sousrequete; |
|
| 648 | + } |
|
| 649 | + foreach ($w as $k => $sw) { |
|
| 650 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $w; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -665,17 +665,17 @@ discard block |
||
| 665 | 665 | * - Conditions avec des sous requêtes |
| 666 | 666 | **/ |
| 667 | 667 | function trouver_sous_requetes($where) { |
| 668 | - $where_simples = []; |
|
| 669 | - $where_sous = []; |
|
| 670 | - foreach ($where as $k => $w) { |
|
| 671 | - if (match_self($w)) { |
|
| 672 | - $where_sous[$k] = $w; |
|
| 673 | - } else { |
|
| 674 | - $where_simples[$k] = $w; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return [$where_simples, $where_sous]; |
|
| 668 | + $where_simples = []; |
|
| 669 | + $where_sous = []; |
|
| 670 | + foreach ($where as $k => $w) { |
|
| 671 | + if (match_self($w)) { |
|
| 672 | + $where_sous[$k] = $w; |
|
| 673 | + } else { |
|
| 674 | + $where_simples[$k] = $w; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return [$where_simples, $where_sous]; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -701,292 +701,292 @@ discard block |
||
| 701 | 701 | * @return resource |
| 702 | 702 | */ |
| 703 | 703 | function calculer_select( |
| 704 | - $select = [], |
|
| 705 | - $from = [], |
|
| 706 | - $from_type = [], |
|
| 707 | - $where = [], |
|
| 708 | - $join = [], |
|
| 709 | - $groupby = [], |
|
| 710 | - $orderby = [], |
|
| 711 | - $limit = '', |
|
| 712 | - $having = [], |
|
| 713 | - $table = '', |
|
| 714 | - $id = '', |
|
| 715 | - $serveur = '', |
|
| 716 | - $requeter = true |
|
| 704 | + $select = [], |
|
| 705 | + $from = [], |
|
| 706 | + $from_type = [], |
|
| 707 | + $where = [], |
|
| 708 | + $join = [], |
|
| 709 | + $groupby = [], |
|
| 710 | + $orderby = [], |
|
| 711 | + $limit = '', |
|
| 712 | + $having = [], |
|
| 713 | + $table = '', |
|
| 714 | + $id = '', |
|
| 715 | + $serveur = '', |
|
| 716 | + $requeter = true |
|
| 717 | 717 | ) { |
| 718 | 718 | |
| 719 | - // retirer les criteres vides: |
|
| 720 | - // {X ?} avec X absent de l'URL |
|
| 721 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | - $menage = false; |
|
| 724 | - foreach ($where as $k => $v) { |
|
| 725 | - if (is_array($v) and count($v)) { |
|
| 726 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | - $op = false; |
|
| 728 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | - $op = false; |
|
| 730 | - } else { |
|
| 731 | - $op = $v[0] ?: $v; |
|
| 732 | - } |
|
| 733 | - } else { |
|
| 734 | - $op = $v; |
|
| 735 | - } |
|
| 736 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | - unset($where[$k]); |
|
| 738 | - $menage = true; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | - $groupby = array_diff($groupby, ['']); |
|
| 744 | - |
|
| 745 | - // remplacer les sous requetes recursives au calcul |
|
| 746 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | - foreach ($where_sous as $k => $w) { |
|
| 748 | - $menage = true; |
|
| 749 | - // on recupere la sous requete |
|
| 750 | - $sous = match_self($w); |
|
| 751 | - if ($sous[0] == 'SELF') { |
|
| 752 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | - array_push($where_simples, $sous[2]); |
|
| 754 | - $wheresub = [ |
|
| 755 | - $sous[2], |
|
| 756 | - '0=0' |
|
| 757 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | - $jsub = $join; |
|
| 759 | - // trouver les jointures utiles a |
|
| 760 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | - // ie L1.objet='article' |
|
| 762 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | - $i = 0; |
|
| 764 | - do { |
|
| 765 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | - [$sous[1] . ' AS id'], |
|
| 767 | - $from, |
|
| 768 | - $from_type, |
|
| 769 | - $wheresub, |
|
| 770 | - $jsub, |
|
| 771 | - [], |
|
| 772 | - [], |
|
| 773 | - '', |
|
| 774 | - $having, |
|
| 775 | - $table, |
|
| 776 | - $id, |
|
| 777 | - $serveur, |
|
| 778 | - false |
|
| 779 | - ) . ')'); |
|
| 780 | - if (!$i) { |
|
| 781 | - $i = 1; |
|
| 782 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | - foreach ($join as $cle => $wj) { |
|
| 784 | - if ( |
|
| 785 | - (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | - and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | - ) { |
|
| 788 | - $i = 0; |
|
| 789 | - $wheresub[] = $wj[3]; |
|
| 790 | - unset($jsub[$cle][3]); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } while ($i++ < 1); |
|
| 795 | - } |
|
| 796 | - if ($sous[0] == 'SUBSELECT') { |
|
| 797 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | - $sous[1], # select |
|
| 801 | - $sous[2], #from |
|
| 802 | - [], #from_type |
|
| 803 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | - [], #join |
|
| 806 | - $sous[4] ?: [], #groupby |
|
| 807 | - $sous[5] ?: [], #orderby |
|
| 808 | - $sous[6], #limit |
|
| 809 | - $sous[7] ?: [], #having |
|
| 810 | - $table, |
|
| 811 | - $id, |
|
| 812 | - $serveur, |
|
| 813 | - false |
|
| 814 | - ) . ')'); |
|
| 815 | - } |
|
| 816 | - array_pop($where_simples); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - foreach ($having as $k => $v) { |
|
| 820 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | - unset($having[$k]); |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - // Installer les jointures. |
|
| 826 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | - |
|
| 830 | - $afrom = []; |
|
| 831 | - $equiv = []; |
|
| 832 | - $k = count($join); |
|
| 833 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | - $cle = $cledef; |
|
| 835 | - // le format de join est : |
|
| 836 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | - if (count($join[$cle]) == 2) { |
|
| 839 | - $join[$cle][] = $join[$cle][1]; |
|
| 840 | - } |
|
| 841 | - if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | - $join[$cle][] = ''; |
|
| 843 | - } |
|
| 844 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | - // pour compat avec ancienne convention |
|
| 847 | - if (is_numeric($cle)) { |
|
| 848 | - $cle = "L$k"; |
|
| 849 | - } |
|
| 850 | - $cle_where_lie = "JOIN-$cle"; |
|
| 851 | - if ( |
|
| 852 | - !$menage |
|
| 853 | - or isset($afrom[$cle]) |
|
| 854 | - or calculer_jointnul($cle, $select) |
|
| 855 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | - or calculer_jointnul($cle, $having) |
|
| 857 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | - ) { |
|
| 859 | - // corriger les references non explicites dans select |
|
| 860 | - // ou groupby |
|
| 861 | - foreach ($select as $i => $s) { |
|
| 862 | - if ($s == $c) { |
|
| 863 | - $select[$i] = "$cle.$c AS $c"; |
|
| 864 | - break; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - foreach ($groupby as $i => $g) { |
|
| 868 | - if ($g == $c) { |
|
| 869 | - $groupby[$i] = "$cle.$c"; |
|
| 870 | - break; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | - // sans recours a preg_match |
|
| 875 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | - $afrom[$t][$cle] = [ |
|
| 877 | - "\n" . |
|
| 878 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | - $from[$cle], |
|
| 880 | - "AS $cle", |
|
| 881 | - 'ON (', |
|
| 882 | - "$cle.$c", |
|
| 883 | - '=', |
|
| 884 | - "$t.$carr", |
|
| 885 | - ($and ? 'AND ' . $and : '') . |
|
| 886 | - ')' |
|
| 887 | - ]; |
|
| 888 | - if (isset($afrom[$cle])) { |
|
| 889 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | - unset($afrom[$cle]); |
|
| 891 | - } |
|
| 892 | - $equiv[] = $carr; |
|
| 893 | - } else { |
|
| 894 | - unset($join[$cledef]); |
|
| 895 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | - unset($where_simples[$cle_where_lie]); |
|
| 897 | - unset($where[$cle_where_lie]); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - unset($from[$cle]); |
|
| 901 | - $k--; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - if (count($afrom)) { |
|
| 905 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | - // ou dans |
|
| 910 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | - // qui comporte plusieurs jointures |
|
| 912 | - // ou dans |
|
| 913 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | - |
|
| 920 | - $t = key($from); |
|
| 921 | - $c = current($from); |
|
| 922 | - reset($from); |
|
| 923 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | - if ( |
|
| 925 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | - calculer_jointnul($t, $select, $e) or |
|
| 927 | - calculer_jointnul($t, $join, $e) or |
|
| 928 | - calculer_jointnul($t, $where, $e) or |
|
| 929 | - calculer_jointnul($t, $orderby, $e) or |
|
| 930 | - calculer_jointnul($t, $groupby, $e) or |
|
| 931 | - calculer_jointnul($t, $having, $e)) |
|
| 932 | - && count($afrom[$t]) |
|
| 933 | - ) { |
|
| 934 | - $nfrom = reset($afrom[$t]); |
|
| 935 | - $nt = array_key_first($afrom[$t]); |
|
| 936 | - unset($from[$t]); |
|
| 937 | - $from[$nt] = $nfrom[1]; |
|
| 938 | - unset($afrom[$t][$nt]); |
|
| 939 | - $afrom[$nt] = $afrom[$t]; |
|
| 940 | - unset($afrom[$t]); |
|
| 941 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | - $t = $nfrom[4]; |
|
| 943 | - $alias = ''; |
|
| 944 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | - $oldcle = explode('.', $nfrom[6]); |
|
| 946 | - $oldcle = end($oldcle); |
|
| 947 | - $newcle = explode('.', $nfrom[4]); |
|
| 948 | - $newcle = end($newcle); |
|
| 949 | - if ($newcle != $oldcle) { |
|
| 950 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | - // reprendre simplement ce AS |
|
| 952 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | - $alias = ''; |
|
| 955 | - } else { |
|
| 956 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | - } |
|
| 966 | - $from = reinjecte_joint($afrom, $from); |
|
| 967 | - } |
|
| 968 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | - $GLOBALS['debug'] = []; |
|
| 971 | - if ($wasdebug) { |
|
| 972 | - $GLOBALS['debug']['debug'] = true; |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | - $r = sql_select( |
|
| 977 | - $select, |
|
| 978 | - $from, |
|
| 979 | - $where, |
|
| 980 | - $groupby, |
|
| 981 | - array_filter($orderby), |
|
| 982 | - $limit, |
|
| 983 | - $having, |
|
| 984 | - $serveur, |
|
| 985 | - $requeter |
|
| 986 | - ); |
|
| 987 | - unset($GLOBALS['debug']['aucasou']); |
|
| 988 | - |
|
| 989 | - return $r; |
|
| 719 | + // retirer les criteres vides: |
|
| 720 | + // {X ?} avec X absent de l'URL |
|
| 721 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | + $menage = false; |
|
| 724 | + foreach ($where as $k => $v) { |
|
| 725 | + if (is_array($v) and count($v)) { |
|
| 726 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | + $op = false; |
|
| 728 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | + $op = false; |
|
| 730 | + } else { |
|
| 731 | + $op = $v[0] ?: $v; |
|
| 732 | + } |
|
| 733 | + } else { |
|
| 734 | + $op = $v; |
|
| 735 | + } |
|
| 736 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | + unset($where[$k]); |
|
| 738 | + $menage = true; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | + $groupby = array_diff($groupby, ['']); |
|
| 744 | + |
|
| 745 | + // remplacer les sous requetes recursives au calcul |
|
| 746 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | + foreach ($where_sous as $k => $w) { |
|
| 748 | + $menage = true; |
|
| 749 | + // on recupere la sous requete |
|
| 750 | + $sous = match_self($w); |
|
| 751 | + if ($sous[0] == 'SELF') { |
|
| 752 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | + array_push($where_simples, $sous[2]); |
|
| 754 | + $wheresub = [ |
|
| 755 | + $sous[2], |
|
| 756 | + '0=0' |
|
| 757 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | + $jsub = $join; |
|
| 759 | + // trouver les jointures utiles a |
|
| 760 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | + // ie L1.objet='article' |
|
| 762 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | + $i = 0; |
|
| 764 | + do { |
|
| 765 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | + [$sous[1] . ' AS id'], |
|
| 767 | + $from, |
|
| 768 | + $from_type, |
|
| 769 | + $wheresub, |
|
| 770 | + $jsub, |
|
| 771 | + [], |
|
| 772 | + [], |
|
| 773 | + '', |
|
| 774 | + $having, |
|
| 775 | + $table, |
|
| 776 | + $id, |
|
| 777 | + $serveur, |
|
| 778 | + false |
|
| 779 | + ) . ')'); |
|
| 780 | + if (!$i) { |
|
| 781 | + $i = 1; |
|
| 782 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | + foreach ($join as $cle => $wj) { |
|
| 784 | + if ( |
|
| 785 | + (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | + and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | + ) { |
|
| 788 | + $i = 0; |
|
| 789 | + $wheresub[] = $wj[3]; |
|
| 790 | + unset($jsub[$cle][3]); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } while ($i++ < 1); |
|
| 795 | + } |
|
| 796 | + if ($sous[0] == 'SUBSELECT') { |
|
| 797 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | + $sous[1], # select |
|
| 801 | + $sous[2], #from |
|
| 802 | + [], #from_type |
|
| 803 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | + [], #join |
|
| 806 | + $sous[4] ?: [], #groupby |
|
| 807 | + $sous[5] ?: [], #orderby |
|
| 808 | + $sous[6], #limit |
|
| 809 | + $sous[7] ?: [], #having |
|
| 810 | + $table, |
|
| 811 | + $id, |
|
| 812 | + $serveur, |
|
| 813 | + false |
|
| 814 | + ) . ')'); |
|
| 815 | + } |
|
| 816 | + array_pop($where_simples); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + foreach ($having as $k => $v) { |
|
| 820 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | + unset($having[$k]); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + // Installer les jointures. |
|
| 826 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | + |
|
| 830 | + $afrom = []; |
|
| 831 | + $equiv = []; |
|
| 832 | + $k = count($join); |
|
| 833 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | + $cle = $cledef; |
|
| 835 | + // le format de join est : |
|
| 836 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | + if (count($join[$cle]) == 2) { |
|
| 839 | + $join[$cle][] = $join[$cle][1]; |
|
| 840 | + } |
|
| 841 | + if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | + $join[$cle][] = ''; |
|
| 843 | + } |
|
| 844 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | + // pour compat avec ancienne convention |
|
| 847 | + if (is_numeric($cle)) { |
|
| 848 | + $cle = "L$k"; |
|
| 849 | + } |
|
| 850 | + $cle_where_lie = "JOIN-$cle"; |
|
| 851 | + if ( |
|
| 852 | + !$menage |
|
| 853 | + or isset($afrom[$cle]) |
|
| 854 | + or calculer_jointnul($cle, $select) |
|
| 855 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | + or calculer_jointnul($cle, $having) |
|
| 857 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | + ) { |
|
| 859 | + // corriger les references non explicites dans select |
|
| 860 | + // ou groupby |
|
| 861 | + foreach ($select as $i => $s) { |
|
| 862 | + if ($s == $c) { |
|
| 863 | + $select[$i] = "$cle.$c AS $c"; |
|
| 864 | + break; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + foreach ($groupby as $i => $g) { |
|
| 868 | + if ($g == $c) { |
|
| 869 | + $groupby[$i] = "$cle.$c"; |
|
| 870 | + break; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | + // sans recours a preg_match |
|
| 875 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | + $afrom[$t][$cle] = [ |
|
| 877 | + "\n" . |
|
| 878 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | + $from[$cle], |
|
| 880 | + "AS $cle", |
|
| 881 | + 'ON (', |
|
| 882 | + "$cle.$c", |
|
| 883 | + '=', |
|
| 884 | + "$t.$carr", |
|
| 885 | + ($and ? 'AND ' . $and : '') . |
|
| 886 | + ')' |
|
| 887 | + ]; |
|
| 888 | + if (isset($afrom[$cle])) { |
|
| 889 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | + unset($afrom[$cle]); |
|
| 891 | + } |
|
| 892 | + $equiv[] = $carr; |
|
| 893 | + } else { |
|
| 894 | + unset($join[$cledef]); |
|
| 895 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | + unset($where_simples[$cle_where_lie]); |
|
| 897 | + unset($where[$cle_where_lie]); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + unset($from[$cle]); |
|
| 901 | + $k--; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + if (count($afrom)) { |
|
| 905 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | + // ou dans |
|
| 910 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | + // qui comporte plusieurs jointures |
|
| 912 | + // ou dans |
|
| 913 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | + |
|
| 920 | + $t = key($from); |
|
| 921 | + $c = current($from); |
|
| 922 | + reset($from); |
|
| 923 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | + if ( |
|
| 925 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | + calculer_jointnul($t, $select, $e) or |
|
| 927 | + calculer_jointnul($t, $join, $e) or |
|
| 928 | + calculer_jointnul($t, $where, $e) or |
|
| 929 | + calculer_jointnul($t, $orderby, $e) or |
|
| 930 | + calculer_jointnul($t, $groupby, $e) or |
|
| 931 | + calculer_jointnul($t, $having, $e)) |
|
| 932 | + && count($afrom[$t]) |
|
| 933 | + ) { |
|
| 934 | + $nfrom = reset($afrom[$t]); |
|
| 935 | + $nt = array_key_first($afrom[$t]); |
|
| 936 | + unset($from[$t]); |
|
| 937 | + $from[$nt] = $nfrom[1]; |
|
| 938 | + unset($afrom[$t][$nt]); |
|
| 939 | + $afrom[$nt] = $afrom[$t]; |
|
| 940 | + unset($afrom[$t]); |
|
| 941 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | + $t = $nfrom[4]; |
|
| 943 | + $alias = ''; |
|
| 944 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | + $oldcle = explode('.', $nfrom[6]); |
|
| 946 | + $oldcle = end($oldcle); |
|
| 947 | + $newcle = explode('.', $nfrom[4]); |
|
| 948 | + $newcle = end($newcle); |
|
| 949 | + if ($newcle != $oldcle) { |
|
| 950 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | + // reprendre simplement ce AS |
|
| 952 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | + $alias = ''; |
|
| 955 | + } else { |
|
| 956 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | + } |
|
| 966 | + $from = reinjecte_joint($afrom, $from); |
|
| 967 | + } |
|
| 968 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | + $GLOBALS['debug'] = []; |
|
| 971 | + if ($wasdebug) { |
|
| 972 | + $GLOBALS['debug']['debug'] = true; |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | + $r = sql_select( |
|
| 977 | + $select, |
|
| 978 | + $from, |
|
| 979 | + $where, |
|
| 980 | + $groupby, |
|
| 981 | + array_filter($orderby), |
|
| 982 | + $limit, |
|
| 983 | + $having, |
|
| 984 | + $serveur, |
|
| 985 | + $requeter |
|
| 986 | + ); |
|
| 987 | + unset($GLOBALS['debug']['aucasou']); |
|
| 988 | + |
|
| 989 | + return $r; |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -997,79 +997,79 @@ discard block |
||
| 997 | 997 | * @return string |
| 998 | 998 | */ |
| 999 | 999 | function calculer_where_to_string($v, $join = 'AND') { |
| 1000 | - if (empty($v)) { |
|
| 1001 | - return ''; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - if (!is_array($v)) { |
|
| 1005 | - return $v; |
|
| 1006 | - } else { |
|
| 1007 | - $exp = ''; |
|
| 1008 | - if (strtoupper($join) === 'AND') { |
|
| 1009 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | - } else { |
|
| 1011 | - return $exp . join($join, $v); |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1000 | + if (empty($v)) { |
|
| 1001 | + return ''; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + if (!is_array($v)) { |
|
| 1005 | + return $v; |
|
| 1006 | + } else { |
|
| 1007 | + $exp = ''; |
|
| 1008 | + if (strtoupper($join) === 'AND') { |
|
| 1009 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | + } else { |
|
| 1011 | + return $exp . join($join, $v); |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1018 | 1018 | |
| 1019 | 1019 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1020 | - if (!is_array($exp)) { |
|
| 1021 | - if ($equiv) { |
|
| 1022 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | - } else { |
|
| 1027 | - foreach ($exp as $v) { |
|
| 1028 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | - return true; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - return false; |
|
| 1034 | - } |
|
| 1020 | + if (!is_array($exp)) { |
|
| 1021 | + if ($equiv) { |
|
| 1022 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | + } else { |
|
| 1027 | + foreach ($exp as $v) { |
|
| 1028 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | + return true; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | function reinjecte_joint($afrom, $from) { |
| 1038 | - $from_synth = []; |
|
| 1039 | - foreach ($from as $k => $v) { |
|
| 1040 | - $from_synth[$k] = $from[$k]; |
|
| 1041 | - if (isset($afrom[$k])) { |
|
| 1042 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | - } |
|
| 1045 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | - unset($afrom[$k]); |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - return $from_synth; |
|
| 1038 | + $from_synth = []; |
|
| 1039 | + foreach ($from as $k => $v) { |
|
| 1040 | + $from_synth[$k] = $from[$k]; |
|
| 1041 | + if (isset($afrom[$k])) { |
|
| 1042 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | + } |
|
| 1045 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | + unset($afrom[$k]); |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + return $from_synth; |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1054 | - if (!is_array($exp)) { |
|
| 1055 | - return preg_replace($equiv, $cle, $exp); |
|
| 1056 | - } else { |
|
| 1057 | - foreach ($exp as $k => $v) { |
|
| 1058 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - return $exp; |
|
| 1062 | - } |
|
| 1054 | + if (!is_array($exp)) { |
|
| 1055 | + return preg_replace($equiv, $cle, $exp); |
|
| 1056 | + } else { |
|
| 1057 | + foreach ($exp as $k => $v) { |
|
| 1058 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + return $exp; |
|
| 1062 | + } |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // calcul du nom du squelette |
| 1066 | 1066 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1067 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return $mime_type |
|
| 1073 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1067 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return $mime_type |
|
| 1073 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1075 | 1075 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,193 +29,193 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = []; |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ''; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = 'prive/squelettes/'; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ''; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | - _DIR_PLUGIN_DIST, |
|
| 58 | - '/' |
|
| 59 | - ) : '')); |
|
| 60 | - } |
|
| 61 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | - } |
|
| 63 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | - |
|
| 65 | - $fond = $flux['args']['fond']; |
|
| 66 | - |
|
| 67 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | - $fond = substr($fond, $prefix_length); |
|
| 69 | - $squelette = $flux['data']; |
|
| 70 | - $ext = $flux['args']['ext']; |
|
| 71 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | - if ( |
|
| 73 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | - and $dir = explode('/', $fond) |
|
| 75 | - and count($dir) == 2 // pas un sous repertoire |
|
| 76 | - and $dir = reset($dir) |
|
| 77 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | - and defined($apl_constant) |
|
| 79 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | - ) { |
|
| 82 | - $flux['data'] = $pipe; |
|
| 83 | - |
|
| 84 | - return $flux; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | - $squelette = ''; |
|
| 90 | - $echafauder = ''; |
|
| 91 | - } |
|
| 92 | - if ($prepend) { |
|
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | - if ($squelette) { |
|
| 95 | - $flux['data'] = $squelette; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // gerer les squelettes non trouves |
|
| 100 | - // -> router vers les /dist.html |
|
| 101 | - // ou scaffolding ou page automatique les contenus |
|
| 102 | - if (!$squelette) { |
|
| 103 | - // si on est sur un ?page=XX non trouve |
|
| 104 | - if ( |
|
| 105 | - (isset($flux['args']['contexte'][$page]) |
|
| 106 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | - or ($fond == 'sommaire' |
|
| 110 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | - ) { |
|
| 112 | - // si on est sur un ?page=XX non trouve |
|
| 113 | - // se brancher sur contenu/xx si il existe |
|
| 114 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | - if (!isset($disponible[$fond])) { |
|
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($disponible[$fond]) { |
|
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // echafaudage : |
|
| 125 | - // si c'est un fond de contenu d'un objet en base |
|
| 126 | - // generer un fond automatique a la volee pour les webmestres |
|
| 127 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | - $type = $flux['args']['contexte'][$page]; |
|
| 131 | - } |
|
| 132 | - if (!isset($disponible[$type])) { |
|
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | - } |
|
| 135 | - if (is_string($disponible[$type])) { |
|
| 136 | - $flux['data'] = $disponible[$type]; |
|
| 137 | - } elseif ( |
|
| 138 | - $echafauder |
|
| 139 | - and include_spip('inc/autoriser') |
|
| 140 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | - and autoriser('echafauder', $type) |
|
| 142 | - and $is = $disponible[$type] |
|
| 143 | - and is_array($is) |
|
| 144 | - ) { |
|
| 145 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | - } else { |
|
| 147 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | - $prefix_path . $prepend, |
|
| 149 | - $z_contenu, |
|
| 150 | - '404', |
|
| 151 | - $ext, |
|
| 152 | - $echafauder |
|
| 153 | - )); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | - else { |
|
| 161 | - if ( |
|
| 162 | - $dir = explode('/', $fond) |
|
| 163 | - and $dir = reset($dir) |
|
| 164 | - and $dir !== $z_contenu |
|
| 165 | - and in_array($dir, $z_blocs) |
|
| 166 | - ) { |
|
| 167 | - $type = substr($fond, strlen("$dir/")); |
|
| 168 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | - $type = $flux['args']['contexte'][$page]; |
|
| 170 | - } |
|
| 171 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | - } |
|
| 174 | - if ($type == 'page' or $disponible[$type]) { |
|
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $squelette = $flux['data']; |
|
| 180 | - } |
|
| 181 | - // layout specifiques par type et compositions : |
|
| 182 | - // body-article.html |
|
| 183 | - // body-sommaire.html |
|
| 184 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | - // meme dossier que body.html |
|
| 186 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | - if ( |
|
| 188 | - isset($flux['args']['contexte']['type-page']) |
|
| 189 | - and ( |
|
| 190 | - (isset($flux['args']['contexte']['composition']) |
|
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | - or |
|
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - $flux['data'] = $f; |
|
| 197 | - } |
|
| 198 | - } elseif ( |
|
| 199 | - $fond == 'structure' |
|
| 200 | - and z_sanitize_var_zajax() |
|
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | - ) { |
|
| 203 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | - } // chercher le fond correspondant a la composition |
|
| 205 | - elseif ( |
|
| 206 | - isset($flux['args']['contexte']['composition']) |
|
| 207 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | - and $dir = substr($fond, $prefix_length) |
|
| 209 | - and $dir = explode('/', $dir) |
|
| 210 | - and $dir = reset($dir) |
|
| 211 | - and in_array($dir, $z_blocs) |
|
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | - ) { |
|
| 214 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = []; |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ''; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = 'prive/squelettes/'; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ''; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | + _DIR_PLUGIN_DIST, |
|
| 58 | + '/' |
|
| 59 | + ) : '')); |
|
| 60 | + } |
|
| 61 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | + } |
|
| 63 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | + |
|
| 65 | + $fond = $flux['args']['fond']; |
|
| 66 | + |
|
| 67 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | + $fond = substr($fond, $prefix_length); |
|
| 69 | + $squelette = $flux['data']; |
|
| 70 | + $ext = $flux['args']['ext']; |
|
| 71 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | + if ( |
|
| 73 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | + and $dir = explode('/', $fond) |
|
| 75 | + and count($dir) == 2 // pas un sous repertoire |
|
| 76 | + and $dir = reset($dir) |
|
| 77 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | + and defined($apl_constant) |
|
| 79 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | + ) { |
|
| 82 | + $flux['data'] = $pipe; |
|
| 83 | + |
|
| 84 | + return $flux; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | + $squelette = ''; |
|
| 90 | + $echafauder = ''; |
|
| 91 | + } |
|
| 92 | + if ($prepend) { |
|
| 93 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | + if ($squelette) { |
|
| 95 | + $flux['data'] = $squelette; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // gerer les squelettes non trouves |
|
| 100 | + // -> router vers les /dist.html |
|
| 101 | + // ou scaffolding ou page automatique les contenus |
|
| 102 | + if (!$squelette) { |
|
| 103 | + // si on est sur un ?page=XX non trouve |
|
| 104 | + if ( |
|
| 105 | + (isset($flux['args']['contexte'][$page]) |
|
| 106 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | + or ($fond == 'sommaire' |
|
| 110 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | + ) { |
|
| 112 | + // si on est sur un ?page=XX non trouve |
|
| 113 | + // se brancher sur contenu/xx si il existe |
|
| 114 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | + if (!isset($disponible[$fond])) { |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($disponible[$fond]) { |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // echafaudage : |
|
| 125 | + // si c'est un fond de contenu d'un objet en base |
|
| 126 | + // generer un fond automatique a la volee pour les webmestres |
|
| 127 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | + $type = $flux['args']['contexte'][$page]; |
|
| 131 | + } |
|
| 132 | + if (!isset($disponible[$type])) { |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | + } |
|
| 135 | + if (is_string($disponible[$type])) { |
|
| 136 | + $flux['data'] = $disponible[$type]; |
|
| 137 | + } elseif ( |
|
| 138 | + $echafauder |
|
| 139 | + and include_spip('inc/autoriser') |
|
| 140 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | + and autoriser('echafauder', $type) |
|
| 142 | + and $is = $disponible[$type] |
|
| 143 | + and is_array($is) |
|
| 144 | + ) { |
|
| 145 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | + } else { |
|
| 147 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | + $prefix_path . $prepend, |
|
| 149 | + $z_contenu, |
|
| 150 | + '404', |
|
| 151 | + $ext, |
|
| 152 | + $echafauder |
|
| 153 | + )); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | + else { |
|
| 161 | + if ( |
|
| 162 | + $dir = explode('/', $fond) |
|
| 163 | + and $dir = reset($dir) |
|
| 164 | + and $dir !== $z_contenu |
|
| 165 | + and in_array($dir, $z_blocs) |
|
| 166 | + ) { |
|
| 167 | + $type = substr($fond, strlen("$dir/")); |
|
| 168 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | + $type = $flux['args']['contexte'][$page]; |
|
| 170 | + } |
|
| 171 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | + } |
|
| 174 | + if ($type == 'page' or $disponible[$type]) { |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $squelette = $flux['data']; |
|
| 180 | + } |
|
| 181 | + // layout specifiques par type et compositions : |
|
| 182 | + // body-article.html |
|
| 183 | + // body-sommaire.html |
|
| 184 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | + // meme dossier que body.html |
|
| 186 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | + if ( |
|
| 188 | + isset($flux['args']['contexte']['type-page']) |
|
| 189 | + and ( |
|
| 190 | + (isset($flux['args']['contexte']['composition']) |
|
| 191 | + and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | + or |
|
| 193 | + file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + $flux['data'] = $f; |
|
| 197 | + } |
|
| 198 | + } elseif ( |
|
| 199 | + $fond == 'structure' |
|
| 200 | + and z_sanitize_var_zajax() |
|
| 201 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | + ) { |
|
| 203 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | + } // chercher le fond correspondant a la composition |
|
| 205 | + elseif ( |
|
| 206 | + isset($flux['args']['contexte']['composition']) |
|
| 207 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | + and $dir = substr($fond, $prefix_length) |
|
| 209 | + and $dir = explode('/', $dir) |
|
| 210 | + and $dir = reset($dir) |
|
| 211 | + and in_array($dir, $z_blocs) |
|
| 212 | + and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | + ) { |
|
| 214 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return $flux; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | * @return array |
| 226 | 226 | */ |
| 227 | 227 | function z_blocs($espace_prive = false) { |
| 228 | - if ($espace_prive) { |
|
| 229 | - return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | - 'contenu', |
|
| 231 | - 'navigation', |
|
| 232 | - 'extra', |
|
| 233 | - 'head', |
|
| 234 | - 'hierarchie', |
|
| 235 | - 'top' |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 228 | + if ($espace_prive) { |
|
| 229 | + return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | + 'contenu', |
|
| 231 | + 'navigation', |
|
| 232 | + 'extra', |
|
| 233 | + 'head', |
|
| 234 | + 'hierarchie', |
|
| 235 | + 'top' |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | 253 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 254 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | - return $d; |
|
| 256 | - } |
|
| 254 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | + return $d; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 258 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * `true` si on peut l'utiliser, `false` sinon. |
| 270 | 270 | **/ |
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | - if ( |
|
| 273 | - !_ZCORE_EXCLURE_PATH |
|
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | - ) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return false; |
|
| 272 | + if ( |
|
| 273 | + !_ZCORE_EXCLURE_PATH |
|
| 274 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | + ) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return false; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 297 | - if ( |
|
| 298 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | - ) { |
|
| 301 | - return substr($f, 0, -strlen(".$ext")); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 297 | + if ( |
|
| 298 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | + ) { |
|
| 301 | + return substr($f, 0, -strlen(".$ext")); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,52 +313,52 @@ discard block |
||
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | 315 | function z_echafaudable($type) { |
| 316 | - static $pages = null; |
|
| 317 | - static $echafaudable = []; |
|
| 318 | - if (isset($echafaudable[$type])) { |
|
| 319 | - return $echafaudable[$type]; |
|
| 320 | - } |
|
| 321 | - if (preg_match(',[^\w],', $type)) { |
|
| 322 | - return $echafaudable[$type] = false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if (test_espace_prive()) { |
|
| 326 | - if (!function_exists('trouver_objet_exec')) { |
|
| 327 | - include_spip('inc/pipelines_ecrire'); |
|
| 328 | - } |
|
| 329 | - if ($e = trouver_objet_exec($type)) { |
|
| 330 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | - } else { |
|
| 332 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | - if ( |
|
| 334 | - ($t = objet_type($type, false)) !== $type |
|
| 335 | - and $e = trouver_objet_exec($t) |
|
| 336 | - ) { |
|
| 337 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if (is_null($pages)) { |
|
| 342 | - $pages = []; |
|
| 343 | - $liste = lister_tables_objets_sql(); |
|
| 344 | - foreach ($liste as $t => $d) { |
|
| 345 | - if ($d['page']) { |
|
| 346 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - if (!isset($pages[$type])) { |
|
| 351 | - return $echafaudable[$type] = false; |
|
| 352 | - } |
|
| 353 | - if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $echafaudable[$type] = $pages[$type]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $echafaudable[$type] = false; |
|
| 316 | + static $pages = null; |
|
| 317 | + static $echafaudable = []; |
|
| 318 | + if (isset($echafaudable[$type])) { |
|
| 319 | + return $echafaudable[$type]; |
|
| 320 | + } |
|
| 321 | + if (preg_match(',[^\w],', $type)) { |
|
| 322 | + return $echafaudable[$type] = false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if (test_espace_prive()) { |
|
| 326 | + if (!function_exists('trouver_objet_exec')) { |
|
| 327 | + include_spip('inc/pipelines_ecrire'); |
|
| 328 | + } |
|
| 329 | + if ($e = trouver_objet_exec($type)) { |
|
| 330 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | + } else { |
|
| 332 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | + if ( |
|
| 334 | + ($t = objet_type($type, false)) !== $type |
|
| 335 | + and $e = trouver_objet_exec($t) |
|
| 336 | + ) { |
|
| 337 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if (is_null($pages)) { |
|
| 342 | + $pages = []; |
|
| 343 | + $liste = lister_tables_objets_sql(); |
|
| 344 | + foreach ($liste as $t => $d) { |
|
| 345 | + if ($d['page']) { |
|
| 346 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + if (!isset($pages[$type])) { |
|
| 351 | + return $echafaudable[$type] = false; |
|
| 352 | + } |
|
| 353 | + if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $echafaudable[$type] = $pages[$type]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $echafaudable[$type] = false; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -375,46 +375,46 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | 377 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 378 | - $scaffold = ''; |
|
| 379 | - |
|
| 380 | - // page objet ou objet_edit |
|
| 381 | - if (is_array($desc_exec)) { |
|
| 382 | - $type = $desc_exec['type']; |
|
| 383 | - $primary = $desc_exec['id_table_objet']; |
|
| 384 | - |
|
| 385 | - if ($desc_exec['edition'] === false) { |
|
| 386 | - $fond = 'objet'; |
|
| 387 | - } else { |
|
| 388 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | - $desc = $trouver_table($table_sql); |
|
| 390 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | - $fond = 'objet_edit'; |
|
| 392 | - } else { |
|
| 393 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $dir = z_blocs(test_espace_prive()); |
|
| 397 | - $dir = reset($dir); |
|
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | - } // page objets |
|
| 400 | - elseif ($type = $desc_exec and !str_contains($type, '/')) { |
|
| 401 | - $dir = z_blocs(test_espace_prive()); |
|
| 402 | - $dir = reset($dir); |
|
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | - } |
|
| 405 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | - // et objet et tire de $table |
|
| 407 | - elseif ($fond = $desc_exec) { |
|
| 408 | - $dir = md5(dirname($fond)); |
|
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | - $f = $base_dir . "$exec"; |
|
| 415 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | - |
|
| 417 | - return $f; |
|
| 378 | + $scaffold = ''; |
|
| 379 | + |
|
| 380 | + // page objet ou objet_edit |
|
| 381 | + if (is_array($desc_exec)) { |
|
| 382 | + $type = $desc_exec['type']; |
|
| 383 | + $primary = $desc_exec['id_table_objet']; |
|
| 384 | + |
|
| 385 | + if ($desc_exec['edition'] === false) { |
|
| 386 | + $fond = 'objet'; |
|
| 387 | + } else { |
|
| 388 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | + $desc = $trouver_table($table_sql); |
|
| 390 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | + $fond = 'objet_edit'; |
|
| 392 | + } else { |
|
| 393 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + $dir = z_blocs(test_espace_prive()); |
|
| 397 | + $dir = reset($dir); |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | + } // page objets |
|
| 400 | + elseif ($type = $desc_exec and !str_contains($type, '/')) { |
|
| 401 | + $dir = z_blocs(test_espace_prive()); |
|
| 402 | + $dir = reset($dir); |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | + } |
|
| 405 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | + // et objet et tire de $table |
|
| 407 | + elseif ($fond = $desc_exec) { |
|
| 408 | + $dir = md5(dirname($fond)); |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | + $f = $base_dir . "$exec"; |
|
| 415 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | + |
|
| 417 | + return $f; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return bool|string |
| 424 | 424 | */ |
| 425 | 425 | function z_sanitize_var_zajax() { |
| 426 | - $z_ajax = _request('var_zajax'); |
|
| 427 | - if (!$z_ajax) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if ( |
|
| 431 | - !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | - or !in_array($z_ajax, $z_blocs) |
|
| 433 | - ) { |
|
| 434 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | - $z_ajax = false; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $z_ajax; |
|
| 426 | + $z_ajax = _request('var_zajax'); |
|
| 427 | + if (!$z_ajax) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if ( |
|
| 431 | + !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | + or !in_array($z_ajax, $z_blocs) |
|
| 433 | + ) { |
|
| 434 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | + $z_ajax = false; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $z_ajax; |
|
| 439 | 439 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,42 +59,42 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | - if (strpbrk($f, ':')) { // Class::method |
|
| 72 | - $refl = new ReflectionMethod($f); |
|
| 73 | - } else { |
|
| 74 | - $refl = new ReflectionFunction($f); |
|
| 75 | - } |
|
| 76 | - $refs = $refl->getParameters(); |
|
| 77 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | - } else { |
|
| 81 | - $code = "$f($code$arglist)"; |
|
| 82 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | - } |
|
| 84 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | - if (($nb_args_f < $min_f)) { |
|
| 87 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - // le filtre n'existe pas, |
|
| 92 | - // on le notifie |
|
| 93 | - else { |
|
| 94 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | + if (strpbrk($f, ':')) { // Class::method |
|
| 72 | + $refl = new ReflectionMethod($f); |
|
| 73 | + } else { |
|
| 74 | + $refl = new ReflectionFunction($f); |
|
| 75 | + } |
|
| 76 | + $refs = $refl->getParameters(); |
|
| 77 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | + } else { |
|
| 81 | + $code = "$f($code$arglist)"; |
|
| 82 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | + } |
|
| 84 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | + if (($nb_args_f < $min_f)) { |
|
| 87 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + // le filtre n'existe pas, |
|
| 92 | + // on le notifie |
|
| 93 | + else { |
|
| 94 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $code; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Calculer un <INCLURE(xx.php)> |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | 119 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 120 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | - // si inexistant, on essaiera a l'execution |
|
| 122 | - if ($path = find_in_path($fichier)) { |
|
| 123 | - $path = "\"$path\""; |
|
| 124 | - } else { |
|
| 125 | - $path = "find_in_path(\"$fichier\")"; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 120 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | + // si inexistant, on essaiera a l'execution |
|
| 122 | + if ($path = find_in_path($fichier)) { |
|
| 123 | + $path = "\"$path\""; |
|
| 124 | + } else { |
|
| 125 | + $path = "find_in_path(\"$fichier\")"; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 140 | - // Securite |
|
| 141 | - if ( |
|
| 142 | - $p->interdire_scripts |
|
| 143 | - and $p->etoile != '**' |
|
| 144 | - ) { |
|
| 145 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | - $code = "interdire_scripts($code)"; |
|
| 147 | - } else { |
|
| 148 | - $code = interdire_scripts($r[2]); |
|
| 149 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $code; |
|
| 140 | + // Securite |
|
| 141 | + if ( |
|
| 142 | + $p->interdire_scripts |
|
| 143 | + and $p->etoile != '**' |
|
| 144 | + ) { |
|
| 145 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | + $code = "interdire_scripts($code)"; |
|
| 147 | + } else { |
|
| 148 | + $code = interdire_scripts($r[2]); |
|
| 149 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $code; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,30 +169,30 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | - $series_filtres = func_get_args(); |
|
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 175 | - |
|
| 176 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | - if ($skel['process_ins'] == 'php') { |
|
| 178 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer les couples de remplacement |
|
| 182 | - $replace = echapper_php_callback(); |
|
| 183 | - |
|
| 184 | - foreach ($series_filtres as $filtres) { |
|
| 185 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | - foreach ($filtres as $filtre) { |
|
| 187 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | - $corps = $f($corps); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // restaurer les echappements |
|
| 195 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 172 | + $series_filtres = func_get_args(); |
|
| 173 | + array_shift($series_filtres);// skel |
|
| 174 | + array_shift($series_filtres);// corps |
|
| 175 | + |
|
| 176 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | + if ($skel['process_ins'] == 'php') { |
|
| 178 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer les couples de remplacement |
|
| 182 | + $replace = echapper_php_callback(); |
|
| 183 | + |
|
| 184 | + foreach ($series_filtres as $filtres) { |
|
| 185 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | + foreach ($filtres as $filtre) { |
|
| 187 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | + $corps = $f($corps); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // restaurer les echappements |
|
| 195 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 212 | 212 | **/ |
| 213 | 213 | function echapper_php_callback($r = null) { |
| 214 | - static $src = []; |
|
| 215 | - static $dst = []; |
|
| 214 | + static $src = []; |
|
| 215 | + static $dst = []; |
|
| 216 | 216 | |
| 217 | - // si on recoit un tableau, on est en mode echappement |
|
| 218 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | - if (is_array($r)) { |
|
| 220 | - $dst[] = $r[0]; |
|
| 217 | + // si on recoit un tableau, on est en mode echappement |
|
| 218 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | + if (is_array($r)) { |
|
| 220 | + $dst[] = $r[0]; |
|
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | - } |
|
| 222 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | - // et on RAZ les remplacements |
|
| 227 | - $r = [$src, $dst]; |
|
| 228 | - $src = $dst = []; |
|
| 225 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | + // et on RAZ les remplacements |
|
| 227 | + $r = [$src, $dst]; |
|
| 228 | + $src = $dst = []; |
|
| 229 | 229 | |
| 230 | - return $r; |
|
| 230 | + return $r; |
|
| 231 | 231 | } |
@@ -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 | /** |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 43 | - verifier_htaccess(_DIR_VENDOR); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | + verifier_htaccess(_DIR_VENDOR); |
|
| 44 | 44 | |
| 45 | - // Verifier qu'aucune table n'est crashee |
|
| 46 | - if (!_request('reinstall')) { |
|
| 47 | - verifier_crash_tables(); |
|
| 48 | - } |
|
| 45 | + // Verifier qu'aucune table n'est crashee |
|
| 46 | + if (!_request('reinstall')) { |
|
| 47 | + verifier_crash_tables(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return 1; |
|
| 50 | + return 1; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -64,33 +64,33 @@ discard block |
||
| 64 | 64 | * des tables qui ont crashé. |
| 65 | 65 | */ |
| 66 | 66 | function verifier_crash_tables() { |
| 67 | - if (spip_connect()) { |
|
| 68 | - include_spip('base/serial'); |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - $crash = []; |
|
| 71 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | - if ( |
|
| 74 | - !sql_select('*', $table, '', '', '', 1) |
|
| 75 | - and !defined('spip_interdire_cache') |
|
| 76 | - ) { # cas "LOST CONNECTION" |
|
| 77 | - $crash[] = $table; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - #$crash[] = 'test'; |
|
| 82 | - if ($crash) { |
|
| 83 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | - spip_log('crash des tables', 'err'); |
|
| 85 | - spip_log($crash, 'err'); |
|
| 86 | - } else { |
|
| 87 | - effacer_meta('message_crash_tables'); |
|
| 88 | - } |
|
| 67 | + if (spip_connect()) { |
|
| 68 | + include_spip('base/serial'); |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + $crash = []; |
|
| 71 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | + if ( |
|
| 74 | + !sql_select('*', $table, '', '', '', 1) |
|
| 75 | + and !defined('spip_interdire_cache') |
|
| 76 | + ) { # cas "LOST CONNECTION" |
|
| 77 | + $crash[] = $table; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + #$crash[] = 'test'; |
|
| 82 | + if ($crash) { |
|
| 83 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | + spip_log('crash des tables', 'err'); |
|
| 85 | + spip_log($crash, 'err'); |
|
| 86 | + } else { |
|
| 87 | + effacer_meta('message_crash_tables'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return $crash; |
|
| 91 | - } |
|
| 90 | + return $crash; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return false; |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function message_crash_tables() { |
| 109 | - if ($crash = verifier_crash_tables()) { |
|
| 110 | - return |
|
| 111 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | - . generer_form_ecrire( |
|
| 114 | - 'base_repair', |
|
| 115 | - _T('texte_crash_base'), |
|
| 116 | - '', |
|
| 117 | - _T('bouton_tenter_recuperation') |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - return ''; |
|
| 109 | + if ($crash = verifier_crash_tables()) { |
|
| 110 | + return |
|
| 111 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | + . generer_form_ecrire( |
|
| 114 | + 'base_repair', |
|
| 115 | + _T('texte_crash_base'), |
|
| 116 | + '', |
|
| 117 | + _T('bouton_tenter_recuperation') |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + return ''; |
|
| 121 | 121 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 26 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * Description de la boucle complétée des champs |
| 45 | 45 | */ |
| 46 | 46 | function iterateur_DATA_dist($b) { |
| 47 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | - $b->show = [ |
|
| 49 | - 'field' => [ |
|
| 50 | - 'cle' => 'STRING', |
|
| 51 | - 'valeur' => 'STRING', |
|
| 52 | - '*' => 'ALL' // Champ joker * |
|
| 53 | - ] |
|
| 54 | - ]; |
|
| 55 | - $b->select[] = '.valeur'; |
|
| 56 | - |
|
| 57 | - return $b; |
|
| 47 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | + $b->show = [ |
|
| 49 | + 'field' => [ |
|
| 50 | + 'cle' => 'STRING', |
|
| 51 | + 'valeur' => 'STRING', |
|
| 52 | + '*' => 'ALL' // Champ joker * |
|
| 53 | + ] |
|
| 54 | + ]; |
|
| 55 | + $b->select[] = '.valeur'; |
|
| 56 | + |
|
| 57 | + return $b; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function inc_file_to_array_dist($data) { |
| 72 | - return preg_split('/\r?\n/', $data); |
|
| 72 | + return preg_split('/\r?\n/', $data); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | function inc_plugins_to_array_dist() { |
| 81 | - include_spip('inc/plugin'); |
|
| 81 | + include_spip('inc/plugin'); |
|
| 82 | 82 | |
| 83 | - return liste_chemin_plugin_actifs(); |
|
| 83 | + return liste_chemin_plugin_actifs(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | 92 | function inc_xml_to_array_dist($data) { |
| 93 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | */ |
| 104 | 104 | function inc_object_to_array($object) { |
| 105 | - if (!is_object($object) && !is_array($object)) { |
|
| 106 | - return $object; |
|
| 107 | - } |
|
| 108 | - if (is_object($object)) { |
|
| 109 | - $object = get_object_vars($object); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return array_map('inc_object_to_array', $object); |
|
| 105 | + if (!is_object($object) && !is_array($object)) { |
|
| 106 | + return $object; |
|
| 107 | + } |
|
| 108 | + if (is_object($object)) { |
|
| 109 | + $object = get_object_vars($object); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return array_map('inc_object_to_array', $object); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,20 +119,20 @@ discard block |
||
| 119 | 119 | * @return array|bool |
| 120 | 120 | */ |
| 121 | 121 | function inc_sql_to_array_dist($data) { |
| 122 | - # sortir le connecteur de $data |
|
| 123 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | - $serveur = (string)$v[1]; |
|
| 125 | - $req = trim($v[2]); |
|
| 126 | - if ($s = sql_query($req, $serveur)) { |
|
| 127 | - $r = []; |
|
| 128 | - while ($t = sql_fetch($s)) { |
|
| 129 | - $r[] = $t; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $r; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return false; |
|
| 122 | + # sortir le connecteur de $data |
|
| 123 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | + $serveur = (string)$v[1]; |
|
| 125 | + $req = trim($v[2]); |
|
| 126 | + if ($s = sql_query($req, $serveur)) { |
|
| 127 | + $r = []; |
|
| 128 | + while ($t = sql_fetch($s)) { |
|
| 129 | + $r[] = $t; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $r; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | * @return array|bool |
| 143 | 143 | */ |
| 144 | 144 | function inc_json_to_array_dist($data) { |
| 145 | - try { |
|
| 146 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | - } catch (JsonException $e) { |
|
| 148 | - $json = null; |
|
| 149 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | - } |
|
| 151 | - return is_array($json) ? (array) $json : []; |
|
| 145 | + try { |
|
| 146 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | + } catch (JsonException $e) { |
|
| 148 | + $json = null; |
|
| 149 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | + } |
|
| 151 | + return is_array($json) ? (array) $json : []; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return array|bool |
| 159 | 159 | */ |
| 160 | 160 | function inc_csv_to_array_dist($data) { |
| 161 | - include_spip('inc/csv'); |
|
| 162 | - [$entete, $csv] = analyse_csv($data); |
|
| 163 | - array_unshift($csv, $entete); |
|
| 164 | - |
|
| 165 | - include_spip('inc/charsets'); |
|
| 166 | - $i = 1; |
|
| 167 | - foreach ($entete as $k => $v) { |
|
| 168 | - if (trim($v) == '') { |
|
| 169 | - $v = 'col' . $i; |
|
| 170 | - } // reperer des eventuelles cases vides |
|
| 171 | - if (is_numeric($v) and $v < 0) { |
|
| 172 | - $v = '__' . $v; |
|
| 173 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | - if (is_numeric($v)) { |
|
| 175 | - $v = '_' . $v; |
|
| 176 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | - foreach ($csv as &$item) { |
|
| 179 | - $item[$v] = &$item[$k]; |
|
| 180 | - } |
|
| 181 | - $i++; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $csv; |
|
| 161 | + include_spip('inc/csv'); |
|
| 162 | + [$entete, $csv] = analyse_csv($data); |
|
| 163 | + array_unshift($csv, $entete); |
|
| 164 | + |
|
| 165 | + include_spip('inc/charsets'); |
|
| 166 | + $i = 1; |
|
| 167 | + foreach ($entete as $k => $v) { |
|
| 168 | + if (trim($v) == '') { |
|
| 169 | + $v = 'col' . $i; |
|
| 170 | + } // reperer des eventuelles cases vides |
|
| 171 | + if (is_numeric($v) and $v < 0) { |
|
| 172 | + $v = '__' . $v; |
|
| 173 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | + if (is_numeric($v)) { |
|
| 175 | + $v = '_' . $v; |
|
| 176 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | + foreach ($csv as &$item) { |
|
| 179 | + $item[$v] = &$item[$k]; |
|
| 180 | + } |
|
| 181 | + $i++; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $csv; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return array|bool |
| 192 | 192 | */ |
| 193 | 193 | function inc_rss_to_array_dist($data) { |
| 194 | - $tableau = null; |
|
| 195 | - include_spip('inc/syndic'); |
|
| 196 | - if (is_array($rss = analyser_backend($data))) { |
|
| 197 | - $tableau = $rss; |
|
| 198 | - } |
|
| 194 | + $tableau = null; |
|
| 195 | + include_spip('inc/syndic'); |
|
| 196 | + if (is_array($rss = analyser_backend($data))) { |
|
| 197 | + $tableau = $rss; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - return $tableau; |
|
| 200 | + return $tableau; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | * @return array|bool |
| 208 | 208 | */ |
| 209 | 209 | function inc_atom_to_array_dist($data) { |
| 210 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 211 | 211 | |
| 212 | - return $rss_to_array($data); |
|
| 212 | + return $rss_to_array($data); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | * @return array|bool |
| 221 | 221 | */ |
| 222 | 222 | function inc_glob_to_array_dist($data) { |
| 223 | - $a = glob( |
|
| 224 | - $data, |
|
| 225 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | - ); |
|
| 223 | + $a = glob( |
|
| 224 | + $data, |
|
| 225 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - return $a ?: []; |
|
| 228 | + return $a ?: []; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * @throws Exception |
| 237 | 237 | */ |
| 238 | 238 | function inc_yaml_to_array_dist($data) { |
| 239 | - include_spip('inc/yaml-mini'); |
|
| 240 | - if (!function_exists('yaml_decode')) { |
|
| 241 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 239 | + include_spip('inc/yaml-mini'); |
|
| 240 | + if (!function_exists('yaml_decode')) { |
|
| 241 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 242 | 242 | |
| 243 | - return false; |
|
| 244 | - } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return yaml_decode($data); |
|
| 246 | + return yaml_decode($data); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return array|bool |
| 259 | 259 | */ |
| 260 | 260 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 261 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | * @return array|bool |
| 271 | 271 | */ |
| 272 | 272 | function inc_ls_to_array_dist($data) { |
| 273 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | - $a = $glob_to_array($data); |
|
| 275 | - foreach ($a as &$v) { |
|
| 276 | - $b = (array)@stat($v); |
|
| 277 | - foreach ($b as $k => $ignore) { |
|
| 278 | - if (is_numeric($k)) { |
|
| 279 | - unset($b[$k]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | - $v = array_merge( |
|
| 284 | - pathinfo($v), |
|
| 285 | - $b |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $a; |
|
| 273 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | + $a = $glob_to_array($data); |
|
| 275 | + foreach ($a as &$v) { |
|
| 276 | + $b = (array)@stat($v); |
|
| 277 | + foreach ($b as $k => $ignore) { |
|
| 278 | + if (is_numeric($k)) { |
|
| 279 | + unset($b[$k]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | + $v = array_merge( |
|
| 284 | + pathinfo($v), |
|
| 285 | + $b |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $a; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,25 +296,25 @@ discard block |
||
| 296 | 296 | * @return array|bool |
| 297 | 297 | */ |
| 298 | 298 | function XMLObjectToArray($object) { |
| 299 | - $xml_array = []; |
|
| 300 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | - $key .= '-' . uniqid(); |
|
| 303 | - } |
|
| 304 | - $vars = get_object_vars($object->current()); |
|
| 305 | - if (isset($vars['@attributes'])) { |
|
| 306 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | - $xml_array[$key][$k] = $v; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if ($object->hasChildren()) { |
|
| 311 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | - $object->current() |
|
| 313 | - ); |
|
| 314 | - } else { |
|
| 315 | - $xml_array[$key][] = strval($object->current()); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $xml_array; |
|
| 299 | + $xml_array = []; |
|
| 300 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | + $key .= '-' . uniqid(); |
|
| 303 | + } |
|
| 304 | + $vars = get_object_vars($object->current()); |
|
| 305 | + if (isset($vars['@attributes'])) { |
|
| 306 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | + $xml_array[$key][$k] = $v; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if ($object->hasChildren()) { |
|
| 311 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | + $object->current() |
|
| 313 | + ); |
|
| 314 | + } else { |
|
| 315 | + $xml_array[$key][] = strval($object->current()); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $xml_array; |
|
| 320 | 320 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('iterateur/data'); |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | * Description de la boucle complétée des champs |
| 38 | 38 | */ |
| 39 | 39 | function iterateur_CONDITION_dist($b) { |
| 40 | - $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | - $b->show = [ |
|
| 42 | - 'field' => [] |
|
| 43 | - ]; |
|
| 40 | + $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | + $b->show = [ |
|
| 42 | + 'field' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - return $b; |
|
| 45 | + return $b; |
|
| 46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_POUR_dist($b) { |
| 41 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 41 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - return $b; |
|
| 49 | + return $b; |
|
| 50 | 50 | } |