@@ -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 . '('; |
@@ -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 */ |
@@ -64,82 +64,82 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
| 67 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | - $match = array_pad($match, 3, null); |
|
| 69 | - $p = strpos($texte, (string) $match[0]); |
|
| 70 | - $debut = substr($texte, 0, $p); |
|
| 71 | - if ($p) { |
|
| 72 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | - } |
|
| 74 | - $ligne += substr_count($debut, "\n"); |
|
| 75 | - $champ = new Inclure(); |
|
| 76 | - $champ->ligne = $ligne; |
|
| 77 | - $ligne += substr_count($match[0], "\n"); |
|
| 78 | - $fichier = $match[2]; |
|
| 79 | - # assurer ici la migration .php3 => .php |
|
| 80 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | - $fichier = $r[1]; |
|
| 83 | - } |
|
| 84 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | - $pos_apres = 0; |
|
| 88 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | - $result[] = $champ; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 67 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | + $match = array_pad($match, 3, null); |
|
| 69 | + $p = strpos($texte, (string) $match[0]); |
|
| 70 | + $debut = substr($texte, 0, $p); |
|
| 71 | + if ($p) { |
|
| 72 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | + } |
|
| 74 | + $ligne += substr_count($debut, "\n"); |
|
| 75 | + $champ = new Inclure(); |
|
| 76 | + $champ->ligne = $ligne; |
|
| 77 | + $ligne += substr_count($match[0], "\n"); |
|
| 78 | + $fichier = $match[2]; |
|
| 79 | + # assurer ici la migration .php3 => .php |
|
| 80 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | + $fichier = $r[1]; |
|
| 83 | + } |
|
| 84 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | + $pos_apres = 0; |
|
| 88 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | + $result[] = $champ; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function phraser_polyglotte($texte, $ligne, $result) { |
| 104 | 104 | |
| 105 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | - foreach ($m as $match) { |
|
| 107 | - $p = strpos($texte, (string) $match[0]); |
|
| 108 | - $debut = substr($texte, 0, $p); |
|
| 109 | - if ($p) { |
|
| 110 | - $champ = new Texte(); |
|
| 111 | - $champ->texte = $debut; |
|
| 112 | - $champ->ligne = $ligne; |
|
| 113 | - $result[] = $champ; |
|
| 114 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $champ = new Polyglotte(); |
|
| 118 | - $champ->ligne = $ligne; |
|
| 119 | - $ligne += substr_count($match[0], "\n"); |
|
| 120 | - $lang = ''; |
|
| 121 | - $bloc = $match[1]; |
|
| 122 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | - $trad = $regs[1]; |
|
| 125 | - if ($trad or $lang) { |
|
| 126 | - $champ->traductions[$lang] = $trad; |
|
| 127 | - } |
|
| 128 | - $lang = $regs[2]; |
|
| 129 | - $bloc = $regs[3]; |
|
| 130 | - } |
|
| 131 | - $champ->traductions[$lang] = $bloc; |
|
| 132 | - $result[] = $champ; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if ($texte !== '') { |
|
| 136 | - $champ = new Texte(); |
|
| 137 | - $champ->texte = $texte; |
|
| 138 | - $champ->ligne = $ligne; |
|
| 139 | - $result[] = $champ; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $result; |
|
| 105 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | + foreach ($m as $match) { |
|
| 107 | + $p = strpos($texte, (string) $match[0]); |
|
| 108 | + $debut = substr($texte, 0, $p); |
|
| 109 | + if ($p) { |
|
| 110 | + $champ = new Texte(); |
|
| 111 | + $champ->texte = $debut; |
|
| 112 | + $champ->ligne = $ligne; |
|
| 113 | + $result[] = $champ; |
|
| 114 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $champ = new Polyglotte(); |
|
| 118 | + $champ->ligne = $ligne; |
|
| 119 | + $ligne += substr_count($match[0], "\n"); |
|
| 120 | + $lang = ''; |
|
| 121 | + $bloc = $match[1]; |
|
| 122 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | + $trad = $regs[1]; |
|
| 125 | + if ($trad or $lang) { |
|
| 126 | + $champ->traductions[$lang] = $trad; |
|
| 127 | + } |
|
| 128 | + $lang = $regs[2]; |
|
| 129 | + $bloc = $regs[3]; |
|
| 130 | + } |
|
| 131 | + $champ->traductions[$lang] = $bloc; |
|
| 132 | + $result[] = $champ; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if ($texte !== '') { |
|
| 136 | + $champ = new Texte(); |
|
| 137 | + $champ->texte = $texte; |
|
| 138 | + $champ->ligne = $ligne; |
|
| 139 | + $result[] = $champ; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $result; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -161,43 +161,43 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | **/ |
| 163 | 163 | function phraser_idiomes($texte, $ligne, $result) { |
| 164 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | - $match = array_pad($match, 8, null); |
|
| 166 | - $p = strpos($texte, (string) $match[0]); |
|
| 167 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | - if ($debut) { |
|
| 170 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | - } |
|
| 172 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | - $ligne += substr_count($debut, "\n"); |
|
| 174 | - if ($ko) { |
|
| 175 | - continue; |
|
| 176 | - } // faux idiome |
|
| 177 | - $champ = new Idiome(); |
|
| 178 | - $champ->ligne = $ligne; |
|
| 179 | - $ligne += substr_count($match[0], "\n"); |
|
| 180 | - // Stocker les arguments de la balise de traduction |
|
| 181 | - $args = []; |
|
| 182 | - $largs = $match[5]; |
|
| 183 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | - $largs = substr($largs, strlen($r[0])); |
|
| 186 | - } |
|
| 187 | - $champ->arg = $args; |
|
| 188 | - $champ->nom_champ = strtolower($match[3]); |
|
| 189 | - $champ->module = $match[2]; |
|
| 190 | - // pas d'imbrication pour les filtres sur langue |
|
| 191 | - $pos_apres = 0; |
|
| 192 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== '') { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $result; |
|
| 164 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | + $match = array_pad($match, 8, null); |
|
| 166 | + $p = strpos($texte, (string) $match[0]); |
|
| 167 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | + if ($debut) { |
|
| 170 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | + } |
|
| 172 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | + $ligne += substr_count($debut, "\n"); |
|
| 174 | + if ($ko) { |
|
| 175 | + continue; |
|
| 176 | + } // faux idiome |
|
| 177 | + $champ = new Idiome(); |
|
| 178 | + $champ->ligne = $ligne; |
|
| 179 | + $ligne += substr_count($match[0], "\n"); |
|
| 180 | + // Stocker les arguments de la balise de traduction |
|
| 181 | + $args = []; |
|
| 182 | + $largs = $match[5]; |
|
| 183 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | + $largs = substr($largs, strlen($r[0])); |
|
| 186 | + } |
|
| 187 | + $champ->arg = $args; |
|
| 188 | + $champ->nom_champ = strtolower($match[3]); |
|
| 189 | + $champ->module = $match[2]; |
|
| 190 | + // pas d'imbrication pour les filtres sur langue |
|
| 191 | + $pos_apres = 0; |
|
| 192 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | + $result[] = $champ; |
|
| 195 | + } |
|
| 196 | + if ($texte !== '') { |
|
| 197 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $result; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | - $p = strpos($texte, (string) $match[0]); |
|
| 220 | - // texte après la balise |
|
| 221 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | - |
|
| 223 | - $debut = substr($texte, 0, $p); |
|
| 224 | - if ($p) { |
|
| 225 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | - } |
|
| 227 | - $ligne += substr_count($debut, "\n"); |
|
| 228 | - $champ = new Champ(); |
|
| 229 | - $champ->ligne = $ligne; |
|
| 230 | - $ligne += substr_count($match[0], "\n"); |
|
| 231 | - $champ->nom_boucle = $match[2]; |
|
| 232 | - $champ->nom_champ = $match[3]; |
|
| 233 | - $champ->etoile = $match[5]; |
|
| 234 | - |
|
| 235 | - if ($suite and $suite[0] == '{') { |
|
| 236 | - phraser_arg($suite, '', [], $champ); |
|
| 237 | - // ce ltrim est une ereur de conception |
|
| 238 | - // mais on le conserve par souci de compatibilite |
|
| 239 | - $texte = ltrim($suite); |
|
| 240 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 218 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | + $p = strpos($texte, (string) $match[0]); |
|
| 220 | + // texte après la balise |
|
| 221 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | + |
|
| 223 | + $debut = substr($texte, 0, $p); |
|
| 224 | + if ($p) { |
|
| 225 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | + } |
|
| 227 | + $ligne += substr_count($debut, "\n"); |
|
| 228 | + $champ = new Champ(); |
|
| 229 | + $champ->ligne = $ligne; |
|
| 230 | + $ligne += substr_count($match[0], "\n"); |
|
| 231 | + $champ->nom_boucle = $match[2]; |
|
| 232 | + $champ->nom_champ = $match[3]; |
|
| 233 | + $champ->etoile = $match[5]; |
|
| 234 | + |
|
| 235 | + if ($suite and $suite[0] == '{') { |
|
| 236 | + phraser_arg($suite, '', [], $champ); |
|
| 237 | + // ce ltrim est une ereur de conception |
|
| 238 | + // mais on le conserve par souci de compatibilite |
|
| 239 | + $texte = ltrim($suite); |
|
| 240 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 243 | 243 | if ($n = (strlen($suite) - strlen($texte))) { |
| 244 | 244 | $champ->apres = array(new Texte); |
| 245 | 245 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 246 | 246 | } |
| 247 | 247 | */ |
| 248 | - } else { |
|
| 249 | - $texte = $suite; |
|
| 250 | - } |
|
| 251 | - phraser_vieux($champ); |
|
| 252 | - $result[] = $champ; |
|
| 253 | - } |
|
| 254 | - if ($texte !== '') { |
|
| 255 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $result; |
|
| 248 | + } else { |
|
| 249 | + $texte = $suite; |
|
| 250 | + } |
|
| 251 | + phraser_vieux($champ); |
|
| 252 | + $result[] = $champ; |
|
| 253 | + } |
|
| 254 | + if ($texte !== '') { |
|
| 255 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $result; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Gestion des imbrications: |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 265 | |
| 266 | 266 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 267 | - if ($texte === '') { |
|
| 268 | - return $result; |
|
| 269 | - } |
|
| 270 | - $sep = '##'; |
|
| 271 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | - $sep .= '#'; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 267 | + if ($texte === '') { |
|
| 268 | + return $result; |
|
| 269 | + } |
|
| 270 | + $sep = '##'; |
|
| 271 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | + $sep .= '#'; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -291,275 +291,275 @@ discard block |
||
| 291 | 291 | * @return array |
| 292 | 292 | */ |
| 293 | 293 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 294 | - $length = strlen($texte); |
|
| 295 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | - $pos_debut++; |
|
| 297 | - } |
|
| 298 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | - $st = substr($texte, $pos_debut); |
|
| 301 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | - $pos_debut = $length - strlen($st); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $result; |
|
| 294 | + $length = strlen($texte); |
|
| 295 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | + $pos_debut++; |
|
| 297 | + } |
|
| 298 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | + $st = substr($texte, $pos_debut); |
|
| 301 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | + $pos_debut = $length - strlen($st); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $result; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 312 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | - $suite = ltrim($match[2]); |
|
| 314 | - $fonc = trim($match[1]); |
|
| 315 | - if ($fonc && $fonc[0] == '|') { |
|
| 316 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | - } |
|
| 318 | - $res = [$fonc]; |
|
| 319 | - $err_f = ''; |
|
| 320 | - // cas du filtre sans argument ou du critere / |
|
| 321 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | - if (!$match[1]) { |
|
| 324 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | - $texte = ''; |
|
| 327 | - } else { |
|
| 328 | - $texte = $suite; |
|
| 329 | - } |
|
| 330 | - if ($err_f) { |
|
| 331 | - $pointeur_champ->param = false; |
|
| 332 | - } elseif ($fonc !== '') { |
|
| 333 | - $pointeur_champ->param[] = $res; |
|
| 334 | - } |
|
| 335 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | - |
|
| 338 | - return $result; |
|
| 339 | - } |
|
| 340 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | - $collecte = []; |
|
| 342 | - while ($args && $args[0] != '}') { |
|
| 343 | - if ($args[0] == '"') { |
|
| 344 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | - } elseif ($args[0] == "'") { |
|
| 346 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | - } else { |
|
| 348 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | - $champ = new Texte(); |
|
| 353 | - $champ->apres = $champ->avant = $args = ''; |
|
| 354 | - break; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $arg = $regs[2]; |
|
| 358 | - if (trim($regs[1])) { |
|
| 359 | - $champ = new Texte(); |
|
| 360 | - $champ->texte = $arg; |
|
| 361 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | - $result[] = $champ; |
|
| 363 | - $collecte[] = $champ; |
|
| 364 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | - } else { |
|
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | - // 0 est un aveu d'impuissance. A completer |
|
| 368 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | - |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - $collecte = array_merge($collecte, $arg); |
|
| 372 | - $result = array_merge($result, $arg); |
|
| 373 | - } else { |
|
| 374 | - $n = strpos($args, (string) $r[0]); |
|
| 375 | - $pred = substr($args, 0, $n); |
|
| 376 | - $par = ',}'; |
|
| 377 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | - $pred = $m[1]; |
|
| 379 | - $par = ')'; |
|
| 380 | - } |
|
| 381 | - if ($pred) { |
|
| 382 | - $champ = new Texte(); |
|
| 383 | - $champ->texte = $pred; |
|
| 384 | - $champ->apres = $champ->avant = ''; |
|
| 385 | - $result[] = $champ; |
|
| 386 | - $collecte[] = $champ; |
|
| 387 | - } |
|
| 388 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | - $champ = new Champ(); |
|
| 390 | - $champ->nom_boucle = $r[2]; |
|
| 391 | - $champ->nom_champ = $r[3]; |
|
| 392 | - $champ->etoile = $r[5]; |
|
| 393 | - $next = $r[6]; |
|
| 394 | - while ($next == '{') { |
|
| 395 | - phraser_arg($rec, $sep, [], $champ); |
|
| 396 | - $args = ltrim($rec); |
|
| 397 | - $next = $args[0] ?? ''; |
|
| 398 | - } |
|
| 399 | - while ($next == '|') { |
|
| 400 | - $pos_apres = 0; |
|
| 401 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | - $args = substr($rec, $pos_apres); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | - if ($champ->param === false) { |
|
| 407 | - $err_f = true; |
|
| 408 | - } else { |
|
| 409 | - phraser_vieux($champ); |
|
| 410 | - } |
|
| 411 | - if ($par == ')') { |
|
| 412 | - $args = substr($args, 1); |
|
| 413 | - } |
|
| 414 | - $collecte[] = $champ; |
|
| 415 | - $result[] = $champ; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | - $args = ltrim(substr($args, 1)); |
|
| 420 | - if ($collecte) { |
|
| 421 | - $res[] = $collecte; |
|
| 422 | - $collecte = []; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - $texte = substr($args, 1); |
|
| 431 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | - // propager les erreurs, et ignorer les param vides |
|
| 433 | - if ($pointeur_champ->param !== false) { |
|
| 434 | - if ($err_f) { |
|
| 435 | - $pointeur_champ->param = false; |
|
| 436 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | - $pointeur_champ->param[] = $res; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | - |
|
| 443 | - return $result; |
|
| 312 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | + $suite = ltrim($match[2]); |
|
| 314 | + $fonc = trim($match[1]); |
|
| 315 | + if ($fonc && $fonc[0] == '|') { |
|
| 316 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | + } |
|
| 318 | + $res = [$fonc]; |
|
| 319 | + $err_f = ''; |
|
| 320 | + // cas du filtre sans argument ou du critere / |
|
| 321 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | + if (!$match[1]) { |
|
| 324 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | + $texte = ''; |
|
| 327 | + } else { |
|
| 328 | + $texte = $suite; |
|
| 329 | + } |
|
| 330 | + if ($err_f) { |
|
| 331 | + $pointeur_champ->param = false; |
|
| 332 | + } elseif ($fonc !== '') { |
|
| 333 | + $pointeur_champ->param[] = $res; |
|
| 334 | + } |
|
| 335 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | + |
|
| 338 | + return $result; |
|
| 339 | + } |
|
| 340 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | + $collecte = []; |
|
| 342 | + while ($args && $args[0] != '}') { |
|
| 343 | + if ($args[0] == '"') { |
|
| 344 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | + } elseif ($args[0] == "'") { |
|
| 346 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | + } else { |
|
| 348 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | + $champ = new Texte(); |
|
| 353 | + $champ->apres = $champ->avant = $args = ''; |
|
| 354 | + break; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $arg = $regs[2]; |
|
| 358 | + if (trim($regs[1])) { |
|
| 359 | + $champ = new Texte(); |
|
| 360 | + $champ->texte = $arg; |
|
| 361 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | + $result[] = $champ; |
|
| 363 | + $collecte[] = $champ; |
|
| 364 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | + } else { |
|
| 366 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | + // 0 est un aveu d'impuissance. A completer |
|
| 368 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | + |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + $collecte = array_merge($collecte, $arg); |
|
| 372 | + $result = array_merge($result, $arg); |
|
| 373 | + } else { |
|
| 374 | + $n = strpos($args, (string) $r[0]); |
|
| 375 | + $pred = substr($args, 0, $n); |
|
| 376 | + $par = ',}'; |
|
| 377 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | + $pred = $m[1]; |
|
| 379 | + $par = ')'; |
|
| 380 | + } |
|
| 381 | + if ($pred) { |
|
| 382 | + $champ = new Texte(); |
|
| 383 | + $champ->texte = $pred; |
|
| 384 | + $champ->apres = $champ->avant = ''; |
|
| 385 | + $result[] = $champ; |
|
| 386 | + $collecte[] = $champ; |
|
| 387 | + } |
|
| 388 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | + $champ = new Champ(); |
|
| 390 | + $champ->nom_boucle = $r[2]; |
|
| 391 | + $champ->nom_champ = $r[3]; |
|
| 392 | + $champ->etoile = $r[5]; |
|
| 393 | + $next = $r[6]; |
|
| 394 | + while ($next == '{') { |
|
| 395 | + phraser_arg($rec, $sep, [], $champ); |
|
| 396 | + $args = ltrim($rec); |
|
| 397 | + $next = $args[0] ?? ''; |
|
| 398 | + } |
|
| 399 | + while ($next == '|') { |
|
| 400 | + $pos_apres = 0; |
|
| 401 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | + $args = substr($rec, $pos_apres); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | + if ($champ->param === false) { |
|
| 407 | + $err_f = true; |
|
| 408 | + } else { |
|
| 409 | + phraser_vieux($champ); |
|
| 410 | + } |
|
| 411 | + if ($par == ')') { |
|
| 412 | + $args = substr($args, 1); |
|
| 413 | + } |
|
| 414 | + $collecte[] = $champ; |
|
| 415 | + $result[] = $champ; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | + $args = ltrim(substr($args, 1)); |
|
| 420 | + if ($collecte) { |
|
| 421 | + $res[] = $collecte; |
|
| 422 | + $collecte = []; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + $texte = substr($args, 1); |
|
| 431 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | + // propager les erreurs, et ignorer les param vides |
|
| 433 | + if ($pointeur_champ->param !== false) { |
|
| 434 | + if ($err_f) { |
|
| 435 | + $pointeur_champ->param = false; |
|
| 436 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | + $pointeur_champ->param[] = $res; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | + |
|
| 443 | + return $result; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | - $res = []; |
|
| 449 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | - break; |
|
| 452 | - } |
|
| 453 | - $debut = substr($texte, 0, $p); |
|
| 454 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | - if ($p) { |
|
| 456 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | - } |
|
| 458 | - $ligne += substr_count($debut, "\n"); |
|
| 459 | - $res[] = $nested[$m[1]]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 448 | + $res = []; |
|
| 449 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | + break; |
|
| 452 | + } |
|
| 453 | + $debut = substr($texte, 0, $p); |
|
| 454 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | + if ($p) { |
|
| 456 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | + } |
|
| 458 | + $ligne += substr_count($debut, "\n"); |
|
| 459 | + $res[] = $nested[$m[1]]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | - $i = 0; // en fait count($result) |
|
| 467 | - $x = ''; |
|
| 468 | - |
|
| 469 | - while (true) { |
|
| 470 | - $j = $i; |
|
| 471 | - $n = $ligne; |
|
| 472 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | - $p = strpos($texte, (string) $match[0]); |
|
| 474 | - $debut = substr($texte, 0, $p); |
|
| 475 | - if ($p) { |
|
| 476 | - $result[$i] = $debut; |
|
| 477 | - $i++; |
|
| 478 | - } |
|
| 479 | - $nom = $match[4]; |
|
| 480 | - $champ = new Champ(); |
|
| 481 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | - $champ->nom_boucle = $match[3]; |
|
| 484 | - $champ->nom_champ = $nom; |
|
| 485 | - $champ->etoile = $match[6]; |
|
| 486 | - // phraser_args indiquera ou commence apres |
|
| 487 | - $pos_apres = 0; |
|
| 488 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | - phraser_vieux($champ); |
|
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | - if (!empty($debut)) { |
|
| 493 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | - } |
|
| 495 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | - |
|
| 497 | - // reinjecter la boucle si c'en est une |
|
| 498 | - phraser_boucle_placeholder($champ); |
|
| 499 | - |
|
| 500 | - $result[$i] = $champ; |
|
| 501 | - $i++; |
|
| 502 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | - } |
|
| 504 | - if ($texte !== '') { |
|
| 505 | - $result[$i] = $texte; |
|
| 506 | - $i++; |
|
| 507 | - } |
|
| 508 | - $x = ''; |
|
| 509 | - |
|
| 510 | - while ($j < $i) { |
|
| 511 | - $z = $result[$j]; |
|
| 512 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | - if (is_object($z)) { |
|
| 514 | - $x .= "%$sep$j@"; |
|
| 515 | - } else { |
|
| 516 | - $x .= $z; |
|
| 517 | - } |
|
| 518 | - $j++; |
|
| 519 | - } |
|
| 520 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | - $texte = $x; |
|
| 522 | - } else { |
|
| 523 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | - } |
|
| 525 | - } |
|
| 466 | + $i = 0; // en fait count($result) |
|
| 467 | + $x = ''; |
|
| 468 | + |
|
| 469 | + while (true) { |
|
| 470 | + $j = $i; |
|
| 471 | + $n = $ligne; |
|
| 472 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | + $p = strpos($texte, (string) $match[0]); |
|
| 474 | + $debut = substr($texte, 0, $p); |
|
| 475 | + if ($p) { |
|
| 476 | + $result[$i] = $debut; |
|
| 477 | + $i++; |
|
| 478 | + } |
|
| 479 | + $nom = $match[4]; |
|
| 480 | + $champ = new Champ(); |
|
| 481 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | + $champ->nom_boucle = $match[3]; |
|
| 484 | + $champ->nom_champ = $nom; |
|
| 485 | + $champ->etoile = $match[6]; |
|
| 486 | + // phraser_args indiquera ou commence apres |
|
| 487 | + $pos_apres = 0; |
|
| 488 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | + phraser_vieux($champ); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | + if (!empty($debut)) { |
|
| 493 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | + } |
|
| 495 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | + |
|
| 497 | + // reinjecter la boucle si c'en est une |
|
| 498 | + phraser_boucle_placeholder($champ); |
|
| 499 | + |
|
| 500 | + $result[$i] = $champ; |
|
| 501 | + $i++; |
|
| 502 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | + } |
|
| 504 | + if ($texte !== '') { |
|
| 505 | + $result[$i] = $texte; |
|
| 506 | + $i++; |
|
| 507 | + } |
|
| 508 | + $x = ''; |
|
| 509 | + |
|
| 510 | + while ($j < $i) { |
|
| 511 | + $z = $result[$j]; |
|
| 512 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | + if (is_object($z)) { |
|
| 514 | + $x .= "%$sep$j@"; |
|
| 515 | + } else { |
|
| 516 | + $x .= $z; |
|
| 517 | + } |
|
| 518 | + $j++; |
|
| 519 | + } |
|
| 520 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | + $texte = $x; |
|
| 522 | + } else { |
|
| 523 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | function phraser_vieux(&$champ) { |
| 529 | - $nom = $champ->nom_champ; |
|
| 530 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | - include_spip('public/normaliser'); |
|
| 533 | - } |
|
| 534 | - phraser_vieux_emb($champ); |
|
| 535 | - } elseif ($nom == 'EXPOSER') { |
|
| 536 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | - include_spip('public/normaliser'); |
|
| 538 | - } |
|
| 539 | - phraser_vieux_exposer($champ); |
|
| 540 | - } elseif ($champ->param) { |
|
| 541 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | - include_spip('public/normaliser'); |
|
| 544 | - } |
|
| 545 | - phraser_vieux_recherche($champ); |
|
| 546 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | - include_spip('public/normaliser'); |
|
| 549 | - } |
|
| 550 | - phraser_vieux_logos($champ); |
|
| 551 | - } elseif ($nom == 'MODELE') { |
|
| 552 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | - include_spip('public/normaliser'); |
|
| 554 | - } |
|
| 555 | - phraser_vieux_modele($champ); |
|
| 556 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | - include_spip('public/normaliser'); |
|
| 559 | - } |
|
| 560 | - phraser_vieux_inclu($champ); |
|
| 561 | - } |
|
| 562 | - } |
|
| 529 | + $nom = $champ->nom_champ; |
|
| 530 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | + include_spip('public/normaliser'); |
|
| 533 | + } |
|
| 534 | + phraser_vieux_emb($champ); |
|
| 535 | + } elseif ($nom == 'EXPOSER') { |
|
| 536 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | + include_spip('public/normaliser'); |
|
| 538 | + } |
|
| 539 | + phraser_vieux_exposer($champ); |
|
| 540 | + } elseif ($champ->param) { |
|
| 541 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | + include_spip('public/normaliser'); |
|
| 544 | + } |
|
| 545 | + phraser_vieux_recherche($champ); |
|
| 546 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | + include_spip('public/normaliser'); |
|
| 549 | + } |
|
| 550 | + phraser_vieux_logos($champ); |
|
| 551 | + } elseif ($nom == 'MODELE') { |
|
| 552 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | + include_spip('public/normaliser'); |
|
| 554 | + } |
|
| 555 | + phraser_vieux_modele($champ); |
|
| 556 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | + include_spip('public/normaliser'); |
|
| 559 | + } |
|
| 560 | + phraser_vieux_inclu($champ); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | |
@@ -587,200 +587,200 @@ discard block |
||
| 587 | 587 | **/ |
| 588 | 588 | function phraser_criteres($params, &$result) { |
| 589 | 589 | |
| 590 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | - $args = []; |
|
| 592 | - $type = $result->type_requete; |
|
| 593 | - $doublons = []; |
|
| 594 | - foreach ($params as $v) { |
|
| 595 | - $var = $v[1][0]; |
|
| 596 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | - // plus d'un argument et pas le critere IN: |
|
| 599 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | - if ( |
|
| 601 | - $var->type != 'texte' |
|
| 602 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | - ) { |
|
| 604 | - $op = ','; |
|
| 605 | - $not = ''; |
|
| 606 | - $cond = false; |
|
| 607 | - } else { |
|
| 608 | - // Le debut du premier argument est l'operateur |
|
| 609 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | - $op = $m[2]; |
|
| 611 | - $not = $m[1]; |
|
| 612 | - $cond = $m[3]; |
|
| 613 | - // virer le premier argument, |
|
| 614 | - // et mettre son reliquat eventuel |
|
| 615 | - // Recopier pour ne pas alterer le texte source |
|
| 616 | - // utile au debusqueur |
|
| 617 | - if ($m[4]) { |
|
| 618 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | - $c = null; |
|
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 622 | - if (isset($c)) { |
|
| 623 | - $m[4] = $c; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - $texte = new Texte(); |
|
| 627 | - $texte->texte = $m[4]; |
|
| 628 | - $v[1][0] = $texte; |
|
| 629 | - } else { |
|
| 630 | - array_shift($v[1]); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - array_shift($v); // $v[O] est vide |
|
| 634 | - $crit = new Critere(); |
|
| 635 | - $crit->op = $op; |
|
| 636 | - $crit->not = $not; |
|
| 637 | - $crit->cond = $cond; |
|
| 638 | - $crit->exclus = ''; |
|
| 639 | - $crit->param = $v; |
|
| 640 | - $args[] = $crit; |
|
| 641 | - } else { |
|
| 642 | - if ($var->type != 'texte') { |
|
| 643 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | - // erreur ou critere infixe "/" |
|
| 645 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | - $err_ci = [ |
|
| 647 | - 'zbug_critere_inconnu', |
|
| 648 | - ['critere' => $var->nom_champ] |
|
| 649 | - ]; |
|
| 650 | - erreur_squelette($err_ci, $result); |
|
| 651 | - } else { |
|
| 652 | - $crit = new Critere(); |
|
| 653 | - $crit->op = '/'; |
|
| 654 | - $crit->not = ''; |
|
| 655 | - $crit->exclus = ''; |
|
| 656 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | - $args[] = $crit; |
|
| 658 | - } |
|
| 659 | - } else { |
|
| 660 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | - // les separateurs |
|
| 662 | - if ($var->apres) { |
|
| 663 | - $result->separateur[] = $param; |
|
| 664 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | - $result->modificateur['tout'] = true; |
|
| 666 | - } elseif ($param == 'plat') { |
|
| 667 | - $result->modificateur['plat'] = true; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | - // ceux-ci pour avoir la rubrique mere... |
|
| 673 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | - // traités normalement. |
|
| 675 | - elseif ( |
|
| 676 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | - ) { |
|
| 680 | - $result->modificateur['tout'] = true; |
|
| 681 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | - // rien a faire sur {id_rubrique} tout seul |
|
| 683 | - } else { |
|
| 684 | - // pas d'emplacement statique, faut un dynamique |
|
| 685 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | - // cette variable sera inseree dans le code |
|
| 688 | - // et son nom sert d'indicateur des maintenant |
|
| 689 | - $result->doublons = '$doublons_index'; |
|
| 690 | - if ($param == 'unique') { |
|
| 691 | - $param = 'doublons'; |
|
| 692 | - } |
|
| 693 | - } elseif ($param == 'recherche') { |
|
| 694 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | - $result->hash = ' '; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | - } elseif ( |
|
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | - ) { |
|
| 704 | - $a2 = trim($m[8]); |
|
| 705 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | - $a2 = substr($a2, 1, -1); |
|
| 707 | - } |
|
| 708 | - $crit = phraser_critere_infixe( |
|
| 709 | - $m[2], |
|
| 710 | - $a2, |
|
| 711 | - $v, |
|
| 712 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | - $m[6], |
|
| 714 | - $m[5] |
|
| 715 | - ); |
|
| 716 | - $crit->exclus = $m[1]; |
|
| 717 | - } elseif ( |
|
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 720 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | - ) { |
|
| 722 | - // contient aussi les comparaisons implicites ! |
|
| 723 | - // Comme ci-dessus: |
|
| 724 | - // le premier arg contient l'operateur |
|
| 725 | - array_shift($v); |
|
| 726 | - if ($m[6]) { |
|
| 727 | - $v[0][0] = new Texte(); |
|
| 728 | - $v[0][0]->texte = $m[6]; |
|
| 729 | - } else { |
|
| 730 | - array_shift($v[0]); |
|
| 731 | - if (!$v[0]) { |
|
| 732 | - array_shift($v); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - $crit = new Critere(); |
|
| 736 | - $crit->op = $m[2]; |
|
| 737 | - $crit->param = $v; |
|
| 738 | - $crit->not = $m[1]; |
|
| 739 | - $crit->cond = $m[5]; |
|
| 740 | - } else { |
|
| 741 | - $err_ci = [ |
|
| 742 | - 'zbug_critere_inconnu', |
|
| 743 | - ['critere' => $param] |
|
| 744 | - ]; |
|
| 745 | - erreur_squelette($err_ci, $result); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | - $args[] = $crit; |
|
| 750 | - } else { |
|
| 751 | - $doublons[] = $crit; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // les doublons non nies doivent etre le dernier critere |
|
| 759 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | - // cf critere_doublon |
|
| 761 | - if ($doublons) { |
|
| 762 | - $args = [...$args, ...$doublons]; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | - if (!$err_ci) { |
|
| 767 | - $result->criteres = $args; |
|
| 768 | - } |
|
| 590 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | + $args = []; |
|
| 592 | + $type = $result->type_requete; |
|
| 593 | + $doublons = []; |
|
| 594 | + foreach ($params as $v) { |
|
| 595 | + $var = $v[1][0]; |
|
| 596 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | + // plus d'un argument et pas le critere IN: |
|
| 599 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | + if ( |
|
| 601 | + $var->type != 'texte' |
|
| 602 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | + ) { |
|
| 604 | + $op = ','; |
|
| 605 | + $not = ''; |
|
| 606 | + $cond = false; |
|
| 607 | + } else { |
|
| 608 | + // Le debut du premier argument est l'operateur |
|
| 609 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | + $op = $m[2]; |
|
| 611 | + $not = $m[1]; |
|
| 612 | + $cond = $m[3]; |
|
| 613 | + // virer le premier argument, |
|
| 614 | + // et mettre son reliquat eventuel |
|
| 615 | + // Recopier pour ne pas alterer le texte source |
|
| 616 | + // utile au debusqueur |
|
| 617 | + if ($m[4]) { |
|
| 618 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | + $c = null; |
|
| 621 | + eval('$c = ' . $m[4] . ';'); |
|
| 622 | + if (isset($c)) { |
|
| 623 | + $m[4] = $c; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + $texte = new Texte(); |
|
| 627 | + $texte->texte = $m[4]; |
|
| 628 | + $v[1][0] = $texte; |
|
| 629 | + } else { |
|
| 630 | + array_shift($v[1]); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + array_shift($v); // $v[O] est vide |
|
| 634 | + $crit = new Critere(); |
|
| 635 | + $crit->op = $op; |
|
| 636 | + $crit->not = $not; |
|
| 637 | + $crit->cond = $cond; |
|
| 638 | + $crit->exclus = ''; |
|
| 639 | + $crit->param = $v; |
|
| 640 | + $args[] = $crit; |
|
| 641 | + } else { |
|
| 642 | + if ($var->type != 'texte') { |
|
| 643 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | + // erreur ou critere infixe "/" |
|
| 645 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | + $err_ci = [ |
|
| 647 | + 'zbug_critere_inconnu', |
|
| 648 | + ['critere' => $var->nom_champ] |
|
| 649 | + ]; |
|
| 650 | + erreur_squelette($err_ci, $result); |
|
| 651 | + } else { |
|
| 652 | + $crit = new Critere(); |
|
| 653 | + $crit->op = '/'; |
|
| 654 | + $crit->not = ''; |
|
| 655 | + $crit->exclus = ''; |
|
| 656 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | + $args[] = $crit; |
|
| 658 | + } |
|
| 659 | + } else { |
|
| 660 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | + // les separateurs |
|
| 662 | + if ($var->apres) { |
|
| 663 | + $result->separateur[] = $param; |
|
| 664 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | + $result->modificateur['tout'] = true; |
|
| 666 | + } elseif ($param == 'plat') { |
|
| 667 | + $result->modificateur['plat'] = true; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | + // ceux-ci pour avoir la rubrique mere... |
|
| 673 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | + // traités normalement. |
|
| 675 | + elseif ( |
|
| 676 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | + ) { |
|
| 680 | + $result->modificateur['tout'] = true; |
|
| 681 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | + // rien a faire sur {id_rubrique} tout seul |
|
| 683 | + } else { |
|
| 684 | + // pas d'emplacement statique, faut un dynamique |
|
| 685 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | + // cette variable sera inseree dans le code |
|
| 688 | + // et son nom sert d'indicateur des maintenant |
|
| 689 | + $result->doublons = '$doublons_index'; |
|
| 690 | + if ($param == 'unique') { |
|
| 691 | + $param = 'doublons'; |
|
| 692 | + } |
|
| 693 | + } elseif ($param == 'recherche') { |
|
| 694 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | + $result->hash = ' '; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | + } elseif ( |
|
| 701 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | + ) { |
|
| 704 | + $a2 = trim($m[8]); |
|
| 705 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | + $a2 = substr($a2, 1, -1); |
|
| 707 | + } |
|
| 708 | + $crit = phraser_critere_infixe( |
|
| 709 | + $m[2], |
|
| 710 | + $a2, |
|
| 711 | + $v, |
|
| 712 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | + $m[6], |
|
| 714 | + $m[5] |
|
| 715 | + ); |
|
| 716 | + $crit->exclus = $m[1]; |
|
| 717 | + } elseif ( |
|
| 718 | + preg_match('/^([!]?)\s*(' . |
|
| 719 | + CHAMP_SQL_PLUS_FONC . |
|
| 720 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | + ) { |
|
| 722 | + // contient aussi les comparaisons implicites ! |
|
| 723 | + // Comme ci-dessus: |
|
| 724 | + // le premier arg contient l'operateur |
|
| 725 | + array_shift($v); |
|
| 726 | + if ($m[6]) { |
|
| 727 | + $v[0][0] = new Texte(); |
|
| 728 | + $v[0][0]->texte = $m[6]; |
|
| 729 | + } else { |
|
| 730 | + array_shift($v[0]); |
|
| 731 | + if (!$v[0]) { |
|
| 732 | + array_shift($v); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + $crit = new Critere(); |
|
| 736 | + $crit->op = $m[2]; |
|
| 737 | + $crit->param = $v; |
|
| 738 | + $crit->not = $m[1]; |
|
| 739 | + $crit->cond = $m[5]; |
|
| 740 | + } else { |
|
| 741 | + $err_ci = [ |
|
| 742 | + 'zbug_critere_inconnu', |
|
| 743 | + ['critere' => $param] |
|
| 744 | + ]; |
|
| 745 | + erreur_squelette($err_ci, $result); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | + $args[] = $crit; |
|
| 750 | + } else { |
|
| 751 | + $doublons[] = $crit; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // les doublons non nies doivent etre le dernier critere |
|
| 759 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | + // cf critere_doublon |
|
| 761 | + if ($doublons) { |
|
| 762 | + $args = [...$args, ...$doublons]; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | + if (!$err_ci) { |
|
| 767 | + $result->criteres = $args; |
|
| 768 | + } |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 772 | - $args[0] = new Texte(); |
|
| 773 | - $args[0]->texte = $arg1; |
|
| 774 | - $args[0] = [$args[0]]; |
|
| 775 | - $args[1][0] = new Texte(); |
|
| 776 | - $args[1][0]->texte = $arg2; |
|
| 777 | - $crit = new Critere(); |
|
| 778 | - $crit->op = $op; |
|
| 779 | - $crit->not = $not; |
|
| 780 | - $crit->cond = $cond; |
|
| 781 | - $crit->param = $args; |
|
| 782 | - |
|
| 783 | - return $crit; |
|
| 772 | + $args[0] = new Texte(); |
|
| 773 | + $args[0]->texte = $arg1; |
|
| 774 | + $args[0] = [$args[0]]; |
|
| 775 | + $args[1][0] = new Texte(); |
|
| 776 | + $args[1][0]->texte = $arg2; |
|
| 777 | + $crit = new Critere(); |
|
| 778 | + $crit->op = $op; |
|
| 779 | + $crit->not = $not; |
|
| 780 | + $crit->cond = $cond; |
|
| 781 | + $crit->param = $args; |
|
| 782 | + |
|
| 783 | + return $crit; |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -791,12 +791,12 @@ discard block |
||
| 791 | 791 | * @return int |
| 792 | 792 | */ |
| 793 | 793 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 794 | - if (is_null($fin)) { |
|
| 795 | - return substr_count($texte, "\n", $debut); |
|
| 796 | - } |
|
| 797 | - else { |
|
| 798 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | - } |
|
| 794 | + if (is_null($fin)) { |
|
| 795 | + return substr_count($texte, "\n", $debut); |
|
| 796 | + } |
|
| 797 | + else { |
|
| 798 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | + } |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | |
@@ -812,87 +812,87 @@ discard block |
||
| 812 | 812 | * @return array|null |
| 813 | 813 | */ |
| 814 | 814 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 815 | - $premiere_boucle = null; |
|
| 816 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | - |
|
| 818 | - $current_pos = $pos_debut_texte; |
|
| 819 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | - $current_pos = $pos_boucle + 1; |
|
| 821 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | - |
|
| 823 | - $id_boucle = ''; |
|
| 824 | - if ($pos_parent !== false) { |
|
| 825 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | - } |
|
| 827 | - if ( |
|
| 828 | - $pos_parent === false |
|
| 829 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | - ) { |
|
| 831 | - $result = new Boucle(); |
|
| 832 | - $result->id_parent = $id_parent; |
|
| 833 | - $result->descr = $descr; |
|
| 834 | - |
|
| 835 | - // un id_boucle pour l'affichage de l'erreur |
|
| 836 | - if (!strlen($id_boucle)) { |
|
| 837 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | - } |
|
| 839 | - $result->id_boucle = $id_boucle; |
|
| 840 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | - erreur_squelette($err_b, $result); |
|
| 842 | - |
|
| 843 | - continue; |
|
| 844 | - } |
|
| 845 | - else { |
|
| 846 | - $boucle = [ |
|
| 847 | - 'id_boucle' => $id_boucle, |
|
| 848 | - 'id_boucle_err' => $id_boucle, |
|
| 849 | - 'debut_boucle' => $pos_boucle, |
|
| 850 | - 'pos_boucle' => $pos_boucle, |
|
| 851 | - 'pos_parent' => $pos_parent, |
|
| 852 | - 'pos_precond' => false, |
|
| 853 | - 'pos_precond_inside' => false, |
|
| 854 | - 'pos_preaff' => false, |
|
| 855 | - 'pos_preaff_inside' => false, |
|
| 856 | - ]; |
|
| 857 | - |
|
| 858 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | - if (!strlen($id_boucle)) { |
|
| 860 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | - if ( |
|
| 867 | - $pos_precond !== false |
|
| 868 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | - ) { |
|
| 870 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | - $boucle['pos_precond'] = $pos_precond; |
|
| 872 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | - if ( |
|
| 878 | - $pos_preaff !== false |
|
| 879 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | - ) { |
|
| 881 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | - } |
|
| 885 | - if (!strlen($id_boucle)) { |
|
| 886 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | - $premiere_boucle = $boucle; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $premiere_boucle; |
|
| 815 | + $premiere_boucle = null; |
|
| 816 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | + |
|
| 818 | + $current_pos = $pos_debut_texte; |
|
| 819 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | + $current_pos = $pos_boucle + 1; |
|
| 821 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | + |
|
| 823 | + $id_boucle = ''; |
|
| 824 | + if ($pos_parent !== false) { |
|
| 825 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | + } |
|
| 827 | + if ( |
|
| 828 | + $pos_parent === false |
|
| 829 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | + ) { |
|
| 831 | + $result = new Boucle(); |
|
| 832 | + $result->id_parent = $id_parent; |
|
| 833 | + $result->descr = $descr; |
|
| 834 | + |
|
| 835 | + // un id_boucle pour l'affichage de l'erreur |
|
| 836 | + if (!strlen($id_boucle)) { |
|
| 837 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | + } |
|
| 839 | + $result->id_boucle = $id_boucle; |
|
| 840 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | + erreur_squelette($err_b, $result); |
|
| 842 | + |
|
| 843 | + continue; |
|
| 844 | + } |
|
| 845 | + else { |
|
| 846 | + $boucle = [ |
|
| 847 | + 'id_boucle' => $id_boucle, |
|
| 848 | + 'id_boucle_err' => $id_boucle, |
|
| 849 | + 'debut_boucle' => $pos_boucle, |
|
| 850 | + 'pos_boucle' => $pos_boucle, |
|
| 851 | + 'pos_parent' => $pos_parent, |
|
| 852 | + 'pos_precond' => false, |
|
| 853 | + 'pos_precond_inside' => false, |
|
| 854 | + 'pos_preaff' => false, |
|
| 855 | + 'pos_preaff_inside' => false, |
|
| 856 | + ]; |
|
| 857 | + |
|
| 858 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | + if (!strlen($id_boucle)) { |
|
| 860 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | + if ( |
|
| 867 | + $pos_precond !== false |
|
| 868 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | + ) { |
|
| 870 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | + $boucle['pos_precond'] = $pos_precond; |
|
| 872 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | + if ( |
|
| 878 | + $pos_preaff !== false |
|
| 879 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | + ) { |
|
| 881 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | + } |
|
| 885 | + if (!strlen($id_boucle)) { |
|
| 886 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | + $premiere_boucle = $boucle; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $premiere_boucle; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -907,68 +907,68 @@ discard block |
||
| 907 | 907 | * @return mixed |
| 908 | 908 | */ |
| 909 | 909 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 910 | - $id_boucle = $boucle['id_boucle']; |
|
| 911 | - $pos_courante = $pos_debut_texte; |
|
| 912 | - |
|
| 913 | - $boucle['pos_postcond'] = false; |
|
| 914 | - $boucle['pos_postcond_inside'] = false; |
|
| 915 | - $boucle['pos_altern'] = false; |
|
| 916 | - $boucle['pos_altern_inside'] = false; |
|
| 917 | - $boucle['pos_postaff'] = false; |
|
| 918 | - $boucle['pos_postaff_inside'] = false; |
|
| 919 | - |
|
| 920 | - $pos_anonyme_next = null; |
|
| 921 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | - if (!strlen($id_boucle)) { |
|
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // |
|
| 927 | - // 1. Recuperer la partie conditionnelle apres |
|
| 928 | - // |
|
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | - if ( |
|
| 932 | - $pos_apres !== false |
|
| 933 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | - ) { |
|
| 935 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | - $pos_apres += strlen($apres_boucle); |
|
| 937 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | - $pos_courante = $pos_apres ; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // |
|
| 942 | - // 2. Récuperer la partie alternative apres |
|
| 943 | - // |
|
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | - if ( |
|
| 947 | - $pos_altern !== false |
|
| 948 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | - ) { |
|
| 950 | - $boucle['pos_altern'] = $pos_altern; |
|
| 951 | - $pos_altern += strlen($altern_boucle); |
|
| 952 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | - $pos_courante = $pos_altern; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // |
|
| 957 | - // 3. Recuperer la partie footer non alternative |
|
| 958 | - // |
|
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | - if ( |
|
| 962 | - $pos_postaff !== false |
|
| 963 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | - ) { |
|
| 965 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | - $pos_postaff += strlen($postaff_boucle); |
|
| 967 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | - $pos_courante = $pos_postaff ; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - return $boucle; |
|
| 910 | + $id_boucle = $boucle['id_boucle']; |
|
| 911 | + $pos_courante = $pos_debut_texte; |
|
| 912 | + |
|
| 913 | + $boucle['pos_postcond'] = false; |
|
| 914 | + $boucle['pos_postcond_inside'] = false; |
|
| 915 | + $boucle['pos_altern'] = false; |
|
| 916 | + $boucle['pos_altern_inside'] = false; |
|
| 917 | + $boucle['pos_postaff'] = false; |
|
| 918 | + $boucle['pos_postaff_inside'] = false; |
|
| 919 | + |
|
| 920 | + $pos_anonyme_next = null; |
|
| 921 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | + if (!strlen($id_boucle)) { |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // |
|
| 927 | + // 1. Recuperer la partie conditionnelle apres |
|
| 928 | + // |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | + if ( |
|
| 932 | + $pos_apres !== false |
|
| 933 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | + ) { |
|
| 935 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | + $pos_apres += strlen($apres_boucle); |
|
| 937 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | + $pos_courante = $pos_apres ; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // |
|
| 942 | + // 2. Récuperer la partie alternative apres |
|
| 943 | + // |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | + if ( |
|
| 947 | + $pos_altern !== false |
|
| 948 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | + ) { |
|
| 950 | + $boucle['pos_altern'] = $pos_altern; |
|
| 951 | + $pos_altern += strlen($altern_boucle); |
|
| 952 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | + $pos_courante = $pos_altern; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // |
|
| 957 | + // 3. Recuperer la partie footer non alternative |
|
| 958 | + // |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | + if ( |
|
| 962 | + $pos_postaff !== false |
|
| 963 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | + ) { |
|
| 965 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | + $pos_postaff += strlen($postaff_boucle); |
|
| 967 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | + $pos_courante = $pos_postaff ; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + return $boucle; |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | |
@@ -978,21 +978,21 @@ discard block |
||
| 978 | 978 | * @param null|object $boucle |
| 979 | 979 | */ |
| 980 | 980 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 981 | - static $boucles_connues = []; |
|
| 982 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | - } |
|
| 986 | - else { |
|
| 987 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | - $placeholder = $champ->nom_champ; |
|
| 989 | - $id = reset($champ->param[0][1]); |
|
| 990 | - $id = $id->texte; |
|
| 991 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 981 | + static $boucles_connues = []; |
|
| 982 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | + } |
|
| 986 | + else { |
|
| 987 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | + $placeholder = $champ->nom_champ; |
|
| 989 | + $id = reset($champ->param[0][1]); |
|
| 990 | + $id = $id->texte; |
|
| 991 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1005,274 +1005,274 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | - //memoriser la boucle a reinjecter |
|
| 1010 | - $id_boucle = "$id_boucle"; |
|
| 1011 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | - return $placeholder; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | + //memoriser la boucle a reinjecter |
|
| 1010 | + $id_boucle = "$id_boucle"; |
|
| 1011 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | + return $placeholder; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1016 | 1016 | |
| 1017 | - $all_res = []; |
|
| 1018 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | - if (is_null($boucle_placeholder)) { |
|
| 1020 | - do { |
|
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | - $pos_debut_texte = 0; |
|
| 1027 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | - $result = new Boucle(); |
|
| 1030 | - $result->id_parent = $id_parent; |
|
| 1031 | - $result->descr = $descr; |
|
| 1032 | - |
|
| 1033 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | - $pos_parent = $boucle['pos_parent']; |
|
| 1035 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | - |
|
| 1037 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | - |
|
| 1039 | - // boucle anonyme ? |
|
| 1040 | - if (!strlen($id_boucle)) { |
|
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - $pos_debut_boucle = $pos_courante; |
|
| 1045 | - |
|
| 1046 | - $pos_milieu = $pos_parent; |
|
| 1047 | - |
|
| 1048 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | - if ($boucle['pos_precond'] !== false) { |
|
| 1050 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | - |
|
| 1052 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | - $end_preaff = $pos_debut_boucle; |
|
| 1060 | - |
|
| 1061 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $result->id_boucle = $id_boucle; |
|
| 1067 | - |
|
| 1068 | - if ( |
|
| 1069 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | - or $pos_match > $pos_milieu |
|
| 1072 | - ) { |
|
| 1073 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | - erreur_squelette($err_b, $result); |
|
| 1075 | - |
|
| 1076 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | - continue; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $result->type_requete = $match[0]; |
|
| 1082 | - $pos_milieu += strlen($match[0]); |
|
| 1083 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | - |
|
| 1085 | - $type = $match[1]; |
|
| 1086 | - $jointures = trim($match[2]); |
|
| 1087 | - $table_optionnelle = ($match[3]); |
|
| 1088 | - if ($jointures) { |
|
| 1089 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | - // ou elles seront completees des jointures declarees |
|
| 1091 | - $result->jointures_explicites = $jointures; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if ($table_optionnelle) { |
|
| 1095 | - $result->table_optionnelle = $type; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | - // Resultat mis dans result->param |
|
| 1100 | - $pos_fin_criteres = $pos_milieu; |
|
| 1101 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | - |
|
| 1103 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | - // pour l'instant on met le source (chaine) : |
|
| 1105 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | - $pos_milieu = $pos_fin_criteres; |
|
| 1109 | - |
|
| 1110 | - // |
|
| 1111 | - // Recuperer la fin : |
|
| 1112 | - // |
|
| 1113 | - if ($texte[$pos_milieu] === '/') { |
|
| 1114 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | - $pos_courante += 2; |
|
| 1116 | - $result->milieu = ''; |
|
| 1117 | - } else { |
|
| 1118 | - $pos_milieu += 1; |
|
| 1119 | - |
|
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | - if ($pos_fin === false) { |
|
| 1123 | - $err_b = [ |
|
| 1124 | - 'zbug_erreur_boucle_fermant', |
|
| 1125 | - ['id' => $id_boucle] |
|
| 1126 | - ]; |
|
| 1127 | - erreur_squelette($err_b, $result); |
|
| 1128 | - $pos_courante += strlen($fin_boucle); |
|
| 1129 | - } |
|
| 1130 | - else { |
|
| 1131 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | - $search_from = $pos_milieu; |
|
| 1135 | - $nb_open = 1; |
|
| 1136 | - $nb_close = 1; |
|
| 1137 | - $maxiter = 0; |
|
| 1138 | - do { |
|
| 1139 | - while ( |
|
| 1140 | - $nb_close < $nb_open |
|
| 1141 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | - ) { |
|
| 1143 | - $nb_close++; |
|
| 1144 | - $pos_fin = $p; |
|
| 1145 | - } |
|
| 1146 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | - if ($nb_close < $nb_open) { |
|
| 1148 | - break; |
|
| 1149 | - } |
|
| 1150 | - while ( |
|
| 1151 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | - and $p < $pos_fin |
|
| 1153 | - ) { |
|
| 1154 | - $nb_open++; |
|
| 1155 | - $search_from = $p + 1; |
|
| 1156 | - } |
|
| 1157 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | - |
|
| 1159 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | - } |
|
| 1161 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | - |
|
| 1167 | - // |
|
| 1168 | - // 1. Partie conditionnelle apres ? |
|
| 1169 | - // |
|
| 1170 | - if ($boucle['pos_postcond']) { |
|
| 1171 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - // |
|
| 1178 | - // 2. Partie alternative apres ? |
|
| 1179 | - // |
|
| 1180 | - $ligne_altern = $ligne_suite; |
|
| 1181 | - if ($boucle['pos_altern']) { |
|
| 1182 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // |
|
| 1188 | - // 3. Partie footer non alternative ? |
|
| 1189 | - // |
|
| 1190 | - $ligne_postaff = $ligne_suite; |
|
| 1191 | - if ($boucle['pos_postaff']) { |
|
| 1192 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $result->ligne = $ligne_preaff; |
|
| 1198 | - |
|
| 1199 | - if ($p = strpos($type, ':')) { |
|
| 1200 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | - $type = substr($type, $p + 1); |
|
| 1202 | - } |
|
| 1203 | - $soustype = strtolower($type); |
|
| 1204 | - |
|
| 1205 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | - $soustype = $type; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $result->type_requete = $soustype; |
|
| 1210 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | - if (!is_array($result->param)) { |
|
| 1212 | - $err_b = true; |
|
| 1213 | - } else { |
|
| 1214 | - phraser_criteres($result->param, $result); |
|
| 1215 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | - $args = $result->param; |
|
| 1218 | - array_unshift( |
|
| 1219 | - $args, |
|
| 1220 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | - ); |
|
| 1222 | - $result->param = $args; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | - if (empty($boucles[$id_boucle])) { |
|
| 1232 | - $boucles[$id_boucle] = null; |
|
| 1233 | - } |
|
| 1234 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | - |
|
| 1240 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | - if ($err_b) { |
|
| 1242 | - $result->type_requete = false; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - // Verifier qu'il n'y a pas double definition |
|
| 1246 | - // apres analyse des sous-parties (pas avant). |
|
| 1247 | - if (!empty($boucles[$id_boucle])) { |
|
| 1248 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | - $err_b_d = [ |
|
| 1250 | - 'zbug_erreur_boucle_double', |
|
| 1251 | - ['id' => $id_boucle] |
|
| 1252 | - ]; |
|
| 1253 | - erreur_squelette($err_b_d, $result); |
|
| 1254 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | - } |
|
| 1257 | - } else { |
|
| 1258 | - $boucles[$id_boucle] = $result; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | - |
|
| 1267 | - // phraser la partie avant le debut de la boucle |
|
| 1268 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | - |
|
| 1271 | - $ligne_debut_texte = $ligne_suite; |
|
| 1272 | - $pos_debut_texte = $pos_courante; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | - |
|
| 1277 | - return $all_res; |
|
| 1017 | + $all_res = []; |
|
| 1018 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | + if (is_null($boucle_placeholder)) { |
|
| 1020 | + do { |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | + $pos_debut_texte = 0; |
|
| 1027 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | + $result = new Boucle(); |
|
| 1030 | + $result->id_parent = $id_parent; |
|
| 1031 | + $result->descr = $descr; |
|
| 1032 | + |
|
| 1033 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | + $pos_parent = $boucle['pos_parent']; |
|
| 1035 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | + |
|
| 1037 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | + |
|
| 1039 | + // boucle anonyme ? |
|
| 1040 | + if (!strlen($id_boucle)) { |
|
| 1041 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + $pos_debut_boucle = $pos_courante; |
|
| 1045 | + |
|
| 1046 | + $pos_milieu = $pos_parent; |
|
| 1047 | + |
|
| 1048 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | + if ($boucle['pos_precond'] !== false) { |
|
| 1050 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | + |
|
| 1052 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | + $end_preaff = $pos_debut_boucle; |
|
| 1060 | + |
|
| 1061 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $result->id_boucle = $id_boucle; |
|
| 1067 | + |
|
| 1068 | + if ( |
|
| 1069 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | + or $pos_match > $pos_milieu |
|
| 1072 | + ) { |
|
| 1073 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | + erreur_squelette($err_b, $result); |
|
| 1075 | + |
|
| 1076 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | + continue; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $result->type_requete = $match[0]; |
|
| 1082 | + $pos_milieu += strlen($match[0]); |
|
| 1083 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | + |
|
| 1085 | + $type = $match[1]; |
|
| 1086 | + $jointures = trim($match[2]); |
|
| 1087 | + $table_optionnelle = ($match[3]); |
|
| 1088 | + if ($jointures) { |
|
| 1089 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | + // ou elles seront completees des jointures declarees |
|
| 1091 | + $result->jointures_explicites = $jointures; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if ($table_optionnelle) { |
|
| 1095 | + $result->table_optionnelle = $type; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | + // Resultat mis dans result->param |
|
| 1100 | + $pos_fin_criteres = $pos_milieu; |
|
| 1101 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | + |
|
| 1103 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | + // pour l'instant on met le source (chaine) : |
|
| 1105 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | + $pos_milieu = $pos_fin_criteres; |
|
| 1109 | + |
|
| 1110 | + // |
|
| 1111 | + // Recuperer la fin : |
|
| 1112 | + // |
|
| 1113 | + if ($texte[$pos_milieu] === '/') { |
|
| 1114 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | + $pos_courante += 2; |
|
| 1116 | + $result->milieu = ''; |
|
| 1117 | + } else { |
|
| 1118 | + $pos_milieu += 1; |
|
| 1119 | + |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | + if ($pos_fin === false) { |
|
| 1123 | + $err_b = [ |
|
| 1124 | + 'zbug_erreur_boucle_fermant', |
|
| 1125 | + ['id' => $id_boucle] |
|
| 1126 | + ]; |
|
| 1127 | + erreur_squelette($err_b, $result); |
|
| 1128 | + $pos_courante += strlen($fin_boucle); |
|
| 1129 | + } |
|
| 1130 | + else { |
|
| 1131 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | + $search_from = $pos_milieu; |
|
| 1135 | + $nb_open = 1; |
|
| 1136 | + $nb_close = 1; |
|
| 1137 | + $maxiter = 0; |
|
| 1138 | + do { |
|
| 1139 | + while ( |
|
| 1140 | + $nb_close < $nb_open |
|
| 1141 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | + ) { |
|
| 1143 | + $nb_close++; |
|
| 1144 | + $pos_fin = $p; |
|
| 1145 | + } |
|
| 1146 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | + if ($nb_close < $nb_open) { |
|
| 1148 | + break; |
|
| 1149 | + } |
|
| 1150 | + while ( |
|
| 1151 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | + and $p < $pos_fin |
|
| 1153 | + ) { |
|
| 1154 | + $nb_open++; |
|
| 1155 | + $search_from = $p + 1; |
|
| 1156 | + } |
|
| 1157 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | + |
|
| 1159 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | + } |
|
| 1161 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | + |
|
| 1167 | + // |
|
| 1168 | + // 1. Partie conditionnelle apres ? |
|
| 1169 | + // |
|
| 1170 | + if ($boucle['pos_postcond']) { |
|
| 1171 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + // |
|
| 1178 | + // 2. Partie alternative apres ? |
|
| 1179 | + // |
|
| 1180 | + $ligne_altern = $ligne_suite; |
|
| 1181 | + if ($boucle['pos_altern']) { |
|
| 1182 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // |
|
| 1188 | + // 3. Partie footer non alternative ? |
|
| 1189 | + // |
|
| 1190 | + $ligne_postaff = $ligne_suite; |
|
| 1191 | + if ($boucle['pos_postaff']) { |
|
| 1192 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $result->ligne = $ligne_preaff; |
|
| 1198 | + |
|
| 1199 | + if ($p = strpos($type, ':')) { |
|
| 1200 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | + $type = substr($type, $p + 1); |
|
| 1202 | + } |
|
| 1203 | + $soustype = strtolower($type); |
|
| 1204 | + |
|
| 1205 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | + $soustype = $type; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $result->type_requete = $soustype; |
|
| 1210 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | + if (!is_array($result->param)) { |
|
| 1212 | + $err_b = true; |
|
| 1213 | + } else { |
|
| 1214 | + phraser_criteres($result->param, $result); |
|
| 1215 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | + $args = $result->param; |
|
| 1218 | + array_unshift( |
|
| 1219 | + $args, |
|
| 1220 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | + ); |
|
| 1222 | + $result->param = $args; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | + if (empty($boucles[$id_boucle])) { |
|
| 1232 | + $boucles[$id_boucle] = null; |
|
| 1233 | + } |
|
| 1234 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | + |
|
| 1240 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | + if ($err_b) { |
|
| 1242 | + $result->type_requete = false; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + // Verifier qu'il n'y a pas double definition |
|
| 1246 | + // apres analyse des sous-parties (pas avant). |
|
| 1247 | + if (!empty($boucles[$id_boucle])) { |
|
| 1248 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | + $err_b_d = [ |
|
| 1250 | + 'zbug_erreur_boucle_double', |
|
| 1251 | + ['id' => $id_boucle] |
|
| 1252 | + ]; |
|
| 1253 | + erreur_squelette($err_b_d, $result); |
|
| 1254 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | + } |
|
| 1257 | + } else { |
|
| 1258 | + $boucles[$id_boucle] = $result; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | + |
|
| 1267 | + // phraser la partie avant le debut de la boucle |
|
| 1268 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | + |
|
| 1271 | + $ligne_debut_texte = $ligne_suite; |
|
| 1272 | + $pos_debut_texte = $pos_courante; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | + |
|
| 1277 | + return $all_res; |
|
| 1278 | 1278 | } |
@@ -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 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 218 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 219 | 219 | $p = strpos($texte, (string) $match[0]); |
| 220 | 220 | // texte après la balise |
| 221 | 221 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $collecte[] = $champ; |
| 364 | 364 | $args = ltrim($regs[count($regs) - 1]); |
| 365 | 365 | } else { |
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 366 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 367 | 367 | // 0 est un aveu d'impuissance. A completer |
| 368 | 368 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 369 | 369 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | 448 | $res = []; |
| 449 | 449 | while (($p = strpos($texte, (string) "%$sep")) !== false) { |
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | 451 | break; |
| 452 | 452 | } |
| 453 | 453 | $debut = substr($texte, 0, $p); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | $pos_apres = 0; |
| 488 | 488 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 489 | 489 | phraser_vieux($champ); |
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | 491 | $debut = substr($match[7], $pos_apres + 1); |
| 492 | 492 | if (!empty($debut)) { |
| 493 | 493 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 619 | 619 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 620 | 620 | $c = null; |
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 621 | + eval('$c = '.$m[4].';'); |
|
| 622 | 622 | if (isset($c)) { |
| 623 | 623 | $m[4] = $c; |
| 624 | 624 | } |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 699 | 699 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 700 | 700 | } elseif ( |
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 701 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 702 | 702 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 703 | 703 | ) { |
| 704 | 704 | $a2 = trim($m[8]); |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | ); |
| 716 | 716 | $crit->exclus = $m[1]; |
| 717 | 717 | } elseif ( |
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 718 | + preg_match('/^([!]?)\s*('. |
|
| 719 | + CHAMP_SQL_PLUS_FONC. |
|
| 720 | 720 | ')\s*(\??)(.*)$/is', $param, $m) |
| 721 | 721 | ) { |
| 722 | 722 | // contient aussi les comparaisons implicites ! |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 865 | 865 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 866 | 866 | if ( |
| 867 | 867 | $pos_precond !== false |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 876 | 876 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 877 | 877 | if ( |
| 878 | 878 | $pos_preaff !== false |
@@ -920,13 +920,13 @@ discard block |
||
| 920 | 920 | $pos_anonyme_next = null; |
| 921 | 921 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 922 | 922 | if (!strlen($id_boucle)) { |
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | // |
| 927 | 927 | // 1. Recuperer la partie conditionnelle apres |
| 928 | 928 | // |
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 930 | 930 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 931 | 931 | if ( |
| 932 | 932 | $pos_apres !== false |
@@ -935,13 +935,13 @@ discard block |
||
| 935 | 935 | $boucle['pos_postcond'] = $pos_apres; |
| 936 | 936 | $pos_apres += strlen($apres_boucle); |
| 937 | 937 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 938 | - $pos_courante = $pos_apres ; |
|
| 938 | + $pos_courante = $pos_apres; |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | // |
| 942 | 942 | // 2. Récuperer la partie alternative apres |
| 943 | 943 | // |
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 945 | 945 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 946 | 946 | if ( |
| 947 | 947 | $pos_altern !== false |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | // |
| 957 | 957 | // 3. Recuperer la partie footer non alternative |
| 958 | 958 | // |
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 960 | 960 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 961 | 961 | if ( |
| 962 | 962 | $pos_postaff !== false |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | $boucle['pos_postaff'] = $pos_postaff; |
| 966 | 966 | $pos_postaff += strlen($postaff_boucle); |
| 967 | 967 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 968 | - $pos_courante = $pos_postaff ; |
|
| 968 | + $pos_courante = $pos_postaff; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | return $boucle; |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1009 | 1009 | //memoriser la boucle a reinjecter |
| 1010 | 1010 | $id_boucle = "$id_boucle"; |
| 1011 | 1011 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1019 | 1019 | if (is_null($boucle_placeholder)) { |
| 1020 | 1020 | do { |
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1022 | 1022 | } while (strpos($texte, $boucle_placeholder) !== false); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | |
| 1039 | 1039 | // boucle anonyme ? |
| 1040 | 1040 | if (!strlen($id_boucle)) { |
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1041 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | $pos_debut_boucle = $pos_courante; |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | |
| 1052 | 1052 | $pos_avant = $boucle['pos_precond_inside']; |
| 1053 | 1053 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1062 | 1062 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | $result->id_boucle = $id_boucle; |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | } else { |
| 1118 | 1118 | $pos_milieu += 1; |
| 1119 | 1119 | |
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1121 | 1121 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1122 | 1122 | if ($pos_fin === false) { |
| 1123 | 1123 | $err_b = [ |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | else { |
| 1131 | 1131 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1132 | 1132 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1134 | 1134 | $search_from = $pos_milieu; |
| 1135 | 1135 | $nb_open = 1; |
| 1136 | 1136 | $nb_close = 1; |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | if ($boucle['pos_postcond']) { |
| 1171 | 1171 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1172 | 1172 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -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 | |
@@ -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 < (is_countable($p->param) ? count($p->param) : 0); $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 < (is_countable($p->param) ? count($p->param) : 0); $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 ((is_countable($champ->param[0]) ? count($champ->param[0]) : 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 ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 217 | 217 | } |
@@ -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 |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,42 +59,42 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | - if (strpbrk($f, ':')) { // Class::method |
|
| 72 | - $refl = new ReflectionMethod($f); |
|
| 73 | - } else { |
|
| 74 | - $refl = new ReflectionFunction($f); |
|
| 75 | - } |
|
| 76 | - $refs = $refl->getParameters(); |
|
| 77 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | - } else { |
|
| 81 | - $code = "$f($code$arglist)"; |
|
| 82 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | - } |
|
| 84 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | - if (($nb_args_f < $min_f)) { |
|
| 87 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - // le filtre n'existe pas, |
|
| 92 | - // on le notifie |
|
| 93 | - else { |
|
| 94 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | + if (strpbrk($f, ':')) { // Class::method |
|
| 72 | + $refl = new ReflectionMethod($f); |
|
| 73 | + } else { |
|
| 74 | + $refl = new ReflectionFunction($f); |
|
| 75 | + } |
|
| 76 | + $refs = $refl->getParameters(); |
|
| 77 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | + } else { |
|
| 81 | + $code = "$f($code$arglist)"; |
|
| 82 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | + } |
|
| 84 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | + if (($nb_args_f < $min_f)) { |
|
| 87 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + // le filtre n'existe pas, |
|
| 92 | + // on le notifie |
|
| 93 | + else { |
|
| 94 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $code; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Calculer un <INCLURE(xx.php)> |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | 119 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 120 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | - // si inexistant, on essaiera a l'execution |
|
| 122 | - if ($path = find_in_path($fichier)) { |
|
| 123 | - $path = "\"$path\""; |
|
| 124 | - } else { |
|
| 125 | - $path = "find_in_path(\"$fichier\")"; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 120 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | + // si inexistant, on essaiera a l'execution |
|
| 122 | + if ($path = find_in_path($fichier)) { |
|
| 123 | + $path = "\"$path\""; |
|
| 124 | + } else { |
|
| 125 | + $path = "find_in_path(\"$fichier\")"; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 140 | - // Securite |
|
| 141 | - if ( |
|
| 142 | - $p->interdire_scripts |
|
| 143 | - and $p->etoile != '**' |
|
| 144 | - ) { |
|
| 145 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | - $code = "interdire_scripts($code)"; |
|
| 147 | - } else { |
|
| 148 | - $code = interdire_scripts($r[2]); |
|
| 149 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $code; |
|
| 140 | + // Securite |
|
| 141 | + if ( |
|
| 142 | + $p->interdire_scripts |
|
| 143 | + and $p->etoile != '**' |
|
| 144 | + ) { |
|
| 145 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | + $code = "interdire_scripts($code)"; |
|
| 147 | + } else { |
|
| 148 | + $code = interdire_scripts($r[2]); |
|
| 149 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $code; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,30 +169,30 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | - $series_filtres = func_get_args(); |
|
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 175 | - |
|
| 176 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | - if ($skel['process_ins'] == 'php') { |
|
| 178 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer les couples de remplacement |
|
| 182 | - $replace = echapper_php_callback(); |
|
| 183 | - |
|
| 184 | - foreach ($series_filtres as $filtres) { |
|
| 185 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | - foreach ($filtres as $filtre) { |
|
| 187 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | - $corps = $f($corps); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // restaurer les echappements |
|
| 195 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 172 | + $series_filtres = func_get_args(); |
|
| 173 | + array_shift($series_filtres);// skel |
|
| 174 | + array_shift($series_filtres);// corps |
|
| 175 | + |
|
| 176 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | + if ($skel['process_ins'] == 'php') { |
|
| 178 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer les couples de remplacement |
|
| 182 | + $replace = echapper_php_callback(); |
|
| 183 | + |
|
| 184 | + foreach ($series_filtres as $filtres) { |
|
| 185 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | + foreach ($filtres as $filtre) { |
|
| 187 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | + $corps = $f($corps); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // restaurer les echappements |
|
| 195 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 212 | 212 | **/ |
| 213 | 213 | function echapper_php_callback($r = null) { |
| 214 | - static $src = []; |
|
| 215 | - static $dst = []; |
|
| 214 | + static $src = []; |
|
| 215 | + static $dst = []; |
|
| 216 | 216 | |
| 217 | - // si on recoit un tableau, on est en mode echappement |
|
| 218 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | - if (is_array($r)) { |
|
| 220 | - $dst[] = $r[0]; |
|
| 217 | + // si on recoit un tableau, on est en mode echappement |
|
| 218 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | + if (is_array($r)) { |
|
| 220 | + $dst[] = $r[0]; |
|
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | - } |
|
| 222 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | - // et on RAZ les remplacements |
|
| 227 | - $r = [$src, $dst]; |
|
| 228 | - $src = $dst = []; |
|
| 225 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | + // et on RAZ les remplacements |
|
| 227 | + $r = [$src, $dst]; |
|
| 228 | + $src = $dst = []; |
|
| 229 | 229 | |
| 230 | - return $r; |
|
| 230 | + return $r; |
|
| 231 | 231 | } |
@@ -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; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,193 +29,193 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = []; |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ''; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = 'prive/squelettes/'; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ''; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | - _DIR_PLUGIN_DIST, |
|
| 58 | - '/' |
|
| 59 | - ) : '')); |
|
| 60 | - } |
|
| 61 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | - } |
|
| 63 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | - |
|
| 65 | - $fond = $flux['args']['fond']; |
|
| 66 | - |
|
| 67 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | - $fond = substr($fond, $prefix_length); |
|
| 69 | - $squelette = $flux['data']; |
|
| 70 | - $ext = $flux['args']['ext']; |
|
| 71 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | - if ( |
|
| 73 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | - and $dir = explode('/', $fond) |
|
| 75 | - and count($dir) == 2 // pas un sous repertoire |
|
| 76 | - and $dir = reset($dir) |
|
| 77 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | - and defined($apl_constant) |
|
| 79 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | - ) { |
|
| 82 | - $flux['data'] = $pipe; |
|
| 83 | - |
|
| 84 | - return $flux; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | - $squelette = ''; |
|
| 90 | - $echafauder = ''; |
|
| 91 | - } |
|
| 92 | - if ($prepend) { |
|
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | - if ($squelette) { |
|
| 95 | - $flux['data'] = $squelette; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // gerer les squelettes non trouves |
|
| 100 | - // -> router vers les /dist.html |
|
| 101 | - // ou scaffolding ou page automatique les contenus |
|
| 102 | - if (!$squelette) { |
|
| 103 | - // si on est sur un ?page=XX non trouve |
|
| 104 | - if ( |
|
| 105 | - (isset($flux['args']['contexte'][$page]) |
|
| 106 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | - or ($fond == 'sommaire' |
|
| 110 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | - ) { |
|
| 112 | - // si on est sur un ?page=XX non trouve |
|
| 113 | - // se brancher sur contenu/xx si il existe |
|
| 114 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | - if (!isset($disponible[$fond])) { |
|
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($disponible[$fond]) { |
|
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // echafaudage : |
|
| 125 | - // si c'est un fond de contenu d'un objet en base |
|
| 126 | - // generer un fond automatique a la volee pour les webmestres |
|
| 127 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | - $type = $flux['args']['contexte'][$page]; |
|
| 131 | - } |
|
| 132 | - if (!isset($disponible[$type])) { |
|
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | - } |
|
| 135 | - if (is_string($disponible[$type])) { |
|
| 136 | - $flux['data'] = $disponible[$type]; |
|
| 137 | - } elseif ( |
|
| 138 | - $echafauder |
|
| 139 | - and include_spip('inc/autoriser') |
|
| 140 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | - and autoriser('echafauder', $type) |
|
| 142 | - and $is = $disponible[$type] |
|
| 143 | - and is_array($is) |
|
| 144 | - ) { |
|
| 145 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | - } else { |
|
| 147 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | - $prefix_path . $prepend, |
|
| 149 | - $z_contenu, |
|
| 150 | - '404', |
|
| 151 | - $ext, |
|
| 152 | - $echafauder |
|
| 153 | - )); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | - else { |
|
| 161 | - if ( |
|
| 162 | - $dir = explode('/', $fond) |
|
| 163 | - and $dir = reset($dir) |
|
| 164 | - and $dir !== $z_contenu |
|
| 165 | - and in_array($dir, $z_blocs) |
|
| 166 | - ) { |
|
| 167 | - $type = substr($fond, strlen("$dir/")); |
|
| 168 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | - $type = $flux['args']['contexte'][$page]; |
|
| 170 | - } |
|
| 171 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | - } |
|
| 174 | - if ($type == 'page' or $disponible[$type]) { |
|
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $squelette = $flux['data']; |
|
| 180 | - } |
|
| 181 | - // layout specifiques par type et compositions : |
|
| 182 | - // body-article.html |
|
| 183 | - // body-sommaire.html |
|
| 184 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | - // meme dossier que body.html |
|
| 186 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | - if ( |
|
| 188 | - isset($flux['args']['contexte']['type-page']) |
|
| 189 | - and ( |
|
| 190 | - (isset($flux['args']['contexte']['composition']) |
|
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | - or |
|
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - $flux['data'] = $f; |
|
| 197 | - } |
|
| 198 | - } elseif ( |
|
| 199 | - $fond == 'structure' |
|
| 200 | - and z_sanitize_var_zajax() |
|
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | - ) { |
|
| 203 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | - } // chercher le fond correspondant a la composition |
|
| 205 | - elseif ( |
|
| 206 | - isset($flux['args']['contexte']['composition']) |
|
| 207 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | - and $dir = substr($fond, $prefix_length) |
|
| 209 | - and $dir = explode('/', $dir) |
|
| 210 | - and $dir = reset($dir) |
|
| 211 | - and in_array($dir, $z_blocs) |
|
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | - ) { |
|
| 214 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = []; |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ''; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = 'prive/squelettes/'; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ''; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | + _DIR_PLUGIN_DIST, |
|
| 58 | + '/' |
|
| 59 | + ) : '')); |
|
| 60 | + } |
|
| 61 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | + } |
|
| 63 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | + |
|
| 65 | + $fond = $flux['args']['fond']; |
|
| 66 | + |
|
| 67 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | + $fond = substr($fond, $prefix_length); |
|
| 69 | + $squelette = $flux['data']; |
|
| 70 | + $ext = $flux['args']['ext']; |
|
| 71 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | + if ( |
|
| 73 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | + and $dir = explode('/', $fond) |
|
| 75 | + and count($dir) == 2 // pas un sous repertoire |
|
| 76 | + and $dir = reset($dir) |
|
| 77 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | + and defined($apl_constant) |
|
| 79 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | + ) { |
|
| 82 | + $flux['data'] = $pipe; |
|
| 83 | + |
|
| 84 | + return $flux; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | + $squelette = ''; |
|
| 90 | + $echafauder = ''; |
|
| 91 | + } |
|
| 92 | + if ($prepend) { |
|
| 93 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | + if ($squelette) { |
|
| 95 | + $flux['data'] = $squelette; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // gerer les squelettes non trouves |
|
| 100 | + // -> router vers les /dist.html |
|
| 101 | + // ou scaffolding ou page automatique les contenus |
|
| 102 | + if (!$squelette) { |
|
| 103 | + // si on est sur un ?page=XX non trouve |
|
| 104 | + if ( |
|
| 105 | + (isset($flux['args']['contexte'][$page]) |
|
| 106 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | + or ($fond == 'sommaire' |
|
| 110 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | + ) { |
|
| 112 | + // si on est sur un ?page=XX non trouve |
|
| 113 | + // se brancher sur contenu/xx si il existe |
|
| 114 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | + if (!isset($disponible[$fond])) { |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($disponible[$fond]) { |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // echafaudage : |
|
| 125 | + // si c'est un fond de contenu d'un objet en base |
|
| 126 | + // generer un fond automatique a la volee pour les webmestres |
|
| 127 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | + $type = $flux['args']['contexte'][$page]; |
|
| 131 | + } |
|
| 132 | + if (!isset($disponible[$type])) { |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | + } |
|
| 135 | + if (is_string($disponible[$type])) { |
|
| 136 | + $flux['data'] = $disponible[$type]; |
|
| 137 | + } elseif ( |
|
| 138 | + $echafauder |
|
| 139 | + and include_spip('inc/autoriser') |
|
| 140 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | + and autoriser('echafauder', $type) |
|
| 142 | + and $is = $disponible[$type] |
|
| 143 | + and is_array($is) |
|
| 144 | + ) { |
|
| 145 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | + } else { |
|
| 147 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | + $prefix_path . $prepend, |
|
| 149 | + $z_contenu, |
|
| 150 | + '404', |
|
| 151 | + $ext, |
|
| 152 | + $echafauder |
|
| 153 | + )); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | + else { |
|
| 161 | + if ( |
|
| 162 | + $dir = explode('/', $fond) |
|
| 163 | + and $dir = reset($dir) |
|
| 164 | + and $dir !== $z_contenu |
|
| 165 | + and in_array($dir, $z_blocs) |
|
| 166 | + ) { |
|
| 167 | + $type = substr($fond, strlen("$dir/")); |
|
| 168 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | + $type = $flux['args']['contexte'][$page]; |
|
| 170 | + } |
|
| 171 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | + } |
|
| 174 | + if ($type == 'page' or $disponible[$type]) { |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $squelette = $flux['data']; |
|
| 180 | + } |
|
| 181 | + // layout specifiques par type et compositions : |
|
| 182 | + // body-article.html |
|
| 183 | + // body-sommaire.html |
|
| 184 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | + // meme dossier que body.html |
|
| 186 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | + if ( |
|
| 188 | + isset($flux['args']['contexte']['type-page']) |
|
| 189 | + and ( |
|
| 190 | + (isset($flux['args']['contexte']['composition']) |
|
| 191 | + and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | + or |
|
| 193 | + file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + $flux['data'] = $f; |
|
| 197 | + } |
|
| 198 | + } elseif ( |
|
| 199 | + $fond == 'structure' |
|
| 200 | + and z_sanitize_var_zajax() |
|
| 201 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | + ) { |
|
| 203 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | + } // chercher le fond correspondant a la composition |
|
| 205 | + elseif ( |
|
| 206 | + isset($flux['args']['contexte']['composition']) |
|
| 207 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | + and $dir = substr($fond, $prefix_length) |
|
| 209 | + and $dir = explode('/', $dir) |
|
| 210 | + and $dir = reset($dir) |
|
| 211 | + and in_array($dir, $z_blocs) |
|
| 212 | + and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | + ) { |
|
| 214 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return $flux; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | * @return array |
| 226 | 226 | */ |
| 227 | 227 | function z_blocs($espace_prive = false) { |
| 228 | - if ($espace_prive) { |
|
| 229 | - return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | - 'contenu', |
|
| 231 | - 'navigation', |
|
| 232 | - 'extra', |
|
| 233 | - 'head', |
|
| 234 | - 'hierarchie', |
|
| 235 | - 'top' |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 228 | + if ($espace_prive) { |
|
| 229 | + return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | + 'contenu', |
|
| 231 | + 'navigation', |
|
| 232 | + 'extra', |
|
| 233 | + 'head', |
|
| 234 | + 'hierarchie', |
|
| 235 | + 'top' |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | 253 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 254 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | - return $d; |
|
| 256 | - } |
|
| 254 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | + return $d; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 258 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * `true` si on peut l'utiliser, `false` sinon. |
| 270 | 270 | **/ |
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | - if ( |
|
| 273 | - !_ZCORE_EXCLURE_PATH |
|
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | - ) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return false; |
|
| 272 | + if ( |
|
| 273 | + !_ZCORE_EXCLURE_PATH |
|
| 274 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | + ) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return false; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 297 | - if ( |
|
| 298 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | - ) { |
|
| 301 | - return substr($f, 0, -strlen(".$ext")); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 297 | + if ( |
|
| 298 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | + ) { |
|
| 301 | + return substr($f, 0, -strlen(".$ext")); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,52 +313,52 @@ discard block |
||
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | 315 | function z_echafaudable($type) { |
| 316 | - static $pages = null; |
|
| 317 | - static $echafaudable = []; |
|
| 318 | - if (isset($echafaudable[$type])) { |
|
| 319 | - return $echafaudable[$type]; |
|
| 320 | - } |
|
| 321 | - if (preg_match(',[^\w],', $type)) { |
|
| 322 | - return $echafaudable[$type] = false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if (test_espace_prive()) { |
|
| 326 | - if (!function_exists('trouver_objet_exec')) { |
|
| 327 | - include_spip('inc/pipelines_ecrire'); |
|
| 328 | - } |
|
| 329 | - if ($e = trouver_objet_exec($type)) { |
|
| 330 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | - } else { |
|
| 332 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | - if ( |
|
| 334 | - ($t = objet_type($type, false)) !== $type |
|
| 335 | - and $e = trouver_objet_exec($t) |
|
| 336 | - ) { |
|
| 337 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if (is_null($pages)) { |
|
| 342 | - $pages = []; |
|
| 343 | - $liste = lister_tables_objets_sql(); |
|
| 344 | - foreach ($liste as $t => $d) { |
|
| 345 | - if ($d['page']) { |
|
| 346 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - if (!isset($pages[$type])) { |
|
| 351 | - return $echafaudable[$type] = false; |
|
| 352 | - } |
|
| 353 | - if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $echafaudable[$type] = $pages[$type]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $echafaudable[$type] = false; |
|
| 316 | + static $pages = null; |
|
| 317 | + static $echafaudable = []; |
|
| 318 | + if (isset($echafaudable[$type])) { |
|
| 319 | + return $echafaudable[$type]; |
|
| 320 | + } |
|
| 321 | + if (preg_match(',[^\w],', $type)) { |
|
| 322 | + return $echafaudable[$type] = false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if (test_espace_prive()) { |
|
| 326 | + if (!function_exists('trouver_objet_exec')) { |
|
| 327 | + include_spip('inc/pipelines_ecrire'); |
|
| 328 | + } |
|
| 329 | + if ($e = trouver_objet_exec($type)) { |
|
| 330 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | + } else { |
|
| 332 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | + if ( |
|
| 334 | + ($t = objet_type($type, false)) !== $type |
|
| 335 | + and $e = trouver_objet_exec($t) |
|
| 336 | + ) { |
|
| 337 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if (is_null($pages)) { |
|
| 342 | + $pages = []; |
|
| 343 | + $liste = lister_tables_objets_sql(); |
|
| 344 | + foreach ($liste as $t => $d) { |
|
| 345 | + if ($d['page']) { |
|
| 346 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + if (!isset($pages[$type])) { |
|
| 351 | + return $echafaudable[$type] = false; |
|
| 352 | + } |
|
| 353 | + if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $echafaudable[$type] = $pages[$type]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $echafaudable[$type] = false; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -375,46 +375,46 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | 377 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 378 | - $scaffold = ''; |
|
| 379 | - |
|
| 380 | - // page objet ou objet_edit |
|
| 381 | - if (is_array($desc_exec)) { |
|
| 382 | - $type = $desc_exec['type']; |
|
| 383 | - $primary = $desc_exec['id_table_objet']; |
|
| 384 | - |
|
| 385 | - if ($desc_exec['edition'] === false) { |
|
| 386 | - $fond = 'objet'; |
|
| 387 | - } else { |
|
| 388 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | - $desc = $trouver_table($table_sql); |
|
| 390 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | - $fond = 'objet_edit'; |
|
| 392 | - } else { |
|
| 393 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $dir = z_blocs(test_espace_prive()); |
|
| 397 | - $dir = reset($dir); |
|
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | - } // page objets |
|
| 400 | - elseif ($type = $desc_exec and 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 | } |
@@ -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 | - string $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + string $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 ?: 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 ?: 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 ($res[$ids] ?? ''); |
|
| 344 | + return ($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 [$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 ?: ''); |
|
| 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 [$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 ?: ''); |
|
| 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,20 +535,20 @@ 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 | - return $f($arg, ...$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 | + return $f($arg, ...$args); |
|
| 554 | 554 | } |
@@ -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 | function assembler($fond, string $connect = '') { |
| 32 | 32 | |
| 33 | - $chemin_cache = null; |
|
| 34 | - $lastmodified = null; |
|
| 35 | - $res = null; |
|
| 36 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | - |
|
| 40 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | - ',\.[a-zA-Z0-9]*$,', |
|
| 44 | - '', |
|
| 45 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | - ); |
|
| 47 | - // Cette fonction est utilisee deux fois |
|
| 48 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | - if ($cacher) { |
|
| 52 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | - } else { |
|
| 54 | - $GLOBALS['use_cache'] = -1; |
|
| 55 | - } |
|
| 56 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | - if ($res) { |
|
| 58 | - return ['texte' => $res]; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$chemin_cache || !$lastmodified) { |
|
| 62 | - $lastmodified = time(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | - $calculer_page = true; |
|
| 67 | - |
|
| 68 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | - // pages sont dynamiques) |
|
| 71 | - if ( |
|
| 72 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | - and $chemin_cache |
|
| 75 | - and isset($page['entetes']) |
|
| 76 | - and isset($page['entetes']['Cache-Control']) |
|
| 77 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | - ) { |
|
| 80 | - $since = preg_replace( |
|
| 81 | - '/;.*/', |
|
| 82 | - '', |
|
| 83 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | - ); |
|
| 85 | - $since = str_replace('GMT', '', $since); |
|
| 86 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | - $page['status'] = 304; |
|
| 88 | - $headers_only = true; |
|
| 89 | - $calculer_page = false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | - if (!$calculer_page) { |
|
| 96 | - $page['texte'] = ''; |
|
| 97 | - } else { |
|
| 98 | - // si la page est prise dans le cache |
|
| 99 | - if (!$GLOBALS['use_cache']) { |
|
| 100 | - // Informer les boutons d'admin du contexte |
|
| 101 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | - |
|
| 104 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | - // d'inversion url => objet |
|
| 106 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | - #unset($_ENV['url_propre']); |
|
| 109 | - } else { |
|
| 110 | - // Compat ascendante : |
|
| 111 | - // 1. $contexte est global |
|
| 112 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | - // et calculer la page |
|
| 114 | - if (!test_espace_prive()) { |
|
| 115 | - include_spip('inc/urls'); |
|
| 116 | - [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | - nettoyer_uri(), |
|
| 118 | - $fond, |
|
| 119 | - $GLOBALS['contexte'], |
|
| 120 | - true |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - // squelette par defaut |
|
| 124 | - if (!strlen($fond ?? '')) { |
|
| 125 | - $fond = 'sommaire'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // produire la page : peut mettre a jour $lastmodified |
|
| 129 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | - $page = $produire_page( |
|
| 131 | - $fond, |
|
| 132 | - $GLOBALS['contexte'], |
|
| 133 | - $GLOBALS['use_cache'], |
|
| 134 | - $chemin_cache, |
|
| 135 | - null, |
|
| 136 | - $page, |
|
| 137 | - $lastmodified, |
|
| 138 | - $connect |
|
| 139 | - ); |
|
| 140 | - if ($page === '') { |
|
| 141 | - $erreur = _T( |
|
| 142 | - 'info_erreur_squelette2', |
|
| 143 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | - ); |
|
| 145 | - erreur_squelette($erreur); |
|
| 146 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($page and $chemin_cache) { |
|
| 152 | - $page['cache'] = $chemin_cache; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - auto_content_type($page); |
|
| 156 | - |
|
| 157 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | - |
|
| 159 | - // Definir les entetes si ce n'est fait |
|
| 160 | - if (!$GLOBALS['flag_preserver']) { |
|
| 161 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | - if ( |
|
| 163 | - trim($page['texte']) === '' |
|
| 164 | - and _VAR_MODE !== 'debug' |
|
| 165 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | - ) { |
|
| 167 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | - } |
|
| 170 | - // pas de cache client en mode 'observation' |
|
| 171 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 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; |
|
| 33 | + $chemin_cache = null; |
|
| 34 | + $lastmodified = null; |
|
| 35 | + $res = null; |
|
| 36 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | + |
|
| 40 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | + ',\.[a-zA-Z0-9]*$,', |
|
| 44 | + '', |
|
| 45 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | + ); |
|
| 47 | + // Cette fonction est utilisee deux fois |
|
| 48 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | + if ($cacher) { |
|
| 52 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | + } else { |
|
| 54 | + $GLOBALS['use_cache'] = -1; |
|
| 55 | + } |
|
| 56 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | + if ($res) { |
|
| 58 | + return ['texte' => $res]; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$chemin_cache || !$lastmodified) { |
|
| 62 | + $lastmodified = time(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | + $calculer_page = true; |
|
| 67 | + |
|
| 68 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | + // pages sont dynamiques) |
|
| 71 | + if ( |
|
| 72 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | + and $chemin_cache |
|
| 75 | + and isset($page['entetes']) |
|
| 76 | + and isset($page['entetes']['Cache-Control']) |
|
| 77 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | + ) { |
|
| 80 | + $since = preg_replace( |
|
| 81 | + '/;.*/', |
|
| 82 | + '', |
|
| 83 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | + ); |
|
| 85 | + $since = str_replace('GMT', '', $since); |
|
| 86 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | + $page['status'] = 304; |
|
| 88 | + $headers_only = true; |
|
| 89 | + $calculer_page = false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | + if (!$calculer_page) { |
|
| 96 | + $page['texte'] = ''; |
|
| 97 | + } else { |
|
| 98 | + // si la page est prise dans le cache |
|
| 99 | + if (!$GLOBALS['use_cache']) { |
|
| 100 | + // Informer les boutons d'admin du contexte |
|
| 101 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | + |
|
| 104 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | + // d'inversion url => objet |
|
| 106 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | + #unset($_ENV['url_propre']); |
|
| 109 | + } else { |
|
| 110 | + // Compat ascendante : |
|
| 111 | + // 1. $contexte est global |
|
| 112 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | + // et calculer la page |
|
| 114 | + if (!test_espace_prive()) { |
|
| 115 | + include_spip('inc/urls'); |
|
| 116 | + [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | + nettoyer_uri(), |
|
| 118 | + $fond, |
|
| 119 | + $GLOBALS['contexte'], |
|
| 120 | + true |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + // squelette par defaut |
|
| 124 | + if (!strlen($fond ?? '')) { |
|
| 125 | + $fond = 'sommaire'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // produire la page : peut mettre a jour $lastmodified |
|
| 129 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | + $page = $produire_page( |
|
| 131 | + $fond, |
|
| 132 | + $GLOBALS['contexte'], |
|
| 133 | + $GLOBALS['use_cache'], |
|
| 134 | + $chemin_cache, |
|
| 135 | + null, |
|
| 136 | + $page, |
|
| 137 | + $lastmodified, |
|
| 138 | + $connect |
|
| 139 | + ); |
|
| 140 | + if ($page === '') { |
|
| 141 | + $erreur = _T( |
|
| 142 | + 'info_erreur_squelette2', |
|
| 143 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | + ); |
|
| 145 | + erreur_squelette($erreur); |
|
| 146 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($page and $chemin_cache) { |
|
| 152 | + $page['cache'] = $chemin_cache; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + auto_content_type($page); |
|
| 156 | + |
|
| 157 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | + |
|
| 159 | + // Definir les entetes si ce n'est fait |
|
| 160 | + if (!$GLOBALS['flag_preserver']) { |
|
| 161 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | + if ( |
|
| 163 | + trim($page['texte']) === '' |
|
| 164 | + and _VAR_MODE !== 'debug' |
|
| 165 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | + ) { |
|
| 167 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | + } |
|
| 170 | + // pas de cache client en mode 'observation' |
|
| 171 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 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 | /** |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function calculer_contexte() { |
| 210 | 210 | |
| 211 | - $contexte = []; |
|
| 212 | - foreach ($_GET as $var => $val) { |
|
| 213 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | - $contexte[$var] = $val; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - foreach ($_POST as $var => $val) { |
|
| 218 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | - $contexte[$var] = $val; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $contexte; |
|
| 211 | + $contexte = []; |
|
| 212 | + foreach ($_GET as $var => $val) { |
|
| 213 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | + $contexte[$var] = $val; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + foreach ($_POST as $var => $val) { |
|
| 218 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | + $contexte[$var] = $val; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $contexte; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,25 +231,25 @@ discard block |
||
| 231 | 231 | * @return array |
| 232 | 232 | */ |
| 233 | 233 | function calculer_contexte_implicite() { |
| 234 | - static $notes = null; |
|
| 235 | - if (is_null($notes)) { |
|
| 236 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | - } |
|
| 238 | - $contexte_implicite = [ |
|
| 239 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | - 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | - 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | - 'espace' => test_espace_prive(), |
|
| 243 | - 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | - 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | - ]; |
|
| 248 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $contexte_implicite; |
|
| 234 | + static $notes = null; |
|
| 235 | + if (is_null($notes)) { |
|
| 236 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | + } |
|
| 238 | + $contexte_implicite = [ |
|
| 239 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | + 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | + 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | + 'espace' => test_espace_prive(), |
|
| 243 | + 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | + 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | + ]; |
|
| 248 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $contexte_implicite; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // |
@@ -258,55 +258,55 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | function auto_content_type($page) { |
| 260 | 260 | |
| 261 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | - $page['texte'] |
|
| 265 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | - } |
|
| 261 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | + $page['texte'] |
|
| 265 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | + } |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | function inclure_page($fond, $contexte, string $connect = '') { |
| 270 | - $use_cache = null; |
|
| 271 | - $chemin_cache = null; |
|
| 272 | - $lastinclude = null; |
|
| 273 | - $res = null; |
|
| 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(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 270 | + $use_cache = null; |
|
| 271 | + $chemin_cache = null; |
|
| 272 | + $lastinclude = null; |
|
| 273 | + $res = null; |
|
| 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(($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 | /** |
@@ -392,101 +392,101 @@ discard block |
||
| 392 | 392 | * @return string |
| 393 | 393 | */ |
| 394 | 394 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 395 | - if (is_array($texte)) { |
|
| 396 | - [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | - |
|
| 398 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | - $d = $GLOBALS['delais'] ?? null; |
|
| 400 | - $GLOBALS['delais'] = $delainc; |
|
| 401 | - |
|
| 402 | - $page = recuperer_fond( |
|
| 403 | - $fond, |
|
| 404 | - $contexte_inclus, |
|
| 405 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - $texte = $page['texte']; |
|
| 409 | - |
|
| 410 | - $GLOBALS['delais'] = $d; |
|
| 411 | - // Faire remonter les entetes |
|
| 412 | - if ( |
|
| 413 | - isset($page['entetes']) |
|
| 414 | - and is_array($page['entetes']) |
|
| 415 | - ) { |
|
| 416 | - // mais pas toutes |
|
| 417 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | - unset($page['entetes']['Content-Type']); |
|
| 419 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | - $GLOBALS['page']['entetes'] = []; |
|
| 422 | - } |
|
| 423 | - $GLOBALS['page']['entetes'] = |
|
| 424 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | - if ( |
|
| 429 | - isset($page['contexte']['_pipelines']) |
|
| 430 | - and is_array($page['contexte']['_pipelines']) |
|
| 431 | - and count($page['contexte']['_pipelines']) |
|
| 432 | - ) { |
|
| 433 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | - $args['contexte'] = $page['contexte']; |
|
| 435 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | - $texte = pipeline( |
|
| 437 | - $pipe, |
|
| 438 | - [ |
|
| 439 | - 'data' => $texte, |
|
| 440 | - 'args' => $args |
|
| 441 | - ] |
|
| 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($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 | - } |
|
| 395 | + if (is_array($texte)) { |
|
| 396 | + [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | + |
|
| 398 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | + $d = $GLOBALS['delais'] ?? null; |
|
| 400 | + $GLOBALS['delais'] = $delainc; |
|
| 401 | + |
|
| 402 | + $page = recuperer_fond( |
|
| 403 | + $fond, |
|
| 404 | + $contexte_inclus, |
|
| 405 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + $texte = $page['texte']; |
|
| 409 | + |
|
| 410 | + $GLOBALS['delais'] = $d; |
|
| 411 | + // Faire remonter les entetes |
|
| 412 | + if ( |
|
| 413 | + isset($page['entetes']) |
|
| 414 | + and is_array($page['entetes']) |
|
| 415 | + ) { |
|
| 416 | + // mais pas toutes |
|
| 417 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | + unset($page['entetes']['Content-Type']); |
|
| 419 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | + $GLOBALS['page']['entetes'] = []; |
|
| 422 | + } |
|
| 423 | + $GLOBALS['page']['entetes'] = |
|
| 424 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | + if ( |
|
| 429 | + isset($page['contexte']['_pipelines']) |
|
| 430 | + and is_array($page['contexte']['_pipelines']) |
|
| 431 | + and count($page['contexte']['_pipelines']) |
|
| 432 | + ) { |
|
| 433 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | + $args['contexte'] = $page['contexte']; |
|
| 435 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | + $texte = pipeline( |
|
| 437 | + $pipe, |
|
| 438 | + [ |
|
| 439 | + 'data' => $texte, |
|
| 440 | + 'args' => $args |
|
| 441 | + ] |
|
| 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($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 | function message_page_indisponible($page, $contexte) { |
| 460 | - static $deja = false; |
|
| 461 | - if ($deja) { |
|
| 462 | - return 'erreur'; |
|
| 463 | - } |
|
| 464 | - $codes = [ |
|
| 465 | - '404' => '404 Not Found', |
|
| 466 | - '503' => '503 Service Unavailable', |
|
| 467 | - ]; |
|
| 468 | - |
|
| 469 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | - if (!isset($contexte['lang'])) { |
|
| 473 | - include_spip('inc/lang'); |
|
| 474 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $deja = true; |
|
| 478 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | - // ex restriction d'acces => 401 |
|
| 480 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | - |
|
| 482 | - // produire la page d'erreur |
|
| 483 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | - if (!$page) { |
|
| 485 | - $page = inclure_page('404', $contexte); |
|
| 486 | - } |
|
| 487 | - $page['status'] = $contexte['status']; |
|
| 488 | - |
|
| 489 | - return $page; |
|
| 460 | + static $deja = false; |
|
| 461 | + if ($deja) { |
|
| 462 | + return 'erreur'; |
|
| 463 | + } |
|
| 464 | + $codes = [ |
|
| 465 | + '404' => '404 Not Found', |
|
| 466 | + '503' => '503 Service Unavailable', |
|
| 467 | + ]; |
|
| 468 | + |
|
| 469 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | + if (!isset($contexte['lang'])) { |
|
| 473 | + include_spip('inc/lang'); |
|
| 474 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $deja = true; |
|
| 478 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | + // ex restriction d'acces => 401 |
|
| 480 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | + |
|
| 482 | + // produire la page d'erreur |
|
| 483 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | + if (!$page) { |
|
| 485 | + $page = inclure_page('404', $contexte); |
|
| 486 | + } |
|
| 487 | + $page['status'] = $contexte['status']; |
|
| 488 | + |
|
| 489 | + return $page; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -498,44 +498,44 @@ discard block |
||
| 498 | 498 | * @return mixed |
| 499 | 499 | */ |
| 500 | 500 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 501 | - static $balise_dyn_appellee_par_modele = null; |
|
| 502 | - switch ($operation) { |
|
| 503 | - case 'read': |
|
| 504 | - return $balise_dyn_appellee_par_modele; |
|
| 505 | - case 'reset': |
|
| 506 | - $balise_dyn_appellee_par_modele = null; |
|
| 507 | - return null; |
|
| 508 | - case 'set': |
|
| 509 | - default: |
|
| 510 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | - return $arg; |
|
| 512 | - } |
|
| 501 | + static $balise_dyn_appellee_par_modele = null; |
|
| 502 | + switch ($operation) { |
|
| 503 | + case 'read': |
|
| 504 | + return $balise_dyn_appellee_par_modele; |
|
| 505 | + case 'reset': |
|
| 506 | + $balise_dyn_appellee_par_modele = null; |
|
| 507 | + return null; |
|
| 508 | + case 'set': |
|
| 509 | + default: |
|
| 510 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | + return $arg; |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // temporairement ici : a mettre dans le futur inc/modeles |
| 516 | 516 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 517 | 517 | function creer_contexte_de_modele($args) { |
| 518 | - $contexte = []; |
|
| 519 | - foreach ($args as $var => $val) { |
|
| 520 | - if (is_int($var)) { // argument pas formate |
|
| 521 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | - $var = 'align'; |
|
| 523 | - $contexte[$var] = $val; |
|
| 524 | - } else { |
|
| 525 | - $args = explode('=', $val); |
|
| 526 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | - } else // notation abregee |
|
| 529 | - { |
|
| 530 | - $contexte[trim($val)] = trim($val); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - } else { |
|
| 534 | - $contexte[$var] = $val; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $contexte; |
|
| 518 | + $contexte = []; |
|
| 519 | + foreach ($args as $var => $val) { |
|
| 520 | + if (is_int($var)) { // argument pas formate |
|
| 521 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | + $var = 'align'; |
|
| 523 | + $contexte[$var] = $val; |
|
| 524 | + } else { |
|
| 525 | + $args = explode('=', $val); |
|
| 526 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | + } else // notation abregee |
|
| 529 | + { |
|
| 530 | + $contexte[trim($val)] = trim($val); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + } else { |
|
| 534 | + $contexte[$var] = $val; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $contexte; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -550,43 +550,43 @@ discard block |
||
| 550 | 550 | * @return string |
| 551 | 551 | */ |
| 552 | 552 | function styliser_modele($modele, $id, $contexte = null) { |
| 553 | - static $styliseurs = null; |
|
| 554 | - if (is_null($styliseurs)) { |
|
| 555 | - $tables_objet = lister_tables_objets_sql(); |
|
| 556 | - foreach ($tables_objet as $table => $desc) { |
|
| 557 | - if ( |
|
| 558 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | - and function_exists($desc['modeles_styliser']) |
|
| 561 | - ) { |
|
| 562 | - $primary = id_table_objet($table); |
|
| 563 | - foreach ($desc['modeles'] as $m) { |
|
| 564 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (isset($styliseurs[$modele])) { |
|
| 571 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | - $primary = $styliseurs[$modele]['primary']; |
|
| 573 | - if (is_null($id) and $contexte) { |
|
| 574 | - if (isset($contexte['id'])) { |
|
| 575 | - $id = $contexte['id']; |
|
| 576 | - } elseif (isset($contexte[$primary])) { |
|
| 577 | - $id = $contexte[$primary]; |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - if (is_null($id)) { |
|
| 581 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | - erreur_squelette($msg); |
|
| 583 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | - $id = 0; |
|
| 585 | - } |
|
| 586 | - $modele = $styliseur($modele, $id); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $modele; |
|
| 553 | + static $styliseurs = null; |
|
| 554 | + if (is_null($styliseurs)) { |
|
| 555 | + $tables_objet = lister_tables_objets_sql(); |
|
| 556 | + foreach ($tables_objet as $table => $desc) { |
|
| 557 | + if ( |
|
| 558 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | + and function_exists($desc['modeles_styliser']) |
|
| 561 | + ) { |
|
| 562 | + $primary = id_table_objet($table); |
|
| 563 | + foreach ($desc['modeles'] as $m) { |
|
| 564 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (isset($styliseurs[$modele])) { |
|
| 571 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | + $primary = $styliseurs[$modele]['primary']; |
|
| 573 | + if (is_null($id) and $contexte) { |
|
| 574 | + if (isset($contexte['id'])) { |
|
| 575 | + $id = $contexte['id']; |
|
| 576 | + } elseif (isset($contexte[$primary])) { |
|
| 577 | + $id = $contexte[$primary]; |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + if (is_null($id)) { |
|
| 581 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + erreur_squelette($msg); |
|
| 583 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | + $id = 0; |
|
| 585 | + } |
|
| 586 | + $modele = $styliseur($modele, $id); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $modele; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -603,102 +603,102 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 605 | 605 | |
| 606 | - static $compteur; |
|
| 607 | - if (++$compteur > 10) { |
|
| 608 | - return ''; |
|
| 609 | - } # ne pas boucler indefiniment |
|
| 610 | - |
|
| 611 | - $type = strtolower($type); |
|
| 612 | - $type = styliser_modele($type, $id); |
|
| 613 | - |
|
| 614 | - $fond = $class = ''; |
|
| 615 | - |
|
| 616 | - $params = array_filter(explode('|', $params)); |
|
| 617 | - if ($params) { |
|
| 618 | - $soustype = current($params); |
|
| 619 | - $soustype = strtolower(trim($soustype)); |
|
| 620 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | - $soustype = next($params); |
|
| 622 | - $soustype = strtolower($soustype); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | - $fond = ''; |
|
| 628 | - $class = $soustype; |
|
| 629 | - } |
|
| 630 | - // enlever le sous type des params |
|
| 631 | - $params = array_diff($params, [$soustype]); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | - |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - $fond = 'modeles/' . $fond; |
|
| 642 | - // Creer le contexte |
|
| 643 | - $contexte = $env; |
|
| 644 | - $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 |
|
| 645 | - |
|
| 646 | - // Le numero du modele est mis dans l'environnement |
|
| 647 | - // d'une part sous l'identifiant "id" |
|
| 648 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | - // par la fonction id_table_objet, |
|
| 650 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | - $_id = id_table_objet($type); |
|
| 652 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | - |
|
| 654 | - if (isset($class)) { |
|
| 655 | - $contexte['class'] = $class; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | - if ($lien) { |
|
| 660 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | - $contexte['lien_class'] = $lien['class']; |
|
| 663 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | - $contexte['lien_title'] = $lien['title']; |
|
| 665 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - // Traiter les parametres |
|
| 669 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | - $arg_list = creer_contexte_de_modele($params); |
|
| 671 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | - $contexte = array_merge($contexte, $arg_list); |
|
| 673 | - |
|
| 674 | - // Appliquer le modele avec le contexte |
|
| 675 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | - |
|
| 677 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | - if ( |
|
| 681 | - strstr( |
|
| 682 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | - 'spip_lien_ok' |
|
| 684 | - ) |
|
| 685 | - ) { |
|
| 686 | - $retour = inserer_attribut( |
|
| 687 | - $retour, |
|
| 688 | - 'class', |
|
| 689 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | - ); |
|
| 691 | - } else { |
|
| 692 | - if ($lien) { |
|
| 693 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $compteur--; |
|
| 698 | - |
|
| 699 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | - : $retour; |
|
| 606 | + static $compteur; |
|
| 607 | + if (++$compteur > 10) { |
|
| 608 | + return ''; |
|
| 609 | + } # ne pas boucler indefiniment |
|
| 610 | + |
|
| 611 | + $type = strtolower($type); |
|
| 612 | + $type = styliser_modele($type, $id); |
|
| 613 | + |
|
| 614 | + $fond = $class = ''; |
|
| 615 | + |
|
| 616 | + $params = array_filter(explode('|', $params)); |
|
| 617 | + if ($params) { |
|
| 618 | + $soustype = current($params); |
|
| 619 | + $soustype = strtolower(trim($soustype)); |
|
| 620 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | + $soustype = next($params); |
|
| 622 | + $soustype = strtolower($soustype); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | + $fond = ''; |
|
| 628 | + $class = $soustype; |
|
| 629 | + } |
|
| 630 | + // enlever le sous type des params |
|
| 631 | + $params = array_diff($params, [$soustype]); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | + |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + $fond = 'modeles/' . $fond; |
|
| 642 | + // Creer le contexte |
|
| 643 | + $contexte = $env; |
|
| 644 | + $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 |
|
| 645 | + |
|
| 646 | + // Le numero du modele est mis dans l'environnement |
|
| 647 | + // d'une part sous l'identifiant "id" |
|
| 648 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | + // par la fonction id_table_objet, |
|
| 650 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | + $_id = id_table_objet($type); |
|
| 652 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | + |
|
| 654 | + if (isset($class)) { |
|
| 655 | + $contexte['class'] = $class; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | + if ($lien) { |
|
| 660 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | + $contexte['lien_class'] = $lien['class']; |
|
| 663 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | + $contexte['lien_title'] = $lien['title']; |
|
| 665 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + // Traiter les parametres |
|
| 669 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | + $arg_list = creer_contexte_de_modele($params); |
|
| 671 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | + $contexte = array_merge($contexte, $arg_list); |
|
| 673 | + |
|
| 674 | + // Appliquer le modele avec le contexte |
|
| 675 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | + |
|
| 677 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | + if ( |
|
| 681 | + strstr( |
|
| 682 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | + 'spip_lien_ok' |
|
| 684 | + ) |
|
| 685 | + ) { |
|
| 686 | + $retour = inserer_attribut( |
|
| 687 | + $retour, |
|
| 688 | + 'class', |
|
| 689 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | + ); |
|
| 691 | + } else { |
|
| 692 | + if ($lien) { |
|
| 693 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $compteur--; |
|
| 698 | + |
|
| 699 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | + : $retour; |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -707,105 +707,105 @@ discard block |
||
| 707 | 707 | // recuperer_fond($fond,$contexte,array('raw'=>true)) |
| 708 | 708 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 709 | 709 | |
| 710 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | - |
|
| 712 | - if (!$page) { |
|
| 713 | - return $page; |
|
| 714 | - } |
|
| 715 | - // eval $page et affecte $res |
|
| 716 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | - |
|
| 718 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | - // a destination de public/parametrer |
|
| 720 | - // pour remonter vers les inclusions appelantes |
|
| 721 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | - if ( |
|
| 724 | - isset($page['invalideurs']) |
|
| 725 | - and isset($page['invalideurs']['session']) |
|
| 726 | - ) { |
|
| 727 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $page; |
|
| 710 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | + |
|
| 712 | + if (!$page) { |
|
| 713 | + return $page; |
|
| 714 | + } |
|
| 715 | + // eval $page et affecte $res |
|
| 716 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | + |
|
| 718 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | + // a destination de public/parametrer |
|
| 720 | + // pour remonter vers les inclusions appelantes |
|
| 721 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | + if ( |
|
| 724 | + isset($page['invalideurs']) |
|
| 725 | + and isset($page['invalideurs']['session']) |
|
| 726 | + ) { |
|
| 727 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $page; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
| 734 | 734 | function page_base_href(&$texte) { |
| 735 | - static $set_html_base = null; |
|
| 736 | - if (is_null($set_html_base)) { |
|
| 737 | - if (!defined('_SET_HTML_BASE')) { |
|
| 738 | - // si la profondeur est superieure a 1 |
|
| 739 | - // est que ce n'est pas une url page ni une url action |
|
| 740 | - // activer par defaut |
|
| 741 | - $set_html_base = (( |
|
| 742 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | - and !_request('action')) ? true : false); |
|
| 745 | - } else { |
|
| 746 | - $set_html_base = _SET_HTML_BASE; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - if ( |
|
| 751 | - $set_html_base |
|
| 752 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | - ) { |
|
| 756 | - $head = substr($texte, 0, $poshead); |
|
| 757 | - $insert = false; |
|
| 758 | - $href_base = false; |
|
| 759 | - if (strpos($head, '<base') === false) { |
|
| 760 | - $insert = true; |
|
| 761 | - } else { |
|
| 762 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | - // sinon juste re-ecrire les ancres si besoin |
|
| 764 | - $insert = true; |
|
| 765 | - include_spip('inc/filtres'); |
|
| 766 | - $bases = extraire_balises($head, 'base'); |
|
| 767 | - foreach ($bases as $base) { |
|
| 768 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | - $insert = false; |
|
| 770 | - break; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if ($insert) { |
|
| 776 | - include_spip('inc/filtres_mini'); |
|
| 777 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | - $href_base = url_absolue('./'); |
|
| 779 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | - } |
|
| 785 | - $texte = $head . substr($texte, $poshead); |
|
| 786 | - } |
|
| 787 | - if ($href_base) { |
|
| 788 | - // gerer les ancres |
|
| 789 | - $base = $_SERVER['REQUEST_URI']; |
|
| 790 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | - } |
|
| 794 | - if (strpos($texte, "href='#") !== false) { |
|
| 795 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | - } |
|
| 797 | - if (strpos($texte, 'href="#') !== false) { |
|
| 798 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 735 | + static $set_html_base = null; |
|
| 736 | + if (is_null($set_html_base)) { |
|
| 737 | + if (!defined('_SET_HTML_BASE')) { |
|
| 738 | + // si la profondeur est superieure a 1 |
|
| 739 | + // est que ce n'est pas une url page ni une url action |
|
| 740 | + // activer par defaut |
|
| 741 | + $set_html_base = (( |
|
| 742 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | + and !_request('action')) ? true : false); |
|
| 745 | + } else { |
|
| 746 | + $set_html_base = _SET_HTML_BASE; |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + if ( |
|
| 751 | + $set_html_base |
|
| 752 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | + ) { |
|
| 756 | + $head = substr($texte, 0, $poshead); |
|
| 757 | + $insert = false; |
|
| 758 | + $href_base = false; |
|
| 759 | + if (strpos($head, '<base') === false) { |
|
| 760 | + $insert = true; |
|
| 761 | + } else { |
|
| 762 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | + // sinon juste re-ecrire les ancres si besoin |
|
| 764 | + $insert = true; |
|
| 765 | + include_spip('inc/filtres'); |
|
| 766 | + $bases = extraire_balises($head, 'base'); |
|
| 767 | + foreach ($bases as $base) { |
|
| 768 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | + $insert = false; |
|
| 770 | + break; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if ($insert) { |
|
| 776 | + include_spip('inc/filtres_mini'); |
|
| 777 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | + $href_base = url_absolue('./'); |
|
| 779 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | + } |
|
| 785 | + $texte = $head . substr($texte, $poshead); |
|
| 786 | + } |
|
| 787 | + if ($href_base) { |
|
| 788 | + // gerer les ancres |
|
| 789 | + $base = $_SERVER['REQUEST_URI']; |
|
| 790 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | + } |
|
| 794 | + if (strpos($texte, "href='#") !== false) { |
|
| 795 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | + } |
|
| 797 | + if (strpos($texte, 'href="#') !== false) { |
|
| 798 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | |
| 805 | 805 | // Envoyer les entetes, en retenant ceux qui sont a usage interne |
| 806 | 806 | // et demarrent par X-Spip-... |
| 807 | 807 | function envoyer_entetes($entetes) { |
| 808 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | - } |
|
| 808 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | + } |
|
| 811 | 811 | } |
@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * Code PHP compilé de la boucle |
| 33 | 33 | **/ |
| 34 | 34 | function boucle_DEFAUT_dist($id_boucle, &$boucles) { |
| 35 | - return calculer_boucle($id_boucle, $boucles); |
|
| 35 | + return calculer_boucle($id_boucle, $boucles); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Code PHP compilé de la boucle |
| 52 | 52 | **/ |
| 53 | 53 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { |
| 54 | - return calculer_boucle($id_boucle, $boucles); |
|
| 54 | + return calculer_boucle($id_boucle, $boucles); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -81,30 +81,30 @@ discard block |
||
| 81 | 81 | * Code PHP compilé de la boucle |
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | - $boucle = &$boucles[$id_boucle]; |
|
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 84 | + $boucle = &$boucles[$id_boucle]; |
|
| 85 | + $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 86 | 86 | |
| 87 | - // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | - // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | - // ou {id_article} qui positionne aussi le {tout} |
|
| 87 | + // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | + // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | + // ou {id_article} qui positionne aussi le {tout} |
|
| 90 | 90 | |
| 91 | - $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | - . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | - . ")))\n\t\treturn '';\n\t" |
|
| 94 | - . "include_spip('inc/rubriques');\n\t" |
|
| 95 | - . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | - . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | - . ");\n\t" |
|
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 91 | + $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | + . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | + . ")))\n\t\treturn '';\n\t" |
|
| 94 | + . "include_spip('inc/rubriques');\n\t" |
|
| 95 | + . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | + . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | + . ");\n\t" |
|
| 98 | + . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 99 | 99 | |
| 100 | - $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 100 | + $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 101 | 101 | |
| 102 | - $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | - if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | - $boucle->default_order[] = "\"$order\""; |
|
| 105 | - } else { |
|
| 106 | - $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | - } |
|
| 102 | + $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | + if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | + $boucle->default_order[] = "\"$order\""; |
|
| 105 | + } else { |
|
| 106 | + $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return calculer_boucle($id_boucle, $boucles); |
|
| 109 | + return calculer_boucle($id_boucle, $boucles); |
|
| 110 | 110 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | 84 | $boucle = &$boucles[$id_boucle]; |
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 85 | + $id_table = $boucle->id_table.'.id_rubrique'; |
|
| 86 | 86 | |
| 87 | 87 | // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
| 88 | 88 | // sauf en presence du critere {tout} (vu par phraser_html) |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
| 96 | 96 | . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
| 97 | 97 | . ");\n\t" |
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 98 | + . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 99 | 99 | |
| 100 | 100 | $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
| 101 | 101 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][21676] = [ |
| 26 | - ['ranger_cache_gd2'], |
|
| 26 | + ['ranger_cache_gd2'], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,30 +32,30 @@ discard block |
||
| 32 | 32 | * https://core.spip.net/issues/3277 |
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | - spip_log('ranger_cache_gd2'); |
|
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | - if (is_dir($base) and is_readable($base)) { |
|
| 38 | - if ($dir = opendir($base)) { |
|
| 39 | - while (($f = readdir($dir)) !== false) { |
|
| 40 | - if ( |
|
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | - and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | - ) { |
|
| 44 | - $sub = substr($f, 0, 2); |
|
| 45 | - $sub = sous_repertoire($base, $sub); |
|
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | - } |
|
| 49 | - if (time() >= _TIME_OUT) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 35 | + spip_log('ranger_cache_gd2'); |
|
| 36 | + $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | + if (is_dir($base) and is_readable($base)) { |
|
| 38 | + if ($dir = opendir($base)) { |
|
| 39 | + while (($f = readdir($dir)) !== false) { |
|
| 40 | + if ( |
|
| 41 | + !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | + and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | + ) { |
|
| 44 | + $sub = substr($f, 0, 2); |
|
| 45 | + $sub = sous_repertoire($base, $sub); |
|
| 46 | + @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | + @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | + } |
|
| 49 | + if (time() >= _TIME_OUT) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | $GLOBALS['maj'][21742] = [ |
| 59 | - ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | - ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 59 | + ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | + ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 61 | 61 | ]; |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | 35 | spip_log('ranger_cache_gd2'); |
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 36 | + $base = _DIR_VAR.'cache-gd2/'; |
|
| 37 | 37 | if (is_dir($base) and is_readable($base)) { |
| 38 | 38 | if ($dir = opendir($base)) { |
| 39 | 39 | while (($f = readdir($dir)) !== false) { |
| 40 | 40 | if ( |
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 41 | + !is_dir($base.$f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | 42 | and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
| 43 | 43 | ) { |
| 44 | 44 | $sub = substr($f, 0, 2); |
| 45 | 45 | $sub = sous_repertoire($base, $sub); |
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 46 | + @rename($base.$f, $sub.substr($f, 2)); |
|
| 47 | + @unlink($base.$f); // au cas ou le rename a foire (collision) |
|
| 48 | 48 | } |
| 49 | 49 | if (time() >= _TIME_OUT) { |
| 50 | 50 | return; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('base/medias'); |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // http://archives.rezo.net/archives/spip-zone.mbox/C6RZKNBUNJYN42IOEOC4QKVCA233AMLI/ |
| 29 | 29 | $GLOBALS['maj'][13833] = [ |
| 30 | - ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 30 | + ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | // 2.1 |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][13904] = [ |
| 36 | - ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | - [ |
|
| 38 | - 'sql_update', |
|
| 39 | - 'spip_auteurs', |
|
| 40 | - ['webmestre' => "'oui'"], |
|
| 41 | - sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | - ':', |
|
| 43 | - _ID_WEBMESTRES |
|
| 44 | - ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | - ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 36 | + ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | + [ |
|
| 38 | + 'sql_update', |
|
| 39 | + 'spip_auteurs', |
|
| 40 | + ['webmestre' => "'oui'"], |
|
| 41 | + sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | + ':', |
|
| 43 | + _ID_WEBMESTRES |
|
| 44 | + ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | + ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | 48 | // sites plantes en mode "'su" au lieu de "sus" |
| 49 | 49 | $GLOBALS['maj'][13929] = [ |
| 50 | - ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 50 | + ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | 53 | // Types de fichiers m4a/m4b/m4p/m4u/m4v/dv |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | // La version 14588 etait une mauvaise piste: |
| 62 | 62 | // Retour en arriere pour ceux qui l'ont subi, ne rien faire sinon |
| 63 | 63 | if (@$GLOBALS['meta']['version_installee'] >= 14588) { |
| 64 | - // "mode" est un mot-cle d'Oracle |
|
| 65 | - $GLOBALS['maj'][14588] = [ |
|
| 66 | - ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | - [ |
|
| 68 | - 'sql_alter', |
|
| 69 | - "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | - ], |
|
| 71 | - ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | - ]; |
|
| 73 | - // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | - $GLOBALS['maj'][14598] = [ |
|
| 75 | - ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | - [ |
|
| 77 | - 'sql_alter', |
|
| 78 | - "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | - ], |
|
| 80 | - ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | - ]; |
|
| 64 | + // "mode" est un mot-cle d'Oracle |
|
| 65 | + $GLOBALS['maj'][14588] = [ |
|
| 66 | + ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | + [ |
|
| 68 | + 'sql_alter', |
|
| 69 | + "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | + ], |
|
| 71 | + ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | + ]; |
|
| 73 | + // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | + $GLOBALS['maj'][14598] = [ |
|
| 75 | + ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | + [ |
|
| 77 | + 'sql_alter', |
|
| 78 | + "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | + ], |
|
| 80 | + ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | + ]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Restauration correcte des types mime des fichiers Ogg |