@@ -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 | |
@@ -54,84 +54,84 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function balise_LOGO__dist($p) { |
| 56 | 56 | |
| 57 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | - $type = strtolower($regs[1]); |
|
| 59 | - $suite_logo = $regs[2]; |
|
| 60 | - |
|
| 61 | - // cas de #LOGO_SITE_SPIP |
|
| 62 | - if ($type == 'site_spip') { |
|
| 63 | - $type = 'site'; |
|
| 64 | - $_id_objet = "\"'0'\""; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $id_objet = id_table_objet($type); |
|
| 68 | - if (!isset($_id_objet)) { |
|
| 69 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | - $coord = []; |
|
| 74 | - $align = $lien = ''; |
|
| 75 | - $mode_logo = ''; |
|
| 76 | - |
|
| 77 | - if ($p->param and !$p->param[0][0]) { |
|
| 78 | - $params = $p->param[0]; |
|
| 79 | - array_shift($params); |
|
| 80 | - foreach ($params as $a) { |
|
| 81 | - if ($a[0]->type === 'texte') { |
|
| 82 | - $n = $a[0]->texte; |
|
| 83 | - if (is_numeric($n)) { |
|
| 84 | - $coord[] = $n; |
|
| 85 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | - $align = $n; |
|
| 87 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | - $mode_logo = $n; |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | - $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | - |
|
| 99 | - if ($p->etoile === '*') { |
|
| 100 | - include_spip('balise/url_'); |
|
| 101 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | - if ($type == 'document') { |
|
| 106 | - $qconnect = _q($connect); |
|
| 107 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | - if ($fichier) { |
|
| 109 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | - } else { |
|
| 111 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | - } |
|
| 113 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | - if ($p->descr['documents']) { |
|
| 115 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | - . $_id_objet |
|
| 117 | - . ") ? $code : '')"; |
|
| 118 | - } |
|
| 119 | - } elseif ($connect) { |
|
| 120 | - $code = "''"; |
|
| 121 | - spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | - } else { |
|
| 123 | - $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | - if ($coord_x or $coord_y) { |
|
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $p->code = $code; |
|
| 132 | - $p->interdire_scripts = false; |
|
| 133 | - |
|
| 134 | - return $p; |
|
| 57 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | + $type = strtolower($regs[1]); |
|
| 59 | + $suite_logo = $regs[2]; |
|
| 60 | + |
|
| 61 | + // cas de #LOGO_SITE_SPIP |
|
| 62 | + if ($type == 'site_spip') { |
|
| 63 | + $type = 'site'; |
|
| 64 | + $_id_objet = "\"'0'\""; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $id_objet = id_table_objet($type); |
|
| 68 | + if (!isset($_id_objet)) { |
|
| 69 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | + $coord = []; |
|
| 74 | + $align = $lien = ''; |
|
| 75 | + $mode_logo = ''; |
|
| 76 | + |
|
| 77 | + if ($p->param and !$p->param[0][0]) { |
|
| 78 | + $params = $p->param[0]; |
|
| 79 | + array_shift($params); |
|
| 80 | + foreach ($params as $a) { |
|
| 81 | + if ($a[0]->type === 'texte') { |
|
| 82 | + $n = $a[0]->texte; |
|
| 83 | + if (is_numeric($n)) { |
|
| 84 | + $coord[] = $n; |
|
| 85 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | + $align = $n; |
|
| 87 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | + $mode_logo = $n; |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | + $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | + |
|
| 99 | + if ($p->etoile === '*') { |
|
| 100 | + include_spip('balise/url_'); |
|
| 101 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | + if ($type == 'document') { |
|
| 106 | + $qconnect = _q($connect); |
|
| 107 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | + if ($fichier) { |
|
| 109 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | + } else { |
|
| 111 | + $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | + } |
|
| 113 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | + if ($p->descr['documents']) { |
|
| 115 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | + . $_id_objet |
|
| 117 | + . ") ? $code : '')"; |
|
| 118 | + } |
|
| 119 | + } elseif ($connect) { |
|
| 120 | + $code = "''"; |
|
| 121 | + spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | + } else { |
|
| 123 | + $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | + if ($coord_x or $coord_y) { |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $p->code = $code; |
|
| 132 | + $p->interdire_scripts = false; |
|
| 133 | + |
|
| 134 | + return $p; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 165 | - (($suite == '_RUBRIQUE') ? |
|
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 169 | - |
|
| 170 | - if ($fichier) { |
|
| 171 | - return $code; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $align = preg_replace(',\W,', '', $align); |
|
| 175 | - |
|
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 161 | + $code = "quete_logo('$id_objet', '" . |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : |
|
| 163 | + (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | + "', $_id_objet," . |
|
| 165 | + (($suite == '_RUBRIQUE') ? |
|
| 166 | + champ_sql('id_rubrique', $p) : |
|
| 167 | + (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | + ', ' . intval($fichier) . ')'; |
|
| 169 | + |
|
| 170 | + if ($fichier) { |
|
| 171 | + return $code; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $align = preg_replace(',\W,', '', $align); |
|
| 175 | + |
|
| 176 | + return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 177 | 177 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | if ($fichier) { |
| 109 | 109 | $code = "quete_logo_file($doc, $qconnect)"; |
| 110 | 110 | } else { |
| 111 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 111 | + $code = "quete_logo_document($doc, ".($lien ?: "''").", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | 112 | } |
| 113 | 113 | // (x=non-faux ? y : '') pour affecter x en retournant y |
| 114 | 114 | if ($p->descr['documents']) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
| 127 | 127 | if ($coord_x or $coord_y) { |
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $p->code = $code; |
@@ -158,14 +158,12 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 161 | + $code = "quete_logo('$id_objet', '". |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : (($suite == '_NORMAL') ? 'on' : 'ON')). |
|
| 163 | + "', $_id_objet,". |
|
| 165 | 164 | (($suite == '_RUBRIQUE') ? |
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 165 | + champ_sql('id_rubrique', $p) : (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")). |
|
| 166 | + ', '.intval($fichier).')'; |
|
| 169 | 167 | |
| 170 | 168 | if ($fichier) { |
| 171 | 169 | return $code; |
@@ -173,5 +171,5 @@ discard block |
||
| 173 | 171 | |
| 174 | 172 | $align = preg_replace(',\W,', '', $align); |
| 175 | 173 | |
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 174 | + return "quete_html_logo($code, '$align', ".($_lien ?: "''").')'; |
|
| 177 | 175 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = $args[0] ?? ''; |
|
| 55 | + $url = $args[0] ?? ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -73,5 +73,5 @@ |
||
| 73 | 73 | return ''; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url='.rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * - chaîne vide sinon. |
| 73 | 73 | */ |
| 74 | 74 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 75 | - [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | - include_spip('action/inscrire_auteur'); |
|
| 77 | - $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 75 | + [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | + include_spip('action/inscrire_auteur'); |
|
| 77 | + $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 78 | 78 | |
| 79 | - return $mode ? [$mode, $id, $retour] : ''; |
|
| 79 | + return $mode ? [$mode, $id, $retour] : ''; |
|
| 80 | 80 | } |
@@ -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 | } |
@@ -53,8 +53,7 @@ discard block |
||
| 53 | 53 | // (pas glop) |
| 54 | 54 | try { |
| 55 | 55 | switch (is_countable($a) ? count($a) : 0) { |
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 56 | + case 0 : $iter = new $iterateur(); |
|
| 58 | 57 | break; |
| 59 | 58 | case 1: |
| 60 | 59 | $iter = new $iterateur($a[0]); |
@@ -79,10 +78,10 @@ discard block |
||
| 79 | 78 | // chercher la classe d'iterateur |
| 80 | 79 | // IterateurXXX |
| 81 | 80 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 81 | + $class = 'Iterateur'.$iterateur; |
|
| 83 | 82 | if (!class_exists($class)) { |
| 84 | 83 | if ( |
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 84 | + !include_spip('iterateur/'.strtolower($iterateur)) |
|
| 86 | 85 | or !class_exists($class) |
| 87 | 86 | ) { |
| 88 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -210,7 +209,7 @@ discard block |
||
| 210 | 209 | return $this->iter->$nom(); |
| 211 | 210 | } catch (Exception $e) { |
| 212 | 211 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 214 | 213 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 215 | 214 | |
| 216 | 215 | return ''; |
@@ -259,7 +258,7 @@ discard block |
||
| 259 | 258 | // Creer la fonction de filtrage sur $this |
| 260 | 259 | if ($this->filtre) { |
| 261 | 260 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 261 | + $filtres = 'return '.$filtres.';'; |
|
| 263 | 262 | $this->func_filtre = fn() => eval($filtres); |
| 264 | 263 | } |
| 265 | 264 | else { |
@@ -294,7 +293,7 @@ discard block |
||
| 294 | 293 | return null; |
| 295 | 294 | } |
| 296 | 295 | |
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 296 | + return '('.implode(") $operateur (", $filtres_string).')'; |
|
| 298 | 297 | } |
| 299 | 298 | |
| 300 | 299 | /** |
@@ -375,7 +374,7 @@ discard block |
||
| 375 | 374 | return $this->composer_filtre($v[1], $v[0], $v[2]); |
| 376 | 375 | } |
| 377 | 376 | |
| 378 | - return null; // sera ignore |
|
| 377 | + return null; // sera ignore |
|
| 379 | 378 | } |
| 380 | 379 | |
| 381 | 380 | /** |
@@ -401,28 +400,28 @@ discard block |
||
| 401 | 400 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 402 | 401 | # return; |
| 403 | 402 | |
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 403 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 405 | 404 | |
| 406 | 405 | $filtre = ''; |
| 407 | 406 | |
| 408 | 407 | if ($op == 'REGEXP') { |
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 408 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 410 | 409 | $op = ''; |
| 411 | 410 | } else { |
| 412 | 411 | if ($op == 'LIKE') { |
| 413 | 412 | $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 413 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 415 | 414 | $op = ''; |
| 416 | 415 | } else { |
| 417 | 416 | if ($op == '=') { |
| 418 | 417 | $op = '=='; |
| 419 | 418 | } else { |
| 420 | 419 | if ($op == 'IN') { |
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 420 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 422 | 421 | $op = ''; |
| 423 | 422 | } else { |
| 424 | 423 | if (!in_array($op, ['<', '<=', '>', '>='])) { |
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 424 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 426 | 425 | $op = ''; |
| 427 | 426 | } |
| 428 | 427 | } |
@@ -431,7 +430,7 @@ discard block |
||
| 431 | 430 | } |
| 432 | 431 | |
| 433 | 432 | if ($op) { |
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 433 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 435 | 434 | } |
| 436 | 435 | |
| 437 | 436 | if ($not) { |
@@ -261,8 +261,7 @@ discard block |
||
| 261 | 261 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 262 | 262 | $filtres = 'return ' . $filtres . ';'; |
| 263 | 263 | $this->func_filtre = fn() => eval($filtres); |
| 264 | - } |
|
| 265 | - else { |
|
| 264 | + } else { |
|
| 266 | 265 | $this->func_filtre = null; |
| 267 | 266 | } |
| 268 | 267 | } |
@@ -345,16 +344,14 @@ discard block |
||
| 345 | 344 | $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
| 346 | 345 | if ($v[$k] === null) { |
| 347 | 346 | unset($v[$k]); |
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 347 | + } elseif ($v[$k] === 'true') { |
|
| 350 | 348 | if ($op === 'OR') { |
| 351 | 349 | return 'true'; |
| 352 | 350 | } |
| 353 | 351 | if ($op === 'AND') { |
| 354 | 352 | unset($v[$k]); |
| 355 | 353 | } |
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 354 | + } elseif ($v[$k] === 'false') { |
|
| 358 | 355 | if ($op === 'OR') { |
| 359 | 356 | unset($v[$k]); |
| 360 | 357 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,667 +21,667 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - $iter = null; |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = $command['args'] ?? []; |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if ( |
|
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | - or !class_exists($class) |
|
| 87 | - ) { |
|
| 88 | - die("Iterateur $iterateur non trouvé"); |
|
| 89 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | - # $iter = new EmptyIterator(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $iter = new $class($command, $info); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return new IterDecorator($iter, $command, $info); |
|
| 97 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + $iter = null; |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = $command['args'] ?? []; |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = 'Iterateur' . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if ( |
|
| 85 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | + or !class_exists($class) |
|
| 87 | + ) { |
|
| 88 | + die("Iterateur $iterateur non trouvé"); |
|
| 89 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | + # $iter = new EmptyIterator(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $iter = new $class($command, $info); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return new IterDecorator($iter, $command, $info); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | class IterDecorator extends FilterIterator { |
| 102 | - private $iter; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Conditions de filtrage |
|
| 106 | - * ie criteres de selection |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $filtre = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $func_filtre = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Critere {offset, limit} |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - * @var int |
|
| 124 | - */ |
|
| 125 | - protected $offset = null; |
|
| 126 | - protected $limit = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * nombre d'elements recuperes depuis la position 0, |
|
| 130 | - * en tenant compte des filtres |
|
| 131 | - * |
|
| 132 | - * @var int |
|
| 133 | - */ |
|
| 134 | - protected $fetched = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Y a t'il une erreur ? |
|
| 138 | - * |
|
| 139 | - * @var bool |
|
| 140 | - **/ |
|
| 141 | - protected $err = false; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Drapeau a activer en cas d'echec |
|
| 145 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | - */ |
|
| 147 | - public function err() { |
|
| 148 | - if (method_exists($this->iter, 'err')) { |
|
| 149 | - return $this->iter->err(); |
|
| 150 | - } |
|
| 151 | - if (property_exists($this->iter, 'err')) { |
|
| 152 | - return $this->iter->err; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | - parent::__construct($iter); |
|
| 160 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | - |
|
| 162 | - // recuperer l'iterateur transmis |
|
| 163 | - $this->iter = $this->getInnerIterator(); |
|
| 164 | - $this->command = $command; |
|
| 165 | - $this->info = $info; |
|
| 166 | - $this->pos = 0; |
|
| 167 | - $this->fetched = 0; |
|
| 168 | - |
|
| 169 | - // chercher la liste des champs a retourner par |
|
| 170 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | - $this->calculer_select(); |
|
| 173 | - $this->calculer_filtres(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | - if (isset($this->iter->err)) { |
|
| 178 | - $this->err = $this->iter->err; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | - //$this->total = $this->count(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - // calcule les elements a retournes par fetch() |
|
| 187 | - // enleve les elements inutiles du select() |
|
| 188 | - // |
|
| 189 | - private function calculer_select() { |
|
| 190 | - if ($select = &$this->command['select']) { |
|
| 191 | - foreach ($select as $s) { |
|
| 192 | - // /!\ $s = '.nom' |
|
| 193 | - if ($s[0] == '.') { |
|
| 194 | - $s = substr($s, 1); |
|
| 195 | - } |
|
| 196 | - $this->select[] = $s; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // recuperer la valeur d'une balise #X |
|
| 202 | - // en fonction des methodes |
|
| 203 | - // et proprietes disponibles |
|
| 204 | - public function get_select($nom) { |
|
| 205 | - if ( |
|
| 206 | - is_object($this->iter) |
|
| 207 | - and method_exists($this->iter, $nom) |
|
| 208 | - ) { |
|
| 209 | - try { |
|
| 210 | - return $this->iter->$nom(); |
|
| 211 | - } catch (Exception $e) { |
|
| 212 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - /* |
|
| 102 | + private $iter; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Conditions de filtrage |
|
| 106 | + * ie criteres de selection |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $filtre = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $func_filtre = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Critere {offset, limit} |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + * @var int |
|
| 124 | + */ |
|
| 125 | + protected $offset = null; |
|
| 126 | + protected $limit = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * nombre d'elements recuperes depuis la position 0, |
|
| 130 | + * en tenant compte des filtres |
|
| 131 | + * |
|
| 132 | + * @var int |
|
| 133 | + */ |
|
| 134 | + protected $fetched = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Y a t'il une erreur ? |
|
| 138 | + * |
|
| 139 | + * @var bool |
|
| 140 | + **/ |
|
| 141 | + protected $err = false; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Drapeau a activer en cas d'echec |
|
| 145 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | + */ |
|
| 147 | + public function err() { |
|
| 148 | + if (method_exists($this->iter, 'err')) { |
|
| 149 | + return $this->iter->err(); |
|
| 150 | + } |
|
| 151 | + if (property_exists($this->iter, 'err')) { |
|
| 152 | + return $this->iter->err; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | + parent::__construct($iter); |
|
| 160 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | + |
|
| 162 | + // recuperer l'iterateur transmis |
|
| 163 | + $this->iter = $this->getInnerIterator(); |
|
| 164 | + $this->command = $command; |
|
| 165 | + $this->info = $info; |
|
| 166 | + $this->pos = 0; |
|
| 167 | + $this->fetched = 0; |
|
| 168 | + |
|
| 169 | + // chercher la liste des champs a retourner par |
|
| 170 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | + $this->calculer_select(); |
|
| 173 | + $this->calculer_filtres(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | + if (isset($this->iter->err)) { |
|
| 178 | + $this->err = $this->iter->err; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | + //$this->total = $this->count(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + // calcule les elements a retournes par fetch() |
|
| 187 | + // enleve les elements inutiles du select() |
|
| 188 | + // |
|
| 189 | + private function calculer_select() { |
|
| 190 | + if ($select = &$this->command['select']) { |
|
| 191 | + foreach ($select as $s) { |
|
| 192 | + // /!\ $s = '.nom' |
|
| 193 | + if ($s[0] == '.') { |
|
| 194 | + $s = substr($s, 1); |
|
| 195 | + } |
|
| 196 | + $this->select[] = $s; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // recuperer la valeur d'une balise #X |
|
| 202 | + // en fonction des methodes |
|
| 203 | + // et proprietes disponibles |
|
| 204 | + public function get_select($nom) { |
|
| 205 | + if ( |
|
| 206 | + is_object($this->iter) |
|
| 207 | + and method_exists($this->iter, $nom) |
|
| 208 | + ) { |
|
| 209 | + try { |
|
| 210 | + return $this->iter->$nom(); |
|
| 211 | + } catch (Exception $e) { |
|
| 212 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + /* |
|
| 220 | 220 | if (property_exists($this->iter, $nom)) { |
| 221 | 221 | return $this->iter->$nom; |
| 222 | 222 | }*/ |
| 223 | - // cle et valeur par defaut |
|
| 224 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | - if ( |
|
| 226 | - in_array($nom, ['cle', 'valeur']) |
|
| 227 | - and method_exists($this, $nom) |
|
| 228 | - ) { |
|
| 229 | - return $this->$nom(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Par defaut chercher en xpath dans la valeur() |
|
| 233 | - return table_valeur($this->valeur(), $nom, null); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - private function calculer_filtres() { |
|
| 238 | - |
|
| 239 | - // Issu de calculer_select() de public/composer L.519 |
|
| 240 | - // TODO: externaliser... |
|
| 241 | - // |
|
| 242 | - // retirer les criteres vides: |
|
| 243 | - // {X ?} avec X absent de l'URL |
|
| 244 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | - if ($where = &$this->command['where']) { |
|
| 247 | - foreach ($where as $k => $v) { |
|
| 248 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // critere {2,7} |
|
| 253 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | - $limit = explode(',', $this->command['limit']); |
|
| 255 | - $this->offset = $limit[0]; |
|
| 256 | - $this->limit = $limit[1]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Creer la fonction de filtrage sur $this |
|
| 260 | - if ($this->filtre) { |
|
| 261 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 263 | - $this->func_filtre = fn() => eval($filtres); |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $this->func_filtre = null; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | - * les filtres vides ou null sont ignores |
|
| 274 | - * @param $filtres |
|
| 275 | - * @param string $operateur |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | - |
|
| 280 | - $filtres_string = []; |
|
| 281 | - foreach ($filtres as $k => $v) { |
|
| 282 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | - $op = array_shift($v); |
|
| 285 | - $v = $this->assembler_filtres($v, $op); |
|
| 286 | - } |
|
| 287 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $filtres_string[] = $v; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!count($filtres_string)) { |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Traduire un element du tableau where SQL en un filtre |
|
| 302 | - * @param $v |
|
| 303 | - * @return string|array|null |
|
| 304 | - */ |
|
| 305 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | - if (is_array($v)) { |
|
| 307 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | - return 'true'; |
|
| 309 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | - return 'true'; |
|
| 311 | - } else { |
|
| 312 | - $op = $v[0] ?: $v; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $op = $v; |
|
| 316 | - } |
|
| 317 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | - return 'true'; |
|
| 319 | - } |
|
| 320 | - if ($op === '0=1') { |
|
| 321 | - return 'false'; |
|
| 322 | - } |
|
| 323 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // 3 possibilites : count($v) = |
|
| 329 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | - |
|
| 333 | - // 1 : forcement traite par un critere, on passe |
|
| 334 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | - return null; // sera ignore |
|
| 336 | - } |
|
| 337 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | - } |
|
| 340 | - if (count($v) == 3) { |
|
| 341 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | - array_shift($v); |
|
| 344 | - foreach (array_keys($v) as $k) { |
|
| 345 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | - if ($v[$k] === null) { |
|
| 347 | - unset($v[$k]); |
|
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 350 | - if ($op === 'OR') { |
|
| 351 | - return 'true'; |
|
| 352 | - } |
|
| 353 | - if ($op === 'AND') { |
|
| 354 | - unset($v[$k]); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 358 | - if ($op === 'OR') { |
|
| 359 | - unset($v[$k]); |
|
| 360 | - } |
|
| 361 | - if ($op === 'AND') { |
|
| 362 | - return 'false'; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - if (!count($v)) { |
|
| 367 | - return null; |
|
| 368 | - } |
|
| 369 | - if (count($v) === 1) { |
|
| 370 | - return reset($v); |
|
| 371 | - } |
|
| 372 | - array_unshift($v, $op); |
|
| 373 | - return $v; |
|
| 374 | - } |
|
| 375 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return null; // sera ignore |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Calculer un filtre sur un champ du tableau |
|
| 383 | - * @param $cle |
|
| 384 | - * @param $op |
|
| 385 | - * @param $valeur |
|
| 386 | - * @param false $not |
|
| 387 | - * @return string|null |
|
| 388 | - */ |
|
| 389 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | - |
|
| 401 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | - # return; |
|
| 403 | - |
|
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | - |
|
| 406 | - $filtre = ''; |
|
| 407 | - |
|
| 408 | - if ($op == 'REGEXP') { |
|
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | - $op = ''; |
|
| 411 | - } else { |
|
| 412 | - if ($op == 'LIKE') { |
|
| 413 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | - $op = ''; |
|
| 416 | - } else { |
|
| 417 | - if ($op == '=') { |
|
| 418 | - $op = '=='; |
|
| 419 | - } else { |
|
| 420 | - if ($op == 'IN') { |
|
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | - $op = ''; |
|
| 423 | - } else { |
|
| 424 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | - $op = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($op) { |
|
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($not) { |
|
| 438 | - $filtre = "!($filtre)"; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return $filtre; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - public function next(): void { |
|
| 446 | - $this->pos++; |
|
| 447 | - parent::next(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * revient au depart |
|
| 452 | - * |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function rewind(): void { |
|
| 456 | - $this->pos = 0; |
|
| 457 | - $this->fetched = 0; |
|
| 458 | - parent::rewind(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - # Extension SPIP des iterateurs PHP |
|
| 463 | - /** |
|
| 464 | - * type de l'iterateur |
|
| 465 | - * |
|
| 466 | - * @var string |
|
| 467 | - */ |
|
| 468 | - protected $type; |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * parametres de l'iterateur |
|
| 472 | - * |
|
| 473 | - * @var array |
|
| 474 | - */ |
|
| 475 | - protected $command; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * infos de compilateur |
|
| 479 | - * |
|
| 480 | - * @var array |
|
| 481 | - */ |
|
| 482 | - protected $info; |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * position courante de l'iterateur |
|
| 486 | - * |
|
| 487 | - * @var int |
|
| 488 | - */ |
|
| 489 | - protected $pos = null; |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * nombre total resultats dans l'iterateur |
|
| 493 | - * |
|
| 494 | - * @var int |
|
| 495 | - */ |
|
| 496 | - protected $total = null; |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * nombre maximal de recherche pour $total |
|
| 500 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | - */ |
|
| 502 | - protected $max = 100000; |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Liste des champs a inserer dans les $row |
|
| 507 | - * retournes par ->fetch() |
|
| 508 | - */ |
|
| 509 | - protected $select = []; |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * aller a la position absolue n, |
|
| 514 | - * comptee depuis le debut |
|
| 515 | - * |
|
| 516 | - * @param int $n |
|
| 517 | - * absolute pos |
|
| 518 | - * @param string $continue |
|
| 519 | - * param for sql_ api |
|
| 520 | - * @return bool |
|
| 521 | - * success or fail if not implemented |
|
| 522 | - */ |
|
| 523 | - public function seek($n = 0, $continue = null) { |
|
| 524 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | - $this->seek_loop($n); |
|
| 526 | - } |
|
| 527 | - $this->pos = $n; |
|
| 528 | - $this->fetched = $n; |
|
| 529 | - |
|
| 530 | - return true; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /* |
|
| 223 | + // cle et valeur par defaut |
|
| 224 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | + if ( |
|
| 226 | + in_array($nom, ['cle', 'valeur']) |
|
| 227 | + and method_exists($this, $nom) |
|
| 228 | + ) { |
|
| 229 | + return $this->$nom(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Par defaut chercher en xpath dans la valeur() |
|
| 233 | + return table_valeur($this->valeur(), $nom, null); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + private function calculer_filtres() { |
|
| 238 | + |
|
| 239 | + // Issu de calculer_select() de public/composer L.519 |
|
| 240 | + // TODO: externaliser... |
|
| 241 | + // |
|
| 242 | + // retirer les criteres vides: |
|
| 243 | + // {X ?} avec X absent de l'URL |
|
| 244 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | + if ($where = &$this->command['where']) { |
|
| 247 | + foreach ($where as $k => $v) { |
|
| 248 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // critere {2,7} |
|
| 253 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | + $limit = explode(',', $this->command['limit']); |
|
| 255 | + $this->offset = $limit[0]; |
|
| 256 | + $this->limit = $limit[1]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Creer la fonction de filtrage sur $this |
|
| 260 | + if ($this->filtre) { |
|
| 261 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | + $filtres = 'return ' . $filtres . ';'; |
|
| 263 | + $this->func_filtre = fn() => eval($filtres); |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $this->func_filtre = null; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | + * les filtres vides ou null sont ignores |
|
| 274 | + * @param $filtres |
|
| 275 | + * @param string $operateur |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | + |
|
| 280 | + $filtres_string = []; |
|
| 281 | + foreach ($filtres as $k => $v) { |
|
| 282 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | + $op = array_shift($v); |
|
| 285 | + $v = $this->assembler_filtres($v, $op); |
|
| 286 | + } |
|
| 287 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $filtres_string[] = $v; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!count($filtres_string)) { |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Traduire un element du tableau where SQL en un filtre |
|
| 302 | + * @param $v |
|
| 303 | + * @return string|array|null |
|
| 304 | + */ |
|
| 305 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | + if (is_array($v)) { |
|
| 307 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | + return 'true'; |
|
| 309 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | + return 'true'; |
|
| 311 | + } else { |
|
| 312 | + $op = $v[0] ?: $v; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $op = $v; |
|
| 316 | + } |
|
| 317 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | + return 'true'; |
|
| 319 | + } |
|
| 320 | + if ($op === '0=1') { |
|
| 321 | + return 'false'; |
|
| 322 | + } |
|
| 323 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // 3 possibilites : count($v) = |
|
| 329 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | + |
|
| 333 | + // 1 : forcement traite par un critere, on passe |
|
| 334 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | + return null; // sera ignore |
|
| 336 | + } |
|
| 337 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | + } |
|
| 340 | + if (count($v) == 3) { |
|
| 341 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | + array_shift($v); |
|
| 344 | + foreach (array_keys($v) as $k) { |
|
| 345 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | + if ($v[$k] === null) { |
|
| 347 | + unset($v[$k]); |
|
| 348 | + } |
|
| 349 | + elseif ($v[$k] === 'true') { |
|
| 350 | + if ($op === 'OR') { |
|
| 351 | + return 'true'; |
|
| 352 | + } |
|
| 353 | + if ($op === 'AND') { |
|
| 354 | + unset($v[$k]); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + elseif ($v[$k] === 'false') { |
|
| 358 | + if ($op === 'OR') { |
|
| 359 | + unset($v[$k]); |
|
| 360 | + } |
|
| 361 | + if ($op === 'AND') { |
|
| 362 | + return 'false'; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + if (!count($v)) { |
|
| 367 | + return null; |
|
| 368 | + } |
|
| 369 | + if (count($v) === 1) { |
|
| 370 | + return reset($v); |
|
| 371 | + } |
|
| 372 | + array_unshift($v, $op); |
|
| 373 | + return $v; |
|
| 374 | + } |
|
| 375 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return null; // sera ignore |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Calculer un filtre sur un champ du tableau |
|
| 383 | + * @param $cle |
|
| 384 | + * @param $op |
|
| 385 | + * @param $valeur |
|
| 386 | + * @param false $not |
|
| 387 | + * @return string|null |
|
| 388 | + */ |
|
| 389 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | + |
|
| 401 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | + # return; |
|
| 403 | + |
|
| 404 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | + |
|
| 406 | + $filtre = ''; |
|
| 407 | + |
|
| 408 | + if ($op == 'REGEXP') { |
|
| 409 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | + $op = ''; |
|
| 411 | + } else { |
|
| 412 | + if ($op == 'LIKE') { |
|
| 413 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | + $op = ''; |
|
| 416 | + } else { |
|
| 417 | + if ($op == '=') { |
|
| 418 | + $op = '=='; |
|
| 419 | + } else { |
|
| 420 | + if ($op == 'IN') { |
|
| 421 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | + $op = ''; |
|
| 423 | + } else { |
|
| 424 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | + $op = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($op) { |
|
| 434 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($not) { |
|
| 438 | + $filtre = "!($filtre)"; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return $filtre; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + public function next(): void { |
|
| 446 | + $this->pos++; |
|
| 447 | + parent::next(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * revient au depart |
|
| 452 | + * |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function rewind(): void { |
|
| 456 | + $this->pos = 0; |
|
| 457 | + $this->fetched = 0; |
|
| 458 | + parent::rewind(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + # Extension SPIP des iterateurs PHP |
|
| 463 | + /** |
|
| 464 | + * type de l'iterateur |
|
| 465 | + * |
|
| 466 | + * @var string |
|
| 467 | + */ |
|
| 468 | + protected $type; |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * parametres de l'iterateur |
|
| 472 | + * |
|
| 473 | + * @var array |
|
| 474 | + */ |
|
| 475 | + protected $command; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * infos de compilateur |
|
| 479 | + * |
|
| 480 | + * @var array |
|
| 481 | + */ |
|
| 482 | + protected $info; |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * position courante de l'iterateur |
|
| 486 | + * |
|
| 487 | + * @var int |
|
| 488 | + */ |
|
| 489 | + protected $pos = null; |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * nombre total resultats dans l'iterateur |
|
| 493 | + * |
|
| 494 | + * @var int |
|
| 495 | + */ |
|
| 496 | + protected $total = null; |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * nombre maximal de recherche pour $total |
|
| 500 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | + */ |
|
| 502 | + protected $max = 100000; |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Liste des champs a inserer dans les $row |
|
| 507 | + * retournes par ->fetch() |
|
| 508 | + */ |
|
| 509 | + protected $select = []; |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * aller a la position absolue n, |
|
| 514 | + * comptee depuis le debut |
|
| 515 | + * |
|
| 516 | + * @param int $n |
|
| 517 | + * absolute pos |
|
| 518 | + * @param string $continue |
|
| 519 | + * param for sql_ api |
|
| 520 | + * @return bool |
|
| 521 | + * success or fail if not implemented |
|
| 522 | + */ |
|
| 523 | + public function seek($n = 0, $continue = null) { |
|
| 524 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | + $this->seek_loop($n); |
|
| 526 | + } |
|
| 527 | + $this->pos = $n; |
|
| 528 | + $this->fetched = $n; |
|
| 529 | + |
|
| 530 | + return true; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /* |
|
| 534 | 534 | * aller a la position $n en parcourant |
| 535 | 535 | * un par un tous les elements |
| 536 | 536 | */ |
| 537 | - private function seek_loop($n) { |
|
| 538 | - if ($this->pos > $n) { |
|
| 539 | - $this->rewind(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - while ($this->pos < $n and $this->valid()) { |
|
| 543 | - $this->next(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Avancer de $saut pas |
|
| 551 | - * |
|
| 552 | - * @param $saut |
|
| 553 | - * @param $max |
|
| 554 | - * @return int |
|
| 555 | - */ |
|
| 556 | - public function skip($saut, $max = null) { |
|
| 557 | - // pas de saut en arriere autorise pour cette fonction |
|
| 558 | - if (($saut = intval($saut)) <= 0) { |
|
| 559 | - return $this->pos; |
|
| 560 | - } |
|
| 561 | - $seek = $this->pos + $saut; |
|
| 562 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | - // et on sort |
|
| 564 | - if (is_null($max)) { |
|
| 565 | - $max = $this->count(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | - $this->free(); |
|
| 571 | - |
|
| 572 | - return $max; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $this->seek($seek); |
|
| 576 | - |
|
| 577 | - return $this->pos; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Renvoyer un tableau des donnees correspondantes |
|
| 582 | - * a la position courante de l'iterateur |
|
| 583 | - * en controlant si on respecte le filtre |
|
| 584 | - * Appliquer aussi le critere {offset,limit} |
|
| 585 | - * |
|
| 586 | - * @return array|bool |
|
| 587 | - */ |
|
| 588 | - public function fetch() { |
|
| 589 | - if (method_exists($this->iter, 'fetch')) { |
|
| 590 | - return $this->iter->fetch(); |
|
| 591 | - } else { |
|
| 592 | - while ( |
|
| 593 | - $this->valid() |
|
| 594 | - and ( |
|
| 595 | - !$this->accept() |
|
| 596 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->next(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if (!$this->valid()) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ( |
|
| 607 | - isset($this->limit) |
|
| 608 | - and $this->fetched > $this->offset + $this->limit |
|
| 609 | - ) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $r = []; |
|
| 614 | - foreach ($this->select as $nom) { |
|
| 615 | - $r[$nom] = $this->get_select($nom); |
|
| 616 | - } |
|
| 617 | - $this->next(); |
|
| 618 | - |
|
| 619 | - return $r; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // retourner la cle pour #CLE |
|
| 624 | - public function cle() { |
|
| 625 | - return $this->key(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // retourner la valeur pour #VALEUR |
|
| 629 | - public function valeur() { |
|
| 630 | - return $this->current(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Accepte-t-on l'entree courante lue ? |
|
| 635 | - * On execute les filtres pour le savoir. |
|
| 636 | - **/ |
|
| 637 | - public function accept(): bool { |
|
| 638 | - if ($f = $this->func_filtre) { |
|
| 639 | - return $f(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * liberer la ressource |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function free() { |
|
| 651 | - if (method_exists($this->iter, 'free')) { |
|
| 652 | - $this->iter->free(); |
|
| 653 | - } |
|
| 654 | - $this->pos = $this->total = 0; |
|
| 655 | - |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Compter le nombre total de resultats |
|
| 661 | - * pour #TOTAL_BOUCLE |
|
| 662 | - * |
|
| 663 | - * @return int |
|
| 664 | - */ |
|
| 665 | - public function count() { |
|
| 666 | - if (is_null($this->total)) { |
|
| 667 | - if ( |
|
| 668 | - method_exists($this->iter, 'count') |
|
| 669 | - and !$this->func_filtre |
|
| 670 | - ) { |
|
| 671 | - return $this->total = $this->iter->count(); |
|
| 672 | - } else { |
|
| 673 | - // compter les lignes et rembobiner |
|
| 674 | - $total = 0; |
|
| 675 | - $pos = $this->pos; // sauver la position |
|
| 676 | - $this->rewind(); |
|
| 677 | - while ($this->fetch() and $total < $this->max) { |
|
| 678 | - $total++; |
|
| 679 | - } |
|
| 680 | - $this->seek($pos); |
|
| 681 | - $this->total = $total; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $this->total; |
|
| 686 | - } |
|
| 537 | + private function seek_loop($n) { |
|
| 538 | + if ($this->pos > $n) { |
|
| 539 | + $this->rewind(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + while ($this->pos < $n and $this->valid()) { |
|
| 543 | + $this->next(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Avancer de $saut pas |
|
| 551 | + * |
|
| 552 | + * @param $saut |
|
| 553 | + * @param $max |
|
| 554 | + * @return int |
|
| 555 | + */ |
|
| 556 | + public function skip($saut, $max = null) { |
|
| 557 | + // pas de saut en arriere autorise pour cette fonction |
|
| 558 | + if (($saut = intval($saut)) <= 0) { |
|
| 559 | + return $this->pos; |
|
| 560 | + } |
|
| 561 | + $seek = $this->pos + $saut; |
|
| 562 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | + // et on sort |
|
| 564 | + if (is_null($max)) { |
|
| 565 | + $max = $this->count(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | + $this->free(); |
|
| 571 | + |
|
| 572 | + return $max; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->seek($seek); |
|
| 576 | + |
|
| 577 | + return $this->pos; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Renvoyer un tableau des donnees correspondantes |
|
| 582 | + * a la position courante de l'iterateur |
|
| 583 | + * en controlant si on respecte le filtre |
|
| 584 | + * Appliquer aussi le critere {offset,limit} |
|
| 585 | + * |
|
| 586 | + * @return array|bool |
|
| 587 | + */ |
|
| 588 | + public function fetch() { |
|
| 589 | + if (method_exists($this->iter, 'fetch')) { |
|
| 590 | + return $this->iter->fetch(); |
|
| 591 | + } else { |
|
| 592 | + while ( |
|
| 593 | + $this->valid() |
|
| 594 | + and ( |
|
| 595 | + !$this->accept() |
|
| 596 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->next(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if (!$this->valid()) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ( |
|
| 607 | + isset($this->limit) |
|
| 608 | + and $this->fetched > $this->offset + $this->limit |
|
| 609 | + ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $r = []; |
|
| 614 | + foreach ($this->select as $nom) { |
|
| 615 | + $r[$nom] = $this->get_select($nom); |
|
| 616 | + } |
|
| 617 | + $this->next(); |
|
| 618 | + |
|
| 619 | + return $r; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // retourner la cle pour #CLE |
|
| 624 | + public function cle() { |
|
| 625 | + return $this->key(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // retourner la valeur pour #VALEUR |
|
| 629 | + public function valeur() { |
|
| 630 | + return $this->current(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Accepte-t-on l'entree courante lue ? |
|
| 635 | + * On execute les filtres pour le savoir. |
|
| 636 | + **/ |
|
| 637 | + public function accept(): bool { |
|
| 638 | + if ($f = $this->func_filtre) { |
|
| 639 | + return $f(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * liberer la ressource |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function free() { |
|
| 651 | + if (method_exists($this->iter, 'free')) { |
|
| 652 | + $this->iter->free(); |
|
| 653 | + } |
|
| 654 | + $this->pos = $this->total = 0; |
|
| 655 | + |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Compter le nombre total de resultats |
|
| 661 | + * pour #TOTAL_BOUCLE |
|
| 662 | + * |
|
| 663 | + * @return int |
|
| 664 | + */ |
|
| 665 | + public function count() { |
|
| 666 | + if (is_null($this->total)) { |
|
| 667 | + if ( |
|
| 668 | + method_exists($this->iter, 'count') |
|
| 669 | + and !$this->func_filtre |
|
| 670 | + ) { |
|
| 671 | + return $this->total = $this->iter->count(); |
|
| 672 | + } else { |
|
| 673 | + // compter les lignes et rembobiner |
|
| 674 | + $total = 0; |
|
| 675 | + $pos = $this->pos; // sauver la position |
|
| 676 | + $this->rewind(); |
|
| 677 | + while ($this->fetch() and $total < $this->max) { |
|
| 678 | + $total++; |
|
| 679 | + } |
|
| 680 | + $this->seek($pos); |
|
| 681 | + $this->total = $total; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $this->total; |
|
| 686 | + } |
|
| 687 | 687 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return sql_getfetsel( |
| 37 | 37 | 'virtuel', |
| 38 | 38 | 'spip_articles', |
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 39 | + ['id_article='.intval($id_article), "statut='publie'"], |
|
| 40 | 40 | '', |
| 41 | 41 | '', |
| 42 | 42 | '', |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $cache_quete[$connect][$table][$id] = sql_fetsel( |
| 82 | 82 | $cache_quete[$connect][$table]['_select'], |
| 83 | 83 | $table, |
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 84 | + $cache_quete[$connect][$table]['_id'].'='.intval($id), |
|
| 85 | 85 | '', |
| 86 | 86 | '', |
| 87 | 87 | '', |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return |
| 174 | 174 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 175 | 175 | and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 176 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | 177 | : '1=1'; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | and $id_table = reset($objet) |
| 233 | 233 | and $objet = objet_type($id_table) |
| 234 | 234 | ) { |
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 235 | + $w = "$mstatut<>".sql_quote($v); |
|
| 236 | 236 | |
| 237 | 237 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 238 | 238 | // sinon l’auteur en session |
@@ -246,22 +246,22 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 249 | + if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) { |
|
| 250 | 250 | // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
| 251 | 251 | if (!$id_auteur) { |
| 252 | 252 | $where[] = $w; |
| 253 | 253 | } else { |
| 254 | 254 | $primary = id_table_objet($objet); |
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (".sql_get_select( |
|
| 256 | 256 | 'ssss.id_objet', |
| 257 | 257 | 'spip_auteurs_liens AS ssss', |
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 258 | + 'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur), |
|
| 259 | 259 | '', |
| 260 | 260 | '', |
| 261 | 261 | '', |
| 262 | 262 | '', |
| 263 | 263 | $serveur |
| 264 | - ) . '))'; |
|
| 264 | + ).'))'; |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } // ignorer ce statut si on ne sait pas comment le filtrer |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document='.intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | // qui permet de distinguer le changement de logo |
| 378 | 378 | // et placer un expire sur le dossier IMG/ |
| 379 | 379 | $res = [ |
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 380 | + $on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' '.$taille[3])) |
|
| 383 | 383 | ]; |
| 384 | 384 | $res['src'] = $res[0]; |
| 385 | 385 | $res['logo_on'] = $res[0]; |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if ( |
| 477 | 477 | strcmp($logo, _DIR_PLUGINS) == 0 |
| 478 | 478 | or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE.'prive/') == 0 |
|
| 480 | 480 | ) { |
| 481 | 481 | return $logo; |
| 482 | 482 | } |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $exposer[$m][$type][$principal] = true; |
| 647 | 647 | if ($type == 'id_mot') { |
| 648 | 648 | if (!$parent) { |
| 649 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 649 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect); |
|
| 650 | 650 | } |
| 651 | 651 | if ($parent) { |
| 652 | 652 | $exposer[$m]['id_groupe'][$parent] = true; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,41 +57,41 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, string $connect = '') { |
| 60 | - static $cache_quete = []; |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if ( |
|
| 66 | - !$desc = $trouver_table( |
|
| 67 | - $table, |
|
| 68 | - $connect |
|
| 69 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | - ) { |
|
| 71 | - // pas de parent rubrique, on passe |
|
| 72 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | - } else { |
|
| 74 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | - $cache_quete[$connect][$table]['_select'], |
|
| 83 | - $table, |
|
| 84 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - '', |
|
| 89 | - $connect |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $cache_quete[$connect][$table][$id] ?? null; |
|
| 60 | + static $cache_quete = []; |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if ( |
|
| 66 | + !$desc = $trouver_table( |
|
| 67 | + $table, |
|
| 68 | + $connect |
|
| 69 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 70 | + ) { |
|
| 71 | + // pas de parent rubrique, on passe |
|
| 72 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 73 | + } else { |
|
| 74 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 75 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 76 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 77 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 81 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 82 | + $cache_quete[$connect][$table]['_select'], |
|
| 83 | + $table, |
|
| 84 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + '', |
|
| 89 | + $connect |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $cache_quete[$connect][$table][$id] ?? null; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @return int |
| 109 | 109 | */ |
| 110 | 110 | function quete_parent($id_rubrique, string $connect = '') { |
| 111 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | - return 0; |
|
| 113 | - } |
|
| 114 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 111 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 114 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 115 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | function quete_rubrique($id_article, $serveur) { |
| 131 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 132 | 132 | |
| 133 | - return $id_parent['id_rubrique']; |
|
| 133 | + return $id_parent['id_rubrique']; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | * @return int |
| 145 | 145 | */ |
| 146 | 146 | function quete_profondeur($id, string $connect = '') { |
| 147 | - $n = 0; |
|
| 148 | - while ($id) { |
|
| 149 | - $n++; |
|
| 150 | - $id = quete_parent($id, $connect); |
|
| 151 | - } |
|
| 147 | + $n = 0; |
|
| 148 | + while ($id) { |
|
| 149 | + $n++; |
|
| 150 | + $id = quete_parent($id, $connect); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $n; |
|
| 153 | + return $n; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * Morceau de la requête SQL testant la date |
| 167 | 167 | */ |
| 168 | 168 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 169 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | - return '1=1'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return |
|
| 174 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | - : '1=1'; |
|
| 169 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 170 | + return '1=1'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return |
|
| 174 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 175 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 176 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 177 | + : '1=1'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -194,101 +194,101 @@ discard block |
||
| 194 | 194 | * @return array|string |
| 195 | 195 | */ |
| 196 | 196 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 197 | - static $cond = []; |
|
| 198 | - $key = func_get_args(); |
|
| 199 | - $key = implode('-', $key); |
|
| 200 | - if (isset($cond[$key])) { |
|
| 201 | - return $cond[$key]; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $liste_statuts = $publie; |
|
| 205 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | - $liste_statuts = $previsu; |
|
| 207 | - } |
|
| 208 | - $not = false; |
|
| 209 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | - $not = true; |
|
| 211 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | - } |
|
| 213 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | - if (!strlen($liste_statuts)) { |
|
| 215 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | - $where = []; |
|
| 220 | - foreach ($liste_statuts as $k => $v) { |
|
| 221 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | - // a ceux de l'auteur identifie |
|
| 223 | - if (strpos($v, '/') !== false) { |
|
| 224 | - $v = explode('/', $v); |
|
| 225 | - $filtre = end($v); |
|
| 226 | - $v = reset($v); |
|
| 227 | - $v = preg_replace(',\W,', '', $v); |
|
| 228 | - if ( |
|
| 229 | - $filtre == 'auteur' |
|
| 230 | - and (strpos($mstatut, '.') !== false) |
|
| 231 | - and $objet = explode('.', $mstatut) |
|
| 232 | - and $id_table = reset($objet) |
|
| 233 | - and $objet = objet_type($id_table) |
|
| 234 | - ) { |
|
| 235 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | - |
|
| 237 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | - // sinon l’auteur en session |
|
| 239 | - include_spip('inc/securiser_action'); |
|
| 240 | - if ($desc = decrire_token_previsu()) { |
|
| 241 | - $id_auteur = $desc['id_auteur']; |
|
| 242 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | - } else { |
|
| 245 | - $id_auteur = null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | - if (!$id_auteur) { |
|
| 252 | - $where[] = $w; |
|
| 253 | - } else { |
|
| 254 | - $primary = id_table_objet($objet); |
|
| 255 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | - 'ssss.id_objet', |
|
| 257 | - 'spip_auteurs_liens AS ssss', |
|
| 258 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - '', |
|
| 263 | - $serveur |
|
| 264 | - ) . '))'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | - else { |
|
| 269 | - $v = ''; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // securite |
|
| 273 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | - } |
|
| 275 | - $liste_statuts = array_filter($liste_statuts); |
|
| 276 | - if (count($liste_statuts) == 1) { |
|
| 277 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | - } else { |
|
| 279 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - while (count($where) > 1) { |
|
| 283 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | - $where[] = $and; |
|
| 285 | - } |
|
| 286 | - $cond[$key] = reset($where); |
|
| 287 | - if ($not) { |
|
| 288 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $cond[$key]; |
|
| 197 | + static $cond = []; |
|
| 198 | + $key = func_get_args(); |
|
| 199 | + $key = implode('-', $key); |
|
| 200 | + if (isset($cond[$key])) { |
|
| 201 | + return $cond[$key]; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $liste_statuts = $publie; |
|
| 205 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 206 | + $liste_statuts = $previsu; |
|
| 207 | + } |
|
| 208 | + $not = false; |
|
| 209 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 210 | + $not = true; |
|
| 211 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 212 | + } |
|
| 213 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 214 | + if (!strlen($liste_statuts)) { |
|
| 215 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 219 | + $where = []; |
|
| 220 | + foreach ($liste_statuts as $k => $v) { |
|
| 221 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 222 | + // a ceux de l'auteur identifie |
|
| 223 | + if (strpos($v, '/') !== false) { |
|
| 224 | + $v = explode('/', $v); |
|
| 225 | + $filtre = end($v); |
|
| 226 | + $v = reset($v); |
|
| 227 | + $v = preg_replace(',\W,', '', $v); |
|
| 228 | + if ( |
|
| 229 | + $filtre == 'auteur' |
|
| 230 | + and (strpos($mstatut, '.') !== false) |
|
| 231 | + and $objet = explode('.', $mstatut) |
|
| 232 | + and $id_table = reset($objet) |
|
| 233 | + and $objet = objet_type($id_table) |
|
| 234 | + ) { |
|
| 235 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 236 | + |
|
| 237 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 238 | + // sinon l’auteur en session |
|
| 239 | + include_spip('inc/securiser_action'); |
|
| 240 | + if ($desc = decrire_token_previsu()) { |
|
| 241 | + $id_auteur = $desc['id_auteur']; |
|
| 242 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 243 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 244 | + } else { |
|
| 245 | + $id_auteur = null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 249 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 250 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 251 | + if (!$id_auteur) { |
|
| 252 | + $where[] = $w; |
|
| 253 | + } else { |
|
| 254 | + $primary = id_table_objet($objet); |
|
| 255 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 256 | + 'ssss.id_objet', |
|
| 257 | + 'spip_auteurs_liens AS ssss', |
|
| 258 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + '', |
|
| 263 | + $serveur |
|
| 264 | + ) . '))'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 268 | + else { |
|
| 269 | + $v = ''; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // securite |
|
| 273 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 274 | + } |
|
| 275 | + $liste_statuts = array_filter($liste_statuts); |
|
| 276 | + if (count($liste_statuts) == 1) { |
|
| 277 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 278 | + } else { |
|
| 279 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + while (count($where) > 1) { |
|
| 283 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 284 | + $where[] = $and; |
|
| 285 | + } |
|
| 286 | + $cond[$key] = reset($where); |
|
| 287 | + if ($not) { |
|
| 288 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $cond[$key]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return array|bool|null |
| 300 | 300 | */ |
| 301 | 301 | function quete_fichier($id_document, $serveur = '') { |
| 302 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | * @return array|bool |
| 311 | 311 | */ |
| 312 | 312 | function quete_document($id_document, $serveur = '') { |
| 313 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return array|bool|null |
| 322 | 322 | */ |
| 323 | 323 | function quete_meta($nom, $serveur) { |
| 324 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -347,66 +347,66 @@ discard block |
||
| 347 | 347 | * Retourne soit un tableau, soit le chemin du fichier. |
| 348 | 348 | */ |
| 349 | 349 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 350 | - include_spip('base/objets'); |
|
| 351 | - $nom = strtolower($onoff); |
|
| 352 | - |
|
| 353 | - $cle_objet = id_table_objet($cle_objet); |
|
| 354 | - |
|
| 355 | - while (1) { |
|
| 356 | - $objet = objet_type($cle_objet); |
|
| 357 | - |
|
| 358 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | - |
|
| 360 | - if ($on) { |
|
| 361 | - if ($flag) { |
|
| 362 | - return basename($on['chemin']); |
|
| 363 | - } else { |
|
| 364 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | - |
|
| 366 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | - // alors on ne cherche pas du tout le survol ici |
|
| 369 | - if ($onoff != 'ON') { |
|
| 370 | - $off = ''; |
|
| 371 | - } else { |
|
| 372 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | - // qui permet de distinguer le changement de logo |
|
| 378 | - // et placer un expire sur le dossier IMG/ |
|
| 379 | - $res = [ |
|
| 380 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | - ]; |
|
| 384 | - $res['src'] = $res[0]; |
|
| 385 | - $res['logo_on'] = $res[0]; |
|
| 386 | - $res['logo_off'] = $res[1]; |
|
| 387 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | - |
|
| 390 | - return $res; |
|
| 391 | - } |
|
| 392 | - } else { |
|
| 393 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | - return ''; |
|
| 395 | - } else { |
|
| 396 | - if ($id_rubrique) { |
|
| 397 | - $cle_objet = 'id_rubrique'; |
|
| 398 | - $id = $id_rubrique; |
|
| 399 | - $id_rubrique = 0; |
|
| 400 | - } else { |
|
| 401 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | - $id = quete_parent($id); |
|
| 403 | - } else { |
|
| 404 | - return ''; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 350 | + include_spip('base/objets'); |
|
| 351 | + $nom = strtolower($onoff); |
|
| 352 | + |
|
| 353 | + $cle_objet = id_table_objet($cle_objet); |
|
| 354 | + |
|
| 355 | + while (1) { |
|
| 356 | + $objet = objet_type($cle_objet); |
|
| 357 | + |
|
| 358 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 359 | + |
|
| 360 | + if ($on) { |
|
| 361 | + if ($flag) { |
|
| 362 | + return basename($on['chemin']); |
|
| 363 | + } else { |
|
| 364 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 365 | + |
|
| 366 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 367 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 368 | + // alors on ne cherche pas du tout le survol ici |
|
| 369 | + if ($onoff != 'ON') { |
|
| 370 | + $off = ''; |
|
| 371 | + } else { |
|
| 372 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 373 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 377 | + // qui permet de distinguer le changement de logo |
|
| 378 | + // et placer un expire sur le dossier IMG/ |
|
| 379 | + $res = [ |
|
| 380 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 381 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 382 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 383 | + ]; |
|
| 384 | + $res['src'] = $res[0]; |
|
| 385 | + $res['logo_on'] = $res[0]; |
|
| 386 | + $res['logo_off'] = $res[1]; |
|
| 387 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 388 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 389 | + |
|
| 390 | + return $res; |
|
| 391 | + } |
|
| 392 | + } else { |
|
| 393 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 394 | + return ''; |
|
| 395 | + } else { |
|
| 396 | + if ($id_rubrique) { |
|
| 397 | + $cle_objet = 'id_rubrique'; |
|
| 398 | + $id = $id_rubrique; |
|
| 399 | + $id_rubrique = 0; |
|
| 400 | + } else { |
|
| 401 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 402 | + $id = quete_parent($id); |
|
| 403 | + } else { |
|
| 404 | + return ''; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -420,37 +420,37 @@ discard block |
||
| 420 | 420 | * "on" ou "off" suivant le logo normal ou survol |
| 421 | 421 | **/ |
| 422 | 422 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 423 | - static $chercher_logo; |
|
| 424 | - if (is_null($chercher_logo)) { |
|
| 425 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | - } |
|
| 427 | - $cle_objet = id_table_objet($objet); |
|
| 428 | - |
|
| 429 | - // On cherche pas la méthode classique |
|
| 430 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | - if (!empty($infos_logo)) { |
|
| 433 | - $infos_logo = [ |
|
| 434 | - 'chemin' => $infos_logo[0], |
|
| 435 | - 'timestamp' => $infos_logo[4], |
|
| 436 | - ]; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // On passe cette recherche de logo dans un pipeline |
|
| 440 | - $infos_logo = pipeline( |
|
| 441 | - 'quete_logo_objet', |
|
| 442 | - [ |
|
| 443 | - 'args' => [ |
|
| 444 | - 'id_objet' => $id_objet, |
|
| 445 | - 'objet' => $objet, |
|
| 446 | - 'cle_objet' => $cle_objet, |
|
| 447 | - 'mode' => $mode, |
|
| 448 | - ], |
|
| 449 | - 'data' => $infos_logo, |
|
| 450 | - ] |
|
| 451 | - ); |
|
| 452 | - |
|
| 453 | - return $infos_logo; |
|
| 423 | + static $chercher_logo; |
|
| 424 | + if (is_null($chercher_logo)) { |
|
| 425 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 426 | + } |
|
| 427 | + $cle_objet = id_table_objet($objet); |
|
| 428 | + |
|
| 429 | + // On cherche pas la méthode classique |
|
| 430 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 431 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 432 | + if (!empty($infos_logo)) { |
|
| 433 | + $infos_logo = [ |
|
| 434 | + 'chemin' => $infos_logo[0], |
|
| 435 | + 'timestamp' => $infos_logo[4], |
|
| 436 | + ]; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // On passe cette recherche de logo dans un pipeline |
|
| 440 | + $infos_logo = pipeline( |
|
| 441 | + 'quete_logo_objet', |
|
| 442 | + [ |
|
| 443 | + 'args' => [ |
|
| 444 | + 'id_objet' => $id_objet, |
|
| 445 | + 'objet' => $objet, |
|
| 446 | + 'cle_objet' => $cle_objet, |
|
| 447 | + 'mode' => $mode, |
|
| 448 | + ], |
|
| 449 | + 'data' => $infos_logo, |
|
| 450 | + ] |
|
| 451 | + ); |
|
| 452 | + |
|
| 453 | + return $infos_logo; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | * @return bool|string |
| 464 | 464 | */ |
| 465 | 465 | function quete_logo_file($row, $connect = null) { |
| 466 | - include_spip('inc/documents'); |
|
| 467 | - $logo = vignette_logo_document($row, $connect); |
|
| 468 | - if (!$logo) { |
|
| 469 | - $logo = image_du_document($row, $connect); |
|
| 470 | - } |
|
| 471 | - if (!$logo) { |
|
| 472 | - $f = charger_fonction('vignette', 'inc'); |
|
| 473 | - $logo = $f($row['extension'], false); |
|
| 474 | - } |
|
| 475 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | - if ( |
|
| 477 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | - ) { |
|
| 481 | - return $logo; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - return get_spip_doc($logo); |
|
| 466 | + include_spip('inc/documents'); |
|
| 467 | + $logo = vignette_logo_document($row, $connect); |
|
| 468 | + if (!$logo) { |
|
| 469 | + $logo = image_du_document($row, $connect); |
|
| 470 | + } |
|
| 471 | + if (!$logo) { |
|
| 472 | + $f = charger_fonction('vignette', 'inc'); |
|
| 473 | + $logo = $f($row['extension'], false); |
|
| 474 | + } |
|
| 475 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 476 | + if ( |
|
| 477 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 478 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 479 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 480 | + ) { |
|
| 481 | + return $logo; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + return get_spip_doc($logo); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -509,20 +509,20 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 511 | 511 | |
| 512 | - include_spip('inc/documents'); |
|
| 513 | - $logo = ''; |
|
| 514 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | - $logo = vignette_logo_document($row, $connect); |
|
| 516 | - } |
|
| 517 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | - return ''; |
|
| 520 | - } |
|
| 521 | - if ($mode_logo == 'icone') { |
|
| 522 | - $row['fichier'] = ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 512 | + include_spip('inc/documents'); |
|
| 513 | + $logo = ''; |
|
| 514 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 515 | + $logo = vignette_logo_document($row, $connect); |
|
| 516 | + } |
|
| 517 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 518 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 519 | + return ''; |
|
| 520 | + } |
|
| 521 | + if ($mode_logo == 'icone') { |
|
| 522 | + $row['fichier'] = ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -534,19 +534,19 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | function quete_html_logo($logo, $align, $lien) { |
| 536 | 536 | |
| 537 | - if (!is_array($logo)) { |
|
| 538 | - return ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - $contexte = []; |
|
| 542 | - foreach ($logo as $k => $v) { |
|
| 543 | - if (!is_numeric($k)) { |
|
| 544 | - $contexte[$k] = $v; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - $contexte['align'] = $align; |
|
| 548 | - $contexte['lien'] = $lien; |
|
| 549 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 537 | + if (!is_array($logo)) { |
|
| 538 | + return ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + $contexte = []; |
|
| 542 | + foreach ($logo as $k => $v) { |
|
| 543 | + if (!is_numeric($k)) { |
|
| 544 | + $contexte[$k] = $v; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + $contexte['align'] = $align; |
|
| 548 | + $contexte['lien'] = $lien; |
|
| 549 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | * @return string|false |
| 561 | 561 | */ |
| 562 | 562 | function document_spip_externe($fichier, $connect) { |
| 563 | - if ($connect) { |
|
| 564 | - $site = quete_meta('adresse_site', $connect); |
|
| 565 | - if ($site) { |
|
| 566 | - $dir = quete_meta('dir_img', $connect); |
|
| 567 | - return "$site/$dir$fichier"; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 563 | + if ($connect) { |
|
| 564 | + $site = quete_meta('adresse_site', $connect); |
|
| 565 | + if ($site) { |
|
| 566 | + $dir = quete_meta('dir_img', $connect); |
|
| 567 | + return "$site/$dir$fichier"; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -581,23 +581,23 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | function vignette_logo_document($row, string $connect = '') { |
| 583 | 583 | |
| 584 | - if (!$row or empty($row['id_vignette'])) { |
|
| 585 | - return ''; |
|
| 586 | - } |
|
| 587 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 588 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 589 | - return $url; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $f = get_spip_doc($fichier); |
|
| 593 | - if ($f and @file_exists($f)) { |
|
| 594 | - return $f; |
|
| 595 | - } |
|
| 596 | - if ($row['mode'] !== 'vignette') { |
|
| 597 | - return ''; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 584 | + if (!$row or empty($row['id_vignette'])) { |
|
| 585 | + return ''; |
|
| 586 | + } |
|
| 587 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 588 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 589 | + return $url; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $f = get_spip_doc($fichier); |
|
| 593 | + if ($f and @file_exists($f)) { |
|
| 594 | + return $f; |
|
| 595 | + } |
|
| 596 | + if ($row['mode'] !== 'vignette') { |
|
| 597 | + return ''; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
@@ -613,66 +613,66 @@ discard block |
||
| 613 | 613 | * @return bool|string |
| 614 | 614 | */ |
| 615 | 615 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 616 | - static $exposer = []; |
|
| 617 | - |
|
| 618 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 619 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 620 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 621 | - // en static. |
|
| 622 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 623 | - $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 624 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 625 | - // il n'est donc pas utile |
|
| 626 | - $parent = 0; |
|
| 627 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 628 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 629 | - if (isset($enfants[$type])) { |
|
| 630 | - foreach ($enfants[$type] as $t) { |
|
| 631 | - if ( |
|
| 632 | - isset($reference[$t]) |
|
| 633 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 634 | - or isset($reference["@$t"]) |
|
| 635 | - ) { |
|
| 636 | - $type = $t; |
|
| 637 | - $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 638 | - continue; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - $exposer[$m][$type] = []; |
|
| 644 | - if ($principal) { |
|
| 645 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 646 | - foreach ($principaux as $principal) { |
|
| 647 | - $exposer[$m][$type][$principal] = true; |
|
| 648 | - if ($type == 'id_mot') { |
|
| 649 | - if (!$parent) { |
|
| 650 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 651 | - } |
|
| 652 | - if ($parent) { |
|
| 653 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 654 | - } |
|
| 655 | - } else { |
|
| 656 | - if ($type != 'id_groupe') { |
|
| 657 | - if (!$parent) { |
|
| 658 | - if ($type == 'id_rubrique') { |
|
| 659 | - $parent = $principal; |
|
| 660 | - } |
|
| 661 | - if ($type == 'id_article') { |
|
| 662 | - $parent = quete_rubrique($principal, $connect); |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - do { |
|
| 666 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 667 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - // And the winner is... |
|
| 675 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 616 | + static $exposer = []; |
|
| 617 | + |
|
| 618 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 619 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 620 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 621 | + // en static. |
|
| 622 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 623 | + $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 624 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 625 | + // il n'est donc pas utile |
|
| 626 | + $parent = 0; |
|
| 627 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 628 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 629 | + if (isset($enfants[$type])) { |
|
| 630 | + foreach ($enfants[$type] as $t) { |
|
| 631 | + if ( |
|
| 632 | + isset($reference[$t]) |
|
| 633 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 634 | + or isset($reference["@$t"]) |
|
| 635 | + ) { |
|
| 636 | + $type = $t; |
|
| 637 | + $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 638 | + continue; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + $exposer[$m][$type] = []; |
|
| 644 | + if ($principal) { |
|
| 645 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 646 | + foreach ($principaux as $principal) { |
|
| 647 | + $exposer[$m][$type][$principal] = true; |
|
| 648 | + if ($type == 'id_mot') { |
|
| 649 | + if (!$parent) { |
|
| 650 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 651 | + } |
|
| 652 | + if ($parent) { |
|
| 653 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 654 | + } |
|
| 655 | + } else { |
|
| 656 | + if ($type != 'id_groupe') { |
|
| 657 | + if (!$parent) { |
|
| 658 | + if ($type == 'id_rubrique') { |
|
| 659 | + $parent = $principal; |
|
| 660 | + } |
|
| 661 | + if ($type == 'id_article') { |
|
| 662 | + $parent = quete_rubrique($principal, $connect); |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + do { |
|
| 666 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 667 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + // And the winner is... |
|
| 675 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -687,23 +687,23 @@ discard block |
||
| 687 | 687 | * @return int |
| 688 | 688 | */ |
| 689 | 689 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 690 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 691 | - // ou composee, mais verifions |
|
| 692 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 693 | - return 0; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $pos = 0; |
|
| 697 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 698 | - $pos++; |
|
| 699 | - } |
|
| 700 | - // si on a pas trouve |
|
| 701 | - if (!$row or $row[$primary] != $valeur) { |
|
| 702 | - return 0; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - // sinon, calculer le bon numero de page |
|
| 706 | - return floor($pos / $pas) * $pas; |
|
| 690 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 691 | + // ou composee, mais verifions |
|
| 692 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 693 | + return 0; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $pos = 0; |
|
| 697 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 698 | + $pos++; |
|
| 699 | + } |
|
| 700 | + // si on a pas trouve |
|
| 701 | + if (!$row or $row[$primary] != $valeur) { |
|
| 702 | + return 0; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + // sinon, calculer le bon numero de page |
|
| 706 | + return floor($pos / $pas) * $pas; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -714,11 +714,11 @@ discard block |
||
| 714 | 714 | * @return boolean |
| 715 | 715 | */ |
| 716 | 716 | function is_whereable($value): bool { |
| 717 | - if (is_array($value) && count($value)) { |
|
| 718 | - return true; |
|
| 719 | - } |
|
| 720 | - if (is_scalar($value) && strlen($value)) { |
|
| 721 | - return true; |
|
| 722 | - } |
|
| 723 | - return false; |
|
| 717 | + if (is_array($value) && count($value)) { |
|
| 718 | + return true; |
|
| 719 | + } |
|
| 720 | + if (is_scalar($value) && strlen($value)) { |
|
| 721 | + return true; |
|
| 722 | + } |
|
| 723 | + return false; |
|
| 724 | 724 | } |
@@ -2071,8 +2071,7 @@ discard block |
||
| 2071 | 2071 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2072 | 2072 | if (@array_key_exists('*', $desc['field'])) { |
| 2073 | 2073 | $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 2074 | - } |
|
| 2075 | - else { |
|
| 2074 | + } else { |
|
| 2076 | 2075 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2077 | 2076 | if (!$r) { |
| 2078 | 2077 | return ''; |
@@ -2115,8 +2114,7 @@ discard block |
||
| 2115 | 2114 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2116 | 2115 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 2117 | 2116 | $val[0] = "sql_quote($r)"; |
| 2118 | - } |
|
| 2119 | - elseif ( |
|
| 2117 | + } elseif ( |
|
| 2120 | 2118 | strpos($val[0], '@@defaultcast@@') !== false |
| 2121 | 2119 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2122 | 2120 | ) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void|array |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void|array |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void|array |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string|array Clause pour le Order by (array si erreur) |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string|array Clause pour le Order by (array si erreur) |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string|array Clause pour le Order by (array si erreur) |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1114,139 +1114,139 @@ discard block |
||
| 1114 | 1114 | * @return void|array |
| 1115 | 1115 | */ |
| 1116 | 1116 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1117 | - $boucle = &$boucles[$idb]; |
|
| 1117 | + $boucle = &$boucles[$idb]; |
|
| 1118 | 1118 | |
| 1119 | - $sens = $collecte = ''; |
|
| 1120 | - if ($crit->not) { |
|
| 1121 | - $sens = " . ' DESC'"; |
|
| 1122 | - } |
|
| 1119 | + $sens = $collecte = ''; |
|
| 1120 | + if ($crit->not) { |
|
| 1121 | + $sens = " . ' DESC'"; |
|
| 1122 | + } |
|
| 1123 | 1123 | |
| 1124 | - $crit2 = clone $crit; |
|
| 1125 | - $crit2->not = false; |
|
| 1126 | - $crit2->param = [reset($crit->param)]; |
|
| 1127 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1124 | + $crit2 = clone $crit; |
|
| 1125 | + $crit2->not = false; |
|
| 1126 | + $crit2->param = [reset($crit->param)]; |
|
| 1127 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1128 | 1128 | |
| 1129 | - // erreur ? |
|
| 1130 | - if (is_array($res)) { |
|
| 1131 | - return $res; |
|
| 1132 | - } |
|
| 1129 | + // erreur ? |
|
| 1130 | + if (is_array($res)) { |
|
| 1131 | + return $res; |
|
| 1132 | + } |
|
| 1133 | 1133 | |
| 1134 | - $_order = array_pop($boucle->order); |
|
| 1134 | + $_order = array_pop($boucle->order); |
|
| 1135 | 1135 | |
| 1136 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1137 | 1137 | |
| 1138 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1139 | - $boucle->order[] = $order; |
|
| 1138 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1139 | + $boucle->order[] = $order; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
| 1143 | 1143 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1144 | - $params = $crit->param; |
|
| 1145 | - |
|
| 1146 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1147 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $boucle = &$boucles[$idb]; |
|
| 1151 | - $parent = $boucle->id_parent; |
|
| 1152 | - $fields = $boucle->show['field']; |
|
| 1153 | - |
|
| 1154 | - $date = array_shift($params); |
|
| 1155 | - $type = array_shift($params); |
|
| 1156 | - |
|
| 1157 | - // la valeur $type doit etre connue a la compilation |
|
| 1158 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1159 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1160 | - |
|
| 1161 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1162 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1163 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1164 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1165 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1166 | - $date = $date[0]->texte; |
|
| 1167 | - if (!isset($fields[$date])) { |
|
| 1168 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1169 | - } |
|
| 1170 | - } else { |
|
| 1171 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1172 | - $noms = array_keys($fields); |
|
| 1173 | - $defaut = $noms[0]; |
|
| 1174 | - $noms = join(' ', $noms); |
|
| 1175 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1176 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1177 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1178 | - } |
|
| 1179 | - $annee = $params ? array_shift($params) : ''; |
|
| 1180 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1182 | - ') ? $x : date("Y"))'; |
|
| 1183 | - |
|
| 1184 | - $mois = $params ? array_shift($params) : ''; |
|
| 1185 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1187 | - ') ? $x : date("m"))'; |
|
| 1188 | - |
|
| 1189 | - $jour = $params ? array_shift($params) : ''; |
|
| 1190 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1192 | - ') ? $x : date("d"))'; |
|
| 1193 | - |
|
| 1194 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1195 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1197 | - ') ? $x : date("Y"))'; |
|
| 1198 | - |
|
| 1199 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1200 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1202 | - ') ? $x : date("m"))'; |
|
| 1203 | - |
|
| 1204 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1205 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1207 | - ') ? $x : date("d"))'; |
|
| 1208 | - |
|
| 1209 | - $date = $boucle->id_table . ".$date"; |
|
| 1210 | - |
|
| 1211 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1212 | - if ($type == 'jour') { |
|
| 1213 | - $boucle->where[] = [ |
|
| 1214 | - "'='", |
|
| 1215 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1217 | - ]; |
|
| 1218 | - } elseif ($type == 'mois') { |
|
| 1219 | - $boucle->where[] = [ |
|
| 1220 | - "'='", |
|
| 1221 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1222 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1223 | - ]; |
|
| 1224 | - } elseif ($type == 'semaine') { |
|
| 1225 | - $boucle->where[] = [ |
|
| 1226 | - "'AND'", |
|
| 1227 | - [ |
|
| 1228 | - "'>='", |
|
| 1229 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1230 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1231 | - ], |
|
| 1232 | - [ |
|
| 1233 | - "'<='", |
|
| 1234 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1235 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1236 | - ] |
|
| 1237 | - ]; |
|
| 1238 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1239 | - $boucle->where[] = [ |
|
| 1240 | - "'AND'", |
|
| 1241 | - [ |
|
| 1242 | - "'>='", |
|
| 1243 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1244 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1245 | - ], |
|
| 1246 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1247 | - ]; |
|
| 1248 | - } |
|
| 1249 | - // sinon on prend tout |
|
| 1144 | + $params = $crit->param; |
|
| 1145 | + |
|
| 1146 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1147 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + $boucle = &$boucles[$idb]; |
|
| 1151 | + $parent = $boucle->id_parent; |
|
| 1152 | + $fields = $boucle->show['field']; |
|
| 1153 | + |
|
| 1154 | + $date = array_shift($params); |
|
| 1155 | + $type = array_shift($params); |
|
| 1156 | + |
|
| 1157 | + // la valeur $type doit etre connue a la compilation |
|
| 1158 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1159 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1160 | + |
|
| 1161 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1162 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1163 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1164 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1165 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1166 | + $date = $date[0]->texte; |
|
| 1167 | + if (!isset($fields[$date])) { |
|
| 1168 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1169 | + } |
|
| 1170 | + } else { |
|
| 1171 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1172 | + $noms = array_keys($fields); |
|
| 1173 | + $defaut = $noms[0]; |
|
| 1174 | + $noms = join(' ', $noms); |
|
| 1175 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1176 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1177 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1178 | + } |
|
| 1179 | + $annee = $params ? array_shift($params) : ''; |
|
| 1180 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1182 | + ') ? $x : date("Y"))'; |
|
| 1183 | + |
|
| 1184 | + $mois = $params ? array_shift($params) : ''; |
|
| 1185 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1187 | + ') ? $x : date("m"))'; |
|
| 1188 | + |
|
| 1189 | + $jour = $params ? array_shift($params) : ''; |
|
| 1190 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1192 | + ') ? $x : date("d"))'; |
|
| 1193 | + |
|
| 1194 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1195 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1197 | + ') ? $x : date("Y"))'; |
|
| 1198 | + |
|
| 1199 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1200 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1202 | + ') ? $x : date("m"))'; |
|
| 1203 | + |
|
| 1204 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1205 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1207 | + ') ? $x : date("d"))'; |
|
| 1208 | + |
|
| 1209 | + $date = $boucle->id_table . ".$date"; |
|
| 1210 | + |
|
| 1211 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1212 | + if ($type == 'jour') { |
|
| 1213 | + $boucle->where[] = [ |
|
| 1214 | + "'='", |
|
| 1215 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1217 | + ]; |
|
| 1218 | + } elseif ($type == 'mois') { |
|
| 1219 | + $boucle->where[] = [ |
|
| 1220 | + "'='", |
|
| 1221 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1222 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1223 | + ]; |
|
| 1224 | + } elseif ($type == 'semaine') { |
|
| 1225 | + $boucle->where[] = [ |
|
| 1226 | + "'AND'", |
|
| 1227 | + [ |
|
| 1228 | + "'>='", |
|
| 1229 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1230 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1231 | + ], |
|
| 1232 | + [ |
|
| 1233 | + "'<='", |
|
| 1234 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1235 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1236 | + ] |
|
| 1237 | + ]; |
|
| 1238 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1239 | + $boucle->where[] = [ |
|
| 1240 | + "'AND'", |
|
| 1241 | + [ |
|
| 1242 | + "'>='", |
|
| 1243 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1244 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1245 | + ], |
|
| 1246 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1247 | + ]; |
|
| 1248 | + } |
|
| 1249 | + // sinon on prend tout |
|
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | |
@@ -1271,33 +1271,33 @@ discard block |
||
| 1271 | 1271 | * @return void |
| 1272 | 1272 | **/ |
| 1273 | 1273 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1274 | - $boucle = &$boucles[$idb]; |
|
| 1275 | - $a1 = $crit->param[0]; |
|
| 1276 | - $a2 = $crit->param[1]; |
|
| 1277 | - $op = $crit->op; |
|
| 1278 | - |
|
| 1279 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1280 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1281 | - |
|
| 1282 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1283 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1284 | - } else { |
|
| 1285 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1286 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1287 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1288 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1289 | - $mode = (($op == '/') ? '/' : |
|
| 1290 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1291 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1292 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1293 | - $boucle->limit = |
|
| 1294 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1295 | - . ".','." |
|
| 1296 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1297 | - } else { |
|
| 1298 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1274 | + $boucle = &$boucles[$idb]; |
|
| 1275 | + $a1 = $crit->param[0]; |
|
| 1276 | + $a2 = $crit->param[1]; |
|
| 1277 | + $op = $crit->op; |
|
| 1278 | + |
|
| 1279 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1280 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1281 | + |
|
| 1282 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1283 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1284 | + } else { |
|
| 1285 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1286 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1287 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1288 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1289 | + $mode = (($op == '/') ? '/' : |
|
| 1290 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1291 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1292 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1293 | + $boucle->limit = |
|
| 1294 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1295 | + . ".','." |
|
| 1296 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1297 | + } else { |
|
| 1298 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | /** |
@@ -1325,63 +1325,63 @@ discard block |
||
| 1325 | 1325 | * @return void |
| 1326 | 1326 | **/ |
| 1327 | 1327 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1328 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1329 | - |
|
| 1330 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1331 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1332 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1333 | - // {1/3} |
|
| 1334 | - if ($op1 == '/') { |
|
| 1335 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1336 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | - "($total_parties ? $total_parties : 1)"; |
|
| 1338 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1339 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1340 | - } else { |
|
| 1341 | - // cas {n-1,x} |
|
| 1342 | - if ($op1 == '-') { |
|
| 1343 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - // cas {x,n-1} |
|
| 1347 | - if ($op2 == '-') { |
|
| 1348 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | - ($total_parties . ' - 1')); |
|
| 1351 | - } else { |
|
| 1352 | - // {x,1} ou {pagination} |
|
| 1353 | - $fin = '$debut_boucle' |
|
| 1354 | - . (is_numeric($total_parties) ? |
|
| 1355 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | - ('+' . $total_parties . ' - 1')); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1360 | - if ($op1 == 'p') { |
|
| 1361 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1362 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1363 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1364 | - } |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - // Notes : |
|
| 1368 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1369 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1370 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1371 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1372 | - |
|
| 1373 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1374 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1375 | - . "\$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);' |
|
| 1379 | - . "\n\tif (\$debut_boucle>0" |
|
| 1380 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1381 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1382 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1383 | - |
|
| 1384 | - $boucles[$id_boucle]->partie = " |
|
| 1328 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1329 | + |
|
| 1330 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1331 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1332 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1333 | + // {1/3} |
|
| 1334 | + if ($op1 == '/') { |
|
| 1335 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1336 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | + "($total_parties ? $total_parties : 1)"; |
|
| 1338 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1339 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1340 | + } else { |
|
| 1341 | + // cas {n-1,x} |
|
| 1342 | + if ($op1 == '-') { |
|
| 1343 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + // cas {x,n-1} |
|
| 1347 | + if ($op2 == '-') { |
|
| 1348 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | + ($total_parties . ' - 1')); |
|
| 1351 | + } else { |
|
| 1352 | + // {x,1} ou {pagination} |
|
| 1353 | + $fin = '$debut_boucle' |
|
| 1354 | + . (is_numeric($total_parties) ? |
|
| 1355 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | + ('+' . $total_parties . ' - 1')); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1360 | + if ($op1 == 'p') { |
|
| 1361 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1362 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1363 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + // Notes : |
|
| 1368 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1369 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1370 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1371 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1372 | + |
|
| 1373 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1374 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1375 | + . "\$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);' |
|
| 1379 | + . "\n\tif (\$debut_boucle>0" |
|
| 1380 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1381 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1382 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1383 | + |
|
| 1384 | + $boucles[$id_boucle]->partie = " |
|
| 1385 | 1385 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1386 | 1386 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1387 | 1387 | } |
@@ -1398,26 +1398,26 @@ discard block |
||
| 1398 | 1398 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1399 | 1399 | **/ |
| 1400 | 1400 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1401 | - if ($param[0]->type != 'texte') { |
|
| 1402 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1403 | - if (isset($param[1]->texte)) { |
|
| 1404 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1405 | - |
|
| 1406 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1407 | - } else { |
|
| 1408 | - return ["intval($a1)", 0]; |
|
| 1409 | - } |
|
| 1410 | - } else { |
|
| 1411 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1412 | - $a1 = $m[1]; |
|
| 1413 | - if (empty($m[3])) { |
|
| 1414 | - return [$a1, 0]; |
|
| 1415 | - } elseif (!empty($m[4])) { |
|
| 1416 | - return [$a1, $m[4]]; |
|
| 1417 | - } else { |
|
| 1418 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1401 | + if ($param[0]->type != 'texte') { |
|
| 1402 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1403 | + if (isset($param[1]->texte)) { |
|
| 1404 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1405 | + |
|
| 1406 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1407 | + } else { |
|
| 1408 | + return ["intval($a1)", 0]; |
|
| 1409 | + } |
|
| 1410 | + } else { |
|
| 1411 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1412 | + $a1 = $m[1]; |
|
| 1413 | + if (empty($m[3])) { |
|
| 1414 | + return [$a1, 0]; |
|
| 1415 | + } elseif (!empty($m[4])) { |
|
| 1416 | + return [$a1, $m[4]]; |
|
| 1417 | + } else { |
|
| 1418 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | 1423 | |
@@ -1444,47 +1444,47 @@ discard block |
||
| 1444 | 1444 | * array : Erreur sur un des critères |
| 1445 | 1445 | **/ |
| 1446 | 1446 | function calculer_criteres($idb, &$boucles) { |
| 1447 | - $msg = ''; |
|
| 1448 | - $boucle = $boucles[$idb]; |
|
| 1449 | - $table = strtoupper($boucle->type_requete); |
|
| 1450 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1451 | - |
|
| 1452 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1453 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1454 | - if (!is_array($boucle->criteres)) { |
|
| 1455 | - return []; |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - foreach ($boucle->criteres as $crit) { |
|
| 1459 | - $critere = $crit->op; |
|
| 1460 | - // critere personnalise ? |
|
| 1461 | - if ( |
|
| 1462 | - (!$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')) |
|
| 1467 | - ) |
|
| 1468 | - ) |
|
| 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')) |
|
| 1473 | - ) { |
|
| 1474 | - // fonction critere standard |
|
| 1475 | - $f = $defaut; |
|
| 1476 | - } |
|
| 1477 | - // compile le critere |
|
| 1478 | - $res = $f($idb, $boucles, $crit); |
|
| 1479 | - |
|
| 1480 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1481 | - if (is_array($res)) { |
|
| 1482 | - $msg = $res; |
|
| 1483 | - erreur_squelette($msg, $boucle); |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - return $msg; |
|
| 1447 | + $msg = ''; |
|
| 1448 | + $boucle = $boucles[$idb]; |
|
| 1449 | + $table = strtoupper($boucle->type_requete); |
|
| 1450 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1451 | + |
|
| 1452 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1453 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1454 | + if (!is_array($boucle->criteres)) { |
|
| 1455 | + return []; |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + foreach ($boucle->criteres as $crit) { |
|
| 1459 | + $critere = $crit->op; |
|
| 1460 | + // critere personnalise ? |
|
| 1461 | + if ( |
|
| 1462 | + (!$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')) |
|
| 1467 | + ) |
|
| 1468 | + ) |
|
| 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')) |
|
| 1473 | + ) { |
|
| 1474 | + // fonction critere standard |
|
| 1475 | + $f = $defaut; |
|
| 1476 | + } |
|
| 1477 | + // compile le critere |
|
| 1478 | + $res = $f($idb, $boucles, $crit); |
|
| 1479 | + |
|
| 1480 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1481 | + if (is_array($res)) { |
|
| 1482 | + $msg = $res; |
|
| 1483 | + erreur_squelette($msg, $boucle); |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + return $msg; |
|
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | /** |
@@ -1499,11 +1499,11 @@ discard block |
||
| 1499 | 1499 | * @return string Code compilé rééchappé |
| 1500 | 1500 | */ |
| 1501 | 1501 | function kwote($lisp, $serveur = '', $type = '') { |
| 1502 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1503 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1504 | - } else { |
|
| 1505 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1506 | - } |
|
| 1502 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1503 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1504 | + } else { |
|
| 1505 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1506 | + } |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | |
@@ -1522,81 +1522,81 @@ discard block |
||
| 1522 | 1522 | * @return void|array |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1525 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1526 | - if (!$r) { |
|
| 1527 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1528 | - } |
|
| 1529 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1530 | - |
|
| 1531 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1532 | - |
|
| 1533 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1534 | - $where = $in; |
|
| 1535 | - if ($crit->cond) { |
|
| 1536 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1537 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1538 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1539 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1540 | - } |
|
| 1541 | - } |
|
| 1542 | - if ($crit->exclus) { |
|
| 1543 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1544 | - $where = ["'NOT'", $where]; |
|
| 1545 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1546 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1547 | - { |
|
| 1548 | - $where = [ |
|
| 1549 | - "'NOT'", |
|
| 1550 | - [ |
|
| 1551 | - "'IN'", |
|
| 1552 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1554 | - ] |
|
| 1555 | - ]; |
|
| 1556 | - } |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - $boucles[$idb]->where[] = $where; |
|
| 1560 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1561 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1562 | - } |
|
| 1525 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1526 | + if (!$r) { |
|
| 1527 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1528 | + } |
|
| 1529 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1530 | + |
|
| 1531 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1532 | + |
|
| 1533 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1534 | + $where = $in; |
|
| 1535 | + if ($crit->cond) { |
|
| 1536 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1537 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1538 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1539 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1540 | + } |
|
| 1541 | + } |
|
| 1542 | + if ($crit->exclus) { |
|
| 1543 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1544 | + $where = ["'NOT'", $where]; |
|
| 1545 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1546 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1547 | + { |
|
| 1548 | + $where = [ |
|
| 1549 | + "'NOT'", |
|
| 1550 | + [ |
|
| 1551 | + "'IN'", |
|
| 1552 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1554 | + ] |
|
| 1555 | + ]; |
|
| 1556 | + } |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + $boucles[$idb]->where[] = $where; |
|
| 1560 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1561 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1562 | + } |
|
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | 1565 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1566 | - static $num = []; |
|
| 1567 | - $descr = $boucles[$idb]->descr; |
|
| 1568 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1569 | - |
|
| 1570 | - $var = '$in' . $cpt++; |
|
| 1571 | - $x = "\n\t$var = array();"; |
|
| 1572 | - foreach ($val as $k => $v) { |
|
| 1573 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1574 | - // optimiser le traitement des constantes |
|
| 1575 | - if (is_numeric($r[2])) { |
|
| 1576 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1577 | - } else { |
|
| 1578 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1579 | - } |
|
| 1580 | - } else { |
|
| 1581 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1582 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1583 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1584 | - // 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);"; |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - $boucles[$idb]->in .= $x; |
|
| 1590 | - |
|
| 1591 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1592 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1593 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1594 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1595 | - if (!$crit2) { |
|
| 1596 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1566 | + static $num = []; |
|
| 1567 | + $descr = $boucles[$idb]->descr; |
|
| 1568 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1569 | + |
|
| 1570 | + $var = '$in' . $cpt++; |
|
| 1571 | + $x = "\n\t$var = array();"; |
|
| 1572 | + foreach ($val as $k => $v) { |
|
| 1573 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1574 | + // optimiser le traitement des constantes |
|
| 1575 | + if (is_numeric($r[2])) { |
|
| 1576 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1577 | + } else { |
|
| 1578 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1579 | + } |
|
| 1580 | + } else { |
|
| 1581 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1582 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1583 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1584 | + // 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);"; |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + $boucles[$idb]->in .= $x; |
|
| 1590 | + |
|
| 1591 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1592 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1593 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1594 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1595 | + if (!$crit2) { |
|
| 1596 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1612,22 +1612,22 @@ discard block |
||
| 1612 | 1612 | * @return void |
| 1613 | 1613 | */ |
| 1614 | 1614 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1615 | - $boucle = &$boucles[$idb]; |
|
| 1616 | - if (isset($crit->param[0])) { |
|
| 1617 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1618 | - } else { |
|
| 1619 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - if ($crit->cond) { |
|
| 1623 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - if ($crit->not) { |
|
| 1627 | - $_where = "array('NOT',$_where)"; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - $boucle->where[] = $_where; |
|
| 1615 | + $boucle = &$boucles[$idb]; |
|
| 1616 | + if (isset($crit->param[0])) { |
|
| 1617 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1618 | + } else { |
|
| 1619 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + if ($crit->cond) { |
|
| 1623 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + if ($crit->not) { |
|
| 1627 | + $_where = "array('NOT',$_where)"; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + $boucle->where[] = $_where; |
|
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | /** |
@@ -1655,31 +1655,31 @@ discard block |
||
| 1655 | 1655 | * @return void |
| 1656 | 1656 | */ |
| 1657 | 1657 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1658 | - /** @var Boucle $boucle */ |
|
| 1659 | - $boucle = $boucles[$idb]; |
|
| 1660 | - |
|
| 1661 | - $champs = lister_champs_id_conditionnel( |
|
| 1662 | - $boucle->show['table'], |
|
| 1663 | - $boucle->show, |
|
| 1664 | - $boucle->sql_serveur |
|
| 1665 | - ); |
|
| 1666 | - |
|
| 1667 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1668 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1669 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1670 | - } |
|
| 1671 | - // nous aider en mode debug. |
|
| 1672 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1673 | - $boucle->modificateur['id_'] = $champs; |
|
| 1674 | - |
|
| 1675 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1676 | - foreach ($champs as $champ) { |
|
| 1677 | - $critere_id_table = new Critere(); |
|
| 1678 | - $critere_id_table->op = $champ; |
|
| 1679 | - $critere_id_table->cond = '?'; |
|
| 1680 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1681 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1682 | - } |
|
| 1658 | + /** @var Boucle $boucle */ |
|
| 1659 | + $boucle = $boucles[$idb]; |
|
| 1660 | + |
|
| 1661 | + $champs = lister_champs_id_conditionnel( |
|
| 1662 | + $boucle->show['table'], |
|
| 1663 | + $boucle->show, |
|
| 1664 | + $boucle->sql_serveur |
|
| 1665 | + ); |
|
| 1666 | + |
|
| 1667 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1668 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1669 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1670 | + } |
|
| 1671 | + // nous aider en mode debug. |
|
| 1672 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1673 | + $boucle->modificateur['id_'] = $champs; |
|
| 1674 | + |
|
| 1675 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1676 | + foreach ($champs as $champ) { |
|
| 1677 | + $critere_id_table = new Critere(); |
|
| 1678 | + $critere_id_table->op = $champ; |
|
| 1679 | + $critere_id_table->cond = '?'; |
|
| 1680 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1681 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1682 | + } |
|
| 1683 | 1683 | } |
| 1684 | 1684 | |
| 1685 | 1685 | /** |
@@ -1699,75 +1699,75 @@ discard block |
||
| 1699 | 1699 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1700 | 1700 | */ |
| 1701 | 1701 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1702 | - // calculer la description de la table |
|
| 1703 | - if (!is_array($desc)) { |
|
| 1704 | - $desc = description_table($table, $serveur); |
|
| 1705 | - } |
|
| 1706 | - if (!$desc) { |
|
| 1707 | - return []; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - // Les champs id_xx de la table demandée |
|
| 1711 | - $champs = array_filter( |
|
| 1712 | - array_keys($desc['field']), |
|
| 1713 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1714 | - ); |
|
| 1715 | - |
|
| 1716 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1717 | - if ( |
|
| 1718 | - in_array('id_rubrique', $champs) |
|
| 1719 | - and !in_array('id_secteur', $champs) |
|
| 1720 | - ) { |
|
| 1721 | - $champs[] = 'id_secteur'; |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1725 | - if ($serveur) { |
|
| 1726 | - return $champs; |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - $primary = false; |
|
| 1730 | - $associable = false; |
|
| 1731 | - include_spip('action/editer_liens'); |
|
| 1732 | - |
|
| 1733 | - if (isset($desc['type'])) { |
|
| 1734 | - $primary = id_table_objet($desc['type']); |
|
| 1735 | - $associable = objet_associable($desc['type']); |
|
| 1736 | - } |
|
| 1737 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1738 | - $associable = true; |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - // liste de toutes les tables principales, sauf la notre |
|
| 1742 | - $tables = lister_tables_objets_sql(); |
|
| 1743 | - unset($tables[$table]); |
|
| 1744 | - |
|
| 1745 | - foreach ($tables as $_table => $_desc) { |
|
| 1746 | - if ( |
|
| 1747 | - $associable |
|
| 1748 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1749 | - or objet_associable($_desc['type']) |
|
| 1750 | - ) { |
|
| 1751 | - $champs[] = id_table_objet($_table); |
|
| 1752 | - } |
|
| 1753 | - } |
|
| 1754 | - $champs = array_values(array_unique($champs)); |
|
| 1755 | - |
|
| 1756 | - // Exclusions de certains id |
|
| 1757 | - $exclusions = pipeline( |
|
| 1758 | - 'exclure_id_conditionnel', |
|
| 1759 | - [ |
|
| 1760 | - 'args' => [ |
|
| 1761 | - 'table' => $table, |
|
| 1762 | - 'id_table_objet' => $primary, |
|
| 1763 | - 'associable' => $associable, |
|
| 1764 | - ], |
|
| 1765 | - 'data' => [], |
|
| 1766 | - ] |
|
| 1767 | - ); |
|
| 1768 | - $champs = array_diff($champs, $exclusions); |
|
| 1769 | - |
|
| 1770 | - return $champs; |
|
| 1702 | + // calculer la description de la table |
|
| 1703 | + if (!is_array($desc)) { |
|
| 1704 | + $desc = description_table($table, $serveur); |
|
| 1705 | + } |
|
| 1706 | + if (!$desc) { |
|
| 1707 | + return []; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + // Les champs id_xx de la table demandée |
|
| 1711 | + $champs = array_filter( |
|
| 1712 | + array_keys($desc['field']), |
|
| 1713 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1714 | + ); |
|
| 1715 | + |
|
| 1716 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1717 | + if ( |
|
| 1718 | + in_array('id_rubrique', $champs) |
|
| 1719 | + and !in_array('id_secteur', $champs) |
|
| 1720 | + ) { |
|
| 1721 | + $champs[] = 'id_secteur'; |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1725 | + if ($serveur) { |
|
| 1726 | + return $champs; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + $primary = false; |
|
| 1730 | + $associable = false; |
|
| 1731 | + include_spip('action/editer_liens'); |
|
| 1732 | + |
|
| 1733 | + if (isset($desc['type'])) { |
|
| 1734 | + $primary = id_table_objet($desc['type']); |
|
| 1735 | + $associable = objet_associable($desc['type']); |
|
| 1736 | + } |
|
| 1737 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1738 | + $associable = true; |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + // liste de toutes les tables principales, sauf la notre |
|
| 1742 | + $tables = lister_tables_objets_sql(); |
|
| 1743 | + unset($tables[$table]); |
|
| 1744 | + |
|
| 1745 | + foreach ($tables as $_table => $_desc) { |
|
| 1746 | + if ( |
|
| 1747 | + $associable |
|
| 1748 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1749 | + or objet_associable($_desc['type']) |
|
| 1750 | + ) { |
|
| 1751 | + $champs[] = id_table_objet($_table); |
|
| 1752 | + } |
|
| 1753 | + } |
|
| 1754 | + $champs = array_values(array_unique($champs)); |
|
| 1755 | + |
|
| 1756 | + // Exclusions de certains id |
|
| 1757 | + $exclusions = pipeline( |
|
| 1758 | + 'exclure_id_conditionnel', |
|
| 1759 | + [ |
|
| 1760 | + 'args' => [ |
|
| 1761 | + 'table' => $table, |
|
| 1762 | + 'id_table_objet' => $primary, |
|
| 1763 | + 'associable' => $associable, |
|
| 1764 | + ], |
|
| 1765 | + 'data' => [], |
|
| 1766 | + ] |
|
| 1767 | + ); |
|
| 1768 | + $champs = array_diff($champs, $exclusions); |
|
| 1769 | + |
|
| 1770 | + return $champs; |
|
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | /** |
@@ -1822,28 +1822,28 @@ discard block |
||
| 1822 | 1822 | * @return void |
| 1823 | 1823 | */ |
| 1824 | 1824 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1825 | - $boucle = &$boucles[$idb]; |
|
| 1826 | - |
|
| 1827 | - // definition du champ par defaut |
|
| 1828 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1829 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1830 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1831 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1832 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1833 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | - |
|
| 1835 | - $_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):'')"; |
|
| 1836 | - |
|
| 1837 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1838 | - $_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)"; |
|
| 1839 | - |
|
| 1840 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1841 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1842 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1843 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1844 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1845 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1846 | - $boucle->hash .= " |
|
| 1825 | + $boucle = &$boucles[$idb]; |
|
| 1826 | + |
|
| 1827 | + // definition du champ par defaut |
|
| 1828 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1829 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1830 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1831 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1832 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1833 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | + |
|
| 1835 | + $_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):'')"; |
|
| 1836 | + |
|
| 1837 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1838 | + $_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)"; |
|
| 1839 | + |
|
| 1840 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1841 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1842 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1843 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1844 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1845 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1846 | + $boucle->hash .= " |
|
| 1847 | 1847 | \$senstri = ''; |
| 1848 | 1848 | \$tri = $_tri; |
| 1849 | 1849 | if (\$tri){ |
@@ -1851,8 +1851,8 @@ discard block |
||
| 1851 | 1851 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1852 | 1852 | }; |
| 1853 | 1853 | "; |
| 1854 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1855 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1854 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1855 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | 1858 | # Criteres de comparaison |
@@ -1869,20 +1869,20 @@ discard block |
||
| 1869 | 1869 | * @return void|array |
| 1870 | 1870 | **/ |
| 1871 | 1871 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1872 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1873 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1874 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1878 | - if (!$r) { |
|
| 1879 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1880 | - # if (!$crit->cond) { |
|
| 1881 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1882 | - # } |
|
| 1883 | - } else { |
|
| 1884 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1885 | - } |
|
| 1872 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1873 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1874 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1878 | + if (!$r) { |
|
| 1879 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1880 | + # if (!$crit->cond) { |
|
| 1881 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1882 | + # } |
|
| 1883 | + } else { |
|
| 1884 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1885 | + } |
|
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | 1888 | |
@@ -1902,62 +1902,62 @@ discard block |
||
| 1902 | 1902 | * @return void |
| 1903 | 1903 | **/ |
| 1904 | 1904 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1905 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1906 | - |
|
| 1907 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1908 | - |
|
| 1909 | - // inserer la negation (cf !...) |
|
| 1910 | - |
|
| 1911 | - if ($crit->not) { |
|
| 1912 | - $where = ["'NOT'", $where]; |
|
| 1913 | - } |
|
| 1914 | - if ($crit->exclus) { |
|
| 1915 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1916 | - $where = ["'NOT'", $where]; |
|
| 1917 | - } else { |
|
| 1918 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1919 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1920 | - $where = [ |
|
| 1921 | - "'NOT'", |
|
| 1922 | - [ |
|
| 1923 | - "'IN'", |
|
| 1924 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1926 | - ] |
|
| 1927 | - ]; |
|
| 1928 | - } |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - // inserer la condition (cf {lang?}) |
|
| 1932 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1933 | - if ($crit->cond) { |
|
| 1934 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1935 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1936 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1937 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - if ($op === '=' and !$crit->not) { |
|
| 1942 | - $where = [ |
|
| 1943 | - "'?'", |
|
| 1944 | - "(is_array($pred))", |
|
| 1945 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1946 | - $where |
|
| 1947 | - ]; |
|
| 1948 | - } |
|
| 1949 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1950 | - if ($where_complement) { |
|
| 1951 | - // condition annexe du type "AND (objet='article')" |
|
| 1952 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1953 | - } |
|
| 1954 | - } |
|
| 1955 | - |
|
| 1956 | - $boucles[$idb]->where[] = $where; |
|
| 1957 | - if ($where_complement) { |
|
| 1958 | - // condition annexe du type "AND (objet='article')" |
|
| 1959 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1960 | - } |
|
| 1905 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1906 | + |
|
| 1907 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1908 | + |
|
| 1909 | + // inserer la negation (cf !...) |
|
| 1910 | + |
|
| 1911 | + if ($crit->not) { |
|
| 1912 | + $where = ["'NOT'", $where]; |
|
| 1913 | + } |
|
| 1914 | + if ($crit->exclus) { |
|
| 1915 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1916 | + $where = ["'NOT'", $where]; |
|
| 1917 | + } else { |
|
| 1918 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1919 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1920 | + $where = [ |
|
| 1921 | + "'NOT'", |
|
| 1922 | + [ |
|
| 1923 | + "'IN'", |
|
| 1924 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1926 | + ] |
|
| 1927 | + ]; |
|
| 1928 | + } |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + // inserer la condition (cf {lang?}) |
|
| 1932 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1933 | + if ($crit->cond) { |
|
| 1934 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1935 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1936 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1937 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + if ($op === '=' and !$crit->not) { |
|
| 1942 | + $where = [ |
|
| 1943 | + "'?'", |
|
| 1944 | + "(is_array($pred))", |
|
| 1945 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1946 | + $where |
|
| 1947 | + ]; |
|
| 1948 | + } |
|
| 1949 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1950 | + if ($where_complement) { |
|
| 1951 | + // condition annexe du type "AND (objet='article')" |
|
| 1952 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1953 | + } |
|
| 1954 | + } |
|
| 1955 | + |
|
| 1956 | + $boucles[$idb]->where[] = $where; |
|
| 1957 | + if ($where_complement) { |
|
| 1958 | + // condition annexe du type "AND (objet='article')" |
|
| 1959 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1960 | + } |
|
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | 1963 | |
@@ -1998,165 +1998,165 @@ discard block |
||
| 1998 | 1998 | **/ |
| 1999 | 1999 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2000 | 2000 | |
| 2001 | - $boucle = &$boucles[$idb]; |
|
| 2002 | - $type = $boucle->type_requete; |
|
| 2003 | - $table = $boucle->id_table; |
|
| 2004 | - $desc = $boucle->show; |
|
| 2005 | - $col_vraie = null; |
|
| 2006 | - |
|
| 2007 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2008 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2009 | - |
|
| 2010 | - $col_alias = $col; |
|
| 2011 | - $where_complement = false; |
|
| 2012 | - |
|
| 2013 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2014 | - if ($col == 'id_enfant') { |
|
| 2015 | - $col = $boucle->primary; |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2019 | - if ( |
|
| 2020 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2021 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2022 | - ) { |
|
| 2023 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2024 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2025 | - else { |
|
| 2026 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2027 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2031 | - // sauf si exception declaree : sauter cette etape |
|
| 2032 | - else { |
|
| 2033 | - if ( |
|
| 2034 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2035 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2036 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2037 | - ) { |
|
| 2038 | - $e = decompose_champ_id_objet($col); |
|
| 2039 | - $col = array_shift($e); |
|
| 2040 | - $where_complement = primary_doublee($e, $table); |
|
| 2041 | - } // Cas particulier : expressions de date |
|
| 2042 | - else { |
|
| 2043 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2044 | - [$col, $col_vraie] = $c; |
|
| 2045 | - $table = ''; |
|
| 2046 | - } // table explicitée {mots.titre} |
|
| 2047 | - else { |
|
| 2048 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2049 | - [, $table, $col] = $r; |
|
| 2050 | - $col_alias = $col; |
|
| 2051 | - |
|
| 2052 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2053 | - if ( |
|
| 2054 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2055 | - and isset($desc['field'][$col]) |
|
| 2056 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2057 | - ) { |
|
| 2058 | - $table = $cle; |
|
| 2059 | - } else { |
|
| 2060 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2061 | - } |
|
| 2062 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2063 | - if (!$table) { |
|
| 2064 | - return ''; |
|
| 2065 | - } |
|
| 2066 | - } |
|
| 2067 | - // si le champ n'est pas trouvé dans la table, |
|
| 2068 | - // on cherche si une jointure peut l'obtenir |
|
| 2069 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2070 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2071 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2072 | - $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 |
|
| 2073 | - } |
|
| 2074 | - else { |
|
| 2075 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2076 | - if (!$r) { |
|
| 2077 | - return ''; |
|
| 2078 | - } |
|
| 2079 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - } |
|
| 2083 | - } |
|
| 2084 | - } |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2088 | - // Dans tous les cas, |
|
| 2089 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2090 | - // et passer dans sql_quote avec le type si connu |
|
| 2091 | - // et int sinon si la valeur est numerique |
|
| 2092 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2093 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2094 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2095 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2096 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2097 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2098 | - 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) . '"'; |
|
| 2100 | - } |
|
| 2101 | - // sinon expliciter les |
|
| 2102 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2103 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2104 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2105 | - // sans toucher aux |
|
| 2106 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2107 | - // sql_quote(truc,'','varchar') |
|
| 2108 | - elseif ( |
|
| 2109 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2110 | - // si pas deja un type |
|
| 2111 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2112 | - ) { |
|
| 2113 | - $r = $r[1] |
|
| 2114 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2115 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2116 | - $val[0] = "sql_quote($r)"; |
|
| 2117 | - } |
|
| 2118 | - elseif ( |
|
| 2119 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2120 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2121 | - ) { |
|
| 2122 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2123 | - } |
|
| 2124 | - } |
|
| 2125 | - |
|
| 2126 | - if ( |
|
| 2127 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2128 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2129 | - ) { |
|
| 2130 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2131 | - } |
|
| 2132 | - |
|
| 2133 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2134 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2135 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2136 | - if ($table === $boucle->id_table) { |
|
| 2137 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2138 | - if ($col_alias != $col_vraie) { |
|
| 2139 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2140 | - } |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2144 | - if ($table) { |
|
| 2145 | - if ($col[0] == '`') { |
|
| 2146 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2147 | - } else { |
|
| 2148 | - $arg = "$table.$col"; |
|
| 2149 | - } |
|
| 2150 | - } else { |
|
| 2151 | - $arg = $col; |
|
| 2152 | - } |
|
| 2153 | - |
|
| 2154 | - // inserer la fonction SQL |
|
| 2155 | - if ($fct) { |
|
| 2156 | - $arg = "$fct($arg$args_sql)"; |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2001 | + $boucle = &$boucles[$idb]; |
|
| 2002 | + $type = $boucle->type_requete; |
|
| 2003 | + $table = $boucle->id_table; |
|
| 2004 | + $desc = $boucle->show; |
|
| 2005 | + $col_vraie = null; |
|
| 2006 | + |
|
| 2007 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2008 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2009 | + |
|
| 2010 | + $col_alias = $col; |
|
| 2011 | + $where_complement = false; |
|
| 2012 | + |
|
| 2013 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2014 | + if ($col == 'id_enfant') { |
|
| 2015 | + $col = $boucle->primary; |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2019 | + if ( |
|
| 2020 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2021 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2022 | + ) { |
|
| 2023 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2024 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2025 | + else { |
|
| 2026 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2027 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2031 | + // sauf si exception declaree : sauter cette etape |
|
| 2032 | + else { |
|
| 2033 | + if ( |
|
| 2034 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2035 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2036 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2037 | + ) { |
|
| 2038 | + $e = decompose_champ_id_objet($col); |
|
| 2039 | + $col = array_shift($e); |
|
| 2040 | + $where_complement = primary_doublee($e, $table); |
|
| 2041 | + } // Cas particulier : expressions de date |
|
| 2042 | + else { |
|
| 2043 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2044 | + [$col, $col_vraie] = $c; |
|
| 2045 | + $table = ''; |
|
| 2046 | + } // table explicitée {mots.titre} |
|
| 2047 | + else { |
|
| 2048 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2049 | + [, $table, $col] = $r; |
|
| 2050 | + $col_alias = $col; |
|
| 2051 | + |
|
| 2052 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2053 | + if ( |
|
| 2054 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2055 | + and isset($desc['field'][$col]) |
|
| 2056 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2057 | + ) { |
|
| 2058 | + $table = $cle; |
|
| 2059 | + } else { |
|
| 2060 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2061 | + } |
|
| 2062 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2063 | + if (!$table) { |
|
| 2064 | + return ''; |
|
| 2065 | + } |
|
| 2066 | + } |
|
| 2067 | + // si le champ n'est pas trouvé dans la table, |
|
| 2068 | + // on cherche si une jointure peut l'obtenir |
|
| 2069 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2070 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2071 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2072 | + $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 |
|
| 2073 | + } |
|
| 2074 | + else { |
|
| 2075 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2076 | + if (!$r) { |
|
| 2077 | + return ''; |
|
| 2078 | + } |
|
| 2079 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + } |
|
| 2083 | + } |
|
| 2084 | + } |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2088 | + // Dans tous les cas, |
|
| 2089 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2090 | + // et passer dans sql_quote avec le type si connu |
|
| 2091 | + // et int sinon si la valeur est numerique |
|
| 2092 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2093 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2094 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2095 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2096 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2097 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2098 | + 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) . '"'; |
|
| 2100 | + } |
|
| 2101 | + // sinon expliciter les |
|
| 2102 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2103 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2104 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2105 | + // sans toucher aux |
|
| 2106 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2107 | + // sql_quote(truc,'','varchar') |
|
| 2108 | + elseif ( |
|
| 2109 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2110 | + // si pas deja un type |
|
| 2111 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2112 | + ) { |
|
| 2113 | + $r = $r[1] |
|
| 2114 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2115 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2116 | + $val[0] = "sql_quote($r)"; |
|
| 2117 | + } |
|
| 2118 | + elseif ( |
|
| 2119 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2120 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2121 | + ) { |
|
| 2122 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2123 | + } |
|
| 2124 | + } |
|
| 2125 | + |
|
| 2126 | + if ( |
|
| 2127 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2128 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2129 | + ) { |
|
| 2130 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2134 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2135 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2136 | + if ($table === $boucle->id_table) { |
|
| 2137 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2138 | + if ($col_alias != $col_vraie) { |
|
| 2139 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2140 | + } |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2144 | + if ($table) { |
|
| 2145 | + if ($col[0] == '`') { |
|
| 2146 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2147 | + } else { |
|
| 2148 | + $arg = "$table.$col"; |
|
| 2149 | + } |
|
| 2150 | + } else { |
|
| 2151 | + $arg = $col; |
|
| 2152 | + } |
|
| 2153 | + |
|
| 2154 | + // inserer la fonction SQL |
|
| 2155 | + if ($fct) { |
|
| 2156 | + $arg = "$fct($arg$args_sql)"; |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2160 | 2160 | } |
| 2161 | 2161 | |
| 2162 | 2162 | |
@@ -2185,77 +2185,77 @@ discard block |
||
| 2185 | 2185 | **/ |
| 2186 | 2186 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2187 | 2187 | |
| 2188 | - $where = ''; |
|
| 2189 | - |
|
| 2190 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2191 | - // gestion par les plugins des jointures tordues |
|
| 2192 | - // pas automatiques mais necessaires |
|
| 2193 | - $table_sql = table_objet_sql($table); |
|
| 2194 | - if ( |
|
| 2195 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2196 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2197 | - and |
|
| 2198 | - ( |
|
| 2199 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2200 | - or |
|
| 2201 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2202 | - ) |
|
| 2203 | - ) { |
|
| 2204 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2205 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2206 | - |
|
| 2207 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2208 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2209 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2210 | - [$t, $col] = $t[$col]; |
|
| 2211 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2212 | - [$calculer_critere_externe] = $index; |
|
| 2213 | - $t = $table; |
|
| 2214 | - } else { |
|
| 2215 | - $t = ''; |
|
| 2216 | - } // jointure non declaree. La trouver. |
|
| 2217 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2218 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2219 | - } else { |
|
| 2220 | - $t = ''; |
|
| 2221 | - } // jointure non declaree. La trouver. |
|
| 2222 | - |
|
| 2223 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2224 | - |
|
| 2225 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2226 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2227 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2228 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2229 | - $table = ''; |
|
| 2230 | - if ($boucle->jointures_explicites) { |
|
| 2231 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2232 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2236 | - if (!$table) { |
|
| 2237 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - if (!$table) { |
|
| 2241 | - return ''; |
|
| 2242 | - } |
|
| 2243 | - |
|
| 2244 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2245 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2246 | - |
|
| 2247 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2248 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2249 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2250 | - $e = decompose_champ_id_objet($col); |
|
| 2251 | - $col = array_shift($e); |
|
| 2252 | - $where = primary_doublee($e, $table); |
|
| 2253 | - } else { |
|
| 2254 | - $col = reset($cle); |
|
| 2255 | - } |
|
| 2256 | - } |
|
| 2257 | - |
|
| 2258 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2188 | + $where = ''; |
|
| 2189 | + |
|
| 2190 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2191 | + // gestion par les plugins des jointures tordues |
|
| 2192 | + // pas automatiques mais necessaires |
|
| 2193 | + $table_sql = table_objet_sql($table); |
|
| 2194 | + if ( |
|
| 2195 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2196 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2197 | + and |
|
| 2198 | + ( |
|
| 2199 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2200 | + or |
|
| 2201 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2202 | + ) |
|
| 2203 | + ) { |
|
| 2204 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2205 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2206 | + |
|
| 2207 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2208 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2209 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2210 | + [$t, $col] = $t[$col]; |
|
| 2211 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2212 | + [$calculer_critere_externe] = $index; |
|
| 2213 | + $t = $table; |
|
| 2214 | + } else { |
|
| 2215 | + $t = ''; |
|
| 2216 | + } // jointure non declaree. La trouver. |
|
| 2217 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2218 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2219 | + } else { |
|
| 2220 | + $t = ''; |
|
| 2221 | + } // jointure non declaree. La trouver. |
|
| 2222 | + |
|
| 2223 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2224 | + |
|
| 2225 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2226 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2227 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2228 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2229 | + $table = ''; |
|
| 2230 | + if ($boucle->jointures_explicites) { |
|
| 2231 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2232 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2236 | + if (!$table) { |
|
| 2237 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + if (!$table) { |
|
| 2241 | + return ''; |
|
| 2242 | + } |
|
| 2243 | + |
|
| 2244 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2245 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2246 | + |
|
| 2247 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2248 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2249 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2250 | + $e = decompose_champ_id_objet($col); |
|
| 2251 | + $col = array_shift($e); |
|
| 2252 | + $where = primary_doublee($e, $table); |
|
| 2253 | + } else { |
|
| 2254 | + $col = reset($cle); |
|
| 2255 | + } |
|
| 2256 | + } |
|
| 2257 | + |
|
| 2258 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | 2261 | |
@@ -2276,10 +2276,10 @@ discard block |
||
| 2276 | 2276 | * - valeur |
| 2277 | 2277 | **/ |
| 2278 | 2278 | function primary_doublee($decompose, $table) { |
| 2279 | - $e1 = reset($decompose); |
|
| 2280 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2279 | + $e1 = reset($decompose); |
|
| 2280 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2281 | 2281 | |
| 2282 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2282 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2283 | 2283 | } |
| 2284 | 2284 | |
| 2285 | 2285 | /** |
@@ -2310,57 +2310,57 @@ discard block |
||
| 2310 | 2310 | * Vide sinon. |
| 2311 | 2311 | */ |
| 2312 | 2312 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2313 | - // si on demande un truc du genre spip_mots |
|
| 2314 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2315 | - // et qu'on est la |
|
| 2316 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2317 | - if ( |
|
| 2318 | - $checkarrivee |
|
| 2319 | - and is_string($checkarrivee) |
|
| 2320 | - and $a = table_objet($checkarrivee) |
|
| 2321 | - and in_array($a . '_liens', $joints) |
|
| 2322 | - ) { |
|
| 2323 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2324 | - return $res; |
|
| 2325 | - } |
|
| 2326 | - } |
|
| 2327 | - foreach ($joints as $joint) { |
|
| 2328 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2329 | - // alias de table dans le from |
|
| 2330 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2331 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2332 | - $cols = $arrivee[2]; |
|
| 2333 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2334 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2335 | - array_pop($cols); |
|
| 2336 | - } |
|
| 2337 | - if ($t) { |
|
| 2338 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2339 | - $joindre = false; |
|
| 2340 | - foreach ($cols as $col) { |
|
| 2341 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2342 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2343 | - $joindre = true; |
|
| 2344 | - } else { |
|
| 2345 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2346 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2347 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2348 | - $joindre = true; |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - if (!$joindre) { |
|
| 2353 | - return $t; |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - array_pop($arrivee); |
|
| 2357 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2358 | - return $res; |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - |
|
| 2363 | - return ''; |
|
| 2313 | + // si on demande un truc du genre spip_mots |
|
| 2314 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2315 | + // et qu'on est la |
|
| 2316 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2317 | + if ( |
|
| 2318 | + $checkarrivee |
|
| 2319 | + and is_string($checkarrivee) |
|
| 2320 | + and $a = table_objet($checkarrivee) |
|
| 2321 | + and in_array($a . '_liens', $joints) |
|
| 2322 | + ) { |
|
| 2323 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2324 | + return $res; |
|
| 2325 | + } |
|
| 2326 | + } |
|
| 2327 | + foreach ($joints as $joint) { |
|
| 2328 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2329 | + // alias de table dans le from |
|
| 2330 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2331 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2332 | + $cols = $arrivee[2]; |
|
| 2333 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2334 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2335 | + array_pop($cols); |
|
| 2336 | + } |
|
| 2337 | + if ($t) { |
|
| 2338 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2339 | + $joindre = false; |
|
| 2340 | + foreach ($cols as $col) { |
|
| 2341 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2342 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2343 | + $joindre = true; |
|
| 2344 | + } else { |
|
| 2345 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2346 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2347 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2348 | + $joindre = true; |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + if (!$joindre) { |
|
| 2353 | + return $t; |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + array_pop($arrivee); |
|
| 2357 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2358 | + return $res; |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + |
|
| 2363 | + return ''; |
|
| 2364 | 2364 | } |
| 2365 | 2365 | |
| 2366 | 2366 | /** |
@@ -2386,35 +2386,35 @@ discard block |
||
| 2386 | 2386 | * Alias de la table de jointure (Lx) |
| 2387 | 2387 | */ |
| 2388 | 2388 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2389 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2390 | - |
|
| 2391 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2392 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2393 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2394 | - |
|
| 2395 | - if (!$intermediaire or !$arrivee) { |
|
| 2396 | - return ''; |
|
| 2397 | - } |
|
| 2398 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2399 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2400 | - |
|
| 2401 | - $res = fabrique_jointures( |
|
| 2402 | - $boucle, |
|
| 2403 | - [ |
|
| 2404 | - [ |
|
| 2405 | - $boucle->id_table, |
|
| 2406 | - $intermediaire, |
|
| 2407 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2408 | - ], |
|
| 2409 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2410 | - ], |
|
| 2411 | - $cond, |
|
| 2412 | - $desc, |
|
| 2413 | - $boucle->id_table, |
|
| 2414 | - [$col] |
|
| 2415 | - ); |
|
| 2416 | - |
|
| 2417 | - return $res; |
|
| 2389 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2390 | + |
|
| 2391 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2392 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2393 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2394 | + |
|
| 2395 | + if (!$intermediaire or !$arrivee) { |
|
| 2396 | + return ''; |
|
| 2397 | + } |
|
| 2398 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2399 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2400 | + |
|
| 2401 | + $res = fabrique_jointures( |
|
| 2402 | + $boucle, |
|
| 2403 | + [ |
|
| 2404 | + [ |
|
| 2405 | + $boucle->id_table, |
|
| 2406 | + $intermediaire, |
|
| 2407 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2408 | + ], |
|
| 2409 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2410 | + ], |
|
| 2411 | + $cond, |
|
| 2412 | + $desc, |
|
| 2413 | + $boucle->id_table, |
|
| 2414 | + [$col] |
|
| 2415 | + ); |
|
| 2416 | + |
|
| 2417 | + return $res; |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | |
@@ -2431,17 +2431,17 @@ discard block |
||
| 2431 | 2431 | * false sinon. |
| 2432 | 2432 | **/ |
| 2433 | 2433 | function trouver_champ($champ, $where) { |
| 2434 | - if (!is_array($where)) { |
|
| 2435 | - return preg_match($champ, $where); |
|
| 2436 | - } else { |
|
| 2437 | - foreach ($where as $clause) { |
|
| 2438 | - if (trouver_champ($champ, $clause)) { |
|
| 2439 | - return true; |
|
| 2440 | - } |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - return false; |
|
| 2444 | - } |
|
| 2434 | + if (!is_array($where)) { |
|
| 2435 | + return preg_match($champ, $where); |
|
| 2436 | + } else { |
|
| 2437 | + foreach ($where as $clause) { |
|
| 2438 | + if (trouver_champ($champ, $clause)) { |
|
| 2439 | + return true; |
|
| 2440 | + } |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + return false; |
|
| 2444 | + } |
|
| 2445 | 2445 | } |
| 2446 | 2446 | |
| 2447 | 2447 | |
@@ -2467,129 +2467,129 @@ discard block |
||
| 2467 | 2467 | * - string $args_sql Suite des arguments du critère. ? |
| 2468 | 2468 | **/ |
| 2469 | 2469 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2470 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2471 | - if (count($crit->param) == 0) { |
|
| 2472 | - $op = '='; |
|
| 2473 | - $col = $val = $crit->op; |
|
| 2474 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2475 | - $val = $r[2]; |
|
| 2476 | - } |
|
| 2477 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2478 | - if ($val == 'lang') { |
|
| 2479 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2480 | - } else { |
|
| 2481 | - $defaut = null; |
|
| 2482 | - if ($val == 'id_parent') { |
|
| 2483 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2484 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2485 | - // pour eviter l'erreur SQL |
|
| 2486 | - $val = $boucles[$idb]->primary; |
|
| 2487 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2488 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2489 | - } elseif ($val == 'id_enfant') { |
|
| 2490 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2491 | - // de la boucle superieure |
|
| 2492 | - $val = 'id_parent'; |
|
| 2493 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2494 | - // un critere conditionnel sur date est traite a part |
|
| 2495 | - // car la date est mise d'office par SPIP, |
|
| 2496 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2497 | - } |
|
| 2498 | - |
|
| 2499 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2500 | - $val = [kwote($val)]; |
|
| 2501 | - } |
|
| 2502 | - } else { |
|
| 2503 | - // comparaison explicite |
|
| 2504 | - // le phraseur impose que le premier param soit du texte |
|
| 2505 | - $params = $crit->param; |
|
| 2506 | - $op = $crit->op; |
|
| 2507 | - if ($op == '==') { |
|
| 2508 | - $op = 'REGEXP'; |
|
| 2509 | - } |
|
| 2510 | - $col = array_shift($params); |
|
| 2511 | - $col = $col[0]->texte; |
|
| 2512 | - |
|
| 2513 | - $val = []; |
|
| 2514 | - $parent = $boucles[$idb]->id_parent; |
|
| 2515 | - |
|
| 2516 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2517 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2518 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2519 | - if ( |
|
| 2520 | - count($params) == 1 |
|
| 2521 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2522 | - and $params[0][0]->type == 'texte' |
|
| 2523 | - and $params[0][2]->type == 'texte' |
|
| 2524 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2525 | - and (($p == "'") or ($p == '"')) |
|
| 2526 | - and $params[0][1]->type == 'champ' |
|
| 2527 | - ) { |
|
| 2528 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2529 | - } else { |
|
| 2530 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2531 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2532 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2533 | - $val[] = $a; |
|
| 2534 | - } else { |
|
| 2535 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2536 | - } // toujours quoter en char ici |
|
| 2537 | - } |
|
| 2538 | - } |
|
| 2539 | - } |
|
| 2540 | - |
|
| 2541 | - $fct = $args_sql = ''; |
|
| 2542 | - // fonction SQL ? |
|
| 2543 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2544 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2545 | - $fct = $m[1]; |
|
| 2546 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2547 | - $col = $a[1]; |
|
| 2548 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2549 | - $col = $m[1]; |
|
| 2550 | - $args_sql = $m[2]; |
|
| 2551 | - } |
|
| 2552 | - $args_sql .= $a[2]; |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2470 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2471 | + if (count($crit->param) == 0) { |
|
| 2472 | + $op = '='; |
|
| 2473 | + $col = $val = $crit->op; |
|
| 2474 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2475 | + $val = $r[2]; |
|
| 2476 | + } |
|
| 2477 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2478 | + if ($val == 'lang') { |
|
| 2479 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2480 | + } else { |
|
| 2481 | + $defaut = null; |
|
| 2482 | + if ($val == 'id_parent') { |
|
| 2483 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2484 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2485 | + // pour eviter l'erreur SQL |
|
| 2486 | + $val = $boucles[$idb]->primary; |
|
| 2487 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2488 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2489 | + } elseif ($val == 'id_enfant') { |
|
| 2490 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2491 | + // de la boucle superieure |
|
| 2492 | + $val = 'id_parent'; |
|
| 2493 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2494 | + // un critere conditionnel sur date est traite a part |
|
| 2495 | + // car la date est mise d'office par SPIP, |
|
| 2496 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2497 | + } |
|
| 2498 | + |
|
| 2499 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2500 | + $val = [kwote($val)]; |
|
| 2501 | + } |
|
| 2502 | + } else { |
|
| 2503 | + // comparaison explicite |
|
| 2504 | + // le phraseur impose que le premier param soit du texte |
|
| 2505 | + $params = $crit->param; |
|
| 2506 | + $op = $crit->op; |
|
| 2507 | + if ($op == '==') { |
|
| 2508 | + $op = 'REGEXP'; |
|
| 2509 | + } |
|
| 2510 | + $col = array_shift($params); |
|
| 2511 | + $col = $col[0]->texte; |
|
| 2512 | + |
|
| 2513 | + $val = []; |
|
| 2514 | + $parent = $boucles[$idb]->id_parent; |
|
| 2515 | + |
|
| 2516 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2517 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2518 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2519 | + if ( |
|
| 2520 | + count($params) == 1 |
|
| 2521 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2522 | + and $params[0][0]->type == 'texte' |
|
| 2523 | + and $params[0][2]->type == 'texte' |
|
| 2524 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2525 | + and (($p == "'") or ($p == '"')) |
|
| 2526 | + and $params[0][1]->type == 'champ' |
|
| 2527 | + ) { |
|
| 2528 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2529 | + } else { |
|
| 2530 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2531 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2532 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2533 | + $val[] = $a; |
|
| 2534 | + } else { |
|
| 2535 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2536 | + } // toujours quoter en char ici |
|
| 2537 | + } |
|
| 2538 | + } |
|
| 2539 | + } |
|
| 2540 | + |
|
| 2541 | + $fct = $args_sql = ''; |
|
| 2542 | + // fonction SQL ? |
|
| 2543 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2544 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2545 | + $fct = $m[1]; |
|
| 2546 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2547 | + $col = $a[1]; |
|
| 2548 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2549 | + $col = $m[1]; |
|
| 2550 | + $args_sql = $m[2]; |
|
| 2551 | + } |
|
| 2552 | + $args_sql .= $a[2]; |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2556 | 2556 | } |
| 2557 | 2557 | |
| 2558 | 2558 | // compatibilite ancienne version |
| 2559 | 2559 | |
| 2560 | 2560 | function calculer_vieux_in($params) { |
| 2561 | - $deb = $params[0][0]; |
|
| 2562 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2563 | - $last = $params[$k]; |
|
| 2564 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2565 | - $last = $last[$j]; |
|
| 2566 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2567 | - |
|
| 2568 | - if ( |
|
| 2569 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2570 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2571 | - ) { |
|
| 2572 | - return $params; |
|
| 2573 | - } |
|
| 2574 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2575 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2576 | - $last = $params[$k][$j]; |
|
| 2577 | - $n = strlen($last->texte); |
|
| 2578 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2579 | - $newp = []; |
|
| 2580 | - foreach ($params as $v) { |
|
| 2581 | - if ($v[0]->type != 'texte') { |
|
| 2582 | - $newp[] = $v; |
|
| 2583 | - } else { |
|
| 2584 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2585 | - $t = new Texte(); |
|
| 2586 | - $t->texte = $x; |
|
| 2587 | - $newp[] = [$t]; |
|
| 2588 | - } |
|
| 2589 | - } |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - return $newp; |
|
| 2561 | + $deb = $params[0][0]; |
|
| 2562 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2563 | + $last = $params[$k]; |
|
| 2564 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2565 | + $last = $last[$j]; |
|
| 2566 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2567 | + |
|
| 2568 | + if ( |
|
| 2569 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2570 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2571 | + ) { |
|
| 2572 | + return $params; |
|
| 2573 | + } |
|
| 2574 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2575 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2576 | + $last = $params[$k][$j]; |
|
| 2577 | + $n = strlen($last->texte); |
|
| 2578 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2579 | + $newp = []; |
|
| 2580 | + foreach ($params as $v) { |
|
| 2581 | + if ($v[0]->type != 'texte') { |
|
| 2582 | + $newp[] = $v; |
|
| 2583 | + } else { |
|
| 2584 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2585 | + $t = new Texte(); |
|
| 2586 | + $t->texte = $x; |
|
| 2587 | + $newp[] = [$t]; |
|
| 2588 | + } |
|
| 2589 | + } |
|
| 2590 | + } |
|
| 2591 | + |
|
| 2592 | + return $newp; |
|
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 2595 | 2595 | /** |
@@ -2608,95 +2608,95 @@ discard block |
||
| 2608 | 2608 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2609 | 2609 | **/ |
| 2610 | 2610 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2611 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2612 | - return ''; |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - $boucle = $boucles[$idb]; |
|
| 2616 | - $table = $boucle->show; |
|
| 2617 | - |
|
| 2618 | - // si c'est une colonne de la table, ne rien faire |
|
| 2619 | - if (isset($table['field'][$col])) { |
|
| 2620 | - return ''; |
|
| 2621 | - } |
|
| 2622 | - |
|
| 2623 | - // Le type de critère à prendre en compte |
|
| 2624 | - $col = $regs[1]; |
|
| 2625 | - |
|
| 2626 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2627 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2628 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2629 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2630 | - if (isset($table['field']["date$suite"])) { |
|
| 2631 | - $date_orig = 'date' . $suite; |
|
| 2632 | - } else { |
|
| 2633 | - $date_orig = substr($suite, 1); |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - $pred = $date_orig; |
|
| 2637 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2638 | - // Si aucune déclaration trouvée, on quitte |
|
| 2639 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2640 | - return ''; |
|
| 2641 | - } |
|
| 2642 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2643 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2644 | - |
|
| 2645 | - // Si c'est pour du relatif |
|
| 2646 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2647 | - $pred = 'date'; |
|
| 2648 | - } |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2653 | - ") . '\""; |
|
| 2654 | - |
|
| 2655 | - $col_vraie = $date_orig; |
|
| 2656 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2657 | - |
|
| 2658 | - switch ($col) { |
|
| 2659 | - case 'date': |
|
| 2660 | - $col = $date_orig; |
|
| 2661 | - break; |
|
| 2662 | - case 'jour': |
|
| 2663 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2664 | - break; |
|
| 2665 | - case 'mois': |
|
| 2666 | - $col = "MONTH($date_orig)"; |
|
| 2667 | - break; |
|
| 2668 | - case 'annee': |
|
| 2669 | - $col = "YEAR($date_orig)"; |
|
| 2670 | - break; |
|
| 2671 | - case 'heure': |
|
| 2672 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2673 | - break; |
|
| 2674 | - case 'age': |
|
| 2675 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2676 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2677 | - break; |
|
| 2678 | - case 'age_relatif': |
|
| 2679 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'jour_relatif': |
|
| 2683 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | - break; |
|
| 2686 | - 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) |
|
| 2691 | - break; |
|
| 2692 | - case 'annee_relatif': |
|
| 2693 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | - $date_orig . ')'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | - break; |
|
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - return [$col, $col_vraie]; |
|
| 2611 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2612 | + return ''; |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + $boucle = $boucles[$idb]; |
|
| 2616 | + $table = $boucle->show; |
|
| 2617 | + |
|
| 2618 | + // si c'est une colonne de la table, ne rien faire |
|
| 2619 | + if (isset($table['field'][$col])) { |
|
| 2620 | + return ''; |
|
| 2621 | + } |
|
| 2622 | + |
|
| 2623 | + // Le type de critère à prendre en compte |
|
| 2624 | + $col = $regs[1]; |
|
| 2625 | + |
|
| 2626 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2627 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2628 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2629 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2630 | + if (isset($table['field']["date$suite"])) { |
|
| 2631 | + $date_orig = 'date' . $suite; |
|
| 2632 | + } else { |
|
| 2633 | + $date_orig = substr($suite, 1); |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + $pred = $date_orig; |
|
| 2637 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2638 | + // Si aucune déclaration trouvée, on quitte |
|
| 2639 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2640 | + return ''; |
|
| 2641 | + } |
|
| 2642 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2643 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2644 | + |
|
| 2645 | + // Si c'est pour du relatif |
|
| 2646 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2647 | + $pred = 'date'; |
|
| 2648 | + } |
|
| 2649 | + } |
|
| 2650 | + |
|
| 2651 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2653 | + ") . '\""; |
|
| 2654 | + |
|
| 2655 | + $col_vraie = $date_orig; |
|
| 2656 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2657 | + |
|
| 2658 | + switch ($col) { |
|
| 2659 | + case 'date': |
|
| 2660 | + $col = $date_orig; |
|
| 2661 | + break; |
|
| 2662 | + case 'jour': |
|
| 2663 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2664 | + break; |
|
| 2665 | + case 'mois': |
|
| 2666 | + $col = "MONTH($date_orig)"; |
|
| 2667 | + break; |
|
| 2668 | + case 'annee': |
|
| 2669 | + $col = "YEAR($date_orig)"; |
|
| 2670 | + break; |
|
| 2671 | + case 'heure': |
|
| 2672 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2673 | + break; |
|
| 2674 | + case 'age': |
|
| 2675 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2676 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2677 | + break; |
|
| 2678 | + case 'age_relatif': |
|
| 2679 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'jour_relatif': |
|
| 2683 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + break; |
|
| 2686 | + 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) |
|
| 2691 | + break; |
|
| 2692 | + case 'annee_relatif': |
|
| 2693 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | + $date_orig . ')'; |
|
| 2695 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | + break; |
|
| 2697 | + } |
|
| 2698 | + |
|
| 2699 | + return [$col, $col_vraie]; |
|
| 2700 | 2700 | } |
| 2701 | 2701 | |
| 2702 | 2702 | /** |
@@ -2715,16 +2715,16 @@ discard block |
||
| 2715 | 2715 | * de colonne SQL et une date. |
| 2716 | 2716 | **/ |
| 2717 | 2717 | function calculer_param_date($date_compare, $date_orig) { |
| 2718 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2719 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2720 | - $date_compare = '\'$x\''; |
|
| 2721 | - } else { |
|
| 2722 | - $init = $date_compare; |
|
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - return |
|
| 2726 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2727 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2718 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2719 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2720 | + $date_compare = '\'$x\''; |
|
| 2721 | + } else { |
|
| 2722 | + $init = $date_compare; |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + return |
|
| 2726 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2727 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2728 | 2728 | } |
| 2729 | 2729 | |
| 2730 | 2730 | /** |
@@ -2742,20 +2742,20 @@ discard block |
||
| 2742 | 2742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2743 | 2743 | */ |
| 2744 | 2744 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2745 | - $boucle = &$boucles[$idb]; |
|
| 2746 | - |
|
| 2747 | - $args = []; |
|
| 2748 | - foreach ($crit->param as &$param) { |
|
| 2749 | - array_push( |
|
| 2750 | - $args, |
|
| 2751 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2752 | - ); |
|
| 2753 | - } |
|
| 2745 | + $boucle = &$boucles[$idb]; |
|
| 2754 | 2746 | |
| 2755 | - $boucle->hash .= ' |
|
| 2747 | + $args = []; |
|
| 2748 | + foreach ($crit->param as &$param) { |
|
| 2749 | + array_push( |
|
| 2750 | + $args, |
|
| 2751 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2752 | + ); |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + $boucle->hash .= ' |
|
| 2756 | 2756 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2757 | 2757 | |
| 2758 | - $boucle->hash .= ' |
|
| 2758 | + $boucle->hash .= ' |
|
| 2759 | 2759 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2760 | 2760 | } |
| 2761 | 2761 | |
@@ -2773,8 +2773,8 @@ discard block |
||
| 2773 | 2773 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2774 | 2774 | */ |
| 2775 | 2775 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2776 | - $boucle = &$boucles[$idb]; |
|
| 2777 | - $boucle->hash .= ' |
|
| 2776 | + $boucle = &$boucles[$idb]; |
|
| 2777 | + $boucle->hash .= ' |
|
| 2778 | 2778 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2779 | 2779 | } |
| 2780 | 2780 | |
@@ -2790,12 +2790,12 @@ discard block |
||
| 2790 | 2790 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2791 | 2791 | */ |
| 2792 | 2792 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2793 | - $boucle = &$boucles[$idb]; |
|
| 2794 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2795 | - foreach ($crit->param as $param) { |
|
| 2796 | - $boucle->hash .= ' |
|
| 2793 | + $boucle = &$boucles[$idb]; |
|
| 2794 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2795 | + foreach ($crit->param as $param) { |
|
| 2796 | + $boucle->hash .= ' |
|
| 2797 | 2797 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2798 | - } |
|
| 2798 | + } |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | /** |
@@ -2812,16 +2812,16 @@ discard block |
||
| 2812 | 2812 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2813 | 2813 | */ |
| 2814 | 2814 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2815 | - $boucle = &$boucles[$idb]; |
|
| 2816 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2817 | - foreach ($crit->param as $param) { |
|
| 2818 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2819 | - $param, |
|
| 2820 | - $idb, |
|
| 2821 | - $boucles, |
|
| 2822 | - $boucles[$idb]->id_parent |
|
| 2823 | - ) . ";\n"; |
|
| 2824 | - } |
|
| 2815 | + $boucle = &$boucles[$idb]; |
|
| 2816 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2817 | + foreach ($crit->param as $param) { |
|
| 2818 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2819 | + $param, |
|
| 2820 | + $idb, |
|
| 2821 | + $boucles, |
|
| 2822 | + $boucles[$idb]->id_parent |
|
| 2823 | + ) . ";\n"; |
|
| 2824 | + } |
|
| 2825 | 2825 | } |
| 2826 | 2826 | |
| 2827 | 2827 | /** |
@@ -2846,16 +2846,16 @@ discard block |
||
| 2846 | 2846 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2847 | 2847 | */ |
| 2848 | 2848 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2849 | - $boucle = &$boucles[$idb]; |
|
| 2850 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2851 | - foreach ($crit->param as $param) { |
|
| 2852 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2853 | - $param, |
|
| 2854 | - $idb, |
|
| 2855 | - $boucles, |
|
| 2856 | - $boucles[$idb]->id_parent |
|
| 2857 | - ) . ";\n"; |
|
| 2858 | - } |
|
| 2849 | + $boucle = &$boucles[$idb]; |
|
| 2850 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2851 | + foreach ($crit->param as $param) { |
|
| 2852 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2853 | + $param, |
|
| 2854 | + $idb, |
|
| 2855 | + $boucles, |
|
| 2856 | + $boucles[$idb]->id_parent |
|
| 2857 | + ) . ";\n"; |
|
| 2858 | + } |
|
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | 2861 | /** |
@@ -2870,11 +2870,11 @@ discard block |
||
| 2870 | 2870 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2871 | 2871 | */ |
| 2872 | 2872 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2873 | - $boucle = &$boucles[$idb]; |
|
| 2874 | - foreach ($crit->param as $param) { |
|
| 2875 | - $boucle->hash .= ' |
|
| 2873 | + $boucle = &$boucles[$idb]; |
|
| 2874 | + foreach ($crit->param as $param) { |
|
| 2875 | + $boucle->hash .= ' |
|
| 2876 | 2876 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2877 | - } |
|
| 2877 | + } |
|
| 2878 | 2878 | } |
| 2879 | 2879 | |
| 2880 | 2880 | |
@@ -2906,20 +2906,20 @@ discard block |
||
| 2906 | 2906 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2907 | 2907 | */ |
| 2908 | 2908 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2909 | - $boucle = &$boucles[$idb]; |
|
| 2910 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2911 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2912 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2913 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2914 | - if ($crit->param) { |
|
| 2915 | - foreach ($crit->param as $param) { |
|
| 2916 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2917 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2918 | - } |
|
| 2919 | - // interdire {si 0} aussi ! |
|
| 2920 | - } else { |
|
| 2921 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2922 | - } |
|
| 2909 | + $boucle = &$boucles[$idb]; |
|
| 2910 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2911 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2912 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2913 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2914 | + if ($crit->param) { |
|
| 2915 | + foreach ($crit->param as $param) { |
|
| 2916 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2917 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2918 | + } |
|
| 2919 | + // interdire {si 0} aussi ! |
|
| 2920 | + } else { |
|
| 2921 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2922 | + } |
|
| 2923 | 2923 | } |
| 2924 | 2924 | |
| 2925 | 2925 | /** |
@@ -2936,8 +2936,8 @@ discard block |
||
| 2936 | 2936 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2937 | 2937 | */ |
| 2938 | 2938 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2939 | - $boucle = &$boucles[$idb]; |
|
| 2940 | - $boucle->hash .= ' |
|
| 2939 | + $boucle = &$boucles[$idb]; |
|
| 2940 | + $boucle->hash .= ' |
|
| 2941 | 2941 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2942 | 2942 | $command[\'sourcemode\'] = \'table\';'; |
| 2943 | 2943 | } |
@@ -2958,27 +2958,27 @@ discard block |
||
| 2958 | 2958 | */ |
| 2959 | 2959 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2960 | 2960 | |
| 2961 | - $not = $crit->not; |
|
| 2962 | - $boucle = &$boucles[$idb]; |
|
| 2963 | - $primary = $boucle->primary; |
|
| 2961 | + $not = $crit->not; |
|
| 2962 | + $boucle = &$boucles[$idb]; |
|
| 2963 | + $primary = $boucle->primary; |
|
| 2964 | 2964 | |
| 2965 | - if (!$primary or strpos($primary, ',')) { |
|
| 2966 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2965 | + if (!$primary or strpos($primary, ',')) { |
|
| 2966 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2967 | 2967 | |
| 2968 | - return; |
|
| 2969 | - } |
|
| 2970 | - $table = $boucle->type_requete; |
|
| 2971 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2968 | + return; |
|
| 2969 | + } |
|
| 2970 | + $table = $boucle->type_requete; |
|
| 2971 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2972 | 2972 | |
| 2973 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2973 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2974 | 2974 | |
| 2975 | - $in = 'IN'; |
|
| 2976 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | - if ($not) { |
|
| 2978 | - $where = ["'NOT'", $where]; |
|
| 2979 | - } |
|
| 2975 | + $in = 'IN'; |
|
| 2976 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | + if ($not) { |
|
| 2978 | + $where = ["'NOT'", $where]; |
|
| 2979 | + } |
|
| 2980 | 2980 | |
| 2981 | - $boucle->where[] = $where; |
|
| 2981 | + $boucle->where[] = $where; |
|
| 2982 | 2982 | } |
| 2983 | 2983 | |
| 2984 | 2984 | /** |
@@ -2994,8 +2994,8 @@ discard block |
||
| 2994 | 2994 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2995 | 2995 | */ |
| 2996 | 2996 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2997 | - $not = $crit->not; |
|
| 2998 | - $crit->not = $not ? false : true; |
|
| 2999 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3000 | - $crit->not = $not; |
|
| 2997 | + $not = $crit->not; |
|
| 2998 | + $crit->not = $not ? false : true; |
|
| 2999 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3000 | + $crit->not = $not; |
|
| 3001 | 3001 | } |
@@ -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 | } |
@@ -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 | } |