@@ -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 | - list($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 | + list($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 ? $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 ? $defaut : "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,77 +237,77 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 256 | - } |
|
| 257 | - if ($excep) { |
|
| 258 | - $joker = false; // indiquer a l'appelant |
|
| 259 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | - } // pas d'alias. Le champ existe t'il ? |
|
| 261 | - else { |
|
| 262 | - // le champ est réellement présent, on le prend. |
|
| 263 | - if (isset($desc['field'][$nom_champ])) { |
|
| 264 | - $t = $boucles[$idb]->id_table; |
|
| 265 | - $joker = false; // indiquer a l'appelant |
|
| 266 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | - } |
|
| 268 | - // Tous les champs sont-ils acceptés ? |
|
| 269 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | - elseif ( |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 256 | + } |
|
| 257 | + if ($excep) { |
|
| 258 | + $joker = false; // indiquer a l'appelant |
|
| 259 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | + } // pas d'alias. Le champ existe t'il ? |
|
| 261 | + else { |
|
| 262 | + // le champ est réellement présent, on le prend. |
|
| 263 | + if (isset($desc['field'][$nom_champ])) { |
|
| 264 | + $t = $boucles[$idb]->id_table; |
|
| 265 | + $joker = false; // indiquer a l'appelant |
|
| 266 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | + } |
|
| 268 | + // Tous les champs sont-ils acceptés ? |
|
| 269 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | + elseif ( |
|
| 274 | 274 | /*$joker AND */ |
| 275 | - isset($desc['field']['*']) |
|
| 276 | - ) { |
|
| 277 | - $joker = true; // indiquer a l'appelant |
|
| 278 | - return [$nom_champ, $nom_champ]; |
|
| 279 | - } |
|
| 280 | - // pas d'alias, pas de champ, pas de joker... |
|
| 281 | - // tenter via une jointure... |
|
| 282 | - else { |
|
| 283 | - $joker = false; // indiquer a l'appelant |
|
| 284 | - // regarder si le champ est deja dans une jointure existante |
|
| 285 | - // sinon, si il y a des joitures explicites, la construire |
|
| 286 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | - // mais est-ce ce qu'on veut ? |
|
| 291 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($t) { |
|
| 298 | - // si on a trouvé une jointure possible, on fait comme |
|
| 299 | - // si c'était une exception pour le champ demandé |
|
| 300 | - return index_exception( |
|
| 301 | - $boucles[$idb], |
|
| 302 | - $desc, |
|
| 303 | - $nom_champ, |
|
| 304 | - [$t[1]['id_table'], reset($t[2])] |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return ['', '']; |
|
| 309 | - } |
|
| 310 | - } |
|
| 275 | + isset($desc['field']['*']) |
|
| 276 | + ) { |
|
| 277 | + $joker = true; // indiquer a l'appelant |
|
| 278 | + return [$nom_champ, $nom_champ]; |
|
| 279 | + } |
|
| 280 | + // pas d'alias, pas de champ, pas de joker... |
|
| 281 | + // tenter via une jointure... |
|
| 282 | + else { |
|
| 283 | + $joker = false; // indiquer a l'appelant |
|
| 284 | + // regarder si le champ est deja dans une jointure existante |
|
| 285 | + // sinon, si il y a des joitures explicites, la construire |
|
| 286 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | + // mais est-ce ce qu'on veut ? |
|
| 291 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($t) { |
|
| 298 | + // si on a trouvé une jointure possible, on fait comme |
|
| 299 | + // si c'était une exception pour le champ demandé |
|
| 300 | + return index_exception( |
|
| 301 | + $boucles[$idb], |
|
| 302 | + $desc, |
|
| 303 | + $nom_champ, |
|
| 304 | + [$t[1]['id_table'], reset($t[2])] |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return ['', '']; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -335,52 +335,52 @@ discard block |
||
| 335 | 335 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 336 | 336 | **/ |
| 337 | 337 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 338 | - static $trouver_table; |
|
| 339 | - if (!$trouver_table) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - if (is_array($excep)) { |
|
| 344 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | - $t = null; |
|
| 346 | - if (count($excep) == 3) { |
|
| 347 | - $index_exception_derogatoire = array_pop($excep); |
|
| 348 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | - } |
|
| 350 | - if ($t == null) { |
|
| 351 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | - if (!$j) { |
|
| 355 | - return ['', '']; |
|
| 356 | - } |
|
| 357 | - $e = $j['table']; |
|
| 358 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | - $k = $j['key']['PRIMARY KEY']; |
|
| 360 | - if (strpos($k, ',')) { |
|
| 361 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | - if (!in_array($k, $l)) { |
|
| 364 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | - |
|
| 366 | - return ['', '']; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | - fabrique_jointures($boucle, [$k]); |
|
| 371 | - $t = array_search($e, $boucle->from); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } else { |
|
| 375 | - $t = $boucle->id_table; |
|
| 376 | - } |
|
| 377 | - // demander a SQL de gerer le synonyme |
|
| 378 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | - if ($excep != $nom_champ) { |
|
| 380 | - $excep .= ' AS ' . $nom_champ; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return ["$t.$excep", $nom_champ]; |
|
| 338 | + static $trouver_table; |
|
| 339 | + if (!$trouver_table) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + if (is_array($excep)) { |
|
| 344 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | + $t = null; |
|
| 346 | + if (count($excep) == 3) { |
|
| 347 | + $index_exception_derogatoire = array_pop($excep); |
|
| 348 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | + } |
|
| 350 | + if ($t == null) { |
|
| 351 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | + if (!$j) { |
|
| 355 | + return ['', '']; |
|
| 356 | + } |
|
| 357 | + $e = $j['table']; |
|
| 358 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | + $k = $j['key']['PRIMARY KEY']; |
|
| 360 | + if (strpos($k, ',')) { |
|
| 361 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | + if (!in_array($k, $l)) { |
|
| 364 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | + |
|
| 366 | + return ['', '']; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | + fabrique_jointures($boucle, [$k]); |
|
| 371 | + $t = array_search($e, $boucle->from); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } else { |
|
| 375 | + $t = $boucle->id_table; |
|
| 376 | + } |
|
| 377 | + // demander a SQL de gerer le synonyme |
|
| 378 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | + if ($excep != $nom_champ) { |
|
| 380 | + $excep .= ' AS ' . $nom_champ; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return ["$t.$excep", $nom_champ]; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * Code PHP pour retrouver le champ |
| 406 | 406 | */ |
| 407 | 407 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 408 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 408 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 426 | 426 | **/ |
| 427 | 427 | function calculer_champ($p) { |
| 428 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 428 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 429 | 429 | |
| 430 | - return applique_filtres($p); |
|
| 430 | + return applique_filtres($p); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_balise($nom, $p) { |
| 466 | 466 | |
| 467 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | - $p->balise_calculee = true; |
|
| 470 | - $res = $f($p); |
|
| 471 | - if ($res !== null and is_object($res)) { |
|
| 472 | - return $res; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Certaines des balises comportant un _ sont generiques |
|
| 477 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | - $res = $balise_generique['fonction_generique']($p); |
|
| 479 | - if ($res !== null and is_object($res)) { |
|
| 480 | - return $res; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | - |
|
| 486 | - return $f($nom, $p); |
|
| 467 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | + $p->balise_calculee = true; |
|
| 470 | + $res = $f($p); |
|
| 471 | + if ($res !== null and is_object($res)) { |
|
| 472 | + return $res; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Certaines des balises comportant un _ sont generiques |
|
| 477 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | + $res = $balise_generique['fonction_generique']($p); |
|
| 479 | + if ($res !== null and is_object($res)) { |
|
| 480 | + return $res; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | + |
|
| 486 | + return $f($nom, $p); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -511,37 +511,37 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 513 | 513 | |
| 514 | - // ca pourrait etre un champ SQL homonyme, |
|
| 515 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | - |
|
| 517 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | - $code = addslashes($p->fonctions[0][1]); |
|
| 521 | - $p->code .= " . '$code'"; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | - if (strpos($nom, 'ID_') === 0) { |
|
| 526 | - $p->interdire_scripts = false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | - // SI le champ SQL n'est pas trouve |
|
| 531 | - // ET si la balise a une forme de couleur |
|
| 532 | - // ET s'il n'y a ni filtre ni etoile |
|
| 533 | - // ALORS retourner la couleur. |
|
| 534 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | - if ( |
|
| 536 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | - and !$p->etoile |
|
| 538 | - and !$p->fonctions |
|
| 539 | - ) { |
|
| 540 | - $p->code = "'#$nom'"; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return $p; |
|
| 514 | + // ca pourrait etre un champ SQL homonyme, |
|
| 515 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | + |
|
| 517 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | + $code = addslashes($p->fonctions[0][1]); |
|
| 521 | + $p->code .= " . '$code'"; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | + if (strpos($nom, 'ID_') === 0) { |
|
| 526 | + $p->interdire_scripts = false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | + // SI le champ SQL n'est pas trouve |
|
| 531 | + // ET si la balise a une forme de couleur |
|
| 532 | + // ET s'il n'y a ni filtre ni etoile |
|
| 533 | + // ALORS retourner la couleur. |
|
| 534 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | + if ( |
|
| 536 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | + and !$p->etoile |
|
| 538 | + and !$p->fonctions |
|
| 539 | + ) { |
|
| 540 | + $p->code = "'#$nom'"; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -584,39 +584,39 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 586 | 586 | |
| 587 | - if (!balise_distante_interdite($p)) { |
|
| 588 | - $p->code = "''"; |
|
| 589 | - |
|
| 590 | - return $p; |
|
| 591 | - } |
|
| 592 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | - $p->fonctions = null; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if ($p->param and ($c = $p->param[0])) { |
|
| 599 | - // liste d'arguments commence toujours par la chaine vide |
|
| 600 | - array_shift($c); |
|
| 601 | - // construire la liste d'arguments comme pour un filtre |
|
| 602 | - $param = compose_filtres_args($p, $c, ','); |
|
| 603 | - } else { |
|
| 604 | - $param = ''; |
|
| 605 | - } |
|
| 606 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | - |
|
| 608 | - $p->code = sprintf( |
|
| 609 | - CODE_EXECUTER_BALISE, |
|
| 610 | - $nom, |
|
| 611 | - join(',', $collecte), |
|
| 612 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | - memoriser_contexte_compil($p), |
|
| 614 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | - ); |
|
| 616 | - |
|
| 617 | - $p->interdire_scripts = false; |
|
| 618 | - |
|
| 619 | - return $p; |
|
| 587 | + if (!balise_distante_interdite($p)) { |
|
| 588 | + $p->code = "''"; |
|
| 589 | + |
|
| 590 | + return $p; |
|
| 591 | + } |
|
| 592 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | + $p->fonctions = null; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if ($p->param and ($c = $p->param[0])) { |
|
| 599 | + // liste d'arguments commence toujours par la chaine vide |
|
| 600 | + array_shift($c); |
|
| 601 | + // construire la liste d'arguments comme pour un filtre |
|
| 602 | + $param = compose_filtres_args($p, $c, ','); |
|
| 603 | + } else { |
|
| 604 | + $param = ''; |
|
| 605 | + } |
|
| 606 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | + |
|
| 608 | + $p->code = sprintf( |
|
| 609 | + CODE_EXECUTER_BALISE, |
|
| 610 | + $nom, |
|
| 611 | + join(',', $collecte), |
|
| 612 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | + memoriser_contexte_compil($p), |
|
| 614 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | + ); |
|
| 616 | + |
|
| 617 | + $p->interdire_scripts = false; |
|
| 618 | + |
|
| 619 | + return $p; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | |
@@ -646,13 +646,13 @@ discard block |
||
| 646 | 646 | * Liste des codes PHP d'éxecution des balises collectées |
| 647 | 647 | **/ |
| 648 | 648 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 649 | - $args = []; |
|
| 650 | - foreach ($l as $c) { |
|
| 651 | - $x = calculer_balise($c, $p); |
|
| 652 | - $args[] = $x->code; |
|
| 653 | - } |
|
| 649 | + $args = []; |
|
| 650 | + foreach ($l as $c) { |
|
| 651 | + $x = calculer_balise($c, $p); |
|
| 652 | + $args[] = $x->code; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - return $args; |
|
| 655 | + return $args; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -667,22 +667,22 @@ discard block |
||
| 667 | 667 | * Nom de la connexion |
| 668 | 668 | **/ |
| 669 | 669 | function trouver_nom_serveur_distant($p) { |
| 670 | - $nom = $p->id_boucle; |
|
| 671 | - if ( |
|
| 672 | - $nom |
|
| 673 | - and isset($p->boucles[$nom]) |
|
| 674 | - ) { |
|
| 675 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 676 | - if ( |
|
| 677 | - strlen($s) |
|
| 678 | - and strlen($serveur = strtolower($s)) |
|
| 679 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 680 | - ) { |
|
| 681 | - return $serveur; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return ''; |
|
| 670 | + $nom = $p->id_boucle; |
|
| 671 | + if ( |
|
| 672 | + $nom |
|
| 673 | + and isset($p->boucles[$nom]) |
|
| 674 | + ) { |
|
| 675 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 676 | + if ( |
|
| 677 | + strlen($s) |
|
| 678 | + and strlen($serveur = strtolower($s)) |
|
| 679 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 680 | + ) { |
|
| 681 | + return $serveur; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return ''; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
@@ -706,15 +706,15 @@ discard block |
||
| 706 | 706 | * - false : La balise est interdite car le serveur est distant |
| 707 | 707 | **/ |
| 708 | 708 | function balise_distante_interdite($p) { |
| 709 | - $nom = $p->id_boucle; |
|
| 709 | + $nom = $p->id_boucle; |
|
| 710 | 710 | |
| 711 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 712 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 711 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 712 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 713 | 713 | |
| 714 | - return false; |
|
| 715 | - } |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - return true; |
|
| 717 | + return true; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | |
@@ -725,84 +725,84 @@ discard block |
||
| 725 | 725 | // https://code.spip.net/@champs_traitements |
| 726 | 726 | function champs_traitements($p) { |
| 727 | 727 | |
| 728 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 729 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 730 | - } else { |
|
| 731 | - // quand on utilise un traitement catch-all * |
|
| 732 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 733 | - // leur propre securite |
|
| 734 | - if (!$p->balise_calculee) { |
|
| 735 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 736 | - } else { |
|
| 737 | - $ps = false; |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - if (is_array($ps)) { |
|
| 742 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 743 | - $idb = index_boucle($p); |
|
| 744 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 745 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 746 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 750 | - $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 751 | - $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 752 | - |
|
| 753 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 754 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 755 | - $type_alias = $type_requete; |
|
| 756 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 757 | - } else { |
|
| 758 | - $type_alias = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 762 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 763 | - $ps = $ps[$table_sql]; |
|
| 764 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 765 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 766 | - $ps = $ps[$type_requete]; |
|
| 767 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 768 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 769 | - $ps = $ps[$type_alias]; |
|
| 770 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 771 | - elseif (isset($ps[0])) { |
|
| 772 | - $ps = $ps[0]; |
|
| 773 | - } else { |
|
| 774 | - $ps = false; |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - if (!$ps) { |
|
| 779 | - return $p->code; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 783 | - // ou si in INCLURE contient {doublons} |
|
| 784 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 785 | - // dans les filtres propre() ou typo() |
|
| 786 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 787 | - |
|
| 788 | - if ( |
|
| 789 | - isset($p->descr['documents']) |
|
| 790 | - and |
|
| 791 | - $p->descr['documents'] |
|
| 792 | - and ( |
|
| 793 | - (strpos($ps, 'propre') !== false) |
|
| 794 | - or |
|
| 795 | - (strpos($ps, 'typo') !== false) |
|
| 796 | - ) |
|
| 797 | - ) { |
|
| 798 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 802 | - // dans la declaration des traitements des champs sensibles |
|
| 803 | - |
|
| 804 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 805 | - return str_replace('%s', $p->code, $ps); |
|
| 728 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 729 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 730 | + } else { |
|
| 731 | + // quand on utilise un traitement catch-all * |
|
| 732 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 733 | + // leur propre securite |
|
| 734 | + if (!$p->balise_calculee) { |
|
| 735 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 736 | + } else { |
|
| 737 | + $ps = false; |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + if (is_array($ps)) { |
|
| 742 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 743 | + $idb = index_boucle($p); |
|
| 744 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 745 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 746 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 750 | + $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 751 | + $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 752 | + |
|
| 753 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 754 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 755 | + $type_alias = $type_requete; |
|
| 756 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 757 | + } else { |
|
| 758 | + $type_alias = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 762 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 763 | + $ps = $ps[$table_sql]; |
|
| 764 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 765 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 766 | + $ps = $ps[$type_requete]; |
|
| 767 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 768 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 769 | + $ps = $ps[$type_alias]; |
|
| 770 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 771 | + elseif (isset($ps[0])) { |
|
| 772 | + $ps = $ps[0]; |
|
| 773 | + } else { |
|
| 774 | + $ps = false; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + if (!$ps) { |
|
| 779 | + return $p->code; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 783 | + // ou si in INCLURE contient {doublons} |
|
| 784 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 785 | + // dans les filtres propre() ou typo() |
|
| 786 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 787 | + |
|
| 788 | + if ( |
|
| 789 | + isset($p->descr['documents']) |
|
| 790 | + and |
|
| 791 | + $p->descr['documents'] |
|
| 792 | + and ( |
|
| 793 | + (strpos($ps, 'propre') !== false) |
|
| 794 | + or |
|
| 795 | + (strpos($ps, 'typo') !== false) |
|
| 796 | + ) |
|
| 797 | + ) { |
|
| 798 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 802 | + // dans la declaration des traitements des champs sensibles |
|
| 803 | + |
|
| 804 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 805 | + return str_replace('%s', $p->code, $ps); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -815,112 +815,112 @@ discard block |
||
| 815 | 815 | // https://code.spip.net/@applique_filtres |
| 816 | 816 | function applique_filtres($p) { |
| 817 | 817 | |
| 818 | - // Traitements standards (cf. supra) |
|
| 819 | - if ($p->etoile == '') { |
|
| 820 | - $code = champs_traitements($p); |
|
| 821 | - } else { |
|
| 822 | - $code = $p->code; |
|
| 823 | - } |
|
| 818 | + // Traitements standards (cf. supra) |
|
| 819 | + if ($p->etoile == '') { |
|
| 820 | + $code = champs_traitements($p); |
|
| 821 | + } else { |
|
| 822 | + $code = $p->code; |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - // Appliquer les filtres perso |
|
| 826 | - if ($p->param) { |
|
| 827 | - $code = compose_filtres($p, $code); |
|
| 828 | - } |
|
| 825 | + // Appliquer les filtres perso |
|
| 826 | + if ($p->param) { |
|
| 827 | + $code = compose_filtres($p, $code); |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 831 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 832 | - if (isset($p->descr['session'])) { |
|
| 833 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 834 | - } |
|
| 830 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 831 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 832 | + if (isset($p->descr['session'])) { |
|
| 833 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 836 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 837 | 837 | |
| 838 | - return $code; |
|
| 838 | + return $code; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 842 | 842 | // https://code.spip.net/@compose_filtres |
| 843 | 843 | function compose_filtres(&$p, $code) { |
| 844 | 844 | |
| 845 | - $image_miette = false; |
|
| 846 | - foreach ($p->param as $filtre) { |
|
| 847 | - $fonc = array_shift($filtre); |
|
| 848 | - if (!$fonc) { |
|
| 849 | - continue; |
|
| 850 | - } // normalement qu'au premier tour. |
|
| 851 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 852 | - if ($image_miette and !$is_filtre_image) { |
|
| 853 | - // il faut graver maintenant car apres le filtre en cours |
|
| 854 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 855 | - $code = "filtrer('image_graver', $code)"; |
|
| 856 | - $image_miette = false; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - // recuperer les arguments du filtre, |
|
| 860 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 861 | - $countfiltre = count($filtre); |
|
| 862 | - if ($fonc !== '?') { |
|
| 863 | - $sep = ','; |
|
| 864 | - } else { |
|
| 865 | - $sep = ':'; |
|
| 866 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 867 | - if ($countfiltre != 2) { |
|
| 868 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 869 | - $countfiltre = 2; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 873 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 874 | - if ($logique) { |
|
| 875 | - $code = $logique; |
|
| 876 | - } else { |
|
| 877 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 878 | - if ($is_filtre_image) { |
|
| 879 | - $image_miette = true; |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 884 | - if ($image_miette) { |
|
| 885 | - $code = "filtrer('image_graver',$code)"; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - return $code; |
|
| 845 | + $image_miette = false; |
|
| 846 | + foreach ($p->param as $filtre) { |
|
| 847 | + $fonc = array_shift($filtre); |
|
| 848 | + if (!$fonc) { |
|
| 849 | + continue; |
|
| 850 | + } // normalement qu'au premier tour. |
|
| 851 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 852 | + if ($image_miette and !$is_filtre_image) { |
|
| 853 | + // il faut graver maintenant car apres le filtre en cours |
|
| 854 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 855 | + $code = "filtrer('image_graver', $code)"; |
|
| 856 | + $image_miette = false; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + // recuperer les arguments du filtre, |
|
| 860 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 861 | + $countfiltre = count($filtre); |
|
| 862 | + if ($fonc !== '?') { |
|
| 863 | + $sep = ','; |
|
| 864 | + } else { |
|
| 865 | + $sep = ':'; |
|
| 866 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 867 | + if ($countfiltre != 2) { |
|
| 868 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 869 | + $countfiltre = 2; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 873 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 874 | + if ($logique) { |
|
| 875 | + $code = $logique; |
|
| 876 | + } else { |
|
| 877 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 878 | + if ($is_filtre_image) { |
|
| 879 | + $image_miette = true; |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 884 | + if ($image_miette) { |
|
| 885 | + $code = "filtrer('image_graver',$code)"; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + return $code; |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 892 | 892 | // et comparateurs |
| 893 | 893 | function filtre_logique($fonc, $code, $arg) { |
| 894 | 894 | |
| 895 | - switch (true) { |
|
| 896 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 897 | - return "($code $fonc $arg)"; |
|
| 898 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 899 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 900 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 901 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 902 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 903 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 904 | - case ($fonc == 'sinon'): |
|
| 905 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 906 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 907 | - return "(($code) ?'' :' ')"; |
|
| 908 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 909 | - return "(($code) ?' ' :'')"; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - return ''; |
|
| 895 | + switch (true) { |
|
| 896 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 897 | + return "($code $fonc $arg)"; |
|
| 898 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 899 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 900 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 901 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 902 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 903 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 904 | + case ($fonc == 'sinon'): |
|
| 905 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 906 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 907 | + return "(($code) ?'' :' ')"; |
|
| 908 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 909 | + return "(($code) ?' ' :'')"; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + return ''; |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | // https://code.spip.net/@compose_filtres_args |
| 916 | 916 | function compose_filtres_args($p, $args, $sep) { |
| 917 | - $arglist = ''; |
|
| 918 | - foreach ($args as $arg) { |
|
| 919 | - $arglist .= $sep . |
|
| 920 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | - } |
|
| 917 | + $arglist = ''; |
|
| 918 | + foreach ($args as $arg) { |
|
| 919 | + $arglist .= $sep . |
|
| 920 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | - return $arglist; |
|
| 923 | + return $arglist; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -938,15 +938,15 @@ discard block |
||
| 938 | 938 | **/ |
| 939 | 939 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 940 | 940 | |
| 941 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | - if ($boucles[$idb]->externe) { |
|
| 943 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | - // on ignore le defaut fourni dans ce cas |
|
| 946 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | - } |
|
| 941 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | + if ($boucles[$idb]->externe) { |
|
| 943 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | + // on ignore le defaut fourni dans ce cas |
|
| 946 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | + } |
|
| 948 | 948 | |
| 949 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 949 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | // |
@@ -961,30 +961,30 @@ discard block |
||
| 961 | 961 | |
| 962 | 962 | // https://code.spip.net/@rindex_pile |
| 963 | 963 | function rindex_pile($p, $champ, $motif) { |
| 964 | - $n = 0; |
|
| 965 | - $b = $p->id_boucle; |
|
| 966 | - $p->code = ''; |
|
| 967 | - while ($b != '') { |
|
| 968 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 969 | - if ($critere->op == $motif) { |
|
| 970 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 971 | - "]['$champ']"; |
|
| 972 | - $b = ''; |
|
| 973 | - break 2; |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - $n++; |
|
| 977 | - $b = $p->boucles[$b]->id_parent; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 981 | - if (!$p->code) { |
|
| 982 | - $p->code = "''"; |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - $p->interdire_scripts = false; |
|
| 986 | - |
|
| 987 | - return $p; |
|
| 964 | + $n = 0; |
|
| 965 | + $b = $p->id_boucle; |
|
| 966 | + $p->code = ''; |
|
| 967 | + while ($b != '') { |
|
| 968 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 969 | + if ($critere->op == $motif) { |
|
| 970 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 971 | + "]['$champ']"; |
|
| 972 | + $b = ''; |
|
| 973 | + break 2; |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + $n++; |
|
| 977 | + $b = $p->boucles[$b]->id_parent; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 981 | + if (!$p->code) { |
|
| 982 | + $p->code = "''"; |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + $p->interdire_scripts = false; |
|
| 986 | + |
|
| 987 | + return $p; |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 995 | 995 | */ |
| 996 | 996 | function zbug_presenter_champ($p, $champ = '') { |
| 997 | - $balise = $champ ? $champ : $p->nom_champ; |
|
| 998 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 999 | - return "#{$explicite}{$balise}"; |
|
| 997 | + $balise = $champ ? $champ : $p->nom_champ; |
|
| 998 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 999 | + return "#{$explicite}{$balise}"; |
|
| 1000 | 1000 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $select = true |
| 125 | 125 | ) { |
| 126 | 126 | if (!is_string($defaut)) { |
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 127 | + $defaut = '($Pile[0][\''.strtolower($nom_champ).'\'] ?? null)'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $idb_origine = $idb; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | // renseigner la boucle source de ce champ pour les traitements |
| 159 | 159 | $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 160 | + $champ = '$Pile[$SP'.($i ? "-$i" : '').'][\''.$c.'\']'; |
|
| 161 | 161 | if (!$joker) { |
| 162 | 162 | return index_compose($conditionnel, $champ); |
| 163 | 163 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | 199 | while ($c = array_pop($conditionnel)) { |
| 200 | 200 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 201 | - $defaut = "($c:(" . ($defaut ? $defaut : "''") . '))'; |
|
| 201 | + $defaut = "($c:(".($defaut ? $defaut : "''").'))'; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return $defaut; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if (!$r) { |
| 246 | 246 | $joker = false; // indiquer a l'appelant |
| 247 | 247 | # continuer pour chercher l'erreur suivante |
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 248 | + return ["'#".$r.':'.$nom_champ."'", '']; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $desc = $boucles[$idb]->show; |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 349 | 349 | } |
| 350 | 350 | if ($t == null) { |
| 351 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 351 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | 353 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 354 | 354 | if (!$j) { |
| 355 | 355 | return ['', '']; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | $l = (preg_split('/\s*,\s*/', $k)); |
| 362 | 362 | $k = $desc['key']['PRIMARY KEY']; |
| 363 | 363 | if (!in_array($k, $l)) { |
| 364 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 364 | + spip_log("jointure impossible $e ".join(',', $l)); |
|
| 365 | 365 | |
| 366 | 366 | return ['', '']; |
| 367 | 367 | } |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | // demander a SQL de gerer le synonyme |
| 378 | 378 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 379 | 379 | if ($excep != $nom_champ) { |
| 380 | - $excep .= ' AS ' . $nom_champ; |
|
| 380 | + $excep .= ' AS '.$nom_champ; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | return ["$t.$excep", $nom_champ]; |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | join(',', $collecte), |
| 612 | 612 | ($collecte ? $param : substr($param, 1)), # virer la virgule |
| 613 | 613 | memoriser_contexte_compil($p), |
| 614 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 614 | + (!$supp ? '' : (', '.join(',', $supp))) |
|
| 615 | 615 | ); |
| 616 | 616 | |
| 617 | 617 | $p->interdire_scripts = false; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | $nom = $p->id_boucle; |
| 710 | 710 | |
| 711 | 711 | if ($nom and trouver_nom_serveur_distant($p)) { |
| 712 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 712 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 713 | 713 | |
| 714 | 714 | return false; |
| 715 | 715 | } |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | (strpos($ps, 'typo') !== false) |
| 796 | 796 | ) |
| 797 | 797 | ) { |
| 798 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 798 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | // La protection des champs par |safehtml est assuree par les extensions |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | function compose_filtres_args($p, $args, $sep) { |
| 917 | 917 | $arglist = ''; |
| 918 | 918 | foreach ($args as $arg) { |
| 919 | - $arglist .= $sep . |
|
| 919 | + $arglist .= $sep. |
|
| 920 | 920 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 921 | 921 | } |
| 922 | 922 | |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | while ($b != '') { |
| 968 | 968 | foreach ($p->boucles[$b]->criteres as $critere) { |
| 969 | 969 | if ($critere->op == $motif) { |
| 970 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 970 | + $p->code = '$Pile[$SP'.(($n == 0) ? '' : "-$n"). |
|
| 971 | 971 | "]['$champ']"; |
| 972 | 972 | $b = ''; |
| 973 | 973 | break 2; |
@@ -995,6 +995,6 @@ discard block |
||
| 995 | 995 | */ |
| 996 | 996 | function zbug_presenter_champ($p, $champ = '') { |
| 997 | 997 | $balise = $champ ? $champ : $p->nom_champ; |
| 998 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 998 | + $explicite = $p->nom_boucle ? $p->nom_boucle.':' : ''; |
|
| 999 | 999 | return "#{$explicite}{$balise}"; |
| 1000 | 1000 | } |
@@ -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 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,58 +256,58 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ( |
|
| 305 | - $boucle->primary |
|
| 306 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 307 | - and !in_array($t, $boucle->select) |
|
| 308 | - ) { |
|
| 309 | - $boucle->select[] = $t; |
|
| 310 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ( |
|
| 305 | + $boucle->primary |
|
| 306 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 307 | + and !in_array($t, $boucle->select) |
|
| 308 | + ) { |
|
| 309 | + $boucle->select[] = $t; |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -329,24 +329,24 @@ discard block |
||
| 329 | 329 | **/ |
| 330 | 330 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 331 | 331 | |
| 332 | - $boucle = &$boucles[$idb]; |
|
| 332 | + $boucle = &$boucles[$idb]; |
|
| 333 | 333 | |
| 334 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 335 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 334 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 335 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 336 | 336 | |
| 337 | - return; |
|
| 338 | - } |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - if (isset($crit->param[0])) { |
|
| 341 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 342 | - } else { |
|
| 343 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 344 | - } |
|
| 340 | + if (isset($crit->param[0])) { |
|
| 341 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 342 | + } else { |
|
| 343 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 347 | - $boucle->hash .= ' |
|
| 346 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 347 | + $boucle->hash .= ' |
|
| 348 | 348 | // RECHERCHE' |
| 349 | - . ($crit->cond ? ' |
|
| 349 | + . ($crit->cond ? ' |
|
| 350 | 350 | if (!strlen(' . $quoi . ')){ |
| 351 | 351 | list($rech_select, $rech_where) = array("0 as points",""); |
| 352 | 352 | } else' : '') . ' |
@@ -357,21 +357,21 @@ discard block |
||
| 357 | 357 | '; |
| 358 | 358 | |
| 359 | 359 | |
| 360 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 361 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 362 | - $boucle->select[] = $t; |
|
| 363 | - } # pour postgres, neuneu ici |
|
| 364 | - // jointure uniquement sur le serveur principal |
|
| 365 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 366 | - if (!$boucle->sql_serveur) { |
|
| 367 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 368 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 369 | - } |
|
| 370 | - $boucle->select[] = '$rech_select'; |
|
| 371 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 372 | - |
|
| 373 | - // et la recherche trouve |
|
| 374 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 360 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 361 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 362 | + $boucle->select[] = $t; |
|
| 363 | + } # pour postgres, neuneu ici |
|
| 364 | + // jointure uniquement sur le serveur principal |
|
| 365 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 366 | + if (!$boucle->sql_serveur) { |
|
| 367 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 368 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 369 | + } |
|
| 370 | + $boucle->select[] = '$rech_select'; |
|
| 371 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 372 | + |
|
| 373 | + // et la recherche trouve |
|
| 374 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * @return void |
| 389 | 389 | **/ |
| 390 | 390 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 391 | - $boucle = &$boucles[$idb]; |
|
| 392 | - $prim = $boucle->primary; |
|
| 393 | - $table = $boucle->id_table; |
|
| 394 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 395 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 396 | - $boucle->where[] = |
|
| 397 | - [ |
|
| 398 | - "'OR'", |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'='", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.$prim'", $dprim] |
|
| 403 | - ], |
|
| 404 | - [ |
|
| 405 | - "'AND'", |
|
| 406 | - ["'>'", "'$table.id_trad'", 0], |
|
| 407 | - ["'='", "'$table.id_trad'", $arg] |
|
| 408 | - ] |
|
| 409 | - ]; |
|
| 391 | + $boucle = &$boucles[$idb]; |
|
| 392 | + $prim = $boucle->primary; |
|
| 393 | + $table = $boucle->id_table; |
|
| 394 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 395 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 396 | + $boucle->where[] = |
|
| 397 | + [ |
|
| 398 | + "'OR'", |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'='", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.$prim'", $dprim] |
|
| 403 | + ], |
|
| 404 | + [ |
|
| 405 | + "'AND'", |
|
| 406 | + ["'>'", "'$table.id_trad'", 0], |
|
| 407 | + ["'='", "'$table.id_trad'", $arg] |
|
| 408 | + ] |
|
| 409 | + ]; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -424,17 +424,17 @@ discard block |
||
| 424 | 424 | * @return void |
| 425 | 425 | **/ |
| 426 | 426 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 427 | - $boucle = &$boucles[$idb]; |
|
| 428 | - $prim = $boucle->primary; |
|
| 429 | - $table = $boucle->id_table; |
|
| 430 | - |
|
| 431 | - $c = |
|
| 432 | - [ |
|
| 433 | - "'OR'", |
|
| 434 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 435 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 436 | - ]; |
|
| 437 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 427 | + $boucle = &$boucles[$idb]; |
|
| 428 | + $prim = $boucle->primary; |
|
| 429 | + $table = $boucle->id_table; |
|
| 430 | + |
|
| 431 | + $c = |
|
| 432 | + [ |
|
| 433 | + "'OR'", |
|
| 434 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 435 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 436 | + ]; |
|
| 437 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -451,19 +451,19 @@ discard block |
||
| 451 | 451 | **/ |
| 452 | 452 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 453 | 453 | |
| 454 | - $boucle = &$boucles[$idb]; |
|
| 455 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 456 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 457 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 458 | - 'id_parent'; |
|
| 459 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 460 | - |
|
| 461 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 462 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 466 | - } |
|
| 454 | + $boucle = &$boucles[$idb]; |
|
| 455 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 456 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 457 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 458 | + 'id_parent'; |
|
| 459 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 460 | + |
|
| 461 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 462 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = 'id_rubrique'; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = 'id_rubrique'; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @return void |
| 615 | 615 | **/ |
| 616 | 616 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 617 | - $boucles[$idb]->group = []; |
|
| 617 | + $boucles[$idb]->group = []; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -651,45 +651,45 @@ discard block |
||
| 651 | 651 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 652 | 652 | */ |
| 653 | 653 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 654 | - if (isset($crit->param[0])) { |
|
| 655 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 656 | - $boucle = $boucles[$idb]; |
|
| 657 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 658 | - $n = count($boucle->order); |
|
| 659 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 660 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 661 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 662 | - if ( |
|
| 663 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 664 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 665 | - ) { |
|
| 666 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 667 | - } else { |
|
| 668 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } else { |
|
| 672 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 673 | - } |
|
| 654 | + if (isset($crit->param[0])) { |
|
| 655 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 656 | + $boucle = $boucles[$idb]; |
|
| 657 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 658 | + $n = count($boucle->order); |
|
| 659 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 660 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 661 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 662 | + if ( |
|
| 663 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 664 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 665 | + ) { |
|
| 666 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 667 | + } else { |
|
| 668 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } else { |
|
| 672 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 677 | 677 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 678 | - $boucle = $boucles[$idb]; |
|
| 679 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 680 | - $var = '$champs_' . $idb; |
|
| 681 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 682 | - if (!$desc) { |
|
| 683 | - $desc = $boucle->show['field']; |
|
| 684 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 685 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 686 | - } |
|
| 687 | - if ($desc) { |
|
| 688 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 689 | - } |
|
| 690 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 691 | - |
|
| 692 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 678 | + $boucle = $boucles[$idb]; |
|
| 679 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 680 | + $var = '$champs_' . $idb; |
|
| 681 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 682 | + if (!$desc) { |
|
| 683 | + $desc = $boucle->show['field']; |
|
| 684 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 685 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 686 | + } |
|
| 687 | + if ($desc) { |
|
| 688 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 689 | + } |
|
| 690 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 691 | + |
|
| 692 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 729 | 729 | */ |
| 730 | 730 | function critere_par_dist($idb, &$boucles, $crit) { |
| 731 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 731 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -750,93 +750,93 @@ discard block |
||
| 750 | 750 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 751 | 751 | */ |
| 752 | 752 | function critere_parinverse($idb, &$boucles, $crit) { |
| 753 | - $boucle = &$boucles[$idb]; |
|
| 754 | - |
|
| 755 | - $sens = $collecte = ''; |
|
| 756 | - if ($crit->not) { |
|
| 757 | - $sens = " . ' DESC'"; |
|
| 758 | - } |
|
| 759 | - if (isset($boucle->modificateur['collate'])) { |
|
| 760 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - // Pour chaque paramètre du critère |
|
| 764 | - foreach ($crit->param as $tri) { |
|
| 765 | - $order = $fct = ''; |
|
| 766 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 767 | - if ($tri[0]->type != 'texte') { |
|
| 768 | - // calculer le order dynamique qui verifie les champs |
|
| 769 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 770 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 771 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 772 | - } |
|
| 773 | - // tris textuels {par titre} |
|
| 774 | - else { |
|
| 775 | - $par = array_shift($tri); |
|
| 776 | - $par = $par->texte; |
|
| 777 | - |
|
| 778 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 779 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 780 | - $expression = trim($m[1]); |
|
| 781 | - $champ = trim($m[2]); |
|
| 782 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 783 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 784 | - } else { |
|
| 785 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 789 | - } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 790 | - // {par FONCTION(champ)} |
|
| 791 | - if (count($match) > 2) { |
|
| 792 | - $par = substr($match[2], 1, -1); |
|
| 793 | - $fct = $match[1]; |
|
| 794 | - } |
|
| 795 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 796 | - if ($par == 'hasard') { |
|
| 797 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 798 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 799 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 800 | - } else { |
|
| 801 | - // cas général {par champ}, {par table.champ}, ... |
|
| 802 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - // on ne sait pas traiter… |
|
| 807 | - else { |
|
| 808 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 812 | - if (is_array($order)) { |
|
| 813 | - return $order; |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 818 | - $t = $m[1]; |
|
| 819 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 820 | - $boucle->select[] = $t; |
|
| 821 | - } |
|
| 822 | - } else { |
|
| 823 | - $sens = ''; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - if ($fct) { |
|
| 827 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 828 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 829 | - } else { |
|
| 830 | - $order = "'$fct(' . $order . ')'"; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - $t = $order . $collecte . $sens; |
|
| 834 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 835 | - $t = $r[1] . $r[2]; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - $boucle->order[] = $t; |
|
| 839 | - } |
|
| 753 | + $boucle = &$boucles[$idb]; |
|
| 754 | + |
|
| 755 | + $sens = $collecte = ''; |
|
| 756 | + if ($crit->not) { |
|
| 757 | + $sens = " . ' DESC'"; |
|
| 758 | + } |
|
| 759 | + if (isset($boucle->modificateur['collate'])) { |
|
| 760 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + // Pour chaque paramètre du critère |
|
| 764 | + foreach ($crit->param as $tri) { |
|
| 765 | + $order = $fct = ''; |
|
| 766 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 767 | + if ($tri[0]->type != 'texte') { |
|
| 768 | + // calculer le order dynamique qui verifie les champs |
|
| 769 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 770 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 771 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 772 | + } |
|
| 773 | + // tris textuels {par titre} |
|
| 774 | + else { |
|
| 775 | + $par = array_shift($tri); |
|
| 776 | + $par = $par->texte; |
|
| 777 | + |
|
| 778 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 779 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 780 | + $expression = trim($m[1]); |
|
| 781 | + $champ = trim($m[2]); |
|
| 782 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 783 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 784 | + } else { |
|
| 785 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 789 | + } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 790 | + // {par FONCTION(champ)} |
|
| 791 | + if (count($match) > 2) { |
|
| 792 | + $par = substr($match[2], 1, -1); |
|
| 793 | + $fct = $match[1]; |
|
| 794 | + } |
|
| 795 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 796 | + if ($par == 'hasard') { |
|
| 797 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 798 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 799 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 800 | + } else { |
|
| 801 | + // cas général {par champ}, {par table.champ}, ... |
|
| 802 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + // on ne sait pas traiter… |
|
| 807 | + else { |
|
| 808 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 812 | + if (is_array($order)) { |
|
| 813 | + return $order; |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 818 | + $t = $m[1]; |
|
| 819 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 820 | + $boucle->select[] = $t; |
|
| 821 | + } |
|
| 822 | + } else { |
|
| 823 | + $sens = ''; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + if ($fct) { |
|
| 827 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 828 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 829 | + } else { |
|
| 830 | + $order = "'$fct(' . $order . ')'"; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + $t = $order . $collecte . $sens; |
|
| 834 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 835 | + $t = $r[1] . $r[2]; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + $boucle->order[] = $t; |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -850,13 +850,13 @@ discard block |
||
| 850 | 850 | * @return string Clause pour le Order by |
| 851 | 851 | */ |
| 852 | 852 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 853 | - $boucle = &$boucles[$idb]; |
|
| 854 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 855 | - $parha = 'rand() AS hasard'; |
|
| 856 | - if (!in_array($parha, $boucle->select)) { |
|
| 857 | - $boucle->select[] = $parha; |
|
| 858 | - } |
|
| 859 | - return "'hasard'"; |
|
| 853 | + $boucle = &$boucles[$idb]; |
|
| 854 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 855 | + $parha = 'rand() AS hasard'; |
|
| 856 | + if (!in_array($parha, $boucle->select)) { |
|
| 857 | + $boucle->select[] = $parha; |
|
| 858 | + } |
|
| 859 | + return "'hasard'"; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -880,24 +880,24 @@ discard block |
||
| 880 | 880 | * @return string Clause pour le Order by |
| 881 | 881 | */ |
| 882 | 882 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 883 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 884 | - if (is_array($_champ)) { |
|
| 885 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 886 | - } |
|
| 887 | - $boucle = &$boucles[$idb]; |
|
| 888 | - $texte = '0+' . $_champ; |
|
| 889 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 890 | - if ($suite !== "''") { |
|
| 891 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 892 | - } |
|
| 893 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 894 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 895 | - |
|
| 896 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 897 | - $orderassinum = trim($orderassinum, "'"); |
|
| 898 | - |
|
| 899 | - $order = "'$orderassinum, $asnum'"; |
|
| 900 | - return $order; |
|
| 883 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 884 | + if (is_array($_champ)) { |
|
| 885 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 886 | + } |
|
| 887 | + $boucle = &$boucles[$idb]; |
|
| 888 | + $texte = '0+' . $_champ; |
|
| 889 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 890 | + if ($suite !== "''") { |
|
| 891 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 892 | + } |
|
| 893 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 894 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 895 | + |
|
| 896 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 897 | + $orderassinum = trim($orderassinum, "'"); |
|
| 898 | + |
|
| 899 | + $order = "'$orderassinum, $asnum'"; |
|
| 900 | + return $order; |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -918,35 +918,35 @@ discard block |
||
| 918 | 918 | * @return string Clause pour le Order by |
| 919 | 919 | */ |
| 920 | 920 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 921 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 922 | - if (is_array($_champ)) { |
|
| 923 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 924 | - } |
|
| 925 | - $boucle = &$boucles[$idb]; |
|
| 926 | - $texte = '0+' . $_champ; |
|
| 927 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 928 | - if ($suite !== "''") { |
|
| 929 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - $as = false; |
|
| 933 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 934 | - foreach ($boucle->select as $s) { |
|
| 935 | - if (strpos($s, $select) === 0) { |
|
| 936 | - $as = trim(substr($s, strlen($select))); |
|
| 937 | - if (!preg_match(',\W,', $as)) { |
|
| 938 | - break; |
|
| 939 | - } |
|
| 940 | - $as = false; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - if (!$as) { |
|
| 945 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 946 | - $boucle->select[] = $select . $as; |
|
| 947 | - } |
|
| 948 | - $order = "'$as'"; |
|
| 949 | - return $order; |
|
| 921 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 922 | + if (is_array($_champ)) { |
|
| 923 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 924 | + } |
|
| 925 | + $boucle = &$boucles[$idb]; |
|
| 926 | + $texte = '0+' . $_champ; |
|
| 927 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 928 | + if ($suite !== "''") { |
|
| 929 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + $as = false; |
|
| 933 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 934 | + foreach ($boucle->select as $s) { |
|
| 935 | + if (strpos($s, $select) === 0) { |
|
| 936 | + $as = trim(substr($s, strlen($select))); |
|
| 937 | + if (!preg_match(',\W,', $as)) { |
|
| 938 | + break; |
|
| 939 | + } |
|
| 940 | + $as = false; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + if (!$as) { |
|
| 945 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 946 | + $boucle->select[] = $select . $as; |
|
| 947 | + } |
|
| 948 | + $order = "'$as'"; |
|
| 949 | + return $order; |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | |
@@ -966,14 +966,14 @@ discard block |
||
| 966 | 966 | * @return string Clause pour le Order by |
| 967 | 967 | */ |
| 968 | 968 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 969 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 970 | - if (is_array($_champ)) { |
|
| 971 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 972 | - } |
|
| 973 | - $boucle = &$boucles[$idb]; |
|
| 974 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 975 | - $order = "'multi'"; |
|
| 976 | - return $order; |
|
| 969 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 970 | + if (is_array($_champ)) { |
|
| 971 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 972 | + } |
|
| 973 | + $boucle = &$boucles[$idb]; |
|
| 974 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 975 | + $order = "'multi'"; |
|
| 976 | + return $order; |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | /** |
@@ -992,56 +992,56 @@ discard block |
||
| 992 | 992 | * @return array|string |
| 993 | 993 | */ |
| 994 | 994 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 995 | - $boucle = &$boucles[$idb]; |
|
| 996 | - $desc = $boucle->show; |
|
| 997 | - |
|
| 998 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 999 | - if (isset($desc['field'][$par])) { |
|
| 1000 | - $par = $boucle->id_table . '.' . $par; |
|
| 1001 | - } |
|
| 1002 | - // le champ est peut être une jointure |
|
| 1003 | - else { |
|
| 1004 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1005 | - $champ = $par; |
|
| 1006 | - |
|
| 1007 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1008 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1009 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1010 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1011 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1012 | - list(, $table, $champ) = $r; |
|
| 1013 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1014 | - $table = table_objet_sql($table); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1018 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1019 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1020 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1021 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1022 | - } elseif ( |
|
| 1023 | - $boucle->jointures_explicites |
|
| 1024 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1025 | - ) { |
|
| 1026 | - $par = $alias . '.' . $champ; |
|
| 1027 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1028 | - $par = $alias . '.' . $champ; |
|
| 1029 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1030 | - } elseif ( |
|
| 1031 | - $table_alias |
|
| 1032 | - and isset($boucle->from[$table_alias]) |
|
| 1033 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1034 | - ) { |
|
| 1035 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1036 | - } elseif ($table) { |
|
| 1037 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1038 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1039 | - } else { |
|
| 1040 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - return $raw ? $par : "'$par'"; |
|
| 995 | + $boucle = &$boucles[$idb]; |
|
| 996 | + $desc = $boucle->show; |
|
| 997 | + |
|
| 998 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 999 | + if (isset($desc['field'][$par])) { |
|
| 1000 | + $par = $boucle->id_table . '.' . $par; |
|
| 1001 | + } |
|
| 1002 | + // le champ est peut être une jointure |
|
| 1003 | + else { |
|
| 1004 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1005 | + $champ = $par; |
|
| 1006 | + |
|
| 1007 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1008 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1009 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1010 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1011 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1012 | + list(, $table, $champ) = $r; |
|
| 1013 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1014 | + $table = table_objet_sql($table); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1018 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1019 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1020 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1021 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1022 | + } elseif ( |
|
| 1023 | + $boucle->jointures_explicites |
|
| 1024 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1025 | + ) { |
|
| 1026 | + $par = $alias . '.' . $champ; |
|
| 1027 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1028 | + $par = $alias . '.' . $champ; |
|
| 1029 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1030 | + } elseif ( |
|
| 1031 | + $table_alias |
|
| 1032 | + and isset($boucle->from[$table_alias]) |
|
| 1033 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1034 | + ) { |
|
| 1035 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1036 | + } elseif ($table) { |
|
| 1037 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1038 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1039 | + } else { |
|
| 1040 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + return $raw ? $par : "'$par'"; |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
@@ -1055,11 +1055,11 @@ discard block |
||
| 1055 | 1055 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1056 | 1056 | */ |
| 1057 | 1057 | function critere_par_joint($table, $champ, &$boucle) { |
| 1058 | - $t = array_search($table, $boucle->from); |
|
| 1059 | - if (!$t) { |
|
| 1060 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1061 | - } |
|
| 1062 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1058 | + $t = array_search($table, $boucle->from); |
|
| 1059 | + if (!$t) { |
|
| 1060 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1061 | + } |
|
| 1062 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /** |
@@ -1084,33 +1084,33 @@ discard block |
||
| 1084 | 1084 | */ |
| 1085 | 1085 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1086 | 1086 | |
| 1087 | - $boucle = &$boucles[$idb]; |
|
| 1088 | - // Classement par ordre inverse |
|
| 1089 | - if ($crit->not) { |
|
| 1090 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1091 | - } else { |
|
| 1092 | - $order = "' DESC'"; |
|
| 1093 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1094 | - if (isset($crit->param[0])) { |
|
| 1095 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1096 | - $order = "(($critere)?' DESC':'')"; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - $n = count($boucle->order); |
|
| 1100 | - if (!$n) { |
|
| 1101 | - if (isset($boucle->default_order[0])) { |
|
| 1102 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1103 | - } else { |
|
| 1104 | - $boucle->default_order[] = ' DESC'; |
|
| 1105 | - } |
|
| 1106 | - } else { |
|
| 1107 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1108 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1109 | - $t = $r[1] . $r[2]; |
|
| 1110 | - } |
|
| 1111 | - $boucle->order[$n - 1] = $t; |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1087 | + $boucle = &$boucles[$idb]; |
|
| 1088 | + // Classement par ordre inverse |
|
| 1089 | + if ($crit->not) { |
|
| 1090 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1091 | + } else { |
|
| 1092 | + $order = "' DESC'"; |
|
| 1093 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1094 | + if (isset($crit->param[0])) { |
|
| 1095 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1096 | + $order = "(($critere)?' DESC':'')"; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + $n = count($boucle->order); |
|
| 1100 | + if (!$n) { |
|
| 1101 | + if (isset($boucle->default_order[0])) { |
|
| 1102 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1103 | + } else { |
|
| 1104 | + $boucle->default_order[] = ' DESC'; |
|
| 1105 | + } |
|
| 1106 | + } else { |
|
| 1107 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1108 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1109 | + $t = $r[1] . $r[2]; |
|
| 1110 | + } |
|
| 1111 | + $boucle->order[$n - 1] = $t; |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | /** |
@@ -1121,138 +1121,138 @@ discard block |
||
| 1121 | 1121 | * @return array|string |
| 1122 | 1122 | */ |
| 1123 | 1123 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1124 | - $boucle = &$boucles[$idb]; |
|
| 1124 | + $boucle = &$boucles[$idb]; |
|
| 1125 | 1125 | |
| 1126 | - $sens = $collecte = ''; |
|
| 1127 | - if ($crit->not) { |
|
| 1128 | - $sens = " . ' DESC'"; |
|
| 1129 | - } |
|
| 1126 | + $sens = $collecte = ''; |
|
| 1127 | + if ($crit->not) { |
|
| 1128 | + $sens = " . ' DESC'"; |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - $crit2 = clone $crit; |
|
| 1132 | - $crit2->not = false; |
|
| 1133 | - $crit2->param = [reset($crit->param)]; |
|
| 1134 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1131 | + $crit2 = clone $crit; |
|
| 1132 | + $crit2->not = false; |
|
| 1133 | + $crit2->param = [reset($crit->param)]; |
|
| 1134 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1135 | 1135 | |
| 1136 | - // erreur ? |
|
| 1137 | - if (is_array($res)) { |
|
| 1138 | - return $res; |
|
| 1139 | - } |
|
| 1136 | + // erreur ? |
|
| 1137 | + if (is_array($res)) { |
|
| 1138 | + return $res; |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | - $_order = array_pop($boucle->order); |
|
| 1141 | + $_order = array_pop($boucle->order); |
|
| 1142 | 1142 | |
| 1143 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1144 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1144 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | |
| 1148 | 1148 | // https://code.spip.net/@critere_agenda_dist |
| 1149 | 1149 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1150 | - $params = $crit->param; |
|
| 1151 | - |
|
| 1152 | - if (count($params) < 1) { |
|
| 1153 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - $boucle = &$boucles[$idb]; |
|
| 1157 | - $parent = $boucle->id_parent; |
|
| 1158 | - $fields = $boucle->show['field']; |
|
| 1159 | - |
|
| 1160 | - $date = array_shift($params); |
|
| 1161 | - $type = array_shift($params); |
|
| 1162 | - |
|
| 1163 | - // la valeur $type doit etre connue a la compilation |
|
| 1164 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1165 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1166 | - |
|
| 1167 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1168 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1169 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1170 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1171 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1172 | - $date = $date[0]->texte; |
|
| 1173 | - if (!isset($fields[$date])) { |
|
| 1174 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1175 | - } |
|
| 1176 | - } else { |
|
| 1177 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1178 | - $noms = array_keys($fields); |
|
| 1179 | - $defaut = $noms[0]; |
|
| 1180 | - $noms = join(' ', $noms); |
|
| 1181 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1182 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1183 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1184 | - } |
|
| 1185 | - $annee = $params ? array_shift($params) : ''; |
|
| 1186 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1187 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1188 | - ') ? $x : date("Y"))'; |
|
| 1189 | - |
|
| 1190 | - $mois = $params ? array_shift($params) : ''; |
|
| 1191 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1192 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1193 | - ') ? $x : date("m"))'; |
|
| 1194 | - |
|
| 1195 | - $jour = $params ? array_shift($params) : ''; |
|
| 1196 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1197 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1198 | - ') ? $x : date("d"))'; |
|
| 1199 | - |
|
| 1200 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1201 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1202 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1203 | - ') ? $x : date("Y"))'; |
|
| 1204 | - |
|
| 1205 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1206 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1207 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1208 | - ') ? $x : date("m"))'; |
|
| 1209 | - |
|
| 1210 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1211 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1212 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1213 | - ') ? $x : date("d"))'; |
|
| 1214 | - |
|
| 1215 | - $date = $boucle->id_table . ".$date"; |
|
| 1216 | - |
|
| 1217 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1218 | - if ($type == 'jour') { |
|
| 1219 | - $boucle->where[] = [ |
|
| 1220 | - "'='", |
|
| 1221 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1222 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1223 | - ]; |
|
| 1224 | - } elseif ($type == 'mois') { |
|
| 1225 | - $boucle->where[] = [ |
|
| 1226 | - "'='", |
|
| 1227 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1228 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1229 | - ]; |
|
| 1230 | - } elseif ($type == 'semaine') { |
|
| 1231 | - $boucle->where[] = [ |
|
| 1232 | - "'AND'", |
|
| 1233 | - [ |
|
| 1234 | - "'>='", |
|
| 1235 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1236 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1237 | - ], |
|
| 1238 | - [ |
|
| 1239 | - "'<='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1242 | - ] |
|
| 1243 | - ]; |
|
| 1244 | - } elseif (count($crit->param) > 2) { |
|
| 1245 | - $boucle->where[] = [ |
|
| 1246 | - "'AND'", |
|
| 1247 | - [ |
|
| 1248 | - "'>='", |
|
| 1249 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1250 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1251 | - ], |
|
| 1252 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1253 | - ]; |
|
| 1254 | - } |
|
| 1255 | - // sinon on prend tout |
|
| 1150 | + $params = $crit->param; |
|
| 1151 | + |
|
| 1152 | + if (count($params) < 1) { |
|
| 1153 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + $boucle = &$boucles[$idb]; |
|
| 1157 | + $parent = $boucle->id_parent; |
|
| 1158 | + $fields = $boucle->show['field']; |
|
| 1159 | + |
|
| 1160 | + $date = array_shift($params); |
|
| 1161 | + $type = array_shift($params); |
|
| 1162 | + |
|
| 1163 | + // la valeur $type doit etre connue a la compilation |
|
| 1164 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1165 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1166 | + |
|
| 1167 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1168 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1169 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1170 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1171 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1172 | + $date = $date[0]->texte; |
|
| 1173 | + if (!isset($fields[$date])) { |
|
| 1174 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1175 | + } |
|
| 1176 | + } else { |
|
| 1177 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1178 | + $noms = array_keys($fields); |
|
| 1179 | + $defaut = $noms[0]; |
|
| 1180 | + $noms = join(' ', $noms); |
|
| 1181 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1182 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1183 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1184 | + } |
|
| 1185 | + $annee = $params ? array_shift($params) : ''; |
|
| 1186 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1187 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1188 | + ') ? $x : date("Y"))'; |
|
| 1189 | + |
|
| 1190 | + $mois = $params ? array_shift($params) : ''; |
|
| 1191 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1192 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1193 | + ') ? $x : date("m"))'; |
|
| 1194 | + |
|
| 1195 | + $jour = $params ? array_shift($params) : ''; |
|
| 1196 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1197 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1198 | + ') ? $x : date("d"))'; |
|
| 1199 | + |
|
| 1200 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1201 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1202 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1203 | + ') ? $x : date("Y"))'; |
|
| 1204 | + |
|
| 1205 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1206 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1207 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1208 | + ') ? $x : date("m"))'; |
|
| 1209 | + |
|
| 1210 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1211 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1212 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1213 | + ') ? $x : date("d"))'; |
|
| 1214 | + |
|
| 1215 | + $date = $boucle->id_table . ".$date"; |
|
| 1216 | + |
|
| 1217 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1218 | + if ($type == 'jour') { |
|
| 1219 | + $boucle->where[] = [ |
|
| 1220 | + "'='", |
|
| 1221 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1222 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1223 | + ]; |
|
| 1224 | + } elseif ($type == 'mois') { |
|
| 1225 | + $boucle->where[] = [ |
|
| 1226 | + "'='", |
|
| 1227 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1228 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1229 | + ]; |
|
| 1230 | + } elseif ($type == 'semaine') { |
|
| 1231 | + $boucle->where[] = [ |
|
| 1232 | + "'AND'", |
|
| 1233 | + [ |
|
| 1234 | + "'>='", |
|
| 1235 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1236 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1237 | + ], |
|
| 1238 | + [ |
|
| 1239 | + "'<='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1242 | + ] |
|
| 1243 | + ]; |
|
| 1244 | + } elseif (count($crit->param) > 2) { |
|
| 1245 | + $boucle->where[] = [ |
|
| 1246 | + "'AND'", |
|
| 1247 | + [ |
|
| 1248 | + "'>='", |
|
| 1249 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1250 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1251 | + ], |
|
| 1252 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1253 | + ]; |
|
| 1254 | + } |
|
| 1255 | + // sinon on prend tout |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
@@ -1277,33 +1277,33 @@ discard block |
||
| 1277 | 1277 | * @return void |
| 1278 | 1278 | **/ |
| 1279 | 1279 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1280 | - $boucle = &$boucles[$idb]; |
|
| 1281 | - $a1 = $crit->param[0]; |
|
| 1282 | - $a2 = $crit->param[1]; |
|
| 1283 | - $op = $crit->op; |
|
| 1284 | - |
|
| 1285 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1286 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1287 | - |
|
| 1288 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1289 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1290 | - } else { |
|
| 1291 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1292 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1293 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1294 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1295 | - $mode = (($op == '/') ? '/' : |
|
| 1296 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1297 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1298 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1299 | - $boucle->limit = |
|
| 1300 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1301 | - . ".','." |
|
| 1302 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1303 | - } else { |
|
| 1304 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1280 | + $boucle = &$boucles[$idb]; |
|
| 1281 | + $a1 = $crit->param[0]; |
|
| 1282 | + $a2 = $crit->param[1]; |
|
| 1283 | + $op = $crit->op; |
|
| 1284 | + |
|
| 1285 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1286 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1287 | + |
|
| 1288 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1289 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1290 | + } else { |
|
| 1291 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1292 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1293 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1294 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1295 | + $mode = (($op == '/') ? '/' : |
|
| 1296 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1297 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1298 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1299 | + $boucle->limit = |
|
| 1300 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1301 | + . ".','." |
|
| 1302 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1303 | + } else { |
|
| 1304 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | /** |
@@ -1331,63 +1331,63 @@ discard block |
||
| 1331 | 1331 | * @return void |
| 1332 | 1332 | **/ |
| 1333 | 1333 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1334 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1335 | - |
|
| 1336 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1337 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1338 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1339 | - // {1/3} |
|
| 1340 | - if ($op1 == '/') { |
|
| 1341 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1342 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1343 | - "($total_parties ? $total_parties : 1)"; |
|
| 1344 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1345 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1346 | - } else { |
|
| 1347 | - // cas {n-1,x} |
|
| 1348 | - if ($op1 == '-') { |
|
| 1349 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - // cas {x,n-1} |
|
| 1353 | - if ($op2 == '-') { |
|
| 1354 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1355 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1356 | - ($total_parties . ' - 1')); |
|
| 1357 | - } else { |
|
| 1358 | - // {x,1} ou {pagination} |
|
| 1359 | - $fin = '$debut_boucle' |
|
| 1360 | - . (is_numeric($total_parties) ? |
|
| 1361 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1362 | - ('+' . $total_parties . ' - 1')); |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1366 | - if ($op1 == 'p') { |
|
| 1367 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1368 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1369 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - // Notes : |
|
| 1374 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1375 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1376 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1377 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1378 | - |
|
| 1379 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1380 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1381 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1382 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1383 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1384 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1385 | - . "\n\tif (\$debut_boucle>0" |
|
| 1386 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1387 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1388 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1389 | - |
|
| 1390 | - $boucles[$id_boucle]->partie = " |
|
| 1334 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1335 | + |
|
| 1336 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1337 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1338 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1339 | + // {1/3} |
|
| 1340 | + if ($op1 == '/') { |
|
| 1341 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1342 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1343 | + "($total_parties ? $total_parties : 1)"; |
|
| 1344 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1345 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1346 | + } else { |
|
| 1347 | + // cas {n-1,x} |
|
| 1348 | + if ($op1 == '-') { |
|
| 1349 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + // cas {x,n-1} |
|
| 1353 | + if ($op2 == '-') { |
|
| 1354 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1355 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1356 | + ($total_parties . ' - 1')); |
|
| 1357 | + } else { |
|
| 1358 | + // {x,1} ou {pagination} |
|
| 1359 | + $fin = '$debut_boucle' |
|
| 1360 | + . (is_numeric($total_parties) ? |
|
| 1361 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1362 | + ('+' . $total_parties . ' - 1')); |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1366 | + if ($op1 == 'p') { |
|
| 1367 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1368 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1369 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + // Notes : |
|
| 1374 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1375 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1376 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1377 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1378 | + |
|
| 1379 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1380 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1381 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1382 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1383 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1384 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1385 | + . "\n\tif (\$debut_boucle>0" |
|
| 1386 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1387 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1388 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1389 | + |
|
| 1390 | + $boucles[$id_boucle]->partie = " |
|
| 1391 | 1391 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1392 | 1392 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1393 | 1393 | } |
@@ -1404,26 +1404,26 @@ discard block |
||
| 1404 | 1404 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1405 | 1405 | **/ |
| 1406 | 1406 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1407 | - if ($param[0]->type != 'texte') { |
|
| 1408 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1409 | - if (isset($param[1]->texte)) { |
|
| 1410 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1411 | - |
|
| 1412 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1413 | - } else { |
|
| 1414 | - return ["intval($a1)", 0]; |
|
| 1415 | - } |
|
| 1416 | - } else { |
|
| 1417 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1418 | - $a1 = $m[1]; |
|
| 1419 | - if (empty($m[3])) { |
|
| 1420 | - return [$a1, 0]; |
|
| 1421 | - } elseif (!empty($m[4])) { |
|
| 1422 | - return [$a1, $m[4]]; |
|
| 1423 | - } else { |
|
| 1424 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1407 | + if ($param[0]->type != 'texte') { |
|
| 1408 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1409 | + if (isset($param[1]->texte)) { |
|
| 1410 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1411 | + |
|
| 1412 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1413 | + } else { |
|
| 1414 | + return ["intval($a1)", 0]; |
|
| 1415 | + } |
|
| 1416 | + } else { |
|
| 1417 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1418 | + $a1 = $m[1]; |
|
| 1419 | + if (empty($m[3])) { |
|
| 1420 | + return [$a1, 0]; |
|
| 1421 | + } elseif (!empty($m[4])) { |
|
| 1422 | + return [$a1, $m[4]]; |
|
| 1423 | + } else { |
|
| 1424 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1425 | + } |
|
| 1426 | + } |
|
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | 1429 | |
@@ -1450,47 +1450,47 @@ discard block |
||
| 1450 | 1450 | * array : Erreur sur un des critères |
| 1451 | 1451 | **/ |
| 1452 | 1452 | function calculer_criteres($idb, &$boucles) { |
| 1453 | - $msg = ''; |
|
| 1454 | - $boucle = $boucles[$idb]; |
|
| 1455 | - $table = strtoupper($boucle->type_requete); |
|
| 1456 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1457 | - |
|
| 1458 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1459 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1460 | - if (!is_array($boucle->criteres)) { |
|
| 1461 | - return []; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - foreach ($boucle->criteres as $crit) { |
|
| 1465 | - $critere = $crit->op; |
|
| 1466 | - // critere personnalise ? |
|
| 1467 | - if ( |
|
| 1468 | - (!$serveur or |
|
| 1469 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1473 | - ) |
|
| 1474 | - ) |
|
| 1475 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1476 | - and (!function_exists($f = $f . '_dist')) |
|
| 1477 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1478 | - and (!function_exists($f = $f . '_dist')) |
|
| 1479 | - ) { |
|
| 1480 | - // fonction critere standard |
|
| 1481 | - $f = $defaut; |
|
| 1482 | - } |
|
| 1483 | - // compile le critere |
|
| 1484 | - $res = $f($idb, $boucles, $crit); |
|
| 1485 | - |
|
| 1486 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1487 | - if (is_array($res)) { |
|
| 1488 | - $msg = $res; |
|
| 1489 | - erreur_squelette($msg, $boucle); |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - return $msg; |
|
| 1453 | + $msg = ''; |
|
| 1454 | + $boucle = $boucles[$idb]; |
|
| 1455 | + $table = strtoupper($boucle->type_requete); |
|
| 1456 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1457 | + |
|
| 1458 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1459 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1460 | + if (!is_array($boucle->criteres)) { |
|
| 1461 | + return []; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + foreach ($boucle->criteres as $crit) { |
|
| 1465 | + $critere = $crit->op; |
|
| 1466 | + // critere personnalise ? |
|
| 1467 | + if ( |
|
| 1468 | + (!$serveur or |
|
| 1469 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1470 | + and (!function_exists($f = $f . '_dist')) |
|
| 1471 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1472 | + and (!function_exists($f = $f . '_dist')) |
|
| 1473 | + ) |
|
| 1474 | + ) |
|
| 1475 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1476 | + and (!function_exists($f = $f . '_dist')) |
|
| 1477 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1478 | + and (!function_exists($f = $f . '_dist')) |
|
| 1479 | + ) { |
|
| 1480 | + // fonction critere standard |
|
| 1481 | + $f = $defaut; |
|
| 1482 | + } |
|
| 1483 | + // compile le critere |
|
| 1484 | + $res = $f($idb, $boucles, $crit); |
|
| 1485 | + |
|
| 1486 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1487 | + if (is_array($res)) { |
|
| 1488 | + $msg = $res; |
|
| 1489 | + erreur_squelette($msg, $boucle); |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + return $msg; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | /** |
@@ -1507,11 +1507,11 @@ discard block |
||
| 1507 | 1507 | * @return string Code compilé rééchappé |
| 1508 | 1508 | */ |
| 1509 | 1509 | function kwote($lisp, $serveur = '', $type = '') { |
| 1510 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1511 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1512 | - } else { |
|
| 1513 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1514 | - } |
|
| 1510 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1511 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1512 | + } else { |
|
| 1513 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1514 | + } |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | |
@@ -1530,82 +1530,82 @@ discard block |
||
| 1530 | 1530 | * @return void |
| 1531 | 1531 | **/ |
| 1532 | 1532 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1533 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1534 | - if (!$r) { |
|
| 1535 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1536 | - } |
|
| 1537 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1538 | - |
|
| 1539 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1540 | - |
|
| 1541 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1542 | - $where = $in; |
|
| 1543 | - if ($crit->cond) { |
|
| 1544 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1545 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1546 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1547 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - if ($crit->exclus) { |
|
| 1551 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1552 | - $where = ["'NOT'", $where]; |
|
| 1553 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1554 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1555 | - { |
|
| 1556 | - $where = [ |
|
| 1557 | - "'NOT'", |
|
| 1558 | - [ |
|
| 1559 | - "'IN'", |
|
| 1560 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1561 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1562 | - ] |
|
| 1563 | - ]; |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - $boucles[$idb]->where[] = $where; |
|
| 1568 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1570 | - } |
|
| 1533 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1534 | + if (!$r) { |
|
| 1535 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1536 | + } |
|
| 1537 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1538 | + |
|
| 1539 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1540 | + |
|
| 1541 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1542 | + $where = $in; |
|
| 1543 | + if ($crit->cond) { |
|
| 1544 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1545 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1546 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1547 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + if ($crit->exclus) { |
|
| 1551 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1552 | + $where = ["'NOT'", $where]; |
|
| 1553 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1554 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1555 | + { |
|
| 1556 | + $where = [ |
|
| 1557 | + "'NOT'", |
|
| 1558 | + [ |
|
| 1559 | + "'IN'", |
|
| 1560 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1561 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1562 | + ] |
|
| 1563 | + ]; |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + $boucles[$idb]->where[] = $where; |
|
| 1568 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1570 | + } |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | // https://code.spip.net/@critere_IN_cas |
| 1574 | 1574 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1575 | - static $num = []; |
|
| 1576 | - $descr = $boucles[$idb]->descr; |
|
| 1577 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1578 | - |
|
| 1579 | - $var = '$in' . $cpt++; |
|
| 1580 | - $x = "\n\t$var = array();"; |
|
| 1581 | - foreach ($val as $k => $v) { |
|
| 1582 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1583 | - // optimiser le traitement des constantes |
|
| 1584 | - if (is_numeric($r[2])) { |
|
| 1585 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1586 | - } else { |
|
| 1587 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1588 | - } |
|
| 1589 | - } else { |
|
| 1590 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1591 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1592 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1593 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1594 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1595 | - } |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - $boucles[$idb]->in .= $x; |
|
| 1599 | - |
|
| 1600 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1601 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1602 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1603 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1604 | - if (!$crit2) { |
|
| 1605 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1575 | + static $num = []; |
|
| 1576 | + $descr = $boucles[$idb]->descr; |
|
| 1577 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1578 | + |
|
| 1579 | + $var = '$in' . $cpt++; |
|
| 1580 | + $x = "\n\t$var = array();"; |
|
| 1581 | + foreach ($val as $k => $v) { |
|
| 1582 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1583 | + // optimiser le traitement des constantes |
|
| 1584 | + if (is_numeric($r[2])) { |
|
| 1585 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1586 | + } else { |
|
| 1587 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1588 | + } |
|
| 1589 | + } else { |
|
| 1590 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1591 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1592 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1593 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1594 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1595 | + } |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + $boucles[$idb]->in .= $x; |
|
| 1599 | + |
|
| 1600 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1601 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1602 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1603 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1604 | + if (!$crit2) { |
|
| 1605 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | /** |
@@ -1621,22 +1621,22 @@ discard block |
||
| 1621 | 1621 | * @return void |
| 1622 | 1622 | */ |
| 1623 | 1623 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1624 | - $boucle = &$boucles[$idb]; |
|
| 1625 | - if (isset($crit->param[0])) { |
|
| 1626 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1627 | - } else { |
|
| 1628 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - if ($crit->cond) { |
|
| 1632 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - if ($crit->not) { |
|
| 1636 | - $_where = "array('NOT',$_where)"; |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - $boucle->where[] = $_where; |
|
| 1624 | + $boucle = &$boucles[$idb]; |
|
| 1625 | + if (isset($crit->param[0])) { |
|
| 1626 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1627 | + } else { |
|
| 1628 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + if ($crit->cond) { |
|
| 1632 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + if ($crit->not) { |
|
| 1636 | + $_where = "array('NOT',$_where)"; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + $boucle->where[] = $_where; |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | /** |
@@ -1664,31 +1664,31 @@ discard block |
||
| 1664 | 1664 | * @return void |
| 1665 | 1665 | */ |
| 1666 | 1666 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1667 | - /** @var Boucle $boucle */ |
|
| 1668 | - $boucle = $boucles[$idb]; |
|
| 1669 | - |
|
| 1670 | - $champs = lister_champs_id_conditionnel( |
|
| 1671 | - $boucle->show['table'], |
|
| 1672 | - $boucle->show, |
|
| 1673 | - $boucle->sql_serveur |
|
| 1674 | - ); |
|
| 1675 | - |
|
| 1676 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1677 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1678 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1679 | - } |
|
| 1680 | - // nous aider en mode debug. |
|
| 1681 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1682 | - $boucle->modificateur['id_'] = $champs; |
|
| 1683 | - |
|
| 1684 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1685 | - foreach ($champs as $champ) { |
|
| 1686 | - $critere_id_table = new Critere(); |
|
| 1687 | - $critere_id_table->op = $champ; |
|
| 1688 | - $critere_id_table->cond = '?'; |
|
| 1689 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1690 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1691 | - } |
|
| 1667 | + /** @var Boucle $boucle */ |
|
| 1668 | + $boucle = $boucles[$idb]; |
|
| 1669 | + |
|
| 1670 | + $champs = lister_champs_id_conditionnel( |
|
| 1671 | + $boucle->show['table'], |
|
| 1672 | + $boucle->show, |
|
| 1673 | + $boucle->sql_serveur |
|
| 1674 | + ); |
|
| 1675 | + |
|
| 1676 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1677 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1678 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1679 | + } |
|
| 1680 | + // nous aider en mode debug. |
|
| 1681 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1682 | + $boucle->modificateur['id_'] = $champs; |
|
| 1683 | + |
|
| 1684 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1685 | + foreach ($champs as $champ) { |
|
| 1686 | + $critere_id_table = new Critere(); |
|
| 1687 | + $critere_id_table->op = $champ; |
|
| 1688 | + $critere_id_table->cond = '?'; |
|
| 1689 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1690 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1691 | + } |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1708,79 +1708,79 @@ discard block |
||
| 1708 | 1708 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1709 | 1709 | */ |
| 1710 | 1710 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1711 | - // calculer la description de la table |
|
| 1712 | - if (!is_array($desc)) { |
|
| 1713 | - $desc = description_table($table, $serveur); |
|
| 1714 | - } |
|
| 1715 | - if (!$desc) { |
|
| 1716 | - return []; |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - // Les champs id_xx de la table demandée |
|
| 1720 | - $champs = array_filter( |
|
| 1721 | - array_keys($desc['field']), |
|
| 1722 | - function ($champ) { |
|
| 1723 | - return |
|
| 1724 | - strpos($champ, 'id_') === 0 |
|
| 1725 | - or (in_array($champ, ['objet'])); |
|
| 1726 | - } |
|
| 1727 | - ); |
|
| 1728 | - |
|
| 1729 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1730 | - if ( |
|
| 1731 | - in_array('id_rubrique', $champs) |
|
| 1732 | - and !in_array('id_secteur', $champs) |
|
| 1733 | - ) { |
|
| 1734 | - $champs[] = 'id_secteur'; |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1738 | - if ($serveur) { |
|
| 1739 | - return $champs; |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - $primary = false; |
|
| 1743 | - $associable = false; |
|
| 1744 | - include_spip('action/editer_liens'); |
|
| 1745 | - |
|
| 1746 | - if (isset($desc['type'])) { |
|
| 1747 | - $primary = id_table_objet($desc['type']); |
|
| 1748 | - $associable = objet_associable($desc['type']); |
|
| 1749 | - } |
|
| 1750 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1751 | - $associable = true; |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - // liste de toutes les tables principales, sauf la notre |
|
| 1755 | - $tables = lister_tables_objets_sql(); |
|
| 1756 | - unset($tables[$table]); |
|
| 1757 | - |
|
| 1758 | - foreach ($tables as $_table => $_desc) { |
|
| 1759 | - if ( |
|
| 1760 | - $associable |
|
| 1761 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1762 | - or objet_associable($_desc['type']) |
|
| 1763 | - ) { |
|
| 1764 | - $champs[] = id_table_objet($_table); |
|
| 1765 | - } |
|
| 1766 | - } |
|
| 1767 | - $champs = array_values(array_unique($champs)); |
|
| 1768 | - |
|
| 1769 | - // Exclusions de certains id |
|
| 1770 | - $exclusions = pipeline( |
|
| 1771 | - 'exclure_id_conditionnel', |
|
| 1772 | - [ |
|
| 1773 | - 'args' => [ |
|
| 1774 | - 'table' => $table, |
|
| 1775 | - 'id_table_objet' => $primary, |
|
| 1776 | - 'associable' => $associable, |
|
| 1777 | - ], |
|
| 1778 | - 'data' => [], |
|
| 1779 | - ] |
|
| 1780 | - ); |
|
| 1781 | - $champs = array_diff($champs, $exclusions); |
|
| 1782 | - |
|
| 1783 | - return $champs; |
|
| 1711 | + // calculer la description de la table |
|
| 1712 | + if (!is_array($desc)) { |
|
| 1713 | + $desc = description_table($table, $serveur); |
|
| 1714 | + } |
|
| 1715 | + if (!$desc) { |
|
| 1716 | + return []; |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + // Les champs id_xx de la table demandée |
|
| 1720 | + $champs = array_filter( |
|
| 1721 | + array_keys($desc['field']), |
|
| 1722 | + function ($champ) { |
|
| 1723 | + return |
|
| 1724 | + strpos($champ, 'id_') === 0 |
|
| 1725 | + or (in_array($champ, ['objet'])); |
|
| 1726 | + } |
|
| 1727 | + ); |
|
| 1728 | + |
|
| 1729 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1730 | + if ( |
|
| 1731 | + in_array('id_rubrique', $champs) |
|
| 1732 | + and !in_array('id_secteur', $champs) |
|
| 1733 | + ) { |
|
| 1734 | + $champs[] = 'id_secteur'; |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1738 | + if ($serveur) { |
|
| 1739 | + return $champs; |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + $primary = false; |
|
| 1743 | + $associable = false; |
|
| 1744 | + include_spip('action/editer_liens'); |
|
| 1745 | + |
|
| 1746 | + if (isset($desc['type'])) { |
|
| 1747 | + $primary = id_table_objet($desc['type']); |
|
| 1748 | + $associable = objet_associable($desc['type']); |
|
| 1749 | + } |
|
| 1750 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1751 | + $associable = true; |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + // liste de toutes les tables principales, sauf la notre |
|
| 1755 | + $tables = lister_tables_objets_sql(); |
|
| 1756 | + unset($tables[$table]); |
|
| 1757 | + |
|
| 1758 | + foreach ($tables as $_table => $_desc) { |
|
| 1759 | + if ( |
|
| 1760 | + $associable |
|
| 1761 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1762 | + or objet_associable($_desc['type']) |
|
| 1763 | + ) { |
|
| 1764 | + $champs[] = id_table_objet($_table); |
|
| 1765 | + } |
|
| 1766 | + } |
|
| 1767 | + $champs = array_values(array_unique($champs)); |
|
| 1768 | + |
|
| 1769 | + // Exclusions de certains id |
|
| 1770 | + $exclusions = pipeline( |
|
| 1771 | + 'exclure_id_conditionnel', |
|
| 1772 | + [ |
|
| 1773 | + 'args' => [ |
|
| 1774 | + 'table' => $table, |
|
| 1775 | + 'id_table_objet' => $primary, |
|
| 1776 | + 'associable' => $associable, |
|
| 1777 | + ], |
|
| 1778 | + 'data' => [], |
|
| 1779 | + ] |
|
| 1780 | + ); |
|
| 1781 | + $champs = array_diff($champs, $exclusions); |
|
| 1782 | + |
|
| 1783 | + return $champs; |
|
| 1784 | 1784 | } |
| 1785 | 1785 | |
| 1786 | 1786 | /** |
@@ -1835,27 +1835,27 @@ discard block |
||
| 1835 | 1835 | * @return void |
| 1836 | 1836 | */ |
| 1837 | 1837 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1838 | - $boucle = &$boucles[$idb]; |
|
| 1839 | - |
|
| 1840 | - // definition du champ par defaut |
|
| 1841 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1842 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1843 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1844 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1845 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1846 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1847 | - |
|
| 1848 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1849 | - |
|
| 1850 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1851 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1852 | - |
|
| 1853 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1854 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1855 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1856 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1857 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1858 | - $boucle->hash .= " |
|
| 1838 | + $boucle = &$boucles[$idb]; |
|
| 1839 | + |
|
| 1840 | + // definition du champ par defaut |
|
| 1841 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1842 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1843 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1844 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1845 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1846 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1847 | + |
|
| 1848 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1849 | + |
|
| 1850 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1851 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1852 | + |
|
| 1853 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1854 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1855 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1856 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1857 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1858 | + $boucle->hash .= " |
|
| 1859 | 1859 | \$senstri = ''; |
| 1860 | 1860 | \$tri = $_tri; |
| 1861 | 1861 | if (\$tri){ |
@@ -1863,8 +1863,8 @@ discard block |
||
| 1863 | 1863 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1864 | 1864 | }; |
| 1865 | 1865 | "; |
| 1866 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1867 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1866 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1867 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1868 | 1868 | } |
| 1869 | 1869 | |
| 1870 | 1870 | # Criteres de comparaison |
@@ -1881,20 +1881,20 @@ discard block |
||
| 1881 | 1881 | * @return void |
| 1882 | 1882 | **/ |
| 1883 | 1883 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1884 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1885 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1886 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1890 | - if (!$r) { |
|
| 1891 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1892 | - # if (!$crit->cond) { |
|
| 1893 | - return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1894 | - # } |
|
| 1895 | - } else { |
|
| 1896 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1897 | - } |
|
| 1884 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1885 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1886 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1890 | + if (!$r) { |
|
| 1891 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1892 | + # if (!$crit->cond) { |
|
| 1893 | + return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1894 | + # } |
|
| 1895 | + } else { |
|
| 1896 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1897 | + } |
|
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | |
@@ -1914,62 +1914,62 @@ discard block |
||
| 1914 | 1914 | * @return void |
| 1915 | 1915 | **/ |
| 1916 | 1916 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1917 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1918 | - |
|
| 1919 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1920 | - |
|
| 1921 | - // inserer la negation (cf !...) |
|
| 1922 | - |
|
| 1923 | - if ($crit->not) { |
|
| 1924 | - $where = ["'NOT'", $where]; |
|
| 1925 | - } |
|
| 1926 | - if ($crit->exclus) { |
|
| 1927 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1928 | - $where = ["'NOT'", $where]; |
|
| 1929 | - } else { |
|
| 1930 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1931 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1932 | - $where = [ |
|
| 1933 | - "'NOT'", |
|
| 1934 | - [ |
|
| 1935 | - "'IN'", |
|
| 1936 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1937 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1938 | - ] |
|
| 1939 | - ]; |
|
| 1940 | - } |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - // inserer la condition (cf {lang?}) |
|
| 1944 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1945 | - if ($crit->cond) { |
|
| 1946 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1947 | - if ($col == 'date' or $col == 'date_redac') { |
|
| 1948 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1949 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - if ($op == '=' and !$crit->not) { |
|
| 1954 | - $where = [ |
|
| 1955 | - "'?'", |
|
| 1956 | - "(is_array($pred))", |
|
| 1957 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1958 | - $where |
|
| 1959 | - ]; |
|
| 1960 | - } |
|
| 1961 | - $where = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where]; |
|
| 1962 | - if ($where_complement) { |
|
| 1963 | - // condition annexe du type "AND (objet='article')" |
|
| 1964 | - $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1965 | - } |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - $boucles[$idb]->where[] = $where; |
|
| 1969 | - if ($where_complement) { |
|
| 1970 | - // condition annexe du type "AND (objet='article')" |
|
| 1971 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1972 | - } |
|
| 1917 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1918 | + |
|
| 1919 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1920 | + |
|
| 1921 | + // inserer la negation (cf !...) |
|
| 1922 | + |
|
| 1923 | + if ($crit->not) { |
|
| 1924 | + $where = ["'NOT'", $where]; |
|
| 1925 | + } |
|
| 1926 | + if ($crit->exclus) { |
|
| 1927 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1928 | + $where = ["'NOT'", $where]; |
|
| 1929 | + } else { |
|
| 1930 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1931 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1932 | + $where = [ |
|
| 1933 | + "'NOT'", |
|
| 1934 | + [ |
|
| 1935 | + "'IN'", |
|
| 1936 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1937 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1938 | + ] |
|
| 1939 | + ]; |
|
| 1940 | + } |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + // inserer la condition (cf {lang?}) |
|
| 1944 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1945 | + if ($crit->cond) { |
|
| 1946 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1947 | + if ($col == 'date' or $col == 'date_redac') { |
|
| 1948 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1949 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + if ($op == '=' and !$crit->not) { |
|
| 1954 | + $where = [ |
|
| 1955 | + "'?'", |
|
| 1956 | + "(is_array($pred))", |
|
| 1957 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1958 | + $where |
|
| 1959 | + ]; |
|
| 1960 | + } |
|
| 1961 | + $where = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where]; |
|
| 1962 | + if ($where_complement) { |
|
| 1963 | + // condition annexe du type "AND (objet='article')" |
|
| 1964 | + $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1965 | + } |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + $boucles[$idb]->where[] = $where; |
|
| 1969 | + if ($where_complement) { |
|
| 1970 | + // condition annexe du type "AND (objet='article')" |
|
| 1971 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1972 | + } |
|
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | 1975 | |
@@ -2010,165 +2010,165 @@ discard block |
||
| 2010 | 2010 | **/ |
| 2011 | 2011 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2012 | 2012 | |
| 2013 | - $boucle = &$boucles[$idb]; |
|
| 2014 | - $type = $boucle->type_requete; |
|
| 2015 | - $table = $boucle->id_table; |
|
| 2016 | - $desc = $boucle->show; |
|
| 2017 | - $col_vraie = null; |
|
| 2018 | - |
|
| 2019 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 2020 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2021 | - |
|
| 2022 | - $col_alias = $col; |
|
| 2023 | - $where_complement = false; |
|
| 2024 | - |
|
| 2025 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2026 | - if ($col == 'id_enfant') { |
|
| 2027 | - $col = $boucle->primary; |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2031 | - if ( |
|
| 2032 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2033 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2034 | - ) { |
|
| 2035 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2036 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2037 | - else { |
|
| 2038 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2039 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2043 | - // sauf si exception declaree : sauter cette etape |
|
| 2044 | - else { |
|
| 2045 | - if ( |
|
| 2046 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2047 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2048 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2049 | - ) { |
|
| 2050 | - $e = decompose_champ_id_objet($col); |
|
| 2051 | - $col = array_shift($e); |
|
| 2052 | - $where_complement = primary_doublee($e, $table); |
|
| 2053 | - } // Cas particulier : expressions de date |
|
| 2054 | - else { |
|
| 2055 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2056 | - list($col, $col_vraie) = $c; |
|
| 2057 | - $table = ''; |
|
| 2058 | - } // table explicitée {mots.titre} |
|
| 2059 | - else { |
|
| 2060 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2061 | - list(, $table, $col) = $r; |
|
| 2062 | - $col_alias = $col; |
|
| 2063 | - |
|
| 2064 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2065 | - if ( |
|
| 2066 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2067 | - and isset($desc['field'][$col]) |
|
| 2068 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2069 | - ) { |
|
| 2070 | - $table = $cle; |
|
| 2071 | - } else { |
|
| 2072 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2073 | - } |
|
| 2074 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2075 | - if (!$table) { |
|
| 2076 | - return ''; |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - // si le champ n'est pas trouvé dans la table, |
|
| 2080 | - // on cherche si une jointure peut l'obtenir |
|
| 2081 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2082 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2083 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2084 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2085 | - } |
|
| 2086 | - else { |
|
| 2087 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2088 | - if (!$r) { |
|
| 2089 | - return ''; |
|
| 2090 | - } |
|
| 2091 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - } |
|
| 2098 | - |
|
| 2099 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2100 | - // Dans tous les cas, |
|
| 2101 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2102 | - // et passer dans sql_quote avec le type si connu |
|
| 2103 | - // et int sinon si la valeur est numerique |
|
| 2104 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2105 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2106 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2107 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2108 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2109 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2110 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2111 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2112 | - } |
|
| 2113 | - // sinon expliciter les |
|
| 2114 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2115 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2116 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2117 | - // sans toucher aux |
|
| 2118 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2119 | - // sql_quote(truc,'','varchar') |
|
| 2120 | - elseif ( |
|
| 2121 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2122 | - // si pas deja un type |
|
| 2123 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2124 | - ) { |
|
| 2125 | - $r = $r[1] |
|
| 2126 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2127 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2128 | - $val[0] = "sql_quote($r)"; |
|
| 2129 | - } |
|
| 2130 | - elseif ( |
|
| 2131 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | - ) { |
|
| 2134 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - if ( |
|
| 2139 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2140 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2141 | - ) { |
|
| 2142 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2143 | - } |
|
| 2144 | - |
|
| 2145 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2146 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2147 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2148 | - if ($table === $boucle->id_table) { |
|
| 2149 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2150 | - if ($col_alias != $col_vraie) { |
|
| 2151 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2152 | - } |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2156 | - if ($table) { |
|
| 2157 | - if ($col[0] == '`') { |
|
| 2158 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2159 | - } else { |
|
| 2160 | - $arg = "$table.$col"; |
|
| 2161 | - } |
|
| 2162 | - } else { |
|
| 2163 | - $arg = $col; |
|
| 2164 | - } |
|
| 2165 | - |
|
| 2166 | - // inserer la fonction SQL |
|
| 2167 | - if ($fct) { |
|
| 2168 | - $arg = "$fct($arg$args_sql)"; |
|
| 2169 | - } |
|
| 2170 | - |
|
| 2171 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2013 | + $boucle = &$boucles[$idb]; |
|
| 2014 | + $type = $boucle->type_requete; |
|
| 2015 | + $table = $boucle->id_table; |
|
| 2016 | + $desc = $boucle->show; |
|
| 2017 | + $col_vraie = null; |
|
| 2018 | + |
|
| 2019 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 2020 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2021 | + |
|
| 2022 | + $col_alias = $col; |
|
| 2023 | + $where_complement = false; |
|
| 2024 | + |
|
| 2025 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2026 | + if ($col == 'id_enfant') { |
|
| 2027 | + $col = $boucle->primary; |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2031 | + if ( |
|
| 2032 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2033 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2034 | + ) { |
|
| 2035 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2036 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2037 | + else { |
|
| 2038 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2039 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2043 | + // sauf si exception declaree : sauter cette etape |
|
| 2044 | + else { |
|
| 2045 | + if ( |
|
| 2046 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2047 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2048 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2049 | + ) { |
|
| 2050 | + $e = decompose_champ_id_objet($col); |
|
| 2051 | + $col = array_shift($e); |
|
| 2052 | + $where_complement = primary_doublee($e, $table); |
|
| 2053 | + } // Cas particulier : expressions de date |
|
| 2054 | + else { |
|
| 2055 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2056 | + list($col, $col_vraie) = $c; |
|
| 2057 | + $table = ''; |
|
| 2058 | + } // table explicitée {mots.titre} |
|
| 2059 | + else { |
|
| 2060 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2061 | + list(, $table, $col) = $r; |
|
| 2062 | + $col_alias = $col; |
|
| 2063 | + |
|
| 2064 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2065 | + if ( |
|
| 2066 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2067 | + and isset($desc['field'][$col]) |
|
| 2068 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2069 | + ) { |
|
| 2070 | + $table = $cle; |
|
| 2071 | + } else { |
|
| 2072 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2073 | + } |
|
| 2074 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2075 | + if (!$table) { |
|
| 2076 | + return ''; |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + // si le champ n'est pas trouvé dans la table, |
|
| 2080 | + // on cherche si une jointure peut l'obtenir |
|
| 2081 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2082 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2083 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2084 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2085 | + } |
|
| 2086 | + else { |
|
| 2087 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2088 | + if (!$r) { |
|
| 2089 | + return ''; |
|
| 2090 | + } |
|
| 2091 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + } |
|
| 2098 | + |
|
| 2099 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2100 | + // Dans tous les cas, |
|
| 2101 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2102 | + // et passer dans sql_quote avec le type si connu |
|
| 2103 | + // et int sinon si la valeur est numerique |
|
| 2104 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2105 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2106 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2107 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2108 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2109 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2110 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2111 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2112 | + } |
|
| 2113 | + // sinon expliciter les |
|
| 2114 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2115 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2116 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2117 | + // sans toucher aux |
|
| 2118 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2119 | + // sql_quote(truc,'','varchar') |
|
| 2120 | + elseif ( |
|
| 2121 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2122 | + // si pas deja un type |
|
| 2123 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2124 | + ) { |
|
| 2125 | + $r = $r[1] |
|
| 2126 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2127 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2128 | + $val[0] = "sql_quote($r)"; |
|
| 2129 | + } |
|
| 2130 | + elseif ( |
|
| 2131 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | + ) { |
|
| 2134 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + if ( |
|
| 2139 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2140 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2141 | + ) { |
|
| 2142 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2146 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2147 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2148 | + if ($table === $boucle->id_table) { |
|
| 2149 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2150 | + if ($col_alias != $col_vraie) { |
|
| 2151 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2152 | + } |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2156 | + if ($table) { |
|
| 2157 | + if ($col[0] == '`') { |
|
| 2158 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2159 | + } else { |
|
| 2160 | + $arg = "$table.$col"; |
|
| 2161 | + } |
|
| 2162 | + } else { |
|
| 2163 | + $arg = $col; |
|
| 2164 | + } |
|
| 2165 | + |
|
| 2166 | + // inserer la fonction SQL |
|
| 2167 | + if ($fct) { |
|
| 2168 | + $arg = "$fct($arg$args_sql)"; |
|
| 2169 | + } |
|
| 2170 | + |
|
| 2171 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | |
@@ -2197,78 +2197,78 @@ discard block |
||
| 2197 | 2197 | **/ |
| 2198 | 2198 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2199 | 2199 | |
| 2200 | - $where = ''; |
|
| 2201 | - |
|
| 2202 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2203 | - // gestion par les plugins des jointures tordues |
|
| 2204 | - // pas automatiques mais necessaires |
|
| 2205 | - $table_sql = table_objet_sql($table); |
|
| 2206 | - if ( |
|
| 2207 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2208 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2209 | - and |
|
| 2210 | - ( |
|
| 2211 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2212 | - or |
|
| 2213 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2214 | - ) |
|
| 2215 | - ) { |
|
| 2216 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2217 | - $index = isset($t[$col]) |
|
| 2218 | - ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2219 | - |
|
| 2220 | - if (count($index) == 3) { |
|
| 2221 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2222 | - } elseif (count($index) == 2) { |
|
| 2223 | - list($t, $col) = $t[$col]; |
|
| 2224 | - } elseif (count($index) == 1) { |
|
| 2225 | - list($calculer_critere_externe) = $index; |
|
| 2226 | - $t = $table; |
|
| 2227 | - } else { |
|
| 2228 | - $t = ''; |
|
| 2229 | - } // jointure non declaree. La trouver. |
|
| 2230 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2231 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2232 | - } else { |
|
| 2233 | - $t = ''; |
|
| 2234 | - } // jointure non declaree. La trouver. |
|
| 2235 | - |
|
| 2236 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2237 | - |
|
| 2238 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2239 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2240 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2241 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2242 | - $table = ''; |
|
| 2243 | - if ($boucle->jointures_explicites) { |
|
| 2244 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2245 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2246 | - } |
|
| 2247 | - |
|
| 2248 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2249 | - if (!$table) { |
|
| 2250 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - if (!$table) { |
|
| 2254 | - return ''; |
|
| 2255 | - } |
|
| 2256 | - |
|
| 2257 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2258 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2259 | - |
|
| 2260 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2261 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2262 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2263 | - $e = decompose_champ_id_objet($col); |
|
| 2264 | - $col = array_shift($e); |
|
| 2265 | - $where = primary_doublee($e, $table); |
|
| 2266 | - } else { |
|
| 2267 | - $col = reset($cle); |
|
| 2268 | - } |
|
| 2269 | - } |
|
| 2270 | - |
|
| 2271 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2200 | + $where = ''; |
|
| 2201 | + |
|
| 2202 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2203 | + // gestion par les plugins des jointures tordues |
|
| 2204 | + // pas automatiques mais necessaires |
|
| 2205 | + $table_sql = table_objet_sql($table); |
|
| 2206 | + if ( |
|
| 2207 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2208 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2209 | + and |
|
| 2210 | + ( |
|
| 2211 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2212 | + or |
|
| 2213 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2214 | + ) |
|
| 2215 | + ) { |
|
| 2216 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2217 | + $index = isset($t[$col]) |
|
| 2218 | + ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2219 | + |
|
| 2220 | + if (count($index) == 3) { |
|
| 2221 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2222 | + } elseif (count($index) == 2) { |
|
| 2223 | + list($t, $col) = $t[$col]; |
|
| 2224 | + } elseif (count($index) == 1) { |
|
| 2225 | + list($calculer_critere_externe) = $index; |
|
| 2226 | + $t = $table; |
|
| 2227 | + } else { |
|
| 2228 | + $t = ''; |
|
| 2229 | + } // jointure non declaree. La trouver. |
|
| 2230 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2231 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2232 | + } else { |
|
| 2233 | + $t = ''; |
|
| 2234 | + } // jointure non declaree. La trouver. |
|
| 2235 | + |
|
| 2236 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2237 | + |
|
| 2238 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2239 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2240 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2241 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2242 | + $table = ''; |
|
| 2243 | + if ($boucle->jointures_explicites) { |
|
| 2244 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2245 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2246 | + } |
|
| 2247 | + |
|
| 2248 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2249 | + if (!$table) { |
|
| 2250 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + if (!$table) { |
|
| 2254 | + return ''; |
|
| 2255 | + } |
|
| 2256 | + |
|
| 2257 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2258 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2259 | + |
|
| 2260 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2261 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2262 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2263 | + $e = decompose_champ_id_objet($col); |
|
| 2264 | + $col = array_shift($e); |
|
| 2265 | + $where = primary_doublee($e, $table); |
|
| 2266 | + } else { |
|
| 2267 | + $col = reset($cle); |
|
| 2268 | + } |
|
| 2269 | + } |
|
| 2270 | + |
|
| 2271 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | |
@@ -2289,10 +2289,10 @@ discard block |
||
| 2289 | 2289 | * - valeur |
| 2290 | 2290 | **/ |
| 2291 | 2291 | function primary_doublee($decompose, $table) { |
| 2292 | - $e1 = reset($decompose); |
|
| 2293 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2292 | + $e1 = reset($decompose); |
|
| 2293 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2294 | 2294 | |
| 2295 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2295 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | 2298 | /** |
@@ -2323,57 +2323,57 @@ discard block |
||
| 2323 | 2323 | * Vide sinon. |
| 2324 | 2324 | */ |
| 2325 | 2325 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2326 | - // si on demande un truc du genre spip_mots |
|
| 2327 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2328 | - // et qu'on est la |
|
| 2329 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2330 | - if ( |
|
| 2331 | - $checkarrivee |
|
| 2332 | - and is_string($checkarrivee) |
|
| 2333 | - and $a = table_objet($checkarrivee) |
|
| 2334 | - and in_array($a . '_liens', $joints) |
|
| 2335 | - ) { |
|
| 2336 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2337 | - return $res; |
|
| 2338 | - } |
|
| 2339 | - } |
|
| 2340 | - foreach ($joints as $joint) { |
|
| 2341 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2342 | - // alias de table dans le from |
|
| 2343 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2344 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2345 | - $cols = $arrivee[2]; |
|
| 2346 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2347 | - if (count($cols) > 2) { |
|
| 2348 | - array_pop($cols); |
|
| 2349 | - } |
|
| 2350 | - if ($t) { |
|
| 2351 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2352 | - $joindre = false; |
|
| 2353 | - foreach ($cols as $col) { |
|
| 2354 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2355 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2356 | - $joindre = true; |
|
| 2357 | - } else { |
|
| 2358 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2359 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2360 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2361 | - $joindre = true; |
|
| 2362 | - } |
|
| 2363 | - } |
|
| 2364 | - } |
|
| 2365 | - if (!$joindre) { |
|
| 2366 | - return $t; |
|
| 2367 | - } |
|
| 2368 | - } |
|
| 2369 | - array_pop($arrivee); |
|
| 2370 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2371 | - return $res; |
|
| 2372 | - } |
|
| 2373 | - } |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - return ''; |
|
| 2326 | + // si on demande un truc du genre spip_mots |
|
| 2327 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2328 | + // et qu'on est la |
|
| 2329 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2330 | + if ( |
|
| 2331 | + $checkarrivee |
|
| 2332 | + and is_string($checkarrivee) |
|
| 2333 | + and $a = table_objet($checkarrivee) |
|
| 2334 | + and in_array($a . '_liens', $joints) |
|
| 2335 | + ) { |
|
| 2336 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2337 | + return $res; |
|
| 2338 | + } |
|
| 2339 | + } |
|
| 2340 | + foreach ($joints as $joint) { |
|
| 2341 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2342 | + // alias de table dans le from |
|
| 2343 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2344 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2345 | + $cols = $arrivee[2]; |
|
| 2346 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2347 | + if (count($cols) > 2) { |
|
| 2348 | + array_pop($cols); |
|
| 2349 | + } |
|
| 2350 | + if ($t) { |
|
| 2351 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2352 | + $joindre = false; |
|
| 2353 | + foreach ($cols as $col) { |
|
| 2354 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2355 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2356 | + $joindre = true; |
|
| 2357 | + } else { |
|
| 2358 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2359 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2360 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2361 | + $joindre = true; |
|
| 2362 | + } |
|
| 2363 | + } |
|
| 2364 | + } |
|
| 2365 | + if (!$joindre) { |
|
| 2366 | + return $t; |
|
| 2367 | + } |
|
| 2368 | + } |
|
| 2369 | + array_pop($arrivee); |
|
| 2370 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2371 | + return $res; |
|
| 2372 | + } |
|
| 2373 | + } |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + return ''; |
|
| 2377 | 2377 | } |
| 2378 | 2378 | |
| 2379 | 2379 | /** |
@@ -2399,35 +2399,35 @@ discard block |
||
| 2399 | 2399 | * Alias de la table de jointure (Lx) |
| 2400 | 2400 | */ |
| 2401 | 2401 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2402 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2403 | - |
|
| 2404 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2405 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2406 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2407 | - |
|
| 2408 | - if (!$intermediaire or !$arrivee) { |
|
| 2409 | - return ''; |
|
| 2410 | - } |
|
| 2411 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2412 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2413 | - |
|
| 2414 | - $res = fabrique_jointures( |
|
| 2415 | - $boucle, |
|
| 2416 | - [ |
|
| 2417 | - [ |
|
| 2418 | - $boucle->id_table, |
|
| 2419 | - $intermediaire, |
|
| 2420 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2421 | - ], |
|
| 2422 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2423 | - ], |
|
| 2424 | - $cond, |
|
| 2425 | - $desc, |
|
| 2426 | - $boucle->id_table, |
|
| 2427 | - [$col] |
|
| 2428 | - ); |
|
| 2429 | - |
|
| 2430 | - return $res; |
|
| 2402 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2403 | + |
|
| 2404 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2405 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2406 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2407 | + |
|
| 2408 | + if (!$intermediaire or !$arrivee) { |
|
| 2409 | + return ''; |
|
| 2410 | + } |
|
| 2411 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2412 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2413 | + |
|
| 2414 | + $res = fabrique_jointures( |
|
| 2415 | + $boucle, |
|
| 2416 | + [ |
|
| 2417 | + [ |
|
| 2418 | + $boucle->id_table, |
|
| 2419 | + $intermediaire, |
|
| 2420 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2421 | + ], |
|
| 2422 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2423 | + ], |
|
| 2424 | + $cond, |
|
| 2425 | + $desc, |
|
| 2426 | + $boucle->id_table, |
|
| 2427 | + [$col] |
|
| 2428 | + ); |
|
| 2429 | + |
|
| 2430 | + return $res; |
|
| 2431 | 2431 | } |
| 2432 | 2432 | |
| 2433 | 2433 | |
@@ -2444,17 +2444,17 @@ discard block |
||
| 2444 | 2444 | * false sinon. |
| 2445 | 2445 | **/ |
| 2446 | 2446 | function trouver_champ($champ, $where) { |
| 2447 | - if (!is_array($where)) { |
|
| 2448 | - return preg_match($champ, $where); |
|
| 2449 | - } else { |
|
| 2450 | - foreach ($where as $clause) { |
|
| 2451 | - if (trouver_champ($champ, $clause)) { |
|
| 2452 | - return true; |
|
| 2453 | - } |
|
| 2454 | - } |
|
| 2455 | - |
|
| 2456 | - return false; |
|
| 2457 | - } |
|
| 2447 | + if (!is_array($where)) { |
|
| 2448 | + return preg_match($champ, $where); |
|
| 2449 | + } else { |
|
| 2450 | + foreach ($where as $clause) { |
|
| 2451 | + if (trouver_champ($champ, $clause)) { |
|
| 2452 | + return true; |
|
| 2453 | + } |
|
| 2454 | + } |
|
| 2455 | + |
|
| 2456 | + return false; |
|
| 2457 | + } |
|
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | |
@@ -2480,130 +2480,130 @@ discard block |
||
| 2480 | 2480 | * - string $args_sql Suite des arguments du critère. ? |
| 2481 | 2481 | **/ |
| 2482 | 2482 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2483 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2484 | - if (count($crit->param) == 0) { |
|
| 2485 | - $op = '='; |
|
| 2486 | - $col = $val = $crit->op; |
|
| 2487 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2488 | - $val = $r[2]; |
|
| 2489 | - } |
|
| 2490 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2491 | - if ($val == 'lang') { |
|
| 2492 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2493 | - } else { |
|
| 2494 | - $defaut = null; |
|
| 2495 | - if ($val == 'id_parent') { |
|
| 2496 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2497 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2498 | - // pour eviter l'erreur SQL |
|
| 2499 | - $val = $boucles[$idb]->primary; |
|
| 2500 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2501 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2502 | - } elseif ($val == 'id_enfant') { |
|
| 2503 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2504 | - // de la boucle superieure |
|
| 2505 | - $val = 'id_parent'; |
|
| 2506 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2507 | - // un critere conditionnel sur date est traite a part |
|
| 2508 | - // car la date est mise d'office par SPIP, |
|
| 2509 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2513 | - $val = [kwote($val)]; |
|
| 2514 | - } |
|
| 2515 | - } else { |
|
| 2516 | - // comparaison explicite |
|
| 2517 | - // le phraseur impose que le premier param soit du texte |
|
| 2518 | - $params = $crit->param; |
|
| 2519 | - $op = $crit->op; |
|
| 2520 | - if ($op == '==') { |
|
| 2521 | - $op = 'REGEXP'; |
|
| 2522 | - } |
|
| 2523 | - $col = array_shift($params); |
|
| 2524 | - $col = $col[0]->texte; |
|
| 2525 | - |
|
| 2526 | - $val = []; |
|
| 2527 | - $parent = $boucles[$idb]->id_parent; |
|
| 2528 | - |
|
| 2529 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2530 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2531 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2532 | - if ( |
|
| 2533 | - count($params) == 1 |
|
| 2534 | - and count($params[0]) == 3 |
|
| 2535 | - and $params[0][0]->type == 'texte' |
|
| 2536 | - and $params[0][2]->type == 'texte' |
|
| 2537 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2538 | - and (($p == "'") or ($p == '"')) |
|
| 2539 | - and $params[0][1]->type == 'champ' |
|
| 2540 | - ) { |
|
| 2541 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2542 | - } else { |
|
| 2543 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2544 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2545 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2546 | - $val[] = $a; |
|
| 2547 | - } else { |
|
| 2548 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2549 | - } // toujours quoter en char ici |
|
| 2550 | - } |
|
| 2551 | - } |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - $fct = $args_sql = ''; |
|
| 2555 | - // fonction SQL ? |
|
| 2556 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2557 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2558 | - $fct = $m[1]; |
|
| 2559 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2560 | - $col = $a[1]; |
|
| 2561 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2562 | - $col = $m[1]; |
|
| 2563 | - $args_sql = $m[2]; |
|
| 2564 | - } |
|
| 2565 | - $args_sql .= $a[2]; |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2483 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2484 | + if (count($crit->param) == 0) { |
|
| 2485 | + $op = '='; |
|
| 2486 | + $col = $val = $crit->op; |
|
| 2487 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2488 | + $val = $r[2]; |
|
| 2489 | + } |
|
| 2490 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2491 | + if ($val == 'lang') { |
|
| 2492 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2493 | + } else { |
|
| 2494 | + $defaut = null; |
|
| 2495 | + if ($val == 'id_parent') { |
|
| 2496 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2497 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2498 | + // pour eviter l'erreur SQL |
|
| 2499 | + $val = $boucles[$idb]->primary; |
|
| 2500 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2501 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2502 | + } elseif ($val == 'id_enfant') { |
|
| 2503 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2504 | + // de la boucle superieure |
|
| 2505 | + $val = 'id_parent'; |
|
| 2506 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2507 | + // un critere conditionnel sur date est traite a part |
|
| 2508 | + // car la date est mise d'office par SPIP, |
|
| 2509 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2513 | + $val = [kwote($val)]; |
|
| 2514 | + } |
|
| 2515 | + } else { |
|
| 2516 | + // comparaison explicite |
|
| 2517 | + // le phraseur impose que le premier param soit du texte |
|
| 2518 | + $params = $crit->param; |
|
| 2519 | + $op = $crit->op; |
|
| 2520 | + if ($op == '==') { |
|
| 2521 | + $op = 'REGEXP'; |
|
| 2522 | + } |
|
| 2523 | + $col = array_shift($params); |
|
| 2524 | + $col = $col[0]->texte; |
|
| 2525 | + |
|
| 2526 | + $val = []; |
|
| 2527 | + $parent = $boucles[$idb]->id_parent; |
|
| 2528 | + |
|
| 2529 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2530 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2531 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2532 | + if ( |
|
| 2533 | + count($params) == 1 |
|
| 2534 | + and count($params[0]) == 3 |
|
| 2535 | + and $params[0][0]->type == 'texte' |
|
| 2536 | + and $params[0][2]->type == 'texte' |
|
| 2537 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2538 | + and (($p == "'") or ($p == '"')) |
|
| 2539 | + and $params[0][1]->type == 'champ' |
|
| 2540 | + ) { |
|
| 2541 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2542 | + } else { |
|
| 2543 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2544 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2545 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2546 | + $val[] = $a; |
|
| 2547 | + } else { |
|
| 2548 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2549 | + } // toujours quoter en char ici |
|
| 2550 | + } |
|
| 2551 | + } |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + $fct = $args_sql = ''; |
|
| 2555 | + // fonction SQL ? |
|
| 2556 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2557 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2558 | + $fct = $m[1]; |
|
| 2559 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2560 | + $col = $a[1]; |
|
| 2561 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2562 | + $col = $m[1]; |
|
| 2563 | + $args_sql = $m[2]; |
|
| 2564 | + } |
|
| 2565 | + $args_sql .= $a[2]; |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2569 | 2569 | } |
| 2570 | 2570 | |
| 2571 | 2571 | // compatibilite ancienne version |
| 2572 | 2572 | |
| 2573 | 2573 | // https://code.spip.net/@calculer_vieux_in |
| 2574 | 2574 | function calculer_vieux_in($params) { |
| 2575 | - $deb = $params[0][0]; |
|
| 2576 | - $k = count($params) - 1; |
|
| 2577 | - $last = $params[$k]; |
|
| 2578 | - $j = count($last) - 1; |
|
| 2579 | - $last = $last[$j]; |
|
| 2580 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2581 | - |
|
| 2582 | - if ( |
|
| 2583 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2584 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2585 | - ) { |
|
| 2586 | - return $params; |
|
| 2587 | - } |
|
| 2588 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2589 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2590 | - $last = $params[$k][$j]; |
|
| 2591 | - $n = strlen($last->texte); |
|
| 2592 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2593 | - $newp = []; |
|
| 2594 | - foreach ($params as $v) { |
|
| 2595 | - if ($v[0]->type != 'texte') { |
|
| 2596 | - $newp[] = $v; |
|
| 2597 | - } else { |
|
| 2598 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2599 | - $t = new Texte(); |
|
| 2600 | - $t->texte = $x; |
|
| 2601 | - $newp[] = [$t]; |
|
| 2602 | - } |
|
| 2603 | - } |
|
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - return $newp; |
|
| 2575 | + $deb = $params[0][0]; |
|
| 2576 | + $k = count($params) - 1; |
|
| 2577 | + $last = $params[$k]; |
|
| 2578 | + $j = count($last) - 1; |
|
| 2579 | + $last = $last[$j]; |
|
| 2580 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2581 | + |
|
| 2582 | + if ( |
|
| 2583 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2584 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2585 | + ) { |
|
| 2586 | + return $params; |
|
| 2587 | + } |
|
| 2588 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2589 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2590 | + $last = $params[$k][$j]; |
|
| 2591 | + $n = strlen($last->texte); |
|
| 2592 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2593 | + $newp = []; |
|
| 2594 | + foreach ($params as $v) { |
|
| 2595 | + if ($v[0]->type != 'texte') { |
|
| 2596 | + $newp[] = $v; |
|
| 2597 | + } else { |
|
| 2598 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2599 | + $t = new Texte(); |
|
| 2600 | + $t->texte = $x; |
|
| 2601 | + $newp[] = [$t]; |
|
| 2602 | + } |
|
| 2603 | + } |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + return $newp; |
|
| 2607 | 2607 | } |
| 2608 | 2608 | |
| 2609 | 2609 | /** |
@@ -2622,89 +2622,89 @@ discard block |
||
| 2622 | 2622 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2623 | 2623 | **/ |
| 2624 | 2624 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2625 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2626 | - return ''; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - $boucle = $boucles[$idb]; |
|
| 2630 | - $table = $boucle->show; |
|
| 2631 | - |
|
| 2632 | - // si c'est une colonne de la table, ne rien faire |
|
| 2633 | - if (isset($table['field'][$col])) { |
|
| 2634 | - return ''; |
|
| 2635 | - } |
|
| 2636 | - |
|
| 2637 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2638 | - return ''; |
|
| 2639 | - } |
|
| 2640 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2641 | - |
|
| 2642 | - $col = $regs[1]; |
|
| 2643 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2644 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2645 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2646 | - |
|
| 2647 | - if (isset($table['field']["date$suite"])) { |
|
| 2648 | - $date_orig = 'date' . $suite; |
|
| 2649 | - } else { |
|
| 2650 | - $date_orig = substr($suite, 1); |
|
| 2651 | - } |
|
| 2652 | - $pred = $date_orig; |
|
| 2653 | - } else { |
|
| 2654 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2655 | - $pred = 'date'; |
|
| 2656 | - } |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2660 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2661 | - ") . '\""; |
|
| 2662 | - |
|
| 2663 | - $col_vraie = $date_orig; |
|
| 2664 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2665 | - |
|
| 2666 | - switch ($col) { |
|
| 2667 | - case 'date': |
|
| 2668 | - $col = $date_orig; |
|
| 2669 | - break; |
|
| 2670 | - case 'jour': |
|
| 2671 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2672 | - break; |
|
| 2673 | - case 'mois': |
|
| 2674 | - $col = "MONTH($date_orig)"; |
|
| 2675 | - break; |
|
| 2676 | - case 'annee': |
|
| 2677 | - $col = "YEAR($date_orig)"; |
|
| 2678 | - break; |
|
| 2679 | - case 'heure': |
|
| 2680 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2681 | - break; |
|
| 2682 | - case 'age': |
|
| 2683 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | - break; |
|
| 2686 | - case 'age_relatif': |
|
| 2687 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2688 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | - break; |
|
| 2690 | - case 'jour_relatif': |
|
| 2691 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2692 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | - break; |
|
| 2694 | - case 'mois_relatif': |
|
| 2695 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2696 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2697 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2698 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2699 | - break; |
|
| 2700 | - case 'annee_relatif': |
|
| 2701 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2702 | - $date_orig . ')'; |
|
| 2703 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2704 | - break; |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - return [$col, $col_vraie]; |
|
| 2625 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2626 | + return ''; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + $boucle = $boucles[$idb]; |
|
| 2630 | + $table = $boucle->show; |
|
| 2631 | + |
|
| 2632 | + // si c'est une colonne de la table, ne rien faire |
|
| 2633 | + if (isset($table['field'][$col])) { |
|
| 2634 | + return ''; |
|
| 2635 | + } |
|
| 2636 | + |
|
| 2637 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2638 | + return ''; |
|
| 2639 | + } |
|
| 2640 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2641 | + |
|
| 2642 | + $col = $regs[1]; |
|
| 2643 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2644 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2645 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2646 | + |
|
| 2647 | + if (isset($table['field']["date$suite"])) { |
|
| 2648 | + $date_orig = 'date' . $suite; |
|
| 2649 | + } else { |
|
| 2650 | + $date_orig = substr($suite, 1); |
|
| 2651 | + } |
|
| 2652 | + $pred = $date_orig; |
|
| 2653 | + } else { |
|
| 2654 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2655 | + $pred = 'date'; |
|
| 2656 | + } |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2660 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2661 | + ") . '\""; |
|
| 2662 | + |
|
| 2663 | + $col_vraie = $date_orig; |
|
| 2664 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2665 | + |
|
| 2666 | + switch ($col) { |
|
| 2667 | + case 'date': |
|
| 2668 | + $col = $date_orig; |
|
| 2669 | + break; |
|
| 2670 | + case 'jour': |
|
| 2671 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2672 | + break; |
|
| 2673 | + case 'mois': |
|
| 2674 | + $col = "MONTH($date_orig)"; |
|
| 2675 | + break; |
|
| 2676 | + case 'annee': |
|
| 2677 | + $col = "YEAR($date_orig)"; |
|
| 2678 | + break; |
|
| 2679 | + case 'heure': |
|
| 2680 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2681 | + break; |
|
| 2682 | + case 'age': |
|
| 2683 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2684 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + break; |
|
| 2686 | + case 'age_relatif': |
|
| 2687 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2688 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | + break; |
|
| 2690 | + case 'jour_relatif': |
|
| 2691 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2692 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | + break; |
|
| 2694 | + case 'mois_relatif': |
|
| 2695 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2696 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2697 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2698 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2699 | + break; |
|
| 2700 | + case 'annee_relatif': |
|
| 2701 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2702 | + $date_orig . ')'; |
|
| 2703 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2704 | + break; |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + return [$col, $col_vraie]; |
|
| 2708 | 2708 | } |
| 2709 | 2709 | |
| 2710 | 2710 | /** |
@@ -2723,16 +2723,16 @@ discard block |
||
| 2723 | 2723 | * de colonne SQL et une date. |
| 2724 | 2724 | **/ |
| 2725 | 2725 | function calculer_param_date($date_compare, $date_orig) { |
| 2726 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2727 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2728 | - $date_compare = '\'$x\''; |
|
| 2729 | - } else { |
|
| 2730 | - $init = $date_compare; |
|
| 2731 | - } |
|
| 2732 | - |
|
| 2733 | - return |
|
| 2734 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2735 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2726 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2727 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2728 | + $date_compare = '\'$x\''; |
|
| 2729 | + } else { |
|
| 2730 | + $init = $date_compare; |
|
| 2731 | + } |
|
| 2732 | + |
|
| 2733 | + return |
|
| 2734 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2735 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2736 | 2736 | } |
| 2737 | 2737 | |
| 2738 | 2738 | /** |
@@ -2750,20 +2750,20 @@ discard block |
||
| 2750 | 2750 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2751 | 2751 | */ |
| 2752 | 2752 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2753 | - $boucle = &$boucles[$idb]; |
|
| 2754 | - |
|
| 2755 | - $args = []; |
|
| 2756 | - foreach ($crit->param as &$param) { |
|
| 2757 | - array_push( |
|
| 2758 | - $args, |
|
| 2759 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2760 | - ); |
|
| 2761 | - } |
|
| 2753 | + $boucle = &$boucles[$idb]; |
|
| 2762 | 2754 | |
| 2763 | - $boucle->hash .= ' |
|
| 2755 | + $args = []; |
|
| 2756 | + foreach ($crit->param as &$param) { |
|
| 2757 | + array_push( |
|
| 2758 | + $args, |
|
| 2759 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2760 | + ); |
|
| 2761 | + } |
|
| 2762 | + |
|
| 2763 | + $boucle->hash .= ' |
|
| 2764 | 2764 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2765 | 2765 | |
| 2766 | - $boucle->hash .= ' |
|
| 2766 | + $boucle->hash .= ' |
|
| 2767 | 2767 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2768 | 2768 | } |
| 2769 | 2769 | |
@@ -2781,8 +2781,8 @@ discard block |
||
| 2781 | 2781 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2782 | 2782 | */ |
| 2783 | 2783 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2784 | - $boucle = &$boucles[$idb]; |
|
| 2785 | - $boucle->hash .= ' |
|
| 2784 | + $boucle = &$boucles[$idb]; |
|
| 2785 | + $boucle->hash .= ' |
|
| 2786 | 2786 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2787 | 2787 | } |
| 2788 | 2788 | |
@@ -2798,12 +2798,12 @@ discard block |
||
| 2798 | 2798 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2799 | 2799 | */ |
| 2800 | 2800 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2801 | - $boucle = &$boucles[$idb]; |
|
| 2802 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2803 | - foreach ($crit->param as $param) { |
|
| 2804 | - $boucle->hash .= ' |
|
| 2801 | + $boucle = &$boucles[$idb]; |
|
| 2802 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2803 | + foreach ($crit->param as $param) { |
|
| 2804 | + $boucle->hash .= ' |
|
| 2805 | 2805 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2806 | - } |
|
| 2806 | + } |
|
| 2807 | 2807 | } |
| 2808 | 2808 | |
| 2809 | 2809 | /** |
@@ -2820,16 +2820,16 @@ discard block |
||
| 2820 | 2820 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2821 | 2821 | */ |
| 2822 | 2822 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2823 | - $boucle = &$boucles[$idb]; |
|
| 2824 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2825 | - foreach ($crit->param as $param) { |
|
| 2826 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2827 | - $param, |
|
| 2828 | - $idb, |
|
| 2829 | - $boucles, |
|
| 2830 | - $boucles[$idb]->id_parent |
|
| 2831 | - ) . ";\n"; |
|
| 2832 | - } |
|
| 2823 | + $boucle = &$boucles[$idb]; |
|
| 2824 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2825 | + foreach ($crit->param as $param) { |
|
| 2826 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2827 | + $param, |
|
| 2828 | + $idb, |
|
| 2829 | + $boucles, |
|
| 2830 | + $boucles[$idb]->id_parent |
|
| 2831 | + ) . ";\n"; |
|
| 2832 | + } |
|
| 2833 | 2833 | } |
| 2834 | 2834 | |
| 2835 | 2835 | /** |
@@ -2854,16 +2854,16 @@ discard block |
||
| 2854 | 2854 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2855 | 2855 | */ |
| 2856 | 2856 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2857 | - $boucle = &$boucles[$idb]; |
|
| 2858 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2859 | - foreach ($crit->param as $param) { |
|
| 2860 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2861 | - $param, |
|
| 2862 | - $idb, |
|
| 2863 | - $boucles, |
|
| 2864 | - $boucles[$idb]->id_parent |
|
| 2865 | - ) . ";\n"; |
|
| 2866 | - } |
|
| 2857 | + $boucle = &$boucles[$idb]; |
|
| 2858 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2859 | + foreach ($crit->param as $param) { |
|
| 2860 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2861 | + $param, |
|
| 2862 | + $idb, |
|
| 2863 | + $boucles, |
|
| 2864 | + $boucles[$idb]->id_parent |
|
| 2865 | + ) . ";\n"; |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2878,11 +2878,11 @@ discard block |
||
| 2878 | 2878 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2879 | 2879 | */ |
| 2880 | 2880 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2881 | - $boucle = &$boucles[$idb]; |
|
| 2882 | - foreach ($crit->param as $param) { |
|
| 2883 | - $boucle->hash .= ' |
|
| 2881 | + $boucle = &$boucles[$idb]; |
|
| 2882 | + foreach ($crit->param as $param) { |
|
| 2883 | + $boucle->hash .= ' |
|
| 2884 | 2884 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2885 | - } |
|
| 2885 | + } |
|
| 2886 | 2886 | } |
| 2887 | 2887 | |
| 2888 | 2888 | |
@@ -2914,20 +2914,20 @@ discard block |
||
| 2914 | 2914 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2915 | 2915 | */ |
| 2916 | 2916 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2917 | - $boucle = &$boucles[$idb]; |
|
| 2918 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2919 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2920 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2921 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2922 | - if ($crit->param) { |
|
| 2923 | - foreach ($crit->param as $param) { |
|
| 2924 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2925 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2926 | - } |
|
| 2927 | - // interdire {si 0} aussi ! |
|
| 2928 | - } else { |
|
| 2929 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2930 | - } |
|
| 2917 | + $boucle = &$boucles[$idb]; |
|
| 2918 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2919 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2920 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2921 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2922 | + if ($crit->param) { |
|
| 2923 | + foreach ($crit->param as $param) { |
|
| 2924 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2925 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2926 | + } |
|
| 2927 | + // interdire {si 0} aussi ! |
|
| 2928 | + } else { |
|
| 2929 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2930 | + } |
|
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | /** |
@@ -2944,8 +2944,8 @@ discard block |
||
| 2944 | 2944 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2945 | 2945 | */ |
| 2946 | 2946 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2947 | - $boucle = &$boucles[$idb]; |
|
| 2948 | - $boucle->hash .= ' |
|
| 2947 | + $boucle = &$boucles[$idb]; |
|
| 2948 | + $boucle->hash .= ' |
|
| 2949 | 2949 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2950 | 2950 | $command[\'sourcemode\'] = \'table\';'; |
| 2951 | 2951 | } |
@@ -2966,29 +2966,29 @@ discard block |
||
| 2966 | 2966 | */ |
| 2967 | 2967 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2968 | 2968 | |
| 2969 | - $not = $crit->not; |
|
| 2970 | - $boucle = &$boucles[$idb]; |
|
| 2971 | - $primary = $boucle->primary; |
|
| 2969 | + $not = $crit->not; |
|
| 2970 | + $boucle = &$boucles[$idb]; |
|
| 2971 | + $primary = $boucle->primary; |
|
| 2972 | 2972 | |
| 2973 | - if (!$primary or strpos($primary, ',')) { |
|
| 2974 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2973 | + if (!$primary or strpos($primary, ',')) { |
|
| 2974 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2975 | 2975 | |
| 2976 | - return; |
|
| 2977 | - } |
|
| 2978 | - $table = $boucle->type_requete; |
|
| 2979 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2976 | + return; |
|
| 2977 | + } |
|
| 2978 | + $table = $boucle->type_requete; |
|
| 2979 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2980 | 2980 | |
| 2981 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2982 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2983 | - 'id_parent'; |
|
| 2981 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2982 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2983 | + 'id_parent'; |
|
| 2984 | 2984 | |
| 2985 | - $in = 'IN'; |
|
| 2986 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2987 | - if ($not) { |
|
| 2988 | - $where = ["'NOT'", $where]; |
|
| 2989 | - } |
|
| 2985 | + $in = 'IN'; |
|
| 2986 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2987 | + if ($not) { |
|
| 2988 | + $where = ["'NOT'", $where]; |
|
| 2989 | + } |
|
| 2990 | 2990 | |
| 2991 | - $boucle->where[] = $where; |
|
| 2991 | + $boucle->where[] = $where; |
|
| 2992 | 2992 | } |
| 2993 | 2993 | |
| 2994 | 2994 | /** |
@@ -3004,8 +3004,8 @@ discard block |
||
| 3004 | 3004 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3005 | 3005 | */ |
| 3006 | 3006 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3007 | - $not = $crit->not; |
|
| 3008 | - $crit->not = $not ? false : true; |
|
| 3009 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3010 | - $crit->not = $not; |
|
| 3007 | + $not = $crit->not; |
|
| 3008 | + $crit->not = $not ? false : true; |
|
| 3009 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3010 | + $crit->not = $not; |
|
| 3011 | 3011 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | **/ |
| 27 | 27 | |
| 28 | 28 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 29 | - return; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | * Code PHP si cet argument est présent, sinon null |
| 49 | 49 | **/ |
| 50 | 50 | function interprete_argument_balise($n, $p) { |
| 51 | - if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) { |
|
| 52 | - return calculer_liste( |
|
| 53 | - $p->param[0][$n], |
|
| 54 | - $p->descr, |
|
| 55 | - $p->boucles, |
|
| 56 | - $p->id_boucle |
|
| 57 | - ); |
|
| 58 | - } else { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 51 | + if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) { |
|
| 52 | + return calculer_liste( |
|
| 53 | + $p->param[0][$n], |
|
| 54 | + $p->descr, |
|
| 55 | + $p->boucles, |
|
| 56 | + $p->id_boucle |
|
| 57 | + ); |
|
| 58 | + } else { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * Pile complétée par le code à générer |
| 78 | 78 | **/ |
| 79 | 79 | function balise_NOM_SITE_SPIP_dist($p) { |
| 80 | - $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 80 | + $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 81 | 81 | |
| 82 | - #$p->interdire_scripts = true; |
|
| 83 | - return $p; |
|
| 82 | + #$p->interdire_scripts = true; |
|
| 83 | + return $p; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | * Pile complétée par le code à générer |
| 97 | 97 | **/ |
| 98 | 98 | function balise_EMAIL_WEBMASTER_dist($p) { |
| 99 | - $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 99 | + $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 100 | 100 | |
| 101 | - #$p->interdire_scripts = true; |
|
| 102 | - return $p; |
|
| 101 | + #$p->interdire_scripts = true; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * Pile complétée par le code à générer |
| 116 | 116 | **/ |
| 117 | 117 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { |
| 118 | - $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 118 | + $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 119 | 119 | |
| 120 | - #$p->interdire_scripts = true; |
|
| 121 | - return $p; |
|
| 120 | + #$p->interdire_scripts = true; |
|
| 121 | + return $p; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * Pile complétée par le code à générer |
| 140 | 140 | **/ |
| 141 | 141 | function balise_CHARSET_dist($p) { |
| 142 | - $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 142 | + $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 143 | 143 | |
| 144 | - #$p->interdire_scripts = true; |
|
| 145 | - return $p; |
|
| 144 | + #$p->interdire_scripts = true; |
|
| 145 | + return $p; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * Pile complétée par le code à générer |
| 168 | 168 | **/ |
| 169 | 169 | function balise_LANG_LEFT_dist($p) { |
| 170 | - $_lang = champ_sql('lang', $p); |
|
| 171 | - $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | - $p->interdire_scripts = false; |
|
| 170 | + $_lang = champ_sql('lang', $p); |
|
| 171 | + $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | + $p->interdire_scripts = false; |
|
| 173 | 173 | |
| 174 | - return $p; |
|
| 174 | + return $p; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * Pile complétée par le code à générer |
| 192 | 192 | **/ |
| 193 | 193 | function balise_LANG_RIGHT_dist($p) { |
| 194 | - $_lang = champ_sql('lang', $p); |
|
| 195 | - $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | - $p->interdire_scripts = false; |
|
| 194 | + $_lang = champ_sql('lang', $p); |
|
| 195 | + $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | + $p->interdire_scripts = false; |
|
| 197 | 197 | |
| 198 | - return $p; |
|
| 198 | + return $p; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * Pile complétée par le code à générer |
| 221 | 221 | **/ |
| 222 | 222 | function balise_LANG_DIR_dist($p) { |
| 223 | - $_lang = champ_sql('lang', $p); |
|
| 224 | - $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | - $p->interdire_scripts = false; |
|
| 223 | + $_lang = champ_sql('lang', $p); |
|
| 224 | + $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | + $p->interdire_scripts = false; |
|
| 226 | 226 | |
| 227 | - return $p; |
|
| 227 | + return $p; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * Pile complétée par le code à générer |
| 242 | 242 | **/ |
| 243 | 243 | function balise_PUCE_dist($p) { |
| 244 | - $p->code = 'definir_puce()'; |
|
| 245 | - $p->interdire_scripts = false; |
|
| 244 | + $p->code = 'definir_puce()'; |
|
| 245 | + $p->interdire_scripts = false; |
|
| 246 | 246 | |
| 247 | - return $p; |
|
| 247 | + return $p; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * Pile completée du code PHP d'exécution de la balise |
| 269 | 269 | */ |
| 270 | 270 | function balise_DATE_dist($p) { |
| 271 | - $p->code = champ_sql('date', $p); |
|
| 271 | + $p->code = champ_sql('date', $p); |
|
| 272 | 272 | |
| 273 | - return $p; |
|
| 273 | + return $p; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * Pile completée du code PHP d'exécution de la balise |
| 291 | 291 | */ |
| 292 | 292 | function balise_DATE_REDAC_dist($p) { |
| 293 | - $p->code = champ_sql('date_redac', $p); |
|
| 294 | - $p->interdire_scripts = false; |
|
| 293 | + $p->code = champ_sql('date_redac', $p); |
|
| 294 | + $p->interdire_scripts = false; |
|
| 295 | 295 | |
| 296 | - return $p; |
|
| 296 | + return $p; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Pile completée du code PHP d'exécution de la balise |
| 313 | 313 | */ |
| 314 | 314 | function balise_DATE_MODIF_dist($p) { |
| 315 | - $p->code = champ_sql('date_modif', $p); |
|
| 316 | - $p->interdire_scripts = false; |
|
| 315 | + $p->code = champ_sql('date_modif', $p); |
|
| 316 | + $p->interdire_scripts = false; |
|
| 317 | 317 | |
| 318 | - return $p; |
|
| 318 | + return $p; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | * Pile completée du code PHP d'exécution de la balise |
| 334 | 334 | */ |
| 335 | 335 | function balise_DATE_NOUVEAUTES_dist($p) { |
| 336 | - $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 336 | + $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 337 | 337 | AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ? |
| 338 | 338 | \$GLOBALS['meta']['dernier_envoi_neuf'] : |
| 339 | 339 | \"'0000-00-00'\")"; |
| 340 | - $p->interdire_scripts = false; |
|
| 340 | + $p->interdire_scripts = false; |
|
| 341 | 341 | |
| 342 | - return $p; |
|
| 342 | + return $p; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * Pile completée du code PHP d'exécution de la balise |
| 358 | 358 | */ |
| 359 | 359 | function balise_DOSSIER_SQUELETTE_dist($p) { |
| 360 | - $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | - $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | - $p->interdire_scripts = false; |
|
| 360 | + $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | + $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | + $p->interdire_scripts = false; |
|
| 363 | 363 | |
| 364 | - return $p; |
|
| 364 | + return $p; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * Pile completée du code PHP d'exécution de la balise |
| 377 | 377 | */ |
| 378 | 378 | function balise_SQUELETTE_dist($p) { |
| 379 | - $code = addslashes($p->descr['sourcefile']); |
|
| 380 | - $p->code = "'$code'" . |
|
| 381 | - $p->interdire_scripts = false; |
|
| 379 | + $code = addslashes($p->descr['sourcefile']); |
|
| 380 | + $p->code = "'$code'" . |
|
| 381 | + $p->interdire_scripts = false; |
|
| 382 | 382 | |
| 383 | - return $p; |
|
| 383 | + return $p; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | * Pile completée du code PHP d'exécution de la balise |
| 400 | 400 | */ |
| 401 | 401 | function balise_SPIP_VERSION_dist($p) { |
| 402 | - $p->code = 'spip_version()'; |
|
| 403 | - $p->interdire_scripts = false; |
|
| 402 | + $p->code = 'spip_version()'; |
|
| 403 | + $p->interdire_scripts = false; |
|
| 404 | 404 | |
| 405 | - return $p; |
|
| 405 | + return $p; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -428,18 +428,18 @@ discard block |
||
| 428 | 428 | * Pile complétée par le code à générer |
| 429 | 429 | **/ |
| 430 | 430 | function balise_NOM_SITE_dist($p) { |
| 431 | - if (!$p->etoile) { |
|
| 432 | - $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | - champ_sql('url_site', $p) . ',' . |
|
| 434 | - champ_sql('nom_site', $p) . |
|
| 435 | - ", 'titre', \$connect, false))"; |
|
| 436 | - } else { |
|
| 437 | - $p->code = champ_sql('nom_site', $p); |
|
| 438 | - } |
|
| 431 | + if (!$p->etoile) { |
|
| 432 | + $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | + champ_sql('url_site', $p) . ',' . |
|
| 434 | + champ_sql('nom_site', $p) . |
|
| 435 | + ", 'titre', \$connect, false))"; |
|
| 436 | + } else { |
|
| 437 | + $p->code = champ_sql('nom_site', $p); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $p->interdire_scripts = true; |
|
| 440 | + $p->interdire_scripts = true; |
|
| 441 | 441 | |
| 442 | - return $p; |
|
| 442 | + return $p; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | * Pile complétée par le code à générer |
| 457 | 457 | **/ |
| 458 | 458 | function balise_NOTES_dist($p) { |
| 459 | - // Recuperer les notes |
|
| 460 | - $p->code = 'calculer_notes()'; |
|
| 459 | + // Recuperer les notes |
|
| 460 | + $p->code = 'calculer_notes()'; |
|
| 461 | 461 | |
| 462 | - #$p->interdire_scripts = true; |
|
| 463 | - return $p; |
|
| 462 | + #$p->interdire_scripts = true; |
|
| 463 | + return $p; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * Pile complétée par le code à générer |
| 483 | 483 | **/ |
| 484 | 484 | function balise_RECHERCHE_dist($p) { |
| 485 | - $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | - $p->interdire_scripts = false; |
|
| 485 | + $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | + $p->interdire_scripts = false; |
|
| 487 | 487 | |
| 488 | - return $p; |
|
| 488 | + return $p; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -503,17 +503,17 @@ discard block |
||
| 503 | 503 | * Pile complétée par le code à générer |
| 504 | 504 | **/ |
| 505 | 505 | function balise_COMPTEUR_BOUCLE_dist($p) { |
| 506 | - $b = index_boucle_mere($p); |
|
| 507 | - if ($b === '') { |
|
| 508 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | - erreur_squelette($msg, $p); |
|
| 510 | - } else { |
|
| 511 | - $p->code = "\$Numrows['$b']['compteur_boucle']"; |
|
| 512 | - $p->boucles[$b]->cptrows = true; |
|
| 513 | - $p->interdire_scripts = false; |
|
| 506 | + $b = index_boucle_mere($p); |
|
| 507 | + if ($b === '') { |
|
| 508 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | + erreur_squelette($msg, $p); |
|
| 510 | + } else { |
|
| 511 | + $p->code = "\$Numrows['$b']['compteur_boucle']"; |
|
| 512 | + $p->boucles[$b]->cptrows = true; |
|
| 513 | + $p->interdire_scripts = false; |
|
| 514 | 514 | |
| 515 | - return $p; |
|
| 516 | - } |
|
| 515 | + return $p; |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -531,17 +531,17 @@ discard block |
||
| 531 | 531 | * Pile complétée par le code à générer |
| 532 | 532 | **/ |
| 533 | 533 | function balise_TOTAL_BOUCLE_dist($p) { |
| 534 | - $b = index_boucle_mere($p); |
|
| 535 | - if ($b === '') { |
|
| 536 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | - erreur_squelette($msg, $p); |
|
| 538 | - } else { |
|
| 539 | - $p->code = "\$Numrows['$b']['total']"; |
|
| 540 | - $p->boucles[$b]->numrows = true; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 534 | + $b = index_boucle_mere($p); |
|
| 535 | + if ($b === '') { |
|
| 536 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | + erreur_squelette($msg, $p); |
|
| 538 | + } else { |
|
| 539 | + $p->code = "\$Numrows['$b']['total']"; |
|
| 540 | + $p->boucles[$b]->numrows = true; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - return $p; |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * Pile complétée par le code à générer |
| 562 | 562 | **/ |
| 563 | 563 | function balise_POINTS_dist($p) { |
| 564 | - return rindex_pile($p, 'points', 'recherche'); |
|
| 564 | + return rindex_pile($p, 'points', 'recherche'); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | * Pile complétée par le code à générer |
| 583 | 583 | **/ |
| 584 | 584 | function balise_POPULARITE_ABSOLUE_dist($p) { |
| 585 | - $p->code = 'ceil(' . |
|
| 586 | - champ_sql('popularite', $p) . |
|
| 587 | - ')'; |
|
| 588 | - $p->interdire_scripts = false; |
|
| 585 | + $p->code = 'ceil(' . |
|
| 586 | + champ_sql('popularite', $p) . |
|
| 587 | + ')'; |
|
| 588 | + $p->interdire_scripts = false; |
|
| 589 | 589 | |
| 590 | - return $p; |
|
| 590 | + return $p; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | * Pile complétée par le code à générer |
| 608 | 608 | **/ |
| 609 | 609 | function balise_POPULARITE_SITE_dist($p) { |
| 610 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | - $p->interdire_scripts = false; |
|
| 610 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | + $p->interdire_scripts = false; |
|
| 612 | 612 | |
| 613 | - return $p; |
|
| 613 | + return $p; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -631,10 +631,10 @@ discard block |
||
| 631 | 631 | * Pile complétée par le code à générer |
| 632 | 632 | **/ |
| 633 | 633 | function balise_POPULARITE_MAX_dist($p) { |
| 634 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | - $p->interdire_scripts = false; |
|
| 634 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | + $p->interdire_scripts = false; |
|
| 636 | 636 | |
| 637 | - return $p; |
|
| 637 | + return $p; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | |
@@ -660,15 +660,15 @@ discard block |
||
| 660 | 660 | * Pile complétée par le code à générer |
| 661 | 661 | **/ |
| 662 | 662 | function balise_VALEUR_dist($p) { |
| 663 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 664 | - $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 663 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 664 | + $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 665 | 665 | ; |
| 666 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | - $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | - } |
|
| 669 | - $p->interdire_scripts = true; |
|
| 666 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | + $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | + } |
|
| 669 | + $p->interdire_scripts = true; |
|
| 670 | 670 | |
| 671 | - return $p; |
|
| 671 | + return $p; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -697,16 +697,16 @@ discard block |
||
| 697 | 697 | * Pile complétée par le code à générer |
| 698 | 698 | **/ |
| 699 | 699 | function balise_EXPOSE_dist($p) { |
| 700 | - $on = "'on'"; |
|
| 701 | - $off = "''"; |
|
| 702 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | - $on = $v; |
|
| 704 | - if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | - $off = $v; |
|
| 706 | - } |
|
| 707 | - } |
|
| 700 | + $on = "'on'"; |
|
| 701 | + $off = "''"; |
|
| 702 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | + $on = $v; |
|
| 704 | + if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | + $off = $v; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return calculer_balise_expose($p, $on, $off); |
|
| 709 | + return calculer_balise_expose($p, $on, $off); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -724,35 +724,35 @@ discard block |
||
| 724 | 724 | * Pile complétée par le code à générer |
| 725 | 725 | **/ |
| 726 | 726 | function calculer_balise_expose($p, $on, $off) { |
| 727 | - $b = index_boucle($p); |
|
| 728 | - if (empty($p->boucles[$b]->primary)) { |
|
| 729 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | - erreur_squelette($msg, $p); |
|
| 731 | - } else { |
|
| 732 | - $key = $p->boucles[$b]->primary; |
|
| 733 | - $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | - $desc = $p->boucles[$b]->show; |
|
| 735 | - $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 727 | + $b = index_boucle($p); |
|
| 728 | + if (empty($p->boucles[$b]->primary)) { |
|
| 729 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | + erreur_squelette($msg, $p); |
|
| 731 | + } else { |
|
| 732 | + $key = $p->boucles[$b]->primary; |
|
| 733 | + $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | + $desc = $p->boucles[$b]->show; |
|
| 735 | + $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 736 | 736 | |
| 737 | - // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | - $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 737 | + // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | + $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 739 | 739 | |
| 740 | - if (isset($desc['field']['id_parent'])) { |
|
| 741 | - $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | - } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | - $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | - } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | - $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | - } else { |
|
| 747 | - $parent = "''"; |
|
| 748 | - } |
|
| 740 | + if (isset($desc['field']['id_parent'])) { |
|
| 741 | + $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | + } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | + $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | + } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | + $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | + } else { |
|
| 747 | + $parent = "''"; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | - } |
|
| 750 | + $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - $p->interdire_scripts = false; |
|
| 753 | + $p->interdire_scripts = false; |
|
| 754 | 754 | |
| 755 | - return $p; |
|
| 755 | + return $p; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -792,46 +792,46 @@ discard block |
||
| 792 | 792 | **/ |
| 793 | 793 | function balise_INTRODUCTION_dist($p) { |
| 794 | 794 | |
| 795 | - $type_objet = $p->type_requete; |
|
| 796 | - $cle_objet = id_table_objet($type_objet); |
|
| 797 | - $_id_objet = champ_sql($cle_objet, $p); |
|
| 798 | - |
|
| 799 | - // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 800 | - // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 801 | - $_introduction_longueur = 'null'; |
|
| 802 | - $_ligne = 'array('; |
|
| 803 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 804 | - if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 805 | - if (isset($desc['field']['descriptif'])) { |
|
| 806 | - $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 807 | - } |
|
| 808 | - if (isset($desc['field']['texte'])) { |
|
| 809 | - $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 810 | - } |
|
| 811 | - if (isset($desc['field']['chapo'])) { |
|
| 812 | - $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 813 | - } |
|
| 814 | - if (isset($desc['introduction_longueur'])) { |
|
| 815 | - $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 816 | - } |
|
| 817 | - } |
|
| 818 | - $_ligne .= ')'; |
|
| 819 | - |
|
| 820 | - // Récupérer la longueur et la suite passés en paramètres |
|
| 821 | - $_longueur_ou_suite = 'null'; |
|
| 822 | - if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 823 | - $_longueur_ou_suite = $v1; |
|
| 824 | - } |
|
| 825 | - $_suite = 'null'; |
|
| 826 | - if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 827 | - $_suite = $v2; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 831 | - |
|
| 832 | - #$p->interdire_scripts = true; |
|
| 833 | - $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 834 | - return $p; |
|
| 795 | + $type_objet = $p->type_requete; |
|
| 796 | + $cle_objet = id_table_objet($type_objet); |
|
| 797 | + $_id_objet = champ_sql($cle_objet, $p); |
|
| 798 | + |
|
| 799 | + // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 800 | + // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 801 | + $_introduction_longueur = 'null'; |
|
| 802 | + $_ligne = 'array('; |
|
| 803 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 804 | + if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 805 | + if (isset($desc['field']['descriptif'])) { |
|
| 806 | + $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 807 | + } |
|
| 808 | + if (isset($desc['field']['texte'])) { |
|
| 809 | + $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 810 | + } |
|
| 811 | + if (isset($desc['field']['chapo'])) { |
|
| 812 | + $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 813 | + } |
|
| 814 | + if (isset($desc['introduction_longueur'])) { |
|
| 815 | + $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | + $_ligne .= ')'; |
|
| 819 | + |
|
| 820 | + // Récupérer la longueur et la suite passés en paramètres |
|
| 821 | + $_longueur_ou_suite = 'null'; |
|
| 822 | + if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 823 | + $_longueur_ou_suite = $v1; |
|
| 824 | + } |
|
| 825 | + $_suite = 'null'; |
|
| 826 | + if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 827 | + $_suite = $v2; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 831 | + |
|
| 832 | + #$p->interdire_scripts = true; |
|
| 833 | + $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 834 | + return $p; |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | |
@@ -851,15 +851,15 @@ discard block |
||
| 851 | 851 | * Pile complétée par le code à générer |
| 852 | 852 | **/ |
| 853 | 853 | function balise_LANG_dist($p) { |
| 854 | - $_lang = champ_sql('lang', $p); |
|
| 855 | - if (!$p->etoile) { |
|
| 856 | - $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 857 | - } else { |
|
| 858 | - $p->code = "spip_htmlentities($_lang)"; |
|
| 859 | - } |
|
| 860 | - $p->interdire_scripts = false; |
|
| 854 | + $_lang = champ_sql('lang', $p); |
|
| 855 | + if (!$p->etoile) { |
|
| 856 | + $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 857 | + } else { |
|
| 858 | + $p->code = "spip_htmlentities($_lang)"; |
|
| 859 | + } |
|
| 860 | + $p->interdire_scripts = false; |
|
| 861 | 861 | |
| 862 | - return $p; |
|
| 862 | + return $p; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | /** |
@@ -881,48 +881,48 @@ discard block |
||
| 881 | 881 | * Pile complétée par le code à générer |
| 882 | 882 | */ |
| 883 | 883 | function balise_LESAUTEURS_dist($p) { |
| 884 | - // Cherche le champ 'lesauteurs' dans la pile |
|
| 885 | - $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 886 | - |
|
| 887 | - // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 888 | - // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 889 | - // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 890 | - // (cf extension sites/) |
|
| 891 | - if ( |
|
| 892 | - $_lesauteurs |
|
| 893 | - and $_lesauteurs != '@$Pile[0][\'lesauteurs\']' |
|
| 894 | - ) { |
|
| 895 | - $p->code = "safehtml($_lesauteurs)"; |
|
| 896 | - // $p->interdire_scripts = true; |
|
| 897 | - } else { |
|
| 898 | - if (!$p->id_boucle) { |
|
| 899 | - $connect = ''; |
|
| 900 | - $objet = 'article'; |
|
| 901 | - $id_table_objet = 'id_article'; |
|
| 902 | - } else { |
|
| 903 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 904 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 905 | - $type_boucle = $p->boucles[$b]->type_requete; |
|
| 906 | - $objet = objet_type($type_boucle); |
|
| 907 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 908 | - } |
|
| 909 | - $c = memoriser_contexte_compil($p); |
|
| 910 | - |
|
| 911 | - $p->code = sprintf( |
|
| 912 | - CODE_RECUPERER_FOND, |
|
| 913 | - "'modeles/lesauteurs'", |
|
| 914 | - "array('objet'=>'" . $objet . |
|
| 915 | - "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 916 | - ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 917 | - ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 918 | - ')', |
|
| 919 | - "'trim'=>true, 'compil'=>array($c)", |
|
| 920 | - _q($connect) |
|
| 921 | - ); |
|
| 922 | - $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - return $p; |
|
| 884 | + // Cherche le champ 'lesauteurs' dans la pile |
|
| 885 | + $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 886 | + |
|
| 887 | + // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 888 | + // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 889 | + // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 890 | + // (cf extension sites/) |
|
| 891 | + if ( |
|
| 892 | + $_lesauteurs |
|
| 893 | + and $_lesauteurs != '@$Pile[0][\'lesauteurs\']' |
|
| 894 | + ) { |
|
| 895 | + $p->code = "safehtml($_lesauteurs)"; |
|
| 896 | + // $p->interdire_scripts = true; |
|
| 897 | + } else { |
|
| 898 | + if (!$p->id_boucle) { |
|
| 899 | + $connect = ''; |
|
| 900 | + $objet = 'article'; |
|
| 901 | + $id_table_objet = 'id_article'; |
|
| 902 | + } else { |
|
| 903 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 904 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 905 | + $type_boucle = $p->boucles[$b]->type_requete; |
|
| 906 | + $objet = objet_type($type_boucle); |
|
| 907 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 908 | + } |
|
| 909 | + $c = memoriser_contexte_compil($p); |
|
| 910 | + |
|
| 911 | + $p->code = sprintf( |
|
| 912 | + CODE_RECUPERER_FOND, |
|
| 913 | + "'modeles/lesauteurs'", |
|
| 914 | + "array('objet'=>'" . $objet . |
|
| 915 | + "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 916 | + ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 917 | + ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 918 | + ')', |
|
| 919 | + "'trim'=>true, 'compil'=>array($c)", |
|
| 920 | + _q($connect) |
|
| 921 | + ); |
|
| 922 | + $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + return $p; |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | |
@@ -949,76 +949,76 @@ discard block |
||
| 949 | 949 | * Pile complétée par le code à générer |
| 950 | 950 | */ |
| 951 | 951 | function balise_RANG_dist($p) { |
| 952 | - $b = index_boucle($p); |
|
| 953 | - if ($b === '') { |
|
| 954 | - $msg = [ |
|
| 955 | - 'zbug_champ_hors_boucle', |
|
| 956 | - ['champ' => '#RANG'] |
|
| 957 | - ]; |
|
| 958 | - erreur_squelette($msg, $p); |
|
| 959 | - } else { |
|
| 960 | - // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 961 | - // dans la boucle immediatement englobante uniquement |
|
| 962 | - // sinon on compose le champ calcule |
|
| 963 | - $_rang = champ_sql('rang', $p, '', false); |
|
| 964 | - |
|
| 965 | - // si pas trouve de champ sql rang : |
|
| 966 | - if (!$_rang or $_rang == "''") { |
|
| 967 | - $boucle = &$p->boucles[$b]; |
|
| 968 | - |
|
| 969 | - // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 970 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 971 | - $desc = $trouver_table($boucle->id_table); |
|
| 972 | - $_titre = ''; # où extraire le numero ? |
|
| 973 | - |
|
| 974 | - if (isset($desc['titre'])) { |
|
| 975 | - $t = $desc['titre']; |
|
| 976 | - if ( |
|
| 977 | - // Soit on trouve avec la déclaration de la lang AVANT |
|
| 978 | - preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | - // Soit on prend depuis le début |
|
| 980 | - or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 981 | - ) { |
|
| 982 | - $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 983 | - $m = trim($m); |
|
| 984 | - if ($m != "''") { |
|
| 985 | - if (!preg_match(',\W,', $m)) { |
|
| 986 | - $m = $boucle->id_table . ".$m"; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - $m .= ' AS titre_rang'; |
|
| 990 | - |
|
| 991 | - $boucle->select[] = $m; |
|
| 992 | - $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 998 | - if (!$_titre) { |
|
| 999 | - $_titre = champ_sql('titre', $p); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1003 | - // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1004 | - $type_boucle = $boucle->type_requete; |
|
| 1005 | - $objet = objet_type($type_boucle); |
|
| 1006 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 1007 | - $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1008 | - $_env = '$Pile[0]'; |
|
| 1009 | - |
|
| 1010 | - if (!$_titre) {$_titre = "''"; |
|
| 1011 | - } |
|
| 1012 | - if (!$_primary) {$_primary = "''"; |
|
| 1013 | - } |
|
| 1014 | - $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - $p->code = $_rang; |
|
| 1018 | - $p->interdire_scripts = false; |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - return $p; |
|
| 952 | + $b = index_boucle($p); |
|
| 953 | + if ($b === '') { |
|
| 954 | + $msg = [ |
|
| 955 | + 'zbug_champ_hors_boucle', |
|
| 956 | + ['champ' => '#RANG'] |
|
| 957 | + ]; |
|
| 958 | + erreur_squelette($msg, $p); |
|
| 959 | + } else { |
|
| 960 | + // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 961 | + // dans la boucle immediatement englobante uniquement |
|
| 962 | + // sinon on compose le champ calcule |
|
| 963 | + $_rang = champ_sql('rang', $p, '', false); |
|
| 964 | + |
|
| 965 | + // si pas trouve de champ sql rang : |
|
| 966 | + if (!$_rang or $_rang == "''") { |
|
| 967 | + $boucle = &$p->boucles[$b]; |
|
| 968 | + |
|
| 969 | + // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 970 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 971 | + $desc = $trouver_table($boucle->id_table); |
|
| 972 | + $_titre = ''; # où extraire le numero ? |
|
| 973 | + |
|
| 974 | + if (isset($desc['titre'])) { |
|
| 975 | + $t = $desc['titre']; |
|
| 976 | + if ( |
|
| 977 | + // Soit on trouve avec la déclaration de la lang AVANT |
|
| 978 | + preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | + // Soit on prend depuis le début |
|
| 980 | + or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 981 | + ) { |
|
| 982 | + $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 983 | + $m = trim($m); |
|
| 984 | + if ($m != "''") { |
|
| 985 | + if (!preg_match(',\W,', $m)) { |
|
| 986 | + $m = $boucle->id_table . ".$m"; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + $m .= ' AS titre_rang'; |
|
| 990 | + |
|
| 991 | + $boucle->select[] = $m; |
|
| 992 | + $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 998 | + if (!$_titre) { |
|
| 999 | + $_titre = champ_sql('titre', $p); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1003 | + // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1004 | + $type_boucle = $boucle->type_requete; |
|
| 1005 | + $objet = objet_type($type_boucle); |
|
| 1006 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 1007 | + $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1008 | + $_env = '$Pile[0]'; |
|
| 1009 | + |
|
| 1010 | + if (!$_titre) {$_titre = "''"; |
|
| 1011 | + } |
|
| 1012 | + if (!$_primary) {$_primary = "''"; |
|
| 1013 | + } |
|
| 1014 | + $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + $p->code = $_rang; |
|
| 1018 | + $p->interdire_scripts = false; |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + return $p; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | |
@@ -1040,12 +1040,12 @@ discard block |
||
| 1040 | 1040 | * Pile complétée par le code à générer |
| 1041 | 1041 | **/ |
| 1042 | 1042 | function balise_POPULARITE_dist($p) { |
| 1043 | - $_popularite = champ_sql('popularite', $p); |
|
| 1044 | - $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1043 | + $_popularite = champ_sql('popularite', $p); |
|
| 1044 | + $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1045 | 1045 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; |
| 1046 | - $p->interdire_scripts = false; |
|
| 1046 | + $p->interdire_scripts = false; |
|
| 1047 | 1047 | |
| 1048 | - return $p; |
|
| 1048 | + return $p; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1056,8 +1056,8 @@ discard block |
||
| 1056 | 1056 | * l'absence peut-être due à une faute de frappe dans le contexte inclus. |
| 1057 | 1057 | */ |
| 1058 | 1058 | define( |
| 1059 | - 'CODE_PAGINATION', |
|
| 1060 | - '%s($Numrows["%s"]["grand_total"], |
|
| 1059 | + 'CODE_PAGINATION', |
|
| 1060 | + '%s($Numrows["%s"]["grand_total"], |
|
| 1061 | 1061 | %s, |
| 1062 | 1062 | isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)), |
| 1063 | 1063 | %5$s, %6$s, %7$s, %8$s, array(%9$s))' |
@@ -1094,75 +1094,75 @@ discard block |
||
| 1094 | 1094 | * Pile complétée par le code à générer |
| 1095 | 1095 | */ |
| 1096 | 1096 | function balise_PAGINATION_dist($p, $liste = 'true') { |
| 1097 | - $b = index_boucle_mere($p); |
|
| 1098 | - |
|
| 1099 | - // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1100 | - if ($b === '') { |
|
| 1101 | - $msg = [ |
|
| 1102 | - 'zbug_champ_hors_boucle', |
|
| 1103 | - ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1104 | - ]; |
|
| 1105 | - erreur_squelette($msg, $p); |
|
| 1106 | - |
|
| 1107 | - return $p; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1111 | - // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1112 | - if (!$p->boucles[$b]->mode_partie) { |
|
| 1113 | - if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1114 | - $msg = [ |
|
| 1115 | - 'zbug_pagination_sans_critere', |
|
| 1116 | - ['champ' => '#PAGINATION'] |
|
| 1117 | - ]; |
|
| 1118 | - erreur_squelette($msg, $p); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - return $p; |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - // a priori true |
|
| 1125 | - // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1126 | - // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1127 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1128 | - if (count($_contexte)) { |
|
| 1129 | - $key = key($_contexte); |
|
| 1130 | - if (is_numeric($key)) { |
|
| 1131 | - array_shift($_contexte); |
|
| 1132 | - $__modele = interprete_argument_balise(1, $p); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - if (count($_contexte)) { |
|
| 1137 | - $code_contexte = implode(',', $_contexte); |
|
| 1138 | - } else { |
|
| 1139 | - $code_contexte = ''; |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 1143 | - $pas = $p->boucles[$b]->total_parties; |
|
| 1144 | - $f_pagination = chercher_filtre('pagination'); |
|
| 1145 | - $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1146 | - $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1147 | - : ("'debut" . substr($type, 1)); |
|
| 1148 | - |
|
| 1149 | - $p->code = sprintf( |
|
| 1150 | - CODE_PAGINATION, |
|
| 1151 | - $f_pagination, |
|
| 1152 | - $b, |
|
| 1153 | - $type, |
|
| 1154 | - $modif, |
|
| 1155 | - $pas, |
|
| 1156 | - $liste, |
|
| 1157 | - ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1158 | - _q($connect), |
|
| 1159 | - $code_contexte |
|
| 1160 | - ); |
|
| 1161 | - |
|
| 1162 | - $p->boucles[$b]->numrows = true; |
|
| 1163 | - $p->interdire_scripts = false; |
|
| 1164 | - |
|
| 1165 | - return $p; |
|
| 1097 | + $b = index_boucle_mere($p); |
|
| 1098 | + |
|
| 1099 | + // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1100 | + if ($b === '') { |
|
| 1101 | + $msg = [ |
|
| 1102 | + 'zbug_champ_hors_boucle', |
|
| 1103 | + ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1104 | + ]; |
|
| 1105 | + erreur_squelette($msg, $p); |
|
| 1106 | + |
|
| 1107 | + return $p; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1111 | + // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1112 | + if (!$p->boucles[$b]->mode_partie) { |
|
| 1113 | + if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1114 | + $msg = [ |
|
| 1115 | + 'zbug_pagination_sans_critere', |
|
| 1116 | + ['champ' => '#PAGINATION'] |
|
| 1117 | + ]; |
|
| 1118 | + erreur_squelette($msg, $p); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + return $p; |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + // a priori true |
|
| 1125 | + // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1126 | + // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1127 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1128 | + if (count($_contexte)) { |
|
| 1129 | + $key = key($_contexte); |
|
| 1130 | + if (is_numeric($key)) { |
|
| 1131 | + array_shift($_contexte); |
|
| 1132 | + $__modele = interprete_argument_balise(1, $p); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + if (count($_contexte)) { |
|
| 1137 | + $code_contexte = implode(',', $_contexte); |
|
| 1138 | + } else { |
|
| 1139 | + $code_contexte = ''; |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 1143 | + $pas = $p->boucles[$b]->total_parties; |
|
| 1144 | + $f_pagination = chercher_filtre('pagination'); |
|
| 1145 | + $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1146 | + $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1147 | + : ("'debut" . substr($type, 1)); |
|
| 1148 | + |
|
| 1149 | + $p->code = sprintf( |
|
| 1150 | + CODE_PAGINATION, |
|
| 1151 | + $f_pagination, |
|
| 1152 | + $b, |
|
| 1153 | + $type, |
|
| 1154 | + $modif, |
|
| 1155 | + $pas, |
|
| 1156 | + $liste, |
|
| 1157 | + ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1158 | + _q($connect), |
|
| 1159 | + $code_contexte |
|
| 1160 | + ); |
|
| 1161 | + |
|
| 1162 | + $p->boucles[$b]->numrows = true; |
|
| 1163 | + $p->interdire_scripts = false; |
|
| 1164 | + |
|
| 1165 | + return $p; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | |
@@ -1189,11 +1189,11 @@ discard block |
||
| 1189 | 1189 | * Pile complétée par le code à générer |
| 1190 | 1190 | **/ |
| 1191 | 1191 | function balise_ANCRE_PAGINATION_dist($p) { |
| 1192 | - if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1193 | - return $f($p, $liste = 'false'); |
|
| 1194 | - } else { |
|
| 1195 | - return null; |
|
| 1196 | - } // ou une erreur ? |
|
| 1192 | + if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1193 | + return $f($p, $liste = 'false'); |
|
| 1194 | + } else { |
|
| 1195 | + return null; |
|
| 1196 | + } // ou une erreur ? |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | |
@@ -1214,18 +1214,18 @@ discard block |
||
| 1214 | 1214 | * Pile complétée par le code à générer |
| 1215 | 1215 | **/ |
| 1216 | 1216 | function balise_GRAND_TOTAL_dist($p) { |
| 1217 | - $b = index_boucle_mere($p); |
|
| 1218 | - if ($b === '') { |
|
| 1219 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1220 | - erreur_squelette($msg, $p); |
|
| 1221 | - } else { |
|
| 1222 | - $p->code = "(isset(\$Numrows['$b']['grand_total']) |
|
| 1217 | + $b = index_boucle_mere($p); |
|
| 1218 | + if ($b === '') { |
|
| 1219 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1220 | + erreur_squelette($msg, $p); |
|
| 1221 | + } else { |
|
| 1222 | + $p->code = "(isset(\$Numrows['$b']['grand_total']) |
|
| 1223 | 1223 | ? \$Numrows['$b']['grand_total'] : \$Numrows['$b']['total'])"; |
| 1224 | - $p->boucles[$b]->numrows = true; |
|
| 1225 | - $p->interdire_scripts = false; |
|
| 1226 | - } |
|
| 1224 | + $p->boucles[$b]->numrows = true; |
|
| 1225 | + $p->interdire_scripts = false; |
|
| 1226 | + } |
|
| 1227 | 1227 | |
| 1228 | - return $p; |
|
| 1228 | + return $p; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | |
@@ -1253,10 +1253,10 @@ discard block |
||
| 1253 | 1253 | * Pile complétée par le code à générer |
| 1254 | 1254 | **/ |
| 1255 | 1255 | function balise_SELF_dist($p) { |
| 1256 | - $p->code = 'self()'; |
|
| 1257 | - $p->interdire_scripts = false; |
|
| 1256 | + $p->code = 'self()'; |
|
| 1257 | + $p->interdire_scripts = false; |
|
| 1258 | 1258 | |
| 1259 | - return $p; |
|
| 1259 | + return $p; |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | |
@@ -1283,17 +1283,17 @@ discard block |
||
| 1283 | 1283 | * Pile complétée par le code à générer |
| 1284 | 1284 | **/ |
| 1285 | 1285 | function balise_CHEMIN_dist($p) { |
| 1286 | - $arg = interprete_argument_balise(1, $p); |
|
| 1287 | - if (!$arg) { |
|
| 1288 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1289 | - erreur_squelette($msg, $p); |
|
| 1290 | - } else { |
|
| 1291 | - $p->code = 'find_in_path(' . $arg . ')'; |
|
| 1292 | - } |
|
| 1286 | + $arg = interprete_argument_balise(1, $p); |
|
| 1287 | + if (!$arg) { |
|
| 1288 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1289 | + erreur_squelette($msg, $p); |
|
| 1290 | + } else { |
|
| 1291 | + $p->code = 'find_in_path(' . $arg . ')'; |
|
| 1292 | + } |
|
| 1293 | 1293 | |
| 1294 | - $p->interdire_scripts = false; |
|
| 1294 | + $p->interdire_scripts = false; |
|
| 1295 | 1295 | |
| 1296 | - return $p; |
|
| 1296 | + return $p; |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | /** |
@@ -1318,16 +1318,16 @@ discard block |
||
| 1318 | 1318 | * Pile complétée par le code à générer |
| 1319 | 1319 | **/ |
| 1320 | 1320 | function balise_CHEMIN_IMAGE_dist($p) { |
| 1321 | - $arg = interprete_argument_balise(1, $p); |
|
| 1322 | - if (!$arg) { |
|
| 1323 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1324 | - erreur_squelette($msg, $p); |
|
| 1325 | - } else { |
|
| 1326 | - $p->code = 'chemin_image(' . $arg . ')'; |
|
| 1327 | - } |
|
| 1321 | + $arg = interprete_argument_balise(1, $p); |
|
| 1322 | + if (!$arg) { |
|
| 1323 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1324 | + erreur_squelette($msg, $p); |
|
| 1325 | + } else { |
|
| 1326 | + $p->code = 'chemin_image(' . $arg . ')'; |
|
| 1327 | + } |
|
| 1328 | 1328 | |
| 1329 | - $p->interdire_scripts = false; |
|
| 1330 | - return $p; |
|
| 1329 | + $p->interdire_scripts = false; |
|
| 1330 | + return $p; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | |
@@ -1365,36 +1365,36 @@ discard block |
||
| 1365 | 1365 | **/ |
| 1366 | 1366 | function balise_ENV_dist($p, $src = null) { |
| 1367 | 1367 | |
| 1368 | - // cle du tableau desiree |
|
| 1369 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1370 | - // valeur par defaut |
|
| 1371 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1368 | + // cle du tableau desiree |
|
| 1369 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1370 | + // valeur par defaut |
|
| 1371 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1372 | 1372 | |
| 1373 | - // $src est un tableau de donnees sources eventuellement transmis |
|
| 1374 | - // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1373 | + // $src est un tableau de donnees sources eventuellement transmis |
|
| 1374 | + // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1375 | 1375 | |
| 1376 | - if (!$_nom) { |
|
| 1377 | - // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1378 | - // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1379 | - if ($src) { |
|
| 1380 | - $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1381 | - } else { |
|
| 1382 | - $p->code = 'serialize($Pile[0]??[])'; |
|
| 1383 | - } |
|
| 1384 | - } else { |
|
| 1385 | - if (!$src) { |
|
| 1386 | - $src = '$Pile[0]??[]'; |
|
| 1387 | - } |
|
| 1388 | - if ($_sinon) { |
|
| 1389 | - $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1390 | - } else { |
|
| 1391 | - $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1392 | - } |
|
| 1393 | - } |
|
| 1376 | + if (!$_nom) { |
|
| 1377 | + // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1378 | + // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1379 | + if ($src) { |
|
| 1380 | + $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1381 | + } else { |
|
| 1382 | + $p->code = 'serialize($Pile[0]??[])'; |
|
| 1383 | + } |
|
| 1384 | + } else { |
|
| 1385 | + if (!$src) { |
|
| 1386 | + $src = '$Pile[0]??[]'; |
|
| 1387 | + } |
|
| 1388 | + if ($_sinon) { |
|
| 1389 | + $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1390 | + } else { |
|
| 1391 | + $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1392 | + } |
|
| 1393 | + } |
|
| 1394 | 1394 | |
| 1395 | - #$p->interdire_scripts = true; |
|
| 1395 | + #$p->interdire_scripts = true; |
|
| 1396 | 1396 | |
| 1397 | - return $p; |
|
| 1397 | + return $p; |
|
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | 1400 | /** |
@@ -1424,16 +1424,16 @@ discard block |
||
| 1424 | 1424 | * Pile completée du code PHP d'exécution de la balise |
| 1425 | 1425 | */ |
| 1426 | 1426 | function balise_CONFIG_dist($p) { |
| 1427 | - if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1428 | - $arg = "''"; |
|
| 1429 | - } |
|
| 1430 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1431 | - $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1427 | + if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1428 | + $arg = "''"; |
|
| 1429 | + } |
|
| 1430 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1431 | + $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1432 | 1432 | |
| 1433 | - $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1434 | - ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1433 | + $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1434 | + ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1435 | 1435 | |
| 1436 | - return $p; |
|
| 1436 | + return $p; |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | |
@@ -1456,10 +1456,10 @@ discard block |
||
| 1456 | 1456 | * Pile completée du code PHP d'exécution de la balise |
| 1457 | 1457 | */ |
| 1458 | 1458 | function balise_CONNECT_dist($p) { |
| 1459 | - $p->code = '($connect ? $connect : NULL)'; |
|
| 1460 | - $p->interdire_scripts = false; |
|
| 1459 | + $p->code = '($connect ? $connect : NULL)'; |
|
| 1460 | + $p->interdire_scripts = false; |
|
| 1461 | 1461 | |
| 1462 | - return $p; |
|
| 1462 | + return $p; |
|
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | |
@@ -1487,15 +1487,15 @@ discard block |
||
| 1487 | 1487 | * Pile completée du code PHP d'exécution de la balise |
| 1488 | 1488 | **/ |
| 1489 | 1489 | function balise_SESSION_dist($p) { |
| 1490 | - $p->descr['session'] = true; |
|
| 1490 | + $p->descr['session'] = true; |
|
| 1491 | 1491 | |
| 1492 | - $f = function_exists('balise_ENV') |
|
| 1493 | - ? 'balise_ENV' |
|
| 1494 | - : 'balise_ENV_dist'; |
|
| 1492 | + $f = function_exists('balise_ENV') |
|
| 1493 | + ? 'balise_ENV' |
|
| 1494 | + : 'balise_ENV_dist'; |
|
| 1495 | 1495 | |
| 1496 | - $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1496 | + $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1497 | 1497 | |
| 1498 | - return $p; |
|
| 1498 | + return $p; |
|
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | |
@@ -1518,18 +1518,18 @@ discard block |
||
| 1518 | 1518 | * Pile completée du code PHP d'exécution de la balise |
| 1519 | 1519 | **/ |
| 1520 | 1520 | function balise_SESSION_SET_dist($p) { |
| 1521 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1522 | - $_val = interprete_argument_balise(2, $p); |
|
| 1523 | - if (!$_nom or !$_val) { |
|
| 1524 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1525 | - erreur_squelette($err_b_s_a, $p); |
|
| 1526 | - } else { |
|
| 1527 | - $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1528 | - } |
|
| 1521 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1522 | + $_val = interprete_argument_balise(2, $p); |
|
| 1523 | + if (!$_nom or !$_val) { |
|
| 1524 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1525 | + erreur_squelette($err_b_s_a, $p); |
|
| 1526 | + } else { |
|
| 1527 | + $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1528 | + } |
|
| 1529 | 1529 | |
| 1530 | - $p->interdire_scripts = false; |
|
| 1530 | + $p->interdire_scripts = false; |
|
| 1531 | 1531 | |
| 1532 | - return $p; |
|
| 1532 | + return $p; |
|
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | |
@@ -1560,30 +1560,30 @@ discard block |
||
| 1560 | 1560 | * Pile completée du code PHP d'exécution de la balise |
| 1561 | 1561 | **/ |
| 1562 | 1562 | function balise_EVAL_dist($p) { |
| 1563 | - $php = interprete_argument_balise(1, $p); |
|
| 1564 | - if ($php) { |
|
| 1565 | - # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1566 | - # attention au commentaire "// x signes" qui precede |
|
| 1567 | - if ( |
|
| 1568 | - preg_match( |
|
| 1569 | - ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1570 | - $php, |
|
| 1571 | - $r |
|
| 1572 | - ) |
|
| 1573 | - ) { |
|
| 1574 | - $p->code = /* $r[1]. */ |
|
| 1575 | - '(' . $r[2] . ')'; |
|
| 1576 | - } else { |
|
| 1577 | - $p->code = "eval('return '.$php.';')"; |
|
| 1578 | - } |
|
| 1579 | - } else { |
|
| 1580 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1581 | - erreur_squelette($msg, $p); |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - #$p->interdire_scripts = true; |
|
| 1585 | - |
|
| 1586 | - return $p; |
|
| 1563 | + $php = interprete_argument_balise(1, $p); |
|
| 1564 | + if ($php) { |
|
| 1565 | + # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1566 | + # attention au commentaire "// x signes" qui precede |
|
| 1567 | + if ( |
|
| 1568 | + preg_match( |
|
| 1569 | + ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1570 | + $php, |
|
| 1571 | + $r |
|
| 1572 | + ) |
|
| 1573 | + ) { |
|
| 1574 | + $p->code = /* $r[1]. */ |
|
| 1575 | + '(' . $r[2] . ')'; |
|
| 1576 | + } else { |
|
| 1577 | + $p->code = "eval('return '.$php.';')"; |
|
| 1578 | + } |
|
| 1579 | + } else { |
|
| 1580 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1581 | + erreur_squelette($msg, $p); |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + #$p->interdire_scripts = true; |
|
| 1585 | + |
|
| 1586 | + return $p; |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | 1589 | |
@@ -1613,19 +1613,19 @@ discard block |
||
| 1613 | 1613 | **/ |
| 1614 | 1614 | function balise_CHAMP_SQL_dist($p) { |
| 1615 | 1615 | |
| 1616 | - if ( |
|
| 1617 | - $p->param |
|
| 1618 | - and isset($p->param[0][1][0]) |
|
| 1619 | - and $champ = ($p->param[0][1][0]->texte) |
|
| 1620 | - ) { |
|
| 1621 | - $p->code = champ_sql($champ, $p); |
|
| 1622 | - } else { |
|
| 1623 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1624 | - erreur_squelette($err_b_s_a, $p); |
|
| 1625 | - } |
|
| 1616 | + if ( |
|
| 1617 | + $p->param |
|
| 1618 | + and isset($p->param[0][1][0]) |
|
| 1619 | + and $champ = ($p->param[0][1][0]->texte) |
|
| 1620 | + ) { |
|
| 1621 | + $p->code = champ_sql($champ, $p); |
|
| 1622 | + } else { |
|
| 1623 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1624 | + erreur_squelette($err_b_s_a, $p); |
|
| 1625 | + } |
|
| 1626 | 1626 | |
| 1627 | - #$p->interdire_scripts = true; |
|
| 1628 | - return $p; |
|
| 1627 | + #$p->interdire_scripts = true; |
|
| 1628 | + return $p; |
|
| 1629 | 1629 | } |
| 1630 | 1630 | |
| 1631 | 1631 | /** |
@@ -1651,13 +1651,13 @@ discard block |
||
| 1651 | 1651 | * Pile complétée par le code à générer |
| 1652 | 1652 | **/ |
| 1653 | 1653 | function balise_VAL_dist($p) { |
| 1654 | - $p->code = interprete_argument_balise(1, $p); |
|
| 1655 | - if (!strlen($p->code)) { |
|
| 1656 | - $p->code = "''"; |
|
| 1657 | - } |
|
| 1658 | - $p->interdire_scripts = false; |
|
| 1654 | + $p->code = interprete_argument_balise(1, $p); |
|
| 1655 | + if (!strlen($p->code)) { |
|
| 1656 | + $p->code = "''"; |
|
| 1657 | + } |
|
| 1658 | + $p->interdire_scripts = false; |
|
| 1659 | 1659 | |
| 1660 | - return $p; |
|
| 1660 | + return $p; |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1686,10 +1686,10 @@ discard block |
||
| 1686 | 1686 | * Pile complétée par le code à générer |
| 1687 | 1687 | **/ |
| 1688 | 1688 | function balise_REM_dist($p) { |
| 1689 | - $p->code = "''"; |
|
| 1690 | - $p->interdire_scripts = false; |
|
| 1689 | + $p->code = "''"; |
|
| 1690 | + $p->interdire_scripts = false; |
|
| 1691 | 1691 | |
| 1692 | - return $p; |
|
| 1692 | + return $p; |
|
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | /** |
@@ -1699,10 +1699,10 @@ discard block |
||
| 1699 | 1699 | * @return mixed |
| 1700 | 1700 | */ |
| 1701 | 1701 | function balise_NULL_dist($p) { |
| 1702 | - $p->code = 'null'; |
|
| 1703 | - $p->interdire_scripts = false; |
|
| 1702 | + $p->code = 'null'; |
|
| 1703 | + $p->interdire_scripts = false; |
|
| 1704 | 1704 | |
| 1705 | - return $p; |
|
| 1705 | + return $p; |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | |
@@ -1726,18 +1726,18 @@ discard block |
||
| 1726 | 1726 | **/ |
| 1727 | 1727 | function balise_HTTP_HEADER_dist($p) { |
| 1728 | 1728 | |
| 1729 | - $header = interprete_argument_balise(1, $p); |
|
| 1730 | - if (!$header) { |
|
| 1731 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1732 | - erreur_squelette($err_b_s_a, $p); |
|
| 1733 | - } else { |
|
| 1734 | - $p->code = "'<'.'?php header(' . _q(" |
|
| 1735 | - . $header |
|
| 1736 | - . ") . '); ?'.'>'"; |
|
| 1737 | - } |
|
| 1738 | - $p->interdire_scripts = false; |
|
| 1729 | + $header = interprete_argument_balise(1, $p); |
|
| 1730 | + if (!$header) { |
|
| 1731 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1732 | + erreur_squelette($err_b_s_a, $p); |
|
| 1733 | + } else { |
|
| 1734 | + $p->code = "'<'.'?php header(' . _q(" |
|
| 1735 | + . $header |
|
| 1736 | + . ") . '); ?'.'>'"; |
|
| 1737 | + } |
|
| 1738 | + $p->interdire_scripts = false; |
|
| 1739 | 1739 | |
| 1740 | - return $p; |
|
| 1740 | + return $p; |
|
| 1741 | 1741 | } |
| 1742 | 1742 | |
| 1743 | 1743 | |
@@ -1762,20 +1762,20 @@ discard block |
||
| 1762 | 1762 | * Pile complétée par le code à générer |
| 1763 | 1763 | **/ |
| 1764 | 1764 | function balise_FILTRE_dist($p) { |
| 1765 | - if ($p->param) { |
|
| 1766 | - $args = []; |
|
| 1767 | - foreach ($p->param as $i => $ignore) { |
|
| 1768 | - $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1769 | - } |
|
| 1770 | - $p->code = "'<' . '" |
|
| 1771 | - . '?php header("X-Spip-Filtre: \'.' |
|
| 1772 | - . join('.\'|\'.', $args) |
|
| 1773 | - . " . '\"); ?'.'>'"; |
|
| 1765 | + if ($p->param) { |
|
| 1766 | + $args = []; |
|
| 1767 | + foreach ($p->param as $i => $ignore) { |
|
| 1768 | + $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1769 | + } |
|
| 1770 | + $p->code = "'<' . '" |
|
| 1771 | + . '?php header("X-Spip-Filtre: \'.' |
|
| 1772 | + . join('.\'|\'.', $args) |
|
| 1773 | + . " . '\"); ?'.'>'"; |
|
| 1774 | 1774 | |
| 1775 | - $p->interdire_scripts = false; |
|
| 1775 | + $p->interdire_scripts = false; |
|
| 1776 | 1776 | |
| 1777 | - return $p; |
|
| 1778 | - } |
|
| 1777 | + return $p; |
|
| 1778 | + } |
|
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | |
@@ -1811,55 +1811,55 @@ discard block |
||
| 1811 | 1811 | **/ |
| 1812 | 1812 | function balise_CACHE_dist($p) { |
| 1813 | 1813 | |
| 1814 | - if ($p->param) { |
|
| 1815 | - $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1816 | - |
|
| 1817 | - // noter la duree du cache dans un entete proprietaire |
|
| 1818 | - |
|
| 1819 | - $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1820 | - . $duree |
|
| 1821 | - . '"); ?' . "'.'>'"; |
|
| 1822 | - |
|
| 1823 | - // Remplir le header Cache-Control |
|
| 1824 | - // cas #CACHE{0} |
|
| 1825 | - if ($duree == 0) { |
|
| 1826 | - $code .= ".'<'.'" |
|
| 1827 | - . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1828 | - . "'.'><'.'" |
|
| 1829 | - . '?php header("Pragma: no-cache"); ?' |
|
| 1830 | - . "'.'>'"; |
|
| 1831 | - } |
|
| 1832 | - |
|
| 1833 | - // recuperer les parametres suivants |
|
| 1834 | - $i = 1; |
|
| 1835 | - while (isset($p->param[0][++$i])) { |
|
| 1836 | - $pa = ($p->param[0][$i][0]->texte); |
|
| 1837 | - |
|
| 1838 | - if ( |
|
| 1839 | - $pa == 'cache-client' |
|
| 1840 | - and $duree > 0 |
|
| 1841 | - ) { |
|
| 1842 | - $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1843 | - . $duree |
|
| 1844 | - . '"); ?' . "'.'>'"; |
|
| 1845 | - // il semble logique, si on cache-client, de ne pas invalider |
|
| 1846 | - $pa = 'statique'; |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - if ( |
|
| 1850 | - $pa == 'statique' |
|
| 1851 | - and $duree > 0 |
|
| 1852 | - ) { |
|
| 1853 | - $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1854 | - } |
|
| 1855 | - } |
|
| 1856 | - } else { |
|
| 1857 | - $code = "''"; |
|
| 1858 | - } |
|
| 1859 | - $p->code = $code; |
|
| 1860 | - $p->interdire_scripts = false; |
|
| 1861 | - |
|
| 1862 | - return $p; |
|
| 1814 | + if ($p->param) { |
|
| 1815 | + $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1816 | + |
|
| 1817 | + // noter la duree du cache dans un entete proprietaire |
|
| 1818 | + |
|
| 1819 | + $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1820 | + . $duree |
|
| 1821 | + . '"); ?' . "'.'>'"; |
|
| 1822 | + |
|
| 1823 | + // Remplir le header Cache-Control |
|
| 1824 | + // cas #CACHE{0} |
|
| 1825 | + if ($duree == 0) { |
|
| 1826 | + $code .= ".'<'.'" |
|
| 1827 | + . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1828 | + . "'.'><'.'" |
|
| 1829 | + . '?php header("Pragma: no-cache"); ?' |
|
| 1830 | + . "'.'>'"; |
|
| 1831 | + } |
|
| 1832 | + |
|
| 1833 | + // recuperer les parametres suivants |
|
| 1834 | + $i = 1; |
|
| 1835 | + while (isset($p->param[0][++$i])) { |
|
| 1836 | + $pa = ($p->param[0][$i][0]->texte); |
|
| 1837 | + |
|
| 1838 | + if ( |
|
| 1839 | + $pa == 'cache-client' |
|
| 1840 | + and $duree > 0 |
|
| 1841 | + ) { |
|
| 1842 | + $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1843 | + . $duree |
|
| 1844 | + . '"); ?' . "'.'>'"; |
|
| 1845 | + // il semble logique, si on cache-client, de ne pas invalider |
|
| 1846 | + $pa = 'statique'; |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + if ( |
|
| 1850 | + $pa == 'statique' |
|
| 1851 | + and $duree > 0 |
|
| 1852 | + ) { |
|
| 1853 | + $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1854 | + } |
|
| 1855 | + } |
|
| 1856 | + } else { |
|
| 1857 | + $code = "''"; |
|
| 1858 | + } |
|
| 1859 | + $p->code = $code; |
|
| 1860 | + $p->interdire_scripts = false; |
|
| 1861 | + |
|
| 1862 | + return $p; |
|
| 1863 | 1863 | } |
| 1864 | 1864 | |
| 1865 | 1865 | |
@@ -1891,13 +1891,13 @@ discard block |
||
| 1891 | 1891 | * Pile complétée par le code à générer |
| 1892 | 1892 | */ |
| 1893 | 1893 | function balise_INSERT_HEAD_dist($p) { |
| 1894 | - $p->code = "'<'.'" |
|
| 1895 | - . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1896 | - . "'.'>'"; |
|
| 1897 | - $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1898 | - $p->interdire_scripts = false; |
|
| 1894 | + $p->code = "'<'.'" |
|
| 1895 | + . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1896 | + . "'.'>'"; |
|
| 1897 | + $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1898 | + $p->interdire_scripts = false; |
|
| 1899 | 1899 | |
| 1900 | - return $p; |
|
| 1900 | + return $p; |
|
| 1901 | 1901 | } |
| 1902 | 1902 | |
| 1903 | 1903 | /** |
@@ -1915,10 +1915,10 @@ discard block |
||
| 1915 | 1915 | * Pile complétée par le code à générer |
| 1916 | 1916 | */ |
| 1917 | 1917 | function balise_INSERT_HEAD_CSS_dist($p) { |
| 1918 | - $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1919 | - $p->interdire_scripts = false; |
|
| 1918 | + $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1919 | + $p->interdire_scripts = false; |
|
| 1920 | 1920 | |
| 1921 | - return $p; |
|
| 1921 | + return $p; |
|
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | 1924 | /** |
@@ -1933,11 +1933,11 @@ discard block |
||
| 1933 | 1933 | * Pile complétée par le code à générer |
| 1934 | 1934 | **/ |
| 1935 | 1935 | function balise_INCLUDE_dist($p) { |
| 1936 | - if (function_exists('balise_INCLURE')) { |
|
| 1937 | - return balise_INCLURE($p); |
|
| 1938 | - } else { |
|
| 1939 | - return balise_INCLURE_dist($p); |
|
| 1940 | - } |
|
| 1936 | + if (function_exists('balise_INCLURE')) { |
|
| 1937 | + return balise_INCLURE($p); |
|
| 1938 | + } else { |
|
| 1939 | + return balise_INCLURE_dist($p); |
|
| 1940 | + } |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | 1943 | /** |
@@ -1971,66 +1971,66 @@ discard block |
||
| 1971 | 1971 | * Pile complétée par le code à générer |
| 1972 | 1972 | **/ |
| 1973 | 1973 | function balise_INCLURE_dist($p) { |
| 1974 | - $id_boucle = $p->id_boucle; |
|
| 1975 | - // la lang n'est pas passe de facon automatique par argumenter |
|
| 1976 | - // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1977 | - // en option |
|
| 1978 | - |
|
| 1979 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1980 | - |
|
| 1981 | - // erreur de syntaxe = fond absent |
|
| 1982 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1983 | - if (!$_contexte) { |
|
| 1984 | - $contexte = []; |
|
| 1985 | - } |
|
| 1986 | - |
|
| 1987 | - if (isset($_contexte['fond'])) { |
|
| 1988 | - $f = $_contexte['fond']; |
|
| 1989 | - // toujours vrai : |
|
| 1990 | - if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1991 | - $f = $r[1]; |
|
| 1992 | - unset($_contexte['fond']); |
|
| 1993 | - } else { |
|
| 1994 | - spip_log('compilation de #INCLURE a revoir'); |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - // #INCLURE{doublons} |
|
| 1998 | - if (isset($_contexte['doublons'])) { |
|
| 1999 | - $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 2000 | - } |
|
| 2001 | - |
|
| 2002 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2003 | - $flag_env = false; |
|
| 2004 | - if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2005 | - $flag_env = true; |
|
| 2006 | - unset($_contexte['env']); |
|
| 2007 | - } |
|
| 2008 | - |
|
| 2009 | - $_options = []; |
|
| 2010 | - if (isset($_contexte['ajax'])) { |
|
| 2011 | - $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2012 | - unset($_contexte['ajax']); |
|
| 2013 | - } |
|
| 2014 | - if ($p->etoile) { |
|
| 2015 | - $_options[] = "'etoile'=>true"; |
|
| 2016 | - } |
|
| 2017 | - $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2018 | - |
|
| 2019 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2020 | - if ($flag_env) { |
|
| 2021 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2022 | - } |
|
| 2023 | - |
|
| 2024 | - $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect')"); |
|
| 2025 | - } elseif (!isset($_contexte[1])) { |
|
| 2026 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2027 | - erreur_squelette($msg, $p); |
|
| 2028 | - } else { |
|
| 2029 | - $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2030 | - } |
|
| 2031 | - |
|
| 2032 | - $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2033 | - return $p; |
|
| 1974 | + $id_boucle = $p->id_boucle; |
|
| 1975 | + // la lang n'est pas passe de facon automatique par argumenter |
|
| 1976 | + // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1977 | + // en option |
|
| 1978 | + |
|
| 1979 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1980 | + |
|
| 1981 | + // erreur de syntaxe = fond absent |
|
| 1982 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1983 | + if (!$_contexte) { |
|
| 1984 | + $contexte = []; |
|
| 1985 | + } |
|
| 1986 | + |
|
| 1987 | + if (isset($_contexte['fond'])) { |
|
| 1988 | + $f = $_contexte['fond']; |
|
| 1989 | + // toujours vrai : |
|
| 1990 | + if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1991 | + $f = $r[1]; |
|
| 1992 | + unset($_contexte['fond']); |
|
| 1993 | + } else { |
|
| 1994 | + spip_log('compilation de #INCLURE a revoir'); |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + // #INCLURE{doublons} |
|
| 1998 | + if (isset($_contexte['doublons'])) { |
|
| 1999 | + $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 2000 | + } |
|
| 2001 | + |
|
| 2002 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2003 | + $flag_env = false; |
|
| 2004 | + if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2005 | + $flag_env = true; |
|
| 2006 | + unset($_contexte['env']); |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + $_options = []; |
|
| 2010 | + if (isset($_contexte['ajax'])) { |
|
| 2011 | + $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2012 | + unset($_contexte['ajax']); |
|
| 2013 | + } |
|
| 2014 | + if ($p->etoile) { |
|
| 2015 | + $_options[] = "'etoile'=>true"; |
|
| 2016 | + } |
|
| 2017 | + $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2018 | + |
|
| 2019 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2020 | + if ($flag_env) { |
|
| 2021 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2022 | + } |
|
| 2023 | + |
|
| 2024 | + $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect')"); |
|
| 2025 | + } elseif (!isset($_contexte[1])) { |
|
| 2026 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2027 | + erreur_squelette($msg, $p); |
|
| 2028 | + } else { |
|
| 2029 | + $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2030 | + } |
|
| 2031 | + |
|
| 2032 | + $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2033 | + return $p; |
|
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | |
@@ -2058,69 +2058,69 @@ discard block |
||
| 2058 | 2058 | **/ |
| 2059 | 2059 | function balise_MODELE_dist($p) { |
| 2060 | 2060 | |
| 2061 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2062 | - |
|
| 2063 | - // erreur de syntaxe = fond absent |
|
| 2064 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2065 | - if (!$_contexte) { |
|
| 2066 | - $_contexte = []; |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - if (!isset($_contexte[1])) { |
|
| 2070 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2071 | - erreur_squelette($msg, $p); |
|
| 2072 | - } else { |
|
| 2073 | - $nom = $_contexte[1]; |
|
| 2074 | - unset($_contexte[1]); |
|
| 2075 | - |
|
| 2076 | - if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2077 | - $nom = "'modeles/" . substr($nom, 1); |
|
| 2078 | - } else { |
|
| 2079 | - $nom = "'modeles/' . $nom"; |
|
| 2080 | - } |
|
| 2081 | - |
|
| 2082 | - $flag_env = false; |
|
| 2083 | - if (isset($_contexte['env'])) { |
|
| 2084 | - $flag_env = true; |
|
| 2085 | - unset($_contexte['env']); |
|
| 2086 | - } |
|
| 2087 | - |
|
| 2088 | - // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2089 | - // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2090 | - if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2091 | - $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2092 | - if (!strpos($primary, ',')) { |
|
| 2093 | - $id = champ_sql($primary, $p); |
|
| 2094 | - $_contexte[] = "'$primary'=>" . $id; |
|
| 2095 | - $_contexte[] = "'id'=>" . $id; |
|
| 2096 | - } |
|
| 2097 | - } |
|
| 2098 | - $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2099 | - $connect = ''; |
|
| 2100 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2101 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2102 | - } |
|
| 2103 | - |
|
| 2104 | - $_options = memoriser_contexte_compil($p); |
|
| 2105 | - $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2106 | - if (isset($_contexte['ajax'])) { |
|
| 2107 | - $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2108 | - unset($_contexte['ajax']); |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2112 | - if ($flag_env) { |
|
| 2113 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2117 | - |
|
| 2118 | - $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2119 | - |
|
| 2120 | - $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - return $p; |
|
| 2061 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2062 | + |
|
| 2063 | + // erreur de syntaxe = fond absent |
|
| 2064 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2065 | + if (!$_contexte) { |
|
| 2066 | + $_contexte = []; |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + if (!isset($_contexte[1])) { |
|
| 2070 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2071 | + erreur_squelette($msg, $p); |
|
| 2072 | + } else { |
|
| 2073 | + $nom = $_contexte[1]; |
|
| 2074 | + unset($_contexte[1]); |
|
| 2075 | + |
|
| 2076 | + if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2077 | + $nom = "'modeles/" . substr($nom, 1); |
|
| 2078 | + } else { |
|
| 2079 | + $nom = "'modeles/' . $nom"; |
|
| 2080 | + } |
|
| 2081 | + |
|
| 2082 | + $flag_env = false; |
|
| 2083 | + if (isset($_contexte['env'])) { |
|
| 2084 | + $flag_env = true; |
|
| 2085 | + unset($_contexte['env']); |
|
| 2086 | + } |
|
| 2087 | + |
|
| 2088 | + // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2089 | + // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2090 | + if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2091 | + $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2092 | + if (!strpos($primary, ',')) { |
|
| 2093 | + $id = champ_sql($primary, $p); |
|
| 2094 | + $_contexte[] = "'$primary'=>" . $id; |
|
| 2095 | + $_contexte[] = "'id'=>" . $id; |
|
| 2096 | + } |
|
| 2097 | + } |
|
| 2098 | + $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2099 | + $connect = ''; |
|
| 2100 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2101 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2102 | + } |
|
| 2103 | + |
|
| 2104 | + $_options = memoriser_contexte_compil($p); |
|
| 2105 | + $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2106 | + if (isset($_contexte['ajax'])) { |
|
| 2107 | + $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2108 | + unset($_contexte['ajax']); |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2112 | + if ($flag_env) { |
|
| 2113 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2117 | + |
|
| 2118 | + $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2119 | + |
|
| 2120 | + $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + return $p; |
|
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | 2126 | |
@@ -2144,21 +2144,21 @@ discard block |
||
| 2144 | 2144 | * Pile complétée par le code à générer |
| 2145 | 2145 | **/ |
| 2146 | 2146 | function balise_SET_dist($p) { |
| 2147 | - $_nom = interprete_argument_balise(1, $p); |
|
| 2148 | - $_val = interprete_argument_balise(2, $p); |
|
| 2147 | + $_nom = interprete_argument_balise(1, $p); |
|
| 2148 | + $_val = interprete_argument_balise(2, $p); |
|
| 2149 | 2149 | |
| 2150 | - if (!$_nom or !$_val) { |
|
| 2151 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2152 | - erreur_squelette($err_b_s_a, $p); |
|
| 2153 | - } |
|
| 2154 | - // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2155 | - // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2156 | - else { |
|
| 2157 | - $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2158 | - } |
|
| 2150 | + if (!$_nom or !$_val) { |
|
| 2151 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2152 | + erreur_squelette($err_b_s_a, $p); |
|
| 2153 | + } |
|
| 2154 | + // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2155 | + // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2156 | + else { |
|
| 2157 | + $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2158 | + } |
|
| 2159 | 2159 | |
| 2160 | - $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2161 | - return $p; |
|
| 2160 | + $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2161 | + return $p; |
|
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | 2164 | |
@@ -2188,12 +2188,12 @@ discard block |
||
| 2188 | 2188 | * Pile complétée par le code à générer |
| 2189 | 2189 | **/ |
| 2190 | 2190 | function balise_GET_dist($p) { |
| 2191 | - $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2192 | - if (function_exists('balise_ENV')) { |
|
| 2193 | - return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2194 | - } else { |
|
| 2195 | - return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2196 | - } |
|
| 2191 | + $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2192 | + if (function_exists('balise_ENV')) { |
|
| 2193 | + return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2194 | + } else { |
|
| 2195 | + return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2196 | + } |
|
| 2197 | 2197 | } |
| 2198 | 2198 | |
| 2199 | 2199 | |
@@ -2216,22 +2216,22 @@ discard block |
||
| 2216 | 2216 | * Pile complétée par le code à générer |
| 2217 | 2217 | **/ |
| 2218 | 2218 | function balise_DOUBLONS_dist($p) { |
| 2219 | - if ($type = interprete_argument_balise(1, $p)) { |
|
| 2220 | - if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2221 | - $type .= '.' . $famille; |
|
| 2222 | - } |
|
| 2223 | - $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2224 | - if (!$p->etoile) { |
|
| 2225 | - $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2226 | - . $p->code . ')))'; |
|
| 2227 | - } |
|
| 2228 | - } else { |
|
| 2229 | - $p->code = '$doublons'; |
|
| 2230 | - } |
|
| 2219 | + if ($type = interprete_argument_balise(1, $p)) { |
|
| 2220 | + if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2221 | + $type .= '.' . $famille; |
|
| 2222 | + } |
|
| 2223 | + $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2224 | + if (!$p->etoile) { |
|
| 2225 | + $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2226 | + . $p->code . ')))'; |
|
| 2227 | + } |
|
| 2228 | + } else { |
|
| 2229 | + $p->code = '$doublons'; |
|
| 2230 | + } |
|
| 2231 | 2231 | |
| 2232 | - $p->interdire_scripts = false; |
|
| 2232 | + $p->interdire_scripts = false; |
|
| 2233 | 2233 | |
| 2234 | - return $p; |
|
| 2234 | + return $p; |
|
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | 2237 | |
@@ -2254,18 +2254,18 @@ discard block |
||
| 2254 | 2254 | * Pile complétée par le code à générer |
| 2255 | 2255 | **/ |
| 2256 | 2256 | function balise_PIPELINE_dist($p) { |
| 2257 | - $_pipe = interprete_argument_balise(1, $p); |
|
| 2258 | - if (!$_pipe) { |
|
| 2259 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2260 | - erreur_squelette($err_b_s_a, $p); |
|
| 2261 | - } else { |
|
| 2262 | - $_flux = interprete_argument_balise(2, $p); |
|
| 2263 | - $_flux = $_flux ? $_flux : "''"; |
|
| 2264 | - $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2265 | - $p->interdire_scripts = false; |
|
| 2266 | - } |
|
| 2257 | + $_pipe = interprete_argument_balise(1, $p); |
|
| 2258 | + if (!$_pipe) { |
|
| 2259 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2260 | + erreur_squelette($err_b_s_a, $p); |
|
| 2261 | + } else { |
|
| 2262 | + $_flux = interprete_argument_balise(2, $p); |
|
| 2263 | + $_flux = $_flux ? $_flux : "''"; |
|
| 2264 | + $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2265 | + $p->interdire_scripts = false; |
|
| 2266 | + } |
|
| 2267 | 2267 | |
| 2268 | - return $p; |
|
| 2268 | + return $p; |
|
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | 2271 | |
@@ -2290,10 +2290,10 @@ discard block |
||
| 2290 | 2290 | * Pile complétée par le code à générer |
| 2291 | 2291 | **/ |
| 2292 | 2292 | function balise_EDIT_dist($p) { |
| 2293 | - $p->code = "''"; |
|
| 2294 | - $p->interdire_scripts = false; |
|
| 2293 | + $p->code = "''"; |
|
| 2294 | + $p->interdire_scripts = false; |
|
| 2295 | 2295 | |
| 2296 | - return $p; |
|
| 2296 | + return $p; |
|
| 2297 | 2297 | } |
| 2298 | 2298 | |
| 2299 | 2299 | |
@@ -2316,11 +2316,11 @@ discard block |
||
| 2316 | 2316 | * Pile complétée par le code à générer |
| 2317 | 2317 | **/ |
| 2318 | 2318 | function balise_TOTAL_UNIQUE_dist($p) { |
| 2319 | - $_famille = interprete_argument_balise(1, $p); |
|
| 2320 | - $_famille = $_famille ? $_famille : "''"; |
|
| 2321 | - $p->code = "unique('', $_famille, true)"; |
|
| 2319 | + $_famille = interprete_argument_balise(1, $p); |
|
| 2320 | + $_famille = $_famille ? $_famille : "''"; |
|
| 2321 | + $p->code = "unique('', $_famille, true)"; |
|
| 2322 | 2322 | |
| 2323 | - return $p; |
|
| 2323 | + return $p; |
|
| 2324 | 2324 | } |
| 2325 | 2325 | |
| 2326 | 2326 | /** |
@@ -2343,19 +2343,19 @@ discard block |
||
| 2343 | 2343 | * Pile complétée par le code à générer |
| 2344 | 2344 | **/ |
| 2345 | 2345 | function balise_ARRAY_dist($p) { |
| 2346 | - $_code = []; |
|
| 2347 | - $n = 1; |
|
| 2348 | - do { |
|
| 2349 | - $_key = interprete_argument_balise($n++, $p); |
|
| 2350 | - $_val = interprete_argument_balise($n++, $p); |
|
| 2351 | - if ($_key and $_val) { |
|
| 2352 | - $_code[] = "$_key => $_val"; |
|
| 2353 | - } |
|
| 2354 | - } while ($_key && $_val); |
|
| 2355 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2356 | - $p->interdire_scripts = false; |
|
| 2346 | + $_code = []; |
|
| 2347 | + $n = 1; |
|
| 2348 | + do { |
|
| 2349 | + $_key = interprete_argument_balise($n++, $p); |
|
| 2350 | + $_val = interprete_argument_balise($n++, $p); |
|
| 2351 | + if ($_key and $_val) { |
|
| 2352 | + $_code[] = "$_key => $_val"; |
|
| 2353 | + } |
|
| 2354 | + } while ($_key && $_val); |
|
| 2355 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2356 | + $p->interdire_scripts = false; |
|
| 2357 | 2357 | |
| 2358 | - return $p; |
|
| 2358 | + return $p; |
|
| 2359 | 2359 | } |
| 2360 | 2360 | |
| 2361 | 2361 | /** |
@@ -2374,15 +2374,15 @@ discard block |
||
| 2374 | 2374 | * Pile complétée par le code à générer |
| 2375 | 2375 | */ |
| 2376 | 2376 | function balise_LISTE_dist($p) { |
| 2377 | - $_code = []; |
|
| 2378 | - $n = 1; |
|
| 2379 | - while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2380 | - $_code[] = $_val; |
|
| 2381 | - } |
|
| 2382 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2383 | - $p->interdire_scripts = false; |
|
| 2377 | + $_code = []; |
|
| 2378 | + $n = 1; |
|
| 2379 | + while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2380 | + $_code[] = $_val; |
|
| 2381 | + } |
|
| 2382 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2383 | + $p->interdire_scripts = false; |
|
| 2384 | 2384 | |
| 2385 | - return $p; |
|
| 2385 | + return $p; |
|
| 2386 | 2386 | } |
| 2387 | 2387 | |
| 2388 | 2388 | |
@@ -2416,21 +2416,21 @@ discard block |
||
| 2416 | 2416 | * Pile complétée par le code à générer |
| 2417 | 2417 | **/ |
| 2418 | 2418 | function balise_AUTORISER_dist($p) { |
| 2419 | - $_code = []; |
|
| 2420 | - $p->descr['session'] = true; // faire un cache par session |
|
| 2419 | + $_code = []; |
|
| 2420 | + $p->descr['session'] = true; // faire un cache par session |
|
| 2421 | 2421 | |
| 2422 | - $n = 1; |
|
| 2423 | - while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2424 | - $_code[] = $_v; |
|
| 2425 | - } |
|
| 2422 | + $n = 1; |
|
| 2423 | + while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2424 | + $_code[] = $_v; |
|
| 2425 | + } |
|
| 2426 | 2426 | |
| 2427 | - $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2428 | - ', ', |
|
| 2429 | - $_code |
|
| 2430 | - ) . ')?" ":"")'; |
|
| 2431 | - $p->interdire_scripts = false; |
|
| 2427 | + $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2428 | + ', ', |
|
| 2429 | + $_code |
|
| 2430 | + ) . ')?" ":"")'; |
|
| 2431 | + $p->interdire_scripts = false; |
|
| 2432 | 2432 | |
| 2433 | - return $p; |
|
| 2433 | + return $p; |
|
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | 2436 | |
@@ -2454,15 +2454,15 @@ discard block |
||
| 2454 | 2454 | * Pile complétée par le code à générer |
| 2455 | 2455 | **/ |
| 2456 | 2456 | function balise_PLUGIN_dist($p) { |
| 2457 | - $plugin = interprete_argument_balise(1, $p); |
|
| 2458 | - $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2459 | - $type_info = interprete_argument_balise(2, $p); |
|
| 2460 | - $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2457 | + $plugin = interprete_argument_balise(1, $p); |
|
| 2458 | + $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2459 | + $type_info = interprete_argument_balise(2, $p); |
|
| 2460 | + $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2461 | 2461 | |
| 2462 | - $f = chercher_filtre('info_plugin'); |
|
| 2463 | - $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2462 | + $f = chercher_filtre('info_plugin'); |
|
| 2463 | + $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2464 | 2464 | |
| 2465 | - return $p; |
|
| 2465 | + return $p; |
|
| 2466 | 2466 | } |
| 2467 | 2467 | |
| 2468 | 2468 | /** |
@@ -2483,9 +2483,9 @@ discard block |
||
| 2483 | 2483 | * Pile complétée par le code à générer |
| 2484 | 2484 | **/ |
| 2485 | 2485 | function balise_AIDER_dist($p) { |
| 2486 | - $_motif = interprete_argument_balise(1, $p); |
|
| 2487 | - $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2488 | - return $p; |
|
| 2486 | + $_motif = interprete_argument_balise(1, $p); |
|
| 2487 | + $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2488 | + return $p; |
|
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | 2491 | /** |
@@ -2511,16 +2511,16 @@ discard block |
||
| 2511 | 2511 | * Pile complétée par le code à générer |
| 2512 | 2512 | **/ |
| 2513 | 2513 | function balise_ACTION_FORMULAIRE($p) { |
| 2514 | - if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2515 | - $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2516 | - } |
|
| 2517 | - if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2518 | - $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - // envoyer le nom du formulaire que l'on traite |
|
| 2522 | - // transmettre les eventuels args de la balise formulaire |
|
| 2523 | - $p->code = " '<span class=\"form-hidden\">' . |
|
| 2514 | + if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2515 | + $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2516 | + } |
|
| 2517 | + if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2518 | + $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + // envoyer le nom du formulaire que l'on traite |
|
| 2522 | + // transmettre les eventuels args de la balise formulaire |
|
| 2523 | + $p->code = " '<span class=\"form-hidden\">' . |
|
| 2524 | 2524 | form_hidden($_url) . |
| 2525 | 2525 | '<input name=\'formulaire_action\' type=\'hidden\' |
| 2526 | 2526 | value=\'' . $_form . '\' />' . |
@@ -2531,9 +2531,9 @@ discard block |
||
| 2531 | 2531 | (\$Pile[0]['_hidden'] ?? '') . |
| 2532 | 2532 | '</span>'"; |
| 2533 | 2533 | |
| 2534 | - $p->interdire_scripts = false; |
|
| 2534 | + $p->interdire_scripts = false; |
|
| 2535 | 2535 | |
| 2536 | - return $p; |
|
| 2536 | + return $p; |
|
| 2537 | 2537 | } |
| 2538 | 2538 | |
| 2539 | 2539 | |
@@ -2574,25 +2574,25 @@ discard block |
||
| 2574 | 2574 | */ |
| 2575 | 2575 | function balise_BOUTON_ACTION_dist($p) { |
| 2576 | 2576 | |
| 2577 | - $args = []; |
|
| 2578 | - for ($k = 1; $k <= 6; $k++) { |
|
| 2579 | - $_a = interprete_argument_balise($k, $p); |
|
| 2580 | - if (!$_a) { |
|
| 2581 | - $_a = "''"; |
|
| 2582 | - } |
|
| 2583 | - $args[] = $_a; |
|
| 2584 | - } |
|
| 2585 | - // supprimer les args vides |
|
| 2586 | - while (end($args) == "''" and count($args) > 2) { |
|
| 2587 | - array_pop($args); |
|
| 2588 | - } |
|
| 2589 | - $args = implode(',', $args); |
|
| 2577 | + $args = []; |
|
| 2578 | + for ($k = 1; $k <= 6; $k++) { |
|
| 2579 | + $_a = interprete_argument_balise($k, $p); |
|
| 2580 | + if (!$_a) { |
|
| 2581 | + $_a = "''"; |
|
| 2582 | + } |
|
| 2583 | + $args[] = $_a; |
|
| 2584 | + } |
|
| 2585 | + // supprimer les args vides |
|
| 2586 | + while (end($args) == "''" and count($args) > 2) { |
|
| 2587 | + array_pop($args); |
|
| 2588 | + } |
|
| 2589 | + $args = implode(',', $args); |
|
| 2590 | 2590 | |
| 2591 | - $bouton_action = chercher_filtre('bouton_action'); |
|
| 2592 | - $p->code = "$bouton_action($args)"; |
|
| 2593 | - $p->interdire_scripts = false; |
|
| 2591 | + $bouton_action = chercher_filtre('bouton_action'); |
|
| 2592 | + $p->code = "$bouton_action($args)"; |
|
| 2593 | + $p->interdire_scripts = false; |
|
| 2594 | 2594 | |
| 2595 | - return $p; |
|
| 2595 | + return $p; |
|
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | |
@@ -2611,10 +2611,10 @@ discard block |
||
| 2611 | 2611 | * Pile complétée par le code à générer |
| 2612 | 2612 | */ |
| 2613 | 2613 | function balise_SLOGAN_SITE_SPIP_dist($p) { |
| 2614 | - $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2614 | + $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2615 | 2615 | |
| 2616 | - #$p->interdire_scripts = true; |
|
| 2617 | - return $p; |
|
| 2616 | + #$p->interdire_scripts = true; |
|
| 2617 | + return $p; |
|
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 2620 | 2620 | |
@@ -2638,10 +2638,10 @@ discard block |
||
| 2638 | 2638 | * Pile complétée par le code à générer |
| 2639 | 2639 | */ |
| 2640 | 2640 | function balise_HTML5_dist($p) { |
| 2641 | - $p->code = html5_permis() ? "' '" : "''"; |
|
| 2642 | - $p->interdire_scripts = false; |
|
| 2641 | + $p->code = html5_permis() ? "' '" : "''"; |
|
| 2642 | + $p->interdire_scripts = false; |
|
| 2643 | 2643 | |
| 2644 | - return $p; |
|
| 2644 | + return $p; |
|
| 2645 | 2645 | } |
| 2646 | 2646 | |
| 2647 | 2647 | |
@@ -2667,61 +2667,61 @@ discard block |
||
| 2667 | 2667 | * Pile complétée par le code à générer |
| 2668 | 2668 | */ |
| 2669 | 2669 | function balise_TRI_dist($p, $liste = 'true') { |
| 2670 | - $b = index_boucle_mere($p); |
|
| 2671 | - // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2672 | - if ($b === '') { |
|
| 2673 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2674 | - erreur_squelette($msg, $p); |
|
| 2675 | - $p->code = "''"; |
|
| 2670 | + $b = index_boucle_mere($p); |
|
| 2671 | + // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2672 | + if ($b === '') { |
|
| 2673 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2674 | + erreur_squelette($msg, $p); |
|
| 2675 | + $p->code = "''"; |
|
| 2676 | 2676 | |
| 2677 | - return $p; |
|
| 2678 | - } |
|
| 2679 | - $boucle = $p->boucles[$b]; |
|
| 2677 | + return $p; |
|
| 2678 | + } |
|
| 2679 | + $boucle = $p->boucles[$b]; |
|
| 2680 | 2680 | |
| 2681 | - // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2682 | - // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2683 | - if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2684 | - $msg = ['zbug_champ_hors_critere', [ |
|
| 2685 | - 'champ' => zbug_presenter_champ($p), |
|
| 2686 | - 'critere' => 'tri' |
|
| 2687 | - ]]; |
|
| 2688 | - erreur_squelette($msg, $p); |
|
| 2689 | - $p->code = "''"; |
|
| 2681 | + // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2682 | + // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2683 | + if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2684 | + $msg = ['zbug_champ_hors_critere', [ |
|
| 2685 | + 'champ' => zbug_presenter_champ($p), |
|
| 2686 | + 'critere' => 'tri' |
|
| 2687 | + ]]; |
|
| 2688 | + erreur_squelette($msg, $p); |
|
| 2689 | + $p->code = "''"; |
|
| 2690 | 2690 | |
| 2691 | - return $p; |
|
| 2692 | - } |
|
| 2691 | + return $p; |
|
| 2692 | + } |
|
| 2693 | 2693 | |
| 2694 | - $_champ = interprete_argument_balise(1, $p); |
|
| 2695 | - // si pas de champ, renvoyer le critere de tri utilise |
|
| 2696 | - if (!$_champ) { |
|
| 2697 | - $p->code = $boucle->modificateur['tri_champ']; |
|
| 2694 | + $_champ = interprete_argument_balise(1, $p); |
|
| 2695 | + // si pas de champ, renvoyer le critere de tri utilise |
|
| 2696 | + if (!$_champ) { |
|
| 2697 | + $p->code = $boucle->modificateur['tri_champ']; |
|
| 2698 | 2698 | |
| 2699 | - return $p; |
|
| 2700 | - } |
|
| 2701 | - // forcer la jointure si besoin, et si le champ est statique |
|
| 2702 | - if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) { |
|
| 2703 | - index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2704 | - } |
|
| 2699 | + return $p; |
|
| 2700 | + } |
|
| 2701 | + // forcer la jointure si besoin, et si le champ est statique |
|
| 2702 | + if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) { |
|
| 2703 | + index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2704 | + } |
|
| 2705 | 2705 | |
| 2706 | - $_libelle = interprete_argument_balise(2, $p); |
|
| 2707 | - $_libelle = $_libelle ? $_libelle : $_champ; |
|
| 2706 | + $_libelle = interprete_argument_balise(2, $p); |
|
| 2707 | + $_libelle = $_libelle ? $_libelle : $_champ; |
|
| 2708 | 2708 | |
| 2709 | - $_class = interprete_argument_balise(3, $p); |
|
| 2710 | - // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 2711 | - // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 2712 | - $_issens = "in_array($_champ,array('>','<'))"; |
|
| 2713 | - $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 2709 | + $_class = interprete_argument_balise(3, $p); |
|
| 2710 | + // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 2711 | + // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 2712 | + $_issens = "in_array($_champ,array('>','<'))"; |
|
| 2713 | + $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 2714 | 2714 | |
| 2715 | - $_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom']; |
|
| 2716 | - $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 2717 | - $_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')"; |
|
| 2718 | - $_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)"; |
|
| 2715 | + $_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom']; |
|
| 2716 | + $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 2717 | + $_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')"; |
|
| 2718 | + $_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)"; |
|
| 2719 | 2719 | |
| 2720 | - $p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')'; |
|
| 2721 | - //$p->code = "''"; |
|
| 2722 | - $p->interdire_scripts = false; |
|
| 2720 | + $p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')'; |
|
| 2721 | + //$p->code = "''"; |
|
| 2722 | + $p->interdire_scripts = false; |
|
| 2723 | 2723 | |
| 2724 | - return $p; |
|
| 2724 | + return $p; |
|
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | 2727 | |
@@ -2742,21 +2742,21 @@ discard block |
||
| 2742 | 2742 | * Pile complétée par le code à générer |
| 2743 | 2743 | */ |
| 2744 | 2744 | function balise_SAUTER_dist($p) { |
| 2745 | - $id_boucle = $p->id_boucle; |
|
| 2745 | + $id_boucle = $p->id_boucle; |
|
| 2746 | 2746 | |
| 2747 | - if (empty($p->boucles[$id_boucle])) { |
|
| 2748 | - $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2749 | - erreur_squelette($msg, $p); |
|
| 2750 | - } else { |
|
| 2751 | - $_saut = interprete_argument_balise(1, $p); |
|
| 2752 | - $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2753 | - $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2747 | + if (empty($p->boucles[$id_boucle])) { |
|
| 2748 | + $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2749 | + erreur_squelette($msg, $p); |
|
| 2750 | + } else { |
|
| 2751 | + $_saut = interprete_argument_balise(1, $p); |
|
| 2752 | + $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2753 | + $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2754 | 2754 | |
| 2755 | - $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2756 | - } |
|
| 2757 | - $p->interdire_scripts = false; |
|
| 2755 | + $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2756 | + } |
|
| 2757 | + $p->interdire_scripts = false; |
|
| 2758 | 2758 | |
| 2759 | - return $p; |
|
| 2759 | + return $p; |
|
| 2760 | 2760 | } |
| 2761 | 2761 | |
| 2762 | 2762 | |
@@ -2778,22 +2778,22 @@ discard block |
||
| 2778 | 2778 | * Pile complétée par le code à générer |
| 2779 | 2779 | */ |
| 2780 | 2780 | function balise_PUBLIE_dist($p) { |
| 2781 | - if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2782 | - $_type = _q($p->type_requete); |
|
| 2783 | - $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2784 | - } else { |
|
| 2785 | - $_id = interprete_argument_balise(2, $p); |
|
| 2786 | - } |
|
| 2781 | + if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2782 | + $_type = _q($p->type_requete); |
|
| 2783 | + $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2784 | + } else { |
|
| 2785 | + $_id = interprete_argument_balise(2, $p); |
|
| 2786 | + } |
|
| 2787 | 2787 | |
| 2788 | - $connect = ''; |
|
| 2789 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2790 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2791 | - } |
|
| 2788 | + $connect = ''; |
|
| 2789 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2790 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2791 | + } |
|
| 2792 | 2792 | |
| 2793 | - $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2794 | - $p->interdire_scripts = false; |
|
| 2793 | + $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2794 | + $p->interdire_scripts = false; |
|
| 2795 | 2795 | |
| 2796 | - return $p; |
|
| 2796 | + return $p; |
|
| 2797 | 2797 | } |
| 2798 | 2798 | |
| 2799 | 2799 | /** |
@@ -2822,12 +2822,12 @@ discard block |
||
| 2822 | 2822 | * Pile complétée par le code à générer |
| 2823 | 2823 | */ |
| 2824 | 2824 | function balise_PRODUIRE_dist($p) { |
| 2825 | - $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2826 | - $p = $balise_inclure($p); |
|
| 2825 | + $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2826 | + $p = $balise_inclure($p); |
|
| 2827 | 2827 | |
| 2828 | - $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2828 | + $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2829 | 2829 | |
| 2830 | - return $p; |
|
| 2830 | + return $p; |
|
| 2831 | 2831 | } |
| 2832 | 2832 | |
| 2833 | 2833 | /** |
@@ -2846,13 +2846,13 @@ discard block |
||
| 2846 | 2846 | * Pile complétée par le code à générer |
| 2847 | 2847 | */ |
| 2848 | 2848 | function balise_LARGEUR_ECRAN_dist($p) { |
| 2849 | - $_class = interprete_argument_balise(1, $p); |
|
| 2850 | - if (!$_class) { |
|
| 2851 | - $_class = 'null'; |
|
| 2852 | - } |
|
| 2853 | - $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2849 | + $_class = interprete_argument_balise(1, $p); |
|
| 2850 | + if (!$_class) { |
|
| 2851 | + $_class = 'null'; |
|
| 2852 | + } |
|
| 2853 | + $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2854 | 2854 | |
| 2855 | - return $p; |
|
| 2855 | + return $p; |
|
| 2856 | 2856 | } |
| 2857 | 2857 | |
| 2858 | 2858 | |
@@ -2868,14 +2868,14 @@ discard block |
||
| 2868 | 2868 | * Pile complétée par le code à générer |
| 2869 | 2869 | **/ |
| 2870 | 2870 | function balise_CONST_dist($p) { |
| 2871 | - $_const = interprete_argument_balise(1, $p); |
|
| 2872 | - if (!strlen($_const)) { |
|
| 2873 | - $p->code = "''"; |
|
| 2874 | - } |
|
| 2875 | - else { |
|
| 2876 | - $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2877 | - } |
|
| 2878 | - $p->interdire_scripts = false; |
|
| 2879 | - |
|
| 2880 | - return $p; |
|
| 2871 | + $_const = interprete_argument_balise(1, $p); |
|
| 2872 | + if (!strlen($_const)) { |
|
| 2873 | + $p->code = "''"; |
|
| 2874 | + } |
|
| 2875 | + else { |
|
| 2876 | + $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2877 | + } |
|
| 2878 | + $p->interdire_scripts = false; |
|
| 2879 | + |
|
| 2880 | + return $p; |
|
| 2881 | 2881 | } |
@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,87 +68,87 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode === 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local === $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode === 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | - |
|
| 126 | - // si on retrouve l'extension |
|
| 127 | - if ( |
|
| 128 | - !empty($res['headers']) |
|
| 129 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 130 | - ) { |
|
| 131 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 132 | - $sanitizer($localrac); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // pour une eventuelle indexation |
|
| 137 | - pipeline( |
|
| 138 | - 'post_edition', |
|
| 139 | - [ |
|
| 140 | - 'args' => [ |
|
| 141 | - 'operation' => 'copie_locale', |
|
| 142 | - 'source' => $source, |
|
| 143 | - 'fichier' => $local, |
|
| 144 | - 'http_res' => $res['length'], |
|
| 145 | - ], |
|
| 146 | - 'data' => null |
|
| 147 | - ] |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode === 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local === $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode === 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 125 | + |
|
| 126 | + // si on retrouve l'extension |
|
| 127 | + if ( |
|
| 128 | + !empty($res['headers']) |
|
| 129 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 130 | + ) { |
|
| 131 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 132 | + $sanitizer($localrac); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // pour une eventuelle indexation |
|
| 137 | + pipeline( |
|
| 138 | + 'post_edition', |
|
| 139 | + [ |
|
| 140 | + 'args' => [ |
|
| 141 | + 'operation' => 'copie_locale', |
|
| 142 | + 'source' => $source, |
|
| 143 | + 'fichier' => $local, |
|
| 144 | + 'http_res' => $res['length'], |
|
| 145 | + ], |
|
| 146 | + 'data' => null |
|
| 147 | + ] |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + return $local; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -163,99 +163,99 @@ discard block |
||
| 163 | 163 | * url ou false en cas d'echec |
| 164 | 164 | */ |
| 165 | 165 | function valider_url_distante($url, $known_hosts = []) { |
| 166 | - if (!function_exists('protocole_verifier')) { |
|
| 167 | - include_spip('inc/filtres_mini'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $parsed_url = parse_url($url); |
|
| 175 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 184 | - return false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if (!is_array($known_hosts)) { |
|
| 188 | - $known_hosts = [$known_hosts]; |
|
| 189 | - } |
|
| 190 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 191 | - $known_hosts[] = url_de_base(); |
|
| 192 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 193 | - |
|
| 194 | - $is_known_host = false; |
|
| 195 | - foreach ($known_hosts as $known_host) { |
|
| 196 | - $parse_known = parse_url($known_host); |
|
| 197 | - if ( |
|
| 198 | - $parse_known |
|
| 199 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 200 | - ) { |
|
| 201 | - $is_known_host = true; |
|
| 202 | - break; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (!$is_known_host) { |
|
| 207 | - $host = trim($parsed_url['host'], '.'); |
|
| 208 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 209 | - $ip = gethostbyname($host); |
|
| 210 | - if ($ip === $host) { |
|
| 211 | - // Error condition for gethostbyname() |
|
| 212 | - $ip = false; |
|
| 213 | - } |
|
| 214 | - if ($records = dns_get_record($host)) { |
|
| 215 | - foreach ($records as $record) { |
|
| 216 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 217 | - // se fasse sur la meme IP |
|
| 218 | - if ($record['ttl']<10) { |
|
| 219 | - $ip = false; |
|
| 220 | - break; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - else { |
|
| 225 | - $ip = false; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - if ($ip) { |
|
| 229 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 230 | - return false; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - if (empty($parsed_url['port'])) { |
|
| 236 | - return $url; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $port = $parsed_url['port']; |
|
| 240 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 241 | - return $url; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($is_known_host) { |
|
| 245 | - foreach ($known_hosts as $known_host) { |
|
| 246 | - $parse_known = parse_url($known_host); |
|
| 247 | - if ( |
|
| 248 | - $parse_known |
|
| 249 | - and !empty($parse_known['port']) |
|
| 250 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 251 | - and $parse_known['port'] == $port |
|
| 252 | - ) { |
|
| 253 | - return $url; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return false; |
|
| 166 | + if (!function_exists('protocole_verifier')) { |
|
| 167 | + include_spip('inc/filtres_mini'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $parsed_url = parse_url($url); |
|
| 175 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if (!is_array($known_hosts)) { |
|
| 188 | + $known_hosts = [$known_hosts]; |
|
| 189 | + } |
|
| 190 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 191 | + $known_hosts[] = url_de_base(); |
|
| 192 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 193 | + |
|
| 194 | + $is_known_host = false; |
|
| 195 | + foreach ($known_hosts as $known_host) { |
|
| 196 | + $parse_known = parse_url($known_host); |
|
| 197 | + if ( |
|
| 198 | + $parse_known |
|
| 199 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 200 | + ) { |
|
| 201 | + $is_known_host = true; |
|
| 202 | + break; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (!$is_known_host) { |
|
| 207 | + $host = trim($parsed_url['host'], '.'); |
|
| 208 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 209 | + $ip = gethostbyname($host); |
|
| 210 | + if ($ip === $host) { |
|
| 211 | + // Error condition for gethostbyname() |
|
| 212 | + $ip = false; |
|
| 213 | + } |
|
| 214 | + if ($records = dns_get_record($host)) { |
|
| 215 | + foreach ($records as $record) { |
|
| 216 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 217 | + // se fasse sur la meme IP |
|
| 218 | + if ($record['ttl']<10) { |
|
| 219 | + $ip = false; |
|
| 220 | + break; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + else { |
|
| 225 | + $ip = false; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + if ($ip) { |
|
| 229 | + if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 230 | + return false; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + if (empty($parsed_url['port'])) { |
|
| 236 | + return $url; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $port = $parsed_url['port']; |
|
| 240 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 241 | + return $url; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($is_known_host) { |
|
| 245 | + foreach ($known_hosts as $known_host) { |
|
| 246 | + $parse_known = parse_url($known_host); |
|
| 247 | + if ( |
|
| 248 | + $parse_known |
|
| 249 | + and !empty($parse_known['port']) |
|
| 250 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 251 | + and $parse_known['port'] == $port |
|
| 252 | + ) { |
|
| 253 | + return $url; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -275,86 +275,86 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | function prepare_donnees_post($donnees, $boundary = '') { |
| 277 | 277 | |
| 278 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 279 | - // pour un appel soap par exemple |
|
| 280 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 281 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 282 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 283 | - $entete = ''; |
|
| 284 | - // on repasse tous les \r\n et \r en simples \n |
|
| 285 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 286 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 287 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 288 | - $p = strpos($donnees, "\n\n"); |
|
| 289 | - if ($p !== false) { |
|
| 290 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 291 | - $donnees = substr($donnees, $p + 2); |
|
| 292 | - } |
|
| 293 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 294 | - } else { |
|
| 295 | - /* boundary automatique */ |
|
| 296 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 297 | - if ($boundary === '') { |
|
| 298 | - $taille = 0; |
|
| 299 | - foreach ($donnees as $cle => $valeur) { |
|
| 300 | - if (is_array($valeur)) { |
|
| 301 | - foreach ($valeur as $val2) { |
|
| 302 | - $taille += strlen($val2); |
|
| 303 | - } |
|
| 304 | - } else { |
|
| 305 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 306 | - $taille += strlen($valeur); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - if ($taille > 500) { |
|
| 310 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 315 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 316 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 317 | - $chaine = ''; |
|
| 318 | - if (is_array($donnees)) { |
|
| 319 | - foreach ($donnees as $cle => $valeur) { |
|
| 320 | - if (is_array($valeur)) { |
|
| 321 | - foreach ($valeur as $val2) { |
|
| 322 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 323 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 324 | - $chaine .= "\r\n"; |
|
| 325 | - $chaine .= $val2; |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 329 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 330 | - $chaine .= "\r\n"; |
|
| 331 | - $chaine .= $valeur; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 335 | - } |
|
| 336 | - } else { |
|
| 337 | - // fabrique une chaine HTTP simple pour un POST |
|
| 338 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 339 | - $chaine = []; |
|
| 340 | - if (is_array($donnees)) { |
|
| 341 | - foreach ($donnees as $cle => $valeur) { |
|
| 342 | - if (is_array($valeur)) { |
|
| 343 | - foreach ($valeur as $val2) { |
|
| 344 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 345 | - } |
|
| 346 | - } else { |
|
| 347 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - $chaine = implode('&', $chaine); |
|
| 351 | - } else { |
|
| 352 | - $chaine = $donnees; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return [$entete, $chaine]; |
|
| 278 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 279 | + // pour un appel soap par exemple |
|
| 280 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 281 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 282 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 283 | + $entete = ''; |
|
| 284 | + // on repasse tous les \r\n et \r en simples \n |
|
| 285 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 286 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 287 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 288 | + $p = strpos($donnees, "\n\n"); |
|
| 289 | + if ($p !== false) { |
|
| 290 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 291 | + $donnees = substr($donnees, $p + 2); |
|
| 292 | + } |
|
| 293 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 294 | + } else { |
|
| 295 | + /* boundary automatique */ |
|
| 296 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 297 | + if ($boundary === '') { |
|
| 298 | + $taille = 0; |
|
| 299 | + foreach ($donnees as $cle => $valeur) { |
|
| 300 | + if (is_array($valeur)) { |
|
| 301 | + foreach ($valeur as $val2) { |
|
| 302 | + $taille += strlen($val2); |
|
| 303 | + } |
|
| 304 | + } else { |
|
| 305 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 306 | + $taille += strlen($valeur); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + if ($taille > 500) { |
|
| 310 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 315 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 316 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 317 | + $chaine = ''; |
|
| 318 | + if (is_array($donnees)) { |
|
| 319 | + foreach ($donnees as $cle => $valeur) { |
|
| 320 | + if (is_array($valeur)) { |
|
| 321 | + foreach ($valeur as $val2) { |
|
| 322 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 323 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 324 | + $chaine .= "\r\n"; |
|
| 325 | + $chaine .= $val2; |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 329 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 330 | + $chaine .= "\r\n"; |
|
| 331 | + $chaine .= $valeur; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 335 | + } |
|
| 336 | + } else { |
|
| 337 | + // fabrique une chaine HTTP simple pour un POST |
|
| 338 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 339 | + $chaine = []; |
|
| 340 | + if (is_array($donnees)) { |
|
| 341 | + foreach ($donnees as $cle => $valeur) { |
|
| 342 | + if (is_array($valeur)) { |
|
| 343 | + foreach ($valeur as $val2) { |
|
| 344 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 345 | + } |
|
| 346 | + } else { |
|
| 347 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + $chaine = implode('&', $chaine); |
|
| 351 | + } else { |
|
| 352 | + $chaine = $donnees; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return [$entete, $chaine]; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -368,22 +368,22 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | function url_to_ascii($url_idn) { |
| 370 | 370 | |
| 371 | - if ($parts = parse_url($url_idn)) { |
|
| 372 | - $host = $parts['host']; |
|
| 373 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 374 | - include_spip('inc/idna_convert.class'); |
|
| 375 | - $IDN = new idna_convert(); |
|
| 376 | - $host_ascii = $IDN->encode($host); |
|
| 377 | - $url_idn = explode($host, $url_idn, 2); |
|
| 378 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 379 | - } |
|
| 380 | - // et on urlencode les char utf si besoin dans le path |
|
| 381 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 382 | - return urlencode($match[0]); |
|
| 383 | - }, $url_idn); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - return $url_idn; |
|
| 371 | + if ($parts = parse_url($url_idn)) { |
|
| 372 | + $host = $parts['host']; |
|
| 373 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 374 | + include_spip('inc/idna_convert.class'); |
|
| 375 | + $IDN = new idna_convert(); |
|
| 376 | + $host_ascii = $IDN->encode($host); |
|
| 377 | + $url_idn = explode($host, $url_idn, 2); |
|
| 378 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 379 | + } |
|
| 380 | + // et on urlencode les char utf si besoin dans le path |
|
| 381 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 382 | + return urlencode($match[0]); |
|
| 383 | + }, $url_idn); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + return $url_idn; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -424,197 +424,197 @@ discard block |
||
| 424 | 424 | * string file : nom du fichier si enregistre dans un fichier |
| 425 | 425 | */ |
| 426 | 426 | function recuperer_url($url, $options = []) { |
| 427 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 428 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 429 | - $default = [ |
|
| 430 | - 'transcoder' => false, |
|
| 431 | - 'methode' => 'GET', |
|
| 432 | - 'taille_max' => null, |
|
| 433 | - 'headers' => [], |
|
| 434 | - 'datas' => '', |
|
| 435 | - 'boundary' => '', |
|
| 436 | - 'refuser_gz' => false, |
|
| 437 | - 'if_modified_since' => '', |
|
| 438 | - 'uri_referer' => '', |
|
| 439 | - 'file' => '', |
|
| 440 | - 'follow_location' => 10, |
|
| 441 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 442 | - ]; |
|
| 443 | - $options = array_merge($default, $options); |
|
| 444 | - // copier directement dans un fichier ? |
|
| 445 | - $copy = $options['file']; |
|
| 446 | - |
|
| 447 | - if ($options['methode'] == 'HEAD') { |
|
| 448 | - $options['taille_max'] = 0; |
|
| 449 | - } |
|
| 450 | - if (is_null($options['taille_max'])) { |
|
| 451 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - // Ajout des en-têtes spécifiques si besoin |
|
| 456 | - $head_add = ''; |
|
| 457 | - if (!empty($options['headers'])) { |
|
| 458 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 459 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 460 | - } |
|
| 461 | - // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 462 | - unset($options['headers']); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - if (!empty($options['datas'])) { |
|
| 466 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 467 | - $head .= $head_add; |
|
| 468 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 469 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 470 | - } |
|
| 471 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 472 | - if ( |
|
| 473 | - strlen($postdata) |
|
| 474 | - and !$methode_demandee |
|
| 475 | - ) { |
|
| 476 | - $options['methode'] = 'POST'; |
|
| 477 | - } |
|
| 478 | - } elseif ($head_add) { |
|
| 479 | - $options['datas'] = $head_add . "\r\n"; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 483 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 484 | - if (!tester_url_absolue($url)) { |
|
| 485 | - $url = 'http://' . $url; |
|
| 486 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 487 | - $url = 'http:' . $url; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $url = url_to_ascii($url); |
|
| 491 | - |
|
| 492 | - $result = [ |
|
| 493 | - 'status' => 0, |
|
| 494 | - 'headers' => '', |
|
| 495 | - 'page' => '', |
|
| 496 | - 'length' => 0, |
|
| 497 | - 'last_modified' => '', |
|
| 498 | - 'location' => '', |
|
| 499 | - 'url' => $url |
|
| 500 | - ]; |
|
| 501 | - |
|
| 502 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 503 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 504 | - |
|
| 505 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 506 | - list($handle, $fopen) = init_http( |
|
| 507 | - $options['methode'], |
|
| 508 | - $url, |
|
| 509 | - $refuser_gz, |
|
| 510 | - $options['uri_referer'], |
|
| 511 | - $options['datas'], |
|
| 512 | - $options['version_http'], |
|
| 513 | - $options['if_modified_since'] |
|
| 514 | - ); |
|
| 515 | - if (!$handle) { |
|
| 516 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 517 | - |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 522 | - // et recuperer les en-tetes de reponses |
|
| 523 | - if (!$fopen) { |
|
| 524 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 525 | - if (!$res) { |
|
| 526 | - fclose($handle); |
|
| 527 | - $t = @parse_url($url); |
|
| 528 | - $host = $t['host']; |
|
| 529 | - // Chinoisierie inexplicable pour contrer |
|
| 530 | - // les actions liberticides de l'empire du milieu |
|
| 531 | - if ( |
|
| 532 | - !need_proxy($host) |
|
| 533 | - and $res = @file_get_contents($url) |
|
| 534 | - ) { |
|
| 535 | - $result['length'] = strlen($res); |
|
| 536 | - if ($copy) { |
|
| 537 | - ecrire_fichier($copy, $res); |
|
| 538 | - $result['file'] = $copy; |
|
| 539 | - } else { |
|
| 540 | - $result['page'] = $res; |
|
| 541 | - } |
|
| 542 | - $res = [ |
|
| 543 | - 'status' => 200, |
|
| 544 | - ]; |
|
| 545 | - } else { |
|
| 546 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 550 | - $options['follow_location']--; |
|
| 551 | - fclose($handle); |
|
| 552 | - include_spip('inc/filtres'); |
|
| 553 | - $url = suivre_lien($url, $res['location']); |
|
| 554 | - spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 555 | - |
|
| 556 | - return recuperer_url($url, $options); |
|
| 557 | - } elseif ($res['status'] !== 200) { |
|
| 558 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 559 | - } |
|
| 560 | - $result['status'] = $res['status']; |
|
| 561 | - if (isset($res['headers'])) { |
|
| 562 | - $result['headers'] = $res['headers']; |
|
| 563 | - } |
|
| 564 | - if (isset($res['last_modified'])) { |
|
| 565 | - $result['last_modified'] = $res['last_modified']; |
|
| 566 | - } |
|
| 567 | - if (isset($res['location'])) { |
|
| 568 | - $result['location'] = $res['location']; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // on ne veut que les entetes |
|
| 573 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 574 | - return $result; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 579 | - // sinon la memoire explose pour les gros flux |
|
| 580 | - |
|
| 581 | - $gz = false; |
|
| 582 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 583 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 587 | - if (!$result['length']) { |
|
| 588 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 589 | - fclose($handle); |
|
| 590 | - if ($copy) { |
|
| 591 | - $result['length'] = $res; |
|
| 592 | - $result['file'] = $copy; |
|
| 593 | - } elseif ($res) { |
|
| 594 | - $result['page'] = &$res; |
|
| 595 | - $result['length'] = strlen($result['page']); |
|
| 596 | - } |
|
| 597 | - if (!$result['status']) { |
|
| 598 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (!$result['page']) { |
|
| 602 | - return $result; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // Decompresser au besoin |
|
| 606 | - if ($gz) { |
|
| 607 | - $result['page'] = implode('', gzfile($gz)); |
|
| 608 | - supprimer_fichier($gz); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - // Faut-il l'importer dans notre charset local ? |
|
| 612 | - if ($options['transcoder']) { |
|
| 613 | - include_spip('inc/charsets'); |
|
| 614 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $result; |
|
| 427 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 428 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 429 | + $default = [ |
|
| 430 | + 'transcoder' => false, |
|
| 431 | + 'methode' => 'GET', |
|
| 432 | + 'taille_max' => null, |
|
| 433 | + 'headers' => [], |
|
| 434 | + 'datas' => '', |
|
| 435 | + 'boundary' => '', |
|
| 436 | + 'refuser_gz' => false, |
|
| 437 | + 'if_modified_since' => '', |
|
| 438 | + 'uri_referer' => '', |
|
| 439 | + 'file' => '', |
|
| 440 | + 'follow_location' => 10, |
|
| 441 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 442 | + ]; |
|
| 443 | + $options = array_merge($default, $options); |
|
| 444 | + // copier directement dans un fichier ? |
|
| 445 | + $copy = $options['file']; |
|
| 446 | + |
|
| 447 | + if ($options['methode'] == 'HEAD') { |
|
| 448 | + $options['taille_max'] = 0; |
|
| 449 | + } |
|
| 450 | + if (is_null($options['taille_max'])) { |
|
| 451 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + // Ajout des en-têtes spécifiques si besoin |
|
| 456 | + $head_add = ''; |
|
| 457 | + if (!empty($options['headers'])) { |
|
| 458 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 459 | + $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 460 | + } |
|
| 461 | + // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
|
| 462 | + unset($options['headers']); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + if (!empty($options['datas'])) { |
|
| 466 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 467 | + $head .= $head_add; |
|
| 468 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 469 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 470 | + } |
|
| 471 | + $options['datas'] = $head . "\r\n" . $postdata; |
|
| 472 | + if ( |
|
| 473 | + strlen($postdata) |
|
| 474 | + and !$methode_demandee |
|
| 475 | + ) { |
|
| 476 | + $options['methode'] = 'POST'; |
|
| 477 | + } |
|
| 478 | + } elseif ($head_add) { |
|
| 479 | + $options['datas'] = $head_add . "\r\n"; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 483 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 484 | + if (!tester_url_absolue($url)) { |
|
| 485 | + $url = 'http://' . $url; |
|
| 486 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 487 | + $url = 'http:' . $url; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $url = url_to_ascii($url); |
|
| 491 | + |
|
| 492 | + $result = [ |
|
| 493 | + 'status' => 0, |
|
| 494 | + 'headers' => '', |
|
| 495 | + 'page' => '', |
|
| 496 | + 'length' => 0, |
|
| 497 | + 'last_modified' => '', |
|
| 498 | + 'location' => '', |
|
| 499 | + 'url' => $url |
|
| 500 | + ]; |
|
| 501 | + |
|
| 502 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 503 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 504 | + |
|
| 505 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 506 | + list($handle, $fopen) = init_http( |
|
| 507 | + $options['methode'], |
|
| 508 | + $url, |
|
| 509 | + $refuser_gz, |
|
| 510 | + $options['uri_referer'], |
|
| 511 | + $options['datas'], |
|
| 512 | + $options['version_http'], |
|
| 513 | + $options['if_modified_since'] |
|
| 514 | + ); |
|
| 515 | + if (!$handle) { |
|
| 516 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 517 | + |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 522 | + // et recuperer les en-tetes de reponses |
|
| 523 | + if (!$fopen) { |
|
| 524 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 525 | + if (!$res) { |
|
| 526 | + fclose($handle); |
|
| 527 | + $t = @parse_url($url); |
|
| 528 | + $host = $t['host']; |
|
| 529 | + // Chinoisierie inexplicable pour contrer |
|
| 530 | + // les actions liberticides de l'empire du milieu |
|
| 531 | + if ( |
|
| 532 | + !need_proxy($host) |
|
| 533 | + and $res = @file_get_contents($url) |
|
| 534 | + ) { |
|
| 535 | + $result['length'] = strlen($res); |
|
| 536 | + if ($copy) { |
|
| 537 | + ecrire_fichier($copy, $res); |
|
| 538 | + $result['file'] = $copy; |
|
| 539 | + } else { |
|
| 540 | + $result['page'] = $res; |
|
| 541 | + } |
|
| 542 | + $res = [ |
|
| 543 | + 'status' => 200, |
|
| 544 | + ]; |
|
| 545 | + } else { |
|
| 546 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 550 | + $options['follow_location']--; |
|
| 551 | + fclose($handle); |
|
| 552 | + include_spip('inc/filtres'); |
|
| 553 | + $url = suivre_lien($url, $res['location']); |
|
| 554 | + spip_log("recuperer_url recommence sur $url", 'distant'); |
|
| 555 | + |
|
| 556 | + return recuperer_url($url, $options); |
|
| 557 | + } elseif ($res['status'] !== 200) { |
|
| 558 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 559 | + } |
|
| 560 | + $result['status'] = $res['status']; |
|
| 561 | + if (isset($res['headers'])) { |
|
| 562 | + $result['headers'] = $res['headers']; |
|
| 563 | + } |
|
| 564 | + if (isset($res['last_modified'])) { |
|
| 565 | + $result['last_modified'] = $res['last_modified']; |
|
| 566 | + } |
|
| 567 | + if (isset($res['location'])) { |
|
| 568 | + $result['location'] = $res['location']; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // on ne veut que les entetes |
|
| 573 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 574 | + return $result; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 579 | + // sinon la memoire explose pour les gros flux |
|
| 580 | + |
|
| 581 | + $gz = false; |
|
| 582 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 583 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 587 | + if (!$result['length']) { |
|
| 588 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 589 | + fclose($handle); |
|
| 590 | + if ($copy) { |
|
| 591 | + $result['length'] = $res; |
|
| 592 | + $result['file'] = $copy; |
|
| 593 | + } elseif ($res) { |
|
| 594 | + $result['page'] = &$res; |
|
| 595 | + $result['length'] = strlen($result['page']); |
|
| 596 | + } |
|
| 597 | + if (!$result['status']) { |
|
| 598 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (!$result['page']) { |
|
| 602 | + return $result; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // Decompresser au besoin |
|
| 606 | + if ($gz) { |
|
| 607 | + $result['page'] = implode('', gzfile($gz)); |
|
| 608 | + supprimer_fichier($gz); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + // Faut-il l'importer dans notre charset local ? |
|
| 612 | + if ($options['transcoder']) { |
|
| 613 | + include_spip('inc/charsets'); |
|
| 614 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $result; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -630,73 +630,73 @@ discard block |
||
| 630 | 630 | * @return array|bool|mixed |
| 631 | 631 | */ |
| 632 | 632 | function recuperer_url_cache($url, $options = []) { |
| 633 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 634 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 635 | - } |
|
| 636 | - $default = [ |
|
| 637 | - 'transcoder' => false, |
|
| 638 | - 'methode' => 'GET', |
|
| 639 | - 'taille_max' => null, |
|
| 640 | - 'datas' => '', |
|
| 641 | - 'boundary' => '', |
|
| 642 | - 'refuser_gz' => false, |
|
| 643 | - 'if_modified_since' => '', |
|
| 644 | - 'uri_referer' => '', |
|
| 645 | - 'file' => '', |
|
| 646 | - 'follow_location' => 10, |
|
| 647 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 648 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 649 | - ]; |
|
| 650 | - $options = array_merge($default, $options); |
|
| 651 | - |
|
| 652 | - // cas ou il n'est pas possible de cacher |
|
| 653 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 654 | - return recuperer_url($url, $options); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 658 | - static $errors = []; |
|
| 659 | - if (isset($errors[$url])) { |
|
| 660 | - return $errors[$url]; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $sig = $options; |
|
| 664 | - unset($sig['if_modified_since']); |
|
| 665 | - unset($sig['delai_cache']); |
|
| 666 | - $sig['url'] = $url; |
|
| 667 | - |
|
| 668 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 669 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 670 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 671 | - $cache = "$sub$cache"; |
|
| 672 | - |
|
| 673 | - $res = false; |
|
| 674 | - $is_cached = file_exists($cache); |
|
| 675 | - if ( |
|
| 676 | - $is_cached |
|
| 677 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 678 | - ) { |
|
| 679 | - lire_fichier($cache, $res); |
|
| 680 | - if ($res = unserialize($res)) { |
|
| 681 | - // mettre le last_modified et le status=304 ? |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - if (!$res) { |
|
| 685 | - $res = recuperer_url($url, $options); |
|
| 686 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 687 | - if (!$res) { |
|
| 688 | - if ($is_cached) { |
|
| 689 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 690 | - lire_fichier($cache, $res); |
|
| 691 | - $res = unserialize($res); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return $errors[$url] = $res; |
|
| 695 | - } |
|
| 696 | - ecrire_fichier($cache, serialize($res)); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return $res; |
|
| 633 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 634 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 635 | + } |
|
| 636 | + $default = [ |
|
| 637 | + 'transcoder' => false, |
|
| 638 | + 'methode' => 'GET', |
|
| 639 | + 'taille_max' => null, |
|
| 640 | + 'datas' => '', |
|
| 641 | + 'boundary' => '', |
|
| 642 | + 'refuser_gz' => false, |
|
| 643 | + 'if_modified_since' => '', |
|
| 644 | + 'uri_referer' => '', |
|
| 645 | + 'file' => '', |
|
| 646 | + 'follow_location' => 10, |
|
| 647 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 648 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 649 | + ]; |
|
| 650 | + $options = array_merge($default, $options); |
|
| 651 | + |
|
| 652 | + // cas ou il n'est pas possible de cacher |
|
| 653 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 654 | + return recuperer_url($url, $options); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 658 | + static $errors = []; |
|
| 659 | + if (isset($errors[$url])) { |
|
| 660 | + return $errors[$url]; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $sig = $options; |
|
| 664 | + unset($sig['if_modified_since']); |
|
| 665 | + unset($sig['delai_cache']); |
|
| 666 | + $sig['url'] = $url; |
|
| 667 | + |
|
| 668 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 669 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 670 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 671 | + $cache = "$sub$cache"; |
|
| 672 | + |
|
| 673 | + $res = false; |
|
| 674 | + $is_cached = file_exists($cache); |
|
| 675 | + if ( |
|
| 676 | + $is_cached |
|
| 677 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 678 | + ) { |
|
| 679 | + lire_fichier($cache, $res); |
|
| 680 | + if ($res = unserialize($res)) { |
|
| 681 | + // mettre le last_modified et le status=304 ? |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + if (!$res) { |
|
| 685 | + $res = recuperer_url($url, $options); |
|
| 686 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 687 | + if (!$res) { |
|
| 688 | + if ($is_cached) { |
|
| 689 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 690 | + lire_fichier($cache, $res); |
|
| 691 | + $res = unserialize($res); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return $errors[$url] = $res; |
|
| 695 | + } |
|
| 696 | + ecrire_fichier($cache, serialize($res)); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return $res; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -714,41 +714,41 @@ discard block |
||
| 714 | 714 | * string contenu de la resource |
| 715 | 715 | */ |
| 716 | 716 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 717 | - $taille = 0; |
|
| 718 | - $result = ''; |
|
| 719 | - $fp = false; |
|
| 720 | - if ($fichier) { |
|
| 721 | - include_spip('inc/acces'); |
|
| 722 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 723 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 724 | - if (!$fp and file_exists($fichier)) { |
|
| 725 | - return filesize($fichier); |
|
| 726 | - } |
|
| 727 | - if (!$fp) { |
|
| 728 | - return false; |
|
| 729 | - } |
|
| 730 | - $result = 0; // on renvoie la taille du fichier |
|
| 731 | - } |
|
| 732 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 733 | - $res = fread($handle, 16384); |
|
| 734 | - $taille += strlen($res); |
|
| 735 | - if ($fp) { |
|
| 736 | - fwrite($fp, $res); |
|
| 737 | - $result = $taille; |
|
| 738 | - } else { |
|
| 739 | - $result .= $res; |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - if ($fp) { |
|
| 743 | - spip_fclose_unlock($fp); |
|
| 744 | - spip_unlink($fichier); |
|
| 745 | - @rename($tmpfile, $fichier); |
|
| 746 | - if (!file_exists($fichier)) { |
|
| 747 | - return false; |
|
| 748 | - } |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $result; |
|
| 717 | + $taille = 0; |
|
| 718 | + $result = ''; |
|
| 719 | + $fp = false; |
|
| 720 | + if ($fichier) { |
|
| 721 | + include_spip('inc/acces'); |
|
| 722 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 723 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 724 | + if (!$fp and file_exists($fichier)) { |
|
| 725 | + return filesize($fichier); |
|
| 726 | + } |
|
| 727 | + if (!$fp) { |
|
| 728 | + return false; |
|
| 729 | + } |
|
| 730 | + $result = 0; // on renvoie la taille du fichier |
|
| 731 | + } |
|
| 732 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 733 | + $res = fread($handle, 16384); |
|
| 734 | + $taille += strlen($res); |
|
| 735 | + if ($fp) { |
|
| 736 | + fwrite($fp, $res); |
|
| 737 | + $result = $taille; |
|
| 738 | + } else { |
|
| 739 | + $result .= $res; |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + if ($fp) { |
|
| 743 | + spip_fclose_unlock($fp); |
|
| 744 | + spip_unlink($fichier); |
|
| 745 | + @rename($tmpfile, $fichier); |
|
| 746 | + if (!file_exists($fichier)) { |
|
| 747 | + return false; |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $result; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -770,35 +770,35 @@ discard block |
||
| 770 | 770 | * string location |
| 771 | 771 | */ |
| 772 | 772 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 773 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 774 | - |
|
| 775 | - $s = @trim(fgets($handle, 16384)); |
|
| 776 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - $result['status'] = intval($r[1]); |
|
| 780 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 781 | - $result['headers'][] = $s . "\n"; |
|
| 782 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 783 | - list(, $d, $v) = $r; |
|
| 784 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 785 | - $result['location'] = $v; |
|
| 786 | - } elseif ($d == 'Last-Modified') { |
|
| 787 | - $result['last_modified'] = strtotime($v); |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - if ( |
|
| 791 | - $if_modified_since |
|
| 792 | - and $result['last_modified'] |
|
| 793 | - and $if_modified_since > $result['last_modified'] |
|
| 794 | - and $result['status'] == 200 |
|
| 795 | - ) { |
|
| 796 | - $result['status'] = 304; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - $result['headers'] = implode('', $result['headers']); |
|
| 800 | - |
|
| 801 | - return $result; |
|
| 773 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 774 | + |
|
| 775 | + $s = @trim(fgets($handle, 16384)); |
|
| 776 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + $result['status'] = intval($r[1]); |
|
| 780 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 781 | + $result['headers'][] = $s . "\n"; |
|
| 782 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 783 | + list(, $d, $v) = $r; |
|
| 784 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 785 | + $result['location'] = $v; |
|
| 786 | + } elseif ($d == 'Last-Modified') { |
|
| 787 | + $result['last_modified'] = strtotime($v); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + if ( |
|
| 791 | + $if_modified_since |
|
| 792 | + and $result['last_modified'] |
|
| 793 | + and $if_modified_since > $result['last_modified'] |
|
| 794 | + and $result['status'] == 200 |
|
| 795 | + ) { |
|
| 796 | + $result['status'] = 304; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + $result['headers'] = implode('', $result['headers']); |
|
| 800 | + |
|
| 801 | + return $result; |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -820,22 +820,22 @@ discard block |
||
| 820 | 820 | * Nom du fichier pour copie locale |
| 821 | 821 | **/ |
| 822 | 822 | function nom_fichier_copie_locale($source, $extension) { |
| 823 | - include_spip('inc/documents'); |
|
| 823 | + include_spip('inc/documents'); |
|
| 824 | 824 | |
| 825 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 826 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 825 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 826 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 827 | 827 | |
| 828 | - // on se place tout le temps comme si on etait a la racine |
|
| 829 | - if (_DIR_RACINE) { |
|
| 830 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 831 | - } |
|
| 828 | + // on se place tout le temps comme si on etait a la racine |
|
| 829 | + if (_DIR_RACINE) { |
|
| 830 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 831 | + } |
|
| 832 | 832 | |
| 833 | - $m = md5($source); |
|
| 833 | + $m = md5($source); |
|
| 834 | 834 | |
| 835 | - return $d |
|
| 836 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 837 | - . substr($m, 0, 4) |
|
| 838 | - . ".$extension"; |
|
| 835 | + return $d |
|
| 836 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 837 | + . substr($m, 0, 4) |
|
| 838 | + . ".$extension"; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -853,70 +853,70 @@ discard block |
||
| 853 | 853 | * Nom du fichier calculé |
| 854 | 854 | **/ |
| 855 | 855 | function fichier_copie_locale($source) { |
| 856 | - // Si c'est deja local pas de souci |
|
| 857 | - if (!tester_url_absolue($source)) { |
|
| 858 | - if (_DIR_RACINE) { |
|
| 859 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return $source; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 866 | - // a deja ete copie en local avec cette extension |
|
| 867 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 868 | - $path_parts = pathinfo($source); |
|
| 869 | - if (!isset($path_parts['extension'])) { |
|
| 870 | - $path_parts['extension'] = ''; |
|
| 871 | - } |
|
| 872 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 873 | - if ( |
|
| 874 | - $ext |
|
| 875 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 876 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 877 | - and file_exists(_DIR_RACINE . $f) |
|
| 878 | - ) { |
|
| 879 | - return $f; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - // Si c'est deja dans la table des documents, |
|
| 884 | - // ramener le nom de sa copie potentielle |
|
| 885 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 886 | - |
|
| 887 | - if ($ext) { |
|
| 888 | - return nom_fichier_copie_locale($source, $ext); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 892 | - // et si il n'aurait pas deja ete rapatrie |
|
| 893 | - |
|
| 894 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 895 | - |
|
| 896 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 897 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 898 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 899 | - return $f; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - // Ping pour voir si son extension est connue et autorisee |
|
| 904 | - // avec mise en cache du resultat du ping |
|
| 905 | - |
|
| 906 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 907 | - if ( |
|
| 908 | - !@file_exists($cache) |
|
| 909 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 910 | - or _request('var_mode') === 'recalcul' |
|
| 911 | - ) { |
|
| 912 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 913 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 914 | - } |
|
| 915 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 916 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 917 | - return nom_fichier_copie_locale($source, $ext); |
|
| 918 | - } |
|
| 919 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 856 | + // Si c'est deja local pas de souci |
|
| 857 | + if (!tester_url_absolue($source)) { |
|
| 858 | + if (_DIR_RACINE) { |
|
| 859 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return $source; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 866 | + // a deja ete copie en local avec cette extension |
|
| 867 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 868 | + $path_parts = pathinfo($source); |
|
| 869 | + if (!isset($path_parts['extension'])) { |
|
| 870 | + $path_parts['extension'] = ''; |
|
| 871 | + } |
|
| 872 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 873 | + if ( |
|
| 874 | + $ext |
|
| 875 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 876 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 877 | + and file_exists(_DIR_RACINE . $f) |
|
| 878 | + ) { |
|
| 879 | + return $f; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + // Si c'est deja dans la table des documents, |
|
| 884 | + // ramener le nom de sa copie potentielle |
|
| 885 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 886 | + |
|
| 887 | + if ($ext) { |
|
| 888 | + return nom_fichier_copie_locale($source, $ext); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 892 | + // et si il n'aurait pas deja ete rapatrie |
|
| 893 | + |
|
| 894 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 895 | + |
|
| 896 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 897 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 898 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 899 | + return $f; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + // Ping pour voir si son extension est connue et autorisee |
|
| 904 | + // avec mise en cache du resultat du ping |
|
| 905 | + |
|
| 906 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 907 | + if ( |
|
| 908 | + !@file_exists($cache) |
|
| 909 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 910 | + or _request('var_mode') === 'recalcul' |
|
| 911 | + ) { |
|
| 912 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 913 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 914 | + } |
|
| 915 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 916 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 917 | + return nom_fichier_copie_locale($source, $ext); |
|
| 918 | + } |
|
| 919 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
@@ -944,97 +944,97 @@ discard block |
||
| 944 | 944 | **/ |
| 945 | 945 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 946 | 946 | |
| 947 | - // pas la peine de perdre son temps |
|
| 948 | - if (!tester_url_absolue($source)) { |
|
| 949 | - return false; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - # charger les alias des types mime |
|
| 953 | - include_spip('base/typedoc'); |
|
| 954 | - |
|
| 955 | - $a = []; |
|
| 956 | - $mime_type = ''; |
|
| 957 | - // On va directement charger le debut des images et des fichiers html, |
|
| 958 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 959 | - // ca echoue l'utilisateur devra les entrer... |
|
| 960 | - $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 961 | - $headers = $reponse['headers'] ?? ''; |
|
| 962 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 963 | - if ($headers) { |
|
| 964 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 965 | - return false; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - $a['extension'] = $extension; |
|
| 969 | - |
|
| 970 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 971 | - $a['taille'] = intval($regs[1]); |
|
| 972 | - } |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - // Echec avec HEAD, on tente avec GET |
|
| 976 | - if (!$a and !$max) { |
|
| 977 | - spip_log("tenter GET $source", 'distant'); |
|
| 978 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - // si on a rien trouve pas la peine d'insister |
|
| 982 | - if (!$a) { |
|
| 983 | - return false; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 987 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 988 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 989 | - if ( |
|
| 990 | - strpos($mime_type, 'image/') === 0 |
|
| 991 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 992 | - ) { |
|
| 993 | - if ( |
|
| 994 | - $max == 0 |
|
| 995 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 996 | - and in_array($extension, formats_image_acceptables()) |
|
| 997 | - and $charger_si_petite_image |
|
| 998 | - ) { |
|
| 999 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1000 | - } else { |
|
| 1001 | - if ($a['body']) { |
|
| 1002 | - $a['extension'] = $extension; |
|
| 1003 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1004 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1005 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1006 | - $a['largeur'] = intval($size_image[0]); |
|
| 1007 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1008 | - $a['type_image'] = true; |
|
| 1009 | - } |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1014 | - // ce sera mieux que 0x0 |
|
| 1015 | - // Flash is dead! |
|
| 1016 | - if ( |
|
| 1017 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1018 | - and empty($a['largeur']) |
|
| 1019 | - ) { |
|
| 1020 | - $a['largeur'] = 425; |
|
| 1021 | - $a['hauteur'] = 350; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - if ($mime_type == 'text/html') { |
|
| 1025 | - include_spip('inc/filtres'); |
|
| 1026 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1027 | - $page = $page['page'] ?? ''; |
|
| 1028 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1029 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1030 | - } |
|
| 1031 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1032 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - $a['mime_type'] = $mime_type; |
|
| 1036 | - |
|
| 1037 | - return $a; |
|
| 947 | + // pas la peine de perdre son temps |
|
| 948 | + if (!tester_url_absolue($source)) { |
|
| 949 | + return false; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + # charger les alias des types mime |
|
| 953 | + include_spip('base/typedoc'); |
|
| 954 | + |
|
| 955 | + $a = []; |
|
| 956 | + $mime_type = ''; |
|
| 957 | + // On va directement charger le debut des images et des fichiers html, |
|
| 958 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 959 | + // ca echoue l'utilisateur devra les entrer... |
|
| 960 | + $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]); |
|
| 961 | + $headers = $reponse['headers'] ?? ''; |
|
| 962 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 963 | + if ($headers) { |
|
| 964 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 965 | + return false; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + $a['extension'] = $extension; |
|
| 969 | + |
|
| 970 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 971 | + $a['taille'] = intval($regs[1]); |
|
| 972 | + } |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + // Echec avec HEAD, on tente avec GET |
|
| 976 | + if (!$a and !$max) { |
|
| 977 | + spip_log("tenter GET $source", 'distant'); |
|
| 978 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + // si on a rien trouve pas la peine d'insister |
|
| 982 | + if (!$a) { |
|
| 983 | + return false; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 987 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 988 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 989 | + if ( |
|
| 990 | + strpos($mime_type, 'image/') === 0 |
|
| 991 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 992 | + ) { |
|
| 993 | + if ( |
|
| 994 | + $max == 0 |
|
| 995 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 996 | + and in_array($extension, formats_image_acceptables()) |
|
| 997 | + and $charger_si_petite_image |
|
| 998 | + ) { |
|
| 999 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1000 | + } else { |
|
| 1001 | + if ($a['body']) { |
|
| 1002 | + $a['extension'] = $extension; |
|
| 1003 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1004 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1005 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1006 | + $a['largeur'] = intval($size_image[0]); |
|
| 1007 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1008 | + $a['type_image'] = true; |
|
| 1009 | + } |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1014 | + // ce sera mieux que 0x0 |
|
| 1015 | + // Flash is dead! |
|
| 1016 | + if ( |
|
| 1017 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1018 | + and empty($a['largeur']) |
|
| 1019 | + ) { |
|
| 1020 | + $a['largeur'] = 425; |
|
| 1021 | + $a['hauteur'] = 350; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + if ($mime_type == 'text/html') { |
|
| 1025 | + include_spip('inc/filtres'); |
|
| 1026 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1027 | + $page = $page['page'] ?? ''; |
|
| 1028 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1029 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1030 | + } |
|
| 1031 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1032 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + $a['mime_type'] = $mime_type; |
|
| 1036 | + |
|
| 1037 | + return $a; |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | /** |
@@ -1043,67 +1043,67 @@ discard block |
||
| 1043 | 1043 | * @return false|mixed |
| 1044 | 1044 | */ |
| 1045 | 1045 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1046 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1047 | - $mime_type = (trim($regs[1])); |
|
| 1048 | - } else { |
|
| 1049 | - $mime_type = ''; |
|
| 1050 | - } // inconnu |
|
| 1051 | - |
|
| 1052 | - // Appliquer les alias |
|
| 1053 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1054 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Si on a un mime-type insignifiant |
|
| 1058 | - // text/plain,application/octet-stream ou vide |
|
| 1059 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1060 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1061 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1062 | - $t = null; |
|
| 1063 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1064 | - if ( |
|
| 1065 | - !$t |
|
| 1066 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1067 | - ) { |
|
| 1068 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1069 | - } |
|
| 1070 | - if ( |
|
| 1071 | - !$t |
|
| 1072 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1073 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1074 | - ) { |
|
| 1075 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1080 | - if (!$t) { |
|
| 1081 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1085 | - // On essaie de nouveau avec l'extension |
|
| 1086 | - if ( |
|
| 1087 | - !$t |
|
| 1088 | - and $mime_type != 'text/plain' |
|
| 1089 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1090 | - ) { |
|
| 1091 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1092 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - if ($t) { |
|
| 1096 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1097 | - return $t['extension']; |
|
| 1098 | - } else { |
|
| 1099 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1100 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1101 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1102 | - if (!$t) { |
|
| 1103 | - return false; |
|
| 1104 | - } |
|
| 1105 | - return $t['extension']; |
|
| 1106 | - } |
|
| 1046 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1047 | + $mime_type = (trim($regs[1])); |
|
| 1048 | + } else { |
|
| 1049 | + $mime_type = ''; |
|
| 1050 | + } // inconnu |
|
| 1051 | + |
|
| 1052 | + // Appliquer les alias |
|
| 1053 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1054 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Si on a un mime-type insignifiant |
|
| 1058 | + // text/plain,application/octet-stream ou vide |
|
| 1059 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1060 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1061 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1062 | + $t = null; |
|
| 1063 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1064 | + if ( |
|
| 1065 | + !$t |
|
| 1066 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1067 | + ) { |
|
| 1068 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1069 | + } |
|
| 1070 | + if ( |
|
| 1071 | + !$t |
|
| 1072 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1073 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1074 | + ) { |
|
| 1075 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1080 | + if (!$t) { |
|
| 1081 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1085 | + // On essaie de nouveau avec l'extension |
|
| 1086 | + if ( |
|
| 1087 | + !$t |
|
| 1088 | + and $mime_type != 'text/plain' |
|
| 1089 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1090 | + ) { |
|
| 1091 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1092 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + if ($t) { |
|
| 1096 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1097 | + return $t['extension']; |
|
| 1098 | + } else { |
|
| 1099 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1100 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1101 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1102 | + if (!$t) { |
|
| 1103 | + return false; |
|
| 1104 | + } |
|
| 1105 | + return $t['extension']; |
|
| 1106 | + } |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | /** |
@@ -1118,46 +1118,46 @@ discard block |
||
| 1118 | 1118 | * @return string |
| 1119 | 1119 | */ |
| 1120 | 1120 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1121 | - if (is_null($http_proxy)) { |
|
| 1122 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1123 | - } |
|
| 1124 | - // rien a faire si pas de proxy :) |
|
| 1125 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1126 | - return ''; |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - if (is_null($http_noproxy)) { |
|
| 1130 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1131 | - } |
|
| 1132 | - // si pas d'exception, on retourne le proxy |
|
| 1133 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1134 | - return $http_proxy; |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1138 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1139 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1140 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1141 | - $http_noproxy = " $http_noproxy "; |
|
| 1142 | - $domain = $host; |
|
| 1143 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1144 | - if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1145 | - return ''; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - while (strpos($domain, '.') !== false) { |
|
| 1149 | - $domain = explode('.', $domain); |
|
| 1150 | - array_shift($domain); |
|
| 1151 | - $domain = implode('.', $domain); |
|
| 1152 | - |
|
| 1153 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1154 | - if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1155 | - return ''; |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - // ok c'est pas une exception |
|
| 1160 | - return $http_proxy; |
|
| 1121 | + if (is_null($http_proxy)) { |
|
| 1122 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1123 | + } |
|
| 1124 | + // rien a faire si pas de proxy :) |
|
| 1125 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1126 | + return ''; |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + if (is_null($http_noproxy)) { |
|
| 1130 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1131 | + } |
|
| 1132 | + // si pas d'exception, on retourne le proxy |
|
| 1133 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1134 | + return $http_proxy; |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1138 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1139 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1140 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1141 | + $http_noproxy = " $http_noproxy "; |
|
| 1142 | + $domain = $host; |
|
| 1143 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1144 | + if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1145 | + return ''; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + while (strpos($domain, '.') !== false) { |
|
| 1149 | + $domain = explode('.', $domain); |
|
| 1150 | + array_shift($domain); |
|
| 1151 | + $domain = implode('.', $domain); |
|
| 1152 | + |
|
| 1153 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1154 | + if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1155 | + return ''; |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + // ok c'est pas une exception |
|
| 1160 | + return $http_proxy; |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | |
@@ -1180,59 +1180,59 @@ discard block |
||
| 1180 | 1180 | * @return array |
| 1181 | 1181 | */ |
| 1182 | 1182 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1183 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1184 | - $fopen = false; |
|
| 1185 | - |
|
| 1186 | - $t = @parse_url($url); |
|
| 1187 | - $host = $t['host']; |
|
| 1188 | - if ($t['scheme'] == 'http') { |
|
| 1189 | - $scheme = 'http'; |
|
| 1190 | - $noproxy = ''; |
|
| 1191 | - } elseif ($t['scheme'] == 'https') { |
|
| 1192 | - $scheme = 'ssl'; |
|
| 1193 | - $noproxy = 'ssl://'; |
|
| 1194 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1195 | - $t['port'] = 443; |
|
| 1196 | - } |
|
| 1197 | - } else { |
|
| 1198 | - $scheme = $t['scheme']; |
|
| 1199 | - $noproxy = $scheme . '://'; |
|
| 1200 | - } |
|
| 1201 | - if (isset($t['user'])) { |
|
| 1202 | - $user = [$t['user'], $t['pass']]; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1206 | - $port = 80; |
|
| 1207 | - } |
|
| 1208 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1209 | - $path = '/'; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - if (!empty($t['query'])) { |
|
| 1213 | - $path .= '?' . $t['query']; |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1217 | - if (!$f or !is_resource($f)) { |
|
| 1218 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1219 | - // ce qui correspond a $f===110 |
|
| 1220 | - if ( |
|
| 1221 | - $f !== 110 |
|
| 1222 | - and !need_proxy($host) |
|
| 1223 | - and !_request('tester_proxy') |
|
| 1224 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1225 | - ) { |
|
| 1226 | - $f = @fopen($url, 'rb'); |
|
| 1227 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1228 | - $fopen = true; |
|
| 1229 | - } else { |
|
| 1230 | - // echec total |
|
| 1231 | - $f = false; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - return [$f, $fopen]; |
|
| 1183 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1184 | + $fopen = false; |
|
| 1185 | + |
|
| 1186 | + $t = @parse_url($url); |
|
| 1187 | + $host = $t['host']; |
|
| 1188 | + if ($t['scheme'] == 'http') { |
|
| 1189 | + $scheme = 'http'; |
|
| 1190 | + $noproxy = ''; |
|
| 1191 | + } elseif ($t['scheme'] == 'https') { |
|
| 1192 | + $scheme = 'ssl'; |
|
| 1193 | + $noproxy = 'ssl://'; |
|
| 1194 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1195 | + $t['port'] = 443; |
|
| 1196 | + } |
|
| 1197 | + } else { |
|
| 1198 | + $scheme = $t['scheme']; |
|
| 1199 | + $noproxy = $scheme . '://'; |
|
| 1200 | + } |
|
| 1201 | + if (isset($t['user'])) { |
|
| 1202 | + $user = [$t['user'], $t['pass']]; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1206 | + $port = 80; |
|
| 1207 | + } |
|
| 1208 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1209 | + $path = '/'; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + if (!empty($t['query'])) { |
|
| 1213 | + $path .= '?' . $t['query']; |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1217 | + if (!$f or !is_resource($f)) { |
|
| 1218 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1219 | + // ce qui correspond a $f===110 |
|
| 1220 | + if ( |
|
| 1221 | + $f !== 110 |
|
| 1222 | + and !need_proxy($host) |
|
| 1223 | + and !_request('tester_proxy') |
|
| 1224 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1225 | + ) { |
|
| 1226 | + $f = @fopen($url, 'rb'); |
|
| 1227 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1228 | + $fopen = true; |
|
| 1229 | + } else { |
|
| 1230 | + // echec total |
|
| 1231 | + $f = false; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + return [$f, $fopen]; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1267,125 +1267,125 @@ discard block |
||
| 1267 | 1267 | * resource socket vers l'url demandee |
| 1268 | 1268 | */ |
| 1269 | 1269 | function lance_requete( |
| 1270 | - $method, |
|
| 1271 | - $scheme, |
|
| 1272 | - $user, |
|
| 1273 | - $host, |
|
| 1274 | - $path, |
|
| 1275 | - $port, |
|
| 1276 | - $noproxy, |
|
| 1277 | - $refuse_gz = false, |
|
| 1278 | - $referer = '', |
|
| 1279 | - $datas = '', |
|
| 1280 | - $vers = 'HTTP/1.0', |
|
| 1281 | - $date = '' |
|
| 1270 | + $method, |
|
| 1271 | + $scheme, |
|
| 1272 | + $user, |
|
| 1273 | + $host, |
|
| 1274 | + $path, |
|
| 1275 | + $port, |
|
| 1276 | + $noproxy, |
|
| 1277 | + $refuse_gz = false, |
|
| 1278 | + $referer = '', |
|
| 1279 | + $datas = '', |
|
| 1280 | + $vers = 'HTTP/1.0', |
|
| 1281 | + $date = '' |
|
| 1282 | 1282 | ) { |
| 1283 | 1283 | |
| 1284 | - $proxy_user = ''; |
|
| 1285 | - $http_proxy = need_proxy($host); |
|
| 1286 | - if ($user) { |
|
| 1287 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - $connect = ''; |
|
| 1291 | - if ($http_proxy) { |
|
| 1292 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1293 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1294 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1295 | - . "Host: $path_host\r\n" |
|
| 1296 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1297 | - } else { |
|
| 1298 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1299 | - . (!$user ? '' : "$user@") |
|
| 1300 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1301 | - } |
|
| 1302 | - $t2 = @parse_url($http_proxy); |
|
| 1303 | - $first_host = $t2['host']; |
|
| 1304 | - if (!($port = $t2['port'])) { |
|
| 1305 | - $port = 80; |
|
| 1306 | - } |
|
| 1307 | - if ($t2['user']) { |
|
| 1308 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1309 | - } |
|
| 1310 | - } else { |
|
| 1311 | - $first_host = $noproxy . $host; |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - if ($connect) { |
|
| 1315 | - $streamContext = stream_context_create([ |
|
| 1316 | - 'ssl' => [ |
|
| 1317 | - 'verify_peer' => false, |
|
| 1318 | - 'allow_self_signed' => true, |
|
| 1319 | - 'SNI_enabled' => true, |
|
| 1320 | - 'peer_name' => $host, |
|
| 1321 | - ] |
|
| 1322 | - ]); |
|
| 1323 | - $f = @stream_socket_client( |
|
| 1324 | - "tcp://$first_host:$port", |
|
| 1325 | - $errno, |
|
| 1326 | - $errstr, |
|
| 1327 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1328 | - STREAM_CLIENT_CONNECT, |
|
| 1329 | - $streamContext |
|
| 1330 | - ); |
|
| 1331 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1332 | - if (!$f) { |
|
| 1333 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1334 | - return $errno; |
|
| 1335 | - } |
|
| 1336 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1337 | - |
|
| 1338 | - fputs($f, $connect); |
|
| 1339 | - fputs($f, "\r\n"); |
|
| 1340 | - $res = fread($f, 1024); |
|
| 1341 | - if ( |
|
| 1342 | - !$res |
|
| 1343 | - or !count($res = explode(' ', $res)) |
|
| 1344 | - or $res[1] !== '200' |
|
| 1345 | - ) { |
|
| 1346 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1347 | - fclose($f); |
|
| 1348 | - |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1352 | - stream_set_blocking($f, true); |
|
| 1353 | - // envoyer le handshake |
|
| 1354 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1355 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1356 | - } else { |
|
| 1357 | - $ntry = 3; |
|
| 1358 | - do { |
|
| 1359 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1360 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1361 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1362 | - if (!$f) { |
|
| 1363 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1364 | - |
|
| 1365 | - return $errno; |
|
| 1366 | - } |
|
| 1367 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1371 | - |
|
| 1372 | - $host_port = $host; |
|
| 1373 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1374 | - $host_port .= ":$port"; |
|
| 1375 | - } |
|
| 1376 | - $req = "$method $path $vers\r\n" |
|
| 1377 | - . "Host: $host_port\r\n" |
|
| 1378 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1379 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1380 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1381 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1382 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1383 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1384 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1284 | + $proxy_user = ''; |
|
| 1285 | + $http_proxy = need_proxy($host); |
|
| 1286 | + if ($user) { |
|
| 1287 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + $connect = ''; |
|
| 1291 | + if ($http_proxy) { |
|
| 1292 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1293 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1294 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1295 | + . "Host: $path_host\r\n" |
|
| 1296 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1297 | + } else { |
|
| 1298 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1299 | + . (!$user ? '' : "$user@") |
|
| 1300 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1301 | + } |
|
| 1302 | + $t2 = @parse_url($http_proxy); |
|
| 1303 | + $first_host = $t2['host']; |
|
| 1304 | + if (!($port = $t2['port'])) { |
|
| 1305 | + $port = 80; |
|
| 1306 | + } |
|
| 1307 | + if ($t2['user']) { |
|
| 1308 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1309 | + } |
|
| 1310 | + } else { |
|
| 1311 | + $first_host = $noproxy . $host; |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + if ($connect) { |
|
| 1315 | + $streamContext = stream_context_create([ |
|
| 1316 | + 'ssl' => [ |
|
| 1317 | + 'verify_peer' => false, |
|
| 1318 | + 'allow_self_signed' => true, |
|
| 1319 | + 'SNI_enabled' => true, |
|
| 1320 | + 'peer_name' => $host, |
|
| 1321 | + ] |
|
| 1322 | + ]); |
|
| 1323 | + $f = @stream_socket_client( |
|
| 1324 | + "tcp://$first_host:$port", |
|
| 1325 | + $errno, |
|
| 1326 | + $errstr, |
|
| 1327 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1328 | + STREAM_CLIENT_CONNECT, |
|
| 1329 | + $streamContext |
|
| 1330 | + ); |
|
| 1331 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1332 | + if (!$f) { |
|
| 1333 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1334 | + return $errno; |
|
| 1335 | + } |
|
| 1336 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1337 | + |
|
| 1338 | + fputs($f, $connect); |
|
| 1339 | + fputs($f, "\r\n"); |
|
| 1340 | + $res = fread($f, 1024); |
|
| 1341 | + if ( |
|
| 1342 | + !$res |
|
| 1343 | + or !count($res = explode(' ', $res)) |
|
| 1344 | + or $res[1] !== '200' |
|
| 1345 | + ) { |
|
| 1346 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1347 | + fclose($f); |
|
| 1348 | + |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1352 | + stream_set_blocking($f, true); |
|
| 1353 | + // envoyer le handshake |
|
| 1354 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1355 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1356 | + } else { |
|
| 1357 | + $ntry = 3; |
|
| 1358 | + do { |
|
| 1359 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1360 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1361 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1362 | + if (!$f) { |
|
| 1363 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1364 | + |
|
| 1365 | + return $errno; |
|
| 1366 | + } |
|
| 1367 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1371 | + |
|
| 1372 | + $host_port = $host; |
|
| 1373 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1374 | + $host_port .= ":$port"; |
|
| 1375 | + } |
|
| 1376 | + $req = "$method $path $vers\r\n" |
|
| 1377 | + . "Host: $host_port\r\n" |
|
| 1378 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1379 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1380 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1381 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1382 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1383 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1384 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1385 | 1385 | |
| 1386 | 1386 | # spip_log("Requete\n$req", 'distant'); |
| 1387 | - fputs($f, $req); |
|
| 1388 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1387 | + fputs($f, $req); |
|
| 1388 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1389 | 1389 | |
| 1390 | - return $f; |
|
| 1390 | + return $f; |
|
| 1391 | 1391 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode === 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant'); |
|
| 125 | 125 | |
| 126 | 126 | // si on retrouve l'extension |
| 127 | 127 | if ( |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if (!$is_known_host) { |
| 207 | 207 | $host = trim($parsed_url['host'], '.'); |
| 208 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 208 | + if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 209 | 209 | $ip = gethostbyname($host); |
| 210 | 210 | if ($ip === $host) { |
| 211 | 211 | // Error condition for gethostbyname() |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | foreach ($records as $record) { |
| 216 | 216 | // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
| 217 | 217 | // se fasse sur la meme IP |
| 218 | - if ($record['ttl']<10) { |
|
| 218 | + if ($record['ttl'] < 10) { |
|
| 219 | 219 | $ip = false; |
| 220 | 220 | break; |
| 221 | 221 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | if ($ip) { |
| 229 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 229 | + if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 230 | 230 | return false; |
| 231 | 231 | } |
| 232 | 232 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $port = $parsed_url['port']; |
| 240 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 240 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 241 | 241 | return $url; |
| 242 | 242 | } |
| 243 | 243 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | if ($taille > 500) { |
| 310 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 310 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
@@ -335,16 +335,16 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | } else { |
| 337 | 337 | // fabrique une chaine HTTP simple pour un POST |
| 338 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 338 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 339 | 339 | $chaine = []; |
| 340 | 340 | if (is_array($donnees)) { |
| 341 | 341 | foreach ($donnees as $cle => $valeur) { |
| 342 | 342 | if (is_array($valeur)) { |
| 343 | 343 | foreach ($valeur as $val2) { |
| 344 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 344 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 345 | 345 | } |
| 346 | 346 | } else { |
| 347 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 347 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | $chaine = implode('&', $chaine); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $url_idn = implode($host_ascii, $url_idn); |
| 379 | 379 | } |
| 380 | 380 | // et on urlencode les char utf si besoin dans le path |
| 381 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) { |
|
| 381 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { |
|
| 382 | 382 | return urlencode($match[0]); |
| 383 | 383 | }, $url_idn); |
| 384 | 384 | } |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | $head_add = ''; |
| 457 | 457 | if (!empty($options['headers'])) { |
| 458 | 458 | foreach ($options['headers'] as $champ => $valeur) { |
| 459 | - $head_add .= $champ . ': ' . $valeur . "\r\n"; |
|
| 459 | + $head_add .= $champ.': '.$valeur."\r\n"; |
|
| 460 | 460 | } |
| 461 | 461 | // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas |
| 462 | 462 | unset($options['headers']); |
@@ -466,9 +466,9 @@ discard block |
||
| 466 | 466 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 467 | 467 | $head .= $head_add; |
| 468 | 468 | if (stripos($head, 'Content-Length:') === false) { |
| 469 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 469 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 470 | 470 | } |
| 471 | - $options['datas'] = $head . "\r\n" . $postdata; |
|
| 471 | + $options['datas'] = $head."\r\n".$postdata; |
|
| 472 | 472 | if ( |
| 473 | 473 | strlen($postdata) |
| 474 | 474 | and !$methode_demandee |
@@ -476,15 +476,15 @@ discard block |
||
| 476 | 476 | $options['methode'] = 'POST'; |
| 477 | 477 | } |
| 478 | 478 | } elseif ($head_add) { |
| 479 | - $options['datas'] = $head_add . "\r\n"; |
|
| 479 | + $options['datas'] = $head_add."\r\n"; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 483 | 483 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 484 | 484 | if (!tester_url_absolue($url)) { |
| 485 | - $url = 'http://' . $url; |
|
| 485 | + $url = 'http://'.$url; |
|
| 486 | 486 | } elseif (strncmp($url, '//', 2) == 0) { |
| 487 | - $url = 'http:' . $url; |
|
| 487 | + $url = 'http:'.$url; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | $url = url_to_ascii($url); |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $options['if_modified_since'] |
| 514 | 514 | ); |
| 515 | 515 | if (!$handle) { |
| 516 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 516 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 517 | 517 | |
| 518 | 518 | return false; |
| 519 | 519 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | 'status' => 200, |
| 544 | 544 | ]; |
| 545 | 545 | } else { |
| 546 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 546 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | return recuperer_url($url, $options); |
| 557 | 557 | } elseif ($res['status'] !== 200) { |
| 558 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 558 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 559 | 559 | } |
| 560 | 560 | $result['status'] = $res['status']; |
| 561 | 561 | if (isset($res['headers'])) { |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | |
| 581 | 581 | $gz = false; |
| 582 | 582 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 583 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 583 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | $sig['url'] = $url; |
| 667 | 667 | |
| 668 | 668 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 669 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 669 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 670 | 670 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 671 | 671 | $cache = "$sub$cache"; |
| 672 | 672 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $fp = false; |
| 720 | 720 | if ($fichier) { |
| 721 | 721 | include_spip('inc/acces'); |
| 722 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 722 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 723 | 723 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 724 | 724 | if (!$fp and file_exists($fichier)) { |
| 725 | 725 | return filesize($fichier); |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | } |
| 779 | 779 | $result['status'] = intval($r[1]); |
| 780 | 780 | while ($s = trim(fgets($handle, 16384))) { |
| 781 | - $result['headers'][] = $s . "\n"; |
|
| 781 | + $result['headers'][] = $s."\n"; |
|
| 782 | 782 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 783 | 783 | list(, $d, $v) = $r; |
| 784 | 784 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -827,13 +827,13 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | // on se place tout le temps comme si on etait a la racine |
| 829 | 829 | if (_DIR_RACINE) { |
| 830 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 830 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | $m = md5($source); |
| 834 | 834 | |
| 835 | 835 | return $d |
| 836 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 836 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 837 | 837 | . substr($m, 0, 4) |
| 838 | 838 | . ".$extension"; |
| 839 | 839 | } |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | // Si c'est deja local pas de souci |
| 857 | 857 | if (!tester_url_absolue($source)) { |
| 858 | 858 | if (_DIR_RACINE) { |
| 859 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 859 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | return $source; |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | $ext |
| 875 | 875 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 876 | 876 | and $f = nom_fichier_copie_locale($source, $ext) |
| 877 | - and file_exists(_DIR_RACINE . $f) |
|
| 877 | + and file_exists(_DIR_RACINE.$f) |
|
| 878 | 878 | ) { |
| 879 | 879 | return $f; |
| 880 | 880 | } |
@@ -882,7 +882,7 @@ discard block |
||
| 882 | 882 | |
| 883 | 883 | // Si c'est deja dans la table des documents, |
| 884 | 884 | // ramener le nom de sa copie potentielle |
| 885 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 885 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 886 | 886 | |
| 887 | 887 | if ($ext) { |
| 888 | 888 | return nom_fichier_copie_locale($source, $ext); |
@@ -893,9 +893,9 @@ discard block |
||
| 893 | 893 | |
| 894 | 894 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 895 | 895 | |
| 896 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 896 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 897 | 897 | $f = nom_fichier_copie_locale($source, $ext); |
| 898 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 898 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 899 | 899 | return $f; |
| 900 | 900 | } |
| 901 | 901 | } |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | // Ping pour voir si son extension est connue et autorisee |
| 904 | 904 | // avec mise en cache du resultat du ping |
| 905 | 905 | |
| 906 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 906 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 907 | 907 | if ( |
| 908 | 908 | !@file_exists($cache) |
| 909 | 909 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
@@ -913,10 +913,10 @@ discard block |
||
| 913 | 913 | ecrire_fichier($cache, serialize($path_parts)); |
| 914 | 914 | } |
| 915 | 915 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 916 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 916 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 917 | 917 | return nom_fichier_copie_locale($source, $ext); |
| 918 | 918 | } |
| 919 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 919 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
@@ -1000,7 +1000,7 @@ discard block |
||
| 1000 | 1000 | } else { |
| 1001 | 1001 | if ($a['body']) { |
| 1002 | 1002 | $a['extension'] = $extension; |
| 1003 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1003 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 1004 | 1004 | ecrire_fichier($a['fichier'], $a['body']); |
| 1005 | 1005 | $size_image = @spip_getimagesize($a['fichier']); |
| 1006 | 1006 | $a['largeur'] = intval($size_image[0]); |
@@ -1065,20 +1065,20 @@ discard block |
||
| 1065 | 1065 | !$t |
| 1066 | 1066 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1067 | 1067 | ) { |
| 1068 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1068 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | if ( |
| 1071 | 1071 | !$t |
| 1072 | 1072 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1073 | 1073 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1074 | 1074 | ) { |
| 1075 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1075 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1080 | 1080 | if (!$t) { |
| 1081 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1081 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1089,11 +1089,11 @@ discard block |
||
| 1089 | 1089 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1090 | 1090 | ) { |
| 1091 | 1091 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1092 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1092 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | if ($t) { |
| 1096 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1096 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 1097 | 1097 | return $t['extension']; |
| 1098 | 1098 | } else { |
| 1099 | 1099 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | } |
| 1197 | 1197 | } else { |
| 1198 | 1198 | $scheme = $t['scheme']; |
| 1199 | - $noproxy = $scheme . '://'; |
|
| 1199 | + $noproxy = $scheme.'://'; |
|
| 1200 | 1200 | } |
| 1201 | 1201 | if (isset($t['user'])) { |
| 1202 | 1202 | $user = [$t['user'], $t['pass']]; |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | if (!empty($t['query'])) { |
| 1213 | - $path .= '?' . $t['query']; |
|
| 1213 | + $path .= '?'.$t['query']; |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1284,20 +1284,20 @@ discard block |
||
| 1284 | 1284 | $proxy_user = ''; |
| 1285 | 1285 | $http_proxy = need_proxy($host); |
| 1286 | 1286 | if ($user) { |
| 1287 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1287 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | $connect = ''; |
| 1291 | 1291 | if ($http_proxy) { |
| 1292 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1293 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1294 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1292 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) { |
|
| 1293 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1294 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1295 | 1295 | . "Host: $path_host\r\n" |
| 1296 | 1296 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1297 | 1297 | } else { |
| 1298 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1298 | + $path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://") |
|
| 1299 | 1299 | . (!$user ? '' : "$user@") |
| 1300 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1300 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1301 | 1301 | } |
| 1302 | 1302 | $t2 = @parse_url($http_proxy); |
| 1303 | 1303 | $first_host = $t2['host']; |
@@ -1305,10 +1305,10 @@ discard block |
||
| 1305 | 1305 | $port = 80; |
| 1306 | 1306 | } |
| 1307 | 1307 | if ($t2['user']) { |
| 1308 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1308 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | } else { |
| 1311 | - $first_host = $noproxy . $host; |
|
| 1311 | + $first_host = $noproxy.$host; |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | if ($connect) { |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | ); |
| 1331 | 1331 | spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
| 1332 | 1332 | if (!$f) { |
| 1333 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1333 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1334 | 1334 | return $errno; |
| 1335 | 1335 | } |
| 1336 | 1336 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1343,7 +1343,7 @@ discard block |
||
| 1343 | 1343 | or !count($res = explode(' ', $res)) |
| 1344 | 1344 | or $res[1] !== '200' |
| 1345 | 1345 | ) { |
| 1346 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1346 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1347 | 1347 | fclose($f); |
| 1348 | 1348 | |
| 1349 | 1349 | return false; |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1361 | 1361 | spip_log("Recuperer $path sur $first_host:$port par $f"); |
| 1362 | 1362 | if (!$f) { |
| 1363 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1363 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1364 | 1364 | |
| 1365 | 1365 | return $errno; |
| 1366 | 1366 | } |
@@ -1370,16 +1370,16 @@ discard block |
||
| 1370 | 1370 | $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
| 1371 | 1371 | |
| 1372 | 1372 | $host_port = $host; |
| 1373 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1373 | + if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) { |
|
| 1374 | 1374 | $host_port .= ":$port"; |
| 1375 | 1375 | } |
| 1376 | 1376 | $req = "$method $path $vers\r\n" |
| 1377 | 1377 | . "Host: $host_port\r\n" |
| 1378 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1379 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1378 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1379 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1380 | 1380 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1381 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1382 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1381 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1382 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1383 | 1383 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1384 | 1384 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1385 | 1385 | |