@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | define('_PHP_MAX', '8.2.99'); |
| 40 | 40 | |
| 41 | 41 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 42 | - /** le nom du repertoire ecrire/ */ |
|
| 43 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 42 | + /** le nom du repertoire ecrire/ */ |
|
| 43 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** Chemin relatif pour aller dans ecrire |
| 47 | 47 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 48 | 48 | define( |
| 49 | - '_DIR_RESTREINT', |
|
| 50 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 49 | + '_DIR_RESTREINT', |
|
| 50 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | /** Chemin relatif pour aller à la racine */ |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | // Icones |
| 64 | 64 | if (!defined('_NOM_IMG_PACK')) { |
| 65 | - /** Nom du dossier images */ |
|
| 66 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 65 | + /** Nom du dossier images */ |
|
| 66 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 67 | 67 | } |
| 68 | 68 | /** le chemin http (relatif) vers les images standard */ |
| 69 | 69 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 73 | 73 | |
| 74 | 74 | if (!defined('_JAVASCRIPT')) { |
| 75 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 76 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 75 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 76 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 77 | 77 | } // utilisable avec #CHEMIN et find_in_path |
| 78 | 78 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 79 | 79 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -83,47 +83,47 @@ discard block |
||
| 83 | 83 | # mais on peut les mettre ailleurs et changer completement les noms |
| 84 | 84 | |
| 85 | 85 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 86 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 87 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 86 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 87 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 88 | 88 | } |
| 89 | 89 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 90 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 91 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 90 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 91 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 92 | 92 | } |
| 93 | 93 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 94 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 95 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 94 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 95 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 96 | 96 | } |
| 97 | 97 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 98 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 99 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 98 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 99 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | /** Le nom du fichier de personnalisation */ |
| 104 | 104 | if (!defined('_NOM_CONFIG')) { |
| 105 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 105 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Son emplacement absolu si on le trouve |
| 109 | 109 | if ( |
| 110 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 111 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 110 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 111 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 112 | 112 | ) { |
| 113 | - /** Emplacement absolu du fichier d'option */ |
|
| 114 | - define('_FILE_OPTIONS', $f); |
|
| 113 | + /** Emplacement absolu du fichier d'option */ |
|
| 114 | + define('_FILE_OPTIONS', $f); |
|
| 115 | 115 | } else { |
| 116 | - define('_FILE_OPTIONS', ''); |
|
| 116 | + define('_FILE_OPTIONS', ''); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if (!defined('MODULES_IDIOMES')) { |
| 120 | - /** |
|
| 121 | - * Modules par défaut pour la traduction. |
|
| 122 | - * |
|
| 123 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 124 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 125 | - */ |
|
| 126 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 120 | + /** |
|
| 121 | + * Modules par défaut pour la traduction. |
|
| 122 | + * |
|
| 123 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 124 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 125 | + */ |
|
| 126 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // *** Fin des define *** // |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | // inclure l'ecran de securite |
| 133 | 133 | if ( |
| 134 | - !defined('_ECRAN_SECURITE') |
|
| 135 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 134 | + !defined('_ECRAN_SECURITE') |
|
| 135 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 136 | 136 | ) { |
| 137 | - include $f; |
|
| 137 | + include $f; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | |
@@ -142,30 +142,30 @@ discard block |
||
| 142 | 142 | * Détecteur de robot d'indexation |
| 143 | 143 | */ |
| 144 | 144 | if (!defined('_IS_BOT')) { |
| 145 | - define( |
|
| 146 | - '_IS_BOT', |
|
| 147 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 148 | - and preg_match( |
|
| 149 | - // mots generiques |
|
| 150 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 151 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 152 | - . 'MSIE 6\.0|' |
|
| 153 | - // UA plus cibles |
|
| 154 | - . '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' |
|
| 155 | - . ',i', |
|
| 156 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 145 | + define( |
|
| 146 | + '_IS_BOT', |
|
| 147 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 148 | + and preg_match( |
|
| 149 | + // mots generiques |
|
| 150 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 151 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 152 | + . 'MSIE 6\.0|' |
|
| 153 | + // UA plus cibles |
|
| 154 | + . '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' |
|
| 155 | + . ',i', |
|
| 156 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | if (!defined('_IS_CLI')) { |
| 162 | - define( |
|
| 163 | - '_IS_CLI', |
|
| 164 | - !isset($_SERVER['HTTP_HOST']) |
|
| 165 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 166 | - and !empty($_SERVER['argv']) |
|
| 167 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 168 | - ); |
|
| 162 | + define( |
|
| 163 | + '_IS_CLI', |
|
| 164 | + !isset($_SERVER['HTTP_HOST']) |
|
| 165 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 166 | + and !empty($_SERVER['argv']) |
|
| 167 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 168 | + ); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // *** Parametrage par defaut de SPIP *** |
@@ -177,61 +177,61 @@ discard block |
||
| 177 | 177 | // Ne pas les rendre indefinies. |
| 178 | 178 | |
| 179 | 179 | global |
| 180 | - $nombre_de_logs, |
|
| 181 | - $taille_des_logs, |
|
| 182 | - $table_prefix, |
|
| 183 | - $cookie_prefix, |
|
| 184 | - $dossier_squelettes, |
|
| 185 | - $filtrer_javascript, |
|
| 186 | - $type_urls, |
|
| 187 | - $debut_date_publication, |
|
| 188 | - $ip, |
|
| 189 | - $mysql_rappel_connexion, |
|
| 190 | - $mysql_rappel_nom_base, |
|
| 191 | - $test_i18n, |
|
| 192 | - $ignore_auth_http, |
|
| 193 | - $ignore_remote_user, |
|
| 194 | - $derniere_modif_invalide, |
|
| 195 | - $home_server, |
|
| 196 | - $help_server, |
|
| 197 | - $url_glossaire_externe, |
|
| 198 | - $tex_server, |
|
| 199 | - $traiter_math, |
|
| 200 | - $xhtml, |
|
| 201 | - $xml_indent, |
|
| 202 | - $source_vignettes, |
|
| 203 | - $formats_logos, |
|
| 204 | - $controler_dates_rss, |
|
| 205 | - $spip_pipeline, |
|
| 206 | - $spip_matrice, |
|
| 207 | - $plugins, |
|
| 208 | - $surcharges, |
|
| 209 | - $exceptions_des_tables, |
|
| 210 | - $tables_principales, |
|
| 211 | - $table_des_tables, |
|
| 212 | - $tables_auxiliaires, |
|
| 213 | - $table_primary, |
|
| 214 | - $table_date, |
|
| 215 | - $table_titre, |
|
| 216 | - $tables_jointures, |
|
| 217 | - $liste_des_statuts, |
|
| 218 | - $liste_des_etats, |
|
| 219 | - $liste_des_authentifications, |
|
| 220 | - $spip_version_branche, |
|
| 221 | - $spip_version_code, |
|
| 222 | - $spip_version_base, |
|
| 223 | - $spip_sql_version, |
|
| 224 | - $spip_version_affichee, |
|
| 225 | - $visiteur_session, |
|
| 226 | - $auteur_session, |
|
| 227 | - $connect_statut, |
|
| 228 | - $connect_toutes_rubriques, |
|
| 229 | - $hash_recherche, |
|
| 230 | - $hash_recherche_strict, |
|
| 231 | - $ldap_present, |
|
| 232 | - $meta, |
|
| 233 | - $connect_id_rubrique, |
|
| 234 | - $puce; |
|
| 180 | + $nombre_de_logs, |
|
| 181 | + $taille_des_logs, |
|
| 182 | + $table_prefix, |
|
| 183 | + $cookie_prefix, |
|
| 184 | + $dossier_squelettes, |
|
| 185 | + $filtrer_javascript, |
|
| 186 | + $type_urls, |
|
| 187 | + $debut_date_publication, |
|
| 188 | + $ip, |
|
| 189 | + $mysql_rappel_connexion, |
|
| 190 | + $mysql_rappel_nom_base, |
|
| 191 | + $test_i18n, |
|
| 192 | + $ignore_auth_http, |
|
| 193 | + $ignore_remote_user, |
|
| 194 | + $derniere_modif_invalide, |
|
| 195 | + $home_server, |
|
| 196 | + $help_server, |
|
| 197 | + $url_glossaire_externe, |
|
| 198 | + $tex_server, |
|
| 199 | + $traiter_math, |
|
| 200 | + $xhtml, |
|
| 201 | + $xml_indent, |
|
| 202 | + $source_vignettes, |
|
| 203 | + $formats_logos, |
|
| 204 | + $controler_dates_rss, |
|
| 205 | + $spip_pipeline, |
|
| 206 | + $spip_matrice, |
|
| 207 | + $plugins, |
|
| 208 | + $surcharges, |
|
| 209 | + $exceptions_des_tables, |
|
| 210 | + $tables_principales, |
|
| 211 | + $table_des_tables, |
|
| 212 | + $tables_auxiliaires, |
|
| 213 | + $table_primary, |
|
| 214 | + $table_date, |
|
| 215 | + $table_titre, |
|
| 216 | + $tables_jointures, |
|
| 217 | + $liste_des_statuts, |
|
| 218 | + $liste_des_etats, |
|
| 219 | + $liste_des_authentifications, |
|
| 220 | + $spip_version_branche, |
|
| 221 | + $spip_version_code, |
|
| 222 | + $spip_version_base, |
|
| 223 | + $spip_sql_version, |
|
| 224 | + $spip_version_affichee, |
|
| 225 | + $visiteur_session, |
|
| 226 | + $auteur_session, |
|
| 227 | + $connect_statut, |
|
| 228 | + $connect_toutes_rubriques, |
|
| 229 | + $hash_recherche, |
|
| 230 | + $hash_recherche_strict, |
|
| 231 | + $ldap_present, |
|
| 232 | + $meta, |
|
| 233 | + $connect_id_rubrique, |
|
| 234 | + $puce; |
|
| 235 | 235 | |
| 236 | 236 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 237 | 237 | $nombre_de_logs = 4; |
@@ -286,48 +286,48 @@ discard block |
||
| 286 | 286 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 287 | 287 | // |
| 288 | 288 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 289 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 290 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 291 | - } |
|
| 292 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 293 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 294 | - } |
|
| 289 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 290 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 291 | + } |
|
| 292 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 293 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 294 | + } |
|
| 295 | 295 | } |
| 296 | 296 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 297 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 298 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 299 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 300 | - $_SERVER['HTTPS'] = 'on'; |
|
| 301 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 302 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 307 | - if (strpos($host, ',') !== false) { |
|
| 308 | - $h = explode(',', $host); |
|
| 309 | - $host = trim(reset($h)); |
|
| 310 | - } |
|
| 311 | - // securite sur le contenu de l'entete |
|
| 312 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 313 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 297 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 298 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 299 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 300 | + $_SERVER['HTTPS'] = 'on'; |
|
| 301 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 302 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 307 | + if (strpos($host, ',') !== false) { |
|
| 308 | + $h = explode(',', $host); |
|
| 309 | + $host = trim(reset($h)); |
|
| 310 | + } |
|
| 311 | + // securite sur le contenu de l'entete |
|
| 312 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 313 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 314 | 314 | } |
| 315 | 315 | // |
| 316 | 316 | // On note le numero IP du client dans la variable $ip |
| 317 | 317 | // |
| 318 | 318 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 319 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 320 | - if (strpos($ip, ',') !== false) { |
|
| 321 | - $ip = explode(',', $ip); |
|
| 322 | - $ip = reset($ip); |
|
| 323 | - } |
|
| 324 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 325 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 326 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 327 | - } |
|
| 319 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 320 | + if (strpos($ip, ',') !== false) { |
|
| 321 | + $ip = explode(',', $ip); |
|
| 322 | + $ip = reset($ip); |
|
| 323 | + } |
|
| 324 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 325 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 326 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 327 | + } |
|
| 328 | 328 | } |
| 329 | 329 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 330 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 330 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -412,24 +412,24 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | // Liste des statuts. |
| 414 | 414 | $liste_des_statuts = [ |
| 415 | - 'info_administrateurs' => '0minirezo', |
|
| 416 | - 'info_redacteurs' => '1comite', |
|
| 417 | - 'info_visiteurs' => '6forum', |
|
| 418 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 415 | + 'info_administrateurs' => '0minirezo', |
|
| 416 | + 'info_redacteurs' => '1comite', |
|
| 417 | + 'info_visiteurs' => '6forum', |
|
| 418 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 419 | 419 | ]; |
| 420 | 420 | |
| 421 | 421 | $liste_des_etats = [ |
| 422 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 423 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 424 | - 'texte_statut_publie' => 'publie', |
|
| 425 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 426 | - 'texte_statut_refuse' => 'refuse' |
|
| 422 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 423 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 424 | + 'texte_statut_publie' => 'publie', |
|
| 425 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 426 | + 'texte_statut_refuse' => 'refuse' |
|
| 427 | 427 | ]; |
| 428 | 428 | |
| 429 | 429 | // liste des methodes d'authentifications |
| 430 | 430 | $liste_des_authentifications = [ |
| 431 | - 'spip' => 'spip', |
|
| 432 | - 'ldap' => 'ldap' |
|
| 431 | + 'spip' => 'spip', |
|
| 432 | + 'ldap' => 'ldap' |
|
| 433 | 433 | ]; |
| 434 | 434 | |
| 435 | 435 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -479,12 +479,12 @@ discard block |
||
| 479 | 479 | // Definition personnelles eventuelles |
| 480 | 480 | |
| 481 | 481 | if (_FILE_OPTIONS) { |
| 482 | - include_once _FILE_OPTIONS; |
|
| 482 | + include_once _FILE_OPTIONS; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 486 | - /** Masquer les warning */ |
|
| 487 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 486 | + /** Masquer les warning */ |
|
| 487 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 488 | 488 | } |
| 489 | 489 | error_reporting(SPIP_ERREUR_REPORT); |
| 490 | 490 | |
@@ -497,10 +497,10 @@ discard block |
||
| 497 | 497 | // ===> on execute en neutralisant les messages d'erreur |
| 498 | 498 | |
| 499 | 499 | spip_initialisation_core( |
| 500 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 501 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 502 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 503 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 500 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 501 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 502 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 503 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 504 | 504 | ); |
| 505 | 505 | |
| 506 | 506 | |
@@ -510,70 +510,70 @@ discard block |
||
| 510 | 510 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 511 | 511 | |
| 512 | 512 | if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) { |
| 513 | - // chargement optimise precompile |
|
| 514 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 513 | + // chargement optimise precompile |
|
| 514 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 515 | 515 | } else { |
| 516 | - spip_initialisation_suite(); |
|
| 517 | - include_spip('inc/plugin'); |
|
| 518 | - // generer les fichiers php precompiles |
|
| 519 | - // de chargement des plugins et des pipelines |
|
| 520 | - actualise_plugins_actifs(); |
|
| 516 | + spip_initialisation_suite(); |
|
| 517 | + include_spip('inc/plugin'); |
|
| 518 | + // generer les fichiers php precompiles |
|
| 519 | + // de chargement des plugins et des pipelines |
|
| 520 | + actualise_plugins_actifs(); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | // Initialisations non critiques surchargeables par les plugins |
| 524 | 524 | spip_initialisation_suite(); |
| 525 | 525 | |
| 526 | 526 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 527 | - /** niveau maxi d'enregistrement des logs */ |
|
| 528 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 527 | + /** niveau maxi d'enregistrement des logs */ |
|
| 528 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 532 | - /** Activer des outils pour développeurs ? */ |
|
| 533 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 532 | + /** Activer des outils pour développeurs ? */ |
|
| 533 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 537 | 537 | if (test_espace_prive()) { |
| 538 | - include_spip('inc/autoriser'); |
|
| 538 | + include_spip('inc/autoriser'); |
|
| 539 | 539 | } |
| 540 | 540 | // |
| 541 | 541 | // Installer Spip si pas installe... sauf si justement on est en train |
| 542 | 542 | // |
| 543 | 543 | if ( |
| 544 | - !(_FILE_CONNECT |
|
| 545 | - or autoriser_sans_cookie(_request('exec')) |
|
| 546 | - or _request('action') == 'cookie' |
|
| 547 | - or _request('action') == 'converser' |
|
| 548 | - or _request('action') == 'test_dirs') |
|
| 544 | + !(_FILE_CONNECT |
|
| 545 | + or autoriser_sans_cookie(_request('exec')) |
|
| 546 | + or _request('action') == 'cookie' |
|
| 547 | + or _request('action') == 'converser' |
|
| 548 | + or _request('action') == 'test_dirs') |
|
| 549 | 549 | ) { |
| 550 | - // Si on peut installer, on lance illico |
|
| 551 | - if (test_espace_prive()) { |
|
| 552 | - include_spip('inc/headers'); |
|
| 553 | - redirige_url_ecrire('install'); |
|
| 554 | - } else { |
|
| 555 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 556 | - include_spip('inc/minipres'); |
|
| 557 | - utiliser_langue_visiteur(); |
|
| 558 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 559 | - exit; |
|
| 560 | - } |
|
| 561 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 550 | + // Si on peut installer, on lance illico |
|
| 551 | + if (test_espace_prive()) { |
|
| 552 | + include_spip('inc/headers'); |
|
| 553 | + redirige_url_ecrire('install'); |
|
| 554 | + } else { |
|
| 555 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 556 | + include_spip('inc/minipres'); |
|
| 557 | + utiliser_langue_visiteur(); |
|
| 558 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 559 | + exit; |
|
| 560 | + } |
|
| 561 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | // memoriser un tri sessionne eventuel |
| 565 | 565 | if ( |
| 566 | - isset($_REQUEST['var_memotri']) |
|
| 567 | - and $t = $_REQUEST['var_memotri'] |
|
| 568 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 566 | + isset($_REQUEST['var_memotri']) |
|
| 567 | + and $t = $_REQUEST['var_memotri'] |
|
| 568 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 569 | 569 | ) { |
| 570 | - if (!function_exists('session_set')) { |
|
| 571 | - include_spip('inc/session'); |
|
| 572 | - } |
|
| 573 | - $t = preg_replace(',\W,', '_', $t); |
|
| 574 | - if ($v = _request($t)) { |
|
| 575 | - session_set($t, $v); |
|
| 576 | - } |
|
| 570 | + if (!function_exists('session_set')) { |
|
| 571 | + include_spip('inc/session'); |
|
| 572 | + } |
|
| 573 | + $t = preg_replace(',\W,', '_', $t); |
|
| 574 | + if ($v = _request($t)) { |
|
| 575 | + session_set($t, $v); |
|
| 576 | + } |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,22 +583,22 @@ discard block |
||
| 583 | 583 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 584 | 584 | */ |
| 585 | 585 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 586 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 586 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 587 | 587 | } |
| 588 | 588 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 589 | - if (!defined('_HEADER_VARY')) { |
|
| 590 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 591 | - } |
|
| 592 | - if (_HEADER_VARY) { |
|
| 593 | - header(_HEADER_VARY); |
|
| 594 | - } |
|
| 595 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 596 | - include_spip('inc/filtres_mini'); |
|
| 597 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 598 | - } else { |
|
| 599 | - // header minimal |
|
| 600 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 601 | - } |
|
| 589 | + if (!defined('_HEADER_VARY')) { |
|
| 590 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 591 | + } |
|
| 592 | + if (_HEADER_VARY) { |
|
| 593 | + header(_HEADER_VARY); |
|
| 594 | + } |
|
| 595 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 596 | + include_spip('inc/filtres_mini'); |
|
| 597 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 598 | + } else { |
|
| 599 | + // header minimal |
|
| 600 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 601 | + } |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * Ce programme est un logiciel libre distribué sous licence GNU/GPL. * |
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 12 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Initialisation de SPIP |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | define('_DIR_RACINE', _DIR_RESTREINT ? '' : '../'); |
| 54 | 54 | |
| 55 | 55 | /** chemin absolu vers la racine */ |
| 56 | -define('_ROOT_RACINE', dirname(__DIR__) . '/'); |
|
| 56 | +define('_ROOT_RACINE', dirname(__DIR__).'/'); |
|
| 57 | 57 | /** chemin absolu vers le repertoire de travail */ |
| 58 | -define('_ROOT_CWD', getcwd() . '/'); |
|
| 58 | +define('_ROOT_CWD', getcwd().'/'); |
|
| 59 | 59 | /** chemin absolu vers ecrire */ |
| 60 | -define('_ROOT_RESTREINT', _ROOT_CWD . _DIR_RESTREINT); |
|
| 60 | +define('_ROOT_RESTREINT', _ROOT_CWD._DIR_RESTREINT); |
|
| 61 | 61 | |
| 62 | 62 | // Icones |
| 63 | 63 | if (!defined('_NOM_IMG_PACK')) { |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | define('_NOM_IMG_PACK', 'images/'); |
| 66 | 66 | } |
| 67 | 67 | /** le chemin http (relatif) vers les images standard */ |
| 68 | -define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
|
| 68 | +define('_DIR_IMG_PACK', (_DIR_RACINE.'prive/'._NOM_IMG_PACK)); |
|
| 69 | 69 | |
| 70 | 70 | /** le chemin php (absolu) vers les images standard (pour hebergement centralise) */ |
| 71 | -define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
|
| 71 | +define('_ROOT_IMG_PACK', dirname(__DIR__).'/prive/'._NOM_IMG_PACK); |
|
| 72 | 72 | |
| 73 | 73 | if (!defined('_JAVASCRIPT')) { |
| 74 | 74 | /** Nom du repertoire des bibliotheques JavaScript */ |
| 75 | 75 | define('_JAVASCRIPT', 'javascript/'); |
| 76 | 76 | } // utilisable avec #CHEMIN et find_in_path |
| 77 | 77 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 78 | -define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
|
| 78 | +define('_DIR_JAVASCRIPT', (_DIR_RACINE.'prive/'._JAVASCRIPT)); |
|
| 79 | 79 | |
| 80 | 80 | # Le nom des 4 repertoires modifiables par les scripts lances par httpd |
| 81 | 81 | # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas) |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | // Son emplacement absolu si on le trouve |
| 108 | 108 | if ( |
| 109 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 110 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 109 | + @file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES._NOM_CONFIG.'.php') |
|
| 110 | + or (@file_exists($f = _ROOT_RESTREINT._NOM_CONFIG.'.php')) |
|
| 111 | 111 | ) { |
| 112 | 112 | /** Emplacement absolu du fichier d'option */ |
| 113 | 113 | define('_FILE_OPTIONS', $f); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | // inclure l'ecran de securite |
| 132 | 132 | if ( |
| 133 | 133 | !defined('_ECRAN_SECURITE') |
| 134 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 134 | + and @file_exists($f = _ROOT_RACINE._NOM_PERMANENTS_INACCESSIBLES.'ecran_securite.php') |
|
| 135 | 135 | ) { |
| 136 | 136 | include $f; |
| 137 | 137 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // UA plus cibles |
| 153 | 153 | . '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' |
| 154 | 154 | . ',i', |
| 155 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 155 | + (string) $_SERVER['HTTP_USER_AGENT'] |
|
| 156 | 156 | ) |
| 157 | 157 | ); |
| 158 | 158 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | # la matrice standard (fichiers definissant les fonctions a inclure) |
| 395 | 395 | $spip_matrice = []; |
| 396 | 396 | # les plugins a activer |
| 397 | -$plugins = []; // voir le contenu du repertoire /plugins/ |
|
| 397 | +$plugins = []; // voir le contenu du repertoire /plugins/ |
|
| 398 | 398 | # les surcharges de include_spip() |
| 399 | 399 | $surcharges = []; // format 'inc_truc' => '/plugins/chose/inc_truc2.php' |
| 400 | 400 | |
@@ -472,8 +472,8 @@ discard block |
||
| 472 | 472 | // |
| 473 | 473 | // Charger les fonctions liees aux serveurs Http et Sql. |
| 474 | 474 | // |
| 475 | -require_once _ROOT_RESTREINT . 'inc/utils.php'; |
|
| 476 | -require_once _ROOT_RESTREINT . 'base/connect_sql.php'; |
|
| 475 | +require_once _ROOT_RESTREINT.'inc/utils.php'; |
|
| 476 | +require_once _ROOT_RESTREINT.'base/connect_sql.php'; |
|
| 477 | 477 | |
| 478 | 478 | // Definition personnelles eventuelles |
| 479 | 479 | |
@@ -496,10 +496,10 @@ discard block |
||
| 496 | 496 | // ===> on execute en neutralisant les messages d'erreur |
| 497 | 497 | |
| 498 | 498 | spip_initialisation_core( |
| 499 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 501 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 502 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 499 | + (_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES), |
|
| 501 | + (_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 502 | + (_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 503 | 503 | ); |
| 504 | 504 | |
| 505 | 505 | |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | // Si on est dans le site public, dire que qq s'en occupe |
| 555 | 555 | include_spip('inc/minipres'); |
| 556 | 556 | utiliser_langue_visiteur(); |
| 557 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 557 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>"._T('info_travaux_texte').'</p>', ['status' => 503]); |
|
| 558 | 558 | exit; |
| 559 | 559 | } |
| 560 | 560 | // autrement c'est une install ad hoc (spikini...), on sait pas faire |
@@ -593,12 +593,12 @@ discard block |
||
| 593 | 593 | } |
| 594 | 594 | if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
| 595 | 595 | include_spip('inc/filtres_mini'); |
| 596 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 596 | + header(_HEADER_COMPOSED_BY." $spip_version_affichee @ www.spip.net + ".url_absolue(_DIR_VAR.'config.txt')); |
|
| 597 | 597 | } else { |
| 598 | 598 | // header minimal |
| 599 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 599 | + header(_HEADER_COMPOSED_BY.' @ www.spip.net'); |
|
| 600 | 600 | } |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |
| 604 | -spip_log($methode . ' ' . self() . ' - ' . _FILE_CONNECT, _LOG_DEBUG); |
|
| 604 | +spip_log($methode.' '.self().' - '._FILE_CONNECT, _LOG_DEBUG); |
|
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 26 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * Description de la boucle complétée des champs |
| 45 | 45 | */ |
| 46 | 46 | function iterateur_DATA_dist($b) { |
| 47 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | - $b->show = [ |
|
| 49 | - 'field' => [ |
|
| 50 | - 'cle' => 'STRING', |
|
| 51 | - 'valeur' => 'STRING', |
|
| 52 | - '*' => 'ALL' // Champ joker * |
|
| 53 | - ] |
|
| 54 | - ]; |
|
| 55 | - $b->select[] = '.valeur'; |
|
| 56 | - |
|
| 57 | - return $b; |
|
| 47 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | + $b->show = [ |
|
| 49 | + 'field' => [ |
|
| 50 | + 'cle' => 'STRING', |
|
| 51 | + 'valeur' => 'STRING', |
|
| 52 | + '*' => 'ALL' // Champ joker * |
|
| 53 | + ] |
|
| 54 | + ]; |
|
| 55 | + $b->select[] = '.valeur'; |
|
| 56 | + |
|
| 57 | + return $b; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function inc_file_to_array_dist($data) { |
| 72 | - return preg_split('/\r?\n/', $data); |
|
| 72 | + return preg_split('/\r?\n/', $data); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | function inc_plugins_to_array_dist() { |
| 81 | - include_spip('inc/plugin'); |
|
| 81 | + include_spip('inc/plugin'); |
|
| 82 | 82 | |
| 83 | - return liste_chemin_plugin_actifs(); |
|
| 83 | + return liste_chemin_plugin_actifs(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | 92 | function inc_xml_to_array_dist($data) { |
| 93 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | */ |
| 104 | 104 | function inc_object_to_array($object) { |
| 105 | - if (!is_object($object) && !is_array($object)) { |
|
| 106 | - return $object; |
|
| 107 | - } |
|
| 108 | - if (is_object($object)) { |
|
| 109 | - $object = get_object_vars($object); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return array_map('inc_object_to_array', $object); |
|
| 105 | + if (!is_object($object) && !is_array($object)) { |
|
| 106 | + return $object; |
|
| 107 | + } |
|
| 108 | + if (is_object($object)) { |
|
| 109 | + $object = get_object_vars($object); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return array_map('inc_object_to_array', $object); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,20 +119,20 @@ discard block |
||
| 119 | 119 | * @return array|bool |
| 120 | 120 | */ |
| 121 | 121 | function inc_sql_to_array_dist($data) { |
| 122 | - # sortir le connecteur de $data |
|
| 123 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | - $serveur = (string)$v[1]; |
|
| 125 | - $req = trim($v[2]); |
|
| 126 | - if ($s = sql_query($req, $serveur)) { |
|
| 127 | - $r = []; |
|
| 128 | - while ($t = sql_fetch($s)) { |
|
| 129 | - $r[] = $t; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $r; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return false; |
|
| 122 | + # sortir le connecteur de $data |
|
| 123 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | + $serveur = (string)$v[1]; |
|
| 125 | + $req = trim($v[2]); |
|
| 126 | + if ($s = sql_query($req, $serveur)) { |
|
| 127 | + $r = []; |
|
| 128 | + while ($t = sql_fetch($s)) { |
|
| 129 | + $r[] = $t; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $r; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | * @return array|bool |
| 143 | 143 | */ |
| 144 | 144 | function inc_json_to_array_dist($data) { |
| 145 | - try { |
|
| 146 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | - } catch (JsonException $e) { |
|
| 148 | - $json = null; |
|
| 149 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | - } |
|
| 151 | - return is_array($json) ? (array) $json : []; |
|
| 145 | + try { |
|
| 146 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | + } catch (JsonException $e) { |
|
| 148 | + $json = null; |
|
| 149 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | + } |
|
| 151 | + return is_array($json) ? (array) $json : []; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return array|bool |
| 159 | 159 | */ |
| 160 | 160 | function inc_csv_to_array_dist($data) { |
| 161 | - include_spip('inc/csv'); |
|
| 162 | - [$entete, $csv] = analyse_csv($data); |
|
| 163 | - array_unshift($csv, $entete); |
|
| 164 | - |
|
| 165 | - include_spip('inc/charsets'); |
|
| 166 | - $i = 1; |
|
| 167 | - foreach ($entete as $k => $v) { |
|
| 168 | - if (trim($v) == '') { |
|
| 169 | - $v = 'col' . $i; |
|
| 170 | - } // reperer des eventuelles cases vides |
|
| 171 | - if (is_numeric($v) and $v < 0) { |
|
| 172 | - $v = '__' . $v; |
|
| 173 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | - if (is_numeric($v)) { |
|
| 175 | - $v = '_' . $v; |
|
| 176 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | - foreach ($csv as &$item) { |
|
| 179 | - $item[$v] = &$item[$k]; |
|
| 180 | - } |
|
| 181 | - $i++; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $csv; |
|
| 161 | + include_spip('inc/csv'); |
|
| 162 | + [$entete, $csv] = analyse_csv($data); |
|
| 163 | + array_unshift($csv, $entete); |
|
| 164 | + |
|
| 165 | + include_spip('inc/charsets'); |
|
| 166 | + $i = 1; |
|
| 167 | + foreach ($entete as $k => $v) { |
|
| 168 | + if (trim($v) == '') { |
|
| 169 | + $v = 'col' . $i; |
|
| 170 | + } // reperer des eventuelles cases vides |
|
| 171 | + if (is_numeric($v) and $v < 0) { |
|
| 172 | + $v = '__' . $v; |
|
| 173 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | + if (is_numeric($v)) { |
|
| 175 | + $v = '_' . $v; |
|
| 176 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | + foreach ($csv as &$item) { |
|
| 179 | + $item[$v] = &$item[$k]; |
|
| 180 | + } |
|
| 181 | + $i++; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $csv; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return array|bool |
| 192 | 192 | */ |
| 193 | 193 | function inc_rss_to_array_dist($data) { |
| 194 | - $tableau = null; |
|
| 195 | - include_spip('inc/syndic'); |
|
| 196 | - if (is_array($rss = analyser_backend($data))) { |
|
| 197 | - $tableau = $rss; |
|
| 198 | - } |
|
| 194 | + $tableau = null; |
|
| 195 | + include_spip('inc/syndic'); |
|
| 196 | + if (is_array($rss = analyser_backend($data))) { |
|
| 197 | + $tableau = $rss; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - return $tableau; |
|
| 200 | + return $tableau; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | * @return array|bool |
| 208 | 208 | */ |
| 209 | 209 | function inc_atom_to_array_dist($data) { |
| 210 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 211 | 211 | |
| 212 | - return $rss_to_array($data); |
|
| 212 | + return $rss_to_array($data); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | * @return array|bool |
| 221 | 221 | */ |
| 222 | 222 | function inc_glob_to_array_dist($data) { |
| 223 | - $a = glob( |
|
| 224 | - $data, |
|
| 225 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | - ); |
|
| 223 | + $a = glob( |
|
| 224 | + $data, |
|
| 225 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - return $a ?: []; |
|
| 228 | + return $a ?: []; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * @throws Exception |
| 237 | 237 | */ |
| 238 | 238 | function inc_yaml_to_array_dist($data) { |
| 239 | - include_spip('inc/yaml-mini'); |
|
| 240 | - if (!function_exists('yaml_decode')) { |
|
| 241 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 239 | + include_spip('inc/yaml-mini'); |
|
| 240 | + if (!function_exists('yaml_decode')) { |
|
| 241 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 242 | 242 | |
| 243 | - return false; |
|
| 244 | - } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return yaml_decode($data); |
|
| 246 | + return yaml_decode($data); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return array|bool |
| 259 | 259 | */ |
| 260 | 260 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 261 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | * @return array|bool |
| 271 | 271 | */ |
| 272 | 272 | function inc_ls_to_array_dist($data) { |
| 273 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | - $a = $glob_to_array($data); |
|
| 275 | - foreach ($a as &$v) { |
|
| 276 | - $b = (array)@stat($v); |
|
| 277 | - foreach ($b as $k => $ignore) { |
|
| 278 | - if (is_numeric($k)) { |
|
| 279 | - unset($b[$k]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | - $v = array_merge( |
|
| 284 | - pathinfo($v), |
|
| 285 | - $b |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $a; |
|
| 273 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | + $a = $glob_to_array($data); |
|
| 275 | + foreach ($a as &$v) { |
|
| 276 | + $b = (array)@stat($v); |
|
| 277 | + foreach ($b as $k => $ignore) { |
|
| 278 | + if (is_numeric($k)) { |
|
| 279 | + unset($b[$k]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | + $v = array_merge( |
|
| 284 | + pathinfo($v), |
|
| 285 | + $b |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $a; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,25 +296,25 @@ discard block |
||
| 296 | 296 | * @return array|bool |
| 297 | 297 | */ |
| 298 | 298 | function XMLObjectToArray($object) { |
| 299 | - $xml_array = []; |
|
| 300 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | - $key .= '-' . uniqid(); |
|
| 303 | - } |
|
| 304 | - $vars = get_object_vars($object->current()); |
|
| 305 | - if (isset($vars['@attributes'])) { |
|
| 306 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | - $xml_array[$key][$k] = $v; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if ($object->hasChildren()) { |
|
| 311 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | - $object->current() |
|
| 313 | - ); |
|
| 314 | - } else { |
|
| 315 | - $xml_array[$key][] = strval($object->current()); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $xml_array; |
|
| 299 | + $xml_array = []; |
|
| 300 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | + $key .= '-' . uniqid(); |
|
| 303 | + } |
|
| 304 | + $vars = get_object_vars($object->current()); |
|
| 305 | + if (isset($vars['@attributes'])) { |
|
| 306 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | + $xml_array[$key][$k] = $v; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if ($object->hasChildren()) { |
|
| 311 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | + $object->current() |
|
| 313 | + ); |
|
| 314 | + } else { |
|
| 315 | + $xml_array[$key][] = strval($object->current()); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $xml_array; |
|
| 320 | 320 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | function inc_sql_to_array_dist($data) { |
| 122 | 122 | # sortir le connecteur de $data |
| 123 | 123 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 124 | - $serveur = (string)$v[1]; |
|
| 124 | + $serveur = (string) $v[1]; |
|
| 125 | 125 | $req = trim($v[2]); |
| 126 | 126 | if ($s = sql_query($req, $serveur)) { |
| 127 | 127 | $r = []; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 147 | 147 | } catch (JsonException $e) { |
| 148 | 148 | $json = null; |
| 149 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 150 | 150 | } |
| 151 | 151 | return is_array($json) ? (array) $json : []; |
| 152 | 152 | } |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | $i = 1; |
| 167 | 167 | foreach ($entete as $k => $v) { |
| 168 | 168 | if (trim($v) == '') { |
| 169 | - $v = 'col' . $i; |
|
| 169 | + $v = 'col'.$i; |
|
| 170 | 170 | } // reperer des eventuelles cases vides |
| 171 | 171 | if (is_numeric($v) and $v < 0) { |
| 172 | - $v = '__' . $v; |
|
| 172 | + $v = '__'.$v; |
|
| 173 | 173 | } // ne pas risquer d'ecraser une cle numerique |
| 174 | 174 | if (is_numeric($v)) { |
| 175 | - $v = '_' . $v; |
|
| 175 | + $v = '_'.$v; |
|
| 176 | 176 | } // ne pas risquer d'ecraser une cle numerique |
| 177 | 177 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 178 | 178 | foreach ($csv as &$item) { |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return array|bool |
| 259 | 259 | */ |
| 260 | 260 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 261 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 274 | 274 | $a = $glob_to_array($data); |
| 275 | 275 | foreach ($a as &$v) { |
| 276 | - $b = (array)@stat($v); |
|
| 276 | + $b = (array) @stat($v); |
|
| 277 | 277 | foreach ($b as $k => $ignore) { |
| 278 | 278 | if (is_numeric($k)) { |
| 279 | 279 | unset($b[$k]); |
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 282 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 283 | 283 | $v = array_merge( |
| 284 | 284 | pathinfo($v), |
| 285 | 285 | $b |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $xml_array = []; |
| 300 | 300 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 301 | 301 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 302 | - $key .= '-' . uniqid(); |
|
| 302 | + $key .= '-'.uniqid(); |
|
| 303 | 303 | } |
| 304 | 304 | $vars = get_object_vars($object->current()); |
| 305 | 305 | if (isset($vars['@attributes'])) { |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('iterateur/data'); |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | * Description de la boucle complétée des champs |
| 38 | 38 | */ |
| 39 | 39 | function iterateur_CONDITION_dist($b) { |
| 40 | - $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | - $b->show = [ |
|
| 42 | - 'field' => [] |
|
| 43 | - ]; |
|
| 40 | + $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | + $b->show = [ |
|
| 42 | + 'field' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - return $b; |
|
| 45 | + return $b; |
|
| 46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_POUR_dist($b) { |
| 41 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 41 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - return $b; |
|
| 49 | + return $b; |
|
| 50 | 50 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_php_dist($b, $iteratorName) { |
| 41 | - $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | - $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $b; |
|
| 41 | + $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | + $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $b; |
|
| 54 | 54 | } |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | if (test_espace_prive()) { |
| 22 | - include_spip('inc/pipelines_ecrire'); |
|
| 22 | + include_spip('inc/pipelines_ecrire'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -45,28 +45,28 @@ discard block |
||
| 45 | 45 | * @return string Contenu qui sera inséré dans le head HTML |
| 46 | 46 | **/ |
| 47 | 47 | function f_jQuery($texte) { |
| 48 | - $x = ''; |
|
| 49 | - $jquery_plugins = pipeline( |
|
| 50 | - 'jquery_plugins', |
|
| 51 | - [ |
|
| 52 | - 'javascript/jquery.js', |
|
| 53 | - 'javascript/jquery.form.js', |
|
| 54 | - 'javascript/jquery.autosave.js', |
|
| 55 | - 'javascript/jquery.placeholder-label.js', |
|
| 56 | - 'javascript/ajaxCallback.js', |
|
| 57 | - 'javascript/js.cookie.js', |
|
| 58 | - ] |
|
| 59 | - ); |
|
| 60 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 61 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 62 | - $script = timestamp($script); |
|
| 63 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 48 | + $x = ''; |
|
| 49 | + $jquery_plugins = pipeline( |
|
| 50 | + 'jquery_plugins', |
|
| 51 | + [ |
|
| 52 | + 'javascript/jquery.js', |
|
| 53 | + 'javascript/jquery.form.js', |
|
| 54 | + 'javascript/jquery.autosave.js', |
|
| 55 | + 'javascript/jquery.placeholder-label.js', |
|
| 56 | + 'javascript/ajaxCallback.js', |
|
| 57 | + 'javascript/js.cookie.js', |
|
| 58 | + ] |
|
| 59 | + ); |
|
| 60 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 61 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 62 | + $script = timestamp($script); |
|
| 63 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $texte = $x . $texte; |
|
| 67 | + $texte = $x . $texte; |
|
| 68 | 68 | |
| 69 | - return $texte; |
|
| 69 | + return $texte; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | * @return string Contenu de la page envoyée au navigateur |
| 86 | 86 | **/ |
| 87 | 87 | function f_surligne($texte) { |
| 88 | - if (!$GLOBALS['html']) { |
|
| 89 | - return $texte; |
|
| 90 | - } |
|
| 91 | - $rech = _request('var_recherche'); |
|
| 92 | - if ( |
|
| 93 | - !$rech |
|
| 94 | - and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 95 | - or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 96 | - or !isset($_SERVER['HTTP_REFERER'])) |
|
| 97 | - ) { |
|
| 98 | - return $texte; |
|
| 99 | - } |
|
| 100 | - include_spip('inc/surligne'); |
|
| 88 | + if (!$GLOBALS['html']) { |
|
| 89 | + return $texte; |
|
| 90 | + } |
|
| 91 | + $rech = _request('var_recherche'); |
|
| 92 | + if ( |
|
| 93 | + !$rech |
|
| 94 | + and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 95 | + or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 96 | + or !isset($_SERVER['HTTP_REFERER'])) |
|
| 97 | + ) { |
|
| 98 | + return $texte; |
|
| 99 | + } |
|
| 100 | + include_spip('inc/surligne'); |
|
| 101 | 101 | |
| 102 | - if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 103 | - $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 104 | - } |
|
| 105 | - if ($rech) { |
|
| 106 | - $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 107 | - } |
|
| 102 | + if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 103 | + $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 104 | + } |
|
| 105 | + if ($rech) { |
|
| 106 | + $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return surligner_mots($texte, $rech); |
|
| 109 | + return surligner_mots($texte, $rech); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -123,33 +123,33 @@ discard block |
||
| 123 | 123 | * @return string Contenu de la page envoyée au navigateur |
| 124 | 124 | **/ |
| 125 | 125 | function f_tidy($texte) { |
| 126 | - /** |
|
| 127 | - * Indentation à faire ? |
|
| 128 | - * |
|
| 129 | - * - true : actif. |
|
| 130 | - * - false par défaut. |
|
| 131 | - */ |
|
| 126 | + /** |
|
| 127 | + * Indentation à faire ? |
|
| 128 | + * |
|
| 129 | + * - true : actif. |
|
| 130 | + * - false par défaut. |
|
| 131 | + */ |
|
| 132 | 132 | |
| 133 | - if ( |
|
| 134 | - $GLOBALS['xhtml'] # tidy demande |
|
| 135 | - and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 136 | - and strlen($texte) |
|
| 137 | - and !headers_sent() |
|
| 138 | - ) { |
|
| 139 | - # Compatibilite ascendante |
|
| 140 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 141 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 142 | - } |
|
| 133 | + if ( |
|
| 134 | + $GLOBALS['xhtml'] # tidy demande |
|
| 135 | + and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 136 | + and strlen($texte) |
|
| 137 | + and !headers_sent() |
|
| 138 | + ) { |
|
| 139 | + # Compatibilite ascendante |
|
| 140 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 141 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 145 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 146 | - $f = charger_fonction('sax', 'xml'); |
|
| 147 | - } |
|
| 144 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 145 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 146 | + $f = charger_fonction('sax', 'xml'); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return $f($texte); |
|
| 150 | - } |
|
| 149 | + return $f($texte); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $texte; |
|
| 152 | + return $texte; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -168,21 +168,21 @@ discard block |
||
| 168 | 168 | * @return string Contenu de la page envoyée au navigateur |
| 169 | 169 | **/ |
| 170 | 170 | function f_insert_head($texte) { |
| 171 | - if (!$GLOBALS['html']) { |
|
| 172 | - return $texte; |
|
| 173 | - } |
|
| 174 | - include_spip('public/admin'); // pour strripos |
|
| 171 | + if (!$GLOBALS['html']) { |
|
| 172 | + return $texte; |
|
| 173 | + } |
|
| 174 | + include_spip('public/admin'); // pour strripos |
|
| 175 | 175 | |
| 176 | - ($pos = stripos($texte, '</head>')) |
|
| 177 | - || ($pos = stripos($texte, '<body>')) |
|
| 178 | - || ($pos = 0); |
|
| 176 | + ($pos = stripos($texte, '</head>')) |
|
| 177 | + || ($pos = stripos($texte, '<body>')) |
|
| 178 | + || ($pos = 0); |
|
| 179 | 179 | |
| 180 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 181 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 182 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 183 | - } |
|
| 180 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 181 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 182 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - return $texte; |
|
| 185 | + return $texte; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -198,34 +198,34 @@ discard block |
||
| 198 | 198 | * @return string Contenu de la page envoyée au navigateur |
| 199 | 199 | **/ |
| 200 | 200 | function f_admin($texte) { |
| 201 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 202 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 203 | - $x = "<div class='spip-previsu' " |
|
| 204 | - . http_style_background('preview-32.png', '', 32) |
|
| 205 | - . '>' |
|
| 206 | - . _T('previsualisation') |
|
| 207 | - . '</div>'; |
|
| 208 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 209 | - $pos = strlen($texte); |
|
| 210 | - } |
|
| 211 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 212 | - // pas de preview en fenetre enfant |
|
| 213 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 214 | - if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 215 | - $pos = -1; |
|
| 216 | - } |
|
| 217 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 218 | - } |
|
| 201 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 202 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 203 | + $x = "<div class='spip-previsu' " |
|
| 204 | + . http_style_background('preview-32.png', '', 32) |
|
| 205 | + . '>' |
|
| 206 | + . _T('previsualisation') |
|
| 207 | + . '</div>'; |
|
| 208 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 209 | + $pos = strlen($texte); |
|
| 210 | + } |
|
| 211 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 212 | + // pas de preview en fenetre enfant |
|
| 213 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 214 | + if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 215 | + $pos = -1; |
|
| 216 | + } |
|
| 217 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 221 | - include_spip('public/admin'); |
|
| 222 | - $texte = affiche_boutons_admin($texte); |
|
| 223 | - } |
|
| 224 | - if (_request('var_mode') == 'noajax') { |
|
| 225 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 226 | - } |
|
| 220 | + if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 221 | + include_spip('public/admin'); |
|
| 222 | + $texte = affiche_boutons_admin($texte); |
|
| 223 | + } |
|
| 224 | + if (_request('var_mode') == 'noajax') { |
|
| 225 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return $texte; |
|
| 228 | + return $texte; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * @return array $flux Description et contenu de l'inclusion |
| 244 | 244 | **/ |
| 245 | 245 | function f_recuperer_fond($flux) { |
| 246 | - if (!test_espace_prive()) { |
|
| 247 | - return $flux; |
|
| 248 | - } |
|
| 246 | + if (!test_espace_prive()) { |
|
| 247 | + return $flux; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return f_afficher_blocs_ecrire($flux); |
|
| 250 | + return f_afficher_blocs_ecrire($flux); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -261,30 +261,30 @@ discard block |
||
| 261 | 261 | * @return string Contenu de la page envoyée au navigateur |
| 262 | 262 | */ |
| 263 | 263 | function f_queue($texte) { |
| 264 | - // eviter une inclusion si rien a faire |
|
| 265 | - if ( |
|
| 266 | - _request('action') == 'cron' |
|
| 267 | - or queue_sleep_time_to_next_job() > 0 |
|
| 268 | - or defined('_DEBUG_BLOCK_QUEUE') |
|
| 269 | - ) { |
|
| 270 | - return $texte; |
|
| 271 | - } |
|
| 264 | + // eviter une inclusion si rien a faire |
|
| 265 | + if ( |
|
| 266 | + _request('action') == 'cron' |
|
| 267 | + or queue_sleep_time_to_next_job() > 0 |
|
| 268 | + or defined('_DEBUG_BLOCK_QUEUE') |
|
| 269 | + ) { |
|
| 270 | + return $texte; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - include_spip('inc/queue'); |
|
| 274 | - $code = queue_affichage_cron(); |
|
| 273 | + include_spip('inc/queue'); |
|
| 274 | + $code = queue_affichage_cron(); |
|
| 275 | 275 | |
| 276 | - // si rien a afficher |
|
| 277 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 278 | - if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 279 | - return $texte; |
|
| 280 | - } |
|
| 276 | + // si rien a afficher |
|
| 277 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 278 | + if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 279 | + return $texte; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 283 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 284 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 285 | - } else { |
|
| 286 | - $texte .= $code; |
|
| 287 | - } |
|
| 282 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 283 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 284 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 285 | + } else { |
|
| 286 | + $texte .= $code; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return $texte; |
|
| 289 | + return $texte; |
|
| 290 | 290 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - $texte = $x . $texte; |
|
| 67 | + $texte = $x.$texte; |
|
| 68 | 68 | |
| 69 | 69 | return $texte; |
| 70 | 70 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | || ($pos = 0); |
| 179 | 179 | |
| 180 | 180 | if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
| 181 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 181 | + $insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n"; |
|
| 182 | 182 | $texte = substr_replace($texte, $insert, $pos, 0); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | $texte = substr_replace($texte, $x, $pos, 0); |
| 212 | 212 | // pas de preview en fenetre enfant |
| 213 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 213 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes($GLOBALS['meta']['adresse_site'])."';}</script>"; |
|
| 214 | 214 | if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
| 215 | 215 | $pos = -1; |
| 216 | 216 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | |
| 282 | 282 | // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
| 283 | 283 | if (($p = strpos($texte, '</body>')) !== false) { |
| 284 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 284 | + $texte = substr($texte, 0, $p).$code.substr($texte, $p); |
|
| 285 | 285 | } else { |
| 286 | 286 | $texte .= $code; |
| 287 | 287 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 41 | 41 | */ |
| 42 | 42 | function find_langs_in_path($file, $dirname = 'lang') { |
| 43 | - static $dirs = []; |
|
| 44 | - $liste = []; |
|
| 45 | - foreach (creer_chemin() as $dir) { |
|
| 46 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | - } |
|
| 49 | - if ($dirs[$a]) { |
|
| 50 | - if (is_readable($a .= $file)) { |
|
| 51 | - $liste[] = $a; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 43 | + static $dirs = []; |
|
| 44 | + $liste = []; |
|
| 45 | + foreach (creer_chemin() as $dir) { |
|
| 46 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | + } |
|
| 49 | + if ($dirs[$a]) { |
|
| 50 | + if (is_readable($a .= $file)) { |
|
| 51 | + $liste[] = $a; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return array_reverse($liste); |
|
| 56 | + return array_reverse($liste); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -68,23 +68,23 @@ discard block |
||
| 68 | 68 | * Liste des fichiers touvés pour ce module et cette langue. |
| 69 | 69 | **/ |
| 70 | 70 | function chercher_module_lang($module, $lang = '') { |
| 71 | - if ($lang) { |
|
| 72 | - $lang = '_' . $lang; |
|
| 73 | - } |
|
| 71 | + if ($lang) { |
|
| 72 | + $lang = '_' . $lang; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | - if ( |
|
| 77 | - $f = ($module == 'local' |
|
| 78 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | - ) { |
|
| 81 | - return is_array($f) ? $f : [$f]; |
|
| 82 | - } |
|
| 75 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | + if ( |
|
| 77 | + $f = ($module == 'local' |
|
| 78 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | + ) { |
|
| 81 | + return is_array($f) ? $f : [$f]; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | - return (($module == 'local') or strpos($module, '/')) |
|
| 86 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | - : false; |
|
| 84 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | + return (($module == 'local') or strpos($module, '/')) |
|
| 86 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | + : false; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -106,33 +106,33 @@ discard block |
||
| 106 | 106 | * @return void |
| 107 | 107 | **/ |
| 108 | 108 | function charger_langue($lang, $module = 'spip') { |
| 109 | - static $langs = []; |
|
| 110 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | - if (!isset($langs[$lang])) { |
|
| 112 | - $langs[$lang] = []; |
|
| 113 | - if ($lang) { |
|
| 114 | - $langs[$lang][] = $lang; |
|
| 115 | - if (strpos($lang, '_') !== false) { |
|
| 116 | - $l = explode('_', $lang); |
|
| 117 | - $langs[$lang][] = reset($l); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | - } |
|
| 123 | - foreach ($langs[$lang] as $l) { |
|
| 124 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | - surcharger_langue($fichiers_lang); |
|
| 128 | - if ($l !== $lang) { |
|
| 129 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | - } |
|
| 131 | - $GLOBALS['lang_' . $var] = $l; |
|
| 132 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 109 | + static $langs = []; |
|
| 110 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | + if (!isset($langs[$lang])) { |
|
| 112 | + $langs[$lang] = []; |
|
| 113 | + if ($lang) { |
|
| 114 | + $langs[$lang][] = $lang; |
|
| 115 | + if (strpos($lang, '_') !== false) { |
|
| 116 | + $l = explode('_', $lang); |
|
| 117 | + $langs[$lang][] = reset($l); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | + } |
|
| 123 | + foreach ($langs[$lang] as $l) { |
|
| 124 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | + surcharger_langue($fichiers_lang); |
|
| 128 | + if ($l !== $lang) { |
|
| 129 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | + } |
|
| 131 | + $GLOBALS['lang_' . $var] = $l; |
|
| 132 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -145,21 +145,21 @@ discard block |
||
| 145 | 145 | * @return array<string, string> |
| 146 | 146 | */ |
| 147 | 147 | function lire_fichier_langue(string $fichier): array { |
| 148 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | - $idx_lang = include $fichier; |
|
| 152 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | - if (!is_array($idx_lang)) { |
|
| 154 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | - } else { |
|
| 157 | - $idx_lang = []; |
|
| 158 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | - } |
|
| 160 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | - } |
|
| 162 | - return $idx_lang; |
|
| 148 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | + $idx_lang = include $fichier; |
|
| 152 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | + if (!is_array($idx_lang)) { |
|
| 154 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | + } else { |
|
| 157 | + $idx_lang = []; |
|
| 158 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | + } |
|
| 160 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | + } |
|
| 162 | + return $idx_lang; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -179,29 +179,29 @@ discard block |
||
| 179 | 179 | * Liste des chemins de fichiers de langue à surcharger. |
| 180 | 180 | **/ |
| 181 | 181 | function surcharger_langue($fichiers) { |
| 182 | - static $surcharges = []; |
|
| 183 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | - return; |
|
| 185 | - } |
|
| 182 | + static $surcharges = []; |
|
| 183 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if (!is_array($fichiers)) { |
|
| 188 | - $fichiers = [$fichiers]; |
|
| 189 | - } |
|
| 190 | - if (!count($fichiers)) { |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - foreach ($fichiers as $fichier) { |
|
| 194 | - if (!isset($surcharges[$fichier])) { |
|
| 195 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | - } |
|
| 197 | - if (is_array($surcharges[$fichier])) { |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | - $surcharges[$fichier] |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 187 | + if (!is_array($fichiers)) { |
|
| 188 | + $fichiers = [$fichiers]; |
|
| 189 | + } |
|
| 190 | + if (!count($fichiers)) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + foreach ($fichiers as $fichier) { |
|
| 194 | + if (!isset($surcharges[$fichier])) { |
|
| 195 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | + } |
|
| 197 | + if (is_array($surcharges[$fichier])) { |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | + $surcharges[$fichier] |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -242,99 +242,99 @@ discard block |
||
| 242 | 242 | * - Description : traduction et description (texte, module, langue) |
| 243 | 243 | **/ |
| 244 | 244 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 245 | - static $deja_vu = []; |
|
| 246 | - static $local = []; |
|
| 245 | + static $deja_vu = []; |
|
| 246 | + static $local = []; |
|
| 247 | 247 | |
| 248 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | - } |
|
| 248 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | - if (strpos($ori, ':')) { |
|
| 254 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | - $modules = explode('|', $modules); |
|
| 256 | - $ori_complet = $ori; |
|
| 257 | - } else { |
|
| 258 | - $modules = ['spip', 'ecrire']; |
|
| 259 | - $code = $ori; |
|
| 260 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | - } |
|
| 252 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | + if (strpos($ori, ':')) { |
|
| 254 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | + $modules = explode('|', $modules); |
|
| 256 | + $ori_complet = $ori; |
|
| 257 | + } else { |
|
| 258 | + $modules = ['spip', 'ecrire']; |
|
| 259 | + $code = $ori; |
|
| 260 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $desc = new Description(); |
|
| 263 | + $desc = new Description(); |
|
| 264 | 264 | |
| 265 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | - foreach ($modules as $module) { |
|
| 267 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 265 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | + foreach ($modules as $module) { |
|
| 267 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 268 | 268 | |
| 269 | - if (empty($GLOBALS[$var])) { |
|
| 270 | - charger_langue($lang, $module); |
|
| 271 | - // surcharges persos -- on cherche |
|
| 272 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | - if (!isset($local['local_' . $lang])) { |
|
| 274 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | - $GLOBALS['idx_lang'] = $var; |
|
| 276 | - // ... (lang/)local_xx.php |
|
| 277 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | - } |
|
| 279 | - if ($local['local_' . $lang]) { |
|
| 280 | - surcharger_langue($local['local_' . $lang]); |
|
| 281 | - } |
|
| 282 | - // ... puis (lang/)local.php |
|
| 283 | - if (!isset($local['local'])) { |
|
| 284 | - $local['local'] = chercher_module_lang('local'); |
|
| 285 | - } |
|
| 286 | - if ($local['local']) { |
|
| 287 | - surcharger_langue($local['local']); |
|
| 288 | - } |
|
| 289 | - } |
|
| 269 | + if (empty($GLOBALS[$var])) { |
|
| 270 | + charger_langue($lang, $module); |
|
| 271 | + // surcharges persos -- on cherche |
|
| 272 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | + if (!isset($local['local_' . $lang])) { |
|
| 274 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | + $GLOBALS['idx_lang'] = $var; |
|
| 276 | + // ... (lang/)local_xx.php |
|
| 277 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | + } |
|
| 279 | + if ($local['local_' . $lang]) { |
|
| 280 | + surcharger_langue($local['local_' . $lang]); |
|
| 281 | + } |
|
| 282 | + // ... puis (lang/)local.php |
|
| 283 | + if (!isset($local['local'])) { |
|
| 284 | + $local['local'] = chercher_module_lang('local'); |
|
| 285 | + } |
|
| 286 | + if ($local['local']) { |
|
| 287 | + surcharger_langue($local['local']); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - if (isset($GLOBALS[$var][$code])) { |
|
| 292 | - $desc->code = $code; |
|
| 293 | - $desc->module = $module; |
|
| 294 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | - break; |
|
| 297 | - } |
|
| 298 | - } |
|
| 291 | + if (isset($GLOBALS[$var][$code])) { |
|
| 292 | + $desc->code = $code; |
|
| 293 | + $desc->module = $module; |
|
| 294 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | + break; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - if (!$desc->corrections) { |
|
| 301 | - $desc->corrections = true; |
|
| 302 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | - if ( |
|
| 305 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | - ) { |
|
| 308 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | - } else { |
|
| 311 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | - } |
|
| 313 | - } |
|
| 300 | + if (!$desc->corrections) { |
|
| 301 | + $desc->corrections = true; |
|
| 302 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | + if ( |
|
| 305 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | + ) { |
|
| 308 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | + } else { |
|
| 311 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | - } |
|
| 315 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | - if ( |
|
| 323 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | - ) { |
|
| 326 | - include_spip('inc/charsets'); |
|
| 327 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | - } |
|
| 329 | - } |
|
| 320 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | + if ( |
|
| 323 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | + ) { |
|
| 326 | + include_spip('inc/charsets'); |
|
| 327 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - if (_request('var_mode') == 'traduction') { |
|
| 332 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | - } else { |
|
| 334 | - $deja_vu[$lang][$ori] = $desc; |
|
| 335 | - } |
|
| 331 | + if (_request('var_mode') == 'traduction') { |
|
| 332 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | + } else { |
|
| 334 | + $deja_vu[$lang][$ori] = $desc; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - return $raw ? $desc : $desc->texte; |
|
| 337 | + return $raw ? $desc : $desc->texte; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -346,23 +346,23 @@ discard block |
||
| 346 | 346 | * @return Description |
| 347 | 347 | */ |
| 348 | 348 | function definir_details_traduction($desc, $modules) { |
| 349 | - if (!$desc->mode and $desc->texte) { |
|
| 350 | - // ne pas modifier 2 fois l'affichage |
|
| 351 | - $desc->mode = 'traduction'; |
|
| 352 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | - $desc->texte = '<span ' |
|
| 354 | - . 'lang=' . $desc->langue |
|
| 355 | - . ' class=' . $classe |
|
| 356 | - . ' data-module=' . $desc->module |
|
| 357 | - . ' data-code=' . $desc->code |
|
| 358 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | - . $desc->texte |
|
| 360 | - . '</span>'; |
|
| 361 | - $desc->texte = str_replace( |
|
| 362 | - ["$desc->module:", "$desc->module|"], |
|
| 363 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | - $desc->texte |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - return $desc; |
|
| 349 | + if (!$desc->mode and $desc->texte) { |
|
| 350 | + // ne pas modifier 2 fois l'affichage |
|
| 351 | + $desc->mode = 'traduction'; |
|
| 352 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | + $desc->texte = '<span ' |
|
| 354 | + . 'lang=' . $desc->langue |
|
| 355 | + . ' class=' . $classe |
|
| 356 | + . ' data-module=' . $desc->module |
|
| 357 | + . ' data-code=' . $desc->code |
|
| 358 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | + . $desc->texte |
|
| 360 | + . '</span>'; |
|
| 361 | + $desc->texte = str_replace( |
|
| 362 | + ["$desc->module:", "$desc->module|"], |
|
| 363 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | + $desc->texte |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + return $desc; |
|
| 368 | 368 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | static $dirs = []; |
| 44 | 44 | $liste = []; |
| 45 | 45 | foreach (creer_chemin() as $dir) { |
| 46 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 46 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 47 | 47 | $dirs[$a] = (is_dir($a) || !$a); |
| 48 | 48 | } |
| 49 | 49 | if ($dirs[$a]) { |
@@ -69,21 +69,21 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function chercher_module_lang($module, $lang = '') { |
| 71 | 71 | if ($lang) { |
| 72 | - $lang = '_' . $lang; |
|
| 72 | + $lang = '_'.$lang; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
| 76 | 76 | if ( |
| 77 | 77 | $f = ($module == 'local' |
| 78 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | + ? find_in_path($module.$lang.'.php', 'lang/') |
|
| 79 | + : find_langs_in_path($module.$lang.'.php', 'lang/')) |
|
| 80 | 80 | ) { |
| 81 | 81 | return is_array($f) ? $f : [$f]; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // 2) directement dans le chemin (old style, uniquement pour local) |
| 85 | 85 | return (($module == 'local') or strpos($module, '/')) |
| 86 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 86 | + ? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false) |
|
| 87 | 87 | : false; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | **/ |
| 108 | 108 | function charger_langue($lang, $module = 'spip') { |
| 109 | 109 | static $langs = []; |
| 110 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 110 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 111 | 111 | if (!isset($langs[$lang])) { |
| 112 | 112 | $langs[$lang] = []; |
| 113 | 113 | if ($lang) { |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | foreach ($langs[$lang] as $l) { |
| 124 | 124 | if ($fichiers_lang = chercher_module_lang($module, $l)) { |
| 125 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 125 | + $GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l; |
|
| 126 | 126 | $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
| 127 | 127 | surcharger_langue($fichiers_lang); |
| 128 | 128 | if ($l !== $lang) { |
| 129 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 129 | + $GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l]; |
|
| 130 | 130 | } |
| 131 | - $GLOBALS['lang_' . $var] = $l; |
|
| 131 | + $GLOBALS['lang_'.$var] = $l; |
|
| 132 | 132 | #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
| 133 | 133 | break; |
| 134 | 134 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | function lire_fichier_langue(string $fichier): array { |
| 148 | 148 | $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
| 149 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 149 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire'; |
|
| 150 | 150 | $GLOBALS['idx_lang'] = $idx_lang_tmp; |
| 151 | 151 | $idx_lang = include $fichier; |
| 152 | 152 | $GLOBALS['idx_lang'] = $idx_lang_before; |
@@ -257,27 +257,27 @@ discard block |
||
| 257 | 257 | } else { |
| 258 | 258 | $modules = ['spip', 'ecrire']; |
| 259 | 259 | $code = $ori; |
| 260 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 260 | + $ori_complet = implode('|', $modules).':'.$ori; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | $desc = new Description(); |
| 264 | 264 | |
| 265 | 265 | // parcourir tous les modules jusqu'a ce qu'on trouve |
| 266 | 266 | foreach ($modules as $module) { |
| 267 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 267 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 268 | 268 | |
| 269 | 269 | if (empty($GLOBALS[$var])) { |
| 270 | 270 | charger_langue($lang, $module); |
| 271 | 271 | // surcharges persos -- on cherche |
| 272 | 272 | // (lang/)local_xx.php et/ou (lang/)local.php ... |
| 273 | - if (!isset($local['local_' . $lang])) { |
|
| 273 | + if (!isset($local['local_'.$lang])) { |
|
| 274 | 274 | // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
| 275 | 275 | $GLOBALS['idx_lang'] = $var; |
| 276 | 276 | // ... (lang/)local_xx.php |
| 277 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 277 | + $local['local_'.$lang] = chercher_module_lang('local', $lang); |
|
| 278 | 278 | } |
| 279 | - if ($local['local_' . $lang]) { |
|
| 280 | - surcharger_langue($local['local_' . $lang]); |
|
| 279 | + if ($local['local_'.$lang]) { |
|
| 280 | + surcharger_langue($local['local_'.$lang]); |
|
| 281 | 281 | } |
| 282 | 282 | // ... puis (lang/)local.php |
| 283 | 283 | if (!isset($local['local'])) { |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | if (isset($GLOBALS[$var][$code])) { |
| 292 | 292 | $desc->code = $code; |
| 293 | 293 | $desc->module = $module; |
| 294 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 294 | + $desc->langue = $GLOBALS['lang_'.$var] ?? $lang; |
|
| 295 | 295 | $desc->texte = $GLOBALS[$var][$code]; |
| 296 | 296 | break; |
| 297 | 297 | } |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | if (!$desc->mode and $desc->texte) { |
| 350 | 350 | // ne pas modifier 2 fois l'affichage |
| 351 | 351 | $desc->mode = 'traduction'; |
| 352 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 352 | + $classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | 353 | $desc->texte = '<span ' |
| 354 | - . 'lang=' . $desc->langue |
|
| 355 | - . ' class=' . $classe |
|
| 356 | - . ' data-module=' . $desc->module |
|
| 357 | - . ' data-code=' . $desc->code |
|
| 358 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 354 | + . 'lang='.$desc->langue |
|
| 355 | + . ' class='.$classe |
|
| 356 | + . ' data-module='.$desc->module |
|
| 357 | + . ' data-code='.$desc->code |
|
| 358 | + . ' title='.$modules.'('.$desc->langue.')>' |
|
| 359 | 359 | . $desc->texte |
| 360 | 360 | . '</span>'; |
| 361 | 361 | $desc->texte = str_replace( |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | * Initialisation |
| 33 | 33 | */ |
| 34 | 34 | function init_charset(): void { |
| 35 | - // Initialisation |
|
| 36 | - $GLOBALS['CHARSET'] = []; |
|
| 37 | - |
|
| 38 | - // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 39 | - // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 40 | - // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 41 | - if ( |
|
| 42 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 43 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 44 | - ) { |
|
| 45 | - include_spip('inc/meta'); |
|
| 46 | - ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 47 | - } |
|
| 35 | + // Initialisation |
|
| 36 | + $GLOBALS['CHARSET'] = []; |
|
| 37 | + |
|
| 38 | + // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u |
|
| 39 | + // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
|
| 40 | + // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
|
| 41 | + if ( |
|
| 42 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 43 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 44 | + ) { |
|
| 45 | + include_spip('inc/meta'); |
|
| 46 | + ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : ''); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // TODO: code d’exécution en dehors du fichier. |
@@ -65,39 +65,39 @@ discard block |
||
| 65 | 65 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 66 | 66 | **/ |
| 67 | 67 | function load_charset($charset = 'AUTO') { |
| 68 | - if ($charset == 'AUTO') { |
|
| 69 | - $charset = $GLOBALS['meta']['charset']; |
|
| 70 | - } |
|
| 71 | - $charset = trim(strtolower($charset)); |
|
| 72 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 73 | - return $charset; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($charset == 'utf-8') { |
|
| 77 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 78 | - |
|
| 79 | - return $charset; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Quelques synonymes |
|
| 83 | - if ($charset === '') { |
|
| 84 | - $charset = 'iso-8859-1'; |
|
| 85 | - } elseif ($charset === 'windows-1250') { |
|
| 86 | - $charset = 'cp1250'; |
|
| 87 | - } elseif ($charset === 'windows-1251') { |
|
| 88 | - $charset = 'cp1251'; |
|
| 89 | - } elseif ($charset === 'windows-1256') { |
|
| 90 | - $charset = 'cp1256'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 94 | - return $charset; |
|
| 95 | - } else { |
|
| 96 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 97 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 68 | + if ($charset == 'AUTO') { |
|
| 69 | + $charset = $GLOBALS['meta']['charset']; |
|
| 70 | + } |
|
| 71 | + $charset = trim(strtolower($charset)); |
|
| 72 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 73 | + return $charset; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($charset == 'utf-8') { |
|
| 77 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 78 | + |
|
| 79 | + return $charset; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Quelques synonymes |
|
| 83 | + if ($charset === '') { |
|
| 84 | + $charset = 'iso-8859-1'; |
|
| 85 | + } elseif ($charset === 'windows-1250') { |
|
| 86 | + $charset = 'cp1250'; |
|
| 87 | + } elseif ($charset === 'windows-1251') { |
|
| 88 | + $charset = 'cp1251'; |
|
| 89 | + } elseif ($charset === 'windows-1256') { |
|
| 90 | + $charset = 'cp1256'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 94 | + return $charset; |
|
| 95 | + } else { |
|
| 96 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 97 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * true si notre charset est utilisable par mb_strsing |
| 111 | 111 | **/ |
| 112 | 112 | function init_mb_string(): bool { |
| 113 | - static $mb; |
|
| 114 | - |
|
| 115 | - // verifier que le charset interne est connu de mb_string |
|
| 116 | - if (!$mb) { |
|
| 117 | - if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 118 | - mb_internal_encoding('utf-8'); |
|
| 119 | - $mb = 1; |
|
| 120 | - } else { |
|
| 121 | - $mb = -1; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return ($mb === 1); |
|
| 113 | + static $mb; |
|
| 114 | + |
|
| 115 | + // verifier que le charset interne est connu de mb_string |
|
| 116 | + if (!$mb) { |
|
| 117 | + if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) { |
|
| 118 | + mb_internal_encoding('utf-8'); |
|
| 119 | + $mb = 1; |
|
| 120 | + } else { |
|
| 121 | + $mb = -1; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return ($mb === 1); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -137,21 +137,21 @@ discard block |
||
| 137 | 137 | * true si iconv fonctionne correctement |
| 138 | 138 | **/ |
| 139 | 139 | function test_iconv(): bool { |
| 140 | - static $iconv_ok; |
|
| 141 | - |
|
| 142 | - if (!$iconv_ok) { |
|
| 143 | - if (!function_exists('iconv')) { |
|
| 144 | - $iconv_ok = -1; |
|
| 145 | - } else { |
|
| 146 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') { |
|
| 147 | - $iconv_ok = 1; |
|
| 148 | - } else { |
|
| 149 | - $iconv_ok = -1; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return ($iconv_ok === 1); |
|
| 140 | + static $iconv_ok; |
|
| 141 | + |
|
| 142 | + if (!$iconv_ok) { |
|
| 143 | + if (!function_exists('iconv')) { |
|
| 144 | + $iconv_ok = -1; |
|
| 145 | + } else { |
|
| 146 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') { |
|
| 147 | + $iconv_ok = 1; |
|
| 148 | + } else { |
|
| 149 | + $iconv_ok = -1; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return ($iconv_ok === 1); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -171,75 +171,75 @@ discard block |
||
| 171 | 171 | * texte corrigé |
| 172 | 172 | **/ |
| 173 | 173 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 174 | - static $trans; |
|
| 175 | - |
|
| 176 | - if (is_array($texte)) { |
|
| 177 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if ($charset == 'AUTO') { |
|
| 181 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 182 | - } |
|
| 183 | - if ($charset == 'utf-8') { |
|
| 184 | - $p = chr(194); |
|
| 185 | - if (strpos($texte, $p) == false) { |
|
| 186 | - return $texte; |
|
| 187 | - } |
|
| 188 | - } else { |
|
| 189 | - if ($charset == 'iso-8859-1') { |
|
| 190 | - $p = ''; |
|
| 191 | - } else { |
|
| 192 | - return $texte; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 197 | - $trans[$charset][$charset_cible] = [ |
|
| 198 | - $p . chr(128) => '€', |
|
| 199 | - $p . chr(129) => ' ', # pas affecte |
|
| 200 | - $p . chr(130) => '‚', |
|
| 201 | - $p . chr(131) => 'ƒ', |
|
| 202 | - $p . chr(132) => '„', |
|
| 203 | - $p . chr(133) => '…', |
|
| 204 | - $p . chr(134) => '†', |
|
| 205 | - $p . chr(135) => '‡', |
|
| 206 | - $p . chr(136) => 'ˆ', |
|
| 207 | - $p . chr(137) => '‰', |
|
| 208 | - $p . chr(138) => 'Š', |
|
| 209 | - $p . chr(139) => '‹', |
|
| 210 | - $p . chr(140) => 'Œ', |
|
| 211 | - $p . chr(141) => ' ', # pas affecte |
|
| 212 | - $p . chr(142) => 'Ž', |
|
| 213 | - $p . chr(143) => ' ', # pas affecte |
|
| 214 | - $p . chr(144) => ' ', # pas affecte |
|
| 215 | - $p . chr(145) => '‘', |
|
| 216 | - $p . chr(146) => '’', |
|
| 217 | - $p . chr(147) => '“', |
|
| 218 | - $p . chr(148) => '”', |
|
| 219 | - $p . chr(149) => '•', |
|
| 220 | - $p . chr(150) => '–', |
|
| 221 | - $p . chr(151) => '—', |
|
| 222 | - $p . chr(152) => '˜', |
|
| 223 | - $p . chr(153) => '™', |
|
| 224 | - $p . chr(154) => 'š', |
|
| 225 | - $p . chr(155) => '›', |
|
| 226 | - $p . chr(156) => 'œ', |
|
| 227 | - $p . chr(157) => ' ', # pas affecte |
|
| 228 | - $p . chr(158) => 'ž', |
|
| 229 | - $p . chr(159) => 'Ÿ', |
|
| 230 | - ]; |
|
| 231 | - if ($charset_cible != 'unicode') { |
|
| 232 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 233 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return @str_replace( |
|
| 239 | - array_keys($trans[$charset][$charset_cible]), |
|
| 240 | - array_values($trans[$charset][$charset_cible]), |
|
| 241 | - $texte |
|
| 242 | - ); |
|
| 174 | + static $trans; |
|
| 175 | + |
|
| 176 | + if (is_array($texte)) { |
|
| 177 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if ($charset == 'AUTO') { |
|
| 181 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 182 | + } |
|
| 183 | + if ($charset == 'utf-8') { |
|
| 184 | + $p = chr(194); |
|
| 185 | + if (strpos($texte, $p) == false) { |
|
| 186 | + return $texte; |
|
| 187 | + } |
|
| 188 | + } else { |
|
| 189 | + if ($charset == 'iso-8859-1') { |
|
| 190 | + $p = ''; |
|
| 191 | + } else { |
|
| 192 | + return $texte; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 197 | + $trans[$charset][$charset_cible] = [ |
|
| 198 | + $p . chr(128) => '€', |
|
| 199 | + $p . chr(129) => ' ', # pas affecte |
|
| 200 | + $p . chr(130) => '‚', |
|
| 201 | + $p . chr(131) => 'ƒ', |
|
| 202 | + $p . chr(132) => '„', |
|
| 203 | + $p . chr(133) => '…', |
|
| 204 | + $p . chr(134) => '†', |
|
| 205 | + $p . chr(135) => '‡', |
|
| 206 | + $p . chr(136) => 'ˆ', |
|
| 207 | + $p . chr(137) => '‰', |
|
| 208 | + $p . chr(138) => 'Š', |
|
| 209 | + $p . chr(139) => '‹', |
|
| 210 | + $p . chr(140) => 'Œ', |
|
| 211 | + $p . chr(141) => ' ', # pas affecte |
|
| 212 | + $p . chr(142) => 'Ž', |
|
| 213 | + $p . chr(143) => ' ', # pas affecte |
|
| 214 | + $p . chr(144) => ' ', # pas affecte |
|
| 215 | + $p . chr(145) => '‘', |
|
| 216 | + $p . chr(146) => '’', |
|
| 217 | + $p . chr(147) => '“', |
|
| 218 | + $p . chr(148) => '”', |
|
| 219 | + $p . chr(149) => '•', |
|
| 220 | + $p . chr(150) => '–', |
|
| 221 | + $p . chr(151) => '—', |
|
| 222 | + $p . chr(152) => '˜', |
|
| 223 | + $p . chr(153) => '™', |
|
| 224 | + $p . chr(154) => 'š', |
|
| 225 | + $p . chr(155) => '›', |
|
| 226 | + $p . chr(156) => 'œ', |
|
| 227 | + $p . chr(157) => ' ', # pas affecte |
|
| 228 | + $p . chr(158) => 'ž', |
|
| 229 | + $p . chr(159) => 'Ÿ', |
|
| 230 | + ]; |
|
| 231 | + if ($charset_cible != 'unicode') { |
|
| 232 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 233 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return @str_replace( |
|
| 239 | + array_keys($trans[$charset][$charset_cible]), |
|
| 240 | + array_values($trans[$charset][$charset_cible]), |
|
| 241 | + $texte |
|
| 242 | + ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -256,26 +256,26 @@ discard block |
||
| 256 | 256 | * texte converti |
| 257 | 257 | **/ |
| 258 | 258 | function html2unicode($texte, $secure = false) { |
| 259 | - if (strpos($texte, '&') === false) { |
|
| 260 | - return $texte; |
|
| 261 | - } |
|
| 262 | - static $trans = []; |
|
| 263 | - if (!$trans) { |
|
| 264 | - load_charset('html'); |
|
| 265 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | - $trans["&$key;"] = $val; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - if ($secure) { |
|
| 271 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 272 | - } else { |
|
| 273 | - return str_replace( |
|
| 274 | - ['&', '"', '<', '>'], |
|
| 275 | - ['&', '"', '<', '>'], |
|
| 276 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 277 | - ); |
|
| 278 | - } |
|
| 259 | + if (strpos($texte, '&') === false) { |
|
| 260 | + return $texte; |
|
| 261 | + } |
|
| 262 | + static $trans = []; |
|
| 263 | + if (!$trans) { |
|
| 264 | + load_charset('html'); |
|
| 265 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 266 | + $trans["&$key;"] = $val; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + if ($secure) { |
|
| 271 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 272 | + } else { |
|
| 273 | + return str_replace( |
|
| 274 | + ['&', '"', '<', '>'], |
|
| 275 | + ['&', '"', '<', '>'], |
|
| 276 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,16 +290,16 @@ discard block |
||
| 290 | 290 | * texte converti |
| 291 | 291 | **/ |
| 292 | 292 | function mathml2unicode($texte) { |
| 293 | - static $trans; |
|
| 294 | - if (!$trans) { |
|
| 295 | - load_charset('mathml'); |
|
| 293 | + static $trans; |
|
| 294 | + if (!$trans) { |
|
| 295 | + load_charset('mathml'); |
|
| 296 | 296 | |
| 297 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | - $trans["&$key;"] = $val; |
|
| 299 | - } |
|
| 300 | - } |
|
| 297 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 298 | + $trans["&$key;"] = $val; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 302 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -321,75 +321,75 @@ discard block |
||
| 321 | 321 | * texte converti en unicode |
| 322 | 322 | **/ |
| 323 | 323 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 324 | - static $trans; |
|
| 325 | - |
|
| 326 | - if ($charset === 'AUTO') { |
|
| 327 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if ($charset === '') { |
|
| 331 | - $charset = 'iso-8859-1'; |
|
| 332 | - } |
|
| 333 | - $charset = strtolower($charset); |
|
| 334 | - |
|
| 335 | - switch ($charset) { |
|
| 336 | - case 'utf-8': |
|
| 337 | - case 'utf8': |
|
| 338 | - return utf_8_to_unicode($texte); |
|
| 339 | - |
|
| 340 | - case 'iso-8859-1': |
|
| 341 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 342 | - // pas de break; ici, on suit sur default: |
|
| 343 | - |
|
| 344 | - default: |
|
| 345 | - // mbstring presente ? |
|
| 346 | - if (init_mb_string()) { |
|
| 347 | - $order = mb_detect_order(); |
|
| 348 | - try { |
|
| 349 | - # mb_string connait-il $charset? |
|
| 350 | - if ($order and mb_detect_order($charset)) { |
|
| 351 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 352 | - if ($s && $s != $texte) { |
|
| 353 | - return utf_8_to_unicode($s); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } catch (\Error $e) { |
|
| 357 | - // Le charset n'existe probablement pas |
|
| 358 | - } finally { |
|
| 359 | - mb_detect_order($order); # remettre comme precedemment |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 364 | - if (!isset($trans[$charset])) { |
|
| 365 | - if ( |
|
| 366 | - $cset = load_charset($charset) |
|
| 367 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 368 | - ) { |
|
| 369 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 375 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 379 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 380 | - // surtout en utf-8, gere ci-dessus) |
|
| 381 | - if (test_iconv()) { |
|
| 382 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 383 | - if ($s) { |
|
| 384 | - return utf_32_to_unicode($s); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // Au pire ne rien faire |
|
| 389 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 390 | - |
|
| 391 | - return $texte; |
|
| 392 | - } |
|
| 324 | + static $trans; |
|
| 325 | + |
|
| 326 | + if ($charset === 'AUTO') { |
|
| 327 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if ($charset === '') { |
|
| 331 | + $charset = 'iso-8859-1'; |
|
| 332 | + } |
|
| 333 | + $charset = strtolower($charset); |
|
| 334 | + |
|
| 335 | + switch ($charset) { |
|
| 336 | + case 'utf-8': |
|
| 337 | + case 'utf8': |
|
| 338 | + return utf_8_to_unicode($texte); |
|
| 339 | + |
|
| 340 | + case 'iso-8859-1': |
|
| 341 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 342 | + // pas de break; ici, on suit sur default: |
|
| 343 | + |
|
| 344 | + default: |
|
| 345 | + // mbstring presente ? |
|
| 346 | + if (init_mb_string()) { |
|
| 347 | + $order = mb_detect_order(); |
|
| 348 | + try { |
|
| 349 | + # mb_string connait-il $charset? |
|
| 350 | + if ($order and mb_detect_order($charset)) { |
|
| 351 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 352 | + if ($s && $s != $texte) { |
|
| 353 | + return utf_8_to_unicode($s); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } catch (\Error $e) { |
|
| 357 | + // Le charset n'existe probablement pas |
|
| 358 | + } finally { |
|
| 359 | + mb_detect_order($order); # remettre comme precedemment |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 364 | + if (!isset($trans[$charset])) { |
|
| 365 | + if ( |
|
| 366 | + $cset = load_charset($charset) |
|
| 367 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 368 | + ) { |
|
| 369 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 370 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 375 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 379 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 380 | + // surtout en utf-8, gere ci-dessus) |
|
| 381 | + if (test_iconv()) { |
|
| 382 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 383 | + if ($s) { |
|
| 384 | + return utf_32_to_unicode($s); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // Au pire ne rien faire |
|
| 389 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 390 | + |
|
| 391 | + return $texte; |
|
| 392 | + } |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -408,43 +408,43 @@ discard block |
||
| 408 | 408 | * texte transformé dans le charset souhaité |
| 409 | 409 | **/ |
| 410 | 410 | function unicode2charset($texte, $charset = 'AUTO') { |
| 411 | - static $CHARSET_REVERSE = []; |
|
| 412 | - static $trans = []; |
|
| 413 | - |
|
| 414 | - if ($charset == 'AUTO') { |
|
| 415 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - switch ($charset) { |
|
| 419 | - case 'utf-8': |
|
| 420 | - return unicode_to_utf_8($texte); |
|
| 421 | - |
|
| 422 | - default: |
|
| 423 | - $charset = load_charset($charset); |
|
| 424 | - |
|
| 425 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 426 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - if (!isset($trans[$charset])) { |
|
| 430 | - $trans[$charset] = []; |
|
| 431 | - $t = &$trans[$charset]; |
|
| 432 | - for ($e = 128; $e < 255; $e++) { |
|
| 433 | - $h = dechex($e); |
|
| 434 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 435 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 436 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 437 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 438 | - } else { |
|
| 439 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 440 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | - |
|
| 446 | - return $texte; |
|
| 447 | - } |
|
| 411 | + static $CHARSET_REVERSE = []; |
|
| 412 | + static $trans = []; |
|
| 413 | + |
|
| 414 | + if ($charset == 'AUTO') { |
|
| 415 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + switch ($charset) { |
|
| 419 | + case 'utf-8': |
|
| 420 | + return unicode_to_utf_8($texte); |
|
| 421 | + |
|
| 422 | + default: |
|
| 423 | + $charset = load_charset($charset); |
|
| 424 | + |
|
| 425 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 426 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + if (!isset($trans[$charset])) { |
|
| 430 | + $trans[$charset] = []; |
|
| 431 | + $t = &$trans[$charset]; |
|
| 432 | + for ($e = 128; $e < 255; $e++) { |
|
| 433 | + $h = dechex($e); |
|
| 434 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 435 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 436 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 437 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 438 | + } else { |
|
| 439 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 440 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 445 | + |
|
| 446 | + return $texte; |
|
| 447 | + } |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -462,40 +462,40 @@ discard block |
||
| 462 | 462 | * texte transformé dans le charset site |
| 463 | 463 | **/ |
| 464 | 464 | function importer_charset($texte, $charset = 'AUTO') { |
| 465 | - $s = null; |
|
| 466 | - static $trans = []; |
|
| 467 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 468 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 469 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 470 | - if (init_mb_string()) { |
|
| 471 | - if ( |
|
| 472 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 473 | - and mb_detect_order($charset) |
|
| 474 | - ) { |
|
| 475 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 476 | - } |
|
| 477 | - mb_detect_order($order); # remettre comme precedemment |
|
| 478 | - return $s; |
|
| 479 | - } |
|
| 480 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 481 | - if (!isset($trans[$charset])) { |
|
| 482 | - if ( |
|
| 483 | - $cset = load_charset($charset) |
|
| 484 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 485 | - ) { |
|
| 486 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 487 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 492 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - return $texte; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 465 | + $s = null; |
|
| 466 | + static $trans = []; |
|
| 467 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 468 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 469 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 470 | + if (init_mb_string()) { |
|
| 471 | + if ( |
|
| 472 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 473 | + and mb_detect_order($charset) |
|
| 474 | + ) { |
|
| 475 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 476 | + } |
|
| 477 | + mb_detect_order($order); # remettre comme precedemment |
|
| 478 | + return $s; |
|
| 479 | + } |
|
| 480 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 481 | + if (!isset($trans[$charset])) { |
|
| 482 | + if ( |
|
| 483 | + $cset = load_charset($charset) |
|
| 484 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 485 | + ) { |
|
| 486 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 487 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 492 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + return $texte; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
@@ -511,92 +511,92 @@ discard block |
||
| 511 | 511 | **/ |
| 512 | 512 | function utf_8_to_unicode($source) { |
| 513 | 513 | |
| 514 | - // mb_string : methode rapide |
|
| 515 | - if (init_mb_string()) { |
|
| 516 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 517 | - |
|
| 518 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Sinon methode pas a pas |
|
| 522 | - static $decrement; |
|
| 523 | - static $shift; |
|
| 524 | - |
|
| 525 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 526 | - if (!is_array($decrement)) { |
|
| 527 | - // array used to figure what number to decrement from character order value |
|
| 528 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 529 | - $decrement[4] = 240; |
|
| 530 | - $decrement[3] = 224; |
|
| 531 | - $decrement[2] = 192; |
|
| 532 | - $decrement[1] = 0; |
|
| 533 | - // the number of bits to shift each charNum by |
|
| 534 | - $shift[1][0] = 0; |
|
| 535 | - $shift[2][0] = 6; |
|
| 536 | - $shift[2][1] = 0; |
|
| 537 | - $shift[3][0] = 12; |
|
| 538 | - $shift[3][1] = 6; |
|
| 539 | - $shift[3][2] = 0; |
|
| 540 | - $shift[4][0] = 18; |
|
| 541 | - $shift[4][1] = 12; |
|
| 542 | - $shift[4][2] = 6; |
|
| 543 | - $shift[4][3] = 0; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - $pos = 0; |
|
| 547 | - $len = strlen($source); |
|
| 548 | - $encodedString = ''; |
|
| 549 | - while ($pos < $len) { |
|
| 550 | - $char = ''; |
|
| 551 | - $ischar = false; |
|
| 552 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 553 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 554 | - // 4 chars representing one unicode character |
|
| 555 | - $thisLetter = substr($source, $pos, 4); |
|
| 556 | - $pos += 4; |
|
| 557 | - } else { |
|
| 558 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 559 | - // 3 chars representing one unicode character |
|
| 560 | - $thisLetter = substr($source, $pos, 3); |
|
| 561 | - $pos += 3; |
|
| 562 | - } else { |
|
| 563 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 564 | - // 2 chars representing one unicode character |
|
| 565 | - $thisLetter = substr($source, $pos, 2); |
|
| 566 | - $pos += 2; |
|
| 567 | - } else { |
|
| 568 | - // 1 char (lower ascii) |
|
| 569 | - $thisLetter = substr($source, $pos, 1); |
|
| 570 | - $pos += 1; |
|
| 571 | - $char = $thisLetter; |
|
| 572 | - $ischar = true; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - if ($ischar) { |
|
| 578 | - $encodedString .= $char; |
|
| 579 | - } else { // process the string representing the letter to a unicode entity |
|
| 580 | - $thisLen = strlen($thisLetter); |
|
| 581 | - $thisPos = 0; |
|
| 582 | - $decimalCode = 0; |
|
| 583 | - while ($thisPos < $thisLen) { |
|
| 584 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 585 | - if ($thisPos == 0) { |
|
| 586 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 587 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | - } else { |
|
| 589 | - $charNum = intval($thisCharOrd - 128); |
|
| 590 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 591 | - } |
|
| 592 | - $thisPos++; |
|
| 593 | - } |
|
| 594 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 595 | - $encodedString .= $encodedLetter; |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - return $encodedString; |
|
| 514 | + // mb_string : methode rapide |
|
| 515 | + if (init_mb_string()) { |
|
| 516 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 517 | + |
|
| 518 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Sinon methode pas a pas |
|
| 522 | + static $decrement; |
|
| 523 | + static $shift; |
|
| 524 | + |
|
| 525 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 526 | + if (!is_array($decrement)) { |
|
| 527 | + // array used to figure what number to decrement from character order value |
|
| 528 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 529 | + $decrement[4] = 240; |
|
| 530 | + $decrement[3] = 224; |
|
| 531 | + $decrement[2] = 192; |
|
| 532 | + $decrement[1] = 0; |
|
| 533 | + // the number of bits to shift each charNum by |
|
| 534 | + $shift[1][0] = 0; |
|
| 535 | + $shift[2][0] = 6; |
|
| 536 | + $shift[2][1] = 0; |
|
| 537 | + $shift[3][0] = 12; |
|
| 538 | + $shift[3][1] = 6; |
|
| 539 | + $shift[3][2] = 0; |
|
| 540 | + $shift[4][0] = 18; |
|
| 541 | + $shift[4][1] = 12; |
|
| 542 | + $shift[4][2] = 6; |
|
| 543 | + $shift[4][3] = 0; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + $pos = 0; |
|
| 547 | + $len = strlen($source); |
|
| 548 | + $encodedString = ''; |
|
| 549 | + while ($pos < $len) { |
|
| 550 | + $char = ''; |
|
| 551 | + $ischar = false; |
|
| 552 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 553 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 554 | + // 4 chars representing one unicode character |
|
| 555 | + $thisLetter = substr($source, $pos, 4); |
|
| 556 | + $pos += 4; |
|
| 557 | + } else { |
|
| 558 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 559 | + // 3 chars representing one unicode character |
|
| 560 | + $thisLetter = substr($source, $pos, 3); |
|
| 561 | + $pos += 3; |
|
| 562 | + } else { |
|
| 563 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 564 | + // 2 chars representing one unicode character |
|
| 565 | + $thisLetter = substr($source, $pos, 2); |
|
| 566 | + $pos += 2; |
|
| 567 | + } else { |
|
| 568 | + // 1 char (lower ascii) |
|
| 569 | + $thisLetter = substr($source, $pos, 1); |
|
| 570 | + $pos += 1; |
|
| 571 | + $char = $thisLetter; |
|
| 572 | + $ischar = true; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + if ($ischar) { |
|
| 578 | + $encodedString .= $char; |
|
| 579 | + } else { // process the string representing the letter to a unicode entity |
|
| 580 | + $thisLen = strlen($thisLetter); |
|
| 581 | + $thisPos = 0; |
|
| 582 | + $decimalCode = 0; |
|
| 583 | + while ($thisPos < $thisLen) { |
|
| 584 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 585 | + if ($thisPos == 0) { |
|
| 586 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 587 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 588 | + } else { |
|
| 589 | + $charNum = intval($thisCharOrd - 128); |
|
| 590 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 591 | + } |
|
| 592 | + $thisPos++; |
|
| 593 | + } |
|
| 594 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 595 | + $encodedString .= $encodedLetter; |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + return $encodedString; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -615,32 +615,32 @@ discard block |
||
| 615 | 615 | **/ |
| 616 | 616 | function utf_32_to_unicode($source) { |
| 617 | 617 | |
| 618 | - // mb_string : methode rapide |
|
| 619 | - if (init_mb_string()) { |
|
| 620 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 621 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 622 | - |
|
| 623 | - return str_replace(chr(0), '', $source); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // Sinon methode lente |
|
| 627 | - $texte = ''; |
|
| 628 | - while ($source) { |
|
| 629 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 630 | - $source = substr($source, 1024); |
|
| 631 | - foreach ($words as $word) { |
|
| 632 | - if ($word < 128) { |
|
| 633 | - $texte .= chr($word); |
|
| 634 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 635 | - else { |
|
| 636 | - if ($word != 65279) { |
|
| 637 | - $texte .= '&#' . $word . ';'; |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - return $texte; |
|
| 618 | + // mb_string : methode rapide |
|
| 619 | + if (init_mb_string()) { |
|
| 620 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 621 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 622 | + |
|
| 623 | + return str_replace(chr(0), '', $source); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // Sinon methode lente |
|
| 627 | + $texte = ''; |
|
| 628 | + while ($source) { |
|
| 629 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 630 | + $source = substr($source, 1024); |
|
| 631 | + foreach ($words as $word) { |
|
| 632 | + if ($word < 128) { |
|
| 633 | + $texte .= chr($word); |
|
| 634 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 635 | + else { |
|
| 636 | + if ($word != 65279) { |
|
| 637 | + $texte .= '&#' . $word . ';'; |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + return $texte; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | |
@@ -657,21 +657,21 @@ discard block |
||
| 657 | 657 | * Caractère utf8 si trouvé, '' sinon |
| 658 | 658 | **/ |
| 659 | 659 | function caractere_utf_8($num) { |
| 660 | - $num = intval($num); |
|
| 661 | - if ($num < 128) { |
|
| 662 | - return chr($num); |
|
| 663 | - } |
|
| 664 | - if ($num < 2048) { |
|
| 665 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 666 | - } |
|
| 667 | - if ($num < 65536) { |
|
| 668 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | - } |
|
| 670 | - if ($num < 1_114_112) { |
|
| 671 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return ''; |
|
| 660 | + $num = intval($num); |
|
| 661 | + if ($num < 128) { |
|
| 662 | + return chr($num); |
|
| 663 | + } |
|
| 664 | + if ($num < 2048) { |
|
| 665 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 666 | + } |
|
| 667 | + if ($num < 65536) { |
|
| 668 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 669 | + } |
|
| 670 | + if ($num < 1_114_112) { |
|
| 671 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return ''; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
@@ -684,42 +684,42 @@ discard block |
||
| 684 | 684 | **/ |
| 685 | 685 | function unicode_to_utf_8($texte) { |
| 686 | 686 | |
| 687 | - // 1. Entites € et suivantes |
|
| 688 | - $vu = []; |
|
| 689 | - if ( |
|
| 690 | - preg_match_all( |
|
| 691 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 692 | - $texte, |
|
| 693 | - $regs, |
|
| 694 | - PREG_SET_ORDER |
|
| 695 | - ) |
|
| 696 | - ) { |
|
| 697 | - foreach ($regs as $reg) { |
|
| 698 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 699 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 704 | - |
|
| 705 | - // 2. Entites > ÿ |
|
| 706 | - //$vu = array(); |
|
| 707 | - if ( |
|
| 708 | - preg_match_all( |
|
| 709 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 710 | - $texte, |
|
| 711 | - $regs, |
|
| 712 | - PREG_SET_ORDER |
|
| 713 | - ) |
|
| 714 | - ) { |
|
| 715 | - foreach ($regs as $reg) { |
|
| 716 | - if (!isset($vu[$reg[0]])) { |
|
| 717 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 687 | + // 1. Entites € et suivantes |
|
| 688 | + $vu = []; |
|
| 689 | + if ( |
|
| 690 | + preg_match_all( |
|
| 691 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 692 | + $texte, |
|
| 693 | + $regs, |
|
| 694 | + PREG_SET_ORDER |
|
| 695 | + ) |
|
| 696 | + ) { |
|
| 697 | + foreach ($regs as $reg) { |
|
| 698 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 699 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 704 | + |
|
| 705 | + // 2. Entites > ÿ |
|
| 706 | + //$vu = array(); |
|
| 707 | + if ( |
|
| 708 | + preg_match_all( |
|
| 709 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 710 | + $texte, |
|
| 711 | + $regs, |
|
| 712 | + PREG_SET_ORDER |
|
| 713 | + ) |
|
| 714 | + ) { |
|
| 715 | + foreach ($regs as $reg) { |
|
| 716 | + if (!isset($vu[$reg[0]])) { |
|
| 717 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -731,15 +731,15 @@ discard block |
||
| 731 | 731 | * texte converti |
| 732 | 732 | **/ |
| 733 | 733 | function unicode_to_javascript($texte) { |
| 734 | - $vu = []; |
|
| 735 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 736 | - $num = $regs[1]; |
|
| 737 | - $vu[$num] = true; |
|
| 738 | - $s = '\u' . sprintf('%04x', $num); |
|
| 739 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $texte; |
|
| 734 | + $vu = []; |
|
| 735 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 736 | + $num = $regs[1]; |
|
| 737 | + $vu[$num] = true; |
|
| 738 | + $s = '\u' . sprintf('%04x', $num); |
|
| 739 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $texte; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | /** |
@@ -751,11 +751,11 @@ discard block |
||
| 751 | 751 | * texte converti |
| 752 | 752 | **/ |
| 753 | 753 | function javascript_to_unicode($texte) { |
| 754 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 755 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 756 | - } |
|
| 754 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 755 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 756 | + } |
|
| 757 | 757 | |
| 758 | - return $texte; |
|
| 758 | + return $texte; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -767,11 +767,11 @@ discard block |
||
| 767 | 767 | * texte converti |
| 768 | 768 | **/ |
| 769 | 769 | function javascript_to_binary($texte) { |
| 770 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 771 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 772 | - } |
|
| 770 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 771 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 772 | + } |
|
| 773 | 773 | |
| 774 | - return $texte; |
|
| 774 | + return $texte; |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | |
@@ -789,26 +789,26 @@ discard block |
||
| 789 | 789 | * @return string |
| 790 | 790 | */ |
| 791 | 791 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string { |
| 792 | - static $trans = []; |
|
| 793 | - if ($charset == 'AUTO') { |
|
| 794 | - $charset = $GLOBALS['meta']['charset']; |
|
| 795 | - } |
|
| 796 | - if (!strlen($texte)) { |
|
| 797 | - return $texte; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - $table_translit = 'translit' . $complexe; |
|
| 801 | - |
|
| 802 | - // 2. Translitterer grace a la table predefinie |
|
| 803 | - if (!isset($trans[$complexe])) { |
|
| 804 | - $trans[$complexe] = []; |
|
| 805 | - load_charset($table_translit); |
|
| 806 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 807 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 792 | + static $trans = []; |
|
| 793 | + if ($charset == 'AUTO') { |
|
| 794 | + $charset = $GLOBALS['meta']['charset']; |
|
| 795 | + } |
|
| 796 | + if (!strlen($texte)) { |
|
| 797 | + return $texte; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + $table_translit = 'translit' . $complexe; |
|
| 801 | + |
|
| 802 | + // 2. Translitterer grace a la table predefinie |
|
| 803 | + if (!isset($trans[$complexe])) { |
|
| 804 | + $trans[$complexe] = []; |
|
| 805 | + load_charset($table_translit); |
|
| 806 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 807 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -831,14 +831,14 @@ discard block |
||
| 831 | 831 | * @return string |
| 832 | 832 | */ |
| 833 | 833 | function translitteration($texte, $charset = 'AUTO', $complexe = ''): string { |
| 834 | - // 0. Supprimer les caracteres illegaux |
|
| 835 | - include_spip('inc/filtres'); |
|
| 836 | - $texte = corriger_caracteres($texte); |
|
| 834 | + // 0. Supprimer les caracteres illegaux |
|
| 835 | + include_spip('inc/filtres'); |
|
| 836 | + $texte = corriger_caracteres($texte); |
|
| 837 | 837 | |
| 838 | - // 1. Passer le charset et les é en utf-8 |
|
| 839 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 838 | + // 1. Passer le charset et les é en utf-8 |
|
| 839 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 840 | 840 | |
| 841 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 841 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | /** |
@@ -853,17 +853,17 @@ discard block |
||
| 853 | 853 | * @return string |
| 854 | 854 | */ |
| 855 | 855 | function translitteration_complexe($texte, $chiffres = false): string { |
| 856 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 856 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 857 | 857 | |
| 858 | - if ($chiffres) { |
|
| 859 | - $texte = preg_replace_callback( |
|
| 860 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 861 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 862 | - $texte |
|
| 863 | - ); |
|
| 864 | - } |
|
| 858 | + if ($chiffres) { |
|
| 859 | + $texte = preg_replace_callback( |
|
| 860 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 861 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 862 | + $texte |
|
| 863 | + ); |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - return $texte; |
|
| 866 | + return $texte; |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | /** |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | * @return string |
| 876 | 876 | */ |
| 877 | 877 | function translitteration_chiffree($car): string { |
| 878 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 878 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * true s'il a un BOM |
| 889 | 889 | **/ |
| 890 | 890 | function bom_utf8($texte): bool { |
| 891 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 891 | + return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | /** |
@@ -905,21 +905,21 @@ discard block |
||
| 905 | 905 | * true si c'est le cas |
| 906 | 906 | **/ |
| 907 | 907 | function is_utf8($string): bool { |
| 908 | - return !strlen( |
|
| 909 | - preg_replace( |
|
| 910 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 911 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 912 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 913 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 914 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 915 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 916 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 917 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 918 | - . ',sS', |
|
| 919 | - '', |
|
| 920 | - $string |
|
| 921 | - ) |
|
| 922 | - ); |
|
| 908 | + return !strlen( |
|
| 909 | + preg_replace( |
|
| 910 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 911 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 912 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 913 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 914 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 915 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 916 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 917 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 918 | + . ',sS', |
|
| 919 | + '', |
|
| 920 | + $string |
|
| 921 | + ) |
|
| 922 | + ); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -931,13 +931,13 @@ discard block |
||
| 931 | 931 | * true si c'est le cas |
| 932 | 932 | **/ |
| 933 | 933 | function is_ascii($string): bool { |
| 934 | - return !strlen( |
|
| 935 | - preg_replace( |
|
| 936 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 937 | - '', |
|
| 938 | - $string |
|
| 939 | - ) |
|
| 940 | - ); |
|
| 934 | + return !strlen( |
|
| 935 | + preg_replace( |
|
| 936 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 937 | + '', |
|
| 938 | + $string |
|
| 939 | + ) |
|
| 940 | + ); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -956,53 +956,53 @@ discard block |
||
| 956 | 956 | **/ |
| 957 | 957 | function transcoder_page($texte, $headers = ''): string { |
| 958 | 958 | |
| 959 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 960 | - if (is_ascii($texte)) { |
|
| 961 | - #spip_log('charset: ascii'); |
|
| 962 | - return $texte; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - if (bom_utf8($texte)) { |
|
| 966 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 967 | - $charset = 'utf-8'; |
|
| 968 | - $texte = substr($texte, 3); |
|
| 969 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 970 | - // charset precise par le contenu (xml) |
|
| 971 | - $charset = trim(strtolower($regs[1])); |
|
| 972 | - } elseif ( |
|
| 973 | - // charset precise par le contenu (html) |
|
| 974 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 975 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 976 | - and !str_contains($regs[2], '#') |
|
| 977 | - and $tmp = trim(strtolower($regs[2])) |
|
| 978 | - ) { |
|
| 979 | - $charset = $tmp; |
|
| 980 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 981 | - // charset de la reponse http |
|
| 982 | - $charset = trim(strtolower($regs[1])); |
|
| 983 | - } else { |
|
| 984 | - $charset = ''; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - // normaliser les noms du shif-jis japonais |
|
| 989 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 990 | - $charset = 'shift-jis'; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - if ($charset) { |
|
| 994 | - spip_log("charset: $charset"); |
|
| 995 | - } else { |
|
| 996 | - // valeur par defaut |
|
| 997 | - if (is_utf8($texte)) { |
|
| 998 | - $charset = 'utf-8'; |
|
| 999 | - } else { |
|
| 1000 | - $charset = 'iso-8859-1'; |
|
| 1001 | - } |
|
| 1002 | - spip_log("charset probable: $charset"); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return importer_charset($texte, $charset); |
|
| 959 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 960 | + if (is_ascii($texte)) { |
|
| 961 | + #spip_log('charset: ascii'); |
|
| 962 | + return $texte; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + if (bom_utf8($texte)) { |
|
| 966 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 967 | + $charset = 'utf-8'; |
|
| 968 | + $texte = substr($texte, 3); |
|
| 969 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 970 | + // charset precise par le contenu (xml) |
|
| 971 | + $charset = trim(strtolower($regs[1])); |
|
| 972 | + } elseif ( |
|
| 973 | + // charset precise par le contenu (html) |
|
| 974 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 975 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 976 | + and !str_contains($regs[2], '#') |
|
| 977 | + and $tmp = trim(strtolower($regs[2])) |
|
| 978 | + ) { |
|
| 979 | + $charset = $tmp; |
|
| 980 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 981 | + // charset de la reponse http |
|
| 982 | + $charset = trim(strtolower($regs[1])); |
|
| 983 | + } else { |
|
| 984 | + $charset = ''; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + // normaliser les noms du shif-jis japonais |
|
| 989 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 990 | + $charset = 'shift-jis'; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + if ($charset) { |
|
| 994 | + spip_log("charset: $charset"); |
|
| 995 | + } else { |
|
| 996 | + // valeur par defaut |
|
| 997 | + if (is_utf8($texte)) { |
|
| 998 | + $charset = 'utf-8'; |
|
| 999 | + } else { |
|
| 1000 | + $charset = 'iso-8859-1'; |
|
| 1001 | + } |
|
| 1002 | + spip_log("charset probable: $charset"); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return importer_charset($texte, $charset); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
@@ -1026,19 +1026,19 @@ discard block |
||
| 1026 | 1026 | * Le texte coupé |
| 1027 | 1027 | **/ |
| 1028 | 1028 | function spip_substr($c, $start = 0, $length = null) { |
| 1029 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1030 | - if ($length) { |
|
| 1031 | - return substr($c, $start, $length); |
|
| 1032 | - } else { |
|
| 1033 | - return substr($c, $start); |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - if ($length) { |
|
| 1038 | - return mb_substr($c, $start, $length); |
|
| 1039 | - } else { |
|
| 1040 | - return mb_substr($c, $start); |
|
| 1041 | - } |
|
| 1029 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1030 | + if ($length) { |
|
| 1031 | + return substr($c, $start, $length); |
|
| 1032 | + } else { |
|
| 1033 | + return substr($c, $start); |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + if ($length) { |
|
| 1038 | + return mb_substr($c, $start, $length); |
|
| 1039 | + } else { |
|
| 1040 | + return mb_substr($c, $start); |
|
| 1041 | + } |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1052,13 +1052,13 @@ discard block |
||
| 1052 | 1052 | * La chaîne avec une majuscule sur le premier mot |
| 1053 | 1053 | */ |
| 1054 | 1054 | function spip_ucfirst($c) { |
| 1055 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1056 | - return ucfirst($c); |
|
| 1057 | - } |
|
| 1055 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1056 | + return ucfirst($c); |
|
| 1057 | + } |
|
| 1058 | 1058 | |
| 1059 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1059 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1060 | 1060 | |
| 1061 | - return $lettre1 . spip_substr($c, 1); |
|
| 1061 | + return $lettre1 . spip_substr($c, 1); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -1072,11 +1072,11 @@ discard block |
||
| 1072 | 1072 | * La chaîne en minuscules |
| 1073 | 1073 | */ |
| 1074 | 1074 | function spip_strtolower($c) { |
| 1075 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1076 | - return strtolower($c); |
|
| 1077 | - } |
|
| 1075 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1076 | + return strtolower($c); |
|
| 1077 | + } |
|
| 1078 | 1078 | |
| 1079 | - return mb_strtolower($c); |
|
| 1079 | + return mb_strtolower($c); |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | /** |
@@ -1090,15 +1090,15 @@ discard block |
||
| 1090 | 1090 | * Longueur de la chaîne |
| 1091 | 1091 | */ |
| 1092 | 1092 | function spip_strlen($c) { |
| 1093 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1094 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1093 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1094 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1095 | 1095 | |
| 1096 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1097 | - if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1098 | - return strlen($c); |
|
| 1099 | - } |
|
| 1096 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1097 | + if ($GLOBALS['meta']['charset'] !== 'utf-8') { |
|
| 1098 | + return strlen($c); |
|
| 1099 | + } |
|
| 1100 | 1100 | |
| 1101 | - return mb_strlen($c); |
|
| 1101 | + return mb_strlen($c); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | /** |
@@ -1113,17 +1113,17 @@ discard block |
||
| 1113 | 1113 | * en unicode : 💩 |
| 1114 | 1114 | */ |
| 1115 | 1115 | function utf8_noplanes($x): string { |
| 1116 | - $regexp_utf8_4bytes = '/( |
|
| 1116 | + $regexp_utf8_4bytes = '/( |
|
| 1117 | 1117 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1118 | 1118 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1119 | 1119 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1120 | 1120 | )/xS'; |
| 1121 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1122 | - foreach ($z[0] as $k) { |
|
| 1123 | - $ku = utf_8_to_unicode($k); |
|
| 1124 | - $x = str_replace($k, $ku, $x); |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - return $x; |
|
| 1121 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1122 | + foreach ($z[0] as $k) { |
|
| 1123 | + $ku = utf_8_to_unicode($k); |
|
| 1124 | + $x = str_replace($k, $ku, $x); |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + return $x; |
|
| 1129 | 1129 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $charset = 'cp1256'; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 93 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 94 | 94 | return $charset; |
| 95 | 95 | } else { |
| 96 | 96 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -195,38 +195,38 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | if (!isset($trans[$charset][$charset_cible])) { |
| 197 | 197 | $trans[$charset][$charset_cible] = [ |
| 198 | - $p . chr(128) => '€', |
|
| 199 | - $p . chr(129) => ' ', # pas affecte |
|
| 200 | - $p . chr(130) => '‚', |
|
| 201 | - $p . chr(131) => 'ƒ', |
|
| 202 | - $p . chr(132) => '„', |
|
| 203 | - $p . chr(133) => '…', |
|
| 204 | - $p . chr(134) => '†', |
|
| 205 | - $p . chr(135) => '‡', |
|
| 206 | - $p . chr(136) => 'ˆ', |
|
| 207 | - $p . chr(137) => '‰', |
|
| 208 | - $p . chr(138) => 'Š', |
|
| 209 | - $p . chr(139) => '‹', |
|
| 210 | - $p . chr(140) => 'Œ', |
|
| 211 | - $p . chr(141) => ' ', # pas affecte |
|
| 212 | - $p . chr(142) => 'Ž', |
|
| 213 | - $p . chr(143) => ' ', # pas affecte |
|
| 214 | - $p . chr(144) => ' ', # pas affecte |
|
| 215 | - $p . chr(145) => '‘', |
|
| 216 | - $p . chr(146) => '’', |
|
| 217 | - $p . chr(147) => '“', |
|
| 218 | - $p . chr(148) => '”', |
|
| 219 | - $p . chr(149) => '•', |
|
| 220 | - $p . chr(150) => '–', |
|
| 221 | - $p . chr(151) => '—', |
|
| 222 | - $p . chr(152) => '˜', |
|
| 223 | - $p . chr(153) => '™', |
|
| 224 | - $p . chr(154) => 'š', |
|
| 225 | - $p . chr(155) => '›', |
|
| 226 | - $p . chr(156) => 'œ', |
|
| 227 | - $p . chr(157) => ' ', # pas affecte |
|
| 228 | - $p . chr(158) => 'ž', |
|
| 229 | - $p . chr(159) => 'Ÿ', |
|
| 198 | + $p.chr(128) => '€', |
|
| 199 | + $p.chr(129) => ' ', # pas affecte |
|
| 200 | + $p.chr(130) => '‚', |
|
| 201 | + $p.chr(131) => 'ƒ', |
|
| 202 | + $p.chr(132) => '„', |
|
| 203 | + $p.chr(133) => '…', |
|
| 204 | + $p.chr(134) => '†', |
|
| 205 | + $p.chr(135) => '‡', |
|
| 206 | + $p.chr(136) => 'ˆ', |
|
| 207 | + $p.chr(137) => '‰', |
|
| 208 | + $p.chr(138) => 'Š', |
|
| 209 | + $p.chr(139) => '‹', |
|
| 210 | + $p.chr(140) => 'Œ', |
|
| 211 | + $p.chr(141) => ' ', # pas affecte |
|
| 212 | + $p.chr(142) => 'Ž', |
|
| 213 | + $p.chr(143) => ' ', # pas affecte |
|
| 214 | + $p.chr(144) => ' ', # pas affecte |
|
| 215 | + $p.chr(145) => '‘', |
|
| 216 | + $p.chr(146) => '’', |
|
| 217 | + $p.chr(147) => '“', |
|
| 218 | + $p.chr(148) => '”', |
|
| 219 | + $p.chr(149) => '•', |
|
| 220 | + $p.chr(150) => '–', |
|
| 221 | + $p.chr(151) => '—', |
|
| 222 | + $p.chr(152) => '˜', |
|
| 223 | + $p.chr(153) => '™', |
|
| 224 | + $p.chr(154) => 'š', |
|
| 225 | + $p.chr(155) => '›', |
|
| 226 | + $p.chr(156) => 'œ', |
|
| 227 | + $p.chr(157) => ' ', # pas affecte |
|
| 228 | + $p.chr(158) => 'ž', |
|
| 229 | + $p.chr(159) => 'Ÿ', |
|
| 230 | 230 | ]; |
| 231 | 231 | if ($charset_cible != 'unicode') { |
| 232 | 232 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 368 | 368 | ) { |
| 369 | 369 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 370 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 370 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -433,11 +433,11 @@ discard block |
||
| 433 | 433 | $h = dechex($e); |
| 434 | 434 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 435 | 435 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 436 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 437 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 436 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 437 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 438 | 438 | } else { |
| 439 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 440 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 439 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 440 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | } |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 485 | 485 | ) { |
| 486 | 486 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 487 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 487 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | 490 | } |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | $thisPos++; |
| 593 | 593 | } |
| 594 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 594 | + $encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 595 | 595 | $encodedString .= $encodedLetter; |
| 596 | 596 | } |
| 597 | 597 | } |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 635 | 635 | else { |
| 636 | 636 | if ($word != 65279) { |
| 637 | - $texte .= '&#' . $word . ';'; |
|
| 637 | + $texte .= '&#'.$word.';'; |
|
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | } |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | return chr($num); |
| 663 | 663 | } |
| 664 | 664 | if ($num < 2048) { |
| 665 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 665 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 666 | 666 | } |
| 667 | 667 | if ($num < 65536) { |
| 668 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 668 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 669 | 669 | } |
| 670 | 670 | if ($num < 1_114_112) { |
| 671 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 671 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | return ''; |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
| 736 | 736 | $num = $regs[1]; |
| 737 | 737 | $vu[$num] = true; |
| 738 | - $s = '\u' . sprintf('%04x', $num); |
|
| 738 | + $s = '\u'.sprintf('%04x', $num); |
|
| 739 | 739 | $texte = str_replace($regs[0], $s, $texte); |
| 740 | 740 | } |
| 741 | 741 | |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | **/ |
| 753 | 753 | function javascript_to_unicode($texte) { |
| 754 | 754 | while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
| 755 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 755 | + $texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | return $texte; |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | return $texte; |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - $table_translit = 'translit' . $complexe; |
|
| 800 | + $table_translit = 'translit'.$complexe; |
|
| 801 | 801 | |
| 802 | 802 | // 2. Translitterer grace a la table predefinie |
| 803 | 803 | if (!isset($trans[$complexe])) { |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * true s'il a un BOM |
| 889 | 889 | **/ |
| 890 | 890 | function bom_utf8($texte): bool { |
| 891 | - return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 891 | + return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | /** |
@@ -1058,7 +1058,7 @@ discard block |
||
| 1058 | 1058 | |
| 1059 | 1059 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1060 | 1060 | |
| 1061 | - return $lettre1 . spip_substr($c, 1); |
|
| 1061 | + return $lettre1.spip_substr($c, 1); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | /** |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $res = admin_repair_tables(); |
| 40 | 40 | if (!$res) { |
| 41 | - $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 41 | + $res = "<div class='error'>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error()."</div>\n"; |
|
| 42 | 42 | } else { |
| 43 | 43 | include_spip('inc/rubriques'); |
| 44 | 44 | calculer_rubriques(); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $res .= pipeline('base_admin_repair', $res); |
| 49 | 49 | echo minipres( |
| 50 | 50 | _T('texte_tentative_recuperation'), |
| 51 | - $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 51 | + $res.generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 52 | 52 | ); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | $count = sql_countsel($tab); |
| 92 | 92 | |
| 93 | 93 | if ($count > 1) { |
| 94 | - $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 94 | + $m .= '('._T('texte_compte_elements', ['count' => $count]).")\n"; |
|
| 95 | 95 | } else { |
| 96 | 96 | if ($count == 1) { |
| 97 | - $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 97 | + $m .= '('._T('texte_compte_element', ['count' => $count]).")\n"; |
|
| 98 | 98 | } else { |
| 99 | - $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 99 | + $m .= '('._T('texte_vide').")\n"; |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | and $msg = join( |
| 106 | 106 | ' ', |
| 107 | 107 | (is_resource($result_repair) or is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
| 108 | - ) . ' ' |
|
| 108 | + ).' ' |
|
| 109 | 109 | and !str_contains($msg, ' OK ') |
| 110 | 110 | ) { |
| 111 | 111 | $class = " class='notice'"; |
| 112 | - $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 112 | + $m .= '<br /><tt>'.spip_htmlentities($msg)."</tt>\n"; |
|
| 113 | 113 | } else { |
| 114 | - $m .= ' ' . _T('texte_table_ok'); |
|
| 114 | + $m .= ' '._T('texte_table_ok'); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $res .= "<div$class>$m</div>"; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -36,20 +36,20 @@ discard block |
||
| 36 | 36 | **/ |
| 37 | 37 | function base_repair_dist($titre = '', $reprise = '') { |
| 38 | 38 | |
| 39 | - $res = admin_repair_tables(); |
|
| 40 | - if (!$res) { |
|
| 41 | - $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 42 | - } else { |
|
| 43 | - include_spip('inc/rubriques'); |
|
| 44 | - calculer_rubriques(); |
|
| 45 | - propager_les_secteurs(); |
|
| 46 | - } |
|
| 47 | - include_spip('inc/minipres'); |
|
| 48 | - $res .= pipeline('base_admin_repair', $res); |
|
| 49 | - echo minipres( |
|
| 50 | - _T('texte_tentative_recuperation'), |
|
| 51 | - $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 52 | - ); |
|
| 39 | + $res = admin_repair_tables(); |
|
| 40 | + if (!$res) { |
|
| 41 | + $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n"; |
|
| 42 | + } else { |
|
| 43 | + include_spip('inc/rubriques'); |
|
| 44 | + calculer_rubriques(); |
|
| 45 | + propager_les_secteurs(); |
|
| 46 | + } |
|
| 47 | + include_spip('inc/minipres'); |
|
| 48 | + $res .= pipeline('base_admin_repair', $res); |
|
| 49 | + echo minipres( |
|
| 50 | + _T('texte_tentative_recuperation'), |
|
| 51 | + $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site')) |
|
| 52 | + ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -63,60 +63,60 @@ discard block |
||
| 63 | 63 | **/ |
| 64 | 64 | function admin_repair_tables() { |
| 65 | 65 | |
| 66 | - $repair = sql_serveur('repair', '', true); |
|
| 66 | + $repair = sql_serveur('repair', '', true); |
|
| 67 | 67 | |
| 68 | - // recreer les tables manquantes eventuelles |
|
| 69 | - include_spip('base/create'); |
|
| 70 | - creer_base(); |
|
| 71 | - $tables = sql_alltable(); |
|
| 68 | + // recreer les tables manquantes eventuelles |
|
| 69 | + include_spip('base/create'); |
|
| 70 | + creer_base(); |
|
| 71 | + $tables = sql_alltable(); |
|
| 72 | 72 | |
| 73 | - $res = ''; |
|
| 74 | - foreach ($tables as $tab) { |
|
| 75 | - $class = ''; |
|
| 76 | - $m = "<strong>$tab</strong> "; |
|
| 77 | - spip_log("Repare $tab", _LOG_INFO_IMPORTANTE); |
|
| 78 | - // supprimer la meta avant de lancer la reparation |
|
| 79 | - // car le repair peut etre long ; on ne veut pas boucler |
|
| 80 | - effacer_meta('admin_repair'); |
|
| 81 | - if ($repair) { |
|
| 82 | - $result_repair = sql_repair($tab); |
|
| 83 | - if (!$result_repair) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - } |
|
| 73 | + $res = ''; |
|
| 74 | + foreach ($tables as $tab) { |
|
| 75 | + $class = ''; |
|
| 76 | + $m = "<strong>$tab</strong> "; |
|
| 77 | + spip_log("Repare $tab", _LOG_INFO_IMPORTANTE); |
|
| 78 | + // supprimer la meta avant de lancer la reparation |
|
| 79 | + // car le repair peut etre long ; on ne veut pas boucler |
|
| 80 | + effacer_meta('admin_repair'); |
|
| 81 | + if ($repair) { |
|
| 82 | + $result_repair = sql_repair($tab); |
|
| 83 | + if (!$result_repair) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // essayer de maj la table (creation de champs manquants) |
|
| 89 | - maj_tables($tab); |
|
| 88 | + // essayer de maj la table (creation de champs manquants) |
|
| 89 | + maj_tables($tab); |
|
| 90 | 90 | |
| 91 | - $count = sql_countsel($tab); |
|
| 91 | + $count = sql_countsel($tab); |
|
| 92 | 92 | |
| 93 | - if ($count > 1) { |
|
| 94 | - $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 95 | - } else { |
|
| 96 | - if ($count == 1) { |
|
| 97 | - $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 98 | - } else { |
|
| 99 | - $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 100 | - } |
|
| 101 | - } |
|
| 93 | + if ($count > 1) { |
|
| 94 | + $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n"; |
|
| 95 | + } else { |
|
| 96 | + if ($count == 1) { |
|
| 97 | + $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n"; |
|
| 98 | + } else { |
|
| 99 | + $m .= '(' . _T('texte_vide') . ")\n"; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - if ( |
|
| 104 | - $repair |
|
| 105 | - and $result_repair |
|
| 106 | - and $msg = join( |
|
| 107 | - ' ', |
|
| 108 | - (is_resource($result_repair) or is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 109 | - ) . ' ' |
|
| 110 | - and !str_contains($msg, ' OK ') |
|
| 111 | - ) { |
|
| 112 | - $class = " class='notice'"; |
|
| 113 | - $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 114 | - } else { |
|
| 115 | - $m .= ' ' . _T('texte_table_ok'); |
|
| 116 | - } |
|
| 103 | + if ( |
|
| 104 | + $repair |
|
| 105 | + and $result_repair |
|
| 106 | + and $msg = join( |
|
| 107 | + ' ', |
|
| 108 | + (is_resource($result_repair) or is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair |
|
| 109 | + ) . ' ' |
|
| 110 | + and !str_contains($msg, ' OK ') |
|
| 111 | + ) { |
|
| 112 | + $class = " class='notice'"; |
|
| 113 | + $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n"; |
|
| 114 | + } else { |
|
| 115 | + $m .= ' ' . _T('texte_table_ok'); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - $res .= "<div$class>$m</div>"; |
|
| 119 | - } |
|
| 118 | + $res .= "<div$class>$m</div>"; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - return $res; |
|
| 121 | + return $res; |
|
| 122 | 122 | } |