@@ -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 | /** |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_desinstaller_plugin_dist() { |
| 34 | 34 | |
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $arg = $securiser_action(); |
|
| 37 | - [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | - $dir_type = '_DIR_PLUGINS'; |
|
| 39 | - if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | - $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | - } |
|
| 42 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | - $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | - if ($infos and !$infos['install_test'][0]) { |
|
| 45 | - include_spip('inc/plugin'); |
|
| 46 | - ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | - $erreur = ''; |
|
| 48 | - } else { |
|
| 49 | - $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | - } |
|
| 51 | - if ($redirect = _request('redirect')) { |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - if ($erreur) { |
|
| 54 | - $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | - } |
|
| 56 | - $redirect = str_replace('&', '&', $redirect); |
|
| 57 | - redirige_par_entete($redirect); |
|
| 58 | - } |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $arg = $securiser_action(); |
|
| 37 | + [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | + $dir_type = '_DIR_PLUGINS'; |
|
| 39 | + if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | + $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | + } |
|
| 42 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | + $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | + if ($infos and !$infos['install_test'][0]) { |
|
| 45 | + include_spip('inc/plugin'); |
|
| 46 | + ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | + $erreur = ''; |
|
| 48 | + } else { |
|
| 49 | + $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | + } |
|
| 51 | + if ($redirect = _request('redirect')) { |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + if ($erreur) { |
|
| 54 | + $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | + } |
|
| 56 | + $redirect = str_replace('&', '&', $redirect); |
|
| 57 | + redirige_par_entete($redirect); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | ) { |
@@ -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 | } |
@@ -1135,7 +1134,7 @@ discard block |
||
| 1135 | 1134 | |
| 1136 | 1135 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1137 | 1136 | |
| 1138 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1139 | 1138 | $boucle->order[] = $order; |
| 1140 | 1139 | } |
| 1141 | 1140 | |
@@ -1144,7 +1143,7 @@ discard block |
||
| 1144 | 1143 | $params = $crit->param; |
| 1145 | 1144 | |
| 1146 | 1145 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1147 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1146 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1148 | 1147 | } |
| 1149 | 1148 | |
| 1150 | 1149 | $boucle = &$boucles[$idb]; |
@@ -1165,7 +1164,7 @@ discard block |
||
| 1165 | 1164 | if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
| 1166 | 1165 | $date = $date[0]->texte; |
| 1167 | 1166 | if (!isset($fields[$date])) { |
| 1168 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1167 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1169 | 1168 | } |
| 1170 | 1169 | } else { |
| 1171 | 1170 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1177,38 +1176,38 @@ discard block |
||
| 1177 | 1176 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1178 | 1177 | } |
| 1179 | 1178 | $annee = $params ? array_shift($params) : ''; |
| 1180 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1180 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1182 | 1181 | ') ? $x : date("Y"))'; |
| 1183 | 1182 | |
| 1184 | 1183 | $mois = $params ? array_shift($params) : ''; |
| 1185 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1185 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1187 | 1186 | ') ? $x : date("m"))'; |
| 1188 | 1187 | |
| 1189 | 1188 | $jour = $params ? array_shift($params) : ''; |
| 1190 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1190 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1192 | 1191 | ') ? $x : date("d"))'; |
| 1193 | 1192 | |
| 1194 | 1193 | $annee2 = $params ? array_shift($params) : ''; |
| 1195 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1195 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1197 | 1196 | ') ? $x : date("Y"))'; |
| 1198 | 1197 | |
| 1199 | 1198 | $mois2 = $params ? array_shift($params) : ''; |
| 1200 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1200 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1202 | 1201 | ') ? $x : date("m"))'; |
| 1203 | 1202 | |
| 1204 | 1203 | $jour2 = $params ? array_shift($params) : ''; |
| 1205 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1205 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1207 | 1206 | ') ? $x : date("d"))'; |
| 1208 | 1207 | |
| 1209 | - $date = $boucle->id_table . ".$date"; |
|
| 1208 | + $date = $boucle->id_table.".$date"; |
|
| 1210 | 1209 | |
| 1211 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1210 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1212 | 1211 | if ($type == 'jour') { |
| 1213 | 1212 | $boucle->where[] = [ |
| 1214 | 1213 | "'='", |
@@ -1280,14 +1279,13 @@ discard block |
||
| 1280 | 1279 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1281 | 1280 | |
| 1282 | 1281 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1283 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1282 | + $boucle->limit = $a11.','.$a21; |
|
| 1284 | 1283 | } else { |
| 1285 | 1284 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1286 | 1285 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1287 | 1286 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1288 | 1287 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1289 | - $mode = (($op == '/') ? '/' : |
|
| 1290 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1291 | 1289 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1292 | 1290 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1293 | 1291 | $boucle->limit = |
@@ -1333,8 +1331,7 @@ discard block |
||
| 1333 | 1331 | // {1/3} |
| 1334 | 1332 | if ($op1 == '/') { |
| 1335 | 1333 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1336 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | - "($total_parties ? $total_parties : 1)"; |
|
| 1334 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1338 | 1335 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1339 | 1336 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1340 | 1337 | } else { |
@@ -1345,15 +1342,13 @@ discard block |
||
| 1345 | 1342 | |
| 1346 | 1343 | // cas {x,n-1} |
| 1347 | 1344 | if ($op2 == '-') { |
| 1348 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | - ($total_parties . ' - 1')); |
|
| 1345 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1351 | 1347 | } else { |
| 1352 | 1348 | // {x,1} ou {pagination} |
| 1353 | 1349 | $fin = '$debut_boucle' |
| 1354 | 1350 | . (is_numeric($total_parties) ? |
| 1355 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | - ('+' . $total_parties . ' - 1')); |
|
| 1351 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1357 | 1352 | } |
| 1358 | 1353 | |
| 1359 | 1354 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1371,11 +1366,11 @@ discard block |
||
| 1371 | 1366 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1372 | 1367 | |
| 1373 | 1368 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1374 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1369 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1375 | 1370 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1376 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1377 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1378 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1371 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1372 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1373 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1379 | 1374 | . "\n\tif (\$debut_boucle>0" |
| 1380 | 1375 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1381 | 1376 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1460,16 +1455,16 @@ discard block |
||
| 1460 | 1455 | // critere personnalise ? |
| 1461 | 1456 | if ( |
| 1462 | 1457 | (!$serveur or |
| 1463 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1464 | - and (!function_exists($f = $f . '_dist')) |
|
| 1465 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1466 | - and (!function_exists($f = $f . '_dist')) |
|
| 1458 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1459 | + and (!function_exists($f = $f.'_dist')) |
|
| 1460 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1461 | + and (!function_exists($f = $f.'_dist')) |
|
| 1467 | 1462 | ) |
| 1468 | 1463 | ) |
| 1469 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1465 | + and (!function_exists($f = $f.'_dist')) |
|
| 1466 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1467 | + and (!function_exists($f = $f.'_dist')) |
|
| 1473 | 1468 | ) { |
| 1474 | 1469 | // fonction critere standard |
| 1475 | 1470 | $f = $defaut; |
@@ -1500,9 +1495,9 @@ discard block |
||
| 1500 | 1495 | */ |
| 1501 | 1496 | function kwote($lisp, $serveur = '', $type = '') { |
| 1502 | 1497 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1503 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1498 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1504 | 1499 | } else { |
| 1505 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1500 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1506 | 1501 | } |
| 1507 | 1502 | } |
| 1508 | 1503 | |
@@ -1524,7 +1519,7 @@ discard block |
||
| 1524 | 1519 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1525 | 1520 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1526 | 1521 | if (!$r) { |
| 1527 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1522 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1528 | 1523 | } |
| 1529 | 1524 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1530 | 1525 | |
@@ -1549,8 +1544,8 @@ discard block |
||
| 1549 | 1544 | "'NOT'", |
| 1550 | 1545 | [ |
| 1551 | 1546 | "'IN'", |
| 1552 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1547 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1548 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1554 | 1549 | ] |
| 1555 | 1550 | ]; |
| 1556 | 1551 | } |
@@ -1567,22 +1562,22 @@ discard block |
||
| 1567 | 1562 | $descr = $boucles[$idb]->descr; |
| 1568 | 1563 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1569 | 1564 | |
| 1570 | - $var = '$in' . $cpt++; |
|
| 1565 | + $var = '$in'.$cpt++; |
|
| 1571 | 1566 | $x = "\n\t$var = array();"; |
| 1572 | 1567 | foreach ($val as $k => $v) { |
| 1573 | 1568 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1574 | 1569 | // optimiser le traitement des constantes |
| 1575 | 1570 | if (is_numeric($r[2])) { |
| 1576 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1571 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1577 | 1572 | } else { |
| 1578 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1573 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1579 | 1574 | } |
| 1580 | 1575 | } else { |
| 1581 | 1576 | // Pour permettre de passer des tableaux de valeurs |
| 1582 | 1577 | // on repere l'utilisation brute de #ENV**{X}, |
| 1583 | 1578 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1584 | 1579 | // et on deballe mais en rajoutant l'anti XSS |
| 1585 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1580 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1586 | 1581 | } |
| 1587 | 1582 | } |
| 1588 | 1583 | |
@@ -1596,7 +1591,7 @@ discard block |
||
| 1596 | 1591 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1597 | 1592 | } |
| 1598 | 1593 | |
| 1599 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1594 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1600 | 1595 | } |
| 1601 | 1596 | |
| 1602 | 1597 | /** |
@@ -1669,7 +1664,7 @@ discard block |
||
| 1669 | 1664 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1670 | 1665 | } |
| 1671 | 1666 | // nous aider en mode debug. |
| 1672 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1667 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1673 | 1668 | $boucle->modificateur['id_'] = $champs; |
| 1674 | 1669 | |
| 1675 | 1670 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1921,8 +1916,8 @@ discard block |
||
| 1921 | 1916 | "'NOT'", |
| 1922 | 1917 | [ |
| 1923 | 1918 | "'IN'", |
| 1924 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1919 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1920 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1926 | 1921 | ] |
| 1927 | 1922 | ]; |
| 1928 | 1923 | } |
@@ -1933,7 +1928,7 @@ discard block |
||
| 1933 | 1928 | if ($crit->cond) { |
| 1934 | 1929 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1935 | 1930 | if ($col === 'date' or $col === 'date_redac') { |
| 1936 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1931 | + if ($pred === "\$Pile[0]['".$col."']") { |
|
| 1937 | 1932 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1938 | 1933 | } |
| 1939 | 1934 | } |
@@ -2096,7 +2091,7 @@ discard block |
||
| 2096 | 2091 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2097 | 2092 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2098 | 2093 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2099 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2094 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2100 | 2095 | } |
| 2101 | 2096 | // sinon expliciter les |
| 2102 | 2097 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2112,14 +2107,14 @@ discard block |
||
| 2112 | 2107 | ) { |
| 2113 | 2108 | $r = $r[1] |
| 2114 | 2109 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2115 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2110 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2116 | 2111 | $val[0] = "sql_quote($r)"; |
| 2117 | 2112 | } |
| 2118 | 2113 | elseif ( |
| 2119 | 2114 | strpos($val[0], '@@defaultcast@@') !== false |
| 2120 | 2115 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2121 | 2116 | ) { |
| 2122 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2117 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2123 | 2118 | } |
| 2124 | 2119 | } |
| 2125 | 2120 | |
@@ -2127,7 +2122,7 @@ discard block |
||
| 2127 | 2122 | strpos($val[0], '@@defaultcast@@') !== false |
| 2128 | 2123 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2129 | 2124 | ) { |
| 2130 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2125 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2131 | 2126 | } |
| 2132 | 2127 | |
| 2133 | 2128 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2143,7 +2138,7 @@ discard block |
||
| 2143 | 2138 | // inserer le nom de la table SQL devant le nom du champ |
| 2144 | 2139 | if ($table) { |
| 2145 | 2140 | if ($col[0] == '`') { |
| 2146 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2141 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2147 | 2142 | } else { |
| 2148 | 2143 | $arg = "$table.$col"; |
| 2149 | 2144 | } |
@@ -2277,9 +2272,9 @@ discard block |
||
| 2277 | 2272 | **/ |
| 2278 | 2273 | function primary_doublee($decompose, $table) { |
| 2279 | 2274 | $e1 = reset($decompose); |
| 2280 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2281 | 2276 | |
| 2282 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2277 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2283 | 2278 | } |
| 2284 | 2279 | |
| 2285 | 2280 | /** |
@@ -2318,7 +2313,7 @@ discard block |
||
| 2318 | 2313 | $checkarrivee |
| 2319 | 2314 | and is_string($checkarrivee) |
| 2320 | 2315 | and $a = table_objet($checkarrivee) |
| 2321 | - and in_array($a . '_liens', $joints) |
|
| 2316 | + and in_array($a.'_liens', $joints) |
|
| 2322 | 2317 | ) { |
| 2323 | 2318 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2324 | 2319 | return $res; |
@@ -2338,12 +2333,12 @@ discard block |
||
| 2338 | 2333 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2339 | 2334 | $joindre = false; |
| 2340 | 2335 | foreach ($cols as $col) { |
| 2341 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2336 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2342 | 2337 | if (trouver_champ($c, $boucle->where)) { |
| 2343 | 2338 | $joindre = true; |
| 2344 | 2339 | } else { |
| 2345 | 2340 | // mais ca peut etre dans le FIELD pour le Having |
| 2346 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2341 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2347 | 2342 | if (trouver_champ($c, $boucle->select)) { |
| 2348 | 2343 | $joindre = true; |
| 2349 | 2344 | } |
@@ -2389,7 +2384,7 @@ discard block |
||
| 2389 | 2384 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2390 | 2385 | |
| 2391 | 2386 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2392 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2387 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2393 | 2388 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2394 | 2389 | |
| 2395 | 2390 | if (!$intermediaire or !$arrivee) { |
@@ -2493,7 +2488,7 @@ discard block |
||
| 2493 | 2488 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2494 | 2489 | // un critere conditionnel sur date est traite a part |
| 2495 | 2490 | // car la date est mise d'office par SPIP, |
| 2496 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2491 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2497 | 2492 | } |
| 2498 | 2493 | |
| 2499 | 2494 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2525,7 +2520,7 @@ discard block |
||
| 2525 | 2520 | and (($p == "'") or ($p == '"')) |
| 2526 | 2521 | and $params[0][1]->type == 'champ' |
| 2527 | 2522 | ) { |
| 2528 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2523 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2529 | 2524 | } else { |
| 2530 | 2525 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2531 | 2526 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2541,7 +2536,7 @@ discard block |
||
| 2541 | 2536 | $fct = $args_sql = ''; |
| 2542 | 2537 | // fonction SQL ? |
| 2543 | 2538 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2544 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2539 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2545 | 2540 | $fct = $m[1]; |
| 2546 | 2541 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2547 | 2542 | $col = $a[1]; |
@@ -2628,7 +2623,7 @@ discard block |
||
| 2628 | 2623 | # Recherche de l'existence du champ date_xxxx, |
| 2629 | 2624 | # si oui choisir ce champ, sinon choisir xxxx |
| 2630 | 2625 | if (isset($table['field']["date$suite"])) { |
| 2631 | - $date_orig = 'date' . $suite; |
|
| 2626 | + $date_orig = 'date'.$suite; |
|
| 2632 | 2627 | } else { |
| 2633 | 2628 | $date_orig = substr($suite, 1); |
| 2634 | 2629 | } |
@@ -2648,12 +2643,12 @@ discard block |
||
| 2648 | 2643 | } |
| 2649 | 2644 | } |
| 2650 | 2645 | |
| 2651 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2646 | + $date_compare = "\"' . normaliser_date(". |
|
| 2647 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2653 | 2648 | ") . '\""; |
| 2654 | 2649 | |
| 2655 | 2650 | $col_vraie = $date_orig; |
| 2656 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2651 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2657 | 2652 | |
| 2658 | 2653 | switch ($col) { |
| 2659 | 2654 | case 'date': |
@@ -2673,26 +2668,26 @@ discard block |
||
| 2673 | 2668 | break; |
| 2674 | 2669 | case 'age': |
| 2675 | 2670 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2676 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2677 | 2672 | break; |
| 2678 | 2673 | case 'age_relatif': |
| 2679 | 2674 | $col = calculer_param_date($date_compare, $date_orig); |
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2681 | 2676 | break; |
| 2682 | 2677 | case 'jour_relatif': |
| 2683 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2679 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2685 | 2680 | break; |
| 2686 | 2681 | case 'mois_relatif': |
| 2687 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2688 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2689 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2683 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2684 | + ')-YEAR('.$date_orig.'))'; |
|
| 2685 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2691 | 2686 | break; |
| 2692 | 2687 | case 'annee_relatif': |
| 2693 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | - $date_orig . ')'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2688 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2689 | + $date_orig.')'; |
|
| 2690 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2696 | 2691 | break; |
| 2697 | 2692 | } |
| 2698 | 2693 | |
@@ -2753,10 +2748,10 @@ discard block |
||
| 2753 | 2748 | } |
| 2754 | 2749 | |
| 2755 | 2750 | $boucle->hash .= ' |
| 2756 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2751 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2757 | 2752 | |
| 2758 | 2753 | $boucle->hash .= ' |
| 2759 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2754 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2760 | 2755 | } |
| 2761 | 2756 | |
| 2762 | 2757 | /** |
@@ -2775,7 +2770,7 @@ discard block |
||
| 2775 | 2770 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2776 | 2771 | $boucle = &$boucles[$idb]; |
| 2777 | 2772 | $boucle->hash .= ' |
| 2778 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2773 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2779 | 2774 | } |
| 2780 | 2775 | |
| 2781 | 2776 | |
@@ -2794,7 +2789,7 @@ discard block |
||
| 2794 | 2789 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2795 | 2790 | foreach ($crit->param as $param) { |
| 2796 | 2791 | $boucle->hash .= ' |
| 2797 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2792 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2798 | 2793 | } |
| 2799 | 2794 | } |
| 2800 | 2795 | |
@@ -2813,14 +2808,14 @@ discard block |
||
| 2813 | 2808 | */ |
| 2814 | 2809 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2815 | 2810 | $boucle = &$boucles[$idb]; |
| 2816 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2811 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2817 | 2812 | foreach ($crit->param as $param) { |
| 2818 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2813 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2819 | 2814 | $param, |
| 2820 | 2815 | $idb, |
| 2821 | 2816 | $boucles, |
| 2822 | 2817 | $boucles[$idb]->id_parent |
| 2823 | - ) . ";\n"; |
|
| 2818 | + ).";\n"; |
|
| 2824 | 2819 | } |
| 2825 | 2820 | } |
| 2826 | 2821 | |
@@ -2847,14 +2842,14 @@ discard block |
||
| 2847 | 2842 | */ |
| 2848 | 2843 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2849 | 2844 | $boucle = &$boucles[$idb]; |
| 2850 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2845 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2851 | 2846 | foreach ($crit->param as $param) { |
| 2852 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2847 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2853 | 2848 | $param, |
| 2854 | 2849 | $idb, |
| 2855 | 2850 | $boucles, |
| 2856 | 2851 | $boucles[$idb]->id_parent |
| 2857 | - ) . ";\n"; |
|
| 2852 | + ).";\n"; |
|
| 2858 | 2853 | } |
| 2859 | 2854 | } |
| 2860 | 2855 | |
@@ -2873,7 +2868,7 @@ discard block |
||
| 2873 | 2868 | $boucle = &$boucles[$idb]; |
| 2874 | 2869 | foreach ($crit->param as $param) { |
| 2875 | 2870 | $boucle->hash .= ' |
| 2876 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2871 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2877 | 2872 | } |
| 2878 | 2873 | } |
| 2879 | 2874 | |
@@ -2914,7 +2909,7 @@ discard block |
||
| 2914 | 2909 | if ($crit->param) { |
| 2915 | 2910 | foreach ($crit->param as $param) { |
| 2916 | 2911 | $boucle->hash .= "\t\$command['si'][] = " |
| 2917 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2912 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2918 | 2913 | } |
| 2919 | 2914 | // interdire {si 0} aussi ! |
| 2920 | 2915 | } else { |
@@ -2938,7 +2933,7 @@ discard block |
||
| 2938 | 2933 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2939 | 2934 | $boucle = &$boucles[$idb]; |
| 2940 | 2935 | $boucle->hash .= ' |
| 2941 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2936 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2942 | 2937 | $command[\'sourcemode\'] = \'table\';'; |
| 2943 | 2938 | } |
| 2944 | 2939 | |
@@ -2973,7 +2968,7 @@ discard block |
||
| 2973 | 2968 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2974 | 2969 | |
| 2975 | 2970 | $in = 'IN'; |
| 2976 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2971 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | 2972 | if ($not) { |
| 2978 | 2973 | $where = ["'NOT'", $where]; |
| 2979 | 2974 | } |
@@ -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 | /** |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | **/ |
| 47 | 47 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 48 | 48 | |
| 49 | - $not = $crit->not; |
|
| 50 | - $boucle = &$boucles[$idb]; |
|
| 51 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | + $not = $crit->not; |
|
| 50 | + $boucle = &$boucles[$idb]; |
|
| 51 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 52 | 52 | |
| 53 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 53 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * @return void|array |
| 69 | 69 | **/ |
| 70 | 70 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 71 | - $not = $crit->not; |
|
| 72 | - $boucle = &$boucles[$idb]; |
|
| 73 | - $id = $boucle->primary; |
|
| 74 | - |
|
| 75 | - if ($not or !$id) { |
|
| 76 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | - } |
|
| 78 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 71 | + $not = $crit->not; |
|
| 72 | + $boucle = &$boucles[$idb]; |
|
| 73 | + $id = $boucle->primary; |
|
| 74 | + |
|
| 75 | + if ($not or !$id) { |
|
| 76 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | + } |
|
| 78 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -96,73 +96,73 @@ discard block |
||
| 96 | 96 | * @return void|array |
| 97 | 97 | **/ |
| 98 | 98 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 99 | - $boucle = &$boucles[$idb]; |
|
| 100 | - $primary = $boucle->primary; |
|
| 101 | - |
|
| 102 | - // la table nécessite une clé primaire, non composée |
|
| 103 | - if (!$primary or strpos($primary, ',')) { |
|
| 104 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | - |
|
| 109 | - // le doublon s'applique sur un type de boucle (article) |
|
| 110 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | - |
|
| 112 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | - // on obtient $nom = "'article' . 'nom'" |
|
| 114 | - if (isset($crit->param[0])) { |
|
| 115 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | - |
|
| 122 | - // on crée un sql_in avec la clé primaire de la table |
|
| 123 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | - // $doublons et son index, ici $nom |
|
| 125 | - |
|
| 126 | - // debut du code "sql_in('articles.id_article', " |
|
| 127 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 131 | - |
|
| 132 | - // le debut complet du code des doublons |
|
| 133 | - $debut_doub = $debut_in . $debut_doub; |
|
| 134 | - |
|
| 135 | - // nom du doublon "('article' . 'nom')]" |
|
| 136 | - $fin_doub = "($nom)]"; |
|
| 137 | - |
|
| 138 | - // si on trouve un autre critère doublon, |
|
| 139 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | - foreach ($boucle->where as $k => $w) { |
|
| 141 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 142 | - // fusionner le sql_in (du where) |
|
| 143 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 144 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | - $x = strpos($boucle->hash, $init_comment); |
|
| 146 | - $len = strlen($init_comment); |
|
| 147 | - $boucle->hash = |
|
| 148 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 149 | - |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | - |
|
| 157 | - // déclarer le doublon s'il n'existe pas encore |
|
| 158 | - $boucle->hash .= $init_comment . $init_code; |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | - # {!doublons A}{doublons B} |
|
| 164 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 99 | + $boucle = &$boucles[$idb]; |
|
| 100 | + $primary = $boucle->primary; |
|
| 101 | + |
|
| 102 | + // la table nécessite une clé primaire, non composée |
|
| 103 | + if (!$primary or strpos($primary, ',')) { |
|
| 104 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | + |
|
| 109 | + // le doublon s'applique sur un type de boucle (article) |
|
| 110 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | + |
|
| 112 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | + // on obtient $nom = "'article' . 'nom'" |
|
| 114 | + if (isset($crit->param[0])) { |
|
| 115 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | + |
|
| 122 | + // on crée un sql_in avec la clé primaire de la table |
|
| 123 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | + // $doublons et son index, ici $nom |
|
| 125 | + |
|
| 126 | + // debut du code "sql_in('articles.id_article', " |
|
| 127 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 131 | + |
|
| 132 | + // le debut complet du code des doublons |
|
| 133 | + $debut_doub = $debut_in . $debut_doub; |
|
| 134 | + |
|
| 135 | + // nom du doublon "('article' . 'nom')]" |
|
| 136 | + $fin_doub = "($nom)]"; |
|
| 137 | + |
|
| 138 | + // si on trouve un autre critère doublon, |
|
| 139 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | + foreach ($boucle->where as $k => $w) { |
|
| 141 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 142 | + // fusionner le sql_in (du where) |
|
| 143 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 144 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | + $x = strpos($boucle->hash, $init_comment); |
|
| 146 | + $len = strlen($init_comment); |
|
| 147 | + $boucle->hash = |
|
| 148 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 149 | + |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | + |
|
| 157 | + // déclarer le doublon s'il n'existe pas encore |
|
| 158 | + $boucle->hash .= $init_comment . $init_code; |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | + # {!doublons A}{doublons B} |
|
| 164 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | * @return void |
| 184 | 184 | **/ |
| 185 | 185 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 186 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 187 | - $param = 'oui'; |
|
| 188 | - } |
|
| 189 | - if ($crit->not) { |
|
| 190 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | - } |
|
| 192 | - $boucle = &$boucles[$idb]; |
|
| 193 | - $boucle->lang_select = $param; |
|
| 186 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 187 | + $param = 'oui'; |
|
| 188 | + } |
|
| 189 | + if ($crit->not) { |
|
| 190 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | + } |
|
| 192 | + $boucle = &$boucles[$idb]; |
|
| 193 | + $boucle->lang_select = $param; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | **/ |
| 214 | 214 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 215 | - [$un, $deux] = $crit->param; |
|
| 216 | - $un = $un[0]->texte; |
|
| 217 | - $deux = $deux[0]->texte; |
|
| 218 | - if ($deux) { |
|
| 219 | - $boucles[$idb]->limit = |
|
| 220 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | - } else { |
|
| 222 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | - } |
|
| 215 | + [$un, $deux] = $crit->param; |
|
| 216 | + $un = $un[0]->texte; |
|
| 217 | + $deux = $deux[0]->texte; |
|
| 218 | + if ($deux) { |
|
| 219 | + $boucles[$idb]->limit = |
|
| 220 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | + } else { |
|
| 222 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | + } |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -254,58 +254,58 @@ discard block |
||
| 254 | 254 | **/ |
| 255 | 255 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 256 | 256 | |
| 257 | - $boucle = &$boucles[$idb]; |
|
| 258 | - // definition de la taille de la page |
|
| 259 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 260 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 261 | - |
|
| 262 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 263 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 264 | - } else { |
|
| 265 | - $r = intval($r[2]); |
|
| 266 | - $pas = strval($r ?: 10); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Calcul du nommage de la pagination si il existe. |
|
| 270 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 271 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 272 | - $type = "'$idb'"; |
|
| 273 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 274 | - // Syntaxe {pagination 20, nom} |
|
| 275 | - if (isset($crit->param[0][1])) { |
|
| 276 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 278 | - elseif (isset($crit->param[1][0])) { |
|
| 279 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 284 | - $partie = |
|
| 285 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 286 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 288 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 289 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 290 | - . "\t}\n" |
|
| 291 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | - |
|
| 293 | - $boucle->hash .= ' |
|
| 257 | + $boucle = &$boucles[$idb]; |
|
| 258 | + // definition de la taille de la page |
|
| 259 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 260 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 261 | + |
|
| 262 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 263 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 264 | + } else { |
|
| 265 | + $r = intval($r[2]); |
|
| 266 | + $pas = strval($r ?: 10); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Calcul du nommage de la pagination si il existe. |
|
| 270 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 271 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 272 | + $type = "'$idb'"; |
|
| 273 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 274 | + // Syntaxe {pagination 20, nom} |
|
| 275 | + if (isset($crit->param[0][1])) { |
|
| 276 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 278 | + elseif (isset($crit->param[1][0])) { |
|
| 279 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 284 | + $partie = |
|
| 285 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 286 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 288 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 289 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 290 | + . "\t}\n" |
|
| 291 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + |
|
| 293 | + $boucle->hash .= ' |
|
| 294 | 294 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 295 | 295 | |
| 296 | - $boucle->total_parties = $pas; |
|
| 297 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 298 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 299 | - // sauf si pas de primaire, ou si primaire composee |
|
| 300 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 301 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | - if ( |
|
| 303 | - $boucle->primary |
|
| 304 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 305 | - and !in_array($t, $boucle->select) |
|
| 306 | - ) { |
|
| 307 | - $boucle->select[] = $t; |
|
| 308 | - } |
|
| 296 | + $boucle->total_parties = $pas; |
|
| 297 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 298 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 299 | + // sauf si pas de primaire, ou si primaire composee |
|
| 300 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 301 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + if ( |
|
| 303 | + $boucle->primary |
|
| 304 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 305 | + and !in_array($t, $boucle->select) |
|
| 306 | + ) { |
|
| 307 | + $boucle->select[] = $t; |
|
| 308 | + } |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -327,24 +327,24 @@ discard block |
||
| 327 | 327 | **/ |
| 328 | 328 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 329 | 329 | |
| 330 | - $boucle = &$boucles[$idb]; |
|
| 330 | + $boucle = &$boucles[$idb]; |
|
| 331 | 331 | |
| 332 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 333 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 332 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 333 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 334 | 334 | |
| 335 | - return; |
|
| 336 | - } |
|
| 335 | + return; |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - if (isset($crit->param[0])) { |
|
| 339 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 340 | - } else { |
|
| 341 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 342 | - } |
|
| 338 | + if (isset($crit->param[0])) { |
|
| 339 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 340 | + } else { |
|
| 341 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 345 | - $boucle->hash .= ' |
|
| 344 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 345 | + $boucle->hash .= ' |
|
| 346 | 346 | // RECHERCHE' |
| 347 | - . ($crit->cond ? ' |
|
| 347 | + . ($crit->cond ? ' |
|
| 348 | 348 | if (!strlen(' . $quoi . ')){ |
| 349 | 349 | list($rech_select, $rech_where) = array("0 as points",""); |
| 350 | 350 | } else' : '') . ' |
@@ -355,21 +355,21 @@ discard block |
||
| 355 | 355 | '; |
| 356 | 356 | |
| 357 | 357 | |
| 358 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 359 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 360 | - $boucle->select[] = $t; |
|
| 361 | - } # pour postgres, neuneu ici |
|
| 362 | - // jointure uniquement sur le serveur principal |
|
| 363 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 364 | - if (!$boucle->sql_serveur) { |
|
| 365 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 366 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 367 | - } |
|
| 368 | - $boucle->select[] = '$rech_select'; |
|
| 369 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 370 | - |
|
| 371 | - // et la recherche trouve |
|
| 372 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 358 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 359 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 360 | + $boucle->select[] = $t; |
|
| 361 | + } # pour postgres, neuneu ici |
|
| 362 | + // jointure uniquement sur le serveur principal |
|
| 363 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 364 | + if (!$boucle->sql_serveur) { |
|
| 365 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 366 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 367 | + } |
|
| 368 | + $boucle->select[] = '$rech_select'; |
|
| 369 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 370 | + |
|
| 371 | + // et la recherche trouve |
|
| 372 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -386,25 +386,25 @@ discard block |
||
| 386 | 386 | * @return void |
| 387 | 387 | **/ |
| 388 | 388 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 389 | - $boucle = &$boucles[$idb]; |
|
| 390 | - $prim = $boucle->primary; |
|
| 391 | - $table = $boucle->id_table; |
|
| 392 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 393 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 394 | - $boucle->where[] = |
|
| 395 | - [ |
|
| 396 | - "'OR'", |
|
| 397 | - [ |
|
| 398 | - "'AND'", |
|
| 399 | - ["'='", "'$table.id_trad'", 0], |
|
| 400 | - ["'='", "'$table.$prim'", $dprim] |
|
| 401 | - ], |
|
| 402 | - [ |
|
| 403 | - "'AND'", |
|
| 404 | - ["'>'", "'$table.id_trad'", 0], |
|
| 405 | - ["'='", "'$table.id_trad'", $arg] |
|
| 406 | - ] |
|
| 407 | - ]; |
|
| 389 | + $boucle = &$boucles[$idb]; |
|
| 390 | + $prim = $boucle->primary; |
|
| 391 | + $table = $boucle->id_table; |
|
| 392 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 393 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 394 | + $boucle->where[] = |
|
| 395 | + [ |
|
| 396 | + "'OR'", |
|
| 397 | + [ |
|
| 398 | + "'AND'", |
|
| 399 | + ["'='", "'$table.id_trad'", 0], |
|
| 400 | + ["'='", "'$table.$prim'", $dprim] |
|
| 401 | + ], |
|
| 402 | + [ |
|
| 403 | + "'AND'", |
|
| 404 | + ["'>'", "'$table.id_trad'", 0], |
|
| 405 | + ["'='", "'$table.id_trad'", $arg] |
|
| 406 | + ] |
|
| 407 | + ]; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
@@ -422,17 +422,17 @@ discard block |
||
| 422 | 422 | * @return void |
| 423 | 423 | **/ |
| 424 | 424 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 425 | - $boucle = &$boucles[$idb]; |
|
| 426 | - $prim = $boucle->primary; |
|
| 427 | - $table = $boucle->id_table; |
|
| 428 | - |
|
| 429 | - $c = |
|
| 430 | - [ |
|
| 431 | - "'OR'", |
|
| 432 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 433 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 434 | - ]; |
|
| 435 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 425 | + $boucle = &$boucles[$idb]; |
|
| 426 | + $prim = $boucle->primary; |
|
| 427 | + $table = $boucle->id_table; |
|
| 428 | + |
|
| 429 | + $c = |
|
| 430 | + [ |
|
| 431 | + "'OR'", |
|
| 432 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 433 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 434 | + ]; |
|
| 435 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | **/ |
| 450 | 450 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 451 | 451 | |
| 452 | - $boucle = &$boucles[$idb]; |
|
| 453 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 454 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 455 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 456 | - |
|
| 457 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 458 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 459 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 460 | - else { |
|
| 461 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 462 | - } |
|
| 452 | + $boucle = &$boucles[$idb]; |
|
| 453 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 454 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 455 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 456 | + |
|
| 457 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 458 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 459 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 460 | + else { |
|
| 461 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 462 | + } |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | |
@@ -490,37 +490,37 @@ discard block |
||
| 490 | 490 | **/ |
| 491 | 491 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 492 | 492 | |
| 493 | - $not = $crit->not; |
|
| 494 | - $boucle = &$boucles[$idb]; |
|
| 495 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 496 | - if (isset($crit->param[0])) { |
|
| 497 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 498 | - // sinon on le prend chez une boucle parente |
|
| 499 | - } else { |
|
| 500 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - //Trouver une jointure |
|
| 504 | - $champ = 'id_rubrique'; |
|
| 505 | - $desc = $boucle->show; |
|
| 506 | - //Seulement si necessaire |
|
| 507 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 508 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 509 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 510 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 511 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 512 | - $decompose = decompose_champ_id_objet($champ); |
|
| 513 | - $champ = array_shift($decompose); |
|
| 514 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 515 | - } |
|
| 516 | - } else { |
|
| 517 | - $cle = $boucle->id_table; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 521 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 522 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 523 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 493 | + $not = $crit->not; |
|
| 494 | + $boucle = &$boucles[$idb]; |
|
| 495 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 496 | + if (isset($crit->param[0])) { |
|
| 497 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 498 | + // sinon on le prend chez une boucle parente |
|
| 499 | + } else { |
|
| 500 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + //Trouver une jointure |
|
| 504 | + $champ = 'id_rubrique'; |
|
| 505 | + $desc = $boucle->show; |
|
| 506 | + //Seulement si necessaire |
|
| 507 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 508 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 509 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 510 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 511 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 512 | + $decompose = decompose_champ_id_objet($champ); |
|
| 513 | + $champ = array_shift($decompose); |
|
| 514 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 515 | + } |
|
| 516 | + } else { |
|
| 517 | + $cle = $boucle->id_table; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 521 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 522 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 523 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -536,15 +536,15 @@ discard block |
||
| 536 | 536 | **/ |
| 537 | 537 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 538 | 538 | |
| 539 | - $boucle = &$boucles[$idb]; |
|
| 540 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 541 | - $serveur = $boucle->sql_serveur; |
|
| 539 | + $boucle = &$boucles[$idb]; |
|
| 540 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 541 | + $serveur = $boucle->sql_serveur; |
|
| 542 | 542 | |
| 543 | - $c = "sql_in('" . |
|
| 544 | - $boucle->id_table . '.' . $boucle->primary |
|
| 545 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | + $c = "sql_in('" . |
|
| 544 | + $boucle->id_table . '.' . $boucle->primary |
|
| 545 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 546 | 546 | |
| 547 | - $boucle->where[] = $c; |
|
| 547 | + $boucle->where[] = $c; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -566,31 +566,31 @@ discard block |
||
| 566 | 566 | * @return void|array |
| 567 | 567 | **/ |
| 568 | 568 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 569 | - if ($t = isset($crit->param[0])) { |
|
| 570 | - $t = $crit->param[0]; |
|
| 571 | - if ($t[0]->type == 'texte') { |
|
| 572 | - $t = $t[0]->texte; |
|
| 573 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 574 | - $t = table_objet_sql($r[1]); |
|
| 575 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 576 | - if ($t) { |
|
| 577 | - $t .= '.' . $r[2]; |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - } else { |
|
| 581 | - $t = '".' |
|
| 582 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 583 | - . '."'; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if ($t) { |
|
| 587 | - $boucles[$idb]->group[] = $t; |
|
| 588 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 589 | - $boucles[$idb]->select[] = $t; |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 593 | - } |
|
| 569 | + if ($t = isset($crit->param[0])) { |
|
| 570 | + $t = $crit->param[0]; |
|
| 571 | + if ($t[0]->type == 'texte') { |
|
| 572 | + $t = $t[0]->texte; |
|
| 573 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 574 | + $t = table_objet_sql($r[1]); |
|
| 575 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 576 | + if ($t) { |
|
| 577 | + $t .= '.' . $r[2]; |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + } else { |
|
| 581 | + $t = '".' |
|
| 582 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 583 | + . '."'; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if ($t) { |
|
| 587 | + $boucles[$idb]->group[] = $t; |
|
| 588 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 589 | + $boucles[$idb]->select[] = $t; |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 593 | + } |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @return void |
| 611 | 611 | **/ |
| 612 | 612 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 613 | - $boucles[$idb]->group = []; |
|
| 613 | + $boucles[$idb]->group = []; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -647,44 +647,44 @@ discard block |
||
| 647 | 647 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 648 | 648 | */ |
| 649 | 649 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 650 | - if (isset($crit->param[0])) { |
|
| 651 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 652 | - $boucle = $boucles[$idb]; |
|
| 653 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 654 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 655 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 656 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 657 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 658 | - if ( |
|
| 659 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 660 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 661 | - ) { |
|
| 662 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 663 | - } else { |
|
| 664 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 669 | - } |
|
| 650 | + if (isset($crit->param[0])) { |
|
| 651 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 652 | + $boucle = $boucles[$idb]; |
|
| 653 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 654 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 655 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 656 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 657 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 658 | + if ( |
|
| 659 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 660 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 661 | + ) { |
|
| 662 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 663 | + } else { |
|
| 664 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 669 | + } |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 673 | - $boucle = $boucles[$idb]; |
|
| 674 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 675 | - $var = '$champs_' . $idb; |
|
| 676 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 677 | - if (!$desc) { |
|
| 678 | - $desc = $boucle->show['field']; |
|
| 679 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 680 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 681 | - } |
|
| 682 | - if ($desc) { |
|
| 683 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 684 | - } |
|
| 685 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 686 | - |
|
| 687 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | + $boucle = $boucles[$idb]; |
|
| 674 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 675 | + $var = '$champs_' . $idb; |
|
| 676 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 677 | + if (!$desc) { |
|
| 678 | + $desc = $boucle->show['field']; |
|
| 679 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 680 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 681 | + } |
|
| 682 | + if ($desc) { |
|
| 683 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 684 | + } |
|
| 685 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 686 | + |
|
| 687 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | /** |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 724 | 724 | */ |
| 725 | 725 | function critere_par_dist($idb, &$boucles, $crit) { |
| 726 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 726 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** |
@@ -745,93 +745,93 @@ discard block |
||
| 745 | 745 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 746 | 746 | */ |
| 747 | 747 | function critere_parinverse($idb, &$boucles, $crit) { |
| 748 | - $boucle = &$boucles[$idb]; |
|
| 749 | - |
|
| 750 | - $sens = $collecte = ''; |
|
| 751 | - if ($crit->not) { |
|
| 752 | - $sens = " . ' DESC'"; |
|
| 753 | - } |
|
| 754 | - if (isset($boucle->modificateur['collate'])) { |
|
| 755 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // Pour chaque paramètre du critère |
|
| 759 | - foreach ($crit->param as $tri) { |
|
| 760 | - $order = $fct = ''; |
|
| 761 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 762 | - if ($tri[0]->type != 'texte') { |
|
| 763 | - // calculer le order dynamique qui verifie les champs |
|
| 764 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 765 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 766 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 767 | - } |
|
| 768 | - // tris textuels {par titre} |
|
| 769 | - else { |
|
| 770 | - $par = array_shift($tri); |
|
| 771 | - $par = $par->texte; |
|
| 772 | - |
|
| 773 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 774 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 775 | - $expression = trim($m[1]); |
|
| 776 | - $champ = trim($m[2]); |
|
| 777 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 778 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 779 | - } else { |
|
| 780 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 784 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 785 | - // {par FONCTION(champ)} |
|
| 786 | - if (isset($match) and count($match) > 2) { |
|
| 787 | - $par = substr($match[2], 1, -1); |
|
| 788 | - $fct = $match[1]; |
|
| 789 | - } |
|
| 790 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 791 | - if ($par == 'hasard') { |
|
| 792 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 793 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 794 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 795 | - } else { |
|
| 796 | - // cas général {par champ}, {par table.champ}, ... |
|
| 797 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - // on ne sait pas traiter… |
|
| 802 | - else { |
|
| 803 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 807 | - if (is_array($order)) { |
|
| 808 | - return $order; |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 813 | - $t = $m[1]; |
|
| 814 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 815 | - $boucle->select[] = $t; |
|
| 816 | - } |
|
| 817 | - } else { |
|
| 818 | - $sens = ''; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - if ($fct) { |
|
| 822 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 823 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 824 | - } else { |
|
| 825 | - $order = "'$fct(' . $order . ')'"; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - $t = $order . $collecte . $sens; |
|
| 829 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 830 | - $t = $r[1] . $r[2]; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - $boucle->order[] = $t; |
|
| 834 | - } |
|
| 748 | + $boucle = &$boucles[$idb]; |
|
| 749 | + |
|
| 750 | + $sens = $collecte = ''; |
|
| 751 | + if ($crit->not) { |
|
| 752 | + $sens = " . ' DESC'"; |
|
| 753 | + } |
|
| 754 | + if (isset($boucle->modificateur['collate'])) { |
|
| 755 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // Pour chaque paramètre du critère |
|
| 759 | + foreach ($crit->param as $tri) { |
|
| 760 | + $order = $fct = ''; |
|
| 761 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 762 | + if ($tri[0]->type != 'texte') { |
|
| 763 | + // calculer le order dynamique qui verifie les champs |
|
| 764 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 765 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 766 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 767 | + } |
|
| 768 | + // tris textuels {par titre} |
|
| 769 | + else { |
|
| 770 | + $par = array_shift($tri); |
|
| 771 | + $par = $par->texte; |
|
| 772 | + |
|
| 773 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 774 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 775 | + $expression = trim($m[1]); |
|
| 776 | + $champ = trim($m[2]); |
|
| 777 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 778 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 779 | + } else { |
|
| 780 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 784 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 785 | + // {par FONCTION(champ)} |
|
| 786 | + if (isset($match) and count($match) > 2) { |
|
| 787 | + $par = substr($match[2], 1, -1); |
|
| 788 | + $fct = $match[1]; |
|
| 789 | + } |
|
| 790 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 791 | + if ($par == 'hasard') { |
|
| 792 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 793 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 794 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 795 | + } else { |
|
| 796 | + // cas général {par champ}, {par table.champ}, ... |
|
| 797 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + // on ne sait pas traiter… |
|
| 802 | + else { |
|
| 803 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 807 | + if (is_array($order)) { |
|
| 808 | + return $order; |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 813 | + $t = $m[1]; |
|
| 814 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 815 | + $boucle->select[] = $t; |
|
| 816 | + } |
|
| 817 | + } else { |
|
| 818 | + $sens = ''; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + if ($fct) { |
|
| 822 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 823 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 824 | + } else { |
|
| 825 | + $order = "'$fct(' . $order . ')'"; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + $t = $order . $collecte . $sens; |
|
| 829 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 830 | + $t = $r[1] . $r[2]; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + $boucle->order[] = $t; |
|
| 834 | + } |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -845,13 +845,13 @@ discard block |
||
| 845 | 845 | * @return string Clause pour le Order by |
| 846 | 846 | */ |
| 847 | 847 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 848 | - $boucle = &$boucles[$idb]; |
|
| 849 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 850 | - $parha = 'rand() AS hasard'; |
|
| 851 | - if (!in_array($parha, $boucle->select)) { |
|
| 852 | - $boucle->select[] = $parha; |
|
| 853 | - } |
|
| 854 | - return "'hasard'"; |
|
| 848 | + $boucle = &$boucles[$idb]; |
|
| 849 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 850 | + $parha = 'rand() AS hasard'; |
|
| 851 | + if (!in_array($parha, $boucle->select)) { |
|
| 852 | + $boucle->select[] = $parha; |
|
| 853 | + } |
|
| 854 | + return "'hasard'"; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -875,24 +875,24 @@ discard block |
||
| 875 | 875 | * @return string|array Clause pour le Order by (array si erreur) |
| 876 | 876 | */ |
| 877 | 877 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 878 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 879 | - if (is_array($_champ)) { |
|
| 880 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 881 | - } |
|
| 882 | - $boucle = &$boucles[$idb]; |
|
| 883 | - $texte = '0+' . $_champ; |
|
| 884 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 885 | - if ($suite !== "''") { |
|
| 886 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 887 | - } |
|
| 888 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 890 | - |
|
| 891 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 892 | - $orderassinum = trim($orderassinum, "'"); |
|
| 893 | - |
|
| 894 | - $order = "'$orderassinum, $asnum'"; |
|
| 895 | - return $order; |
|
| 878 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 879 | + if (is_array($_champ)) { |
|
| 880 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 881 | + } |
|
| 882 | + $boucle = &$boucles[$idb]; |
|
| 883 | + $texte = '0+' . $_champ; |
|
| 884 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 885 | + if ($suite !== "''") { |
|
| 886 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 887 | + } |
|
| 888 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 890 | + |
|
| 891 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 892 | + $orderassinum = trim($orderassinum, "'"); |
|
| 893 | + |
|
| 894 | + $order = "'$orderassinum, $asnum'"; |
|
| 895 | + return $order; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -913,35 +913,35 @@ discard block |
||
| 913 | 913 | * @return string|array Clause pour le Order by (array si erreur) |
| 914 | 914 | */ |
| 915 | 915 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 916 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 917 | - if (is_array($_champ)) { |
|
| 918 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 919 | - } |
|
| 920 | - $boucle = &$boucles[$idb]; |
|
| 921 | - $texte = '0+' . $_champ; |
|
| 922 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 923 | - if ($suite !== "''") { |
|
| 924 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - $as = false; |
|
| 928 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 929 | - foreach ($boucle->select as $s) { |
|
| 930 | - if (strpos($s, $select) === 0) { |
|
| 931 | - $as = trim(substr($s, strlen($select))); |
|
| 932 | - if (!preg_match(',\W,', $as)) { |
|
| 933 | - break; |
|
| 934 | - } |
|
| 935 | - $as = false; |
|
| 936 | - } |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - if (!$as) { |
|
| 940 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 941 | - $boucle->select[] = $select . $as; |
|
| 942 | - } |
|
| 943 | - $order = "'$as'"; |
|
| 944 | - return $order; |
|
| 916 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 917 | + if (is_array($_champ)) { |
|
| 918 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 919 | + } |
|
| 920 | + $boucle = &$boucles[$idb]; |
|
| 921 | + $texte = '0+' . $_champ; |
|
| 922 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 923 | + if ($suite !== "''") { |
|
| 924 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + $as = false; |
|
| 928 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 929 | + foreach ($boucle->select as $s) { |
|
| 930 | + if (strpos($s, $select) === 0) { |
|
| 931 | + $as = trim(substr($s, strlen($select))); |
|
| 932 | + if (!preg_match(',\W,', $as)) { |
|
| 933 | + break; |
|
| 934 | + } |
|
| 935 | + $as = false; |
|
| 936 | + } |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + if (!$as) { |
|
| 940 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 941 | + $boucle->select[] = $select . $as; |
|
| 942 | + } |
|
| 943 | + $order = "'$as'"; |
|
| 944 | + return $order; |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | |
@@ -961,14 +961,14 @@ discard block |
||
| 961 | 961 | * @return string|array Clause pour le Order by (array si erreur) |
| 962 | 962 | */ |
| 963 | 963 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 964 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 965 | - if (is_array($_champ)) { |
|
| 966 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 967 | - } |
|
| 968 | - $boucle = &$boucles[$idb]; |
|
| 969 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 970 | - $order = "'multi'"; |
|
| 971 | - return $order; |
|
| 964 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 965 | + if (is_array($_champ)) { |
|
| 966 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 967 | + } |
|
| 968 | + $boucle = &$boucles[$idb]; |
|
| 969 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 970 | + $order = "'multi'"; |
|
| 971 | + return $order; |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | /** |
@@ -987,56 +987,56 @@ discard block |
||
| 987 | 987 | * @return array|string |
| 988 | 988 | */ |
| 989 | 989 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 990 | - $boucle = &$boucles[$idb]; |
|
| 991 | - $desc = $boucle->show; |
|
| 992 | - |
|
| 993 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 994 | - if (isset($desc['field'][$par])) { |
|
| 995 | - $par = $boucle->id_table . '.' . $par; |
|
| 996 | - } |
|
| 997 | - // le champ est peut être une jointure |
|
| 998 | - else { |
|
| 999 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1000 | - $champ = $par; |
|
| 1001 | - |
|
| 1002 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1003 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1004 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1005 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1006 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1007 | - [, $table, $champ] = $r; |
|
| 1008 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1009 | - $table = table_objet_sql($table); |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1013 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1014 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1015 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1016 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1017 | - } elseif ( |
|
| 1018 | - $boucle->jointures_explicites |
|
| 1019 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1020 | - ) { |
|
| 1021 | - $par = $alias . '.' . $champ; |
|
| 1022 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1023 | - $par = $alias . '.' . $champ; |
|
| 1024 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1025 | - } elseif ( |
|
| 1026 | - $table_alias |
|
| 1027 | - and isset($boucle->from[$table_alias]) |
|
| 1028 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1029 | - ) { |
|
| 1030 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1031 | - } elseif ($table) { |
|
| 1032 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1033 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1034 | - } else { |
|
| 1035 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - return $raw ? $par : "'$par'"; |
|
| 990 | + $boucle = &$boucles[$idb]; |
|
| 991 | + $desc = $boucle->show; |
|
| 992 | + |
|
| 993 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 994 | + if (isset($desc['field'][$par])) { |
|
| 995 | + $par = $boucle->id_table . '.' . $par; |
|
| 996 | + } |
|
| 997 | + // le champ est peut être une jointure |
|
| 998 | + else { |
|
| 999 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1000 | + $champ = $par; |
|
| 1001 | + |
|
| 1002 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1003 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1004 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1005 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1006 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1007 | + [, $table, $champ] = $r; |
|
| 1008 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1009 | + $table = table_objet_sql($table); |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1013 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1014 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1015 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1016 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1017 | + } elseif ( |
|
| 1018 | + $boucle->jointures_explicites |
|
| 1019 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1020 | + ) { |
|
| 1021 | + $par = $alias . '.' . $champ; |
|
| 1022 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1023 | + $par = $alias . '.' . $champ; |
|
| 1024 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1025 | + } elseif ( |
|
| 1026 | + $table_alias |
|
| 1027 | + and isset($boucle->from[$table_alias]) |
|
| 1028 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1029 | + ) { |
|
| 1030 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1031 | + } elseif ($table) { |
|
| 1032 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1033 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1034 | + } else { |
|
| 1035 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1036 | + } |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + return $raw ? $par : "'$par'"; |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1050,11 +1050,11 @@ discard block |
||
| 1050 | 1050 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1051 | 1051 | */ |
| 1052 | 1052 | function critere_par_joint($table, $champ, &$boucle) { |
| 1053 | - $t = array_search($table, $boucle->from); |
|
| 1054 | - if (!$t) { |
|
| 1055 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1056 | - } |
|
| 1057 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1053 | + $t = array_search($table, $boucle->from); |
|
| 1054 | + if (!$t) { |
|
| 1055 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1056 | + } |
|
| 1057 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | /** |
@@ -1079,33 +1079,33 @@ discard block |
||
| 1079 | 1079 | */ |
| 1080 | 1080 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1081 | 1081 | |
| 1082 | - $boucle = &$boucles[$idb]; |
|
| 1083 | - // Classement par ordre inverse |
|
| 1084 | - if ($crit->not) { |
|
| 1085 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1086 | - } else { |
|
| 1087 | - $order = "' DESC'"; |
|
| 1088 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1089 | - if (isset($crit->param[0])) { |
|
| 1090 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1091 | - $order = "(($critere)?' DESC':'')"; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1095 | - if (!$n) { |
|
| 1096 | - if (isset($boucle->default_order[0])) { |
|
| 1097 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1098 | - } else { |
|
| 1099 | - $boucle->default_order[] = ' DESC'; |
|
| 1100 | - } |
|
| 1101 | - } else { |
|
| 1102 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1103 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1104 | - $t = $r[1] . $r[2]; |
|
| 1105 | - } |
|
| 1106 | - $boucle->order[$n - 1] = $t; |
|
| 1107 | - } |
|
| 1108 | - } |
|
| 1082 | + $boucle = &$boucles[$idb]; |
|
| 1083 | + // Classement par ordre inverse |
|
| 1084 | + if ($crit->not) { |
|
| 1085 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1086 | + } else { |
|
| 1087 | + $order = "' DESC'"; |
|
| 1088 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1089 | + if (isset($crit->param[0])) { |
|
| 1090 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1091 | + $order = "(($critere)?' DESC':'')"; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1095 | + if (!$n) { |
|
| 1096 | + if (isset($boucle->default_order[0])) { |
|
| 1097 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1098 | + } else { |
|
| 1099 | + $boucle->default_order[] = ' DESC'; |
|
| 1100 | + } |
|
| 1101 | + } else { |
|
| 1102 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1103 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1104 | + $t = $r[1] . $r[2]; |
|
| 1105 | + } |
|
| 1106 | + $boucle->order[$n - 1] = $t; |
|
| 1107 | + } |
|
| 1108 | + } |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | /** |
@@ -1117,139 +1117,139 @@ discard block |
||
| 1117 | 1117 | * @return void|array |
| 1118 | 1118 | */ |
| 1119 | 1119 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1120 | - $boucle = &$boucles[$idb]; |
|
| 1120 | + $boucle = &$boucles[$idb]; |
|
| 1121 | 1121 | |
| 1122 | - $sens = $collecte = ''; |
|
| 1123 | - if ($crit->not) { |
|
| 1124 | - $sens = " . ' DESC'"; |
|
| 1125 | - } |
|
| 1122 | + $sens = $collecte = ''; |
|
| 1123 | + if ($crit->not) { |
|
| 1124 | + $sens = " . ' DESC'"; |
|
| 1125 | + } |
|
| 1126 | 1126 | |
| 1127 | - $crit2 = clone $crit; |
|
| 1128 | - $crit2->not = false; |
|
| 1129 | - $crit2->param = [reset($crit->param)]; |
|
| 1130 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1127 | + $crit2 = clone $crit; |
|
| 1128 | + $crit2->not = false; |
|
| 1129 | + $crit2->param = [reset($crit->param)]; |
|
| 1130 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1131 | 1131 | |
| 1132 | - // erreur ? |
|
| 1133 | - if (is_array($res)) { |
|
| 1134 | - return $res; |
|
| 1135 | - } |
|
| 1132 | + // erreur ? |
|
| 1133 | + if (is_array($res)) { |
|
| 1134 | + return $res; |
|
| 1135 | + } |
|
| 1136 | 1136 | |
| 1137 | - $_order = array_pop($boucle->order); |
|
| 1137 | + $_order = array_pop($boucle->order); |
|
| 1138 | 1138 | |
| 1139 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1139 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1140 | 1140 | |
| 1141 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1142 | - $boucle->order[] = $order; |
|
| 1141 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1142 | + $boucle->order[] = $order; |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | |
| 1146 | 1146 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1147 | - $params = $crit->param; |
|
| 1148 | - |
|
| 1149 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1150 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - $boucle = &$boucles[$idb]; |
|
| 1154 | - $parent = $boucle->id_parent; |
|
| 1155 | - $fields = $boucle->show['field']; |
|
| 1156 | - |
|
| 1157 | - $date = array_shift($params); |
|
| 1158 | - $type = array_shift($params); |
|
| 1159 | - |
|
| 1160 | - // la valeur $type doit etre connue a la compilation |
|
| 1161 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1162 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1163 | - |
|
| 1164 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1165 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1166 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1167 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1168 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1169 | - $date = $date[0]->texte; |
|
| 1170 | - if (!isset($fields[$date])) { |
|
| 1171 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1172 | - } |
|
| 1173 | - } else { |
|
| 1174 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1175 | - $noms = array_keys($fields); |
|
| 1176 | - $defaut = $noms[0]; |
|
| 1177 | - $noms = join(' ', $noms); |
|
| 1178 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1179 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1180 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1181 | - } |
|
| 1182 | - $annee = $params ? array_shift($params) : ''; |
|
| 1183 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1184 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1185 | - ') ? $x : date("Y"))'; |
|
| 1186 | - |
|
| 1187 | - $mois = $params ? array_shift($params) : ''; |
|
| 1188 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1189 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1190 | - ') ? $x : date("m"))'; |
|
| 1191 | - |
|
| 1192 | - $jour = $params ? array_shift($params) : ''; |
|
| 1193 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1194 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1195 | - ') ? $x : date("d"))'; |
|
| 1196 | - |
|
| 1197 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1198 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1199 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1200 | - ') ? $x : date("Y"))'; |
|
| 1201 | - |
|
| 1202 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1203 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1204 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1205 | - ') ? $x : date("m"))'; |
|
| 1206 | - |
|
| 1207 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1208 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1209 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1210 | - ') ? $x : date("d"))'; |
|
| 1211 | - |
|
| 1212 | - $date = $boucle->id_table . ".$date"; |
|
| 1213 | - |
|
| 1214 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1215 | - if ($type == 'jour') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1219 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'mois') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'='", |
|
| 1224 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1225 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1226 | - ]; |
|
| 1227 | - } elseif ($type == 'semaine') { |
|
| 1228 | - $boucle->where[] = [ |
|
| 1229 | - "'AND'", |
|
| 1230 | - [ |
|
| 1231 | - "'>='", |
|
| 1232 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1233 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1234 | - ], |
|
| 1235 | - [ |
|
| 1236 | - "'<='", |
|
| 1237 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1238 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1239 | - ] |
|
| 1240 | - ]; |
|
| 1241 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1242 | - $boucle->where[] = [ |
|
| 1243 | - "'AND'", |
|
| 1244 | - [ |
|
| 1245 | - "'>='", |
|
| 1246 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | - ], |
|
| 1249 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1250 | - ]; |
|
| 1251 | - } |
|
| 1252 | - // sinon on prend tout |
|
| 1147 | + $params = $crit->param; |
|
| 1148 | + |
|
| 1149 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1150 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + $boucle = &$boucles[$idb]; |
|
| 1154 | + $parent = $boucle->id_parent; |
|
| 1155 | + $fields = $boucle->show['field']; |
|
| 1156 | + |
|
| 1157 | + $date = array_shift($params); |
|
| 1158 | + $type = array_shift($params); |
|
| 1159 | + |
|
| 1160 | + // la valeur $type doit etre connue a la compilation |
|
| 1161 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1162 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1163 | + |
|
| 1164 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1165 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1166 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1167 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1168 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1169 | + $date = $date[0]->texte; |
|
| 1170 | + if (!isset($fields[$date])) { |
|
| 1171 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1172 | + } |
|
| 1173 | + } else { |
|
| 1174 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1175 | + $noms = array_keys($fields); |
|
| 1176 | + $defaut = $noms[0]; |
|
| 1177 | + $noms = join(' ', $noms); |
|
| 1178 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1179 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1180 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1181 | + } |
|
| 1182 | + $annee = $params ? array_shift($params) : ''; |
|
| 1183 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1184 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1185 | + ') ? $x : date("Y"))'; |
|
| 1186 | + |
|
| 1187 | + $mois = $params ? array_shift($params) : ''; |
|
| 1188 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1189 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1190 | + ') ? $x : date("m"))'; |
|
| 1191 | + |
|
| 1192 | + $jour = $params ? array_shift($params) : ''; |
|
| 1193 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1194 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1195 | + ') ? $x : date("d"))'; |
|
| 1196 | + |
|
| 1197 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1198 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1199 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1200 | + ') ? $x : date("Y"))'; |
|
| 1201 | + |
|
| 1202 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1203 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1204 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1205 | + ') ? $x : date("m"))'; |
|
| 1206 | + |
|
| 1207 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1208 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1209 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1210 | + ') ? $x : date("d"))'; |
|
| 1211 | + |
|
| 1212 | + $date = $boucle->id_table . ".$date"; |
|
| 1213 | + |
|
| 1214 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1215 | + if ($type == 'jour') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1219 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'mois') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'='", |
|
| 1224 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1225 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1226 | + ]; |
|
| 1227 | + } elseif ($type == 'semaine') { |
|
| 1228 | + $boucle->where[] = [ |
|
| 1229 | + "'AND'", |
|
| 1230 | + [ |
|
| 1231 | + "'>='", |
|
| 1232 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1233 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1234 | + ], |
|
| 1235 | + [ |
|
| 1236 | + "'<='", |
|
| 1237 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1238 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1239 | + ] |
|
| 1240 | + ]; |
|
| 1241 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1242 | + $boucle->where[] = [ |
|
| 1243 | + "'AND'", |
|
| 1244 | + [ |
|
| 1245 | + "'>='", |
|
| 1246 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | + ], |
|
| 1249 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1250 | + ]; |
|
| 1251 | + } |
|
| 1252 | + // sinon on prend tout |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -1274,33 +1274,33 @@ discard block |
||
| 1274 | 1274 | * @return void |
| 1275 | 1275 | **/ |
| 1276 | 1276 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1277 | - $boucle = &$boucles[$idb]; |
|
| 1278 | - $a1 = $crit->param[0]; |
|
| 1279 | - $a2 = $crit->param[1]; |
|
| 1280 | - $op = $crit->op; |
|
| 1281 | - |
|
| 1282 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1283 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1284 | - |
|
| 1285 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1286 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1287 | - } else { |
|
| 1288 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1289 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1290 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1291 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1292 | - $mode = (($op == '/') ? '/' : |
|
| 1293 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1294 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1295 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1296 | - $boucle->limit = |
|
| 1297 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1298 | - . ".','." |
|
| 1299 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1300 | - } else { |
|
| 1301 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1277 | + $boucle = &$boucles[$idb]; |
|
| 1278 | + $a1 = $crit->param[0]; |
|
| 1279 | + $a2 = $crit->param[1]; |
|
| 1280 | + $op = $crit->op; |
|
| 1281 | + |
|
| 1282 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1283 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1284 | + |
|
| 1285 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1286 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1287 | + } else { |
|
| 1288 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1289 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1290 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1291 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1292 | + $mode = (($op == '/') ? '/' : |
|
| 1293 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1294 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1295 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1296 | + $boucle->limit = |
|
| 1297 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1298 | + . ".','." |
|
| 1299 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1300 | + } else { |
|
| 1301 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | /** |
@@ -1328,63 +1328,63 @@ discard block |
||
| 1328 | 1328 | * @return void |
| 1329 | 1329 | **/ |
| 1330 | 1330 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1331 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1332 | - |
|
| 1333 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1334 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1335 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1336 | - // {1/3} |
|
| 1337 | - if ($op1 == '/') { |
|
| 1338 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1339 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1340 | - "($total_parties ? $total_parties : 1)"; |
|
| 1341 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1342 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1343 | - } else { |
|
| 1344 | - // cas {n-1,x} |
|
| 1345 | - if ($op1 == '-') { |
|
| 1346 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - // cas {x,n-1} |
|
| 1350 | - if ($op2 == '-') { |
|
| 1351 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1352 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1353 | - ($total_parties . ' - 1')); |
|
| 1354 | - } else { |
|
| 1355 | - // {x,1} ou {pagination} |
|
| 1356 | - $fin = '$debut_boucle' |
|
| 1357 | - . (is_numeric($total_parties) ? |
|
| 1358 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1359 | - ('+' . $total_parties . ' - 1')); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1363 | - if ($op1 == 'p') { |
|
| 1364 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1365 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1366 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - // Notes : |
|
| 1371 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1372 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1373 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1374 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1375 | - |
|
| 1376 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1377 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1378 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1379 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1380 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1381 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1382 | - . "\n\tif (\$debut_boucle>0" |
|
| 1383 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1384 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1385 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1386 | - |
|
| 1387 | - $boucles[$id_boucle]->partie = " |
|
| 1331 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1332 | + |
|
| 1333 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1334 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1335 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1336 | + // {1/3} |
|
| 1337 | + if ($op1 == '/') { |
|
| 1338 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1339 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1340 | + "($total_parties ? $total_parties : 1)"; |
|
| 1341 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1342 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1343 | + } else { |
|
| 1344 | + // cas {n-1,x} |
|
| 1345 | + if ($op1 == '-') { |
|
| 1346 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + // cas {x,n-1} |
|
| 1350 | + if ($op2 == '-') { |
|
| 1351 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1352 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1353 | + ($total_parties . ' - 1')); |
|
| 1354 | + } else { |
|
| 1355 | + // {x,1} ou {pagination} |
|
| 1356 | + $fin = '$debut_boucle' |
|
| 1357 | + . (is_numeric($total_parties) ? |
|
| 1358 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1359 | + ('+' . $total_parties . ' - 1')); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1363 | + if ($op1 == 'p') { |
|
| 1364 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1365 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1366 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + // Notes : |
|
| 1371 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1372 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1373 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1374 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1375 | + |
|
| 1376 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1377 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1378 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1379 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1380 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1381 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1382 | + . "\n\tif (\$debut_boucle>0" |
|
| 1383 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1384 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1385 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1386 | + |
|
| 1387 | + $boucles[$id_boucle]->partie = " |
|
| 1388 | 1388 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1389 | 1389 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1390 | 1390 | } |
@@ -1401,26 +1401,26 @@ discard block |
||
| 1401 | 1401 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1402 | 1402 | **/ |
| 1403 | 1403 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1404 | - if ($param[0]->type != 'texte') { |
|
| 1405 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1406 | - if (isset($param[1]->texte)) { |
|
| 1407 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1408 | - |
|
| 1409 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1410 | - } else { |
|
| 1411 | - return ["intval($a1)", 0]; |
|
| 1412 | - } |
|
| 1413 | - } else { |
|
| 1414 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1415 | - $a1 = $m[1]; |
|
| 1416 | - if (empty($m[3])) { |
|
| 1417 | - return [$a1, 0]; |
|
| 1418 | - } elseif (!empty($m[4])) { |
|
| 1419 | - return [$a1, $m[4]]; |
|
| 1420 | - } else { |
|
| 1421 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1404 | + if ($param[0]->type != 'texte') { |
|
| 1405 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1406 | + if (isset($param[1]->texte)) { |
|
| 1407 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1408 | + |
|
| 1409 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1410 | + } else { |
|
| 1411 | + return ["intval($a1)", 0]; |
|
| 1412 | + } |
|
| 1413 | + } else { |
|
| 1414 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1415 | + $a1 = $m[1]; |
|
| 1416 | + if (empty($m[3])) { |
|
| 1417 | + return [$a1, 0]; |
|
| 1418 | + } elseif (!empty($m[4])) { |
|
| 1419 | + return [$a1, $m[4]]; |
|
| 1420 | + } else { |
|
| 1421 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | |
@@ -1447,47 +1447,47 @@ discard block |
||
| 1447 | 1447 | * array : Erreur sur un des critères |
| 1448 | 1448 | **/ |
| 1449 | 1449 | function calculer_criteres($idb, &$boucles) { |
| 1450 | - $msg = ''; |
|
| 1451 | - $boucle = $boucles[$idb]; |
|
| 1452 | - $table = strtoupper($boucle->type_requete); |
|
| 1453 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1454 | - |
|
| 1455 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1456 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1457 | - if (!is_array($boucle->criteres)) { |
|
| 1458 | - return []; |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - foreach ($boucle->criteres as $crit) { |
|
| 1462 | - $critere = $crit->op; |
|
| 1463 | - // critere personnalise ? |
|
| 1464 | - if ( |
|
| 1465 | - (!$serveur or |
|
| 1466 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) |
|
| 1471 | - ) |
|
| 1472 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1473 | - and (!function_exists($f = $f . '_dist')) |
|
| 1474 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1475 | - and (!function_exists($f = $f . '_dist')) |
|
| 1476 | - ) { |
|
| 1477 | - // fonction critere standard |
|
| 1478 | - $f = $defaut; |
|
| 1479 | - } |
|
| 1480 | - // compile le critere |
|
| 1481 | - $res = $f($idb, $boucles, $crit); |
|
| 1482 | - |
|
| 1483 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1484 | - if (is_array($res)) { |
|
| 1485 | - $msg = $res; |
|
| 1486 | - erreur_squelette($msg, $boucle); |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - return $msg; |
|
| 1450 | + $msg = ''; |
|
| 1451 | + $boucle = $boucles[$idb]; |
|
| 1452 | + $table = strtoupper($boucle->type_requete); |
|
| 1453 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1454 | + |
|
| 1455 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1456 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1457 | + if (!is_array($boucle->criteres)) { |
|
| 1458 | + return []; |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + foreach ($boucle->criteres as $crit) { |
|
| 1462 | + $critere = $crit->op; |
|
| 1463 | + // critere personnalise ? |
|
| 1464 | + if ( |
|
| 1465 | + (!$serveur or |
|
| 1466 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) |
|
| 1471 | + ) |
|
| 1472 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1473 | + and (!function_exists($f = $f . '_dist')) |
|
| 1474 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1475 | + and (!function_exists($f = $f . '_dist')) |
|
| 1476 | + ) { |
|
| 1477 | + // fonction critere standard |
|
| 1478 | + $f = $defaut; |
|
| 1479 | + } |
|
| 1480 | + // compile le critere |
|
| 1481 | + $res = $f($idb, $boucles, $crit); |
|
| 1482 | + |
|
| 1483 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1484 | + if (is_array($res)) { |
|
| 1485 | + $msg = $res; |
|
| 1486 | + erreur_squelette($msg, $boucle); |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + return $msg; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | /** |
@@ -1502,11 +1502,11 @@ discard block |
||
| 1502 | 1502 | * @return string Code compilé rééchappé |
| 1503 | 1503 | */ |
| 1504 | 1504 | function kwote($lisp, $serveur = '', $type = '') { |
| 1505 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1506 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1507 | - } else { |
|
| 1508 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1509 | - } |
|
| 1505 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1506 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1507 | + } else { |
|
| 1508 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1509 | + } |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | |
@@ -1525,81 +1525,81 @@ discard block |
||
| 1525 | 1525 | * @return void|array |
| 1526 | 1526 | **/ |
| 1527 | 1527 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1528 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1529 | - if (!$r) { |
|
| 1530 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1531 | - } |
|
| 1532 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1533 | - |
|
| 1534 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1535 | - |
|
| 1536 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1537 | - $where = $in; |
|
| 1538 | - if ($crit->cond) { |
|
| 1539 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1540 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1541 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1542 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - if ($crit->exclus) { |
|
| 1546 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1547 | - $where = ["'NOT'", $where]; |
|
| 1548 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1549 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1550 | - { |
|
| 1551 | - $where = [ |
|
| 1552 | - "'NOT'", |
|
| 1553 | - [ |
|
| 1554 | - "'IN'", |
|
| 1555 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1556 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1557 | - ] |
|
| 1558 | - ]; |
|
| 1559 | - } |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - $boucles[$idb]->where[] = $where; |
|
| 1563 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1564 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1565 | - } |
|
| 1528 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1529 | + if (!$r) { |
|
| 1530 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1531 | + } |
|
| 1532 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1533 | + |
|
| 1534 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1535 | + |
|
| 1536 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1537 | + $where = $in; |
|
| 1538 | + if ($crit->cond) { |
|
| 1539 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1540 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1541 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1542 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + if ($crit->exclus) { |
|
| 1546 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1547 | + $where = ["'NOT'", $where]; |
|
| 1548 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1549 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1550 | + { |
|
| 1551 | + $where = [ |
|
| 1552 | + "'NOT'", |
|
| 1553 | + [ |
|
| 1554 | + "'IN'", |
|
| 1555 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1556 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1557 | + ] |
|
| 1558 | + ]; |
|
| 1559 | + } |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + $boucles[$idb]->where[] = $where; |
|
| 1563 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1564 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1565 | + } |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1569 | - static $num = []; |
|
| 1570 | - $descr = $boucles[$idb]->descr; |
|
| 1571 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1572 | - |
|
| 1573 | - $var = '$in' . $cpt++; |
|
| 1574 | - $x = "\n\t$var = array();"; |
|
| 1575 | - foreach ($val as $k => $v) { |
|
| 1576 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1577 | - // optimiser le traitement des constantes |
|
| 1578 | - if (is_numeric($r[2])) { |
|
| 1579 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1580 | - } else { |
|
| 1581 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1582 | - } |
|
| 1583 | - } else { |
|
| 1584 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1585 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1586 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1587 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1588 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1589 | - } |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - $boucles[$idb]->in .= $x; |
|
| 1593 | - |
|
| 1594 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1595 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1596 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1597 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1598 | - if (!$crit2) { |
|
| 1599 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1569 | + static $num = []; |
|
| 1570 | + $descr = $boucles[$idb]->descr; |
|
| 1571 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1572 | + |
|
| 1573 | + $var = '$in' . $cpt++; |
|
| 1574 | + $x = "\n\t$var = array();"; |
|
| 1575 | + foreach ($val as $k => $v) { |
|
| 1576 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1577 | + // optimiser le traitement des constantes |
|
| 1578 | + if (is_numeric($r[2])) { |
|
| 1579 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1580 | + } else { |
|
| 1581 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1582 | + } |
|
| 1583 | + } else { |
|
| 1584 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1585 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1586 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1587 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1588 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1589 | + } |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + $boucles[$idb]->in .= $x; |
|
| 1593 | + |
|
| 1594 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1595 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1596 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1597 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1598 | + if (!$crit2) { |
|
| 1599 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | /** |
@@ -1615,22 +1615,22 @@ discard block |
||
| 1615 | 1615 | * @return void |
| 1616 | 1616 | */ |
| 1617 | 1617 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1618 | - $boucle = &$boucles[$idb]; |
|
| 1619 | - if (isset($crit->param[0])) { |
|
| 1620 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1621 | - } else { |
|
| 1622 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - if ($crit->cond) { |
|
| 1626 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - if ($crit->not) { |
|
| 1630 | - $_where = "array('NOT',$_where)"; |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - $boucle->where[] = $_where; |
|
| 1618 | + $boucle = &$boucles[$idb]; |
|
| 1619 | + if (isset($crit->param[0])) { |
|
| 1620 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1621 | + } else { |
|
| 1622 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + if ($crit->cond) { |
|
| 1626 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + if ($crit->not) { |
|
| 1630 | + $_where = "array('NOT',$_where)"; |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + $boucle->where[] = $_where; |
|
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | 1636 | /** |
@@ -1658,31 +1658,31 @@ discard block |
||
| 1658 | 1658 | * @return void |
| 1659 | 1659 | */ |
| 1660 | 1660 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1661 | - /** @var Boucle $boucle */ |
|
| 1662 | - $boucle = $boucles[$idb]; |
|
| 1663 | - |
|
| 1664 | - $champs = lister_champs_id_conditionnel( |
|
| 1665 | - $boucle->show['table'], |
|
| 1666 | - $boucle->show, |
|
| 1667 | - $boucle->sql_serveur |
|
| 1668 | - ); |
|
| 1669 | - |
|
| 1670 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1671 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1672 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1673 | - } |
|
| 1674 | - // nous aider en mode debug. |
|
| 1675 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1676 | - $boucle->modificateur['id_'] = $champs; |
|
| 1677 | - |
|
| 1678 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1679 | - foreach ($champs as $champ) { |
|
| 1680 | - $critere_id_table = new Critere(); |
|
| 1681 | - $critere_id_table->op = $champ; |
|
| 1682 | - $critere_id_table->cond = true; |
|
| 1683 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1684 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1685 | - } |
|
| 1661 | + /** @var Boucle $boucle */ |
|
| 1662 | + $boucle = $boucles[$idb]; |
|
| 1663 | + |
|
| 1664 | + $champs = lister_champs_id_conditionnel( |
|
| 1665 | + $boucle->show['table'], |
|
| 1666 | + $boucle->show, |
|
| 1667 | + $boucle->sql_serveur |
|
| 1668 | + ); |
|
| 1669 | + |
|
| 1670 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1671 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1672 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1673 | + } |
|
| 1674 | + // nous aider en mode debug. |
|
| 1675 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1676 | + $boucle->modificateur['id_'] = $champs; |
|
| 1677 | + |
|
| 1678 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1679 | + foreach ($champs as $champ) { |
|
| 1680 | + $critere_id_table = new Critere(); |
|
| 1681 | + $critere_id_table->op = $champ; |
|
| 1682 | + $critere_id_table->cond = true; |
|
| 1683 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1684 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1685 | + } |
|
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | /** |
@@ -1702,75 +1702,75 @@ discard block |
||
| 1702 | 1702 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1703 | 1703 | */ |
| 1704 | 1704 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1705 | - // calculer la description de la table |
|
| 1706 | - if (!is_array($desc)) { |
|
| 1707 | - $desc = description_table($table, $serveur); |
|
| 1708 | - } |
|
| 1709 | - if (!$desc) { |
|
| 1710 | - return []; |
|
| 1711 | - } |
|
| 1712 | - |
|
| 1713 | - // Les champs id_xx de la table demandée |
|
| 1714 | - $champs = array_filter( |
|
| 1715 | - array_keys($desc['field']), |
|
| 1716 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1717 | - ); |
|
| 1718 | - |
|
| 1719 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1720 | - if ( |
|
| 1721 | - in_array('id_rubrique', $champs) |
|
| 1722 | - and !in_array('id_secteur', $champs) |
|
| 1723 | - ) { |
|
| 1724 | - $champs[] = 'id_secteur'; |
|
| 1725 | - } |
|
| 1726 | - |
|
| 1727 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1728 | - if ($serveur) { |
|
| 1729 | - return $champs; |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - $primary = false; |
|
| 1733 | - $associable = false; |
|
| 1734 | - include_spip('action/editer_liens'); |
|
| 1735 | - |
|
| 1736 | - if (isset($desc['type'])) { |
|
| 1737 | - $primary = id_table_objet($desc['type']); |
|
| 1738 | - $associable = objet_associable($desc['type']); |
|
| 1739 | - } |
|
| 1740 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1741 | - $associable = true; |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - // liste de toutes les tables principales, sauf la notre |
|
| 1745 | - $tables = lister_tables_objets_sql(); |
|
| 1746 | - unset($tables[$table]); |
|
| 1747 | - |
|
| 1748 | - foreach ($tables as $_table => $_desc) { |
|
| 1749 | - if ( |
|
| 1750 | - $associable |
|
| 1751 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1752 | - or objet_associable($_desc['type']) |
|
| 1753 | - ) { |
|
| 1754 | - $champs[] = id_table_objet($_table); |
|
| 1755 | - } |
|
| 1756 | - } |
|
| 1757 | - $champs = array_values(array_unique($champs)); |
|
| 1758 | - |
|
| 1759 | - // Exclusions de certains id |
|
| 1760 | - $exclusions = pipeline( |
|
| 1761 | - 'exclure_id_conditionnel', |
|
| 1762 | - [ |
|
| 1763 | - 'args' => [ |
|
| 1764 | - 'table' => $table, |
|
| 1765 | - 'id_table_objet' => $primary, |
|
| 1766 | - 'associable' => $associable, |
|
| 1767 | - ], |
|
| 1768 | - 'data' => [], |
|
| 1769 | - ] |
|
| 1770 | - ); |
|
| 1771 | - $champs = array_diff($champs, $exclusions); |
|
| 1772 | - |
|
| 1773 | - return $champs; |
|
| 1705 | + // calculer la description de la table |
|
| 1706 | + if (!is_array($desc)) { |
|
| 1707 | + $desc = description_table($table, $serveur); |
|
| 1708 | + } |
|
| 1709 | + if (!$desc) { |
|
| 1710 | + return []; |
|
| 1711 | + } |
|
| 1712 | + |
|
| 1713 | + // Les champs id_xx de la table demandée |
|
| 1714 | + $champs = array_filter( |
|
| 1715 | + array_keys($desc['field']), |
|
| 1716 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1717 | + ); |
|
| 1718 | + |
|
| 1719 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1720 | + if ( |
|
| 1721 | + in_array('id_rubrique', $champs) |
|
| 1722 | + and !in_array('id_secteur', $champs) |
|
| 1723 | + ) { |
|
| 1724 | + $champs[] = 'id_secteur'; |
|
| 1725 | + } |
|
| 1726 | + |
|
| 1727 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1728 | + if ($serveur) { |
|
| 1729 | + return $champs; |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + $primary = false; |
|
| 1733 | + $associable = false; |
|
| 1734 | + include_spip('action/editer_liens'); |
|
| 1735 | + |
|
| 1736 | + if (isset($desc['type'])) { |
|
| 1737 | + $primary = id_table_objet($desc['type']); |
|
| 1738 | + $associable = objet_associable($desc['type']); |
|
| 1739 | + } |
|
| 1740 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1741 | + $associable = true; |
|
| 1742 | + } |
|
| 1743 | + |
|
| 1744 | + // liste de toutes les tables principales, sauf la notre |
|
| 1745 | + $tables = lister_tables_objets_sql(); |
|
| 1746 | + unset($tables[$table]); |
|
| 1747 | + |
|
| 1748 | + foreach ($tables as $_table => $_desc) { |
|
| 1749 | + if ( |
|
| 1750 | + $associable |
|
| 1751 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1752 | + or objet_associable($_desc['type']) |
|
| 1753 | + ) { |
|
| 1754 | + $champs[] = id_table_objet($_table); |
|
| 1755 | + } |
|
| 1756 | + } |
|
| 1757 | + $champs = array_values(array_unique($champs)); |
|
| 1758 | + |
|
| 1759 | + // Exclusions de certains id |
|
| 1760 | + $exclusions = pipeline( |
|
| 1761 | + 'exclure_id_conditionnel', |
|
| 1762 | + [ |
|
| 1763 | + 'args' => [ |
|
| 1764 | + 'table' => $table, |
|
| 1765 | + 'id_table_objet' => $primary, |
|
| 1766 | + 'associable' => $associable, |
|
| 1767 | + ], |
|
| 1768 | + 'data' => [], |
|
| 1769 | + ] |
|
| 1770 | + ); |
|
| 1771 | + $champs = array_diff($champs, $exclusions); |
|
| 1772 | + |
|
| 1773 | + return $champs; |
|
| 1774 | 1774 | } |
| 1775 | 1775 | |
| 1776 | 1776 | /** |
@@ -1825,28 +1825,28 @@ discard block |
||
| 1825 | 1825 | * @return void |
| 1826 | 1826 | */ |
| 1827 | 1827 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1828 | - $boucle = &$boucles[$idb]; |
|
| 1829 | - |
|
| 1830 | - // definition du champ par defaut |
|
| 1831 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1832 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1833 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1834 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1835 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1836 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1837 | - |
|
| 1838 | - $_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):'')"; |
|
| 1839 | - |
|
| 1840 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1841 | - $_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)"; |
|
| 1842 | - |
|
| 1843 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1844 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1845 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1846 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1847 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1848 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1849 | - $boucle->hash .= " |
|
| 1828 | + $boucle = &$boucles[$idb]; |
|
| 1829 | + |
|
| 1830 | + // definition du champ par defaut |
|
| 1831 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1832 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1833 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1834 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1835 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1836 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1837 | + |
|
| 1838 | + $_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):'')"; |
|
| 1839 | + |
|
| 1840 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1841 | + $_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)"; |
|
| 1842 | + |
|
| 1843 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1844 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1845 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1846 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1847 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1848 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1849 | + $boucle->hash .= " |
|
| 1850 | 1850 | \$senstri = ''; |
| 1851 | 1851 | \$tri = $_tri; |
| 1852 | 1852 | if (\$tri){ |
@@ -1854,8 +1854,8 @@ discard block |
||
| 1854 | 1854 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1855 | 1855 | }; |
| 1856 | 1856 | "; |
| 1857 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1858 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1857 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1858 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1859 | 1859 | } |
| 1860 | 1860 | |
| 1861 | 1861 | # criteres de comparaison |
@@ -1872,21 +1872,21 @@ discard block |
||
| 1872 | 1872 | * @return void|array |
| 1873 | 1873 | **/ |
| 1874 | 1874 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1875 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1876 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1877 | - calculer_critere_parties($idb, $boucles, $crit); |
|
| 1878 | - return; |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1882 | - if (!$r) { |
|
| 1883 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1884 | - # if (!$crit->cond) { |
|
| 1885 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1886 | - # } |
|
| 1887 | - } else { |
|
| 1888 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1889 | - } |
|
| 1875 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1876 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1877 | + calculer_critere_parties($idb, $boucles, $crit); |
|
| 1878 | + return; |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1882 | + if (!$r) { |
|
| 1883 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1884 | + # if (!$crit->cond) { |
|
| 1885 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1886 | + # } |
|
| 1887 | + } else { |
|
| 1888 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1889 | + } |
|
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | 1892 | |
@@ -1906,62 +1906,62 @@ discard block |
||
| 1906 | 1906 | * @return void |
| 1907 | 1907 | **/ |
| 1908 | 1908 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1909 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1910 | - |
|
| 1911 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1912 | - |
|
| 1913 | - // inserer la negation (cf !...) |
|
| 1914 | - |
|
| 1915 | - if ($crit->not) { |
|
| 1916 | - $where = ["'NOT'", $where]; |
|
| 1917 | - } |
|
| 1918 | - if ($crit->exclus) { |
|
| 1919 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1920 | - $where = ["'NOT'", $where]; |
|
| 1921 | - } else { |
|
| 1922 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1923 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1924 | - $where = [ |
|
| 1925 | - "'NOT'", |
|
| 1926 | - [ |
|
| 1927 | - "'IN'", |
|
| 1928 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1929 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1930 | - ] |
|
| 1931 | - ]; |
|
| 1932 | - } |
|
| 1933 | - } |
|
| 1934 | - |
|
| 1935 | - // inserer la condition (cf {lang?}) |
|
| 1936 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1937 | - if ($crit->cond) { |
|
| 1938 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1939 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1940 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1941 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1942 | - } |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - if ($op === '=' and !$crit->not) { |
|
| 1946 | - $where = [ |
|
| 1947 | - "'?'", |
|
| 1948 | - "(is_array($pred))", |
|
| 1949 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1950 | - $where |
|
| 1951 | - ]; |
|
| 1952 | - } |
|
| 1953 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1954 | - if ($where_complement) { |
|
| 1955 | - // condition annexe du type "AND (objet='article')" |
|
| 1956 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1957 | - } |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - $boucles[$idb]->where[] = $where; |
|
| 1961 | - if ($where_complement) { |
|
| 1962 | - // condition annexe du type "AND (objet='article')" |
|
| 1963 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1964 | - } |
|
| 1909 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1910 | + |
|
| 1911 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1912 | + |
|
| 1913 | + // inserer la negation (cf !...) |
|
| 1914 | + |
|
| 1915 | + if ($crit->not) { |
|
| 1916 | + $where = ["'NOT'", $where]; |
|
| 1917 | + } |
|
| 1918 | + if ($crit->exclus) { |
|
| 1919 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1920 | + $where = ["'NOT'", $where]; |
|
| 1921 | + } else { |
|
| 1922 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1923 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1924 | + $where = [ |
|
| 1925 | + "'NOT'", |
|
| 1926 | + [ |
|
| 1927 | + "'IN'", |
|
| 1928 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1929 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1930 | + ] |
|
| 1931 | + ]; |
|
| 1932 | + } |
|
| 1933 | + } |
|
| 1934 | + |
|
| 1935 | + // inserer la condition (cf {lang?}) |
|
| 1936 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1937 | + if ($crit->cond) { |
|
| 1938 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1939 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1940 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1941 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1942 | + } |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + if ($op === '=' and !$crit->not) { |
|
| 1946 | + $where = [ |
|
| 1947 | + "'?'", |
|
| 1948 | + "(is_array($pred))", |
|
| 1949 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1950 | + $where |
|
| 1951 | + ]; |
|
| 1952 | + } |
|
| 1953 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1954 | + if ($where_complement) { |
|
| 1955 | + // condition annexe du type "AND (objet='article')" |
|
| 1956 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1957 | + } |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + $boucles[$idb]->where[] = $where; |
|
| 1961 | + if ($where_complement) { |
|
| 1962 | + // condition annexe du type "AND (objet='article')" |
|
| 1963 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1964 | + } |
|
| 1965 | 1965 | } |
| 1966 | 1966 | |
| 1967 | 1967 | |
@@ -2002,165 +2002,165 @@ discard block |
||
| 2002 | 2002 | **/ |
| 2003 | 2003 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2004 | 2004 | |
| 2005 | - $boucle = &$boucles[$idb]; |
|
| 2006 | - $type = $boucle->type_requete; |
|
| 2007 | - $table = $boucle->id_table; |
|
| 2008 | - $desc = $boucle->show; |
|
| 2009 | - $col_vraie = null; |
|
| 2010 | - |
|
| 2011 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2012 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2013 | - |
|
| 2014 | - $col_alias = $col; |
|
| 2015 | - $where_complement = false; |
|
| 2016 | - |
|
| 2017 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2018 | - if ($col == 'id_enfant') { |
|
| 2019 | - $col = $boucle->primary; |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2023 | - if ( |
|
| 2024 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2025 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | - ) { |
|
| 2027 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2028 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2029 | - else { |
|
| 2030 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2031 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2032 | - } |
|
| 2033 | - |
|
| 2034 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2035 | - // sauf si exception declaree : sauter cette etape |
|
| 2036 | - else { |
|
| 2037 | - if ( |
|
| 2038 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2039 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2040 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2041 | - ) { |
|
| 2042 | - $e = decompose_champ_id_objet($col); |
|
| 2043 | - $col = array_shift($e); |
|
| 2044 | - $where_complement = primary_doublee($e, $table); |
|
| 2045 | - } // Cas particulier : expressions de date |
|
| 2046 | - else { |
|
| 2047 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2048 | - [$col, $col_vraie] = $c; |
|
| 2049 | - $table = ''; |
|
| 2050 | - } // table explicitée {mots.titre} |
|
| 2051 | - else { |
|
| 2052 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2053 | - [, $table, $col] = $r; |
|
| 2054 | - $col_alias = $col; |
|
| 2055 | - |
|
| 2056 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2057 | - if ( |
|
| 2058 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2059 | - and isset($desc['field'][$col]) |
|
| 2060 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2061 | - ) { |
|
| 2062 | - $table = $cle; |
|
| 2063 | - } else { |
|
| 2064 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2065 | - } |
|
| 2066 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2067 | - if (!$table) { |
|
| 2068 | - return ''; |
|
| 2069 | - } |
|
| 2070 | - } |
|
| 2071 | - // si le champ n'est pas trouvé dans la table, |
|
| 2072 | - // on cherche si une jointure peut l'obtenir |
|
| 2073 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2074 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2075 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2076 | - $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 |
|
| 2077 | - } |
|
| 2078 | - else { |
|
| 2079 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2080 | - if (!$r) { |
|
| 2081 | - return ''; |
|
| 2082 | - } |
|
| 2083 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2090 | - |
|
| 2091 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2092 | - // Dans tous les cas, |
|
| 2093 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2094 | - // et passer dans sql_quote avec le type si connu |
|
| 2095 | - // et int sinon si la valeur est numerique |
|
| 2096 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2097 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2098 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2099 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2100 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2101 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2102 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2103 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2104 | - } |
|
| 2105 | - // sinon expliciter les |
|
| 2106 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2107 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2108 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2109 | - // sans toucher aux |
|
| 2110 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2111 | - // sql_quote(truc,'','varchar') |
|
| 2112 | - elseif ( |
|
| 2113 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2114 | - // si pas deja un type |
|
| 2115 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2116 | - ) { |
|
| 2117 | - $r = $r[1] |
|
| 2118 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2119 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2120 | - $val[0] = "sql_quote($r)"; |
|
| 2121 | - } |
|
| 2122 | - elseif ( |
|
| 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])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2127 | - } |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - if ( |
|
| 2131 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | - ) { |
|
| 2134 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2135 | - } |
|
| 2136 | - |
|
| 2137 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2138 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2139 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2140 | - if ($table === $boucle->id_table) { |
|
| 2141 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2142 | - if ($col_alias != $col_vraie) { |
|
| 2143 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2144 | - } |
|
| 2145 | - } |
|
| 2146 | - |
|
| 2147 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2148 | - if ($table) { |
|
| 2149 | - if ($col[0] == '`') { |
|
| 2150 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2151 | - } else { |
|
| 2152 | - $arg = "$table.$col"; |
|
| 2153 | - } |
|
| 2154 | - } else { |
|
| 2155 | - $arg = $col; |
|
| 2156 | - } |
|
| 2157 | - |
|
| 2158 | - // inserer la fonction SQL |
|
| 2159 | - if ($fct) { |
|
| 2160 | - $arg = "$fct($arg$args_sql)"; |
|
| 2161 | - } |
|
| 2162 | - |
|
| 2163 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2005 | + $boucle = &$boucles[$idb]; |
|
| 2006 | + $type = $boucle->type_requete; |
|
| 2007 | + $table = $boucle->id_table; |
|
| 2008 | + $desc = $boucle->show; |
|
| 2009 | + $col_vraie = null; |
|
| 2010 | + |
|
| 2011 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2012 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2013 | + |
|
| 2014 | + $col_alias = $col; |
|
| 2015 | + $where_complement = false; |
|
| 2016 | + |
|
| 2017 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2018 | + if ($col == 'id_enfant') { |
|
| 2019 | + $col = $boucle->primary; |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2023 | + if ( |
|
| 2024 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2025 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | + ) { |
|
| 2027 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2028 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2029 | + else { |
|
| 2030 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2031 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2032 | + } |
|
| 2033 | + |
|
| 2034 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2035 | + // sauf si exception declaree : sauter cette etape |
|
| 2036 | + else { |
|
| 2037 | + if ( |
|
| 2038 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2039 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2040 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2041 | + ) { |
|
| 2042 | + $e = decompose_champ_id_objet($col); |
|
| 2043 | + $col = array_shift($e); |
|
| 2044 | + $where_complement = primary_doublee($e, $table); |
|
| 2045 | + } // Cas particulier : expressions de date |
|
| 2046 | + else { |
|
| 2047 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2048 | + [$col, $col_vraie] = $c; |
|
| 2049 | + $table = ''; |
|
| 2050 | + } // table explicitée {mots.titre} |
|
| 2051 | + else { |
|
| 2052 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2053 | + [, $table, $col] = $r; |
|
| 2054 | + $col_alias = $col; |
|
| 2055 | + |
|
| 2056 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2057 | + if ( |
|
| 2058 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2059 | + and isset($desc['field'][$col]) |
|
| 2060 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2061 | + ) { |
|
| 2062 | + $table = $cle; |
|
| 2063 | + } else { |
|
| 2064 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2065 | + } |
|
| 2066 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2067 | + if (!$table) { |
|
| 2068 | + return ''; |
|
| 2069 | + } |
|
| 2070 | + } |
|
| 2071 | + // si le champ n'est pas trouvé dans la table, |
|
| 2072 | + // on cherche si une jointure peut l'obtenir |
|
| 2073 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2074 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2075 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2076 | + $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 |
|
| 2077 | + } |
|
| 2078 | + else { |
|
| 2079 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2080 | + if (!$r) { |
|
| 2081 | + return ''; |
|
| 2082 | + } |
|
| 2083 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | + |
|
| 2091 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2092 | + // Dans tous les cas, |
|
| 2093 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2094 | + // et passer dans sql_quote avec le type si connu |
|
| 2095 | + // et int sinon si la valeur est numerique |
|
| 2096 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2097 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2098 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2099 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2100 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2101 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2102 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2103 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2104 | + } |
|
| 2105 | + // sinon expliciter les |
|
| 2106 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2107 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2108 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2109 | + // sans toucher aux |
|
| 2110 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2111 | + // sql_quote(truc,'','varchar') |
|
| 2112 | + elseif ( |
|
| 2113 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2114 | + // si pas deja un type |
|
| 2115 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2116 | + ) { |
|
| 2117 | + $r = $r[1] |
|
| 2118 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2119 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2120 | + $val[0] = "sql_quote($r)"; |
|
| 2121 | + } |
|
| 2122 | + elseif ( |
|
| 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])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2127 | + } |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + if ( |
|
| 2131 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2132 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2133 | + ) { |
|
| 2134 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2135 | + } |
|
| 2136 | + |
|
| 2137 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2138 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2139 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2140 | + if ($table === $boucle->id_table) { |
|
| 2141 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2142 | + if ($col_alias != $col_vraie) { |
|
| 2143 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2144 | + } |
|
| 2145 | + } |
|
| 2146 | + |
|
| 2147 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2148 | + if ($table) { |
|
| 2149 | + if ($col[0] == '`') { |
|
| 2150 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2151 | + } else { |
|
| 2152 | + $arg = "$table.$col"; |
|
| 2153 | + } |
|
| 2154 | + } else { |
|
| 2155 | + $arg = $col; |
|
| 2156 | + } |
|
| 2157 | + |
|
| 2158 | + // inserer la fonction SQL |
|
| 2159 | + if ($fct) { |
|
| 2160 | + $arg = "$fct($arg$args_sql)"; |
|
| 2161 | + } |
|
| 2162 | + |
|
| 2163 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | |
@@ -2189,77 +2189,77 @@ discard block |
||
| 2189 | 2189 | **/ |
| 2190 | 2190 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2191 | 2191 | |
| 2192 | - $where = ''; |
|
| 2193 | - |
|
| 2194 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2195 | - // gestion par les plugins des jointures tordues |
|
| 2196 | - // pas automatiques mais necessaires |
|
| 2197 | - $table_sql = table_objet_sql($table); |
|
| 2198 | - if ( |
|
| 2199 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2200 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | - and |
|
| 2202 | - ( |
|
| 2203 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2204 | - or |
|
| 2205 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2206 | - ) |
|
| 2207 | - ) { |
|
| 2208 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2209 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2210 | - |
|
| 2211 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2212 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2213 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2214 | - [$t, $col] = $t[$col]; |
|
| 2215 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2216 | - [$calculer_critere_externe] = $index; |
|
| 2217 | - $t = $table; |
|
| 2218 | - } else { |
|
| 2219 | - $t = ''; |
|
| 2220 | - } // jointure non declaree. La trouver. |
|
| 2221 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2222 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2223 | - } else { |
|
| 2224 | - $t = ''; |
|
| 2225 | - } // jointure non declaree. La trouver. |
|
| 2226 | - |
|
| 2227 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2228 | - |
|
| 2229 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2230 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2231 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2232 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2233 | - $table = ''; |
|
| 2234 | - if ($boucle->jointures_explicites) { |
|
| 2235 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2236 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2237 | - } |
|
| 2238 | - |
|
| 2239 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2240 | - if (!$table) { |
|
| 2241 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - if (!$table) { |
|
| 2245 | - return ''; |
|
| 2246 | - } |
|
| 2247 | - |
|
| 2248 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2249 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2250 | - |
|
| 2251 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2252 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2253 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2254 | - $e = decompose_champ_id_objet($col); |
|
| 2255 | - $col = array_shift($e); |
|
| 2256 | - $where = primary_doublee($e, $table); |
|
| 2257 | - } else { |
|
| 2258 | - $col = reset($cle); |
|
| 2259 | - } |
|
| 2260 | - } |
|
| 2261 | - |
|
| 2262 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2192 | + $where = ''; |
|
| 2193 | + |
|
| 2194 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2195 | + // gestion par les plugins des jointures tordues |
|
| 2196 | + // pas automatiques mais necessaires |
|
| 2197 | + $table_sql = table_objet_sql($table); |
|
| 2198 | + if ( |
|
| 2199 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2200 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | + and |
|
| 2202 | + ( |
|
| 2203 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2204 | + or |
|
| 2205 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2206 | + ) |
|
| 2207 | + ) { |
|
| 2208 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2209 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2210 | + |
|
| 2211 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2212 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2213 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2214 | + [$t, $col] = $t[$col]; |
|
| 2215 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2216 | + [$calculer_critere_externe] = $index; |
|
| 2217 | + $t = $table; |
|
| 2218 | + } else { |
|
| 2219 | + $t = ''; |
|
| 2220 | + } // jointure non declaree. La trouver. |
|
| 2221 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2222 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2223 | + } else { |
|
| 2224 | + $t = ''; |
|
| 2225 | + } // jointure non declaree. La trouver. |
|
| 2226 | + |
|
| 2227 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2228 | + |
|
| 2229 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2230 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2231 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2232 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2233 | + $table = ''; |
|
| 2234 | + if ($boucle->jointures_explicites) { |
|
| 2235 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2236 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2237 | + } |
|
| 2238 | + |
|
| 2239 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2240 | + if (!$table) { |
|
| 2241 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + if (!$table) { |
|
| 2245 | + return ''; |
|
| 2246 | + } |
|
| 2247 | + |
|
| 2248 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2249 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2250 | + |
|
| 2251 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2252 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2253 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2254 | + $e = decompose_champ_id_objet($col); |
|
| 2255 | + $col = array_shift($e); |
|
| 2256 | + $where = primary_doublee($e, $table); |
|
| 2257 | + } else { |
|
| 2258 | + $col = reset($cle); |
|
| 2259 | + } |
|
| 2260 | + } |
|
| 2261 | + |
|
| 2262 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2263 | 2263 | } |
| 2264 | 2264 | |
| 2265 | 2265 | |
@@ -2280,10 +2280,10 @@ discard block |
||
| 2280 | 2280 | * - valeur |
| 2281 | 2281 | **/ |
| 2282 | 2282 | function primary_doublee($decompose, $table) { |
| 2283 | - $e1 = reset($decompose); |
|
| 2284 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2283 | + $e1 = reset($decompose); |
|
| 2284 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2285 | 2285 | |
| 2286 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2286 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2287 | 2287 | } |
| 2288 | 2288 | |
| 2289 | 2289 | /** |
@@ -2314,57 +2314,57 @@ discard block |
||
| 2314 | 2314 | * Vide sinon. |
| 2315 | 2315 | */ |
| 2316 | 2316 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2317 | - // si on demande un truc du genre spip_mots |
|
| 2318 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2319 | - // et qu'on est la |
|
| 2320 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2321 | - if ( |
|
| 2322 | - $checkarrivee |
|
| 2323 | - and is_string($checkarrivee) |
|
| 2324 | - and $a = table_objet($checkarrivee) |
|
| 2325 | - and in_array($a . '_liens', $joints) |
|
| 2326 | - ) { |
|
| 2327 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2328 | - return $res; |
|
| 2329 | - } |
|
| 2330 | - } |
|
| 2331 | - foreach ($joints as $joint) { |
|
| 2332 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2333 | - // alias de table dans le from |
|
| 2334 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2335 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2336 | - $cols = $arrivee[2]; |
|
| 2337 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2338 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2339 | - array_pop($cols); |
|
| 2340 | - } |
|
| 2341 | - if ($t) { |
|
| 2342 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2343 | - $joindre = false; |
|
| 2344 | - foreach ($cols as $col) { |
|
| 2345 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2346 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2347 | - $joindre = true; |
|
| 2348 | - } else { |
|
| 2349 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2350 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2351 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2352 | - $joindre = true; |
|
| 2353 | - } |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - if (!$joindre) { |
|
| 2357 | - return $t; |
|
| 2358 | - } |
|
| 2359 | - } |
|
| 2360 | - array_pop($arrivee); |
|
| 2361 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2362 | - return $res; |
|
| 2363 | - } |
|
| 2364 | - } |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - return ''; |
|
| 2317 | + // si on demande un truc du genre spip_mots |
|
| 2318 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2319 | + // et qu'on est la |
|
| 2320 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2321 | + if ( |
|
| 2322 | + $checkarrivee |
|
| 2323 | + and is_string($checkarrivee) |
|
| 2324 | + and $a = table_objet($checkarrivee) |
|
| 2325 | + and in_array($a . '_liens', $joints) |
|
| 2326 | + ) { |
|
| 2327 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2328 | + return $res; |
|
| 2329 | + } |
|
| 2330 | + } |
|
| 2331 | + foreach ($joints as $joint) { |
|
| 2332 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2333 | + // alias de table dans le from |
|
| 2334 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2335 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2336 | + $cols = $arrivee[2]; |
|
| 2337 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2338 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2339 | + array_pop($cols); |
|
| 2340 | + } |
|
| 2341 | + if ($t) { |
|
| 2342 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2343 | + $joindre = false; |
|
| 2344 | + foreach ($cols as $col) { |
|
| 2345 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2346 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2347 | + $joindre = true; |
|
| 2348 | + } else { |
|
| 2349 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2350 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2351 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2352 | + $joindre = true; |
|
| 2353 | + } |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + if (!$joindre) { |
|
| 2357 | + return $t; |
|
| 2358 | + } |
|
| 2359 | + } |
|
| 2360 | + array_pop($arrivee); |
|
| 2361 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2362 | + return $res; |
|
| 2363 | + } |
|
| 2364 | + } |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + return ''; |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | /** |
@@ -2390,35 +2390,35 @@ discard block |
||
| 2390 | 2390 | * Alias de la table de jointure (Lx) |
| 2391 | 2391 | */ |
| 2392 | 2392 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2393 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2394 | - |
|
| 2395 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2396 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2397 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2398 | - |
|
| 2399 | - if (!$intermediaire or !$arrivee) { |
|
| 2400 | - return ''; |
|
| 2401 | - } |
|
| 2402 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2403 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2404 | - |
|
| 2405 | - $res = fabrique_jointures( |
|
| 2406 | - $boucle, |
|
| 2407 | - [ |
|
| 2408 | - [ |
|
| 2409 | - $boucle->id_table, |
|
| 2410 | - $intermediaire, |
|
| 2411 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2412 | - ], |
|
| 2413 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2414 | - ], |
|
| 2415 | - $cond, |
|
| 2416 | - $desc, |
|
| 2417 | - $boucle->id_table, |
|
| 2418 | - [$col] |
|
| 2419 | - ); |
|
| 2420 | - |
|
| 2421 | - return $res; |
|
| 2393 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2394 | + |
|
| 2395 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2396 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2397 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2398 | + |
|
| 2399 | + if (!$intermediaire or !$arrivee) { |
|
| 2400 | + return ''; |
|
| 2401 | + } |
|
| 2402 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2403 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2404 | + |
|
| 2405 | + $res = fabrique_jointures( |
|
| 2406 | + $boucle, |
|
| 2407 | + [ |
|
| 2408 | + [ |
|
| 2409 | + $boucle->id_table, |
|
| 2410 | + $intermediaire, |
|
| 2411 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2412 | + ], |
|
| 2413 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2414 | + ], |
|
| 2415 | + $cond, |
|
| 2416 | + $desc, |
|
| 2417 | + $boucle->id_table, |
|
| 2418 | + [$col] |
|
| 2419 | + ); |
|
| 2420 | + |
|
| 2421 | + return $res; |
|
| 2422 | 2422 | } |
| 2423 | 2423 | |
| 2424 | 2424 | |
@@ -2435,17 +2435,17 @@ discard block |
||
| 2435 | 2435 | * false sinon. |
| 2436 | 2436 | **/ |
| 2437 | 2437 | function trouver_champ($champ, $where) { |
| 2438 | - if (!is_array($where)) { |
|
| 2439 | - return preg_match($champ, $where); |
|
| 2440 | - } else { |
|
| 2441 | - foreach ($where as $clause) { |
|
| 2442 | - if (trouver_champ($champ, $clause)) { |
|
| 2443 | - return true; |
|
| 2444 | - } |
|
| 2445 | - } |
|
| 2446 | - |
|
| 2447 | - return false; |
|
| 2448 | - } |
|
| 2438 | + if (!is_array($where)) { |
|
| 2439 | + return preg_match($champ, $where); |
|
| 2440 | + } else { |
|
| 2441 | + foreach ($where as $clause) { |
|
| 2442 | + if (trouver_champ($champ, $clause)) { |
|
| 2443 | + return true; |
|
| 2444 | + } |
|
| 2445 | + } |
|
| 2446 | + |
|
| 2447 | + return false; |
|
| 2448 | + } |
|
| 2449 | 2449 | } |
| 2450 | 2450 | |
| 2451 | 2451 | |
@@ -2471,129 +2471,129 @@ discard block |
||
| 2471 | 2471 | * - string $args_sql Suite des arguments du critère. ? |
| 2472 | 2472 | **/ |
| 2473 | 2473 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2474 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2475 | - if (count($crit->param) == 0) { |
|
| 2476 | - $op = '='; |
|
| 2477 | - $col = $val = $crit->op; |
|
| 2478 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2479 | - $val = $r[2]; |
|
| 2480 | - } |
|
| 2481 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2482 | - if ($val == 'lang') { |
|
| 2483 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2484 | - } else { |
|
| 2485 | - $defaut = null; |
|
| 2486 | - if ($val == 'id_parent') { |
|
| 2487 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2488 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2489 | - // pour eviter l'erreur SQL |
|
| 2490 | - $val = $boucles[$idb]->primary; |
|
| 2491 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2492 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2493 | - } elseif ($val == 'id_enfant') { |
|
| 2494 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2495 | - // de la boucle superieure |
|
| 2496 | - $val = 'id_parent'; |
|
| 2497 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2498 | - // un critere conditionnel sur date est traite a part |
|
| 2499 | - // car la date est mise d'office par SPIP, |
|
| 2500 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2504 | - $val = [kwote($val)]; |
|
| 2505 | - } |
|
| 2506 | - } else { |
|
| 2507 | - // comparaison explicite |
|
| 2508 | - // le phraseur impose que le premier param soit du texte |
|
| 2509 | - $params = $crit->param; |
|
| 2510 | - $op = $crit->op; |
|
| 2511 | - if ($op == '==') { |
|
| 2512 | - $op = 'REGEXP'; |
|
| 2513 | - } |
|
| 2514 | - $col = array_shift($params); |
|
| 2515 | - $col = $col[0]->texte; |
|
| 2516 | - |
|
| 2517 | - $val = []; |
|
| 2518 | - $parent = $boucles[$idb]->id_parent; |
|
| 2519 | - |
|
| 2520 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2521 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2522 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2523 | - if ( |
|
| 2524 | - count($params) == 1 |
|
| 2525 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2526 | - and $params[0][0]->type == 'texte' |
|
| 2527 | - and $params[0][2]->type == 'texte' |
|
| 2528 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2529 | - and (($p == "'") or ($p == '"')) |
|
| 2530 | - and $params[0][1]->type == 'champ' |
|
| 2531 | - ) { |
|
| 2532 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2533 | - } else { |
|
| 2534 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2535 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2536 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2537 | - $val[] = $a; |
|
| 2538 | - } else { |
|
| 2539 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2540 | - } // toujours quoter en char ici |
|
| 2541 | - } |
|
| 2542 | - } |
|
| 2543 | - } |
|
| 2544 | - |
|
| 2545 | - $fct = $args_sql = ''; |
|
| 2546 | - // fonction SQL ? |
|
| 2547 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2548 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2549 | - $fct = $m[1]; |
|
| 2550 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2551 | - $col = $a[1]; |
|
| 2552 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2553 | - $col = $m[1]; |
|
| 2554 | - $args_sql = $m[2]; |
|
| 2555 | - } |
|
| 2556 | - $args_sql .= $a[2]; |
|
| 2557 | - } |
|
| 2558 | - |
|
| 2559 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2474 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2475 | + if (count($crit->param) == 0) { |
|
| 2476 | + $op = '='; |
|
| 2477 | + $col = $val = $crit->op; |
|
| 2478 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2479 | + $val = $r[2]; |
|
| 2480 | + } |
|
| 2481 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2482 | + if ($val == 'lang') { |
|
| 2483 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2484 | + } else { |
|
| 2485 | + $defaut = null; |
|
| 2486 | + if ($val == 'id_parent') { |
|
| 2487 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2488 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2489 | + // pour eviter l'erreur SQL |
|
| 2490 | + $val = $boucles[$idb]->primary; |
|
| 2491 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2492 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2493 | + } elseif ($val == 'id_enfant') { |
|
| 2494 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2495 | + // de la boucle superieure |
|
| 2496 | + $val = 'id_parent'; |
|
| 2497 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2498 | + // un critere conditionnel sur date est traite a part |
|
| 2499 | + // car la date est mise d'office par SPIP, |
|
| 2500 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2504 | + $val = [kwote($val)]; |
|
| 2505 | + } |
|
| 2506 | + } else { |
|
| 2507 | + // comparaison explicite |
|
| 2508 | + // le phraseur impose que le premier param soit du texte |
|
| 2509 | + $params = $crit->param; |
|
| 2510 | + $op = $crit->op; |
|
| 2511 | + if ($op == '==') { |
|
| 2512 | + $op = 'REGEXP'; |
|
| 2513 | + } |
|
| 2514 | + $col = array_shift($params); |
|
| 2515 | + $col = $col[0]->texte; |
|
| 2516 | + |
|
| 2517 | + $val = []; |
|
| 2518 | + $parent = $boucles[$idb]->id_parent; |
|
| 2519 | + |
|
| 2520 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2521 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2522 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2523 | + if ( |
|
| 2524 | + count($params) == 1 |
|
| 2525 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2526 | + and $params[0][0]->type == 'texte' |
|
| 2527 | + and $params[0][2]->type == 'texte' |
|
| 2528 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2529 | + and (($p == "'") or ($p == '"')) |
|
| 2530 | + and $params[0][1]->type == 'champ' |
|
| 2531 | + ) { |
|
| 2532 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2533 | + } else { |
|
| 2534 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2535 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2536 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2537 | + $val[] = $a; |
|
| 2538 | + } else { |
|
| 2539 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2540 | + } // toujours quoter en char ici |
|
| 2541 | + } |
|
| 2542 | + } |
|
| 2543 | + } |
|
| 2544 | + |
|
| 2545 | + $fct = $args_sql = ''; |
|
| 2546 | + // fonction SQL ? |
|
| 2547 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2548 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2549 | + $fct = $m[1]; |
|
| 2550 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2551 | + $col = $a[1]; |
|
| 2552 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2553 | + $col = $m[1]; |
|
| 2554 | + $args_sql = $m[2]; |
|
| 2555 | + } |
|
| 2556 | + $args_sql .= $a[2]; |
|
| 2557 | + } |
|
| 2558 | + |
|
| 2559 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2560 | 2560 | } |
| 2561 | 2561 | |
| 2562 | 2562 | // compatibilite ancienne version |
| 2563 | 2563 | |
| 2564 | 2564 | function calculer_vieux_in($params) { |
| 2565 | - $deb = $params[0][0]; |
|
| 2566 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2567 | - $last = $params[$k]; |
|
| 2568 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2569 | - $last = $last[$j]; |
|
| 2570 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2571 | - |
|
| 2572 | - if ( |
|
| 2573 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2574 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2575 | - ) { |
|
| 2576 | - return $params; |
|
| 2577 | - } |
|
| 2578 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2579 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2580 | - $last = $params[$k][$j]; |
|
| 2581 | - $n = strlen($last->texte); |
|
| 2582 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2583 | - $newp = []; |
|
| 2584 | - foreach ($params as $v) { |
|
| 2585 | - if ($v[0]->type != 'texte') { |
|
| 2586 | - $newp[] = $v; |
|
| 2587 | - } else { |
|
| 2588 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2589 | - $t = new Texte(); |
|
| 2590 | - $t->texte = $x; |
|
| 2591 | - $newp[] = [$t]; |
|
| 2592 | - } |
|
| 2593 | - } |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - return $newp; |
|
| 2565 | + $deb = $params[0][0]; |
|
| 2566 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2567 | + $last = $params[$k]; |
|
| 2568 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2569 | + $last = $last[$j]; |
|
| 2570 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2571 | + |
|
| 2572 | + if ( |
|
| 2573 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2574 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2575 | + ) { |
|
| 2576 | + return $params; |
|
| 2577 | + } |
|
| 2578 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2579 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2580 | + $last = $params[$k][$j]; |
|
| 2581 | + $n = strlen($last->texte); |
|
| 2582 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2583 | + $newp = []; |
|
| 2584 | + foreach ($params as $v) { |
|
| 2585 | + if ($v[0]->type != 'texte') { |
|
| 2586 | + $newp[] = $v; |
|
| 2587 | + } else { |
|
| 2588 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2589 | + $t = new Texte(); |
|
| 2590 | + $t->texte = $x; |
|
| 2591 | + $newp[] = [$t]; |
|
| 2592 | + } |
|
| 2593 | + } |
|
| 2594 | + } |
|
| 2595 | + |
|
| 2596 | + return $newp; |
|
| 2597 | 2597 | } |
| 2598 | 2598 | |
| 2599 | 2599 | /** |
@@ -2612,95 +2612,95 @@ discard block |
||
| 2612 | 2612 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2613 | 2613 | **/ |
| 2614 | 2614 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2615 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2616 | - return ''; |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - $boucle = $boucles[$idb]; |
|
| 2620 | - $table = $boucle->show; |
|
| 2621 | - |
|
| 2622 | - // si c'est une colonne de la table, ne rien faire |
|
| 2623 | - if (isset($table['field'][$col])) { |
|
| 2624 | - return ''; |
|
| 2625 | - } |
|
| 2626 | - |
|
| 2627 | - // Le type de critère à prendre en compte |
|
| 2628 | - $col = $regs[1]; |
|
| 2629 | - |
|
| 2630 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2631 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2632 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2633 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2634 | - if (isset($table['field']["date$suite"])) { |
|
| 2635 | - $date_orig = 'date' . $suite; |
|
| 2636 | - } else { |
|
| 2637 | - $date_orig = substr($suite, 1); |
|
| 2638 | - } |
|
| 2639 | - |
|
| 2640 | - $pred = $date_orig; |
|
| 2641 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2642 | - // Si aucune déclaration trouvée, on quitte |
|
| 2643 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2644 | - return ''; |
|
| 2645 | - } |
|
| 2646 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2647 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2648 | - |
|
| 2649 | - // Si c'est pour du relatif |
|
| 2650 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2651 | - $pred = 'date'; |
|
| 2652 | - } |
|
| 2653 | - } |
|
| 2654 | - |
|
| 2655 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2656 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2657 | - ") . '\""; |
|
| 2658 | - |
|
| 2659 | - $col_vraie = $date_orig; |
|
| 2660 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2661 | - |
|
| 2662 | - switch ($col) { |
|
| 2663 | - case 'date': |
|
| 2664 | - $col = $date_orig; |
|
| 2665 | - break; |
|
| 2666 | - case 'jour': |
|
| 2667 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2668 | - break; |
|
| 2669 | - case 'mois': |
|
| 2670 | - $col = "MONTH($date_orig)"; |
|
| 2671 | - break; |
|
| 2672 | - case 'annee': |
|
| 2673 | - $col = "YEAR($date_orig)"; |
|
| 2674 | - break; |
|
| 2675 | - case 'heure': |
|
| 2676 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2677 | - break; |
|
| 2678 | - case 'age': |
|
| 2679 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'age_relatif': |
|
| 2683 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | - break; |
|
| 2686 | - case 'jour_relatif': |
|
| 2687 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2688 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | - break; |
|
| 2690 | - case 'mois_relatif': |
|
| 2691 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2692 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2693 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2694 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2695 | - break; |
|
| 2696 | - case 'annee_relatif': |
|
| 2697 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2698 | - $date_orig . ')'; |
|
| 2699 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2700 | - break; |
|
| 2701 | - } |
|
| 2702 | - |
|
| 2703 | - return [$col, $col_vraie]; |
|
| 2615 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2616 | + return ''; |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + $boucle = $boucles[$idb]; |
|
| 2620 | + $table = $boucle->show; |
|
| 2621 | + |
|
| 2622 | + // si c'est une colonne de la table, ne rien faire |
|
| 2623 | + if (isset($table['field'][$col])) { |
|
| 2624 | + return ''; |
|
| 2625 | + } |
|
| 2626 | + |
|
| 2627 | + // Le type de critère à prendre en compte |
|
| 2628 | + $col = $regs[1]; |
|
| 2629 | + |
|
| 2630 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2631 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2632 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2633 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2634 | + if (isset($table['field']["date$suite"])) { |
|
| 2635 | + $date_orig = 'date' . $suite; |
|
| 2636 | + } else { |
|
| 2637 | + $date_orig = substr($suite, 1); |
|
| 2638 | + } |
|
| 2639 | + |
|
| 2640 | + $pred = $date_orig; |
|
| 2641 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2642 | + // Si aucune déclaration trouvée, on quitte |
|
| 2643 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2644 | + return ''; |
|
| 2645 | + } |
|
| 2646 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2647 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2648 | + |
|
| 2649 | + // Si c'est pour du relatif |
|
| 2650 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2651 | + $pred = 'date'; |
|
| 2652 | + } |
|
| 2653 | + } |
|
| 2654 | + |
|
| 2655 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2656 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2657 | + ") . '\""; |
|
| 2658 | + |
|
| 2659 | + $col_vraie = $date_orig; |
|
| 2660 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2661 | + |
|
| 2662 | + switch ($col) { |
|
| 2663 | + case 'date': |
|
| 2664 | + $col = $date_orig; |
|
| 2665 | + break; |
|
| 2666 | + case 'jour': |
|
| 2667 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2668 | + break; |
|
| 2669 | + case 'mois': |
|
| 2670 | + $col = "MONTH($date_orig)"; |
|
| 2671 | + break; |
|
| 2672 | + case 'annee': |
|
| 2673 | + $col = "YEAR($date_orig)"; |
|
| 2674 | + break; |
|
| 2675 | + case 'heure': |
|
| 2676 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2677 | + break; |
|
| 2678 | + case 'age': |
|
| 2679 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'age_relatif': |
|
| 2683 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2684 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + break; |
|
| 2686 | + case 'jour_relatif': |
|
| 2687 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2688 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2689 | + break; |
|
| 2690 | + case 'mois_relatif': |
|
| 2691 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2692 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2693 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2694 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2695 | + break; |
|
| 2696 | + case 'annee_relatif': |
|
| 2697 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2698 | + $date_orig . ')'; |
|
| 2699 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2700 | + break; |
|
| 2701 | + } |
|
| 2702 | + |
|
| 2703 | + return [$col, $col_vraie]; |
|
| 2704 | 2704 | } |
| 2705 | 2705 | |
| 2706 | 2706 | /** |
@@ -2719,16 +2719,16 @@ discard block |
||
| 2719 | 2719 | * de colonne SQL et une date. |
| 2720 | 2720 | **/ |
| 2721 | 2721 | function calculer_param_date($date_compare, $date_orig) { |
| 2722 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2723 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2724 | - $date_compare = '\'$x\''; |
|
| 2725 | - } else { |
|
| 2726 | - $init = $date_compare; |
|
| 2727 | - } |
|
| 2728 | - |
|
| 2729 | - return |
|
| 2730 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2731 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2722 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2723 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2724 | + $date_compare = '\'$x\''; |
|
| 2725 | + } else { |
|
| 2726 | + $init = $date_compare; |
|
| 2727 | + } |
|
| 2728 | + |
|
| 2729 | + return |
|
| 2730 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2731 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | /** |
@@ -2746,20 +2746,20 @@ discard block |
||
| 2746 | 2746 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2747 | 2747 | */ |
| 2748 | 2748 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2749 | - $boucle = &$boucles[$idb]; |
|
| 2750 | - |
|
| 2751 | - $args = []; |
|
| 2752 | - foreach ($crit->param as &$param) { |
|
| 2753 | - array_push( |
|
| 2754 | - $args, |
|
| 2755 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2756 | - ); |
|
| 2757 | - } |
|
| 2749 | + $boucle = &$boucles[$idb]; |
|
| 2758 | 2750 | |
| 2759 | - $boucle->hash .= ' |
|
| 2751 | + $args = []; |
|
| 2752 | + foreach ($crit->param as &$param) { |
|
| 2753 | + array_push( |
|
| 2754 | + $args, |
|
| 2755 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2756 | + ); |
|
| 2757 | + } |
|
| 2758 | + |
|
| 2759 | + $boucle->hash .= ' |
|
| 2760 | 2760 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2761 | 2761 | |
| 2762 | - $boucle->hash .= ' |
|
| 2762 | + $boucle->hash .= ' |
|
| 2763 | 2763 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2764 | 2764 | } |
| 2765 | 2765 | |
@@ -2777,8 +2777,8 @@ discard block |
||
| 2777 | 2777 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2778 | 2778 | */ |
| 2779 | 2779 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2780 | - $boucle = &$boucles[$idb]; |
|
| 2781 | - $boucle->hash .= ' |
|
| 2780 | + $boucle = &$boucles[$idb]; |
|
| 2781 | + $boucle->hash .= ' |
|
| 2782 | 2782 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2783 | 2783 | } |
| 2784 | 2784 | |
@@ -2794,12 +2794,12 @@ discard block |
||
| 2794 | 2794 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2795 | 2795 | */ |
| 2796 | 2796 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2797 | - $boucle = &$boucles[$idb]; |
|
| 2798 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2799 | - foreach ($crit->param as $param) { |
|
| 2800 | - $boucle->hash .= ' |
|
| 2797 | + $boucle = &$boucles[$idb]; |
|
| 2798 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2799 | + foreach ($crit->param as $param) { |
|
| 2800 | + $boucle->hash .= ' |
|
| 2801 | 2801 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2802 | - } |
|
| 2802 | + } |
|
| 2803 | 2803 | } |
| 2804 | 2804 | |
| 2805 | 2805 | /** |
@@ -2816,16 +2816,16 @@ discard block |
||
| 2816 | 2816 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2817 | 2817 | */ |
| 2818 | 2818 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2819 | - $boucle = &$boucles[$idb]; |
|
| 2820 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2821 | - foreach ($crit->param as $param) { |
|
| 2822 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2823 | - $param, |
|
| 2824 | - $idb, |
|
| 2825 | - $boucles, |
|
| 2826 | - $boucles[$idb]->id_parent |
|
| 2827 | - ) . ";\n"; |
|
| 2828 | - } |
|
| 2819 | + $boucle = &$boucles[$idb]; |
|
| 2820 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2821 | + foreach ($crit->param as $param) { |
|
| 2822 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2823 | + $param, |
|
| 2824 | + $idb, |
|
| 2825 | + $boucles, |
|
| 2826 | + $boucles[$idb]->id_parent |
|
| 2827 | + ) . ";\n"; |
|
| 2828 | + } |
|
| 2829 | 2829 | } |
| 2830 | 2830 | |
| 2831 | 2831 | /** |
@@ -2850,16 +2850,16 @@ discard block |
||
| 2850 | 2850 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2851 | 2851 | */ |
| 2852 | 2852 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2853 | - $boucle = &$boucles[$idb]; |
|
| 2854 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2855 | - foreach ($crit->param as $param) { |
|
| 2856 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2857 | - $param, |
|
| 2858 | - $idb, |
|
| 2859 | - $boucles, |
|
| 2860 | - $boucles[$idb]->id_parent |
|
| 2861 | - ) . ";\n"; |
|
| 2862 | - } |
|
| 2853 | + $boucle = &$boucles[$idb]; |
|
| 2854 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2855 | + foreach ($crit->param as $param) { |
|
| 2856 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2857 | + $param, |
|
| 2858 | + $idb, |
|
| 2859 | + $boucles, |
|
| 2860 | + $boucles[$idb]->id_parent |
|
| 2861 | + ) . ";\n"; |
|
| 2862 | + } |
|
| 2863 | 2863 | } |
| 2864 | 2864 | |
| 2865 | 2865 | /** |
@@ -2874,11 +2874,11 @@ discard block |
||
| 2874 | 2874 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2875 | 2875 | */ |
| 2876 | 2876 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2877 | - $boucle = &$boucles[$idb]; |
|
| 2878 | - foreach ($crit->param as $param) { |
|
| 2879 | - $boucle->hash .= ' |
|
| 2877 | + $boucle = &$boucles[$idb]; |
|
| 2878 | + foreach ($crit->param as $param) { |
|
| 2879 | + $boucle->hash .= ' |
|
| 2880 | 2880 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2881 | - } |
|
| 2881 | + } |
|
| 2882 | 2882 | } |
| 2883 | 2883 | |
| 2884 | 2884 | |
@@ -2910,20 +2910,20 @@ discard block |
||
| 2910 | 2910 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2911 | 2911 | */ |
| 2912 | 2912 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2913 | - $boucle = &$boucles[$idb]; |
|
| 2914 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2915 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2916 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2917 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2918 | - if ($crit->param) { |
|
| 2919 | - foreach ($crit->param as $param) { |
|
| 2920 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2921 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2922 | - } |
|
| 2923 | - // interdire {si 0} aussi ! |
|
| 2924 | - } else { |
|
| 2925 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2926 | - } |
|
| 2913 | + $boucle = &$boucles[$idb]; |
|
| 2914 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2915 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2916 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2917 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2918 | + if ($crit->param) { |
|
| 2919 | + foreach ($crit->param as $param) { |
|
| 2920 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2921 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2922 | + } |
|
| 2923 | + // interdire {si 0} aussi ! |
|
| 2924 | + } else { |
|
| 2925 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2926 | + } |
|
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | 2929 | /** |
@@ -2940,8 +2940,8 @@ discard block |
||
| 2940 | 2940 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2941 | 2941 | */ |
| 2942 | 2942 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2943 | - $boucle = &$boucles[$idb]; |
|
| 2944 | - $boucle->hash .= ' |
|
| 2943 | + $boucle = &$boucles[$idb]; |
|
| 2944 | + $boucle->hash .= ' |
|
| 2945 | 2945 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2946 | 2946 | $command[\'sourcemode\'] = \'table\';'; |
| 2947 | 2947 | } |
@@ -2962,27 +2962,27 @@ discard block |
||
| 2962 | 2962 | */ |
| 2963 | 2963 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2964 | 2964 | |
| 2965 | - $not = $crit->not; |
|
| 2966 | - $boucle = &$boucles[$idb]; |
|
| 2967 | - $primary = $boucle->primary; |
|
| 2965 | + $not = $crit->not; |
|
| 2966 | + $boucle = &$boucles[$idb]; |
|
| 2967 | + $primary = $boucle->primary; |
|
| 2968 | 2968 | |
| 2969 | - if (!$primary or strpos($primary, ',')) { |
|
| 2970 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2969 | + if (!$primary or strpos($primary, ',')) { |
|
| 2970 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2971 | 2971 | |
| 2972 | - return; |
|
| 2973 | - } |
|
| 2974 | - $table = $boucle->type_requete; |
|
| 2975 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2972 | + return; |
|
| 2973 | + } |
|
| 2974 | + $table = $boucle->type_requete; |
|
| 2975 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2976 | 2976 | |
| 2977 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2977 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2978 | 2978 | |
| 2979 | - $in = 'IN'; |
|
| 2980 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2981 | - if ($not) { |
|
| 2982 | - $where = ["'NOT'", $where]; |
|
| 2983 | - } |
|
| 2979 | + $in = 'IN'; |
|
| 2980 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2981 | + if ($not) { |
|
| 2982 | + $where = ["'NOT'", $where]; |
|
| 2983 | + } |
|
| 2984 | 2984 | |
| 2985 | - $boucle->where[] = $where; |
|
| 2985 | + $boucle->where[] = $where; |
|
| 2986 | 2986 | } |
| 2987 | 2987 | |
| 2988 | 2988 | /** |
@@ -2998,8 +2998,8 @@ discard block |
||
| 2998 | 2998 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2999 | 2999 | */ |
| 3000 | 3000 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3001 | - $not = $crit->not; |
|
| 3002 | - $crit->not = $not ? false : true; |
|
| 3003 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3004 | - $crit->not = $not; |
|
| 3001 | + $not = $crit->not; |
|
| 3002 | + $crit->not = $not ? false : true; |
|
| 3003 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3004 | + $crit->not = $not; |
|
| 3005 | 3005 | } |
@@ -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 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } else { |
| 81 | 81 | // Preparer l'appel de la fonction principale du squelette |
| 82 | 82 | |
| 83 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 83 | + spip_timer($a = 'calcul page '.random_int(0, 1000)); |
|
| 84 | 84 | |
| 85 | 85 | // On cree un marqueur de notes unique lie a cette composition |
| 86 | 86 | // et on enregistre l'etat courant des globales de notes... |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | try { |
| 113 | 113 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 114 | 114 | } catch (Throwable $e) { |
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 116 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 117 | 117 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 118 | 118 | $corps = "<pre>$msg</pre>"; |
| 119 | 119 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $profile = spip_timer($a); |
| 146 | 146 | spip_log("calcul ($profile) [$skel] $infos" |
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 148 | 148 | |
| 149 | 149 | if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
| 150 | 150 | spip_log("calcul ($profile) [$skel] $infos" |
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | + . ' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($debug) { |
| 155 | 155 | // si c'est ce que demande le debusqueur, lui passer la main |
| 156 | 156 | $t = strlen($page['texte']) ? $page['texte'] : ' '; |
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 158 | 158 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 159 | 159 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 160 | 160 | if ( |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 189 | 189 | . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | $val = ''; |
| 223 | 223 | } elseif (is_array($val)) { |
| 224 | 224 | if ($profondeur_max > 0) { |
| 225 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 225 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 226 | 226 | } else { |
| 227 | - $val = 'array:' . count($val); |
|
| 227 | + $val = 'array:'.count($val); |
|
| 228 | 228 | } |
| 229 | 229 | } elseif (is_object($val)) { |
| 230 | 230 | $val = get_class($val); |
| 231 | 231 | } elseif (strlen("$val") > 30) { |
| 232 | - $val = substr("$val", 0, 29) . '…'; |
|
| 232 | + $val = substr("$val", 0, 29).'…'; |
|
| 233 | 233 | if (strstr($val, ' ')) { |
| 234 | 234 | $val = "'$val'"; |
| 235 | 235 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | } elseif (!strlen($val)) { |
| 239 | 239 | $val = "''"; |
| 240 | 240 | } |
| 241 | - $infos[] = $var . '=' . $val; |
|
| 241 | + $infos[] = $var.'='.$val; |
|
| 242 | 242 | } |
| 243 | 243 | return join(', ', $infos); |
| 244 | 244 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 307 | 307 | . texte_script($url) |
| 308 | 308 | . "','',$status);" |
| 309 | - . '?' . '>', |
|
| 309 | + . '?'.'>', |
|
| 310 | 310 | 'process_ins' => 'php', |
| 311 | 311 | 'status' => $status |
| 312 | 312 | ]; |
@@ -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 | include_fichiers_fonctions(); |
@@ -30,177 +30,177 @@ discard block |
||
| 30 | 30 | # En cas d'erreur process_ins est absent et texte est un tableau de 2 chaines |
| 31 | 31 | |
| 32 | 32 | function public_parametrer_dist($fond, $contexte = '', $cache = '', string $connect = '') { |
| 33 | - static $composer, $styliser, $notes = null; |
|
| 34 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 35 | - if ($page) { |
|
| 36 | - return $page; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - if (isset($contexte['lang'])) { |
|
| 40 | - $lang = $contexte['lang']; |
|
| 41 | - } elseif (!isset($lang)) { |
|
| 42 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 46 | - if ($select) { |
|
| 47 | - $select = lang_select($lang); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 51 | - |
|
| 52 | - if (!$styliser) { |
|
| 53 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 54 | - } |
|
| 55 | - [$skel, $mime_type, $gram, $sourcefile] = |
|
| 56 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 57 | - |
|
| 58 | - if ($skel) { |
|
| 59 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 60 | - // (recursion possible a cause des modeles) |
|
| 61 | - if ($debug) { |
|
| 62 | - $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 63 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // charger le squelette en specifiant les langages cibles et source |
|
| 67 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 68 | - |
|
| 69 | - if (!$composer) { |
|
| 70 | - $composer = charger_fonction('composer', 'public'); |
|
| 71 | - } |
|
| 72 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 73 | - } else { |
|
| 74 | - $fonc = ''; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 78 | - $page = $fonc; |
|
| 79 | - } else { |
|
| 80 | - // Preparer l'appel de la fonction principale du squelette |
|
| 81 | - |
|
| 82 | - spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 83 | - |
|
| 84 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 85 | - // et on enregistre l'etat courant des globales de notes... |
|
| 86 | - if (is_null($notes)) { |
|
| 87 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 88 | - } |
|
| 89 | - if ($notes) { |
|
| 90 | - $notes('', 'empiler'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Rajouter d'office ces deux parametres |
|
| 94 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 95 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 96 | - if (!isset($contexte['date'])) { |
|
| 97 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 98 | - $contexte['date_default'] = true; |
|
| 99 | - } else { |
|
| 100 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - if (!isset($contexte['date_redac'])) { |
|
| 104 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 105 | - $contexte['date_redac_default'] = true; |
|
| 106 | - } else { |
|
| 107 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 111 | - try { |
|
| 112 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 113 | - } catch (Throwable $e) { |
|
| 114 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 115 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 116 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 117 | - $corps = "<pre>$msg</pre>"; |
|
| 118 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 119 | - erreur_squelette($full_msg); |
|
| 120 | - unset($msg, $full_msg, $corps); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 124 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 125 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 126 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 127 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 128 | - if ($notes) { |
|
| 129 | - $notes('', 'depiler'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // reinjecter en dynamique la pile des notes |
|
| 133 | - // si il y a des inclure dynamiques |
|
| 134 | - // si la pile n'est pas vide |
|
| 135 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 136 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 137 | - if ($notes) { |
|
| 138 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // spip_log: un joli contexte |
|
| 142 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 143 | - |
|
| 144 | - $profile = spip_timer($a); |
|
| 145 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 146 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | - |
|
| 148 | - if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 149 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 150 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if ($debug) { |
|
| 154 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 155 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 156 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 158 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 159 | - if ( |
|
| 160 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 161 | - and (_request('var_mode_objet') == $fonc) |
|
| 162 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 163 | - ) { |
|
| 164 | - erreur_squelette(); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 168 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 169 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 170 | - // si aucun #CACHE{} spécifié |
|
| 171 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 172 | - // entre public et prive |
|
| 173 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 174 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 175 | - } else { |
|
| 176 | - $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $page['contexte'] = $contexte; |
|
| 181 | - |
|
| 182 | - // faire remonter le fichier source |
|
| 183 | - static $js_inclus = false; |
|
| 184 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 185 | - $page['sourcefile'] = $sourcefile; |
|
| 186 | - $page['texte'] = |
|
| 187 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 189 | - $js_inclus = true; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 193 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 194 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 195 | - unset($GLOBALS['cache_utilise_session']); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if ($select) { |
|
| 200 | - lang_select(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return $page; |
|
| 33 | + static $composer, $styliser, $notes = null; |
|
| 34 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 35 | + if ($page) { |
|
| 36 | + return $page; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + if (isset($contexte['lang'])) { |
|
| 40 | + $lang = $contexte['lang']; |
|
| 41 | + } elseif (!isset($lang)) { |
|
| 42 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 46 | + if ($select) { |
|
| 47 | + $select = lang_select($lang); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 51 | + |
|
| 52 | + if (!$styliser) { |
|
| 53 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 54 | + } |
|
| 55 | + [$skel, $mime_type, $gram, $sourcefile] = |
|
| 56 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 57 | + |
|
| 58 | + if ($skel) { |
|
| 59 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 60 | + // (recursion possible a cause des modeles) |
|
| 61 | + if ($debug) { |
|
| 62 | + $courant = $GLOBALS['debug_objets']['courant'] ?? null; |
|
| 63 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // charger le squelette en specifiant les langages cibles et source |
|
| 67 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 68 | + |
|
| 69 | + if (!$composer) { |
|
| 70 | + $composer = charger_fonction('composer', 'public'); |
|
| 71 | + } |
|
| 72 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 73 | + } else { |
|
| 74 | + $fonc = ''; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 78 | + $page = $fonc; |
|
| 79 | + } else { |
|
| 80 | + // Preparer l'appel de la fonction principale du squelette |
|
| 81 | + |
|
| 82 | + spip_timer($a = 'calcul page ' . random_int(0, 1000)); |
|
| 83 | + |
|
| 84 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 85 | + // et on enregistre l'etat courant des globales de notes... |
|
| 86 | + if (is_null($notes)) { |
|
| 87 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 88 | + } |
|
| 89 | + if ($notes) { |
|
| 90 | + $notes('', 'empiler'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Rajouter d'office ces deux parametres |
|
| 94 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 95 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 96 | + if (!isset($contexte['date'])) { |
|
| 97 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 98 | + $contexte['date_default'] = true; |
|
| 99 | + } else { |
|
| 100 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + if (!isset($contexte['date_redac'])) { |
|
| 104 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 105 | + $contexte['date_redac_default'] = true; |
|
| 106 | + } else { |
|
| 107 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 111 | + try { |
|
| 112 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 113 | + } catch (Throwable $e) { |
|
| 114 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 115 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 116 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 117 | + $corps = "<pre>$msg</pre>"; |
|
| 118 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 119 | + erreur_squelette($full_msg); |
|
| 120 | + unset($msg, $full_msg, $corps); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 124 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 125 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 126 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 127 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 128 | + if ($notes) { |
|
| 129 | + $notes('', 'depiler'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // reinjecter en dynamique la pile des notes |
|
| 133 | + // si il y a des inclure dynamiques |
|
| 134 | + // si la pile n'est pas vide |
|
| 135 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 136 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 137 | + if ($notes) { |
|
| 138 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // spip_log: un joli contexte |
|
| 142 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 143 | + |
|
| 144 | + $profile = spip_timer($a); |
|
| 145 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 146 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | + |
|
| 148 | + if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 149 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 150 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if ($debug) { |
|
| 154 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 155 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 156 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 158 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 159 | + if ( |
|
| 160 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 161 | + and (_request('var_mode_objet') == $fonc) |
|
| 162 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 163 | + ) { |
|
| 164 | + erreur_squelette(); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 168 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 169 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 170 | + // si aucun #CACHE{} spécifié |
|
| 171 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 172 | + // entre public et prive |
|
| 173 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 174 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 175 | + } else { |
|
| 176 | + $page['entetes']['X-Spip-Cache'] = $GLOBALS['delais'] ?? 36000; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $page['contexte'] = $contexte; |
|
| 181 | + |
|
| 182 | + // faire remonter le fichier source |
|
| 183 | + static $js_inclus = false; |
|
| 184 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 185 | + $page['sourcefile'] = $sourcefile; |
|
| 186 | + $page['texte'] = |
|
| 187 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 189 | + $js_inclus = true; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 193 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 194 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 195 | + unset($GLOBALS['cache_utilise_session']); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if ($select) { |
|
| 200 | + lang_select(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return $page; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -209,37 +209,37 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 212 | - $infos = []; |
|
| 213 | - $line = 0; |
|
| 214 | - foreach ($contexte as $var => $val) { |
|
| 215 | - $line++; |
|
| 216 | - if ($max_lines and $max_lines < $line) { |
|
| 217 | - $infos[] = '…'; |
|
| 218 | - break; |
|
| 219 | - } |
|
| 220 | - if ($val === null) { |
|
| 221 | - $val = ''; |
|
| 222 | - } elseif (is_array($val)) { |
|
| 223 | - if ($profondeur_max > 0) { |
|
| 224 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 225 | - } else { |
|
| 226 | - $val = 'array:' . count($val); |
|
| 227 | - } |
|
| 228 | - } elseif (is_object($val)) { |
|
| 229 | - $val = get_class($val); |
|
| 230 | - } elseif (strlen("$val") > 30) { |
|
| 231 | - $val = substr("$val", 0, 29) . '…'; |
|
| 232 | - if (strstr($val, ' ')) { |
|
| 233 | - $val = "'$val'"; |
|
| 234 | - } |
|
| 235 | - } elseif (strstr($val, ' ')) { |
|
| 236 | - $val = "'$val'"; |
|
| 237 | - } elseif (!strlen($val)) { |
|
| 238 | - $val = "''"; |
|
| 239 | - } |
|
| 240 | - $infos[] = $var . '=' . $val; |
|
| 241 | - } |
|
| 242 | - return join(', ', $infos); |
|
| 212 | + $infos = []; |
|
| 213 | + $line = 0; |
|
| 214 | + foreach ($contexte as $var => $val) { |
|
| 215 | + $line++; |
|
| 216 | + if ($max_lines and $max_lines < $line) { |
|
| 217 | + $infos[] = '…'; |
|
| 218 | + break; |
|
| 219 | + } |
|
| 220 | + if ($val === null) { |
|
| 221 | + $val = ''; |
|
| 222 | + } elseif (is_array($val)) { |
|
| 223 | + if ($profondeur_max > 0) { |
|
| 224 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 225 | + } else { |
|
| 226 | + $val = 'array:' . count($val); |
|
| 227 | + } |
|
| 228 | + } elseif (is_object($val)) { |
|
| 229 | + $val = get_class($val); |
|
| 230 | + } elseif (strlen("$val") > 30) { |
|
| 231 | + $val = substr("$val", 0, 29) . '…'; |
|
| 232 | + if (strstr($val, ' ')) { |
|
| 233 | + $val = "'$val'"; |
|
| 234 | + } |
|
| 235 | + } elseif (strstr($val, ' ')) { |
|
| 236 | + $val = "'$val'"; |
|
| 237 | + } elseif (!strlen($val)) { |
|
| 238 | + $val = "''"; |
|
| 239 | + } |
|
| 240 | + $infos[] = $var . '=' . $val; |
|
| 241 | + } |
|
| 242 | + return join(', ', $infos); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -256,11 +256,11 @@ discard block |
||
| 256 | 256 | * @return array|bool |
| 257 | 257 | */ |
| 258 | 258 | function tester_redirection($fond, $contexte, $connect) { |
| 259 | - static $tester_redirection = null; |
|
| 260 | - if (is_null($tester_redirection)) { |
|
| 261 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 262 | - } |
|
| 263 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 259 | + static $tester_redirection = null; |
|
| 260 | + if (is_null($tester_redirection)) { |
|
| 261 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 262 | + } |
|
| 263 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -276,42 +276,42 @@ discard block |
||
| 276 | 276 | * @return array|bool |
| 277 | 277 | */ |
| 278 | 278 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 279 | - if ( |
|
| 280 | - $fond == 'article' |
|
| 281 | - and !empty($contexte['id_article']) |
|
| 282 | - and $id_article = intval($contexte['id_article']) |
|
| 283 | - ) { |
|
| 284 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 285 | - $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 286 | - if (strlen($m)) { |
|
| 287 | - include_spip('inc/texte'); |
|
| 288 | - // les navigateurs pataugent si l'URL est vide |
|
| 289 | - if ($url = virtuel_redirige($m, true)) { |
|
| 290 | - // passer en url absolue car cette redirection pourra |
|
| 291 | - // etre utilisee dans un contexte d'url qui change |
|
| 292 | - // y compris url arbo |
|
| 293 | - $status = 302; |
|
| 294 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 295 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 296 | - } |
|
| 297 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 298 | - include_spip('inc/filtres_mini'); |
|
| 299 | - $url = url_absolue($url); |
|
| 300 | - } |
|
| 301 | - $url = str_replace('&', '&', $url); |
|
| 302 | - |
|
| 303 | - return [ |
|
| 304 | - 'texte' => '<' |
|
| 305 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 306 | - . texte_script($url) |
|
| 307 | - . "','',$status);" |
|
| 308 | - . '?' . '>', |
|
| 309 | - 'process_ins' => 'php', |
|
| 310 | - 'status' => $status |
|
| 311 | - ]; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return false; |
|
| 279 | + if ( |
|
| 280 | + $fond == 'article' |
|
| 281 | + and !empty($contexte['id_article']) |
|
| 282 | + and $id_article = intval($contexte['id_article']) |
|
| 283 | + ) { |
|
| 284 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 285 | + $m = quete_virtuel($id_article, $connect) ?? ''; |
|
| 286 | + if (strlen($m)) { |
|
| 287 | + include_spip('inc/texte'); |
|
| 288 | + // les navigateurs pataugent si l'URL est vide |
|
| 289 | + if ($url = virtuel_redirige($m, true)) { |
|
| 290 | + // passer en url absolue car cette redirection pourra |
|
| 291 | + // etre utilisee dans un contexte d'url qui change |
|
| 292 | + // y compris url arbo |
|
| 293 | + $status = 302; |
|
| 294 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 295 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 296 | + } |
|
| 297 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 298 | + include_spip('inc/filtres_mini'); |
|
| 299 | + $url = url_absolue($url); |
|
| 300 | + } |
|
| 301 | + $url = str_replace('&', '&', $url); |
|
| 302 | + |
|
| 303 | + return [ |
|
| 304 | + 'texte' => '<' |
|
| 305 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 306 | + . texte_script($url) |
|
| 307 | + . "','',$status);" |
|
| 308 | + . '?' . '>', |
|
| 309 | + 'process_ins' => 'php', |
|
| 310 | + 'status' => $status |
|
| 311 | + ]; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return false; |
|
| 317 | 317 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -31,25 +31,25 @@ discard block |
||
| 31 | 31 | * Réparer la base de données |
| 32 | 32 | */ |
| 33 | 33 | function exec_base_repair_dist() { |
| 34 | - $action = null; |
|
| 35 | - $ok = false; |
|
| 36 | - if (!spip_connect()) { |
|
| 37 | - $message = _T('titre_probleme_technique'); |
|
| 38 | - } else { |
|
| 39 | - $version_sql = sql_version(); |
|
| 40 | - if (!$version_sql) { |
|
| 41 | - $message = _T('avis_erreur_connexion_mysql'); |
|
| 42 | - } else { |
|
| 43 | - $message = _T('texte_requetes_echouent'); |
|
| 44 | - $ok = true; |
|
| 45 | - } |
|
| 46 | - $action = _T('texte_tenter_reparation'); |
|
| 47 | - } |
|
| 48 | - if ($ok) { |
|
| 49 | - $admin = charger_fonction('admin', 'inc'); |
|
| 50 | - echo $admin('repair', $action, $message, true); |
|
| 51 | - } else { |
|
| 52 | - include_spip('inc/minipres'); |
|
| 53 | - echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 54 | - } |
|
| 34 | + $action = null; |
|
| 35 | + $ok = false; |
|
| 36 | + if (!spip_connect()) { |
|
| 37 | + $message = _T('titre_probleme_technique'); |
|
| 38 | + } else { |
|
| 39 | + $version_sql = sql_version(); |
|
| 40 | + if (!$version_sql) { |
|
| 41 | + $message = _T('avis_erreur_connexion_mysql'); |
|
| 42 | + } else { |
|
| 43 | + $message = _T('texte_requetes_echouent'); |
|
| 44 | + $ok = true; |
|
| 45 | + } |
|
| 46 | + $action = _T('texte_tenter_reparation'); |
|
| 47 | + } |
|
| 48 | + if ($ok) { |
|
| 49 | + $admin = charger_fonction('admin', 'inc'); |
|
| 50 | + echo $admin('repair', $action, $message, true); |
|
| 51 | + } else { |
|
| 52 | + include_spip('inc/minipres'); |
|
| 53 | + echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -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 | |
@@ -28,29 +28,29 @@ discard block |
||
| 28 | 28 | * Demander à mettre à jour la base de données |
| 29 | 29 | */ |
| 30 | 30 | function exec_demande_mise_a_jour_dist() { |
| 31 | - // on fait la verif du path avant tout, |
|
| 32 | - // et l'installation des qu'on est dans la colonne principale |
|
| 33 | - // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 34 | - // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 35 | - include_spip('inc/plugin'); |
|
| 36 | - if (actualise_plugins_actifs()) { |
|
| 37 | - include_spip('inc/headers'); |
|
| 38 | - redirige_par_entete(self()); |
|
| 39 | - } |
|
| 31 | + // on fait la verif du path avant tout, |
|
| 32 | + // et l'installation des qu'on est dans la colonne principale |
|
| 33 | + // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 34 | + // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 35 | + include_spip('inc/plugin'); |
|
| 36 | + if (actualise_plugins_actifs()) { |
|
| 37 | + include_spip('inc/headers'); |
|
| 38 | + redirige_par_entete(self()); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - include_spip('inc/presentation'); |
|
| 42 | - include_spip('inc/filtres_boites'); |
|
| 43 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 44 | - echo $commencer_page('', '', '', '', true, false, false); |
|
| 41 | + include_spip('inc/presentation'); |
|
| 42 | + include_spip('inc/filtres_boites'); |
|
| 43 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 44 | + echo $commencer_page('', '', '', '', true, false, false); |
|
| 45 | 45 | |
| 46 | - echo debut_grand_cadre(); |
|
| 47 | - echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
|
| 48 | - echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | - '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 50 | - echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
|
| 51 | - echo boite_fermer(); |
|
| 52 | - // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
|
| 53 | - echo '<style type="text/css">#debug-nav {display: none;}</style>'; |
|
| 54 | - echo fin_grand_cadre(); |
|
| 55 | - echo fin_page(); |
|
| 46 | + echo debut_grand_cadre(); |
|
| 47 | + echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
|
| 48 | + echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | + '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 50 | + echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
|
| 51 | + echo boite_fermer(); |
|
| 52 | + // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
|
| 53 | + echo '<style type="text/css">#debug-nav {display: none;}</style>'; |
|
| 54 | + echo fin_grand_cadre(); |
|
| 55 | + echo fin_page(); |
|
| 56 | 56 | } |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | |
| 46 | 46 | echo debut_grand_cadre(); |
| 47 | 47 | echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
| 48 | - echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | - '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 48 | + echo '<p>'._T('info_procedure_maj_version').'</p>', |
|
| 49 | + '<p>'._T('info_administrateur_site_01').'</p>'; |
|
| 50 | 50 | echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
| 51 | 51 | echo boite_fermer(); |
| 52 | 52 | // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
@@ -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 | /** |
@@ -25,25 +25,25 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function exec_404_dist() { |
| 27 | 27 | |
| 28 | - $exec = _request('exec'); |
|
| 28 | + $exec = _request('exec'); |
|
| 29 | 29 | |
| 30 | - $titre = "exec_$exec"; |
|
| 31 | - $navigation = ''; |
|
| 32 | - $extra = ''; |
|
| 30 | + $titre = "exec_$exec"; |
|
| 31 | + $navigation = ''; |
|
| 32 | + $extra = ''; |
|
| 33 | 33 | |
| 34 | - include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini |
|
| 35 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 36 | - echo $commencer_page($titre); |
|
| 34 | + include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini |
|
| 35 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 36 | + echo $commencer_page($titre); |
|
| 37 | 37 | |
| 38 | - echo debut_gauche(); |
|
| 39 | - echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 38 | + echo debut_gauche(); |
|
| 39 | + echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 40 | 40 | |
| 41 | - echo creer_colonne_droite(); |
|
| 42 | - echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 41 | + echo creer_colonne_droite(); |
|
| 42 | + echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 43 | 43 | |
| 44 | - echo debut_droite(); |
|
| 45 | - echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 46 | - echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 44 | + echo debut_droite(); |
|
| 45 | + echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 46 | + echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 47 | 47 | |
| 48 | - echo fin_gauche(), fin_page(); |
|
| 48 | + echo fin_gauche(), fin_page(); |
|
| 49 | 49 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
| 43 | 43 | |
| 44 | 44 | echo debut_droite(); |
| 45 | - echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 45 | + echo "<h1 class='grostitre'>"._T('fichier_introuvable', ['fichier' => $exec]).'</h1>'; |
|
| 46 | 46 | echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
| 47 | 47 | |
| 48 | 48 | echo fin_gauche(), fin_page(); |