@@ -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 | } |
@@ -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 | /** |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function generer_nom_fichier_cache($contexte, $page) { |
| 27 | - $u = md5(var_export([$contexte, $page], true)); |
|
| 27 | + $u = md5(var_export([$contexte, $page], true)); |
|
| 28 | 28 | |
| 29 | - return $u . '.cache'; |
|
| 29 | + return $u . '.cache'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | 44 | function cache_chemin_fichier($nom_cache, $ecrire = false) { |
| 45 | - static $l1, $l2; |
|
| 46 | - if (is_null($l1)) { |
|
| 47 | - $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 48 | - $l1 = (int) floor($length / 2); |
|
| 49 | - $l2 = $length - $l1; |
|
| 50 | - } |
|
| 51 | - $d = substr((string) $nom_cache, 0, $l1); |
|
| 52 | - $u = substr((string) $nom_cache, $l1, $l2); |
|
| 53 | - |
|
| 54 | - if ($ecrire) { |
|
| 55 | - $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 56 | - $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 57 | - $rep = sous_repertoire($rep, $d, false, true); |
|
| 58 | - } |
|
| 59 | - else { |
|
| 60 | - // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 61 | - $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $rep . $u . '.cache'; |
|
| 45 | + static $l1, $l2; |
|
| 46 | + if (is_null($l1)) { |
|
| 47 | + $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 48 | + $l1 = (int) floor($length / 2); |
|
| 49 | + $l2 = $length - $l1; |
|
| 50 | + } |
|
| 51 | + $d = substr((string) $nom_cache, 0, $l1); |
|
| 52 | + $u = substr((string) $nom_cache, $l1, $l2); |
|
| 53 | + |
|
| 54 | + if ($ecrire) { |
|
| 55 | + $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 56 | + $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 57 | + $rep = sous_repertoire($rep, $d, false, true); |
|
| 58 | + } |
|
| 59 | + else { |
|
| 60 | + // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 61 | + $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $rep . $u . '.cache'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | 74 | function ecrire_cache($nom_cache, $valeur) { |
| 75 | - return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 75 | + return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,38 +82,38 @@ discard block |
||
| 82 | 82 | * @return mixed |
| 83 | 83 | */ |
| 84 | 84 | function lire_cache($nom_cache) { |
| 85 | - $tmp = []; |
|
| 86 | - if ( |
|
| 87 | - file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 88 | - && lire_fichier($f, $tmp) |
|
| 89 | - && ($tmp = unserialize($tmp)) |
|
| 90 | - && $tmp['nom_cache'] == $nom_cache |
|
| 91 | - && isset($tmp['valeur']) |
|
| 92 | - ) { |
|
| 93 | - return $tmp['valeur']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return false; |
|
| 85 | + $tmp = []; |
|
| 86 | + if ( |
|
| 87 | + file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 88 | + && lire_fichier($f, $tmp) |
|
| 89 | + && ($tmp = unserialize($tmp)) |
|
| 90 | + && $tmp['nom_cache'] == $nom_cache |
|
| 91 | + && isset($tmp['valeur']) |
|
| 92 | + ) { |
|
| 93 | + return $tmp['valeur']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return false; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Parano : on signe le cache, afin d'interdire un hack d'injection |
| 100 | 100 | // dans notre memcache |
| 101 | 101 | function cache_signature(&$page) { |
| 102 | - if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 103 | - include_spip('inc/acces'); |
|
| 104 | - include_spip('auth/sha256.inc'); |
|
| 105 | - ecrire_meta( |
|
| 106 | - 'cache_signature', |
|
| 107 | - spip_sha256( |
|
| 108 | - $_SERVER['DOCUMENT_ROOT'] |
|
| 109 | - . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 110 | - . creer_uniqid() |
|
| 111 | - ), |
|
| 112 | - 'non' |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 102 | + if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 103 | + include_spip('inc/acces'); |
|
| 104 | + include_spip('auth/sha256.inc'); |
|
| 105 | + ecrire_meta( |
|
| 106 | + 'cache_signature', |
|
| 107 | + spip_sha256( |
|
| 108 | + $_SERVER['DOCUMENT_ROOT'] |
|
| 109 | + . ($_SERVER['SERVER_SIGNATURE'] ?? '') |
|
| 110 | + . creer_uniqid() |
|
| 111 | + ), |
|
| 112 | + 'non' |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | * @return array |
| 127 | 127 | */ |
| 128 | 128 | function gzip_page($page) { |
| 129 | - if (function_exists('gzcompress') && strlen((string) $page['texte']) > 16 * 1024) { |
|
| 130 | - $page['gz'] = true; |
|
| 131 | - $page['texte'] = gzcompress((string) $page['texte']); |
|
| 132 | - } else { |
|
| 133 | - $page['gz'] = false; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $page; |
|
| 129 | + if (function_exists('gzcompress') && strlen((string) $page['texte']) > 16 * 1024) { |
|
| 130 | + $page['gz'] = true; |
|
| 131 | + $page['texte'] = gzcompress((string) $page['texte']); |
|
| 132 | + } else { |
|
| 133 | + $page['gz'] = false; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $page; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -146,10 +146,10 @@ discard block |
||
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | 148 | function gunzip_page(&$page) { |
| 149 | - if ($page['gz']) { |
|
| 150 | - $page['texte'] = gzuncompress($page['texte']); |
|
| 151 | - $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 152 | - } |
|
| 149 | + if ($page['gz']) { |
|
| 150 | + $page['texte'] = gzuncompress($page['texte']); |
|
| 151 | + $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 152 | + } |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -164,72 +164,72 @@ discard block |
||
| 164 | 164 | * -1 si il faut calculer sans stocker en cache |
| 165 | 165 | */ |
| 166 | 166 | function cache_valide(&$page, $date) { |
| 167 | - $now = $_SERVER['REQUEST_TIME']; |
|
| 168 | - |
|
| 169 | - // Apparition d'un nouvel article post-date ? |
|
| 170 | - if ( |
|
| 171 | - isset($GLOBALS['meta']['post_dates']) |
|
| 172 | - && $GLOBALS['meta']['post_dates'] == 'non' |
|
| 173 | - && isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 174 | - && $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 175 | - ) { |
|
| 176 | - spip_log('Un article post-date invalide le cache'); |
|
| 177 | - include_spip('inc/rubriques'); |
|
| 178 | - calculer_prochain_postdate(true); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (defined('_VAR_NOCACHE') && _VAR_NOCACHE) { |
|
| 182 | - return -1; |
|
| 183 | - } |
|
| 184 | - if (isset($GLOBALS['meta']['cache_inhib']) && $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 185 | - return -1; |
|
| 186 | - } |
|
| 187 | - if (defined('_NO_CACHE')) { |
|
| 188 | - return (_NO_CACHE == 0 && !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 192 | - if (!$page || !isset($page['texte']) || !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 193 | - return _IS_BOT ? -1 : 1; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // controle de la signature |
|
| 197 | - if ($page['sig'] !== cache_signature($page)) { |
|
| 198 | - return _IS_BOT ? -1 : 1; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 202 | - // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 203 | - // Cache invalide par la meta 'derniere_modif' |
|
| 204 | - // sauf pour les bots, qui utilisent toujours le cache |
|
| 205 | - if ( |
|
| 206 | - (!isset($page['entetes']['X-Spip-Statique']) || $page['entetes']['X-Spip-Statique'] !== 'oui') |
|
| 207 | - && ( |
|
| 208 | - !_IS_BOT |
|
| 209 | - && $GLOBALS['derniere_modif_invalide'] |
|
| 210 | - && isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | - && $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | - ) |
|
| 213 | - ) { |
|
| 214 | - return 1; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | - $duree = (int) $page['entetes']['X-Spip-Cache']; |
|
| 219 | - $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | - if ($duree == 0) { #CACHE{0} |
|
| 221 | - return -1; |
|
| 222 | - } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | - else { |
|
| 224 | - if ( |
|
| 225 | - !_IS_BOT && $date + $duree < $now |
|
| 226 | - || $date < $cache_mark |
|
| 227 | - ) { |
|
| 228 | - return _IS_BOT ? -1 : 1; |
|
| 229 | - } else { |
|
| 230 | - return 0; |
|
| 231 | - } |
|
| 232 | - } |
|
| 167 | + $now = $_SERVER['REQUEST_TIME']; |
|
| 168 | + |
|
| 169 | + // Apparition d'un nouvel article post-date ? |
|
| 170 | + if ( |
|
| 171 | + isset($GLOBALS['meta']['post_dates']) |
|
| 172 | + && $GLOBALS['meta']['post_dates'] == 'non' |
|
| 173 | + && isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 174 | + && $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 175 | + ) { |
|
| 176 | + spip_log('Un article post-date invalide le cache'); |
|
| 177 | + include_spip('inc/rubriques'); |
|
| 178 | + calculer_prochain_postdate(true); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (defined('_VAR_NOCACHE') && _VAR_NOCACHE) { |
|
| 182 | + return -1; |
|
| 183 | + } |
|
| 184 | + if (isset($GLOBALS['meta']['cache_inhib']) && $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 185 | + return -1; |
|
| 186 | + } |
|
| 187 | + if (defined('_NO_CACHE')) { |
|
| 188 | + return (_NO_CACHE == 0 && !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 192 | + if (!$page || !isset($page['texte']) || !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 193 | + return _IS_BOT ? -1 : 1; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // controle de la signature |
|
| 197 | + if ($page['sig'] !== cache_signature($page)) { |
|
| 198 | + return _IS_BOT ? -1 : 1; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 202 | + // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 203 | + // Cache invalide par la meta 'derniere_modif' |
|
| 204 | + // sauf pour les bots, qui utilisent toujours le cache |
|
| 205 | + if ( |
|
| 206 | + (!isset($page['entetes']['X-Spip-Statique']) || $page['entetes']['X-Spip-Statique'] !== 'oui') |
|
| 207 | + && ( |
|
| 208 | + !_IS_BOT |
|
| 209 | + && $GLOBALS['derniere_modif_invalide'] |
|
| 210 | + && isset($GLOBALS['meta']['derniere_modif']) |
|
| 211 | + && $date < $GLOBALS['meta']['derniere_modif'] |
|
| 212 | + ) |
|
| 213 | + ) { |
|
| 214 | + return 1; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // Sinon comparer l'age du fichier a sa duree de cache |
|
| 218 | + $duree = (int) $page['entetes']['X-Spip-Cache']; |
|
| 219 | + $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 220 | + if ($duree == 0) { #CACHE{0} |
|
| 221 | + return -1; |
|
| 222 | + } // sauf pour les bots, qui utilisent toujours le cache |
|
| 223 | + else { |
|
| 224 | + if ( |
|
| 225 | + !_IS_BOT && $date + $duree < $now |
|
| 226 | + || $date < $cache_mark |
|
| 227 | + ) { |
|
| 228 | + return _IS_BOT ? -1 : 1; |
|
| 229 | + } else { |
|
| 230 | + return 0; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -242,59 +242,59 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | function creer_cache(&$page, &$chemin_cache) { |
| 244 | 244 | |
| 245 | - // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 246 | - // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 247 | - // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 248 | - // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 249 | - if ( |
|
| 250 | - defined('_VAR_NOCACHE') && _VAR_NOCACHE |
|
| 251 | - || defined('spip_interdire_cache') |
|
| 252 | - ) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 257 | - // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 258 | - if ( |
|
| 259 | - isset($page['invalideurs']) |
|
| 260 | - && isset($page['invalideurs']['session']) |
|
| 261 | - ) { |
|
| 262 | - // on verifie que le contenu du chemin cache indique seulement |
|
| 263 | - // "cache sessionne" ; sa date indique la date de validite |
|
| 264 | - // des caches sessionnes |
|
| 265 | - if (!$tmp = lire_cache($chemin_cache)) { |
|
| 266 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 267 | - $tmp = [ |
|
| 268 | - 'invalideurs' => ['session' => ''], |
|
| 269 | - 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 270 | - ]; |
|
| 271 | - ecrire_cache($chemin_cache, $tmp); |
|
| 272 | - } |
|
| 273 | - $chemin_cache = generer_nom_fichier_cache( |
|
| 274 | - ['chemin_cache' => $chemin_cache], |
|
| 275 | - ['session' => $page['invalideurs']['session']] |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // ajouter la date de production dans le cache lui meme |
|
| 280 | - // (qui contient deja sa duree de validite) |
|
| 281 | - $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 282 | - |
|
| 283 | - // compresser le contenu si besoin |
|
| 284 | - $pagez = gzip_page($page); |
|
| 285 | - |
|
| 286 | - // signer le contenu |
|
| 287 | - $pagez['sig'] = cache_signature($pagez); |
|
| 288 | - |
|
| 289 | - // l'enregistrer, compresse ou non... |
|
| 290 | - $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 291 | - |
|
| 292 | - spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 293 | - . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 294 | - |
|
| 295 | - // Inserer ses invalideurs |
|
| 296 | - include_spip('inc/invalideur'); |
|
| 297 | - maj_invalideurs($chemin_cache, $page); |
|
| 245 | + // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 246 | + // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 247 | + // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 248 | + // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 249 | + if ( |
|
| 250 | + defined('_VAR_NOCACHE') && _VAR_NOCACHE |
|
| 251 | + || defined('spip_interdire_cache') |
|
| 252 | + ) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 257 | + // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 258 | + if ( |
|
| 259 | + isset($page['invalideurs']) |
|
| 260 | + && isset($page['invalideurs']['session']) |
|
| 261 | + ) { |
|
| 262 | + // on verifie que le contenu du chemin cache indique seulement |
|
| 263 | + // "cache sessionne" ; sa date indique la date de validite |
|
| 264 | + // des caches sessionnes |
|
| 265 | + if (!$tmp = lire_cache($chemin_cache)) { |
|
| 266 | + spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 267 | + $tmp = [ |
|
| 268 | + 'invalideurs' => ['session' => ''], |
|
| 269 | + 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 270 | + ]; |
|
| 271 | + ecrire_cache($chemin_cache, $tmp); |
|
| 272 | + } |
|
| 273 | + $chemin_cache = generer_nom_fichier_cache( |
|
| 274 | + ['chemin_cache' => $chemin_cache], |
|
| 275 | + ['session' => $page['invalideurs']['session']] |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // ajouter la date de production dans le cache lui meme |
|
| 280 | + // (qui contient deja sa duree de validite) |
|
| 281 | + $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 282 | + |
|
| 283 | + // compresser le contenu si besoin |
|
| 284 | + $pagez = gzip_page($page); |
|
| 285 | + |
|
| 286 | + // signer le contenu |
|
| 287 | + $pagez['sig'] = cache_signature($pagez); |
|
| 288 | + |
|
| 289 | + // l'enregistrer, compresse ou non... |
|
| 290 | + $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 291 | + |
|
| 292 | + spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 293 | + . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 294 | + |
|
| 295 | + // Inserer ses invalideurs |
|
| 296 | + include_spip('inc/invalideur'); |
|
| 297 | + maj_invalideurs($chemin_cache, $page); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -307,15 +307,15 @@ discard block |
||
| 307 | 307 | * @return void |
| 308 | 308 | */ |
| 309 | 309 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 310 | - // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 311 | - $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 312 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 313 | - foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 314 | - if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 315 | - spip_unlink($f); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 310 | + // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 311 | + $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 312 | + if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 313 | + foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 314 | + if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 315 | + spip_unlink($f); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -343,132 +343,132 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) { |
| 345 | 345 | |
| 346 | - # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 347 | - # $use_cache = -1; return; |
|
| 348 | - |
|
| 349 | - // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 350 | - if (isset($chemin_cache)) { |
|
| 351 | - creer_cache($page, $chemin_cache); |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // Toute la suite correspond au premier appel |
|
| 356 | - $contexte_implicite = $page['contexte_implicite']; |
|
| 357 | - |
|
| 358 | - // Cas ignorant le cache car completement dynamique |
|
| 359 | - if ( |
|
| 360 | - !empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' |
|
| 361 | - || _request('connect') |
|
| 362 | - ) { |
|
| 363 | - $use_cache = -1; |
|
| 364 | - $lastmodified = 0; |
|
| 365 | - $chemin_cache = ''; |
|
| 366 | - $page = []; |
|
| 367 | - |
|
| 368 | - return; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // Controler l'existence d'un cache nous correspondant |
|
| 372 | - $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 373 | - $lastmodified = 0; |
|
| 374 | - |
|
| 375 | - // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 376 | - if (!$page = lire_cache($chemin_cache)) { |
|
| 377 | - $page = []; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - // s'il est sessionne, charger celui correspondant a notre session |
|
| 381 | - if ( |
|
| 382 | - isset($page['invalideurs']) |
|
| 383 | - && isset($page['invalideurs']['session']) |
|
| 384 | - ) { |
|
| 385 | - $chemin_cache_session = generer_nom_fichier_cache( |
|
| 386 | - ['chemin_cache' => $chemin_cache], |
|
| 387 | - ['session' => spip_session()] |
|
| 388 | - ); |
|
| 389 | - if ( |
|
| 390 | - ($page_session = lire_cache($chemin_cache_session)) && $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 391 | - ) { |
|
| 392 | - $page = $page_session; |
|
| 393 | - } else { |
|
| 394 | - $page = []; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 400 | - // ne le faire que si la base est disponible |
|
| 401 | - if (isset($GLOBALS['meta']['invalider']) && spip_connect()) { |
|
| 402 | - include_spip('inc/invalideur'); |
|
| 403 | - retire_caches($chemin_cache); |
|
| 404 | - # API invalideur inutile |
|
| 405 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 406 | - if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 407 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 412 | - // on supprime le cache |
|
| 413 | - if ( |
|
| 414 | - defined('_VAR_MODE') && |
|
| 415 | - _VAR_MODE && |
|
| 416 | - (isset($_COOKIE['spip_session']) || |
|
| 417 | - isset($_COOKIE['spip_admin']) || |
|
| 418 | - @file_exists(_ACCESS_FILE_NAME)) |
|
| 419 | - ) { |
|
| 420 | - $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 421 | - include_spip('inc/invalideur'); |
|
| 422 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 423 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 424 | - if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 425 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // $delais par defaut |
|
| 430 | - // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 431 | - // qui sont a cache nul par defaut |
|
| 432 | - if (!isset($GLOBALS['delais'])) { |
|
| 433 | - if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 434 | - define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 435 | - } |
|
| 436 | - $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // determiner la validite de la page |
|
| 440 | - if ($page) { |
|
| 441 | - $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 442 | - // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 443 | - // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 444 | - $page['contexte_implicite'] = $contexte_implicite; |
|
| 445 | - if (!$use_cache) { |
|
| 446 | - // $page est un cache utilisable |
|
| 447 | - gunzip_page($page); |
|
| 448 | - |
|
| 449 | - return; |
|
| 450 | - } |
|
| 451 | - } else { |
|
| 452 | - $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 453 | - $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 457 | - if (!spip_connect()) { |
|
| 458 | - if (isset($page['texte'])) { |
|
| 459 | - gunzip_page($page); |
|
| 460 | - $use_cache = 0; |
|
| 461 | - } else { |
|
| 462 | - spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 463 | - include_spip('inc/minipres'); |
|
| 464 | - |
|
| 465 | - return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - if ($use_cache < 0) { |
|
| 470 | - $chemin_cache = ''; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - return; |
|
| 346 | + # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 347 | + # $use_cache = -1; return; |
|
| 348 | + |
|
| 349 | + // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 350 | + if (isset($chemin_cache)) { |
|
| 351 | + creer_cache($page, $chemin_cache); |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // Toute la suite correspond au premier appel |
|
| 356 | + $contexte_implicite = $page['contexte_implicite']; |
|
| 357 | + |
|
| 358 | + // Cas ignorant le cache car completement dynamique |
|
| 359 | + if ( |
|
| 360 | + !empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' |
|
| 361 | + || _request('connect') |
|
| 362 | + ) { |
|
| 363 | + $use_cache = -1; |
|
| 364 | + $lastmodified = 0; |
|
| 365 | + $chemin_cache = ''; |
|
| 366 | + $page = []; |
|
| 367 | + |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // Controler l'existence d'un cache nous correspondant |
|
| 372 | + $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 373 | + $lastmodified = 0; |
|
| 374 | + |
|
| 375 | + // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 376 | + if (!$page = lire_cache($chemin_cache)) { |
|
| 377 | + $page = []; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + // s'il est sessionne, charger celui correspondant a notre session |
|
| 381 | + if ( |
|
| 382 | + isset($page['invalideurs']) |
|
| 383 | + && isset($page['invalideurs']['session']) |
|
| 384 | + ) { |
|
| 385 | + $chemin_cache_session = generer_nom_fichier_cache( |
|
| 386 | + ['chemin_cache' => $chemin_cache], |
|
| 387 | + ['session' => spip_session()] |
|
| 388 | + ); |
|
| 389 | + if ( |
|
| 390 | + ($page_session = lire_cache($chemin_cache_session)) && $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 391 | + ) { |
|
| 392 | + $page = $page_session; |
|
| 393 | + } else { |
|
| 394 | + $page = []; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 400 | + // ne le faire que si la base est disponible |
|
| 401 | + if (isset($GLOBALS['meta']['invalider']) && spip_connect()) { |
|
| 402 | + include_spip('inc/invalideur'); |
|
| 403 | + retire_caches($chemin_cache); |
|
| 404 | + # API invalideur inutile |
|
| 405 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 406 | + if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 407 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 412 | + // on supprime le cache |
|
| 413 | + if ( |
|
| 414 | + defined('_VAR_MODE') && |
|
| 415 | + _VAR_MODE && |
|
| 416 | + (isset($_COOKIE['spip_session']) || |
|
| 417 | + isset($_COOKIE['spip_admin']) || |
|
| 418 | + @file_exists(_ACCESS_FILE_NAME)) |
|
| 419 | + ) { |
|
| 420 | + $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 421 | + include_spip('inc/invalideur'); |
|
| 422 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 423 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 424 | + if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 425 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // $delais par defaut |
|
| 430 | + // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 431 | + // qui sont a cache nul par defaut |
|
| 432 | + if (!isset($GLOBALS['delais'])) { |
|
| 433 | + if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 434 | + define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 435 | + } |
|
| 436 | + $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // determiner la validite de la page |
|
| 440 | + if ($page) { |
|
| 441 | + $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 442 | + // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 443 | + // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 444 | + $page['contexte_implicite'] = $contexte_implicite; |
|
| 445 | + if (!$use_cache) { |
|
| 446 | + // $page est un cache utilisable |
|
| 447 | + gunzip_page($page); |
|
| 448 | + |
|
| 449 | + return; |
|
| 450 | + } |
|
| 451 | + } else { |
|
| 452 | + $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 453 | + $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 457 | + if (!spip_connect()) { |
|
| 458 | + if (isset($page['texte'])) { |
|
| 459 | + gunzip_page($page); |
|
| 460 | + $use_cache = 0; |
|
| 461 | + } else { |
|
| 462 | + spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 463 | + include_spip('inc/minipres'); |
|
| 464 | + |
|
| 465 | + return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + if ($use_cache < 0) { |
|
| 470 | + $chemin_cache = ''; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + return; |
|
| 474 | 474 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -10,187 +10,187 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function trace_query_start() { |
| 17 | - static $trace = '?'; |
|
| 18 | - if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | - if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | - $trace = true; |
|
| 21 | - } |
|
| 22 | - else { |
|
| 23 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | - // ou une requete SQL faite avant chargement de la session |
|
| 27 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | - } |
|
| 29 | - else { |
|
| 30 | - include_spip('inc/autoriser'); |
|
| 31 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | - // A fortiori quand on demande une trace |
|
| 33 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return $trace ? microtime() : 0; |
|
| 17 | + static $trace = '?'; |
|
| 18 | + if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | + if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | + $trace = true; |
|
| 21 | + } |
|
| 22 | + else { |
|
| 23 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | + // ou une requete SQL faite avant chargement de la session |
|
| 27 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | + } |
|
| 29 | + else { |
|
| 30 | + include_spip('inc/autoriser'); |
|
| 31 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | + // A fortiori quand on demande une trace |
|
| 33 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return $trace ? microtime() : 0; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 43 | - static $trace = '?'; |
|
| 44 | - if ($trace === '?') { |
|
| 45 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | - // ou une requete SQL faite avant chargement de la session |
|
| 49 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | - } |
|
| 51 | - else { |
|
| 52 | - include_spip('inc/autoriser'); |
|
| 53 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | - // A fortiori quand on demande une trace |
|
| 55 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($start) { |
|
| 60 | - $end = microtime(); |
|
| 61 | - [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | - if ($trace) { |
|
| 66 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | - if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return $result; |
|
| 43 | + static $trace = '?'; |
|
| 44 | + if ($trace === '?') { |
|
| 45 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | + // ou une requete SQL faite avant chargement de la session |
|
| 49 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + include_spip('inc/autoriser'); |
|
| 53 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | + // A fortiori quand on demande une trace |
|
| 55 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($start) { |
|
| 60 | + $end = microtime(); |
|
| 61 | + [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | + if ($trace) { |
|
| 66 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | + if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return $result; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 78 | - include_spip('inc/filtres_mini'); |
|
| 79 | - static $tt = 0, $nb = 0; |
|
| 80 | - |
|
| 81 | - $x = _request('var_mode_objet'); |
|
| 82 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | - if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - if ($serveur) { |
|
| 88 | - $boucle .= " ($serveur)"; |
|
| 89 | - } |
|
| 90 | - $boucle = "<b>$boucle</b>"; |
|
| 91 | - } else { |
|
| 92 | - if ($x) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $boucle = $contexte = ''; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $tt += $dt; |
|
| 99 | - $nb++; |
|
| 100 | - |
|
| 101 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | - $e = sql_explain($query, $serveur); |
|
| 103 | - $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 78 | + include_spip('inc/filtres_mini'); |
|
| 79 | + static $tt = 0, $nb = 0; |
|
| 80 | + |
|
| 81 | + $x = _request('var_mode_objet'); |
|
| 82 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | + if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + if ($serveur) { |
|
| 88 | + $boucle .= " ($serveur)"; |
|
| 89 | + } |
|
| 90 | + $boucle = "<b>$boucle</b>"; |
|
| 91 | + } else { |
|
| 92 | + if ($x) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $boucle = $contexte = ''; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $tt += $dt; |
|
| 99 | + $nb++; |
|
| 100 | + |
|
| 101 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | + $e = sql_explain($query, $serveur); |
|
| 103 | + $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | function chrono_requete($temps) { |
| 109 | - $total = 0; |
|
| 110 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | - $t = $q = $n = $d = []; |
|
| 112 | - // Totaliser les temps et completer le Explain |
|
| 113 | - foreach ($temps as $key => $v) { |
|
| 114 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | - if (is_array($contexte)) { |
|
| 116 | - $k = ($contexte[0] . " $boucle"); |
|
| 117 | - include_spip('public/compiler'); |
|
| 118 | - $env = reconstruire_contexte_compil($contexte); |
|
| 119 | - } else { |
|
| 120 | - $k = $env = $boucle; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $total += $dt; |
|
| 124 | - $t[$key] = $dt; |
|
| 125 | - $q[$key] = $nb; |
|
| 126 | - if (!isset($d[$k])) { |
|
| 127 | - $d[$k] = 0; |
|
| 128 | - $n[$k] = 0; |
|
| 129 | - } |
|
| 130 | - $d[$k] += $dt; |
|
| 131 | - ++$n[$k]; |
|
| 132 | - |
|
| 133 | - if (!is_array($explain)) { |
|
| 134 | - $explain = []; |
|
| 135 | - } |
|
| 136 | - foreach ($explain as $j => $v) { |
|
| 137 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | - . str_replace(';', '<br />', (string) $v) |
|
| 139 | - . '</td></tr>'; |
|
| 140 | - } |
|
| 141 | - $e = "<table class='explain'>" |
|
| 142 | - . '<caption>' |
|
| 143 | - . $query |
|
| 144 | - . '</caption>' |
|
| 145 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | - . implode('', $explain) |
|
| 149 | - . '</table>'; |
|
| 150 | - |
|
| 151 | - $temps[$key] = [$e, $env, $k]; |
|
| 152 | - } |
|
| 153 | - // Trier par temps d'execution decroissant |
|
| 154 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | - arsort($d); |
|
| 156 | - $i = 1; |
|
| 157 | - $t = []; |
|
| 158 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | - foreach ($temps as $k => $v) { |
|
| 160 | - $titre = strip_tags((string) $v[2]); |
|
| 161 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | - $href = str_replace("\\'", ''', $href); |
|
| 163 | - |
|
| 164 | - if (!isset($t[$v[2]])) { |
|
| 165 | - $t[$v[2]] = []; |
|
| 166 | - } |
|
| 167 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | - . '</span>' |
|
| 170 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | - $i++; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($d['']) { |
|
| 175 | - $d[$hors] = $d['']; |
|
| 176 | - $n[$hors] = $n['']; |
|
| 177 | - $t[$hors] = $t['']; |
|
| 178 | - } |
|
| 179 | - unset($d['']); |
|
| 180 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | - foreach ($d as $k => $v) { |
|
| 182 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | - . implode('', $t[$k]); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $navigation = [ |
|
| 187 | - _T('zbug_statistiques'), |
|
| 188 | - '<tr><td>' |
|
| 189 | - . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | - . "</td></tr>\n" |
|
| 191 | - . (# _request('var_mode_objet') ? '' : |
|
| 192 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | - ]; |
|
| 194 | - |
|
| 195 | - return [$temps, $navigation]; |
|
| 109 | + $total = 0; |
|
| 110 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | + $t = $q = $n = $d = []; |
|
| 112 | + // Totaliser les temps et completer le Explain |
|
| 113 | + foreach ($temps as $key => $v) { |
|
| 114 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | + if (is_array($contexte)) { |
|
| 116 | + $k = ($contexte[0] . " $boucle"); |
|
| 117 | + include_spip('public/compiler'); |
|
| 118 | + $env = reconstruire_contexte_compil($contexte); |
|
| 119 | + } else { |
|
| 120 | + $k = $env = $boucle; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $total += $dt; |
|
| 124 | + $t[$key] = $dt; |
|
| 125 | + $q[$key] = $nb; |
|
| 126 | + if (!isset($d[$k])) { |
|
| 127 | + $d[$k] = 0; |
|
| 128 | + $n[$k] = 0; |
|
| 129 | + } |
|
| 130 | + $d[$k] += $dt; |
|
| 131 | + ++$n[$k]; |
|
| 132 | + |
|
| 133 | + if (!is_array($explain)) { |
|
| 134 | + $explain = []; |
|
| 135 | + } |
|
| 136 | + foreach ($explain as $j => $v) { |
|
| 137 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | + . str_replace(';', '<br />', (string) $v) |
|
| 139 | + . '</td></tr>'; |
|
| 140 | + } |
|
| 141 | + $e = "<table class='explain'>" |
|
| 142 | + . '<caption>' |
|
| 143 | + . $query |
|
| 144 | + . '</caption>' |
|
| 145 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | + . implode('', $explain) |
|
| 149 | + . '</table>'; |
|
| 150 | + |
|
| 151 | + $temps[$key] = [$e, $env, $k]; |
|
| 152 | + } |
|
| 153 | + // Trier par temps d'execution decroissant |
|
| 154 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | + arsort($d); |
|
| 156 | + $i = 1; |
|
| 157 | + $t = []; |
|
| 158 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | + foreach ($temps as $k => $v) { |
|
| 160 | + $titre = strip_tags((string) $v[2]); |
|
| 161 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | + $href = str_replace("\\'", ''', $href); |
|
| 163 | + |
|
| 164 | + if (!isset($t[$v[2]])) { |
|
| 165 | + $t[$v[2]] = []; |
|
| 166 | + } |
|
| 167 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | + . '</span>' |
|
| 170 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | + $i++; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($d['']) { |
|
| 175 | + $d[$hors] = $d['']; |
|
| 176 | + $n[$hors] = $n['']; |
|
| 177 | + $t[$hors] = $t['']; |
|
| 178 | + } |
|
| 179 | + unset($d['']); |
|
| 180 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | + foreach ($d as $k => $v) { |
|
| 182 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | + . implode('', $t[$k]); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $navigation = [ |
|
| 187 | + _T('zbug_statistiques'), |
|
| 188 | + '<tr><td>' |
|
| 189 | + . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | + . "</td></tr>\n" |
|
| 191 | + . (# _request('var_mode_objet') ? '' : |
|
| 192 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | + ]; |
|
| 194 | + |
|
| 195 | + return [$temps, $navigation]; |
|
| 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 | } |