@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | \***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -27,182 +27,182 @@ discard block |
||
| 27 | 27 | // -> https://www.spip.net/fr_article901.html |
| 28 | 28 | |
| 29 | 29 | function phraser_vieux_logos(&$p) { |
| 30 | - $args = $p->param[0][0] ? [''] : array_shift($p->param); |
|
| 31 | - |
|
| 32 | - foreach ($p->param as $couple) { |
|
| 33 | - $nom = trim($couple[0]); |
|
| 34 | - if ($nom == '') { |
|
| 35 | - array_shift($p->param); |
|
| 36 | - break; |
|
| 37 | - } |
|
| 38 | - $r = phraser_logo_faux_filtres($nom); |
|
| 39 | - if ($r === 0) { |
|
| 40 | - $c = new Texte(); |
|
| 41 | - $c->texte = $nom; |
|
| 42 | - $args[] = [$c]; |
|
| 43 | - array_shift($p->param); |
|
| 44 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 45 | - } elseif ($r === 2) { |
|
| 46 | - $p->etoile = '**'; |
|
| 47 | - array_shift($p->param); |
|
| 48 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 49 | - } elseif ($r === 1) { |
|
| 50 | - array_shift($p->param); |
|
| 51 | - $p->etoile = '*'; |
|
| 52 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 53 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 54 | - $champ = new Champ(); |
|
| 55 | - $champ->nom_boucle = $m[2]; |
|
| 56 | - $champ->nom_champ = $m[3]; |
|
| 57 | - $champ->etoile = $m[5]; |
|
| 58 | - $champ = [$champ]; |
|
| 59 | - if ($m[6]) { |
|
| 60 | - $r = new Texte(); |
|
| 61 | - $r->texte = $m[6]; |
|
| 62 | - $champ[] = $r; |
|
| 63 | - } |
|
| 64 | - $args[] = $champ; |
|
| 65 | - array_shift($p->param); |
|
| 66 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 67 | - } // le cas else est la seule incompatibilite |
|
| 68 | - } |
|
| 69 | - array_unshift($p->param, $args); |
|
| 30 | + $args = $p->param[0][0] ? [''] : array_shift($p->param); |
|
| 31 | + |
|
| 32 | + foreach ($p->param as $couple) { |
|
| 33 | + $nom = trim($couple[0]); |
|
| 34 | + if ($nom == '') { |
|
| 35 | + array_shift($p->param); |
|
| 36 | + break; |
|
| 37 | + } |
|
| 38 | + $r = phraser_logo_faux_filtres($nom); |
|
| 39 | + if ($r === 0) { |
|
| 40 | + $c = new Texte(); |
|
| 41 | + $c->texte = $nom; |
|
| 42 | + $args[] = [$c]; |
|
| 43 | + array_shift($p->param); |
|
| 44 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 45 | + } elseif ($r === 2) { |
|
| 46 | + $p->etoile = '**'; |
|
| 47 | + array_shift($p->param); |
|
| 48 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 49 | + } elseif ($r === 1) { |
|
| 50 | + array_shift($p->param); |
|
| 51 | + $p->etoile = '*'; |
|
| 52 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 53 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 54 | + $champ = new Champ(); |
|
| 55 | + $champ->nom_boucle = $m[2]; |
|
| 56 | + $champ->nom_champ = $m[3]; |
|
| 57 | + $champ->etoile = $m[5]; |
|
| 58 | + $champ = [$champ]; |
|
| 59 | + if ($m[6]) { |
|
| 60 | + $r = new Texte(); |
|
| 61 | + $r->texte = $m[6]; |
|
| 62 | + $champ[] = $r; |
|
| 63 | + } |
|
| 64 | + $args[] = $champ; |
|
| 65 | + array_shift($p->param); |
|
| 66 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 67 | + } // le cas else est la seule incompatibilite |
|
| 68 | + } |
|
| 69 | + array_unshift($p->param, $args); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
| 73 | 73 | function phraser_logo_faux_filtres($nom) { |
| 74 | - return match ($nom) { |
|
| 75 | - 'top', 'left', 'right', 'center', 'bottom' => 0, |
|
| 76 | - 'lien' => 1, |
|
| 77 | - 'fichier' => 2, |
|
| 78 | - default => $nom, |
|
| 79 | - }; |
|
| 74 | + return match ($nom) { |
|
| 75 | + 'top', 'left', 'right', 'center', 'bottom' => 0, |
|
| 76 | + 'lien' => 1, |
|
| 77 | + 'fichier' => 2, |
|
| 78 | + default => $nom, |
|
| 79 | + }; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | // La balise embed_document est a present le modele emb |
| 84 | 84 | |
| 85 | 85 | function phraser_vieux_emb(&$p) { |
| 86 | - if (!is_array($p->param)) { |
|
| 87 | - $p->param = []; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Produire le premier argument {emb} |
|
| 91 | - $texte = new Texte(); |
|
| 92 | - $texte->texte = 'emb'; |
|
| 93 | - $param = ['', [$texte]]; |
|
| 94 | - |
|
| 95 | - // Transformer les filtres en arguments |
|
| 96 | - $paramCount = is_countable($p->param) ? count($p->param) : 0; |
|
| 97 | - for ($i = 0; $i < $paramCount; $i++) { |
|
| 98 | - if ($p->param[$i][0]) { |
|
| 99 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 100 | - break; |
|
| 101 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 102 | - $texte = new Texte(); |
|
| 103 | - $texte->texte = $p->param[$i][0]; |
|
| 104 | - $param[] = [$texte]; |
|
| 105 | - } |
|
| 106 | - array_shift($p->param); |
|
| 107 | - } |
|
| 108 | - array_unshift($p->param, $param); |
|
| 109 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 110 | - $p->nom_champ = 'MODELE'; |
|
| 86 | + if (!is_array($p->param)) { |
|
| 87 | + $p->param = []; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Produire le premier argument {emb} |
|
| 91 | + $texte = new Texte(); |
|
| 92 | + $texte->texte = 'emb'; |
|
| 93 | + $param = ['', [$texte]]; |
|
| 94 | + |
|
| 95 | + // Transformer les filtres en arguments |
|
| 96 | + $paramCount = is_countable($p->param) ? count($p->param) : 0; |
|
| 97 | + for ($i = 0; $i < $paramCount; $i++) { |
|
| 98 | + if ($p->param[$i][0]) { |
|
| 99 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 100 | + break; |
|
| 101 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 102 | + $texte = new Texte(); |
|
| 103 | + $texte->texte = $p->param[$i][0]; |
|
| 104 | + $param[] = [$texte]; |
|
| 105 | + } |
|
| 106 | + array_shift($p->param); |
|
| 107 | + } |
|
| 108 | + array_unshift($p->param, $param); |
|
| 109 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 110 | + $p->nom_champ = 'MODELE'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // Vieux formulaire de recherch |
| 114 | 114 | |
| 115 | 115 | function phraser_vieux_recherche($p) { |
| 116 | - if ($p->param[0][0]) { |
|
| 117 | - $c = new Texte(); |
|
| 118 | - $c->texte = $p->param[0][0]; |
|
| 119 | - $p->param[0][1] = [$c]; |
|
| 120 | - $p->param[0][0] = ''; |
|
| 121 | - $p->fonctions = []; |
|
| 122 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 123 | - } |
|
| 116 | + if ($p->param[0][0]) { |
|
| 117 | + $c = new Texte(); |
|
| 118 | + $c->texte = $p->param[0][0]; |
|
| 119 | + $p->param[0][1] = [$c]; |
|
| 120 | + $p->param[0][0] = ''; |
|
| 121 | + $p->fonctions = []; |
|
| 122 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 123 | + } |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // Gerer la notation [(#EXPOSER|on,off)] |
| 127 | 127 | function phraser_vieux_exposer($p) { |
| 128 | - if ($a = $p->fonctions) { |
|
| 129 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 130 | - $args = []; |
|
| 131 | - if ($regs[1]) { |
|
| 132 | - $a = new Texte(); |
|
| 133 | - $a->texte = $regs[1]; |
|
| 134 | - $args = ['', [$a]]; |
|
| 135 | - if ($regs[3]) { |
|
| 136 | - $a = new Texte(); |
|
| 137 | - $a->texte = $regs[3]; |
|
| 138 | - $args[] = [$a]; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - $p->param[0] = $args; |
|
| 142 | - $p->fonctions = []; |
|
| 143 | - $p->nom_champ = 'EXPOSE'; |
|
| 144 | - } |
|
| 128 | + if ($a = $p->fonctions) { |
|
| 129 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 130 | + $args = []; |
|
| 131 | + if ($regs[1]) { |
|
| 132 | + $a = new Texte(); |
|
| 133 | + $a->texte = $regs[1]; |
|
| 134 | + $args = ['', [$a]]; |
|
| 135 | + if ($regs[3]) { |
|
| 136 | + $a = new Texte(); |
|
| 137 | + $a->texte = $regs[3]; |
|
| 138 | + $args[] = [$a]; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + $p->param[0] = $args; |
|
| 142 | + $p->fonctions = []; |
|
| 143 | + $p->nom_champ = 'EXPOSE'; |
|
| 144 | + } |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | function phraser_vieux_modele($p) { |
| 148 | - normaliser_args_inclumodel($p); |
|
| 148 | + normaliser_args_inclumodel($p); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function phraser_vieux_inclu($p) { |
| 152 | - normaliser_args_inclumodel($p); |
|
| 152 | + normaliser_args_inclumodel($p); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | function normaliser_args_inclumodel($p) { |
| 156 | - $params = $p->param; |
|
| 157 | - if (!$params) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - $args = $params[0]; |
|
| 161 | - if ($args[0]) { |
|
| 162 | - return; |
|
| 163 | - } // filtre immediat |
|
| 164 | - array_shift($p->param); |
|
| 165 | - foreach ($p->param as $l) { |
|
| 166 | - if (!array_shift($l)) { |
|
| 167 | - $args = array_merge($args, $l); |
|
| 168 | - array_shift($p->param); |
|
| 169 | - } else { |
|
| 170 | - break; |
|
| 171 | - } // filtre |
|
| 172 | - } |
|
| 173 | - array_unshift($p->param, $args); |
|
| 156 | + $params = $p->param; |
|
| 157 | + if (!$params) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + $args = $params[0]; |
|
| 161 | + if ($args[0]) { |
|
| 162 | + return; |
|
| 163 | + } // filtre immediat |
|
| 164 | + array_shift($p->param); |
|
| 165 | + foreach ($p->param as $l) { |
|
| 166 | + if (!array_shift($l)) { |
|
| 167 | + $args = array_merge($args, $l); |
|
| 168 | + array_shift($p->param); |
|
| 169 | + } else { |
|
| 170 | + break; |
|
| 171 | + } // filtre |
|
| 172 | + } |
|
| 173 | + array_unshift($p->param, $args); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | function normaliser_inclure($champ) { |
| 177 | - normaliser_args_inclumodel($champ); |
|
| 178 | - $l = $champ->param[0]; |
|
| 179 | - if (is_array($l) && !$l[0]) { |
|
| 180 | - foreach ($l as $k => $p) { |
|
| 181 | - if ($p && $p[0]->type == 'texte' && !strpos($p[0]->texte, '=')) { |
|
| 182 | - $p[0]->texte = trim($p[0]->texte); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - foreach ($l as $k => $p) { |
|
| 186 | - if ( |
|
| 187 | - !$p || $p[0]->type != 'texte' |
|
| 188 | - || !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 189 | - ) { |
|
| 190 | - continue; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($r[1]) { |
|
| 194 | - $p[0]->texte = $r[1]; |
|
| 195 | - } else { |
|
| 196 | - unset($p[0]); |
|
| 197 | - } |
|
| 198 | - $champ->texte = $p; |
|
| 199 | - unset($champ->param[0][$k]); |
|
| 200 | - if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 201 | - array_shift($champ->param); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - spip_log('inclure sans fond ni fichier'); |
|
| 177 | + normaliser_args_inclumodel($champ); |
|
| 178 | + $l = $champ->param[0]; |
|
| 179 | + if (is_array($l) && !$l[0]) { |
|
| 180 | + foreach ($l as $k => $p) { |
|
| 181 | + if ($p && $p[0]->type == 'texte' && !strpos($p[0]->texte, '=')) { |
|
| 182 | + $p[0]->texte = trim($p[0]->texte); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + foreach ($l as $k => $p) { |
|
| 186 | + if ( |
|
| 187 | + !$p || $p[0]->type != 'texte' |
|
| 188 | + || !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 189 | + ) { |
|
| 190 | + continue; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($r[1]) { |
|
| 194 | + $p[0]->texte = $r[1]; |
|
| 195 | + } else { |
|
| 196 | + unset($p[0]); |
|
| 197 | + } |
|
| 198 | + $champ->texte = $p; |
|
| 199 | + unset($champ->param[0][$k]); |
|
| 200 | + if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 201 | + array_shift($champ->param); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + spip_log('inclure sans fond ni fichier'); |
|
| 208 | 208 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\Compilateur\References |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | * - '' si une référence explicite incorrecte est envoyée |
| 44 | 44 | */ |
| 45 | 45 | function index_boucle($p) { |
| 46 | - if (strlen($p->nom_boucle)) { |
|
| 47 | - // retourne l’index explicite demandé s’il existe |
|
| 48 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 49 | - return $p->nom_boucle; |
|
| 50 | - } |
|
| 51 | - return ''; |
|
| 52 | - } |
|
| 53 | - return $p->id_boucle; |
|
| 46 | + if (strlen($p->nom_boucle)) { |
|
| 47 | + // retourne l’index explicite demandé s’il existe |
|
| 48 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 49 | + return $p->nom_boucle; |
|
| 50 | + } |
|
| 51 | + return ''; |
|
| 52 | + } |
|
| 53 | + return $p->id_boucle; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | * - '' si une référence explicite incorrecte est envoyée |
| 74 | 74 | */ |
| 75 | 75 | function index_boucle_mere($p) { |
| 76 | - if (strlen($p->nom_boucle)) { |
|
| 77 | - // retourne l’index explicite demandé s’il existe |
|
| 78 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 79 | - return $p->nom_boucle; |
|
| 80 | - } |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 83 | - if (!empty($p->descr['id_mere'])) { |
|
| 84 | - return $p->descr['id_mere']; |
|
| 85 | - } |
|
| 86 | - return ''; |
|
| 76 | + if (strlen($p->nom_boucle)) { |
|
| 77 | + // retourne l’index explicite demandé s’il existe |
|
| 78 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 79 | + return $p->nom_boucle; |
|
| 80 | + } |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | + if (!empty($p->descr['id_mere'])) { |
|
| 84 | + return $p->descr['id_mere']; |
|
| 85 | + } |
|
| 86 | + return ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -117,74 +117,74 @@ discard block |
||
| 117 | 117 | * Code PHP pour obtenir le champ SQL |
| 118 | 118 | */ |
| 119 | 119 | function index_pile( |
| 120 | - $idb, |
|
| 121 | - $nom_champ, |
|
| 122 | - &$boucles, |
|
| 123 | - $explicite = '', |
|
| 124 | - $defaut = null, |
|
| 125 | - $remonte_pile = true, |
|
| 126 | - $select = true |
|
| 120 | + $idb, |
|
| 121 | + $nom_champ, |
|
| 122 | + &$boucles, |
|
| 123 | + $explicite = '', |
|
| 124 | + $defaut = null, |
|
| 125 | + $remonte_pile = true, |
|
| 126 | + $select = true |
|
| 127 | 127 | ) { |
| 128 | - if (!is_string($defaut)) { |
|
| 129 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $idb_origine = $idb; |
|
| 133 | - $nom_champ_origine = $nom_champ; |
|
| 134 | - |
|
| 135 | - $i = 0; |
|
| 136 | - if (strlen($explicite)) { |
|
| 137 | - // Recherche d'un champ dans un etage superieur |
|
| 138 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 139 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 140 | - $i++; |
|
| 141 | - $idb = $boucles[$idb]->id_parent; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 146 | - $nom_champ = strtolower($nom_champ); |
|
| 147 | - $conditionnel = []; |
|
| 148 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 149 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 150 | - while (isset($boucles[$idb])) { |
|
| 151 | - $joker = true; |
|
| 152 | - // modifie $joker si tous les champs sont autorisés. |
|
| 153 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 154 | - // $c = le nom du champ demandé |
|
| 155 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 156 | - if ($t) { |
|
| 157 | - if ($select && !in_array($t, $boucles[$idb]->select)) { |
|
| 158 | - $boucles[$idb]->select[] = $t; |
|
| 159 | - } |
|
| 160 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 161 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 162 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 163 | - if (!$joker) { |
|
| 164 | - return index_compose($conditionnel, $champ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 168 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 169 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 170 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 171 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($remonte_pile) { |
|
| 175 | - # spip_log("On remonte vers $i"); |
|
| 176 | - // Sinon on remonte d'un cran |
|
| 177 | - $idb = $boucles[$idb]->id_parent; |
|
| 178 | - $i++; |
|
| 179 | - } else { |
|
| 180 | - $idb = null; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - # spip_log("Pas vu $nom_champ"); |
|
| 185 | - // esperons qu'il y sera |
|
| 186 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 187 | - return index_compose($conditionnel, $defaut); |
|
| 128 | + if (!is_string($defaut)) { |
|
| 129 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $idb_origine = $idb; |
|
| 133 | + $nom_champ_origine = $nom_champ; |
|
| 134 | + |
|
| 135 | + $i = 0; |
|
| 136 | + if (strlen($explicite)) { |
|
| 137 | + // Recherche d'un champ dans un etage superieur |
|
| 138 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 139 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 140 | + $i++; |
|
| 141 | + $idb = $boucles[$idb]->id_parent; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 146 | + $nom_champ = strtolower($nom_champ); |
|
| 147 | + $conditionnel = []; |
|
| 148 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 149 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 150 | + while (isset($boucles[$idb])) { |
|
| 151 | + $joker = true; |
|
| 152 | + // modifie $joker si tous les champs sont autorisés. |
|
| 153 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 154 | + // $c = le nom du champ demandé |
|
| 155 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 156 | + if ($t) { |
|
| 157 | + if ($select && !in_array($t, $boucles[$idb]->select)) { |
|
| 158 | + $boucles[$idb]->select[] = $t; |
|
| 159 | + } |
|
| 160 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 161 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 162 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 163 | + if (!$joker) { |
|
| 164 | + return index_compose($conditionnel, $champ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 168 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 169 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 170 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 171 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($remonte_pile) { |
|
| 175 | + # spip_log("On remonte vers $i"); |
|
| 176 | + // Sinon on remonte d'un cran |
|
| 177 | + $idb = $boucles[$idb]->id_parent; |
|
| 178 | + $i++; |
|
| 179 | + } else { |
|
| 180 | + $idb = null; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + # spip_log("Pas vu $nom_champ"); |
|
| 185 | + // esperons qu'il y sera |
|
| 186 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 187 | + return index_compose($conditionnel, $defaut); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -198,12 +198,12 @@ discard block |
||
| 198 | 198 | * @return string Code PHP complet de recherche d'un champ |
| 199 | 199 | */ |
| 200 | 200 | function index_compose($conditionnel, $defaut) { |
| 201 | - while ($c = array_pop($conditionnel)) { |
|
| 202 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 203 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 204 | - } |
|
| 201 | + while ($c = array_pop($conditionnel)) { |
|
| 202 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 203 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - return $defaut; |
|
| 206 | + return $defaut; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -239,98 +239,98 @@ discard block |
||
| 239 | 239 | **/ |
| 240 | 240 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 241 | 241 | |
| 242 | - $r = $boucles[$idb]->type_requete; |
|
| 243 | - // boucle recursive, c'est foutu... |
|
| 244 | - if ($r == TYPE_RECURSIF) { |
|
| 245 | - return []; |
|
| 246 | - } |
|
| 247 | - if (!$r) { |
|
| 248 | - $joker = false; // indiquer a l'appelant |
|
| 249 | - # continuer pour chercher l'erreur suivante |
|
| 250 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $desc = $boucles[$idb]->show; |
|
| 254 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 255 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 256 | - if ($excep) { |
|
| 257 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - // il y a un alias connu pour ce champ |
|
| 261 | - if ($excep) { |
|
| 262 | - $joker = false; // indiquer a l'appelant |
|
| 263 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // le champ existe dans la table, on le prend. |
|
| 267 | - if (isset($desc['field'][$nom_champ])) { |
|
| 268 | - $t = $boucles[$idb]->id_table ?? ''; |
|
| 269 | - $joker = false; // indiquer a l'appelant |
|
| 270 | - // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 271 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Tous les champs sont-ils acceptés ? |
|
| 275 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 276 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 277 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 278 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 279 | - if ( |
|
| 280 | - /*$joker AND */ |
|
| 281 | - isset($desc['field']['*']) |
|
| 282 | - ) { |
|
| 283 | - $joker = true; // indiquer a l'appelant |
|
| 284 | - return [$nom_champ, $nom_champ]; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $joker = false; // indiquer a l'appelant |
|
| 288 | - |
|
| 289 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 290 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 291 | - [, $_table, $_nom_champ] = $r; |
|
| 292 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 293 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 294 | - return index_exception( |
|
| 295 | - $boucles[$idb], |
|
| 296 | - $desc, |
|
| 297 | - $_alias, |
|
| 298 | - [$_table, $_nom_champ] |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - return ['', '']; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // pas d'alias, pas de champ, pas de joker... |
|
| 305 | - // tenter via une jointure... |
|
| 306 | - |
|
| 307 | - // regarder si le champ est deja dans une jointure existante |
|
| 308 | - // sinon, si il y a des joitures explicites, la construire |
|
| 309 | - if ( |
|
| 310 | - !($t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) |
|
| 311 | - && $boucles[$idb]->jointures_explicites |
|
| 312 | - ) { |
|
| 313 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 314 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 315 | - // mais est-ce ce qu'on veut ? |
|
| 316 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 317 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 318 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if ($t) { |
|
| 323 | - // si on a trouvé une jointure possible, on fait comme |
|
| 324 | - // si c'était une exception pour le champ demandé |
|
| 325 | - return index_exception( |
|
| 326 | - $boucles[$idb], |
|
| 327 | - $desc, |
|
| 328 | - $nom_champ, |
|
| 329 | - [$t[1]['id_table'], reset($t[2])] |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - return ['', '']; |
|
| 242 | + $r = $boucles[$idb]->type_requete; |
|
| 243 | + // boucle recursive, c'est foutu... |
|
| 244 | + if ($r == TYPE_RECURSIF) { |
|
| 245 | + return []; |
|
| 246 | + } |
|
| 247 | + if (!$r) { |
|
| 248 | + $joker = false; // indiquer a l'appelant |
|
| 249 | + # continuer pour chercher l'erreur suivante |
|
| 250 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $desc = $boucles[$idb]->show; |
|
| 254 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 255 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 256 | + if ($excep) { |
|
| 257 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + // il y a un alias connu pour ce champ |
|
| 261 | + if ($excep) { |
|
| 262 | + $joker = false; // indiquer a l'appelant |
|
| 263 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // le champ existe dans la table, on le prend. |
|
| 267 | + if (isset($desc['field'][$nom_champ])) { |
|
| 268 | + $t = $boucles[$idb]->id_table ?? ''; |
|
| 269 | + $joker = false; // indiquer a l'appelant |
|
| 270 | + // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 271 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Tous les champs sont-ils acceptés ? |
|
| 275 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 276 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 277 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 278 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 279 | + if ( |
|
| 280 | + /*$joker AND */ |
|
| 281 | + isset($desc['field']['*']) |
|
| 282 | + ) { |
|
| 283 | + $joker = true; // indiquer a l'appelant |
|
| 284 | + return [$nom_champ, $nom_champ]; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $joker = false; // indiquer a l'appelant |
|
| 288 | + |
|
| 289 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 290 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 291 | + [, $_table, $_nom_champ] = $r; |
|
| 292 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 293 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 294 | + return index_exception( |
|
| 295 | + $boucles[$idb], |
|
| 296 | + $desc, |
|
| 297 | + $_alias, |
|
| 298 | + [$_table, $_nom_champ] |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + return ['', '']; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // pas d'alias, pas de champ, pas de joker... |
|
| 305 | + // tenter via une jointure... |
|
| 306 | + |
|
| 307 | + // regarder si le champ est deja dans une jointure existante |
|
| 308 | + // sinon, si il y a des joitures explicites, la construire |
|
| 309 | + if ( |
|
| 310 | + !($t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) |
|
| 311 | + && $boucles[$idb]->jointures_explicites |
|
| 312 | + ) { |
|
| 313 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 314 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 315 | + // mais est-ce ce qu'on veut ? |
|
| 316 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 317 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 318 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if ($t) { |
|
| 323 | + // si on a trouvé une jointure possible, on fait comme |
|
| 324 | + // si c'était une exception pour le champ demandé |
|
| 325 | + return index_exception( |
|
| 326 | + $boucles[$idb], |
|
| 327 | + $desc, |
|
| 328 | + $nom_champ, |
|
| 329 | + [$t[1]['id_table'], reset($t[2])] |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + return ['', '']; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | |
@@ -358,52 +358,52 @@ discard block |
||
| 358 | 358 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 359 | 359 | **/ |
| 360 | 360 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_array($excep)) { |
|
| 367 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | - $t = null; |
|
| 369 | - if (count($excep) == 3) { |
|
| 370 | - $index_exception_derogatoire = array_pop($excep); |
|
| 371 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | - } |
|
| 373 | - if ($t == null) { |
|
| 374 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | - if (!$j) { |
|
| 378 | - return ['', '']; |
|
| 379 | - } |
|
| 380 | - $e = $j['table']; |
|
| 381 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | - $k = $j['key']['PRIMARY KEY']; |
|
| 383 | - if (strpos($k, ',')) { |
|
| 384 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | - if (!in_array($k, $l)) { |
|
| 387 | - spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 388 | - |
|
| 389 | - return ['', '']; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | - fabrique_jointures($boucle, [$k]); |
|
| 394 | - $t = array_search($e, $boucle->from); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - $t = $boucle->id_table; |
|
| 399 | - } |
|
| 400 | - // demander a SQL de gerer le synonyme |
|
| 401 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | - if ($excep != $nom_champ) { |
|
| 403 | - $excep .= ' AS ' . $nom_champ; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return ["$t.$excep", $nom_champ]; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_array($excep)) { |
|
| 367 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 368 | + $t = null; |
|
| 369 | + if (count($excep) == 3) { |
|
| 370 | + $index_exception_derogatoire = array_pop($excep); |
|
| 371 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 372 | + } |
|
| 373 | + if ($t == null) { |
|
| 374 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 377 | + if (!$j) { |
|
| 378 | + return ['', '']; |
|
| 379 | + } |
|
| 380 | + $e = $j['table']; |
|
| 381 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 382 | + $k = $j['key']['PRIMARY KEY']; |
|
| 383 | + if (strpos($k, ',')) { |
|
| 384 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 385 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 386 | + if (!in_array($k, $l)) { |
|
| 387 | + spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 388 | + |
|
| 389 | + return ['', '']; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 393 | + fabrique_jointures($boucle, [$k]); |
|
| 394 | + $t = array_search($e, $boucle->from); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + $t = $boucle->id_table; |
|
| 399 | + } |
|
| 400 | + // demander a SQL de gerer le synonyme |
|
| 401 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 402 | + if ($excep != $nom_champ) { |
|
| 403 | + $excep .= ' AS ' . $nom_champ; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return ["$t.$excep", $nom_champ]; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * Code PHP pour retrouver le champ |
| 429 | 429 | */ |
| 430 | 430 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 431 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 431 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | |
@@ -448,9 +448,9 @@ discard block |
||
| 448 | 448 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 449 | 449 | **/ |
| 450 | 450 | function calculer_champ($p) { |
| 451 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 451 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 452 | 452 | |
| 453 | - return applique_filtres($p); |
|
| 453 | + return applique_filtres($p); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function calculer_balise(string $nom, Champ $p): Champ { |
| 489 | 489 | |
| 490 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | - $p->balise_calculee = true; |
|
| 493 | - $res = $f($p); |
|
| 494 | - if ($res !== null && is_object($res)) { |
|
| 495 | - return $res; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Certaines des balises comportant un _ sont generiques |
|
| 500 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | - $res = $balise_generique['fonction_generique']($p); |
|
| 502 | - if ($res !== null && is_object($res)) { |
|
| 503 | - return $res; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | - |
|
| 509 | - return $f($nom, $p); |
|
| 490 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 491 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 492 | + $p->balise_calculee = true; |
|
| 493 | + $res = $f($p); |
|
| 494 | + if ($res !== null && is_object($res)) { |
|
| 495 | + return $res; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Certaines des balises comportant un _ sont generiques |
|
| 500 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 501 | + $res = $balise_generique['fonction_generique']($p); |
|
| 502 | + if ($res !== null && is_object($res)) { |
|
| 503 | + return $res; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 508 | + |
|
| 509 | + return $f($nom, $p); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | |
@@ -534,33 +534,33 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 536 | 536 | |
| 537 | - // ca pourrait etre un champ SQL homonyme, |
|
| 538 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | - |
|
| 540 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | - if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 543 | - $code = addslashes($p->fonctions[0][1]); |
|
| 544 | - $p->code .= " . '$code'"; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | - if (str_starts_with($nom, 'ID_')) { |
|
| 549 | - $p->interdire_scripts = false; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | - // SI le champ SQL n'est pas trouve |
|
| 554 | - // ET si la balise a une forme de couleur |
|
| 555 | - // ET s'il n'y a ni filtre ni etoile |
|
| 556 | - // ALORS retourner la couleur. |
|
| 557 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | - if (preg_match('/^[A-F]{1,6}$/i', $nom) && !$p->etoile && !$p->fonctions) { |
|
| 559 | - $p->code = "'#$nom'"; |
|
| 560 | - $p->interdire_scripts = false; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return $p; |
|
| 537 | + // ca pourrait etre un champ SQL homonyme, |
|
| 538 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 539 | + |
|
| 540 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 541 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 542 | + if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 543 | + $code = addslashes($p->fonctions[0][1]); |
|
| 544 | + $p->code .= " . '$code'"; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 548 | + if (str_starts_with($nom, 'ID_')) { |
|
| 549 | + $p->interdire_scripts = false; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 553 | + // SI le champ SQL n'est pas trouve |
|
| 554 | + // ET si la balise a une forme de couleur |
|
| 555 | + // ET s'il n'y a ni filtre ni etoile |
|
| 556 | + // ALORS retourner la couleur. |
|
| 557 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 558 | + if (preg_match('/^[A-F]{1,6}$/i', $nom) && !$p->etoile && !$p->fonctions) { |
|
| 559 | + $p->code = "'#$nom'"; |
|
| 560 | + $p->interdire_scripts = false; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return $p; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -608,52 +608,52 @@ discard block |
||
| 608 | 608 | **/ |
| 609 | 609 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 610 | 610 | |
| 611 | - if (!balise_distante_interdite($p)) { |
|
| 612 | - $p->code = "''"; |
|
| 613 | - |
|
| 614 | - return $p; |
|
| 615 | - } |
|
| 616 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 617 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 618 | - if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 619 | - $p->fonctions = []; |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - if ($p->param && ($c = $p->param[0])) { |
|
| 623 | - // liste d'arguments commence toujours par la chaine vide |
|
| 624 | - array_shift($c); |
|
| 625 | - // construire la liste d'arguments comme pour un filtre |
|
| 626 | - $param = compose_filtres_args($p, $c, ','); |
|
| 627 | - } else { |
|
| 628 | - $param = ''; |
|
| 629 | - } |
|
| 630 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 631 | - |
|
| 632 | - $dans_un_modele = false; |
|
| 633 | - if ( |
|
| 634 | - !empty($p->descr['sourcefile']) && ($f = $p->descr['sourcefile']) && basename(dirname($f)) === 'modeles' |
|
| 635 | - ) { |
|
| 636 | - $dans_un_modele = true; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // un modele est toujours inséré en texte dans son contenant |
|
| 640 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 641 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 642 | - // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 643 | - // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 644 | - // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 645 | - $p->code = sprintf( |
|
| 646 | - $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 647 | - $nom, |
|
| 648 | - implode(',', $collecte), |
|
| 649 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 650 | - memoriser_contexte_compil($p), |
|
| 651 | - ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 652 | - ); |
|
| 653 | - |
|
| 654 | - $p->interdire_scripts = false; |
|
| 655 | - |
|
| 656 | - return $p; |
|
| 611 | + if (!balise_distante_interdite($p)) { |
|
| 612 | + $p->code = "''"; |
|
| 613 | + |
|
| 614 | + return $p; |
|
| 615 | + } |
|
| 616 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 617 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 618 | + if ($p->fonctions && !$p->fonctions[0][0] && $p->fonctions[0][1]) { |
|
| 619 | + $p->fonctions = []; |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + if ($p->param && ($c = $p->param[0])) { |
|
| 623 | + // liste d'arguments commence toujours par la chaine vide |
|
| 624 | + array_shift($c); |
|
| 625 | + // construire la liste d'arguments comme pour un filtre |
|
| 626 | + $param = compose_filtres_args($p, $c, ','); |
|
| 627 | + } else { |
|
| 628 | + $param = ''; |
|
| 629 | + } |
|
| 630 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 631 | + |
|
| 632 | + $dans_un_modele = false; |
|
| 633 | + if ( |
|
| 634 | + !empty($p->descr['sourcefile']) && ($f = $p->descr['sourcefile']) && basename(dirname($f)) === 'modeles' |
|
| 635 | + ) { |
|
| 636 | + $dans_un_modele = true; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // un modele est toujours inséré en texte dans son contenant |
|
| 640 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 641 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 642 | + // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 643 | + // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 644 | + // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 645 | + $p->code = sprintf( |
|
| 646 | + $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 647 | + $nom, |
|
| 648 | + implode(',', $collecte), |
|
| 649 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 650 | + memoriser_contexte_compil($p), |
|
| 651 | + ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 652 | + ); |
|
| 653 | + |
|
| 654 | + $p->interdire_scripts = false; |
|
| 655 | + |
|
| 656 | + return $p; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
@@ -683,17 +683,17 @@ discard block |
||
| 683 | 683 | * Liste des codes PHP d'éxecution des balises collectées |
| 684 | 684 | **/ |
| 685 | 685 | function collecter_balise_dynamique(array $l, Champ &$p, string $nom): array { |
| 686 | - $args = []; |
|
| 687 | - foreach ($l as $c) { |
|
| 688 | - if ($c === null) { |
|
| 689 | - $args[] = 'null'; |
|
| 690 | - } else { |
|
| 691 | - $x = calculer_balise($c, $p); |
|
| 692 | - $args[] = $x->code; |
|
| 693 | - } |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $args; |
|
| 686 | + $args = []; |
|
| 687 | + foreach ($l as $c) { |
|
| 688 | + if ($c === null) { |
|
| 689 | + $args[] = 'null'; |
|
| 690 | + } else { |
|
| 691 | + $x = calculer_balise($c, $p); |
|
| 692 | + $args[] = $x->code; |
|
| 693 | + } |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $args; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -708,19 +708,19 @@ discard block |
||
| 708 | 708 | * Nom de la connexion |
| 709 | 709 | **/ |
| 710 | 710 | function trouver_nom_serveur_distant($p) { |
| 711 | - $nom = $p->id_boucle; |
|
| 712 | - if ( |
|
| 713 | - $nom && isset($p->boucles[$nom]) |
|
| 714 | - ) { |
|
| 715 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 716 | - if ( |
|
| 717 | - strlen($s) && strlen($serveur = strtolower($s)) && !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 718 | - ) { |
|
| 719 | - return $serveur; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - return ''; |
|
| 711 | + $nom = $p->id_boucle; |
|
| 712 | + if ( |
|
| 713 | + $nom && isset($p->boucles[$nom]) |
|
| 714 | + ) { |
|
| 715 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 716 | + if ( |
|
| 717 | + strlen($s) && strlen($serveur = strtolower($s)) && !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 718 | + ) { |
|
| 719 | + return $serveur; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + return ''; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
@@ -744,15 +744,15 @@ discard block |
||
| 744 | 744 | * - false : La balise est interdite car le serveur est distant |
| 745 | 745 | **/ |
| 746 | 746 | function balise_distante_interdite($p) { |
| 747 | - $nom = $p->id_boucle; |
|
| 747 | + $nom = $p->id_boucle; |
|
| 748 | 748 | |
| 749 | - if ($nom && trouver_nom_serveur_distant($p)) { |
|
| 750 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 749 | + if ($nom && trouver_nom_serveur_distant($p)) { |
|
| 750 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 751 | 751 | |
| 752 | - return false; |
|
| 753 | - } |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - return true; |
|
| 755 | + return true; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -762,75 +762,75 @@ discard block |
||
| 762 | 762 | // |
| 763 | 763 | function champs_traitements($p) { |
| 764 | 764 | |
| 765 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 766 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 767 | - } else { |
|
| 768 | - // quand on utilise un traitement catch-all * |
|
| 769 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 770 | - // leur propre securite |
|
| 771 | - $ps = $p->balise_calculee ? false : $GLOBALS['table_des_traitements']['*']; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - if (is_array($ps)) { |
|
| 775 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 776 | - $idb = index_boucle($p); |
|
| 777 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 778 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 779 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 783 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 784 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 785 | - |
|
| 786 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 787 | - if ($type_requete && isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 788 | - $type_alias = $type_requete; |
|
| 789 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 790 | - } else { |
|
| 791 | - $type_alias = false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 795 | - if ($table_sql && isset($ps[$table_sql])) { |
|
| 796 | - $ps = $ps[$table_sql]; |
|
| 797 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 798 | - elseif ($type_requete && isset($ps[$type_requete])) { |
|
| 799 | - $ps = $ps[$type_requete]; |
|
| 800 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 801 | - elseif ($type_alias && isset($ps[$type_alias])) { |
|
| 802 | - $ps = $ps[$type_alias]; |
|
| 803 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 804 | - elseif (isset($ps[0])) { |
|
| 805 | - $ps = $ps[0]; |
|
| 806 | - } else { |
|
| 807 | - $ps = false; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - if (!$ps) { |
|
| 812 | - return $p->code; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 816 | - // ou si in INCLURE contient {doublons} |
|
| 817 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 818 | - // dans les filtres propre() ou typo() |
|
| 819 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 820 | - |
|
| 821 | - if ( |
|
| 822 | - isset($p->descr['documents']) |
|
| 823 | - && $p->descr['documents'] |
|
| 824 | - && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
|
| 825 | - ) { |
|
| 826 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 830 | - // dans la declaration des traitements des champs sensibles |
|
| 831 | - |
|
| 832 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 833 | - return str_replace('%s', $p->code, $ps); |
|
| 765 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 766 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 767 | + } else { |
|
| 768 | + // quand on utilise un traitement catch-all * |
|
| 769 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 770 | + // leur propre securite |
|
| 771 | + $ps = $p->balise_calculee ? false : $GLOBALS['table_des_traitements']['*']; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + if (is_array($ps)) { |
|
| 775 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 776 | + $idb = index_boucle($p); |
|
| 777 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 778 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 779 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 783 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 784 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 785 | + |
|
| 786 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 787 | + if ($type_requete && isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 788 | + $type_alias = $type_requete; |
|
| 789 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 790 | + } else { |
|
| 791 | + $type_alias = false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 795 | + if ($table_sql && isset($ps[$table_sql])) { |
|
| 796 | + $ps = $ps[$table_sql]; |
|
| 797 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 798 | + elseif ($type_requete && isset($ps[$type_requete])) { |
|
| 799 | + $ps = $ps[$type_requete]; |
|
| 800 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 801 | + elseif ($type_alias && isset($ps[$type_alias])) { |
|
| 802 | + $ps = $ps[$type_alias]; |
|
| 803 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 804 | + elseif (isset($ps[0])) { |
|
| 805 | + $ps = $ps[0]; |
|
| 806 | + } else { |
|
| 807 | + $ps = false; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + if (!$ps) { |
|
| 812 | + return $p->code; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 816 | + // ou si in INCLURE contient {doublons} |
|
| 817 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 818 | + // dans les filtres propre() ou typo() |
|
| 819 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 820 | + |
|
| 821 | + if ( |
|
| 822 | + isset($p->descr['documents']) |
|
| 823 | + && $p->descr['documents'] |
|
| 824 | + && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
|
| 825 | + ) { |
|
| 826 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 830 | + // dans la declaration des traitements des champs sensibles |
|
| 831 | + |
|
| 832 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 833 | + return str_replace('%s', $p->code, $ps); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | |
@@ -842,96 +842,96 @@ discard block |
||
| 842 | 842 | // |
| 843 | 843 | function applique_filtres($p) { |
| 844 | 844 | |
| 845 | - // Traitements standards (cf. supra) |
|
| 846 | - $code = $p->etoile == '' ? champs_traitements($p) : $p->code; |
|
| 845 | + // Traitements standards (cf. supra) |
|
| 846 | + $code = $p->etoile == '' ? champs_traitements($p) : $p->code; |
|
| 847 | 847 | |
| 848 | - // Appliquer les filtres perso |
|
| 849 | - if ($p->param) { |
|
| 850 | - $code = compose_filtres($p, $code); |
|
| 851 | - } |
|
| 848 | + // Appliquer les filtres perso |
|
| 849 | + if ($p->param) { |
|
| 850 | + $code = compose_filtres($p, $code); |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 854 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 855 | - if (isset($p->descr['session'])) { |
|
| 856 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 857 | - } |
|
| 853 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 854 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 855 | + if (isset($p->descr['session'])) { |
|
| 856 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 857 | + } |
|
| 858 | 858 | |
| 859 | - return sandbox_composer_interdire_scripts($code, $p); |
|
| 859 | + return sandbox_composer_interdire_scripts($code, $p); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 863 | 863 | function compose_filtres(&$p, $code) { |
| 864 | 864 | |
| 865 | - $image_miette = false; |
|
| 866 | - foreach ($p->param as $filtre) { |
|
| 867 | - $fonc = array_shift($filtre); |
|
| 868 | - if (!$fonc) { |
|
| 869 | - continue; |
|
| 870 | - } // normalement qu'au premier tour. |
|
| 871 | - $is_filtre_image = (str_starts_with($fonc, 'image_') && $fonc != 'image_graver'); |
|
| 872 | - if ($image_miette && !$is_filtre_image) { |
|
| 873 | - // il faut graver maintenant car apres le filtre en cours |
|
| 874 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | - $code = "filtrer('image_graver', $code)"; |
|
| 876 | - $image_miette = false; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - // recuperer les arguments du filtre, |
|
| 880 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | - if ($fonc !== '?') { |
|
| 883 | - $sep = ','; |
|
| 884 | - } else { |
|
| 885 | - $sep = ':'; |
|
| 886 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | - if ($countfiltre != 2) { |
|
| 888 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | - $countfiltre = 2; |
|
| 890 | - } |
|
| 891 | - } |
|
| 892 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | - if ($logique) { |
|
| 895 | - $code = $logique; |
|
| 896 | - } else { |
|
| 897 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | - if ($is_filtre_image) { |
|
| 899 | - $image_miette = true; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | - if ($image_miette) { |
|
| 905 | - $code = "filtrer('image_graver',$code)"; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - return $code; |
|
| 865 | + $image_miette = false; |
|
| 866 | + foreach ($p->param as $filtre) { |
|
| 867 | + $fonc = array_shift($filtre); |
|
| 868 | + if (!$fonc) { |
|
| 869 | + continue; |
|
| 870 | + } // normalement qu'au premier tour. |
|
| 871 | + $is_filtre_image = (str_starts_with($fonc, 'image_') && $fonc != 'image_graver'); |
|
| 872 | + if ($image_miette && !$is_filtre_image) { |
|
| 873 | + // il faut graver maintenant car apres le filtre en cours |
|
| 874 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 875 | + $code = "filtrer('image_graver', $code)"; |
|
| 876 | + $image_miette = false; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + // recuperer les arguments du filtre, |
|
| 880 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 881 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 882 | + if ($fonc !== '?') { |
|
| 883 | + $sep = ','; |
|
| 884 | + } else { |
|
| 885 | + $sep = ':'; |
|
| 886 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 887 | + if ($countfiltre != 2) { |
|
| 888 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 889 | + $countfiltre = 2; |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 893 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 894 | + if ($logique) { |
|
| 895 | + $code = $logique; |
|
| 896 | + } else { |
|
| 897 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 898 | + if ($is_filtre_image) { |
|
| 899 | + $image_miette = true; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 904 | + if ($image_miette) { |
|
| 905 | + $code = "filtrer('image_graver',$code)"; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + return $code; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 912 | 912 | // et comparateurs |
| 913 | 913 | function filtre_logique($fonc, $code, $arg) |
| 914 | 914 | { |
| 915 | - return match (true) { |
|
| 916 | - in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 917 | - $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 918 | - $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 919 | - $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 920 | - $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 921 | - $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 922 | - $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 923 | - default => '', |
|
| 924 | - }; |
|
| 915 | + return match (true) { |
|
| 916 | + in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 917 | + $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 918 | + $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 919 | + $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 920 | + $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 921 | + $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 922 | + $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 923 | + default => '', |
|
| 924 | + }; |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | function compose_filtres_args($p, $args, $sep) { |
| 928 | - $arglist = ''; |
|
| 929 | - foreach ($args as $arg) { |
|
| 930 | - $arglist .= $sep . |
|
| 931 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 932 | - } |
|
| 928 | + $arglist = ''; |
|
| 929 | + foreach ($args as $arg) { |
|
| 930 | + $arglist .= $sep . |
|
| 931 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 932 | + } |
|
| 933 | 933 | |
| 934 | - return $arglist; |
|
| 934 | + return $arglist; |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | |
@@ -949,15 +949,15 @@ discard block |
||
| 949 | 949 | **/ |
| 950 | 950 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 951 | 951 | |
| 952 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 953 | - if ($boucles[$idb]->externe) { |
|
| 954 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 955 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 956 | - // on ignore le defaut fourni dans ce cas |
|
| 957 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 958 | - } |
|
| 952 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 953 | + if ($boucles[$idb]->externe) { |
|
| 954 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 955 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 956 | + // on ignore le defaut fourni dans ce cas |
|
| 957 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 960 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | // |
@@ -971,30 +971,30 @@ discard block |
||
| 971 | 971 | // |
| 972 | 972 | |
| 973 | 973 | function rindex_pile($p, $champ, $motif) { |
| 974 | - $n = 0; |
|
| 975 | - $b = $p->id_boucle; |
|
| 976 | - $p->code = ''; |
|
| 977 | - while ($b != '') { |
|
| 978 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 979 | - if ($critere->op == $motif) { |
|
| 980 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 981 | - "]['$champ']"; |
|
| 982 | - $b = ''; |
|
| 983 | - break 2; |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - $n++; |
|
| 987 | - $b = $p->boucles[$b]->id_parent; |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 991 | - if (!$p->code) { |
|
| 992 | - $p->code = "''"; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - $p->interdire_scripts = false; |
|
| 996 | - |
|
| 997 | - return $p; |
|
| 974 | + $n = 0; |
|
| 975 | + $b = $p->id_boucle; |
|
| 976 | + $p->code = ''; |
|
| 977 | + while ($b != '') { |
|
| 978 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 979 | + if ($critere->op == $motif) { |
|
| 980 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 981 | + "]['$champ']"; |
|
| 982 | + $b = ''; |
|
| 983 | + break 2; |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + $n++; |
|
| 987 | + $b = $p->boucles[$b]->id_parent; |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 991 | + if (!$p->code) { |
|
| 992 | + $p->code = "''"; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + $p->interdire_scripts = false; |
|
| 996 | + |
|
| 997 | + return $p; |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | /** |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1005 | 1005 | */ |
| 1006 | 1006 | function zbug_presenter_champ($p, $champ = '') { |
| 1007 | - $balise = $champ ?: $p->nom_champ; |
|
| 1008 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1009 | - return "#{$explicite}{$balise}"; |
|
| 1007 | + $balise = $champ ?: $p->nom_champ; |
|
| 1008 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1009 | + return "#{$explicite}{$balise}"; |
|
| 1010 | 1010 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $select = true |
| 127 | 127 | ) { |
| 128 | 128 | if (!is_string($defaut)) { |
| 129 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 129 | + $defaut = '($Pile[0][\''.strtolower($nom_champ).'\'] ?? null)'; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $idb_origine = $idb; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | // renseigner la boucle source de ce champ pour les traitements |
| 161 | 161 | $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
| 162 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 162 | + $champ = '$Pile[$SP'.($i ? "-$i" : '').'][\''.$c.'\']'; |
|
| 163 | 163 | if (!$joker) { |
| 164 | 164 | return index_compose($conditionnel, $champ); |
| 165 | 165 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | function index_compose($conditionnel, $defaut) { |
| 201 | 201 | while ($c = array_pop($conditionnel)) { |
| 202 | 202 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 203 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 203 | + $defaut = "($c:(".($defaut ?: "''").'))'; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | return $defaut; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | if (!$r) { |
| 248 | 248 | $joker = false; // indiquer a l'appelant |
| 249 | 249 | # continuer pour chercher l'erreur suivante |
| 250 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 250 | + return ["'#".$r.':'.$nom_champ."'", '']; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | $desc = $boucles[$idb]->show; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
| 291 | 291 | [, $_table, $_nom_champ] = $r; |
| 292 | 292 | if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
| 293 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 293 | + $_alias = $cle.'_'.$_nom_champ; |
|
| 294 | 294 | return index_exception( |
| 295 | 295 | $boucles[$idb], |
| 296 | 296 | $desc, |
@@ -371,8 +371,8 @@ discard block |
||
| 371 | 371 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 372 | 372 | } |
| 373 | 373 | if ($t == null) { |
| 374 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 374 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 375 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 376 | 376 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 377 | 377 | if (!$j) { |
| 378 | 378 | return ['', '']; |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $l = (preg_split('/\s*,\s*/', $k)); |
| 385 | 385 | $k = $desc['key']['PRIMARY KEY']; |
| 386 | 386 | if (!in_array($k, $l)) { |
| 387 | - spip_log("jointure impossible $e " . implode(',', $l)); |
|
| 387 | + spip_log("jointure impossible $e ".implode(',', $l)); |
|
| 388 | 388 | |
| 389 | 389 | return ['', '']; |
| 390 | 390 | } |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | // demander a SQL de gerer le synonyme |
| 401 | 401 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 402 | 402 | if ($excep != $nom_champ) { |
| 403 | - $excep .= ' AS ' . $nom_champ; |
|
| 403 | + $excep .= ' AS '.$nom_champ; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | return ["$t.$excep", $nom_champ]; |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | implode(',', $collecte), |
| 649 | 649 | ($collecte ? $param : substr($param, 1)), # virer la virgule |
| 650 | 650 | memoriser_contexte_compil($p), |
| 651 | - ($supp ? ', ' . implode(',', $supp) : ('')) |
|
| 651 | + ($supp ? ', '.implode(',', $supp) : ('')) |
|
| 652 | 652 | ); |
| 653 | 653 | |
| 654 | 654 | $p->interdire_scripts = false; |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | * @return array |
| 683 | 683 | * Liste des codes PHP d'éxecution des balises collectées |
| 684 | 684 | **/ |
| 685 | -function collecter_balise_dynamique(array $l, Champ &$p, string $nom): array { |
|
| 685 | +function collecter_balise_dynamique(array $l, Champ & $p, string $nom): array { |
|
| 686 | 686 | $args = []; |
| 687 | 687 | foreach ($l as $c) { |
| 688 | 688 | if ($c === null) { |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | $nom = $p->id_boucle; |
| 748 | 748 | |
| 749 | 749 | if ($nom && trouver_nom_serveur_distant($p)) { |
| 750 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 750 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 751 | 751 | |
| 752 | 752 | return false; |
| 753 | 753 | } |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | && $p->descr['documents'] |
| 824 | 824 | && (str_contains($ps, 'propre') || str_contains($ps, 'typo')) |
| 825 | 825 | ) { |
| 826 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 826 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | // La protection des champs par |safehtml est assuree par les extensions |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | function compose_filtres_args($p, $args, $sep) { |
| 928 | 928 | $arglist = ''; |
| 929 | 929 | foreach ($args as $arg) { |
| 930 | - $arglist .= $sep . |
|
| 930 | + $arglist .= $sep. |
|
| 931 | 931 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 932 | 932 | } |
| 933 | 933 | |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | while ($b != '') { |
| 978 | 978 | foreach ($p->boucles[$b]->criteres as $critere) { |
| 979 | 979 | if ($critere->op == $motif) { |
| 980 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | + $p->code = '$Pile[$SP'.(($n == 0) ? '' : "-$n"). |
|
| 981 | 981 | "]['$champ']"; |
| 982 | 982 | $b = ''; |
| 983 | 983 | break 2; |
@@ -1005,6 +1005,6 @@ discard block |
||
| 1005 | 1005 | */ |
| 1006 | 1006 | function zbug_presenter_champ($p, $champ = '') { |
| 1007 | 1007 | $balise = $champ ?: $p->nom_champ; |
| 1008 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | + $explicite = $p->nom_boucle ? $p->nom_boucle.':' : ''; |
|
| 1009 | 1009 | return "#{$explicite}{$balise}"; |
| 1010 | 1010 | } |
@@ -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, $texte, $match)) { |
|
| 75 | - $match = array_pad($match, 3, null); |
|
| 76 | - $p = strpos($texte, (string) $match[0]); |
|
| 77 | - $debut = substr($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($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$,', $fichier, $r)) { |
|
| 89 | - $fichier = $r[1]; |
|
| 90 | - } |
|
| 91 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 92 | - $texte = substr($texte, $p + strlen($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, $texte, $match)) { |
|
| 75 | + $match = array_pad($match, 3, null); |
|
| 76 | + $p = strpos($texte, (string) $match[0]); |
|
| 77 | + $debut = substr($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($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$,', $fichier, $r)) { |
|
| 89 | + $fichier = $r[1]; |
|
| 90 | + } |
|
| 91 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 92 | + $texte = substr($texte, $p + strlen($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, $texte, $m, PREG_SET_ORDER)) { |
|
| 113 | - foreach ($m as $match) { |
|
| 114 | - $p = strpos($texte, (string) $match[0]); |
|
| 115 | - $debut = substr($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($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, $texte, $m, PREG_SET_ORDER)) { |
|
| 113 | + foreach ($m as $match) { |
|
| 114 | + $p = strpos($texte, (string) $match[0]); |
|
| 115 | + $debut = substr($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($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($match[0]) : 0)); |
|
| 176 | - if ($debut) { |
|
| 177 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 178 | - } |
|
| 179 | - $texte = substr($texte, $p + strlen($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($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, $largs, $r)) { |
|
| 191 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 192 | - $largs = substr($largs, strlen($r[0])); |
|
| 193 | - } |
|
| 194 | - $champ->arg = $args; |
|
| 195 | - $champ->nom_champ = strtolower($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($match[0]) : 0)); |
|
| 176 | + if ($debut) { |
|
| 177 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 178 | + } |
|
| 179 | + $texte = substr($texte, $p + strlen($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($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, $largs, $r)) { |
|
| 191 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 192 | + $largs = substr($largs, strlen($r[0])); |
|
| 193 | + } |
|
| 194 | + $champ->arg = $args; |
|
| 195 | + $champ->nom_champ = strtolower($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($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($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($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($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($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($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', $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($rec); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - while ($next == '|') { |
|
| 406 | - $pos_apres = 0; |
|
| 407 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | - $args = substr($rec, $pos_apres); |
|
| 409 | - $next = $args[0] ?? ''; |
|
| 410 | - } |
|
| 411 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | - if ($champ->param === false) { |
|
| 413 | - $err_f = true; |
|
| 414 | - } else { |
|
| 415 | - phraser_vieux($champ); |
|
| 416 | - } |
|
| 417 | - if ($par == ')') { |
|
| 418 | - $args = substr($args, 1); |
|
| 419 | - } |
|
| 420 | - $collecte[] = $champ; |
|
| 421 | - $result[] = $champ; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if (isset($args[0]) && $args[0] == ',') { |
|
| 425 | - $args = ltrim(substr($args, 1)); |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - if ($collecte) { |
|
| 433 | - $res[] = $collecte; |
|
| 434 | - $collecte = []; |
|
| 435 | - } |
|
| 436 | - $texte = substr($args, 1); |
|
| 437 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | - // propager les erreurs, et ignorer les param vides |
|
| 439 | - if ($pointeur_champ->param !== false) { |
|
| 440 | - if ($err_f) { |
|
| 441 | - $pointeur_champ->param = false; |
|
| 442 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | - $pointeur_champ->param[] = $res; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | - |
|
| 449 | - return $result; |
|
| 318 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | + $suite = ltrim($match[2]); |
|
| 320 | + $fonc = trim($match[1]); |
|
| 321 | + if ($fonc && $fonc[0] == '|') { |
|
| 322 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | + } |
|
| 324 | + $res = [$fonc]; |
|
| 325 | + $err_f = ''; |
|
| 326 | + // cas du filtre sans argument ou du critere / |
|
| 327 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | + if (!$match[1]) { |
|
| 330 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | + $texte = ''; |
|
| 333 | + } else { |
|
| 334 | + $texte = $suite; |
|
| 335 | + } |
|
| 336 | + if ($err_f) { |
|
| 337 | + $pointeur_champ->param = false; |
|
| 338 | + } elseif ($fonc !== '') { |
|
| 339 | + $pointeur_champ->param[] = $res; |
|
| 340 | + } |
|
| 341 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | + |
|
| 344 | + return $result; |
|
| 345 | + } |
|
| 346 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | + $collecte = []; |
|
| 348 | + while ($args && $args[0] != '}') { |
|
| 349 | + if ($args[0] == '"') { |
|
| 350 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | + } elseif ($args[0] == "'") { |
|
| 352 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | + } else { |
|
| 354 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | + if (!isset($regs[2]) || !strlen($regs[2])) { |
|
| 356 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | + $champ = new Texte(); |
|
| 359 | + $champ->apres = $champ->avant = $args = ''; |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + $arg = $regs[2]; |
|
| 364 | + if (trim($regs[1])) { |
|
| 365 | + $champ = new Texte(); |
|
| 366 | + $champ->texte = $arg; |
|
| 367 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | + $result[] = $champ; |
|
| 369 | + $collecte[] = $champ; |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + } else { |
|
| 372 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | + // 0 est un aveu d'impuissance. A completer |
|
| 374 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | + |
|
| 376 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | + $collecte = array_merge($collecte, $arg); |
|
| 378 | + $result = array_merge($result, $arg); |
|
| 379 | + } else { |
|
| 380 | + $n = strpos($args, (string) $r[0]); |
|
| 381 | + $pred = substr($args, 0, $n); |
|
| 382 | + $par = ',}'; |
|
| 383 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | + $pred = $m[1]; |
|
| 385 | + $par = ')'; |
|
| 386 | + } |
|
| 387 | + if ($pred) { |
|
| 388 | + $champ = new Texte(); |
|
| 389 | + $champ->texte = $pred; |
|
| 390 | + $champ->apres = $champ->avant = ''; |
|
| 391 | + $result[] = $champ; |
|
| 392 | + $collecte[] = $champ; |
|
| 393 | + } |
|
| 394 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | + $champ = new Champ(); |
|
| 396 | + $champ->nom_boucle = $r[2]; |
|
| 397 | + $champ->nom_champ = $r[3]; |
|
| 398 | + $champ->etoile = $r[5]; |
|
| 399 | + $next = $r[6]; |
|
| 400 | + while ($next == '{') { |
|
| 401 | + phraser_arg($rec, $sep, [], $champ); |
|
| 402 | + $args = ltrim($rec); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + while ($next == '|') { |
|
| 406 | + $pos_apres = 0; |
|
| 407 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | + $args = substr($rec, $pos_apres); |
|
| 409 | + $next = $args[0] ?? ''; |
|
| 410 | + } |
|
| 411 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | + if ($champ->param === false) { |
|
| 413 | + $err_f = true; |
|
| 414 | + } else { |
|
| 415 | + phraser_vieux($champ); |
|
| 416 | + } |
|
| 417 | + if ($par == ')') { |
|
| 418 | + $args = substr($args, 1); |
|
| 419 | + } |
|
| 420 | + $collecte[] = $champ; |
|
| 421 | + $result[] = $champ; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if (isset($args[0]) && $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($texte, (string) "%$sep")) !== false) { |
|
| 456 | - if (!preg_match(',^%' . preg_quote($sep, ',') . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - $debut = substr($texte, 0, $p); |
|
| 460 | - $texte = substr($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($texte, (string) "%$sep")) !== false) { |
|
| 456 | + if (!preg_match(',^%' . preg_quote($sep, ',') . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + $debut = substr($texte, 0, $p); |
|
| 460 | + $texte = substr($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, $texte, $match)) { |
|
| 479 | - $p = strpos($texte, (string) $match[0]); |
|
| 480 | - $debut = substr($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($texte, 0, strpos($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($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, $texte, $match)) { |
|
| 479 | + $p = strpos($texte, (string) $match[0]); |
|
| 480 | + $debut = substr($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($texte, 0, strpos($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($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]+,', $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]+,', $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', $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', $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', $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($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,", $param) |
|
| 683 | - && preg_match(',^id_\w+\s*$,', $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 *,', $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-]+) *(/) *(.+) *$,', $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', $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', $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 *,', $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', $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', $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', $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($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,", $param) |
|
| 683 | + && preg_match(',^id_\w+\s*$,', $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 *,', $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-]+) *(/) *(.+) *$,', $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', $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', $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 *,', $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($texte, "\n", $debut); |
|
| 801 | - } |
|
| 802 | - else { |
|
| 803 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 804 | - } |
|
| 799 | + if (is_null($fin)) { |
|
| 800 | + return substr_count($texte, "\n", $debut); |
|
| 801 | + } |
|
| 802 | + else { |
|
| 803 | + return substr_count($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($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 825 | - $current_pos = $pos_boucle + 1; |
|
| 826 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 827 | - |
|
| 828 | - $id_boucle = ''; |
|
| 829 | - if ($pos_parent !== false) { |
|
| 830 | - $id_boucle = trim(substr($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($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($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($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($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($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 825 | + $current_pos = $pos_boucle + 1; |
|
| 826 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 827 | + |
|
| 828 | + $id_boucle = ''; |
|
| 829 | + if ($pos_parent !== false) { |
|
| 830 | + $id_boucle = trim(substr($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($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($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($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($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($id_boucle)) { |
|
| 928 | - $pos_anonyme_next = strpos($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($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($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($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($id_boucle)) { |
|
| 928 | + $pos_anonyme_next = strpos($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($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($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($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($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($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($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($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, $texte, $match, 0, $pos_milieu) |
|
| 1075 | - || ($pos_match = strpos($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($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($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($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($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($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($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($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($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($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($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($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($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($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, $texte, $match, 0, $pos_milieu) |
|
| 1075 | + || ($pos_match = strpos($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($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($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($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($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($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($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($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($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($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1270 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1271 | + |
|
| 1272 | + // phraser la partie avant le debut de la boucle |
|
| 1273 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1274 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1275 | + |
|
| 1276 | + $ligne_debut_texte = $ligne_suite; |
|
| 1277 | + $pos_debut_texte = $pos_courante; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1281 | 1281 | } |
@@ -55,19 +55,19 @@ discard block |
||
| 55 | 55 | * Nom d'une balise #TOTO |
| 56 | 56 | * |
| 57 | 57 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 58 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 58 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 59 | 59 | /** Balise complète [...(#TOTO) ... ] */ |
| 60 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 60 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 61 | 61 | |
| 62 | 62 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 63 | 63 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 64 | 64 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 65 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 65 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 66 | 66 | |
| 67 | 67 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 68 | 68 | define('SQL_ARGS', '(\([^)]*\))'); |
| 69 | 69 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 70 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 70 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 71 | 71 | |
| 72 | 72 | function phraser_inclure($texte, $ligne, $result) { |
| 73 | 73 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @return array |
| 223 | 223 | **/ |
| 224 | 224 | function phraser_champs($texte, $ligne, $result) { |
| 225 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 225 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 226 | 226 | $p = strpos($texte, (string) $match[0]); |
| 227 | 227 | // texte après la balise |
| 228 | 228 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | $collecte[] = $champ; |
| 370 | 370 | $args = ltrim($regs[count($regs) - 1]); |
| 371 | 371 | } else { |
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 372 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 373 | 373 | // 0 est un aveu d'impuissance. A completer |
| 374 | 374 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 375 | 375 | |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 454 | 454 | $res = []; |
| 455 | 455 | while (($p = strpos($texte, (string) "%$sep")) !== false) { |
| 456 | - if (!preg_match(',^%' . preg_quote($sep, ',') . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 456 | + if (!preg_match(',^%'.preg_quote($sep, ',').'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 457 | 457 | break; |
| 458 | 458 | } |
| 459 | 459 | $debut = substr($texte, 0, $p); |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | $pos_apres = 0; |
| 494 | 494 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 495 | 495 | phraser_vieux($champ); |
| 496 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 496 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 497 | 497 | $debut = substr($match[7], $pos_apres + 1); |
| 498 | 498 | if (!empty($debut)) { |
| 499 | 499 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 624 | 624 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 625 | 625 | $c = null; |
| 626 | - eval('$c = ' . $m[4] . ';'); |
|
| 626 | + eval('$c = '.$m[4].';'); |
|
| 627 | 627 | if (isset($c)) { |
| 628 | 628 | $m[4] = $c; |
| 629 | 629 | } |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 704 | 704 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 705 | 705 | } elseif ( |
| 706 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 706 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 707 | 707 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 708 | 708 | ) { |
| 709 | 709 | $a2 = trim($m[8]); |
@@ -720,8 +720,8 @@ discard block |
||
| 720 | 720 | ); |
| 721 | 721 | $crit->exclus = $m[1]; |
| 722 | 722 | } elseif ( |
| 723 | - preg_match('/^([!]?)\s*(' . |
|
| 724 | - CHAMP_SQL_PLUS_FONC . |
|
| 723 | + preg_match('/^([!]?)\s*('. |
|
| 724 | + CHAMP_SQL_PLUS_FONC. |
|
| 725 | 725 | ')\s*(\??)(.*)$/is', $param, $m) |
| 726 | 726 | ) { |
| 727 | 727 | // contient aussi les comparaisons implicites ! |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 869 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 869 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 870 | 870 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 871 | 871 | if ( |
| 872 | 872 | $pos_precond !== false |
@@ -877,7 +877,7 @@ discard block |
||
| 877 | 877 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 880 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 881 | 881 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 882 | 882 | if ( |
| 883 | 883 | $pos_preaff !== false |
@@ -925,13 +925,13 @@ discard block |
||
| 925 | 925 | $pos_anonyme_next = null; |
| 926 | 926 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 927 | 927 | if (!strlen($id_boucle)) { |
| 928 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 928 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | // |
| 932 | 932 | // 1. Recuperer la partie conditionnelle apres |
| 933 | 933 | // |
| 934 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 934 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 935 | 935 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 936 | 936 | if ( |
| 937 | 937 | $pos_apres !== false |
@@ -940,13 +940,13 @@ discard block |
||
| 940 | 940 | $boucle['pos_postcond'] = $pos_apres; |
| 941 | 941 | $pos_apres += strlen($apres_boucle); |
| 942 | 942 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 943 | - $pos_courante = $pos_apres ; |
|
| 943 | + $pos_courante = $pos_apres; |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | // |
| 947 | 947 | // 2. Récuperer la partie alternative apres |
| 948 | 948 | // |
| 949 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 949 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 950 | 950 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 951 | 951 | if ( |
| 952 | 952 | $pos_altern !== false |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | // |
| 962 | 962 | // 3. Recuperer la partie footer non alternative |
| 963 | 963 | // |
| 964 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 964 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 965 | 965 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 966 | 966 | if ( |
| 967 | 967 | $pos_postaff !== false |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | $boucle['pos_postaff'] = $pos_postaff; |
| 971 | 971 | $pos_postaff += strlen($postaff_boucle); |
| 972 | 972 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 973 | - $pos_courante = $pos_postaff ; |
|
| 973 | + $pos_courante = $pos_postaff; |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | return $boucle; |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | * @return string |
| 1011 | 1011 | */ |
| 1012 | 1012 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1013 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1013 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1014 | 1014 | //memoriser la boucle a reinjecter |
| 1015 | 1015 | $id_boucle = "$id_boucle"; |
| 1016 | 1016 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1024 | 1024 | if (is_null($boucle_placeholder)) { |
| 1025 | 1025 | do { |
| 1026 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1026 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1027 | 1027 | } while (str_contains($texte, $boucle_placeholder)); |
| 1028 | 1028 | } |
| 1029 | 1029 | |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | |
| 1044 | 1044 | // boucle anonyme ? |
| 1045 | 1045 | if (!strlen($id_boucle)) { |
| 1046 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1046 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | $pos_debut_boucle = $pos_courante; |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | |
| 1057 | 1057 | $pos_avant = $boucle['pos_precond_inside']; |
| 1058 | 1058 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1059 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1059 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | |
| 1066 | 1066 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1067 | 1067 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1068 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1068 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | $result->id_boucle = $id_boucle; |
@@ -1122,7 +1122,7 @@ discard block |
||
| 1122 | 1122 | } else { |
| 1123 | 1123 | $pos_milieu += 1; |
| 1124 | 1124 | |
| 1125 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1125 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1126 | 1126 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1127 | 1127 | if ($pos_fin === false) { |
| 1128 | 1128 | $err_b = [ |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | else { |
| 1136 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1137 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1138 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1138 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1139 | 1139 | $search_from = $pos_milieu; |
| 1140 | 1140 | $nb_open = 1; |
| 1141 | 1141 | $nb_close = 1; |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | if ($boucle['pos_postcond']) { |
| 1176 | 1176 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1177 | 1177 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1178 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1178 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | |
@@ -798,8 +798,7 @@ discard block |
||
| 798 | 798 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 799 | 799 | if (is_null($fin)) { |
| 800 | 800 | return substr_count($texte, "\n", $debut); |
| 801 | - } |
|
| 802 | - else { |
|
| 801 | + } else { |
|
| 803 | 802 | return substr_count($texte, "\n", $debut, $fin - $debut); |
| 804 | 803 | } |
| 805 | 804 | } |
@@ -846,8 +845,7 @@ discard block |
||
| 846 | 845 | erreur_squelette($err_b, $result); |
| 847 | 846 | |
| 848 | 847 | continue; |
| 849 | - } |
|
| 850 | - else { |
|
| 848 | + } else { |
|
| 851 | 849 | $boucle = [ |
| 852 | 850 | 'id_boucle' => $id_boucle, |
| 853 | 851 | 'id_boucle_err' => $id_boucle, |
@@ -987,8 +985,7 @@ discard block |
||
| 987 | 985 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 988 | 986 | if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) { |
| 989 | 987 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 990 | - } |
|
| 991 | - else { |
|
| 988 | + } else { |
|
| 992 | 989 | if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) { |
| 993 | 990 | $placeholder = $champ->nom_champ; |
| 994 | 991 | $id = reset($champ->param[0][1]); |
@@ -1131,8 +1128,7 @@ discard block |
||
| 1131 | 1128 | ]; |
| 1132 | 1129 | erreur_squelette($err_b, $result); |
| 1133 | 1130 | $pos_courante += strlen($fin_boucle); |
| 1134 | - } |
|
| 1135 | - else { |
|
| 1131 | + } else { |
|
| 1136 | 1132 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1137 | 1133 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1138 | 1134 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
@@ -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(' ', $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', $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(' ', $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', $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\$/", $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\$/", $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 />', $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($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 />', $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($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 | } |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | function chrono_requete($temps) { |
| 109 | 109 | $total = 0; |
| 110 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 110 | + $hors = '<i>'._T('zbug_hors_compilation').'</i>'; |
|
| 111 | 111 | $t = $q = $n = $d = []; |
| 112 | 112 | // Totaliser les temps et completer le Explain |
| 113 | 113 | foreach ($temps as $key => $v) { |
| 114 | 114 | [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
| 115 | 115 | if (is_array($contexte)) { |
| 116 | - $k = ($contexte[0] . " $boucle"); |
|
| 116 | + $k = ($contexte[0]." $boucle"); |
|
| 117 | 117 | include_spip('public/compiler'); |
| 118 | 118 | $env = reconstruire_contexte_compil($contexte); |
| 119 | 119 | } else { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | // Fabriquer les liens de navigations dans le tableau des temps |
| 159 | 159 | foreach ($temps as $k => $v) { |
| 160 | 160 | $titre = strip_tags($v[2]); |
| 161 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 161 | + $href = quote_amp($GLOBALS['REQUEST_URI'])."#req$i"; |
|
| 162 | 162 | $href = str_replace("\\'", ''', $href); |
| 163 | 163 | |
| 164 | 164 | if (!isset($t[$v[2]])) { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | unset($d['']); |
| 180 | 180 | // Fabriquer le tableau des liens de navigation dans le grand tableau |
| 181 | 181 | foreach ($d as $k => $v) { |
| 182 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 182 | + $d[$k] = $n[$k]."</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | 183 | . implode('', $t[$k]); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | . implode("</td></tr>\n<tr><td>", $d) |
| 190 | 190 | . "</td></tr>\n" |
| 191 | 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>')) |
|
| 192 | + ('<tr><td>'.(is_countable($temps) ? count($temps) : 0).'</td><td>'._T('info_total').'</td><td class="time">'.$total.'</td><td></td></tr>')) |
|
| 193 | 193 | ]; |
| 194 | 194 | |
| 195 | 195 | return [$temps, $navigation]; |
@@ -18,15 +18,13 @@ discard block |
||
| 18 | 18 | if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
| 19 | 19 | if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
| 20 | 20 | $trace = true; |
| 21 | - } |
|
| 22 | - else { |
|
| 21 | + } else { |
|
| 23 | 22 | if (empty($GLOBALS['visiteur_session'])) { |
| 24 | 23 | // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
| 25 | 24 | // car ici on ne sait pas si c'est un hit anonyme |
| 26 | 25 | // ou une requete SQL faite avant chargement de la session |
| 27 | 26 | $trace = (empty($_GET['var_profile']) ? false : '?'); |
| 28 | - } |
|
| 29 | - else { |
|
| 27 | + } else { |
|
| 30 | 28 | include_spip('inc/autoriser'); |
| 31 | 29 | // gare au bouclage sur calcul de droits au premier appel |
| 32 | 30 | // A fortiori quand on demande une trace |
@@ -47,8 +45,7 @@ discard block |
||
| 47 | 45 | // car ici on ne sait pas si c'est un hit anonyme |
| 48 | 46 | // ou une requete SQL faite avant chargement de la session |
| 49 | 47 | $trace = (empty($_GET['var_profile']) ? false : '?'); |
| 50 | - } |
|
| 51 | - else { |
|
| 48 | + } else { |
|
| 52 | 49 | include_spip('inc/autoriser'); |
| 53 | 50 | // gare au bouclage sur calcul de droits au premier appel |
| 54 | 51 | // A fortiori quand on demande une trace |
@@ -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 | - _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($fond, $prefix_path, $prefix_length) == 0) { |
|
| 67 | - $fond = substr($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(',', 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(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(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($z_contenu) + 1) == 0) { |
|
| 124 | - $type = substr($fond, strlen($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($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($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($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($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 | + _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($fond, $prefix_path, $prefix_length) == 0) { |
|
| 67 | + $fond = substr($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(',', 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(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(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($z_contenu) + 1) == 0) { |
|
| 124 | + $type = substr($fond, strlen($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($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($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($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($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($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($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($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($primary) . ',env}>'; |
|
| 382 | + } // page objets |
|
| 383 | + elseif (($type = $desc_exec) && !str_contains($type, '/')) { |
|
| 384 | + $dir = z_blocs(test_espace_prive()); |
|
| 385 | + $dir = reset($dir); |
|
| 386 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 387 | + } |
|
| 388 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 389 | + // et objet et tire de $table |
|
| 390 | + elseif ($fond = $desc_exec) { |
|
| 391 | + $dir = md5(dirname($fond)); |
|
| 392 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 396 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 397 | + $f = $base_dir . "$exec"; |
|
| 398 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 399 | + |
|
| 400 | + return $f; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -406,17 +406,17 @@ discard block |
||
| 406 | 406 | * @return bool|string |
| 407 | 407 | */ |
| 408 | 408 | function z_sanitize_var_zajax() { |
| 409 | - $z_ajax = _request('var_zajax'); |
|
| 410 | - if (!$z_ajax) { |
|
| 411 | - return false; |
|
| 412 | - } |
|
| 413 | - if ( |
|
| 414 | - !($z_blocs = z_blocs(test_espace_prive())) |
|
| 415 | - || !in_array($z_ajax, $z_blocs) |
|
| 416 | - ) { |
|
| 417 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 418 | - $z_ajax = false; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $z_ajax; |
|
| 409 | + $z_ajax = _request('var_zajax'); |
|
| 410 | + if (!$z_ajax) { |
|
| 411 | + return false; |
|
| 412 | + } |
|
| 413 | + if ( |
|
| 414 | + !($z_blocs = z_blocs(test_espace_prive())) |
|
| 415 | + || !in_array($z_ajax, $z_blocs) |
|
| 416 | + ) { |
|
| 417 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 418 | + $z_ajax = false; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $z_ajax; |
|
| 422 | 422 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 53 | 53 | $page = _SPIP_PAGE; |
| 54 | 54 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 55 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 55 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim( |
|
| 56 | 56 | _DIR_PLUGIN_DIST, |
| 57 | 57 | '/' |
| 58 | 58 | ) : '')); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | && in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 77 | 77 | && defined($apl_constant) |
| 78 | 78 | && in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
| 79 | - && ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 79 | + && ($pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL |
|
| 80 | 80 | ) { |
| 81 | 81 | $flux['data'] = $pipe; |
| 82 | 82 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $echafauder = ''; |
| 90 | 90 | } |
| 91 | 91 | if ($prepend) { |
| 92 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 92 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | 93 | if ($squelette) { |
| 94 | 94 | $flux['data'] = $squelette; |
| 95 | 95 | } |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | // se brancher sur contenu/xx si il existe |
| 110 | 110 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 111 | 111 | if (!isset($disponible[$fond])) { |
| 112 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 112 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | if ($disponible[$fond]) { |
| 116 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 116 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $type = $flux['args']['contexte'][$page]; |
| 127 | 127 | } |
| 128 | 128 | if (!isset($disponible[$type])) { |
| 129 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 129 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 130 | 130 | } |
| 131 | 131 | if (is_string($disponible[$type])) { |
| 132 | 132 | $flux['data'] = $disponible[$type]; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 142 | 142 | } else { |
| 143 | 143 | $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
| 144 | - $prefix_path . $prepend, |
|
| 144 | + $prefix_path.$prepend, |
|
| 145 | 145 | $z_contenu, |
| 146 | 146 | '404', |
| 147 | 147 | $ext, |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | $type = $flux['args']['contexte'][$page]; |
| 166 | 166 | } |
| 167 | 167 | if ($type !== 'page' && !isset($disponible[$type])) { |
| 168 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 168 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 169 | 169 | } |
| 170 | 170 | if ($type == 'page' || $disponible[$type]) { |
| 171 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 171 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | if ( |
| 184 | 184 | isset($flux['args']['contexte']['type-page']) |
| 185 | 185 | && ( |
| 186 | - isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext") |
|
| 187 | - || file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 186 | + isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext") |
|
| 187 | + || file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext") |
|
| 188 | 188 | ) |
| 189 | 189 | ) { |
| 190 | 190 | $flux['data'] = $f; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | } elseif ( |
| 193 | 193 | $fond == 'structure' |
| 194 | 194 | && z_sanitize_var_zajax() |
| 195 | - && ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")) |
|
| 195 | + && ($f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")) |
|
| 196 | 196 | ) { |
| 197 | 197 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 198 | 198 | } // chercher le fond correspondant a la composition |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | && ($dir = explode('/', $dir)) |
| 204 | 204 | && ($dir = reset($dir)) |
| 205 | 205 | && in_array($dir, $z_blocs) |
| 206 | - && ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")) |
|
| 206 | + && ($f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext")) |
|
| 207 | 207 | ) { |
| 208 | 208 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 209 | 209 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * `true` si on peut l'utiliser, `false` sinon. |
| 264 | 264 | **/ |
| 265 | 265 | function z_fond_valide($squelette) { |
| 266 | - return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette); |
|
| 266 | + return !_ZCORE_EXCLURE_PATH || !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -378,23 +378,23 @@ discard block |
||
| 378 | 378 | } |
| 379 | 379 | $dir = z_blocs(test_espace_prive()); |
| 380 | 380 | $dir = reset($dir); |
| 381 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 381 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper($primary).',env}>'; |
|
| 382 | 382 | } // page objets |
| 383 | 383 | elseif (($type = $desc_exec) && !str_contains($type, '/')) { |
| 384 | 384 | $dir = z_blocs(test_espace_prive()); |
| 385 | 385 | $dir = reset($dir); |
| 386 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 386 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />'; |
|
| 387 | 387 | } |
| 388 | 388 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 389 | 389 | // et objet et tire de $table |
| 390 | 390 | elseif ($fond = $desc_exec) { |
| 391 | 391 | $dir = md5(dirname($fond)); |
| 392 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 392 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />'; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
| 396 | 396 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 397 | - $f = $base_dir . "$exec"; |
|
| 397 | + $f = $base_dir."$exec"; |
|
| 398 | 398 | ecrire_fichier("$f.$ext", $scaffold); |
| 399 | 399 | |
| 400 | 400 | return $f; |
@@ -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($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($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($args, '(#')); |
|
| 66 | + $s = ($avant || $apres || $filtres || str_contains($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($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($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($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($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($texte2), '|') |
|
| 120 | - || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', $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($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($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($texte2), '|') |
|
| 120 | + || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', $texte2) |
|
| 121 | + ) { |
|
| 122 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function format_texte_html($texte) { |
| 131 | - return $texte; |
|
| 131 | + return $texte; |
|
| 132 | 132 | } |
@@ -26,36 +26,36 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | 28 | if (!str_contains($file, '#')) { |
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 29 | + $t = $file ? ('('.$file.')') : ''; |
|
| 30 | 30 | } else { |
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 31 | + $t = '{fond='.$file.'}'; |
|
| 32 | 32 | } |
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 33 | + $args = $args ? '{'.implode(', ', $args).'}' : (''); |
|
| 34 | 34 | |
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 35 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | 39 | $contenu = []; |
| 40 | 40 | foreach ($args as $l => $t) { |
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>'.implode(' ', $contenu).'</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | 48 | foreach ($args as $k => $v) { |
| 49 | 49 | $args[$k] = "$k=$v"; |
| 50 | 50 | } |
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 51 | + $args = ($args ? '{'.implode(',', $args).'}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | 57 | $nom = '#' |
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 58 | + . ($boucle ? ($boucle.':') : '') |
|
| 59 | 59 | . $nom |
| 60 | 60 | . $etoile |
| 61 | 61 | . $args |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | $critere[$k] = $crit_s; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 87 | + return ($critere ? '{'.implode(',', $critere).'}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | 91 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 92 | + . ($args ? '{'.implode(',', $args).'}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | // si un texte se termine par ( et est suivi d'un champ |
| 107 | 107 | // ou assimiles, forcer la notation pleine |
| 108 | 108 | if ($c1 == '(' && str_starts_with($texte2, '#')) { |
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 109 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 110 | 110 | } |
| 111 | 111 | } else { |
| 112 | 112 | if ($type == 'texte') { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $c1 == '}' && str_starts_with(ltrim($texte2), '|') |
| 120 | 120 | || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', $texte2) |
| 121 | 121 | ) { |
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 122 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_fichiers_fonctions(); |
@@ -29,177 +29,177 @@ discard block |
||
| 29 | 29 | # En cas d'erreur process_ins est absent et texte est un tableau de 2 chaines |
| 30 | 30 | |
| 31 | 31 | function public_parametrer_dist($fond, $contexte = '', $cache = '', string $connect = '') { |
| 32 | - static $composer, $styliser, $notes = null; |
|
| 33 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 34 | - if ($page) { |
|
| 35 | - return $page; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (isset($contexte['lang'])) { |
|
| 39 | - $lang = $contexte['lang']; |
|
| 40 | - } elseif (!isset($lang)) { |
|
| 41 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $select = ((!isset($GLOBALS['forcer_lang']) || !$GLOBALS['forcer_lang']) && $lang != $GLOBALS['spip_lang']); |
|
| 45 | - if ($select) { |
|
| 46 | - $select = lang_select($lang); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 50 | - |
|
| 51 | - if (!$styliser) { |
|
| 52 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 53 | - } |
|
| 54 | - [$skel, $mime_type, $gram, $sourcefile] = |
|
| 55 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 56 | - |
|
| 57 | - if ($skel) { |
|
| 58 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 59 | - // (recursion possible a cause des modeles) |
|
| 60 | - if ($debug) { |
|
| 61 | - $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 62 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // charger le squelette en specifiant les langages cibles et source |
|
| 66 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 67 | - |
|
| 68 | - if (!$composer) { |
|
| 69 | - $composer = charger_fonction('composer', 'public'); |
|
| 70 | - } |
|
| 71 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 72 | - } else { |
|
| 73 | - $fonc = ''; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 77 | - $page = $fonc; |
|
| 78 | - } else { |
|
| 79 | - // Preparer l'appel de la fonction principale du squelette |
|
| 80 | - |
|
| 81 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 82 | - |
|
| 83 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 84 | - // et on enregistre l'etat courant des globales de notes... |
|
| 85 | - if (is_null($notes)) { |
|
| 86 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 87 | - } |
|
| 88 | - if ($notes) { |
|
| 89 | - $notes('', 'empiler'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Rajouter d'office ces deux parametres |
|
| 93 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 94 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 95 | - if (!isset($contexte['date'])) { |
|
| 96 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 97 | - $contexte['date_default'] = true; |
|
| 98 | - } else { |
|
| 99 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (!isset($contexte['date_redac'])) { |
|
| 103 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 104 | - $contexte['date_redac_default'] = true; |
|
| 105 | - } else { |
|
| 106 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 110 | - try { |
|
| 111 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 112 | - } catch (Throwable $e) { |
|
| 113 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 116 | - $corps = "<pre>$msg</pre>"; |
|
| 117 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 118 | - erreur_squelette($full_msg); |
|
| 119 | - unset($msg, $full_msg, $corps); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 123 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 124 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 125 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 126 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 127 | - if ($notes) { |
|
| 128 | - $notes('', 'depiler'); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // reinjecter en dynamique la pile des notes |
|
| 132 | - // si il y a des inclure dynamiques |
|
| 133 | - // si la pile n'est pas vide |
|
| 134 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 135 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 136 | - if ($notes) { |
|
| 137 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // spip_log: un joli contexte |
|
| 141 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 142 | - |
|
| 143 | - $profile = spip_timer($a); |
|
| 144 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 145 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 146 | - |
|
| 147 | - if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
|
| 148 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 149 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($debug) { |
|
| 153 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 155 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | - if ( |
|
| 159 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 160 | - && _request('var_mode_objet') == $fonc |
|
| 161 | - && _request('var_mode_affiche') == 'resultat' |
|
| 162 | - ) { |
|
| 163 | - erreur_squelette(); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 167 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 168 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 169 | - // si aucun #CACHE{} spécifié |
|
| 170 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 171 | - // entre public et prive |
|
| 172 | - if (test_espace_prive() || str_starts_with($fond, 'modeles/')) { |
|
| 173 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 174 | - } else { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $page['contexte'] = $contexte; |
|
| 180 | - |
|
| 181 | - // faire remonter le fichier source |
|
| 182 | - static $js_inclus = false; |
|
| 183 | - if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
|
| 184 | - $page['sourcefile'] = $sourcefile; |
|
| 185 | - $page['texte'] = |
|
| 186 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 187 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 188 | - $js_inclus = true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 192 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 193 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 194 | - unset($GLOBALS['cache_utilise_session']); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($select) { |
|
| 199 | - lang_select(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $page; |
|
| 32 | + static $composer, $styliser, $notes = null; |
|
| 33 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 34 | + if ($page) { |
|
| 35 | + return $page; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (isset($contexte['lang'])) { |
|
| 39 | + $lang = $contexte['lang']; |
|
| 40 | + } elseif (!isset($lang)) { |
|
| 41 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $select = ((!isset($GLOBALS['forcer_lang']) || !$GLOBALS['forcer_lang']) && $lang != $GLOBALS['spip_lang']); |
|
| 45 | + if ($select) { |
|
| 46 | + $select = lang_select($lang); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 50 | + |
|
| 51 | + if (!$styliser) { |
|
| 52 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 53 | + } |
|
| 54 | + [$skel, $mime_type, $gram, $sourcefile] = |
|
| 55 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 56 | + |
|
| 57 | + if ($skel) { |
|
| 58 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 59 | + // (recursion possible a cause des modeles) |
|
| 60 | + if ($debug) { |
|
| 61 | + $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 62 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // charger le squelette en specifiant les langages cibles et source |
|
| 66 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 67 | + |
|
| 68 | + if (!$composer) { |
|
| 69 | + $composer = charger_fonction('composer', 'public'); |
|
| 70 | + } |
|
| 71 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 72 | + } else { |
|
| 73 | + $fonc = ''; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 77 | + $page = $fonc; |
|
| 78 | + } else { |
|
| 79 | + // Preparer l'appel de la fonction principale du squelette |
|
| 80 | + |
|
| 81 | + spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 82 | + |
|
| 83 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 84 | + // et on enregistre l'etat courant des globales de notes... |
|
| 85 | + if (is_null($notes)) { |
|
| 86 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 87 | + } |
|
| 88 | + if ($notes) { |
|
| 89 | + $notes('', 'empiler'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Rajouter d'office ces deux parametres |
|
| 93 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 94 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 95 | + if (!isset($contexte['date'])) { |
|
| 96 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 97 | + $contexte['date_default'] = true; |
|
| 98 | + } else { |
|
| 99 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (!isset($contexte['date_redac'])) { |
|
| 103 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 104 | + $contexte['date_redac_default'] = true; |
|
| 105 | + } else { |
|
| 106 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 110 | + try { |
|
| 111 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 112 | + } catch (Throwable $e) { |
|
| 113 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 116 | + $corps = "<pre>$msg</pre>"; |
|
| 117 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 118 | + erreur_squelette($full_msg); |
|
| 119 | + unset($msg, $full_msg, $corps); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 123 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 124 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 125 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 126 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 127 | + if ($notes) { |
|
| 128 | + $notes('', 'depiler'); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // reinjecter en dynamique la pile des notes |
|
| 132 | + // si il y a des inclure dynamiques |
|
| 133 | + // si la pile n'est pas vide |
|
| 134 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 135 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 136 | + if ($notes) { |
|
| 137 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // spip_log: un joli contexte |
|
| 141 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 142 | + |
|
| 143 | + $profile = spip_timer($a); |
|
| 144 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 145 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 146 | + |
|
| 147 | + if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
|
| 148 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 149 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($debug) { |
|
| 153 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 155 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | + if ( |
|
| 159 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 160 | + && _request('var_mode_objet') == $fonc |
|
| 161 | + && _request('var_mode_affiche') == 'resultat' |
|
| 162 | + ) { |
|
| 163 | + erreur_squelette(); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 167 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 168 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 169 | + // si aucun #CACHE{} spécifié |
|
| 170 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 171 | + // entre public et prive |
|
| 172 | + if (test_espace_prive() || str_starts_with($fond, 'modeles/')) { |
|
| 173 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 174 | + } else { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $page['contexte'] = $contexte; |
|
| 180 | + |
|
| 181 | + // faire remonter le fichier source |
|
| 182 | + static $js_inclus = false; |
|
| 183 | + if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
|
| 184 | + $page['sourcefile'] = $sourcefile; |
|
| 185 | + $page['texte'] = |
|
| 186 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 187 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 188 | + $js_inclus = true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 192 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 193 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 194 | + unset($GLOBALS['cache_utilise_session']); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($select) { |
|
| 199 | + lang_select(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $page; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -208,37 +208,37 @@ discard block |
||
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | 210 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 211 | - $infos = []; |
|
| 212 | - $line = 0; |
|
| 213 | - foreach ($contexte as $var => $val) { |
|
| 214 | - $line++; |
|
| 215 | - if ($max_lines && $max_lines < $line) { |
|
| 216 | - $infos[] = '…'; |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - if ($val === null) { |
|
| 220 | - $val = ''; |
|
| 221 | - } elseif (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = $val::class; |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr($val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } elseif (!strlen($val)) { |
|
| 237 | - $val = "''"; |
|
| 238 | - } |
|
| 239 | - $infos[] = $var . '=' . $val; |
|
| 240 | - } |
|
| 241 | - return implode(', ', $infos); |
|
| 211 | + $infos = []; |
|
| 212 | + $line = 0; |
|
| 213 | + foreach ($contexte as $var => $val) { |
|
| 214 | + $line++; |
|
| 215 | + if ($max_lines && $max_lines < $line) { |
|
| 216 | + $infos[] = '…'; |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + if ($val === null) { |
|
| 220 | + $val = ''; |
|
| 221 | + } elseif (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = $val::class; |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr($val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } elseif (!strlen($val)) { |
|
| 237 | + $val = "''"; |
|
| 238 | + } |
|
| 239 | + $infos[] = $var . '=' . $val; |
|
| 240 | + } |
|
| 241 | + return implode(', ', $infos); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | * @return array|bool |
| 256 | 256 | */ |
| 257 | 257 | function tester_redirection($fond, $contexte, $connect) { |
| 258 | - static $tester_redirection = null; |
|
| 259 | - if (is_null($tester_redirection)) { |
|
| 260 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 261 | - } |
|
| 262 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 258 | + static $tester_redirection = null; |
|
| 259 | + if (is_null($tester_redirection)) { |
|
| 260 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 261 | + } |
|
| 262 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -275,42 +275,42 @@ discard block |
||
| 275 | 275 | * @return array|bool |
| 276 | 276 | */ |
| 277 | 277 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 278 | - if ( |
|
| 279 | - $fond == 'article' |
|
| 280 | - && !empty($contexte['id_article']) |
|
| 281 | - && ($id_article = (int) $contexte['id_article']) |
|
| 282 | - ) { |
|
| 283 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 284 | - $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 285 | - if (strlen($m)) { |
|
| 286 | - include_spip('inc/texte'); |
|
| 287 | - // les navigateurs pataugent si l'URL est vide |
|
| 288 | - if ($url = virtuel_redirige($m, true)) { |
|
| 289 | - // passer en url absolue car cette redirection pourra |
|
| 290 | - // etre utilisee dans un contexte d'url qui change |
|
| 291 | - // y compris url arbo |
|
| 292 | - $status = 302; |
|
| 293 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 294 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 295 | - } |
|
| 296 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 297 | - include_spip('inc/filtres_mini'); |
|
| 298 | - $url = url_absolue($url); |
|
| 299 | - } |
|
| 300 | - $url = str_replace('&', '&', $url); |
|
| 301 | - |
|
| 302 | - return [ |
|
| 303 | - 'texte' => '<' |
|
| 304 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 305 | - . texte_script($url) |
|
| 306 | - . "','',$status);" |
|
| 307 | - . '?' . '>', |
|
| 308 | - 'process_ins' => 'php', |
|
| 309 | - 'status' => $status |
|
| 310 | - ]; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return false; |
|
| 278 | + if ( |
|
| 279 | + $fond == 'article' |
|
| 280 | + && !empty($contexte['id_article']) |
|
| 281 | + && ($id_article = (int) $contexte['id_article']) |
|
| 282 | + ) { |
|
| 283 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 284 | + $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 285 | + if (strlen($m)) { |
|
| 286 | + include_spip('inc/texte'); |
|
| 287 | + // les navigateurs pataugent si l'URL est vide |
|
| 288 | + if ($url = virtuel_redirige($m, true)) { |
|
| 289 | + // passer en url absolue car cette redirection pourra |
|
| 290 | + // etre utilisee dans un contexte d'url qui change |
|
| 291 | + // y compris url arbo |
|
| 292 | + $status = 302; |
|
| 293 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 294 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 295 | + } |
|
| 296 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 297 | + include_spip('inc/filtres_mini'); |
|
| 298 | + $url = url_absolue($url); |
|
| 299 | + } |
|
| 300 | + $url = str_replace('&', '&', $url); |
|
| 301 | + |
|
| 302 | + return [ |
|
| 303 | + 'texte' => '<' |
|
| 304 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 305 | + . texte_script($url) |
|
| 306 | + . "','',$status);" |
|
| 307 | + . '?' . '>', |
|
| 308 | + 'process_ins' => 'php', |
|
| 309 | + 'status' => $status |
|
| 310 | + ]; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return false; |
|
| 316 | 316 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } else { |
| 79 | 79 | // Preparer l'appel de la fonction principale du squelette |
| 80 | 80 | |
| 81 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 81 | + spip_timer($a = 'calcul page '.random_int(0, 1000)); |
|
| 82 | 82 | |
| 83 | 83 | // On cree un marqueur de notes unique lie a cette composition |
| 84 | 84 | // et on enregistre l'etat courant des globales de notes... |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | try { |
| 111 | 111 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 112 | 112 | } catch (Throwable $e) { |
| 113 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 114 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 113 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 114 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 115 | 115 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 116 | 116 | $corps = "<pre>$msg</pre>"; |
| 117 | 117 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -142,17 +142,17 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $profile = spip_timer($a); |
| 144 | 144 | spip_log("calcul ($profile) [$skel] $infos" |
| 145 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 145 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 146 | 146 | |
| 147 | 147 | if (defined('_CALCUL_PROFILER') && (int) $profile > _CALCUL_PROFILER) { |
| 148 | 148 | spip_log("calcul ($profile) [$skel] $infos" |
| 149 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 149 | + . ' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | if ($debug) { |
| 153 | 153 | // si c'est ce que demande le debusqueur, lui passer la main |
| 154 | 154 | $t = strlen($page['texte']) ? $page['texte'] : ' '; |
| 155 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 155 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 156 | 156 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 157 | 157 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 158 | 158 | if ( |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if (defined('_VAR_INCLURE') && _VAR_INCLURE) { |
| 184 | 184 | $page['sourcefile'] = $sourcefile; |
| 185 | 185 | $page['texte'] = |
| 186 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 186 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 187 | 187 | . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 188 | 188 | $js_inclus = true; |
| 189 | 189 | } |
@@ -220,14 +220,14 @@ discard block |
||
| 220 | 220 | $val = ''; |
| 221 | 221 | } elseif (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = $val::class; |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | } elseif (!strlen($val)) { |
| 237 | 237 | $val = "''"; |
| 238 | 238 | } |
| 239 | - $infos[] = $var . '=' . $val; |
|
| 239 | + $infos[] = $var.'='.$val; |
|
| 240 | 240 | } |
| 241 | 241 | return implode(', ', $infos); |
| 242 | 242 | } |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 305 | 305 | . texte_script($url) |
| 306 | 306 | . "','',$status);" |
| 307 | - . '?' . '>', |
|
| 307 | + . '?'.'>', |
|
| 308 | 308 | 'process_ins' => 'php', |
| 309 | 309 | 'status' => $status |
| 310 | 310 | ]; |
@@ -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("\\'", ''', 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("\\'", ''', 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', $msg, $regs)) { |
|
| 349 | - $errno = $regs[2]; |
|
| 350 | - } elseif ( |
|
| 351 | - is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | - && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', $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', $msg, $regs)) { |
|
| 349 | + $errno = $regs[2]; |
|
| 350 | + } elseif ( |
|
| 351 | + is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | + && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', $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', $v[0], $r)) { |
|
| 391 | - $y = substr_count($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($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($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', $v[0], $r)) { |
|
| 391 | + $y = substr_count($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($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($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?.\);/', $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' => '([^']*)'/", $script, $reg) |
|
| 431 | - && !preg_match("/'param' => '([^']*)'/", $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, $v)) { |
|
| 439 | - return $k; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return ''; |
|
| 423 | + preg_match('/include\(.(.*).php3?.\);/', $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' => '([^']*)'/", $script, $reg) |
|
| 431 | + && !preg_match("/'param' => '([^']*)'/", $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, $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($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($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($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($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($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($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', $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', $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+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 730 | - |
|
| 731 | - foreach ($boucles as $objet => $boucle) { |
|
| 732 | - if (str_starts_with($objet, $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+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 730 | + |
|
| 731 | + foreach ($boucles as $objet => $boucle) { |
|
| 732 | + if (str_starts_with($objet, $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($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', '', $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('/^([^_]+)_/', $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($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', '', $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('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 824 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 825 | + } elseif ($affiche == 'squelette') { |
|
| 826 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 827 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return [$legend, $res, $res2]; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | function debusquer_entete($titre, $corps) { |
| 834 | 834 | |
| 835 | - include_spip('balise/formulaire_admin'); |
|
| 836 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | - |
|
| 839 | - return _DOCTYPE_ECRIRE . |
|
| 840 | - html_lang_attributes() . |
|
| 841 | - "<head>\n<title>" . |
|
| 842 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | - ")</title>\n" . |
|
| 846 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | - "' />\n" . |
|
| 849 | - http_script('', 'jquery.js') |
|
| 850 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | - . "' type='text/css' />" . |
|
| 852 | - "</head>\n" . |
|
| 853 | - "<body style='margin:0 10px;'>\n" . |
|
| 854 | - "<div id='spip-debug-header'>" . |
|
| 855 | - $corps . |
|
| 856 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | - '</div></body></html>'; |
|
| 835 | + include_spip('balise/formulaire_admin'); |
|
| 836 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | + |
|
| 839 | + return _DOCTYPE_ECRIRE . |
|
| 840 | + html_lang_attributes() . |
|
| 841 | + "<head>\n<title>" . |
|
| 842 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | + _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | + ")</title>\n" . |
|
| 846 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | + "' />\n" . |
|
| 849 | + http_script('', 'jquery.js') |
|
| 850 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | + . "' type='text/css' />" . |
|
| 852 | + "</head>\n" . |
|
| 853 | + "<body style='margin:0 10px;'>\n" . |
|
| 854 | + "<div id='spip-debug-header'>" . |
|
| 855 | + $corps . |
|
| 856 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | + '</div></body></html>'; |
|
| 858 | 858 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | if (!$fonc) { |
| 147 | 147 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 148 | 148 | } |
| 149 | - $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 149 | + $titre = $mode ? $mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' '.$GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | 150 | } |
| 151 | 151 | if ($message === false) { |
| 152 | 152 | lang_select(); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $fond = $GLOBALS['fond'] ?? ''; |
| 170 | 170 | // une erreur critique sort $message en array |
| 171 | 171 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 172 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 172 | + spip_log('Debug: '.$debug.' ('.$fond.')'); |
|
| 173 | 173 | |
| 174 | 174 | return $msg; |
| 175 | 175 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | function debusquer_bandeau($erreurs) { |
| 178 | 178 | |
| 179 | 179 | if (!empty($erreurs)) { |
| 180 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 180 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0).' '._T('zbug_erreur_squelette')]; |
|
| 181 | 181 | |
| 182 | 182 | return debusquer_navigation($erreurs, $n); |
| 183 | 183 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | $valeur_simple = []; |
| 211 | 211 | foreach ($valeur as $v) { |
| 212 | 212 | if (is_array($v)) { |
| 213 | - $valeur_simple[] = 'array:' . count($v); |
|
| 213 | + $valeur_simple[] = 'array:'.count($v); |
|
| 214 | 214 | } elseif (is_object($v)) { |
| 215 | 215 | $valeur_simple[] = $v::class; |
| 216 | 216 | } elseif (is_string($v)) { |
| 217 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 217 | + $valeur_simple[] = "'".$v."'"; |
|
| 218 | 218 | } else { |
| 219 | 219 | $valeur_simple[] = $v; |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | $n = count($valeur); |
| 223 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | - $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 223 | + $valeur = (($n > 3) ? 'array:'.$n.' ' : ''); |
|
| 224 | + $valeur .= '['.implode(', ', $valeur_simple).']'; |
|
| 225 | 225 | } elseif (is_object($valeur)) { |
| 226 | 226 | $valeur = $valeur::class; |
| 227 | 227 | } elseif (is_string($valeur)) { |
| 228 | - $valeur = "'" . $valeur . "'"; |
|
| 228 | + $valeur = "'".$valeur."'"; |
|
| 229 | 229 | } |
| 230 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 230 | + $res .= "\n<tr><td><strong>".nl2br((string) entites_html($nom)) |
|
| 231 | + . '</strong></td><td>: '.nl2br((string) entites_html($valeur)) |
|
| 232 | 232 | . "</td></tr>\n"; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | if ($ligne) { |
| 254 | 254 | $msg .= " L$ligne"; |
| 255 | 255 | } |
| 256 | - spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 256 | + spip_log($msg, 'debusquer'._LOG_ERREUR); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | $nom_code = $lieu->descr['nom']; |
| 279 | 279 | $skel = $lieu->descr['sourcefile']; |
| 280 | 280 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 281 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 281 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 282 | 282 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 283 | 283 | if ($boucle) { |
| 284 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 284 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | 285 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 286 | 286 | } |
| 287 | 287 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | // Requete erronee |
| 373 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 373 | + $err = '<b>'._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 374 | 374 | . spip_htmlspecialchars($msg) |
| 375 | 375 | . "\n<br /><span style='color: red'><b>" |
| 376 | 376 | . spip_htmlspecialchars($query) |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 386 | 386 | |
| 387 | - $id = $nom . $boucle; |
|
| 387 | + $id = $nom.$boucle; |
|
| 388 | 388 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 389 | 389 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 390 | 390 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | ) { |
| 433 | 433 | $reg[1] = 'inconnu'; |
| 434 | 434 | } |
| 435 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 435 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 436 | 436 | |
| 437 | 437 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 438 | 438 | if (preg_match($incl, $v)) { |
@@ -448,16 +448,14 @@ discard block |
||
| 448 | 448 | |
| 449 | 449 | if (!$boucle) { |
| 450 | 450 | return $ligne |
| 451 | - ? ' (' . |
|
| 452 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | - _T('squelette_ligne')) . |
|
| 451 | + ? ' ('. |
|
| 452 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 454 | 453 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
| 455 | 454 | : ''; |
| 456 | 455 | } else { |
| 457 | 456 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 458 | 457 | |
| 459 | - return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | - " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 458 | + return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | 459 | } |
| 462 | 460 | } |
| 463 | 461 | |
@@ -479,14 +477,14 @@ discard block |
||
| 479 | 477 | |
| 480 | 478 | $s = preg_replace( |
| 481 | 479 | ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 482 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 480 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 483 | 481 | $s |
| 484 | 482 | ); |
| 485 | 483 | |
| 486 | 484 | |
| 487 | 485 | $tableau = explode('<br />', $s); |
| 488 | 486 | |
| 489 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 487 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: ".($nocpt ? 'hidden' : 'visible').";%s' href='#T%s' title=\"%s\">%0".(string) @strlen(count($tableau))."d</a></span> %s<br />\n"; |
|
| 490 | 488 | |
| 491 | 489 | $format10 = str_replace('white', 'lightgrey', $format); |
| 492 | 490 | $formaterr = 'color: red;'; |
@@ -530,7 +528,7 @@ discard block |
||
| 530 | 528 | . '" style="cursor: pointer;">' |
| 531 | 529 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 532 | 530 | . '</div> |
| 533 | - ' . $res . "</div>\n"; |
|
| 531 | + ' . $res."</div>\n"; |
|
| 534 | 532 | } |
| 535 | 533 | |
| 536 | 534 | // l'environnement graphique du debuggueur |
@@ -552,14 +550,14 @@ discard block |
||
| 552 | 550 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 553 | 551 | [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
| 554 | 552 | $texte .= $res2; |
| 555 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | - $legend = _T('zbug_' . $mode); |
|
| 557 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 553 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 554 | + $legend = _T('zbug_'.$mode); |
|
| 555 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 558 | 556 | $texte = ancre_texte($texte, ['', '']); |
| 559 | 557 | } |
| 560 | 558 | } else { |
| 561 | 559 | if (strlen(trim($res))) { |
| 562 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 560 | + return "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 563 | 561 | } else { |
| 564 | 562 | // cas de l'appel sur erreur: montre la page |
| 565 | 563 | return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
@@ -567,7 +565,7 @@ discard block |
||
| 567 | 565 | } |
| 568 | 566 | } else { |
| 569 | 567 | $valider = charger_fonction('valider', 'xml'); |
| 570 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 568 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 571 | 569 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 572 | 570 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 573 | 571 | [$texte, $err] = emboite_texte($val, $fonc, $self); |
@@ -578,14 +576,14 @@ discard block |
||
| 578 | 576 | } else { |
| 579 | 577 | $err = ": $err"; |
| 580 | 578 | } |
| 581 | - $legend = _T('validation') . ' ' . $err; |
|
| 579 | + $legend = _T('validation').' '.$err; |
|
| 582 | 580 | $res = $id = ''; |
| 583 | 581 | } |
| 584 | 582 | |
| 585 | 583 | return trim($texte) |
| 586 | - ? "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 584 | + ? "<img src='".chemin_image('debug-xx.svg')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 587 | 585 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 588 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 586 | + . "<a href='".$self.'#f_'.substr($fonc, 0, 37)."'> ↑ " |
|
| 589 | 587 | . ($legend ?: $mode) |
| 590 | 588 | . '</a></legend>' |
| 591 | 589 | . $texte |
@@ -597,7 +595,7 @@ discard block |
||
| 597 | 595 | |
| 598 | 596 | function emboite_texte($res, $fonc = '', $self = '') { |
| 599 | 597 | $errs = $res->err; |
| 600 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 598 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 601 | 599 | |
| 602 | 600 | if (!$texte && !$errs) { |
| 603 | 601 | return [ancre_texte('', ['', '']), false]; |
@@ -653,7 +651,7 @@ discard block |
||
| 653 | 651 | $err = "<h2 style='text-align: center'>" |
| 654 | 652 | . $i |
| 655 | 653 | . "<a href='#fin_err'>" |
| 656 | - . ' ' . _T('erreur_texte') |
|
| 654 | + . ' '._T('erreur_texte') |
|
| 657 | 655 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 658 | 656 | . $err |
| 659 | 657 | . " </table><a id='fin_err'></a>"; |
@@ -663,9 +661,9 @@ discard block |
||
| 663 | 661 | [$msg, $fermant, $ouvrant] = $errs[0]; |
| 664 | 662 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 665 | 663 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 666 | - $err = $msg . |
|
| 667 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 664 | + $err = $msg. |
|
| 665 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 666 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 669 | 667 | |
| 670 | 668 | return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
| 671 | 669 | } |
@@ -698,7 +696,7 @@ discard block |
||
| 698 | 696 | ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
| 699 | 697 | ) : ''; |
| 700 | 698 | |
| 701 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 699 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 702 | 700 | . $t_skel |
| 703 | 701 | . ' ' |
| 704 | 702 | . $sourcefile |
@@ -713,7 +711,7 @@ discard block |
||
| 713 | 711 | . "'>" |
| 714 | 712 | . _T('zbug_calcul') |
| 715 | 713 | . '</a></legend>' |
| 716 | - . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 714 | + . ($temps ? "\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />" : ('')) |
|
| 717 | 715 | . debusquer_contexte($contexte[$sourcefile]) |
| 718 | 716 | . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
| 719 | 717 | . "</fieldset>\n"; |
@@ -734,33 +732,33 @@ discard block |
||
| 734 | 732 | $nom = $boucle->id_boucle; |
| 735 | 733 | $req = $boucle->type_requete; |
| 736 | 734 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 737 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | - |
|
| 739 | - $res .= "\n<tr style='background-color: " . |
|
| 740 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | - "'><td align='right'>$i</td><td>\n" . |
|
| 742 | - "<a class='debug_link_boucle' href='" . |
|
| 743 | - $self2 . |
|
| 744 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | - _T('zbug_boucle') . |
|
| 746 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | - $self2 . |
|
| 748 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | - _T('zbug_resultat') . |
|
| 750 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | - $self2 . |
|
| 752 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | - _T('zbug_code') . |
|
| 754 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | - "'>" . |
|
| 757 | - _T('zbug_calcul') . |
|
| 758 | - "</a></td><td>\n" . |
|
| 759 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | - "</td><td>\n" . |
|
| 761 | - $req . |
|
| 762 | - "</td><td>\n" . |
|
| 763 | - spip_htmlspecialchars($crit) . |
|
| 735 | + $self2 = $self.'&var_mode_objet='.$objet; |
|
| 736 | + |
|
| 737 | + $res .= "\n<tr style='background-color: ". |
|
| 738 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 739 | + "'><td align='right'>$i</td><td>\n". |
|
| 740 | + "<a class='debug_link_boucle' href='". |
|
| 741 | + $self2. |
|
| 742 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 743 | + _T('zbug_boucle'). |
|
| 744 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 745 | + $self2. |
|
| 746 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 747 | + _T('zbug_resultat'). |
|
| 748 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 749 | + $self2. |
|
| 750 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 751 | + _T('zbug_code'). |
|
| 752 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 753 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 754 | + "'>". |
|
| 755 | + _T('zbug_calcul'). |
|
| 756 | + "</a></td><td>\n". |
|
| 757 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 758 | + "</td><td>\n". |
|
| 759 | + $req. |
|
| 760 | + "</td><td>\n". |
|
| 761 | + spip_htmlspecialchars($crit). |
|
| 764 | 762 | '</td></tr>'; |
| 765 | 763 | } |
| 766 | 764 | } |
@@ -787,7 +785,7 @@ discard block |
||
| 787 | 785 | } |
| 788 | 786 | // permettre le copier/coller facile |
| 789 | 787 | // $res = ancre_texte($req, array(), true); |
| 790 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 788 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 791 | 789 | // formatage et affichage des resultats bruts de la requete |
| 792 | 790 | $ress_req = spip_query($req); |
| 793 | 791 | $brut_sql = ''; |
@@ -797,10 +795,10 @@ discard block |
||
| 797 | 795 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 798 | 796 | while ($retours_sql = sql_fetch($ress_req)) { |
| 799 | 797 | if ($num <= $max_aff) { |
| 800 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 798 | + $brut_sql .= '<h3>'.($num == 1 ? $num.' sur '.sql_count($ress_req) : $num).'</h3>'; |
|
| 801 | 799 | $brut_sql .= '<p>'; |
| 802 | 800 | foreach ($retours_sql as $key => $val) { |
| 803 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 801 | + $brut_sql .= '<strong>'.$key.'</strong> => '.spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 804 | 802 | } |
| 805 | 803 | $brut_sql .= '</p>'; |
| 806 | 804 | } |
@@ -811,14 +809,14 @@ discard block |
||
| 811 | 809 | // ne pas afficher les $contexte_inclus |
| 812 | 810 | $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
| 813 | 811 | if ($view) { |
| 814 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 812 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view).'</fieldset>'; |
|
| 815 | 813 | } |
| 816 | 814 | } |
| 817 | 815 | } elseif ($affiche == 'code') { |
| 818 | 816 | $legend = $nom; |
| 819 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 817 | + $res = ancre_texte('<'."?php\n".$quoi."\n?".'>'); |
|
| 820 | 818 | } elseif ($affiche == 'boucle') { |
| 821 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 819 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 822 | 820 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 823 | 821 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 824 | 822 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -836,23 +834,23 @@ discard block |
||
| 836 | 834 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 837 | 835 | include_spip('inc/texte'); // pour corriger_typo |
| 838 | 836 | |
| 839 | - return _DOCTYPE_ECRIRE . |
|
| 840 | - html_lang_attributes() . |
|
| 841 | - "<head>\n<title>" . |
|
| 842 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | - ")</title>\n" . |
|
| 846 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | - "' />\n" . |
|
| 837 | + return _DOCTYPE_ECRIRE. |
|
| 838 | + html_lang_attributes(). |
|
| 839 | + "<head>\n<title>". |
|
| 840 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 841 | + _T('admin_debug').' '.spip_htmlspecialchars($titre).' ('. |
|
| 842 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 843 | + ")</title>\n". |
|
| 844 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 845 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 846 | + "' />\n". |
|
| 849 | 847 | http_script('', 'jquery.js') |
| 850 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | - . "' type='text/css' />" . |
|
| 852 | - "</head>\n" . |
|
| 853 | - "<body style='margin:0 10px;'>\n" . |
|
| 854 | - "<div id='spip-debug-header'>" . |
|
| 855 | - $corps . |
|
| 856 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 848 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 849 | + . "' type='text/css' />". |
|
| 850 | + "</head>\n". |
|
| 851 | + "<body style='margin:0 10px;'>\n". |
|
| 852 | + "<div id='spip-debug-header'>". |
|
| 853 | + $corps. |
|
| 854 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 857 | 855 | '</div></body></html>'; |
| 858 | 856 | } |
@@ -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($flux['args']['fond'], 'prive/objets/') |
|
| 116 | - && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | - ) { |
|
| 118 | - if (str_starts_with($flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | - $table = table_objet(substr($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($flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | - $type = substr($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($flux['args']['fond'], 'prive/objets/') |
|
| 116 | + && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | + ) { |
|
| 118 | + if (str_starts_with($flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | + $table = table_objet(substr($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($flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | + $type = substr($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 | } |