@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,583 +21,583 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - // cas des SI {si expression} analises tres tot |
|
| 27 | - // pour eviter le chargement de tout iterateur |
|
| 28 | - if (isset($command['si'])) { |
|
| 29 | - foreach ($command['si'] as $si) { |
|
| 30 | - if (!$si) { |
|
| 31 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 32 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 33 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 39 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 40 | - // pour etre certain qu'on est sur un "php:") |
|
| 41 | - if (class_exists($iterateur)) { |
|
| 42 | - $a = isset($command['args']) ? $command['args'] : []; |
|
| 43 | - |
|
| 44 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 45 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 46 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 47 | - $iter = $a[0]; |
|
| 48 | - |
|
| 49 | - // sinon, on cree un iterateur du type donne |
|
| 50 | - } else { |
|
| 51 | - // arguments de creation de l'iterateur... |
|
| 52 | - // (pas glop) |
|
| 53 | - try { |
|
| 54 | - switch (count($a)) { |
|
| 55 | - case 0: |
|
| 56 | - $iter = new $iterateur(); |
|
| 57 | - break; |
|
| 58 | - case 1: |
|
| 59 | - $iter = new $iterateur($a[0]); |
|
| 60 | - break; |
|
| 61 | - case 2: |
|
| 62 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 63 | - break; |
|
| 64 | - case 3: |
|
| 65 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 66 | - break; |
|
| 67 | - case 4: |
|
| 68 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - } catch (Exception $e) { |
|
| 72 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 73 | - spip_log($e->getMessage()); |
|
| 74 | - $iter = new EmptyIterator(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - // chercher la classe d'iterateur |
|
| 79 | - // IterateurXXX |
|
| 80 | - // definie dans le fichier iterateurs/xxx.php |
|
| 81 | - $class = 'Iterateur' . $iterateur; |
|
| 82 | - if (!class_exists($class)) { |
|
| 83 | - if ( |
|
| 84 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + // cas des SI {si expression} analises tres tot |
|
| 27 | + // pour eviter le chargement de tout iterateur |
|
| 28 | + if (isset($command['si'])) { |
|
| 29 | + foreach ($command['si'] as $si) { |
|
| 30 | + if (!$si) { |
|
| 31 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 32 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 33 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 39 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 40 | + // pour etre certain qu'on est sur un "php:") |
|
| 41 | + if (class_exists($iterateur)) { |
|
| 42 | + $a = isset($command['args']) ? $command['args'] : []; |
|
| 43 | + |
|
| 44 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 45 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 46 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 47 | + $iter = $a[0]; |
|
| 48 | + |
|
| 49 | + // sinon, on cree un iterateur du type donne |
|
| 50 | + } else { |
|
| 51 | + // arguments de creation de l'iterateur... |
|
| 52 | + // (pas glop) |
|
| 53 | + try { |
|
| 54 | + switch (count($a)) { |
|
| 55 | + case 0: |
|
| 56 | + $iter = new $iterateur(); |
|
| 57 | + break; |
|
| 58 | + case 1: |
|
| 59 | + $iter = new $iterateur($a[0]); |
|
| 60 | + break; |
|
| 61 | + case 2: |
|
| 62 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 63 | + break; |
|
| 64 | + case 3: |
|
| 65 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 66 | + break; |
|
| 67 | + case 4: |
|
| 68 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + } catch (Exception $e) { |
|
| 72 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 73 | + spip_log($e->getMessage()); |
|
| 74 | + $iter = new EmptyIterator(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + // chercher la classe d'iterateur |
|
| 79 | + // IterateurXXX |
|
| 80 | + // definie dans le fichier iterateurs/xxx.php |
|
| 81 | + $class = 'Iterateur' . $iterateur; |
|
| 82 | + if (!class_exists($class)) { |
|
| 83 | + if ( |
|
| 84 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = []; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if ( |
|
| 205 | - is_object($this->iter) |
|
| 206 | - and method_exists($this->iter, $nom) |
|
| 207 | - ) { |
|
| 208 | - try { |
|
| 209 | - return $this->iter->$nom(); |
|
| 210 | - } catch (Exception $e) { |
|
| 211 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 212 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 213 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = []; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if ( |
|
| 205 | + is_object($this->iter) |
|
| 206 | + and method_exists($this->iter, $nom) |
|
| 207 | + ) { |
|
| 208 | + try { |
|
| 209 | + return $this->iter->$nom(); |
|
| 210 | + } catch (Exception $e) { |
|
| 211 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 212 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 213 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + /* |
|
| 219 | 219 | if (property_exists($this->iter, $nom)) { |
| 220 | 220 | return $this->iter->$nom; |
| 221 | 221 | }*/ |
| 222 | - // cle et valeur par defaut |
|
| 223 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 224 | - if ( |
|
| 225 | - in_array($nom, ['cle', 'valeur']) |
|
| 226 | - and method_exists($this, $nom) |
|
| 227 | - ) { |
|
| 228 | - return $this->$nom(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Par defaut chercher en xpath dans la valeur() |
|
| 232 | - return table_valeur($this->valeur(), $nom, null); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - private function calculer_filtres() { |
|
| 237 | - |
|
| 238 | - // Issu de calculer_select() de public/composer L.519 |
|
| 239 | - // TODO: externaliser... |
|
| 240 | - // |
|
| 241 | - // retirer les criteres vides: |
|
| 242 | - // {X ?} avec X absent de l'URL |
|
| 243 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 244 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 245 | - if ($where = &$this->command['where']) { |
|
| 246 | - foreach ($where as $k => $v) { |
|
| 247 | - if (is_array($v)) { |
|
| 248 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 249 | - $op = false; |
|
| 250 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 251 | - $op = false; |
|
| 252 | - } else { |
|
| 253 | - $op = $v[0] ? $v[0] : $v; |
|
| 254 | - } |
|
| 255 | - } else { |
|
| 256 | - $op = $v; |
|
| 257 | - } |
|
| 258 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 259 | - unset($where[$k]); |
|
| 260 | - } |
|
| 261 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 262 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 263 | - $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 264 | - unset($op, $where[$k]); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - foreach ($where as $k => $v) { |
|
| 268 | - // 3 possibilites : count($v) = |
|
| 269 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 270 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 271 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 272 | - |
|
| 273 | - // 1 : forcement traite par un critere, on passe |
|
| 274 | - if (!$v or count($v) == 1) { |
|
| 275 | - continue; |
|
| 276 | - } |
|
| 277 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 278 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 279 | - } |
|
| 280 | - if (count($v) == 3) { |
|
| 281 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // critere {2,7} |
|
| 287 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 288 | - $limit = explode(',', $this->command['limit']); |
|
| 289 | - $this->offset = $limit[0]; |
|
| 290 | - $this->limit = $limit[1]; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Creer la fonction de filtrage sur $this |
|
| 294 | - if ($this->filtre) { |
|
| 295 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 296 | - $this->func_filtre = function () use ($filtres) { |
|
| 297 | - return eval($filtres); |
|
| 298 | - }; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 304 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 305 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 306 | - return; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 310 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 311 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 312 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 313 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 314 | - |
|
| 315 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 316 | - # return; |
|
| 317 | - |
|
| 318 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 319 | - |
|
| 320 | - $filtre = ''; |
|
| 321 | - |
|
| 322 | - if ($op == 'REGEXP') { |
|
| 323 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 324 | - $op = ''; |
|
| 325 | - } else { |
|
| 326 | - if ($op == 'LIKE') { |
|
| 327 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 328 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 329 | - $op = ''; |
|
| 330 | - } else { |
|
| 331 | - if ($op == '=') { |
|
| 332 | - $op = '=='; |
|
| 333 | - } else { |
|
| 334 | - if ($op == 'IN') { |
|
| 335 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 336 | - $op = ''; |
|
| 337 | - } else { |
|
| 338 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 339 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 340 | - $op = ''; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - if ($op) { |
|
| 348 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - if ($not) { |
|
| 352 | - $filtre = "!($filtre)"; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ($filtre) { |
|
| 356 | - $this->filtre[] = $filtre; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - public function next() { |
|
| 362 | - $this->pos++; |
|
| 363 | - parent::next(); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * revient au depart |
|
| 368 | - * |
|
| 369 | - * @return void |
|
| 370 | - */ |
|
| 371 | - public function rewind() { |
|
| 372 | - $this->pos = 0; |
|
| 373 | - $this->fetched = 0; |
|
| 374 | - parent::rewind(); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - # Extension SPIP des iterateurs PHP |
|
| 379 | - /** |
|
| 380 | - * type de l'iterateur |
|
| 381 | - * |
|
| 382 | - * @var string |
|
| 383 | - */ |
|
| 384 | - protected $type; |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * parametres de l'iterateur |
|
| 388 | - * |
|
| 389 | - * @var array |
|
| 390 | - */ |
|
| 391 | - protected $command; |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * infos de compilateur |
|
| 395 | - * |
|
| 396 | - * @var array |
|
| 397 | - */ |
|
| 398 | - protected $info; |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * position courante de l'iterateur |
|
| 402 | - * |
|
| 403 | - * @var int |
|
| 404 | - */ |
|
| 405 | - protected $pos = null; |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * nombre total resultats dans l'iterateur |
|
| 409 | - * |
|
| 410 | - * @var int |
|
| 411 | - */ |
|
| 412 | - protected $total = null; |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * nombre maximal de recherche pour $total |
|
| 416 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 417 | - */ |
|
| 418 | - protected $max = 100000; |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Liste des champs a inserer dans les $row |
|
| 423 | - * retournes par ->fetch() |
|
| 424 | - */ |
|
| 425 | - protected $select = []; |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * aller a la position absolue n, |
|
| 430 | - * comptee depuis le debut |
|
| 431 | - * |
|
| 432 | - * @param int $n |
|
| 433 | - * absolute pos |
|
| 434 | - * @param string $continue |
|
| 435 | - * param for sql_ api |
|
| 436 | - * @return bool |
|
| 437 | - * success or fail if not implemented |
|
| 438 | - */ |
|
| 439 | - public function seek($n = 0, $continue = null) { |
|
| 440 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 441 | - $this->seek_loop($n); |
|
| 442 | - } |
|
| 443 | - $this->pos = $n; |
|
| 444 | - $this->fetched = $n; |
|
| 445 | - |
|
| 446 | - return true; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /* |
|
| 222 | + // cle et valeur par defaut |
|
| 223 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 224 | + if ( |
|
| 225 | + in_array($nom, ['cle', 'valeur']) |
|
| 226 | + and method_exists($this, $nom) |
|
| 227 | + ) { |
|
| 228 | + return $this->$nom(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Par defaut chercher en xpath dans la valeur() |
|
| 232 | + return table_valeur($this->valeur(), $nom, null); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + private function calculer_filtres() { |
|
| 237 | + |
|
| 238 | + // Issu de calculer_select() de public/composer L.519 |
|
| 239 | + // TODO: externaliser... |
|
| 240 | + // |
|
| 241 | + // retirer les criteres vides: |
|
| 242 | + // {X ?} avec X absent de l'URL |
|
| 243 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 244 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 245 | + if ($where = &$this->command['where']) { |
|
| 246 | + foreach ($where as $k => $v) { |
|
| 247 | + if (is_array($v)) { |
|
| 248 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 249 | + $op = false; |
|
| 250 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 251 | + $op = false; |
|
| 252 | + } else { |
|
| 253 | + $op = $v[0] ? $v[0] : $v; |
|
| 254 | + } |
|
| 255 | + } else { |
|
| 256 | + $op = $v; |
|
| 257 | + } |
|
| 258 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 259 | + unset($where[$k]); |
|
| 260 | + } |
|
| 261 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 262 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 263 | + $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 264 | + unset($op, $where[$k]); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + foreach ($where as $k => $v) { |
|
| 268 | + // 3 possibilites : count($v) = |
|
| 269 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 270 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 271 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 272 | + |
|
| 273 | + // 1 : forcement traite par un critere, on passe |
|
| 274 | + if (!$v or count($v) == 1) { |
|
| 275 | + continue; |
|
| 276 | + } |
|
| 277 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 278 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 279 | + } |
|
| 280 | + if (count($v) == 3) { |
|
| 281 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // critere {2,7} |
|
| 287 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 288 | + $limit = explode(',', $this->command['limit']); |
|
| 289 | + $this->offset = $limit[0]; |
|
| 290 | + $this->limit = $limit[1]; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Creer la fonction de filtrage sur $this |
|
| 294 | + if ($this->filtre) { |
|
| 295 | + $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 296 | + $this->func_filtre = function () use ($filtres) { |
|
| 297 | + return eval($filtres); |
|
| 298 | + }; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 304 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 305 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 306 | + return; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 310 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 311 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 312 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 313 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 314 | + |
|
| 315 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 316 | + # return; |
|
| 317 | + |
|
| 318 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 319 | + |
|
| 320 | + $filtre = ''; |
|
| 321 | + |
|
| 322 | + if ($op == 'REGEXP') { |
|
| 323 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 324 | + $op = ''; |
|
| 325 | + } else { |
|
| 326 | + if ($op == 'LIKE') { |
|
| 327 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 328 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 329 | + $op = ''; |
|
| 330 | + } else { |
|
| 331 | + if ($op == '=') { |
|
| 332 | + $op = '=='; |
|
| 333 | + } else { |
|
| 334 | + if ($op == 'IN') { |
|
| 335 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 336 | + $op = ''; |
|
| 337 | + } else { |
|
| 338 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 339 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 340 | + $op = ''; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + if ($op) { |
|
| 348 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + if ($not) { |
|
| 352 | + $filtre = "!($filtre)"; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ($filtre) { |
|
| 356 | + $this->filtre[] = $filtre; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + public function next() { |
|
| 362 | + $this->pos++; |
|
| 363 | + parent::next(); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * revient au depart |
|
| 368 | + * |
|
| 369 | + * @return void |
|
| 370 | + */ |
|
| 371 | + public function rewind() { |
|
| 372 | + $this->pos = 0; |
|
| 373 | + $this->fetched = 0; |
|
| 374 | + parent::rewind(); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + # Extension SPIP des iterateurs PHP |
|
| 379 | + /** |
|
| 380 | + * type de l'iterateur |
|
| 381 | + * |
|
| 382 | + * @var string |
|
| 383 | + */ |
|
| 384 | + protected $type; |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * parametres de l'iterateur |
|
| 388 | + * |
|
| 389 | + * @var array |
|
| 390 | + */ |
|
| 391 | + protected $command; |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * infos de compilateur |
|
| 395 | + * |
|
| 396 | + * @var array |
|
| 397 | + */ |
|
| 398 | + protected $info; |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * position courante de l'iterateur |
|
| 402 | + * |
|
| 403 | + * @var int |
|
| 404 | + */ |
|
| 405 | + protected $pos = null; |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * nombre total resultats dans l'iterateur |
|
| 409 | + * |
|
| 410 | + * @var int |
|
| 411 | + */ |
|
| 412 | + protected $total = null; |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * nombre maximal de recherche pour $total |
|
| 416 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 417 | + */ |
|
| 418 | + protected $max = 100000; |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Liste des champs a inserer dans les $row |
|
| 423 | + * retournes par ->fetch() |
|
| 424 | + */ |
|
| 425 | + protected $select = []; |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * aller a la position absolue n, |
|
| 430 | + * comptee depuis le debut |
|
| 431 | + * |
|
| 432 | + * @param int $n |
|
| 433 | + * absolute pos |
|
| 434 | + * @param string $continue |
|
| 435 | + * param for sql_ api |
|
| 436 | + * @return bool |
|
| 437 | + * success or fail if not implemented |
|
| 438 | + */ |
|
| 439 | + public function seek($n = 0, $continue = null) { |
|
| 440 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 441 | + $this->seek_loop($n); |
|
| 442 | + } |
|
| 443 | + $this->pos = $n; |
|
| 444 | + $this->fetched = $n; |
|
| 445 | + |
|
| 446 | + return true; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /* |
|
| 450 | 450 | * aller a la position $n en parcourant |
| 451 | 451 | * un par un tous les elements |
| 452 | 452 | */ |
| 453 | - private function seek_loop($n) { |
|
| 454 | - if ($this->pos > $n) { |
|
| 455 | - $this->rewind(); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - while ($this->pos < $n and $this->valid()) { |
|
| 459 | - $this->next(); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return true; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Avancer de $saut pas |
|
| 467 | - * |
|
| 468 | - * @param $saut |
|
| 469 | - * @param $max |
|
| 470 | - * @return int |
|
| 471 | - */ |
|
| 472 | - public function skip($saut, $max = null) { |
|
| 473 | - // pas de saut en arriere autorise pour cette fonction |
|
| 474 | - if (($saut = intval($saut)) <= 0) { |
|
| 475 | - return $this->pos; |
|
| 476 | - } |
|
| 477 | - $seek = $this->pos + $saut; |
|
| 478 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 479 | - // et on sort |
|
| 480 | - if (is_null($max)) { |
|
| 481 | - $max = $this->count(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 485 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 486 | - $this->free(); |
|
| 487 | - |
|
| 488 | - return $max; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $this->seek($seek); |
|
| 492 | - |
|
| 493 | - return $this->pos; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Renvoyer un tableau des donnees correspondantes |
|
| 498 | - * a la position courante de l'iterateur |
|
| 499 | - * en controlant si on respecte le filtre |
|
| 500 | - * Appliquer aussi le critere {offset,limit} |
|
| 501 | - * |
|
| 502 | - * @return array|bool |
|
| 503 | - */ |
|
| 504 | - public function fetch() { |
|
| 505 | - if (method_exists($this->iter, 'fetch')) { |
|
| 506 | - return $this->iter->fetch(); |
|
| 507 | - } else { |
|
| 508 | - while ( |
|
| 509 | - $this->valid() |
|
| 510 | - and ( |
|
| 511 | - !$this->accept() |
|
| 512 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 513 | - ) |
|
| 514 | - ) { |
|
| 515 | - $this->next(); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (!$this->valid()) { |
|
| 519 | - return false; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - if ( |
|
| 523 | - isset($this->limit) |
|
| 524 | - and $this->fetched > $this->offset + $this->limit |
|
| 525 | - ) { |
|
| 526 | - return false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $r = []; |
|
| 530 | - foreach ($this->select as $nom) { |
|
| 531 | - $r[$nom] = $this->get_select($nom); |
|
| 532 | - } |
|
| 533 | - $this->next(); |
|
| 534 | - |
|
| 535 | - return $r; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - // retourner la cle pour #CLE |
|
| 540 | - public function cle() { |
|
| 541 | - return $this->key(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // retourner la valeur pour #VALEUR |
|
| 545 | - public function valeur() { |
|
| 546 | - return $this->current(); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Accepte-t-on l'entree courante lue ? |
|
| 551 | - * On execute les filtres pour le savoir. |
|
| 552 | - **/ |
|
| 553 | - public function accept() { |
|
| 554 | - if ($f = $this->func_filtre) { |
|
| 555 | - return $f(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - return true; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * liberer la ressource |
|
| 563 | - * |
|
| 564 | - * @return bool |
|
| 565 | - */ |
|
| 566 | - public function free() { |
|
| 567 | - if (method_exists($this->iter, 'free')) { |
|
| 568 | - $this->iter->free(); |
|
| 569 | - } |
|
| 570 | - $this->pos = $this->total = 0; |
|
| 571 | - |
|
| 572 | - return true; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Compter le nombre total de resultats |
|
| 577 | - * pour #TOTAL_BOUCLE |
|
| 578 | - * |
|
| 579 | - * @return int |
|
| 580 | - */ |
|
| 581 | - public function count() { |
|
| 582 | - if (is_null($this->total)) { |
|
| 583 | - if ( |
|
| 584 | - method_exists($this->iter, 'count') |
|
| 585 | - and !$this->func_filtre |
|
| 586 | - ) { |
|
| 587 | - return $this->total = $this->iter->count(); |
|
| 588 | - } else { |
|
| 589 | - // compter les lignes et rembobiner |
|
| 590 | - $total = 0; |
|
| 591 | - $pos = $this->pos; // sauver la position |
|
| 592 | - $this->rewind(); |
|
| 593 | - while ($this->fetch() and $total < $this->max) { |
|
| 594 | - $total++; |
|
| 595 | - } |
|
| 596 | - $this->seek($pos); |
|
| 597 | - $this->total = $total; |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - return $this->total; |
|
| 602 | - } |
|
| 453 | + private function seek_loop($n) { |
|
| 454 | + if ($this->pos > $n) { |
|
| 455 | + $this->rewind(); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + while ($this->pos < $n and $this->valid()) { |
|
| 459 | + $this->next(); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return true; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Avancer de $saut pas |
|
| 467 | + * |
|
| 468 | + * @param $saut |
|
| 469 | + * @param $max |
|
| 470 | + * @return int |
|
| 471 | + */ |
|
| 472 | + public function skip($saut, $max = null) { |
|
| 473 | + // pas de saut en arriere autorise pour cette fonction |
|
| 474 | + if (($saut = intval($saut)) <= 0) { |
|
| 475 | + return $this->pos; |
|
| 476 | + } |
|
| 477 | + $seek = $this->pos + $saut; |
|
| 478 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 479 | + // et on sort |
|
| 480 | + if (is_null($max)) { |
|
| 481 | + $max = $this->count(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 485 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 486 | + $this->free(); |
|
| 487 | + |
|
| 488 | + return $max; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $this->seek($seek); |
|
| 492 | + |
|
| 493 | + return $this->pos; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Renvoyer un tableau des donnees correspondantes |
|
| 498 | + * a la position courante de l'iterateur |
|
| 499 | + * en controlant si on respecte le filtre |
|
| 500 | + * Appliquer aussi le critere {offset,limit} |
|
| 501 | + * |
|
| 502 | + * @return array|bool |
|
| 503 | + */ |
|
| 504 | + public function fetch() { |
|
| 505 | + if (method_exists($this->iter, 'fetch')) { |
|
| 506 | + return $this->iter->fetch(); |
|
| 507 | + } else { |
|
| 508 | + while ( |
|
| 509 | + $this->valid() |
|
| 510 | + and ( |
|
| 511 | + !$this->accept() |
|
| 512 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 513 | + ) |
|
| 514 | + ) { |
|
| 515 | + $this->next(); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (!$this->valid()) { |
|
| 519 | + return false; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + if ( |
|
| 523 | + isset($this->limit) |
|
| 524 | + and $this->fetched > $this->offset + $this->limit |
|
| 525 | + ) { |
|
| 526 | + return false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $r = []; |
|
| 530 | + foreach ($this->select as $nom) { |
|
| 531 | + $r[$nom] = $this->get_select($nom); |
|
| 532 | + } |
|
| 533 | + $this->next(); |
|
| 534 | + |
|
| 535 | + return $r; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + // retourner la cle pour #CLE |
|
| 540 | + public function cle() { |
|
| 541 | + return $this->key(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // retourner la valeur pour #VALEUR |
|
| 545 | + public function valeur() { |
|
| 546 | + return $this->current(); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Accepte-t-on l'entree courante lue ? |
|
| 551 | + * On execute les filtres pour le savoir. |
|
| 552 | + **/ |
|
| 553 | + public function accept() { |
|
| 554 | + if ($f = $this->func_filtre) { |
|
| 555 | + return $f(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + return true; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * liberer la ressource |
|
| 563 | + * |
|
| 564 | + * @return bool |
|
| 565 | + */ |
|
| 566 | + public function free() { |
|
| 567 | + if (method_exists($this->iter, 'free')) { |
|
| 568 | + $this->iter->free(); |
|
| 569 | + } |
|
| 570 | + $this->pos = $this->total = 0; |
|
| 571 | + |
|
| 572 | + return true; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Compter le nombre total de resultats |
|
| 577 | + * pour #TOTAL_BOUCLE |
|
| 578 | + * |
|
| 579 | + * @return int |
|
| 580 | + */ |
|
| 581 | + public function count() { |
|
| 582 | + if (is_null($this->total)) { |
|
| 583 | + if ( |
|
| 584 | + method_exists($this->iter, 'count') |
|
| 585 | + and !$this->func_filtre |
|
| 586 | + ) { |
|
| 587 | + return $this->total = $this->iter->count(); |
|
| 588 | + } else { |
|
| 589 | + // compter les lignes et rembobiner |
|
| 590 | + $total = 0; |
|
| 591 | + $pos = $this->pos; // sauver la position |
|
| 592 | + $this->rewind(); |
|
| 593 | + while ($this->fetch() and $total < $this->max) { |
|
| 594 | + $total++; |
|
| 595 | + } |
|
| 596 | + $this->seek($pos); |
|
| 597 | + $this->total = $total; |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + return $this->total; |
|
| 602 | + } |
|
| 603 | 603 | } |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | // chercher la classe d'iterateur |
| 79 | 79 | // IterateurXXX |
| 80 | 80 | // definie dans le fichier iterateurs/xxx.php |
| 81 | - $class = 'Iterateur' . $iterateur; |
|
| 81 | + $class = 'Iterateur'.$iterateur; |
|
| 82 | 82 | if (!class_exists($class)) { |
| 83 | 83 | if ( |
| 84 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 84 | + !include_spip('iterateur/'.strtolower($iterateur)) |
|
| 85 | 85 | or !class_exists($class) |
| 86 | 86 | ) { |
| 87 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | return $this->iter->$nom(); |
| 210 | 210 | } catch (Exception $e) { |
| 211 | 211 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 212 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 213 | 213 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 214 | 214 | |
| 215 | 215 | return ''; |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | // Creer la fonction de filtrage sur $this |
| 294 | 294 | if ($this->filtre) { |
| 295 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 296 | - $this->func_filtre = function () use ($filtres) { |
|
| 295 | + $filtres = 'return ('.join(') AND (', $this->filtre).');'; |
|
| 296 | + $this->func_filtre = function() use ($filtres) { |
|
| 297 | 297 | return eval($filtres); |
| 298 | 298 | }; |
| 299 | 299 | } |
@@ -315,28 +315,28 @@ discard block |
||
| 315 | 315 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 316 | 316 | # return; |
| 317 | 317 | |
| 318 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 318 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 319 | 319 | |
| 320 | 320 | $filtre = ''; |
| 321 | 321 | |
| 322 | 322 | if ($op == 'REGEXP') { |
| 323 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 323 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 324 | 324 | $op = ''; |
| 325 | 325 | } else { |
| 326 | 326 | if ($op == 'LIKE') { |
| 327 | 327 | $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
| 328 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 328 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 329 | 329 | $op = ''; |
| 330 | 330 | } else { |
| 331 | 331 | if ($op == '=') { |
| 332 | 332 | $op = '=='; |
| 333 | 333 | } else { |
| 334 | 334 | if ($op == 'IN') { |
| 335 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 335 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 336 | 336 | $op = ''; |
| 337 | 337 | } else { |
| 338 | 338 | if (!in_array($op, ['<', '<=', '>', '>='])) { |
| 339 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 339 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 340 | 340 | $op = ''; |
| 341 | 341 | } |
| 342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | if ($op) { |
| 348 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 348 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | if ($not) { |
@@ -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 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if ( |
|
| 60 | - !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | - or array_key_exists($champ, $desc['field']) |
|
| 62 | - ) { |
|
| 63 | - return [$champ]; |
|
| 64 | - } |
|
| 65 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | - array_pop($decompose); |
|
| 68 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | - return $decompose; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return [$champ]; |
|
| 59 | + if ( |
|
| 60 | + !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | + or array_key_exists($champ, $desc['field']) |
|
| 62 | + ) { |
|
| 63 | + return [$champ]; |
|
| 64 | + } |
|
| 65 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | + array_pop($decompose); |
|
| 68 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | + return $decompose; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return [$champ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
@@ -100,23 +100,23 @@ discard block |
||
| 100 | 100 | * Alias de la table de jointure (Lx) |
| 101 | 101 | */ |
| 102 | 102 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 103 | - // les jointures minimales sont optimales : |
|
| 104 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | - $max = 1; |
|
| 107 | - $res = false; |
|
| 108 | - $milieu_exclus = ($col ? $col : []); |
|
| 109 | - while ($max <= $max_liens and !$res) { |
|
| 110 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | - $max++; |
|
| 112 | - } |
|
| 113 | - if (!$res) { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - list($nom, $desc) = $depart; |
|
| 118 | - |
|
| 119 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 103 | + // les jointures minimales sont optimales : |
|
| 104 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | + $max = 1; |
|
| 107 | + $res = false; |
|
| 108 | + $milieu_exclus = ($col ? $col : []); |
|
| 109 | + while ($max <= $max_liens and !$res) { |
|
| 110 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | + $max++; |
|
| 112 | + } |
|
| 113 | + if (!$res) { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + list($nom, $desc) = $depart; |
|
| 118 | + |
|
| 119 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -155,79 +155,79 @@ discard block |
||
| 155 | 155 | * Alias de la table de jointure (Lx) |
| 156 | 156 | */ |
| 157 | 157 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 158 | - static $num = []; |
|
| 159 | - $id_table = ''; |
|
| 160 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 161 | - foreach ($res as $cle => $r) { |
|
| 162 | - list($d, $a, $j) = $r; |
|
| 163 | - if (!$id_table) { |
|
| 164 | - $id_table = $d; |
|
| 165 | - } |
|
| 166 | - $n = ++$cpt; |
|
| 167 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 168 | - list($j1, $j2, $obj, $type) = $j; |
|
| 169 | - // trouver de quel cote est (id_objet,objet) |
|
| 170 | - if ($j1 == "id_$obj") { |
|
| 171 | - $obj = "$id_table.$obj"; |
|
| 172 | - } else { |
|
| 173 | - $obj = "L$n.$obj"; |
|
| 174 | - } |
|
| 175 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | - $boucle->where["JOIN-L$n"] = |
|
| 179 | - $echap ? |
|
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | - : |
|
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 183 | - $boucle->join["L$n"] = |
|
| 184 | - $echap ? |
|
| 185 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | - : |
|
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | - } else { |
|
| 189 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | - } |
|
| 191 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - // pas besoin de group by |
|
| 196 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | - // si une seule jointure et sur une table avec primary key formee |
|
| 198 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | - |
|
| 201 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // pas de group by |
|
| 206 | - // si une seule jointure |
|
| 207 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | - if ( |
|
| 209 | - !$pk |
|
| 210 | - and (count($boucle->from) == 2) |
|
| 211 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 213 | - ) { |
|
| 214 | - $pk = true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | - if (!$pk) { |
|
| 220 | - foreach ($groups as $id_prim) { |
|
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 222 | - if (!in_array($id_field, $boucle->group)) { |
|
| 223 | - $boucle->group[] = $id_field; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $boucle->modificateur['lien'] = true; |
|
| 229 | - |
|
| 230 | - return "L$n"; |
|
| 158 | + static $num = []; |
|
| 159 | + $id_table = ''; |
|
| 160 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 161 | + foreach ($res as $cle => $r) { |
|
| 162 | + list($d, $a, $j) = $r; |
|
| 163 | + if (!$id_table) { |
|
| 164 | + $id_table = $d; |
|
| 165 | + } |
|
| 166 | + $n = ++$cpt; |
|
| 167 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 168 | + list($j1, $j2, $obj, $type) = $j; |
|
| 169 | + // trouver de quel cote est (id_objet,objet) |
|
| 170 | + if ($j1 == "id_$obj") { |
|
| 171 | + $obj = "$id_table.$obj"; |
|
| 172 | + } else { |
|
| 173 | + $obj = "L$n.$obj"; |
|
| 174 | + } |
|
| 175 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | + $boucle->where["JOIN-L$n"] = |
|
| 179 | + $echap ? |
|
| 180 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | + : |
|
| 182 | + ['=',"$obj",sql_quote($type)]; |
|
| 183 | + $boucle->join["L$n"] = |
|
| 184 | + $echap ? |
|
| 185 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | + : |
|
| 187 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | + } else { |
|
| 189 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | + } |
|
| 191 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + // pas besoin de group by |
|
| 196 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | + // si une seule jointure et sur une table avec primary key formee |
|
| 198 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | + |
|
| 201 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // pas de group by |
|
| 206 | + // si une seule jointure |
|
| 207 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | + if ( |
|
| 209 | + !$pk |
|
| 210 | + and (count($boucle->from) == 2) |
|
| 211 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 213 | + ) { |
|
| 214 | + $pk = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | + if (!$pk) { |
|
| 220 | + foreach ($groups as $id_prim) { |
|
| 221 | + $id_field = $nom . '.' . $id_prim; |
|
| 222 | + if (!in_array($id_field, $boucle->group)) { |
|
| 223 | + $boucle->group[] = $id_field; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $boucle->modificateur['lien'] = true; |
|
| 229 | + |
|
| 230 | + return "L$n"; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,16 +242,16 @@ discard block |
||
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | 244 | function nogroupby_if($depart, $arrivee, $col) { |
| 245 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 246 | - if (!$pk) { |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 250 | - if (is_array($col)) { |
|
| 251 | - $col = implode(', *', $col); |
|
| 252 | - } // cas id_objet, objet |
|
| 253 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 254 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 245 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 246 | + if (!$pk) { |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 250 | + if (is_array($col)) { |
|
| 251 | + $col = implode(', *', $col); |
|
| 252 | + } // cas id_objet, objet |
|
| 253 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 254 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -269,46 +269,46 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 271 | 271 | |
| 272 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 272 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 273 | 273 | |
| 274 | - // si cle primaire demandee, la privilegier |
|
| 275 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 276 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 277 | - } |
|
| 274 | + // si cle primaire demandee, la privilegier |
|
| 275 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 276 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // les champs declares explicitement pour les jointures |
|
| 280 | - if (isset($desc['join'])) { |
|
| 281 | - return $desc['join']; |
|
| 282 | - } |
|
| 283 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 279 | + // les champs declares explicitement pour les jointures |
|
| 280 | + if (isset($desc['join'])) { |
|
| 281 | + return $desc['join']; |
|
| 282 | + } |
|
| 283 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 284 | 284 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 285 | 285 | |
| 286 | - // si pas de cle, c'est fichu |
|
| 287 | - if (!isset($desc['key'])) { |
|
| 288 | - return []; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // si cle primaire |
|
| 292 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 293 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // ici on se rabat sur les cles secondaires, |
|
| 297 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 298 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 299 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 300 | - |
|
| 301 | - $join = []; |
|
| 302 | - foreach ($desc['key'] as $v) { |
|
| 303 | - $join = split_key($v, $join); |
|
| 304 | - } |
|
| 305 | - foreach ($join as $k) { |
|
| 306 | - if (in_array($k, $nojoin)) { |
|
| 307 | - unset($join[$k]); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return $join; |
|
| 286 | + // si pas de cle, c'est fichu |
|
| 287 | + if (!isset($desc['key'])) { |
|
| 288 | + return []; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // si cle primaire |
|
| 292 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 293 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // ici on se rabat sur les cles secondaires, |
|
| 297 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 298 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 299 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 300 | + |
|
| 301 | + $join = []; |
|
| 302 | + foreach ($desc['key'] as $v) { |
|
| 303 | + $join = split_key($v, $join); |
|
| 304 | + } |
|
| 305 | + foreach ($join as $k) { |
|
| 306 | + if (in_array($k, $nojoin)) { |
|
| 307 | + unset($join[$k]); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return $join; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -319,14 +319,14 @@ discard block |
||
| 319 | 319 | * @return array |
| 320 | 320 | */ |
| 321 | 321 | function split_key($v, $join = []) { |
| 322 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 323 | - if (strpos($k, '(') !== false) { |
|
| 324 | - $k = explode('(', $k); |
|
| 325 | - $k = trim(reset($k)); |
|
| 326 | - } |
|
| 327 | - $join[$k] = $k; |
|
| 328 | - } |
|
| 329 | - return $join; |
|
| 322 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 323 | + if (strpos($k, '(') !== false) { |
|
| 324 | + $k = explode('(', $k); |
|
| 325 | + $k = trim(reset($k)); |
|
| 326 | + } |
|
| 327 | + $join[$k] = $k; |
|
| 328 | + } |
|
| 329 | + return $join; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -349,135 +349,135 @@ discard block |
||
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | 351 | function calculer_chaine_jointures( |
| 352 | - &$boucle, |
|
| 353 | - $depart, |
|
| 354 | - $arrivee, |
|
| 355 | - $vu = [], |
|
| 356 | - $milieu_exclus = [], |
|
| 357 | - $max_liens = 5 |
|
| 352 | + &$boucle, |
|
| 353 | + $depart, |
|
| 354 | + $arrivee, |
|
| 355 | + $vu = [], |
|
| 356 | + $milieu_exclus = [], |
|
| 357 | + $max_liens = 5 |
|
| 358 | 358 | ) { |
| 359 | - static $trouver_table; |
|
| 360 | - if (!$trouver_table) { |
|
| 361 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (is_string($milieu_exclus)) { |
|
| 365 | - $milieu_exclus = [$milieu_exclus]; |
|
| 366 | - } |
|
| 367 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 368 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 369 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 370 | - $milieu_exclus[] = 'objet'; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - list($dnom, $ddesc) = $depart; |
|
| 374 | - list($anom, $adesc) = $arrivee; |
|
| 375 | - if (!count($vu)) { |
|
| 376 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 377 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - $akeys = []; |
|
| 381 | - foreach ($adesc['key'] as $k) { |
|
| 382 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 383 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 387 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 388 | - |
|
| 389 | - // cles candidates au depart |
|
| 390 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 391 | - // enlever les cles dde depart exclues par l'appel |
|
| 392 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 393 | - |
|
| 394 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 395 | - |
|
| 396 | - if ($v) { |
|
| 397 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 401 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 402 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 403 | - // id_objet,objet |
|
| 404 | - // si oui on la prend |
|
| 405 | - foreach ($akeys as $key) { |
|
| 406 | - $v = decompose_champ_id_objet($key); |
|
| 407 | - if (is_array($v)) { |
|
| 408 | - $objet = array_shift($v); // objet,'article' |
|
| 409 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 410 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 411 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 416 | - // id_objet,objet a l'arrivee |
|
| 417 | - // si oui on la prend |
|
| 418 | - foreach ($keys as $key) { |
|
| 419 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 420 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 421 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 422 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 423 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 429 | - if ($max_liens <= 1) { |
|
| 430 | - return []; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // sinon essayer de passer par une autre table |
|
| 434 | - $new = $vu; |
|
| 435 | - foreach ($boucle->jointures as $v) { |
|
| 436 | - if ( |
|
| 437 | - $v |
|
| 438 | - and !in_array($v, $vu) |
|
| 439 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 440 | - and !in_array($def['table_sql'], $vu) |
|
| 441 | - ) { |
|
| 442 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 443 | - // ie la cle de la jointure precedente |
|
| 444 | - $test_cles = $milieu_exclus; |
|
| 445 | - $new[] = $v; |
|
| 446 | - $max_iter = 50; // securite |
|
| 447 | - while ( |
|
| 448 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 449 | - $boucle, |
|
| 450 | - $depart, |
|
| 451 | - [$v, $def], |
|
| 452 | - $vu, |
|
| 453 | - $test_cles, |
|
| 454 | - 1 |
|
| 455 | - )) |
|
| 456 | - and $max_iter-- |
|
| 457 | - ) { |
|
| 458 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 459 | - $milieu = end($jointure_directe_possible); |
|
| 460 | - $exclure_fin = $milieu_exclus; |
|
| 461 | - if (is_string($milieu)) { |
|
| 462 | - $exclure_fin[] = $milieu; |
|
| 463 | - $test_cles[] = $milieu; |
|
| 464 | - } else { |
|
| 465 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 466 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 467 | - } |
|
| 468 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 469 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 470 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 471 | - if ($r) { |
|
| 472 | - array_unshift($r, $jointure_directe_possible); |
|
| 473 | - |
|
| 474 | - return $r; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - return []; |
|
| 359 | + static $trouver_table; |
|
| 360 | + if (!$trouver_table) { |
|
| 361 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (is_string($milieu_exclus)) { |
|
| 365 | + $milieu_exclus = [$milieu_exclus]; |
|
| 366 | + } |
|
| 367 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 368 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 369 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 370 | + $milieu_exclus[] = 'objet'; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + list($dnom, $ddesc) = $depart; |
|
| 374 | + list($anom, $adesc) = $arrivee; |
|
| 375 | + if (!count($vu)) { |
|
| 376 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 377 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + $akeys = []; |
|
| 381 | + foreach ($adesc['key'] as $k) { |
|
| 382 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 383 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 387 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 388 | + |
|
| 389 | + // cles candidates au depart |
|
| 390 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 391 | + // enlever les cles dde depart exclues par l'appel |
|
| 392 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 393 | + |
|
| 394 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 395 | + |
|
| 396 | + if ($v) { |
|
| 397 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 401 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 402 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 403 | + // id_objet,objet |
|
| 404 | + // si oui on la prend |
|
| 405 | + foreach ($akeys as $key) { |
|
| 406 | + $v = decompose_champ_id_objet($key); |
|
| 407 | + if (is_array($v)) { |
|
| 408 | + $objet = array_shift($v); // objet,'article' |
|
| 409 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 410 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 411 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 416 | + // id_objet,objet a l'arrivee |
|
| 417 | + // si oui on la prend |
|
| 418 | + foreach ($keys as $key) { |
|
| 419 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 420 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 421 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 422 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 423 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 429 | + if ($max_liens <= 1) { |
|
| 430 | + return []; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // sinon essayer de passer par une autre table |
|
| 434 | + $new = $vu; |
|
| 435 | + foreach ($boucle->jointures as $v) { |
|
| 436 | + if ( |
|
| 437 | + $v |
|
| 438 | + and !in_array($v, $vu) |
|
| 439 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 440 | + and !in_array($def['table_sql'], $vu) |
|
| 441 | + ) { |
|
| 442 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 443 | + // ie la cle de la jointure precedente |
|
| 444 | + $test_cles = $milieu_exclus; |
|
| 445 | + $new[] = $v; |
|
| 446 | + $max_iter = 50; // securite |
|
| 447 | + while ( |
|
| 448 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 449 | + $boucle, |
|
| 450 | + $depart, |
|
| 451 | + [$v, $def], |
|
| 452 | + $vu, |
|
| 453 | + $test_cles, |
|
| 454 | + 1 |
|
| 455 | + )) |
|
| 456 | + and $max_iter-- |
|
| 457 | + ) { |
|
| 458 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 459 | + $milieu = end($jointure_directe_possible); |
|
| 460 | + $exclure_fin = $milieu_exclus; |
|
| 461 | + if (is_string($milieu)) { |
|
| 462 | + $exclure_fin[] = $milieu; |
|
| 463 | + $test_cles[] = $milieu; |
|
| 464 | + } else { |
|
| 465 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 466 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 467 | + } |
|
| 468 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 469 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 470 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 471 | + if ($r) { |
|
| 472 | + array_unshift($r, $jointure_directe_possible); |
|
| 473 | + |
|
| 474 | + return $r; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + return []; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -488,18 +488,18 @@ discard block |
||
| 488 | 488 | * @return array |
| 489 | 489 | */ |
| 490 | 490 | function trouver_cles_table($keys) { |
| 491 | - $res = []; |
|
| 492 | - foreach ($keys as $v) { |
|
| 493 | - if (!strpos($v, ',')) { |
|
| 494 | - $res[$v] = 1; |
|
| 495 | - } else { |
|
| 496 | - foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 497 | - $res[$k] = 1; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return array_keys($res); |
|
| 491 | + $res = []; |
|
| 492 | + foreach ($keys as $v) { |
|
| 493 | + if (!strpos($v, ',')) { |
|
| 494 | + $res[$v] = 1; |
|
| 495 | + } else { |
|
| 496 | + foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 497 | + $res[$k] = 1; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return array_keys($res); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | |
@@ -526,34 +526,34 @@ discard block |
||
| 526 | 526 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 527 | 527 | */ |
| 528 | 528 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 529 | - static $trouver_table = ''; |
|
| 530 | - if (!$trouver_table) { |
|
| 531 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - if (!is_array($cle)) { |
|
| 535 | - $cle = [$cle]; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - foreach ($tables as $k => $table) { |
|
| 539 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 540 | - if ( |
|
| 541 | - isset($desc['field']) |
|
| 542 | - // verifier que toutes les cles cherchees sont la |
|
| 543 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 544 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 545 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 546 | - ) { |
|
| 547 | - return [ |
|
| 548 | - 'desc' => $desc, |
|
| 549 | - 'table' => $desc['table'], |
|
| 550 | - 'alias' => $k, |
|
| 551 | - ]; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - return false; |
|
| 529 | + static $trouver_table = ''; |
|
| 530 | + if (!$trouver_table) { |
|
| 531 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + if (!is_array($cle)) { |
|
| 535 | + $cle = [$cle]; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + foreach ($tables as $k => $table) { |
|
| 539 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 540 | + if ( |
|
| 541 | + isset($desc['field']) |
|
| 542 | + // verifier que toutes les cles cherchees sont la |
|
| 543 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 544 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 545 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 546 | + ) { |
|
| 547 | + return [ |
|
| 548 | + 'desc' => $desc, |
|
| 549 | + 'table' => $desc['table'], |
|
| 550 | + 'alias' => $k, |
|
| 551 | + ]; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + return false; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -579,52 +579,52 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 581 | 581 | |
| 582 | - // support de la recherche multi champ : |
|
| 583 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 584 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 585 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 586 | - if (!is_array($cle)) { |
|
| 587 | - $cle = [$cle]; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 591 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - // au premier coup, on essaye de decomposer, si possible |
|
| 595 | - if ( |
|
| 596 | - count($cle) == 1 |
|
| 597 | - and $c = reset($cle) |
|
| 598 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 599 | - ) { |
|
| 600 | - $desc = $boucle->show; |
|
| 601 | - |
|
| 602 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 603 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 604 | - if (isset($desc['field'][$c])) { |
|
| 605 | - $cle = []; |
|
| 606 | - $cle[] = array_shift($decompose); // id_objet |
|
| 607 | - $cle[] = array_shift($decompose); // objet |
|
| 608 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 609 | - } |
|
| 610 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 611 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 612 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 613 | - else { |
|
| 614 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 615 | - foreach ($depart as $d) { |
|
| 616 | - $cle = []; |
|
| 617 | - $cle[] = array_shift($decompose); // id_objet |
|
| 618 | - $cle[] = array_shift($decompose); // objet |
|
| 619 | - $cle[] = $d; |
|
| 620 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 621 | - return $ext; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - return ''; |
|
| 582 | + // support de la recherche multi champ : |
|
| 583 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 584 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 585 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 586 | + if (!is_array($cle)) { |
|
| 587 | + $cle = [$cle]; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 591 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + // au premier coup, on essaye de decomposer, si possible |
|
| 595 | + if ( |
|
| 596 | + count($cle) == 1 |
|
| 597 | + and $c = reset($cle) |
|
| 598 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 599 | + ) { |
|
| 600 | + $desc = $boucle->show; |
|
| 601 | + |
|
| 602 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 603 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 604 | + if (isset($desc['field'][$c])) { |
|
| 605 | + $cle = []; |
|
| 606 | + $cle[] = array_shift($decompose); // id_objet |
|
| 607 | + $cle[] = array_shift($decompose); // objet |
|
| 608 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 609 | + } |
|
| 610 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 611 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 612 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 613 | + else { |
|
| 614 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 615 | + foreach ($depart as $d) { |
|
| 616 | + $cle = []; |
|
| 617 | + $cle[] = array_shift($decompose); // id_objet |
|
| 618 | + $cle[] = array_shift($decompose); // objet |
|
| 619 | + $cle[] = $d; |
|
| 620 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 621 | + return $ext; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + return ''; |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -656,21 +656,21 @@ discard block |
||
| 656 | 656 | * @return string |
| 657 | 657 | */ |
| 658 | 658 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 659 | - if ($jointures === false) { |
|
| 660 | - $jointures = $boucle->jointures; |
|
| 661 | - } |
|
| 662 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 663 | - // mais pas poour construire la jointure ensuite |
|
| 664 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 665 | - if ($arrivee) { |
|
| 666 | - $desc = $boucle->show; |
|
| 667 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 668 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 669 | - if ($cle) { |
|
| 670 | - return $cle; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 674 | - |
|
| 675 | - return ''; |
|
| 659 | + if ($jointures === false) { |
|
| 660 | + $jointures = $boucle->jointures; |
|
| 661 | + } |
|
| 662 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 663 | + // mais pas poour construire la jointure ensuite |
|
| 664 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 665 | + if ($arrivee) { |
|
| 666 | + $desc = $boucle->show; |
|
| 667 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 668 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 669 | + if ($cle) { |
|
| 670 | + return $cle; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 674 | + |
|
| 675 | + return ''; |
|
| 676 | 676 | } |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | // sache qu'il peut enlever ce where si il enleve la jointure |
| 178 | 178 | $boucle->where["JOIN-L$n"] = |
| 179 | 179 | $echap ? |
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 180 | + ["'='", "'$obj'", "sql_quote('$type')"] |
|
| 181 | 181 | : |
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 182 | + ['=', "$obj", sql_quote($type)]; |
|
| 183 | 183 | $boucle->join["L$n"] = |
| 184 | 184 | $echap ? |
| 185 | 185 | ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
| 186 | 186 | : |
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 187 | + [$id_table, $j2, $j1, "$obj=".sql_quote($type)]; |
|
| 188 | 188 | } else { |
| 189 | 189 | $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
| 190 | 190 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $groups = liste_champs_jointures($nom, $desc, true); |
| 219 | 219 | if (!$pk) { |
| 220 | 220 | foreach ($groups as $id_prim) { |
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 221 | + $id_field = $nom.'.'.$id_prim; |
|
| 222 | 222 | if (!in_array($id_field, $boucle->group)) { |
| 223 | 223 | $boucle->group[] = $id_field; |
| 224 | 224 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | ) { |
| 29 | 29 | // si l'url est une url du site, on la laisse passer sans rien faire |
| 30 | 30 | // c'est encore le plus simple |
| 31 | - $base = $GLOBALS['meta']['adresse_site'] . '/'; |
|
| 31 | + $base = $GLOBALS['meta']['adresse_site'].'/'; |
|
| 32 | 32 | if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
| 33 | 33 | return $redirect; |
| 34 | 34 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | if ($ancre = _request('var_ajax_ancre')) { |
| 157 | 157 | // pas n'importe quoi quand meme dans la variable ! |
| 158 | 158 | $ancre = str_replace(['<', '"', "'"], ['<', '"', ''], $ancre); |
| 159 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 159 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>".$texte; |
|
| 160 | 160 | } |
| 161 | 161 | } else { |
| 162 | 162 | include_spip('inc/headers'); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
| 315 | 315 | // sans cela le formulaire n'est pas actif apres le hit ajax |
| 316 | 316 | // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
| 317 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 317 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>".$retour; |
|
| 318 | 318 | ajax_retour($retour, false); |
| 319 | 319 | |
| 320 | 320 | return true; // on a fini le hit |
@@ -11,164 +11,164 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect |
|
| 19 | - if (strpos($redirect, '%') !== false) { |
|
| 20 | - $r2 = urldecode($redirect); |
|
| 21 | - if (($r3 = securiser_redirect_action($r2)) !== $r2) { |
|
| 22 | - return $r3; |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - if ( |
|
| 26 | - (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 27 | - and !defined('_AUTORISER_ACTION_ABS_REDIRECT') |
|
| 28 | - ) { |
|
| 29 | - // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 30 | - // c'est encore le plus simple |
|
| 31 | - $base = $GLOBALS['meta']['adresse_site'] . '/'; |
|
| 32 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 33 | - return $redirect; |
|
| 34 | - } |
|
| 35 | - $base = url_de_base(); |
|
| 36 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 37 | - return $redirect; |
|
| 38 | - } |
|
| 18 | + // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect |
|
| 19 | + if (strpos($redirect, '%') !== false) { |
|
| 20 | + $r2 = urldecode($redirect); |
|
| 21 | + if (($r3 = securiser_redirect_action($r2)) !== $r2) { |
|
| 22 | + return $r3; |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + if ( |
|
| 26 | + (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 27 | + and !defined('_AUTORISER_ACTION_ABS_REDIRECT') |
|
| 28 | + ) { |
|
| 29 | + // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 30 | + // c'est encore le plus simple |
|
| 31 | + $base = $GLOBALS['meta']['adresse_site'] . '/'; |
|
| 32 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 33 | + return $redirect; |
|
| 34 | + } |
|
| 35 | + $base = url_de_base(); |
|
| 36 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 37 | + return $redirect; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return ''; |
|
| 41 | - } |
|
| 40 | + return ''; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $redirect; |
|
| 43 | + return $redirect; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // https://code.spip.net/@traiter_appels_actions |
| 47 | 47 | function traiter_appels_actions() { |
| 48 | - // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 49 | - if ($action = _request('action')) { |
|
| 50 | - include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 51 | - include_spip('inc/autoriser'); |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - include_spip('inc/actions'); |
|
| 54 | - // des actions peuvent appeler _T |
|
| 55 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 56 | - include_spip('inc/lang'); |
|
| 57 | - utiliser_langue_visiteur(); |
|
| 58 | - } |
|
| 59 | - // si l'action est provoque par un hit {ajax} |
|
| 60 | - // il faut transmettre l'env ajax au redirect |
|
| 61 | - // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 62 | - if ( |
|
| 63 | - ($v = _request('var_ajax')) |
|
| 64 | - and ($v !== 'form') |
|
| 65 | - and ($args = _request('var_ajax_env')) |
|
| 66 | - and ($url = _request('redirect')) |
|
| 67 | - ) { |
|
| 68 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 69 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 70 | - set_request('redirect', $url); |
|
| 71 | - } else { |
|
| 72 | - if (_request('redirect')) { |
|
| 73 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $var_f = charger_fonction($action, 'action'); |
|
| 77 | - $var_f(); |
|
| 78 | - if (!isset($GLOBALS['redirect'])) { |
|
| 79 | - $GLOBALS['redirect'] = _request('redirect'); |
|
| 80 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 81 | - $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 82 | - } |
|
| 83 | - $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 84 | - } |
|
| 85 | - if ($url = $GLOBALS['redirect']) { |
|
| 86 | - // si l'action est provoque par un hit {ajax} |
|
| 87 | - // il faut transmettre l'env ajax au redirect |
|
| 88 | - // qui a pu etre defini par l'action |
|
| 89 | - if ( |
|
| 90 | - ($v = _request('var_ajax')) |
|
| 91 | - and ($v !== 'form') |
|
| 92 | - and ($args = _request('var_ajax_env')) |
|
| 93 | - ) { |
|
| 94 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 95 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 96 | - // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 97 | - $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 98 | - } |
|
| 99 | - $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 100 | - redirige_par_entete($url); |
|
| 101 | - } |
|
| 48 | + // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 49 | + if ($action = _request('action')) { |
|
| 50 | + include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 51 | + include_spip('inc/autoriser'); |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + include_spip('inc/actions'); |
|
| 54 | + // des actions peuvent appeler _T |
|
| 55 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 56 | + include_spip('inc/lang'); |
|
| 57 | + utiliser_langue_visiteur(); |
|
| 58 | + } |
|
| 59 | + // si l'action est provoque par un hit {ajax} |
|
| 60 | + // il faut transmettre l'env ajax au redirect |
|
| 61 | + // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 62 | + if ( |
|
| 63 | + ($v = _request('var_ajax')) |
|
| 64 | + and ($v !== 'form') |
|
| 65 | + and ($args = _request('var_ajax_env')) |
|
| 66 | + and ($url = _request('redirect')) |
|
| 67 | + ) { |
|
| 68 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 69 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 70 | + set_request('redirect', $url); |
|
| 71 | + } else { |
|
| 72 | + if (_request('redirect')) { |
|
| 73 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $var_f = charger_fonction($action, 'action'); |
|
| 77 | + $var_f(); |
|
| 78 | + if (!isset($GLOBALS['redirect'])) { |
|
| 79 | + $GLOBALS['redirect'] = _request('redirect'); |
|
| 80 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 81 | + $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 82 | + } |
|
| 83 | + $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 84 | + } |
|
| 85 | + if ($url = $GLOBALS['redirect']) { |
|
| 86 | + // si l'action est provoque par un hit {ajax} |
|
| 87 | + // il faut transmettre l'env ajax au redirect |
|
| 88 | + // qui a pu etre defini par l'action |
|
| 89 | + if ( |
|
| 90 | + ($v = _request('var_ajax')) |
|
| 91 | + and ($v !== 'form') |
|
| 92 | + and ($args = _request('var_ajax_env')) |
|
| 93 | + ) { |
|
| 94 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 95 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 96 | + // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 97 | + $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 98 | + } |
|
| 99 | + $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 100 | + redirige_par_entete($url); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0 |
|
| 104 | - // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment) |
|
| 105 | - if ( |
|
| 106 | - !headers_sent() |
|
| 107 | - and !ob_get_length() |
|
| 108 | - ) { |
|
| 109 | - http_status(204); |
|
| 110 | - } // No Content |
|
| 111 | - return true; |
|
| 112 | - } |
|
| 103 | + // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0 |
|
| 104 | + // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment) |
|
| 105 | + if ( |
|
| 106 | + !headers_sent() |
|
| 107 | + and !ob_get_length() |
|
| 108 | + ) { |
|
| 109 | + http_status(204); |
|
| 110 | + } // No Content |
|
| 111 | + return true; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // https://code.spip.net/@refuser_traiter_formulaire_ajax |
| 119 | 119 | function refuser_traiter_formulaire_ajax() { |
| 120 | - if ( |
|
| 121 | - $v = _request('var_ajax') |
|
| 122 | - and $v == 'form' |
|
| 123 | - and $form = _request('formulaire_action') |
|
| 124 | - and $args = _request('formulaire_action_args') |
|
| 125 | - and decoder_contexte_ajax($args, $form) !== false |
|
| 126 | - ) { |
|
| 127 | - // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 128 | - // mais traiter ne veut pas |
|
| 129 | - // on le dit a la page qui va resumbit |
|
| 130 | - // sans ajax |
|
| 131 | - include_spip('inc/actions'); |
|
| 132 | - ajax_retour('noajax', false); |
|
| 133 | - exit; |
|
| 134 | - } |
|
| 120 | + if ( |
|
| 121 | + $v = _request('var_ajax') |
|
| 122 | + and $v == 'form' |
|
| 123 | + and $form = _request('formulaire_action') |
|
| 124 | + and $args = _request('formulaire_action_args') |
|
| 125 | + and decoder_contexte_ajax($args, $form) !== false |
|
| 126 | + ) { |
|
| 127 | + // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 128 | + // mais traiter ne veut pas |
|
| 129 | + // on le dit a la page qui va resumbit |
|
| 130 | + // sans ajax |
|
| 131 | + include_spip('inc/actions'); |
|
| 132 | + ajax_retour('noajax', false); |
|
| 133 | + exit; |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // https://code.spip.net/@traiter_appels_inclusions_ajax |
| 138 | 138 | function traiter_appels_inclusions_ajax() { |
| 139 | - // traiter les appels de bloc ajax (ex: pagination) |
|
| 140 | - if ( |
|
| 141 | - $v = _request('var_ajax') |
|
| 142 | - and $v !== 'form' |
|
| 143 | - and $args = _request('var_ajax_env') |
|
| 144 | - ) { |
|
| 145 | - include_spip('inc/filtres'); |
|
| 146 | - include_spip('inc/actions'); |
|
| 147 | - if ( |
|
| 148 | - $args = decoder_contexte_ajax($args) |
|
| 149 | - and $fond = $args['fond'] |
|
| 150 | - ) { |
|
| 151 | - include_spip('public/assembler'); |
|
| 152 | - $contexte = calculer_contexte(); |
|
| 153 | - $contexte = array_merge($args, $contexte); |
|
| 154 | - $page = recuperer_fond($fond, $contexte, ['trim' => false]); |
|
| 155 | - $texte = $page; |
|
| 156 | - if ($ancre = _request('var_ajax_ancre')) { |
|
| 157 | - // pas n'importe quoi quand meme dans la variable ! |
|
| 158 | - $ancre = str_replace(['<', '"', "'"], ['<', '"', ''], $ancre); |
|
| 159 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - include_spip('inc/headers'); |
|
| 163 | - http_response_code(400); |
|
| 164 | - $texte = _L('signature ajax bloc incorrecte'); |
|
| 165 | - } |
|
| 166 | - ajax_retour($texte, false); |
|
| 139 | + // traiter les appels de bloc ajax (ex: pagination) |
|
| 140 | + if ( |
|
| 141 | + $v = _request('var_ajax') |
|
| 142 | + and $v !== 'form' |
|
| 143 | + and $args = _request('var_ajax_env') |
|
| 144 | + ) { |
|
| 145 | + include_spip('inc/filtres'); |
|
| 146 | + include_spip('inc/actions'); |
|
| 147 | + if ( |
|
| 148 | + $args = decoder_contexte_ajax($args) |
|
| 149 | + and $fond = $args['fond'] |
|
| 150 | + ) { |
|
| 151 | + include_spip('public/assembler'); |
|
| 152 | + $contexte = calculer_contexte(); |
|
| 153 | + $contexte = array_merge($args, $contexte); |
|
| 154 | + $page = recuperer_fond($fond, $contexte, ['trim' => false]); |
|
| 155 | + $texte = $page; |
|
| 156 | + if ($ancre = _request('var_ajax_ancre')) { |
|
| 157 | + // pas n'importe quoi quand meme dans la variable ! |
|
| 158 | + $ancre = str_replace(['<', '"', "'"], ['<', '"', ''], $ancre); |
|
| 159 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + include_spip('inc/headers'); |
|
| 163 | + http_response_code(400); |
|
| 164 | + $texte = _L('signature ajax bloc incorrecte'); |
|
| 165 | + } |
|
| 166 | + ajax_retour($texte, false); |
|
| 167 | 167 | |
| 168 | - return true; // on a fini le hit |
|
| 169 | - } |
|
| 168 | + return true; // on a fini le hit |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - return false; |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter |
@@ -177,152 +177,152 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | // https://code.spip.net/@traiter_formulaires_dynamiques |
| 179 | 179 | function traiter_formulaires_dynamiques($get = false) { |
| 180 | - static $post = []; |
|
| 181 | - static $done = false; |
|
| 180 | + static $post = []; |
|
| 181 | + static $done = false; |
|
| 182 | 182 | |
| 183 | - if ($get) { |
|
| 184 | - return $post; |
|
| 185 | - } |
|
| 186 | - if ($done) { |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 189 | - $done = true; |
|
| 183 | + if ($get) { |
|
| 184 | + return $post; |
|
| 185 | + } |
|
| 186 | + if ($done) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | + $done = true; |
|
| 190 | 190 | |
| 191 | - if ( |
|
| 192 | - !($form = _request('formulaire_action') |
|
| 193 | - and $args = _request('formulaire_action_args')) |
|
| 194 | - ) { |
|
| 195 | - return false; |
|
| 196 | - } // le hit peut continuer normalement |
|
| 191 | + if ( |
|
| 192 | + !($form = _request('formulaire_action') |
|
| 193 | + and $args = _request('formulaire_action_args')) |
|
| 194 | + ) { |
|
| 195 | + return false; |
|
| 196 | + } // le hit peut continuer normalement |
|
| 197 | 197 | |
| 198 | - include_spip('inc/filtres'); |
|
| 199 | - if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 200 | - spip_log("signature ajax form incorrecte : $form"); |
|
| 198 | + include_spip('inc/filtres'); |
|
| 199 | + if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 200 | + spip_log("signature ajax form incorrecte : $form"); |
|
| 201 | 201 | |
| 202 | - return false; // continuons le hit comme si de rien etait |
|
| 203 | - } else { |
|
| 204 | - include_spip('inc/lang'); |
|
| 205 | - // sauvegarder la lang en cours |
|
| 206 | - $old_lang = $GLOBALS['spip_lang']; |
|
| 207 | - // changer la langue avec celle qui a cours dans le formulaire |
|
| 208 | - // on la depile de $args car c'est un argument implicite masque |
|
| 209 | - changer_langue(array_shift($args)); |
|
| 202 | + return false; // continuons le hit comme si de rien etait |
|
| 203 | + } else { |
|
| 204 | + include_spip('inc/lang'); |
|
| 205 | + // sauvegarder la lang en cours |
|
| 206 | + $old_lang = $GLOBALS['spip_lang']; |
|
| 207 | + // changer la langue avec celle qui a cours dans le formulaire |
|
| 208 | + // on la depile de $args car c'est un argument implicite masque |
|
| 209 | + changer_langue(array_shift($args)); |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | - // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 213 | - include_fichiers_fonctions(); |
|
| 214 | - // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 215 | - include_spip('base/abstract_sql'); |
|
| 212 | + // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 213 | + include_fichiers_fonctions(); |
|
| 214 | + // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 215 | + include_spip('base/abstract_sql'); |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 219 | - * mais avant l'appel de la fonction de vérification. |
|
| 220 | - */ |
|
| 221 | - pipeline( |
|
| 222 | - 'formulaire_receptionner', |
|
| 223 | - [ |
|
| 224 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 225 | - 'data' => null, |
|
| 226 | - ] |
|
| 227 | - ); |
|
| 217 | + /** |
|
| 218 | + * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 219 | + * mais avant l'appel de la fonction de vérification. |
|
| 220 | + */ |
|
| 221 | + pipeline( |
|
| 222 | + 'formulaire_receptionner', |
|
| 223 | + [ |
|
| 224 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 225 | + 'data' => null, |
|
| 226 | + ] |
|
| 227 | + ); |
|
| 228 | 228 | |
| 229 | - $verifier = charger_fonction('verifier', "formulaires/$form/", true); |
|
| 230 | - $post["erreurs_$form"] = pipeline( |
|
| 231 | - 'formulaire_verifier', |
|
| 232 | - [ |
|
| 233 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 234 | - 'data' => $verifier ? call_user_func_array($verifier, $args) : [] |
|
| 235 | - ] |
|
| 236 | - ); |
|
| 237 | - // prise en charge CVT multi etape si besoin |
|
| 238 | - if (_request('cvtm_prev_post')) { |
|
| 239 | - include_spip('inc/cvt_multietapes'); |
|
| 240 | - $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 241 | - ['form' => $form, 'args' => $args], |
|
| 242 | - $post["erreurs_$form"] |
|
| 243 | - ); |
|
| 244 | - } |
|
| 229 | + $verifier = charger_fonction('verifier', "formulaires/$form/", true); |
|
| 230 | + $post["erreurs_$form"] = pipeline( |
|
| 231 | + 'formulaire_verifier', |
|
| 232 | + [ |
|
| 233 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 234 | + 'data' => $verifier ? call_user_func_array($verifier, $args) : [] |
|
| 235 | + ] |
|
| 236 | + ); |
|
| 237 | + // prise en charge CVT multi etape si besoin |
|
| 238 | + if (_request('cvtm_prev_post')) { |
|
| 239 | + include_spip('inc/cvt_multietapes'); |
|
| 240 | + $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 241 | + ['form' => $form, 'args' => $args], |
|
| 242 | + $post["erreurs_$form"] |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 247 | - if ((isset($post["erreurs_$form"]) and count($post["erreurs_$form"])) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 248 | - $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel( |
|
| 249 | - count($post["erreurs_$form"]), |
|
| 250 | - 'avis_1_erreur_saisie', |
|
| 251 | - 'avis_nb_erreurs_saisie' |
|
| 252 | - ); |
|
| 253 | - } |
|
| 246 | + // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 247 | + if ((isset($post["erreurs_$form"]) and count($post["erreurs_$form"])) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 248 | + $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel( |
|
| 249 | + count($post["erreurs_$form"]), |
|
| 250 | + 'avis_1_erreur_saisie', |
|
| 251 | + 'avis_nb_erreurs_saisie' |
|
| 252 | + ); |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // si on ne demandait qu'une verif json |
|
| 256 | - if (_request('formulaire_action_verifier_json')) { |
|
| 257 | - include_spip('inc/json'); |
|
| 258 | - include_spip('inc/actions'); |
|
| 259 | - ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 255 | + // si on ne demandait qu'une verif json |
|
| 256 | + if (_request('formulaire_action_verifier_json')) { |
|
| 257 | + include_spip('inc/json'); |
|
| 258 | + include_spip('inc/actions'); |
|
| 259 | + ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 260 | 260 | |
| 261 | - return true; // on a fini le hit |
|
| 262 | - } |
|
| 263 | - $retour = ''; |
|
| 264 | - if (isset($post["erreurs_$form"]) and (count($post["erreurs_$form"]) == 0)) { |
|
| 265 | - $rev = ''; |
|
| 266 | - if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) { |
|
| 267 | - $rev = call_user_func_array($traiter, $args); |
|
| 268 | - } |
|
| 261 | + return true; // on a fini le hit |
|
| 262 | + } |
|
| 263 | + $retour = ''; |
|
| 264 | + if (isset($post["erreurs_$form"]) and (count($post["erreurs_$form"]) == 0)) { |
|
| 265 | + $rev = ''; |
|
| 266 | + if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) { |
|
| 267 | + $rev = call_user_func_array($traiter, $args); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - $rev = pipeline( |
|
| 271 | - 'formulaire_traiter', |
|
| 272 | - [ |
|
| 273 | - 'args' => ['form' => $form, 'args' => $args], |
|
| 274 | - 'data' => $rev |
|
| 275 | - ] |
|
| 276 | - ); |
|
| 277 | - // le retour de traiter est |
|
| 278 | - // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 279 | - // il permet le pipelinage, en particulier |
|
| 280 | - // en y passant l'id de l'objet cree/modifie |
|
| 281 | - // si message_erreur est present, on considere que le traitement a echoue |
|
| 282 | - $post["message_ok_$form"] = ''; |
|
| 283 | - // on peut avoir message_ok et message_erreur |
|
| 284 | - if (isset($rev['message_ok'])) { |
|
| 285 | - $post["message_ok_$form"] = $rev['message_ok']; |
|
| 286 | - } |
|
| 270 | + $rev = pipeline( |
|
| 271 | + 'formulaire_traiter', |
|
| 272 | + [ |
|
| 273 | + 'args' => ['form' => $form, 'args' => $args], |
|
| 274 | + 'data' => $rev |
|
| 275 | + ] |
|
| 276 | + ); |
|
| 277 | + // le retour de traiter est |
|
| 278 | + // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 279 | + // il permet le pipelinage, en particulier |
|
| 280 | + // en y passant l'id de l'objet cree/modifie |
|
| 281 | + // si message_erreur est present, on considere que le traitement a echoue |
|
| 282 | + $post["message_ok_$form"] = ''; |
|
| 283 | + // on peut avoir message_ok et message_erreur |
|
| 284 | + if (isset($rev['message_ok'])) { |
|
| 285 | + $post["message_ok_$form"] = $rev['message_ok']; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - // verifier si traiter n'a pas echoue avec une erreur : |
|
| 289 | - if (isset($rev['message_erreur'])) { |
|
| 290 | - $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur']; |
|
| 291 | - // si il y a une erreur on ne redirige pas |
|
| 292 | - } else { |
|
| 293 | - // sinon faire ce qu'il faut : |
|
| 294 | - if (isset($rev['editable'])) { |
|
| 295 | - $post["editable_$form"] = $rev['editable']; |
|
| 296 | - } |
|
| 297 | - // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 298 | - // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 299 | - if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 300 | - include_spip('inc/headers'); |
|
| 301 | - list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 302 | - $post["message_ok_$form"] .= $message; |
|
| 303 | - $retour .= $masque; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 308 | - if (_request('var_ajax')) { |
|
| 309 | - if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 310 | - include_spip('inc/actions'); |
|
| 311 | - include_spip('public/assembler'); |
|
| 312 | - array_unshift($args, $form); |
|
| 313 | - $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 314 | - // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 315 | - // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 316 | - // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 317 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 318 | - ajax_retour($retour, false); |
|
| 288 | + // verifier si traiter n'a pas echoue avec une erreur : |
|
| 289 | + if (isset($rev['message_erreur'])) { |
|
| 290 | + $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur']; |
|
| 291 | + // si il y a une erreur on ne redirige pas |
|
| 292 | + } else { |
|
| 293 | + // sinon faire ce qu'il faut : |
|
| 294 | + if (isset($rev['editable'])) { |
|
| 295 | + $post["editable_$form"] = $rev['editable']; |
|
| 296 | + } |
|
| 297 | + // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 298 | + // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 299 | + if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 300 | + include_spip('inc/headers'); |
|
| 301 | + list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 302 | + $post["message_ok_$form"] .= $message; |
|
| 303 | + $retour .= $masque; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 308 | + if (_request('var_ajax')) { |
|
| 309 | + if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 310 | + include_spip('inc/actions'); |
|
| 311 | + include_spip('public/assembler'); |
|
| 312 | + array_unshift($args, $form); |
|
| 313 | + $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 314 | + // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 315 | + // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 316 | + // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 317 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 318 | + ajax_retour($retour, false); |
|
| 319 | 319 | |
| 320 | - return true; // on a fini le hit |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - // restaurer la lang en cours |
|
| 324 | - changer_langue($old_lang); |
|
| 325 | - } |
|
| 320 | + return true; // on a fini le hit |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + // restaurer la lang en cours |
|
| 324 | + changer_langue($old_lang); |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - return false; // le hit peut continuer normalement |
|
| 327 | + return false; // le hit peut continuer normalement |
|
| 328 | 328 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | if (!$fonc) { |
| 149 | 149 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 150 | 150 | } |
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' '.$GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | 152 | } |
| 153 | 153 | if ($message === false) { |
| 154 | 154 | lang_select(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
| 178 | 178 | // une erreur critique sort $message en array |
| 179 | 179 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | + spip_log('Debug: '.$debug.' ('.$fond.')'); |
|
| 181 | 181 | |
| 182 | 182 | return $msg; |
| 183 | 183 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | 187 | if (!empty($erreurs)) { |
| 188 | - $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 188 | + $n = [count($erreurs).' '._T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | 190 | return debusquer_navigation($erreurs, $n); |
| 191 | 191 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -218,25 +218,25 @@ discard block |
||
| 218 | 218 | $valeur_simple = []; |
| 219 | 219 | foreach ($valeur as $v) { |
| 220 | 220 | if (is_array($v)) { |
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 221 | + $valeur_simple[] = 'array:'.count($v); |
|
| 222 | 222 | } elseif (is_object($v)) { |
| 223 | 223 | $valeur_simple[] = get_class($v); |
| 224 | 224 | } elseif (is_string($v)) { |
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | + $valeur_simple[] = "'".$v."'"; |
|
| 226 | 226 | } else { |
| 227 | 227 | $valeur_simple[] = $v; |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | $n = count($valeur); |
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 231 | + $valeur = (($n > 3) ? 'array:'.$n.' ' : ''); |
|
| 232 | + $valeur .= '['.join(', ', $valeur_simple).']'; |
|
| 233 | 233 | } elseif (is_object($valeur)) { |
| 234 | 234 | $valeur = get_class($valeur); |
| 235 | 235 | } elseif (is_string($valeur)) { |
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 236 | + $valeur = "'".$valeur."'"; |
|
| 237 | 237 | } |
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 238 | + $res .= "\n<tr><td><strong>".nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: '.nl2br(entites_html($valeur)) |
|
| 240 | 240 | . "</td></tr>\n"; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | $nom_code = $lieu->descr['nom']; |
| 265 | 265 | $skel = $lieu->descr['sourcefile']; |
| 266 | 266 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 268 | 268 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 269 | 269 | if ($boucle) { |
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 270 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | 271 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // Requete erronee |
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 359 | + $err = '<b>'._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 360 | 360 | . spip_htmlspecialchars($msg) |
| 361 | 361 | . "\n<br /><span style='color: red'><b>" |
| 362 | 362 | . spip_htmlspecialchars($query) |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 374 | + $id = $nom.$boucle; |
|
| 375 | 375 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 376 | 376 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 377 | 377 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 421 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 422 | 422 | |
| 423 | 423 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 424 | 424 | if (preg_match($incl, $v)) { |
@@ -434,16 +434,13 @@ discard block |
||
| 434 | 434 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 435 | 435 | |
| 436 | 436 | if (!$boucle) { |
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 437 | + return !$ligne ? '' : (' ('. |
|
| 438 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 441 | 439 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 442 | 440 | } else { |
| 443 | 441 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 444 | 442 | |
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 443 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | 444 | } |
| 448 | 445 | } |
| 449 | 446 | |
@@ -466,14 +463,14 @@ discard block |
||
| 466 | 463 | |
| 467 | 464 | $s = preg_replace( |
| 468 | 465 | ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 466 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 470 | 467 | $s |
| 471 | 468 | ); |
| 472 | 469 | |
| 473 | 470 | |
| 474 | 471 | $tableau = explode('<br />', $s); |
| 475 | 472 | |
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 473 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: ".($nocpt ? 'hidden' : 'visible').";%s' href='#T%s' title=\"%s\">%0".strval(@strlen(count($tableau)))."d</a></span> %s<br />\n"; |
|
| 477 | 474 | |
| 478 | 475 | $format10 = str_replace('white', 'lightgrey', $format); |
| 479 | 476 | $formaterr = 'color: red;'; |
@@ -517,7 +514,7 @@ discard block |
||
| 517 | 514 | . '" style="cursor: pointer;">' |
| 518 | 515 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 519 | 516 | . '</div> |
| 520 | - ' . $res . "</div>\n"; |
|
| 517 | + ' . $res."</div>\n"; |
|
| 521 | 518 | } |
| 522 | 519 | |
| 523 | 520 | // l'environnement graphique du debuggueur |
@@ -538,14 +535,14 @@ discard block |
||
| 538 | 535 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 539 | 536 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 540 | 537 | $texte .= $res2; |
| 541 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | - $legend = _T('zbug_' . $mode); |
|
| 543 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 538 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 539 | + $legend = _T('zbug_'.$mode); |
|
| 540 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 544 | 541 | $texte = ancre_texte($texte, ['', '']); |
| 545 | 542 | } |
| 546 | 543 | } else { |
| 547 | 544 | if (strlen(trim($res))) { |
| 548 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 545 | + return "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | 546 | } else { |
| 550 | 547 | // cas de l'appel sur erreur: montre la page |
| 551 | 548 | return isset($GLOBALS['debug_objets']['resultat']['tout']) |
@@ -555,7 +552,7 @@ discard block |
||
| 555 | 552 | } |
| 556 | 553 | } else { |
| 557 | 554 | $valider = charger_fonction('valider', 'xml'); |
| 558 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 555 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 559 | 556 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 560 | 557 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 561 | 558 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
@@ -566,14 +563,14 @@ discard block |
||
| 566 | 563 | } else { |
| 567 | 564 | $err = ": $err"; |
| 568 | 565 | } |
| 569 | - $legend = _T('validation') . ' ' . $err; |
|
| 566 | + $legend = _T('validation').' '.$err; |
|
| 570 | 567 | $res = $id = ''; |
| 571 | 568 | } |
| 572 | 569 | |
| 573 | 570 | return !trim($texte) ? '' : ( |
| 574 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 571 | + "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | 572 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 576 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 573 | + . "<a href='".$self.'#f_'.substr($fonc, 0, 37)."'> ↑ " |
|
| 577 | 574 | . ($legend ? $legend : $mode) |
| 578 | 575 | . '</a></legend>' |
| 579 | 576 | . $texte |
@@ -585,7 +582,7 @@ discard block |
||
| 585 | 582 | // https://code.spip.net/@emboite_texte |
| 586 | 583 | function emboite_texte($res, $fonc = '', $self = '') { |
| 587 | 584 | $errs = $res->err; |
| 588 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 585 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 589 | 586 | |
| 590 | 587 | if (!$texte and !$errs) { |
| 591 | 588 | return [ancre_texte('', ['', '']), false]; |
@@ -641,7 +638,7 @@ discard block |
||
| 641 | 638 | $err = "<h2 style='text-align: center'>" |
| 642 | 639 | . $i |
| 643 | 640 | . "<a href='#fin_err'>" |
| 644 | - . ' ' . _T('erreur_texte') |
|
| 641 | + . ' '._T('erreur_texte') |
|
| 645 | 642 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 646 | 643 | . $err |
| 647 | 644 | . " </table><a id='fin_err'></a>"; |
@@ -651,9 +648,9 @@ discard block |
||
| 651 | 648 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 652 | 649 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 653 | 650 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 651 | + $err = $msg. |
|
| 652 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 653 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 657 | 654 | |
| 658 | 655 | return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
| 659 | 656 | } |
@@ -687,7 +684,7 @@ discard block |
||
| 687 | 684 | ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
| 688 | 685 | ); |
| 689 | 686 | |
| 690 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 687 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 691 | 688 | . $t_skel |
| 692 | 689 | . ' ' |
| 693 | 690 | . $sourcefile |
@@ -702,7 +699,7 @@ discard block |
||
| 702 | 699 | . "'>" |
| 703 | 700 | . _T('zbug_calcul') |
| 704 | 701 | . '</a></legend>' |
| 705 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 702 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 706 | 703 | . debusquer_contexte($contexte[$sourcefile]) |
| 707 | 704 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 708 | 705 | . "</fieldset>\n"; |
@@ -723,33 +720,33 @@ discard block |
||
| 723 | 720 | $nom = $boucle->id_boucle; |
| 724 | 721 | $req = $boucle->type_requete; |
| 725 | 722 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 726 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | - |
|
| 728 | - $res .= "\n<tr style='background-color: " . |
|
| 729 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | - "'><td align='right'>$i</td><td>\n" . |
|
| 731 | - "<a class='debug_link_boucle' href='" . |
|
| 732 | - $self2 . |
|
| 733 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | - _T('zbug_boucle') . |
|
| 735 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | - $self2 . |
|
| 737 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | - _T('zbug_resultat') . |
|
| 739 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | - $self2 . |
|
| 741 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | - _T('zbug_code') . |
|
| 743 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | - "'>" . |
|
| 746 | - _T('zbug_calcul') . |
|
| 747 | - "</a></td><td>\n" . |
|
| 748 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - $req . |
|
| 751 | - "</td><td>\n" . |
|
| 752 | - spip_htmlspecialchars($crit) . |
|
| 723 | + $self2 = $self.'&var_mode_objet='.$objet; |
|
| 724 | + |
|
| 725 | + $res .= "\n<tr style='background-color: ". |
|
| 726 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 727 | + "'><td align='right'>$i</td><td>\n". |
|
| 728 | + "<a class='debug_link_boucle' href='". |
|
| 729 | + $self2. |
|
| 730 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 731 | + _T('zbug_boucle'). |
|
| 732 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 733 | + $self2. |
|
| 734 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 735 | + _T('zbug_resultat'). |
|
| 736 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 737 | + $self2. |
|
| 738 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 739 | + _T('zbug_code'). |
|
| 740 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 741 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 742 | + "'>". |
|
| 743 | + _T('zbug_calcul'). |
|
| 744 | + "</a></td><td>\n". |
|
| 745 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 746 | + "</td><td>\n". |
|
| 747 | + $req. |
|
| 748 | + "</td><td>\n". |
|
| 749 | + spip_htmlspecialchars($crit). |
|
| 753 | 750 | '</td></tr>'; |
| 754 | 751 | } |
| 755 | 752 | } |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | } |
| 777 | 774 | // permettre le copier/coller facile |
| 778 | 775 | // $res = ancre_texte($req, array(), true); |
| 779 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 776 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 780 | 777 | // formatage et affichage des resultats bruts de la requete |
| 781 | 778 | $ress_req = spip_query($req); |
| 782 | 779 | $brut_sql = ''; |
@@ -786,10 +783,10 @@ discard block |
||
| 786 | 783 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 787 | 784 | while ($retours_sql = sql_fetch($ress_req)) { |
| 788 | 785 | if ($num <= $max_aff) { |
| 789 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 786 | + $brut_sql .= '<h3>'.($num == 1 ? $num.' sur '.sql_count($ress_req) : $num).'</h3>'; |
|
| 790 | 787 | $brut_sql .= '<p>'; |
| 791 | 788 | foreach ($retours_sql as $key => $val) { |
| 792 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 789 | + $brut_sql .= '<strong>'.$key.'</strong> => '.spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 793 | 790 | } |
| 794 | 791 | $brut_sql .= '</p>'; |
| 795 | 792 | } |
@@ -800,14 +797,14 @@ discard block |
||
| 800 | 797 | // ne pas afficher les $contexte_inclus |
| 801 | 798 | $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
| 802 | 799 | if ($view) { |
| 803 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 800 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view).'</fieldset>'; |
|
| 804 | 801 | } |
| 805 | 802 | } |
| 806 | 803 | } elseif ($affiche == 'code') { |
| 807 | 804 | $legend = $nom; |
| 808 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 805 | + $res = ancre_texte('<'."?php\n".$quoi."\n?".'>'); |
|
| 809 | 806 | } elseif ($affiche == 'boucle') { |
| 810 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 807 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 811 | 808 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 812 | 809 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 813 | 810 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -826,23 +823,23 @@ discard block |
||
| 826 | 823 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 827 | 824 | include_spip('inc/texte'); // pour corriger_typo |
| 828 | 825 | |
| 829 | - return _DOCTYPE_ECRIRE . |
|
| 830 | - html_lang_attributes() . |
|
| 831 | - "<head>\n<title>" . |
|
| 832 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | - ")</title>\n" . |
|
| 836 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | - "' />\n" . |
|
| 826 | + return _DOCTYPE_ECRIRE. |
|
| 827 | + html_lang_attributes(). |
|
| 828 | + "<head>\n<title>". |
|
| 829 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 830 | + _T('admin_debug').' '.$titre.' ('. |
|
| 831 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 832 | + ")</title>\n". |
|
| 833 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 834 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 835 | + "' />\n". |
|
| 839 | 836 | http_script('', 'jquery.js') |
| 840 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | - . "' type='text/css' />" . |
|
| 842 | - "</head>\n" . |
|
| 843 | - "<body style='margin:0 10px;'>\n" . |
|
| 844 | - "<div id='spip-debug-header'>" . |
|
| 845 | - $corps . |
|
| 846 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 837 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 838 | + . "' type='text/css' />". |
|
| 839 | + "</head>\n". |
|
| 840 | + "<body style='margin:0 10px;'>\n". |
|
| 841 | + "<div id='spip-debug-header'>". |
|
| 842 | + $corps. |
|
| 843 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 847 | 844 | '</div></body></html>'; |
| 848 | 845 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,136 +66,136 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 69 | - static $tableau_des_erreurs = []; |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = []; |
|
| 78 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if ( |
|
| 119 | - ob_get_length() |
|
| 120 | - and |
|
| 121 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | - ) { |
|
| 123 | - ob_end_clean(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | - $fonc = _request('var_mode_objet'); |
|
| 128 | - $mode = _request('var_mode_affiche'); |
|
| 129 | - $self = str_replace("\\'", ''', self()); |
|
| 130 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | - |
|
| 132 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | - . '<br />' |
|
| 134 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | - |
|
| 136 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | - return $res; |
|
| 138 | - } |
|
| 139 | - if ($tableau_des_erreurs) { |
|
| 140 | - http_response_code(503); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - http_no_cache(); |
|
| 144 | - if (isset($_GET['var_profile'])) { |
|
| 145 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | - } else { |
|
| 148 | - if (!$fonc) { |
|
| 149 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | - } |
|
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | - } |
|
| 153 | - if ($message === false) { |
|
| 154 | - lang_select(); |
|
| 155 | - |
|
| 156 | - return debusquer_entete($titre, $res); |
|
| 157 | - } else { |
|
| 158 | - echo debusquer_entete($titre, $res); |
|
| 159 | - } |
|
| 160 | - exit; |
|
| 69 | + static $tableau_des_erreurs = []; |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = []; |
|
| 78 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if ( |
|
| 119 | + ob_get_length() |
|
| 120 | + and |
|
| 121 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | + ) { |
|
| 123 | + ob_end_clean(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | + $fonc = _request('var_mode_objet'); |
|
| 128 | + $mode = _request('var_mode_affiche'); |
|
| 129 | + $self = str_replace("\\'", ''', self()); |
|
| 130 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | + |
|
| 132 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | + . '<br />' |
|
| 134 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | + |
|
| 136 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | + return $res; |
|
| 138 | + } |
|
| 139 | + if ($tableau_des_erreurs) { |
|
| 140 | + http_response_code(503); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + http_no_cache(); |
|
| 144 | + if (isset($_GET['var_profile'])) { |
|
| 145 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | + } else { |
|
| 148 | + if (!$fonc) { |
|
| 149 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | + } |
|
| 151 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | + } |
|
| 153 | + if ($message === false) { |
|
| 154 | + lang_select(); |
|
| 155 | + |
|
| 156 | + return debusquer_entete($titre, $res); |
|
| 157 | + } else { |
|
| 158 | + echo debusquer_entete($titre, $res); |
|
| 159 | + } |
|
| 160 | + exit; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debusquer_compose_message($msg) { |
| 164 | - if (is_array($msg)) { |
|
| 165 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | - // message avec argument: instancier |
|
| 169 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | - } else { |
|
| 171 | - // message SQL: interpreter |
|
| 172 | - $msg = debusquer_requete($msg); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | - // une erreur critique sort $message en array |
|
| 179 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | - |
|
| 182 | - return $msg; |
|
| 164 | + if (is_array($msg)) { |
|
| 165 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | + // message avec argument: instancier |
|
| 169 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | + } else { |
|
| 171 | + // message SQL: interpreter |
|
| 172 | + $msg = debusquer_requete($msg); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ''; |
|
| 178 | + // une erreur critique sort $message en array |
|
| 179 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | + |
|
| 182 | + return $msg; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | - if (!empty($erreurs)) { |
|
| 188 | - $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 187 | + if (!empty($erreurs)) { |
|
| 188 | + $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | - return debusquer_navigation($erreurs, $n); |
|
| 191 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | - include_spip('public/tracer'); |
|
| 193 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 190 | + return debusquer_navigation($erreurs, $n); |
|
| 191 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | + include_spip('public/tracer'); |
|
| 193 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 194 | 194 | |
| 195 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | - } else { |
|
| 197 | - return ''; |
|
| 198 | - } |
|
| 195 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | + } else { |
|
| 197 | + return ''; |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -205,42 +205,42 @@ discard block |
||
| 205 | 205 | * @return string Code HTML |
| 206 | 206 | **/ |
| 207 | 207 | function debusquer_contexte($env) { |
| 208 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | - $env = $env_tab; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!$env) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $res = ''; |
|
| 216 | - foreach ($env as $nom => $valeur) { |
|
| 217 | - if (is_array($valeur)) { |
|
| 218 | - $valeur_simple = []; |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - if (is_array($v)) { |
|
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 222 | - } elseif (is_object($v)) { |
|
| 223 | - $valeur_simple[] = get_class($v); |
|
| 224 | - } elseif (is_string($v)) { |
|
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | - } else { |
|
| 227 | - $valeur_simple[] = $v; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - $n = count($valeur); |
|
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | - } elseif (is_object($valeur)) { |
|
| 234 | - $valeur = get_class($valeur); |
|
| 235 | - } elseif (is_string($valeur)) { |
|
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 237 | - } |
|
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | - . "</td></tr>\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | + $env = $env_tab; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!$env) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $res = ''; |
|
| 216 | + foreach ($env as $nom => $valeur) { |
|
| 217 | + if (is_array($valeur)) { |
|
| 218 | + $valeur_simple = []; |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + if (is_array($v)) { |
|
| 221 | + $valeur_simple[] = 'array:' . count($v); |
|
| 222 | + } elseif (is_object($v)) { |
|
| 223 | + $valeur_simple[] = get_class($v); |
|
| 224 | + } elseif (is_string($v)) { |
|
| 225 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | + } else { |
|
| 227 | + $valeur_simple[] = $v; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + $n = count($valeur); |
|
| 231 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | + } elseif (is_object($valeur)) { |
|
| 234 | + $valeur = get_class($valeur); |
|
| 235 | + } elseif (is_string($valeur)) { |
|
| 236 | + $valeur = "'" . $valeur . "'"; |
|
| 237 | + } |
|
| 238 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | + . "</td></tr>\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 250 | 250 | |
| 251 | - if (_request('exec') == 'valider_xml') { |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 254 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | - $res = ''; |
|
| 256 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | - foreach ($tableau as $i => $err) { |
|
| 258 | - $boucle = $ligne = $skel = ''; |
|
| 259 | - list($msg, $lieu) = $err; |
|
| 260 | - if (is_object($lieu)) { |
|
| 261 | - $ligne = $lieu->ligne; |
|
| 262 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 263 | - if (isset($lieu->descr['nom'])) { |
|
| 264 | - $nom_code = $lieu->descr['nom']; |
|
| 265 | - $skel = $lieu->descr['sourcefile']; |
|
| 266 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | - if ($boucle) { |
|
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $j = ($i + 1); |
|
| 277 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | - . $j |
|
| 279 | - . " </td><td style='text-align: left'>" |
|
| 280 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | - . "</td><td style='text-align: left'>" |
|
| 282 | - . ($skel ? $skel : ' / ') |
|
| 283 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | - . ($boucle ? $boucle : ' / ') |
|
| 285 | - . "</td><td style='text-align: right'>" |
|
| 286 | - . $ligne |
|
| 287 | - . "</td></tr>\n"; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return "\n<table id='$id'>" |
|
| 291 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | - . $caption[0] |
|
| 251 | + if (_request('exec') == 'valider_xml') { |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | + $res = ''; |
|
| 256 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | + foreach ($tableau as $i => $err) { |
|
| 258 | + $boucle = $ligne = $skel = ''; |
|
| 259 | + list($msg, $lieu) = $err; |
|
| 260 | + if (is_object($lieu)) { |
|
| 261 | + $ligne = $lieu->ligne; |
|
| 262 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 263 | + if (isset($lieu->descr['nom'])) { |
|
| 264 | + $nom_code = $lieu->descr['nom']; |
|
| 265 | + $skel = $lieu->descr['sourcefile']; |
|
| 266 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | + if ($boucle) { |
|
| 270 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $j = ($i + 1); |
|
| 277 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | + . $j |
|
| 279 | + . " </td><td style='text-align: left'>" |
|
| 280 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | + . "</td><td style='text-align: left'>" |
|
| 282 | + . ($skel ? $skel : ' / ') |
|
| 283 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | + . ($boucle ? $boucle : ' / ') |
|
| 285 | + . "</td><td style='text-align: right'>" |
|
| 286 | + . $ligne |
|
| 287 | + . "</td></tr>\n"; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return "\n<table id='$id'>" |
|
| 291 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | + . $caption[0] |
|
| 293 | 293 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 294 | 294 | # aider('erreur_compilation'), |
| 295 | - . '</caption>' |
|
| 296 | - // fausse caption du chrono (mais vraie nav) |
|
| 297 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | - . '<tr><th>' |
|
| 299 | - . _T('numero') |
|
| 300 | - . '</th><th>' |
|
| 301 | - . _T('public:message') |
|
| 302 | - . '</th><th>' |
|
| 303 | - . _T('squelette') |
|
| 304 | - . '</th><th>' |
|
| 305 | - . _T('zbug_boucle') |
|
| 306 | - . '</th><th>' |
|
| 307 | - . _T('ligne') |
|
| 308 | - . '</th></tr>' |
|
| 309 | - . $res |
|
| 310 | - . '</table>'; |
|
| 295 | + . '</caption>' |
|
| 296 | + // fausse caption du chrono (mais vraie nav) |
|
| 297 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | + . '<tr><th>' |
|
| 299 | + . _T('numero') |
|
| 300 | + . '</th><th>' |
|
| 301 | + . _T('public:message') |
|
| 302 | + . '</th><th>' |
|
| 303 | + . _T('squelette') |
|
| 304 | + . '</th><th>' |
|
| 305 | + . _T('zbug_boucle') |
|
| 306 | + . '</th><th>' |
|
| 307 | + . _T('ligne') |
|
| 308 | + . '</th></tr>' |
|
| 309 | + . $res |
|
| 310 | + . '</table>'; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -327,124 +327,124 @@ discard block |
||
| 327 | 327 | * ou un tableau si l'erreur est critique |
| 328 | 328 | **/ |
| 329 | 329 | function debusquer_requete($message) { |
| 330 | - list($errno, $msg, $query) = $message; |
|
| 331 | - |
|
| 332 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | - $errno = $regs[2]; |
|
| 336 | - } elseif ( |
|
| 337 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | - ) { |
|
| 340 | - $errno = $regs[1]; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Erreur systeme |
|
| 344 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | - $retour = '<tt><br /><br /><blink>' |
|
| 346 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | - . "</blink><br />\n<b>" |
|
| 348 | - . _T( |
|
| 349 | - 'info_erreur_systeme2', |
|
| 350 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | - ) |
|
| 352 | - . '</b><br />'; |
|
| 353 | - spip_log("Erreur systeme $errno"); |
|
| 354 | - |
|
| 355 | - return [$retour, '']; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Requete erronee |
|
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | - . spip_htmlspecialchars($msg) |
|
| 361 | - . "\n<br /><span style='color: red'><b>" |
|
| 362 | - . spip_htmlspecialchars($query) |
|
| 363 | - . '</b></span></tt><br />'; |
|
| 364 | - |
|
| 365 | - //. aider('erreur_mysql'); |
|
| 366 | - |
|
| 367 | - return $err; |
|
| 330 | + list($errno, $msg, $query) = $message; |
|
| 331 | + |
|
| 332 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | + $errno = $regs[2]; |
|
| 336 | + } elseif ( |
|
| 337 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | + ) { |
|
| 340 | + $errno = $regs[1]; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Erreur systeme |
|
| 344 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | + $retour = '<tt><br /><br /><blink>' |
|
| 346 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | + . "</blink><br />\n<b>" |
|
| 348 | + . _T( |
|
| 349 | + 'info_erreur_systeme2', |
|
| 350 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | + ) |
|
| 352 | + . '</b><br />'; |
|
| 353 | + spip_log("Erreur systeme $errno"); |
|
| 354 | + |
|
| 355 | + return [$retour, '']; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Requete erronee |
|
| 359 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | + . spip_htmlspecialchars($msg) |
|
| 361 | + . "\n<br /><span style='color: red'><b>" |
|
| 362 | + . spip_htmlspecialchars($query) |
|
| 363 | + . '</b></span></tt><br />'; |
|
| 364 | + |
|
| 365 | + //. aider('erreur_mysql'); |
|
| 366 | + |
|
| 367 | + return $err; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 375 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | - $y = substr_count($v[0], "\n"); |
|
| 379 | - } else { |
|
| 380 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | - } else // inclusion |
|
| 383 | - { |
|
| 384 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | - } |
|
| 386 | - $y = substr_count($incl, "\n") |
|
| 387 | - + substr_count($r[1], "\n") |
|
| 388 | - + substr_count($r[3], "\n"); |
|
| 389 | - } |
|
| 390 | - if ($n <= ($y + $debut)) { |
|
| 391 | - if ($v[1][0] == '?') { |
|
| 392 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | - } elseif ($v[1][0] == '!') { |
|
| 394 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | - } |
|
| 401 | - $debut += $y; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return [$nom, $boucle, $n - $debut]; |
|
| 374 | + $id = $nom . $boucle; |
|
| 375 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | + $y = substr_count($v[0], "\n"); |
|
| 379 | + } else { |
|
| 380 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | + } else // inclusion |
|
| 383 | + { |
|
| 384 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | + } |
|
| 386 | + $y = substr_count($incl, "\n") |
|
| 387 | + + substr_count($r[1], "\n") |
|
| 388 | + + substr_count($r[3], "\n"); |
|
| 389 | + } |
|
| 390 | + if ($n <= ($y + $debut)) { |
|
| 391 | + if ($v[1][0] == '?') { |
|
| 392 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | + } elseif ($v[1][0] == '!') { |
|
| 394 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | + } |
|
| 401 | + $debut += $y; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return [$nom, $boucle, $n - $debut]; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // https://code.spip.net/@trouve_squelette_inclus |
| 409 | 409 | function trouve_squelette_inclus($script) { |
| 410 | 410 | |
| 411 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | - // si le script X.php n'est pas ecrire/public.php |
|
| 413 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | - $reg[1] = 'inconnu'; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | - |
|
| 423 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | - if (preg_match($incl, $v)) { |
|
| 425 | - return $k; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return ''; |
|
| 411 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | + // si le script X.php n'est pas ecrire/public.php |
|
| 413 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | + $reg[1] = 'inconnu'; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | + |
|
| 423 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | + if (preg_match($incl, $v)) { |
|
| 425 | + return $k; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return ''; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // https://code.spip.net/@reference_boucle_debug |
| 433 | 433 | function reference_boucle_debug($n, $nom, $self) { |
| 434 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | - |
|
| 436 | - if (!$boucle) { |
|
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 441 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | - } else { |
|
| 443 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | - |
|
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | - } |
|
| 434 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 435 | + |
|
| 436 | + if (!$boucle) { |
|
| 437 | + return !$ligne ? '' : |
|
| 438 | + (' (' . |
|
| 439 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | + _T('squelette_ligne')) . |
|
| 441 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | + } else { |
|
| 443 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | + |
|
| 445 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // affiche un texte avec numero de ligne et ancre. |
@@ -452,397 +452,397 @@ discard block |
||
| 452 | 452 | // https://code.spip.net/@ancre_texte |
| 453 | 453 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 454 | 454 | |
| 455 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | - if ($var_mode_ligne) { |
|
| 457 | - $fautifs[] = [$var_mode_ligne]; |
|
| 458 | - } |
|
| 459 | - $res = ''; |
|
| 460 | - |
|
| 461 | - $s = highlight_string($texte, true); |
|
| 462 | - if (substr($s, 0, 6) == '<code>') { |
|
| 463 | - $s = substr($s, 6); |
|
| 464 | - $res = '<code>'; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $s = preg_replace( |
|
| 468 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | - $s |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - $tableau = explode('<br />', $s); |
|
| 475 | - |
|
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | - |
|
| 478 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | - $formaterr = 'color: red;'; |
|
| 480 | - $i = 1; |
|
| 481 | - $flignes = []; |
|
| 482 | - $loc = [0, 0]; |
|
| 483 | - foreach ($fautifs as $lc) { |
|
| 484 | - if (is_array($lc)) { |
|
| 485 | - $l = array_shift($lc); |
|
| 486 | - $flignes[$l] = $lc; |
|
| 487 | - } else { |
|
| 488 | - $flignes[$lc] = $loc; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - $ancre = md5($texte); |
|
| 493 | - foreach ($tableau as $ligne) { |
|
| 494 | - if (isset($flignes[$i])) { |
|
| 495 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | - $indexmesg = $flignes[$i][1]; |
|
| 497 | - $err = textebrut($flignes[$i][2]); |
|
| 498 | - // tentative de pointer sur la colonne fautive; |
|
| 499 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | - // $m = $flignes[$i][0]; |
|
| 501 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | - $bg = $formaterr; |
|
| 504 | - } else { |
|
| 505 | - $indexmesg = $ancre; |
|
| 506 | - $err = $bg = ''; |
|
| 507 | - } |
|
| 508 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | - $i++; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return "<div id='T$ancre'>" |
|
| 513 | - . '<div onclick="' |
|
| 514 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | - . '" title="' |
|
| 516 | - . _T('masquer_colonne') |
|
| 517 | - . '" style="cursor: pointer;">' |
|
| 518 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | - . '</div> |
|
| 455 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | + if ($var_mode_ligne) { |
|
| 457 | + $fautifs[] = [$var_mode_ligne]; |
|
| 458 | + } |
|
| 459 | + $res = ''; |
|
| 460 | + |
|
| 461 | + $s = highlight_string($texte, true); |
|
| 462 | + if (substr($s, 0, 6) == '<code>') { |
|
| 463 | + $s = substr($s, 6); |
|
| 464 | + $res = '<code>'; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $s = preg_replace( |
|
| 468 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | + $s |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + $tableau = explode('<br />', $s); |
|
| 475 | + |
|
| 476 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | + |
|
| 478 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | + $formaterr = 'color: red;'; |
|
| 480 | + $i = 1; |
|
| 481 | + $flignes = []; |
|
| 482 | + $loc = [0, 0]; |
|
| 483 | + foreach ($fautifs as $lc) { |
|
| 484 | + if (is_array($lc)) { |
|
| 485 | + $l = array_shift($lc); |
|
| 486 | + $flignes[$l] = $lc; |
|
| 487 | + } else { |
|
| 488 | + $flignes[$lc] = $loc; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + $ancre = md5($texte); |
|
| 493 | + foreach ($tableau as $ligne) { |
|
| 494 | + if (isset($flignes[$i])) { |
|
| 495 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | + $indexmesg = $flignes[$i][1]; |
|
| 497 | + $err = textebrut($flignes[$i][2]); |
|
| 498 | + // tentative de pointer sur la colonne fautive; |
|
| 499 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | + // $m = $flignes[$i][0]; |
|
| 501 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | + $bg = $formaterr; |
|
| 504 | + } else { |
|
| 505 | + $indexmesg = $ancre; |
|
| 506 | + $err = $bg = ''; |
|
| 507 | + } |
|
| 508 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | + $i++; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return "<div id='T$ancre'>" |
|
| 513 | + . '<div onclick="' |
|
| 514 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | + . '" title="' |
|
| 516 | + . _T('masquer_colonne') |
|
| 517 | + . '" style="cursor: pointer;">' |
|
| 518 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | + . '</div> |
|
| 520 | 520 | ' . $res . "</div>\n"; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | // l'environnement graphique du debuggueur |
| 524 | 524 | |
| 525 | 525 | function debusquer_squelette($fonc, $mode, $self) { |
| 526 | - $texte = ''; |
|
| 527 | - |
|
| 528 | - if ($mode !== 'validation') { |
|
| 529 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | - $res = "<div id='spip-boucles'>\n" |
|
| 531 | - . debusquer_navigation_squelettes($self) |
|
| 532 | - . '</div>'; |
|
| 533 | - } else { |
|
| 534 | - $res = ''; |
|
| 535 | - } |
|
| 536 | - if ($fonc) { |
|
| 537 | - $id = " id='$fonc'"; |
|
| 538 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | - $texte .= $res2; |
|
| 541 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | - $legend = _T('zbug_' . $mode); |
|
| 543 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | - $texte = ancre_texte($texte, ['', '']); |
|
| 545 | - } |
|
| 546 | - } else { |
|
| 547 | - if (strlen(trim($res))) { |
|
| 548 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | - } else { |
|
| 550 | - // cas de l'appel sur erreur: montre la page |
|
| 551 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | - : ''; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } else { |
|
| 557 | - $valider = charger_fonction('valider', 'xml'); |
|
| 558 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | - if ($err === false) { |
|
| 563 | - $err = _T('impossible'); |
|
| 564 | - } elseif ($err === true) { |
|
| 565 | - $err = _T('correcte'); |
|
| 566 | - } else { |
|
| 567 | - $err = ": $err"; |
|
| 568 | - } |
|
| 569 | - $legend = _T('validation') . ' ' . $err; |
|
| 570 | - $res = $id = ''; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return !trim($texte) ? '' : ( |
|
| 574 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | - . ($legend ? $legend : $mode) |
|
| 578 | - . '</a></legend>' |
|
| 579 | - . $texte |
|
| 580 | - . '</fieldset></div>' |
|
| 581 | - . '</div>'); |
|
| 526 | + $texte = ''; |
|
| 527 | + |
|
| 528 | + if ($mode !== 'validation') { |
|
| 529 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 530 | + $res = "<div id='spip-boucles'>\n" |
|
| 531 | + . debusquer_navigation_squelettes($self) |
|
| 532 | + . '</div>'; |
|
| 533 | + } else { |
|
| 534 | + $res = ''; |
|
| 535 | + } |
|
| 536 | + if ($fonc) { |
|
| 537 | + $id = " id='$fonc'"; |
|
| 538 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 539 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 540 | + $texte .= $res2; |
|
| 541 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 542 | + $legend = _T('zbug_' . $mode); |
|
| 543 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 544 | + $texte = ancre_texte($texte, ['', '']); |
|
| 545 | + } |
|
| 546 | + } else { |
|
| 547 | + if (strlen(trim($res))) { |
|
| 548 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 549 | + } else { |
|
| 550 | + // cas de l'appel sur erreur: montre la page |
|
| 551 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 552 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 553 | + : ''; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } else { |
|
| 557 | + $valider = charger_fonction('valider', 'xml'); |
|
| 558 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 559 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 560 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 561 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 562 | + if ($err === false) { |
|
| 563 | + $err = _T('impossible'); |
|
| 564 | + } elseif ($err === true) { |
|
| 565 | + $err = _T('correcte'); |
|
| 566 | + } else { |
|
| 567 | + $err = ": $err"; |
|
| 568 | + } |
|
| 569 | + $legend = _T('validation') . ' ' . $err; |
|
| 570 | + $res = $id = ''; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return !trim($texte) ? '' : ( |
|
| 574 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 575 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 576 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 577 | + . ($legend ? $legend : $mode) |
|
| 578 | + . '</a></legend>' |
|
| 579 | + . $texte |
|
| 580 | + . '</fieldset></div>' |
|
| 581 | + . '</div>'); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | // https://code.spip.net/@emboite_texte |
| 586 | 586 | function emboite_texte($res, $fonc = '', $self = '') { |
| 587 | - $errs = $res->err; |
|
| 588 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | - |
|
| 590 | - if (!$texte and !$errs) { |
|
| 591 | - return [ancre_texte('', ['', '']), false]; |
|
| 592 | - } |
|
| 593 | - if (!$errs) { |
|
| 594 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | - $encore = count_occ($errs); |
|
| 600 | - $encore2 = []; |
|
| 601 | - $fautifs = []; |
|
| 602 | - |
|
| 603 | - $err = '<tr><th>' |
|
| 604 | - . _T('numero') |
|
| 605 | - . '</th><th>' |
|
| 606 | - . _T('occurence') |
|
| 607 | - . '</th><th>' |
|
| 608 | - . _T('ligne') |
|
| 609 | - . '</th><th>' |
|
| 610 | - . _T('colonne') |
|
| 611 | - . '</th><th>' |
|
| 612 | - . _T('erreur') |
|
| 613 | - . '</th></tr>'; |
|
| 614 | - |
|
| 615 | - $i = 0; |
|
| 616 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | - foreach ($errs as $r) { |
|
| 618 | - $i++; |
|
| 619 | - list($msg, $ligne, $col) = $r; |
|
| 620 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | - if (isset($encore2[$msg])) { |
|
| 622 | - $ref = ++$encore2[$msg]; |
|
| 623 | - } else { |
|
| 624 | - $encore2[$msg] = $ref = 1; |
|
| 625 | - } |
|
| 626 | - $err .= "<tr style='background-color: " |
|
| 627 | - . $colors[$i % 2] |
|
| 628 | - . "'><td $style><a href='#debut_err'>" |
|
| 629 | - . $i |
|
| 630 | - . "</a></td><td $style>" |
|
| 631 | - . "$ref/$encore[$msg]</td>" |
|
| 632 | - . "<td $style><a href='#L" |
|
| 633 | - . $ligne |
|
| 634 | - . "' id='T$i'>" |
|
| 635 | - . $ligne |
|
| 636 | - . "</a></td><td $style>" |
|
| 637 | - . $col |
|
| 638 | - . "</td><td>$msg</td></tr>\n"; |
|
| 639 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | - } |
|
| 641 | - $err = "<h2 style='text-align: center'>" |
|
| 642 | - . $i |
|
| 643 | - . "<a href='#fin_err'>" |
|
| 644 | - . ' ' . _T('erreur_texte') |
|
| 645 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | - . $err |
|
| 647 | - . " </table><a id='fin_err'></a>"; |
|
| 648 | - |
|
| 649 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | - } else { |
|
| 651 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | - $err = $msg . |
|
| 655 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | - |
|
| 658 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | - } |
|
| 587 | + $errs = $res->err; |
|
| 588 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | + |
|
| 590 | + if (!$texte and !$errs) { |
|
| 591 | + return [ancre_texte('', ['', '']), false]; |
|
| 592 | + } |
|
| 593 | + if (!$errs) { |
|
| 594 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 599 | + $encore = count_occ($errs); |
|
| 600 | + $encore2 = []; |
|
| 601 | + $fautifs = []; |
|
| 602 | + |
|
| 603 | + $err = '<tr><th>' |
|
| 604 | + . _T('numero') |
|
| 605 | + . '</th><th>' |
|
| 606 | + . _T('occurence') |
|
| 607 | + . '</th><th>' |
|
| 608 | + . _T('ligne') |
|
| 609 | + . '</th><th>' |
|
| 610 | + . _T('colonne') |
|
| 611 | + . '</th><th>' |
|
| 612 | + . _T('erreur') |
|
| 613 | + . '</th></tr>'; |
|
| 614 | + |
|
| 615 | + $i = 0; |
|
| 616 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 617 | + foreach ($errs as $r) { |
|
| 618 | + $i++; |
|
| 619 | + list($msg, $ligne, $col) = $r; |
|
| 620 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 621 | + if (isset($encore2[$msg])) { |
|
| 622 | + $ref = ++$encore2[$msg]; |
|
| 623 | + } else { |
|
| 624 | + $encore2[$msg] = $ref = 1; |
|
| 625 | + } |
|
| 626 | + $err .= "<tr style='background-color: " |
|
| 627 | + . $colors[$i % 2] |
|
| 628 | + . "'><td $style><a href='#debut_err'>" |
|
| 629 | + . $i |
|
| 630 | + . "</a></td><td $style>" |
|
| 631 | + . "$ref/$encore[$msg]</td>" |
|
| 632 | + . "<td $style><a href='#L" |
|
| 633 | + . $ligne |
|
| 634 | + . "' id='T$i'>" |
|
| 635 | + . $ligne |
|
| 636 | + . "</a></td><td $style>" |
|
| 637 | + . $col |
|
| 638 | + . "</td><td>$msg</td></tr>\n"; |
|
| 639 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 640 | + } |
|
| 641 | + $err = "<h2 style='text-align: center'>" |
|
| 642 | + . $i |
|
| 643 | + . "<a href='#fin_err'>" |
|
| 644 | + . ' ' . _T('erreur_texte') |
|
| 645 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 646 | + . $err |
|
| 647 | + . " </table><a id='fin_err'></a>"; |
|
| 648 | + |
|
| 649 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 650 | + } else { |
|
| 651 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 652 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 653 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 654 | + $err = $msg . |
|
| 655 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 656 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 657 | + |
|
| 658 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | // https://code.spip.net/@count_occ |
| 663 | 663 | function count_occ($regs) { |
| 664 | - $encore = []; |
|
| 665 | - foreach ($regs as $r) { |
|
| 666 | - if (isset($encore[$r[0]])) { |
|
| 667 | - $encore[$r[0]]++; |
|
| 668 | - } else { |
|
| 669 | - $encore[$r[0]] = 1; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return $encore; |
|
| 664 | + $encore = []; |
|
| 665 | + foreach ($regs as $r) { |
|
| 666 | + if (isset($encore[$r[0]])) { |
|
| 667 | + $encore[$r[0]]++; |
|
| 668 | + } else { |
|
| 669 | + $encore[$r[0]] = 1; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return $encore; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | function debusquer_navigation_squelettes($self) { |
| 677 | 677 | |
| 678 | - $res = ''; |
|
| 679 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | - $t_skel = _T('squelette'); |
|
| 682 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | - 'zbug_profile', |
|
| 687 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | - ); |
|
| 689 | - |
|
| 690 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | - . $t_skel |
|
| 692 | - . ' ' |
|
| 693 | - . $sourcefile |
|
| 694 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | - . $t_skel |
|
| 696 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | - . _T('zbug_resultat') |
|
| 698 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | - . _T('zbug_code') |
|
| 700 | - . "</a>\n<a href='" |
|
| 701 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | - . "'>" |
|
| 703 | - . _T('zbug_calcul') |
|
| 704 | - . '</a></legend>' |
|
| 705 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | - . "</fieldset>\n"; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - return $res; |
|
| 678 | + $res = ''; |
|
| 679 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 680 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 681 | + $t_skel = _T('squelette'); |
|
| 682 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 683 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 684 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 685 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 686 | + 'zbug_profile', |
|
| 687 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 688 | + ); |
|
| 689 | + |
|
| 690 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 691 | + . $t_skel |
|
| 692 | + . ' ' |
|
| 693 | + . $sourcefile |
|
| 694 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 695 | + . $t_skel |
|
| 696 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 697 | + . _T('zbug_resultat') |
|
| 698 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 699 | + . _T('zbug_code') |
|
| 700 | + . "</a>\n<a href='" |
|
| 701 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 702 | + . "'>" |
|
| 703 | + . _T('zbug_calcul') |
|
| 704 | + . '</a></legend>' |
|
| 705 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 706 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 707 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 708 | + . "</fieldset>\n"; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + return $res; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 715 | - $i = 0; |
|
| 716 | - $res = ''; |
|
| 717 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | - |
|
| 720 | - foreach ($boucles as $objet => $boucle) { |
|
| 721 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | - $i++; |
|
| 723 | - $nom = $boucle->id_boucle; |
|
| 724 | - $req = $boucle->type_requete; |
|
| 725 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | - |
|
| 728 | - $res .= "\n<tr style='background-color: " . |
|
| 729 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | - "'><td align='right'>$i</td><td>\n" . |
|
| 731 | - "<a class='debug_link_boucle' href='" . |
|
| 732 | - $self2 . |
|
| 733 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | - _T('zbug_boucle') . |
|
| 735 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | - $self2 . |
|
| 737 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | - _T('zbug_resultat') . |
|
| 739 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | - $self2 . |
|
| 741 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | - _T('zbug_code') . |
|
| 743 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | - "'>" . |
|
| 746 | - _T('zbug_calcul') . |
|
| 747 | - "</a></td><td>\n" . |
|
| 748 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | - "</td><td>\n" . |
|
| 750 | - $req . |
|
| 751 | - "</td><td>\n" . |
|
| 752 | - spip_htmlspecialchars($crit) . |
|
| 753 | - '</td></tr>'; |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $res; |
|
| 715 | + $i = 0; |
|
| 716 | + $res = ''; |
|
| 717 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 718 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 719 | + |
|
| 720 | + foreach ($boucles as $objet => $boucle) { |
|
| 721 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 722 | + $i++; |
|
| 723 | + $nom = $boucle->id_boucle; |
|
| 724 | + $req = $boucle->type_requete; |
|
| 725 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 726 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 727 | + |
|
| 728 | + $res .= "\n<tr style='background-color: " . |
|
| 729 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 730 | + "'><td align='right'>$i</td><td>\n" . |
|
| 731 | + "<a class='debug_link_boucle' href='" . |
|
| 732 | + $self2 . |
|
| 733 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 734 | + _T('zbug_boucle') . |
|
| 735 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 736 | + $self2 . |
|
| 737 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 738 | + _T('zbug_resultat') . |
|
| 739 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 740 | + $self2 . |
|
| 741 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 742 | + _T('zbug_code') . |
|
| 743 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 744 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 745 | + "'>" . |
|
| 746 | + _T('zbug_calcul') . |
|
| 747 | + "</a></td><td>\n" . |
|
| 748 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 749 | + "</td><td>\n" . |
|
| 750 | + $req . |
|
| 751 | + "</td><td>\n" . |
|
| 752 | + spip_htmlspecialchars($crit) . |
|
| 753 | + '</td></tr>'; |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $res; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | function debusquer_source($objet, $affiche) { |
| 761 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | - } else { |
|
| 765 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | - } |
|
| 767 | - $res2 = ''; |
|
| 768 | - |
|
| 769 | - if ($affiche == 'resultat') { |
|
| 770 | - $legend = $nom; |
|
| 771 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | - if (function_exists('_mysql_traite_query')) { |
|
| 773 | - $c = strtolower(_request('connect')); |
|
| 774 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | - $req = _mysql_traite_query($req, '', $c); |
|
| 776 | - } |
|
| 777 | - // permettre le copier/coller facile |
|
| 778 | - // $res = ancre_texte($req, array(), true); |
|
| 779 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | - // formatage et affichage des resultats bruts de la requete |
|
| 781 | - $ress_req = spip_query($req); |
|
| 782 | - $brut_sql = ''; |
|
| 783 | - $num = 1; |
|
| 784 | - // eviter l'affichage de milliers de lignes |
|
| 785 | - // personnalisation possible dans mes_options |
|
| 786 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | - if ($num <= $max_aff) { |
|
| 789 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | - $brut_sql .= '<p>'; |
|
| 791 | - foreach ($retours_sql as $key => $val) { |
|
| 792 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | - } |
|
| 794 | - $brut_sql .= '</p>'; |
|
| 795 | - } |
|
| 796 | - $num++; |
|
| 797 | - } |
|
| 798 | - $res2 = interdire_scripts($brut_sql); |
|
| 799 | - foreach ($quoi as $view) { |
|
| 800 | - // ne pas afficher les $contexte_inclus |
|
| 801 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | - if ($view) { |
|
| 803 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - } elseif ($affiche == 'code') { |
|
| 807 | - $legend = $nom; |
|
| 808 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | - } elseif ($affiche == 'boucle') { |
|
| 810 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | - } elseif ($affiche == 'squelette') { |
|
| 815 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - return [$legend, $res, $res2]; |
|
| 761 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 762 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 763 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 764 | + } else { |
|
| 765 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 766 | + } |
|
| 767 | + $res2 = ''; |
|
| 768 | + |
|
| 769 | + if ($affiche == 'resultat') { |
|
| 770 | + $legend = $nom; |
|
| 771 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 772 | + if (function_exists('_mysql_traite_query')) { |
|
| 773 | + $c = strtolower(_request('connect')); |
|
| 774 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 775 | + $req = _mysql_traite_query($req, '', $c); |
|
| 776 | + } |
|
| 777 | + // permettre le copier/coller facile |
|
| 778 | + // $res = ancre_texte($req, array(), true); |
|
| 779 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 780 | + // formatage et affichage des resultats bruts de la requete |
|
| 781 | + $ress_req = spip_query($req); |
|
| 782 | + $brut_sql = ''; |
|
| 783 | + $num = 1; |
|
| 784 | + // eviter l'affichage de milliers de lignes |
|
| 785 | + // personnalisation possible dans mes_options |
|
| 786 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 787 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 788 | + if ($num <= $max_aff) { |
|
| 789 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 790 | + $brut_sql .= '<p>'; |
|
| 791 | + foreach ($retours_sql as $key => $val) { |
|
| 792 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 793 | + } |
|
| 794 | + $brut_sql .= '</p>'; |
|
| 795 | + } |
|
| 796 | + $num++; |
|
| 797 | + } |
|
| 798 | + $res2 = interdire_scripts($brut_sql); |
|
| 799 | + foreach ($quoi as $view) { |
|
| 800 | + // ne pas afficher les $contexte_inclus |
|
| 801 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 802 | + if ($view) { |
|
| 803 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + } elseif ($affiche == 'code') { |
|
| 807 | + $legend = $nom; |
|
| 808 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 809 | + } elseif ($affiche == 'boucle') { |
|
| 810 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 811 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 812 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 813 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 814 | + } elseif ($affiche == 'squelette') { |
|
| 815 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 816 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + return [$legend, $res, $res2]; |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // https://code.spip.net/@debusquer_entete |
| 823 | 823 | function debusquer_entete($titre, $corps) { |
| 824 | 824 | |
| 825 | - include_spip('balise/formulaire_admin'); |
|
| 826 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | - |
|
| 829 | - return _DOCTYPE_ECRIRE . |
|
| 830 | - html_lang_attributes() . |
|
| 831 | - "<head>\n<title>" . |
|
| 832 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | - ")</title>\n" . |
|
| 836 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | - "' />\n" . |
|
| 839 | - http_script('', 'jquery.js') |
|
| 840 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | - . "' type='text/css' />" . |
|
| 842 | - "</head>\n" . |
|
| 843 | - "<body style='margin:0 10px;'>\n" . |
|
| 844 | - "<div id='spip-debug-header'>" . |
|
| 845 | - $corps . |
|
| 846 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | - '</div></body></html>'; |
|
| 825 | + include_spip('balise/formulaire_admin'); |
|
| 826 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 827 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 828 | + |
|
| 829 | + return _DOCTYPE_ECRIRE . |
|
| 830 | + html_lang_attributes() . |
|
| 831 | + "<head>\n<title>" . |
|
| 832 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 833 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 834 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 835 | + ")</title>\n" . |
|
| 836 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 837 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 838 | + "' />\n" . |
|
| 839 | + http_script('', 'jquery.js') |
|
| 840 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 841 | + . "' type='text/css' />" . |
|
| 842 | + "</head>\n" . |
|
| 843 | + "<body style='margin:0 10px;'>\n" . |
|
| 844 | + "<div id='spip-debug-header'>" . |
|
| 845 | + $corps . |
|
| 846 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 847 | + '</div></body></html>'; |
|
| 848 | 848 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | - // (recursion possible a cause des modeles) |
|
| 62 | - if ($debug) { |
|
| 63 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // charger le squelette en specifiant les langages cibles et source |
|
| 68 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | - |
|
| 70 | - if (!$composer) { |
|
| 71 | - $composer = charger_fonction('composer', 'public'); |
|
| 72 | - } |
|
| 73 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | - } else { |
|
| 75 | - $fonc = ''; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | - $page = $fonc; |
|
| 80 | - } else { |
|
| 81 | - // Preparer l'appel de la fonction principale du squelette |
|
| 82 | - |
|
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | - |
|
| 85 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | - // et on enregistre l'etat courant des globales de notes... |
|
| 87 | - if (is_null($notes)) { |
|
| 88 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | - } |
|
| 90 | - if ($notes) { |
|
| 91 | - $notes('', 'empiler'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Rajouter d'office ces deux parametres |
|
| 95 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | - if (!isset($contexte['date'])) { |
|
| 98 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | - $contexte['date_default'] = true; |
|
| 100 | - } else { |
|
| 101 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!isset($contexte['date_redac'])) { |
|
| 105 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | - $contexte['date_redac_default'] = true; |
|
| 107 | - } else { |
|
| 108 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | - try { |
|
| 113 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | - } catch (Throwable $e) { |
|
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | - $corps = "<pre>$msg</pre>"; |
|
| 119 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | - erreur_squelette($full_msg); |
|
| 121 | - unset($msg, $full_msg, $corps); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | - if ($notes) { |
|
| 130 | - $notes('', 'depiler'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // reinjecter en dynamique la pile des notes |
|
| 134 | - // si il y a des inclure dynamiques |
|
| 135 | - // si la pile n'est pas vide |
|
| 136 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | - if ($notes) { |
|
| 139 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // spip_log: un joli contexte |
|
| 143 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | - |
|
| 145 | - $profile = spip_timer($a); |
|
| 146 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | - |
|
| 149 | - if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ($debug) { |
|
| 155 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | - if ( |
|
| 161 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | + // (recursion possible a cause des modeles) |
|
| 62 | + if ($debug) { |
|
| 63 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // charger le squelette en specifiant les langages cibles et source |
|
| 68 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | + |
|
| 70 | + if (!$composer) { |
|
| 71 | + $composer = charger_fonction('composer', 'public'); |
|
| 72 | + } |
|
| 73 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | + } else { |
|
| 75 | + $fonc = ''; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | + $page = $fonc; |
|
| 80 | + } else { |
|
| 81 | + // Preparer l'appel de la fonction principale du squelette |
|
| 82 | + |
|
| 83 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + |
|
| 85 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | + // et on enregistre l'etat courant des globales de notes... |
|
| 87 | + if (is_null($notes)) { |
|
| 88 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | + } |
|
| 90 | + if ($notes) { |
|
| 91 | + $notes('', 'empiler'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Rajouter d'office ces deux parametres |
|
| 95 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | + if (!isset($contexte['date'])) { |
|
| 98 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | + $contexte['date_default'] = true; |
|
| 100 | + } else { |
|
| 101 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!isset($contexte['date_redac'])) { |
|
| 105 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | + $contexte['date_redac_default'] = true; |
|
| 107 | + } else { |
|
| 108 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | + try { |
|
| 113 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | + } catch (Throwable $e) { |
|
| 115 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | + $corps = "<pre>$msg</pre>"; |
|
| 119 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | + erreur_squelette($full_msg); |
|
| 121 | + unset($msg, $full_msg, $corps); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | + if ($notes) { |
|
| 130 | + $notes('', 'depiler'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // reinjecter en dynamique la pile des notes |
|
| 134 | + // si il y a des inclure dynamiques |
|
| 135 | + // si la pile n'est pas vide |
|
| 136 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | + if ($notes) { |
|
| 139 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // spip_log: un joli contexte |
|
| 143 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | + |
|
| 145 | + $profile = spip_timer($a); |
|
| 146 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + |
|
| 149 | + if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ($debug) { |
|
| 155 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | + if ( |
|
| 161 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,33 +210,33 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = []; |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = get_class($val); |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr($val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } |
|
| 237 | - $infos[] = $var . '=' . $val; |
|
| 238 | - } |
|
| 239 | - return join(', ', $infos); |
|
| 213 | + $infos = []; |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = get_class($val); |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr($val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } |
|
| 237 | + $infos[] = $var . '=' . $val; |
|
| 238 | + } |
|
| 239 | + return join(', ', $infos); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @return array|bool |
| 254 | 254 | */ |
| 255 | 255 | function tester_redirection($fond, $contexte, $connect) { |
| 256 | - static $tester_redirection = null; |
|
| 257 | - if (is_null($tester_redirection)) { |
|
| 258 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | - } |
|
| 260 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 256 | + static $tester_redirection = null; |
|
| 257 | + if (is_null($tester_redirection)) { |
|
| 258 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | + } |
|
| 260 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -273,42 +273,42 @@ discard block |
||
| 273 | 273 | * @return array|bool |
| 274 | 274 | */ |
| 275 | 275 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 276 | - if ( |
|
| 277 | - $fond == 'article' |
|
| 278 | - and !empty($contexte['id_article']) |
|
| 279 | - and $id_article = intval($contexte['id_article']) |
|
| 280 | - ) { |
|
| 281 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 282 | - $m = quete_virtuel($id_article, $connect); |
|
| 283 | - if (strlen($m)) { |
|
| 284 | - include_spip('inc/texte'); |
|
| 285 | - // les navigateurs pataugent si l'URL est vide |
|
| 286 | - if ($url = virtuel_redirige($m, true)) { |
|
| 287 | - // passer en url absolue car cette redirection pourra |
|
| 288 | - // etre utilisee dans un contexte d'url qui change |
|
| 289 | - // y compris url arbo |
|
| 290 | - $status = 302; |
|
| 291 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 292 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 293 | - } |
|
| 294 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 295 | - include_spip('inc/filtres_mini'); |
|
| 296 | - $url = url_absolue($url); |
|
| 297 | - } |
|
| 298 | - $url = str_replace('&', '&', $url); |
|
| 299 | - |
|
| 300 | - return [ |
|
| 301 | - 'texte' => '<' |
|
| 302 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 303 | - . texte_script($url) |
|
| 304 | - . "','',$status);" |
|
| 305 | - . '?' . '>', |
|
| 306 | - 'process_ins' => 'php', |
|
| 307 | - 'status' => $status |
|
| 308 | - ]; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return false; |
|
| 276 | + if ( |
|
| 277 | + $fond == 'article' |
|
| 278 | + and !empty($contexte['id_article']) |
|
| 279 | + and $id_article = intval($contexte['id_article']) |
|
| 280 | + ) { |
|
| 281 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 282 | + $m = quete_virtuel($id_article, $connect); |
|
| 283 | + if (strlen($m)) { |
|
| 284 | + include_spip('inc/texte'); |
|
| 285 | + // les navigateurs pataugent si l'URL est vide |
|
| 286 | + if ($url = virtuel_redirige($m, true)) { |
|
| 287 | + // passer en url absolue car cette redirection pourra |
|
| 288 | + // etre utilisee dans un contexte d'url qui change |
|
| 289 | + // y compris url arbo |
|
| 290 | + $status = 302; |
|
| 291 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 292 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 293 | + } |
|
| 294 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 295 | + include_spip('inc/filtres_mini'); |
|
| 296 | + $url = url_absolue($url); |
|
| 297 | + } |
|
| 298 | + $url = str_replace('&', '&', $url); |
|
| 299 | + |
|
| 300 | + return [ |
|
| 301 | + 'texte' => '<' |
|
| 302 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 303 | + . texte_script($url) |
|
| 304 | + . "','',$status);" |
|
| 305 | + . '?' . '>', |
|
| 306 | + 'process_ins' => 'php', |
|
| 307 | + 'status' => $status |
|
| 308 | + ]; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return false; |
|
| 314 | 314 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } else { |
| 81 | 81 | // Preparer l'appel de la fonction principale du squelette |
| 82 | 82 | |
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 83 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 84 | 84 | |
| 85 | 85 | // On cree un marqueur de notes unique lie a cette composition |
| 86 | 86 | // et on enregistre l'etat courant des globales de notes... |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | try { |
| 113 | 113 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 114 | 114 | } catch (Throwable $e) { |
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 116 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 117 | 117 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 118 | 118 | $corps = "<pre>$msg</pre>"; |
| 119 | 119 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $profile = spip_timer($a); |
| 146 | 146 | spip_log("calcul ($profile) [$skel] $infos" |
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 148 | 148 | |
| 149 | 149 | if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
| 150 | 150 | spip_log("calcul ($profile) [$skel] $infos" |
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | + . ' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($debug) { |
| 155 | 155 | // si c'est ce que demande le debusqueur, lui passer la main |
| 156 | 156 | $t = strlen($page['texte']) ? $page['texte'] : ' '; |
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 158 | 158 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 159 | 159 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 160 | 160 | if ( |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 189 | 189 | . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -220,21 +220,21 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | if (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = get_class($val); |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
| 234 | 234 | } elseif (strstr($val, ' ')) { |
| 235 | 235 | $val = "'$val'"; |
| 236 | 236 | } |
| 237 | - $infos[] = $var . '=' . $val; |
|
| 237 | + $infos[] = $var.'='.$val; |
|
| 238 | 238 | } |
| 239 | 239 | return join(', ', $infos); |
| 240 | 240 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 303 | 303 | . texte_script($url) |
| 304 | 304 | . "','',$status);" |
| 305 | - . '?' . '>', |
|
| 305 | + . '?'.'>', |
|
| 306 | 306 | 'process_ins' => 'php', |
| 307 | 307 | 'status' => $status |
| 308 | 308 | ]; |
@@ -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 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -59,92 +59,92 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // https://code.spip.net/@argumenter_inclure |
| 61 | 61 | function argumenter_inclure( |
| 62 | - $params, |
|
| 63 | - $rejet_filtres, |
|
| 64 | - $p, |
|
| 65 | - &$boucles, |
|
| 66 | - $id_boucle, |
|
| 67 | - $echap = true, |
|
| 68 | - $lang = '', |
|
| 69 | - $fond1 = false |
|
| 62 | + $params, |
|
| 63 | + $rejet_filtres, |
|
| 64 | + $p, |
|
| 65 | + &$boucles, |
|
| 66 | + $id_boucle, |
|
| 67 | + $echap = true, |
|
| 68 | + $lang = '', |
|
| 69 | + $fond1 = false |
|
| 70 | 70 | ) { |
| 71 | - $l = []; |
|
| 72 | - $erreur_p_i_i = ''; |
|
| 73 | - if (!is_array($params)) { |
|
| 74 | - return $l; |
|
| 75 | - } |
|
| 76 | - foreach ($params as $k => $couple) { |
|
| 77 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | - $filtre = array_shift($couple); |
|
| 79 | - if ($filtre) { |
|
| 80 | - break; |
|
| 81 | - } |
|
| 82 | - foreach ($couple as $n => $val) { |
|
| 83 | - $var = $val[0]; |
|
| 84 | - if ($var->type != 'texte') { |
|
| 85 | - if ($n or $k or $fond1) { |
|
| 86 | - $erreur_p_i_i = [ |
|
| 87 | - 'zbug_parametres_inclus_incorrects', |
|
| 88 | - ['param' => $var->nom_champ] |
|
| 89 | - ]; |
|
| 90 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | - break; |
|
| 92 | - } else { |
|
| 93 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | - } |
|
| 95 | - } else { |
|
| 96 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | - $m = array_pad($m, 3, null); |
|
| 98 | - $var = $m[1]; |
|
| 99 | - $auto = false; |
|
| 71 | + $l = []; |
|
| 72 | + $erreur_p_i_i = ''; |
|
| 73 | + if (!is_array($params)) { |
|
| 74 | + return $l; |
|
| 75 | + } |
|
| 76 | + foreach ($params as $k => $couple) { |
|
| 77 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 78 | + $filtre = array_shift($couple); |
|
| 79 | + if ($filtre) { |
|
| 80 | + break; |
|
| 81 | + } |
|
| 82 | + foreach ($couple as $n => $val) { |
|
| 83 | + $var = $val[0]; |
|
| 84 | + if ($var->type != 'texte') { |
|
| 85 | + if ($n or $k or $fond1) { |
|
| 86 | + $erreur_p_i_i = [ |
|
| 87 | + 'zbug_parametres_inclus_incorrects', |
|
| 88 | + ['param' => $var->nom_champ] |
|
| 89 | + ]; |
|
| 90 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 91 | + break; |
|
| 92 | + } else { |
|
| 93 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 94 | + } |
|
| 95 | + } else { |
|
| 96 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 97 | + $m = array_pad($m, 3, null); |
|
| 98 | + $var = $m[1]; |
|
| 99 | + $auto = false; |
|
| 100 | 100 | ; |
| 101 | - if ($m[2]) { |
|
| 102 | - $v = $m[3]; |
|
| 103 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | - $v = $m[1]; |
|
| 105 | - } |
|
| 106 | - $val[0] = new Texte(); |
|
| 107 | - $val[0]->texte = $v; |
|
| 108 | - } elseif ($k or $n or $fond1) { |
|
| 109 | - $auto = true; |
|
| 110 | - } else { |
|
| 111 | - $var = 1; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($var == 'lang') { |
|
| 115 | - $lang = !$auto |
|
| 116 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | - : '$GLOBALS["spip_lang"]'; |
|
| 118 | - } else { |
|
| 119 | - $val = $auto |
|
| 120 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | - if ($var !== 1) { |
|
| 123 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 125 | - } else { |
|
| 126 | - $val = $echap ? "'.$val.'" : $val; |
|
| 127 | - } |
|
| 128 | - $l[$var] = $val; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($erreur_p_i_i) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | - // sauf si on n'en veut pas |
|
| 139 | - if ($lang === false) { |
|
| 140 | - return $l; |
|
| 141 | - } |
|
| 142 | - if (!$lang) { |
|
| 143 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | - } |
|
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | - |
|
| 147 | - return $l; |
|
| 101 | + if ($m[2]) { |
|
| 102 | + $v = $m[3]; |
|
| 103 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | + $v = $m[1]; |
|
| 105 | + } |
|
| 106 | + $val[0] = new Texte(); |
|
| 107 | + $val[0]->texte = $v; |
|
| 108 | + } elseif ($k or $n or $fond1) { |
|
| 109 | + $auto = true; |
|
| 110 | + } else { |
|
| 111 | + $var = 1; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($var == 'lang') { |
|
| 115 | + $lang = !$auto |
|
| 116 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | + : '$GLOBALS["spip_lang"]'; |
|
| 118 | + } else { |
|
| 119 | + $val = $auto |
|
| 120 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | + if ($var !== 1) { |
|
| 123 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | + . $val . ($echap ? ") . '" : ' '); |
|
| 125 | + } else { |
|
| 126 | + $val = $echap ? "'.$val.'" : $val; |
|
| 127 | + } |
|
| 128 | + $l[$var] = $val; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($erreur_p_i_i) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | + // sauf si on n'en veut pas |
|
| 139 | + if ($lang === false) { |
|
| 140 | + return $l; |
|
| 141 | + } |
|
| 142 | + if (!$lang) { |
|
| 143 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | + } |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 146 | + |
|
| 147 | + return $l; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,83 +168,83 @@ discard block |
||
| 168 | 168 | **/ |
| 169 | 169 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 170 | 170 | |
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - '_request("connect")' |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + '_request("connect")' |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,173 +478,173 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $boucle = &$boucles[$id_boucle]; |
|
| 482 | - $return = $boucle->return; |
|
| 483 | - $type_boucle = $boucle->type_requete; |
|
| 484 | - $primary = $boucle->primary; |
|
| 485 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | - $corps = ''; |
|
| 488 | - |
|
| 489 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | - // et puis faire un [] plutot qu'un "','." |
|
| 491 | - if ($boucle->doublons) { |
|
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | - index_pile($id_boucle, $primary, $boucles) |
|
| 494 | - . "; // doublons\n"; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - // La boucle doit-elle selectionner la langue ? |
|
| 498 | - // - par defaut, les boucles suivantes le font |
|
| 499 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | - if ( |
|
| 502 | - !$constant && $boucle->lang_select != 'non' && |
|
| 503 | - (($boucle->lang_select == 'oui') || |
|
| 504 | - in_array($type_boucle, [ |
|
| 505 | - 'articles', |
|
| 506 | - 'rubriques', |
|
| 507 | - 'hierarchie', |
|
| 508 | - 'breves' |
|
| 509 | - ])) |
|
| 510 | - ) { |
|
| 511 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | - // afin que le corps de boucle affecte la globale directement |
|
| 513 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | - $fin_lang = "lang_select();\n\t"; |
|
| 515 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | - |
|
| 517 | - $corps .= |
|
| 518 | - "\n\t\tlang_select_public(" |
|
| 519 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 521 | - . (in_array($type_boucle, [ |
|
| 522 | - 'articles', |
|
| 523 | - 'rubriques', |
|
| 524 | - 'hierarchie', |
|
| 525 | - 'breves' |
|
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | - . ');'; |
|
| 528 | - } else { |
|
| 529 | - $init_lang = ''; |
|
| 530 | - $fin_lang = ''; |
|
| 531 | - $fin_lang_select_public = ''; |
|
| 532 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | - if ( |
|
| 534 | - strpos($return, '?php') === false |
|
| 535 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | - ) { |
|
| 537 | - $i = 1; |
|
| 538 | - foreach ($r[1] as $t) { |
|
| 539 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | - $return = str_replace($t, "\$l$i", $return); |
|
| 541 | - $i++; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // gestion optimale des separateurs et des boucles constantes |
|
| 547 | - if (count($boucle->separateur)) { |
|
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $corps .= |
|
| 552 | - ((!$boucle->separateur) ? |
|
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 557 | - ((strpos($return, '$t1.') === 0) ? |
|
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | - |
|
| 563 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | - // souhaite invalider ces elements |
|
| 565 | - if (!$constant and $primary) { |
|
| 566 | - include_spip('inc/invalideur'); |
|
| 567 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - // gerer le compteur de boucle |
|
| 571 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | - |
|
| 573 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | - . $boucle->partie |
|
| 576 | - . $corps; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // depiler la lang de la boucle si besoin |
|
| 580 | - $corps .= $fin_lang_select_public; |
|
| 581 | - |
|
| 582 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | - |
|
| 584 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | - if (!$boucle->numrows) { |
|
| 587 | - return "\n\t\$t0 = '';"; |
|
| 588 | - } else { |
|
| 589 | - $corps = ''; |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $boucle->numrows = true; |
|
| 593 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $count = ''; |
|
| 600 | - if (!$boucle->select) { |
|
| 601 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | - $count = '1'; |
|
| 603 | - } else { |
|
| 604 | - $count = 'count(*)'; |
|
| 605 | - } |
|
| 606 | - $boucles[$id_boucle]->select[] = $count; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if ($flag_cpt) { |
|
| 610 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | - } else { |
|
| 613 | - $nums = ''; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | - . $boucle->mode_partie |
|
| 620 | - . "\n\t"; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // Ne calculer la requete que maintenant |
|
| 624 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | - |
|
| 626 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | - ? ("\n\t$init = array();") : '') |
|
| 628 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | - |
|
| 630 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | - |
|
| 632 | - $a = sprintf( |
|
| 633 | - CODE_CORPS_BOUCLE, |
|
| 634 | - $init, |
|
| 635 | - $boucle->iterateur, |
|
| 636 | - '$command', |
|
| 637 | - $contexte, |
|
| 638 | - $nums, |
|
| 639 | - $init_lang, |
|
| 640 | - $corps, |
|
| 641 | - $fin_lang, |
|
| 642 | - $trace, |
|
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | - ); |
|
| 481 | + $boucle = &$boucles[$id_boucle]; |
|
| 482 | + $return = $boucle->return; |
|
| 483 | + $type_boucle = $boucle->type_requete; |
|
| 484 | + $primary = $boucle->primary; |
|
| 485 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 486 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 487 | + $corps = ''; |
|
| 488 | + |
|
| 489 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 490 | + // et puis faire un [] plutot qu'un "','." |
|
| 491 | + if ($boucle->doublons) { |
|
| 492 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | + index_pile($id_boucle, $primary, $boucles) |
|
| 494 | + . "; // doublons\n"; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + // La boucle doit-elle selectionner la langue ? |
|
| 498 | + // - par defaut, les boucles suivantes le font |
|
| 499 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 500 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 501 | + if ( |
|
| 502 | + !$constant && $boucle->lang_select != 'non' && |
|
| 503 | + (($boucle->lang_select == 'oui') || |
|
| 504 | + in_array($type_boucle, [ |
|
| 505 | + 'articles', |
|
| 506 | + 'rubriques', |
|
| 507 | + 'hierarchie', |
|
| 508 | + 'breves' |
|
| 509 | + ])) |
|
| 510 | + ) { |
|
| 511 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 512 | + // afin que le corps de boucle affecte la globale directement |
|
| 513 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 514 | + $fin_lang = "lang_select();\n\t"; |
|
| 515 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 516 | + |
|
| 517 | + $corps .= |
|
| 518 | + "\n\t\tlang_select_public(" |
|
| 519 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 520 | + . ", '" . $boucle->lang_select . "'" |
|
| 521 | + . (in_array($type_boucle, [ |
|
| 522 | + 'articles', |
|
| 523 | + 'rubriques', |
|
| 524 | + 'hierarchie', |
|
| 525 | + 'breves' |
|
| 526 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | + . ');'; |
|
| 528 | + } else { |
|
| 529 | + $init_lang = ''; |
|
| 530 | + $fin_lang = ''; |
|
| 531 | + $fin_lang_select_public = ''; |
|
| 532 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 533 | + if ( |
|
| 534 | + strpos($return, '?php') === false |
|
| 535 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 536 | + ) { |
|
| 537 | + $i = 1; |
|
| 538 | + foreach ($r[1] as $t) { |
|
| 539 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 540 | + $return = str_replace($t, "\$l$i", $return); |
|
| 541 | + $i++; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // gestion optimale des separateurs et des boucles constantes |
|
| 547 | + if (count($boucle->separateur)) { |
|
| 548 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $corps .= |
|
| 552 | + ((!$boucle->separateur) ? |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | + (($return === "''") ? '' : |
|
| 555 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | + ("\n\t\t\$t1 " . |
|
| 557 | + ((strpos($return, '$t1.') === 0) ? |
|
| 558 | + ('.=' . substr($return, 4)) : |
|
| 559 | + ('= ' . $return)) . |
|
| 560 | + ";\n\t\t" . |
|
| 561 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 562 | + |
|
| 563 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 564 | + // souhaite invalider ces elements |
|
| 565 | + if (!$constant and $primary) { |
|
| 566 | + include_spip('inc/invalideur'); |
|
| 567 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + // gerer le compteur de boucle |
|
| 571 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 572 | + |
|
| 573 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 574 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 575 | + . $boucle->partie |
|
| 576 | + . $corps; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // depiler la lang de la boucle si besoin |
|
| 580 | + $corps .= $fin_lang_select_public; |
|
| 581 | + |
|
| 582 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 583 | + |
|
| 584 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 585 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 586 | + if (!$boucle->numrows) { |
|
| 587 | + return "\n\t\$t0 = '';"; |
|
| 588 | + } else { |
|
| 589 | + $corps = ''; |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $boucle->numrows = true; |
|
| 593 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $count = ''; |
|
| 600 | + if (!$boucle->select) { |
|
| 601 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 602 | + $count = '1'; |
|
| 603 | + } else { |
|
| 604 | + $count = 'count(*)'; |
|
| 605 | + } |
|
| 606 | + $boucles[$id_boucle]->select[] = $count; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if ($flag_cpt) { |
|
| 610 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 611 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 612 | + } else { |
|
| 613 | + $nums = ''; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 617 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 618 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 619 | + . $boucle->mode_partie |
|
| 620 | + . "\n\t"; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // Ne calculer la requete que maintenant |
|
| 624 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 625 | + |
|
| 626 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 627 | + ? ("\n\t$init = array();") : '') |
|
| 628 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 629 | + |
|
| 630 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 631 | + |
|
| 632 | + $a = sprintf( |
|
| 633 | + CODE_CORPS_BOUCLE, |
|
| 634 | + $init, |
|
| 635 | + $boucle->iterateur, |
|
| 636 | + '$command', |
|
| 637 | + $contexte, |
|
| 638 | + $nums, |
|
| 639 | + $init_lang, |
|
| 640 | + $corps, |
|
| 641 | + $fin_lang, |
|
| 642 | + $trace, |
|
| 643 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 644 | + ); |
|
| 645 | 645 | |
| 646 | 646 | # var_dump($a);exit; |
| 647 | - return $a; |
|
| 647 | + return $a; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | |
@@ -660,47 +660,47 @@ discard block |
||
| 660 | 660 | * Code PHP compilé définissant les informations de requête |
| 661 | 661 | **/ |
| 662 | 662 | function calculer_requete_sql($boucle) { |
| 663 | - $init = []; |
|
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | - # En absence de champ c'est un decompte : |
|
| 667 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | - $init[] = calculer_dec( |
|
| 670 | - 'groupby', |
|
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | - ); |
|
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | - $init[] = calculer_dec( |
|
| 678 | - 'limit', |
|
| 679 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 680 | - "'" . $boucle->limit . "'" |
|
| 681 | - : |
|
| 682 | - $boucle->limit) |
|
| 683 | - ); |
|
| 684 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 685 | - $s = $d = ''; |
|
| 686 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 687 | - // ou recalculée à chaque passage (vide) |
|
| 688 | - foreach ($init as $i) { |
|
| 689 | - if (reset($i)) { |
|
| 690 | - $s .= "\n\t\t" . end($i); |
|
| 691 | - } # statique |
|
| 692 | - else { |
|
| 693 | - $d .= "\n\t" . end($i); |
|
| 694 | - } # dynamique |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 698 | - . $boucle->in |
|
| 699 | - . $boucle->hash |
|
| 700 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 701 | - . $s |
|
| 702 | - . "\n\t}" |
|
| 703 | - . $d; |
|
| 663 | + $init = []; |
|
| 664 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 666 | + # En absence de champ c'est un decompte : |
|
| 667 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 668 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 669 | + $init[] = calculer_dec( |
|
| 670 | + 'groupby', |
|
| 671 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 672 | + ); |
|
| 673 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 675 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 676 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 677 | + $init[] = calculer_dec( |
|
| 678 | + 'limit', |
|
| 679 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 680 | + "'" . $boucle->limit . "'" |
|
| 681 | + : |
|
| 682 | + $boucle->limit) |
|
| 683 | + ); |
|
| 684 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 685 | + $s = $d = ''; |
|
| 686 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 687 | + // ou recalculée à chaque passage (vide) |
|
| 688 | + foreach ($init as $i) { |
|
| 689 | + if (reset($i)) { |
|
| 690 | + $s .= "\n\t\t" . end($i); |
|
| 691 | + } # statique |
|
| 692 | + else { |
|
| 693 | + $d .= "\n\t" . end($i); |
|
| 694 | + } # dynamique |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 698 | + . $boucle->in |
|
| 699 | + . $boucle->hash |
|
| 700 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 701 | + . $s |
|
| 702 | + . "\n\t}" |
|
| 703 | + . $d; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | /** |
@@ -718,13 +718,13 @@ discard block |
||
| 718 | 718 | * qui peut être utilisé pour la production d'un tableau array() |
| 719 | 719 | **/ |
| 720 | 720 | function memoriser_contexte_compil($p) { |
| 721 | - return join(',', [ |
|
| 722 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 723 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 724 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 725 | - intval($p->ligne), |
|
| 726 | - '$GLOBALS[\'spip_lang\']' |
|
| 727 | - ]); |
|
| 721 | + return join(',', [ |
|
| 722 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 723 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 724 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 725 | + intval($p->ligne), |
|
| 726 | + '$GLOBALS[\'spip_lang\']' |
|
| 727 | + ]); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -742,19 +742,19 @@ discard block |
||
| 742 | 742 | * Objet Contexte |
| 743 | 743 | **/ |
| 744 | 744 | function reconstruire_contexte_compil($context_compil) { |
| 745 | - if (!is_array($context_compil)) { |
|
| 746 | - return $context_compil; |
|
| 747 | - } |
|
| 748 | - $p = new Contexte(); |
|
| 749 | - $p->descr = [ |
|
| 750 | - 'sourcefile' => $context_compil[0], |
|
| 751 | - 'nom' => $context_compil[1] |
|
| 752 | - ]; |
|
| 753 | - $p->id_boucle = $context_compil[2]; |
|
| 754 | - $p->ligne = $context_compil[3]; |
|
| 755 | - $p->lang = $context_compil[4]; |
|
| 756 | - |
|
| 757 | - return $p; |
|
| 745 | + if (!is_array($context_compil)) { |
|
| 746 | + return $context_compil; |
|
| 747 | + } |
|
| 748 | + $p = new Contexte(); |
|
| 749 | + $p->descr = [ |
|
| 750 | + 'sourcefile' => $context_compil[0], |
|
| 751 | + 'nom' => $context_compil[1] |
|
| 752 | + ]; |
|
| 753 | + $p->id_boucle = $context_compil[2]; |
|
| 754 | + $p->ligne = $context_compil[3]; |
|
| 755 | + $p->lang = $context_compil[4]; |
|
| 756 | + |
|
| 757 | + return $p; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
@@ -780,12 +780,12 @@ discard block |
||
| 780 | 780 | * - index 1 : Code de l'affectation |
| 781 | 781 | **/ |
| 782 | 782 | function calculer_dec($nom, $val) { |
| 783 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 784 | - // si une variable apparait dans le calcul de la clause |
|
| 785 | - // il faut la re-evaluer a chaque passage |
|
| 786 | - if ( |
|
| 787 | - strpos($val, '$') !== false |
|
| 788 | - /* |
|
| 783 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 784 | + // si une variable apparait dans le calcul de la clause |
|
| 785 | + // il faut la re-evaluer a chaque passage |
|
| 786 | + if ( |
|
| 787 | + strpos($val, '$') !== false |
|
| 788 | + /* |
|
| 789 | 789 | OR strpos($val, 'sql_') !== false |
| 790 | 790 | OR ( |
| 791 | 791 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 794 | 794 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 795 | 795 | )*/ |
| 796 | - ) { |
|
| 797 | - $static = ''; |
|
| 798 | - } |
|
| 796 | + ) { |
|
| 797 | + $static = ''; |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 800 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -817,33 +817,33 @@ discard block |
||
| 817 | 817 | * Expression PHP décrivant un texte ou un tableau |
| 818 | 818 | **/ |
| 819 | 819 | function calculer_dump_array($a) { |
| 820 | - if (!is_array($a)) { |
|
| 821 | - return $a; |
|
| 822 | - } |
|
| 823 | - $res = ''; |
|
| 824 | - if ($a and $a[0] == "'?'") { |
|
| 825 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 828 | - ')'); |
|
| 829 | - } else { |
|
| 830 | - foreach ($a as $k => $v) { |
|
| 831 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 836 | - } |
|
| 820 | + if (!is_array($a)) { |
|
| 821 | + return $a; |
|
| 822 | + } |
|
| 823 | + $res = ''; |
|
| 824 | + if ($a and $a[0] == "'?'") { |
|
| 825 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 828 | + ')'); |
|
| 829 | + } else { |
|
| 830 | + foreach ($a as $k => $v) { |
|
| 831 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 836 | + } |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | // https://code.spip.net/@calculer_dump_join |
| 840 | 840 | function calculer_dump_join($a) { |
| 841 | - $res = ''; |
|
| 842 | - foreach ($a as $k => $v) { |
|
| 843 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 844 | - } |
|
| 841 | + $res = ''; |
|
| 842 | + foreach ($a as $k => $v) { |
|
| 843 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | - return 'array(' . substr($res, 2) . ')'; |
|
| 846 | + return 'array(' . substr($res, 2) . ')'; |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -855,12 +855,12 @@ discard block |
||
| 855 | 855 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 856 | 856 | **/ |
| 857 | 857 | function calculer_from(&$boucle) { |
| 858 | - $res = ''; |
|
| 859 | - foreach ($boucle->from as $k => $v) { |
|
| 860 | - $res .= ",'$k' => '$v'"; |
|
| 861 | - } |
|
| 858 | + $res = ''; |
|
| 859 | + foreach ($boucle->from as $k => $v) { |
|
| 860 | + $res .= ",'$k' => '$v'"; |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - return 'array(' . substr($res, 1) . ')'; |
|
| 863 | + return 'array(' . substr($res, 1) . ')'; |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | /** |
@@ -873,31 +873,31 @@ discard block |
||
| 873 | 873 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 874 | 874 | **/ |
| 875 | 875 | function calculer_from_type(&$boucle) { |
| 876 | - $res = ''; |
|
| 877 | - foreach ($boucle->from_type as $k => $v) { |
|
| 878 | - $res .= ",'$k' => '$v'"; |
|
| 879 | - } |
|
| 876 | + $res = ''; |
|
| 877 | + foreach ($boucle->from_type as $k => $v) { |
|
| 878 | + $res .= ",'$k' => '$v'"; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - return 'array(' . substr($res, 1) . ')'; |
|
| 881 | + return 'array(' . substr($res, 1) . ')'; |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | // https://code.spip.net/@calculer_order |
| 885 | 885 | function calculer_order(&$boucle) { |
| 886 | - if ( |
|
| 887 | - !$order = $boucle->order |
|
| 888 | - and !$order = $boucle->default_order |
|
| 889 | - ) { |
|
| 890 | - $order = []; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 886 | + if ( |
|
| 887 | + !$order = $boucle->order |
|
| 888 | + and !$order = $boucle->default_order |
|
| 889 | + ) { |
|
| 890 | + $order = []; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 894 | 894 | $col = "." . $boucle->modificateur['collate']; |
| 895 | 895 | foreach($order as $k=>$o) |
| 896 | 896 | if (strpos($order[$k],'COLLATE')===false) |
| 897 | 897 | $order[$k].= $col; |
| 898 | 898 | }*/ |
| 899 | 899 | |
| 900 | - return join(', ', $order); |
|
| 900 | + return join(', ', $order); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -907,62 +907,62 @@ discard block |
||
| 907 | 907 | |
| 908 | 908 | // https://code.spip.net/@calculer_liste |
| 909 | 909 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 910 | - if (!$tableau) { |
|
| 911 | - return "''"; |
|
| 912 | - } |
|
| 913 | - if (is_string($descr)) { |
|
| 914 | - if (isset($boucles[$descr])) { |
|
| 915 | - $idb = $descr; |
|
| 916 | - $descr = []; |
|
| 917 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | - } |
|
| 920 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - else { |
|
| 925 | - $descr = []; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - if (!isset($descr['niv'])) { |
|
| 929 | - $descr['niv'] = 0; |
|
| 930 | - } |
|
| 931 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | - if ($codes === false) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - $n = count($codes); |
|
| 936 | - if (!$n) { |
|
| 937 | - return "''"; |
|
| 938 | - } |
|
| 939 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | - if ($n == 1) { |
|
| 942 | - return $codes[0]; |
|
| 943 | - } else { |
|
| 944 | - $res = ''; |
|
| 945 | - foreach ($codes as $code) { |
|
| 946 | - if ( |
|
| 947 | - !preg_match("/^'[^']*'$/", $code) |
|
| 948 | - or substr($res, -1, 1) !== "'" |
|
| 949 | - ) { |
|
| 950 | - $res .= " .\n$tab$code"; |
|
| 951 | - } else { |
|
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | - } |
|
| 958 | - } else { |
|
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | - |
|
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | - " ,\n$tab", |
|
| 963 | - $codes |
|
| 964 | - ) . ')))'; |
|
| 965 | - } |
|
| 910 | + if (!$tableau) { |
|
| 911 | + return "''"; |
|
| 912 | + } |
|
| 913 | + if (is_string($descr)) { |
|
| 914 | + if (isset($boucles[$descr])) { |
|
| 915 | + $idb = $descr; |
|
| 916 | + $descr = []; |
|
| 917 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | + } |
|
| 920 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + else { |
|
| 925 | + $descr = []; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + if (!isset($descr['niv'])) { |
|
| 929 | + $descr['niv'] = 0; |
|
| 930 | + } |
|
| 931 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | + if ($codes === false) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + $n = count($codes); |
|
| 936 | + if (!$n) { |
|
| 937 | + return "''"; |
|
| 938 | + } |
|
| 939 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | + if ($n == 1) { |
|
| 942 | + return $codes[0]; |
|
| 943 | + } else { |
|
| 944 | + $res = ''; |
|
| 945 | + foreach ($codes as $code) { |
|
| 946 | + if ( |
|
| 947 | + !preg_match("/^'[^']*'$/", $code) |
|
| 948 | + or substr($res, -1, 1) !== "'" |
|
| 949 | + ) { |
|
| 950 | + $res .= " .\n$tab$code"; |
|
| 951 | + } else { |
|
| 952 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | + } |
|
| 958 | + } else { |
|
| 959 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | + |
|
| 961 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | + " ,\n$tab", |
|
| 963 | + $codes |
|
| 964 | + ) . ')))'; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | |
@@ -973,213 +973,213 @@ discard block |
||
| 973 | 973 | // https://code.spip.net/@compile_cas |
| 974 | 974 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 975 | 975 | |
| 976 | - $codes = []; |
|
| 977 | - // cas de la boucle recursive |
|
| 978 | - if (is_array($id_boucle)) { |
|
| 979 | - $id_boucle = $id_boucle[0]; |
|
| 980 | - } |
|
| 981 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 982 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 983 | - $mode = _request('var_mode_affiche'); |
|
| 984 | - $err_e_c = ''; |
|
| 985 | - // chaque commentaire introduit dans le code doit commencer |
|
| 986 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 987 | - foreach ($tableau as $p) { |
|
| 988 | - switch ($p->type) { |
|
| 989 | - // texte seul |
|
| 990 | - case 'texte': |
|
| 991 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 992 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 993 | - $avant = ''; |
|
| 994 | - $apres = ''; |
|
| 995 | - $altern = "''"; |
|
| 996 | - break; |
|
| 997 | - |
|
| 998 | - case 'polyglotte': |
|
| 999 | - $code = ''; |
|
| 1000 | - foreach ($p->traductions as $k => $v) { |
|
| 1001 | - $code .= ",'" . |
|
| 1002 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | - "' => '" . |
|
| 1004 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1005 | - "'"; |
|
| 1006 | - } |
|
| 1007 | - $code = 'choisir_traduction(array(' . |
|
| 1008 | - substr($code, 1) . |
|
| 1009 | - '))'; |
|
| 1010 | - $commentaire = '&'; |
|
| 1011 | - $avant = ''; |
|
| 1012 | - $apres = ''; |
|
| 1013 | - $altern = "''"; |
|
| 1014 | - break; |
|
| 1015 | - |
|
| 1016 | - // inclure |
|
| 1017 | - case 'include': |
|
| 1018 | - $p->descr = $descr; |
|
| 1019 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1020 | - if ($code === false) { |
|
| 1021 | - $err_e_c = true; |
|
| 1022 | - $code = "''"; |
|
| 1023 | - } else { |
|
| 1024 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1025 | - $avant = ''; |
|
| 1026 | - $apres = ''; |
|
| 1027 | - $altern = "''"; |
|
| 1028 | - } |
|
| 1029 | - break; |
|
| 1030 | - |
|
| 1031 | - // boucle |
|
| 1032 | - case TYPE_RECURSIF: |
|
| 1033 | - $nom = $p->id_boucle; |
|
| 1034 | - $newdescr = $descr; |
|
| 1035 | - $newdescr['id_mere'] = $nom; |
|
| 1036 | - $newdescr['niv']++; |
|
| 1037 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1038 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1039 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1040 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1041 | - $newdescr['niv']--; |
|
| 1042 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1043 | - if ( |
|
| 1044 | - $preaff === false |
|
| 1045 | - or $avant === false |
|
| 1046 | - or $apres === false |
|
| 1047 | - or $altern === false |
|
| 1048 | - or $postaff === false |
|
| 1049 | - ) { |
|
| 1050 | - $err_e_c = true; |
|
| 1051 | - $code = "''"; |
|
| 1052 | - } else { |
|
| 1053 | - $code = 'BOUCLE' . |
|
| 1054 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1055 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1056 | - $commentaire = "?$nom"; |
|
| 1057 | - if ( |
|
| 1058 | - !$boucles[$nom]->milieu |
|
| 1059 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1060 | - ) { |
|
| 1061 | - if ($preaff != "''") { |
|
| 1062 | - $code .= "\n. $preaff"; |
|
| 1063 | - } |
|
| 1064 | - if ($altern != "''") { |
|
| 1065 | - $code .= "\n. $altern"; |
|
| 1066 | - } |
|
| 1067 | - if ($postaff != "''") { |
|
| 1068 | - $code .= "\n. $postaff"; |
|
| 1069 | - } |
|
| 1070 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1071 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1072 | - } |
|
| 1073 | - $avant = $apres = $altern = "''"; |
|
| 1074 | - } else { |
|
| 1075 | - if ($preaff != "''") { |
|
| 1076 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1077 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1078 | - } |
|
| 1079 | - if ($postaff != "''") { |
|
| 1080 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1081 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1082 | - } |
|
| 1083 | - if ($altern != "''") { |
|
| 1084 | - $altern = "($altern)"; |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - } |
|
| 1088 | - break; |
|
| 1089 | - |
|
| 1090 | - case 'idiome': |
|
| 1091 | - $l = []; |
|
| 1092 | - $code = ''; |
|
| 1093 | - foreach ($p->arg as $k => $v) { |
|
| 1094 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1095 | - if ($k) { |
|
| 1096 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1097 | - } else { |
|
| 1098 | - $code = $_v; |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1102 | - if ($p->module) { |
|
| 1103 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1104 | - } elseif ($p->nom_champ) { |
|
| 1105 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1106 | - } else { |
|
| 1107 | - $m = ''; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - $code = (!$code ? "'$m'" : |
|
| 1111 | - ($m ? "'$m' . $code" : |
|
| 1112 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1114 | - $code = "_T($code)"; |
|
| 1115 | - if ($p->param) { |
|
| 1116 | - $p->id_boucle = $id_boucle; |
|
| 1117 | - $p->boucles = &$boucles; |
|
| 1118 | - $code = compose_filtres($p, $code); |
|
| 1119 | - } |
|
| 1120 | - $commentaire = ':'; |
|
| 1121 | - $avant = ''; |
|
| 1122 | - $apres = ''; |
|
| 1123 | - $altern = "''"; |
|
| 1124 | - break; |
|
| 1125 | - |
|
| 1126 | - case 'champ': |
|
| 1127 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1128 | - $p->id_boucle = $id_boucle; |
|
| 1129 | - $p->boucles = &$boucles; |
|
| 1130 | - $p->descr = $descr; |
|
| 1131 | - #$p->interdire_scripts = true; |
|
| 1132 | - $p->type_requete = $type; |
|
| 1133 | - |
|
| 1134 | - $code = calculer_champ($p); |
|
| 1135 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1136 | - $avant = calculer_liste( |
|
| 1137 | - $p->avant, |
|
| 1138 | - $descr, |
|
| 1139 | - $boucles, |
|
| 1140 | - $id_boucle |
|
| 1141 | - ); |
|
| 1142 | - $apres = calculer_liste( |
|
| 1143 | - $p->apres, |
|
| 1144 | - $descr, |
|
| 1145 | - $boucles, |
|
| 1146 | - $id_boucle |
|
| 1147 | - ); |
|
| 1148 | - $altern = "''"; |
|
| 1149 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1150 | - // forcer la conversion en une chaine par strval |
|
| 1151 | - // si ca peut etre autre chose qu'une chaine |
|
| 1152 | - if ( |
|
| 1153 | - ($avant != "''" or $apres != "''") |
|
| 1154 | - and $code[0] != "'" |
|
| 976 | + $codes = []; |
|
| 977 | + // cas de la boucle recursive |
|
| 978 | + if (is_array($id_boucle)) { |
|
| 979 | + $id_boucle = $id_boucle[0]; |
|
| 980 | + } |
|
| 981 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 982 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 983 | + $mode = _request('var_mode_affiche'); |
|
| 984 | + $err_e_c = ''; |
|
| 985 | + // chaque commentaire introduit dans le code doit commencer |
|
| 986 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 987 | + foreach ($tableau as $p) { |
|
| 988 | + switch ($p->type) { |
|
| 989 | + // texte seul |
|
| 990 | + case 'texte': |
|
| 991 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 992 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 993 | + $avant = ''; |
|
| 994 | + $apres = ''; |
|
| 995 | + $altern = "''"; |
|
| 996 | + break; |
|
| 997 | + |
|
| 998 | + case 'polyglotte': |
|
| 999 | + $code = ''; |
|
| 1000 | + foreach ($p->traductions as $k => $v) { |
|
| 1001 | + $code .= ",'" . |
|
| 1002 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | + "' => '" . |
|
| 1004 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1005 | + "'"; |
|
| 1006 | + } |
|
| 1007 | + $code = 'choisir_traduction(array(' . |
|
| 1008 | + substr($code, 1) . |
|
| 1009 | + '))'; |
|
| 1010 | + $commentaire = '&'; |
|
| 1011 | + $avant = ''; |
|
| 1012 | + $apres = ''; |
|
| 1013 | + $altern = "''"; |
|
| 1014 | + break; |
|
| 1015 | + |
|
| 1016 | + // inclure |
|
| 1017 | + case 'include': |
|
| 1018 | + $p->descr = $descr; |
|
| 1019 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1020 | + if ($code === false) { |
|
| 1021 | + $err_e_c = true; |
|
| 1022 | + $code = "''"; |
|
| 1023 | + } else { |
|
| 1024 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1025 | + $avant = ''; |
|
| 1026 | + $apres = ''; |
|
| 1027 | + $altern = "''"; |
|
| 1028 | + } |
|
| 1029 | + break; |
|
| 1030 | + |
|
| 1031 | + // boucle |
|
| 1032 | + case TYPE_RECURSIF: |
|
| 1033 | + $nom = $p->id_boucle; |
|
| 1034 | + $newdescr = $descr; |
|
| 1035 | + $newdescr['id_mere'] = $nom; |
|
| 1036 | + $newdescr['niv']++; |
|
| 1037 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1038 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1039 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1040 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1041 | + $newdescr['niv']--; |
|
| 1042 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1043 | + if ( |
|
| 1044 | + $preaff === false |
|
| 1045 | + or $avant === false |
|
| 1046 | + or $apres === false |
|
| 1047 | + or $altern === false |
|
| 1048 | + or $postaff === false |
|
| 1049 | + ) { |
|
| 1050 | + $err_e_c = true; |
|
| 1051 | + $code = "''"; |
|
| 1052 | + } else { |
|
| 1053 | + $code = 'BOUCLE' . |
|
| 1054 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1055 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1056 | + $commentaire = "?$nom"; |
|
| 1057 | + if ( |
|
| 1058 | + !$boucles[$nom]->milieu |
|
| 1059 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1060 | + ) { |
|
| 1061 | + if ($preaff != "''") { |
|
| 1062 | + $code .= "\n. $preaff"; |
|
| 1063 | + } |
|
| 1064 | + if ($altern != "''") { |
|
| 1065 | + $code .= "\n. $altern"; |
|
| 1066 | + } |
|
| 1067 | + if ($postaff != "''") { |
|
| 1068 | + $code .= "\n. $postaff"; |
|
| 1069 | + } |
|
| 1070 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1071 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1072 | + } |
|
| 1073 | + $avant = $apres = $altern = "''"; |
|
| 1074 | + } else { |
|
| 1075 | + if ($preaff != "''") { |
|
| 1076 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1077 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1078 | + } |
|
| 1079 | + if ($postaff != "''") { |
|
| 1080 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1081 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1082 | + } |
|
| 1083 | + if ($altern != "''") { |
|
| 1084 | + $altern = "($altern)"; |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + } |
|
| 1088 | + break; |
|
| 1089 | + |
|
| 1090 | + case 'idiome': |
|
| 1091 | + $l = []; |
|
| 1092 | + $code = ''; |
|
| 1093 | + foreach ($p->arg as $k => $v) { |
|
| 1094 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1095 | + if ($k) { |
|
| 1096 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1097 | + } else { |
|
| 1098 | + $code = $_v; |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1102 | + if ($p->module) { |
|
| 1103 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1104 | + } elseif ($p->nom_champ) { |
|
| 1105 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1106 | + } else { |
|
| 1107 | + $m = ''; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + $code = (!$code ? "'$m'" : |
|
| 1111 | + ($m ? "'$m' . $code" : |
|
| 1112 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1114 | + $code = "_T($code)"; |
|
| 1115 | + if ($p->param) { |
|
| 1116 | + $p->id_boucle = $id_boucle; |
|
| 1117 | + $p->boucles = &$boucles; |
|
| 1118 | + $code = compose_filtres($p, $code); |
|
| 1119 | + } |
|
| 1120 | + $commentaire = ':'; |
|
| 1121 | + $avant = ''; |
|
| 1122 | + $apres = ''; |
|
| 1123 | + $altern = "''"; |
|
| 1124 | + break; |
|
| 1125 | + |
|
| 1126 | + case 'champ': |
|
| 1127 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1128 | + $p->id_boucle = $id_boucle; |
|
| 1129 | + $p->boucles = &$boucles; |
|
| 1130 | + $p->descr = $descr; |
|
| 1131 | + #$p->interdire_scripts = true; |
|
| 1132 | + $p->type_requete = $type; |
|
| 1133 | + |
|
| 1134 | + $code = calculer_champ($p); |
|
| 1135 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1136 | + $avant = calculer_liste( |
|
| 1137 | + $p->avant, |
|
| 1138 | + $descr, |
|
| 1139 | + $boucles, |
|
| 1140 | + $id_boucle |
|
| 1141 | + ); |
|
| 1142 | + $apres = calculer_liste( |
|
| 1143 | + $p->apres, |
|
| 1144 | + $descr, |
|
| 1145 | + $boucles, |
|
| 1146 | + $id_boucle |
|
| 1147 | + ); |
|
| 1148 | + $altern = "''"; |
|
| 1149 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1150 | + // forcer la conversion en une chaine par strval |
|
| 1151 | + // si ca peut etre autre chose qu'une chaine |
|
| 1152 | + if ( |
|
| 1153 | + ($avant != "''" or $apres != "''") |
|
| 1154 | + and $code[0] != "'" |
|
| 1155 | 1155 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1156 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1157 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1158 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1159 | - ) { |
|
| 1160 | - $code = "strval($code)"; |
|
| 1161 | - } |
|
| 1162 | - break; |
|
| 1163 | - |
|
| 1164 | - default: |
|
| 1165 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1166 | - $code = "''"; |
|
| 1167 | - $p->descr = $descr; |
|
| 1168 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1169 | - erreur_squelette($err_e_c, $p); |
|
| 1170 | - } // switch |
|
| 1171 | - |
|
| 1172 | - if ($code != "''") { |
|
| 1173 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1174 | - $codes[] = (($mode == 'validation') ? |
|
| 1175 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1176 | - : (($mode == 'code') ? |
|
| 1177 | - "\n// $commentaire\n$code" : |
|
| 1178 | - $code)); |
|
| 1179 | - } |
|
| 1180 | - } // foreach |
|
| 1181 | - |
|
| 1182 | - return $err_e_c ? false : $codes; |
|
| 1156 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1157 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1158 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1159 | + ) { |
|
| 1160 | + $code = "strval($code)"; |
|
| 1161 | + } |
|
| 1162 | + break; |
|
| 1163 | + |
|
| 1164 | + default: |
|
| 1165 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1166 | + $code = "''"; |
|
| 1167 | + $p->descr = $descr; |
|
| 1168 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1169 | + erreur_squelette($err_e_c, $p); |
|
| 1170 | + } // switch |
|
| 1171 | + |
|
| 1172 | + if ($code != "''") { |
|
| 1173 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1174 | + $codes[] = (($mode == 'validation') ? |
|
| 1175 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1176 | + : (($mode == 'code') ? |
|
| 1177 | + "\n// $commentaire\n$code" : |
|
| 1178 | + $code)); |
|
| 1179 | + } |
|
| 1180 | + } // foreach |
|
| 1181 | + |
|
| 1182 | + return $err_e_c ? false : $codes; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1189,13 +1189,13 @@ discard block |
||
| 1189 | 1189 | * @return string |
| 1190 | 1190 | */ |
| 1191 | 1191 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1192 | - if ($partie1 === "''") { |
|
| 1193 | - return $partie2; |
|
| 1194 | - } |
|
| 1195 | - if ($partie2 === "''") { |
|
| 1196 | - return $partie1; |
|
| 1197 | - } |
|
| 1198 | - return "$partie1\n. $partie2"; |
|
| 1192 | + if ($partie1 === "''") { |
|
| 1193 | + return $partie2; |
|
| 1194 | + } |
|
| 1195 | + if ($partie2 === "''") { |
|
| 1196 | + return $partie1; |
|
| 1197 | + } |
|
| 1198 | + return "$partie1\n. $partie2"; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | |
@@ -1220,56 +1220,56 @@ discard block |
||
| 1220 | 1220 | * @return mixed|string |
| 1221 | 1221 | */ |
| 1222 | 1222 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1223 | - if ($avant === "''") { |
|
| 1224 | - $avant = ''; |
|
| 1225 | - } |
|
| 1226 | - if ($apres === "''") { |
|
| 1227 | - $apres = ''; |
|
| 1228 | - } |
|
| 1229 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1230 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1231 | - $t = $code; |
|
| 1232 | - $cond = ''; |
|
| 1233 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1234 | - $t = $r[2]; |
|
| 1235 | - $cond = '!' . $r[1]; |
|
| 1236 | - } else { |
|
| 1237 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1238 | - $t = $r[2]; |
|
| 1239 | - $cond = $r[1]; |
|
| 1240 | - } else { |
|
| 1241 | - $t = '$t' . $n; |
|
| 1242 | - $cond = "($t = $code)!==''"; |
|
| 1243 | - } |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | - $t . |
|
| 1248 | - (!$apres ? '' : " . $apres"); |
|
| 1249 | - |
|
| 1250 | - if ($res !== $t) { |
|
| 1251 | - $res = "($res)"; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - return $code; |
|
| 1223 | + if ($avant === "''") { |
|
| 1224 | + $avant = ''; |
|
| 1225 | + } |
|
| 1226 | + if ($apres === "''") { |
|
| 1227 | + $apres = ''; |
|
| 1228 | + } |
|
| 1229 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1230 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1231 | + $t = $code; |
|
| 1232 | + $cond = ''; |
|
| 1233 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1234 | + $t = $r[2]; |
|
| 1235 | + $cond = '!' . $r[1]; |
|
| 1236 | + } else { |
|
| 1237 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1238 | + $t = $r[2]; |
|
| 1239 | + $cond = $r[1]; |
|
| 1240 | + } else { |
|
| 1241 | + $t = '$t' . $n; |
|
| 1242 | + $cond = "($t = $code)!==''"; |
|
| 1243 | + } |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | + $t . |
|
| 1248 | + (!$apres ? '' : " . $apres"); |
|
| 1249 | + |
|
| 1250 | + if ($res !== $t) { |
|
| 1251 | + $res = "($res)"; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + return $code; |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | |
| 1261 | 1261 | function compile_inclure_doublons($lexemes) { |
| 1262 | - foreach ($lexemes as $v) { |
|
| 1263 | - if ($v->type === 'include' and $v->param) { |
|
| 1264 | - foreach ($v->param as $r) { |
|
| 1265 | - if (trim($r[0]) === 'doublons') { |
|
| 1266 | - return true; |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - return false; |
|
| 1262 | + foreach ($lexemes as $v) { |
|
| 1263 | + if ($v->type === 'include' and $v->param) { |
|
| 1264 | + foreach ($v->param as $r) { |
|
| 1265 | + if (trim($r[0]) === 'doublons') { |
|
| 1266 | + return true; |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + return false; |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1289,360 +1289,360 @@ discard block |
||
| 1289 | 1289 | |
| 1290 | 1290 | // https://code.spip.net/@public_compiler_dist |
| 1291 | 1291 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1292 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1293 | - // Bonus : supprime le BOM |
|
| 1294 | - include_spip('inc/charsets'); |
|
| 1295 | - $squelette = transcoder_page($squelette); |
|
| 1296 | - |
|
| 1297 | - // rendre inertes les echappements de #[](){}<> |
|
| 1298 | - $i = 0; |
|
| 1299 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1300 | - $i++; |
|
| 1301 | - } |
|
| 1302 | - $squelette = preg_replace_callback( |
|
| 1303 | - ',\\\\([#[()\]{}<>]),', |
|
| 1304 | - function ($a) use ($inerte) { |
|
| 1305 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1306 | - }, |
|
| 1307 | - $squelette, |
|
| 1308 | - -1, |
|
| 1309 | - $esc |
|
| 1310 | - ); |
|
| 1311 | - |
|
| 1312 | - $descr = [ |
|
| 1313 | - 'nom' => $nom, |
|
| 1314 | - 'gram' => $gram, |
|
| 1315 | - 'sourcefile' => $sourcefile, |
|
| 1316 | - 'squelette' => $squelette |
|
| 1317 | - ]; |
|
| 1318 | - |
|
| 1319 | - // Phraser le squelette, selon sa grammaire |
|
| 1320 | - |
|
| 1321 | - $boucles = []; |
|
| 1322 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1323 | - |
|
| 1324 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1325 | - |
|
| 1326 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1327 | - |
|
| 1328 | - // restituer les echappements |
|
| 1329 | - if ($esc) { |
|
| 1330 | - foreach ($boucles as $i => $boucle) { |
|
| 1331 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1332 | - ",$inerte-(\d+)-,", |
|
| 1333 | - function ($a) { |
|
| 1334 | - return chr($a[1]); |
|
| 1335 | - }, |
|
| 1336 | - $boucle->return |
|
| 1337 | - ); |
|
| 1338 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1339 | - ",$inerte-(\d+)-,", |
|
| 1340 | - function ($a) { |
|
| 1341 | - return '\\\\' . chr($a[1]); |
|
| 1342 | - }, |
|
| 1343 | - $boucle->descr['squelette'] |
|
| 1344 | - ); |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | - if ($debug) { |
|
| 1350 | - include_spip('public/decompiler'); |
|
| 1351 | - foreach ($boucles as $id => $boucle) { |
|
| 1352 | - if ($id) { |
|
| 1353 | - $decomp = "\n/* BOUCLE " . |
|
| 1354 | - $boucle->type_requete . |
|
| 1355 | - ' ' . |
|
| 1356 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | - " */\n"; |
|
| 1359 | - } else { |
|
| 1360 | - $decomp = ("\n/*\n" . |
|
| 1361 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | - . "\n*/"); |
|
| 1363 | - } |
|
| 1364 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - return $boucles; |
|
| 1292 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1293 | + // Bonus : supprime le BOM |
|
| 1294 | + include_spip('inc/charsets'); |
|
| 1295 | + $squelette = transcoder_page($squelette); |
|
| 1296 | + |
|
| 1297 | + // rendre inertes les echappements de #[](){}<> |
|
| 1298 | + $i = 0; |
|
| 1299 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1300 | + $i++; |
|
| 1301 | + } |
|
| 1302 | + $squelette = preg_replace_callback( |
|
| 1303 | + ',\\\\([#[()\]{}<>]),', |
|
| 1304 | + function ($a) use ($inerte) { |
|
| 1305 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1306 | + }, |
|
| 1307 | + $squelette, |
|
| 1308 | + -1, |
|
| 1309 | + $esc |
|
| 1310 | + ); |
|
| 1311 | + |
|
| 1312 | + $descr = [ |
|
| 1313 | + 'nom' => $nom, |
|
| 1314 | + 'gram' => $gram, |
|
| 1315 | + 'sourcefile' => $sourcefile, |
|
| 1316 | + 'squelette' => $squelette |
|
| 1317 | + ]; |
|
| 1318 | + |
|
| 1319 | + // Phraser le squelette, selon sa grammaire |
|
| 1320 | + |
|
| 1321 | + $boucles = []; |
|
| 1322 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1323 | + |
|
| 1324 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1325 | + |
|
| 1326 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1327 | + |
|
| 1328 | + // restituer les echappements |
|
| 1329 | + if ($esc) { |
|
| 1330 | + foreach ($boucles as $i => $boucle) { |
|
| 1331 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1332 | + ",$inerte-(\d+)-,", |
|
| 1333 | + function ($a) { |
|
| 1334 | + return chr($a[1]); |
|
| 1335 | + }, |
|
| 1336 | + $boucle->return |
|
| 1337 | + ); |
|
| 1338 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1339 | + ",$inerte-(\d+)-,", |
|
| 1340 | + function ($a) { |
|
| 1341 | + return '\\\\' . chr($a[1]); |
|
| 1342 | + }, |
|
| 1343 | + $boucle->descr['squelette'] |
|
| 1344 | + ); |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | + if ($debug) { |
|
| 1350 | + include_spip('public/decompiler'); |
|
| 1351 | + foreach ($boucles as $id => $boucle) { |
|
| 1352 | + if ($id) { |
|
| 1353 | + $decomp = "\n/* BOUCLE " . |
|
| 1354 | + $boucle->type_requete . |
|
| 1355 | + ' ' . |
|
| 1356 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | + " */\n"; |
|
| 1359 | + } else { |
|
| 1360 | + $decomp = ("\n/*\n" . |
|
| 1361 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | + . "\n*/"); |
|
| 1363 | + } |
|
| 1364 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + return $boucles; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1373 | 1373 | // Autres specifications comme ci-dessus |
| 1374 | 1374 | |
| 1375 | 1375 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1376 | - static $trouver_table; |
|
| 1377 | - spip_timer('calcul_skel'); |
|
| 1378 | - |
|
| 1379 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | - |
|
| 1383 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - foreach ($boucles as $id => $boucle) { |
|
| 1388 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | - } |
|
| 1390 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | - |
|
| 1392 | - // Demander la description des tables une fois pour toutes |
|
| 1393 | - if (!$trouver_table) { |
|
| 1394 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - // reperer si les doublons sont demandes |
|
| 1398 | - // pour un inclure ou une boucle document |
|
| 1399 | - // c'est utile a la fonction champs_traitements |
|
| 1400 | - foreach ($boucles as $id => $boucle) { |
|
| 1401 | - if (!($type = $boucle->type_requete)) { |
|
| 1402 | - continue; |
|
| 1403 | - } |
|
| 1404 | - if ( |
|
| 1405 | - !$descr['documents'] and ( |
|
| 1406 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | - compile_inclure_doublons($boucle->avant) or |
|
| 1408 | - compile_inclure_doublons($boucle->apres) or |
|
| 1409 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | - compile_inclure_doublons($boucle->altern)) |
|
| 1411 | - ) { |
|
| 1412 | - $descr['documents'] = true; |
|
| 1413 | - } |
|
| 1414 | - if ($type != TYPE_RECURSIF) { |
|
| 1415 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | - if ( |
|
| 1421 | - $g = charger_fonction( |
|
| 1422 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | - 'iterateur', |
|
| 1424 | - true |
|
| 1425 | - ) |
|
| 1426 | - ) { |
|
| 1427 | - $boucles[$id] = $g($boucle); |
|
| 1428 | - |
|
| 1429 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | - // utiliser les informations donnees par le requeteur |
|
| 1431 | - // cas "php:xx" et "data:xx". |
|
| 1432 | - } else { |
|
| 1433 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | - $requeteur($boucles, $boucle, $id); |
|
| 1435 | - |
|
| 1436 | - // utiliser la description des champs transmis |
|
| 1437 | - } else { |
|
| 1438 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | - if ( |
|
| 1443 | - !$show |
|
| 1444 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | - ) { |
|
| 1446 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | - } |
|
| 1448 | - if ($show) { |
|
| 1449 | - $boucles[$id]->show = $show; |
|
| 1450 | - // recopie les infos les plus importantes |
|
| 1451 | - $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1452 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | - |
|
| 1456 | - if (empty($boucles[$id]->descr)) { |
|
| 1457 | - $boucles[$id]->descr = &$descr; |
|
| 1458 | - } |
|
| 1459 | - if ( |
|
| 1460 | - (!$boucles[$id]->jointures) |
|
| 1461 | - and is_array($show['tables_jointures']) |
|
| 1462 | - and count($x = $show['tables_jointures']) |
|
| 1463 | - ) { |
|
| 1464 | - $boucles[$id]->jointures = $x; |
|
| 1465 | - } |
|
| 1466 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | - while ($j = array_pop($jointures)) { |
|
| 1469 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1472 | - } else { |
|
| 1473 | - // Pas une erreur si la table est optionnelle |
|
| 1474 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | - $boucles[$id]->type_requete = ''; |
|
| 1476 | - } else { |
|
| 1477 | - $boucles[$id]->type_requete = false; |
|
| 1478 | - $boucle = $boucles[$id]; |
|
| 1479 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | - ($boucle->sql_serveur . ':')) . |
|
| 1481 | - $type; |
|
| 1482 | - $msg = [ |
|
| 1483 | - 'zbug_table_inconnue', |
|
| 1484 | - ['table' => $x] |
|
| 1485 | - ]; |
|
| 1486 | - erreur_squelette($msg, $boucle); |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | - foreach ($boucles as $id => $boucle) { |
|
| 1497 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | - $boucles[$id]->descr = &$descr; |
|
| 1499 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | - if (!$rec) { |
|
| 1501 | - $msg = [ |
|
| 1502 | - 'zbug_boucle_recursive_undef', |
|
| 1503 | - ['nom' => $boucle->param[0]] |
|
| 1504 | - ]; |
|
| 1505 | - erreur_squelette($msg, $boucle); |
|
| 1506 | - $boucles[$id]->type_requete = false; |
|
| 1507 | - } else { |
|
| 1508 | - $rec->externe = $id; |
|
| 1509 | - $descr['id_mere'] = $id; |
|
| 1510 | - $boucles[$id]->return = |
|
| 1511 | - calculer_liste( |
|
| 1512 | - [$rec], |
|
| 1513 | - $descr, |
|
| 1514 | - $boucles, |
|
| 1515 | - $boucle->param |
|
| 1516 | - ); |
|
| 1517 | - } |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - foreach ($boucles as $id => $boucle) { |
|
| 1521 | - $id = strval($id); // attention au type dans index_pile |
|
| 1522 | - $type = $boucle->type_requete; |
|
| 1523 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | - $res = ''; |
|
| 1525 | - if ($boucle->param) { |
|
| 1526 | - // retourne un tableau en cas d'erreur |
|
| 1527 | - $res = calculer_criteres($id, $boucles); |
|
| 1528 | - } |
|
| 1529 | - $descr['id_mere'] = $id; |
|
| 1530 | - $boucles[$id]->return = |
|
| 1531 | - calculer_liste( |
|
| 1532 | - $boucle->milieu, |
|
| 1533 | - $descr, |
|
| 1534 | - $boucles, |
|
| 1535 | - $id |
|
| 1536 | - ); |
|
| 1537 | - // Si les criteres se sont mal compiles |
|
| 1538 | - // ne pas tenter d'assembler le code final |
|
| 1539 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | - if (is_array($res)) { |
|
| 1541 | - $boucles[$id]->type_requete = false; |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // idem pour la racine |
|
| 1547 | - $descr['id_mere'] = ''; |
|
| 1548 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | - |
|
| 1550 | - |
|
| 1551 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | - // de'terminables seulement maintenant |
|
| 1554 | - |
|
| 1555 | - foreach ($boucles as $id => $boucle) { |
|
| 1556 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | - if ($boucle->return === false) { |
|
| 1558 | - $corps = false; |
|
| 1559 | - continue; |
|
| 1560 | - } |
|
| 1561 | - // appeler la fonction de definition de la boucle |
|
| 1562 | - |
|
| 1563 | - if ($req = $boucle->type_requete) { |
|
| 1564 | - // boucle personnalisée ? |
|
| 1565 | - $table = strtoupper($boucle->type_requete); |
|
| 1566 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | - if ( |
|
| 1568 | - // fonction de boucle avec serveur & table |
|
| 1569 | - (!$serveur or |
|
| 1570 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | - and (!function_exists($f = $f . '_dist')) |
|
| 1572 | - ) |
|
| 1573 | - ) |
|
| 1574 | - // fonction de boucle avec table |
|
| 1575 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | - and (!function_exists($f = $f . '_dist')) |
|
| 1577 | - ) { |
|
| 1578 | - // fonction de boucle standard |
|
| 1579 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | - "static \$connect;\n\t" . |
|
| 1586 | - "\$command['connect'] = \$connect = " . |
|
| 1587 | - _q($boucle->sql_serveur) . |
|
| 1588 | - ';' . |
|
| 1589 | - $f($id, $boucles); |
|
| 1590 | - } else { |
|
| 1591 | - $req = ("\n\treturn '';"); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - $boucles[$id]->return = |
|
| 1595 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | - $req . |
|
| 1598 | - "\n}\n"; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | - // retourner False, sinon inserer leur decompilation |
|
| 1603 | - if (is_bool($corps)) { |
|
| 1604 | - return false; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1376 | + static $trouver_table; |
|
| 1377 | + spip_timer('calcul_skel'); |
|
| 1378 | + |
|
| 1379 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | + |
|
| 1383 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + foreach ($boucles as $id => $boucle) { |
|
| 1388 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | + } |
|
| 1390 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | + |
|
| 1392 | + // Demander la description des tables une fois pour toutes |
|
| 1393 | + if (!$trouver_table) { |
|
| 1394 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + // reperer si les doublons sont demandes |
|
| 1398 | + // pour un inclure ou une boucle document |
|
| 1399 | + // c'est utile a la fonction champs_traitements |
|
| 1400 | + foreach ($boucles as $id => $boucle) { |
|
| 1401 | + if (!($type = $boucle->type_requete)) { |
|
| 1402 | + continue; |
|
| 1403 | + } |
|
| 1404 | + if ( |
|
| 1405 | + !$descr['documents'] and ( |
|
| 1406 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | + compile_inclure_doublons($boucle->avant) or |
|
| 1408 | + compile_inclure_doublons($boucle->apres) or |
|
| 1409 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | + compile_inclure_doublons($boucle->altern)) |
|
| 1411 | + ) { |
|
| 1412 | + $descr['documents'] = true; |
|
| 1413 | + } |
|
| 1414 | + if ($type != TYPE_RECURSIF) { |
|
| 1415 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | + if ( |
|
| 1421 | + $g = charger_fonction( |
|
| 1422 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | + 'iterateur', |
|
| 1424 | + true |
|
| 1425 | + ) |
|
| 1426 | + ) { |
|
| 1427 | + $boucles[$id] = $g($boucle); |
|
| 1428 | + |
|
| 1429 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | + // utiliser les informations donnees par le requeteur |
|
| 1431 | + // cas "php:xx" et "data:xx". |
|
| 1432 | + } else { |
|
| 1433 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | + $requeteur($boucles, $boucle, $id); |
|
| 1435 | + |
|
| 1436 | + // utiliser la description des champs transmis |
|
| 1437 | + } else { |
|
| 1438 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | + if ( |
|
| 1443 | + !$show |
|
| 1444 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | + ) { |
|
| 1446 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | + } |
|
| 1448 | + if ($show) { |
|
| 1449 | + $boucles[$id]->show = $show; |
|
| 1450 | + // recopie les infos les plus importantes |
|
| 1451 | + $boucles[$id]->primary = isset($show['key']['PRIMARY KEY']) ? $show['key']['PRIMARY KEY'] : ''; |
|
| 1452 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | + |
|
| 1456 | + if (empty($boucles[$id]->descr)) { |
|
| 1457 | + $boucles[$id]->descr = &$descr; |
|
| 1458 | + } |
|
| 1459 | + if ( |
|
| 1460 | + (!$boucles[$id]->jointures) |
|
| 1461 | + and is_array($show['tables_jointures']) |
|
| 1462 | + and count($x = $show['tables_jointures']) |
|
| 1463 | + ) { |
|
| 1464 | + $boucles[$id]->jointures = $x; |
|
| 1465 | + } |
|
| 1466 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | + while ($j = array_pop($jointures)) { |
|
| 1469 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | + } else { |
|
| 1473 | + // Pas une erreur si la table est optionnelle |
|
| 1474 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | + $boucles[$id]->type_requete = ''; |
|
| 1476 | + } else { |
|
| 1477 | + $boucles[$id]->type_requete = false; |
|
| 1478 | + $boucle = $boucles[$id]; |
|
| 1479 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | + ($boucle->sql_serveur . ':')) . |
|
| 1481 | + $type; |
|
| 1482 | + $msg = [ |
|
| 1483 | + 'zbug_table_inconnue', |
|
| 1484 | + ['table' => $x] |
|
| 1485 | + ]; |
|
| 1486 | + erreur_squelette($msg, $boucle); |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | + foreach ($boucles as $id => $boucle) { |
|
| 1497 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | + $boucles[$id]->descr = &$descr; |
|
| 1499 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | + if (!$rec) { |
|
| 1501 | + $msg = [ |
|
| 1502 | + 'zbug_boucle_recursive_undef', |
|
| 1503 | + ['nom' => $boucle->param[0]] |
|
| 1504 | + ]; |
|
| 1505 | + erreur_squelette($msg, $boucle); |
|
| 1506 | + $boucles[$id]->type_requete = false; |
|
| 1507 | + } else { |
|
| 1508 | + $rec->externe = $id; |
|
| 1509 | + $descr['id_mere'] = $id; |
|
| 1510 | + $boucles[$id]->return = |
|
| 1511 | + calculer_liste( |
|
| 1512 | + [$rec], |
|
| 1513 | + $descr, |
|
| 1514 | + $boucles, |
|
| 1515 | + $boucle->param |
|
| 1516 | + ); |
|
| 1517 | + } |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + foreach ($boucles as $id => $boucle) { |
|
| 1521 | + $id = strval($id); // attention au type dans index_pile |
|
| 1522 | + $type = $boucle->type_requete; |
|
| 1523 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | + $res = ''; |
|
| 1525 | + if ($boucle->param) { |
|
| 1526 | + // retourne un tableau en cas d'erreur |
|
| 1527 | + $res = calculer_criteres($id, $boucles); |
|
| 1528 | + } |
|
| 1529 | + $descr['id_mere'] = $id; |
|
| 1530 | + $boucles[$id]->return = |
|
| 1531 | + calculer_liste( |
|
| 1532 | + $boucle->milieu, |
|
| 1533 | + $descr, |
|
| 1534 | + $boucles, |
|
| 1535 | + $id |
|
| 1536 | + ); |
|
| 1537 | + // Si les criteres se sont mal compiles |
|
| 1538 | + // ne pas tenter d'assembler le code final |
|
| 1539 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | + if (is_array($res)) { |
|
| 1541 | + $boucles[$id]->type_requete = false; |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // idem pour la racine |
|
| 1547 | + $descr['id_mere'] = ''; |
|
| 1548 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | + |
|
| 1550 | + |
|
| 1551 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | + // de'terminables seulement maintenant |
|
| 1554 | + |
|
| 1555 | + foreach ($boucles as $id => $boucle) { |
|
| 1556 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | + if ($boucle->return === false) { |
|
| 1558 | + $corps = false; |
|
| 1559 | + continue; |
|
| 1560 | + } |
|
| 1561 | + // appeler la fonction de definition de la boucle |
|
| 1562 | + |
|
| 1563 | + if ($req = $boucle->type_requete) { |
|
| 1564 | + // boucle personnalisée ? |
|
| 1565 | + $table = strtoupper($boucle->type_requete); |
|
| 1566 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | + if ( |
|
| 1568 | + // fonction de boucle avec serveur & table |
|
| 1569 | + (!$serveur or |
|
| 1570 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | + and (!function_exists($f = $f . '_dist')) |
|
| 1572 | + ) |
|
| 1573 | + ) |
|
| 1574 | + // fonction de boucle avec table |
|
| 1575 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | + and (!function_exists($f = $f . '_dist')) |
|
| 1577 | + ) { |
|
| 1578 | + // fonction de boucle standard |
|
| 1579 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | + "static \$connect;\n\t" . |
|
| 1586 | + "\$command['connect'] = \$connect = " . |
|
| 1587 | + _q($boucle->sql_serveur) . |
|
| 1588 | + ';' . |
|
| 1589 | + $f($id, $boucles); |
|
| 1590 | + } else { |
|
| 1591 | + $req = ("\n\treturn '';"); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + $boucles[$id]->return = |
|
| 1595 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | + $req . |
|
| 1598 | + "\n}\n"; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | + // retourner False, sinon inserer leur decompilation |
|
| 1603 | + if (is_bool($corps)) { |
|
| 1604 | + return false; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1608 | 1608 | ' |
| 1609 | - // reporter de maniere securisee les doublons inclus |
|
| 1610 | - . ' |
|
| 1609 | + // reporter de maniere securisee les doublons inclus |
|
| 1610 | + . ' |
|
| 1611 | 1611 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1612 | 1612 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1613 | 1613 | |
| 1614 | 1614 | $connect = ' . |
| 1615 | - _q($connect) . '; |
|
| 1615 | + _q($connect) . '; |
|
| 1616 | 1616 | $page = ' . |
| 1617 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | - // avant de referencer $Cache |
|
| 1620 | - $corps . '; |
|
| 1617 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | + // avant de referencer $Cache |
|
| 1620 | + $corps . '; |
|
| 1621 | 1621 | |
| 1622 | 1622 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1623 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1623 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1624 | 1624 | }'; |
| 1625 | 1625 | |
| 1626 | - $secondes = spip_timer('calcul_skel'); |
|
| 1627 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | - // $connect n'est pas sûr : on nettoie |
|
| 1629 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1626 | + $secondes = spip_timer('calcul_skel'); |
|
| 1627 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | + // $connect n'est pas sûr : on nettoie |
|
| 1629 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1630 | 1630 | |
| 1631 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | - $code = new Boucle(); |
|
| 1633 | - $code->descr = $descr; |
|
| 1634 | - $code->return = ' |
|
| 1631 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | + $code = new Boucle(); |
|
| 1633 | + $code->descr = $descr; |
|
| 1634 | + $code->return = ' |
|
| 1635 | 1635 | // |
| 1636 | 1636 | // Fonction principale du squelette ' . |
| 1637 | - $sourcefile . |
|
| 1638 | - ($connect ? " pour $connect" : '') . |
|
| 1639 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | - "\n//\n" . |
|
| 1641 | - $principal; |
|
| 1637 | + $sourcefile . |
|
| 1638 | + ($connect ? " pour $connect" : '') . |
|
| 1639 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | + "\n//\n" . |
|
| 1641 | + $principal; |
|
| 1642 | 1642 | |
| 1643 | - $boucles[''] = $code; |
|
| 1643 | + $boucles[''] = $code; |
|
| 1644 | 1644 | |
| 1645 | - return $boucles; |
|
| 1645 | + return $boucles; |
|
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | |
@@ -1659,18 +1659,18 @@ discard block |
||
| 1659 | 1659 | * |
| 1660 | 1660 | **/ |
| 1661 | 1661 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1662 | - if (class_exists($boucle->type_requete)) { |
|
| 1663 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | - } else { |
|
| 1666 | - $x = $boucle->type_requete; |
|
| 1667 | - $boucle->type_requete = false; |
|
| 1668 | - $msg = [ |
|
| 1669 | - 'zbug_iterateur_inconnu', |
|
| 1670 | - ['iterateur' => $x] |
|
| 1671 | - ]; |
|
| 1672 | - erreur_squelette($msg, $boucle); |
|
| 1673 | - } |
|
| 1662 | + if (class_exists($boucle->type_requete)) { |
|
| 1663 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | + } else { |
|
| 1666 | + $x = $boucle->type_requete; |
|
| 1667 | + $boucle->type_requete = false; |
|
| 1668 | + $msg = [ |
|
| 1669 | + 'zbug_iterateur_inconnu', |
|
| 1670 | + ['iterateur' => $x] |
|
| 1671 | + ]; |
|
| 1672 | + erreur_squelette($msg, $boucle); |
|
| 1673 | + } |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | |
@@ -1688,22 +1688,22 @@ discard block |
||
| 1688 | 1688 | * |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1691 | - include_spip('iterateur/data'); |
|
| 1692 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | - $boucles[$id] = $g($boucle); |
|
| 1695 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | - } else { |
|
| 1698 | - $x = $boucle->type_requete; |
|
| 1699 | - $boucle->type_requete = false; |
|
| 1700 | - $msg = [ |
|
| 1701 | - 'zbug_requeteur_inconnu', |
|
| 1702 | - [ |
|
| 1703 | - 'requeteur' => 'data', |
|
| 1704 | - 'type' => $x |
|
| 1705 | - ] |
|
| 1706 | - ]; |
|
| 1707 | - erreur_squelette($msg, $boucle); |
|
| 1708 | - } |
|
| 1691 | + include_spip('iterateur/data'); |
|
| 1692 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | + $boucles[$id] = $g($boucle); |
|
| 1695 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | + } else { |
|
| 1698 | + $x = $boucle->type_requete; |
|
| 1699 | + $boucle->type_requete = false; |
|
| 1700 | + $msg = [ |
|
| 1701 | + 'zbug_requeteur_inconnu', |
|
| 1702 | + [ |
|
| 1703 | + 'requeteur' => 'data', |
|
| 1704 | + 'type' => $x |
|
| 1705 | + ] |
|
| 1706 | + ]; |
|
| 1707 | + erreur_squelette($msg, $boucle); |
|
| 1708 | + } |
|
| 1709 | 1709 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 122 | 122 | if ($var !== 1) { |
| 123 | 123 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 124 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + . $val.($echap ? ") . '" : ' '); |
|
| 125 | 125 | } else { |
| 126 | 126 | $val = $echap ? "'.$val.'" : $val; |
| 127 | 127 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (!$lang) { |
| 143 | 143 | $lang = '$GLOBALS["spip_lang"]'; |
| 144 | 144 | } |
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : ' '); |
|
| 146 | 146 | |
| 147 | 147 | return $l; |
| 148 | 148 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 174 | + $code = '"'.str_replace('"', '\"', $fichier).'"'; |
|
| 175 | 175 | } else { |
| 176 | 176 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
| 177 | 177 | if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | return false; |
| 221 | 221 | } // j'aurais voulu toucher le fond ... |
| 222 | 222 | |
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 223 | + $contexte = 'array('.$_contexte.')'; |
|
| 224 | 224 | |
| 225 | 225 | if ($env) { |
| 226 | 226 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | $_options[] = $ajax; |
| 236 | 236 | } |
| 237 | 237 | $code = " ' . argumenter_squelette($code) . '"; |
| 238 | - $code = 'echo ' . sprintf( |
|
| 238 | + $code = 'echo '.sprintf( |
|
| 239 | 239 | CODE_RECUPERER_FOND, |
| 240 | 240 | $code, |
| 241 | 241 | $contexte, |
| 242 | 242 | implode(',', $_options), |
| 243 | 243 | '_request("connect")' |
| 244 | - ) . ';'; |
|
| 244 | + ).';'; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 247 | + return "\n'<'.'".'?php '.$code."\n?'."."'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $id = $id_table; |
| 325 | 325 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 326 | 326 | } |
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 327 | + $mstatut = $id.'.'.$statut; |
|
| 328 | 328 | |
| 329 | 329 | $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
| 330 | 330 | include_spip('public/quete'); |
@@ -332,11 +332,11 @@ discard block |
||
| 332 | 332 | isset($s['post_date']) and $s['post_date'] |
| 333 | 333 | and $GLOBALS['meta']['post_dates'] == 'non' |
| 334 | 334 | ) { |
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 335 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | 336 | array_unshift( |
| 337 | 337 | $boucle->where, |
| 338 | 338 | $echapper ? |
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 339 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 340 | 340 | : |
| 341 | 341 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 342 | 342 | ); |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | $boucle->where, |
| 346 | 346 | $echapper ? |
| 347 | 347 | "\nquete_condition_statut('$mstatut'," |
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 348 | + . _q($s['previsu']).',' |
|
| 349 | + . _q($s['publie']).',' |
|
| 350 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 351 | 351 | : |
| 352 | 352 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 353 | 353 | ); |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | if (_request('var_mode_affiche') != 'resultat') { |
| 382 | 382 | $trace = ''; |
| 383 | 383 | } else { |
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 385 | 385 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 386 | 386 | $trace = " |
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | - $_trace" . '[] = $t0; |
|
| 391 | + $_trace".'[] = $t0; |
|
| 392 | 392 | }'; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | return |
| 423 | 423 | // Numrows[$nom] peut ne pas être encore defini |
| 424 | 424 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 425 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.';' |
|
| 426 | 426 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 427 | 427 | . $trace |
| 428 | 428 | . "\n\treturn \$t0;"; |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 490 | 490 | // et puis faire un [] plutot qu'un "','." |
| 491 | 491 | if ($boucle->doublons) { |
| 492 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 492 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 493 | 493 | index_pile($id_boucle, $primary, $boucles) |
| 494 | 494 | . "; // doublons\n"; |
| 495 | 495 | } |
@@ -517,13 +517,13 @@ discard block |
||
| 517 | 517 | $corps .= |
| 518 | 518 | "\n\t\tlang_select_public(" |
| 519 | 519 | . index_pile($id_boucle, 'lang', $boucles) |
| 520 | - . ", '" . $boucle->lang_select . "'" |
|
| 520 | + . ", '".$boucle->lang_select."'" |
|
| 521 | 521 | . (in_array($type_boucle, [ |
| 522 | 522 | 'articles', |
| 523 | 523 | 'rubriques', |
| 524 | 524 | 'hierarchie', |
| 525 | 525 | 'breves' |
| 526 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 526 | + ]) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | 527 | . ');'; |
| 528 | 528 | } else { |
| 529 | 529 | $init_lang = ''; |
@@ -545,20 +545,16 @@ discard block |
||
| 545 | 545 | |
| 546 | 546 | // gestion optimale des separateurs et des boucles constantes |
| 547 | 547 | if (count($boucle->separateur)) { |
| 548 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 548 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | $corps .= |
| 552 | 552 | ((!$boucle->separateur) ? |
| 553 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 554 | - (($return === "''") ? '' : |
|
| 555 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 556 | - ("\n\t\t\$t1 " . |
|
| 553 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.';'))) : ("\n\t\t\$t1 ". |
|
| 557 | 554 | ((strpos($return, '$t1.') === 0) ? |
| 558 | - ('.=' . substr($return, 4)) : |
|
| 559 | - ('= ' . $return)) . |
|
| 560 | - ";\n\t\t" . |
|
| 561 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 555 | + ('.='.substr($return, 4)) : ('= '.$return)). |
|
| 556 | + ";\n\t\t". |
|
| 557 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 562 | 558 | |
| 563 | 559 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 564 | 560 | // souhaite invalider ces elements |
@@ -640,7 +636,7 @@ discard block |
||
| 640 | 636 | $corps, |
| 641 | 637 | $fin_lang, |
| 642 | 638 | $trace, |
| 643 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 639 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 644 | 640 | ); |
| 645 | 641 | |
| 646 | 642 | # var_dump($a);exit; |
@@ -661,23 +657,23 @@ discard block |
||
| 661 | 657 | **/ |
| 662 | 658 | function calculer_requete_sql($boucle) { |
| 663 | 659 | $init = []; |
| 664 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 665 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 660 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 661 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 666 | 662 | # En absence de champ c'est un decompte : |
| 667 | 663 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 668 | 664 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 669 | 665 | $init[] = calculer_dec( |
| 670 | 666 | 'groupby', |
| 671 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 667 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').')' |
|
| 672 | 668 | ); |
| 673 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 674 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 669 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select).'")'); |
|
| 670 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).')'); |
|
| 675 | 671 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 676 | 672 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 677 | 673 | $init[] = calculer_dec( |
| 678 | 674 | 'limit', |
| 679 | 675 | (strpos($boucle->limit, 'intval') === false ? |
| 680 | - "'" . $boucle->limit . "'" |
|
| 676 | + "'".$boucle->limit."'" |
|
| 681 | 677 | : |
| 682 | 678 | $boucle->limit) |
| 683 | 679 | ); |
@@ -687,17 +683,17 @@ discard block |
||
| 687 | 683 | // ou recalculée à chaque passage (vide) |
| 688 | 684 | foreach ($init as $i) { |
| 689 | 685 | if (reset($i)) { |
| 690 | - $s .= "\n\t\t" . end($i); |
|
| 686 | + $s .= "\n\t\t".end($i); |
|
| 691 | 687 | } # statique |
| 692 | 688 | else { |
| 693 | - $d .= "\n\t" . end($i); |
|
| 689 | + $d .= "\n\t".end($i); |
|
| 694 | 690 | } # dynamique |
| 695 | 691 | } |
| 696 | 692 | |
| 697 | 693 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 698 | 694 | . $boucle->in |
| 699 | 695 | . $boucle->hash |
| 700 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 696 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 701 | 697 | . $s |
| 702 | 698 | . "\n\t}" |
| 703 | 699 | . $d; |
@@ -780,7 +776,7 @@ discard block |
||
| 780 | 776 | * - index 1 : Code de l'affectation |
| 781 | 777 | **/ |
| 782 | 778 | function calculer_dec($nom, $val) { |
| 783 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 779 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 784 | 780 | // si une variable apparait dans le calcul de la clause |
| 785 | 781 | // il faut la re-evaluer a chaque passage |
| 786 | 782 | if ( |
@@ -797,7 +793,7 @@ discard block |
||
| 797 | 793 | $static = ''; |
| 798 | 794 | } |
| 799 | 795 | |
| 800 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 796 | + return [$static, '$command[\''.$nom.'\'] = '.$val.';']; |
|
| 801 | 797 | } |
| 802 | 798 | |
| 803 | 799 | /** |
@@ -822,17 +818,17 @@ discard block |
||
| 822 | 818 | } |
| 823 | 819 | $res = ''; |
| 824 | 820 | if ($a and $a[0] == "'?'") { |
| 825 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 826 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 827 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 821 | + return ('('.calculer_dump_array($a[1]). |
|
| 822 | + ' ? '.calculer_dump_array($a[2]). |
|
| 823 | + ' : '.calculer_dump_array($a[3]). |
|
| 828 | 824 | ')'); |
| 829 | 825 | } else { |
| 830 | 826 | foreach ($a as $k => $v) { |
| 831 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 832 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 827 | + $showk = (is_numeric($k) ? '' : sql_quote($k).' => '); |
|
| 828 | + $res .= ', '.$showk.calculer_dump_array($v); |
|
| 833 | 829 | } |
| 834 | 830 | |
| 835 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 831 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 836 | 832 | } |
| 837 | 833 | } |
| 838 | 834 | |
@@ -840,10 +836,10 @@ discard block |
||
| 840 | 836 | function calculer_dump_join($a) { |
| 841 | 837 | $res = ''; |
| 842 | 838 | foreach ($a as $k => $v) { |
| 843 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 839 | + $res .= ", '$k' => array(".implode(',', $v).')'; |
|
| 844 | 840 | } |
| 845 | 841 | |
| 846 | - return 'array(' . substr($res, 2) . ')'; |
|
| 842 | + return 'array('.substr($res, 2).')'; |
|
| 847 | 843 | } |
| 848 | 844 | |
| 849 | 845 | /** |
@@ -860,7 +856,7 @@ discard block |
||
| 860 | 856 | $res .= ",'$k' => '$v'"; |
| 861 | 857 | } |
| 862 | 858 | |
| 863 | - return 'array(' . substr($res, 1) . ')'; |
|
| 859 | + return 'array('.substr($res, 1).')'; |
|
| 864 | 860 | } |
| 865 | 861 | |
| 866 | 862 | /** |
@@ -878,7 +874,7 @@ discard block |
||
| 878 | 874 | $res .= ",'$k' => '$v'"; |
| 879 | 875 | } |
| 880 | 876 | |
| 881 | - return 'array(' . substr($res, 1) . ')'; |
|
| 877 | + return 'array('.substr($res, 1).')'; |
|
| 882 | 878 | } |
| 883 | 879 | |
| 884 | 880 | // https://code.spip.net/@calculer_order |
@@ -949,19 +945,19 @@ discard block |
||
| 949 | 945 | ) { |
| 950 | 946 | $res .= " .\n$tab$code"; |
| 951 | 947 | } else { |
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 948 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 953 | 949 | } |
| 954 | 950 | } |
| 955 | 951 | |
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 952 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 957 | 953 | } |
| 958 | 954 | } else { |
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 955 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 960 | 956 | |
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 957 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join( |
|
| 962 | 958 | " ,\n$tab", |
| 963 | 959 | $codes |
| 964 | - ) . ')))'; |
|
| 960 | + ).')))'; |
|
| 965 | 961 | } |
| 966 | 962 | } |
| 967 | 963 | |
@@ -989,7 +985,7 @@ discard block |
||
| 989 | 985 | // texte seul |
| 990 | 986 | case 'texte': |
| 991 | 987 | $code = sandbox_composer_texte($p->texte, $p); |
| 992 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 988 | + $commentaire = strlen($p->texte).' signes'; |
|
| 993 | 989 | $avant = ''; |
| 994 | 990 | $apres = ''; |
| 995 | 991 | $altern = "''"; |
@@ -998,14 +994,14 @@ discard block |
||
| 998 | 994 | case 'polyglotte': |
| 999 | 995 | $code = ''; |
| 1000 | 996 | foreach ($p->traductions as $k => $v) { |
| 1001 | - $code .= ",'" . |
|
| 1002 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1003 | - "' => '" . |
|
| 1004 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 997 | + $code .= ",'". |
|
| 998 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k). |
|
| 999 | + "' => '". |
|
| 1000 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v). |
|
| 1005 | 1001 | "'"; |
| 1006 | 1002 | } |
| 1007 | - $code = 'choisir_traduction(array(' . |
|
| 1008 | - substr($code, 1) . |
|
| 1003 | + $code = 'choisir_traduction(array('. |
|
| 1004 | + substr($code, 1). |
|
| 1009 | 1005 | '))'; |
| 1010 | 1006 | $commentaire = '&'; |
| 1011 | 1007 | $avant = ''; |
@@ -1021,7 +1017,7 @@ discard block |
||
| 1021 | 1017 | $err_e_c = true; |
| 1022 | 1018 | $code = "''"; |
| 1023 | 1019 | } else { |
| 1024 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1020 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 1025 | 1021 | $avant = ''; |
| 1026 | 1022 | $apres = ''; |
| 1027 | 1023 | $altern = "''"; |
@@ -1050,8 +1046,8 @@ discard block |
||
| 1050 | 1046 | $err_e_c = true; |
| 1051 | 1047 | $code = "''"; |
| 1052 | 1048 | } else { |
| 1053 | - $code = 'BOUCLE' . |
|
| 1054 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1049 | + $code = 'BOUCLE'. |
|
| 1050 | + str_replace('-', '_', $nom).$descr['nom']. |
|
| 1055 | 1051 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1056 | 1052 | $commentaire = "?$nom"; |
| 1057 | 1053 | if ( |
@@ -1093,24 +1089,22 @@ discard block |
||
| 1093 | 1089 | foreach ($p->arg as $k => $v) { |
| 1094 | 1090 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1095 | 1091 | if ($k) { |
| 1096 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1092 | + $l[] = _q($k).' => '.$_v; |
|
| 1097 | 1093 | } else { |
| 1098 | 1094 | $code = $_v; |
| 1099 | 1095 | } |
| 1100 | 1096 | } |
| 1101 | 1097 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1102 | 1098 | if ($p->module) { |
| 1103 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1099 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1104 | 1100 | } elseif ($p->nom_champ) { |
| 1105 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1101 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1106 | 1102 | } else { |
| 1107 | 1103 | $m = ''; |
| 1108 | 1104 | } |
| 1109 | 1105 | |
| 1110 | - $code = (!$code ? "'$m'" : |
|
| 1111 | - ($m ? "'$m' . $code" : |
|
| 1112 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1113 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1106 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1107 | + . (!$l ? '' : (', array('.implode(",\n", $l).')')); |
|
| 1114 | 1108 | $code = "_T($code)"; |
| 1115 | 1109 | if ($p->param) { |
| 1116 | 1110 | $p->id_boucle = $id_boucle; |
@@ -1132,7 +1126,7 @@ discard block |
||
| 1132 | 1126 | $p->type_requete = $type; |
| 1133 | 1127 | |
| 1134 | 1128 | $code = calculer_champ($p); |
| 1135 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1129 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1136 | 1130 | $avant = calculer_liste( |
| 1137 | 1131 | $p->avant, |
| 1138 | 1132 | $descr, |
@@ -1172,10 +1166,9 @@ discard block |
||
| 1172 | 1166 | if ($code != "''") { |
| 1173 | 1167 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1174 | 1168 | $codes[] = (($mode == 'validation') ? |
| 1175 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1169 | + "array($code, '$commentaire', ".$p->ligne.')' |
|
| 1176 | 1170 | : (($mode == 'code') ? |
| 1177 | - "\n// $commentaire\n$code" : |
|
| 1178 | - $code)); |
|
| 1171 | + "\n// $commentaire\n$code" : $code)); |
|
| 1179 | 1172 | } |
| 1180 | 1173 | } // foreach |
| 1181 | 1174 | |
@@ -1232,19 +1225,19 @@ discard block |
||
| 1232 | 1225 | $cond = ''; |
| 1233 | 1226 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1234 | 1227 | $t = $r[2]; |
| 1235 | - $cond = '!' . $r[1]; |
|
| 1228 | + $cond = '!'.$r[1]; |
|
| 1236 | 1229 | } else { |
| 1237 | 1230 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1238 | 1231 | $t = $r[2]; |
| 1239 | 1232 | $cond = $r[1]; |
| 1240 | 1233 | } else { |
| 1241 | - $t = '$t' . $n; |
|
| 1234 | + $t = '$t'.$n; |
|
| 1242 | 1235 | $cond = "($t = $code)!==''"; |
| 1243 | 1236 | } |
| 1244 | 1237 | } |
| 1245 | 1238 | |
| 1246 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1247 | - $t . |
|
| 1239 | + $res = (!$avant ? '' : "$avant . "). |
|
| 1240 | + $t. |
|
| 1248 | 1241 | (!$apres ? '' : " . $apres"); |
| 1249 | 1242 | |
| 1250 | 1243 | if ($res !== $t) { |
@@ -1296,13 +1289,13 @@ discard block |
||
| 1296 | 1289 | |
| 1297 | 1290 | // rendre inertes les echappements de #[](){}<> |
| 1298 | 1291 | $i = 0; |
| 1299 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1292 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1300 | 1293 | $i++; |
| 1301 | 1294 | } |
| 1302 | 1295 | $squelette = preg_replace_callback( |
| 1303 | 1296 | ',\\\\([#[()\]{}<>]),', |
| 1304 | - function ($a) use ($inerte) { |
|
| 1305 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1297 | + function($a) use ($inerte) { |
|
| 1298 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1306 | 1299 | }, |
| 1307 | 1300 | $squelette, |
| 1308 | 1301 | -1, |
@@ -1319,7 +1312,7 @@ discard block |
||
| 1319 | 1312 | // Phraser le squelette, selon sa grammaire |
| 1320 | 1313 | |
| 1321 | 1314 | $boucles = []; |
| 1322 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1315 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1323 | 1316 | |
| 1324 | 1317 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1325 | 1318 | |
@@ -1330,15 +1323,15 @@ discard block |
||
| 1330 | 1323 | foreach ($boucles as $i => $boucle) { |
| 1331 | 1324 | $boucles[$i]->return = preg_replace_callback( |
| 1332 | 1325 | ",$inerte-(\d+)-,", |
| 1333 | - function ($a) { |
|
| 1326 | + function($a) { |
|
| 1334 | 1327 | return chr($a[1]); |
| 1335 | 1328 | }, |
| 1336 | 1329 | $boucle->return |
| 1337 | 1330 | ); |
| 1338 | 1331 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1339 | 1332 | ",$inerte-(\d+)-,", |
| 1340 | - function ($a) { |
|
| 1341 | - return '\\\\' . chr($a[1]); |
|
| 1333 | + function($a) { |
|
| 1334 | + return '\\\\'.chr($a[1]); |
|
| 1342 | 1335 | }, |
| 1343 | 1336 | $boucle->descr['squelette'] |
| 1344 | 1337 | ); |
@@ -1350,19 +1343,19 @@ discard block |
||
| 1350 | 1343 | include_spip('public/decompiler'); |
| 1351 | 1344 | foreach ($boucles as $id => $boucle) { |
| 1352 | 1345 | if ($id) { |
| 1353 | - $decomp = "\n/* BOUCLE " . |
|
| 1354 | - $boucle->type_requete . |
|
| 1355 | - ' ' . |
|
| 1356 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1346 | + $decomp = "\n/* BOUCLE ". |
|
| 1347 | + $boucle->type_requete. |
|
| 1348 | + ' '. |
|
| 1349 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1350 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1358 | 1351 | " */\n"; |
| 1359 | 1352 | } else { |
| 1360 | - $decomp = ("\n/*\n" . |
|
| 1353 | + $decomp = ("\n/*\n". |
|
| 1361 | 1354 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1362 | 1355 | . "\n*/"); |
| 1363 | 1356 | } |
| 1364 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1358 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1366 | 1359 | } |
| 1367 | 1360 | } |
| 1368 | 1361 | |
@@ -1385,7 +1378,7 @@ discard block |
||
| 1385 | 1378 | } |
| 1386 | 1379 | } |
| 1387 | 1380 | foreach ($boucles as $id => $boucle) { |
| 1388 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1381 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1389 | 1382 | } |
| 1390 | 1383 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1391 | 1384 | |
@@ -1476,8 +1469,7 @@ discard block |
||
| 1476 | 1469 | } else { |
| 1477 | 1470 | $boucles[$id]->type_requete = false; |
| 1478 | 1471 | $boucle = $boucles[$id]; |
| 1479 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | - ($boucle->sql_serveur . ':')) . |
|
| 1472 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.':')). |
|
| 1481 | 1473 | $type; |
| 1482 | 1474 | $msg = [ |
| 1483 | 1475 | 'zbug_table_inconnue', |
@@ -1567,13 +1559,13 @@ discard block |
||
| 1567 | 1559 | if ( |
| 1568 | 1560 | // fonction de boucle avec serveur & table |
| 1569 | 1561 | (!$serveur or |
| 1570 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | - and (!function_exists($f = $f . '_dist')) |
|
| 1562 | + ((!function_exists($f = 'boucle_'.$serveur.'_'.$table)) |
|
| 1563 | + and (!function_exists($f = $f.'_dist')) |
|
| 1572 | 1564 | ) |
| 1573 | 1565 | ) |
| 1574 | 1566 | // fonction de boucle avec table |
| 1575 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | - and (!function_exists($f = $f . '_dist')) |
|
| 1567 | + and (!function_exists($f = 'boucle_'.$table)) |
|
| 1568 | + and (!function_exists($f = $f.'_dist')) |
|
| 1577 | 1569 | ) { |
| 1578 | 1570 | // fonction de boucle standard |
| 1579 | 1571 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1581,20 +1573,20 @@ discard block |
||
| 1581 | 1573 | } |
| 1582 | 1574 | } |
| 1583 | 1575 | |
| 1584 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | - "static \$connect;\n\t" . |
|
| 1586 | - "\$command['connect'] = \$connect = " . |
|
| 1587 | - _q($boucle->sql_serveur) . |
|
| 1588 | - ';' . |
|
| 1576 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1577 | + "static \$connect;\n\t". |
|
| 1578 | + "\$command['connect'] = \$connect = ". |
|
| 1579 | + _q($boucle->sql_serveur). |
|
| 1580 | + ';'. |
|
| 1589 | 1581 | $f($id, $boucles); |
| 1590 | 1582 | } else { |
| 1591 | 1583 | $req = ("\n\treturn '';"); |
| 1592 | 1584 | } |
| 1593 | 1585 | |
| 1594 | 1586 | $boucles[$id]->return = |
| 1595 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | - $req . |
|
| 1587 | + "\n\nfunction BOUCLE".strtr($id, '-', '_').$nom. |
|
| 1588 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1589 | + $req. |
|
| 1598 | 1590 | "\n}\n"; |
| 1599 | 1591 | } |
| 1600 | 1592 | |
@@ -1604,7 +1596,7 @@ discard block |
||
| 1604 | 1596 | return false; |
| 1605 | 1597 | } |
| 1606 | 1598 | |
| 1607 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1608 | 1600 | ' |
| 1609 | 1601 | // reporter de maniere securisee les doublons inclus |
| 1610 | 1602 | . ' |
@@ -1612,15 +1604,15 @@ discard block |
||
| 1612 | 1604 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1613 | 1605 | |
| 1614 | 1606 | $connect = ' . |
| 1615 | - _q($connect) . '; |
|
| 1607 | + _q($connect).'; |
|
| 1616 | 1608 | $page = ' . |
| 1617 | 1609 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1618 | 1610 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1619 | 1611 | // avant de referencer $Cache |
| 1620 | - $corps . '; |
|
| 1612 | + $corps.'; |
|
| 1621 | 1613 | |
| 1622 | 1614 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1623 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1615 | + . ', $Cache, $page, '.var_export($sourcefile, true).'); |
|
| 1624 | 1616 | }'; |
| 1625 | 1617 | |
| 1626 | 1618 | $secondes = spip_timer('calcul_skel'); |
@@ -1634,10 +1626,10 @@ discard block |
||
| 1634 | 1626 | $code->return = ' |
| 1635 | 1627 | // |
| 1636 | 1628 | // Fonction principale du squelette ' . |
| 1637 | - $sourcefile . |
|
| 1638 | - ($connect ? " pour $connect" : '') . |
|
| 1639 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | - "\n//\n" . |
|
| 1629 | + $sourcefile. |
|
| 1630 | + ($connect ? " pour $connect" : ''). |
|
| 1631 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1632 | + "\n//\n". |
|
| 1641 | 1633 | $principal; |
| 1642 | 1634 | |
| 1643 | 1635 | $boucles[''] = $code; |
@@ -1689,7 +1681,7 @@ discard block |
||
| 1689 | 1681 | **/ |
| 1690 | 1682 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1691 | 1683 | include_spip('iterateur/data'); |
| 1692 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1693 | 1685 | $g = charger_fonction('data', 'iterateur'); |
| 1694 | 1686 | $boucles[$id] = $g($boucle); |
| 1695 | 1687 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -920,8 +920,7 @@ |
||
| 920 | 920 | if (isset($boucles[$idb]->descr['sourcefile'])) { |
| 921 | 921 | $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
| 922 | 922 | } |
| 923 | - } |
|
| 924 | - else { |
|
| 923 | + } else { |
|
| 925 | 924 | $descr = []; |
| 926 | 925 | } |
| 927 | 926 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** Début de la partie principale d'une boucle */ |
@@ -65,83 +65,83 @@ discard block |
||
| 65 | 65 | // https://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
| 67 | 67 | |
| 68 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | - $match = array_pad($match, 3, null); |
|
| 70 | - $p = strpos($texte, $match[0]); |
|
| 71 | - $debut = substr($texte, 0, $p); |
|
| 72 | - if ($p) { |
|
| 73 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | - } |
|
| 75 | - $ligne += substr_count($debut, "\n"); |
|
| 76 | - $champ = new Inclure(); |
|
| 77 | - $champ->ligne = $ligne; |
|
| 78 | - $ligne += substr_count($match[0], "\n"); |
|
| 79 | - $fichier = $match[2]; |
|
| 80 | - # assurer ici la migration .php3 => .php |
|
| 81 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | - $fichier = $r[1]; |
|
| 84 | - } |
|
| 85 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | - $pos_apres = 0; |
|
| 89 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | - if (!function_exists('normaliser_inclure')) { |
|
| 92 | - include_spip('public/normaliser'); |
|
| 93 | - } |
|
| 94 | - normaliser_inclure($champ); |
|
| 95 | - } |
|
| 96 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | - $result[] = $champ; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 68 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | + $match = array_pad($match, 3, null); |
|
| 70 | + $p = strpos($texte, $match[0]); |
|
| 71 | + $debut = substr($texte, 0, $p); |
|
| 72 | + if ($p) { |
|
| 73 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | + } |
|
| 75 | + $ligne += substr_count($debut, "\n"); |
|
| 76 | + $champ = new Inclure(); |
|
| 77 | + $champ->ligne = $ligne; |
|
| 78 | + $ligne += substr_count($match[0], "\n"); |
|
| 79 | + $fichier = $match[2]; |
|
| 80 | + # assurer ici la migration .php3 => .php |
|
| 81 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | + $fichier = $r[1]; |
|
| 84 | + } |
|
| 85 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | + $pos_apres = 0; |
|
| 89 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | + if (!function_exists('normaliser_inclure')) { |
|
| 92 | + include_spip('public/normaliser'); |
|
| 93 | + } |
|
| 94 | + normaliser_inclure($champ); |
|
| 95 | + } |
|
| 96 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | + $result[] = $champ; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // https://code.spip.net/@phraser_polyglotte |
| 105 | 105 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 106 | |
| 107 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | - foreach ($m as $match) { |
|
| 109 | - $p = strpos($texte, $match[0]); |
|
| 110 | - $debut = substr($texte, 0, $p); |
|
| 111 | - if ($p) { |
|
| 112 | - $champ = new Texte(); |
|
| 113 | - $champ->texte = $debut; |
|
| 114 | - $champ->ligne = $ligne; |
|
| 115 | - $result[] = $champ; |
|
| 116 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $champ = new Polyglotte(); |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $ligne += substr_count($match[0], "\n"); |
|
| 122 | - $lang = ''; |
|
| 123 | - $bloc = $match[1]; |
|
| 124 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | - $trad = $regs[1]; |
|
| 127 | - if ($trad or $lang) { |
|
| 128 | - $champ->traductions[$lang] = $trad; |
|
| 129 | - } |
|
| 130 | - $lang = $regs[2]; |
|
| 131 | - $bloc = $regs[3]; |
|
| 132 | - } |
|
| 133 | - $champ->traductions[$lang] = $bloc; |
|
| 134 | - $result[] = $champ; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if ($texte !== '') { |
|
| 138 | - $champ = new Texte(); |
|
| 139 | - $champ->texte = $texte; |
|
| 140 | - $champ->ligne = $ligne; |
|
| 141 | - $result[] = $champ; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $result; |
|
| 107 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | + foreach ($m as $match) { |
|
| 109 | + $p = strpos($texte, $match[0]); |
|
| 110 | + $debut = substr($texte, 0, $p); |
|
| 111 | + if ($p) { |
|
| 112 | + $champ = new Texte(); |
|
| 113 | + $champ->texte = $debut; |
|
| 114 | + $champ->ligne = $ligne; |
|
| 115 | + $result[] = $champ; |
|
| 116 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $champ = new Polyglotte(); |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $ligne += substr_count($match[0], "\n"); |
|
| 122 | + $lang = ''; |
|
| 123 | + $bloc = $match[1]; |
|
| 124 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | + $trad = $regs[1]; |
|
| 127 | + if ($trad or $lang) { |
|
| 128 | + $champ->traductions[$lang] = $trad; |
|
| 129 | + } |
|
| 130 | + $lang = $regs[2]; |
|
| 131 | + $bloc = $regs[3]; |
|
| 132 | + } |
|
| 133 | + $champ->traductions[$lang] = $bloc; |
|
| 134 | + $result[] = $champ; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if ($texte !== '') { |
|
| 138 | + $champ = new Texte(); |
|
| 139 | + $champ->texte = $texte; |
|
| 140 | + $champ->ligne = $ligne; |
|
| 141 | + $result[] = $champ; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $result; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -163,43 +163,43 @@ discard block |
||
| 163 | 163 | * @return array |
| 164 | 164 | **/ |
| 165 | 165 | function phraser_idiomes($texte, $ligne, $result) { |
| 166 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | - $match = array_pad($match, 8, null); |
|
| 168 | - $p = strpos($texte, $match[0]); |
|
| 169 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | - if ($debut) { |
|
| 172 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | - } |
|
| 174 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | - $ligne += substr_count($debut, "\n"); |
|
| 176 | - if ($ko) { |
|
| 177 | - continue; |
|
| 178 | - } // faux idiome |
|
| 179 | - $champ = new Idiome(); |
|
| 180 | - $champ->ligne = $ligne; |
|
| 181 | - $ligne += substr_count($match[0], "\n"); |
|
| 182 | - // Stocker les arguments de la balise de traduction |
|
| 183 | - $args = []; |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | - $largs = substr($largs, strlen($r[0])); |
|
| 188 | - } |
|
| 189 | - $champ->arg = $args; |
|
| 190 | - $champ->nom_champ = strtolower($match[3]); |
|
| 191 | - $champ->module = $match[2]; |
|
| 192 | - // pas d'imbrication pour les filtres sur langue |
|
| 193 | - $pos_apres = 0; |
|
| 194 | - phraser_args($match[7], ':', '', [], $champ, $pos_apres); |
|
| 195 | - $champ->apres = substr($match[7], $pos_apres); |
|
| 196 | - $result[] = $champ; |
|
| 197 | - } |
|
| 198 | - if ($texte !== '') { |
|
| 199 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $result; |
|
| 166 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | + $match = array_pad($match, 8, null); |
|
| 168 | + $p = strpos($texte, $match[0]); |
|
| 169 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | + if ($debut) { |
|
| 172 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | + } |
|
| 174 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | + $ligne += substr_count($debut, "\n"); |
|
| 176 | + if ($ko) { |
|
| 177 | + continue; |
|
| 178 | + } // faux idiome |
|
| 179 | + $champ = new Idiome(); |
|
| 180 | + $champ->ligne = $ligne; |
|
| 181 | + $ligne += substr_count($match[0], "\n"); |
|
| 182 | + // Stocker les arguments de la balise de traduction |
|
| 183 | + $args = []; |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | + $largs = substr($largs, strlen($r[0])); |
|
| 188 | + } |
|
| 189 | + $champ->arg = $args; |
|
| 190 | + $champ->nom_champ = strtolower($match[3]); |
|
| 191 | + $champ->module = $match[2]; |
|
| 192 | + // pas d'imbrication pour les filtres sur langue |
|
| 193 | + $pos_apres = 0; |
|
| 194 | + phraser_args($match[7], ':', '', [], $champ, $pos_apres); |
|
| 195 | + $champ->apres = substr($match[7], $pos_apres); |
|
| 196 | + $result[] = $champ; |
|
| 197 | + } |
|
| 198 | + if ($texte !== '') { |
|
| 199 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $result; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -217,47 +217,47 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | - $p = strpos($texte, $match[0]); |
|
| 222 | - // texte après la balise |
|
| 223 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | - |
|
| 225 | - $debut = substr($texte, 0, $p); |
|
| 226 | - if ($p) { |
|
| 227 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | - } |
|
| 229 | - $ligne += substr_count($debut, "\n"); |
|
| 230 | - $champ = new Champ(); |
|
| 231 | - $champ->ligne = $ligne; |
|
| 232 | - $ligne += substr_count($match[0], "\n"); |
|
| 233 | - $champ->nom_boucle = $match[2]; |
|
| 234 | - $champ->nom_champ = $match[3]; |
|
| 235 | - $champ->etoile = $match[5]; |
|
| 236 | - |
|
| 237 | - if ($suite and $suite[0] == '{') { |
|
| 238 | - phraser_arg($suite, '', [], $champ); |
|
| 239 | - // ce ltrim est une ereur de conception |
|
| 240 | - // mais on le conserve par souci de compatibilite |
|
| 241 | - $texte = ltrim($suite); |
|
| 242 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 220 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | + $p = strpos($texte, $match[0]); |
|
| 222 | + // texte après la balise |
|
| 223 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | + |
|
| 225 | + $debut = substr($texte, 0, $p); |
|
| 226 | + if ($p) { |
|
| 227 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | + } |
|
| 229 | + $ligne += substr_count($debut, "\n"); |
|
| 230 | + $champ = new Champ(); |
|
| 231 | + $champ->ligne = $ligne; |
|
| 232 | + $ligne += substr_count($match[0], "\n"); |
|
| 233 | + $champ->nom_boucle = $match[2]; |
|
| 234 | + $champ->nom_champ = $match[3]; |
|
| 235 | + $champ->etoile = $match[5]; |
|
| 236 | + |
|
| 237 | + if ($suite and $suite[0] == '{') { |
|
| 238 | + phraser_arg($suite, '', [], $champ); |
|
| 239 | + // ce ltrim est une ereur de conception |
|
| 240 | + // mais on le conserve par souci de compatibilite |
|
| 241 | + $texte = ltrim($suite); |
|
| 242 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 245 | 245 | if ($n = (strlen($suite) - strlen($texte))) { |
| 246 | 246 | $champ->apres = array(new Texte); |
| 247 | 247 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 248 | 248 | } |
| 249 | 249 | */ |
| 250 | - } else { |
|
| 251 | - $texte = $suite; |
|
| 252 | - } |
|
| 253 | - phraser_vieux($champ); |
|
| 254 | - $result[] = $champ; |
|
| 255 | - } |
|
| 256 | - if ($texte !== '') { |
|
| 257 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $result; |
|
| 250 | + } else { |
|
| 251 | + $texte = $suite; |
|
| 252 | + } |
|
| 253 | + phraser_vieux($champ); |
|
| 254 | + $result[] = $champ; |
|
| 255 | + } |
|
| 256 | + if ($texte !== '') { |
|
| 257 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $result; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Gestion des imbrications: |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // https://code.spip.net/@phraser_champs_etendus |
| 269 | 269 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 270 | - if ($texte === '') { |
|
| 271 | - return $result; |
|
| 272 | - } |
|
| 273 | - $sep = '##'; |
|
| 274 | - while (strpos($texte, $sep) !== false) { |
|
| 275 | - $sep .= '#'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 270 | + if ($texte === '') { |
|
| 271 | + return $result; |
|
| 272 | + } |
|
| 273 | + $sep = '##'; |
|
| 274 | + while (strpos($texte, $sep) !== false) { |
|
| 275 | + $sep .= '#'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -296,278 +296,278 @@ discard block |
||
| 296 | 296 | * @return array |
| 297 | 297 | */ |
| 298 | 298 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 299 | - $length = strlen($texte); |
|
| 300 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | - $pos_debut++; |
|
| 302 | - } |
|
| 303 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | - $st = substr($texte, $pos_debut); |
|
| 306 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | - $pos_debut = $length - strlen($st); |
|
| 308 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | - $pos_debut++; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $result; |
|
| 299 | + $length = strlen($texte); |
|
| 300 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | + $pos_debut++; |
|
| 302 | + } |
|
| 303 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | + $st = substr($texte, $pos_debut); |
|
| 306 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | + $pos_debut = $length - strlen($st); |
|
| 308 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | + $pos_debut++; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $result; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // https://code.spip.net/@phraser_arg |
| 317 | 317 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 318 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | - $suite = ltrim($match[2]); |
|
| 320 | - $fonc = trim($match[1]); |
|
| 321 | - if ($fonc && $fonc[0] == '|') { |
|
| 322 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | - } |
|
| 324 | - $res = [$fonc]; |
|
| 325 | - $err_f = ''; |
|
| 326 | - // cas du filtre sans argument ou du critere / |
|
| 327 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | - if (!$match[1]) { |
|
| 330 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | - $texte = ''; |
|
| 333 | - } else { |
|
| 334 | - $texte = $suite; |
|
| 335 | - } |
|
| 336 | - if ($err_f) { |
|
| 337 | - $pointeur_champ->param = false; |
|
| 338 | - } elseif ($fonc !== '') { |
|
| 339 | - $pointeur_champ->param[] = $res; |
|
| 340 | - } |
|
| 341 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | - |
|
| 344 | - return $result; |
|
| 345 | - } |
|
| 346 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | - $collecte = []; |
|
| 348 | - while ($args && $args[0] != '}') { |
|
| 349 | - if ($args[0] == '"') { |
|
| 350 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | - } elseif ($args[0] == "'") { |
|
| 352 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | - } else { |
|
| 354 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | - $champ = new Texte(); |
|
| 359 | - $champ->apres = $champ->avant = $args = ''; |
|
| 360 | - break; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - $arg = $regs[2]; |
|
| 364 | - if (trim($regs[1])) { |
|
| 365 | - $champ = new Texte(); |
|
| 366 | - $champ->texte = $arg; |
|
| 367 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | - $result[] = $champ; |
|
| 369 | - $collecte[] = $champ; |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - } else { |
|
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | - // 0 est un aveu d'impuissance. A completer |
|
| 374 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | - |
|
| 376 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | - $collecte = array_merge($collecte, $arg); |
|
| 378 | - $result = array_merge($result, $arg); |
|
| 379 | - } else { |
|
| 380 | - $n = strpos($args, $r[0]); |
|
| 381 | - $pred = substr($args, 0, $n); |
|
| 382 | - $par = ',}'; |
|
| 383 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | - $pred = $m[1]; |
|
| 385 | - $par = ')'; |
|
| 386 | - } |
|
| 387 | - if ($pred) { |
|
| 388 | - $champ = new Texte(); |
|
| 389 | - $champ->texte = $pred; |
|
| 390 | - $champ->apres = $champ->avant = ''; |
|
| 391 | - $result[] = $champ; |
|
| 392 | - $collecte[] = $champ; |
|
| 393 | - } |
|
| 394 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | - $champ = new Champ(); |
|
| 396 | - $champ->nom_boucle = $r[2]; |
|
| 397 | - $champ->nom_champ = $r[3]; |
|
| 398 | - $champ->etoile = $r[5]; |
|
| 399 | - $next = $r[6]; |
|
| 400 | - while ($next == '{') { |
|
| 401 | - phraser_arg($rec, $sep, [], $champ); |
|
| 402 | - $args = ltrim($rec); |
|
| 403 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | - } |
|
| 405 | - while ($next == '|') { |
|
| 406 | - $pos_apres = 0; |
|
| 407 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | - $args = substr($rec, $pos_apres); |
|
| 409 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | - } |
|
| 411 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | - if ($champ->param === false) { |
|
| 413 | - $err_f = true; |
|
| 414 | - } else { |
|
| 415 | - phraser_vieux($champ); |
|
| 416 | - } |
|
| 417 | - if ($par == ')') { |
|
| 418 | - $args = substr($args, 1); |
|
| 419 | - } |
|
| 420 | - $collecte[] = $champ; |
|
| 421 | - $result[] = $champ; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | - $args = ltrim(substr($args, 1)); |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - if ($collecte) { |
|
| 433 | - $res[] = $collecte; |
|
| 434 | - $collecte = []; |
|
| 435 | - } |
|
| 436 | - $texte = substr($args, 1); |
|
| 437 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | - // propager les erreurs, et ignorer les param vides |
|
| 439 | - if ($pointeur_champ->param !== false) { |
|
| 440 | - if ($err_f) { |
|
| 441 | - $pointeur_champ->param = false; |
|
| 442 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | - $pointeur_champ->param[] = $res; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | - |
|
| 449 | - return $result; |
|
| 318 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | + $suite = ltrim($match[2]); |
|
| 320 | + $fonc = trim($match[1]); |
|
| 321 | + if ($fonc && $fonc[0] == '|') { |
|
| 322 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | + } |
|
| 324 | + $res = [$fonc]; |
|
| 325 | + $err_f = ''; |
|
| 326 | + // cas du filtre sans argument ou du critere / |
|
| 327 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | + if (!$match[1]) { |
|
| 330 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | + $texte = ''; |
|
| 333 | + } else { |
|
| 334 | + $texte = $suite; |
|
| 335 | + } |
|
| 336 | + if ($err_f) { |
|
| 337 | + $pointeur_champ->param = false; |
|
| 338 | + } elseif ($fonc !== '') { |
|
| 339 | + $pointeur_champ->param[] = $res; |
|
| 340 | + } |
|
| 341 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | + |
|
| 344 | + return $result; |
|
| 345 | + } |
|
| 346 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | + $collecte = []; |
|
| 348 | + while ($args && $args[0] != '}') { |
|
| 349 | + if ($args[0] == '"') { |
|
| 350 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | + } elseif ($args[0] == "'") { |
|
| 352 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | + } else { |
|
| 354 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | + $champ = new Texte(); |
|
| 359 | + $champ->apres = $champ->avant = $args = ''; |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + $arg = $regs[2]; |
|
| 364 | + if (trim($regs[1])) { |
|
| 365 | + $champ = new Texte(); |
|
| 366 | + $champ->texte = $arg; |
|
| 367 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | + $result[] = $champ; |
|
| 369 | + $collecte[] = $champ; |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + } else { |
|
| 372 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | + // 0 est un aveu d'impuissance. A completer |
|
| 374 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | + |
|
| 376 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | + $collecte = array_merge($collecte, $arg); |
|
| 378 | + $result = array_merge($result, $arg); |
|
| 379 | + } else { |
|
| 380 | + $n = strpos($args, $r[0]); |
|
| 381 | + $pred = substr($args, 0, $n); |
|
| 382 | + $par = ',}'; |
|
| 383 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | + $pred = $m[1]; |
|
| 385 | + $par = ')'; |
|
| 386 | + } |
|
| 387 | + if ($pred) { |
|
| 388 | + $champ = new Texte(); |
|
| 389 | + $champ->texte = $pred; |
|
| 390 | + $champ->apres = $champ->avant = ''; |
|
| 391 | + $result[] = $champ; |
|
| 392 | + $collecte[] = $champ; |
|
| 393 | + } |
|
| 394 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | + $champ = new Champ(); |
|
| 396 | + $champ->nom_boucle = $r[2]; |
|
| 397 | + $champ->nom_champ = $r[3]; |
|
| 398 | + $champ->etoile = $r[5]; |
|
| 399 | + $next = $r[6]; |
|
| 400 | + while ($next == '{') { |
|
| 401 | + phraser_arg($rec, $sep, [], $champ); |
|
| 402 | + $args = ltrim($rec); |
|
| 403 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | + } |
|
| 405 | + while ($next == '|') { |
|
| 406 | + $pos_apres = 0; |
|
| 407 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | + $args = substr($rec, $pos_apres); |
|
| 409 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | + } |
|
| 411 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | + if ($champ->param === false) { |
|
| 413 | + $err_f = true; |
|
| 414 | + } else { |
|
| 415 | + phraser_vieux($champ); |
|
| 416 | + } |
|
| 417 | + if ($par == ')') { |
|
| 418 | + $args = substr($args, 1); |
|
| 419 | + } |
|
| 420 | + $collecte[] = $champ; |
|
| 421 | + $result[] = $champ; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | + $args = ltrim(substr($args, 1)); |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + if ($collecte) { |
|
| 433 | + $res[] = $collecte; |
|
| 434 | + $collecte = []; |
|
| 435 | + } |
|
| 436 | + $texte = substr($args, 1); |
|
| 437 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | + // propager les erreurs, et ignorer les param vides |
|
| 439 | + if ($pointeur_champ->param !== false) { |
|
| 440 | + if ($err_f) { |
|
| 441 | + $pointeur_champ->param = false; |
|
| 442 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | + $pointeur_champ->param[] = $res; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | + |
|
| 449 | + return $result; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| 453 | 453 | // https://code.spip.net/@phraser_champs_exterieurs |
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | - $res = []; |
|
| 456 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - $debut = substr($texte, 0, $p); |
|
| 461 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | - if ($p) { |
|
| 463 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | - } |
|
| 465 | - $ligne += substr_count($debut, "\n"); |
|
| 466 | - $res[] = $nested[$m[1]]; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 455 | + $res = []; |
|
| 456 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + $debut = substr($texte, 0, $p); |
|
| 461 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | + if ($p) { |
|
| 463 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | + } |
|
| 465 | + $ligne += substr_count($debut, "\n"); |
|
| 466 | + $res[] = $nested[$m[1]]; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // https://code.spip.net/@phraser_champs_interieurs |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,201 +595,201 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = ''; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = ''; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = array_merge($args, $doublons); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = ''; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = ''; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = array_merge($args, $doublons); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | // https://code.spip.net/@phraser_critere_infixe |
| 780 | 780 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 781 | - $args[0] = new Texte(); |
|
| 782 | - $args[0]->texte = $arg1; |
|
| 783 | - $args[0] = [$args[0]]; |
|
| 784 | - $args[1][0] = new Texte(); |
|
| 785 | - $args[1][0]->texte = $arg2; |
|
| 786 | - $crit = new Critere(); |
|
| 787 | - $crit->op = $op; |
|
| 788 | - $crit->not = $not; |
|
| 789 | - $crit->cond = $cond; |
|
| 790 | - $crit->param = $args; |
|
| 791 | - |
|
| 792 | - return $crit; |
|
| 781 | + $args[0] = new Texte(); |
|
| 782 | + $args[0]->texte = $arg1; |
|
| 783 | + $args[0] = [$args[0]]; |
|
| 784 | + $args[1][0] = new Texte(); |
|
| 785 | + $args[1][0]->texte = $arg2; |
|
| 786 | + $crit = new Critere(); |
|
| 787 | + $crit->op = $op; |
|
| 788 | + $crit->not = $not; |
|
| 789 | + $crit->cond = $cond; |
|
| 790 | + $crit->param = $args; |
|
| 791 | + |
|
| 792 | + return $crit; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -800,12 +800,12 @@ discard block |
||
| 800 | 800 | * @return int |
| 801 | 801 | */ |
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | - if (is_null($fin)) { |
|
| 804 | - return substr_count($texte, "\n", $debut); |
|
| 805 | - } |
|
| 806 | - else { |
|
| 807 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | - } |
|
| 803 | + if (is_null($fin)) { |
|
| 804 | + return substr_count($texte, "\n", $debut); |
|
| 805 | + } |
|
| 806 | + else { |
|
| 807 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | + } |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -821,87 +821,87 @@ discard block |
||
| 821 | 821 | * @return array|null |
| 822 | 822 | */ |
| 823 | 823 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 824 | - $premiere_boucle = null; |
|
| 825 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | - |
|
| 827 | - $current_pos = $pos_debut_texte; |
|
| 828 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | - $current_pos = $pos_boucle + 1; |
|
| 830 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | - |
|
| 832 | - $id_boucle = ''; |
|
| 833 | - if ($pos_parent !== false) { |
|
| 834 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | - } |
|
| 836 | - if ( |
|
| 837 | - $pos_parent === false |
|
| 838 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | - ) { |
|
| 840 | - $result = new Boucle(); |
|
| 841 | - $result->id_parent = $id_parent; |
|
| 842 | - $result->descr = $descr; |
|
| 843 | - |
|
| 844 | - // un id_boucle pour l'affichage de l'erreur |
|
| 845 | - if (!strlen($id_boucle)) { |
|
| 846 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | - } |
|
| 848 | - $result->id_boucle = $id_boucle; |
|
| 849 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | - erreur_squelette($err_b, $result); |
|
| 851 | - |
|
| 852 | - continue; |
|
| 853 | - } |
|
| 854 | - else { |
|
| 855 | - $boucle = [ |
|
| 856 | - 'id_boucle' => $id_boucle, |
|
| 857 | - 'id_boucle_err' => $id_boucle, |
|
| 858 | - 'debut_boucle' => $pos_boucle, |
|
| 859 | - 'pos_boucle' => $pos_boucle, |
|
| 860 | - 'pos_parent' => $pos_parent, |
|
| 861 | - 'pos_precond' => false, |
|
| 862 | - 'pos_precond_inside' => false, |
|
| 863 | - 'pos_preaff' => false, |
|
| 864 | - 'pos_preaff_inside' => false, |
|
| 865 | - ]; |
|
| 866 | - |
|
| 867 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | - if (!strlen($id_boucle)) { |
|
| 869 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | - if ( |
|
| 876 | - $pos_precond !== false |
|
| 877 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | - ) { |
|
| 879 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond'] = $pos_precond; |
|
| 881 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | - if ( |
|
| 887 | - $pos_preaff !== false |
|
| 888 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | - ) { |
|
| 890 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | - } |
|
| 894 | - if (!strlen($id_boucle)) { |
|
| 895 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | - $premiere_boucle = $boucle; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $premiere_boucle; |
|
| 824 | + $premiere_boucle = null; |
|
| 825 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | + |
|
| 827 | + $current_pos = $pos_debut_texte; |
|
| 828 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | + $current_pos = $pos_boucle + 1; |
|
| 830 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | + |
|
| 832 | + $id_boucle = ''; |
|
| 833 | + if ($pos_parent !== false) { |
|
| 834 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | + } |
|
| 836 | + if ( |
|
| 837 | + $pos_parent === false |
|
| 838 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | + ) { |
|
| 840 | + $result = new Boucle(); |
|
| 841 | + $result->id_parent = $id_parent; |
|
| 842 | + $result->descr = $descr; |
|
| 843 | + |
|
| 844 | + // un id_boucle pour l'affichage de l'erreur |
|
| 845 | + if (!strlen($id_boucle)) { |
|
| 846 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | + } |
|
| 848 | + $result->id_boucle = $id_boucle; |
|
| 849 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | + erreur_squelette($err_b, $result); |
|
| 851 | + |
|
| 852 | + continue; |
|
| 853 | + } |
|
| 854 | + else { |
|
| 855 | + $boucle = [ |
|
| 856 | + 'id_boucle' => $id_boucle, |
|
| 857 | + 'id_boucle_err' => $id_boucle, |
|
| 858 | + 'debut_boucle' => $pos_boucle, |
|
| 859 | + 'pos_boucle' => $pos_boucle, |
|
| 860 | + 'pos_parent' => $pos_parent, |
|
| 861 | + 'pos_precond' => false, |
|
| 862 | + 'pos_precond_inside' => false, |
|
| 863 | + 'pos_preaff' => false, |
|
| 864 | + 'pos_preaff_inside' => false, |
|
| 865 | + ]; |
|
| 866 | + |
|
| 867 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | + if (!strlen($id_boucle)) { |
|
| 869 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | + if ( |
|
| 876 | + $pos_precond !== false |
|
| 877 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | + ) { |
|
| 879 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond'] = $pos_precond; |
|
| 881 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | + if ( |
|
| 887 | + $pos_preaff !== false |
|
| 888 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | + ) { |
|
| 890 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | + } |
|
| 894 | + if (!strlen($id_boucle)) { |
|
| 895 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | + $premiere_boucle = $boucle; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $premiere_boucle; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -916,68 +916,68 @@ discard block |
||
| 916 | 916 | * @return mixed |
| 917 | 917 | */ |
| 918 | 918 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 919 | - $id_boucle = $boucle['id_boucle']; |
|
| 920 | - $pos_courante = $pos_debut_texte; |
|
| 921 | - |
|
| 922 | - $boucle['pos_postcond'] = false; |
|
| 923 | - $boucle['pos_postcond_inside'] = false; |
|
| 924 | - $boucle['pos_altern'] = false; |
|
| 925 | - $boucle['pos_altern_inside'] = false; |
|
| 926 | - $boucle['pos_postaff'] = false; |
|
| 927 | - $boucle['pos_postaff_inside'] = false; |
|
| 928 | - |
|
| 929 | - $pos_anonyme_next = null; |
|
| 930 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | - if (!strlen($id_boucle)) { |
|
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // |
|
| 936 | - // 1. Recuperer la partie conditionnelle apres |
|
| 937 | - // |
|
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | - if ( |
|
| 941 | - $pos_apres !== false |
|
| 942 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | - ) { |
|
| 944 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | - $pos_apres += strlen($apres_boucle); |
|
| 946 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | - $pos_courante = $pos_apres ; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // |
|
| 951 | - // 2. Récuperer la partie alternative apres |
|
| 952 | - // |
|
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | - if ( |
|
| 956 | - $pos_altern !== false |
|
| 957 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | - ) { |
|
| 959 | - $boucle['pos_altern'] = $pos_altern; |
|
| 960 | - $pos_altern += strlen($altern_boucle); |
|
| 961 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | - $pos_courante = $pos_altern; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - // |
|
| 966 | - // 3. Recuperer la partie footer non alternative |
|
| 967 | - // |
|
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | - if ( |
|
| 971 | - $pos_postaff !== false |
|
| 972 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | - ) { |
|
| 974 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | - $pos_postaff += strlen($postaff_boucle); |
|
| 976 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | - $pos_courante = $pos_postaff ; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - return $boucle; |
|
| 919 | + $id_boucle = $boucle['id_boucle']; |
|
| 920 | + $pos_courante = $pos_debut_texte; |
|
| 921 | + |
|
| 922 | + $boucle['pos_postcond'] = false; |
|
| 923 | + $boucle['pos_postcond_inside'] = false; |
|
| 924 | + $boucle['pos_altern'] = false; |
|
| 925 | + $boucle['pos_altern_inside'] = false; |
|
| 926 | + $boucle['pos_postaff'] = false; |
|
| 927 | + $boucle['pos_postaff_inside'] = false; |
|
| 928 | + |
|
| 929 | + $pos_anonyme_next = null; |
|
| 930 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | + if (!strlen($id_boucle)) { |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // |
|
| 936 | + // 1. Recuperer la partie conditionnelle apres |
|
| 937 | + // |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | + if ( |
|
| 941 | + $pos_apres !== false |
|
| 942 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | + ) { |
|
| 944 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | + $pos_apres += strlen($apres_boucle); |
|
| 946 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | + $pos_courante = $pos_apres ; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // |
|
| 951 | + // 2. Récuperer la partie alternative apres |
|
| 952 | + // |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | + if ( |
|
| 956 | + $pos_altern !== false |
|
| 957 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | + ) { |
|
| 959 | + $boucle['pos_altern'] = $pos_altern; |
|
| 960 | + $pos_altern += strlen($altern_boucle); |
|
| 961 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | + $pos_courante = $pos_altern; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + // |
|
| 966 | + // 3. Recuperer la partie footer non alternative |
|
| 967 | + // |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | + if ( |
|
| 971 | + $pos_postaff !== false |
|
| 972 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | + ) { |
|
| 974 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | + $pos_postaff += strlen($postaff_boucle); |
|
| 976 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | + $pos_courante = $pos_postaff ; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + return $boucle; |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -987,21 +987,21 @@ discard block |
||
| 987 | 987 | * @param null|object $boucle |
| 988 | 988 | */ |
| 989 | 989 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 990 | - static $boucles_connues = []; |
|
| 991 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | - } |
|
| 995 | - else { |
|
| 996 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | - $placeholder = $champ->nom_champ; |
|
| 998 | - $id = reset($champ->param[0][1]); |
|
| 999 | - $id = $id->texte; |
|
| 1000 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 990 | + static $boucles_connues = []; |
|
| 991 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | + } |
|
| 995 | + else { |
|
| 996 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | + $placeholder = $champ->nom_champ; |
|
| 998 | + $id = reset($champ->param[0][1]); |
|
| 999 | + $id = $id->texte; |
|
| 1000 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1014,274 +1014,274 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | - //memoriser la boucle a reinjecter |
|
| 1019 | - $id_boucle = "$id_boucle"; |
|
| 1020 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | - return $placeholder; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | + //memoriser la boucle a reinjecter |
|
| 1019 | + $id_boucle = "$id_boucle"; |
|
| 1020 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | + return $placeholder; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1025 | 1025 | |
| 1026 | - $all_res = []; |
|
| 1027 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | - if (is_null($boucle_placeholder)) { |
|
| 1029 | - do { |
|
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | - $pos_debut_texte = 0; |
|
| 1036 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | - $result = new Boucle(); |
|
| 1039 | - $result->id_parent = $id_parent; |
|
| 1040 | - $result->descr = $descr; |
|
| 1041 | - |
|
| 1042 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | - $pos_parent = $boucle['pos_parent']; |
|
| 1044 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | - |
|
| 1046 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | - |
|
| 1048 | - // boucle anonyme ? |
|
| 1049 | - if (!strlen($id_boucle)) { |
|
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $pos_debut_boucle = $pos_courante; |
|
| 1054 | - |
|
| 1055 | - $pos_milieu = $pos_parent; |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | - if ($boucle['pos_precond'] !== false) { |
|
| 1059 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | - |
|
| 1061 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | - $end_preaff = $pos_debut_boucle; |
|
| 1069 | - |
|
| 1070 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - $result->id_boucle = $id_boucle; |
|
| 1076 | - |
|
| 1077 | - if ( |
|
| 1078 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | - or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | - or $pos_match > $pos_milieu |
|
| 1081 | - ) { |
|
| 1082 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | - erreur_squelette($err_b, $result); |
|
| 1084 | - |
|
| 1085 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | - continue; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $result->type_requete = $match[0]; |
|
| 1091 | - $pos_milieu += strlen($match[0]); |
|
| 1092 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | - |
|
| 1094 | - $type = $match[1]; |
|
| 1095 | - $jointures = trim($match[2]); |
|
| 1096 | - $table_optionnelle = ($match[3]); |
|
| 1097 | - if ($jointures) { |
|
| 1098 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | - // ou elles seront completees des jointures declarees |
|
| 1100 | - $result->jointures_explicites = $jointures; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - if ($table_optionnelle) { |
|
| 1104 | - $result->table_optionnelle = $type; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | - // Resultat mis dans result->param |
|
| 1109 | - $pos_fin_criteres = $pos_milieu; |
|
| 1110 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | - |
|
| 1112 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | - // pour l'instant on met le source (chaine) : |
|
| 1114 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | - $pos_milieu = $pos_fin_criteres; |
|
| 1118 | - |
|
| 1119 | - // |
|
| 1120 | - // Recuperer la fin : |
|
| 1121 | - // |
|
| 1122 | - if ($texte[$pos_milieu] === '/') { |
|
| 1123 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | - $pos_courante += 2; |
|
| 1125 | - $result->milieu = ''; |
|
| 1126 | - } else { |
|
| 1127 | - $pos_milieu += 1; |
|
| 1128 | - |
|
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | - if ($pos_fin === false) { |
|
| 1132 | - $err_b = [ |
|
| 1133 | - 'zbug_erreur_boucle_fermant', |
|
| 1134 | - ['id' => $id_boucle] |
|
| 1135 | - ]; |
|
| 1136 | - erreur_squelette($err_b, $result); |
|
| 1137 | - $pos_courante += strlen($fin_boucle); |
|
| 1138 | - } |
|
| 1139 | - else { |
|
| 1140 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | - $search_from = $pos_milieu; |
|
| 1144 | - $nb_open = 1; |
|
| 1145 | - $nb_close = 1; |
|
| 1146 | - $maxiter = 0; |
|
| 1147 | - do { |
|
| 1148 | - while ( |
|
| 1149 | - $nb_close < $nb_open |
|
| 1150 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | - ) { |
|
| 1152 | - $nb_close++; |
|
| 1153 | - $pos_fin = $p; |
|
| 1154 | - } |
|
| 1155 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | - if ($nb_close < $nb_open) { |
|
| 1157 | - break; |
|
| 1158 | - } |
|
| 1159 | - while ( |
|
| 1160 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | - and $p < $pos_fin |
|
| 1162 | - ) { |
|
| 1163 | - $nb_open++; |
|
| 1164 | - $search_from = $p + 1; |
|
| 1165 | - } |
|
| 1166 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | - |
|
| 1168 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | - } |
|
| 1170 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | - |
|
| 1176 | - // |
|
| 1177 | - // 1. Partie conditionnelle apres ? |
|
| 1178 | - // |
|
| 1179 | - if ($boucle['pos_postcond']) { |
|
| 1180 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - // |
|
| 1187 | - // 2. Partie alternative apres ? |
|
| 1188 | - // |
|
| 1189 | - $ligne_altern = $ligne_suite; |
|
| 1190 | - if ($boucle['pos_altern']) { |
|
| 1191 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // |
|
| 1197 | - // 3. Partie footer non alternative ? |
|
| 1198 | - // |
|
| 1199 | - $ligne_postaff = $ligne_suite; |
|
| 1200 | - if ($boucle['pos_postaff']) { |
|
| 1201 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $result->ligne = $ligne_preaff; |
|
| 1207 | - |
|
| 1208 | - if ($p = strpos($type, ':')) { |
|
| 1209 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | - $type = substr($type, $p + 1); |
|
| 1211 | - } |
|
| 1212 | - $soustype = strtolower($type); |
|
| 1213 | - |
|
| 1214 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | - $soustype = $type; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $result->type_requete = $soustype; |
|
| 1219 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | - if (!is_array($result->param)) { |
|
| 1221 | - $err_b = true; |
|
| 1222 | - } else { |
|
| 1223 | - phraser_criteres($result->param, $result); |
|
| 1224 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | - $args = $result->param; |
|
| 1227 | - array_unshift( |
|
| 1228 | - $args, |
|
| 1229 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | - ); |
|
| 1231 | - $result->param = $args; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | - if (empty($boucles[$id_boucle])) { |
|
| 1241 | - $boucles[$id_boucle] = null; |
|
| 1242 | - } |
|
| 1243 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | - |
|
| 1249 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | - if ($err_b) { |
|
| 1251 | - $result->type_requete = false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // Verifier qu'il n'y a pas double definition |
|
| 1255 | - // apres analyse des sous-parties (pas avant). |
|
| 1256 | - if (!empty($boucles[$id_boucle])) { |
|
| 1257 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | - $err_b_d = [ |
|
| 1259 | - 'zbug_erreur_boucle_double', |
|
| 1260 | - ['id' => $id_boucle] |
|
| 1261 | - ]; |
|
| 1262 | - erreur_squelette($err_b_d, $result); |
|
| 1263 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | - } |
|
| 1266 | - } else { |
|
| 1267 | - $boucles[$id_boucle] = $result; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | - |
|
| 1276 | - // phraser la partie avant le debut de la boucle |
|
| 1277 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | - |
|
| 1280 | - $ligne_debut_texte = $ligne_suite; |
|
| 1281 | - $pos_debut_texte = $pos_courante; |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | - |
|
| 1286 | - return $all_res; |
|
| 1026 | + $all_res = []; |
|
| 1027 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | + if (is_null($boucle_placeholder)) { |
|
| 1029 | + do { |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | + $pos_debut_texte = 0; |
|
| 1036 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | + $result = new Boucle(); |
|
| 1039 | + $result->id_parent = $id_parent; |
|
| 1040 | + $result->descr = $descr; |
|
| 1041 | + |
|
| 1042 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | + $pos_parent = $boucle['pos_parent']; |
|
| 1044 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | + |
|
| 1046 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | + |
|
| 1048 | + // boucle anonyme ? |
|
| 1049 | + if (!strlen($id_boucle)) { |
|
| 1050 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $pos_debut_boucle = $pos_courante; |
|
| 1054 | + |
|
| 1055 | + $pos_milieu = $pos_parent; |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | + if ($boucle['pos_precond'] !== false) { |
|
| 1059 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | + |
|
| 1061 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | + $end_preaff = $pos_debut_boucle; |
|
| 1069 | + |
|
| 1070 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + $result->id_boucle = $id_boucle; |
|
| 1076 | + |
|
| 1077 | + if ( |
|
| 1078 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | + or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | + or $pos_match > $pos_milieu |
|
| 1081 | + ) { |
|
| 1082 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | + erreur_squelette($err_b, $result); |
|
| 1084 | + |
|
| 1085 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | + continue; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $result->type_requete = $match[0]; |
|
| 1091 | + $pos_milieu += strlen($match[0]); |
|
| 1092 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | + |
|
| 1094 | + $type = $match[1]; |
|
| 1095 | + $jointures = trim($match[2]); |
|
| 1096 | + $table_optionnelle = ($match[3]); |
|
| 1097 | + if ($jointures) { |
|
| 1098 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | + // ou elles seront completees des jointures declarees |
|
| 1100 | + $result->jointures_explicites = $jointures; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + if ($table_optionnelle) { |
|
| 1104 | + $result->table_optionnelle = $type; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | + // Resultat mis dans result->param |
|
| 1109 | + $pos_fin_criteres = $pos_milieu; |
|
| 1110 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | + |
|
| 1112 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | + // pour l'instant on met le source (chaine) : |
|
| 1114 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | + $pos_milieu = $pos_fin_criteres; |
|
| 1118 | + |
|
| 1119 | + // |
|
| 1120 | + // Recuperer la fin : |
|
| 1121 | + // |
|
| 1122 | + if ($texte[$pos_milieu] === '/') { |
|
| 1123 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | + $pos_courante += 2; |
|
| 1125 | + $result->milieu = ''; |
|
| 1126 | + } else { |
|
| 1127 | + $pos_milieu += 1; |
|
| 1128 | + |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | + if ($pos_fin === false) { |
|
| 1132 | + $err_b = [ |
|
| 1133 | + 'zbug_erreur_boucle_fermant', |
|
| 1134 | + ['id' => $id_boucle] |
|
| 1135 | + ]; |
|
| 1136 | + erreur_squelette($err_b, $result); |
|
| 1137 | + $pos_courante += strlen($fin_boucle); |
|
| 1138 | + } |
|
| 1139 | + else { |
|
| 1140 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | + $search_from = $pos_milieu; |
|
| 1144 | + $nb_open = 1; |
|
| 1145 | + $nb_close = 1; |
|
| 1146 | + $maxiter = 0; |
|
| 1147 | + do { |
|
| 1148 | + while ( |
|
| 1149 | + $nb_close < $nb_open |
|
| 1150 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | + ) { |
|
| 1152 | + $nb_close++; |
|
| 1153 | + $pos_fin = $p; |
|
| 1154 | + } |
|
| 1155 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | + if ($nb_close < $nb_open) { |
|
| 1157 | + break; |
|
| 1158 | + } |
|
| 1159 | + while ( |
|
| 1160 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | + and $p < $pos_fin |
|
| 1162 | + ) { |
|
| 1163 | + $nb_open++; |
|
| 1164 | + $search_from = $p + 1; |
|
| 1165 | + } |
|
| 1166 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | + |
|
| 1168 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | + } |
|
| 1170 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | + |
|
| 1176 | + // |
|
| 1177 | + // 1. Partie conditionnelle apres ? |
|
| 1178 | + // |
|
| 1179 | + if ($boucle['pos_postcond']) { |
|
| 1180 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + // |
|
| 1187 | + // 2. Partie alternative apres ? |
|
| 1188 | + // |
|
| 1189 | + $ligne_altern = $ligne_suite; |
|
| 1190 | + if ($boucle['pos_altern']) { |
|
| 1191 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // |
|
| 1197 | + // 3. Partie footer non alternative ? |
|
| 1198 | + // |
|
| 1199 | + $ligne_postaff = $ligne_suite; |
|
| 1200 | + if ($boucle['pos_postaff']) { |
|
| 1201 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $result->ligne = $ligne_preaff; |
|
| 1207 | + |
|
| 1208 | + if ($p = strpos($type, ':')) { |
|
| 1209 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | + $type = substr($type, $p + 1); |
|
| 1211 | + } |
|
| 1212 | + $soustype = strtolower($type); |
|
| 1213 | + |
|
| 1214 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | + $soustype = $type; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $result->type_requete = $soustype; |
|
| 1219 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | + if (!is_array($result->param)) { |
|
| 1221 | + $err_b = true; |
|
| 1222 | + } else { |
|
| 1223 | + phraser_criteres($result->param, $result); |
|
| 1224 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | + $args = $result->param; |
|
| 1227 | + array_unshift( |
|
| 1228 | + $args, |
|
| 1229 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | + ); |
|
| 1231 | + $result->param = $args; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | + if (empty($boucles[$id_boucle])) { |
|
| 1241 | + $boucles[$id_boucle] = null; |
|
| 1242 | + } |
|
| 1243 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | + |
|
| 1249 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | + if ($err_b) { |
|
| 1251 | + $result->type_requete = false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // Verifier qu'il n'y a pas double definition |
|
| 1255 | + // apres analyse des sous-parties (pas avant). |
|
| 1256 | + if (!empty($boucles[$id_boucle])) { |
|
| 1257 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | + $err_b_d = [ |
|
| 1259 | + 'zbug_erreur_boucle_double', |
|
| 1260 | + ['id' => $id_boucle] |
|
| 1261 | + ]; |
|
| 1262 | + erreur_squelette($err_b_d, $result); |
|
| 1263 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | + } |
|
| 1266 | + } else { |
|
| 1267 | + $boucles[$id_boucle] = $result; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | + |
|
| 1276 | + // phraser la partie avant le debut de la boucle |
|
| 1277 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | + |
|
| 1280 | + $ligne_debut_texte = $ligne_suite; |
|
| 1281 | + $pos_debut_texte = $pos_courante; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | + |
|
| 1286 | + return $all_res; |
|
| 1287 | 1287 | } |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | * Nom d'une balise #TOTO |
| 49 | 49 | * |
| 50 | 50 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 51 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 51 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 52 | 52 | /** Balise complète [...(#TOTO) ... ] */ |
| 53 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 53 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 54 | 54 | |
| 55 | 55 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 56 | 56 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 57 | 57 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 58 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 58 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 59 | 59 | |
| 60 | 60 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 61 | 61 | define('SQL_ARGS', '(\([^)]*\))'); |
| 62 | 62 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 63 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 63 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 64 | 64 | |
| 65 | 65 | // https://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 220 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 221 | 221 | $p = strpos($texte, $match[0]); |
| 222 | 222 | // texte après la balise |
| 223 | 223 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $collecte[] = $champ; |
| 370 | 370 | $args = ltrim($regs[count($regs) - 1]); |
| 371 | 371 | } else { |
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 372 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 373 | 373 | // 0 est un aveu d'impuissance. A completer |
| 374 | 374 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 375 | 375 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | 455 | $res = []; |
| 456 | 456 | while (($p = strpos($texte, "%$sep")) !== false) { |
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 457 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | 458 | break; |
| 459 | 459 | } |
| 460 | 460 | $debut = substr($texte, 0, $p); |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | $pos_apres = 0; |
| 496 | 496 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 497 | 497 | phraser_vieux($champ); |
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | 499 | $debut = substr($match[7], $pos_apres + 1); |
| 500 | 500 | if (!empty($debut)) { |
| 501 | 501 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 627 | 627 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 628 | 628 | $c = null; |
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 629 | + eval('$c = '.$m[4].';'); |
|
| 630 | 630 | if (isset($c)) { |
| 631 | 631 | $m[4] = $c; |
| 632 | 632 | } |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 707 | 707 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 708 | 708 | } elseif ( |
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 709 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 710 | 710 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 711 | 711 | ) { |
| 712 | 712 | $a2 = trim($m[8]); |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | ); |
| 724 | 724 | $crit->exclus = $m[1]; |
| 725 | 725 | } elseif ( |
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 726 | + preg_match('/^([!]?)\s*('. |
|
| 727 | + CHAMP_SQL_PLUS_FONC. |
|
| 728 | 728 | ')\s*(\??)(.*)$/is', $param, $m) |
| 729 | 729 | ) { |
| 730 | 730 | // contient aussi les comparaisons implicites ! |
@@ -870,7 +870,7 @@ discard block |
||
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 874 | 874 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 875 | 875 | if ( |
| 876 | 876 | $pos_precond !== false |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 885 | 885 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 886 | 886 | if ( |
| 887 | 887 | $pos_preaff !== false |
@@ -929,13 +929,13 @@ discard block |
||
| 929 | 929 | $pos_anonyme_next = null; |
| 930 | 930 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 931 | 931 | if (!strlen($id_boucle)) { |
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | // |
| 936 | 936 | // 1. Recuperer la partie conditionnelle apres |
| 937 | 937 | // |
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 939 | 939 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 940 | 940 | if ( |
| 941 | 941 | $pos_apres !== false |
@@ -944,13 +944,13 @@ discard block |
||
| 944 | 944 | $boucle['pos_postcond'] = $pos_apres; |
| 945 | 945 | $pos_apres += strlen($apres_boucle); |
| 946 | 946 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 947 | - $pos_courante = $pos_apres ; |
|
| 947 | + $pos_courante = $pos_apres; |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | // |
| 951 | 951 | // 2. Récuperer la partie alternative apres |
| 952 | 952 | // |
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 954 | 954 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 955 | 955 | if ( |
| 956 | 956 | $pos_altern !== false |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | // |
| 966 | 966 | // 3. Recuperer la partie footer non alternative |
| 967 | 967 | // |
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 969 | 969 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 970 | 970 | if ( |
| 971 | 971 | $pos_postaff !== false |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | $boucle['pos_postaff'] = $pos_postaff; |
| 975 | 975 | $pos_postaff += strlen($postaff_boucle); |
| 976 | 976 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 977 | - $pos_courante = $pos_postaff ; |
|
| 977 | + $pos_courante = $pos_postaff; |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | return $boucle; |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1018 | 1018 | //memoriser la boucle a reinjecter |
| 1019 | 1019 | $id_boucle = "$id_boucle"; |
| 1020 | 1020 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1028 | 1028 | if (is_null($boucle_placeholder)) { |
| 1029 | 1029 | do { |
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1031 | 1031 | } while (strpos($texte, $boucle_placeholder) !== false); |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | |
| 1048 | 1048 | // boucle anonyme ? |
| 1049 | 1049 | if (!strlen($id_boucle)) { |
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1050 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle)), 0, 8); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | $pos_debut_boucle = $pos_courante; |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | $pos_avant = $boucle['pos_precond_inside']; |
| 1062 | 1062 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1071 | 1071 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | $result->id_boucle = $id_boucle; |
@@ -1126,7 +1126,7 @@ discard block |
||
| 1126 | 1126 | } else { |
| 1127 | 1127 | $pos_milieu += 1; |
| 1128 | 1128 | |
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1130 | 1130 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1131 | 1131 | if ($pos_fin === false) { |
| 1132 | 1132 | $err_b = [ |
@@ -1139,7 +1139,7 @@ discard block |
||
| 1139 | 1139 | else { |
| 1140 | 1140 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1141 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1143 | 1143 | $search_from = $pos_milieu; |
| 1144 | 1144 | $nb_open = 1; |
| 1145 | 1145 | $nb_close = 1; |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | if ($boucle['pos_postcond']) { |
| 1180 | 1180 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1181 | 1181 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | |
@@ -802,8 +802,7 @@ discard block |
||
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | 803 | if (is_null($fin)) { |
| 804 | 804 | return substr_count($texte, "\n", $debut); |
| 805 | - } |
|
| 806 | - else { |
|
| 805 | + } else { |
|
| 807 | 806 | return substr_count($texte, "\n", $debut, $fin - $debut); |
| 808 | 807 | } |
| 809 | 808 | } |
@@ -850,8 +849,7 @@ discard block |
||
| 850 | 849 | erreur_squelette($err_b, $result); |
| 851 | 850 | |
| 852 | 851 | continue; |
| 853 | - } |
|
| 854 | - else { |
|
| 852 | + } else { |
|
| 855 | 853 | $boucle = [ |
| 856 | 854 | 'id_boucle' => $id_boucle, |
| 857 | 855 | 'id_boucle_err' => $id_boucle, |
@@ -991,8 +989,7 @@ discard block |
||
| 991 | 989 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 992 | 990 | if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
| 993 | 991 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 994 | - } |
|
| 995 | - else { |
|
| 992 | + } else { |
|
| 996 | 993 | if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
| 997 | 994 | $placeholder = $champ->nom_champ; |
| 998 | 995 | $id = reset($champ->param[0][1]); |
@@ -1135,8 +1132,7 @@ discard block |
||
| 1135 | 1132 | ]; |
| 1136 | 1133 | erreur_squelette($err_b, $result); |
| 1137 | 1134 | $pos_courante += strlen($fin_boucle); |
| 1138 | - } |
|
| 1139 | - else { |
|
| 1135 | + } else { |
|
| 1140 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | 1138 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
@@ -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,60 +1914,60 @@ 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 // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1930 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1931 | - { |
|
| 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) { // condition annexe du type "AND (objet='article')" |
|
| 1963 | - $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1964 | - } |
|
| 1965 | - } |
|
| 1966 | - |
|
| 1967 | - $boucles[$idb]->where[] = $where; |
|
| 1968 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1969 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1970 | - } |
|
| 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 // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1930 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1931 | + { |
|
| 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) { // condition annexe du type "AND (objet='article')" |
|
| 1963 | + $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1964 | + } |
|
| 1965 | + } |
|
| 1966 | + |
|
| 1967 | + $boucles[$idb]->where[] = $where; |
|
| 1968 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1969 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1970 | + } |
|
| 1971 | 1971 | } |
| 1972 | 1972 | |
| 1973 | 1973 | |
@@ -2008,165 +2008,165 @@ discard block |
||
| 2008 | 2008 | **/ |
| 2009 | 2009 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2010 | 2010 | |
| 2011 | - $boucle = &$boucles[$idb]; |
|
| 2012 | - $type = $boucle->type_requete; |
|
| 2013 | - $table = $boucle->id_table; |
|
| 2014 | - $desc = $boucle->show; |
|
| 2015 | - $col_vraie = null; |
|
| 2016 | - |
|
| 2017 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 2018 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2019 | - |
|
| 2020 | - $col_alias = $col; |
|
| 2021 | - $where_complement = false; |
|
| 2022 | - |
|
| 2023 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2024 | - if ($col == 'id_enfant') { |
|
| 2025 | - $col = $boucle->primary; |
|
| 2026 | - } |
|
| 2027 | - |
|
| 2028 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2029 | - if ( |
|
| 2030 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2031 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2032 | - ) { |
|
| 2033 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2034 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2035 | - else { |
|
| 2036 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2037 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2041 | - // sauf si exception declaree : sauter cette etape |
|
| 2042 | - else { |
|
| 2043 | - if ( |
|
| 2044 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2045 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2046 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2047 | - ) { |
|
| 2048 | - $e = decompose_champ_id_objet($col); |
|
| 2049 | - $col = array_shift($e); |
|
| 2050 | - $where_complement = primary_doublee($e, $table); |
|
| 2051 | - } // Cas particulier : expressions de date |
|
| 2052 | - else { |
|
| 2053 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2054 | - list($col, $col_vraie) = $c; |
|
| 2055 | - $table = ''; |
|
| 2056 | - } // table explicitée {mots.titre} |
|
| 2057 | - else { |
|
| 2058 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2059 | - list(, $table, $col) = $r; |
|
| 2060 | - $col_alias = $col; |
|
| 2061 | - |
|
| 2062 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2063 | - if ( |
|
| 2064 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2065 | - and isset($desc['field'][$col]) |
|
| 2066 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2067 | - ) { |
|
| 2068 | - $table = $cle; |
|
| 2069 | - } else { |
|
| 2070 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2071 | - } |
|
| 2072 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2073 | - if (!$table) { |
|
| 2074 | - return ''; |
|
| 2075 | - } |
|
| 2076 | - } |
|
| 2077 | - // si le champ n'est pas trouvé dans la table, |
|
| 2078 | - // on cherche si une jointure peut l'obtenir |
|
| 2079 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2080 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2081 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2082 | - $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 |
|
| 2083 | - } |
|
| 2084 | - else { |
|
| 2085 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2086 | - if (!$r) { |
|
| 2087 | - return ''; |
|
| 2088 | - } |
|
| 2089 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - } |
|
| 2096 | - |
|
| 2097 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2098 | - // Dans tous les cas, |
|
| 2099 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2100 | - // et passer dans sql_quote avec le type si connu |
|
| 2101 | - // et int sinon si la valeur est numerique |
|
| 2102 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2103 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2104 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2105 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2106 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2107 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2108 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2109 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2110 | - } |
|
| 2111 | - // sinon expliciter les |
|
| 2112 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2113 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2114 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2115 | - // sans toucher aux |
|
| 2116 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2117 | - // sql_quote(truc,'','varchar') |
|
| 2118 | - elseif ( |
|
| 2119 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2120 | - // si pas deja un type |
|
| 2121 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2122 | - ) { |
|
| 2123 | - $r = $r[1] |
|
| 2124 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2125 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2126 | - $val[0] = "sql_quote($r)"; |
|
| 2127 | - } |
|
| 2128 | - elseif ( |
|
| 2129 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2130 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2131 | - ) { |
|
| 2132 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2133 | - } |
|
| 2134 | - } |
|
| 2135 | - |
|
| 2136 | - if ( |
|
| 2137 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2138 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2139 | - ) { |
|
| 2140 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2144 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2145 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2146 | - if ($table === $boucle->id_table) { |
|
| 2147 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2148 | - if ($col_alias != $col_vraie) { |
|
| 2149 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2150 | - } |
|
| 2151 | - } |
|
| 2152 | - |
|
| 2153 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2154 | - if ($table) { |
|
| 2155 | - if ($col[0] == '`') { |
|
| 2156 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2157 | - } else { |
|
| 2158 | - $arg = "$table.$col"; |
|
| 2159 | - } |
|
| 2160 | - } else { |
|
| 2161 | - $arg = $col; |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - // inserer la fonction SQL |
|
| 2165 | - if ($fct) { |
|
| 2166 | - $arg = "$fct($arg$args_sql)"; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2011 | + $boucle = &$boucles[$idb]; |
|
| 2012 | + $type = $boucle->type_requete; |
|
| 2013 | + $table = $boucle->id_table; |
|
| 2014 | + $desc = $boucle->show; |
|
| 2015 | + $col_vraie = null; |
|
| 2016 | + |
|
| 2017 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 2018 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2019 | + |
|
| 2020 | + $col_alias = $col; |
|
| 2021 | + $where_complement = false; |
|
| 2022 | + |
|
| 2023 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2024 | + if ($col == 'id_enfant') { |
|
| 2025 | + $col = $boucle->primary; |
|
| 2026 | + } |
|
| 2027 | + |
|
| 2028 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2029 | + if ( |
|
| 2030 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2031 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2032 | + ) { |
|
| 2033 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2034 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2035 | + else { |
|
| 2036 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2037 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2041 | + // sauf si exception declaree : sauter cette etape |
|
| 2042 | + else { |
|
| 2043 | + if ( |
|
| 2044 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2045 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2046 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2047 | + ) { |
|
| 2048 | + $e = decompose_champ_id_objet($col); |
|
| 2049 | + $col = array_shift($e); |
|
| 2050 | + $where_complement = primary_doublee($e, $table); |
|
| 2051 | + } // Cas particulier : expressions de date |
|
| 2052 | + else { |
|
| 2053 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2054 | + list($col, $col_vraie) = $c; |
|
| 2055 | + $table = ''; |
|
| 2056 | + } // table explicitée {mots.titre} |
|
| 2057 | + else { |
|
| 2058 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2059 | + list(, $table, $col) = $r; |
|
| 2060 | + $col_alias = $col; |
|
| 2061 | + |
|
| 2062 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2063 | + if ( |
|
| 2064 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2065 | + and isset($desc['field'][$col]) |
|
| 2066 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2067 | + ) { |
|
| 2068 | + $table = $cle; |
|
| 2069 | + } else { |
|
| 2070 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2071 | + } |
|
| 2072 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2073 | + if (!$table) { |
|
| 2074 | + return ''; |
|
| 2075 | + } |
|
| 2076 | + } |
|
| 2077 | + // si le champ n'est pas trouvé dans la table, |
|
| 2078 | + // on cherche si une jointure peut l'obtenir |
|
| 2079 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2080 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2081 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2082 | + $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 |
|
| 2083 | + } |
|
| 2084 | + else { |
|
| 2085 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2086 | + if (!$r) { |
|
| 2087 | + return ''; |
|
| 2088 | + } |
|
| 2089 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + } |
|
| 2096 | + |
|
| 2097 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2098 | + // Dans tous les cas, |
|
| 2099 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2100 | + // et passer dans sql_quote avec le type si connu |
|
| 2101 | + // et int sinon si la valeur est numerique |
|
| 2102 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2103 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2104 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2105 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2106 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2107 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2108 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2109 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2110 | + } |
|
| 2111 | + // sinon expliciter les |
|
| 2112 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2113 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2114 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2115 | + // sans toucher aux |
|
| 2116 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2117 | + // sql_quote(truc,'','varchar') |
|
| 2118 | + elseif ( |
|
| 2119 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2120 | + // si pas deja un type |
|
| 2121 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2122 | + ) { |
|
| 2123 | + $r = $r[1] |
|
| 2124 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2125 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2126 | + $val[0] = "sql_quote($r)"; |
|
| 2127 | + } |
|
| 2128 | + elseif ( |
|
| 2129 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2130 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2131 | + ) { |
|
| 2132 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2133 | + } |
|
| 2134 | + } |
|
| 2135 | + |
|
| 2136 | + if ( |
|
| 2137 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2138 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2139 | + ) { |
|
| 2140 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2144 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2145 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2146 | + if ($table === $boucle->id_table) { |
|
| 2147 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2148 | + if ($col_alias != $col_vraie) { |
|
| 2149 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2150 | + } |
|
| 2151 | + } |
|
| 2152 | + |
|
| 2153 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2154 | + if ($table) { |
|
| 2155 | + if ($col[0] == '`') { |
|
| 2156 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2157 | + } else { |
|
| 2158 | + $arg = "$table.$col"; |
|
| 2159 | + } |
|
| 2160 | + } else { |
|
| 2161 | + $arg = $col; |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + // inserer la fonction SQL |
|
| 2165 | + if ($fct) { |
|
| 2166 | + $arg = "$fct($arg$args_sql)"; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2170 | 2170 | } |
| 2171 | 2171 | |
| 2172 | 2172 | |
@@ -2195,78 +2195,78 @@ discard block |
||
| 2195 | 2195 | **/ |
| 2196 | 2196 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2197 | 2197 | |
| 2198 | - $where = ''; |
|
| 2199 | - |
|
| 2200 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2201 | - // gestion par les plugins des jointures tordues |
|
| 2202 | - // pas automatiques mais necessaires |
|
| 2203 | - $table_sql = table_objet_sql($table); |
|
| 2204 | - if ( |
|
| 2205 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2206 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2207 | - and |
|
| 2208 | - ( |
|
| 2209 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2210 | - or |
|
| 2211 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2212 | - ) |
|
| 2213 | - ) { |
|
| 2214 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2215 | - $index = isset($t[$col]) |
|
| 2216 | - ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2217 | - |
|
| 2218 | - if (count($index) == 3) { |
|
| 2219 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2220 | - } elseif (count($index) == 2) { |
|
| 2221 | - list($t, $col) = $t[$col]; |
|
| 2222 | - } elseif (count($index) == 1) { |
|
| 2223 | - list($calculer_critere_externe) = $index; |
|
| 2224 | - $t = $table; |
|
| 2225 | - } else { |
|
| 2226 | - $t = ''; |
|
| 2227 | - } // jointure non declaree. La trouver. |
|
| 2228 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2229 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2230 | - } else { |
|
| 2231 | - $t = ''; |
|
| 2232 | - } // jointure non declaree. La trouver. |
|
| 2233 | - |
|
| 2234 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2235 | - |
|
| 2236 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2237 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2238 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2239 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2240 | - $table = ''; |
|
| 2241 | - if ($boucle->jointures_explicites) { |
|
| 2242 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2243 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2247 | - if (!$table) { |
|
| 2248 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2249 | - } |
|
| 2250 | - |
|
| 2251 | - if (!$table) { |
|
| 2252 | - return ''; |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2256 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2257 | - |
|
| 2258 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2259 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2260 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2261 | - $e = decompose_champ_id_objet($col); |
|
| 2262 | - $col = array_shift($e); |
|
| 2263 | - $where = primary_doublee($e, $table); |
|
| 2264 | - } else { |
|
| 2265 | - $col = reset($cle); |
|
| 2266 | - } |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2198 | + $where = ''; |
|
| 2199 | + |
|
| 2200 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2201 | + // gestion par les plugins des jointures tordues |
|
| 2202 | + // pas automatiques mais necessaires |
|
| 2203 | + $table_sql = table_objet_sql($table); |
|
| 2204 | + if ( |
|
| 2205 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2206 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2207 | + and |
|
| 2208 | + ( |
|
| 2209 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2210 | + or |
|
| 2211 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2212 | + ) |
|
| 2213 | + ) { |
|
| 2214 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2215 | + $index = isset($t[$col]) |
|
| 2216 | + ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2217 | + |
|
| 2218 | + if (count($index) == 3) { |
|
| 2219 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2220 | + } elseif (count($index) == 2) { |
|
| 2221 | + list($t, $col) = $t[$col]; |
|
| 2222 | + } elseif (count($index) == 1) { |
|
| 2223 | + list($calculer_critere_externe) = $index; |
|
| 2224 | + $t = $table; |
|
| 2225 | + } else { |
|
| 2226 | + $t = ''; |
|
| 2227 | + } // jointure non declaree. La trouver. |
|
| 2228 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2229 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2230 | + } else { |
|
| 2231 | + $t = ''; |
|
| 2232 | + } // jointure non declaree. La trouver. |
|
| 2233 | + |
|
| 2234 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2235 | + |
|
| 2236 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2237 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2238 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2239 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2240 | + $table = ''; |
|
| 2241 | + if ($boucle->jointures_explicites) { |
|
| 2242 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2243 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2247 | + if (!$table) { |
|
| 2248 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2249 | + } |
|
| 2250 | + |
|
| 2251 | + if (!$table) { |
|
| 2252 | + return ''; |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2256 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2257 | + |
|
| 2258 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2259 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2260 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2261 | + $e = decompose_champ_id_objet($col); |
|
| 2262 | + $col = array_shift($e); |
|
| 2263 | + $where = primary_doublee($e, $table); |
|
| 2264 | + } else { |
|
| 2265 | + $col = reset($cle); |
|
| 2266 | + } |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2270 | 2270 | } |
| 2271 | 2271 | |
| 2272 | 2272 | |
@@ -2287,10 +2287,10 @@ discard block |
||
| 2287 | 2287 | * - valeur |
| 2288 | 2288 | **/ |
| 2289 | 2289 | function primary_doublee($decompose, $table) { |
| 2290 | - $e1 = reset($decompose); |
|
| 2291 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2290 | + $e1 = reset($decompose); |
|
| 2291 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2292 | 2292 | |
| 2293 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2293 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | |
| 2296 | 2296 | /** |
@@ -2321,57 +2321,57 @@ discard block |
||
| 2321 | 2321 | * Vide sinon. |
| 2322 | 2322 | */ |
| 2323 | 2323 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2324 | - // si on demande un truc du genre spip_mots |
|
| 2325 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2326 | - // et qu'on est la |
|
| 2327 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2328 | - if ( |
|
| 2329 | - $checkarrivee |
|
| 2330 | - and is_string($checkarrivee) |
|
| 2331 | - and $a = table_objet($checkarrivee) |
|
| 2332 | - and in_array($a . '_liens', $joints) |
|
| 2333 | - ) { |
|
| 2334 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2335 | - return $res; |
|
| 2336 | - } |
|
| 2337 | - } |
|
| 2338 | - foreach ($joints as $joint) { |
|
| 2339 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2340 | - // alias de table dans le from |
|
| 2341 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2342 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2343 | - $cols = $arrivee[2]; |
|
| 2344 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2345 | - if (count($cols) > 2) { |
|
| 2346 | - array_pop($cols); |
|
| 2347 | - } |
|
| 2348 | - if ($t) { |
|
| 2349 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2350 | - $joindre = false; |
|
| 2351 | - foreach ($cols as $col) { |
|
| 2352 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2353 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2354 | - $joindre = true; |
|
| 2355 | - } else { |
|
| 2356 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2357 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2358 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2359 | - $joindre = true; |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - } |
|
| 2363 | - if (!$joindre) { |
|
| 2364 | - return $t; |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 2367 | - array_pop($arrivee); |
|
| 2368 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2369 | - return $res; |
|
| 2370 | - } |
|
| 2371 | - } |
|
| 2372 | - } |
|
| 2373 | - |
|
| 2374 | - return ''; |
|
| 2324 | + // si on demande un truc du genre spip_mots |
|
| 2325 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2326 | + // et qu'on est la |
|
| 2327 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2328 | + if ( |
|
| 2329 | + $checkarrivee |
|
| 2330 | + and is_string($checkarrivee) |
|
| 2331 | + and $a = table_objet($checkarrivee) |
|
| 2332 | + and in_array($a . '_liens', $joints) |
|
| 2333 | + ) { |
|
| 2334 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2335 | + return $res; |
|
| 2336 | + } |
|
| 2337 | + } |
|
| 2338 | + foreach ($joints as $joint) { |
|
| 2339 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2340 | + // alias de table dans le from |
|
| 2341 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2342 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2343 | + $cols = $arrivee[2]; |
|
| 2344 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2345 | + if (count($cols) > 2) { |
|
| 2346 | + array_pop($cols); |
|
| 2347 | + } |
|
| 2348 | + if ($t) { |
|
| 2349 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2350 | + $joindre = false; |
|
| 2351 | + foreach ($cols as $col) { |
|
| 2352 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2353 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2354 | + $joindre = true; |
|
| 2355 | + } else { |
|
| 2356 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2357 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2358 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2359 | + $joindre = true; |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + } |
|
| 2363 | + if (!$joindre) { |
|
| 2364 | + return $t; |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + array_pop($arrivee); |
|
| 2368 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2369 | + return $res; |
|
| 2370 | + } |
|
| 2371 | + } |
|
| 2372 | + } |
|
| 2373 | + |
|
| 2374 | + return ''; |
|
| 2375 | 2375 | } |
| 2376 | 2376 | |
| 2377 | 2377 | /** |
@@ -2397,35 +2397,35 @@ discard block |
||
| 2397 | 2397 | * Alias de la table de jointure (Lx) |
| 2398 | 2398 | */ |
| 2399 | 2399 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2400 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2401 | - |
|
| 2402 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2403 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2404 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2405 | - |
|
| 2406 | - if (!$intermediaire or !$arrivee) { |
|
| 2407 | - return ''; |
|
| 2408 | - } |
|
| 2409 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2410 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2411 | - |
|
| 2412 | - $res = fabrique_jointures( |
|
| 2413 | - $boucle, |
|
| 2414 | - [ |
|
| 2415 | - [ |
|
| 2416 | - $boucle->id_table, |
|
| 2417 | - $intermediaire, |
|
| 2418 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2419 | - ], |
|
| 2420 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2421 | - ], |
|
| 2422 | - $cond, |
|
| 2423 | - $desc, |
|
| 2424 | - $boucle->id_table, |
|
| 2425 | - [$col] |
|
| 2426 | - ); |
|
| 2427 | - |
|
| 2428 | - return $res; |
|
| 2400 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2401 | + |
|
| 2402 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2403 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2404 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2405 | + |
|
| 2406 | + if (!$intermediaire or !$arrivee) { |
|
| 2407 | + return ''; |
|
| 2408 | + } |
|
| 2409 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2410 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2411 | + |
|
| 2412 | + $res = fabrique_jointures( |
|
| 2413 | + $boucle, |
|
| 2414 | + [ |
|
| 2415 | + [ |
|
| 2416 | + $boucle->id_table, |
|
| 2417 | + $intermediaire, |
|
| 2418 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2419 | + ], |
|
| 2420 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2421 | + ], |
|
| 2422 | + $cond, |
|
| 2423 | + $desc, |
|
| 2424 | + $boucle->id_table, |
|
| 2425 | + [$col] |
|
| 2426 | + ); |
|
| 2427 | + |
|
| 2428 | + return $res; |
|
| 2429 | 2429 | } |
| 2430 | 2430 | |
| 2431 | 2431 | |
@@ -2442,17 +2442,17 @@ discard block |
||
| 2442 | 2442 | * false sinon. |
| 2443 | 2443 | **/ |
| 2444 | 2444 | function trouver_champ($champ, $where) { |
| 2445 | - if (!is_array($where)) { |
|
| 2446 | - return preg_match($champ, $where); |
|
| 2447 | - } else { |
|
| 2448 | - foreach ($where as $clause) { |
|
| 2449 | - if (trouver_champ($champ, $clause)) { |
|
| 2450 | - return true; |
|
| 2451 | - } |
|
| 2452 | - } |
|
| 2453 | - |
|
| 2454 | - return false; |
|
| 2455 | - } |
|
| 2445 | + if (!is_array($where)) { |
|
| 2446 | + return preg_match($champ, $where); |
|
| 2447 | + } else { |
|
| 2448 | + foreach ($where as $clause) { |
|
| 2449 | + if (trouver_champ($champ, $clause)) { |
|
| 2450 | + return true; |
|
| 2451 | + } |
|
| 2452 | + } |
|
| 2453 | + |
|
| 2454 | + return false; |
|
| 2455 | + } |
|
| 2456 | 2456 | } |
| 2457 | 2457 | |
| 2458 | 2458 | |
@@ -2478,130 +2478,130 @@ discard block |
||
| 2478 | 2478 | * - string $args_sql Suite des arguments du critère. ? |
| 2479 | 2479 | **/ |
| 2480 | 2480 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2481 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2482 | - if (count($crit->param) == 0) { |
|
| 2483 | - $op = '='; |
|
| 2484 | - $col = $val = $crit->op; |
|
| 2485 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2486 | - $val = $r[2]; |
|
| 2487 | - } |
|
| 2488 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2489 | - if ($val == 'lang') { |
|
| 2490 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2491 | - } else { |
|
| 2492 | - $defaut = null; |
|
| 2493 | - if ($val == 'id_parent') { |
|
| 2494 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2495 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2496 | - // pour eviter l'erreur SQL |
|
| 2497 | - $val = $boucles[$idb]->primary; |
|
| 2498 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2499 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2500 | - } elseif ($val == 'id_enfant') { |
|
| 2501 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2502 | - // de la boucle superieure |
|
| 2503 | - $val = 'id_parent'; |
|
| 2504 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2505 | - // un critere conditionnel sur date est traite a part |
|
| 2506 | - // car la date est mise d'office par SPIP, |
|
| 2507 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2511 | - $val = [kwote($val)]; |
|
| 2512 | - } |
|
| 2513 | - } else { |
|
| 2514 | - // comparaison explicite |
|
| 2515 | - // le phraseur impose que le premier param soit du texte |
|
| 2516 | - $params = $crit->param; |
|
| 2517 | - $op = $crit->op; |
|
| 2518 | - if ($op == '==') { |
|
| 2519 | - $op = 'REGEXP'; |
|
| 2520 | - } |
|
| 2521 | - $col = array_shift($params); |
|
| 2522 | - $col = $col[0]->texte; |
|
| 2523 | - |
|
| 2524 | - $val = []; |
|
| 2525 | - $parent = $boucles[$idb]->id_parent; |
|
| 2526 | - |
|
| 2527 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2528 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2529 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2530 | - if ( |
|
| 2531 | - count($params) == 1 |
|
| 2532 | - and count($params[0]) == 3 |
|
| 2533 | - and $params[0][0]->type == 'texte' |
|
| 2534 | - and $params[0][2]->type == 'texte' |
|
| 2535 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2536 | - and (($p == "'") or ($p == '"')) |
|
| 2537 | - and $params[0][1]->type == 'champ' |
|
| 2538 | - ) { |
|
| 2539 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2540 | - } else { |
|
| 2541 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2542 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2543 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2544 | - $val[] = $a; |
|
| 2545 | - } else { |
|
| 2546 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2547 | - } // toujours quoter en char ici |
|
| 2548 | - } |
|
| 2549 | - } |
|
| 2550 | - } |
|
| 2551 | - |
|
| 2552 | - $fct = $args_sql = ''; |
|
| 2553 | - // fonction SQL ? |
|
| 2554 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2555 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2556 | - $fct = $m[1]; |
|
| 2557 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2558 | - $col = $a[1]; |
|
| 2559 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2560 | - $col = $m[1]; |
|
| 2561 | - $args_sql = $m[2]; |
|
| 2562 | - } |
|
| 2563 | - $args_sql .= $a[2]; |
|
| 2564 | - } |
|
| 2565 | - |
|
| 2566 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2481 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2482 | + if (count($crit->param) == 0) { |
|
| 2483 | + $op = '='; |
|
| 2484 | + $col = $val = $crit->op; |
|
| 2485 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2486 | + $val = $r[2]; |
|
| 2487 | + } |
|
| 2488 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2489 | + if ($val == 'lang') { |
|
| 2490 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2491 | + } else { |
|
| 2492 | + $defaut = null; |
|
| 2493 | + if ($val == 'id_parent') { |
|
| 2494 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2495 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2496 | + // pour eviter l'erreur SQL |
|
| 2497 | + $val = $boucles[$idb]->primary; |
|
| 2498 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2499 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2500 | + } elseif ($val == 'id_enfant') { |
|
| 2501 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2502 | + // de la boucle superieure |
|
| 2503 | + $val = 'id_parent'; |
|
| 2504 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2505 | + // un critere conditionnel sur date est traite a part |
|
| 2506 | + // car la date est mise d'office par SPIP, |
|
| 2507 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2511 | + $val = [kwote($val)]; |
|
| 2512 | + } |
|
| 2513 | + } else { |
|
| 2514 | + // comparaison explicite |
|
| 2515 | + // le phraseur impose que le premier param soit du texte |
|
| 2516 | + $params = $crit->param; |
|
| 2517 | + $op = $crit->op; |
|
| 2518 | + if ($op == '==') { |
|
| 2519 | + $op = 'REGEXP'; |
|
| 2520 | + } |
|
| 2521 | + $col = array_shift($params); |
|
| 2522 | + $col = $col[0]->texte; |
|
| 2523 | + |
|
| 2524 | + $val = []; |
|
| 2525 | + $parent = $boucles[$idb]->id_parent; |
|
| 2526 | + |
|
| 2527 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2528 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2529 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2530 | + if ( |
|
| 2531 | + count($params) == 1 |
|
| 2532 | + and count($params[0]) == 3 |
|
| 2533 | + and $params[0][0]->type == 'texte' |
|
| 2534 | + and $params[0][2]->type == 'texte' |
|
| 2535 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2536 | + and (($p == "'") or ($p == '"')) |
|
| 2537 | + and $params[0][1]->type == 'champ' |
|
| 2538 | + ) { |
|
| 2539 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2540 | + } else { |
|
| 2541 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2542 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2543 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2544 | + $val[] = $a; |
|
| 2545 | + } else { |
|
| 2546 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2547 | + } // toujours quoter en char ici |
|
| 2548 | + } |
|
| 2549 | + } |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + $fct = $args_sql = ''; |
|
| 2553 | + // fonction SQL ? |
|
| 2554 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2555 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2556 | + $fct = $m[1]; |
|
| 2557 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2558 | + $col = $a[1]; |
|
| 2559 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2560 | + $col = $m[1]; |
|
| 2561 | + $args_sql = $m[2]; |
|
| 2562 | + } |
|
| 2563 | + $args_sql .= $a[2]; |
|
| 2564 | + } |
|
| 2565 | + |
|
| 2566 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2567 | 2567 | } |
| 2568 | 2568 | |
| 2569 | 2569 | // compatibilite ancienne version |
| 2570 | 2570 | |
| 2571 | 2571 | // https://code.spip.net/@calculer_vieux_in |
| 2572 | 2572 | function calculer_vieux_in($params) { |
| 2573 | - $deb = $params[0][0]; |
|
| 2574 | - $k = count($params) - 1; |
|
| 2575 | - $last = $params[$k]; |
|
| 2576 | - $j = count($last) - 1; |
|
| 2577 | - $last = $last[$j]; |
|
| 2578 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2579 | - |
|
| 2580 | - if ( |
|
| 2581 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2582 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2583 | - ) { |
|
| 2584 | - return $params; |
|
| 2585 | - } |
|
| 2586 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2587 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2588 | - $last = $params[$k][$j]; |
|
| 2589 | - $n = strlen($last->texte); |
|
| 2590 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2591 | - $newp = []; |
|
| 2592 | - foreach ($params as $v) { |
|
| 2593 | - if ($v[0]->type != 'texte') { |
|
| 2594 | - $newp[] = $v; |
|
| 2595 | - } else { |
|
| 2596 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2597 | - $t = new Texte(); |
|
| 2598 | - $t->texte = $x; |
|
| 2599 | - $newp[] = [$t]; |
|
| 2600 | - } |
|
| 2601 | - } |
|
| 2602 | - } |
|
| 2603 | - |
|
| 2604 | - return $newp; |
|
| 2573 | + $deb = $params[0][0]; |
|
| 2574 | + $k = count($params) - 1; |
|
| 2575 | + $last = $params[$k]; |
|
| 2576 | + $j = count($last) - 1; |
|
| 2577 | + $last = $last[$j]; |
|
| 2578 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2579 | + |
|
| 2580 | + if ( |
|
| 2581 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2582 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2583 | + ) { |
|
| 2584 | + return $params; |
|
| 2585 | + } |
|
| 2586 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2587 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2588 | + $last = $params[$k][$j]; |
|
| 2589 | + $n = strlen($last->texte); |
|
| 2590 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2591 | + $newp = []; |
|
| 2592 | + foreach ($params as $v) { |
|
| 2593 | + if ($v[0]->type != 'texte') { |
|
| 2594 | + $newp[] = $v; |
|
| 2595 | + } else { |
|
| 2596 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2597 | + $t = new Texte(); |
|
| 2598 | + $t->texte = $x; |
|
| 2599 | + $newp[] = [$t]; |
|
| 2600 | + } |
|
| 2601 | + } |
|
| 2602 | + } |
|
| 2603 | + |
|
| 2604 | + return $newp; |
|
| 2605 | 2605 | } |
| 2606 | 2606 | |
| 2607 | 2607 | /** |
@@ -2620,89 +2620,89 @@ discard block |
||
| 2620 | 2620 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2621 | 2621 | **/ |
| 2622 | 2622 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2623 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2624 | - return ''; |
|
| 2625 | - } |
|
| 2626 | - |
|
| 2627 | - $boucle = $boucles[$idb]; |
|
| 2628 | - $table = $boucle->show; |
|
| 2629 | - |
|
| 2630 | - // si c'est une colonne de la table, ne rien faire |
|
| 2631 | - if (isset($table['field'][$col])) { |
|
| 2632 | - return ''; |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2636 | - return ''; |
|
| 2637 | - } |
|
| 2638 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2639 | - |
|
| 2640 | - $col = $regs[1]; |
|
| 2641 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2642 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2643 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2644 | - |
|
| 2645 | - if (isset($table['field']["date$suite"])) { |
|
| 2646 | - $date_orig = 'date' . $suite; |
|
| 2647 | - } else { |
|
| 2648 | - $date_orig = substr($suite, 1); |
|
| 2649 | - } |
|
| 2650 | - $pred = $date_orig; |
|
| 2651 | - } else { |
|
| 2652 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2653 | - $pred = 'date'; |
|
| 2654 | - } |
|
| 2655 | - } |
|
| 2656 | - |
|
| 2657 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2658 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2659 | - ") . '\""; |
|
| 2660 | - |
|
| 2661 | - $col_vraie = $date_orig; |
|
| 2662 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2663 | - |
|
| 2664 | - switch ($col) { |
|
| 2665 | - case 'date': |
|
| 2666 | - $col = $date_orig; |
|
| 2667 | - break; |
|
| 2668 | - case 'jour': |
|
| 2669 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2670 | - break; |
|
| 2671 | - case 'mois': |
|
| 2672 | - $col = "MONTH($date_orig)"; |
|
| 2673 | - break; |
|
| 2674 | - case 'annee': |
|
| 2675 | - $col = "YEAR($date_orig)"; |
|
| 2676 | - break; |
|
| 2677 | - case 'heure': |
|
| 2678 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2679 | - break; |
|
| 2680 | - case 'age': |
|
| 2681 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2682 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2683 | - break; |
|
| 2684 | - case 'age_relatif': |
|
| 2685 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2686 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2687 | - break; |
|
| 2688 | - case 'jour_relatif': |
|
| 2689 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2691 | - break; |
|
| 2692 | - case 'mois_relatif': |
|
| 2693 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2694 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2695 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2696 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2697 | - break; |
|
| 2698 | - case 'annee_relatif': |
|
| 2699 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2700 | - $date_orig . ')'; |
|
| 2701 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2702 | - break; |
|
| 2703 | - } |
|
| 2704 | - |
|
| 2705 | - return [$col, $col_vraie]; |
|
| 2623 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2624 | + return ''; |
|
| 2625 | + } |
|
| 2626 | + |
|
| 2627 | + $boucle = $boucles[$idb]; |
|
| 2628 | + $table = $boucle->show; |
|
| 2629 | + |
|
| 2630 | + // si c'est une colonne de la table, ne rien faire |
|
| 2631 | + if (isset($table['field'][$col])) { |
|
| 2632 | + return ''; |
|
| 2633 | + } |
|
| 2634 | + |
|
| 2635 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2636 | + return ''; |
|
| 2637 | + } |
|
| 2638 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2639 | + |
|
| 2640 | + $col = $regs[1]; |
|
| 2641 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2642 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2643 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2644 | + |
|
| 2645 | + if (isset($table['field']["date$suite"])) { |
|
| 2646 | + $date_orig = 'date' . $suite; |
|
| 2647 | + } else { |
|
| 2648 | + $date_orig = substr($suite, 1); |
|
| 2649 | + } |
|
| 2650 | + $pred = $date_orig; |
|
| 2651 | + } else { |
|
| 2652 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2653 | + $pred = 'date'; |
|
| 2654 | + } |
|
| 2655 | + } |
|
| 2656 | + |
|
| 2657 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2658 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2659 | + ") . '\""; |
|
| 2660 | + |
|
| 2661 | + $col_vraie = $date_orig; |
|
| 2662 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2663 | + |
|
| 2664 | + switch ($col) { |
|
| 2665 | + case 'date': |
|
| 2666 | + $col = $date_orig; |
|
| 2667 | + break; |
|
| 2668 | + case 'jour': |
|
| 2669 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2670 | + break; |
|
| 2671 | + case 'mois': |
|
| 2672 | + $col = "MONTH($date_orig)"; |
|
| 2673 | + break; |
|
| 2674 | + case 'annee': |
|
| 2675 | + $col = "YEAR($date_orig)"; |
|
| 2676 | + break; |
|
| 2677 | + case 'heure': |
|
| 2678 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2679 | + break; |
|
| 2680 | + case 'age': |
|
| 2681 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2682 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2683 | + break; |
|
| 2684 | + case 'age_relatif': |
|
| 2685 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2686 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2687 | + break; |
|
| 2688 | + case 'jour_relatif': |
|
| 2689 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2690 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2691 | + break; |
|
| 2692 | + case 'mois_relatif': |
|
| 2693 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2694 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2695 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2696 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2697 | + break; |
|
| 2698 | + case 'annee_relatif': |
|
| 2699 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2700 | + $date_orig . ')'; |
|
| 2701 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2702 | + break; |
|
| 2703 | + } |
|
| 2704 | + |
|
| 2705 | + return [$col, $col_vraie]; |
|
| 2706 | 2706 | } |
| 2707 | 2707 | |
| 2708 | 2708 | /** |
@@ -2721,16 +2721,16 @@ discard block |
||
| 2721 | 2721 | * de colonne SQL et une date. |
| 2722 | 2722 | **/ |
| 2723 | 2723 | function calculer_param_date($date_compare, $date_orig) { |
| 2724 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2725 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2726 | - $date_compare = '\'$x\''; |
|
| 2727 | - } else { |
|
| 2728 | - $init = $date_compare; |
|
| 2729 | - } |
|
| 2730 | - |
|
| 2731 | - return |
|
| 2732 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2733 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2724 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2725 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2726 | + $date_compare = '\'$x\''; |
|
| 2727 | + } else { |
|
| 2728 | + $init = $date_compare; |
|
| 2729 | + } |
|
| 2730 | + |
|
| 2731 | + return |
|
| 2732 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2733 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2734 | 2734 | } |
| 2735 | 2735 | |
| 2736 | 2736 | /** |
@@ -2748,20 +2748,20 @@ discard block |
||
| 2748 | 2748 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2749 | 2749 | */ |
| 2750 | 2750 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2751 | - $boucle = &$boucles[$idb]; |
|
| 2752 | - |
|
| 2753 | - $args = []; |
|
| 2754 | - foreach ($crit->param as &$param) { |
|
| 2755 | - array_push( |
|
| 2756 | - $args, |
|
| 2757 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2758 | - ); |
|
| 2759 | - } |
|
| 2751 | + $boucle = &$boucles[$idb]; |
|
| 2760 | 2752 | |
| 2761 | - $boucle->hash .= ' |
|
| 2753 | + $args = []; |
|
| 2754 | + foreach ($crit->param as &$param) { |
|
| 2755 | + array_push( |
|
| 2756 | + $args, |
|
| 2757 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2758 | + ); |
|
| 2759 | + } |
|
| 2760 | + |
|
| 2761 | + $boucle->hash .= ' |
|
| 2762 | 2762 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2763 | 2763 | |
| 2764 | - $boucle->hash .= ' |
|
| 2764 | + $boucle->hash .= ' |
|
| 2765 | 2765 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2766 | 2766 | } |
| 2767 | 2767 | |
@@ -2779,8 +2779,8 @@ discard block |
||
| 2779 | 2779 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2780 | 2780 | */ |
| 2781 | 2781 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2782 | - $boucle = &$boucles[$idb]; |
|
| 2783 | - $boucle->hash .= ' |
|
| 2782 | + $boucle = &$boucles[$idb]; |
|
| 2783 | + $boucle->hash .= ' |
|
| 2784 | 2784 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2785 | 2785 | } |
| 2786 | 2786 | |
@@ -2796,12 +2796,12 @@ discard block |
||
| 2796 | 2796 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2797 | 2797 | */ |
| 2798 | 2798 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2799 | - $boucle = &$boucles[$idb]; |
|
| 2800 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2801 | - foreach ($crit->param as $param) { |
|
| 2802 | - $boucle->hash .= ' |
|
| 2799 | + $boucle = &$boucles[$idb]; |
|
| 2800 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2801 | + foreach ($crit->param as $param) { |
|
| 2802 | + $boucle->hash .= ' |
|
| 2803 | 2803 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2804 | - } |
|
| 2804 | + } |
|
| 2805 | 2805 | } |
| 2806 | 2806 | |
| 2807 | 2807 | /** |
@@ -2818,16 +2818,16 @@ discard block |
||
| 2818 | 2818 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2819 | 2819 | */ |
| 2820 | 2820 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2821 | - $boucle = &$boucles[$idb]; |
|
| 2822 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2823 | - foreach ($crit->param as $param) { |
|
| 2824 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2825 | - $param, |
|
| 2826 | - $idb, |
|
| 2827 | - $boucles, |
|
| 2828 | - $boucles[$idb]->id_parent |
|
| 2829 | - ) . ";\n"; |
|
| 2830 | - } |
|
| 2821 | + $boucle = &$boucles[$idb]; |
|
| 2822 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2823 | + foreach ($crit->param as $param) { |
|
| 2824 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2825 | + $param, |
|
| 2826 | + $idb, |
|
| 2827 | + $boucles, |
|
| 2828 | + $boucles[$idb]->id_parent |
|
| 2829 | + ) . ";\n"; |
|
| 2830 | + } |
|
| 2831 | 2831 | } |
| 2832 | 2832 | |
| 2833 | 2833 | /** |
@@ -2852,16 +2852,16 @@ discard block |
||
| 2852 | 2852 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2853 | 2853 | */ |
| 2854 | 2854 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2855 | - $boucle = &$boucles[$idb]; |
|
| 2856 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2857 | - foreach ($crit->param as $param) { |
|
| 2858 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2859 | - $param, |
|
| 2860 | - $idb, |
|
| 2861 | - $boucles, |
|
| 2862 | - $boucles[$idb]->id_parent |
|
| 2863 | - ) . ";\n"; |
|
| 2864 | - } |
|
| 2855 | + $boucle = &$boucles[$idb]; |
|
| 2856 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2857 | + foreach ($crit->param as $param) { |
|
| 2858 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2859 | + $param, |
|
| 2860 | + $idb, |
|
| 2861 | + $boucles, |
|
| 2862 | + $boucles[$idb]->id_parent |
|
| 2863 | + ) . ";\n"; |
|
| 2864 | + } |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | /** |
@@ -2876,11 +2876,11 @@ discard block |
||
| 2876 | 2876 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2877 | 2877 | */ |
| 2878 | 2878 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2879 | - $boucle = &$boucles[$idb]; |
|
| 2880 | - foreach ($crit->param as $param) { |
|
| 2881 | - $boucle->hash .= ' |
|
| 2879 | + $boucle = &$boucles[$idb]; |
|
| 2880 | + foreach ($crit->param as $param) { |
|
| 2881 | + $boucle->hash .= ' |
|
| 2882 | 2882 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2883 | - } |
|
| 2883 | + } |
|
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 2886 | |
@@ -2912,20 +2912,20 @@ discard block |
||
| 2912 | 2912 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2913 | 2913 | */ |
| 2914 | 2914 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2915 | - $boucle = &$boucles[$idb]; |
|
| 2916 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2917 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2918 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2919 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2920 | - if ($crit->param) { |
|
| 2921 | - foreach ($crit->param as $param) { |
|
| 2922 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2923 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2924 | - } |
|
| 2925 | - // interdire {si 0} aussi ! |
|
| 2926 | - } else { |
|
| 2927 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2928 | - } |
|
| 2915 | + $boucle = &$boucles[$idb]; |
|
| 2916 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2917 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2918 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2919 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2920 | + if ($crit->param) { |
|
| 2921 | + foreach ($crit->param as $param) { |
|
| 2922 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2923 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2924 | + } |
|
| 2925 | + // interdire {si 0} aussi ! |
|
| 2926 | + } else { |
|
| 2927 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2928 | + } |
|
| 2929 | 2929 | } |
| 2930 | 2930 | |
| 2931 | 2931 | /** |
@@ -2942,8 +2942,8 @@ discard block |
||
| 2942 | 2942 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2943 | 2943 | */ |
| 2944 | 2944 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2945 | - $boucle = &$boucles[$idb]; |
|
| 2946 | - $boucle->hash .= ' |
|
| 2945 | + $boucle = &$boucles[$idb]; |
|
| 2946 | + $boucle->hash .= ' |
|
| 2947 | 2947 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2948 | 2948 | $command[\'sourcemode\'] = \'table\';'; |
| 2949 | 2949 | } |
@@ -2964,29 +2964,29 @@ discard block |
||
| 2964 | 2964 | */ |
| 2965 | 2965 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2966 | 2966 | |
| 2967 | - $not = $crit->not; |
|
| 2968 | - $boucle = &$boucles[$idb]; |
|
| 2969 | - $primary = $boucle->primary; |
|
| 2967 | + $not = $crit->not; |
|
| 2968 | + $boucle = &$boucles[$idb]; |
|
| 2969 | + $primary = $boucle->primary; |
|
| 2970 | 2970 | |
| 2971 | - if (!$primary or strpos($primary, ',')) { |
|
| 2972 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2971 | + if (!$primary or strpos($primary, ',')) { |
|
| 2972 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2973 | 2973 | |
| 2974 | - return; |
|
| 2975 | - } |
|
| 2976 | - $table = $boucle->type_requete; |
|
| 2977 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2974 | + return; |
|
| 2975 | + } |
|
| 2976 | + $table = $boucle->type_requete; |
|
| 2977 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2978 | 2978 | |
| 2979 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2980 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2981 | - 'id_parent'; |
|
| 2979 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2980 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2981 | + 'id_parent'; |
|
| 2982 | 2982 | |
| 2983 | - $in = 'IN'; |
|
| 2984 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2985 | - if ($not) { |
|
| 2986 | - $where = ["'NOT'", $where]; |
|
| 2987 | - } |
|
| 2983 | + $in = 'IN'; |
|
| 2984 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2985 | + if ($not) { |
|
| 2986 | + $where = ["'NOT'", $where]; |
|
| 2987 | + } |
|
| 2988 | 2988 | |
| 2989 | - $boucle->where[] = $where; |
|
| 2989 | + $boucle->where[] = $where; |
|
| 2990 | 2990 | } |
| 2991 | 2991 | |
| 2992 | 2992 | /** |
@@ -3002,8 +3002,8 @@ discard block |
||
| 3002 | 3002 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3003 | 3003 | */ |
| 3004 | 3004 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3005 | - $not = $crit->not; |
|
| 3006 | - $crit->not = $not ? false : true; |
|
| 3007 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3008 | - $crit->not = $not; |
|
| 3005 | + $not = $crit->not; |
|
| 3006 | + $crit->not = $not ? false : true; |
|
| 3007 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3008 | + $crit->not = $not; |
|
| 3009 | 3009 | } |
@@ -46,10 +46,9 @@ discard block |
||
| 46 | 46 | $not = $crit->not; |
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 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'; |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 51 | 50 | |
| 52 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -72,10 +71,10 @@ discard block |
||
| 72 | 71 | $id = $boucle->primary; |
| 73 | 72 | |
| 74 | 73 | if ($not or !$id) { |
| 75 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | + return (['zbug_critere_inconnu', ['critere' => $not.$crit->op]]); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
@@ -106,12 +105,12 @@ discard block |
||
| 106 | 105 | $not = ($crit->not ? '' : 'NOT'); |
| 107 | 106 | |
| 108 | 107 | // le doublon s'applique sur un type de boucle (article) |
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + $nom = "'".$boucle->type_requete."'"; |
|
| 110 | 109 | |
| 111 | 110 | // compléter le nom avec un nom précisé {doublons nom} |
| 112 | 111 | // on obtient $nom = "'article' . 'nom'" |
| 113 | 112 | if (isset($crit->param[0])) { |
| 114 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | // $doublons et son index, ici $nom |
| 124 | 123 | |
| 125 | 124 | // debut du code "sql_in('articles.id_article', " |
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 127 | 126 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 128 | 127 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons.'[]= ')); |
|
| 130 | 129 | |
| 131 | 130 | // le debut complet du code des doublons |
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + $debut_doub = $debut_in.$debut_doub; |
|
| 133 | 132 | |
| 134 | 133 | // nom du doublon "('article' . 'nom')]" |
| 135 | 134 | $fin_doub = "($nom)]"; |
@@ -139,22 +138,22 @@ discard block |
||
| 139 | 138 | foreach ($boucle->where as $k => $w) { |
| 140 | 139 | if (strpos($w[0], $debut_doub) === 0) { |
| 141 | 140 | // fusionner le sql_in (du where) |
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 143 | 142 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 144 | 143 | $x = strpos($boucle->hash, $init_comment); |
| 145 | 144 | $len = strlen($init_comment); |
| 146 | 145 | $boucle->hash = |
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 148 | 147 | |
| 149 | 148 | return; |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 154 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 155 | 154 | |
| 156 | 155 | // déclarer le doublon s'il n'existe pas encore |
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + $boucle->hash .= $init_comment.$init_code; |
|
| 158 | 157 | |
| 159 | 158 | |
| 160 | 159 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | $un = $un[0]->texte; |
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 217 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 218 | + $un. |
|
| 219 | + '"]) . ",'. |
|
| 220 | + $deux. |
|
| 222 | 221 | '"'; |
| 223 | 222 | } else { |
| 224 | 223 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
@@ -281,26 +280,26 @@ discard block |
||
| 281 | 280 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 285 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 286 | 285 | $partie = |
| 287 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 289 | 288 | . "\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" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 292 | 291 | . "\t}\n" |
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->hash .= ' |
| 296 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 297 | 296 | |
| 298 | 297 | $boucle->total_parties = $pas; |
| 299 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 300 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 301 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 302 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 304 | 303 | if ( |
| 305 | 304 | $boucle->primary |
| 306 | 305 | and !preg_match('/[,\s]/', $boucle->primary) |
@@ -347,24 +346,24 @@ discard block |
||
| 347 | 346 | $boucle->hash .= ' |
| 348 | 347 | // RECHERCHE' |
| 349 | 348 | . ($crit->cond ? ' |
| 350 | - if (!strlen(' . $quoi . ')){ |
|
| 349 | + if (!strlen(' . $quoi.')){ |
|
| 351 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 352 | - } else' : '') . ' |
|
| 351 | + } else' : '').' |
|
| 353 | 352 | { |
| 354 | 353 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 355 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 354 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 356 | 355 | } |
| 357 | 356 | '; |
| 358 | 357 | |
| 359 | 358 | |
| 360 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 359 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 361 | 360 | if (!in_array($t, $boucles[$idb]->select)) { |
| 362 | 361 | $boucle->select[] = $t; |
| 363 | 362 | } # pour postgres, neuneu ici |
| 364 | 363 | // jointure uniquement sur le serveur principal |
| 365 | 364 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 366 | 365 | if (!$boucle->sql_serveur) { |
| 367 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 366 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 368 | 367 | $boucle->from['resultats'] = 'spip_resultats'; |
| 369 | 368 | } |
| 370 | 369 | $boucle->select[] = '$rech_select'; |
@@ -431,7 +430,7 @@ discard block |
||
| 431 | 430 | $c = |
| 432 | 431 | [ |
| 433 | 432 | "'OR'", |
| 434 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 433 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 435 | 434 | ["'='", "'$table.id_trad'", "'0'"] |
| 436 | 435 | ]; |
| 437 | 436 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -454,15 +453,14 @@ discard block |
||
| 454 | 453 | $boucle = &$boucles[$idb]; |
| 455 | 454 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 456 | 455 | $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; |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 457 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 460 | 458 | |
| 461 | 459 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 462 | 460 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 463 | 461 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 464 | 462 | else { |
| 465 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 463 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]); |
|
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |
@@ -515,16 +513,15 @@ discard block |
||
| 515 | 513 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 516 | 514 | $decompose = decompose_champ_id_objet($champ); |
| 517 | 515 | $champ = array_shift($decompose); |
| 518 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 519 | 517 | } |
| 520 | 518 | } else { |
| 521 | 519 | $cle = $boucle->id_table; |
| 522 | 520 | } |
| 523 | 521 | |
| 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'") . ')'); |
|
| 522 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 523 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 524 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | /** |
@@ -544,9 +541,9 @@ discard block |
||
| 544 | 541 | $not = ($crit->not ? 'NOT' : ''); |
| 545 | 542 | $serveur = $boucle->sql_serveur; |
| 546 | 543 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('". |
|
| 545 | + $boucle->id_table.'.'.$boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 550 | 547 | |
| 551 | 548 | $boucle->where[] = $c; |
| 552 | 549 | } |
@@ -578,7 +575,7 @@ discard block |
||
| 578 | 575 | $t = table_objet_sql($r[1]); |
| 579 | 576 | $t = array_search($t, $boucles[$idb]->from); |
| 580 | 577 | if ($t) { |
| 581 | - $t .= '.' . $r[2]; |
|
| 578 | + $t .= '.'.$r[2]; |
|
| 582 | 579 | } |
| 583 | 580 | } |
| 584 | 581 | } else { |
@@ -593,7 +590,7 @@ discard block |
||
| 593 | 590 | $boucles[$idb]->select[] = $t; |
| 594 | 591 | } |
| 595 | 592 | } else { |
| 596 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 593 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 597 | 594 | } |
| 598 | 595 | } |
| 599 | 596 | |
@@ -663,26 +660,26 @@ discard block |
||
| 663 | 660 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 664 | 661 | or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 665 | 662 | ) { |
| 666 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 663 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 667 | 664 | } else { |
| 668 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 665 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 669 | 666 | } |
| 670 | 667 | } |
| 671 | 668 | } else { |
| 672 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 669 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.count($boucles[$idb]->order)]]); |
|
| 673 | 670 | } |
| 674 | 671 | } |
| 675 | 672 | |
| 676 | 673 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 677 | 674 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 678 | 675 | $boucle = $boucles[$idb]; |
| 679 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 680 | - $var = '$champs_' . $idb; |
|
| 676 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 677 | + $var = '$champs_'.$idb; |
|
| 681 | 678 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 682 | 679 | if (!$desc) { |
| 683 | 680 | $desc = $boucle->show['field']; |
| 684 | 681 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 685 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 686 | 683 | } |
| 687 | 684 | if ($desc) { |
| 688 | 685 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -757,7 +754,7 @@ discard block |
||
| 757 | 754 | $sens = " . ' DESC'"; |
| 758 | 755 | } |
| 759 | 756 | if (isset($boucle->modificateur['collate'])) { |
| 760 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 761 | 758 | } |
| 762 | 759 | |
| 763 | 760 | // Pour chaque paramètre du critère |
@@ -779,14 +776,14 @@ discard block |
||
| 779 | 776 | if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
| 780 | 777 | $expression = trim($m[1]); |
| 781 | 778 | $champ = trim($m[2]); |
| 782 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 783 | 780 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 784 | 781 | } else { |
| 785 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 786 | 783 | } |
| 787 | 784 | |
| 788 | 785 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 789 | - } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 786 | + } elseif (preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 790 | 787 | // {par FONCTION(champ)} |
| 791 | 788 | if (count($match) > 2) { |
| 792 | 789 | $par = substr($match[2], 1, -1); |
@@ -796,7 +793,7 @@ discard block |
||
| 796 | 793 | if ($par == 'hasard') { |
| 797 | 794 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 798 | 795 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 799 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 800 | 797 | } else { |
| 801 | 798 | // cas général {par champ}, {par table.champ}, ... |
| 802 | 799 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -805,7 +802,7 @@ discard block |
||
| 805 | 802 | |
| 806 | 803 | // on ne sait pas traiter… |
| 807 | 804 | else { |
| 808 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 809 | 806 | } |
| 810 | 807 | |
| 811 | 808 | // En cas d'erreur de squelette retournée par une fonction |
@@ -825,14 +822,14 @@ discard block |
||
| 825 | 822 | |
| 826 | 823 | if ($fct) { |
| 827 | 824 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 828 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 825 | + $order = "'$fct(".$r[1].")'"; |
|
| 829 | 826 | } else { |
| 830 | 827 | $order = "'$fct(' . $order . ')'"; |
| 831 | 828 | } |
| 832 | 829 | } |
| 833 | - $t = $order . $collecte . $sens; |
|
| 830 | + $t = $order.$collecte.$sens; |
|
| 834 | 831 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 835 | - $t = $r[1] . $r[2]; |
|
| 832 | + $t = $r[1].$r[2]; |
|
| 836 | 833 | } |
| 837 | 834 | |
| 838 | 835 | $boucle->order[] = $t; |
@@ -882,16 +879,16 @@ discard block |
||
| 882 | 879 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 883 | 880 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 884 | 881 | if (is_array($_champ)) { |
| 885 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 882 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 886 | 883 | } |
| 887 | 884 | $boucle = &$boucles[$idb]; |
| 888 | - $texte = '0+' . $_champ; |
|
| 885 | + $texte = '0+'.$_champ; |
|
| 889 | 886 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 890 | 887 | if ($suite !== "''") { |
| 891 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 888 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 892 | 889 | } |
| 893 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 894 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 890 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 891 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 895 | 892 | |
| 896 | 893 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 897 | 894 | $orderassinum = trim($orderassinum, "'"); |
@@ -920,13 +917,13 @@ discard block |
||
| 920 | 917 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 921 | 918 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 922 | 919 | if (is_array($_champ)) { |
| 923 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 920 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 924 | 921 | } |
| 925 | 922 | $boucle = &$boucles[$idb]; |
| 926 | - $texte = '0+' . $_champ; |
|
| 923 | + $texte = '0+'.$_champ; |
|
| 927 | 924 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 928 | 925 | if ($suite !== "''") { |
| 929 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 926 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 930 | 927 | } |
| 931 | 928 | |
| 932 | 929 | $as = false; |
@@ -942,8 +939,8 @@ discard block |
||
| 942 | 939 | } |
| 943 | 940 | |
| 944 | 941 | if (!$as) { |
| 945 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 946 | - $boucle->select[] = $select . $as; |
|
| 942 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 943 | + $boucle->select[] = $select.$as; |
|
| 947 | 944 | } |
| 948 | 945 | $order = "'$as'"; |
| 949 | 946 | return $order; |
@@ -968,10 +965,10 @@ discard block |
||
| 968 | 965 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 969 | 966 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 970 | 967 | if (is_array($_champ)) { |
| 971 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 968 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 972 | 969 | } |
| 973 | 970 | $boucle = &$boucles[$idb]; |
| 974 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 971 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 975 | 972 | $order = "'multi'"; |
| 976 | 973 | return $order; |
| 977 | 974 | } |
@@ -997,7 +994,7 @@ discard block |
||
| 997 | 994 | |
| 998 | 995 | // le champ existe dans la table, pas de souci (le plus commun) |
| 999 | 996 | if (isset($desc['field'][$par])) { |
| 1000 | - $par = $boucle->id_table . '.' . $par; |
|
| 997 | + $par = $boucle->id_table.'.'.$par; |
|
| 1001 | 998 | } |
| 1002 | 999 | // le champ est peut être une jointure |
| 1003 | 1000 | else { |
@@ -1018,24 +1015,24 @@ discard block |
||
| 1018 | 1015 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1019 | 1016 | // Si la table est déjà dans le from, on la réutilise. |
| 1020 | 1017 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1021 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1018 | + $par = $infos['alias'].'.'.$champ; |
|
| 1022 | 1019 | } elseif ( |
| 1023 | 1020 | $boucle->jointures_explicites |
| 1024 | 1021 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 1025 | 1022 | ) { |
| 1026 | - $par = $alias . '.' . $champ; |
|
| 1023 | + $par = $alias.'.'.$champ; |
|
| 1027 | 1024 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1028 | - $par = $alias . '.' . $champ; |
|
| 1025 | + $par = $alias.'.'.$champ; |
|
| 1029 | 1026 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1030 | 1027 | } elseif ( |
| 1031 | 1028 | $table_alias |
| 1032 | 1029 | and isset($boucle->from[$table_alias]) |
| 1033 | 1030 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1034 | 1031 | ) { |
| 1035 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1032 | + $par = $infos['alias'].'.'.$champ; |
|
| 1036 | 1033 | } elseif ($table) { |
| 1037 | 1034 | // On avait table + champ, mais on ne les a pas trouvés |
| 1038 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1035 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1039 | 1036 | } else { |
| 1040 | 1037 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1041 | 1038 | } |
@@ -1059,7 +1056,7 @@ discard block |
||
| 1059 | 1056 | if (!$t) { |
| 1060 | 1057 | $t = trouver_jointure_champ($champ, $boucle); |
| 1061 | 1058 | } |
| 1062 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1059 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1063 | 1060 | } |
| 1064 | 1061 | |
| 1065 | 1062 | /** |
@@ -1104,9 +1101,9 @@ discard block |
||
| 1104 | 1101 | $boucle->default_order[] = ' DESC'; |
| 1105 | 1102 | } |
| 1106 | 1103 | } else { |
| 1107 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1104 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1108 | 1105 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1109 | - $t = $r[1] . $r[2]; |
|
| 1106 | + $t = $r[1].$r[2]; |
|
| 1110 | 1107 | } |
| 1111 | 1108 | $boucle->order[$n - 1] = $t; |
| 1112 | 1109 | } |
@@ -1141,7 +1138,7 @@ discard block |
||
| 1141 | 1138 | $_order = array_pop($boucle->order); |
| 1142 | 1139 | |
| 1143 | 1140 | $_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"; |
|
| 1141 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1145 | 1142 | } |
| 1146 | 1143 | |
| 1147 | 1144 | |
@@ -1150,7 +1147,7 @@ discard block |
||
| 1150 | 1147 | $params = $crit->param; |
| 1151 | 1148 | |
| 1152 | 1149 | if (count($params) < 1) { |
| 1153 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1150 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1154 | 1151 | } |
| 1155 | 1152 | |
| 1156 | 1153 | $boucle = &$boucles[$idb]; |
@@ -1171,7 +1168,7 @@ discard block |
||
| 1171 | 1168 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1172 | 1169 | $date = $date[0]->texte; |
| 1173 | 1170 | if (!isset($fields[$date])) { |
| 1174 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1171 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1175 | 1172 | } |
| 1176 | 1173 | } else { |
| 1177 | 1174 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1183,38 +1180,38 @@ discard block |
||
| 1183 | 1180 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1184 | 1181 | } |
| 1185 | 1182 | $annee = $params ? array_shift($params) : ''; |
| 1186 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1187 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1183 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1184 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1188 | 1185 | ') ? $x : date("Y"))'; |
| 1189 | 1186 | |
| 1190 | 1187 | $mois = $params ? array_shift($params) : ''; |
| 1191 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1192 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1188 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1189 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1193 | 1190 | ') ? $x : date("m"))'; |
| 1194 | 1191 | |
| 1195 | 1192 | $jour = $params ? array_shift($params) : ''; |
| 1196 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1197 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1193 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1194 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1198 | 1195 | ') ? $x : date("d"))'; |
| 1199 | 1196 | |
| 1200 | 1197 | $annee2 = $params ? array_shift($params) : ''; |
| 1201 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1202 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1198 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1199 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1203 | 1200 | ') ? $x : date("Y"))'; |
| 1204 | 1201 | |
| 1205 | 1202 | $mois2 = $params ? array_shift($params) : ''; |
| 1206 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1207 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1203 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1204 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1208 | 1205 | ') ? $x : date("m"))'; |
| 1209 | 1206 | |
| 1210 | 1207 | $jour2 = $params ? array_shift($params) : ''; |
| 1211 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1212 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1208 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1209 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1213 | 1210 | ') ? $x : date("d"))'; |
| 1214 | 1211 | |
| 1215 | - $date = $boucle->id_table . ".$date"; |
|
| 1212 | + $date = $boucle->id_table.".$date"; |
|
| 1216 | 1213 | |
| 1217 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1214 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1218 | 1215 | if ($type == 'jour') { |
| 1219 | 1216 | $boucle->where[] = [ |
| 1220 | 1217 | "'='", |
@@ -1286,14 +1283,13 @@ discard block |
||
| 1286 | 1283 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1287 | 1284 | |
| 1288 | 1285 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1289 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1286 | + $boucle->limit = $a11.','.$a21; |
|
| 1290 | 1287 | } else { |
| 1291 | 1288 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1292 | 1289 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1293 | 1290 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1294 | 1291 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1295 | - $mode = (($op == '/') ? '/' : |
|
| 1296 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1292 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1297 | 1293 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1298 | 1294 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1299 | 1295 | $boucle->limit = |
@@ -1339,8 +1335,7 @@ discard block |
||
| 1339 | 1335 | // {1/3} |
| 1340 | 1336 | if ($op1 == '/') { |
| 1341 | 1337 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1342 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1343 | - "($total_parties ? $total_parties : 1)"; |
|
| 1338 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1344 | 1339 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1345 | 1340 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1346 | 1341 | } else { |
@@ -1351,15 +1346,13 @@ discard block |
||
| 1351 | 1346 | |
| 1352 | 1347 | // cas {x,n-1} |
| 1353 | 1348 | if ($op2 == '-') { |
| 1354 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1355 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1356 | - ($total_parties . ' - 1')); |
|
| 1349 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1350 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1357 | 1351 | } else { |
| 1358 | 1352 | // {x,1} ou {pagination} |
| 1359 | 1353 | $fin = '$debut_boucle' |
| 1360 | 1354 | . (is_numeric($total_parties) ? |
| 1361 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1362 | - ('+' . $total_parties . ' - 1')); |
|
| 1355 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1363 | 1356 | } |
| 1364 | 1357 | |
| 1365 | 1358 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1377,11 +1370,11 @@ discard block |
||
| 1377 | 1370 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1378 | 1371 | |
| 1379 | 1372 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1380 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1373 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1381 | 1374 | . "\$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);' |
|
| 1375 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1376 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1377 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1385 | 1378 | . "\n\tif (\$debut_boucle>0" |
| 1386 | 1379 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1387 | 1380 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1466,16 +1459,16 @@ discard block |
||
| 1466 | 1459 | // critere personnalise ? |
| 1467 | 1460 | if ( |
| 1468 | 1461 | (!$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')) |
|
| 1462 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1463 | + and (!function_exists($f = $f.'_dist')) |
|
| 1464 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1465 | + and (!function_exists($f = $f.'_dist')) |
|
| 1473 | 1466 | ) |
| 1474 | 1467 | ) |
| 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')) |
|
| 1468 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1469 | + and (!function_exists($f = $f.'_dist')) |
|
| 1470 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1471 | + and (!function_exists($f = $f.'_dist')) |
|
| 1479 | 1472 | ) { |
| 1480 | 1473 | // fonction critere standard |
| 1481 | 1474 | $f = $defaut; |
@@ -1508,9 +1501,9 @@ discard block |
||
| 1508 | 1501 | */ |
| 1509 | 1502 | function kwote($lisp, $serveur = '', $type = '') { |
| 1510 | 1503 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1511 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1504 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1512 | 1505 | } else { |
| 1513 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1506 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1514 | 1507 | } |
| 1515 | 1508 | } |
| 1516 | 1509 | |
@@ -1532,7 +1525,7 @@ discard block |
||
| 1532 | 1525 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1533 | 1526 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1534 | 1527 | if (!$r) { |
| 1535 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1528 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 1536 | 1529 | } |
| 1537 | 1530 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1538 | 1531 | |
@@ -1557,8 +1550,8 @@ discard block |
||
| 1557 | 1550 | "'NOT'", |
| 1558 | 1551 | [ |
| 1559 | 1552 | "'IN'", |
| 1560 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1561 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1553 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1554 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1562 | 1555 | ] |
| 1563 | 1556 | ]; |
| 1564 | 1557 | } |
@@ -1576,22 +1569,22 @@ discard block |
||
| 1576 | 1569 | $descr = $boucles[$idb]->descr; |
| 1577 | 1570 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1578 | 1571 | |
| 1579 | - $var = '$in' . $cpt++; |
|
| 1572 | + $var = '$in'.$cpt++; |
|
| 1580 | 1573 | $x = "\n\t$var = array();"; |
| 1581 | 1574 | foreach ($val as $k => $v) { |
| 1582 | 1575 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1583 | 1576 | // optimiser le traitement des constantes |
| 1584 | 1577 | if (is_numeric($r[2])) { |
| 1585 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1578 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1586 | 1579 | } else { |
| 1587 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1580 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1588 | 1581 | } |
| 1589 | 1582 | } else { |
| 1590 | 1583 | // Pour permettre de passer des tableaux de valeurs |
| 1591 | 1584 | // on repere l'utilisation brute de #ENV**{X}, |
| 1592 | 1585 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1593 | 1586 | // 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);"; |
|
| 1587 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1595 | 1588 | } |
| 1596 | 1589 | } |
| 1597 | 1590 | |
@@ -1605,7 +1598,7 @@ discard block |
||
| 1605 | 1598 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1606 | 1599 | } |
| 1607 | 1600 | |
| 1608 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1601 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1609 | 1602 | } |
| 1610 | 1603 | |
| 1611 | 1604 | /** |
@@ -1678,7 +1671,7 @@ discard block |
||
| 1678 | 1671 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1679 | 1672 | } |
| 1680 | 1673 | // nous aider en mode debug. |
| 1681 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1674 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1682 | 1675 | $boucle->modificateur['id_'] = $champs; |
| 1683 | 1676 | |
| 1684 | 1677 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1719,7 +1712,7 @@ discard block |
||
| 1719 | 1712 | // Les champs id_xx de la table demandée |
| 1720 | 1713 | $champs = array_filter( |
| 1721 | 1714 | array_keys($desc['field']), |
| 1722 | - function ($champ) { |
|
| 1715 | + function($champ) { |
|
| 1723 | 1716 | return |
| 1724 | 1717 | strpos($champ, 'id_') === 0 |
| 1725 | 1718 | or (in_array($champ, ['objet'])); |
@@ -1933,8 +1926,8 @@ discard block |
||
| 1933 | 1926 | "'NOT'", |
| 1934 | 1927 | [ |
| 1935 | 1928 | "'IN'", |
| 1936 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1937 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1929 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1930 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1938 | 1931 | ] |
| 1939 | 1932 | ]; |
| 1940 | 1933 | } |
@@ -1945,7 +1938,7 @@ discard block |
||
| 1945 | 1938 | if ($crit->cond) { |
| 1946 | 1939 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1947 | 1940 | if ($col == 'date' or $col == 'date_redac') { |
| 1948 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1941 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1949 | 1942 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1950 | 1943 | } |
| 1951 | 1944 | } |
@@ -2106,7 +2099,7 @@ discard block |
||
| 2106 | 2099 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2107 | 2100 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2108 | 2101 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2109 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2102 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2110 | 2103 | } |
| 2111 | 2104 | // sinon expliciter les |
| 2112 | 2105 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2122,14 +2115,14 @@ discard block |
||
| 2122 | 2115 | ) { |
| 2123 | 2116 | $r = $r[1] |
| 2124 | 2117 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2125 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2118 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2126 | 2119 | $val[0] = "sql_quote($r)"; |
| 2127 | 2120 | } |
| 2128 | 2121 | elseif ( |
| 2129 | 2122 | strpos($val[0], '@@defaultcast@@') !== false |
| 2130 | 2123 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2131 | 2124 | ) { |
| 2132 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2125 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2133 | 2126 | } |
| 2134 | 2127 | } |
| 2135 | 2128 | |
@@ -2137,7 +2130,7 @@ discard block |
||
| 2137 | 2130 | strpos($val[0], '@@defaultcast@@') !== false |
| 2138 | 2131 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2139 | 2132 | ) { |
| 2140 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2133 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2141 | 2134 | } |
| 2142 | 2135 | |
| 2143 | 2136 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2153,7 +2146,7 @@ discard block |
||
| 2153 | 2146 | // inserer le nom de la table SQL devant le nom du champ |
| 2154 | 2147 | if ($table) { |
| 2155 | 2148 | if ($col[0] == '`') { |
| 2156 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2149 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2157 | 2150 | } else { |
| 2158 | 2151 | $arg = "$table.$col"; |
| 2159 | 2152 | } |
@@ -2288,9 +2281,9 @@ discard block |
||
| 2288 | 2281 | **/ |
| 2289 | 2282 | function primary_doublee($decompose, $table) { |
| 2290 | 2283 | $e1 = reset($decompose); |
| 2291 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2284 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2292 | 2285 | |
| 2293 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2286 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2294 | 2287 | } |
| 2295 | 2288 | |
| 2296 | 2289 | /** |
@@ -2329,7 +2322,7 @@ discard block |
||
| 2329 | 2322 | $checkarrivee |
| 2330 | 2323 | and is_string($checkarrivee) |
| 2331 | 2324 | and $a = table_objet($checkarrivee) |
| 2332 | - and in_array($a . '_liens', $joints) |
|
| 2325 | + and in_array($a.'_liens', $joints) |
|
| 2333 | 2326 | ) { |
| 2334 | 2327 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2335 | 2328 | return $res; |
@@ -2349,12 +2342,12 @@ discard block |
||
| 2349 | 2342 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2350 | 2343 | $joindre = false; |
| 2351 | 2344 | foreach ($cols as $col) { |
| 2352 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2345 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2353 | 2346 | if (trouver_champ($c, $boucle->where)) { |
| 2354 | 2347 | $joindre = true; |
| 2355 | 2348 | } else { |
| 2356 | 2349 | // mais ca peut etre dans le FIELD pour le Having |
| 2357 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2350 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2358 | 2351 | if (trouver_champ($c, $boucle->select)) { |
| 2359 | 2352 | $joindre = true; |
| 2360 | 2353 | } |
@@ -2400,7 +2393,7 @@ discard block |
||
| 2400 | 2393 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2401 | 2394 | |
| 2402 | 2395 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2403 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2396 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2404 | 2397 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2405 | 2398 | |
| 2406 | 2399 | if (!$intermediaire or !$arrivee) { |
@@ -2504,7 +2497,7 @@ discard block |
||
| 2504 | 2497 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2505 | 2498 | // un critere conditionnel sur date est traite a part |
| 2506 | 2499 | // car la date est mise d'office par SPIP, |
| 2507 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2500 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2508 | 2501 | } |
| 2509 | 2502 | |
| 2510 | 2503 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2536,7 +2529,7 @@ discard block |
||
| 2536 | 2529 | and (($p == "'") or ($p == '"')) |
| 2537 | 2530 | and $params[0][1]->type == 'champ' |
| 2538 | 2531 | ) { |
| 2539 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2532 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2540 | 2533 | } else { |
| 2541 | 2534 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2542 | 2535 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2552,7 +2545,7 @@ discard block |
||
| 2552 | 2545 | $fct = $args_sql = ''; |
| 2553 | 2546 | // fonction SQL ? |
| 2554 | 2547 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2555 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2548 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2556 | 2549 | $fct = $m[1]; |
| 2557 | 2550 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2558 | 2551 | $col = $a[1]; |
@@ -2643,7 +2636,7 @@ discard block |
||
| 2643 | 2636 | # si oui choisir ce champ, sinon choisir xxxx |
| 2644 | 2637 | |
| 2645 | 2638 | if (isset($table['field']["date$suite"])) { |
| 2646 | - $date_orig = 'date' . $suite; |
|
| 2639 | + $date_orig = 'date'.$suite; |
|
| 2647 | 2640 | } else { |
| 2648 | 2641 | $date_orig = substr($suite, 1); |
| 2649 | 2642 | } |
@@ -2654,12 +2647,12 @@ discard block |
||
| 2654 | 2647 | } |
| 2655 | 2648 | } |
| 2656 | 2649 | |
| 2657 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2658 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2650 | + $date_compare = "\"' . normaliser_date(". |
|
| 2651 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2659 | 2652 | ") . '\""; |
| 2660 | 2653 | |
| 2661 | 2654 | $col_vraie = $date_orig; |
| 2662 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2655 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2663 | 2656 | |
| 2664 | 2657 | switch ($col) { |
| 2665 | 2658 | case 'date': |
@@ -2679,26 +2672,26 @@ discard block |
||
| 2679 | 2672 | break; |
| 2680 | 2673 | case 'age': |
| 2681 | 2674 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2682 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2683 | 2676 | break; |
| 2684 | 2677 | case 'age_relatif': |
| 2685 | 2678 | $col = calculer_param_date($date_compare, $date_orig); |
| 2686 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2679 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2687 | 2680 | break; |
| 2688 | 2681 | case 'jour_relatif': |
| 2689 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2683 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2691 | 2684 | break; |
| 2692 | 2685 | case 'mois_relatif': |
| 2693 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2694 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2695 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2696 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2687 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2688 | + ')-YEAR('.$date_orig.'))'; |
|
| 2689 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2697 | 2690 | break; |
| 2698 | 2691 | case 'annee_relatif': |
| 2699 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2700 | - $date_orig . ')'; |
|
| 2701 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2692 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2693 | + $date_orig.')'; |
|
| 2694 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2702 | 2695 | break; |
| 2703 | 2696 | } |
| 2704 | 2697 | |
@@ -2759,10 +2752,10 @@ discard block |
||
| 2759 | 2752 | } |
| 2760 | 2753 | |
| 2761 | 2754 | $boucle->hash .= ' |
| 2762 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2755 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2763 | 2756 | |
| 2764 | 2757 | $boucle->hash .= ' |
| 2765 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2758 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2766 | 2759 | } |
| 2767 | 2760 | |
| 2768 | 2761 | /** |
@@ -2781,7 +2774,7 @@ discard block |
||
| 2781 | 2774 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2782 | 2775 | $boucle = &$boucles[$idb]; |
| 2783 | 2776 | $boucle->hash .= ' |
| 2784 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2777 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2785 | 2778 | } |
| 2786 | 2779 | |
| 2787 | 2780 | |
@@ -2800,7 +2793,7 @@ discard block |
||
| 2800 | 2793 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2801 | 2794 | foreach ($crit->param as $param) { |
| 2802 | 2795 | $boucle->hash .= ' |
| 2803 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2796 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2804 | 2797 | } |
| 2805 | 2798 | } |
| 2806 | 2799 | |
@@ -2819,14 +2812,14 @@ discard block |
||
| 2819 | 2812 | */ |
| 2820 | 2813 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2821 | 2814 | $boucle = &$boucles[$idb]; |
| 2822 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2815 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2823 | 2816 | foreach ($crit->param as $param) { |
| 2824 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2817 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2825 | 2818 | $param, |
| 2826 | 2819 | $idb, |
| 2827 | 2820 | $boucles, |
| 2828 | 2821 | $boucles[$idb]->id_parent |
| 2829 | - ) . ";\n"; |
|
| 2822 | + ).";\n"; |
|
| 2830 | 2823 | } |
| 2831 | 2824 | } |
| 2832 | 2825 | |
@@ -2853,14 +2846,14 @@ discard block |
||
| 2853 | 2846 | */ |
| 2854 | 2847 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2855 | 2848 | $boucle = &$boucles[$idb]; |
| 2856 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2849 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2857 | 2850 | foreach ($crit->param as $param) { |
| 2858 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2851 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2859 | 2852 | $param, |
| 2860 | 2853 | $idb, |
| 2861 | 2854 | $boucles, |
| 2862 | 2855 | $boucles[$idb]->id_parent |
| 2863 | - ) . ";\n"; |
|
| 2856 | + ).";\n"; |
|
| 2864 | 2857 | } |
| 2865 | 2858 | } |
| 2866 | 2859 | |
@@ -2879,7 +2872,7 @@ discard block |
||
| 2879 | 2872 | $boucle = &$boucles[$idb]; |
| 2880 | 2873 | foreach ($crit->param as $param) { |
| 2881 | 2874 | $boucle->hash .= ' |
| 2882 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2875 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2883 | 2876 | } |
| 2884 | 2877 | } |
| 2885 | 2878 | |
@@ -2920,7 +2913,7 @@ discard block |
||
| 2920 | 2913 | if ($crit->param) { |
| 2921 | 2914 | foreach ($crit->param as $param) { |
| 2922 | 2915 | $boucle->hash .= "\t\$command['si'][] = " |
| 2923 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2916 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2924 | 2917 | } |
| 2925 | 2918 | // interdire {si 0} aussi ! |
| 2926 | 2919 | } else { |
@@ -2944,7 +2937,7 @@ discard block |
||
| 2944 | 2937 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2945 | 2938 | $boucle = &$boucles[$idb]; |
| 2946 | 2939 | $boucle->hash .= ' |
| 2947 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2940 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2948 | 2941 | $command[\'sourcemode\'] = \'table\';'; |
| 2949 | 2942 | } |
| 2950 | 2943 | |
@@ -2977,11 +2970,10 @@ discard block |
||
| 2977 | 2970 | $table_sql = table_objet_sql(objet_type($table)); |
| 2978 | 2971 | |
| 2979 | 2972 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2980 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2981 | - 'id_parent'; |
|
| 2973 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2982 | 2974 | |
| 2983 | 2975 | $in = 'IN'; |
| 2984 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2976 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2985 | 2977 | if ($not) { |
| 2986 | 2978 | $where = ["'NOT'", $where]; |
| 2987 | 2979 | } |
@@ -2080,8 +2080,7 @@ discard block |
||
| 2080 | 2080 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2081 | 2081 | if (@array_key_exists('*', $desc['field'])) { |
| 2082 | 2082 | $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 |
| 2083 | - } |
|
| 2084 | - else { |
|
| 2083 | + } else { |
|
| 2085 | 2084 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2086 | 2085 | if (!$r) { |
| 2087 | 2086 | return ''; |
@@ -2124,8 +2123,7 @@ discard block |
||
| 2124 | 2123 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2125 | 2124 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 2126 | 2125 | $val[0] = "sql_quote($r)"; |
| 2127 | - } |
|
| 2128 | - elseif ( |
|
| 2126 | + } elseif ( |
|
| 2129 | 2127 | strpos($val[0], '@@defaultcast@@') !== false |
| 2130 | 2128 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2131 | 2129 | ) { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,193 +25,193 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = ['']; |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte(); |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = [$c]; |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | - $champ = new Champ(); |
|
| 57 | - $champ->nom_boucle = $m[2]; |
|
| 58 | - $champ->nom_champ = $m[3]; |
|
| 59 | - $champ->etoile = $m[5]; |
|
| 60 | - $champ = [$champ]; |
|
| 61 | - if ($m[6]) { |
|
| 62 | - $r = new Texte(); |
|
| 63 | - $r->texte = $m[6]; |
|
| 64 | - $champ[] = $r; |
|
| 65 | - } |
|
| 66 | - $args[] = $champ; |
|
| 67 | - array_shift($p->param); |
|
| 68 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | - } // le cas else est la seule incompatibilite |
|
| 70 | - } |
|
| 71 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = ['']; |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte(); |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = [$c]; |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + $champ = new Champ(); |
|
| 57 | + $champ->nom_boucle = $m[2]; |
|
| 58 | + $champ->nom_champ = $m[3]; |
|
| 59 | + $champ->etoile = $m[5]; |
|
| 60 | + $champ = [$champ]; |
|
| 61 | + if ($m[6]) { |
|
| 62 | + $r = new Texte(); |
|
| 63 | + $r->texte = $m[6]; |
|
| 64 | + $champ[] = $r; |
|
| 65 | + } |
|
| 66 | + $args[] = $champ; |
|
| 67 | + array_shift($p->param); |
|
| 68 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | + } // le cas else est la seule incompatibilite |
|
| 70 | + } |
|
| 71 | + array_unshift($p->param, $args); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | function phraser_logo_faux_filtres($nom) { |
| 76 | - switch ($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': |
|
| 82 | - return 0; |
|
| 83 | - case 'lien': |
|
| 84 | - return 1; |
|
| 85 | - case 'fichier': |
|
| 86 | - return 2; |
|
| 87 | - default: |
|
| 88 | - return $nom; |
|
| 89 | - } |
|
| 76 | + switch ($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': |
|
| 82 | + return 0; |
|
| 83 | + case 'lien': |
|
| 84 | + return 1; |
|
| 85 | + case 'fichier': |
|
| 86 | + return 2; |
|
| 87 | + default: |
|
| 88 | + return $nom; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | // La balise embed_document est a present le modele emb |
| 94 | 94 | |
| 95 | 95 | function phraser_vieux_emb(&$p) { |
| 96 | - if (!is_array($p->param)) { |
|
| 97 | - $p->param = []; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Produire le premier argument {emb} |
|
| 101 | - $texte = new Texte(); |
|
| 102 | - $texte->texte = 'emb'; |
|
| 103 | - $param = ['', [$texte]]; |
|
| 104 | - |
|
| 105 | - // Transformer les filtres en arguments |
|
| 106 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 107 | - if ($p->param[$i][0]) { |
|
| 108 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | - break; |
|
| 110 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | - $texte = new Texte(); |
|
| 112 | - $texte->texte = $p->param[$i][0]; |
|
| 113 | - $param[] = [$texte]; |
|
| 114 | - } |
|
| 115 | - array_shift($p->param); |
|
| 116 | - } |
|
| 117 | - array_unshift($p->param, $param); |
|
| 118 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | - $p->nom_champ = 'MODELE'; |
|
| 96 | + if (!is_array($p->param)) { |
|
| 97 | + $p->param = []; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Produire le premier argument {emb} |
|
| 101 | + $texte = new Texte(); |
|
| 102 | + $texte->texte = 'emb'; |
|
| 103 | + $param = ['', [$texte]]; |
|
| 104 | + |
|
| 105 | + // Transformer les filtres en arguments |
|
| 106 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 107 | + if ($p->param[$i][0]) { |
|
| 108 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | + break; |
|
| 110 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | + $texte = new Texte(); |
|
| 112 | + $texte->texte = $p->param[$i][0]; |
|
| 113 | + $param[] = [$texte]; |
|
| 114 | + } |
|
| 115 | + array_shift($p->param); |
|
| 116 | + } |
|
| 117 | + array_unshift($p->param, $param); |
|
| 118 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | + $p->nom_champ = 'MODELE'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Vieux formulaire de recherch |
| 123 | 123 | |
| 124 | 124 | function phraser_vieux_recherche($p) { |
| 125 | - if ($p->param[0][0]) { |
|
| 126 | - $c = new Texte(); |
|
| 127 | - $c->texte = $p->param[0][0]; |
|
| 128 | - $p->param[0][1] = [$c]; |
|
| 129 | - $p->param[0][0] = ''; |
|
| 130 | - $p->fonctions = []; |
|
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | - } |
|
| 125 | + if ($p->param[0][0]) { |
|
| 126 | + $c = new Texte(); |
|
| 127 | + $c->texte = $p->param[0][0]; |
|
| 128 | + $p->param[0][1] = [$c]; |
|
| 129 | + $p->param[0][0] = ''; |
|
| 130 | + $p->fonctions = []; |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Gerer la notation [(#EXPOSER|on,off)] |
| 136 | 136 | function phraser_vieux_exposer($p) { |
| 137 | - if ($a = $p->fonctions) { |
|
| 138 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | - $args = []; |
|
| 140 | - if ($regs[1]) { |
|
| 141 | - $a = new Texte(); |
|
| 142 | - $a->texte = $regs[1]; |
|
| 143 | - $args = ['', [$a]]; |
|
| 144 | - if ($regs[3]) { |
|
| 145 | - $a = new Texte(); |
|
| 146 | - $a->texte = $regs[3]; |
|
| 147 | - $args[] = [$a]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $p->param[0] = $args; |
|
| 151 | - $p->fonctions = []; |
|
| 152 | - $p->nom_champ = 'EXPOSE'; |
|
| 153 | - } |
|
| 137 | + if ($a = $p->fonctions) { |
|
| 138 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | + $args = []; |
|
| 140 | + if ($regs[1]) { |
|
| 141 | + $a = new Texte(); |
|
| 142 | + $a->texte = $regs[1]; |
|
| 143 | + $args = ['', [$a]]; |
|
| 144 | + if ($regs[3]) { |
|
| 145 | + $a = new Texte(); |
|
| 146 | + $a->texte = $regs[3]; |
|
| 147 | + $args[] = [$a]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $p->param[0] = $args; |
|
| 151 | + $p->fonctions = []; |
|
| 152 | + $p->nom_champ = 'EXPOSE'; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function phraser_vieux_modele($p) { |
| 157 | - normaliser_args_inclumodel($p); |
|
| 157 | + normaliser_args_inclumodel($p); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function phraser_vieux_inclu($p) { |
| 161 | - normaliser_args_inclumodel($p); |
|
| 161 | + normaliser_args_inclumodel($p); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function normaliser_args_inclumodel($p) { |
| 165 | - $params = $p->param; |
|
| 166 | - if (!$params) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - $args = $params[0]; |
|
| 170 | - if ($args[0]) { |
|
| 171 | - return; |
|
| 172 | - } // filtre immediat |
|
| 173 | - array_shift($p->param); |
|
| 174 | - foreach ($p->param as $l) { |
|
| 175 | - if (!array_shift($l)) { |
|
| 176 | - $args = array_merge($args, $l); |
|
| 177 | - array_shift($p->param); |
|
| 178 | - } else { |
|
| 179 | - break; |
|
| 180 | - } // filtre |
|
| 181 | - } |
|
| 182 | - array_unshift($p->param, $args); |
|
| 165 | + $params = $p->param; |
|
| 166 | + if (!$params) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + $args = $params[0]; |
|
| 170 | + if ($args[0]) { |
|
| 171 | + return; |
|
| 172 | + } // filtre immediat |
|
| 173 | + array_shift($p->param); |
|
| 174 | + foreach ($p->param as $l) { |
|
| 175 | + if (!array_shift($l)) { |
|
| 176 | + $args = array_merge($args, $l); |
|
| 177 | + array_shift($p->param); |
|
| 178 | + } else { |
|
| 179 | + break; |
|
| 180 | + } // filtre |
|
| 181 | + } |
|
| 182 | + array_unshift($p->param, $args); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function normaliser_inclure($champ) { |
| 186 | - normaliser_args_inclumodel($champ); |
|
| 187 | - $l = $champ->param[0]; |
|
| 188 | - if (is_array($l) and !$l[0]) { |
|
| 189 | - foreach ($l as $k => $p) { |
|
| 190 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | - $p[0]->texte = trim($p[0]->texte); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - foreach ($l as $k => $p) { |
|
| 195 | - if ( |
|
| 196 | - !$p or $p[0]->type != 'texte' or |
|
| 197 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | - ) { |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($r[1]) { |
|
| 203 | - $p[0]->texte = $r[1]; |
|
| 204 | - } else { |
|
| 205 | - unset($p[0]); |
|
| 206 | - } |
|
| 207 | - $champ->texte = $p; |
|
| 208 | - unset($champ->param[0][$k]); |
|
| 209 | - if (count($champ->param[0]) == 1) { |
|
| 210 | - array_shift($champ->param); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - spip_log('inclure sans fond ni fichier'); |
|
| 186 | + normaliser_args_inclumodel($champ); |
|
| 187 | + $l = $champ->param[0]; |
|
| 188 | + if (is_array($l) and !$l[0]) { |
|
| 189 | + foreach ($l as $k => $p) { |
|
| 190 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | + $p[0]->texte = trim($p[0]->texte); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + foreach ($l as $k => $p) { |
|
| 195 | + if ( |
|
| 196 | + !$p or $p[0]->type != 'texte' or |
|
| 197 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | + ) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($r[1]) { |
|
| 203 | + $p[0]->texte = $r[1]; |
|
| 204 | + } else { |
|
| 205 | + unset($p[0]); |
|
| 206 | + } |
|
| 207 | + $champ->texte = $p; |
|
| 208 | + unset($champ->param[0][$k]); |
|
| 209 | + if (count($champ->param[0]) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 217 | 217 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | array_shift($p->param); |
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 55 | + } elseif (preg_match('/^'.NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 56 | 56 | $champ = new Champ(); |
| 57 | 57 | $champ->nom_boucle = $m[2]; |
| 58 | 58 | $champ->nom_champ = $m[3]; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $p->param[0][1] = [$c]; |
| 129 | 129 | $p->param[0][0] = ''; |
| 130 | 130 | $p->fonctions = []; |
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |