@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_fichiers_fonctions(); |
@@ -29,177 +29,177 @@ discard block |
||
| 29 | 29 | # En cas d'erreur process_ins est absent et texte est un tableau de 2 chaines |
| 30 | 30 | |
| 31 | 31 | function public_parametrer_dist($fond, $contexte = '', $cache = '', string $connect = '') { |
| 32 | - static $composer, $styliser, $notes = null; |
|
| 33 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 34 | - if ($page) { |
|
| 35 | - return $page; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (isset($contexte['lang'])) { |
|
| 39 | - $lang = $contexte['lang']; |
|
| 40 | - } elseif (!isset($lang)) { |
|
| 41 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $select = ((!isset($GLOBALS['forcer_lang']) || !$GLOBALS['forcer_lang']) && $lang != $GLOBALS['spip_lang']); |
|
| 45 | - if ($select) { |
|
| 46 | - $select = lang_select($lang); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 50 | - |
|
| 51 | - if (!$styliser) { |
|
| 52 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 53 | - } |
|
| 54 | - [$skel, $mime_type, $gram, $sourcefile] = |
|
| 55 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 56 | - |
|
| 57 | - if ($skel) { |
|
| 58 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 59 | - // (recursion possible a cause des modeles) |
|
| 60 | - if ($debug) { |
|
| 61 | - $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 62 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // charger le squelette en specifiant les langages cibles et source |
|
| 66 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 67 | - |
|
| 68 | - if (!$composer) { |
|
| 69 | - $composer = charger_fonction('composer', 'public'); |
|
| 70 | - } |
|
| 71 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 72 | - } else { |
|
| 73 | - $fonc = ''; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 77 | - $page = $fonc; |
|
| 78 | - } else { |
|
| 79 | - // Preparer l'appel de la fonction principale du squelette |
|
| 80 | - |
|
| 81 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 82 | - |
|
| 83 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 84 | - // et on enregistre l'etat courant des globales de notes... |
|
| 85 | - if (is_null($notes)) { |
|
| 86 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 87 | - } |
|
| 88 | - if ($notes) { |
|
| 89 | - $notes('', 'empiler'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Rajouter d'office ces deux parametres |
|
| 93 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 94 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 95 | - if (!isset($contexte['date'])) { |
|
| 96 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 97 | - $contexte['date_default'] = true; |
|
| 98 | - } else { |
|
| 99 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (!isset($contexte['date_redac'])) { |
|
| 103 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 104 | - $contexte['date_redac_default'] = true; |
|
| 105 | - } else { |
|
| 106 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 110 | - try { |
|
| 111 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 112 | - } catch (Throwable $e) { |
|
| 113 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 116 | - $corps = "<pre>$msg</pre>"; |
|
| 117 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 118 | - erreur_squelette($full_msg); |
|
| 119 | - unset($msg, $full_msg, $corps); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 123 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 124 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 125 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 126 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 127 | - if ($notes) { |
|
| 128 | - $notes('', 'depiler'); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // reinjecter en dynamique la pile des notes |
|
| 132 | - // si il y a des inclure dynamiques |
|
| 133 | - // si la pile n'est pas vide |
|
| 134 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 135 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 136 | - if ($notes) { |
|
| 137 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // spip_log: un joli contexte |
|
| 141 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 142 | - |
|
| 143 | - $profile = spip_timer($a); |
|
| 144 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 145 | - . ' (' . strlen((string) $page['texte']) . ' octets)'); |
|
| 146 | - |
|
| 147 | - if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
|
| 148 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 149 | - . ' (' . strlen((string) $page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($debug) { |
|
| 153 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | - $t = strlen((string) $page['texte']) ? $page['texte'] : ' '; |
|
| 155 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | - if ( |
|
| 159 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 160 | - && _request('var_mode_objet') == $fonc |
|
| 161 | - && _request('var_mode_affiche') == 'resultat' |
|
| 162 | - ) { |
|
| 163 | - erreur_squelette(); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 167 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 168 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 169 | - // si aucun #CACHE{} spécifié |
|
| 170 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 171 | - // entre public et prive |
|
| 172 | - if (test_espace_prive() || str_starts_with((string) $fond, 'modeles/')) { |
|
| 173 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 174 | - } else { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $page['contexte'] = $contexte; |
|
| 180 | - |
|
| 181 | - // faire remonter le fichier source |
|
| 182 | - static $js_inclus = false; |
|
| 183 | - if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
|
| 184 | - $page['sourcefile'] = $sourcefile; |
|
| 185 | - $page['texte'] = |
|
| 186 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 187 | - . ($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>"); |
|
| 188 | - $js_inclus = true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 192 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 193 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 194 | - unset($GLOBALS['cache_utilise_session']); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($select) { |
|
| 199 | - lang_select(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $page; |
|
| 32 | + static $composer, $styliser, $notes = null; |
|
| 33 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 34 | + if ($page) { |
|
| 35 | + return $page; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (isset($contexte['lang'])) { |
|
| 39 | + $lang = $contexte['lang']; |
|
| 40 | + } elseif (!isset($lang)) { |
|
| 41 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $select = ((!isset($GLOBALS['forcer_lang']) || !$GLOBALS['forcer_lang']) && $lang != $GLOBALS['spip_lang']); |
|
| 45 | + if ($select) { |
|
| 46 | + $select = lang_select($lang); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 50 | + |
|
| 51 | + if (!$styliser) { |
|
| 52 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 53 | + } |
|
| 54 | + [$skel, $mime_type, $gram, $sourcefile] = |
|
| 55 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 56 | + |
|
| 57 | + if ($skel) { |
|
| 58 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 59 | + // (recursion possible a cause des modeles) |
|
| 60 | + if ($debug) { |
|
| 61 | + $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 62 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // charger le squelette en specifiant les langages cibles et source |
|
| 66 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 67 | + |
|
| 68 | + if (!$composer) { |
|
| 69 | + $composer = charger_fonction('composer', 'public'); |
|
| 70 | + } |
|
| 71 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 72 | + } else { |
|
| 73 | + $fonc = ''; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 77 | + $page = $fonc; |
|
| 78 | + } else { |
|
| 79 | + // Preparer l'appel de la fonction principale du squelette |
|
| 80 | + |
|
| 81 | + spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 82 | + |
|
| 83 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 84 | + // et on enregistre l'etat courant des globales de notes... |
|
| 85 | + if (is_null($notes)) { |
|
| 86 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 87 | + } |
|
| 88 | + if ($notes) { |
|
| 89 | + $notes('', 'empiler'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Rajouter d'office ces deux parametres |
|
| 93 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 94 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 95 | + if (!isset($contexte['date'])) { |
|
| 96 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 97 | + $contexte['date_default'] = true; |
|
| 98 | + } else { |
|
| 99 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (!isset($contexte['date_redac'])) { |
|
| 103 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 104 | + $contexte['date_redac_default'] = true; |
|
| 105 | + } else { |
|
| 106 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 110 | + try { |
|
| 111 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 112 | + } catch (Throwable $e) { |
|
| 113 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 116 | + $corps = "<pre>$msg</pre>"; |
|
| 117 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 118 | + erreur_squelette($full_msg); |
|
| 119 | + unset($msg, $full_msg, $corps); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 123 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 124 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 125 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 126 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 127 | + if ($notes) { |
|
| 128 | + $notes('', 'depiler'); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // reinjecter en dynamique la pile des notes |
|
| 132 | + // si il y a des inclure dynamiques |
|
| 133 | + // si la pile n'est pas vide |
|
| 134 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 135 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 136 | + if ($notes) { |
|
| 137 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // spip_log: un joli contexte |
|
| 141 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 142 | + |
|
| 143 | + $profile = spip_timer($a); |
|
| 144 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 145 | + . ' (' . strlen((string) $page['texte']) . ' octets)'); |
|
| 146 | + |
|
| 147 | + if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
|
| 148 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 149 | + . ' (' . strlen((string) $page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($debug) { |
|
| 153 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | + $t = strlen((string) $page['texte']) ? $page['texte'] : ' '; |
|
| 155 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | + if ( |
|
| 159 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 160 | + && _request('var_mode_objet') == $fonc |
|
| 161 | + && _request('var_mode_affiche') == 'resultat' |
|
| 162 | + ) { |
|
| 163 | + erreur_squelette(); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 167 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 168 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 169 | + // si aucun #CACHE{} spécifié |
|
| 170 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 171 | + // entre public et prive |
|
| 172 | + if (test_espace_prive() || str_starts_with((string) $fond, 'modeles/')) { |
|
| 173 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 174 | + } else { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $page['contexte'] = $contexte; |
|
| 180 | + |
|
| 181 | + // faire remonter le fichier source |
|
| 182 | + static $js_inclus = false; |
|
| 183 | + if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
|
| 184 | + $page['sourcefile'] = $sourcefile; |
|
| 185 | + $page['texte'] = |
|
| 186 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 187 | + . ($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>"); |
|
| 188 | + $js_inclus = true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 192 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 193 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 194 | + unset($GLOBALS['cache_utilise_session']); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($select) { |
|
| 199 | + lang_select(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $page; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -208,37 +208,37 @@ discard block |
||
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | 210 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 211 | - $infos = []; |
|
| 212 | - $line = 0; |
|
| 213 | - foreach ($contexte as $var => $val) { |
|
| 214 | - $line++; |
|
| 215 | - if ($max_lines && $max_lines < $line) { |
|
| 216 | - $infos[] = '…'; |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - if ($val === null) { |
|
| 220 | - $val = ''; |
|
| 221 | - } elseif (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = $val::class; |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr((string) $val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } elseif (!strlen((string) $val)) { |
|
| 237 | - $val = "''"; |
|
| 238 | - } |
|
| 239 | - $infos[] = $var . '=' . $val; |
|
| 240 | - } |
|
| 241 | - return implode(', ', $infos); |
|
| 211 | + $infos = []; |
|
| 212 | + $line = 0; |
|
| 213 | + foreach ($contexte as $var => $val) { |
|
| 214 | + $line++; |
|
| 215 | + if ($max_lines && $max_lines < $line) { |
|
| 216 | + $infos[] = '…'; |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + if ($val === null) { |
|
| 220 | + $val = ''; |
|
| 221 | + } elseif (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = $val::class; |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr((string) $val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } elseif (!strlen((string) $val)) { |
|
| 237 | + $val = "''"; |
|
| 238 | + } |
|
| 239 | + $infos[] = $var . '=' . $val; |
|
| 240 | + } |
|
| 241 | + return implode(', ', $infos); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | * @return array|bool |
| 256 | 256 | */ |
| 257 | 257 | function tester_redirection($fond, $contexte, $connect) { |
| 258 | - static $tester_redirection = null; |
|
| 259 | - if (is_null($tester_redirection)) { |
|
| 260 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 261 | - } |
|
| 262 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 258 | + static $tester_redirection = null; |
|
| 259 | + if (is_null($tester_redirection)) { |
|
| 260 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 261 | + } |
|
| 262 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -275,42 +275,42 @@ discard block |
||
| 275 | 275 | * @return array|bool |
| 276 | 276 | */ |
| 277 | 277 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 278 | - if ( |
|
| 279 | - $fond == 'article' |
|
| 280 | - && !empty($contexte['id_article']) |
|
| 281 | - && ($id_article = (int) $contexte['id_article']) |
|
| 282 | - ) { |
|
| 283 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 284 | - $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 285 | - if (strlen($m)) { |
|
| 286 | - include_spip('inc/texte'); |
|
| 287 | - // les navigateurs pataugent si l'URL est vide |
|
| 288 | - if ($url = virtuel_redirige($m, true)) { |
|
| 289 | - // passer en url absolue car cette redirection pourra |
|
| 290 | - // etre utilisee dans un contexte d'url qui change |
|
| 291 | - // y compris url arbo |
|
| 292 | - $status = 302; |
|
| 293 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 294 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 295 | - } |
|
| 296 | - if (!preg_match(',^\w+:,', (string) $url)) { |
|
| 297 | - include_spip('inc/filtres_mini'); |
|
| 298 | - $url = url_absolue($url); |
|
| 299 | - } |
|
| 300 | - $url = str_replace('&', '&', (string) $url); |
|
| 301 | - |
|
| 302 | - return [ |
|
| 303 | - 'texte' => '<' |
|
| 304 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 305 | - . texte_script($url) |
|
| 306 | - . "','',$status);" |
|
| 307 | - . '?' . '>', |
|
| 308 | - 'process_ins' => 'php', |
|
| 309 | - 'status' => $status |
|
| 310 | - ]; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return false; |
|
| 278 | + if ( |
|
| 279 | + $fond == 'article' |
|
| 280 | + && !empty($contexte['id_article']) |
|
| 281 | + && ($id_article = (int) $contexte['id_article']) |
|
| 282 | + ) { |
|
| 283 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 284 | + $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 285 | + if (strlen($m)) { |
|
| 286 | + include_spip('inc/texte'); |
|
| 287 | + // les navigateurs pataugent si l'URL est vide |
|
| 288 | + if ($url = virtuel_redirige($m, true)) { |
|
| 289 | + // passer en url absolue car cette redirection pourra |
|
| 290 | + // etre utilisee dans un contexte d'url qui change |
|
| 291 | + // y compris url arbo |
|
| 292 | + $status = 302; |
|
| 293 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 294 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 295 | + } |
|
| 296 | + if (!preg_match(',^\w+:,', (string) $url)) { |
|
| 297 | + include_spip('inc/filtres_mini'); |
|
| 298 | + $url = url_absolue($url); |
|
| 299 | + } |
|
| 300 | + $url = str_replace('&', '&', (string) $url); |
|
| 301 | + |
|
| 302 | + return [ |
|
| 303 | + 'texte' => '<' |
|
| 304 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 305 | + . texte_script($url) |
|
| 306 | + . "','',$status);" |
|
| 307 | + . '?' . '>', |
|
| 308 | + 'process_ins' => 'php', |
|
| 309 | + 'status' => $status |
|
| 310 | + ]; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return false; |
|
| 316 | 316 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } else { |
| 79 | 79 | // Preparer l'appel de la fonction principale du squelette |
| 80 | 80 | |
| 81 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 81 | + spip_timer($a = 'calcul page '.random_int(0, 1000)); |
|
| 82 | 82 | |
| 83 | 83 | // On cree un marqueur de notes unique lie a cette composition |
| 84 | 84 | // et on enregistre l'etat courant des globales de notes... |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | try { |
| 111 | 111 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 112 | 112 | } catch (Throwable $e) { |
| 113 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 113 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 114 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 115 | 115 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 116 | 116 | $corps = "<pre>$msg</pre>"; |
| 117 | 117 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -142,17 +142,17 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $profile = spip_timer($a); |
| 144 | 144 | spip_log("calcul ($profile) [$skel] $infos" |
| 145 | - . ' (' . strlen((string) $page['texte']) . ' octets)'); |
|
| 145 | + . ' ('.strlen((string) $page['texte']).' octets)'); |
|
| 146 | 146 | |
| 147 | 147 | if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
| 148 | 148 | spip_log("calcul ($profile) [$skel] $infos" |
| 149 | - . ' (' . strlen((string) $page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 149 | + . ' ('.strlen((string) $page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if ($debug) { |
| 153 | 153 | // si c'est ce que demande le debusqueur, lui passer la main |
| 154 | 154 | $t = strlen((string) $page['texte']) ? $page['texte'] : ' '; |
| 155 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 155 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 156 | 156 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 157 | 157 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 158 | 158 | if ( |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
| 184 | 184 | $page['sourcefile'] = $sourcefile; |
| 185 | 185 | $page['texte'] = |
| 186 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 186 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 187 | 187 | . ($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>"); |
| 188 | 188 | $js_inclus = true; |
| 189 | 189 | } |
@@ -220,14 +220,14 @@ discard block |
||
| 220 | 220 | $val = ''; |
| 221 | 221 | } elseif (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = $val::class; |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } elseif (!strlen((string) $val)) { |
| 237 | 237 | $val = "''"; |
| 238 | 238 | } |
| 239 | - $infos[] = $var . '=' . $val; |
|
| 239 | + $infos[] = $var.'='.$val; |
|
| 240 | 240 | } |
| 241 | 241 | return implode(', ', $infos); |
| 242 | 242 | } |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 305 | 305 | . texte_script($url) |
| 306 | 306 | . "','',$status);" |
| 307 | - . '?' . '>', |
|
| 307 | + . '?'.'>', |
|
| 308 | 308 | 'process_ins' => 'php', |
| 309 | 309 | 'status' => $status |
| 310 | 310 | ]; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -28,50 +28,50 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | - /** @var bool Évaluation réussie ? */ |
|
| 31 | + /** @var bool Évaluation réussie ? */ |
|
| 32 | 32 | $res = true; |
| 33 | 33 | |
| 34 | 34 | // Cas d'une page contenant du PHP : |
| 35 | 35 | if (empty($page['process_ins']) || $page['process_ins'] != 'html') { |
| 36 | - include_spip('inc/lang'); |
|
| 36 | + include_spip('inc/lang'); |
|
| 37 | 37 | |
| 38 | - // restaurer l'etat des notes avant calcul |
|
| 39 | - if ( |
|
| 40 | - isset($page['notes']) |
|
| 41 | - && $page['notes'] |
|
| 42 | - && ($notes = charger_fonction('notes', 'inc', true)) |
|
| 43 | - ) { |
|
| 44 | - $notes($page['notes'], 'restaurer_etat'); |
|
| 45 | - } |
|
| 46 | - ob_start(); |
|
| 47 | - if (str_contains((string) $page['texte'], '?xml')) { |
|
| 48 | - $page['texte'] = str_replace('<?xml', "<\1?xml", (string) $page['texte']); |
|
| 49 | - } |
|
| 38 | + // restaurer l'etat des notes avant calcul |
|
| 39 | + if ( |
|
| 40 | + isset($page['notes']) |
|
| 41 | + && $page['notes'] |
|
| 42 | + && ($notes = charger_fonction('notes', 'inc', true)) |
|
| 43 | + ) { |
|
| 44 | + $notes($page['notes'], 'restaurer_etat'); |
|
| 45 | + } |
|
| 46 | + ob_start(); |
|
| 47 | + if (str_contains((string) $page['texte'], '?xml')) { |
|
| 48 | + $page['texte'] = str_replace('<?xml', "<\1?xml", (string) $page['texte']); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - try { |
|
| 52 | - $res = eval('?' . '>' . $page['texte']); |
|
| 53 | - $page['texte'] = ob_get_contents(); |
|
| 54 | - } catch (\Throwable $e) { |
|
| 55 | - $code = $page['texte']; |
|
| 56 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 57 | - if (!function_exists('numerote_ligne_php')) { |
|
| 58 | - function numerote_ligne_php($match) { |
|
| 59 | - $GLOBALS['numero_ligne_php']++; |
|
| 60 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code); |
|
| 64 | - $code = trim(highlight_string($code, true)); |
|
| 65 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 66 | - $page['texte'] = '<!-- Erreur -->'; |
|
| 67 | - } |
|
| 68 | - ob_end_clean(); |
|
| 51 | + try { |
|
| 52 | + $res = eval('?' . '>' . $page['texte']); |
|
| 53 | + $page['texte'] = ob_get_contents(); |
|
| 54 | + } catch (\Throwable $e) { |
|
| 55 | + $code = $page['texte']; |
|
| 56 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 57 | + if (!function_exists('numerote_ligne_php')) { |
|
| 58 | + function numerote_ligne_php($match) { |
|
| 59 | + $GLOBALS['numero_ligne_php']++; |
|
| 60 | + return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code); |
|
| 64 | + $code = trim(highlight_string($code, true)); |
|
| 65 | + erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 66 | + $page['texte'] = '<!-- Erreur -->'; |
|
| 67 | + } |
|
| 68 | + ob_end_clean(); |
|
| 69 | 69 | |
| 70 | - $page['process_ins'] = 'html'; |
|
| 70 | + $page['process_ins'] = 'html'; |
|
| 71 | 71 | |
| 72 | - if (str_contains((string) $page['texte'], '?xml')) { |
|
| 73 | - $page['texte'] = str_replace("<\1?xml", '<?xml', (string) $page['texte']); |
|
| 74 | - } |
|
| 72 | + if (str_contains((string) $page['texte'], '?xml')) { |
|
| 73 | + $page['texte'] = str_replace("<\1?xml", '<?xml', (string) $page['texte']); |
|
| 74 | + } |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // le résultat de calcul d'un squelette est toujours de type string |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | try { |
| 52 | - $res = eval('?' . '>' . $page['texte']); |
|
| 52 | + $res = eval('?'.'>'.$page['texte']); |
|
| 53 | 53 | $page['texte'] = ob_get_contents(); |
| 54 | 54 | } catch (\Throwable $e) { |
| 55 | 55 | $code = $page['texte']; |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | if (!function_exists('numerote_ligne_php')) { |
| 58 | 58 | function numerote_ligne_php($match) { |
| 59 | 59 | $GLOBALS['numero_ligne_php']++; |
| 60 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 60 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/'; |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code); |
|
| 63 | + $code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code); |
|
| 64 | 64 | $code = trim(highlight_string($code, true)); |
| 65 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 65 | + erreur_squelette('L'.$e->getLine().': '.$e->getMessage().'<br />'.$code, [$page['source'], '', $e->getFile(), '', $GLOBALS['spip_lang']]); |
|
| 66 | 66 | $page['texte'] = '<!-- Erreur -->'; |
| 67 | 67 | } |
| 68 | 68 | ob_end_clean(); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -33,37 +33,37 @@ discard block |
||
| 33 | 33 | * Contenu HTML, avec boutons d'administrations et sa CSS |
| 34 | 34 | **/ |
| 35 | 35 | function affiche_boutons_admin($contenu) { |
| 36 | - include_spip('inc/filtres'); |
|
| 36 | + include_spip('inc/filtres'); |
|
| 37 | 37 | |
| 38 | - // Inserer le css d'admin |
|
| 39 | - $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | - . "' type='text/css' />\n"; |
|
| 41 | - if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | - $css .= "<link rel='stylesheet' href='" |
|
| 43 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | - } |
|
| 38 | + // Inserer le css d'admin |
|
| 39 | + $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | + . "' type='text/css' />\n"; |
|
| 41 | + if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | + $css .= "<link rel='stylesheet' href='" |
|
| 43 | + . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ( |
|
| 47 | - !($pos = stripos($contenu, '</head>')) |
|
| 48 | - && !($pos = stripos($contenu, '<body>')) |
|
| 49 | - ) { |
|
| 50 | - $pos = 0; |
|
| 51 | - } |
|
| 52 | - $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 46 | + if ( |
|
| 47 | + !($pos = stripos($contenu, '</head>')) |
|
| 48 | + && !($pos = stripos($contenu, '<body>')) |
|
| 49 | + ) { |
|
| 50 | + $pos = 0; |
|
| 51 | + } |
|
| 52 | + $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | - $boutons_admin = inclure_balise_dynamique( |
|
| 57 | - balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | - false |
|
| 59 | - ); |
|
| 60 | - if ( |
|
| 61 | - !($pos = strripos($contenu, '</body>')) |
|
| 62 | - && !($pos = strripos($contenu, '</html>')) |
|
| 63 | - ) { |
|
| 64 | - $pos = strlen($contenu); |
|
| 65 | - } |
|
| 55 | + // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | + $boutons_admin = inclure_balise_dynamique( |
|
| 57 | + balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | + false |
|
| 59 | + ); |
|
| 60 | + if ( |
|
| 61 | + !($pos = strripos($contenu, '</body>')) |
|
| 62 | + && !($pos = strripos($contenu, '</html>')) |
|
| 63 | + ) { |
|
| 64 | + $pos = strlen($contenu); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 68 | + return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 69 | 69 | } |
@@ -36,11 +36,11 @@ |
||
| 36 | 36 | include_spip('inc/filtres'); |
| 37 | 37 | |
| 38 | 38 | // Inserer le css d'admin |
| 39 | - $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 39 | + $css = "<link rel='stylesheet' href='".url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | 40 | . "' type='text/css' />\n"; |
| 41 | 41 | if ($f = find_in_path('spip_admin_perso.css')) { |
| 42 | 42 | $css .= "<link rel='stylesheet' href='" |
| 43 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 43 | + . url_absolue(direction_css($f))."' type='text/css' />\n"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ( |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('public/decompiler'); |
@@ -69,125 +69,125 @@ discard block |
||
| 69 | 69 | * - true si $opt 'erreurs' = 'reset' |
| 70 | 70 | **/ |
| 71 | 71 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 72 | - static $should_log; |
|
| 73 | - static $tableau_des_erreurs = []; |
|
| 74 | - |
|
| 75 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 76 | - if (isset($opt['erreurs'])) { |
|
| 77 | - if ($opt['erreurs'] == 'get') { |
|
| 78 | - return $tableau_des_erreurs; |
|
| 79 | - } |
|
| 80 | - if ($opt['erreurs'] == 'reset') { |
|
| 81 | - $tableau_des_erreurs = []; |
|
| 82 | - |
|
| 83 | - return true; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (is_null($should_log)) { |
|
| 88 | - $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Erreur ou appel final ? |
|
| 92 | - if ($message) { |
|
| 93 | - $message = debusquer_compose_message($message); |
|
| 94 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 95 | - set_request('var_mode', 'debug'); |
|
| 96 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 97 | - // Permettre a la compil de continuer |
|
| 98 | - if (is_object($lieu) && (!isset($lieu->code) || !$lieu->code)) { |
|
| 99 | - $lieu->code = "''"; |
|
| 100 | - } |
|
| 101 | - // loger si personne ne verra l'erreur |
|
| 102 | - if ($should_log) { |
|
| 103 | - debusquer_loger_erreur($message, $lieu); |
|
| 104 | - } |
|
| 105 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 106 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS && (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 107 | - if (!$urgence) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - // espace public ? |
|
| 112 | - if (empty($GLOBALS['debug_objets']['principal']) && isset($GLOBALS['fond'])) { |
|
| 113 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - include_spip('inc/autoriser'); |
|
| 117 | - if (!autoriser('debug')) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - include_spip('inc/headers'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - |
|
| 123 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 124 | - $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 125 | - $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 126 | - |
|
| 127 | - $self = str_replace("\\'", ''', (string) self()); |
|
| 128 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 129 | - |
|
| 130 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 131 | - . '<br />' |
|
| 132 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 133 | - |
|
| 134 | - if (!_DIR_RESTREINT || headers_sent()) { |
|
| 135 | - return $res; |
|
| 136 | - } |
|
| 137 | - if ($tableau_des_erreurs) { |
|
| 138 | - http_response_code(503); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - http_no_cache(); |
|
| 142 | - if (isset($_GET['var_profile'])) { |
|
| 143 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 144 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 145 | - } else { |
|
| 146 | - if (!$fonc) { |
|
| 147 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 148 | - } |
|
| 149 | - $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | - } |
|
| 151 | - if ($message === false) { |
|
| 152 | - lang_select(); |
|
| 153 | - |
|
| 154 | - return debusquer_entete($titre, $res); |
|
| 155 | - } else { |
|
| 156 | - echo debusquer_entete($titre, $res); |
|
| 157 | - } |
|
| 158 | - exit; |
|
| 72 | + static $should_log; |
|
| 73 | + static $tableau_des_erreurs = []; |
|
| 74 | + |
|
| 75 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 76 | + if (isset($opt['erreurs'])) { |
|
| 77 | + if ($opt['erreurs'] == 'get') { |
|
| 78 | + return $tableau_des_erreurs; |
|
| 79 | + } |
|
| 80 | + if ($opt['erreurs'] == 'reset') { |
|
| 81 | + $tableau_des_erreurs = []; |
|
| 82 | + |
|
| 83 | + return true; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (is_null($should_log)) { |
|
| 88 | + $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Erreur ou appel final ? |
|
| 92 | + if ($message) { |
|
| 93 | + $message = debusquer_compose_message($message); |
|
| 94 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 95 | + set_request('var_mode', 'debug'); |
|
| 96 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 97 | + // Permettre a la compil de continuer |
|
| 98 | + if (is_object($lieu) && (!isset($lieu->code) || !$lieu->code)) { |
|
| 99 | + $lieu->code = "''"; |
|
| 100 | + } |
|
| 101 | + // loger si personne ne verra l'erreur |
|
| 102 | + if ($should_log) { |
|
| 103 | + debusquer_loger_erreur($message, $lieu); |
|
| 104 | + } |
|
| 105 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 106 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS && (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 107 | + if (!$urgence) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + // espace public ? |
|
| 112 | + if (empty($GLOBALS['debug_objets']['principal']) && isset($GLOBALS['fond'])) { |
|
| 113 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + include_spip('inc/autoriser'); |
|
| 117 | + if (!autoriser('debug')) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + include_spip('inc/headers'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + |
|
| 123 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 124 | + $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 125 | + $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 126 | + |
|
| 127 | + $self = str_replace("\\'", ''', (string) self()); |
|
| 128 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 129 | + |
|
| 130 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 131 | + . '<br />' |
|
| 132 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 133 | + |
|
| 134 | + if (!_DIR_RESTREINT || headers_sent()) { |
|
| 135 | + return $res; |
|
| 136 | + } |
|
| 137 | + if ($tableau_des_erreurs) { |
|
| 138 | + http_response_code(503); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + http_no_cache(); |
|
| 142 | + if (isset($_GET['var_profile'])) { |
|
| 143 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 144 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 145 | + } else { |
|
| 146 | + if (!$fonc) { |
|
| 147 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 148 | + } |
|
| 149 | + $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | + } |
|
| 151 | + if ($message === false) { |
|
| 152 | + lang_select(); |
|
| 153 | + |
|
| 154 | + return debusquer_entete($titre, $res); |
|
| 155 | + } else { |
|
| 156 | + echo debusquer_entete($titre, $res); |
|
| 157 | + } |
|
| 158 | + exit; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | function debusquer_compose_message($msg) { |
| 162 | - if (is_array($msg)) { |
|
| 163 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 164 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 165 | - $msg = !is_numeric($msg[0]) && count($msg) == 2 ? _T($msg[0], $msg[1], 'spip-debug-arg') : debusquer_requete($msg); |
|
| 166 | - } |
|
| 167 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 168 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 169 | - $fond = $GLOBALS['fond'] ?? ''; |
|
| 170 | - // une erreur critique sort $message en array |
|
| 171 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 172 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 173 | - |
|
| 174 | - return $msg; |
|
| 162 | + if (is_array($msg)) { |
|
| 163 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 164 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 165 | + $msg = !is_numeric($msg[0]) && count($msg) == 2 ? _T($msg[0], $msg[1], 'spip-debug-arg') : debusquer_requete($msg); |
|
| 166 | + } |
|
| 167 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 168 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 169 | + $fond = $GLOBALS['fond'] ?? ''; |
|
| 170 | + // une erreur critique sort $message en array |
|
| 171 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 172 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 173 | + |
|
| 174 | + return $msg; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function debusquer_bandeau($erreurs) { |
| 178 | 178 | |
| 179 | - if (!empty($erreurs)) { |
|
| 180 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 179 | + if (!empty($erreurs)) { |
|
| 180 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 181 | 181 | |
| 182 | - return debusquer_navigation($erreurs, $n); |
|
| 183 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 184 | - include_spip('public/tracer'); |
|
| 185 | - [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 182 | + return debusquer_navigation($erreurs, $n); |
|
| 183 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 184 | + include_spip('public/tracer'); |
|
| 185 | + [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 186 | 186 | |
| 187 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 188 | - } else { |
|
| 189 | - return ''; |
|
| 190 | - } |
|
| 187 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 188 | + } else { |
|
| 189 | + return ''; |
|
| 190 | + } |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -197,63 +197,63 @@ discard block |
||
| 197 | 197 | * @return string Code HTML |
| 198 | 198 | **/ |
| 199 | 199 | function debusquer_contexte($env) { |
| 200 | - if (is_string($env) && is_array($env_tab = @unserialize($env))) { |
|
| 201 | - $env = $env_tab; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (!$env) { |
|
| 205 | - return ''; |
|
| 206 | - } |
|
| 207 | - $res = ''; |
|
| 208 | - foreach ($env as $nom => $valeur) { |
|
| 209 | - if (is_array($valeur)) { |
|
| 210 | - $valeur_simple = []; |
|
| 211 | - foreach ($valeur as $v) { |
|
| 212 | - if (is_array($v)) { |
|
| 213 | - $valeur_simple[] = 'array:' . count($v); |
|
| 214 | - } elseif (is_object($v)) { |
|
| 215 | - $valeur_simple[] = $v::class; |
|
| 216 | - } elseif (is_string($v)) { |
|
| 217 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 218 | - } else { |
|
| 219 | - $valeur_simple[] = $v; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - $n = count($valeur); |
|
| 223 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | - $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 225 | - } elseif (is_object($valeur)) { |
|
| 226 | - $valeur = $valeur::class; |
|
| 227 | - } elseif (is_string($valeur)) { |
|
| 228 | - $valeur = "'" . $valeur . "'"; |
|
| 229 | - } |
|
| 230 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 232 | - . "</td></tr>\n"; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 200 | + if (is_string($env) && is_array($env_tab = @unserialize($env))) { |
|
| 201 | + $env = $env_tab; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (!$env) { |
|
| 205 | + return ''; |
|
| 206 | + } |
|
| 207 | + $res = ''; |
|
| 208 | + foreach ($env as $nom => $valeur) { |
|
| 209 | + if (is_array($valeur)) { |
|
| 210 | + $valeur_simple = []; |
|
| 211 | + foreach ($valeur as $v) { |
|
| 212 | + if (is_array($v)) { |
|
| 213 | + $valeur_simple[] = 'array:' . count($v); |
|
| 214 | + } elseif (is_object($v)) { |
|
| 215 | + $valeur_simple[] = $v::class; |
|
| 216 | + } elseif (is_string($v)) { |
|
| 217 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 218 | + } else { |
|
| 219 | + $valeur_simple[] = $v; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + $n = count($valeur); |
|
| 223 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | + $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 225 | + } elseif (is_object($valeur)) { |
|
| 226 | + $valeur = $valeur::class; |
|
| 227 | + } elseif (is_string($valeur)) { |
|
| 228 | + $valeur = "'" . $valeur . "'"; |
|
| 229 | + } |
|
| 230 | + $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | + . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 232 | + . "</td></tr>\n"; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | function debusquer_loger_erreur($msg, $lieu) { |
| 240 | - $boucle = $ligne = $skel = ''; |
|
| 241 | - if (is_object($lieu)) { |
|
| 242 | - $ligne = ($lieu->ligne ?? ''); |
|
| 243 | - $boucle = ($lieu->id_boucle ?? ''); |
|
| 244 | - $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 245 | - } |
|
| 246 | - $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 247 | - if ($skel) { |
|
| 248 | - $msg .= " Squelette $skel"; |
|
| 249 | - } |
|
| 250 | - if ($boucle) { |
|
| 251 | - $msg .= " Boucle $boucle"; |
|
| 252 | - } |
|
| 253 | - if ($ligne) { |
|
| 254 | - $msg .= " L$ligne"; |
|
| 255 | - } |
|
| 256 | - spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 240 | + $boucle = $ligne = $skel = ''; |
|
| 241 | + if (is_object($lieu)) { |
|
| 242 | + $ligne = ($lieu->ligne ?? ''); |
|
| 243 | + $boucle = ($lieu->id_boucle ?? ''); |
|
| 244 | + $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 245 | + } |
|
| 246 | + $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 247 | + if ($skel) { |
|
| 248 | + $msg .= " Squelette $skel"; |
|
| 249 | + } |
|
| 250 | + if ($boucle) { |
|
| 251 | + $msg .= " Boucle $boucle"; |
|
| 252 | + } |
|
| 253 | + if ($ligne) { |
|
| 254 | + $msg .= " L$ligne"; |
|
| 255 | + } |
|
| 256 | + spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -262,66 +262,66 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 264 | 264 | |
| 265 | - if (_request('exec') == 'valider_xml') { |
|
| 266 | - return ''; |
|
| 267 | - } |
|
| 268 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 269 | - $res = ''; |
|
| 270 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 271 | - foreach ($tableau as $i => $err) { |
|
| 272 | - $boucle = $ligne = $skel = ''; |
|
| 273 | - [$msg, $lieu] = $err; |
|
| 274 | - if (is_object($lieu)) { |
|
| 275 | - $ligne = $lieu->ligne; |
|
| 276 | - $boucle = empty($lieu->id_boucle) ? '' : $lieu->id_boucle; |
|
| 277 | - if (isset($lieu->descr['nom'])) { |
|
| 278 | - $nom_code = $lieu->descr['nom']; |
|
| 279 | - $skel = $lieu->descr['sourcefile']; |
|
| 280 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 281 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 282 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 283 | - if ($boucle) { |
|
| 284 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - $j = ($i + 1); |
|
| 291 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 292 | - . $j |
|
| 293 | - . " </td><td style='text-align: left'>" |
|
| 294 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 295 | - . "</td><td style='text-align: left'>" |
|
| 296 | - . ($skel ?: ' / ') |
|
| 297 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 298 | - . ($boucle ?: ' / ') |
|
| 299 | - . "</td><td style='text-align: right'>" |
|
| 300 | - . $ligne |
|
| 301 | - . "</td></tr>\n"; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return "\n<table id='$id'>" |
|
| 305 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 306 | - . $caption[0] |
|
| 265 | + if (_request('exec') == 'valider_xml') { |
|
| 266 | + return ''; |
|
| 267 | + } |
|
| 268 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 269 | + $res = ''; |
|
| 270 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 271 | + foreach ($tableau as $i => $err) { |
|
| 272 | + $boucle = $ligne = $skel = ''; |
|
| 273 | + [$msg, $lieu] = $err; |
|
| 274 | + if (is_object($lieu)) { |
|
| 275 | + $ligne = $lieu->ligne; |
|
| 276 | + $boucle = empty($lieu->id_boucle) ? '' : $lieu->id_boucle; |
|
| 277 | + if (isset($lieu->descr['nom'])) { |
|
| 278 | + $nom_code = $lieu->descr['nom']; |
|
| 279 | + $skel = $lieu->descr['sourcefile']; |
|
| 280 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 281 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 282 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 283 | + if ($boucle) { |
|
| 284 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + $j = ($i + 1); |
|
| 291 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 292 | + . $j |
|
| 293 | + . " </td><td style='text-align: left'>" |
|
| 294 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 295 | + . "</td><td style='text-align: left'>" |
|
| 296 | + . ($skel ?: ' / ') |
|
| 297 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 298 | + . ($boucle ?: ' / ') |
|
| 299 | + . "</td><td style='text-align: right'>" |
|
| 300 | + . $ligne |
|
| 301 | + . "</td></tr>\n"; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return "\n<table id='$id'>" |
|
| 305 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 306 | + . $caption[0] |
|
| 307 | 307 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 308 | 308 | # aider('erreur_compilation'), |
| 309 | - . '</caption>' |
|
| 310 | - // fausse caption du chrono (mais vraie nav) |
|
| 311 | - . (empty($caption[1]) ? '' : $caption[1]) |
|
| 312 | - . '<tr><th>' |
|
| 313 | - . _T('numero') |
|
| 314 | - . '</th><th>' |
|
| 315 | - . _T('public:message') |
|
| 316 | - . '</th><th>' |
|
| 317 | - . _T('squelette') |
|
| 318 | - . '</th><th>' |
|
| 319 | - . _T('zbug_boucle') |
|
| 320 | - . '</th><th>' |
|
| 321 | - . _T('ligne') |
|
| 322 | - . '</th></tr>' |
|
| 323 | - . $res |
|
| 324 | - . '</table>'; |
|
| 309 | + . '</caption>' |
|
| 310 | + // fausse caption du chrono (mais vraie nav) |
|
| 311 | + . (empty($caption[1]) ? '' : $caption[1]) |
|
| 312 | + . '<tr><th>' |
|
| 313 | + . _T('numero') |
|
| 314 | + . '</th><th>' |
|
| 315 | + . _T('public:message') |
|
| 316 | + . '</th><th>' |
|
| 317 | + . _T('squelette') |
|
| 318 | + . '</th><th>' |
|
| 319 | + . _T('zbug_boucle') |
|
| 320 | + . '</th><th>' |
|
| 321 | + . _T('ligne') |
|
| 322 | + . '</th></tr>' |
|
| 323 | + . $res |
|
| 324 | + . '</table>'; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -341,518 +341,518 @@ discard block |
||
| 341 | 341 | * ou un tableau si l'erreur est critique |
| 342 | 342 | **/ |
| 343 | 343 | function debusquer_requete($message) { |
| 344 | - [$errno, $msg, $query] = $message; |
|
| 345 | - |
|
| 346 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 347 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 348 | - if (preg_match(',err(no|code):?[[:space:]]*(\d+),i', (string) $msg, $regs)) { |
|
| 349 | - $errno = $regs[2]; |
|
| 350 | - } elseif ( |
|
| 351 | - is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | - && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', (string) $msg, $regs) |
|
| 353 | - ) { |
|
| 354 | - $errno = $regs[1]; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // Erreur systeme |
|
| 358 | - if (is_numeric($errno) && $errno > 0 && $errno < 200) { |
|
| 359 | - $retour = '<tt><br /><br /><blink>' |
|
| 360 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 361 | - . "</blink><br />\n<b>" |
|
| 362 | - . _T( |
|
| 363 | - 'info_erreur_systeme2', |
|
| 364 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 365 | - ) |
|
| 366 | - . '</b><br />'; |
|
| 367 | - spip_log("Erreur systeme $errno"); |
|
| 368 | - |
|
| 369 | - return [$retour, '']; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Requete erronee |
|
| 373 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 374 | - . spip_htmlspecialchars($msg) |
|
| 375 | - . "\n<br /><span style='color: red'><b>" |
|
| 376 | - . spip_htmlspecialchars($query) |
|
| 377 | - . '</b></span></tt><br />'; |
|
| 378 | - |
|
| 379 | - //. aider('erreur_mysql'); |
|
| 380 | - |
|
| 381 | - return $err; |
|
| 344 | + [$errno, $msg, $query] = $message; |
|
| 345 | + |
|
| 346 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 347 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 348 | + if (preg_match(',err(no|code):?[[:space:]]*(\d+),i', (string) $msg, $regs)) { |
|
| 349 | + $errno = $regs[2]; |
|
| 350 | + } elseif ( |
|
| 351 | + is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | + && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', (string) $msg, $regs) |
|
| 353 | + ) { |
|
| 354 | + $errno = $regs[1]; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // Erreur systeme |
|
| 358 | + if (is_numeric($errno) && $errno > 0 && $errno < 200) { |
|
| 359 | + $retour = '<tt><br /><br /><blink>' |
|
| 360 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 361 | + . "</blink><br />\n<b>" |
|
| 362 | + . _T( |
|
| 363 | + 'info_erreur_systeme2', |
|
| 364 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 365 | + ) |
|
| 366 | + . '</b><br />'; |
|
| 367 | + spip_log("Erreur systeme $errno"); |
|
| 368 | + |
|
| 369 | + return [$retour, '']; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Requete erronee |
|
| 373 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 374 | + . spip_htmlspecialchars($msg) |
|
| 375 | + . "\n<br /><span style='color: red'><b>" |
|
| 376 | + . spip_htmlspecialchars($query) |
|
| 377 | + . '</b></span></tt><br />'; |
|
| 378 | + |
|
| 379 | + //. aider('erreur_mysql'); |
|
| 380 | + |
|
| 381 | + return $err; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
| 385 | 385 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 386 | 386 | |
| 387 | - $id = $nom . $boucle; |
|
| 388 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 389 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 390 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', (string) $v[0], $r)) { |
|
| 391 | - $y = substr_count((string) $v[0], "\n"); |
|
| 392 | - } else { |
|
| 393 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 394 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 395 | - } else // inclusion |
|
| 396 | - { |
|
| 397 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 398 | - } |
|
| 399 | - $y = substr_count((string) $incl, "\n") |
|
| 400 | - + substr_count($r[1], "\n") |
|
| 401 | - + substr_count($r[3], "\n"); |
|
| 402 | - } |
|
| 403 | - if ($n <= ($y + $debut)) { |
|
| 404 | - if ($v[1][0] == '?') { |
|
| 405 | - return trouve_boucle_debug($n, $nom, $debut, substr((string) $v[1], 1)); |
|
| 406 | - } elseif ($v[1][0] == '!') { |
|
| 407 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 408 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 413 | - } |
|
| 414 | - $debut += $y; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - return [$nom, $boucle, $n - $debut]; |
|
| 387 | + $id = $nom . $boucle; |
|
| 388 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 389 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 390 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', (string) $v[0], $r)) { |
|
| 391 | + $y = substr_count((string) $v[0], "\n"); |
|
| 392 | + } else { |
|
| 393 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 394 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 395 | + } else // inclusion |
|
| 396 | + { |
|
| 397 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 398 | + } |
|
| 399 | + $y = substr_count((string) $incl, "\n") |
|
| 400 | + + substr_count($r[1], "\n") |
|
| 401 | + + substr_count($r[3], "\n"); |
|
| 402 | + } |
|
| 403 | + if ($n <= ($y + $debut)) { |
|
| 404 | + if ($v[1][0] == '?') { |
|
| 405 | + return trouve_boucle_debug($n, $nom, $debut, substr((string) $v[1], 1)); |
|
| 406 | + } elseif ($v[1][0] == '!') { |
|
| 407 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 408 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 413 | + } |
|
| 414 | + $debut += $y; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + return [$nom, $boucle, $n - $debut]; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | function trouve_squelette_inclus($script) { |
| 422 | 422 | |
| 423 | - preg_match('/include\(.(.*).php3?.\);/', (string) $script, $reg); |
|
| 424 | - // si le script X.php n'est pas ecrire/public.php |
|
| 425 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 426 | - // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 427 | - // a defaut on cherche le param 'page' |
|
| 428 | - if ( |
|
| 429 | - $reg[1] == 'ecrire/public' |
|
| 430 | - && !preg_match("/'fond' => '([^']*)'/", (string) $script, $reg) |
|
| 431 | - && !preg_match("/'param' => '([^']*)'/", (string) $script, $reg) |
|
| 432 | - ) { |
|
| 433 | - $reg[1] = 'inconnu'; |
|
| 434 | - } |
|
| 435 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 436 | - |
|
| 437 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 438 | - if (preg_match($incl, (string) $v)) { |
|
| 439 | - return $k; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return ''; |
|
| 423 | + preg_match('/include\(.(.*).php3?.\);/', (string) $script, $reg); |
|
| 424 | + // si le script X.php n'est pas ecrire/public.php |
|
| 425 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 426 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 427 | + // a defaut on cherche le param 'page' |
|
| 428 | + if ( |
|
| 429 | + $reg[1] == 'ecrire/public' |
|
| 430 | + && !preg_match("/'fond' => '([^']*)'/", (string) $script, $reg) |
|
| 431 | + && !preg_match("/'param' => '([^']*)'/", (string) $script, $reg) |
|
| 432 | + ) { |
|
| 433 | + $reg[1] = 'inconnu'; |
|
| 434 | + } |
|
| 435 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 436 | + |
|
| 437 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 438 | + if (preg_match($incl, (string) $v)) { |
|
| 439 | + return $k; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return ''; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | function reference_boucle_debug($n, $nom, $self) { |
| 447 | - [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 448 | - |
|
| 449 | - if (!$boucle) { |
|
| 450 | - return $ligne |
|
| 451 | - ? ' (' . |
|
| 452 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | - _T('squelette_ligne')) . |
|
| 454 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
|
| 455 | - : ''; |
|
| 456 | - } else { |
|
| 457 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 458 | - |
|
| 459 | - return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | - " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | - } |
|
| 447 | + [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 448 | + |
|
| 449 | + if (!$boucle) { |
|
| 450 | + return $ligne |
|
| 451 | + ? ' (' . |
|
| 452 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | + _T('squelette_ligne')) . |
|
| 454 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
|
| 455 | + : ''; |
|
| 456 | + } else { |
|
| 457 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 458 | + |
|
| 459 | + return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | + " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | + } |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // affiche un texte avec numero de ligne et ancre. |
| 465 | 465 | |
| 466 | 466 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 467 | 467 | |
| 468 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 469 | - if ($var_mode_ligne) { |
|
| 470 | - $fautifs[] = [$var_mode_ligne]; |
|
| 471 | - } |
|
| 472 | - $res = ''; |
|
| 473 | - |
|
| 474 | - $s = highlight_string($texte, true); |
|
| 475 | - if (str_starts_with($s, '<code>')) { |
|
| 476 | - $s = substr($s, 6); |
|
| 477 | - $res = '<code>'; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $s = preg_replace( |
|
| 481 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 482 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 483 | - $s |
|
| 484 | - ); |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - $tableau = explode('<br />', $s); |
|
| 488 | - |
|
| 489 | - $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" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 490 | - |
|
| 491 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 492 | - $formaterr = 'color: red;'; |
|
| 493 | - $i = 1; |
|
| 494 | - $flignes = []; |
|
| 495 | - $loc = [0, 0]; |
|
| 496 | - foreach ($fautifs as $lc) { |
|
| 497 | - if (is_array($lc)) { |
|
| 498 | - $l = array_shift($lc); |
|
| 499 | - $flignes[$l] = $lc; |
|
| 500 | - } else { |
|
| 501 | - $flignes[$lc] = $loc; |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - $ancre = md5((string) $texte); |
|
| 506 | - foreach ($tableau as $ligne) { |
|
| 507 | - if (isset($flignes[$i])) { |
|
| 508 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 509 | - $indexmesg = $flignes[$i][1]; |
|
| 510 | - $err = textebrut($flignes[$i][2]); |
|
| 511 | - // tentative de pointer sur la colonne fautive; |
|
| 512 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 513 | - // $m = $flignes[$i][0]; |
|
| 514 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 515 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 516 | - $bg = $formaterr; |
|
| 517 | - } else { |
|
| 518 | - $indexmesg = $ancre; |
|
| 519 | - $err = $bg = ''; |
|
| 520 | - } |
|
| 521 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 522 | - $i++; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return "<div id='T$ancre'>" |
|
| 526 | - . '<div onclick="' |
|
| 527 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 528 | - . '" title="' |
|
| 529 | - . _T('masquer_colonne') |
|
| 530 | - . '" style="cursor: pointer;">' |
|
| 531 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 532 | - . '</div> |
|
| 468 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 469 | + if ($var_mode_ligne) { |
|
| 470 | + $fautifs[] = [$var_mode_ligne]; |
|
| 471 | + } |
|
| 472 | + $res = ''; |
|
| 473 | + |
|
| 474 | + $s = highlight_string($texte, true); |
|
| 475 | + if (str_starts_with($s, '<code>')) { |
|
| 476 | + $s = substr($s, 6); |
|
| 477 | + $res = '<code>'; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $s = preg_replace( |
|
| 481 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 482 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 483 | + $s |
|
| 484 | + ); |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + $tableau = explode('<br />', $s); |
|
| 488 | + |
|
| 489 | + $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" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 490 | + |
|
| 491 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 492 | + $formaterr = 'color: red;'; |
|
| 493 | + $i = 1; |
|
| 494 | + $flignes = []; |
|
| 495 | + $loc = [0, 0]; |
|
| 496 | + foreach ($fautifs as $lc) { |
|
| 497 | + if (is_array($lc)) { |
|
| 498 | + $l = array_shift($lc); |
|
| 499 | + $flignes[$l] = $lc; |
|
| 500 | + } else { |
|
| 501 | + $flignes[$lc] = $loc; |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + $ancre = md5((string) $texte); |
|
| 506 | + foreach ($tableau as $ligne) { |
|
| 507 | + if (isset($flignes[$i])) { |
|
| 508 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 509 | + $indexmesg = $flignes[$i][1]; |
|
| 510 | + $err = textebrut($flignes[$i][2]); |
|
| 511 | + // tentative de pointer sur la colonne fautive; |
|
| 512 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 513 | + // $m = $flignes[$i][0]; |
|
| 514 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 515 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 516 | + $bg = $formaterr; |
|
| 517 | + } else { |
|
| 518 | + $indexmesg = $ancre; |
|
| 519 | + $err = $bg = ''; |
|
| 520 | + } |
|
| 521 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 522 | + $i++; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return "<div id='T$ancre'>" |
|
| 526 | + . '<div onclick="' |
|
| 527 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 528 | + . '" title="' |
|
| 529 | + . _T('masquer_colonne') |
|
| 530 | + . '" style="cursor: pointer;">' |
|
| 531 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 532 | + . '</div> |
|
| 533 | 533 | ' . $res . "</div>\n"; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // l'environnement graphique du debuggueur |
| 537 | 537 | |
| 538 | 538 | function debusquer_squelette($fonc, $mode, $self) { |
| 539 | - $legend = null; |
|
| 540 | - $texte = ''; |
|
| 541 | - |
|
| 542 | - if ($mode !== 'validation') { |
|
| 543 | - if (isset($GLOBALS['debug_objets']['sourcefile']) && $GLOBALS['debug_objets']['sourcefile']) { |
|
| 544 | - $res = "<div id='spip-boucles'>\n" |
|
| 545 | - . debusquer_navigation_squelettes($self) |
|
| 546 | - . '</div>'; |
|
| 547 | - } else { |
|
| 548 | - $res = ''; |
|
| 549 | - } |
|
| 550 | - if ($fonc) { |
|
| 551 | - $id = " id='$fonc'"; |
|
| 552 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 553 | - [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 554 | - $texte .= $res2; |
|
| 555 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | - $legend = _T('zbug_' . $mode); |
|
| 557 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 558 | - $texte = ancre_texte($texte, ['', '']); |
|
| 559 | - } |
|
| 560 | - } else { |
|
| 561 | - if (strlen(trim($res))) { |
|
| 562 | - 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>"; |
|
| 563 | - } else { |
|
| 564 | - // cas de l'appel sur erreur: montre la page |
|
| 565 | - return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - } else { |
|
| 569 | - $valider = charger_fonction('valider', 'xml'); |
|
| 570 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 571 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 572 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 573 | - [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 574 | - if ($err === false) { |
|
| 575 | - $err = _T('impossible'); |
|
| 576 | - } elseif ($err === true) { |
|
| 577 | - $err = _T('correcte'); |
|
| 578 | - } else { |
|
| 579 | - $err = ": $err"; |
|
| 580 | - } |
|
| 581 | - $legend = _T('validation') . ' ' . $err; |
|
| 582 | - $res = $id = ''; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - return trim((string) $texte) |
|
| 586 | - ? "<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" |
|
| 587 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 588 | - . "<a href='" . $self . '#f_' . substr((string) $fonc, 0, 37) . "'> ↑ " |
|
| 589 | - . ($legend ?: $mode) |
|
| 590 | - . '</a></legend>' |
|
| 591 | - . $texte |
|
| 592 | - . '</fieldset></div>' |
|
| 593 | - . '</div>' |
|
| 594 | - : ''; |
|
| 539 | + $legend = null; |
|
| 540 | + $texte = ''; |
|
| 541 | + |
|
| 542 | + if ($mode !== 'validation') { |
|
| 543 | + if (isset($GLOBALS['debug_objets']['sourcefile']) && $GLOBALS['debug_objets']['sourcefile']) { |
|
| 544 | + $res = "<div id='spip-boucles'>\n" |
|
| 545 | + . debusquer_navigation_squelettes($self) |
|
| 546 | + . '</div>'; |
|
| 547 | + } else { |
|
| 548 | + $res = ''; |
|
| 549 | + } |
|
| 550 | + if ($fonc) { |
|
| 551 | + $id = " id='$fonc'"; |
|
| 552 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 553 | + [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 554 | + $texte .= $res2; |
|
| 555 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | + $legend = _T('zbug_' . $mode); |
|
| 557 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 558 | + $texte = ancre_texte($texte, ['', '']); |
|
| 559 | + } |
|
| 560 | + } else { |
|
| 561 | + if (strlen(trim($res))) { |
|
| 562 | + 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>"; |
|
| 563 | + } else { |
|
| 564 | + // cas de l'appel sur erreur: montre la page |
|
| 565 | + return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } else { |
|
| 569 | + $valider = charger_fonction('valider', 'xml'); |
|
| 570 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 571 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 572 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 573 | + [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 574 | + if ($err === false) { |
|
| 575 | + $err = _T('impossible'); |
|
| 576 | + } elseif ($err === true) { |
|
| 577 | + $err = _T('correcte'); |
|
| 578 | + } else { |
|
| 579 | + $err = ": $err"; |
|
| 580 | + } |
|
| 581 | + $legend = _T('validation') . ' ' . $err; |
|
| 582 | + $res = $id = ''; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + return trim((string) $texte) |
|
| 586 | + ? "<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" |
|
| 587 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 588 | + . "<a href='" . $self . '#f_' . substr((string) $fonc, 0, 37) . "'> ↑ " |
|
| 589 | + . ($legend ?: $mode) |
|
| 590 | + . '</a></legend>' |
|
| 591 | + . $texte |
|
| 592 | + . '</fieldset></div>' |
|
| 593 | + . '</div>' |
|
| 594 | + : ''; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | |
| 598 | 598 | function emboite_texte($res, $fonc = '', $self = '') { |
| 599 | - $errs = $res->err; |
|
| 600 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 601 | - |
|
| 602 | - if (!$texte && !$errs) { |
|
| 603 | - return [ancre_texte('', ['', '']), false]; |
|
| 604 | - } |
|
| 605 | - if (!$errs) { |
|
| 606 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 610 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 611 | - $encore = count_occ($errs); |
|
| 612 | - $encore2 = []; |
|
| 613 | - $fautifs = []; |
|
| 614 | - |
|
| 615 | - $err = '<tr><th>' |
|
| 616 | - . _T('numero') |
|
| 617 | - . '</th><th>' |
|
| 618 | - . _T('occurence') |
|
| 619 | - . '</th><th>' |
|
| 620 | - . _T('ligne') |
|
| 621 | - . '</th><th>' |
|
| 622 | - . _T('colonne') |
|
| 623 | - . '</th><th>' |
|
| 624 | - . _T('erreur') |
|
| 625 | - . '</th></tr>'; |
|
| 626 | - |
|
| 627 | - $i = 0; |
|
| 628 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 629 | - foreach ($errs as $r) { |
|
| 630 | - $i++; |
|
| 631 | - [$msg, $ligne, $col] = $r; |
|
| 632 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 633 | - if (isset($encore2[$msg])) { |
|
| 634 | - $ref = ++$encore2[$msg]; |
|
| 635 | - } else { |
|
| 636 | - $encore2[$msg] = $ref = 1; |
|
| 637 | - } |
|
| 638 | - $err .= "<tr style='background-color: " |
|
| 639 | - . $colors[$i % 2] |
|
| 640 | - . "'><td $style><a href='#debut_err'>" |
|
| 641 | - . $i |
|
| 642 | - . "</a></td><td $style>" |
|
| 643 | - . "$ref/$encore[$msg]</td>" |
|
| 644 | - . "<td $style><a href='#L" |
|
| 645 | - . $ligne |
|
| 646 | - . "' id='T$i'>" |
|
| 647 | - . $ligne |
|
| 648 | - . "</a></td><td $style>" |
|
| 649 | - . $col |
|
| 650 | - . "</td><td>$msg</td></tr>\n"; |
|
| 651 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 652 | - } |
|
| 653 | - $err = "<h2 style='text-align: center'>" |
|
| 654 | - . $i |
|
| 655 | - . "<a href='#fin_err'>" |
|
| 656 | - . ' ' . _T('erreur_texte') |
|
| 657 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 658 | - . $err |
|
| 659 | - . " </table><a id='fin_err'></a>"; |
|
| 660 | - |
|
| 661 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 662 | - } else { |
|
| 663 | - [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 664 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 665 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 666 | - $err = $msg . |
|
| 667 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 669 | - |
|
| 670 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 671 | - } |
|
| 599 | + $errs = $res->err; |
|
| 600 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 601 | + |
|
| 602 | + if (!$texte && !$errs) { |
|
| 603 | + return [ancre_texte('', ['', '']), false]; |
|
| 604 | + } |
|
| 605 | + if (!$errs) { |
|
| 606 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 610 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 611 | + $encore = count_occ($errs); |
|
| 612 | + $encore2 = []; |
|
| 613 | + $fautifs = []; |
|
| 614 | + |
|
| 615 | + $err = '<tr><th>' |
|
| 616 | + . _T('numero') |
|
| 617 | + . '</th><th>' |
|
| 618 | + . _T('occurence') |
|
| 619 | + . '</th><th>' |
|
| 620 | + . _T('ligne') |
|
| 621 | + . '</th><th>' |
|
| 622 | + . _T('colonne') |
|
| 623 | + . '</th><th>' |
|
| 624 | + . _T('erreur') |
|
| 625 | + . '</th></tr>'; |
|
| 626 | + |
|
| 627 | + $i = 0; |
|
| 628 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 629 | + foreach ($errs as $r) { |
|
| 630 | + $i++; |
|
| 631 | + [$msg, $ligne, $col] = $r; |
|
| 632 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 633 | + if (isset($encore2[$msg])) { |
|
| 634 | + $ref = ++$encore2[$msg]; |
|
| 635 | + } else { |
|
| 636 | + $encore2[$msg] = $ref = 1; |
|
| 637 | + } |
|
| 638 | + $err .= "<tr style='background-color: " |
|
| 639 | + . $colors[$i % 2] |
|
| 640 | + . "'><td $style><a href='#debut_err'>" |
|
| 641 | + . $i |
|
| 642 | + . "</a></td><td $style>" |
|
| 643 | + . "$ref/$encore[$msg]</td>" |
|
| 644 | + . "<td $style><a href='#L" |
|
| 645 | + . $ligne |
|
| 646 | + . "' id='T$i'>" |
|
| 647 | + . $ligne |
|
| 648 | + . "</a></td><td $style>" |
|
| 649 | + . $col |
|
| 650 | + . "</td><td>$msg</td></tr>\n"; |
|
| 651 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 652 | + } |
|
| 653 | + $err = "<h2 style='text-align: center'>" |
|
| 654 | + . $i |
|
| 655 | + . "<a href='#fin_err'>" |
|
| 656 | + . ' ' . _T('erreur_texte') |
|
| 657 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 658 | + . $err |
|
| 659 | + . " </table><a id='fin_err'></a>"; |
|
| 660 | + |
|
| 661 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 662 | + } else { |
|
| 663 | + [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 664 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 665 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 666 | + $err = $msg . |
|
| 667 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 669 | + |
|
| 670 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 671 | + } |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function count_occ($regs) { |
| 675 | - $encore = []; |
|
| 676 | - foreach ($regs as $r) { |
|
| 677 | - if (isset($encore[$r[0]])) { |
|
| 678 | - $encore[$r[0]]++; |
|
| 679 | - } else { |
|
| 680 | - $encore[$r[0]] = 1; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - return $encore; |
|
| 675 | + $encore = []; |
|
| 676 | + foreach ($regs as $r) { |
|
| 677 | + if (isset($encore[$r[0]])) { |
|
| 678 | + $encore[$r[0]]++; |
|
| 679 | + } else { |
|
| 680 | + $encore[$r[0]] = 1; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + return $encore; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | function debusquer_navigation_squelettes($self) { |
| 688 | 688 | |
| 689 | - $res = ''; |
|
| 690 | - $boucles = empty($GLOBALS['debug_objets']['boucle']) ? '' : $GLOBALS['debug_objets']['boucle']; |
|
| 691 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 692 | - $t_skel = _T('squelette'); |
|
| 693 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 694 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 695 | - $nav = $boucles ? debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile) : ''; |
|
| 696 | - $temps = isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? _T( |
|
| 697 | - 'zbug_profile', |
|
| 698 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 699 | - ) : ''; |
|
| 700 | - |
|
| 701 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 702 | - . $t_skel |
|
| 703 | - . ' ' |
|
| 704 | - . $sourcefile |
|
| 705 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 706 | - . $t_skel |
|
| 707 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 708 | - . _T('zbug_resultat') |
|
| 709 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 710 | - . _T('zbug_code') |
|
| 711 | - . "</a>\n<a href='" |
|
| 712 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', (string) $self) |
|
| 713 | - . "'>" |
|
| 714 | - . _T('zbug_calcul') |
|
| 715 | - . '</a></legend>' |
|
| 716 | - . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 717 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 718 | - . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
|
| 719 | - . "</fieldset>\n"; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return $res; |
|
| 689 | + $res = ''; |
|
| 690 | + $boucles = empty($GLOBALS['debug_objets']['boucle']) ? '' : $GLOBALS['debug_objets']['boucle']; |
|
| 691 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 692 | + $t_skel = _T('squelette'); |
|
| 693 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 694 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 695 | + $nav = $boucles ? debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile) : ''; |
|
| 696 | + $temps = isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? _T( |
|
| 697 | + 'zbug_profile', |
|
| 698 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 699 | + ) : ''; |
|
| 700 | + |
|
| 701 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 702 | + . $t_skel |
|
| 703 | + . ' ' |
|
| 704 | + . $sourcefile |
|
| 705 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 706 | + . $t_skel |
|
| 707 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 708 | + . _T('zbug_resultat') |
|
| 709 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 710 | + . _T('zbug_code') |
|
| 711 | + . "</a>\n<a href='" |
|
| 712 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', (string) $self) |
|
| 713 | + . "'>" |
|
| 714 | + . _T('zbug_calcul') |
|
| 715 | + . '</a></legend>' |
|
| 716 | + . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 717 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 718 | + . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
|
| 719 | + . "</fieldset>\n"; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return $res; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 726 | - $i = 0; |
|
| 727 | - $res = ''; |
|
| 728 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 729 | - $gram = preg_match('/[.](\w+)$/', (string) $nom_source, $r) ? $r[1] : ''; |
|
| 730 | - |
|
| 731 | - foreach ($boucles as $objet => $boucle) { |
|
| 732 | - if (str_starts_with((string) $objet, (string) $nom_skel)) { |
|
| 733 | - $i++; |
|
| 734 | - $nom = $boucle->id_boucle; |
|
| 735 | - $req = $boucle->type_requete; |
|
| 736 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 737 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | - |
|
| 739 | - $res .= "\n<tr style='background-color: " . |
|
| 740 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | - "'><td align='right'>$i</td><td>\n" . |
|
| 742 | - "<a class='debug_link_boucle' href='" . |
|
| 743 | - $self2 . |
|
| 744 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | - _T('zbug_boucle') . |
|
| 746 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | - $self2 . |
|
| 748 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | - _T('zbug_resultat') . |
|
| 750 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | - $self2 . |
|
| 752 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | - _T('zbug_code') . |
|
| 754 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | - "'>" . |
|
| 757 | - _T('zbug_calcul') . |
|
| 758 | - "</a></td><td>\n" . |
|
| 759 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | - "</td><td>\n" . |
|
| 761 | - $req . |
|
| 762 | - "</td><td>\n" . |
|
| 763 | - spip_htmlspecialchars($crit) . |
|
| 764 | - '</td></tr>'; |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - return $res; |
|
| 726 | + $i = 0; |
|
| 727 | + $res = ''; |
|
| 728 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 729 | + $gram = preg_match('/[.](\w+)$/', (string) $nom_source, $r) ? $r[1] : ''; |
|
| 730 | + |
|
| 731 | + foreach ($boucles as $objet => $boucle) { |
|
| 732 | + if (str_starts_with((string) $objet, (string) $nom_skel)) { |
|
| 733 | + $i++; |
|
| 734 | + $nom = $boucle->id_boucle; |
|
| 735 | + $req = $boucle->type_requete; |
|
| 736 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 737 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | + |
|
| 739 | + $res .= "\n<tr style='background-color: " . |
|
| 740 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | + "'><td align='right'>$i</td><td>\n" . |
|
| 742 | + "<a class='debug_link_boucle' href='" . |
|
| 743 | + $self2 . |
|
| 744 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | + _T('zbug_boucle') . |
|
| 746 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | + $self2 . |
|
| 748 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | + _T('zbug_resultat') . |
|
| 750 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | + $self2 . |
|
| 752 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | + _T('zbug_code') . |
|
| 754 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | + "'>" . |
|
| 757 | + _T('zbug_calcul') . |
|
| 758 | + "</a></td><td>\n" . |
|
| 759 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | + "</td><td>\n" . |
|
| 761 | + $req . |
|
| 762 | + "</td><td>\n" . |
|
| 763 | + spip_htmlspecialchars($crit) . |
|
| 764 | + '</td></tr>'; |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + return $res; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function debusquer_source($objet, $affiche) { |
| 772 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 773 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 774 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 775 | - } else { |
|
| 776 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 777 | - } |
|
| 778 | - $res2 = ''; |
|
| 779 | - |
|
| 780 | - if ($affiche == 'resultat') { |
|
| 781 | - $legend = $nom; |
|
| 782 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 783 | - if (function_exists('_mysql_traite_query')) { |
|
| 784 | - $c = strtolower(_request('connect') ?? ''); |
|
| 785 | - $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 786 | - $req = _mysql_traite_query($req, '', $c); |
|
| 787 | - } |
|
| 788 | - // permettre le copier/coller facile |
|
| 789 | - // $res = ancre_texte($req, array(), true); |
|
| 790 | - $res = "<div id='T" . md5((string) $req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 791 | - // formatage et affichage des resultats bruts de la requete |
|
| 792 | - $ress_req = spip_query($req); |
|
| 793 | - $brut_sql = ''; |
|
| 794 | - $num = 1; |
|
| 795 | - // eviter l'affichage de milliers de lignes |
|
| 796 | - // personnalisation possible dans mes_options |
|
| 797 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 798 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 799 | - if ($num <= $max_aff) { |
|
| 800 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 801 | - $brut_sql .= '<p>'; |
|
| 802 | - foreach ($retours_sql as $key => $val) { |
|
| 803 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 804 | - } |
|
| 805 | - $brut_sql .= '</p>'; |
|
| 806 | - } |
|
| 807 | - $num++; |
|
| 808 | - } |
|
| 809 | - $res2 = interdire_scripts($brut_sql); |
|
| 810 | - foreach ($quoi as $view) { |
|
| 811 | - // ne pas afficher les $contexte_inclus |
|
| 812 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', (string) $view); |
|
| 813 | - if ($view) { |
|
| 814 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - } elseif ($affiche == 'code') { |
|
| 818 | - $legend = $nom; |
|
| 819 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 820 | - } elseif ($affiche == 'boucle') { |
|
| 821 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 822 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 823 | - $gram = preg_match('/^([^_]+)_/', (string) $objet, $r) ? $r[1] : ''; |
|
| 824 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 825 | - } elseif ($affiche == 'squelette') { |
|
| 826 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 827 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return [$legend, $res, $res2]; |
|
| 772 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 773 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 774 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 775 | + } else { |
|
| 776 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 777 | + } |
|
| 778 | + $res2 = ''; |
|
| 779 | + |
|
| 780 | + if ($affiche == 'resultat') { |
|
| 781 | + $legend = $nom; |
|
| 782 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 783 | + if (function_exists('_mysql_traite_query')) { |
|
| 784 | + $c = strtolower(_request('connect') ?? ''); |
|
| 785 | + $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 786 | + $req = _mysql_traite_query($req, '', $c); |
|
| 787 | + } |
|
| 788 | + // permettre le copier/coller facile |
|
| 789 | + // $res = ancre_texte($req, array(), true); |
|
| 790 | + $res = "<div id='T" . md5((string) $req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 791 | + // formatage et affichage des resultats bruts de la requete |
|
| 792 | + $ress_req = spip_query($req); |
|
| 793 | + $brut_sql = ''; |
|
| 794 | + $num = 1; |
|
| 795 | + // eviter l'affichage de milliers de lignes |
|
| 796 | + // personnalisation possible dans mes_options |
|
| 797 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 798 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 799 | + if ($num <= $max_aff) { |
|
| 800 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 801 | + $brut_sql .= '<p>'; |
|
| 802 | + foreach ($retours_sql as $key => $val) { |
|
| 803 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 804 | + } |
|
| 805 | + $brut_sql .= '</p>'; |
|
| 806 | + } |
|
| 807 | + $num++; |
|
| 808 | + } |
|
| 809 | + $res2 = interdire_scripts($brut_sql); |
|
| 810 | + foreach ($quoi as $view) { |
|
| 811 | + // ne pas afficher les $contexte_inclus |
|
| 812 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', (string) $view); |
|
| 813 | + if ($view) { |
|
| 814 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + } elseif ($affiche == 'code') { |
|
| 818 | + $legend = $nom; |
|
| 819 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 820 | + } elseif ($affiche == 'boucle') { |
|
| 821 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 822 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 823 | + $gram = preg_match('/^([^_]+)_/', (string) $objet, $r) ? $r[1] : ''; |
|
| 824 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 825 | + } elseif ($affiche == 'squelette') { |
|
| 826 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 827 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return [$legend, $res, $res2]; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | function debusquer_entete($titre, $corps) { |
| 834 | 834 | |
| 835 | - include_spip('balise/formulaire_admin'); |
|
| 836 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | - |
|
| 839 | - return _DOCTYPE_ECRIRE . |
|
| 840 | - html_lang_attributes() . |
|
| 841 | - "<head>\n<title>" . |
|
| 842 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | - ")</title>\n" . |
|
| 846 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | - "' />\n" . |
|
| 849 | - http_script('', 'jquery.js') |
|
| 850 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | - . "' type='text/css' />" . |
|
| 852 | - "</head>\n" . |
|
| 853 | - "<body style='margin:0 10px;'>\n" . |
|
| 854 | - "<div id='spip-debug-header'>" . |
|
| 855 | - $corps . |
|
| 856 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | - '</div></body></html>'; |
|
| 835 | + include_spip('balise/formulaire_admin'); |
|
| 836 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | + |
|
| 839 | + return _DOCTYPE_ECRIRE . |
|
| 840 | + html_lang_attributes() . |
|
| 841 | + "<head>\n<title>" . |
|
| 842 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | + _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | + ")</title>\n" . |
|
| 846 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | + "' />\n" . |
|
| 849 | + http_script('', 'jquery.js') |
|
| 850 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | + . "' type='text/css' />" . |
|
| 852 | + "</head>\n" . |
|
| 853 | + "<body style='margin:0 10px;'>\n" . |
|
| 854 | + "<div id='spip-debug-header'>" . |
|
| 855 | + $corps . |
|
| 856 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | + '</div></body></html>'; |
|
| 858 | 858 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | if (!$fonc) { |
| 147 | 147 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 148 | 148 | } |
| 149 | - $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 149 | + $titre = $mode ? $mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' '.$GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | 150 | } |
| 151 | 151 | if ($message === false) { |
| 152 | 152 | lang_select(); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $fond = $GLOBALS['fond'] ?? ''; |
| 170 | 170 | // une erreur critique sort $message en array |
| 171 | 171 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 172 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 172 | + spip_log('Debug: '.$debug.' ('.$fond.')'); |
|
| 173 | 173 | |
| 174 | 174 | return $msg; |
| 175 | 175 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | function debusquer_bandeau($erreurs) { |
| 178 | 178 | |
| 179 | 179 | if (!empty($erreurs)) { |
| 180 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 180 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0).' '._T('zbug_erreur_squelette')]; |
|
| 181 | 181 | |
| 182 | 182 | return debusquer_navigation($erreurs, $n); |
| 183 | 183 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | $valeur_simple = []; |
| 211 | 211 | foreach ($valeur as $v) { |
| 212 | 212 | if (is_array($v)) { |
| 213 | - $valeur_simple[] = 'array:' . count($v); |
|
| 213 | + $valeur_simple[] = 'array:'.count($v); |
|
| 214 | 214 | } elseif (is_object($v)) { |
| 215 | 215 | $valeur_simple[] = $v::class; |
| 216 | 216 | } elseif (is_string($v)) { |
| 217 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 217 | + $valeur_simple[] = "'".$v."'"; |
|
| 218 | 218 | } else { |
| 219 | 219 | $valeur_simple[] = $v; |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | $n = count($valeur); |
| 223 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | - $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 223 | + $valeur = (($n > 3) ? 'array:'.$n.' ' : ''); |
|
| 224 | + $valeur .= '['.implode(', ', $valeur_simple).']'; |
|
| 225 | 225 | } elseif (is_object($valeur)) { |
| 226 | 226 | $valeur = $valeur::class; |
| 227 | 227 | } elseif (is_string($valeur)) { |
| 228 | - $valeur = "'" . $valeur . "'"; |
|
| 228 | + $valeur = "'".$valeur."'"; |
|
| 229 | 229 | } |
| 230 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 230 | + $res .= "\n<tr><td><strong>".nl2br((string) entites_html($nom)) |
|
| 231 | + . '</strong></td><td>: '.nl2br((string) entites_html($valeur)) |
|
| 232 | 232 | . "</td></tr>\n"; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | if ($ligne) { |
| 254 | 254 | $msg .= " L$ligne"; |
| 255 | 255 | } |
| 256 | - spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 256 | + spip_log($msg, 'debusquer'._LOG_ERREUR); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | $nom_code = $lieu->descr['nom']; |
| 279 | 279 | $skel = $lieu->descr['sourcefile']; |
| 280 | 280 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 281 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 281 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 282 | 282 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 283 | 283 | if ($boucle) { |
| 284 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 284 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | 285 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 286 | 286 | } |
| 287 | 287 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Requete erronee |
| 373 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 373 | + $err = '<b>'._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 374 | 374 | . spip_htmlspecialchars($msg) |
| 375 | 375 | . "\n<br /><span style='color: red'><b>" |
| 376 | 376 | . spip_htmlspecialchars($query) |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 386 | 386 | |
| 387 | - $id = $nom . $boucle; |
|
| 387 | + $id = $nom.$boucle; |
|
| 388 | 388 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 389 | 389 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 390 | 390 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', (string) $v[0], $r)) { |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | ) { |
| 433 | 433 | $reg[1] = 'inconnu'; |
| 434 | 434 | } |
| 435 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 435 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 436 | 436 | |
| 437 | 437 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 438 | 438 | if (preg_match($incl, (string) $v)) { |
@@ -448,16 +448,14 @@ discard block |
||
| 448 | 448 | |
| 449 | 449 | if (!$boucle) { |
| 450 | 450 | return $ligne |
| 451 | - ? ' (' . |
|
| 452 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | - _T('squelette_ligne')) . |
|
| 451 | + ? ' ('. |
|
| 452 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 454 | 453 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
| 455 | 454 | : ''; |
| 456 | 455 | } else { |
| 457 | 456 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 458 | 457 | |
| 459 | - return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | - " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 458 | + return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | 459 | } |
| 462 | 460 | } |
| 463 | 461 | |
@@ -479,14 +477,14 @@ discard block |
||
| 479 | 477 | |
| 480 | 478 | $s = preg_replace( |
| 481 | 479 | ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 482 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 480 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 483 | 481 | $s |
| 484 | 482 | ); |
| 485 | 483 | |
| 486 | 484 | |
| 487 | 485 | $tableau = explode('<br />', $s); |
| 488 | 486 | |
| 489 | - $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" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 487 | + $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".(string) @strlen(count($tableau))."d</a></span> %s<br />\n"; |
|
| 490 | 488 | |
| 491 | 489 | $format10 = str_replace('white', 'lightgrey', $format); |
| 492 | 490 | $formaterr = 'color: red;'; |
@@ -530,7 +528,7 @@ discard block |
||
| 530 | 528 | . '" style="cursor: pointer;">' |
| 531 | 529 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 532 | 530 | . '</div> |
| 533 | - ' . $res . "</div>\n"; |
|
| 531 | + ' . $res."</div>\n"; |
|
| 534 | 532 | } |
| 535 | 533 | |
| 536 | 534 | // l'environnement graphique du debuggueur |
@@ -552,14 +550,14 @@ discard block |
||
| 552 | 550 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 553 | 551 | [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
| 554 | 552 | $texte .= $res2; |
| 555 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | - $legend = _T('zbug_' . $mode); |
|
| 557 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 553 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 554 | + $legend = _T('zbug_'.$mode); |
|
| 555 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 558 | 556 | $texte = ancre_texte($texte, ['', '']); |
| 559 | 557 | } |
| 560 | 558 | } else { |
| 561 | 559 | if (strlen(trim($res))) { |
| 562 | - 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>"; |
|
| 560 | + 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>"; |
|
| 563 | 561 | } else { |
| 564 | 562 | // cas de l'appel sur erreur: montre la page |
| 565 | 563 | return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
@@ -567,7 +565,7 @@ discard block |
||
| 567 | 565 | } |
| 568 | 566 | } else { |
| 569 | 567 | $valider = charger_fonction('valider', 'xml'); |
| 570 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 568 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 571 | 569 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 572 | 570 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 573 | 571 | [$texte, $err] = emboite_texte($val, $fonc, $self); |
@@ -578,14 +576,14 @@ discard block |
||
| 578 | 576 | } else { |
| 579 | 577 | $err = ": $err"; |
| 580 | 578 | } |
| 581 | - $legend = _T('validation') . ' ' . $err; |
|
| 579 | + $legend = _T('validation').' '.$err; |
|
| 582 | 580 | $res = $id = ''; |
| 583 | 581 | } |
| 584 | 582 | |
| 585 | 583 | return trim((string) $texte) |
| 586 | - ? "<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" |
|
| 584 | + ? "<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" |
|
| 587 | 585 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 588 | - . "<a href='" . $self . '#f_' . substr((string) $fonc, 0, 37) . "'> ↑ " |
|
| 586 | + . "<a href='".$self.'#f_'.substr((string) $fonc, 0, 37)."'> ↑ " |
|
| 589 | 587 | . ($legend ?: $mode) |
| 590 | 588 | . '</a></legend>' |
| 591 | 589 | . $texte |
@@ -597,7 +595,7 @@ discard block |
||
| 597 | 595 | |
| 598 | 596 | function emboite_texte($res, $fonc = '', $self = '') { |
| 599 | 597 | $errs = $res->err; |
| 600 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 598 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 601 | 599 | |
| 602 | 600 | if (!$texte && !$errs) { |
| 603 | 601 | return [ancre_texte('', ['', '']), false]; |
@@ -653,7 +651,7 @@ discard block |
||
| 653 | 651 | $err = "<h2 style='text-align: center'>" |
| 654 | 652 | . $i |
| 655 | 653 | . "<a href='#fin_err'>" |
| 656 | - . ' ' . _T('erreur_texte') |
|
| 654 | + . ' '._T('erreur_texte') |
|
| 657 | 655 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 658 | 656 | . $err |
| 659 | 657 | . " </table><a id='fin_err'></a>"; |
@@ -663,9 +661,9 @@ discard block |
||
| 663 | 661 | [$msg, $fermant, $ouvrant] = $errs[0]; |
| 664 | 662 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 665 | 663 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 666 | - $err = $msg . |
|
| 667 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 664 | + $err = $msg. |
|
| 665 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 666 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 669 | 667 | |
| 670 | 668 | return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
| 671 | 669 | } |
@@ -698,7 +696,7 @@ discard block |
||
| 698 | 696 | ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
| 699 | 697 | ) : ''; |
| 700 | 698 | |
| 701 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 699 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 702 | 700 | . $t_skel |
| 703 | 701 | . ' ' |
| 704 | 702 | . $sourcefile |
@@ -713,7 +711,7 @@ discard block |
||
| 713 | 711 | . "'>" |
| 714 | 712 | . _T('zbug_calcul') |
| 715 | 713 | . '</a></legend>' |
| 716 | - . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 714 | + . ($temps ? "\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />" : ('')) |
|
| 717 | 715 | . debusquer_contexte($contexte[$sourcefile]) |
| 718 | 716 | . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
| 719 | 717 | . "</fieldset>\n"; |
@@ -734,33 +732,33 @@ discard block |
||
| 734 | 732 | $nom = $boucle->id_boucle; |
| 735 | 733 | $req = $boucle->type_requete; |
| 736 | 734 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 737 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | - |
|
| 739 | - $res .= "\n<tr style='background-color: " . |
|
| 740 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | - "'><td align='right'>$i</td><td>\n" . |
|
| 742 | - "<a class='debug_link_boucle' href='" . |
|
| 743 | - $self2 . |
|
| 744 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | - _T('zbug_boucle') . |
|
| 746 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | - $self2 . |
|
| 748 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | - _T('zbug_resultat') . |
|
| 750 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | - $self2 . |
|
| 752 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | - _T('zbug_code') . |
|
| 754 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | - "'>" . |
|
| 757 | - _T('zbug_calcul') . |
|
| 758 | - "</a></td><td>\n" . |
|
| 759 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | - "</td><td>\n" . |
|
| 761 | - $req . |
|
| 762 | - "</td><td>\n" . |
|
| 763 | - spip_htmlspecialchars($crit) . |
|
| 735 | + $self2 = $self.'&var_mode_objet='.$objet; |
|
| 736 | + |
|
| 737 | + $res .= "\n<tr style='background-color: ". |
|
| 738 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 739 | + "'><td align='right'>$i</td><td>\n". |
|
| 740 | + "<a class='debug_link_boucle' href='". |
|
| 741 | + $self2. |
|
| 742 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 743 | + _T('zbug_boucle'). |
|
| 744 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 745 | + $self2. |
|
| 746 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 747 | + _T('zbug_resultat'). |
|
| 748 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 749 | + $self2. |
|
| 750 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 751 | + _T('zbug_code'). |
|
| 752 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 753 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 754 | + "'>". |
|
| 755 | + _T('zbug_calcul'). |
|
| 756 | + "</a></td><td>\n". |
|
| 757 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 758 | + "</td><td>\n". |
|
| 759 | + $req. |
|
| 760 | + "</td><td>\n". |
|
| 761 | + spip_htmlspecialchars($crit). |
|
| 764 | 762 | '</td></tr>'; |
| 765 | 763 | } |
| 766 | 764 | } |
@@ -787,7 +785,7 @@ discard block |
||
| 787 | 785 | } |
| 788 | 786 | // permettre le copier/coller facile |
| 789 | 787 | // $res = ancre_texte($req, array(), true); |
| 790 | - $res = "<div id='T" . md5((string) $req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 788 | + $res = "<div id='T".md5((string) $req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 791 | 789 | // formatage et affichage des resultats bruts de la requete |
| 792 | 790 | $ress_req = spip_query($req); |
| 793 | 791 | $brut_sql = ''; |
@@ -797,10 +795,10 @@ discard block |
||
| 797 | 795 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 798 | 796 | while ($retours_sql = sql_fetch($ress_req)) { |
| 799 | 797 | if ($num <= $max_aff) { |
| 800 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 798 | + $brut_sql .= '<h3>'.($num == 1 ? $num.' sur '.sql_count($ress_req) : $num).'</h3>'; |
|
| 801 | 799 | $brut_sql .= '<p>'; |
| 802 | 800 | foreach ($retours_sql as $key => $val) { |
| 803 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 801 | + $brut_sql .= '<strong>'.$key.'</strong> => '.spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 804 | 802 | } |
| 805 | 803 | $brut_sql .= '</p>'; |
| 806 | 804 | } |
@@ -811,14 +809,14 @@ discard block |
||
| 811 | 809 | // ne pas afficher les $contexte_inclus |
| 812 | 810 | $view = preg_replace(',<\?php.+\?[>],Uims', '', (string) $view); |
| 813 | 811 | if ($view) { |
| 814 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 812 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view).'</fieldset>'; |
|
| 815 | 813 | } |
| 816 | 814 | } |
| 817 | 815 | } elseif ($affiche == 'code') { |
| 818 | 816 | $legend = $nom; |
| 819 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 817 | + $res = ancre_texte('<'."?php\n".$quoi."\n?".'>'); |
|
| 820 | 818 | } elseif ($affiche == 'boucle') { |
| 821 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 819 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 822 | 820 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 823 | 821 | $gram = preg_match('/^([^_]+)_/', (string) $objet, $r) ? $r[1] : ''; |
| 824 | 822 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -836,23 +834,23 @@ discard block |
||
| 836 | 834 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 837 | 835 | include_spip('inc/texte'); // pour corriger_typo |
| 838 | 836 | |
| 839 | - return _DOCTYPE_ECRIRE . |
|
| 840 | - html_lang_attributes() . |
|
| 841 | - "<head>\n<title>" . |
|
| 842 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | - ")</title>\n" . |
|
| 846 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | - "' />\n" . |
|
| 837 | + return _DOCTYPE_ECRIRE. |
|
| 838 | + html_lang_attributes(). |
|
| 839 | + "<head>\n<title>". |
|
| 840 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 841 | + _T('admin_debug').' '.spip_htmlspecialchars($titre).' ('. |
|
| 842 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 843 | + ")</title>\n". |
|
| 844 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 845 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 846 | + "' />\n". |
|
| 849 | 847 | http_script('', 'jquery.js') |
| 850 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | - . "' type='text/css' />" . |
|
| 852 | - "</head>\n" . |
|
| 853 | - "<body style='margin:0 10px;'>\n" . |
|
| 854 | - "<div id='spip-debug-header'>" . |
|
| 855 | - $corps . |
|
| 856 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 848 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 849 | + . "' type='text/css' />". |
|
| 850 | + "</head>\n". |
|
| 851 | + "<body style='margin:0 10px;'>\n". |
|
| 852 | + "<div id='spip-debug-header'>". |
|
| 853 | + $corps. |
|
| 854 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 857 | 855 | '</div></body></html>'; |
| 858 | 856 | } |
@@ -10,123 +10,123 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 17 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | - $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | - |
|
| 24 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 17 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | + $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | + |
|
| 24 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | - if (!str_contains((string) $file, '#')) { |
|
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | - } else { |
|
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 32 | - } |
|
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | - |
|
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 28 | + if (!str_contains((string) $file, '#')) { |
|
| 29 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | + } else { |
|
| 31 | + $t = '{fond=' . $file . '}'; |
|
| 32 | + } |
|
| 33 | + $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | + |
|
| 35 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | - $contenu = []; |
|
| 40 | - foreach ($args as $l => $t) { |
|
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | - } |
|
| 39 | + $contenu = []; |
|
| 40 | + foreach ($args as $l => $t) { |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | - foreach ($args as $k => $v) { |
|
| 49 | - $args[$k] = "$k=$v"; |
|
| 50 | - } |
|
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 48 | + foreach ($args as $k => $v) { |
|
| 49 | + $args[$k] = "$k=$v"; |
|
| 50 | + } |
|
| 51 | + $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | - $nom = '#' |
|
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 59 | - . $nom |
|
| 60 | - . $etoile |
|
| 61 | - . $args |
|
| 62 | - . $filtres; |
|
| 57 | + $nom = '#' |
|
| 58 | + . ($boucle ? ($boucle . ':') : '') |
|
| 59 | + . $nom |
|
| 60 | + . $etoile |
|
| 61 | + . $args |
|
| 62 | + . $filtres; |
|
| 63 | 63 | |
| 64 | - // Determiner si c'est un champ etendu, |
|
| 64 | + // Determiner si c'est un champ etendu, |
|
| 65 | 65 | |
| 66 | - $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 66 | + $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 67 | 67 | |
| 68 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 68 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function format_critere_html($critere) { |
| 72 | - foreach ($critere as $k => $crit) { |
|
| 73 | - $crit_s = ''; |
|
| 74 | - foreach ($crit as $operande) { |
|
| 75 | - [$type, $valeur] = $operande; |
|
| 76 | - if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | - $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | - $valeur = substr($valeur, 1, -1); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - $crit_s .= $valeur; |
|
| 83 | - } |
|
| 84 | - $critere[$k] = $crit_s; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 72 | + foreach ($critere as $k => $crit) { |
|
| 73 | + $crit_s = ''; |
|
| 74 | + foreach ($crit as $operande) { |
|
| 75 | + [$type, $valeur] = $operande; |
|
| 76 | + if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | + $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | + $valeur = substr($valeur, 1, -1); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + $crit_s .= $valeur; |
|
| 83 | + } |
|
| 84 | + $critere[$k] = $crit_s; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 91 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | + . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 96 | 96 | function format_suite_html($args) { |
| 97 | - $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | - for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | - [$texte, $type] = $args[$i]; |
|
| 100 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | - if (!$texte || !$texte2) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - $c1 = substr((string) $texte, -1); |
|
| 105 | - if ($type2 !== 'texte') { |
|
| 106 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | - // ou assimiles, forcer la notation pleine |
|
| 108 | - if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | - } |
|
| 111 | - } else { |
|
| 112 | - if ($type == 'texte') { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - // si un champ ou assimiles est suivi d'un texte |
|
| 116 | - // et si celui-ci commence par un caractere de champ |
|
| 117 | - // forcer la notation pleine |
|
| 118 | - if ( |
|
| 119 | - $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | - || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | - ) { |
|
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 97 | + $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | + for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | + [$texte, $type] = $args[$i]; |
|
| 100 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | + if (!$texte || !$texte2) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 104 | + $c1 = substr((string) $texte, -1); |
|
| 105 | + if ($type2 !== 'texte') { |
|
| 106 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | + // ou assimiles, forcer la notation pleine |
|
| 108 | + if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | + } |
|
| 111 | + } else { |
|
| 112 | + if ($type == 'texte') { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + // si un champ ou assimiles est suivi d'un texte |
|
| 116 | + // et si celui-ci commence par un caractere de champ |
|
| 117 | + // forcer la notation pleine |
|
| 118 | + if ( |
|
| 119 | + $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | + || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | + ) { |
|
| 122 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function format_texte_html($texte) { |
| 131 | - return $texte; |
|
| 131 | + return $texte; |
|
| 132 | 132 | } |
@@ -26,36 +26,36 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | 28 | if (!str_contains((string) $file, '#')) { |
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 29 | + $t = $file ? ('('.$file.')') : ''; |
|
| 30 | 30 | } else { |
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 31 | + $t = '{fond='.$file.'}'; |
|
| 32 | 32 | } |
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 33 | + $args = $args ? '{'.implode(', ', $args).'}' : (''); |
|
| 34 | 34 | |
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 35 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | 39 | $contenu = []; |
| 40 | 40 | foreach ($args as $l => $t) { |
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>'.implode(' ', $contenu).'</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | 48 | foreach ($args as $k => $v) { |
| 49 | 49 | $args[$k] = "$k=$v"; |
| 50 | 50 | } |
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 51 | + $args = ($args ? '{'.implode(',', $args).'}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | 57 | $nom = '#' |
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 58 | + . ($boucle ? ($boucle.':') : '') |
|
| 59 | 59 | . $nom |
| 60 | 60 | . $etoile |
| 61 | 61 | . $args |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | $critere[$k] = $crit_s; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 87 | + return ($critere ? '{'.implode(',', $critere).'}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | 91 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 92 | + . ($args ? '{'.implode(',', $args).'}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | // si un texte se termine par ( et est suivi d'un champ |
| 107 | 107 | // ou assimiles, forcer la notation pleine |
| 108 | 108 | if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 109 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 110 | 110 | } |
| 111 | 111 | } else { |
| 112 | 112 | if ($type == 'texte') { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
| 120 | 120 | || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
| 121 | 121 | ) { |
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 122 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\Public\Styliser |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -28,188 +28,188 @@ discard block |
||
| 28 | 28 | * @return array Données modifiées du pipeline |
| 29 | 29 | */ |
| 30 | 30 | function public_styliser_par_z_dist($flux) { |
| 31 | - static $prefix_path = null; |
|
| 32 | - static $prefix_length; |
|
| 33 | - static $z_blocs; |
|
| 34 | - static $apl_constant; |
|
| 35 | - static $page; |
|
| 36 | - static $disponible = []; |
|
| 37 | - static $echafauder; |
|
| 38 | - static $prepend = ''; |
|
| 39 | - |
|
| 40 | - if (!isset($prefix_path)) { |
|
| 41 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 42 | - if (test_espace_prive()) { |
|
| 43 | - $prefix_path = 'prive/squelettes/'; |
|
| 44 | - $prefix_length = strlen($prefix_path); |
|
| 45 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 46 | - $page = 'exec'; |
|
| 47 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 48 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 49 | - } else { |
|
| 50 | - $prefix_path = ''; |
|
| 51 | - $prefix_length = 0; |
|
| 52 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 53 | - $page = _SPIP_PAGE; |
|
| 54 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 55 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 56 | - (string) _DIR_PLUGIN_DIST, |
|
| 57 | - '/' |
|
| 58 | - ) : '')); |
|
| 59 | - } |
|
| 60 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 61 | - } |
|
| 62 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 63 | - |
|
| 64 | - $fond = $flux['args']['fond']; |
|
| 65 | - |
|
| 66 | - if ($prepend || strncmp((string) $fond, (string) $prefix_path, $prefix_length) == 0) { |
|
| 67 | - $fond = substr((string) $fond, $prefix_length); |
|
| 68 | - $squelette = $flux['data']; |
|
| 69 | - $ext = $flux['args']['ext']; |
|
| 70 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 71 | - if ( |
|
| 72 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 73 | - && ($dir = explode('/', $fond)) |
|
| 74 | - && count($dir) == 2 // pas un sous repertoire |
|
| 75 | - && ($dir = reset($dir)) |
|
| 76 | - && in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 77 | - && defined($apl_constant) |
|
| 78 | - && in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL |
|
| 79 | - && ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 80 | - ) { |
|
| 81 | - $flux['data'] = $pipe; |
|
| 82 | - |
|
| 83 | - return $flux; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 87 | - if ($squelette && !z_fond_valide($squelette)) { |
|
| 88 | - $squelette = ''; |
|
| 89 | - $echafauder = ''; |
|
| 90 | - } |
|
| 91 | - if ($prepend) { |
|
| 92 | - $squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | - if ($squelette) { |
|
| 94 | - $flux['data'] = $squelette; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // gerer les squelettes non trouves |
|
| 99 | - // -> router vers les /dist.html |
|
| 100 | - // ou scaffolding ou page automatique les contenus |
|
| 101 | - if (!$squelette) { |
|
| 102 | - // si on est sur un ?page=XX non trouve |
|
| 103 | - if ( |
|
| 104 | - isset($flux['args']['contexte'][$page]) && $flux['args']['contexte'][$page] == $fond |
|
| 105 | - || isset($flux['args']['contexte']['type-page']) && $flux['args']['contexte']['type-page'] == $fond |
|
| 106 | - || $fond == 'sommaire' && (!isset($flux['args']['contexte'][$page]) || !$flux['args']['contexte'][$page]) |
|
| 107 | - ) { |
|
| 108 | - // si on est sur un ?page=XX non trouve |
|
| 109 | - // se brancher sur contenu/xx si il existe |
|
| 110 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 111 | - if (!isset($disponible[$fond])) { |
|
| 112 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($disponible[$fond]) { |
|
| 116 | - $flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // echafaudage : |
|
| 121 | - // si c'est un fond de contenu d'un objet en base |
|
| 122 | - // generer un fond automatique a la volee pour les webmestres |
|
| 123 | - elseif (strncmp($fond, "$z_contenu/", strlen((string) $z_contenu) + 1) == 0) { |
|
| 124 | - $type = substr($fond, strlen((string) $z_contenu) + 1); |
|
| 125 | - if ($type == 'page' && isset($flux['args']['contexte'][$page])) { |
|
| 126 | - $type = $flux['args']['contexte'][$page]; |
|
| 127 | - } |
|
| 128 | - if (!isset($disponible[$type])) { |
|
| 129 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 130 | - } |
|
| 131 | - if (is_string($disponible[$type])) { |
|
| 132 | - $flux['data'] = $disponible[$type]; |
|
| 133 | - } elseif ( |
|
| 134 | - $echafauder |
|
| 135 | - && include_spip('inc/autoriser') |
|
| 136 | - && isset($GLOBALS['visiteur_session']['statut']) |
|
| 137 | - && autoriser('echafauder', $type) |
|
| 138 | - && ($is = $disponible[$type]) |
|
| 139 | - && is_array($is) |
|
| 140 | - ) { |
|
| 141 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 142 | - } else { |
|
| 143 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 144 | - $prefix_path . $prepend, |
|
| 145 | - $z_contenu, |
|
| 146 | - '404', |
|
| 147 | - $ext, |
|
| 148 | - $echafauder |
|
| 149 | - )); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 154 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 155 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 156 | - else { |
|
| 157 | - if ( |
|
| 158 | - ($dir = explode('/', $fond)) |
|
| 159 | - && ($dir = reset($dir)) |
|
| 160 | - && $dir !== $z_contenu |
|
| 161 | - && in_array($dir, $z_blocs) |
|
| 162 | - ) { |
|
| 163 | - $type = substr($fond, strlen("$dir/")); |
|
| 164 | - if ($type == 'page' && isset($flux['args']['contexte'][$page])) { |
|
| 165 | - $type = $flux['args']['contexte'][$page]; |
|
| 166 | - } |
|
| 167 | - if ($type !== 'page' && !isset($disponible[$type])) { |
|
| 168 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 169 | - } |
|
| 170 | - if ($type == 'page' || $disponible[$type]) { |
|
| 171 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - $squelette = $flux['data']; |
|
| 176 | - } |
|
| 177 | - // layout specifiques par type et compositions : |
|
| 178 | - // body-article.html |
|
| 179 | - // body-sommaire.html |
|
| 180 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 181 | - // meme dossier que body.html |
|
| 182 | - if ($fond == 'body' && str_ends_with((string) $squelette, $fond)) { |
|
| 183 | - if ( |
|
| 184 | - isset($flux['args']['contexte']['type-page']) |
|
| 185 | - && ( |
|
| 186 | - isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext") |
|
| 187 | - || file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 188 | - ) |
|
| 189 | - ) { |
|
| 190 | - $flux['data'] = $f; |
|
| 191 | - } |
|
| 192 | - } elseif ( |
|
| 193 | - $fond == 'structure' |
|
| 194 | - && z_sanitize_var_zajax() |
|
| 195 | - && ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")) |
|
| 196 | - ) { |
|
| 197 | - $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
|
| 198 | - } // chercher le fond correspondant a la composition |
|
| 199 | - elseif ( |
|
| 200 | - isset($flux['args']['contexte']['composition']) |
|
| 201 | - && (basename($fond) == 'page' || $squelette && str_ends_with((string) $squelette, $fond)) |
|
| 202 | - && ($dir = substr($fond, $prefix_length)) |
|
| 203 | - && ($dir = explode('/', $dir)) |
|
| 204 | - && ($dir = reset($dir)) |
|
| 205 | - && in_array($dir, $z_blocs) |
|
| 206 | - && ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")) |
|
| 207 | - ) { |
|
| 208 | - $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - return $flux; |
|
| 31 | + static $prefix_path = null; |
|
| 32 | + static $prefix_length; |
|
| 33 | + static $z_blocs; |
|
| 34 | + static $apl_constant; |
|
| 35 | + static $page; |
|
| 36 | + static $disponible = []; |
|
| 37 | + static $echafauder; |
|
| 38 | + static $prepend = ''; |
|
| 39 | + |
|
| 40 | + if (!isset($prefix_path)) { |
|
| 41 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 42 | + if (test_espace_prive()) { |
|
| 43 | + $prefix_path = 'prive/squelettes/'; |
|
| 44 | + $prefix_length = strlen($prefix_path); |
|
| 45 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 46 | + $page = 'exec'; |
|
| 47 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 48 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 49 | + } else { |
|
| 50 | + $prefix_path = ''; |
|
| 51 | + $prefix_length = 0; |
|
| 52 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 53 | + $page = _SPIP_PAGE; |
|
| 54 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 55 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 56 | + (string) _DIR_PLUGIN_DIST, |
|
| 57 | + '/' |
|
| 58 | + ) : '')); |
|
| 59 | + } |
|
| 60 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 61 | + } |
|
| 62 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 63 | + |
|
| 64 | + $fond = $flux['args']['fond']; |
|
| 65 | + |
|
| 66 | + if ($prepend || strncmp((string) $fond, (string) $prefix_path, $prefix_length) == 0) { |
|
| 67 | + $fond = substr((string) $fond, $prefix_length); |
|
| 68 | + $squelette = $flux['data']; |
|
| 69 | + $ext = $flux['args']['ext']; |
|
| 70 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 71 | + if ( |
|
| 72 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 73 | + && ($dir = explode('/', $fond)) |
|
| 74 | + && count($dir) == 2 // pas un sous repertoire |
|
| 75 | + && ($dir = reset($dir)) |
|
| 76 | + && in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 77 | + && defined($apl_constant) |
|
| 78 | + && in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL |
|
| 79 | + && ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 80 | + ) { |
|
| 81 | + $flux['data'] = $pipe; |
|
| 82 | + |
|
| 83 | + return $flux; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 87 | + if ($squelette && !z_fond_valide($squelette)) { |
|
| 88 | + $squelette = ''; |
|
| 89 | + $echafauder = ''; |
|
| 90 | + } |
|
| 91 | + if ($prepend) { |
|
| 92 | + $squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | + if ($squelette) { |
|
| 94 | + $flux['data'] = $squelette; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // gerer les squelettes non trouves |
|
| 99 | + // -> router vers les /dist.html |
|
| 100 | + // ou scaffolding ou page automatique les contenus |
|
| 101 | + if (!$squelette) { |
|
| 102 | + // si on est sur un ?page=XX non trouve |
|
| 103 | + if ( |
|
| 104 | + isset($flux['args']['contexte'][$page]) && $flux['args']['contexte'][$page] == $fond |
|
| 105 | + || isset($flux['args']['contexte']['type-page']) && $flux['args']['contexte']['type-page'] == $fond |
|
| 106 | + || $fond == 'sommaire' && (!isset($flux['args']['contexte'][$page]) || !$flux['args']['contexte'][$page]) |
|
| 107 | + ) { |
|
| 108 | + // si on est sur un ?page=XX non trouve |
|
| 109 | + // se brancher sur contenu/xx si il existe |
|
| 110 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 111 | + if (!isset($disponible[$fond])) { |
|
| 112 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($disponible[$fond]) { |
|
| 116 | + $flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // echafaudage : |
|
| 121 | + // si c'est un fond de contenu d'un objet en base |
|
| 122 | + // generer un fond automatique a la volee pour les webmestres |
|
| 123 | + elseif (strncmp($fond, "$z_contenu/", strlen((string) $z_contenu) + 1) == 0) { |
|
| 124 | + $type = substr($fond, strlen((string) $z_contenu) + 1); |
|
| 125 | + if ($type == 'page' && isset($flux['args']['contexte'][$page])) { |
|
| 126 | + $type = $flux['args']['contexte'][$page]; |
|
| 127 | + } |
|
| 128 | + if (!isset($disponible[$type])) { |
|
| 129 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 130 | + } |
|
| 131 | + if (is_string($disponible[$type])) { |
|
| 132 | + $flux['data'] = $disponible[$type]; |
|
| 133 | + } elseif ( |
|
| 134 | + $echafauder |
|
| 135 | + && include_spip('inc/autoriser') |
|
| 136 | + && isset($GLOBALS['visiteur_session']['statut']) |
|
| 137 | + && autoriser('echafauder', $type) |
|
| 138 | + && ($is = $disponible[$type]) |
|
| 139 | + && is_array($is) |
|
| 140 | + ) { |
|
| 141 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 142 | + } else { |
|
| 143 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 144 | + $prefix_path . $prepend, |
|
| 145 | + $z_contenu, |
|
| 146 | + '404', |
|
| 147 | + $ext, |
|
| 148 | + $echafauder |
|
| 149 | + )); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 154 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 155 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 156 | + else { |
|
| 157 | + if ( |
|
| 158 | + ($dir = explode('/', $fond)) |
|
| 159 | + && ($dir = reset($dir)) |
|
| 160 | + && $dir !== $z_contenu |
|
| 161 | + && in_array($dir, $z_blocs) |
|
| 162 | + ) { |
|
| 163 | + $type = substr($fond, strlen("$dir/")); |
|
| 164 | + if ($type == 'page' && isset($flux['args']['contexte'][$page])) { |
|
| 165 | + $type = $flux['args']['contexte'][$page]; |
|
| 166 | + } |
|
| 167 | + if ($type !== 'page' && !isset($disponible[$type])) { |
|
| 168 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 169 | + } |
|
| 170 | + if ($type == 'page' || $disponible[$type]) { |
|
| 171 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + $squelette = $flux['data']; |
|
| 176 | + } |
|
| 177 | + // layout specifiques par type et compositions : |
|
| 178 | + // body-article.html |
|
| 179 | + // body-sommaire.html |
|
| 180 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 181 | + // meme dossier que body.html |
|
| 182 | + if ($fond == 'body' && str_ends_with((string) $squelette, $fond)) { |
|
| 183 | + if ( |
|
| 184 | + isset($flux['args']['contexte']['type-page']) |
|
| 185 | + && ( |
|
| 186 | + isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext") |
|
| 187 | + || file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 188 | + ) |
|
| 189 | + ) { |
|
| 190 | + $flux['data'] = $f; |
|
| 191 | + } |
|
| 192 | + } elseif ( |
|
| 193 | + $fond == 'structure' |
|
| 194 | + && z_sanitize_var_zajax() |
|
| 195 | + && ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")) |
|
| 196 | + ) { |
|
| 197 | + $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
|
| 198 | + } // chercher le fond correspondant a la composition |
|
| 199 | + elseif ( |
|
| 200 | + isset($flux['args']['contexte']['composition']) |
|
| 201 | + && (basename($fond) == 'page' || $squelette && str_ends_with((string) $squelette, $fond)) |
|
| 202 | + && ($dir = substr($fond, $prefix_length)) |
|
| 203 | + && ($dir = explode('/', $dir)) |
|
| 204 | + && ($dir = reset($dir)) |
|
| 205 | + && in_array($dir, $z_blocs) |
|
| 206 | + && ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")) |
|
| 207 | + ) { |
|
| 208 | + $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + return $flux; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | * @return array |
| 220 | 220 | */ |
| 221 | 221 | function z_blocs($espace_prive = false) { |
| 222 | - if ($espace_prive) { |
|
| 223 | - return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 224 | - 'contenu', |
|
| 225 | - 'navigation', |
|
| 226 | - 'extra', |
|
| 227 | - 'head', |
|
| 228 | - 'hierarchie', |
|
| 229 | - 'top' |
|
| 230 | - ]); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 222 | + if ($espace_prive) { |
|
| 223 | + return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 224 | + 'contenu', |
|
| 225 | + 'navigation', |
|
| 226 | + 'extra', |
|
| 227 | + 'head', |
|
| 228 | + 'hierarchie', |
|
| 229 | + 'top' |
|
| 230 | + ]); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | * @return mixed |
| 246 | 246 | */ |
| 247 | 247 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 248 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 249 | - return $d; |
|
| 250 | - } |
|
| 248 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 249 | + return $d; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 252 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * `true` si on peut l'utiliser, `false` sinon. |
| 264 | 264 | **/ |
| 265 | 265 | function z_fond_valide($squelette) { |
| 266 | - return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette); |
|
| 266 | + return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -281,14 +281,14 @@ discard block |
||
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | 283 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 284 | - if ( |
|
| 285 | - defined('_ZCORE_BLOC_PREFIX_SKEL') && ($f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext")) && z_fond_valide($f) |
|
| 286 | - || ($f = find_in_path("$prefix_path$bloc/$fond.$ext")) && z_fond_valide($f) |
|
| 287 | - ) { |
|
| 288 | - return substr((string) $f, 0, -strlen(".$ext")); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return ''; |
|
| 284 | + if ( |
|
| 285 | + defined('_ZCORE_BLOC_PREFIX_SKEL') && ($f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext")) && z_fond_valide($f) |
|
| 286 | + || ($f = find_in_path("$prefix_path$bloc/$fond.$ext")) && z_fond_valide($f) |
|
| 287 | + ) { |
|
| 288 | + return substr((string) $f, 0, -strlen(".$ext")); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return ''; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -300,52 +300,52 @@ discard block |
||
| 300 | 300 | * @return bool |
| 301 | 301 | */ |
| 302 | 302 | function z_echafaudable($type) { |
| 303 | - static $pages = null; |
|
| 304 | - static $echafaudable = []; |
|
| 305 | - if (isset($echafaudable[$type])) { |
|
| 306 | - return $echafaudable[$type]; |
|
| 307 | - } |
|
| 308 | - if (preg_match(',[^\w],', $type)) { |
|
| 309 | - return $echafaudable[$type] = false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if (test_espace_prive()) { |
|
| 313 | - if (!function_exists('trouver_objet_exec')) { |
|
| 314 | - include_spip('inc/pipelines_ecrire'); |
|
| 315 | - } |
|
| 316 | - if ($e = trouver_objet_exec($type)) { |
|
| 317 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 318 | - } else { |
|
| 319 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | - if ( |
|
| 321 | - ($t = objet_type($type, false)) !== $type |
|
| 322 | - && ($e = trouver_objet_exec($t)) |
|
| 323 | - ) { |
|
| 324 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - if (is_null($pages)) { |
|
| 329 | - $pages = []; |
|
| 330 | - $liste = lister_tables_objets_sql(); |
|
| 331 | - foreach ($liste as $t => $d) { |
|
| 332 | - if ($d['page']) { |
|
| 333 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - if (!isset($pages[$type])) { |
|
| 338 | - return $echafaudable[$type] = false; |
|
| 339 | - } |
|
| 340 | - if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 341 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return $echafaudable[$type] = $pages[$type]; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - return $echafaudable[$type] = false; |
|
| 303 | + static $pages = null; |
|
| 304 | + static $echafaudable = []; |
|
| 305 | + if (isset($echafaudable[$type])) { |
|
| 306 | + return $echafaudable[$type]; |
|
| 307 | + } |
|
| 308 | + if (preg_match(',[^\w],', $type)) { |
|
| 309 | + return $echafaudable[$type] = false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if (test_espace_prive()) { |
|
| 313 | + if (!function_exists('trouver_objet_exec')) { |
|
| 314 | + include_spip('inc/pipelines_ecrire'); |
|
| 315 | + } |
|
| 316 | + if ($e = trouver_objet_exec($type)) { |
|
| 317 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 318 | + } else { |
|
| 319 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | + if ( |
|
| 321 | + ($t = objet_type($type, false)) !== $type |
|
| 322 | + && ($e = trouver_objet_exec($t)) |
|
| 323 | + ) { |
|
| 324 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + if (is_null($pages)) { |
|
| 329 | + $pages = []; |
|
| 330 | + $liste = lister_tables_objets_sql(); |
|
| 331 | + foreach ($liste as $t => $d) { |
|
| 332 | + if ($d['page']) { |
|
| 333 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + if (!isset($pages[$type])) { |
|
| 338 | + return $echafaudable[$type] = false; |
|
| 339 | + } |
|
| 340 | + if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 341 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 342 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return $echafaudable[$type] = $pages[$type]; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + return $echafaudable[$type] = false; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | |
@@ -362,42 +362,42 @@ discard block |
||
| 362 | 362 | * @return string |
| 363 | 363 | */ |
| 364 | 364 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 365 | - $scaffold = ''; |
|
| 366 | - |
|
| 367 | - // page objet ou objet_edit |
|
| 368 | - if (is_array($desc_exec)) { |
|
| 369 | - $type = $desc_exec['type']; |
|
| 370 | - $primary = $desc_exec['id_table_objet']; |
|
| 371 | - |
|
| 372 | - if ($desc_exec['edition'] === false) { |
|
| 373 | - $fond = 'objet'; |
|
| 374 | - } else { |
|
| 375 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 376 | - $desc = $trouver_table($table_sql); |
|
| 377 | - $fond = isset($desc['field']['id_rubrique']) ? 'objet_edit' : 'objet_edit.sans_rubrique'; |
|
| 378 | - } |
|
| 379 | - $dir = z_blocs(test_espace_prive()); |
|
| 380 | - $dir = reset($dir); |
|
| 381 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>'; |
|
| 382 | - } // page objets |
|
| 383 | - elseif (($type = $desc_exec) && !str_contains($type, '/')) { |
|
| 384 | - $dir = z_blocs(test_espace_prive()); |
|
| 385 | - $dir = reset($dir); |
|
| 386 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 387 | - } |
|
| 388 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 389 | - // et objet et tire de $table |
|
| 390 | - elseif ($fond = $desc_exec) { |
|
| 391 | - $dir = md5(dirname($fond)); |
|
| 392 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 396 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 397 | - $f = $base_dir . "$exec"; |
|
| 398 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 399 | - |
|
| 400 | - return $f; |
|
| 365 | + $scaffold = ''; |
|
| 366 | + |
|
| 367 | + // page objet ou objet_edit |
|
| 368 | + if (is_array($desc_exec)) { |
|
| 369 | + $type = $desc_exec['type']; |
|
| 370 | + $primary = $desc_exec['id_table_objet']; |
|
| 371 | + |
|
| 372 | + if ($desc_exec['edition'] === false) { |
|
| 373 | + $fond = 'objet'; |
|
| 374 | + } else { |
|
| 375 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 376 | + $desc = $trouver_table($table_sql); |
|
| 377 | + $fond = isset($desc['field']['id_rubrique']) ? 'objet_edit' : 'objet_edit.sans_rubrique'; |
|
| 378 | + } |
|
| 379 | + $dir = z_blocs(test_espace_prive()); |
|
| 380 | + $dir = reset($dir); |
|
| 381 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>'; |
|
| 382 | + } // page objets |
|
| 383 | + elseif (($type = $desc_exec) && !str_contains($type, '/')) { |
|
| 384 | + $dir = z_blocs(test_espace_prive()); |
|
| 385 | + $dir = reset($dir); |
|
| 386 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 387 | + } |
|
| 388 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 389 | + // et objet et tire de $table |
|
| 390 | + elseif ($fond = $desc_exec) { |
|
| 391 | + $dir = md5(dirname($fond)); |
|
| 392 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 396 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 397 | + $f = $base_dir . "$exec"; |
|
| 398 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 399 | + |
|
| 400 | + return $f; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -406,17 +406,17 @@ discard block |
||
| 406 | 406 | * @return bool|string |
| 407 | 407 | */ |
| 408 | 408 | function z_sanitize_var_zajax() { |
| 409 | - $z_ajax = _request('var_zajax'); |
|
| 410 | - if (!$z_ajax) { |
|
| 411 | - return false; |
|
| 412 | - } |
|
| 413 | - if ( |
|
| 414 | - !($z_blocs = z_blocs(test_espace_prive())) |
|
| 415 | - || !in_array($z_ajax, $z_blocs) |
|
| 416 | - ) { |
|
| 417 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 418 | - $z_ajax = false; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $z_ajax; |
|
| 409 | + $z_ajax = _request('var_zajax'); |
|
| 410 | + if (!$z_ajax) { |
|
| 411 | + return false; |
|
| 412 | + } |
|
| 413 | + if ( |
|
| 414 | + !($z_blocs = z_blocs(test_espace_prive())) |
|
| 415 | + || !in_array($z_ajax, $z_blocs) |
|
| 416 | + ) { |
|
| 417 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 418 | + $z_ajax = false; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $z_ajax; |
|
| 422 | 422 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 53 | 53 | $page = _SPIP_PAGE; |
| 54 | 54 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 55 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 55 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim( |
|
| 56 | 56 | (string) _DIR_PLUGIN_DIST, |
| 57 | 57 | '/' |
| 58 | 58 | ) : '')); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | && in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 77 | 77 | && defined($apl_constant) |
| 78 | 78 | && in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL |
| 79 | - && ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 79 | + && ($pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 80 | 80 | ) { |
| 81 | 81 | $flux['data'] = $pipe; |
| 82 | 82 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $echafauder = ''; |
| 90 | 90 | } |
| 91 | 91 | if ($prepend) { |
| 92 | - $squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 92 | + $squelette = substr((string) find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | 93 | if ($squelette) { |
| 94 | 94 | $flux['data'] = $squelette; |
| 95 | 95 | } |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | // se brancher sur contenu/xx si il existe |
| 110 | 110 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 111 | 111 | if (!isset($disponible[$fond])) { |
| 112 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 112 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | if ($disponible[$fond]) { |
| 116 | - $flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 116 | + $flux['data'] = substr((string) find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $type = $flux['args']['contexte'][$page]; |
| 127 | 127 | } |
| 128 | 128 | if (!isset($disponible[$type])) { |
| 129 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 129 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 130 | 130 | } |
| 131 | 131 | if (is_string($disponible[$type])) { |
| 132 | 132 | $flux['data'] = $disponible[$type]; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 142 | 142 | } else { |
| 143 | 143 | $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
| 144 | - $prefix_path . $prepend, |
|
| 144 | + $prefix_path.$prepend, |
|
| 145 | 145 | $z_contenu, |
| 146 | 146 | '404', |
| 147 | 147 | $ext, |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | $type = $flux['args']['contexte'][$page]; |
| 166 | 166 | } |
| 167 | 167 | if ($type !== 'page' && !isset($disponible[$type])) { |
| 168 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 168 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 169 | 169 | } |
| 170 | 170 | if ($type == 'page' || $disponible[$type]) { |
| 171 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 171 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | if ( |
| 184 | 184 | isset($flux['args']['contexte']['type-page']) |
| 185 | 185 | && ( |
| 186 | - isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext") |
|
| 187 | - || file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 186 | + isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext") |
|
| 187 | + || file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext") |
|
| 188 | 188 | ) |
| 189 | 189 | ) { |
| 190 | 190 | $flux['data'] = $f; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | } elseif ( |
| 193 | 193 | $fond == 'structure' |
| 194 | 194 | && z_sanitize_var_zajax() |
| 195 | - && ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")) |
|
| 195 | + && ($f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) |
|
| 196 | 196 | ) { |
| 197 | 197 | $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
| 198 | 198 | } // chercher le fond correspondant a la composition |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | && ($dir = explode('/', $dir)) |
| 204 | 204 | && ($dir = reset($dir)) |
| 205 | 205 | && in_array($dir, $z_blocs) |
| 206 | - && ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")) |
|
| 206 | + && ($f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext")) |
|
| 207 | 207 | ) { |
| 208 | 208 | $flux['data'] = substr((string) $f, 0, -strlen(".$ext")); |
| 209 | 209 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * `true` si on peut l'utiliser, `false` sinon. |
| 264 | 264 | **/ |
| 265 | 265 | function z_fond_valide($squelette) { |
| 266 | - return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette); |
|
| 266 | + return !_ZCORE_EXCLURE_PATH || !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -378,23 +378,23 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | $dir = z_blocs(test_espace_prive()); |
| 380 | 380 | $dir = reset($dir); |
| 381 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>'; |
|
| 381 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper((string) $primary).',env}>'; |
|
| 382 | 382 | } // page objets |
| 383 | 383 | elseif (($type = $desc_exec) && !str_contains($type, '/')) { |
| 384 | 384 | $dir = z_blocs(test_espace_prive()); |
| 385 | 385 | $dir = reset($dir); |
| 386 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 386 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />'; |
|
| 387 | 387 | } |
| 388 | 388 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 389 | 389 | // et objet et tire de $table |
| 390 | 390 | elseif ($fond = $desc_exec) { |
| 391 | 391 | $dir = md5(dirname($fond)); |
| 392 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 392 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />'; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
| 396 | 396 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 397 | - $f = $base_dir . "$exec"; |
|
| 397 | + $f = $base_dir."$exec"; |
|
| 398 | 398 | ecrire_fichier("$f.$ext", $scaffold); |
| 399 | 399 | |
| 400 | 400 | return $f; |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * texte |
| 41 | 41 | */ |
| 42 | 42 | function sandbox_composer_texte($texte, &$p) { |
| 43 | - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 43 | + return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -56,38 +56,38 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 59 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | - $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | - $refs = $refl->getParameters(); |
|
| 70 | - if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | - } else { |
|
| 74 | - $code = "$f($code$arglist)"; |
|
| 75 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | - } |
|
| 77 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | - if (($nb_args_f < $min_f)) { |
|
| 80 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - // le filtre n'existe pas, |
|
| 85 | - // on le notifie |
|
| 86 | - else { |
|
| 87 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $code; |
|
| 59 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | + $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | + $refs = $refl->getParameters(); |
|
| 70 | + if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | + } else { |
|
| 74 | + $code = "$f($code$arglist)"; |
|
| 75 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | + } |
|
| 77 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | + if (($nb_args_f < $min_f)) { |
|
| 80 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + // le filtre n'existe pas, |
|
| 85 | + // on le notifie |
|
| 86 | + else { |
|
| 87 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $code; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Calculer un <INCLURE(xx.php)> |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 113 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | - // si inexistant, on essaiera a l'execution |
|
| 115 | - $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 113 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | + // si inexistant, on essaiera a l'execution |
|
| 115 | + $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 116 | 116 | |
| 117 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 117 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | 128 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 129 | - // Securite |
|
| 130 | - if ( |
|
| 131 | - $p->interdire_scripts |
|
| 132 | - && $p->etoile != '**' |
|
| 133 | - ) { |
|
| 134 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | - $code = "interdire_scripts($code)"; |
|
| 136 | - } else { |
|
| 137 | - $code = interdire_scripts($r[2]); |
|
| 138 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $code; |
|
| 129 | + // Securite |
|
| 130 | + if ( |
|
| 131 | + $p->interdire_scripts |
|
| 132 | + && $p->etoile != '**' |
|
| 133 | + ) { |
|
| 134 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | + $code = "interdire_scripts($code)"; |
|
| 136 | + } else { |
|
| 137 | + $code = interdire_scripts($r[2]); |
|
| 138 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $code; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return mixed|string |
| 159 | 159 | */ |
| 160 | 160 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 161 | - $series_filtres = func_get_args(); |
|
| 162 | - array_shift($series_filtres);// skel |
|
| 163 | - array_shift($series_filtres);// corps |
|
| 164 | - |
|
| 165 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | - if ($skel['process_ins'] == 'php') { |
|
| 167 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // recuperer les couples de remplacement |
|
| 171 | - $replace = echapper_php_callback(); |
|
| 172 | - |
|
| 173 | - foreach ($series_filtres as $filtres) { |
|
| 174 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | - foreach ($filtres as $filtre) { |
|
| 176 | - if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | - $corps = $f($corps); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // restaurer les echappements |
|
| 184 | - return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 161 | + $series_filtres = func_get_args(); |
|
| 162 | + array_shift($series_filtres);// skel |
|
| 163 | + array_shift($series_filtres);// corps |
|
| 164 | + |
|
| 165 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | + if ($skel['process_ins'] == 'php') { |
|
| 167 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // recuperer les couples de remplacement |
|
| 171 | + $replace = echapper_php_callback(); |
|
| 172 | + |
|
| 173 | + foreach ($series_filtres as $filtres) { |
|
| 174 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | + foreach ($filtres as $filtre) { |
|
| 176 | + if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | + $corps = $f($corps); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // restaurer les echappements |
|
| 184 | + return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -200,21 +200,21 @@ discard block |
||
| 200 | 200 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 201 | 201 | **/ |
| 202 | 202 | function echapper_php_callback($r = null) { |
| 203 | - static $src = []; |
|
| 204 | - static $dst = []; |
|
| 203 | + static $src = []; |
|
| 204 | + static $dst = []; |
|
| 205 | 205 | |
| 206 | - // si on recoit un tableau, on est en mode echappement |
|
| 207 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | - if (is_array($r)) { |
|
| 209 | - $dst[] = $r[0]; |
|
| 206 | + // si on recoit un tableau, on est en mode echappement |
|
| 207 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | + if (is_array($r)) { |
|
| 209 | + $dst[] = $r[0]; |
|
| 210 | 210 | |
| 211 | - return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | - } |
|
| 211 | + return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | - // et on RAZ les remplacements |
|
| 216 | - $r = [$src, $dst]; |
|
| 217 | - $src = $dst = []; |
|
| 214 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | + // et on RAZ les remplacements |
|
| 216 | + $r = [$src, $dst]; |
|
| 217 | + $src = $dst = []; |
|
| 218 | 218 | |
| 219 | - return $r; |
|
| 219 | + return $r; |
|
| 220 | 220 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * texte |
| 41 | 41 | */ |
| 42 | 42 | function sandbox_composer_texte($texte, &$p) { |
| 43 | - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 43 | + return "'".str_replace(['\\', "'"], ['\\\\', "\\'"], $texte)."'"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $min_f = $refl->getNumberOfRequiredParameters(); |
| 79 | 79 | if (($nb_args_f < $min_f)) { |
| 80 | 80 | $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
| 81 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 81 | + erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | // le filtre n'existe pas, |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 161 | 161 | $series_filtres = func_get_args(); |
| 162 | - array_shift($series_filtres);// skel |
|
| 163 | - array_shift($series_filtres);// corps |
|
| 162 | + array_shift($series_filtres); // skel |
|
| 163 | + array_shift($series_filtres); // corps |
|
| 164 | 164 | |
| 165 | 165 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 166 | 166 | if ($skel['process_ins'] == 'php') { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | if (is_array($r)) { |
| 209 | 209 | $dst[] = $r[0]; |
| 210 | 210 | |
| 211 | - return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 211 | + return $src[] = '___'.md5((string) $r[0]).'___'; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -38,59 +38,59 @@ discard block |
||
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| 40 | 40 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 41 | - static $styliser_par_z; |
|
| 42 | - |
|
| 43 | - // s'assurer que le fond est licite |
|
| 44 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | - if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | - $fond = '404'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | - $modele = substr($fond, 8); |
|
| 51 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | - $fond = "modeles/$modele"; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | - $id_rubrique = 0; |
|
| 57 | - // Chercher le fond qui va servir de squelette |
|
| 58 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | - [$id_rubrique, $lang] = $r; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // trouver un squelette du nom demande |
|
| 63 | - // ne rien dire si on ne trouve pas, |
|
| 64 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | - $squelette = trouver_fond($fond, '', true); |
|
| 67 | - $ext = $squelette['extension']; |
|
| 68 | - |
|
| 69 | - $flux = [ |
|
| 70 | - 'args' => [ |
|
| 71 | - 'id_rubrique' => $id_rubrique, |
|
| 72 | - 'ext' => $ext, |
|
| 73 | - 'fond' => $fond, |
|
| 74 | - 'lang' => $lang, |
|
| 75 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | - 'connect' => $connect |
|
| 77 | - ], |
|
| 78 | - 'data' => $squelette['fond'], |
|
| 79 | - ]; |
|
| 80 | - |
|
| 81 | - if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | - if (!$styliser_par_z) { |
|
| 83 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | - } |
|
| 85 | - $flux = $styliser_par_z($flux); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $flux = styliser_par_objets($flux); |
|
| 89 | - |
|
| 90 | - // pipeline styliser |
|
| 91 | - $squelette = pipeline('styliser', $flux); |
|
| 92 | - |
|
| 93 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 41 | + static $styliser_par_z; |
|
| 42 | + |
|
| 43 | + // s'assurer que le fond est licite |
|
| 44 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | + if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | + $fond = '404'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | + $modele = substr($fond, 8); |
|
| 51 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | + $fond = "modeles/$modele"; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | + $id_rubrique = 0; |
|
| 57 | + // Chercher le fond qui va servir de squelette |
|
| 58 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | + [$id_rubrique, $lang] = $r; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // trouver un squelette du nom demande |
|
| 63 | + // ne rien dire si on ne trouve pas, |
|
| 64 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | + $squelette = trouver_fond($fond, '', true); |
|
| 67 | + $ext = $squelette['extension']; |
|
| 68 | + |
|
| 69 | + $flux = [ |
|
| 70 | + 'args' => [ |
|
| 71 | + 'id_rubrique' => $id_rubrique, |
|
| 72 | + 'ext' => $ext, |
|
| 73 | + 'fond' => $fond, |
|
| 74 | + 'lang' => $lang, |
|
| 75 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | + 'connect' => $connect |
|
| 77 | + ], |
|
| 78 | + 'data' => $squelette['fond'], |
|
| 79 | + ]; |
|
| 80 | + |
|
| 81 | + if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | + if (!$styliser_par_z) { |
|
| 83 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | + } |
|
| 85 | + $flux = $styliser_par_z($flux); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $flux = styliser_par_objets($flux); |
|
| 89 | + |
|
| 90 | + // pipeline styliser |
|
| 91 | + $squelette = pipeline('styliser', $flux); |
|
| 92 | + |
|
| 93 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -109,32 +109,32 @@ discard block |
||
| 109 | 109 | * Données du pipeline styliser |
| 110 | 110 | **/ |
| 111 | 111 | function styliser_par_objets($flux) { |
| 112 | - if ( |
|
| 113 | - test_espace_prive() |
|
| 114 | - && !($squelette = $flux['data']) |
|
| 115 | - && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | - && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | - ) { |
|
| 118 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | - $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | - $table_sql = table_objet_sql($table); |
|
| 121 | - $objets = lister_tables_objets_sql(); |
|
| 122 | - if (isset($objets[$table_sql])) { |
|
| 123 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | - $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | - $table = table_objet($type); |
|
| 129 | - $table_sql = table_objet_sql($table); |
|
| 130 | - $objets = lister_tables_objets_sql(); |
|
| 131 | - if (isset($objets[$table_sql])) { |
|
| 132 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $flux; |
|
| 112 | + if ( |
|
| 113 | + test_espace_prive() |
|
| 114 | + && !($squelette = $flux['data']) |
|
| 115 | + && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | + && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | + ) { |
|
| 118 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | + $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | + $table_sql = table_objet_sql($table); |
|
| 121 | + $objets = lister_tables_objets_sql(); |
|
| 122 | + if (isset($objets[$table_sql])) { |
|
| 123 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | + $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | + $table = table_objet($type); |
|
| 129 | + $table_sql = table_objet_sql($table); |
|
| 130 | + $objets = lister_tables_objets_sql(); |
|
| 131 | + if (isset($objets[$table_sql])) { |
|
| 132 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $flux; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -150,47 +150,47 @@ discard block |
||
| 150 | 150 | * @return array|false |
| 151 | 151 | */ |
| 152 | 152 | function quete_rubrique_fond($contexte) { |
| 153 | - static $liste_objets = null; |
|
| 154 | - static $quete = []; |
|
| 155 | - if (is_null($liste_objets)) { |
|
| 156 | - $liste_objets = []; |
|
| 157 | - include_spip('inc/urls'); |
|
| 158 | - include_spip('public/quete'); |
|
| 159 | - $l = urls_liste_objets(false); |
|
| 160 | - // placer la rubrique en tete des objets |
|
| 161 | - $l = array_diff($l, ['rubrique']); |
|
| 162 | - array_unshift($l, 'rubrique'); |
|
| 163 | - foreach ($l as $objet) { |
|
| 164 | - $id = id_table_objet($objet); |
|
| 165 | - if (!isset($liste_objets[$id])) { |
|
| 166 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | - if ($c === []) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $c = array_map('intval', $c); |
|
| 176 | - $s = serialize($c); |
|
| 177 | - if (isset($quete[$s])) { |
|
| 178 | - return $quete[$s]; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | - unset($c['id_rubrique']); |
|
| 183 | - $c = ['id_rubrique' => $r] + $c; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - foreach ($c as $_id => $id) { |
|
| 187 | - if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | - $lang = $row['lang'] ?? ''; |
|
| 189 | - if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | - return $quete[$s] = [$id, $lang]; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $quete[$s] = false; |
|
| 153 | + static $liste_objets = null; |
|
| 154 | + static $quete = []; |
|
| 155 | + if (is_null($liste_objets)) { |
|
| 156 | + $liste_objets = []; |
|
| 157 | + include_spip('inc/urls'); |
|
| 158 | + include_spip('public/quete'); |
|
| 159 | + $l = urls_liste_objets(false); |
|
| 160 | + // placer la rubrique en tete des objets |
|
| 161 | + $l = array_diff($l, ['rubrique']); |
|
| 162 | + array_unshift($l, 'rubrique'); |
|
| 163 | + foreach ($l as $objet) { |
|
| 164 | + $id = id_table_objet($objet); |
|
| 165 | + if (!isset($liste_objets[$id])) { |
|
| 166 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | + if ($c === []) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $c = array_map('intval', $c); |
|
| 176 | + $s = serialize($c); |
|
| 177 | + if (isset($quete[$s])) { |
|
| 178 | + return $quete[$s]; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | + unset($c['id_rubrique']); |
|
| 183 | + $c = ['id_rubrique' => $r] + $c; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + foreach ($c as $_id => $id) { |
|
| 187 | + if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | + $lang = $row['lang'] ?? ''; |
|
| 189 | + if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | + return $quete[$s] = [$id, $lang]; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $quete[$s] = false; |
|
| 196 | 196 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | **/ |
| 28 | 28 | |
| 29 | 29 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 30 | - return; |
|
| 30 | + return; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** Début de la partie principale d'une boucle */ |
@@ -71,82 +71,82 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | function phraser_inclure($texte, $ligne, $result) { |
| 73 | 73 | |
| 74 | - while (preg_match(BALISE_INCLURE, (string) $texte, $match)) { |
|
| 75 | - $match = array_pad($match, 3, null); |
|
| 76 | - $p = strpos((string) $texte, (string) $match[0]); |
|
| 77 | - $debut = substr((string) $texte, 0, $p); |
|
| 78 | - if ($p) { |
|
| 79 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 80 | - } |
|
| 81 | - $ligne += substr_count($debut, "\n"); |
|
| 82 | - $champ = new Inclure(); |
|
| 83 | - $champ->ligne = $ligne; |
|
| 84 | - $ligne += substr_count((string) $match[0], "\n"); |
|
| 85 | - $fichier = $match[2]; |
|
| 86 | - # assurer ici la migration .php3 => .php |
|
| 87 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 88 | - if ($fichier && preg_match(',^(.*[.]php)3$,', (string) $fichier, $r)) { |
|
| 89 | - $fichier = $r[1]; |
|
| 90 | - } |
|
| 91 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 92 | - $texte = substr((string) $texte, $p + strlen((string) $match[0])); |
|
| 93 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 94 | - $pos_apres = 0; |
|
| 95 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 96 | - if (!$champ->texte || (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 97 | - if (!function_exists('normaliser_inclure')) { |
|
| 98 | - include_spip('public/normaliser'); |
|
| 99 | - } |
|
| 100 | - normaliser_inclure($champ); |
|
| 101 | - } |
|
| 102 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 103 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 104 | - $result[] = $champ; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 74 | + while (preg_match(BALISE_INCLURE, (string) $texte, $match)) { |
|
| 75 | + $match = array_pad($match, 3, null); |
|
| 76 | + $p = strpos((string) $texte, (string) $match[0]); |
|
| 77 | + $debut = substr((string) $texte, 0, $p); |
|
| 78 | + if ($p) { |
|
| 79 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 80 | + } |
|
| 81 | + $ligne += substr_count($debut, "\n"); |
|
| 82 | + $champ = new Inclure(); |
|
| 83 | + $champ->ligne = $ligne; |
|
| 84 | + $ligne += substr_count((string) $match[0], "\n"); |
|
| 85 | + $fichier = $match[2]; |
|
| 86 | + # assurer ici la migration .php3 => .php |
|
| 87 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 88 | + if ($fichier && preg_match(',^(.*[.]php)3$,', (string) $fichier, $r)) { |
|
| 89 | + $fichier = $r[1]; |
|
| 90 | + } |
|
| 91 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 92 | + $texte = substr((string) $texte, $p + strlen((string) $match[0])); |
|
| 93 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 94 | + $pos_apres = 0; |
|
| 95 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 96 | + if (!$champ->texte || (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 97 | + if (!function_exists('normaliser_inclure')) { |
|
| 98 | + include_spip('public/normaliser'); |
|
| 99 | + } |
|
| 100 | + normaliser_inclure($champ); |
|
| 101 | + } |
|
| 102 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 103 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 104 | + $result[] = $champ; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | function phraser_polyglotte($texte, $ligne, $result) { |
| 111 | 111 | |
| 112 | - if (preg_match_all(BALISE_POLYGLOTTE, (string) $texte, $m, PREG_SET_ORDER)) { |
|
| 113 | - foreach ($m as $match) { |
|
| 114 | - $p = strpos((string) $texte, (string) $match[0]); |
|
| 115 | - $debut = substr((string) $texte, 0, $p); |
|
| 116 | - if ($p) { |
|
| 117 | - $champ = new Texte(); |
|
| 118 | - $champ->texte = $debut; |
|
| 119 | - $champ->ligne = $ligne; |
|
| 120 | - $result[] = $champ; |
|
| 121 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $champ = new Polyglotte(); |
|
| 125 | - $champ->ligne = $ligne; |
|
| 126 | - $ligne += substr_count($match[0], "\n"); |
|
| 127 | - $lang = ''; |
|
| 128 | - $bloc = $match[1]; |
|
| 129 | - $texte = substr((string) $texte, $p + strlen($match[0])); |
|
| 130 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 131 | - $trad = $regs[1]; |
|
| 132 | - if ($trad || $lang) { |
|
| 133 | - $champ->traductions[$lang] = $trad; |
|
| 134 | - } |
|
| 135 | - $lang = $regs[2]; |
|
| 136 | - $bloc = $regs[3]; |
|
| 137 | - } |
|
| 138 | - $champ->traductions[$lang] = $bloc; |
|
| 139 | - $result[] = $champ; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - if ($texte !== '') { |
|
| 143 | - $champ = new Texte(); |
|
| 144 | - $champ->texte = $texte; |
|
| 145 | - $champ->ligne = $ligne; |
|
| 146 | - $result[] = $champ; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $result; |
|
| 112 | + if (preg_match_all(BALISE_POLYGLOTTE, (string) $texte, $m, PREG_SET_ORDER)) { |
|
| 113 | + foreach ($m as $match) { |
|
| 114 | + $p = strpos((string) $texte, (string) $match[0]); |
|
| 115 | + $debut = substr((string) $texte, 0, $p); |
|
| 116 | + if ($p) { |
|
| 117 | + $champ = new Texte(); |
|
| 118 | + $champ->texte = $debut; |
|
| 119 | + $champ->ligne = $ligne; |
|
| 120 | + $result[] = $champ; |
|
| 121 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $champ = new Polyglotte(); |
|
| 125 | + $champ->ligne = $ligne; |
|
| 126 | + $ligne += substr_count($match[0], "\n"); |
|
| 127 | + $lang = ''; |
|
| 128 | + $bloc = $match[1]; |
|
| 129 | + $texte = substr((string) $texte, $p + strlen($match[0])); |
|
| 130 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 131 | + $trad = $regs[1]; |
|
| 132 | + if ($trad || $lang) { |
|
| 133 | + $champ->traductions[$lang] = $trad; |
|
| 134 | + } |
|
| 135 | + $lang = $regs[2]; |
|
| 136 | + $bloc = $regs[3]; |
|
| 137 | + } |
|
| 138 | + $champ->traductions[$lang] = $bloc; |
|
| 139 | + $result[] = $champ; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + if ($texte !== '') { |
|
| 143 | + $champ = new Texte(); |
|
| 144 | + $champ->texte = $texte; |
|
| 145 | + $champ->ligne = $ligne; |
|
| 146 | + $result[] = $champ; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $result; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -168,43 +168,43 @@ discard block |
||
| 168 | 168 | * @return array |
| 169 | 169 | **/ |
| 170 | 170 | function phraser_idiomes($texte, $ligne, $result) { |
| 171 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 172 | - $match = array_pad($match, 8, null); |
|
| 173 | - $p = strpos($texte, (string) $match[0]); |
|
| 174 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 175 | - $debut = substr($texte, 0, $p + ($ko ? strlen((string) $match[0]) : 0)); |
|
| 176 | - if ($debut) { |
|
| 177 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 178 | - } |
|
| 179 | - $texte = substr($texte, $p + strlen((string) $match[0])); |
|
| 180 | - $ligne += substr_count($debut, "\n"); |
|
| 181 | - if ($ko) { |
|
| 182 | - continue; |
|
| 183 | - } // faux idiome |
|
| 184 | - $champ = new Idiome(); |
|
| 185 | - $champ->ligne = $ligne; |
|
| 186 | - $ligne += substr_count((string) $match[0], "\n"); |
|
| 187 | - // Stocker les arguments de la balise de traduction |
|
| 188 | - $args = []; |
|
| 189 | - $largs = $match[5]; |
|
| 190 | - while (preg_match(BALISE_IDIOMES_ARGS, (string) $largs, $r)) { |
|
| 191 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 192 | - $largs = substr((string) $largs, strlen($r[0])); |
|
| 193 | - } |
|
| 194 | - $champ->arg = $args; |
|
| 195 | - $champ->nom_champ = strtolower((string) $match[3]); |
|
| 196 | - $champ->module = $match[2]; |
|
| 197 | - // pas d'imbrication pour les filtres sur langue |
|
| 198 | - $pos_apres = 0; |
|
| 199 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 200 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 201 | - $result[] = $champ; |
|
| 202 | - } |
|
| 203 | - if ($texte !== '') { |
|
| 204 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $result; |
|
| 171 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 172 | + $match = array_pad($match, 8, null); |
|
| 173 | + $p = strpos($texte, (string) $match[0]); |
|
| 174 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 175 | + $debut = substr($texte, 0, $p + ($ko ? strlen((string) $match[0]) : 0)); |
|
| 176 | + if ($debut) { |
|
| 177 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 178 | + } |
|
| 179 | + $texte = substr($texte, $p + strlen((string) $match[0])); |
|
| 180 | + $ligne += substr_count($debut, "\n"); |
|
| 181 | + if ($ko) { |
|
| 182 | + continue; |
|
| 183 | + } // faux idiome |
|
| 184 | + $champ = new Idiome(); |
|
| 185 | + $champ->ligne = $ligne; |
|
| 186 | + $ligne += substr_count((string) $match[0], "\n"); |
|
| 187 | + // Stocker les arguments de la balise de traduction |
|
| 188 | + $args = []; |
|
| 189 | + $largs = $match[5]; |
|
| 190 | + while (preg_match(BALISE_IDIOMES_ARGS, (string) $largs, $r)) { |
|
| 191 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 192 | + $largs = substr((string) $largs, strlen($r[0])); |
|
| 193 | + } |
|
| 194 | + $champ->arg = $args; |
|
| 195 | + $champ->nom_champ = strtolower((string) $match[3]); |
|
| 196 | + $champ->module = $match[2]; |
|
| 197 | + // pas d'imbrication pour les filtres sur langue |
|
| 198 | + $pos_apres = 0; |
|
| 199 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 200 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 201 | + $result[] = $champ; |
|
| 202 | + } |
|
| 203 | + if ($texte !== '') { |
|
| 204 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $result; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -222,47 +222,47 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | **/ |
| 224 | 224 | function phraser_champs($texte, $ligne, $result) { |
| 225 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 226 | - $p = strpos($texte, (string) $match[0]); |
|
| 227 | - // texte après la balise |
|
| 228 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 229 | - |
|
| 230 | - $debut = substr($texte, 0, $p); |
|
| 231 | - if ($p) { |
|
| 232 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 233 | - } |
|
| 234 | - $ligne += substr_count($debut, "\n"); |
|
| 235 | - $champ = new Champ(); |
|
| 236 | - $champ->ligne = $ligne; |
|
| 237 | - $ligne += substr_count($match[0], "\n"); |
|
| 238 | - $champ->nom_boucle = $match[2]; |
|
| 239 | - $champ->nom_champ = $match[3]; |
|
| 240 | - $champ->etoile = $match[5]; |
|
| 241 | - |
|
| 242 | - if ($suite && $suite[0] == '{') { |
|
| 243 | - phraser_arg($suite, '', [], $champ); |
|
| 244 | - // ce ltrim est une ereur de conception |
|
| 245 | - // mais on le conserve par souci de compatibilite |
|
| 246 | - $texte = ltrim((string) $suite); |
|
| 247 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 248 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 249 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 225 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 226 | + $p = strpos($texte, (string) $match[0]); |
|
| 227 | + // texte après la balise |
|
| 228 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 229 | + |
|
| 230 | + $debut = substr($texte, 0, $p); |
|
| 231 | + if ($p) { |
|
| 232 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 233 | + } |
|
| 234 | + $ligne += substr_count($debut, "\n"); |
|
| 235 | + $champ = new Champ(); |
|
| 236 | + $champ->ligne = $ligne; |
|
| 237 | + $ligne += substr_count($match[0], "\n"); |
|
| 238 | + $champ->nom_boucle = $match[2]; |
|
| 239 | + $champ->nom_champ = $match[3]; |
|
| 240 | + $champ->etoile = $match[5]; |
|
| 241 | + |
|
| 242 | + if ($suite && $suite[0] == '{') { |
|
| 243 | + phraser_arg($suite, '', [], $champ); |
|
| 244 | + // ce ltrim est une ereur de conception |
|
| 245 | + // mais on le conserve par souci de compatibilite |
|
| 246 | + $texte = ltrim((string) $suite); |
|
| 247 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 248 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 249 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 250 | 250 | if ($n = (strlen($suite) - strlen($texte))) { |
| 251 | 251 | $champ->apres = array(new Texte); |
| 252 | 252 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 253 | 253 | } |
| 254 | 254 | */ |
| 255 | - } else { |
|
| 256 | - $texte = $suite; |
|
| 257 | - } |
|
| 258 | - phraser_vieux($champ); |
|
| 259 | - $result[] = $champ; |
|
| 260 | - } |
|
| 261 | - if ($texte !== '') { |
|
| 262 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - return $result; |
|
| 255 | + } else { |
|
| 256 | + $texte = $suite; |
|
| 257 | + } |
|
| 258 | + phraser_vieux($champ); |
|
| 259 | + $result[] = $champ; |
|
| 260 | + } |
|
| 261 | + if ($texte !== '') { |
|
| 262 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + return $result; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // Gestion des imbrications: |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 272 | 272 | |
| 273 | 273 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 274 | - if ($texte === '') { |
|
| 275 | - return $result; |
|
| 276 | - } |
|
| 277 | - $sep = '##'; |
|
| 278 | - while (str_contains((string) $texte, (string) $sep)) { |
|
| 279 | - $sep .= '#'; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 274 | + if ($texte === '') { |
|
| 275 | + return $result; |
|
| 276 | + } |
|
| 277 | + $sep = '##'; |
|
| 278 | + while (str_contains((string) $texte, (string) $sep)) { |
|
| 279 | + $sep .= '#'; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -297,275 +297,275 @@ discard block |
||
| 297 | 297 | * @return array |
| 298 | 298 | */ |
| 299 | 299 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 300 | - $length = strlen($texte); |
|
| 301 | - while ($pos_debut < $length && trim($texte[$pos_debut]) === '') { |
|
| 302 | - $pos_debut++; |
|
| 303 | - } |
|
| 304 | - while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 305 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 306 | - $st = substr($texte, $pos_debut); |
|
| 307 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 308 | - $pos_debut = $length - strlen((string) $st); |
|
| 309 | - while ($pos_debut < $length && trim($texte[$pos_debut]) === '') { |
|
| 310 | - $pos_debut++; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $result; |
|
| 300 | + $length = strlen($texte); |
|
| 301 | + while ($pos_debut < $length && trim($texte[$pos_debut]) === '') { |
|
| 302 | + $pos_debut++; |
|
| 303 | + } |
|
| 304 | + while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 305 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 306 | + $st = substr($texte, $pos_debut); |
|
| 307 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 308 | + $pos_debut = $length - strlen((string) $st); |
|
| 309 | + while ($pos_debut < $length && trim($texte[$pos_debut]) === '') { |
|
| 310 | + $pos_debut++; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $result; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 318 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', (string) $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]) || !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((string) $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((string) $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]) && $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', (string) $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]) || !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((string) $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((string) $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]) && $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 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 454 | - $res = []; |
|
| 455 | - while (($p = strpos((string) $texte, (string) "%$sep")) !== false) { |
|
| 456 | - if (!preg_match(',^%' . preg_quote((string) $sep, ',') . '([0-9]+)@,', substr((string) $texte, $p), $m)) { |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - $debut = substr((string) $texte, 0, $p); |
|
| 460 | - $texte = substr((string) $texte, $p + strlen($m[0])); |
|
| 461 | - if ($p) { |
|
| 462 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 463 | - } |
|
| 464 | - $ligne += substr_count($debut, "\n"); |
|
| 465 | - $res[] = $nested[$m[1]]; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 454 | + $res = []; |
|
| 455 | + while (($p = strpos((string) $texte, (string) "%$sep")) !== false) { |
|
| 456 | + if (!preg_match(',^%' . preg_quote((string) $sep, ',') . '([0-9]+)@,', substr((string) $texte, $p), $m)) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + $debut = substr((string) $texte, 0, $p); |
|
| 460 | + $texte = substr((string) $texte, $p + strlen($m[0])); |
|
| 461 | + if ($p) { |
|
| 462 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 463 | + } |
|
| 464 | + $ligne += substr_count($debut, "\n"); |
|
| 465 | + $res[] = $nested[$m[1]]; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 472 | - $i = 0; // en fait count($result) |
|
| 473 | - $x = ''; |
|
| 474 | - |
|
| 475 | - while (true) { |
|
| 476 | - $j = $i; |
|
| 477 | - $n = $ligne; |
|
| 478 | - while (preg_match(CHAMP_ETENDU, (string) $texte, $match)) { |
|
| 479 | - $p = strpos((string) $texte, (string) $match[0]); |
|
| 480 | - $debut = substr((string) $texte, 0, $p); |
|
| 481 | - if ($p) { |
|
| 482 | - $result[$i] = $debut; |
|
| 483 | - $i++; |
|
| 484 | - } |
|
| 485 | - $nom = $match[4]; |
|
| 486 | - $champ = new Champ(); |
|
| 487 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 488 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 489 | - $champ->nom_boucle = $match[3]; |
|
| 490 | - $champ->nom_champ = $nom; |
|
| 491 | - $champ->etoile = $match[6]; |
|
| 492 | - // phraser_args indiquera ou commence apres |
|
| 493 | - $pos_apres = 0; |
|
| 494 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 495 | - phraser_vieux($champ); |
|
| 496 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 497 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 498 | - if (!empty($debut)) { |
|
| 499 | - $n += substr_count(substr((string) $texte, 0, strpos((string) $texte, $debut)), "\n"); |
|
| 500 | - } |
|
| 501 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 502 | - |
|
| 503 | - // reinjecter la boucle si c'en est une |
|
| 504 | - phraser_boucle_placeholder($champ); |
|
| 505 | - |
|
| 506 | - $result[$i] = $champ; |
|
| 507 | - $i++; |
|
| 508 | - $texte = substr((string) $texte, $p + strlen($match[0])); |
|
| 509 | - } |
|
| 510 | - if ($texte !== '') { |
|
| 511 | - $result[$i] = $texte; |
|
| 512 | - $i++; |
|
| 513 | - } |
|
| 514 | - $x = ''; |
|
| 515 | - |
|
| 516 | - while ($j < $i) { |
|
| 517 | - $z = $result[$j]; |
|
| 518 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 519 | - if (is_object($z)) { |
|
| 520 | - $x .= "%$sep$j@"; |
|
| 521 | - } else { |
|
| 522 | - $x .= $z; |
|
| 523 | - } |
|
| 524 | - $j++; |
|
| 525 | - } |
|
| 526 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 527 | - $texte = $x; |
|
| 528 | - } else { |
|
| 529 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 530 | - } |
|
| 531 | - } |
|
| 472 | + $i = 0; // en fait count($result) |
|
| 473 | + $x = ''; |
|
| 474 | + |
|
| 475 | + while (true) { |
|
| 476 | + $j = $i; |
|
| 477 | + $n = $ligne; |
|
| 478 | + while (preg_match(CHAMP_ETENDU, (string) $texte, $match)) { |
|
| 479 | + $p = strpos((string) $texte, (string) $match[0]); |
|
| 480 | + $debut = substr((string) $texte, 0, $p); |
|
| 481 | + if ($p) { |
|
| 482 | + $result[$i] = $debut; |
|
| 483 | + $i++; |
|
| 484 | + } |
|
| 485 | + $nom = $match[4]; |
|
| 486 | + $champ = new Champ(); |
|
| 487 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 488 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 489 | + $champ->nom_boucle = $match[3]; |
|
| 490 | + $champ->nom_champ = $nom; |
|
| 491 | + $champ->etoile = $match[6]; |
|
| 492 | + // phraser_args indiquera ou commence apres |
|
| 493 | + $pos_apres = 0; |
|
| 494 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 495 | + phraser_vieux($champ); |
|
| 496 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 497 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 498 | + if (!empty($debut)) { |
|
| 499 | + $n += substr_count(substr((string) $texte, 0, strpos((string) $texte, $debut)), "\n"); |
|
| 500 | + } |
|
| 501 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 502 | + |
|
| 503 | + // reinjecter la boucle si c'en est une |
|
| 504 | + phraser_boucle_placeholder($champ); |
|
| 505 | + |
|
| 506 | + $result[$i] = $champ; |
|
| 507 | + $i++; |
|
| 508 | + $texte = substr((string) $texte, $p + strlen($match[0])); |
|
| 509 | + } |
|
| 510 | + if ($texte !== '') { |
|
| 511 | + $result[$i] = $texte; |
|
| 512 | + $i++; |
|
| 513 | + } |
|
| 514 | + $x = ''; |
|
| 515 | + |
|
| 516 | + while ($j < $i) { |
|
| 517 | + $z = $result[$j]; |
|
| 518 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 519 | + if (is_object($z)) { |
|
| 520 | + $x .= "%$sep$j@"; |
|
| 521 | + } else { |
|
| 522 | + $x .= $z; |
|
| 523 | + } |
|
| 524 | + $j++; |
|
| 525 | + } |
|
| 526 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 527 | + $texte = $x; |
|
| 528 | + } else { |
|
| 529 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | function phraser_vieux(&$champ) { |
| 535 | - $nom = $champ->nom_champ; |
|
| 536 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 537 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 538 | - include_spip('public/normaliser'); |
|
| 539 | - } |
|
| 540 | - phraser_vieux_emb($champ); |
|
| 541 | - } elseif ($nom == 'EXPOSER') { |
|
| 542 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 543 | - include_spip('public/normaliser'); |
|
| 544 | - } |
|
| 545 | - phraser_vieux_exposer($champ); |
|
| 546 | - } elseif ($champ->param) { |
|
| 547 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 548 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 549 | - include_spip('public/normaliser'); |
|
| 550 | - } |
|
| 551 | - phraser_vieux_recherche($champ); |
|
| 552 | - } elseif (preg_match(',^LOGO_[A-Z]+,', (string) $nom)) { |
|
| 553 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 554 | - include_spip('public/normaliser'); |
|
| 555 | - } |
|
| 556 | - phraser_vieux_logos($champ); |
|
| 557 | - } elseif ($nom == 'MODELE') { |
|
| 558 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 559 | - include_spip('public/normaliser'); |
|
| 560 | - } |
|
| 561 | - phraser_vieux_modele($champ); |
|
| 562 | - } elseif ($nom == 'INCLURE' || $nom == 'INCLUDE') { |
|
| 563 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 564 | - include_spip('public/normaliser'); |
|
| 565 | - } |
|
| 566 | - phraser_vieux_inclu($champ); |
|
| 567 | - } |
|
| 568 | - } |
|
| 535 | + $nom = $champ->nom_champ; |
|
| 536 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 537 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 538 | + include_spip('public/normaliser'); |
|
| 539 | + } |
|
| 540 | + phraser_vieux_emb($champ); |
|
| 541 | + } elseif ($nom == 'EXPOSER') { |
|
| 542 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 543 | + include_spip('public/normaliser'); |
|
| 544 | + } |
|
| 545 | + phraser_vieux_exposer($champ); |
|
| 546 | + } elseif ($champ->param) { |
|
| 547 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 548 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 549 | + include_spip('public/normaliser'); |
|
| 550 | + } |
|
| 551 | + phraser_vieux_recherche($champ); |
|
| 552 | + } elseif (preg_match(',^LOGO_[A-Z]+,', (string) $nom)) { |
|
| 553 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 554 | + include_spip('public/normaliser'); |
|
| 555 | + } |
|
| 556 | + phraser_vieux_logos($champ); |
|
| 557 | + } elseif ($nom == 'MODELE') { |
|
| 558 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 559 | + include_spip('public/normaliser'); |
|
| 560 | + } |
|
| 561 | + phraser_vieux_modele($champ); |
|
| 562 | + } elseif ($nom == 'INCLURE' || $nom == 'INCLUDE') { |
|
| 563 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 564 | + include_spip('public/normaliser'); |
|
| 565 | + } |
|
| 566 | + phraser_vieux_inclu($champ); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -593,199 +593,199 @@ discard block |
||
| 593 | 593 | **/ |
| 594 | 594 | function phraser_criteres($params, &$result) { |
| 595 | 595 | |
| 596 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 597 | - $args = []; |
|
| 598 | - $type = $result->type_requete; |
|
| 599 | - $doublons = []; |
|
| 600 | - foreach ($params as $v) { |
|
| 601 | - $var = $v[1][0]; |
|
| 602 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 603 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', (string) $param))) { |
|
| 604 | - // plus d'un argument et pas le critere IN: |
|
| 605 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 606 | - if ( |
|
| 607 | - $var->type != 'texte' || preg_match('/^(n|n-|(n-)?\d+)$/S', (string) $param) |
|
| 608 | - ) { |
|
| 609 | - $op = ','; |
|
| 610 | - $not = false; |
|
| 611 | - $cond = false; |
|
| 612 | - } else { |
|
| 613 | - // Le debut du premier argument est l'operateur |
|
| 614 | - preg_match('/^([!]?)([a-zA-Z]\w*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', (string) $param, $m); |
|
| 615 | - $op = $m[2]; |
|
| 616 | - $not = (bool) $m[1]; |
|
| 617 | - $cond = (bool) $m[3]; |
|
| 618 | - // virer le premier argument, |
|
| 619 | - // et mettre son reliquat eventuel |
|
| 620 | - // Recopier pour ne pas alterer le texte source |
|
| 621 | - // utile au debusqueur |
|
| 622 | - if ($m[4]) { |
|
| 623 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 624 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 625 | - $c = null; |
|
| 626 | - eval('$c = ' . $m[4] . ';'); |
|
| 627 | - if (isset($c)) { |
|
| 628 | - $m[4] = $c; |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - $texte = new Texte(); |
|
| 632 | - $texte->texte = $m[4]; |
|
| 633 | - $v[1][0] = $texte; |
|
| 634 | - } else { |
|
| 635 | - array_shift($v[1]); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - array_shift($v); // $v[O] est vide |
|
| 639 | - $crit = new Critere(); |
|
| 640 | - $crit->op = $op; |
|
| 641 | - $crit->not = $not; |
|
| 642 | - $crit->cond = $cond; |
|
| 643 | - $crit->exclus = ''; |
|
| 644 | - $crit->param = $v; |
|
| 645 | - $args[] = $crit; |
|
| 646 | - } else { |
|
| 647 | - if ($var->type != 'texte') { |
|
| 648 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 649 | - // erreur ou critere infixe "/" |
|
| 650 | - if (($v[1][1]->type != 'texte') || (trim((string) $v[1][1]->texte) != '/')) { |
|
| 651 | - $err_ci = [ |
|
| 652 | - 'zbug_critere_inconnu', |
|
| 653 | - ['critere' => $var->nom_champ] |
|
| 654 | - ]; |
|
| 655 | - erreur_squelette($err_ci, $result); |
|
| 656 | - } else { |
|
| 657 | - $crit = new Critere(); |
|
| 658 | - $crit->op = '/'; |
|
| 659 | - $crit->not = false; |
|
| 660 | - $crit->exclus = ''; |
|
| 661 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 662 | - $args[] = $crit; |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 666 | - // les separateurs |
|
| 667 | - if ($var->apres) { |
|
| 668 | - $result->separateur[] = $param; |
|
| 669 | - } elseif ($param == 'tout' || $param == 'tous') { |
|
| 670 | - $result->modificateur['tout'] = true; |
|
| 671 | - } elseif ($param == 'plat') { |
|
| 672 | - $result->modificateur['plat'] = true; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 676 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 677 | - // ceux-ci pour avoir la rubrique mere... |
|
| 678 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 679 | - // traités normalement. |
|
| 680 | - elseif ( |
|
| 681 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 682 | - && !preg_match(",^id_rubrique\b,", (string) $param) |
|
| 683 | - && preg_match(',^id_\w+\s*$,', (string) $param) |
|
| 684 | - ) { |
|
| 685 | - $result->modificateur['tout'] = true; |
|
| 686 | - } elseif (strcasecmp($type, 'hierarchie') == 0 && $param == 'id_rubrique') { |
|
| 687 | - // rien a faire sur {id_rubrique} tout seul |
|
| 688 | - } else { |
|
| 689 | - // pas d'emplacement statique, faut un dynamique |
|
| 690 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 691 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', (string) $param))) { |
|
| 692 | - // cette variable sera inseree dans le code |
|
| 693 | - // et son nom sert d'indicateur des maintenant |
|
| 694 | - $result->doublons = '$doublons_index'; |
|
| 695 | - if ($param == 'unique') { |
|
| 696 | - $param = 'doublons'; |
|
| 697 | - } |
|
| 698 | - } elseif ($param == 'recherche') { |
|
| 699 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 700 | - $result->hash = ' '; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) { |
|
| 704 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 705 | - } elseif ( |
|
| 706 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 707 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m) |
|
| 708 | - ) { |
|
| 709 | - $a2 = trim($m[8]); |
|
| 710 | - if ($a2 && ($a2[0] == "'" || $a2[0] == '"') && $a2[0] == substr($a2, -1)) { |
|
| 711 | - $a2 = substr($a2, 1, -1); |
|
| 712 | - } |
|
| 713 | - $crit = phraser_critere_infixe( |
|
| 714 | - $m[2], |
|
| 715 | - $a2, |
|
| 716 | - $v, |
|
| 717 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 718 | - $m[6], |
|
| 719 | - $m[5] |
|
| 720 | - ); |
|
| 721 | - $crit->exclus = $m[1]; |
|
| 722 | - } elseif ( |
|
| 723 | - preg_match('/^([!]?)\s*(' . |
|
| 724 | - CHAMP_SQL_PLUS_FONC . |
|
| 725 | - ')\s*(\??)(.*)$/is', (string) $param, $m) |
|
| 726 | - ) { |
|
| 727 | - // contient aussi les comparaisons implicites ! |
|
| 728 | - // Comme ci-dessus: |
|
| 729 | - // le premier arg contient l'operateur |
|
| 730 | - array_shift($v); |
|
| 731 | - if ($m[6]) { |
|
| 732 | - $v[0][0] = new Texte(); |
|
| 733 | - $v[0][0]->texte = $m[6]; |
|
| 734 | - } else { |
|
| 735 | - array_shift($v[0]); |
|
| 736 | - if (!$v[0]) { |
|
| 737 | - array_shift($v); |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - $crit = new Critere(); |
|
| 741 | - $crit->op = $m[2]; |
|
| 742 | - $crit->param = $v; |
|
| 743 | - $crit->not = (bool) $m[1]; |
|
| 744 | - $crit->cond = (bool) $m[5]; |
|
| 745 | - } else { |
|
| 746 | - $err_ci = [ |
|
| 747 | - 'zbug_critere_inconnu', |
|
| 748 | - ['critere' => $param] |
|
| 749 | - ]; |
|
| 750 | - erreur_squelette($err_ci, $result); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if ((!preg_match(',^!?doublons *,', (string) $param)) || $crit->not) { |
|
| 754 | - $args[] = $crit; |
|
| 755 | - } else { |
|
| 756 | - $doublons[] = $crit; |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - // les doublons non nies doivent etre le dernier critere |
|
| 764 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 765 | - // cf critere_doublon |
|
| 766 | - if ($doublons) { |
|
| 767 | - $args = [...$args, ...$doublons]; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 771 | - if (!$err_ci) { |
|
| 772 | - $result->criteres = $args; |
|
| 773 | - } |
|
| 596 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 597 | + $args = []; |
|
| 598 | + $type = $result->type_requete; |
|
| 599 | + $doublons = []; |
|
| 600 | + foreach ($params as $v) { |
|
| 601 | + $var = $v[1][0]; |
|
| 602 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 603 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', (string) $param))) { |
|
| 604 | + // plus d'un argument et pas le critere IN: |
|
| 605 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 606 | + if ( |
|
| 607 | + $var->type != 'texte' || preg_match('/^(n|n-|(n-)?\d+)$/S', (string) $param) |
|
| 608 | + ) { |
|
| 609 | + $op = ','; |
|
| 610 | + $not = false; |
|
| 611 | + $cond = false; |
|
| 612 | + } else { |
|
| 613 | + // Le debut du premier argument est l'operateur |
|
| 614 | + preg_match('/^([!]?)([a-zA-Z]\w*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', (string) $param, $m); |
|
| 615 | + $op = $m[2]; |
|
| 616 | + $not = (bool) $m[1]; |
|
| 617 | + $cond = (bool) $m[3]; |
|
| 618 | + // virer le premier argument, |
|
| 619 | + // et mettre son reliquat eventuel |
|
| 620 | + // Recopier pour ne pas alterer le texte source |
|
| 621 | + // utile au debusqueur |
|
| 622 | + if ($m[4]) { |
|
| 623 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 624 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 625 | + $c = null; |
|
| 626 | + eval('$c = ' . $m[4] . ';'); |
|
| 627 | + if (isset($c)) { |
|
| 628 | + $m[4] = $c; |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + $texte = new Texte(); |
|
| 632 | + $texte->texte = $m[4]; |
|
| 633 | + $v[1][0] = $texte; |
|
| 634 | + } else { |
|
| 635 | + array_shift($v[1]); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + array_shift($v); // $v[O] est vide |
|
| 639 | + $crit = new Critere(); |
|
| 640 | + $crit->op = $op; |
|
| 641 | + $crit->not = $not; |
|
| 642 | + $crit->cond = $cond; |
|
| 643 | + $crit->exclus = ''; |
|
| 644 | + $crit->param = $v; |
|
| 645 | + $args[] = $crit; |
|
| 646 | + } else { |
|
| 647 | + if ($var->type != 'texte') { |
|
| 648 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 649 | + // erreur ou critere infixe "/" |
|
| 650 | + if (($v[1][1]->type != 'texte') || (trim((string) $v[1][1]->texte) != '/')) { |
|
| 651 | + $err_ci = [ |
|
| 652 | + 'zbug_critere_inconnu', |
|
| 653 | + ['critere' => $var->nom_champ] |
|
| 654 | + ]; |
|
| 655 | + erreur_squelette($err_ci, $result); |
|
| 656 | + } else { |
|
| 657 | + $crit = new Critere(); |
|
| 658 | + $crit->op = '/'; |
|
| 659 | + $crit->not = false; |
|
| 660 | + $crit->exclus = ''; |
|
| 661 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 662 | + $args[] = $crit; |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 666 | + // les separateurs |
|
| 667 | + if ($var->apres) { |
|
| 668 | + $result->separateur[] = $param; |
|
| 669 | + } elseif ($param == 'tout' || $param == 'tous') { |
|
| 670 | + $result->modificateur['tout'] = true; |
|
| 671 | + } elseif ($param == 'plat') { |
|
| 672 | + $result->modificateur['plat'] = true; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 676 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 677 | + // ceux-ci pour avoir la rubrique mere... |
|
| 678 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 679 | + // traités normalement. |
|
| 680 | + elseif ( |
|
| 681 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 682 | + && !preg_match(",^id_rubrique\b,", (string) $param) |
|
| 683 | + && preg_match(',^id_\w+\s*$,', (string) $param) |
|
| 684 | + ) { |
|
| 685 | + $result->modificateur['tout'] = true; |
|
| 686 | + } elseif (strcasecmp($type, 'hierarchie') == 0 && $param == 'id_rubrique') { |
|
| 687 | + // rien a faire sur {id_rubrique} tout seul |
|
| 688 | + } else { |
|
| 689 | + // pas d'emplacement statique, faut un dynamique |
|
| 690 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 691 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', (string) $param))) { |
|
| 692 | + // cette variable sera inseree dans le code |
|
| 693 | + // et son nom sert d'indicateur des maintenant |
|
| 694 | + $result->doublons = '$doublons_index'; |
|
| 695 | + if ($param == 'unique') { |
|
| 696 | + $param = 'doublons'; |
|
| 697 | + } |
|
| 698 | + } elseif ($param == 'recherche') { |
|
| 699 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 700 | + $result->hash = ' '; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) { |
|
| 704 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 705 | + } elseif ( |
|
| 706 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 707 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m) |
|
| 708 | + ) { |
|
| 709 | + $a2 = trim($m[8]); |
|
| 710 | + if ($a2 && ($a2[0] == "'" || $a2[0] == '"') && $a2[0] == substr($a2, -1)) { |
|
| 711 | + $a2 = substr($a2, 1, -1); |
|
| 712 | + } |
|
| 713 | + $crit = phraser_critere_infixe( |
|
| 714 | + $m[2], |
|
| 715 | + $a2, |
|
| 716 | + $v, |
|
| 717 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 718 | + $m[6], |
|
| 719 | + $m[5] |
|
| 720 | + ); |
|
| 721 | + $crit->exclus = $m[1]; |
|
| 722 | + } elseif ( |
|
| 723 | + preg_match('/^([!]?)\s*(' . |
|
| 724 | + CHAMP_SQL_PLUS_FONC . |
|
| 725 | + ')\s*(\??)(.*)$/is', (string) $param, $m) |
|
| 726 | + ) { |
|
| 727 | + // contient aussi les comparaisons implicites ! |
|
| 728 | + // Comme ci-dessus: |
|
| 729 | + // le premier arg contient l'operateur |
|
| 730 | + array_shift($v); |
|
| 731 | + if ($m[6]) { |
|
| 732 | + $v[0][0] = new Texte(); |
|
| 733 | + $v[0][0]->texte = $m[6]; |
|
| 734 | + } else { |
|
| 735 | + array_shift($v[0]); |
|
| 736 | + if (!$v[0]) { |
|
| 737 | + array_shift($v); |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + $crit = new Critere(); |
|
| 741 | + $crit->op = $m[2]; |
|
| 742 | + $crit->param = $v; |
|
| 743 | + $crit->not = (bool) $m[1]; |
|
| 744 | + $crit->cond = (bool) $m[5]; |
|
| 745 | + } else { |
|
| 746 | + $err_ci = [ |
|
| 747 | + 'zbug_critere_inconnu', |
|
| 748 | + ['critere' => $param] |
|
| 749 | + ]; |
|
| 750 | + erreur_squelette($err_ci, $result); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + if ((!preg_match(',^!?doublons *,', (string) $param)) || $crit->not) { |
|
| 754 | + $args[] = $crit; |
|
| 755 | + } else { |
|
| 756 | + $doublons[] = $crit; |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + // les doublons non nies doivent etre le dernier critere |
|
| 764 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 765 | + // cf critere_doublon |
|
| 766 | + if ($doublons) { |
|
| 767 | + $args = [...$args, ...$doublons]; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 771 | + if (!$err_ci) { |
|
| 772 | + $result->criteres = $args; |
|
| 773 | + } |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 777 | - $args[0] = new Texte(); |
|
| 778 | - $args[0]->texte = $arg1; |
|
| 779 | - $args[0] = [$args[0]]; |
|
| 780 | - $args[1][0] = new Texte(); |
|
| 781 | - $args[1][0]->texte = $arg2; |
|
| 782 | - $crit = new Critere(); |
|
| 783 | - $crit->op = $op; |
|
| 784 | - $crit->not = $not; |
|
| 785 | - $crit->cond = $cond; |
|
| 786 | - $crit->param = $args; |
|
| 787 | - |
|
| 788 | - return $crit; |
|
| 777 | + $args[0] = new Texte(); |
|
| 778 | + $args[0]->texte = $arg1; |
|
| 779 | + $args[0] = [$args[0]]; |
|
| 780 | + $args[1][0] = new Texte(); |
|
| 781 | + $args[1][0]->texte = $arg2; |
|
| 782 | + $crit = new Critere(); |
|
| 783 | + $crit->op = $op; |
|
| 784 | + $crit->not = $not; |
|
| 785 | + $crit->cond = $cond; |
|
| 786 | + $crit->param = $args; |
|
| 787 | + |
|
| 788 | + return $crit; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -796,12 +796,12 @@ discard block |
||
| 796 | 796 | * @return int |
| 797 | 797 | */ |
| 798 | 798 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 799 | - if (is_null($fin)) { |
|
| 800 | - return substr_count((string) $texte, "\n", $debut); |
|
| 801 | - } |
|
| 802 | - else { |
|
| 803 | - return substr_count((string) $texte, "\n", $debut, $fin - $debut); |
|
| 804 | - } |
|
| 799 | + if (is_null($fin)) { |
|
| 800 | + return substr_count((string) $texte, "\n", $debut); |
|
| 801 | + } |
|
| 802 | + else { |
|
| 803 | + return substr_count((string) $texte, "\n", $debut, $fin - $debut); |
|
| 804 | + } |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | |
@@ -817,87 +817,87 @@ discard block |
||
| 817 | 817 | * @return array|null |
| 818 | 818 | */ |
| 819 | 819 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 820 | - $premiere_boucle = null; |
|
| 821 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 822 | - |
|
| 823 | - $current_pos = $pos_debut_texte; |
|
| 824 | - while (($pos_boucle = strpos((string) $texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 825 | - $current_pos = $pos_boucle + 1; |
|
| 826 | - $pos_parent = strpos((string) $texte, '(', $pos_boucle); |
|
| 827 | - |
|
| 828 | - $id_boucle = ''; |
|
| 829 | - if ($pos_parent !== false) { |
|
| 830 | - $id_boucle = trim(substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 831 | - } |
|
| 832 | - if ( |
|
| 833 | - $pos_parent === false |
|
| 834 | - || strlen($id_boucle) && (!is_numeric($id_boucle) && !str_starts_with($id_boucle, '_')) |
|
| 835 | - ) { |
|
| 836 | - $result = new Boucle(); |
|
| 837 | - $result->id_parent = $id_parent; |
|
| 838 | - $result->descr = $descr; |
|
| 839 | - |
|
| 840 | - // un id_boucle pour l'affichage de l'erreur |
|
| 841 | - if (!strlen($id_boucle)) { |
|
| 842 | - $id_boucle = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 843 | - } |
|
| 844 | - $result->id_boucle = $id_boucle; |
|
| 845 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 846 | - erreur_squelette($err_b, $result); |
|
| 847 | - |
|
| 848 | - continue; |
|
| 849 | - } |
|
| 850 | - else { |
|
| 851 | - $boucle = [ |
|
| 852 | - 'id_boucle' => $id_boucle, |
|
| 853 | - 'id_boucle_err' => $id_boucle, |
|
| 854 | - 'debut_boucle' => $pos_boucle, |
|
| 855 | - 'pos_boucle' => $pos_boucle, |
|
| 856 | - 'pos_parent' => $pos_parent, |
|
| 857 | - 'pos_precond' => false, |
|
| 858 | - 'pos_precond_inside' => false, |
|
| 859 | - 'pos_preaff' => false, |
|
| 860 | - 'pos_preaff_inside' => false, |
|
| 861 | - ]; |
|
| 862 | - |
|
| 863 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 864 | - if (!strlen($id_boucle)) { |
|
| 865 | - $boucle['id_boucle_err'] = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 869 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 870 | - $pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 871 | - if ( |
|
| 872 | - $pos_precond !== false |
|
| 873 | - && $pos_precond < $boucle['debut_boucle'] |
|
| 874 | - ) { |
|
| 875 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 876 | - $boucle['pos_precond'] = $pos_precond; |
|
| 877 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 881 | - $pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 882 | - if ( |
|
| 883 | - $pos_preaff !== false |
|
| 884 | - && $pos_preaff < $boucle['debut_boucle'] |
|
| 885 | - ) { |
|
| 886 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 887 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 888 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 889 | - } |
|
| 890 | - if (!strlen($id_boucle)) { |
|
| 891 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - if (is_null($premiere_boucle) || $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 895 | - $premiere_boucle = $boucle; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - return $premiere_boucle; |
|
| 820 | + $premiere_boucle = null; |
|
| 821 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 822 | + |
|
| 823 | + $current_pos = $pos_debut_texte; |
|
| 824 | + while (($pos_boucle = strpos((string) $texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 825 | + $current_pos = $pos_boucle + 1; |
|
| 826 | + $pos_parent = strpos((string) $texte, '(', $pos_boucle); |
|
| 827 | + |
|
| 828 | + $id_boucle = ''; |
|
| 829 | + if ($pos_parent !== false) { |
|
| 830 | + $id_boucle = trim(substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 831 | + } |
|
| 832 | + if ( |
|
| 833 | + $pos_parent === false |
|
| 834 | + || strlen($id_boucle) && (!is_numeric($id_boucle) && !str_starts_with($id_boucle, '_')) |
|
| 835 | + ) { |
|
| 836 | + $result = new Boucle(); |
|
| 837 | + $result->id_parent = $id_parent; |
|
| 838 | + $result->descr = $descr; |
|
| 839 | + |
|
| 840 | + // un id_boucle pour l'affichage de l'erreur |
|
| 841 | + if (!strlen($id_boucle)) { |
|
| 842 | + $id_boucle = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 843 | + } |
|
| 844 | + $result->id_boucle = $id_boucle; |
|
| 845 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 846 | + erreur_squelette($err_b, $result); |
|
| 847 | + |
|
| 848 | + continue; |
|
| 849 | + } |
|
| 850 | + else { |
|
| 851 | + $boucle = [ |
|
| 852 | + 'id_boucle' => $id_boucle, |
|
| 853 | + 'id_boucle_err' => $id_boucle, |
|
| 854 | + 'debut_boucle' => $pos_boucle, |
|
| 855 | + 'pos_boucle' => $pos_boucle, |
|
| 856 | + 'pos_parent' => $pos_parent, |
|
| 857 | + 'pos_precond' => false, |
|
| 858 | + 'pos_precond_inside' => false, |
|
| 859 | + 'pos_preaff' => false, |
|
| 860 | + 'pos_preaff_inside' => false, |
|
| 861 | + ]; |
|
| 862 | + |
|
| 863 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 864 | + if (!strlen($id_boucle)) { |
|
| 865 | + $boucle['id_boucle_err'] = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 869 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 870 | + $pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 871 | + if ( |
|
| 872 | + $pos_precond !== false |
|
| 873 | + && $pos_precond < $boucle['debut_boucle'] |
|
| 874 | + ) { |
|
| 875 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 876 | + $boucle['pos_precond'] = $pos_precond; |
|
| 877 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 881 | + $pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 882 | + if ( |
|
| 883 | + $pos_preaff !== false |
|
| 884 | + && $pos_preaff < $boucle['debut_boucle'] |
|
| 885 | + ) { |
|
| 886 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 887 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 888 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 889 | + } |
|
| 890 | + if (!strlen($id_boucle)) { |
|
| 891 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + if (is_null($premiere_boucle) || $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 895 | + $premiere_boucle = $boucle; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + return $premiere_boucle; |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -912,68 +912,68 @@ discard block |
||
| 912 | 912 | * @return mixed |
| 913 | 913 | */ |
| 914 | 914 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 915 | - $id_boucle = $boucle['id_boucle']; |
|
| 916 | - $pos_courante = $pos_debut_texte; |
|
| 917 | - |
|
| 918 | - $boucle['pos_postcond'] = false; |
|
| 919 | - $boucle['pos_postcond_inside'] = false; |
|
| 920 | - $boucle['pos_altern'] = false; |
|
| 921 | - $boucle['pos_altern_inside'] = false; |
|
| 922 | - $boucle['pos_postaff'] = false; |
|
| 923 | - $boucle['pos_postaff_inside'] = false; |
|
| 924 | - |
|
| 925 | - $pos_anonyme_next = null; |
|
| 926 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 927 | - if (!strlen((string) $id_boucle)) { |
|
| 928 | - $pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - // |
|
| 932 | - // 1. Recuperer la partie conditionnelle apres |
|
| 933 | - // |
|
| 934 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 935 | - $pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante); |
|
| 936 | - if ( |
|
| 937 | - $pos_apres !== false |
|
| 938 | - && (!$pos_anonyme_next || $pos_apres < $pos_anonyme_next) |
|
| 939 | - ) { |
|
| 940 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 941 | - $pos_apres += strlen($apres_boucle); |
|
| 942 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 943 | - $pos_courante = $pos_apres ; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - // |
|
| 947 | - // 2. Récuperer la partie alternative apres |
|
| 948 | - // |
|
| 949 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 950 | - $pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante); |
|
| 951 | - if ( |
|
| 952 | - $pos_altern !== false |
|
| 953 | - && (!$pos_anonyme_next || $pos_altern < $pos_anonyme_next) |
|
| 954 | - ) { |
|
| 955 | - $boucle['pos_altern'] = $pos_altern; |
|
| 956 | - $pos_altern += strlen($altern_boucle); |
|
| 957 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 958 | - $pos_courante = $pos_altern; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - // |
|
| 962 | - // 3. Recuperer la partie footer non alternative |
|
| 963 | - // |
|
| 964 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 965 | - $pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante); |
|
| 966 | - if ( |
|
| 967 | - $pos_postaff !== false |
|
| 968 | - && (!$pos_anonyme_next || $pos_postaff < $pos_anonyme_next) |
|
| 969 | - ) { |
|
| 970 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 971 | - $pos_postaff += strlen($postaff_boucle); |
|
| 972 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 973 | - $pos_courante = $pos_postaff ; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - return $boucle; |
|
| 915 | + $id_boucle = $boucle['id_boucle']; |
|
| 916 | + $pos_courante = $pos_debut_texte; |
|
| 917 | + |
|
| 918 | + $boucle['pos_postcond'] = false; |
|
| 919 | + $boucle['pos_postcond_inside'] = false; |
|
| 920 | + $boucle['pos_altern'] = false; |
|
| 921 | + $boucle['pos_altern_inside'] = false; |
|
| 922 | + $boucle['pos_postaff'] = false; |
|
| 923 | + $boucle['pos_postaff_inside'] = false; |
|
| 924 | + |
|
| 925 | + $pos_anonyme_next = null; |
|
| 926 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 927 | + if (!strlen((string) $id_boucle)) { |
|
| 928 | + $pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + // |
|
| 932 | + // 1. Recuperer la partie conditionnelle apres |
|
| 933 | + // |
|
| 934 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 935 | + $pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante); |
|
| 936 | + if ( |
|
| 937 | + $pos_apres !== false |
|
| 938 | + && (!$pos_anonyme_next || $pos_apres < $pos_anonyme_next) |
|
| 939 | + ) { |
|
| 940 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 941 | + $pos_apres += strlen($apres_boucle); |
|
| 942 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 943 | + $pos_courante = $pos_apres ; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + // |
|
| 947 | + // 2. Récuperer la partie alternative apres |
|
| 948 | + // |
|
| 949 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 950 | + $pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante); |
|
| 951 | + if ( |
|
| 952 | + $pos_altern !== false |
|
| 953 | + && (!$pos_anonyme_next || $pos_altern < $pos_anonyme_next) |
|
| 954 | + ) { |
|
| 955 | + $boucle['pos_altern'] = $pos_altern; |
|
| 956 | + $pos_altern += strlen($altern_boucle); |
|
| 957 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 958 | + $pos_courante = $pos_altern; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + // |
|
| 962 | + // 3. Recuperer la partie footer non alternative |
|
| 963 | + // |
|
| 964 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 965 | + $pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante); |
|
| 966 | + if ( |
|
| 967 | + $pos_postaff !== false |
|
| 968 | + && (!$pos_anonyme_next || $pos_postaff < $pos_anonyme_next) |
|
| 969 | + ) { |
|
| 970 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 971 | + $pos_postaff += strlen($postaff_boucle); |
|
| 972 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 973 | + $pos_courante = $pos_postaff ; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + return $boucle; |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | |
@@ -983,21 +983,21 @@ discard block |
||
| 983 | 983 | * @param null|object $boucle |
| 984 | 984 | */ |
| 985 | 985 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 986 | - static $boucles_connues = []; |
|
| 987 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 988 | - if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) { |
|
| 989 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 990 | - } |
|
| 991 | - else { |
|
| 992 | - if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) { |
|
| 993 | - $placeholder = $champ->nom_champ; |
|
| 994 | - $id = reset($champ->param[0][1]); |
|
| 995 | - $id = $id->texte; |
|
| 996 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 997 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 998 | - } |
|
| 999 | - } |
|
| 1000 | - } |
|
| 986 | + static $boucles_connues = []; |
|
| 987 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 988 | + if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) { |
|
| 989 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 990 | + } |
|
| 991 | + else { |
|
| 992 | + if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) { |
|
| 993 | + $placeholder = $champ->nom_champ; |
|
| 994 | + $id = reset($champ->param[0][1]); |
|
| 995 | + $id = $id->texte; |
|
| 996 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 997 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 998 | + } |
|
| 999 | + } |
|
| 1000 | + } |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | |
@@ -1010,272 +1010,272 @@ discard block |
||
| 1010 | 1010 | * @return string |
| 1011 | 1011 | */ |
| 1012 | 1012 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1013 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1014 | - //memoriser la boucle a reinjecter |
|
| 1015 | - $id_boucle = "$id_boucle"; |
|
| 1016 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1017 | - return $placeholder; |
|
| 1013 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1014 | + //memoriser la boucle a reinjecter |
|
| 1015 | + $id_boucle = "$id_boucle"; |
|
| 1016 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1017 | + return $placeholder; |
|
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1021 | 1021 | |
| 1022 | - $all_res = []; |
|
| 1023 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1024 | - if (is_null($boucle_placeholder)) { |
|
| 1025 | - do { |
|
| 1026 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1027 | - } while (str_contains((string) $texte, $boucle_placeholder)); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1031 | - $pos_debut_texte = 0; |
|
| 1032 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1033 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1034 | - $result = new Boucle(); |
|
| 1035 | - $result->id_parent = $id_parent; |
|
| 1036 | - $result->descr = $descr; |
|
| 1037 | - |
|
| 1038 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1039 | - $pos_parent = $boucle['pos_parent']; |
|
| 1040 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1041 | - |
|
| 1042 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1043 | - |
|
| 1044 | - // boucle anonyme ? |
|
| 1045 | - if (!strlen((string) $id_boucle)) { |
|
| 1046 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - $pos_debut_boucle = $pos_courante; |
|
| 1050 | - |
|
| 1051 | - $pos_milieu = $pos_parent; |
|
| 1052 | - |
|
| 1053 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1054 | - if ($boucle['pos_precond'] !== false) { |
|
| 1055 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1056 | - |
|
| 1057 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1058 | - $result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1059 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1063 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1064 | - $end_preaff = $pos_debut_boucle; |
|
| 1065 | - |
|
| 1066 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1067 | - $result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1068 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - $result->id_boucle = $id_boucle; |
|
| 1072 | - |
|
| 1073 | - if ( |
|
| 1074 | - !preg_match(SPEC_BOUCLE, (string) $texte, $match, 0, $pos_milieu) |
|
| 1075 | - || ($pos_match = strpos((string) $texte, (string) $match[0], $pos_milieu)) === false |
|
| 1076 | - || $pos_match > $pos_milieu |
|
| 1077 | - ) { |
|
| 1078 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1079 | - erreur_squelette($err_b, $result); |
|
| 1080 | - |
|
| 1081 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1082 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1083 | - continue; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - $result->type_requete = $match[0]; |
|
| 1087 | - $pos_milieu += strlen($match[0]); |
|
| 1088 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1089 | - |
|
| 1090 | - $type = $match[1]; |
|
| 1091 | - $jointures = trim($match[2]); |
|
| 1092 | - $table_optionnelle = ($match[3]); |
|
| 1093 | - if ($jointures) { |
|
| 1094 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1095 | - // ou elles seront completees des jointures declarees |
|
| 1096 | - $result->jointures_explicites = $jointures; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - if ($table_optionnelle) { |
|
| 1100 | - $result->table_optionnelle = $type; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1104 | - // Resultat mis dans result->param |
|
| 1105 | - $pos_fin_criteres = $pos_milieu; |
|
| 1106 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1107 | - |
|
| 1108 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1109 | - // pour l'instant on met le source (chaine) : |
|
| 1110 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1111 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1112 | - $result->criteres = substr((string) $texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1113 | - $pos_milieu = $pos_fin_criteres; |
|
| 1114 | - |
|
| 1115 | - // |
|
| 1116 | - // Recuperer la fin : |
|
| 1117 | - // |
|
| 1118 | - if ($texte[$pos_milieu] === '/') { |
|
| 1119 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1120 | - $pos_courante += 2; |
|
| 1121 | - $result->milieu = ''; |
|
| 1122 | - } else { |
|
| 1123 | - $pos_milieu += 1; |
|
| 1124 | - |
|
| 1125 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1126 | - $pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu); |
|
| 1127 | - if ($pos_fin === false) { |
|
| 1128 | - $err_b = [ |
|
| 1129 | - 'zbug_erreur_boucle_fermant', |
|
| 1130 | - ['id' => $id_boucle] |
|
| 1131 | - ]; |
|
| 1132 | - erreur_squelette($err_b, $result); |
|
| 1133 | - $pos_courante += strlen($fin_boucle); |
|
| 1134 | - } |
|
| 1135 | - else { |
|
| 1136 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1137 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1138 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1139 | - $search_from = $pos_milieu; |
|
| 1140 | - $nb_open = 1; |
|
| 1141 | - $nb_close = 1; |
|
| 1142 | - $maxiter = 0; |
|
| 1143 | - do { |
|
| 1144 | - while ( |
|
| 1145 | - $nb_close < $nb_open |
|
| 1146 | - && ($p = strpos((string) $texte, $fin_boucle, $pos_fin + 1)) |
|
| 1147 | - ) { |
|
| 1148 | - $nb_close++; |
|
| 1149 | - $pos_fin = $p; |
|
| 1150 | - } |
|
| 1151 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1152 | - if ($nb_close < $nb_open) { |
|
| 1153 | - break; |
|
| 1154 | - } |
|
| 1155 | - while ( |
|
| 1156 | - ($p = strpos((string) $texte, $search_debut_boucle, $search_from)) |
|
| 1157 | - && $p < $pos_fin |
|
| 1158 | - ) { |
|
| 1159 | - $nb_open++; |
|
| 1160 | - $search_from = $p + 1; |
|
| 1161 | - } |
|
| 1162 | - } while ($nb_close < $nb_open && $maxiter++ < 5); |
|
| 1163 | - |
|
| 1164 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1165 | - } |
|
| 1166 | - $result->milieu = substr((string) $texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1170 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1171 | - |
|
| 1172 | - // |
|
| 1173 | - // 1. Partie conditionnelle apres ? |
|
| 1174 | - // |
|
| 1175 | - if ($boucle['pos_postcond']) { |
|
| 1176 | - $result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1177 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1178 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - // |
|
| 1183 | - // 2. Partie alternative apres ? |
|
| 1184 | - // |
|
| 1185 | - $ligne_altern = $ligne_suite; |
|
| 1186 | - if ($boucle['pos_altern']) { |
|
| 1187 | - $result->altern = substr((string) $texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1188 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1189 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - // |
|
| 1193 | - // 3. Partie footer non alternative ? |
|
| 1194 | - // |
|
| 1195 | - $ligne_postaff = $ligne_suite; |
|
| 1196 | - if ($boucle['pos_postaff']) { |
|
| 1197 | - $result->postaff = substr((string) $texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1198 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1199 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - $result->ligne = $ligne_preaff; |
|
| 1203 | - |
|
| 1204 | - if ($p = strpos($type, ':')) { |
|
| 1205 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1206 | - $type = substr($type, $p + 1); |
|
| 1207 | - } |
|
| 1208 | - $soustype = strtolower($type); |
|
| 1209 | - |
|
| 1210 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1211 | - $soustype = $type; |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - $result->type_requete = $soustype; |
|
| 1215 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1216 | - if (!is_array($result->param)) { |
|
| 1217 | - $err_b = true; |
|
| 1218 | - } else { |
|
| 1219 | - phraser_criteres($result->param, $result); |
|
| 1220 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1221 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1222 | - $args = $result->param; |
|
| 1223 | - array_unshift( |
|
| 1224 | - $args, |
|
| 1225 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1226 | - ); |
|
| 1227 | - $result->param = $args; |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1232 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1233 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1234 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1235 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1236 | - if (empty($boucles[$id_boucle])) { |
|
| 1237 | - $boucles[$id_boucle] = null; |
|
| 1238 | - } |
|
| 1239 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1240 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1241 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1242 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1243 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1244 | - |
|
| 1245 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1246 | - if ($err_b) { |
|
| 1247 | - $result->type_requete = false; |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - // Verifier qu'il n'y a pas double definition |
|
| 1251 | - // apres analyse des sous-parties (pas avant). |
|
| 1252 | - if (!empty($boucles[$id_boucle])) { |
|
| 1253 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1254 | - $err_b_d = [ |
|
| 1255 | - 'zbug_erreur_boucle_double', |
|
| 1256 | - ['id' => $id_boucle] |
|
| 1257 | - ]; |
|
| 1258 | - erreur_squelette($err_b_d, $result); |
|
| 1259 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1260 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1261 | - } |
|
| 1262 | - } else { |
|
| 1263 | - $boucles[$id_boucle] = $result; |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1267 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1268 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1269 | - $texte = substr_replace((string) $texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1270 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1271 | - |
|
| 1272 | - // phraser la partie avant le debut de la boucle |
|
| 1273 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1274 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1275 | - |
|
| 1276 | - $ligne_debut_texte = $ligne_suite; |
|
| 1277 | - $pos_debut_texte = $pos_courante; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - return phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1022 | + $all_res = []; |
|
| 1023 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1024 | + if (is_null($boucle_placeholder)) { |
|
| 1025 | + do { |
|
| 1026 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1027 | + } while (str_contains((string) $texte, $boucle_placeholder)); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1031 | + $pos_debut_texte = 0; |
|
| 1032 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1033 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1034 | + $result = new Boucle(); |
|
| 1035 | + $result->id_parent = $id_parent; |
|
| 1036 | + $result->descr = $descr; |
|
| 1037 | + |
|
| 1038 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1039 | + $pos_parent = $boucle['pos_parent']; |
|
| 1040 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1041 | + |
|
| 1042 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1043 | + |
|
| 1044 | + // boucle anonyme ? |
|
| 1045 | + if (!strlen((string) $id_boucle)) { |
|
| 1046 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + $pos_debut_boucle = $pos_courante; |
|
| 1050 | + |
|
| 1051 | + $pos_milieu = $pos_parent; |
|
| 1052 | + |
|
| 1053 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1054 | + if ($boucle['pos_precond'] !== false) { |
|
| 1055 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1056 | + |
|
| 1057 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1058 | + $result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1059 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1063 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1064 | + $end_preaff = $pos_debut_boucle; |
|
| 1065 | + |
|
| 1066 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1067 | + $result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1068 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + $result->id_boucle = $id_boucle; |
|
| 1072 | + |
|
| 1073 | + if ( |
|
| 1074 | + !preg_match(SPEC_BOUCLE, (string) $texte, $match, 0, $pos_milieu) |
|
| 1075 | + || ($pos_match = strpos((string) $texte, (string) $match[0], $pos_milieu)) === false |
|
| 1076 | + || $pos_match > $pos_milieu |
|
| 1077 | + ) { |
|
| 1078 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1079 | + erreur_squelette($err_b, $result); |
|
| 1080 | + |
|
| 1081 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1082 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1083 | + continue; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + $result->type_requete = $match[0]; |
|
| 1087 | + $pos_milieu += strlen($match[0]); |
|
| 1088 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1089 | + |
|
| 1090 | + $type = $match[1]; |
|
| 1091 | + $jointures = trim($match[2]); |
|
| 1092 | + $table_optionnelle = ($match[3]); |
|
| 1093 | + if ($jointures) { |
|
| 1094 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1095 | + // ou elles seront completees des jointures declarees |
|
| 1096 | + $result->jointures_explicites = $jointures; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + if ($table_optionnelle) { |
|
| 1100 | + $result->table_optionnelle = $type; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1104 | + // Resultat mis dans result->param |
|
| 1105 | + $pos_fin_criteres = $pos_milieu; |
|
| 1106 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1107 | + |
|
| 1108 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1109 | + // pour l'instant on met le source (chaine) : |
|
| 1110 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1111 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1112 | + $result->criteres = substr((string) $texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1113 | + $pos_milieu = $pos_fin_criteres; |
|
| 1114 | + |
|
| 1115 | + // |
|
| 1116 | + // Recuperer la fin : |
|
| 1117 | + // |
|
| 1118 | + if ($texte[$pos_milieu] === '/') { |
|
| 1119 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1120 | + $pos_courante += 2; |
|
| 1121 | + $result->milieu = ''; |
|
| 1122 | + } else { |
|
| 1123 | + $pos_milieu += 1; |
|
| 1124 | + |
|
| 1125 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1126 | + $pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu); |
|
| 1127 | + if ($pos_fin === false) { |
|
| 1128 | + $err_b = [ |
|
| 1129 | + 'zbug_erreur_boucle_fermant', |
|
| 1130 | + ['id' => $id_boucle] |
|
| 1131 | + ]; |
|
| 1132 | + erreur_squelette($err_b, $result); |
|
| 1133 | + $pos_courante += strlen($fin_boucle); |
|
| 1134 | + } |
|
| 1135 | + else { |
|
| 1136 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1137 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1138 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1139 | + $search_from = $pos_milieu; |
|
| 1140 | + $nb_open = 1; |
|
| 1141 | + $nb_close = 1; |
|
| 1142 | + $maxiter = 0; |
|
| 1143 | + do { |
|
| 1144 | + while ( |
|
| 1145 | + $nb_close < $nb_open |
|
| 1146 | + && ($p = strpos((string) $texte, $fin_boucle, $pos_fin + 1)) |
|
| 1147 | + ) { |
|
| 1148 | + $nb_close++; |
|
| 1149 | + $pos_fin = $p; |
|
| 1150 | + } |
|
| 1151 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1152 | + if ($nb_close < $nb_open) { |
|
| 1153 | + break; |
|
| 1154 | + } |
|
| 1155 | + while ( |
|
| 1156 | + ($p = strpos((string) $texte, $search_debut_boucle, $search_from)) |
|
| 1157 | + && $p < $pos_fin |
|
| 1158 | + ) { |
|
| 1159 | + $nb_open++; |
|
| 1160 | + $search_from = $p + 1; |
|
| 1161 | + } |
|
| 1162 | + } while ($nb_close < $nb_open && $maxiter++ < 5); |
|
| 1163 | + |
|
| 1164 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1165 | + } |
|
| 1166 | + $result->milieu = substr((string) $texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1170 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1171 | + |
|
| 1172 | + // |
|
| 1173 | + // 1. Partie conditionnelle apres ? |
|
| 1174 | + // |
|
| 1175 | + if ($boucle['pos_postcond']) { |
|
| 1176 | + $result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1177 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1178 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + // |
|
| 1183 | + // 2. Partie alternative apres ? |
|
| 1184 | + // |
|
| 1185 | + $ligne_altern = $ligne_suite; |
|
| 1186 | + if ($boucle['pos_altern']) { |
|
| 1187 | + $result->altern = substr((string) $texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1188 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1189 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + // |
|
| 1193 | + // 3. Partie footer non alternative ? |
|
| 1194 | + // |
|
| 1195 | + $ligne_postaff = $ligne_suite; |
|
| 1196 | + if ($boucle['pos_postaff']) { |
|
| 1197 | + $result->postaff = substr((string) $texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1198 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1199 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + $result->ligne = $ligne_preaff; |
|
| 1203 | + |
|
| 1204 | + if ($p = strpos($type, ':')) { |
|
| 1205 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1206 | + $type = substr($type, $p + 1); |
|
| 1207 | + } |
|
| 1208 | + $soustype = strtolower($type); |
|
| 1209 | + |
|
| 1210 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1211 | + $soustype = $type; |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + $result->type_requete = $soustype; |
|
| 1215 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1216 | + if (!is_array($result->param)) { |
|
| 1217 | + $err_b = true; |
|
| 1218 | + } else { |
|
| 1219 | + phraser_criteres($result->param, $result); |
|
| 1220 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1221 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1222 | + $args = $result->param; |
|
| 1223 | + array_unshift( |
|
| 1224 | + $args, |
|
| 1225 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1226 | + ); |
|
| 1227 | + $result->param = $args; |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1232 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1233 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1234 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1235 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1236 | + if (empty($boucles[$id_boucle])) { |
|
| 1237 | + $boucles[$id_boucle] = null; |
|
| 1238 | + } |
|
| 1239 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1240 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1241 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1242 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1243 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1244 | + |
|
| 1245 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1246 | + if ($err_b) { |
|
| 1247 | + $result->type_requete = false; |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + // Verifier qu'il n'y a pas double definition |
|
| 1251 | + // apres analyse des sous-parties (pas avant). |
|
| 1252 | + if (!empty($boucles[$id_boucle])) { |
|
| 1253 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1254 | + $err_b_d = [ |
|
| 1255 | + 'zbug_erreur_boucle_double', |
|
| 1256 | + ['id' => $id_boucle] |
|
| 1257 | + ]; |
|
| 1258 | + erreur_squelette($err_b_d, $result); |
|
| 1259 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1260 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1261 | + } |
|
| 1262 | + } else { |
|
| 1263 | + $boucles[$id_boucle] = $result; |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1267 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1268 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1269 | + $texte = substr_replace((string) $texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1270 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1271 | + |
|
| 1272 | + // phraser la partie avant le debut de la boucle |
|
| 1273 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1274 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1275 | + |
|
| 1276 | + $ligne_debut_texte = $ligne_suite; |
|
| 1277 | + $pos_debut_texte = $pos_courante; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1281 | 1281 | } |
@@ -55,19 +55,19 @@ discard block |
||
| 55 | 55 | * Nom d'une balise #TOTO |
| 56 | 56 | * |
| 57 | 57 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 58 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 58 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 59 | 59 | /** Balise complète [...(#TOTO) ... ] */ |
| 60 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 60 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 61 | 61 | |
| 62 | 62 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 63 | 63 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 64 | 64 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 65 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 65 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 66 | 66 | |
| 67 | 67 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 68 | 68 | define('SQL_ARGS', '(\([^)]*\))'); |
| 69 | 69 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 70 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 70 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 71 | 71 | |
| 72 | 72 | function phraser_inclure($texte, $ligne, $result) { |
| 73 | 73 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | **/ |
| 224 | 224 | function phraser_champs($texte, $ligne, $result) { |
| 225 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 225 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 226 | 226 | $p = strpos($texte, (string) $match[0]); |
| 227 | 227 | // texte après la balise |
| 228 | 228 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $collecte[] = $champ; |
| 370 | 370 | $args = ltrim($regs[count($regs) - 1]); |
| 371 | 371 | } else { |
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 372 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 373 | 373 | // 0 est un aveu d'impuissance. A completer |
| 374 | 374 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 375 | 375 | |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 454 | 454 | $res = []; |
| 455 | 455 | while (($p = strpos((string) $texte, (string) "%$sep")) !== false) { |
| 456 | - if (!preg_match(',^%' . preg_quote((string) $sep, ',') . '([0-9]+)@,', substr((string) $texte, $p), $m)) { |
|
| 456 | + if (!preg_match(',^%'.preg_quote((string) $sep, ',').'([0-9]+)@,', substr((string) $texte, $p), $m)) { |
|
| 457 | 457 | break; |
| 458 | 458 | } |
| 459 | 459 | $debut = substr((string) $texte, 0, $p); |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | $pos_apres = 0; |
| 494 | 494 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 495 | 495 | phraser_vieux($champ); |
| 496 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 496 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 497 | 497 | $debut = substr($match[7], $pos_apres + 1); |
| 498 | 498 | if (!empty($debut)) { |
| 499 | 499 | $n += substr_count(substr((string) $texte, 0, strpos((string) $texte, $debut)), "\n"); |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 624 | 624 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 625 | 625 | $c = null; |
| 626 | - eval('$c = ' . $m[4] . ';'); |
|
| 626 | + eval('$c = '.$m[4].';'); |
|
| 627 | 627 | if (isset($c)) { |
| 628 | 628 | $m[4] = $c; |
| 629 | 629 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) { |
| 704 | 704 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 705 | 705 | } elseif ( |
| 706 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 706 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 707 | 707 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m) |
| 708 | 708 | ) { |
| 709 | 709 | $a2 = trim($m[8]); |
@@ -720,8 +720,8 @@ discard block |
||
| 720 | 720 | ); |
| 721 | 721 | $crit->exclus = $m[1]; |
| 722 | 722 | } elseif ( |
| 723 | - preg_match('/^([!]?)\s*(' . |
|
| 724 | - CHAMP_SQL_PLUS_FONC . |
|
| 723 | + preg_match('/^([!]?)\s*('. |
|
| 724 | + CHAMP_SQL_PLUS_FONC. |
|
| 725 | 725 | ')\s*(\??)(.*)$/is', (string) $param, $m) |
| 726 | 726 | ) { |
| 727 | 727 | // contient aussi les comparaisons implicites ! |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 869 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 869 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 870 | 870 | $pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 871 | 871 | if ( |
| 872 | 872 | $pos_precond !== false |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 880 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 881 | 881 | $pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 882 | 882 | if ( |
| 883 | 883 | $pos_preaff !== false |
@@ -925,13 +925,13 @@ discard block |
||
| 925 | 925 | $pos_anonyme_next = null; |
| 926 | 926 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 927 | 927 | if (!strlen((string) $id_boucle)) { |
| 928 | - $pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 928 | + $pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | // |
| 932 | 932 | // 1. Recuperer la partie conditionnelle apres |
| 933 | 933 | // |
| 934 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 934 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 935 | 935 | $pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante); |
| 936 | 936 | if ( |
| 937 | 937 | $pos_apres !== false |
@@ -940,13 +940,13 @@ discard block |
||
| 940 | 940 | $boucle['pos_postcond'] = $pos_apres; |
| 941 | 941 | $pos_apres += strlen($apres_boucle); |
| 942 | 942 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 943 | - $pos_courante = $pos_apres ; |
|
| 943 | + $pos_courante = $pos_apres; |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | // |
| 947 | 947 | // 2. Récuperer la partie alternative apres |
| 948 | 948 | // |
| 949 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 949 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 950 | 950 | $pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante); |
| 951 | 951 | if ( |
| 952 | 952 | $pos_altern !== false |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | // |
| 962 | 962 | // 3. Recuperer la partie footer non alternative |
| 963 | 963 | // |
| 964 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 964 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 965 | 965 | $pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante); |
| 966 | 966 | if ( |
| 967 | 967 | $pos_postaff !== false |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | $boucle['pos_postaff'] = $pos_postaff; |
| 971 | 971 | $pos_postaff += strlen($postaff_boucle); |
| 972 | 972 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 973 | - $pos_courante = $pos_postaff ; |
|
| 973 | + $pos_courante = $pos_postaff; |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | return $boucle; |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | * @return string |
| 1011 | 1011 | */ |
| 1012 | 1012 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1013 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1013 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1014 | 1014 | //memoriser la boucle a reinjecter |
| 1015 | 1015 | $id_boucle = "$id_boucle"; |
| 1016 | 1016 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1024 | 1024 | if (is_null($boucle_placeholder)) { |
| 1025 | 1025 | do { |
| 1026 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1026 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1027 | 1027 | } while (str_contains((string) $texte, $boucle_placeholder)); |
| 1028 | 1028 | } |
| 1029 | 1029 | |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | |
| 1044 | 1044 | // boucle anonyme ? |
| 1045 | 1045 | if (!strlen((string) $id_boucle)) { |
| 1046 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1046 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | $pos_debut_boucle = $pos_courante; |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | |
| 1057 | 1057 | $pos_avant = $boucle['pos_precond_inside']; |
| 1058 | 1058 | $result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant); |
| 1059 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1059 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | |
| 1066 | 1066 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1067 | 1067 | $result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1068 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1068 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | $result->id_boucle = $id_boucle; |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | } else { |
| 1123 | 1123 | $pos_milieu += 1; |
| 1124 | 1124 | |
| 1125 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1125 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1126 | 1126 | $pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu); |
| 1127 | 1127 | if ($pos_fin === false) { |
| 1128 | 1128 | $err_b = [ |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | else { |
| 1136 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1137 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1138 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1138 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1139 | 1139 | $search_from = $pos_milieu; |
| 1140 | 1140 | $nb_open = 1; |
| 1141 | 1141 | $nb_close = 1; |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | if ($boucle['pos_postcond']) { |
| 1176 | 1176 | $result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1177 | 1177 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1178 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1178 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | |
@@ -798,8 +798,7 @@ discard block |
||
| 798 | 798 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 799 | 799 | if (is_null($fin)) { |
| 800 | 800 | return substr_count((string) $texte, "\n", $debut); |
| 801 | - } |
|
| 802 | - else { |
|
| 801 | + } else { |
|
| 803 | 802 | return substr_count((string) $texte, "\n", $debut, $fin - $debut); |
| 804 | 803 | } |
| 805 | 804 | } |
@@ -846,8 +845,7 @@ discard block |
||
| 846 | 845 | erreur_squelette($err_b, $result); |
| 847 | 846 | |
| 848 | 847 | continue; |
| 849 | - } |
|
| 850 | - else { |
|
| 848 | + } else { |
|
| 851 | 849 | $boucle = [ |
| 852 | 850 | 'id_boucle' => $id_boucle, |
| 853 | 851 | 'id_boucle_err' => $id_boucle, |
@@ -987,8 +985,7 @@ discard block |
||
| 987 | 985 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 988 | 986 | if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) { |
| 989 | 987 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 990 | - } |
|
| 991 | - else { |
|
| 988 | + } else { |
|
| 992 | 989 | if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) { |
| 993 | 990 | $placeholder = $champ->nom_champ; |
| 994 | 991 | $id = reset($champ->param[0][1]); |
@@ -1131,8 +1128,7 @@ discard block |
||
| 1131 | 1128 | ]; |
| 1132 | 1129 | erreur_squelette($err_b, $result); |
| 1133 | 1130 | $pos_courante += strlen($fin_boucle); |
| 1134 | - } |
|
| 1135 | - else { |
|
| 1131 | + } else { |
|
| 1136 | 1132 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1137 | 1133 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1138 | 1134 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |