@@ -10,110 +10,110 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 17 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | - $racine = basename((string) _DIR_PLUGINS); |
|
| 19 | - $init_dir = $current_dir = ''; |
|
| 20 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | - // des qu'un path est deja note deplie on s'arrete |
|
| 22 | - $deplie = [$racine => true]; |
|
| 23 | - $fast_liste_plugins_actifs = []; |
|
| 24 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | - $dir = dirname((string) $chemin_plug); |
|
| 28 | - $maxiter = 100; |
|
| 29 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | - $deplie[$dir] = true; |
|
| 31 | - $dir = dirname($dir); |
|
| 32 | - } |
|
| 33 | - } |
|
| 17 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | + $racine = basename((string) _DIR_PLUGINS); |
|
| 19 | + $init_dir = $current_dir = ''; |
|
| 20 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | + // des qu'un path est deja note deplie on s'arrete |
|
| 22 | + $deplie = [$racine => true]; |
|
| 23 | + $fast_liste_plugins_actifs = []; |
|
| 24 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | + $dir = dirname((string) $chemin_plug); |
|
| 28 | + $maxiter = 100; |
|
| 29 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | + $deplie[$dir] = true; |
|
| 31 | + $dir = dirname($dir); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - // index repertoires --> plugin |
|
| 36 | - $dir_index = []; |
|
| 37 | - foreach ($liste_plugins as $key => $plug) { |
|
| 38 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | - $dir_index[dirname((string) $liste_plugins[$key])][] = $key; |
|
| 40 | - } |
|
| 35 | + // index repertoires --> plugin |
|
| 36 | + $dir_index = []; |
|
| 37 | + foreach ($liste_plugins as $key => $plug) { |
|
| 38 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | + $dir_index[dirname((string) $liste_plugins[$key])][] = $key; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $visible = @isset($deplie[$current_dir]); |
|
| 43 | - $maxiter = 1000; |
|
| 42 | + $visible = @isset($deplie[$current_dir]); |
|
| 43 | + $maxiter = 1000; |
|
| 44 | 44 | |
| 45 | - $res = ''; |
|
| 46 | - while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | - // le rep suivant |
|
| 48 | - $dir = dirname((string) reset($liste_plugins)); |
|
| 49 | - if ($dir != $current_dir) { |
|
| 50 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | - } |
|
| 45 | + $res = ''; |
|
| 46 | + while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | + // le rep suivant |
|
| 48 | + $dir = dirname((string) reset($liste_plugins)); |
|
| 49 | + if ($dir != $current_dir) { |
|
| 50 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // d'abord tous les plugins du rep courant |
|
| 54 | - if (isset($dir_index[$current_dir])) { |
|
| 55 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | - $plug = $liste_plugins[$key]; |
|
| 57 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | - $id = substr(md5((string) $plug), 0, 16); |
|
| 59 | - $res .= $ligne_plug( |
|
| 60 | - $url_page, |
|
| 61 | - str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | - $actif, |
|
| 63 | - 'menu-entree' |
|
| 64 | - ) . "\n"; |
|
| 65 | - unset($liste_plugins[$key]); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 53 | + // d'abord tous les plugins du rep courant |
|
| 54 | + if (isset($dir_index[$current_dir])) { |
|
| 55 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | + $plug = $liste_plugins[$key]; |
|
| 57 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | + $id = substr(md5((string) $plug), 0, 16); |
|
| 59 | + $res .= $ligne_plug( |
|
| 60 | + $url_page, |
|
| 61 | + str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | + $actif, |
|
| 63 | + 'menu-entree' |
|
| 64 | + ) . "\n"; |
|
| 65 | + unset($liste_plugins[$key]); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 70 | 70 | |
| 71 | - return "<ul class='menu-liste plugins'>" |
|
| 72 | - . $res |
|
| 73 | - . '</ul>'; |
|
| 71 | + return "<ul class='menu-liste plugins'>" |
|
| 72 | + . $res |
|
| 73 | + . '</ul>'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 78 | 78 | // une fonction pour aider... |
| 79 | 79 | function chemin_plug($racine, $plug) { |
| 80 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = []) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ''; |
|
| 86 | - } |
|
| 87 | - $tcur = explode('/', (string) $current); |
|
| 88 | - $ttarg = explode('/', (string) $target); |
|
| 89 | - $tcom = []; |
|
| 90 | - $output = ''; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) === reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ''; |
|
| 103 | - if ($tcom !== []) { |
|
| 104 | - $chemin .= implode('/', $tcom) . '/'; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . '/'; |
|
| 110 | - $output .= '<li>'; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ''; |
|
| 86 | + } |
|
| 87 | + $tcur = explode('/', (string) $current); |
|
| 88 | + $ttarg = explode('/', (string) $target); |
|
| 89 | + $tcom = []; |
|
| 90 | + $output = ''; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) === reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ''; |
|
| 103 | + if ($tcom !== []) { |
|
| 104 | + $chemin .= implode('/', $tcom) . '/'; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . '/'; |
|
| 110 | + $output .= '<li>'; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -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,95 +842,95 @@ 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 | - return match (true) { |
|
| 915 | - in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 916 | - $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 917 | - $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 918 | - $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 919 | - $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 920 | - $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 921 | - $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 922 | - default => '', |
|
| 923 | - }; |
|
| 914 | + return match (true) { |
|
| 915 | + in_array($fonc, $GLOBALS['table_criteres_infixes']) => "($code $fonc $arg)", |
|
| 916 | + $fonc == 'and' || $fonc == 'et' => "((($code) AND ($arg)) ?' ' :'')", |
|
| 917 | + $fonc == 'or' || $fonc == 'ou' => "((($code) OR ($arg)) ?' ' :'')", |
|
| 918 | + $fonc == 'xor' || $fonc == 'xou' => "((($code) XOR ($arg)) ?' ' :'')", |
|
| 919 | + $fonc == 'sinon' => "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)", |
|
| 920 | + $fonc == 'not' || $fonc == 'non' => "(($code) ?'' :' ')", |
|
| 921 | + $fonc == 'yes' || $fonc == 'oui' => "(($code) ?' ' :'')", |
|
| 922 | + default => '', |
|
| 923 | + }; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | function compose_filtres_args($p, $args, $sep) { |
| 927 | - $arglist = ''; |
|
| 928 | - foreach ($args as $arg) { |
|
| 929 | - $arglist .= $sep . |
|
| 930 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 931 | - } |
|
| 927 | + $arglist = ''; |
|
| 928 | + foreach ($args as $arg) { |
|
| 929 | + $arglist .= $sep . |
|
| 930 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return $arglist; |
|
| 933 | + return $arglist; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | |
@@ -948,15 +948,15 @@ discard block |
||
| 948 | 948 | **/ |
| 949 | 949 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 950 | 950 | |
| 951 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 952 | - if ($boucles[$idb]->externe) { |
|
| 953 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 954 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 955 | - // on ignore le defaut fourni dans ce cas |
|
| 956 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 957 | - } |
|
| 951 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 952 | + if ($boucles[$idb]->externe) { |
|
| 953 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 954 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 955 | + // on ignore le defaut fourni dans ce cas |
|
| 956 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 957 | + } |
|
| 958 | 958 | |
| 959 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 959 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | // |
@@ -970,30 +970,30 @@ discard block |
||
| 970 | 970 | // |
| 971 | 971 | |
| 972 | 972 | function rindex_pile($p, $champ, $motif) { |
| 973 | - $n = 0; |
|
| 974 | - $b = $p->id_boucle; |
|
| 975 | - $p->code = ''; |
|
| 976 | - while ($b != '') { |
|
| 977 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 978 | - if ($critere->op == $motif) { |
|
| 979 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | - "]['$champ']"; |
|
| 981 | - $b = ''; |
|
| 982 | - break 2; |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - $n++; |
|
| 986 | - $b = $p->boucles[$b]->id_parent; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 990 | - if (!$p->code) { |
|
| 991 | - $p->code = "''"; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - $p->interdire_scripts = false; |
|
| 995 | - |
|
| 996 | - return $p; |
|
| 973 | + $n = 0; |
|
| 974 | + $b = $p->id_boucle; |
|
| 975 | + $p->code = ''; |
|
| 976 | + while ($b != '') { |
|
| 977 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 978 | + if ($critere->op == $motif) { |
|
| 979 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 980 | + "]['$champ']"; |
|
| 981 | + $b = ''; |
|
| 982 | + break 2; |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + $n++; |
|
| 986 | + $b = $p->boucles[$b]->id_parent; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 990 | + if (!$p->code) { |
|
| 991 | + $p->code = "''"; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + $p->interdire_scripts = false; |
|
| 995 | + |
|
| 996 | + return $p; |
|
| 997 | 997 | } |
| 998 | 998 | |
| 999 | 999 | /** |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1004 | 1004 | */ |
| 1005 | 1005 | function zbug_presenter_champ($p, $champ = '') { |
| 1006 | - $balise = $champ ?: $p->nom_champ; |
|
| 1007 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | - return "#{$explicite}{$balise}"; |
|
| 1006 | + $balise = $champ ?: $p->nom_champ; |
|
| 1007 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1008 | + return "#{$explicite}{$balise}"; |
|
| 1009 | 1009 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -33,37 +33,37 @@ discard block |
||
| 33 | 33 | * Contenu HTML, avec boutons d'administrations et sa CSS |
| 34 | 34 | **/ |
| 35 | 35 | function affiche_boutons_admin($contenu) { |
| 36 | - include_spip('inc/filtres'); |
|
| 36 | + include_spip('inc/filtres'); |
|
| 37 | 37 | |
| 38 | - // Inserer le css d'admin |
|
| 39 | - $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | - . "' type='text/css' />\n"; |
|
| 41 | - if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | - $css .= "<link rel='stylesheet' href='" |
|
| 43 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | - } |
|
| 38 | + // Inserer le css d'admin |
|
| 39 | + $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | + . "' type='text/css' />\n"; |
|
| 41 | + if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | + $css .= "<link rel='stylesheet' href='" |
|
| 43 | + . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ( |
|
| 47 | - !($pos = stripos($contenu, '</head>')) |
|
| 48 | - && !($pos = stripos($contenu, '<body>')) |
|
| 49 | - ) { |
|
| 50 | - $pos = 0; |
|
| 51 | - } |
|
| 52 | - $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 46 | + if ( |
|
| 47 | + !($pos = stripos($contenu, '</head>')) |
|
| 48 | + && !($pos = stripos($contenu, '<body>')) |
|
| 49 | + ) { |
|
| 50 | + $pos = 0; |
|
| 51 | + } |
|
| 52 | + $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | - $boutons_admin = inclure_balise_dynamique( |
|
| 57 | - balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | - false |
|
| 59 | - ); |
|
| 60 | - if ( |
|
| 61 | - !($pos = strripos($contenu, '</body>')) |
|
| 62 | - && !($pos = strripos($contenu, '</html>')) |
|
| 63 | - ) { |
|
| 64 | - $pos = strlen($contenu); |
|
| 65 | - } |
|
| 55 | + // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | + $boutons_admin = inclure_balise_dynamique( |
|
| 57 | + balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | + false |
|
| 59 | + ); |
|
| 60 | + if ( |
|
| 61 | + !($pos = strripos($contenu, '</body>')) |
|
| 62 | + && !($pos = strripos($contenu, '</html>')) |
|
| 63 | + ) { |
|
| 64 | + $pos = strlen($contenu); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 68 | + return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 69 | 69 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | include_spip('public/decompiler'); |
@@ -69,125 +69,125 @@ discard block |
||
| 69 | 69 | * - true si $opt 'erreurs' = 'reset' |
| 70 | 70 | **/ |
| 71 | 71 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 72 | - static $should_log; |
|
| 73 | - static $tableau_des_erreurs = []; |
|
| 74 | - |
|
| 75 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 76 | - if (isset($opt['erreurs'])) { |
|
| 77 | - if ($opt['erreurs'] == 'get') { |
|
| 78 | - return $tableau_des_erreurs; |
|
| 79 | - } |
|
| 80 | - if ($opt['erreurs'] == 'reset') { |
|
| 81 | - $tableau_des_erreurs = []; |
|
| 82 | - |
|
| 83 | - return true; |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (is_null($should_log)) { |
|
| 88 | - $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Erreur ou appel final ? |
|
| 92 | - if ($message) { |
|
| 93 | - $message = debusquer_compose_message($message); |
|
| 94 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 95 | - set_request('var_mode', 'debug'); |
|
| 96 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 97 | - // Permettre a la compil de continuer |
|
| 98 | - if (is_object($lieu) && (!isset($lieu->code) || !$lieu->code)) { |
|
| 99 | - $lieu->code = "''"; |
|
| 100 | - } |
|
| 101 | - // loger si personne ne verra l'erreur |
|
| 102 | - if ($should_log) { |
|
| 103 | - debusquer_loger_erreur($message, $lieu); |
|
| 104 | - } |
|
| 105 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 106 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS && (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 107 | - if (!$urgence) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - // espace public ? |
|
| 112 | - if (empty($GLOBALS['debug_objets']['principal']) && isset($GLOBALS['fond'])) { |
|
| 113 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - include_spip('inc/autoriser'); |
|
| 117 | - if (!autoriser('debug')) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - include_spip('inc/headers'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - |
|
| 123 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 124 | - $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 125 | - $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 126 | - |
|
| 127 | - $self = str_replace("\\'", ''', (string) self()); |
|
| 128 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 129 | - |
|
| 130 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 131 | - . '<br />' |
|
| 132 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 133 | - |
|
| 134 | - if (!_DIR_RESTREINT || headers_sent()) { |
|
| 135 | - return $res; |
|
| 136 | - } |
|
| 137 | - if ($tableau_des_erreurs) { |
|
| 138 | - http_response_code(503); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - http_no_cache(); |
|
| 142 | - if (isset($_GET['var_profile'])) { |
|
| 143 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 144 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 145 | - } else { |
|
| 146 | - if (!$fonc) { |
|
| 147 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 148 | - } |
|
| 149 | - $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | - } |
|
| 151 | - if ($message === false) { |
|
| 152 | - lang_select(); |
|
| 153 | - |
|
| 154 | - return debusquer_entete($titre, $res); |
|
| 155 | - } else { |
|
| 156 | - echo debusquer_entete($titre, $res); |
|
| 157 | - } |
|
| 158 | - exit; |
|
| 72 | + static $should_log; |
|
| 73 | + static $tableau_des_erreurs = []; |
|
| 74 | + |
|
| 75 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 76 | + if (isset($opt['erreurs'])) { |
|
| 77 | + if ($opt['erreurs'] == 'get') { |
|
| 78 | + return $tableau_des_erreurs; |
|
| 79 | + } |
|
| 80 | + if ($opt['erreurs'] == 'reset') { |
|
| 81 | + $tableau_des_erreurs = []; |
|
| 82 | + |
|
| 83 | + return true; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (is_null($should_log)) { |
|
| 88 | + $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Erreur ou appel final ? |
|
| 92 | + if ($message) { |
|
| 93 | + $message = debusquer_compose_message($message); |
|
| 94 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 95 | + set_request('var_mode', 'debug'); |
|
| 96 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 97 | + // Permettre a la compil de continuer |
|
| 98 | + if (is_object($lieu) && (!isset($lieu->code) || !$lieu->code)) { |
|
| 99 | + $lieu->code = "''"; |
|
| 100 | + } |
|
| 101 | + // loger si personne ne verra l'erreur |
|
| 102 | + if ($should_log) { |
|
| 103 | + debusquer_loger_erreur($message, $lieu); |
|
| 104 | + } |
|
| 105 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 106 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS && (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 107 | + if (!$urgence) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + // espace public ? |
|
| 112 | + if (empty($GLOBALS['debug_objets']['principal']) && isset($GLOBALS['fond'])) { |
|
| 113 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + include_spip('inc/autoriser'); |
|
| 117 | + if (!autoriser('debug')) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + include_spip('inc/headers'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + |
|
| 123 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 124 | + $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 125 | + $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 126 | + |
|
| 127 | + $self = str_replace("\\'", ''', (string) self()); |
|
| 128 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 129 | + |
|
| 130 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 131 | + . '<br />' |
|
| 132 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 133 | + |
|
| 134 | + if (!_DIR_RESTREINT || headers_sent()) { |
|
| 135 | + return $res; |
|
| 136 | + } |
|
| 137 | + if ($tableau_des_erreurs) { |
|
| 138 | + http_response_code(503); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + http_no_cache(); |
|
| 142 | + if (isset($_GET['var_profile'])) { |
|
| 143 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 144 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 145 | + } else { |
|
| 146 | + if (!$fonc) { |
|
| 147 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 148 | + } |
|
| 149 | + $titre = $mode ? $mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '') : ($fonc); |
|
| 150 | + } |
|
| 151 | + if ($message === false) { |
|
| 152 | + lang_select(); |
|
| 153 | + |
|
| 154 | + return debusquer_entete($titre, $res); |
|
| 155 | + } else { |
|
| 156 | + echo debusquer_entete($titre, $res); |
|
| 157 | + } |
|
| 158 | + exit; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | function debusquer_compose_message($msg) { |
| 162 | - if (is_array($msg)) { |
|
| 163 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 164 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 165 | - $msg = !is_numeric($msg[0]) && count($msg) == 2 ? _T($msg[0], $msg[1], 'spip-debug-arg') : debusquer_requete($msg); |
|
| 166 | - } |
|
| 167 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 168 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 169 | - $fond = $GLOBALS['fond'] ?? ''; |
|
| 170 | - // une erreur critique sort $message en array |
|
| 171 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 172 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 173 | - |
|
| 174 | - return $msg; |
|
| 162 | + if (is_array($msg)) { |
|
| 163 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 164 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 165 | + $msg = !is_numeric($msg[0]) && count($msg) == 2 ? _T($msg[0], $msg[1], 'spip-debug-arg') : debusquer_requete($msg); |
|
| 166 | + } |
|
| 167 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 168 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 169 | + $fond = $GLOBALS['fond'] ?? ''; |
|
| 170 | + // une erreur critique sort $message en array |
|
| 171 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 172 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 173 | + |
|
| 174 | + return $msg; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function debusquer_bandeau($erreurs) { |
| 178 | 178 | |
| 179 | - if (!empty($erreurs)) { |
|
| 180 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 179 | + if (!empty($erreurs)) { |
|
| 180 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 181 | 181 | |
| 182 | - return debusquer_navigation($erreurs, $n); |
|
| 183 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 184 | - include_spip('public/tracer'); |
|
| 185 | - [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 182 | + return debusquer_navigation($erreurs, $n); |
|
| 183 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 184 | + include_spip('public/tracer'); |
|
| 185 | + [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 186 | 186 | |
| 187 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 188 | - } else { |
|
| 189 | - return ''; |
|
| 190 | - } |
|
| 187 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 188 | + } else { |
|
| 189 | + return ''; |
|
| 190 | + } |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -197,63 +197,63 @@ discard block |
||
| 197 | 197 | * @return string Code HTML |
| 198 | 198 | **/ |
| 199 | 199 | function debusquer_contexte($env) { |
| 200 | - if (is_string($env) && is_array($env_tab = @unserialize($env))) { |
|
| 201 | - $env = $env_tab; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (!$env) { |
|
| 205 | - return ''; |
|
| 206 | - } |
|
| 207 | - $res = ''; |
|
| 208 | - foreach ($env as $nom => $valeur) { |
|
| 209 | - if (is_array($valeur)) { |
|
| 210 | - $valeur_simple = []; |
|
| 211 | - foreach ($valeur as $v) { |
|
| 212 | - if (is_array($v)) { |
|
| 213 | - $valeur_simple[] = 'array:' . count($v); |
|
| 214 | - } elseif (is_object($v)) { |
|
| 215 | - $valeur_simple[] = $v::class; |
|
| 216 | - } elseif (is_string($v)) { |
|
| 217 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 218 | - } else { |
|
| 219 | - $valeur_simple[] = $v; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - $n = count($valeur); |
|
| 223 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | - $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 225 | - } elseif (is_object($valeur)) { |
|
| 226 | - $valeur = $valeur::class; |
|
| 227 | - } elseif (is_string($valeur)) { |
|
| 228 | - $valeur = "'" . $valeur . "'"; |
|
| 229 | - } |
|
| 230 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 232 | - . "</td></tr>\n"; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 200 | + if (is_string($env) && is_array($env_tab = @unserialize($env))) { |
|
| 201 | + $env = $env_tab; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (!$env) { |
|
| 205 | + return ''; |
|
| 206 | + } |
|
| 207 | + $res = ''; |
|
| 208 | + foreach ($env as $nom => $valeur) { |
|
| 209 | + if (is_array($valeur)) { |
|
| 210 | + $valeur_simple = []; |
|
| 211 | + foreach ($valeur as $v) { |
|
| 212 | + if (is_array($v)) { |
|
| 213 | + $valeur_simple[] = 'array:' . count($v); |
|
| 214 | + } elseif (is_object($v)) { |
|
| 215 | + $valeur_simple[] = $v::class; |
|
| 216 | + } elseif (is_string($v)) { |
|
| 217 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 218 | + } else { |
|
| 219 | + $valeur_simple[] = $v; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + $n = count($valeur); |
|
| 223 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 224 | + $valeur .= '[' . implode(', ', $valeur_simple) . ']'; |
|
| 225 | + } elseif (is_object($valeur)) { |
|
| 226 | + $valeur = $valeur::class; |
|
| 227 | + } elseif (is_string($valeur)) { |
|
| 228 | + $valeur = "'" . $valeur . "'"; |
|
| 229 | + } |
|
| 230 | + $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 231 | + . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 232 | + . "</td></tr>\n"; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | function debusquer_loger_erreur($msg, $lieu) { |
| 240 | - $boucle = $ligne = $skel = ''; |
|
| 241 | - if (is_object($lieu)) { |
|
| 242 | - $ligne = ($lieu->ligne ?? ''); |
|
| 243 | - $boucle = ($lieu->id_boucle ?? ''); |
|
| 244 | - $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 245 | - } |
|
| 246 | - $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 247 | - if ($skel) { |
|
| 248 | - $msg .= " Squelette $skel"; |
|
| 249 | - } |
|
| 250 | - if ($boucle) { |
|
| 251 | - $msg .= " Boucle $boucle"; |
|
| 252 | - } |
|
| 253 | - if ($ligne) { |
|
| 254 | - $msg .= " L$ligne"; |
|
| 255 | - } |
|
| 256 | - spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 240 | + $boucle = $ligne = $skel = ''; |
|
| 241 | + if (is_object($lieu)) { |
|
| 242 | + $ligne = ($lieu->ligne ?? ''); |
|
| 243 | + $boucle = ($lieu->id_boucle ?? ''); |
|
| 244 | + $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 245 | + } |
|
| 246 | + $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 247 | + if ($skel) { |
|
| 248 | + $msg .= " Squelette $skel"; |
|
| 249 | + } |
|
| 250 | + if ($boucle) { |
|
| 251 | + $msg .= " Boucle $boucle"; |
|
| 252 | + } |
|
| 253 | + if ($ligne) { |
|
| 254 | + $msg .= " L$ligne"; |
|
| 255 | + } |
|
| 256 | + spip_log($msg, 'debusquer' . _LOG_ERREUR); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -262,66 +262,66 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 264 | 264 | |
| 265 | - if (_request('exec') == 'valider_xml') { |
|
| 266 | - return ''; |
|
| 267 | - } |
|
| 268 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 269 | - $res = ''; |
|
| 270 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 271 | - foreach ($tableau as $i => $err) { |
|
| 272 | - $boucle = $ligne = $skel = ''; |
|
| 273 | - [$msg, $lieu] = $err; |
|
| 274 | - if (is_object($lieu)) { |
|
| 275 | - $ligne = $lieu->ligne; |
|
| 276 | - $boucle = empty($lieu->id_boucle) ? '' : $lieu->id_boucle; |
|
| 277 | - if (isset($lieu->descr['nom'])) { |
|
| 278 | - $nom_code = $lieu->descr['nom']; |
|
| 279 | - $skel = $lieu->descr['sourcefile']; |
|
| 280 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 281 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 282 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 283 | - if ($boucle) { |
|
| 284 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - $j = ($i + 1); |
|
| 291 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 292 | - . $j |
|
| 293 | - . " </td><td style='text-align: left'>" |
|
| 294 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 295 | - . "</td><td style='text-align: left'>" |
|
| 296 | - . ($skel ?: ' / ') |
|
| 297 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 298 | - . ($boucle ?: ' / ') |
|
| 299 | - . "</td><td style='text-align: right'>" |
|
| 300 | - . $ligne |
|
| 301 | - . "</td></tr>\n"; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return "\n<table id='$id'>" |
|
| 305 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 306 | - . $caption[0] |
|
| 265 | + if (_request('exec') == 'valider_xml') { |
|
| 266 | + return ''; |
|
| 267 | + } |
|
| 268 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 269 | + $res = ''; |
|
| 270 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 271 | + foreach ($tableau as $i => $err) { |
|
| 272 | + $boucle = $ligne = $skel = ''; |
|
| 273 | + [$msg, $lieu] = $err; |
|
| 274 | + if (is_object($lieu)) { |
|
| 275 | + $ligne = $lieu->ligne; |
|
| 276 | + $boucle = empty($lieu->id_boucle) ? '' : $lieu->id_boucle; |
|
| 277 | + if (isset($lieu->descr['nom'])) { |
|
| 278 | + $nom_code = $lieu->descr['nom']; |
|
| 279 | + $skel = $lieu->descr['sourcefile']; |
|
| 280 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 281 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 282 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 283 | + if ($boucle) { |
|
| 284 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 285 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + $j = ($i + 1); |
|
| 291 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 292 | + . $j |
|
| 293 | + . " </td><td style='text-align: left'>" |
|
| 294 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 295 | + . "</td><td style='text-align: left'>" |
|
| 296 | + . ($skel ?: ' / ') |
|
| 297 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 298 | + . ($boucle ?: ' / ') |
|
| 299 | + . "</td><td style='text-align: right'>" |
|
| 300 | + . $ligne |
|
| 301 | + . "</td></tr>\n"; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return "\n<table id='$id'>" |
|
| 305 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 306 | + . $caption[0] |
|
| 307 | 307 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 308 | 308 | # aider('erreur_compilation'), |
| 309 | - . '</caption>' |
|
| 310 | - // fausse caption du chrono (mais vraie nav) |
|
| 311 | - . (empty($caption[1]) ? '' : $caption[1]) |
|
| 312 | - . '<tr><th>' |
|
| 313 | - . _T('numero') |
|
| 314 | - . '</th><th>' |
|
| 315 | - . _T('public:message') |
|
| 316 | - . '</th><th>' |
|
| 317 | - . _T('squelette') |
|
| 318 | - . '</th><th>' |
|
| 319 | - . _T('zbug_boucle') |
|
| 320 | - . '</th><th>' |
|
| 321 | - . _T('ligne') |
|
| 322 | - . '</th></tr>' |
|
| 323 | - . $res |
|
| 324 | - . '</table>'; |
|
| 309 | + . '</caption>' |
|
| 310 | + // fausse caption du chrono (mais vraie nav) |
|
| 311 | + . (empty($caption[1]) ? '' : $caption[1]) |
|
| 312 | + . '<tr><th>' |
|
| 313 | + . _T('numero') |
|
| 314 | + . '</th><th>' |
|
| 315 | + . _T('public:message') |
|
| 316 | + . '</th><th>' |
|
| 317 | + . _T('squelette') |
|
| 318 | + . '</th><th>' |
|
| 319 | + . _T('zbug_boucle') |
|
| 320 | + . '</th><th>' |
|
| 321 | + . _T('ligne') |
|
| 322 | + . '</th></tr>' |
|
| 323 | + . $res |
|
| 324 | + . '</table>'; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -341,518 +341,518 @@ discard block |
||
| 341 | 341 | * ou un tableau si l'erreur est critique |
| 342 | 342 | **/ |
| 343 | 343 | function debusquer_requete($message) { |
| 344 | - [$errno, $msg, $query] = $message; |
|
| 345 | - |
|
| 346 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 347 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 348 | - if (preg_match(',err(no|code):?[[:space:]]*(\d+),i', (string) $msg, $regs)) { |
|
| 349 | - $errno = $regs[2]; |
|
| 350 | - } elseif ( |
|
| 351 | - is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | - && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', (string) $msg, $regs) |
|
| 353 | - ) { |
|
| 354 | - $errno = $regs[1]; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // Erreur systeme |
|
| 358 | - if (is_numeric($errno) && $errno > 0 && $errno < 200) { |
|
| 359 | - $retour = '<tt><br /><br /><blink>' |
|
| 360 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 361 | - . "</blink><br />\n<b>" |
|
| 362 | - . _T( |
|
| 363 | - 'info_erreur_systeme2', |
|
| 364 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 365 | - ) |
|
| 366 | - . '</b><br />'; |
|
| 367 | - spip_log("Erreur systeme $errno"); |
|
| 368 | - |
|
| 369 | - return [$retour, '']; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Requete erronee |
|
| 373 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 374 | - . spip_htmlspecialchars($msg) |
|
| 375 | - . "\n<br /><span style='color: red'><b>" |
|
| 376 | - . spip_htmlspecialchars($query) |
|
| 377 | - . '</b></span></tt><br />'; |
|
| 378 | - |
|
| 379 | - //. aider('erreur_mysql'); |
|
| 380 | - |
|
| 381 | - return $err; |
|
| 344 | + [$errno, $msg, $query] = $message; |
|
| 345 | + |
|
| 346 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 347 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 348 | + if (preg_match(',err(no|code):?[[:space:]]*(\d+),i', (string) $msg, $regs)) { |
|
| 349 | + $errno = $regs[2]; |
|
| 350 | + } elseif ( |
|
| 351 | + is_numeric($errno) && ($errno == 1030 || $errno <= 1026) |
|
| 352 | + && preg_match(',[^[:alnum:]](\d+)[^[:alnum:]],', (string) $msg, $regs) |
|
| 353 | + ) { |
|
| 354 | + $errno = $regs[1]; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // Erreur systeme |
|
| 358 | + if (is_numeric($errno) && $errno > 0 && $errno < 200) { |
|
| 359 | + $retour = '<tt><br /><br /><blink>' |
|
| 360 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 361 | + . "</blink><br />\n<b>" |
|
| 362 | + . _T( |
|
| 363 | + 'info_erreur_systeme2', |
|
| 364 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 365 | + ) |
|
| 366 | + . '</b><br />'; |
|
| 367 | + spip_log("Erreur systeme $errno"); |
|
| 368 | + |
|
| 369 | + return [$retour, '']; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Requete erronee |
|
| 373 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 374 | + . spip_htmlspecialchars($msg) |
|
| 375 | + . "\n<br /><span style='color: red'><b>" |
|
| 376 | + . spip_htmlspecialchars($query) |
|
| 377 | + . '</b></span></tt><br />'; |
|
| 378 | + |
|
| 379 | + //. aider('erreur_mysql'); |
|
| 380 | + |
|
| 381 | + return $err; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
| 385 | 385 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 386 | 386 | |
| 387 | - $id = $nom . $boucle; |
|
| 388 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 389 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 390 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', (string) $v[0], $r)) { |
|
| 391 | - $y = substr_count((string) $v[0], "\n"); |
|
| 392 | - } else { |
|
| 393 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 394 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 395 | - } else // inclusion |
|
| 396 | - { |
|
| 397 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 398 | - } |
|
| 399 | - $y = substr_count((string) $incl, "\n") |
|
| 400 | - + substr_count($r[1], "\n") |
|
| 401 | - + substr_count($r[3], "\n"); |
|
| 402 | - } |
|
| 403 | - if ($n <= ($y + $debut)) { |
|
| 404 | - if ($v[1][0] == '?') { |
|
| 405 | - return trouve_boucle_debug($n, $nom, $debut, substr((string) $v[1], 1)); |
|
| 406 | - } elseif ($v[1][0] == '!') { |
|
| 407 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 408 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 413 | - } |
|
| 414 | - $debut += $y; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - return [$nom, $boucle, $n - $debut]; |
|
| 387 | + $id = $nom . $boucle; |
|
| 388 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 389 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 390 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', (string) $v[0], $r)) { |
|
| 391 | + $y = substr_count((string) $v[0], "\n"); |
|
| 392 | + } else { |
|
| 393 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 394 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 395 | + } else // inclusion |
|
| 396 | + { |
|
| 397 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 398 | + } |
|
| 399 | + $y = substr_count((string) $incl, "\n") |
|
| 400 | + + substr_count($r[1], "\n") |
|
| 401 | + + substr_count($r[3], "\n"); |
|
| 402 | + } |
|
| 403 | + if ($n <= ($y + $debut)) { |
|
| 404 | + if ($v[1][0] == '?') { |
|
| 405 | + return trouve_boucle_debug($n, $nom, $debut, substr((string) $v[1], 1)); |
|
| 406 | + } elseif ($v[1][0] == '!') { |
|
| 407 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 408 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 413 | + } |
|
| 414 | + $debut += $y; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + return [$nom, $boucle, $n - $debut]; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | function trouve_squelette_inclus($script) { |
| 422 | 422 | |
| 423 | - preg_match('/include\(.(.*).php3?.\);/', (string) $script, $reg); |
|
| 424 | - // si le script X.php n'est pas ecrire/public.php |
|
| 425 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 426 | - // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 427 | - // a defaut on cherche le param 'page' |
|
| 428 | - if ( |
|
| 429 | - $reg[1] == 'ecrire/public' |
|
| 430 | - && !preg_match("/'fond' => '([^']*)'/", (string) $script, $reg) |
|
| 431 | - && !preg_match("/'param' => '([^']*)'/", (string) $script, $reg) |
|
| 432 | - ) { |
|
| 433 | - $reg[1] = 'inconnu'; |
|
| 434 | - } |
|
| 435 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 436 | - |
|
| 437 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 438 | - if (preg_match($incl, (string) $v)) { |
|
| 439 | - return $k; |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return ''; |
|
| 423 | + preg_match('/include\(.(.*).php3?.\);/', (string) $script, $reg); |
|
| 424 | + // si le script X.php n'est pas ecrire/public.php |
|
| 425 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 426 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 427 | + // a defaut on cherche le param 'page' |
|
| 428 | + if ( |
|
| 429 | + $reg[1] == 'ecrire/public' |
|
| 430 | + && !preg_match("/'fond' => '([^']*)'/", (string) $script, $reg) |
|
| 431 | + && !preg_match("/'param' => '([^']*)'/", (string) $script, $reg) |
|
| 432 | + ) { |
|
| 433 | + $reg[1] = 'inconnu'; |
|
| 434 | + } |
|
| 435 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 436 | + |
|
| 437 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 438 | + if (preg_match($incl, (string) $v)) { |
|
| 439 | + return $k; |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return ''; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | function reference_boucle_debug($n, $nom, $self) { |
| 447 | - [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 448 | - |
|
| 449 | - if (!$boucle) { |
|
| 450 | - return $ligne |
|
| 451 | - ? ' (' . |
|
| 452 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | - _T('squelette_ligne')) . |
|
| 454 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
|
| 455 | - : ''; |
|
| 456 | - } else { |
|
| 457 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 458 | - |
|
| 459 | - return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | - " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | - } |
|
| 447 | + [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 448 | + |
|
| 449 | + if (!$boucle) { |
|
| 450 | + return $ligne |
|
| 451 | + ? ' (' . |
|
| 452 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 453 | + _T('squelette_ligne')) . |
|
| 454 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" |
|
| 455 | + : ''; |
|
| 456 | + } else { |
|
| 457 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 458 | + |
|
| 459 | + return $ligne ? " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)" : |
|
| 460 | + " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)"; |
|
| 461 | + } |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // affiche un texte avec numero de ligne et ancre. |
| 465 | 465 | |
| 466 | 466 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 467 | 467 | |
| 468 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 469 | - if ($var_mode_ligne) { |
|
| 470 | - $fautifs[] = [$var_mode_ligne]; |
|
| 471 | - } |
|
| 472 | - $res = ''; |
|
| 473 | - |
|
| 474 | - $s = highlight_string($texte, true); |
|
| 475 | - if (str_starts_with($s, '<code>')) { |
|
| 476 | - $s = substr($s, 6); |
|
| 477 | - $res = '<code>'; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $s = preg_replace( |
|
| 481 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 482 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 483 | - $s |
|
| 484 | - ); |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - $tableau = explode('<br />', $s); |
|
| 488 | - |
|
| 489 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 490 | - |
|
| 491 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 492 | - $formaterr = 'color: red;'; |
|
| 493 | - $i = 1; |
|
| 494 | - $flignes = []; |
|
| 495 | - $loc = [0, 0]; |
|
| 496 | - foreach ($fautifs as $lc) { |
|
| 497 | - if (is_array($lc)) { |
|
| 498 | - $l = array_shift($lc); |
|
| 499 | - $flignes[$l] = $lc; |
|
| 500 | - } else { |
|
| 501 | - $flignes[$lc] = $loc; |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - $ancre = md5((string) $texte); |
|
| 506 | - foreach ($tableau as $ligne) { |
|
| 507 | - if (isset($flignes[$i])) { |
|
| 508 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 509 | - $indexmesg = $flignes[$i][1]; |
|
| 510 | - $err = textebrut($flignes[$i][2]); |
|
| 511 | - // tentative de pointer sur la colonne fautive; |
|
| 512 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 513 | - // $m = $flignes[$i][0]; |
|
| 514 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 515 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 516 | - $bg = $formaterr; |
|
| 517 | - } else { |
|
| 518 | - $indexmesg = $ancre; |
|
| 519 | - $err = $bg = ''; |
|
| 520 | - } |
|
| 521 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 522 | - $i++; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return "<div id='T$ancre'>" |
|
| 526 | - . '<div onclick="' |
|
| 527 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 528 | - . '" title="' |
|
| 529 | - . _T('masquer_colonne') |
|
| 530 | - . '" style="cursor: pointer;">' |
|
| 531 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 532 | - . '</div> |
|
| 468 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 469 | + if ($var_mode_ligne) { |
|
| 470 | + $fautifs[] = [$var_mode_ligne]; |
|
| 471 | + } |
|
| 472 | + $res = ''; |
|
| 473 | + |
|
| 474 | + $s = highlight_string($texte, true); |
|
| 475 | + if (str_starts_with($s, '<code>')) { |
|
| 476 | + $s = substr($s, 6); |
|
| 477 | + $res = '<code>'; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $s = preg_replace( |
|
| 481 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 482 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 483 | + $s |
|
| 484 | + ); |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + $tableau = explode('<br />', $s); |
|
| 488 | + |
|
| 489 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . (string) @strlen(count($tableau)) . "d</a></span> %s<br />\n"; |
|
| 490 | + |
|
| 491 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 492 | + $formaterr = 'color: red;'; |
|
| 493 | + $i = 1; |
|
| 494 | + $flignes = []; |
|
| 495 | + $loc = [0, 0]; |
|
| 496 | + foreach ($fautifs as $lc) { |
|
| 497 | + if (is_array($lc)) { |
|
| 498 | + $l = array_shift($lc); |
|
| 499 | + $flignes[$l] = $lc; |
|
| 500 | + } else { |
|
| 501 | + $flignes[$lc] = $loc; |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + $ancre = md5((string) $texte); |
|
| 506 | + foreach ($tableau as $ligne) { |
|
| 507 | + if (isset($flignes[$i])) { |
|
| 508 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 509 | + $indexmesg = $flignes[$i][1]; |
|
| 510 | + $err = textebrut($flignes[$i][2]); |
|
| 511 | + // tentative de pointer sur la colonne fautive; |
|
| 512 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 513 | + // $m = $flignes[$i][0]; |
|
| 514 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 515 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 516 | + $bg = $formaterr; |
|
| 517 | + } else { |
|
| 518 | + $indexmesg = $ancre; |
|
| 519 | + $err = $bg = ''; |
|
| 520 | + } |
|
| 521 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 522 | + $i++; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return "<div id='T$ancre'>" |
|
| 526 | + . '<div onclick="' |
|
| 527 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 528 | + . '" title="' |
|
| 529 | + . _T('masquer_colonne') |
|
| 530 | + . '" style="cursor: pointer;">' |
|
| 531 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 532 | + . '</div> |
|
| 533 | 533 | ' . $res . "</div>\n"; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // l'environnement graphique du debuggueur |
| 537 | 537 | |
| 538 | 538 | function debusquer_squelette($fonc, $mode, $self) { |
| 539 | - $legend = null; |
|
| 540 | - $texte = ''; |
|
| 541 | - |
|
| 542 | - if ($mode !== 'validation') { |
|
| 543 | - if (isset($GLOBALS['debug_objets']['sourcefile']) && $GLOBALS['debug_objets']['sourcefile']) { |
|
| 544 | - $res = "<div id='spip-boucles'>\n" |
|
| 545 | - . debusquer_navigation_squelettes($self) |
|
| 546 | - . '</div>'; |
|
| 547 | - } else { |
|
| 548 | - $res = ''; |
|
| 549 | - } |
|
| 550 | - if ($fonc) { |
|
| 551 | - $id = " id='$fonc'"; |
|
| 552 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 553 | - [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 554 | - $texte .= $res2; |
|
| 555 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | - $legend = _T('zbug_' . $mode); |
|
| 557 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 558 | - $texte = ancre_texte($texte, ['', '']); |
|
| 559 | - } |
|
| 560 | - } else { |
|
| 561 | - if (strlen(trim($res))) { |
|
| 562 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 563 | - } else { |
|
| 564 | - // cas de l'appel sur erreur: montre la page |
|
| 565 | - return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - } else { |
|
| 569 | - $valider = charger_fonction('valider', 'xml'); |
|
| 570 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 571 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 572 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 573 | - [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 574 | - if ($err === false) { |
|
| 575 | - $err = _T('impossible'); |
|
| 576 | - } elseif ($err === true) { |
|
| 577 | - $err = _T('correcte'); |
|
| 578 | - } else { |
|
| 579 | - $err = ": $err"; |
|
| 580 | - } |
|
| 581 | - $legend = _T('validation') . ' ' . $err; |
|
| 582 | - $res = $id = ''; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - return trim((string) $texte) |
|
| 586 | - ? "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 587 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 588 | - . "<a href='" . $self . '#f_' . substr((string) $fonc, 0, 37) . "'> ↑ " |
|
| 589 | - . ($legend ?: $mode) |
|
| 590 | - . '</a></legend>' |
|
| 591 | - . $texte |
|
| 592 | - . '</fieldset></div>' |
|
| 593 | - . '</div>' |
|
| 594 | - : ''; |
|
| 539 | + $legend = null; |
|
| 540 | + $texte = ''; |
|
| 541 | + |
|
| 542 | + if ($mode !== 'validation') { |
|
| 543 | + if (isset($GLOBALS['debug_objets']['sourcefile']) && $GLOBALS['debug_objets']['sourcefile']) { |
|
| 544 | + $res = "<div id='spip-boucles'>\n" |
|
| 545 | + . debusquer_navigation_squelettes($self) |
|
| 546 | + . '</div>'; |
|
| 547 | + } else { |
|
| 548 | + $res = ''; |
|
| 549 | + } |
|
| 550 | + if ($fonc) { |
|
| 551 | + $id = " id='$fonc'"; |
|
| 552 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 553 | + [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 554 | + $texte .= $res2; |
|
| 555 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 556 | + $legend = _T('zbug_' . $mode); |
|
| 557 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 558 | + $texte = ancre_texte($texte, ['', '']); |
|
| 559 | + } |
|
| 560 | + } else { |
|
| 561 | + if (strlen(trim($res))) { |
|
| 562 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 563 | + } else { |
|
| 564 | + // cas de l'appel sur erreur: montre la page |
|
| 565 | + return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } else { |
|
| 569 | + $valider = charger_fonction('valider', 'xml'); |
|
| 570 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 571 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 572 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 573 | + [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 574 | + if ($err === false) { |
|
| 575 | + $err = _T('impossible'); |
|
| 576 | + } elseif ($err === true) { |
|
| 577 | + $err = _T('correcte'); |
|
| 578 | + } else { |
|
| 579 | + $err = ": $err"; |
|
| 580 | + } |
|
| 581 | + $legend = _T('validation') . ' ' . $err; |
|
| 582 | + $res = $id = ''; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + return trim((string) $texte) |
|
| 586 | + ? "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 587 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 588 | + . "<a href='" . $self . '#f_' . substr((string) $fonc, 0, 37) . "'> ↑ " |
|
| 589 | + . ($legend ?: $mode) |
|
| 590 | + . '</a></legend>' |
|
| 591 | + . $texte |
|
| 592 | + . '</fieldset></div>' |
|
| 593 | + . '</div>' |
|
| 594 | + : ''; |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | |
| 598 | 598 | function emboite_texte($res, $fonc = '', $self = '') { |
| 599 | - $errs = $res->err; |
|
| 600 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 601 | - |
|
| 602 | - if (!$texte && !$errs) { |
|
| 603 | - return [ancre_texte('', ['', '']), false]; |
|
| 604 | - } |
|
| 605 | - if (!$errs) { |
|
| 606 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 610 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 611 | - $encore = count_occ($errs); |
|
| 612 | - $encore2 = []; |
|
| 613 | - $fautifs = []; |
|
| 614 | - |
|
| 615 | - $err = '<tr><th>' |
|
| 616 | - . _T('numero') |
|
| 617 | - . '</th><th>' |
|
| 618 | - . _T('occurence') |
|
| 619 | - . '</th><th>' |
|
| 620 | - . _T('ligne') |
|
| 621 | - . '</th><th>' |
|
| 622 | - . _T('colonne') |
|
| 623 | - . '</th><th>' |
|
| 624 | - . _T('erreur') |
|
| 625 | - . '</th></tr>'; |
|
| 626 | - |
|
| 627 | - $i = 0; |
|
| 628 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 629 | - foreach ($errs as $r) { |
|
| 630 | - $i++; |
|
| 631 | - [$msg, $ligne, $col] = $r; |
|
| 632 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 633 | - if (isset($encore2[$msg])) { |
|
| 634 | - $ref = ++$encore2[$msg]; |
|
| 635 | - } else { |
|
| 636 | - $encore2[$msg] = $ref = 1; |
|
| 637 | - } |
|
| 638 | - $err .= "<tr style='background-color: " |
|
| 639 | - . $colors[$i % 2] |
|
| 640 | - . "'><td $style><a href='#debut_err'>" |
|
| 641 | - . $i |
|
| 642 | - . "</a></td><td $style>" |
|
| 643 | - . "$ref/$encore[$msg]</td>" |
|
| 644 | - . "<td $style><a href='#L" |
|
| 645 | - . $ligne |
|
| 646 | - . "' id='T$i'>" |
|
| 647 | - . $ligne |
|
| 648 | - . "</a></td><td $style>" |
|
| 649 | - . $col |
|
| 650 | - . "</td><td>$msg</td></tr>\n"; |
|
| 651 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 652 | - } |
|
| 653 | - $err = "<h2 style='text-align: center'>" |
|
| 654 | - . $i |
|
| 655 | - . "<a href='#fin_err'>" |
|
| 656 | - . ' ' . _T('erreur_texte') |
|
| 657 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 658 | - . $err |
|
| 659 | - . " </table><a id='fin_err'></a>"; |
|
| 660 | - |
|
| 661 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 662 | - } else { |
|
| 663 | - [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 664 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 665 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 666 | - $err = $msg . |
|
| 667 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 669 | - |
|
| 670 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 671 | - } |
|
| 599 | + $errs = $res->err; |
|
| 600 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 601 | + |
|
| 602 | + if (!$texte && !$errs) { |
|
| 603 | + return [ancre_texte('', ['', '']), false]; |
|
| 604 | + } |
|
| 605 | + if (!$errs) { |
|
| 606 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 610 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 611 | + $encore = count_occ($errs); |
|
| 612 | + $encore2 = []; |
|
| 613 | + $fautifs = []; |
|
| 614 | + |
|
| 615 | + $err = '<tr><th>' |
|
| 616 | + . _T('numero') |
|
| 617 | + . '</th><th>' |
|
| 618 | + . _T('occurence') |
|
| 619 | + . '</th><th>' |
|
| 620 | + . _T('ligne') |
|
| 621 | + . '</th><th>' |
|
| 622 | + . _T('colonne') |
|
| 623 | + . '</th><th>' |
|
| 624 | + . _T('erreur') |
|
| 625 | + . '</th></tr>'; |
|
| 626 | + |
|
| 627 | + $i = 0; |
|
| 628 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 629 | + foreach ($errs as $r) { |
|
| 630 | + $i++; |
|
| 631 | + [$msg, $ligne, $col] = $r; |
|
| 632 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 633 | + if (isset($encore2[$msg])) { |
|
| 634 | + $ref = ++$encore2[$msg]; |
|
| 635 | + } else { |
|
| 636 | + $encore2[$msg] = $ref = 1; |
|
| 637 | + } |
|
| 638 | + $err .= "<tr style='background-color: " |
|
| 639 | + . $colors[$i % 2] |
|
| 640 | + . "'><td $style><a href='#debut_err'>" |
|
| 641 | + . $i |
|
| 642 | + . "</a></td><td $style>" |
|
| 643 | + . "$ref/$encore[$msg]</td>" |
|
| 644 | + . "<td $style><a href='#L" |
|
| 645 | + . $ligne |
|
| 646 | + . "' id='T$i'>" |
|
| 647 | + . $ligne |
|
| 648 | + . "</a></td><td $style>" |
|
| 649 | + . $col |
|
| 650 | + . "</td><td>$msg</td></tr>\n"; |
|
| 651 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 652 | + } |
|
| 653 | + $err = "<h2 style='text-align: center'>" |
|
| 654 | + . $i |
|
| 655 | + . "<a href='#fin_err'>" |
|
| 656 | + . ' ' . _T('erreur_texte') |
|
| 657 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 658 | + . $err |
|
| 659 | + . " </table><a id='fin_err'></a>"; |
|
| 660 | + |
|
| 661 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 662 | + } else { |
|
| 663 | + [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 664 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 665 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 666 | + $err = $msg . |
|
| 667 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 668 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 669 | + |
|
| 670 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 671 | + } |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function count_occ($regs) { |
| 675 | - $encore = []; |
|
| 676 | - foreach ($regs as $r) { |
|
| 677 | - if (isset($encore[$r[0]])) { |
|
| 678 | - $encore[$r[0]]++; |
|
| 679 | - } else { |
|
| 680 | - $encore[$r[0]] = 1; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - return $encore; |
|
| 675 | + $encore = []; |
|
| 676 | + foreach ($regs as $r) { |
|
| 677 | + if (isset($encore[$r[0]])) { |
|
| 678 | + $encore[$r[0]]++; |
|
| 679 | + } else { |
|
| 680 | + $encore[$r[0]] = 1; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + return $encore; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | function debusquer_navigation_squelettes($self) { |
| 688 | 688 | |
| 689 | - $res = ''; |
|
| 690 | - $boucles = empty($GLOBALS['debug_objets']['boucle']) ? '' : $GLOBALS['debug_objets']['boucle']; |
|
| 691 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 692 | - $t_skel = _T('squelette'); |
|
| 693 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 694 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 695 | - $nav = $boucles ? debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile) : ''; |
|
| 696 | - $temps = isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? _T( |
|
| 697 | - 'zbug_profile', |
|
| 698 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 699 | - ) : ''; |
|
| 700 | - |
|
| 701 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 702 | - . $t_skel |
|
| 703 | - . ' ' |
|
| 704 | - . $sourcefile |
|
| 705 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 706 | - . $t_skel |
|
| 707 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 708 | - . _T('zbug_resultat') |
|
| 709 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 710 | - . _T('zbug_code') |
|
| 711 | - . "</a>\n<a href='" |
|
| 712 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', (string) $self) |
|
| 713 | - . "'>" |
|
| 714 | - . _T('zbug_calcul') |
|
| 715 | - . '</a></legend>' |
|
| 716 | - . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 717 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 718 | - . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
|
| 719 | - . "</fieldset>\n"; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return $res; |
|
| 689 | + $res = ''; |
|
| 690 | + $boucles = empty($GLOBALS['debug_objets']['boucle']) ? '' : $GLOBALS['debug_objets']['boucle']; |
|
| 691 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 692 | + $t_skel = _T('squelette'); |
|
| 693 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 694 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 695 | + $nav = $boucles ? debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile) : ''; |
|
| 696 | + $temps = isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? _T( |
|
| 697 | + 'zbug_profile', |
|
| 698 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 699 | + ) : ''; |
|
| 700 | + |
|
| 701 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 702 | + . $t_skel |
|
| 703 | + . ' ' |
|
| 704 | + . $sourcefile |
|
| 705 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 706 | + . $t_skel |
|
| 707 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 708 | + . _T('zbug_resultat') |
|
| 709 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 710 | + . _T('zbug_code') |
|
| 711 | + . "</a>\n<a href='" |
|
| 712 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', (string) $self) |
|
| 713 | + . "'>" |
|
| 714 | + . _T('zbug_calcul') |
|
| 715 | + . '</a></legend>' |
|
| 716 | + . ($temps ? "\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />" : ('')) |
|
| 717 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 718 | + . ($nav ? "<table width='100%'>\n$nav</table>\n" : ('')) |
|
| 719 | + . "</fieldset>\n"; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return $res; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 726 | - $i = 0; |
|
| 727 | - $res = ''; |
|
| 728 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 729 | - $gram = preg_match('/[.](\w+)$/', (string) $nom_source, $r) ? $r[1] : ''; |
|
| 730 | - |
|
| 731 | - foreach ($boucles as $objet => $boucle) { |
|
| 732 | - if (str_starts_with((string) $objet, (string) $nom_skel)) { |
|
| 733 | - $i++; |
|
| 734 | - $nom = $boucle->id_boucle; |
|
| 735 | - $req = $boucle->type_requete; |
|
| 736 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 737 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | - |
|
| 739 | - $res .= "\n<tr style='background-color: " . |
|
| 740 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | - "'><td align='right'>$i</td><td>\n" . |
|
| 742 | - "<a class='debug_link_boucle' href='" . |
|
| 743 | - $self2 . |
|
| 744 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | - _T('zbug_boucle') . |
|
| 746 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | - $self2 . |
|
| 748 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | - _T('zbug_resultat') . |
|
| 750 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | - $self2 . |
|
| 752 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | - _T('zbug_code') . |
|
| 754 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | - "'>" . |
|
| 757 | - _T('zbug_calcul') . |
|
| 758 | - "</a></td><td>\n" . |
|
| 759 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | - "</td><td>\n" . |
|
| 761 | - $req . |
|
| 762 | - "</td><td>\n" . |
|
| 763 | - spip_htmlspecialchars($crit) . |
|
| 764 | - '</td></tr>'; |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - return $res; |
|
| 726 | + $i = 0; |
|
| 727 | + $res = ''; |
|
| 728 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 729 | + $gram = preg_match('/[.](\w+)$/', (string) $nom_source, $r) ? $r[1] : ''; |
|
| 730 | + |
|
| 731 | + foreach ($boucles as $objet => $boucle) { |
|
| 732 | + if (str_starts_with((string) $objet, (string) $nom_skel)) { |
|
| 733 | + $i++; |
|
| 734 | + $nom = $boucle->id_boucle; |
|
| 735 | + $req = $boucle->type_requete; |
|
| 736 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 737 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 738 | + |
|
| 739 | + $res .= "\n<tr style='background-color: " . |
|
| 740 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 741 | + "'><td align='right'>$i</td><td>\n" . |
|
| 742 | + "<a class='debug_link_boucle' href='" . |
|
| 743 | + $self2 . |
|
| 744 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 745 | + _T('zbug_boucle') . |
|
| 746 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 747 | + $self2 . |
|
| 748 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 749 | + _T('zbug_resultat') . |
|
| 750 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 751 | + $self2 . |
|
| 752 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 753 | + _T('zbug_code') . |
|
| 754 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 755 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 756 | + "'>" . |
|
| 757 | + _T('zbug_calcul') . |
|
| 758 | + "</a></td><td>\n" . |
|
| 759 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 760 | + "</td><td>\n" . |
|
| 761 | + $req . |
|
| 762 | + "</td><td>\n" . |
|
| 763 | + spip_htmlspecialchars($crit) . |
|
| 764 | + '</td></tr>'; |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + return $res; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function debusquer_source($objet, $affiche) { |
| 772 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 773 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 774 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 775 | - } else { |
|
| 776 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 777 | - } |
|
| 778 | - $res2 = ''; |
|
| 779 | - |
|
| 780 | - if ($affiche == 'resultat') { |
|
| 781 | - $legend = $nom; |
|
| 782 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 783 | - if (function_exists('_mysql_traite_query')) { |
|
| 784 | - $c = strtolower(_request('connect') ?? ''); |
|
| 785 | - $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 786 | - $req = _mysql_traite_query($req, '', $c); |
|
| 787 | - } |
|
| 788 | - // permettre le copier/coller facile |
|
| 789 | - // $res = ancre_texte($req, array(), true); |
|
| 790 | - $res = "<div id='T" . md5((string) $req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 791 | - // formatage et affichage des resultats bruts de la requete |
|
| 792 | - $ress_req = spip_query($req); |
|
| 793 | - $brut_sql = ''; |
|
| 794 | - $num = 1; |
|
| 795 | - // eviter l'affichage de milliers de lignes |
|
| 796 | - // personnalisation possible dans mes_options |
|
| 797 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 798 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 799 | - if ($num <= $max_aff) { |
|
| 800 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 801 | - $brut_sql .= '<p>'; |
|
| 802 | - foreach ($retours_sql as $key => $val) { |
|
| 803 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 804 | - } |
|
| 805 | - $brut_sql .= '</p>'; |
|
| 806 | - } |
|
| 807 | - $num++; |
|
| 808 | - } |
|
| 809 | - $res2 = interdire_scripts($brut_sql); |
|
| 810 | - foreach ($quoi as $view) { |
|
| 811 | - // ne pas afficher les $contexte_inclus |
|
| 812 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', (string) $view); |
|
| 813 | - if ($view) { |
|
| 814 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - } elseif ($affiche == 'code') { |
|
| 818 | - $legend = $nom; |
|
| 819 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 820 | - } elseif ($affiche == 'boucle') { |
|
| 821 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 822 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 823 | - $gram = preg_match('/^([^_]+)_/', (string) $objet, $r) ? $r[1] : ''; |
|
| 824 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 825 | - } elseif ($affiche == 'squelette') { |
|
| 826 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 827 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return [$legend, $res, $res2]; |
|
| 772 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 773 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 774 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 775 | + } else { |
|
| 776 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 777 | + } |
|
| 778 | + $res2 = ''; |
|
| 779 | + |
|
| 780 | + if ($affiche == 'resultat') { |
|
| 781 | + $legend = $nom; |
|
| 782 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 783 | + if (function_exists('_mysql_traite_query')) { |
|
| 784 | + $c = strtolower(_request('connect') ?? ''); |
|
| 785 | + $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 786 | + $req = _mysql_traite_query($req, '', $c); |
|
| 787 | + } |
|
| 788 | + // permettre le copier/coller facile |
|
| 789 | + // $res = ancre_texte($req, array(), true); |
|
| 790 | + $res = "<div id='T" . md5((string) $req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 791 | + // formatage et affichage des resultats bruts de la requete |
|
| 792 | + $ress_req = spip_query($req); |
|
| 793 | + $brut_sql = ''; |
|
| 794 | + $num = 1; |
|
| 795 | + // eviter l'affichage de milliers de lignes |
|
| 796 | + // personnalisation possible dans mes_options |
|
| 797 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 798 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 799 | + if ($num <= $max_aff) { |
|
| 800 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 801 | + $brut_sql .= '<p>'; |
|
| 802 | + foreach ($retours_sql as $key => $val) { |
|
| 803 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 804 | + } |
|
| 805 | + $brut_sql .= '</p>'; |
|
| 806 | + } |
|
| 807 | + $num++; |
|
| 808 | + } |
|
| 809 | + $res2 = interdire_scripts($brut_sql); |
|
| 810 | + foreach ($quoi as $view) { |
|
| 811 | + // ne pas afficher les $contexte_inclus |
|
| 812 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', (string) $view); |
|
| 813 | + if ($view) { |
|
| 814 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + } elseif ($affiche == 'code') { |
|
| 818 | + $legend = $nom; |
|
| 819 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 820 | + } elseif ($affiche == 'boucle') { |
|
| 821 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 822 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 823 | + $gram = preg_match('/^([^_]+)_/', (string) $objet, $r) ? $r[1] : ''; |
|
| 824 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 825 | + } elseif ($affiche == 'squelette') { |
|
| 826 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 827 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return [$legend, $res, $res2]; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | function debusquer_entete($titre, $corps) { |
| 834 | 834 | |
| 835 | - include_spip('balise/formulaire_admin'); |
|
| 836 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | - |
|
| 839 | - return _DOCTYPE_ECRIRE . |
|
| 840 | - html_lang_attributes() . |
|
| 841 | - "<head>\n<title>" . |
|
| 842 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | - ")</title>\n" . |
|
| 846 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | - "' />\n" . |
|
| 849 | - http_script('', 'jquery.js') |
|
| 850 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | - . "' type='text/css' />" . |
|
| 852 | - "</head>\n" . |
|
| 853 | - "<body style='margin:0 10px;'>\n" . |
|
| 854 | - "<div id='spip-debug-header'>" . |
|
| 855 | - $corps . |
|
| 856 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | - '</div></body></html>'; |
|
| 835 | + include_spip('balise/formulaire_admin'); |
|
| 836 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 837 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 838 | + |
|
| 839 | + return _DOCTYPE_ECRIRE . |
|
| 840 | + html_lang_attributes() . |
|
| 841 | + "<head>\n<title>" . |
|
| 842 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 843 | + _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 844 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 845 | + ")</title>\n" . |
|
| 846 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 847 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 848 | + "' />\n" . |
|
| 849 | + http_script('', 'jquery.js') |
|
| 850 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 851 | + . "' type='text/css' />" . |
|
| 852 | + "</head>\n" . |
|
| 853 | + "<body style='margin:0 10px;'>\n" . |
|
| 854 | + "<div id='spip-debug-header'>" . |
|
| 855 | + $corps . |
|
| 856 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 857 | + '</div></body></html>'; |
|
| 858 | 858 | } |
@@ -10,123 +10,123 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 17 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | - $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | - |
|
| 24 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 17 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | + $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | + |
|
| 24 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | - if (!str_contains((string) $file, '#')) { |
|
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | - } else { |
|
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 32 | - } |
|
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | - |
|
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 28 | + if (!str_contains((string) $file, '#')) { |
|
| 29 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | + } else { |
|
| 31 | + $t = '{fond=' . $file . '}'; |
|
| 32 | + } |
|
| 33 | + $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | + |
|
| 35 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | - $contenu = []; |
|
| 40 | - foreach ($args as $l => $t) { |
|
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | - } |
|
| 39 | + $contenu = []; |
|
| 40 | + foreach ($args as $l => $t) { |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | - foreach ($args as $k => $v) { |
|
| 49 | - $args[$k] = "$k=$v"; |
|
| 50 | - } |
|
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 48 | + foreach ($args as $k => $v) { |
|
| 49 | + $args[$k] = "$k=$v"; |
|
| 50 | + } |
|
| 51 | + $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | - $nom = '#' |
|
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 59 | - . $nom |
|
| 60 | - . $etoile |
|
| 61 | - . $args |
|
| 62 | - . $filtres; |
|
| 57 | + $nom = '#' |
|
| 58 | + . ($boucle ? ($boucle . ':') : '') |
|
| 59 | + . $nom |
|
| 60 | + . $etoile |
|
| 61 | + . $args |
|
| 62 | + . $filtres; |
|
| 63 | 63 | |
| 64 | - // Determiner si c'est un champ etendu, |
|
| 64 | + // Determiner si c'est un champ etendu, |
|
| 65 | 65 | |
| 66 | - $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 66 | + $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 67 | 67 | |
| 68 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 68 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function format_critere_html($critere) { |
| 72 | - foreach ($critere as $k => $crit) { |
|
| 73 | - $crit_s = ''; |
|
| 74 | - foreach ($crit as $operande) { |
|
| 75 | - [$type, $valeur] = $operande; |
|
| 76 | - if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | - $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | - $valeur = substr($valeur, 1, -1); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - $crit_s .= $valeur; |
|
| 83 | - } |
|
| 84 | - $critere[$k] = $crit_s; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 72 | + foreach ($critere as $k => $crit) { |
|
| 73 | + $crit_s = ''; |
|
| 74 | + foreach ($crit as $operande) { |
|
| 75 | + [$type, $valeur] = $operande; |
|
| 76 | + if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | + $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | + $valeur = substr($valeur, 1, -1); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + $crit_s .= $valeur; |
|
| 83 | + } |
|
| 84 | + $critere[$k] = $crit_s; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 91 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | + . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 96 | 96 | function format_suite_html($args) { |
| 97 | - $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | - for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | - [$texte, $type] = $args[$i]; |
|
| 100 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | - if (!$texte || !$texte2) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - $c1 = substr((string) $texte, -1); |
|
| 105 | - if ($type2 !== 'texte') { |
|
| 106 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | - // ou assimiles, forcer la notation pleine |
|
| 108 | - if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | - } |
|
| 111 | - } else { |
|
| 112 | - if ($type == 'texte') { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - // si un champ ou assimiles est suivi d'un texte |
|
| 116 | - // et si celui-ci commence par un caractere de champ |
|
| 117 | - // forcer la notation pleine |
|
| 118 | - if ( |
|
| 119 | - $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | - || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | - ) { |
|
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 97 | + $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | + for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | + [$texte, $type] = $args[$i]; |
|
| 100 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | + if (!$texte || !$texte2) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 104 | + $c1 = substr((string) $texte, -1); |
|
| 105 | + if ($type2 !== 'texte') { |
|
| 106 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | + // ou assimiles, forcer la notation pleine |
|
| 108 | + if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | + } |
|
| 111 | + } else { |
|
| 112 | + if ($type == 'texte') { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + // si un champ ou assimiles est suivi d'un texte |
|
| 116 | + // et si celui-ci commence par un caractere de champ |
|
| 117 | + // forcer la notation pleine |
|
| 118 | + if ( |
|
| 119 | + $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | + || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | + ) { |
|
| 122 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function format_texte_html($texte) { |
| 131 | - return $texte; |
|
| 131 | + return $texte; |
|
| 132 | 132 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * texte |
| 41 | 41 | */ |
| 42 | 42 | function sandbox_composer_texte($texte, &$p) { |
| 43 | - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 43 | + return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -56,38 +56,38 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 59 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | - $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | - $refs = $refl->getParameters(); |
|
| 70 | - if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | - } else { |
|
| 74 | - $code = "$f($code$arglist)"; |
|
| 75 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | - } |
|
| 77 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | - if (($nb_args_f < $min_f)) { |
|
| 80 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - // le filtre n'existe pas, |
|
| 85 | - // on le notifie |
|
| 86 | - else { |
|
| 87 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $code; |
|
| 59 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | + $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | + $refs = $refl->getParameters(); |
|
| 70 | + if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | + } else { |
|
| 74 | + $code = "$f($code$arglist)"; |
|
| 75 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | + } |
|
| 77 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | + if (($nb_args_f < $min_f)) { |
|
| 80 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + // le filtre n'existe pas, |
|
| 85 | + // on le notifie |
|
| 86 | + else { |
|
| 87 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $code; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Calculer un <INCLURE(xx.php)> |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 113 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | - // si inexistant, on essaiera a l'execution |
|
| 115 | - $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 113 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | + // si inexistant, on essaiera a l'execution |
|
| 115 | + $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 116 | 116 | |
| 117 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 117 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | 128 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 129 | - // Securite |
|
| 130 | - if ( |
|
| 131 | - $p->interdire_scripts |
|
| 132 | - && $p->etoile != '**' |
|
| 133 | - ) { |
|
| 134 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | - $code = "interdire_scripts($code)"; |
|
| 136 | - } else { |
|
| 137 | - $code = interdire_scripts($r[2]); |
|
| 138 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $code; |
|
| 129 | + // Securite |
|
| 130 | + if ( |
|
| 131 | + $p->interdire_scripts |
|
| 132 | + && $p->etoile != '**' |
|
| 133 | + ) { |
|
| 134 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | + $code = "interdire_scripts($code)"; |
|
| 136 | + } else { |
|
| 137 | + $code = interdire_scripts($r[2]); |
|
| 138 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $code; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return mixed|string |
| 159 | 159 | */ |
| 160 | 160 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 161 | - $series_filtres = func_get_args(); |
|
| 162 | - array_shift($series_filtres);// skel |
|
| 163 | - array_shift($series_filtres);// corps |
|
| 164 | - |
|
| 165 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | - if ($skel['process_ins'] == 'php') { |
|
| 167 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // recuperer les couples de remplacement |
|
| 171 | - $replace = echapper_php_callback(); |
|
| 172 | - |
|
| 173 | - foreach ($series_filtres as $filtres) { |
|
| 174 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | - foreach ($filtres as $filtre) { |
|
| 176 | - if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | - $corps = $f($corps); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // restaurer les echappements |
|
| 184 | - return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 161 | + $series_filtres = func_get_args(); |
|
| 162 | + array_shift($series_filtres);// skel |
|
| 163 | + array_shift($series_filtres);// corps |
|
| 164 | + |
|
| 165 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | + if ($skel['process_ins'] == 'php') { |
|
| 167 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // recuperer les couples de remplacement |
|
| 171 | + $replace = echapper_php_callback(); |
|
| 172 | + |
|
| 173 | + foreach ($series_filtres as $filtres) { |
|
| 174 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | + foreach ($filtres as $filtre) { |
|
| 176 | + if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | + $corps = $f($corps); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // restaurer les echappements |
|
| 184 | + return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -200,21 +200,21 @@ discard block |
||
| 200 | 200 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 201 | 201 | **/ |
| 202 | 202 | function echapper_php_callback($r = null) { |
| 203 | - static $src = []; |
|
| 204 | - static $dst = []; |
|
| 203 | + static $src = []; |
|
| 204 | + static $dst = []; |
|
| 205 | 205 | |
| 206 | - // si on recoit un tableau, on est en mode echappement |
|
| 207 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | - if (is_array($r)) { |
|
| 209 | - $dst[] = $r[0]; |
|
| 206 | + // si on recoit un tableau, on est en mode echappement |
|
| 207 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | + if (is_array($r)) { |
|
| 209 | + $dst[] = $r[0]; |
|
| 210 | 210 | |
| 211 | - return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | - } |
|
| 211 | + return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | - // et on RAZ les remplacements |
|
| 216 | - $r = [$src, $dst]; |
|
| 217 | - $src = $dst = []; |
|
| 214 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | + // et on RAZ les remplacements |
|
| 216 | + $r = [$src, $dst]; |
|
| 217 | + $src = $dst = []; |
|
| 218 | 218 | |
| 219 | - return $r; |
|
| 219 | + return $r; |
|
| 220 | 220 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -38,59 +38,59 @@ discard block |
||
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| 40 | 40 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 41 | - static $styliser_par_z; |
|
| 42 | - |
|
| 43 | - // s'assurer que le fond est licite |
|
| 44 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | - if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | - $fond = '404'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | - $modele = substr($fond, 8); |
|
| 51 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | - $fond = "modeles/$modele"; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | - $id_rubrique = 0; |
|
| 57 | - // Chercher le fond qui va servir de squelette |
|
| 58 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | - [$id_rubrique, $lang] = $r; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // trouver un squelette du nom demande |
|
| 63 | - // ne rien dire si on ne trouve pas, |
|
| 64 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | - $squelette = trouver_fond($fond, '', true); |
|
| 67 | - $ext = $squelette['extension']; |
|
| 68 | - |
|
| 69 | - $flux = [ |
|
| 70 | - 'args' => [ |
|
| 71 | - 'id_rubrique' => $id_rubrique, |
|
| 72 | - 'ext' => $ext, |
|
| 73 | - 'fond' => $fond, |
|
| 74 | - 'lang' => $lang, |
|
| 75 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | - 'connect' => $connect |
|
| 77 | - ], |
|
| 78 | - 'data' => $squelette['fond'], |
|
| 79 | - ]; |
|
| 80 | - |
|
| 81 | - if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | - if (!$styliser_par_z) { |
|
| 83 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | - } |
|
| 85 | - $flux = $styliser_par_z($flux); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $flux = styliser_par_objets($flux); |
|
| 89 | - |
|
| 90 | - // pipeline styliser |
|
| 91 | - $squelette = pipeline('styliser', $flux); |
|
| 92 | - |
|
| 93 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 41 | + static $styliser_par_z; |
|
| 42 | + |
|
| 43 | + // s'assurer que le fond est licite |
|
| 44 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | + if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | + $fond = '404'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | + $modele = substr($fond, 8); |
|
| 51 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | + $fond = "modeles/$modele"; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | + $id_rubrique = 0; |
|
| 57 | + // Chercher le fond qui va servir de squelette |
|
| 58 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | + [$id_rubrique, $lang] = $r; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // trouver un squelette du nom demande |
|
| 63 | + // ne rien dire si on ne trouve pas, |
|
| 64 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | + $squelette = trouver_fond($fond, '', true); |
|
| 67 | + $ext = $squelette['extension']; |
|
| 68 | + |
|
| 69 | + $flux = [ |
|
| 70 | + 'args' => [ |
|
| 71 | + 'id_rubrique' => $id_rubrique, |
|
| 72 | + 'ext' => $ext, |
|
| 73 | + 'fond' => $fond, |
|
| 74 | + 'lang' => $lang, |
|
| 75 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | + 'connect' => $connect |
|
| 77 | + ], |
|
| 78 | + 'data' => $squelette['fond'], |
|
| 79 | + ]; |
|
| 80 | + |
|
| 81 | + if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | + if (!$styliser_par_z) { |
|
| 83 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | + } |
|
| 85 | + $flux = $styliser_par_z($flux); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $flux = styliser_par_objets($flux); |
|
| 89 | + |
|
| 90 | + // pipeline styliser |
|
| 91 | + $squelette = pipeline('styliser', $flux); |
|
| 92 | + |
|
| 93 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -109,32 +109,32 @@ discard block |
||
| 109 | 109 | * Données du pipeline styliser |
| 110 | 110 | **/ |
| 111 | 111 | function styliser_par_objets($flux) { |
| 112 | - if ( |
|
| 113 | - test_espace_prive() |
|
| 114 | - && !($squelette = $flux['data']) |
|
| 115 | - && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | - && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | - ) { |
|
| 118 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | - $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | - $table_sql = table_objet_sql($table); |
|
| 121 | - $objets = lister_tables_objets_sql(); |
|
| 122 | - if (isset($objets[$table_sql])) { |
|
| 123 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | - $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | - $table = table_objet($type); |
|
| 129 | - $table_sql = table_objet_sql($table); |
|
| 130 | - $objets = lister_tables_objets_sql(); |
|
| 131 | - if (isset($objets[$table_sql])) { |
|
| 132 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $flux; |
|
| 112 | + if ( |
|
| 113 | + test_espace_prive() |
|
| 114 | + && !($squelette = $flux['data']) |
|
| 115 | + && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | + && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | + ) { |
|
| 118 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | + $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | + $table_sql = table_objet_sql($table); |
|
| 121 | + $objets = lister_tables_objets_sql(); |
|
| 122 | + if (isset($objets[$table_sql])) { |
|
| 123 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | + $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | + $table = table_objet($type); |
|
| 129 | + $table_sql = table_objet_sql($table); |
|
| 130 | + $objets = lister_tables_objets_sql(); |
|
| 131 | + if (isset($objets[$table_sql])) { |
|
| 132 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $flux; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -150,47 +150,47 @@ discard block |
||
| 150 | 150 | * @return array|false |
| 151 | 151 | */ |
| 152 | 152 | function quete_rubrique_fond($contexte) { |
| 153 | - static $liste_objets = null; |
|
| 154 | - static $quete = []; |
|
| 155 | - if (is_null($liste_objets)) { |
|
| 156 | - $liste_objets = []; |
|
| 157 | - include_spip('inc/urls'); |
|
| 158 | - include_spip('public/quete'); |
|
| 159 | - $l = urls_liste_objets(false); |
|
| 160 | - // placer la rubrique en tete des objets |
|
| 161 | - $l = array_diff($l, ['rubrique']); |
|
| 162 | - array_unshift($l, 'rubrique'); |
|
| 163 | - foreach ($l as $objet) { |
|
| 164 | - $id = id_table_objet($objet); |
|
| 165 | - if (!isset($liste_objets[$id])) { |
|
| 166 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | - if ($c === []) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $c = array_map('intval', $c); |
|
| 176 | - $s = serialize($c); |
|
| 177 | - if (isset($quete[$s])) { |
|
| 178 | - return $quete[$s]; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | - unset($c['id_rubrique']); |
|
| 183 | - $c = ['id_rubrique' => $r] + $c; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - foreach ($c as $_id => $id) { |
|
| 187 | - if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | - $lang = $row['lang'] ?? ''; |
|
| 189 | - if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | - return $quete[$s] = [$id, $lang]; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $quete[$s] = false; |
|
| 153 | + static $liste_objets = null; |
|
| 154 | + static $quete = []; |
|
| 155 | + if (is_null($liste_objets)) { |
|
| 156 | + $liste_objets = []; |
|
| 157 | + include_spip('inc/urls'); |
|
| 158 | + include_spip('public/quete'); |
|
| 159 | + $l = urls_liste_objets(false); |
|
| 160 | + // placer la rubrique en tete des objets |
|
| 161 | + $l = array_diff($l, ['rubrique']); |
|
| 162 | + array_unshift($l, 'rubrique'); |
|
| 163 | + foreach ($l as $objet) { |
|
| 164 | + $id = id_table_objet($objet); |
|
| 165 | + if (!isset($liste_objets[$id])) { |
|
| 166 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | + if ($c === []) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $c = array_map('intval', $c); |
|
| 176 | + $s = serialize($c); |
|
| 177 | + if (isset($quete[$s])) { |
|
| 178 | + return $quete[$s]; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | + unset($c['id_rubrique']); |
|
| 183 | + $c = ['id_rubrique' => $r] + $c; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + foreach ($c as $_id => $id) { |
|
| 187 | + if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | + $lang = $row['lang'] ?? ''; |
|
| 189 | + if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | + return $quete[$s] = [$id, $lang]; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $quete[$s] = false; |
|
| 196 | 196 | } |
@@ -10,187 +10,187 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function trace_query_start() { |
| 17 | - static $trace = '?'; |
|
| 18 | - if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | - if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | - $trace = true; |
|
| 21 | - } |
|
| 22 | - else { |
|
| 23 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | - // ou une requete SQL faite avant chargement de la session |
|
| 27 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | - } |
|
| 29 | - else { |
|
| 30 | - include_spip('inc/autoriser'); |
|
| 31 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | - // A fortiori quand on demande une trace |
|
| 33 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return $trace ? microtime() : 0; |
|
| 17 | + static $trace = '?'; |
|
| 18 | + if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | + if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | + $trace = true; |
|
| 21 | + } |
|
| 22 | + else { |
|
| 23 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | + // ou une requete SQL faite avant chargement de la session |
|
| 27 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | + } |
|
| 29 | + else { |
|
| 30 | + include_spip('inc/autoriser'); |
|
| 31 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | + // A fortiori quand on demande une trace |
|
| 33 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return $trace ? microtime() : 0; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 43 | - static $trace = '?'; |
|
| 44 | - if ($trace === '?') { |
|
| 45 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | - // ou une requete SQL faite avant chargement de la session |
|
| 49 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | - } |
|
| 51 | - else { |
|
| 52 | - include_spip('inc/autoriser'); |
|
| 53 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | - // A fortiori quand on demande une trace |
|
| 55 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($start) { |
|
| 60 | - $end = microtime(); |
|
| 61 | - [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | - if ($trace) { |
|
| 66 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | - if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return $result; |
|
| 43 | + static $trace = '?'; |
|
| 44 | + if ($trace === '?') { |
|
| 45 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | + // ou une requete SQL faite avant chargement de la session |
|
| 49 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + include_spip('inc/autoriser'); |
|
| 53 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | + // A fortiori quand on demande une trace |
|
| 55 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($start) { |
|
| 60 | + $end = microtime(); |
|
| 61 | + [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | + if ($trace) { |
|
| 66 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | + if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return $result; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 78 | - include_spip('inc/filtres_mini'); |
|
| 79 | - static $tt = 0, $nb = 0; |
|
| 80 | - |
|
| 81 | - $x = _request('var_mode_objet'); |
|
| 82 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | - if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - if ($serveur) { |
|
| 88 | - $boucle .= " ($serveur)"; |
|
| 89 | - } |
|
| 90 | - $boucle = "<b>$boucle</b>"; |
|
| 91 | - } else { |
|
| 92 | - if ($x) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $boucle = $contexte = ''; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $tt += $dt; |
|
| 99 | - $nb++; |
|
| 100 | - |
|
| 101 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | - $e = sql_explain($query, $serveur); |
|
| 103 | - $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 78 | + include_spip('inc/filtres_mini'); |
|
| 79 | + static $tt = 0, $nb = 0; |
|
| 80 | + |
|
| 81 | + $x = _request('var_mode_objet'); |
|
| 82 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | + if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + if ($serveur) { |
|
| 88 | + $boucle .= " ($serveur)"; |
|
| 89 | + } |
|
| 90 | + $boucle = "<b>$boucle</b>"; |
|
| 91 | + } else { |
|
| 92 | + if ($x) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $boucle = $contexte = ''; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $tt += $dt; |
|
| 99 | + $nb++; |
|
| 100 | + |
|
| 101 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | + $e = sql_explain($query, $serveur); |
|
| 103 | + $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | function chrono_requete($temps) { |
| 109 | - $total = 0; |
|
| 110 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | - $t = $q = $n = $d = []; |
|
| 112 | - // Totaliser les temps et completer le Explain |
|
| 113 | - foreach ($temps as $key => $v) { |
|
| 114 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | - if (is_array($contexte)) { |
|
| 116 | - $k = ($contexte[0] . " $boucle"); |
|
| 117 | - include_spip('public/compiler'); |
|
| 118 | - $env = reconstruire_contexte_compil($contexte); |
|
| 119 | - } else { |
|
| 120 | - $k = $env = $boucle; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $total += $dt; |
|
| 124 | - $t[$key] = $dt; |
|
| 125 | - $q[$key] = $nb; |
|
| 126 | - if (!isset($d[$k])) { |
|
| 127 | - $d[$k] = 0; |
|
| 128 | - $n[$k] = 0; |
|
| 129 | - } |
|
| 130 | - $d[$k] += $dt; |
|
| 131 | - ++$n[$k]; |
|
| 132 | - |
|
| 133 | - if (!is_array($explain)) { |
|
| 134 | - $explain = []; |
|
| 135 | - } |
|
| 136 | - foreach ($explain as $j => $v) { |
|
| 137 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | - . str_replace(';', '<br />', (string) $v) |
|
| 139 | - . '</td></tr>'; |
|
| 140 | - } |
|
| 141 | - $e = "<table class='explain'>" |
|
| 142 | - . '<caption>' |
|
| 143 | - . $query |
|
| 144 | - . '</caption>' |
|
| 145 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | - . implode('', $explain) |
|
| 149 | - . '</table>'; |
|
| 150 | - |
|
| 151 | - $temps[$key] = [$e, $env, $k]; |
|
| 152 | - } |
|
| 153 | - // Trier par temps d'execution decroissant |
|
| 154 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | - arsort($d); |
|
| 156 | - $i = 1; |
|
| 157 | - $t = []; |
|
| 158 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | - foreach ($temps as $k => $v) { |
|
| 160 | - $titre = strip_tags((string) $v[2]); |
|
| 161 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | - $href = str_replace("\\'", ''', $href); |
|
| 163 | - |
|
| 164 | - if (!isset($t[$v[2]])) { |
|
| 165 | - $t[$v[2]] = []; |
|
| 166 | - } |
|
| 167 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | - . '</span>' |
|
| 170 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | - $i++; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($d['']) { |
|
| 175 | - $d[$hors] = $d['']; |
|
| 176 | - $n[$hors] = $n['']; |
|
| 177 | - $t[$hors] = $t['']; |
|
| 178 | - } |
|
| 179 | - unset($d['']); |
|
| 180 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | - foreach ($d as $k => $v) { |
|
| 182 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | - . implode('', $t[$k]); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $navigation = [ |
|
| 187 | - _T('zbug_statistiques'), |
|
| 188 | - '<tr><td>' |
|
| 189 | - . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | - . "</td></tr>\n" |
|
| 191 | - . (# _request('var_mode_objet') ? '' : |
|
| 192 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | - ]; |
|
| 194 | - |
|
| 195 | - return [$temps, $navigation]; |
|
| 109 | + $total = 0; |
|
| 110 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | + $t = $q = $n = $d = []; |
|
| 112 | + // Totaliser les temps et completer le Explain |
|
| 113 | + foreach ($temps as $key => $v) { |
|
| 114 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | + if (is_array($contexte)) { |
|
| 116 | + $k = ($contexte[0] . " $boucle"); |
|
| 117 | + include_spip('public/compiler'); |
|
| 118 | + $env = reconstruire_contexte_compil($contexte); |
|
| 119 | + } else { |
|
| 120 | + $k = $env = $boucle; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $total += $dt; |
|
| 124 | + $t[$key] = $dt; |
|
| 125 | + $q[$key] = $nb; |
|
| 126 | + if (!isset($d[$k])) { |
|
| 127 | + $d[$k] = 0; |
|
| 128 | + $n[$k] = 0; |
|
| 129 | + } |
|
| 130 | + $d[$k] += $dt; |
|
| 131 | + ++$n[$k]; |
|
| 132 | + |
|
| 133 | + if (!is_array($explain)) { |
|
| 134 | + $explain = []; |
|
| 135 | + } |
|
| 136 | + foreach ($explain as $j => $v) { |
|
| 137 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | + . str_replace(';', '<br />', (string) $v) |
|
| 139 | + . '</td></tr>'; |
|
| 140 | + } |
|
| 141 | + $e = "<table class='explain'>" |
|
| 142 | + . '<caption>' |
|
| 143 | + . $query |
|
| 144 | + . '</caption>' |
|
| 145 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | + . implode('', $explain) |
|
| 149 | + . '</table>'; |
|
| 150 | + |
|
| 151 | + $temps[$key] = [$e, $env, $k]; |
|
| 152 | + } |
|
| 153 | + // Trier par temps d'execution decroissant |
|
| 154 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | + arsort($d); |
|
| 156 | + $i = 1; |
|
| 157 | + $t = []; |
|
| 158 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | + foreach ($temps as $k => $v) { |
|
| 160 | + $titre = strip_tags((string) $v[2]); |
|
| 161 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | + $href = str_replace("\\'", ''', $href); |
|
| 163 | + |
|
| 164 | + if (!isset($t[$v[2]])) { |
|
| 165 | + $t[$v[2]] = []; |
|
| 166 | + } |
|
| 167 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | + . '</span>' |
|
| 170 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | + $i++; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($d['']) { |
|
| 175 | + $d[$hors] = $d['']; |
|
| 176 | + $n[$hors] = $n['']; |
|
| 177 | + $t[$hors] = $t['']; |
|
| 178 | + } |
|
| 179 | + unset($d['']); |
|
| 180 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | + foreach ($d as $k => $v) { |
|
| 182 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | + . implode('', $t[$k]); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $navigation = [ |
|
| 187 | + _T('zbug_statistiques'), |
|
| 188 | + '<tr><td>' |
|
| 189 | + . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | + . "</td></tr>\n" |
|
| 191 | + . (# _request('var_mode_objet') ? '' : |
|
| 192 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | + ]; |
|
| 194 | + |
|
| 195 | + return [$temps, $navigation]; |
|
| 196 | 196 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 35 | 35 | */ |
| 36 | 36 | function decompose_champ_id_objet($champ) { |
| 37 | - if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | - } |
|
| 37 | + if ($champ !== 'id_objet' && preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 38 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - return $champ; |
|
| 41 | + return $champ; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 58 | 58 | */ |
| 59 | 59 | function trouver_champs_decomposes($champ, $desc): array { |
| 60 | - if ( |
|
| 61 | - !is_array($desc) |
|
| 62 | - || array_key_exists($champ, $desc['field']) |
|
| 63 | - ) { |
|
| 64 | - return [$champ]; |
|
| 65 | - } |
|
| 66 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | - array_pop($decompose); |
|
| 69 | - if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | - return $decompose; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return [$champ]; |
|
| 60 | + if ( |
|
| 61 | + !is_array($desc) |
|
| 62 | + || array_key_exists($champ, $desc['field']) |
|
| 63 | + ) { |
|
| 64 | + return [$champ]; |
|
| 65 | + } |
|
| 66 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 67 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 68 | + array_pop($decompose); |
|
| 69 | + if (count(array_intersect($decompose, array_keys($desc['field']))) === count($decompose)) { |
|
| 70 | + return $decompose; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return [$champ]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | * Alias de la table de jointure (Lx) |
| 102 | 102 | */ |
| 103 | 103 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 104 | - // les jointures minimales sont optimales : |
|
| 105 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | - $max = 1; |
|
| 108 | - $res = false; |
|
| 109 | - $milieu_exclus = ($col ?: []); |
|
| 110 | - while ($max <= $max_liens && !$res) { |
|
| 111 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | - $max++; |
|
| 113 | - } |
|
| 114 | - if (!$res) { |
|
| 115 | - return ''; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - [$nom, $desc] = $depart; |
|
| 119 | - |
|
| 120 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 104 | + // les jointures minimales sont optimales : |
|
| 105 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 106 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 107 | + $max = 1; |
|
| 108 | + $res = false; |
|
| 109 | + $milieu_exclus = ($col ?: []); |
|
| 110 | + while ($max <= $max_liens && !$res) { |
|
| 111 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 112 | + $max++; |
|
| 113 | + } |
|
| 114 | + if (!$res) { |
|
| 115 | + return ''; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + [$nom, $desc] = $depart; |
|
| 119 | + |
|
| 120 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -156,78 +156,78 @@ discard block |
||
| 156 | 156 | * Alias de la table de jointure (Lx) |
| 157 | 157 | */ |
| 158 | 158 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 159 | - $a = []; |
|
| 160 | - $j = null; |
|
| 161 | - $n = null; |
|
| 162 | - static $num = []; |
|
| 163 | - $id_table = ''; |
|
| 164 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | - foreach ($res as $cle => $r) { |
|
| 166 | - [$d, $a, $j] = $r; |
|
| 167 | - if (!$id_table) { |
|
| 168 | - $id_table = $d; |
|
| 169 | - } |
|
| 170 | - $n = ++$cpt; |
|
| 171 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | - [$j1, $j2, $obj, $type] = $j; |
|
| 173 | - // trouver de quel cote est (id_objet,objet) |
|
| 174 | - $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | - $boucle->where["JOIN-L$n"] = |
|
| 179 | - $echap ? |
|
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | - : |
|
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 183 | - $boucle->join["L$n"] = |
|
| 184 | - $echap ? |
|
| 185 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | - : |
|
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | - } else { |
|
| 189 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | - } |
|
| 191 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - // pas besoin de group by |
|
| 196 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | - // si une seule jointure et sur une table avec primary key formee |
|
| 198 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | - |
|
| 201 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // pas de group by |
|
| 206 | - // si une seule jointure |
|
| 207 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | - if ( |
|
| 209 | - !$pk |
|
| 210 | - && count($boucle->from) == 2 |
|
| 211 | - && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | - && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | - ) { |
|
| 214 | - $pk = true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | - if (!$pk) { |
|
| 220 | - foreach ($groups as $id_prim) { |
|
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 222 | - if (!in_array($id_field, $boucle->group)) { |
|
| 223 | - $boucle->group[] = $id_field; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $boucle->modificateur['lien'] = true; |
|
| 229 | - |
|
| 230 | - return "L$n"; |
|
| 159 | + $a = []; |
|
| 160 | + $j = null; |
|
| 161 | + $n = null; |
|
| 162 | + static $num = []; |
|
| 163 | + $id_table = ''; |
|
| 164 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 165 | + foreach ($res as $cle => $r) { |
|
| 166 | + [$d, $a, $j] = $r; |
|
| 167 | + if (!$id_table) { |
|
| 168 | + $id_table = $d; |
|
| 169 | + } |
|
| 170 | + $n = ++$cpt; |
|
| 171 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 172 | + [$j1, $j2, $obj, $type] = $j; |
|
| 173 | + // trouver de quel cote est (id_objet,objet) |
|
| 174 | + $obj = $j1 == "id_$obj" ? "$id_table.$obj" : "L$n.$obj"; |
|
| 175 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 176 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 177 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 178 | + $boucle->where["JOIN-L$n"] = |
|
| 179 | + $echap ? |
|
| 180 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 181 | + : |
|
| 182 | + ['=',"$obj",sql_quote($type)]; |
|
| 183 | + $boucle->join["L$n"] = |
|
| 184 | + $echap ? |
|
| 185 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 186 | + : |
|
| 187 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 188 | + } else { |
|
| 189 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 190 | + } |
|
| 191 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + // pas besoin de group by |
|
| 196 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 197 | + // si une seule jointure et sur une table avec primary key formee |
|
| 198 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 199 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 200 | + |
|
| 201 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 202 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // pas de group by |
|
| 206 | + // si une seule jointure |
|
| 207 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 208 | + if ( |
|
| 209 | + !$pk |
|
| 210 | + && count($boucle->from) == 2 |
|
| 211 | + && isset($a[1]['key']['PRIMARY KEY']) |
|
| 212 | + && $j == $a[1]['key']['PRIMARY KEY'] |
|
| 213 | + ) { |
|
| 214 | + $pk = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 218 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 219 | + if (!$pk) { |
|
| 220 | + foreach ($groups as $id_prim) { |
|
| 221 | + $id_field = $nom . '.' . $id_prim; |
|
| 222 | + if (!in_array($id_field, $boucle->group)) { |
|
| 223 | + $boucle->group[] = $id_field; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $boucle->modificateur['lien'] = true; |
|
| 229 | + |
|
| 230 | + return "L$n"; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,18 +242,18 @@ discard block |
||
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | 244 | function nogroupby_if($depart, $arrivee, $col) { |
| 245 | - if ( |
|
| 246 | - empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | - || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | - || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | - ) { |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | - if (is_array($col)) { |
|
| 254 | - $col = implode(', *', $col); |
|
| 255 | - } // cas id_objet, objet |
|
| 256 | - return (preg_match("/^$id_primary, *$col$/", (string) $pk) || preg_match("/^$col, *$id_primary$/", (string) $pk)); |
|
| 245 | + if ( |
|
| 246 | + empty($arrivee['key']['PRIMARY KEY']) |
|
| 247 | + || !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 248 | + || empty($depart['key']['PRIMARY KEY']) |
|
| 249 | + ) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 253 | + if (is_array($col)) { |
|
| 254 | + $col = implode(', *', $col); |
|
| 255 | + } // cas id_objet, objet |
|
| 256 | + return (preg_match("/^$id_primary, *$col$/", (string) $pk) || preg_match("/^$col, *$id_primary$/", (string) $pk)); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -271,46 +271,46 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 273 | 273 | |
| 274 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 274 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 275 | 275 | |
| 276 | - // si cle primaire demandee, la privilegier |
|
| 277 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | - } |
|
| 276 | + // si cle primaire demandee, la privilegier |
|
| 277 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 278 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // les champs declares explicitement pour les jointures |
|
| 282 | - if (isset($desc['join'])) { |
|
| 283 | - return $desc['join']; |
|
| 284 | - } |
|
| 285 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 281 | + // les champs declares explicitement pour les jointures |
|
| 282 | + if (isset($desc['join'])) { |
|
| 283 | + return $desc['join']; |
|
| 284 | + } |
|
| 285 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 286 | 286 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 287 | 287 | |
| 288 | - // si pas de cle, c'est fichu |
|
| 289 | - if (!isset($desc['key'])) { |
|
| 290 | - return []; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // si cle primaire |
|
| 294 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // ici on se rabat sur les cles secondaires, |
|
| 299 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | - |
|
| 303 | - $join = []; |
|
| 304 | - foreach ($desc['key'] as $v) { |
|
| 305 | - $join = split_key($v, $join); |
|
| 306 | - } |
|
| 307 | - foreach ($join as $k) { |
|
| 308 | - if (in_array($k, $nojoin)) { |
|
| 309 | - unset($join[$k]); |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $join; |
|
| 288 | + // si pas de cle, c'est fichu |
|
| 289 | + if (!isset($desc['key'])) { |
|
| 290 | + return []; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // si cle primaire |
|
| 294 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 295 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // ici on se rabat sur les cles secondaires, |
|
| 299 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 300 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 301 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 302 | + |
|
| 303 | + $join = []; |
|
| 304 | + foreach ($desc['key'] as $v) { |
|
| 305 | + $join = split_key($v, $join); |
|
| 306 | + } |
|
| 307 | + foreach ($join as $k) { |
|
| 308 | + if (in_array($k, $nojoin)) { |
|
| 309 | + unset($join[$k]); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $join; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,14 +321,14 @@ discard block |
||
| 321 | 321 | * @return array |
| 322 | 322 | */ |
| 323 | 323 | function split_key($v, $join = []) { |
| 324 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | - if (str_contains((string) $k, '(')) { |
|
| 326 | - $k = explode('(', (string) $k); |
|
| 327 | - $k = trim(reset($k)); |
|
| 328 | - } |
|
| 329 | - $join[$k] = $k; |
|
| 330 | - } |
|
| 331 | - return $join; |
|
| 324 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 325 | + if (str_contains((string) $k, '(')) { |
|
| 326 | + $k = explode('(', (string) $k); |
|
| 327 | + $k = trim(reset($k)); |
|
| 328 | + } |
|
| 329 | + $join[$k] = $k; |
|
| 330 | + } |
|
| 331 | + return $join; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -351,134 +351,134 @@ discard block |
||
| 351 | 351 | * @return array |
| 352 | 352 | */ |
| 353 | 353 | function calculer_chaine_jointures( |
| 354 | - &$boucle, |
|
| 355 | - $depart, |
|
| 356 | - $arrivee, |
|
| 357 | - $vu = [], |
|
| 358 | - $milieu_exclus = [], |
|
| 359 | - $max_liens = 5 |
|
| 354 | + &$boucle, |
|
| 355 | + $depart, |
|
| 356 | + $arrivee, |
|
| 357 | + $vu = [], |
|
| 358 | + $milieu_exclus = [], |
|
| 359 | + $max_liens = 5 |
|
| 360 | 360 | ) { |
| 361 | - static $trouver_table; |
|
| 362 | - if (!$trouver_table) { |
|
| 363 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (is_string($milieu_exclus)) { |
|
| 367 | - $milieu_exclus = [$milieu_exclus]; |
|
| 368 | - } |
|
| 369 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | - if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | - $milieu_exclus[] = 'objet'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - [$dnom, $ddesc] = $depart; |
|
| 376 | - [$anom, $adesc] = $arrivee; |
|
| 377 | - if ($vu === []) { |
|
| 378 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $akeys = []; |
|
| 383 | - foreach ($adesc['key'] as $k) { |
|
| 384 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | - $akeys = array_merge($akeys, preg_split('/,\s*/', (string) $k)); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | - |
|
| 391 | - // cles candidates au depart |
|
| 392 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | - // enlever les cles dde depart exclues par l'appel |
|
| 394 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | - |
|
| 396 | - $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | - |
|
| 398 | - if ($v) { |
|
| 399 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | - // id_objet,objet |
|
| 406 | - // si oui on la prend |
|
| 407 | - foreach ($akeys as $key) { |
|
| 408 | - $v = decompose_champ_id_objet($key); |
|
| 409 | - if (is_array($v)) { |
|
| 410 | - $objet = array_shift($v); // objet,'article' |
|
| 411 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } else { |
|
| 417 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | - // id_objet,objet a l'arrivee |
|
| 419 | - // si oui on la prend |
|
| 420 | - foreach ($keys as $key) { |
|
| 421 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | - $v = decompose_champ_id_objet($key); |
|
| 423 | - // id_objet,objet,'article' |
|
| 424 | - array_unshift($v, $key); |
|
| 425 | - // id_article,id_objet,objet,'article' |
|
| 426 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | - if ($max_liens <= 1) { |
|
| 432 | - return []; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // sinon essayer de passer par une autre table |
|
| 436 | - $new = $vu; |
|
| 437 | - foreach ($boucle->jointures as $v) { |
|
| 438 | - if ( |
|
| 439 | - $v |
|
| 440 | - && !in_array($v, $vu) |
|
| 441 | - && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | - && !in_array($def['table_sql'], $vu) |
|
| 443 | - ) { |
|
| 444 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | - // ie la cle de la jointure precedente |
|
| 446 | - $test_cles = $milieu_exclus; |
|
| 447 | - $new[] = $v; |
|
| 448 | - $max_iter = 50; // securite |
|
| 449 | - while ( |
|
| 450 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | - $boucle, |
|
| 452 | - $depart, |
|
| 453 | - [$v, $def], |
|
| 454 | - $vu, |
|
| 455 | - $test_cles, |
|
| 456 | - 1 |
|
| 457 | - )) && $max_iter-- |
|
| 458 | - ) { |
|
| 459 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | - $milieu = end($jointure_directe_possible); |
|
| 461 | - $exclure_fin = $milieu_exclus; |
|
| 462 | - if (is_string($milieu)) { |
|
| 463 | - $exclure_fin[] = $milieu; |
|
| 464 | - $test_cles[] = $milieu; |
|
| 465 | - } else { |
|
| 466 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | - } |
|
| 469 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | - if ($r) { |
|
| 473 | - array_unshift($r, $jointure_directe_possible); |
|
| 474 | - |
|
| 475 | - return $r; |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return []; |
|
| 361 | + static $trouver_table; |
|
| 362 | + if (!$trouver_table) { |
|
| 363 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (is_string($milieu_exclus)) { |
|
| 367 | + $milieu_exclus = [$milieu_exclus]; |
|
| 368 | + } |
|
| 369 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 370 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 371 | + if (in_array('id_objet', $milieu_exclus) && !in_array('objet', $milieu_exclus)) { |
|
| 372 | + $milieu_exclus[] = 'objet'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + [$dnom, $ddesc] = $depart; |
|
| 376 | + [$anom, $adesc] = $arrivee; |
|
| 377 | + if ($vu === []) { |
|
| 378 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 379 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $akeys = []; |
|
| 383 | + foreach ($adesc['key'] as $k) { |
|
| 384 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 385 | + $akeys = array_merge($akeys, preg_split('/,\s*/', (string) $k)); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 389 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 390 | + |
|
| 391 | + // cles candidates au depart |
|
| 392 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 393 | + // enlever les cles dde depart exclues par l'appel |
|
| 394 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 395 | + |
|
| 396 | + $v = $keys ? array_intersect(array_values($keys), $akeys) : false; |
|
| 397 | + |
|
| 398 | + if ($v) { |
|
| 399 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 403 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 404 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 405 | + // id_objet,objet |
|
| 406 | + // si oui on la prend |
|
| 407 | + foreach ($akeys as $key) { |
|
| 408 | + $v = decompose_champ_id_objet($key); |
|
| 409 | + if (is_array($v)) { |
|
| 410 | + $objet = array_shift($v); // objet,'article' |
|
| 411 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 412 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 413 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } else { |
|
| 417 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 418 | + // id_objet,objet a l'arrivee |
|
| 419 | + // si oui on la prend |
|
| 420 | + foreach ($keys as $key) { |
|
| 421 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1 && count($v) == count(array_intersect($v, $akeys))) { |
|
| 422 | + $v = decompose_champ_id_objet($key); |
|
| 423 | + // id_objet,objet,'article' |
|
| 424 | + array_unshift($v, $key); |
|
| 425 | + // id_article,id_objet,objet,'article' |
|
| 426 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 431 | + if ($max_liens <= 1) { |
|
| 432 | + return []; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // sinon essayer de passer par une autre table |
|
| 436 | + $new = $vu; |
|
| 437 | + foreach ($boucle->jointures as $v) { |
|
| 438 | + if ( |
|
| 439 | + $v |
|
| 440 | + && !in_array($v, $vu) |
|
| 441 | + && ($def = $trouver_table($v, $boucle->sql_serveur)) |
|
| 442 | + && !in_array($def['table_sql'], $vu) |
|
| 443 | + ) { |
|
| 444 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 445 | + // ie la cle de la jointure precedente |
|
| 446 | + $test_cles = $milieu_exclus; |
|
| 447 | + $new[] = $v; |
|
| 448 | + $max_iter = 50; // securite |
|
| 449 | + while ( |
|
| 450 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 451 | + $boucle, |
|
| 452 | + $depart, |
|
| 453 | + [$v, $def], |
|
| 454 | + $vu, |
|
| 455 | + $test_cles, |
|
| 456 | + 1 |
|
| 457 | + )) && $max_iter-- |
|
| 458 | + ) { |
|
| 459 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 460 | + $milieu = end($jointure_directe_possible); |
|
| 461 | + $exclure_fin = $milieu_exclus; |
|
| 462 | + if (is_string($milieu)) { |
|
| 463 | + $exclure_fin[] = $milieu; |
|
| 464 | + $test_cles[] = $milieu; |
|
| 465 | + } else { |
|
| 466 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 467 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 468 | + } |
|
| 469 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 470 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 471 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 472 | + if ($r) { |
|
| 473 | + array_unshift($r, $jointure_directe_possible); |
|
| 474 | + |
|
| 475 | + return $r; |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return []; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -489,18 +489,18 @@ discard block |
||
| 489 | 489 | * @return array |
| 490 | 490 | */ |
| 491 | 491 | function trouver_cles_table($keys) { |
| 492 | - $res = []; |
|
| 493 | - foreach ($keys as $v) { |
|
| 494 | - if (!strpos((string) $v, ',')) { |
|
| 495 | - $res[$v] = 1; |
|
| 496 | - } else { |
|
| 497 | - foreach (preg_split('/\s*,\s*/', (string) $v) as $k) { |
|
| 498 | - $res[$k] = 1; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - return array_keys($res); |
|
| 492 | + $res = []; |
|
| 493 | + foreach ($keys as $v) { |
|
| 494 | + if (!strpos((string) $v, ',')) { |
|
| 495 | + $res[$v] = 1; |
|
| 496 | + } else { |
|
| 497 | + foreach (preg_split('/\s*,\s*/', (string) $v) as $k) { |
|
| 498 | + $res[$k] = 1; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + return array_keys($res); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -527,34 +527,34 @@ discard block |
||
| 527 | 527 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 528 | 528 | */ |
| 529 | 529 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 530 | - static $trouver_table = ''; |
|
| 531 | - if (!$trouver_table) { |
|
| 532 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - if (!is_array($cle)) { |
|
| 536 | - $cle = [$cle]; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - foreach ($tables as $k => $table) { |
|
| 540 | - if ( |
|
| 541 | - $table |
|
| 542 | - && ($desc = $trouver_table($table, $connect)) |
|
| 543 | - && ( |
|
| 544 | - isset($desc['field']) |
|
| 545 | - && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | - && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - return [ |
|
| 550 | - 'desc' => $desc, |
|
| 551 | - 'table' => $desc['table'], |
|
| 552 | - 'alias' => $k, |
|
| 553 | - ]; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return false; |
|
| 530 | + static $trouver_table = ''; |
|
| 531 | + if (!$trouver_table) { |
|
| 532 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + if (!is_array($cle)) { |
|
| 536 | + $cle = [$cle]; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + foreach ($tables as $k => $table) { |
|
| 540 | + if ( |
|
| 541 | + $table |
|
| 542 | + && ($desc = $trouver_table($table, $connect)) |
|
| 543 | + && ( |
|
| 544 | + isset($desc['field']) |
|
| 545 | + && count(array_intersect($cle, array_keys($desc['field']))) === count($cle) |
|
| 546 | + && ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + return [ |
|
| 550 | + 'desc' => $desc, |
|
| 551 | + 'table' => $desc['table'], |
|
| 552 | + 'alias' => $k, |
|
| 553 | + ]; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return false; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -580,52 +580,52 @@ discard block |
||
| 580 | 580 | */ |
| 581 | 581 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 582 | 582 | |
| 583 | - // support de la recherche multi champ : |
|
| 584 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | - if (!is_array($cle)) { |
|
| 588 | - $cle = [$cle]; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - // au premier coup, on essaye de decomposer, si possible |
|
| 596 | - if ( |
|
| 597 | - count($cle) == 1 |
|
| 598 | - && ($c = reset($cle)) |
|
| 599 | - && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | - ) { |
|
| 601 | - $desc = $boucle->show; |
|
| 602 | - |
|
| 603 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | - if (isset($desc['field'][$c])) { |
|
| 606 | - $cle = []; |
|
| 607 | - $cle[] = array_shift($decompose); // id_objet |
|
| 608 | - $cle[] = array_shift($decompose); // objet |
|
| 609 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | - } |
|
| 611 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | - else { |
|
| 615 | - $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | - foreach ($depart as $d) { |
|
| 617 | - $cle = []; |
|
| 618 | - $cle[] = array_shift($decompose); // id_objet |
|
| 619 | - $cle[] = array_shift($decompose); // objet |
|
| 620 | - $cle[] = $d; |
|
| 621 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | - return $ext; |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - return ''; |
|
| 583 | + // support de la recherche multi champ : |
|
| 584 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 585 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 586 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 587 | + if (!is_array($cle)) { |
|
| 588 | + $cle = [$cle]; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 592 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + // au premier coup, on essaye de decomposer, si possible |
|
| 596 | + if ( |
|
| 597 | + count($cle) == 1 |
|
| 598 | + && ($c = reset($cle)) |
|
| 599 | + && is_array($decompose = decompose_champ_id_objet($c)) |
|
| 600 | + ) { |
|
| 601 | + $desc = $boucle->show; |
|
| 602 | + |
|
| 603 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 604 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 605 | + if (isset($desc['field'][$c])) { |
|
| 606 | + $cle = []; |
|
| 607 | + $cle[] = array_shift($decompose); // id_objet |
|
| 608 | + $cle[] = array_shift($decompose); // objet |
|
| 609 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 610 | + } |
|
| 611 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 612 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 613 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 614 | + else { |
|
| 615 | + $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 616 | + foreach ($depart as $d) { |
|
| 617 | + $cle = []; |
|
| 618 | + $cle[] = array_shift($decompose); // id_objet |
|
| 619 | + $cle[] = array_shift($decompose); // objet |
|
| 620 | + $cle[] = $d; |
|
| 621 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 622 | + return $ext; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + return ''; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -657,21 +657,21 @@ discard block |
||
| 657 | 657 | * @return string |
| 658 | 658 | */ |
| 659 | 659 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 660 | - if ($jointures === false) { |
|
| 661 | - $jointures = $boucle->jointures; |
|
| 662 | - } |
|
| 663 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | - // mais pas poour construire la jointure ensuite |
|
| 665 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | - if ($arrivee) { |
|
| 667 | - $desc = $boucle->show; |
|
| 668 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | - if ($cle) { |
|
| 671 | - return $cle; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | - |
|
| 676 | - return ''; |
|
| 660 | + if ($jointures === false) { |
|
| 661 | + $jointures = $boucle->jointures; |
|
| 662 | + } |
|
| 663 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 664 | + // mais pas poour construire la jointure ensuite |
|
| 665 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 666 | + if ($arrivee) { |
|
| 667 | + $desc = $boucle->show; |
|
| 668 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 669 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 670 | + if ($cle) { |
|
| 671 | + return $cle; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 675 | + |
|
| 676 | + return ''; |
|
| 677 | 677 | } |