@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,15 +37,15 @@ discard block |
||
| 37 | 37 | define('_PHP_MAX', '8.2.99'); |
| 38 | 38 | |
| 39 | 39 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 40 | - /** le nom du repertoire ecrire/ */ |
|
| 41 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 40 | + /** le nom du repertoire ecrire/ */ |
|
| 41 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** Chemin relatif pour aller dans ecrire |
| 45 | 45 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 46 | 46 | define( |
| 47 | - '_DIR_RESTREINT', |
|
| 48 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 47 | + '_DIR_RESTREINT', |
|
| 48 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | /** Chemin relatif pour aller à la racine */ |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // Icones |
| 62 | 62 | if (!defined('_NOM_IMG_PACK')) { |
| 63 | - /** Nom du dossier images */ |
|
| 64 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 63 | + /** Nom du dossier images */ |
|
| 64 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 65 | 65 | } |
| 66 | 66 | /** le chemin http (relatif) vers les images standard */ |
| 67 | 67 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 71 | 71 | |
| 72 | 72 | if (!defined('_JAVASCRIPT')) { |
| 73 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 74 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 73 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 74 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 75 | 75 | } // utilisable avec #CHEMIN et find_in_path |
| 76 | 76 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 77 | 77 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -81,47 +81,47 @@ discard block |
||
| 81 | 81 | # mais on peut les mettre ailleurs et changer completement les noms |
| 82 | 82 | |
| 83 | 83 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 84 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 85 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 84 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 85 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 86 | 86 | } |
| 87 | 87 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 88 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 89 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 88 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 89 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 90 | 90 | } |
| 91 | 91 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 92 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 93 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 92 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 93 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 94 | 94 | } |
| 95 | 95 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 96 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 97 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 96 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 97 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | /** Le nom du fichier de personnalisation */ |
| 102 | 102 | if (!defined('_NOM_CONFIG')) { |
| 103 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 103 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Son emplacement absolu si on le trouve |
| 107 | 107 | if ( |
| 108 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 109 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 108 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 109 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 110 | 110 | ) { |
| 111 | - /** Emplacement absolu du fichier d'option */ |
|
| 112 | - define('_FILE_OPTIONS', $f); |
|
| 111 | + /** Emplacement absolu du fichier d'option */ |
|
| 112 | + define('_FILE_OPTIONS', $f); |
|
| 113 | 113 | } else { |
| 114 | - define('_FILE_OPTIONS', ''); |
|
| 114 | + define('_FILE_OPTIONS', ''); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if (!defined('MODULES_IDIOMES')) { |
| 118 | - /** |
|
| 119 | - * Modules par défaut pour la traduction. |
|
| 120 | - * |
|
| 121 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 122 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 123 | - */ |
|
| 124 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 118 | + /** |
|
| 119 | + * Modules par défaut pour la traduction. |
|
| 120 | + * |
|
| 121 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 122 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 123 | + */ |
|
| 124 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // *** Fin des define *** // |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | // Inclure l'ecran de securite |
| 131 | 131 | if ( |
| 132 | - !defined('_ECRAN_SECURITE') |
|
| 133 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 132 | + !defined('_ECRAN_SECURITE') |
|
| 133 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 134 | 134 | ) { |
| 135 | - include $f; |
|
| 135 | + include $f; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -140,30 +140,30 @@ discard block |
||
| 140 | 140 | * Détecteur de robot d'indexation |
| 141 | 141 | */ |
| 142 | 142 | if (!defined('_IS_BOT')) { |
| 143 | - define( |
|
| 144 | - '_IS_BOT', |
|
| 145 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 146 | - and preg_match( |
|
| 147 | - // mots generiques |
|
| 148 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 149 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 150 | - . 'MSIE 6\.0|' |
|
| 151 | - // UA plus cibles |
|
| 152 | - . '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' |
|
| 153 | - . ',i', |
|
| 154 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 143 | + define( |
|
| 144 | + '_IS_BOT', |
|
| 145 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 146 | + and preg_match( |
|
| 147 | + // mots generiques |
|
| 148 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 149 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 150 | + . 'MSIE 6\.0|' |
|
| 151 | + // UA plus cibles |
|
| 152 | + . '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' |
|
| 153 | + . ',i', |
|
| 154 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | if (!defined('_IS_CLI')) { |
| 160 | - define( |
|
| 161 | - '_IS_CLI', |
|
| 162 | - !isset($_SERVER['HTTP_HOST']) |
|
| 163 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 164 | - and !empty($_SERVER['argv']) |
|
| 165 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 166 | - ); |
|
| 160 | + define( |
|
| 161 | + '_IS_CLI', |
|
| 162 | + !isset($_SERVER['HTTP_HOST']) |
|
| 163 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 164 | + and !empty($_SERVER['argv']) |
|
| 165 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 166 | + ); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // *** Parametrage par defaut de SPIP *** |
@@ -175,61 +175,61 @@ discard block |
||
| 175 | 175 | // Ne pas les rendre indefinies. |
| 176 | 176 | |
| 177 | 177 | global |
| 178 | - $nombre_de_logs, |
|
| 179 | - $taille_des_logs, |
|
| 180 | - $table_prefix, |
|
| 181 | - $cookie_prefix, |
|
| 182 | - $dossier_squelettes, |
|
| 183 | - $filtrer_javascript, |
|
| 184 | - $type_urls, |
|
| 185 | - $debut_date_publication, |
|
| 186 | - $ip, |
|
| 187 | - $mysql_rappel_connexion, |
|
| 188 | - $mysql_rappel_nom_base, |
|
| 189 | - $test_i18n, |
|
| 190 | - $ignore_auth_http, |
|
| 191 | - $ignore_remote_user, |
|
| 192 | - $derniere_modif_invalide, |
|
| 193 | - $home_server, |
|
| 194 | - $help_server, |
|
| 195 | - $url_glossaire_externe, |
|
| 196 | - $tex_server, |
|
| 197 | - $traiter_math, |
|
| 198 | - $xhtml, |
|
| 199 | - $xml_indent, |
|
| 200 | - $source_vignettes, |
|
| 201 | - $formats_logos, |
|
| 202 | - $controler_dates_rss, |
|
| 203 | - $spip_pipeline, |
|
| 204 | - $spip_matrice, |
|
| 205 | - $plugins, |
|
| 206 | - $surcharges, |
|
| 207 | - $exceptions_des_tables, |
|
| 208 | - $tables_principales, |
|
| 209 | - $table_des_tables, |
|
| 210 | - $tables_auxiliaires, |
|
| 211 | - $table_primary, |
|
| 212 | - $table_date, |
|
| 213 | - $table_titre, |
|
| 214 | - $tables_jointures, |
|
| 215 | - $liste_des_statuts, |
|
| 216 | - $liste_des_etats, |
|
| 217 | - $liste_des_authentifications, |
|
| 218 | - $spip_version_branche, |
|
| 219 | - $spip_version_code, |
|
| 220 | - $spip_version_base, |
|
| 221 | - $spip_sql_version, |
|
| 222 | - $spip_version_affichee, |
|
| 223 | - $visiteur_session, |
|
| 224 | - $auteur_session, |
|
| 225 | - $connect_statut, |
|
| 226 | - $connect_toutes_rubriques, |
|
| 227 | - $hash_recherche, |
|
| 228 | - $hash_recherche_strict, |
|
| 229 | - $ldap_present, |
|
| 230 | - $meta, |
|
| 231 | - $connect_id_rubrique, |
|
| 232 | - $puce; |
|
| 178 | + $nombre_de_logs, |
|
| 179 | + $taille_des_logs, |
|
| 180 | + $table_prefix, |
|
| 181 | + $cookie_prefix, |
|
| 182 | + $dossier_squelettes, |
|
| 183 | + $filtrer_javascript, |
|
| 184 | + $type_urls, |
|
| 185 | + $debut_date_publication, |
|
| 186 | + $ip, |
|
| 187 | + $mysql_rappel_connexion, |
|
| 188 | + $mysql_rappel_nom_base, |
|
| 189 | + $test_i18n, |
|
| 190 | + $ignore_auth_http, |
|
| 191 | + $ignore_remote_user, |
|
| 192 | + $derniere_modif_invalide, |
|
| 193 | + $home_server, |
|
| 194 | + $help_server, |
|
| 195 | + $url_glossaire_externe, |
|
| 196 | + $tex_server, |
|
| 197 | + $traiter_math, |
|
| 198 | + $xhtml, |
|
| 199 | + $xml_indent, |
|
| 200 | + $source_vignettes, |
|
| 201 | + $formats_logos, |
|
| 202 | + $controler_dates_rss, |
|
| 203 | + $spip_pipeline, |
|
| 204 | + $spip_matrice, |
|
| 205 | + $plugins, |
|
| 206 | + $surcharges, |
|
| 207 | + $exceptions_des_tables, |
|
| 208 | + $tables_principales, |
|
| 209 | + $table_des_tables, |
|
| 210 | + $tables_auxiliaires, |
|
| 211 | + $table_primary, |
|
| 212 | + $table_date, |
|
| 213 | + $table_titre, |
|
| 214 | + $tables_jointures, |
|
| 215 | + $liste_des_statuts, |
|
| 216 | + $liste_des_etats, |
|
| 217 | + $liste_des_authentifications, |
|
| 218 | + $spip_version_branche, |
|
| 219 | + $spip_version_code, |
|
| 220 | + $spip_version_base, |
|
| 221 | + $spip_sql_version, |
|
| 222 | + $spip_version_affichee, |
|
| 223 | + $visiteur_session, |
|
| 224 | + $auteur_session, |
|
| 225 | + $connect_statut, |
|
| 226 | + $connect_toutes_rubriques, |
|
| 227 | + $hash_recherche, |
|
| 228 | + $hash_recherche_strict, |
|
| 229 | + $ldap_present, |
|
| 230 | + $meta, |
|
| 231 | + $connect_id_rubrique, |
|
| 232 | + $puce; |
|
| 233 | 233 | |
| 234 | 234 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 235 | 235 | $nombre_de_logs = 4; |
@@ -284,48 +284,48 @@ discard block |
||
| 284 | 284 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 285 | 285 | // |
| 286 | 286 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 287 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 288 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 289 | - } |
|
| 290 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 291 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 292 | - } |
|
| 287 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 288 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 289 | + } |
|
| 290 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 291 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 292 | + } |
|
| 293 | 293 | } |
| 294 | 294 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 295 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 296 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 297 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 298 | - $_SERVER['HTTPS'] = 'on'; |
|
| 299 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 300 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 305 | - if (strpos($host, ',') !== false) { |
|
| 306 | - $h = explode(',', $host); |
|
| 307 | - $host = trim(reset($h)); |
|
| 308 | - } |
|
| 309 | - // securite sur le contenu de l'entete |
|
| 310 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 311 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 295 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 296 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 297 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 298 | + $_SERVER['HTTPS'] = 'on'; |
|
| 299 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 300 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 305 | + if (strpos($host, ',') !== false) { |
|
| 306 | + $h = explode(',', $host); |
|
| 307 | + $host = trim(reset($h)); |
|
| 308 | + } |
|
| 309 | + // securite sur le contenu de l'entete |
|
| 310 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 311 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 312 | 312 | } |
| 313 | 313 | // |
| 314 | 314 | // On note le numero IP du client dans la variable $ip |
| 315 | 315 | // |
| 316 | 316 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 317 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 318 | - if (strpos($ip, ',') !== false) { |
|
| 319 | - $ip = explode(',', $ip); |
|
| 320 | - $ip = reset($ip); |
|
| 321 | - } |
|
| 322 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 323 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 324 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 325 | - } |
|
| 317 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 318 | + if (strpos($ip, ',') !== false) { |
|
| 319 | + $ip = explode(',', $ip); |
|
| 320 | + $ip = reset($ip); |
|
| 321 | + } |
|
| 322 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 323 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 324 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 325 | + } |
|
| 326 | 326 | } |
| 327 | 327 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 328 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 328 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -410,24 +410,24 @@ discard block |
||
| 410 | 410 | |
| 411 | 411 | // Liste des statuts. |
| 412 | 412 | $liste_des_statuts = [ |
| 413 | - 'info_administrateurs' => '0minirezo', |
|
| 414 | - 'info_redacteurs' => '1comite', |
|
| 415 | - 'info_visiteurs' => '6forum', |
|
| 416 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 413 | + 'info_administrateurs' => '0minirezo', |
|
| 414 | + 'info_redacteurs' => '1comite', |
|
| 415 | + 'info_visiteurs' => '6forum', |
|
| 416 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 417 | 417 | ]; |
| 418 | 418 | |
| 419 | 419 | $liste_des_etats = [ |
| 420 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 421 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 422 | - 'texte_statut_publie' => 'publie', |
|
| 423 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 424 | - 'texte_statut_refuse' => 'refuse' |
|
| 420 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 421 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 422 | + 'texte_statut_publie' => 'publie', |
|
| 423 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 424 | + 'texte_statut_refuse' => 'refuse' |
|
| 425 | 425 | ]; |
| 426 | 426 | |
| 427 | 427 | // liste des methodes d'authentifications |
| 428 | 428 | $liste_des_authentifications = [ |
| 429 | - 'spip' => 'spip', |
|
| 430 | - 'ldap' => 'ldap' |
|
| 429 | + 'spip' => 'spip', |
|
| 430 | + 'ldap' => 'ldap' |
|
| 431 | 431 | ]; |
| 432 | 432 | |
| 433 | 433 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -477,12 +477,12 @@ discard block |
||
| 477 | 477 | // Definition personnelles eventuelles |
| 478 | 478 | |
| 479 | 479 | if (_FILE_OPTIONS) { |
| 480 | - include_once _FILE_OPTIONS; |
|
| 480 | + include_once _FILE_OPTIONS; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 484 | - /** Masquer les warning */ |
|
| 485 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 484 | + /** Masquer les warning */ |
|
| 485 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 486 | 486 | } |
| 487 | 487 | error_reporting(SPIP_ERREUR_REPORT); |
| 488 | 488 | |
@@ -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,70 +508,70 @@ 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) and @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 | - or autoriser_sans_cookie(_request('exec')) |
|
| 544 | - or _request('action') == 'cookie' |
|
| 545 | - or _request('action') == 'converser' |
|
| 546 | - or _request('action') == 'test_dirs') |
|
| 542 | + !(_FILE_CONNECT |
|
| 543 | + or autoriser_sans_cookie(_request('exec')) |
|
| 544 | + or _request('action') == 'cookie' |
|
| 545 | + or _request('action') == 'converser' |
|
| 546 | + or _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/minipres'); |
|
| 555 | - utiliser_langue_visiteur(); |
|
| 556 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 557 | - exit; |
|
| 558 | - } |
|
| 559 | - // 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/minipres'); |
|
| 555 | + utiliser_langue_visiteur(); |
|
| 556 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 557 | + exit; |
|
| 558 | + } |
|
| 559 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | // memoriser un tri sessionne eventuel |
| 563 | 563 | if ( |
| 564 | - isset($_REQUEST['var_memotri']) |
|
| 565 | - and $t = $_REQUEST['var_memotri'] |
|
| 566 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 564 | + isset($_REQUEST['var_memotri']) |
|
| 565 | + and $t = $_REQUEST['var_memotri'] |
|
| 566 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 567 | 567 | ) { |
| 568 | - if (!function_exists('session_set')) { |
|
| 569 | - include_spip('inc/session'); |
|
| 570 | - } |
|
| 571 | - $t = preg_replace(',\W,', '_', $t); |
|
| 572 | - if ($v = _request($t)) { |
|
| 573 | - session_set($t, $v); |
|
| 574 | - } |
|
| 568 | + if (!function_exists('session_set')) { |
|
| 569 | + include_spip('inc/session'); |
|
| 570 | + } |
|
| 571 | + $t = preg_replace(',\W,', '_', $t); |
|
| 572 | + if ($v = _request($t)) { |
|
| 573 | + session_set($t, $v); |
|
| 574 | + } |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -581,22 +581,22 @@ discard block |
||
| 581 | 581 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 582 | 582 | */ |
| 583 | 583 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 584 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 584 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 585 | 585 | } |
| 586 | 586 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 587 | - if (!defined('_HEADER_VARY')) { |
|
| 588 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 589 | - } |
|
| 590 | - if (_HEADER_VARY) { |
|
| 591 | - header(_HEADER_VARY); |
|
| 592 | - } |
|
| 593 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 594 | - include_spip('inc/filtres_mini'); |
|
| 595 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 596 | - } else { |
|
| 597 | - // header minimal |
|
| 598 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 599 | - } |
|
| 587 | + if (!defined('_HEADER_VARY')) { |
|
| 588 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 589 | + } |
|
| 590 | + if (_HEADER_VARY) { |
|
| 591 | + header(_HEADER_VARY); |
|
| 592 | + } |
|
| 593 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 594 | + include_spip('inc/filtres_mini'); |
|
| 595 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 596 | + } else { |
|
| 597 | + // header minimal |
|
| 598 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 599 | + } |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return [$id, _L('echec enregistrement en base')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return [$id, $err]; |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return [$id, _L('echec enregistrement en base')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return [$id, $err]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,85 +75,85 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if ( |
|
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 85 | - ) { |
|
| 86 | - return $modifier($id, $set); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $table_sql = table_objet_sql($objet); |
|
| 90 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | - $desc = $trouver_table($table_sql); |
|
| 92 | - if (!$desc or !isset($desc['field'])) { |
|
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | - |
|
| 95 | - return _L("Erreur objet $objet inconnu"); |
|
| 96 | - } |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - |
|
| 99 | - $champ_date = ''; |
|
| 100 | - if (isset($desc['date']) and $desc['date']) { |
|
| 101 | - $champ_date = $desc['date']; |
|
| 102 | - } elseif (isset($desc['field']['date'])) { |
|
| 103 | - $champ_date = 'date'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $include_list = array_keys($desc['field']); |
|
| 107 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $include_list = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // include list |
|
| 116 | - $include_list, |
|
| 117 | - // exclude list |
|
| 118 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | - // donnees eventuellement fournies |
|
| 120 | - $set |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | - if (objet_test_si_publie($objet, $id)) { |
|
| 125 | - $invalideur = "id='$objet/$id'"; |
|
| 126 | - $indexation = true; |
|
| 127 | - } else { |
|
| 128 | - $invalideur = ''; |
|
| 129 | - $indexation = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( |
|
| 133 | - $err = objet_modifier_champs( |
|
| 134 | - $objet, |
|
| 135 | - $id, |
|
| 136 | - [ |
|
| 137 | - 'data' => $set, |
|
| 138 | - 'nonvide' => '', |
|
| 139 | - 'invalideur' => $invalideur, |
|
| 140 | - 'indexation' => $indexation, |
|
| 141 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | - ], |
|
| 144 | - $c |
|
| 145 | - ) |
|
| 146 | - ) { |
|
| 147 | - return $err; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Modification de statut, changement de rubrique ? |
|
| 151 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | - $err = objet_instituer($objet, $id, $c); |
|
| 155 | - |
|
| 156 | - return $err; |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if ( |
|
| 83 | + include_spip('action/editer_' . $objet) |
|
| 84 | + and function_exists($modifier = $objet . '_modifier') |
|
| 85 | + ) { |
|
| 86 | + return $modifier($id, $set); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $table_sql = table_objet_sql($objet); |
|
| 90 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | + $desc = $trouver_table($table_sql); |
|
| 92 | + if (!$desc or !isset($desc['field'])) { |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | + |
|
| 95 | + return _L("Erreur objet $objet inconnu"); |
|
| 96 | + } |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + |
|
| 99 | + $champ_date = ''; |
|
| 100 | + if (isset($desc['date']) and $desc['date']) { |
|
| 101 | + $champ_date = $desc['date']; |
|
| 102 | + } elseif (isset($desc['field']['date'])) { |
|
| 103 | + $champ_date = 'date'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $include_list = array_keys($desc['field']); |
|
| 107 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $include_list = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // include list |
|
| 116 | + $include_list, |
|
| 117 | + // exclude list |
|
| 118 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | + // donnees eventuellement fournies |
|
| 120 | + $set |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | + if (objet_test_si_publie($objet, $id)) { |
|
| 125 | + $invalideur = "id='$objet/$id'"; |
|
| 126 | + $indexation = true; |
|
| 127 | + } else { |
|
| 128 | + $invalideur = ''; |
|
| 129 | + $indexation = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( |
|
| 133 | + $err = objet_modifier_champs( |
|
| 134 | + $objet, |
|
| 135 | + $id, |
|
| 136 | + [ |
|
| 137 | + 'data' => $set, |
|
| 138 | + 'nonvide' => '', |
|
| 139 | + 'invalideur' => $invalideur, |
|
| 140 | + 'indexation' => $indexation, |
|
| 141 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | + ], |
|
| 144 | + $c |
|
| 145 | + ) |
|
| 146 | + ) { |
|
| 147 | + return $err; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Modification de statut, changement de rubrique ? |
|
| 151 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | + $err = objet_instituer($objet, $id, $c); |
|
| 155 | + |
|
| 156 | + return $err; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,135 +168,135 @@ discard block |
||
| 168 | 168 | * @return bool|int |
| 169 | 169 | */ |
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | - $d = null; |
|
| 172 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | - $objet = $t; |
|
| 175 | - } |
|
| 176 | - if ( |
|
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 179 | - ) { |
|
| 180 | - return $inserer($id_parent, $set); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $table_sql = table_objet_sql($objet); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $desc = $trouver_table($table_sql); |
|
| 186 | - if (!$desc or !isset($desc['field'])) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $lang_rub = ''; |
|
| 191 | - $champs = []; |
|
| 192 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | - // dans la premiere rubrique racine |
|
| 195 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | - $id_rubrique = $row['id_rubrique']; |
|
| 198 | - } else { |
|
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | - if (isset($desc['field']['id_secteur'])) { |
|
| 204 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | - } |
|
| 206 | - $lang_rub = $row['lang']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | - // ou a defaut celle de la rubrique |
|
| 212 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | - if ( |
|
| 214 | - isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | - $table_sql, |
|
| 216 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | - if ( |
|
| 221 | - in_array( |
|
| 222 | - $GLOBALS['spip_lang'], |
|
| 223 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | - ) |
|
| 225 | - ) { |
|
| 226 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | - $champs['langue_choisie'] = 'oui'; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | - $champs['langue_choisie'] = 'non'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (isset($desc['field']['statut'])) { |
|
| 237 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | - $champs['statut'] = reset($cles_statut); |
|
| 240 | - } else { |
|
| 241 | - $champs['statut'] = 'prepa'; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($set) { |
|
| 251 | - $champs = array_merge($champs, $set); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Envoyer aux plugins |
|
| 255 | - $champs = pipeline( |
|
| 256 | - 'pre_insertion', |
|
| 257 | - [ |
|
| 258 | - 'args' => [ |
|
| 259 | - 'table' => $table_sql, |
|
| 260 | - 'id_parent' => $id_parent, |
|
| 261 | - ], |
|
| 262 | - 'data' => $champs |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - $id = sql_insertq($table_sql, $champs); |
|
| 267 | - |
|
| 268 | - if ($id) { |
|
| 269 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | - // et associer l'auteur sinon |
|
| 271 | - // si la table n'a pas deja un champ id_auteur |
|
| 272 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | - if ( |
|
| 274 | - $id > 0 |
|
| 275 | - and !isset($desc['field']['id_auteur']) |
|
| 276 | - ) { |
|
| 277 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | - : _request('id_auteur')); |
|
| 280 | - if ($id_auteur) { |
|
| 281 | - include_spip('action/editer_auteur'); |
|
| 282 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - pipeline( |
|
| 287 | - 'post_insertion', |
|
| 288 | - [ |
|
| 289 | - 'args' => [ |
|
| 290 | - 'table' => $table_sql, |
|
| 291 | - 'id_parent' => $id_parent, |
|
| 292 | - 'id_objet' => $id, |
|
| 293 | - ], |
|
| 294 | - 'data' => $champs |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $id; |
|
| 171 | + $d = null; |
|
| 172 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | + $objet = $t; |
|
| 175 | + } |
|
| 176 | + if ( |
|
| 177 | + include_spip('action/editer_' . $objet) |
|
| 178 | + and function_exists($inserer = $objet . '_inserer') |
|
| 179 | + ) { |
|
| 180 | + return $inserer($id_parent, $set); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $table_sql = table_objet_sql($objet); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $desc = $trouver_table($table_sql); |
|
| 186 | + if (!$desc or !isset($desc['field'])) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $lang_rub = ''; |
|
| 191 | + $champs = []; |
|
| 192 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | + // dans la premiere rubrique racine |
|
| 195 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | + $id_rubrique = $row['id_rubrique']; |
|
| 198 | + } else { |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | + if (isset($desc['field']['id_secteur'])) { |
|
| 204 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | + } |
|
| 206 | + $lang_rub = $row['lang']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | + // ou a defaut celle de la rubrique |
|
| 212 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | + if ( |
|
| 214 | + isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | + $table_sql, |
|
| 216 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | + if ( |
|
| 221 | + in_array( |
|
| 222 | + $GLOBALS['spip_lang'], |
|
| 223 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | + ) |
|
| 225 | + ) { |
|
| 226 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | + $champs['langue_choisie'] = 'oui'; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | + $champs['langue_choisie'] = 'non'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (isset($desc['field']['statut'])) { |
|
| 237 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | + $champs['statut'] = reset($cles_statut); |
|
| 240 | + } else { |
|
| 241 | + $champs['statut'] = 'prepa'; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($set) { |
|
| 251 | + $champs = array_merge($champs, $set); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // Envoyer aux plugins |
|
| 255 | + $champs = pipeline( |
|
| 256 | + 'pre_insertion', |
|
| 257 | + [ |
|
| 258 | + 'args' => [ |
|
| 259 | + 'table' => $table_sql, |
|
| 260 | + 'id_parent' => $id_parent, |
|
| 261 | + ], |
|
| 262 | + 'data' => $champs |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + $id = sql_insertq($table_sql, $champs); |
|
| 267 | + |
|
| 268 | + if ($id) { |
|
| 269 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | + // et associer l'auteur sinon |
|
| 271 | + // si la table n'a pas deja un champ id_auteur |
|
| 272 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | + if ( |
|
| 274 | + $id > 0 |
|
| 275 | + and !isset($desc['field']['id_auteur']) |
|
| 276 | + ) { |
|
| 277 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | + : _request('id_auteur')); |
|
| 280 | + if ($id_auteur) { |
|
| 281 | + include_spip('action/editer_auteur'); |
|
| 282 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + pipeline( |
|
| 287 | + 'post_insertion', |
|
| 288 | + [ |
|
| 289 | + 'args' => [ |
|
| 290 | + 'table' => $table_sql, |
|
| 291 | + 'id_parent' => $id_parent, |
|
| 292 | + 'id_objet' => $id, |
|
| 293 | + ], |
|
| 294 | + 'data' => $champs |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $id; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -313,138 +313,138 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | - $objet = $t; |
|
| 319 | - } |
|
| 320 | - if ( |
|
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 323 | - ) { |
|
| 324 | - return $instituer($id, $c, $calcul_rub); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $table_sql = table_objet_sql($objet); |
|
| 328 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | - $desc = $trouver_table($table_sql); |
|
| 330 | - if (!$desc or !isset($desc['field'])) { |
|
| 331 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - include_spip('inc/autoriser'); |
|
| 335 | - include_spip('inc/rubriques'); |
|
| 336 | - include_spip('inc/modifier'); |
|
| 337 | - |
|
| 338 | - $sel = []; |
|
| 339 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | - |
|
| 341 | - $champ_date = ''; |
|
| 342 | - if (isset($desc['date']) and $desc['date']) { |
|
| 343 | - $champ_date = $desc['date']; |
|
| 344 | - } elseif (isset($desc['field']['date'])) { |
|
| 345 | - $champ_date = 'date'; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | - |
|
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | - |
|
| 353 | - $id_rubrique = $row['id_rubrique']; |
|
| 354 | - $statut_ancien = $statut = $row['statut']; |
|
| 355 | - $date_ancienne = $date = $row['date']; |
|
| 356 | - $champs = []; |
|
| 357 | - |
|
| 358 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | - |
|
| 361 | - // cf autorisations dans inc/instituer_objet |
|
| 362 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | - if ( |
|
| 364 | - $id_rubrique ? |
|
| 365 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | - : |
|
| 367 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | - ) { |
|
| 369 | - $statut = $champs['statut'] = $s; |
|
| 370 | - } else { |
|
| 371 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | - $statut = $champs['statut'] = $s; |
|
| 373 | - } else { |
|
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // En cas de publication, fixer la date a "maintenant" |
|
| 379 | - // sauf si $c commande autre chose |
|
| 380 | - // ou si l'objet est deja date dans le futur |
|
| 381 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | - if ($champ_date) { |
|
| 383 | - if ( |
|
| 384 | - $champs['statut'] == 'publie' |
|
| 385 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | - or $d |
|
| 387 | - ) { |
|
| 388 | - if ($d or strtotime($d = $date) > time()) { |
|
| 389 | - $champs[$champ_date] = $date = $d; |
|
| 390 | - } else { |
|
| 391 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Verifier que la rubrique demandee existe et est differente |
|
| 398 | - // de la rubrique actuelle |
|
| 399 | - if ( |
|
| 400 | - $id_rubrique |
|
| 401 | - and isset($c['id_parent']) |
|
| 402 | - and $id_parent = $c['id_parent'] |
|
| 403 | - and $id_parent != $id_rubrique |
|
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | - ) { |
|
| 406 | - $champs['id_rubrique'] = $id_parent; |
|
| 407 | - |
|
| 408 | - // si l'objet etait publie |
|
| 409 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | - // repasser l'objet en statut 'propose'. |
|
| 411 | - if ( |
|
| 412 | - $statut == 'publie' |
|
| 413 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | - ) { |
|
| 415 | - $champs['statut'] = 'prop'; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - // Envoyer aux plugins |
|
| 421 | - $champs = pipeline( |
|
| 422 | - 'pre_edition', |
|
| 423 | - [ |
|
| 424 | - 'args' => [ |
|
| 425 | - 'table' => $table_sql, |
|
| 426 | - 'id_objet' => $id, |
|
| 427 | - 'action' => 'instituer', |
|
| 428 | - 'statut_ancien' => $statut_ancien, |
|
| 429 | - 'date_ancienne' => $date_ancienne, |
|
| 430 | - 'id_parent_ancien' => $id_rubrique, |
|
| 431 | - ], |
|
| 432 | - 'data' => $champs |
|
| 433 | - ] |
|
| 434 | - ); |
|
| 435 | - |
|
| 436 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | - return ''; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // Envoyer les modifs. |
|
| 441 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | - |
|
| 443 | - // Invalider les caches |
|
| 444 | - include_spip('inc/invalideur'); |
|
| 445 | - suivre_invalideur("id='$objet/$id'"); |
|
| 446 | - |
|
| 447 | - /* |
|
| 316 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 318 | + $objet = $t; |
|
| 319 | + } |
|
| 320 | + if ( |
|
| 321 | + include_spip('action/editer_' . $objet) |
|
| 322 | + and function_exists($instituer = $objet . '_instituer') |
|
| 323 | + ) { |
|
| 324 | + return $instituer($id, $c, $calcul_rub); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $table_sql = table_objet_sql($objet); |
|
| 328 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 329 | + $desc = $trouver_table($table_sql); |
|
| 330 | + if (!$desc or !isset($desc['field'])) { |
|
| 331 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + include_spip('inc/autoriser'); |
|
| 335 | + include_spip('inc/rubriques'); |
|
| 336 | + include_spip('inc/modifier'); |
|
| 337 | + |
|
| 338 | + $sel = []; |
|
| 339 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 340 | + |
|
| 341 | + $champ_date = ''; |
|
| 342 | + if (isset($desc['date']) and $desc['date']) { |
|
| 343 | + $champ_date = $desc['date']; |
|
| 344 | + } elseif (isset($desc['field']['date'])) { |
|
| 345 | + $champ_date = 'date'; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 349 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 350 | + |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 352 | + |
|
| 353 | + $id_rubrique = $row['id_rubrique']; |
|
| 354 | + $statut_ancien = $statut = $row['statut']; |
|
| 355 | + $date_ancienne = $date = $row['date']; |
|
| 356 | + $champs = []; |
|
| 357 | + |
|
| 358 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 359 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 360 | + |
|
| 361 | + // cf autorisations dans inc/instituer_objet |
|
| 362 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 363 | + if ( |
|
| 364 | + $id_rubrique ? |
|
| 365 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 366 | + : |
|
| 367 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 368 | + ) { |
|
| 369 | + $statut = $champs['statut'] = $s; |
|
| 370 | + } else { |
|
| 371 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 372 | + $statut = $champs['statut'] = $s; |
|
| 373 | + } else { |
|
| 374 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // En cas de publication, fixer la date a "maintenant" |
|
| 379 | + // sauf si $c commande autre chose |
|
| 380 | + // ou si l'objet est deja date dans le futur |
|
| 381 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 382 | + if ($champ_date) { |
|
| 383 | + if ( |
|
| 384 | + $champs['statut'] == 'publie' |
|
| 385 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 386 | + or $d |
|
| 387 | + ) { |
|
| 388 | + if ($d or strtotime($d = $date) > time()) { |
|
| 389 | + $champs[$champ_date] = $date = $d; |
|
| 390 | + } else { |
|
| 391 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Verifier que la rubrique demandee existe et est differente |
|
| 398 | + // de la rubrique actuelle |
|
| 399 | + if ( |
|
| 400 | + $id_rubrique |
|
| 401 | + and isset($c['id_parent']) |
|
| 402 | + and $id_parent = $c['id_parent'] |
|
| 403 | + and $id_parent != $id_rubrique |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 405 | + ) { |
|
| 406 | + $champs['id_rubrique'] = $id_parent; |
|
| 407 | + |
|
| 408 | + // si l'objet etait publie |
|
| 409 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 410 | + // repasser l'objet en statut 'propose'. |
|
| 411 | + if ( |
|
| 412 | + $statut == 'publie' |
|
| 413 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 414 | + ) { |
|
| 415 | + $champs['statut'] = 'prop'; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + // Envoyer aux plugins |
|
| 421 | + $champs = pipeline( |
|
| 422 | + 'pre_edition', |
|
| 423 | + [ |
|
| 424 | + 'args' => [ |
|
| 425 | + 'table' => $table_sql, |
|
| 426 | + 'id_objet' => $id, |
|
| 427 | + 'action' => 'instituer', |
|
| 428 | + 'statut_ancien' => $statut_ancien, |
|
| 429 | + 'date_ancienne' => $date_ancienne, |
|
| 430 | + 'id_parent_ancien' => $id_rubrique, |
|
| 431 | + ], |
|
| 432 | + 'data' => $champs |
|
| 433 | + ] |
|
| 434 | + ); |
|
| 435 | + |
|
| 436 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 437 | + return ''; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // Envoyer les modifs. |
|
| 441 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 442 | + |
|
| 443 | + // Invalider les caches |
|
| 444 | + include_spip('inc/invalideur'); |
|
| 445 | + suivre_invalideur("id='$objet/$id'"); |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | if ($date) { |
| 449 | 449 | $t = strtotime($date); |
| 450 | 450 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -453,32 +453,32 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | }*/ |
| 455 | 455 | |
| 456 | - // Pipeline |
|
| 457 | - pipeline( |
|
| 458 | - 'post_edition', |
|
| 459 | - [ |
|
| 460 | - 'args' => [ |
|
| 461 | - 'table' => $table_sql, |
|
| 462 | - 'id_objet' => $id, |
|
| 463 | - 'action' => 'instituer', |
|
| 464 | - 'statut_ancien' => $statut_ancien, |
|
| 465 | - 'date_ancienne' => $date_ancienne, |
|
| 466 | - 'id_parent_ancien' => $id_rubrique, |
|
| 467 | - ], |
|
| 468 | - 'data' => $champs |
|
| 469 | - ] |
|
| 470 | - ); |
|
| 471 | - |
|
| 472 | - // Notifications |
|
| 473 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | - $notifications( |
|
| 475 | - "instituer$objet", |
|
| 476 | - $id, |
|
| 477 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return ''; // pas d'erreur |
|
| 456 | + // Pipeline |
|
| 457 | + pipeline( |
|
| 458 | + 'post_edition', |
|
| 459 | + [ |
|
| 460 | + 'args' => [ |
|
| 461 | + 'table' => $table_sql, |
|
| 462 | + 'id_objet' => $id, |
|
| 463 | + 'action' => 'instituer', |
|
| 464 | + 'statut_ancien' => $statut_ancien, |
|
| 465 | + 'date_ancienne' => $date_ancienne, |
|
| 466 | + 'id_parent_ancien' => $id_rubrique, |
|
| 467 | + ], |
|
| 468 | + 'data' => $champs |
|
| 469 | + ] |
|
| 470 | + ); |
|
| 471 | + |
|
| 472 | + // Notifications |
|
| 473 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 474 | + $notifications( |
|
| 475 | + "instituer$objet", |
|
| 476 | + $id, |
|
| 477 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return ''; // pas d'erreur |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -493,51 +493,51 @@ discard block |
||
| 493 | 493 | * @return void |
| 494 | 494 | */ |
| 495 | 495 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 496 | - $table_sql = table_objet_sql($objet); |
|
| 497 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | - $desc = $trouver_table($table_sql); |
|
| 499 | - |
|
| 500 | - // Si on deplace l'objet |
|
| 501 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | - if (isset($champs['id_rubrique'])) { |
|
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | - $langue = $row_rub['lang']; |
|
| 505 | - |
|
| 506 | - if (isset($desc['field']['id_secteur'])) { |
|
| 507 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | - if ( |
|
| 512 | - sql_fetsel( |
|
| 513 | - '1', |
|
| 514 | - $table_sql, |
|
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | - ) |
|
| 517 | - ) { |
|
| 518 | - $champs['lang'] = $langue; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if (!$champs) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | - |
|
| 528 | - // Changer le statut des rubriques concernees |
|
| 529 | - if ($cond) { |
|
| 530 | - include_spip('inc/rubriques'); |
|
| 531 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | - $postdate = false; |
|
| 533 | - // On rajoute les infos de l'objet |
|
| 534 | - $infos = [ |
|
| 535 | - 'objet' => $objet, |
|
| 536 | - 'id_objet' => $id, |
|
| 537 | - 'statut_ancien' => $statut, |
|
| 538 | - ]; |
|
| 539 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | - } |
|
| 496 | + $table_sql = table_objet_sql($objet); |
|
| 497 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 498 | + $desc = $trouver_table($table_sql); |
|
| 499 | + |
|
| 500 | + // Si on deplace l'objet |
|
| 501 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 502 | + if (isset($champs['id_rubrique'])) { |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 504 | + $langue = $row_rub['lang']; |
|
| 505 | + |
|
| 506 | + if (isset($desc['field']['id_secteur'])) { |
|
| 507 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 511 | + if ( |
|
| 512 | + sql_fetsel( |
|
| 513 | + '1', |
|
| 514 | + $table_sql, |
|
| 515 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 516 | + ) |
|
| 517 | + ) { |
|
| 518 | + $champs['lang'] = $langue; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if (!$champs) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 527 | + |
|
| 528 | + // Changer le statut des rubriques concernees |
|
| 529 | + if ($cond) { |
|
| 530 | + include_spip('inc/rubriques'); |
|
| 531 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 532 | + $postdate = false; |
|
| 533 | + // On rajoute les infos de l'objet |
|
| 534 | + $infos = [ |
|
| 535 | + 'objet' => $objet, |
|
| 536 | + 'id_objet' => $id, |
|
| 537 | + 'statut_ancien' => $statut, |
|
| 538 | + ]; |
|
| 539 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 540 | + } |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | |
@@ -566,75 +566,75 @@ discard block |
||
| 566 | 566 | * string|int : valeur du champ demande pour l'objet demande |
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | - $objet = $t; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | - static $descriptions = []; |
|
| 577 | - |
|
| 578 | - // On détermine le nom du champ id de la table. |
|
| 579 | - include_spip('base/objets'); |
|
| 580 | - $primary = id_table_objet($objet); |
|
| 581 | - |
|
| 582 | - // On détermine l'id à utiliser. |
|
| 583 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | - |
|
| 585 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | - if ( |
|
| 587 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | - or (isset($options['force']) and $options['force']) |
|
| 589 | - ) { |
|
| 590 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | - if ( |
|
| 592 | - include_spip('action/editer_' . $objet) |
|
| 593 | - and function_exists($lire = "{$objet}_lire_champs") |
|
| 594 | - ) { |
|
| 595 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | - } else { |
|
| 597 | - // On récupère la table SQL à partir du type d'objet. |
|
| 598 | - $table = table_objet_sql($objet); |
|
| 599 | - |
|
| 600 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | - $where = [ |
|
| 602 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 603 | - ]; |
|
| 604 | - |
|
| 605 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - if (!$valeurs) { |
|
| 610 | - $valeurs = false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | - |
|
| 615 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | - |
|
| 623 | - // On ne retourne maintenant que les champs demandés. |
|
| 624 | - // - on détermine les informations à renvoyer. |
|
| 625 | - if ($retour and !empty($options['champs'])) { |
|
| 626 | - $champs = $options['champs']; |
|
| 627 | - // Extraction des seules informations demandées. |
|
| 628 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | - if (is_array($champs)) { |
|
| 631 | - // Tableau des informations valides |
|
| 632 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | - } else { |
|
| 634 | - // Valeur unique demandée. |
|
| 635 | - $retour = ($retour[$champs] ?? false); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - return $retour; |
|
| 569 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 571 | + $objet = $t; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 575 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 576 | + static $descriptions = []; |
|
| 577 | + |
|
| 578 | + // On détermine le nom du champ id de la table. |
|
| 579 | + include_spip('base/objets'); |
|
| 580 | + $primary = id_table_objet($objet); |
|
| 581 | + |
|
| 582 | + // On détermine l'id à utiliser. |
|
| 583 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 584 | + |
|
| 585 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 586 | + if ( |
|
| 587 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 588 | + or (isset($options['force']) and $options['force']) |
|
| 589 | + ) { |
|
| 590 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 591 | + if ( |
|
| 592 | + include_spip('action/editer_' . $objet) |
|
| 593 | + and function_exists($lire = "{$objet}_lire_champs") |
|
| 594 | + ) { |
|
| 595 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 596 | + } else { |
|
| 597 | + // On récupère la table SQL à partir du type d'objet. |
|
| 598 | + $table = table_objet_sql($objet); |
|
| 599 | + |
|
| 600 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 601 | + $where = [ |
|
| 602 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 603 | + ]; |
|
| 604 | + |
|
| 605 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 606 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + if (!$valeurs) { |
|
| 610 | + $valeurs = false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 614 | + |
|
| 615 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 616 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 617 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 622 | + |
|
| 623 | + // On ne retourne maintenant que les champs demandés. |
|
| 624 | + // - on détermine les informations à renvoyer. |
|
| 625 | + if ($retour and !empty($options['champs'])) { |
|
| 626 | + $champs = $options['champs']; |
|
| 627 | + // Extraction des seules informations demandées. |
|
| 628 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 629 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 630 | + if (is_array($champs)) { |
|
| 631 | + // Tableau des informations valides |
|
| 632 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 633 | + } else { |
|
| 634 | + // Valeur unique demandée. |
|
| 635 | + $retour = ($retour[$champs] ?? false); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + return $retour; |
|
| 640 | 640 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base{$subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base{$subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = ''; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = ''; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,89 +79,89 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | - if ($position < 0) { |
|
| 112 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | - } |
|
| 114 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | - + [ |
|
| 116 | - $id => new Bouton( |
|
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 119 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | - ) |
|
| 122 | - ] |
|
| 123 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | - } |
|
| 125 | - if ( |
|
| 126 | - !$parent |
|
| 127 | - // provisoire, eviter les vieux boutons |
|
| 128 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | - ) { |
|
| 131 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | - + [ |
|
| 134 | - $id => new Bouton( |
|
| 135 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | - $infos['titre'], // titre |
|
| 137 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | - ) |
|
| 140 | - ] |
|
| 141 | - + array_slice($boutons_admin, $position, 100); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | + if ($position < 0) { |
|
| 112 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | + } |
|
| 114 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | + + [ |
|
| 116 | + $id => new Bouton( |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | + ) |
|
| 122 | + ] |
|
| 123 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | + } |
|
| 125 | + if ( |
|
| 126 | + !$parent |
|
| 127 | + // provisoire, eviter les vieux boutons |
|
| 128 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | + ) { |
|
| 131 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | + + [ |
|
| 134 | + $id => new Bouton( |
|
| 135 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | + $infos['titre'], // titre |
|
| 137 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | + ) |
|
| 140 | + ] |
|
| 141 | + + array_slice($boutons_admin, $position, 100); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 146 | 146 | |
| 147 | - // définir les favoris et positions d’origine |
|
| 148 | - if ($boutons_admin) { |
|
| 149 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | - $i = 1; |
|
| 151 | - foreach ($boutons_admin as $key => $menu) { |
|
| 152 | - $menu->favori = (bool) table_valeur($menus_favoris, $key, false); |
|
| 153 | - $menu->position = $i++; |
|
| 154 | - if ($menu->sousmenu) { |
|
| 155 | - $j = 1; |
|
| 156 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | - $bouton->favori = (bool) table_valeur($menus_favoris, $key, false); |
|
| 158 | - $bouton->position = $j++; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 147 | + // définir les favoris et positions d’origine |
|
| 148 | + if ($boutons_admin) { |
|
| 149 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | + $i = 1; |
|
| 151 | + foreach ($boutons_admin as $key => $menu) { |
|
| 152 | + $menu->favori = (bool) table_valeur($menus_favoris, $key, false); |
|
| 153 | + $menu->position = $i++; |
|
| 154 | + if ($menu->sousmenu) { |
|
| 155 | + $j = 1; |
|
| 156 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | + $bouton->favori = (bool) table_valeur($menus_favoris, $key, false); |
|
| 158 | + $bouton->position = $j++; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $boutons_admin; |
|
| 164 | + return $boutons_admin; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return Bouton[] |
| 174 | 174 | */ |
| 175 | 175 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 176 | - foreach ($menus as $menu) { |
|
| 177 | - if ($menu->sousmenu) { |
|
| 178 | - $libelles = $isfavoris = $favoris = []; |
|
| 179 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | - $isfavoris[$key] = $item->favori; |
|
| 182 | - $favoris[$key] = $item->favori; |
|
| 183 | - } |
|
| 184 | - if ($avec_favoris) { |
|
| 185 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | - } else { |
|
| 187 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - return $menus; |
|
| 176 | + foreach ($menus as $menu) { |
|
| 177 | + if ($menu->sousmenu) { |
|
| 178 | + $libelles = $isfavoris = $favoris = []; |
|
| 179 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | + $isfavoris[$key] = $item->favori; |
|
| 182 | + $favoris[$key] = $item->favori; |
|
| 183 | + } |
|
| 184 | + if ($avec_favoris) { |
|
| 185 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | + } else { |
|
| 187 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + return $menus; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Bouton[] |
| 200 | 200 | */ |
| 201 | 201 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 202 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 202 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -212,23 +212,23 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 215 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | - $url = generer_url_ecrire($url, $args, true); |
|
| 217 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | - // &truc=@machin@ |
|
| 219 | - // @machin@ etant remplace par _request('machin') |
|
| 220 | - $url = str_replace('&', '&', $url); |
|
| 221 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | - } |
|
| 225 | - $val = _request($matches[2], $contexte); |
|
| 226 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | - } |
|
| 228 | - $url = str_replace('&', '&', $url); |
|
| 229 | - } |
|
| 215 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | + $url = generer_url_ecrire($url, $args, true); |
|
| 217 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | + // &truc=@machin@ |
|
| 219 | + // @machin@ etant remplace par _request('machin') |
|
| 220 | + $url = str_replace('&', '&', $url); |
|
| 221 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | + } |
|
| 225 | + $val = _request($matches[2], $contexte); |
|
| 226 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | + } |
|
| 228 | + $url = str_replace('&', '&', $url); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - return $url; |
|
| 231 | + return $url; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * Code HTML du bandeau |
| 239 | 239 | */ |
| 240 | 240 | function inc_bandeau_dist() { |
| 241 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 241 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | function obtenir_menus_favoris() { |
| 250 | - if ( |
|
| 251 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | - ) { |
|
| 255 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | - } |
|
| 257 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | - return $definir_menus_favoris(); |
|
| 250 | + if ( |
|
| 251 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | + ) { |
|
| 255 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | + } |
|
| 257 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | + return $definir_menus_favoris(); |
|
| 259 | 259 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -25,58 +25,58 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** L'icone à mettre dans le bouton */ |
|
| 29 | - public string $icone; |
|
| 30 | - |
|
| 31 | - /** Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public string $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** Sous-barre de boutons / onglets */ |
|
| 47 | - public array $sousmenu = []; |
|
| 48 | - |
|
| 49 | - /** Position dans le menu */ |
|
| 50 | - public int $position = 0; |
|
| 51 | - |
|
| 52 | - /** Entrée favorite ? */ |
|
| 53 | - public bool $favori = false; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Définit un bouton |
|
| 58 | - * |
|
| 59 | - * @param string $icone |
|
| 60 | - * L'icone à mettre dans le bouton |
|
| 61 | - * @param string $libelle |
|
| 62 | - * Le nom de l'entrée i18n associé |
|
| 63 | - * @param null|string $url |
|
| 64 | - * L'URL de la page |
|
| 65 | - * @param null|string|array $urlArg |
|
| 66 | - * Arguments supplémentaires de l'URL |
|
| 67 | - * @param null|string $url2 |
|
| 68 | - * URL du javascript |
|
| 69 | - * @param null|mixed $target |
|
| 70 | - * Pour ouvrir une fenêtre à part |
|
| 71 | - */ |
|
| 72 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 73 | - $this->icone = $icone; |
|
| 74 | - $this->libelle = $libelle; |
|
| 75 | - $this->url = $url; |
|
| 76 | - $this->urlArg = $urlArg; |
|
| 77 | - $this->url2 = $url2; |
|
| 78 | - $this->target = $target; |
|
| 79 | - } |
|
| 28 | + /** L'icone à mettre dans le bouton */ |
|
| 29 | + public string $icone; |
|
| 30 | + |
|
| 31 | + /** Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public string $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** Sous-barre de boutons / onglets */ |
|
| 47 | + public array $sousmenu = []; |
|
| 48 | + |
|
| 49 | + /** Position dans le menu */ |
|
| 50 | + public int $position = 0; |
|
| 51 | + |
|
| 52 | + /** Entrée favorite ? */ |
|
| 53 | + public bool $favori = false; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Définit un bouton |
|
| 58 | + * |
|
| 59 | + * @param string $icone |
|
| 60 | + * L'icone à mettre dans le bouton |
|
| 61 | + * @param string $libelle |
|
| 62 | + * Le nom de l'entrée i18n associé |
|
| 63 | + * @param null|string $url |
|
| 64 | + * L'URL de la page |
|
| 65 | + * @param null|string|array $urlArg |
|
| 66 | + * Arguments supplémentaires de l'URL |
|
| 67 | + * @param null|string $url2 |
|
| 68 | + * URL du javascript |
|
| 69 | + * @param null|mixed $target |
|
| 70 | + * Pour ouvrir une fenêtre à part |
|
| 71 | + */ |
|
| 72 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 73 | + $this->icone = $icone; |
|
| 74 | + $this->libelle = $libelle; |
|
| 75 | + $this->url = $url; |
|
| 76 | + $this->urlArg = $urlArg; |
|
| 77 | + $this->url2 = $url2; |
|
| 78 | + $this->target = $target; |
|
| 79 | + } |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -93,35 +93,35 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | function definir_barre_onglets($script) { |
| 95 | 95 | |
| 96 | - $onglets = []; |
|
| 97 | - $liste_onglets = []; |
|
| 98 | - |
|
| 99 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 100 | - if (function_exists('onglets_plugins')) { |
|
| 101 | - $liste_onglets = onglets_plugins(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - foreach ($liste_onglets as $id => $infos) { |
|
| 106 | - if ( |
|
| 107 | - ($parent = $infos['parent']) |
|
| 108 | - && $parent == $script |
|
| 109 | - && autoriser('onglet', "_$id") |
|
| 110 | - ) { |
|
| 111 | - $onglets[$id] = new Bouton( |
|
| 112 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 113 | - $infos['titre'], // titre |
|
| 114 | - (isset($infos['action']) and $infos['action']) |
|
| 115 | - ? generer_url_ecrire( |
|
| 116 | - $infos['action'], |
|
| 117 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 118 | - ) |
|
| 119 | - : null |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 96 | + $onglets = []; |
|
| 97 | + $liste_onglets = []; |
|
| 98 | + |
|
| 99 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 100 | + if (function_exists('onglets_plugins')) { |
|
| 101 | + $liste_onglets = onglets_plugins(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + foreach ($liste_onglets as $id => $infos) { |
|
| 106 | + if ( |
|
| 107 | + ($parent = $infos['parent']) |
|
| 108 | + && $parent == $script |
|
| 109 | + && autoriser('onglet', "_$id") |
|
| 110 | + ) { |
|
| 111 | + $onglets[$id] = new Bouton( |
|
| 112 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 113 | + $infos['titre'], // titre |
|
| 114 | + (isset($infos['action']) and $infos['action']) |
|
| 115 | + ? generer_url_ecrire( |
|
| 116 | + $infos['action'], |
|
| 117 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 118 | + ) |
|
| 119 | + : null |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -140,14 +140,14 @@ discard block |
||
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | 142 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 143 | - include_spip('inc/presentation'); |
|
| 143 | + include_spip('inc/presentation'); |
|
| 144 | 144 | |
| 145 | - $res = ''; |
|
| 145 | + $res = ''; |
|
| 146 | 146 | |
| 147 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 148 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 149 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 150 | - } |
|
| 147 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 148 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 149 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 152 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 153 | 153 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | - } else { |
|
| 45 | - if (is_array($liste_langues)) { |
|
| 46 | - $liste_langues = implode(',', $liste_langues); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | - |
|
| 51 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | - if (!$lang) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 62 | - ) { |
|
| 63 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | - |
|
| 67 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | + } else { |
|
| 45 | + if (is_array($liste_langues)) { |
|
| 46 | + $liste_langues = implode(',', $liste_langues); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + |
|
| 51 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | + if (!$lang) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 62 | + ) { |
|
| 63 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | + |
|
| 67 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 81 | 81 | |
| 82 | 82 | function choisir_traduction($trads, $lang = '') { |
| 83 | - $k = approcher_langue($trads, $lang); |
|
| 83 | + $k = approcher_langue($trads, $lang); |
|
| 84 | 84 | |
| 85 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // retourne son 2e argument si c'est un index du premier |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | // la langue X etant consideree comme une approche de X_Y |
| 91 | 91 | function approcher_langue($trads, $lang = '') { |
| 92 | 92 | |
| 93 | - if (!$lang) { |
|
| 94 | - $lang = $GLOBALS['spip_lang']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (isset($trads[$lang])) { |
|
| 98 | - return $lang; |
|
| 99 | - } // cas des langues xx_yy |
|
| 100 | - else { |
|
| 101 | - $r = explode('_', $lang); |
|
| 102 | - if (isset($trads[$r[0]])) { |
|
| 103 | - return $r[0]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return ''; |
|
| 93 | + if (!$lang) { |
|
| 94 | + $lang = $GLOBALS['spip_lang']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (isset($trads[$lang])) { |
|
| 98 | + return $lang; |
|
| 99 | + } // cas des langues xx_yy |
|
| 100 | + else { |
|
| 101 | + $r = explode('_', $lang); |
|
| 102 | + if (isset($trads[$r[0]])) { |
|
| 103 | + return $r[0]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * Nom de la langue, sinon son code. |
| 120 | 120 | **/ |
| 121 | 121 | function traduire_nom_langue($lang) { |
| 122 | - include_spip('inc/lang_liste'); |
|
| 123 | - include_spip('inc/charsets'); |
|
| 122 | + include_spip('inc/lang_liste'); |
|
| 123 | + include_spip('inc/charsets'); |
|
| 124 | 124 | |
| 125 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | // hebreu a priori), 'droitier' sinon. |
| 136 | 136 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 137 | 137 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 138 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | 139 | |
| 140 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | - $gaucher : $droitier; |
|
| 140 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | + $gaucher : $droitier; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // typo francaise ou anglaise ? |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | // sinon determiner la typo en fonction de la langue courante |
| 148 | 148 | |
| 149 | 149 | function lang_typo($lang = '') { |
| 150 | - if (!$lang) { |
|
| 151 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | - } |
|
| 153 | - if ( |
|
| 154 | - $lang == 'eo' |
|
| 155 | - or $lang == 'fr' |
|
| 156 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | - or $lang == 'cpf' |
|
| 158 | - ) { |
|
| 159 | - return 'fr'; |
|
| 160 | - } else { |
|
| 161 | - return 'en'; |
|
| 162 | - } |
|
| 150 | + if (!$lang) { |
|
| 151 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | + } |
|
| 153 | + if ( |
|
| 154 | + $lang == 'eo' |
|
| 155 | + or $lang == 'fr' |
|
| 156 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | + or $lang == 'cpf' |
|
| 158 | + ) { |
|
| 159 | + return 'fr'; |
|
| 160 | + } else { |
|
| 161 | + return 'en'; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 166 | 166 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 167 | 167 | function changer_typo($lang = '') { |
| 168 | - if ($lang) { |
|
| 169 | - $GLOBALS['lang_objet'] = $lang; |
|
| 170 | - } else { |
|
| 171 | - unset($GLOBALS['lang_objet']); |
|
| 172 | - } |
|
| 168 | + if ($lang) { |
|
| 169 | + $GLOBALS['lang_objet'] = $lang; |
|
| 170 | + } else { |
|
| 171 | + unset($GLOBALS['lang_objet']); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // |
@@ -179,58 +179,58 @@ discard block |
||
| 179 | 179 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 180 | 180 | // |
| 181 | 181 | function menu_langues($nom_select, $default = '') { |
| 182 | - include_spip('inc/actions'); |
|
| 183 | - |
|
| 184 | - $langues = liste_options_langues($nom_select); |
|
| 185 | - $ret = ''; |
|
| 186 | - if (!count($langues)) { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$default) { |
|
| 191 | - $default = $GLOBALS['spip_lang']; |
|
| 192 | - } |
|
| 193 | - foreach ($langues as $l) { |
|
| 194 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (!test_espace_prive()) { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = ''; |
|
| 201 | - } else { |
|
| 202 | - $cible = self(); |
|
| 203 | - $base = spip_connect() ? 'base' : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | - |
|
| 208 | - return generer_action_auteur( |
|
| 209 | - 'converser', |
|
| 210 | - $base, |
|
| 211 | - $cible, |
|
| 212 | - (select_langues($nom_select, $change, $ret) |
|
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | - " method='post'" |
|
| 215 | - ); |
|
| 182 | + include_spip('inc/actions'); |
|
| 183 | + |
|
| 184 | + $langues = liste_options_langues($nom_select); |
|
| 185 | + $ret = ''; |
|
| 186 | + if (!count($langues)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$default) { |
|
| 191 | + $default = $GLOBALS['spip_lang']; |
|
| 192 | + } |
|
| 193 | + foreach ($langues as $l) { |
|
| 194 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (!test_espace_prive()) { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = ''; |
|
| 201 | + } else { |
|
| 202 | + $cible = self(); |
|
| 203 | + $base = spip_connect() ? 'base' : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | + |
|
| 208 | + return generer_action_auteur( |
|
| 209 | + 'converser', |
|
| 210 | + $base, |
|
| 211 | + $cible, |
|
| 212 | + (select_langues($nom_select, $change, $ret) |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | + " method='post'" |
|
| 215 | + ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | - static $cpt = 0; |
|
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 221 | - |
|
| 222 | - return |
|
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | - "<select name='$nom_select' id='$id' " |
|
| 225 | - . ((!test_espace_prive()) ? |
|
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 230 | - . $change |
|
| 231 | - . ">\n" |
|
| 232 | - . $options |
|
| 233 | - . '</select>'; |
|
| 219 | + static $cpt = 0; |
|
| 220 | + $id = 'menu_langues' . $cpt++; |
|
| 221 | + |
|
| 222 | + return |
|
| 223 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | + "<select name='$nom_select' id='$id' " |
|
| 225 | + . ((!test_espace_prive()) ? |
|
| 226 | + ("class='forml menu_langues'") : |
|
| 227 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | + ("class='lang_ecrire'") : |
|
| 229 | + "class='fondl'")) |
|
| 230 | + . $change |
|
| 231 | + . ">\n" |
|
| 232 | + . $options |
|
| 233 | + . '</select>'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function liste_options_langues($nom_select) { |
| 254 | 254 | |
| 255 | - switch ($nom_select) { |
|
| 256 | - # #MENU_LANG |
|
| 257 | - case 'var_lang': |
|
| 258 | - # menu de changement de la langue d'un article |
|
| 259 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | - case 'changer_lang': |
|
| 261 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | - break; |
|
| 263 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | - # les langues presentes sous forme de fichiers de langue |
|
| 265 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | - case 'var_lang_ecrire': |
|
| 267 | - default: |
|
| 268 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | - init_langues(); |
|
| 270 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | - break; |
|
| 255 | + switch ($nom_select) { |
|
| 256 | + # #MENU_LANG |
|
| 257 | + case 'var_lang': |
|
| 258 | + # menu de changement de la langue d'un article |
|
| 259 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | + case 'changer_lang': |
|
| 261 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | + break; |
|
| 263 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | + # les langues presentes sous forme de fichiers de langue |
|
| 265 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | + case 'var_lang_ecrire': |
|
| 267 | + default: |
|
| 268 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | + init_langues(); |
|
| 270 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | + break; |
|
| 272 | 272 | |
| 273 | 273 | # dernier choix possible : toutes les langues = langues_proposees |
| 274 | 274 | # + langues_multilingues ; mais, ne sert pas |
| 275 | 275 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 276 | - } |
|
| 277 | - if (count($langues) <= 1) { |
|
| 278 | - return []; |
|
| 279 | - } |
|
| 280 | - sort($langues); |
|
| 276 | + } |
|
| 277 | + if (count($langues) <= 1) { |
|
| 278 | + return []; |
|
| 279 | + } |
|
| 280 | + sort($langues); |
|
| 281 | 281 | |
| 282 | - return $langues; |
|
| 282 | + return $langues; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -294,39 +294,39 @@ discard block |
||
| 294 | 294 | **/ |
| 295 | 295 | function verifier_lang_url() { |
| 296 | 296 | |
| 297 | - // quelle langue est demandee ? |
|
| 298 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | - } |
|
| 302 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | - } |
|
| 305 | - if (isset($_GET['lang'])) { |
|
| 306 | - $lang_demandee = $_GET['lang']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | - if ( |
|
| 311 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | - and changer_langue($lang_demandee) |
|
| 313 | - and $lang_demandee != @$_GET['lang'] |
|
| 314 | - ) { |
|
| 315 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | - // ici on a besoin des var_truc |
|
| 317 | - foreach ($_GET as $var => $val) { |
|
| 318 | - if (!strncmp('var_', $var, 4)) { |
|
| 319 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - include_spip('inc/headers'); |
|
| 323 | - redirige_par_entete($destination); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | - // (pour criteres {lang}). |
|
| 329 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 297 | + // quelle langue est demandee ? |
|
| 298 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | + } |
|
| 302 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | + } |
|
| 305 | + if (isset($_GET['lang'])) { |
|
| 306 | + $lang_demandee = $_GET['lang']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | + if ( |
|
| 311 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | + and changer_langue($lang_demandee) |
|
| 313 | + and $lang_demandee != @$_GET['lang'] |
|
| 314 | + ) { |
|
| 315 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | + // ici on a besoin des var_truc |
|
| 317 | + foreach ($_GET as $var => $val) { |
|
| 318 | + if (!strncmp('var_', $var, 4)) { |
|
| 319 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + include_spip('inc/headers'); |
|
| 323 | + redirige_par_entete($destination); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | + // (pour criteres {lang}). |
|
| 329 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,22 +344,22 @@ discard block |
||
| 344 | 344 | * La langue sélectionnée |
| 345 | 345 | **/ |
| 346 | 346 | function utiliser_langue_site($liste_langues = null) { |
| 347 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | - if ( |
|
| 349 | - isset($GLOBALS['meta']['langue_site']) |
|
| 350 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | - and (!isset($GLOBALS['spip_lang']) |
|
| 353 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | - ) { |
|
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | - } |
|
| 357 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $GLOBALS['spip_lang']; |
|
| 347 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | + if ( |
|
| 349 | + isset($GLOBALS['meta']['langue_site']) |
|
| 350 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | + and (!isset($GLOBALS['spip_lang']) |
|
| 353 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | + ) { |
|
| 355 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | + } |
|
| 357 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $GLOBALS['spip_lang']; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,30 +378,30 @@ discard block |
||
| 378 | 378 | **/ |
| 379 | 379 | function utiliser_langue_visiteur($liste_langues = null) { |
| 380 | 380 | |
| 381 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 382 | - if (isset($_COOKIE[$l])) { |
|
| 383 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 384 | - return $l; |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 389 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 390 | - return $l; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 397 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 398 | - return $l; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return utiliser_langue_site($liste_langues); |
|
| 381 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 382 | + if (isset($_COOKIE[$l])) { |
|
| 383 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 384 | + return $l; |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 389 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 390 | + return $l; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 397 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 398 | + return $l; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return utiliser_langue_site($liste_langues); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @return int |
| 412 | 412 | */ |
| 413 | 413 | function match_langue($chaine) { |
| 414 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 414 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -429,36 +429,36 @@ discard block |
||
| 429 | 429 | **/ |
| 430 | 430 | function init_langues() { |
| 431 | 431 | |
| 432 | - // liste des langues dans les meta, sauf a l'install |
|
| 433 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 434 | - |
|
| 435 | - $tout = []; |
|
| 436 | - if (!$all_langs) { |
|
| 437 | - // trouver tous les modules lang/spip_xx.php |
|
| 438 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 439 | - foreach ($modules as $name => $path) { |
|
| 440 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 441 | - if (match_langue($regs[1])) { |
|
| 442 | - $tout[] = $regs[1]; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - sort($tout); |
|
| 447 | - $tout = join(',', $tout); |
|
| 448 | - // Si les langues n'ont pas change, ne rien faire |
|
| 449 | - if ($tout != $all_langs) { |
|
| 450 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 451 | - include_spip('inc/meta'); |
|
| 452 | - ecrire_meta('langues_proposees', $tout); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 456 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 457 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 458 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 459 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 460 | - ecrire_meta('langue_site', $tout); |
|
| 461 | - } |
|
| 432 | + // liste des langues dans les meta, sauf a l'install |
|
| 433 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 434 | + |
|
| 435 | + $tout = []; |
|
| 436 | + if (!$all_langs) { |
|
| 437 | + // trouver tous les modules lang/spip_xx.php |
|
| 438 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 439 | + foreach ($modules as $name => $path) { |
|
| 440 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 441 | + if (match_langue($regs[1])) { |
|
| 442 | + $tout[] = $regs[1]; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + sort($tout); |
|
| 447 | + $tout = join(',', $tout); |
|
| 448 | + // Si les langues n'ont pas change, ne rien faire |
|
| 449 | + if ($tout != $all_langs) { |
|
| 450 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 451 | + include_spip('inc/meta'); |
|
| 452 | + ecrire_meta('langues_proposees', $tout); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 456 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 457 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 458 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 459 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 460 | + ecrire_meta('langue_site', $tout); |
|
| 461 | + } |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -472,10 +472,10 @@ discard block |
||
| 472 | 472 | * Code html de la balise <html> |
| 473 | 473 | **/ |
| 474 | 474 | function html_lang_attributes() { |
| 475 | - $lang = $GLOBALS['spip_lang']; |
|
| 476 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 475 | + $lang = $GLOBALS['spip_lang']; |
|
| 476 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 477 | 477 | |
| 478 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 478 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * @return string |
| 490 | 490 | */ |
| 491 | 491 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 492 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 492 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,33 +77,33 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - if (is_callable($f)) { |
|
| 102 | - return $f; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + if (is_callable($f)) { |
|
| 102 | + return $f; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $default; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * Chaîne vide sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function appliquer_filtre($arg, $filtre) { |
| 150 | - $args = func_get_args(); |
|
| 151 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 150 | + $args = func_get_args(); |
|
| 151 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * Texte d'origine sinon |
| 174 | 174 | **/ |
| 175 | 175 | function appliquer_si_filtre($arg, $filtre) { |
| 176 | - $args = func_get_args(); |
|
| 177 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 176 | + $args = func_get_args(); |
|
| 177 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * Version de SPIP |
| 191 | 191 | **/ |
| 192 | 192 | function spip_version() { |
| 193 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | - $version .= " $vcs_version"; |
|
| 196 | - } |
|
| 193 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | + $version .= " $vcs_version"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return $version; |
|
| 198 | + return $version; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | 209 | function header_silencieux($version): string { |
| 210 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | - $version = ''; |
|
| 212 | - } |
|
| 210 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | + $version = ''; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return (string) $version; |
|
| 214 | + return (string) $version; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -224,19 +224,19 @@ discard block |
||
| 224 | 224 | * - string|null si $raw = false |
| 225 | 225 | */ |
| 226 | 226 | function version_vcs_courante($dir, $raw = false) { |
| 227 | - $desc = decrire_version_git($dir); |
|
| 228 | - if ($desc === null) { |
|
| 229 | - $desc = decrire_version_svn($dir); |
|
| 230 | - } |
|
| 231 | - if ($desc === null or $raw) { |
|
| 232 | - return $desc; |
|
| 233 | - } |
|
| 234 | - // affichage "GIT [master: abcdef]" |
|
| 235 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | - if ($desc['branch']) { |
|
| 237 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | - } |
|
| 239 | - return "{$desc['vcs']} [$commit]"; |
|
| 227 | + $desc = decrire_version_git($dir); |
|
| 228 | + if ($desc === null) { |
|
| 229 | + $desc = decrire_version_svn($dir); |
|
| 230 | + } |
|
| 231 | + if ($desc === null or $raw) { |
|
| 232 | + return $desc; |
|
| 233 | + } |
|
| 234 | + // affichage "GIT [master: abcdef]" |
|
| 235 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | + if ($desc['branch']) { |
|
| 237 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | + } |
|
| 239 | + return "{$desc['vcs']} [$commit]"; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -248,24 +248,24 @@ discard block |
||
| 248 | 248 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function decrire_version_git($dir) { |
| 251 | - if (!$dir) { |
|
| 252 | - $dir = '.'; |
|
| 253 | - } |
|
| 251 | + if (!$dir) { |
|
| 252 | + $dir = '.'; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // version installee par GIT |
|
| 256 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | - $currentHead = trim(substr($c, 4)); |
|
| 258 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | - return [ |
|
| 260 | - 'vcs' => 'GIT', |
|
| 261 | - 'branch' => basename($currentHead), |
|
| 262 | - 'commit' => trim($hash), |
|
| 263 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | - ]; |
|
| 265 | - } |
|
| 266 | - } |
|
| 255 | + // version installee par GIT |
|
| 256 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | + $currentHead = trim(substr($c, 4)); |
|
| 258 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | + return [ |
|
| 260 | + 'vcs' => 'GIT', |
|
| 261 | + 'branch' => basename($currentHead), |
|
| 262 | + 'commit' => trim($hash), |
|
| 263 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | + ]; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return null; |
|
| 268 | + return null; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -278,25 +278,25 @@ discard block |
||
| 278 | 278 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 279 | 279 | **/ |
| 280 | 280 | function decrire_version_svn($dir) { |
| 281 | - if (!$dir) { |
|
| 282 | - $dir = '.'; |
|
| 283 | - } |
|
| 284 | - // version installee par SVN |
|
| 285 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | - if ($result) { |
|
| 289 | - $row = $result->fetchArray(); |
|
| 290 | - if ($row['changed_revision'] != '') { |
|
| 291 | - return [ |
|
| 292 | - 'vcs' => 'SVN', |
|
| 293 | - 'branch' => '', |
|
| 294 | - 'commit' => $row['changed_revision'], |
|
| 295 | - ]; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - return null; |
|
| 281 | + if (!$dir) { |
|
| 282 | + $dir = '.'; |
|
| 283 | + } |
|
| 284 | + // version installee par SVN |
|
| 285 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | + if ($result) { |
|
| 289 | + $row = $result->fetchArray(); |
|
| 290 | + if ($row['changed_revision'] != '') { |
|
| 291 | + return [ |
|
| 292 | + 'vcs' => 'SVN', |
|
| 293 | + 'branch' => '', |
|
| 294 | + 'commit' => $row['changed_revision'], |
|
| 295 | + ]; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + return null; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -343,18 +343,18 @@ discard block |
||
| 343 | 343 | * Code HTML retourné par le filtre |
| 344 | 344 | **/ |
| 345 | 345 | function filtrer($filtre) { |
| 346 | - $tous = func_get_args(); |
|
| 347 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | - return image_filtrer($tous); |
|
| 349 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | - array_shift($tous); |
|
| 351 | - return $f(...$tous); |
|
| 352 | - } else { |
|
| 353 | - // le filtre n'existe pas, on provoque une erreur |
|
| 354 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | - erreur_squelette($msg); |
|
| 356 | - return ''; |
|
| 357 | - } |
|
| 346 | + $tous = func_get_args(); |
|
| 347 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | + return image_filtrer($tous); |
|
| 349 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | + array_shift($tous); |
|
| 351 | + return $f(...$tous); |
|
| 352 | + } else { |
|
| 353 | + // le filtre n'existe pas, on provoque une erreur |
|
| 354 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | + erreur_squelette($msg); |
|
| 356 | + return ''; |
|
| 357 | + } |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 372 | 372 | */ |
| 373 | 373 | function trouver_filtre_matrice($filtre) { |
| 374 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | - find_in_path($f, '', true); |
|
| 376 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | - } |
|
| 378 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 374 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | + find_in_path($f, '', true); |
|
| 376 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | + } |
|
| 378 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * @return mixed |
| 404 | 404 | */ |
| 405 | 405 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 406 | - $Pile['vars'][$key] = $val; |
|
| 407 | - return $continue ? $val : ''; |
|
| 406 | + $Pile['vars'][$key] = $val; |
|
| 407 | + return $continue ? $val : ''; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 431 | 431 | */ |
| 432 | 432 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 433 | - $Pile[0][$key] = $val; |
|
| 434 | - return $continue ? $val : ''; |
|
| 433 | + $Pile[0][$key] = $val; |
|
| 434 | + return $continue ? $val : ''; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @return string |
| 441 | 441 | */ |
| 442 | 442 | function filtre_sanitize_env(&$Pile, $keys) { |
| 443 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | - return ''; |
|
| 443 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | + return ''; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -464,18 +464,18 @@ discard block |
||
| 464 | 464 | * @return mixed Retourne la valeur (sans la modifier). |
| 465 | 465 | */ |
| 466 | 466 | function filtre_debug($val, $key = null) { |
| 467 | - $debug = ( |
|
| 468 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | - ) . var_export($val, true); |
|
| 467 | + $debug = ( |
|
| 468 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | + ) . var_export($val, true); |
|
| 470 | 470 | |
| 471 | - include_spip('inc/autoriser'); |
|
| 472 | - if (autoriser('webmestre')) { |
|
| 473 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | - } |
|
| 471 | + include_spip('inc/autoriser'); |
|
| 472 | + if (autoriser('webmestre')) { |
|
| 473 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - spip_log($debug, 'debug'); |
|
| 476 | + spip_log($debug, 'debug'); |
|
| 477 | 477 | |
| 478 | - return $val; |
|
| 478 | + return $val; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -505,84 +505,84 @@ discard block |
||
| 505 | 505 | * Texte qui a reçu les filtres |
| 506 | 506 | **/ |
| 507 | 507 | function image_filtrer($args) { |
| 508 | - $filtre = array_shift($args); # enlever $filtre |
|
| 509 | - $texte = array_shift($args); |
|
| 510 | - if ($texte === null || !strlen($texte)) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | - // Cas du nom de fichier local |
|
| 516 | - $is_file = trim($texte); |
|
| 517 | - if ( |
|
| 518 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | - or strpos($is_file, '/') === 0 |
|
| 521 | - ) { |
|
| 522 | - $is_file = false; |
|
| 523 | - } |
|
| 524 | - if ($is_file) { |
|
| 525 | - $is_local_file = function ($path) { |
|
| 526 | - if (strpos($path, '?') !== false) { |
|
| 527 | - $path = supprimer_timestamp($path); |
|
| 528 | - // remove ?24px added by find_in_theme on .svg files |
|
| 529 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | - } |
|
| 531 | - return file_exists($path); |
|
| 532 | - }; |
|
| 533 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | - return $res; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | - if ( |
|
| 542 | - preg_match_all( |
|
| 543 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | - $texte, |
|
| 545 | - $tags, |
|
| 546 | - PREG_SET_ORDER |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - foreach ($tags as $tag) { |
|
| 550 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | - if ( |
|
| 552 | - !$class or |
|
| 553 | - (strpos($class, 'filtre_inactif') === false |
|
| 554 | - // compat historique a virer en 3.2 |
|
| 555 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | - ) { |
|
| 557 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | - if ($tag[1]) { |
|
| 560 | - $w = extraire_attribut($reduit, 'width'); |
|
| 561 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | - $w = $regs[1]; |
|
| 563 | - } |
|
| 564 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - // traiter aussi un eventuel mouseover |
|
| 571 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | - $srcover = $match[1]; |
|
| 574 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | - return $texte; |
|
| 508 | + $filtre = array_shift($args); # enlever $filtre |
|
| 509 | + $texte = array_shift($args); |
|
| 510 | + if ($texte === null || !strlen($texte)) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | + // Cas du nom de fichier local |
|
| 516 | + $is_file = trim($texte); |
|
| 517 | + if ( |
|
| 518 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | + or strpos($is_file, '/') === 0 |
|
| 521 | + ) { |
|
| 522 | + $is_file = false; |
|
| 523 | + } |
|
| 524 | + if ($is_file) { |
|
| 525 | + $is_local_file = function ($path) { |
|
| 526 | + if (strpos($path, '?') !== false) { |
|
| 527 | + $path = supprimer_timestamp($path); |
|
| 528 | + // remove ?24px added by find_in_theme on .svg files |
|
| 529 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | + } |
|
| 531 | + return file_exists($path); |
|
| 532 | + }; |
|
| 533 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | + return $res; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | + if ( |
|
| 542 | + preg_match_all( |
|
| 543 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | + $texte, |
|
| 545 | + $tags, |
|
| 546 | + PREG_SET_ORDER |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + foreach ($tags as $tag) { |
|
| 550 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | + if ( |
|
| 552 | + !$class or |
|
| 553 | + (strpos($class, 'filtre_inactif') === false |
|
| 554 | + // compat historique a virer en 3.2 |
|
| 555 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | + ) { |
|
| 557 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | + if ($tag[1]) { |
|
| 560 | + $w = extraire_attribut($reduit, 'width'); |
|
| 561 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | + $w = $regs[1]; |
|
| 563 | + } |
|
| 564 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + // traiter aussi un eventuel mouseover |
|
| 571 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | + $srcover = $match[1]; |
|
| 574 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | + return $texte; |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -599,91 +599,91 @@ discard block |
||
| 599 | 599 | **/ |
| 600 | 600 | function infos_image($img, $force_refresh = false) { |
| 601 | 601 | |
| 602 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | - $srcWidth = 0; |
|
| 604 | - $srcHeight = 0; |
|
| 605 | - $srcSize = null; |
|
| 606 | - |
|
| 607 | - $src = extraire_attribut($img, 'src'); |
|
| 608 | - |
|
| 609 | - if (!$src) { |
|
| 610 | - $src = $img; |
|
| 611 | - } else { |
|
| 612 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | - if (tester_url_absolue($src)) { |
|
| 619 | - include_spip('inc/distant'); |
|
| 620 | - $fichier = copie_locale($src); |
|
| 621 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | - } |
|
| 623 | - if (($p = strpos($src, '?')) !== false) { |
|
| 624 | - $src = substr($src, 0, $p); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $imagesize = false; |
|
| 628 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | - $srcWidth = $largeur_img[$src]; |
|
| 630 | - } |
|
| 631 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | - $srcHeight = $hauteur_img[$src]; |
|
| 633 | - } |
|
| 634 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | - $srcSize = $poids_img[$src]; |
|
| 636 | - } |
|
| 637 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | - if ( |
|
| 639 | - file_exists($src) |
|
| 640 | - and $imagesize = spip_getimagesize($src) |
|
| 641 | - ) { |
|
| 642 | - if (!$srcWidth) { |
|
| 643 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | - } |
|
| 645 | - if (!$srcHeight) { |
|
| 646 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | - } |
|
| 648 | - if (!$srcSize) { |
|
| 649 | - $poids_img[$src] = filesize($src); |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - elseif (strpos($src, '<svg') !== false) { |
|
| 653 | - include_spip('inc/svg'); |
|
| 654 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | - if (!$srcWidth) { |
|
| 657 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | - } |
|
| 659 | - if (!$srcHeight) { |
|
| 660 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | - } |
|
| 662 | - if (!$srcSize) { |
|
| 663 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | - elseif ( |
|
| 670 | - @file_exists($f = "$src.src") |
|
| 671 | - and lire_fichier($f, $valeurs) |
|
| 672 | - and $valeurs = unserialize($valeurs) |
|
| 673 | - ) { |
|
| 674 | - if (!$srcWidth) { |
|
| 675 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | - } |
|
| 677 | - if (!$srcHeight) { |
|
| 678 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | - } |
|
| 680 | - if (!$srcSize) { |
|
| 681 | - $poids_img[$src] = $srcSize = 0; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 602 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | + $srcWidth = 0; |
|
| 604 | + $srcHeight = 0; |
|
| 605 | + $srcSize = null; |
|
| 606 | + |
|
| 607 | + $src = extraire_attribut($img, 'src'); |
|
| 608 | + |
|
| 609 | + if (!$src) { |
|
| 610 | + $src = $img; |
|
| 611 | + } else { |
|
| 612 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | + if (tester_url_absolue($src)) { |
|
| 619 | + include_spip('inc/distant'); |
|
| 620 | + $fichier = copie_locale($src); |
|
| 621 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | + } |
|
| 623 | + if (($p = strpos($src, '?')) !== false) { |
|
| 624 | + $src = substr($src, 0, $p); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $imagesize = false; |
|
| 628 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | + $srcWidth = $largeur_img[$src]; |
|
| 630 | + } |
|
| 631 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | + $srcHeight = $hauteur_img[$src]; |
|
| 633 | + } |
|
| 634 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | + $srcSize = $poids_img[$src]; |
|
| 636 | + } |
|
| 637 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | + if ( |
|
| 639 | + file_exists($src) |
|
| 640 | + and $imagesize = spip_getimagesize($src) |
|
| 641 | + ) { |
|
| 642 | + if (!$srcWidth) { |
|
| 643 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | + } |
|
| 645 | + if (!$srcHeight) { |
|
| 646 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | + } |
|
| 648 | + if (!$srcSize) { |
|
| 649 | + $poids_img[$src] = filesize($src); |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + elseif (strpos($src, '<svg') !== false) { |
|
| 653 | + include_spip('inc/svg'); |
|
| 654 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | + if (!$srcWidth) { |
|
| 657 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | + } |
|
| 659 | + if (!$srcHeight) { |
|
| 660 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | + } |
|
| 662 | + if (!$srcSize) { |
|
| 663 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | + elseif ( |
|
| 670 | + @file_exists($f = "$src.src") |
|
| 671 | + and lire_fichier($f, $valeurs) |
|
| 672 | + and $valeurs = unserialize($valeurs) |
|
| 673 | + ) { |
|
| 674 | + if (!$srcWidth) { |
|
| 675 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | + } |
|
| 677 | + if (!$srcHeight) { |
|
| 678 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | + } |
|
| 680 | + if (!$srcSize) { |
|
| 681 | + $poids_img[$src] = $srcSize = 0; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -699,13 +699,13 @@ discard block |
||
| 699 | 699 | * poids |
| 700 | 700 | **/ |
| 701 | 701 | function poids_image($img, $force_refresh = false) { |
| 702 | - $infos = infos_image($img, $force_refresh); |
|
| 703 | - return $infos['poids']; |
|
| 702 | + $infos = infos_image($img, $force_refresh); |
|
| 703 | + return $infos['poids']; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | function taille_image($img, $force_refresh = false) { |
| 707 | - $infos = infos_image($img, $force_refresh); |
|
| 708 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 707 | + $infos = infos_image($img, $force_refresh); |
|
| 708 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -722,12 +722,12 @@ discard block |
||
| 722 | 722 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 723 | 723 | **/ |
| 724 | 724 | function largeur($img) { |
| 725 | - if (!$img) { |
|
| 726 | - return; |
|
| 727 | - } |
|
| 728 | - [$h, $l] = taille_image($img); |
|
| 725 | + if (!$img) { |
|
| 726 | + return; |
|
| 727 | + } |
|
| 728 | + [$h, $l] = taille_image($img); |
|
| 729 | 729 | |
| 730 | - return $l; |
|
| 730 | + return $l; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -744,12 +744,12 @@ discard block |
||
| 744 | 744 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 745 | 745 | **/ |
| 746 | 746 | function hauteur($img) { |
| 747 | - if (!$img) { |
|
| 748 | - return; |
|
| 749 | - } |
|
| 750 | - [$h, $l] = taille_image($img); |
|
| 747 | + if (!$img) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 750 | + [$h, $l] = taille_image($img); |
|
| 751 | 751 | |
| 752 | - return $h; |
|
| 752 | + return $h; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | **/ |
| 771 | 771 | function corriger_entites_html($texte) { |
| 772 | - if (strpos($texte, '&') === false) { |
|
| 773 | - return $texte; |
|
| 774 | - } |
|
| 772 | + if (strpos($texte, '&') === false) { |
|
| 773 | + return $texte; |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 776 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * @return string |
| 789 | 789 | **/ |
| 790 | 790 | function corriger_toutes_entites_html($texte) { |
| 791 | - if (strpos($texte, '&') === false) { |
|
| 792 | - return $texte; |
|
| 793 | - } |
|
| 791 | + if (strpos($texte, '&') === false) { |
|
| 792 | + return $texte; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 795 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * @return string |
| 803 | 803 | **/ |
| 804 | 804 | function proteger_amp($texte) { |
| 805 | - return str_replace('&', '&', $texte); |
|
| 805 | + return str_replace('&', '&', $texte); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -833,21 +833,21 @@ discard block |
||
| 833 | 833 | * @return mixed|string |
| 834 | 834 | */ |
| 835 | 835 | function entites_html($texte, $tout = false, $quote = true) { |
| 836 | - if ( |
|
| 837 | - !is_string($texte) or !$texte |
|
| 838 | - or strpbrk($texte, "&\"'<>") == false |
|
| 839 | - ) { |
|
| 840 | - return $texte; |
|
| 841 | - } |
|
| 842 | - include_spip('inc/texte'); |
|
| 843 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | - $flags |= ENT_HTML401; |
|
| 845 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | - if ($tout) { |
|
| 847 | - return corriger_toutes_entites_html($texte); |
|
| 848 | - } else { |
|
| 849 | - return corriger_entites_html($texte); |
|
| 850 | - } |
|
| 836 | + if ( |
|
| 837 | + !is_string($texte) or !$texte |
|
| 838 | + or strpbrk($texte, "&\"'<>") == false |
|
| 839 | + ) { |
|
| 840 | + return $texte; |
|
| 841 | + } |
|
| 842 | + include_spip('inc/texte'); |
|
| 843 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | + $flags |= ENT_HTML401; |
|
| 845 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | + if ($tout) { |
|
| 847 | + return corriger_toutes_entites_html($texte); |
|
| 848 | + } else { |
|
| 849 | + return corriger_entites_html($texte); |
|
| 850 | + } |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -866,37 +866,37 @@ discard block |
||
| 866 | 866 | * Texte converti |
| 867 | 867 | **/ |
| 868 | 868 | function filtrer_entites($texte) { |
| 869 | - if (strpos($texte, '&') === false) { |
|
| 870 | - return $texte; |
|
| 871 | - } |
|
| 872 | - // filtrer |
|
| 873 | - $texte = html2unicode($texte); |
|
| 874 | - // remettre le tout dans le charset cible |
|
| 875 | - $texte = unicode2charset($texte); |
|
| 876 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 877 | - // (on le faisait deja avec un ") |
|
| 878 | - if (strpos($texte, '&#') !== false) { |
|
| 879 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 880 | - } |
|
| 869 | + if (strpos($texte, '&') === false) { |
|
| 870 | + return $texte; |
|
| 871 | + } |
|
| 872 | + // filtrer |
|
| 873 | + $texte = html2unicode($texte); |
|
| 874 | + // remettre le tout dans le charset cible |
|
| 875 | + $texte = unicode2charset($texte); |
|
| 876 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 877 | + // (on le faisait deja avec un ") |
|
| 878 | + if (strpos($texte, '&#') !== false) { |
|
| 879 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 880 | + } |
|
| 881 | 881 | |
| 882 | - return $texte; |
|
| 882 | + return $texte; |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | |
| 886 | 886 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 887 | - /** |
|
| 888 | - * Version sécurisée de filtrer_entites |
|
| 889 | - * |
|
| 890 | - * @uses interdire_scripts() |
|
| 891 | - * @uses filtrer_entites() |
|
| 892 | - * |
|
| 893 | - * @param string $t |
|
| 894 | - * @return string |
|
| 895 | - */ |
|
| 896 | - function filtre_filtrer_entites_dist($t) { |
|
| 897 | - include_spip('inc/texte'); |
|
| 898 | - return interdire_scripts(filtrer_entites($t)); |
|
| 899 | - } |
|
| 887 | + /** |
|
| 888 | + * Version sécurisée de filtrer_entites |
|
| 889 | + * |
|
| 890 | + * @uses interdire_scripts() |
|
| 891 | + * @uses filtrer_entites() |
|
| 892 | + * |
|
| 893 | + * @param string $t |
|
| 894 | + * @return string |
|
| 895 | + */ |
|
| 896 | + function filtre_filtrer_entites_dist($t) { |
|
| 897 | + include_spip('inc/texte'); |
|
| 898 | + return interdire_scripts(filtrer_entites($t)); |
|
| 899 | + } |
|
| 900 | 900 | } |
| 901 | 901 | |
| 902 | 902 | |
@@ -911,18 +911,18 @@ discard block |
||
| 911 | 911 | * @return string|array |
| 912 | 912 | **/ |
| 913 | 913 | function supprimer_caracteres_illegaux($texte) { |
| 914 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 915 | - static $to = null; |
|
| 914 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 915 | + static $to = null; |
|
| 916 | 916 | |
| 917 | - if (is_array($texte)) { |
|
| 918 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 919 | - } |
|
| 917 | + if (is_array($texte)) { |
|
| 918 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 919 | + } |
|
| 920 | 920 | |
| 921 | - if (!$to) { |
|
| 922 | - $to = str_repeat('-', strlen($from)); |
|
| 923 | - } |
|
| 921 | + if (!$to) { |
|
| 922 | + $to = str_repeat('-', strlen($from)); |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | - return strtr($texte, $from, $to); |
|
| 925 | + return strtr($texte, $from, $to); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /** |
@@ -934,10 +934,10 @@ discard block |
||
| 934 | 934 | * @return string|array |
| 935 | 935 | **/ |
| 936 | 936 | function corriger_caracteres($texte) { |
| 937 | - $texte = corriger_caracteres_windows($texte); |
|
| 938 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 937 | + $texte = corriger_caracteres_windows($texte); |
|
| 938 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 939 | 939 | |
| 940 | - return $texte; |
|
| 940 | + return $texte; |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -954,44 +954,44 @@ discard block |
||
| 954 | 954 | * Texte encodé pour XML |
| 955 | 955 | */ |
| 956 | 956 | function texte_backend(string $texte): string { |
| 957 | - if ($texte === '') { |
|
| 958 | - return ''; |
|
| 959 | - } |
|
| 957 | + if ($texte === '') { |
|
| 958 | + return ''; |
|
| 959 | + } |
|
| 960 | 960 | |
| 961 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 961 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 962 | 962 | |
| 963 | - // si on a des liens ou des images, les passer en absolu |
|
| 964 | - $texte = liens_absolus($texte); |
|
| 963 | + // si on a des liens ou des images, les passer en absolu |
|
| 964 | + $texte = liens_absolus($texte); |
|
| 965 | 965 | |
| 966 | - // echapper les tags > < |
|
| 967 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 966 | + // echapper les tags > < |
|
| 967 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 968 | 968 | |
| 969 | - // importer les é |
|
| 970 | - $texte = filtrer_entites($texte); |
|
| 969 | + // importer les é |
|
| 970 | + $texte = filtrer_entites($texte); |
|
| 971 | 971 | |
| 972 | - // " -> " et tout ce genre de choses |
|
| 973 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 974 | - $texte = str_replace(' ', ' ', $texte); |
|
| 975 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 976 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 977 | - $texte = entites_html($texte, false, false); |
|
| 978 | - // mais bien echapper les double quotes ! |
|
| 979 | - $texte = str_replace('"', '"', $texte); |
|
| 972 | + // " -> " et tout ce genre de choses |
|
| 973 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 974 | + $texte = str_replace(' ', ' ', $texte); |
|
| 975 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 976 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 977 | + $texte = entites_html($texte, false, false); |
|
| 978 | + // mais bien echapper les double quotes ! |
|
| 979 | + $texte = str_replace('"', '"', $texte); |
|
| 980 | 980 | |
| 981 | - // verifier le charset |
|
| 982 | - $texte = charset2unicode($texte); |
|
| 981 | + // verifier le charset |
|
| 982 | + $texte = charset2unicode($texte); |
|
| 983 | 983 | |
| 984 | - // Caracteres problematiques en iso-latin 1 |
|
| 985 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 986 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 987 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 988 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 989 | - } |
|
| 984 | + // Caracteres problematiques en iso-latin 1 |
|
| 985 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 986 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 987 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 988 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 989 | + } |
|
| 990 | 990 | |
| 991 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 992 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 993 | - // ==> on les remplace par l'entite HTML |
|
| 994 | - return str_replace($apostrophe, "'", $texte); |
|
| 991 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 992 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 993 | + // ==> on les remplace par l'entite HTML |
|
| 994 | + return str_replace($apostrophe, "'", $texte); |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | * Texte encodé et quote pour XML |
| 1009 | 1009 | */ |
| 1010 | 1010 | function texte_backendq(string $texte): string { |
| 1011 | - return addslashes(texte_backend($texte)); |
|
| 1011 | + return addslashes(texte_backend($texte)); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
@@ -1031,11 +1031,11 @@ discard block |
||
| 1031 | 1031 | * Numéro de titre, sinon chaîne vide |
| 1032 | 1032 | **/ |
| 1033 | 1033 | function supprimer_numero($texte) { |
| 1034 | - return preg_replace( |
|
| 1035 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | - '', |
|
| 1037 | - $texte |
|
| 1038 | - ); |
|
| 1034 | + return preg_replace( |
|
| 1035 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | + '', |
|
| 1037 | + $texte |
|
| 1038 | + ); |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | /** |
@@ -1058,17 +1058,17 @@ discard block |
||
| 1058 | 1058 | * Numéro de titre, sinon chaîne vide |
| 1059 | 1059 | **/ |
| 1060 | 1060 | function recuperer_numero($texte) { |
| 1061 | - if ( |
|
| 1062 | - preg_match( |
|
| 1063 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1064 | - $texte, |
|
| 1065 | - $regs |
|
| 1066 | - ) |
|
| 1067 | - ) { |
|
| 1068 | - return strval($regs[1]); |
|
| 1069 | - } else { |
|
| 1070 | - return ''; |
|
| 1071 | - } |
|
| 1061 | + if ( |
|
| 1062 | + preg_match( |
|
| 1063 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1064 | + $texte, |
|
| 1065 | + $regs |
|
| 1066 | + ) |
|
| 1067 | + ) { |
|
| 1068 | + return strval($regs[1]); |
|
| 1069 | + } else { |
|
| 1070 | + return ''; |
|
| 1071 | + } |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | /** |
@@ -1095,16 +1095,16 @@ discard block |
||
| 1095 | 1095 | * Texte ou tableau de textes converti |
| 1096 | 1096 | **/ |
| 1097 | 1097 | function supprimer_tags($texte, $rempl = '') { |
| 1098 | - if ($texte === null) { |
|
| 1099 | - return ''; |
|
| 1100 | - } |
|
| 1101 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1102 | - // ne pas oublier un < final non ferme car coupe |
|
| 1103 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1104 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1105 | - $texte = str_replace('<', '<', $texte); |
|
| 1098 | + if ($texte === null) { |
|
| 1099 | + return ''; |
|
| 1100 | + } |
|
| 1101 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1102 | + // ne pas oublier un < final non ferme car coupe |
|
| 1103 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1104 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1105 | + $texte = str_replace('<', '<', $texte); |
|
| 1106 | 1106 | |
| 1107 | - return $texte; |
|
| 1107 | + return $texte; |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | /** |
@@ -1127,9 +1127,9 @@ discard block |
||
| 1127 | 1127 | * Texte converti |
| 1128 | 1128 | **/ |
| 1129 | 1129 | function echapper_tags($texte, $rempl = '') { |
| 1130 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1130 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1131 | 1131 | |
| 1132 | - return $texte; |
|
| 1132 | + return $texte; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | /** |
@@ -1150,18 +1150,18 @@ discard block |
||
| 1150 | 1150 | * Texte converti |
| 1151 | 1151 | **/ |
| 1152 | 1152 | function textebrut($texte) { |
| 1153 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1154 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1155 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1156 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1157 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1158 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1159 | - $texte = supprimer_tags($texte); |
|
| 1160 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1161 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1162 | - $texte = str_replace('’', "'", $texte); |
|
| 1153 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1154 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1155 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1156 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1157 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1158 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1159 | + $texte = supprimer_tags($texte); |
|
| 1160 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1161 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1162 | + $texte = str_replace('’', "'", $texte); |
|
| 1163 | 1163 | |
| 1164 | - return $texte; |
|
| 1164 | + return $texte; |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | |
@@ -1177,23 +1177,23 @@ discard block |
||
| 1177 | 1177 | * Texte avec liens ouvrants |
| 1178 | 1178 | **/ |
| 1179 | 1179 | function liens_ouvrants($texte) { |
| 1180 | - if ( |
|
| 1181 | - preg_match_all( |
|
| 1182 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1183 | - $texte, |
|
| 1184 | - $liens, |
|
| 1185 | - PREG_PATTERN_ORDER |
|
| 1186 | - ) |
|
| 1187 | - ) { |
|
| 1188 | - foreach ($liens[0] as $a) { |
|
| 1189 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1190 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1191 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1192 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1193 | - } |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - return $texte; |
|
| 1180 | + if ( |
|
| 1181 | + preg_match_all( |
|
| 1182 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1183 | + $texte, |
|
| 1184 | + $liens, |
|
| 1185 | + PREG_PATTERN_ORDER |
|
| 1186 | + ) |
|
| 1187 | + ) { |
|
| 1188 | + foreach ($liens[0] as $a) { |
|
| 1189 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1190 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1191 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1192 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1193 | + } |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + return $texte; |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | /** |
@@ -1203,22 +1203,22 @@ discard block |
||
| 1203 | 1203 | * @return string |
| 1204 | 1204 | */ |
| 1205 | 1205 | function liens_nofollow($texte) { |
| 1206 | - if (stripos($texte, '<a') === false) { |
|
| 1207 | - return $texte; |
|
| 1208 | - } |
|
| 1206 | + if (stripos($texte, '<a') === false) { |
|
| 1207 | + return $texte; |
|
| 1208 | + } |
|
| 1209 | 1209 | |
| 1210 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1211 | - foreach ($regs[0] as $a) { |
|
| 1212 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1213 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1214 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1215 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1216 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1217 | - } |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1210 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1211 | + foreach ($regs[0] as $a) { |
|
| 1212 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1213 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1214 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1215 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1216 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1217 | + } |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | 1220 | |
| 1221 | - return $texte; |
|
| 1221 | + return $texte; |
|
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | /** |
@@ -1237,12 +1237,12 @@ discard block |
||
| 1237 | 1237 | * Texte sans paraghaphes |
| 1238 | 1238 | **/ |
| 1239 | 1239 | function PtoBR($texte) { |
| 1240 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1241 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1242 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1243 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1240 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1241 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1242 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1243 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1244 | 1244 | |
| 1245 | - return $texte; |
|
| 1245 | + return $texte; |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | |
@@ -1267,14 +1267,14 @@ discard block |
||
| 1267 | 1267 | * @return string Texte encadré du style CSS |
| 1268 | 1268 | */ |
| 1269 | 1269 | function lignes_longues($texte) { |
| 1270 | - if (!strlen(trim($texte))) { |
|
| 1271 | - return $texte; |
|
| 1272 | - } |
|
| 1273 | - include_spip('inc/texte'); |
|
| 1274 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1275 | - 'div' : 'span'; |
|
| 1270 | + if (!strlen(trim($texte))) { |
|
| 1271 | + return $texte; |
|
| 1272 | + } |
|
| 1273 | + include_spip('inc/texte'); |
|
| 1274 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1275 | + 'div' : 'span'; |
|
| 1276 | 1276 | |
| 1277 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1277 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | /** |
@@ -1293,30 +1293,30 @@ discard block |
||
| 1293 | 1293 | * @return string Texte en majuscule |
| 1294 | 1294 | */ |
| 1295 | 1295 | function majuscules($texte) { |
| 1296 | - if (!strlen($texte)) { |
|
| 1297 | - return ''; |
|
| 1298 | - } |
|
| 1296 | + if (!strlen($texte)) { |
|
| 1297 | + return ''; |
|
| 1298 | + } |
|
| 1299 | 1299 | |
| 1300 | - // Cas du turc |
|
| 1301 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1302 | - # remplacer hors des tags et des entites |
|
| 1303 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1304 | - foreach ($regs as $n => $match) { |
|
| 1305 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1300 | + // Cas du turc |
|
| 1301 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1302 | + # remplacer hors des tags et des entites |
|
| 1303 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1304 | + foreach ($regs as $n => $match) { |
|
| 1305 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1309 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1310 | 1310 | |
| 1311 | - if ($regs) { |
|
| 1312 | - foreach ($regs as $n => $match) { |
|
| 1313 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1311 | + if ($regs) { |
|
| 1312 | + foreach ($regs as $n => $match) { |
|
| 1313 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | 1317 | |
| 1318 | - // Cas general |
|
| 1319 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1318 | + // Cas general |
|
| 1319 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | /** |
@@ -1334,29 +1334,29 @@ discard block |
||
| 1334 | 1334 | * @return string |
| 1335 | 1335 | **/ |
| 1336 | 1336 | function taille_en_octets($taille) { |
| 1337 | - if (!defined('_KILOBYTE')) { |
|
| 1338 | - /** |
|
| 1339 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1340 | - * |
|
| 1341 | - * @var int |
|
| 1342 | - **/ |
|
| 1343 | - define('_KILOBYTE', 1024); |
|
| 1344 | - } |
|
| 1337 | + if (!defined('_KILOBYTE')) { |
|
| 1338 | + /** |
|
| 1339 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1340 | + * |
|
| 1341 | + * @var int |
|
| 1342 | + **/ |
|
| 1343 | + define('_KILOBYTE', 1024); |
|
| 1344 | + } |
|
| 1345 | 1345 | |
| 1346 | - if ($taille < 1) { |
|
| 1347 | - return ''; |
|
| 1348 | - } |
|
| 1349 | - if ($taille < _KILOBYTE) { |
|
| 1350 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1351 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1352 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1353 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1354 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1355 | - } else { |
|
| 1356 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1357 | - } |
|
| 1346 | + if ($taille < 1) { |
|
| 1347 | + return ''; |
|
| 1348 | + } |
|
| 1349 | + if ($taille < _KILOBYTE) { |
|
| 1350 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1351 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1352 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1353 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1354 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1355 | + } else { |
|
| 1356 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1357 | + } |
|
| 1358 | 1358 | |
| 1359 | - return $taille; |
|
| 1359 | + return $taille; |
|
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | |
@@ -1378,21 +1378,21 @@ discard block |
||
| 1378 | 1378 | * Texte prêt pour être utilisé en attribut HTML |
| 1379 | 1379 | **/ |
| 1380 | 1380 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1381 | - if ($texte === null) { |
|
| 1382 | - return ''; |
|
| 1383 | - } |
|
| 1384 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1385 | - if ($textebrut) { |
|
| 1386 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1387 | - } |
|
| 1388 | - $texte = texte_backend($texte); |
|
| 1389 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1381 | + if ($texte === null) { |
|
| 1382 | + return ''; |
|
| 1383 | + } |
|
| 1384 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1385 | + if ($textebrut) { |
|
| 1386 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1387 | + } |
|
| 1388 | + $texte = texte_backend($texte); |
|
| 1389 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1390 | 1390 | |
| 1391 | - return preg_replace( |
|
| 1392 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1393 | - ['&', '&'], |
|
| 1394 | - $texte |
|
| 1395 | - ); |
|
| 1391 | + return preg_replace( |
|
| 1392 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1393 | + ['&', '&'], |
|
| 1394 | + $texte |
|
| 1395 | + ); |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | |
@@ -1412,15 +1412,15 @@ discard block |
||
| 1412 | 1412 | * URL ou chaîne vide |
| 1413 | 1413 | **/ |
| 1414 | 1414 | function vider_url(?string $url, $entites = true): string { |
| 1415 | - if ($url === null) { |
|
| 1416 | - return ''; |
|
| 1417 | - } |
|
| 1418 | - # un message pour abs_url |
|
| 1419 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1420 | - $url = trim($url); |
|
| 1421 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1415 | + if ($url === null) { |
|
| 1416 | + return ''; |
|
| 1417 | + } |
|
| 1418 | + # un message pour abs_url |
|
| 1419 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1420 | + $url = trim($url); |
|
| 1421 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1422 | 1422 | |
| 1423 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1423 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | |
@@ -1435,10 +1435,10 @@ discard block |
||
| 1435 | 1435 | * @return string Adresse email maquillée |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function antispam($texte) { |
| 1438 | - include_spip('inc/acces'); |
|
| 1439 | - $masque = creer_pass_aleatoire(3); |
|
| 1438 | + include_spip('inc/acces'); |
|
| 1439 | + $masque = creer_pass_aleatoire(3); |
|
| 1440 | 1440 | |
| 1441 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1441 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | /** |
@@ -1470,8 +1470,8 @@ discard block |
||
| 1470 | 1470 | * True si on a le droit d'accès, false sinon. |
| 1471 | 1471 | **/ |
| 1472 | 1472 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1473 | - include_spip('inc/acces'); |
|
| 1474 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1473 | + include_spip('inc/acces'); |
|
| 1474 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | /** |
@@ -1496,13 +1496,13 @@ discard block |
||
| 1496 | 1496 | * Retourne $texte, sinon $sinon. |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function sinon($texte, $sinon = '') { |
| 1499 | - if ($texte) { |
|
| 1500 | - return $texte; |
|
| 1501 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1502 | - return $texte; |
|
| 1503 | - } else { |
|
| 1504 | - return $sinon; |
|
| 1505 | - } |
|
| 1499 | + if ($texte) { |
|
| 1500 | + return $texte; |
|
| 1501 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1502 | + return $texte; |
|
| 1503 | + } else { |
|
| 1504 | + return $sinon; |
|
| 1505 | + } |
|
| 1506 | 1506 | } |
| 1507 | 1507 | |
| 1508 | 1508 | /** |
@@ -1526,7 +1526,7 @@ discard block |
||
| 1526 | 1526 | * @return mixed |
| 1527 | 1527 | **/ |
| 1528 | 1528 | function choixsivide($a, $vide, $pasvide) { |
| 1529 | - return $a ? $pasvide : $vide; |
|
| 1529 | + return $a ? $pasvide : $vide; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | /** |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | * @return mixed |
| 1551 | 1551 | **/ |
| 1552 | 1552 | function choixsiegal($a1, $a2, $v, $f) { |
| 1553 | - return ($a1 == $a2) ? $v : $f; |
|
| 1553 | + return ($a1 == $a2) ? $v : $f; |
|
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | // |
@@ -1569,13 +1569,13 @@ discard block |
||
| 1569 | 1569 | * @return string |
| 1570 | 1570 | **/ |
| 1571 | 1571 | function filtrer_ical($texte) { |
| 1572 | - #include_spip('inc/charsets'); |
|
| 1573 | - $texte = html2unicode($texte); |
|
| 1574 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1575 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1576 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1572 | + #include_spip('inc/charsets'); |
|
| 1573 | + $texte = html2unicode($texte); |
|
| 1574 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1575 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1576 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1577 | 1577 | |
| 1578 | - return $texte; |
|
| 1578 | + return $texte; |
|
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | |
@@ -1600,54 +1600,54 @@ discard block |
||
| 1600 | 1600 | * @return string |
| 1601 | 1601 | **/ |
| 1602 | 1602 | function post_autobr($texte, $delim = "\n_ ") { |
| 1603 | - if (!function_exists('echappe_html')) { |
|
| 1604 | - include_spip('inc/texte_mini'); |
|
| 1605 | - } |
|
| 1606 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1607 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1608 | - |
|
| 1609 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1610 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1611 | - } else { |
|
| 1612 | - $fin = ''; |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - $texte = echappe_html($texte, '', true); |
|
| 1616 | - |
|
| 1617 | - // echapper les modeles |
|
| 1618 | - if (strpos($texte, '<') !== false) { |
|
| 1619 | - include_spip('inc/lien'); |
|
| 1620 | - if (defined('_PREG_MODELE')) { |
|
| 1621 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1622 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1623 | - } |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - $debut = ''; |
|
| 1627 | - $suite = $texte; |
|
| 1628 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1629 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1630 | - $suite = substr($suite, $t); |
|
| 1631 | - $car = substr($suite, 0, 1); |
|
| 1632 | - if ( |
|
| 1633 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1634 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1635 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1636 | - ) { |
|
| 1637 | - $debut .= $delim; |
|
| 1638 | - } else { |
|
| 1639 | - $debut .= "\n"; |
|
| 1640 | - } |
|
| 1641 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1642 | - $debut .= $regs[0]; |
|
| 1643 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1644 | - } |
|
| 1645 | - } |
|
| 1646 | - $texte = $debut . $suite; |
|
| 1647 | - |
|
| 1648 | - $texte = echappe_retour($texte); |
|
| 1649 | - |
|
| 1650 | - return $texte . $fin; |
|
| 1603 | + if (!function_exists('echappe_html')) { |
|
| 1604 | + include_spip('inc/texte_mini'); |
|
| 1605 | + } |
|
| 1606 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1607 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1608 | + |
|
| 1609 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1610 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1611 | + } else { |
|
| 1612 | + $fin = ''; |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + $texte = echappe_html($texte, '', true); |
|
| 1616 | + |
|
| 1617 | + // echapper les modeles |
|
| 1618 | + if (strpos($texte, '<') !== false) { |
|
| 1619 | + include_spip('inc/lien'); |
|
| 1620 | + if (defined('_PREG_MODELE')) { |
|
| 1621 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1622 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1623 | + } |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + $debut = ''; |
|
| 1627 | + $suite = $texte; |
|
| 1628 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1629 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1630 | + $suite = substr($suite, $t); |
|
| 1631 | + $car = substr($suite, 0, 1); |
|
| 1632 | + if ( |
|
| 1633 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1634 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1635 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1636 | + ) { |
|
| 1637 | + $debut .= $delim; |
|
| 1638 | + } else { |
|
| 1639 | + $debut .= "\n"; |
|
| 1640 | + } |
|
| 1641 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1642 | + $debut .= $regs[0]; |
|
| 1643 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1644 | + } |
|
| 1645 | + } |
|
| 1646 | + $texte = $debut . $suite; |
|
| 1647 | + |
|
| 1648 | + $texte = echappe_retour($texte); |
|
| 1649 | + |
|
| 1650 | + return $texte . $fin; |
|
| 1651 | 1651 | } |
| 1652 | 1652 | |
| 1653 | 1653 | |
@@ -1688,47 +1688,47 @@ discard block |
||
| 1688 | 1688 | * @return string |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1691 | - static $traduire = false; |
|
| 1692 | - if ( |
|
| 1693 | - $letexte |
|
| 1694 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1695 | - ) { |
|
| 1696 | - if (!$traduire) { |
|
| 1697 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1698 | - include_spip('inc/lang'); |
|
| 1699 | - } |
|
| 1700 | - if (!$lang) { |
|
| 1701 | - $lang = $GLOBALS['spip_lang']; |
|
| 1702 | - } |
|
| 1703 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1704 | - if (is_bool($options)) { |
|
| 1705 | - $options = ['echappe_span' => $options]; |
|
| 1706 | - } |
|
| 1707 | - if (!isset($options['echappe_span'])) { |
|
| 1708 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - foreach ($regs as $reg) { |
|
| 1712 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1713 | - $desc = $traduire($cle, $lang, true); |
|
| 1714 | - $l = $desc->langue; |
|
| 1715 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1716 | - if (strlen($desc->texte ?? '')) { |
|
| 1717 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1718 | - if ($l !== $lang) { |
|
| 1719 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1720 | - } |
|
| 1721 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1722 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1723 | - } |
|
| 1724 | - if (!$options['echappe_span']) { |
|
| 1725 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1726 | - } |
|
| 1727 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1728 | - } |
|
| 1729 | - } |
|
| 1730 | - } |
|
| 1731 | - return $letexte; |
|
| 1691 | + static $traduire = false; |
|
| 1692 | + if ( |
|
| 1693 | + $letexte |
|
| 1694 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1695 | + ) { |
|
| 1696 | + if (!$traduire) { |
|
| 1697 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1698 | + include_spip('inc/lang'); |
|
| 1699 | + } |
|
| 1700 | + if (!$lang) { |
|
| 1701 | + $lang = $GLOBALS['spip_lang']; |
|
| 1702 | + } |
|
| 1703 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1704 | + if (is_bool($options)) { |
|
| 1705 | + $options = ['echappe_span' => $options]; |
|
| 1706 | + } |
|
| 1707 | + if (!isset($options['echappe_span'])) { |
|
| 1708 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + foreach ($regs as $reg) { |
|
| 1712 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1713 | + $desc = $traduire($cle, $lang, true); |
|
| 1714 | + $l = $desc->langue; |
|
| 1715 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1716 | + if (strlen($desc->texte ?? '')) { |
|
| 1717 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1718 | + if ($l !== $lang) { |
|
| 1719 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1720 | + } |
|
| 1721 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1722 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1723 | + } |
|
| 1724 | + if (!$options['echappe_span']) { |
|
| 1725 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1726 | + } |
|
| 1727 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1728 | + } |
|
| 1729 | + } |
|
| 1730 | + } |
|
| 1731 | + return $letexte; |
|
| 1732 | 1732 | } |
| 1733 | 1733 | |
| 1734 | 1734 | /** |
@@ -1780,68 +1780,68 @@ discard block |
||
| 1780 | 1780 | **/ |
| 1781 | 1781 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1782 | 1782 | |
| 1783 | - if ( |
|
| 1784 | - $letexte |
|
| 1785 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1786 | - ) { |
|
| 1787 | - if (!$lang) { |
|
| 1788 | - $lang = $GLOBALS['spip_lang']; |
|
| 1789 | - } |
|
| 1790 | - |
|
| 1791 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1792 | - if (is_bool($options)) { |
|
| 1793 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1794 | - } |
|
| 1795 | - if (!isset($options['echappe_span'])) { |
|
| 1796 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1797 | - } |
|
| 1798 | - if (!isset($options['lang_defaut'])) { |
|
| 1799 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1800 | - } |
|
| 1801 | - |
|
| 1802 | - include_spip('inc/lang'); |
|
| 1803 | - foreach ($regs as $reg) { |
|
| 1804 | - // chercher la version de la langue courante |
|
| 1805 | - $trads = extraire_trads($reg[1]); |
|
| 1806 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1807 | - $trad = $trads[$l]; |
|
| 1808 | - } else { |
|
| 1809 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1810 | - $trad = ''; |
|
| 1811 | - } else { |
|
| 1812 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1813 | - // ou la premiere dispo |
|
| 1814 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1815 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1816 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1817 | - $l = key($trads); |
|
| 1818 | - } |
|
| 1819 | - $trad = $trads[$l]; |
|
| 1820 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1821 | - $trad = $typographie($trad); |
|
| 1822 | - // Tester si on echappe en span ou en div |
|
| 1823 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1824 | - include_spip('inc/texte'); |
|
| 1825 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1826 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1827 | - if ($mode === 'div') { |
|
| 1828 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1829 | - } |
|
| 1830 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1831 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1832 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1833 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1834 | - } |
|
| 1835 | - if (!$options['echappe_span']) { |
|
| 1836 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1837 | - } |
|
| 1838 | - } |
|
| 1839 | - } |
|
| 1840 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1841 | - } |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - return $letexte; |
|
| 1783 | + if ( |
|
| 1784 | + $letexte |
|
| 1785 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1786 | + ) { |
|
| 1787 | + if (!$lang) { |
|
| 1788 | + $lang = $GLOBALS['spip_lang']; |
|
| 1789 | + } |
|
| 1790 | + |
|
| 1791 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1792 | + if (is_bool($options)) { |
|
| 1793 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1794 | + } |
|
| 1795 | + if (!isset($options['echappe_span'])) { |
|
| 1796 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1797 | + } |
|
| 1798 | + if (!isset($options['lang_defaut'])) { |
|
| 1799 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1800 | + } |
|
| 1801 | + |
|
| 1802 | + include_spip('inc/lang'); |
|
| 1803 | + foreach ($regs as $reg) { |
|
| 1804 | + // chercher la version de la langue courante |
|
| 1805 | + $trads = extraire_trads($reg[1]); |
|
| 1806 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1807 | + $trad = $trads[$l]; |
|
| 1808 | + } else { |
|
| 1809 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1810 | + $trad = ''; |
|
| 1811 | + } else { |
|
| 1812 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1813 | + // ou la premiere dispo |
|
| 1814 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1815 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1816 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1817 | + $l = key($trads); |
|
| 1818 | + } |
|
| 1819 | + $trad = $trads[$l]; |
|
| 1820 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1821 | + $trad = $typographie($trad); |
|
| 1822 | + // Tester si on echappe en span ou en div |
|
| 1823 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1824 | + include_spip('inc/texte'); |
|
| 1825 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1826 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1827 | + if ($mode === 'div') { |
|
| 1828 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1829 | + } |
|
| 1830 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1831 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1832 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1833 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1834 | + } |
|
| 1835 | + if (!$options['echappe_span']) { |
|
| 1836 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1837 | + } |
|
| 1838 | + } |
|
| 1839 | + } |
|
| 1840 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1841 | + } |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + return $letexte; |
|
| 1845 | 1845 | } |
| 1846 | 1846 | |
| 1847 | 1847 | /** |
@@ -1857,21 +1857,21 @@ discard block |
||
| 1857 | 1857 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1858 | 1858 | **/ |
| 1859 | 1859 | function extraire_trads($bloc) { |
| 1860 | - $trads = []; |
|
| 1861 | - $lang = ''; |
|
| 1860 | + $trads = []; |
|
| 1861 | + $lang = ''; |
|
| 1862 | 1862 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1863 | 1863 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1864 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1865 | - $texte = trim($regs[1]); |
|
| 1866 | - if ($texte or $lang) { |
|
| 1867 | - $trads[$lang] = $texte; |
|
| 1868 | - } |
|
| 1869 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1870 | - $lang = $regs[2]; |
|
| 1871 | - } |
|
| 1872 | - $trads[$lang] = $bloc; |
|
| 1864 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1865 | + $texte = trim($regs[1]); |
|
| 1866 | + if ($texte or $lang) { |
|
| 1867 | + $trads[$lang] = $texte; |
|
| 1868 | + } |
|
| 1869 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1870 | + $lang = $regs[2]; |
|
| 1871 | + } |
|
| 1872 | + $trads[$lang] = $bloc; |
|
| 1873 | 1873 | |
| 1874 | - return $trads; |
|
| 1874 | + return $trads; |
|
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | 1877 | |
@@ -1882,7 +1882,7 @@ discard block |
||
| 1882 | 1882 | * @return string L'initiale en majuscule |
| 1883 | 1883 | */ |
| 1884 | 1884 | function filtre_initiale($nom) { |
| 1885 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1885 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | 1888 | |
@@ -1927,33 +1927,33 @@ discard block |
||
| 1927 | 1927 | * - null (interne) : si on empile |
| 1928 | 1928 | **/ |
| 1929 | 1929 | function unique($donnee, $famille = '', $cpt = false) { |
| 1930 | - static $mem = []; |
|
| 1931 | - // permettre de vider la pile et de la restaurer |
|
| 1932 | - // pour le calcul de introduction... |
|
| 1933 | - if ($famille == '_spip_raz_') { |
|
| 1934 | - $tmp = $mem; |
|
| 1935 | - $mem = []; |
|
| 1936 | - |
|
| 1937 | - return $tmp; |
|
| 1938 | - } elseif ($famille == '_spip_set_') { |
|
| 1939 | - $mem = $donnee; |
|
| 1940 | - |
|
| 1941 | - return; |
|
| 1942 | - } |
|
| 1943 | - // eviter une notice |
|
| 1944 | - if (!isset($mem[$famille])) { |
|
| 1945 | - $mem[$famille] = []; |
|
| 1946 | - } |
|
| 1947 | - if ($cpt) { |
|
| 1948 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1949 | - } |
|
| 1950 | - // eviter une notice |
|
| 1951 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1952 | - $mem[$famille][$donnee] = 0; |
|
| 1953 | - } |
|
| 1954 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1955 | - return $donnee; |
|
| 1956 | - } |
|
| 1930 | + static $mem = []; |
|
| 1931 | + // permettre de vider la pile et de la restaurer |
|
| 1932 | + // pour le calcul de introduction... |
|
| 1933 | + if ($famille == '_spip_raz_') { |
|
| 1934 | + $tmp = $mem; |
|
| 1935 | + $mem = []; |
|
| 1936 | + |
|
| 1937 | + return $tmp; |
|
| 1938 | + } elseif ($famille == '_spip_set_') { |
|
| 1939 | + $mem = $donnee; |
|
| 1940 | + |
|
| 1941 | + return; |
|
| 1942 | + } |
|
| 1943 | + // eviter une notice |
|
| 1944 | + if (!isset($mem[$famille])) { |
|
| 1945 | + $mem[$famille] = []; |
|
| 1946 | + } |
|
| 1947 | + if ($cpt) { |
|
| 1948 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1949 | + } |
|
| 1950 | + // eviter une notice |
|
| 1951 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1952 | + $mem[$famille][$donnee] = 0; |
|
| 1953 | + } |
|
| 1954 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1955 | + return $donnee; |
|
| 1956 | + } |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | |
@@ -1983,20 +1983,20 @@ discard block |
||
| 1983 | 1983 | * Une des valeurs en fonction du compteur. |
| 1984 | 1984 | **/ |
| 1985 | 1985 | function alterner($i, ...$args) { |
| 1986 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1987 | - $num = count($args); |
|
| 1986 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1987 | + $num = count($args); |
|
| 1988 | 1988 | |
| 1989 | - if ($num === 1 && is_array($args[0])) { |
|
| 1990 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1991 | - $args = array_values($args[0]); |
|
| 1992 | - $num = count($args); |
|
| 1993 | - } |
|
| 1989 | + if ($num === 1 && is_array($args[0])) { |
|
| 1990 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1991 | + $args = array_values($args[0]); |
|
| 1992 | + $num = count($args); |
|
| 1993 | + } |
|
| 1994 | 1994 | |
| 1995 | - // un index compris entre 0 et num exclus |
|
| 1996 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1997 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1998 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1999 | - return $args[$i]; |
|
| 1995 | + // un index compris entre 0 et num exclus |
|
| 1996 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1997 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1998 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1999 | + return $args[$i]; |
|
| 2000 | 2000 | } |
| 2001 | 2001 | |
| 2002 | 2002 | |
@@ -2022,51 +2022,51 @@ discard block |
||
| 2022 | 2022 | * - null lorsque l’attribut n’existe pas. |
| 2023 | 2023 | **/ |
| 2024 | 2024 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 2025 | - if (is_array($balise)) { |
|
| 2026 | - array_walk( |
|
| 2027 | - $balise, |
|
| 2028 | - function (&$a, $key, $t) { |
|
| 2029 | - $a = extraire_attribut($a, $t); |
|
| 2030 | - }, |
|
| 2031 | - $attribut |
|
| 2032 | - ); |
|
| 2033 | - |
|
| 2034 | - return $balise; |
|
| 2035 | - } |
|
| 2036 | - if ( |
|
| 2037 | - $balise |
|
| 2038 | - && preg_match( |
|
| 2039 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2040 | - . $attribut |
|
| 2041 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2042 | - $balise, |
|
| 2043 | - $r |
|
| 2044 | - ) |
|
| 2045 | - ) { |
|
| 2046 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2047 | - $r[4] = substr($r[3], 1, -1); |
|
| 2048 | - $r[3] = $r[3][0]; |
|
| 2049 | - } elseif ($r[3] !== '') { |
|
| 2050 | - $r[4] = $r[3]; |
|
| 2051 | - $r[3] = ''; |
|
| 2052 | - } else { |
|
| 2053 | - $r[4] = trim($r[2]); |
|
| 2054 | - } |
|
| 2055 | - $att = $r[4]; |
|
| 2056 | - if (strpos($att, '&#') !== false) { |
|
| 2057 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2058 | - } |
|
| 2059 | - $att = filtrer_entites($att); |
|
| 2060 | - } else { |
|
| 2061 | - $att = null; |
|
| 2062 | - $r = []; |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - if ($complet) { |
|
| 2066 | - return [$att, $r]; |
|
| 2067 | - } else { |
|
| 2068 | - return $att; |
|
| 2069 | - } |
|
| 2025 | + if (is_array($balise)) { |
|
| 2026 | + array_walk( |
|
| 2027 | + $balise, |
|
| 2028 | + function (&$a, $key, $t) { |
|
| 2029 | + $a = extraire_attribut($a, $t); |
|
| 2030 | + }, |
|
| 2031 | + $attribut |
|
| 2032 | + ); |
|
| 2033 | + |
|
| 2034 | + return $balise; |
|
| 2035 | + } |
|
| 2036 | + if ( |
|
| 2037 | + $balise |
|
| 2038 | + && preg_match( |
|
| 2039 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2040 | + . $attribut |
|
| 2041 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2042 | + $balise, |
|
| 2043 | + $r |
|
| 2044 | + ) |
|
| 2045 | + ) { |
|
| 2046 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2047 | + $r[4] = substr($r[3], 1, -1); |
|
| 2048 | + $r[3] = $r[3][0]; |
|
| 2049 | + } elseif ($r[3] !== '') { |
|
| 2050 | + $r[4] = $r[3]; |
|
| 2051 | + $r[3] = ''; |
|
| 2052 | + } else { |
|
| 2053 | + $r[4] = trim($r[2]); |
|
| 2054 | + } |
|
| 2055 | + $att = $r[4]; |
|
| 2056 | + if (strpos($att, '&#') !== false) { |
|
| 2057 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2058 | + } |
|
| 2059 | + $att = filtrer_entites($att); |
|
| 2060 | + } else { |
|
| 2061 | + $att = null; |
|
| 2062 | + $r = []; |
|
| 2063 | + } |
|
| 2064 | + |
|
| 2065 | + if ($complet) { |
|
| 2066 | + return [$att, $r]; |
|
| 2067 | + } else { |
|
| 2068 | + return $att; |
|
| 2069 | + } |
|
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | /** |
@@ -2099,41 +2099,41 @@ discard block |
||
| 2099 | 2099 | **/ |
| 2100 | 2100 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2101 | 2101 | |
| 2102 | - if ($balise === null or $balise === '') { |
|
| 2103 | - return ''; |
|
| 2104 | - } |
|
| 2102 | + if ($balise === null or $balise === '') { |
|
| 2103 | + return ''; |
|
| 2104 | + } |
|
| 2105 | 2105 | |
| 2106 | - // preparer l'attribut |
|
| 2107 | - // supprimer les etc mais pas les balises html |
|
| 2108 | - // qui ont un sens dans un attribut value d'un input |
|
| 2109 | - if ($proteger) { |
|
| 2110 | - $val = attribut_html($val, false); |
|
| 2111 | - } |
|
| 2106 | + // preparer l'attribut |
|
| 2107 | + // supprimer les etc mais pas les balises html |
|
| 2108 | + // qui ont un sens dans un attribut value d'un input |
|
| 2109 | + if ($proteger) { |
|
| 2110 | + $val = attribut_html($val, false); |
|
| 2111 | + } |
|
| 2112 | 2112 | |
| 2113 | - // echapper les ' pour eviter tout bug |
|
| 2114 | - $val = str_replace("'", ''', $val); |
|
| 2115 | - if ($vider and strlen($val) === 0) { |
|
| 2116 | - $insert = ''; |
|
| 2117 | - } else { |
|
| 2118 | - $insert = " $attribut='$val'"; |
|
| 2119 | - } |
|
| 2113 | + // echapper les ' pour eviter tout bug |
|
| 2114 | + $val = str_replace("'", ''', $val); |
|
| 2115 | + if ($vider and strlen($val) === 0) { |
|
| 2116 | + $insert = ''; |
|
| 2117 | + } else { |
|
| 2118 | + $insert = " $attribut='$val'"; |
|
| 2119 | + } |
|
| 2120 | 2120 | |
| 2121 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2121 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2122 | 2122 | |
| 2123 | - if ($old !== null) { |
|
| 2124 | - // Remplacer l'ancien attribut du meme nom |
|
| 2125 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2126 | - } else { |
|
| 2127 | - // preferer une balise " />" (comme <img />) |
|
| 2128 | - if (preg_match(',/>,', $balise)) { |
|
| 2129 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2130 | - } // sinon une balise <a ...> ... </a> |
|
| 2131 | - else { |
|
| 2132 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2133 | - } |
|
| 2134 | - } |
|
| 2123 | + if ($old !== null) { |
|
| 2124 | + // Remplacer l'ancien attribut du meme nom |
|
| 2125 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2126 | + } else { |
|
| 2127 | + // preferer une balise " />" (comme <img />) |
|
| 2128 | + if (preg_match(',/>,', $balise)) { |
|
| 2129 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2130 | + } // sinon une balise <a ...> ... </a> |
|
| 2131 | + else { |
|
| 2132 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2133 | + } |
|
| 2134 | + } |
|
| 2135 | 2135 | |
| 2136 | - return $balise; |
|
| 2136 | + return $balise; |
|
| 2137 | 2137 | } |
| 2138 | 2138 | |
| 2139 | 2139 | /** |
@@ -2151,7 +2151,7 @@ discard block |
||
| 2151 | 2151 | * @return string Code HTML sans l'attribut |
| 2152 | 2152 | **/ |
| 2153 | 2153 | function vider_attribut(?string $balise, string $attribut): string { |
| 2154 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2154 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2155 | 2155 | } |
| 2156 | 2156 | |
| 2157 | 2157 | /** |
@@ -2163,53 +2163,53 @@ discard block |
||
| 2163 | 2163 | * @return string |
| 2164 | 2164 | */ |
| 2165 | 2165 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2166 | - if (is_string($class)) { |
|
| 2167 | - $class = explode(' ', trim($class)); |
|
| 2168 | - } |
|
| 2169 | - $class = array_filter($class); |
|
| 2170 | - $class = array_unique($class); |
|
| 2171 | - if (!$class) { |
|
| 2172 | - return $balise; |
|
| 2173 | - } |
|
| 2174 | - |
|
| 2175 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2176 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2177 | - return $balise; |
|
| 2178 | - } |
|
| 2179 | - |
|
| 2180 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2181 | - $class_new = $class_courante; |
|
| 2182 | - foreach ($class as $c) { |
|
| 2183 | - $is_class_presente = false; |
|
| 2184 | - if ( |
|
| 2185 | - $class_courante |
|
| 2186 | - and strpos($class_courante, (string) $c) !== false |
|
| 2187 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2188 | - ) { |
|
| 2189 | - $is_class_presente = true; |
|
| 2190 | - } |
|
| 2191 | - if ( |
|
| 2192 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2193 | - and !$is_class_presente |
|
| 2194 | - ) { |
|
| 2195 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2196 | - } elseif ( |
|
| 2197 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2198 | - and $is_class_presente |
|
| 2199 | - ) { |
|
| 2200 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2201 | - } |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - if ($class_new !== $class_courante) { |
|
| 2205 | - if (strlen($class_new)) { |
|
| 2206 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2207 | - } elseif ($class_courante) { |
|
| 2208 | - $balise = vider_attribut($balise, 'class'); |
|
| 2209 | - } |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - return $balise; |
|
| 2166 | + if (is_string($class)) { |
|
| 2167 | + $class = explode(' ', trim($class)); |
|
| 2168 | + } |
|
| 2169 | + $class = array_filter($class); |
|
| 2170 | + $class = array_unique($class); |
|
| 2171 | + if (!$class) { |
|
| 2172 | + return $balise; |
|
| 2173 | + } |
|
| 2174 | + |
|
| 2175 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2176 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2177 | + return $balise; |
|
| 2178 | + } |
|
| 2179 | + |
|
| 2180 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2181 | + $class_new = $class_courante; |
|
| 2182 | + foreach ($class as $c) { |
|
| 2183 | + $is_class_presente = false; |
|
| 2184 | + if ( |
|
| 2185 | + $class_courante |
|
| 2186 | + and strpos($class_courante, (string) $c) !== false |
|
| 2187 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2188 | + ) { |
|
| 2189 | + $is_class_presente = true; |
|
| 2190 | + } |
|
| 2191 | + if ( |
|
| 2192 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2193 | + and !$is_class_presente |
|
| 2194 | + ) { |
|
| 2195 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2196 | + } elseif ( |
|
| 2197 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2198 | + and $is_class_presente |
|
| 2199 | + ) { |
|
| 2200 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2201 | + } |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + if ($class_new !== $class_courante) { |
|
| 2205 | + if (strlen($class_new)) { |
|
| 2206 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2207 | + } elseif ($class_courante) { |
|
| 2208 | + $balise = vider_attribut($balise, 'class'); |
|
| 2209 | + } |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + return $balise; |
|
| 2213 | 2213 | } |
| 2214 | 2214 | |
| 2215 | 2215 | /** |
@@ -2219,7 +2219,7 @@ discard block |
||
| 2219 | 2219 | * @return string |
| 2220 | 2220 | */ |
| 2221 | 2221 | function ajouter_class($balise, $class) { |
| 2222 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2222 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2223 | 2223 | } |
| 2224 | 2224 | |
| 2225 | 2225 | /** |
@@ -2229,7 +2229,7 @@ discard block |
||
| 2229 | 2229 | * @return string |
| 2230 | 2230 | */ |
| 2231 | 2231 | function supprimer_class($balise, $class) { |
| 2232 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2232 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2233 | 2233 | } |
| 2234 | 2234 | |
| 2235 | 2235 | /** |
@@ -2240,7 +2240,7 @@ discard block |
||
| 2240 | 2240 | * @return string |
| 2241 | 2241 | */ |
| 2242 | 2242 | function commuter_class($balise, $class) { |
| 2243 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2243 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2244 | 2244 | } |
| 2245 | 2245 | |
| 2246 | 2246 | /** |
@@ -2251,19 +2251,19 @@ discard block |
||
| 2251 | 2251 | * @return string |
| 2252 | 2252 | */ |
| 2253 | 2253 | function tester_config($id, $mode = '') { |
| 2254 | - include_spip('action/inscrire_auteur'); |
|
| 2254 | + include_spip('action/inscrire_auteur'); |
|
| 2255 | 2255 | |
| 2256 | - return tester_statut_inscription($mode, $id); |
|
| 2256 | + return tester_statut_inscription($mode, $id); |
|
| 2257 | 2257 | } |
| 2258 | 2258 | |
| 2259 | 2259 | // |
| 2260 | 2260 | // Quelques fonctions de calcul arithmetique |
| 2261 | 2261 | // |
| 2262 | 2262 | function floatstr($a) { |
| 2263 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2263 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2264 | 2264 | } |
| 2265 | 2265 | function strize($f, $a, $b) { |
| 2266 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2266 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2267 | 2267 | } |
| 2268 | 2268 | |
| 2269 | 2269 | /** |
@@ -2282,7 +2282,7 @@ discard block |
||
| 2282 | 2282 | * @return int $a+$b |
| 2283 | 2283 | **/ |
| 2284 | 2284 | function plus($a, $b) { |
| 2285 | - return $a + $b; |
|
| 2285 | + return $a + $b; |
|
| 2286 | 2286 | } |
| 2287 | 2287 | function strplus($a, $b) { |
| 2288 | 2288 | return strize('plus', $a, $b); |
@@ -2303,7 +2303,7 @@ discard block |
||
| 2303 | 2303 | * @return int $a-$b |
| 2304 | 2304 | **/ |
| 2305 | 2305 | function moins($a, $b) { |
| 2306 | - return $a - $b; |
|
| 2306 | + return $a - $b; |
|
| 2307 | 2307 | } |
| 2308 | 2308 | function strmoins($a, $b) { |
| 2309 | 2309 | return strize('moins', $a, $b); |
@@ -2326,7 +2326,7 @@ discard block |
||
| 2326 | 2326 | * @return int $a*$b |
| 2327 | 2327 | **/ |
| 2328 | 2328 | function mult($a, $b) { |
| 2329 | - return $a * $b; |
|
| 2329 | + return $a * $b; |
|
| 2330 | 2330 | } |
| 2331 | 2331 | function strmult($a, $b) { |
| 2332 | 2332 | return strize('mult', $a, $b); |
@@ -2349,7 +2349,7 @@ discard block |
||
| 2349 | 2349 | * @return int $a/$b (ou 0 si $b est nul) |
| 2350 | 2350 | **/ |
| 2351 | 2351 | function div($a, $b) { |
| 2352 | - return $b ? $a / $b : 0; |
|
| 2352 | + return $b ? $a / $b : 0; |
|
| 2353 | 2353 | } |
| 2354 | 2354 | function strdiv($a, $b) { |
| 2355 | 2355 | return strize('div', $a, $b); |
@@ -2373,7 +2373,7 @@ discard block |
||
| 2373 | 2373 | * @return int ($nb % $mod) + $add |
| 2374 | 2374 | **/ |
| 2375 | 2375 | function modulo($nb, $mod, $add = 0) { |
| 2376 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2376 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2377 | 2377 | } |
| 2378 | 2378 | |
| 2379 | 2379 | |
@@ -2388,26 +2388,26 @@ discard block |
||
| 2388 | 2388 | * - true sinon |
| 2389 | 2389 | **/ |
| 2390 | 2390 | function nom_acceptable($nom) { |
| 2391 | - $remp2 = []; |
|
| 2392 | - $remp1 = []; |
|
| 2393 | - if (!is_string($nom)) { |
|
| 2394 | - return false; |
|
| 2395 | - } |
|
| 2396 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2397 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2398 | - } |
|
| 2399 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2400 | - foreach ($tags_acceptes as $tag) { |
|
| 2401 | - if (strlen($tag)) { |
|
| 2402 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2403 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2404 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2405 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2406 | - } |
|
| 2407 | - } |
|
| 2408 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2409 | - |
|
| 2410 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2391 | + $remp2 = []; |
|
| 2392 | + $remp1 = []; |
|
| 2393 | + if (!is_string($nom)) { |
|
| 2394 | + return false; |
|
| 2395 | + } |
|
| 2396 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2397 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2398 | + } |
|
| 2399 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2400 | + foreach ($tags_acceptes as $tag) { |
|
| 2401 | + if (strlen($tag)) { |
|
| 2402 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2403 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2404 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2405 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2406 | + } |
|
| 2407 | + } |
|
| 2408 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2409 | + |
|
| 2410 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2411 | 2411 | } |
| 2412 | 2412 | |
| 2413 | 2413 | |
@@ -2423,14 +2423,14 @@ discard block |
||
| 2423 | 2423 | * - renvoie un tableau si l'entree est un tableau |
| 2424 | 2424 | **/ |
| 2425 | 2425 | function email_valide($adresses) { |
| 2426 | - if (is_array($adresses)) { |
|
| 2427 | - $adresses = array_map('email_valide', $adresses); |
|
| 2428 | - $adresses = array_filter($adresses); |
|
| 2429 | - return $adresses; |
|
| 2430 | - } |
|
| 2426 | + if (is_array($adresses)) { |
|
| 2427 | + $adresses = array_map('email_valide', $adresses); |
|
| 2428 | + $adresses = array_filter($adresses); |
|
| 2429 | + return $adresses; |
|
| 2430 | + } |
|
| 2431 | 2431 | |
| 2432 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2433 | - return $email_valide($adresses); |
|
| 2432 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2433 | + return $email_valide($adresses); |
|
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | 2436 | /** |
@@ -2444,29 +2444,29 @@ discard block |
||
| 2444 | 2444 | * @return string Texte |
| 2445 | 2445 | **/ |
| 2446 | 2446 | function afficher_enclosures($tags) { |
| 2447 | - $s = []; |
|
| 2448 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2449 | - if ( |
|
| 2450 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2451 | - and $t = extraire_attribut($tag, 'href') |
|
| 2452 | - ) { |
|
| 2453 | - $s[] = preg_replace( |
|
| 2454 | - ',>[^<]+</a>,S', |
|
| 2455 | - '>' |
|
| 2456 | - . http_img_pack( |
|
| 2457 | - 'attachment-16.png', |
|
| 2458 | - $t, |
|
| 2459 | - '', |
|
| 2460 | - $t, |
|
| 2461 | - ['utiliser_suffixe_size' => true] |
|
| 2462 | - ) |
|
| 2463 | - . '</a>', |
|
| 2464 | - $tag |
|
| 2465 | - ); |
|
| 2466 | - } |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - return join(' ', $s); |
|
| 2447 | + $s = []; |
|
| 2448 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2449 | + if ( |
|
| 2450 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2451 | + and $t = extraire_attribut($tag, 'href') |
|
| 2452 | + ) { |
|
| 2453 | + $s[] = preg_replace( |
|
| 2454 | + ',>[^<]+</a>,S', |
|
| 2455 | + '>' |
|
| 2456 | + . http_img_pack( |
|
| 2457 | + 'attachment-16.png', |
|
| 2458 | + $t, |
|
| 2459 | + '', |
|
| 2460 | + $t, |
|
| 2461 | + ['utiliser_suffixe_size' => true] |
|
| 2462 | + ) |
|
| 2463 | + . '</a>', |
|
| 2464 | + $tag |
|
| 2465 | + ); |
|
| 2466 | + } |
|
| 2467 | + } |
|
| 2468 | + |
|
| 2469 | + return join(' ', $s); |
|
| 2470 | 2470 | } |
| 2471 | 2471 | |
| 2472 | 2472 | /** |
@@ -2481,15 +2481,15 @@ discard block |
||
| 2481 | 2481 | * @return string Liens trouvés |
| 2482 | 2482 | **/ |
| 2483 | 2483 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2484 | - $s = []; |
|
| 2485 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2486 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2487 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2488 | - $s[] = $tag; |
|
| 2489 | - } |
|
| 2490 | - } |
|
| 2484 | + $s = []; |
|
| 2485 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2486 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2487 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2488 | + $s[] = $tag; |
|
| 2489 | + } |
|
| 2490 | + } |
|
| 2491 | 2491 | |
| 2492 | - return join(', ', $s); |
|
| 2492 | + return join(', ', $s); |
|
| 2493 | 2493 | } |
| 2494 | 2494 | |
| 2495 | 2495 | |
@@ -2511,21 +2511,21 @@ discard block |
||
| 2511 | 2511 | * @return string Tag HTML `<a>` avec microformat. |
| 2512 | 2512 | **/ |
| 2513 | 2513 | function enclosure2microformat($e) { |
| 2514 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2515 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2516 | - } |
|
| 2517 | - $type = extraire_attribut($e, 'type'); |
|
| 2518 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2519 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2520 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2521 | - } |
|
| 2522 | - $fichier = basename($url); |
|
| 2514 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2515 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2516 | + } |
|
| 2517 | + $type = extraire_attribut($e, 'type'); |
|
| 2518 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2519 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2520 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2521 | + } |
|
| 2522 | + $fichier = basename($url); |
|
| 2523 | 2523 | |
| 2524 | - return '<a rel="enclosure"' |
|
| 2525 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2526 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2527 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2528 | - . '>' . $fichier . '</a>'; |
|
| 2524 | + return '<a rel="enclosure"' |
|
| 2525 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2526 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2527 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2528 | + . '>' . $fichier . '</a>'; |
|
| 2529 | 2529 | } |
| 2530 | 2530 | |
| 2531 | 2531 | /** |
@@ -2543,24 +2543,24 @@ discard block |
||
| 2543 | 2543 | * @return string Tags RSS `<enclosure>`. |
| 2544 | 2544 | **/ |
| 2545 | 2545 | function microformat2enclosure($tags) { |
| 2546 | - $enclosures = []; |
|
| 2547 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2548 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2549 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2550 | - $type = extraire_attribut($e, 'type'); |
|
| 2551 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2552 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2553 | - } # vieux data |
|
| 2554 | - $fichier = basename($url); |
|
| 2555 | - $enclosures[] = '<enclosure' |
|
| 2556 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2557 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2558 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2559 | - . ' />'; |
|
| 2560 | - } |
|
| 2561 | - } |
|
| 2546 | + $enclosures = []; |
|
| 2547 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2548 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2549 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2550 | + $type = extraire_attribut($e, 'type'); |
|
| 2551 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2552 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2553 | + } # vieux data |
|
| 2554 | + $fichier = basename($url); |
|
| 2555 | + $enclosures[] = '<enclosure' |
|
| 2556 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2557 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2558 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2559 | + . ' />'; |
|
| 2560 | + } |
|
| 2561 | + } |
|
| 2562 | 2562 | |
| 2563 | - return join("\n", $enclosures); |
|
| 2563 | + return join("\n", $enclosures); |
|
| 2564 | 2564 | } |
| 2565 | 2565 | |
| 2566 | 2566 | |
@@ -2576,16 +2576,16 @@ discard block |
||
| 2576 | 2576 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2577 | 2577 | **/ |
| 2578 | 2578 | function tags2dcsubject($tags) { |
| 2579 | - $subjects = ''; |
|
| 2580 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2581 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2582 | - $subjects .= '<dc:subject>' |
|
| 2583 | - . texte_backend(textebrut($e)) |
|
| 2584 | - . '</dc:subject>' . "\n"; |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2579 | + $subjects = ''; |
|
| 2580 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2581 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2582 | + $subjects .= '<dc:subject>' |
|
| 2583 | + . texte_backend(textebrut($e)) |
|
| 2584 | + . '</dc:subject>' . "\n"; |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | 2587 | |
| 2588 | - return $subjects; |
|
| 2588 | + return $subjects; |
|
| 2589 | 2589 | } |
| 2590 | 2590 | |
| 2591 | 2591 | /** |
@@ -2614,27 +2614,27 @@ discard block |
||
| 2614 | 2614 | * - Tableau de résultats, si tableau en entrée. |
| 2615 | 2615 | **/ |
| 2616 | 2616 | function extraire_balise($texte, $tag = 'a') { |
| 2617 | - if (is_array($texte)) { |
|
| 2618 | - array_walk( |
|
| 2619 | - $texte, |
|
| 2620 | - function (&$a, $key, $t) { |
|
| 2621 | - $a = extraire_balise($a, $t); |
|
| 2622 | - }, |
|
| 2623 | - $tag |
|
| 2624 | - ); |
|
| 2625 | - |
|
| 2626 | - return $texte; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - if ( |
|
| 2630 | - preg_match( |
|
| 2631 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2632 | - $texte, |
|
| 2633 | - $regs |
|
| 2634 | - ) |
|
| 2635 | - ) { |
|
| 2636 | - return $regs[0]; |
|
| 2637 | - } |
|
| 2617 | + if (is_array($texte)) { |
|
| 2618 | + array_walk( |
|
| 2619 | + $texte, |
|
| 2620 | + function (&$a, $key, $t) { |
|
| 2621 | + $a = extraire_balise($a, $t); |
|
| 2622 | + }, |
|
| 2623 | + $tag |
|
| 2624 | + ); |
|
| 2625 | + |
|
| 2626 | + return $texte; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + if ( |
|
| 2630 | + preg_match( |
|
| 2631 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2632 | + $texte, |
|
| 2633 | + $regs |
|
| 2634 | + ) |
|
| 2635 | + ) { |
|
| 2636 | + return $regs[0]; |
|
| 2637 | + } |
|
| 2638 | 2638 | } |
| 2639 | 2639 | |
| 2640 | 2640 | /** |
@@ -2662,30 +2662,30 @@ discard block |
||
| 2662 | 2662 | * - Tableau de résultats, si tableau en entrée. |
| 2663 | 2663 | **/ |
| 2664 | 2664 | function extraire_balises($texte, $tag = 'a') { |
| 2665 | - if (is_array($texte)) { |
|
| 2666 | - array_walk( |
|
| 2667 | - $texte, |
|
| 2668 | - function (&$a, $key, $t) { |
|
| 2669 | - $a = extraire_balises($a, $t); |
|
| 2670 | - }, |
|
| 2671 | - $tag |
|
| 2672 | - ); |
|
| 2673 | - |
|
| 2674 | - return $texte; |
|
| 2675 | - } |
|
| 2676 | - |
|
| 2677 | - if ( |
|
| 2678 | - preg_match_all( |
|
| 2679 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2680 | - $texte, |
|
| 2681 | - $regs, |
|
| 2682 | - PREG_PATTERN_ORDER |
|
| 2683 | - ) |
|
| 2684 | - ) { |
|
| 2685 | - return $regs[0]; |
|
| 2686 | - } else { |
|
| 2687 | - return []; |
|
| 2688 | - } |
|
| 2665 | + if (is_array($texte)) { |
|
| 2666 | + array_walk( |
|
| 2667 | + $texte, |
|
| 2668 | + function (&$a, $key, $t) { |
|
| 2669 | + $a = extraire_balises($a, $t); |
|
| 2670 | + }, |
|
| 2671 | + $tag |
|
| 2672 | + ); |
|
| 2673 | + |
|
| 2674 | + return $texte; |
|
| 2675 | + } |
|
| 2676 | + |
|
| 2677 | + if ( |
|
| 2678 | + preg_match_all( |
|
| 2679 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2680 | + $texte, |
|
| 2681 | + $regs, |
|
| 2682 | + PREG_PATTERN_ORDER |
|
| 2683 | + ) |
|
| 2684 | + ) { |
|
| 2685 | + return $regs[0]; |
|
| 2686 | + } else { |
|
| 2687 | + return []; |
|
| 2688 | + } |
|
| 2689 | 2689 | } |
| 2690 | 2690 | |
| 2691 | 2691 | /** |
@@ -2714,11 +2714,11 @@ discard block |
||
| 2714 | 2714 | * - `$def` si on n'a pas transmis de tableau |
| 2715 | 2715 | **/ |
| 2716 | 2716 | function in_any($val, $vals, $def = '') { |
| 2717 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2718 | - $vals = $v; |
|
| 2719 | - } |
|
| 2717 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2718 | + $vals = $v; |
|
| 2719 | + } |
|
| 2720 | 2720 | |
| 2721 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2721 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2722 | 2722 | } |
| 2723 | 2723 | |
| 2724 | 2724 | |
@@ -2739,12 +2739,12 @@ discard block |
||
| 2739 | 2739 | * Résultat du calcul |
| 2740 | 2740 | **/ |
| 2741 | 2741 | function valeur_numerique($expr) { |
| 2742 | - $a = 0; |
|
| 2743 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2744 | - eval("\$a = $expr;"); |
|
| 2745 | - } |
|
| 2742 | + $a = 0; |
|
| 2743 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2744 | + eval("\$a = $expr;"); |
|
| 2745 | + } |
|
| 2746 | 2746 | |
| 2747 | - return intval($a); |
|
| 2747 | + return intval($a); |
|
| 2748 | 2748 | } |
| 2749 | 2749 | |
| 2750 | 2750 | /** |
@@ -2763,7 +2763,7 @@ discard block |
||
| 2763 | 2763 | * Retourne `$a*$b/$c` |
| 2764 | 2764 | **/ |
| 2765 | 2765 | function regledetrois($a, $b, $c) { |
| 2766 | - return round($a * $b / $c); |
|
| 2766 | + return round($a * $b / $c); |
|
| 2767 | 2767 | } |
| 2768 | 2768 | |
| 2769 | 2769 | |
@@ -2786,79 +2786,79 @@ discard block |
||
| 2786 | 2786 | * @return string Suite de champs input hidden |
| 2787 | 2787 | **/ |
| 2788 | 2788 | function form_hidden(?string $action = ''): string { |
| 2789 | - $action ??= ''; |
|
| 2790 | - |
|
| 2791 | - $contexte = []; |
|
| 2792 | - include_spip('inc/urls'); |
|
| 2793 | - if ( |
|
| 2794 | - $p = urls_decoder_url($action, '') |
|
| 2795 | - and reset($p) |
|
| 2796 | - ) { |
|
| 2797 | - $fond = array_shift($p); |
|
| 2798 | - if ($fond != '404') { |
|
| 2799 | - $contexte = array_shift($p); |
|
| 2800 | - $contexte['page'] = $fond; |
|
| 2801 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2802 | - } |
|
| 2803 | - } |
|
| 2804 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2805 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2806 | - unset($contexte['type']); |
|
| 2807 | - } |
|
| 2808 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2809 | - unset($contexte['type-page']); |
|
| 2810 | - } |
|
| 2811 | - |
|
| 2812 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2813 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2814 | - $values = []; |
|
| 2815 | - |
|
| 2816 | - // d'abord avec celles de l'url |
|
| 2817 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2818 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2819 | - $c = explode('=', $c, 2); |
|
| 2820 | - $var = array_shift($c); |
|
| 2821 | - $val = array_shift($c) ?? ''; |
|
| 2822 | - if ($var) { |
|
| 2823 | - $val = rawurldecode($val); |
|
| 2824 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2825 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2826 | - $values[] = [$var, $val]; |
|
| 2827 | - } else { |
|
| 2828 | - if (!isset($values[$var])) { |
|
| 2829 | - $values[$var] = [$var, $val]; |
|
| 2830 | - } |
|
| 2831 | - } |
|
| 2832 | - } |
|
| 2833 | - } |
|
| 2834 | - } |
|
| 2835 | - |
|
| 2836 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2837 | - foreach ($contexte as $var => $val) { |
|
| 2838 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2839 | - $values[] = [$var, $val]; |
|
| 2840 | - } else { |
|
| 2841 | - if (!isset($values[$var])) { |
|
| 2842 | - $values[$var] = [$var, $val]; |
|
| 2843 | - } |
|
| 2844 | - } |
|
| 2845 | - } |
|
| 2846 | - |
|
| 2847 | - // puis on rassemble le tout |
|
| 2848 | - $hidden = []; |
|
| 2849 | - foreach ($values as $value) { |
|
| 2850 | - [$var, $val] = $value; |
|
| 2851 | - $hidden[] = '<input name="' |
|
| 2852 | - . entites_html($var) |
|
| 2853 | - . '"' |
|
| 2854 | - . (is_null($val) |
|
| 2855 | - ? '' |
|
| 2856 | - : ' value="' . entites_html($val) . '"' |
|
| 2857 | - ) |
|
| 2858 | - . ' type="hidden"' . "\n/>"; |
|
| 2859 | - } |
|
| 2860 | - |
|
| 2861 | - return join('', $hidden); |
|
| 2789 | + $action ??= ''; |
|
| 2790 | + |
|
| 2791 | + $contexte = []; |
|
| 2792 | + include_spip('inc/urls'); |
|
| 2793 | + if ( |
|
| 2794 | + $p = urls_decoder_url($action, '') |
|
| 2795 | + and reset($p) |
|
| 2796 | + ) { |
|
| 2797 | + $fond = array_shift($p); |
|
| 2798 | + if ($fond != '404') { |
|
| 2799 | + $contexte = array_shift($p); |
|
| 2800 | + $contexte['page'] = $fond; |
|
| 2801 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2802 | + } |
|
| 2803 | + } |
|
| 2804 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2805 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2806 | + unset($contexte['type']); |
|
| 2807 | + } |
|
| 2808 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2809 | + unset($contexte['type-page']); |
|
| 2810 | + } |
|
| 2811 | + |
|
| 2812 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2813 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2814 | + $values = []; |
|
| 2815 | + |
|
| 2816 | + // d'abord avec celles de l'url |
|
| 2817 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2818 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2819 | + $c = explode('=', $c, 2); |
|
| 2820 | + $var = array_shift($c); |
|
| 2821 | + $val = array_shift($c) ?? ''; |
|
| 2822 | + if ($var) { |
|
| 2823 | + $val = rawurldecode($val); |
|
| 2824 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2825 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2826 | + $values[] = [$var, $val]; |
|
| 2827 | + } else { |
|
| 2828 | + if (!isset($values[$var])) { |
|
| 2829 | + $values[$var] = [$var, $val]; |
|
| 2830 | + } |
|
| 2831 | + } |
|
| 2832 | + } |
|
| 2833 | + } |
|
| 2834 | + } |
|
| 2835 | + |
|
| 2836 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2837 | + foreach ($contexte as $var => $val) { |
|
| 2838 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2839 | + $values[] = [$var, $val]; |
|
| 2840 | + } else { |
|
| 2841 | + if (!isset($values[$var])) { |
|
| 2842 | + $values[$var] = [$var, $val]; |
|
| 2843 | + } |
|
| 2844 | + } |
|
| 2845 | + } |
|
| 2846 | + |
|
| 2847 | + // puis on rassemble le tout |
|
| 2848 | + $hidden = []; |
|
| 2849 | + foreach ($values as $value) { |
|
| 2850 | + [$var, $val] = $value; |
|
| 2851 | + $hidden[] = '<input name="' |
|
| 2852 | + . entites_html($var) |
|
| 2853 | + . '"' |
|
| 2854 | + . (is_null($val) |
|
| 2855 | + ? '' |
|
| 2856 | + : ' value="' . entites_html($val) . '"' |
|
| 2857 | + ) |
|
| 2858 | + . ' type="hidden"' . "\n/>"; |
|
| 2859 | + } |
|
| 2860 | + |
|
| 2861 | + return join('', $hidden); |
|
| 2862 | 2862 | } |
| 2863 | 2863 | |
| 2864 | 2864 | |
@@ -2880,7 +2880,7 @@ discard block |
||
| 2880 | 2880 | * - la première valeur du tableau sinon. |
| 2881 | 2881 | **/ |
| 2882 | 2882 | function filtre_reset($array) { |
| 2883 | - return !is_array($array) ? null : reset($array); |
|
| 2883 | + return !is_array($array) ? null : reset($array); |
|
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 2886 | /** |
@@ -2901,7 +2901,7 @@ discard block |
||
| 2901 | 2901 | * - la dernière valeur du tableau sinon. |
| 2902 | 2902 | **/ |
| 2903 | 2903 | function filtre_end($array) { |
| 2904 | - return !is_array($array) ? null : end($array); |
|
| 2904 | + return !is_array($array) ? null : end($array); |
|
| 2905 | 2905 | } |
| 2906 | 2906 | |
| 2907 | 2907 | /** |
@@ -2921,11 +2921,11 @@ discard block |
||
| 2921 | 2921 | * |
| 2922 | 2922 | **/ |
| 2923 | 2923 | function filtre_push($array, $val) { |
| 2924 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2925 | - return ''; |
|
| 2926 | - } |
|
| 2924 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2925 | + return ''; |
|
| 2926 | + } |
|
| 2927 | 2927 | |
| 2928 | - return $array; |
|
| 2928 | + return $array; |
|
| 2929 | 2929 | } |
| 2930 | 2930 | |
| 2931 | 2931 | /** |
@@ -2944,7 +2944,7 @@ discard block |
||
| 2944 | 2944 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2945 | 2945 | **/ |
| 2946 | 2946 | function filtre_find($array, $val) { |
| 2947 | - return (is_array($array) and in_array($val, $array)); |
|
| 2947 | + return (is_array($array) and in_array($val, $array)); |
|
| 2948 | 2948 | } |
| 2949 | 2949 | |
| 2950 | 2950 | |
@@ -2961,13 +2961,13 @@ discard block |
||
| 2961 | 2961 | * Contenu avec urls en absolus |
| 2962 | 2962 | **/ |
| 2963 | 2963 | function urls_absolues_css($contenu, $source) { |
| 2964 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2964 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2965 | 2965 | |
| 2966 | - return preg_replace_callback( |
|
| 2967 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2968 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2969 | - $contenu |
|
| 2970 | - ); |
|
| 2966 | + return preg_replace_callback( |
|
| 2967 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2968 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2969 | + $contenu |
|
| 2970 | + ); |
|
| 2971 | 2971 | } |
| 2972 | 2972 | |
| 2973 | 2973 | |
@@ -2996,119 +2996,119 @@ discard block |
||
| 2996 | 2996 | * Chemin du fichier CSS inversé |
| 2997 | 2997 | **/ |
| 2998 | 2998 | function direction_css($css, $voulue = '') { |
| 2999 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3000 | - return $css; |
|
| 3001 | - } |
|
| 3002 | - include_spip('inc/lang'); |
|
| 3003 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3004 | - if ($voulue = strtolower($voulue)) { |
|
| 3005 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3006 | - $voulue = lang_dir($voulue); |
|
| 3007 | - } |
|
| 3008 | - } else { |
|
| 3009 | - $voulue = lang_dir(); |
|
| 3010 | - } |
|
| 3011 | - |
|
| 3012 | - $r = count($r) > 1; |
|
| 3013 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3014 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 3015 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3016 | - |
|
| 3017 | - if ($voulue == $dir) { |
|
| 3018 | - return $css; |
|
| 3019 | - } |
|
| 3020 | - |
|
| 3021 | - if ( |
|
| 3022 | - // url absolue |
|
| 3023 | - preg_match(',^https?:,i', $css) |
|
| 3024 | - // ou qui contient un ? |
|
| 3025 | - or (($p = strpos($css, '?')) !== false) |
|
| 3026 | - ) { |
|
| 3027 | - $distant = true; |
|
| 3028 | - $cssf = parse_url($css); |
|
| 3029 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3030 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3031 | - } else { |
|
| 3032 | - $distant = false; |
|
| 3033 | - $cssf = $css; |
|
| 3034 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3035 | - //propose (rien a faire dans ce cas) |
|
| 3036 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3037 | - if (@file_exists($f)) { |
|
| 3038 | - return $f; |
|
| 3039 | - } |
|
| 3040 | - } |
|
| 3041 | - |
|
| 3042 | - // 2. |
|
| 3043 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3044 | - $f = $dir_var |
|
| 3045 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3046 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3047 | - |
|
| 3048 | - // la css peut etre distante (url absolue !) |
|
| 3049 | - if ($distant) { |
|
| 3050 | - include_spip('inc/distant'); |
|
| 3051 | - $res = recuperer_url($css); |
|
| 3052 | - if (!$res or !$contenu = $res['page']) { |
|
| 3053 | - return $css; |
|
| 3054 | - } |
|
| 3055 | - } else { |
|
| 3056 | - if ( |
|
| 3057 | - (@filemtime($f) > @filemtime($css)) |
|
| 3058 | - and (_VAR_MODE != 'recalcul') |
|
| 3059 | - ) { |
|
| 3060 | - return $f; |
|
| 3061 | - } |
|
| 3062 | - if (!lire_fichier($css, $contenu)) { |
|
| 3063 | - return $css; |
|
| 3064 | - } |
|
| 3065 | - } |
|
| 3066 | - |
|
| 3067 | - |
|
| 3068 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3069 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3070 | - $parser = new csstidy(); |
|
| 3071 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3072 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3073 | - $parser->parse($contenu); |
|
| 3074 | - |
|
| 3075 | - $contenu = $parser->print->plain(); |
|
| 3076 | - |
|
| 3077 | - |
|
| 3078 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3079 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3080 | - $src = []; |
|
| 3081 | - $src_direction_css = []; |
|
| 3082 | - $src_faux_abs = []; |
|
| 3083 | - $d = dirname($css); |
|
| 3084 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3085 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3086 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3087 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3088 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3089 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3090 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3091 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3092 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3093 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3094 | - } |
|
| 3095 | - $src[] = $regs[0][$k]; |
|
| 3096 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3097 | - } |
|
| 3098 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3099 | - |
|
| 3100 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3101 | - |
|
| 3102 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3103 | - if (count($src_faux_abs)) { |
|
| 3104 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3105 | - } |
|
| 3106 | - |
|
| 3107 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3108 | - return $css; |
|
| 3109 | - } |
|
| 3110 | - |
|
| 3111 | - return $f; |
|
| 2999 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3000 | + return $css; |
|
| 3001 | + } |
|
| 3002 | + include_spip('inc/lang'); |
|
| 3003 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3004 | + if ($voulue = strtolower($voulue)) { |
|
| 3005 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3006 | + $voulue = lang_dir($voulue); |
|
| 3007 | + } |
|
| 3008 | + } else { |
|
| 3009 | + $voulue = lang_dir(); |
|
| 3010 | + } |
|
| 3011 | + |
|
| 3012 | + $r = count($r) > 1; |
|
| 3013 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3014 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 3015 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3016 | + |
|
| 3017 | + if ($voulue == $dir) { |
|
| 3018 | + return $css; |
|
| 3019 | + } |
|
| 3020 | + |
|
| 3021 | + if ( |
|
| 3022 | + // url absolue |
|
| 3023 | + preg_match(',^https?:,i', $css) |
|
| 3024 | + // ou qui contient un ? |
|
| 3025 | + or (($p = strpos($css, '?')) !== false) |
|
| 3026 | + ) { |
|
| 3027 | + $distant = true; |
|
| 3028 | + $cssf = parse_url($css); |
|
| 3029 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3030 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3031 | + } else { |
|
| 3032 | + $distant = false; |
|
| 3033 | + $cssf = $css; |
|
| 3034 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3035 | + //propose (rien a faire dans ce cas) |
|
| 3036 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3037 | + if (@file_exists($f)) { |
|
| 3038 | + return $f; |
|
| 3039 | + } |
|
| 3040 | + } |
|
| 3041 | + |
|
| 3042 | + // 2. |
|
| 3043 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3044 | + $f = $dir_var |
|
| 3045 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3046 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3047 | + |
|
| 3048 | + // la css peut etre distante (url absolue !) |
|
| 3049 | + if ($distant) { |
|
| 3050 | + include_spip('inc/distant'); |
|
| 3051 | + $res = recuperer_url($css); |
|
| 3052 | + if (!$res or !$contenu = $res['page']) { |
|
| 3053 | + return $css; |
|
| 3054 | + } |
|
| 3055 | + } else { |
|
| 3056 | + if ( |
|
| 3057 | + (@filemtime($f) > @filemtime($css)) |
|
| 3058 | + and (_VAR_MODE != 'recalcul') |
|
| 3059 | + ) { |
|
| 3060 | + return $f; |
|
| 3061 | + } |
|
| 3062 | + if (!lire_fichier($css, $contenu)) { |
|
| 3063 | + return $css; |
|
| 3064 | + } |
|
| 3065 | + } |
|
| 3066 | + |
|
| 3067 | + |
|
| 3068 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3069 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3070 | + $parser = new csstidy(); |
|
| 3071 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3072 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3073 | + $parser->parse($contenu); |
|
| 3074 | + |
|
| 3075 | + $contenu = $parser->print->plain(); |
|
| 3076 | + |
|
| 3077 | + |
|
| 3078 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3079 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3080 | + $src = []; |
|
| 3081 | + $src_direction_css = []; |
|
| 3082 | + $src_faux_abs = []; |
|
| 3083 | + $d = dirname($css); |
|
| 3084 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3085 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3086 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3087 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3088 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3089 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3090 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3091 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3092 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3093 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3094 | + } |
|
| 3095 | + $src[] = $regs[0][$k]; |
|
| 3096 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3097 | + } |
|
| 3098 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3099 | + |
|
| 3100 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3101 | + |
|
| 3102 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3103 | + if (count($src_faux_abs)) { |
|
| 3104 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3105 | + } |
|
| 3106 | + |
|
| 3107 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3108 | + return $css; |
|
| 3109 | + } |
|
| 3110 | + |
|
| 3111 | + return $f; |
|
| 3112 | 3112 | } |
| 3113 | 3113 | |
| 3114 | 3114 | |
@@ -3131,46 +3131,46 @@ discard block |
||
| 3131 | 3131 | * - Chemin ou URL du fichier CSS source sinon. |
| 3132 | 3132 | **/ |
| 3133 | 3133 | function url_absolue_css($css) { |
| 3134 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3135 | - return $css; |
|
| 3136 | - } |
|
| 3134 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3135 | + return $css; |
|
| 3136 | + } |
|
| 3137 | 3137 | |
| 3138 | - $url_absolue_css = url_absolue($css); |
|
| 3138 | + $url_absolue_css = url_absolue($css); |
|
| 3139 | 3139 | |
| 3140 | - $f = basename($css, '.css'); |
|
| 3141 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3142 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3143 | - . '.css'; |
|
| 3140 | + $f = basename($css, '.css'); |
|
| 3141 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3142 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3143 | + . '.css'; |
|
| 3144 | 3144 | |
| 3145 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3146 | - return $f; |
|
| 3147 | - } |
|
| 3145 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3146 | + return $f; |
|
| 3147 | + } |
|
| 3148 | 3148 | |
| 3149 | - if ($url_absolue_css == $css) { |
|
| 3150 | - if ( |
|
| 3151 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3152 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3153 | - ) { |
|
| 3154 | - include_spip('inc/distant'); |
|
| 3155 | - $contenu = recuperer_url($css); |
|
| 3156 | - $contenu = $contenu['page'] ?? ''; |
|
| 3157 | - if (!$contenu) { |
|
| 3158 | - return $css; |
|
| 3159 | - } |
|
| 3160 | - } |
|
| 3161 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3162 | - return $css; |
|
| 3163 | - } |
|
| 3149 | + if ($url_absolue_css == $css) { |
|
| 3150 | + if ( |
|
| 3151 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3152 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3153 | + ) { |
|
| 3154 | + include_spip('inc/distant'); |
|
| 3155 | + $contenu = recuperer_url($css); |
|
| 3156 | + $contenu = $contenu['page'] ?? ''; |
|
| 3157 | + if (!$contenu) { |
|
| 3158 | + return $css; |
|
| 3159 | + } |
|
| 3160 | + } |
|
| 3161 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3162 | + return $css; |
|
| 3163 | + } |
|
| 3164 | 3164 | |
| 3165 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3166 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3165 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3166 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3167 | 3167 | |
| 3168 | - // ecrire la css |
|
| 3169 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3170 | - return $css; |
|
| 3171 | - } |
|
| 3168 | + // ecrire la css |
|
| 3169 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3170 | + return $css; |
|
| 3171 | + } |
|
| 3172 | 3172 | |
| 3173 | - return $f; |
|
| 3173 | + return $f; |
|
| 3174 | 3174 | } |
| 3175 | 3175 | |
| 3176 | 3176 | |
@@ -3204,24 +3204,24 @@ discard block |
||
| 3204 | 3204 | * Valeur trouvée ou valeur par défaut. |
| 3205 | 3205 | **/ |
| 3206 | 3206 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3207 | - foreach (explode('/', $cle) as $k) { |
|
| 3208 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3207 | + foreach (explode('/', $cle) as $k) { |
|
| 3208 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3209 | 3209 | |
| 3210 | - if (is_object($table)) { |
|
| 3211 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3212 | - } elseif (is_array($table)) { |
|
| 3213 | - if ($conserver_null) { |
|
| 3214 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3215 | - } else { |
|
| 3216 | - $table = ($table[$k] ?? $defaut); |
|
| 3217 | - } |
|
| 3218 | - } else { |
|
| 3219 | - $table = $defaut; |
|
| 3220 | - break; |
|
| 3221 | - } |
|
| 3222 | - } |
|
| 3210 | + if (is_object($table)) { |
|
| 3211 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3212 | + } elseif (is_array($table)) { |
|
| 3213 | + if ($conserver_null) { |
|
| 3214 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3215 | + } else { |
|
| 3216 | + $table = ($table[$k] ?? $defaut); |
|
| 3217 | + } |
|
| 3218 | + } else { |
|
| 3219 | + $table = $defaut; |
|
| 3220 | + break; |
|
| 3221 | + } |
|
| 3222 | + } |
|
| 3223 | 3223 | |
| 3224 | - return $table; |
|
| 3224 | + return $table; |
|
| 3225 | 3225 | } |
| 3226 | 3226 | |
| 3227 | 3227 | /** |
@@ -3254,22 +3254,22 @@ discard block |
||
| 3254 | 3254 | * - string : expression trouvée. |
| 3255 | 3255 | **/ |
| 3256 | 3256 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3257 | - if (intval($modif) and $capte == 0) { |
|
| 3258 | - $capte = $modif; |
|
| 3259 | - $modif = 'UuimsS'; |
|
| 3260 | - } |
|
| 3261 | - $expression = str_replace('\/', '/', $expression); |
|
| 3262 | - $expression = str_replace('/', '\/', $expression); |
|
| 3257 | + if (intval($modif) and $capte == 0) { |
|
| 3258 | + $capte = $modif; |
|
| 3259 | + $modif = 'UuimsS'; |
|
| 3260 | + } |
|
| 3261 | + $expression = str_replace('\/', '/', $expression); |
|
| 3262 | + $expression = str_replace('/', '\/', $expression); |
|
| 3263 | 3263 | |
| 3264 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3265 | - if (isset($r[$capte])) { |
|
| 3266 | - return $r[$capte]; |
|
| 3267 | - } else { |
|
| 3268 | - return true; |
|
| 3269 | - } |
|
| 3270 | - } |
|
| 3264 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3265 | + if (isset($r[$capte])) { |
|
| 3266 | + return $r[$capte]; |
|
| 3267 | + } else { |
|
| 3268 | + return true; |
|
| 3269 | + } |
|
| 3270 | + } |
|
| 3271 | 3271 | |
| 3272 | - return false; |
|
| 3272 | + return false; |
|
| 3273 | 3273 | } |
| 3274 | 3274 | |
| 3275 | 3275 | |
@@ -3296,10 +3296,10 @@ discard block |
||
| 3296 | 3296 | * Texte |
| 3297 | 3297 | **/ |
| 3298 | 3298 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3299 | - $expression = str_replace('\/', '/', $expression); |
|
| 3300 | - $expression = str_replace('/', '\/', $expression); |
|
| 3299 | + $expression = str_replace('\/', '/', $expression); |
|
| 3300 | + $expression = str_replace('/', '\/', $expression); |
|
| 3301 | 3301 | |
| 3302 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3302 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3303 | 3303 | } |
| 3304 | 3304 | |
| 3305 | 3305 | |
@@ -3317,25 +3317,25 @@ discard block |
||
| 3317 | 3317 | **/ |
| 3318 | 3318 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3319 | 3319 | |
| 3320 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3321 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3320 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3321 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3322 | 3322 | |
| 3323 | - if ( |
|
| 3324 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3325 | - and preg_match_all( |
|
| 3326 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3327 | - $t, |
|
| 3328 | - $matches, |
|
| 3329 | - PREG_PATTERN_ORDER |
|
| 3330 | - ) |
|
| 3331 | - ) { |
|
| 3332 | - if (!isset($doublons['documents'])) { |
|
| 3333 | - $doublons['documents'] = ''; |
|
| 3334 | - } |
|
| 3335 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3336 | - } |
|
| 3323 | + if ( |
|
| 3324 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3325 | + and preg_match_all( |
|
| 3326 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3327 | + $t, |
|
| 3328 | + $matches, |
|
| 3329 | + PREG_PATTERN_ORDER |
|
| 3330 | + ) |
|
| 3331 | + ) { |
|
| 3332 | + if (!isset($doublons['documents'])) { |
|
| 3333 | + $doublons['documents'] = ''; |
|
| 3334 | + } |
|
| 3335 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3336 | + } |
|
| 3337 | 3337 | |
| 3338 | - return $letexte; |
|
| 3338 | + return $letexte; |
|
| 3339 | 3339 | } |
| 3340 | 3340 | |
| 3341 | 3341 | /** |
@@ -3349,7 +3349,7 @@ discard block |
||
| 3349 | 3349 | * @return string Chaîne vide |
| 3350 | 3350 | **/ |
| 3351 | 3351 | function vide($texte) { |
| 3352 | - return ''; |
|
| 3352 | + return ''; |
|
| 3353 | 3353 | } |
| 3354 | 3354 | |
| 3355 | 3355 | // |
@@ -3378,23 +3378,23 @@ discard block |
||
| 3378 | 3378 | * Code HTML résultant |
| 3379 | 3379 | **/ |
| 3380 | 3380 | function env_to_params($env, $ignore_params = []) { |
| 3381 | - $ignore_params = array_merge( |
|
| 3382 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3383 | - $ignore_params |
|
| 3384 | - ); |
|
| 3385 | - if (!is_array($env)) { |
|
| 3386 | - $env = unserialize($env); |
|
| 3387 | - } |
|
| 3388 | - $texte = ''; |
|
| 3389 | - if ($env) { |
|
| 3390 | - foreach ($env as $i => $j) { |
|
| 3391 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3392 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3393 | - } |
|
| 3394 | - } |
|
| 3395 | - } |
|
| 3396 | - |
|
| 3397 | - return $texte; |
|
| 3381 | + $ignore_params = array_merge( |
|
| 3382 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3383 | + $ignore_params |
|
| 3384 | + ); |
|
| 3385 | + if (!is_array($env)) { |
|
| 3386 | + $env = unserialize($env); |
|
| 3387 | + } |
|
| 3388 | + $texte = ''; |
|
| 3389 | + if ($env) { |
|
| 3390 | + foreach ($env as $i => $j) { |
|
| 3391 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3392 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3393 | + } |
|
| 3394 | + } |
|
| 3395 | + } |
|
| 3396 | + |
|
| 3397 | + return $texte; |
|
| 3398 | 3398 | } |
| 3399 | 3399 | |
| 3400 | 3400 | /** |
@@ -3417,23 +3417,23 @@ discard block |
||
| 3417 | 3417 | * Code HTML résultant |
| 3418 | 3418 | **/ |
| 3419 | 3419 | function env_to_attributs($env, $ignore_params = []) { |
| 3420 | - $ignore_params = array_merge( |
|
| 3421 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3422 | - $ignore_params |
|
| 3423 | - ); |
|
| 3424 | - if (!is_array($env)) { |
|
| 3425 | - $env = unserialize($env); |
|
| 3426 | - } |
|
| 3427 | - $texte = ''; |
|
| 3428 | - if ($env) { |
|
| 3429 | - foreach ($env as $i => $j) { |
|
| 3430 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3431 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3432 | - } |
|
| 3433 | - } |
|
| 3434 | - } |
|
| 3420 | + $ignore_params = array_merge( |
|
| 3421 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3422 | + $ignore_params |
|
| 3423 | + ); |
|
| 3424 | + if (!is_array($env)) { |
|
| 3425 | + $env = unserialize($env); |
|
| 3426 | + } |
|
| 3427 | + $texte = ''; |
|
| 3428 | + if ($env) { |
|
| 3429 | + foreach ($env as $i => $j) { |
|
| 3430 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3431 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3432 | + } |
|
| 3433 | + } |
|
| 3434 | + } |
|
| 3435 | 3435 | |
| 3436 | - return $texte; |
|
| 3436 | + return $texte; |
|
| 3437 | 3437 | } |
| 3438 | 3438 | |
| 3439 | 3439 | |
@@ -3451,7 +3451,7 @@ discard block |
||
| 3451 | 3451 | * @return string Chaînes concaténés |
| 3452 | 3452 | **/ |
| 3453 | 3453 | function concat(...$args): string { |
| 3454 | - return join('', $args); |
|
| 3454 | + return join('', $args); |
|
| 3455 | 3455 | } |
| 3456 | 3456 | |
| 3457 | 3457 | |
@@ -3471,23 +3471,23 @@ discard block |
||
| 3471 | 3471 | * Contenu du ou des fichiers, concaténé |
| 3472 | 3472 | **/ |
| 3473 | 3473 | function charge_scripts($files, $script = true) { |
| 3474 | - $flux = ''; |
|
| 3475 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3476 | - if (!is_string($file)) { |
|
| 3477 | - continue; |
|
| 3478 | - } |
|
| 3479 | - if ($script) { |
|
| 3480 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3481 | - } |
|
| 3482 | - if ($file) { |
|
| 3483 | - $path = find_in_path($file); |
|
| 3484 | - if ($path) { |
|
| 3485 | - $flux .= spip_file_get_contents($path); |
|
| 3486 | - } |
|
| 3487 | - } |
|
| 3488 | - } |
|
| 3489 | - |
|
| 3490 | - return $flux; |
|
| 3474 | + $flux = ''; |
|
| 3475 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3476 | + if (!is_string($file)) { |
|
| 3477 | + continue; |
|
| 3478 | + } |
|
| 3479 | + if ($script) { |
|
| 3480 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3481 | + } |
|
| 3482 | + if ($file) { |
|
| 3483 | + $path = find_in_path($file); |
|
| 3484 | + if ($path) { |
|
| 3485 | + $flux .= spip_file_get_contents($path); |
|
| 3486 | + } |
|
| 3487 | + } |
|
| 3488 | + } |
|
| 3489 | + |
|
| 3490 | + return $flux; |
|
| 3491 | 3491 | } |
| 3492 | 3492 | |
| 3493 | 3493 | /** |
@@ -3498,22 +3498,22 @@ discard block |
||
| 3498 | 3498 | * @return string |
| 3499 | 3499 | */ |
| 3500 | 3500 | function http_img_variante_svg_si_possible($img_file) { |
| 3501 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3502 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3503 | - if ( |
|
| 3504 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3505 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3506 | - and file_exists($variante_svg_generique) |
|
| 3507 | - ) { |
|
| 3508 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3509 | - $img_file = $variante_svg_size; |
|
| 3510 | - } |
|
| 3511 | - else { |
|
| 3512 | - $img_file = $variante_svg_generique; |
|
| 3513 | - } |
|
| 3514 | - } |
|
| 3501 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3502 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3503 | + if ( |
|
| 3504 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3505 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3506 | + and file_exists($variante_svg_generique) |
|
| 3507 | + ) { |
|
| 3508 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3509 | + $img_file = $variante_svg_size; |
|
| 3510 | + } |
|
| 3511 | + else { |
|
| 3512 | + $img_file = $variante_svg_generique; |
|
| 3513 | + } |
|
| 3514 | + } |
|
| 3515 | 3515 | |
| 3516 | - return $img_file; |
|
| 3516 | + return $img_file; |
|
| 3517 | 3517 | } |
| 3518 | 3518 | |
| 3519 | 3519 | /** |
@@ -3534,54 +3534,54 @@ discard block |
||
| 3534 | 3534 | */ |
| 3535 | 3535 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3536 | 3536 | |
| 3537 | - $img_file = $img; |
|
| 3538 | - if ($p = strpos($img_file, '?')) { |
|
| 3539 | - $img_file = substr($img_file, 0, $p); |
|
| 3540 | - } |
|
| 3541 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3542 | - $img_file = chemin_image($img); |
|
| 3543 | - } |
|
| 3544 | - else { |
|
| 3545 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3546 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3547 | - } |
|
| 3548 | - } |
|
| 3549 | - if (stripos($atts, 'width') === false) { |
|
| 3550 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3551 | - if ( |
|
| 3552 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3553 | - or $options['utiliser_suffixe_size'] == true |
|
| 3554 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3555 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3556 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3557 | - ) { |
|
| 3558 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3559 | - } else { |
|
| 3560 | - $taille = taille_image($img_file); |
|
| 3561 | - [$hauteur, $largeur] = $taille; |
|
| 3562 | - if (!$hauteur or !$largeur) { |
|
| 3563 | - return ''; |
|
| 3564 | - } |
|
| 3565 | - } |
|
| 3566 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3567 | - } |
|
| 3568 | - |
|
| 3569 | - if (file_exists($img_file)) { |
|
| 3570 | - $img_file = timestamp($img_file); |
|
| 3571 | - } |
|
| 3572 | - if ($alt === false) { |
|
| 3573 | - $alt = ''; |
|
| 3574 | - } |
|
| 3575 | - elseif ($alt or $alt === '') { |
|
| 3576 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3577 | - } |
|
| 3578 | - else { |
|
| 3579 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3580 | - } |
|
| 3581 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3582 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3583 | - . ' ' . ltrim($atts) |
|
| 3584 | - . ' />'; |
|
| 3537 | + $img_file = $img; |
|
| 3538 | + if ($p = strpos($img_file, '?')) { |
|
| 3539 | + $img_file = substr($img_file, 0, $p); |
|
| 3540 | + } |
|
| 3541 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3542 | + $img_file = chemin_image($img); |
|
| 3543 | + } |
|
| 3544 | + else { |
|
| 3545 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3546 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3547 | + } |
|
| 3548 | + } |
|
| 3549 | + if (stripos($atts, 'width') === false) { |
|
| 3550 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3551 | + if ( |
|
| 3552 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3553 | + or $options['utiliser_suffixe_size'] == true |
|
| 3554 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3555 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3556 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3557 | + ) { |
|
| 3558 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3559 | + } else { |
|
| 3560 | + $taille = taille_image($img_file); |
|
| 3561 | + [$hauteur, $largeur] = $taille; |
|
| 3562 | + if (!$hauteur or !$largeur) { |
|
| 3563 | + return ''; |
|
| 3564 | + } |
|
| 3565 | + } |
|
| 3566 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3567 | + } |
|
| 3568 | + |
|
| 3569 | + if (file_exists($img_file)) { |
|
| 3570 | + $img_file = timestamp($img_file); |
|
| 3571 | + } |
|
| 3572 | + if ($alt === false) { |
|
| 3573 | + $alt = ''; |
|
| 3574 | + } |
|
| 3575 | + elseif ($alt or $alt === '') { |
|
| 3576 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3577 | + } |
|
| 3578 | + else { |
|
| 3579 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3580 | + } |
|
| 3581 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3582 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3583 | + . ' ' . ltrim($atts) |
|
| 3584 | + . ' />'; |
|
| 3585 | 3585 | } |
| 3586 | 3586 | |
| 3587 | 3587 | /** |
@@ -3593,70 +3593,70 @@ discard block |
||
| 3593 | 3593 | * @return string |
| 3594 | 3594 | */ |
| 3595 | 3595 | function http_style_background($img, $att = '', $size = null) { |
| 3596 | - if ($size and is_numeric($size)) { |
|
| 3597 | - $size = trim($size) . 'px'; |
|
| 3598 | - } |
|
| 3599 | - return " style='background" . |
|
| 3600 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3601 | - . ($size ? "background-size:{$size};" : '') |
|
| 3602 | - . "'"; |
|
| 3596 | + if ($size and is_numeric($size)) { |
|
| 3597 | + $size = trim($size) . 'px'; |
|
| 3598 | + } |
|
| 3599 | + return " style='background" . |
|
| 3600 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3601 | + . ($size ? "background-size:{$size};" : '') |
|
| 3602 | + . "'"; |
|
| 3603 | 3603 | } |
| 3604 | 3604 | |
| 3605 | 3605 | |
| 3606 | 3606 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3607 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3608 | - while (is_null(end($args)) and count($args)) { |
|
| 3609 | - array_pop($args); |
|
| 3610 | - } |
|
| 3611 | - if (!count($args)) { |
|
| 3612 | - return [null, null, null]; |
|
| 3613 | - } |
|
| 3614 | - if (count($args) < 3) { |
|
| 3615 | - $maybe_size = array_pop($args); |
|
| 3616 | - // @2x |
|
| 3617 | - // @1.5x |
|
| 3618 | - // 512 |
|
| 3619 | - // 512x* |
|
| 3620 | - // 512x300 |
|
| 3621 | - if ( |
|
| 3622 | - !strlen($maybe_size) |
|
| 3623 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3624 | - ) { |
|
| 3625 | - $args[] = $maybe_size; |
|
| 3626 | - $maybe_size = null; |
|
| 3627 | - } |
|
| 3628 | - while (count($args) < 2) { |
|
| 3629 | - $args[] = null; // default alt or class |
|
| 3630 | - } |
|
| 3631 | - $args[] = $maybe_size; |
|
| 3632 | - } |
|
| 3633 | - return $args; |
|
| 3607 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3608 | + while (is_null(end($args)) and count($args)) { |
|
| 3609 | + array_pop($args); |
|
| 3610 | + } |
|
| 3611 | + if (!count($args)) { |
|
| 3612 | + return [null, null, null]; |
|
| 3613 | + } |
|
| 3614 | + if (count($args) < 3) { |
|
| 3615 | + $maybe_size = array_pop($args); |
|
| 3616 | + // @2x |
|
| 3617 | + // @1.5x |
|
| 3618 | + // 512 |
|
| 3619 | + // 512x* |
|
| 3620 | + // 512x300 |
|
| 3621 | + if ( |
|
| 3622 | + !strlen($maybe_size) |
|
| 3623 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3624 | + ) { |
|
| 3625 | + $args[] = $maybe_size; |
|
| 3626 | + $maybe_size = null; |
|
| 3627 | + } |
|
| 3628 | + while (count($args) < 2) { |
|
| 3629 | + $args[] = null; // default alt or class |
|
| 3630 | + } |
|
| 3631 | + $args[] = $maybe_size; |
|
| 3632 | + } |
|
| 3633 | + return $args; |
|
| 3634 | 3634 | } |
| 3635 | 3635 | |
| 3636 | 3636 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3637 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3638 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3639 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3640 | - [$h, $w] = taille_image($img); |
|
| 3641 | - $height = intval(round($h / $coef)); |
|
| 3642 | - $width = intval(round($w / $coef)); |
|
| 3643 | - } |
|
| 3644 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3645 | - else { |
|
| 3646 | - $size = explode('x', $size, 2); |
|
| 3647 | - $size = array_map('trim', $size); |
|
| 3648 | - $height = $width = intval(array_shift($size)); |
|
| 3649 | - |
|
| 3650 | - if (count($size) and reset($size)) { |
|
| 3651 | - $height = array_shift($size); |
|
| 3652 | - if ($height === '*') { |
|
| 3653 | - [$h, $w] = taille_image($img); |
|
| 3654 | - $height = intval(round($h * $width / $w)); |
|
| 3655 | - } |
|
| 3656 | - } |
|
| 3657 | - } |
|
| 3658 | - |
|
| 3659 | - return [$width, $height]; |
|
| 3637 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3638 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3639 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3640 | + [$h, $w] = taille_image($img); |
|
| 3641 | + $height = intval(round($h / $coef)); |
|
| 3642 | + $width = intval(round($w / $coef)); |
|
| 3643 | + } |
|
| 3644 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3645 | + else { |
|
| 3646 | + $size = explode('x', $size, 2); |
|
| 3647 | + $size = array_map('trim', $size); |
|
| 3648 | + $height = $width = intval(array_shift($size)); |
|
| 3649 | + |
|
| 3650 | + if (count($size) and reset($size)) { |
|
| 3651 | + $height = array_shift($size); |
|
| 3652 | + if ($height === '*') { |
|
| 3653 | + [$h, $w] = taille_image($img); |
|
| 3654 | + $height = intval(round($h * $width / $w)); |
|
| 3655 | + } |
|
| 3656 | + } |
|
| 3657 | + } |
|
| 3658 | + |
|
| 3659 | + return [$width, $height]; |
|
| 3660 | 3660 | } |
| 3661 | 3661 | |
| 3662 | 3662 | /** |
@@ -3692,43 +3692,43 @@ discard block |
||
| 3692 | 3692 | */ |
| 3693 | 3693 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3694 | 3694 | |
| 3695 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3696 | - |
|
| 3697 | - $img = trim((string) $img); |
|
| 3698 | - if (strpos($img, '<img') === 0) { |
|
| 3699 | - if (!is_null($alt)) { |
|
| 3700 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3701 | - } |
|
| 3702 | - if (!is_null($class)) { |
|
| 3703 | - if (strlen($class)) { |
|
| 3704 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3705 | - } |
|
| 3706 | - else { |
|
| 3707 | - $img = vider_attribut($img, 'class'); |
|
| 3708 | - } |
|
| 3709 | - } |
|
| 3710 | - } |
|
| 3711 | - else { |
|
| 3712 | - $img = http_img_pack( |
|
| 3713 | - $img, |
|
| 3714 | - $alt, |
|
| 3715 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3716 | - '', |
|
| 3717 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3718 | - ); |
|
| 3719 | - if (is_null($alt)) { |
|
| 3720 | - $img = vider_attribut($img, 'alt'); |
|
| 3721 | - } |
|
| 3722 | - } |
|
| 3723 | - |
|
| 3724 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3725 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3726 | - |
|
| 3727 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3728 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3729 | - } |
|
| 3730 | - |
|
| 3731 | - return $img; |
|
| 3695 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3696 | + |
|
| 3697 | + $img = trim((string) $img); |
|
| 3698 | + if (strpos($img, '<img') === 0) { |
|
| 3699 | + if (!is_null($alt)) { |
|
| 3700 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3701 | + } |
|
| 3702 | + if (!is_null($class)) { |
|
| 3703 | + if (strlen($class)) { |
|
| 3704 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3705 | + } |
|
| 3706 | + else { |
|
| 3707 | + $img = vider_attribut($img, 'class'); |
|
| 3708 | + } |
|
| 3709 | + } |
|
| 3710 | + } |
|
| 3711 | + else { |
|
| 3712 | + $img = http_img_pack( |
|
| 3713 | + $img, |
|
| 3714 | + $alt, |
|
| 3715 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3716 | + '', |
|
| 3717 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3718 | + ); |
|
| 3719 | + if (is_null($alt)) { |
|
| 3720 | + $img = vider_attribut($img, 'alt'); |
|
| 3721 | + } |
|
| 3722 | + } |
|
| 3723 | + |
|
| 3724 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3725 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3726 | + |
|
| 3727 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3728 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3729 | + } |
|
| 3730 | + |
|
| 3731 | + return $img; |
|
| 3732 | 3732 | } |
| 3733 | 3733 | |
| 3734 | 3734 | |
@@ -3762,80 +3762,80 @@ discard block |
||
| 3762 | 3762 | */ |
| 3763 | 3763 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3764 | 3764 | |
| 3765 | - $svg = null; |
|
| 3766 | - $img = trim($img); |
|
| 3767 | - $img_file = $img; |
|
| 3768 | - if (strpos($img, '<svg') === false) { |
|
| 3769 | - if ($p = strpos($img_file, '?')) { |
|
| 3770 | - $img_file = substr($img_file, 0, $p); |
|
| 3771 | - } |
|
| 3772 | - |
|
| 3773 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3774 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3775 | - if (tester_url_absolue($img_file)) { |
|
| 3776 | - include_spip('inc/distant'); |
|
| 3777 | - $fichier = copie_locale($img_file); |
|
| 3778 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3779 | - } |
|
| 3780 | - |
|
| 3781 | - if ( |
|
| 3782 | - !$img_file |
|
| 3783 | - or !file_exists($img_file) |
|
| 3784 | - or !$svg = file_get_contents($img_file) |
|
| 3785 | - ) { |
|
| 3786 | - return ''; |
|
| 3787 | - } |
|
| 3788 | - } |
|
| 3789 | - |
|
| 3790 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3791 | - return ''; |
|
| 3792 | - } |
|
| 3793 | - |
|
| 3794 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3795 | - |
|
| 3796 | - $balise_svg = $match[0]; |
|
| 3797 | - $balise_svg_source = $balise_svg; |
|
| 3798 | - |
|
| 3799 | - // entete XML à supprimer |
|
| 3800 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3801 | - |
|
| 3802 | - // IE est toujours mon ami |
|
| 3803 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3804 | - |
|
| 3805 | - // regler la classe |
|
| 3806 | - if (!is_null($class)) { |
|
| 3807 | - if (strlen($class)) { |
|
| 3808 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3809 | - } |
|
| 3810 | - else { |
|
| 3811 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3812 | - } |
|
| 3813 | - } |
|
| 3814 | - |
|
| 3815 | - // regler le alt |
|
| 3816 | - if ($alt) { |
|
| 3817 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3818 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3819 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3820 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3821 | - $balise_svg .= $title; |
|
| 3822 | - } |
|
| 3823 | - else { |
|
| 3824 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3825 | - } |
|
| 3826 | - |
|
| 3827 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3828 | - |
|
| 3829 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3830 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3831 | - |
|
| 3832 | - if (!function_exists('svg_redimensionner')) { |
|
| 3833 | - include_spip('inc/svg'); |
|
| 3834 | - } |
|
| 3835 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3836 | - } |
|
| 3837 | - |
|
| 3838 | - return $svg; |
|
| 3765 | + $svg = null; |
|
| 3766 | + $img = trim($img); |
|
| 3767 | + $img_file = $img; |
|
| 3768 | + if (strpos($img, '<svg') === false) { |
|
| 3769 | + if ($p = strpos($img_file, '?')) { |
|
| 3770 | + $img_file = substr($img_file, 0, $p); |
|
| 3771 | + } |
|
| 3772 | + |
|
| 3773 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3774 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3775 | + if (tester_url_absolue($img_file)) { |
|
| 3776 | + include_spip('inc/distant'); |
|
| 3777 | + $fichier = copie_locale($img_file); |
|
| 3778 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3779 | + } |
|
| 3780 | + |
|
| 3781 | + if ( |
|
| 3782 | + !$img_file |
|
| 3783 | + or !file_exists($img_file) |
|
| 3784 | + or !$svg = file_get_contents($img_file) |
|
| 3785 | + ) { |
|
| 3786 | + return ''; |
|
| 3787 | + } |
|
| 3788 | + } |
|
| 3789 | + |
|
| 3790 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3791 | + return ''; |
|
| 3792 | + } |
|
| 3793 | + |
|
| 3794 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3795 | + |
|
| 3796 | + $balise_svg = $match[0]; |
|
| 3797 | + $balise_svg_source = $balise_svg; |
|
| 3798 | + |
|
| 3799 | + // entete XML à supprimer |
|
| 3800 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3801 | + |
|
| 3802 | + // IE est toujours mon ami |
|
| 3803 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3804 | + |
|
| 3805 | + // regler la classe |
|
| 3806 | + if (!is_null($class)) { |
|
| 3807 | + if (strlen($class)) { |
|
| 3808 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3809 | + } |
|
| 3810 | + else { |
|
| 3811 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3812 | + } |
|
| 3813 | + } |
|
| 3814 | + |
|
| 3815 | + // regler le alt |
|
| 3816 | + if ($alt) { |
|
| 3817 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3818 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3819 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3820 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3821 | + $balise_svg .= $title; |
|
| 3822 | + } |
|
| 3823 | + else { |
|
| 3824 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3825 | + } |
|
| 3826 | + |
|
| 3827 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3828 | + |
|
| 3829 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3830 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3831 | + |
|
| 3832 | + if (!function_exists('svg_redimensionner')) { |
|
| 3833 | + include_spip('inc/svg'); |
|
| 3834 | + } |
|
| 3835 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3836 | + } |
|
| 3837 | + |
|
| 3838 | + return $svg; |
|
| 3839 | 3839 | } |
| 3840 | 3840 | |
| 3841 | 3841 | |
@@ -3861,18 +3861,18 @@ discard block |
||
| 3861 | 3861 | * Code HTML résultant |
| 3862 | 3862 | **/ |
| 3863 | 3863 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3864 | - $texte = ''; |
|
| 3865 | - if (is_array($tableau)) { |
|
| 3866 | - foreach ($tableau as $k => $v) { |
|
| 3867 | - $res = recuperer_fond( |
|
| 3868 | - 'modeles/' . $modele, |
|
| 3869 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3870 | - ); |
|
| 3871 | - $texte .= $res; |
|
| 3872 | - } |
|
| 3873 | - } |
|
| 3864 | + $texte = ''; |
|
| 3865 | + if (is_array($tableau)) { |
|
| 3866 | + foreach ($tableau as $k => $v) { |
|
| 3867 | + $res = recuperer_fond( |
|
| 3868 | + 'modeles/' . $modele, |
|
| 3869 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3870 | + ); |
|
| 3871 | + $texte .= $res; |
|
| 3872 | + } |
|
| 3873 | + } |
|
| 3874 | 3874 | |
| 3875 | - return $texte; |
|
| 3875 | + return $texte; |
|
| 3876 | 3876 | } |
| 3877 | 3877 | |
| 3878 | 3878 | |
@@ -3897,37 +3897,37 @@ discard block |
||
| 3897 | 3897 | * - tout : retourne toutes les informations du plugin actif |
| 3898 | 3898 | **/ |
| 3899 | 3899 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3900 | - include_spip('inc/plugin'); |
|
| 3901 | - $plugin = strtoupper($plugin); |
|
| 3902 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3903 | - |
|
| 3904 | - if (!$plugin) { |
|
| 3905 | - return serialize(array_keys($plugins_actifs)); |
|
| 3906 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3907 | - return ''; |
|
| 3908 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3909 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3910 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3911 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3912 | - } else { |
|
| 3913 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3914 | - // On prend en compte les extensions |
|
| 3915 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3916 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3917 | - } else { |
|
| 3918 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3919 | - } |
|
| 3920 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3921 | - return ''; |
|
| 3922 | - } |
|
| 3923 | - if ($type_info == 'tout') { |
|
| 3924 | - return $infos; |
|
| 3925 | - } elseif ($type_info == 'est_actif') { |
|
| 3926 | - return $infos ? 1 : 0; |
|
| 3927 | - } else { |
|
| 3928 | - return strval($infos[$type_info]); |
|
| 3929 | - } |
|
| 3930 | - } |
|
| 3900 | + include_spip('inc/plugin'); |
|
| 3901 | + $plugin = strtoupper($plugin); |
|
| 3902 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3903 | + |
|
| 3904 | + if (!$plugin) { |
|
| 3905 | + return serialize(array_keys($plugins_actifs)); |
|
| 3906 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3907 | + return ''; |
|
| 3908 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3909 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3910 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3911 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3912 | + } else { |
|
| 3913 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3914 | + // On prend en compte les extensions |
|
| 3915 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3916 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3917 | + } else { |
|
| 3918 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3919 | + } |
|
| 3920 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3921 | + return ''; |
|
| 3922 | + } |
|
| 3923 | + if ($type_info == 'tout') { |
|
| 3924 | + return $infos; |
|
| 3925 | + } elseif ($type_info == 'est_actif') { |
|
| 3926 | + return $infos ? 1 : 0; |
|
| 3927 | + } else { |
|
| 3928 | + return strval($infos[$type_info]); |
|
| 3929 | + } |
|
| 3930 | + } |
|
| 3931 | 3931 | } |
| 3932 | 3932 | |
| 3933 | 3933 | |
@@ -3954,9 +3954,9 @@ discard block |
||
| 3954 | 3954 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3955 | 3955 | */ |
| 3956 | 3956 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3957 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3957 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3958 | 3958 | |
| 3959 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3959 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3960 | 3960 | } |
| 3961 | 3961 | |
| 3962 | 3962 | |
@@ -3986,19 +3986,19 @@ discard block |
||
| 3986 | 3986 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3987 | 3987 | */ |
| 3988 | 3988 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3989 | - static $puce_statut = null; |
|
| 3990 | - if (!$puce_statut) { |
|
| 3991 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3992 | - } |
|
| 3989 | + static $puce_statut = null; |
|
| 3990 | + if (!$puce_statut) { |
|
| 3991 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3992 | + } |
|
| 3993 | 3993 | |
| 3994 | - return $puce_statut( |
|
| 3995 | - $id_objet, |
|
| 3996 | - $statut, |
|
| 3997 | - $id_parent, |
|
| 3998 | - $objet, |
|
| 3999 | - false, |
|
| 4000 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4001 | - ); |
|
| 3994 | + return $puce_statut( |
|
| 3995 | + $id_objet, |
|
| 3996 | + $statut, |
|
| 3997 | + $id_parent, |
|
| 3998 | + $objet, |
|
| 3999 | + false, |
|
| 4000 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4001 | + ); |
|
| 4002 | 4002 | } |
| 4003 | 4003 | |
| 4004 | 4004 | |
@@ -4025,98 +4025,98 @@ discard block |
||
| 4025 | 4025 | * hash du contexte |
| 4026 | 4026 | */ |
| 4027 | 4027 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 4028 | - $env = null; |
|
| 4029 | - if ( |
|
| 4030 | - is_string($c) |
|
| 4031 | - and @unserialize($c) !== false |
|
| 4032 | - ) { |
|
| 4033 | - $c = unserialize($c); |
|
| 4034 | - } |
|
| 4035 | - |
|
| 4036 | - // supprimer les parametres debut_x |
|
| 4037 | - // pour que la pagination ajax ne soit pas plantee |
|
| 4038 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4039 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4040 | - if (is_array($c)) { |
|
| 4041 | - foreach ($c as $k => $v) { |
|
| 4042 | - if (strpos($k, 'debut_') === 0) { |
|
| 4043 | - unset($c[$k]); |
|
| 4044 | - } |
|
| 4045 | - } |
|
| 4046 | - } |
|
| 4047 | - |
|
| 4048 | - if (!function_exists('calculer_cle_action')) { |
|
| 4049 | - include_spip('inc/securiser_action'); |
|
| 4050 | - } |
|
| 4051 | - |
|
| 4052 | - $c = serialize($c); |
|
| 4053 | - $cle = calculer_cle_action($form . $c); |
|
| 4054 | - $c = "$cle:$c"; |
|
| 4055 | - |
|
| 4056 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4057 | - // par defaut, sauf si cette configuration a été forcée |
|
| 4058 | - // OU que la longueur de l’argument géneré est plus long |
|
| 4059 | - // que ce qui est toléré. |
|
| 4060 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4061 | - if (!$cache_contextes_ajax) { |
|
| 4062 | - $env = $c; |
|
| 4063 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4064 | - $env = gzdeflate($env); |
|
| 4065 | - } |
|
| 4066 | - $env = _xor($env); |
|
| 4067 | - $env = base64_encode($env); |
|
| 4068 | - $len = strlen($env); |
|
| 4069 | - // Si l’url est trop longue pour le navigateur |
|
| 4070 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4071 | - if ($len > $max_len) { |
|
| 4072 | - $cache_contextes_ajax = true; |
|
| 4073 | - spip_log( |
|
| 4074 | - 'Contextes AJAX forces en fichiers !' |
|
| 4075 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4076 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4077 | - _LOG_AVERTISSEMENT |
|
| 4078 | - ); |
|
| 4079 | - } |
|
| 4080 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4081 | - elseif ( |
|
| 4082 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4083 | - and $max_len < $len |
|
| 4084 | - ) { |
|
| 4085 | - $cache_contextes_ajax = true; |
|
| 4086 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4087 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4088 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4089 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4090 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4091 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4092 | - } |
|
| 4093 | - } |
|
| 4094 | - |
|
| 4095 | - if ($cache_contextes_ajax) { |
|
| 4096 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4097 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4098 | - $md5 = md5($c); |
|
| 4099 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4100 | - $env = $md5; |
|
| 4101 | - } |
|
| 4102 | - |
|
| 4103 | - if ($emboite === null) { |
|
| 4104 | - return $env; |
|
| 4105 | - } |
|
| 4106 | - if (!trim($emboite)) { |
|
| 4107 | - return ''; |
|
| 4108 | - } |
|
| 4109 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4110 | - $r = self(); |
|
| 4111 | - $r = ' data-origin="' . $r . '"'; |
|
| 4112 | - $class = 'ajaxbloc'; |
|
| 4113 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4114 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4115 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4116 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4117 | - } |
|
| 4118 | - |
|
| 4119 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4028 | + $env = null; |
|
| 4029 | + if ( |
|
| 4030 | + is_string($c) |
|
| 4031 | + and @unserialize($c) !== false |
|
| 4032 | + ) { |
|
| 4033 | + $c = unserialize($c); |
|
| 4034 | + } |
|
| 4035 | + |
|
| 4036 | + // supprimer les parametres debut_x |
|
| 4037 | + // pour que la pagination ajax ne soit pas plantee |
|
| 4038 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4039 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4040 | + if (is_array($c)) { |
|
| 4041 | + foreach ($c as $k => $v) { |
|
| 4042 | + if (strpos($k, 'debut_') === 0) { |
|
| 4043 | + unset($c[$k]); |
|
| 4044 | + } |
|
| 4045 | + } |
|
| 4046 | + } |
|
| 4047 | + |
|
| 4048 | + if (!function_exists('calculer_cle_action')) { |
|
| 4049 | + include_spip('inc/securiser_action'); |
|
| 4050 | + } |
|
| 4051 | + |
|
| 4052 | + $c = serialize($c); |
|
| 4053 | + $cle = calculer_cle_action($form . $c); |
|
| 4054 | + $c = "$cle:$c"; |
|
| 4055 | + |
|
| 4056 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4057 | + // par defaut, sauf si cette configuration a été forcée |
|
| 4058 | + // OU que la longueur de l’argument géneré est plus long |
|
| 4059 | + // que ce qui est toléré. |
|
| 4060 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4061 | + if (!$cache_contextes_ajax) { |
|
| 4062 | + $env = $c; |
|
| 4063 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4064 | + $env = gzdeflate($env); |
|
| 4065 | + } |
|
| 4066 | + $env = _xor($env); |
|
| 4067 | + $env = base64_encode($env); |
|
| 4068 | + $len = strlen($env); |
|
| 4069 | + // Si l’url est trop longue pour le navigateur |
|
| 4070 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4071 | + if ($len > $max_len) { |
|
| 4072 | + $cache_contextes_ajax = true; |
|
| 4073 | + spip_log( |
|
| 4074 | + 'Contextes AJAX forces en fichiers !' |
|
| 4075 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4076 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4077 | + _LOG_AVERTISSEMENT |
|
| 4078 | + ); |
|
| 4079 | + } |
|
| 4080 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4081 | + elseif ( |
|
| 4082 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4083 | + and $max_len < $len |
|
| 4084 | + ) { |
|
| 4085 | + $cache_contextes_ajax = true; |
|
| 4086 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4087 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4088 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4089 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4090 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4091 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4092 | + } |
|
| 4093 | + } |
|
| 4094 | + |
|
| 4095 | + if ($cache_contextes_ajax) { |
|
| 4096 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4097 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4098 | + $md5 = md5($c); |
|
| 4099 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4100 | + $env = $md5; |
|
| 4101 | + } |
|
| 4102 | + |
|
| 4103 | + if ($emboite === null) { |
|
| 4104 | + return $env; |
|
| 4105 | + } |
|
| 4106 | + if (!trim($emboite)) { |
|
| 4107 | + return ''; |
|
| 4108 | + } |
|
| 4109 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4110 | + $r = self(); |
|
| 4111 | + $r = ' data-origin="' . $r . '"'; |
|
| 4112 | + $class = 'ajaxbloc'; |
|
| 4113 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4114 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4115 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4116 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4117 | + } |
|
| 4118 | + |
|
| 4119 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4120 | 4120 | } |
| 4121 | 4121 | |
| 4122 | 4122 | /** |
@@ -4136,37 +4136,37 @@ discard block |
||
| 4136 | 4136 | * - false : erreur de décodage |
| 4137 | 4137 | */ |
| 4138 | 4138 | function decoder_contexte_ajax($c, $form = '') { |
| 4139 | - if (!function_exists('calculer_cle_action')) { |
|
| 4140 | - include_spip('inc/securiser_action'); |
|
| 4141 | - } |
|
| 4142 | - if ( |
|
| 4143 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4144 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4145 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4146 | - ) { |
|
| 4147 | - $c = $contexte; |
|
| 4148 | - } else { |
|
| 4149 | - $c = @base64_decode($c); |
|
| 4150 | - $c = _xor($c); |
|
| 4151 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4152 | - $c = @gzinflate($c); |
|
| 4153 | - } |
|
| 4154 | - } |
|
| 4155 | - |
|
| 4156 | - // extraire la signature en debut de contexte |
|
| 4157 | - // et la verifier avant de deserializer |
|
| 4158 | - // format : signature:donneesserializees |
|
| 4159 | - if ($p = strpos($c, ':')) { |
|
| 4160 | - $cle = substr($c, 0, $p); |
|
| 4161 | - $c = substr($c, $p + 1); |
|
| 4162 | - |
|
| 4163 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4164 | - $env = @unserialize($c); |
|
| 4165 | - return $env; |
|
| 4166 | - } |
|
| 4167 | - } |
|
| 4168 | - |
|
| 4169 | - return false; |
|
| 4139 | + if (!function_exists('calculer_cle_action')) { |
|
| 4140 | + include_spip('inc/securiser_action'); |
|
| 4141 | + } |
|
| 4142 | + if ( |
|
| 4143 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4144 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4145 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4146 | + ) { |
|
| 4147 | + $c = $contexte; |
|
| 4148 | + } else { |
|
| 4149 | + $c = @base64_decode($c); |
|
| 4150 | + $c = _xor($c); |
|
| 4151 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4152 | + $c = @gzinflate($c); |
|
| 4153 | + } |
|
| 4154 | + } |
|
| 4155 | + |
|
| 4156 | + // extraire la signature en debut de contexte |
|
| 4157 | + // et la verifier avant de deserializer |
|
| 4158 | + // format : signature:donneesserializees |
|
| 4159 | + if ($p = strpos($c, ':')) { |
|
| 4160 | + $cle = substr($c, 0, $p); |
|
| 4161 | + $c = substr($c, $p + 1); |
|
| 4162 | + |
|
| 4163 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4164 | + $env = @unserialize($c); |
|
| 4165 | + return $env; |
|
| 4166 | + } |
|
| 4167 | + } |
|
| 4168 | + |
|
| 4169 | + return false; |
|
| 4170 | 4170 | } |
| 4171 | 4171 | |
| 4172 | 4172 | |
@@ -4184,20 +4184,20 @@ discard block |
||
| 4184 | 4184 | * Message décrypté ou encrypté |
| 4185 | 4185 | **/ |
| 4186 | 4186 | function _xor($message, $key = null) { |
| 4187 | - if (is_null($key)) { |
|
| 4188 | - if (!function_exists('calculer_cle_action')) { |
|
| 4189 | - include_spip('inc/securiser_action'); |
|
| 4190 | - } |
|
| 4191 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4192 | - } |
|
| 4187 | + if (is_null($key)) { |
|
| 4188 | + if (!function_exists('calculer_cle_action')) { |
|
| 4189 | + include_spip('inc/securiser_action'); |
|
| 4190 | + } |
|
| 4191 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4192 | + } |
|
| 4193 | 4193 | |
| 4194 | - $keylen = strlen($key); |
|
| 4195 | - $messagelen = strlen($message); |
|
| 4196 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4197 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4198 | - } |
|
| 4194 | + $keylen = strlen($key); |
|
| 4195 | + $messagelen = strlen($message); |
|
| 4196 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4197 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4198 | + } |
|
| 4199 | 4199 | |
| 4200 | - return $message; |
|
| 4200 | + return $message; |
|
| 4201 | 4201 | } |
| 4202 | 4202 | |
| 4203 | 4203 | /** |
@@ -4211,7 +4211,7 @@ discard block |
||
| 4211 | 4211 | * @return string |
| 4212 | 4212 | */ |
| 4213 | 4213 | function url_reponse_forum($texte) { |
| 4214 | - return $texte; |
|
| 4214 | + return $texte; |
|
| 4215 | 4215 | } |
| 4216 | 4216 | |
| 4217 | 4217 | /** |
@@ -4225,7 +4225,7 @@ discard block |
||
| 4225 | 4225 | * @return string |
| 4226 | 4226 | */ |
| 4227 | 4227 | function url_rss_forum($texte) { |
| 4228 | - return $texte; |
|
| 4228 | + return $texte; |
|
| 4229 | 4229 | } |
| 4230 | 4230 | |
| 4231 | 4231 | |
@@ -4264,37 +4264,37 @@ discard block |
||
| 4264 | 4264 | * Code HTML |
| 4265 | 4265 | */ |
| 4266 | 4266 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4267 | - if ($on) { |
|
| 4268 | - $bal = 'strong'; |
|
| 4269 | - $class = ''; |
|
| 4270 | - $att = ''; |
|
| 4271 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4272 | - // a.active span.selected.active etc.... |
|
| 4273 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4274 | - $on = explode('.', $on); |
|
| 4275 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4276 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4277 | - $bal = array_shift($on); |
|
| 4278 | - $class = implode(' ', $on); |
|
| 4279 | - if ($bal == 'a') { |
|
| 4280 | - $att = 'href="#" '; |
|
| 4281 | - } |
|
| 4282 | - } |
|
| 4283 | - } |
|
| 4284 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4285 | - } else { |
|
| 4286 | - $bal = 'a'; |
|
| 4287 | - $att = "href='$url'" |
|
| 4288 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4289 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4290 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4291 | - . $evt; |
|
| 4292 | - } |
|
| 4293 | - if ($libelle === null) { |
|
| 4294 | - $libelle = $url; |
|
| 4295 | - } |
|
| 4296 | - |
|
| 4297 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4267 | + if ($on) { |
|
| 4268 | + $bal = 'strong'; |
|
| 4269 | + $class = ''; |
|
| 4270 | + $att = ''; |
|
| 4271 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4272 | + // a.active span.selected.active etc.... |
|
| 4273 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4274 | + $on = explode('.', $on); |
|
| 4275 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4276 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4277 | + $bal = array_shift($on); |
|
| 4278 | + $class = implode(' ', $on); |
|
| 4279 | + if ($bal == 'a') { |
|
| 4280 | + $att = 'href="#" '; |
|
| 4281 | + } |
|
| 4282 | + } |
|
| 4283 | + } |
|
| 4284 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4285 | + } else { |
|
| 4286 | + $bal = 'a'; |
|
| 4287 | + $att = "href='$url'" |
|
| 4288 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4289 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4290 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4291 | + . $evt; |
|
| 4292 | + } |
|
| 4293 | + if ($libelle === null) { |
|
| 4294 | + $libelle = $url; |
|
| 4295 | + } |
|
| 4296 | + |
|
| 4297 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4298 | 4298 | } |
| 4299 | 4299 | |
| 4300 | 4300 | |
@@ -4311,39 +4311,39 @@ discard block |
||
| 4311 | 4311 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4312 | 4312 | */ |
| 4313 | 4313 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4314 | - static $local_singulier_ou_pluriel = []; |
|
| 4315 | - |
|
| 4316 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4317 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4318 | - return ''; |
|
| 4319 | - } |
|
| 4320 | - if (!is_array($vars)) { |
|
| 4321 | - return ''; |
|
| 4322 | - } |
|
| 4323 | - |
|
| 4324 | - $langue = $GLOBALS['spip_lang']; |
|
| 4325 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4326 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4327 | - if ( |
|
| 4328 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4329 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4330 | - ) { |
|
| 4331 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4332 | - } |
|
| 4333 | - } |
|
| 4334 | - |
|
| 4335 | - // si on a une surcharge on l'utilise |
|
| 4336 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4337 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4338 | - } |
|
| 4339 | - |
|
| 4340 | - // sinon traitement par defaut |
|
| 4341 | - $vars[$var] = $nb; |
|
| 4342 | - if ($nb >= 2) { |
|
| 4343 | - return _T($chaine_plusieurs, $vars); |
|
| 4344 | - } else { |
|
| 4345 | - return _T($chaine_un, $vars); |
|
| 4346 | - } |
|
| 4314 | + static $local_singulier_ou_pluriel = []; |
|
| 4315 | + |
|
| 4316 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4317 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4318 | + return ''; |
|
| 4319 | + } |
|
| 4320 | + if (!is_array($vars)) { |
|
| 4321 | + return ''; |
|
| 4322 | + } |
|
| 4323 | + |
|
| 4324 | + $langue = $GLOBALS['spip_lang']; |
|
| 4325 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4326 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4327 | + if ( |
|
| 4328 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4329 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4330 | + ) { |
|
| 4331 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4332 | + } |
|
| 4333 | + } |
|
| 4334 | + |
|
| 4335 | + // si on a une surcharge on l'utilise |
|
| 4336 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4337 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4338 | + } |
|
| 4339 | + |
|
| 4340 | + // sinon traitement par defaut |
|
| 4341 | + $vars[$var] = $nb; |
|
| 4342 | + if ($nb >= 2) { |
|
| 4343 | + return _T($chaine_plusieurs, $vars); |
|
| 4344 | + } else { |
|
| 4345 | + return _T($chaine_un, $vars); |
|
| 4346 | + } |
|
| 4347 | 4347 | } |
| 4348 | 4348 | |
| 4349 | 4349 | |
@@ -4371,73 +4371,73 @@ discard block |
||
| 4371 | 4371 | */ |
| 4372 | 4372 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4373 | 4373 | |
| 4374 | - $class_lien = $class_bouton = $class; |
|
| 4375 | - |
|
| 4376 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4377 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4378 | - $class_lien .= ' danger'; |
|
| 4379 | - $class_bouton .= ' btn_danger'; |
|
| 4380 | - } elseif ($fonction == 'rien.gif') { |
|
| 4381 | - $fonction = ''; |
|
| 4382 | - } elseif ($fonction == 'delsafe') { |
|
| 4383 | - $fonction = 'del'; |
|
| 4384 | - } |
|
| 4385 | - |
|
| 4386 | - $fond_origine = $fond; |
|
| 4387 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4388 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4389 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4390 | - } |
|
| 4391 | - |
|
| 4392 | - // Ajouter le type d'objet dans la classe |
|
| 4393 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4394 | - $class_lien .= " $objet_type"; |
|
| 4395 | - $class_bouton .= " $objet_type"; |
|
| 4396 | - |
|
| 4397 | - // Texte |
|
| 4398 | - $alt = attribut_html($texte); |
|
| 4399 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4400 | - |
|
| 4401 | - // Liens : préparer les classes ajax |
|
| 4402 | - $ajax = ''; |
|
| 4403 | - if ($type === 'lien') { |
|
| 4404 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4405 | - $ajax = 'ajax'; |
|
| 4406 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4407 | - $ajax .= ' preload'; |
|
| 4408 | - } |
|
| 4409 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4410 | - $ajax .= ' nocache'; |
|
| 4411 | - } |
|
| 4412 | - $ajax = " class='$ajax'"; |
|
| 4413 | - } |
|
| 4414 | - } |
|
| 4415 | - |
|
| 4416 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4417 | - $size = 24; |
|
| 4418 | - if ( |
|
| 4419 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4420 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4421 | - ) { |
|
| 4422 | - $size = $match[1]; |
|
| 4423 | - } |
|
| 4424 | - $class_lien .= " s$size"; |
|
| 4425 | - $class_bouton .= " s$size"; |
|
| 4426 | - |
|
| 4427 | - // Icône |
|
| 4428 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4429 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4430 | - |
|
| 4431 | - // Markup final |
|
| 4432 | - if ($type == 'lien') { |
|
| 4433 | - return "<span class='icone $class_lien'>" |
|
| 4434 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4435 | - . $icone |
|
| 4436 | - . "<b>$texte</b>" |
|
| 4437 | - . "</a></span>\n"; |
|
| 4438 | - } else { |
|
| 4439 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4440 | - } |
|
| 4374 | + $class_lien = $class_bouton = $class; |
|
| 4375 | + |
|
| 4376 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4377 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4378 | + $class_lien .= ' danger'; |
|
| 4379 | + $class_bouton .= ' btn_danger'; |
|
| 4380 | + } elseif ($fonction == 'rien.gif') { |
|
| 4381 | + $fonction = ''; |
|
| 4382 | + } elseif ($fonction == 'delsafe') { |
|
| 4383 | + $fonction = 'del'; |
|
| 4384 | + } |
|
| 4385 | + |
|
| 4386 | + $fond_origine = $fond; |
|
| 4387 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4388 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4389 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4390 | + } |
|
| 4391 | + |
|
| 4392 | + // Ajouter le type d'objet dans la classe |
|
| 4393 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4394 | + $class_lien .= " $objet_type"; |
|
| 4395 | + $class_bouton .= " $objet_type"; |
|
| 4396 | + |
|
| 4397 | + // Texte |
|
| 4398 | + $alt = attribut_html($texte); |
|
| 4399 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4400 | + |
|
| 4401 | + // Liens : préparer les classes ajax |
|
| 4402 | + $ajax = ''; |
|
| 4403 | + if ($type === 'lien') { |
|
| 4404 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4405 | + $ajax = 'ajax'; |
|
| 4406 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4407 | + $ajax .= ' preload'; |
|
| 4408 | + } |
|
| 4409 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4410 | + $ajax .= ' nocache'; |
|
| 4411 | + } |
|
| 4412 | + $ajax = " class='$ajax'"; |
|
| 4413 | + } |
|
| 4414 | + } |
|
| 4415 | + |
|
| 4416 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4417 | + $size = 24; |
|
| 4418 | + if ( |
|
| 4419 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4420 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4421 | + ) { |
|
| 4422 | + $size = $match[1]; |
|
| 4423 | + } |
|
| 4424 | + $class_lien .= " s$size"; |
|
| 4425 | + $class_bouton .= " s$size"; |
|
| 4426 | + |
|
| 4427 | + // Icône |
|
| 4428 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4429 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4430 | + |
|
| 4431 | + // Markup final |
|
| 4432 | + if ($type == 'lien') { |
|
| 4433 | + return "<span class='icone $class_lien'>" |
|
| 4434 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4435 | + . $icone |
|
| 4436 | + . "<b>$texte</b>" |
|
| 4437 | + . "</a></span>\n"; |
|
| 4438 | + } else { |
|
| 4439 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4440 | + } |
|
| 4441 | 4441 | } |
| 4442 | 4442 | |
| 4443 | 4443 | /** |
@@ -4461,7 +4461,7 @@ discard block |
||
| 4461 | 4461 | * Code HTML du lien |
| 4462 | 4462 | **/ |
| 4463 | 4463 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4464 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4464 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4465 | 4465 | } |
| 4466 | 4466 | |
| 4467 | 4467 | /** |
@@ -4496,7 +4496,7 @@ discard block |
||
| 4496 | 4496 | * Code HTML du lien |
| 4497 | 4497 | **/ |
| 4498 | 4498 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4499 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4499 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4500 | 4500 | } |
| 4501 | 4501 | |
| 4502 | 4502 | /** |
@@ -4541,7 +4541,7 @@ discard block |
||
| 4541 | 4541 | * Code HTML du lien |
| 4542 | 4542 | **/ |
| 4543 | 4543 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4544 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4544 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4545 | 4545 | } |
| 4546 | 4546 | |
| 4547 | 4547 | /** |
@@ -4572,7 +4572,7 @@ discard block |
||
| 4572 | 4572 | * Code HTML du lien |
| 4573 | 4573 | **/ |
| 4574 | 4574 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4575 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4575 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4576 | 4576 | } |
| 4577 | 4577 | |
| 4578 | 4578 | /** |
@@ -4603,7 +4603,7 @@ discard block |
||
| 4603 | 4603 | * Code HTML du lien |
| 4604 | 4604 | */ |
| 4605 | 4605 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4606 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4606 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4607 | 4607 | } |
| 4608 | 4608 | |
| 4609 | 4609 | |
@@ -4625,7 +4625,7 @@ discard block |
||
| 4625 | 4625 | * @return array Liste des éléments |
| 4626 | 4626 | */ |
| 4627 | 4627 | function filtre_explode_dist($a, $b) { |
| 4628 | - return explode($b, (string) $a); |
|
| 4628 | + return explode($b, (string) $a); |
|
| 4629 | 4629 | } |
| 4630 | 4630 | |
| 4631 | 4631 | /** |
@@ -4646,7 +4646,7 @@ discard block |
||
| 4646 | 4646 | * @return string Texte |
| 4647 | 4647 | */ |
| 4648 | 4648 | function filtre_implode_dist($a, $b) { |
| 4649 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4649 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4650 | 4650 | } |
| 4651 | 4651 | |
| 4652 | 4652 | /** |
@@ -4655,22 +4655,22 @@ discard block |
||
| 4655 | 4655 | * @return string Code CSS |
| 4656 | 4656 | */ |
| 4657 | 4657 | function bando_images_background() { |
| 4658 | - include_spip('inc/bandeau'); |
|
| 4659 | - // recuperer tous les boutons et leurs images |
|
| 4660 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4658 | + include_spip('inc/bandeau'); |
|
| 4659 | + // recuperer tous les boutons et leurs images |
|
| 4660 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4661 | 4661 | |
| 4662 | - $res = ''; |
|
| 4663 | - foreach ($boutons as $page => $detail) { |
|
| 4664 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4665 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4666 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4667 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4668 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4669 | - } |
|
| 4670 | - } |
|
| 4671 | - } |
|
| 4662 | + $res = ''; |
|
| 4663 | + foreach ($boutons as $page => $detail) { |
|
| 4664 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4665 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4666 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4667 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4668 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4669 | + } |
|
| 4670 | + } |
|
| 4671 | + } |
|
| 4672 | 4672 | |
| 4673 | - return $res; |
|
| 4673 | + return $res; |
|
| 4674 | 4674 | } |
| 4675 | 4675 | |
| 4676 | 4676 | /** |
@@ -4695,27 +4695,27 @@ discard block |
||
| 4695 | 4695 | */ |
| 4696 | 4696 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4697 | 4697 | |
| 4698 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4699 | - $class_form = ''; |
|
| 4700 | - if (strpos($class, 'ajax') !== false) { |
|
| 4701 | - $class_form = 'ajax'; |
|
| 4702 | - $class = str_replace('ajax', '', $class); |
|
| 4703 | - } |
|
| 4704 | - $class_btn = 'submit ' . trim($class); |
|
| 4698 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4699 | + $class_form = ''; |
|
| 4700 | + if (strpos($class, 'ajax') !== false) { |
|
| 4701 | + $class_form = 'ajax'; |
|
| 4702 | + $class = str_replace('ajax', '', $class); |
|
| 4703 | + } |
|
| 4704 | + $class_btn = 'submit ' . trim($class); |
|
| 4705 | 4705 | |
| 4706 | - if ($confirm) { |
|
| 4707 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4708 | - if ($callback) { |
|
| 4709 | - $callback = "$confirm?($callback):false"; |
|
| 4710 | - } else { |
|
| 4711 | - $callback = $confirm; |
|
| 4712 | - } |
|
| 4713 | - } |
|
| 4714 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4715 | - $title = $title ? " title='$title'" : ''; |
|
| 4706 | + if ($confirm) { |
|
| 4707 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4708 | + if ($callback) { |
|
| 4709 | + $callback = "$confirm?($callback):false"; |
|
| 4710 | + } else { |
|
| 4711 | + $callback = $confirm; |
|
| 4712 | + } |
|
| 4713 | + } |
|
| 4714 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4715 | + $title = $title ? " title='$title'" : ''; |
|
| 4716 | 4716 | |
| 4717 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4718 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4717 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4718 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4719 | 4719 | } |
| 4720 | 4720 | |
| 4721 | 4721 | /** |
@@ -4738,101 +4738,101 @@ discard block |
||
| 4738 | 4738 | * @return string |
| 4739 | 4739 | */ |
| 4740 | 4740 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4741 | - static $trouver_table = null; |
|
| 4742 | - static $objets; |
|
| 4743 | - |
|
| 4744 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4745 | - $id_objet = intval($id_objet); |
|
| 4746 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4747 | - return ''; |
|
| 4748 | - } |
|
| 4749 | - |
|
| 4750 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4751 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4752 | - return ''; |
|
| 4753 | - } |
|
| 4754 | - |
|
| 4755 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4756 | - if ($info == 'url') { |
|
| 4757 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4758 | - } |
|
| 4759 | - |
|
| 4760 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4761 | - $demande_titre = ($info === 'titre'); |
|
| 4762 | - $demande_introduction = ($info === 'introduction'); |
|
| 4763 | - |
|
| 4764 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4765 | - if ( |
|
| 4766 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4767 | - or |
|
| 4768 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4769 | - ) { |
|
| 4770 | - if (!$trouver_table) { |
|
| 4771 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4772 | - } |
|
| 4773 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4774 | - if (!$desc) { |
|
| 4775 | - return $objets[$type_objet] = false; |
|
| 4776 | - } |
|
| 4777 | - |
|
| 4778 | - // Si on demande le titre, on le gere en interne |
|
| 4779 | - $champ_titre = ''; |
|
| 4780 | - if ($demande_titre) { |
|
| 4781 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4782 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4783 | - } |
|
| 4784 | - include_spip('base/abstract_sql'); |
|
| 4785 | - include_spip('base/connect_sql'); |
|
| 4786 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4787 | - '*' . $champ_titre, |
|
| 4788 | - $desc['table_sql'], |
|
| 4789 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4790 | - ); |
|
| 4791 | - |
|
| 4792 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4793 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4794 | - } |
|
| 4795 | - |
|
| 4796 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4797 | - // ajouter la longueur au début des params supplémentaires |
|
| 4798 | - if ($demande_introduction) { |
|
| 4799 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4800 | - array_unshift($params, $introduction_longueur); |
|
| 4801 | - } |
|
| 4802 | - |
|
| 4803 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4804 | - if ( |
|
| 4805 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4806 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4807 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4808 | - ) { |
|
| 4809 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4810 | - } |
|
| 4811 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | - elseif ( |
|
| 4813 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4814 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4815 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4816 | - ) { |
|
| 4817 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4819 | - else { |
|
| 4820 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4821 | - } |
|
| 4822 | - |
|
| 4823 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4824 | - if (!$etoile) { |
|
| 4825 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4826 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4827 | - $info_generee = appliquer_traitement_champ( |
|
| 4828 | - $info_generee, |
|
| 4829 | - $info, |
|
| 4830 | - table_objet($type_objet), |
|
| 4831 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4832 | - ); |
|
| 4833 | - } |
|
| 4834 | - |
|
| 4835 | - return $info_generee; |
|
| 4741 | + static $trouver_table = null; |
|
| 4742 | + static $objets; |
|
| 4743 | + |
|
| 4744 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4745 | + $id_objet = intval($id_objet); |
|
| 4746 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4747 | + return ''; |
|
| 4748 | + } |
|
| 4749 | + |
|
| 4750 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4751 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4752 | + return ''; |
|
| 4753 | + } |
|
| 4754 | + |
|
| 4755 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4756 | + if ($info == 'url') { |
|
| 4757 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4758 | + } |
|
| 4759 | + |
|
| 4760 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4761 | + $demande_titre = ($info === 'titre'); |
|
| 4762 | + $demande_introduction = ($info === 'introduction'); |
|
| 4763 | + |
|
| 4764 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4765 | + if ( |
|
| 4766 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4767 | + or |
|
| 4768 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4769 | + ) { |
|
| 4770 | + if (!$trouver_table) { |
|
| 4771 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4772 | + } |
|
| 4773 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4774 | + if (!$desc) { |
|
| 4775 | + return $objets[$type_objet] = false; |
|
| 4776 | + } |
|
| 4777 | + |
|
| 4778 | + // Si on demande le titre, on le gere en interne |
|
| 4779 | + $champ_titre = ''; |
|
| 4780 | + if ($demande_titre) { |
|
| 4781 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4782 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4783 | + } |
|
| 4784 | + include_spip('base/abstract_sql'); |
|
| 4785 | + include_spip('base/connect_sql'); |
|
| 4786 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4787 | + '*' . $champ_titre, |
|
| 4788 | + $desc['table_sql'], |
|
| 4789 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4790 | + ); |
|
| 4791 | + |
|
| 4792 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4793 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4794 | + } |
|
| 4795 | + |
|
| 4796 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4797 | + // ajouter la longueur au début des params supplémentaires |
|
| 4798 | + if ($demande_introduction) { |
|
| 4799 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4800 | + array_unshift($params, $introduction_longueur); |
|
| 4801 | + } |
|
| 4802 | + |
|
| 4803 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4804 | + if ( |
|
| 4805 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4806 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4807 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4808 | + ) { |
|
| 4809 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4810 | + } |
|
| 4811 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4812 | + elseif ( |
|
| 4813 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4814 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4815 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4816 | + ) { |
|
| 4817 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4818 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4819 | + else { |
|
| 4820 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4821 | + } |
|
| 4822 | + |
|
| 4823 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4824 | + if (!$etoile) { |
|
| 4825 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4826 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4827 | + $info_generee = appliquer_traitement_champ( |
|
| 4828 | + $info_generee, |
|
| 4829 | + $info, |
|
| 4830 | + table_objet($type_objet), |
|
| 4831 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4832 | + ); |
|
| 4833 | + } |
|
| 4834 | + |
|
| 4835 | + return $info_generee; |
|
| 4836 | 4836 | } |
| 4837 | 4837 | |
| 4838 | 4838 | /** |
@@ -4840,7 +4840,7 @@ discard block |
||
| 4840 | 4840 | * @see generer_objet_info |
| 4841 | 4841 | */ |
| 4842 | 4842 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4843 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4843 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4844 | 4844 | } |
| 4845 | 4845 | |
| 4846 | 4846 | /** |
@@ -4873,36 +4873,36 @@ discard block |
||
| 4873 | 4873 | */ |
| 4874 | 4874 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4875 | 4875 | |
| 4876 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4877 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4878 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4879 | - if (isset($ligne_sql['chapo'])) { |
|
| 4880 | - $chapo = $ligne_sql['chapo']; |
|
| 4881 | - $texte = strlen($descriptif) ? |
|
| 4882 | - '' : |
|
| 4883 | - "$chapo \n\n $texte"; |
|
| 4884 | - } |
|
| 4876 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4877 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4878 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4879 | + if (isset($ligne_sql['chapo'])) { |
|
| 4880 | + $chapo = $ligne_sql['chapo']; |
|
| 4881 | + $texte = strlen($descriptif) ? |
|
| 4882 | + '' : |
|
| 4883 | + "$chapo \n\n $texte"; |
|
| 4884 | + } |
|
| 4885 | 4885 | |
| 4886 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4887 | - if (!intval($longueur_ou_suite)) { |
|
| 4888 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4889 | - } else { |
|
| 4890 | - $longueur = intval($longueur_ou_suite); |
|
| 4891 | - } |
|
| 4886 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4887 | + if (!intval($longueur_ou_suite)) { |
|
| 4888 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4889 | + } else { |
|
| 4890 | + $longueur = intval($longueur_ou_suite); |
|
| 4891 | + } |
|
| 4892 | 4892 | |
| 4893 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4894 | - // Ex : #INTRODUCTION{...} |
|
| 4895 | - if ( |
|
| 4896 | - is_null($suite) |
|
| 4897 | - and !intval($longueur_ou_suite) |
|
| 4898 | - ) { |
|
| 4899 | - $suite = $longueur_ou_suite; |
|
| 4900 | - } |
|
| 4893 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4894 | + // Ex : #INTRODUCTION{...} |
|
| 4895 | + if ( |
|
| 4896 | + is_null($suite) |
|
| 4897 | + and !intval($longueur_ou_suite) |
|
| 4898 | + ) { |
|
| 4899 | + $suite = $longueur_ou_suite; |
|
| 4900 | + } |
|
| 4901 | 4901 | |
| 4902 | - $f = chercher_filtre('introduction'); |
|
| 4903 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4902 | + $f = chercher_filtre('introduction'); |
|
| 4903 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4904 | 4904 | |
| 4905 | - return $introduction; |
|
| 4905 | + return $introduction; |
|
| 4906 | 4906 | } |
| 4907 | 4907 | |
| 4908 | 4908 | /** |
@@ -4910,7 +4910,7 @@ discard block |
||
| 4910 | 4910 | * @see generer_objet_introduction |
| 4911 | 4911 | */ |
| 4912 | 4912 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4913 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4913 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4914 | 4914 | } |
| 4915 | 4915 | |
| 4916 | 4916 | /** |
@@ -4924,49 +4924,49 @@ discard block |
||
| 4924 | 4924 | * @return string |
| 4925 | 4925 | */ |
| 4926 | 4926 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4927 | - if (!$champ) { |
|
| 4928 | - return $texte; |
|
| 4929 | - } |
|
| 4927 | + if (!$champ) { |
|
| 4928 | + return $texte; |
|
| 4929 | + } |
|
| 4930 | 4930 | |
| 4931 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4932 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4933 | - include_fichiers_fonctions(); |
|
| 4931 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4932 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4933 | + include_fichiers_fonctions(); |
|
| 4934 | 4934 | |
| 4935 | - $champ = strtoupper($champ); |
|
| 4936 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4937 | - if (!$traitements or !is_array($traitements)) { |
|
| 4938 | - return $texte; |
|
| 4939 | - } |
|
| 4935 | + $champ = strtoupper($champ); |
|
| 4936 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4937 | + if (!$traitements or !is_array($traitements)) { |
|
| 4938 | + return $texte; |
|
| 4939 | + } |
|
| 4940 | 4940 | |
| 4941 | - $traitement = ''; |
|
| 4942 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4943 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4944 | - $table_objet = table_objet($table_objet); |
|
| 4945 | - if (isset($traitements[$table_objet])) { |
|
| 4946 | - $traitement = $traitements[$table_objet]; |
|
| 4947 | - } |
|
| 4948 | - } |
|
| 4949 | - if (!$traitement and isset($traitements[0])) { |
|
| 4950 | - $traitement = $traitements[0]; |
|
| 4951 | - } |
|
| 4952 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4941 | + $traitement = ''; |
|
| 4942 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4943 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4944 | + $table_objet = table_objet($table_objet); |
|
| 4945 | + if (isset($traitements[$table_objet])) { |
|
| 4946 | + $traitement = $traitements[$table_objet]; |
|
| 4947 | + } |
|
| 4948 | + } |
|
| 4949 | + if (!$traitement and isset($traitements[0])) { |
|
| 4950 | + $traitement = $traitements[0]; |
|
| 4951 | + } |
|
| 4952 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4953 | 4953 | |
| 4954 | - if (!$traitement) { |
|
| 4955 | - return $texte; |
|
| 4956 | - } |
|
| 4954 | + if (!$traitement) { |
|
| 4955 | + return $texte; |
|
| 4956 | + } |
|
| 4957 | 4957 | |
| 4958 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4958 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4959 | 4959 | |
| 4960 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4961 | - if (test_espace_prive()) { |
|
| 4962 | - $env['espace_prive'] = 1; |
|
| 4963 | - } |
|
| 4960 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4961 | + if (test_espace_prive()) { |
|
| 4962 | + $env['espace_prive'] = 1; |
|
| 4963 | + } |
|
| 4964 | 4964 | |
| 4965 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4966 | - $Pile = [0 => $env]; |
|
| 4967 | - eval("\$texte = $traitement;"); |
|
| 4965 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4966 | + $Pile = [0 => $env]; |
|
| 4967 | + eval("\$texte = $traitement;"); |
|
| 4968 | 4968 | |
| 4969 | - return $texte; |
|
| 4969 | + return $texte; |
|
| 4970 | 4970 | } |
| 4971 | 4971 | |
| 4972 | 4972 | |
@@ -4980,21 +4980,21 @@ discard block |
||
| 4980 | 4980 | * @return string |
| 4981 | 4981 | */ |
| 4982 | 4982 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4983 | - include_spip('inc/liens'); |
|
| 4984 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4985 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4986 | - // le raccourcis n'est plus valide |
|
| 4987 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4988 | - // on essaye avec generer_info_entite ? |
|
| 4989 | - if (!strlen($titre) and !$connect) { |
|
| 4990 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4991 | - } |
|
| 4992 | - if (!strlen($titre)) { |
|
| 4993 | - $titre = _T('info_sans_titre'); |
|
| 4994 | - } |
|
| 4995 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4983 | + include_spip('inc/liens'); |
|
| 4984 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4985 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4986 | + // le raccourcis n'est plus valide |
|
| 4987 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4988 | + // on essaye avec generer_info_entite ? |
|
| 4989 | + if (!strlen($titre) and !$connect) { |
|
| 4990 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4991 | + } |
|
| 4992 | + if (!strlen($titre)) { |
|
| 4993 | + $titre = _T('info_sans_titre'); |
|
| 4994 | + } |
|
| 4995 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4996 | 4996 | |
| 4997 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4997 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4998 | 4998 | } |
| 4999 | 4999 | |
| 5000 | 5000 | /** |
@@ -5002,7 +5002,7 @@ discard block |
||
| 5002 | 5002 | * @see generer_objet_lien |
| 5003 | 5003 | */ |
| 5004 | 5004 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 5005 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5005 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5006 | 5006 | } |
| 5007 | 5007 | |
| 5008 | 5008 | /** |
@@ -5018,15 +5018,15 @@ discard block |
||
| 5018 | 5018 | * @return string |
| 5019 | 5019 | */ |
| 5020 | 5020 | function wrap($texte, $wrap) { |
| 5021 | - $balises = extraire_balises($wrap); |
|
| 5022 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5023 | - $texte = $wrap . $texte; |
|
| 5024 | - $regs = array_reverse($regs[1]); |
|
| 5025 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5026 | - $texte = $texte . $wrap; |
|
| 5027 | - } |
|
| 5021 | + $balises = extraire_balises($wrap); |
|
| 5022 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5023 | + $texte = $wrap . $texte; |
|
| 5024 | + $regs = array_reverse($regs[1]); |
|
| 5025 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5026 | + $texte = $texte . $wrap; |
|
| 5027 | + } |
|
| 5028 | 5028 | |
| 5029 | - return $texte; |
|
| 5029 | + return $texte; |
|
| 5030 | 5030 | } |
| 5031 | 5031 | |
| 5032 | 5032 | |
@@ -5046,44 +5046,44 @@ discard block |
||
| 5046 | 5046 | * @return array|mixed|string |
| 5047 | 5047 | */ |
| 5048 | 5048 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 5049 | - if (is_string($u)) { |
|
| 5050 | - $u = typo($u); |
|
| 5049 | + if (is_string($u)) { |
|
| 5050 | + $u = typo($u); |
|
| 5051 | 5051 | |
| 5052 | - return $u; |
|
| 5053 | - } |
|
| 5052 | + return $u; |
|
| 5053 | + } |
|
| 5054 | 5054 | |
| 5055 | - // caster $u en array si besoin |
|
| 5056 | - if (is_object($u)) { |
|
| 5057 | - $u = (array)$u; |
|
| 5058 | - } |
|
| 5055 | + // caster $u en array si besoin |
|
| 5056 | + if (is_object($u)) { |
|
| 5057 | + $u = (array)$u; |
|
| 5058 | + } |
|
| 5059 | 5059 | |
| 5060 | - if (is_array($u)) { |
|
| 5061 | - $out = ''; |
|
| 5062 | - // toutes les cles sont numeriques ? |
|
| 5063 | - // et aucun enfant n'est un tableau |
|
| 5064 | - // liste simple separee par des virgules |
|
| 5065 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5066 | - $array_values = array_map('is_array', $u); |
|
| 5067 | - $object_values = array_map('is_object', $u); |
|
| 5068 | - if ( |
|
| 5069 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 5070 | - and !array_sum($array_values) |
|
| 5071 | - and !array_sum($object_values) |
|
| 5072 | - ) { |
|
| 5073 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5074 | - } |
|
| 5060 | + if (is_array($u)) { |
|
| 5061 | + $out = ''; |
|
| 5062 | + // toutes les cles sont numeriques ? |
|
| 5063 | + // et aucun enfant n'est un tableau |
|
| 5064 | + // liste simple separee par des virgules |
|
| 5065 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5066 | + $array_values = array_map('is_array', $u); |
|
| 5067 | + $object_values = array_map('is_object', $u); |
|
| 5068 | + if ( |
|
| 5069 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 5070 | + and !array_sum($array_values) |
|
| 5071 | + and !array_sum($object_values) |
|
| 5072 | + ) { |
|
| 5073 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5074 | + } |
|
| 5075 | 5075 | |
| 5076 | - // sinon on passe a la ligne et on indente |
|
| 5077 | - $i_str = str_pad('', $indent, ' '); |
|
| 5078 | - foreach ($u as $k => $v) { |
|
| 5079 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5080 | - } |
|
| 5076 | + // sinon on passe a la ligne et on indente |
|
| 5077 | + $i_str = str_pad('', $indent, ' '); |
|
| 5078 | + foreach ($u as $k => $v) { |
|
| 5079 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5080 | + } |
|
| 5081 | 5081 | |
| 5082 | - return $out; |
|
| 5083 | - } |
|
| 5082 | + return $out; |
|
| 5083 | + } |
|
| 5084 | 5084 | |
| 5085 | - // on sait pas quoi faire... |
|
| 5086 | - return $u; |
|
| 5085 | + // on sait pas quoi faire... |
|
| 5086 | + return $u; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | |
| 5089 | 5089 | |
@@ -5096,10 +5096,10 @@ discard block |
||
| 5096 | 5096 | * @return string|array |
| 5097 | 5097 | */ |
| 5098 | 5098 | function objet_info($objet, $info) { |
| 5099 | - $table = table_objet_sql($objet); |
|
| 5100 | - $infos = lister_tables_objets_sql($table); |
|
| 5099 | + $table = table_objet_sql($objet); |
|
| 5100 | + $infos = lister_tables_objets_sql($table); |
|
| 5101 | 5101 | |
| 5102 | - return ($infos[$info] ?? ''); |
|
| 5102 | + return ($infos[$info] ?? ''); |
|
| 5103 | 5103 | } |
| 5104 | 5104 | |
| 5105 | 5105 | /** |
@@ -5114,11 +5114,11 @@ discard block |
||
| 5114 | 5114 | * Texte traduit du comptage, tel que '3 articles' |
| 5115 | 5115 | */ |
| 5116 | 5116 | function objet_afficher_nb($nb, $objet) { |
| 5117 | - if (!$nb) { |
|
| 5118 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5119 | - } else { |
|
| 5120 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5121 | - } |
|
| 5117 | + if (!$nb) { |
|
| 5118 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5119 | + } else { |
|
| 5120 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5121 | + } |
|
| 5122 | 5122 | } |
| 5123 | 5123 | |
| 5124 | 5124 | /** |
@@ -5130,11 +5130,11 @@ discard block |
||
| 5130 | 5130 | * @return string |
| 5131 | 5131 | */ |
| 5132 | 5132 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5133 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5134 | - $icone = chemin_image($icone); |
|
| 5135 | - $balise_img = charger_filtre('balise_img'); |
|
| 5133 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5134 | + $icone = chemin_image($icone); |
|
| 5135 | + $balise_img = charger_filtre('balise_img'); |
|
| 5136 | 5136 | |
| 5137 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5137 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5138 | 5138 | } |
| 5139 | 5139 | |
| 5140 | 5140 | /** |
@@ -5155,12 +5155,12 @@ discard block |
||
| 5155 | 5155 | * @return string |
| 5156 | 5156 | */ |
| 5157 | 5157 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5158 | - $chaine = explode(':', $chaine); |
|
| 5159 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5160 | - return $t; |
|
| 5161 | - } |
|
| 5162 | - $chaine = implode(':', $chaine); |
|
| 5163 | - return _T($chaine, $args, $options); |
|
| 5158 | + $chaine = explode(':', $chaine); |
|
| 5159 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5160 | + return $t; |
|
| 5161 | + } |
|
| 5162 | + $chaine = implode(':', $chaine); |
|
| 5163 | + return _T($chaine, $args, $options); |
|
| 5164 | 5164 | } |
| 5165 | 5165 | |
| 5166 | 5166 | /** |
@@ -5174,18 +5174,18 @@ discard block |
||
| 5174 | 5174 | * @return string Code HTML |
| 5175 | 5175 | */ |
| 5176 | 5176 | function insert_head_css_conditionnel($flux) { |
| 5177 | - if ( |
|
| 5178 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5179 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5180 | - ) { |
|
| 5181 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5182 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5183 | - $p = $p1; |
|
| 5184 | - } |
|
| 5185 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5186 | - } |
|
| 5177 | + if ( |
|
| 5178 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5179 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5180 | + ) { |
|
| 5181 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5182 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5183 | + $p = $p1; |
|
| 5184 | + } |
|
| 5185 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5186 | + } |
|
| 5187 | 5187 | |
| 5188 | - return $flux; |
|
| 5188 | + return $flux; |
|
| 5189 | 5189 | } |
| 5190 | 5190 | |
| 5191 | 5191 | /** |
@@ -5208,75 +5208,75 @@ discard block |
||
| 5208 | 5208 | * @return string |
| 5209 | 5209 | */ |
| 5210 | 5210 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5211 | - if (isset($contexte['format'])) { |
|
| 5212 | - $extension = $contexte['format']; |
|
| 5213 | - unset($contexte['format']); |
|
| 5214 | - } else { |
|
| 5215 | - $extension = 'html'; |
|
| 5216 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5217 | - $extension = $m[1]; |
|
| 5218 | - } |
|
| 5219 | - } |
|
| 5220 | - // recuperer le contenu produit par le squelette |
|
| 5221 | - $options['raw'] = true; |
|
| 5222 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5223 | - |
|
| 5224 | - // calculer le nom de la css |
|
| 5225 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5226 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5227 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5228 | - |
|
| 5229 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5230 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5231 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5232 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5233 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5234 | - } |
|
| 5235 | - else { |
|
| 5236 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5237 | - ksort($contexte); |
|
| 5238 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5239 | - } |
|
| 5240 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5241 | - |
|
| 5242 | - // mettre a jour le fichier si il n'existe pas |
|
| 5243 | - // ou trop ancien |
|
| 5244 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5245 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5246 | - if ( |
|
| 5247 | - !file_exists($filename) |
|
| 5248 | - or !file_exists($filename . '.last') |
|
| 5249 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5250 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5251 | - ) { |
|
| 5252 | - $contenu = $cache['texte']; |
|
| 5253 | - // passer les urls en absolu si c'est une css |
|
| 5254 | - if ($extension == 'css') { |
|
| 5255 | - $contenu = urls_absolues_css( |
|
| 5256 | - $contenu, |
|
| 5257 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5258 | - ); |
|
| 5259 | - } |
|
| 5260 | - |
|
| 5261 | - $comment = ''; |
|
| 5262 | - // ne pas insérer de commentaire sur certains formats |
|
| 5263 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5264 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5265 | - foreach ($contexte as $k => $v) { |
|
| 5266 | - if (is_array($v)) { |
|
| 5267 | - $v = var_export($v, true); |
|
| 5268 | - } |
|
| 5269 | - $comment .= ",$k=$v"; |
|
| 5270 | - } |
|
| 5271 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | - } |
|
| 5275 | - // et ecrire le fichier si il change |
|
| 5276 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | - } |
|
| 5278 | - |
|
| 5279 | - return timestamp($filename); |
|
| 5211 | + if (isset($contexte['format'])) { |
|
| 5212 | + $extension = $contexte['format']; |
|
| 5213 | + unset($contexte['format']); |
|
| 5214 | + } else { |
|
| 5215 | + $extension = 'html'; |
|
| 5216 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5217 | + $extension = $m[1]; |
|
| 5218 | + } |
|
| 5219 | + } |
|
| 5220 | + // recuperer le contenu produit par le squelette |
|
| 5221 | + $options['raw'] = true; |
|
| 5222 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5223 | + |
|
| 5224 | + // calculer le nom de la css |
|
| 5225 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5226 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5227 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5228 | + |
|
| 5229 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5230 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5231 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5232 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5233 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5234 | + } |
|
| 5235 | + else { |
|
| 5236 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5237 | + ksort($contexte); |
|
| 5238 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5239 | + } |
|
| 5240 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5241 | + |
|
| 5242 | + // mettre a jour le fichier si il n'existe pas |
|
| 5243 | + // ou trop ancien |
|
| 5244 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5245 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5246 | + if ( |
|
| 5247 | + !file_exists($filename) |
|
| 5248 | + or !file_exists($filename . '.last') |
|
| 5249 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5250 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5251 | + ) { |
|
| 5252 | + $contenu = $cache['texte']; |
|
| 5253 | + // passer les urls en absolu si c'est une css |
|
| 5254 | + if ($extension == 'css') { |
|
| 5255 | + $contenu = urls_absolues_css( |
|
| 5256 | + $contenu, |
|
| 5257 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5258 | + ); |
|
| 5259 | + } |
|
| 5260 | + |
|
| 5261 | + $comment = ''; |
|
| 5262 | + // ne pas insérer de commentaire sur certains formats |
|
| 5263 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5264 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5265 | + foreach ($contexte as $k => $v) { |
|
| 5266 | + if (is_array($v)) { |
|
| 5267 | + $v = var_export($v, true); |
|
| 5268 | + } |
|
| 5269 | + $comment .= ",$k=$v"; |
|
| 5270 | + } |
|
| 5271 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5272 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5273 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5274 | + } |
|
| 5275 | + // et ecrire le fichier si il change |
|
| 5276 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5277 | + } |
|
| 5278 | + |
|
| 5279 | + return timestamp($filename); |
|
| 5280 | 5280 | } |
| 5281 | 5281 | |
| 5282 | 5282 | /** |
@@ -5289,15 +5289,15 @@ discard block |
||
| 5289 | 5289 | * $fichier auquel on a ajouté le timestamp |
| 5290 | 5290 | */ |
| 5291 | 5291 | function timestamp($fichier) { |
| 5292 | - if ( |
|
| 5293 | - !$fichier |
|
| 5294 | - or !file_exists($fichier) |
|
| 5295 | - or !$m = filemtime($fichier) |
|
| 5296 | - ) { |
|
| 5297 | - return $fichier; |
|
| 5298 | - } |
|
| 5292 | + if ( |
|
| 5293 | + !$fichier |
|
| 5294 | + or !file_exists($fichier) |
|
| 5295 | + or !$m = filemtime($fichier) |
|
| 5296 | + ) { |
|
| 5297 | + return $fichier; |
|
| 5298 | + } |
|
| 5299 | 5299 | |
| 5300 | - return "$fichier?$m"; |
|
| 5300 | + return "$fichier?$m"; |
|
| 5301 | 5301 | } |
| 5302 | 5302 | |
| 5303 | 5303 | /** |
@@ -5307,11 +5307,11 @@ discard block |
||
| 5307 | 5307 | * @return string |
| 5308 | 5308 | */ |
| 5309 | 5309 | function supprimer_timestamp($url) { |
| 5310 | - if (strpos($url, '?') === false) { |
|
| 5311 | - return $url; |
|
| 5312 | - } |
|
| 5310 | + if (strpos($url, '?') === false) { |
|
| 5311 | + return $url; |
|
| 5312 | + } |
|
| 5313 | 5313 | |
| 5314 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5314 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5315 | 5315 | } |
| 5316 | 5316 | |
| 5317 | 5317 | /** |
@@ -5326,15 +5326,15 @@ discard block |
||
| 5326 | 5326 | * @return string |
| 5327 | 5327 | */ |
| 5328 | 5328 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5329 | - include_spip('inc/envoyer_mail'); |
|
| 5329 | + include_spip('inc/envoyer_mail'); |
|
| 5330 | 5330 | |
| 5331 | - $titre = nettoyer_titre_email($titre); |
|
| 5332 | - // on est dans un squelette : securiser le retour |
|
| 5333 | - if (strpos($titre, '<') !== false) { |
|
| 5334 | - $titre = interdire_scripts($titre); |
|
| 5335 | - } |
|
| 5331 | + $titre = nettoyer_titre_email($titre); |
|
| 5332 | + // on est dans un squelette : securiser le retour |
|
| 5333 | + if (strpos($titre, '<') !== false) { |
|
| 5334 | + $titre = interdire_scripts($titre); |
|
| 5335 | + } |
|
| 5336 | 5336 | |
| 5337 | - return $titre; |
|
| 5337 | + return $titre; |
|
| 5338 | 5338 | } |
| 5339 | 5339 | |
| 5340 | 5340 | /** |
@@ -5356,27 +5356,27 @@ discard block |
||
| 5356 | 5356 | * @return string |
| 5357 | 5357 | */ |
| 5358 | 5358 | function filtre_chercher_rubrique_dist( |
| 5359 | - $titre, |
|
| 5360 | - $id_objet, |
|
| 5361 | - $id_parent, |
|
| 5362 | - $objet, |
|
| 5363 | - $id_secteur, |
|
| 5364 | - $restreint, |
|
| 5365 | - $actionable = false, |
|
| 5366 | - $retour_sans_cadre = false |
|
| 5359 | + $titre, |
|
| 5360 | + $id_objet, |
|
| 5361 | + $id_parent, |
|
| 5362 | + $objet, |
|
| 5363 | + $id_secteur, |
|
| 5364 | + $restreint, |
|
| 5365 | + $actionable = false, |
|
| 5366 | + $retour_sans_cadre = false |
|
| 5367 | 5367 | ) { |
| 5368 | - include_spip('inc/filtres_ecrire'); |
|
| 5368 | + include_spip('inc/filtres_ecrire'); |
|
| 5369 | 5369 | |
| 5370 | - return chercher_rubrique( |
|
| 5371 | - $titre, |
|
| 5372 | - $id_objet, |
|
| 5373 | - $id_parent, |
|
| 5374 | - $objet, |
|
| 5375 | - $id_secteur, |
|
| 5376 | - $restreint, |
|
| 5377 | - $actionable, |
|
| 5378 | - $retour_sans_cadre |
|
| 5379 | - ); |
|
| 5370 | + return chercher_rubrique( |
|
| 5371 | + $titre, |
|
| 5372 | + $id_objet, |
|
| 5373 | + $id_parent, |
|
| 5374 | + $objet, |
|
| 5375 | + $id_secteur, |
|
| 5376 | + $restreint, |
|
| 5377 | + $actionable, |
|
| 5378 | + $retour_sans_cadre |
|
| 5379 | + ); |
|
| 5380 | 5380 | } |
| 5381 | 5381 | |
| 5382 | 5382 | /** |
@@ -5405,56 +5405,56 @@ discard block |
||
| 5405 | 5405 | * Chaîne vide si l'accès est autorisé |
| 5406 | 5406 | */ |
| 5407 | 5407 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5408 | - if ($ok) { |
|
| 5409 | - return ''; |
|
| 5410 | - } |
|
| 5411 | - |
|
| 5412 | - // Vider tous les tampons |
|
| 5413 | - $level = @ob_get_level(); |
|
| 5414 | - while ($level--) { |
|
| 5415 | - @ob_end_clean(); |
|
| 5416 | - } |
|
| 5417 | - |
|
| 5418 | - include_spip('inc/headers'); |
|
| 5419 | - |
|
| 5420 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5421 | - if ($url) { |
|
| 5422 | - redirige_par_entete($url, '', $statut); |
|
| 5423 | - } |
|
| 5424 | - |
|
| 5425 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5426 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5427 | - $message = $statut; |
|
| 5428 | - $statut = 0; |
|
| 5429 | - } |
|
| 5430 | - if (!$message) { |
|
| 5431 | - $message = ''; |
|
| 5432 | - } |
|
| 5433 | - $statut = intval($statut); |
|
| 5434 | - |
|
| 5435 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5436 | - if (test_espace_prive()) { |
|
| 5437 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5438 | - $statut = 403; |
|
| 5439 | - } |
|
| 5440 | - http_response_code(403); |
|
| 5441 | - $echec = charger_fonction('403', 'exec'); |
|
| 5442 | - $echec($message); |
|
| 5443 | - } else { |
|
| 5444 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5445 | - if (!$statut) { |
|
| 5446 | - $statut = 404; |
|
| 5447 | - } |
|
| 5448 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5449 | - http_response_code($statut); |
|
| 5450 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5451 | - if ($statut >= 400) { |
|
| 5452 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5453 | - } |
|
| 5454 | - } |
|
| 5455 | - |
|
| 5456 | - |
|
| 5457 | - exit; |
|
| 5408 | + if ($ok) { |
|
| 5409 | + return ''; |
|
| 5410 | + } |
|
| 5411 | + |
|
| 5412 | + // Vider tous les tampons |
|
| 5413 | + $level = @ob_get_level(); |
|
| 5414 | + while ($level--) { |
|
| 5415 | + @ob_end_clean(); |
|
| 5416 | + } |
|
| 5417 | + |
|
| 5418 | + include_spip('inc/headers'); |
|
| 5419 | + |
|
| 5420 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5421 | + if ($url) { |
|
| 5422 | + redirige_par_entete($url, '', $statut); |
|
| 5423 | + } |
|
| 5424 | + |
|
| 5425 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5426 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5427 | + $message = $statut; |
|
| 5428 | + $statut = 0; |
|
| 5429 | + } |
|
| 5430 | + if (!$message) { |
|
| 5431 | + $message = ''; |
|
| 5432 | + } |
|
| 5433 | + $statut = intval($statut); |
|
| 5434 | + |
|
| 5435 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5436 | + if (test_espace_prive()) { |
|
| 5437 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5438 | + $statut = 403; |
|
| 5439 | + } |
|
| 5440 | + http_response_code(403); |
|
| 5441 | + $echec = charger_fonction('403', 'exec'); |
|
| 5442 | + $echec($message); |
|
| 5443 | + } else { |
|
| 5444 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5445 | + if (!$statut) { |
|
| 5446 | + $statut = 404; |
|
| 5447 | + } |
|
| 5448 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5449 | + http_response_code($statut); |
|
| 5450 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5451 | + if ($statut >= 400) { |
|
| 5452 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5453 | + } |
|
| 5454 | + } |
|
| 5455 | + |
|
| 5456 | + |
|
| 5457 | + exit; |
|
| 5458 | 5458 | } |
| 5459 | 5459 | |
| 5460 | 5460 | /** |
@@ -5465,11 +5465,11 @@ discard block |
||
| 5465 | 5465 | * @return string |
| 5466 | 5466 | */ |
| 5467 | 5467 | function filtre_compacte_dist($source, $format = null) { |
| 5468 | - if (function_exists('minifier')) { |
|
| 5469 | - return minifier($source, $format); |
|
| 5470 | - } |
|
| 5468 | + if (function_exists('minifier')) { |
|
| 5469 | + return minifier($source, $format); |
|
| 5470 | + } |
|
| 5471 | 5471 | |
| 5472 | - return $source; |
|
| 5472 | + return $source; |
|
| 5473 | 5473 | } |
| 5474 | 5474 | |
| 5475 | 5475 | |
@@ -5481,32 +5481,32 @@ discard block |
||
| 5481 | 5481 | * @return string |
| 5482 | 5482 | */ |
| 5483 | 5483 | function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5484 | - $passe ??= ''; |
|
| 5485 | - $l = strlen($passe); |
|
| 5486 | - |
|
| 5487 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5488 | - if (!$l) { |
|
| 5489 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5490 | - } |
|
| 5491 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5492 | - } |
|
| 5493 | - |
|
| 5494 | - if (is_null($portion_pourcent)) { |
|
| 5495 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5496 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5497 | - } |
|
| 5498 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5499 | - } |
|
| 5500 | - if ($portion_pourcent >= 100) { |
|
| 5501 | - return $passe; |
|
| 5502 | - } |
|
| 5503 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5504 | - $e = max($e, 0); |
|
| 5505 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5506 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5507 | - $mid = '***...***'; |
|
| 5508 | - } |
|
| 5509 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5484 | + $passe ??= ''; |
|
| 5485 | + $l = strlen($passe); |
|
| 5486 | + |
|
| 5487 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5488 | + if (!$l) { |
|
| 5489 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5490 | + } |
|
| 5491 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5492 | + } |
|
| 5493 | + |
|
| 5494 | + if (is_null($portion_pourcent)) { |
|
| 5495 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5496 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5497 | + } |
|
| 5498 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5499 | + } |
|
| 5500 | + if ($portion_pourcent >= 100) { |
|
| 5501 | + return $passe; |
|
| 5502 | + } |
|
| 5503 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5504 | + $e = max($e, 0); |
|
| 5505 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5506 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5507 | + $mid = '***...***'; |
|
| 5508 | + } |
|
| 5509 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5510 | 5510 | } |
| 5511 | 5511 | |
| 5512 | 5512 | |
@@ -5527,64 +5527,64 @@ discard block |
||
| 5527 | 5527 | */ |
| 5528 | 5528 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5529 | 5529 | |
| 5530 | - $original = $texte; |
|
| 5531 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5532 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5533 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5530 | + $original = $texte; |
|
| 5531 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5532 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5533 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5534 | 5534 | |
| 5535 | - if (!function_exists('translitteration')) { |
|
| 5536 | - include_spip('inc/charsets'); |
|
| 5537 | - } |
|
| 5535 | + if (!function_exists('translitteration')) { |
|
| 5536 | + include_spip('inc/charsets'); |
|
| 5537 | + } |
|
| 5538 | 5538 | |
| 5539 | - // pas de balise html |
|
| 5540 | - if (strpos($texte, '<') !== false) { |
|
| 5541 | - $texte = strip_tags($texte); |
|
| 5542 | - } |
|
| 5543 | - if (strpos($texte, '&') !== false) { |
|
| 5544 | - $texte = unicode2charset($texte); |
|
| 5545 | - } |
|
| 5546 | - // On enlève les espaces indésirables |
|
| 5547 | - $texte = trim($texte); |
|
| 5539 | + // pas de balise html |
|
| 5540 | + if (strpos($texte, '<') !== false) { |
|
| 5541 | + $texte = strip_tags($texte); |
|
| 5542 | + } |
|
| 5543 | + if (strpos($texte, '&') !== false) { |
|
| 5544 | + $texte = unicode2charset($texte); |
|
| 5545 | + } |
|
| 5546 | + // On enlève les espaces indésirables |
|
| 5547 | + $texte = trim($texte); |
|
| 5548 | 5548 | |
| 5549 | - // On enlève les accents et cie |
|
| 5550 | - $texte = translitteration($texte); |
|
| 5549 | + // On enlève les accents et cie |
|
| 5550 | + $texte = translitteration($texte); |
|
| 5551 | 5551 | |
| 5552 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5553 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5552 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5553 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5554 | 5554 | |
| 5555 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5556 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5557 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5558 | - } |
|
| 5555 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5556 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5557 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5558 | + } |
|
| 5559 | 5559 | |
| 5560 | - // pas de separateur au debut ni a la fin |
|
| 5561 | - $texte = trim($texte, $separateur); |
|
| 5560 | + // pas de separateur au debut ni a la fin |
|
| 5561 | + $texte = trim($texte, $separateur); |
|
| 5562 | 5562 | |
| 5563 | - // en minuscules |
|
| 5564 | - $texte = strtolower($texte); |
|
| 5563 | + // en minuscules |
|
| 5564 | + $texte = strtolower($texte); |
|
| 5565 | 5565 | |
| 5566 | - switch ($type) { |
|
| 5567 | - case 'class': |
|
| 5568 | - case 'id': |
|
| 5569 | - case 'anchor': |
|
| 5570 | - if (preg_match(',^\d,', $texte)) { |
|
| 5571 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5572 | - } |
|
| 5573 | - } |
|
| 5566 | + switch ($type) { |
|
| 5567 | + case 'class': |
|
| 5568 | + case 'id': |
|
| 5569 | + case 'anchor': |
|
| 5570 | + if (preg_match(',^\d,', $texte)) { |
|
| 5571 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5572 | + } |
|
| 5573 | + } |
|
| 5574 | 5574 | |
| 5575 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5576 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5577 | - } |
|
| 5575 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5576 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5577 | + } |
|
| 5578 | 5578 | |
| 5579 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5580 | - if (preg_match(',^\d,', $texte)) { |
|
| 5581 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5582 | - } |
|
| 5583 | - $texte .= $separateur . md5($original); |
|
| 5584 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5585 | - } |
|
| 5579 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5580 | + if (preg_match(',^\d,', $texte)) { |
|
| 5581 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5582 | + } |
|
| 5583 | + $texte .= $separateur . md5($original); |
|
| 5584 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5585 | + } |
|
| 5586 | 5586 | |
| 5587 | - return $texte; |
|
| 5587 | + return $texte; |
|
| 5588 | 5588 | } |
| 5589 | 5589 | |
| 5590 | 5590 | |
@@ -5605,11 +5605,11 @@ discard block |
||
| 5605 | 5605 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5606 | 5606 | */ |
| 5607 | 5607 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5608 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5609 | - if ($ucfirst) { |
|
| 5610 | - $label = spip_ucfirst($label); |
|
| 5611 | - } |
|
| 5612 | - return $label; |
|
| 5608 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5609 | + if ($ucfirst) { |
|
| 5610 | + $label = spip_ucfirst($label); |
|
| 5611 | + } |
|
| 5612 | + return $label; |
|
| 5613 | 5613 | } |
| 5614 | 5614 | |
| 5615 | 5615 | /** |
@@ -5622,8 +5622,8 @@ discard block |
||
| 5622 | 5622 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5623 | 5623 | */ |
| 5624 | 5624 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5625 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5626 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5625 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5626 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5627 | 5627 | } |
| 5628 | 5628 | |
| 5629 | 5629 | |
@@ -5636,19 +5636,19 @@ discard block |
||
| 5636 | 5636 | * @return array |
| 5637 | 5637 | */ |
| 5638 | 5638 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5639 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5640 | - return []; |
|
| 5641 | - } |
|
| 5639 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5640 | + return []; |
|
| 5641 | + } |
|
| 5642 | 5642 | |
| 5643 | - // compatibilite signature inversee |
|
| 5644 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5645 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5646 | - } |
|
| 5643 | + // compatibilite signature inversee |
|
| 5644 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5645 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5646 | + } |
|
| 5647 | 5647 | |
| 5648 | - if (!function_exists($fonction)) { |
|
| 5649 | - include_spip('base/objets'); |
|
| 5650 | - } |
|
| 5651 | - return $fonction($objet, $id_objet); |
|
| 5648 | + if (!function_exists($fonction)) { |
|
| 5649 | + include_spip('base/objets'); |
|
| 5650 | + } |
|
| 5651 | + return $fonction($objet, $id_objet); |
|
| 5652 | 5652 | } |
| 5653 | 5653 | |
| 5654 | 5654 | |
@@ -5663,7 +5663,7 @@ discard block |
||
| 5663 | 5663 | * @return array |
| 5664 | 5664 | */ |
| 5665 | 5665 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5666 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5666 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5667 | 5667 | } |
| 5668 | 5668 | |
| 5669 | 5669 | /** |
@@ -5677,7 +5677,7 @@ discard block |
||
| 5677 | 5677 | * @return array |
| 5678 | 5678 | */ |
| 5679 | 5679 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5680 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5680 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5681 | 5681 | } |
| 5682 | 5682 | |
| 5683 | 5683 | /** |
@@ -5691,7 +5691,7 @@ discard block |
||
| 5691 | 5691 | * @return array |
| 5692 | 5692 | */ |
| 5693 | 5693 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5694 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5694 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5695 | 5695 | } |
| 5696 | 5696 | |
| 5697 | 5697 | /** |
@@ -5705,5 +5705,5 @@ discard block |
||
| 5705 | 5705 | * @return array |
| 5706 | 5706 | */ |
| 5707 | 5707 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5708 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5708 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5709 | 5709 | } |
@@ -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 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,56 +198,56 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $titre = trim($titre ?? ''); |
|
| 205 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $titre = trim($titre ?? ''); |
|
| 205 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 206 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 207 | 207 | |
| 208 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | - $types = [ |
|
| 210 | - 'notice', |
|
| 211 | - 'error', |
|
| 212 | - 'success', |
|
| 213 | - 'info', |
|
| 214 | - ]; |
|
| 215 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | - $type = reset($type); |
|
| 217 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 208 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 209 | + $types = [ |
|
| 210 | + 'notice', |
|
| 211 | + 'error', |
|
| 212 | + 'success', |
|
| 213 | + 'info', |
|
| 214 | + ]; |
|
| 215 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 216 | + $type = reset($type); |
|
| 217 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 218 | 218 | |
| 219 | - // Classes |
|
| 220 | - $class_racine = 'msg-alert'; |
|
| 221 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | - $class_alerte = "$class_racine $class"; |
|
| 223 | - $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | - $class_titre = "{$class_racine}__heading"; |
|
| 219 | + // Classes |
|
| 220 | + $class_racine = 'msg-alert'; |
|
| 221 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 222 | + $class_alerte = "$class_racine $class"; |
|
| 223 | + $class_texte = "{$class_racine}__text $clearfix"; |
|
| 224 | + $class_titre = "{$class_racine}__heading"; |
|
| 225 | 225 | |
| 226 | - // Titre : markup |
|
| 227 | - $titre = trim($titre); |
|
| 228 | - if (strlen($titre)) { |
|
| 229 | - include_spip('inc/filtres'); |
|
| 230 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | - $titre = wrap($titre, $wrap_tag); |
|
| 235 | - } |
|
| 236 | - // puis on ajoute la classe |
|
| 237 | - $titre = ajouter_class($titre, $class_titre); |
|
| 238 | - } |
|
| 226 | + // Titre : markup |
|
| 227 | + $titre = trim($titre); |
|
| 228 | + if (strlen($titre)) { |
|
| 229 | + include_spip('inc/filtres'); |
|
| 230 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 231 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 232 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 233 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 234 | + $titre = wrap($titre, $wrap_tag); |
|
| 235 | + } |
|
| 236 | + // puis on ajoute la classe |
|
| 237 | + $titre = ajouter_class($titre, $class_titre); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Attributs |
|
| 241 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 240 | + // Attributs |
|
| 241 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 242 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 243 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 244 | 244 | |
| 245 | - $message = |
|
| 246 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | - . $titre |
|
| 248 | - . "<div class=\"$class_texte\">"; |
|
| 245 | + $message = |
|
| 246 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 247 | + . $titre |
|
| 248 | + . "<div class=\"$class_texte\">"; |
|
| 249 | 249 | |
| 250 | - return $message; |
|
| 250 | + return $message; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -261,5 +261,5 @@ discard block |
||
| 261 | 261 | * HTML de fin de l'alerte |
| 262 | 262 | */ |
| 263 | 263 | function message_alerte_fermer(): string { |
| 264 | - return '</div></div>'; |
|
| 264 | + return '</div></div>'; |
|
| 265 | 265 | } |
@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - [$primary, $table_liens] = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - [$primary, $table_liens] = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + [$primary, $table_liens] = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + [$primary, $table_liens] = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |