@@ -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 . '('; |
@@ -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 | ) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,58 +256,58 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ( |
|
| 305 | - $boucle->primary |
|
| 306 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 307 | - and !in_array($t, $boucle->select) |
|
| 308 | - ) { |
|
| 309 | - $boucle->select[] = $t; |
|
| 310 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ( |
|
| 305 | + $boucle->primary |
|
| 306 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 307 | + and !in_array($t, $boucle->select) |
|
| 308 | + ) { |
|
| 309 | + $boucle->select[] = $t; |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -329,24 +329,24 @@ discard block |
||
| 329 | 329 | **/ |
| 330 | 330 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 331 | 331 | |
| 332 | - $boucle = &$boucles[$idb]; |
|
| 332 | + $boucle = &$boucles[$idb]; |
|
| 333 | 333 | |
| 334 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 335 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 334 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 335 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 336 | 336 | |
| 337 | - return; |
|
| 338 | - } |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - if (isset($crit->param[0])) { |
|
| 341 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 342 | - } else { |
|
| 343 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 344 | - } |
|
| 340 | + if (isset($crit->param[0])) { |
|
| 341 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 342 | + } else { |
|
| 343 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 347 | - $boucle->hash .= ' |
|
| 346 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 347 | + $boucle->hash .= ' |
|
| 348 | 348 | // RECHERCHE' |
| 349 | - . ($crit->cond ? ' |
|
| 349 | + . ($crit->cond ? ' |
|
| 350 | 350 | if (!strlen(' . $quoi . ')){ |
| 351 | 351 | list($rech_select, $rech_where) = array("0 as points",""); |
| 352 | 352 | } else' : '') . ' |
@@ -357,21 +357,21 @@ discard block |
||
| 357 | 357 | '; |
| 358 | 358 | |
| 359 | 359 | |
| 360 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 361 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 362 | - $boucle->select[] = $t; |
|
| 363 | - } # pour postgres, neuneu ici |
|
| 364 | - // jointure uniquement sur le serveur principal |
|
| 365 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 366 | - if (!$boucle->sql_serveur) { |
|
| 367 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 368 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 369 | - } |
|
| 370 | - $boucle->select[] = '$rech_select'; |
|
| 371 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 372 | - |
|
| 373 | - // et la recherche trouve |
|
| 374 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 360 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 361 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 362 | + $boucle->select[] = $t; |
|
| 363 | + } # pour postgres, neuneu ici |
|
| 364 | + // jointure uniquement sur le serveur principal |
|
| 365 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 366 | + if (!$boucle->sql_serveur) { |
|
| 367 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 368 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 369 | + } |
|
| 370 | + $boucle->select[] = '$rech_select'; |
|
| 371 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 372 | + |
|
| 373 | + // et la recherche trouve |
|
| 374 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * @return void |
| 389 | 389 | **/ |
| 390 | 390 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 391 | - $boucle = &$boucles[$idb]; |
|
| 392 | - $prim = $boucle->primary; |
|
| 393 | - $table = $boucle->id_table; |
|
| 394 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 395 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 396 | - $boucle->where[] = |
|
| 397 | - [ |
|
| 398 | - "'OR'", |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'='", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.$prim'", $dprim] |
|
| 403 | - ], |
|
| 404 | - [ |
|
| 405 | - "'AND'", |
|
| 406 | - ["'>'", "'$table.id_trad'", 0], |
|
| 407 | - ["'='", "'$table.id_trad'", $arg] |
|
| 408 | - ] |
|
| 409 | - ]; |
|
| 391 | + $boucle = &$boucles[$idb]; |
|
| 392 | + $prim = $boucle->primary; |
|
| 393 | + $table = $boucle->id_table; |
|
| 394 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 395 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 396 | + $boucle->where[] = |
|
| 397 | + [ |
|
| 398 | + "'OR'", |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'='", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.$prim'", $dprim] |
|
| 403 | + ], |
|
| 404 | + [ |
|
| 405 | + "'AND'", |
|
| 406 | + ["'>'", "'$table.id_trad'", 0], |
|
| 407 | + ["'='", "'$table.id_trad'", $arg] |
|
| 408 | + ] |
|
| 409 | + ]; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -424,17 +424,17 @@ discard block |
||
| 424 | 424 | * @return void |
| 425 | 425 | **/ |
| 426 | 426 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 427 | - $boucle = &$boucles[$idb]; |
|
| 428 | - $prim = $boucle->primary; |
|
| 429 | - $table = $boucle->id_table; |
|
| 430 | - |
|
| 431 | - $c = |
|
| 432 | - [ |
|
| 433 | - "'OR'", |
|
| 434 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 435 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 436 | - ]; |
|
| 437 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 427 | + $boucle = &$boucles[$idb]; |
|
| 428 | + $prim = $boucle->primary; |
|
| 429 | + $table = $boucle->id_table; |
|
| 430 | + |
|
| 431 | + $c = |
|
| 432 | + [ |
|
| 433 | + "'OR'", |
|
| 434 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 435 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 436 | + ]; |
|
| 437 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -451,19 +451,19 @@ discard block |
||
| 451 | 451 | **/ |
| 452 | 452 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 453 | 453 | |
| 454 | - $boucle = &$boucles[$idb]; |
|
| 455 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 456 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 457 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 458 | - 'id_parent'; |
|
| 459 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 460 | - |
|
| 461 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 462 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 466 | - } |
|
| 454 | + $boucle = &$boucles[$idb]; |
|
| 455 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 456 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 457 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 458 | + 'id_parent'; |
|
| 459 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 460 | + |
|
| 461 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 462 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = 'id_rubrique'; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = 'id_rubrique'; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @return void |
| 615 | 615 | **/ |
| 616 | 616 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 617 | - $boucles[$idb]->group = []; |
|
| 617 | + $boucles[$idb]->group = []; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -651,45 +651,45 @@ discard block |
||
| 651 | 651 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 652 | 652 | */ |
| 653 | 653 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 654 | - if (isset($crit->param[0])) { |
|
| 655 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 656 | - $boucle = $boucles[$idb]; |
|
| 657 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 658 | - $n = count($boucle->order); |
|
| 659 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 660 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 661 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 662 | - if ( |
|
| 663 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 664 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 665 | - ) { |
|
| 666 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 667 | - } else { |
|
| 668 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } else { |
|
| 672 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 673 | - } |
|
| 654 | + if (isset($crit->param[0])) { |
|
| 655 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 656 | + $boucle = $boucles[$idb]; |
|
| 657 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 658 | + $n = count($boucle->order); |
|
| 659 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 660 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 661 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 662 | + if ( |
|
| 663 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 664 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 665 | + ) { |
|
| 666 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 667 | + } else { |
|
| 668 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } else { |
|
| 672 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 677 | 677 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 678 | - $boucle = $boucles[$idb]; |
|
| 679 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 680 | - $var = '$champs_' . $idb; |
|
| 681 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 682 | - if (!$desc) { |
|
| 683 | - $desc = $boucle->show['field']; |
|
| 684 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 685 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 686 | - } |
|
| 687 | - if ($desc) { |
|
| 688 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 689 | - } |
|
| 690 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 691 | - |
|
| 692 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 678 | + $boucle = $boucles[$idb]; |
|
| 679 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 680 | + $var = '$champs_' . $idb; |
|
| 681 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 682 | + if (!$desc) { |
|
| 683 | + $desc = $boucle->show['field']; |
|
| 684 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 685 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 686 | + } |
|
| 687 | + if ($desc) { |
|
| 688 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 689 | + } |
|
| 690 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 691 | + |
|
| 692 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 729 | 729 | */ |
| 730 | 730 | function critere_par_dist($idb, &$boucles, $crit) { |
| 731 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 731 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -750,93 +750,93 @@ discard block |
||
| 750 | 750 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 751 | 751 | */ |
| 752 | 752 | function critere_parinverse($idb, &$boucles, $crit) { |
| 753 | - $boucle = &$boucles[$idb]; |
|
| 754 | - |
|
| 755 | - $sens = $collecte = ''; |
|
| 756 | - if ($crit->not) { |
|
| 757 | - $sens = " . ' DESC'"; |
|
| 758 | - } |
|
| 759 | - if (isset($boucle->modificateur['collate'])) { |
|
| 760 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - // Pour chaque paramètre du critère |
|
| 764 | - foreach ($crit->param as $tri) { |
|
| 765 | - $order = $fct = ''; |
|
| 766 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 767 | - if ($tri[0]->type != 'texte') { |
|
| 768 | - // calculer le order dynamique qui verifie les champs |
|
| 769 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 770 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 771 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 772 | - } |
|
| 773 | - // tris textuels {par titre} |
|
| 774 | - else { |
|
| 775 | - $par = array_shift($tri); |
|
| 776 | - $par = $par->texte; |
|
| 777 | - |
|
| 778 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 779 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 780 | - $expression = trim($m[1]); |
|
| 781 | - $champ = trim($m[2]); |
|
| 782 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 783 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 784 | - } else { |
|
| 785 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 789 | - } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 790 | - // {par FONCTION(champ)} |
|
| 791 | - if (count($match) > 2) { |
|
| 792 | - $par = substr($match[2], 1, -1); |
|
| 793 | - $fct = $match[1]; |
|
| 794 | - } |
|
| 795 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 796 | - if ($par == 'hasard') { |
|
| 797 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 798 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 799 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 800 | - } else { |
|
| 801 | - // cas général {par champ}, {par table.champ}, ... |
|
| 802 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - // on ne sait pas traiter… |
|
| 807 | - else { |
|
| 808 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 812 | - if (is_array($order)) { |
|
| 813 | - return $order; |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 818 | - $t = $m[1]; |
|
| 819 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 820 | - $boucle->select[] = $t; |
|
| 821 | - } |
|
| 822 | - } else { |
|
| 823 | - $sens = ''; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - if ($fct) { |
|
| 827 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 828 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 829 | - } else { |
|
| 830 | - $order = "'$fct(' . $order . ')'"; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - $t = $order . $collecte . $sens; |
|
| 834 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 835 | - $t = $r[1] . $r[2]; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - $boucle->order[] = $t; |
|
| 839 | - } |
|
| 753 | + $boucle = &$boucles[$idb]; |
|
| 754 | + |
|
| 755 | + $sens = $collecte = ''; |
|
| 756 | + if ($crit->not) { |
|
| 757 | + $sens = " . ' DESC'"; |
|
| 758 | + } |
|
| 759 | + if (isset($boucle->modificateur['collate'])) { |
|
| 760 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + // Pour chaque paramètre du critère |
|
| 764 | + foreach ($crit->param as $tri) { |
|
| 765 | + $order = $fct = ''; |
|
| 766 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 767 | + if ($tri[0]->type != 'texte') { |
|
| 768 | + // calculer le order dynamique qui verifie les champs |
|
| 769 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 770 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 771 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 772 | + } |
|
| 773 | + // tris textuels {par titre} |
|
| 774 | + else { |
|
| 775 | + $par = array_shift($tri); |
|
| 776 | + $par = $par->texte; |
|
| 777 | + |
|
| 778 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 779 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 780 | + $expression = trim($m[1]); |
|
| 781 | + $champ = trim($m[2]); |
|
| 782 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 783 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 784 | + } else { |
|
| 785 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 789 | + } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 790 | + // {par FONCTION(champ)} |
|
| 791 | + if (count($match) > 2) { |
|
| 792 | + $par = substr($match[2], 1, -1); |
|
| 793 | + $fct = $match[1]; |
|
| 794 | + } |
|
| 795 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 796 | + if ($par == 'hasard') { |
|
| 797 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 798 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 799 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 800 | + } else { |
|
| 801 | + // cas général {par champ}, {par table.champ}, ... |
|
| 802 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + // on ne sait pas traiter… |
|
| 807 | + else { |
|
| 808 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 812 | + if (is_array($order)) { |
|
| 813 | + return $order; |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 818 | + $t = $m[1]; |
|
| 819 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 820 | + $boucle->select[] = $t; |
|
| 821 | + } |
|
| 822 | + } else { |
|
| 823 | + $sens = ''; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + if ($fct) { |
|
| 827 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 828 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 829 | + } else { |
|
| 830 | + $order = "'$fct(' . $order . ')'"; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + $t = $order . $collecte . $sens; |
|
| 834 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 835 | + $t = $r[1] . $r[2]; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + $boucle->order[] = $t; |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -850,13 +850,13 @@ discard block |
||
| 850 | 850 | * @return string Clause pour le Order by |
| 851 | 851 | */ |
| 852 | 852 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 853 | - $boucle = &$boucles[$idb]; |
|
| 854 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 855 | - $parha = 'rand() AS hasard'; |
|
| 856 | - if (!in_array($parha, $boucle->select)) { |
|
| 857 | - $boucle->select[] = $parha; |
|
| 858 | - } |
|
| 859 | - return "'hasard'"; |
|
| 853 | + $boucle = &$boucles[$idb]; |
|
| 854 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 855 | + $parha = 'rand() AS hasard'; |
|
| 856 | + if (!in_array($parha, $boucle->select)) { |
|
| 857 | + $boucle->select[] = $parha; |
|
| 858 | + } |
|
| 859 | + return "'hasard'"; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | /** |
@@ -880,24 +880,24 @@ discard block |
||
| 880 | 880 | * @return string Clause pour le Order by |
| 881 | 881 | */ |
| 882 | 882 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 883 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 884 | - if (is_array($_champ)) { |
|
| 885 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 886 | - } |
|
| 887 | - $boucle = &$boucles[$idb]; |
|
| 888 | - $texte = '0+' . $_champ; |
|
| 889 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 890 | - if ($suite !== "''") { |
|
| 891 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 892 | - } |
|
| 893 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 894 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 895 | - |
|
| 896 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 897 | - $orderassinum = trim($orderassinum, "'"); |
|
| 898 | - |
|
| 899 | - $order = "'$orderassinum, $asnum'"; |
|
| 900 | - return $order; |
|
| 883 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 884 | + if (is_array($_champ)) { |
|
| 885 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 886 | + } |
|
| 887 | + $boucle = &$boucles[$idb]; |
|
| 888 | + $texte = '0+' . $_champ; |
|
| 889 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 890 | + if ($suite !== "''") { |
|
| 891 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 892 | + } |
|
| 893 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 894 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 895 | + |
|
| 896 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 897 | + $orderassinum = trim($orderassinum, "'"); |
|
| 898 | + |
|
| 899 | + $order = "'$orderassinum, $asnum'"; |
|
| 900 | + return $order; |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -918,35 +918,35 @@ discard block |
||
| 918 | 918 | * @return string Clause pour le Order by |
| 919 | 919 | */ |
| 920 | 920 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 921 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 922 | - if (is_array($_champ)) { |
|
| 923 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 924 | - } |
|
| 925 | - $boucle = &$boucles[$idb]; |
|
| 926 | - $texte = '0+' . $_champ; |
|
| 927 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 928 | - if ($suite !== "''") { |
|
| 929 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - $as = false; |
|
| 933 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 934 | - foreach ($boucle->select as $s) { |
|
| 935 | - if (strpos($s, $select) === 0) { |
|
| 936 | - $as = trim(substr($s, strlen($select))); |
|
| 937 | - if (!preg_match(',\W,', $as)) { |
|
| 938 | - break; |
|
| 939 | - } |
|
| 940 | - $as = false; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - if (!$as) { |
|
| 945 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 946 | - $boucle->select[] = $select . $as; |
|
| 947 | - } |
|
| 948 | - $order = "'$as'"; |
|
| 949 | - return $order; |
|
| 921 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 922 | + if (is_array($_champ)) { |
|
| 923 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 924 | + } |
|
| 925 | + $boucle = &$boucles[$idb]; |
|
| 926 | + $texte = '0+' . $_champ; |
|
| 927 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 928 | + if ($suite !== "''") { |
|
| 929 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + $as = false; |
|
| 933 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 934 | + foreach ($boucle->select as $s) { |
|
| 935 | + if (strpos($s, $select) === 0) { |
|
| 936 | + $as = trim(substr($s, strlen($select))); |
|
| 937 | + if (!preg_match(',\W,', $as)) { |
|
| 938 | + break; |
|
| 939 | + } |
|
| 940 | + $as = false; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + if (!$as) { |
|
| 945 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 946 | + $boucle->select[] = $select . $as; |
|
| 947 | + } |
|
| 948 | + $order = "'$as'"; |
|
| 949 | + return $order; |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | |
@@ -966,14 +966,14 @@ discard block |
||
| 966 | 966 | * @return string Clause pour le Order by |
| 967 | 967 | */ |
| 968 | 968 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 969 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 970 | - if (is_array($_champ)) { |
|
| 971 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 972 | - } |
|
| 973 | - $boucle = &$boucles[$idb]; |
|
| 974 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 975 | - $order = "'multi'"; |
|
| 976 | - return $order; |
|
| 969 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 970 | + if (is_array($_champ)) { |
|
| 971 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 972 | + } |
|
| 973 | + $boucle = &$boucles[$idb]; |
|
| 974 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 975 | + $order = "'multi'"; |
|
| 976 | + return $order; |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | /** |
@@ -992,56 +992,56 @@ discard block |
||
| 992 | 992 | * @return array|string |
| 993 | 993 | */ |
| 994 | 994 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 995 | - $boucle = &$boucles[$idb]; |
|
| 996 | - $desc = $boucle->show; |
|
| 997 | - |
|
| 998 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 999 | - if (isset($desc['field'][$par])) { |
|
| 1000 | - $par = $boucle->id_table . '.' . $par; |
|
| 1001 | - } |
|
| 1002 | - // le champ est peut être une jointure |
|
| 1003 | - else { |
|
| 1004 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1005 | - $champ = $par; |
|
| 1006 | - |
|
| 1007 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1008 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1009 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1010 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1011 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1012 | - list(, $table, $champ) = $r; |
|
| 1013 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1014 | - $table = table_objet_sql($table); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1018 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1019 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1020 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1021 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1022 | - } elseif ( |
|
| 1023 | - $boucle->jointures_explicites |
|
| 1024 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1025 | - ) { |
|
| 1026 | - $par = $alias . '.' . $champ; |
|
| 1027 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1028 | - $par = $alias . '.' . $champ; |
|
| 1029 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1030 | - } elseif ( |
|
| 1031 | - $table_alias |
|
| 1032 | - and isset($boucle->from[$table_alias]) |
|
| 1033 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1034 | - ) { |
|
| 1035 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1036 | - } elseif ($table) { |
|
| 1037 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1038 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1039 | - } else { |
|
| 1040 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - return $raw ? $par : "'$par'"; |
|
| 995 | + $boucle = &$boucles[$idb]; |
|
| 996 | + $desc = $boucle->show; |
|
| 997 | + |
|
| 998 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 999 | + if (isset($desc['field'][$par])) { |
|
| 1000 | + $par = $boucle->id_table . '.' . $par; |
|
| 1001 | + } |
|
| 1002 | + // le champ est peut être une jointure |
|
| 1003 | + else { |
|
| 1004 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1005 | + $champ = $par; |
|
| 1006 | + |
|
| 1007 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1008 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1009 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1010 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1011 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1012 | + list(, $table, $champ) = $r; |
|
| 1013 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1014 | + $table = table_objet_sql($table); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1018 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1019 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1020 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1021 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1022 | + } elseif ( |
|
| 1023 | + $boucle->jointures_explicites |
|
| 1024 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1025 | + ) { |
|
| 1026 | + $par = $alias . '.' . $champ; |
|
| 1027 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1028 | + $par = $alias . '.' . $champ; |
|
| 1029 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1030 | + } elseif ( |
|
| 1031 | + $table_alias |
|
| 1032 | + and isset($boucle->from[$table_alias]) |
|
| 1033 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1034 | + ) { |
|
| 1035 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1036 | + } elseif ($table) { |
|
| 1037 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1038 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1039 | + } else { |
|
| 1040 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + return $raw ? $par : "'$par'"; |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
@@ -1055,11 +1055,11 @@ discard block |
||
| 1055 | 1055 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1056 | 1056 | */ |
| 1057 | 1057 | function critere_par_joint($table, $champ, &$boucle) { |
| 1058 | - $t = array_search($table, $boucle->from); |
|
| 1059 | - if (!$t) { |
|
| 1060 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1061 | - } |
|
| 1062 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1058 | + $t = array_search($table, $boucle->from); |
|
| 1059 | + if (!$t) { |
|
| 1060 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1061 | + } |
|
| 1062 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /** |
@@ -1084,33 +1084,33 @@ discard block |
||
| 1084 | 1084 | */ |
| 1085 | 1085 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1086 | 1086 | |
| 1087 | - $boucle = &$boucles[$idb]; |
|
| 1088 | - // Classement par ordre inverse |
|
| 1089 | - if ($crit->not) { |
|
| 1090 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1091 | - } else { |
|
| 1092 | - $order = "' DESC'"; |
|
| 1093 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1094 | - if (isset($crit->param[0])) { |
|
| 1095 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1096 | - $order = "(($critere)?' DESC':'')"; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - $n = count($boucle->order); |
|
| 1100 | - if (!$n) { |
|
| 1101 | - if (isset($boucle->default_order[0])) { |
|
| 1102 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1103 | - } else { |
|
| 1104 | - $boucle->default_order[] = ' DESC'; |
|
| 1105 | - } |
|
| 1106 | - } else { |
|
| 1107 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1108 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1109 | - $t = $r[1] . $r[2]; |
|
| 1110 | - } |
|
| 1111 | - $boucle->order[$n - 1] = $t; |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1087 | + $boucle = &$boucles[$idb]; |
|
| 1088 | + // Classement par ordre inverse |
|
| 1089 | + if ($crit->not) { |
|
| 1090 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1091 | + } else { |
|
| 1092 | + $order = "' DESC'"; |
|
| 1093 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1094 | + if (isset($crit->param[0])) { |
|
| 1095 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1096 | + $order = "(($critere)?' DESC':'')"; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + $n = count($boucle->order); |
|
| 1100 | + if (!$n) { |
|
| 1101 | + if (isset($boucle->default_order[0])) { |
|
| 1102 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1103 | + } else { |
|
| 1104 | + $boucle->default_order[] = ' DESC'; |
|
| 1105 | + } |
|
| 1106 | + } else { |
|
| 1107 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1108 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1109 | + $t = $r[1] . $r[2]; |
|
| 1110 | + } |
|
| 1111 | + $boucle->order[$n - 1] = $t; |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | /** |
@@ -1121,138 +1121,138 @@ discard block |
||
| 1121 | 1121 | * @return array|string |
| 1122 | 1122 | */ |
| 1123 | 1123 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1124 | - $boucle = &$boucles[$idb]; |
|
| 1124 | + $boucle = &$boucles[$idb]; |
|
| 1125 | 1125 | |
| 1126 | - $sens = $collecte = ''; |
|
| 1127 | - if ($crit->not) { |
|
| 1128 | - $sens = " . ' DESC'"; |
|
| 1129 | - } |
|
| 1126 | + $sens = $collecte = ''; |
|
| 1127 | + if ($crit->not) { |
|
| 1128 | + $sens = " . ' DESC'"; |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - $crit2 = clone $crit; |
|
| 1132 | - $crit2->not = false; |
|
| 1133 | - $crit2->param = [reset($crit->param)]; |
|
| 1134 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1131 | + $crit2 = clone $crit; |
|
| 1132 | + $crit2->not = false; |
|
| 1133 | + $crit2->param = [reset($crit->param)]; |
|
| 1134 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1135 | 1135 | |
| 1136 | - // erreur ? |
|
| 1137 | - if (is_array($res)) { |
|
| 1138 | - return $res; |
|
| 1139 | - } |
|
| 1136 | + // erreur ? |
|
| 1137 | + if (is_array($res)) { |
|
| 1138 | + return $res; |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | - $_order = array_pop($boucle->order); |
|
| 1141 | + $_order = array_pop($boucle->order); |
|
| 1142 | 1142 | |
| 1143 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1144 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1144 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | |
| 1148 | 1148 | // https://code.spip.net/@critere_agenda_dist |
| 1149 | 1149 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1150 | - $params = $crit->param; |
|
| 1151 | - |
|
| 1152 | - if (count($params) < 1) { |
|
| 1153 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - $boucle = &$boucles[$idb]; |
|
| 1157 | - $parent = $boucle->id_parent; |
|
| 1158 | - $fields = $boucle->show['field']; |
|
| 1159 | - |
|
| 1160 | - $date = array_shift($params); |
|
| 1161 | - $type = array_shift($params); |
|
| 1162 | - |
|
| 1163 | - // la valeur $type doit etre connue a la compilation |
|
| 1164 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1165 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1166 | - |
|
| 1167 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1168 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1169 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1170 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1171 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1172 | - $date = $date[0]->texte; |
|
| 1173 | - if (!isset($fields[$date])) { |
|
| 1174 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1175 | - } |
|
| 1176 | - } else { |
|
| 1177 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1178 | - $noms = array_keys($fields); |
|
| 1179 | - $defaut = $noms[0]; |
|
| 1180 | - $noms = join(' ', $noms); |
|
| 1181 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1182 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1183 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1184 | - } |
|
| 1185 | - $annee = $params ? array_shift($params) : ''; |
|
| 1186 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1187 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1188 | - ') ? $x : date("Y"))'; |
|
| 1189 | - |
|
| 1190 | - $mois = $params ? array_shift($params) : ''; |
|
| 1191 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1192 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1193 | - ') ? $x : date("m"))'; |
|
| 1194 | - |
|
| 1195 | - $jour = $params ? array_shift($params) : ''; |
|
| 1196 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1197 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1198 | - ') ? $x : date("d"))'; |
|
| 1199 | - |
|
| 1200 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1201 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1202 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1203 | - ') ? $x : date("Y"))'; |
|
| 1204 | - |
|
| 1205 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1206 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1207 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1208 | - ') ? $x : date("m"))'; |
|
| 1209 | - |
|
| 1210 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1211 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1212 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1213 | - ') ? $x : date("d"))'; |
|
| 1214 | - |
|
| 1215 | - $date = $boucle->id_table . ".$date"; |
|
| 1216 | - |
|
| 1217 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1218 | - if ($type == 'jour') { |
|
| 1219 | - $boucle->where[] = [ |
|
| 1220 | - "'='", |
|
| 1221 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1222 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1223 | - ]; |
|
| 1224 | - } elseif ($type == 'mois') { |
|
| 1225 | - $boucle->where[] = [ |
|
| 1226 | - "'='", |
|
| 1227 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1228 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1229 | - ]; |
|
| 1230 | - } elseif ($type == 'semaine') { |
|
| 1231 | - $boucle->where[] = [ |
|
| 1232 | - "'AND'", |
|
| 1233 | - [ |
|
| 1234 | - "'>='", |
|
| 1235 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1236 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1237 | - ], |
|
| 1238 | - [ |
|
| 1239 | - "'<='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1242 | - ] |
|
| 1243 | - ]; |
|
| 1244 | - } elseif (count($crit->param) > 2) { |
|
| 1245 | - $boucle->where[] = [ |
|
| 1246 | - "'AND'", |
|
| 1247 | - [ |
|
| 1248 | - "'>='", |
|
| 1249 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1250 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1251 | - ], |
|
| 1252 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1253 | - ]; |
|
| 1254 | - } |
|
| 1255 | - // sinon on prend tout |
|
| 1150 | + $params = $crit->param; |
|
| 1151 | + |
|
| 1152 | + if (count($params) < 1) { |
|
| 1153 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + $boucle = &$boucles[$idb]; |
|
| 1157 | + $parent = $boucle->id_parent; |
|
| 1158 | + $fields = $boucle->show['field']; |
|
| 1159 | + |
|
| 1160 | + $date = array_shift($params); |
|
| 1161 | + $type = array_shift($params); |
|
| 1162 | + |
|
| 1163 | + // la valeur $type doit etre connue a la compilation |
|
| 1164 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1165 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1166 | + |
|
| 1167 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1168 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1169 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1170 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1171 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1172 | + $date = $date[0]->texte; |
|
| 1173 | + if (!isset($fields[$date])) { |
|
| 1174 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1175 | + } |
|
| 1176 | + } else { |
|
| 1177 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1178 | + $noms = array_keys($fields); |
|
| 1179 | + $defaut = $noms[0]; |
|
| 1180 | + $noms = join(' ', $noms); |
|
| 1181 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1182 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1183 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1184 | + } |
|
| 1185 | + $annee = $params ? array_shift($params) : ''; |
|
| 1186 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1187 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1188 | + ') ? $x : date("Y"))'; |
|
| 1189 | + |
|
| 1190 | + $mois = $params ? array_shift($params) : ''; |
|
| 1191 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1192 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1193 | + ') ? $x : date("m"))'; |
|
| 1194 | + |
|
| 1195 | + $jour = $params ? array_shift($params) : ''; |
|
| 1196 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1197 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1198 | + ') ? $x : date("d"))'; |
|
| 1199 | + |
|
| 1200 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1201 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1202 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1203 | + ') ? $x : date("Y"))'; |
|
| 1204 | + |
|
| 1205 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1206 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1207 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1208 | + ') ? $x : date("m"))'; |
|
| 1209 | + |
|
| 1210 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1211 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1212 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1213 | + ') ? $x : date("d"))'; |
|
| 1214 | + |
|
| 1215 | + $date = $boucle->id_table . ".$date"; |
|
| 1216 | + |
|
| 1217 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1218 | + if ($type == 'jour') { |
|
| 1219 | + $boucle->where[] = [ |
|
| 1220 | + "'='", |
|
| 1221 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1222 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1223 | + ]; |
|
| 1224 | + } elseif ($type == 'mois') { |
|
| 1225 | + $boucle->where[] = [ |
|
| 1226 | + "'='", |
|
| 1227 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1228 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1229 | + ]; |
|
| 1230 | + } elseif ($type == 'semaine') { |
|
| 1231 | + $boucle->where[] = [ |
|
| 1232 | + "'AND'", |
|
| 1233 | + [ |
|
| 1234 | + "'>='", |
|
| 1235 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1236 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1237 | + ], |
|
| 1238 | + [ |
|
| 1239 | + "'<='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1242 | + ] |
|
| 1243 | + ]; |
|
| 1244 | + } elseif (count($crit->param) > 2) { |
|
| 1245 | + $boucle->where[] = [ |
|
| 1246 | + "'AND'", |
|
| 1247 | + [ |
|
| 1248 | + "'>='", |
|
| 1249 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1250 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1251 | + ], |
|
| 1252 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1253 | + ]; |
|
| 1254 | + } |
|
| 1255 | + // sinon on prend tout |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
@@ -1277,33 +1277,33 @@ discard block |
||
| 1277 | 1277 | * @return void |
| 1278 | 1278 | **/ |
| 1279 | 1279 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1280 | - $boucle = &$boucles[$idb]; |
|
| 1281 | - $a1 = $crit->param[0]; |
|
| 1282 | - $a2 = $crit->param[1]; |
|
| 1283 | - $op = $crit->op; |
|
| 1284 | - |
|
| 1285 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1286 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1287 | - |
|
| 1288 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1289 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1290 | - } else { |
|
| 1291 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1292 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1293 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1294 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1295 | - $mode = (($op == '/') ? '/' : |
|
| 1296 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1297 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1298 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1299 | - $boucle->limit = |
|
| 1300 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1301 | - . ".','." |
|
| 1302 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1303 | - } else { |
|
| 1304 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1280 | + $boucle = &$boucles[$idb]; |
|
| 1281 | + $a1 = $crit->param[0]; |
|
| 1282 | + $a2 = $crit->param[1]; |
|
| 1283 | + $op = $crit->op; |
|
| 1284 | + |
|
| 1285 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1286 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1287 | + |
|
| 1288 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1289 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1290 | + } else { |
|
| 1291 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1292 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1293 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1294 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1295 | + $mode = (($op == '/') ? '/' : |
|
| 1296 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1297 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1298 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1299 | + $boucle->limit = |
|
| 1300 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1301 | + . ".','." |
|
| 1302 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1303 | + } else { |
|
| 1304 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | /** |
@@ -1331,63 +1331,63 @@ discard block |
||
| 1331 | 1331 | * @return void |
| 1332 | 1332 | **/ |
| 1333 | 1333 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1334 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1335 | - |
|
| 1336 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1337 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1338 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1339 | - // {1/3} |
|
| 1340 | - if ($op1 == '/') { |
|
| 1341 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1342 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1343 | - "($total_parties ? $total_parties : 1)"; |
|
| 1344 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1345 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1346 | - } else { |
|
| 1347 | - // cas {n-1,x} |
|
| 1348 | - if ($op1 == '-') { |
|
| 1349 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - // cas {x,n-1} |
|
| 1353 | - if ($op2 == '-') { |
|
| 1354 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1355 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1356 | - ($total_parties . ' - 1')); |
|
| 1357 | - } else { |
|
| 1358 | - // {x,1} ou {pagination} |
|
| 1359 | - $fin = '$debut_boucle' |
|
| 1360 | - . (is_numeric($total_parties) ? |
|
| 1361 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1362 | - ('+' . $total_parties . ' - 1')); |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1366 | - if ($op1 == 'p') { |
|
| 1367 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1368 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1369 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - // Notes : |
|
| 1374 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1375 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1376 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1377 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1378 | - |
|
| 1379 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1380 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1381 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1382 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1383 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1384 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1385 | - . "\n\tif (\$debut_boucle>0" |
|
| 1386 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1387 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1388 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1389 | - |
|
| 1390 | - $boucles[$id_boucle]->partie = " |
|
| 1334 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1335 | + |
|
| 1336 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1337 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1338 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1339 | + // {1/3} |
|
| 1340 | + if ($op1 == '/') { |
|
| 1341 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1342 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1343 | + "($total_parties ? $total_parties : 1)"; |
|
| 1344 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1345 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1346 | + } else { |
|
| 1347 | + // cas {n-1,x} |
|
| 1348 | + if ($op1 == '-') { |
|
| 1349 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + // cas {x,n-1} |
|
| 1353 | + if ($op2 == '-') { |
|
| 1354 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1355 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1356 | + ($total_parties . ' - 1')); |
|
| 1357 | + } else { |
|
| 1358 | + // {x,1} ou {pagination} |
|
| 1359 | + $fin = '$debut_boucle' |
|
| 1360 | + . (is_numeric($total_parties) ? |
|
| 1361 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1362 | + ('+' . $total_parties . ' - 1')); |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1366 | + if ($op1 == 'p') { |
|
| 1367 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1368 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1369 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + // Notes : |
|
| 1374 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1375 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1376 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1377 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1378 | + |
|
| 1379 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1380 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1381 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1382 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1383 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1384 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1385 | + . "\n\tif (\$debut_boucle>0" |
|
| 1386 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1387 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1388 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1389 | + |
|
| 1390 | + $boucles[$id_boucle]->partie = " |
|
| 1391 | 1391 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1392 | 1392 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1393 | 1393 | } |
@@ -1404,26 +1404,26 @@ discard block |
||
| 1404 | 1404 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1405 | 1405 | **/ |
| 1406 | 1406 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1407 | - if ($param[0]->type != 'texte') { |
|
| 1408 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1409 | - if (isset($param[1]->texte)) { |
|
| 1410 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1411 | - |
|
| 1412 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1413 | - } else { |
|
| 1414 | - return ["intval($a1)", 0]; |
|
| 1415 | - } |
|
| 1416 | - } else { |
|
| 1417 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1418 | - $a1 = $m[1]; |
|
| 1419 | - if (empty($m[3])) { |
|
| 1420 | - return [$a1, 0]; |
|
| 1421 | - } elseif (!empty($m[4])) { |
|
| 1422 | - return [$a1, $m[4]]; |
|
| 1423 | - } else { |
|
| 1424 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1407 | + if ($param[0]->type != 'texte') { |
|
| 1408 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1409 | + if (isset($param[1]->texte)) { |
|
| 1410 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1411 | + |
|
| 1412 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1413 | + } else { |
|
| 1414 | + return ["intval($a1)", 0]; |
|
| 1415 | + } |
|
| 1416 | + } else { |
|
| 1417 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1418 | + $a1 = $m[1]; |
|
| 1419 | + if (empty($m[3])) { |
|
| 1420 | + return [$a1, 0]; |
|
| 1421 | + } elseif (!empty($m[4])) { |
|
| 1422 | + return [$a1, $m[4]]; |
|
| 1423 | + } else { |
|
| 1424 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1425 | + } |
|
| 1426 | + } |
|
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | 1429 | |
@@ -1450,47 +1450,47 @@ discard block |
||
| 1450 | 1450 | * array : Erreur sur un des critères |
| 1451 | 1451 | **/ |
| 1452 | 1452 | function calculer_criteres($idb, &$boucles) { |
| 1453 | - $msg = ''; |
|
| 1454 | - $boucle = $boucles[$idb]; |
|
| 1455 | - $table = strtoupper($boucle->type_requete); |
|
| 1456 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1457 | - |
|
| 1458 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1459 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1460 | - if (!is_array($boucle->criteres)) { |
|
| 1461 | - return []; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - foreach ($boucle->criteres as $crit) { |
|
| 1465 | - $critere = $crit->op; |
|
| 1466 | - // critere personnalise ? |
|
| 1467 | - if ( |
|
| 1468 | - (!$serveur or |
|
| 1469 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1473 | - ) |
|
| 1474 | - ) |
|
| 1475 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1476 | - and (!function_exists($f = $f . '_dist')) |
|
| 1477 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1478 | - and (!function_exists($f = $f . '_dist')) |
|
| 1479 | - ) { |
|
| 1480 | - // fonction critere standard |
|
| 1481 | - $f = $defaut; |
|
| 1482 | - } |
|
| 1483 | - // compile le critere |
|
| 1484 | - $res = $f($idb, $boucles, $crit); |
|
| 1485 | - |
|
| 1486 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1487 | - if (is_array($res)) { |
|
| 1488 | - $msg = $res; |
|
| 1489 | - erreur_squelette($msg, $boucle); |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - return $msg; |
|
| 1453 | + $msg = ''; |
|
| 1454 | + $boucle = $boucles[$idb]; |
|
| 1455 | + $table = strtoupper($boucle->type_requete); |
|
| 1456 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1457 | + |
|
| 1458 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1459 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1460 | + if (!is_array($boucle->criteres)) { |
|
| 1461 | + return []; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + foreach ($boucle->criteres as $crit) { |
|
| 1465 | + $critere = $crit->op; |
|
| 1466 | + // critere personnalise ? |
|
| 1467 | + if ( |
|
| 1468 | + (!$serveur or |
|
| 1469 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1470 | + and (!function_exists($f = $f . '_dist')) |
|
| 1471 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1472 | + and (!function_exists($f = $f . '_dist')) |
|
| 1473 | + ) |
|
| 1474 | + ) |
|
| 1475 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1476 | + and (!function_exists($f = $f . '_dist')) |
|
| 1477 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1478 | + and (!function_exists($f = $f . '_dist')) |
|
| 1479 | + ) { |
|
| 1480 | + // fonction critere standard |
|
| 1481 | + $f = $defaut; |
|
| 1482 | + } |
|
| 1483 | + // compile le critere |
|
| 1484 | + $res = $f($idb, $boucles, $crit); |
|
| 1485 | + |
|
| 1486 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1487 | + if (is_array($res)) { |
|
| 1488 | + $msg = $res; |
|
| 1489 | + erreur_squelette($msg, $boucle); |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + return $msg; |
|
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | 1496 | /** |
@@ -1507,11 +1507,11 @@ discard block |
||
| 1507 | 1507 | * @return string Code compilé rééchappé |
| 1508 | 1508 | */ |
| 1509 | 1509 | function kwote($lisp, $serveur = '', $type = '') { |
| 1510 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1511 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1512 | - } else { |
|
| 1513 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1514 | - } |
|
| 1510 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1511 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1512 | + } else { |
|
| 1513 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1514 | + } |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | |
@@ -1530,82 +1530,82 @@ discard block |
||
| 1530 | 1530 | * @return void |
| 1531 | 1531 | **/ |
| 1532 | 1532 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1533 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1534 | - if (!$r) { |
|
| 1535 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1536 | - } |
|
| 1537 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1538 | - |
|
| 1539 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1540 | - |
|
| 1541 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1542 | - $where = $in; |
|
| 1543 | - if ($crit->cond) { |
|
| 1544 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1545 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1546 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1547 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - if ($crit->exclus) { |
|
| 1551 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1552 | - $where = ["'NOT'", $where]; |
|
| 1553 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1554 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1555 | - { |
|
| 1556 | - $where = [ |
|
| 1557 | - "'NOT'", |
|
| 1558 | - [ |
|
| 1559 | - "'IN'", |
|
| 1560 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1561 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1562 | - ] |
|
| 1563 | - ]; |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - $boucles[$idb]->where[] = $where; |
|
| 1568 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1570 | - } |
|
| 1533 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1534 | + if (!$r) { |
|
| 1535 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1536 | + } |
|
| 1537 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1538 | + |
|
| 1539 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1540 | + |
|
| 1541 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1542 | + $where = $in; |
|
| 1543 | + if ($crit->cond) { |
|
| 1544 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1545 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1546 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1547 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + if ($crit->exclus) { |
|
| 1551 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1552 | + $where = ["'NOT'", $where]; |
|
| 1553 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1554 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1555 | + { |
|
| 1556 | + $where = [ |
|
| 1557 | + "'NOT'", |
|
| 1558 | + [ |
|
| 1559 | + "'IN'", |
|
| 1560 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1561 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1562 | + ] |
|
| 1563 | + ]; |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + $boucles[$idb]->where[] = $where; |
|
| 1568 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1570 | + } |
|
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | 1573 | // https://code.spip.net/@critere_IN_cas |
| 1574 | 1574 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1575 | - static $num = []; |
|
| 1576 | - $descr = $boucles[$idb]->descr; |
|
| 1577 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1578 | - |
|
| 1579 | - $var = '$in' . $cpt++; |
|
| 1580 | - $x = "\n\t$var = array();"; |
|
| 1581 | - foreach ($val as $k => $v) { |
|
| 1582 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1583 | - // optimiser le traitement des constantes |
|
| 1584 | - if (is_numeric($r[2])) { |
|
| 1585 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1586 | - } else { |
|
| 1587 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1588 | - } |
|
| 1589 | - } else { |
|
| 1590 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1591 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1592 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1593 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1594 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1595 | - } |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - $boucles[$idb]->in .= $x; |
|
| 1599 | - |
|
| 1600 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1601 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1602 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1603 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1604 | - if (!$crit2) { |
|
| 1605 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1575 | + static $num = []; |
|
| 1576 | + $descr = $boucles[$idb]->descr; |
|
| 1577 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1578 | + |
|
| 1579 | + $var = '$in' . $cpt++; |
|
| 1580 | + $x = "\n\t$var = array();"; |
|
| 1581 | + foreach ($val as $k => $v) { |
|
| 1582 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1583 | + // optimiser le traitement des constantes |
|
| 1584 | + if (is_numeric($r[2])) { |
|
| 1585 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1586 | + } else { |
|
| 1587 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1588 | + } |
|
| 1589 | + } else { |
|
| 1590 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1591 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1592 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1593 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1594 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1595 | + } |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + $boucles[$idb]->in .= $x; |
|
| 1599 | + |
|
| 1600 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1601 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1602 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1603 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1604 | + if (!$crit2) { |
|
| 1605 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | /** |
@@ -1621,22 +1621,22 @@ discard block |
||
| 1621 | 1621 | * @return void |
| 1622 | 1622 | */ |
| 1623 | 1623 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1624 | - $boucle = &$boucles[$idb]; |
|
| 1625 | - if (isset($crit->param[0])) { |
|
| 1626 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1627 | - } else { |
|
| 1628 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - if ($crit->cond) { |
|
| 1632 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - if ($crit->not) { |
|
| 1636 | - $_where = "array('NOT',$_where)"; |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - $boucle->where[] = $_where; |
|
| 1624 | + $boucle = &$boucles[$idb]; |
|
| 1625 | + if (isset($crit->param[0])) { |
|
| 1626 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1627 | + } else { |
|
| 1628 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + if ($crit->cond) { |
|
| 1632 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + if ($crit->not) { |
|
| 1636 | + $_where = "array('NOT',$_where)"; |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + $boucle->where[] = $_where; |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | /** |
@@ -1664,31 +1664,31 @@ discard block |
||
| 1664 | 1664 | * @return void |
| 1665 | 1665 | */ |
| 1666 | 1666 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1667 | - /** @var Boucle $boucle */ |
|
| 1668 | - $boucle = $boucles[$idb]; |
|
| 1669 | - |
|
| 1670 | - $champs = lister_champs_id_conditionnel( |
|
| 1671 | - $boucle->show['table'], |
|
| 1672 | - $boucle->show, |
|
| 1673 | - $boucle->sql_serveur |
|
| 1674 | - ); |
|
| 1675 | - |
|
| 1676 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1677 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1678 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1679 | - } |
|
| 1680 | - // nous aider en mode debug. |
|
| 1681 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1682 | - $boucle->modificateur['id_'] = $champs; |
|
| 1683 | - |
|
| 1684 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1685 | - foreach ($champs as $champ) { |
|
| 1686 | - $critere_id_table = new Critere(); |
|
| 1687 | - $critere_id_table->op = $champ; |
|
| 1688 | - $critere_id_table->cond = '?'; |
|
| 1689 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1690 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1691 | - } |
|
| 1667 | + /** @var Boucle $boucle */ |
|
| 1668 | + $boucle = $boucles[$idb]; |
|
| 1669 | + |
|
| 1670 | + $champs = lister_champs_id_conditionnel( |
|
| 1671 | + $boucle->show['table'], |
|
| 1672 | + $boucle->show, |
|
| 1673 | + $boucle->sql_serveur |
|
| 1674 | + ); |
|
| 1675 | + |
|
| 1676 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1677 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1678 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1679 | + } |
|
| 1680 | + // nous aider en mode debug. |
|
| 1681 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1682 | + $boucle->modificateur['id_'] = $champs; |
|
| 1683 | + |
|
| 1684 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1685 | + foreach ($champs as $champ) { |
|
| 1686 | + $critere_id_table = new Critere(); |
|
| 1687 | + $critere_id_table->op = $champ; |
|
| 1688 | + $critere_id_table->cond = '?'; |
|
| 1689 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1690 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1691 | + } |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1708,79 +1708,79 @@ discard block |
||
| 1708 | 1708 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1709 | 1709 | */ |
| 1710 | 1710 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1711 | - // calculer la description de la table |
|
| 1712 | - if (!is_array($desc)) { |
|
| 1713 | - $desc = description_table($table, $serveur); |
|
| 1714 | - } |
|
| 1715 | - if (!$desc) { |
|
| 1716 | - return []; |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - // Les champs id_xx de la table demandée |
|
| 1720 | - $champs = array_filter( |
|
| 1721 | - array_keys($desc['field']), |
|
| 1722 | - function ($champ) { |
|
| 1723 | - return |
|
| 1724 | - strpos($champ, 'id_') === 0 |
|
| 1725 | - or (in_array($champ, ['objet'])); |
|
| 1726 | - } |
|
| 1727 | - ); |
|
| 1728 | - |
|
| 1729 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1730 | - if ( |
|
| 1731 | - in_array('id_rubrique', $champs) |
|
| 1732 | - and !in_array('id_secteur', $champs) |
|
| 1733 | - ) { |
|
| 1734 | - $champs[] = 'id_secteur'; |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1738 | - if ($serveur) { |
|
| 1739 | - return $champs; |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - $primary = false; |
|
| 1743 | - $associable = false; |
|
| 1744 | - include_spip('action/editer_liens'); |
|
| 1745 | - |
|
| 1746 | - if (isset($desc['type'])) { |
|
| 1747 | - $primary = id_table_objet($desc['type']); |
|
| 1748 | - $associable = objet_associable($desc['type']); |
|
| 1749 | - } |
|
| 1750 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1751 | - $associable = true; |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - // liste de toutes les tables principales, sauf la notre |
|
| 1755 | - $tables = lister_tables_objets_sql(); |
|
| 1756 | - unset($tables[$table]); |
|
| 1757 | - |
|
| 1758 | - foreach ($tables as $_table => $_desc) { |
|
| 1759 | - if ( |
|
| 1760 | - $associable |
|
| 1761 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1762 | - or objet_associable($_desc['type']) |
|
| 1763 | - ) { |
|
| 1764 | - $champs[] = id_table_objet($_table); |
|
| 1765 | - } |
|
| 1766 | - } |
|
| 1767 | - $champs = array_values(array_unique($champs)); |
|
| 1768 | - |
|
| 1769 | - // Exclusions de certains id |
|
| 1770 | - $exclusions = pipeline( |
|
| 1771 | - 'exclure_id_conditionnel', |
|
| 1772 | - [ |
|
| 1773 | - 'args' => [ |
|
| 1774 | - 'table' => $table, |
|
| 1775 | - 'id_table_objet' => $primary, |
|
| 1776 | - 'associable' => $associable, |
|
| 1777 | - ], |
|
| 1778 | - 'data' => [], |
|
| 1779 | - ] |
|
| 1780 | - ); |
|
| 1781 | - $champs = array_diff($champs, $exclusions); |
|
| 1782 | - |
|
| 1783 | - return $champs; |
|
| 1711 | + // calculer la description de la table |
|
| 1712 | + if (!is_array($desc)) { |
|
| 1713 | + $desc = description_table($table, $serveur); |
|
| 1714 | + } |
|
| 1715 | + if (!$desc) { |
|
| 1716 | + return []; |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + // Les champs id_xx de la table demandée |
|
| 1720 | + $champs = array_filter( |
|
| 1721 | + array_keys($desc['field']), |
|
| 1722 | + function ($champ) { |
|
| 1723 | + return |
|
| 1724 | + strpos($champ, 'id_') === 0 |
|
| 1725 | + or (in_array($champ, ['objet'])); |
|
| 1726 | + } |
|
| 1727 | + ); |
|
| 1728 | + |
|
| 1729 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1730 | + if ( |
|
| 1731 | + in_array('id_rubrique', $champs) |
|
| 1732 | + and !in_array('id_secteur', $champs) |
|
| 1733 | + ) { |
|
| 1734 | + $champs[] = 'id_secteur'; |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1738 | + if ($serveur) { |
|
| 1739 | + return $champs; |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + $primary = false; |
|
| 1743 | + $associable = false; |
|
| 1744 | + include_spip('action/editer_liens'); |
|
| 1745 | + |
|
| 1746 | + if (isset($desc['type'])) { |
|
| 1747 | + $primary = id_table_objet($desc['type']); |
|
| 1748 | + $associable = objet_associable($desc['type']); |
|
| 1749 | + } |
|
| 1750 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1751 | + $associable = true; |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + // liste de toutes les tables principales, sauf la notre |
|
| 1755 | + $tables = lister_tables_objets_sql(); |
|
| 1756 | + unset($tables[$table]); |
|
| 1757 | + |
|
| 1758 | + foreach ($tables as $_table => $_desc) { |
|
| 1759 | + if ( |
|
| 1760 | + $associable |
|
| 1761 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1762 | + or objet_associable($_desc['type']) |
|
| 1763 | + ) { |
|
| 1764 | + $champs[] = id_table_objet($_table); |
|
| 1765 | + } |
|
| 1766 | + } |
|
| 1767 | + $champs = array_values(array_unique($champs)); |
|
| 1768 | + |
|
| 1769 | + // Exclusions de certains id |
|
| 1770 | + $exclusions = pipeline( |
|
| 1771 | + 'exclure_id_conditionnel', |
|
| 1772 | + [ |
|
| 1773 | + 'args' => [ |
|
| 1774 | + 'table' => $table, |
|
| 1775 | + 'id_table_objet' => $primary, |
|
| 1776 | + 'associable' => $associable, |
|
| 1777 | + ], |
|
| 1778 | + 'data' => [], |
|
| 1779 | + ] |
|
| 1780 | + ); |
|
| 1781 | + $champs = array_diff($champs, $exclusions); |
|
| 1782 | + |
|
| 1783 | + return $champs; |
|
| 1784 | 1784 | } |
| 1785 | 1785 | |
| 1786 | 1786 | /** |
@@ -1835,27 +1835,27 @@ discard block |
||
| 1835 | 1835 | * @return void |
| 1836 | 1836 | */ |
| 1837 | 1837 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1838 | - $boucle = &$boucles[$idb]; |
|
| 1839 | - |
|
| 1840 | - // definition du champ par defaut |
|
| 1841 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1842 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1843 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1844 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1845 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1846 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1847 | - |
|
| 1848 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1849 | - |
|
| 1850 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1851 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1852 | - |
|
| 1853 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1854 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1855 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1856 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1857 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1858 | - $boucle->hash .= " |
|
| 1838 | + $boucle = &$boucles[$idb]; |
|
| 1839 | + |
|
| 1840 | + // definition du champ par defaut |
|
| 1841 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1842 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1843 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1844 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1845 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1846 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1847 | + |
|
| 1848 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1849 | + |
|
| 1850 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1851 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1852 | + |
|
| 1853 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1854 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1855 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1856 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1857 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1858 | + $boucle->hash .= " |
|
| 1859 | 1859 | \$senstri = ''; |
| 1860 | 1860 | \$tri = $_tri; |
| 1861 | 1861 | if (\$tri){ |
@@ -1863,8 +1863,8 @@ discard block |
||
| 1863 | 1863 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1864 | 1864 | }; |
| 1865 | 1865 | "; |
| 1866 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1867 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1866 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1867 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1868 | 1868 | } |
| 1869 | 1869 | |
| 1870 | 1870 | # Criteres de comparaison |
@@ -1881,20 +1881,20 @@ discard block |
||
| 1881 | 1881 | * @return void |
| 1882 | 1882 | **/ |
| 1883 | 1883 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1884 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1885 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1886 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1890 | - if (!$r) { |
|
| 1891 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1892 | - # if (!$crit->cond) { |
|
| 1893 | - return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1894 | - # } |
|
| 1895 | - } else { |
|
| 1896 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1897 | - } |
|
| 1884 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1885 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1886 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1890 | + if (!$r) { |
|
| 1891 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1892 | + # if (!$crit->cond) { |
|
| 1893 | + return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1894 | + # } |
|
| 1895 | + } else { |
|
| 1896 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1897 | + } |
|
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | |
@@ -1914,62 +1914,62 @@ discard block |
||
| 1914 | 1914 | * @return void |
| 1915 | 1915 | **/ |
| 1916 | 1916 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1917 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1918 | - |
|
| 1919 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1920 | - |
|
| 1921 | - // inserer la negation (cf !...) |
|
| 1922 | - |
|
| 1923 | - if ($crit->not) { |
|
| 1924 | - $where = ["'NOT'", $where]; |
|
| 1925 | - } |
|
| 1926 | - if ($crit->exclus) { |
|
| 1927 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1928 | - $where = ["'NOT'", $where]; |
|
| 1929 | - } else { |
|
| 1930 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1931 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1932 | - $where = [ |
|
| 1933 | - "'NOT'", |
|
| 1934 | - [ |
|
| 1935 | - "'IN'", |
|
| 1936 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1937 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1938 | - ] |
|
| 1939 | - ]; |
|
| 1940 | - } |
|
| 1941 | - } |
|
| 1942 | - |
|
| 1943 | - // inserer la condition (cf {lang?}) |
|
| 1944 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1945 | - if ($crit->cond) { |
|
| 1946 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1947 | - if ($col == 'date' or $col == 'date_redac') { |
|
| 1948 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1949 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - if ($op == '=' and !$crit->not) { |
|
| 1954 | - $where = [ |
|
| 1955 | - "'?'", |
|
| 1956 | - "(is_array($pred))", |
|
| 1957 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1958 | - $where |
|
| 1959 | - ]; |
|
| 1960 | - } |
|
| 1961 | - $where = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where]; |
|
| 1962 | - if ($where_complement) { |
|
| 1963 | - // condition annexe du type "AND (objet='article')" |
|
| 1964 | - $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1965 | - } |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - $boucles[$idb]->where[] = $where; |
|
| 1969 | - if ($where_complement) { |
|
| 1970 | - // condition annexe du type "AND (objet='article')" |
|
| 1971 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1972 | - } |
|
| 1917 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1918 | + |
|
| 1919 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1920 | + |
|
| 1921 | + // inserer la negation (cf !...) |
|
| 1922 | + |
|
| 1923 | + if ($crit->not) { |
|
| 1924 | + $where = ["'NOT'", $where]; |
|
| 1925 | + } |
|
| 1926 | + if ($crit->exclus) { |
|
| 1927 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1928 | + $where = ["'NOT'", $where]; |
|
| 1929 | + } else { |
|
| 1930 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1931 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1932 | + $where = [ |
|
| 1933 | + "'NOT'", |
|
| 1934 | + [ |
|
| 1935 | + "'IN'", |
|
| 1936 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1937 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1938 | + ] |
|
| 1939 | + ]; |
|
| 1940 | + } |
|
| 1941 | + } |
|
| 1942 | + |
|
| 1943 | + // inserer la condition (cf {lang?}) |
|
| 1944 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1945 | + if ($crit->cond) { |
|
| 1946 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1947 | + if ($col == 'date' or $col == 'date_redac') { |
|
| 1948 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1949 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + if ($op == '=' and !$crit->not) { |
|
| 1954 | + $where = [ |
|
| 1955 | + "'?'", |
|
| 1956 | + "(is_array($pred))", |
|
| 1957 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1958 | + $where |
|
| 1959 | + ]; |
|
| 1960 | + } |
|
| 1961 | + $where = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where]; |
|
| 1962 | + if ($where_complement) { |
|
| 1963 | + // condition annexe du type "AND (objet='article')" |
|
| 1964 | + $where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement]; |
|
| 1965 | + } |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + $boucles[$idb]->where[] = $where; |
|
| 1969 | + if ($where_complement) { |
|
| 1970 | + // condition annexe du type "AND (objet='article')" |
|
| 1971 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1972 | + } |
|
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | 1975 | |
@@ -2010,165 +2010,165 @@ discard block |
||
| 2010 | 2010 | **/ |
| 2011 | 2011 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2012 | 2012 | |
| 2013 | - $boucle = &$boucles[$idb]; |
|
| 2014 | - $type = $boucle->type_requete; |
|
| 2015 | - $table = $boucle->id_table; |
|
| 2016 | - $desc = $boucle->show; |
|
| 2017 | - $col_vraie = null; |
|
| 2018 | - |
|
| 2019 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 2020 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2021 | - |
|
| 2022 | - $col_alias = $col; |
|
| 2023 | - $where_complement = false; |
|
| 2024 | - |
|
| 2025 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2026 | - if ($col == 'id_enfant') { |
|
| 2027 | - $col = $boucle->primary; |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2031 | - if ( |
|
| 2032 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2033 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2034 | - ) { |
|
| 2035 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2036 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2037 | - else { |
|
| 2038 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2039 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2043 | - // sauf si exception declaree : sauter cette etape |
|
| 2044 | - else { |
|
| 2045 | - if ( |
|
| 2046 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2047 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2048 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2049 | - ) { |
|
| 2050 | - $e = decompose_champ_id_objet($col); |
|
| 2051 | - $col = array_shift($e); |
|
| 2052 | - $where_complement = primary_doublee($e, $table); |
|
| 2053 | - } // Cas particulier : expressions de date |
|
| 2054 | - else { |
|
| 2055 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2056 | - list($col, $col_vraie) = $c; |
|
| 2057 | - $table = ''; |
|
| 2058 | - } // table explicitée {mots.titre} |
|
| 2059 | - else { |
|
| 2060 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2061 | - list(, $table, $col) = $r; |
|
| 2062 | - $col_alias = $col; |
|
| 2063 | - |
|
| 2064 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2065 | - if ( |
|
| 2066 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2067 | - and isset($desc['field'][$col]) |
|
| 2068 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2069 | - ) { |
|
| 2070 | - $table = $cle; |
|
| 2071 | - } else { |
|
| 2072 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2073 | - } |
|
| 2074 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2075 | - if (!$table) { |
|
| 2076 | - return ''; |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - // si le champ n'est pas trouvé dans la table, |
|
| 2080 | - // on cherche si une jointure peut l'obtenir |
|
| 2081 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2082 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2083 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2084 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2085 | - } |
|
| 2086 | - else { |
|
| 2087 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2088 | - if (!$r) { |
|
| 2089 | - return ''; |
|
| 2090 | - } |
|
| 2091 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - } |
|
| 2098 | - |
|
| 2099 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2100 | - // Dans tous les cas, |
|
| 2101 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2102 | - // et passer dans sql_quote avec le type si connu |
|
| 2103 | - // et int sinon si la valeur est numerique |
|
| 2104 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2105 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2106 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2107 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2108 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2109 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2110 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2111 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2112 | - } |
|
| 2113 | - // sinon expliciter les |
|
| 2114 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2115 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2116 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2117 | - // sans toucher aux |
|
| 2118 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2119 | - // sql_quote(truc,'','varchar') |
|
| 2120 | - elseif ( |
|
| 2121 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2122 | - // si pas deja un type |
|
| 2123 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2124 | - ) { |
|
| 2125 | - $r = $r[1] |
|
| 2126 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2127 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2128 | - $val[0] = "sql_quote($r)"; |
|
| 2129 | - } |
|
| 2130 | - elseif ( |
|
| 2131 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | - ) { |
|
| 2134 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - if ( |
|
| 2139 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2140 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2141 | - ) { |
|
| 2142 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2143 | - } |
|
| 2144 | - |
|
| 2145 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2146 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2147 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2148 | - if ($table === $boucle->id_table) { |
|
| 2149 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2150 | - if ($col_alias != $col_vraie) { |
|
| 2151 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2152 | - } |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2156 | - if ($table) { |
|
| 2157 | - if ($col[0] == '`') { |
|
| 2158 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2159 | - } else { |
|
| 2160 | - $arg = "$table.$col"; |
|
| 2161 | - } |
|
| 2162 | - } else { |
|
| 2163 | - $arg = $col; |
|
| 2164 | - } |
|
| 2165 | - |
|
| 2166 | - // inserer la fonction SQL |
|
| 2167 | - if ($fct) { |
|
| 2168 | - $arg = "$fct($arg$args_sql)"; |
|
| 2169 | - } |
|
| 2170 | - |
|
| 2171 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2013 | + $boucle = &$boucles[$idb]; |
|
| 2014 | + $type = $boucle->type_requete; |
|
| 2015 | + $table = $boucle->id_table; |
|
| 2016 | + $desc = $boucle->show; |
|
| 2017 | + $col_vraie = null; |
|
| 2018 | + |
|
| 2019 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 2020 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2021 | + |
|
| 2022 | + $col_alias = $col; |
|
| 2023 | + $where_complement = false; |
|
| 2024 | + |
|
| 2025 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2026 | + if ($col == 'id_enfant') { |
|
| 2027 | + $col = $boucle->primary; |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2031 | + if ( |
|
| 2032 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2033 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2034 | + ) { |
|
| 2035 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2036 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2037 | + else { |
|
| 2038 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2039 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2043 | + // sauf si exception declaree : sauter cette etape |
|
| 2044 | + else { |
|
| 2045 | + if ( |
|
| 2046 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2047 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2048 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2049 | + ) { |
|
| 2050 | + $e = decompose_champ_id_objet($col); |
|
| 2051 | + $col = array_shift($e); |
|
| 2052 | + $where_complement = primary_doublee($e, $table); |
|
| 2053 | + } // Cas particulier : expressions de date |
|
| 2054 | + else { |
|
| 2055 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2056 | + list($col, $col_vraie) = $c; |
|
| 2057 | + $table = ''; |
|
| 2058 | + } // table explicitée {mots.titre} |
|
| 2059 | + else { |
|
| 2060 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2061 | + list(, $table, $col) = $r; |
|
| 2062 | + $col_alias = $col; |
|
| 2063 | + |
|
| 2064 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2065 | + if ( |
|
| 2066 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2067 | + and isset($desc['field'][$col]) |
|
| 2068 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2069 | + ) { |
|
| 2070 | + $table = $cle; |
|
| 2071 | + } else { |
|
| 2072 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2073 | + } |
|
| 2074 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2075 | + if (!$table) { |
|
| 2076 | + return ''; |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + // si le champ n'est pas trouvé dans la table, |
|
| 2080 | + // on cherche si une jointure peut l'obtenir |
|
| 2081 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2082 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2083 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2084 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2085 | + } |
|
| 2086 | + else { |
|
| 2087 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2088 | + if (!$r) { |
|
| 2089 | + return ''; |
|
| 2090 | + } |
|
| 2091 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + } |
|
| 2098 | + |
|
| 2099 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2100 | + // Dans tous les cas, |
|
| 2101 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2102 | + // et passer dans sql_quote avec le type si connu |
|
| 2103 | + // et int sinon si la valeur est numerique |
|
| 2104 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2105 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2106 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2107 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2108 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2109 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2110 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2111 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2112 | + } |
|
| 2113 | + // sinon expliciter les |
|
| 2114 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2115 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2116 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2117 | + // sans toucher aux |
|
| 2118 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2119 | + // sql_quote(truc,'','varchar') |
|
| 2120 | + elseif ( |
|
| 2121 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2122 | + // si pas deja un type |
|
| 2123 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2124 | + ) { |
|
| 2125 | + $r = $r[1] |
|
| 2126 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2127 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2128 | + $val[0] = "sql_quote($r)"; |
|
| 2129 | + } |
|
| 2130 | + elseif ( |
|
| 2131 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | + ) { |
|
| 2134 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + if ( |
|
| 2139 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2140 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2141 | + ) { |
|
| 2142 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2146 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2147 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2148 | + if ($table === $boucle->id_table) { |
|
| 2149 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2150 | + if ($col_alias != $col_vraie) { |
|
| 2151 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2152 | + } |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2156 | + if ($table) { |
|
| 2157 | + if ($col[0] == '`') { |
|
| 2158 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2159 | + } else { |
|
| 2160 | + $arg = "$table.$col"; |
|
| 2161 | + } |
|
| 2162 | + } else { |
|
| 2163 | + $arg = $col; |
|
| 2164 | + } |
|
| 2165 | + |
|
| 2166 | + // inserer la fonction SQL |
|
| 2167 | + if ($fct) { |
|
| 2168 | + $arg = "$fct($arg$args_sql)"; |
|
| 2169 | + } |
|
| 2170 | + |
|
| 2171 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | |
@@ -2197,78 +2197,78 @@ discard block |
||
| 2197 | 2197 | **/ |
| 2198 | 2198 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2199 | 2199 | |
| 2200 | - $where = ''; |
|
| 2201 | - |
|
| 2202 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2203 | - // gestion par les plugins des jointures tordues |
|
| 2204 | - // pas automatiques mais necessaires |
|
| 2205 | - $table_sql = table_objet_sql($table); |
|
| 2206 | - if ( |
|
| 2207 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2208 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2209 | - and |
|
| 2210 | - ( |
|
| 2211 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2212 | - or |
|
| 2213 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2214 | - ) |
|
| 2215 | - ) { |
|
| 2216 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2217 | - $index = isset($t[$col]) |
|
| 2218 | - ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2219 | - |
|
| 2220 | - if (count($index) == 3) { |
|
| 2221 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2222 | - } elseif (count($index) == 2) { |
|
| 2223 | - list($t, $col) = $t[$col]; |
|
| 2224 | - } elseif (count($index) == 1) { |
|
| 2225 | - list($calculer_critere_externe) = $index; |
|
| 2226 | - $t = $table; |
|
| 2227 | - } else { |
|
| 2228 | - $t = ''; |
|
| 2229 | - } // jointure non declaree. La trouver. |
|
| 2230 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2231 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2232 | - } else { |
|
| 2233 | - $t = ''; |
|
| 2234 | - } // jointure non declaree. La trouver. |
|
| 2235 | - |
|
| 2236 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2237 | - |
|
| 2238 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2239 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2240 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2241 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2242 | - $table = ''; |
|
| 2243 | - if ($boucle->jointures_explicites) { |
|
| 2244 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2245 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2246 | - } |
|
| 2247 | - |
|
| 2248 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2249 | - if (!$table) { |
|
| 2250 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - if (!$table) { |
|
| 2254 | - return ''; |
|
| 2255 | - } |
|
| 2256 | - |
|
| 2257 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2258 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2259 | - |
|
| 2260 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2261 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2262 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2263 | - $e = decompose_champ_id_objet($col); |
|
| 2264 | - $col = array_shift($e); |
|
| 2265 | - $where = primary_doublee($e, $table); |
|
| 2266 | - } else { |
|
| 2267 | - $col = reset($cle); |
|
| 2268 | - } |
|
| 2269 | - } |
|
| 2270 | - |
|
| 2271 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2200 | + $where = ''; |
|
| 2201 | + |
|
| 2202 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2203 | + // gestion par les plugins des jointures tordues |
|
| 2204 | + // pas automatiques mais necessaires |
|
| 2205 | + $table_sql = table_objet_sql($table); |
|
| 2206 | + if ( |
|
| 2207 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2208 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2209 | + and |
|
| 2210 | + ( |
|
| 2211 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2212 | + or |
|
| 2213 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2214 | + ) |
|
| 2215 | + ) { |
|
| 2216 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2217 | + $index = isset($t[$col]) |
|
| 2218 | + ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2219 | + |
|
| 2220 | + if (count($index) == 3) { |
|
| 2221 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2222 | + } elseif (count($index) == 2) { |
|
| 2223 | + list($t, $col) = $t[$col]; |
|
| 2224 | + } elseif (count($index) == 1) { |
|
| 2225 | + list($calculer_critere_externe) = $index; |
|
| 2226 | + $t = $table; |
|
| 2227 | + } else { |
|
| 2228 | + $t = ''; |
|
| 2229 | + } // jointure non declaree. La trouver. |
|
| 2230 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2231 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2232 | + } else { |
|
| 2233 | + $t = ''; |
|
| 2234 | + } // jointure non declaree. La trouver. |
|
| 2235 | + |
|
| 2236 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2237 | + |
|
| 2238 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2239 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2240 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2241 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2242 | + $table = ''; |
|
| 2243 | + if ($boucle->jointures_explicites) { |
|
| 2244 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2245 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2246 | + } |
|
| 2247 | + |
|
| 2248 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2249 | + if (!$table) { |
|
| 2250 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + if (!$table) { |
|
| 2254 | + return ''; |
|
| 2255 | + } |
|
| 2256 | + |
|
| 2257 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2258 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2259 | + |
|
| 2260 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2261 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2262 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2263 | + $e = decompose_champ_id_objet($col); |
|
| 2264 | + $col = array_shift($e); |
|
| 2265 | + $where = primary_doublee($e, $table); |
|
| 2266 | + } else { |
|
| 2267 | + $col = reset($cle); |
|
| 2268 | + } |
|
| 2269 | + } |
|
| 2270 | + |
|
| 2271 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | |
@@ -2289,10 +2289,10 @@ discard block |
||
| 2289 | 2289 | * - valeur |
| 2290 | 2290 | **/ |
| 2291 | 2291 | function primary_doublee($decompose, $table) { |
| 2292 | - $e1 = reset($decompose); |
|
| 2293 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2292 | + $e1 = reset($decompose); |
|
| 2293 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2294 | 2294 | |
| 2295 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2295 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | 2298 | /** |
@@ -2323,57 +2323,57 @@ discard block |
||
| 2323 | 2323 | * Vide sinon. |
| 2324 | 2324 | */ |
| 2325 | 2325 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2326 | - // si on demande un truc du genre spip_mots |
|
| 2327 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2328 | - // et qu'on est la |
|
| 2329 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2330 | - if ( |
|
| 2331 | - $checkarrivee |
|
| 2332 | - and is_string($checkarrivee) |
|
| 2333 | - and $a = table_objet($checkarrivee) |
|
| 2334 | - and in_array($a . '_liens', $joints) |
|
| 2335 | - ) { |
|
| 2336 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2337 | - return $res; |
|
| 2338 | - } |
|
| 2339 | - } |
|
| 2340 | - foreach ($joints as $joint) { |
|
| 2341 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2342 | - // alias de table dans le from |
|
| 2343 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2344 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2345 | - $cols = $arrivee[2]; |
|
| 2346 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2347 | - if (count($cols) > 2) { |
|
| 2348 | - array_pop($cols); |
|
| 2349 | - } |
|
| 2350 | - if ($t) { |
|
| 2351 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2352 | - $joindre = false; |
|
| 2353 | - foreach ($cols as $col) { |
|
| 2354 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2355 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2356 | - $joindre = true; |
|
| 2357 | - } else { |
|
| 2358 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2359 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2360 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2361 | - $joindre = true; |
|
| 2362 | - } |
|
| 2363 | - } |
|
| 2364 | - } |
|
| 2365 | - if (!$joindre) { |
|
| 2366 | - return $t; |
|
| 2367 | - } |
|
| 2368 | - } |
|
| 2369 | - array_pop($arrivee); |
|
| 2370 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2371 | - return $res; |
|
| 2372 | - } |
|
| 2373 | - } |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - return ''; |
|
| 2326 | + // si on demande un truc du genre spip_mots |
|
| 2327 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2328 | + // et qu'on est la |
|
| 2329 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2330 | + if ( |
|
| 2331 | + $checkarrivee |
|
| 2332 | + and is_string($checkarrivee) |
|
| 2333 | + and $a = table_objet($checkarrivee) |
|
| 2334 | + and in_array($a . '_liens', $joints) |
|
| 2335 | + ) { |
|
| 2336 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2337 | + return $res; |
|
| 2338 | + } |
|
| 2339 | + } |
|
| 2340 | + foreach ($joints as $joint) { |
|
| 2341 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2342 | + // alias de table dans le from |
|
| 2343 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2344 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2345 | + $cols = $arrivee[2]; |
|
| 2346 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2347 | + if (count($cols) > 2) { |
|
| 2348 | + array_pop($cols); |
|
| 2349 | + } |
|
| 2350 | + if ($t) { |
|
| 2351 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2352 | + $joindre = false; |
|
| 2353 | + foreach ($cols as $col) { |
|
| 2354 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2355 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2356 | + $joindre = true; |
|
| 2357 | + } else { |
|
| 2358 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2359 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2360 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2361 | + $joindre = true; |
|
| 2362 | + } |
|
| 2363 | + } |
|
| 2364 | + } |
|
| 2365 | + if (!$joindre) { |
|
| 2366 | + return $t; |
|
| 2367 | + } |
|
| 2368 | + } |
|
| 2369 | + array_pop($arrivee); |
|
| 2370 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2371 | + return $res; |
|
| 2372 | + } |
|
| 2373 | + } |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + return ''; |
|
| 2377 | 2377 | } |
| 2378 | 2378 | |
| 2379 | 2379 | /** |
@@ -2399,35 +2399,35 @@ discard block |
||
| 2399 | 2399 | * Alias de la table de jointure (Lx) |
| 2400 | 2400 | */ |
| 2401 | 2401 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2402 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2403 | - |
|
| 2404 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2405 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2406 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2407 | - |
|
| 2408 | - if (!$intermediaire or !$arrivee) { |
|
| 2409 | - return ''; |
|
| 2410 | - } |
|
| 2411 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2412 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2413 | - |
|
| 2414 | - $res = fabrique_jointures( |
|
| 2415 | - $boucle, |
|
| 2416 | - [ |
|
| 2417 | - [ |
|
| 2418 | - $boucle->id_table, |
|
| 2419 | - $intermediaire, |
|
| 2420 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2421 | - ], |
|
| 2422 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2423 | - ], |
|
| 2424 | - $cond, |
|
| 2425 | - $desc, |
|
| 2426 | - $boucle->id_table, |
|
| 2427 | - [$col] |
|
| 2428 | - ); |
|
| 2429 | - |
|
| 2430 | - return $res; |
|
| 2402 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2403 | + |
|
| 2404 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2405 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2406 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2407 | + |
|
| 2408 | + if (!$intermediaire or !$arrivee) { |
|
| 2409 | + return ''; |
|
| 2410 | + } |
|
| 2411 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2412 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2413 | + |
|
| 2414 | + $res = fabrique_jointures( |
|
| 2415 | + $boucle, |
|
| 2416 | + [ |
|
| 2417 | + [ |
|
| 2418 | + $boucle->id_table, |
|
| 2419 | + $intermediaire, |
|
| 2420 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2421 | + ], |
|
| 2422 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2423 | + ], |
|
| 2424 | + $cond, |
|
| 2425 | + $desc, |
|
| 2426 | + $boucle->id_table, |
|
| 2427 | + [$col] |
|
| 2428 | + ); |
|
| 2429 | + |
|
| 2430 | + return $res; |
|
| 2431 | 2431 | } |
| 2432 | 2432 | |
| 2433 | 2433 | |
@@ -2444,17 +2444,17 @@ discard block |
||
| 2444 | 2444 | * false sinon. |
| 2445 | 2445 | **/ |
| 2446 | 2446 | function trouver_champ($champ, $where) { |
| 2447 | - if (!is_array($where)) { |
|
| 2448 | - return preg_match($champ, $where); |
|
| 2449 | - } else { |
|
| 2450 | - foreach ($where as $clause) { |
|
| 2451 | - if (trouver_champ($champ, $clause)) { |
|
| 2452 | - return true; |
|
| 2453 | - } |
|
| 2454 | - } |
|
| 2455 | - |
|
| 2456 | - return false; |
|
| 2457 | - } |
|
| 2447 | + if (!is_array($where)) { |
|
| 2448 | + return preg_match($champ, $where); |
|
| 2449 | + } else { |
|
| 2450 | + foreach ($where as $clause) { |
|
| 2451 | + if (trouver_champ($champ, $clause)) { |
|
| 2452 | + return true; |
|
| 2453 | + } |
|
| 2454 | + } |
|
| 2455 | + |
|
| 2456 | + return false; |
|
| 2457 | + } |
|
| 2458 | 2458 | } |
| 2459 | 2459 | |
| 2460 | 2460 | |
@@ -2480,130 +2480,130 @@ discard block |
||
| 2480 | 2480 | * - string $args_sql Suite des arguments du critère. ? |
| 2481 | 2481 | **/ |
| 2482 | 2482 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2483 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2484 | - if (count($crit->param) == 0) { |
|
| 2485 | - $op = '='; |
|
| 2486 | - $col = $val = $crit->op; |
|
| 2487 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2488 | - $val = $r[2]; |
|
| 2489 | - } |
|
| 2490 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2491 | - if ($val == 'lang') { |
|
| 2492 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2493 | - } else { |
|
| 2494 | - $defaut = null; |
|
| 2495 | - if ($val == 'id_parent') { |
|
| 2496 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2497 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2498 | - // pour eviter l'erreur SQL |
|
| 2499 | - $val = $boucles[$idb]->primary; |
|
| 2500 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2501 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2502 | - } elseif ($val == 'id_enfant') { |
|
| 2503 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2504 | - // de la boucle superieure |
|
| 2505 | - $val = 'id_parent'; |
|
| 2506 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2507 | - // un critere conditionnel sur date est traite a part |
|
| 2508 | - // car la date est mise d'office par SPIP, |
|
| 2509 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2513 | - $val = [kwote($val)]; |
|
| 2514 | - } |
|
| 2515 | - } else { |
|
| 2516 | - // comparaison explicite |
|
| 2517 | - // le phraseur impose que le premier param soit du texte |
|
| 2518 | - $params = $crit->param; |
|
| 2519 | - $op = $crit->op; |
|
| 2520 | - if ($op == '==') { |
|
| 2521 | - $op = 'REGEXP'; |
|
| 2522 | - } |
|
| 2523 | - $col = array_shift($params); |
|
| 2524 | - $col = $col[0]->texte; |
|
| 2525 | - |
|
| 2526 | - $val = []; |
|
| 2527 | - $parent = $boucles[$idb]->id_parent; |
|
| 2528 | - |
|
| 2529 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2530 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2531 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2532 | - if ( |
|
| 2533 | - count($params) == 1 |
|
| 2534 | - and count($params[0]) == 3 |
|
| 2535 | - and $params[0][0]->type == 'texte' |
|
| 2536 | - and $params[0][2]->type == 'texte' |
|
| 2537 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2538 | - and (($p == "'") or ($p == '"')) |
|
| 2539 | - and $params[0][1]->type == 'champ' |
|
| 2540 | - ) { |
|
| 2541 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2542 | - } else { |
|
| 2543 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2544 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2545 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2546 | - $val[] = $a; |
|
| 2547 | - } else { |
|
| 2548 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2549 | - } // toujours quoter en char ici |
|
| 2550 | - } |
|
| 2551 | - } |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - $fct = $args_sql = ''; |
|
| 2555 | - // fonction SQL ? |
|
| 2556 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2557 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2558 | - $fct = $m[1]; |
|
| 2559 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2560 | - $col = $a[1]; |
|
| 2561 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2562 | - $col = $m[1]; |
|
| 2563 | - $args_sql = $m[2]; |
|
| 2564 | - } |
|
| 2565 | - $args_sql .= $a[2]; |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2483 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2484 | + if (count($crit->param) == 0) { |
|
| 2485 | + $op = '='; |
|
| 2486 | + $col = $val = $crit->op; |
|
| 2487 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2488 | + $val = $r[2]; |
|
| 2489 | + } |
|
| 2490 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2491 | + if ($val == 'lang') { |
|
| 2492 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2493 | + } else { |
|
| 2494 | + $defaut = null; |
|
| 2495 | + if ($val == 'id_parent') { |
|
| 2496 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2497 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2498 | + // pour eviter l'erreur SQL |
|
| 2499 | + $val = $boucles[$idb]->primary; |
|
| 2500 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2501 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2502 | + } elseif ($val == 'id_enfant') { |
|
| 2503 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2504 | + // de la boucle superieure |
|
| 2505 | + $val = 'id_parent'; |
|
| 2506 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2507 | + // un critere conditionnel sur date est traite a part |
|
| 2508 | + // car la date est mise d'office par SPIP, |
|
| 2509 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2513 | + $val = [kwote($val)]; |
|
| 2514 | + } |
|
| 2515 | + } else { |
|
| 2516 | + // comparaison explicite |
|
| 2517 | + // le phraseur impose que le premier param soit du texte |
|
| 2518 | + $params = $crit->param; |
|
| 2519 | + $op = $crit->op; |
|
| 2520 | + if ($op == '==') { |
|
| 2521 | + $op = 'REGEXP'; |
|
| 2522 | + } |
|
| 2523 | + $col = array_shift($params); |
|
| 2524 | + $col = $col[0]->texte; |
|
| 2525 | + |
|
| 2526 | + $val = []; |
|
| 2527 | + $parent = $boucles[$idb]->id_parent; |
|
| 2528 | + |
|
| 2529 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2530 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2531 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2532 | + if ( |
|
| 2533 | + count($params) == 1 |
|
| 2534 | + and count($params[0]) == 3 |
|
| 2535 | + and $params[0][0]->type == 'texte' |
|
| 2536 | + and $params[0][2]->type == 'texte' |
|
| 2537 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2538 | + and (($p == "'") or ($p == '"')) |
|
| 2539 | + and $params[0][1]->type == 'champ' |
|
| 2540 | + ) { |
|
| 2541 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2542 | + } else { |
|
| 2543 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2544 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2545 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2546 | + $val[] = $a; |
|
| 2547 | + } else { |
|
| 2548 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2549 | + } // toujours quoter en char ici |
|
| 2550 | + } |
|
| 2551 | + } |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + $fct = $args_sql = ''; |
|
| 2555 | + // fonction SQL ? |
|
| 2556 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2557 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2558 | + $fct = $m[1]; |
|
| 2559 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2560 | + $col = $a[1]; |
|
| 2561 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2562 | + $col = $m[1]; |
|
| 2563 | + $args_sql = $m[2]; |
|
| 2564 | + } |
|
| 2565 | + $args_sql .= $a[2]; |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2569 | 2569 | } |
| 2570 | 2570 | |
| 2571 | 2571 | // compatibilite ancienne version |
| 2572 | 2572 | |
| 2573 | 2573 | // https://code.spip.net/@calculer_vieux_in |
| 2574 | 2574 | function calculer_vieux_in($params) { |
| 2575 | - $deb = $params[0][0]; |
|
| 2576 | - $k = count($params) - 1; |
|
| 2577 | - $last = $params[$k]; |
|
| 2578 | - $j = count($last) - 1; |
|
| 2579 | - $last = $last[$j]; |
|
| 2580 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2581 | - |
|
| 2582 | - if ( |
|
| 2583 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2584 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2585 | - ) { |
|
| 2586 | - return $params; |
|
| 2587 | - } |
|
| 2588 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2589 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2590 | - $last = $params[$k][$j]; |
|
| 2591 | - $n = strlen($last->texte); |
|
| 2592 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2593 | - $newp = []; |
|
| 2594 | - foreach ($params as $v) { |
|
| 2595 | - if ($v[0]->type != 'texte') { |
|
| 2596 | - $newp[] = $v; |
|
| 2597 | - } else { |
|
| 2598 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2599 | - $t = new Texte(); |
|
| 2600 | - $t->texte = $x; |
|
| 2601 | - $newp[] = [$t]; |
|
| 2602 | - } |
|
| 2603 | - } |
|
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - return $newp; |
|
| 2575 | + $deb = $params[0][0]; |
|
| 2576 | + $k = count($params) - 1; |
|
| 2577 | + $last = $params[$k]; |
|
| 2578 | + $j = count($last) - 1; |
|
| 2579 | + $last = $last[$j]; |
|
| 2580 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2581 | + |
|
| 2582 | + if ( |
|
| 2583 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2584 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2585 | + ) { |
|
| 2586 | + return $params; |
|
| 2587 | + } |
|
| 2588 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2589 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2590 | + $last = $params[$k][$j]; |
|
| 2591 | + $n = strlen($last->texte); |
|
| 2592 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2593 | + $newp = []; |
|
| 2594 | + foreach ($params as $v) { |
|
| 2595 | + if ($v[0]->type != 'texte') { |
|
| 2596 | + $newp[] = $v; |
|
| 2597 | + } else { |
|
| 2598 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2599 | + $t = new Texte(); |
|
| 2600 | + $t->texte = $x; |
|
| 2601 | + $newp[] = [$t]; |
|
| 2602 | + } |
|
| 2603 | + } |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + return $newp; |
|
| 2607 | 2607 | } |
| 2608 | 2608 | |
| 2609 | 2609 | /** |
@@ -2622,89 +2622,89 @@ discard block |
||
| 2622 | 2622 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2623 | 2623 | **/ |
| 2624 | 2624 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2625 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2626 | - return ''; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - $boucle = $boucles[$idb]; |
|
| 2630 | - $table = $boucle->show; |
|
| 2631 | - |
|
| 2632 | - // si c'est une colonne de la table, ne rien faire |
|
| 2633 | - if (isset($table['field'][$col])) { |
|
| 2634 | - return ''; |
|
| 2635 | - } |
|
| 2636 | - |
|
| 2637 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2638 | - return ''; |
|
| 2639 | - } |
|
| 2640 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2641 | - |
|
| 2642 | - $col = $regs[1]; |
|
| 2643 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2644 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2645 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2646 | - |
|
| 2647 | - if (isset($table['field']["date$suite"])) { |
|
| 2648 | - $date_orig = 'date' . $suite; |
|
| 2649 | - } else { |
|
| 2650 | - $date_orig = substr($suite, 1); |
|
| 2651 | - } |
|
| 2652 | - $pred = $date_orig; |
|
| 2653 | - } else { |
|
| 2654 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2655 | - $pred = 'date'; |
|
| 2656 | - } |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2660 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2661 | - ") . '\""; |
|
| 2662 | - |
|
| 2663 | - $col_vraie = $date_orig; |
|
| 2664 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2665 | - |
|
| 2666 | - switch ($col) { |
|
| 2667 | - case 'date': |
|
| 2668 | - $col = $date_orig; |
|
| 2669 | - break; |
|
| 2670 | - case 'jour': |
|
| 2671 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2672 | - break; |
|
| 2673 | - case 'mois': |
|
| 2674 | - $col = "MONTH($date_orig)"; |
|
| 2675 | - break; |
|
| 2676 | - case 'annee': |
|
| 2677 | - $col = "YEAR($date_orig)"; |
|
| 2678 | - break; |
|
| 2679 | - case 'heure': |
|
| 2680 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2681 | - break; |
|
| 2682 | - case 'age': |
|
| 2683 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | - break; |
|
| 2686 | - case 'age_relatif': |
|
| 2687 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2688 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | - break; |
|
| 2690 | - case 'jour_relatif': |
|
| 2691 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2692 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | - break; |
|
| 2694 | - case 'mois_relatif': |
|
| 2695 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2696 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2697 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2698 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2699 | - break; |
|
| 2700 | - case 'annee_relatif': |
|
| 2701 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2702 | - $date_orig . ')'; |
|
| 2703 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2704 | - break; |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - return [$col, $col_vraie]; |
|
| 2625 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2626 | + return ''; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + $boucle = $boucles[$idb]; |
|
| 2630 | + $table = $boucle->show; |
|
| 2631 | + |
|
| 2632 | + // si c'est une colonne de la table, ne rien faire |
|
| 2633 | + if (isset($table['field'][$col])) { |
|
| 2634 | + return ''; |
|
| 2635 | + } |
|
| 2636 | + |
|
| 2637 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2638 | + return ''; |
|
| 2639 | + } |
|
| 2640 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2641 | + |
|
| 2642 | + $col = $regs[1]; |
|
| 2643 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2644 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2645 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2646 | + |
|
| 2647 | + if (isset($table['field']["date$suite"])) { |
|
| 2648 | + $date_orig = 'date' . $suite; |
|
| 2649 | + } else { |
|
| 2650 | + $date_orig = substr($suite, 1); |
|
| 2651 | + } |
|
| 2652 | + $pred = $date_orig; |
|
| 2653 | + } else { |
|
| 2654 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2655 | + $pred = 'date'; |
|
| 2656 | + } |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2660 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2661 | + ") . '\""; |
|
| 2662 | + |
|
| 2663 | + $col_vraie = $date_orig; |
|
| 2664 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2665 | + |
|
| 2666 | + switch ($col) { |
|
| 2667 | + case 'date': |
|
| 2668 | + $col = $date_orig; |
|
| 2669 | + break; |
|
| 2670 | + case 'jour': |
|
| 2671 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2672 | + break; |
|
| 2673 | + case 'mois': |
|
| 2674 | + $col = "MONTH($date_orig)"; |
|
| 2675 | + break; |
|
| 2676 | + case 'annee': |
|
| 2677 | + $col = "YEAR($date_orig)"; |
|
| 2678 | + break; |
|
| 2679 | + case 'heure': |
|
| 2680 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2681 | + break; |
|
| 2682 | + case 'age': |
|
| 2683 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2684 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + break; |
|
| 2686 | + case 'age_relatif': |
|
| 2687 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2688 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | + break; |
|
| 2690 | + case 'jour_relatif': |
|
| 2691 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2692 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | + break; |
|
| 2694 | + case 'mois_relatif': |
|
| 2695 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2696 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2697 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2698 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2699 | + break; |
|
| 2700 | + case 'annee_relatif': |
|
| 2701 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2702 | + $date_orig . ')'; |
|
| 2703 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2704 | + break; |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + return [$col, $col_vraie]; |
|
| 2708 | 2708 | } |
| 2709 | 2709 | |
| 2710 | 2710 | /** |
@@ -2723,16 +2723,16 @@ discard block |
||
| 2723 | 2723 | * de colonne SQL et une date. |
| 2724 | 2724 | **/ |
| 2725 | 2725 | function calculer_param_date($date_compare, $date_orig) { |
| 2726 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2727 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2728 | - $date_compare = '\'$x\''; |
|
| 2729 | - } else { |
|
| 2730 | - $init = $date_compare; |
|
| 2731 | - } |
|
| 2732 | - |
|
| 2733 | - return |
|
| 2734 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2735 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2726 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2727 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2728 | + $date_compare = '\'$x\''; |
|
| 2729 | + } else { |
|
| 2730 | + $init = $date_compare; |
|
| 2731 | + } |
|
| 2732 | + |
|
| 2733 | + return |
|
| 2734 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2735 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2736 | 2736 | } |
| 2737 | 2737 | |
| 2738 | 2738 | /** |
@@ -2750,20 +2750,20 @@ discard block |
||
| 2750 | 2750 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2751 | 2751 | */ |
| 2752 | 2752 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2753 | - $boucle = &$boucles[$idb]; |
|
| 2754 | - |
|
| 2755 | - $args = []; |
|
| 2756 | - foreach ($crit->param as &$param) { |
|
| 2757 | - array_push( |
|
| 2758 | - $args, |
|
| 2759 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2760 | - ); |
|
| 2761 | - } |
|
| 2753 | + $boucle = &$boucles[$idb]; |
|
| 2762 | 2754 | |
| 2763 | - $boucle->hash .= ' |
|
| 2755 | + $args = []; |
|
| 2756 | + foreach ($crit->param as &$param) { |
|
| 2757 | + array_push( |
|
| 2758 | + $args, |
|
| 2759 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2760 | + ); |
|
| 2761 | + } |
|
| 2762 | + |
|
| 2763 | + $boucle->hash .= ' |
|
| 2764 | 2764 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2765 | 2765 | |
| 2766 | - $boucle->hash .= ' |
|
| 2766 | + $boucle->hash .= ' |
|
| 2767 | 2767 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2768 | 2768 | } |
| 2769 | 2769 | |
@@ -2781,8 +2781,8 @@ discard block |
||
| 2781 | 2781 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2782 | 2782 | */ |
| 2783 | 2783 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2784 | - $boucle = &$boucles[$idb]; |
|
| 2785 | - $boucle->hash .= ' |
|
| 2784 | + $boucle = &$boucles[$idb]; |
|
| 2785 | + $boucle->hash .= ' |
|
| 2786 | 2786 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2787 | 2787 | } |
| 2788 | 2788 | |
@@ -2798,12 +2798,12 @@ discard block |
||
| 2798 | 2798 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2799 | 2799 | */ |
| 2800 | 2800 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2801 | - $boucle = &$boucles[$idb]; |
|
| 2802 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2803 | - foreach ($crit->param as $param) { |
|
| 2804 | - $boucle->hash .= ' |
|
| 2801 | + $boucle = &$boucles[$idb]; |
|
| 2802 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2803 | + foreach ($crit->param as $param) { |
|
| 2804 | + $boucle->hash .= ' |
|
| 2805 | 2805 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2806 | - } |
|
| 2806 | + } |
|
| 2807 | 2807 | } |
| 2808 | 2808 | |
| 2809 | 2809 | /** |
@@ -2820,16 +2820,16 @@ discard block |
||
| 2820 | 2820 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2821 | 2821 | */ |
| 2822 | 2822 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2823 | - $boucle = &$boucles[$idb]; |
|
| 2824 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2825 | - foreach ($crit->param as $param) { |
|
| 2826 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2827 | - $param, |
|
| 2828 | - $idb, |
|
| 2829 | - $boucles, |
|
| 2830 | - $boucles[$idb]->id_parent |
|
| 2831 | - ) . ";\n"; |
|
| 2832 | - } |
|
| 2823 | + $boucle = &$boucles[$idb]; |
|
| 2824 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2825 | + foreach ($crit->param as $param) { |
|
| 2826 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2827 | + $param, |
|
| 2828 | + $idb, |
|
| 2829 | + $boucles, |
|
| 2830 | + $boucles[$idb]->id_parent |
|
| 2831 | + ) . ";\n"; |
|
| 2832 | + } |
|
| 2833 | 2833 | } |
| 2834 | 2834 | |
| 2835 | 2835 | /** |
@@ -2854,16 +2854,16 @@ discard block |
||
| 2854 | 2854 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2855 | 2855 | */ |
| 2856 | 2856 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2857 | - $boucle = &$boucles[$idb]; |
|
| 2858 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2859 | - foreach ($crit->param as $param) { |
|
| 2860 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2861 | - $param, |
|
| 2862 | - $idb, |
|
| 2863 | - $boucles, |
|
| 2864 | - $boucles[$idb]->id_parent |
|
| 2865 | - ) . ";\n"; |
|
| 2866 | - } |
|
| 2857 | + $boucle = &$boucles[$idb]; |
|
| 2858 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2859 | + foreach ($crit->param as $param) { |
|
| 2860 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2861 | + $param, |
|
| 2862 | + $idb, |
|
| 2863 | + $boucles, |
|
| 2864 | + $boucles[$idb]->id_parent |
|
| 2865 | + ) . ";\n"; |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2878,11 +2878,11 @@ discard block |
||
| 2878 | 2878 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2879 | 2879 | */ |
| 2880 | 2880 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2881 | - $boucle = &$boucles[$idb]; |
|
| 2882 | - foreach ($crit->param as $param) { |
|
| 2883 | - $boucle->hash .= ' |
|
| 2881 | + $boucle = &$boucles[$idb]; |
|
| 2882 | + foreach ($crit->param as $param) { |
|
| 2883 | + $boucle->hash .= ' |
|
| 2884 | 2884 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2885 | - } |
|
| 2885 | + } |
|
| 2886 | 2886 | } |
| 2887 | 2887 | |
| 2888 | 2888 | |
@@ -2914,20 +2914,20 @@ discard block |
||
| 2914 | 2914 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2915 | 2915 | */ |
| 2916 | 2916 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2917 | - $boucle = &$boucles[$idb]; |
|
| 2918 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2919 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2920 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2921 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2922 | - if ($crit->param) { |
|
| 2923 | - foreach ($crit->param as $param) { |
|
| 2924 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2925 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2926 | - } |
|
| 2927 | - // interdire {si 0} aussi ! |
|
| 2928 | - } else { |
|
| 2929 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2930 | - } |
|
| 2917 | + $boucle = &$boucles[$idb]; |
|
| 2918 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2919 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2920 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2921 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2922 | + if ($crit->param) { |
|
| 2923 | + foreach ($crit->param as $param) { |
|
| 2924 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2925 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2926 | + } |
|
| 2927 | + // interdire {si 0} aussi ! |
|
| 2928 | + } else { |
|
| 2929 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2930 | + } |
|
| 2931 | 2931 | } |
| 2932 | 2932 | |
| 2933 | 2933 | /** |
@@ -2944,8 +2944,8 @@ discard block |
||
| 2944 | 2944 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2945 | 2945 | */ |
| 2946 | 2946 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2947 | - $boucle = &$boucles[$idb]; |
|
| 2948 | - $boucle->hash .= ' |
|
| 2947 | + $boucle = &$boucles[$idb]; |
|
| 2948 | + $boucle->hash .= ' |
|
| 2949 | 2949 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2950 | 2950 | $command[\'sourcemode\'] = \'table\';'; |
| 2951 | 2951 | } |
@@ -2966,29 +2966,29 @@ discard block |
||
| 2966 | 2966 | */ |
| 2967 | 2967 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2968 | 2968 | |
| 2969 | - $not = $crit->not; |
|
| 2970 | - $boucle = &$boucles[$idb]; |
|
| 2971 | - $primary = $boucle->primary; |
|
| 2969 | + $not = $crit->not; |
|
| 2970 | + $boucle = &$boucles[$idb]; |
|
| 2971 | + $primary = $boucle->primary; |
|
| 2972 | 2972 | |
| 2973 | - if (!$primary or strpos($primary, ',')) { |
|
| 2974 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2973 | + if (!$primary or strpos($primary, ',')) { |
|
| 2974 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2975 | 2975 | |
| 2976 | - return; |
|
| 2977 | - } |
|
| 2978 | - $table = $boucle->type_requete; |
|
| 2979 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2976 | + return; |
|
| 2977 | + } |
|
| 2978 | + $table = $boucle->type_requete; |
|
| 2979 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2980 | 2980 | |
| 2981 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2982 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2983 | - 'id_parent'; |
|
| 2981 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2982 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2983 | + 'id_parent'; |
|
| 2984 | 2984 | |
| 2985 | - $in = 'IN'; |
|
| 2986 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2987 | - if ($not) { |
|
| 2988 | - $where = ["'NOT'", $where]; |
|
| 2989 | - } |
|
| 2985 | + $in = 'IN'; |
|
| 2986 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2987 | + if ($not) { |
|
| 2988 | + $where = ["'NOT'", $where]; |
|
| 2989 | + } |
|
| 2990 | 2990 | |
| 2991 | - $boucle->where[] = $where; |
|
| 2991 | + $boucle->where[] = $where; |
|
| 2992 | 2992 | } |
| 2993 | 2993 | |
| 2994 | 2994 | /** |
@@ -3004,8 +3004,8 @@ discard block |
||
| 3004 | 3004 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3005 | 3005 | */ |
| 3006 | 3006 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3007 | - $not = $crit->not; |
|
| 3008 | - $crit->not = $not ? false : true; |
|
| 3009 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3010 | - $crit->not = $not; |
|
| 3007 | + $not = $crit->not; |
|
| 3008 | + $crit->not = $not ? false : true; |
|
| 3009 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3010 | + $crit->not = $not; |
|
| 3011 | 3011 | } |
@@ -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 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,42 +59,42 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | - if (strpbrk($f, ':')) { // Class::method |
|
| 72 | - $refl = new ReflectionMethod($f); |
|
| 73 | - } else { |
|
| 74 | - $refl = new ReflectionFunction($f); |
|
| 75 | - } |
|
| 76 | - $refs = $refl->getParameters(); |
|
| 77 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | - } else { |
|
| 81 | - $code = "$f($code$arglist)"; |
|
| 82 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | - } |
|
| 84 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | - if (($nb_args_f < $min_f)) { |
|
| 87 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - // le filtre n'existe pas, |
|
| 92 | - // on le notifie |
|
| 93 | - else { |
|
| 94 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | + if (strpbrk($f, ':')) { // Class::method |
|
| 72 | + $refl = new ReflectionMethod($f); |
|
| 73 | + } else { |
|
| 74 | + $refl = new ReflectionFunction($f); |
|
| 75 | + } |
|
| 76 | + $refs = $refl->getParameters(); |
|
| 77 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | + } else { |
|
| 81 | + $code = "$f($code$arglist)"; |
|
| 82 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | + } |
|
| 84 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | + if (($nb_args_f < $min_f)) { |
|
| 87 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + // le filtre n'existe pas, |
|
| 92 | + // on le notifie |
|
| 93 | + else { |
|
| 94 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $code; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Calculer un <INCLURE(xx.php)> |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | 119 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 120 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | - // si inexistant, on essaiera a l'execution |
|
| 122 | - if ($path = find_in_path($fichier)) { |
|
| 123 | - $path = "\"$path\""; |
|
| 124 | - } else { |
|
| 125 | - $path = "find_in_path(\"$fichier\")"; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 120 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | + // si inexistant, on essaiera a l'execution |
|
| 122 | + if ($path = find_in_path($fichier)) { |
|
| 123 | + $path = "\"$path\""; |
|
| 124 | + } else { |
|
| 125 | + $path = "find_in_path(\"$fichier\")"; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 140 | - // Securite |
|
| 141 | - if ( |
|
| 142 | - $p->interdire_scripts |
|
| 143 | - and $p->etoile != '**' |
|
| 144 | - ) { |
|
| 145 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | - $code = "interdire_scripts($code)"; |
|
| 147 | - } else { |
|
| 148 | - $code = interdire_scripts($r[2]); |
|
| 149 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $code; |
|
| 140 | + // Securite |
|
| 141 | + if ( |
|
| 142 | + $p->interdire_scripts |
|
| 143 | + and $p->etoile != '**' |
|
| 144 | + ) { |
|
| 145 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | + $code = "interdire_scripts($code)"; |
|
| 147 | + } else { |
|
| 148 | + $code = interdire_scripts($r[2]); |
|
| 149 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $code; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,30 +169,30 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | - $series_filtres = func_get_args(); |
|
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 175 | - |
|
| 176 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | - if ($skel['process_ins'] == 'php') { |
|
| 178 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer les couples de remplacement |
|
| 182 | - $replace = echapper_php_callback(); |
|
| 183 | - |
|
| 184 | - foreach ($series_filtres as $filtres) { |
|
| 185 | - if (count($filtres)) { |
|
| 186 | - foreach ($filtres as $filtre) { |
|
| 187 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | - $corps = $f($corps); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // restaurer les echappements |
|
| 195 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 172 | + $series_filtres = func_get_args(); |
|
| 173 | + array_shift($series_filtres);// skel |
|
| 174 | + array_shift($series_filtres);// corps |
|
| 175 | + |
|
| 176 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | + if ($skel['process_ins'] == 'php') { |
|
| 178 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer les couples de remplacement |
|
| 182 | + $replace = echapper_php_callback(); |
|
| 183 | + |
|
| 184 | + foreach ($series_filtres as $filtres) { |
|
| 185 | + if (count($filtres)) { |
|
| 186 | + foreach ($filtres as $filtre) { |
|
| 187 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | + $corps = $f($corps); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // restaurer les echappements |
|
| 195 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 212 | 212 | **/ |
| 213 | 213 | function echapper_php_callback($r = null) { |
| 214 | - static $src = []; |
|
| 215 | - static $dst = []; |
|
| 214 | + static $src = []; |
|
| 215 | + static $dst = []; |
|
| 216 | 216 | |
| 217 | - // si on recoit un tableau, on est en mode echappement |
|
| 218 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | - if (is_array($r)) { |
|
| 220 | - $dst[] = $r[0]; |
|
| 217 | + // si on recoit un tableau, on est en mode echappement |
|
| 218 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | + if (is_array($r)) { |
|
| 220 | + $dst[] = $r[0]; |
|
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | - } |
|
| 222 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | - // et on RAZ les remplacements |
|
| 227 | - $r = [$src, $dst]; |
|
| 228 | - $src = $dst = []; |
|
| 225 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | + // et on RAZ les remplacements |
|
| 227 | + $r = [$src, $dst]; |
|
| 228 | + $src = $dst = []; |
|
| 229 | 229 | |
| 230 | - return $r; |
|
| 230 | + return $r; |
|
| 231 | 231 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'".str_replace(['\\', "'"], ['\\\\', "\\'"], $texte)."'"; |
|
| 45 | 45 | |
| 46 | 46 | return $code; |
| 47 | 47 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $min_f = $refl->getNumberOfRequiredParameters(); |
| 86 | 86 | if (($nb_args_f < $min_f)) { |
| 87 | 87 | $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 88 | + erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | // le filtre n'existe pas, |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | 172 | $series_filtres = func_get_args(); |
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 173 | + array_shift($series_filtres); // skel |
|
| 174 | + array_shift($series_filtres); // corps |
|
| 175 | 175 | |
| 176 | 176 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 177 | 177 | if ($skel['process_ins'] == 'php') { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if (is_array($r)) { |
| 220 | 220 | $dst[] = $r[0]; |
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 222 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -11,129 +11,129 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = ' />'; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = ' />'; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | - } else { |
|
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | - |
|
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | + } else { |
|
| 36 | + $t = '{fond=' . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | + |
|
| 40 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = []; |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = []; |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = '#' |
|
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = '#' |
|
| 63 | + . ($boucle ? ($boucle . ':') : '') |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - list($type, $valeur) = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + list($type, $valeur) = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | - list($texte, $type) = $args[$i]; |
|
| 105 | - list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if ( |
|
| 124 | - ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | - ) { |
|
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return join('', array_map(function ($arg) { |
|
| 133 | - return reset($arg); |
|
| 134 | - }, $args)); |
|
| 103 | + for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | + list($texte, $type) = $args[$i]; |
|
| 105 | + list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if ( |
|
| 124 | + ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | + ) { |
|
| 127 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return join('', array_map(function ($arg) { |
|
| 133 | + return reset($arg); |
|
| 134 | + }, $args)); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function format_texte_html($texte) { |
| 138 | - return $texte; |
|
| 138 | + return $texte; |
|
| 139 | 139 | } |
@@ -31,36 +31,36 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | 33 | if (strpos($file, '#') === false) { |
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 34 | + $t = $file ? ('('.$file.')') : ''; |
|
| 35 | 35 | } else { |
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 36 | + $t = '{fond='.$file.'}'; |
|
| 37 | 37 | } |
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 38 | + $args = !$args ? '' : ('{'.join(', ', $args).'}'); |
|
| 39 | 39 | |
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 40 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | 44 | $contenu = []; |
| 45 | 45 | foreach ($args as $l => $t) { |
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>'.join(' ', $contenu).'</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | 53 | foreach ($args as $k => $v) { |
| 54 | 54 | $args[$k] = "$k=$v"; |
| 55 | 55 | } |
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 56 | + $args = (!$args ? '' : ('{'.join(',', $args).'}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | 62 | $nom = '#' |
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 63 | + . ($boucle ? ($boucle.':') : '') |
|
| 64 | 64 | . $nom |
| 65 | 65 | . $etoile |
| 66 | 66 | . $args |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | $critere[$k] = $crit_s; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 93 | + return (!$critere ? '' : ('{'.join(',', $critere).'}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | 97 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 98 | + . (!$args ? '' : ('{'.join(',', $args).'}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | // si un texte se termine par ( et est suivi d'un champ |
| 112 | 112 | // ou assimiles, forcer la notation pleine |
| 113 | 113 | if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 114 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 115 | 115 | } |
| 116 | 116 | } else { |
| 117 | 117 | if ($type == 'texte') { |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
| 125 | 125 | or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
| 126 | 126 | ) { |
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return join('', array_map(function ($arg) { |
|
| 132 | + return join('', array_map(function($arg) { |
|
| 133 | 133 | return reset($arg); |
| 134 | 134 | }, $args)); |
| 135 | 135 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,193 +29,193 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = []; |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ''; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = 'prive/squelettes/'; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ''; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | - _DIR_PLUGIN_DIST, |
|
| 58 | - '/' |
|
| 59 | - ) : '')); |
|
| 60 | - } |
|
| 61 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | - } |
|
| 63 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | - |
|
| 65 | - $fond = $flux['args']['fond']; |
|
| 66 | - |
|
| 67 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | - $fond = substr($fond, $prefix_length); |
|
| 69 | - $squelette = $flux['data']; |
|
| 70 | - $ext = $flux['args']['ext']; |
|
| 71 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | - if ( |
|
| 73 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | - and $dir = explode('/', $fond) |
|
| 75 | - and count($dir) == 2 // pas un sous repertoire |
|
| 76 | - and $dir = reset($dir) |
|
| 77 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | - and defined($apl_constant) |
|
| 79 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | - ) { |
|
| 82 | - $flux['data'] = $pipe; |
|
| 83 | - |
|
| 84 | - return $flux; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | - $squelette = ''; |
|
| 90 | - $echafauder = ''; |
|
| 91 | - } |
|
| 92 | - if ($prepend) { |
|
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | - if ($squelette) { |
|
| 95 | - $flux['data'] = $squelette; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // gerer les squelettes non trouves |
|
| 100 | - // -> router vers les /dist.html |
|
| 101 | - // ou scaffolding ou page automatique les contenus |
|
| 102 | - if (!$squelette) { |
|
| 103 | - // si on est sur un ?page=XX non trouve |
|
| 104 | - if ( |
|
| 105 | - (isset($flux['args']['contexte'][$page]) |
|
| 106 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | - or ($fond == 'sommaire' |
|
| 110 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | - ) { |
|
| 112 | - // si on est sur un ?page=XX non trouve |
|
| 113 | - // se brancher sur contenu/xx si il existe |
|
| 114 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | - if (!isset($disponible[$fond])) { |
|
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($disponible[$fond]) { |
|
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // echafaudage : |
|
| 125 | - // si c'est un fond de contenu d'un objet en base |
|
| 126 | - // generer un fond automatique a la volee pour les webmestres |
|
| 127 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | - $type = $flux['args']['contexte'][$page]; |
|
| 131 | - } |
|
| 132 | - if (!isset($disponible[$type])) { |
|
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | - } |
|
| 135 | - if (is_string($disponible[$type])) { |
|
| 136 | - $flux['data'] = $disponible[$type]; |
|
| 137 | - } elseif ( |
|
| 138 | - $echafauder |
|
| 139 | - and include_spip('inc/autoriser') |
|
| 140 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | - and autoriser('echafauder', $type) |
|
| 142 | - and $is = $disponible[$type] |
|
| 143 | - and is_array($is) |
|
| 144 | - ) { |
|
| 145 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | - } else { |
|
| 147 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | - $prefix_path . $prepend, |
|
| 149 | - $z_contenu, |
|
| 150 | - '404', |
|
| 151 | - $ext, |
|
| 152 | - $echafauder |
|
| 153 | - )); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | - else { |
|
| 161 | - if ( |
|
| 162 | - $dir = explode('/', $fond) |
|
| 163 | - and $dir = reset($dir) |
|
| 164 | - and $dir !== $z_contenu |
|
| 165 | - and in_array($dir, $z_blocs) |
|
| 166 | - ) { |
|
| 167 | - $type = substr($fond, strlen("$dir/")); |
|
| 168 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | - $type = $flux['args']['contexte'][$page]; |
|
| 170 | - } |
|
| 171 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | - } |
|
| 174 | - if ($type == 'page' or $disponible[$type]) { |
|
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $squelette = $flux['data']; |
|
| 180 | - } |
|
| 181 | - // layout specifiques par type et compositions : |
|
| 182 | - // body-article.html |
|
| 183 | - // body-sommaire.html |
|
| 184 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | - // meme dossier que body.html |
|
| 186 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | - if ( |
|
| 188 | - isset($flux['args']['contexte']['type-page']) |
|
| 189 | - and ( |
|
| 190 | - (isset($flux['args']['contexte']['composition']) |
|
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | - or |
|
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - $flux['data'] = $f; |
|
| 197 | - } |
|
| 198 | - } elseif ( |
|
| 199 | - $fond == 'structure' |
|
| 200 | - and z_sanitize_var_zajax() |
|
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | - ) { |
|
| 203 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | - } // chercher le fond correspondant a la composition |
|
| 205 | - elseif ( |
|
| 206 | - isset($flux['args']['contexte']['composition']) |
|
| 207 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | - and $dir = substr($fond, $prefix_length) |
|
| 209 | - and $dir = explode('/', $dir) |
|
| 210 | - and $dir = reset($dir) |
|
| 211 | - and in_array($dir, $z_blocs) |
|
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | - ) { |
|
| 214 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = []; |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ''; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = 'prive/squelettes/'; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ''; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | + _DIR_PLUGIN_DIST, |
|
| 58 | + '/' |
|
| 59 | + ) : '')); |
|
| 60 | + } |
|
| 61 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | + } |
|
| 63 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | + |
|
| 65 | + $fond = $flux['args']['fond']; |
|
| 66 | + |
|
| 67 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | + $fond = substr($fond, $prefix_length); |
|
| 69 | + $squelette = $flux['data']; |
|
| 70 | + $ext = $flux['args']['ext']; |
|
| 71 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | + if ( |
|
| 73 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | + and $dir = explode('/', $fond) |
|
| 75 | + and count($dir) == 2 // pas un sous repertoire |
|
| 76 | + and $dir = reset($dir) |
|
| 77 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | + and defined($apl_constant) |
|
| 79 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | + ) { |
|
| 82 | + $flux['data'] = $pipe; |
|
| 83 | + |
|
| 84 | + return $flux; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | + $squelette = ''; |
|
| 90 | + $echafauder = ''; |
|
| 91 | + } |
|
| 92 | + if ($prepend) { |
|
| 93 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | + if ($squelette) { |
|
| 95 | + $flux['data'] = $squelette; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // gerer les squelettes non trouves |
|
| 100 | + // -> router vers les /dist.html |
|
| 101 | + // ou scaffolding ou page automatique les contenus |
|
| 102 | + if (!$squelette) { |
|
| 103 | + // si on est sur un ?page=XX non trouve |
|
| 104 | + if ( |
|
| 105 | + (isset($flux['args']['contexte'][$page]) |
|
| 106 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | + or ($fond == 'sommaire' |
|
| 110 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | + ) { |
|
| 112 | + // si on est sur un ?page=XX non trouve |
|
| 113 | + // se brancher sur contenu/xx si il existe |
|
| 114 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | + if (!isset($disponible[$fond])) { |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($disponible[$fond]) { |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // echafaudage : |
|
| 125 | + // si c'est un fond de contenu d'un objet en base |
|
| 126 | + // generer un fond automatique a la volee pour les webmestres |
|
| 127 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | + $type = $flux['args']['contexte'][$page]; |
|
| 131 | + } |
|
| 132 | + if (!isset($disponible[$type])) { |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | + } |
|
| 135 | + if (is_string($disponible[$type])) { |
|
| 136 | + $flux['data'] = $disponible[$type]; |
|
| 137 | + } elseif ( |
|
| 138 | + $echafauder |
|
| 139 | + and include_spip('inc/autoriser') |
|
| 140 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | + and autoriser('echafauder', $type) |
|
| 142 | + and $is = $disponible[$type] |
|
| 143 | + and is_array($is) |
|
| 144 | + ) { |
|
| 145 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | + } else { |
|
| 147 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | + $prefix_path . $prepend, |
|
| 149 | + $z_contenu, |
|
| 150 | + '404', |
|
| 151 | + $ext, |
|
| 152 | + $echafauder |
|
| 153 | + )); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | + else { |
|
| 161 | + if ( |
|
| 162 | + $dir = explode('/', $fond) |
|
| 163 | + and $dir = reset($dir) |
|
| 164 | + and $dir !== $z_contenu |
|
| 165 | + and in_array($dir, $z_blocs) |
|
| 166 | + ) { |
|
| 167 | + $type = substr($fond, strlen("$dir/")); |
|
| 168 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | + $type = $flux['args']['contexte'][$page]; |
|
| 170 | + } |
|
| 171 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | + } |
|
| 174 | + if ($type == 'page' or $disponible[$type]) { |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $squelette = $flux['data']; |
|
| 180 | + } |
|
| 181 | + // layout specifiques par type et compositions : |
|
| 182 | + // body-article.html |
|
| 183 | + // body-sommaire.html |
|
| 184 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | + // meme dossier que body.html |
|
| 186 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | + if ( |
|
| 188 | + isset($flux['args']['contexte']['type-page']) |
|
| 189 | + and ( |
|
| 190 | + (isset($flux['args']['contexte']['composition']) |
|
| 191 | + and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | + or |
|
| 193 | + file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + $flux['data'] = $f; |
|
| 197 | + } |
|
| 198 | + } elseif ( |
|
| 199 | + $fond == 'structure' |
|
| 200 | + and z_sanitize_var_zajax() |
|
| 201 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | + ) { |
|
| 203 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | + } // chercher le fond correspondant a la composition |
|
| 205 | + elseif ( |
|
| 206 | + isset($flux['args']['contexte']['composition']) |
|
| 207 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | + and $dir = substr($fond, $prefix_length) |
|
| 209 | + and $dir = explode('/', $dir) |
|
| 210 | + and $dir = reset($dir) |
|
| 211 | + and in_array($dir, $z_blocs) |
|
| 212 | + and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | + ) { |
|
| 214 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return $flux; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | * @return array |
| 226 | 226 | */ |
| 227 | 227 | function z_blocs($espace_prive = false) { |
| 228 | - if ($espace_prive) { |
|
| 229 | - return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : [ |
|
| 230 | - 'contenu', |
|
| 231 | - 'navigation', |
|
| 232 | - 'extra', |
|
| 233 | - 'head', |
|
| 234 | - 'hierarchie', |
|
| 235 | - 'top' |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : ['contenu']); |
|
| 228 | + if ($espace_prive) { |
|
| 229 | + return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : [ |
|
| 230 | + 'contenu', |
|
| 231 | + 'navigation', |
|
| 232 | + 'extra', |
|
| 233 | + 'head', |
|
| 234 | + 'hierarchie', |
|
| 235 | + 'top' |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : ['contenu']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | 253 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 254 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | - return $d; |
|
| 256 | - } |
|
| 254 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | + return $d; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 258 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * `true` si on peut l'utiliser, `false` sinon. |
| 270 | 270 | **/ |
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | - if ( |
|
| 273 | - !_ZCORE_EXCLURE_PATH |
|
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | - ) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return false; |
|
| 272 | + if ( |
|
| 273 | + !_ZCORE_EXCLURE_PATH |
|
| 274 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | + ) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return false; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 297 | - if ( |
|
| 298 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | - ) { |
|
| 301 | - return substr($f, 0, -strlen(".$ext")); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 297 | + if ( |
|
| 298 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | + ) { |
|
| 301 | + return substr($f, 0, -strlen(".$ext")); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,52 +313,52 @@ discard block |
||
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | 315 | function z_echafaudable($type) { |
| 316 | - static $pages = null; |
|
| 317 | - static $echafaudable = []; |
|
| 318 | - if (isset($echafaudable[$type])) { |
|
| 319 | - return $echafaudable[$type]; |
|
| 320 | - } |
|
| 321 | - if (preg_match(',[^\w],', $type)) { |
|
| 322 | - return $echafaudable[$type] = false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if (test_espace_prive()) { |
|
| 326 | - if (!function_exists('trouver_objet_exec')) { |
|
| 327 | - include_spip('inc/pipelines_ecrire'); |
|
| 328 | - } |
|
| 329 | - if ($e = trouver_objet_exec($type)) { |
|
| 330 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | - } else { |
|
| 332 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | - if ( |
|
| 334 | - ($t = objet_type($type, false)) !== $type |
|
| 335 | - and $e = trouver_objet_exec($t) |
|
| 336 | - ) { |
|
| 337 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if (is_null($pages)) { |
|
| 342 | - $pages = []; |
|
| 343 | - $liste = lister_tables_objets_sql(); |
|
| 344 | - foreach ($liste as $t => $d) { |
|
| 345 | - if ($d['page']) { |
|
| 346 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - if (!isset($pages[$type])) { |
|
| 351 | - return $echafaudable[$type] = false; |
|
| 352 | - } |
|
| 353 | - if (count($pages[$type]) == 2) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $echafaudable[$type] = $pages[$type]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $echafaudable[$type] = false; |
|
| 316 | + static $pages = null; |
|
| 317 | + static $echafaudable = []; |
|
| 318 | + if (isset($echafaudable[$type])) { |
|
| 319 | + return $echafaudable[$type]; |
|
| 320 | + } |
|
| 321 | + if (preg_match(',[^\w],', $type)) { |
|
| 322 | + return $echafaudable[$type] = false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if (test_espace_prive()) { |
|
| 326 | + if (!function_exists('trouver_objet_exec')) { |
|
| 327 | + include_spip('inc/pipelines_ecrire'); |
|
| 328 | + } |
|
| 329 | + if ($e = trouver_objet_exec($type)) { |
|
| 330 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | + } else { |
|
| 332 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | + if ( |
|
| 334 | + ($t = objet_type($type, false)) !== $type |
|
| 335 | + and $e = trouver_objet_exec($t) |
|
| 336 | + ) { |
|
| 337 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if (is_null($pages)) { |
|
| 342 | + $pages = []; |
|
| 343 | + $liste = lister_tables_objets_sql(); |
|
| 344 | + foreach ($liste as $t => $d) { |
|
| 345 | + if ($d['page']) { |
|
| 346 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + if (!isset($pages[$type])) { |
|
| 351 | + return $echafaudable[$type] = false; |
|
| 352 | + } |
|
| 353 | + if (count($pages[$type]) == 2) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $echafaudable[$type] = $pages[$type]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $echafaudable[$type] = false; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -375,46 +375,46 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | 377 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 378 | - $scaffold = ''; |
|
| 379 | - |
|
| 380 | - // page objet ou objet_edit |
|
| 381 | - if (is_array($desc_exec)) { |
|
| 382 | - $type = $desc_exec['type']; |
|
| 383 | - $primary = $desc_exec['id_table_objet']; |
|
| 384 | - |
|
| 385 | - if ($desc_exec['edition'] === false) { |
|
| 386 | - $fond = 'objet'; |
|
| 387 | - } else { |
|
| 388 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | - $desc = $trouver_table($table_sql); |
|
| 390 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | - $fond = 'objet_edit'; |
|
| 392 | - } else { |
|
| 393 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $dir = z_blocs(test_espace_prive()); |
|
| 397 | - $dir = reset($dir); |
|
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | - } // page objets |
|
| 400 | - elseif ($type = $desc_exec and strpos($type, '/') === false) { |
|
| 401 | - $dir = z_blocs(test_espace_prive()); |
|
| 402 | - $dir = reset($dir); |
|
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | - } |
|
| 405 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | - // et objet et tire de $table |
|
| 407 | - elseif ($fond = $desc_exec) { |
|
| 408 | - $dir = md5(dirname($fond)); |
|
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | - $f = $base_dir . "$exec"; |
|
| 415 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | - |
|
| 417 | - return $f; |
|
| 378 | + $scaffold = ''; |
|
| 379 | + |
|
| 380 | + // page objet ou objet_edit |
|
| 381 | + if (is_array($desc_exec)) { |
|
| 382 | + $type = $desc_exec['type']; |
|
| 383 | + $primary = $desc_exec['id_table_objet']; |
|
| 384 | + |
|
| 385 | + if ($desc_exec['edition'] === false) { |
|
| 386 | + $fond = 'objet'; |
|
| 387 | + } else { |
|
| 388 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | + $desc = $trouver_table($table_sql); |
|
| 390 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | + $fond = 'objet_edit'; |
|
| 392 | + } else { |
|
| 393 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + $dir = z_blocs(test_espace_prive()); |
|
| 397 | + $dir = reset($dir); |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | + } // page objets |
|
| 400 | + elseif ($type = $desc_exec and strpos($type, '/') === false) { |
|
| 401 | + $dir = z_blocs(test_espace_prive()); |
|
| 402 | + $dir = reset($dir); |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | + } |
|
| 405 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | + // et objet et tire de $table |
|
| 407 | + elseif ($fond = $desc_exec) { |
|
| 408 | + $dir = md5(dirname($fond)); |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | + $f = $base_dir . "$exec"; |
|
| 415 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | + |
|
| 417 | + return $f; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return bool|string |
| 424 | 424 | */ |
| 425 | 425 | function z_sanitize_var_zajax() { |
| 426 | - $z_ajax = _request('var_zajax'); |
|
| 427 | - if (!$z_ajax) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if ( |
|
| 431 | - !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | - or !in_array($z_ajax, $z_blocs) |
|
| 433 | - ) { |
|
| 434 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | - $z_ajax = false; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $z_ajax; |
|
| 426 | + $z_ajax = _request('var_zajax'); |
|
| 427 | + if (!$z_ajax) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if ( |
|
| 431 | + !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | + or !in_array($z_ajax, $z_blocs) |
|
| 433 | + ) { |
|
| 434 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | + $z_ajax = false; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $z_ajax; |
|
| 439 | 439 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 54 | 54 | $page = _SPIP_PAGE; |
| 55 | 55 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim( |
|
| 57 | 57 | _DIR_PLUGIN_DIST, |
| 58 | 58 | '/' |
| 59 | 59 | ) : '')); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 78 | 78 | and defined($apl_constant) |
| 79 | 79 | and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | 81 | ) { |
| 82 | 82 | $flux['data'] = $pipe; |
| 83 | 83 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $echafauder = ''; |
| 91 | 91 | } |
| 92 | 92 | if ($prepend) { |
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | 94 | if ($squelette) { |
| 95 | 95 | $flux['data'] = $squelette; |
| 96 | 96 | } |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | // se brancher sur contenu/xx si il existe |
| 114 | 114 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 115 | 115 | if (!isset($disponible[$fond])) { |
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if ($disponible[$fond]) { |
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $type = $flux['args']['contexte'][$page]; |
| 131 | 131 | } |
| 132 | 132 | if (!isset($disponible[$type])) { |
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | 134 | } |
| 135 | 135 | if (is_string($disponible[$type])) { |
| 136 | 136 | $flux['data'] = $disponible[$type]; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 146 | 146 | } else { |
| 147 | 147 | $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
| 148 | - $prefix_path . $prepend, |
|
| 148 | + $prefix_path.$prepend, |
|
| 149 | 149 | $z_contenu, |
| 150 | 150 | '404', |
| 151 | 151 | $ext, |
@@ -169,10 +169,10 @@ discard block |
||
| 169 | 169 | $type = $flux['args']['contexte'][$page]; |
| 170 | 170 | } |
| 171 | 171 | if ($type !== 'page' and !isset($disponible[$type])) { |
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | 173 | } |
| 174 | 174 | if ($type == 'page' or $disponible[$type]) { |
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | isset($flux['args']['contexte']['type-page']) |
| 189 | 189 | and ( |
| 190 | 190 | (isset($flux['args']['contexte']['composition']) |
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 191 | + and file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext")) |
|
| 192 | 192 | or |
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 193 | + file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext") |
|
| 194 | 194 | ) |
| 195 | 195 | ) { |
| 196 | 196 | $flux['data'] = $f; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } elseif ( |
| 199 | 199 | $fond == 'structure' |
| 200 | 200 | and z_sanitize_var_zajax() |
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 201 | + and $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext") |
|
| 202 | 202 | ) { |
| 203 | 203 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 204 | 204 | } // chercher le fond correspondant a la composition |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | and $dir = explode('/', $dir) |
| 210 | 210 | and $dir = reset($dir) |
| 211 | 211 | and in_array($dir, $z_blocs) |
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 212 | + and $f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext") |
|
| 213 | 213 | ) { |
| 214 | 214 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 215 | 215 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | 272 | if ( |
| 273 | 273 | !_ZCORE_EXCLURE_PATH |
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 274 | + or !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette) |
|
| 275 | 275 | ) { |
| 276 | 276 | return true; |
| 277 | 277 | } |
@@ -395,23 +395,23 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | $dir = z_blocs(test_espace_prive()); |
| 397 | 397 | $dir = reset($dir); |
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper($primary).',env}>'; |
|
| 399 | 399 | } // page objets |
| 400 | 400 | elseif ($type = $desc_exec and strpos($type, '/') === false) { |
| 401 | 401 | $dir = z_blocs(test_espace_prive()); |
| 402 | 402 | $dir = reset($dir); |
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />'; |
|
| 404 | 404 | } |
| 405 | 405 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 406 | 406 | // et objet et tire de $table |
| 407 | 407 | elseif ($fond = $desc_exec) { |
| 408 | 408 | $dir = md5(dirname($fond)); |
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
| 413 | 413 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 414 | - $f = $base_dir . "$exec"; |
|
| 414 | + $f = $base_dir."$exec"; |
|
| 415 | 415 | ecrire_fichier("$f.$ext", $scaffold); |
| 416 | 416 | |
| 417 | 417 | return $f; |
@@ -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 | /** |
@@ -32,67 +32,67 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // Cas d'une page contenant du PHP : |
| 34 | 34 | if (empty($page['process_ins']) or $page['process_ins'] != 'html') { |
| 35 | - include_spip('inc/lang'); |
|
| 35 | + include_spip('inc/lang'); |
|
| 36 | 36 | |
| 37 | - // restaurer l'etat des notes avant calcul |
|
| 38 | - if ( |
|
| 39 | - isset($page['notes']) |
|
| 40 | - and $page['notes'] |
|
| 41 | - and $notes = charger_fonction('notes', 'inc', true) |
|
| 42 | - ) { |
|
| 43 | - $notes($page['notes'], 'restaurer_etat'); |
|
| 44 | - } |
|
| 45 | - ob_start(); |
|
| 46 | - if (strpos($page['texte'], '?xml') !== false) { |
|
| 47 | - $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 48 | - } |
|
| 37 | + // restaurer l'etat des notes avant calcul |
|
| 38 | + if ( |
|
| 39 | + isset($page['notes']) |
|
| 40 | + and $page['notes'] |
|
| 41 | + and $notes = charger_fonction('notes', 'inc', true) |
|
| 42 | + ) { |
|
| 43 | + $notes($page['notes'], 'restaurer_etat'); |
|
| 44 | + } |
|
| 45 | + ob_start(); |
|
| 46 | + if (strpos($page['texte'], '?xml') !== false) { |
|
| 47 | + $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - try { |
|
| 51 | - $res = eval('?' . '>' . $page['texte']); |
|
| 52 | - // error catching 5.2<=PHP<7 |
|
| 53 | - if ( |
|
| 54 | - $res === false |
|
| 55 | - and function_exists('error_get_last') |
|
| 56 | - and ($erreur = error_get_last()) |
|
| 57 | - ) { |
|
| 58 | - $code = $page['texte']; |
|
| 59 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 60 | - if (!function_exists('numerote_ligne_php')) { |
|
| 61 | - function numerote_ligne_php($match) { |
|
| 62 | - $GLOBALS['numero_ligne_php']++; |
|
| 63 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | - $code = trim(highlight_string($code, true)); |
|
| 68 | - erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 69 | - $page['texte'] = '<!-- Erreur -->'; |
|
| 70 | - } |
|
| 71 | - else { |
|
| 72 | - $page['texte'] = ob_get_contents(); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - catch (Exception $e) { |
|
| 76 | - $code = $page['texte']; |
|
| 77 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 78 | - if (!function_exists('numerote_ligne_php')) { |
|
| 79 | - function numerote_ligne_php($match) { |
|
| 80 | - $GLOBALS['numero_ligne_php']++; |
|
| 81 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | - $code = trim(highlight_string($code, true)); |
|
| 86 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 87 | - $page['texte'] = '<!-- Erreur -->'; |
|
| 88 | - } |
|
| 89 | - ob_end_clean(); |
|
| 50 | + try { |
|
| 51 | + $res = eval('?' . '>' . $page['texte']); |
|
| 52 | + // error catching 5.2<=PHP<7 |
|
| 53 | + if ( |
|
| 54 | + $res === false |
|
| 55 | + and function_exists('error_get_last') |
|
| 56 | + and ($erreur = error_get_last()) |
|
| 57 | + ) { |
|
| 58 | + $code = $page['texte']; |
|
| 59 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 60 | + if (!function_exists('numerote_ligne_php')) { |
|
| 61 | + function numerote_ligne_php($match) { |
|
| 62 | + $GLOBALS['numero_ligne_php']++; |
|
| 63 | + return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | + $code = trim(highlight_string($code, true)); |
|
| 68 | + erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 69 | + $page['texte'] = '<!-- Erreur -->'; |
|
| 70 | + } |
|
| 71 | + else { |
|
| 72 | + $page['texte'] = ob_get_contents(); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + catch (Exception $e) { |
|
| 76 | + $code = $page['texte']; |
|
| 77 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 78 | + if (!function_exists('numerote_ligne_php')) { |
|
| 79 | + function numerote_ligne_php($match) { |
|
| 80 | + $GLOBALS['numero_ligne_php']++; |
|
| 81 | + return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | + $code = trim(highlight_string($code, true)); |
|
| 86 | + erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 87 | + $page['texte'] = '<!-- Erreur -->'; |
|
| 88 | + } |
|
| 89 | + ob_end_clean(); |
|
| 90 | 90 | |
| 91 | - $page['process_ins'] = 'html'; |
|
| 91 | + $page['process_ins'] = 'html'; |
|
| 92 | 92 | |
| 93 | - if (strpos($page['texte'], '?xml') !== false) { |
|
| 94 | - $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 95 | - } |
|
| 93 | + if (strpos($page['texte'], '?xml') !== false) { |
|
| 94 | + $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | page_base_href($page['texte']); |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | ob_start(); |
| 46 | 46 | if (strpos($page['texte'], '?xml') !== false) { |
| 47 | - $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 47 | + $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | try { |
| 51 | - $res = eval('?' . '>' . $page['texte']); |
|
| 51 | + $res = eval('?'.'>'.$page['texte']); |
|
| 52 | 52 | // error catching 5.2<=PHP<7 |
| 53 | 53 | if ( |
| 54 | 54 | $res === false |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | if (!function_exists('numerote_ligne_php')) { |
| 61 | 61 | function numerote_ligne_php($match) { |
| 62 | 62 | $GLOBALS['numero_ligne_php']++; |
| 63 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 63 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/'; |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 66 | + $code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | 67 | $code = trim(highlight_string($code, true)); |
| 68 | - erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 68 | + erreur_squelette('L'.$erreur['line'].': '.$erreur['message'].'<br />'.$code, [$page['source'], '', $erreur['file'], '', $GLOBALS['spip_lang']]); |
|
| 69 | 69 | $page['texte'] = '<!-- Erreur -->'; |
| 70 | 70 | } |
| 71 | 71 | else { |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | if (!function_exists('numerote_ligne_php')) { |
| 79 | 79 | function numerote_ligne_php($match) { |
| 80 | 80 | $GLOBALS['numero_ligne_php']++; |
| 81 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 81 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/'; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 84 | + $code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | 85 | $code = trim(highlight_string($code, true)); |
| 86 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 86 | + erreur_squelette('L'.$e->getLine().': '.$e->getMessage().'<br />'.$code, [$page['source'], '', $e->getFile(), '', $GLOBALS['spip_lang']]); |
|
| 87 | 87 | $page['texte'] = '<!-- Erreur -->'; |
| 88 | 88 | } |
| 89 | 89 | ob_end_clean(); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $page['process_ins'] = 'html'; |
| 92 | 92 | |
| 93 | 93 | if (strpos($page['texte'], '?xml') !== false) { |
| 94 | - $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 94 | + $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -67,12 +67,10 @@ |
||
| 67 | 67 | $code = trim(highlight_string($code, true)); |
| 68 | 68 | erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
| 69 | 69 | $page['texte'] = '<!-- Erreur -->'; |
| 70 | - } |
|
| 71 | - else { |
|
| 70 | + } else { |
|
| 72 | 71 | $page['texte'] = ob_get_contents(); |
| 73 | 72 | } |
| 74 | - } |
|
| 75 | - catch (Exception $e) { |
|
| 73 | + } catch (Exception $e) { |
|
| 76 | 74 | $code = $page['texte']; |
| 77 | 75 | $GLOBALS['numero_ligne_php'] = 1; |
| 78 | 76 | if (!function_exists('numerote_ligne_php')) { |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $texte = $intro; |
| 85 | 85 | } else { |
| 86 | 86 | if ( |
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 87 | + strpos("\n".$texte, "\n|") === false |
|
| 88 | 88 | and strlen($texte) > 2.5 * $longueur |
| 89 | 89 | ) { |
| 90 | 90 | if (strpos($texte, '<multi') !== false) { |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | if ($pas < 1) { |
| 169 | 169 | return ''; |
| 170 | 170 | } |
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 171 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 172 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 173 | 173 | |
| 174 | 174 | // n'afficher l'ancre qu'une fois |
| 175 | 175 | if (!isset($ancres[$ancre])) { |
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='".$ancre."' class='pagination_ancre'></a>"; |
|
| 177 | 177 | } else { |
| 178 | 178 | $bloc_ancre = ''; |
| 179 | 179 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ($modele) { |
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 208 | + if (trouver_fond('pagination_'.$modele, 'modeles')) { |
|
| 209 | + $modele = '_'.$modele; |
|
| 210 | 210 | } |
| 211 | 211 | else { |
| 212 | 212 | $modele = ''; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | 293 | $objet = objet_type($type); |
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode='.sql_quote('logoon').' AND L.objet='.sql_quote($objet)); |
|
| 295 | 295 | if ($ids) { |
| 296 | 296 | $ids = array_column($ids, 'id_objet'); |
| 297 | 297 | return implode(',', $ids); |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | case 'sinum ': |
| 466 | 466 | return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
| 467 | 467 | default: |
| 468 | - return $champ . $senstri; |
|
| 468 | + return $champ.$senstri; |
|
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | |
@@ -207,8 +207,7 @@ discard block |
||
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | 208 | if (trouver_fond('pagination_' . $modele, 'modeles')) { |
| 209 | 209 | $modele = '_' . $modele; |
| 210 | - } |
|
| 211 | - else { |
|
| 210 | + } else { |
|
| 212 | 211 | $modele = ''; |
| 213 | 212 | } |
| 214 | 213 | } |
@@ -295,8 +294,7 @@ discard block |
||
| 295 | 294 | if ($ids) { |
| 296 | 295 | $ids = array_column($ids, 'id_objet'); |
| 297 | 296 | return implode(',', $ids); |
| 298 | - } |
|
| 299 | - else { |
|
| 297 | + } else { |
|
| 300 | 298 | return '0'; |
| 301 | 299 | } |
| 302 | 300 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if ( |
|
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 88 | - and strlen($texte) > 2.5 * $longueur |
|
| 89 | - ) { |
|
| 90 | - if (strpos($texte, '<multi') !== false) { |
|
| 91 | - $texte = extraire_multi($texte); |
|
| 92 | - } |
|
| 93 | - $texte = couper($texte, 2 * $longueur); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // ne pas tenir compte des notes |
|
| 98 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | - $notes('', 'empiler'); |
|
| 100 | - } |
|
| 101 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | - // dans l'introduction. |
|
| 103 | - $texte = supprime_img($texte, ''); |
|
| 104 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | - |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'depiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | - $suite = _INTRODUCTION_SUITE; |
|
| 112 | - } |
|
| 113 | - $texte = couper($texte, $longueur, $suite); |
|
| 114 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | - $texte = typo($texte, true, $connect, []); |
|
| 116 | - |
|
| 117 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | - // une introduction a tojours un <p> |
|
| 119 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if ( |
|
| 87 | + strpos("\n" . $texte, "\n|") === false |
|
| 88 | + and strlen($texte) > 2.5 * $longueur |
|
| 89 | + ) { |
|
| 90 | + if (strpos($texte, '<multi') !== false) { |
|
| 91 | + $texte = extraire_multi($texte); |
|
| 92 | + } |
|
| 93 | + $texte = couper($texte, 2 * $longueur); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // ne pas tenir compte des notes |
|
| 98 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | + $notes('', 'empiler'); |
|
| 100 | + } |
|
| 101 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | + // dans l'introduction. |
|
| 103 | + $texte = supprime_img($texte, ''); |
|
| 104 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | + |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'depiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | + $suite = _INTRODUCTION_SUITE; |
|
| 112 | + } |
|
| 113 | + $texte = couper($texte, $longueur, $suite); |
|
| 114 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | + $texte = typo($texte, true, $connect, []); |
|
| 116 | + |
|
| 117 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | + // une introduction a tojours un <p> |
|
| 119 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -155,73 +155,73 @@ discard block |
||
| 155 | 155 | * Code HTML de la pagination |
| 156 | 156 | **/ |
| 157 | 157 | function filtre_pagination_dist( |
| 158 | - $total, |
|
| 159 | - $nom, |
|
| 160 | - $position, |
|
| 161 | - $pas, |
|
| 162 | - $liste = true, |
|
| 163 | - $modele = '', |
|
| 164 | - $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + $connect = '', |
|
| 165 | + $env = [] |
|
| 166 | 166 | ) { |
| 167 | - static $ancres = []; |
|
| 168 | - if ($pas < 1) { |
|
| 169 | - return ''; |
|
| 170 | - } |
|
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | - |
|
| 174 | - // n'afficher l'ancre qu'une fois |
|
| 175 | - if (!isset($ancres[$ancre])) { |
|
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | - } else { |
|
| 178 | - $bloc_ancre = ''; |
|
| 179 | - } |
|
| 180 | - // liste = false : on ne veut que l'ancre |
|
| 181 | - if (!$liste) { |
|
| 182 | - return $ancres[$ancre]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | - $pagination = [ |
|
| 187 | - 'debut' => $debut, |
|
| 188 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | - 'total' => $total, |
|
| 190 | - 'position' => intval($position), |
|
| 191 | - 'pas' => $pas, |
|
| 192 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | - 'ancre' => $ancre, |
|
| 195 | - 'bloc_ancre' => $bloc_ancre |
|
| 196 | - ]; |
|
| 197 | - if (is_array($env)) { |
|
| 198 | - $pagination = array_merge($env, $pagination); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Pas de pagination |
|
| 202 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($modele) { |
|
| 207 | - $pagination['type_pagination'] = $modele; |
|
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - $modele = ''; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | - } |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 167 | + static $ancres = []; |
|
| 168 | + if ($pas < 1) { |
|
| 169 | + return ''; |
|
| 170 | + } |
|
| 171 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + |
|
| 174 | + // n'afficher l'ancre qu'une fois |
|
| 175 | + if (!isset($ancres[$ancre])) { |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | + } else { |
|
| 178 | + $bloc_ancre = ''; |
|
| 179 | + } |
|
| 180 | + // liste = false : on ne veut que l'ancre |
|
| 181 | + if (!$liste) { |
|
| 182 | + return $ancres[$ancre]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | + $pagination = [ |
|
| 187 | + 'debut' => $debut, |
|
| 188 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | + 'total' => $total, |
|
| 190 | + 'position' => intval($position), |
|
| 191 | + 'pas' => $pas, |
|
| 192 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | + 'ancre' => $ancre, |
|
| 195 | + 'bloc_ancre' => $bloc_ancre |
|
| 196 | + ]; |
|
| 197 | + if (is_array($env)) { |
|
| 198 | + $pagination = array_merge($env, $pagination); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Pas de pagination |
|
| 202 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($modele) { |
|
| 207 | + $pagination['type_pagination'] = $modele; |
|
| 208 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | + $modele = '_' . $modele; |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + $modele = ''; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | + } |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -240,44 +240,44 @@ discard block |
||
| 240 | 240 | * Liste (première page, dernière page). |
| 241 | 241 | **/ |
| 242 | 242 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 243 | - if ($max <= 0 or $max >= $nombre) { |
|
| 244 | - return [1, $nombre]; |
|
| 245 | - } |
|
| 246 | - if ($max <= 1) { |
|
| 247 | - return [$courante, $courante]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | - |
|
| 254 | - return [$premiere, $derniere]; |
|
| 243 | + if ($max <= 0 or $max >= $nombre) { |
|
| 244 | + return [1, $nombre]; |
|
| 245 | + } |
|
| 246 | + if ($max <= 1) { |
|
| 247 | + return [$courante, $courante]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | + |
|
| 254 | + return [$premiere, $derniere]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 258 | - if ($numero_page === 'tous') { |
|
| 259 | - return '∞'; |
|
| 260 | - } |
|
| 261 | - if ($numero_page === 'prev') { |
|
| 262 | - return '<'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'next') { |
|
| 265 | - return '>'; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - switch ($type_pagination) { |
|
| 269 | - case 'resultats': |
|
| 270 | - return $rang_item + 1; // 1 11 21 31... |
|
| 271 | - case 'naturel': |
|
| 272 | - return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | - case 'rang': |
|
| 274 | - return $rang_item; // 0 10 20 30... |
|
| 275 | - |
|
| 276 | - case 'page': |
|
| 277 | - case 'prive': |
|
| 278 | - default: |
|
| 279 | - return $numero_page; // 1 2 3 4 5... |
|
| 280 | - } |
|
| 258 | + if ($numero_page === 'tous') { |
|
| 259 | + return '∞'; |
|
| 260 | + } |
|
| 261 | + if ($numero_page === 'prev') { |
|
| 262 | + return '<'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'next') { |
|
| 265 | + return '>'; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + switch ($type_pagination) { |
|
| 269 | + case 'resultats': |
|
| 270 | + return $rang_item + 1; // 1 11 21 31... |
|
| 271 | + case 'naturel': |
|
| 272 | + return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | + case 'rang': |
|
| 274 | + return $rang_item; // 0 10 20 30... |
|
| 275 | + |
|
| 276 | + case 'page': |
|
| 277 | + case 'prive': |
|
| 278 | + default: |
|
| 279 | + return $numero_page; // 1 2 3 4 5... |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | - $objet = objet_type($type); |
|
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | - if ($ids) { |
|
| 296 | - $ids = array_column($ids, 'id_objet'); |
|
| 297 | - return implode(',', $ids); |
|
| 298 | - } |
|
| 299 | - else { |
|
| 300 | - return '0'; |
|
| 301 | - } |
|
| 293 | + $objet = objet_type($type); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | + if ($ids) { |
|
| 296 | + $ids = array_column($ids, 'id_objet'); |
|
| 297 | + return implode(',', $ids); |
|
| 298 | + } |
|
| 299 | + else { |
|
| 300 | + return '0'; |
|
| 301 | + } |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | * Code HTML des notes |
| 315 | 315 | **/ |
| 316 | 316 | function calculer_notes() { |
| 317 | - $r = ''; |
|
| 318 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | - $r = $notes([]); |
|
| 320 | - $notes('', 'depiler'); |
|
| 321 | - $notes('', 'empiler'); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $r; |
|
| 317 | + $r = ''; |
|
| 318 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | + $r = $notes([]); |
|
| 320 | + $notes('', 'depiler'); |
|
| 321 | + $notes('', 'empiler'); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $r; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | 340 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 341 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 341 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 343 | 343 | |
| 344 | - return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 344 | + return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @private |
| 359 | 359 | */ |
| 360 | 360 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 361 | - static $liens = []; |
|
| 362 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | - include_spip('action/editer_liens'); |
|
| 364 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | - } else { |
|
| 368 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | - } |
|
| 373 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | + static $liens = []; |
|
| 362 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | + include_spip('action/editer_liens'); |
|
| 364 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | + } else { |
|
| 368 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | + } |
|
| 373 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | * @return int|string |
| 385 | 385 | */ |
| 386 | 386 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 387 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | - if ( |
|
| 390 | - isset($env['form']) and $env['form'] |
|
| 391 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | - and $r = objet_associable($env['_objet_lien']) |
|
| 394 | - and list($p, $table_lien) = $r |
|
| 395 | - and lien_triables($table_lien) |
|
| 396 | - and isset($env['objet']) and $env['objet'] |
|
| 397 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | - and $objet_source |
|
| 399 | - and $id = intval($id) |
|
| 400 | - ) { |
|
| 401 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | - return ($rang ? $rang : ''); |
|
| 403 | - } |
|
| 404 | - return recuperer_numero($titre); |
|
| 387 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | + if ( |
|
| 390 | + isset($env['form']) and $env['form'] |
|
| 391 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | + and $r = objet_associable($env['_objet_lien']) |
|
| 394 | + and list($p, $table_lien) = $r |
|
| 395 | + and lien_triables($table_lien) |
|
| 396 | + and isset($env['objet']) and $env['objet'] |
|
| 397 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | + and $objet_source |
|
| 399 | + and $id = intval($id) |
|
| 400 | + ) { |
|
| 401 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | + return ($rang ? $rang : ''); |
|
| 403 | + } |
|
| 404 | + return recuperer_numero($titre); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function tri_protege_champ($t) { |
| 420 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 420 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -430,43 +430,43 @@ discard block |
||
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | 432 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 433 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | - return 'multi'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $champ = $t; |
|
| 438 | - |
|
| 439 | - $prefixe = ''; |
|
| 440 | - foreach (['num ', 'sinum '] as $p) { |
|
| 441 | - if (strpos($t, $p) === 0) { |
|
| 442 | - $champ = substr($t, strlen($p)); |
|
| 443 | - $prefixe = $p; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | - |
|
| 450 | - if (is_array($from)) { |
|
| 451 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | - foreach ($from as $idt => $table_sql) { |
|
| 453 | - if ( |
|
| 454 | - $desc = $trouver_table($table_sql) |
|
| 455 | - and isset($desc['field'][$champ]) |
|
| 456 | - ) { |
|
| 457 | - $champ = "$idt.$champ"; |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - switch ($prefixe) { |
|
| 463 | - case 'num ': |
|
| 464 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | - case 'sinum ': |
|
| 466 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | - default: |
|
| 468 | - return $champ . $senstri; |
|
| 469 | - } |
|
| 433 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | + return 'multi'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $champ = $t; |
|
| 438 | + |
|
| 439 | + $prefixe = ''; |
|
| 440 | + foreach (['num ', 'sinum '] as $p) { |
|
| 441 | + if (strpos($t, $p) === 0) { |
|
| 442 | + $champ = substr($t, strlen($p)); |
|
| 443 | + $prefixe = $p; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | + |
|
| 450 | + if (is_array($from)) { |
|
| 451 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | + foreach ($from as $idt => $table_sql) { |
|
| 453 | + if ( |
|
| 454 | + $desc = $trouver_table($table_sql) |
|
| 455 | + and isset($desc['field'][$champ]) |
|
| 456 | + ) { |
|
| 457 | + $champ = "$idt.$champ"; |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + switch ($prefixe) { |
|
| 463 | + case 'num ': |
|
| 464 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | + case 'sinum ': |
|
| 466 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | + default: |
|
| 468 | + return $champ . $senstri; |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,18 +480,18 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function tri_champ_select($t) { |
| 483 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | - $t = substr($t, 6); |
|
| 485 | - $t = preg_replace(',\s,', '', $t); |
|
| 486 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | - |
|
| 488 | - return $t; |
|
| 489 | - } |
|
| 490 | - if (trim($t) == 'hasard') { |
|
| 491 | - return 'rand() AS hasard'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return "''"; |
|
| 483 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | + $t = substr($t, 6); |
|
| 485 | + $t = preg_replace(',\s,', '', $t); |
|
| 486 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | + |
|
| 488 | + return $t; |
|
| 489 | + } |
|
| 490 | + if (trim($t) == 'hasard') { |
|
| 491 | + return 'rand() AS hasard'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return "''"; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 506 | - if (!is_array($valeurs)) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $f = sql_serveur('quote', $serveur, true); |
|
| 510 | - if (!is_string($f) or !$f) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | - |
|
| 515 | - return $valeurs; |
|
| 506 | + if (!is_array($valeurs)) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $f = sql_serveur('quote', $serveur, true); |
|
| 510 | + if (!is_string($f) or !$f) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | + |
|
| 515 | + return $valeurs; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * Valeur $defaut sinon. |
| 536 | 536 | **/ |
| 537 | 537 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 538 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | - $args[1] = $args[0]; |
|
| 543 | - $args[0] = $filtre; |
|
| 544 | - return image_graver(image_filtrer($args)); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $f = chercher_filtre($filtre); |
|
| 548 | - if (!$f) { |
|
| 549 | - return $defaut; |
|
| 550 | - } |
|
| 551 | - array_shift($args); // enlever $arg |
|
| 552 | - array_shift($args); // enlever $filtre |
|
| 553 | - array_unshift($args, $arg); // remettre $arg |
|
| 554 | - return call_user_func_array($f, $args); |
|
| 538 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | + $args[1] = $args[0]; |
|
| 543 | + $args[0] = $filtre; |
|
| 544 | + return image_graver(image_filtrer($args)); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $f = chercher_filtre($filtre); |
|
| 548 | + if (!$f) { |
|
| 549 | + return $defaut; |
|
| 550 | + } |
|
| 551 | + array_shift($args); // enlever $arg |
|
| 552 | + array_shift($args); // enlever $filtre |
|
| 553 | + array_unshift($args, $arg); // remettre $arg |
|
| 554 | + return call_user_func_array($f, $args); |
|
| 555 | 555 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $GLOBALS['contexte'] = calculer_contexte(); |
| 39 | 39 | $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond.preg_replace( |
|
| 41 | 41 | ',\.[a-zA-Z0-9]*$,', |
| 42 | 42 | '', |
| 43 | 43 | preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | if ($page === '') { |
| 139 | 139 | $erreur = _T( |
| 140 | 140 | 'info_erreur_squelette2', |
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES] |
|
| 142 | 142 | ); |
| 143 | 143 | erreur_squelette($erreur); |
| 144 | 144 | // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
| 184 | 184 | and !isset($page['entetes']['Last-Modified']) |
| 185 | 185 | ) { |
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified).' GMT'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // fermer la connexion apres les headers si requete HEAD |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | 'spip_version_code' => $GLOBALS['spip_version_code'], |
| 249 | 249 | ]; |
| 250 | 250 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | + $contexte_implicite['host'] .= '|'.$_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return $contexte_implicite; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | if (is_null($id)) { |
| 582 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + $msg = "modeles/$modele : "._T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 583 | 583 | erreur_squelette($msg); |
| 584 | 584 | // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
| 585 | 585 | $id = 0; |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
| 629 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 629 | + if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 630 | 630 | $fond = ''; |
| 631 | 631 | $class = $soustype; |
| 632 | 632 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | |
| 642 | 642 | return false; |
| 643 | 643 | } |
| 644 | - $fond = 'modeles/' . $fond; |
|
| 644 | + $fond = 'modeles/'.$fond; |
|
| 645 | 645 | // Creer le contexte |
| 646 | 646 | $contexte = $env; |
| 647 | 647 | $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | // sinon, s'il y a un lien, on l'ajoute classiquement |
| 683 | 683 | if ( |
| 684 | 684 | strstr( |
| 685 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 685 | + ' '.($classes = extraire_attribut($retour, 'class')).' ', |
|
| 686 | 686 | 'spip_lien_ok' |
| 687 | 687 | ) |
| 688 | 688 | ) { |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | ); |
| 694 | 694 | } else { |
| 695 | 695 | if ($lien) { |
| 696 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 696 | + $retour = "<a href='".$lien['href']."' class='".$lien['class']."'>".$retour.'</a>'; |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | return $page; |
| 718 | 718 | } |
| 719 | 719 | // eval $page et affecte $res |
| 720 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 720 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 721 | 721 | |
| 722 | 722 | // Lever un drapeau (global) si le fond utilise #SESSION |
| 723 | 723 | // a destination de public/parametrer |
@@ -785,16 +785,16 @@ discard block |
||
| 785 | 785 | if (($pos = strpos($head, '<head>')) !== false) { |
| 786 | 786 | $head = substr_replace($head, $base, $pos + 6, 0); |
| 787 | 787 | } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
| 788 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 788 | + $head = str_replace($r[0], $r[0].$base, $head); |
|
| 789 | 789 | } |
| 790 | - $texte = $head . substr($texte, $poshead); |
|
| 790 | + $texte = $head.substr($texte, $poshead); |
|
| 791 | 791 | } |
| 792 | 792 | if ($href_base) { |
| 793 | 793 | // gerer les ancres |
| 794 | 794 | $base = $_SERVER['REQUEST_URI']; |
| 795 | 795 | // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
| 796 | 796 | if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
| 797 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 797 | + $base = str_replace(["'", '"', '<'], ['%27', '%22', '%3C'], $base); |
|
| 798 | 798 | } |
| 799 | 799 | if (strpos($texte, "href='#") !== false) { |
| 800 | 800 | $texte = str_replace("href='#", "href='$base#", $texte); |
@@ -20,178 +20,178 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // https://code.spip.net/@assembler |
| 32 | 32 | function assembler($fond, $connect = '') { |
| 33 | 33 | |
| 34 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | - |
|
| 38 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | - ',\.[a-zA-Z0-9]*$,', |
|
| 42 | - '', |
|
| 43 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | - ); |
|
| 45 | - // Cette fonction est utilisee deux fois |
|
| 46 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | - if ($cacher) { |
|
| 50 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | - } else { |
|
| 52 | - $GLOBALS['use_cache'] = -1; |
|
| 53 | - } |
|
| 54 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | - if ($res) { |
|
| 56 | - return ['texte' => $res]; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (!$chemin_cache || !$lastmodified) { |
|
| 60 | - $lastmodified = time(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | - $calculer_page = true; |
|
| 65 | - |
|
| 66 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | - // pages sont dynamiques) |
|
| 69 | - if ( |
|
| 70 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | - and $chemin_cache |
|
| 73 | - and isset($page['entetes']) |
|
| 74 | - and isset($page['entetes']['Cache-Control']) |
|
| 75 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | - ) { |
|
| 78 | - $since = preg_replace( |
|
| 79 | - '/;.*/', |
|
| 80 | - '', |
|
| 81 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | - ); |
|
| 83 | - $since = str_replace('GMT', '', $since); |
|
| 84 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | - $page['status'] = 304; |
|
| 86 | - $headers_only = true; |
|
| 87 | - $calculer_page = false; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | - if (!$calculer_page) { |
|
| 94 | - $page['texte'] = ''; |
|
| 95 | - } else { |
|
| 96 | - // si la page est prise dans le cache |
|
| 97 | - if (!$GLOBALS['use_cache']) { |
|
| 98 | - // Informer les boutons d'admin du contexte |
|
| 99 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | - |
|
| 102 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | - // d'inversion url => objet |
|
| 104 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | - #unset($_ENV['url_propre']); |
|
| 107 | - } else { |
|
| 108 | - // Compat ascendante : |
|
| 109 | - // 1. $contexte est global |
|
| 110 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | - // et calculer la page |
|
| 112 | - if (!test_espace_prive()) { |
|
| 113 | - include_spip('inc/urls'); |
|
| 114 | - list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | - nettoyer_uri(), |
|
| 116 | - $fond, |
|
| 117 | - $GLOBALS['contexte'], |
|
| 118 | - true |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - // squelette par defaut |
|
| 122 | - if (!strlen($fond)) { |
|
| 123 | - $fond = 'sommaire'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // produire la page : peut mettre a jour $lastmodified |
|
| 127 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | - $page = $produire_page( |
|
| 129 | - $fond, |
|
| 130 | - $GLOBALS['contexte'], |
|
| 131 | - $GLOBALS['use_cache'], |
|
| 132 | - $chemin_cache, |
|
| 133 | - null, |
|
| 134 | - $page, |
|
| 135 | - $lastmodified, |
|
| 136 | - $connect |
|
| 137 | - ); |
|
| 138 | - if ($page === '') { |
|
| 139 | - $erreur = _T( |
|
| 140 | - 'info_erreur_squelette2', |
|
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | - ); |
|
| 143 | - erreur_squelette($erreur); |
|
| 144 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($page and $chemin_cache) { |
|
| 150 | - $page['cache'] = $chemin_cache; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - auto_content_type($page); |
|
| 154 | - |
|
| 155 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | - |
|
| 157 | - // Definir les entetes si ce n'est fait |
|
| 158 | - if (!$GLOBALS['flag_preserver']) { |
|
| 159 | - if ($GLOBALS['flag_ob']) { |
|
| 160 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | - if ( |
|
| 162 | - trim($page['texte']) === '' |
|
| 163 | - and _VAR_MODE != 'debug' |
|
| 164 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | - ) { |
|
| 166 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | - } |
|
| 169 | - // pas de cache client en mode 'observation' |
|
| 170 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Entete Last-Modified: |
|
| 179 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | - if ( |
|
| 182 | - $lastmodified |
|
| 183 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | - and !isset($page['entetes']['Last-Modified']) |
|
| 185 | - ) { |
|
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // fermer la connexion apres les headers si requete HEAD |
|
| 190 | - if ($headers_only) { |
|
| 191 | - $page['entetes']['Connection'] = 'close'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 34 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | + |
|
| 38 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | + ',\.[a-zA-Z0-9]*$,', |
|
| 42 | + '', |
|
| 43 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | + ); |
|
| 45 | + // Cette fonction est utilisee deux fois |
|
| 46 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | + if ($cacher) { |
|
| 50 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | + } else { |
|
| 52 | + $GLOBALS['use_cache'] = -1; |
|
| 53 | + } |
|
| 54 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | + if ($res) { |
|
| 56 | + return ['texte' => $res]; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (!$chemin_cache || !$lastmodified) { |
|
| 60 | + $lastmodified = time(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | + $calculer_page = true; |
|
| 65 | + |
|
| 66 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | + // pages sont dynamiques) |
|
| 69 | + if ( |
|
| 70 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | + and $chemin_cache |
|
| 73 | + and isset($page['entetes']) |
|
| 74 | + and isset($page['entetes']['Cache-Control']) |
|
| 75 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | + ) { |
|
| 78 | + $since = preg_replace( |
|
| 79 | + '/;.*/', |
|
| 80 | + '', |
|
| 81 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | + ); |
|
| 83 | + $since = str_replace('GMT', '', $since); |
|
| 84 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | + $page['status'] = 304; |
|
| 86 | + $headers_only = true; |
|
| 87 | + $calculer_page = false; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | + if (!$calculer_page) { |
|
| 94 | + $page['texte'] = ''; |
|
| 95 | + } else { |
|
| 96 | + // si la page est prise dans le cache |
|
| 97 | + if (!$GLOBALS['use_cache']) { |
|
| 98 | + // Informer les boutons d'admin du contexte |
|
| 99 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | + |
|
| 102 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | + // d'inversion url => objet |
|
| 104 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | + #unset($_ENV['url_propre']); |
|
| 107 | + } else { |
|
| 108 | + // Compat ascendante : |
|
| 109 | + // 1. $contexte est global |
|
| 110 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | + // et calculer la page |
|
| 112 | + if (!test_espace_prive()) { |
|
| 113 | + include_spip('inc/urls'); |
|
| 114 | + list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | + nettoyer_uri(), |
|
| 116 | + $fond, |
|
| 117 | + $GLOBALS['contexte'], |
|
| 118 | + true |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + // squelette par defaut |
|
| 122 | + if (!strlen($fond)) { |
|
| 123 | + $fond = 'sommaire'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // produire la page : peut mettre a jour $lastmodified |
|
| 127 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | + $page = $produire_page( |
|
| 129 | + $fond, |
|
| 130 | + $GLOBALS['contexte'], |
|
| 131 | + $GLOBALS['use_cache'], |
|
| 132 | + $chemin_cache, |
|
| 133 | + null, |
|
| 134 | + $page, |
|
| 135 | + $lastmodified, |
|
| 136 | + $connect |
|
| 137 | + ); |
|
| 138 | + if ($page === '') { |
|
| 139 | + $erreur = _T( |
|
| 140 | + 'info_erreur_squelette2', |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | + ); |
|
| 143 | + erreur_squelette($erreur); |
|
| 144 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($page and $chemin_cache) { |
|
| 150 | + $page['cache'] = $chemin_cache; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + auto_content_type($page); |
|
| 154 | + |
|
| 155 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | + |
|
| 157 | + // Definir les entetes si ce n'est fait |
|
| 158 | + if (!$GLOBALS['flag_preserver']) { |
|
| 159 | + if ($GLOBALS['flag_ob']) { |
|
| 160 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | + if ( |
|
| 162 | + trim($page['texte']) === '' |
|
| 163 | + and _VAR_MODE != 'debug' |
|
| 164 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | + ) { |
|
| 166 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | + } |
|
| 169 | + // pas de cache client en mode 'observation' |
|
| 170 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Entete Last-Modified: |
|
| 179 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | + if ( |
|
| 182 | + $lastmodified |
|
| 183 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | + and !isset($page['entetes']['Last-Modified']) |
|
| 185 | + ) { |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // fermer la connexion apres les headers si requete HEAD |
|
| 190 | + if ($headers_only) { |
|
| 191 | + $page['entetes']['Connection'] = 'close'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | function calculer_contexte() { |
| 212 | 212 | |
| 213 | - $contexte = []; |
|
| 214 | - foreach ($_GET as $var => $val) { |
|
| 215 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | - $contexte[$var] = $val; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - foreach ($_POST as $var => $val) { |
|
| 220 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | - $contexte[$var] = $val; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $contexte; |
|
| 213 | + $contexte = []; |
|
| 214 | + foreach ($_GET as $var => $val) { |
|
| 215 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | + $contexte[$var] = $val; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + foreach ($_POST as $var => $val) { |
|
| 220 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | + $contexte[$var] = $val; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $contexte; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | 235 | function calculer_contexte_implicite() { |
| 236 | - static $notes = null; |
|
| 237 | - if (is_null($notes)) { |
|
| 238 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | - } |
|
| 240 | - $contexte_implicite = [ |
|
| 241 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | - 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | - 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | - 'espace' => test_espace_prive(), |
|
| 245 | - 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | - 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | - ]; |
|
| 250 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $contexte_implicite; |
|
| 236 | + static $notes = null; |
|
| 237 | + if (is_null($notes)) { |
|
| 238 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | + } |
|
| 240 | + $contexte_implicite = [ |
|
| 241 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | + 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | + 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | + 'espace' => test_espace_prive(), |
|
| 245 | + 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | + 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | + ]; |
|
| 250 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $contexte_implicite; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // |
@@ -261,52 +261,52 @@ discard block |
||
| 261 | 261 | // https://code.spip.net/@auto_content_type |
| 262 | 262 | function auto_content_type($page) { |
| 263 | 263 | |
| 264 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | - $page['texte'] |
|
| 268 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | - } |
|
| 264 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | + $page['texte'] |
|
| 268 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // https://code.spip.net/@inclure_page |
| 273 | 273 | function inclure_page($fond, $contexte, $connect = '') { |
| 274 | - static $cacher, $produire_page; |
|
| 275 | - |
|
| 276 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | - // (cette precaution n'est probablement plus utile) |
|
| 279 | - unset($contexte['fond']); |
|
| 280 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | - if (is_null($cacher)) { |
|
| 283 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | - } |
|
| 285 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | - if ($cacher) { |
|
| 288 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | - } else { |
|
| 290 | - $use_cache = -1; |
|
| 291 | - } |
|
| 292 | - // $res = message d'erreur : on sort de la |
|
| 293 | - if ($res) { |
|
| 294 | - return ['texte' => $res]; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | - // produire la page : peut mettre a jour $lastinclude |
|
| 299 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | - if ($use_cache) { |
|
| 301 | - if (is_null($produire_page)) { |
|
| 302 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | - } |
|
| 304 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | - $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 274 | + static $cacher, $produire_page; |
|
| 275 | + |
|
| 276 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | + // (cette precaution n'est probablement plus utile) |
|
| 279 | + unset($contexte['fond']); |
|
| 280 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | + if (is_null($cacher)) { |
|
| 283 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | + } |
|
| 285 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | + if ($cacher) { |
|
| 288 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | + } else { |
|
| 290 | + $use_cache = -1; |
|
| 291 | + } |
|
| 292 | + // $res = message d'erreur : on sort de la |
|
| 293 | + if ($res) { |
|
| 294 | + return ['texte' => $res]; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | + // produire la page : peut mettre a jour $lastinclude |
|
| 299 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | + if ($use_cache) { |
|
| 301 | + if (is_null($produire_page)) { |
|
| 302 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | + } |
|
| 304 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | + $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | + |
|
| 309 | + return $page; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -324,41 +324,41 @@ discard block |
||
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | 326 | function public_produire_page_dist( |
| 327 | - $fond, |
|
| 328 | - $contexte, |
|
| 329 | - $use_cache, |
|
| 330 | - $chemin_cache, |
|
| 331 | - $contexte_cache, |
|
| 332 | - &$page, |
|
| 333 | - &$lastinclude, |
|
| 334 | - $connect = '' |
|
| 327 | + $fond, |
|
| 328 | + $contexte, |
|
| 329 | + $use_cache, |
|
| 330 | + $chemin_cache, |
|
| 331 | + $contexte_cache, |
|
| 332 | + &$page, |
|
| 333 | + &$lastinclude, |
|
| 334 | + $connect = '' |
|
| 335 | 335 | ) { |
| 336 | - static $parametrer, $cacher; |
|
| 337 | - if (!$parametrer) { |
|
| 338 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | - } |
|
| 340 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | - // et on l'enregistre sur le disque |
|
| 342 | - if ( |
|
| 343 | - $chemin_cache |
|
| 344 | - and $use_cache > -1 |
|
| 345 | - and is_array($page) |
|
| 346 | - and count($page) |
|
| 347 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | - ) { |
|
| 350 | - if (is_null($cacher)) { |
|
| 351 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | - } |
|
| 353 | - $lastinclude = time(); |
|
| 354 | - if ($cacher) { |
|
| 355 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | - } else { |
|
| 357 | - $use_cache = -1; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $page; |
|
| 336 | + static $parametrer, $cacher; |
|
| 337 | + if (!$parametrer) { |
|
| 338 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | + } |
|
| 340 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | + // et on l'enregistre sur le disque |
|
| 342 | + if ( |
|
| 343 | + $chemin_cache |
|
| 344 | + and $use_cache > -1 |
|
| 345 | + and is_array($page) |
|
| 346 | + and count($page) |
|
| 347 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | + ) { |
|
| 350 | + if (is_null($cacher)) { |
|
| 351 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | + } |
|
| 353 | + $lastinclude = time(); |
|
| 354 | + if ($cacher) { |
|
| 355 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | + } else { |
|
| 357 | + $use_cache = -1; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $page; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Fonction inseree par le compilateur dans le code compile. |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | // 4: langue |
| 373 | 373 | |
| 374 | 374 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 375 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | - |
|
| 377 | - if (!is_array($contexte_exec)) { |
|
| 378 | - echo $contexte_exec; |
|
| 379 | - } // message d'erreur etc |
|
| 380 | - else { |
|
| 381 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | - } |
|
| 375 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | + |
|
| 377 | + if (!is_array($contexte_exec)) { |
|
| 378 | + echo $contexte_exec; |
|
| 379 | + } // message d'erreur etc |
|
| 380 | + else { |
|
| 381 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -394,100 +394,100 @@ discard block |
||
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | 396 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 397 | - if (is_array($texte)) { |
|
| 398 | - list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | - |
|
| 400 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | - $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | - $GLOBALS['delais'] = $delainc; |
|
| 403 | - |
|
| 404 | - $page = recuperer_fond( |
|
| 405 | - $fond, |
|
| 406 | - $contexte_inclus, |
|
| 407 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | - ); |
|
| 409 | - |
|
| 410 | - $texte = $page['texte']; |
|
| 411 | - |
|
| 412 | - $GLOBALS['delais'] = $d; |
|
| 413 | - // Faire remonter les entetes |
|
| 414 | - if (is_array($page['entetes'])) { |
|
| 415 | - // mais pas toutes |
|
| 416 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | - unset($page['entetes']['Content-Type']); |
|
| 418 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | - $GLOBALS['page']['entetes'] = []; |
|
| 421 | - } |
|
| 422 | - $GLOBALS['page']['entetes'] = |
|
| 423 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | - if ( |
|
| 428 | - isset($page['contexte']['_pipelines']) |
|
| 429 | - and is_array($page['contexte']['_pipelines']) |
|
| 430 | - and count($page['contexte']['_pipelines']) |
|
| 431 | - ) { |
|
| 432 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | - $args['contexte'] = $page['contexte']; |
|
| 434 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | - $texte = pipeline( |
|
| 436 | - $pipe, |
|
| 437 | - [ |
|
| 438 | - 'data' => $texte, |
|
| 439 | - 'args' => $args |
|
| 440 | - ], |
|
| 441 | - false |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | - $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | - } |
|
| 452 | - if ($echo) { |
|
| 453 | - echo $texte; |
|
| 454 | - } else { |
|
| 455 | - return $texte; |
|
| 456 | - } |
|
| 397 | + if (is_array($texte)) { |
|
| 398 | + list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | + |
|
| 400 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | + $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | + $GLOBALS['delais'] = $delainc; |
|
| 403 | + |
|
| 404 | + $page = recuperer_fond( |
|
| 405 | + $fond, |
|
| 406 | + $contexte_inclus, |
|
| 407 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | + ); |
|
| 409 | + |
|
| 410 | + $texte = $page['texte']; |
|
| 411 | + |
|
| 412 | + $GLOBALS['delais'] = $d; |
|
| 413 | + // Faire remonter les entetes |
|
| 414 | + if (is_array($page['entetes'])) { |
|
| 415 | + // mais pas toutes |
|
| 416 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | + unset($page['entetes']['Content-Type']); |
|
| 418 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | + $GLOBALS['page']['entetes'] = []; |
|
| 421 | + } |
|
| 422 | + $GLOBALS['page']['entetes'] = |
|
| 423 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | + if ( |
|
| 428 | + isset($page['contexte']['_pipelines']) |
|
| 429 | + and is_array($page['contexte']['_pipelines']) |
|
| 430 | + and count($page['contexte']['_pipelines']) |
|
| 431 | + ) { |
|
| 432 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | + $args['contexte'] = $page['contexte']; |
|
| 434 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | + $texte = pipeline( |
|
| 436 | + $pipe, |
|
| 437 | + [ |
|
| 438 | + 'data' => $texte, |
|
| 439 | + 'args' => $args |
|
| 440 | + ], |
|
| 441 | + false |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | + $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | + } |
|
| 452 | + if ($echo) { |
|
| 453 | + echo $texte; |
|
| 454 | + } else { |
|
| 455 | + return $texte; |
|
| 456 | + } |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // https://code.spip.net/@message_page_indisponible |
| 460 | 460 | function message_page_indisponible($page, $contexte) { |
| 461 | - static $deja = false; |
|
| 462 | - if ($deja) { |
|
| 463 | - return 'erreur'; |
|
| 464 | - } |
|
| 465 | - $codes = [ |
|
| 466 | - '404' => '404 Not Found', |
|
| 467 | - '503' => '503 Service Unavailable', |
|
| 468 | - ]; |
|
| 469 | - |
|
| 470 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | - if (!isset($contexte['lang'])) { |
|
| 474 | - include_spip('inc/lang'); |
|
| 475 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $deja = true; |
|
| 479 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | - // ex restriction d'acces => 401 |
|
| 481 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | - |
|
| 483 | - // produire la page d'erreur |
|
| 484 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | - if (!$page) { |
|
| 486 | - $page = inclure_page('404', $contexte); |
|
| 487 | - } |
|
| 488 | - $page['status'] = $contexte['status']; |
|
| 489 | - |
|
| 490 | - return $page; |
|
| 461 | + static $deja = false; |
|
| 462 | + if ($deja) { |
|
| 463 | + return 'erreur'; |
|
| 464 | + } |
|
| 465 | + $codes = [ |
|
| 466 | + '404' => '404 Not Found', |
|
| 467 | + '503' => '503 Service Unavailable', |
|
| 468 | + ]; |
|
| 469 | + |
|
| 470 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | + if (!isset($contexte['lang'])) { |
|
| 474 | + include_spip('inc/lang'); |
|
| 475 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $deja = true; |
|
| 479 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | + // ex restriction d'acces => 401 |
|
| 481 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | + |
|
| 483 | + // produire la page d'erreur |
|
| 484 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | + if (!$page) { |
|
| 486 | + $page = inclure_page('404', $contexte); |
|
| 487 | + } |
|
| 488 | + $page['status'] = $contexte['status']; |
|
| 489 | + |
|
| 490 | + return $page; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
@@ -499,45 +499,45 @@ discard block |
||
| 499 | 499 | * @return mixed |
| 500 | 500 | */ |
| 501 | 501 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 502 | - static $balise_dyn_appellee_par_modele = null; |
|
| 503 | - switch ($operation) { |
|
| 504 | - case 'read': |
|
| 505 | - return $balise_dyn_appellee_par_modele; |
|
| 506 | - case 'reset': |
|
| 507 | - $balise_dyn_appellee_par_modele = null; |
|
| 508 | - return null; |
|
| 509 | - case 'set': |
|
| 510 | - default: |
|
| 511 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | - return $arg; |
|
| 513 | - } |
|
| 502 | + static $balise_dyn_appellee_par_modele = null; |
|
| 503 | + switch ($operation) { |
|
| 504 | + case 'read': |
|
| 505 | + return $balise_dyn_appellee_par_modele; |
|
| 506 | + case 'reset': |
|
| 507 | + $balise_dyn_appellee_par_modele = null; |
|
| 508 | + return null; |
|
| 509 | + case 'set': |
|
| 510 | + default: |
|
| 511 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | + return $arg; |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // temporairement ici : a mettre dans le futur inc/modeles |
| 517 | 517 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 518 | 518 | // https://code.spip.net/@creer_contexte_de_modele |
| 519 | 519 | function creer_contexte_de_modele($args) { |
| 520 | - $contexte = []; |
|
| 521 | - foreach ($args as $var => $val) { |
|
| 522 | - if (is_int($var)) { // argument pas formate |
|
| 523 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | - $var = 'align'; |
|
| 525 | - $contexte[$var] = $val; |
|
| 526 | - } else { |
|
| 527 | - $args = explode('=', $val); |
|
| 528 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | - } else // notation abregee |
|
| 531 | - { |
|
| 532 | - $contexte[trim($val)] = trim($val); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } else { |
|
| 536 | - $contexte[$var] = $val; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $contexte; |
|
| 520 | + $contexte = []; |
|
| 521 | + foreach ($args as $var => $val) { |
|
| 522 | + if (is_int($var)) { // argument pas formate |
|
| 523 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | + $var = 'align'; |
|
| 525 | + $contexte[$var] = $val; |
|
| 526 | + } else { |
|
| 527 | + $args = explode('=', $val); |
|
| 528 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | + } else // notation abregee |
|
| 531 | + { |
|
| 532 | + $contexte[trim($val)] = trim($val); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } else { |
|
| 536 | + $contexte[$var] = $val; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $contexte; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,43 +552,43 @@ discard block |
||
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | 554 | function styliser_modele($modele, $id, $contexte = null) { |
| 555 | - static $styliseurs = null; |
|
| 556 | - if (is_null($styliseurs)) { |
|
| 557 | - $tables_objet = lister_tables_objets_sql(); |
|
| 558 | - foreach ($tables_objet as $table => $desc) { |
|
| 559 | - if ( |
|
| 560 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | - and function_exists($desc['modeles_styliser']) |
|
| 563 | - ) { |
|
| 564 | - $primary = id_table_objet($table); |
|
| 565 | - foreach ($desc['modeles'] as $m) { |
|
| 566 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - if (isset($styliseurs[$modele])) { |
|
| 573 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | - $primary = $styliseurs[$modele]['primary']; |
|
| 575 | - if (is_null($id) and $contexte) { |
|
| 576 | - if (isset($contexte['id'])) { |
|
| 577 | - $id = $contexte['id']; |
|
| 578 | - } elseif (isset($contexte[$primary])) { |
|
| 579 | - $id = $contexte[$primary]; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - if (is_null($id)) { |
|
| 583 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | - erreur_squelette($msg); |
|
| 585 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | - $id = 0; |
|
| 587 | - } |
|
| 588 | - $modele = $styliseur($modele, $id); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $modele; |
|
| 555 | + static $styliseurs = null; |
|
| 556 | + if (is_null($styliseurs)) { |
|
| 557 | + $tables_objet = lister_tables_objets_sql(); |
|
| 558 | + foreach ($tables_objet as $table => $desc) { |
|
| 559 | + if ( |
|
| 560 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | + and function_exists($desc['modeles_styliser']) |
|
| 563 | + ) { |
|
| 564 | + $primary = id_table_objet($table); |
|
| 565 | + foreach ($desc['modeles'] as $m) { |
|
| 566 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + if (isset($styliseurs[$modele])) { |
|
| 573 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | + $primary = $styliseurs[$modele]['primary']; |
|
| 575 | + if (is_null($id) and $contexte) { |
|
| 576 | + if (isset($contexte['id'])) { |
|
| 577 | + $id = $contexte['id']; |
|
| 578 | + } elseif (isset($contexte[$primary])) { |
|
| 579 | + $id = $contexte[$primary]; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + if (is_null($id)) { |
|
| 583 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | + erreur_squelette($msg); |
|
| 585 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | + $id = 0; |
|
| 587 | + } |
|
| 588 | + $modele = $styliseur($modele, $id); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $modele; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -607,102 +607,102 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | function inclure_modele($type, $id, $params, $lien, $connect = '', $env = []) { |
| 609 | 609 | |
| 610 | - static $compteur; |
|
| 611 | - if (++$compteur > 10) { |
|
| 612 | - return ''; |
|
| 613 | - } # ne pas boucler indefiniment |
|
| 614 | - |
|
| 615 | - $type = strtolower($type); |
|
| 616 | - $type = styliser_modele($type, $id); |
|
| 617 | - |
|
| 618 | - $fond = $class = ''; |
|
| 619 | - |
|
| 620 | - $params = array_filter(explode('|', $params)); |
|
| 621 | - if ($params) { |
|
| 622 | - $soustype = current($params); |
|
| 623 | - $soustype = strtolower(trim($soustype)); |
|
| 624 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | - $soustype = next($params); |
|
| 626 | - $soustype = strtolower($soustype); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | - $fond = ''; |
|
| 632 | - $class = $soustype; |
|
| 633 | - } |
|
| 634 | - // enlever le sous type des params |
|
| 635 | - $params = array_diff($params, [$soustype]); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | - |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - $fond = 'modeles/' . $fond; |
|
| 646 | - // Creer le contexte |
|
| 647 | - $contexte = $env; |
|
| 648 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | - |
|
| 650 | - // Le numero du modele est mis dans l'environnement |
|
| 651 | - // d'une part sous l'identifiant "id" |
|
| 652 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | - // par la fonction id_table_objet, |
|
| 654 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | - $_id = id_table_objet($type); |
|
| 656 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | - |
|
| 658 | - if (isset($class)) { |
|
| 659 | - $contexte['class'] = $class; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | - if ($lien) { |
|
| 664 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | - $contexte['lien_class'] = $lien['class']; |
|
| 667 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | - $contexte['lien_title'] = $lien['title']; |
|
| 669 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - // Traiter les parametres |
|
| 673 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | - $arg_list = creer_contexte_de_modele($params); |
|
| 675 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | - $contexte = array_merge($contexte, $arg_list); |
|
| 677 | - |
|
| 678 | - // Appliquer le modele avec le contexte |
|
| 679 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | - |
|
| 681 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | - if ( |
|
| 685 | - strstr( |
|
| 686 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | - 'spip_lien_ok' |
|
| 688 | - ) |
|
| 689 | - ) { |
|
| 690 | - $retour = inserer_attribut( |
|
| 691 | - $retour, |
|
| 692 | - 'class', |
|
| 693 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | - ); |
|
| 695 | - } else { |
|
| 696 | - if ($lien) { |
|
| 697 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - $compteur--; |
|
| 702 | - |
|
| 703 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | - : $retour; |
|
| 610 | + static $compteur; |
|
| 611 | + if (++$compteur > 10) { |
|
| 612 | + return ''; |
|
| 613 | + } # ne pas boucler indefiniment |
|
| 614 | + |
|
| 615 | + $type = strtolower($type); |
|
| 616 | + $type = styliser_modele($type, $id); |
|
| 617 | + |
|
| 618 | + $fond = $class = ''; |
|
| 619 | + |
|
| 620 | + $params = array_filter(explode('|', $params)); |
|
| 621 | + if ($params) { |
|
| 622 | + $soustype = current($params); |
|
| 623 | + $soustype = strtolower(trim($soustype)); |
|
| 624 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | + $soustype = next($params); |
|
| 626 | + $soustype = strtolower($soustype); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | + $fond = ''; |
|
| 632 | + $class = $soustype; |
|
| 633 | + } |
|
| 634 | + // enlever le sous type des params |
|
| 635 | + $params = array_diff($params, [$soustype]); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | + |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + $fond = 'modeles/' . $fond; |
|
| 646 | + // Creer le contexte |
|
| 647 | + $contexte = $env; |
|
| 648 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | + |
|
| 650 | + // Le numero du modele est mis dans l'environnement |
|
| 651 | + // d'une part sous l'identifiant "id" |
|
| 652 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | + // par la fonction id_table_objet, |
|
| 654 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | + $_id = id_table_objet($type); |
|
| 656 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | + |
|
| 658 | + if (isset($class)) { |
|
| 659 | + $contexte['class'] = $class; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | + if ($lien) { |
|
| 664 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | + $contexte['lien_class'] = $lien['class']; |
|
| 667 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | + $contexte['lien_title'] = $lien['title']; |
|
| 669 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + // Traiter les parametres |
|
| 673 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | + $arg_list = creer_contexte_de_modele($params); |
|
| 675 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | + $contexte = array_merge($contexte, $arg_list); |
|
| 677 | + |
|
| 678 | + // Appliquer le modele avec le contexte |
|
| 679 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | + |
|
| 681 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | + if ( |
|
| 685 | + strstr( |
|
| 686 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | + 'spip_lien_ok' |
|
| 688 | + ) |
|
| 689 | + ) { |
|
| 690 | + $retour = inserer_attribut( |
|
| 691 | + $retour, |
|
| 692 | + 'class', |
|
| 693 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | + ); |
|
| 695 | + } else { |
|
| 696 | + if ($lien) { |
|
| 697 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + $compteur--; |
|
| 702 | + |
|
| 703 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | + : $retour; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -712,99 +712,99 @@ discard block |
||
| 712 | 712 | // https://code.spip.net/@evaluer_fond |
| 713 | 713 | function evaluer_fond($fond, $contexte = [], $connect = null) { |
| 714 | 714 | |
| 715 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | - |
|
| 717 | - if (!$page) { |
|
| 718 | - return $page; |
|
| 719 | - } |
|
| 720 | - // eval $page et affecte $res |
|
| 721 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | - |
|
| 723 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | - // a destination de public/parametrer |
|
| 725 | - // pour remonter vers les inclusions appelantes |
|
| 726 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | - if ( |
|
| 729 | - isset($page['invalideurs']) |
|
| 730 | - and isset($page['invalideurs']['session']) |
|
| 731 | - ) { |
|
| 732 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $page; |
|
| 715 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | + |
|
| 717 | + if (!$page) { |
|
| 718 | + return $page; |
|
| 719 | + } |
|
| 720 | + // eval $page et affecte $res |
|
| 721 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | + |
|
| 723 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | + // a destination de public/parametrer |
|
| 725 | + // pour remonter vers les inclusions appelantes |
|
| 726 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | + if ( |
|
| 729 | + isset($page['invalideurs']) |
|
| 730 | + and isset($page['invalideurs']['session']) |
|
| 731 | + ) { |
|
| 732 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $page; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | // https://code.spip.net/@page_base_href |
| 740 | 740 | function page_base_href(&$texte) { |
| 741 | - static $set_html_base = null; |
|
| 742 | - if (is_null($set_html_base)) { |
|
| 743 | - if (!defined('_SET_HTML_BASE')) { |
|
| 744 | - // si la profondeur est superieure a 1 |
|
| 745 | - // est que ce n'est pas une url page ni une url action |
|
| 746 | - // activer par defaut |
|
| 747 | - $set_html_base = (( |
|
| 748 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | - and !_request('action')) ? true : false); |
|
| 751 | - } else { |
|
| 752 | - $set_html_base = _SET_HTML_BASE; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ( |
|
| 757 | - $set_html_base |
|
| 758 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | - ) { |
|
| 762 | - $head = substr($texte, 0, $poshead); |
|
| 763 | - $insert = false; |
|
| 764 | - $href_base = false; |
|
| 765 | - if (strpos($head, '<base') === false) { |
|
| 766 | - $insert = true; |
|
| 767 | - } else { |
|
| 768 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | - // sinon juste re-ecrire les ancres si besoin |
|
| 770 | - $insert = true; |
|
| 771 | - include_spip('inc/filtres'); |
|
| 772 | - $bases = extraire_balises($head, 'base'); |
|
| 773 | - foreach ($bases as $base) { |
|
| 774 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | - $insert = false; |
|
| 776 | - break; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if ($insert) { |
|
| 782 | - include_spip('inc/filtres_mini'); |
|
| 783 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | - $href_base = url_absolue('./'); |
|
| 785 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | - } |
|
| 791 | - $texte = $head . substr($texte, $poshead); |
|
| 792 | - } |
|
| 793 | - if ($href_base) { |
|
| 794 | - // gerer les ancres |
|
| 795 | - $base = $_SERVER['REQUEST_URI']; |
|
| 796 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | - } |
|
| 800 | - if (strpos($texte, "href='#") !== false) { |
|
| 801 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | - } |
|
| 803 | - if (strpos($texte, 'href="#') !== false) { |
|
| 804 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 741 | + static $set_html_base = null; |
|
| 742 | + if (is_null($set_html_base)) { |
|
| 743 | + if (!defined('_SET_HTML_BASE')) { |
|
| 744 | + // si la profondeur est superieure a 1 |
|
| 745 | + // est que ce n'est pas une url page ni une url action |
|
| 746 | + // activer par defaut |
|
| 747 | + $set_html_base = (( |
|
| 748 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | + and !_request('action')) ? true : false); |
|
| 751 | + } else { |
|
| 752 | + $set_html_base = _SET_HTML_BASE; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ( |
|
| 757 | + $set_html_base |
|
| 758 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | + ) { |
|
| 762 | + $head = substr($texte, 0, $poshead); |
|
| 763 | + $insert = false; |
|
| 764 | + $href_base = false; |
|
| 765 | + if (strpos($head, '<base') === false) { |
|
| 766 | + $insert = true; |
|
| 767 | + } else { |
|
| 768 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | + // sinon juste re-ecrire les ancres si besoin |
|
| 770 | + $insert = true; |
|
| 771 | + include_spip('inc/filtres'); |
|
| 772 | + $bases = extraire_balises($head, 'base'); |
|
| 773 | + foreach ($bases as $base) { |
|
| 774 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | + $insert = false; |
|
| 776 | + break; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if ($insert) { |
|
| 782 | + include_spip('inc/filtres_mini'); |
|
| 783 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | + $href_base = url_absolue('./'); |
|
| 785 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | + } |
|
| 791 | + $texte = $head . substr($texte, $poshead); |
|
| 792 | + } |
|
| 793 | + if ($href_base) { |
|
| 794 | + // gerer les ancres |
|
| 795 | + $base = $_SERVER['REQUEST_URI']; |
|
| 796 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | + } |
|
| 800 | + if (strpos($texte, "href='#") !== false) { |
|
| 801 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | + } |
|
| 803 | + if (strpos($texte, 'href="#') !== false) { |
|
| 804 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | // et demarrent par X-Spip-... |
| 813 | 813 | // https://code.spip.net/@envoyer_entetes |
| 814 | 814 | function envoyer_entetes($entetes) { |
| 815 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | - } |
|
| 815 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | + } |
|
| 818 | 818 | } |