@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,136 +66,136 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 69 | - static $tableau_des_erreurs = []; |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = []; |
|
| 78 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if ( |
|
| 119 | - ob_get_length() |
|
| 120 | - and |
|
| 121 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | - ) { |
|
| 123 | - ob_end_clean(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | - $fonc = _request('var_mode_objet'); |
|
| 128 | - $mode = _request('var_mode_affiche'); |
|
| 129 | - $self = str_replace("\\'", ''', self()); |
|
| 130 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | - |
|
| 132 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | - . '<br />' |
|
| 134 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | - |
|
| 136 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | - return $res; |
|
| 138 | - } |
|
| 139 | - if ($tableau_des_erreurs) { |
|
| 140 | - http_response_code(503); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - http_no_cache(); |
|
| 144 | - if (isset($_GET['var_profile'])) { |
|
| 145 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | - } else { |
|
| 148 | - if (!$fonc) { |
|
| 149 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | - } |
|
| 151 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | - } |
|
| 153 | - if ($message === false) { |
|
| 154 | - lang_select(); |
|
| 155 | - |
|
| 156 | - return debusquer_entete($titre, $res); |
|
| 157 | - } else { |
|
| 158 | - echo debusquer_entete($titre, $res); |
|
| 159 | - } |
|
| 160 | - exit; |
|
| 69 | + static $tableau_des_erreurs = []; |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = []; |
|
| 78 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if ( |
|
| 119 | + ob_get_length() |
|
| 120 | + and |
|
| 121 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 122 | + ) { |
|
| 123 | + ob_end_clean(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 127 | + $fonc = _request('var_mode_objet'); |
|
| 128 | + $mode = _request('var_mode_affiche'); |
|
| 129 | + $self = str_replace("\\'", ''', self()); |
|
| 130 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 131 | + |
|
| 132 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 133 | + . '<br />' |
|
| 134 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 135 | + |
|
| 136 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 137 | + return $res; |
|
| 138 | + } |
|
| 139 | + if ($tableau_des_erreurs) { |
|
| 140 | + http_response_code(503); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + http_no_cache(); |
|
| 144 | + if (isset($_GET['var_profile'])) { |
|
| 145 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 146 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 147 | + } else { |
|
| 148 | + if (!$fonc) { |
|
| 149 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 150 | + } |
|
| 151 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 152 | + } |
|
| 153 | + if ($message === false) { |
|
| 154 | + lang_select(); |
|
| 155 | + |
|
| 156 | + return debusquer_entete($titre, $res); |
|
| 157 | + } else { |
|
| 158 | + echo debusquer_entete($titre, $res); |
|
| 159 | + } |
|
| 160 | + exit; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debusquer_compose_message($msg) { |
| 164 | - if (is_array($msg)) { |
|
| 165 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | - // message avec argument: instancier |
|
| 169 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | - } else { |
|
| 171 | - // message SQL: interpreter |
|
| 172 | - $msg = debusquer_requete($msg); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | - $fond = $GLOBALS['fond'] ?? ''; |
|
| 178 | - // une erreur critique sort $message en array |
|
| 179 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | - |
|
| 182 | - return $msg; |
|
| 164 | + if (is_array($msg)) { |
|
| 165 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 166 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 167 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 168 | + // message avec argument: instancier |
|
| 169 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 170 | + } else { |
|
| 171 | + // message SQL: interpreter |
|
| 172 | + $msg = debusquer_requete($msg); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 176 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 177 | + $fond = $GLOBALS['fond'] ?? ''; |
|
| 178 | + // une erreur critique sort $message en array |
|
| 179 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 180 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 181 | + |
|
| 182 | + return $msg; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function debusquer_bandeau($erreurs) { |
| 186 | 186 | |
| 187 | - if (!empty($erreurs)) { |
|
| 188 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 187 | + if (!empty($erreurs)) { |
|
| 188 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 189 | 189 | |
| 190 | - return debusquer_navigation($erreurs, $n); |
|
| 191 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | - include_spip('public/tracer'); |
|
| 193 | - [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 190 | + return debusquer_navigation($erreurs, $n); |
|
| 191 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 192 | + include_spip('public/tracer'); |
|
| 193 | + [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 194 | 194 | |
| 195 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | - } else { |
|
| 197 | - return ''; |
|
| 198 | - } |
|
| 195 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 196 | + } else { |
|
| 197 | + return ''; |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -205,42 +205,42 @@ discard block |
||
| 205 | 205 | * @return string Code HTML |
| 206 | 206 | **/ |
| 207 | 207 | function debusquer_contexte($env) { |
| 208 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | - $env = $env_tab; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!$env) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $res = ''; |
|
| 216 | - foreach ($env as $nom => $valeur) { |
|
| 217 | - if (is_array($valeur)) { |
|
| 218 | - $valeur_simple = []; |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - if (is_array($v)) { |
|
| 221 | - $valeur_simple[] = 'array:' . count($v); |
|
| 222 | - } elseif (is_object($v)) { |
|
| 223 | - $valeur_simple[] = get_class($v); |
|
| 224 | - } elseif (is_string($v)) { |
|
| 225 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | - } else { |
|
| 227 | - $valeur_simple[] = $v; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - $n = count($valeur); |
|
| 231 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | - } elseif (is_object($valeur)) { |
|
| 234 | - $valeur = get_class($valeur); |
|
| 235 | - } elseif (is_string($valeur)) { |
|
| 236 | - $valeur = "'" . $valeur . "'"; |
|
| 237 | - } |
|
| 238 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | - . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | - . "</td></tr>\n"; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 209 | + $env = $env_tab; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!$env) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $res = ''; |
|
| 216 | + foreach ($env as $nom => $valeur) { |
|
| 217 | + if (is_array($valeur)) { |
|
| 218 | + $valeur_simple = []; |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + if (is_array($v)) { |
|
| 221 | + $valeur_simple[] = 'array:' . count($v); |
|
| 222 | + } elseif (is_object($v)) { |
|
| 223 | + $valeur_simple[] = get_class($v); |
|
| 224 | + } elseif (is_string($v)) { |
|
| 225 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 226 | + } else { |
|
| 227 | + $valeur_simple[] = $v; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + $n = count($valeur); |
|
| 231 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 232 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 233 | + } elseif (is_object($valeur)) { |
|
| 234 | + $valeur = get_class($valeur); |
|
| 235 | + } elseif (is_string($valeur)) { |
|
| 236 | + $valeur = "'" . $valeur . "'"; |
|
| 237 | + } |
|
| 238 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 239 | + . '</strong></td><td>: ' . nl2br(entites_html($valeur)) |
|
| 240 | + . "</td></tr>\n"; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -248,66 +248,66 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 250 | 250 | |
| 251 | - if (_request('exec') == 'valider_xml') { |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 254 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | - $res = ''; |
|
| 256 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | - foreach ($tableau as $i => $err) { |
|
| 258 | - $boucle = $ligne = $skel = ''; |
|
| 259 | - [$msg, $lieu] = $err; |
|
| 260 | - if (is_object($lieu)) { |
|
| 261 | - $ligne = $lieu->ligne; |
|
| 262 | - $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | - if (isset($lieu->descr['nom'])) { |
|
| 264 | - $nom_code = $lieu->descr['nom']; |
|
| 265 | - $skel = $lieu->descr['sourcefile']; |
|
| 266 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | - if ($boucle) { |
|
| 270 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $j = ($i + 1); |
|
| 277 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | - . $j |
|
| 279 | - . " </td><td style='text-align: left'>" |
|
| 280 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | - . "</td><td style='text-align: left'>" |
|
| 282 | - . ($skel ?: ' / ') |
|
| 283 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | - . ($boucle ?: ' / ') |
|
| 285 | - . "</td><td style='text-align: right'>" |
|
| 286 | - . $ligne |
|
| 287 | - . "</td></tr>\n"; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return "\n<table id='$id'>" |
|
| 291 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | - . $caption[0] |
|
| 251 | + if (_request('exec') == 'valider_xml') { |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 255 | + $res = ''; |
|
| 256 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 257 | + foreach ($tableau as $i => $err) { |
|
| 258 | + $boucle = $ligne = $skel = ''; |
|
| 259 | + [$msg, $lieu] = $err; |
|
| 260 | + if (is_object($lieu)) { |
|
| 261 | + $ligne = $lieu->ligne; |
|
| 262 | + $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 263 | + if (isset($lieu->descr['nom'])) { |
|
| 264 | + $nom_code = $lieu->descr['nom']; |
|
| 265 | + $skel = $lieu->descr['sourcefile']; |
|
| 266 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 267 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 268 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 269 | + if ($boucle) { |
|
| 270 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 271 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $j = ($i + 1); |
|
| 277 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 278 | + . $j |
|
| 279 | + . " </td><td style='text-align: left'>" |
|
| 280 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 281 | + . "</td><td style='text-align: left'>" |
|
| 282 | + . ($skel ?: ' / ') |
|
| 283 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 284 | + . ($boucle ?: ' / ') |
|
| 285 | + . "</td><td style='text-align: right'>" |
|
| 286 | + . $ligne |
|
| 287 | + . "</td></tr>\n"; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return "\n<table id='$id'>" |
|
| 291 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 292 | + . $caption[0] |
|
| 293 | 293 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 294 | 294 | # aider('erreur_compilation'), |
| 295 | - . '</caption>' |
|
| 296 | - // fausse caption du chrono (mais vraie nav) |
|
| 297 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | - . '<tr><th>' |
|
| 299 | - . _T('numero') |
|
| 300 | - . '</th><th>' |
|
| 301 | - . _T('public:message') |
|
| 302 | - . '</th><th>' |
|
| 303 | - . _T('squelette') |
|
| 304 | - . '</th><th>' |
|
| 305 | - . _T('zbug_boucle') |
|
| 306 | - . '</th><th>' |
|
| 307 | - . _T('ligne') |
|
| 308 | - . '</th></tr>' |
|
| 309 | - . $res |
|
| 310 | - . '</table>'; |
|
| 295 | + . '</caption>' |
|
| 296 | + // fausse caption du chrono (mais vraie nav) |
|
| 297 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 298 | + . '<tr><th>' |
|
| 299 | + . _T('numero') |
|
| 300 | + . '</th><th>' |
|
| 301 | + . _T('public:message') |
|
| 302 | + . '</th><th>' |
|
| 303 | + . _T('squelette') |
|
| 304 | + . '</th><th>' |
|
| 305 | + . _T('zbug_boucle') |
|
| 306 | + . '</th><th>' |
|
| 307 | + . _T('ligne') |
|
| 308 | + . '</th></tr>' |
|
| 309 | + . $res |
|
| 310 | + . '</table>'; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -327,124 +327,124 @@ discard block |
||
| 327 | 327 | * ou un tableau si l'erreur est critique |
| 328 | 328 | **/ |
| 329 | 329 | function debusquer_requete($message) { |
| 330 | - [$errno, $msg, $query] = $message; |
|
| 331 | - |
|
| 332 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | - $errno = $regs[2]; |
|
| 336 | - } elseif ( |
|
| 337 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | - ) { |
|
| 340 | - $errno = $regs[1]; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Erreur systeme |
|
| 344 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | - $retour = '<tt><br /><br /><blink>' |
|
| 346 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | - . "</blink><br />\n<b>" |
|
| 348 | - . _T( |
|
| 349 | - 'info_erreur_systeme2', |
|
| 350 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | - ) |
|
| 352 | - . '</b><br />'; |
|
| 353 | - spip_log("Erreur systeme $errno"); |
|
| 354 | - |
|
| 355 | - return [$retour, '']; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // Requete erronee |
|
| 359 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | - . spip_htmlspecialchars($msg) |
|
| 361 | - . "\n<br /><span style='color: red'><b>" |
|
| 362 | - . spip_htmlspecialchars($query) |
|
| 363 | - . '</b></span></tt><br />'; |
|
| 364 | - |
|
| 365 | - //. aider('erreur_mysql'); |
|
| 366 | - |
|
| 367 | - return $err; |
|
| 330 | + [$errno, $msg, $query] = $message; |
|
| 331 | + |
|
| 332 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 333 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 334 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 335 | + $errno = $regs[2]; |
|
| 336 | + } elseif ( |
|
| 337 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 338 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 339 | + ) { |
|
| 340 | + $errno = $regs[1]; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Erreur systeme |
|
| 344 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 345 | + $retour = '<tt><br /><br /><blink>' |
|
| 346 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 347 | + . "</blink><br />\n<b>" |
|
| 348 | + . _T( |
|
| 349 | + 'info_erreur_systeme2', |
|
| 350 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 351 | + ) |
|
| 352 | + . '</b><br />'; |
|
| 353 | + spip_log("Erreur systeme $errno"); |
|
| 354 | + |
|
| 355 | + return [$retour, '']; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // Requete erronee |
|
| 359 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 360 | + . spip_htmlspecialchars($msg) |
|
| 361 | + . "\n<br /><span style='color: red'><b>" |
|
| 362 | + . spip_htmlspecialchars($query) |
|
| 363 | + . '</b></span></tt><br />'; |
|
| 364 | + |
|
| 365 | + //. aider('erreur_mysql'); |
|
| 366 | + |
|
| 367 | + return $err; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
| 371 | 371 | // https://code.spip.net/@trouve_boucle_debug |
| 372 | 372 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 373 | 373 | |
| 374 | - $id = $nom . $boucle; |
|
| 375 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | - $y = substr_count($v[0], "\n"); |
|
| 379 | - } else { |
|
| 380 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | - } else // inclusion |
|
| 383 | - { |
|
| 384 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | - } |
|
| 386 | - $y = substr_count($incl, "\n") |
|
| 387 | - + substr_count($r[1], "\n") |
|
| 388 | - + substr_count($r[3], "\n"); |
|
| 389 | - } |
|
| 390 | - if ($n <= ($y + $debut)) { |
|
| 391 | - if ($v[1][0] == '?') { |
|
| 392 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | - } elseif ($v[1][0] == '!') { |
|
| 394 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | - } |
|
| 401 | - $debut += $y; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return [$nom, $boucle, $n - $debut]; |
|
| 374 | + $id = $nom . $boucle; |
|
| 375 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 376 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 377 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 378 | + $y = substr_count($v[0], "\n"); |
|
| 379 | + } else { |
|
| 380 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 381 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 382 | + } else // inclusion |
|
| 383 | + { |
|
| 384 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 385 | + } |
|
| 386 | + $y = substr_count($incl, "\n") |
|
| 387 | + + substr_count($r[1], "\n") |
|
| 388 | + + substr_count($r[3], "\n"); |
|
| 389 | + } |
|
| 390 | + if ($n <= ($y + $debut)) { |
|
| 391 | + if ($v[1][0] == '?') { |
|
| 392 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 393 | + } elseif ($v[1][0] == '!') { |
|
| 394 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 395 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 400 | + } |
|
| 401 | + $debut += $y; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return [$nom, $boucle, $n - $debut]; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | // https://code.spip.net/@trouve_squelette_inclus |
| 409 | 409 | function trouve_squelette_inclus($script) { |
| 410 | 410 | |
| 411 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | - // si le script X.php n'est pas ecrire/public.php |
|
| 413 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | - $reg[1] = 'inconnu'; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | - |
|
| 423 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | - if (preg_match($incl, $v)) { |
|
| 425 | - return $k; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - return ''; |
|
| 411 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 412 | + // si le script X.php n'est pas ecrire/public.php |
|
| 413 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 414 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 415 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 416 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 417 | + $reg[1] = 'inconnu'; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 422 | + |
|
| 423 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 424 | + if (preg_match($incl, $v)) { |
|
| 425 | + return $k; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + return ''; |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // https://code.spip.net/@reference_boucle_debug |
| 433 | 433 | function reference_boucle_debug($n, $nom, $self) { |
| 434 | - [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 435 | - |
|
| 436 | - if (!$boucle) { |
|
| 437 | - return !$ligne ? '' : |
|
| 438 | - (' (' . |
|
| 439 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | - _T('squelette_ligne')) . |
|
| 441 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | - } else { |
|
| 443 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | - |
|
| 445 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | - } |
|
| 434 | + [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 435 | + |
|
| 436 | + if (!$boucle) { |
|
| 437 | + return !$ligne ? '' : |
|
| 438 | + (' (' . |
|
| 439 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 440 | + _T('squelette_ligne')) . |
|
| 441 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 442 | + } else { |
|
| 443 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 444 | + |
|
| 445 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 446 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // affiche un texte avec numero de ligne et ancre. |
@@ -452,396 +452,396 @@ discard block |
||
| 452 | 452 | // https://code.spip.net/@ancre_texte |
| 453 | 453 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 454 | 454 | |
| 455 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | - if ($var_mode_ligne) { |
|
| 457 | - $fautifs[] = [$var_mode_ligne]; |
|
| 458 | - } |
|
| 459 | - $res = ''; |
|
| 460 | - |
|
| 461 | - $s = highlight_string($texte, true); |
|
| 462 | - if (substr($s, 0, 6) == '<code>') { |
|
| 463 | - $s = substr($s, 6); |
|
| 464 | - $res = '<code>'; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $s = preg_replace( |
|
| 468 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | - $s |
|
| 471 | - ); |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - $tableau = explode('<br />', $s); |
|
| 475 | - |
|
| 476 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | - |
|
| 478 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | - $formaterr = 'color: red;'; |
|
| 480 | - $i = 1; |
|
| 481 | - $flignes = []; |
|
| 482 | - $loc = [0, 0]; |
|
| 483 | - foreach ($fautifs as $lc) { |
|
| 484 | - if (is_array($lc)) { |
|
| 485 | - $l = array_shift($lc); |
|
| 486 | - $flignes[$l] = $lc; |
|
| 487 | - } else { |
|
| 488 | - $flignes[$lc] = $loc; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - $ancre = md5($texte); |
|
| 493 | - foreach ($tableau as $ligne) { |
|
| 494 | - if (isset($flignes[$i])) { |
|
| 495 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | - $indexmesg = $flignes[$i][1]; |
|
| 497 | - $err = textebrut($flignes[$i][2]); |
|
| 498 | - // tentative de pointer sur la colonne fautive; |
|
| 499 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | - // $m = $flignes[$i][0]; |
|
| 501 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | - $bg = $formaterr; |
|
| 504 | - } else { |
|
| 505 | - $indexmesg = $ancre; |
|
| 506 | - $err = $bg = ''; |
|
| 507 | - } |
|
| 508 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | - $i++; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return "<div id='T$ancre'>" |
|
| 513 | - . '<div onclick="' |
|
| 514 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | - . '" title="' |
|
| 516 | - . _T('masquer_colonne') |
|
| 517 | - . '" style="cursor: pointer;">' |
|
| 518 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | - . '</div> |
|
| 455 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 456 | + if ($var_mode_ligne) { |
|
| 457 | + $fautifs[] = [$var_mode_ligne]; |
|
| 458 | + } |
|
| 459 | + $res = ''; |
|
| 460 | + |
|
| 461 | + $s = highlight_string($texte, true); |
|
| 462 | + if (substr($s, 0, 6) == '<code>') { |
|
| 463 | + $s = substr($s, 6); |
|
| 464 | + $res = '<code>'; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $s = preg_replace( |
|
| 468 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 469 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 470 | + $s |
|
| 471 | + ); |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + $tableau = explode('<br />', $s); |
|
| 475 | + |
|
| 476 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 477 | + |
|
| 478 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 479 | + $formaterr = 'color: red;'; |
|
| 480 | + $i = 1; |
|
| 481 | + $flignes = []; |
|
| 482 | + $loc = [0, 0]; |
|
| 483 | + foreach ($fautifs as $lc) { |
|
| 484 | + if (is_array($lc)) { |
|
| 485 | + $l = array_shift($lc); |
|
| 486 | + $flignes[$l] = $lc; |
|
| 487 | + } else { |
|
| 488 | + $flignes[$lc] = $loc; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + $ancre = md5($texte); |
|
| 493 | + foreach ($tableau as $ligne) { |
|
| 494 | + if (isset($flignes[$i])) { |
|
| 495 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 496 | + $indexmesg = $flignes[$i][1]; |
|
| 497 | + $err = textebrut($flignes[$i][2]); |
|
| 498 | + // tentative de pointer sur la colonne fautive; |
|
| 499 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 500 | + // $m = $flignes[$i][0]; |
|
| 501 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 502 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 503 | + $bg = $formaterr; |
|
| 504 | + } else { |
|
| 505 | + $indexmesg = $ancre; |
|
| 506 | + $err = $bg = ''; |
|
| 507 | + } |
|
| 508 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 509 | + $i++; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return "<div id='T$ancre'>" |
|
| 513 | + . '<div onclick="' |
|
| 514 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 515 | + . '" title="' |
|
| 516 | + . _T('masquer_colonne') |
|
| 517 | + . '" style="cursor: pointer;">' |
|
| 518 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 519 | + . '</div> |
|
| 520 | 520 | ' . $res . "</div>\n"; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | // l'environnement graphique du debuggueur |
| 524 | 524 | |
| 525 | 525 | function debusquer_squelette($fonc, $mode, $self) { |
| 526 | - $legend = null; |
|
| 527 | - $texte = ''; |
|
| 528 | - |
|
| 529 | - if ($mode !== 'validation') { |
|
| 530 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 531 | - $res = "<div id='spip-boucles'>\n" |
|
| 532 | - . debusquer_navigation_squelettes($self) |
|
| 533 | - . '</div>'; |
|
| 534 | - } else { |
|
| 535 | - $res = ''; |
|
| 536 | - } |
|
| 537 | - if ($fonc) { |
|
| 538 | - $id = " id='$fonc'"; |
|
| 539 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 540 | - [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 541 | - $texte .= $res2; |
|
| 542 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 543 | - $legend = _T('zbug_' . $mode); |
|
| 544 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 545 | - $texte = ancre_texte($texte, ['', '']); |
|
| 546 | - } |
|
| 547 | - } else { |
|
| 548 | - if (strlen(trim($res))) { |
|
| 549 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 550 | - } else { |
|
| 551 | - // cas de l'appel sur erreur: montre la page |
|
| 552 | - return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - } else { |
|
| 556 | - $valider = charger_fonction('valider', 'xml'); |
|
| 557 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 558 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 559 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 560 | - [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 561 | - if ($err === false) { |
|
| 562 | - $err = _T('impossible'); |
|
| 563 | - } elseif ($err === true) { |
|
| 564 | - $err = _T('correcte'); |
|
| 565 | - } else { |
|
| 566 | - $err = ": $err"; |
|
| 567 | - } |
|
| 568 | - $legend = _T('validation') . ' ' . $err; |
|
| 569 | - $res = $id = ''; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return !trim($texte) ? '' : ( |
|
| 573 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 574 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 575 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 576 | - . ($legend ?: $mode) |
|
| 577 | - . '</a></legend>' |
|
| 578 | - . $texte |
|
| 579 | - . '</fieldset></div>' |
|
| 580 | - . '</div>'); |
|
| 526 | + $legend = null; |
|
| 527 | + $texte = ''; |
|
| 528 | + |
|
| 529 | + if ($mode !== 'validation') { |
|
| 530 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 531 | + $res = "<div id='spip-boucles'>\n" |
|
| 532 | + . debusquer_navigation_squelettes($self) |
|
| 533 | + . '</div>'; |
|
| 534 | + } else { |
|
| 535 | + $res = ''; |
|
| 536 | + } |
|
| 537 | + if ($fonc) { |
|
| 538 | + $id = " id='$fonc'"; |
|
| 539 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 540 | + [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 541 | + $texte .= $res2; |
|
| 542 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 543 | + $legend = _T('zbug_' . $mode); |
|
| 544 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 545 | + $texte = ancre_texte($texte, ['', '']); |
|
| 546 | + } |
|
| 547 | + } else { |
|
| 548 | + if (strlen(trim($res))) { |
|
| 549 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 550 | + } else { |
|
| 551 | + // cas de l'appel sur erreur: montre la page |
|
| 552 | + return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + } else { |
|
| 556 | + $valider = charger_fonction('valider', 'xml'); |
|
| 557 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 558 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 559 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 560 | + [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 561 | + if ($err === false) { |
|
| 562 | + $err = _T('impossible'); |
|
| 563 | + } elseif ($err === true) { |
|
| 564 | + $err = _T('correcte'); |
|
| 565 | + } else { |
|
| 566 | + $err = ": $err"; |
|
| 567 | + } |
|
| 568 | + $legend = _T('validation') . ' ' . $err; |
|
| 569 | + $res = $id = ''; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return !trim($texte) ? '' : ( |
|
| 573 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 574 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 575 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 576 | + . ($legend ?: $mode) |
|
| 577 | + . '</a></legend>' |
|
| 578 | + . $texte |
|
| 579 | + . '</fieldset></div>' |
|
| 580 | + . '</div>'); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
| 584 | 584 | // https://code.spip.net/@emboite_texte |
| 585 | 585 | function emboite_texte($res, $fonc = '', $self = '') { |
| 586 | - $errs = $res->err; |
|
| 587 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 588 | - |
|
| 589 | - if (!$texte and !$errs) { |
|
| 590 | - return [ancre_texte('', ['', '']), false]; |
|
| 591 | - } |
|
| 592 | - if (!$errs) { |
|
| 593 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 597 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 598 | - $encore = count_occ($errs); |
|
| 599 | - $encore2 = []; |
|
| 600 | - $fautifs = []; |
|
| 601 | - |
|
| 602 | - $err = '<tr><th>' |
|
| 603 | - . _T('numero') |
|
| 604 | - . '</th><th>' |
|
| 605 | - . _T('occurence') |
|
| 606 | - . '</th><th>' |
|
| 607 | - . _T('ligne') |
|
| 608 | - . '</th><th>' |
|
| 609 | - . _T('colonne') |
|
| 610 | - . '</th><th>' |
|
| 611 | - . _T('erreur') |
|
| 612 | - . '</th></tr>'; |
|
| 613 | - |
|
| 614 | - $i = 0; |
|
| 615 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 616 | - foreach ($errs as $r) { |
|
| 617 | - $i++; |
|
| 618 | - [$msg, $ligne, $col] = $r; |
|
| 619 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 620 | - if (isset($encore2[$msg])) { |
|
| 621 | - $ref = ++$encore2[$msg]; |
|
| 622 | - } else { |
|
| 623 | - $encore2[$msg] = $ref = 1; |
|
| 624 | - } |
|
| 625 | - $err .= "<tr style='background-color: " |
|
| 626 | - . $colors[$i % 2] |
|
| 627 | - . "'><td $style><a href='#debut_err'>" |
|
| 628 | - . $i |
|
| 629 | - . "</a></td><td $style>" |
|
| 630 | - . "$ref/$encore[$msg]</td>" |
|
| 631 | - . "<td $style><a href='#L" |
|
| 632 | - . $ligne |
|
| 633 | - . "' id='T$i'>" |
|
| 634 | - . $ligne |
|
| 635 | - . "</a></td><td $style>" |
|
| 636 | - . $col |
|
| 637 | - . "</td><td>$msg</td></tr>\n"; |
|
| 638 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 639 | - } |
|
| 640 | - $err = "<h2 style='text-align: center'>" |
|
| 641 | - . $i |
|
| 642 | - . "<a href='#fin_err'>" |
|
| 643 | - . ' ' . _T('erreur_texte') |
|
| 644 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 645 | - . $err |
|
| 646 | - . " </table><a id='fin_err'></a>"; |
|
| 647 | - |
|
| 648 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 649 | - } else { |
|
| 650 | - [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 651 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 652 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 653 | - $err = $msg . |
|
| 654 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 655 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 656 | - |
|
| 657 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 658 | - } |
|
| 586 | + $errs = $res->err; |
|
| 587 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 588 | + |
|
| 589 | + if (!$texte and !$errs) { |
|
| 590 | + return [ancre_texte('', ['', '']), false]; |
|
| 591 | + } |
|
| 592 | + if (!$errs) { |
|
| 593 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 597 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 598 | + $encore = count_occ($errs); |
|
| 599 | + $encore2 = []; |
|
| 600 | + $fautifs = []; |
|
| 601 | + |
|
| 602 | + $err = '<tr><th>' |
|
| 603 | + . _T('numero') |
|
| 604 | + . '</th><th>' |
|
| 605 | + . _T('occurence') |
|
| 606 | + . '</th><th>' |
|
| 607 | + . _T('ligne') |
|
| 608 | + . '</th><th>' |
|
| 609 | + . _T('colonne') |
|
| 610 | + . '</th><th>' |
|
| 611 | + . _T('erreur') |
|
| 612 | + . '</th></tr>'; |
|
| 613 | + |
|
| 614 | + $i = 0; |
|
| 615 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 616 | + foreach ($errs as $r) { |
|
| 617 | + $i++; |
|
| 618 | + [$msg, $ligne, $col] = $r; |
|
| 619 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 620 | + if (isset($encore2[$msg])) { |
|
| 621 | + $ref = ++$encore2[$msg]; |
|
| 622 | + } else { |
|
| 623 | + $encore2[$msg] = $ref = 1; |
|
| 624 | + } |
|
| 625 | + $err .= "<tr style='background-color: " |
|
| 626 | + . $colors[$i % 2] |
|
| 627 | + . "'><td $style><a href='#debut_err'>" |
|
| 628 | + . $i |
|
| 629 | + . "</a></td><td $style>" |
|
| 630 | + . "$ref/$encore[$msg]</td>" |
|
| 631 | + . "<td $style><a href='#L" |
|
| 632 | + . $ligne |
|
| 633 | + . "' id='T$i'>" |
|
| 634 | + . $ligne |
|
| 635 | + . "</a></td><td $style>" |
|
| 636 | + . $col |
|
| 637 | + . "</td><td>$msg</td></tr>\n"; |
|
| 638 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 639 | + } |
|
| 640 | + $err = "<h2 style='text-align: center'>" |
|
| 641 | + . $i |
|
| 642 | + . "<a href='#fin_err'>" |
|
| 643 | + . ' ' . _T('erreur_texte') |
|
| 644 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 645 | + . $err |
|
| 646 | + . " </table><a id='fin_err'></a>"; |
|
| 647 | + |
|
| 648 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 649 | + } else { |
|
| 650 | + [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 651 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 652 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 653 | + $err = $msg . |
|
| 654 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 655 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 656 | + |
|
| 657 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 658 | + } |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | // https://code.spip.net/@count_occ |
| 662 | 662 | function count_occ($regs) { |
| 663 | - $encore = []; |
|
| 664 | - foreach ($regs as $r) { |
|
| 665 | - if (isset($encore[$r[0]])) { |
|
| 666 | - $encore[$r[0]]++; |
|
| 667 | - } else { |
|
| 668 | - $encore[$r[0]] = 1; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - return $encore; |
|
| 663 | + $encore = []; |
|
| 664 | + foreach ($regs as $r) { |
|
| 665 | + if (isset($encore[$r[0]])) { |
|
| 666 | + $encore[$r[0]]++; |
|
| 667 | + } else { |
|
| 668 | + $encore[$r[0]] = 1; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + return $encore; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | function debusquer_navigation_squelettes($self) { |
| 676 | 676 | |
| 677 | - $res = ''; |
|
| 678 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 679 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 680 | - $t_skel = _T('squelette'); |
|
| 681 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 682 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 683 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 684 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 685 | - 'zbug_profile', |
|
| 686 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 687 | - ); |
|
| 688 | - |
|
| 689 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 690 | - . $t_skel |
|
| 691 | - . ' ' |
|
| 692 | - . $sourcefile |
|
| 693 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 694 | - . $t_skel |
|
| 695 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 696 | - . _T('zbug_resultat') |
|
| 697 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 698 | - . _T('zbug_code') |
|
| 699 | - . "</a>\n<a href='" |
|
| 700 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 701 | - . "'>" |
|
| 702 | - . _T('zbug_calcul') |
|
| 703 | - . '</a></legend>' |
|
| 704 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 705 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 706 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 707 | - . "</fieldset>\n"; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $res; |
|
| 677 | + $res = ''; |
|
| 678 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 679 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 680 | + $t_skel = _T('squelette'); |
|
| 681 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 682 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 683 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 684 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 685 | + 'zbug_profile', |
|
| 686 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 687 | + ); |
|
| 688 | + |
|
| 689 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 690 | + . $t_skel |
|
| 691 | + . ' ' |
|
| 692 | + . $sourcefile |
|
| 693 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 694 | + . $t_skel |
|
| 695 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 696 | + . _T('zbug_resultat') |
|
| 697 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 698 | + . _T('zbug_code') |
|
| 699 | + . "</a>\n<a href='" |
|
| 700 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 701 | + . "'>" |
|
| 702 | + . _T('zbug_calcul') |
|
| 703 | + . '</a></legend>' |
|
| 704 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 705 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 706 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 707 | + . "</fieldset>\n"; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $res; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 714 | - $i = 0; |
|
| 715 | - $res = ''; |
|
| 716 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 717 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 718 | - |
|
| 719 | - foreach ($boucles as $objet => $boucle) { |
|
| 720 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 721 | - $i++; |
|
| 722 | - $nom = $boucle->id_boucle; |
|
| 723 | - $req = $boucle->type_requete; |
|
| 724 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 725 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 726 | - |
|
| 727 | - $res .= "\n<tr style='background-color: " . |
|
| 728 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 729 | - "'><td align='right'>$i</td><td>\n" . |
|
| 730 | - "<a class='debug_link_boucle' href='" . |
|
| 731 | - $self2 . |
|
| 732 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 733 | - _T('zbug_boucle') . |
|
| 734 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 735 | - $self2 . |
|
| 736 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 737 | - _T('zbug_resultat') . |
|
| 738 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 739 | - $self2 . |
|
| 740 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 741 | - _T('zbug_code') . |
|
| 742 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 743 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 744 | - "'>" . |
|
| 745 | - _T('zbug_calcul') . |
|
| 746 | - "</a></td><td>\n" . |
|
| 747 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 748 | - "</td><td>\n" . |
|
| 749 | - $req . |
|
| 750 | - "</td><td>\n" . |
|
| 751 | - spip_htmlspecialchars($crit) . |
|
| 752 | - '</td></tr>'; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - return $res; |
|
| 714 | + $i = 0; |
|
| 715 | + $res = ''; |
|
| 716 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 717 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 718 | + |
|
| 719 | + foreach ($boucles as $objet => $boucle) { |
|
| 720 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 721 | + $i++; |
|
| 722 | + $nom = $boucle->id_boucle; |
|
| 723 | + $req = $boucle->type_requete; |
|
| 724 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 725 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 726 | + |
|
| 727 | + $res .= "\n<tr style='background-color: " . |
|
| 728 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 729 | + "'><td align='right'>$i</td><td>\n" . |
|
| 730 | + "<a class='debug_link_boucle' href='" . |
|
| 731 | + $self2 . |
|
| 732 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 733 | + _T('zbug_boucle') . |
|
| 734 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 735 | + $self2 . |
|
| 736 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 737 | + _T('zbug_resultat') . |
|
| 738 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 739 | + $self2 . |
|
| 740 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 741 | + _T('zbug_code') . |
|
| 742 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 743 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 744 | + "'>" . |
|
| 745 | + _T('zbug_calcul') . |
|
| 746 | + "</a></td><td>\n" . |
|
| 747 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 748 | + "</td><td>\n" . |
|
| 749 | + $req . |
|
| 750 | + "</td><td>\n" . |
|
| 751 | + spip_htmlspecialchars($crit) . |
|
| 752 | + '</td></tr>'; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + return $res; |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | function debusquer_source($objet, $affiche) { |
| 760 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 761 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 762 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 763 | - } else { |
|
| 764 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 765 | - } |
|
| 766 | - $res2 = ''; |
|
| 767 | - |
|
| 768 | - if ($affiche == 'resultat') { |
|
| 769 | - $legend = $nom; |
|
| 770 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 771 | - if (function_exists('_mysql_traite_query')) { |
|
| 772 | - $c = strtolower(_request('connect') ?? ''); |
|
| 773 | - $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 774 | - $req = _mysql_traite_query($req, '', $c); |
|
| 775 | - } |
|
| 776 | - // permettre le copier/coller facile |
|
| 777 | - // $res = ancre_texte($req, array(), true); |
|
| 778 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 779 | - // formatage et affichage des resultats bruts de la requete |
|
| 780 | - $ress_req = spip_query($req); |
|
| 781 | - $brut_sql = ''; |
|
| 782 | - $num = 1; |
|
| 783 | - // eviter l'affichage de milliers de lignes |
|
| 784 | - // personnalisation possible dans mes_options |
|
| 785 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 786 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 787 | - if ($num <= $max_aff) { |
|
| 788 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 789 | - $brut_sql .= '<p>'; |
|
| 790 | - foreach ($retours_sql as $key => $val) { |
|
| 791 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 792 | - } |
|
| 793 | - $brut_sql .= '</p>'; |
|
| 794 | - } |
|
| 795 | - $num++; |
|
| 796 | - } |
|
| 797 | - $res2 = interdire_scripts($brut_sql); |
|
| 798 | - foreach ($quoi as $view) { |
|
| 799 | - // ne pas afficher les $contexte_inclus |
|
| 800 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 801 | - if ($view) { |
|
| 802 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - } elseif ($affiche == 'code') { |
|
| 806 | - $legend = $nom; |
|
| 807 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 808 | - } elseif ($affiche == 'boucle') { |
|
| 809 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 810 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 811 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 812 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 813 | - } elseif ($affiche == 'squelette') { |
|
| 814 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 815 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return [$legend, $res, $res2]; |
|
| 760 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 761 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 762 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 763 | + } else { |
|
| 764 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 765 | + } |
|
| 766 | + $res2 = ''; |
|
| 767 | + |
|
| 768 | + if ($affiche == 'resultat') { |
|
| 769 | + $legend = $nom; |
|
| 770 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 771 | + if (function_exists('_mysql_traite_query')) { |
|
| 772 | + $c = strtolower(_request('connect') ?? ''); |
|
| 773 | + $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 774 | + $req = _mysql_traite_query($req, '', $c); |
|
| 775 | + } |
|
| 776 | + // permettre le copier/coller facile |
|
| 777 | + // $res = ancre_texte($req, array(), true); |
|
| 778 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 779 | + // formatage et affichage des resultats bruts de la requete |
|
| 780 | + $ress_req = spip_query($req); |
|
| 781 | + $brut_sql = ''; |
|
| 782 | + $num = 1; |
|
| 783 | + // eviter l'affichage de milliers de lignes |
|
| 784 | + // personnalisation possible dans mes_options |
|
| 785 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 786 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 787 | + if ($num <= $max_aff) { |
|
| 788 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 789 | + $brut_sql .= '<p>'; |
|
| 790 | + foreach ($retours_sql as $key => $val) { |
|
| 791 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 792 | + } |
|
| 793 | + $brut_sql .= '</p>'; |
|
| 794 | + } |
|
| 795 | + $num++; |
|
| 796 | + } |
|
| 797 | + $res2 = interdire_scripts($brut_sql); |
|
| 798 | + foreach ($quoi as $view) { |
|
| 799 | + // ne pas afficher les $contexte_inclus |
|
| 800 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 801 | + if ($view) { |
|
| 802 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + } elseif ($affiche == 'code') { |
|
| 806 | + $legend = $nom; |
|
| 807 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 808 | + } elseif ($affiche == 'boucle') { |
|
| 809 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 810 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 811 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 812 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 813 | + } elseif ($affiche == 'squelette') { |
|
| 814 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 815 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return [$legend, $res, $res2]; |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | // https://code.spip.net/@debusquer_entete |
| 822 | 822 | function debusquer_entete($titre, $corps) { |
| 823 | 823 | |
| 824 | - include_spip('balise/formulaire_admin'); |
|
| 825 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 826 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 827 | - |
|
| 828 | - return _DOCTYPE_ECRIRE . |
|
| 829 | - html_lang_attributes() . |
|
| 830 | - "<head>\n<title>" . |
|
| 831 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 832 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 833 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 834 | - ")</title>\n" . |
|
| 835 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 836 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 837 | - "' />\n" . |
|
| 838 | - http_script('', 'jquery.js') |
|
| 839 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 840 | - . "' type='text/css' />" . |
|
| 841 | - "</head>\n" . |
|
| 842 | - "<body style='margin:0 10px;'>\n" . |
|
| 843 | - "<div id='spip-debug-header'>" . |
|
| 844 | - $corps . |
|
| 845 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 846 | - '</div></body></html>'; |
|
| 824 | + include_spip('balise/formulaire_admin'); |
|
| 825 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 826 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 827 | + |
|
| 828 | + return _DOCTYPE_ECRIRE . |
|
| 829 | + html_lang_attributes() . |
|
| 830 | + "<head>\n<title>" . |
|
| 831 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 832 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 833 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 834 | + ")</title>\n" . |
|
| 835 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 836 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 837 | + "' />\n" . |
|
| 838 | + http_script('', 'jquery.js') |
|
| 839 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 840 | + . "' type='text/css' />" . |
|
| 841 | + "</head>\n" . |
|
| 842 | + "<body style='margin:0 10px;'>\n" . |
|
| 843 | + "<div id='spip-debug-header'>" . |
|
| 844 | + $corps . |
|
| 845 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 846 | + '</div></body></html>'; |
|
| 847 | 847 | } |
@@ -20,181 +20,181 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // https://code.spip.net/@assembler |
| 32 | 32 | function assembler($fond, string $connect = '') { |
| 33 | 33 | |
| 34 | - $chemin_cache = null; |
|
| 35 | - $lastmodified = null; |
|
| 36 | - $res = null; |
|
| 37 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 38 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 39 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 40 | - |
|
| 41 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 42 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 43 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 44 | - ',\.[a-zA-Z0-9]*$,', |
|
| 45 | - '', |
|
| 46 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 47 | - ); |
|
| 48 | - // Cette fonction est utilisee deux fois |
|
| 49 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 50 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 51 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 52 | - if ($cacher) { |
|
| 53 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 54 | - } else { |
|
| 55 | - $GLOBALS['use_cache'] = -1; |
|
| 56 | - } |
|
| 57 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 58 | - if ($res) { |
|
| 59 | - return ['texte' => $res]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (!$chemin_cache || !$lastmodified) { |
|
| 63 | - $lastmodified = time(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 67 | - $calculer_page = true; |
|
| 68 | - |
|
| 69 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 70 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 71 | - // pages sont dynamiques) |
|
| 72 | - if ( |
|
| 73 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 74 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 75 | - and $chemin_cache |
|
| 76 | - and isset($page['entetes']) |
|
| 77 | - and isset($page['entetes']['Cache-Control']) |
|
| 78 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 79 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 80 | - ) { |
|
| 81 | - $since = preg_replace( |
|
| 82 | - '/;.*/', |
|
| 83 | - '', |
|
| 84 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 85 | - ); |
|
| 86 | - $since = str_replace('GMT', '', $since); |
|
| 87 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 88 | - $page['status'] = 304; |
|
| 89 | - $headers_only = true; |
|
| 90 | - $calculer_page = false; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 95 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 96 | - if (!$calculer_page) { |
|
| 97 | - $page['texte'] = ''; |
|
| 98 | - } else { |
|
| 99 | - // si la page est prise dans le cache |
|
| 100 | - if (!$GLOBALS['use_cache']) { |
|
| 101 | - // Informer les boutons d'admin du contexte |
|
| 102 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 103 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 104 | - |
|
| 105 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 106 | - // d'inversion url => objet |
|
| 107 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 108 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 109 | - #unset($_ENV['url_propre']); |
|
| 110 | - } else { |
|
| 111 | - // Compat ascendante : |
|
| 112 | - // 1. $contexte est global |
|
| 113 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 114 | - // et calculer la page |
|
| 115 | - if (!test_espace_prive()) { |
|
| 116 | - include_spip('inc/urls'); |
|
| 117 | - [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 118 | - nettoyer_uri(), |
|
| 119 | - $fond, |
|
| 120 | - $GLOBALS['contexte'], |
|
| 121 | - true |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - // squelette par defaut |
|
| 125 | - if (!strlen($fond)) { |
|
| 126 | - $fond = 'sommaire'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // produire la page : peut mettre a jour $lastmodified |
|
| 130 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 131 | - $page = $produire_page( |
|
| 132 | - $fond, |
|
| 133 | - $GLOBALS['contexte'], |
|
| 134 | - $GLOBALS['use_cache'], |
|
| 135 | - $chemin_cache, |
|
| 136 | - null, |
|
| 137 | - $page, |
|
| 138 | - $lastmodified, |
|
| 139 | - $connect |
|
| 140 | - ); |
|
| 141 | - if ($page === '') { |
|
| 142 | - $erreur = _T( |
|
| 143 | - 'info_erreur_squelette2', |
|
| 144 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 145 | - ); |
|
| 146 | - erreur_squelette($erreur); |
|
| 147 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 148 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($page and $chemin_cache) { |
|
| 153 | - $page['cache'] = $chemin_cache; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - auto_content_type($page); |
|
| 157 | - |
|
| 158 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 159 | - |
|
| 160 | - // Definir les entetes si ce n'est fait |
|
| 161 | - if (!$GLOBALS['flag_preserver']) { |
|
| 162 | - if ($GLOBALS['flag_ob']) { |
|
| 163 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 164 | - if ( |
|
| 165 | - trim($page['texte']) === '' |
|
| 166 | - and _VAR_MODE != 'debug' |
|
| 167 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 168 | - ) { |
|
| 169 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 170 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 171 | - } |
|
| 172 | - // pas de cache client en mode 'observation' |
|
| 173 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 174 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 175 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Entete Last-Modified: |
|
| 182 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 183 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 184 | - if ( |
|
| 185 | - $lastmodified |
|
| 186 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 187 | - and !isset($page['entetes']['Last-Modified']) |
|
| 188 | - ) { |
|
| 189 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // fermer la connexion apres les headers si requete HEAD |
|
| 193 | - if ($headers_only) { |
|
| 194 | - $page['entetes']['Connection'] = 'close'; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $page; |
|
| 34 | + $chemin_cache = null; |
|
| 35 | + $lastmodified = null; |
|
| 36 | + $res = null; |
|
| 37 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 38 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 39 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 40 | + |
|
| 41 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 42 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 43 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 44 | + ',\.[a-zA-Z0-9]*$,', |
|
| 45 | + '', |
|
| 46 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 47 | + ); |
|
| 48 | + // Cette fonction est utilisee deux fois |
|
| 49 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 50 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 51 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 52 | + if ($cacher) { |
|
| 53 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 54 | + } else { |
|
| 55 | + $GLOBALS['use_cache'] = -1; |
|
| 56 | + } |
|
| 57 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 58 | + if ($res) { |
|
| 59 | + return ['texte' => $res]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (!$chemin_cache || !$lastmodified) { |
|
| 63 | + $lastmodified = time(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 67 | + $calculer_page = true; |
|
| 68 | + |
|
| 69 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 70 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 71 | + // pages sont dynamiques) |
|
| 72 | + if ( |
|
| 73 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 74 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 75 | + and $chemin_cache |
|
| 76 | + and isset($page['entetes']) |
|
| 77 | + and isset($page['entetes']['Cache-Control']) |
|
| 78 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 79 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 80 | + ) { |
|
| 81 | + $since = preg_replace( |
|
| 82 | + '/;.*/', |
|
| 83 | + '', |
|
| 84 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 85 | + ); |
|
| 86 | + $since = str_replace('GMT', '', $since); |
|
| 87 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 88 | + $page['status'] = 304; |
|
| 89 | + $headers_only = true; |
|
| 90 | + $calculer_page = false; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 95 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 96 | + if (!$calculer_page) { |
|
| 97 | + $page['texte'] = ''; |
|
| 98 | + } else { |
|
| 99 | + // si la page est prise dans le cache |
|
| 100 | + if (!$GLOBALS['use_cache']) { |
|
| 101 | + // Informer les boutons d'admin du contexte |
|
| 102 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 103 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 104 | + |
|
| 105 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 106 | + // d'inversion url => objet |
|
| 107 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 108 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 109 | + #unset($_ENV['url_propre']); |
|
| 110 | + } else { |
|
| 111 | + // Compat ascendante : |
|
| 112 | + // 1. $contexte est global |
|
| 113 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 114 | + // et calculer la page |
|
| 115 | + if (!test_espace_prive()) { |
|
| 116 | + include_spip('inc/urls'); |
|
| 117 | + [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 118 | + nettoyer_uri(), |
|
| 119 | + $fond, |
|
| 120 | + $GLOBALS['contexte'], |
|
| 121 | + true |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + // squelette par defaut |
|
| 125 | + if (!strlen($fond)) { |
|
| 126 | + $fond = 'sommaire'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // produire la page : peut mettre a jour $lastmodified |
|
| 130 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 131 | + $page = $produire_page( |
|
| 132 | + $fond, |
|
| 133 | + $GLOBALS['contexte'], |
|
| 134 | + $GLOBALS['use_cache'], |
|
| 135 | + $chemin_cache, |
|
| 136 | + null, |
|
| 137 | + $page, |
|
| 138 | + $lastmodified, |
|
| 139 | + $connect |
|
| 140 | + ); |
|
| 141 | + if ($page === '') { |
|
| 142 | + $erreur = _T( |
|
| 143 | + 'info_erreur_squelette2', |
|
| 144 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 145 | + ); |
|
| 146 | + erreur_squelette($erreur); |
|
| 147 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 148 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($page and $chemin_cache) { |
|
| 153 | + $page['cache'] = $chemin_cache; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + auto_content_type($page); |
|
| 157 | + |
|
| 158 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 159 | + |
|
| 160 | + // Definir les entetes si ce n'est fait |
|
| 161 | + if (!$GLOBALS['flag_preserver']) { |
|
| 162 | + if ($GLOBALS['flag_ob']) { |
|
| 163 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 164 | + if ( |
|
| 165 | + trim($page['texte']) === '' |
|
| 166 | + and _VAR_MODE != 'debug' |
|
| 167 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 168 | + ) { |
|
| 169 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 170 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 171 | + } |
|
| 172 | + // pas de cache client en mode 'observation' |
|
| 173 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 174 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 175 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Entete Last-Modified: |
|
| 182 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 183 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 184 | + if ( |
|
| 185 | + $lastmodified |
|
| 186 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 187 | + and !isset($page['entetes']['Last-Modified']) |
|
| 188 | + ) { |
|
| 189 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // fermer la connexion apres les headers si requete HEAD |
|
| 193 | + if ($headers_only) { |
|
| 194 | + $page['entetes']['Connection'] = 'close'; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $page; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | function calculer_contexte() { |
| 215 | 215 | |
| 216 | - $contexte = []; |
|
| 217 | - foreach ($_GET as $var => $val) { |
|
| 218 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | - $contexte[$var] = $val; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - foreach ($_POST as $var => $val) { |
|
| 223 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 224 | - $contexte[$var] = $val; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $contexte; |
|
| 216 | + $contexte = []; |
|
| 217 | + foreach ($_GET as $var => $val) { |
|
| 218 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | + $contexte[$var] = $val; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + foreach ($_POST as $var => $val) { |
|
| 223 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 224 | + $contexte[$var] = $val; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $contexte; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,25 +236,25 @@ discard block |
||
| 236 | 236 | * @return array |
| 237 | 237 | */ |
| 238 | 238 | function calculer_contexte_implicite() { |
| 239 | - static $notes = null; |
|
| 240 | - if (is_null($notes)) { |
|
| 241 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 242 | - } |
|
| 243 | - $contexte_implicite = [ |
|
| 244 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 245 | - 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 246 | - 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 247 | - 'espace' => test_espace_prive(), |
|
| 248 | - 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 249 | - 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 250 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 251 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 252 | - ]; |
|
| 253 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 254 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $contexte_implicite; |
|
| 239 | + static $notes = null; |
|
| 240 | + if (is_null($notes)) { |
|
| 241 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 242 | + } |
|
| 243 | + $contexte_implicite = [ |
|
| 244 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 245 | + 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 246 | + 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 247 | + 'espace' => test_espace_prive(), |
|
| 248 | + 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 249 | + 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 250 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 251 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 252 | + ]; |
|
| 253 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 254 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $contexte_implicite; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // |
@@ -264,56 +264,56 @@ discard block |
||
| 264 | 264 | // https://code.spip.net/@auto_content_type |
| 265 | 265 | function auto_content_type($page) { |
| 266 | 266 | |
| 267 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 268 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 269 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 270 | - $page['texte'] |
|
| 271 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 272 | - } |
|
| 267 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 268 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 269 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 270 | + $page['texte'] |
|
| 271 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 272 | + } |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // https://code.spip.net/@inclure_page |
| 276 | 276 | function inclure_page($fond, $contexte, string $connect = '') { |
| 277 | - $use_cache = null; |
|
| 278 | - $chemin_cache = null; |
|
| 279 | - $lastinclude = null; |
|
| 280 | - $res = null; |
|
| 281 | - static $cacher, $produire_page; |
|
| 282 | - |
|
| 283 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 284 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 285 | - // (cette precaution n'est probablement plus utile) |
|
| 286 | - unset($contexte['fond']); |
|
| 287 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 288 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 289 | - if (is_null($cacher)) { |
|
| 290 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 291 | - } |
|
| 292 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 293 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 294 | - if ($cacher) { |
|
| 295 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 296 | - } else { |
|
| 297 | - $use_cache = -1; |
|
| 298 | - } |
|
| 299 | - // $res = message d'erreur : on sort de la |
|
| 300 | - if ($res) { |
|
| 301 | - return ['texte' => $res]; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 305 | - // produire la page : peut mettre a jour $lastinclude |
|
| 306 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 307 | - if ($use_cache) { |
|
| 308 | - if (is_null($produire_page)) { |
|
| 309 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 310 | - } |
|
| 311 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 312 | - } |
|
| 313 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 314 | - $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 315 | - |
|
| 316 | - return $page; |
|
| 277 | + $use_cache = null; |
|
| 278 | + $chemin_cache = null; |
|
| 279 | + $lastinclude = null; |
|
| 280 | + $res = null; |
|
| 281 | + static $cacher, $produire_page; |
|
| 282 | + |
|
| 283 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 284 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 285 | + // (cette precaution n'est probablement plus utile) |
|
| 286 | + unset($contexte['fond']); |
|
| 287 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 288 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 289 | + if (is_null($cacher)) { |
|
| 290 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 291 | + } |
|
| 292 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 293 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 294 | + if ($cacher) { |
|
| 295 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 296 | + } else { |
|
| 297 | + $use_cache = -1; |
|
| 298 | + } |
|
| 299 | + // $res = message d'erreur : on sort de la |
|
| 300 | + if ($res) { |
|
| 301 | + return ['texte' => $res]; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 305 | + // produire la page : peut mettre a jour $lastinclude |
|
| 306 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 307 | + if ($use_cache) { |
|
| 308 | + if (is_null($produire_page)) { |
|
| 309 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 310 | + } |
|
| 311 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 312 | + } |
|
| 313 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 314 | + $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 315 | + |
|
| 316 | + return $page; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -331,41 +331,41 @@ discard block |
||
| 331 | 331 | * @return array |
| 332 | 332 | */ |
| 333 | 333 | function public_produire_page_dist( |
| 334 | - $fond, |
|
| 335 | - $contexte, |
|
| 336 | - $use_cache, |
|
| 337 | - $chemin_cache, |
|
| 338 | - $contexte_cache, |
|
| 339 | - &$page, |
|
| 340 | - &$lastinclude, |
|
| 341 | - $connect = '' |
|
| 334 | + $fond, |
|
| 335 | + $contexte, |
|
| 336 | + $use_cache, |
|
| 337 | + $chemin_cache, |
|
| 338 | + $contexte_cache, |
|
| 339 | + &$page, |
|
| 340 | + &$lastinclude, |
|
| 341 | + $connect = '' |
|
| 342 | 342 | ) { |
| 343 | - static $parametrer, $cacher; |
|
| 344 | - if (!$parametrer) { |
|
| 345 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 346 | - } |
|
| 347 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 348 | - // et on l'enregistre sur le disque |
|
| 349 | - if ( |
|
| 350 | - $chemin_cache |
|
| 351 | - and $use_cache > -1 |
|
| 352 | - and is_array($page) |
|
| 353 | - and count($page) |
|
| 354 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 355 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 356 | - ) { |
|
| 357 | - if (is_null($cacher)) { |
|
| 358 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 359 | - } |
|
| 360 | - $lastinclude = time(); |
|
| 361 | - if ($cacher) { |
|
| 362 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 363 | - } else { |
|
| 364 | - $use_cache = -1; |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $page; |
|
| 343 | + static $parametrer, $cacher; |
|
| 344 | + if (!$parametrer) { |
|
| 345 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 346 | + } |
|
| 347 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 348 | + // et on l'enregistre sur le disque |
|
| 349 | + if ( |
|
| 350 | + $chemin_cache |
|
| 351 | + and $use_cache > -1 |
|
| 352 | + and is_array($page) |
|
| 353 | + and count($page) |
|
| 354 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 355 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 356 | + ) { |
|
| 357 | + if (is_null($cacher)) { |
|
| 358 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 359 | + } |
|
| 360 | + $lastinclude = time(); |
|
| 361 | + if ($cacher) { |
|
| 362 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 363 | + } else { |
|
| 364 | + $use_cache = -1; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $page; |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Fonction inseree par le compilateur dans le code compile. |
@@ -379,14 +379,14 @@ discard block |
||
| 379 | 379 | // 4: langue |
| 380 | 380 | |
| 381 | 381 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 382 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 383 | - |
|
| 384 | - if (!is_array($contexte_exec)) { |
|
| 385 | - echo $contexte_exec; |
|
| 386 | - } // message d'erreur etc |
|
| 387 | - else { |
|
| 388 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 389 | - } |
|
| 382 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 383 | + |
|
| 384 | + if (!is_array($contexte_exec)) { |
|
| 385 | + echo $contexte_exec; |
|
| 386 | + } // message d'erreur etc |
|
| 387 | + else { |
|
| 388 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 389 | + } |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -401,99 +401,99 @@ discard block |
||
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | 403 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 404 | - if (is_array($texte)) { |
|
| 405 | - [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 406 | - |
|
| 407 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 408 | - $d = $GLOBALS['delais'] ?? null; |
|
| 409 | - $GLOBALS['delais'] = $delainc; |
|
| 410 | - |
|
| 411 | - $page = recuperer_fond( |
|
| 412 | - $fond, |
|
| 413 | - $contexte_inclus, |
|
| 414 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 415 | - ); |
|
| 416 | - |
|
| 417 | - $texte = $page['texte']; |
|
| 418 | - |
|
| 419 | - $GLOBALS['delais'] = $d; |
|
| 420 | - // Faire remonter les entetes |
|
| 421 | - if (is_array($page['entetes'])) { |
|
| 422 | - // mais pas toutes |
|
| 423 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 424 | - unset($page['entetes']['Content-Type']); |
|
| 425 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 426 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 427 | - $GLOBALS['page']['entetes'] = []; |
|
| 428 | - } |
|
| 429 | - $GLOBALS['page']['entetes'] = |
|
| 430 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 434 | - if ( |
|
| 435 | - isset($page['contexte']['_pipelines']) |
|
| 436 | - and is_array($page['contexte']['_pipelines']) |
|
| 437 | - and count($page['contexte']['_pipelines']) |
|
| 438 | - ) { |
|
| 439 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 440 | - $args['contexte'] = $page['contexte']; |
|
| 441 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 442 | - $texte = pipeline( |
|
| 443 | - $pipe, |
|
| 444 | - [ |
|
| 445 | - 'data' => $texte, |
|
| 446 | - 'args' => $args |
|
| 447 | - ] |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 454 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 455 | - $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 456 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 457 | - } |
|
| 458 | - if ($echo) { |
|
| 459 | - echo $texte; |
|
| 460 | - } else { |
|
| 461 | - return $texte; |
|
| 462 | - } |
|
| 404 | + if (is_array($texte)) { |
|
| 405 | + [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 406 | + |
|
| 407 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 408 | + $d = $GLOBALS['delais'] ?? null; |
|
| 409 | + $GLOBALS['delais'] = $delainc; |
|
| 410 | + |
|
| 411 | + $page = recuperer_fond( |
|
| 412 | + $fond, |
|
| 413 | + $contexte_inclus, |
|
| 414 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 415 | + ); |
|
| 416 | + |
|
| 417 | + $texte = $page['texte']; |
|
| 418 | + |
|
| 419 | + $GLOBALS['delais'] = $d; |
|
| 420 | + // Faire remonter les entetes |
|
| 421 | + if (is_array($page['entetes'])) { |
|
| 422 | + // mais pas toutes |
|
| 423 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 424 | + unset($page['entetes']['Content-Type']); |
|
| 425 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 426 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 427 | + $GLOBALS['page']['entetes'] = []; |
|
| 428 | + } |
|
| 429 | + $GLOBALS['page']['entetes'] = |
|
| 430 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 434 | + if ( |
|
| 435 | + isset($page['contexte']['_pipelines']) |
|
| 436 | + and is_array($page['contexte']['_pipelines']) |
|
| 437 | + and count($page['contexte']['_pipelines']) |
|
| 438 | + ) { |
|
| 439 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 440 | + $args['contexte'] = $page['contexte']; |
|
| 441 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 442 | + $texte = pipeline( |
|
| 443 | + $pipe, |
|
| 444 | + [ |
|
| 445 | + 'data' => $texte, |
|
| 446 | + 'args' => $args |
|
| 447 | + ] |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 454 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 455 | + $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 456 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 457 | + } |
|
| 458 | + if ($echo) { |
|
| 459 | + echo $texte; |
|
| 460 | + } else { |
|
| 461 | + return $texte; |
|
| 462 | + } |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // https://code.spip.net/@message_page_indisponible |
| 466 | 466 | function message_page_indisponible($page, $contexte) { |
| 467 | - static $deja = false; |
|
| 468 | - if ($deja) { |
|
| 469 | - return 'erreur'; |
|
| 470 | - } |
|
| 471 | - $codes = [ |
|
| 472 | - '404' => '404 Not Found', |
|
| 473 | - '503' => '503 Service Unavailable', |
|
| 474 | - ]; |
|
| 475 | - |
|
| 476 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 477 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 478 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 479 | - if (!isset($contexte['lang'])) { |
|
| 480 | - include_spip('inc/lang'); |
|
| 481 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $deja = true; |
|
| 485 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 486 | - // ex restriction d'acces => 401 |
|
| 487 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 488 | - |
|
| 489 | - // produire la page d'erreur |
|
| 490 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 491 | - if (!$page) { |
|
| 492 | - $page = inclure_page('404', $contexte); |
|
| 493 | - } |
|
| 494 | - $page['status'] = $contexte['status']; |
|
| 495 | - |
|
| 496 | - return $page; |
|
| 467 | + static $deja = false; |
|
| 468 | + if ($deja) { |
|
| 469 | + return 'erreur'; |
|
| 470 | + } |
|
| 471 | + $codes = [ |
|
| 472 | + '404' => '404 Not Found', |
|
| 473 | + '503' => '503 Service Unavailable', |
|
| 474 | + ]; |
|
| 475 | + |
|
| 476 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 477 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 478 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 479 | + if (!isset($contexte['lang'])) { |
|
| 480 | + include_spip('inc/lang'); |
|
| 481 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $deja = true; |
|
| 485 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 486 | + // ex restriction d'acces => 401 |
|
| 487 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 488 | + |
|
| 489 | + // produire la page d'erreur |
|
| 490 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 491 | + if (!$page) { |
|
| 492 | + $page = inclure_page('404', $contexte); |
|
| 493 | + } |
|
| 494 | + $page['status'] = $contexte['status']; |
|
| 495 | + |
|
| 496 | + return $page; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -505,45 +505,45 @@ discard block |
||
| 505 | 505 | * @return mixed |
| 506 | 506 | */ |
| 507 | 507 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 508 | - static $balise_dyn_appellee_par_modele = null; |
|
| 509 | - switch ($operation) { |
|
| 510 | - case 'read': |
|
| 511 | - return $balise_dyn_appellee_par_modele; |
|
| 512 | - case 'reset': |
|
| 513 | - $balise_dyn_appellee_par_modele = null; |
|
| 514 | - return null; |
|
| 515 | - case 'set': |
|
| 516 | - default: |
|
| 517 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 518 | - return $arg; |
|
| 519 | - } |
|
| 508 | + static $balise_dyn_appellee_par_modele = null; |
|
| 509 | + switch ($operation) { |
|
| 510 | + case 'read': |
|
| 511 | + return $balise_dyn_appellee_par_modele; |
|
| 512 | + case 'reset': |
|
| 513 | + $balise_dyn_appellee_par_modele = null; |
|
| 514 | + return null; |
|
| 515 | + case 'set': |
|
| 516 | + default: |
|
| 517 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 518 | + return $arg; |
|
| 519 | + } |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // temporairement ici : a mettre dans le futur inc/modeles |
| 523 | 523 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 524 | 524 | // https://code.spip.net/@creer_contexte_de_modele |
| 525 | 525 | function creer_contexte_de_modele($args) { |
| 526 | - $contexte = []; |
|
| 527 | - foreach ($args as $var => $val) { |
|
| 528 | - if (is_int($var)) { // argument pas formate |
|
| 529 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 530 | - $var = 'align'; |
|
| 531 | - $contexte[$var] = $val; |
|
| 532 | - } else { |
|
| 533 | - $args = explode('=', $val); |
|
| 534 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 535 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 536 | - } else // notation abregee |
|
| 537 | - { |
|
| 538 | - $contexte[trim($val)] = trim($val); |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - } else { |
|
| 542 | - $contexte[$var] = $val; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return $contexte; |
|
| 526 | + $contexte = []; |
|
| 527 | + foreach ($args as $var => $val) { |
|
| 528 | + if (is_int($var)) { // argument pas formate |
|
| 529 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 530 | + $var = 'align'; |
|
| 531 | + $contexte[$var] = $val; |
|
| 532 | + } else { |
|
| 533 | + $args = explode('=', $val); |
|
| 534 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 535 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 536 | + } else // notation abregee |
|
| 537 | + { |
|
| 538 | + $contexte[trim($val)] = trim($val); |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + } else { |
|
| 542 | + $contexte[$var] = $val; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return $contexte; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -558,43 +558,43 @@ discard block |
||
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | 560 | function styliser_modele($modele, $id, $contexte = null) { |
| 561 | - static $styliseurs = null; |
|
| 562 | - if (is_null($styliseurs)) { |
|
| 563 | - $tables_objet = lister_tables_objets_sql(); |
|
| 564 | - foreach ($tables_objet as $table => $desc) { |
|
| 565 | - if ( |
|
| 566 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 567 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 568 | - and function_exists($desc['modeles_styliser']) |
|
| 569 | - ) { |
|
| 570 | - $primary = id_table_objet($table); |
|
| 571 | - foreach ($desc['modeles'] as $m) { |
|
| 572 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if (isset($styliseurs[$modele])) { |
|
| 579 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 580 | - $primary = $styliseurs[$modele]['primary']; |
|
| 581 | - if (is_null($id) and $contexte) { |
|
| 582 | - if (isset($contexte['id'])) { |
|
| 583 | - $id = $contexte['id']; |
|
| 584 | - } elseif (isset($contexte[$primary])) { |
|
| 585 | - $id = $contexte[$primary]; |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - if (is_null($id)) { |
|
| 589 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 590 | - erreur_squelette($msg); |
|
| 591 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 592 | - $id = 0; |
|
| 593 | - } |
|
| 594 | - $modele = $styliseur($modele, $id); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return $modele; |
|
| 561 | + static $styliseurs = null; |
|
| 562 | + if (is_null($styliseurs)) { |
|
| 563 | + $tables_objet = lister_tables_objets_sql(); |
|
| 564 | + foreach ($tables_objet as $table => $desc) { |
|
| 565 | + if ( |
|
| 566 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 567 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 568 | + and function_exists($desc['modeles_styliser']) |
|
| 569 | + ) { |
|
| 570 | + $primary = id_table_objet($table); |
|
| 571 | + foreach ($desc['modeles'] as $m) { |
|
| 572 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if (isset($styliseurs[$modele])) { |
|
| 579 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 580 | + $primary = $styliseurs[$modele]['primary']; |
|
| 581 | + if (is_null($id) and $contexte) { |
|
| 582 | + if (isset($contexte['id'])) { |
|
| 583 | + $id = $contexte['id']; |
|
| 584 | + } elseif (isset($contexte[$primary])) { |
|
| 585 | + $id = $contexte[$primary]; |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + if (is_null($id)) { |
|
| 589 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 590 | + erreur_squelette($msg); |
|
| 591 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 592 | + $id = 0; |
|
| 593 | + } |
|
| 594 | + $modele = $styliseur($modele, $id); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return $modele; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -613,102 +613,102 @@ discard block |
||
| 613 | 613 | */ |
| 614 | 614 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 615 | 615 | |
| 616 | - static $compteur; |
|
| 617 | - if (++$compteur > 10) { |
|
| 618 | - return ''; |
|
| 619 | - } # ne pas boucler indefiniment |
|
| 620 | - |
|
| 621 | - $type = strtolower($type); |
|
| 622 | - $type = styliser_modele($type, $id); |
|
| 623 | - |
|
| 624 | - $fond = $class = ''; |
|
| 625 | - |
|
| 626 | - $params = array_filter(explode('|', $params)); |
|
| 627 | - if ($params) { |
|
| 628 | - $soustype = current($params); |
|
| 629 | - $soustype = strtolower(trim($soustype)); |
|
| 630 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 631 | - $soustype = next($params); |
|
| 632 | - $soustype = strtolower($soustype); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 636 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 637 | - $fond = ''; |
|
| 638 | - $class = $soustype; |
|
| 639 | - } |
|
| 640 | - // enlever le sous type des params |
|
| 641 | - $params = array_diff($params, [$soustype]); |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 646 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 647 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 648 | - |
|
| 649 | - return false; |
|
| 650 | - } |
|
| 651 | - $fond = 'modeles/' . $fond; |
|
| 652 | - // Creer le contexte |
|
| 653 | - $contexte = $env; |
|
| 654 | - $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 |
|
| 655 | - |
|
| 656 | - // Le numero du modele est mis dans l'environnement |
|
| 657 | - // d'une part sous l'identifiant "id" |
|
| 658 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 659 | - // par la fonction id_table_objet, |
|
| 660 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 661 | - $_id = id_table_objet($type); |
|
| 662 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 663 | - |
|
| 664 | - if (isset($class)) { |
|
| 665 | - $contexte['class'] = $class; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 669 | - if ($lien) { |
|
| 670 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 671 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 672 | - $contexte['lien_class'] = $lien['class']; |
|
| 673 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 674 | - $contexte['lien_title'] = $lien['title']; |
|
| 675 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Traiter les parametres |
|
| 679 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 680 | - $arg_list = creer_contexte_de_modele($params); |
|
| 681 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 682 | - $contexte = array_merge($contexte, $arg_list); |
|
| 683 | - |
|
| 684 | - // Appliquer le modele avec le contexte |
|
| 685 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 686 | - |
|
| 687 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 688 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 689 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 690 | - if ( |
|
| 691 | - strstr( |
|
| 692 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 693 | - 'spip_lien_ok' |
|
| 694 | - ) |
|
| 695 | - ) { |
|
| 696 | - $retour = inserer_attribut( |
|
| 697 | - $retour, |
|
| 698 | - 'class', |
|
| 699 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 700 | - ); |
|
| 701 | - } else { |
|
| 702 | - if ($lien) { |
|
| 703 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - $compteur--; |
|
| 708 | - |
|
| 709 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 710 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 711 | - : $retour; |
|
| 616 | + static $compteur; |
|
| 617 | + if (++$compteur > 10) { |
|
| 618 | + return ''; |
|
| 619 | + } # ne pas boucler indefiniment |
|
| 620 | + |
|
| 621 | + $type = strtolower($type); |
|
| 622 | + $type = styliser_modele($type, $id); |
|
| 623 | + |
|
| 624 | + $fond = $class = ''; |
|
| 625 | + |
|
| 626 | + $params = array_filter(explode('|', $params)); |
|
| 627 | + if ($params) { |
|
| 628 | + $soustype = current($params); |
|
| 629 | + $soustype = strtolower(trim($soustype)); |
|
| 630 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 631 | + $soustype = next($params); |
|
| 632 | + $soustype = strtolower($soustype); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 636 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 637 | + $fond = ''; |
|
| 638 | + $class = $soustype; |
|
| 639 | + } |
|
| 640 | + // enlever le sous type des params |
|
| 641 | + $params = array_diff($params, [$soustype]); |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 646 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 647 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 648 | + |
|
| 649 | + return false; |
|
| 650 | + } |
|
| 651 | + $fond = 'modeles/' . $fond; |
|
| 652 | + // Creer le contexte |
|
| 653 | + $contexte = $env; |
|
| 654 | + $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 |
|
| 655 | + |
|
| 656 | + // Le numero du modele est mis dans l'environnement |
|
| 657 | + // d'une part sous l'identifiant "id" |
|
| 658 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 659 | + // par la fonction id_table_objet, |
|
| 660 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 661 | + $_id = id_table_objet($type); |
|
| 662 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 663 | + |
|
| 664 | + if (isset($class)) { |
|
| 665 | + $contexte['class'] = $class; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 669 | + if ($lien) { |
|
| 670 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 671 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 672 | + $contexte['lien_class'] = $lien['class']; |
|
| 673 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 674 | + $contexte['lien_title'] = $lien['title']; |
|
| 675 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Traiter les parametres |
|
| 679 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 680 | + $arg_list = creer_contexte_de_modele($params); |
|
| 681 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 682 | + $contexte = array_merge($contexte, $arg_list); |
|
| 683 | + |
|
| 684 | + // Appliquer le modele avec le contexte |
|
| 685 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 686 | + |
|
| 687 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 688 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 689 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 690 | + if ( |
|
| 691 | + strstr( |
|
| 692 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 693 | + 'spip_lien_ok' |
|
| 694 | + ) |
|
| 695 | + ) { |
|
| 696 | + $retour = inserer_attribut( |
|
| 697 | + $retour, |
|
| 698 | + 'class', |
|
| 699 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 700 | + ); |
|
| 701 | + } else { |
|
| 702 | + if ($lien) { |
|
| 703 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + $compteur--; |
|
| 708 | + |
|
| 709 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 710 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 711 | + : $retour; |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -718,99 +718,99 @@ discard block |
||
| 718 | 718 | // https://code.spip.net/@evaluer_fond |
| 719 | 719 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 720 | 720 | |
| 721 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 722 | - |
|
| 723 | - if (!$page) { |
|
| 724 | - return $page; |
|
| 725 | - } |
|
| 726 | - // eval $page et affecte $res |
|
| 727 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 728 | - |
|
| 729 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 730 | - // a destination de public/parametrer |
|
| 731 | - // pour remonter vers les inclusions appelantes |
|
| 732 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 733 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 734 | - if ( |
|
| 735 | - isset($page['invalideurs']) |
|
| 736 | - and isset($page['invalideurs']['session']) |
|
| 737 | - ) { |
|
| 738 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - return $page; |
|
| 721 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 722 | + |
|
| 723 | + if (!$page) { |
|
| 724 | + return $page; |
|
| 725 | + } |
|
| 726 | + // eval $page et affecte $res |
|
| 727 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 728 | + |
|
| 729 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 730 | + // a destination de public/parametrer |
|
| 731 | + // pour remonter vers les inclusions appelantes |
|
| 732 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 733 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 734 | + if ( |
|
| 735 | + isset($page['invalideurs']) |
|
| 736 | + and isset($page['invalideurs']['session']) |
|
| 737 | + ) { |
|
| 738 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + return $page; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
| 745 | 745 | // https://code.spip.net/@page_base_href |
| 746 | 746 | function page_base_href(&$texte) { |
| 747 | - static $set_html_base = null; |
|
| 748 | - if (is_null($set_html_base)) { |
|
| 749 | - if (!defined('_SET_HTML_BASE')) { |
|
| 750 | - // si la profondeur est superieure a 1 |
|
| 751 | - // est que ce n'est pas une url page ni une url action |
|
| 752 | - // activer par defaut |
|
| 753 | - $set_html_base = (( |
|
| 754 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 755 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 756 | - and !_request('action')) ? true : false); |
|
| 757 | - } else { |
|
| 758 | - $set_html_base = _SET_HTML_BASE; |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - if ( |
|
| 763 | - $set_html_base |
|
| 764 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 765 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 766 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 767 | - ) { |
|
| 768 | - $head = substr($texte, 0, $poshead); |
|
| 769 | - $insert = false; |
|
| 770 | - $href_base = false; |
|
| 771 | - if (strpos($head, '<base') === false) { |
|
| 772 | - $insert = true; |
|
| 773 | - } else { |
|
| 774 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 775 | - // sinon juste re-ecrire les ancres si besoin |
|
| 776 | - $insert = true; |
|
| 777 | - include_spip('inc/filtres'); |
|
| 778 | - $bases = extraire_balises($head, 'base'); |
|
| 779 | - foreach ($bases as $base) { |
|
| 780 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 781 | - $insert = false; |
|
| 782 | - break; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - if ($insert) { |
|
| 788 | - include_spip('inc/filtres_mini'); |
|
| 789 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 790 | - $href_base = url_absolue('./'); |
|
| 791 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 792 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 793 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 794 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 795 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 796 | - } |
|
| 797 | - $texte = $head . substr($texte, $poshead); |
|
| 798 | - } |
|
| 799 | - if ($href_base) { |
|
| 800 | - // gerer les ancres |
|
| 801 | - $base = $_SERVER['REQUEST_URI']; |
|
| 802 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 803 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 804 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 805 | - } |
|
| 806 | - if (strpos($texte, "href='#") !== false) { |
|
| 807 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 808 | - } |
|
| 809 | - if (strpos($texte, 'href="#') !== false) { |
|
| 810 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - } |
|
| 747 | + static $set_html_base = null; |
|
| 748 | + if (is_null($set_html_base)) { |
|
| 749 | + if (!defined('_SET_HTML_BASE')) { |
|
| 750 | + // si la profondeur est superieure a 1 |
|
| 751 | + // est que ce n'est pas une url page ni une url action |
|
| 752 | + // activer par defaut |
|
| 753 | + $set_html_base = (( |
|
| 754 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 755 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 756 | + and !_request('action')) ? true : false); |
|
| 757 | + } else { |
|
| 758 | + $set_html_base = _SET_HTML_BASE; |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + if ( |
|
| 763 | + $set_html_base |
|
| 764 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 765 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 766 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 767 | + ) { |
|
| 768 | + $head = substr($texte, 0, $poshead); |
|
| 769 | + $insert = false; |
|
| 770 | + $href_base = false; |
|
| 771 | + if (strpos($head, '<base') === false) { |
|
| 772 | + $insert = true; |
|
| 773 | + } else { |
|
| 774 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 775 | + // sinon juste re-ecrire les ancres si besoin |
|
| 776 | + $insert = true; |
|
| 777 | + include_spip('inc/filtres'); |
|
| 778 | + $bases = extraire_balises($head, 'base'); |
|
| 779 | + foreach ($bases as $base) { |
|
| 780 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 781 | + $insert = false; |
|
| 782 | + break; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + if ($insert) { |
|
| 788 | + include_spip('inc/filtres_mini'); |
|
| 789 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 790 | + $href_base = url_absolue('./'); |
|
| 791 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 792 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 793 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 794 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 795 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 796 | + } |
|
| 797 | + $texte = $head . substr($texte, $poshead); |
|
| 798 | + } |
|
| 799 | + if ($href_base) { |
|
| 800 | + // gerer les ancres |
|
| 801 | + $base = $_SERVER['REQUEST_URI']; |
|
| 802 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 803 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 804 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 805 | + } |
|
| 806 | + if (strpos($texte, "href='#") !== false) { |
|
| 807 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 808 | + } |
|
| 809 | + if (strpos($texte, 'href="#') !== false) { |
|
| 810 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | // et demarrent par X-Spip-... |
| 819 | 819 | // https://code.spip.net/@envoyer_entetes |
| 820 | 820 | function envoyer_entetes($entetes) { |
| 821 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 822 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 823 | - } |
|
| 821 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 822 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 823 | + } |
|
| 824 | 824 | } |
@@ -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 | } |
@@ -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 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** Début de la partie principale d'une boucle */ |
@@ -65,83 +65,83 @@ discard block |
||
| 65 | 65 | // https://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
| 67 | 67 | |
| 68 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | - $match = array_pad($match, 3, null); |
|
| 70 | - $p = strpos($texte, (string) $match[0]); |
|
| 71 | - $debut = substr($texte, 0, $p); |
|
| 72 | - if ($p) { |
|
| 73 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | - } |
|
| 75 | - $ligne += substr_count($debut, "\n"); |
|
| 76 | - $champ = new Inclure(); |
|
| 77 | - $champ->ligne = $ligne; |
|
| 78 | - $ligne += substr_count($match[0], "\n"); |
|
| 79 | - $fichier = $match[2]; |
|
| 80 | - # assurer ici la migration .php3 => .php |
|
| 81 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | - $fichier = $r[1]; |
|
| 84 | - } |
|
| 85 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | - $pos_apres = 0; |
|
| 89 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 91 | - if (!function_exists('normaliser_inclure')) { |
|
| 92 | - include_spip('public/normaliser'); |
|
| 93 | - } |
|
| 94 | - normaliser_inclure($champ); |
|
| 95 | - } |
|
| 96 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | - $result[] = $champ; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 68 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | + $match = array_pad($match, 3, null); |
|
| 70 | + $p = strpos($texte, (string) $match[0]); |
|
| 71 | + $debut = substr($texte, 0, $p); |
|
| 72 | + if ($p) { |
|
| 73 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | + } |
|
| 75 | + $ligne += substr_count($debut, "\n"); |
|
| 76 | + $champ = new Inclure(); |
|
| 77 | + $champ->ligne = $ligne; |
|
| 78 | + $ligne += substr_count($match[0], "\n"); |
|
| 79 | + $fichier = $match[2]; |
|
| 80 | + # assurer ici la migration .php3 => .php |
|
| 81 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | + $fichier = $r[1]; |
|
| 84 | + } |
|
| 85 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | + $pos_apres = 0; |
|
| 89 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 91 | + if (!function_exists('normaliser_inclure')) { |
|
| 92 | + include_spip('public/normaliser'); |
|
| 93 | + } |
|
| 94 | + normaliser_inclure($champ); |
|
| 95 | + } |
|
| 96 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 97 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | + $result[] = $champ; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // https://code.spip.net/@phraser_polyglotte |
| 105 | 105 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 106 | |
| 107 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | - foreach ($m as $match) { |
|
| 109 | - $p = strpos($texte, (string) $match[0]); |
|
| 110 | - $debut = substr($texte, 0, $p); |
|
| 111 | - if ($p) { |
|
| 112 | - $champ = new Texte(); |
|
| 113 | - $champ->texte = $debut; |
|
| 114 | - $champ->ligne = $ligne; |
|
| 115 | - $result[] = $champ; |
|
| 116 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $champ = new Polyglotte(); |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $ligne += substr_count($match[0], "\n"); |
|
| 122 | - $lang = ''; |
|
| 123 | - $bloc = $match[1]; |
|
| 124 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | - $trad = $regs[1]; |
|
| 127 | - if ($trad or $lang) { |
|
| 128 | - $champ->traductions[$lang] = $trad; |
|
| 129 | - } |
|
| 130 | - $lang = $regs[2]; |
|
| 131 | - $bloc = $regs[3]; |
|
| 132 | - } |
|
| 133 | - $champ->traductions[$lang] = $bloc; |
|
| 134 | - $result[] = $champ; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if ($texte !== '') { |
|
| 138 | - $champ = new Texte(); |
|
| 139 | - $champ->texte = $texte; |
|
| 140 | - $champ->ligne = $ligne; |
|
| 141 | - $result[] = $champ; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $result; |
|
| 107 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | + foreach ($m as $match) { |
|
| 109 | + $p = strpos($texte, (string) $match[0]); |
|
| 110 | + $debut = substr($texte, 0, $p); |
|
| 111 | + if ($p) { |
|
| 112 | + $champ = new Texte(); |
|
| 113 | + $champ->texte = $debut; |
|
| 114 | + $champ->ligne = $ligne; |
|
| 115 | + $result[] = $champ; |
|
| 116 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $champ = new Polyglotte(); |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $ligne += substr_count($match[0], "\n"); |
|
| 122 | + $lang = ''; |
|
| 123 | + $bloc = $match[1]; |
|
| 124 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 126 | + $trad = $regs[1]; |
|
| 127 | + if ($trad or $lang) { |
|
| 128 | + $champ->traductions[$lang] = $trad; |
|
| 129 | + } |
|
| 130 | + $lang = $regs[2]; |
|
| 131 | + $bloc = $regs[3]; |
|
| 132 | + } |
|
| 133 | + $champ->traductions[$lang] = $bloc; |
|
| 134 | + $result[] = $champ; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if ($texte !== '') { |
|
| 138 | + $champ = new Texte(); |
|
| 139 | + $champ->texte = $texte; |
|
| 140 | + $champ->ligne = $ligne; |
|
| 141 | + $result[] = $champ; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $result; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -163,43 +163,43 @@ discard block |
||
| 163 | 163 | * @return array |
| 164 | 164 | **/ |
| 165 | 165 | function phraser_idiomes($texte, $ligne, $result) { |
| 166 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | - $match = array_pad($match, 8, null); |
|
| 168 | - $p = strpos($texte, (string) $match[0]); |
|
| 169 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | - if ($debut) { |
|
| 172 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | - } |
|
| 174 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | - $ligne += substr_count($debut, "\n"); |
|
| 176 | - if ($ko) { |
|
| 177 | - continue; |
|
| 178 | - } // faux idiome |
|
| 179 | - $champ = new Idiome(); |
|
| 180 | - $champ->ligne = $ligne; |
|
| 181 | - $ligne += substr_count($match[0], "\n"); |
|
| 182 | - // Stocker les arguments de la balise de traduction |
|
| 183 | - $args = []; |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | - $largs = substr($largs, strlen($r[0])); |
|
| 188 | - } |
|
| 189 | - $champ->arg = $args; |
|
| 190 | - $champ->nom_champ = strtolower($match[3]); |
|
| 191 | - $champ->module = $match[2]; |
|
| 192 | - // pas d'imbrication pour les filtres sur langue |
|
| 193 | - $pos_apres = 0; |
|
| 194 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 195 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 196 | - $result[] = $champ; |
|
| 197 | - } |
|
| 198 | - if ($texte !== '') { |
|
| 199 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $result; |
|
| 166 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | + $match = array_pad($match, 8, null); |
|
| 168 | + $p = strpos($texte, (string) $match[0]); |
|
| 169 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | + if ($debut) { |
|
| 172 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | + } |
|
| 174 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | + $ligne += substr_count($debut, "\n"); |
|
| 176 | + if ($ko) { |
|
| 177 | + continue; |
|
| 178 | + } // faux idiome |
|
| 179 | + $champ = new Idiome(); |
|
| 180 | + $champ->ligne = $ligne; |
|
| 181 | + $ligne += substr_count($match[0], "\n"); |
|
| 182 | + // Stocker les arguments de la balise de traduction |
|
| 183 | + $args = []; |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 187 | + $largs = substr($largs, strlen($r[0])); |
|
| 188 | + } |
|
| 189 | + $champ->arg = $args; |
|
| 190 | + $champ->nom_champ = strtolower($match[3]); |
|
| 191 | + $champ->module = $match[2]; |
|
| 192 | + // pas d'imbrication pour les filtres sur langue |
|
| 193 | + $pos_apres = 0; |
|
| 194 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 195 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 196 | + $result[] = $champ; |
|
| 197 | + } |
|
| 198 | + if ($texte !== '') { |
|
| 199 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $result; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -217,47 +217,47 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | - $p = strpos($texte, (string) $match[0]); |
|
| 222 | - // texte après la balise |
|
| 223 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | - |
|
| 225 | - $debut = substr($texte, 0, $p); |
|
| 226 | - if ($p) { |
|
| 227 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | - } |
|
| 229 | - $ligne += substr_count($debut, "\n"); |
|
| 230 | - $champ = new Champ(); |
|
| 231 | - $champ->ligne = $ligne; |
|
| 232 | - $ligne += substr_count($match[0], "\n"); |
|
| 233 | - $champ->nom_boucle = $match[2]; |
|
| 234 | - $champ->nom_champ = $match[3]; |
|
| 235 | - $champ->etoile = $match[5]; |
|
| 236 | - |
|
| 237 | - if ($suite and $suite[0] == '{') { |
|
| 238 | - phraser_arg($suite, '', [], $champ); |
|
| 239 | - // ce ltrim est une ereur de conception |
|
| 240 | - // mais on le conserve par souci de compatibilite |
|
| 241 | - $texte = ltrim($suite); |
|
| 242 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 220 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | + $p = strpos($texte, (string) $match[0]); |
|
| 222 | + // texte après la balise |
|
| 223 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | + |
|
| 225 | + $debut = substr($texte, 0, $p); |
|
| 226 | + if ($p) { |
|
| 227 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | + } |
|
| 229 | + $ligne += substr_count($debut, "\n"); |
|
| 230 | + $champ = new Champ(); |
|
| 231 | + $champ->ligne = $ligne; |
|
| 232 | + $ligne += substr_count($match[0], "\n"); |
|
| 233 | + $champ->nom_boucle = $match[2]; |
|
| 234 | + $champ->nom_champ = $match[3]; |
|
| 235 | + $champ->etoile = $match[5]; |
|
| 236 | + |
|
| 237 | + if ($suite and $suite[0] == '{') { |
|
| 238 | + phraser_arg($suite, '', [], $champ); |
|
| 239 | + // ce ltrim est une ereur de conception |
|
| 240 | + // mais on le conserve par souci de compatibilite |
|
| 241 | + $texte = ltrim($suite); |
|
| 242 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 245 | 245 | if ($n = (strlen($suite) - strlen($texte))) { |
| 246 | 246 | $champ->apres = array(new Texte); |
| 247 | 247 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 248 | 248 | } |
| 249 | 249 | */ |
| 250 | - } else { |
|
| 251 | - $texte = $suite; |
|
| 252 | - } |
|
| 253 | - phraser_vieux($champ); |
|
| 254 | - $result[] = $champ; |
|
| 255 | - } |
|
| 256 | - if ($texte !== '') { |
|
| 257 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $result; |
|
| 250 | + } else { |
|
| 251 | + $texte = $suite; |
|
| 252 | + } |
|
| 253 | + phraser_vieux($champ); |
|
| 254 | + $result[] = $champ; |
|
| 255 | + } |
|
| 256 | + if ($texte !== '') { |
|
| 257 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $result; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Gestion des imbrications: |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // https://code.spip.net/@phraser_champs_etendus |
| 269 | 269 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 270 | - if ($texte === '') { |
|
| 271 | - return $result; |
|
| 272 | - } |
|
| 273 | - $sep = '##'; |
|
| 274 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 275 | - $sep .= '#'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 270 | + if ($texte === '') { |
|
| 271 | + return $result; |
|
| 272 | + } |
|
| 273 | + $sep = '##'; |
|
| 274 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 275 | + $sep .= '#'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -296,278 +296,278 @@ discard block |
||
| 296 | 296 | * @return array |
| 297 | 297 | */ |
| 298 | 298 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 299 | - $length = strlen($texte); |
|
| 300 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | - $pos_debut++; |
|
| 302 | - } |
|
| 303 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | - $st = substr($texte, $pos_debut); |
|
| 306 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | - $pos_debut = $length - strlen($st); |
|
| 308 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | - $pos_debut++; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $result; |
|
| 299 | + $length = strlen($texte); |
|
| 300 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | + $pos_debut++; |
|
| 302 | + } |
|
| 303 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | + $st = substr($texte, $pos_debut); |
|
| 306 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | + $pos_debut = $length - strlen($st); |
|
| 308 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | + $pos_debut++; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $result; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // https://code.spip.net/@phraser_arg |
| 317 | 317 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 318 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | - $suite = ltrim($match[2]); |
|
| 320 | - $fonc = trim($match[1]); |
|
| 321 | - if ($fonc && $fonc[0] == '|') { |
|
| 322 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | - } |
|
| 324 | - $res = [$fonc]; |
|
| 325 | - $err_f = ''; |
|
| 326 | - // cas du filtre sans argument ou du critere / |
|
| 327 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | - if (!$match[1]) { |
|
| 330 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | - $texte = ''; |
|
| 333 | - } else { |
|
| 334 | - $texte = $suite; |
|
| 335 | - } |
|
| 336 | - if ($err_f) { |
|
| 337 | - $pointeur_champ->param = false; |
|
| 338 | - } elseif ($fonc !== '') { |
|
| 339 | - $pointeur_champ->param[] = $res; |
|
| 340 | - } |
|
| 341 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | - |
|
| 344 | - return $result; |
|
| 345 | - } |
|
| 346 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | - $collecte = []; |
|
| 348 | - while ($args && $args[0] != '}') { |
|
| 349 | - if ($args[0] == '"') { |
|
| 350 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | - } elseif ($args[0] == "'") { |
|
| 352 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | - } else { |
|
| 354 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | - $champ = new Texte(); |
|
| 359 | - $champ->apres = $champ->avant = $args = ''; |
|
| 360 | - break; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - $arg = $regs[2]; |
|
| 364 | - if (trim($regs[1])) { |
|
| 365 | - $champ = new Texte(); |
|
| 366 | - $champ->texte = $arg; |
|
| 367 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | - $result[] = $champ; |
|
| 369 | - $collecte[] = $champ; |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - } else { |
|
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | - // 0 est un aveu d'impuissance. A completer |
|
| 374 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | - |
|
| 376 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | - $collecte = array_merge($collecte, $arg); |
|
| 378 | - $result = array_merge($result, $arg); |
|
| 379 | - } else { |
|
| 380 | - $n = strpos($args, (string) $r[0]); |
|
| 381 | - $pred = substr($args, 0, $n); |
|
| 382 | - $par = ',}'; |
|
| 383 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | - $pred = $m[1]; |
|
| 385 | - $par = ')'; |
|
| 386 | - } |
|
| 387 | - if ($pred) { |
|
| 388 | - $champ = new Texte(); |
|
| 389 | - $champ->texte = $pred; |
|
| 390 | - $champ->apres = $champ->avant = ''; |
|
| 391 | - $result[] = $champ; |
|
| 392 | - $collecte[] = $champ; |
|
| 393 | - } |
|
| 394 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | - $champ = new Champ(); |
|
| 396 | - $champ->nom_boucle = $r[2]; |
|
| 397 | - $champ->nom_champ = $r[3]; |
|
| 398 | - $champ->etoile = $r[5]; |
|
| 399 | - $next = $r[6]; |
|
| 400 | - while ($next == '{') { |
|
| 401 | - phraser_arg($rec, $sep, [], $champ); |
|
| 402 | - $args = ltrim($rec); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - while ($next == '|') { |
|
| 406 | - $pos_apres = 0; |
|
| 407 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | - $args = substr($rec, $pos_apres); |
|
| 409 | - $next = $args[0] ?? ''; |
|
| 410 | - } |
|
| 411 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | - if ($champ->param === false) { |
|
| 413 | - $err_f = true; |
|
| 414 | - } else { |
|
| 415 | - phraser_vieux($champ); |
|
| 416 | - } |
|
| 417 | - if ($par == ')') { |
|
| 418 | - $args = substr($args, 1); |
|
| 419 | - } |
|
| 420 | - $collecte[] = $champ; |
|
| 421 | - $result[] = $champ; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | - $args = ltrim(substr($args, 1)); |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - if ($collecte) { |
|
| 433 | - $res[] = $collecte; |
|
| 434 | - $collecte = []; |
|
| 435 | - } |
|
| 436 | - $texte = substr($args, 1); |
|
| 437 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | - // propager les erreurs, et ignorer les param vides |
|
| 439 | - if ($pointeur_champ->param !== false) { |
|
| 440 | - if ($err_f) { |
|
| 441 | - $pointeur_champ->param = false; |
|
| 442 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | - $pointeur_champ->param[] = $res; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | - |
|
| 449 | - return $result; |
|
| 318 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | + $suite = ltrim($match[2]); |
|
| 320 | + $fonc = trim($match[1]); |
|
| 321 | + if ($fonc && $fonc[0] == '|') { |
|
| 322 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | + } |
|
| 324 | + $res = [$fonc]; |
|
| 325 | + $err_f = ''; |
|
| 326 | + // cas du filtre sans argument ou du critere / |
|
| 327 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | + if (!$match[1]) { |
|
| 330 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | + $texte = ''; |
|
| 333 | + } else { |
|
| 334 | + $texte = $suite; |
|
| 335 | + } |
|
| 336 | + if ($err_f) { |
|
| 337 | + $pointeur_champ->param = false; |
|
| 338 | + } elseif ($fonc !== '') { |
|
| 339 | + $pointeur_champ->param[] = $res; |
|
| 340 | + } |
|
| 341 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | + |
|
| 344 | + return $result; |
|
| 345 | + } |
|
| 346 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | + $collecte = []; |
|
| 348 | + while ($args && $args[0] != '}') { |
|
| 349 | + if ($args[0] == '"') { |
|
| 350 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | + } elseif ($args[0] == "'") { |
|
| 352 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | + } else { |
|
| 354 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | + $champ = new Texte(); |
|
| 359 | + $champ->apres = $champ->avant = $args = ''; |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + $arg = $regs[2]; |
|
| 364 | + if (trim($regs[1])) { |
|
| 365 | + $champ = new Texte(); |
|
| 366 | + $champ->texte = $arg; |
|
| 367 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | + $result[] = $champ; |
|
| 369 | + $collecte[] = $champ; |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + } else { |
|
| 372 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | + // 0 est un aveu d'impuissance. A completer |
|
| 374 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | + |
|
| 376 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | + $collecte = array_merge($collecte, $arg); |
|
| 378 | + $result = array_merge($result, $arg); |
|
| 379 | + } else { |
|
| 380 | + $n = strpos($args, (string) $r[0]); |
|
| 381 | + $pred = substr($args, 0, $n); |
|
| 382 | + $par = ',}'; |
|
| 383 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | + $pred = $m[1]; |
|
| 385 | + $par = ')'; |
|
| 386 | + } |
|
| 387 | + if ($pred) { |
|
| 388 | + $champ = new Texte(); |
|
| 389 | + $champ->texte = $pred; |
|
| 390 | + $champ->apres = $champ->avant = ''; |
|
| 391 | + $result[] = $champ; |
|
| 392 | + $collecte[] = $champ; |
|
| 393 | + } |
|
| 394 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | + $champ = new Champ(); |
|
| 396 | + $champ->nom_boucle = $r[2]; |
|
| 397 | + $champ->nom_champ = $r[3]; |
|
| 398 | + $champ->etoile = $r[5]; |
|
| 399 | + $next = $r[6]; |
|
| 400 | + while ($next == '{') { |
|
| 401 | + phraser_arg($rec, $sep, [], $champ); |
|
| 402 | + $args = ltrim($rec); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + while ($next == '|') { |
|
| 406 | + $pos_apres = 0; |
|
| 407 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | + $args = substr($rec, $pos_apres); |
|
| 409 | + $next = $args[0] ?? ''; |
|
| 410 | + } |
|
| 411 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | + if ($champ->param === false) { |
|
| 413 | + $err_f = true; |
|
| 414 | + } else { |
|
| 415 | + phraser_vieux($champ); |
|
| 416 | + } |
|
| 417 | + if ($par == ')') { |
|
| 418 | + $args = substr($args, 1); |
|
| 419 | + } |
|
| 420 | + $collecte[] = $champ; |
|
| 421 | + $result[] = $champ; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | + $args = ltrim(substr($args, 1)); |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + if ($collecte) { |
|
| 433 | + $res[] = $collecte; |
|
| 434 | + $collecte = []; |
|
| 435 | + } |
|
| 436 | + $texte = substr($args, 1); |
|
| 437 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | + // propager les erreurs, et ignorer les param vides |
|
| 439 | + if ($pointeur_champ->param !== false) { |
|
| 440 | + if ($err_f) { |
|
| 441 | + $pointeur_champ->param = false; |
|
| 442 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | + $pointeur_champ->param[] = $res; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | + |
|
| 449 | + return $result; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| 453 | 453 | // https://code.spip.net/@phraser_champs_exterieurs |
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | - $res = []; |
|
| 456 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - $debut = substr($texte, 0, $p); |
|
| 461 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | - if ($p) { |
|
| 463 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | - } |
|
| 465 | - $ligne += substr_count($debut, "\n"); |
|
| 466 | - $res[] = $nested[$m[1]]; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 455 | + $res = []; |
|
| 456 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 457 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + $debut = substr($texte, 0, $p); |
|
| 461 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | + if ($p) { |
|
| 463 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | + } |
|
| 465 | + $ligne += substr_count($debut, "\n"); |
|
| 466 | + $res[] = $nested[$m[1]]; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // https://code.spip.net/@phraser_champs_interieurs |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, (string) $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, (string) $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,201 +595,201 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = ''; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = ''; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = [...$args, ...$doublons]; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = ''; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = ''; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = [...$args, ...$doublons]; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | // https://code.spip.net/@phraser_critere_infixe |
| 780 | 780 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 781 | - $args[0] = new Texte(); |
|
| 782 | - $args[0]->texte = $arg1; |
|
| 783 | - $args[0] = [$args[0]]; |
|
| 784 | - $args[1][0] = new Texte(); |
|
| 785 | - $args[1][0]->texte = $arg2; |
|
| 786 | - $crit = new Critere(); |
|
| 787 | - $crit->op = $op; |
|
| 788 | - $crit->not = $not; |
|
| 789 | - $crit->cond = $cond; |
|
| 790 | - $crit->param = $args; |
|
| 791 | - |
|
| 792 | - return $crit; |
|
| 781 | + $args[0] = new Texte(); |
|
| 782 | + $args[0]->texte = $arg1; |
|
| 783 | + $args[0] = [$args[0]]; |
|
| 784 | + $args[1][0] = new Texte(); |
|
| 785 | + $args[1][0]->texte = $arg2; |
|
| 786 | + $crit = new Critere(); |
|
| 787 | + $crit->op = $op; |
|
| 788 | + $crit->not = $not; |
|
| 789 | + $crit->cond = $cond; |
|
| 790 | + $crit->param = $args; |
|
| 791 | + |
|
| 792 | + return $crit; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -800,12 +800,12 @@ discard block |
||
| 800 | 800 | * @return int |
| 801 | 801 | */ |
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | - if (is_null($fin)) { |
|
| 804 | - return substr_count($texte, "\n", $debut); |
|
| 805 | - } |
|
| 806 | - else { |
|
| 807 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | - } |
|
| 803 | + if (is_null($fin)) { |
|
| 804 | + return substr_count($texte, "\n", $debut); |
|
| 805 | + } |
|
| 806 | + else { |
|
| 807 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | + } |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -821,87 +821,87 @@ discard block |
||
| 821 | 821 | * @return array|null |
| 822 | 822 | */ |
| 823 | 823 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 824 | - $premiere_boucle = null; |
|
| 825 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | - |
|
| 827 | - $current_pos = $pos_debut_texte; |
|
| 828 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | - $current_pos = $pos_boucle + 1; |
|
| 830 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | - |
|
| 832 | - $id_boucle = ''; |
|
| 833 | - if ($pos_parent !== false) { |
|
| 834 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | - } |
|
| 836 | - if ( |
|
| 837 | - $pos_parent === false |
|
| 838 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | - ) { |
|
| 840 | - $result = new Boucle(); |
|
| 841 | - $result->id_parent = $id_parent; |
|
| 842 | - $result->descr = $descr; |
|
| 843 | - |
|
| 844 | - // un id_boucle pour l'affichage de l'erreur |
|
| 845 | - if (!strlen($id_boucle)) { |
|
| 846 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | - } |
|
| 848 | - $result->id_boucle = $id_boucle; |
|
| 849 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | - erreur_squelette($err_b, $result); |
|
| 851 | - |
|
| 852 | - continue; |
|
| 853 | - } |
|
| 854 | - else { |
|
| 855 | - $boucle = [ |
|
| 856 | - 'id_boucle' => $id_boucle, |
|
| 857 | - 'id_boucle_err' => $id_boucle, |
|
| 858 | - 'debut_boucle' => $pos_boucle, |
|
| 859 | - 'pos_boucle' => $pos_boucle, |
|
| 860 | - 'pos_parent' => $pos_parent, |
|
| 861 | - 'pos_precond' => false, |
|
| 862 | - 'pos_precond_inside' => false, |
|
| 863 | - 'pos_preaff' => false, |
|
| 864 | - 'pos_preaff_inside' => false, |
|
| 865 | - ]; |
|
| 866 | - |
|
| 867 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | - if (!strlen($id_boucle)) { |
|
| 869 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | - if ( |
|
| 876 | - $pos_precond !== false |
|
| 877 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | - ) { |
|
| 879 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond'] = $pos_precond; |
|
| 881 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | - if ( |
|
| 887 | - $pos_preaff !== false |
|
| 888 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | - ) { |
|
| 890 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | - } |
|
| 894 | - if (!strlen($id_boucle)) { |
|
| 895 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | - $premiere_boucle = $boucle; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $premiere_boucle; |
|
| 824 | + $premiere_boucle = null; |
|
| 825 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | + |
|
| 827 | + $current_pos = $pos_debut_texte; |
|
| 828 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | + $current_pos = $pos_boucle + 1; |
|
| 830 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | + |
|
| 832 | + $id_boucle = ''; |
|
| 833 | + if ($pos_parent !== false) { |
|
| 834 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | + } |
|
| 836 | + if ( |
|
| 837 | + $pos_parent === false |
|
| 838 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | + ) { |
|
| 840 | + $result = new Boucle(); |
|
| 841 | + $result->id_parent = $id_parent; |
|
| 842 | + $result->descr = $descr; |
|
| 843 | + |
|
| 844 | + // un id_boucle pour l'affichage de l'erreur |
|
| 845 | + if (!strlen($id_boucle)) { |
|
| 846 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | + } |
|
| 848 | + $result->id_boucle = $id_boucle; |
|
| 849 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | + erreur_squelette($err_b, $result); |
|
| 851 | + |
|
| 852 | + continue; |
|
| 853 | + } |
|
| 854 | + else { |
|
| 855 | + $boucle = [ |
|
| 856 | + 'id_boucle' => $id_boucle, |
|
| 857 | + 'id_boucle_err' => $id_boucle, |
|
| 858 | + 'debut_boucle' => $pos_boucle, |
|
| 859 | + 'pos_boucle' => $pos_boucle, |
|
| 860 | + 'pos_parent' => $pos_parent, |
|
| 861 | + 'pos_precond' => false, |
|
| 862 | + 'pos_precond_inside' => false, |
|
| 863 | + 'pos_preaff' => false, |
|
| 864 | + 'pos_preaff_inside' => false, |
|
| 865 | + ]; |
|
| 866 | + |
|
| 867 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | + if (!strlen($id_boucle)) { |
|
| 869 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | + if ( |
|
| 876 | + $pos_precond !== false |
|
| 877 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | + ) { |
|
| 879 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond'] = $pos_precond; |
|
| 881 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | + if ( |
|
| 887 | + $pos_preaff !== false |
|
| 888 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | + ) { |
|
| 890 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | + } |
|
| 894 | + if (!strlen($id_boucle)) { |
|
| 895 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | + $premiere_boucle = $boucle; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $premiere_boucle; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -916,68 +916,68 @@ discard block |
||
| 916 | 916 | * @return mixed |
| 917 | 917 | */ |
| 918 | 918 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 919 | - $id_boucle = $boucle['id_boucle']; |
|
| 920 | - $pos_courante = $pos_debut_texte; |
|
| 921 | - |
|
| 922 | - $boucle['pos_postcond'] = false; |
|
| 923 | - $boucle['pos_postcond_inside'] = false; |
|
| 924 | - $boucle['pos_altern'] = false; |
|
| 925 | - $boucle['pos_altern_inside'] = false; |
|
| 926 | - $boucle['pos_postaff'] = false; |
|
| 927 | - $boucle['pos_postaff_inside'] = false; |
|
| 928 | - |
|
| 929 | - $pos_anonyme_next = null; |
|
| 930 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | - if (!strlen($id_boucle)) { |
|
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // |
|
| 936 | - // 1. Recuperer la partie conditionnelle apres |
|
| 937 | - // |
|
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | - if ( |
|
| 941 | - $pos_apres !== false |
|
| 942 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | - ) { |
|
| 944 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | - $pos_apres += strlen($apres_boucle); |
|
| 946 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | - $pos_courante = $pos_apres ; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // |
|
| 951 | - // 2. Récuperer la partie alternative apres |
|
| 952 | - // |
|
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | - if ( |
|
| 956 | - $pos_altern !== false |
|
| 957 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | - ) { |
|
| 959 | - $boucle['pos_altern'] = $pos_altern; |
|
| 960 | - $pos_altern += strlen($altern_boucle); |
|
| 961 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | - $pos_courante = $pos_altern; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - // |
|
| 966 | - // 3. Recuperer la partie footer non alternative |
|
| 967 | - // |
|
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | - if ( |
|
| 971 | - $pos_postaff !== false |
|
| 972 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | - ) { |
|
| 974 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | - $pos_postaff += strlen($postaff_boucle); |
|
| 976 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | - $pos_courante = $pos_postaff ; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - return $boucle; |
|
| 919 | + $id_boucle = $boucle['id_boucle']; |
|
| 920 | + $pos_courante = $pos_debut_texte; |
|
| 921 | + |
|
| 922 | + $boucle['pos_postcond'] = false; |
|
| 923 | + $boucle['pos_postcond_inside'] = false; |
|
| 924 | + $boucle['pos_altern'] = false; |
|
| 925 | + $boucle['pos_altern_inside'] = false; |
|
| 926 | + $boucle['pos_postaff'] = false; |
|
| 927 | + $boucle['pos_postaff_inside'] = false; |
|
| 928 | + |
|
| 929 | + $pos_anonyme_next = null; |
|
| 930 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | + if (!strlen($id_boucle)) { |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // |
|
| 936 | + // 1. Recuperer la partie conditionnelle apres |
|
| 937 | + // |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | + if ( |
|
| 941 | + $pos_apres !== false |
|
| 942 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | + ) { |
|
| 944 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | + $pos_apres += strlen($apres_boucle); |
|
| 946 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | + $pos_courante = $pos_apres ; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // |
|
| 951 | + // 2. Récuperer la partie alternative apres |
|
| 952 | + // |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | + if ( |
|
| 956 | + $pos_altern !== false |
|
| 957 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | + ) { |
|
| 959 | + $boucle['pos_altern'] = $pos_altern; |
|
| 960 | + $pos_altern += strlen($altern_boucle); |
|
| 961 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | + $pos_courante = $pos_altern; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + // |
|
| 966 | + // 3. Recuperer la partie footer non alternative |
|
| 967 | + // |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | + if ( |
|
| 971 | + $pos_postaff !== false |
|
| 972 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | + ) { |
|
| 974 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | + $pos_postaff += strlen($postaff_boucle); |
|
| 976 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | + $pos_courante = $pos_postaff ; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + return $boucle; |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -987,21 +987,21 @@ discard block |
||
| 987 | 987 | * @param null|object $boucle |
| 988 | 988 | */ |
| 989 | 989 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 990 | - static $boucles_connues = []; |
|
| 991 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | - } |
|
| 995 | - else { |
|
| 996 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | - $placeholder = $champ->nom_champ; |
|
| 998 | - $id = reset($champ->param[0][1]); |
|
| 999 | - $id = $id->texte; |
|
| 1000 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 990 | + static $boucles_connues = []; |
|
| 991 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | + } |
|
| 995 | + else { |
|
| 996 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | + $placeholder = $champ->nom_champ; |
|
| 998 | + $id = reset($champ->param[0][1]); |
|
| 999 | + $id = $id->texte; |
|
| 1000 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1014,274 +1014,274 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | - //memoriser la boucle a reinjecter |
|
| 1019 | - $id_boucle = "$id_boucle"; |
|
| 1020 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | - return $placeholder; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | + //memoriser la boucle a reinjecter |
|
| 1019 | + $id_boucle = "$id_boucle"; |
|
| 1020 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | + return $placeholder; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1025 | 1025 | |
| 1026 | - $all_res = []; |
|
| 1027 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | - if (is_null($boucle_placeholder)) { |
|
| 1029 | - do { |
|
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | - $pos_debut_texte = 0; |
|
| 1036 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | - $result = new Boucle(); |
|
| 1039 | - $result->id_parent = $id_parent; |
|
| 1040 | - $result->descr = $descr; |
|
| 1041 | - |
|
| 1042 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | - $pos_parent = $boucle['pos_parent']; |
|
| 1044 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | - |
|
| 1046 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | - |
|
| 1048 | - // boucle anonyme ? |
|
| 1049 | - if (!strlen($id_boucle)) { |
|
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $pos_debut_boucle = $pos_courante; |
|
| 1054 | - |
|
| 1055 | - $pos_milieu = $pos_parent; |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | - if ($boucle['pos_precond'] !== false) { |
|
| 1059 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | - |
|
| 1061 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | - $end_preaff = $pos_debut_boucle; |
|
| 1069 | - |
|
| 1070 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - $result->id_boucle = $id_boucle; |
|
| 1076 | - |
|
| 1077 | - if ( |
|
| 1078 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1080 | - or $pos_match > $pos_milieu |
|
| 1081 | - ) { |
|
| 1082 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | - erreur_squelette($err_b, $result); |
|
| 1084 | - |
|
| 1085 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | - continue; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $result->type_requete = $match[0]; |
|
| 1091 | - $pos_milieu += strlen($match[0]); |
|
| 1092 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | - |
|
| 1094 | - $type = $match[1]; |
|
| 1095 | - $jointures = trim($match[2]); |
|
| 1096 | - $table_optionnelle = ($match[3]); |
|
| 1097 | - if ($jointures) { |
|
| 1098 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | - // ou elles seront completees des jointures declarees |
|
| 1100 | - $result->jointures_explicites = $jointures; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - if ($table_optionnelle) { |
|
| 1104 | - $result->table_optionnelle = $type; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | - // Resultat mis dans result->param |
|
| 1109 | - $pos_fin_criteres = $pos_milieu; |
|
| 1110 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | - |
|
| 1112 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | - // pour l'instant on met le source (chaine) : |
|
| 1114 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | - $pos_milieu = $pos_fin_criteres; |
|
| 1118 | - |
|
| 1119 | - // |
|
| 1120 | - // Recuperer la fin : |
|
| 1121 | - // |
|
| 1122 | - if ($texte[$pos_milieu] === '/') { |
|
| 1123 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | - $pos_courante += 2; |
|
| 1125 | - $result->milieu = ''; |
|
| 1126 | - } else { |
|
| 1127 | - $pos_milieu += 1; |
|
| 1128 | - |
|
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | - if ($pos_fin === false) { |
|
| 1132 | - $err_b = [ |
|
| 1133 | - 'zbug_erreur_boucle_fermant', |
|
| 1134 | - ['id' => $id_boucle] |
|
| 1135 | - ]; |
|
| 1136 | - erreur_squelette($err_b, $result); |
|
| 1137 | - $pos_courante += strlen($fin_boucle); |
|
| 1138 | - } |
|
| 1139 | - else { |
|
| 1140 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | - $search_from = $pos_milieu; |
|
| 1144 | - $nb_open = 1; |
|
| 1145 | - $nb_close = 1; |
|
| 1146 | - $maxiter = 0; |
|
| 1147 | - do { |
|
| 1148 | - while ( |
|
| 1149 | - $nb_close < $nb_open |
|
| 1150 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | - ) { |
|
| 1152 | - $nb_close++; |
|
| 1153 | - $pos_fin = $p; |
|
| 1154 | - } |
|
| 1155 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | - if ($nb_close < $nb_open) { |
|
| 1157 | - break; |
|
| 1158 | - } |
|
| 1159 | - while ( |
|
| 1160 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | - and $p < $pos_fin |
|
| 1162 | - ) { |
|
| 1163 | - $nb_open++; |
|
| 1164 | - $search_from = $p + 1; |
|
| 1165 | - } |
|
| 1166 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | - |
|
| 1168 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | - } |
|
| 1170 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | - |
|
| 1176 | - // |
|
| 1177 | - // 1. Partie conditionnelle apres ? |
|
| 1178 | - // |
|
| 1179 | - if ($boucle['pos_postcond']) { |
|
| 1180 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - // |
|
| 1187 | - // 2. Partie alternative apres ? |
|
| 1188 | - // |
|
| 1189 | - $ligne_altern = $ligne_suite; |
|
| 1190 | - if ($boucle['pos_altern']) { |
|
| 1191 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // |
|
| 1197 | - // 3. Partie footer non alternative ? |
|
| 1198 | - // |
|
| 1199 | - $ligne_postaff = $ligne_suite; |
|
| 1200 | - if ($boucle['pos_postaff']) { |
|
| 1201 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $result->ligne = $ligne_preaff; |
|
| 1207 | - |
|
| 1208 | - if ($p = strpos($type, ':')) { |
|
| 1209 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | - $type = substr($type, $p + 1); |
|
| 1211 | - } |
|
| 1212 | - $soustype = strtolower($type); |
|
| 1213 | - |
|
| 1214 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | - $soustype = $type; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $result->type_requete = $soustype; |
|
| 1219 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | - if (!is_array($result->param)) { |
|
| 1221 | - $err_b = true; |
|
| 1222 | - } else { |
|
| 1223 | - phraser_criteres($result->param, $result); |
|
| 1224 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | - $args = $result->param; |
|
| 1227 | - array_unshift( |
|
| 1228 | - $args, |
|
| 1229 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | - ); |
|
| 1231 | - $result->param = $args; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | - if (empty($boucles[$id_boucle])) { |
|
| 1241 | - $boucles[$id_boucle] = null; |
|
| 1242 | - } |
|
| 1243 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | - |
|
| 1249 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | - if ($err_b) { |
|
| 1251 | - $result->type_requete = false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // Verifier qu'il n'y a pas double definition |
|
| 1255 | - // apres analyse des sous-parties (pas avant). |
|
| 1256 | - if (!empty($boucles[$id_boucle])) { |
|
| 1257 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | - $err_b_d = [ |
|
| 1259 | - 'zbug_erreur_boucle_double', |
|
| 1260 | - ['id' => $id_boucle] |
|
| 1261 | - ]; |
|
| 1262 | - erreur_squelette($err_b_d, $result); |
|
| 1263 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | - } |
|
| 1266 | - } else { |
|
| 1267 | - $boucles[$id_boucle] = $result; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | - |
|
| 1276 | - // phraser la partie avant le debut de la boucle |
|
| 1277 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | - |
|
| 1280 | - $ligne_debut_texte = $ligne_suite; |
|
| 1281 | - $pos_debut_texte = $pos_courante; |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | - |
|
| 1286 | - return $all_res; |
|
| 1026 | + $all_res = []; |
|
| 1027 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | + if (is_null($boucle_placeholder)) { |
|
| 1029 | + do { |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | + $pos_debut_texte = 0; |
|
| 1036 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | + $result = new Boucle(); |
|
| 1039 | + $result->id_parent = $id_parent; |
|
| 1040 | + $result->descr = $descr; |
|
| 1041 | + |
|
| 1042 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | + $pos_parent = $boucle['pos_parent']; |
|
| 1044 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | + |
|
| 1046 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | + |
|
| 1048 | + // boucle anonyme ? |
|
| 1049 | + if (!strlen($id_boucle)) { |
|
| 1050 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $pos_debut_boucle = $pos_courante; |
|
| 1054 | + |
|
| 1055 | + $pos_milieu = $pos_parent; |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | + if ($boucle['pos_precond'] !== false) { |
|
| 1059 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | + |
|
| 1061 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | + $end_preaff = $pos_debut_boucle; |
|
| 1069 | + |
|
| 1070 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + $result->id_boucle = $id_boucle; |
|
| 1076 | + |
|
| 1077 | + if ( |
|
| 1078 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1080 | + or $pos_match > $pos_milieu |
|
| 1081 | + ) { |
|
| 1082 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | + erreur_squelette($err_b, $result); |
|
| 1084 | + |
|
| 1085 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | + continue; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $result->type_requete = $match[0]; |
|
| 1091 | + $pos_milieu += strlen($match[0]); |
|
| 1092 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | + |
|
| 1094 | + $type = $match[1]; |
|
| 1095 | + $jointures = trim($match[2]); |
|
| 1096 | + $table_optionnelle = ($match[3]); |
|
| 1097 | + if ($jointures) { |
|
| 1098 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | + // ou elles seront completees des jointures declarees |
|
| 1100 | + $result->jointures_explicites = $jointures; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + if ($table_optionnelle) { |
|
| 1104 | + $result->table_optionnelle = $type; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | + // Resultat mis dans result->param |
|
| 1109 | + $pos_fin_criteres = $pos_milieu; |
|
| 1110 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | + |
|
| 1112 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | + // pour l'instant on met le source (chaine) : |
|
| 1114 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | + $pos_milieu = $pos_fin_criteres; |
|
| 1118 | + |
|
| 1119 | + // |
|
| 1120 | + // Recuperer la fin : |
|
| 1121 | + // |
|
| 1122 | + if ($texte[$pos_milieu] === '/') { |
|
| 1123 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | + $pos_courante += 2; |
|
| 1125 | + $result->milieu = ''; |
|
| 1126 | + } else { |
|
| 1127 | + $pos_milieu += 1; |
|
| 1128 | + |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | + if ($pos_fin === false) { |
|
| 1132 | + $err_b = [ |
|
| 1133 | + 'zbug_erreur_boucle_fermant', |
|
| 1134 | + ['id' => $id_boucle] |
|
| 1135 | + ]; |
|
| 1136 | + erreur_squelette($err_b, $result); |
|
| 1137 | + $pos_courante += strlen($fin_boucle); |
|
| 1138 | + } |
|
| 1139 | + else { |
|
| 1140 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | + $search_from = $pos_milieu; |
|
| 1144 | + $nb_open = 1; |
|
| 1145 | + $nb_close = 1; |
|
| 1146 | + $maxiter = 0; |
|
| 1147 | + do { |
|
| 1148 | + while ( |
|
| 1149 | + $nb_close < $nb_open |
|
| 1150 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | + ) { |
|
| 1152 | + $nb_close++; |
|
| 1153 | + $pos_fin = $p; |
|
| 1154 | + } |
|
| 1155 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | + if ($nb_close < $nb_open) { |
|
| 1157 | + break; |
|
| 1158 | + } |
|
| 1159 | + while ( |
|
| 1160 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | + and $p < $pos_fin |
|
| 1162 | + ) { |
|
| 1163 | + $nb_open++; |
|
| 1164 | + $search_from = $p + 1; |
|
| 1165 | + } |
|
| 1166 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | + |
|
| 1168 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | + } |
|
| 1170 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | + |
|
| 1176 | + // |
|
| 1177 | + // 1. Partie conditionnelle apres ? |
|
| 1178 | + // |
|
| 1179 | + if ($boucle['pos_postcond']) { |
|
| 1180 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + // |
|
| 1187 | + // 2. Partie alternative apres ? |
|
| 1188 | + // |
|
| 1189 | + $ligne_altern = $ligne_suite; |
|
| 1190 | + if ($boucle['pos_altern']) { |
|
| 1191 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // |
|
| 1197 | + // 3. Partie footer non alternative ? |
|
| 1198 | + // |
|
| 1199 | + $ligne_postaff = $ligne_suite; |
|
| 1200 | + if ($boucle['pos_postaff']) { |
|
| 1201 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $result->ligne = $ligne_preaff; |
|
| 1207 | + |
|
| 1208 | + if ($p = strpos($type, ':')) { |
|
| 1209 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | + $type = substr($type, $p + 1); |
|
| 1211 | + } |
|
| 1212 | + $soustype = strtolower($type); |
|
| 1213 | + |
|
| 1214 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | + $soustype = $type; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $result->type_requete = $soustype; |
|
| 1219 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | + if (!is_array($result->param)) { |
|
| 1221 | + $err_b = true; |
|
| 1222 | + } else { |
|
| 1223 | + phraser_criteres($result->param, $result); |
|
| 1224 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | + $args = $result->param; |
|
| 1227 | + array_unshift( |
|
| 1228 | + $args, |
|
| 1229 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | + ); |
|
| 1231 | + $result->param = $args; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | + if (empty($boucles[$id_boucle])) { |
|
| 1241 | + $boucles[$id_boucle] = null; |
|
| 1242 | + } |
|
| 1243 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | + |
|
| 1249 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | + if ($err_b) { |
|
| 1251 | + $result->type_requete = false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // Verifier qu'il n'y a pas double definition |
|
| 1255 | + // apres analyse des sous-parties (pas avant). |
|
| 1256 | + if (!empty($boucles[$id_boucle])) { |
|
| 1257 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | + $err_b_d = [ |
|
| 1259 | + 'zbug_erreur_boucle_double', |
|
| 1260 | + ['id' => $id_boucle] |
|
| 1261 | + ]; |
|
| 1262 | + erreur_squelette($err_b_d, $result); |
|
| 1263 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | + } |
|
| 1266 | + } else { |
|
| 1267 | + $boucles[$id_boucle] = $result; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | + |
|
| 1276 | + // phraser la partie avant le debut de la boucle |
|
| 1277 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | + |
|
| 1280 | + $ligne_debut_texte = $ligne_suite; |
|
| 1281 | + $pos_debut_texte = $pos_courante; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | + |
|
| 1286 | + return $all_res; |
|
| 1287 | 1287 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', string $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - [$skel, $mime_type, $gram, $sourcefile] = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | - // (recursion possible a cause des modeles) |
|
| 62 | - if ($debug) { |
|
| 63 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // charger le squelette en specifiant les langages cibles et source |
|
| 68 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | - |
|
| 70 | - if (!$composer) { |
|
| 71 | - $composer = charger_fonction('composer', 'public'); |
|
| 72 | - } |
|
| 73 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | - } else { |
|
| 75 | - $fonc = ''; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | - $page = $fonc; |
|
| 80 | - } else { |
|
| 81 | - // Preparer l'appel de la fonction principale du squelette |
|
| 82 | - |
|
| 83 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 84 | - |
|
| 85 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | - // et on enregistre l'etat courant des globales de notes... |
|
| 87 | - if (is_null($notes)) { |
|
| 88 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | - } |
|
| 90 | - if ($notes) { |
|
| 91 | - $notes('', 'empiler'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Rajouter d'office ces deux parametres |
|
| 95 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | - if (!isset($contexte['date'])) { |
|
| 98 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | - $contexte['date_default'] = true; |
|
| 100 | - } else { |
|
| 101 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!isset($contexte['date_redac'])) { |
|
| 105 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | - $contexte['date_redac_default'] = true; |
|
| 107 | - } else { |
|
| 108 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | - try { |
|
| 113 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | - } catch (Throwable $e) { |
|
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | - $corps = "<pre>$msg</pre>"; |
|
| 119 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | - erreur_squelette($full_msg); |
|
| 121 | - unset($msg, $full_msg, $corps); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | - if ($notes) { |
|
| 130 | - $notes('', 'depiler'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // reinjecter en dynamique la pile des notes |
|
| 134 | - // si il y a des inclure dynamiques |
|
| 135 | - // si la pile n'est pas vide |
|
| 136 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | - if ($notes) { |
|
| 139 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // spip_log: un joli contexte |
|
| 143 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | - |
|
| 145 | - $profile = spip_timer($a); |
|
| 146 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | - |
|
| 149 | - if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ($debug) { |
|
| 155 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | - if ( |
|
| 161 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + [$skel, $mime_type, $gram, $sourcefile] = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | + // (recursion possible a cause des modeles) |
|
| 62 | + if ($debug) { |
|
| 63 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // charger le squelette en specifiant les langages cibles et source |
|
| 68 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | + |
|
| 70 | + if (!$composer) { |
|
| 71 | + $composer = charger_fonction('composer', 'public'); |
|
| 72 | + } |
|
| 73 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | + } else { |
|
| 75 | + $fonc = ''; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | + $page = $fonc; |
|
| 80 | + } else { |
|
| 81 | + // Preparer l'appel de la fonction principale du squelette |
|
| 82 | + |
|
| 83 | + spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 84 | + |
|
| 85 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | + // et on enregistre l'etat courant des globales de notes... |
|
| 87 | + if (is_null($notes)) { |
|
| 88 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | + } |
|
| 90 | + if ($notes) { |
|
| 91 | + $notes('', 'empiler'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Rajouter d'office ces deux parametres |
|
| 95 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | + if (!isset($contexte['date'])) { |
|
| 98 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | + $contexte['date_default'] = true; |
|
| 100 | + } else { |
|
| 101 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!isset($contexte['date_redac'])) { |
|
| 105 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | + $contexte['date_redac_default'] = true; |
|
| 107 | + } else { |
|
| 108 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | + try { |
|
| 113 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | + } catch (Throwable $e) { |
|
| 115 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | + $corps = "<pre>$msg</pre>"; |
|
| 119 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | + erreur_squelette($full_msg); |
|
| 121 | + unset($msg, $full_msg, $corps); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | + if ($notes) { |
|
| 130 | + $notes('', 'depiler'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // reinjecter en dynamique la pile des notes |
|
| 134 | + // si il y a des inclure dynamiques |
|
| 135 | + // si la pile n'est pas vide |
|
| 136 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | + if ($notes) { |
|
| 139 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // spip_log: un joli contexte |
|
| 143 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | + |
|
| 145 | + $profile = spip_timer($a); |
|
| 146 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + |
|
| 149 | + if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ($debug) { |
|
| 155 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | + if ( |
|
| 161 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,37 +210,37 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = []; |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if ($val === null) { |
|
| 222 | - $val = ''; |
|
| 223 | - } elseif (is_array($val)) { |
|
| 224 | - if ($profondeur_max > 0) { |
|
| 225 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 226 | - } else { |
|
| 227 | - $val = 'array:' . count($val); |
|
| 228 | - } |
|
| 229 | - } elseif (is_object($val)) { |
|
| 230 | - $val = get_class($val); |
|
| 231 | - } elseif (strlen("$val") > 30) { |
|
| 232 | - $val = substr("$val", 0, 29) . '…'; |
|
| 233 | - if (strstr($val, ' ')) { |
|
| 234 | - $val = "'$val'"; |
|
| 235 | - } |
|
| 236 | - } elseif (strstr($val, ' ')) { |
|
| 237 | - $val = "'$val'"; |
|
| 238 | - } elseif (!strlen($val)) { |
|
| 239 | - $val = "''"; |
|
| 240 | - } |
|
| 241 | - $infos[] = $var . '=' . $val; |
|
| 242 | - } |
|
| 243 | - return join(', ', $infos); |
|
| 213 | + $infos = []; |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if ($val === null) { |
|
| 222 | + $val = ''; |
|
| 223 | + } elseif (is_array($val)) { |
|
| 224 | + if ($profondeur_max > 0) { |
|
| 225 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 226 | + } else { |
|
| 227 | + $val = 'array:' . count($val); |
|
| 228 | + } |
|
| 229 | + } elseif (is_object($val)) { |
|
| 230 | + $val = get_class($val); |
|
| 231 | + } elseif (strlen("$val") > 30) { |
|
| 232 | + $val = substr("$val", 0, 29) . '…'; |
|
| 233 | + if (strstr($val, ' ')) { |
|
| 234 | + $val = "'$val'"; |
|
| 235 | + } |
|
| 236 | + } elseif (strstr($val, ' ')) { |
|
| 237 | + $val = "'$val'"; |
|
| 238 | + } elseif (!strlen($val)) { |
|
| 239 | + $val = "''"; |
|
| 240 | + } |
|
| 241 | + $infos[] = $var . '=' . $val; |
|
| 242 | + } |
|
| 243 | + return join(', ', $infos); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function tester_redirection($fond, $contexte, $connect) { |
| 260 | - static $tester_redirection = null; |
|
| 261 | - if (is_null($tester_redirection)) { |
|
| 262 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 263 | - } |
|
| 264 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 260 | + static $tester_redirection = null; |
|
| 261 | + if (is_null($tester_redirection)) { |
|
| 262 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 263 | + } |
|
| 264 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -277,42 +277,42 @@ discard block |
||
| 277 | 277 | * @return array|bool |
| 278 | 278 | */ |
| 279 | 279 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 280 | - if ( |
|
| 281 | - $fond == 'article' |
|
| 282 | - and !empty($contexte['id_article']) |
|
| 283 | - and $id_article = intval($contexte['id_article']) |
|
| 284 | - ) { |
|
| 285 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 286 | - $m = quete_virtuel($id_article, $connect); |
|
| 287 | - if (strlen($m)) { |
|
| 288 | - include_spip('inc/texte'); |
|
| 289 | - // les navigateurs pataugent si l'URL est vide |
|
| 290 | - if ($url = virtuel_redirige($m, true)) { |
|
| 291 | - // passer en url absolue car cette redirection pourra |
|
| 292 | - // etre utilisee dans un contexte d'url qui change |
|
| 293 | - // y compris url arbo |
|
| 294 | - $status = 302; |
|
| 295 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 296 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 297 | - } |
|
| 298 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 299 | - include_spip('inc/filtres_mini'); |
|
| 300 | - $url = url_absolue($url); |
|
| 301 | - } |
|
| 302 | - $url = str_replace('&', '&', $url); |
|
| 303 | - |
|
| 304 | - return [ |
|
| 305 | - 'texte' => '<' |
|
| 306 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 307 | - . texte_script($url) |
|
| 308 | - . "','',$status);" |
|
| 309 | - . '?' . '>', |
|
| 310 | - 'process_ins' => 'php', |
|
| 311 | - 'status' => $status |
|
| 312 | - ]; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return false; |
|
| 280 | + if ( |
|
| 281 | + $fond == 'article' |
|
| 282 | + and !empty($contexte['id_article']) |
|
| 283 | + and $id_article = intval($contexte['id_article']) |
|
| 284 | + ) { |
|
| 285 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 286 | + $m = quete_virtuel($id_article, $connect); |
|
| 287 | + if (strlen($m)) { |
|
| 288 | + include_spip('inc/texte'); |
|
| 289 | + // les navigateurs pataugent si l'URL est vide |
|
| 290 | + if ($url = virtuel_redirige($m, true)) { |
|
| 291 | + // passer en url absolue car cette redirection pourra |
|
| 292 | + // etre utilisee dans un contexte d'url qui change |
|
| 293 | + // y compris url arbo |
|
| 294 | + $status = 302; |
|
| 295 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 296 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 297 | + } |
|
| 298 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 299 | + include_spip('inc/filtres_mini'); |
|
| 300 | + $url = url_absolue($url); |
|
| 301 | + } |
|
| 302 | + $url = str_replace('&', '&', $url); |
|
| 303 | + |
|
| 304 | + return [ |
|
| 305 | + 'texte' => '<' |
|
| 306 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 307 | + . texte_script($url) |
|
| 308 | + . "','',$status);" |
|
| 309 | + . '?' . '>', |
|
| 310 | + 'process_ins' => 'php', |
|
| 311 | + 'status' => $status |
|
| 312 | + ]; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return false; |
|
| 318 | 318 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,77 +237,77 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - if ($excep) { |
|
| 258 | - $joker = false; // indiquer a l'appelant |
|
| 259 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | - } // pas d'alias. Le champ existe t'il ? |
|
| 261 | - else { |
|
| 262 | - // le champ est réellement présent, on le prend. |
|
| 263 | - if (isset($desc['field'][$nom_champ])) { |
|
| 264 | - $t = $boucles[$idb]->id_table; |
|
| 265 | - $joker = false; // indiquer a l'appelant |
|
| 266 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | - } |
|
| 268 | - // Tous les champs sont-ils acceptés ? |
|
| 269 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | - elseif ( |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + if ($excep) { |
|
| 258 | + $joker = false; // indiquer a l'appelant |
|
| 259 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 260 | + } // pas d'alias. Le champ existe t'il ? |
|
| 261 | + else { |
|
| 262 | + // le champ est réellement présent, on le prend. |
|
| 263 | + if (isset($desc['field'][$nom_champ])) { |
|
| 264 | + $t = $boucles[$idb]->id_table; |
|
| 265 | + $joker = false; // indiquer a l'appelant |
|
| 266 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 267 | + } |
|
| 268 | + // Tous les champs sont-ils acceptés ? |
|
| 269 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 270 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 271 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 272 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 273 | + elseif ( |
|
| 274 | 274 | /*$joker AND */ |
| 275 | - isset($desc['field']['*']) |
|
| 276 | - ) { |
|
| 277 | - $joker = true; // indiquer a l'appelant |
|
| 278 | - return [$nom_champ, $nom_champ]; |
|
| 279 | - } |
|
| 280 | - // pas d'alias, pas de champ, pas de joker... |
|
| 281 | - // tenter via une jointure... |
|
| 282 | - else { |
|
| 283 | - $joker = false; // indiquer a l'appelant |
|
| 284 | - // regarder si le champ est deja dans une jointure existante |
|
| 285 | - // sinon, si il y a des joitures explicites, la construire |
|
| 286 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | - // mais est-ce ce qu'on veut ? |
|
| 291 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($t) { |
|
| 298 | - // si on a trouvé une jointure possible, on fait comme |
|
| 299 | - // si c'était une exception pour le champ demandé |
|
| 300 | - return index_exception( |
|
| 301 | - $boucles[$idb], |
|
| 302 | - $desc, |
|
| 303 | - $nom_champ, |
|
| 304 | - [$t[1]['id_table'], reset($t[2])] |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return ['', '']; |
|
| 309 | - } |
|
| 310 | - } |
|
| 275 | + isset($desc['field']['*']) |
|
| 276 | + ) { |
|
| 277 | + $joker = true; // indiquer a l'appelant |
|
| 278 | + return [$nom_champ, $nom_champ]; |
|
| 279 | + } |
|
| 280 | + // pas d'alias, pas de champ, pas de joker... |
|
| 281 | + // tenter via une jointure... |
|
| 282 | + else { |
|
| 283 | + $joker = false; // indiquer a l'appelant |
|
| 284 | + // regarder si le champ est deja dans une jointure existante |
|
| 285 | + // sinon, si il y a des joitures explicites, la construire |
|
| 286 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 287 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 288 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 289 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 290 | + // mais est-ce ce qu'on veut ? |
|
| 291 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 292 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 293 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($t) { |
|
| 298 | + // si on a trouvé une jointure possible, on fait comme |
|
| 299 | + // si c'était une exception pour le champ demandé |
|
| 300 | + return index_exception( |
|
| 301 | + $boucles[$idb], |
|
| 302 | + $desc, |
|
| 303 | + $nom_champ, |
|
| 304 | + [$t[1]['id_table'], reset($t[2])] |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return ['', '']; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -335,52 +335,52 @@ discard block |
||
| 335 | 335 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 336 | 336 | **/ |
| 337 | 337 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 338 | - static $trouver_table; |
|
| 339 | - if (!$trouver_table) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - if (is_array($excep)) { |
|
| 344 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | - $t = null; |
|
| 346 | - if (count($excep) == 3) { |
|
| 347 | - $index_exception_derogatoire = array_pop($excep); |
|
| 348 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | - } |
|
| 350 | - if ($t == null) { |
|
| 351 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | - if (!$j) { |
|
| 355 | - return ['', '']; |
|
| 356 | - } |
|
| 357 | - $e = $j['table']; |
|
| 358 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | - $k = $j['key']['PRIMARY KEY']; |
|
| 360 | - if (strpos($k, ',')) { |
|
| 361 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | - if (!in_array($k, $l)) { |
|
| 364 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | - |
|
| 366 | - return ['', '']; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | - fabrique_jointures($boucle, [$k]); |
|
| 371 | - $t = array_search($e, $boucle->from); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } else { |
|
| 375 | - $t = $boucle->id_table; |
|
| 376 | - } |
|
| 377 | - // demander a SQL de gerer le synonyme |
|
| 378 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | - if ($excep != $nom_champ) { |
|
| 380 | - $excep .= ' AS ' . $nom_champ; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return ["$t.$excep", $nom_champ]; |
|
| 338 | + static $trouver_table; |
|
| 339 | + if (!$trouver_table) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + if (is_array($excep)) { |
|
| 344 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 345 | + $t = null; |
|
| 346 | + if (count($excep) == 3) { |
|
| 347 | + $index_exception_derogatoire = array_pop($excep); |
|
| 348 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 349 | + } |
|
| 350 | + if ($t == null) { |
|
| 351 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 352 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 353 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 354 | + if (!$j) { |
|
| 355 | + return ['', '']; |
|
| 356 | + } |
|
| 357 | + $e = $j['table']; |
|
| 358 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 359 | + $k = $j['key']['PRIMARY KEY']; |
|
| 360 | + if (strpos($k, ',')) { |
|
| 361 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 362 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 363 | + if (!in_array($k, $l)) { |
|
| 364 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 365 | + |
|
| 366 | + return ['', '']; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 370 | + fabrique_jointures($boucle, [$k]); |
|
| 371 | + $t = array_search($e, $boucle->from); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } else { |
|
| 375 | + $t = $boucle->id_table; |
|
| 376 | + } |
|
| 377 | + // demander a SQL de gerer le synonyme |
|
| 378 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 379 | + if ($excep != $nom_champ) { |
|
| 380 | + $excep .= ' AS ' . $nom_champ; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return ["$t.$excep", $nom_champ]; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | * Code PHP pour retrouver le champ |
| 406 | 406 | */ |
| 407 | 407 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 408 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 408 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -425,9 +425,9 @@ discard block |
||
| 425 | 425 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 426 | 426 | **/ |
| 427 | 427 | function calculer_champ($p) { |
| 428 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 428 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 429 | 429 | |
| 430 | - return applique_filtres($p); |
|
| 430 | + return applique_filtres($p); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_balise($nom, $p) { |
| 466 | 466 | |
| 467 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | - $p->balise_calculee = true; |
|
| 470 | - $res = $f($p); |
|
| 471 | - if ($res !== null and is_object($res)) { |
|
| 472 | - return $res; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // Certaines des balises comportant un _ sont generiques |
|
| 477 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | - $res = $balise_generique['fonction_generique']($p); |
|
| 479 | - if ($res !== null and is_object($res)) { |
|
| 480 | - return $res; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | - |
|
| 486 | - return $f($nom, $p); |
|
| 467 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 468 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 469 | + $p->balise_calculee = true; |
|
| 470 | + $res = $f($p); |
|
| 471 | + if ($res !== null and is_object($res)) { |
|
| 472 | + return $res; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // Certaines des balises comportant un _ sont generiques |
|
| 477 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 478 | + $res = $balise_generique['fonction_generique']($p); |
|
| 479 | + if ($res !== null and is_object($res)) { |
|
| 480 | + return $res; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 485 | + |
|
| 486 | + return $f($nom, $p); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -511,37 +511,37 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 513 | 513 | |
| 514 | - // ca pourrait etre un champ SQL homonyme, |
|
| 515 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | - |
|
| 517 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | - $code = addslashes($p->fonctions[0][1]); |
|
| 521 | - $p->code .= " . '$code'"; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | - if (strpos($nom, 'ID_') === 0) { |
|
| 526 | - $p->interdire_scripts = false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | - // SI le champ SQL n'est pas trouve |
|
| 531 | - // ET si la balise a une forme de couleur |
|
| 532 | - // ET s'il n'y a ni filtre ni etoile |
|
| 533 | - // ALORS retourner la couleur. |
|
| 534 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | - if ( |
|
| 536 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | - and !$p->etoile |
|
| 538 | - and !$p->fonctions |
|
| 539 | - ) { |
|
| 540 | - $p->code = "'#$nom'"; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return $p; |
|
| 514 | + // ca pourrait etre un champ SQL homonyme, |
|
| 515 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 516 | + |
|
| 517 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 518 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 519 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 520 | + $code = addslashes($p->fonctions[0][1]); |
|
| 521 | + $p->code .= " . '$code'"; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 525 | + if (strpos($nom, 'ID_') === 0) { |
|
| 526 | + $p->interdire_scripts = false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 530 | + // SI le champ SQL n'est pas trouve |
|
| 531 | + // ET si la balise a une forme de couleur |
|
| 532 | + // ET s'il n'y a ni filtre ni etoile |
|
| 533 | + // ALORS retourner la couleur. |
|
| 534 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 535 | + if ( |
|
| 536 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 537 | + and !$p->etoile |
|
| 538 | + and !$p->fonctions |
|
| 539 | + ) { |
|
| 540 | + $p->code = "'#$nom'"; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -584,39 +584,39 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 586 | 586 | |
| 587 | - if (!balise_distante_interdite($p)) { |
|
| 588 | - $p->code = "''"; |
|
| 589 | - |
|
| 590 | - return $p; |
|
| 591 | - } |
|
| 592 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | - $p->fonctions = null; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if ($p->param and ($c = $p->param[0])) { |
|
| 599 | - // liste d'arguments commence toujours par la chaine vide |
|
| 600 | - array_shift($c); |
|
| 601 | - // construire la liste d'arguments comme pour un filtre |
|
| 602 | - $param = compose_filtres_args($p, $c, ','); |
|
| 603 | - } else { |
|
| 604 | - $param = ''; |
|
| 605 | - } |
|
| 606 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | - |
|
| 608 | - $p->code = sprintf( |
|
| 609 | - CODE_EXECUTER_BALISE, |
|
| 610 | - $nom, |
|
| 611 | - join(',', $collecte), |
|
| 612 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | - memoriser_contexte_compil($p), |
|
| 614 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | - ); |
|
| 616 | - |
|
| 617 | - $p->interdire_scripts = false; |
|
| 618 | - |
|
| 619 | - return $p; |
|
| 587 | + if (!balise_distante_interdite($p)) { |
|
| 588 | + $p->code = "''"; |
|
| 589 | + |
|
| 590 | + return $p; |
|
| 591 | + } |
|
| 592 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 593 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 594 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 595 | + $p->fonctions = null; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if ($p->param and ($c = $p->param[0])) { |
|
| 599 | + // liste d'arguments commence toujours par la chaine vide |
|
| 600 | + array_shift($c); |
|
| 601 | + // construire la liste d'arguments comme pour un filtre |
|
| 602 | + $param = compose_filtres_args($p, $c, ','); |
|
| 603 | + } else { |
|
| 604 | + $param = ''; |
|
| 605 | + } |
|
| 606 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 607 | + |
|
| 608 | + $p->code = sprintf( |
|
| 609 | + CODE_EXECUTER_BALISE, |
|
| 610 | + $nom, |
|
| 611 | + join(',', $collecte), |
|
| 612 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 613 | + memoriser_contexte_compil($p), |
|
| 614 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 615 | + ); |
|
| 616 | + |
|
| 617 | + $p->interdire_scripts = false; |
|
| 618 | + |
|
| 619 | + return $p; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | |
@@ -646,13 +646,13 @@ discard block |
||
| 646 | 646 | * Liste des codes PHP d'éxecution des balises collectées |
| 647 | 647 | **/ |
| 648 | 648 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 649 | - $args = []; |
|
| 650 | - foreach ($l as $c) { |
|
| 651 | - $x = calculer_balise($c, $p); |
|
| 652 | - $args[] = $x->code; |
|
| 653 | - } |
|
| 649 | + $args = []; |
|
| 650 | + foreach ($l as $c) { |
|
| 651 | + $x = calculer_balise($c, $p); |
|
| 652 | + $args[] = $x->code; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - return $args; |
|
| 655 | + return $args; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -667,22 +667,22 @@ discard block |
||
| 667 | 667 | * Nom de la connexion |
| 668 | 668 | **/ |
| 669 | 669 | function trouver_nom_serveur_distant($p) { |
| 670 | - $nom = $p->id_boucle; |
|
| 671 | - if ( |
|
| 672 | - $nom |
|
| 673 | - and isset($p->boucles[$nom]) |
|
| 674 | - ) { |
|
| 675 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 676 | - if ( |
|
| 677 | - strlen($s) |
|
| 678 | - and strlen($serveur = strtolower($s)) |
|
| 679 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 680 | - ) { |
|
| 681 | - return $serveur; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return ''; |
|
| 670 | + $nom = $p->id_boucle; |
|
| 671 | + if ( |
|
| 672 | + $nom |
|
| 673 | + and isset($p->boucles[$nom]) |
|
| 674 | + ) { |
|
| 675 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 676 | + if ( |
|
| 677 | + strlen($s) |
|
| 678 | + and strlen($serveur = strtolower($s)) |
|
| 679 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 680 | + ) { |
|
| 681 | + return $serveur; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return ''; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
@@ -706,15 +706,15 @@ discard block |
||
| 706 | 706 | * - false : La balise est interdite car le serveur est distant |
| 707 | 707 | **/ |
| 708 | 708 | function balise_distante_interdite($p) { |
| 709 | - $nom = $p->id_boucle; |
|
| 709 | + $nom = $p->id_boucle; |
|
| 710 | 710 | |
| 711 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 712 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 711 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 712 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 713 | 713 | |
| 714 | - return false; |
|
| 715 | - } |
|
| 714 | + return false; |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - return true; |
|
| 717 | + return true; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | |
@@ -725,84 +725,84 @@ discard block |
||
| 725 | 725 | // https://code.spip.net/@champs_traitements |
| 726 | 726 | function champs_traitements($p) { |
| 727 | 727 | |
| 728 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 729 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 730 | - } else { |
|
| 731 | - // quand on utilise un traitement catch-all * |
|
| 732 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 733 | - // leur propre securite |
|
| 734 | - if (!$p->balise_calculee) { |
|
| 735 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 736 | - } else { |
|
| 737 | - $ps = false; |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - if (is_array($ps)) { |
|
| 742 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 743 | - $idb = index_boucle($p); |
|
| 744 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 745 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 746 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 750 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 751 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 752 | - |
|
| 753 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 754 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 755 | - $type_alias = $type_requete; |
|
| 756 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 757 | - } else { |
|
| 758 | - $type_alias = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 762 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 763 | - $ps = $ps[$table_sql]; |
|
| 764 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 765 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 766 | - $ps = $ps[$type_requete]; |
|
| 767 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 768 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 769 | - $ps = $ps[$type_alias]; |
|
| 770 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 771 | - elseif (isset($ps[0])) { |
|
| 772 | - $ps = $ps[0]; |
|
| 773 | - } else { |
|
| 774 | - $ps = false; |
|
| 775 | - } |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - if (!$ps) { |
|
| 779 | - return $p->code; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 783 | - // ou si in INCLURE contient {doublons} |
|
| 784 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 785 | - // dans les filtres propre() ou typo() |
|
| 786 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 787 | - |
|
| 788 | - if ( |
|
| 789 | - isset($p->descr['documents']) |
|
| 790 | - and |
|
| 791 | - $p->descr['documents'] |
|
| 792 | - and ( |
|
| 793 | - (strpos($ps, 'propre') !== false) |
|
| 794 | - or |
|
| 795 | - (strpos($ps, 'typo') !== false) |
|
| 796 | - ) |
|
| 797 | - ) { |
|
| 798 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 802 | - // dans la declaration des traitements des champs sensibles |
|
| 803 | - |
|
| 804 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 805 | - return str_replace('%s', $p->code, $ps); |
|
| 728 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 729 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 730 | + } else { |
|
| 731 | + // quand on utilise un traitement catch-all * |
|
| 732 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 733 | + // leur propre securite |
|
| 734 | + if (!$p->balise_calculee) { |
|
| 735 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 736 | + } else { |
|
| 737 | + $ps = false; |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + if (is_array($ps)) { |
|
| 742 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 743 | + $idb = index_boucle($p); |
|
| 744 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 745 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 746 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 750 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 751 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 752 | + |
|
| 753 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 754 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 755 | + $type_alias = $type_requete; |
|
| 756 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 757 | + } else { |
|
| 758 | + $type_alias = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 762 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 763 | + $ps = $ps[$table_sql]; |
|
| 764 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 765 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 766 | + $ps = $ps[$type_requete]; |
|
| 767 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 768 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 769 | + $ps = $ps[$type_alias]; |
|
| 770 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 771 | + elseif (isset($ps[0])) { |
|
| 772 | + $ps = $ps[0]; |
|
| 773 | + } else { |
|
| 774 | + $ps = false; |
|
| 775 | + } |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + if (!$ps) { |
|
| 779 | + return $p->code; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 783 | + // ou si in INCLURE contient {doublons} |
|
| 784 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 785 | + // dans les filtres propre() ou typo() |
|
| 786 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 787 | + |
|
| 788 | + if ( |
|
| 789 | + isset($p->descr['documents']) |
|
| 790 | + and |
|
| 791 | + $p->descr['documents'] |
|
| 792 | + and ( |
|
| 793 | + (strpos($ps, 'propre') !== false) |
|
| 794 | + or |
|
| 795 | + (strpos($ps, 'typo') !== false) |
|
| 796 | + ) |
|
| 797 | + ) { |
|
| 798 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 802 | + // dans la declaration des traitements des champs sensibles |
|
| 803 | + |
|
| 804 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 805 | + return str_replace('%s', $p->code, $ps); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -815,112 +815,112 @@ discard block |
||
| 815 | 815 | // https://code.spip.net/@applique_filtres |
| 816 | 816 | function applique_filtres($p) { |
| 817 | 817 | |
| 818 | - // Traitements standards (cf. supra) |
|
| 819 | - if ($p->etoile == '') { |
|
| 820 | - $code = champs_traitements($p); |
|
| 821 | - } else { |
|
| 822 | - $code = $p->code; |
|
| 823 | - } |
|
| 818 | + // Traitements standards (cf. supra) |
|
| 819 | + if ($p->etoile == '') { |
|
| 820 | + $code = champs_traitements($p); |
|
| 821 | + } else { |
|
| 822 | + $code = $p->code; |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - // Appliquer les filtres perso |
|
| 826 | - if ($p->param) { |
|
| 827 | - $code = compose_filtres($p, $code); |
|
| 828 | - } |
|
| 825 | + // Appliquer les filtres perso |
|
| 826 | + if ($p->param) { |
|
| 827 | + $code = compose_filtres($p, $code); |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 831 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 832 | - if (isset($p->descr['session'])) { |
|
| 833 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 834 | - } |
|
| 830 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 831 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 832 | + if (isset($p->descr['session'])) { |
|
| 833 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 836 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 837 | 837 | |
| 838 | - return $code; |
|
| 838 | + return $code; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 842 | 842 | // https://code.spip.net/@compose_filtres |
| 843 | 843 | function compose_filtres(&$p, $code) { |
| 844 | 844 | |
| 845 | - $image_miette = false; |
|
| 846 | - foreach ($p->param as $filtre) { |
|
| 847 | - $fonc = array_shift($filtre); |
|
| 848 | - if (!$fonc) { |
|
| 849 | - continue; |
|
| 850 | - } // normalement qu'au premier tour. |
|
| 851 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 852 | - if ($image_miette and !$is_filtre_image) { |
|
| 853 | - // il faut graver maintenant car apres le filtre en cours |
|
| 854 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 855 | - $code = "filtrer('image_graver', $code)"; |
|
| 856 | - $image_miette = false; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - // recuperer les arguments du filtre, |
|
| 860 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 861 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 862 | - if ($fonc !== '?') { |
|
| 863 | - $sep = ','; |
|
| 864 | - } else { |
|
| 865 | - $sep = ':'; |
|
| 866 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 867 | - if ($countfiltre != 2) { |
|
| 868 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 869 | - $countfiltre = 2; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 873 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 874 | - if ($logique) { |
|
| 875 | - $code = $logique; |
|
| 876 | - } else { |
|
| 877 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 878 | - if ($is_filtre_image) { |
|
| 879 | - $image_miette = true; |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 884 | - if ($image_miette) { |
|
| 885 | - $code = "filtrer('image_graver',$code)"; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - return $code; |
|
| 845 | + $image_miette = false; |
|
| 846 | + foreach ($p->param as $filtre) { |
|
| 847 | + $fonc = array_shift($filtre); |
|
| 848 | + if (!$fonc) { |
|
| 849 | + continue; |
|
| 850 | + } // normalement qu'au premier tour. |
|
| 851 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 852 | + if ($image_miette and !$is_filtre_image) { |
|
| 853 | + // il faut graver maintenant car apres le filtre en cours |
|
| 854 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 855 | + $code = "filtrer('image_graver', $code)"; |
|
| 856 | + $image_miette = false; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + // recuperer les arguments du filtre, |
|
| 860 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 861 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 862 | + if ($fonc !== '?') { |
|
| 863 | + $sep = ','; |
|
| 864 | + } else { |
|
| 865 | + $sep = ':'; |
|
| 866 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 867 | + if ($countfiltre != 2) { |
|
| 868 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 869 | + $countfiltre = 2; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 873 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 874 | + if ($logique) { |
|
| 875 | + $code = $logique; |
|
| 876 | + } else { |
|
| 877 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 878 | + if ($is_filtre_image) { |
|
| 879 | + $image_miette = true; |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 884 | + if ($image_miette) { |
|
| 885 | + $code = "filtrer('image_graver',$code)"; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + return $code; |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 892 | 892 | // et comparateurs |
| 893 | 893 | function filtre_logique($fonc, $code, $arg) { |
| 894 | 894 | |
| 895 | - switch (true) { |
|
| 896 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 897 | - return "($code $fonc $arg)"; |
|
| 898 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 899 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 900 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 901 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 902 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 903 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 904 | - case ($fonc == 'sinon'): |
|
| 905 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 906 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 907 | - return "(($code) ?'' :' ')"; |
|
| 908 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 909 | - return "(($code) ?' ' :'')"; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - return ''; |
|
| 895 | + switch (true) { |
|
| 896 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 897 | + return "($code $fonc $arg)"; |
|
| 898 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 899 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 900 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 901 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 902 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 903 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 904 | + case ($fonc == 'sinon'): |
|
| 905 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 906 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 907 | + return "(($code) ?'' :' ')"; |
|
| 908 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 909 | + return "(($code) ?' ' :'')"; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + return ''; |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | // https://code.spip.net/@compose_filtres_args |
| 916 | 916 | function compose_filtres_args($p, $args, $sep) { |
| 917 | - $arglist = ''; |
|
| 918 | - foreach ($args as $arg) { |
|
| 919 | - $arglist .= $sep . |
|
| 920 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | - } |
|
| 917 | + $arglist = ''; |
|
| 918 | + foreach ($args as $arg) { |
|
| 919 | + $arglist .= $sep . |
|
| 920 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | - return $arglist; |
|
| 923 | + return $arglist; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -938,15 +938,15 @@ discard block |
||
| 938 | 938 | **/ |
| 939 | 939 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 940 | 940 | |
| 941 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | - if ($boucles[$idb]->externe) { |
|
| 943 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | - // on ignore le defaut fourni dans ce cas |
|
| 946 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | - } |
|
| 941 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 942 | + if ($boucles[$idb]->externe) { |
|
| 943 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 944 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 945 | + // on ignore le defaut fourni dans ce cas |
|
| 946 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 947 | + } |
|
| 948 | 948 | |
| 949 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 949 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | // |
@@ -961,30 +961,30 @@ discard block |
||
| 961 | 961 | |
| 962 | 962 | // https://code.spip.net/@rindex_pile |
| 963 | 963 | function rindex_pile($p, $champ, $motif) { |
| 964 | - $n = 0; |
|
| 965 | - $b = $p->id_boucle; |
|
| 966 | - $p->code = ''; |
|
| 967 | - while ($b != '') { |
|
| 968 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 969 | - if ($critere->op == $motif) { |
|
| 970 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 971 | - "]['$champ']"; |
|
| 972 | - $b = ''; |
|
| 973 | - break 2; |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - $n++; |
|
| 977 | - $b = $p->boucles[$b]->id_parent; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 981 | - if (!$p->code) { |
|
| 982 | - $p->code = "''"; |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - $p->interdire_scripts = false; |
|
| 986 | - |
|
| 987 | - return $p; |
|
| 964 | + $n = 0; |
|
| 965 | + $b = $p->id_boucle; |
|
| 966 | + $p->code = ''; |
|
| 967 | + while ($b != '') { |
|
| 968 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 969 | + if ($critere->op == $motif) { |
|
| 970 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 971 | + "]['$champ']"; |
|
| 972 | + $b = ''; |
|
| 973 | + break 2; |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + $n++; |
|
| 977 | + $b = $p->boucles[$b]->id_parent; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 981 | + if (!$p->code) { |
|
| 982 | + $p->code = "''"; |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + $p->interdire_scripts = false; |
|
| 986 | + |
|
| 987 | + return $p; |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 995 | 995 | */ |
| 996 | 996 | function zbug_presenter_champ($p, $champ = '') { |
| 997 | - $balise = $champ ?: $p->nom_champ; |
|
| 998 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 999 | - return "#{$explicite}{$balise}"; |
|
| 997 | + $balise = $champ ?: $p->nom_champ; |
|
| 998 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 999 | + return "#{$explicite}{$balise}"; |
|
| 1000 | 1000 | } |
@@ -11,190 +11,190 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // https://code.spip.net/@trace_query_start |
| 18 | 18 | function trace_query_start() { |
| 19 | - static $trace = '?'; |
|
| 20 | - if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 21 | - if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 22 | - $trace = true; |
|
| 23 | - } |
|
| 24 | - else { |
|
| 25 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 26 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 27 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 28 | - // ou une requete SQL faite avant chargement de la session |
|
| 29 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 30 | - } |
|
| 31 | - else { |
|
| 32 | - include_spip('inc/autoriser'); |
|
| 33 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 34 | - // A fortiori quand on demande une trace |
|
| 35 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 36 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return $trace ? microtime() : 0; |
|
| 19 | + static $trace = '?'; |
|
| 20 | + if ($trace === '?' or defined('_DEBUG_TRACE_QUERIES')) { |
|
| 21 | + if (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES) { |
|
| 22 | + $trace = true; |
|
| 23 | + } |
|
| 24 | + else { |
|
| 25 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 26 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 27 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 28 | + // ou une requete SQL faite avant chargement de la session |
|
| 29 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 30 | + } |
|
| 31 | + else { |
|
| 32 | + include_spip('inc/autoriser'); |
|
| 33 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 34 | + // A fortiori quand on demande une trace |
|
| 35 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 36 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return $trace ? microtime() : 0; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // https://code.spip.net/@trace_query_end |
| 45 | 45 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 46 | - static $trace = '?'; |
|
| 47 | - if ($trace === '?') { |
|
| 48 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 49 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 50 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 51 | - // ou une requete SQL faite avant chargement de la session |
|
| 52 | - $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 53 | - } |
|
| 54 | - else { |
|
| 55 | - include_spip('inc/autoriser'); |
|
| 56 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 57 | - // A fortiori quand on demande une trace |
|
| 58 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 59 | - $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - if ($start) { |
|
| 63 | - $end = microtime(); |
|
| 64 | - [$usec, $sec] = explode(' ', $start); |
|
| 65 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 66 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 67 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 68 | - if ($trace) { |
|
| 69 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 73 | - if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 74 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $result; |
|
| 46 | + static $trace = '?'; |
|
| 47 | + if ($trace === '?') { |
|
| 48 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 49 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 50 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 51 | + // ou une requete SQL faite avant chargement de la session |
|
| 52 | + $trace = (!empty($_GET['var_profile']) ? '?' : false); |
|
| 53 | + } |
|
| 54 | + else { |
|
| 55 | + include_spip('inc/autoriser'); |
|
| 56 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 57 | + // A fortiori quand on demande une trace |
|
| 58 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 59 | + $trace = (!empty($_GET['var_profile']) and autoriser('debug')); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + if ($start) { |
|
| 63 | + $end = microtime(); |
|
| 64 | + [$usec, $sec] = explode(' ', $start); |
|
| 65 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 66 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 67 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 68 | + if ($trace) { |
|
| 69 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 73 | + if ($trace and $erreur and !preg_match('/^select\b/i', $query)) { |
|
| 74 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $result; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // https://code.spip.net/@trace_query_chrono |
| 81 | 81 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 82 | - include_spip('inc/filtres_mini'); |
|
| 83 | - static $tt = 0, $nb = 0; |
|
| 84 | - |
|
| 85 | - $x = _request('var_mode_objet'); |
|
| 86 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 87 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 88 | - if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - if ($serveur) { |
|
| 92 | - $boucle .= " ($serveur)"; |
|
| 93 | - } |
|
| 94 | - $boucle = "<b>$boucle</b>"; |
|
| 95 | - } else { |
|
| 96 | - if ($x) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - $boucle = $contexte = ''; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $tt += $dt; |
|
| 103 | - $nb++; |
|
| 104 | - |
|
| 105 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 106 | - $e = sql_explain($query, $serveur); |
|
| 107 | - $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 108 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 82 | + include_spip('inc/filtres_mini'); |
|
| 83 | + static $tt = 0, $nb = 0; |
|
| 84 | + |
|
| 85 | + $x = _request('var_mode_objet'); |
|
| 86 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 87 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 88 | + if ($x and !preg_match("/$boucle\$/", $x)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + if ($serveur) { |
|
| 92 | + $boucle .= " ($serveur)"; |
|
| 93 | + } |
|
| 94 | + $boucle = "<b>$boucle</b>"; |
|
| 95 | + } else { |
|
| 96 | + if ($x) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + $boucle = $contexte = ''; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $tt += $dt; |
|
| 103 | + $nb++; |
|
| 104 | + |
|
| 105 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 106 | + $e = sql_explain($query, $serveur); |
|
| 107 | + $r = str_replace('Resource id ', '', (is_object($result) ? get_class($result) : $result)); |
|
| 108 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | function chrono_requete($temps) { |
| 113 | - $total = 0; |
|
| 114 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 115 | - $t = $q = $n = $d = []; |
|
| 116 | - // Totaliser les temps et completer le Explain |
|
| 117 | - foreach ($temps as $key => $v) { |
|
| 118 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 119 | - if (is_array($contexte)) { |
|
| 120 | - $k = ($contexte[0] . " $boucle"); |
|
| 121 | - include_spip('public/compiler'); |
|
| 122 | - $env = reconstruire_contexte_compil($contexte); |
|
| 123 | - } else { |
|
| 124 | - $k = $env = $boucle; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $total += $dt; |
|
| 128 | - $t[$key] = $dt; |
|
| 129 | - $q[$key] = $nb; |
|
| 130 | - if (!isset($d[$k])) { |
|
| 131 | - $d[$k] = 0; |
|
| 132 | - $n[$k] = 0; |
|
| 133 | - } |
|
| 134 | - $d[$k] += $dt; |
|
| 135 | - ++$n[$k]; |
|
| 136 | - |
|
| 137 | - if (!is_array($explain)) { |
|
| 138 | - $explain = []; |
|
| 139 | - } |
|
| 140 | - foreach ($explain as $j => $v) { |
|
| 141 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 142 | - . str_replace(';', '<br />', $v) |
|
| 143 | - . '</td></tr>'; |
|
| 144 | - } |
|
| 145 | - $e = "<table class='explain'>" |
|
| 146 | - . '<caption>' |
|
| 147 | - . $query |
|
| 148 | - . '</caption>' |
|
| 149 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 150 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 151 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 152 | - . join('', $explain) |
|
| 153 | - . '</table>'; |
|
| 154 | - |
|
| 155 | - $temps[$key] = [$e, $env, $k]; |
|
| 156 | - } |
|
| 157 | - // Trier par temps d'execution decroissant |
|
| 158 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 159 | - arsort($d); |
|
| 160 | - $i = 1; |
|
| 161 | - $t = []; |
|
| 162 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 163 | - foreach ($temps as $k => $v) { |
|
| 164 | - $titre = strip_tags($v[2]); |
|
| 165 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 166 | - $href = str_replace("\\'", ''', $href); |
|
| 167 | - |
|
| 168 | - if (!isset($t[$v[2]])) { |
|
| 169 | - $t[$v[2]] = []; |
|
| 170 | - } |
|
| 171 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 172 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 173 | - . '</span>' |
|
| 174 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 175 | - $i++; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($d['']) { |
|
| 179 | - $d[$hors] = $d['']; |
|
| 180 | - $n[$hors] = $n['']; |
|
| 181 | - $t[$hors] = $t['']; |
|
| 182 | - } |
|
| 183 | - unset($d['']); |
|
| 184 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 185 | - foreach ($d as $k => $v) { |
|
| 186 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 187 | - . join('', $t[$k]); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $navigation = [ |
|
| 191 | - _T('zbug_statistiques'), |
|
| 192 | - '<tr><td>' |
|
| 193 | - . join("</td></tr>\n<tr><td>", $d) |
|
| 194 | - . "</td></tr>\n" |
|
| 195 | - . (# _request('var_mode_objet') ? '' : |
|
| 196 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 197 | - ]; |
|
| 198 | - |
|
| 199 | - return [$temps, $navigation]; |
|
| 113 | + $total = 0; |
|
| 114 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 115 | + $t = $q = $n = $d = []; |
|
| 116 | + // Totaliser les temps et completer le Explain |
|
| 117 | + foreach ($temps as $key => $v) { |
|
| 118 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 119 | + if (is_array($contexte)) { |
|
| 120 | + $k = ($contexte[0] . " $boucle"); |
|
| 121 | + include_spip('public/compiler'); |
|
| 122 | + $env = reconstruire_contexte_compil($contexte); |
|
| 123 | + } else { |
|
| 124 | + $k = $env = $boucle; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $total += $dt; |
|
| 128 | + $t[$key] = $dt; |
|
| 129 | + $q[$key] = $nb; |
|
| 130 | + if (!isset($d[$k])) { |
|
| 131 | + $d[$k] = 0; |
|
| 132 | + $n[$k] = 0; |
|
| 133 | + } |
|
| 134 | + $d[$k] += $dt; |
|
| 135 | + ++$n[$k]; |
|
| 136 | + |
|
| 137 | + if (!is_array($explain)) { |
|
| 138 | + $explain = []; |
|
| 139 | + } |
|
| 140 | + foreach ($explain as $j => $v) { |
|
| 141 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 142 | + . str_replace(';', '<br />', $v) |
|
| 143 | + . '</td></tr>'; |
|
| 144 | + } |
|
| 145 | + $e = "<table class='explain'>" |
|
| 146 | + . '<caption>' |
|
| 147 | + . $query |
|
| 148 | + . '</caption>' |
|
| 149 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 150 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 151 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 152 | + . join('', $explain) |
|
| 153 | + . '</table>'; |
|
| 154 | + |
|
| 155 | + $temps[$key] = [$e, $env, $k]; |
|
| 156 | + } |
|
| 157 | + // Trier par temps d'execution decroissant |
|
| 158 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 159 | + arsort($d); |
|
| 160 | + $i = 1; |
|
| 161 | + $t = []; |
|
| 162 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 163 | + foreach ($temps as $k => $v) { |
|
| 164 | + $titre = strip_tags($v[2]); |
|
| 165 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 166 | + $href = str_replace("\\'", ''', $href); |
|
| 167 | + |
|
| 168 | + if (!isset($t[$v[2]])) { |
|
| 169 | + $t[$v[2]] = []; |
|
| 170 | + } |
|
| 171 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 172 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 173 | + . '</span>' |
|
| 174 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 175 | + $i++; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($d['']) { |
|
| 179 | + $d[$hors] = $d['']; |
|
| 180 | + $n[$hors] = $n['']; |
|
| 181 | + $t[$hors] = $t['']; |
|
| 182 | + } |
|
| 183 | + unset($d['']); |
|
| 184 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 185 | + foreach ($d as $k => $v) { |
|
| 186 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 187 | + . join('', $t[$k]); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $navigation = [ |
|
| 191 | + _T('zbug_statistiques'), |
|
| 192 | + '<tr><td>' |
|
| 193 | + . join("</td></tr>\n<tr><td>", $d) |
|
| 194 | + . "</td></tr>\n" |
|
| 195 | + . (# _request('var_mode_objet') ? '' : |
|
| 196 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 197 | + ]; |
|
| 198 | + |
|
| 199 | + return [$temps, $navigation]; |
|
| 200 | 200 | } |
@@ -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 | /** |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | define('_PHP_MIN', '7.4.0'); |
| 37 | 37 | |
| 38 | 38 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 39 | - /** le nom du repertoire ecrire/ */ |
|
| 40 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 39 | + /** le nom du repertoire ecrire/ */ |
|
| 40 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** Chemin relatif pour aller dans ecrire |
| 44 | 44 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 45 | 45 | define( |
| 46 | - '_DIR_RESTREINT', |
|
| 47 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 46 | + '_DIR_RESTREINT', |
|
| 47 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | /** Chemin relatif pour aller à la racine */ |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // Icones |
| 61 | 61 | if (!defined('_NOM_IMG_PACK')) { |
| 62 | - /** Nom du dossier images */ |
|
| 63 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 62 | + /** Nom du dossier images */ |
|
| 63 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 64 | 64 | } |
| 65 | 65 | /** le chemin http (relatif) vers les images standard */ |
| 66 | 66 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 70 | 70 | |
| 71 | 71 | if (!defined('_JAVASCRIPT')) { |
| 72 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 72 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 74 | 74 | } // utilisable avec #CHEMIN et find_in_path |
| 75 | 75 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 76 | 76 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -80,47 +80,47 @@ discard block |
||
| 80 | 80 | # mais on peut les mettre ailleurs et changer completement les noms |
| 81 | 81 | |
| 82 | 82 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 83 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 83 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 85 | 85 | } |
| 86 | 86 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 87 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 87 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 89 | 89 | } |
| 90 | 90 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 91 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 91 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 93 | 93 | } |
| 94 | 94 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 95 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 95 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** Le nom du fichier de personnalisation */ |
| 101 | 101 | if (!defined('_NOM_CONFIG')) { |
| 102 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 102 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Son emplacement absolu si on le trouve |
| 106 | 106 | if ( |
| 107 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 107 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 109 | 109 | ) { |
| 110 | - /** Emplacement absolu du fichier d'option */ |
|
| 111 | - define('_FILE_OPTIONS', $f); |
|
| 110 | + /** Emplacement absolu du fichier d'option */ |
|
| 111 | + define('_FILE_OPTIONS', $f); |
|
| 112 | 112 | } else { |
| 113 | - define('_FILE_OPTIONS', ''); |
|
| 113 | + define('_FILE_OPTIONS', ''); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | if (!defined('MODULES_IDIOMES')) { |
| 117 | - /** |
|
| 118 | - * Modules par défaut pour la traduction. |
|
| 119 | - * |
|
| 120 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | - */ |
|
| 123 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 117 | + /** |
|
| 118 | + * Modules par défaut pour la traduction. |
|
| 119 | + * |
|
| 120 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | + */ |
|
| 123 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // *** Fin des define *** // |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Inclure l'ecran de securite |
| 130 | 130 | if ( |
| 131 | - !defined('_ECRAN_SECURITE') |
|
| 132 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 131 | + !defined('_ECRAN_SECURITE') |
|
| 132 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 133 | 133 | ) { |
| 134 | - include $f; |
|
| 134 | + include $f; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -139,30 +139,30 @@ discard block |
||
| 139 | 139 | * Détecteur de robot d'indexation |
| 140 | 140 | */ |
| 141 | 141 | if (!defined('_IS_BOT')) { |
| 142 | - define( |
|
| 143 | - '_IS_BOT', |
|
| 144 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | - and preg_match( |
|
| 146 | - // mots generiques |
|
| 147 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | - . 'MSIE 6\.0|' |
|
| 150 | - // UA plus cibles |
|
| 151 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | - . ',i', |
|
| 153 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 142 | + define( |
|
| 143 | + '_IS_BOT', |
|
| 144 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | + and preg_match( |
|
| 146 | + // mots generiques |
|
| 147 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | + . 'MSIE 6\.0|' |
|
| 150 | + // UA plus cibles |
|
| 151 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | + . ',i', |
|
| 153 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | if (!defined('_IS_CLI')) { |
| 159 | - define( |
|
| 160 | - '_IS_CLI', |
|
| 161 | - !isset($_SERVER['HTTP_HOST']) |
|
| 162 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | - and !empty($_SERVER['argv']) |
|
| 164 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | - ); |
|
| 159 | + define( |
|
| 160 | + '_IS_CLI', |
|
| 161 | + !isset($_SERVER['HTTP_HOST']) |
|
| 162 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | + and !empty($_SERVER['argv']) |
|
| 164 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | + ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // *** Parametrage par defaut de SPIP *** |
@@ -174,61 +174,61 @@ discard block |
||
| 174 | 174 | // Ne pas les rendre indefinies. |
| 175 | 175 | |
| 176 | 176 | global |
| 177 | - $nombre_de_logs, |
|
| 178 | - $taille_des_logs, |
|
| 179 | - $table_prefix, |
|
| 180 | - $cookie_prefix, |
|
| 181 | - $dossier_squelettes, |
|
| 182 | - $filtrer_javascript, |
|
| 183 | - $type_urls, |
|
| 184 | - $debut_date_publication, |
|
| 185 | - $ip, |
|
| 186 | - $mysql_rappel_connexion, |
|
| 187 | - $mysql_rappel_nom_base, |
|
| 188 | - $test_i18n, |
|
| 189 | - $ignore_auth_http, |
|
| 190 | - $ignore_remote_user, |
|
| 191 | - $derniere_modif_invalide, |
|
| 192 | - $home_server, |
|
| 193 | - $help_server, |
|
| 194 | - $url_glossaire_externe, |
|
| 195 | - $tex_server, |
|
| 196 | - $traiter_math, |
|
| 197 | - $xhtml, |
|
| 198 | - $xml_indent, |
|
| 199 | - $source_vignettes, |
|
| 200 | - $formats_logos, |
|
| 201 | - $controler_dates_rss, |
|
| 202 | - $spip_pipeline, |
|
| 203 | - $spip_matrice, |
|
| 204 | - $plugins, |
|
| 205 | - $surcharges, |
|
| 206 | - $exceptions_des_tables, |
|
| 207 | - $tables_principales, |
|
| 208 | - $table_des_tables, |
|
| 209 | - $tables_auxiliaires, |
|
| 210 | - $table_primary, |
|
| 211 | - $table_date, |
|
| 212 | - $table_titre, |
|
| 213 | - $tables_jointures, |
|
| 214 | - $liste_des_statuts, |
|
| 215 | - $liste_des_etats, |
|
| 216 | - $liste_des_authentifications, |
|
| 217 | - $spip_version_branche, |
|
| 218 | - $spip_version_code, |
|
| 219 | - $spip_version_base, |
|
| 220 | - $spip_sql_version, |
|
| 221 | - $spip_version_affichee, |
|
| 222 | - $visiteur_session, |
|
| 223 | - $auteur_session, |
|
| 224 | - $connect_statut, |
|
| 225 | - $connect_toutes_rubriques, |
|
| 226 | - $hash_recherche, |
|
| 227 | - $hash_recherche_strict, |
|
| 228 | - $ldap_present, |
|
| 229 | - $meta, |
|
| 230 | - $connect_id_rubrique, |
|
| 231 | - $puce; |
|
| 177 | + $nombre_de_logs, |
|
| 178 | + $taille_des_logs, |
|
| 179 | + $table_prefix, |
|
| 180 | + $cookie_prefix, |
|
| 181 | + $dossier_squelettes, |
|
| 182 | + $filtrer_javascript, |
|
| 183 | + $type_urls, |
|
| 184 | + $debut_date_publication, |
|
| 185 | + $ip, |
|
| 186 | + $mysql_rappel_connexion, |
|
| 187 | + $mysql_rappel_nom_base, |
|
| 188 | + $test_i18n, |
|
| 189 | + $ignore_auth_http, |
|
| 190 | + $ignore_remote_user, |
|
| 191 | + $derniere_modif_invalide, |
|
| 192 | + $home_server, |
|
| 193 | + $help_server, |
|
| 194 | + $url_glossaire_externe, |
|
| 195 | + $tex_server, |
|
| 196 | + $traiter_math, |
|
| 197 | + $xhtml, |
|
| 198 | + $xml_indent, |
|
| 199 | + $source_vignettes, |
|
| 200 | + $formats_logos, |
|
| 201 | + $controler_dates_rss, |
|
| 202 | + $spip_pipeline, |
|
| 203 | + $spip_matrice, |
|
| 204 | + $plugins, |
|
| 205 | + $surcharges, |
|
| 206 | + $exceptions_des_tables, |
|
| 207 | + $tables_principales, |
|
| 208 | + $table_des_tables, |
|
| 209 | + $tables_auxiliaires, |
|
| 210 | + $table_primary, |
|
| 211 | + $table_date, |
|
| 212 | + $table_titre, |
|
| 213 | + $tables_jointures, |
|
| 214 | + $liste_des_statuts, |
|
| 215 | + $liste_des_etats, |
|
| 216 | + $liste_des_authentifications, |
|
| 217 | + $spip_version_branche, |
|
| 218 | + $spip_version_code, |
|
| 219 | + $spip_version_base, |
|
| 220 | + $spip_sql_version, |
|
| 221 | + $spip_version_affichee, |
|
| 222 | + $visiteur_session, |
|
| 223 | + $auteur_session, |
|
| 224 | + $connect_statut, |
|
| 225 | + $connect_toutes_rubriques, |
|
| 226 | + $hash_recherche, |
|
| 227 | + $hash_recherche_strict, |
|
| 228 | + $ldap_present, |
|
| 229 | + $meta, |
|
| 230 | + $connect_id_rubrique, |
|
| 231 | + $puce; |
|
| 232 | 232 | |
| 233 | 233 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 234 | 234 | $nombre_de_logs = 4; |
@@ -283,48 +283,48 @@ discard block |
||
| 283 | 283 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 284 | 284 | // |
| 285 | 285 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 286 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | - } |
|
| 289 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | - } |
|
| 286 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | + } |
|
| 289 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | + } |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 294 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | - $_SERVER['HTTPS'] = 'on'; |
|
| 298 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | - if (strpos($host, ',') !== false) { |
|
| 305 | - $h = explode(',', $host); |
|
| 306 | - $host = trim(reset($h)); |
|
| 307 | - } |
|
| 308 | - // securite sur le contenu de l'entete |
|
| 309 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 294 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | + $_SERVER['HTTPS'] = 'on'; |
|
| 298 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | + if (strpos($host, ',') !== false) { |
|
| 305 | + $h = explode(',', $host); |
|
| 306 | + $host = trim(reset($h)); |
|
| 307 | + } |
|
| 308 | + // securite sur le contenu de l'entete |
|
| 309 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 311 | 311 | } |
| 312 | 312 | // |
| 313 | 313 | // On note le numero IP du client dans la variable $ip |
| 314 | 314 | // |
| 315 | 315 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 316 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | - if (strpos($ip, ',') !== false) { |
|
| 318 | - $ip = explode(',', $ip); |
|
| 319 | - $ip = reset($ip); |
|
| 320 | - } |
|
| 321 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | - } |
|
| 316 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | + if (strpos($ip, ',') !== false) { |
|
| 318 | + $ip = explode(',', $ip); |
|
| 319 | + $ip = reset($ip); |
|
| 320 | + } |
|
| 321 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 327 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 327 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -409,24 +409,24 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | // Liste des statuts. |
| 411 | 411 | $liste_des_statuts = [ |
| 412 | - 'info_administrateurs' => '0minirezo', |
|
| 413 | - 'info_redacteurs' => '1comite', |
|
| 414 | - 'info_visiteurs' => '6forum', |
|
| 415 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 412 | + 'info_administrateurs' => '0minirezo', |
|
| 413 | + 'info_redacteurs' => '1comite', |
|
| 414 | + 'info_visiteurs' => '6forum', |
|
| 415 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 416 | 416 | ]; |
| 417 | 417 | |
| 418 | 418 | $liste_des_etats = [ |
| 419 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | - 'texte_statut_publie' => 'publie', |
|
| 422 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | - 'texte_statut_refuse' => 'refuse' |
|
| 419 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | + 'texte_statut_publie' => 'publie', |
|
| 422 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | + 'texte_statut_refuse' => 'refuse' |
|
| 424 | 424 | ]; |
| 425 | 425 | |
| 426 | 426 | // liste des methodes d'authentifications |
| 427 | 427 | $liste_des_authentifications = [ |
| 428 | - 'spip' => 'spip', |
|
| 429 | - 'ldap' => 'ldap' |
|
| 428 | + 'spip' => 'spip', |
|
| 429 | + 'ldap' => 'ldap' |
|
| 430 | 430 | ]; |
| 431 | 431 | |
| 432 | 432 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | // Definition personnelles eventuelles |
| 477 | 477 | |
| 478 | 478 | if (_FILE_OPTIONS) { |
| 479 | - include_once _FILE_OPTIONS; |
|
| 479 | + include_once _FILE_OPTIONS; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 483 | - /** Masquer les warning */ |
|
| 484 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 483 | + /** Masquer les warning */ |
|
| 484 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 485 | 485 | } |
| 486 | 486 | error_reporting(SPIP_ERREUR_REPORT); |
| 487 | 487 | |
@@ -494,10 +494,10 @@ discard block |
||
| 494 | 494 | // ===> on execute en neutralisant les messages d'erreur |
| 495 | 495 | |
| 496 | 496 | spip_initialisation_core( |
| 497 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 497 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | |
@@ -507,70 +507,70 @@ discard block |
||
| 507 | 507 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 508 | 508 | |
| 509 | 509 | if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) { |
| 510 | - // chargement optimise precompile |
|
| 511 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 510 | + // chargement optimise precompile |
|
| 511 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 512 | 512 | } else { |
| 513 | - spip_initialisation_suite(); |
|
| 514 | - include_spip('inc/plugin'); |
|
| 515 | - // generer les fichiers php precompiles |
|
| 516 | - // de chargement des plugins et des pipelines |
|
| 517 | - actualise_plugins_actifs(); |
|
| 513 | + spip_initialisation_suite(); |
|
| 514 | + include_spip('inc/plugin'); |
|
| 515 | + // generer les fichiers php precompiles |
|
| 516 | + // de chargement des plugins et des pipelines |
|
| 517 | + actualise_plugins_actifs(); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Initialisations non critiques surchargeables par les plugins |
| 521 | 521 | spip_initialisation_suite(); |
| 522 | 522 | |
| 523 | 523 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 524 | - /** niveau maxi d'enregistrement des logs */ |
|
| 525 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 524 | + /** niveau maxi d'enregistrement des logs */ |
|
| 525 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 529 | - /** Activer des outils pour développeurs ? */ |
|
| 530 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 529 | + /** Activer des outils pour développeurs ? */ |
|
| 530 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 534 | 534 | if (test_espace_prive()) { |
| 535 | - include_spip('inc/autoriser'); |
|
| 535 | + include_spip('inc/autoriser'); |
|
| 536 | 536 | } |
| 537 | 537 | // |
| 538 | 538 | // Installer Spip si pas installe... sauf si justement on est en train |
| 539 | 539 | // |
| 540 | 540 | if ( |
| 541 | - !(_FILE_CONNECT |
|
| 542 | - or autoriser_sans_cookie(_request('exec')) |
|
| 543 | - or _request('action') == 'cookie' |
|
| 544 | - or _request('action') == 'converser' |
|
| 545 | - or _request('action') == 'test_dirs') |
|
| 541 | + !(_FILE_CONNECT |
|
| 542 | + or autoriser_sans_cookie(_request('exec')) |
|
| 543 | + or _request('action') == 'cookie' |
|
| 544 | + or _request('action') == 'converser' |
|
| 545 | + or _request('action') == 'test_dirs') |
|
| 546 | 546 | ) { |
| 547 | - // Si on peut installer, on lance illico |
|
| 548 | - if (test_espace_prive()) { |
|
| 549 | - include_spip('inc/headers'); |
|
| 550 | - redirige_url_ecrire('install'); |
|
| 551 | - } else { |
|
| 552 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | - include_spip('inc/minipres'); |
|
| 554 | - utiliser_langue_visiteur(); |
|
| 555 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | - exit; |
|
| 557 | - } |
|
| 558 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 547 | + // Si on peut installer, on lance illico |
|
| 548 | + if (test_espace_prive()) { |
|
| 549 | + include_spip('inc/headers'); |
|
| 550 | + redirige_url_ecrire('install'); |
|
| 551 | + } else { |
|
| 552 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | + include_spip('inc/minipres'); |
|
| 554 | + utiliser_langue_visiteur(); |
|
| 555 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | + exit; |
|
| 557 | + } |
|
| 558 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | // memoriser un tri sessionne eventuel |
| 562 | 562 | if ( |
| 563 | - isset($_REQUEST['var_memotri']) |
|
| 564 | - and $t = $_REQUEST['var_memotri'] |
|
| 565 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 563 | + isset($_REQUEST['var_memotri']) |
|
| 564 | + and $t = $_REQUEST['var_memotri'] |
|
| 565 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 566 | 566 | ) { |
| 567 | - if (!function_exists('session_set')) { |
|
| 568 | - include_spip('inc/session'); |
|
| 569 | - } |
|
| 570 | - $t = preg_replace(',\W,', '_', $t); |
|
| 571 | - if ($v = _request($t)) { |
|
| 572 | - session_set($t, $v); |
|
| 573 | - } |
|
| 567 | + if (!function_exists('session_set')) { |
|
| 568 | + include_spip('inc/session'); |
|
| 569 | + } |
|
| 570 | + $t = preg_replace(',\W,', '_', $t); |
|
| 571 | + if ($v = _request($t)) { |
|
| 572 | + session_set($t, $v); |
|
| 573 | + } |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -580,22 +580,22 @@ discard block |
||
| 580 | 580 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 581 | 581 | */ |
| 582 | 582 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 583 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 583 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 584 | 584 | } |
| 585 | 585 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 586 | - if (!defined('_HEADER_VARY')) { |
|
| 587 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | - } |
|
| 589 | - if (_HEADER_VARY) { |
|
| 590 | - header(_HEADER_VARY); |
|
| 591 | - } |
|
| 592 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | - include_spip('inc/filtres_mini'); |
|
| 594 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | - } else { |
|
| 596 | - // header minimal |
|
| 597 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | - } |
|
| 586 | + if (!defined('_HEADER_VARY')) { |
|
| 587 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | + } |
|
| 589 | + if (_HEADER_VARY) { |
|
| 590 | + header(_HEADER_VARY); |
|
| 591 | + } |
|
| 592 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | + include_spip('inc/filtres_mini'); |
|
| 594 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | + } else { |
|
| 596 | + // header minimal |
|
| 597 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | + } |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |