@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,96 +237,96 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // il y a un alias connu pour ce champ |
|
| 259 | - if ($excep) { |
|
| 260 | - $joker = false; // indiquer a l'appelant |
|
| 261 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // le champ existe dans la table, on le prend. |
|
| 265 | - if (isset($desc['field'][$nom_champ])) { |
|
| 266 | - $t = $boucles[$idb]->id_table; |
|
| 267 | - $joker = false; // indiquer a l'appelant |
|
| 268 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Tous les champs sont-ils acceptés ? |
|
| 272 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 273 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 274 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 275 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 276 | - if ( |
|
| 277 | - /*$joker AND */ |
|
| 278 | - isset($desc['field']['*']) |
|
| 279 | - ) { |
|
| 280 | - $joker = true; // indiquer a l'appelant |
|
| 281 | - return [$nom_champ, $nom_champ]; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $joker = false; // indiquer a l'appelant |
|
| 285 | - |
|
| 286 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 287 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 288 | - [, $_table, $_nom_champ] = $r; |
|
| 289 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 290 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 291 | - return index_exception( |
|
| 292 | - $boucles[$idb], |
|
| 293 | - $desc, |
|
| 294 | - $_alias, |
|
| 295 | - [$_table, $_nom_champ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - return ['', '']; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // pas d'alias, pas de champ, pas de joker... |
|
| 302 | - // tenter via une jointure... |
|
| 303 | - |
|
| 304 | - // regarder si le champ est deja dans une jointure existante |
|
| 305 | - // sinon, si il y a des joitures explicites, la construire |
|
| 306 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 307 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 308 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 309 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 310 | - // mais est-ce ce qu'on veut ? |
|
| 311 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 312 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 313 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ($t) { |
|
| 319 | - // si on a trouvé une jointure possible, on fait comme |
|
| 320 | - // si c'était une exception pour le champ demandé |
|
| 321 | - return index_exception( |
|
| 322 | - $boucles[$idb], |
|
| 323 | - $desc, |
|
| 324 | - $nom_champ, |
|
| 325 | - [$t[1]['id_table'], reset($t[2])] |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return ['', '']; |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // il y a un alias connu pour ce champ |
|
| 259 | + if ($excep) { |
|
| 260 | + $joker = false; // indiquer a l'appelant |
|
| 261 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // le champ existe dans la table, on le prend. |
|
| 265 | + if (isset($desc['field'][$nom_champ])) { |
|
| 266 | + $t = $boucles[$idb]->id_table; |
|
| 267 | + $joker = false; // indiquer a l'appelant |
|
| 268 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Tous les champs sont-ils acceptés ? |
|
| 272 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 273 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 274 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 275 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 276 | + if ( |
|
| 277 | + /*$joker AND */ |
|
| 278 | + isset($desc['field']['*']) |
|
| 279 | + ) { |
|
| 280 | + $joker = true; // indiquer a l'appelant |
|
| 281 | + return [$nom_champ, $nom_champ]; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $joker = false; // indiquer a l'appelant |
|
| 285 | + |
|
| 286 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 287 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 288 | + [, $_table, $_nom_champ] = $r; |
|
| 289 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 290 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 291 | + return index_exception( |
|
| 292 | + $boucles[$idb], |
|
| 293 | + $desc, |
|
| 294 | + $_alias, |
|
| 295 | + [$_table, $_nom_champ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + return ['', '']; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // pas d'alias, pas de champ, pas de joker... |
|
| 302 | + // tenter via une jointure... |
|
| 303 | + |
|
| 304 | + // regarder si le champ est deja dans une jointure existante |
|
| 305 | + // sinon, si il y a des joitures explicites, la construire |
|
| 306 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 307 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 308 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 309 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 310 | + // mais est-ce ce qu'on veut ? |
|
| 311 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 312 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 313 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ($t) { |
|
| 319 | + // si on a trouvé une jointure possible, on fait comme |
|
| 320 | + // si c'était une exception pour le champ demandé |
|
| 321 | + return index_exception( |
|
| 322 | + $boucles[$idb], |
|
| 323 | + $desc, |
|
| 324 | + $nom_champ, |
|
| 325 | + [$t[1]['id_table'], reset($t[2])] |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return ['', '']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -354,52 +354,52 @@ discard block |
||
| 354 | 354 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 355 | 355 | **/ |
| 356 | 356 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 357 | - static $trouver_table; |
|
| 358 | - if (!$trouver_table) { |
|
| 359 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (is_array($excep)) { |
|
| 363 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 364 | - $t = null; |
|
| 365 | - if (count($excep) == 3) { |
|
| 366 | - $index_exception_derogatoire = array_pop($excep); |
|
| 367 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 368 | - } |
|
| 369 | - if ($t == null) { |
|
| 370 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 371 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 372 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 373 | - if (!$j) { |
|
| 374 | - return ['', '']; |
|
| 375 | - } |
|
| 376 | - $e = $j['table']; |
|
| 377 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 378 | - $k = $j['key']['PRIMARY KEY']; |
|
| 379 | - if (strpos($k, ',')) { |
|
| 380 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 381 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 382 | - if (!in_array($k, $l)) { |
|
| 383 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 384 | - |
|
| 385 | - return ['', '']; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 389 | - fabrique_jointures($boucle, [$k]); |
|
| 390 | - $t = array_search($e, $boucle->from); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } else { |
|
| 394 | - $t = $boucle->id_table; |
|
| 395 | - } |
|
| 396 | - // demander a SQL de gerer le synonyme |
|
| 397 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 398 | - if ($excep != $nom_champ) { |
|
| 399 | - $excep .= ' AS ' . $nom_champ; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - return ["$t.$excep", $nom_champ]; |
|
| 357 | + static $trouver_table; |
|
| 358 | + if (!$trouver_table) { |
|
| 359 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (is_array($excep)) { |
|
| 363 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 364 | + $t = null; |
|
| 365 | + if (count($excep) == 3) { |
|
| 366 | + $index_exception_derogatoire = array_pop($excep); |
|
| 367 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 368 | + } |
|
| 369 | + if ($t == null) { |
|
| 370 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 371 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 372 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 373 | + if (!$j) { |
|
| 374 | + return ['', '']; |
|
| 375 | + } |
|
| 376 | + $e = $j['table']; |
|
| 377 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 378 | + $k = $j['key']['PRIMARY KEY']; |
|
| 379 | + if (strpos($k, ',')) { |
|
| 380 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 381 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 382 | + if (!in_array($k, $l)) { |
|
| 383 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 384 | + |
|
| 385 | + return ['', '']; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 389 | + fabrique_jointures($boucle, [$k]); |
|
| 390 | + $t = array_search($e, $boucle->from); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } else { |
|
| 394 | + $t = $boucle->id_table; |
|
| 395 | + } |
|
| 396 | + // demander a SQL de gerer le synonyme |
|
| 397 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 398 | + if ($excep != $nom_champ) { |
|
| 399 | + $excep .= ' AS ' . $nom_champ; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + return ["$t.$excep", $nom_champ]; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * Code PHP pour retrouver le champ |
| 425 | 425 | */ |
| 426 | 426 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 427 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 427 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | |
@@ -444,9 +444,9 @@ discard block |
||
| 444 | 444 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 445 | 445 | **/ |
| 446 | 446 | function calculer_champ($p) { |
| 447 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 447 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 448 | 448 | |
| 449 | - return applique_filtres($p); |
|
| 449 | + return applique_filtres($p); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -483,26 +483,26 @@ discard block |
||
| 483 | 483 | **/ |
| 484 | 484 | function calculer_balise(string $nom, \Champ $p): \Champ { |
| 485 | 485 | |
| 486 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 487 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 488 | - $p->balise_calculee = true; |
|
| 489 | - $res = $f($p); |
|
| 490 | - if ($res !== null and is_object($res)) { |
|
| 491 | - return $res; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // Certaines des balises comportant un _ sont generiques |
|
| 496 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 497 | - $res = $balise_generique['fonction_generique']($p); |
|
| 498 | - if ($res !== null and is_object($res)) { |
|
| 499 | - return $res; |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 504 | - |
|
| 505 | - return $f($nom, $p); |
|
| 486 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 487 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 488 | + $p->balise_calculee = true; |
|
| 489 | + $res = $f($p); |
|
| 490 | + if ($res !== null and is_object($res)) { |
|
| 491 | + return $res; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // Certaines des balises comportant un _ sont generiques |
|
| 496 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 497 | + $res = $balise_generique['fonction_generique']($p); |
|
| 498 | + if ($res !== null and is_object($res)) { |
|
| 499 | + return $res; |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 504 | + |
|
| 505 | + return $f($nom, $p); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | |
@@ -530,37 +530,37 @@ discard block |
||
| 530 | 530 | **/ |
| 531 | 531 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 532 | 532 | |
| 533 | - // ca pourrait etre un champ SQL homonyme, |
|
| 534 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 535 | - |
|
| 536 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 537 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 538 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 539 | - $code = addslashes($p->fonctions[0][1]); |
|
| 540 | - $p->code .= " . '$code'"; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 544 | - if (strpos($nom, 'ID_') === 0) { |
|
| 545 | - $p->interdire_scripts = false; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 549 | - // SI le champ SQL n'est pas trouve |
|
| 550 | - // ET si la balise a une forme de couleur |
|
| 551 | - // ET s'il n'y a ni filtre ni etoile |
|
| 552 | - // ALORS retourner la couleur. |
|
| 553 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 554 | - if ( |
|
| 555 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 556 | - and !$p->etoile |
|
| 557 | - and !$p->fonctions |
|
| 558 | - ) { |
|
| 559 | - $p->code = "'#$nom'"; |
|
| 560 | - $p->interdire_scripts = false; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return $p; |
|
| 533 | + // ca pourrait etre un champ SQL homonyme, |
|
| 534 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 535 | + |
|
| 536 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 537 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 538 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 539 | + $code = addslashes($p->fonctions[0][1]); |
|
| 540 | + $p->code .= " . '$code'"; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 544 | + if (strpos($nom, 'ID_') === 0) { |
|
| 545 | + $p->interdire_scripts = false; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 549 | + // SI le champ SQL n'est pas trouve |
|
| 550 | + // ET si la balise a une forme de couleur |
|
| 551 | + // ET s'il n'y a ni filtre ni etoile |
|
| 552 | + // ALORS retourner la couleur. |
|
| 553 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 554 | + if ( |
|
| 555 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 556 | + and !$p->etoile |
|
| 557 | + and !$p->fonctions |
|
| 558 | + ) { |
|
| 559 | + $p->code = "'#$nom'"; |
|
| 560 | + $p->interdire_scripts = false; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return $p; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -603,39 +603,39 @@ discard block |
||
| 603 | 603 | **/ |
| 604 | 604 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 605 | 605 | |
| 606 | - if (!balise_distante_interdite($p)) { |
|
| 607 | - $p->code = "''"; |
|
| 608 | - |
|
| 609 | - return $p; |
|
| 610 | - } |
|
| 611 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 612 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 613 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 614 | - $p->fonctions = null; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - if ($p->param and ($c = $p->param[0])) { |
|
| 618 | - // liste d'arguments commence toujours par la chaine vide |
|
| 619 | - array_shift($c); |
|
| 620 | - // construire la liste d'arguments comme pour un filtre |
|
| 621 | - $param = compose_filtres_args($p, $c, ','); |
|
| 622 | - } else { |
|
| 623 | - $param = ''; |
|
| 624 | - } |
|
| 625 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 626 | - |
|
| 627 | - $p->code = sprintf( |
|
| 628 | - CODE_EXECUTER_BALISE, |
|
| 629 | - $nom, |
|
| 630 | - join(',', $collecte), |
|
| 631 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 632 | - memoriser_contexte_compil($p), |
|
| 633 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 634 | - ); |
|
| 635 | - |
|
| 636 | - $p->interdire_scripts = false; |
|
| 637 | - |
|
| 638 | - return $p; |
|
| 606 | + if (!balise_distante_interdite($p)) { |
|
| 607 | + $p->code = "''"; |
|
| 608 | + |
|
| 609 | + return $p; |
|
| 610 | + } |
|
| 611 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 612 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 613 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 614 | + $p->fonctions = null; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + if ($p->param and ($c = $p->param[0])) { |
|
| 618 | + // liste d'arguments commence toujours par la chaine vide |
|
| 619 | + array_shift($c); |
|
| 620 | + // construire la liste d'arguments comme pour un filtre |
|
| 621 | + $param = compose_filtres_args($p, $c, ','); |
|
| 622 | + } else { |
|
| 623 | + $param = ''; |
|
| 624 | + } |
|
| 625 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 626 | + |
|
| 627 | + $p->code = sprintf( |
|
| 628 | + CODE_EXECUTER_BALISE, |
|
| 629 | + $nom, |
|
| 630 | + join(',', $collecte), |
|
| 631 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 632 | + memoriser_contexte_compil($p), |
|
| 633 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 634 | + ); |
|
| 635 | + |
|
| 636 | + $p->interdire_scripts = false; |
|
| 637 | + |
|
| 638 | + return $p; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -665,17 +665,17 @@ discard block |
||
| 665 | 665 | * Liste des codes PHP d'éxecution des balises collectées |
| 666 | 666 | **/ |
| 667 | 667 | function collecter_balise_dynamique(array $l, \Champ &$p, string $nom): array { |
| 668 | - $args = []; |
|
| 669 | - foreach ($l as $c) { |
|
| 670 | - if ($c === null) { |
|
| 671 | - $args[] = 'null'; |
|
| 672 | - } else { |
|
| 673 | - $x = calculer_balise($c, $p); |
|
| 674 | - $args[] = $x->code; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return $args; |
|
| 668 | + $args = []; |
|
| 669 | + foreach ($l as $c) { |
|
| 670 | + if ($c === null) { |
|
| 671 | + $args[] = 'null'; |
|
| 672 | + } else { |
|
| 673 | + $x = calculer_balise($c, $p); |
|
| 674 | + $args[] = $x->code; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return $args; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -690,22 +690,22 @@ discard block |
||
| 690 | 690 | * Nom de la connexion |
| 691 | 691 | **/ |
| 692 | 692 | function trouver_nom_serveur_distant($p) { |
| 693 | - $nom = $p->id_boucle; |
|
| 694 | - if ( |
|
| 695 | - $nom |
|
| 696 | - and isset($p->boucles[$nom]) |
|
| 697 | - ) { |
|
| 698 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 699 | - if ( |
|
| 700 | - strlen($s) |
|
| 701 | - and strlen($serveur = strtolower($s)) |
|
| 702 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 703 | - ) { |
|
| 704 | - return $serveur; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - return ''; |
|
| 693 | + $nom = $p->id_boucle; |
|
| 694 | + if ( |
|
| 695 | + $nom |
|
| 696 | + and isset($p->boucles[$nom]) |
|
| 697 | + ) { |
|
| 698 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 699 | + if ( |
|
| 700 | + strlen($s) |
|
| 701 | + and strlen($serveur = strtolower($s)) |
|
| 702 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 703 | + ) { |
|
| 704 | + return $serveur; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + return ''; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | |
@@ -729,15 +729,15 @@ discard block |
||
| 729 | 729 | * - false : La balise est interdite car le serveur est distant |
| 730 | 730 | **/ |
| 731 | 731 | function balise_distante_interdite($p) { |
| 732 | - $nom = $p->id_boucle; |
|
| 732 | + $nom = $p->id_boucle; |
|
| 733 | 733 | |
| 734 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 735 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 734 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 735 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 736 | 736 | |
| 737 | - return false; |
|
| 738 | - } |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | - return true; |
|
| 740 | + return true; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
@@ -747,84 +747,84 @@ discard block |
||
| 747 | 747 | // |
| 748 | 748 | function champs_traitements($p) { |
| 749 | 749 | |
| 750 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 751 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 752 | - } else { |
|
| 753 | - // quand on utilise un traitement catch-all * |
|
| 754 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 755 | - // leur propre securite |
|
| 756 | - if (!$p->balise_calculee) { |
|
| 757 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 758 | - } else { |
|
| 759 | - $ps = false; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - if (is_array($ps)) { |
|
| 764 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 765 | - $idb = index_boucle($p); |
|
| 766 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 767 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 768 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 772 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 773 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 774 | - |
|
| 775 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 776 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 777 | - $type_alias = $type_requete; |
|
| 778 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 779 | - } else { |
|
| 780 | - $type_alias = false; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 784 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 785 | - $ps = $ps[$table_sql]; |
|
| 786 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 787 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 788 | - $ps = $ps[$type_requete]; |
|
| 789 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 790 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 791 | - $ps = $ps[$type_alias]; |
|
| 792 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 793 | - elseif (isset($ps[0])) { |
|
| 794 | - $ps = $ps[0]; |
|
| 795 | - } else { |
|
| 796 | - $ps = false; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - if (!$ps) { |
|
| 801 | - return $p->code; |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 805 | - // ou si in INCLURE contient {doublons} |
|
| 806 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 807 | - // dans les filtres propre() ou typo() |
|
| 808 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 809 | - |
|
| 810 | - if ( |
|
| 811 | - isset($p->descr['documents']) |
|
| 812 | - and |
|
| 813 | - $p->descr['documents'] |
|
| 814 | - and ( |
|
| 815 | - (strpos($ps, 'propre') !== false) |
|
| 816 | - or |
|
| 817 | - (strpos($ps, 'typo') !== false) |
|
| 818 | - ) |
|
| 819 | - ) { |
|
| 820 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 824 | - // dans la declaration des traitements des champs sensibles |
|
| 825 | - |
|
| 826 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 827 | - return str_replace('%s', $p->code, $ps); |
|
| 750 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 751 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 752 | + } else { |
|
| 753 | + // quand on utilise un traitement catch-all * |
|
| 754 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 755 | + // leur propre securite |
|
| 756 | + if (!$p->balise_calculee) { |
|
| 757 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 758 | + } else { |
|
| 759 | + $ps = false; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + if (is_array($ps)) { |
|
| 764 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 765 | + $idb = index_boucle($p); |
|
| 766 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 767 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 768 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 772 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 773 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 774 | + |
|
| 775 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 776 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 777 | + $type_alias = $type_requete; |
|
| 778 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 779 | + } else { |
|
| 780 | + $type_alias = false; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 784 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 785 | + $ps = $ps[$table_sql]; |
|
| 786 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 787 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 788 | + $ps = $ps[$type_requete]; |
|
| 789 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 790 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 791 | + $ps = $ps[$type_alias]; |
|
| 792 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 793 | + elseif (isset($ps[0])) { |
|
| 794 | + $ps = $ps[0]; |
|
| 795 | + } else { |
|
| 796 | + $ps = false; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + if (!$ps) { |
|
| 801 | + return $p->code; |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 805 | + // ou si in INCLURE contient {doublons} |
|
| 806 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 807 | + // dans les filtres propre() ou typo() |
|
| 808 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 809 | + |
|
| 810 | + if ( |
|
| 811 | + isset($p->descr['documents']) |
|
| 812 | + and |
|
| 813 | + $p->descr['documents'] |
|
| 814 | + and ( |
|
| 815 | + (strpos($ps, 'propre') !== false) |
|
| 816 | + or |
|
| 817 | + (strpos($ps, 'typo') !== false) |
|
| 818 | + ) |
|
| 819 | + ) { |
|
| 820 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 824 | + // dans la declaration des traitements des champs sensibles |
|
| 825 | + |
|
| 826 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 827 | + return str_replace('%s', $p->code, $ps); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | |
@@ -836,110 +836,110 @@ discard block |
||
| 836 | 836 | // |
| 837 | 837 | function applique_filtres($p) { |
| 838 | 838 | |
| 839 | - // Traitements standards (cf. supra) |
|
| 840 | - if ($p->etoile == '') { |
|
| 841 | - $code = champs_traitements($p); |
|
| 842 | - } else { |
|
| 843 | - $code = $p->code; |
|
| 844 | - } |
|
| 839 | + // Traitements standards (cf. supra) |
|
| 840 | + if ($p->etoile == '') { |
|
| 841 | + $code = champs_traitements($p); |
|
| 842 | + } else { |
|
| 843 | + $code = $p->code; |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | - // Appliquer les filtres perso |
|
| 847 | - if ($p->param) { |
|
| 848 | - $code = compose_filtres($p, $code); |
|
| 849 | - } |
|
| 846 | + // Appliquer les filtres perso |
|
| 847 | + if ($p->param) { |
|
| 848 | + $code = compose_filtres($p, $code); |
|
| 849 | + } |
|
| 850 | 850 | |
| 851 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 852 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 853 | - if (isset($p->descr['session'])) { |
|
| 854 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 855 | - } |
|
| 851 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 852 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 853 | + if (isset($p->descr['session'])) { |
|
| 854 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 855 | + } |
|
| 856 | 856 | |
| 857 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 857 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 858 | 858 | |
| 859 | - return $code; |
|
| 859 | + return $code; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 863 | 863 | function compose_filtres(&$p, $code) { |
| 864 | 864 | |
| 865 | - $image_miette = false; |
|
| 866 | - foreach ($p->param as $filtre) { |
|
| 867 | - $fonc = array_shift($filtre); |
|
| 868 | - if (!$fonc) { |
|
| 869 | - continue; |
|
| 870 | - } // normalement qu'au premier tour. |
|
| 871 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 872 | - if ($image_miette and !$is_filtre_image) { |
|
| 873 | - // il faut graver maintenant car apres le filtre en cours |
|
| 874 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | - $code = "filtrer('image_graver', $code)"; |
|
| 876 | - $image_miette = false; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - // recuperer les arguments du filtre, |
|
| 880 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | - if ($fonc !== '?') { |
|
| 883 | - $sep = ','; |
|
| 884 | - } else { |
|
| 885 | - $sep = ':'; |
|
| 886 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | - if ($countfiltre != 2) { |
|
| 888 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | - $countfiltre = 2; |
|
| 890 | - } |
|
| 891 | - } |
|
| 892 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | - if ($logique) { |
|
| 895 | - $code = $logique; |
|
| 896 | - } else { |
|
| 897 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | - if ($is_filtre_image) { |
|
| 899 | - $image_miette = true; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | - if ($image_miette) { |
|
| 905 | - $code = "filtrer('image_graver',$code)"; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - return $code; |
|
| 865 | + $image_miette = false; |
|
| 866 | + foreach ($p->param as $filtre) { |
|
| 867 | + $fonc = array_shift($filtre); |
|
| 868 | + if (!$fonc) { |
|
| 869 | + continue; |
|
| 870 | + } // normalement qu'au premier tour. |
|
| 871 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 872 | + if ($image_miette and !$is_filtre_image) { |
|
| 873 | + // il faut graver maintenant car apres le filtre en cours |
|
| 874 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | + $code = "filtrer('image_graver', $code)"; |
|
| 876 | + $image_miette = false; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + // recuperer les arguments du filtre, |
|
| 880 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | + if ($fonc !== '?') { |
|
| 883 | + $sep = ','; |
|
| 884 | + } else { |
|
| 885 | + $sep = ':'; |
|
| 886 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | + if ($countfiltre != 2) { |
|
| 888 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | + $countfiltre = 2; |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | + if ($logique) { |
|
| 895 | + $code = $logique; |
|
| 896 | + } else { |
|
| 897 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | + if ($is_filtre_image) { |
|
| 899 | + $image_miette = true; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | + if ($image_miette) { |
|
| 905 | + $code = "filtrer('image_graver',$code)"; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + return $code; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 912 | 912 | // et comparateurs |
| 913 | 913 | function filtre_logique($fonc, $code, $arg) { |
| 914 | 914 | |
| 915 | - switch (true) { |
|
| 916 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 917 | - return "($code $fonc $arg)"; |
|
| 918 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 919 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 920 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 921 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 922 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 923 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 924 | - case ($fonc == 'sinon'): |
|
| 925 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 926 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 927 | - return "(($code) ?'' :' ')"; |
|
| 928 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 929 | - return "(($code) ?' ' :'')"; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - return ''; |
|
| 915 | + switch (true) { |
|
| 916 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 917 | + return "($code $fonc $arg)"; |
|
| 918 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 919 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 920 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 921 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 922 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 923 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 924 | + case ($fonc == 'sinon'): |
|
| 925 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 926 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 927 | + return "(($code) ?'' :' ')"; |
|
| 928 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 929 | + return "(($code) ?' ' :'')"; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + return ''; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | function compose_filtres_args($p, $args, $sep) { |
| 936 | - $arglist = ''; |
|
| 937 | - foreach ($args as $arg) { |
|
| 938 | - $arglist .= $sep . |
|
| 939 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 940 | - } |
|
| 936 | + $arglist = ''; |
|
| 937 | + foreach ($args as $arg) { |
|
| 938 | + $arglist .= $sep . |
|
| 939 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 940 | + } |
|
| 941 | 941 | |
| 942 | - return $arglist; |
|
| 942 | + return $arglist; |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | 945 | |
@@ -957,15 +957,15 @@ discard block |
||
| 957 | 957 | **/ |
| 958 | 958 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 959 | 959 | |
| 960 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 961 | - if ($boucles[$idb]->externe) { |
|
| 962 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 963 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 964 | - // on ignore le defaut fourni dans ce cas |
|
| 965 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 966 | - } |
|
| 960 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 961 | + if ($boucles[$idb]->externe) { |
|
| 962 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 963 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 964 | + // on ignore le defaut fourni dans ce cas |
|
| 965 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 966 | + } |
|
| 967 | 967 | |
| 968 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 968 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | // |
@@ -979,30 +979,30 @@ discard block |
||
| 979 | 979 | // |
| 980 | 980 | |
| 981 | 981 | function rindex_pile($p, $champ, $motif) { |
| 982 | - $n = 0; |
|
| 983 | - $b = $p->id_boucle; |
|
| 984 | - $p->code = ''; |
|
| 985 | - while ($b != '') { |
|
| 986 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 987 | - if ($critere->op == $motif) { |
|
| 988 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 989 | - "]['$champ']"; |
|
| 990 | - $b = ''; |
|
| 991 | - break 2; |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - $n++; |
|
| 995 | - $b = $p->boucles[$b]->id_parent; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 999 | - if (!$p->code) { |
|
| 1000 | - $p->code = "''"; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - $p->interdire_scripts = false; |
|
| 1004 | - |
|
| 1005 | - return $p; |
|
| 982 | + $n = 0; |
|
| 983 | + $b = $p->id_boucle; |
|
| 984 | + $p->code = ''; |
|
| 985 | + while ($b != '') { |
|
| 986 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 987 | + if ($critere->op == $motif) { |
|
| 988 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 989 | + "]['$champ']"; |
|
| 990 | + $b = ''; |
|
| 991 | + break 2; |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + $n++; |
|
| 995 | + $b = $p->boucles[$b]->id_parent; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 999 | + if (!$p->code) { |
|
| 1000 | + $p->code = "''"; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + $p->interdire_scripts = false; |
|
| 1004 | + |
|
| 1005 | + return $p; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1013 | 1013 | */ |
| 1014 | 1014 | function zbug_presenter_champ($p, $champ = '') { |
| 1015 | - $balise = $champ ?: $p->nom_champ; |
|
| 1016 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1017 | - return "#{$explicite}{$balise}"; |
|
| 1015 | + $balise = $champ ?: $p->nom_champ; |
|
| 1016 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1017 | + return "#{$explicite}{$balise}"; |
|
| 1018 | 1018 | } |