@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = $args[0] ?? ''; |
|
| 55 | + $url = $args[0] ?? ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -73,5 +73,5 @@ |
||
| 73 | 73 | return ''; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url='.rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * - chaîne vide sinon. |
| 73 | 73 | */ |
| 74 | 74 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 75 | - [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | - include_spip('action/inscrire_auteur'); |
|
| 77 | - $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 75 | + [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | + include_spip('action/inscrire_auteur'); |
|
| 77 | + $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 78 | 78 | |
| 79 | - return $mode ? [$mode, $id, $retour] : ''; |
|
| 79 | + return $mode ? [$mode, $id, $retour] : ''; |
|
| 80 | 80 | } |
@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | - |
|
| 31 | - if ($struct->jointures_explicites) { |
|
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | - } |
|
| 34 | - if ($struct->table_optionnelle) { |
|
| 35 | - $type .= '?'; |
|
| 36 | - } |
|
| 37 | - // Revoir le cas de la boucle recursive |
|
| 38 | - |
|
| 39 | - $crit = $struct->param; |
|
| 40 | - if ($crit and !is_array($crit[0])) { |
|
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 42 | - } |
|
| 43 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | - |
|
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 46 | - |
|
| 47 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | + |
|
| 31 | + if ($struct->jointures_explicites) { |
|
| 32 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | + } |
|
| 34 | + if ($struct->table_optionnelle) { |
|
| 35 | + $type .= '?'; |
|
| 36 | + } |
|
| 37 | + // Revoir le cas de la boucle recursive |
|
| 38 | + |
|
| 39 | + $crit = $struct->param; |
|
| 40 | + if ($crit and !is_array($crit[0])) { |
|
| 41 | + $type = strtolower($type) . array_shift($crit); |
|
| 42 | + } |
|
| 43 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | + |
|
| 45 | + $f = 'format_boucle_' . $fmt; |
|
| 46 | + |
|
| 47 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 51 | - $res = []; |
|
| 52 | - foreach ($struct->param ?: [] as $couple) { |
|
| 53 | - array_shift($couple); |
|
| 54 | - foreach ($couple as $v) { |
|
| 55 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 61 | - |
|
| 62 | - return $f($file, $res, $prof); |
|
| 51 | + $res = []; |
|
| 52 | + foreach ($struct->param ?: [] as $couple) { |
|
| 53 | + array_shift($couple); |
|
| 54 | + foreach ($couple as $v) { |
|
| 55 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | + $f = 'format_inclure_' . $fmt; |
|
| 61 | + |
|
| 62 | + return $f($file, $res, $prof); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 66 | + $f = 'format_texte_' . $fmt; |
|
| 67 | 67 | |
| 68 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 68 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 72 | + $f = 'format_polyglotte_' . $fmt; |
|
| 73 | 73 | |
| 74 | - return $f($struct->traductions, $prof); |
|
| 74 | + return $f($struct->traductions, $prof); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 78 | - $args = []; |
|
| 79 | - foreach ($struct->arg as $k => $v) { |
|
| 80 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | - } |
|
| 78 | + $args = []; |
|
| 79 | + foreach ($struct->arg as $k => $v) { |
|
| 80 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 83 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | 84 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 85 | + $f = 'format_idiome_' . $fmt; |
|
| 86 | 86 | |
| 87 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 87 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 91 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | - $args = $filtres = ''; |
|
| 94 | - if ($p = $struct->param) { |
|
| 95 | - if ($p[0][0] === '') { |
|
| 96 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | - } |
|
| 98 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | - } |
|
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 101 | - |
|
| 102 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 91 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | + $args = $filtres = ''; |
|
| 94 | + if ($p = $struct->param) { |
|
| 95 | + if ($p[0][0] === '') { |
|
| 96 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | + } |
|
| 98 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | + } |
|
| 100 | + $f = 'format_champ_' . $fmt; |
|
| 101 | + |
|
| 102 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 106 | - if (!is_array($sources)) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 110 | - $res = ''; |
|
| 111 | - foreach ($sources as $arg) { |
|
| 112 | - if (!is_array($arg)) { |
|
| 113 | - continue; // ne devrait pas arriver. |
|
| 114 | - } else { |
|
| 115 | - $r = array_shift($arg); |
|
| 116 | - } |
|
| 117 | - $args = []; |
|
| 118 | - foreach ($arg as $v) { |
|
| 119 | - // cas des arguments entoures de ' ou " |
|
| 120 | - if ( |
|
| 121 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 106 | + if (!is_array($sources)) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + $f = 'format_liste_' . $fmt; |
|
| 110 | + $res = ''; |
|
| 111 | + foreach ($sources as $arg) { |
|
| 112 | + if (!is_array($arg)) { |
|
| 113 | + continue; // ne devrait pas arriver. |
|
| 114 | + } else { |
|
| 115 | + $r = array_shift($arg); |
|
| 116 | + } |
|
| 117 | + $args = []; |
|
| 118 | + foreach ($arg as $v) { |
|
| 119 | + // cas des arguments entoures de ' ou " |
|
| 120 | + if ( |
|
| 121 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,93 +141,93 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = []; |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ( |
|
| 158 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | - and $v[0]->type == 'texte' |
|
| 160 | - and $v[0]->apres |
|
| 161 | - ) { |
|
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | - } else { |
|
| 164 | - $res2 = []; |
|
| 165 | - foreach ($v as $k => $p) { |
|
| 166 | - if ( |
|
| 167 | - isset($p->type) |
|
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | - ) { |
|
| 170 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 171 | - $res2[] = [$p->type, $r]; |
|
| 172 | - } else { |
|
| 173 | - spip_log("critere $i / $k mal forme"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - $args[] = $res2; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $res .= $f($args); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = []; |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ( |
|
| 158 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | + and $v[0]->type == 'texte' |
|
| 160 | + and $v[0]->apres |
|
| 161 | + ) { |
|
| 162 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | + } else { |
|
| 164 | + $res2 = []; |
|
| 165 | + foreach ($v as $k => $p) { |
|
| 166 | + if ( |
|
| 167 | + isset($p->type) |
|
| 168 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | + ) { |
|
| 170 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 171 | + $res2[] = [$p->type, $r]; |
|
| 172 | + } else { |
|
| 173 | + spip_log("critere $i / $k mal forme"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + $args[] = $res2; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $res .= $f($args); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $res; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 187 | - if (!is_array($liste)) { |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 190 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | - $contenu = []; |
|
| 192 | - foreach ($liste as $k => $p) { |
|
| 193 | - if (!isset($p->type)) { |
|
| 194 | - continue; |
|
| 195 | - } #?????? |
|
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 197 | - $next = $liste[$k + 1] ?? false; |
|
| 198 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | - // contenait des args et s'il est suivi d'espaces, |
|
| 200 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | - |
|
| 202 | - if ( |
|
| 203 | - $next |
|
| 204 | - and ($next->type == 'texte') |
|
| 205 | - and $p->type == 'champ' |
|
| 206 | - and !$p->apres |
|
| 207 | - and !$p->avant |
|
| 208 | - and $p->fonctions |
|
| 209 | - ) { |
|
| 210 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | - if ($n) { |
|
| 212 | - $champ = new Texte(); |
|
| 213 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | - $champ->ligne = $p->ligne; |
|
| 215 | - $p->apres = [$champ]; |
|
| 216 | - $next->texte = substr($next->texte, $n); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | - } |
|
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 222 | - |
|
| 223 | - return $f($contenu); |
|
| 187 | + if (!is_array($liste)) { |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | + $contenu = []; |
|
| 192 | + foreach ($liste as $k => $p) { |
|
| 193 | + if (!isset($p->type)) { |
|
| 194 | + continue; |
|
| 195 | + } #?????? |
|
| 196 | + $d = 'decompiler_' . $p->type; |
|
| 197 | + $next = $liste[$k + 1] ?? false; |
|
| 198 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | + // contenait des args et s'il est suivi d'espaces, |
|
| 200 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | + |
|
| 202 | + if ( |
|
| 203 | + $next |
|
| 204 | + and ($next->type == 'texte') |
|
| 205 | + and $p->type == 'champ' |
|
| 206 | + and !$p->apres |
|
| 207 | + and !$p->avant |
|
| 208 | + and $p->fonctions |
|
| 209 | + ) { |
|
| 210 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | + if ($n) { |
|
| 212 | + $champ = new Texte(); |
|
| 213 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | + $champ->ligne = $p->ligne; |
|
| 215 | + $p->apres = [$champ]; |
|
| 216 | + $next->texte = substr($next->texte, $n); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | + } |
|
| 221 | + $f = 'format_suite_' . $fmt; |
|
| 222 | + |
|
| 223 | + return $f($contenu); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | - return "'$fmt'?"; |
|
| 229 | - } |
|
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 227 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | + return "'$fmt'?"; |
|
| 229 | + } |
|
| 230 | + $f = 'decompiler_' . $quoi; |
|
| 231 | 231 | |
| 232 | - return $f($liste, $fmt, $prof); |
|
| 232 | + return $f($liste, $fmt, $prof); |
|
| 233 | 233 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
| 30 | 30 | |
| 31 | 31 | if ($struct->jointures_explicites) { |
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 32 | + $type .= ' '.$struct->jointures_explicites; |
|
| 33 | 33 | } |
| 34 | 34 | if ($struct->table_optionnelle) { |
| 35 | 35 | $type .= '?'; |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $crit = $struct->param; |
| 40 | 40 | if ($crit and !is_array($crit[0])) { |
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 42 | 42 | } |
| 43 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 44 | 44 | |
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 46 | 46 | |
| 47 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 48 | 48 | } |
@@ -55,21 +55,20 @@ discard block |
||
| 55 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 61 | 60 | |
| 62 | 61 | return $f($file, $res, $prof); |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 67 | 66 | |
| 68 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 73 | 72 | |
| 74 | 73 | return $f($struct->traductions, $prof); |
| 75 | 74 | } |
@@ -82,7 +81,7 @@ discard block |
||
| 82 | 81 | |
| 83 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 84 | 83 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 86 | 85 | |
| 87 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 88 | 87 | } |
@@ -97,7 +96,7 @@ discard block |
||
| 97 | 96 | } |
| 98 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 99 | 98 | } |
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 101 | 100 | |
| 102 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 103 | 102 | } |
@@ -106,7 +105,7 @@ discard block |
||
| 106 | 105 | if (!is_array($sources)) { |
| 107 | 106 | return ''; |
| 108 | 107 | } |
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 110 | 109 | $res = ''; |
| 111 | 110 | foreach ($sources as $arg) { |
| 112 | 111 | if (!is_array($arg)) { |
@@ -123,7 +122,7 @@ discard block |
||
| 123 | 122 | and (strlen($v[0]->apres) == 1) |
| 124 | 123 | and $v[0]->apres == $v[0]->avant |
| 125 | 124 | ) { |
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 125 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 127 | 126 | } else { |
| 128 | 127 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 129 | 128 | } |
@@ -146,7 +145,7 @@ discard block |
||
| 146 | 145 | return ''; |
| 147 | 146 | } |
| 148 | 147 | $res = ''; |
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 148 | + $f = 'format_critere_'.$fmt; |
|
| 150 | 149 | foreach ($sources as $crit) { |
| 151 | 150 | if (!is_array($crit)) { |
| 152 | 151 | continue; |
@@ -159,13 +158,13 @@ discard block |
||
| 159 | 158 | and $v[0]->type == 'texte' |
| 160 | 159 | and $v[0]->apres |
| 161 | 160 | ) { |
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 161 | + $args[] = [['texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres)]]; |
|
| 163 | 162 | } else { |
| 164 | 163 | $res2 = []; |
| 165 | 164 | foreach ($v as $k => $p) { |
| 166 | 165 | if ( |
| 167 | 166 | isset($p->type) |
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 169 | 168 | ) { |
| 170 | 169 | $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
| 171 | 170 | $res2[] = [$p->type, $r]; |
@@ -193,7 +192,7 @@ discard block |
||
| 193 | 192 | if (!isset($p->type)) { |
| 194 | 193 | continue; |
| 195 | 194 | } #?????? |
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 195 | + $d = 'decompiler_'.$p->type; |
|
| 197 | 196 | $next = $liste[$k + 1] ?? false; |
| 198 | 197 | // Forcer le champ etendu si son source (pas les reecritures) |
| 199 | 198 | // contenait des args et s'il est suivi d'espaces, |
@@ -218,16 +217,16 @@ discard block |
||
| 218 | 217 | } |
| 219 | 218 | $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
| 220 | 219 | } |
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 220 | + $f = 'format_suite_'.$fmt; |
|
| 222 | 221 | |
| 223 | 222 | return $f($contenu); |
| 224 | 223 | } |
| 225 | 224 | |
| 226 | 225 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 228 | 227 | return "'$fmt'?"; |
| 229 | 228 | } |
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 229 | + $f = 'decompiler_'.$quoi; |
|
| 231 | 230 | |
| 232 | 231 | return $f($liste, $fmt, $prof); |
| 233 | 232 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 60 | 60 | |
| 61 | 61 | // si squelette est deja compile et perenne, le charger |
| 62 | 62 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | #} |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 73 | 73 | include_once $lib; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | eval("return true; $f ;"); |
| 98 | 98 | } catch (\ParseError $e) { |
| 99 | 99 | // Code syntaxiquement faux (critere etc mal programme') |
| 100 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 101 | 101 | erreur_squelette($msg, $boucle); |
| 102 | 102 | // continuer pour trouver d'autres fautes eventuelles |
| 103 | 103 | // mais prevenir que c'est mort |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 127 | 127 | // Tracer ce qui vient d'etre compile |
| 128 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 129 | 129 | |
| 130 | 130 | // si c'est ce que demande le debusqueur, lui passer la main |
| 131 | 131 | if ( |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | $code = " |
| 150 | 150 | /* |
| 151 | 151 | * Squelette : $sourcefile |
| 152 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 153 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 154 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 152 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 153 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 154 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 155 | 155 | */ '; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 158 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 159 | 159 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 160 | 160 | ecrire_fichier($phpfile, $code); |
| 161 | 161 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 220 | 220 | |
| 221 | 221 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 222 | - $headers[$j] .= '|' . $r[3]; |
|
| 222 | + $headers[$j] .= '|'.$r[3]; |
|
| 223 | 223 | } else { |
| 224 | 224 | $headers[$j] = $r[3]; |
| 225 | 225 | } |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | // S'agit-il d'un resultat constant ou contenant du code php |
| 229 | 229 | $process_ins = ( |
| 230 | - strpos($corps, '<' . '?') === false |
|
| 230 | + strpos($corps, '<'.'?') === false |
|
| 231 | 231 | or |
| 232 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 233 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 232 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 233 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 234 | 234 | ) |
| 235 | 235 | ? 'html' |
| 236 | 236 | : 'php'; |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | if ($process_ins == 'html') { |
| 261 | 261 | $skel['process_ins'] = ( |
| 262 | - strpos($corps, '<' . '?') === false |
|
| 262 | + strpos($corps, '<'.'?') === false |
|
| 263 | 263 | or |
| 264 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 265 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 264 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 265 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 266 | 266 | ) |
| 267 | 267 | ? 'html' |
| 268 | 268 | : 'php'; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // |
| 281 | 281 | |
| 282 | 282 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 283 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 283 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 284 | 284 | include_once("%s"); |
| 285 | 285 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 286 | 286 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | // pas de lien symbolique sous Windows |
| 312 | 312 | and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
| 313 | 313 | ) { |
| 314 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 314 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $lang = $context_compil[4]; |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | |
| 322 | 322 | $args = array_map('argumenter_squelette', $args); |
| 323 | 323 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 324 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 324 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 325 | 325 | } |
| 326 | 326 | $args = join(', ', $args); |
| 327 | 327 | |
@@ -355,14 +355,14 @@ discard block |
||
| 355 | 355 | if (is_object($v)) { |
| 356 | 356 | return var_export($v, true); |
| 357 | 357 | } elseif (!is_array($v)) { |
| 358 | - return "'" . texte_script((string) $v) . "'"; |
|
| 358 | + return "'".texte_script((string) $v)."'"; |
|
| 359 | 359 | } else { |
| 360 | 360 | $out = []; |
| 361 | 361 | foreach ($v as $k => $val) { |
| 362 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 362 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - return 'array(' . join(', ', $out) . ')'; |
|
| 365 | + return 'array('.join(', ', $out).')'; |
|
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Y a-t-il une fonction de traitement des arguments ? |
| 443 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 443 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 444 | 444 | |
| 445 | 445 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 446 | 446 | |
@@ -450,18 +450,18 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | // verifier que la fonction dyn est la, |
| 452 | 452 | // sinon se replier sur la generique si elle existe |
| 453 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 453 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 454 | 454 | if ( |
| 455 | 455 | $balise_generique = chercher_balise_generique($nom) |
| 456 | 456 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 457 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 458 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 457 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 458 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 459 | 459 | ) { |
| 460 | 460 | // et lui injecter en premier arg le nom de la balise |
| 461 | 461 | array_unshift($r, $nom); |
| 462 | 462 | $nom_balise = $nom_balise_generique; |
| 463 | 463 | if (!_DIR_RESTREINT) { |
| 464 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 464 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 465 | 465 | } |
| 466 | 466 | } else { |
| 467 | 467 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | $n = ''; |
| 564 | 564 | foreach (explode(',', $liste) as $val) { |
| 565 | 565 | if ($a = intval($val) and $val === strval($a)) { |
| 566 | - $n .= ',' . $val; |
|
| 566 | + $n .= ','.$val; |
|
| 567 | 567 | } |
| 568 | 568 | } |
| 569 | 569 | if (strlen($n)) { |
@@ -742,8 +742,8 @@ discard block |
||
| 742 | 742 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 743 | 743 | $i = 0; |
| 744 | 744 | do { |
| 745 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 746 | - [$sous[1] . ' AS id'], |
|
| 745 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 746 | + [$sous[1].' AS id'], |
|
| 747 | 747 | $from, |
| 748 | 748 | $from_type, |
| 749 | 749 | $wheresub, |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $id, |
| 757 | 757 | $serveur, |
| 758 | 758 | false |
| 759 | - ) . ')'); |
|
| 759 | + ).')'); |
|
| 760 | 760 | if (!$i) { |
| 761 | 761 | $i = 1; |
| 762 | 762 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | if ($sous[0] == 'SUBSELECT') { |
| 777 | 777 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 778 | 778 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 779 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 779 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 780 | 780 | $sous[1], # select |
| 781 | 781 | $sous[2], #from |
| 782 | 782 | [], #from_type |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | $id, |
| 792 | 792 | $serveur, |
| 793 | 793 | false |
| 794 | - ) . ')'); |
|
| 794 | + ).')'); |
|
| 795 | 795 | } |
| 796 | 796 | array_pop($where_simples); |
| 797 | 797 | } |
@@ -854,15 +854,15 @@ discard block |
||
| 854 | 854 | // sans recours a preg_match |
| 855 | 855 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 856 | 856 | $afrom[$t][$cle] = [ |
| 857 | - "\n" . |
|
| 858 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 857 | + "\n". |
|
| 858 | + ($from_type[$cle] ?? 'INNER').' JOIN', |
|
| 859 | 859 | $from[$cle], |
| 860 | 860 | "AS $cle", |
| 861 | 861 | 'ON (', |
| 862 | 862 | "$cle.$c", |
| 863 | 863 | '=', |
| 864 | 864 | "$t.$carr", |
| 865 | - ($and ? 'AND ' . $and : '') . |
|
| 865 | + ($and ? 'AND '.$and : ''). |
|
| 866 | 866 | ')' |
| 867 | 867 | ]; |
| 868 | 868 | if (isset($afrom[$cle])) { |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | $t = key($from); |
| 901 | 901 | $c = current($from); |
| 902 | 902 | reset($from); |
| 903 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 903 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 904 | 904 | if ( |
| 905 | 905 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 906 | 906 | calculer_jointnul($t, $select, $e) or |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | unset($afrom[$t][$nt]); |
| 919 | 919 | $afrom[$nt] = $afrom[$t]; |
| 920 | 920 | unset($afrom[$t]); |
| 921 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 921 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 922 | 922 | $t = $nfrom[4]; |
| 923 | 923 | $alias = ''; |
| 924 | 924 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -929,14 +929,14 @@ discard block |
||
| 929 | 929 | if ($newcle != $oldcle) { |
| 930 | 930 | // si l'ancienne cle etait deja dans le select avec un AS |
| 931 | 931 | // reprendre simplement ce AS |
| 932 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 932 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 933 | 933 | if (preg_match($as, implode(',', $select), $m)) { |
| 934 | 934 | $alias = ''; |
| 935 | 935 | } else { |
| 936 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 936 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 939 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 940 | 940 | $join = remplacer_jointnul($t, $join, $e); |
| 941 | 941 | $where = remplacer_jointnul($t, $where, $e); |
| 942 | 942 | $having = remplacer_jointnul($t, $having, $e); |
@@ -986,9 +986,9 @@ discard block |
||
| 986 | 986 | } else { |
| 987 | 987 | $exp = ''; |
| 988 | 988 | if (strtoupper($join) === 'AND') { |
| 989 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 989 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 990 | 990 | } else { |
| 991 | - return $exp . join($join, $v); |
|
| 991 | + return $exp.join($join, $v); |
|
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | 994 | } |
@@ -1054,6 +1054,6 @@ discard block |
||
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | 1056 | return $mime_type |
| 1057 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1058 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1057 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1058 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1059 | 1059 | } |
@@ -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 | include_spip('inc/texte'); |
@@ -42,233 +42,233 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 44 | 44 | |
| 45 | - $skel = null; |
|
| 46 | - $boucle = null; |
|
| 47 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | - |
|
| 49 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | - if (function_exists($nom)) { |
|
| 51 | - return $nom; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 55 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | - |
|
| 60 | - // si squelette est deja compile et perenne, le charger |
|
| 61 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | - include_once $phpfile; |
|
| 63 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | - ## eval('?'.'>'.$skel_code); |
|
| 67 | - # spip_log($skel_code, 'comp') |
|
| 68 | - #} |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | - include_once $lib; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | - |
|
| 77 | - if (function_exists($nom)) { |
|
| 78 | - return $nom; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // charger le source, si possible, et compiler |
|
| 82 | - $skel_code = ''; |
|
| 83 | - if (lire_fichier($source, $skel)) { |
|
| 84 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | - if (!$skel_code) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - foreach ($skel_code as $id => $boucle) { |
|
| 94 | - $f = $boucle->return; |
|
| 95 | - try { |
|
| 96 | - eval("return true; $f ;"); |
|
| 97 | - } catch (\ParseError $e) { |
|
| 98 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | - erreur_squelette($msg, $boucle); |
|
| 101 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | - // mais prevenir que c'est mort |
|
| 103 | - $nom = ''; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Contexte de compil inutile a present |
|
| 107 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | - $skel_code[$id] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $code = ''; |
|
| 112 | - if ($nom) { |
|
| 113 | - // Si le code est bon, concatener et mettre en cache |
|
| 114 | - if (function_exists($nom)) { |
|
| 115 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | - } else { |
|
| 117 | - // code semantiquement faux: bug du compilateur |
|
| 118 | - // $boucle est en fait ici la fct principale du squelette |
|
| 119 | - $msg = _T('zbug_erreur_compilation'); |
|
| 120 | - erreur_squelette($msg, $boucle); |
|
| 121 | - $nom = ''; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 126 | - // Tracer ce qui vient d'etre compile |
|
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | - |
|
| 129 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | - if ( |
|
| 131 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | - and (_request('var_mode_objet') == $nom) |
|
| 133 | - and (_request('var_mode_affiche') == 'code') |
|
| 134 | - ) { |
|
| 135 | - erreur_squelette(); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $nom ?: false; |
|
| 45 | + $skel = null; |
|
| 46 | + $boucle = null; |
|
| 47 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | + |
|
| 49 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | + if (function_exists($nom)) { |
|
| 51 | + return $nom; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 55 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | + |
|
| 60 | + // si squelette est deja compile et perenne, le charger |
|
| 61 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | + include_once $phpfile; |
|
| 63 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | + ## eval('?'.'>'.$skel_code); |
|
| 67 | + # spip_log($skel_code, 'comp') |
|
| 68 | + #} |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | + include_once $lib; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | + |
|
| 77 | + if (function_exists($nom)) { |
|
| 78 | + return $nom; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // charger le source, si possible, et compiler |
|
| 82 | + $skel_code = ''; |
|
| 83 | + if (lire_fichier($source, $skel)) { |
|
| 84 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | + if (!$skel_code) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + foreach ($skel_code as $id => $boucle) { |
|
| 94 | + $f = $boucle->return; |
|
| 95 | + try { |
|
| 96 | + eval("return true; $f ;"); |
|
| 97 | + } catch (\ParseError $e) { |
|
| 98 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | + erreur_squelette($msg, $boucle); |
|
| 101 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | + // mais prevenir que c'est mort |
|
| 103 | + $nom = ''; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Contexte de compil inutile a present |
|
| 107 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | + $skel_code[$id] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $code = ''; |
|
| 112 | + if ($nom) { |
|
| 113 | + // Si le code est bon, concatener et mettre en cache |
|
| 114 | + if (function_exists($nom)) { |
|
| 115 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | + } else { |
|
| 117 | + // code semantiquement faux: bug du compilateur |
|
| 118 | + // $boucle est en fait ici la fct principale du squelette |
|
| 119 | + $msg = _T('zbug_erreur_compilation'); |
|
| 120 | + erreur_squelette($msg, $boucle); |
|
| 121 | + $nom = ''; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 126 | + // Tracer ce qui vient d'etre compile |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | + |
|
| 129 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | + if ( |
|
| 131 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | + and (_request('var_mode_objet') == $nom) |
|
| 133 | + and (_request('var_mode_affiche') == 'code') |
|
| 134 | + ) { |
|
| 135 | + erreur_squelette(); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $nom ?: false; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 143 | 143 | |
| 144 | - $code = null; |
|
| 145 | - // Le dernier index est '' (fonction principale) |
|
| 146 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | - if (CODE_COMMENTE) { |
|
| 148 | - $code = " |
|
| 144 | + $code = null; |
|
| 145 | + // Le dernier index est '' (fonction principale) |
|
| 146 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | + if (CODE_COMMENTE) { |
|
| 148 | + $code = " |
|
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | 151 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 152 | 152 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 153 | 153 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 154 | 154 | */ '; |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 158 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 159 | - ecrire_fichier($phpfile, $code); |
|
| 160 | - } |
|
| 157 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 158 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 159 | + ecrire_fichier($phpfile, $code); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $code; |
|
| 162 | + return $code; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Le squelette compile est-il trop vieux ? |
| 166 | 166 | function squelette_obsolete($skel, $squelette) { |
| 167 | - static $date_change = null; |
|
| 168 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | - // par hit |
|
| 170 | - if (is_null($date_change)) { |
|
| 171 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | - $date_change = @filemtime($fonc); |
|
| 173 | - } # compatibilite |
|
| 174 | - if (defined('_FILE_OPTIONS')) { |
|
| 175 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return ( |
|
| 180 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 181 | - or !@file_exists($skel) |
|
| 182 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 183 | - > ($date = @filemtime($skel))) |
|
| 184 | - or ($date_change > $date) |
|
| 185 | - ); |
|
| 167 | + static $date_change = null; |
|
| 168 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | + // par hit |
|
| 170 | + if (is_null($date_change)) { |
|
| 171 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | + $date_change = @filemtime($fonc); |
|
| 173 | + } # compatibilite |
|
| 174 | + if (defined('_FILE_OPTIONS')) { |
|
| 175 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return ( |
|
| 180 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 181 | + or !@file_exists($skel) |
|
| 182 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 183 | + > ($date = @filemtime($skel))) |
|
| 184 | + or ($date_change > $date) |
|
| 185 | + ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Activer l'invalideur de session |
| 189 | 189 | function invalideur_session(&$Cache, $code = null) { |
| 190 | - $Cache['session'] = spip_session(); |
|
| 190 | + $Cache['session'] = spip_session(); |
|
| 191 | 191 | |
| 192 | - return $code; |
|
| 192 | + return $code; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 197 | - static $filtres = []; |
|
| 198 | - $headers = []; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - and preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = $r[3]; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - strpos($corps, '<' . '?') === false |
|
| 227 | - or |
|
| 228 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | - ) |
|
| 231 | - ? 'html' |
|
| 232 | - : 'php'; |
|
| 233 | - |
|
| 234 | - $skel = [ |
|
| 235 | - 'squelette' => $nom, |
|
| 236 | - 'source' => $source, |
|
| 237 | - 'process_ins' => $process_ins, |
|
| 238 | - 'invalideurs' => $cache, |
|
| 239 | - 'entetes' => $headers, |
|
| 240 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | - ]; |
|
| 242 | - |
|
| 243 | - // traiter #FILTRE{} et filtres |
|
| 244 | - if (!isset($filtres[$nom])) { |
|
| 245 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | - } |
|
| 247 | - $filtres_headers = []; |
|
| 248 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | - unset($headers['X-Spip-Filtre']); |
|
| 251 | - } |
|
| 252 | - if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | - include_spip('public/sandbox'); |
|
| 254 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | - |
|
| 256 | - if ($process_ins == 'html') { |
|
| 257 | - $skel['process_ins'] = ( |
|
| 258 | - strpos($corps, '<' . '?') === false |
|
| 259 | - or |
|
| 260 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | - ) |
|
| 263 | - ? 'html' |
|
| 264 | - : 'php'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $skel['entetes'] = $headers; |
|
| 269 | - $skel['texte'] = $corps; |
|
| 270 | - |
|
| 271 | - return $skel; |
|
| 197 | + static $filtres = []; |
|
| 198 | + $headers = []; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + and preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = $r[3]; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + strpos($corps, '<' . '?') === false |
|
| 227 | + or |
|
| 228 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | + ) |
|
| 231 | + ? 'html' |
|
| 232 | + : 'php'; |
|
| 233 | + |
|
| 234 | + $skel = [ |
|
| 235 | + 'squelette' => $nom, |
|
| 236 | + 'source' => $source, |
|
| 237 | + 'process_ins' => $process_ins, |
|
| 238 | + 'invalideurs' => $cache, |
|
| 239 | + 'entetes' => $headers, |
|
| 240 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | + ]; |
|
| 242 | + |
|
| 243 | + // traiter #FILTRE{} et filtres |
|
| 244 | + if (!isset($filtres[$nom])) { |
|
| 245 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | + } |
|
| 247 | + $filtres_headers = []; |
|
| 248 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | + unset($headers['X-Spip-Filtre']); |
|
| 251 | + } |
|
| 252 | + if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | + include_spip('public/sandbox'); |
|
| 254 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | + |
|
| 256 | + if ($process_ins == 'html') { |
|
| 257 | + $skel['process_ins'] = ( |
|
| 258 | + strpos($corps, '<' . '?') === false |
|
| 259 | + or |
|
| 260 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | + ) |
|
| 263 | + ? 'html' |
|
| 264 | + : 'php'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $skel['entetes'] = $headers; |
|
| 269 | + $skel['texte'] = $corps; |
|
| 270 | + |
|
| 271 | + return $skel; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 283 | 283 | if ($lang_select) lang_select(); |
| 284 | 284 | ?' |
| 285 | - . '>'); |
|
| 285 | + . '>'); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | * Code PHP pour inclure le squelette de la balise dynamique |
| 303 | 303 | **/ |
| 304 | 304 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 305 | - if ( |
|
| 306 | - strncmp($file, '/', 1) !== 0 |
|
| 307 | - // pas de lien symbolique sous Windows |
|
| 308 | - and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 309 | - ) { |
|
| 310 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $lang = $context_compil[4]; |
|
| 314 | - if (preg_match(',\W,', $lang)) { |
|
| 315 | - $lang = ''; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $args = array_map('argumenter_squelette', $args); |
|
| 319 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | - } |
|
| 322 | - $args = join(', ', $args); |
|
| 323 | - |
|
| 324 | - $r = sprintf( |
|
| 325 | - CODE_INCLURE_BALISE, |
|
| 326 | - $file, |
|
| 327 | - $lang, |
|
| 328 | - $nom, |
|
| 329 | - $args, |
|
| 330 | - join(', ', array_map('_q', $context_compil)) |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - return $r; |
|
| 305 | + if ( |
|
| 306 | + strncmp($file, '/', 1) !== 0 |
|
| 307 | + // pas de lien symbolique sous Windows |
|
| 308 | + and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 309 | + ) { |
|
| 310 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $lang = $context_compil[4]; |
|
| 314 | + if (preg_match(',\W,', $lang)) { |
|
| 315 | + $lang = ''; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $args = array_map('argumenter_squelette', $args); |
|
| 319 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + } |
|
| 322 | + $args = join(', ', $args); |
|
| 323 | + |
|
| 324 | + $r = sprintf( |
|
| 325 | + CODE_INCLURE_BALISE, |
|
| 326 | + $file, |
|
| 327 | + $lang, |
|
| 328 | + $nom, |
|
| 329 | + $args, |
|
| 330 | + join(', ', array_map('_q', $context_compil)) |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + return $r; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | **/ |
| 349 | 349 | function argumenter_squelette($v) { |
| 350 | 350 | |
| 351 | - if (is_object($v)) { |
|
| 352 | - return var_export($v, true); |
|
| 353 | - } elseif (!is_array($v)) { |
|
| 354 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | - } else { |
|
| 356 | - $out = []; |
|
| 357 | - foreach ($v as $k => $val) { |
|
| 358 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | - } |
|
| 351 | + if (is_object($v)) { |
|
| 352 | + return var_export($v, true); |
|
| 353 | + } elseif (!is_array($v)) { |
|
| 354 | + return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + } else { |
|
| 356 | + $out = []; |
|
| 357 | + foreach ($v as $k => $val) { |
|
| 358 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -390,87 +390,87 @@ discard block |
||
| 390 | 390 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 391 | 391 | **/ |
| 392 | 392 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 393 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 394 | - $nom_balise = $nom; |
|
| 395 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 396 | - $nom_balise_generique = ''; |
|
| 397 | - |
|
| 398 | - $appel_php_depuis_modele = false; |
|
| 399 | - if ( |
|
| 400 | - is_array($context_compil) |
|
| 401 | - and !is_numeric($context_compil[3]) |
|
| 402 | - and empty($context_compil[0]) |
|
| 403 | - and empty($context_compil[1]) |
|
| 404 | - and empty($context_compil[2]) |
|
| 405 | - and empty($context_compil[3]) |
|
| 406 | - ) { |
|
| 407 | - $appel_php_depuis_modele = true; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 411 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 412 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 413 | - // injecter en premier arg le nom de la balise |
|
| 414 | - array_unshift($args, $nom); |
|
| 415 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 416 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 417 | - $nom_balise = $nom_balise_generique; |
|
| 418 | - } |
|
| 419 | - unset($balise_generique); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - if (!$fonction_balise) { |
|
| 423 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 424 | - erreur_squelette($msg, $context_compil); |
|
| 425 | - |
|
| 426 | - return ''; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // retrouver le fichier qui a déclaré la fonction |
|
| 430 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 431 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 432 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 433 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 434 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 435 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 439 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 440 | - |
|
| 441 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 442 | - |
|
| 443 | - if (!is_array($r)) { |
|
| 444 | - return $r; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // verifier que la fonction dyn est la, |
|
| 448 | - // sinon se replier sur la generique si elle existe |
|
| 449 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 450 | - if ( |
|
| 451 | - $balise_generique = chercher_balise_generique($nom) |
|
| 452 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 453 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 454 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 455 | - ) { |
|
| 456 | - // et lui injecter en premier arg le nom de la balise |
|
| 457 | - array_unshift($r, $nom); |
|
| 458 | - $nom_balise = $nom_balise_generique; |
|
| 459 | - if (!_DIR_RESTREINT) { |
|
| 460 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 461 | - } |
|
| 462 | - } else { |
|
| 463 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 464 | - erreur_squelette($msg, $context_compil); |
|
| 465 | - |
|
| 466 | - return ''; |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - if ($appel_php_depuis_modele) { |
|
| 471 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 472 | - } |
|
| 473 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 393 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 394 | + $nom_balise = $nom; |
|
| 395 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 396 | + $nom_balise_generique = ''; |
|
| 397 | + |
|
| 398 | + $appel_php_depuis_modele = false; |
|
| 399 | + if ( |
|
| 400 | + is_array($context_compil) |
|
| 401 | + and !is_numeric($context_compil[3]) |
|
| 402 | + and empty($context_compil[0]) |
|
| 403 | + and empty($context_compil[1]) |
|
| 404 | + and empty($context_compil[2]) |
|
| 405 | + and empty($context_compil[3]) |
|
| 406 | + ) { |
|
| 407 | + $appel_php_depuis_modele = true; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 411 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 412 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 413 | + // injecter en premier arg le nom de la balise |
|
| 414 | + array_unshift($args, $nom); |
|
| 415 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 416 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 417 | + $nom_balise = $nom_balise_generique; |
|
| 418 | + } |
|
| 419 | + unset($balise_generique); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + if (!$fonction_balise) { |
|
| 423 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 424 | + erreur_squelette($msg, $context_compil); |
|
| 425 | + |
|
| 426 | + return ''; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // retrouver le fichier qui a déclaré la fonction |
|
| 430 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 431 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 432 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 433 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 434 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 435 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 439 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 440 | + |
|
| 441 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 442 | + |
|
| 443 | + if (!is_array($r)) { |
|
| 444 | + return $r; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // verifier que la fonction dyn est la, |
|
| 448 | + // sinon se replier sur la generique si elle existe |
|
| 449 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 450 | + if ( |
|
| 451 | + $balise_generique = chercher_balise_generique($nom) |
|
| 452 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 453 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 454 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 455 | + ) { |
|
| 456 | + // et lui injecter en premier arg le nom de la balise |
|
| 457 | + array_unshift($r, $nom); |
|
| 458 | + $nom_balise = $nom_balise_generique; |
|
| 459 | + if (!_DIR_RESTREINT) { |
|
| 460 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 461 | + } |
|
| 462 | + } else { |
|
| 463 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 464 | + erreur_squelette($msg, $context_compil); |
|
| 465 | + |
|
| 466 | + return ''; |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + if ($appel_php_depuis_modele) { |
|
| 471 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 472 | + } |
|
| 473 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -485,23 +485,23 @@ discard block |
||
| 485 | 485 | * @return array|null |
| 486 | 486 | */ |
| 487 | 487 | function chercher_balise_generique($nom) { |
| 488 | - if (false === strpos($nom, '_')) { |
|
| 489 | - return null; |
|
| 490 | - } |
|
| 491 | - $nom_generique = $nom; |
|
| 492 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 493 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 494 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 495 | - if ($fonction_generique) { |
|
| 496 | - return [ |
|
| 497 | - 'nom' => $nom, |
|
| 498 | - 'nom_generique' => $nom_generique, |
|
| 499 | - 'fonction_generique' => $fonction_generique, |
|
| 500 | - ]; |
|
| 501 | - } |
|
| 502 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 503 | - } |
|
| 504 | - return null; |
|
| 488 | + if (false === strpos($nom, '_')) { |
|
| 489 | + return null; |
|
| 490 | + } |
|
| 491 | + $nom_generique = $nom; |
|
| 492 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 493 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 494 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 495 | + if ($fonction_generique) { |
|
| 496 | + return [ |
|
| 497 | + 'nom' => $nom, |
|
| 498 | + 'nom_generique' => $nom_generique, |
|
| 499 | + 'fonction_generique' => $fonction_generique, |
|
| 500 | + ]; |
|
| 501 | + } |
|
| 502 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 503 | + } |
|
| 504 | + return null; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -525,50 +525,50 @@ discard block |
||
| 525 | 525 | * @return null; |
| 526 | 526 | **/ |
| 527 | 527 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 528 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 529 | - if ( |
|
| 530 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 531 | - and $lang_select !== 'oui' |
|
| 532 | - ) { |
|
| 533 | - $lang = $GLOBALS['spip_lang']; |
|
| 534 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 535 | - elseif (!strlen($lang)) { |
|
| 536 | - $lang = $GLOBALS['spip_lang']; |
|
| 537 | - } // Cas 3. l'objet est multilingue ! |
|
| 538 | - elseif ( |
|
| 539 | - $lang_select !== 'oui' |
|
| 540 | - and strlen($titre) > 10 |
|
| 541 | - and strpos($titre, '<multi>') !== false |
|
| 542 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 543 | - ) { |
|
| 544 | - $lang = $GLOBALS['spip_lang']; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 548 | - lang_select($lang); |
|
| 549 | - |
|
| 550 | - return; |
|
| 528 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 529 | + if ( |
|
| 530 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 531 | + and $lang_select !== 'oui' |
|
| 532 | + ) { |
|
| 533 | + $lang = $GLOBALS['spip_lang']; |
|
| 534 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 535 | + elseif (!strlen($lang)) { |
|
| 536 | + $lang = $GLOBALS['spip_lang']; |
|
| 537 | + } // Cas 3. l'objet est multilingue ! |
|
| 538 | + elseif ( |
|
| 539 | + $lang_select !== 'oui' |
|
| 540 | + and strlen($titre) > 10 |
|
| 541 | + and strpos($titre, '<multi>') !== false |
|
| 542 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 543 | + ) { |
|
| 544 | + $lang = $GLOBALS['spip_lang']; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 548 | + lang_select($lang); |
|
| 549 | + |
|
| 550 | + return; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
| 554 | 554 | // Si un tableau &doublons[articles] est passe en parametre, |
| 555 | 555 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 556 | 556 | function nettoyer_env_doublons($envd) { |
| 557 | - foreach ($envd as $table => $liste) { |
|
| 558 | - $n = ''; |
|
| 559 | - foreach (explode(',', $liste) as $val) { |
|
| 560 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 561 | - $n .= ',' . $val; |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - if (strlen($n)) { |
|
| 565 | - $envd[$table] = $n; |
|
| 566 | - } else { |
|
| 567 | - unset($envd[$table]); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - return $envd; |
|
| 557 | + foreach ($envd as $table => $liste) { |
|
| 558 | + $n = ''; |
|
| 559 | + foreach (explode(',', $liste) as $val) { |
|
| 560 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 561 | + $n .= ',' . $val; |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + if (strlen($n)) { |
|
| 565 | + $envd[$table] = $n; |
|
| 566 | + } else { |
|
| 567 | + unset($envd[$table]); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + return $envd; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -587,21 +587,21 @@ discard block |
||
| 587 | 587 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 588 | 588 | **/ |
| 589 | 589 | function match_self($w) { |
| 590 | - if (is_string($w)) { |
|
| 591 | - return false; |
|
| 592 | - } |
|
| 593 | - if (is_array($w)) { |
|
| 594 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 595 | - return $w; |
|
| 596 | - } |
|
| 597 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 598 | - if ($m = match_self($sw)) { |
|
| 599 | - return $m; |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return false; |
|
| 590 | + if (is_string($w)) { |
|
| 591 | + return false; |
|
| 592 | + } |
|
| 593 | + if (is_array($w)) { |
|
| 594 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 595 | + return $w; |
|
| 596 | + } |
|
| 597 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 598 | + if ($m = match_self($sw)) { |
|
| 599 | + return $m; |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return false; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -617,16 +617,16 @@ discard block |
||
| 617 | 617 | * est remplacée par son code. |
| 618 | 618 | **/ |
| 619 | 619 | function remplace_sous_requete($w, $sousrequete) { |
| 620 | - if (is_array($w)) { |
|
| 621 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 622 | - return $sousrequete; |
|
| 623 | - } |
|
| 624 | - foreach ($w as $k => $sw) { |
|
| 625 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - return $w; |
|
| 620 | + if (is_array($w)) { |
|
| 621 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 622 | + return $sousrequete; |
|
| 623 | + } |
|
| 624 | + foreach ($w as $k => $sw) { |
|
| 625 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + return $w; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -640,17 +640,17 @@ discard block |
||
| 640 | 640 | * - Conditions avec des sous requêtes |
| 641 | 641 | **/ |
| 642 | 642 | function trouver_sous_requetes($where) { |
| 643 | - $where_simples = []; |
|
| 644 | - $where_sous = []; |
|
| 645 | - foreach ($where as $k => $w) { |
|
| 646 | - if (match_self($w)) { |
|
| 647 | - $where_sous[$k] = $w; |
|
| 648 | - } else { |
|
| 649 | - $where_simples[$k] = $w; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return [$where_simples, $where_sous]; |
|
| 643 | + $where_simples = []; |
|
| 644 | + $where_sous = []; |
|
| 645 | + foreach ($where as $k => $w) { |
|
| 646 | + if (match_self($w)) { |
|
| 647 | + $where_sous[$k] = $w; |
|
| 648 | + } else { |
|
| 649 | + $where_simples[$k] = $w; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return [$where_simples, $where_sous]; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | |
@@ -676,292 +676,292 @@ discard block |
||
| 676 | 676 | * @return resource |
| 677 | 677 | */ |
| 678 | 678 | function calculer_select( |
| 679 | - $select = [], |
|
| 680 | - $from = [], |
|
| 681 | - $from_type = [], |
|
| 682 | - $where = [], |
|
| 683 | - $join = [], |
|
| 684 | - $groupby = [], |
|
| 685 | - $orderby = [], |
|
| 686 | - $limit = '', |
|
| 687 | - $having = [], |
|
| 688 | - $table = '', |
|
| 689 | - $id = '', |
|
| 690 | - $serveur = '', |
|
| 691 | - $requeter = true |
|
| 679 | + $select = [], |
|
| 680 | + $from = [], |
|
| 681 | + $from_type = [], |
|
| 682 | + $where = [], |
|
| 683 | + $join = [], |
|
| 684 | + $groupby = [], |
|
| 685 | + $orderby = [], |
|
| 686 | + $limit = '', |
|
| 687 | + $having = [], |
|
| 688 | + $table = '', |
|
| 689 | + $id = '', |
|
| 690 | + $serveur = '', |
|
| 691 | + $requeter = true |
|
| 692 | 692 | ) { |
| 693 | 693 | |
| 694 | - // retirer les criteres vides: |
|
| 695 | - // {X ?} avec X absent de l'URL |
|
| 696 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 697 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 698 | - $menage = false; |
|
| 699 | - foreach ($where as $k => $v) { |
|
| 700 | - if (is_array($v)) { |
|
| 701 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 702 | - $op = false; |
|
| 703 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 704 | - $op = false; |
|
| 705 | - } else { |
|
| 706 | - $op = $v[0] ?: $v; |
|
| 707 | - } |
|
| 708 | - } else { |
|
| 709 | - $op = $v; |
|
| 710 | - } |
|
| 711 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 712 | - unset($where[$k]); |
|
| 713 | - $menage = true; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 718 | - $groupby = array_diff($groupby, ['']); |
|
| 719 | - |
|
| 720 | - // remplacer les sous requetes recursives au calcul |
|
| 721 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 722 | - foreach ($where_sous as $k => $w) { |
|
| 723 | - $menage = true; |
|
| 724 | - // on recupere la sous requete |
|
| 725 | - $sous = match_self($w); |
|
| 726 | - if ($sous[0] == 'SELF') { |
|
| 727 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 728 | - array_push($where_simples, $sous[2]); |
|
| 729 | - $wheresub = [ |
|
| 730 | - $sous[2], |
|
| 731 | - '0=0' |
|
| 732 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 733 | - $jsub = $join; |
|
| 734 | - // trouver les jointures utiles a |
|
| 735 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 736 | - // ie L1.objet='article' |
|
| 737 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 738 | - $i = 0; |
|
| 739 | - do { |
|
| 740 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 741 | - [$sous[1] . ' AS id'], |
|
| 742 | - $from, |
|
| 743 | - $from_type, |
|
| 744 | - $wheresub, |
|
| 745 | - $jsub, |
|
| 746 | - [], |
|
| 747 | - [], |
|
| 748 | - '', |
|
| 749 | - $having, |
|
| 750 | - $table, |
|
| 751 | - $id, |
|
| 752 | - $serveur, |
|
| 753 | - false |
|
| 754 | - ) . ')'); |
|
| 755 | - if (!$i) { |
|
| 756 | - $i = 1; |
|
| 757 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 758 | - foreach ($join as $cle => $wj) { |
|
| 759 | - if ( |
|
| 760 | - (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 761 | - and strpos($wherestring, (string) "{$cle}.") !== false |
|
| 762 | - ) { |
|
| 763 | - $i = 0; |
|
| 764 | - $wheresub[] = $wj[3]; |
|
| 765 | - unset($jsub[$cle][3]); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } while ($i++ < 1); |
|
| 770 | - } |
|
| 771 | - if ($sous[0] == 'SUBSELECT') { |
|
| 772 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 773 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 774 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 775 | - $sous[1], # select |
|
| 776 | - $sous[2], #from |
|
| 777 | - [], #from_type |
|
| 778 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 779 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 780 | - [], #join |
|
| 781 | - $sous[4] ?: [], #groupby |
|
| 782 | - $sous[5] ?: [], #orderby |
|
| 783 | - $sous[6], #limit |
|
| 784 | - $sous[7] ?: [], #having |
|
| 785 | - $table, |
|
| 786 | - $id, |
|
| 787 | - $serveur, |
|
| 788 | - false |
|
| 789 | - ) . ')'); |
|
| 790 | - } |
|
| 791 | - array_pop($where_simples); |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - foreach ($having as $k => $v) { |
|
| 795 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 796 | - unset($having[$k]); |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - // Installer les jointures. |
|
| 801 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 802 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 803 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 804 | - |
|
| 805 | - $afrom = []; |
|
| 806 | - $equiv = []; |
|
| 807 | - $k = count($join); |
|
| 808 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 809 | - $cle = $cledef; |
|
| 810 | - // le format de join est : |
|
| 811 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 812 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 813 | - if (count($join[$cle]) == 2) { |
|
| 814 | - $join[$cle][] = $join[$cle][1]; |
|
| 815 | - } |
|
| 816 | - if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 817 | - $join[$cle][] = ''; |
|
| 818 | - } |
|
| 819 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 820 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 821 | - // pour compat avec ancienne convention |
|
| 822 | - if (is_numeric($cle)) { |
|
| 823 | - $cle = "L$k"; |
|
| 824 | - } |
|
| 825 | - $cle_where_lie = "JOIN-$cle"; |
|
| 826 | - if ( |
|
| 827 | - !$menage |
|
| 828 | - or isset($afrom[$cle]) |
|
| 829 | - or calculer_jointnul($cle, $select) |
|
| 830 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 831 | - or calculer_jointnul($cle, $having) |
|
| 832 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 833 | - ) { |
|
| 834 | - // corriger les references non explicites dans select |
|
| 835 | - // ou groupby |
|
| 836 | - foreach ($select as $i => $s) { |
|
| 837 | - if ($s == $c) { |
|
| 838 | - $select[$i] = "$cle.$c AS $c"; |
|
| 839 | - break; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - foreach ($groupby as $i => $g) { |
|
| 843 | - if ($g == $c) { |
|
| 844 | - $groupby[$i] = "$cle.$c"; |
|
| 845 | - break; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 849 | - // sans recours a preg_match |
|
| 850 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 851 | - $afrom[$t][$cle] = [ |
|
| 852 | - "\n" . |
|
| 853 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 854 | - $from[$cle], |
|
| 855 | - "AS $cle", |
|
| 856 | - 'ON (', |
|
| 857 | - "$cle.$c", |
|
| 858 | - '=', |
|
| 859 | - "$t.$carr", |
|
| 860 | - ($and ? 'AND ' . $and : '') . |
|
| 861 | - ')' |
|
| 862 | - ]; |
|
| 863 | - if (isset($afrom[$cle])) { |
|
| 864 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 865 | - unset($afrom[$cle]); |
|
| 866 | - } |
|
| 867 | - $equiv[] = $carr; |
|
| 868 | - } else { |
|
| 869 | - unset($join[$cledef]); |
|
| 870 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 871 | - unset($where_simples[$cle_where_lie]); |
|
| 872 | - unset($where[$cle_where_lie]); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - unset($from[$cle]); |
|
| 876 | - $k--; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - if (count($afrom)) { |
|
| 880 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 881 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 882 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 883 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 884 | - // ou dans |
|
| 885 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 886 | - // qui comporte plusieurs jointures |
|
| 887 | - // ou dans |
|
| 888 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 889 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 890 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 891 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 892 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 893 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 894 | - |
|
| 895 | - $t = key($from); |
|
| 896 | - $c = current($from); |
|
| 897 | - reset($from); |
|
| 898 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 899 | - if ( |
|
| 900 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 901 | - calculer_jointnul($t, $select, $e) or |
|
| 902 | - calculer_jointnul($t, $join, $e) or |
|
| 903 | - calculer_jointnul($t, $where, $e) or |
|
| 904 | - calculer_jointnul($t, $orderby, $e) or |
|
| 905 | - calculer_jointnul($t, $groupby, $e) or |
|
| 906 | - calculer_jointnul($t, $having, $e)) |
|
| 907 | - && count($afrom[$t]) |
|
| 908 | - ) { |
|
| 909 | - $nfrom = reset($afrom[$t]); |
|
| 910 | - $nt = array_key_first($afrom[$t]); |
|
| 911 | - unset($from[$t]); |
|
| 912 | - $from[$nt] = $nfrom[1]; |
|
| 913 | - unset($afrom[$t][$nt]); |
|
| 914 | - $afrom[$nt] = $afrom[$t]; |
|
| 915 | - unset($afrom[$t]); |
|
| 916 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 917 | - $t = $nfrom[4]; |
|
| 918 | - $alias = ''; |
|
| 919 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 920 | - $oldcle = explode('.', $nfrom[6]); |
|
| 921 | - $oldcle = end($oldcle); |
|
| 922 | - $newcle = explode('.', $nfrom[4]); |
|
| 923 | - $newcle = end($newcle); |
|
| 924 | - if ($newcle != $oldcle) { |
|
| 925 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 926 | - // reprendre simplement ce AS |
|
| 927 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 928 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 929 | - $alias = ''; |
|
| 930 | - } else { |
|
| 931 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 935 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 936 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 937 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 938 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 939 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 940 | - } |
|
| 941 | - $from = reinjecte_joint($afrom, $from); |
|
| 942 | - } |
|
| 943 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 944 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 945 | - $GLOBALS['debug'] = []; |
|
| 946 | - if ($wasdebug) { |
|
| 947 | - $GLOBALS['debug']['debug'] = true; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 951 | - $r = sql_select( |
|
| 952 | - $select, |
|
| 953 | - $from, |
|
| 954 | - $where, |
|
| 955 | - $groupby, |
|
| 956 | - array_filter($orderby), |
|
| 957 | - $limit, |
|
| 958 | - $having, |
|
| 959 | - $serveur, |
|
| 960 | - $requeter |
|
| 961 | - ); |
|
| 962 | - unset($GLOBALS['debug']['aucasou']); |
|
| 963 | - |
|
| 964 | - return $r; |
|
| 694 | + // retirer les criteres vides: |
|
| 695 | + // {X ?} avec X absent de l'URL |
|
| 696 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 697 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 698 | + $menage = false; |
|
| 699 | + foreach ($where as $k => $v) { |
|
| 700 | + if (is_array($v)) { |
|
| 701 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 702 | + $op = false; |
|
| 703 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 704 | + $op = false; |
|
| 705 | + } else { |
|
| 706 | + $op = $v[0] ?: $v; |
|
| 707 | + } |
|
| 708 | + } else { |
|
| 709 | + $op = $v; |
|
| 710 | + } |
|
| 711 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 712 | + unset($where[$k]); |
|
| 713 | + $menage = true; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 718 | + $groupby = array_diff($groupby, ['']); |
|
| 719 | + |
|
| 720 | + // remplacer les sous requetes recursives au calcul |
|
| 721 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 722 | + foreach ($where_sous as $k => $w) { |
|
| 723 | + $menage = true; |
|
| 724 | + // on recupere la sous requete |
|
| 725 | + $sous = match_self($w); |
|
| 726 | + if ($sous[0] == 'SELF') { |
|
| 727 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 728 | + array_push($where_simples, $sous[2]); |
|
| 729 | + $wheresub = [ |
|
| 730 | + $sous[2], |
|
| 731 | + '0=0' |
|
| 732 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 733 | + $jsub = $join; |
|
| 734 | + // trouver les jointures utiles a |
|
| 735 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 736 | + // ie L1.objet='article' |
|
| 737 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 738 | + $i = 0; |
|
| 739 | + do { |
|
| 740 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 741 | + [$sous[1] . ' AS id'], |
|
| 742 | + $from, |
|
| 743 | + $from_type, |
|
| 744 | + $wheresub, |
|
| 745 | + $jsub, |
|
| 746 | + [], |
|
| 747 | + [], |
|
| 748 | + '', |
|
| 749 | + $having, |
|
| 750 | + $table, |
|
| 751 | + $id, |
|
| 752 | + $serveur, |
|
| 753 | + false |
|
| 754 | + ) . ')'); |
|
| 755 | + if (!$i) { |
|
| 756 | + $i = 1; |
|
| 757 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 758 | + foreach ($join as $cle => $wj) { |
|
| 759 | + if ( |
|
| 760 | + (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 761 | + and strpos($wherestring, (string) "{$cle}.") !== false |
|
| 762 | + ) { |
|
| 763 | + $i = 0; |
|
| 764 | + $wheresub[] = $wj[3]; |
|
| 765 | + unset($jsub[$cle][3]); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } while ($i++ < 1); |
|
| 770 | + } |
|
| 771 | + if ($sous[0] == 'SUBSELECT') { |
|
| 772 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 773 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 774 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 775 | + $sous[1], # select |
|
| 776 | + $sous[2], #from |
|
| 777 | + [], #from_type |
|
| 778 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 779 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 780 | + [], #join |
|
| 781 | + $sous[4] ?: [], #groupby |
|
| 782 | + $sous[5] ?: [], #orderby |
|
| 783 | + $sous[6], #limit |
|
| 784 | + $sous[7] ?: [], #having |
|
| 785 | + $table, |
|
| 786 | + $id, |
|
| 787 | + $serveur, |
|
| 788 | + false |
|
| 789 | + ) . ')'); |
|
| 790 | + } |
|
| 791 | + array_pop($where_simples); |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + foreach ($having as $k => $v) { |
|
| 795 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 796 | + unset($having[$k]); |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + // Installer les jointures. |
|
| 801 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 802 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 803 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 804 | + |
|
| 805 | + $afrom = []; |
|
| 806 | + $equiv = []; |
|
| 807 | + $k = count($join); |
|
| 808 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 809 | + $cle = $cledef; |
|
| 810 | + // le format de join est : |
|
| 811 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 812 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 813 | + if (count($join[$cle]) == 2) { |
|
| 814 | + $join[$cle][] = $join[$cle][1]; |
|
| 815 | + } |
|
| 816 | + if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 817 | + $join[$cle][] = ''; |
|
| 818 | + } |
|
| 819 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 820 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 821 | + // pour compat avec ancienne convention |
|
| 822 | + if (is_numeric($cle)) { |
|
| 823 | + $cle = "L$k"; |
|
| 824 | + } |
|
| 825 | + $cle_where_lie = "JOIN-$cle"; |
|
| 826 | + if ( |
|
| 827 | + !$menage |
|
| 828 | + or isset($afrom[$cle]) |
|
| 829 | + or calculer_jointnul($cle, $select) |
|
| 830 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 831 | + or calculer_jointnul($cle, $having) |
|
| 832 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 833 | + ) { |
|
| 834 | + // corriger les references non explicites dans select |
|
| 835 | + // ou groupby |
|
| 836 | + foreach ($select as $i => $s) { |
|
| 837 | + if ($s == $c) { |
|
| 838 | + $select[$i] = "$cle.$c AS $c"; |
|
| 839 | + break; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + foreach ($groupby as $i => $g) { |
|
| 843 | + if ($g == $c) { |
|
| 844 | + $groupby[$i] = "$cle.$c"; |
|
| 845 | + break; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 849 | + // sans recours a preg_match |
|
| 850 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 851 | + $afrom[$t][$cle] = [ |
|
| 852 | + "\n" . |
|
| 853 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 854 | + $from[$cle], |
|
| 855 | + "AS $cle", |
|
| 856 | + 'ON (', |
|
| 857 | + "$cle.$c", |
|
| 858 | + '=', |
|
| 859 | + "$t.$carr", |
|
| 860 | + ($and ? 'AND ' . $and : '') . |
|
| 861 | + ')' |
|
| 862 | + ]; |
|
| 863 | + if (isset($afrom[$cle])) { |
|
| 864 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 865 | + unset($afrom[$cle]); |
|
| 866 | + } |
|
| 867 | + $equiv[] = $carr; |
|
| 868 | + } else { |
|
| 869 | + unset($join[$cledef]); |
|
| 870 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 871 | + unset($where_simples[$cle_where_lie]); |
|
| 872 | + unset($where[$cle_where_lie]); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + unset($from[$cle]); |
|
| 876 | + $k--; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + if (count($afrom)) { |
|
| 880 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 881 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 882 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 883 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 884 | + // ou dans |
|
| 885 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 886 | + // qui comporte plusieurs jointures |
|
| 887 | + // ou dans |
|
| 888 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 889 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 890 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 891 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 892 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 893 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 894 | + |
|
| 895 | + $t = key($from); |
|
| 896 | + $c = current($from); |
|
| 897 | + reset($from); |
|
| 898 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 899 | + if ( |
|
| 900 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 901 | + calculer_jointnul($t, $select, $e) or |
|
| 902 | + calculer_jointnul($t, $join, $e) or |
|
| 903 | + calculer_jointnul($t, $where, $e) or |
|
| 904 | + calculer_jointnul($t, $orderby, $e) or |
|
| 905 | + calculer_jointnul($t, $groupby, $e) or |
|
| 906 | + calculer_jointnul($t, $having, $e)) |
|
| 907 | + && count($afrom[$t]) |
|
| 908 | + ) { |
|
| 909 | + $nfrom = reset($afrom[$t]); |
|
| 910 | + $nt = array_key_first($afrom[$t]); |
|
| 911 | + unset($from[$t]); |
|
| 912 | + $from[$nt] = $nfrom[1]; |
|
| 913 | + unset($afrom[$t][$nt]); |
|
| 914 | + $afrom[$nt] = $afrom[$t]; |
|
| 915 | + unset($afrom[$t]); |
|
| 916 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 917 | + $t = $nfrom[4]; |
|
| 918 | + $alias = ''; |
|
| 919 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 920 | + $oldcle = explode('.', $nfrom[6]); |
|
| 921 | + $oldcle = end($oldcle); |
|
| 922 | + $newcle = explode('.', $nfrom[4]); |
|
| 923 | + $newcle = end($newcle); |
|
| 924 | + if ($newcle != $oldcle) { |
|
| 925 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 926 | + // reprendre simplement ce AS |
|
| 927 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 928 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 929 | + $alias = ''; |
|
| 930 | + } else { |
|
| 931 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 935 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 936 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 937 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 938 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 939 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 940 | + } |
|
| 941 | + $from = reinjecte_joint($afrom, $from); |
|
| 942 | + } |
|
| 943 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 944 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 945 | + $GLOBALS['debug'] = []; |
|
| 946 | + if ($wasdebug) { |
|
| 947 | + $GLOBALS['debug']['debug'] = true; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 951 | + $r = sql_select( |
|
| 952 | + $select, |
|
| 953 | + $from, |
|
| 954 | + $where, |
|
| 955 | + $groupby, |
|
| 956 | + array_filter($orderby), |
|
| 957 | + $limit, |
|
| 958 | + $having, |
|
| 959 | + $serveur, |
|
| 960 | + $requeter |
|
| 961 | + ); |
|
| 962 | + unset($GLOBALS['debug']['aucasou']); |
|
| 963 | + |
|
| 964 | + return $r; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | /** |
@@ -972,79 +972,79 @@ discard block |
||
| 972 | 972 | * @return string |
| 973 | 973 | */ |
| 974 | 974 | function calculer_where_to_string($v, $join = 'AND') { |
| 975 | - if (empty($v)) { |
|
| 976 | - return ''; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - if (!is_array($v)) { |
|
| 980 | - return $v; |
|
| 981 | - } else { |
|
| 982 | - $exp = ''; |
|
| 983 | - if (strtoupper($join) === 'AND') { |
|
| 984 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 985 | - } else { |
|
| 986 | - return $exp . join($join, $v); |
|
| 987 | - } |
|
| 988 | - } |
|
| 975 | + if (empty($v)) { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + if (!is_array($v)) { |
|
| 980 | + return $v; |
|
| 981 | + } else { |
|
| 982 | + $exp = ''; |
|
| 983 | + if (strtoupper($join) === 'AND') { |
|
| 984 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 985 | + } else { |
|
| 986 | + return $exp . join($join, $v); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | |
| 992 | 992 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 993 | 993 | |
| 994 | 994 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 995 | - if (!is_array($exp)) { |
|
| 996 | - if ($equiv) { |
|
| 997 | - $exp = preg_replace($equiv, '', $exp); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1001 | - } else { |
|
| 1002 | - foreach ($exp as $v) { |
|
| 1003 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1004 | - return true; |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - return false; |
|
| 1009 | - } |
|
| 995 | + if (!is_array($exp)) { |
|
| 996 | + if ($equiv) { |
|
| 997 | + $exp = preg_replace($equiv, '', $exp); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1001 | + } else { |
|
| 1002 | + foreach ($exp as $v) { |
|
| 1003 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1004 | + return true; |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + return false; |
|
| 1009 | + } |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | function reinjecte_joint($afrom, $from) { |
| 1013 | - $from_synth = []; |
|
| 1014 | - foreach ($from as $k => $v) { |
|
| 1015 | - $from_synth[$k] = $from[$k]; |
|
| 1016 | - if (isset($afrom[$k])) { |
|
| 1017 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1018 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1019 | - } |
|
| 1020 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1021 | - unset($afrom[$k]); |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - return $from_synth; |
|
| 1013 | + $from_synth = []; |
|
| 1014 | + foreach ($from as $k => $v) { |
|
| 1015 | + $from_synth[$k] = $from[$k]; |
|
| 1016 | + if (isset($afrom[$k])) { |
|
| 1017 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1018 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1019 | + } |
|
| 1020 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1021 | + unset($afrom[$k]); |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + return $from_synth; |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1029 | - if (!is_array($exp)) { |
|
| 1030 | - return preg_replace($equiv, $cle, $exp); |
|
| 1031 | - } else { |
|
| 1032 | - foreach ($exp as $k => $v) { |
|
| 1033 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $exp; |
|
| 1037 | - } |
|
| 1029 | + if (!is_array($exp)) { |
|
| 1030 | + return preg_replace($equiv, $cle, $exp); |
|
| 1031 | + } else { |
|
| 1032 | + foreach ($exp as $k => $v) { |
|
| 1033 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $exp; |
|
| 1037 | + } |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | // calcul du nom du squelette |
| 1041 | 1041 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1042 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1043 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1044 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - return $mime_type |
|
| 1048 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1049 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1042 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1043 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1044 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + return $mime_type |
|
| 1048 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1049 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1050 | 1050 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - [$id_rubrique, $lang] = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + [$id_rubrique, $lang] = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = $row['lang'] ?? ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = $row['lang'] ?? ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,667 +21,667 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - $iter = null; |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = $command['args'] ?? []; |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if ( |
|
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | - or !class_exists($class) |
|
| 87 | - ) { |
|
| 88 | - die("Iterateur $iterateur non trouvé"); |
|
| 89 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | - # $iter = new EmptyIterator(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $iter = new $class($command, $info); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return new IterDecorator($iter, $command, $info); |
|
| 97 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + $iter = null; |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = $command['args'] ?? []; |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = 'Iterateur' . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if ( |
|
| 85 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | + or !class_exists($class) |
|
| 87 | + ) { |
|
| 88 | + die("Iterateur $iterateur non trouvé"); |
|
| 89 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | + # $iter = new EmptyIterator(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $iter = new $class($command, $info); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return new IterDecorator($iter, $command, $info); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | class IterDecorator extends FilterIterator { |
| 102 | - private $iter; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Conditions de filtrage |
|
| 106 | - * ie criteres de selection |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $filtre = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $func_filtre = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Critere {offset, limit} |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - * @var int |
|
| 124 | - */ |
|
| 125 | - protected $offset = null; |
|
| 126 | - protected $limit = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * nombre d'elements recuperes depuis la position 0, |
|
| 130 | - * en tenant compte des filtres |
|
| 131 | - * |
|
| 132 | - * @var int |
|
| 133 | - */ |
|
| 134 | - protected $fetched = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Y a t'il une erreur ? |
|
| 138 | - * |
|
| 139 | - * @var bool |
|
| 140 | - **/ |
|
| 141 | - protected $err = false; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Drapeau a activer en cas d'echec |
|
| 145 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | - */ |
|
| 147 | - public function err() { |
|
| 148 | - if (method_exists($this->iter, 'err')) { |
|
| 149 | - return $this->iter->err(); |
|
| 150 | - } |
|
| 151 | - if (property_exists($this->iter, 'err')) { |
|
| 152 | - return $this->iter->err; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | - parent::__construct($iter); |
|
| 160 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | - |
|
| 162 | - // recuperer l'iterateur transmis |
|
| 163 | - $this->iter = $this->getInnerIterator(); |
|
| 164 | - $this->command = $command; |
|
| 165 | - $this->info = $info; |
|
| 166 | - $this->pos = 0; |
|
| 167 | - $this->fetched = 0; |
|
| 168 | - |
|
| 169 | - // chercher la liste des champs a retourner par |
|
| 170 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | - $this->calculer_select(); |
|
| 173 | - $this->calculer_filtres(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | - if (isset($this->iter->err)) { |
|
| 178 | - $this->err = $this->iter->err; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | - //$this->total = $this->count(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - // calcule les elements a retournes par fetch() |
|
| 187 | - // enleve les elements inutiles du select() |
|
| 188 | - // |
|
| 189 | - private function calculer_select() { |
|
| 190 | - if ($select = &$this->command['select']) { |
|
| 191 | - foreach ($select as $s) { |
|
| 192 | - // /!\ $s = '.nom' |
|
| 193 | - if ($s[0] == '.') { |
|
| 194 | - $s = substr($s, 1); |
|
| 195 | - } |
|
| 196 | - $this->select[] = $s; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // recuperer la valeur d'une balise #X |
|
| 202 | - // en fonction des methodes |
|
| 203 | - // et proprietes disponibles |
|
| 204 | - public function get_select($nom) { |
|
| 205 | - if ( |
|
| 206 | - is_object($this->iter) |
|
| 207 | - and method_exists($this->iter, $nom) |
|
| 208 | - ) { |
|
| 209 | - try { |
|
| 210 | - return $this->iter->$nom(); |
|
| 211 | - } catch (Exception $e) { |
|
| 212 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - /* |
|
| 102 | + private $iter; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Conditions de filtrage |
|
| 106 | + * ie criteres de selection |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $filtre = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $func_filtre = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Critere {offset, limit} |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + * @var int |
|
| 124 | + */ |
|
| 125 | + protected $offset = null; |
|
| 126 | + protected $limit = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * nombre d'elements recuperes depuis la position 0, |
|
| 130 | + * en tenant compte des filtres |
|
| 131 | + * |
|
| 132 | + * @var int |
|
| 133 | + */ |
|
| 134 | + protected $fetched = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Y a t'il une erreur ? |
|
| 138 | + * |
|
| 139 | + * @var bool |
|
| 140 | + **/ |
|
| 141 | + protected $err = false; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Drapeau a activer en cas d'echec |
|
| 145 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | + */ |
|
| 147 | + public function err() { |
|
| 148 | + if (method_exists($this->iter, 'err')) { |
|
| 149 | + return $this->iter->err(); |
|
| 150 | + } |
|
| 151 | + if (property_exists($this->iter, 'err')) { |
|
| 152 | + return $this->iter->err; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | + parent::__construct($iter); |
|
| 160 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | + |
|
| 162 | + // recuperer l'iterateur transmis |
|
| 163 | + $this->iter = $this->getInnerIterator(); |
|
| 164 | + $this->command = $command; |
|
| 165 | + $this->info = $info; |
|
| 166 | + $this->pos = 0; |
|
| 167 | + $this->fetched = 0; |
|
| 168 | + |
|
| 169 | + // chercher la liste des champs a retourner par |
|
| 170 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | + $this->calculer_select(); |
|
| 173 | + $this->calculer_filtres(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | + if (isset($this->iter->err)) { |
|
| 178 | + $this->err = $this->iter->err; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | + //$this->total = $this->count(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + // calcule les elements a retournes par fetch() |
|
| 187 | + // enleve les elements inutiles du select() |
|
| 188 | + // |
|
| 189 | + private function calculer_select() { |
|
| 190 | + if ($select = &$this->command['select']) { |
|
| 191 | + foreach ($select as $s) { |
|
| 192 | + // /!\ $s = '.nom' |
|
| 193 | + if ($s[0] == '.') { |
|
| 194 | + $s = substr($s, 1); |
|
| 195 | + } |
|
| 196 | + $this->select[] = $s; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // recuperer la valeur d'une balise #X |
|
| 202 | + // en fonction des methodes |
|
| 203 | + // et proprietes disponibles |
|
| 204 | + public function get_select($nom) { |
|
| 205 | + if ( |
|
| 206 | + is_object($this->iter) |
|
| 207 | + and method_exists($this->iter, $nom) |
|
| 208 | + ) { |
|
| 209 | + try { |
|
| 210 | + return $this->iter->$nom(); |
|
| 211 | + } catch (Exception $e) { |
|
| 212 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + /* |
|
| 220 | 220 | if (property_exists($this->iter, $nom)) { |
| 221 | 221 | return $this->iter->$nom; |
| 222 | 222 | }*/ |
| 223 | - // cle et valeur par defaut |
|
| 224 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | - if ( |
|
| 226 | - in_array($nom, ['cle', 'valeur']) |
|
| 227 | - and method_exists($this, $nom) |
|
| 228 | - ) { |
|
| 229 | - return $this->$nom(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Par defaut chercher en xpath dans la valeur() |
|
| 233 | - return table_valeur($this->valeur(), $nom, null); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - private function calculer_filtres() { |
|
| 238 | - |
|
| 239 | - // Issu de calculer_select() de public/composer L.519 |
|
| 240 | - // TODO: externaliser... |
|
| 241 | - // |
|
| 242 | - // retirer les criteres vides: |
|
| 243 | - // {X ?} avec X absent de l'URL |
|
| 244 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | - if ($where = &$this->command['where']) { |
|
| 247 | - foreach ($where as $k => $v) { |
|
| 248 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // critere {2,7} |
|
| 253 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | - $limit = explode(',', $this->command['limit']); |
|
| 255 | - $this->offset = $limit[0]; |
|
| 256 | - $this->limit = $limit[1]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Creer la fonction de filtrage sur $this |
|
| 260 | - if ($this->filtre) { |
|
| 261 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 263 | - $this->func_filtre = fn() => eval($filtres); |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $this->func_filtre = null; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | - * les filtres vides ou null sont ignores |
|
| 274 | - * @param $filtres |
|
| 275 | - * @param string $operateur |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | - |
|
| 280 | - $filtres_string = []; |
|
| 281 | - foreach ($filtres as $k => $v) { |
|
| 282 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | - $op = array_shift($v); |
|
| 285 | - $v = $this->assembler_filtres($v, $op); |
|
| 286 | - } |
|
| 287 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $filtres_string[] = $v; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!count($filtres_string)) { |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Traduire un element du tableau where SQL en un filtre |
|
| 302 | - * @param $v |
|
| 303 | - * @return string|array|null |
|
| 304 | - */ |
|
| 305 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | - if (is_array($v)) { |
|
| 307 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | - return 'true'; |
|
| 309 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | - return 'true'; |
|
| 311 | - } else { |
|
| 312 | - $op = $v[0] ?: $v; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $op = $v; |
|
| 316 | - } |
|
| 317 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | - return 'true'; |
|
| 319 | - } |
|
| 320 | - if ($op === '0=1') { |
|
| 321 | - return 'false'; |
|
| 322 | - } |
|
| 323 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // 3 possibilites : count($v) = |
|
| 329 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | - |
|
| 333 | - // 1 : forcement traite par un critere, on passe |
|
| 334 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | - return null; // sera ignore |
|
| 336 | - } |
|
| 337 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | - } |
|
| 340 | - if (count($v) == 3) { |
|
| 341 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | - array_shift($v); |
|
| 344 | - foreach (array_keys($v) as $k) { |
|
| 345 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | - if ($v[$k] === null) { |
|
| 347 | - unset($v[$k]); |
|
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 350 | - if ($op === 'OR') { |
|
| 351 | - return 'true'; |
|
| 352 | - } |
|
| 353 | - if ($op === 'AND') { |
|
| 354 | - unset($v[$k]); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 358 | - if ($op === 'OR') { |
|
| 359 | - unset($v[$k]); |
|
| 360 | - } |
|
| 361 | - if ($op === 'AND') { |
|
| 362 | - return 'false'; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - if (!count($v)) { |
|
| 367 | - return null; |
|
| 368 | - } |
|
| 369 | - if (count($v) === 1) { |
|
| 370 | - return reset($v); |
|
| 371 | - } |
|
| 372 | - array_unshift($v, $op); |
|
| 373 | - return $v; |
|
| 374 | - } |
|
| 375 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return null; // sera ignore |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Calculer un filtre sur un champ du tableau |
|
| 383 | - * @param $cle |
|
| 384 | - * @param $op |
|
| 385 | - * @param $valeur |
|
| 386 | - * @param false $not |
|
| 387 | - * @return string|null |
|
| 388 | - */ |
|
| 389 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | - |
|
| 401 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | - # return; |
|
| 403 | - |
|
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | - |
|
| 406 | - $filtre = ''; |
|
| 407 | - |
|
| 408 | - if ($op == 'REGEXP') { |
|
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | - $op = ''; |
|
| 411 | - } else { |
|
| 412 | - if ($op == 'LIKE') { |
|
| 413 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | - $op = ''; |
|
| 416 | - } else { |
|
| 417 | - if ($op == '=') { |
|
| 418 | - $op = '=='; |
|
| 419 | - } else { |
|
| 420 | - if ($op == 'IN') { |
|
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | - $op = ''; |
|
| 423 | - } else { |
|
| 424 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | - $op = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($op) { |
|
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($not) { |
|
| 438 | - $filtre = "!($filtre)"; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return $filtre; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - public function next() : void { |
|
| 446 | - $this->pos++; |
|
| 447 | - parent::next(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * revient au depart |
|
| 452 | - * |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function rewind() : void { |
|
| 456 | - $this->pos = 0; |
|
| 457 | - $this->fetched = 0; |
|
| 458 | - parent::rewind(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - # Extension SPIP des iterateurs PHP |
|
| 463 | - /** |
|
| 464 | - * type de l'iterateur |
|
| 465 | - * |
|
| 466 | - * @var string |
|
| 467 | - */ |
|
| 468 | - protected $type; |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * parametres de l'iterateur |
|
| 472 | - * |
|
| 473 | - * @var array |
|
| 474 | - */ |
|
| 475 | - protected $command; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * infos de compilateur |
|
| 479 | - * |
|
| 480 | - * @var array |
|
| 481 | - */ |
|
| 482 | - protected $info; |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * position courante de l'iterateur |
|
| 486 | - * |
|
| 487 | - * @var int |
|
| 488 | - */ |
|
| 489 | - protected $pos = null; |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * nombre total resultats dans l'iterateur |
|
| 493 | - * |
|
| 494 | - * @var int |
|
| 495 | - */ |
|
| 496 | - protected $total = null; |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * nombre maximal de recherche pour $total |
|
| 500 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | - */ |
|
| 502 | - protected $max = 100000; |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Liste des champs a inserer dans les $row |
|
| 507 | - * retournes par ->fetch() |
|
| 508 | - */ |
|
| 509 | - protected $select = []; |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * aller a la position absolue n, |
|
| 514 | - * comptee depuis le debut |
|
| 515 | - * |
|
| 516 | - * @param int $n |
|
| 517 | - * absolute pos |
|
| 518 | - * @param string $continue |
|
| 519 | - * param for sql_ api |
|
| 520 | - * @return bool |
|
| 521 | - * success or fail if not implemented |
|
| 522 | - */ |
|
| 523 | - public function seek($n = 0, $continue = null) { |
|
| 524 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | - $this->seek_loop($n); |
|
| 526 | - } |
|
| 527 | - $this->pos = $n; |
|
| 528 | - $this->fetched = $n; |
|
| 529 | - |
|
| 530 | - return true; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /* |
|
| 223 | + // cle et valeur par defaut |
|
| 224 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | + if ( |
|
| 226 | + in_array($nom, ['cle', 'valeur']) |
|
| 227 | + and method_exists($this, $nom) |
|
| 228 | + ) { |
|
| 229 | + return $this->$nom(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Par defaut chercher en xpath dans la valeur() |
|
| 233 | + return table_valeur($this->valeur(), $nom, null); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + private function calculer_filtres() { |
|
| 238 | + |
|
| 239 | + // Issu de calculer_select() de public/composer L.519 |
|
| 240 | + // TODO: externaliser... |
|
| 241 | + // |
|
| 242 | + // retirer les criteres vides: |
|
| 243 | + // {X ?} avec X absent de l'URL |
|
| 244 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | + if ($where = &$this->command['where']) { |
|
| 247 | + foreach ($where as $k => $v) { |
|
| 248 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // critere {2,7} |
|
| 253 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | + $limit = explode(',', $this->command['limit']); |
|
| 255 | + $this->offset = $limit[0]; |
|
| 256 | + $this->limit = $limit[1]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Creer la fonction de filtrage sur $this |
|
| 260 | + if ($this->filtre) { |
|
| 261 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | + $filtres = 'return ' . $filtres . ';'; |
|
| 263 | + $this->func_filtre = fn() => eval($filtres); |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $this->func_filtre = null; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | + * les filtres vides ou null sont ignores |
|
| 274 | + * @param $filtres |
|
| 275 | + * @param string $operateur |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | + |
|
| 280 | + $filtres_string = []; |
|
| 281 | + foreach ($filtres as $k => $v) { |
|
| 282 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | + $op = array_shift($v); |
|
| 285 | + $v = $this->assembler_filtres($v, $op); |
|
| 286 | + } |
|
| 287 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $filtres_string[] = $v; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!count($filtres_string)) { |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Traduire un element du tableau where SQL en un filtre |
|
| 302 | + * @param $v |
|
| 303 | + * @return string|array|null |
|
| 304 | + */ |
|
| 305 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | + if (is_array($v)) { |
|
| 307 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | + return 'true'; |
|
| 309 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | + return 'true'; |
|
| 311 | + } else { |
|
| 312 | + $op = $v[0] ?: $v; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $op = $v; |
|
| 316 | + } |
|
| 317 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | + return 'true'; |
|
| 319 | + } |
|
| 320 | + if ($op === '0=1') { |
|
| 321 | + return 'false'; |
|
| 322 | + } |
|
| 323 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // 3 possibilites : count($v) = |
|
| 329 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | + |
|
| 333 | + // 1 : forcement traite par un critere, on passe |
|
| 334 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | + return null; // sera ignore |
|
| 336 | + } |
|
| 337 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | + } |
|
| 340 | + if (count($v) == 3) { |
|
| 341 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | + array_shift($v); |
|
| 344 | + foreach (array_keys($v) as $k) { |
|
| 345 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | + if ($v[$k] === null) { |
|
| 347 | + unset($v[$k]); |
|
| 348 | + } |
|
| 349 | + elseif ($v[$k] === 'true') { |
|
| 350 | + if ($op === 'OR') { |
|
| 351 | + return 'true'; |
|
| 352 | + } |
|
| 353 | + if ($op === 'AND') { |
|
| 354 | + unset($v[$k]); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + elseif ($v[$k] === 'false') { |
|
| 358 | + if ($op === 'OR') { |
|
| 359 | + unset($v[$k]); |
|
| 360 | + } |
|
| 361 | + if ($op === 'AND') { |
|
| 362 | + return 'false'; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + if (!count($v)) { |
|
| 367 | + return null; |
|
| 368 | + } |
|
| 369 | + if (count($v) === 1) { |
|
| 370 | + return reset($v); |
|
| 371 | + } |
|
| 372 | + array_unshift($v, $op); |
|
| 373 | + return $v; |
|
| 374 | + } |
|
| 375 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return null; // sera ignore |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Calculer un filtre sur un champ du tableau |
|
| 383 | + * @param $cle |
|
| 384 | + * @param $op |
|
| 385 | + * @param $valeur |
|
| 386 | + * @param false $not |
|
| 387 | + * @return string|null |
|
| 388 | + */ |
|
| 389 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | + |
|
| 401 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | + # return; |
|
| 403 | + |
|
| 404 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | + |
|
| 406 | + $filtre = ''; |
|
| 407 | + |
|
| 408 | + if ($op == 'REGEXP') { |
|
| 409 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | + $op = ''; |
|
| 411 | + } else { |
|
| 412 | + if ($op == 'LIKE') { |
|
| 413 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | + $op = ''; |
|
| 416 | + } else { |
|
| 417 | + if ($op == '=') { |
|
| 418 | + $op = '=='; |
|
| 419 | + } else { |
|
| 420 | + if ($op == 'IN') { |
|
| 421 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | + $op = ''; |
|
| 423 | + } else { |
|
| 424 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | + $op = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($op) { |
|
| 434 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($not) { |
|
| 438 | + $filtre = "!($filtre)"; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return $filtre; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + public function next() : void { |
|
| 446 | + $this->pos++; |
|
| 447 | + parent::next(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * revient au depart |
|
| 452 | + * |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function rewind() : void { |
|
| 456 | + $this->pos = 0; |
|
| 457 | + $this->fetched = 0; |
|
| 458 | + parent::rewind(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + # Extension SPIP des iterateurs PHP |
|
| 463 | + /** |
|
| 464 | + * type de l'iterateur |
|
| 465 | + * |
|
| 466 | + * @var string |
|
| 467 | + */ |
|
| 468 | + protected $type; |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * parametres de l'iterateur |
|
| 472 | + * |
|
| 473 | + * @var array |
|
| 474 | + */ |
|
| 475 | + protected $command; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * infos de compilateur |
|
| 479 | + * |
|
| 480 | + * @var array |
|
| 481 | + */ |
|
| 482 | + protected $info; |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * position courante de l'iterateur |
|
| 486 | + * |
|
| 487 | + * @var int |
|
| 488 | + */ |
|
| 489 | + protected $pos = null; |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * nombre total resultats dans l'iterateur |
|
| 493 | + * |
|
| 494 | + * @var int |
|
| 495 | + */ |
|
| 496 | + protected $total = null; |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * nombre maximal de recherche pour $total |
|
| 500 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | + */ |
|
| 502 | + protected $max = 100000; |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Liste des champs a inserer dans les $row |
|
| 507 | + * retournes par ->fetch() |
|
| 508 | + */ |
|
| 509 | + protected $select = []; |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * aller a la position absolue n, |
|
| 514 | + * comptee depuis le debut |
|
| 515 | + * |
|
| 516 | + * @param int $n |
|
| 517 | + * absolute pos |
|
| 518 | + * @param string $continue |
|
| 519 | + * param for sql_ api |
|
| 520 | + * @return bool |
|
| 521 | + * success or fail if not implemented |
|
| 522 | + */ |
|
| 523 | + public function seek($n = 0, $continue = null) { |
|
| 524 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | + $this->seek_loop($n); |
|
| 526 | + } |
|
| 527 | + $this->pos = $n; |
|
| 528 | + $this->fetched = $n; |
|
| 529 | + |
|
| 530 | + return true; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /* |
|
| 534 | 534 | * aller a la position $n en parcourant |
| 535 | 535 | * un par un tous les elements |
| 536 | 536 | */ |
| 537 | - private function seek_loop($n) { |
|
| 538 | - if ($this->pos > $n) { |
|
| 539 | - $this->rewind(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - while ($this->pos < $n and $this->valid()) { |
|
| 543 | - $this->next(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Avancer de $saut pas |
|
| 551 | - * |
|
| 552 | - * @param $saut |
|
| 553 | - * @param $max |
|
| 554 | - * @return int |
|
| 555 | - */ |
|
| 556 | - public function skip($saut, $max = null) { |
|
| 557 | - // pas de saut en arriere autorise pour cette fonction |
|
| 558 | - if (($saut = intval($saut)) <= 0) { |
|
| 559 | - return $this->pos; |
|
| 560 | - } |
|
| 561 | - $seek = $this->pos + $saut; |
|
| 562 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | - // et on sort |
|
| 564 | - if (is_null($max)) { |
|
| 565 | - $max = $this->count(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | - $this->free(); |
|
| 571 | - |
|
| 572 | - return $max; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $this->seek($seek); |
|
| 576 | - |
|
| 577 | - return $this->pos; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Renvoyer un tableau des donnees correspondantes |
|
| 582 | - * a la position courante de l'iterateur |
|
| 583 | - * en controlant si on respecte le filtre |
|
| 584 | - * Appliquer aussi le critere {offset,limit} |
|
| 585 | - * |
|
| 586 | - * @return array|bool |
|
| 587 | - */ |
|
| 588 | - public function fetch() { |
|
| 589 | - if (method_exists($this->iter, 'fetch')) { |
|
| 590 | - return $this->iter->fetch(); |
|
| 591 | - } else { |
|
| 592 | - while ( |
|
| 593 | - $this->valid() |
|
| 594 | - and ( |
|
| 595 | - !$this->accept() |
|
| 596 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->next(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if (!$this->valid()) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ( |
|
| 607 | - isset($this->limit) |
|
| 608 | - and $this->fetched > $this->offset + $this->limit |
|
| 609 | - ) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $r = []; |
|
| 614 | - foreach ($this->select as $nom) { |
|
| 615 | - $r[$nom] = $this->get_select($nom); |
|
| 616 | - } |
|
| 617 | - $this->next(); |
|
| 618 | - |
|
| 619 | - return $r; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // retourner la cle pour #CLE |
|
| 624 | - public function cle() { |
|
| 625 | - return $this->key(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // retourner la valeur pour #VALEUR |
|
| 629 | - public function valeur() { |
|
| 630 | - return $this->current(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Accepte-t-on l'entree courante lue ? |
|
| 635 | - * On execute les filtres pour le savoir. |
|
| 636 | - **/ |
|
| 637 | - public function accept(): bool { |
|
| 638 | - if ($f = $this->func_filtre) { |
|
| 639 | - return $f(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * liberer la ressource |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function free() { |
|
| 651 | - if (method_exists($this->iter, 'free')) { |
|
| 652 | - $this->iter->free(); |
|
| 653 | - } |
|
| 654 | - $this->pos = $this->total = 0; |
|
| 655 | - |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Compter le nombre total de resultats |
|
| 661 | - * pour #TOTAL_BOUCLE |
|
| 662 | - * |
|
| 663 | - * @return int |
|
| 664 | - */ |
|
| 665 | - public function count() { |
|
| 666 | - if (is_null($this->total)) { |
|
| 667 | - if ( |
|
| 668 | - method_exists($this->iter, 'count') |
|
| 669 | - and !$this->func_filtre |
|
| 670 | - ) { |
|
| 671 | - return $this->total = $this->iter->count(); |
|
| 672 | - } else { |
|
| 673 | - // compter les lignes et rembobiner |
|
| 674 | - $total = 0; |
|
| 675 | - $pos = $this->pos; // sauver la position |
|
| 676 | - $this->rewind(); |
|
| 677 | - while ($this->fetch() and $total < $this->max) { |
|
| 678 | - $total++; |
|
| 679 | - } |
|
| 680 | - $this->seek($pos); |
|
| 681 | - $this->total = $total; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $this->total; |
|
| 686 | - } |
|
| 537 | + private function seek_loop($n) { |
|
| 538 | + if ($this->pos > $n) { |
|
| 539 | + $this->rewind(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + while ($this->pos < $n and $this->valid()) { |
|
| 543 | + $this->next(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Avancer de $saut pas |
|
| 551 | + * |
|
| 552 | + * @param $saut |
|
| 553 | + * @param $max |
|
| 554 | + * @return int |
|
| 555 | + */ |
|
| 556 | + public function skip($saut, $max = null) { |
|
| 557 | + // pas de saut en arriere autorise pour cette fonction |
|
| 558 | + if (($saut = intval($saut)) <= 0) { |
|
| 559 | + return $this->pos; |
|
| 560 | + } |
|
| 561 | + $seek = $this->pos + $saut; |
|
| 562 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | + // et on sort |
|
| 564 | + if (is_null($max)) { |
|
| 565 | + $max = $this->count(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | + $this->free(); |
|
| 571 | + |
|
| 572 | + return $max; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->seek($seek); |
|
| 576 | + |
|
| 577 | + return $this->pos; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Renvoyer un tableau des donnees correspondantes |
|
| 582 | + * a la position courante de l'iterateur |
|
| 583 | + * en controlant si on respecte le filtre |
|
| 584 | + * Appliquer aussi le critere {offset,limit} |
|
| 585 | + * |
|
| 586 | + * @return array|bool |
|
| 587 | + */ |
|
| 588 | + public function fetch() { |
|
| 589 | + if (method_exists($this->iter, 'fetch')) { |
|
| 590 | + return $this->iter->fetch(); |
|
| 591 | + } else { |
|
| 592 | + while ( |
|
| 593 | + $this->valid() |
|
| 594 | + and ( |
|
| 595 | + !$this->accept() |
|
| 596 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->next(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if (!$this->valid()) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ( |
|
| 607 | + isset($this->limit) |
|
| 608 | + and $this->fetched > $this->offset + $this->limit |
|
| 609 | + ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $r = []; |
|
| 614 | + foreach ($this->select as $nom) { |
|
| 615 | + $r[$nom] = $this->get_select($nom); |
|
| 616 | + } |
|
| 617 | + $this->next(); |
|
| 618 | + |
|
| 619 | + return $r; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // retourner la cle pour #CLE |
|
| 624 | + public function cle() { |
|
| 625 | + return $this->key(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // retourner la valeur pour #VALEUR |
|
| 629 | + public function valeur() { |
|
| 630 | + return $this->current(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Accepte-t-on l'entree courante lue ? |
|
| 635 | + * On execute les filtres pour le savoir. |
|
| 636 | + **/ |
|
| 637 | + public function accept(): bool { |
|
| 638 | + if ($f = $this->func_filtre) { |
|
| 639 | + return $f(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * liberer la ressource |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function free() { |
|
| 651 | + if (method_exists($this->iter, 'free')) { |
|
| 652 | + $this->iter->free(); |
|
| 653 | + } |
|
| 654 | + $this->pos = $this->total = 0; |
|
| 655 | + |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Compter le nombre total de resultats |
|
| 661 | + * pour #TOTAL_BOUCLE |
|
| 662 | + * |
|
| 663 | + * @return int |
|
| 664 | + */ |
|
| 665 | + public function count() { |
|
| 666 | + if (is_null($this->total)) { |
|
| 667 | + if ( |
|
| 668 | + method_exists($this->iter, 'count') |
|
| 669 | + and !$this->func_filtre |
|
| 670 | + ) { |
|
| 671 | + return $this->total = $this->iter->count(); |
|
| 672 | + } else { |
|
| 673 | + // compter les lignes et rembobiner |
|
| 674 | + $total = 0; |
|
| 675 | + $pos = $this->pos; // sauver la position |
|
| 676 | + $this->rewind(); |
|
| 677 | + while ($this->fetch() and $total < $this->max) { |
|
| 678 | + $total++; |
|
| 679 | + } |
|
| 680 | + $this->seek($pos); |
|
| 681 | + $this->total = $total; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $this->total; |
|
| 686 | + } |
|
| 687 | 687 | } |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | // (pas glop) |
| 54 | 54 | try { |
| 55 | 55 | switch (is_countable($a) ? count($a) : 0) { |
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 56 | + case 0 : $iter = new $iterateur(); |
|
| 58 | 57 | break; |
| 59 | 58 | case 1: |
| 60 | 59 | $iter = new $iterateur($a[0]); |
@@ -79,10 +78,10 @@ discard block |
||
| 79 | 78 | // chercher la classe d'iterateur |
| 80 | 79 | // IterateurXXX |
| 81 | 80 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 81 | + $class = 'Iterateur'.$iterateur; |
|
| 83 | 82 | if (!class_exists($class)) { |
| 84 | 83 | if ( |
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 84 | + !include_spip('iterateur/'.strtolower($iterateur)) |
|
| 86 | 85 | or !class_exists($class) |
| 87 | 86 | ) { |
| 88 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -210,7 +209,7 @@ discard block |
||
| 210 | 209 | return $this->iter->$nom(); |
| 211 | 210 | } catch (Exception $e) { |
| 212 | 211 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 214 | 213 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 215 | 214 | |
| 216 | 215 | return ''; |
@@ -259,7 +258,7 @@ discard block |
||
| 259 | 258 | // Creer la fonction de filtrage sur $this |
| 260 | 259 | if ($this->filtre) { |
| 261 | 260 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 261 | + $filtres = 'return '.$filtres.';'; |
|
| 263 | 262 | $this->func_filtre = fn() => eval($filtres); |
| 264 | 263 | } |
| 265 | 264 | else { |
@@ -294,7 +293,7 @@ discard block |
||
| 294 | 293 | return null; |
| 295 | 294 | } |
| 296 | 295 | |
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 296 | + return '('.implode(") $operateur (", $filtres_string).')'; |
|
| 298 | 297 | } |
| 299 | 298 | |
| 300 | 299 | /** |
@@ -375,7 +374,7 @@ discard block |
||
| 375 | 374 | return $this->composer_filtre($v[1], $v[0], $v[2]); |
| 376 | 375 | } |
| 377 | 376 | |
| 378 | - return null; // sera ignore |
|
| 377 | + return null; // sera ignore |
|
| 379 | 378 | } |
| 380 | 379 | |
| 381 | 380 | /** |
@@ -401,28 +400,28 @@ discard block |
||
| 401 | 400 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 402 | 401 | # return; |
| 403 | 402 | |
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 403 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 405 | 404 | |
| 406 | 405 | $filtre = ''; |
| 407 | 406 | |
| 408 | 407 | if ($op == 'REGEXP') { |
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 408 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 410 | 409 | $op = ''; |
| 411 | 410 | } else { |
| 412 | 411 | if ($op == 'LIKE') { |
| 413 | 412 | $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 413 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 415 | 414 | $op = ''; |
| 416 | 415 | } else { |
| 417 | 416 | if ($op == '=') { |
| 418 | 417 | $op = '=='; |
| 419 | 418 | } else { |
| 420 | 419 | if ($op == 'IN') { |
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 420 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 422 | 421 | $op = ''; |
| 423 | 422 | } else { |
| 424 | 423 | if (!in_array($op, ['<', '<=', '>', '>='])) { |
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 424 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 426 | 425 | $op = ''; |
| 427 | 426 | } |
| 428 | 427 | } |
@@ -431,7 +430,7 @@ discard block |
||
| 431 | 430 | } |
| 432 | 431 | |
| 433 | 432 | if ($op) { |
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 433 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 435 | 434 | } |
| 436 | 435 | |
| 437 | 436 | if ($not) { |
@@ -261,8 +261,7 @@ discard block |
||
| 261 | 261 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | 262 | $filtres = 'return ' . $filtres . ';'; |
| 263 | 263 | $this->func_filtre = fn() => eval($filtres); |
| 264 | - } |
|
| 265 | - else { |
|
| 264 | + } else { |
|
| 266 | 265 | $this->func_filtre = null; |
| 267 | 266 | } |
| 268 | 267 | } |
@@ -345,16 +344,14 @@ discard block |
||
| 345 | 344 | $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
| 346 | 345 | if ($v[$k] === null) { |
| 347 | 346 | unset($v[$k]); |
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 347 | + } elseif ($v[$k] === 'true') { |
|
| 350 | 348 | if ($op === 'OR') { |
| 351 | 349 | return 'true'; |
| 352 | 350 | } |
| 353 | 351 | if ($op === 'AND') { |
| 354 | 352 | unset($v[$k]); |
| 355 | 353 | } |
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 354 | + } elseif ($v[$k] === 'false') { |
|
| 358 | 355 | if ($op === 'OR') { |
| 359 | 356 | unset($v[$k]); |
| 360 | 357 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return sql_getfetsel( |
| 37 | 37 | 'virtuel', |
| 38 | 38 | 'spip_articles', |
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 39 | + ['id_article='.intval($id_article), "statut='publie'"], |
|
| 40 | 40 | '', |
| 41 | 41 | '', |
| 42 | 42 | '', |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $cache_quete[$connect][$table][$id] = sql_fetsel( |
| 82 | 82 | $cache_quete[$connect][$table]['_select'], |
| 83 | 83 | $table, |
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 84 | + $cache_quete[$connect][$table]['_id'].'='.intval($id), |
|
| 85 | 85 | '', |
| 86 | 86 | '', |
| 87 | 87 | '', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return |
| 174 | 174 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 175 | 175 | and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 176 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | 177 | : '1=1'; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | and $id_table = reset($objet) |
| 233 | 233 | and $objet = objet_type($id_table) |
| 234 | 234 | ) { |
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 235 | + $w = "$mstatut<>".sql_quote($v); |
|
| 236 | 236 | |
| 237 | 237 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 238 | 238 | // sinon l’auteur en session |
@@ -246,22 +246,22 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 249 | + if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) { |
|
| 250 | 250 | // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
| 251 | 251 | if (!$id_auteur) { |
| 252 | 252 | $where[] = $w; |
| 253 | 253 | } else { |
| 254 | 254 | $primary = id_table_objet($objet); |
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (".sql_get_select( |
|
| 256 | 256 | 'ssss.id_objet', |
| 257 | 257 | 'spip_auteurs_liens AS ssss', |
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 258 | + 'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur), |
|
| 259 | 259 | '', |
| 260 | 260 | '', |
| 261 | 261 | '', |
| 262 | 262 | '', |
| 263 | 263 | $serveur |
| 264 | - ) . '))'; |
|
| 264 | + ).'))'; |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } // ignorer ce statut si on ne sait pas comment le filtrer |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | // qui permet de distinguer le changement de logo |
| 378 | 378 | // et placer un expire sur le dossier IMG/ |
| 379 | 379 | $res = [ |
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 380 | + $on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' '.$taille[3])) |
|
| 383 | 383 | ]; |
| 384 | 384 | $res['src'] = $res[0]; |
| 385 | 385 | $res['logo_on'] = $res[0]; |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if ( |
| 477 | 477 | strcmp($logo, _DIR_PLUGINS) == 0 |
| 478 | 478 | or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE.'prive/') == 0 |
|
| 480 | 480 | ) { |
| 481 | 481 | return $logo; |
| 482 | 482 | } |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $exposer[$m][$type][$principal] = true; |
| 647 | 647 | if ($type == 'id_mot') { |
| 648 | 648 | if (!$parent) { |
| 649 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 649 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect); |
|
| 650 | 650 | } |
| 651 | 651 | if ($parent) { |
| 652 | 652 | $exposer[$m]['id_groupe'][$parent] = true; |
@@ -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 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, string $connect = '') { |
| 60 | - static $cache_quete = []; |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if ( |
|
| 66 | - !$desc = $trouver_table( |
|
| 67 | - $table, |
|
| 68 | - $connect |
|
| 69 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | - ) { |
|
| 71 | - // pas de parent rubrique, on passe |
|
| 72 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | - } else { |
|
| 74 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | - $cache_quete[$connect][$table]['_select'], |
|
| 83 | - $table, |
|
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - '', |
|
| 89 | - $connect |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $cache_quete[$connect][$table][$id] ?? null; |
|
| 60 | + static $cache_quete = []; |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if ( |
|
| 66 | + !$desc = $trouver_table( |
|
| 67 | + $table, |
|
| 68 | + $connect |
|
| 69 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | + ) { |
|
| 71 | + // pas de parent rubrique, on passe |
|
| 72 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | + } else { |
|
| 74 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | + $cache_quete[$connect][$table]['_select'], |
|
| 83 | + $table, |
|
| 84 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + '', |
|
| 89 | + $connect |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $cache_quete[$connect][$table][$id] ?? null; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | function quete_parent($id_rubrique, string $connect = '') { |
| 111 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | - return 0; |
|
| 113 | - } |
|
| 114 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 111 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | function quete_rubrique($id_article, $serveur) { |
| 131 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 132 | 132 | |
| 133 | - return $id_parent['id_rubrique']; |
|
| 133 | + return $id_parent['id_rubrique']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * @return int |
| 145 | 145 | */ |
| 146 | 146 | function quete_profondeur($id, string $connect = '') { |
| 147 | - $n = 0; |
|
| 148 | - while ($id) { |
|
| 149 | - $n++; |
|
| 150 | - $id = quete_parent($id, $connect); |
|
| 151 | - } |
|
| 147 | + $n = 0; |
|
| 148 | + while ($id) { |
|
| 149 | + $n++; |
|
| 150 | + $id = quete_parent($id, $connect); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $n; |
|
| 153 | + return $n; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * Morceau de la requête SQL testant la date |
| 167 | 167 | */ |
| 168 | 168 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 169 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | - return '1=1'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return |
|
| 174 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | - : '1=1'; |
|
| 169 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | + return '1=1'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return |
|
| 174 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | + : '1=1'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -194,101 +194,101 @@ discard block |
||
| 194 | 194 | * @return array|string |
| 195 | 195 | */ |
| 196 | 196 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 197 | - static $cond = []; |
|
| 198 | - $key = func_get_args(); |
|
| 199 | - $key = implode('-', $key); |
|
| 200 | - if (isset($cond[$key])) { |
|
| 201 | - return $cond[$key]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $liste_statuts = $publie; |
|
| 205 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | - $liste_statuts = $previsu; |
|
| 207 | - } |
|
| 208 | - $not = false; |
|
| 209 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | - $not = true; |
|
| 211 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | - } |
|
| 213 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | - if (!strlen($liste_statuts)) { |
|
| 215 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | - $where = []; |
|
| 220 | - foreach ($liste_statuts as $k => $v) { |
|
| 221 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | - // a ceux de l'auteur identifie |
|
| 223 | - if (strpos($v, '/') !== false) { |
|
| 224 | - $v = explode('/', $v); |
|
| 225 | - $filtre = end($v); |
|
| 226 | - $v = reset($v); |
|
| 227 | - $v = preg_replace(',\W,', '', $v); |
|
| 228 | - if ( |
|
| 229 | - $filtre == 'auteur' |
|
| 230 | - and (strpos($mstatut, '.') !== false) |
|
| 231 | - and $objet = explode('.', $mstatut) |
|
| 232 | - and $id_table = reset($objet) |
|
| 233 | - and $objet = objet_type($id_table) |
|
| 234 | - ) { |
|
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | - |
|
| 237 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | - // sinon l’auteur en session |
|
| 239 | - include_spip('inc/securiser_action'); |
|
| 240 | - if ($desc = decrire_token_previsu()) { |
|
| 241 | - $id_auteur = $desc['id_auteur']; |
|
| 242 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | - } else { |
|
| 245 | - $id_auteur = null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | - if (!$id_auteur) { |
|
| 252 | - $where[] = $w; |
|
| 253 | - } else { |
|
| 254 | - $primary = id_table_objet($objet); |
|
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | - 'ssss.id_objet', |
|
| 257 | - 'spip_auteurs_liens AS ssss', |
|
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - '', |
|
| 263 | - $serveur |
|
| 264 | - ) . '))'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | - else { |
|
| 269 | - $v = ''; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // securite |
|
| 273 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | - } |
|
| 275 | - $liste_statuts = array_filter($liste_statuts); |
|
| 276 | - if (count($liste_statuts) == 1) { |
|
| 277 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | - } else { |
|
| 279 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - while (count($where) > 1) { |
|
| 283 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | - $where[] = $and; |
|
| 285 | - } |
|
| 286 | - $cond[$key] = reset($where); |
|
| 287 | - if ($not) { |
|
| 288 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $cond[$key]; |
|
| 197 | + static $cond = []; |
|
| 198 | + $key = func_get_args(); |
|
| 199 | + $key = implode('-', $key); |
|
| 200 | + if (isset($cond[$key])) { |
|
| 201 | + return $cond[$key]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $liste_statuts = $publie; |
|
| 205 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | + $liste_statuts = $previsu; |
|
| 207 | + } |
|
| 208 | + $not = false; |
|
| 209 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | + $not = true; |
|
| 211 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | + } |
|
| 213 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | + if (!strlen($liste_statuts)) { |
|
| 215 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | + $where = []; |
|
| 220 | + foreach ($liste_statuts as $k => $v) { |
|
| 221 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | + // a ceux de l'auteur identifie |
|
| 223 | + if (strpos($v, '/') !== false) { |
|
| 224 | + $v = explode('/', $v); |
|
| 225 | + $filtre = end($v); |
|
| 226 | + $v = reset($v); |
|
| 227 | + $v = preg_replace(',\W,', '', $v); |
|
| 228 | + if ( |
|
| 229 | + $filtre == 'auteur' |
|
| 230 | + and (strpos($mstatut, '.') !== false) |
|
| 231 | + and $objet = explode('.', $mstatut) |
|
| 232 | + and $id_table = reset($objet) |
|
| 233 | + and $objet = objet_type($id_table) |
|
| 234 | + ) { |
|
| 235 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | + |
|
| 237 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | + // sinon l’auteur en session |
|
| 239 | + include_spip('inc/securiser_action'); |
|
| 240 | + if ($desc = decrire_token_previsu()) { |
|
| 241 | + $id_auteur = $desc['id_auteur']; |
|
| 242 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | + } else { |
|
| 245 | + $id_auteur = null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | + if (!$id_auteur) { |
|
| 252 | + $where[] = $w; |
|
| 253 | + } else { |
|
| 254 | + $primary = id_table_objet($objet); |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | + 'ssss.id_objet', |
|
| 257 | + 'spip_auteurs_liens AS ssss', |
|
| 258 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + '', |
|
| 263 | + $serveur |
|
| 264 | + ) . '))'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | + else { |
|
| 269 | + $v = ''; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // securite |
|
| 273 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | + } |
|
| 275 | + $liste_statuts = array_filter($liste_statuts); |
|
| 276 | + if (count($liste_statuts) == 1) { |
|
| 277 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | + } else { |
|
| 279 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + while (count($where) > 1) { |
|
| 283 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | + $where[] = $and; |
|
| 285 | + } |
|
| 286 | + $cond[$key] = reset($where); |
|
| 287 | + if ($not) { |
|
| 288 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $cond[$key]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -347,66 +347,66 @@ discard block |
||
| 347 | 347 | * Retourne soit un tableau, soit le chemin du fichier. |
| 348 | 348 | */ |
| 349 | 349 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 350 | - include_spip('base/objets'); |
|
| 351 | - $nom = strtolower($onoff); |
|
| 352 | - |
|
| 353 | - $cle_objet = id_table_objet($cle_objet); |
|
| 354 | - |
|
| 355 | - while (1) { |
|
| 356 | - $objet = objet_type($cle_objet); |
|
| 357 | - |
|
| 358 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | - |
|
| 360 | - if ($on) { |
|
| 361 | - if ($flag) { |
|
| 362 | - return basename($on['chemin']); |
|
| 363 | - } else { |
|
| 364 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | - |
|
| 366 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | - // alors on ne cherche pas du tout le survol ici |
|
| 369 | - if ($onoff != 'ON') { |
|
| 370 | - $off = ''; |
|
| 371 | - } else { |
|
| 372 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | - // qui permet de distinguer le changement de logo |
|
| 378 | - // et placer un expire sur le dossier IMG/ |
|
| 379 | - $res = [ |
|
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | - ]; |
|
| 384 | - $res['src'] = $res[0]; |
|
| 385 | - $res['logo_on'] = $res[0]; |
|
| 386 | - $res['logo_off'] = $res[1]; |
|
| 387 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | - |
|
| 390 | - return $res; |
|
| 391 | - } |
|
| 392 | - } else { |
|
| 393 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | - return ''; |
|
| 395 | - } else { |
|
| 396 | - if ($id_rubrique) { |
|
| 397 | - $cle_objet = 'id_rubrique'; |
|
| 398 | - $id = $id_rubrique; |
|
| 399 | - $id_rubrique = 0; |
|
| 400 | - } else { |
|
| 401 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | - $id = quete_parent($id); |
|
| 403 | - } else { |
|
| 404 | - return ''; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 350 | + include_spip('base/objets'); |
|
| 351 | + $nom = strtolower($onoff); |
|
| 352 | + |
|
| 353 | + $cle_objet = id_table_objet($cle_objet); |
|
| 354 | + |
|
| 355 | + while (1) { |
|
| 356 | + $objet = objet_type($cle_objet); |
|
| 357 | + |
|
| 358 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | + |
|
| 360 | + if ($on) { |
|
| 361 | + if ($flag) { |
|
| 362 | + return basename($on['chemin']); |
|
| 363 | + } else { |
|
| 364 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | + |
|
| 366 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | + // alors on ne cherche pas du tout le survol ici |
|
| 369 | + if ($onoff != 'ON') { |
|
| 370 | + $off = ''; |
|
| 371 | + } else { |
|
| 372 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | + // qui permet de distinguer le changement de logo |
|
| 378 | + // et placer un expire sur le dossier IMG/ |
|
| 379 | + $res = [ |
|
| 380 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | + ]; |
|
| 384 | + $res['src'] = $res[0]; |
|
| 385 | + $res['logo_on'] = $res[0]; |
|
| 386 | + $res['logo_off'] = $res[1]; |
|
| 387 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | + |
|
| 390 | + return $res; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | + return ''; |
|
| 395 | + } else { |
|
| 396 | + if ($id_rubrique) { |
|
| 397 | + $cle_objet = 'id_rubrique'; |
|
| 398 | + $id = $id_rubrique; |
|
| 399 | + $id_rubrique = 0; |
|
| 400 | + } else { |
|
| 401 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | + $id = quete_parent($id); |
|
| 403 | + } else { |
|
| 404 | + return ''; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,37 +420,37 @@ discard block |
||
| 420 | 420 | * "on" ou "off" suivant le logo normal ou survol |
| 421 | 421 | **/ |
| 422 | 422 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 423 | - static $chercher_logo; |
|
| 424 | - if (is_null($chercher_logo)) { |
|
| 425 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | - } |
|
| 427 | - $cle_objet = id_table_objet($objet); |
|
| 428 | - |
|
| 429 | - // On cherche pas la méthode classique |
|
| 430 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | - if (!empty($infos_logo)) { |
|
| 433 | - $infos_logo = [ |
|
| 434 | - 'chemin' => $infos_logo[0], |
|
| 435 | - 'timestamp' => $infos_logo[4], |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // On passe cette recherche de logo dans un pipeline |
|
| 440 | - $infos_logo = pipeline( |
|
| 441 | - 'quete_logo_objet', |
|
| 442 | - [ |
|
| 443 | - 'args' => [ |
|
| 444 | - 'id_objet' => $id_objet, |
|
| 445 | - 'objet' => $objet, |
|
| 446 | - 'cle_objet' => $cle_objet, |
|
| 447 | - 'mode' => $mode, |
|
| 448 | - ], |
|
| 449 | - 'data' => $infos_logo, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - return $infos_logo; |
|
| 423 | + static $chercher_logo; |
|
| 424 | + if (is_null($chercher_logo)) { |
|
| 425 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | + } |
|
| 427 | + $cle_objet = id_table_objet($objet); |
|
| 428 | + |
|
| 429 | + // On cherche pas la méthode classique |
|
| 430 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | + if (!empty($infos_logo)) { |
|
| 433 | + $infos_logo = [ |
|
| 434 | + 'chemin' => $infos_logo[0], |
|
| 435 | + 'timestamp' => $infos_logo[4], |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // On passe cette recherche de logo dans un pipeline |
|
| 440 | + $infos_logo = pipeline( |
|
| 441 | + 'quete_logo_objet', |
|
| 442 | + [ |
|
| 443 | + 'args' => [ |
|
| 444 | + 'id_objet' => $id_objet, |
|
| 445 | + 'objet' => $objet, |
|
| 446 | + 'cle_objet' => $cle_objet, |
|
| 447 | + 'mode' => $mode, |
|
| 448 | + ], |
|
| 449 | + 'data' => $infos_logo, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + return $infos_logo; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @return bool|string |
| 464 | 464 | */ |
| 465 | 465 | function quete_logo_file($row, $connect = null) { |
| 466 | - include_spip('inc/documents'); |
|
| 467 | - $logo = vignette_logo_document($row, $connect); |
|
| 468 | - if (!$logo) { |
|
| 469 | - $logo = image_du_document($row, $connect); |
|
| 470 | - } |
|
| 471 | - if (!$logo) { |
|
| 472 | - $f = charger_fonction('vignette', 'inc'); |
|
| 473 | - $logo = $f($row['extension'], false); |
|
| 474 | - } |
|
| 475 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | - if ( |
|
| 477 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | - ) { |
|
| 481 | - return $logo; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return get_spip_doc($logo); |
|
| 466 | + include_spip('inc/documents'); |
|
| 467 | + $logo = vignette_logo_document($row, $connect); |
|
| 468 | + if (!$logo) { |
|
| 469 | + $logo = image_du_document($row, $connect); |
|
| 470 | + } |
|
| 471 | + if (!$logo) { |
|
| 472 | + $f = charger_fonction('vignette', 'inc'); |
|
| 473 | + $logo = $f($row['extension'], false); |
|
| 474 | + } |
|
| 475 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | + if ( |
|
| 477 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | + ) { |
|
| 481 | + return $logo; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return get_spip_doc($logo); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 511 | 511 | |
| 512 | - include_spip('inc/documents'); |
|
| 513 | - $logo = ''; |
|
| 514 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | - $logo = vignette_logo_document($row, $connect); |
|
| 516 | - } |
|
| 517 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | - return ''; |
|
| 520 | - } |
|
| 521 | - if ($mode_logo == 'icone') { |
|
| 522 | - $row['fichier'] = ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 512 | + include_spip('inc/documents'); |
|
| 513 | + $logo = ''; |
|
| 514 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | + $logo = vignette_logo_document($row, $connect); |
|
| 516 | + } |
|
| 517 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | + return ''; |
|
| 520 | + } |
|
| 521 | + if ($mode_logo == 'icone') { |
|
| 522 | + $row['fichier'] = ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function quete_html_logo($logo, $align, $lien) { |
| 536 | 536 | |
| 537 | - if (!is_array($logo)) { |
|
| 538 | - return ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - $contexte = []; |
|
| 542 | - foreach ($logo as $k => $v) { |
|
| 543 | - if (!is_numeric($k)) { |
|
| 544 | - $contexte[$k] = $v; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - $contexte['align'] = $align; |
|
| 548 | - $contexte['lien'] = $lien; |
|
| 549 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 537 | + if (!is_array($logo)) { |
|
| 538 | + return ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + $contexte = []; |
|
| 542 | + foreach ($logo as $k => $v) { |
|
| 543 | + if (!is_numeric($k)) { |
|
| 544 | + $contexte[$k] = $v; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + $contexte['align'] = $align; |
|
| 548 | + $contexte['lien'] = $lien; |
|
| 549 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return string|false |
| 561 | 561 | */ |
| 562 | 562 | function document_spip_externe($fichier, $connect) { |
| 563 | - if ($connect) { |
|
| 564 | - $site = quete_meta('adresse_site', $connect); |
|
| 565 | - if ($site) { |
|
| 566 | - $dir = quete_meta('dir_img', $connect); |
|
| 567 | - return "$site/$dir$fichier"; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 563 | + if ($connect) { |
|
| 564 | + $site = quete_meta('adresse_site', $connect); |
|
| 565 | + if ($site) { |
|
| 566 | + $dir = quete_meta('dir_img', $connect); |
|
| 567 | + return "$site/$dir$fichier"; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -581,23 +581,23 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | function vignette_logo_document($row, string $connect = '') { |
| 583 | 583 | |
| 584 | - if (!$row or empty($row['id_vignette'])) { |
|
| 585 | - return ''; |
|
| 586 | - } |
|
| 587 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 588 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 589 | - return $url; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $f = get_spip_doc($fichier); |
|
| 593 | - if ($f and @file_exists($f)) { |
|
| 594 | - return $f; |
|
| 595 | - } |
|
| 596 | - if ($row['mode'] !== 'vignette') { |
|
| 597 | - return ''; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 584 | + if (!$row or empty($row['id_vignette'])) { |
|
| 585 | + return ''; |
|
| 586 | + } |
|
| 587 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 588 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 589 | + return $url; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $f = get_spip_doc($fichier); |
|
| 593 | + if ($f and @file_exists($f)) { |
|
| 594 | + return $f; |
|
| 595 | + } |
|
| 596 | + if ($row['mode'] !== 'vignette') { |
|
| 597 | + return ''; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -613,66 +613,66 @@ discard block |
||
| 613 | 613 | * @return bool|string |
| 614 | 614 | */ |
| 615 | 615 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 616 | - static $exposer = []; |
|
| 617 | - |
|
| 618 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 619 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 620 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 621 | - // en static. |
|
| 622 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 623 | - $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 624 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 625 | - // il n'est donc pas utile |
|
| 626 | - $parent = 0; |
|
| 627 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 628 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 629 | - if (isset($enfants[$type])) { |
|
| 630 | - foreach ($enfants[$type] as $t) { |
|
| 631 | - if ( |
|
| 632 | - isset($reference[$t]) |
|
| 633 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 634 | - or isset($reference["@$t"]) |
|
| 635 | - ) { |
|
| 636 | - $type = $t; |
|
| 637 | - $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 638 | - continue; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - $exposer[$m][$type] = []; |
|
| 644 | - if ($principal) { |
|
| 645 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 646 | - foreach ($principaux as $principal) { |
|
| 647 | - $exposer[$m][$type][$principal] = true; |
|
| 648 | - if ($type == 'id_mot') { |
|
| 649 | - if (!$parent) { |
|
| 650 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 651 | - } |
|
| 652 | - if ($parent) { |
|
| 653 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 654 | - } |
|
| 655 | - } else { |
|
| 656 | - if ($type != 'id_groupe') { |
|
| 657 | - if (!$parent) { |
|
| 658 | - if ($type == 'id_rubrique') { |
|
| 659 | - $parent = $principal; |
|
| 660 | - } |
|
| 661 | - if ($type == 'id_article') { |
|
| 662 | - $parent = quete_rubrique($principal, $connect); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - do { |
|
| 666 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 667 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - // And the winner is... |
|
| 675 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 616 | + static $exposer = []; |
|
| 617 | + |
|
| 618 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 619 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 620 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 621 | + // en static. |
|
| 622 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 623 | + $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 624 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 625 | + // il n'est donc pas utile |
|
| 626 | + $parent = 0; |
|
| 627 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 628 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 629 | + if (isset($enfants[$type])) { |
|
| 630 | + foreach ($enfants[$type] as $t) { |
|
| 631 | + if ( |
|
| 632 | + isset($reference[$t]) |
|
| 633 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 634 | + or isset($reference["@$t"]) |
|
| 635 | + ) { |
|
| 636 | + $type = $t; |
|
| 637 | + $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 638 | + continue; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + $exposer[$m][$type] = []; |
|
| 644 | + if ($principal) { |
|
| 645 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 646 | + foreach ($principaux as $principal) { |
|
| 647 | + $exposer[$m][$type][$principal] = true; |
|
| 648 | + if ($type == 'id_mot') { |
|
| 649 | + if (!$parent) { |
|
| 650 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 651 | + } |
|
| 652 | + if ($parent) { |
|
| 653 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 654 | + } |
|
| 655 | + } else { |
|
| 656 | + if ($type != 'id_groupe') { |
|
| 657 | + if (!$parent) { |
|
| 658 | + if ($type == 'id_rubrique') { |
|
| 659 | + $parent = $principal; |
|
| 660 | + } |
|
| 661 | + if ($type == 'id_article') { |
|
| 662 | + $parent = quete_rubrique($principal, $connect); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + do { |
|
| 666 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 667 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + // And the winner is... |
|
| 675 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -687,23 +687,23 @@ discard block |
||
| 687 | 687 | * @return int |
| 688 | 688 | */ |
| 689 | 689 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 690 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 691 | - // ou composee, mais verifions |
|
| 692 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 693 | - return 0; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $pos = 0; |
|
| 697 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 698 | - $pos++; |
|
| 699 | - } |
|
| 700 | - // si on a pas trouve |
|
| 701 | - if (!$row or $row[$primary] != $valeur) { |
|
| 702 | - return 0; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // sinon, calculer le bon numero de page |
|
| 706 | - return floor($pos / $pas) * $pas; |
|
| 690 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 691 | + // ou composee, mais verifions |
|
| 692 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 693 | + return 0; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $pos = 0; |
|
| 697 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 698 | + $pos++; |
|
| 699 | + } |
|
| 700 | + // si on a pas trouve |
|
| 701 | + if (!$row or $row[$primary] != $valeur) { |
|
| 702 | + return 0; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // sinon, calculer le bon numero de page |
|
| 706 | + return floor($pos / $pas) * $pas; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -714,11 +714,11 @@ discard block |
||
| 714 | 714 | * @return boolean |
| 715 | 715 | */ |
| 716 | 716 | function is_whereable($value): bool { |
| 717 | - if (is_array($value) && count($value)) { |
|
| 718 | - return true; |
|
| 719 | - } |
|
| 720 | - if (is_scalar($value) && strlen($value)) { |
|
| 721 | - return true; |
|
| 722 | - } |
|
| 723 | - return false; |
|
| 717 | + if (is_array($value) && count($value)) { |
|
| 718 | + return true; |
|
| 719 | + } |
|
| 720 | + if (is_scalar($value) && strlen($value)) { |
|
| 721 | + return true; |
|
| 722 | + } |
|
| 723 | + return false; |
|
| 724 | 724 | } |
@@ -2071,8 +2071,7 @@ discard block |
||
| 2071 | 2071 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2072 | 2072 | if (@array_key_exists('*', $desc['field'])) { |
| 2073 | 2073 | $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 2074 | - } |
|
| 2075 | - else { |
|
| 2074 | + } else { |
|
| 2076 | 2075 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2077 | 2076 | if (!$r) { |
| 2078 | 2077 | return ''; |
@@ -2115,8 +2114,7 @@ discard block |
||
| 2115 | 2114 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2116 | 2115 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 2117 | 2116 | $val[0] = "sql_quote($r)"; |
| 2118 | - } |
|
| 2119 | - elseif ( |
|
| 2117 | + } elseif ( |
|
| 2120 | 2118 | strpos($val[0], '@@defaultcast@@') !== false |
| 2121 | 2119 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2122 | 2120 | ) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string Clause pour le Order by |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string Clause pour le Order by |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string Clause pour le Order by |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1113,137 +1113,137 @@ discard block |
||
| 1113 | 1113 | * @return array|string |
| 1114 | 1114 | */ |
| 1115 | 1115 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1116 | - $boucle = &$boucles[$idb]; |
|
| 1116 | + $boucle = &$boucles[$idb]; |
|
| 1117 | 1117 | |
| 1118 | - $sens = $collecte = ''; |
|
| 1119 | - if ($crit->not) { |
|
| 1120 | - $sens = " . ' DESC'"; |
|
| 1121 | - } |
|
| 1118 | + $sens = $collecte = ''; |
|
| 1119 | + if ($crit->not) { |
|
| 1120 | + $sens = " . ' DESC'"; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - $crit2 = clone $crit; |
|
| 1124 | - $crit2->not = false; |
|
| 1125 | - $crit2->param = [reset($crit->param)]; |
|
| 1126 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1123 | + $crit2 = clone $crit; |
|
| 1124 | + $crit2->not = false; |
|
| 1125 | + $crit2->param = [reset($crit->param)]; |
|
| 1126 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1127 | 1127 | |
| 1128 | - // erreur ? |
|
| 1129 | - if (is_array($res)) { |
|
| 1130 | - return $res; |
|
| 1131 | - } |
|
| 1128 | + // erreur ? |
|
| 1129 | + if (is_array($res)) { |
|
| 1130 | + return $res; |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - $_order = array_pop($boucle->order); |
|
| 1133 | + $_order = array_pop($boucle->order); |
|
| 1134 | 1134 | |
| 1135 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1135 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | 1140 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1141 | - $params = $crit->param; |
|
| 1142 | - |
|
| 1143 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - $boucle = &$boucles[$idb]; |
|
| 1148 | - $parent = $boucle->id_parent; |
|
| 1149 | - $fields = $boucle->show['field']; |
|
| 1150 | - |
|
| 1151 | - $date = array_shift($params); |
|
| 1152 | - $type = array_shift($params); |
|
| 1153 | - |
|
| 1154 | - // la valeur $type doit etre connue a la compilation |
|
| 1155 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | - |
|
| 1158 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | - $date = $date[0]->texte; |
|
| 1164 | - if (!isset($fields[$date])) { |
|
| 1165 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | - } |
|
| 1167 | - } else { |
|
| 1168 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | - $noms = array_keys($fields); |
|
| 1170 | - $defaut = $noms[0]; |
|
| 1171 | - $noms = join(' ', $noms); |
|
| 1172 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | - } |
|
| 1176 | - $annee = $params ? array_shift($params) : ''; |
|
| 1177 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | - ') ? $x : date("Y"))'; |
|
| 1180 | - |
|
| 1181 | - $mois = $params ? array_shift($params) : ''; |
|
| 1182 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | - ') ? $x : date("m"))'; |
|
| 1185 | - |
|
| 1186 | - $jour = $params ? array_shift($params) : ''; |
|
| 1187 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | - ') ? $x : date("d"))'; |
|
| 1190 | - |
|
| 1191 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | - ') ? $x : date("Y"))'; |
|
| 1195 | - |
|
| 1196 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | - ') ? $x : date("m"))'; |
|
| 1200 | - |
|
| 1201 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | - ') ? $x : date("d"))'; |
|
| 1205 | - |
|
| 1206 | - $date = $boucle->id_table . ".$date"; |
|
| 1207 | - |
|
| 1208 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | - if ($type == 'jour') { |
|
| 1210 | - $boucle->where[] = [ |
|
| 1211 | - "'='", |
|
| 1212 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | - ]; |
|
| 1215 | - } elseif ($type == 'mois') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'semaine') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'AND'", |
|
| 1224 | - [ |
|
| 1225 | - "'>='", |
|
| 1226 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | - ], |
|
| 1229 | - [ |
|
| 1230 | - "'<='", |
|
| 1231 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | - ] |
|
| 1234 | - ]; |
|
| 1235 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | - $boucle->where[] = [ |
|
| 1237 | - "'AND'", |
|
| 1238 | - [ |
|
| 1239 | - "'>='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | - ], |
|
| 1243 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | - ]; |
|
| 1245 | - } |
|
| 1246 | - // sinon on prend tout |
|
| 1141 | + $params = $crit->param; |
|
| 1142 | + |
|
| 1143 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + $boucle = &$boucles[$idb]; |
|
| 1148 | + $parent = $boucle->id_parent; |
|
| 1149 | + $fields = $boucle->show['field']; |
|
| 1150 | + |
|
| 1151 | + $date = array_shift($params); |
|
| 1152 | + $type = array_shift($params); |
|
| 1153 | + |
|
| 1154 | + // la valeur $type doit etre connue a la compilation |
|
| 1155 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | + |
|
| 1158 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | + $date = $date[0]->texte; |
|
| 1164 | + if (!isset($fields[$date])) { |
|
| 1165 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | + } |
|
| 1167 | + } else { |
|
| 1168 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | + $noms = array_keys($fields); |
|
| 1170 | + $defaut = $noms[0]; |
|
| 1171 | + $noms = join(' ', $noms); |
|
| 1172 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | + } |
|
| 1176 | + $annee = $params ? array_shift($params) : ''; |
|
| 1177 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + ') ? $x : date("Y"))'; |
|
| 1180 | + |
|
| 1181 | + $mois = $params ? array_shift($params) : ''; |
|
| 1182 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + ') ? $x : date("m"))'; |
|
| 1185 | + |
|
| 1186 | + $jour = $params ? array_shift($params) : ''; |
|
| 1187 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + ') ? $x : date("d"))'; |
|
| 1190 | + |
|
| 1191 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + ') ? $x : date("Y"))'; |
|
| 1195 | + |
|
| 1196 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + ') ? $x : date("m"))'; |
|
| 1200 | + |
|
| 1201 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + ') ? $x : date("d"))'; |
|
| 1205 | + |
|
| 1206 | + $date = $boucle->id_table . ".$date"; |
|
| 1207 | + |
|
| 1208 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | + if ($type == 'jour') { |
|
| 1210 | + $boucle->where[] = [ |
|
| 1211 | + "'='", |
|
| 1212 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | + ]; |
|
| 1215 | + } elseif ($type == 'mois') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'semaine') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'AND'", |
|
| 1224 | + [ |
|
| 1225 | + "'>='", |
|
| 1226 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | + ], |
|
| 1229 | + [ |
|
| 1230 | + "'<='", |
|
| 1231 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | + ] |
|
| 1234 | + ]; |
|
| 1235 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | + $boucle->where[] = [ |
|
| 1237 | + "'AND'", |
|
| 1238 | + [ |
|
| 1239 | + "'>='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | + ], |
|
| 1243 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | + ]; |
|
| 1245 | + } |
|
| 1246 | + // sinon on prend tout |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | |
@@ -1268,33 +1268,33 @@ discard block |
||
| 1268 | 1268 | * @return void |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1271 | - $boucle = &$boucles[$idb]; |
|
| 1272 | - $a1 = $crit->param[0]; |
|
| 1273 | - $a2 = $crit->param[1]; |
|
| 1274 | - $op = $crit->op; |
|
| 1275 | - |
|
| 1276 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | - |
|
| 1279 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | - } else { |
|
| 1282 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | - $mode = (($op == '/') ? '/' : |
|
| 1287 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | - $boucle->limit = |
|
| 1291 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | - . ".','." |
|
| 1293 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | - } else { |
|
| 1295 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | - } |
|
| 1297 | - } |
|
| 1271 | + $boucle = &$boucles[$idb]; |
|
| 1272 | + $a1 = $crit->param[0]; |
|
| 1273 | + $a2 = $crit->param[1]; |
|
| 1274 | + $op = $crit->op; |
|
| 1275 | + |
|
| 1276 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | + |
|
| 1279 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | + } else { |
|
| 1282 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | + $mode = (($op == '/') ? '/' : |
|
| 1287 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | + $boucle->limit = |
|
| 1291 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | + . ".','." |
|
| 1293 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | + } else { |
|
| 1295 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | + } |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1322,63 +1322,63 @@ discard block |
||
| 1322 | 1322 | * @return void |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1325 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | - |
|
| 1327 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | - // {1/3} |
|
| 1331 | - if ($op1 == '/') { |
|
| 1332 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | - "($total_parties ? $total_parties : 1)"; |
|
| 1335 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | - } else { |
|
| 1338 | - // cas {n-1,x} |
|
| 1339 | - if ($op1 == '-') { |
|
| 1340 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - // cas {x,n-1} |
|
| 1344 | - if ($op2 == '-') { |
|
| 1345 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | - ($total_parties . ' - 1')); |
|
| 1348 | - } else { |
|
| 1349 | - // {x,1} ou {pagination} |
|
| 1350 | - $fin = '$debut_boucle' |
|
| 1351 | - . (is_numeric($total_parties) ? |
|
| 1352 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | - ('+' . $total_parties . ' - 1')); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | - if ($op1 == 'p') { |
|
| 1358 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - // Notes : |
|
| 1365 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | - |
|
| 1370 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | - . "\n\tif (\$debut_boucle>0" |
|
| 1377 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | - |
|
| 1381 | - $boucles[$id_boucle]->partie = " |
|
| 1325 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | + |
|
| 1327 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | + // {1/3} |
|
| 1331 | + if ($op1 == '/') { |
|
| 1332 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | + "($total_parties ? $total_parties : 1)"; |
|
| 1335 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | + } else { |
|
| 1338 | + // cas {n-1,x} |
|
| 1339 | + if ($op1 == '-') { |
|
| 1340 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + // cas {x,n-1} |
|
| 1344 | + if ($op2 == '-') { |
|
| 1345 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | + ($total_parties . ' - 1')); |
|
| 1348 | + } else { |
|
| 1349 | + // {x,1} ou {pagination} |
|
| 1350 | + $fin = '$debut_boucle' |
|
| 1351 | + . (is_numeric($total_parties) ? |
|
| 1352 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | + ('+' . $total_parties . ' - 1')); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | + if ($op1 == 'p') { |
|
| 1358 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // Notes : |
|
| 1365 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | + |
|
| 1370 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | + . "\n\tif (\$debut_boucle>0" |
|
| 1377 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | + |
|
| 1381 | + $boucles[$id_boucle]->partie = " |
|
| 1382 | 1382 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1383 | 1383 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1384 | 1384 | } |
@@ -1395,26 +1395,26 @@ discard block |
||
| 1395 | 1395 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1396 | 1396 | **/ |
| 1397 | 1397 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1398 | - if ($param[0]->type != 'texte') { |
|
| 1399 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | - if (isset($param[1]->texte)) { |
|
| 1401 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | - |
|
| 1403 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | - } else { |
|
| 1405 | - return ["intval($a1)", 0]; |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | - $a1 = $m[1]; |
|
| 1410 | - if (empty($m[3])) { |
|
| 1411 | - return [$a1, 0]; |
|
| 1412 | - } elseif (!empty($m[4])) { |
|
| 1413 | - return [$a1, $m[4]]; |
|
| 1414 | - } else { |
|
| 1415 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1398 | + if ($param[0]->type != 'texte') { |
|
| 1399 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | + if (isset($param[1]->texte)) { |
|
| 1401 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | + |
|
| 1403 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | + } else { |
|
| 1405 | + return ["intval($a1)", 0]; |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | + $a1 = $m[1]; |
|
| 1410 | + if (empty($m[3])) { |
|
| 1411 | + return [$a1, 0]; |
|
| 1412 | + } elseif (!empty($m[4])) { |
|
| 1413 | + return [$a1, $m[4]]; |
|
| 1414 | + } else { |
|
| 1415 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | |
@@ -1441,47 +1441,47 @@ discard block |
||
| 1441 | 1441 | * array : Erreur sur un des critères |
| 1442 | 1442 | **/ |
| 1443 | 1443 | function calculer_criteres($idb, &$boucles) { |
| 1444 | - $msg = ''; |
|
| 1445 | - $boucle = $boucles[$idb]; |
|
| 1446 | - $table = strtoupper($boucle->type_requete); |
|
| 1447 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | - |
|
| 1449 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | - if (!is_array($boucle->criteres)) { |
|
| 1452 | - return []; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - foreach ($boucle->criteres as $crit) { |
|
| 1456 | - $critere = $crit->op; |
|
| 1457 | - // critere personnalise ? |
|
| 1458 | - if ( |
|
| 1459 | - (!$serveur or |
|
| 1460 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | - and (!function_exists($f = $f . '_dist')) |
|
| 1462 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | - ) |
|
| 1465 | - ) |
|
| 1466 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) { |
|
| 1471 | - // fonction critere standard |
|
| 1472 | - $f = $defaut; |
|
| 1473 | - } |
|
| 1474 | - // compile le critere |
|
| 1475 | - $res = $f($idb, $boucles, $crit); |
|
| 1476 | - |
|
| 1477 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | - if (is_array($res)) { |
|
| 1479 | - $msg = $res; |
|
| 1480 | - erreur_squelette($msg, $boucle); |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - return $msg; |
|
| 1444 | + $msg = ''; |
|
| 1445 | + $boucle = $boucles[$idb]; |
|
| 1446 | + $table = strtoupper($boucle->type_requete); |
|
| 1447 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | + |
|
| 1449 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | + if (!is_array($boucle->criteres)) { |
|
| 1452 | + return []; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + foreach ($boucle->criteres as $crit) { |
|
| 1456 | + $critere = $crit->op; |
|
| 1457 | + // critere personnalise ? |
|
| 1458 | + if ( |
|
| 1459 | + (!$serveur or |
|
| 1460 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | + and (!function_exists($f = $f . '_dist')) |
|
| 1462 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | + and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + ) |
|
| 1465 | + ) |
|
| 1466 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) { |
|
| 1471 | + // fonction critere standard |
|
| 1472 | + $f = $defaut; |
|
| 1473 | + } |
|
| 1474 | + // compile le critere |
|
| 1475 | + $res = $f($idb, $boucles, $crit); |
|
| 1476 | + |
|
| 1477 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | + if (is_array($res)) { |
|
| 1479 | + $msg = $res; |
|
| 1480 | + erreur_squelette($msg, $boucle); |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + return $msg; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
@@ -1496,11 +1496,11 @@ discard block |
||
| 1496 | 1496 | * @return string Code compilé rééchappé |
| 1497 | 1497 | */ |
| 1498 | 1498 | function kwote($lisp, $serveur = '', $type = '') { |
| 1499 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | - } else { |
|
| 1502 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | - } |
|
| 1499 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | + } else { |
|
| 1502 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | + } |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | |
@@ -1519,81 +1519,81 @@ discard block |
||
| 1519 | 1519 | * @return void |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1522 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | - if (!$r) { |
|
| 1524 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1525 | - } |
|
| 1526 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | - |
|
| 1528 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | - |
|
| 1530 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | - $where = $in; |
|
| 1532 | - if ($crit->cond) { |
|
| 1533 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - if ($crit->exclus) { |
|
| 1540 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | - $where = ["'NOT'", $where]; |
|
| 1542 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | - { |
|
| 1545 | - $where = [ |
|
| 1546 | - "'NOT'", |
|
| 1547 | - [ |
|
| 1548 | - "'IN'", |
|
| 1549 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | - ] |
|
| 1552 | - ]; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - $boucles[$idb]->where[] = $where; |
|
| 1557 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | - } |
|
| 1522 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | + if (!$r) { |
|
| 1524 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1525 | + } |
|
| 1526 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | + |
|
| 1528 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | + |
|
| 1530 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | + $where = $in; |
|
| 1532 | + if ($crit->cond) { |
|
| 1533 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + if ($crit->exclus) { |
|
| 1540 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | + $where = ["'NOT'", $where]; |
|
| 1542 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | + { |
|
| 1545 | + $where = [ |
|
| 1546 | + "'NOT'", |
|
| 1547 | + [ |
|
| 1548 | + "'IN'", |
|
| 1549 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | + ] |
|
| 1552 | + ]; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + $boucles[$idb]->where[] = $where; |
|
| 1557 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | + } |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1563 | - static $num = []; |
|
| 1564 | - $descr = $boucles[$idb]->descr; |
|
| 1565 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | - |
|
| 1567 | - $var = '$in' . $cpt++; |
|
| 1568 | - $x = "\n\t$var = array();"; |
|
| 1569 | - foreach ($val as $k => $v) { |
|
| 1570 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | - // optimiser le traitement des constantes |
|
| 1572 | - if (is_numeric($r[2])) { |
|
| 1573 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | - } else { |
|
| 1575 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | - } |
|
| 1577 | - } else { |
|
| 1578 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - $boucles[$idb]->in .= $x; |
|
| 1587 | - |
|
| 1588 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | - if (!$crit2) { |
|
| 1593 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1563 | + static $num = []; |
|
| 1564 | + $descr = $boucles[$idb]->descr; |
|
| 1565 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | + |
|
| 1567 | + $var = '$in' . $cpt++; |
|
| 1568 | + $x = "\n\t$var = array();"; |
|
| 1569 | + foreach ($val as $k => $v) { |
|
| 1570 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | + // optimiser le traitement des constantes |
|
| 1572 | + if (is_numeric($r[2])) { |
|
| 1573 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | + } else { |
|
| 1575 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | + } |
|
| 1577 | + } else { |
|
| 1578 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + $boucles[$idb]->in .= $x; |
|
| 1587 | + |
|
| 1588 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | + if (!$crit2) { |
|
| 1593 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | /** |
@@ -1609,22 +1609,22 @@ discard block |
||
| 1609 | 1609 | * @return void |
| 1610 | 1610 | */ |
| 1611 | 1611 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1612 | - $boucle = &$boucles[$idb]; |
|
| 1613 | - if (isset($crit->param[0])) { |
|
| 1614 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | - } else { |
|
| 1616 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - if ($crit->cond) { |
|
| 1620 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - if ($crit->not) { |
|
| 1624 | - $_where = "array('NOT',$_where)"; |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - $boucle->where[] = $_where; |
|
| 1612 | + $boucle = &$boucles[$idb]; |
|
| 1613 | + if (isset($crit->param[0])) { |
|
| 1614 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | + } else { |
|
| 1616 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + if ($crit->cond) { |
|
| 1620 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + if ($crit->not) { |
|
| 1624 | + $_where = "array('NOT',$_where)"; |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + $boucle->where[] = $_where; |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
@@ -1652,31 +1652,31 @@ discard block |
||
| 1652 | 1652 | * @return void |
| 1653 | 1653 | */ |
| 1654 | 1654 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1655 | - /** @var Boucle $boucle */ |
|
| 1656 | - $boucle = $boucles[$idb]; |
|
| 1657 | - |
|
| 1658 | - $champs = lister_champs_id_conditionnel( |
|
| 1659 | - $boucle->show['table'], |
|
| 1660 | - $boucle->show, |
|
| 1661 | - $boucle->sql_serveur |
|
| 1662 | - ); |
|
| 1663 | - |
|
| 1664 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | - } |
|
| 1668 | - // nous aider en mode debug. |
|
| 1669 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | - $boucle->modificateur['id_'] = $champs; |
|
| 1671 | - |
|
| 1672 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | - foreach ($champs as $champ) { |
|
| 1674 | - $critere_id_table = new Critere(); |
|
| 1675 | - $critere_id_table->op = $champ; |
|
| 1676 | - $critere_id_table->cond = '?'; |
|
| 1677 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | - } |
|
| 1655 | + /** @var Boucle $boucle */ |
|
| 1656 | + $boucle = $boucles[$idb]; |
|
| 1657 | + |
|
| 1658 | + $champs = lister_champs_id_conditionnel( |
|
| 1659 | + $boucle->show['table'], |
|
| 1660 | + $boucle->show, |
|
| 1661 | + $boucle->sql_serveur |
|
| 1662 | + ); |
|
| 1663 | + |
|
| 1664 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | + } |
|
| 1668 | + // nous aider en mode debug. |
|
| 1669 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | + $boucle->modificateur['id_'] = $champs; |
|
| 1671 | + |
|
| 1672 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | + foreach ($champs as $champ) { |
|
| 1674 | + $critere_id_table = new Critere(); |
|
| 1675 | + $critere_id_table->op = $champ; |
|
| 1676 | + $critere_id_table->cond = '?'; |
|
| 1677 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | + } |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | /** |
@@ -1696,75 +1696,75 @@ discard block |
||
| 1696 | 1696 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1697 | 1697 | */ |
| 1698 | 1698 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1699 | - // calculer la description de la table |
|
| 1700 | - if (!is_array($desc)) { |
|
| 1701 | - $desc = description_table($table, $serveur); |
|
| 1702 | - } |
|
| 1703 | - if (!$desc) { |
|
| 1704 | - return []; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - // Les champs id_xx de la table demandée |
|
| 1708 | - $champs = array_filter( |
|
| 1709 | - array_keys($desc['field']), |
|
| 1710 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | - ); |
|
| 1712 | - |
|
| 1713 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | - if ( |
|
| 1715 | - in_array('id_rubrique', $champs) |
|
| 1716 | - and !in_array('id_secteur', $champs) |
|
| 1717 | - ) { |
|
| 1718 | - $champs[] = 'id_secteur'; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | - if ($serveur) { |
|
| 1723 | - return $champs; |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - $primary = false; |
|
| 1727 | - $associable = false; |
|
| 1728 | - include_spip('action/editer_liens'); |
|
| 1729 | - |
|
| 1730 | - if (isset($desc['type'])) { |
|
| 1731 | - $primary = id_table_objet($desc['type']); |
|
| 1732 | - $associable = objet_associable($desc['type']); |
|
| 1733 | - } |
|
| 1734 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | - $associable = true; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - // liste de toutes les tables principales, sauf la notre |
|
| 1739 | - $tables = lister_tables_objets_sql(); |
|
| 1740 | - unset($tables[$table]); |
|
| 1741 | - |
|
| 1742 | - foreach ($tables as $_table => $_desc) { |
|
| 1743 | - if ( |
|
| 1744 | - $associable |
|
| 1745 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | - or objet_associable($_desc['type']) |
|
| 1747 | - ) { |
|
| 1748 | - $champs[] = id_table_objet($_table); |
|
| 1749 | - } |
|
| 1750 | - } |
|
| 1751 | - $champs = array_values(array_unique($champs)); |
|
| 1752 | - |
|
| 1753 | - // Exclusions de certains id |
|
| 1754 | - $exclusions = pipeline( |
|
| 1755 | - 'exclure_id_conditionnel', |
|
| 1756 | - [ |
|
| 1757 | - 'args' => [ |
|
| 1758 | - 'table' => $table, |
|
| 1759 | - 'id_table_objet' => $primary, |
|
| 1760 | - 'associable' => $associable, |
|
| 1761 | - ], |
|
| 1762 | - 'data' => [], |
|
| 1763 | - ] |
|
| 1764 | - ); |
|
| 1765 | - $champs = array_diff($champs, $exclusions); |
|
| 1766 | - |
|
| 1767 | - return $champs; |
|
| 1699 | + // calculer la description de la table |
|
| 1700 | + if (!is_array($desc)) { |
|
| 1701 | + $desc = description_table($table, $serveur); |
|
| 1702 | + } |
|
| 1703 | + if (!$desc) { |
|
| 1704 | + return []; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + // Les champs id_xx de la table demandée |
|
| 1708 | + $champs = array_filter( |
|
| 1709 | + array_keys($desc['field']), |
|
| 1710 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | + ); |
|
| 1712 | + |
|
| 1713 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | + if ( |
|
| 1715 | + in_array('id_rubrique', $champs) |
|
| 1716 | + and !in_array('id_secteur', $champs) |
|
| 1717 | + ) { |
|
| 1718 | + $champs[] = 'id_secteur'; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | + if ($serveur) { |
|
| 1723 | + return $champs; |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + $primary = false; |
|
| 1727 | + $associable = false; |
|
| 1728 | + include_spip('action/editer_liens'); |
|
| 1729 | + |
|
| 1730 | + if (isset($desc['type'])) { |
|
| 1731 | + $primary = id_table_objet($desc['type']); |
|
| 1732 | + $associable = objet_associable($desc['type']); |
|
| 1733 | + } |
|
| 1734 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | + $associable = true; |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + // liste de toutes les tables principales, sauf la notre |
|
| 1739 | + $tables = lister_tables_objets_sql(); |
|
| 1740 | + unset($tables[$table]); |
|
| 1741 | + |
|
| 1742 | + foreach ($tables as $_table => $_desc) { |
|
| 1743 | + if ( |
|
| 1744 | + $associable |
|
| 1745 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | + or objet_associable($_desc['type']) |
|
| 1747 | + ) { |
|
| 1748 | + $champs[] = id_table_objet($_table); |
|
| 1749 | + } |
|
| 1750 | + } |
|
| 1751 | + $champs = array_values(array_unique($champs)); |
|
| 1752 | + |
|
| 1753 | + // Exclusions de certains id |
|
| 1754 | + $exclusions = pipeline( |
|
| 1755 | + 'exclure_id_conditionnel', |
|
| 1756 | + [ |
|
| 1757 | + 'args' => [ |
|
| 1758 | + 'table' => $table, |
|
| 1759 | + 'id_table_objet' => $primary, |
|
| 1760 | + 'associable' => $associable, |
|
| 1761 | + ], |
|
| 1762 | + 'data' => [], |
|
| 1763 | + ] |
|
| 1764 | + ); |
|
| 1765 | + $champs = array_diff($champs, $exclusions); |
|
| 1766 | + |
|
| 1767 | + return $champs; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1819,27 +1819,27 @@ discard block |
||
| 1819 | 1819 | * @return void |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - |
|
| 1824 | - // definition du champ par defaut |
|
| 1825 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | - |
|
| 1832 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | - |
|
| 1834 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | - |
|
| 1837 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | - $boucle->hash .= " |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + |
|
| 1824 | + // definition du champ par defaut |
|
| 1825 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | + |
|
| 1832 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | + |
|
| 1834 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | + |
|
| 1837 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | + $boucle->hash .= " |
|
| 1843 | 1843 | \$senstri = ''; |
| 1844 | 1844 | \$tri = $_tri; |
| 1845 | 1845 | if (\$tri){ |
@@ -1847,8 +1847,8 @@ discard block |
||
| 1847 | 1847 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1848 | 1848 | }; |
| 1849 | 1849 | "; |
| 1850 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1850 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | # Criteres de comparaison |
@@ -1865,20 +1865,20 @@ discard block |
||
| 1865 | 1865 | * @return void |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1868 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | - if (!$r) { |
|
| 1875 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | - # if (!$crit->cond) { |
|
| 1877 | - return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1878 | - # } |
|
| 1879 | - } else { |
|
| 1880 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | - } |
|
| 1868 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | + if (!$r) { |
|
| 1875 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | + # if (!$crit->cond) { |
|
| 1877 | + return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1878 | + # } |
|
| 1879 | + } else { |
|
| 1880 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | + } |
|
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | 1884 | |
@@ -1898,62 +1898,62 @@ discard block |
||
| 1898 | 1898 | * @return void |
| 1899 | 1899 | **/ |
| 1900 | 1900 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1901 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | - |
|
| 1903 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | - |
|
| 1905 | - // inserer la negation (cf !...) |
|
| 1906 | - |
|
| 1907 | - if ($crit->not) { |
|
| 1908 | - $where = ["'NOT'", $where]; |
|
| 1909 | - } |
|
| 1910 | - if ($crit->exclus) { |
|
| 1911 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | - $where = ["'NOT'", $where]; |
|
| 1913 | - } else { |
|
| 1914 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | - $where = [ |
|
| 1917 | - "'NOT'", |
|
| 1918 | - [ |
|
| 1919 | - "'IN'", |
|
| 1920 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | - ] |
|
| 1923 | - ]; |
|
| 1924 | - } |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - // inserer la condition (cf {lang?}) |
|
| 1928 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | - if ($crit->cond) { |
|
| 1930 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - if ($op === '=' and !$crit->not) { |
|
| 1938 | - $where = [ |
|
| 1939 | - "'?'", |
|
| 1940 | - "(is_array($pred))", |
|
| 1941 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | - $where |
|
| 1943 | - ]; |
|
| 1944 | - } |
|
| 1945 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | - if ($where_complement) { |
|
| 1947 | - // condition annexe du type "AND (objet='article')" |
|
| 1948 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - $boucles[$idb]->where[] = $where; |
|
| 1953 | - if ($where_complement) { |
|
| 1954 | - // condition annexe du type "AND (objet='article')" |
|
| 1955 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | - } |
|
| 1901 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | + |
|
| 1903 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | + |
|
| 1905 | + // inserer la negation (cf !...) |
|
| 1906 | + |
|
| 1907 | + if ($crit->not) { |
|
| 1908 | + $where = ["'NOT'", $where]; |
|
| 1909 | + } |
|
| 1910 | + if ($crit->exclus) { |
|
| 1911 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | + $where = ["'NOT'", $where]; |
|
| 1913 | + } else { |
|
| 1914 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | + $where = [ |
|
| 1917 | + "'NOT'", |
|
| 1918 | + [ |
|
| 1919 | + "'IN'", |
|
| 1920 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | + ] |
|
| 1923 | + ]; |
|
| 1924 | + } |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + // inserer la condition (cf {lang?}) |
|
| 1928 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | + if ($crit->cond) { |
|
| 1930 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + if ($op === '=' and !$crit->not) { |
|
| 1938 | + $where = [ |
|
| 1939 | + "'?'", |
|
| 1940 | + "(is_array($pred))", |
|
| 1941 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | + $where |
|
| 1943 | + ]; |
|
| 1944 | + } |
|
| 1945 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | + if ($where_complement) { |
|
| 1947 | + // condition annexe du type "AND (objet='article')" |
|
| 1948 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + $boucles[$idb]->where[] = $where; |
|
| 1953 | + if ($where_complement) { |
|
| 1954 | + // condition annexe du type "AND (objet='article')" |
|
| 1955 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | + } |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | |
@@ -1994,165 +1994,165 @@ discard block |
||
| 1994 | 1994 | **/ |
| 1995 | 1995 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1996 | 1996 | |
| 1997 | - $boucle = &$boucles[$idb]; |
|
| 1998 | - $type = $boucle->type_requete; |
|
| 1999 | - $table = $boucle->id_table ?? ''; |
|
| 2000 | - $desc = $boucle->show; |
|
| 2001 | - $col_vraie = null; |
|
| 2002 | - |
|
| 2003 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | - |
|
| 2006 | - $col_alias = $col; |
|
| 2007 | - $where_complement = false; |
|
| 2008 | - |
|
| 2009 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | - if ($col == 'id_enfant') { |
|
| 2011 | - $col = $boucle->primary; |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | - if ( |
|
| 2016 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | - ) { |
|
| 2019 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | - else { |
|
| 2022 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | - // sauf si exception declaree : sauter cette etape |
|
| 2028 | - else { |
|
| 2029 | - if ( |
|
| 2030 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | - ) { |
|
| 2034 | - $e = decompose_champ_id_objet($col); |
|
| 2035 | - $col = array_shift($e); |
|
| 2036 | - $where_complement = primary_doublee($e, $table); |
|
| 2037 | - } // Cas particulier : expressions de date |
|
| 2038 | - else { |
|
| 2039 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | - [$col, $col_vraie] = $c; |
|
| 2041 | - $table = ''; |
|
| 2042 | - } // table explicitée {mots.titre} |
|
| 2043 | - else { |
|
| 2044 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | - [, $table, $col] = $r; |
|
| 2046 | - $col_alias = $col; |
|
| 2047 | - |
|
| 2048 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | - if ( |
|
| 2050 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | - and isset($desc['field'][$col]) |
|
| 2052 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | - ) { |
|
| 2054 | - $table = $cle; |
|
| 2055 | - } else { |
|
| 2056 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | - } |
|
| 2058 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | - if (!$table) { |
|
| 2060 | - return ''; |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - // si le champ n'est pas trouvé dans la table, |
|
| 2064 | - // on cherche si une jointure peut l'obtenir |
|
| 2065 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | - } |
|
| 2070 | - else { |
|
| 2071 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | - if (!$r) { |
|
| 2073 | - return ''; |
|
| 2074 | - } |
|
| 2075 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | - } |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - |
|
| 2083 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | - // Dans tous les cas, |
|
| 2085 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | - // et passer dans sql_quote avec le type si connu |
|
| 2087 | - // et int sinon si la valeur est numerique |
|
| 2088 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | - } |
|
| 2097 | - // sinon expliciter les |
|
| 2098 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | - // sans toucher aux |
|
| 2102 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | - // sql_quote(truc,'','varchar') |
|
| 2104 | - elseif ( |
|
| 2105 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | - // si pas deja un type |
|
| 2107 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | - ) { |
|
| 2109 | - $r = $r[1] |
|
| 2110 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | - $val[0] = "sql_quote($r)"; |
|
| 2113 | - } |
|
| 2114 | - elseif ( |
|
| 2115 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | - ) { |
|
| 2118 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - if ( |
|
| 2123 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | - ) { |
|
| 2126 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | - if ($table === $boucle->id_table) { |
|
| 2133 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | - if ($col_alias != $col_vraie) { |
|
| 2135 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | - } |
|
| 2137 | - } |
|
| 2138 | - |
|
| 2139 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | - if ($table) { |
|
| 2141 | - if ($col[0] == '`') { |
|
| 2142 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | - } else { |
|
| 2144 | - $arg = "$table.$col"; |
|
| 2145 | - } |
|
| 2146 | - } else { |
|
| 2147 | - $arg = $col; |
|
| 2148 | - } |
|
| 2149 | - |
|
| 2150 | - // inserer la fonction SQL |
|
| 2151 | - if ($fct) { |
|
| 2152 | - $arg = "$fct($arg$args_sql)"; |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 1997 | + $boucle = &$boucles[$idb]; |
|
| 1998 | + $type = $boucle->type_requete; |
|
| 1999 | + $table = $boucle->id_table ?? ''; |
|
| 2000 | + $desc = $boucle->show; |
|
| 2001 | + $col_vraie = null; |
|
| 2002 | + |
|
| 2003 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | + |
|
| 2006 | + $col_alias = $col; |
|
| 2007 | + $where_complement = false; |
|
| 2008 | + |
|
| 2009 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | + if ($col == 'id_enfant') { |
|
| 2011 | + $col = $boucle->primary; |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | + if ( |
|
| 2016 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | + ) { |
|
| 2019 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | + else { |
|
| 2022 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | + // sauf si exception declaree : sauter cette etape |
|
| 2028 | + else { |
|
| 2029 | + if ( |
|
| 2030 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | + ) { |
|
| 2034 | + $e = decompose_champ_id_objet($col); |
|
| 2035 | + $col = array_shift($e); |
|
| 2036 | + $where_complement = primary_doublee($e, $table); |
|
| 2037 | + } // Cas particulier : expressions de date |
|
| 2038 | + else { |
|
| 2039 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | + [$col, $col_vraie] = $c; |
|
| 2041 | + $table = ''; |
|
| 2042 | + } // table explicitée {mots.titre} |
|
| 2043 | + else { |
|
| 2044 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | + [, $table, $col] = $r; |
|
| 2046 | + $col_alias = $col; |
|
| 2047 | + |
|
| 2048 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | + if ( |
|
| 2050 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | + and isset($desc['field'][$col]) |
|
| 2052 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | + ) { |
|
| 2054 | + $table = $cle; |
|
| 2055 | + } else { |
|
| 2056 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | + } |
|
| 2058 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | + if (!$table) { |
|
| 2060 | + return ''; |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + // si le champ n'est pas trouvé dans la table, |
|
| 2064 | + // on cherche si une jointure peut l'obtenir |
|
| 2065 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | + } |
|
| 2070 | + else { |
|
| 2071 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | + if (!$r) { |
|
| 2073 | + return ''; |
|
| 2074 | + } |
|
| 2075 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | + } |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + |
|
| 2083 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | + // Dans tous les cas, |
|
| 2085 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | + // et passer dans sql_quote avec le type si connu |
|
| 2087 | + // et int sinon si la valeur est numerique |
|
| 2088 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | + } |
|
| 2097 | + // sinon expliciter les |
|
| 2098 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | + // sans toucher aux |
|
| 2102 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | + // sql_quote(truc,'','varchar') |
|
| 2104 | + elseif ( |
|
| 2105 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | + // si pas deja un type |
|
| 2107 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | + ) { |
|
| 2109 | + $r = $r[1] |
|
| 2110 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | + $val[0] = "sql_quote($r)"; |
|
| 2113 | + } |
|
| 2114 | + elseif ( |
|
| 2115 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | + ) { |
|
| 2118 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + if ( |
|
| 2123 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | + ) { |
|
| 2126 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | + if ($table === $boucle->id_table) { |
|
| 2133 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | + if ($col_alias != $col_vraie) { |
|
| 2135 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | + } |
|
| 2137 | + } |
|
| 2138 | + |
|
| 2139 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | + if ($table) { |
|
| 2141 | + if ($col[0] == '`') { |
|
| 2142 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | + } else { |
|
| 2144 | + $arg = "$table.$col"; |
|
| 2145 | + } |
|
| 2146 | + } else { |
|
| 2147 | + $arg = $col; |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + // inserer la fonction SQL |
|
| 2151 | + if ($fct) { |
|
| 2152 | + $arg = "$fct($arg$args_sql)"; |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | |
@@ -2181,77 +2181,77 @@ discard block |
||
| 2181 | 2181 | **/ |
| 2182 | 2182 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2183 | 2183 | |
| 2184 | - $where = ''; |
|
| 2185 | - |
|
| 2186 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | - // gestion par les plugins des jointures tordues |
|
| 2188 | - // pas automatiques mais necessaires |
|
| 2189 | - $table_sql = table_objet_sql($table); |
|
| 2190 | - if ( |
|
| 2191 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | - and |
|
| 2194 | - ( |
|
| 2195 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | - or |
|
| 2197 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | - ) |
|
| 2199 | - ) { |
|
| 2200 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | - |
|
| 2203 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | - [$t, $col] = $t[$col]; |
|
| 2207 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | - [$calculer_critere_externe] = $index; |
|
| 2209 | - $t = $table; |
|
| 2210 | - } else { |
|
| 2211 | - $t = ''; |
|
| 2212 | - } // jointure non declaree. La trouver. |
|
| 2213 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | - } else { |
|
| 2216 | - $t = ''; |
|
| 2217 | - } // jointure non declaree. La trouver. |
|
| 2218 | - |
|
| 2219 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | - |
|
| 2221 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | - $table = ''; |
|
| 2226 | - if ($boucle->jointures_explicites) { |
|
| 2227 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | - if (!$table) { |
|
| 2233 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | - } |
|
| 2235 | - |
|
| 2236 | - if (!$table) { |
|
| 2237 | - return ''; |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | - |
|
| 2243 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | - $e = decompose_champ_id_objet($col); |
|
| 2247 | - $col = array_shift($e); |
|
| 2248 | - $where = primary_doublee($e, $table); |
|
| 2249 | - } else { |
|
| 2250 | - $col = reset($cle); |
|
| 2251 | - } |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2184 | + $where = ''; |
|
| 2185 | + |
|
| 2186 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | + // gestion par les plugins des jointures tordues |
|
| 2188 | + // pas automatiques mais necessaires |
|
| 2189 | + $table_sql = table_objet_sql($table); |
|
| 2190 | + if ( |
|
| 2191 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | + and |
|
| 2194 | + ( |
|
| 2195 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | + or |
|
| 2197 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | + ) |
|
| 2199 | + ) { |
|
| 2200 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | + |
|
| 2203 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | + [$t, $col] = $t[$col]; |
|
| 2207 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | + [$calculer_critere_externe] = $index; |
|
| 2209 | + $t = $table; |
|
| 2210 | + } else { |
|
| 2211 | + $t = ''; |
|
| 2212 | + } // jointure non declaree. La trouver. |
|
| 2213 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | + } else { |
|
| 2216 | + $t = ''; |
|
| 2217 | + } // jointure non declaree. La trouver. |
|
| 2218 | + |
|
| 2219 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | + |
|
| 2221 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | + $table = ''; |
|
| 2226 | + if ($boucle->jointures_explicites) { |
|
| 2227 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | + if (!$table) { |
|
| 2233 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | + } |
|
| 2235 | + |
|
| 2236 | + if (!$table) { |
|
| 2237 | + return ''; |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | + |
|
| 2243 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | + $e = decompose_champ_id_objet($col); |
|
| 2247 | + $col = array_shift($e); |
|
| 2248 | + $where = primary_doublee($e, $table); |
|
| 2249 | + } else { |
|
| 2250 | + $col = reset($cle); |
|
| 2251 | + } |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | |
@@ -2272,10 +2272,10 @@ discard block |
||
| 2272 | 2272 | * - valeur |
| 2273 | 2273 | **/ |
| 2274 | 2274 | function primary_doublee($decompose, $table) { |
| 2275 | - $e1 = reset($decompose); |
|
| 2276 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e1 = reset($decompose); |
|
| 2276 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2277 | 2277 | |
| 2278 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2278 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2279 | 2279 | } |
| 2280 | 2280 | |
| 2281 | 2281 | /** |
@@ -2306,57 +2306,57 @@ discard block |
||
| 2306 | 2306 | * Vide sinon. |
| 2307 | 2307 | */ |
| 2308 | 2308 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2309 | - // si on demande un truc du genre spip_mots |
|
| 2310 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | - // et qu'on est la |
|
| 2312 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | - if ( |
|
| 2314 | - $checkarrivee |
|
| 2315 | - and is_string($checkarrivee) |
|
| 2316 | - and $a = table_objet($checkarrivee) |
|
| 2317 | - and in_array($a . '_liens', $joints) |
|
| 2318 | - ) { |
|
| 2319 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | - return $res; |
|
| 2321 | - } |
|
| 2322 | - } |
|
| 2323 | - foreach ($joints as $joint) { |
|
| 2324 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | - // alias de table dans le from |
|
| 2326 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | - $cols = $arrivee[2]; |
|
| 2329 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | - array_pop($cols); |
|
| 2332 | - } |
|
| 2333 | - if ($t) { |
|
| 2334 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | - $joindre = false; |
|
| 2336 | - foreach ($cols as $col) { |
|
| 2337 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | - $joindre = true; |
|
| 2340 | - } else { |
|
| 2341 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | - $joindre = true; |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - } |
|
| 2348 | - if (!$joindre) { |
|
| 2349 | - return $t; |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - array_pop($arrivee); |
|
| 2353 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | - return $res; |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - return ''; |
|
| 2309 | + // si on demande un truc du genre spip_mots |
|
| 2310 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | + // et qu'on est la |
|
| 2312 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | + if ( |
|
| 2314 | + $checkarrivee |
|
| 2315 | + and is_string($checkarrivee) |
|
| 2316 | + and $a = table_objet($checkarrivee) |
|
| 2317 | + and in_array($a . '_liens', $joints) |
|
| 2318 | + ) { |
|
| 2319 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | + return $res; |
|
| 2321 | + } |
|
| 2322 | + } |
|
| 2323 | + foreach ($joints as $joint) { |
|
| 2324 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | + // alias de table dans le from |
|
| 2326 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | + $cols = $arrivee[2]; |
|
| 2329 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | + array_pop($cols); |
|
| 2332 | + } |
|
| 2333 | + if ($t) { |
|
| 2334 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | + $joindre = false; |
|
| 2336 | + foreach ($cols as $col) { |
|
| 2337 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | + $joindre = true; |
|
| 2340 | + } else { |
|
| 2341 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | + $joindre = true; |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + } |
|
| 2348 | + if (!$joindre) { |
|
| 2349 | + return $t; |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + array_pop($arrivee); |
|
| 2353 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | + return $res; |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + return ''; |
|
| 2360 | 2360 | } |
| 2361 | 2361 | |
| 2362 | 2362 | /** |
@@ -2382,35 +2382,35 @@ discard block |
||
| 2382 | 2382 | * Alias de la table de jointure (Lx) |
| 2383 | 2383 | */ |
| 2384 | 2384 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2385 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | - |
|
| 2387 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | - |
|
| 2391 | - if (!$intermediaire or !$arrivee) { |
|
| 2392 | - return ''; |
|
| 2393 | - } |
|
| 2394 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | - |
|
| 2397 | - $res = fabrique_jointures( |
|
| 2398 | - $boucle, |
|
| 2399 | - [ |
|
| 2400 | - [ |
|
| 2401 | - $boucle->id_table, |
|
| 2402 | - $intermediaire, |
|
| 2403 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | - ], |
|
| 2405 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | - ], |
|
| 2407 | - $cond, |
|
| 2408 | - $desc, |
|
| 2409 | - $boucle->id_table, |
|
| 2410 | - [$col] |
|
| 2411 | - ); |
|
| 2412 | - |
|
| 2413 | - return $res; |
|
| 2385 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | + |
|
| 2387 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | + |
|
| 2391 | + if (!$intermediaire or !$arrivee) { |
|
| 2392 | + return ''; |
|
| 2393 | + } |
|
| 2394 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | + |
|
| 2397 | + $res = fabrique_jointures( |
|
| 2398 | + $boucle, |
|
| 2399 | + [ |
|
| 2400 | + [ |
|
| 2401 | + $boucle->id_table, |
|
| 2402 | + $intermediaire, |
|
| 2403 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | + ], |
|
| 2405 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | + ], |
|
| 2407 | + $cond, |
|
| 2408 | + $desc, |
|
| 2409 | + $boucle->id_table, |
|
| 2410 | + [$col] |
|
| 2411 | + ); |
|
| 2412 | + |
|
| 2413 | + return $res; |
|
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | |
@@ -2427,17 +2427,17 @@ discard block |
||
| 2427 | 2427 | * false sinon. |
| 2428 | 2428 | **/ |
| 2429 | 2429 | function trouver_champ($champ, $where) { |
| 2430 | - if (!is_array($where)) { |
|
| 2431 | - return preg_match($champ, $where); |
|
| 2432 | - } else { |
|
| 2433 | - foreach ($where as $clause) { |
|
| 2434 | - if (trouver_champ($champ, $clause)) { |
|
| 2435 | - return true; |
|
| 2436 | - } |
|
| 2437 | - } |
|
| 2438 | - |
|
| 2439 | - return false; |
|
| 2440 | - } |
|
| 2430 | + if (!is_array($where)) { |
|
| 2431 | + return preg_match($champ, $where); |
|
| 2432 | + } else { |
|
| 2433 | + foreach ($where as $clause) { |
|
| 2434 | + if (trouver_champ($champ, $clause)) { |
|
| 2435 | + return true; |
|
| 2436 | + } |
|
| 2437 | + } |
|
| 2438 | + |
|
| 2439 | + return false; |
|
| 2440 | + } |
|
| 2441 | 2441 | } |
| 2442 | 2442 | |
| 2443 | 2443 | |
@@ -2463,129 +2463,129 @@ discard block |
||
| 2463 | 2463 | * - string $args_sql Suite des arguments du critère. ? |
| 2464 | 2464 | **/ |
| 2465 | 2465 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2466 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | - if (count($crit->param) == 0) { |
|
| 2468 | - $op = '='; |
|
| 2469 | - $col = $val = $crit->op; |
|
| 2470 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | - $val = $r[2]; |
|
| 2472 | - } |
|
| 2473 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | - if ($val == 'lang') { |
|
| 2475 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | - } else { |
|
| 2477 | - $defaut = null; |
|
| 2478 | - if ($val == 'id_parent') { |
|
| 2479 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | - // pour eviter l'erreur SQL |
|
| 2482 | - $val = $boucles[$idb]->primary; |
|
| 2483 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | - } elseif ($val == 'id_enfant') { |
|
| 2486 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | - // de la boucle superieure |
|
| 2488 | - $val = 'id_parent'; |
|
| 2489 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | - // un critere conditionnel sur date est traite a part |
|
| 2491 | - // car la date est mise d'office par SPIP, |
|
| 2492 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | - $val = [kwote($val)]; |
|
| 2497 | - } |
|
| 2498 | - } else { |
|
| 2499 | - // comparaison explicite |
|
| 2500 | - // le phraseur impose que le premier param soit du texte |
|
| 2501 | - $params = $crit->param; |
|
| 2502 | - $op = $crit->op; |
|
| 2503 | - if ($op == '==') { |
|
| 2504 | - $op = 'REGEXP'; |
|
| 2505 | - } |
|
| 2506 | - $col = array_shift($params); |
|
| 2507 | - $col = $col[0]->texte; |
|
| 2508 | - |
|
| 2509 | - $val = []; |
|
| 2510 | - $parent = $boucles[$idb]->id_parent; |
|
| 2511 | - |
|
| 2512 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | - if ( |
|
| 2516 | - count($params) == 1 |
|
| 2517 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | - and $params[0][0]->type == 'texte' |
|
| 2519 | - and $params[0][2]->type == 'texte' |
|
| 2520 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | - and (($p == "'") or ($p == '"')) |
|
| 2522 | - and $params[0][1]->type == 'champ' |
|
| 2523 | - ) { |
|
| 2524 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | - } else { |
|
| 2526 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | - $val[] = $a; |
|
| 2530 | - } else { |
|
| 2531 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | - } // toujours quoter en char ici |
|
| 2533 | - } |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - $fct = $args_sql = ''; |
|
| 2538 | - // fonction SQL ? |
|
| 2539 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | - $fct = $m[1]; |
|
| 2542 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | - $col = $a[1]; |
|
| 2544 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | - $col = $m[1]; |
|
| 2546 | - $args_sql = $m[2]; |
|
| 2547 | - } |
|
| 2548 | - $args_sql .= $a[2]; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2466 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | + if (count($crit->param) == 0) { |
|
| 2468 | + $op = '='; |
|
| 2469 | + $col = $val = $crit->op; |
|
| 2470 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | + $val = $r[2]; |
|
| 2472 | + } |
|
| 2473 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | + if ($val == 'lang') { |
|
| 2475 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | + } else { |
|
| 2477 | + $defaut = null; |
|
| 2478 | + if ($val == 'id_parent') { |
|
| 2479 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | + // pour eviter l'erreur SQL |
|
| 2482 | + $val = $boucles[$idb]->primary; |
|
| 2483 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | + } elseif ($val == 'id_enfant') { |
|
| 2486 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | + // de la boucle superieure |
|
| 2488 | + $val = 'id_parent'; |
|
| 2489 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | + // un critere conditionnel sur date est traite a part |
|
| 2491 | + // car la date est mise d'office par SPIP, |
|
| 2492 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | + $val = [kwote($val)]; |
|
| 2497 | + } |
|
| 2498 | + } else { |
|
| 2499 | + // comparaison explicite |
|
| 2500 | + // le phraseur impose que le premier param soit du texte |
|
| 2501 | + $params = $crit->param; |
|
| 2502 | + $op = $crit->op; |
|
| 2503 | + if ($op == '==') { |
|
| 2504 | + $op = 'REGEXP'; |
|
| 2505 | + } |
|
| 2506 | + $col = array_shift($params); |
|
| 2507 | + $col = $col[0]->texte; |
|
| 2508 | + |
|
| 2509 | + $val = []; |
|
| 2510 | + $parent = $boucles[$idb]->id_parent; |
|
| 2511 | + |
|
| 2512 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | + if ( |
|
| 2516 | + count($params) == 1 |
|
| 2517 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | + and $params[0][0]->type == 'texte' |
|
| 2519 | + and $params[0][2]->type == 'texte' |
|
| 2520 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | + and (($p == "'") or ($p == '"')) |
|
| 2522 | + and $params[0][1]->type == 'champ' |
|
| 2523 | + ) { |
|
| 2524 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | + } else { |
|
| 2526 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | + $val[] = $a; |
|
| 2530 | + } else { |
|
| 2531 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | + } // toujours quoter en char ici |
|
| 2533 | + } |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + $fct = $args_sql = ''; |
|
| 2538 | + // fonction SQL ? |
|
| 2539 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | + $fct = $m[1]; |
|
| 2542 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | + $col = $a[1]; |
|
| 2544 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | + $col = $m[1]; |
|
| 2546 | + $args_sql = $m[2]; |
|
| 2547 | + } |
|
| 2548 | + $args_sql .= $a[2]; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2552 | 2552 | } |
| 2553 | 2553 | |
| 2554 | 2554 | // compatibilite ancienne version |
| 2555 | 2555 | |
| 2556 | 2556 | function calculer_vieux_in($params) { |
| 2557 | - $deb = $params[0][0]; |
|
| 2558 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | - $last = $params[$k]; |
|
| 2560 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | - $last = $last[$j]; |
|
| 2562 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | - |
|
| 2564 | - if ( |
|
| 2565 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | - ) { |
|
| 2568 | - return $params; |
|
| 2569 | - } |
|
| 2570 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | - $last = $params[$k][$j]; |
|
| 2573 | - $n = strlen($last->texte); |
|
| 2574 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | - $newp = []; |
|
| 2576 | - foreach ($params as $v) { |
|
| 2577 | - if ($v[0]->type != 'texte') { |
|
| 2578 | - $newp[] = $v; |
|
| 2579 | - } else { |
|
| 2580 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | - $t = new Texte(); |
|
| 2582 | - $t->texte = $x; |
|
| 2583 | - $newp[] = [$t]; |
|
| 2584 | - } |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2587 | - |
|
| 2588 | - return $newp; |
|
| 2557 | + $deb = $params[0][0]; |
|
| 2558 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | + $last = $params[$k]; |
|
| 2560 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | + $last = $last[$j]; |
|
| 2562 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | + |
|
| 2564 | + if ( |
|
| 2565 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | + ) { |
|
| 2568 | + return $params; |
|
| 2569 | + } |
|
| 2570 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | + $last = $params[$k][$j]; |
|
| 2573 | + $n = strlen($last->texte); |
|
| 2574 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | + $newp = []; |
|
| 2576 | + foreach ($params as $v) { |
|
| 2577 | + if ($v[0]->type != 'texte') { |
|
| 2578 | + $newp[] = $v; |
|
| 2579 | + } else { |
|
| 2580 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | + $t = new Texte(); |
|
| 2582 | + $t->texte = $x; |
|
| 2583 | + $newp[] = [$t]; |
|
| 2584 | + } |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | + |
|
| 2588 | + return $newp; |
|
| 2589 | 2589 | } |
| 2590 | 2590 | |
| 2591 | 2591 | /** |
@@ -2604,89 +2604,89 @@ discard block |
||
| 2604 | 2604 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2605 | 2605 | **/ |
| 2606 | 2606 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2607 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | - return ''; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - $boucle = $boucles[$idb]; |
|
| 2612 | - $table = $boucle->show; |
|
| 2613 | - |
|
| 2614 | - // si c'est une colonne de la table, ne rien faire |
|
| 2615 | - if (isset($table['field'][$col])) { |
|
| 2616 | - return ''; |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | - return ''; |
|
| 2621 | - } |
|
| 2622 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | - |
|
| 2624 | - $col = $regs[1]; |
|
| 2625 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | - |
|
| 2629 | - if (isset($table['field']["date$suite"])) { |
|
| 2630 | - $date_orig = 'date' . $suite; |
|
| 2631 | - } else { |
|
| 2632 | - $date_orig = substr($suite, 1); |
|
| 2633 | - } |
|
| 2634 | - $pred = $date_orig; |
|
| 2635 | - } else { |
|
| 2636 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | - $pred = 'date'; |
|
| 2638 | - } |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | - ") . '\""; |
|
| 2644 | - |
|
| 2645 | - $col_vraie = $date_orig; |
|
| 2646 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | - |
|
| 2648 | - switch ($col) { |
|
| 2649 | - case 'date': |
|
| 2650 | - $col = $date_orig; |
|
| 2651 | - break; |
|
| 2652 | - case 'jour': |
|
| 2653 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | - break; |
|
| 2655 | - case 'mois': |
|
| 2656 | - $col = "MONTH($date_orig)"; |
|
| 2657 | - break; |
|
| 2658 | - case 'annee': |
|
| 2659 | - $col = "YEAR($date_orig)"; |
|
| 2660 | - break; |
|
| 2661 | - case 'heure': |
|
| 2662 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | - break; |
|
| 2664 | - case 'age': |
|
| 2665 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | - break; |
|
| 2668 | - case 'age_relatif': |
|
| 2669 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | - break; |
|
| 2672 | - case 'jour_relatif': |
|
| 2673 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | - break; |
|
| 2676 | - case 'mois_relatif': |
|
| 2677 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'annee_relatif': |
|
| 2683 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | - $date_orig . ')'; |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - return [$col, $col_vraie]; |
|
| 2607 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | + return ''; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + $boucle = $boucles[$idb]; |
|
| 2612 | + $table = $boucle->show; |
|
| 2613 | + |
|
| 2614 | + // si c'est une colonne de la table, ne rien faire |
|
| 2615 | + if (isset($table['field'][$col])) { |
|
| 2616 | + return ''; |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | + return ''; |
|
| 2621 | + } |
|
| 2622 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | + |
|
| 2624 | + $col = $regs[1]; |
|
| 2625 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | + |
|
| 2629 | + if (isset($table['field']["date$suite"])) { |
|
| 2630 | + $date_orig = 'date' . $suite; |
|
| 2631 | + } else { |
|
| 2632 | + $date_orig = substr($suite, 1); |
|
| 2633 | + } |
|
| 2634 | + $pred = $date_orig; |
|
| 2635 | + } else { |
|
| 2636 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | + $pred = 'date'; |
|
| 2638 | + } |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | + ") . '\""; |
|
| 2644 | + |
|
| 2645 | + $col_vraie = $date_orig; |
|
| 2646 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | + |
|
| 2648 | + switch ($col) { |
|
| 2649 | + case 'date': |
|
| 2650 | + $col = $date_orig; |
|
| 2651 | + break; |
|
| 2652 | + case 'jour': |
|
| 2653 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | + break; |
|
| 2655 | + case 'mois': |
|
| 2656 | + $col = "MONTH($date_orig)"; |
|
| 2657 | + break; |
|
| 2658 | + case 'annee': |
|
| 2659 | + $col = "YEAR($date_orig)"; |
|
| 2660 | + break; |
|
| 2661 | + case 'heure': |
|
| 2662 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | + break; |
|
| 2664 | + case 'age': |
|
| 2665 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | + break; |
|
| 2668 | + case 'age_relatif': |
|
| 2669 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + break; |
|
| 2672 | + case 'jour_relatif': |
|
| 2673 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + break; |
|
| 2676 | + case 'mois_relatif': |
|
| 2677 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'annee_relatif': |
|
| 2683 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | + $date_orig . ')'; |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + return [$col, $col_vraie]; |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
@@ -2705,16 +2705,16 @@ discard block |
||
| 2705 | 2705 | * de colonne SQL et une date. |
| 2706 | 2706 | **/ |
| 2707 | 2707 | function calculer_param_date($date_compare, $date_orig) { |
| 2708 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | - $date_compare = '\'$x\''; |
|
| 2711 | - } else { |
|
| 2712 | - $init = $date_compare; |
|
| 2713 | - } |
|
| 2714 | - |
|
| 2715 | - return |
|
| 2716 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2708 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | + $date_compare = '\'$x\''; |
|
| 2711 | + } else { |
|
| 2712 | + $init = $date_compare; |
|
| 2713 | + } |
|
| 2714 | + |
|
| 2715 | + return |
|
| 2716 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2718 | 2718 | } |
| 2719 | 2719 | |
| 2720 | 2720 | /** |
@@ -2732,20 +2732,20 @@ discard block |
||
| 2732 | 2732 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2733 | 2733 | */ |
| 2734 | 2734 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2735 | - $boucle = &$boucles[$idb]; |
|
| 2736 | - |
|
| 2737 | - $args = []; |
|
| 2738 | - foreach ($crit->param as &$param) { |
|
| 2739 | - array_push( |
|
| 2740 | - $args, |
|
| 2741 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | - ); |
|
| 2743 | - } |
|
| 2735 | + $boucle = &$boucles[$idb]; |
|
| 2744 | 2736 | |
| 2745 | - $boucle->hash .= ' |
|
| 2737 | + $args = []; |
|
| 2738 | + foreach ($crit->param as &$param) { |
|
| 2739 | + array_push( |
|
| 2740 | + $args, |
|
| 2741 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | + ); |
|
| 2743 | + } |
|
| 2744 | + |
|
| 2745 | + $boucle->hash .= ' |
|
| 2746 | 2746 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2747 | 2747 | |
| 2748 | - $boucle->hash .= ' |
|
| 2748 | + $boucle->hash .= ' |
|
| 2749 | 2749 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2750 | 2750 | } |
| 2751 | 2751 | |
@@ -2763,8 +2763,8 @@ discard block |
||
| 2763 | 2763 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2764 | 2764 | */ |
| 2765 | 2765 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2766 | - $boucle = &$boucles[$idb]; |
|
| 2767 | - $boucle->hash .= ' |
|
| 2766 | + $boucle = &$boucles[$idb]; |
|
| 2767 | + $boucle->hash .= ' |
|
| 2768 | 2768 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2769 | 2769 | } |
| 2770 | 2770 | |
@@ -2780,12 +2780,12 @@ discard block |
||
| 2780 | 2780 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2781 | 2781 | */ |
| 2782 | 2782 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2783 | - $boucle = &$boucles[$idb]; |
|
| 2784 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | - foreach ($crit->param as $param) { |
|
| 2786 | - $boucle->hash .= ' |
|
| 2783 | + $boucle = &$boucles[$idb]; |
|
| 2784 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | + foreach ($crit->param as $param) { |
|
| 2786 | + $boucle->hash .= ' |
|
| 2787 | 2787 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2788 | - } |
|
| 2788 | + } |
|
| 2789 | 2789 | } |
| 2790 | 2790 | |
| 2791 | 2791 | /** |
@@ -2802,16 +2802,16 @@ discard block |
||
| 2802 | 2802 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2803 | 2803 | */ |
| 2804 | 2804 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2805 | - $boucle = &$boucles[$idb]; |
|
| 2806 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | - foreach ($crit->param as $param) { |
|
| 2808 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | - $param, |
|
| 2810 | - $idb, |
|
| 2811 | - $boucles, |
|
| 2812 | - $boucles[$idb]->id_parent |
|
| 2813 | - ) . ";\n"; |
|
| 2814 | - } |
|
| 2805 | + $boucle = &$boucles[$idb]; |
|
| 2806 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | + foreach ($crit->param as $param) { |
|
| 2808 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | + $param, |
|
| 2810 | + $idb, |
|
| 2811 | + $boucles, |
|
| 2812 | + $boucles[$idb]->id_parent |
|
| 2813 | + ) . ";\n"; |
|
| 2814 | + } |
|
| 2815 | 2815 | } |
| 2816 | 2816 | |
| 2817 | 2817 | /** |
@@ -2836,16 +2836,16 @@ discard block |
||
| 2836 | 2836 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2837 | 2837 | */ |
| 2838 | 2838 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2839 | - $boucle = &$boucles[$idb]; |
|
| 2840 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | - foreach ($crit->param as $param) { |
|
| 2842 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | - $param, |
|
| 2844 | - $idb, |
|
| 2845 | - $boucles, |
|
| 2846 | - $boucles[$idb]->id_parent |
|
| 2847 | - ) . ";\n"; |
|
| 2848 | - } |
|
| 2839 | + $boucle = &$boucles[$idb]; |
|
| 2840 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | + foreach ($crit->param as $param) { |
|
| 2842 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | + $param, |
|
| 2844 | + $idb, |
|
| 2845 | + $boucles, |
|
| 2846 | + $boucles[$idb]->id_parent |
|
| 2847 | + ) . ";\n"; |
|
| 2848 | + } |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | /** |
@@ -2860,11 +2860,11 @@ discard block |
||
| 2860 | 2860 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2861 | 2861 | */ |
| 2862 | 2862 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2863 | - $boucle = &$boucles[$idb]; |
|
| 2864 | - foreach ($crit->param as $param) { |
|
| 2865 | - $boucle->hash .= ' |
|
| 2863 | + $boucle = &$boucles[$idb]; |
|
| 2864 | + foreach ($crit->param as $param) { |
|
| 2865 | + $boucle->hash .= ' |
|
| 2866 | 2866 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2867 | - } |
|
| 2867 | + } |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | |
@@ -2896,20 +2896,20 @@ discard block |
||
| 2896 | 2896 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2897 | 2897 | */ |
| 2898 | 2898 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2899 | - $boucle = &$boucles[$idb]; |
|
| 2900 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | - if ($crit->param) { |
|
| 2905 | - foreach ($crit->param as $param) { |
|
| 2906 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | - } |
|
| 2909 | - // interdire {si 0} aussi ! |
|
| 2910 | - } else { |
|
| 2911 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | - } |
|
| 2899 | + $boucle = &$boucles[$idb]; |
|
| 2900 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | + if ($crit->param) { |
|
| 2905 | + foreach ($crit->param as $param) { |
|
| 2906 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | + } |
|
| 2909 | + // interdire {si 0} aussi ! |
|
| 2910 | + } else { |
|
| 2911 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | + } |
|
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | 2915 | /** |
@@ -2926,8 +2926,8 @@ discard block |
||
| 2926 | 2926 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2927 | 2927 | */ |
| 2928 | 2928 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2929 | - $boucle = &$boucles[$idb]; |
|
| 2930 | - $boucle->hash .= ' |
|
| 2929 | + $boucle = &$boucles[$idb]; |
|
| 2930 | + $boucle->hash .= ' |
|
| 2931 | 2931 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2932 | 2932 | $command[\'sourcemode\'] = \'table\';'; |
| 2933 | 2933 | } |
@@ -2948,27 +2948,27 @@ discard block |
||
| 2948 | 2948 | */ |
| 2949 | 2949 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2950 | 2950 | |
| 2951 | - $not = $crit->not; |
|
| 2952 | - $boucle = &$boucles[$idb]; |
|
| 2953 | - $primary = $boucle->primary; |
|
| 2951 | + $not = $crit->not; |
|
| 2952 | + $boucle = &$boucles[$idb]; |
|
| 2953 | + $primary = $boucle->primary; |
|
| 2954 | 2954 | |
| 2955 | - if (!$primary or strpos($primary, ',')) { |
|
| 2956 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2955 | + if (!$primary or strpos($primary, ',')) { |
|
| 2956 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2957 | 2957 | |
| 2958 | - return; |
|
| 2959 | - } |
|
| 2960 | - $table = $boucle->type_requete; |
|
| 2961 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2958 | + return; |
|
| 2959 | + } |
|
| 2960 | + $table = $boucle->type_requete; |
|
| 2961 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2962 | 2962 | |
| 2963 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2963 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2964 | 2964 | |
| 2965 | - $in = 'IN'; |
|
| 2966 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | - if ($not) { |
|
| 2968 | - $where = ["'NOT'", $where]; |
|
| 2969 | - } |
|
| 2965 | + $in = 'IN'; |
|
| 2966 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | + if ($not) { |
|
| 2968 | + $where = ["'NOT'", $where]; |
|
| 2969 | + } |
|
| 2970 | 2970 | |
| 2971 | - $boucle->where[] = $where; |
|
| 2971 | + $boucle->where[] = $where; |
|
| 2972 | 2972 | } |
| 2973 | 2973 | |
| 2974 | 2974 | /** |
@@ -2984,8 +2984,8 @@ discard block |
||
| 2984 | 2984 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2985 | 2985 | */ |
| 2986 | 2986 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2987 | - $not = $crit->not; |
|
| 2988 | - $crit->not = $not ? false : true; |
|
| 2989 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | - $crit->not = $not; |
|
| 2987 | + $not = $crit->not; |
|
| 2988 | + $crit->not = $not ? false : true; |
|
| 2989 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | + $crit->not = $not; |
|
| 2991 | 2991 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 50 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 51 | 51 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | $id = $boucle->primary; |
| 71 | 71 | |
| 72 | 72 | if ($not or !$id) { |
| 73 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 73 | + return (['zbug_critere_inconnu', ['critere' => $not.$crit->op]]); |
|
| 74 | 74 | } |
| 75 | 75 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | $not = ($crit->not ? '' : 'NOT'); |
| 105 | 105 | |
| 106 | 106 | // le doublon s'applique sur un type de boucle (article) |
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 107 | + $nom = "'".$boucle->type_requete."'"; |
|
| 108 | 108 | |
| 109 | 109 | // compléter le nom avec un nom précisé {doublons nom} |
| 110 | 110 | // on obtient $nom = "'article' . 'nom'" |
| 111 | 111 | if (isset($crit->param[0])) { |
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 112 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | // $doublons et son index, ici $nom |
| 122 | 122 | |
| 123 | 123 | // debut du code "sql_in('articles.id_article', " |
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 124 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 125 | 125 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 126 | 126 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 127 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons.'[]= ')); |
|
| 128 | 128 | |
| 129 | 129 | // le debut complet du code des doublons |
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 130 | + $debut_doub = $debut_in.$debut_doub; |
|
| 131 | 131 | |
| 132 | 132 | // nom du doublon "('article' . 'nom')]" |
| 133 | 133 | $fin_doub = "($nom)]"; |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | foreach ($boucle->where as $k => $w) { |
| 138 | 138 | if (strpos($w[0], $debut_doub) === 0) { |
| 139 | 139 | // fusionner le sql_in (du where) |
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 140 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 141 | 141 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 142 | 142 | $x = strpos($boucle->hash, $init_comment); |
| 143 | 143 | $len = strlen($init_comment); |
| 144 | 144 | $boucle->hash = |
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 145 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 146 | 146 | |
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 152 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 153 | 153 | |
| 154 | 154 | // déclarer le doublon s'il n'existe pas encore |
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 155 | + $boucle->hash .= $init_comment.$init_code; |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $deux = $deux[0]->texte; |
| 215 | 215 | if ($deux) { |
| 216 | 216 | $boucles[$idb]->limit = |
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 217 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 218 | 218 | } else { |
| 219 | 219 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 220 | 220 | } |
@@ -276,26 +276,26 @@ discard block |
||
| 276 | 276 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 280 | 280 | $boucle->modificateur['debut_nom'] = $type; |
| 281 | 281 | $partie = |
| 282 | 282 | // tester si le numero de page demande est de la forme '@yyy' |
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 283 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 284 | 284 | . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 285 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 286 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 287 | 287 | . "\t}\n" |
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 288 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 289 | 289 | |
| 290 | 290 | $boucle->hash .= ' |
| 291 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 291 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 292 | 292 | |
| 293 | 293 | $boucle->total_parties = $pas; |
| 294 | 294 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 295 | 295 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 296 | 296 | // sauf si pas de primaire, ou si primaire composee |
| 297 | 297 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 298 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 299 | 299 | if ( |
| 300 | 300 | $boucle->primary |
| 301 | 301 | and !preg_match('/[,\s]/', $boucle->primary) |
@@ -342,24 +342,24 @@ discard block |
||
| 342 | 342 | $boucle->hash .= ' |
| 343 | 343 | // RECHERCHE' |
| 344 | 344 | . ($crit->cond ? ' |
| 345 | - if (!strlen(' . $quoi . ')){ |
|
| 345 | + if (!strlen(' . $quoi.')){ |
|
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | - } else' : '') . ' |
|
| 347 | + } else' : '').' |
|
| 348 | 348 | { |
| 349 | 349 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 350 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 350 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 351 | 351 | } |
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 355 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 356 | 356 | if (!in_array($t, $boucles[$idb]->select)) { |
| 357 | 357 | $boucle->select[] = $t; |
| 358 | 358 | } # pour postgres, neuneu ici |
| 359 | 359 | // jointure uniquement sur le serveur principal |
| 360 | 360 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 361 | 361 | if (!$boucle->sql_serveur) { |
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 362 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 363 | 363 | $boucle->from['resultats'] = 'spip_resultats'; |
| 364 | 364 | } |
| 365 | 365 | $boucle->select[] = '$rech_select'; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $c = |
| 427 | 427 | [ |
| 428 | 428 | "'OR'", |
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 429 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 430 | 430 | ["'='", "'$table.id_trad'", "'0'"] |
| 431 | 431 | ]; |
| 432 | 432 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -449,13 +449,13 @@ discard block |
||
| 449 | 449 | $boucle = &$boucles[$idb]; |
| 450 | 450 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 451 | 451 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 452 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 453 | 453 | |
| 454 | 454 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 455 | 455 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 456 | 456 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 457 | 457 | else { |
| 458 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 458 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]); |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -508,16 +508,15 @@ discard block |
||
| 508 | 508 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 509 | 509 | $decompose = decompose_champ_id_objet($champ); |
| 510 | 510 | $champ = array_shift($decompose); |
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 511 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 512 | 512 | } |
| 513 | 513 | } else { |
| 514 | 514 | $cle = $boucle->id_table; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 517 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 521 | 520 | } |
| 522 | 521 | |
| 523 | 522 | /** |
@@ -537,9 +536,9 @@ discard block |
||
| 537 | 536 | $not = ($crit->not ? 'NOT' : ''); |
| 538 | 537 | $serveur = $boucle->sql_serveur; |
| 539 | 538 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 539 | + $c = "sql_in('". |
|
| 540 | + $boucle->id_table.'.'.$boucle->primary |
|
| 541 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 543 | 542 | |
| 544 | 543 | $boucle->where[] = $c; |
| 545 | 544 | } |
@@ -571,7 +570,7 @@ discard block |
||
| 571 | 570 | $t = table_objet_sql($r[1]); |
| 572 | 571 | $t = array_search($t, $boucles[$idb]->from); |
| 573 | 572 | if ($t) { |
| 574 | - $t .= '.' . $r[2]; |
|
| 573 | + $t .= '.'.$r[2]; |
|
| 575 | 574 | } |
| 576 | 575 | } |
| 577 | 576 | } else { |
@@ -586,7 +585,7 @@ discard block |
||
| 586 | 585 | $boucles[$idb]->select[] = $t; |
| 587 | 586 | } |
| 588 | 587 | } else { |
| 589 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 588 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 590 | 589 | } |
| 591 | 590 | } |
| 592 | 591 | |
@@ -656,25 +655,25 @@ discard block |
||
| 656 | 655 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 657 | 656 | or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 658 | 657 | ) { |
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 658 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 660 | 659 | } else { |
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 660 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 662 | 661 | } |
| 663 | 662 | } |
| 664 | 663 | } else { |
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 664 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.(is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | 665 | } |
| 667 | 666 | } |
| 668 | 667 | |
| 669 | 668 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | 669 | $boucle = $boucles[$idb]; |
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 670 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 671 | + $var = '$champs_'.$idb; |
|
| 673 | 672 | $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
| 674 | 673 | if (!$desc) { |
| 675 | 674 | $desc = $boucle->show['field']; |
| 676 | 675 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 676 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 678 | 677 | } |
| 679 | 678 | if ($desc) { |
| 680 | 679 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -749,7 +748,7 @@ discard block |
||
| 749 | 748 | $sens = " . ' DESC'"; |
| 750 | 749 | } |
| 751 | 750 | if (isset($boucle->modificateur['collate'])) { |
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 751 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 753 | 752 | } |
| 754 | 753 | |
| 755 | 754 | // Pour chaque paramètre du critère |
@@ -771,14 +770,14 @@ discard block |
||
| 771 | 770 | if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
| 772 | 771 | $expression = trim($m[1]); |
| 773 | 772 | $champ = trim($m[2]); |
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 773 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 775 | 774 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 776 | 775 | } else { |
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 776 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 778 | 777 | } |
| 779 | 778 | |
| 780 | 779 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 780 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 782 | 781 | // {par FONCTION(champ)} |
| 783 | 782 | if (isset($match) and count($match) > 2) { |
| 784 | 783 | $par = substr($match[2], 1, -1); |
@@ -788,7 +787,7 @@ discard block |
||
| 788 | 787 | if ($par == 'hasard') { |
| 789 | 788 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 790 | 789 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 790 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 792 | 791 | } else { |
| 793 | 792 | // cas général {par champ}, {par table.champ}, ... |
| 794 | 793 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -797,7 +796,7 @@ discard block |
||
| 797 | 796 | |
| 798 | 797 | // on ne sait pas traiter… |
| 799 | 798 | else { |
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 799 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 801 | 800 | } |
| 802 | 801 | |
| 803 | 802 | // En cas d'erreur de squelette retournée par une fonction |
@@ -817,14 +816,14 @@ discard block |
||
| 817 | 816 | |
| 818 | 817 | if ($fct) { |
| 819 | 818 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 819 | + $order = "'$fct(".$r[1].")'"; |
|
| 821 | 820 | } else { |
| 822 | 821 | $order = "'$fct(' . $order . ')'"; |
| 823 | 822 | } |
| 824 | 823 | } |
| 825 | - $t = $order . $collecte . $sens; |
|
| 824 | + $t = $order.$collecte.$sens; |
|
| 826 | 825 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 827 | - $t = $r[1] . $r[2]; |
|
| 826 | + $t = $r[1].$r[2]; |
|
| 828 | 827 | } |
| 829 | 828 | |
| 830 | 829 | $boucle->order[] = $t; |
@@ -874,16 +873,16 @@ discard block |
||
| 874 | 873 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | 874 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 876 | 875 | if (is_array($_champ)) { |
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 876 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 878 | 877 | } |
| 879 | 878 | $boucle = &$boucles[$idb]; |
| 880 | - $texte = '0+' . $_champ; |
|
| 879 | + $texte = '0+'.$_champ; |
|
| 881 | 880 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 882 | 881 | if ($suite !== "''") { |
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 882 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 884 | 883 | } |
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 884 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 885 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 887 | 886 | |
| 888 | 887 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 889 | 888 | $orderassinum = trim($orderassinum, "'"); |
@@ -912,13 +911,13 @@ discard block |
||
| 912 | 911 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | 912 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 914 | 913 | if (is_array($_champ)) { |
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 914 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 916 | 915 | } |
| 917 | 916 | $boucle = &$boucles[$idb]; |
| 918 | - $texte = '0+' . $_champ; |
|
| 917 | + $texte = '0+'.$_champ; |
|
| 919 | 918 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 920 | 919 | if ($suite !== "''") { |
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 920 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 922 | 921 | } |
| 923 | 922 | |
| 924 | 923 | $as = false; |
@@ -934,8 +933,8 @@ discard block |
||
| 934 | 933 | } |
| 935 | 934 | |
| 936 | 935 | if (!$as) { |
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 936 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 937 | + $boucle->select[] = $select.$as; |
|
| 939 | 938 | } |
| 940 | 939 | $order = "'$as'"; |
| 941 | 940 | return $order; |
@@ -960,10 +959,10 @@ discard block |
||
| 960 | 959 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | 960 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 962 | 961 | if (is_array($_champ)) { |
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 962 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 964 | 963 | } |
| 965 | 964 | $boucle = &$boucles[$idb]; |
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 965 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 967 | 966 | $order = "'multi'"; |
| 968 | 967 | return $order; |
| 969 | 968 | } |
@@ -989,7 +988,7 @@ discard block |
||
| 989 | 988 | |
| 990 | 989 | // le champ existe dans la table, pas de souci (le plus commun) |
| 991 | 990 | if (isset($desc['field'][$par])) { |
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 991 | + $par = $boucle->id_table.'.'.$par; |
|
| 993 | 992 | } |
| 994 | 993 | // le champ est peut être une jointure |
| 995 | 994 | else { |
@@ -1010,24 +1009,24 @@ discard block |
||
| 1010 | 1009 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1011 | 1010 | // Si la table est déjà dans le from, on la réutilise. |
| 1012 | 1011 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1012 | + $par = $infos['alias'].'.'.$champ; |
|
| 1014 | 1013 | } elseif ( |
| 1015 | 1014 | $boucle->jointures_explicites |
| 1016 | 1015 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 1017 | 1016 | ) { |
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1017 | + $par = $alias.'.'.$champ; |
|
| 1019 | 1018 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1019 | + $par = $alias.'.'.$champ; |
|
| 1021 | 1020 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1022 | 1021 | } elseif ( |
| 1023 | 1022 | $table_alias |
| 1024 | 1023 | and isset($boucle->from[$table_alias]) |
| 1025 | 1024 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1026 | 1025 | ) { |
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1026 | + $par = $infos['alias'].'.'.$champ; |
|
| 1028 | 1027 | } elseif ($table) { |
| 1029 | 1028 | // On avait table + champ, mais on ne les a pas trouvés |
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1031 | 1030 | } else { |
| 1032 | 1031 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1033 | 1032 | } |
@@ -1051,7 +1050,7 @@ discard block |
||
| 1051 | 1050 | if (!$t) { |
| 1052 | 1051 | $t = trouver_jointure_champ($champ, $boucle); |
| 1053 | 1052 | } |
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1053 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1055 | 1054 | } |
| 1056 | 1055 | |
| 1057 | 1056 | /** |
@@ -1096,9 +1095,9 @@ discard block |
||
| 1096 | 1095 | $boucle->default_order[] = ' DESC'; |
| 1097 | 1096 | } |
| 1098 | 1097 | } else { |
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1098 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1100 | 1099 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1100 | + $t = $r[1].$r[2]; |
|
| 1102 | 1101 | } |
| 1103 | 1102 | $boucle->order[$n - 1] = $t; |
| 1104 | 1103 | } |
@@ -1133,7 +1132,7 @@ discard block |
||
| 1133 | 1132 | $_order = array_pop($boucle->order); |
| 1134 | 1133 | |
| 1135 | 1134 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1136 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1135 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1137 | 1136 | } |
| 1138 | 1137 | |
| 1139 | 1138 | |
@@ -1141,7 +1140,7 @@ discard block |
||
| 1141 | 1140 | $params = $crit->param; |
| 1142 | 1141 | |
| 1143 | 1142 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1144 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1143 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1145 | 1144 | } |
| 1146 | 1145 | |
| 1147 | 1146 | $boucle = &$boucles[$idb]; |
@@ -1162,7 +1161,7 @@ discard block |
||
| 1162 | 1161 | if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
| 1163 | 1162 | $date = $date[0]->texte; |
| 1164 | 1163 | if (!isset($fields[$date])) { |
| 1165 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1164 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1166 | 1165 | } |
| 1167 | 1166 | } else { |
| 1168 | 1167 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1174,38 +1173,38 @@ discard block |
||
| 1174 | 1173 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1175 | 1174 | } |
| 1176 | 1175 | $annee = $params ? array_shift($params) : ''; |
| 1177 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1176 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1177 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1179 | 1178 | ') ? $x : date("Y"))'; |
| 1180 | 1179 | |
| 1181 | 1180 | $mois = $params ? array_shift($params) : ''; |
| 1182 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1181 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1182 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1184 | 1183 | ') ? $x : date("m"))'; |
| 1185 | 1184 | |
| 1186 | 1185 | $jour = $params ? array_shift($params) : ''; |
| 1187 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1186 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1187 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1189 | 1188 | ') ? $x : date("d"))'; |
| 1190 | 1189 | |
| 1191 | 1190 | $annee2 = $params ? array_shift($params) : ''; |
| 1192 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1191 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1192 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1194 | 1193 | ') ? $x : date("Y"))'; |
| 1195 | 1194 | |
| 1196 | 1195 | $mois2 = $params ? array_shift($params) : ''; |
| 1197 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1196 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1197 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1199 | 1198 | ') ? $x : date("m"))'; |
| 1200 | 1199 | |
| 1201 | 1200 | $jour2 = $params ? array_shift($params) : ''; |
| 1202 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1201 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1202 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1204 | 1203 | ') ? $x : date("d"))'; |
| 1205 | 1204 | |
| 1206 | - $date = $boucle->id_table . ".$date"; |
|
| 1205 | + $date = $boucle->id_table.".$date"; |
|
| 1207 | 1206 | |
| 1208 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1207 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1209 | 1208 | if ($type == 'jour') { |
| 1210 | 1209 | $boucle->where[] = [ |
| 1211 | 1210 | "'='", |
@@ -1277,14 +1276,13 @@ discard block |
||
| 1277 | 1276 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1278 | 1277 | |
| 1279 | 1278 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1280 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1279 | + $boucle->limit = $a11.','.$a21; |
|
| 1281 | 1280 | } else { |
| 1282 | 1281 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1283 | 1282 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1284 | 1283 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1285 | 1284 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1286 | - $mode = (($op == '/') ? '/' : |
|
| 1287 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1285 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1288 | 1286 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1289 | 1287 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1290 | 1288 | $boucle->limit = |
@@ -1330,8 +1328,7 @@ discard block |
||
| 1330 | 1328 | // {1/3} |
| 1331 | 1329 | if ($op1 == '/') { |
| 1332 | 1330 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1333 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | - "($total_parties ? $total_parties : 1)"; |
|
| 1331 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1335 | 1332 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1336 | 1333 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1337 | 1334 | } else { |
@@ -1342,15 +1339,13 @@ discard block |
||
| 1342 | 1339 | |
| 1343 | 1340 | // cas {x,n-1} |
| 1344 | 1341 | if ($op2 == '-') { |
| 1345 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | - ($total_parties . ' - 1')); |
|
| 1342 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1343 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1348 | 1344 | } else { |
| 1349 | 1345 | // {x,1} ou {pagination} |
| 1350 | 1346 | $fin = '$debut_boucle' |
| 1351 | 1347 | . (is_numeric($total_parties) ? |
| 1352 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | - ('+' . $total_parties . ' - 1')); |
|
| 1348 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1354 | 1349 | } |
| 1355 | 1350 | |
| 1356 | 1351 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1368,11 +1363,11 @@ discard block |
||
| 1368 | 1363 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1369 | 1364 | |
| 1370 | 1365 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1371 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1366 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1372 | 1367 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1373 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1368 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1369 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1370 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | 1371 | . "\n\tif (\$debut_boucle>0" |
| 1377 | 1372 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1378 | 1373 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1457,16 +1452,16 @@ discard block |
||
| 1457 | 1452 | // critere personnalise ? |
| 1458 | 1453 | if ( |
| 1459 | 1454 | (!$serveur or |
| 1460 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | - and (!function_exists($f = $f . '_dist')) |
|
| 1462 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | - and (!function_exists($f = $f . '_dist')) |
|
| 1455 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1456 | + and (!function_exists($f = $f.'_dist')) |
|
| 1457 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1458 | + and (!function_exists($f = $f.'_dist')) |
|
| 1464 | 1459 | ) |
| 1465 | 1460 | ) |
| 1466 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1461 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1462 | + and (!function_exists($f = $f.'_dist')) |
|
| 1463 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1464 | + and (!function_exists($f = $f.'_dist')) |
|
| 1470 | 1465 | ) { |
| 1471 | 1466 | // fonction critere standard |
| 1472 | 1467 | $f = $defaut; |
@@ -1497,9 +1492,9 @@ discard block |
||
| 1497 | 1492 | */ |
| 1498 | 1493 | function kwote($lisp, $serveur = '', $type = '') { |
| 1499 | 1494 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1500 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1495 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1501 | 1496 | } else { |
| 1502 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1497 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1503 | 1498 | } |
| 1504 | 1499 | } |
| 1505 | 1500 | |
@@ -1521,7 +1516,7 @@ discard block |
||
| 1521 | 1516 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1522 | 1517 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1523 | 1518 | if (!$r) { |
| 1524 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1519 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 1525 | 1520 | } |
| 1526 | 1521 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1527 | 1522 | |
@@ -1546,8 +1541,8 @@ discard block |
||
| 1546 | 1541 | "'NOT'", |
| 1547 | 1542 | [ |
| 1548 | 1543 | "'IN'", |
| 1549 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1544 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1545 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1551 | 1546 | ] |
| 1552 | 1547 | ]; |
| 1553 | 1548 | } |
@@ -1564,22 +1559,22 @@ discard block |
||
| 1564 | 1559 | $descr = $boucles[$idb]->descr; |
| 1565 | 1560 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1566 | 1561 | |
| 1567 | - $var = '$in' . $cpt++; |
|
| 1562 | + $var = '$in'.$cpt++; |
|
| 1568 | 1563 | $x = "\n\t$var = array();"; |
| 1569 | 1564 | foreach ($val as $k => $v) { |
| 1570 | 1565 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1571 | 1566 | // optimiser le traitement des constantes |
| 1572 | 1567 | if (is_numeric($r[2])) { |
| 1573 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1568 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1574 | 1569 | } else { |
| 1575 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1570 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1576 | 1571 | } |
| 1577 | 1572 | } else { |
| 1578 | 1573 | // Pour permettre de passer des tableaux de valeurs |
| 1579 | 1574 | // on repere l'utilisation brute de #ENV**{X}, |
| 1580 | 1575 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1581 | 1576 | // et on deballe mais en rajoutant l'anti XSS |
| 1582 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1577 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | 1578 | } |
| 1584 | 1579 | } |
| 1585 | 1580 | |
@@ -1593,7 +1588,7 @@ discard block |
||
| 1593 | 1588 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1594 | 1589 | } |
| 1595 | 1590 | |
| 1596 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1591 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1597 | 1592 | } |
| 1598 | 1593 | |
| 1599 | 1594 | /** |
@@ -1666,7 +1661,7 @@ discard block |
||
| 1666 | 1661 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1667 | 1662 | } |
| 1668 | 1663 | // nous aider en mode debug. |
| 1669 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1664 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1670 | 1665 | $boucle->modificateur['id_'] = $champs; |
| 1671 | 1666 | |
| 1672 | 1667 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1917,8 +1912,8 @@ discard block |
||
| 1917 | 1912 | "'NOT'", |
| 1918 | 1913 | [ |
| 1919 | 1914 | "'IN'", |
| 1920 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1915 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1916 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1922 | 1917 | ] |
| 1923 | 1918 | ]; |
| 1924 | 1919 | } |
@@ -1929,7 +1924,7 @@ discard block |
||
| 1929 | 1924 | if ($crit->cond) { |
| 1930 | 1925 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1931 | 1926 | if ($col === 'date' or $col === 'date_redac') { |
| 1932 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1927 | + if ($pred === "\$Pile[0]['".$col."']") { |
|
| 1933 | 1928 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1934 | 1929 | } |
| 1935 | 1930 | } |
@@ -2092,7 +2087,7 @@ discard block |
||
| 2092 | 2087 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2093 | 2088 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2094 | 2089 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2095 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2090 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2096 | 2091 | } |
| 2097 | 2092 | // sinon expliciter les |
| 2098 | 2093 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2108,14 +2103,14 @@ discard block |
||
| 2108 | 2103 | ) { |
| 2109 | 2104 | $r = $r[1] |
| 2110 | 2105 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2111 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2106 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2112 | 2107 | $val[0] = "sql_quote($r)"; |
| 2113 | 2108 | } |
| 2114 | 2109 | elseif ( |
| 2115 | 2110 | strpos($val[0], '@@defaultcast@@') !== false |
| 2116 | 2111 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2117 | 2112 | ) { |
| 2118 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2113 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2119 | 2114 | } |
| 2120 | 2115 | } |
| 2121 | 2116 | |
@@ -2123,7 +2118,7 @@ discard block |
||
| 2123 | 2118 | strpos($val[0], '@@defaultcast@@') !== false |
| 2124 | 2119 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2125 | 2120 | ) { |
| 2126 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2121 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2127 | 2122 | } |
| 2128 | 2123 | |
| 2129 | 2124 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2139,7 +2134,7 @@ discard block |
||
| 2139 | 2134 | // inserer le nom de la table SQL devant le nom du champ |
| 2140 | 2135 | if ($table) { |
| 2141 | 2136 | if ($col[0] == '`') { |
| 2142 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2137 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2143 | 2138 | } else { |
| 2144 | 2139 | $arg = "$table.$col"; |
| 2145 | 2140 | } |
@@ -2273,9 +2268,9 @@ discard block |
||
| 2273 | 2268 | **/ |
| 2274 | 2269 | function primary_doublee($decompose, $table) { |
| 2275 | 2270 | $e1 = reset($decompose); |
| 2276 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2271 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2277 | 2272 | |
| 2278 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2273 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2279 | 2274 | } |
| 2280 | 2275 | |
| 2281 | 2276 | /** |
@@ -2314,7 +2309,7 @@ discard block |
||
| 2314 | 2309 | $checkarrivee |
| 2315 | 2310 | and is_string($checkarrivee) |
| 2316 | 2311 | and $a = table_objet($checkarrivee) |
| 2317 | - and in_array($a . '_liens', $joints) |
|
| 2312 | + and in_array($a.'_liens', $joints) |
|
| 2318 | 2313 | ) { |
| 2319 | 2314 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2320 | 2315 | return $res; |
@@ -2334,12 +2329,12 @@ discard block |
||
| 2334 | 2329 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2335 | 2330 | $joindre = false; |
| 2336 | 2331 | foreach ($cols as $col) { |
| 2337 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2332 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2338 | 2333 | if (trouver_champ($c, $boucle->where)) { |
| 2339 | 2334 | $joindre = true; |
| 2340 | 2335 | } else { |
| 2341 | 2336 | // mais ca peut etre dans le FIELD pour le Having |
| 2342 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2337 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2343 | 2338 | if (trouver_champ($c, $boucle->select)) { |
| 2344 | 2339 | $joindre = true; |
| 2345 | 2340 | } |
@@ -2385,7 +2380,7 @@ discard block |
||
| 2385 | 2380 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2386 | 2381 | |
| 2387 | 2382 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2388 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2383 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2389 | 2384 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2390 | 2385 | |
| 2391 | 2386 | if (!$intermediaire or !$arrivee) { |
@@ -2489,7 +2484,7 @@ discard block |
||
| 2489 | 2484 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2490 | 2485 | // un critere conditionnel sur date est traite a part |
| 2491 | 2486 | // car la date est mise d'office par SPIP, |
| 2492 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2487 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2493 | 2488 | } |
| 2494 | 2489 | |
| 2495 | 2490 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2521,7 +2516,7 @@ discard block |
||
| 2521 | 2516 | and (($p == "'") or ($p == '"')) |
| 2522 | 2517 | and $params[0][1]->type == 'champ' |
| 2523 | 2518 | ) { |
| 2524 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2519 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2525 | 2520 | } else { |
| 2526 | 2521 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2527 | 2522 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2537,7 +2532,7 @@ discard block |
||
| 2537 | 2532 | $fct = $args_sql = ''; |
| 2538 | 2533 | // fonction SQL ? |
| 2539 | 2534 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2540 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2535 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2541 | 2536 | $fct = $m[1]; |
| 2542 | 2537 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2543 | 2538 | $col = $a[1]; |
@@ -2627,7 +2622,7 @@ discard block |
||
| 2627 | 2622 | # si oui choisir ce champ, sinon choisir xxxx |
| 2628 | 2623 | |
| 2629 | 2624 | if (isset($table['field']["date$suite"])) { |
| 2630 | - $date_orig = 'date' . $suite; |
|
| 2625 | + $date_orig = 'date'.$suite; |
|
| 2631 | 2626 | } else { |
| 2632 | 2627 | $date_orig = substr($suite, 1); |
| 2633 | 2628 | } |
@@ -2638,12 +2633,12 @@ discard block |
||
| 2638 | 2633 | } |
| 2639 | 2634 | } |
| 2640 | 2635 | |
| 2641 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2636 | + $date_compare = "\"' . normaliser_date(". |
|
| 2637 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2643 | 2638 | ") . '\""; |
| 2644 | 2639 | |
| 2645 | 2640 | $col_vraie = $date_orig; |
| 2646 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2641 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2647 | 2642 | |
| 2648 | 2643 | switch ($col) { |
| 2649 | 2644 | case 'date': |
@@ -2663,26 +2658,26 @@ discard block |
||
| 2663 | 2658 | break; |
| 2664 | 2659 | case 'age': |
| 2665 | 2660 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2666 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2661 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2667 | 2662 | break; |
| 2668 | 2663 | case 'age_relatif': |
| 2669 | 2664 | $col = calculer_param_date($date_compare, $date_orig); |
| 2670 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2665 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2671 | 2666 | break; |
| 2672 | 2667 | case 'jour_relatif': |
| 2673 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2668 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2669 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2675 | 2670 | break; |
| 2676 | 2671 | case 'mois_relatif': |
| 2677 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2672 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2673 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2674 | + ')-YEAR('.$date_orig.'))'; |
|
| 2675 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2681 | 2676 | break; |
| 2682 | 2677 | case 'annee_relatif': |
| 2683 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | - $date_orig . ')'; |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2679 | + $date_orig.')'; |
|
| 2680 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2686 | 2681 | break; |
| 2687 | 2682 | } |
| 2688 | 2683 | |
@@ -2743,10 +2738,10 @@ discard block |
||
| 2743 | 2738 | } |
| 2744 | 2739 | |
| 2745 | 2740 | $boucle->hash .= ' |
| 2746 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2741 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2747 | 2742 | |
| 2748 | 2743 | $boucle->hash .= ' |
| 2749 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2744 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2750 | 2745 | } |
| 2751 | 2746 | |
| 2752 | 2747 | /** |
@@ -2765,7 +2760,7 @@ discard block |
||
| 2765 | 2760 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2766 | 2761 | $boucle = &$boucles[$idb]; |
| 2767 | 2762 | $boucle->hash .= ' |
| 2768 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2763 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2769 | 2764 | } |
| 2770 | 2765 | |
| 2771 | 2766 | |
@@ -2784,7 +2779,7 @@ discard block |
||
| 2784 | 2779 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2785 | 2780 | foreach ($crit->param as $param) { |
| 2786 | 2781 | $boucle->hash .= ' |
| 2787 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2782 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2788 | 2783 | } |
| 2789 | 2784 | } |
| 2790 | 2785 | |
@@ -2803,14 +2798,14 @@ discard block |
||
| 2803 | 2798 | */ |
| 2804 | 2799 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2805 | 2800 | $boucle = &$boucles[$idb]; |
| 2806 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2801 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2807 | 2802 | foreach ($crit->param as $param) { |
| 2808 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2803 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2809 | 2804 | $param, |
| 2810 | 2805 | $idb, |
| 2811 | 2806 | $boucles, |
| 2812 | 2807 | $boucles[$idb]->id_parent |
| 2813 | - ) . ";\n"; |
|
| 2808 | + ).";\n"; |
|
| 2814 | 2809 | } |
| 2815 | 2810 | } |
| 2816 | 2811 | |
@@ -2837,14 +2832,14 @@ discard block |
||
| 2837 | 2832 | */ |
| 2838 | 2833 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2839 | 2834 | $boucle = &$boucles[$idb]; |
| 2840 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2835 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2841 | 2836 | foreach ($crit->param as $param) { |
| 2842 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2837 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2843 | 2838 | $param, |
| 2844 | 2839 | $idb, |
| 2845 | 2840 | $boucles, |
| 2846 | 2841 | $boucles[$idb]->id_parent |
| 2847 | - ) . ";\n"; |
|
| 2842 | + ).";\n"; |
|
| 2848 | 2843 | } |
| 2849 | 2844 | } |
| 2850 | 2845 | |
@@ -2863,7 +2858,7 @@ discard block |
||
| 2863 | 2858 | $boucle = &$boucles[$idb]; |
| 2864 | 2859 | foreach ($crit->param as $param) { |
| 2865 | 2860 | $boucle->hash .= ' |
| 2866 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2861 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2867 | 2862 | } |
| 2868 | 2863 | } |
| 2869 | 2864 | |
@@ -2904,7 +2899,7 @@ discard block |
||
| 2904 | 2899 | if ($crit->param) { |
| 2905 | 2900 | foreach ($crit->param as $param) { |
| 2906 | 2901 | $boucle->hash .= "\t\$command['si'][] = " |
| 2907 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2902 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2908 | 2903 | } |
| 2909 | 2904 | // interdire {si 0} aussi ! |
| 2910 | 2905 | } else { |
@@ -2928,7 +2923,7 @@ discard block |
||
| 2928 | 2923 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2929 | 2924 | $boucle = &$boucles[$idb]; |
| 2930 | 2925 | $boucle->hash .= ' |
| 2931 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2926 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2932 | 2927 | $command[\'sourcemode\'] = \'table\';'; |
| 2933 | 2928 | } |
| 2934 | 2929 | |
@@ -2963,7 +2958,7 @@ discard block |
||
| 2963 | 2958 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2964 | 2959 | |
| 2965 | 2960 | $in = 'IN'; |
| 2966 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2961 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | 2962 | if ($not) { |
| 2968 | 2963 | $where = ["'NOT'", $where]; |
| 2969 | 2964 | } |
@@ -11,127 +11,127 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = ' />'; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = ' />'; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | - } else { |
|
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | - |
|
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | + } else { |
|
| 36 | + $t = '{fond=' . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | + |
|
| 40 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = []; |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = []; |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = '#' |
|
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = '#' |
|
| 63 | + . ($boucle ? ($boucle . ':') : '') |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - [$type, $valeur] = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + [$type, $valeur] = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | - [$texte, $type] = $args[$i]; |
|
| 105 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if ( |
|
| 124 | - ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | - ) { |
|
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 103 | + for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | + [$texte, $type] = $args[$i]; |
|
| 105 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if ( |
|
| 124 | + ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | + ) { |
|
| 127 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function format_texte_html($texte) { |
| 136 | - return $texte; |
|
| 136 | + return $texte; |
|
| 137 | 137 | } |
@@ -31,36 +31,36 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | 33 | if (strpos($file, '#') === false) { |
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 34 | + $t = $file ? ('('.$file.')') : ''; |
|
| 35 | 35 | } else { |
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 36 | + $t = '{fond='.$file.'}'; |
|
| 37 | 37 | } |
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 38 | + $args = !$args ? '' : ('{'.join(', ', $args).'}'); |
|
| 39 | 39 | |
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 40 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | 44 | $contenu = []; |
| 45 | 45 | foreach ($args as $l => $t) { |
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>'.join(' ', $contenu).'</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | 53 | foreach ($args as $k => $v) { |
| 54 | 54 | $args[$k] = "$k=$v"; |
| 55 | 55 | } |
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 56 | + $args = (!$args ? '' : ('{'.join(',', $args).'}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | 62 | $nom = '#' |
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 63 | + . ($boucle ? ($boucle.':') : '') |
|
| 64 | 64 | . $nom |
| 65 | 65 | . $etoile |
| 66 | 66 | . $args |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | $critere[$k] = $crit_s; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 93 | + return (!$critere ? '' : ('{'.join(',', $critere).'}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | 97 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 98 | + . (!$args ? '' : ('{'.join(',', $args).'}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | // si un texte se termine par ( et est suivi d'un champ |
| 112 | 112 | // ou assimiles, forcer la notation pleine |
| 113 | 113 | if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 114 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 115 | 115 | } |
| 116 | 116 | } else { |
| 117 | 117 | if ($type == 'texte') { |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
| 125 | 125 | or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
| 126 | 126 | ) { |
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |