@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | define('_PHP_MAX', '8.2.99'); |
| 36 | 36 | |
| 37 | 37 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 38 | - /** le nom du repertoire ecrire/ */ |
|
| 39 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 38 | + /** le nom du repertoire ecrire/ */ |
|
| 39 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** Chemin relatif pour aller dans ecrire |
| 43 | 43 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 44 | 44 | define( |
| 45 | - '_DIR_RESTREINT', |
|
| 46 | - (is_dir(_DIR_RESTREINT_ABS) ? _DIR_RESTREINT_ABS : '') |
|
| 45 | + '_DIR_RESTREINT', |
|
| 46 | + (is_dir(_DIR_RESTREINT_ABS) ? _DIR_RESTREINT_ABS : '') |
|
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | 49 | /** Chemin relatif pour aller à la racine */ |
@@ -60,28 +60,28 @@ discard block |
||
| 60 | 60 | # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas) |
| 61 | 61 | # mais on peut les mettre ailleurs et changer completement les noms |
| 62 | 62 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 63 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 64 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 63 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 64 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 65 | 65 | } |
| 66 | 66 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 67 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 68 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 67 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 68 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 69 | 69 | } |
| 70 | 70 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 71 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 72 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 71 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 72 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 73 | 73 | } |
| 74 | 74 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 75 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 76 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 75 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 76 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // inclure l'ecran de securite si il n'a pas été inclus en prepend php |
| 80 | 80 | if ( |
| 81 | - !defined('_ECRAN_SECURITE') |
|
| 82 | - && @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 81 | + !defined('_ECRAN_SECURITE') |
|
| 82 | + && @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 83 | 83 | ) { |
| 84 | - include $f; |
|
| 84 | + include $f; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // et on peut lancer l'autoloader |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | // Icones |
| 91 | 91 | if (!defined('_NOM_IMG_PACK')) { |
| 92 | - /** Nom du dossier images */ |
|
| 93 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 92 | + /** Nom du dossier images */ |
|
| 93 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 94 | 94 | } |
| 95 | 95 | /** le chemin http (relatif) vers les images standard */ |
| 96 | 96 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 100 | 100 | |
| 101 | 101 | if (!defined('_JAVASCRIPT')) { |
| 102 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 103 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 102 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 103 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 104 | 104 | } // utilisable avec #CHEMIN et find_in_path |
| 105 | 105 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 106 | 106 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -108,28 +108,28 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | /** Le nom du fichier de personnalisation */ |
| 110 | 110 | if (!defined('_NOM_CONFIG')) { |
| 111 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 111 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Son emplacement absolu si on le trouve |
| 115 | 115 | if ( |
| 116 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 117 | - || @file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php') |
|
| 116 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 117 | + || @file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php') |
|
| 118 | 118 | ) { |
| 119 | - /** Emplacement absolu du fichier d'option */ |
|
| 120 | - define('_FILE_OPTIONS', $f); |
|
| 119 | + /** Emplacement absolu du fichier d'option */ |
|
| 120 | + define('_FILE_OPTIONS', $f); |
|
| 121 | 121 | } else { |
| 122 | - define('_FILE_OPTIONS', ''); |
|
| 122 | + define('_FILE_OPTIONS', ''); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | if (!defined('MODULES_IDIOMES')) { |
| 126 | - /** |
|
| 127 | - * Modules par défaut pour la traduction. |
|
| 128 | - * |
|
| 129 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 130 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 131 | - */ |
|
| 132 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 126 | + /** |
|
| 127 | + * Modules par défaut pour la traduction. |
|
| 128 | + * |
|
| 129 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 130 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 131 | + */ |
|
| 132 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // *** Fin des define *** // |
@@ -139,30 +139,30 @@ discard block |
||
| 139 | 139 | * Détecteur de robot d'indexation |
| 140 | 140 | */ |
| 141 | 141 | if (!defined('_IS_BOT')) { |
| 142 | - define( |
|
| 143 | - '_IS_BOT', |
|
| 144 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | - && preg_match( |
|
| 146 | - // mots generiques |
|
| 147 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | - . 'MSIE 6\.0|' |
|
| 150 | - // UA plus cibles |
|
| 151 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | - . ',i', |
|
| 153 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 142 | + define( |
|
| 143 | + '_IS_BOT', |
|
| 144 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | + && preg_match( |
|
| 146 | + // mots generiques |
|
| 147 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | + . 'MSIE 6\.0|' |
|
| 150 | + // UA plus cibles |
|
| 151 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | + . ',i', |
|
| 153 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | if (!defined('_IS_CLI')) { |
| 159 | - define( |
|
| 160 | - '_IS_CLI', |
|
| 161 | - !isset($_SERVER['HTTP_HOST']) |
|
| 162 | - && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 163 | - && !empty($_SERVER['argv']) |
|
| 164 | - && empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | - ); |
|
| 159 | + define( |
|
| 160 | + '_IS_CLI', |
|
| 161 | + !isset($_SERVER['HTTP_HOST']) |
|
| 162 | + && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 163 | + && !empty($_SERVER['argv']) |
|
| 164 | + && empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | + ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // *** Parametrage par defaut de SPIP *** |
@@ -174,61 +174,61 @@ discard block |
||
| 174 | 174 | // Ne pas les rendre indefinies. |
| 175 | 175 | |
| 176 | 176 | global |
| 177 | - $nombre_de_logs, |
|
| 178 | - $taille_des_logs, |
|
| 179 | - $table_prefix, |
|
| 180 | - $cookie_prefix, |
|
| 181 | - $dossier_squelettes, |
|
| 182 | - $filtrer_javascript, |
|
| 183 | - $type_urls, |
|
| 184 | - $debut_date_publication, |
|
| 185 | - $ip, |
|
| 186 | - $mysql_rappel_connexion, |
|
| 187 | - $mysql_rappel_nom_base, |
|
| 188 | - $test_i18n, |
|
| 189 | - $ignore_auth_http, |
|
| 190 | - $ignore_remote_user, |
|
| 191 | - $derniere_modif_invalide, |
|
| 192 | - $home_server, |
|
| 193 | - $help_server, |
|
| 194 | - $url_glossaire_externe, |
|
| 195 | - $tex_server, |
|
| 196 | - $traiter_math, |
|
| 197 | - $xhtml, |
|
| 198 | - $xml_indent, |
|
| 199 | - $source_vignettes, |
|
| 200 | - $formats_logos, |
|
| 201 | - $controler_dates_rss, |
|
| 202 | - $spip_pipeline, |
|
| 203 | - $spip_matrice, |
|
| 204 | - $plugins, |
|
| 205 | - $surcharges, |
|
| 206 | - $exceptions_des_tables, |
|
| 207 | - $tables_principales, |
|
| 208 | - $table_des_tables, |
|
| 209 | - $tables_auxiliaires, |
|
| 210 | - $table_primary, |
|
| 211 | - $table_date, |
|
| 212 | - $table_titre, |
|
| 213 | - $tables_jointures, |
|
| 214 | - $liste_des_statuts, |
|
| 215 | - $liste_des_etats, |
|
| 216 | - $liste_des_authentifications, |
|
| 217 | - $spip_version_branche, |
|
| 218 | - $spip_version_code, |
|
| 219 | - $spip_version_base, |
|
| 220 | - $spip_sql_version, |
|
| 221 | - $spip_version_affichee, |
|
| 222 | - $visiteur_session, |
|
| 223 | - $auteur_session, |
|
| 224 | - $connect_statut, |
|
| 225 | - $connect_toutes_rubriques, |
|
| 226 | - $hash_recherche, |
|
| 227 | - $hash_recherche_strict, |
|
| 228 | - $ldap_present, |
|
| 229 | - $meta, |
|
| 230 | - $connect_id_rubrique, |
|
| 231 | - $puce; |
|
| 177 | + $nombre_de_logs, |
|
| 178 | + $taille_des_logs, |
|
| 179 | + $table_prefix, |
|
| 180 | + $cookie_prefix, |
|
| 181 | + $dossier_squelettes, |
|
| 182 | + $filtrer_javascript, |
|
| 183 | + $type_urls, |
|
| 184 | + $debut_date_publication, |
|
| 185 | + $ip, |
|
| 186 | + $mysql_rappel_connexion, |
|
| 187 | + $mysql_rappel_nom_base, |
|
| 188 | + $test_i18n, |
|
| 189 | + $ignore_auth_http, |
|
| 190 | + $ignore_remote_user, |
|
| 191 | + $derniere_modif_invalide, |
|
| 192 | + $home_server, |
|
| 193 | + $help_server, |
|
| 194 | + $url_glossaire_externe, |
|
| 195 | + $tex_server, |
|
| 196 | + $traiter_math, |
|
| 197 | + $xhtml, |
|
| 198 | + $xml_indent, |
|
| 199 | + $source_vignettes, |
|
| 200 | + $formats_logos, |
|
| 201 | + $controler_dates_rss, |
|
| 202 | + $spip_pipeline, |
|
| 203 | + $spip_matrice, |
|
| 204 | + $plugins, |
|
| 205 | + $surcharges, |
|
| 206 | + $exceptions_des_tables, |
|
| 207 | + $tables_principales, |
|
| 208 | + $table_des_tables, |
|
| 209 | + $tables_auxiliaires, |
|
| 210 | + $table_primary, |
|
| 211 | + $table_date, |
|
| 212 | + $table_titre, |
|
| 213 | + $tables_jointures, |
|
| 214 | + $liste_des_statuts, |
|
| 215 | + $liste_des_etats, |
|
| 216 | + $liste_des_authentifications, |
|
| 217 | + $spip_version_branche, |
|
| 218 | + $spip_version_code, |
|
| 219 | + $spip_version_base, |
|
| 220 | + $spip_sql_version, |
|
| 221 | + $spip_version_affichee, |
|
| 222 | + $visiteur_session, |
|
| 223 | + $auteur_session, |
|
| 224 | + $connect_statut, |
|
| 225 | + $connect_toutes_rubriques, |
|
| 226 | + $hash_recherche, |
|
| 227 | + $hash_recherche_strict, |
|
| 228 | + $ldap_present, |
|
| 229 | + $meta, |
|
| 230 | + $connect_id_rubrique, |
|
| 231 | + $puce; |
|
| 232 | 232 | |
| 233 | 233 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 234 | 234 | $nombre_de_logs = 4; |
@@ -283,48 +283,48 @@ discard block |
||
| 283 | 283 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 284 | 284 | // |
| 285 | 285 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 286 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | - } |
|
| 289 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | - } |
|
| 286 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | + } |
|
| 289 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | + } |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 294 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) && is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | - $_SERVER['HTTPS'] = 'on'; |
|
| 298 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | - if (str_contains((string) $host, ',')) { |
|
| 305 | - $h = explode(',', (string) $host); |
|
| 306 | - $host = trim(reset($h)); |
|
| 307 | - } |
|
| 308 | - // securite sur le contenu de l'entete |
|
| 309 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 294 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) && is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | + $_SERVER['HTTPS'] = 'on'; |
|
| 298 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | + if (str_contains((string) $host, ',')) { |
|
| 305 | + $h = explode(',', (string) $host); |
|
| 306 | + $host = trim(reset($h)); |
|
| 307 | + } |
|
| 308 | + // securite sur le contenu de l'entete |
|
| 309 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 311 | 311 | } |
| 312 | 312 | // |
| 313 | 313 | // On note le numero IP du client dans la variable $ip |
| 314 | 314 | // |
| 315 | 315 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 316 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | - if (str_contains((string) $ip, ',')) { |
|
| 318 | - $ip = explode(',', (string) $ip); |
|
| 319 | - $ip = reset($ip); |
|
| 320 | - } |
|
| 321 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | - if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | - } |
|
| 316 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | + if (str_contains((string) $ip, ',')) { |
|
| 318 | + $ip = explode(',', (string) $ip); |
|
| 319 | + $ip = reset($ip); |
|
| 320 | + } |
|
| 321 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | + if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 327 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 327 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -409,24 +409,24 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | // Liste des statuts. |
| 411 | 411 | $liste_des_statuts = [ |
| 412 | - 'info_administrateurs' => '0minirezo', |
|
| 413 | - 'info_redacteurs' => '1comite', |
|
| 414 | - 'info_visiteurs' => '6forum', |
|
| 415 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 412 | + 'info_administrateurs' => '0minirezo', |
|
| 413 | + 'info_redacteurs' => '1comite', |
|
| 414 | + 'info_visiteurs' => '6forum', |
|
| 415 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 416 | 416 | ]; |
| 417 | 417 | |
| 418 | 418 | $liste_des_etats = [ |
| 419 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | - 'texte_statut_publie' => 'publie', |
|
| 422 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | - 'texte_statut_refuse' => 'refuse' |
|
| 419 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | + 'texte_statut_publie' => 'publie', |
|
| 422 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | + 'texte_statut_refuse' => 'refuse' |
|
| 424 | 424 | ]; |
| 425 | 425 | |
| 426 | 426 | // liste des methodes d'authentifications |
| 427 | 427 | $liste_des_authentifications = [ |
| 428 | - 'spip' => 'spip', |
|
| 429 | - 'ldap' => 'ldap' |
|
| 428 | + 'spip' => 'spip', |
|
| 429 | + 'ldap' => 'ldap' |
|
| 430 | 430 | ]; |
| 431 | 431 | |
| 432 | 432 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | // Definition personnelles eventuelles |
| 477 | 477 | |
| 478 | 478 | if (_FILE_OPTIONS) { |
| 479 | - include_once _FILE_OPTIONS; |
|
| 479 | + include_once _FILE_OPTIONS; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 483 | - /** Masquer les warning */ |
|
| 484 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 483 | + /** Masquer les warning */ |
|
| 484 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | ErrorHandler::setup(SPIP_ERREUR_REPORT); |
@@ -495,10 +495,10 @@ discard block |
||
| 495 | 495 | // ===> on execute en neutralisant les messages d'erreur |
| 496 | 496 | |
| 497 | 497 | spip_initialisation_core( |
| 498 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 499 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 501 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 498 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 499 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 500 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 501 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 502 | 502 | ); |
| 503 | 503 | |
| 504 | 504 | |
@@ -508,71 +508,71 @@ discard block |
||
| 508 | 508 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 509 | 509 | |
| 510 | 510 | if (@is_readable(_CACHE_PLUGINS_OPT) && @is_readable(_CACHE_PLUGINS_PATH)) { |
| 511 | - // chargement optimise precompile |
|
| 512 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 511 | + // chargement optimise precompile |
|
| 512 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 513 | 513 | } else { |
| 514 | - spip_initialisation_suite(); |
|
| 515 | - include_spip('inc/plugin'); |
|
| 516 | - // generer les fichiers php precompiles |
|
| 517 | - // de chargement des plugins et des pipelines |
|
| 518 | - actualise_plugins_actifs(); |
|
| 514 | + spip_initialisation_suite(); |
|
| 515 | + include_spip('inc/plugin'); |
|
| 516 | + // generer les fichiers php precompiles |
|
| 517 | + // de chargement des plugins et des pipelines |
|
| 518 | + actualise_plugins_actifs(); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // Initialisations non critiques surchargeables par les plugins |
| 522 | 522 | spip_initialisation_suite(); |
| 523 | 523 | |
| 524 | 524 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 525 | - /** niveau maxi d'enregistrement des logs */ |
|
| 526 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 525 | + /** niveau maxi d'enregistrement des logs */ |
|
| 526 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 530 | - /** Activer des outils pour développeurs ? */ |
|
| 531 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 530 | + /** Activer des outils pour développeurs ? */ |
|
| 531 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 535 | 535 | if (test_espace_prive()) { |
| 536 | - include_spip('inc/autoriser'); |
|
| 536 | + include_spip('inc/autoriser'); |
|
| 537 | 537 | } |
| 538 | 538 | // |
| 539 | 539 | // Installer Spip si pas installe... sauf si justement on est en train |
| 540 | 540 | // |
| 541 | 541 | if ( |
| 542 | - !(_FILE_CONNECT |
|
| 543 | - || autoriser_sans_cookie(_request('exec')) |
|
| 544 | - || _request('action') == 'cookie' |
|
| 545 | - || _request('action') == 'converser' |
|
| 546 | - || _request('action') == 'test_dirs') |
|
| 542 | + !(_FILE_CONNECT |
|
| 543 | + || autoriser_sans_cookie(_request('exec')) |
|
| 544 | + || _request('action') == 'cookie' |
|
| 545 | + || _request('action') == 'converser' |
|
| 546 | + || _request('action') == 'test_dirs') |
|
| 547 | 547 | ) { |
| 548 | - // Si on peut installer, on lance illico |
|
| 549 | - if (test_espace_prive()) { |
|
| 550 | - include_spip('inc/headers'); |
|
| 551 | - redirige_url_ecrire('install'); |
|
| 552 | - } else { |
|
| 553 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 554 | - include_spip('inc/lang'); |
|
| 555 | - utiliser_langue_visiteur(); |
|
| 556 | - include_spip('inc/minipres'); |
|
| 557 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 558 | - exit; |
|
| 559 | - } |
|
| 560 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 548 | + // Si on peut installer, on lance illico |
|
| 549 | + if (test_espace_prive()) { |
|
| 550 | + include_spip('inc/headers'); |
|
| 551 | + redirige_url_ecrire('install'); |
|
| 552 | + } else { |
|
| 553 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 554 | + include_spip('inc/lang'); |
|
| 555 | + utiliser_langue_visiteur(); |
|
| 556 | + include_spip('inc/minipres'); |
|
| 557 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 558 | + exit; |
|
| 559 | + } |
|
| 560 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // memoriser un tri sessionne eventuel |
| 564 | 564 | if ( |
| 565 | - isset($_REQUEST['var_memotri']) |
|
| 566 | - && ($t = $_REQUEST['var_memotri']) |
|
| 567 | - && (str_starts_with((string) $t, 'trisession') || str_starts_with((string) $t, 'senssession')) |
|
| 565 | + isset($_REQUEST['var_memotri']) |
|
| 566 | + && ($t = $_REQUEST['var_memotri']) |
|
| 567 | + && (str_starts_with((string) $t, 'trisession') || str_starts_with((string) $t, 'senssession')) |
|
| 568 | 568 | ) { |
| 569 | - if (!function_exists('session_set')) { |
|
| 570 | - include_spip('inc/session'); |
|
| 571 | - } |
|
| 572 | - $t = preg_replace(',\W,', '_', (string) $t); |
|
| 573 | - if ($v = _request($t)) { |
|
| 574 | - session_set($t, $v); |
|
| 575 | - } |
|
| 569 | + if (!function_exists('session_set')) { |
|
| 570 | + include_spip('inc/session'); |
|
| 571 | + } |
|
| 572 | + $t = preg_replace(',\W,', '_', (string) $t); |
|
| 573 | + if ($v = _request($t)) { |
|
| 574 | + session_set($t, $v); |
|
| 575 | + } |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -582,22 +582,22 @@ discard block |
||
| 582 | 582 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 583 | 583 | */ |
| 584 | 584 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 585 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 585 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 586 | 586 | } |
| 587 | 587 | if (!headers_sent() && _HEADER_COMPOSED_BY) { |
| 588 | - if (!defined('_HEADER_VARY')) { |
|
| 589 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 590 | - } |
|
| 591 | - if (_HEADER_VARY) { |
|
| 592 | - header(_HEADER_VARY); |
|
| 593 | - } |
|
| 594 | - if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 595 | - include_spip('inc/filtres_mini'); |
|
| 596 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 597 | - } else { |
|
| 598 | - // header minimal |
|
| 599 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 600 | - } |
|
| 588 | + if (!defined('_HEADER_VARY')) { |
|
| 589 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 590 | + } |
|
| 591 | + if (_HEADER_VARY) { |
|
| 592 | + header(_HEADER_VARY); |
|
| 593 | + } |
|
| 594 | + if (!isset($GLOBALS['spip_header_silencieux']) || !$GLOBALS['spip_header_silencieux']) { |
|
| 595 | + include_spip('inc/filtres_mini'); |
|
| 596 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 597 | + } else { |
|
| 598 | + // header minimal |
|
| 599 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 600 | + } |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function generer_nom_fichier_cache($contexte, $page) { |
| 27 | - $u = md5(var_export([$contexte, $page], true)); |
|
| 27 | + $u = md5(var_export([$contexte, $page], true)); |
|
| 28 | 28 | |
| 29 | - return $u . '.cache'; |
|
| 29 | + return $u . '.cache'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | 44 | function cache_chemin_fichier($nom_cache, $ecrire = false) { |
| 45 | - static $l1, $l2; |
|
| 46 | - if (is_null($l1)) { |
|
| 47 | - $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 48 | - $l1 = (int) floor($length / 2); |
|
| 49 | - $l2 = $length - $l1; |
|
| 50 | - } |
|
| 51 | - $d = substr((string) $nom_cache, 0, $l1); |
|
| 52 | - $u = substr((string) $nom_cache, $l1, $l2); |
|
| 53 | - |
|
| 54 | - if ($ecrire) { |
|
| 55 | - $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 56 | - $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 57 | - $rep = sous_repertoire($rep, $d, false, true); |
|
| 58 | - } |
|
| 59 | - else { |
|
| 60 | - // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 61 | - $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $rep . $u . '.cache'; |
|
| 45 | + static $l1, $l2; |
|
| 46 | + if (is_null($l1)) { |
|
| 47 | + $length = (defined('_CACHE_PROFONDEUR_STOCKAGE') ? min(8, max(_CACHE_PROFONDEUR_STOCKAGE, 2)) : 4); |
|
| 48 | + $l1 = (int) floor($length / 2); |
|
| 49 | + $l2 = $length - $l1; |
|
| 50 | + } |
|
| 51 | + $d = substr((string) $nom_cache, 0, $l1); |
|
| 52 | + $u = substr((string) $nom_cache, $l1, $l2); |
|
| 53 | + |
|
| 54 | + if ($ecrire) { |
|
| 55 | + $rep = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 56 | + $rep = sous_repertoire($rep, 'calcul/', false, true); |
|
| 57 | + $rep = sous_repertoire($rep, $d, false, true); |
|
| 58 | + } |
|
| 59 | + else { |
|
| 60 | + // en lecture on essaye pas de creer les repertoires, on va au plus vite |
|
| 61 | + $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $rep . $u . '.cache'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | 74 | function ecrire_cache($nom_cache, $valeur) { |
| 75 | - return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 75 | + return ecrire_fichier(cache_chemin_fichier($nom_cache, true), serialize(['nom_cache' => $nom_cache, 'valeur' => $valeur])); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,33 +82,33 @@ discard block |
||
| 82 | 82 | * @return mixed |
| 83 | 83 | */ |
| 84 | 84 | function lire_cache($nom_cache) { |
| 85 | - $tmp = []; |
|
| 86 | - if ( |
|
| 87 | - file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 88 | - && lire_fichier($f, $tmp) |
|
| 89 | - && ($tmp = unserialize($tmp)) |
|
| 90 | - && $tmp['nom_cache'] == $nom_cache |
|
| 91 | - && isset($tmp['valeur']) |
|
| 92 | - ) { |
|
| 93 | - return $tmp['valeur']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return false; |
|
| 85 | + $tmp = []; |
|
| 86 | + if ( |
|
| 87 | + file_exists($f = cache_chemin_fichier($nom_cache)) |
|
| 88 | + && lire_fichier($f, $tmp) |
|
| 89 | + && ($tmp = unserialize($tmp)) |
|
| 90 | + && $tmp['nom_cache'] == $nom_cache |
|
| 91 | + && isset($tmp['valeur']) |
|
| 92 | + ) { |
|
| 93 | + return $tmp['valeur']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return false; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Parano : on signe le cache, afin d'interdire un hack d'injection |
| 100 | 100 | // dans notre memcache |
| 101 | 101 | function cache_signature(&$page) { |
| 102 | - if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 103 | - include_spip('inc/acces'); |
|
| 104 | - ecrire_meta( |
|
| 105 | - 'cache_signature', |
|
| 106 | - hash('sha256', $_SERVER['DOCUMENT_ROOT'] . ($_SERVER['SERVER_SIGNATURE'] ?? '') . creer_uniqid()), |
|
| 107 | - 'non' |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 102 | + if (!isset($GLOBALS['meta']['cache_signature'])) { |
|
| 103 | + include_spip('inc/acces'); |
|
| 104 | + ecrire_meta( |
|
| 105 | + 'cache_signature', |
|
| 106 | + hash('sha256', $_SERVER['DOCUMENT_ROOT'] . ($_SERVER['SERVER_SIGNATURE'] ?? '') . creer_uniqid()), |
|
| 107 | + 'non' |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | function gzip_page($page) { |
| 124 | - if (function_exists('gzcompress') && strlen((string) $page['texte']) > 16 * 1024) { |
|
| 125 | - $page['gz'] = true; |
|
| 126 | - $page['texte'] = gzcompress((string) $page['texte']); |
|
| 127 | - } else { |
|
| 128 | - $page['gz'] = false; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $page; |
|
| 124 | + if (function_exists('gzcompress') && strlen((string) $page['texte']) > 16 * 1024) { |
|
| 125 | + $page['gz'] = true; |
|
| 126 | + $page['texte'] = gzcompress((string) $page['texte']); |
|
| 127 | + } else { |
|
| 128 | + $page['gz'] = false; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $page; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | 143 | function gunzip_page(&$page) { |
| 144 | - if ($page['gz']) { |
|
| 145 | - $page['texte'] = gzuncompress($page['texte']); |
|
| 146 | - $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 147 | - } |
|
| 144 | + if ($page['gz']) { |
|
| 145 | + $page['texte'] = gzuncompress($page['texte']); |
|
| 146 | + $page['gz'] = false; // ne pas gzuncompress deux fois une meme page |
|
| 147 | + } |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -159,72 +159,72 @@ discard block |
||
| 159 | 159 | * -1 si il faut calculer sans stocker en cache |
| 160 | 160 | */ |
| 161 | 161 | function cache_valide(&$page, $date) { |
| 162 | - $now = $_SERVER['REQUEST_TIME']; |
|
| 163 | - |
|
| 164 | - // Apparition d'un nouvel article post-date ? |
|
| 165 | - if ( |
|
| 166 | - isset($GLOBALS['meta']['post_dates']) |
|
| 167 | - && $GLOBALS['meta']['post_dates'] == 'non' |
|
| 168 | - && isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 169 | - && $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 170 | - ) { |
|
| 171 | - spip_log('Un article post-date invalide le cache'); |
|
| 172 | - include_spip('inc/rubriques'); |
|
| 173 | - calculer_prochain_postdate(true); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if (defined('_VAR_NOCACHE') && _VAR_NOCACHE) { |
|
| 177 | - return -1; |
|
| 178 | - } |
|
| 179 | - if (isset($GLOBALS['meta']['cache_inhib']) && $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 180 | - return -1; |
|
| 181 | - } |
|
| 182 | - if (defined('_NO_CACHE')) { |
|
| 183 | - return (_NO_CACHE == 0 && !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 187 | - if (!$page || !isset($page['texte']) || !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 188 | - return _IS_BOT ? -1 : 1; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // controle de la signature |
|
| 192 | - if ($page['sig'] !== cache_signature($page)) { |
|
| 193 | - return _IS_BOT ? -1 : 1; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 197 | - // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 198 | - // Cache invalide par la meta 'derniere_modif' |
|
| 199 | - // sauf pour les bots, qui utilisent toujours le cache |
|
| 200 | - if ( |
|
| 201 | - (!isset($page['entetes']['X-Spip-Statique']) || $page['entetes']['X-Spip-Statique'] !== 'oui') |
|
| 202 | - && ( |
|
| 203 | - !_IS_BOT |
|
| 204 | - && $GLOBALS['derniere_modif_invalide'] |
|
| 205 | - && isset($GLOBALS['meta']['derniere_modif']) |
|
| 206 | - && $date < $GLOBALS['meta']['derniere_modif'] |
|
| 207 | - ) |
|
| 208 | - ) { |
|
| 209 | - return 1; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Sinon comparer l'age du fichier a sa duree de cache |
|
| 213 | - $duree = (int) $page['entetes']['X-Spip-Cache']; |
|
| 214 | - $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 215 | - if ($duree == 0) { #CACHE{0} |
|
| 216 | - return -1; |
|
| 217 | - } // sauf pour les bots, qui utilisent toujours le cache |
|
| 218 | - else { |
|
| 219 | - if ( |
|
| 220 | - !_IS_BOT && $date + $duree < $now |
|
| 221 | - || $date < $cache_mark |
|
| 222 | - ) { |
|
| 223 | - return _IS_BOT ? -1 : 1; |
|
| 224 | - } else { |
|
| 225 | - return 0; |
|
| 226 | - } |
|
| 227 | - } |
|
| 162 | + $now = $_SERVER['REQUEST_TIME']; |
|
| 163 | + |
|
| 164 | + // Apparition d'un nouvel article post-date ? |
|
| 165 | + if ( |
|
| 166 | + isset($GLOBALS['meta']['post_dates']) |
|
| 167 | + && $GLOBALS['meta']['post_dates'] == 'non' |
|
| 168 | + && isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 169 | + && $now > $GLOBALS['meta']['date_prochain_postdate'] |
|
| 170 | + ) { |
|
| 171 | + spip_log('Un article post-date invalide le cache'); |
|
| 172 | + include_spip('inc/rubriques'); |
|
| 173 | + calculer_prochain_postdate(true); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if (defined('_VAR_NOCACHE') && _VAR_NOCACHE) { |
|
| 177 | + return -1; |
|
| 178 | + } |
|
| 179 | + if (isset($GLOBALS['meta']['cache_inhib']) && $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) { |
|
| 180 | + return -1; |
|
| 181 | + } |
|
| 182 | + if (defined('_NO_CACHE')) { |
|
| 183 | + return (_NO_CACHE == 0 && !isset($page['texte'])) ? 1 : _NO_CACHE; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache) |
|
| 187 | + if (!$page || !isset($page['texte']) || !isset($page['entetes']['X-Spip-Cache'])) { |
|
| 188 | + return _IS_BOT ? -1 : 1; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // controle de la signature |
|
| 192 | + if ($page['sig'] !== cache_signature($page)) { |
|
| 193 | + return _IS_BOT ? -1 : 1; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // #CACHE{n,statique} => on n'invalide pas avec derniere_modif |
|
| 197 | + // cf. ecrire/public/balises.php, balise_CACHE_dist() |
|
| 198 | + // Cache invalide par la meta 'derniere_modif' |
|
| 199 | + // sauf pour les bots, qui utilisent toujours le cache |
|
| 200 | + if ( |
|
| 201 | + (!isset($page['entetes']['X-Spip-Statique']) || $page['entetes']['X-Spip-Statique'] !== 'oui') |
|
| 202 | + && ( |
|
| 203 | + !_IS_BOT |
|
| 204 | + && $GLOBALS['derniere_modif_invalide'] |
|
| 205 | + && isset($GLOBALS['meta']['derniere_modif']) |
|
| 206 | + && $date < $GLOBALS['meta']['derniere_modif'] |
|
| 207 | + ) |
|
| 208 | + ) { |
|
| 209 | + return 1; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Sinon comparer l'age du fichier a sa duree de cache |
|
| 213 | + $duree = (int) $page['entetes']['X-Spip-Cache']; |
|
| 214 | + $cache_mark = ($GLOBALS['meta']['cache_mark'] ?? 0); |
|
| 215 | + if ($duree == 0) { #CACHE{0} |
|
| 216 | + return -1; |
|
| 217 | + } // sauf pour les bots, qui utilisent toujours le cache |
|
| 218 | + else { |
|
| 219 | + if ( |
|
| 220 | + !_IS_BOT && $date + $duree < $now |
|
| 221 | + || $date < $cache_mark |
|
| 222 | + ) { |
|
| 223 | + return _IS_BOT ? -1 : 1; |
|
| 224 | + } else { |
|
| 225 | + return 0; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,59 +237,59 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function creer_cache(&$page, &$chemin_cache) { |
| 239 | 239 | |
| 240 | - // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 241 | - // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 242 | - // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 243 | - // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 244 | - if ( |
|
| 245 | - defined('_VAR_NOCACHE') && _VAR_NOCACHE |
|
| 246 | - || defined('spip_interdire_cache') |
|
| 247 | - ) { |
|
| 248 | - return; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 252 | - // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 253 | - if ( |
|
| 254 | - isset($page['invalideurs']) |
|
| 255 | - && isset($page['invalideurs']['session']) |
|
| 256 | - ) { |
|
| 257 | - // on verifie que le contenu du chemin cache indique seulement |
|
| 258 | - // "cache sessionne" ; sa date indique la date de validite |
|
| 259 | - // des caches sessionnes |
|
| 260 | - if (!$tmp = lire_cache($chemin_cache)) { |
|
| 261 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 262 | - $tmp = [ |
|
| 263 | - 'invalideurs' => ['session' => ''], |
|
| 264 | - 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 265 | - ]; |
|
| 266 | - ecrire_cache($chemin_cache, $tmp); |
|
| 267 | - } |
|
| 268 | - $chemin_cache = generer_nom_fichier_cache( |
|
| 269 | - ['chemin_cache' => $chemin_cache], |
|
| 270 | - ['session' => $page['invalideurs']['session']] |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // ajouter la date de production dans le cache lui meme |
|
| 275 | - // (qui contient deja sa duree de validite) |
|
| 276 | - $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 277 | - |
|
| 278 | - // compresser le contenu si besoin |
|
| 279 | - $pagez = gzip_page($page); |
|
| 280 | - |
|
| 281 | - // signer le contenu |
|
| 282 | - $pagez['sig'] = cache_signature($pagez); |
|
| 283 | - |
|
| 284 | - // l'enregistrer, compresse ou non... |
|
| 285 | - $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 286 | - |
|
| 287 | - spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 288 | - . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 289 | - |
|
| 290 | - // Inserer ses invalideurs |
|
| 291 | - include_spip('inc/invalideur'); |
|
| 292 | - maj_invalideurs($chemin_cache, $page); |
|
| 240 | + // Ne rien faire si on est en preview, debug, ou si une erreur |
|
| 241 | + // grave s'est presentee (compilation du squelette, MySQL, etc) |
|
| 242 | + // le cas var_nocache ne devrait jamais arriver ici (securite) |
|
| 243 | + // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable |
|
| 244 | + if ( |
|
| 245 | + defined('_VAR_NOCACHE') && _VAR_NOCACHE |
|
| 246 | + || defined('spip_interdire_cache') |
|
| 247 | + ) { |
|
| 248 | + return; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // Si la page c1234 a un invalideur de session 'zz', sauver dans |
|
| 252 | + // 'tmp/cache/MD5(chemin_cache)_zz' |
|
| 253 | + if ( |
|
| 254 | + isset($page['invalideurs']) |
|
| 255 | + && isset($page['invalideurs']['session']) |
|
| 256 | + ) { |
|
| 257 | + // on verifie que le contenu du chemin cache indique seulement |
|
| 258 | + // "cache sessionne" ; sa date indique la date de validite |
|
| 259 | + // des caches sessionnes |
|
| 260 | + if (!$tmp = lire_cache($chemin_cache)) { |
|
| 261 | + spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 262 | + $tmp = [ |
|
| 263 | + 'invalideurs' => ['session' => ''], |
|
| 264 | + 'lastmodified' => $_SERVER['REQUEST_TIME'] |
|
| 265 | + ]; |
|
| 266 | + ecrire_cache($chemin_cache, $tmp); |
|
| 267 | + } |
|
| 268 | + $chemin_cache = generer_nom_fichier_cache( |
|
| 269 | + ['chemin_cache' => $chemin_cache], |
|
| 270 | + ['session' => $page['invalideurs']['session']] |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // ajouter la date de production dans le cache lui meme |
|
| 275 | + // (qui contient deja sa duree de validite) |
|
| 276 | + $page['lastmodified'] = $_SERVER['REQUEST_TIME']; |
|
| 277 | + |
|
| 278 | + // compresser le contenu si besoin |
|
| 279 | + $pagez = gzip_page($page); |
|
| 280 | + |
|
| 281 | + // signer le contenu |
|
| 282 | + $pagez['sig'] = cache_signature($pagez); |
|
| 283 | + |
|
| 284 | + // l'enregistrer, compresse ou non... |
|
| 285 | + $ok = ecrire_cache($chemin_cache, $pagez); |
|
| 286 | + |
|
| 287 | + spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 288 | + . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 289 | + |
|
| 290 | + // Inserer ses invalideurs |
|
| 291 | + include_spip('inc/invalideur'); |
|
| 292 | + maj_invalideurs($chemin_cache, $page); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -302,15 +302,15 @@ discard block |
||
| 302 | 302 | * @return void |
| 303 | 303 | */ |
| 304 | 304 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 305 | - // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 306 | - $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 307 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 308 | - foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 309 | - if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 310 | - spip_unlink($f); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - } |
|
| 305 | + // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
|
| 306 | + $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
|
| 307 | + if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 308 | + foreach (preg_files($dircache, '[.]txt$') as $f) { |
|
| 309 | + if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
|
| 310 | + spip_unlink($f); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
@@ -338,132 +338,132 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) { |
| 340 | 340 | |
| 341 | - # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 342 | - # $use_cache = -1; return; |
|
| 343 | - |
|
| 344 | - // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 345 | - if (isset($chemin_cache)) { |
|
| 346 | - creer_cache($page, $chemin_cache); |
|
| 347 | - return; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - // Toute la suite correspond au premier appel |
|
| 351 | - $contexte_implicite = $page['contexte_implicite']; |
|
| 352 | - |
|
| 353 | - // Cas ignorant le cache car completement dynamique |
|
| 354 | - if ( |
|
| 355 | - !empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' |
|
| 356 | - || _request('connect') |
|
| 357 | - ) { |
|
| 358 | - $use_cache = -1; |
|
| 359 | - $lastmodified = 0; |
|
| 360 | - $chemin_cache = ''; |
|
| 361 | - $page = []; |
|
| 362 | - |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Controler l'existence d'un cache nous correspondant |
|
| 367 | - $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 368 | - $lastmodified = 0; |
|
| 369 | - |
|
| 370 | - // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 371 | - if (!$page = lire_cache($chemin_cache)) { |
|
| 372 | - $page = []; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // s'il est sessionne, charger celui correspondant a notre session |
|
| 376 | - if ( |
|
| 377 | - isset($page['invalideurs']) |
|
| 378 | - && isset($page['invalideurs']['session']) |
|
| 379 | - ) { |
|
| 380 | - $chemin_cache_session = generer_nom_fichier_cache( |
|
| 381 | - ['chemin_cache' => $chemin_cache], |
|
| 382 | - ['session' => spip_session()] |
|
| 383 | - ); |
|
| 384 | - if ( |
|
| 385 | - ($page_session = lire_cache($chemin_cache_session)) && $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 386 | - ) { |
|
| 387 | - $page = $page_session; |
|
| 388 | - } else { |
|
| 389 | - $page = []; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 395 | - // ne le faire que si la base est disponible |
|
| 396 | - if (isset($GLOBALS['meta']['invalider']) && spip_connect()) { |
|
| 397 | - include_spip('inc/invalideur'); |
|
| 398 | - retire_caches($chemin_cache); |
|
| 399 | - # API invalideur inutile |
|
| 400 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 401 | - if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 402 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 407 | - // on supprime le cache |
|
| 408 | - if ( |
|
| 409 | - defined('_VAR_MODE') && |
|
| 410 | - _VAR_MODE && |
|
| 411 | - (isset($_COOKIE['spip_session']) || |
|
| 412 | - isset($_COOKIE['spip_admin']) || |
|
| 413 | - @file_exists(_ACCESS_FILE_NAME)) |
|
| 414 | - ) { |
|
| 415 | - $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 416 | - include_spip('inc/invalideur'); |
|
| 417 | - retire_caches($chemin_cache); # API invalideur inutile |
|
| 418 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 419 | - if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 420 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // $delais par defaut |
|
| 425 | - // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 426 | - // qui sont a cache nul par defaut |
|
| 427 | - if (!isset($GLOBALS['delais'])) { |
|
| 428 | - if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 429 | - define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 430 | - } |
|
| 431 | - $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // determiner la validite de la page |
|
| 435 | - if ($page) { |
|
| 436 | - $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 437 | - // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 438 | - // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 439 | - $page['contexte_implicite'] = $contexte_implicite; |
|
| 440 | - if (!$use_cache) { |
|
| 441 | - // $page est un cache utilisable |
|
| 442 | - gunzip_page($page); |
|
| 443 | - |
|
| 444 | - return; |
|
| 445 | - } |
|
| 446 | - } else { |
|
| 447 | - $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 448 | - $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 452 | - if (!spip_connect()) { |
|
| 453 | - if (isset($page['texte'])) { |
|
| 454 | - gunzip_page($page); |
|
| 455 | - $use_cache = 0; |
|
| 456 | - } else { |
|
| 457 | - spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 458 | - include_spip('inc/minipres'); |
|
| 459 | - |
|
| 460 | - return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - if ($use_cache < 0) { |
|
| 465 | - $chemin_cache = ''; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - return; |
|
| 341 | + # fonction de cache minimale : dire "non on ne met rien en cache" |
|
| 342 | + # $use_cache = -1; return; |
|
| 343 | + |
|
| 344 | + // Second appel, destine a l'enregistrement du cache sur le disque |
|
| 345 | + if (isset($chemin_cache)) { |
|
| 346 | + creer_cache($page, $chemin_cache); |
|
| 347 | + return; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + // Toute la suite correspond au premier appel |
|
| 351 | + $contexte_implicite = $page['contexte_implicite']; |
|
| 352 | + |
|
| 353 | + // Cas ignorant le cache car completement dynamique |
|
| 354 | + if ( |
|
| 355 | + !empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' |
|
| 356 | + || _request('connect') |
|
| 357 | + ) { |
|
| 358 | + $use_cache = -1; |
|
| 359 | + $lastmodified = 0; |
|
| 360 | + $chemin_cache = ''; |
|
| 361 | + $page = []; |
|
| 362 | + |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Controler l'existence d'un cache nous correspondant |
|
| 367 | + $chemin_cache = generer_nom_fichier_cache($contexte, $page); |
|
| 368 | + $lastmodified = 0; |
|
| 369 | + |
|
| 370 | + // charger le cache s'il existe (et si il a bien le bon hash = anticollision) |
|
| 371 | + if (!$page = lire_cache($chemin_cache)) { |
|
| 372 | + $page = []; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // s'il est sessionne, charger celui correspondant a notre session |
|
| 376 | + if ( |
|
| 377 | + isset($page['invalideurs']) |
|
| 378 | + && isset($page['invalideurs']['session']) |
|
| 379 | + ) { |
|
| 380 | + $chemin_cache_session = generer_nom_fichier_cache( |
|
| 381 | + ['chemin_cache' => $chemin_cache], |
|
| 382 | + ['session' => spip_session()] |
|
| 383 | + ); |
|
| 384 | + if ( |
|
| 385 | + ($page_session = lire_cache($chemin_cache_session)) && $page_session['lastmodified'] >= $page['lastmodified'] |
|
| 386 | + ) { |
|
| 387 | + $page = $page_session; |
|
| 388 | + } else { |
|
| 389 | + $page = []; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ? |
|
| 395 | + // ne le faire que si la base est disponible |
|
| 396 | + if (isset($GLOBALS['meta']['invalider']) && spip_connect()) { |
|
| 397 | + include_spip('inc/invalideur'); |
|
| 398 | + retire_caches($chemin_cache); |
|
| 399 | + # API invalideur inutile |
|
| 400 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 401 | + if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 402 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande, |
|
| 407 | + // on supprime le cache |
|
| 408 | + if ( |
|
| 409 | + defined('_VAR_MODE') && |
|
| 410 | + _VAR_MODE && |
|
| 411 | + (isset($_COOKIE['spip_session']) || |
|
| 412 | + isset($_COOKIE['spip_admin']) || |
|
| 413 | + @file_exists(_ACCESS_FILE_NAME)) |
|
| 414 | + ) { |
|
| 415 | + $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
|
| 416 | + include_spip('inc/invalideur'); |
|
| 417 | + retire_caches($chemin_cache); # API invalideur inutile |
|
| 418 | + supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 419 | + if (isset($chemin_cache_session) && $chemin_cache_session) { |
|
| 420 | + supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // $delais par defaut |
|
| 425 | + // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé |
|
| 426 | + // qui sont a cache nul par defaut |
|
| 427 | + if (!isset($GLOBALS['delais'])) { |
|
| 428 | + if (!defined('_DUREE_CACHE_DEFAUT')) { |
|
| 429 | + define('_DUREE_CACHE_DEFAUT', 24 * 3600); |
|
| 430 | + } |
|
| 431 | + $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // determiner la validite de la page |
|
| 435 | + if ($page) { |
|
| 436 | + $use_cache = cache_valide($page, $page['lastmodified'] ?? 0); |
|
| 437 | + // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence |
|
| 438 | + // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul |
|
| 439 | + $page['contexte_implicite'] = $contexte_implicite; |
|
| 440 | + if (!$use_cache) { |
|
| 441 | + // $page est un cache utilisable |
|
| 442 | + gunzip_page($page); |
|
| 443 | + |
|
| 444 | + return; |
|
| 445 | + } |
|
| 446 | + } else { |
|
| 447 | + $page = ['contexte_implicite' => $contexte_implicite]; |
|
| 448 | + $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + // Si pas valide mais pas de connexion a la base, le garder quand meme |
|
| 452 | + if (!spip_connect()) { |
|
| 453 | + if (isset($page['texte'])) { |
|
| 454 | + gunzip_page($page); |
|
| 455 | + $use_cache = 0; |
|
| 456 | + } else { |
|
| 457 | + spip_log("Erreur base de donnees, impossible utiliser $chemin_cache"); |
|
| 458 | + include_spip('inc/minipres'); |
|
| 459 | + |
|
| 460 | + return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + if ($use_cache < 0) { |
|
| 465 | + $chemin_cache = ''; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + return; |
|
| 469 | 469 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | function generer_nom_fichier_cache($contexte, $page) { |
| 27 | 27 | $u = md5(var_export([$contexte, $page], true)); |
| 28 | 28 | |
| 29 | - return $u . '.cache'; |
|
| 29 | + return $u.'.cache'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | else { |
| 60 | 60 | // en lecture on essaye pas de creer les repertoires, on va au plus vite |
| 61 | - $rep = _DIR_CACHE . "calcul/$d/"; |
|
| 61 | + $rep = _DIR_CACHE."calcul/$d/"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - return $rep . $u . '.cache'; |
|
| 64 | + return $rep.$u.'.cache'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | include_spip('inc/acces'); |
| 104 | 104 | ecrire_meta( |
| 105 | 105 | 'cache_signature', |
| 106 | - hash('sha256', $_SERVER['DOCUMENT_ROOT'] . ($_SERVER['SERVER_SIGNATURE'] ?? '') . creer_uniqid()), |
|
| 106 | + hash('sha256', $_SERVER['DOCUMENT_ROOT'].($_SERVER['SERVER_SIGNATURE'] ?? '').creer_uniqid()), |
|
| 107 | 107 | 'non' |
| 108 | 108 | ); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']); |
|
| 111 | + return crc32($GLOBALS['meta']['cache_signature'].$page['texte']); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | // "cache sessionne" ; sa date indique la date de validite |
| 259 | 259 | // des caches sessionnes |
| 260 | 260 | if (!$tmp = lire_cache($chemin_cache)) { |
| 261 | - spip_log('Creation cache sessionne ' . $chemin_cache); |
|
| 261 | + spip_log('Creation cache sessionne '.$chemin_cache); |
|
| 262 | 262 | $tmp = [ |
| 263 | 263 | 'invalideurs' => ['session' => ''], |
| 264 | 264 | 'lastmodified' => $_SERVER['REQUEST_TIME'] |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | // l'enregistrer, compresse ou non... |
| 285 | 285 | $ok = ecrire_cache($chemin_cache, $pagez); |
| 286 | 286 | |
| 287 | - spip_log((_IS_BOT ? 'Bot:' : '') . "Creation du cache $chemin_cache pour " |
|
| 288 | - . $page['entetes']['X-Spip-Cache'] . ' secondes' . ($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 287 | + spip_log((_IS_BOT ? 'Bot:' : '')."Creation du cache $chemin_cache pour " |
|
| 288 | + . $page['entetes']['X-Spip-Cache'].' secondes'.($ok ? '' : ' (erreur!)'), _LOG_INFO); |
|
| 289 | 289 | |
| 290 | 290 | // Inserer ses invalideurs |
| 291 | 291 | include_spip('inc/invalideur'); |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | function nettoyer_petit_cache($prefix, $duree = 300) { |
| 305 | 305 | // determiner le repertoire a purger : 'tmp/CACHE/rech/' |
| 306 | 306 | $dircache = sous_repertoire(_DIR_CACHE, $prefix); |
| 307 | - if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) { |
|
| 307 | + if (spip_touch($dircache.'purger_'.$prefix, $duree, true)) { |
|
| 308 | 308 | foreach (preg_files($dircache, '[.]txt$') as $f) { |
| 309 | 309 | if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) { |
| 310 | 310 | spip_unlink($f); |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | include_spip('inc/invalideur'); |
| 398 | 398 | retire_caches($chemin_cache); |
| 399 | 399 | # API invalideur inutile |
| 400 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 400 | + supprimer_fichier(_DIR_CACHE.$chemin_cache); |
|
| 401 | 401 | if (isset($chemin_cache_session) && $chemin_cache_session) { |
| 402 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 402 | + supprimer_fichier(_DIR_CACHE.$chemin_cache_session); |
|
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
@@ -415,9 +415,9 @@ discard block |
||
| 415 | 415 | $page = ['contexte_implicite' => $contexte_implicite]; // ignorer le cache deja lu |
| 416 | 416 | include_spip('inc/invalideur'); |
| 417 | 417 | retire_caches($chemin_cache); # API invalideur inutile |
| 418 | - supprimer_fichier(_DIR_CACHE . $chemin_cache); |
|
| 418 | + supprimer_fichier(_DIR_CACHE.$chemin_cache); |
|
| 419 | 419 | if (isset($chemin_cache_session) && $chemin_cache_session) { |
| 420 | - supprimer_fichier(_DIR_CACHE . $chemin_cache_session); |
|
| 420 | + supprimer_fichier(_DIR_CACHE.$chemin_cache_session); |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | **/ |
| 47 | 47 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 48 | 48 | |
| 49 | - $not = $crit->not; |
|
| 50 | - $boucle = &$boucles[$idb]; |
|
| 51 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | + $not = $crit->not; |
|
| 50 | + $boucle = &$boucles[$idb]; |
|
| 51 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 52 | 52 | |
| 53 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 53 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * @return void|array |
| 69 | 69 | **/ |
| 70 | 70 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 71 | - $not = $crit->not; |
|
| 72 | - $boucle = &$boucles[$idb]; |
|
| 73 | - $id = $boucle->primary; |
|
| 74 | - |
|
| 75 | - if ($not || !$id) { |
|
| 76 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | - } |
|
| 78 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 71 | + $not = $crit->not; |
|
| 72 | + $boucle = &$boucles[$idb]; |
|
| 73 | + $id = $boucle->primary; |
|
| 74 | + |
|
| 75 | + if ($not || !$id) { |
|
| 76 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | + } |
|
| 78 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -96,73 +96,73 @@ discard block |
||
| 96 | 96 | * @return void|array |
| 97 | 97 | **/ |
| 98 | 98 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 99 | - $boucle = &$boucles[$idb]; |
|
| 100 | - $primary = $boucle->primary; |
|
| 101 | - |
|
| 102 | - // la table nécessite une clé primaire, non composée |
|
| 103 | - if (!$primary || strpos((string) $primary, ',')) { |
|
| 104 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | - |
|
| 109 | - // le doublon s'applique sur un type de boucle (article) |
|
| 110 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | - |
|
| 112 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | - // on obtient $nom = "'article' . 'nom'" |
|
| 114 | - if (isset($crit->param[0])) { |
|
| 115 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | - |
|
| 122 | - // on crée un sql_in avec la clé primaire de la table |
|
| 123 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | - // $doublons et son index, ici $nom |
|
| 125 | - |
|
| 126 | - // debut du code "sql_in('articles.id_article', " |
|
| 127 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | - $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 131 | - |
|
| 132 | - // le debut complet du code des doublons |
|
| 133 | - $debut_doub = $debut_in . $debut_doub; |
|
| 134 | - |
|
| 135 | - // nom du doublon "('article' . 'nom')]" |
|
| 136 | - $fin_doub = "($nom)]"; |
|
| 137 | - |
|
| 138 | - // si on trouve un autre critère doublon, |
|
| 139 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | - foreach ($boucle->where as $k => $w) { |
|
| 141 | - if (str_starts_with((string) $w[0], $debut_doub)) { |
|
| 142 | - // fusionner le sql_in (du where) |
|
| 143 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 144 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | - $x = strpos((string) $boucle->hash, $init_comment); |
|
| 146 | - $len = strlen($init_comment); |
|
| 147 | - $boucle->hash = |
|
| 148 | - substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 149 | - |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | - |
|
| 157 | - // déclarer le doublon s'il n'existe pas encore |
|
| 158 | - $boucle->hash .= $init_comment . $init_code; |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | - # {!doublons A}{doublons B} |
|
| 164 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 99 | + $boucle = &$boucles[$idb]; |
|
| 100 | + $primary = $boucle->primary; |
|
| 101 | + |
|
| 102 | + // la table nécessite une clé primaire, non composée |
|
| 103 | + if (!$primary || strpos((string) $primary, ',')) { |
|
| 104 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | + |
|
| 109 | + // le doublon s'applique sur un type de boucle (article) |
|
| 110 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | + |
|
| 112 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | + // on obtient $nom = "'article' . 'nom'" |
|
| 114 | + if (isset($crit->param[0])) { |
|
| 115 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | + |
|
| 122 | + // on crée un sql_in avec la clé primaire de la table |
|
| 123 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | + // $doublons et son index, ici $nom |
|
| 125 | + |
|
| 126 | + // debut du code "sql_in('articles.id_article', " |
|
| 127 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | + $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 131 | + |
|
| 132 | + // le debut complet du code des doublons |
|
| 133 | + $debut_doub = $debut_in . $debut_doub; |
|
| 134 | + |
|
| 135 | + // nom du doublon "('article' . 'nom')]" |
|
| 136 | + $fin_doub = "($nom)]"; |
|
| 137 | + |
|
| 138 | + // si on trouve un autre critère doublon, |
|
| 139 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | + foreach ($boucle->where as $k => $w) { |
|
| 141 | + if (str_starts_with((string) $w[0], $debut_doub)) { |
|
| 142 | + // fusionner le sql_in (du where) |
|
| 143 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 144 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | + $x = strpos((string) $boucle->hash, $init_comment); |
|
| 146 | + $len = strlen($init_comment); |
|
| 147 | + $boucle->hash = |
|
| 148 | + substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 149 | + |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | + |
|
| 157 | + // déclarer le doublon s'il n'existe pas encore |
|
| 158 | + $boucle->hash .= $init_comment . $init_code; |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | + # {!doublons A}{doublons B} |
|
| 164 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | * @return void |
| 184 | 184 | **/ |
| 185 | 185 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 186 | - if (!isset($crit->param[1][0]) || !($param = $crit->param[1][0]->texte)) { |
|
| 187 | - $param = 'oui'; |
|
| 188 | - } |
|
| 189 | - if ($crit->not) { |
|
| 190 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | - } |
|
| 192 | - $boucle = &$boucles[$idb]; |
|
| 193 | - $boucle->lang_select = $param; |
|
| 186 | + if (!isset($crit->param[1][0]) || !($param = $crit->param[1][0]->texte)) { |
|
| 187 | + $param = 'oui'; |
|
| 188 | + } |
|
| 189 | + if ($crit->not) { |
|
| 190 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | + } |
|
| 192 | + $boucle = &$boucles[$idb]; |
|
| 193 | + $boucle->lang_select = $param; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | **/ |
| 214 | 214 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 215 | - [$un, $deux] = $crit->param; |
|
| 216 | - $un = $un[0]->texte; |
|
| 217 | - $deux = $deux[0]->texte; |
|
| 218 | - if ($deux) { |
|
| 219 | - $boucles[$idb]->limit = |
|
| 220 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | - } else { |
|
| 222 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | - } |
|
| 215 | + [$un, $deux] = $crit->param; |
|
| 216 | + $un = $un[0]->texte; |
|
| 217 | + $deux = $deux[0]->texte; |
|
| 218 | + if ($deux) { |
|
| 219 | + $boucles[$idb]->limit = |
|
| 220 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | + } else { |
|
| 222 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | + } |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -254,59 +254,59 @@ discard block |
||
| 254 | 254 | **/ |
| 255 | 255 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 256 | 256 | |
| 257 | - $boucle = &$boucles[$idb]; |
|
| 258 | - // definition de la taille de la page |
|
| 259 | - $pas = isset($crit->param[0][0]) |
|
| 260 | - ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 261 | - : "''"; |
|
| 262 | - |
|
| 263 | - if (!preg_match(_CODE_QUOTE, (string) $pas, $r)) { |
|
| 264 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | - } else { |
|
| 266 | - $r = (int) $r[2]; |
|
| 267 | - $pas = (string) ($r ?: 10); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Calcul du nommage de la pagination si il existe. |
|
| 271 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | - $type = "'$idb'"; |
|
| 274 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | - // Syntaxe {pagination 20, nom} |
|
| 276 | - if (isset($crit->param[0][1])) { |
|
| 277 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | - elseif (isset($crit->param[1][0])) { |
|
| 280 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 284 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | - $partie = |
|
| 286 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 289 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 290 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 291 | - . "\t}\n" |
|
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | - |
|
| 294 | - $boucle->hash .= ' |
|
| 257 | + $boucle = &$boucles[$idb]; |
|
| 258 | + // definition de la taille de la page |
|
| 259 | + $pas = isset($crit->param[0][0]) |
|
| 260 | + ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 261 | + : "''"; |
|
| 262 | + |
|
| 263 | + if (!preg_match(_CODE_QUOTE, (string) $pas, $r)) { |
|
| 264 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | + } else { |
|
| 266 | + $r = (int) $r[2]; |
|
| 267 | + $pas = (string) ($r ?: 10); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Calcul du nommage de la pagination si il existe. |
|
| 271 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | + $type = "'$idb'"; |
|
| 274 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | + // Syntaxe {pagination 20, nom} |
|
| 276 | + if (isset($crit->param[0][1])) { |
|
| 277 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | + elseif (isset($crit->param[1][0])) { |
|
| 280 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 284 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | + $partie = |
|
| 286 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 289 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 290 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 291 | + . "\t}\n" |
|
| 292 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | + |
|
| 294 | + $boucle->hash .= ' |
|
| 295 | 295 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 296 | 296 | |
| 297 | - $boucle->total_parties = $pas; |
|
| 298 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | - // sauf si pas de primaire, ou si primaire composee |
|
| 301 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | - if ( |
|
| 304 | - $boucle->primary |
|
| 305 | - && !preg_match('/[,\s]/', (string) $boucle->primary) |
|
| 306 | - && !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 297 | + $boucle->total_parties = $pas; |
|
| 298 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | + // sauf si pas de primaire, ou si primaire composee |
|
| 301 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | + if ( |
|
| 304 | + $boucle->primary |
|
| 305 | + && !preg_match('/[,\s]/', (string) $boucle->primary) |
|
| 306 | + && !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary || strpos((string) $boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 333 | + if (!$boucle->primary || strpos((string) $boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - [ |
|
| 397 | - "'OR'", |
|
| 398 | - [ |
|
| 399 | - "'AND'", |
|
| 400 | - ["'='", "'$table.id_trad'", 0], |
|
| 401 | - ["'='", "'$table.$prim'", $dprim] |
|
| 402 | - ], |
|
| 403 | - [ |
|
| 404 | - "'AND'", |
|
| 405 | - ["'>'", "'$table.id_trad'", 0], |
|
| 406 | - ["'='", "'$table.id_trad'", $arg] |
|
| 407 | - ] |
|
| 408 | - ]; |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + [ |
|
| 397 | + "'OR'", |
|
| 398 | + [ |
|
| 399 | + "'AND'", |
|
| 400 | + ["'='", "'$table.id_trad'", 0], |
|
| 401 | + ["'='", "'$table.$prim'", $dprim] |
|
| 402 | + ], |
|
| 403 | + [ |
|
| 404 | + "'AND'", |
|
| 405 | + ["'>'", "'$table.id_trad'", 0], |
|
| 406 | + ["'='", "'$table.id_trad'", $arg] |
|
| 407 | + ] |
|
| 408 | + ]; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - [ |
|
| 432 | - "'OR'", |
|
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | - ]; |
|
| 436 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + [ |
|
| 432 | + "'OR'", |
|
| 433 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | + ]; |
|
| 436 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,17 +450,17 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | - |
|
| 458 | - if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | - else { |
|
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | - } |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | + |
|
| 458 | + if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | + else { |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -491,38 +491,38 @@ discard block |
||
| 491 | 491 | **/ |
| 492 | 492 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 493 | 493 | |
| 494 | - $not = $crit->not; |
|
| 495 | - $boucle = &$boucles[$idb]; |
|
| 496 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | - if (isset($crit->param[0])) { |
|
| 498 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | - // sinon on le prend chez une boucle parente |
|
| 500 | - } else { |
|
| 501 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - //Trouver une jointure |
|
| 505 | - $champ = 'id_rubrique'; |
|
| 506 | - $desc = $boucle->show; |
|
| 507 | - //Seulement si necessaire |
|
| 508 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | - $decompose = decompose_champ_id_objet($champ); |
|
| 514 | - $champ = array_shift($decompose); |
|
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - $cle = $boucle->id_table; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = $crit->cond |
|
| 524 | - ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 525 | - : $c; |
|
| 494 | + $not = $crit->not; |
|
| 495 | + $boucle = &$boucles[$idb]; |
|
| 496 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | + if (isset($crit->param[0])) { |
|
| 498 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | + // sinon on le prend chez une boucle parente |
|
| 500 | + } else { |
|
| 501 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + //Trouver une jointure |
|
| 505 | + $champ = 'id_rubrique'; |
|
| 506 | + $desc = $boucle->show; |
|
| 507 | + //Seulement si necessaire |
|
| 508 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | + $decompose = decompose_champ_id_objet($champ); |
|
| 514 | + $champ = array_shift($decompose); |
|
| 515 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + $cle = $boucle->id_table; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | + $boucle->where[] = $crit->cond |
|
| 524 | + ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 525 | + : $c; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -538,15 +538,15 @@ discard block |
||
| 538 | 538 | **/ |
| 539 | 539 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 540 | 540 | |
| 541 | - $boucle = &$boucles[$idb]; |
|
| 542 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 543 | - $serveur = $boucle->sql_serveur; |
|
| 541 | + $boucle = &$boucles[$idb]; |
|
| 542 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 543 | + $serveur = $boucle->sql_serveur; |
|
| 544 | 544 | |
| 545 | - $c = "sql_in('" . |
|
| 546 | - $boucle->id_table . '.' . $boucle->primary |
|
| 547 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 545 | + $c = "sql_in('" . |
|
| 546 | + $boucle->id_table . '.' . $boucle->primary |
|
| 547 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 548 | 548 | |
| 549 | - $boucle->where[] = $c; |
|
| 549 | + $boucle->where[] = $c; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
@@ -568,31 +568,31 @@ discard block |
||
| 568 | 568 | * @return void|array |
| 569 | 569 | **/ |
| 570 | 570 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 571 | - if ($t = isset($crit->param[0])) { |
|
| 572 | - $t = $crit->param[0]; |
|
| 573 | - if ($t[0]->type == 'texte') { |
|
| 574 | - $t = $t[0]->texte; |
|
| 575 | - if (preg_match('/^(.*)\.(.*)$/', (string) $t, $r)) { |
|
| 576 | - $t = table_objet_sql($r[1]); |
|
| 577 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 578 | - if ($t) { |
|
| 579 | - $t .= '.' . $r[2]; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } else { |
|
| 583 | - $t = '".' |
|
| 584 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 585 | - . '."'; |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - if ($t) { |
|
| 589 | - $boucles[$idb]->group[] = $t; |
|
| 590 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 591 | - $boucles[$idb]->select[] = $t; |
|
| 592 | - } |
|
| 593 | - } else { |
|
| 594 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 595 | - } |
|
| 571 | + if ($t = isset($crit->param[0])) { |
|
| 572 | + $t = $crit->param[0]; |
|
| 573 | + if ($t[0]->type == 'texte') { |
|
| 574 | + $t = $t[0]->texte; |
|
| 575 | + if (preg_match('/^(.*)\.(.*)$/', (string) $t, $r)) { |
|
| 576 | + $t = table_objet_sql($r[1]); |
|
| 577 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 578 | + if ($t) { |
|
| 579 | + $t .= '.' . $r[2]; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } else { |
|
| 583 | + $t = '".' |
|
| 584 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 585 | + . '."'; |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + if ($t) { |
|
| 589 | + $boucles[$idb]->group[] = $t; |
|
| 590 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 591 | + $boucles[$idb]->select[] = $t; |
|
| 592 | + } |
|
| 593 | + } else { |
|
| 594 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 595 | + } |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | * @return void |
| 613 | 613 | **/ |
| 614 | 614 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 615 | - $boucles[$idb]->group = []; |
|
| 615 | + $boucles[$idb]->group = []; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -649,44 +649,44 @@ discard block |
||
| 649 | 649 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 650 | 650 | */ |
| 651 | 651 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 652 | - if (isset($crit->param[0])) { |
|
| 653 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 654 | - $boucle = $boucles[$idb]; |
|
| 655 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 656 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 657 | - if ($n && (!str_contains((string) $boucle->order[$n - 1], 'COLLATE'))) { |
|
| 658 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 659 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 660 | - if ( |
|
| 661 | - (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
|
| 662 | - || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
|
| 663 | - ) { |
|
| 664 | - $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 665 | - } else { |
|
| 666 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - } else { |
|
| 670 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 671 | - } |
|
| 652 | + if (isset($crit->param[0])) { |
|
| 653 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 654 | + $boucle = $boucles[$idb]; |
|
| 655 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 656 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 657 | + if ($n && (!str_contains((string) $boucle->order[$n - 1], 'COLLATE'))) { |
|
| 658 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 659 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 660 | + if ( |
|
| 661 | + (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
|
| 662 | + || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
|
| 663 | + ) { |
|
| 664 | + $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 665 | + } else { |
|
| 666 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + } else { |
|
| 670 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 671 | + } |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 675 | - $boucle = $boucles[$idb]; |
|
| 676 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | - $var = '$champs_' . $idb; |
|
| 678 | - $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
|
| 679 | - if (!$desc) { |
|
| 680 | - $desc = $boucle->show['field']; |
|
| 681 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 682 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 683 | - } |
|
| 684 | - if ($desc) { |
|
| 685 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 686 | - } |
|
| 687 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 688 | - |
|
| 689 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 675 | + $boucle = $boucles[$idb]; |
|
| 676 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | + $var = '$champs_' . $idb; |
|
| 678 | + $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
|
| 679 | + if (!$desc) { |
|
| 680 | + $desc = $boucle->show['field']; |
|
| 681 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 682 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 683 | + } |
|
| 684 | + if ($desc) { |
|
| 685 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 686 | + } |
|
| 687 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 688 | + |
|
| 689 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 726 | 726 | */ |
| 727 | 727 | function critere_par_dist($idb, &$boucles, $crit) { |
| 728 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 728 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -747,91 +747,91 @@ discard block |
||
| 747 | 747 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 748 | 748 | */ |
| 749 | 749 | function critere_parinverse($idb, &$boucles, $crit) { |
| 750 | - $boucle = &$boucles[$idb]; |
|
| 751 | - |
|
| 752 | - $sens = $collecte = ''; |
|
| 753 | - if ($crit->not) { |
|
| 754 | - $sens = " . ' DESC'"; |
|
| 755 | - } |
|
| 756 | - if (isset($boucle->modificateur['collate'])) { |
|
| 757 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - // Pour chaque paramètre du critère |
|
| 761 | - foreach ($crit->param as $tri) { |
|
| 762 | - $order = $fct = ''; |
|
| 763 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 764 | - if ($tri[0]->type != 'texte') { |
|
| 765 | - // calculer le order dynamique qui verifie les champs |
|
| 766 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 767 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 768 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 769 | - } |
|
| 770 | - // tris textuels {par titre} |
|
| 771 | - else { |
|
| 772 | - $par = array_shift($tri); |
|
| 773 | - $par = $par->texte; |
|
| 774 | - |
|
| 775 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 776 | - if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
|
| 777 | - $expression = trim($m[1]); |
|
| 778 | - $champ = trim($m[2]); |
|
| 779 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 780 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 781 | - } else { |
|
| 782 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 786 | - } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 787 | - // {par FONCTION(champ)} |
|
| 788 | - if (isset($match) && count($match) > 2) { |
|
| 789 | - $par = substr($match[2], 1, -1); |
|
| 790 | - $fct = $match[1]; |
|
| 791 | - } |
|
| 792 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 793 | - if ($par == 'hasard') { |
|
| 794 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 795 | - } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
|
| 796 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 797 | - } else { |
|
| 798 | - // cas général {par champ}, {par table.champ}, ... |
|
| 799 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // on ne sait pas traiter… |
|
| 804 | - else { |
|
| 805 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 809 | - if (is_array($order)) { |
|
| 810 | - return $order; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - if (preg_match('/^\'([^"]*)\'$/', (string) $order, $m)) { |
|
| 815 | - $t = $m[1]; |
|
| 816 | - if (strpos($t, '.') && !in_array($t, $boucle->select)) { |
|
| 817 | - $boucle->select[] = $t; |
|
| 818 | - } |
|
| 819 | - } else { |
|
| 820 | - $sens = ''; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - if ($fct) { |
|
| 824 | - $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
|
| 825 | - ? "'$fct(" . $r[1] . ")'" |
|
| 826 | - : "'$fct(' . $order . ')'"; |
|
| 827 | - } |
|
| 828 | - $t = $order . $collecte . $sens; |
|
| 829 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 830 | - $t = $r[1] . $r[2]; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - $boucle->order[] = $t; |
|
| 834 | - } |
|
| 750 | + $boucle = &$boucles[$idb]; |
|
| 751 | + |
|
| 752 | + $sens = $collecte = ''; |
|
| 753 | + if ($crit->not) { |
|
| 754 | + $sens = " . ' DESC'"; |
|
| 755 | + } |
|
| 756 | + if (isset($boucle->modificateur['collate'])) { |
|
| 757 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + // Pour chaque paramètre du critère |
|
| 761 | + foreach ($crit->param as $tri) { |
|
| 762 | + $order = $fct = ''; |
|
| 763 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 764 | + if ($tri[0]->type != 'texte') { |
|
| 765 | + // calculer le order dynamique qui verifie les champs |
|
| 766 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 767 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 768 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 769 | + } |
|
| 770 | + // tris textuels {par titre} |
|
| 771 | + else { |
|
| 772 | + $par = array_shift($tri); |
|
| 773 | + $par = $par->texte; |
|
| 774 | + |
|
| 775 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 776 | + if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
|
| 777 | + $expression = trim($m[1]); |
|
| 778 | + $champ = trim($m[2]); |
|
| 779 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 780 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 781 | + } else { |
|
| 782 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 786 | + } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 787 | + // {par FONCTION(champ)} |
|
| 788 | + if (isset($match) && count($match) > 2) { |
|
| 789 | + $par = substr($match[2], 1, -1); |
|
| 790 | + $fct = $match[1]; |
|
| 791 | + } |
|
| 792 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 793 | + if ($par == 'hasard') { |
|
| 794 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 795 | + } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
|
| 796 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 797 | + } else { |
|
| 798 | + // cas général {par champ}, {par table.champ}, ... |
|
| 799 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // on ne sait pas traiter… |
|
| 804 | + else { |
|
| 805 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 809 | + if (is_array($order)) { |
|
| 810 | + return $order; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + if (preg_match('/^\'([^"]*)\'$/', (string) $order, $m)) { |
|
| 815 | + $t = $m[1]; |
|
| 816 | + if (strpos($t, '.') && !in_array($t, $boucle->select)) { |
|
| 817 | + $boucle->select[] = $t; |
|
| 818 | + } |
|
| 819 | + } else { |
|
| 820 | + $sens = ''; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + if ($fct) { |
|
| 824 | + $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
|
| 825 | + ? "'$fct(" . $r[1] . ")'" |
|
| 826 | + : "'$fct(' . $order . ')'"; |
|
| 827 | + } |
|
| 828 | + $t = $order . $collecte . $sens; |
|
| 829 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 830 | + $t = $r[1] . $r[2]; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + $boucle->order[] = $t; |
|
| 834 | + } |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -845,13 +845,13 @@ discard block |
||
| 845 | 845 | * @return string Clause pour le Order by |
| 846 | 846 | */ |
| 847 | 847 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 848 | - $boucle = &$boucles[$idb]; |
|
| 849 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 850 | - $parha = 'rand() AS hasard'; |
|
| 851 | - if (!in_array($parha, $boucle->select)) { |
|
| 852 | - $boucle->select[] = $parha; |
|
| 853 | - } |
|
| 854 | - return "'hasard'"; |
|
| 848 | + $boucle = &$boucles[$idb]; |
|
| 849 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 850 | + $parha = 'rand() AS hasard'; |
|
| 851 | + if (!in_array($parha, $boucle->select)) { |
|
| 852 | + $boucle->select[] = $parha; |
|
| 853 | + } |
|
| 854 | + return "'hasard'"; |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -875,22 +875,22 @@ discard block |
||
| 875 | 875 | * @return string|array Clause pour le Order by (array si erreur) |
| 876 | 876 | */ |
| 877 | 877 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 878 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 879 | - if (is_array($_champ)) { |
|
| 880 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 881 | - } |
|
| 882 | - $boucle = &$boucles[$idb]; |
|
| 883 | - $texte = '0+' . $_champ; |
|
| 884 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 885 | - if ($suite !== "''") { |
|
| 886 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 887 | - } |
|
| 888 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 890 | - |
|
| 891 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 892 | - $orderassinum = trim($orderassinum, "'"); |
|
| 893 | - return "'$orderassinum, $asnum'"; |
|
| 878 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 879 | + if (is_array($_champ)) { |
|
| 880 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 881 | + } |
|
| 882 | + $boucle = &$boucles[$idb]; |
|
| 883 | + $texte = '0+' . $_champ; |
|
| 884 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 885 | + if ($suite !== "''") { |
|
| 886 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 887 | + } |
|
| 888 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 890 | + |
|
| 891 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 892 | + $orderassinum = trim($orderassinum, "'"); |
|
| 893 | + return "'$orderassinum, $asnum'"; |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | /** |
@@ -911,34 +911,34 @@ discard block |
||
| 911 | 911 | * @return string|array Clause pour le Order by (array si erreur) |
| 912 | 912 | */ |
| 913 | 913 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 914 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 915 | - if (is_array($_champ)) { |
|
| 916 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 917 | - } |
|
| 918 | - $boucle = &$boucles[$idb]; |
|
| 919 | - $texte = '0+' . $_champ; |
|
| 920 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 921 | - if ($suite !== "''") { |
|
| 922 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - $as = false; |
|
| 926 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 927 | - foreach ($boucle->select as $s) { |
|
| 928 | - if (str_starts_with((string) $s, $select)) { |
|
| 929 | - $as = trim(substr((string) $s, strlen($select))); |
|
| 930 | - if (!preg_match(',\W,', $as)) { |
|
| 931 | - break; |
|
| 932 | - } |
|
| 933 | - $as = false; |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - if (!$as) { |
|
| 938 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | - $boucle->select[] = $select . $as; |
|
| 940 | - } |
|
| 941 | - return "'$as'"; |
|
| 914 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 915 | + if (is_array($_champ)) { |
|
| 916 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 917 | + } |
|
| 918 | + $boucle = &$boucles[$idb]; |
|
| 919 | + $texte = '0+' . $_champ; |
|
| 920 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 921 | + if ($suite !== "''") { |
|
| 922 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + $as = false; |
|
| 926 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 927 | + foreach ($boucle->select as $s) { |
|
| 928 | + if (str_starts_with((string) $s, $select)) { |
|
| 929 | + $as = trim(substr((string) $s, strlen($select))); |
|
| 930 | + if (!preg_match(',\W,', $as)) { |
|
| 931 | + break; |
|
| 932 | + } |
|
| 933 | + $as = false; |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + if (!$as) { |
|
| 938 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | + $boucle->select[] = $select . $as; |
|
| 940 | + } |
|
| 941 | + return "'$as'"; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,13 +958,13 @@ 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 | - return "'multi'"; |
|
| 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 | + return "'multi'"; |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | /** |
@@ -983,56 +983,56 @@ discard block |
||
| 983 | 983 | * @return array|string |
| 984 | 984 | */ |
| 985 | 985 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 986 | - $boucle = &$boucles[$idb]; |
|
| 987 | - $desc = $boucle->show; |
|
| 988 | - |
|
| 989 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 990 | - if (isset($desc['field'][$par])) { |
|
| 991 | - $par = $boucle->id_table . '.' . $par; |
|
| 992 | - } |
|
| 993 | - // le champ est peut être une jointure |
|
| 994 | - else { |
|
| 995 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 996 | - $champ = $par; |
|
| 997 | - |
|
| 998 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 999 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1000 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1001 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1002 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1003 | - [, $table, $champ] = $r; |
|
| 1004 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1005 | - $table = table_objet_sql($table); |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1009 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1010 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1011 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1012 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1013 | - } elseif ( |
|
| 1014 | - $boucle->jointures_explicites |
|
| 1015 | - && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
|
| 1016 | - ) { |
|
| 1017 | - $par = $alias . '.' . $champ; |
|
| 1018 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1019 | - $par = $alias . '.' . $champ; |
|
| 1020 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1021 | - } elseif ( |
|
| 1022 | - $table_alias |
|
| 1023 | - && isset($boucle->from[$table_alias]) |
|
| 1024 | - && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
|
| 1025 | - ) { |
|
| 1026 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1027 | - } elseif ($table) { |
|
| 1028 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1029 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1030 | - } else { |
|
| 1031 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - return $raw ? $par : "'$par'"; |
|
| 986 | + $boucle = &$boucles[$idb]; |
|
| 987 | + $desc = $boucle->show; |
|
| 988 | + |
|
| 989 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 990 | + if (isset($desc['field'][$par])) { |
|
| 991 | + $par = $boucle->id_table . '.' . $par; |
|
| 992 | + } |
|
| 993 | + // le champ est peut être une jointure |
|
| 994 | + else { |
|
| 995 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 996 | + $champ = $par; |
|
| 997 | + |
|
| 998 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 999 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1000 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1001 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1002 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1003 | + [, $table, $champ] = $r; |
|
| 1004 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1005 | + $table = table_objet_sql($table); |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1009 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1010 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1011 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1012 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1013 | + } elseif ( |
|
| 1014 | + $boucle->jointures_explicites |
|
| 1015 | + && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
|
| 1016 | + ) { |
|
| 1017 | + $par = $alias . '.' . $champ; |
|
| 1018 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1019 | + $par = $alias . '.' . $champ; |
|
| 1020 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1021 | + } elseif ( |
|
| 1022 | + $table_alias |
|
| 1023 | + && isset($boucle->from[$table_alias]) |
|
| 1024 | + && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
|
| 1025 | + ) { |
|
| 1026 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1027 | + } elseif ($table) { |
|
| 1028 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1030 | + } else { |
|
| 1031 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + return $raw ? $par : "'$par'"; |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | 1038 | /** |
@@ -1057,33 +1057,33 @@ discard block |
||
| 1057 | 1057 | */ |
| 1058 | 1058 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1059 | 1059 | |
| 1060 | - $boucle = &$boucles[$idb]; |
|
| 1061 | - // Classement par ordre inverse |
|
| 1062 | - if ($crit->not) { |
|
| 1063 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1064 | - } else { |
|
| 1065 | - $order = "' DESC'"; |
|
| 1066 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1067 | - if (isset($crit->param[0])) { |
|
| 1068 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1069 | - $order = "(($critere)?' DESC':'')"; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1073 | - if (!$n) { |
|
| 1074 | - if (isset($boucle->default_order[0])) { |
|
| 1075 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1076 | - } else { |
|
| 1077 | - $boucle->default_order[] = ' DESC'; |
|
| 1078 | - } |
|
| 1079 | - } else { |
|
| 1080 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1081 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1082 | - $t = $r[1] . $r[2]; |
|
| 1083 | - } |
|
| 1084 | - $boucle->order[$n - 1] = $t; |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1060 | + $boucle = &$boucles[$idb]; |
|
| 1061 | + // Classement par ordre inverse |
|
| 1062 | + if ($crit->not) { |
|
| 1063 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1064 | + } else { |
|
| 1065 | + $order = "' DESC'"; |
|
| 1066 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1067 | + if (isset($crit->param[0])) { |
|
| 1068 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1069 | + $order = "(($critere)?' DESC':'')"; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1073 | + if (!$n) { |
|
| 1074 | + if (isset($boucle->default_order[0])) { |
|
| 1075 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1076 | + } else { |
|
| 1077 | + $boucle->default_order[] = ' DESC'; |
|
| 1078 | + } |
|
| 1079 | + } else { |
|
| 1080 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1081 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1082 | + $t = $r[1] . $r[2]; |
|
| 1083 | + } |
|
| 1084 | + $boucle->order[$n - 1] = $t; |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1095,139 +1095,139 @@ discard block |
||
| 1095 | 1095 | * @return void|array |
| 1096 | 1096 | */ |
| 1097 | 1097 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1098 | - $boucle = &$boucles[$idb]; |
|
| 1098 | + $boucle = &$boucles[$idb]; |
|
| 1099 | 1099 | |
| 1100 | - $sens = $collecte = ''; |
|
| 1101 | - if ($crit->not) { |
|
| 1102 | - $sens = " . ' DESC'"; |
|
| 1103 | - } |
|
| 1100 | + $sens = $collecte = ''; |
|
| 1101 | + if ($crit->not) { |
|
| 1102 | + $sens = " . ' DESC'"; |
|
| 1103 | + } |
|
| 1104 | 1104 | |
| 1105 | - $crit2 = clone $crit; |
|
| 1106 | - $crit2->not = false; |
|
| 1107 | - $crit2->param = [reset($crit->param)]; |
|
| 1108 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1105 | + $crit2 = clone $crit; |
|
| 1106 | + $crit2->not = false; |
|
| 1107 | + $crit2->param = [reset($crit->param)]; |
|
| 1108 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1109 | 1109 | |
| 1110 | - // erreur ? |
|
| 1111 | - if (is_array($res)) { |
|
| 1112 | - return $res; |
|
| 1113 | - } |
|
| 1110 | + // erreur ? |
|
| 1111 | + if (is_array($res)) { |
|
| 1112 | + return $res; |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | - $_order = array_pop($boucle->order); |
|
| 1115 | + $_order = array_pop($boucle->order); |
|
| 1116 | 1116 | |
| 1117 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1117 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1118 | 1118 | |
| 1119 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1120 | - $boucle->order[] = $order; |
|
| 1119 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1120 | + $boucle->order[] = $order; |
|
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | |
| 1124 | 1124 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1125 | - $params = $crit->param; |
|
| 1126 | - |
|
| 1127 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1128 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - $boucle = &$boucles[$idb]; |
|
| 1132 | - $parent = $boucle->id_parent; |
|
| 1133 | - $fields = $boucle->show['field']; |
|
| 1134 | - |
|
| 1135 | - $date = array_shift($params); |
|
| 1136 | - $type = array_shift($params); |
|
| 1137 | - |
|
| 1138 | - // la valeur $type doit etre connue a la compilation |
|
| 1139 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1140 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1141 | - |
|
| 1142 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1143 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1144 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1145 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1146 | - if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
|
| 1147 | - $date = $date[0]->texte; |
|
| 1148 | - if (!isset($fields[$date])) { |
|
| 1149 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1150 | - } |
|
| 1151 | - } else { |
|
| 1152 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1153 | - $noms = array_keys($fields); |
|
| 1154 | - $defaut = $noms[0]; |
|
| 1155 | - $noms = implode(' ', $noms); |
|
| 1156 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1157 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1158 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1159 | - } |
|
| 1160 | - $annee = $params ? array_shift($params) : ''; |
|
| 1161 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1162 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1163 | - ') ? $x : date("Y"))'; |
|
| 1164 | - |
|
| 1165 | - $mois = $params ? array_shift($params) : ''; |
|
| 1166 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1167 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1168 | - ') ? $x : date("m"))'; |
|
| 1169 | - |
|
| 1170 | - $jour = $params ? array_shift($params) : ''; |
|
| 1171 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1172 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1173 | - ') ? $x : date("d"))'; |
|
| 1174 | - |
|
| 1175 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1176 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1177 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1178 | - ') ? $x : date("Y"))'; |
|
| 1179 | - |
|
| 1180 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1181 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1182 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1183 | - ') ? $x : date("m"))'; |
|
| 1184 | - |
|
| 1185 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1186 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1187 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1188 | - ') ? $x : date("d"))'; |
|
| 1189 | - |
|
| 1190 | - $date = $boucle->id_table . ".$date"; |
|
| 1191 | - |
|
| 1192 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1193 | - if ($type == 'jour') { |
|
| 1194 | - $boucle->where[] = [ |
|
| 1195 | - "'='", |
|
| 1196 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1197 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1198 | - ]; |
|
| 1199 | - } elseif ($type == 'mois') { |
|
| 1200 | - $boucle->where[] = [ |
|
| 1201 | - "'='", |
|
| 1202 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1203 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1204 | - ]; |
|
| 1205 | - } elseif ($type == 'semaine') { |
|
| 1206 | - $boucle->where[] = [ |
|
| 1207 | - "'AND'", |
|
| 1208 | - [ |
|
| 1209 | - "'>='", |
|
| 1210 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1211 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1212 | - ], |
|
| 1213 | - [ |
|
| 1214 | - "'<='", |
|
| 1215 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1217 | - ] |
|
| 1218 | - ]; |
|
| 1219 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1220 | - $boucle->where[] = [ |
|
| 1221 | - "'AND'", |
|
| 1222 | - [ |
|
| 1223 | - "'>='", |
|
| 1224 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1225 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1226 | - ], |
|
| 1227 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1228 | - ]; |
|
| 1229 | - } |
|
| 1230 | - // sinon on prend tout |
|
| 1125 | + $params = $crit->param; |
|
| 1126 | + |
|
| 1127 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1128 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + $boucle = &$boucles[$idb]; |
|
| 1132 | + $parent = $boucle->id_parent; |
|
| 1133 | + $fields = $boucle->show['field']; |
|
| 1134 | + |
|
| 1135 | + $date = array_shift($params); |
|
| 1136 | + $type = array_shift($params); |
|
| 1137 | + |
|
| 1138 | + // la valeur $type doit etre connue a la compilation |
|
| 1139 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1140 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1141 | + |
|
| 1142 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1143 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1144 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1145 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1146 | + if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
|
| 1147 | + $date = $date[0]->texte; |
|
| 1148 | + if (!isset($fields[$date])) { |
|
| 1149 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1150 | + } |
|
| 1151 | + } else { |
|
| 1152 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1153 | + $noms = array_keys($fields); |
|
| 1154 | + $defaut = $noms[0]; |
|
| 1155 | + $noms = implode(' ', $noms); |
|
| 1156 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1157 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1158 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1159 | + } |
|
| 1160 | + $annee = $params ? array_shift($params) : ''; |
|
| 1161 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1162 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1163 | + ') ? $x : date("Y"))'; |
|
| 1164 | + |
|
| 1165 | + $mois = $params ? array_shift($params) : ''; |
|
| 1166 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1167 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1168 | + ') ? $x : date("m"))'; |
|
| 1169 | + |
|
| 1170 | + $jour = $params ? array_shift($params) : ''; |
|
| 1171 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1172 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1173 | + ') ? $x : date("d"))'; |
|
| 1174 | + |
|
| 1175 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1176 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1177 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1178 | + ') ? $x : date("Y"))'; |
|
| 1179 | + |
|
| 1180 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1181 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1182 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1183 | + ') ? $x : date("m"))'; |
|
| 1184 | + |
|
| 1185 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1186 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1187 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1188 | + ') ? $x : date("d"))'; |
|
| 1189 | + |
|
| 1190 | + $date = $boucle->id_table . ".$date"; |
|
| 1191 | + |
|
| 1192 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1193 | + if ($type == 'jour') { |
|
| 1194 | + $boucle->where[] = [ |
|
| 1195 | + "'='", |
|
| 1196 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1197 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1198 | + ]; |
|
| 1199 | + } elseif ($type == 'mois') { |
|
| 1200 | + $boucle->where[] = [ |
|
| 1201 | + "'='", |
|
| 1202 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1203 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1204 | + ]; |
|
| 1205 | + } elseif ($type == 'semaine') { |
|
| 1206 | + $boucle->where[] = [ |
|
| 1207 | + "'AND'", |
|
| 1208 | + [ |
|
| 1209 | + "'>='", |
|
| 1210 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1211 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1212 | + ], |
|
| 1213 | + [ |
|
| 1214 | + "'<='", |
|
| 1215 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1216 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1217 | + ] |
|
| 1218 | + ]; |
|
| 1219 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1220 | + $boucle->where[] = [ |
|
| 1221 | + "'AND'", |
|
| 1222 | + [ |
|
| 1223 | + "'>='", |
|
| 1224 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1225 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1226 | + ], |
|
| 1227 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1228 | + ]; |
|
| 1229 | + } |
|
| 1230 | + // sinon on prend tout |
|
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | |
@@ -1252,33 +1252,33 @@ discard block |
||
| 1252 | 1252 | * @return void |
| 1253 | 1253 | **/ |
| 1254 | 1254 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1255 | - $boucle = &$boucles[$idb]; |
|
| 1256 | - $a1 = $crit->param[0]; |
|
| 1257 | - $a2 = $crit->param[1]; |
|
| 1258 | - $op = $crit->op; |
|
| 1259 | - |
|
| 1260 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1261 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1262 | - |
|
| 1263 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1264 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1265 | - } else { |
|
| 1266 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1267 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1268 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1269 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1270 | - $mode = (($op == '/') ? '/' : |
|
| 1271 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1272 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1273 | - if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
|
| 1274 | - $boucle->limit = |
|
| 1275 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1276 | - . ".','." |
|
| 1277 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1278 | - } else { |
|
| 1279 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1255 | + $boucle = &$boucles[$idb]; |
|
| 1256 | + $a1 = $crit->param[0]; |
|
| 1257 | + $a2 = $crit->param[1]; |
|
| 1258 | + $op = $crit->op; |
|
| 1259 | + |
|
| 1260 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1261 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1262 | + |
|
| 1263 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1264 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1265 | + } else { |
|
| 1266 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1267 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1268 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1269 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1270 | + $mode = (($op == '/') ? '/' : |
|
| 1271 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1272 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1273 | + if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
|
| 1274 | + $boucle->limit = |
|
| 1275 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1276 | + . ".','." |
|
| 1277 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1278 | + } else { |
|
| 1279 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | /** |
@@ -1306,63 +1306,63 @@ discard block |
||
| 1306 | 1306 | * @return void |
| 1307 | 1307 | **/ |
| 1308 | 1308 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1309 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1310 | - |
|
| 1311 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1312 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1313 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1314 | - // {1/3} |
|
| 1315 | - if ($op1 == '/') { |
|
| 1316 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1317 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1318 | - "($total_parties ? $total_parties : 1)"; |
|
| 1319 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1320 | - $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
|
| 1321 | - } else { |
|
| 1322 | - // cas {n-1,x} |
|
| 1323 | - if ($op1 == '-') { |
|
| 1324 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - // cas {x,n-1} |
|
| 1328 | - if ($op2 == '-') { |
|
| 1329 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1330 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1331 | - ($total_parties . ' - 1')); |
|
| 1332 | - } else { |
|
| 1333 | - // {x,1} ou {pagination} |
|
| 1334 | - $fin = '$debut_boucle' |
|
| 1335 | - . (is_numeric($total_parties) ? |
|
| 1336 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1337 | - ('+' . $total_parties . ' - 1')); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1341 | - if ($op1 == 'p') { |
|
| 1342 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1343 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1344 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - // Notes : |
|
| 1349 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1350 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1351 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1352 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1353 | - |
|
| 1354 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1355 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1356 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1357 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1358 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1359 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1360 | - . "\n\tif (\$debut_boucle>0" |
|
| 1361 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1362 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1363 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1364 | - |
|
| 1365 | - $boucles[$id_boucle]->partie = " |
|
| 1309 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1310 | + |
|
| 1311 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1312 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1313 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1314 | + // {1/3} |
|
| 1315 | + if ($op1 == '/') { |
|
| 1316 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1317 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1318 | + "($total_parties ? $total_parties : 1)"; |
|
| 1319 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1320 | + $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
|
| 1321 | + } else { |
|
| 1322 | + // cas {n-1,x} |
|
| 1323 | + if ($op1 == '-') { |
|
| 1324 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + // cas {x,n-1} |
|
| 1328 | + if ($op2 == '-') { |
|
| 1329 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1330 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1331 | + ($total_parties . ' - 1')); |
|
| 1332 | + } else { |
|
| 1333 | + // {x,1} ou {pagination} |
|
| 1334 | + $fin = '$debut_boucle' |
|
| 1335 | + . (is_numeric($total_parties) ? |
|
| 1336 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1337 | + ('+' . $total_parties . ' - 1')); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1341 | + if ($op1 == 'p') { |
|
| 1342 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1343 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1344 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + // Notes : |
|
| 1349 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1350 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1351 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1352 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1353 | + |
|
| 1354 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1355 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1356 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1357 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1358 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1359 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1360 | + . "\n\tif (\$debut_boucle>0" |
|
| 1361 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1362 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1363 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1364 | + |
|
| 1365 | + $boucles[$id_boucle]->partie = " |
|
| 1366 | 1366 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1367 | 1367 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1368 | 1368 | } |
@@ -1379,26 +1379,26 @@ discard block |
||
| 1379 | 1379 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1382 | - if ($param[0]->type != 'texte') { |
|
| 1383 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1384 | - if (isset($param[1]->texte)) { |
|
| 1385 | - preg_match(',^\s*(-(\d+))?\s*$,', (string) $param[1]->texte, $m); |
|
| 1386 | - |
|
| 1387 | - return ["intval($a1)", ((isset($m[2]) && $m[2]) ? $m[2] : 0)]; |
|
| 1388 | - } else { |
|
| 1389 | - return ["intval($a1)", 0]; |
|
| 1390 | - } |
|
| 1391 | - } else { |
|
| 1392 | - preg_match(',^\s*((\d+)|n)\s*(-\s*(\d+)?\s*)?$,', (string) $param[0]->texte, $m); |
|
| 1393 | - $a1 = $m[1]; |
|
| 1394 | - if (empty($m[3])) { |
|
| 1395 | - return [$a1, 0]; |
|
| 1396 | - } elseif (!empty($m[4])) { |
|
| 1397 | - return [$a1, $m[4]]; |
|
| 1398 | - } else { |
|
| 1399 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1400 | - } |
|
| 1401 | - } |
|
| 1382 | + if ($param[0]->type != 'texte') { |
|
| 1383 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1384 | + if (isset($param[1]->texte)) { |
|
| 1385 | + preg_match(',^\s*(-(\d+))?\s*$,', (string) $param[1]->texte, $m); |
|
| 1386 | + |
|
| 1387 | + return ["intval($a1)", ((isset($m[2]) && $m[2]) ? $m[2] : 0)]; |
|
| 1388 | + } else { |
|
| 1389 | + return ["intval($a1)", 0]; |
|
| 1390 | + } |
|
| 1391 | + } else { |
|
| 1392 | + preg_match(',^\s*((\d+)|n)\s*(-\s*(\d+)?\s*)?$,', (string) $param[0]->texte, $m); |
|
| 1393 | + $a1 = $m[1]; |
|
| 1394 | + if (empty($m[3])) { |
|
| 1395 | + return [$a1, 0]; |
|
| 1396 | + } elseif (!empty($m[4])) { |
|
| 1397 | + return [$a1, $m[4]]; |
|
| 1398 | + } else { |
|
| 1399 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1400 | + } |
|
| 1401 | + } |
|
| 1402 | 1402 | } |
| 1403 | 1403 | |
| 1404 | 1404 | |
@@ -1425,46 +1425,46 @@ discard block |
||
| 1425 | 1425 | * array : Erreur sur un des critères |
| 1426 | 1426 | **/ |
| 1427 | 1427 | function calculer_criteres($idb, &$boucles) { |
| 1428 | - $msg = ''; |
|
| 1429 | - $boucle = $boucles[$idb]; |
|
| 1430 | - $table = strtoupper((string) $boucle->type_requete); |
|
| 1431 | - $serveur = strtolower((string) $boucle->sql_serveur); |
|
| 1432 | - |
|
| 1433 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1434 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1435 | - if (!is_array($boucle->criteres)) { |
|
| 1436 | - return []; |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - foreach ($boucle->criteres as $crit) { |
|
| 1440 | - $critere = $crit->op; |
|
| 1441 | - // critere personnalise ? |
|
| 1442 | - if ( |
|
| 1443 | - (!$serveur |
|
| 1444 | - || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1445 | - && !function_exists($f .= '_dist') |
|
| 1446 | - && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1447 | - && !function_exists($f .= '_dist') |
|
| 1448 | - ) |
|
| 1449 | - && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1450 | - && !function_exists($f .= '_dist') |
|
| 1451 | - && !function_exists($f = 'critere_' . $critere) |
|
| 1452 | - && !function_exists($f .= '_dist') |
|
| 1453 | - ) { |
|
| 1454 | - // fonction critere standard |
|
| 1455 | - $f = $defaut; |
|
| 1456 | - } |
|
| 1457 | - // compile le critere |
|
| 1458 | - $res = $f($idb, $boucles, $crit); |
|
| 1459 | - |
|
| 1460 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1461 | - if (is_array($res)) { |
|
| 1462 | - $msg = $res; |
|
| 1463 | - erreur_squelette($msg, $boucle); |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - return $msg; |
|
| 1428 | + $msg = ''; |
|
| 1429 | + $boucle = $boucles[$idb]; |
|
| 1430 | + $table = strtoupper((string) $boucle->type_requete); |
|
| 1431 | + $serveur = strtolower((string) $boucle->sql_serveur); |
|
| 1432 | + |
|
| 1433 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1434 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1435 | + if (!is_array($boucle->criteres)) { |
|
| 1436 | + return []; |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + foreach ($boucle->criteres as $crit) { |
|
| 1440 | + $critere = $crit->op; |
|
| 1441 | + // critere personnalise ? |
|
| 1442 | + if ( |
|
| 1443 | + (!$serveur |
|
| 1444 | + || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1445 | + && !function_exists($f .= '_dist') |
|
| 1446 | + && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1447 | + && !function_exists($f .= '_dist') |
|
| 1448 | + ) |
|
| 1449 | + && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1450 | + && !function_exists($f .= '_dist') |
|
| 1451 | + && !function_exists($f = 'critere_' . $critere) |
|
| 1452 | + && !function_exists($f .= '_dist') |
|
| 1453 | + ) { |
|
| 1454 | + // fonction critere standard |
|
| 1455 | + $f = $defaut; |
|
| 1456 | + } |
|
| 1457 | + // compile le critere |
|
| 1458 | + $res = $f($idb, $boucles, $crit); |
|
| 1459 | + |
|
| 1460 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1461 | + if (is_array($res)) { |
|
| 1462 | + $msg = $res; |
|
| 1463 | + erreur_squelette($msg, $boucle); |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + return $msg; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | /** |
@@ -1479,11 +1479,11 @@ discard block |
||
| 1479 | 1479 | * @return string Code compilé rééchappé |
| 1480 | 1480 | */ |
| 1481 | 1481 | function kwote($lisp, $serveur = '', $type = '') { |
| 1482 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1483 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1484 | - } else { |
|
| 1485 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1486 | - } |
|
| 1482 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1483 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1484 | + } else { |
|
| 1485 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1486 | + } |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | |
@@ -1502,81 +1502,81 @@ discard block |
||
| 1502 | 1502 | * @return void|array |
| 1503 | 1503 | **/ |
| 1504 | 1504 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1505 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1506 | - if (!$r) { |
|
| 1507 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1508 | - } |
|
| 1509 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1510 | - |
|
| 1511 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1512 | - |
|
| 1513 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1514 | - $where = $in; |
|
| 1515 | - if ($crit->cond) { |
|
| 1516 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1517 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1518 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1519 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1520 | - } |
|
| 1521 | - } |
|
| 1522 | - if ($crit->exclus) { |
|
| 1523 | - if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1524 | - $where = ["'NOT'", $where]; |
|
| 1525 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1526 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1527 | - { |
|
| 1528 | - $where = [ |
|
| 1529 | - "'NOT'", |
|
| 1530 | - [ |
|
| 1531 | - "'IN'", |
|
| 1532 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1533 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1534 | - ] |
|
| 1535 | - ]; |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - $boucles[$idb]->where[] = $where; |
|
| 1540 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1541 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1542 | - } |
|
| 1505 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1506 | + if (!$r) { |
|
| 1507 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1508 | + } |
|
| 1509 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1510 | + |
|
| 1511 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1512 | + |
|
| 1513 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1514 | + $where = $in; |
|
| 1515 | + if ($crit->cond) { |
|
| 1516 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1517 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1518 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1519 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1520 | + } |
|
| 1521 | + } |
|
| 1522 | + if ($crit->exclus) { |
|
| 1523 | + if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1524 | + $where = ["'NOT'", $where]; |
|
| 1525 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1526 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1527 | + { |
|
| 1528 | + $where = [ |
|
| 1529 | + "'NOT'", |
|
| 1530 | + [ |
|
| 1531 | + "'IN'", |
|
| 1532 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1533 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1534 | + ] |
|
| 1535 | + ]; |
|
| 1536 | + } |
|
| 1537 | + } |
|
| 1538 | + |
|
| 1539 | + $boucles[$idb]->where[] = $where; |
|
| 1540 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1541 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1542 | + } |
|
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1546 | - static $num = []; |
|
| 1547 | - $descr = $boucles[$idb]->descr; |
|
| 1548 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1549 | - |
|
| 1550 | - $var = '$in' . $cpt++; |
|
| 1551 | - $x = "\n\t$var = array();"; |
|
| 1552 | - foreach ($val as $k => $v) { |
|
| 1553 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
|
| 1554 | - // optimiser le traitement des constantes |
|
| 1555 | - if (is_numeric($r[2])) { |
|
| 1556 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1557 | - } else { |
|
| 1558 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1559 | - } |
|
| 1560 | - } else { |
|
| 1561 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1562 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1563 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1564 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1565 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - $boucles[$idb]->in .= $x; |
|
| 1570 | - |
|
| 1571 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1572 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1573 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1574 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1575 | - if (!$crit2) { |
|
| 1576 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1546 | + static $num = []; |
|
| 1547 | + $descr = $boucles[$idb]->descr; |
|
| 1548 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1549 | + |
|
| 1550 | + $var = '$in' . $cpt++; |
|
| 1551 | + $x = "\n\t$var = array();"; |
|
| 1552 | + foreach ($val as $k => $v) { |
|
| 1553 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
|
| 1554 | + // optimiser le traitement des constantes |
|
| 1555 | + if (is_numeric($r[2])) { |
|
| 1556 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1557 | + } else { |
|
| 1558 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1559 | + } |
|
| 1560 | + } else { |
|
| 1561 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1562 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1563 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1564 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1565 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + $boucles[$idb]->in .= $x; |
|
| 1570 | + |
|
| 1571 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1572 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1573 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1574 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1575 | + if (!$crit2) { |
|
| 1576 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | /** |
@@ -1592,22 +1592,22 @@ discard block |
||
| 1592 | 1592 | * @return void |
| 1593 | 1593 | */ |
| 1594 | 1594 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1595 | - $boucle = &$boucles[$idb]; |
|
| 1596 | - if (isset($crit->param[0])) { |
|
| 1597 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1598 | - } else { |
|
| 1599 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - if ($crit->cond) { |
|
| 1603 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - if ($crit->not) { |
|
| 1607 | - $_where = "array('NOT',$_where)"; |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - $boucle->where[] = $_where; |
|
| 1595 | + $boucle = &$boucles[$idb]; |
|
| 1596 | + if (isset($crit->param[0])) { |
|
| 1597 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1598 | + } else { |
|
| 1599 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + if ($crit->cond) { |
|
| 1603 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + if ($crit->not) { |
|
| 1607 | + $_where = "array('NOT',$_where)"; |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + $boucle->where[] = $_where; |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | /** |
@@ -1635,31 +1635,31 @@ discard block |
||
| 1635 | 1635 | * @return void |
| 1636 | 1636 | */ |
| 1637 | 1637 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1638 | - /** @var Boucle $boucle */ |
|
| 1639 | - $boucle = $boucles[$idb]; |
|
| 1640 | - |
|
| 1641 | - $champs = lister_champs_id_conditionnel( |
|
| 1642 | - $boucle->show['table'], |
|
| 1643 | - $boucle->show, |
|
| 1644 | - $boucle->sql_serveur |
|
| 1645 | - ); |
|
| 1646 | - |
|
| 1647 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1648 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1649 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1650 | - } |
|
| 1651 | - // nous aider en mode debug. |
|
| 1652 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1653 | - $boucle->modificateur['id_'] = $champs; |
|
| 1654 | - |
|
| 1655 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1656 | - foreach ($champs as $champ) { |
|
| 1657 | - $critere_id_table = new Critere(); |
|
| 1658 | - $critere_id_table->op = $champ; |
|
| 1659 | - $critere_id_table->cond = true; |
|
| 1660 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1661 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1662 | - } |
|
| 1638 | + /** @var Boucle $boucle */ |
|
| 1639 | + $boucle = $boucles[$idb]; |
|
| 1640 | + |
|
| 1641 | + $champs = lister_champs_id_conditionnel( |
|
| 1642 | + $boucle->show['table'], |
|
| 1643 | + $boucle->show, |
|
| 1644 | + $boucle->sql_serveur |
|
| 1645 | + ); |
|
| 1646 | + |
|
| 1647 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1648 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1649 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1650 | + } |
|
| 1651 | + // nous aider en mode debug. |
|
| 1652 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1653 | + $boucle->modificateur['id_'] = $champs; |
|
| 1654 | + |
|
| 1655 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1656 | + foreach ($champs as $champ) { |
|
| 1657 | + $critere_id_table = new Critere(); |
|
| 1658 | + $critere_id_table->op = $champ; |
|
| 1659 | + $critere_id_table->cond = true; |
|
| 1660 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1661 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1662 | + } |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | /** |
@@ -1679,74 +1679,74 @@ discard block |
||
| 1679 | 1679 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1680 | 1680 | */ |
| 1681 | 1681 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1682 | - // calculer la description de la table |
|
| 1683 | - if (!is_array($desc)) { |
|
| 1684 | - $desc = description_table($table, $serveur); |
|
| 1685 | - } |
|
| 1686 | - if (!$desc) { |
|
| 1687 | - return []; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - // Les champs id_xx de la table demandée |
|
| 1691 | - $champs = array_filter( |
|
| 1692 | - array_keys($desc['field']), |
|
| 1693 | - fn($champ) => str_starts_with($champ, 'id_') || $champ == 'objet' |
|
| 1694 | - ); |
|
| 1695 | - |
|
| 1696 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1697 | - if ( |
|
| 1698 | - in_array('id_rubrique', $champs) |
|
| 1699 | - && !in_array('id_secteur', $champs) |
|
| 1700 | - ) { |
|
| 1701 | - $champs[] = 'id_secteur'; |
|
| 1702 | - } |
|
| 1703 | - |
|
| 1704 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1705 | - if ($serveur) { |
|
| 1706 | - return $champs; |
|
| 1707 | - } |
|
| 1708 | - |
|
| 1709 | - $primary = false; |
|
| 1710 | - $associable = false; |
|
| 1711 | - include_spip('action/editer_liens'); |
|
| 1712 | - |
|
| 1713 | - if (isset($desc['type'])) { |
|
| 1714 | - $primary = id_table_objet($desc['type']); |
|
| 1715 | - $associable = objet_associable($desc['type']); |
|
| 1716 | - } |
|
| 1717 | - if (isset($desc['field']['id_objet']) && isset($desc['field']['objet'])) { |
|
| 1718 | - $associable = true; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - // liste de toutes les tables principales, sauf la notre |
|
| 1722 | - $tables = lister_tables_objets_sql(); |
|
| 1723 | - unset($tables[$table]); |
|
| 1724 | - |
|
| 1725 | - foreach ($tables as $_table => $_desc) { |
|
| 1726 | - if ( |
|
| 1727 | - $associable |
|
| 1728 | - || $primary && array_key_exists($primary, $_desc['field']) |
|
| 1729 | - || objet_associable($_desc['type']) |
|
| 1730 | - ) { |
|
| 1731 | - $champs[] = id_table_objet($_table); |
|
| 1732 | - } |
|
| 1733 | - } |
|
| 1734 | - $champs = array_values(array_unique($champs)); |
|
| 1735 | - |
|
| 1736 | - // Exclusions de certains id |
|
| 1737 | - $exclusions = pipeline( |
|
| 1738 | - 'exclure_id_conditionnel', |
|
| 1739 | - [ |
|
| 1740 | - 'args' => [ |
|
| 1741 | - 'table' => $table, |
|
| 1742 | - 'id_table_objet' => $primary, |
|
| 1743 | - 'associable' => $associable, |
|
| 1744 | - ], |
|
| 1745 | - 'data' => [], |
|
| 1746 | - ] |
|
| 1747 | - ); |
|
| 1748 | - |
|
| 1749 | - return array_diff($champs, $exclusions); |
|
| 1682 | + // calculer la description de la table |
|
| 1683 | + if (!is_array($desc)) { |
|
| 1684 | + $desc = description_table($table, $serveur); |
|
| 1685 | + } |
|
| 1686 | + if (!$desc) { |
|
| 1687 | + return []; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + // Les champs id_xx de la table demandée |
|
| 1691 | + $champs = array_filter( |
|
| 1692 | + array_keys($desc['field']), |
|
| 1693 | + fn($champ) => str_starts_with($champ, 'id_') || $champ == 'objet' |
|
| 1694 | + ); |
|
| 1695 | + |
|
| 1696 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1697 | + if ( |
|
| 1698 | + in_array('id_rubrique', $champs) |
|
| 1699 | + && !in_array('id_secteur', $champs) |
|
| 1700 | + ) { |
|
| 1701 | + $champs[] = 'id_secteur'; |
|
| 1702 | + } |
|
| 1703 | + |
|
| 1704 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1705 | + if ($serveur) { |
|
| 1706 | + return $champs; |
|
| 1707 | + } |
|
| 1708 | + |
|
| 1709 | + $primary = false; |
|
| 1710 | + $associable = false; |
|
| 1711 | + include_spip('action/editer_liens'); |
|
| 1712 | + |
|
| 1713 | + if (isset($desc['type'])) { |
|
| 1714 | + $primary = id_table_objet($desc['type']); |
|
| 1715 | + $associable = objet_associable($desc['type']); |
|
| 1716 | + } |
|
| 1717 | + if (isset($desc['field']['id_objet']) && isset($desc['field']['objet'])) { |
|
| 1718 | + $associable = true; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + // liste de toutes les tables principales, sauf la notre |
|
| 1722 | + $tables = lister_tables_objets_sql(); |
|
| 1723 | + unset($tables[$table]); |
|
| 1724 | + |
|
| 1725 | + foreach ($tables as $_table => $_desc) { |
|
| 1726 | + if ( |
|
| 1727 | + $associable |
|
| 1728 | + || $primary && array_key_exists($primary, $_desc['field']) |
|
| 1729 | + || objet_associable($_desc['type']) |
|
| 1730 | + ) { |
|
| 1731 | + $champs[] = id_table_objet($_table); |
|
| 1732 | + } |
|
| 1733 | + } |
|
| 1734 | + $champs = array_values(array_unique($champs)); |
|
| 1735 | + |
|
| 1736 | + // Exclusions de certains id |
|
| 1737 | + $exclusions = pipeline( |
|
| 1738 | + 'exclure_id_conditionnel', |
|
| 1739 | + [ |
|
| 1740 | + 'args' => [ |
|
| 1741 | + 'table' => $table, |
|
| 1742 | + 'id_table_objet' => $primary, |
|
| 1743 | + 'associable' => $associable, |
|
| 1744 | + ], |
|
| 1745 | + 'data' => [], |
|
| 1746 | + ] |
|
| 1747 | + ); |
|
| 1748 | + |
|
| 1749 | + return array_diff($champs, $exclusions); |
|
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | /** |
@@ -1801,31 +1801,31 @@ discard block |
||
| 1801 | 1801 | * @return void |
| 1802 | 1802 | */ |
| 1803 | 1803 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1804 | - $boucle = &$boucles[$idb]; |
|
| 1805 | - |
|
| 1806 | - // definition du champ par defaut |
|
| 1807 | - $_champ_defaut = isset($crit->param[0][0]) |
|
| 1808 | - ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1809 | - : "''"; |
|
| 1810 | - $_liste_sens_defaut = isset($crit->param[1][0]) |
|
| 1811 | - ? calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1812 | - : '1'; |
|
| 1813 | - $_variable = isset($crit->param[2][0]) |
|
| 1814 | - ? calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1815 | - : "'$idb'"; |
|
| 1816 | - |
|
| 1817 | - $_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):'')"; |
|
| 1818 | - |
|
| 1819 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1820 | - $_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)"; |
|
| 1821 | - |
|
| 1822 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1823 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1824 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1825 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1826 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1827 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1828 | - $boucle->hash .= " |
|
| 1804 | + $boucle = &$boucles[$idb]; |
|
| 1805 | + |
|
| 1806 | + // definition du champ par defaut |
|
| 1807 | + $_champ_defaut = isset($crit->param[0][0]) |
|
| 1808 | + ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1809 | + : "''"; |
|
| 1810 | + $_liste_sens_defaut = isset($crit->param[1][0]) |
|
| 1811 | + ? calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1812 | + : '1'; |
|
| 1813 | + $_variable = isset($crit->param[2][0]) |
|
| 1814 | + ? calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1815 | + : "'$idb'"; |
|
| 1816 | + |
|
| 1817 | + $_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):'')"; |
|
| 1818 | + |
|
| 1819 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1820 | + $_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)"; |
|
| 1821 | + |
|
| 1822 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1823 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1824 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1825 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1826 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1827 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1828 | + $boucle->hash .= " |
|
| 1829 | 1829 | \$senstri = ''; |
| 1830 | 1830 | \$tri = $_tri; |
| 1831 | 1831 | if (\$tri){ |
@@ -1833,8 +1833,8 @@ discard block |
||
| 1833 | 1833 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1834 | 1834 | }; |
| 1835 | 1835 | "; |
| 1836 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1837 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1836 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1837 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | 1840 | # criteres de comparaison |
@@ -1851,21 +1851,21 @@ discard block |
||
| 1851 | 1851 | * @return void|array |
| 1852 | 1852 | **/ |
| 1853 | 1853 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1854 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1855 | - if ($crit->op == ',' || $crit->op == '/') { |
|
| 1856 | - calculer_critere_parties($idb, $boucles, $crit); |
|
| 1857 | - return; |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1861 | - if (!$r) { |
|
| 1862 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1863 | - # if (!$crit->cond) { |
|
| 1864 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1865 | - # } |
|
| 1866 | - } else { |
|
| 1867 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1868 | - } |
|
| 1854 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1855 | + if ($crit->op == ',' || $crit->op == '/') { |
|
| 1856 | + calculer_critere_parties($idb, $boucles, $crit); |
|
| 1857 | + return; |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1861 | + if (!$r) { |
|
| 1862 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1863 | + # if (!$crit->cond) { |
|
| 1864 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1865 | + # } |
|
| 1866 | + } else { |
|
| 1867 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1868 | + } |
|
| 1869 | 1869 | } |
| 1870 | 1870 | |
| 1871 | 1871 | |
@@ -1885,60 +1885,60 @@ discard block |
||
| 1885 | 1885 | * @return void |
| 1886 | 1886 | **/ |
| 1887 | 1887 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1888 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1889 | - |
|
| 1890 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1891 | - |
|
| 1892 | - // inserer la negation (cf !...) |
|
| 1893 | - |
|
| 1894 | - if ($crit->not) { |
|
| 1895 | - $where = ["'NOT'", $where]; |
|
| 1896 | - } |
|
| 1897 | - if ($crit->exclus) { |
|
| 1898 | - if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1899 | - $where = ["'NOT'", $where]; |
|
| 1900 | - } else { |
|
| 1901 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1902 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1903 | - $where = [ |
|
| 1904 | - "'NOT'", |
|
| 1905 | - [ |
|
| 1906 | - "'IN'", |
|
| 1907 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1908 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1909 | - ] |
|
| 1910 | - ]; |
|
| 1911 | - } |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - // inserer la condition (cf {lang?}) |
|
| 1915 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1916 | - if ($crit->cond) { |
|
| 1917 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1918 | - if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 1919 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - if ($op === '=' && !$crit->not) { |
|
| 1923 | - $where = [ |
|
| 1924 | - "'?'", |
|
| 1925 | - "(is_array($pred))", |
|
| 1926 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1927 | - $where |
|
| 1928 | - ]; |
|
| 1929 | - } |
|
| 1930 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1931 | - if ($where_complement) { |
|
| 1932 | - // condition annexe du type "AND (objet='article')" |
|
| 1933 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - $boucles[$idb]->where[] = $where; |
|
| 1938 | - if ($where_complement) { |
|
| 1939 | - // condition annexe du type "AND (objet='article')" |
|
| 1940 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1941 | - } |
|
| 1888 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1889 | + |
|
| 1890 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1891 | + |
|
| 1892 | + // inserer la negation (cf !...) |
|
| 1893 | + |
|
| 1894 | + if ($crit->not) { |
|
| 1895 | + $where = ["'NOT'", $where]; |
|
| 1896 | + } |
|
| 1897 | + if ($crit->exclus) { |
|
| 1898 | + if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1899 | + $where = ["'NOT'", $where]; |
|
| 1900 | + } else { |
|
| 1901 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1902 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1903 | + $where = [ |
|
| 1904 | + "'NOT'", |
|
| 1905 | + [ |
|
| 1906 | + "'IN'", |
|
| 1907 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1908 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1909 | + ] |
|
| 1910 | + ]; |
|
| 1911 | + } |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + // inserer la condition (cf {lang?}) |
|
| 1915 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1916 | + if ($crit->cond) { |
|
| 1917 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1918 | + if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 1919 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + if ($op === '=' && !$crit->not) { |
|
| 1923 | + $where = [ |
|
| 1924 | + "'?'", |
|
| 1925 | + "(is_array($pred))", |
|
| 1926 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1927 | + $where |
|
| 1928 | + ]; |
|
| 1929 | + } |
|
| 1930 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1931 | + if ($where_complement) { |
|
| 1932 | + // condition annexe du type "AND (objet='article')" |
|
| 1933 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + $boucles[$idb]->where[] = $where; |
|
| 1938 | + if ($where_complement) { |
|
| 1939 | + // condition annexe du type "AND (objet='article')" |
|
| 1940 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1941 | + } |
|
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | 1944 | |
@@ -1979,160 +1979,160 @@ discard block |
||
| 1979 | 1979 | **/ |
| 1980 | 1980 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1981 | 1981 | |
| 1982 | - $boucle = &$boucles[$idb]; |
|
| 1983 | - $type = $boucle->type_requete; |
|
| 1984 | - $table = $boucle->id_table; |
|
| 1985 | - $desc = $boucle->show; |
|
| 1986 | - $col_vraie = null; |
|
| 1987 | - |
|
| 1988 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 1989 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1990 | - |
|
| 1991 | - $col_alias = $col; |
|
| 1992 | - $where_complement = false; |
|
| 1993 | - |
|
| 1994 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1995 | - if ($col == 'id_enfant') { |
|
| 1996 | - $col = $boucle->primary; |
|
| 1997 | - } |
|
| 1998 | - |
|
| 1999 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2000 | - if ( |
|
| 2001 | - in_array($col, ['id_parent', 'id_secteur']) |
|
| 2002 | - && isset($GLOBALS['exceptions_des_tables'][$table][$col]) || isset($GLOBALS['exceptions_des_tables'][$table][$col]) && is_string($GLOBALS['exceptions_des_tables'][$table][$col]) |
|
| 2003 | - ) { |
|
| 2004 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2005 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2006 | - else { |
|
| 2007 | - if ($col == 'id_secteur' && ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2008 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2009 | - } |
|
| 2010 | - |
|
| 2011 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2012 | - // sauf si exception declaree : sauter cette etape |
|
| 2013 | - else { |
|
| 2014 | - if ( |
|
| 2015 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2016 | - && !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2017 | - && count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2018 | - ) { |
|
| 2019 | - $e = decompose_champ_id_objet($col); |
|
| 2020 | - $col = array_shift($e); |
|
| 2021 | - $where_complement = primary_doublee($e, $table); |
|
| 2022 | - } // Cas particulier : expressions de date |
|
| 2023 | - else { |
|
| 2024 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2025 | - [$col, $col_vraie] = $c; |
|
| 2026 | - $table = ''; |
|
| 2027 | - } // table explicitée {mots.titre} |
|
| 2028 | - else { |
|
| 2029 | - if (preg_match('/^(.*)\.(.*)$/', (string) $col, $r)) { |
|
| 2030 | - [, $table, $col] = $r; |
|
| 2031 | - $col_alias = $col; |
|
| 2032 | - |
|
| 2033 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2034 | - if ( |
|
| 2035 | - ($desc = $trouver_table($table, $boucle->sql_serveur)) |
|
| 2036 | - && isset($desc['field'][$col]) |
|
| 2037 | - && ($cle = array_search($desc['table'], $boucle->from)) |
|
| 2038 | - ) { |
|
| 2039 | - $table = $cle; |
|
| 2040 | - } else { |
|
| 2041 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond || $op != '=')); |
|
| 2042 | - } |
|
| 2043 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2044 | - if (!$table) { |
|
| 2045 | - return ''; |
|
| 2046 | - } |
|
| 2047 | - } |
|
| 2048 | - // si le champ n'est pas trouvé dans la table, |
|
| 2049 | - // on cherche si une jointure peut l'obtenir |
|
| 2050 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2051 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2052 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2053 | - $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 |
|
| 2054 | - } |
|
| 2055 | - else { |
|
| 2056 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2057 | - if (!$r) { |
|
| 2058 | - return ''; |
|
| 2059 | - } |
|
| 2060 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - } |
|
| 2064 | - } |
|
| 2065 | - } |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2069 | - // Dans tous les cas, |
|
| 2070 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2071 | - // et passer dans sql_quote avec le type si connu |
|
| 2072 | - // et int sinon si la valeur est numerique |
|
| 2073 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2074 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2075 | - if ($op == '=' || in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2076 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2077 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2078 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2079 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
|
| 2080 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2081 | - } |
|
| 2082 | - // sinon expliciter les |
|
| 2083 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2084 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2085 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2086 | - // sans toucher aux |
|
| 2087 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2088 | - // sql_quote(truc,'','varchar') |
|
| 2089 | - elseif ( |
|
| 2090 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', (string) $val[0], $r) |
|
| 2091 | - && (!isset($r[3]) || !$r[3] || !trim($r[3], ", '")) |
|
| 2092 | - ) { |
|
| 2093 | - $r = $r[1] |
|
| 2094 | - . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
|
| 2095 | - . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2096 | - $val[0] = "sql_quote($r)"; |
|
| 2097 | - } |
|
| 2098 | - elseif ( |
|
| 2099 | - str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2100 | - && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2101 | - ) { |
|
| 2102 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2103 | - } |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - if ( |
|
| 2107 | - str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2108 | - && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2109 | - ) { |
|
| 2110 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2114 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2115 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2116 | - if ($table === $boucle->id_table) { |
|
| 2117 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2118 | - if ($col_alias != $col_vraie) { |
|
| 2119 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2120 | - } |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2124 | - if ($table) { |
|
| 2125 | - $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2126 | - } else { |
|
| 2127 | - $arg = $col; |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - // inserer la fonction SQL |
|
| 2131 | - if ($fct) { |
|
| 2132 | - $arg = "$fct($arg$args_sql)"; |
|
| 2133 | - } |
|
| 2134 | - |
|
| 2135 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 1982 | + $boucle = &$boucles[$idb]; |
|
| 1983 | + $type = $boucle->type_requete; |
|
| 1984 | + $table = $boucle->id_table; |
|
| 1985 | + $desc = $boucle->show; |
|
| 1986 | + $col_vraie = null; |
|
| 1987 | + |
|
| 1988 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 1989 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1990 | + |
|
| 1991 | + $col_alias = $col; |
|
| 1992 | + $where_complement = false; |
|
| 1993 | + |
|
| 1994 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1995 | + if ($col == 'id_enfant') { |
|
| 1996 | + $col = $boucle->primary; |
|
| 1997 | + } |
|
| 1998 | + |
|
| 1999 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2000 | + if ( |
|
| 2001 | + in_array($col, ['id_parent', 'id_secteur']) |
|
| 2002 | + && isset($GLOBALS['exceptions_des_tables'][$table][$col]) || isset($GLOBALS['exceptions_des_tables'][$table][$col]) && is_string($GLOBALS['exceptions_des_tables'][$table][$col]) |
|
| 2003 | + ) { |
|
| 2004 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2005 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2006 | + else { |
|
| 2007 | + if ($col == 'id_secteur' && ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2008 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2009 | + } |
|
| 2010 | + |
|
| 2011 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2012 | + // sauf si exception declaree : sauter cette etape |
|
| 2013 | + else { |
|
| 2014 | + if ( |
|
| 2015 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2016 | + && !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2017 | + && count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2018 | + ) { |
|
| 2019 | + $e = decompose_champ_id_objet($col); |
|
| 2020 | + $col = array_shift($e); |
|
| 2021 | + $where_complement = primary_doublee($e, $table); |
|
| 2022 | + } // Cas particulier : expressions de date |
|
| 2023 | + else { |
|
| 2024 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2025 | + [$col, $col_vraie] = $c; |
|
| 2026 | + $table = ''; |
|
| 2027 | + } // table explicitée {mots.titre} |
|
| 2028 | + else { |
|
| 2029 | + if (preg_match('/^(.*)\.(.*)$/', (string) $col, $r)) { |
|
| 2030 | + [, $table, $col] = $r; |
|
| 2031 | + $col_alias = $col; |
|
| 2032 | + |
|
| 2033 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2034 | + if ( |
|
| 2035 | + ($desc = $trouver_table($table, $boucle->sql_serveur)) |
|
| 2036 | + && isset($desc['field'][$col]) |
|
| 2037 | + && ($cle = array_search($desc['table'], $boucle->from)) |
|
| 2038 | + ) { |
|
| 2039 | + $table = $cle; |
|
| 2040 | + } else { |
|
| 2041 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond || $op != '=')); |
|
| 2042 | + } |
|
| 2043 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2044 | + if (!$table) { |
|
| 2045 | + return ''; |
|
| 2046 | + } |
|
| 2047 | + } |
|
| 2048 | + // si le champ n'est pas trouvé dans la table, |
|
| 2049 | + // on cherche si une jointure peut l'obtenir |
|
| 2050 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2051 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2052 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2053 | + $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 |
|
| 2054 | + } |
|
| 2055 | + else { |
|
| 2056 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2057 | + if (!$r) { |
|
| 2058 | + return ''; |
|
| 2059 | + } |
|
| 2060 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + } |
|
| 2064 | + } |
|
| 2065 | + } |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2069 | + // Dans tous les cas, |
|
| 2070 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2071 | + // et passer dans sql_quote avec le type si connu |
|
| 2072 | + // et int sinon si la valeur est numerique |
|
| 2073 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2074 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2075 | + if ($op == '=' || in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2076 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2077 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2078 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2079 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
|
| 2080 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2081 | + } |
|
| 2082 | + // sinon expliciter les |
|
| 2083 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2084 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2085 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2086 | + // sans toucher aux |
|
| 2087 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2088 | + // sql_quote(truc,'','varchar') |
|
| 2089 | + elseif ( |
|
| 2090 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', (string) $val[0], $r) |
|
| 2091 | + && (!isset($r[3]) || !$r[3] || !trim($r[3], ", '")) |
|
| 2092 | + ) { |
|
| 2093 | + $r = $r[1] |
|
| 2094 | + . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
|
| 2095 | + . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2096 | + $val[0] = "sql_quote($r)"; |
|
| 2097 | + } |
|
| 2098 | + elseif ( |
|
| 2099 | + str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2100 | + && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2101 | + ) { |
|
| 2102 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2103 | + } |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + if ( |
|
| 2107 | + str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2108 | + && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2109 | + ) { |
|
| 2110 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2114 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2115 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2116 | + if ($table === $boucle->id_table) { |
|
| 2117 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2118 | + if ($col_alias != $col_vraie) { |
|
| 2119 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2120 | + } |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2124 | + if ($table) { |
|
| 2125 | + $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2126 | + } else { |
|
| 2127 | + $arg = $col; |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + // inserer la fonction SQL |
|
| 2131 | + if ($fct) { |
|
| 2132 | + $arg = "$fct($arg$args_sql)"; |
|
| 2133 | + } |
|
| 2134 | + |
|
| 2135 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | |
@@ -2161,75 +2161,75 @@ discard block |
||
| 2161 | 2161 | **/ |
| 2162 | 2162 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2163 | 2163 | |
| 2164 | - $where = ''; |
|
| 2165 | - |
|
| 2166 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2167 | - // gestion par les plugins des jointures tordues |
|
| 2168 | - // pas automatiques mais necessaires |
|
| 2169 | - $table_sql = table_objet_sql($table); |
|
| 2170 | - if ( |
|
| 2171 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2172 | - && is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2173 | - && ( |
|
| 2174 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2175 | - || isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2176 | - ) |
|
| 2177 | - ) { |
|
| 2178 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2179 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2180 | - |
|
| 2181 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2182 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2183 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2184 | - [$t, $col] = $t[$col]; |
|
| 2185 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2186 | - [$calculer_critere_externe] = $index; |
|
| 2187 | - $t = $table; |
|
| 2188 | - } else { |
|
| 2189 | - $t = ''; |
|
| 2190 | - } // jointure non declaree. La trouver. |
|
| 2191 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2192 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2193 | - } else { |
|
| 2194 | - $t = ''; |
|
| 2195 | - } // jointure non declaree. La trouver. |
|
| 2196 | - |
|
| 2197 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2198 | - |
|
| 2199 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2200 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2201 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2202 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2203 | - $table = ''; |
|
| 2204 | - if ($boucle->jointures_explicites) { |
|
| 2205 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2206 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2207 | - } |
|
| 2208 | - |
|
| 2209 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2210 | - if (!$table) { |
|
| 2211 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - if (!$table) { |
|
| 2215 | - return ''; |
|
| 2216 | - } |
|
| 2217 | - |
|
| 2218 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2219 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2220 | - |
|
| 2221 | - if ((is_countable($cle) ? count($cle) : 0) > 1 || reset($cle) !== $col) { |
|
| 2222 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2223 | - if ((is_countable($cle) ? count($cle) : 0) > 1 && reset($cle) == 'id_objet') { |
|
| 2224 | - $e = decompose_champ_id_objet($col); |
|
| 2225 | - $col = array_shift($e); |
|
| 2226 | - $where = primary_doublee($e, $table); |
|
| 2227 | - } else { |
|
| 2228 | - $col = reset($cle); |
|
| 2229 | - } |
|
| 2230 | - } |
|
| 2231 | - |
|
| 2232 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2164 | + $where = ''; |
|
| 2165 | + |
|
| 2166 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2167 | + // gestion par les plugins des jointures tordues |
|
| 2168 | + // pas automatiques mais necessaires |
|
| 2169 | + $table_sql = table_objet_sql($table); |
|
| 2170 | + if ( |
|
| 2171 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2172 | + && is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2173 | + && ( |
|
| 2174 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2175 | + || isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2176 | + ) |
|
| 2177 | + ) { |
|
| 2178 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2179 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2180 | + |
|
| 2181 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2182 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2183 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2184 | + [$t, $col] = $t[$col]; |
|
| 2185 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2186 | + [$calculer_critere_externe] = $index; |
|
| 2187 | + $t = $table; |
|
| 2188 | + } else { |
|
| 2189 | + $t = ''; |
|
| 2190 | + } // jointure non declaree. La trouver. |
|
| 2191 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2192 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2193 | + } else { |
|
| 2194 | + $t = ''; |
|
| 2195 | + } // jointure non declaree. La trouver. |
|
| 2196 | + |
|
| 2197 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2198 | + |
|
| 2199 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2200 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2201 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2202 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2203 | + $table = ''; |
|
| 2204 | + if ($boucle->jointures_explicites) { |
|
| 2205 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2206 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2207 | + } |
|
| 2208 | + |
|
| 2209 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2210 | + if (!$table) { |
|
| 2211 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + if (!$table) { |
|
| 2215 | + return ''; |
|
| 2216 | + } |
|
| 2217 | + |
|
| 2218 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2219 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2220 | + |
|
| 2221 | + if ((is_countable($cle) ? count($cle) : 0) > 1 || reset($cle) !== $col) { |
|
| 2222 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2223 | + if ((is_countable($cle) ? count($cle) : 0) > 1 && reset($cle) == 'id_objet') { |
|
| 2224 | + $e = decompose_champ_id_objet($col); |
|
| 2225 | + $col = array_shift($e); |
|
| 2226 | + $where = primary_doublee($e, $table); |
|
| 2227 | + } else { |
|
| 2228 | + $col = reset($cle); |
|
| 2229 | + } |
|
| 2230 | + } |
|
| 2231 | + |
|
| 2232 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2233 | 2233 | } |
| 2234 | 2234 | |
| 2235 | 2235 | |
@@ -2250,10 +2250,10 @@ discard block |
||
| 2250 | 2250 | * - valeur |
| 2251 | 2251 | **/ |
| 2252 | 2252 | function primary_doublee($decompose, $table) { |
| 2253 | - $e1 = reset($decompose); |
|
| 2254 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2253 | + $e1 = reset($decompose); |
|
| 2254 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2255 | 2255 | |
| 2256 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2256 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2257 | 2257 | } |
| 2258 | 2258 | |
| 2259 | 2259 | /** |
@@ -2284,56 +2284,56 @@ discard block |
||
| 2284 | 2284 | * Vide sinon. |
| 2285 | 2285 | */ |
| 2286 | 2286 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2287 | - // si on demande un truc du genre spip_mots |
|
| 2288 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2289 | - // et qu'on est la |
|
| 2290 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2291 | - if ( |
|
| 2292 | - $checkarrivee |
|
| 2293 | - && is_string($checkarrivee) |
|
| 2294 | - && ($a = table_objet($checkarrivee)) |
|
| 2295 | - && in_array($a . '_liens', $joints) |
|
| 2296 | - && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
|
| 2297 | - ) { |
|
| 2298 | - return $res; |
|
| 2299 | - } |
|
| 2300 | - foreach ($joints as $joint) { |
|
| 2301 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2302 | - // alias de table dans le from |
|
| 2303 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2304 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2305 | - $cols = $arrivee[2]; |
|
| 2306 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2307 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2308 | - array_pop($cols); |
|
| 2309 | - } |
|
| 2310 | - if ($t) { |
|
| 2311 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2312 | - $joindre = false; |
|
| 2313 | - foreach ($cols as $col) { |
|
| 2314 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2315 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2316 | - $joindre = true; |
|
| 2317 | - } else { |
|
| 2318 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2319 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2320 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2321 | - $joindre = true; |
|
| 2322 | - } |
|
| 2323 | - } |
|
| 2324 | - } |
|
| 2325 | - if (!$joindre) { |
|
| 2326 | - return $t; |
|
| 2327 | - } |
|
| 2328 | - } |
|
| 2329 | - array_pop($arrivee); |
|
| 2330 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2331 | - return $res; |
|
| 2332 | - } |
|
| 2333 | - } |
|
| 2334 | - } |
|
| 2335 | - |
|
| 2336 | - return ''; |
|
| 2287 | + // si on demande un truc du genre spip_mots |
|
| 2288 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2289 | + // et qu'on est la |
|
| 2290 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2291 | + if ( |
|
| 2292 | + $checkarrivee |
|
| 2293 | + && is_string($checkarrivee) |
|
| 2294 | + && ($a = table_objet($checkarrivee)) |
|
| 2295 | + && in_array($a . '_liens', $joints) |
|
| 2296 | + && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
|
| 2297 | + ) { |
|
| 2298 | + return $res; |
|
| 2299 | + } |
|
| 2300 | + foreach ($joints as $joint) { |
|
| 2301 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2302 | + // alias de table dans le from |
|
| 2303 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2304 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2305 | + $cols = $arrivee[2]; |
|
| 2306 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2307 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2308 | + array_pop($cols); |
|
| 2309 | + } |
|
| 2310 | + if ($t) { |
|
| 2311 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2312 | + $joindre = false; |
|
| 2313 | + foreach ($cols as $col) { |
|
| 2314 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2315 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2316 | + $joindre = true; |
|
| 2317 | + } else { |
|
| 2318 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2319 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2320 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2321 | + $joindre = true; |
|
| 2322 | + } |
|
| 2323 | + } |
|
| 2324 | + } |
|
| 2325 | + if (!$joindre) { |
|
| 2326 | + return $t; |
|
| 2327 | + } |
|
| 2328 | + } |
|
| 2329 | + array_pop($arrivee); |
|
| 2330 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2331 | + return $res; |
|
| 2332 | + } |
|
| 2333 | + } |
|
| 2334 | + } |
|
| 2335 | + |
|
| 2336 | + return ''; |
|
| 2337 | 2337 | } |
| 2338 | 2338 | |
| 2339 | 2339 | /** |
@@ -2359,35 +2359,35 @@ discard block |
||
| 2359 | 2359 | * Alias de la table de jointure (Lx) |
| 2360 | 2360 | */ |
| 2361 | 2361 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2362 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2363 | - |
|
| 2364 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2365 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2366 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2367 | - |
|
| 2368 | - if (!$intermediaire || !$arrivee) { |
|
| 2369 | - return ''; |
|
| 2370 | - } |
|
| 2371 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2372 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2373 | - |
|
| 2374 | - $res = fabrique_jointures( |
|
| 2375 | - $boucle, |
|
| 2376 | - [ |
|
| 2377 | - [ |
|
| 2378 | - $boucle->id_table, |
|
| 2379 | - $intermediaire, |
|
| 2380 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2381 | - ], |
|
| 2382 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2383 | - ], |
|
| 2384 | - $cond, |
|
| 2385 | - $desc, |
|
| 2386 | - $boucle->id_table, |
|
| 2387 | - [$col] |
|
| 2388 | - ); |
|
| 2389 | - |
|
| 2390 | - return $res; |
|
| 2362 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2363 | + |
|
| 2364 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2365 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2366 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2367 | + |
|
| 2368 | + if (!$intermediaire || !$arrivee) { |
|
| 2369 | + return ''; |
|
| 2370 | + } |
|
| 2371 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2372 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2373 | + |
|
| 2374 | + $res = fabrique_jointures( |
|
| 2375 | + $boucle, |
|
| 2376 | + [ |
|
| 2377 | + [ |
|
| 2378 | + $boucle->id_table, |
|
| 2379 | + $intermediaire, |
|
| 2380 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2381 | + ], |
|
| 2382 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2383 | + ], |
|
| 2384 | + $cond, |
|
| 2385 | + $desc, |
|
| 2386 | + $boucle->id_table, |
|
| 2387 | + [$col] |
|
| 2388 | + ); |
|
| 2389 | + |
|
| 2390 | + return $res; |
|
| 2391 | 2391 | } |
| 2392 | 2392 | |
| 2393 | 2393 | |
@@ -2404,17 +2404,17 @@ discard block |
||
| 2404 | 2404 | * false sinon. |
| 2405 | 2405 | **/ |
| 2406 | 2406 | function trouver_champ($champ, $where) { |
| 2407 | - if (!is_array($where)) { |
|
| 2408 | - return preg_match($champ, $where); |
|
| 2409 | - } else { |
|
| 2410 | - foreach ($where as $clause) { |
|
| 2411 | - if (trouver_champ($champ, $clause)) { |
|
| 2412 | - return true; |
|
| 2413 | - } |
|
| 2414 | - } |
|
| 2415 | - |
|
| 2416 | - return false; |
|
| 2417 | - } |
|
| 2407 | + if (!is_array($where)) { |
|
| 2408 | + return preg_match($champ, $where); |
|
| 2409 | + } else { |
|
| 2410 | + foreach ($where as $clause) { |
|
| 2411 | + if (trouver_champ($champ, $clause)) { |
|
| 2412 | + return true; |
|
| 2413 | + } |
|
| 2414 | + } |
|
| 2415 | + |
|
| 2416 | + return false; |
|
| 2417 | + } |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | |
@@ -2440,128 +2440,128 @@ discard block |
||
| 2440 | 2440 | * - string $args_sql Suite des arguments du critère. ? |
| 2441 | 2441 | **/ |
| 2442 | 2442 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2443 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2444 | - if ((is_countable($crit->param) ? count($crit->param) : 0) == 0) { |
|
| 2445 | - $op = '='; |
|
| 2446 | - $col = $val = $crit->op; |
|
| 2447 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2448 | - $val = $r[2]; |
|
| 2449 | - } |
|
| 2450 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2451 | - if ($val == 'lang') { |
|
| 2452 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2453 | - } else { |
|
| 2454 | - $defaut = null; |
|
| 2455 | - if ($val == 'id_parent') { |
|
| 2456 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2457 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2458 | - // pour eviter l'erreur SQL |
|
| 2459 | - $val = $boucles[$idb]->primary; |
|
| 2460 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2461 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2462 | - } elseif ($val == 'id_enfant') { |
|
| 2463 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2464 | - // de la boucle superieure |
|
| 2465 | - $val = 'id_parent'; |
|
| 2466 | - } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
|
| 2467 | - // un critere conditionnel sur date est traite a part |
|
| 2468 | - // car la date est mise d'office par SPIP, |
|
| 2469 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2473 | - $val = [kwote($val)]; |
|
| 2474 | - } |
|
| 2475 | - } else { |
|
| 2476 | - // comparaison explicite |
|
| 2477 | - // le phraseur impose que le premier param soit du texte |
|
| 2478 | - $params = $crit->param; |
|
| 2479 | - $op = $crit->op; |
|
| 2480 | - if ($op == '==') { |
|
| 2481 | - $op = 'REGEXP'; |
|
| 2482 | - } |
|
| 2483 | - $col = array_shift($params); |
|
| 2484 | - $col = $col[0]->texte; |
|
| 2485 | - |
|
| 2486 | - $val = []; |
|
| 2487 | - $parent = $boucles[$idb]->id_parent; |
|
| 2488 | - |
|
| 2489 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2490 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2491 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2492 | - if ( |
|
| 2493 | - (is_countable($params) ? count($params) : 0) == 1 |
|
| 2494 | - && (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2495 | - && $params[0][0]->type == 'texte' |
|
| 2496 | - && $params[0][2]->type == 'texte' |
|
| 2497 | - && ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2498 | - && ($p == "'" || $p == '"') |
|
| 2499 | - && $params[0][1]->type == 'champ' |
|
| 2500 | - ) { |
|
| 2501 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2502 | - } else { |
|
| 2503 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2504 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2505 | - $val[] = strcasecmp($op, 'IN') == 0 |
|
| 2506 | - ? $a |
|
| 2507 | - // toujours quoter en char ici |
|
| 2508 | - : kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2509 | - } |
|
| 2510 | - } |
|
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - $fct = $args_sql = ''; |
|
| 2514 | - // fonction SQL ? |
|
| 2515 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2516 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2517 | - $fct = $m[1]; |
|
| 2518 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2519 | - $col = $a[1]; |
|
| 2520 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2521 | - $col = $m[1]; |
|
| 2522 | - $args_sql = $m[2]; |
|
| 2523 | - } |
|
| 2524 | - $args_sql .= $a[2]; |
|
| 2525 | - } |
|
| 2526 | - |
|
| 2527 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2443 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2444 | + if ((is_countable($crit->param) ? count($crit->param) : 0) == 0) { |
|
| 2445 | + $op = '='; |
|
| 2446 | + $col = $val = $crit->op; |
|
| 2447 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2448 | + $val = $r[2]; |
|
| 2449 | + } |
|
| 2450 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2451 | + if ($val == 'lang') { |
|
| 2452 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2453 | + } else { |
|
| 2454 | + $defaut = null; |
|
| 2455 | + if ($val == 'id_parent') { |
|
| 2456 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2457 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2458 | + // pour eviter l'erreur SQL |
|
| 2459 | + $val = $boucles[$idb]->primary; |
|
| 2460 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2461 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2462 | + } elseif ($val == 'id_enfant') { |
|
| 2463 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2464 | + // de la boucle superieure |
|
| 2465 | + $val = 'id_parent'; |
|
| 2466 | + } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
|
| 2467 | + // un critere conditionnel sur date est traite a part |
|
| 2468 | + // car la date est mise d'office par SPIP, |
|
| 2469 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2473 | + $val = [kwote($val)]; |
|
| 2474 | + } |
|
| 2475 | + } else { |
|
| 2476 | + // comparaison explicite |
|
| 2477 | + // le phraseur impose que le premier param soit du texte |
|
| 2478 | + $params = $crit->param; |
|
| 2479 | + $op = $crit->op; |
|
| 2480 | + if ($op == '==') { |
|
| 2481 | + $op = 'REGEXP'; |
|
| 2482 | + } |
|
| 2483 | + $col = array_shift($params); |
|
| 2484 | + $col = $col[0]->texte; |
|
| 2485 | + |
|
| 2486 | + $val = []; |
|
| 2487 | + $parent = $boucles[$idb]->id_parent; |
|
| 2488 | + |
|
| 2489 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2490 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2491 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2492 | + if ( |
|
| 2493 | + (is_countable($params) ? count($params) : 0) == 1 |
|
| 2494 | + && (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2495 | + && $params[0][0]->type == 'texte' |
|
| 2496 | + && $params[0][2]->type == 'texte' |
|
| 2497 | + && ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2498 | + && ($p == "'" || $p == '"') |
|
| 2499 | + && $params[0][1]->type == 'champ' |
|
| 2500 | + ) { |
|
| 2501 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2502 | + } else { |
|
| 2503 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2504 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2505 | + $val[] = strcasecmp($op, 'IN') == 0 |
|
| 2506 | + ? $a |
|
| 2507 | + // toujours quoter en char ici |
|
| 2508 | + : kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2509 | + } |
|
| 2510 | + } |
|
| 2511 | + } |
|
| 2512 | + |
|
| 2513 | + $fct = $args_sql = ''; |
|
| 2514 | + // fonction SQL ? |
|
| 2515 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2516 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2517 | + $fct = $m[1]; |
|
| 2518 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2519 | + $col = $a[1]; |
|
| 2520 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2521 | + $col = $m[1]; |
|
| 2522 | + $args_sql = $m[2]; |
|
| 2523 | + } |
|
| 2524 | + $args_sql .= $a[2]; |
|
| 2525 | + } |
|
| 2526 | + |
|
| 2527 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2528 | 2528 | } |
| 2529 | 2529 | |
| 2530 | 2530 | // compatibilite ancienne version |
| 2531 | 2531 | |
| 2532 | 2532 | function calculer_vieux_in($params) { |
| 2533 | - $deb = $params[0][0]; |
|
| 2534 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2535 | - $last = $params[$k]; |
|
| 2536 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2537 | - $last = $last[$j]; |
|
| 2538 | - $n = isset($last->texte) ? strlen((string) $last->texte) : 0; |
|
| 2539 | - |
|
| 2540 | - if ( |
|
| 2541 | - !((isset($deb->texte[0]) && $deb->texte[0] == '(') |
|
| 2542 | - && (isset($last->texte[$n - 1]) && $last->texte[$n - 1] == ')')) |
|
| 2543 | - ) { |
|
| 2544 | - return $params; |
|
| 2545 | - } |
|
| 2546 | - $params[0][0]->texte = substr((string) $deb->texte, 1); |
|
| 2547 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2548 | - $last = $params[$k][$j]; |
|
| 2549 | - $n = strlen((string) $last->texte); |
|
| 2550 | - $params[$k][$j]->texte = substr((string) $last->texte, 0, $n - 1); |
|
| 2551 | - $newp = []; |
|
| 2552 | - foreach ($params as $v) { |
|
| 2553 | - if ($v[0]->type != 'texte') { |
|
| 2554 | - $newp[] = $v; |
|
| 2555 | - } else { |
|
| 2556 | - foreach (explode(',', (string) $v[0]->texte) as $x) { |
|
| 2557 | - $t = new Texte(); |
|
| 2558 | - $t->texte = $x; |
|
| 2559 | - $newp[] = [$t]; |
|
| 2560 | - } |
|
| 2561 | - } |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - return $newp; |
|
| 2533 | + $deb = $params[0][0]; |
|
| 2534 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2535 | + $last = $params[$k]; |
|
| 2536 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2537 | + $last = $last[$j]; |
|
| 2538 | + $n = isset($last->texte) ? strlen((string) $last->texte) : 0; |
|
| 2539 | + |
|
| 2540 | + if ( |
|
| 2541 | + !((isset($deb->texte[0]) && $deb->texte[0] == '(') |
|
| 2542 | + && (isset($last->texte[$n - 1]) && $last->texte[$n - 1] == ')')) |
|
| 2543 | + ) { |
|
| 2544 | + return $params; |
|
| 2545 | + } |
|
| 2546 | + $params[0][0]->texte = substr((string) $deb->texte, 1); |
|
| 2547 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2548 | + $last = $params[$k][$j]; |
|
| 2549 | + $n = strlen((string) $last->texte); |
|
| 2550 | + $params[$k][$j]->texte = substr((string) $last->texte, 0, $n - 1); |
|
| 2551 | + $newp = []; |
|
| 2552 | + foreach ($params as $v) { |
|
| 2553 | + if ($v[0]->type != 'texte') { |
|
| 2554 | + $newp[] = $v; |
|
| 2555 | + } else { |
|
| 2556 | + foreach (explode(',', (string) $v[0]->texte) as $x) { |
|
| 2557 | + $t = new Texte(); |
|
| 2558 | + $t->texte = $x; |
|
| 2559 | + $newp[] = [$t]; |
|
| 2560 | + } |
|
| 2561 | + } |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + return $newp; |
|
| 2565 | 2565 | } |
| 2566 | 2566 | |
| 2567 | 2567 | /** |
@@ -2580,91 +2580,91 @@ discard block |
||
| 2580 | 2580 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2581 | 2581 | **/ |
| 2582 | 2582 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2583 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2584 | - return ''; |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - $boucle = $boucles[$idb]; |
|
| 2588 | - $table = $boucle->show; |
|
| 2589 | - |
|
| 2590 | - // si c'est une colonne de la table, ne rien faire |
|
| 2591 | - if (isset($table['field'][$col])) { |
|
| 2592 | - return ''; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - // Le type de critère à prendre en compte |
|
| 2596 | - $col = $regs[1]; |
|
| 2597 | - |
|
| 2598 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2599 | - if (isset($regs[3]) && ($suite = $regs[3])) { |
|
| 2600 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2601 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2602 | - $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2603 | - |
|
| 2604 | - $pred = $date_orig; |
|
| 2605 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2606 | - // Si aucune déclaration trouvée, on quitte |
|
| 2607 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2608 | - return ''; |
|
| 2609 | - } |
|
| 2610 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2611 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2612 | - |
|
| 2613 | - // Si c'est pour du relatif |
|
| 2614 | - if (isset($regs[2]) && ($rel = $regs[2])) { |
|
| 2615 | - $pred = 'date'; |
|
| 2616 | - } |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2620 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2621 | - ") . '\""; |
|
| 2622 | - |
|
| 2623 | - $col_vraie = $date_orig; |
|
| 2624 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2625 | - |
|
| 2626 | - switch ($col) { |
|
| 2627 | - case 'date': |
|
| 2628 | - $col = $date_orig; |
|
| 2629 | - break; |
|
| 2630 | - case 'jour': |
|
| 2631 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2632 | - break; |
|
| 2633 | - case 'mois': |
|
| 2634 | - $col = "MONTH($date_orig)"; |
|
| 2635 | - break; |
|
| 2636 | - case 'annee': |
|
| 2637 | - $col = "YEAR($date_orig)"; |
|
| 2638 | - break; |
|
| 2639 | - case 'heure': |
|
| 2640 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2641 | - break; |
|
| 2642 | - case 'age': |
|
| 2643 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2644 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2645 | - break; |
|
| 2646 | - case 'age_relatif': |
|
| 2647 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2648 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2649 | - break; |
|
| 2650 | - case 'jour_relatif': |
|
| 2651 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2652 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2653 | - break; |
|
| 2654 | - case 'mois_relatif': |
|
| 2655 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2656 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2657 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2658 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2659 | - break; |
|
| 2660 | - case 'annee_relatif': |
|
| 2661 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2662 | - $date_orig . ')'; |
|
| 2663 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2664 | - break; |
|
| 2665 | - } |
|
| 2666 | - |
|
| 2667 | - return [$col, $col_vraie]; |
|
| 2583 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2584 | + return ''; |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + $boucle = $boucles[$idb]; |
|
| 2588 | + $table = $boucle->show; |
|
| 2589 | + |
|
| 2590 | + // si c'est une colonne de la table, ne rien faire |
|
| 2591 | + if (isset($table['field'][$col])) { |
|
| 2592 | + return ''; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + // Le type de critère à prendre en compte |
|
| 2596 | + $col = $regs[1]; |
|
| 2597 | + |
|
| 2598 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2599 | + if (isset($regs[3]) && ($suite = $regs[3])) { |
|
| 2600 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2601 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2602 | + $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2603 | + |
|
| 2604 | + $pred = $date_orig; |
|
| 2605 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2606 | + // Si aucune déclaration trouvée, on quitte |
|
| 2607 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2608 | + return ''; |
|
| 2609 | + } |
|
| 2610 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2611 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2612 | + |
|
| 2613 | + // Si c'est pour du relatif |
|
| 2614 | + if (isset($regs[2]) && ($rel = $regs[2])) { |
|
| 2615 | + $pred = 'date'; |
|
| 2616 | + } |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2620 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2621 | + ") . '\""; |
|
| 2622 | + |
|
| 2623 | + $col_vraie = $date_orig; |
|
| 2624 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2625 | + |
|
| 2626 | + switch ($col) { |
|
| 2627 | + case 'date': |
|
| 2628 | + $col = $date_orig; |
|
| 2629 | + break; |
|
| 2630 | + case 'jour': |
|
| 2631 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2632 | + break; |
|
| 2633 | + case 'mois': |
|
| 2634 | + $col = "MONTH($date_orig)"; |
|
| 2635 | + break; |
|
| 2636 | + case 'annee': |
|
| 2637 | + $col = "YEAR($date_orig)"; |
|
| 2638 | + break; |
|
| 2639 | + case 'heure': |
|
| 2640 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2641 | + break; |
|
| 2642 | + case 'age': |
|
| 2643 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2644 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2645 | + break; |
|
| 2646 | + case 'age_relatif': |
|
| 2647 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2648 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2649 | + break; |
|
| 2650 | + case 'jour_relatif': |
|
| 2651 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2652 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2653 | + break; |
|
| 2654 | + case 'mois_relatif': |
|
| 2655 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2656 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2657 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2658 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2659 | + break; |
|
| 2660 | + case 'annee_relatif': |
|
| 2661 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2662 | + $date_orig . ')'; |
|
| 2663 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2664 | + break; |
|
| 2665 | + } |
|
| 2666 | + |
|
| 2667 | + return [$col, $col_vraie]; |
|
| 2668 | 2668 | } |
| 2669 | 2669 | |
| 2670 | 2670 | /** |
@@ -2683,16 +2683,16 @@ discard block |
||
| 2683 | 2683 | * de colonne SQL et une date. |
| 2684 | 2684 | **/ |
| 2685 | 2685 | function calculer_param_date($date_compare, $date_orig) { |
| 2686 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2687 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2688 | - $date_compare = '\'$x\''; |
|
| 2689 | - } else { |
|
| 2690 | - $init = $date_compare; |
|
| 2691 | - } |
|
| 2692 | - |
|
| 2693 | - return |
|
| 2694 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2695 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2686 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2687 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2688 | + $date_compare = '\'$x\''; |
|
| 2689 | + } else { |
|
| 2690 | + $init = $date_compare; |
|
| 2691 | + } |
|
| 2692 | + |
|
| 2693 | + return |
|
| 2694 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2695 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2696 | 2696 | } |
| 2697 | 2697 | |
| 2698 | 2698 | /** |
@@ -2710,17 +2710,17 @@ discard block |
||
| 2710 | 2710 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2711 | 2711 | */ |
| 2712 | 2712 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2713 | - $boucle = &$boucles[$idb]; |
|
| 2713 | + $boucle = &$boucles[$idb]; |
|
| 2714 | 2714 | |
| 2715 | - $args = []; |
|
| 2716 | - foreach ($crit->param as &$param) { |
|
| 2717 | - $args[] = calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 2718 | - } |
|
| 2715 | + $args = []; |
|
| 2716 | + foreach ($crit->param as &$param) { |
|
| 2717 | + $args[] = calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 2718 | + } |
|
| 2719 | 2719 | |
| 2720 | - $boucle->hash .= ' |
|
| 2720 | + $boucle->hash .= ' |
|
| 2721 | 2721 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2722 | 2722 | |
| 2723 | - $boucle->hash .= ' |
|
| 2723 | + $boucle->hash .= ' |
|
| 2724 | 2724 | $command[\'source\'] = array(' . implode(', ', $args) . ");\n"; |
| 2725 | 2725 | } |
| 2726 | 2726 | |
@@ -2738,8 +2738,8 @@ discard block |
||
| 2738 | 2738 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2739 | 2739 | */ |
| 2740 | 2740 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2741 | - $boucle = &$boucles[$idb]; |
|
| 2742 | - $boucle->hash .= ' |
|
| 2741 | + $boucle = &$boucles[$idb]; |
|
| 2742 | + $boucle->hash .= ' |
|
| 2743 | 2743 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2744 | 2744 | } |
| 2745 | 2745 | |
@@ -2755,12 +2755,12 @@ discard block |
||
| 2755 | 2755 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2756 | 2756 | */ |
| 2757 | 2757 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2758 | - $boucle = &$boucles[$idb]; |
|
| 2759 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2760 | - foreach ($crit->param as $param) { |
|
| 2761 | - $boucle->hash .= ' |
|
| 2758 | + $boucle = &$boucles[$idb]; |
|
| 2759 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2760 | + foreach ($crit->param as $param) { |
|
| 2761 | + $boucle->hash .= ' |
|
| 2762 | 2762 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2763 | - } |
|
| 2763 | + } |
|
| 2764 | 2764 | } |
| 2765 | 2765 | |
| 2766 | 2766 | /** |
@@ -2777,16 +2777,16 @@ discard block |
||
| 2777 | 2777 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2778 | 2778 | */ |
| 2779 | 2779 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2780 | - $boucle = &$boucles[$idb]; |
|
| 2781 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2782 | - foreach ($crit->param as $param) { |
|
| 2783 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2784 | - $param, |
|
| 2785 | - $idb, |
|
| 2786 | - $boucles, |
|
| 2787 | - $boucles[$idb]->id_parent |
|
| 2788 | - ) . ";\n"; |
|
| 2789 | - } |
|
| 2780 | + $boucle = &$boucles[$idb]; |
|
| 2781 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2782 | + foreach ($crit->param as $param) { |
|
| 2783 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2784 | + $param, |
|
| 2785 | + $idb, |
|
| 2786 | + $boucles, |
|
| 2787 | + $boucles[$idb]->id_parent |
|
| 2788 | + ) . ";\n"; |
|
| 2789 | + } |
|
| 2790 | 2790 | } |
| 2791 | 2791 | |
| 2792 | 2792 | /** |
@@ -2811,16 +2811,16 @@ discard block |
||
| 2811 | 2811 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2812 | 2812 | */ |
| 2813 | 2813 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2814 | - $boucle = &$boucles[$idb]; |
|
| 2815 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2816 | - foreach ($crit->param as $param) { |
|
| 2817 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2818 | - $param, |
|
| 2819 | - $idb, |
|
| 2820 | - $boucles, |
|
| 2821 | - $boucles[$idb]->id_parent |
|
| 2822 | - ) . ";\n"; |
|
| 2823 | - } |
|
| 2814 | + $boucle = &$boucles[$idb]; |
|
| 2815 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2816 | + foreach ($crit->param as $param) { |
|
| 2817 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2818 | + $param, |
|
| 2819 | + $idb, |
|
| 2820 | + $boucles, |
|
| 2821 | + $boucles[$idb]->id_parent |
|
| 2822 | + ) . ";\n"; |
|
| 2823 | + } |
|
| 2824 | 2824 | } |
| 2825 | 2825 | |
| 2826 | 2826 | /** |
@@ -2835,11 +2835,11 @@ discard block |
||
| 2835 | 2835 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2836 | 2836 | */ |
| 2837 | 2837 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2838 | - $boucle = &$boucles[$idb]; |
|
| 2839 | - foreach ($crit->param as $param) { |
|
| 2840 | - $boucle->hash .= ' |
|
| 2838 | + $boucle = &$boucles[$idb]; |
|
| 2839 | + foreach ($crit->param as $param) { |
|
| 2840 | + $boucle->hash .= ' |
|
| 2841 | 2841 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2842 | - } |
|
| 2842 | + } |
|
| 2843 | 2843 | } |
| 2844 | 2844 | |
| 2845 | 2845 | |
@@ -2871,20 +2871,20 @@ discard block |
||
| 2871 | 2871 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2872 | 2872 | */ |
| 2873 | 2873 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2874 | - $boucle = &$boucles[$idb]; |
|
| 2875 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2876 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2877 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2878 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2879 | - if ($crit->param) { |
|
| 2880 | - foreach ($crit->param as $param) { |
|
| 2881 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2882 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2883 | - } |
|
| 2884 | - // interdire {si 0} aussi ! |
|
| 2885 | - } else { |
|
| 2886 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2887 | - } |
|
| 2874 | + $boucle = &$boucles[$idb]; |
|
| 2875 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2876 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2877 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2878 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2879 | + if ($crit->param) { |
|
| 2880 | + foreach ($crit->param as $param) { |
|
| 2881 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2882 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2883 | + } |
|
| 2884 | + // interdire {si 0} aussi ! |
|
| 2885 | + } else { |
|
| 2886 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2887 | + } |
|
| 2888 | 2888 | } |
| 2889 | 2889 | |
| 2890 | 2890 | /** |
@@ -2902,27 +2902,27 @@ discard block |
||
| 2902 | 2902 | */ |
| 2903 | 2903 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2904 | 2904 | |
| 2905 | - $not = $crit->not; |
|
| 2906 | - $boucle = &$boucles[$idb]; |
|
| 2907 | - $primary = $boucle->primary; |
|
| 2905 | + $not = $crit->not; |
|
| 2906 | + $boucle = &$boucles[$idb]; |
|
| 2907 | + $primary = $boucle->primary; |
|
| 2908 | 2908 | |
| 2909 | - if (!$primary || strpos((string) $primary, ',')) { |
|
| 2910 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2909 | + if (!$primary || strpos((string) $primary, ',')) { |
|
| 2910 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2911 | 2911 | |
| 2912 | - return; |
|
| 2913 | - } |
|
| 2914 | - $table = $boucle->type_requete; |
|
| 2915 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2912 | + return; |
|
| 2913 | + } |
|
| 2914 | + $table = $boucle->type_requete; |
|
| 2915 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2916 | 2916 | |
| 2917 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2917 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2918 | 2918 | |
| 2919 | - $in = 'IN'; |
|
| 2920 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2921 | - if ($not) { |
|
| 2922 | - $where = ["'NOT'", $where]; |
|
| 2923 | - } |
|
| 2919 | + $in = 'IN'; |
|
| 2920 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2921 | + if ($not) { |
|
| 2922 | + $where = ["'NOT'", $where]; |
|
| 2923 | + } |
|
| 2924 | 2924 | |
| 2925 | - $boucle->where[] = $where; |
|
| 2925 | + $boucle->where[] = $where; |
|
| 2926 | 2926 | } |
| 2927 | 2927 | |
| 2928 | 2928 | /** |
@@ -2938,8 +2938,8 @@ discard block |
||
| 2938 | 2938 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2939 | 2939 | */ |
| 2940 | 2940 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2941 | - $not = $crit->not; |
|
| 2942 | - $crit->not = !$not; |
|
| 2943 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2944 | - $crit->not = $not; |
|
| 2941 | + $not = $crit->not; |
|
| 2942 | + $crit->not = !$not; |
|
| 2943 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2944 | + $crit->not = $not; |
|
| 2945 | 2945 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $boucle = &$boucles[$idb]; |
| 51 | 51 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 52 | 52 | |
| 53 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 54 | 54 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | $id = $boucle->primary; |
| 74 | 74 | |
| 75 | 75 | if ($not || !$id) { |
| 76 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 76 | + return ['zbug_critere_inconnu', ['critere' => $not.$crit->op]]; |
|
| 77 | 77 | } |
| 78 | 78 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 79 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 79 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | $not = ($crit->not ? '' : 'NOT'); |
| 108 | 108 | |
| 109 | 109 | // le doublon s'applique sur un type de boucle (article) |
| 110 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + $nom = "'".$boucle->type_requete."'"; |
|
| 111 | 111 | |
| 112 | 112 | // compléter le nom avec un nom précisé {doublons nom} |
| 113 | 113 | // on obtient $nom = "'article' . 'nom'" |
| 114 | 114 | if (isset($crit->param[0])) { |
| 115 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | // $doublons et son index, ici $nom |
| 125 | 125 | |
| 126 | 126 | // debut du code "sql_in('articles.id_article', " |
| 127 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 128 | 128 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 129 | 129 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 130 | - $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 130 | + $debut_doub = '$doublons['.($not ? $boucle->doublons.'[]= ' : ('')); |
|
| 131 | 131 | |
| 132 | 132 | // le debut complet du code des doublons |
| 133 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + $debut_doub = $debut_in.$debut_doub; |
|
| 134 | 134 | |
| 135 | 135 | // nom du doublon "('article' . 'nom')]" |
| 136 | 136 | $fin_doub = "($nom)]"; |
@@ -140,22 +140,22 @@ discard block |
||
| 140 | 140 | foreach ($boucle->where as $k => $w) { |
| 141 | 141 | if (str_starts_with((string) $w[0], $debut_doub)) { |
| 142 | 142 | // fusionner le sql_in (du where) |
| 143 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 143 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr((string) $w[0], strlen($debut_in)); |
|
| 144 | 144 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 145 | 145 | $x = strpos((string) $boucle->hash, $init_comment); |
| 146 | 146 | $len = strlen($init_comment); |
| 147 | 147 | $boucle->hash = |
| 148 | - substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 148 | + substr((string) $boucle->hash, 0, $x + $len).$init_code.substr((string) $boucle->hash, $x + $len); |
|
| 149 | 149 | |
| 150 | 150 | return; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 155 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 156 | 156 | |
| 157 | 157 | // déclarer le doublon s'il n'existe pas encore |
| 158 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + $boucle->hash .= $init_comment.$init_code; |
|
| 159 | 159 | |
| 160 | 160 | |
| 161 | 161 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $deux = $deux[0]->texte; |
| 218 | 218 | if ($deux) { |
| 219 | 219 | $boucles[$idb]->limit = |
| 220 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 220 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 221 | 221 | } else { |
| 222 | 222 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 223 | 223 | } |
@@ -280,26 +280,26 @@ discard block |
||
| 280 | 280 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr((string) $type, 1)); |
|
| 284 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 285 | 285 | $partie = |
| 286 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 288 | 288 | . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
| 289 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 290 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 291 | 291 | . "\t}\n" |
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 293 | 293 | |
| 294 | 294 | $boucle->hash .= ' |
| 295 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 296 | 296 | |
| 297 | 297 | $boucle->total_parties = $pas; |
| 298 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 299 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 300 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 301 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | 303 | if ( |
| 304 | 304 | $boucle->primary |
| 305 | 305 | && !preg_match('/[,\s]/', (string) $boucle->primary) |
@@ -346,24 +346,24 @@ discard block |
||
| 346 | 346 | $boucle->hash .= ' |
| 347 | 347 | // RECHERCHE' |
| 348 | 348 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 349 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 351 | + } else' : '').' |
|
| 352 | 352 | { |
| 353 | 353 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 354 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 354 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 355 | } |
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 359 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 360 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 361 | $boucle->select[] = $t; |
| 362 | 362 | } # pour postgres, neuneu ici |
| 363 | 363 | // jointure uniquement sur le serveur principal |
| 364 | 364 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 365 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 366 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 367 | 367 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 368 | } |
| 369 | 369 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | $c = |
| 431 | 431 | [ |
| 432 | 432 | "'OR'", |
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 433 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 434 | 434 | ["'='", "'$table.id_trad'", "'0'"] |
| 435 | 435 | ]; |
| 436 | 436 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -453,13 +453,13 @@ discard block |
||
| 453 | 453 | $boucle = &$boucles[$idb]; |
| 454 | 454 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 455 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 457 | 457 | |
| 458 | 458 | if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 459 | 459 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 460 | 460 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 461 | 461 | else { |
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]; |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
@@ -512,16 +512,16 @@ discard block |
||
| 512 | 512 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 513 | 513 | $decompose = decompose_champ_id_objet($champ); |
| 514 | 514 | $champ = array_shift($decompose); |
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 515 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 516 | 516 | } |
| 517 | 517 | } else { |
| 518 | 518 | $cle = $boucle->id_table; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 521 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 523 | 523 | $boucle->where[] = $crit->cond |
| 524 | - ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 524 | + ? "($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')' |
|
| 525 | 525 | : $c; |
| 526 | 526 | } |
| 527 | 527 | |
@@ -542,9 +542,9 @@ discard block |
||
| 542 | 542 | $not = ($crit->not ? 'NOT' : ''); |
| 543 | 543 | $serveur = $boucle->sql_serveur; |
| 544 | 544 | |
| 545 | - $c = "sql_in('" . |
|
| 546 | - $boucle->id_table . '.' . $boucle->primary |
|
| 547 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 545 | + $c = "sql_in('". |
|
| 546 | + $boucle->id_table.'.'.$boucle->primary |
|
| 547 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 548 | 548 | |
| 549 | 549 | $boucle->where[] = $c; |
| 550 | 550 | } |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | $t = table_objet_sql($r[1]); |
| 577 | 577 | $t = array_search($t, $boucles[$idb]->from); |
| 578 | 578 | if ($t) { |
| 579 | - $t .= '.' . $r[2]; |
|
| 579 | + $t .= '.'.$r[2]; |
|
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | } else { |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | $boucles[$idb]->select[] = $t; |
| 592 | 592 | } |
| 593 | 593 | } else { |
| 594 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | 597 | |
@@ -661,25 +661,25 @@ discard block |
||
| 661 | 661 | (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
| 662 | 662 | || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
| 663 | 663 | ) { |
| 664 | - $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | + $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 665 | 665 | } else { |
| 666 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } else { |
| 670 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.(is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 675 | 675 | $boucle = $boucles[$idb]; |
| 676 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | - $var = '$champs_' . $idb; |
|
| 676 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 677 | + $var = '$champs_'.$idb; |
|
| 678 | 678 | $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
| 679 | 679 | if (!$desc) { |
| 680 | 680 | $desc = $boucle->show['field']; |
| 681 | 681 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 682 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 683 | 683 | } |
| 684 | 684 | if ($desc) { |
| 685 | 685 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | $sens = " . ' DESC'"; |
| 755 | 755 | } |
| 756 | 756 | if (isset($boucle->modificateur['collate'])) { |
| 757 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | // Pour chaque paramètre du critère |
@@ -776,14 +776,14 @@ discard block |
||
| 776 | 776 | if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
| 777 | 777 | $expression = trim($m[1]); |
| 778 | 778 | $champ = trim($m[2]); |
| 779 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 780 | 780 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 781 | 781 | } else { |
| 782 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 786 | - } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 786 | + } elseif ($boucle->type_requete == 'DATA' || preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', (string) $par, $match)) { |
|
| 787 | 787 | // {par FONCTION(champ)} |
| 788 | 788 | if (isset($match) && count($match) > 2) { |
| 789 | 789 | $par = substr($match[2], 1, -1); |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | if ($par == 'hasard') { |
| 794 | 794 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 795 | 795 | } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
| 796 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 797 | 797 | } else { |
| 798 | 798 | // cas général {par champ}, {par table.champ}, ... |
| 799 | 799 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | |
| 803 | 803 | // on ne sait pas traiter… |
| 804 | 804 | else { |
| 805 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // En cas d'erreur de squelette retournée par une fonction |
@@ -822,12 +822,12 @@ discard block |
||
| 822 | 822 | |
| 823 | 823 | if ($fct) { |
| 824 | 824 | $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
| 825 | - ? "'$fct(" . $r[1] . ")'" |
|
| 825 | + ? "'$fct(".$r[1].")'" |
|
| 826 | 826 | : "'$fct(' . $order . ')'"; |
| 827 | 827 | } |
| 828 | - $t = $order . $collecte . $sens; |
|
| 828 | + $t = $order.$collecte.$sens; |
|
| 829 | 829 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 830 | - $t = $r[1] . $r[2]; |
|
| 830 | + $t = $r[1].$r[2]; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | $boucle->order[] = $t; |
@@ -877,16 +877,16 @@ discard block |
||
| 877 | 877 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 878 | 878 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 879 | 879 | if (is_array($_champ)) { |
| 880 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 880 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 881 | 881 | } |
| 882 | 882 | $boucle = &$boucles[$idb]; |
| 883 | - $texte = '0+' . $_champ; |
|
| 883 | + $texte = '0+'.$_champ; |
|
| 884 | 884 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 885 | 885 | if ($suite !== "''") { |
| 886 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 886 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 887 | 887 | } |
| 888 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 888 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 889 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 890 | 890 | |
| 891 | 891 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 892 | 892 | $orderassinum = trim($orderassinum, "'"); |
@@ -913,13 +913,13 @@ discard block |
||
| 913 | 913 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 914 | 914 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 915 | 915 | if (is_array($_champ)) { |
| 916 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 917 | 917 | } |
| 918 | 918 | $boucle = &$boucles[$idb]; |
| 919 | - $texte = '0+' . $_champ; |
|
| 919 | + $texte = '0+'.$_champ; |
|
| 920 | 920 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 921 | 921 | if ($suite !== "''") { |
| 922 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | $as = false; |
@@ -935,8 +935,8 @@ discard block |
||
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | if (!$as) { |
| 938 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | - $boucle->select[] = $select . $as; |
|
| 938 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 939 | + $boucle->select[] = $select.$as; |
|
| 940 | 940 | } |
| 941 | 941 | return "'$as'"; |
| 942 | 942 | } |
@@ -960,10 +960,10 @@ discard block |
||
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | 961 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 962 | 962 | if (is_array($_champ)) { |
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 964 | 964 | } |
| 965 | 965 | $boucle = &$boucles[$idb]; |
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 966 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 967 | 967 | return "'multi'"; |
| 968 | 968 | } |
| 969 | 969 | |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | |
| 989 | 989 | // le champ existe dans la table, pas de souci (le plus commun) |
| 990 | 990 | if (isset($desc['field'][$par])) { |
| 991 | - $par = $boucle->id_table . '.' . $par; |
|
| 991 | + $par = $boucle->id_table.'.'.$par; |
|
| 992 | 992 | } |
| 993 | 993 | // le champ est peut être une jointure |
| 994 | 994 | else { |
@@ -1009,24 +1009,24 @@ discard block |
||
| 1009 | 1009 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1010 | 1010 | // Si la table est déjà dans le from, on la réutilise. |
| 1011 | 1011 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1012 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1012 | + $par = $infos['alias'].'.'.$champ; |
|
| 1013 | 1013 | } elseif ( |
| 1014 | 1014 | $boucle->jointures_explicites |
| 1015 | 1015 | && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
| 1016 | 1016 | ) { |
| 1017 | - $par = $alias . '.' . $champ; |
|
| 1017 | + $par = $alias.'.'.$champ; |
|
| 1018 | 1018 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1019 | - $par = $alias . '.' . $champ; |
|
| 1019 | + $par = $alias.'.'.$champ; |
|
| 1020 | 1020 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1021 | 1021 | } elseif ( |
| 1022 | 1022 | $table_alias |
| 1023 | 1023 | && isset($boucle->from[$table_alias]) |
| 1024 | 1024 | && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
| 1025 | 1025 | ) { |
| 1026 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1026 | + $par = $infos['alias'].'.'.$champ; |
|
| 1027 | 1027 | } elseif ($table) { |
| 1028 | 1028 | // On avait table + champ, mais on ne les a pas trouvés |
| 1029 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1030 | 1030 | } else { |
| 1031 | 1031 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1032 | 1032 | } |
@@ -1077,9 +1077,9 @@ discard block |
||
| 1077 | 1077 | $boucle->default_order[] = ' DESC'; |
| 1078 | 1078 | } |
| 1079 | 1079 | } else { |
| 1080 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1080 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1081 | 1081 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1082 | - $t = $r[1] . $r[2]; |
|
| 1082 | + $t = $r[1].$r[2]; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | $boucle->order[$n - 1] = $t; |
| 1085 | 1085 | } |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | |
| 1117 | 1117 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1118 | 1118 | |
| 1119 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1119 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1120 | 1120 | $boucle->order[] = $order; |
| 1121 | 1121 | } |
| 1122 | 1122 | |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | $params = $crit->param; |
| 1126 | 1126 | |
| 1127 | 1127 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1128 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1128 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | $boucle = &$boucles[$idb]; |
@@ -1146,7 +1146,7 @@ discard block |
||
| 1146 | 1146 | if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
| 1147 | 1147 | $date = $date[0]->texte; |
| 1148 | 1148 | if (!isset($fields[$date])) { |
| 1149 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1149 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } else { |
| 1152 | 1152 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1158,38 +1158,38 @@ discard block |
||
| 1158 | 1158 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1159 | 1159 | } |
| 1160 | 1160 | $annee = $params ? array_shift($params) : ''; |
| 1161 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1162 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1161 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1162 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1163 | 1163 | ') ? $x : date("Y"))'; |
| 1164 | 1164 | |
| 1165 | 1165 | $mois = $params ? array_shift($params) : ''; |
| 1166 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1167 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1166 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1167 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1168 | 1168 | ') ? $x : date("m"))'; |
| 1169 | 1169 | |
| 1170 | 1170 | $jour = $params ? array_shift($params) : ''; |
| 1171 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1172 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1171 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1172 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1173 | 1173 | ') ? $x : date("d"))'; |
| 1174 | 1174 | |
| 1175 | 1175 | $annee2 = $params ? array_shift($params) : ''; |
| 1176 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1177 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1176 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1177 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1178 | 1178 | ') ? $x : date("Y"))'; |
| 1179 | 1179 | |
| 1180 | 1180 | $mois2 = $params ? array_shift($params) : ''; |
| 1181 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1182 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1181 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1182 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1183 | 1183 | ') ? $x : date("m"))'; |
| 1184 | 1184 | |
| 1185 | 1185 | $jour2 = $params ? array_shift($params) : ''; |
| 1186 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1187 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1186 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1187 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1188 | 1188 | ') ? $x : date("d"))'; |
| 1189 | 1189 | |
| 1190 | - $date = $boucle->id_table . ".$date"; |
|
| 1190 | + $date = $boucle->id_table.".$date"; |
|
| 1191 | 1191 | |
| 1192 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1192 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1193 | 1193 | if ($type == 'jour') { |
| 1194 | 1194 | $boucle->where[] = [ |
| 1195 | 1195 | "'='", |
@@ -1261,14 +1261,13 @@ discard block |
||
| 1261 | 1261 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1262 | 1262 | |
| 1263 | 1263 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1264 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1264 | + $boucle->limit = $a11.','.$a21; |
|
| 1265 | 1265 | } else { |
| 1266 | 1266 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1267 | 1267 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1268 | 1268 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1269 | 1269 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1270 | - $mode = (($op == '/') ? '/' : |
|
| 1271 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1270 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1272 | 1271 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1273 | 1272 | if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
| 1274 | 1273 | $boucle->limit = |
@@ -1314,8 +1313,7 @@ discard block |
||
| 1314 | 1313 | // {1/3} |
| 1315 | 1314 | if ($op1 == '/') { |
| 1316 | 1315 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1317 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1318 | - "($total_parties ? $total_parties : 1)"; |
|
| 1316 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1319 | 1317 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1320 | 1318 | $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
| 1321 | 1319 | } else { |
@@ -1326,15 +1324,13 @@ discard block |
||
| 1326 | 1324 | |
| 1327 | 1325 | // cas {x,n-1} |
| 1328 | 1326 | if ($op2 == '-') { |
| 1329 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1330 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1331 | - ($total_parties . ' - 1')); |
|
| 1327 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1328 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1332 | 1329 | } else { |
| 1333 | 1330 | // {x,1} ou {pagination} |
| 1334 | 1331 | $fin = '$debut_boucle' |
| 1335 | 1332 | . (is_numeric($total_parties) ? |
| 1336 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1337 | - ('+' . $total_parties . ' - 1')); |
|
| 1333 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1338 | 1334 | } |
| 1339 | 1335 | |
| 1340 | 1336 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1352,11 +1348,11 @@ discard block |
||
| 1352 | 1348 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1353 | 1349 | |
| 1354 | 1350 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1355 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1351 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1356 | 1352 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1357 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1358 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1359 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1353 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1354 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1355 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1360 | 1356 | . "\n\tif (\$debut_boucle>0" |
| 1361 | 1357 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1362 | 1358 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1441,14 +1437,14 @@ discard block |
||
| 1441 | 1437 | // critere personnalise ? |
| 1442 | 1438 | if ( |
| 1443 | 1439 | (!$serveur |
| 1444 | - || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1440 | + || !function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere) |
|
| 1445 | 1441 | && !function_exists($f .= '_dist') |
| 1446 | - && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1442 | + && !function_exists($f = 'critere_'.$serveur.'_'.$critere) |
|
| 1447 | 1443 | && !function_exists($f .= '_dist') |
| 1448 | 1444 | ) |
| 1449 | - && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1445 | + && !function_exists($f = 'critere_'.$table.'_'.$critere) |
|
| 1450 | 1446 | && !function_exists($f .= '_dist') |
| 1451 | - && !function_exists($f = 'critere_' . $critere) |
|
| 1447 | + && !function_exists($f = 'critere_'.$critere) |
|
| 1452 | 1448 | && !function_exists($f .= '_dist') |
| 1453 | 1449 | ) { |
| 1454 | 1450 | // fonction critere standard |
@@ -1480,9 +1476,9 @@ discard block |
||
| 1480 | 1476 | */ |
| 1481 | 1477 | function kwote($lisp, $serveur = '', $type = '') { |
| 1482 | 1478 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1483 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1479 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1484 | 1480 | } else { |
| 1485 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1481 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1486 | 1482 | } |
| 1487 | 1483 | } |
| 1488 | 1484 | |
@@ -1504,7 +1500,7 @@ discard block |
||
| 1504 | 1500 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1505 | 1501 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1506 | 1502 | if (!$r) { |
| 1507 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1503 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1508 | 1504 | } |
| 1509 | 1505 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1510 | 1506 | |
@@ -1529,8 +1525,8 @@ discard block |
||
| 1529 | 1525 | "'NOT'", |
| 1530 | 1526 | [ |
| 1531 | 1527 | "'IN'", |
| 1532 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1533 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1528 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1529 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1534 | 1530 | ] |
| 1535 | 1531 | ]; |
| 1536 | 1532 | } |
@@ -1547,22 +1543,22 @@ discard block |
||
| 1547 | 1543 | $descr = $boucles[$idb]->descr; |
| 1548 | 1544 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1549 | 1545 | |
| 1550 | - $var = '$in' . $cpt++; |
|
| 1546 | + $var = '$in'.$cpt++; |
|
| 1551 | 1547 | $x = "\n\t$var = array();"; |
| 1552 | 1548 | foreach ($val as $k => $v) { |
| 1553 | 1549 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
| 1554 | 1550 | // optimiser le traitement des constantes |
| 1555 | 1551 | if (is_numeric($r[2])) { |
| 1556 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1552 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1557 | 1553 | } else { |
| 1558 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1554 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1559 | 1555 | } |
| 1560 | 1556 | } else { |
| 1561 | 1557 | // Pour permettre de passer des tableaux de valeurs |
| 1562 | 1558 | // on repere l'utilisation brute de #ENV**{X}, |
| 1563 | 1559 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1564 | 1560 | // et on deballe mais en rajoutant l'anti XSS |
| 1565 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1561 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1566 | 1562 | } |
| 1567 | 1563 | } |
| 1568 | 1564 | |
@@ -1576,7 +1572,7 @@ discard block |
||
| 1576 | 1572 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1577 | 1573 | } |
| 1578 | 1574 | |
| 1579 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1575 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1580 | 1576 | } |
| 1581 | 1577 | |
| 1582 | 1578 | /** |
@@ -1649,7 +1645,7 @@ discard block |
||
| 1649 | 1645 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1650 | 1646 | } |
| 1651 | 1647 | // nous aider en mode debug. |
| 1652 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1648 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1653 | 1649 | $boucle->modificateur['id_'] = $champs; |
| 1654 | 1650 | |
| 1655 | 1651 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1904,8 +1900,8 @@ discard block |
||
| 1904 | 1900 | "'NOT'", |
| 1905 | 1901 | [ |
| 1906 | 1902 | "'IN'", |
| 1907 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1908 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1903 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1904 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1909 | 1905 | ] |
| 1910 | 1906 | ]; |
| 1911 | 1907 | } |
@@ -1915,7 +1911,7 @@ discard block |
||
| 1915 | 1911 | // traiter a part la date, elle est mise d'office par SPIP, |
| 1916 | 1912 | if ($crit->cond) { |
| 1917 | 1913 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1918 | - if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 1914 | + if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['".$col."']") { |
|
| 1919 | 1915 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1920 | 1916 | } |
| 1921 | 1917 | |
@@ -2077,7 +2073,7 @@ discard block |
||
| 2077 | 2073 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2078 | 2074 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2079 | 2075 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
| 2080 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2076 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2081 | 2077 | } |
| 2082 | 2078 | // sinon expliciter les |
| 2083 | 2079 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2092,14 +2088,14 @@ discard block |
||
| 2092 | 2088 | ) { |
| 2093 | 2089 | $r = $r[1] |
| 2094 | 2090 | . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
| 2095 | - . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2091 | + . ",'".addslashes((string) $type_cast_quote)."'"; |
|
| 2096 | 2092 | $val[0] = "sql_quote($r)"; |
| 2097 | 2093 | } |
| 2098 | 2094 | elseif ( |
| 2099 | 2095 | str_contains((string) $val[0], '@@defaultcast@@') |
| 2100 | 2096 | && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
| 2101 | 2097 | ) { |
| 2102 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2098 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0]))."'".addslashes((string) $type_cast_quote)."')"; |
|
| 2103 | 2099 | } |
| 2104 | 2100 | } |
| 2105 | 2101 | |
@@ -2107,7 +2103,7 @@ discard block |
||
| 2107 | 2103 | str_contains((string) $val[0], '@@defaultcast@@') |
| 2108 | 2104 | && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
| 2109 | 2105 | ) { |
| 2110 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2106 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2111 | 2107 | } |
| 2112 | 2108 | |
| 2113 | 2109 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2122,7 +2118,7 @@ discard block |
||
| 2122 | 2118 | |
| 2123 | 2119 | // inserer le nom de la table SQL devant le nom du champ |
| 2124 | 2120 | if ($table) { |
| 2125 | - $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2121 | + $arg = $col[0] == '`' ? "$table.".substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2126 | 2122 | } else { |
| 2127 | 2123 | $arg = $col; |
| 2128 | 2124 | } |
@@ -2251,9 +2247,9 @@ discard block |
||
| 2251 | 2247 | **/ |
| 2252 | 2248 | function primary_doublee($decompose, $table) { |
| 2253 | 2249 | $e1 = reset($decompose); |
| 2254 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2250 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2255 | 2251 | |
| 2256 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2252 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2257 | 2253 | } |
| 2258 | 2254 | |
| 2259 | 2255 | /** |
@@ -2292,7 +2288,7 @@ discard block |
||
| 2292 | 2288 | $checkarrivee |
| 2293 | 2289 | && is_string($checkarrivee) |
| 2294 | 2290 | && ($a = table_objet($checkarrivee)) |
| 2295 | - && in_array($a . '_liens', $joints) |
|
| 2291 | + && in_array($a.'_liens', $joints) |
|
| 2296 | 2292 | && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
| 2297 | 2293 | ) { |
| 2298 | 2294 | return $res; |
@@ -2311,12 +2307,12 @@ discard block |
||
| 2311 | 2307 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2312 | 2308 | $joindre = false; |
| 2313 | 2309 | foreach ($cols as $col) { |
| 2314 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2310 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2315 | 2311 | if (trouver_champ($c, $boucle->where)) { |
| 2316 | 2312 | $joindre = true; |
| 2317 | 2313 | } else { |
| 2318 | 2314 | // mais ca peut etre dans le FIELD pour le Having |
| 2319 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2315 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2320 | 2316 | if (trouver_champ($c, $boucle->select)) { |
| 2321 | 2317 | $joindre = true; |
| 2322 | 2318 | } |
@@ -2362,7 +2358,7 @@ discard block |
||
| 2362 | 2358 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2363 | 2359 | |
| 2364 | 2360 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2365 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2361 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2366 | 2362 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2367 | 2363 | |
| 2368 | 2364 | if (!$intermediaire || !$arrivee) { |
@@ -2466,7 +2462,7 @@ discard block |
||
| 2466 | 2462 | } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
| 2467 | 2463 | // un critere conditionnel sur date est traite a part |
| 2468 | 2464 | // car la date est mise d'office par SPIP, |
| 2469 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2465 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2470 | 2466 | } |
| 2471 | 2467 | |
| 2472 | 2468 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2498,7 +2494,7 @@ discard block |
||
| 2498 | 2494 | && ($p == "'" || $p == '"') |
| 2499 | 2495 | && $params[0][1]->type == 'champ' |
| 2500 | 2496 | ) { |
| 2501 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2497 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2502 | 2498 | } else { |
| 2503 | 2499 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2504 | 2500 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2513,7 +2509,7 @@ discard block |
||
| 2513 | 2509 | $fct = $args_sql = ''; |
| 2514 | 2510 | // fonction SQL ? |
| 2515 | 2511 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2516 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2512 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', (string) $col, $m)) { |
|
| 2517 | 2513 | $fct = $m[1]; |
| 2518 | 2514 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2519 | 2515 | $col = $a[1]; |
@@ -2599,7 +2595,7 @@ discard block |
||
| 2599 | 2595 | if (isset($regs[3]) && ($suite = $regs[3])) { |
| 2600 | 2596 | # Recherche de l'existence du champ date_xxxx, |
| 2601 | 2597 | # si oui choisir ce champ, sinon choisir xxxx |
| 2602 | - $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2598 | + $date_orig = isset($table['field']["date$suite"]) ? 'date'.$suite : substr($suite, 1); |
|
| 2603 | 2599 | |
| 2604 | 2600 | $pred = $date_orig; |
| 2605 | 2601 | } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
@@ -2616,12 +2612,12 @@ discard block |
||
| 2616 | 2612 | } |
| 2617 | 2613 | } |
| 2618 | 2614 | |
| 2619 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2620 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2615 | + $date_compare = "\"' . normaliser_date(". |
|
| 2616 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2621 | 2617 | ") . '\""; |
| 2622 | 2618 | |
| 2623 | 2619 | $col_vraie = $date_orig; |
| 2624 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2620 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2625 | 2621 | |
| 2626 | 2622 | switch ($col) { |
| 2627 | 2623 | case 'date': |
@@ -2641,26 +2637,26 @@ discard block |
||
| 2641 | 2637 | break; |
| 2642 | 2638 | case 'age': |
| 2643 | 2639 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2644 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2640 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2645 | 2641 | break; |
| 2646 | 2642 | case 'age_relatif': |
| 2647 | 2643 | $col = calculer_param_date($date_compare, $date_orig); |
| 2648 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2644 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2649 | 2645 | break; |
| 2650 | 2646 | case 'jour_relatif': |
| 2651 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2652 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2647 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2648 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2653 | 2649 | break; |
| 2654 | 2650 | case 'mois_relatif': |
| 2655 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2656 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2657 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2658 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2651 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2652 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2653 | + ')-YEAR('.$date_orig.'))'; |
|
| 2654 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2659 | 2655 | break; |
| 2660 | 2656 | case 'annee_relatif': |
| 2661 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2662 | - $date_orig . ')'; |
|
| 2663 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2657 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2658 | + $date_orig.')'; |
|
| 2659 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2664 | 2660 | break; |
| 2665 | 2661 | } |
| 2666 | 2662 | |
@@ -2718,10 +2714,10 @@ discard block |
||
| 2718 | 2714 | } |
| 2719 | 2715 | |
| 2720 | 2716 | $boucle->hash .= ' |
| 2721 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2717 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2722 | 2718 | |
| 2723 | 2719 | $boucle->hash .= ' |
| 2724 | - $command[\'source\'] = array(' . implode(', ', $args) . ");\n"; |
|
| 2720 | + $command[\'source\'] = array(' . implode(', ', $args).");\n"; |
|
| 2725 | 2721 | } |
| 2726 | 2722 | |
| 2727 | 2723 | /** |
@@ -2740,7 +2736,7 @@ discard block |
||
| 2740 | 2736 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2741 | 2737 | $boucle = &$boucles[$idb]; |
| 2742 | 2738 | $boucle->hash .= ' |
| 2743 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2739 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2744 | 2740 | } |
| 2745 | 2741 | |
| 2746 | 2742 | |
@@ -2759,7 +2755,7 @@ discard block |
||
| 2759 | 2755 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2760 | 2756 | foreach ($crit->param as $param) { |
| 2761 | 2757 | $boucle->hash .= ' |
| 2762 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2758 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2763 | 2759 | } |
| 2764 | 2760 | } |
| 2765 | 2761 | |
@@ -2778,14 +2774,14 @@ discard block |
||
| 2778 | 2774 | */ |
| 2779 | 2775 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2780 | 2776 | $boucle = &$boucles[$idb]; |
| 2781 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2777 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2782 | 2778 | foreach ($crit->param as $param) { |
| 2783 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2779 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2784 | 2780 | $param, |
| 2785 | 2781 | $idb, |
| 2786 | 2782 | $boucles, |
| 2787 | 2783 | $boucles[$idb]->id_parent |
| 2788 | - ) . ";\n"; |
|
| 2784 | + ).";\n"; |
|
| 2789 | 2785 | } |
| 2790 | 2786 | } |
| 2791 | 2787 | |
@@ -2812,14 +2808,14 @@ discard block |
||
| 2812 | 2808 | */ |
| 2813 | 2809 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2814 | 2810 | $boucle = &$boucles[$idb]; |
| 2815 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2811 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2816 | 2812 | foreach ($crit->param as $param) { |
| 2817 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2813 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2818 | 2814 | $param, |
| 2819 | 2815 | $idb, |
| 2820 | 2816 | $boucles, |
| 2821 | 2817 | $boucles[$idb]->id_parent |
| 2822 | - ) . ";\n"; |
|
| 2818 | + ).";\n"; |
|
| 2823 | 2819 | } |
| 2824 | 2820 | } |
| 2825 | 2821 | |
@@ -2838,7 +2834,7 @@ discard block |
||
| 2838 | 2834 | $boucle = &$boucles[$idb]; |
| 2839 | 2835 | foreach ($crit->param as $param) { |
| 2840 | 2836 | $boucle->hash .= ' |
| 2841 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2837 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2842 | 2838 | } |
| 2843 | 2839 | } |
| 2844 | 2840 | |
@@ -2879,7 +2875,7 @@ discard block |
||
| 2879 | 2875 | if ($crit->param) { |
| 2880 | 2876 | foreach ($crit->param as $param) { |
| 2881 | 2877 | $boucle->hash .= "\t\$command['si'][] = " |
| 2882 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2878 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2883 | 2879 | } |
| 2884 | 2880 | // interdire {si 0} aussi ! |
| 2885 | 2881 | } else { |
@@ -2917,7 +2913,7 @@ discard block |
||
| 2917 | 2913 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2918 | 2914 | |
| 2919 | 2915 | $in = 'IN'; |
| 2920 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2916 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2921 | 2917 | if ($not) { |
| 2922 | 2918 | $where = ["'NOT'", $where]; |
| 2923 | 2919 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | * @return array|bool|null |
| 33 | 33 | */ |
| 34 | 34 | function quete_virtuel($id_article, $connect) { |
| 35 | - return sql_getfetsel( |
|
| 36 | - 'virtuel', |
|
| 37 | - 'spip_articles', |
|
| 38 | - ['id_article=' . (int) $id_article, "statut='publie'"], |
|
| 39 | - '', |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - $connect |
|
| 44 | - ); |
|
| 35 | + return sql_getfetsel( |
|
| 36 | + 'virtuel', |
|
| 37 | + 'spip_articles', |
|
| 38 | + ['id_article=' . (int) $id_article, "statut='publie'"], |
|
| 39 | + '', |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + $connect |
|
| 44 | + ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,39 +56,39 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | 58 | function quete_parent_lang($table, $id, string $connect = '') { |
| 59 | - static $cache_quete = []; |
|
| 60 | - |
|
| 61 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | - if ( |
|
| 65 | - !($desc = $trouver_table($table, $connect)) |
|
| 66 | - || !isset($desc['field']['id_rubrique']) |
|
| 67 | - ) { |
|
| 68 | - // pas de parent rubrique, on passe |
|
| 69 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | - } else { |
|
| 71 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | - $cache_quete[$connect][$table]['_select'], |
|
| 80 | - $table, |
|
| 81 | - $cache_quete[$connect][$table]['_id'] . '=' . (int) $id, |
|
| 82 | - '', |
|
| 83 | - '', |
|
| 84 | - '', |
|
| 85 | - '', |
|
| 86 | - $connect |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $cache_quete[$connect][$table][$id] ?? null; |
|
| 59 | + static $cache_quete = []; |
|
| 60 | + |
|
| 61 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | + if ( |
|
| 65 | + !($desc = $trouver_table($table, $connect)) |
|
| 66 | + || !isset($desc['field']['id_rubrique']) |
|
| 67 | + ) { |
|
| 68 | + // pas de parent rubrique, on passe |
|
| 69 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | + } else { |
|
| 71 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | + $cache_quete[$connect][$table]['_select'], |
|
| 80 | + $table, |
|
| 81 | + $cache_quete[$connect][$table]['_id'] . '=' . (int) $id, |
|
| 82 | + '', |
|
| 83 | + '', |
|
| 84 | + '', |
|
| 85 | + '', |
|
| 86 | + $connect |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $cache_quete[$connect][$table][$id] ?? null; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | * @return int |
| 106 | 106 | */ |
| 107 | 107 | function quete_parent($id_rubrique, string $connect = '') { |
| 108 | - if (!$id_rubrique = (int) $id_rubrique) { |
|
| 109 | - return 0; |
|
| 110 | - } |
|
| 111 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 108 | + if (!$id_rubrique = (int) $id_rubrique) { |
|
| 109 | + return 0; |
|
| 110 | + } |
|
| 111 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | 127 | function quete_rubrique($id_article, $serveur) { |
| 128 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 128 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 129 | 129 | |
| 130 | - return $id_parent['id_rubrique'] ?? 0; |
|
| 130 | + return $id_parent['id_rubrique'] ?? 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | * @return int |
| 141 | 141 | */ |
| 142 | 142 | function quete_profondeur($id, string $connect = '') { |
| 143 | - $n = 0; |
|
| 144 | - while ($id) { |
|
| 145 | - $n++; |
|
| 146 | - $id = quete_parent($id, $connect); |
|
| 147 | - } |
|
| 143 | + $n = 0; |
|
| 144 | + while ($id) { |
|
| 145 | + $n++; |
|
| 146 | + $id = quete_parent($id, $connect); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return $n; |
|
| 149 | + return $n; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | * Morceau de la requête SQL testant la date |
| 163 | 163 | */ |
| 164 | 164 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 165 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 166 | - return '1=1'; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return |
|
| 170 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 171 | - && $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 172 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 173 | - : '1=1'; |
|
| 165 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 166 | + return '1=1'; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return |
|
| 170 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 171 | + && $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 172 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 173 | + : '1=1'; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -190,101 +190,101 @@ discard block |
||
| 190 | 190 | * @return array|string |
| 191 | 191 | */ |
| 192 | 192 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 193 | - static $cond = []; |
|
| 194 | - $key = func_get_args(); |
|
| 195 | - $key = implode('-', $key); |
|
| 196 | - if (isset($cond[$key])) { |
|
| 197 | - return $cond[$key]; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $liste_statuts = $publie; |
|
| 201 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 202 | - $liste_statuts = $previsu; |
|
| 203 | - } |
|
| 204 | - $not = false; |
|
| 205 | - if (str_starts_with($liste_statuts, '!')) { |
|
| 206 | - $not = true; |
|
| 207 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 208 | - } |
|
| 209 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 210 | - if (!strlen($liste_statuts)) { |
|
| 211 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 215 | - $where = []; |
|
| 216 | - foreach ($liste_statuts as $k => $v) { |
|
| 217 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 218 | - // a ceux de l'auteur identifie |
|
| 219 | - if (str_contains($v, '/')) { |
|
| 220 | - $v = explode('/', $v); |
|
| 221 | - $filtre = end($v); |
|
| 222 | - $v = reset($v); |
|
| 223 | - $v = preg_replace(',\W,', '', $v); |
|
| 224 | - if ( |
|
| 225 | - $filtre == 'auteur' |
|
| 226 | - && str_contains($mstatut, '.') |
|
| 227 | - && ($objet = explode('.', $mstatut)) |
|
| 228 | - && ($id_table = reset($objet)) |
|
| 229 | - && ($objet = objet_type($id_table)) |
|
| 230 | - ) { |
|
| 231 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | - |
|
| 233 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | - // sinon l’auteur en session |
|
| 235 | - include_spip('inc/securiser_action'); |
|
| 236 | - if ($desc = decrire_token_previsu()) { |
|
| 237 | - $id_auteur = $desc['id_auteur']; |
|
| 238 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 240 | - } else { |
|
| 241 | - $id_auteur = null; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | - if (!$id_auteur) { |
|
| 248 | - $where[] = $w; |
|
| 249 | - } else { |
|
| 250 | - $primary = id_table_objet($objet); |
|
| 251 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | - 'ssss.id_objet', |
|
| 253 | - 'spip_auteurs_liens AS ssss', |
|
| 254 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . (int) $id_auteur, |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - '', |
|
| 259 | - $serveur |
|
| 260 | - ) . '))'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | - else { |
|
| 265 | - $v = ''; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // securite |
|
| 269 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | - } |
|
| 271 | - $liste_statuts = array_filter($liste_statuts); |
|
| 272 | - if (count($liste_statuts) == 1) { |
|
| 273 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 274 | - } else { |
|
| 275 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - while (count($where) > 1) { |
|
| 279 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 280 | - $where[] = $and; |
|
| 281 | - } |
|
| 282 | - $cond[$key] = reset($where); |
|
| 283 | - if ($not) { |
|
| 284 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $cond[$key]; |
|
| 193 | + static $cond = []; |
|
| 194 | + $key = func_get_args(); |
|
| 195 | + $key = implode('-', $key); |
|
| 196 | + if (isset($cond[$key])) { |
|
| 197 | + return $cond[$key]; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $liste_statuts = $publie; |
|
| 201 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 202 | + $liste_statuts = $previsu; |
|
| 203 | + } |
|
| 204 | + $not = false; |
|
| 205 | + if (str_starts_with($liste_statuts, '!')) { |
|
| 206 | + $not = true; |
|
| 207 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 208 | + } |
|
| 209 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 210 | + if (!strlen($liste_statuts)) { |
|
| 211 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 215 | + $where = []; |
|
| 216 | + foreach ($liste_statuts as $k => $v) { |
|
| 217 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 218 | + // a ceux de l'auteur identifie |
|
| 219 | + if (str_contains($v, '/')) { |
|
| 220 | + $v = explode('/', $v); |
|
| 221 | + $filtre = end($v); |
|
| 222 | + $v = reset($v); |
|
| 223 | + $v = preg_replace(',\W,', '', $v); |
|
| 224 | + if ( |
|
| 225 | + $filtre == 'auteur' |
|
| 226 | + && str_contains($mstatut, '.') |
|
| 227 | + && ($objet = explode('.', $mstatut)) |
|
| 228 | + && ($id_table = reset($objet)) |
|
| 229 | + && ($objet = objet_type($id_table)) |
|
| 230 | + ) { |
|
| 231 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | + |
|
| 233 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | + // sinon l’auteur en session |
|
| 235 | + include_spip('inc/securiser_action'); |
|
| 236 | + if ($desc = decrire_token_previsu()) { |
|
| 237 | + $id_auteur = $desc['id_auteur']; |
|
| 238 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 240 | + } else { |
|
| 241 | + $id_auteur = null; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | + if (!$id_auteur) { |
|
| 248 | + $where[] = $w; |
|
| 249 | + } else { |
|
| 250 | + $primary = id_table_objet($objet); |
|
| 251 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | + 'ssss.id_objet', |
|
| 253 | + 'spip_auteurs_liens AS ssss', |
|
| 254 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . (int) $id_auteur, |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + '', |
|
| 259 | + $serveur |
|
| 260 | + ) . '))'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | + else { |
|
| 265 | + $v = ''; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // securite |
|
| 269 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | + } |
|
| 271 | + $liste_statuts = array_filter($liste_statuts); |
|
| 272 | + if (count($liste_statuts) == 1) { |
|
| 273 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 274 | + } else { |
|
| 275 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + while (count($where) > 1) { |
|
| 279 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 280 | + $where[] = $and; |
|
| 281 | + } |
|
| 282 | + $cond[$key] = reset($where); |
|
| 283 | + if ($not) { |
|
| 284 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $cond[$key]; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return array|bool|null |
| 296 | 296 | */ |
| 297 | 297 | function quete_fichier($id_document, $serveur = '') { |
| 298 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 298 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return array|bool |
| 307 | 307 | */ |
| 308 | 308 | function quete_document($id_document, $serveur = '') { |
| 309 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 309 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return array|bool|null |
| 318 | 318 | */ |
| 319 | 319 | function quete_meta($nom, $serveur) { |
| 320 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 320 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -343,67 +343,67 @@ discard block |
||
| 343 | 343 | * Retourne soit un tableau, soit le chemin du fichier. |
| 344 | 344 | */ |
| 345 | 345 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag = false) { |
| 346 | - include_spip('base/objets'); |
|
| 347 | - $nom = strtolower($onoff); |
|
| 348 | - |
|
| 349 | - $cle_objet = id_table_objet($cle_objet); |
|
| 350 | - |
|
| 351 | - while (1) { |
|
| 352 | - $objet = objet_type($cle_objet); |
|
| 353 | - |
|
| 354 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | - |
|
| 356 | - if ($on) { |
|
| 357 | - if ($flag) { |
|
| 358 | - return $on['fichier']; |
|
| 359 | - } else { |
|
| 360 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | - |
|
| 362 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | - // alors on ne cherche pas du tout le survol ici |
|
| 365 | - $off = $onoff != 'ON' ? '' : quete_logo_objet($id, $objet, 'off'); |
|
| 366 | - |
|
| 367 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 368 | - // qui permet de distinguer le changement de logo |
|
| 369 | - // et placer un expire sur le dossier IMG/ |
|
| 370 | - $res = [ |
|
| 371 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | - ($taille ? ' ' . $taille[3] : ('')) |
|
| 374 | - ]; |
|
| 375 | - $res['src'] = $res[0]; |
|
| 376 | - $res['logo_on'] = $res[0]; |
|
| 377 | - $res['logo_off'] = $res[1]; |
|
| 378 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 379 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 380 | - $res['fichier'] = $on['fichier']; |
|
| 381 | - $res['titre'] = ($on['titre'] ?? ''); |
|
| 382 | - $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 383 | - $res['credits'] = ($on['credits'] ?? ''); |
|
| 384 | - $res['alt'] = ($on['alt'] ?? ''); |
|
| 385 | - $res['id'] = ($on['id_document'] ?? 0); |
|
| 386 | - |
|
| 387 | - return $res; |
|
| 388 | - } |
|
| 389 | - } else { |
|
| 390 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 391 | - return ''; |
|
| 392 | - } else { |
|
| 393 | - if ($id_rubrique) { |
|
| 394 | - $cle_objet = 'id_rubrique'; |
|
| 395 | - $id = $id_rubrique; |
|
| 396 | - $id_rubrique = 0; |
|
| 397 | - } else { |
|
| 398 | - if ($id && $cle_objet == 'id_rubrique') { |
|
| 399 | - $id = quete_parent($id); |
|
| 400 | - } else { |
|
| 401 | - return ''; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 346 | + include_spip('base/objets'); |
|
| 347 | + $nom = strtolower($onoff); |
|
| 348 | + |
|
| 349 | + $cle_objet = id_table_objet($cle_objet); |
|
| 350 | + |
|
| 351 | + while (1) { |
|
| 352 | + $objet = objet_type($cle_objet); |
|
| 353 | + |
|
| 354 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | + |
|
| 356 | + if ($on) { |
|
| 357 | + if ($flag) { |
|
| 358 | + return $on['fichier']; |
|
| 359 | + } else { |
|
| 360 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | + |
|
| 362 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | + // alors on ne cherche pas du tout le survol ici |
|
| 365 | + $off = $onoff != 'ON' ? '' : quete_logo_objet($id, $objet, 'off'); |
|
| 366 | + |
|
| 367 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 368 | + // qui permet de distinguer le changement de logo |
|
| 369 | + // et placer un expire sur le dossier IMG/ |
|
| 370 | + $res = [ |
|
| 371 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | + ($taille ? ' ' . $taille[3] : ('')) |
|
| 374 | + ]; |
|
| 375 | + $res['src'] = $res[0]; |
|
| 376 | + $res['logo_on'] = $res[0]; |
|
| 377 | + $res['logo_off'] = $res[1]; |
|
| 378 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 379 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 380 | + $res['fichier'] = $on['fichier']; |
|
| 381 | + $res['titre'] = ($on['titre'] ?? ''); |
|
| 382 | + $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 383 | + $res['credits'] = ($on['credits'] ?? ''); |
|
| 384 | + $res['alt'] = ($on['alt'] ?? ''); |
|
| 385 | + $res['id'] = ($on['id_document'] ?? 0); |
|
| 386 | + |
|
| 387 | + return $res; |
|
| 388 | + } |
|
| 389 | + } else { |
|
| 390 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 391 | + return ''; |
|
| 392 | + } else { |
|
| 393 | + if ($id_rubrique) { |
|
| 394 | + $cle_objet = 'id_rubrique'; |
|
| 395 | + $id = $id_rubrique; |
|
| 396 | + $id_rubrique = 0; |
|
| 397 | + } else { |
|
| 398 | + if ($id && $cle_objet == 'id_rubrique') { |
|
| 399 | + $id = quete_parent($id); |
|
| 400 | + } else { |
|
| 401 | + return ''; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -418,43 +418,43 @@ discard block |
||
| 418 | 418 | * @return bool|array |
| 419 | 419 | **/ |
| 420 | 420 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 421 | - static $chercher_logo; |
|
| 422 | - if (is_null($chercher_logo)) { |
|
| 423 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 424 | - } |
|
| 425 | - $cle_objet = id_table_objet($objet); |
|
| 426 | - |
|
| 427 | - // On cherche pas la méthode classique |
|
| 428 | - $infos_logo = $chercher_logo((int) $id_objet, $cle_objet, $mode); |
|
| 429 | - |
|
| 430 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 431 | - if (!empty($infos_logo)) { |
|
| 432 | - $infos = [ |
|
| 433 | - 'chemin' => $infos_logo[0], |
|
| 434 | - 'timestamp' => $infos_logo[4], |
|
| 435 | - 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 436 | - ]; |
|
| 437 | - foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 438 | - $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 439 | - } |
|
| 440 | - $infos_logo = $infos; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // On passe cette recherche de logo dans un pipeline |
|
| 444 | - $infos_logo = pipeline( |
|
| 445 | - 'quete_logo_objet', |
|
| 446 | - [ |
|
| 447 | - 'args' => [ |
|
| 448 | - 'id_objet' => $id_objet, |
|
| 449 | - 'objet' => $objet, |
|
| 450 | - 'cle_objet' => $cle_objet, |
|
| 451 | - 'mode' => $mode, |
|
| 452 | - ], |
|
| 453 | - 'data' => $infos_logo, |
|
| 454 | - ] |
|
| 455 | - ); |
|
| 456 | - |
|
| 457 | - return $infos_logo; |
|
| 421 | + static $chercher_logo; |
|
| 422 | + if (is_null($chercher_logo)) { |
|
| 423 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 424 | + } |
|
| 425 | + $cle_objet = id_table_objet($objet); |
|
| 426 | + |
|
| 427 | + // On cherche pas la méthode classique |
|
| 428 | + $infos_logo = $chercher_logo((int) $id_objet, $cle_objet, $mode); |
|
| 429 | + |
|
| 430 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 431 | + if (!empty($infos_logo)) { |
|
| 432 | + $infos = [ |
|
| 433 | + 'chemin' => $infos_logo[0], |
|
| 434 | + 'timestamp' => $infos_logo[4], |
|
| 435 | + 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 436 | + ]; |
|
| 437 | + foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 438 | + $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 439 | + } |
|
| 440 | + $infos_logo = $infos; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // On passe cette recherche de logo dans un pipeline |
|
| 444 | + $infos_logo = pipeline( |
|
| 445 | + 'quete_logo_objet', |
|
| 446 | + [ |
|
| 447 | + 'args' => [ |
|
| 448 | + 'id_objet' => $id_objet, |
|
| 449 | + 'objet' => $objet, |
|
| 450 | + 'cle_objet' => $cle_objet, |
|
| 451 | + 'mode' => $mode, |
|
| 452 | + ], |
|
| 453 | + 'data' => $infos_logo, |
|
| 454 | + ] |
|
| 455 | + ); |
|
| 456 | + |
|
| 457 | + return $infos_logo; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -467,25 +467,25 @@ discard block |
||
| 467 | 467 | * @return bool|string |
| 468 | 468 | */ |
| 469 | 469 | function quete_logo_file($row, $connect = null) { |
| 470 | - include_spip('inc/documents'); |
|
| 471 | - $logo = vignette_logo_document($row, $connect); |
|
| 472 | - if (!$logo) { |
|
| 473 | - $logo = image_du_document($row, $connect); |
|
| 474 | - } |
|
| 475 | - if (!$logo) { |
|
| 476 | - $f = charger_fonction('vignette', 'inc'); |
|
| 477 | - $logo = $f($row['extension'], false); |
|
| 478 | - } |
|
| 479 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 480 | - if ( |
|
| 481 | - strcmp((string) $logo, (string) _DIR_PLUGINS) == 0 |
|
| 482 | - || strcmp((string) $logo, (string) _DIR_PLUGINS_DIST) == 0 |
|
| 483 | - || strcmp((string) $logo, _DIR_RACINE . 'prive/') == 0 |
|
| 484 | - ) { |
|
| 485 | - return $logo; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - return get_spip_doc($logo); |
|
| 470 | + include_spip('inc/documents'); |
|
| 471 | + $logo = vignette_logo_document($row, $connect); |
|
| 472 | + if (!$logo) { |
|
| 473 | + $logo = image_du_document($row, $connect); |
|
| 474 | + } |
|
| 475 | + if (!$logo) { |
|
| 476 | + $f = charger_fonction('vignette', 'inc'); |
|
| 477 | + $logo = $f($row['extension'], false); |
|
| 478 | + } |
|
| 479 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 480 | + if ( |
|
| 481 | + strcmp((string) $logo, (string) _DIR_PLUGINS) == 0 |
|
| 482 | + || strcmp((string) $logo, (string) _DIR_PLUGINS_DIST) == 0 |
|
| 483 | + || strcmp((string) $logo, _DIR_RACINE . 'prive/') == 0 |
|
| 484 | + ) { |
|
| 485 | + return $logo; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + return get_spip_doc($logo); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -513,20 +513,20 @@ discard block |
||
| 513 | 513 | */ |
| 514 | 514 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 515 | 515 | |
| 516 | - include_spip('inc/documents'); |
|
| 517 | - $logo = ''; |
|
| 518 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 519 | - $logo = vignette_logo_document($row, $connect); |
|
| 520 | - } |
|
| 521 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 522 | - if ($mode_logo == 'vignette' && !$logo) { |
|
| 523 | - return ''; |
|
| 524 | - } |
|
| 525 | - if ($mode_logo == 'icone') { |
|
| 526 | - $row['fichier'] = ''; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 516 | + include_spip('inc/documents'); |
|
| 517 | + $logo = ''; |
|
| 518 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 519 | + $logo = vignette_logo_document($row, $connect); |
|
| 520 | + } |
|
| 521 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 522 | + if ($mode_logo == 'vignette' && !$logo) { |
|
| 523 | + return ''; |
|
| 524 | + } |
|
| 525 | + if ($mode_logo == 'icone') { |
|
| 526 | + $row['fichier'] = ''; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -538,26 +538,26 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | function quete_html_logo($logo, $align, $lien) { |
| 540 | 540 | |
| 541 | - if (!is_array($logo)) { |
|
| 542 | - return ''; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $contexte = []; |
|
| 546 | - foreach ($logo as $k => $v) { |
|
| 547 | - if (!is_numeric($k)) { |
|
| 548 | - $contexte[$k] = $v; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 553 | - if (!empty($contexte[$champ])) { |
|
| 554 | - $contexte[$champ] = appliquer_traitement_champ($contexte[$champ], $champ, 'document'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - $contexte['align'] = $align; |
|
| 559 | - $contexte['lien'] = $lien; |
|
| 560 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 541 | + if (!is_array($logo)) { |
|
| 542 | + return ''; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $contexte = []; |
|
| 546 | + foreach ($logo as $k => $v) { |
|
| 547 | + if (!is_numeric($k)) { |
|
| 548 | + $contexte[$k] = $v; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 553 | + if (!empty($contexte[$champ])) { |
|
| 554 | + $contexte[$champ] = appliquer_traitement_champ($contexte[$champ], $champ, 'document'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + $contexte['align'] = $align; |
|
| 559 | + $contexte['lien'] = $lien; |
|
| 560 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -571,14 +571,14 @@ discard block |
||
| 571 | 571 | * @return string|false |
| 572 | 572 | */ |
| 573 | 573 | function document_spip_externe($fichier, $connect) { |
| 574 | - if ($connect) { |
|
| 575 | - $site = quete_meta('adresse_site', $connect); |
|
| 576 | - if ($site) { |
|
| 577 | - $dir = quete_meta('dir_img', $connect); |
|
| 578 | - return "$site/$dir$fichier"; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - return false; |
|
| 574 | + if ($connect) { |
|
| 575 | + $site = quete_meta('adresse_site', $connect); |
|
| 576 | + if ($site) { |
|
| 577 | + $dir = quete_meta('dir_img', $connect); |
|
| 578 | + return "$site/$dir$fichier"; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + return false; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -591,23 +591,23 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | function vignette_logo_document($row, string $connect = '') { |
| 593 | 593 | |
| 594 | - if (!$row || empty($row['id_vignette'])) { |
|
| 595 | - return ''; |
|
| 596 | - } |
|
| 597 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 598 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 599 | - return $url; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $f = get_spip_doc($fichier); |
|
| 603 | - if ($f && @file_exists($f)) { |
|
| 604 | - return $f; |
|
| 605 | - } |
|
| 606 | - if ($row['mode'] !== 'vignette') { |
|
| 607 | - return ''; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 594 | + if (!$row || empty($row['id_vignette'])) { |
|
| 595 | + return ''; |
|
| 596 | + } |
|
| 597 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 598 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 599 | + return $url; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + $f = get_spip_doc($fichier); |
|
| 603 | + if ($f && @file_exists($f)) { |
|
| 604 | + return $f; |
|
| 605 | + } |
|
| 606 | + if ($row['mode'] !== 'vignette') { |
|
| 607 | + return ''; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -622,66 +622,66 @@ discard block |
||
| 622 | 622 | * @return bool|string |
| 623 | 623 | */ |
| 624 | 624 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 625 | - static $exposer = []; |
|
| 626 | - |
|
| 627 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 628 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 629 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 630 | - // en static. |
|
| 631 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 632 | - $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 633 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 634 | - // il n'est donc pas utile |
|
| 635 | - $parent = 0; |
|
| 636 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 637 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 638 | - if (isset($enfants[$type])) { |
|
| 639 | - foreach ($enfants[$type] as $t) { |
|
| 640 | - if ( |
|
| 641 | - isset($reference[$t]) |
|
| 642 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 643 | - || isset($reference["@$t"]) |
|
| 644 | - ) { |
|
| 645 | - $type = $t; |
|
| 646 | - $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 647 | - continue; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - $exposer[$m][$type] = []; |
|
| 653 | - if ($principal) { |
|
| 654 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 655 | - foreach ($principaux as $principal) { |
|
| 656 | - $exposer[$m][$type][$principal] = true; |
|
| 657 | - if ($type == 'id_mot') { |
|
| 658 | - if (!$parent) { |
|
| 659 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . (int) $principal, '', '', '', '', $connect); |
|
| 660 | - } |
|
| 661 | - if ($parent) { |
|
| 662 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - if ($type != 'id_groupe') { |
|
| 666 | - if (!$parent) { |
|
| 667 | - if ($type == 'id_rubrique') { |
|
| 668 | - $parent = $principal; |
|
| 669 | - } |
|
| 670 | - if ($type == 'id_article') { |
|
| 671 | - $parent = quete_rubrique($principal, $connect); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - do { |
|
| 675 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 676 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - // And the winner is... |
|
| 684 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 625 | + static $exposer = []; |
|
| 626 | + |
|
| 627 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 628 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 629 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 630 | + // en static. |
|
| 631 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 632 | + $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 633 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 634 | + // il n'est donc pas utile |
|
| 635 | + $parent = 0; |
|
| 636 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 637 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 638 | + if (isset($enfants[$type])) { |
|
| 639 | + foreach ($enfants[$type] as $t) { |
|
| 640 | + if ( |
|
| 641 | + isset($reference[$t]) |
|
| 642 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 643 | + || isset($reference["@$t"]) |
|
| 644 | + ) { |
|
| 645 | + $type = $t; |
|
| 646 | + $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 647 | + continue; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + $exposer[$m][$type] = []; |
|
| 653 | + if ($principal) { |
|
| 654 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 655 | + foreach ($principaux as $principal) { |
|
| 656 | + $exposer[$m][$type][$principal] = true; |
|
| 657 | + if ($type == 'id_mot') { |
|
| 658 | + if (!$parent) { |
|
| 659 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . (int) $principal, '', '', '', '', $connect); |
|
| 660 | + } |
|
| 661 | + if ($parent) { |
|
| 662 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + if ($type != 'id_groupe') { |
|
| 666 | + if (!$parent) { |
|
| 667 | + if ($type == 'id_rubrique') { |
|
| 668 | + $parent = $principal; |
|
| 669 | + } |
|
| 670 | + if ($type == 'id_article') { |
|
| 671 | + $parent = quete_rubrique($principal, $connect); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + do { |
|
| 675 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 676 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + // And the winner is... |
|
| 684 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -696,23 +696,23 @@ discard block |
||
| 696 | 696 | * @return int |
| 697 | 697 | */ |
| 698 | 698 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 699 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 700 | - // ou composee, mais verifions |
|
| 701 | - if (!$primary || preg_match('/[,\s]/', $primary)) { |
|
| 702 | - return 0; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - $pos = 0; |
|
| 706 | - while (($row = $iter->fetch()) && $row[$primary] != $valeur) { |
|
| 707 | - $pos++; |
|
| 708 | - } |
|
| 709 | - // si on a pas trouve |
|
| 710 | - if (!$row || $row[$primary] != $valeur) { |
|
| 711 | - return 0; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // sinon, calculer le bon numero de page |
|
| 715 | - return floor($pos / $pas) * $pas; |
|
| 699 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 700 | + // ou composee, mais verifions |
|
| 701 | + if (!$primary || preg_match('/[,\s]/', $primary)) { |
|
| 702 | + return 0; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + $pos = 0; |
|
| 706 | + while (($row = $iter->fetch()) && $row[$primary] != $valeur) { |
|
| 707 | + $pos++; |
|
| 708 | + } |
|
| 709 | + // si on a pas trouve |
|
| 710 | + if (!$row || $row[$primary] != $valeur) { |
|
| 711 | + return 0; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // sinon, calculer le bon numero de page |
|
| 715 | + return floor($pos / $pas) * $pas; |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -722,8 +722,8 @@ discard block |
||
| 722 | 722 | * @return boolean |
| 723 | 723 | */ |
| 724 | 724 | function is_whereable(mixed $value): bool { |
| 725 | - if (is_array($value) && count($value)) { |
|
| 726 | - return true; |
|
| 727 | - } |
|
| 728 | - return is_scalar($value) && strlen($value); |
|
| 725 | + if (is_array($value) && count($value)) { |
|
| 726 | + return true; |
|
| 727 | + } |
|
| 728 | + return is_scalar($value) && strlen($value); |
|
| 729 | 729 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -29,36 +29,36 @@ discard block |
||
| 29 | 29 | * `on` ou `off` |
| 30 | 30 | */ |
| 31 | 31 | function logo_supprimer($objet, $id_objet, $etat) { |
| 32 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 33 | - $objet = objet_type($objet); |
|
| 34 | - $primary = id_table_objet($objet); |
|
| 35 | - include_spip('inc/chercher_logo'); |
|
| 36 | - |
|
| 37 | - // existe-t-il deja un logo ? |
|
| 38 | - $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 39 | - if ($logo) { |
|
| 40 | - # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 41 | - if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 42 | - spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 43 | - spip_unlink($logo[0]); |
|
| 44 | - } |
|
| 45 | - elseif ( |
|
| 46 | - ($doc = $logo[5]) |
|
| 47 | - && isset($doc['id_document']) |
|
| 48 | - && ($id_document = $doc['id_document']) |
|
| 49 | - ) { |
|
| 50 | - include_spip('action/editer_liens'); |
|
| 51 | - // supprimer le lien dans la base |
|
| 52 | - objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 53 | - |
|
| 54 | - // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 55 | - $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 56 | - if ($liens === []) { |
|
| 57 | - $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 58 | - $supprimer_document($doc['id_document']); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 32 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 33 | + $objet = objet_type($objet); |
|
| 34 | + $primary = id_table_objet($objet); |
|
| 35 | + include_spip('inc/chercher_logo'); |
|
| 36 | + |
|
| 37 | + // existe-t-il deja un logo ? |
|
| 38 | + $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 39 | + if ($logo) { |
|
| 40 | + # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 41 | + if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 42 | + spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 43 | + spip_unlink($logo[0]); |
|
| 44 | + } |
|
| 45 | + elseif ( |
|
| 46 | + ($doc = $logo[5]) |
|
| 47 | + && isset($doc['id_document']) |
|
| 48 | + && ($id_document = $doc['id_document']) |
|
| 49 | + ) { |
|
| 50 | + include_spip('action/editer_liens'); |
|
| 51 | + // supprimer le lien dans la base |
|
| 52 | + objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 53 | + |
|
| 54 | + // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 55 | + $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 56 | + if ($liens === []) { |
|
| 57 | + $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 58 | + $supprimer_document($doc['id_document']); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -75,76 +75,76 @@ discard block |
||
| 75 | 75 | * Erreur, sinon '' |
| 76 | 76 | */ |
| 77 | 77 | function logo_modifier($objet, $id_objet, $etat, $source) { |
| 78 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 79 | - $objet = objet_type($objet); |
|
| 80 | - $primary = id_table_objet($objet); |
|
| 81 | - include_spip('inc/chercher_logo'); |
|
| 82 | - |
|
| 83 | - $mode = preg_replace(',\W,', '', $etat); |
|
| 84 | - if (!$mode) { |
|
| 85 | - spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 86 | - |
|
| 87 | - return 'etat invalide'; |
|
| 88 | - } |
|
| 89 | - // chercher dans la base |
|
| 90 | - $mode_document = 'logo' . $mode; |
|
| 91 | - |
|
| 92 | - include_spip('inc/documents'); |
|
| 93 | - $erreur = ''; |
|
| 94 | - |
|
| 95 | - if (!$source) { |
|
| 96 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 97 | - |
|
| 98 | - return 'source inconnue'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // fichier dans upload/ |
|
| 102 | - if (is_string($source)) { |
|
| 103 | - $tmp_name = false; |
|
| 104 | - if (file_exists($source)) { |
|
| 105 | - $tmp_name = $source; |
|
| 106 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 107 | - $tmp_name = $f; |
|
| 108 | - } |
|
| 109 | - if (!$tmp_name) { |
|
| 110 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 111 | - |
|
| 112 | - return 'source inconnue'; |
|
| 113 | - } |
|
| 114 | - $source = [ |
|
| 115 | - 'tmp_name' => $tmp_name, |
|
| 116 | - 'name' => basename($tmp_name), |
|
| 117 | - ]; |
|
| 118 | - } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 119 | - return $erreur; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // supprimer le logo éventuel existant |
|
| 123 | - // TODO : si un logo existe, le modifier plutot que supprimer + reinserer |
|
| 124 | - // (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 125 | - // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 126 | - // @see medias_upgrade_logo_objet() |
|
| 127 | - if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 128 | - logo_supprimer($objet, $id_objet, $etat); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - include_spip('inc/autoriser'); |
|
| 133 | - $source['mode'] = $mode_document; |
|
| 134 | - $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 135 | - autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 136 | - $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 137 | - autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 138 | - |
|
| 139 | - $id_document = reset($ajoutes); |
|
| 140 | - |
|
| 141 | - if (!is_numeric($id_document)) { |
|
| 142 | - $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 143 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 144 | - return $erreur; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ''; // tout est bon, pas d'erreur |
|
| 78 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 79 | + $objet = objet_type($objet); |
|
| 80 | + $primary = id_table_objet($objet); |
|
| 81 | + include_spip('inc/chercher_logo'); |
|
| 82 | + |
|
| 83 | + $mode = preg_replace(',\W,', '', $etat); |
|
| 84 | + if (!$mode) { |
|
| 85 | + spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 86 | + |
|
| 87 | + return 'etat invalide'; |
|
| 88 | + } |
|
| 89 | + // chercher dans la base |
|
| 90 | + $mode_document = 'logo' . $mode; |
|
| 91 | + |
|
| 92 | + include_spip('inc/documents'); |
|
| 93 | + $erreur = ''; |
|
| 94 | + |
|
| 95 | + if (!$source) { |
|
| 96 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 97 | + |
|
| 98 | + return 'source inconnue'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // fichier dans upload/ |
|
| 102 | + if (is_string($source)) { |
|
| 103 | + $tmp_name = false; |
|
| 104 | + if (file_exists($source)) { |
|
| 105 | + $tmp_name = $source; |
|
| 106 | + } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 107 | + $tmp_name = $f; |
|
| 108 | + } |
|
| 109 | + if (!$tmp_name) { |
|
| 110 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 111 | + |
|
| 112 | + return 'source inconnue'; |
|
| 113 | + } |
|
| 114 | + $source = [ |
|
| 115 | + 'tmp_name' => $tmp_name, |
|
| 116 | + 'name' => basename($tmp_name), |
|
| 117 | + ]; |
|
| 118 | + } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 119 | + return $erreur; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // supprimer le logo éventuel existant |
|
| 123 | + // TODO : si un logo existe, le modifier plutot que supprimer + reinserer |
|
| 124 | + // (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 125 | + // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 126 | + // @see medias_upgrade_logo_objet() |
|
| 127 | + if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 128 | + logo_supprimer($objet, $id_objet, $etat); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + include_spip('inc/autoriser'); |
|
| 133 | + $source['mode'] = $mode_document; |
|
| 134 | + $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 135 | + autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 136 | + $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 137 | + autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 138 | + |
|
| 139 | + $id_document = reset($ajoutes); |
|
| 140 | + |
|
| 141 | + if (!is_numeric($id_document)) { |
|
| 142 | + $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 143 | + spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 144 | + return $erreur; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ''; // tout est bon, pas d'erreur |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -164,126 +164,126 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | function logo_migrer_en_base($objet, $time_limit) { |
| 166 | 166 | |
| 167 | - $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 168 | - $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 169 | - $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 170 | - if (isset($GLOBALS['formats_logos'])) { |
|
| 171 | - $formats_logos = $GLOBALS['formats_logos']; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 176 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 177 | - include_spip('inc/chercher_logo'); |
|
| 178 | - $_id_objet = id_table_objet($objet); |
|
| 179 | - $table = table_objet_sql($objet); |
|
| 180 | - $type = type_du_logo($_id_objet); |
|
| 181 | - $desc = $trouver_table($table); |
|
| 182 | - |
|
| 183 | - // on desactive les revisions |
|
| 184 | - $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 185 | - unset($GLOBALS['meta']['objets_versions']); |
|
| 186 | - // et le signalement des editions |
|
| 187 | - $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 188 | - $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 189 | - |
|
| 190 | - foreach (['on', 'off'] as $mode) { |
|
| 191 | - $nom_base = $type . $mode; |
|
| 192 | - $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 193 | - |
|
| 194 | - $files = glob($dir . $nom_base . '*'); |
|
| 195 | - // est-ce que c'est une nouvelle tentative de migration ? |
|
| 196 | - // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 197 | - if (!(is_countable($files) ? count($files) : 0)) { |
|
| 198 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 199 | - if (is_countable($files) ? count($files) : 0) { |
|
| 200 | - // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 201 | - $filescheck = []; |
|
| 202 | - foreach ($files as $file) { |
|
| 203 | - $short = basename(dirname((string) $file)) . DIRECTORY_SEPARATOR . basename((string) $file); |
|
| 204 | - $filescheck[$short] = $file; |
|
| 205 | - } |
|
| 206 | - // trouver ceux deja migres |
|
| 207 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 208 | - if (is_countable($deja) ? count($deja) : 0) { |
|
| 209 | - $deja = array_column($deja, 'fichier'); |
|
| 210 | - $restant = array_diff(array_keys($filescheck), $deja); |
|
| 211 | - $files = []; |
|
| 212 | - if ($restant !== []) { |
|
| 213 | - foreach ($restant as $r) { |
|
| 214 | - $files[] = $filescheck[$r]; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - // et si il en reste on peut y aller... |
|
| 219 | - // mais il faut modifier $dir qui sert de base dans la suite |
|
| 220 | - if (is_countable($files) ? count($files) : 0) { |
|
| 221 | - $dir = $dir_logos; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $count = (is_countable($files) ? count($files) : 0); |
|
| 227 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 228 | - |
|
| 229 | - $deja = []; |
|
| 230 | - foreach ($files as $file) { |
|
| 231 | - $logo = substr((string) $file, strlen($dir . $nom_base)); |
|
| 232 | - $logo = explode('.', $logo); |
|
| 233 | - if ( |
|
| 234 | - is_numeric($logo[0]) |
|
| 235 | - && (($id_objet = (int) $logo[0]) || in_array($objet, ['site', 'rubrique'])) |
|
| 236 | - && !isset($deja[$id_objet]) |
|
| 237 | - ) { |
|
| 238 | - $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 239 | - // if no logo in base |
|
| 240 | - if (!$logo || (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 241 | - foreach ($formats_logos as $format) { |
|
| 242 | - if (@file_exists($d = ($dir . ($nom = $nom_base . (int) $id_objet . '.' . $format)))) { |
|
| 243 | - if (isset($desc['field']['date_modif'])) { |
|
| 244 | - $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 245 | - } else { |
|
| 246 | - $date_modif = null; |
|
| 247 | - } |
|
| 248 | - // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 249 | - @chmod($d, _SPIP_CHMOD & 0666); |
|
| 250 | - // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 251 | - @rename($d, $dir_logos . $nom); |
|
| 252 | - // et on le declare comme nouveau logo |
|
| 253 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 254 | - if ($date_modif) { |
|
| 255 | - sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 256 | - } |
|
| 257 | - break; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $deja[$id_objet] = true; |
|
| 262 | - } |
|
| 263 | - // si le fichier est encore la on le move : rien a faire ici |
|
| 264 | - // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 265 | - if ($dir !== $dir_logos && file_exists($file)) { |
|
| 266 | - @rename($file, $dir_logos_erreurs . basename((string) $file)); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $count--; |
|
| 270 | - if ($count % 250 === 0) { |
|
| 271 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - if ($time_limit && time() > $time_limit) { |
|
| 275 | - effacer_meta('drapeau_edition'); |
|
| 276 | - return; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if ($liste_objets_versionnes) { |
|
| 282 | - $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 283 | - } |
|
| 284 | - $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 285 | - |
|
| 286 | - effacer_meta('drapeau_edition'); |
|
| 167 | + $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 168 | + $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 169 | + $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 170 | + if (isset($GLOBALS['formats_logos'])) { |
|
| 171 | + $formats_logos = $GLOBALS['formats_logos']; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 176 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 177 | + include_spip('inc/chercher_logo'); |
|
| 178 | + $_id_objet = id_table_objet($objet); |
|
| 179 | + $table = table_objet_sql($objet); |
|
| 180 | + $type = type_du_logo($_id_objet); |
|
| 181 | + $desc = $trouver_table($table); |
|
| 182 | + |
|
| 183 | + // on desactive les revisions |
|
| 184 | + $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 185 | + unset($GLOBALS['meta']['objets_versions']); |
|
| 186 | + // et le signalement des editions |
|
| 187 | + $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 188 | + $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 189 | + |
|
| 190 | + foreach (['on', 'off'] as $mode) { |
|
| 191 | + $nom_base = $type . $mode; |
|
| 192 | + $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 193 | + |
|
| 194 | + $files = glob($dir . $nom_base . '*'); |
|
| 195 | + // est-ce que c'est une nouvelle tentative de migration ? |
|
| 196 | + // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 197 | + if (!(is_countable($files) ? count($files) : 0)) { |
|
| 198 | + $files = glob($dir_logos . $nom_base . '*'); |
|
| 199 | + if (is_countable($files) ? count($files) : 0) { |
|
| 200 | + // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 201 | + $filescheck = []; |
|
| 202 | + foreach ($files as $file) { |
|
| 203 | + $short = basename(dirname((string) $file)) . DIRECTORY_SEPARATOR . basename((string) $file); |
|
| 204 | + $filescheck[$short] = $file; |
|
| 205 | + } |
|
| 206 | + // trouver ceux deja migres |
|
| 207 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 208 | + if (is_countable($deja) ? count($deja) : 0) { |
|
| 209 | + $deja = array_column($deja, 'fichier'); |
|
| 210 | + $restant = array_diff(array_keys($filescheck), $deja); |
|
| 211 | + $files = []; |
|
| 212 | + if ($restant !== []) { |
|
| 213 | + foreach ($restant as $r) { |
|
| 214 | + $files[] = $filescheck[$r]; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + // et si il en reste on peut y aller... |
|
| 219 | + // mais il faut modifier $dir qui sert de base dans la suite |
|
| 220 | + if (is_countable($files) ? count($files) : 0) { |
|
| 221 | + $dir = $dir_logos; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $count = (is_countable($files) ? count($files) : 0); |
|
| 227 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 228 | + |
|
| 229 | + $deja = []; |
|
| 230 | + foreach ($files as $file) { |
|
| 231 | + $logo = substr((string) $file, strlen($dir . $nom_base)); |
|
| 232 | + $logo = explode('.', $logo); |
|
| 233 | + if ( |
|
| 234 | + is_numeric($logo[0]) |
|
| 235 | + && (($id_objet = (int) $logo[0]) || in_array($objet, ['site', 'rubrique'])) |
|
| 236 | + && !isset($deja[$id_objet]) |
|
| 237 | + ) { |
|
| 238 | + $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 239 | + // if no logo in base |
|
| 240 | + if (!$logo || (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 241 | + foreach ($formats_logos as $format) { |
|
| 242 | + if (@file_exists($d = ($dir . ($nom = $nom_base . (int) $id_objet . '.' . $format)))) { |
|
| 243 | + if (isset($desc['field']['date_modif'])) { |
|
| 244 | + $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 245 | + } else { |
|
| 246 | + $date_modif = null; |
|
| 247 | + } |
|
| 248 | + // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 249 | + @chmod($d, _SPIP_CHMOD & 0666); |
|
| 250 | + // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 251 | + @rename($d, $dir_logos . $nom); |
|
| 252 | + // et on le declare comme nouveau logo |
|
| 253 | + logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 254 | + if ($date_modif) { |
|
| 255 | + sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 256 | + } |
|
| 257 | + break; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $deja[$id_objet] = true; |
|
| 262 | + } |
|
| 263 | + // si le fichier est encore la on le move : rien a faire ici |
|
| 264 | + // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 265 | + if ($dir !== $dir_logos && file_exists($file)) { |
|
| 266 | + @rename($file, $dir_logos_erreurs . basename((string) $file)); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $count--; |
|
| 270 | + if ($count % 250 === 0) { |
|
| 271 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + if ($time_limit && time() > $time_limit) { |
|
| 275 | + effacer_meta('drapeau_edition'); |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if ($liste_objets_versionnes) { |
|
| 282 | + $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 283 | + } |
|
| 284 | + $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 285 | + |
|
| 286 | + effacer_meta('drapeau_edition'); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | * @deprecated 4.0 MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base |
| 305 | 305 | **/ |
| 306 | 306 | function type_du_logo($_id_objet) { |
| 307 | - $legacy_tables_logos = [ |
|
| 308 | - 'id_article' => 'art', |
|
| 309 | - 'id_auteur' => 'aut', |
|
| 310 | - 'id_rubrique' => 'rub', |
|
| 311 | - 'id_groupe' => 'groupe', |
|
| 312 | - ]; |
|
| 313 | - return $legacy_tables_logos[$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 307 | + $legacy_tables_logos = [ |
|
| 308 | + 'id_article' => 'art', |
|
| 309 | + 'id_auteur' => 'aut', |
|
| 310 | + 'id_rubrique' => 'rub', |
|
| 311 | + 'id_groupe' => 'groupe', |
|
| 312 | + ]; |
|
| 313 | + return $legacy_tables_logos[$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 314 | 314 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\SQL |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 21 | 21 | |
@@ -41,125 +41,125 @@ discard block |
||
| 41 | 41 | **/ |
| 42 | 42 | function spip_connect($serveur = '', $version = '') { |
| 43 | 43 | |
| 44 | - $serveur = is_string($serveur) ? strtolower($serveur) : ''; |
|
| 45 | - $index = $serveur ?: 0; |
|
| 46 | - if (!$version) { |
|
| 47 | - $version = $GLOBALS['spip_sql_version']; |
|
| 48 | - } |
|
| 49 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 50 | - return $GLOBALS['connexions'][$index]; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - include_spip('base/abstract_sql'); |
|
| 54 | - $install = (_request('exec') == 'install'); |
|
| 55 | - |
|
| 56 | - // Premiere connexion ? |
|
| 57 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 58 | - $f = ''; |
|
| 59 | - if ($serveur) { |
|
| 60 | - // serveur externe et nom de serveur bien ecrit ? |
|
| 61 | - if ( |
|
| 62 | - defined('_DIR_CONNECT') |
|
| 63 | - && preg_match('/^[\w\.]*$/', $serveur) |
|
| 64 | - ) { |
|
| 65 | - $f = _DIR_CONNECT . $serveur . '.php'; |
|
| 66 | - if (!is_readable($f) && !$install) { |
|
| 67 | - // chercher une declaration de serveur dans le path |
|
| 68 | - // qui peut servir à des plugins à declarer des connexions à une base sqlite |
|
| 69 | - // Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump |
|
| 70 | - $f = find_in_path("$serveur.php", 'connect/'); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } else { |
|
| 74 | - if (defined('_FILE_CONNECT') && _FILE_CONNECT) { |
|
| 75 | - // init du serveur principal |
|
| 76 | - $f = _FILE_CONNECT; |
|
| 77 | - } elseif ($install && defined('_FILE_CONNECT_TMP')) { |
|
| 78 | - // installation en cours |
|
| 79 | - $f = _FILE_CONNECT_TMP; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - unset($GLOBALS['db_ok']); |
|
| 84 | - unset($GLOBALS['spip_connect_version']); |
|
| 85 | - if ($f && is_readable($f)) { |
|
| 86 | - include($f); |
|
| 87 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 88 | - spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - else { |
|
| 92 | - spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS); |
|
| 93 | - } |
|
| 94 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 95 | - // fera mieux la prochaine fois |
|
| 96 | - if ($install) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - // ne plus reessayer si ce n'est pas l'install |
|
| 100 | - return $GLOBALS['connexions'][$index] = false; |
|
| 101 | - } |
|
| 102 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 103 | - } |
|
| 104 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 105 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 106 | - return false; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // la connexion a reussi ou etait deja faite. |
|
| 110 | - // chargement de la version du jeu de fonctions |
|
| 111 | - // si pas dans le fichier par defaut |
|
| 112 | - $type = $GLOBALS['db_ok']['type']; |
|
| 113 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 114 | - if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 115 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 116 | - // ne plus reessayer |
|
| 117 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 118 | - } |
|
| 119 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 120 | - if ($old) { |
|
| 121 | - return $GLOBALS['connexions'][$index]; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 125 | - |
|
| 126 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 127 | - // si l'installation l'a determine. |
|
| 128 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 129 | - // s'ils le connaissent |
|
| 130 | - |
|
| 131 | - if (!$serveur) { |
|
| 132 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 133 | - if (!$charset) { |
|
| 134 | - unset($GLOBALS['connexions'][$index]); |
|
| 135 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 141 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 142 | - } |
|
| 143 | - // spip_meta n'existe pas toujours dans la base |
|
| 144 | - // C'est le cas d'un dump sqlite par exemple |
|
| 145 | - elseif ( |
|
| 146 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 147 | - && sql_showtable('spip_meta', true, $serveur) |
|
| 148 | - && ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 149 | - ) { |
|
| 150 | - $charset = $r; |
|
| 151 | - } else { |
|
| 152 | - $charset = -1; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - if ($charset != -1) { |
|
| 156 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 157 | - if (function_exists($f)) { |
|
| 158 | - $f($charset, $serveur); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $GLOBALS['connexions'][$index]; |
|
| 44 | + $serveur = is_string($serveur) ? strtolower($serveur) : ''; |
|
| 45 | + $index = $serveur ?: 0; |
|
| 46 | + if (!$version) { |
|
| 47 | + $version = $GLOBALS['spip_sql_version']; |
|
| 48 | + } |
|
| 49 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 50 | + return $GLOBALS['connexions'][$index]; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + include_spip('base/abstract_sql'); |
|
| 54 | + $install = (_request('exec') == 'install'); |
|
| 55 | + |
|
| 56 | + // Premiere connexion ? |
|
| 57 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 58 | + $f = ''; |
|
| 59 | + if ($serveur) { |
|
| 60 | + // serveur externe et nom de serveur bien ecrit ? |
|
| 61 | + if ( |
|
| 62 | + defined('_DIR_CONNECT') |
|
| 63 | + && preg_match('/^[\w\.]*$/', $serveur) |
|
| 64 | + ) { |
|
| 65 | + $f = _DIR_CONNECT . $serveur . '.php'; |
|
| 66 | + if (!is_readable($f) && !$install) { |
|
| 67 | + // chercher une declaration de serveur dans le path |
|
| 68 | + // qui peut servir à des plugins à declarer des connexions à une base sqlite |
|
| 69 | + // Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump |
|
| 70 | + $f = find_in_path("$serveur.php", 'connect/'); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } else { |
|
| 74 | + if (defined('_FILE_CONNECT') && _FILE_CONNECT) { |
|
| 75 | + // init du serveur principal |
|
| 76 | + $f = _FILE_CONNECT; |
|
| 77 | + } elseif ($install && defined('_FILE_CONNECT_TMP')) { |
|
| 78 | + // installation en cours |
|
| 79 | + $f = _FILE_CONNECT_TMP; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + unset($GLOBALS['db_ok']); |
|
| 84 | + unset($GLOBALS['spip_connect_version']); |
|
| 85 | + if ($f && is_readable($f)) { |
|
| 86 | + include($f); |
|
| 87 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 88 | + spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + else { |
|
| 92 | + spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS); |
|
| 93 | + } |
|
| 94 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 95 | + // fera mieux la prochaine fois |
|
| 96 | + if ($install) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + // ne plus reessayer si ce n'est pas l'install |
|
| 100 | + return $GLOBALS['connexions'][$index] = false; |
|
| 101 | + } |
|
| 102 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 103 | + } |
|
| 104 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 105 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // la connexion a reussi ou etait deja faite. |
|
| 110 | + // chargement de la version du jeu de fonctions |
|
| 111 | + // si pas dans le fichier par defaut |
|
| 112 | + $type = $GLOBALS['db_ok']['type']; |
|
| 113 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 114 | + if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 115 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 116 | + // ne plus reessayer |
|
| 117 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 118 | + } |
|
| 119 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 120 | + if ($old) { |
|
| 121 | + return $GLOBALS['connexions'][$index]; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 125 | + |
|
| 126 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 127 | + // si l'installation l'a determine. |
|
| 128 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 129 | + // s'ils le connaissent |
|
| 130 | + |
|
| 131 | + if (!$serveur) { |
|
| 132 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 133 | + if (!$charset) { |
|
| 134 | + unset($GLOBALS['connexions'][$index]); |
|
| 135 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 141 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 142 | + } |
|
| 143 | + // spip_meta n'existe pas toujours dans la base |
|
| 144 | + // C'est le cas d'un dump sqlite par exemple |
|
| 145 | + elseif ( |
|
| 146 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 147 | + && sql_showtable('spip_meta', true, $serveur) |
|
| 148 | + && ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 149 | + ) { |
|
| 150 | + $charset = $r; |
|
| 151 | + } else { |
|
| 152 | + $charset = -1; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + if ($charset != -1) { |
|
| 156 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 157 | + if (function_exists($f)) { |
|
| 158 | + $f($charset, $serveur); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $GLOBALS['connexions'][$index]; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 169 | 169 | **/ |
| 170 | 170 | function spip_sql_erreur($serveur = '') { |
| 171 | - $connexion = spip_connect($serveur); |
|
| 172 | - $e = sql_errno($serveur); |
|
| 173 | - $t = ($connexion['type'] ?? 'sql'); |
|
| 174 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']); |
|
| 175 | - $f = $t . $serveur; |
|
| 176 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | + $connexion = spip_connect($serveur); |
|
| 172 | + $e = sql_errno($serveur); |
|
| 173 | + $t = ($connexion['type'] ?? 'sql'); |
|
| 174 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']); |
|
| 175 | + $f = $t . $serveur; |
|
| 176 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -195,23 +195,23 @@ discard block |
||
| 195 | 195 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 196 | 196 | **/ |
| 197 | 197 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 198 | - $desc = spip_connect($serveur, $version); |
|
| 199 | - if ( |
|
| 200 | - $desc |
|
| 201 | - && ($f = ($desc[$version][$ins] ?? '')) |
|
| 202 | - && function_exists($f) |
|
| 203 | - ) { |
|
| 204 | - return $f; |
|
| 205 | - } |
|
| 206 | - if ($continue) { |
|
| 207 | - return $desc; |
|
| 208 | - } |
|
| 209 | - if ($ins) { |
|
| 210 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 211 | - } |
|
| 212 | - include_spip('inc/minipres'); |
|
| 213 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 214 | - exit; |
|
| 198 | + $desc = spip_connect($serveur, $version); |
|
| 199 | + if ( |
|
| 200 | + $desc |
|
| 201 | + && ($f = ($desc[$version][$ins] ?? '')) |
|
| 202 | + && function_exists($f) |
|
| 203 | + ) { |
|
| 204 | + return $f; |
|
| 205 | + } |
|
| 206 | + if ($continue) { |
|
| 207 | + return $desc; |
|
| 208 | + } |
|
| 209 | + if ($ins) { |
|
| 210 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 211 | + } |
|
| 212 | + include_spip('inc/minipres'); |
|
| 213 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 214 | + exit; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -237,70 +237,70 @@ discard block |
||
| 237 | 237 | * @return array|null Description de la connexion |
| 238 | 238 | */ |
| 239 | 239 | function spip_connect_db( |
| 240 | - $host, |
|
| 241 | - $port, |
|
| 242 | - $login, |
|
| 243 | - #[\SensitiveParameter] $pass, |
|
| 244 | - $db = '', |
|
| 245 | - $type = 'mysql', |
|
| 246 | - $prefixe = '', |
|
| 247 | - $auth = '', |
|
| 248 | - $charset = '' |
|
| 240 | + $host, |
|
| 241 | + $port, |
|
| 242 | + $login, |
|
| 243 | + #[\SensitiveParameter] $pass, |
|
| 244 | + $db = '', |
|
| 245 | + $type = 'mysql', |
|
| 246 | + $prefixe = '', |
|
| 247 | + $auth = '', |
|
| 248 | + $charset = '' |
|
| 249 | 249 | ) { |
| 250 | - // temps avant nouvelle tentative de connexion |
|
| 251 | - // suite a une connection echouee |
|
| 252 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 253 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $f = ''; |
|
| 257 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 258 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 259 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 260 | - // car c'est un test de connexion |
|
| 261 | - if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') { |
|
| 262 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 263 | - } elseif ($db == '@test@') { |
|
| 264 | - $db = ''; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if ( |
|
| 268 | - $f |
|
| 269 | - && @file_exists($f) |
|
| 270 | - && (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 271 | - ) { |
|
| 272 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 273 | - |
|
| 274 | - return null; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - if (!$prefixe) { |
|
| 278 | - $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 279 | - } |
|
| 280 | - $h = charger_fonction($type, 'req', true); |
|
| 281 | - if (!$h) { |
|
| 282 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 283 | - |
|
| 284 | - return null; |
|
| 285 | - } |
|
| 286 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 287 | - if (!is_array($auth)) { |
|
| 288 | - // compatibilite version 0.7 initiale |
|
| 289 | - $g['ldap'] = $auth; |
|
| 290 | - $auth = ['ldap' => $auth]; |
|
| 291 | - } |
|
| 292 | - $g['authentification'] = $auth; |
|
| 293 | - $g['type'] = $type; |
|
| 294 | - $g['charset'] = $charset; |
|
| 295 | - |
|
| 296 | - return $GLOBALS['db_ok'] = $g; |
|
| 297 | - } |
|
| 298 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 299 | - if ($f) { |
|
| 300 | - @touch($f); |
|
| 301 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 302 | - } |
|
| 303 | - return null; |
|
| 250 | + // temps avant nouvelle tentative de connexion |
|
| 251 | + // suite a une connection echouee |
|
| 252 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 253 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $f = ''; |
|
| 257 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 258 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 259 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 260 | + // car c'est un test de connexion |
|
| 261 | + if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') { |
|
| 262 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 263 | + } elseif ($db == '@test@') { |
|
| 264 | + $db = ''; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if ( |
|
| 268 | + $f |
|
| 269 | + && @file_exists($f) |
|
| 270 | + && (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 271 | + ) { |
|
| 272 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 273 | + |
|
| 274 | + return null; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + if (!$prefixe) { |
|
| 278 | + $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 279 | + } |
|
| 280 | + $h = charger_fonction($type, 'req', true); |
|
| 281 | + if (!$h) { |
|
| 282 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 283 | + |
|
| 284 | + return null; |
|
| 285 | + } |
|
| 286 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 287 | + if (!is_array($auth)) { |
|
| 288 | + // compatibilite version 0.7 initiale |
|
| 289 | + $g['ldap'] = $auth; |
|
| 290 | + $auth = ['ldap' => $auth]; |
|
| 291 | + } |
|
| 292 | + $g['authentification'] = $auth; |
|
| 293 | + $g['type'] = $type; |
|
| 294 | + $g['charset'] = $charset; |
|
| 295 | + |
|
| 296 | + return $GLOBALS['db_ok'] = $g; |
|
| 297 | + } |
|
| 298 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 299 | + if ($f) { |
|
| 300 | + @touch($f); |
|
| 301 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 302 | + } |
|
| 303 | + return null; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
@@ -332,32 +332,32 @@ discard block |
||
| 332 | 332 | * - nom du charset sinon |
| 333 | 333 | **/ |
| 334 | 334 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 335 | - if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) { |
|
| 336 | - include_spip('inc/headers'); |
|
| 337 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if (!($f = $connexion['select'])) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - // si le charset est fourni, l'utiliser |
|
| 344 | - if ($charset_sql_connexion) { |
|
| 345 | - return $charset_sql_connexion; |
|
| 346 | - } |
|
| 347 | - // sinon on regarde la table spip_meta |
|
| 348 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 349 | - if ( |
|
| 350 | - !($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")) |
|
| 351 | - || is_string($r) |
|
| 352 | - ) { |
|
| 353 | - return false; |
|
| 354 | - } |
|
| 355 | - if (!($f = $connexion['fetch'])) { |
|
| 356 | - return false; |
|
| 357 | - } |
|
| 358 | - $r = $f($r); |
|
| 359 | - |
|
| 360 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 335 | + if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) { |
|
| 336 | + include_spip('inc/headers'); |
|
| 337 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if (!($f = $connexion['select'])) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + // si le charset est fourni, l'utiliser |
|
| 344 | + if ($charset_sql_connexion) { |
|
| 345 | + return $charset_sql_connexion; |
|
| 346 | + } |
|
| 347 | + // sinon on regarde la table spip_meta |
|
| 348 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 349 | + if ( |
|
| 350 | + !($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")) |
|
| 351 | + || is_string($r) |
|
| 352 | + ) { |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 355 | + if (!($f = $connexion['fetch'])) { |
|
| 356 | + return false; |
|
| 357 | + } |
|
| 358 | + $r = $f($r); |
|
| 359 | + |
|
| 360 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -373,16 +373,16 @@ discard block |
||
| 373 | 373 | * @return string Valeur échappée. |
| 374 | 374 | **/ |
| 375 | 375 | function _q($a): string { |
| 376 | - if (is_numeric($a)) { |
|
| 377 | - return (string) $a; |
|
| 378 | - } elseif (is_array($a)) { |
|
| 379 | - return implode(',', array_map('_q', $a)); |
|
| 380 | - } elseif (is_scalar($a)) { |
|
| 381 | - return ("'" . addslashes($a) . "'"); |
|
| 382 | - } elseif ($a === null) { |
|
| 383 | - return "''"; |
|
| 384 | - } |
|
| 385 | - throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 376 | + if (is_numeric($a)) { |
|
| 377 | + return (string) $a; |
|
| 378 | + } elseif (is_array($a)) { |
|
| 379 | + return implode(',', array_map('_q', $a)); |
|
| 380 | + } elseif (is_scalar($a)) { |
|
| 381 | + return ("'" . addslashes($a) . "'"); |
|
| 382 | + } elseif ($a === null) { |
|
| 383 | + return "''"; |
|
| 384 | + } |
|
| 385 | + throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -398,75 +398,75 @@ discard block |
||
| 398 | 398 | * @return array |
| 399 | 399 | */ |
| 400 | 400 | function query_echappe_textes($query, $uniqid = null) { |
| 401 | - static $codeEchappements = null; |
|
| 402 | - if (is_null($codeEchappements) || $uniqid) { |
|
| 403 | - if (is_null($uniqid)) { |
|
| 404 | - $uniqid = uniqid(); |
|
| 405 | - } |
|
| 406 | - $uniqid = substr(md5((string) $uniqid), 0, 4); |
|
| 407 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 408 | - } |
|
| 409 | - if ($query === null) { |
|
| 410 | - return $codeEchappements; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 414 | - // ce n'est pas un cas legitime |
|
| 415 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 416 | - if (str_contains($query, (string) $codeEchappement)) { |
|
| 417 | - return [$query, []]; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 422 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 423 | - $textes = reset($textes); |
|
| 424 | - |
|
| 425 | - $parts = []; |
|
| 426 | - $currentpos = 0; |
|
| 427 | - $k = 0; |
|
| 428 | - while (count($textes)) { |
|
| 429 | - $part = array_shift($textes); |
|
| 430 | - $nextpos = strpos($query_echappees, (string) $part, $currentpos); |
|
| 431 | - // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 432 | - while (count($textes) && str_ends_with((string) $part, "'")) { |
|
| 433 | - $next = reset($textes); |
|
| 434 | - if ( |
|
| 435 | - str_starts_with((string) $next, "'") |
|
| 436 | - && strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 437 | - ) { |
|
| 438 | - $part .= array_shift($textes); |
|
| 439 | - } |
|
| 440 | - else { |
|
| 441 | - break; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - $k++; |
|
| 445 | - $parts[$k] = [ |
|
| 446 | - 'texte' => $part, |
|
| 447 | - 'position' => $nextpos, |
|
| 448 | - 'placeholder' => '%' . $k . '$s', |
|
| 449 | - ]; |
|
| 450 | - $currentpos = $nextpos + strlen((string) $part); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // et on replace les parts une par une en commencant par la fin |
|
| 454 | - while ($k > 0) { |
|
| 455 | - $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte'])); |
|
| 456 | - $k--; |
|
| 457 | - } |
|
| 458 | - $textes = array_column($parts, 'texte'); |
|
| 459 | - } else { |
|
| 460 | - $textes = []; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 464 | - // dans le doute on ne touche a rien |
|
| 465 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 466 | - return [$query, []]; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return [$query_echappees, $textes]; |
|
| 401 | + static $codeEchappements = null; |
|
| 402 | + if (is_null($codeEchappements) || $uniqid) { |
|
| 403 | + if (is_null($uniqid)) { |
|
| 404 | + $uniqid = uniqid(); |
|
| 405 | + } |
|
| 406 | + $uniqid = substr(md5((string) $uniqid), 0, 4); |
|
| 407 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 408 | + } |
|
| 409 | + if ($query === null) { |
|
| 410 | + return $codeEchappements; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 414 | + // ce n'est pas un cas legitime |
|
| 415 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 416 | + if (str_contains($query, (string) $codeEchappement)) { |
|
| 417 | + return [$query, []]; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 422 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 423 | + $textes = reset($textes); |
|
| 424 | + |
|
| 425 | + $parts = []; |
|
| 426 | + $currentpos = 0; |
|
| 427 | + $k = 0; |
|
| 428 | + while (count($textes)) { |
|
| 429 | + $part = array_shift($textes); |
|
| 430 | + $nextpos = strpos($query_echappees, (string) $part, $currentpos); |
|
| 431 | + // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 432 | + while (count($textes) && str_ends_with((string) $part, "'")) { |
|
| 433 | + $next = reset($textes); |
|
| 434 | + if ( |
|
| 435 | + str_starts_with((string) $next, "'") |
|
| 436 | + && strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 437 | + ) { |
|
| 438 | + $part .= array_shift($textes); |
|
| 439 | + } |
|
| 440 | + else { |
|
| 441 | + break; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + $k++; |
|
| 445 | + $parts[$k] = [ |
|
| 446 | + 'texte' => $part, |
|
| 447 | + 'position' => $nextpos, |
|
| 448 | + 'placeholder' => '%' . $k . '$s', |
|
| 449 | + ]; |
|
| 450 | + $currentpos = $nextpos + strlen((string) $part); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // et on replace les parts une par une en commencant par la fin |
|
| 454 | + while ($k > 0) { |
|
| 455 | + $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte'])); |
|
| 456 | + $k--; |
|
| 457 | + } |
|
| 458 | + $textes = array_column($parts, 'texte'); |
|
| 459 | + } else { |
|
| 460 | + $textes = []; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 464 | + // dans le doute on ne touche a rien |
|
| 465 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 466 | + return [$query, []]; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return [$query_echappees, $textes]; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,14 +480,14 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function query_reinjecte_textes($query, $textes) { |
| 483 | - // recuperer les codes echappements |
|
| 484 | - $codeEchappements = query_echappe_textes(null); |
|
| 483 | + // recuperer les codes echappements |
|
| 484 | + $codeEchappements = query_echappe_textes(null); |
|
| 485 | 485 | |
| 486 | - if (!empty($textes)) { |
|
| 487 | - $query = sprintf($query, ...$textes); |
|
| 488 | - } |
|
| 486 | + if (!empty($textes)) { |
|
| 487 | + $query = sprintf($query, ...$textes); |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 490 | + return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | **/ |
| 507 | 507 | function spip_query($query, $serveur = '') { |
| 508 | 508 | |
| 509 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 509 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 510 | 510 | |
| 511 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 511 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 512 | 512 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | use Spip\Chiffrer\SpipCles; |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -33,167 +33,167 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function auth_spip_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 35 | 35 | |
| 36 | - $methode = null; |
|
| 37 | - // retrouver le login |
|
| 38 | - $login = auth_spip_retrouver_login($login); |
|
| 39 | - // login inconnu, n'allons pas plus loin |
|
| 40 | - if (!$login) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $md5pass = ''; |
|
| 45 | - $shapass = $shanext = ''; |
|
| 46 | - $auteur_peut_sauver_cles = false; |
|
| 47 | - |
|
| 48 | - if ($pass) { |
|
| 49 | - $row = sql_fetsel( |
|
| 50 | - '*', |
|
| 51 | - 'spip_auteurs', |
|
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - '', |
|
| 57 | - $serveur |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - // lever un flag si cet auteur peut sauver les cles |
|
| 61 | - if ($row['statut'] === '0minirezo' && $row['webmestre'] === 'oui' && isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass || !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $cles = SpipCles::instance(); |
|
| 72 | - $secret = $cles->getSecretAuth(); |
|
| 73 | - |
|
| 74 | - $hash = null; |
|
| 75 | - switch (strlen((string) $row['pass'])) { |
|
| 76 | - // legacy = md5 ou sha256 |
|
| 77 | - case 32: |
|
| 78 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | - $methode = 'md5'; |
|
| 81 | - case 64: |
|
| 82 | - if (empty($hash)) { |
|
| 83 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | - $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 85 | - $methode = 'sha256'; |
|
| 86 | - } |
|
| 87 | - if ($row['pass'] === $hash) { |
|
| 88 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 89 | - // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | - if (!empty($row['backup_cles'])) { |
|
| 91 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | - |
|
| 98 | - case 60: |
|
| 99 | - case 98: |
|
| 100 | - default: |
|
| 101 | - // doit-on restaurer un backup des cles ? |
|
| 102 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | - if ( |
|
| 104 | - !$secret |
|
| 105 | - && $auteur_peut_sauver_cles |
|
| 106 | - && !empty($row['backup_cles']) |
|
| 107 | - ) { |
|
| 108 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 110 | - if ($cles->save()) { |
|
| 111 | - $secret = $cles->getSecretAuth(); |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 115 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - else { |
|
| 120 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 121 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | - unset($row); |
|
| 127 | - } |
|
| 128 | - else { |
|
| 129 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | - if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 139 | - $secret = $cles->getSecretAuth(); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // login/mot de passe incorrect |
|
| 143 | - if (empty($row)) { |
|
| 144 | - return []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // fait tourner le codage du pass dans la base |
|
| 148 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 149 | - if (!$phpauth && $secret) { |
|
| 150 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 151 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 152 | - if ($pass_hash_next) { |
|
| 153 | - $set = [ |
|
| 154 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 155 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 156 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 157 | - ]; |
|
| 158 | - |
|
| 159 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 160 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 161 | - $htpass = generer_htpass($pass); |
|
| 162 | - if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 163 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 167 | - if ($auteur_peut_sauver_cles) { |
|
| 168 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - @sql_update( |
|
| 172 | - 'spip_auteurs', |
|
| 173 | - $set, |
|
| 174 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 175 | - $row['pass'], |
|
| 176 | - $serveur, |
|
| 177 | - 'text' |
|
| 178 | - ), |
|
| 179 | - [], |
|
| 180 | - $serveur |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 184 | - if (isset($set['htpass'])) { |
|
| 185 | - ecrire_acces(); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // En profiter pour verifier la securite de tmp/ |
|
| 190 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 191 | - if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $row; |
|
| 36 | + $methode = null; |
|
| 37 | + // retrouver le login |
|
| 38 | + $login = auth_spip_retrouver_login($login); |
|
| 39 | + // login inconnu, n'allons pas plus loin |
|
| 40 | + if (!$login) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $md5pass = ''; |
|
| 45 | + $shapass = $shanext = ''; |
|
| 46 | + $auteur_peut_sauver_cles = false; |
|
| 47 | + |
|
| 48 | + if ($pass) { |
|
| 49 | + $row = sql_fetsel( |
|
| 50 | + '*', |
|
| 51 | + 'spip_auteurs', |
|
| 52 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + '', |
|
| 57 | + $serveur |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + // lever un flag si cet auteur peut sauver les cles |
|
| 61 | + if ($row['statut'] === '0minirezo' && $row['webmestre'] === 'oui' && isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass || !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $cles = SpipCles::instance(); |
|
| 72 | + $secret = $cles->getSecretAuth(); |
|
| 73 | + |
|
| 74 | + $hash = null; |
|
| 75 | + switch (strlen((string) $row['pass'])) { |
|
| 76 | + // legacy = md5 ou sha256 |
|
| 77 | + case 32: |
|
| 78 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | + $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $methode = 'md5'; |
|
| 81 | + case 64: |
|
| 82 | + if (empty($hash)) { |
|
| 83 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | + $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 85 | + $methode = 'sha256'; |
|
| 86 | + } |
|
| 87 | + if ($row['pass'] === $hash) { |
|
| 88 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 89 | + // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 90 | + if (!empty($row['backup_cles'])) { |
|
| 91 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 97 | + |
|
| 98 | + case 60: |
|
| 99 | + case 98: |
|
| 100 | + default: |
|
| 101 | + // doit-on restaurer un backup des cles ? |
|
| 102 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 103 | + if ( |
|
| 104 | + !$secret |
|
| 105 | + && $auteur_peut_sauver_cles |
|
| 106 | + && !empty($row['backup_cles']) |
|
| 107 | + ) { |
|
| 108 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 109 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 110 | + if ($cles->save()) { |
|
| 111 | + $secret = $cles->getSecretAuth(); |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 115 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 116 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + else { |
|
| 120 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 121 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (!$secret || !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 126 | + unset($row); |
|
| 127 | + } |
|
| 128 | + else { |
|
| 129 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 135 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 136 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 137 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 138 | + if (!$secret && $auteur_peut_sauver_cles && auth_spip_initialiser_secret()) { |
|
| 139 | + $secret = $cles->getSecretAuth(); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // login/mot de passe incorrect |
|
| 143 | + if (empty($row)) { |
|
| 144 | + return []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // fait tourner le codage du pass dans la base |
|
| 148 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 149 | + if (!$phpauth && $secret) { |
|
| 150 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 151 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 152 | + if ($pass_hash_next) { |
|
| 153 | + $set = [ |
|
| 154 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 155 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 156 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 157 | + ]; |
|
| 158 | + |
|
| 159 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 160 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 161 | + $htpass = generer_htpass($pass); |
|
| 162 | + if (strlen((string) $htpass) !== strlen((string) $row['htpass'])) { |
|
| 163 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 167 | + if ($auteur_peut_sauver_cles) { |
|
| 168 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + @sql_update( |
|
| 172 | + 'spip_auteurs', |
|
| 173 | + $set, |
|
| 174 | + 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 175 | + $row['pass'], |
|
| 176 | + $serveur, |
|
| 177 | + 'text' |
|
| 178 | + ), |
|
| 179 | + [], |
|
| 180 | + $serveur |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 184 | + if (isset($set['htpass'])) { |
|
| 185 | + ecrire_acces(); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // En profiter pour verifier la securite de tmp/ |
|
| 190 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 191 | + if (!verifier_htaccess(_DIR_TMP) && defined('_ECRIRE_INSTALL')) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $row; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -208,36 +208,36 @@ discard block |
||
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | 210 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 211 | - $cles = SpipCles::instance(); |
|
| 212 | - $secret = $cles->getSecretAuth(); |
|
| 213 | - |
|
| 214 | - // on ne fait rien si on a un secret dispo |
|
| 215 | - if ($secret) { |
|
| 216 | - return false; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 220 | - if ($force) { |
|
| 221 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 222 | - $secret = $cles->getSecretAuth(true); |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 227 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 228 | - if ($has_backup === []) { |
|
| 229 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 230 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 231 | - return true; |
|
| 232 | - } |
|
| 233 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 234 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 235 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 236 | - } |
|
| 237 | - else { |
|
| 238 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 239 | - } |
|
| 240 | - return false; |
|
| 211 | + $cles = SpipCles::instance(); |
|
| 212 | + $secret = $cles->getSecretAuth(); |
|
| 213 | + |
|
| 214 | + // on ne fait rien si on a un secret dispo |
|
| 215 | + if ($secret) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 220 | + if ($force) { |
|
| 221 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 222 | + $secret = $cles->getSecretAuth(true); |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 227 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 228 | + if ($has_backup === []) { |
|
| 229 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 230 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 231 | + return true; |
|
| 232 | + } |
|
| 233 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 234 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 235 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 236 | + } |
|
| 237 | + else { |
|
| 238 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 239 | + } |
|
| 240 | + return false; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -247,19 +247,19 @@ discard block |
||
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | function auth_spip_formulaire_login($flux) { |
| 250 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 251 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 252 | - $flux['data'] .= |
|
| 253 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 254 | - . "$js\n" |
|
| 255 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 257 | - . "'informe_auteur_en_cours':false," |
|
| 258 | - . "'attente_informe':0};" |
|
| 259 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 260 | - . '/*]]>*/</script>'; |
|
| 261 | - |
|
| 262 | - return $flux; |
|
| 250 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 251 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 252 | + $flux['data'] .= |
|
| 253 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 254 | + . "$js\n" |
|
| 255 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 257 | + . "'informe_auteur_en_cours':false," |
|
| 258 | + . "'attente_informe':0};" |
|
| 259 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 260 | + . '/*]]>*/</script>'; |
|
| 261 | + |
|
| 262 | + return $flux; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | * toujours true pour un auteur cree dans SPIP |
| 272 | 272 | */ |
| 273 | 273 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 274 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 275 | - return !strlen($serveur); |
|
| 274 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 275 | + return !strlen($serveur); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -286,25 +286,25 @@ discard block |
||
| 286 | 286 | * message d'erreur si login non valide, chaine vide sinon |
| 287 | 287 | */ |
| 288 | 288 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 289 | - // login et mot de passe |
|
| 290 | - if (strlen($new_login)) { |
|
| 291 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 292 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 293 | - } else { |
|
| 294 | - $n = sql_countsel( |
|
| 295 | - 'spip_auteurs', |
|
| 296 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 297 | - '', |
|
| 298 | - '', |
|
| 299 | - $serveur |
|
| 300 | - ); |
|
| 301 | - if ($n) { |
|
| 302 | - return _T('info_login_existant'); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return ''; |
|
| 289 | + // login et mot de passe |
|
| 290 | + if (strlen($new_login)) { |
|
| 291 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 292 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 293 | + } else { |
|
| 294 | + $n = sql_countsel( |
|
| 295 | + 'spip_auteurs', |
|
| 296 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 297 | + '', |
|
| 298 | + '', |
|
| 299 | + $serveur |
|
| 300 | + ); |
|
| 301 | + if ($n) { |
|
| 302 | + return _T('info_login_existant'); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return ''; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -316,41 +316,41 @@ discard block |
||
| 316 | 316 | * @return bool |
| 317 | 317 | */ |
| 318 | 318 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 319 | - if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - if ( |
|
| 323 | - !($id_auteur = (int) $id_auteur) |
|
| 324 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | - ) { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - if ($new_login == $auteur['login']) { |
|
| 329 | - return true; |
|
| 330 | - } // on a rien fait mais c'est bon ! |
|
| 331 | - |
|
| 332 | - include_spip('action/editer_auteur'); |
|
| 333 | - |
|
| 334 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 335 | - if (strlen($new_login)) { |
|
| 336 | - $anciens = sql_allfetsel( |
|
| 337 | - 'id_auteur', |
|
| 338 | - 'spip_auteurs', |
|
| 339 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 340 | - '', |
|
| 341 | - '', |
|
| 342 | - '', |
|
| 343 | - '', |
|
| 344 | - $serveur |
|
| 345 | - ); |
|
| 346 | - while ($row = array_pop($anciens)) { |
|
| 347 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 352 | - |
|
| 353 | - return true; |
|
| 319 | + if (is_null($new_login) || auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + if ( |
|
| 323 | + !($id_auteur = (int) $id_auteur) |
|
| 324 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | + ) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if ($new_login == $auteur['login']) { |
|
| 329 | + return true; |
|
| 330 | + } // on a rien fait mais c'est bon ! |
|
| 331 | + |
|
| 332 | + include_spip('action/editer_auteur'); |
|
| 333 | + |
|
| 334 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 335 | + if (strlen($new_login)) { |
|
| 336 | + $anciens = sql_allfetsel( |
|
| 337 | + 'id_auteur', |
|
| 338 | + 'spip_auteurs', |
|
| 339 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 340 | + '', |
|
| 341 | + '', |
|
| 342 | + '', |
|
| 343 | + '', |
|
| 344 | + $serveur |
|
| 345 | + ); |
|
| 346 | + while ($row = array_pop($anciens)) { |
|
| 347 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 352 | + |
|
| 353 | + return true; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -362,44 +362,44 @@ discard block |
||
| 362 | 362 | * @return string |
| 363 | 363 | */ |
| 364 | 364 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 365 | - if (!strlen($login)) { |
|
| 366 | - return null; |
|
| 367 | - } // pas la peine de requeter |
|
| 368 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 369 | - if ( |
|
| 370 | - $r = sql_getfetsel( |
|
| 371 | - 'login', |
|
| 372 | - 'spip_auteurs', |
|
| 373 | - "statut<>'5poubelle'" . |
|
| 374 | - ' AND (length(pass)>0)' . |
|
| 375 | - " AND (login=$l)", |
|
| 376 | - '', |
|
| 377 | - '', |
|
| 378 | - '', |
|
| 379 | - '', |
|
| 380 | - $serveur |
|
| 381 | - ) |
|
| 382 | - ) { |
|
| 383 | - return $r; |
|
| 384 | - } |
|
| 385 | - // Si pas d'auteur avec ce login |
|
| 386 | - // regarder s'il a saisi son nom ou son mail. |
|
| 387 | - // Ne pas fusionner avec la requete precedente |
|
| 388 | - // car un nom peut etre homonyme d'un autre login |
|
| 389 | - else { |
|
| 390 | - return sql_getfetsel( |
|
| 391 | - 'login', |
|
| 392 | - 'spip_auteurs', |
|
| 393 | - "statut<>'5poubelle'" . |
|
| 394 | - ' AND (length(pass)>0)' . |
|
| 395 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 396 | - '', |
|
| 397 | - '', |
|
| 398 | - '', |
|
| 399 | - '', |
|
| 400 | - $serveur |
|
| 401 | - ); |
|
| 402 | - } |
|
| 365 | + if (!strlen($login)) { |
|
| 366 | + return null; |
|
| 367 | + } // pas la peine de requeter |
|
| 368 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 369 | + if ( |
|
| 370 | + $r = sql_getfetsel( |
|
| 371 | + 'login', |
|
| 372 | + 'spip_auteurs', |
|
| 373 | + "statut<>'5poubelle'" . |
|
| 374 | + ' AND (length(pass)>0)' . |
|
| 375 | + " AND (login=$l)", |
|
| 376 | + '', |
|
| 377 | + '', |
|
| 378 | + '', |
|
| 379 | + '', |
|
| 380 | + $serveur |
|
| 381 | + ) |
|
| 382 | + ) { |
|
| 383 | + return $r; |
|
| 384 | + } |
|
| 385 | + // Si pas d'auteur avec ce login |
|
| 386 | + // regarder s'il a saisi son nom ou son mail. |
|
| 387 | + // Ne pas fusionner avec la requete precedente |
|
| 388 | + // car un nom peut etre homonyme d'un autre login |
|
| 389 | + else { |
|
| 390 | + return sql_getfetsel( |
|
| 391 | + 'login', |
|
| 392 | + 'spip_auteurs', |
|
| 393 | + "statut<>'5poubelle'" . |
|
| 394 | + ' AND (length(pass)>0)' . |
|
| 395 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 396 | + '', |
|
| 397 | + '', |
|
| 398 | + '', |
|
| 399 | + '', |
|
| 400 | + $serveur |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * toujours true pour un auteur cree dans SPIP |
| 411 | 411 | */ |
| 412 | 412 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 413 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 414 | - return !strlen($serveur); |
|
| 413 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 414 | + return !strlen($serveur); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -432,12 +432,12 @@ discard block |
||
| 432 | 432 | * message d'erreur si login non valide, chaine vide sinon |
| 433 | 433 | */ |
| 434 | 434 | function auth_spip_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 435 | - // login et mot de passe |
|
| 436 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 437 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 438 | - } |
|
| 435 | + // login et mot de passe |
|
| 436 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 437 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - return ''; |
|
| 440 | + return ''; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -451,47 +451,47 @@ discard block |
||
| 451 | 451 | * @return bool |
| 452 | 452 | */ |
| 453 | 453 | function auth_spip_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 454 | - if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - if ( |
|
| 459 | - !($id_auteur = (int) $id_auteur) |
|
| 460 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | - ) { |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $cles = SpipCles::instance(); |
|
| 466 | - $secret = $cles->getSecretAuth(); |
|
| 467 | - if (!$secret) { |
|
| 468 | - if (auth_spip_initialiser_secret()) { |
|
| 469 | - $secret = $cles->getSecretAuth(); |
|
| 470 | - } |
|
| 471 | - else { |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - include_spip('inc/acces'); |
|
| 478 | - $set = [ |
|
| 479 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 480 | - 'htpass' => generer_htpass($new_pass), |
|
| 481 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 482 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | - 'low_sec' => '', |
|
| 484 | - ]; |
|
| 485 | - |
|
| 486 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 487 | - if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 488 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - include_spip('action/editer_auteur'); |
|
| 492 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 493 | - |
|
| 494 | - return true; // on a bien modifie le pass |
|
| 454 | + if (is_null($new_pass) || auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + if ( |
|
| 459 | + !($id_auteur = (int) $id_auteur) |
|
| 460 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | + ) { |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $cles = SpipCles::instance(); |
|
| 466 | + $secret = $cles->getSecretAuth(); |
|
| 467 | + if (!$secret) { |
|
| 468 | + if (auth_spip_initialiser_secret()) { |
|
| 469 | + $secret = $cles->getSecretAuth(); |
|
| 470 | + } |
|
| 471 | + else { |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + include_spip('inc/acces'); |
|
| 478 | + $set = [ |
|
| 479 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 480 | + 'htpass' => generer_htpass($new_pass), |
|
| 481 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 482 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 483 | + 'low_sec' => '', |
|
| 484 | + ]; |
|
| 485 | + |
|
| 486 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 487 | + if ($auteur['statut'] === '0minirezo' && $auteur['webmestre'] === 'oui') { |
|
| 488 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + include_spip('action/editer_auteur'); |
|
| 492 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 493 | + |
|
| 494 | + return true; // on a bien modifie le pass |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -505,54 +505,54 @@ discard block |
||
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | 507 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 508 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 509 | - if (strlen($serveur)) { |
|
| 510 | - return; |
|
| 511 | - } |
|
| 512 | - // si un login, pass ou statut a ete modifie |
|
| 513 | - // regenerer les fichier htpass |
|
| 514 | - if ( |
|
| 515 | - isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 516 | - ) { |
|
| 517 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 519 | - |
|
| 520 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 521 | - // par exemple acces_restreint ; |
|
| 522 | - // si .htaccess existe, outrepasser spip_meta |
|
| 523 | - if ( |
|
| 524 | - (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 525 | - ) { |
|
| 526 | - spip_unlink($htpasswd); |
|
| 527 | - spip_unlink($htpasswd . '-admin'); |
|
| 528 | - |
|
| 529 | - return; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 533 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 534 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 535 | - |
|
| 536 | - $p1 = ''; // login:htpass pour tous |
|
| 537 | - $p2 = ''; // login:htpass pour les admins |
|
| 538 | - $s = sql_select( |
|
| 539 | - 'login, htpass, statut', |
|
| 540 | - 'spip_auteurs', |
|
| 541 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 542 | - ); |
|
| 543 | - while ($t = sql_fetch($s)) { |
|
| 544 | - if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 545 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 546 | - if ($t['statut'] == '0minirezo') { |
|
| 547 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - sql_free($s); |
|
| 552 | - if ($p1) { |
|
| 553 | - ecrire_fichier($htpasswd, $p1); |
|
| 554 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 555 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 556 | - } |
|
| 557 | - } |
|
| 508 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 509 | + if (strlen($serveur)) { |
|
| 510 | + return; |
|
| 511 | + } |
|
| 512 | + // si un login, pass ou statut a ete modifie |
|
| 513 | + // regenerer les fichier htpass |
|
| 514 | + if ( |
|
| 515 | + isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
|
| 516 | + ) { |
|
| 517 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 519 | + |
|
| 520 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 521 | + // par exemple acces_restreint ; |
|
| 522 | + // si .htaccess existe, outrepasser spip_meta |
|
| 523 | + if ( |
|
| 524 | + (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
|
| 525 | + ) { |
|
| 526 | + spip_unlink($htpasswd); |
|
| 527 | + spip_unlink($htpasswd . '-admin'); |
|
| 528 | + |
|
| 529 | + return; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 533 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 534 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 535 | + |
|
| 536 | + $p1 = ''; // login:htpass pour tous |
|
| 537 | + $p2 = ''; // login:htpass pour les admins |
|
| 538 | + $s = sql_select( |
|
| 539 | + 'login, htpass, statut', |
|
| 540 | + 'spip_auteurs', |
|
| 541 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 542 | + ); |
|
| 543 | + while ($t = sql_fetch($s)) { |
|
| 544 | + if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
|
| 545 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 546 | + if ($t['statut'] == '0minirezo') { |
|
| 547 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + sql_free($s); |
|
| 552 | + if ($p1) { |
|
| 553 | + ecrire_fichier($htpasswd, $p1); |
|
| 554 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 555 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | 558 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $row = sql_fetsel( |
| 50 | 50 | '*', |
| 51 | 51 | 'spip_auteurs', |
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + 'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'", |
|
| 53 | 53 | '', |
| 54 | 54 | '', |
| 55 | 55 | '', |
@@ -76,19 +76,19 @@ discard block |
||
| 76 | 76 | // legacy = md5 ou sha256 |
| 77 | 77 | case 32: |
| 78 | 78 | // tres anciens mots de passe encodes en md5(alea.pass) |
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 79 | + $hash = md5($row['alea_actuel'].$pass); |
|
| 80 | 80 | $methode = 'md5'; |
| 81 | 81 | case 64: |
| 82 | 82 | if (empty($hash)) { |
| 83 | 83 | // anciens mots de passe encodes en sha256(alea.pass) |
| 84 | - $hash = hash('sha256', $row['alea_actuel'] . $pass); |
|
| 84 | + $hash = hash('sha256', $row['alea_actuel'].$pass); |
|
| 85 | 85 | $methode = 'sha256'; |
| 86 | 86 | } |
| 87 | 87 | if ($row['pass'] === $hash) { |
| 88 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 88 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG); |
|
| 89 | 89 | // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
| 90 | 90 | if (!empty($row['backup_cles'])) { |
| 91 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 91 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 92 | 92 | } |
| 93 | 93 | break; |
| 94 | 94 | } |
@@ -106,19 +106,19 @@ discard block |
||
| 106 | 106 | && !empty($row['backup_cles']) |
| 107 | 107 | ) { |
| 108 | 108 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 109 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 109 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE); |
|
| 110 | 110 | if ($cles->save()) { |
| 111 | 111 | $secret = $cles->getSecretAuth(); |
| 112 | 112 | } |
| 113 | 113 | else { |
| 114 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 114 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 115 | 115 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 116 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 116 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | else { |
| 120 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 121 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . (int) $row['id_auteur']); |
|
| 120 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR); |
|
| 121 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.(int) $row['id_auteur']); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | unset($row); |
| 127 | 127 | } |
| 128 | 128 | else { |
| 129 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 129 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG); |
|
| 130 | 130 | } |
| 131 | 131 | break; |
| 132 | 132 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | @sql_update( |
| 172 | 172 | 'spip_auteurs', |
| 173 | 173 | $set, |
| 174 | - 'id_auteur=' . (int) $row['id_auteur'] . ' AND pass=' . sql_quote( |
|
| 174 | + 'id_auteur='.(int) $row['id_auteur'].' AND pass='.sql_quote( |
|
| 175 | 175 | $row['pass'], |
| 176 | 176 | $serveur, |
| 177 | 177 | 'text' |
@@ -218,24 +218,24 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | // si force, on ne verifie pas la presence d'un backup chez un webmestre |
| 220 | 220 | if ($force) { |
| 221 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 221 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE); |
|
| 222 | 222 | $secret = $cles->getSecretAuth(true); |
| 223 | 223 | return true; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 226 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 227 | 227 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 228 | 228 | if ($has_backup === []) { |
| 229 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 229 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 230 | 230 | if ($secret = $cles->getSecretAuth(true)) { |
| 231 | 231 | return true; |
| 232 | 232 | } |
| 233 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 233 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 234 | 234 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 235 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 235 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 236 | 236 | } |
| 237 | 237 | else { |
| 238 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 238 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles', 'auth'._LOG_ERREUR); |
|
| 239 | 239 | } |
| 240 | 240 | return false; |
| 241 | 241 | } |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | $flux['data'] .= |
| 253 | 253 | '<script type="text/javascript">/*<![CDATA[*/' |
| 254 | 254 | . "$js\n" |
| 255 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 256 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 255 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 256 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 257 | 257 | . "'informe_auteur_en_cours':false," |
| 258 | 258 | . "'attente_informe':0};" |
| 259 | 259 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | } else { |
| 294 | 294 | $n = sql_countsel( |
| 295 | 295 | 'spip_auteurs', |
| 296 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . (int) $id_auteur . " AND statut!='5poubelle'", |
|
| 296 | + 'login='.sql_quote($new_login).' AND id_auteur!='.(int) $id_auteur." AND statut!='5poubelle'", |
|
| 297 | 297 | '', |
| 298 | 298 | '', |
| 299 | 299 | $serveur |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | if ( |
| 323 | 323 | !($id_auteur = (int) $id_auteur) |
| 324 | - || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur) |
|
| 324 | + || !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur) |
|
| 325 | 325 | ) { |
| 326 | 326 | return false; |
| 327 | 327 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $anciens = sql_allfetsel( |
| 337 | 337 | 'id_auteur', |
| 338 | 338 | 'spip_auteurs', |
| 339 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 339 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 340 | 340 | '', |
| 341 | 341 | '', |
| 342 | 342 | '', |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | $r = sql_getfetsel( |
| 371 | 371 | 'login', |
| 372 | 372 | 'spip_auteurs', |
| 373 | - "statut<>'5poubelle'" . |
|
| 374 | - ' AND (length(pass)>0)' . |
|
| 373 | + "statut<>'5poubelle'". |
|
| 374 | + ' AND (length(pass)>0)'. |
|
| 375 | 375 | " AND (login=$l)", |
| 376 | 376 | '', |
| 377 | 377 | '', |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | return sql_getfetsel( |
| 391 | 391 | 'login', |
| 392 | 392 | 'spip_auteurs', |
| 393 | - "statut<>'5poubelle'" . |
|
| 394 | - ' AND (length(pass)>0)' . |
|
| 393 | + "statut<>'5poubelle'". |
|
| 394 | + ' AND (length(pass)>0)'. |
|
| 395 | 395 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 396 | 396 | '', |
| 397 | 397 | '', |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | if ( |
| 459 | 459 | !($id_auteur = (int) $id_auteur) |
| 460 | - || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . (int) $id_auteur, '', '', '', '', $serveur)) |
|
| 460 | + || !($auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.(int) $id_auteur, '', '', '', '', $serveur)) |
|
| 461 | 461 | ) { |
| 462 | 462 | return false; |
| 463 | 463 | } |
@@ -514,8 +514,8 @@ discard block |
||
| 514 | 514 | if ( |
| 515 | 515 | isset($champs['login']) || isset($champs['pass']) || isset($champs['statut']) || isset($options['all']) && $options['all'] |
| 516 | 516 | ) { |
| 517 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 518 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 517 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 518 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 519 | 519 | |
| 520 | 520 | // Cette variable de configuration peut etre posee par un plugin |
| 521 | 521 | // par exemple acces_restreint ; |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess) |
| 525 | 525 | ) { |
| 526 | 526 | spip_unlink($htpasswd); |
| 527 | - spip_unlink($htpasswd . '-admin'); |
|
| 527 | + spip_unlink($htpasswd.'-admin'); |
|
| 528 | 528 | |
| 529 | 529 | return; |
| 530 | 530 | } |
@@ -542,16 +542,16 @@ discard block |
||
| 542 | 542 | ); |
| 543 | 543 | while ($t = sql_fetch($s)) { |
| 544 | 544 | if (strlen((string) $t['login']) && strlen((string) $t['htpass'])) { |
| 545 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 545 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 546 | 546 | if ($t['statut'] == '0minirezo') { |
| 547 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 547 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | sql_free($s); |
| 552 | 552 | if ($p1) { |
| 553 | 553 | ecrire_fichier($htpasswd, $p1); |
| 554 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 554 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 555 | 555 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | * @return string Le SHA de la chaîne |
| 13 | 13 | */ |
| 14 | 14 | function spip_sha256($str) { |
| 15 | - trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)'); |
|
| 16 | - return hash('sha256', $str); |
|
| 15 | + trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)'); |
|
| 16 | + return hash('sha256', $str); |
|
| 17 | 17 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Formulaires |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('inc/filtres'); |
@@ -34,26 +34,26 @@ discard block |
||
| 34 | 34 | * @see spip_htmlspecialchars() |
| 35 | 35 | */ |
| 36 | 36 | function protege_champ(mixed $valeur, $max_prof = 128) { |
| 37 | - if (is_array($valeur)) { |
|
| 38 | - if ($max_prof > 0) { |
|
| 39 | - return array_map( |
|
| 40 | - fn($v) => protege_champ($v, $max_prof - 1), |
|
| 41 | - $valeur |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - // si on dépasse la prof max on tronque |
|
| 45 | - return []; |
|
| 46 | - } elseif ($valeur === null) { |
|
| 47 | - return $valeur; |
|
| 48 | - } elseif (is_bool($valeur)) { |
|
| 49 | - return $valeur ? '1' : ''; |
|
| 50 | - } elseif (is_string($valeur) && $valeur) { |
|
| 51 | - if (strpbrk($valeur, "&\"'<>") !== false) { |
|
| 52 | - return spip_htmlspecialchars($valeur, ENT_QUOTES); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $valeur; |
|
| 37 | + if (is_array($valeur)) { |
|
| 38 | + if ($max_prof > 0) { |
|
| 39 | + return array_map( |
|
| 40 | + fn($v) => protege_champ($v, $max_prof - 1), |
|
| 41 | + $valeur |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + // si on dépasse la prof max on tronque |
|
| 45 | + return []; |
|
| 46 | + } elseif ($valeur === null) { |
|
| 47 | + return $valeur; |
|
| 48 | + } elseif (is_bool($valeur)) { |
|
| 49 | + return $valeur ? '1' : ''; |
|
| 50 | + } elseif (is_string($valeur) && $valeur) { |
|
| 51 | + if (strpbrk($valeur, "&\"'<>") !== false) { |
|
| 52 | + return spip_htmlspecialchars($valeur, ENT_QUOTES); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $valeur; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * - false : pas de squelette trouvé |
| 68 | 68 | **/ |
| 69 | 69 | function existe_formulaire($form) { |
| 70 | - $form = str_starts_with($form, 'FORMULAIRE_') ? strtolower(substr($form, 11)) : strtolower($form); |
|
| 70 | + $form = str_starts_with($form, 'FORMULAIRE_') ? strtolower(substr($form, 11)) : strtolower($form); |
|
| 71 | 71 | |
| 72 | - if (!$form) { |
|
| 73 | - return ''; |
|
| 74 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 72 | + if (!$form) { |
|
| 73 | + return ''; |
|
| 74 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 75 | 75 | |
| 76 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 76 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | * @return false|array |
| 83 | 83 | */ |
| 84 | 84 | function test_formulaire_inclus_par_modele() { |
| 85 | - $trace = debug_backtrace(0, 20); |
|
| 86 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 87 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 88 | - |
|
| 89 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 90 | - if ( |
|
| 91 | - function_exists('arguments_balise_dyn_depuis_modele') |
|
| 92 | - && ($form = arguments_balise_dyn_depuis_modele(null, 'read')) |
|
| 93 | - && in_array('balise_formulaire__dyn', $trace_fonctions) |
|
| 94 | - ) { |
|
| 95 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | - if ($trace[$k]['args'][0] === $form) { |
|
| 97 | - return $trace[$k]['args']; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 102 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 103 | - if (in_array('eval', $trace_fonctions) && in_array('inclure_modele', $trace_fonctions)) { |
|
| 104 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 105 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 106 | - return $trace[$k - 1]['args'][1]['args']; |
|
| 107 | - } |
|
| 108 | - return false; |
|
| 85 | + $trace = debug_backtrace(0, 20); |
|
| 86 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 87 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 88 | + |
|
| 89 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 90 | + if ( |
|
| 91 | + function_exists('arguments_balise_dyn_depuis_modele') |
|
| 92 | + && ($form = arguments_balise_dyn_depuis_modele(null, 'read')) |
|
| 93 | + && in_array('balise_formulaire__dyn', $trace_fonctions) |
|
| 94 | + ) { |
|
| 95 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 96 | + if ($trace[$k]['args'][0] === $form) { |
|
| 97 | + return $trace[$k]['args']; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 102 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 103 | + if (in_array('eval', $trace_fonctions) && in_array('inclure_modele', $trace_fonctions)) { |
|
| 104 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 105 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 106 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 107 | + } |
|
| 108 | + return false; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | **/ |
| 121 | 121 | function balise_FORMULAIRE__dist($p) { |
| 122 | 122 | |
| 123 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 124 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 125 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 126 | - $p->code = "''"; |
|
| 127 | - $p->interdire_scripts = false; |
|
| 123 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 124 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 125 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 126 | + $p->code = "''"; |
|
| 127 | + $p->interdire_scripts = false; |
|
| 128 | 128 | |
| 129 | - return $p; |
|
| 130 | - } |
|
| 129 | + return $p; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // sinon renvoyer un code php dynamique |
|
| 133 | - $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 132 | + // sinon renvoyer un code php dynamique |
|
| 133 | + $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 134 | 134 | |
| 135 | - return $p; |
|
| 135 | + return $p; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -152,17 +152,17 @@ discard block |
||
| 152 | 152 | * - string : texte à afficher directement |
| 153 | 153 | */ |
| 154 | 154 | function balise_FORMULAIRE__dyn($form, ...$args) { |
| 155 | - $form = existe_formulaire($form); |
|
| 156 | - if (!$form) { |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 155 | + $form = existe_formulaire($form); |
|
| 156 | + if (!$form) { |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 161 | - if (!is_array($contexte)) { |
|
| 162 | - return $contexte; |
|
| 163 | - } |
|
| 160 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 161 | + if (!is_array($contexte)) { |
|
| 162 | + return $contexte; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return ["formulaires/$form", 3600, $contexte]; |
|
| 165 | + return ["formulaires/$form", 3600, $contexte]; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -177,133 +177,133 @@ discard block |
||
| 177 | 177 | * string: Formulaire non applicable (message d’explication) |
| 178 | 178 | **/ |
| 179 | 179 | function balise_FORMULAIRE__contexte($form, $args) { |
| 180 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 181 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 182 | - // si poste, on recupere les erreurs |
|
| 183 | - |
|
| 184 | - $je_suis_poste = false; |
|
| 185 | - if ( |
|
| 186 | - ($post_form = _request('formulaire_action')) |
|
| 187 | - && $post_form == $form |
|
| 188 | - && ($p = _request('formulaire_action_args')) |
|
| 189 | - && is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | - ) { |
|
| 191 | - // enlever le faux attribut de langue masque |
|
| 192 | - array_shift($p); |
|
| 193 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | - $je_suis_poste = true; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $editable = true; |
|
| 199 | - $erreurs = $post = []; |
|
| 200 | - if ($je_suis_poste) { |
|
| 201 | - $post = traiter_formulaires_dynamiques(true); |
|
| 202 | - $e = "erreurs_$form"; |
|
| 203 | - $erreurs = $post[$e] ?? []; |
|
| 204 | - $editable = "editable_$form"; |
|
| 205 | - $editable = (!isset($post[$e])) |
|
| 206 | - || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 207 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | - |
|
| 212 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | - if (!is_array($valeurs)) { |
|
| 216 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | - // ou une action vide si elle ne sert pas |
|
| 221 | - $action = $valeurs['action'] ?? self('&', true); |
|
| 222 | - // bug IEx : si action finit par / |
|
| 223 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | - if (str_ends_with((string) $action, '/')) { |
|
| 225 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | - $action .= '#'; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // recuperer la saisie en cours si erreurs |
|
| 230 | - // seulement si c'est ce formulaire qui est poste |
|
| 231 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | - foreach (array_keys($valeurs) as $champ) { |
|
| 234 | - if ($champ[0] !== '_' && !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 235 | - if ($dispo && ($v = _request($champ)) !== null) { |
|
| 236 | - $valeurs[$champ] = $v; |
|
| 237 | - } |
|
| 238 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | - if ($action) { |
|
| 240 | - $action = parametre_url($action, $champ, ''); |
|
| 241 | - } |
|
| 242 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($action) { |
|
| 248 | - // nettoyer l'url |
|
| 249 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | - $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 255 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 256 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 257 | - |
|
| 258 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 259 | - $valeurs['erreurs'] = $erreurs; |
|
| 260 | - $valeurs['action'] = $action; |
|
| 261 | - $valeurs['form'] = $form; |
|
| 262 | - |
|
| 263 | - $valeurs['formulaire_sign'] = ''; |
|
| 264 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 265 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 266 | - $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 267 | - $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if (!isset($valeurs['id'])) { |
|
| 271 | - $valeurs['id'] = 'new'; |
|
| 272 | - } |
|
| 273 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | - if (!isset($valeurs['editable'])) { |
|
| 275 | - $valeurs['editable'] = $editable; |
|
| 276 | - } |
|
| 277 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | - |
|
| 280 | - if ($je_suis_poste) { |
|
| 281 | - $valeurs['message_erreur'] = ''; |
|
| 282 | - if (isset($erreurs['message_erreur'])) { |
|
| 283 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $valeurs['message_ok'] = ''; |
|
| 287 | - if (isset($post["message_ok_$form"])) { |
|
| 288 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | - $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 294 | - // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 295 | - // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 296 | - if (html5_permis()) { |
|
| 297 | - foreach ($erreurs as $k => $v) { |
|
| 298 | - if (is_string($v) && strlen(trim($v)) && !str_starts_with((string) $k, '_')) { |
|
| 299 | - // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 300 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - return $valeurs; |
|
| 180 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 181 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 182 | + // si poste, on recupere les erreurs |
|
| 183 | + |
|
| 184 | + $je_suis_poste = false; |
|
| 185 | + if ( |
|
| 186 | + ($post_form = _request('formulaire_action')) |
|
| 187 | + && $post_form == $form |
|
| 188 | + && ($p = _request('formulaire_action_args')) |
|
| 189 | + && is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 190 | + ) { |
|
| 191 | + // enlever le faux attribut de langue masque |
|
| 192 | + array_shift($p); |
|
| 193 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 194 | + $je_suis_poste = true; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $editable = true; |
|
| 199 | + $erreurs = $post = []; |
|
| 200 | + if ($je_suis_poste) { |
|
| 201 | + $post = traiter_formulaires_dynamiques(true); |
|
| 202 | + $e = "erreurs_$form"; |
|
| 203 | + $erreurs = $post[$e] ?? []; |
|
| 204 | + $editable = "editable_$form"; |
|
| 205 | + $editable = (!isset($post[$e])) |
|
| 206 | + || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 207 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 211 | + |
|
| 212 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 213 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 214 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 215 | + if (!is_array($valeurs)) { |
|
| 216 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 220 | + // ou une action vide si elle ne sert pas |
|
| 221 | + $action = $valeurs['action'] ?? self('&', true); |
|
| 222 | + // bug IEx : si action finit par / |
|
| 223 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | + if (str_ends_with((string) $action, '/')) { |
|
| 225 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 226 | + $action .= '#'; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // recuperer la saisie en cours si erreurs |
|
| 230 | + // seulement si c'est ce formulaire qui est poste |
|
| 231 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 232 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 233 | + foreach (array_keys($valeurs) as $champ) { |
|
| 234 | + if ($champ[0] !== '_' && !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 235 | + if ($dispo && ($v = _request($champ)) !== null) { |
|
| 236 | + $valeurs[$champ] = $v; |
|
| 237 | + } |
|
| 238 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | + if ($action) { |
|
| 240 | + $action = parametre_url($action, $champ, ''); |
|
| 241 | + } |
|
| 242 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($action) { |
|
| 248 | + // nettoyer l'url |
|
| 249 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | + $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 255 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 256 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 257 | + |
|
| 258 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 259 | + $valeurs['erreurs'] = $erreurs; |
|
| 260 | + $valeurs['action'] = $action; |
|
| 261 | + $valeurs['form'] = $form; |
|
| 262 | + |
|
| 263 | + $valeurs['formulaire_sign'] = ''; |
|
| 264 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 265 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 266 | + $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 267 | + $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if (!isset($valeurs['id'])) { |
|
| 271 | + $valeurs['id'] = 'new'; |
|
| 272 | + } |
|
| 273 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | + if (!isset($valeurs['editable'])) { |
|
| 275 | + $valeurs['editable'] = $editable; |
|
| 276 | + } |
|
| 277 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | + |
|
| 280 | + if ($je_suis_poste) { |
|
| 281 | + $valeurs['message_erreur'] = ''; |
|
| 282 | + if (isset($erreurs['message_erreur'])) { |
|
| 283 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $valeurs['message_ok'] = ''; |
|
| 287 | + if (isset($post["message_ok_$form"])) { |
|
| 288 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | + $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 294 | + // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 295 | + // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 296 | + if (html5_permis()) { |
|
| 297 | + foreach ($erreurs as $k => $v) { |
|
| 298 | + if (is_string($v) && strlen(trim($v)) && !str_starts_with((string) $k, '_')) { |
|
| 299 | + // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 300 | + $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + return $valeurs; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -315,51 +315,51 @@ discard block |
||
| 315 | 315 | * @return array |
| 316 | 316 | */ |
| 317 | 317 | function formulaire__charger($form, $args, $poste) { |
| 318 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 319 | - $valeurs = $charger_valeurs(...$args); |
|
| 320 | - } else { |
|
| 321 | - $valeurs = []; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $valeurs = pipeline( |
|
| 325 | - 'formulaire_charger', |
|
| 326 | - [ |
|
| 327 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 328 | - 'data' => $valeurs |
|
| 329 | - ] |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - // prise en charge CVT multi etape |
|
| 333 | - if (is_array($valeurs) && isset($valeurs['_etapes'])) { |
|
| 334 | - include_spip('inc/cvt_multietapes'); |
|
| 335 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 336 | - ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 337 | - $valeurs |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 342 | - if (is_array($valeurs)) { |
|
| 343 | - if (!isset($valeurs['_pipelines'])) { |
|
| 344 | - $valeurs['_pipelines'] = []; |
|
| 345 | - } |
|
| 346 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 347 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 348 | - if (isset($valeurs['_pipeline'])) { |
|
| 349 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 350 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 351 | - |
|
| 352 | - $pipelines = [$pipe => $args]; |
|
| 353 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 357 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 358 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 359 | - $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $valeurs; |
|
| 318 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 319 | + $valeurs = $charger_valeurs(...$args); |
|
| 320 | + } else { |
|
| 321 | + $valeurs = []; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $valeurs = pipeline( |
|
| 325 | + 'formulaire_charger', |
|
| 326 | + [ |
|
| 327 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 328 | + 'data' => $valeurs |
|
| 329 | + ] |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + // prise en charge CVT multi etape |
|
| 333 | + if (is_array($valeurs) && isset($valeurs['_etapes'])) { |
|
| 334 | + include_spip('inc/cvt_multietapes'); |
|
| 335 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 336 | + ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 337 | + $valeurs |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 342 | + if (is_array($valeurs)) { |
|
| 343 | + if (!isset($valeurs['_pipelines'])) { |
|
| 344 | + $valeurs['_pipelines'] = []; |
|
| 345 | + } |
|
| 346 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 347 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 348 | + if (isset($valeurs['_pipeline'])) { |
|
| 349 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 350 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 351 | + |
|
| 352 | + $pipelines = [$pipe => $args]; |
|
| 353 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 357 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 358 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 359 | + $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $valeurs; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,9 +378,9 @@ discard block |
||
| 378 | 378 | * @return bool |
| 379 | 379 | */ |
| 380 | 380 | function formulaire__identifier($form, $args, $p) { |
| 381 | - if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 382 | - return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 383 | - } |
|
| 381 | + if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 382 | + return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | - return $args === $p; |
|
| 385 | + return $args === $p; |
|
| 386 | 386 | } |