@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -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 |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if ( |
|
| 100 | - function_exists('mb_internal_encoding') |
|
| 101 | - and function_exists('mb_detect_order') |
|
| 102 | - and function_exists('mb_substr') |
|
| 103 | - and function_exists('mb_strlen') |
|
| 104 | - and function_exists('mb_strtolower') |
|
| 105 | - and function_exists('mb_strtoupper') |
|
| 106 | - and function_exists('mb_encode_mimeheader') |
|
| 107 | - and function_exists('mb_encode_numericentity') |
|
| 108 | - and function_exists('mb_decode_numericentity') |
|
| 109 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | - ) { |
|
| 111 | - mb_internal_encoding('utf-8'); |
|
| 112 | - $mb = 1; |
|
| 113 | - } else { |
|
| 114 | - $mb = -1; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if ( |
|
| 100 | + function_exists('mb_internal_encoding') |
|
| 101 | + and function_exists('mb_detect_order') |
|
| 102 | + and function_exists('mb_substr') |
|
| 103 | + and function_exists('mb_strlen') |
|
| 104 | + and function_exists('mb_strtolower') |
|
| 105 | + and function_exists('mb_strtoupper') |
|
| 106 | + and function_exists('mb_encode_mimeheader') |
|
| 107 | + and function_exists('mb_encode_numericentity') |
|
| 108 | + and function_exists('mb_decode_numericentity') |
|
| 109 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | + ) { |
|
| 111 | + mb_internal_encoding('utf-8'); |
|
| 112 | + $mb = 1; |
|
| 113 | + } else { |
|
| 114 | + $mb = -1; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return ($mb == 1); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * true si iconv fonctionne correctement |
| 131 | 131 | **/ |
| 132 | 132 | function test_iconv() { |
| 133 | - static $iconv_ok; |
|
| 134 | - |
|
| 135 | - if (!$iconv_ok) { |
|
| 136 | - if (!function_exists('iconv')) { |
|
| 137 | - $iconv_ok = -1; |
|
| 138 | - } else { |
|
| 139 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | - $iconv_ok = 1; |
|
| 141 | - } else { |
|
| 142 | - $iconv_ok = -1; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ($iconv_ok == 1); |
|
| 133 | + static $iconv_ok; |
|
| 134 | + |
|
| 135 | + if (!$iconv_ok) { |
|
| 136 | + if (!function_exists('iconv')) { |
|
| 137 | + $iconv_ok = -1; |
|
| 138 | + } else { |
|
| 139 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | + $iconv_ok = 1; |
|
| 141 | + } else { |
|
| 142 | + $iconv_ok = -1; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ($iconv_ok == 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | * true si PCRE supporte l'UTF-8 correctement |
| 158 | 158 | **/ |
| 159 | 159 | function test_pcre_unicode() { |
| 160 | - static $pcre_ok = 0; |
|
| 161 | - |
|
| 162 | - if (!$pcre_ok) { |
|
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | - $pcre_ok = 1; |
|
| 166 | - } else { |
|
| 167 | - $pcre_ok = -1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $pcre_ok == 1; |
|
| 160 | + static $pcre_ok = 0; |
|
| 161 | + |
|
| 162 | + if (!$pcre_ok) { |
|
| 163 | + $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | + $pcre_ok = 1; |
|
| 166 | + } else { |
|
| 167 | + $pcre_ok = -1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $pcre_ok == 1; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -184,22 +184,22 @@ discard block |
||
| 184 | 184 | * Plage de caractères |
| 185 | 185 | **/ |
| 186 | 186 | function pcre_lettres_unicode() { |
| 187 | - static $plage_unicode; |
|
| 188 | - |
|
| 189 | - if (!$plage_unicode) { |
|
| 190 | - if (test_pcre_unicode()) { |
|
| 191 | - // cf. http://www.unicode.org/charts/ |
|
| 192 | - $plage_unicode = '\w' // iso-latin |
|
| 193 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | - ; |
|
| 196 | - } else { |
|
| 197 | - // fallback a trois sous |
|
| 198 | - $plage_unicode = '\w'; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $plage_unicode; |
|
| 187 | + static $plage_unicode; |
|
| 188 | + |
|
| 189 | + if (!$plage_unicode) { |
|
| 190 | + if (test_pcre_unicode()) { |
|
| 191 | + // cf. http://www.unicode.org/charts/ |
|
| 192 | + $plage_unicode = '\w' // iso-latin |
|
| 193 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | + ; |
|
| 196 | + } else { |
|
| 197 | + // fallback a trois sous |
|
| 198 | + $plage_unicode = '\w'; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $plage_unicode; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * Plage de caractères |
| 218 | 218 | **/ |
| 219 | 219 | function plage_punct_unicode() { |
| 220 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -237,75 +237,75 @@ discard block |
||
| 237 | 237 | * Texte corrigé |
| 238 | 238 | **/ |
| 239 | 239 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 240 | - static $trans; |
|
| 241 | - |
|
| 242 | - if (is_array($texte)) { |
|
| 243 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($charset == 'AUTO') { |
|
| 247 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | - } |
|
| 249 | - if ($charset == 'utf-8') { |
|
| 250 | - $p = chr(194); |
|
| 251 | - if (strpos($texte, $p) == false) { |
|
| 252 | - return $texte; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - if ($charset == 'iso-8859-1') { |
|
| 256 | - $p = ''; |
|
| 257 | - } else { |
|
| 258 | - return $texte; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | - $trans[$charset][$charset_cible] = [ |
|
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 296 | - ]; |
|
| 297 | - if ($charset_cible != 'unicode') { |
|
| 298 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return @str_replace( |
|
| 305 | - array_keys($trans[$charset][$charset_cible]), |
|
| 306 | - array_values($trans[$charset][$charset_cible]), |
|
| 307 | - $texte |
|
| 308 | - ); |
|
| 240 | + static $trans; |
|
| 241 | + |
|
| 242 | + if (is_array($texte)) { |
|
| 243 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($charset == 'AUTO') { |
|
| 247 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | + } |
|
| 249 | + if ($charset == 'utf-8') { |
|
| 250 | + $p = chr(194); |
|
| 251 | + if (strpos($texte, $p) == false) { |
|
| 252 | + return $texte; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + if ($charset == 'iso-8859-1') { |
|
| 256 | + $p = ''; |
|
| 257 | + } else { |
|
| 258 | + return $texte; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | + $trans[$charset][$charset_cible] = [ |
|
| 264 | + $p . chr(128) => '€', |
|
| 265 | + $p . chr(129) => ' ', # pas affecte |
|
| 266 | + $p . chr(130) => '‚', |
|
| 267 | + $p . chr(131) => 'ƒ', |
|
| 268 | + $p . chr(132) => '„', |
|
| 269 | + $p . chr(133) => '…', |
|
| 270 | + $p . chr(134) => '†', |
|
| 271 | + $p . chr(135) => '‡', |
|
| 272 | + $p . chr(136) => 'ˆ', |
|
| 273 | + $p . chr(137) => '‰', |
|
| 274 | + $p . chr(138) => 'Š', |
|
| 275 | + $p . chr(139) => '‹', |
|
| 276 | + $p . chr(140) => 'Œ', |
|
| 277 | + $p . chr(141) => ' ', # pas affecte |
|
| 278 | + $p . chr(142) => 'Ž', |
|
| 279 | + $p . chr(143) => ' ', # pas affecte |
|
| 280 | + $p . chr(144) => ' ', # pas affecte |
|
| 281 | + $p . chr(145) => '‘', |
|
| 282 | + $p . chr(146) => '’', |
|
| 283 | + $p . chr(147) => '“', |
|
| 284 | + $p . chr(148) => '”', |
|
| 285 | + $p . chr(149) => '•', |
|
| 286 | + $p . chr(150) => '–', |
|
| 287 | + $p . chr(151) => '—', |
|
| 288 | + $p . chr(152) => '˜', |
|
| 289 | + $p . chr(153) => '™', |
|
| 290 | + $p . chr(154) => 'š', |
|
| 291 | + $p . chr(155) => '›', |
|
| 292 | + $p . chr(156) => 'œ', |
|
| 293 | + $p . chr(157) => ' ', # pas affecte |
|
| 294 | + $p . chr(158) => 'ž', |
|
| 295 | + $p . chr(159) => 'Ÿ', |
|
| 296 | + ]; |
|
| 297 | + if ($charset_cible != 'unicode') { |
|
| 298 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return @str_replace( |
|
| 305 | + array_keys($trans[$charset][$charset_cible]), |
|
| 306 | + array_values($trans[$charset][$charset_cible]), |
|
| 307 | + $texte |
|
| 308 | + ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | * Texte converti |
| 323 | 323 | **/ |
| 324 | 324 | function html2unicode($texte, $secure = false) { |
| 325 | - if (strpos($texte, '&') === false) { |
|
| 326 | - return $texte; |
|
| 327 | - } |
|
| 328 | - static $trans = []; |
|
| 329 | - if (!$trans) { |
|
| 330 | - load_charset('html'); |
|
| 331 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | - $trans["&$key;"] = $val; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($secure) { |
|
| 337 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | - } else { |
|
| 339 | - return str_replace( |
|
| 340 | - ['&', '"', '<', '>'], |
|
| 341 | - ['&', '"', '<', '>'], |
|
| 342 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | - ); |
|
| 344 | - } |
|
| 325 | + if (strpos($texte, '&') === false) { |
|
| 326 | + return $texte; |
|
| 327 | + } |
|
| 328 | + static $trans = []; |
|
| 329 | + if (!$trans) { |
|
| 330 | + load_charset('html'); |
|
| 331 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | + $trans["&$key;"] = $val; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($secure) { |
|
| 337 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | + } else { |
|
| 339 | + return str_replace( |
|
| 340 | + ['&', '"', '<', '>'], |
|
| 341 | + ['&', '"', '<', '>'], |
|
| 342 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | * Texte converti |
| 357 | 357 | **/ |
| 358 | 358 | function mathml2unicode($texte) { |
| 359 | - static $trans; |
|
| 360 | - if (!$trans) { |
|
| 361 | - load_charset('mathml'); |
|
| 359 | + static $trans; |
|
| 360 | + if (!$trans) { |
|
| 361 | + load_charset('mathml'); |
|
| 362 | 362 | |
| 363 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | - $trans["&$key;"] = $val; |
|
| 365 | - } |
|
| 366 | - } |
|
| 363 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | + $trans["&$key;"] = $val; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 368 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -387,75 +387,75 @@ discard block |
||
| 387 | 387 | * Texte converti en unicode |
| 388 | 388 | **/ |
| 389 | 389 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 390 | - static $trans; |
|
| 391 | - |
|
| 392 | - if ($charset == 'AUTO') { |
|
| 393 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($charset == '') { |
|
| 397 | - $charset = 'iso-8859-1'; |
|
| 398 | - } |
|
| 399 | - $charset = strtolower($charset); |
|
| 400 | - |
|
| 401 | - switch ($charset) { |
|
| 402 | - case 'utf-8': |
|
| 403 | - case 'utf8': |
|
| 404 | - return utf_8_to_unicode($texte); |
|
| 405 | - |
|
| 406 | - case 'iso-8859-1': |
|
| 407 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | - // pas de break; ici, on suit sur default: |
|
| 409 | - |
|
| 410 | - default: |
|
| 411 | - // mbstring presente ? |
|
| 412 | - if (init_mb_string()) { |
|
| 413 | - $order = mb_detect_order(); |
|
| 414 | - try { |
|
| 415 | - # mb_string connait-il $charset? |
|
| 416 | - if ($order and mb_detect_order($charset)) { |
|
| 417 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | - if ($s && $s != $texte) { |
|
| 419 | - return utf_8_to_unicode($s); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } catch (\Error $e) { |
|
| 423 | - // Le charset n'existe probablement pas |
|
| 424 | - } finally { |
|
| 425 | - mb_detect_order($order); # remettre comme precedemment |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | - if (!isset($trans[$charset])) { |
|
| 431 | - if ( |
|
| 432 | - $cset = load_charset($charset) |
|
| 433 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | - ) { |
|
| 435 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | - // surtout en utf-8, gere ci-dessus) |
|
| 447 | - if (test_iconv()) { |
|
| 448 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | - if ($s) { |
|
| 450 | - return utf_32_to_unicode($s); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // Au pire ne rien faire |
|
| 455 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | - |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 390 | + static $trans; |
|
| 391 | + |
|
| 392 | + if ($charset == 'AUTO') { |
|
| 393 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($charset == '') { |
|
| 397 | + $charset = 'iso-8859-1'; |
|
| 398 | + } |
|
| 399 | + $charset = strtolower($charset); |
|
| 400 | + |
|
| 401 | + switch ($charset) { |
|
| 402 | + case 'utf-8': |
|
| 403 | + case 'utf8': |
|
| 404 | + return utf_8_to_unicode($texte); |
|
| 405 | + |
|
| 406 | + case 'iso-8859-1': |
|
| 407 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | + // pas de break; ici, on suit sur default: |
|
| 409 | + |
|
| 410 | + default: |
|
| 411 | + // mbstring presente ? |
|
| 412 | + if (init_mb_string()) { |
|
| 413 | + $order = mb_detect_order(); |
|
| 414 | + try { |
|
| 415 | + # mb_string connait-il $charset? |
|
| 416 | + if ($order and mb_detect_order($charset)) { |
|
| 417 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | + if ($s && $s != $texte) { |
|
| 419 | + return utf_8_to_unicode($s); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } catch (\Error $e) { |
|
| 423 | + // Le charset n'existe probablement pas |
|
| 424 | + } finally { |
|
| 425 | + mb_detect_order($order); # remettre comme precedemment |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | + if (!isset($trans[$charset])) { |
|
| 431 | + if ( |
|
| 432 | + $cset = load_charset($charset) |
|
| 433 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | + ) { |
|
| 435 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | + // surtout en utf-8, gere ci-dessus) |
|
| 447 | + if (test_iconv()) { |
|
| 448 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | + if ($s) { |
|
| 450 | + return utf_32_to_unicode($s); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // Au pire ne rien faire |
|
| 455 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | + |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -474,44 +474,44 @@ discard block |
||
| 474 | 474 | * Texte transformé dans le charset souhaité |
| 475 | 475 | **/ |
| 476 | 476 | function unicode2charset($texte, $charset = 'AUTO') { |
| 477 | - static $CHARSET_REVERSE = []; |
|
| 478 | - static $trans = []; |
|
| 479 | - |
|
| 480 | - if ($charset == 'AUTO') { |
|
| 481 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - switch ($charset) { |
|
| 485 | - case 'utf-8': |
|
| 486 | - return unicode_to_utf_8($texte); |
|
| 487 | - break; |
|
| 488 | - |
|
| 489 | - default: |
|
| 490 | - $charset = load_charset($charset); |
|
| 491 | - |
|
| 492 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if (!isset($trans[$charset])) { |
|
| 497 | - $trans[$charset] = []; |
|
| 498 | - $t = &$trans[$charset]; |
|
| 499 | - for ($e = 128; $e < 255; $e++) { |
|
| 500 | - $h = dechex($e); |
|
| 501 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | - } else { |
|
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | - |
|
| 513 | - return $texte; |
|
| 514 | - } |
|
| 477 | + static $CHARSET_REVERSE = []; |
|
| 478 | + static $trans = []; |
|
| 479 | + |
|
| 480 | + if ($charset == 'AUTO') { |
|
| 481 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + switch ($charset) { |
|
| 485 | + case 'utf-8': |
|
| 486 | + return unicode_to_utf_8($texte); |
|
| 487 | + break; |
|
| 488 | + |
|
| 489 | + default: |
|
| 490 | + $charset = load_charset($charset); |
|
| 491 | + |
|
| 492 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if (!isset($trans[$charset])) { |
|
| 497 | + $trans[$charset] = []; |
|
| 498 | + $t = &$trans[$charset]; |
|
| 499 | + for ($e = 128; $e < 255; $e++) { |
|
| 500 | + $h = dechex($e); |
|
| 501 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | + } else { |
|
| 506 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | + |
|
| 513 | + return $texte; |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
@@ -529,40 +529,40 @@ discard block |
||
| 529 | 529 | * Texte transformé dans le charset site |
| 530 | 530 | **/ |
| 531 | 531 | function importer_charset($texte, $charset = 'AUTO') { |
| 532 | - $s = null; |
|
| 533 | - static $trans = []; |
|
| 534 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | - if (init_mb_string()) { |
|
| 538 | - if ( |
|
| 539 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | - and mb_detect_order($charset) |
|
| 541 | - ) { |
|
| 542 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | - } |
|
| 544 | - mb_detect_order($order); # remettre comme precedemment |
|
| 545 | - return $s; |
|
| 546 | - } |
|
| 547 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | - if (!isset($trans[$charset])) { |
|
| 549 | - if ( |
|
| 550 | - $cset = load_charset($charset) |
|
| 551 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | - ) { |
|
| 553 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $texte; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 532 | + $s = null; |
|
| 533 | + static $trans = []; |
|
| 534 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | + if (init_mb_string()) { |
|
| 538 | + if ( |
|
| 539 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | + and mb_detect_order($charset) |
|
| 541 | + ) { |
|
| 542 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | + } |
|
| 544 | + mb_detect_order($order); # remettre comme precedemment |
|
| 545 | + return $s; |
|
| 546 | + } |
|
| 547 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | + if (!isset($trans[$charset])) { |
|
| 549 | + if ( |
|
| 550 | + $cset = load_charset($charset) |
|
| 551 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | + ) { |
|
| 553 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $texte; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
@@ -578,92 +578,92 @@ discard block |
||
| 578 | 578 | **/ |
| 579 | 579 | function utf_8_to_unicode($source) { |
| 580 | 580 | |
| 581 | - // mb_string : methode rapide |
|
| 582 | - if (init_mb_string()) { |
|
| 583 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | - |
|
| 585 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - // Sinon methode pas a pas |
|
| 589 | - static $decrement; |
|
| 590 | - static $shift; |
|
| 591 | - |
|
| 592 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | - if (!is_array($decrement)) { |
|
| 594 | - // array used to figure what number to decrement from character order value |
|
| 595 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | - $decrement[4] = 240; |
|
| 597 | - $decrement[3] = 224; |
|
| 598 | - $decrement[2] = 192; |
|
| 599 | - $decrement[1] = 0; |
|
| 600 | - // the number of bits to shift each charNum by |
|
| 601 | - $shift[1][0] = 0; |
|
| 602 | - $shift[2][0] = 6; |
|
| 603 | - $shift[2][1] = 0; |
|
| 604 | - $shift[3][0] = 12; |
|
| 605 | - $shift[3][1] = 6; |
|
| 606 | - $shift[3][2] = 0; |
|
| 607 | - $shift[4][0] = 18; |
|
| 608 | - $shift[4][1] = 12; |
|
| 609 | - $shift[4][2] = 6; |
|
| 610 | - $shift[4][3] = 0; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $pos = 0; |
|
| 614 | - $len = strlen($source); |
|
| 615 | - $encodedString = ''; |
|
| 616 | - while ($pos < $len) { |
|
| 617 | - $char = ''; |
|
| 618 | - $ischar = false; |
|
| 619 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | - // 4 chars representing one unicode character |
|
| 622 | - $thisLetter = substr($source, $pos, 4); |
|
| 623 | - $pos += 4; |
|
| 624 | - } else { |
|
| 625 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | - // 3 chars representing one unicode character |
|
| 627 | - $thisLetter = substr($source, $pos, 3); |
|
| 628 | - $pos += 3; |
|
| 629 | - } else { |
|
| 630 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | - // 2 chars representing one unicode character |
|
| 632 | - $thisLetter = substr($source, $pos, 2); |
|
| 633 | - $pos += 2; |
|
| 634 | - } else { |
|
| 635 | - // 1 char (lower ascii) |
|
| 636 | - $thisLetter = substr($source, $pos, 1); |
|
| 637 | - $pos += 1; |
|
| 638 | - $char = $thisLetter; |
|
| 639 | - $ischar = true; |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ($ischar) { |
|
| 645 | - $encodedString .= $char; |
|
| 646 | - } else { // process the string representing the letter to a unicode entity |
|
| 647 | - $thisLen = strlen($thisLetter); |
|
| 648 | - $thisPos = 0; |
|
| 649 | - $decimalCode = 0; |
|
| 650 | - while ($thisPos < $thisLen) { |
|
| 651 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | - if ($thisPos == 0) { |
|
| 653 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | - } else { |
|
| 656 | - $charNum = intval($thisCharOrd - 128); |
|
| 657 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | - } |
|
| 659 | - $thisPos++; |
|
| 660 | - } |
|
| 661 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | - $encodedString .= $encodedLetter; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $encodedString; |
|
| 581 | + // mb_string : methode rapide |
|
| 582 | + if (init_mb_string()) { |
|
| 583 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | + |
|
| 585 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + // Sinon methode pas a pas |
|
| 589 | + static $decrement; |
|
| 590 | + static $shift; |
|
| 591 | + |
|
| 592 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | + if (!is_array($decrement)) { |
|
| 594 | + // array used to figure what number to decrement from character order value |
|
| 595 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | + $decrement[4] = 240; |
|
| 597 | + $decrement[3] = 224; |
|
| 598 | + $decrement[2] = 192; |
|
| 599 | + $decrement[1] = 0; |
|
| 600 | + // the number of bits to shift each charNum by |
|
| 601 | + $shift[1][0] = 0; |
|
| 602 | + $shift[2][0] = 6; |
|
| 603 | + $shift[2][1] = 0; |
|
| 604 | + $shift[3][0] = 12; |
|
| 605 | + $shift[3][1] = 6; |
|
| 606 | + $shift[3][2] = 0; |
|
| 607 | + $shift[4][0] = 18; |
|
| 608 | + $shift[4][1] = 12; |
|
| 609 | + $shift[4][2] = 6; |
|
| 610 | + $shift[4][3] = 0; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $pos = 0; |
|
| 614 | + $len = strlen($source); |
|
| 615 | + $encodedString = ''; |
|
| 616 | + while ($pos < $len) { |
|
| 617 | + $char = ''; |
|
| 618 | + $ischar = false; |
|
| 619 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | + // 4 chars representing one unicode character |
|
| 622 | + $thisLetter = substr($source, $pos, 4); |
|
| 623 | + $pos += 4; |
|
| 624 | + } else { |
|
| 625 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | + // 3 chars representing one unicode character |
|
| 627 | + $thisLetter = substr($source, $pos, 3); |
|
| 628 | + $pos += 3; |
|
| 629 | + } else { |
|
| 630 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | + // 2 chars representing one unicode character |
|
| 632 | + $thisLetter = substr($source, $pos, 2); |
|
| 633 | + $pos += 2; |
|
| 634 | + } else { |
|
| 635 | + // 1 char (lower ascii) |
|
| 636 | + $thisLetter = substr($source, $pos, 1); |
|
| 637 | + $pos += 1; |
|
| 638 | + $char = $thisLetter; |
|
| 639 | + $ischar = true; |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ($ischar) { |
|
| 645 | + $encodedString .= $char; |
|
| 646 | + } else { // process the string representing the letter to a unicode entity |
|
| 647 | + $thisLen = strlen($thisLetter); |
|
| 648 | + $thisPos = 0; |
|
| 649 | + $decimalCode = 0; |
|
| 650 | + while ($thisPos < $thisLen) { |
|
| 651 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | + if ($thisPos == 0) { |
|
| 653 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | + } else { |
|
| 656 | + $charNum = intval($thisCharOrd - 128); |
|
| 657 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | + } |
|
| 659 | + $thisPos++; |
|
| 660 | + } |
|
| 661 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | + $encodedString .= $encodedLetter; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $encodedString; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -682,32 +682,32 @@ discard block |
||
| 682 | 682 | **/ |
| 683 | 683 | function utf_32_to_unicode($source) { |
| 684 | 684 | |
| 685 | - // mb_string : methode rapide |
|
| 686 | - if (init_mb_string()) { |
|
| 687 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | - |
|
| 690 | - return str_replace(chr(0), '', $source); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - // Sinon methode lente |
|
| 694 | - $texte = ''; |
|
| 695 | - while ($source) { |
|
| 696 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | - $source = substr($source, 1024); |
|
| 698 | - foreach ($words as $word) { |
|
| 699 | - if ($word < 128) { |
|
| 700 | - $texte .= chr($word); |
|
| 701 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | - else { |
|
| 703 | - if ($word != 65279) { |
|
| 704 | - $texte .= '&#' . $word . ';'; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $texte; |
|
| 685 | + // mb_string : methode rapide |
|
| 686 | + if (init_mb_string()) { |
|
| 687 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | + |
|
| 690 | + return str_replace(chr(0), '', $source); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + // Sinon methode lente |
|
| 694 | + $texte = ''; |
|
| 695 | + while ($source) { |
|
| 696 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | + $source = substr($source, 1024); |
|
| 698 | + foreach ($words as $word) { |
|
| 699 | + if ($word < 128) { |
|
| 700 | + $texte .= chr($word); |
|
| 701 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | + else { |
|
| 703 | + if ($word != 65279) { |
|
| 704 | + $texte .= '&#' . $word . ';'; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $texte; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | |
@@ -724,21 +724,21 @@ discard block |
||
| 724 | 724 | * Caractère utf8 si trouvé, '' sinon |
| 725 | 725 | **/ |
| 726 | 726 | function caractere_utf_8($num) { |
| 727 | - $num = intval($num); |
|
| 728 | - if ($num < 128) { |
|
| 729 | - return chr($num); |
|
| 730 | - } |
|
| 731 | - if ($num < 2048) { |
|
| 732 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | - } |
|
| 734 | - if ($num < 65536) { |
|
| 735 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | - } |
|
| 737 | - if ($num < 1_114_112) { |
|
| 738 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - return ''; |
|
| 727 | + $num = intval($num); |
|
| 728 | + if ($num < 128) { |
|
| 729 | + return chr($num); |
|
| 730 | + } |
|
| 731 | + if ($num < 2048) { |
|
| 732 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | + } |
|
| 734 | + if ($num < 65536) { |
|
| 735 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | + } |
|
| 737 | + if ($num < 1_114_112) { |
|
| 738 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + return ''; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -751,42 +751,42 @@ discard block |
||
| 751 | 751 | **/ |
| 752 | 752 | function unicode_to_utf_8($texte) { |
| 753 | 753 | |
| 754 | - // 1. Entites € et suivantes |
|
| 755 | - $vu = []; |
|
| 756 | - if ( |
|
| 757 | - preg_match_all( |
|
| 758 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | - $texte, |
|
| 760 | - $regs, |
|
| 761 | - PREG_SET_ORDER |
|
| 762 | - ) |
|
| 763 | - ) { |
|
| 764 | - foreach ($regs as $reg) { |
|
| 765 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | - |
|
| 772 | - // 2. Entites > ÿ |
|
| 773 | - //$vu = array(); |
|
| 774 | - if ( |
|
| 775 | - preg_match_all( |
|
| 776 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | - $texte, |
|
| 778 | - $regs, |
|
| 779 | - PREG_SET_ORDER |
|
| 780 | - ) |
|
| 781 | - ) { |
|
| 782 | - foreach ($regs as $reg) { |
|
| 783 | - if (!isset($vu[$reg[0]])) { |
|
| 784 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 754 | + // 1. Entites € et suivantes |
|
| 755 | + $vu = []; |
|
| 756 | + if ( |
|
| 757 | + preg_match_all( |
|
| 758 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | + $texte, |
|
| 760 | + $regs, |
|
| 761 | + PREG_SET_ORDER |
|
| 762 | + ) |
|
| 763 | + ) { |
|
| 764 | + foreach ($regs as $reg) { |
|
| 765 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | + |
|
| 772 | + // 2. Entites > ÿ |
|
| 773 | + //$vu = array(); |
|
| 774 | + if ( |
|
| 775 | + preg_match_all( |
|
| 776 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | + $texte, |
|
| 778 | + $regs, |
|
| 779 | + PREG_SET_ORDER |
|
| 780 | + ) |
|
| 781 | + ) { |
|
| 782 | + foreach ($regs as $reg) { |
|
| 783 | + if (!isset($vu[$reg[0]])) { |
|
| 784 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -798,15 +798,15 @@ discard block |
||
| 798 | 798 | * Texte converti |
| 799 | 799 | **/ |
| 800 | 800 | function unicode_to_javascript($texte) { |
| 801 | - $vu = []; |
|
| 802 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | - $num = $regs[1]; |
|
| 804 | - $vu[$num] = true; |
|
| 805 | - $s = '\u' . sprintf('%04x', $num); |
|
| 806 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $texte; |
|
| 801 | + $vu = []; |
|
| 802 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | + $num = $regs[1]; |
|
| 804 | + $vu[$num] = true; |
|
| 805 | + $s = '\u' . sprintf('%04x', $num); |
|
| 806 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $texte; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -818,11 +818,11 @@ discard block |
||
| 818 | 818 | * Texte converti |
| 819 | 819 | **/ |
| 820 | 820 | function javascript_to_unicode($texte) { |
| 821 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | - } |
|
| 821 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - return $texte; |
|
| 825 | + return $texte; |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
@@ -834,11 +834,11 @@ discard block |
||
| 834 | 834 | * Texte converti |
| 835 | 835 | **/ |
| 836 | 836 | function javascript_to_binary($texte) { |
| 837 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | - } |
|
| 837 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | + } |
|
| 840 | 840 | |
| 841 | - return $texte; |
|
| 841 | + return $texte; |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | |
@@ -856,26 +856,26 @@ discard block |
||
| 856 | 856 | * @return string |
| 857 | 857 | */ |
| 858 | 858 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 859 | - static $trans = []; |
|
| 860 | - if ($charset == 'AUTO') { |
|
| 861 | - $charset = $GLOBALS['meta']['charset']; |
|
| 862 | - } |
|
| 863 | - if (!strlen($texte)) { |
|
| 864 | - return $texte; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $table_translit = 'translit' . $complexe; |
|
| 868 | - |
|
| 869 | - // 2. Translitterer grace a la table predefinie |
|
| 870 | - if (!isset($trans[$complexe])) { |
|
| 871 | - $trans[$complexe] = []; |
|
| 872 | - load_charset($table_translit); |
|
| 873 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 859 | + static $trans = []; |
|
| 860 | + if ($charset == 'AUTO') { |
|
| 861 | + $charset = $GLOBALS['meta']['charset']; |
|
| 862 | + } |
|
| 863 | + if (!strlen($texte)) { |
|
| 864 | + return $texte; |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $table_translit = 'translit' . $complexe; |
|
| 868 | + |
|
| 869 | + // 2. Translitterer grace a la table predefinie |
|
| 870 | + if (!isset($trans[$complexe])) { |
|
| 871 | + $trans[$complexe] = []; |
|
| 872 | + load_charset($table_translit); |
|
| 873 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
@@ -898,14 +898,14 @@ discard block |
||
| 898 | 898 | * @return string |
| 899 | 899 | */ |
| 900 | 900 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 901 | - // 0. Supprimer les caracteres illegaux |
|
| 902 | - include_spip('inc/filtres'); |
|
| 903 | - $texte = corriger_caracteres($texte); |
|
| 901 | + // 0. Supprimer les caracteres illegaux |
|
| 902 | + include_spip('inc/filtres'); |
|
| 903 | + $texte = corriger_caracteres($texte); |
|
| 904 | 904 | |
| 905 | - // 1. Passer le charset et les é en utf-8 |
|
| 906 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 905 | + // 1. Passer le charset et les é en utf-8 |
|
| 906 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 907 | 907 | |
| 908 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -920,17 +920,17 @@ discard block |
||
| 920 | 920 | * @return string |
| 921 | 921 | */ |
| 922 | 922 | function translitteration_complexe($texte, $chiffres = false) { |
| 923 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 924 | 924 | |
| 925 | - if ($chiffres) { |
|
| 926 | - $texte = preg_replace_callback( |
|
| 927 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | - $texte |
|
| 930 | - ); |
|
| 931 | - } |
|
| 925 | + if ($chiffres) { |
|
| 926 | + $texte = preg_replace_callback( |
|
| 927 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | + $texte |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return $texte; |
|
| 933 | + return $texte; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | * @return string |
| 943 | 943 | */ |
| 944 | 944 | function translitteration_chiffree($car) { |
| 945 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 945 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * true s'il a un BOM |
| 956 | 956 | **/ |
| 957 | 957 | function bom_utf8($texte) { |
| 958 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -972,21 +972,21 @@ discard block |
||
| 972 | 972 | * true si c'est le cas |
| 973 | 973 | **/ |
| 974 | 974 | function is_utf8($string) { |
| 975 | - return !strlen( |
|
| 976 | - preg_replace( |
|
| 977 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | - . ',sS', |
|
| 986 | - '', |
|
| 987 | - $string |
|
| 988 | - ) |
|
| 989 | - ); |
|
| 975 | + return !strlen( |
|
| 976 | + preg_replace( |
|
| 977 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | + . ',sS', |
|
| 986 | + '', |
|
| 987 | + $string |
|
| 988 | + ) |
|
| 989 | + ); |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -998,13 +998,13 @@ discard block |
||
| 998 | 998 | * true si c'est le cas |
| 999 | 999 | **/ |
| 1000 | 1000 | function is_ascii($string) { |
| 1001 | - return !strlen( |
|
| 1002 | - preg_replace( |
|
| 1003 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | - '', |
|
| 1005 | - $string |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1001 | + return !strlen( |
|
| 1002 | + preg_replace( |
|
| 1003 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | + '', |
|
| 1005 | + $string |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1023,53 +1023,53 @@ discard block |
||
| 1023 | 1023 | **/ |
| 1024 | 1024 | function transcoder_page($texte, $headers = '') { |
| 1025 | 1025 | |
| 1026 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | - if (is_ascii($texte)) { |
|
| 1028 | - #spip_log('charset: ascii'); |
|
| 1029 | - return $texte; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - if (bom_utf8($texte)) { |
|
| 1033 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | - $charset = 'utf-8'; |
|
| 1035 | - $texte = substr($texte, 3); |
|
| 1036 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | - // charset precise par le contenu (xml) |
|
| 1038 | - $charset = trim(strtolower($regs[1])); |
|
| 1039 | - } elseif ( |
|
| 1040 | - // charset precise par le contenu (html) |
|
| 1041 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | - and false === strpos($regs[2], '#') |
|
| 1044 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | - ) { |
|
| 1046 | - $charset = $tmp; |
|
| 1047 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | - // charset de la reponse http |
|
| 1049 | - $charset = trim(strtolower($regs[1])); |
|
| 1050 | - } else { |
|
| 1051 | - $charset = ''; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - // normaliser les noms du shif-jis japonais |
|
| 1056 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | - $charset = 'shift-jis'; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - if ($charset) { |
|
| 1061 | - spip_log("charset: $charset"); |
|
| 1062 | - } else { |
|
| 1063 | - // valeur par defaut |
|
| 1064 | - if (is_utf8($texte)) { |
|
| 1065 | - $charset = 'utf-8'; |
|
| 1066 | - } else { |
|
| 1067 | - $charset = 'iso-8859-1'; |
|
| 1068 | - } |
|
| 1069 | - spip_log("charset probable: $charset"); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return importer_charset($texte, $charset); |
|
| 1026 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | + if (is_ascii($texte)) { |
|
| 1028 | + #spip_log('charset: ascii'); |
|
| 1029 | + return $texte; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + if (bom_utf8($texte)) { |
|
| 1033 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | + $charset = 'utf-8'; |
|
| 1035 | + $texte = substr($texte, 3); |
|
| 1036 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | + // charset precise par le contenu (xml) |
|
| 1038 | + $charset = trim(strtolower($regs[1])); |
|
| 1039 | + } elseif ( |
|
| 1040 | + // charset precise par le contenu (html) |
|
| 1041 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | + and false === strpos($regs[2], '#') |
|
| 1044 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | + ) { |
|
| 1046 | + $charset = $tmp; |
|
| 1047 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | + // charset de la reponse http |
|
| 1049 | + $charset = trim(strtolower($regs[1])); |
|
| 1050 | + } else { |
|
| 1051 | + $charset = ''; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + // normaliser les noms du shif-jis japonais |
|
| 1056 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | + $charset = 'shift-jis'; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + if ($charset) { |
|
| 1061 | + spip_log("charset: $charset"); |
|
| 1062 | + } else { |
|
| 1063 | + // valeur par defaut |
|
| 1064 | + if (is_utf8($texte)) { |
|
| 1065 | + $charset = 'utf-8'; |
|
| 1066 | + } else { |
|
| 1067 | + $charset = 'iso-8859-1'; |
|
| 1068 | + } |
|
| 1069 | + spip_log("charset probable: $charset"); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return importer_charset($texte, $charset); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1093,26 +1093,26 @@ discard block |
||
| 1093 | 1093 | * Le texte coupé |
| 1094 | 1094 | **/ |
| 1095 | 1095 | function spip_substr($c, $start = 0, $length = null) { |
| 1096 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | - if ($length) { |
|
| 1099 | - return substr($c, $start, $length); |
|
| 1100 | - } else { |
|
| 1101 | - substr($c, $start); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | - if (init_mb_string()) { |
|
| 1107 | - if ($length) { |
|
| 1108 | - return mb_substr($c, $start, $length); |
|
| 1109 | - } else { |
|
| 1110 | - return mb_substr($c, $start); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - // Version manuelle (cf. ci-dessous) |
|
| 1115 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1096 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | + if ($length) { |
|
| 1099 | + return substr($c, $start, $length); |
|
| 1100 | + } else { |
|
| 1101 | + substr($c, $start); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | + if (init_mb_string()) { |
|
| 1107 | + if ($length) { |
|
| 1108 | + return mb_substr($c, $start, $length); |
|
| 1109 | + } else { |
|
| 1110 | + return mb_substr($c, $start); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + // Version manuelle (cf. ci-dessous) |
|
| 1115 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | |
@@ -1131,40 +1131,40 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1133 | 1133 | |
| 1134 | - // Cas pathologique |
|
| 1135 | - if ($length === 0) { |
|
| 1136 | - return ''; |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - // S'il y a un demarrage, on se positionne |
|
| 1140 | - if ($start > 0) { |
|
| 1141 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | - } elseif ($start < 0) { |
|
| 1143 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if (!$length) { |
|
| 1147 | - return $c; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - if ($length > 0) { |
|
| 1151 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | - $n = 0; |
|
| 1154 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | - ; |
|
| 1156 | - } |
|
| 1157 | - $c = substr($c, 0, $n * $length); |
|
| 1158 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | - $c = substr($c, 0, $length - $l); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - return $c; |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - // $length < 0 |
|
| 1167 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1134 | + // Cas pathologique |
|
| 1135 | + if ($length === 0) { |
|
| 1136 | + return ''; |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + // S'il y a un demarrage, on se positionne |
|
| 1140 | + if ($start > 0) { |
|
| 1141 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | + } elseif ($start < 0) { |
|
| 1143 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if (!$length) { |
|
| 1147 | + return $c; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + if ($length > 0) { |
|
| 1151 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | + $n = 0; |
|
| 1154 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | + ; |
|
| 1156 | + } |
|
| 1157 | + $c = substr($c, 0, $n * $length); |
|
| 1158 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | + $c = substr($c, 0, $length - $l); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + return $c; |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + // $length < 0 |
|
| 1167 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | /** |
@@ -1178,14 +1178,14 @@ discard block |
||
| 1178 | 1178 | * La chaîne avec une majuscule sur le premier mot |
| 1179 | 1179 | */ |
| 1180 | 1180 | function spip_ucfirst($c) { |
| 1181 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | - return ucfirst($c); |
|
| 1184 | - } |
|
| 1181 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | + return ucfirst($c); |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1186 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1187 | 1187 | |
| 1188 | - return $lettre1 . spip_substr($c, 1); |
|
| 1188 | + return $lettre1 . spip_substr($c, 1); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | /** |
@@ -1199,12 +1199,12 @@ discard block |
||
| 1199 | 1199 | * La chaîne en minuscules |
| 1200 | 1200 | */ |
| 1201 | 1201 | function spip_strtolower($c) { |
| 1202 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | - return strtolower($c); |
|
| 1205 | - } |
|
| 1202 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | + return strtolower($c); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | - return mb_strtolower($c); |
|
| 1207 | + return mb_strtolower($c); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
@@ -1218,23 +1218,23 @@ discard block |
||
| 1218 | 1218 | * Longueur de la chaîne |
| 1219 | 1219 | */ |
| 1220 | 1220 | function spip_strlen($c) { |
| 1221 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | - |
|
| 1224 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | - return strlen($c); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | - if (init_mb_string()) { |
|
| 1231 | - return mb_strlen($c); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | - // de caracteres utf-8 (11......) |
|
| 1237 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1221 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | + |
|
| 1224 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | + return strlen($c); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | + if (init_mb_string()) { |
|
| 1231 | + return mb_strlen($c); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | + // de caracteres utf-8 (11......) |
|
| 1237 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // Initialisation |
@@ -1244,16 +1244,16 @@ discard block |
||
| 1244 | 1244 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1245 | 1245 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1246 | 1246 | if ( |
| 1247 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1247 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1249 | 1249 | ) { |
| 1250 | - include_spip('inc/meta'); |
|
| 1251 | - ecrire_meta( |
|
| 1252 | - 'pcre_u', |
|
| 1253 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | - and test_pcre_unicode()) |
|
| 1255 | - ? 'u' : '' |
|
| 1256 | - ); |
|
| 1250 | + include_spip('inc/meta'); |
|
| 1251 | + ecrire_meta( |
|
| 1252 | + 'pcre_u', |
|
| 1253 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | + and test_pcre_unicode()) |
|
| 1255 | + ? 'u' : '' |
|
| 1256 | + ); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1269,17 +1269,17 @@ discard block |
||
| 1269 | 1269 | * en unicode : 💩 |
| 1270 | 1270 | */ |
| 1271 | 1271 | function utf8_noplanes($x) { |
| 1272 | - $regexp_utf8_4bytes = '/( |
|
| 1272 | + $regexp_utf8_4bytes = '/( |
|
| 1273 | 1273 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1274 | 1274 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1275 | 1275 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1276 | 1276 | )/xS'; |
| 1277 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | - foreach ($z[0] as $k) { |
|
| 1279 | - $ku = utf_8_to_unicode($k); |
|
| 1280 | - $x = str_replace($k, $ku, $x); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - return $x; |
|
| 1277 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | + foreach ($z[0] as $k) { |
|
| 1279 | + $ku = utf_8_to_unicode($k); |
|
| 1280 | + $x = str_replace($k, $ku, $x); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + return $x; |
|
| 1285 | 1285 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 31 | - return; |
|
| 31 | + return; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -48,55 +48,55 @@ discard block |
||
| 48 | 48 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 49 | 49 | **/ |
| 50 | 50 | function roles_presents($objet, $objet_destination = '') { |
| 51 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | - |
|
| 53 | - // pas de liste de roles, on sort |
|
| 54 | - if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // on vérifie que la table de liaison existe |
|
| 59 | - include_spip('action/editer_liens'); |
|
| 60 | - if (!$lien = objet_associable($objet)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | - [, $table_lien] = $lien; |
|
| 68 | - $desc_lien = $trouver_table($table_lien); |
|
| 69 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | - if (!$application = $desc['roles_objets']) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // destination presente, on restreint si possible |
|
| 79 | - if ($objet_destination) { |
|
| 80 | - $objet_destination = table_objet($objet_destination); |
|
| 81 | - |
|
| 82 | - // pour l'objet |
|
| 83 | - if (isset($application[$objet_destination])) { |
|
| 84 | - $application = $application[$objet_destination]; |
|
| 85 | - // sinon pour tous les objets |
|
| 86 | - } elseif (isset($application['*'])) { |
|
| 87 | - $application = $application['*']; |
|
| 88 | - } // sinon tant pis |
|
| 89 | - else { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // tout est ok |
|
| 95 | - return [ |
|
| 96 | - 'titres' => $titres, |
|
| 97 | - 'roles' => $application, |
|
| 98 | - 'colonne' => $colonne |
|
| 99 | - ]; |
|
| 51 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | + |
|
| 53 | + // pas de liste de roles, on sort |
|
| 54 | + if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // on vérifie que la table de liaison existe |
|
| 59 | + include_spip('action/editer_liens'); |
|
| 60 | + if (!$lien = objet_associable($objet)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | + [, $table_lien] = $lien; |
|
| 68 | + $desc_lien = $trouver_table($table_lien); |
|
| 69 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | + if (!$application = $desc['roles_objets']) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // destination presente, on restreint si possible |
|
| 79 | + if ($objet_destination) { |
|
| 80 | + $objet_destination = table_objet($objet_destination); |
|
| 81 | + |
|
| 82 | + // pour l'objet |
|
| 83 | + if (isset($application[$objet_destination])) { |
|
| 84 | + $application = $application[$objet_destination]; |
|
| 85 | + // sinon pour tous les objets |
|
| 86 | + } elseif (isset($application['*'])) { |
|
| 87 | + $application = $application['*']; |
|
| 88 | + } // sinon tant pis |
|
| 89 | + else { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // tout est ok |
|
| 95 | + return [ |
|
| 96 | + 'titres' => $titres, |
|
| 97 | + 'roles' => $application, |
|
| 98 | + 'colonne' => $colonne |
|
| 99 | + ]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * Nom de la colonne, sinon vide |
| 111 | 111 | **/ |
| 112 | 112 | function roles_colonne($objet, $objet_destination) { |
| 113 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | - return $roles['colonne']; |
|
| 115 | - } |
|
| 113 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | + return $roles['colonne']; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return ''; |
|
| 117 | + return ''; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -136,24 +136,24 @@ discard block |
||
| 136 | 136 | * Liste ('', '', array()) sinon. |
| 137 | 137 | **/ |
| 138 | 138 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 139 | - // si des rôles sont possibles, on les utilise |
|
| 140 | - $role = $colonne_role = ''; # role défini |
|
| 141 | - // condition du where par defaut |
|
| 142 | - $cond = []; |
|
| 143 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | - $colonne_role = $roles['colonne']; |
|
| 145 | - // qu'il n'est pas défini |
|
| 146 | - if ( |
|
| 147 | - !isset($qualif[$colonne_role]) |
|
| 148 | - or !($role = $qualif[$colonne_role]) |
|
| 149 | - ) { |
|
| 150 | - $role = $roles['roles']['defaut']; |
|
| 151 | - } |
|
| 152 | - // where |
|
| 153 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return [$role, $colonne_role, $cond]; |
|
| 139 | + // si des rôles sont possibles, on les utilise |
|
| 140 | + $role = $colonne_role = ''; # role défini |
|
| 141 | + // condition du where par defaut |
|
| 142 | + $cond = []; |
|
| 143 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | + $colonne_role = $roles['colonne']; |
|
| 145 | + // qu'il n'est pas défini |
|
| 146 | + if ( |
|
| 147 | + !isset($qualif[$colonne_role]) |
|
| 148 | + or !($role = $qualif[$colonne_role]) |
|
| 149 | + ) { |
|
| 150 | + $role = $roles['roles']['defaut']; |
|
| 151 | + } |
|
| 152 | + // where |
|
| 153 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return [$role, $colonne_role, $cond]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -175,21 +175,21 @@ discard block |
||
| 175 | 175 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 176 | 176 | **/ |
| 177 | 177 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 178 | - // role par défaut, colonne |
|
| 179 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 178 | + // role par défaut, colonne |
|
| 179 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 180 | 180 | |
| 181 | - // chercher d'eventuels rôles transmis |
|
| 182 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | - unset($cond['role']); // cette condition est particuliere... |
|
| 181 | + // chercher d'eventuels rôles transmis |
|
| 182 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | + unset($cond['role']); // cette condition est particuliere... |
|
| 184 | 184 | |
| 185 | - if ($colonne_role) { |
|
| 186 | - // on ajoute la condition du role aux autres conditions. |
|
| 187 | - if ($role != '*') { |
|
| 188 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | - } |
|
| 190 | - } |
|
| 185 | + if ($colonne_role) { |
|
| 186 | + // on ajoute la condition du role aux autres conditions. |
|
| 187 | + if ($role != '*') { |
|
| 188 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - return [$cond, $colonne_role, $role]; |
|
| 192 | + return [$cond, $colonne_role, $role]; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -211,28 +211,28 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 213 | 213 | |
| 214 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | - if ($presents === false) { |
|
| 217 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // types de roles possibles |
|
| 221 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | - // couples id / roles |
|
| 223 | - $ids = $presents['ids']; |
|
| 224 | - |
|
| 225 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | - // n'est pas complet |
|
| 228 | - $complets = []; |
|
| 229 | - foreach ($ids as $id => $roles_presents) { |
|
| 230 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | - $complets[] = $id; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $complets; |
|
| 214 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | + if ($presents === false) { |
|
| 217 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // types de roles possibles |
|
| 221 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | + // couples id / roles |
|
| 223 | + $ids = $presents['ids']; |
|
| 224 | + |
|
| 225 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | + // n'est pas complet |
|
| 228 | + $complets = []; |
|
| 229 | + foreach ($ids as $id => $roles_presents) { |
|
| 230 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | + $complets[] = $id; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $complets; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 251 | 251 | |
| 252 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | - if ($presents === false) { |
|
| 255 | - return []; |
|
| 256 | - } |
|
| 252 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | + if ($presents === false) { |
|
| 255 | + return []; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | - return []; |
|
| 260 | - } |
|
| 258 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | + return []; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return $presents['ids'][$id_objet_source]; |
|
| 262 | + return $presents['ids'][$id_objet_source]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -287,47 +287,47 @@ discard block |
||
| 287 | 287 | * - False si pas de role déclarés |
| 288 | 288 | */ |
| 289 | 289 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 290 | - static $done = []; |
|
| 291 | - |
|
| 292 | - // stocker le résultat |
|
| 293 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | - if (isset($done[$hash])) { |
|
| 295 | - return $done[$hash]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // pas de roles sur ces objets, on sort |
|
| 299 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | - if (!$roles) { |
|
| 301 | - return $done[$hash] = false; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // inspiré de lister_objets_lies() |
|
| 305 | - if ($objet_lien == $objet) { |
|
| 306 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | - } else { |
|
| 308 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // types de roles possibles |
|
| 312 | - $roles_possibles = $roles['roles']['choix']; |
|
| 313 | - // colonne du role |
|
| 314 | - $colonne = $roles['colonne']; |
|
| 315 | - |
|
| 316 | - // on recupere par id, et role existant |
|
| 317 | - $ids = []; |
|
| 318 | - while ($row = array_shift($res)) { |
|
| 319 | - $id = $row[$objet_source]; |
|
| 320 | - if (!isset($ids[$id])) { |
|
| 321 | - $ids[$id] = []; |
|
| 322 | - } |
|
| 323 | - // tableau des roles présents |
|
| 324 | - $ids[$id][] = $row[$colonne]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $done[$hash] = [ |
|
| 328 | - 'roles' => $roles, |
|
| 329 | - 'ids' => $ids |
|
| 330 | - ]; |
|
| 290 | + static $done = []; |
|
| 291 | + |
|
| 292 | + // stocker le résultat |
|
| 293 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | + if (isset($done[$hash])) { |
|
| 295 | + return $done[$hash]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // pas de roles sur ces objets, on sort |
|
| 299 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | + if (!$roles) { |
|
| 301 | + return $done[$hash] = false; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // inspiré de lister_objets_lies() |
|
| 305 | + if ($objet_lien == $objet) { |
|
| 306 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | + } else { |
|
| 308 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // types de roles possibles |
|
| 312 | + $roles_possibles = $roles['roles']['choix']; |
|
| 313 | + // colonne du role |
|
| 314 | + $colonne = $roles['colonne']; |
|
| 315 | + |
|
| 316 | + // on recupere par id, et role existant |
|
| 317 | + $ids = []; |
|
| 318 | + while ($row = array_shift($res)) { |
|
| 319 | + $id = $row[$objet_source]; |
|
| 320 | + if (!isset($ids[$id])) { |
|
| 321 | + $ids[$id] = []; |
|
| 322 | + } |
|
| 323 | + // tableau des roles présents |
|
| 324 | + $ids[$id][] = $row[$colonne]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $done[$hash] = [ |
|
| 328 | + 'roles' => $roles, |
|
| 329 | + 'ids' => $ids |
|
| 330 | + ]; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -345,33 +345,33 @@ discard block |
||
| 345 | 345 | * - false si pas de role déclarés |
| 346 | 346 | */ |
| 347 | 347 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 348 | - static $done = []; |
|
| 349 | - |
|
| 350 | - // stocker le résultat |
|
| 351 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | - if (isset($done[$hash])) { |
|
| 353 | - return $done[$hash]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | - return $done[$hash] = false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // pas de roles sur ces objets, on sort |
|
| 361 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | - if (!$roles) { |
|
| 363 | - return $done[$hash] = false; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - [$primary, $l] = $lien; |
|
| 367 | - $colone_role = $roles['colonne']; |
|
| 368 | - |
|
| 369 | - $all = sql_allfetsel( |
|
| 370 | - "DISTINCT $colone_role", |
|
| 371 | - $l, |
|
| 372 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | - ); |
|
| 374 | - $done[$hash] = array_map('reset', $all); |
|
| 375 | - |
|
| 376 | - return $done[$hash]; |
|
| 348 | + static $done = []; |
|
| 349 | + |
|
| 350 | + // stocker le résultat |
|
| 351 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | + if (isset($done[$hash])) { |
|
| 353 | + return $done[$hash]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | + return $done[$hash] = false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // pas de roles sur ces objets, on sort |
|
| 361 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | + if (!$roles) { |
|
| 363 | + return $done[$hash] = false; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + [$primary, $l] = $lien; |
|
| 367 | + $colone_role = $roles['colonne']; |
|
| 368 | + |
|
| 369 | + $all = sql_allfetsel( |
|
| 370 | + "DISTINCT $colone_role", |
|
| 371 | + $l, |
|
| 372 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | + ); |
|
| 374 | + $done[$hash] = array_map('reset', $all); |
|
| 375 | + |
|
| 376 | + return $done[$hash]; |
|
| 377 | 377 | } |
@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - [$primary, $table_liens] = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - [$primary, $table_liens] = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + [$primary, $table_liens] = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + [$primary, $table_liens] = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,39 +415,39 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (!$t) { |
|
| 431 | - return strval($t); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | - // avant echappement des balises <html> |
|
| 436 | - // https://core.spip.net/issues/3371 |
|
| 437 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | - // https://core.spip.net/issues/4166 |
|
| 439 | - if ( |
|
| 440 | - $interdire_script |
|
| 441 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - ) { |
|
| 445 | - $t = echapper_html_suspect($t, false); |
|
| 446 | - } |
|
| 447 | - $t = echappe_html($t); |
|
| 448 | - $t = expanser_liens($t, $connect, $env); |
|
| 449 | - $t = traiter_raccourcis($t); |
|
| 450 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | - |
|
| 452 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (!$t) { |
|
| 431 | + return strval($t); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | + // avant echappement des balises <html> |
|
| 436 | + // https://core.spip.net/issues/3371 |
|
| 437 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | + // https://core.spip.net/issues/4166 |
|
| 439 | + if ( |
|
| 440 | + $interdire_script |
|
| 441 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + ) { |
|
| 445 | + $t = echapper_html_suspect($t, false); |
|
| 446 | + } |
|
| 447 | + $t = echappe_html($t); |
|
| 448 | + $t = expanser_liens($t, $connect, $env); |
|
| 449 | + $t = traiter_raccourcis($t); |
|
| 450 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | + |
|
| 452 | + return $t; |
|
| 453 | 453 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,55 +198,55 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 206 | 206 | |
| 207 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | - $types = [ |
|
| 209 | - 'notice', |
|
| 210 | - 'error', |
|
| 211 | - 'success', |
|
| 212 | - 'info', |
|
| 213 | - ]; |
|
| 214 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | - $type = reset($type); |
|
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 207 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | + $types = [ |
|
| 209 | + 'notice', |
|
| 210 | + 'error', |
|
| 211 | + 'success', |
|
| 212 | + 'info', |
|
| 213 | + ]; |
|
| 214 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | + $type = reset($type); |
|
| 216 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 217 | 217 | |
| 218 | - // Classes |
|
| 219 | - $class_racine = 'msg-alert'; |
|
| 220 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | - $class_alerte = "$class_racine $class"; |
|
| 222 | - $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | - $class_titre = "${class_racine}__heading"; |
|
| 218 | + // Classes |
|
| 219 | + $class_racine = 'msg-alert'; |
|
| 220 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | + $class_alerte = "$class_racine $class"; |
|
| 222 | + $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | + $class_titre = "${class_racine}__heading"; |
|
| 224 | 224 | |
| 225 | - // Titre : markup |
|
| 226 | - $titre = trim($titre); |
|
| 227 | - if (strlen($titre)) { |
|
| 228 | - include_spip('inc/filtres'); |
|
| 229 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | - $titre = wrap($titre, $wrap_tag); |
|
| 234 | - } |
|
| 235 | - // puis on ajoute la classe |
|
| 236 | - $titre = ajouter_class($titre, $class_titre); |
|
| 237 | - } |
|
| 225 | + // Titre : markup |
|
| 226 | + $titre = trim($titre); |
|
| 227 | + if (strlen($titre)) { |
|
| 228 | + include_spip('inc/filtres'); |
|
| 229 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | + $titre = wrap($titre, $wrap_tag); |
|
| 234 | + } |
|
| 235 | + // puis on ajoute la classe |
|
| 236 | + $titre = ajouter_class($titre, $class_titre); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - // Attributs |
|
| 240 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 239 | + // Attributs |
|
| 240 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 243 | 243 | |
| 244 | - $message = |
|
| 245 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | - . $titre |
|
| 247 | - . "<div class=\"$class_texte\">"; |
|
| 244 | + $message = |
|
| 245 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | + . $titre |
|
| 247 | + . "<div class=\"$class_texte\">"; |
|
| 248 | 248 | |
| 249 | - return $message; |
|
| 249 | + return $message; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -260,5 +260,5 @@ discard block |
||
| 260 | 260 | * HTML de fin de l'alerte |
| 261 | 261 | */ |
| 262 | 262 | function message_alerte_fermer(): string { |
| 263 | - return '</div></div>'; |
|
| 263 | + return '</div></div>'; |
|
| 264 | 264 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base${subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base${subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = "^$dir"; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = "^$dir"; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | * Date au format SQL tel que `2008-04-01` |
| 37 | 37 | **/ |
| 38 | 38 | function extraire_date($texte) { |
| 39 | - // format = 2001-08 |
|
| 40 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | - } |
|
| 39 | + // format = 2001-08 |
|
| 40 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -61,29 +61,29 @@ discard block |
||
| 61 | 61 | * - une chaîne vide si la date est considérée nulle |
| 62 | 62 | **/ |
| 63 | 63 | function normaliser_date($date, $forcer_jour = false) { |
| 64 | - $date = vider_date($date); |
|
| 65 | - if ($date) { |
|
| 66 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 67 | - $date = date('Y-m-d H:i:s', $date); |
|
| 68 | - } |
|
| 69 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 70 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 71 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 72 | - } else { |
|
| 73 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 74 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 75 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 76 | - } else { |
|
| 77 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ($forcer_jour) { |
|
| 82 | - $date = str_replace('-00', '-01', $date); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $date; |
|
| 64 | + $date = vider_date($date); |
|
| 65 | + if ($date) { |
|
| 66 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 67 | + $date = date('Y-m-d H:i:s', $date); |
|
| 68 | + } |
|
| 69 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 70 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 71 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 72 | + } else { |
|
| 73 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 74 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 75 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 76 | + } else { |
|
| 77 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ($forcer_jour) { |
|
| 82 | + $date = str_replace('-00', '-01', $date); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $date; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,22 +96,22 @@ discard block |
||
| 96 | 96 | * - Une chaine vide |
| 97 | 97 | **/ |
| 98 | 98 | function vider_date($letexte, $verif_format_date = false) { |
| 99 | - if ( |
|
| 100 | - !$verif_format_date |
|
| 101 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 102 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 103 | - ) { |
|
| 104 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 105 | - return ''; |
|
| 106 | - } |
|
| 107 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } // eviter le bug GMT-1 |
|
| 113 | - } |
|
| 114 | - return $letexte; |
|
| 99 | + if ( |
|
| 100 | + !$verif_format_date |
|
| 101 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 102 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 103 | + ) { |
|
| 104 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 105 | + return ''; |
|
| 106 | + } |
|
| 107 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } // eviter le bug GMT-1 |
|
| 113 | + } |
|
| 114 | + return $letexte; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | **/ |
| 128 | 128 | function recup_heure($date) { |
| 129 | 129 | |
| 130 | - static $d = [0, 0, 0]; |
|
| 131 | - if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) { |
|
| 132 | - return $d; |
|
| 133 | - } |
|
| 130 | + static $d = [0, 0, 0]; |
|
| 131 | + if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) { |
|
| 132 | + return $d; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - array_shift($r); |
|
| 135 | + array_shift($r); |
|
| 136 | 136 | |
| 137 | - return $r; |
|
| 137 | + return $r; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | * @return int heures, sinon 0 |
| 149 | 149 | **/ |
| 150 | 150 | function heures($numdate) { |
| 151 | - $heures = null; |
|
| 152 | - $date_array = recup_heure($numdate); |
|
| 153 | - if ($date_array) { |
|
| 154 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 155 | - } |
|
| 151 | + $heures = null; |
|
| 152 | + $date_array = recup_heure($numdate); |
|
| 153 | + if ($date_array) { |
|
| 154 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - return $heures; |
|
| 157 | + return $heures; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -168,13 +168,13 @@ discard block |
||
| 168 | 168 | * @return int minutes, sinon 0 |
| 169 | 169 | **/ |
| 170 | 170 | function minutes($numdate) { |
| 171 | - $minutes = null; |
|
| 172 | - $date_array = recup_heure($numdate); |
|
| 173 | - if ($date_array) { |
|
| 174 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 175 | - } |
|
| 171 | + $minutes = null; |
|
| 172 | + $date_array = recup_heure($numdate); |
|
| 173 | + if ($date_array) { |
|
| 174 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - return $minutes; |
|
| 177 | + return $minutes; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | * @return int secondes, sinon 0 |
| 189 | 189 | **/ |
| 190 | 190 | function secondes($numdate) { |
| 191 | - $secondes = null; |
|
| 192 | - $date_array = recup_heure($numdate); |
|
| 193 | - if ($date_array) { |
|
| 194 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 195 | - } |
|
| 191 | + $secondes = null; |
|
| 192 | + $date_array = recup_heure($numdate); |
|
| 193 | + if ($date_array) { |
|
| 194 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $secondes; |
|
| 197 | + return $secondes; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -213,12 +213,12 @@ discard block |
||
| 213 | 213 | * @return string L'heure formatée dans la langue en cours. |
| 214 | 214 | **/ |
| 215 | 215 | function heures_minutes($numdate, $forme = '') { |
| 216 | - if ($forme != 'abbr') { |
|
| 217 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 218 | - } |
|
| 219 | - else { |
|
| 220 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 221 | - } |
|
| 216 | + if ($forme != 'abbr') { |
|
| 217 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 218 | + } |
|
| 219 | + else { |
|
| 220 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 221 | + } |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -243,56 +243,56 @@ discard block |
||
| 243 | 243 | * @return array [année, mois, jour, heures, minutes, secondes] |
| 244 | 244 | **/ |
| 245 | 245 | function recup_date($numdate, $forcer_jour = true) { |
| 246 | - if (!$numdate) { |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - $heures = $minutes = $secondes = 0; |
|
| 250 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 251 | - $jour = $regs[1]; |
|
| 252 | - $mois = $regs[2]; |
|
| 253 | - $annee = $regs[3]; |
|
| 254 | - if ($annee < 90) { |
|
| 255 | - $annee = 2000 + $annee; |
|
| 256 | - } elseif ($annee < 100) { |
|
| 257 | - $annee = 1900 + $annee; |
|
| 258 | - } |
|
| 259 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 260 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 261 | - $annee = $regs[1]; |
|
| 262 | - $mois = $regs[2]; |
|
| 263 | - $jour = $regs[3]; |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = ''; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = $regs[3]; |
|
| 274 | - $heures = $regs[4]; |
|
| 275 | - $minutes = $regs[5]; |
|
| 276 | - $secondes = $regs[6]; |
|
| 277 | - } else { |
|
| 278 | - $annee = $mois = $jour = ''; |
|
| 279 | - } |
|
| 280 | - if ($annee > 4000) { |
|
| 281 | - $annee -= 9000; |
|
| 282 | - } |
|
| 283 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 284 | - $jour = substr($jour, 1); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if ($forcer_jour and $jour == '0') { |
|
| 288 | - $jour = '1'; |
|
| 289 | - } |
|
| 290 | - if ($forcer_jour and $mois == '0') { |
|
| 291 | - $mois = '1'; |
|
| 292 | - } |
|
| 293 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 294 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 295 | - } |
|
| 246 | + if (!$numdate) { |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + $heures = $minutes = $secondes = 0; |
|
| 250 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 251 | + $jour = $regs[1]; |
|
| 252 | + $mois = $regs[2]; |
|
| 253 | + $annee = $regs[3]; |
|
| 254 | + if ($annee < 90) { |
|
| 255 | + $annee = 2000 + $annee; |
|
| 256 | + } elseif ($annee < 100) { |
|
| 257 | + $annee = 1900 + $annee; |
|
| 258 | + } |
|
| 259 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 260 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 261 | + $annee = $regs[1]; |
|
| 262 | + $mois = $regs[2]; |
|
| 263 | + $jour = $regs[3]; |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = ''; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = $regs[3]; |
|
| 274 | + $heures = $regs[4]; |
|
| 275 | + $minutes = $regs[5]; |
|
| 276 | + $secondes = $regs[6]; |
|
| 277 | + } else { |
|
| 278 | + $annee = $mois = $jour = ''; |
|
| 279 | + } |
|
| 280 | + if ($annee > 4000) { |
|
| 281 | + $annee -= 9000; |
|
| 282 | + } |
|
| 283 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 284 | + $jour = substr($jour, 1); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if ($forcer_jour and $jour == '0') { |
|
| 288 | + $jour = '1'; |
|
| 289 | + } |
|
| 290 | + if ($forcer_jour and $mois == '0') { |
|
| 291 | + $mois = '1'; |
|
| 292 | + } |
|
| 293 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 294 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 295 | + } |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | * La date relative ou complète |
| 320 | 320 | **/ |
| 321 | 321 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */) { |
| 322 | - return sinon( |
|
| 323 | - date_relative($date, $decalage_maxi), |
|
| 324 | - affdate_heure($date) |
|
| 325 | - ); |
|
| 322 | + return sinon( |
|
| 323 | + date_relative($date, $decalage_maxi), |
|
| 324 | + affdate_heure($date) |
|
| 325 | + ); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -355,85 +355,85 @@ discard block |
||
| 355 | 355 | **/ |
| 356 | 356 | function date_relative($date, $decalage_maxi = 0, $ref_date = null) { |
| 357 | 357 | |
| 358 | - if (is_null($ref_date)) { |
|
| 359 | - $ref_time = time(); |
|
| 360 | - } else { |
|
| 361 | - $ref_time = strtotime($ref_date); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!$date) { |
|
| 365 | - return; |
|
| 366 | - } |
|
| 367 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 368 | - |
|
| 369 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 370 | - return ''; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if ($decal < 0) { |
|
| 374 | - $il_y_a = 'date_dans'; |
|
| 375 | - $decal = -1 * $decal; |
|
| 376 | - } else { |
|
| 377 | - $il_y_a = 'date_il_y_a'; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 381 | - return affdate_court($date); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ($decal > 3600 * 24 * 30) { |
|
| 385 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 386 | - if ($mois < 2) { |
|
| 387 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 388 | - } else { |
|
| 389 | - $delai = "$mois " . _T('date_mois'); |
|
| 390 | - } |
|
| 391 | - } else { |
|
| 392 | - if ($decal > 3600 * 24 * 7) { |
|
| 393 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 394 | - if ($semaines < 2) { |
|
| 395 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 396 | - } else { |
|
| 397 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 398 | - } |
|
| 399 | - } else { |
|
| 400 | - if ($decal > 3600 * 24) { |
|
| 401 | - $jours = floor($decal / (3600 * 24)); |
|
| 402 | - if ($jours < 2) { |
|
| 403 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 404 | - } else { |
|
| 405 | - $delai = "$jours " . _T('date_jours'); |
|
| 406 | - } |
|
| 407 | - } else { |
|
| 408 | - if ($decal >= 3600) { |
|
| 409 | - $heures = floor($decal / 3600); |
|
| 410 | - if ($heures < 2) { |
|
| 411 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 412 | - } else { |
|
| 413 | - $delai = "$heures " . _T('date_heures'); |
|
| 414 | - } |
|
| 415 | - } else { |
|
| 416 | - if ($decal >= 60) { |
|
| 417 | - $minutes = floor($decal / 60); |
|
| 418 | - if ($minutes < 2) { |
|
| 419 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 420 | - } else { |
|
| 421 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 422 | - } |
|
| 423 | - } else { |
|
| 424 | - $secondes = ceil($decal); |
|
| 425 | - if ($secondes < 2) { |
|
| 426 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 358 | + if (is_null($ref_date)) { |
|
| 359 | + $ref_time = time(); |
|
| 360 | + } else { |
|
| 361 | + $ref_time = strtotime($ref_date); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!$date) { |
|
| 365 | + return; |
|
| 366 | + } |
|
| 367 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 368 | + |
|
| 369 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 370 | + return ''; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if ($decal < 0) { |
|
| 374 | + $il_y_a = 'date_dans'; |
|
| 375 | + $decal = -1 * $decal; |
|
| 376 | + } else { |
|
| 377 | + $il_y_a = 'date_il_y_a'; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 381 | + return affdate_court($date); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ($decal > 3600 * 24 * 30) { |
|
| 385 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 386 | + if ($mois < 2) { |
|
| 387 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 388 | + } else { |
|
| 389 | + $delai = "$mois " . _T('date_mois'); |
|
| 390 | + } |
|
| 391 | + } else { |
|
| 392 | + if ($decal > 3600 * 24 * 7) { |
|
| 393 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 394 | + if ($semaines < 2) { |
|
| 395 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 396 | + } else { |
|
| 397 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 398 | + } |
|
| 399 | + } else { |
|
| 400 | + if ($decal > 3600 * 24) { |
|
| 401 | + $jours = floor($decal / (3600 * 24)); |
|
| 402 | + if ($jours < 2) { |
|
| 403 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 404 | + } else { |
|
| 405 | + $delai = "$jours " . _T('date_jours'); |
|
| 406 | + } |
|
| 407 | + } else { |
|
| 408 | + if ($decal >= 3600) { |
|
| 409 | + $heures = floor($decal / 3600); |
|
| 410 | + if ($heures < 2) { |
|
| 411 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 412 | + } else { |
|
| 413 | + $delai = "$heures " . _T('date_heures'); |
|
| 414 | + } |
|
| 415 | + } else { |
|
| 416 | + if ($decal >= 60) { |
|
| 417 | + $minutes = floor($decal / 60); |
|
| 418 | + if ($minutes < 2) { |
|
| 419 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 420 | + } else { |
|
| 421 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 422 | + } |
|
| 423 | + } else { |
|
| 424 | + $secondes = ceil($decal); |
|
| 425 | + if ($secondes < 2) { |
|
| 426 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -459,32 +459,32 @@ discard block |
||
| 459 | 459 | **/ |
| 460 | 460 | function date_relativecourt($date, $decalage_maxi = 0) { |
| 461 | 461 | |
| 462 | - if (!$date) { |
|
| 463 | - return; |
|
| 464 | - } |
|
| 465 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 466 | - |
|
| 467 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 468 | - return ''; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($decal < -24 * 3600) { |
|
| 472 | - $retour = date_relative($date, $decalage_maxi); |
|
| 473 | - } elseif ($decal < 0) { |
|
| 474 | - $retour = _T('date_demain'); |
|
| 475 | - } else { |
|
| 476 | - if ($decal < (3600 * 24)) { |
|
| 477 | - $retour = _T('date_aujourdhui'); |
|
| 478 | - } else { |
|
| 479 | - if ($decal < (3600 * 24 * 2)) { |
|
| 480 | - $retour = _T('date_hier'); |
|
| 481 | - } else { |
|
| 482 | - $retour = date_relative($date, $decalage_maxi); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $retour; |
|
| 462 | + if (!$date) { |
|
| 463 | + return; |
|
| 464 | + } |
|
| 465 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 466 | + |
|
| 467 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 468 | + return ''; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($decal < -24 * 3600) { |
|
| 472 | + $retour = date_relative($date, $decalage_maxi); |
|
| 473 | + } elseif ($decal < 0) { |
|
| 474 | + $retour = _T('date_demain'); |
|
| 475 | + } else { |
|
| 476 | + if ($decal < (3600 * 24)) { |
|
| 477 | + $retour = _T('date_aujourdhui'); |
|
| 478 | + } else { |
|
| 479 | + if ($decal < (3600 * 24 * 2)) { |
|
| 480 | + $retour = _T('date_hier'); |
|
| 481 | + } else { |
|
| 482 | + $retour = date_relative($date, $decalage_maxi); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $retour; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -503,174 +503,174 @@ discard block |
||
| 503 | 503 | * @return mixed|string |
| 504 | 504 | */ |
| 505 | 505 | function affdate_base($numdate, $vue, $options = []) { |
| 506 | - if (is_string($options)) { |
|
| 507 | - $options = ['param' => $options]; |
|
| 508 | - } |
|
| 509 | - $date_array = recup_date($numdate, false); |
|
| 510 | - if (!$date_array) { |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 514 | - |
|
| 515 | - // 1er, 21st, etc. |
|
| 516 | - $journum = $jour; |
|
| 517 | - |
|
| 518 | - if ($jour == 0) { |
|
| 519 | - $jour = ''; |
|
| 520 | - $njour = 0; |
|
| 521 | - } else { |
|
| 522 | - $njour = intval($jour); |
|
| 523 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 524 | - $jour = $jourth; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $mois = intval($mois); |
|
| 529 | - if ($mois > 0 and $mois < 13) { |
|
| 530 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 531 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 532 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | - if ($jour) { |
|
| 534 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 535 | - } else { |
|
| 536 | - $jourmois = $nommois; |
|
| 537 | - } |
|
| 538 | - } else { |
|
| 539 | - $nommois = ''; |
|
| 540 | - $jourmois = ''; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ($annee < 0) { |
|
| 544 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 545 | - $avjc = true; |
|
| 546 | - } else { |
|
| 547 | - $avjc = false; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - switch ($vue) { |
|
| 551 | - case 'saison': |
|
| 552 | - case 'saison_annee': |
|
| 553 | - $saison = ''; |
|
| 554 | - if ($mois > 0) { |
|
| 555 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 556 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 557 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 558 | - } |
|
| 559 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 561 | - } |
|
| 562 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 563 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 564 | - } |
|
| 565 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 566 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - if ($vue == 'saison') { |
|
| 570 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 571 | - } else { |
|
| 572 | - return $saison ? trim(_T( |
|
| 573 | - 'date_fmt_saison_annee', |
|
| 574 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 575 | - )) : ''; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - case 'court': |
|
| 579 | - if ($avjc) { |
|
| 580 | - return $annee; |
|
| 581 | - } |
|
| 582 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 583 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 584 | - return $annee; |
|
| 585 | - } |
|
| 586 | - if ($annee != $a) { |
|
| 587 | - return _T( |
|
| 588 | - 'date_fmt_mois_annee', |
|
| 589 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return _T( |
|
| 594 | - 'date_fmt_jour_mois', |
|
| 595 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 596 | - ); |
|
| 597 | - |
|
| 598 | - case 'jourcourt': |
|
| 599 | - if ($avjc) { |
|
| 600 | - return $annee; |
|
| 601 | - } |
|
| 602 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 603 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 604 | - return $annee; |
|
| 605 | - } |
|
| 606 | - if ($annee != $a) { |
|
| 607 | - return _T( |
|
| 608 | - 'date_fmt_jour_mois_annee', |
|
| 609 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 610 | - ); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return _T( |
|
| 614 | - 'date_fmt_jour_mois', |
|
| 615 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 616 | - ); |
|
| 617 | - |
|
| 618 | - case 'entier': |
|
| 619 | - if ($avjc) { |
|
| 620 | - return $annee; |
|
| 621 | - } |
|
| 622 | - if ($jour) { |
|
| 623 | - return _T( |
|
| 624 | - 'date_fmt_jour_mois_annee', |
|
| 625 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 626 | - ); |
|
| 627 | - } elseif ($mois) { |
|
| 628 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 629 | - } else { |
|
| 630 | - return $annee; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - case 'nom_mois': |
|
| 634 | - return $nommois; |
|
| 635 | - |
|
| 636 | - case 'mois': |
|
| 637 | - return sprintf('%02s', $mois); |
|
| 638 | - |
|
| 639 | - case 'jour': |
|
| 640 | - return $jour; |
|
| 641 | - |
|
| 642 | - case 'journum': |
|
| 643 | - return $journum; |
|
| 644 | - |
|
| 645 | - case 'nom_jour': |
|
| 646 | - if (!$mois or !$njour) { |
|
| 647 | - return ''; |
|
| 648 | - } |
|
| 649 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 650 | - $nom = 1 + date('w', $nom); |
|
| 651 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 652 | - |
|
| 653 | - return _T('date_jour_' . $nom . $param); |
|
| 654 | - |
|
| 655 | - case 'mois_annee': |
|
| 656 | - if ($avjc) { |
|
| 657 | - return $annee; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 661 | - |
|
| 662 | - case 'annee': |
|
| 663 | - return $annee; |
|
| 664 | - |
|
| 665 | - // Cas d'une vue non definie : retomber sur le format |
|
| 666 | - // de date propose par http://www.php.net/date |
|
| 667 | - default: |
|
| 668 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 669 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 670 | - $time = strtotime($numdate); |
|
| 671 | - } |
|
| 672 | - return date($vue, $time); |
|
| 673 | - } |
|
| 506 | + if (is_string($options)) { |
|
| 507 | + $options = ['param' => $options]; |
|
| 508 | + } |
|
| 509 | + $date_array = recup_date($numdate, false); |
|
| 510 | + if (!$date_array) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 514 | + |
|
| 515 | + // 1er, 21st, etc. |
|
| 516 | + $journum = $jour; |
|
| 517 | + |
|
| 518 | + if ($jour == 0) { |
|
| 519 | + $jour = ''; |
|
| 520 | + $njour = 0; |
|
| 521 | + } else { |
|
| 522 | + $njour = intval($jour); |
|
| 523 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 524 | + $jour = $jourth; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $mois = intval($mois); |
|
| 529 | + if ($mois > 0 and $mois < 13) { |
|
| 530 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 531 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 532 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | + if ($jour) { |
|
| 534 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 535 | + } else { |
|
| 536 | + $jourmois = $nommois; |
|
| 537 | + } |
|
| 538 | + } else { |
|
| 539 | + $nommois = ''; |
|
| 540 | + $jourmois = ''; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ($annee < 0) { |
|
| 544 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 545 | + $avjc = true; |
|
| 546 | + } else { |
|
| 547 | + $avjc = false; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + switch ($vue) { |
|
| 551 | + case 'saison': |
|
| 552 | + case 'saison_annee': |
|
| 553 | + $saison = ''; |
|
| 554 | + if ($mois > 0) { |
|
| 555 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 556 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 557 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 558 | + } |
|
| 559 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 561 | + } |
|
| 562 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 563 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 564 | + } |
|
| 565 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 566 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + if ($vue == 'saison') { |
|
| 570 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 571 | + } else { |
|
| 572 | + return $saison ? trim(_T( |
|
| 573 | + 'date_fmt_saison_annee', |
|
| 574 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 575 | + )) : ''; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + case 'court': |
|
| 579 | + if ($avjc) { |
|
| 580 | + return $annee; |
|
| 581 | + } |
|
| 582 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 583 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 584 | + return $annee; |
|
| 585 | + } |
|
| 586 | + if ($annee != $a) { |
|
| 587 | + return _T( |
|
| 588 | + 'date_fmt_mois_annee', |
|
| 589 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return _T( |
|
| 594 | + 'date_fmt_jour_mois', |
|
| 595 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 596 | + ); |
|
| 597 | + |
|
| 598 | + case 'jourcourt': |
|
| 599 | + if ($avjc) { |
|
| 600 | + return $annee; |
|
| 601 | + } |
|
| 602 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 603 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 604 | + return $annee; |
|
| 605 | + } |
|
| 606 | + if ($annee != $a) { |
|
| 607 | + return _T( |
|
| 608 | + 'date_fmt_jour_mois_annee', |
|
| 609 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 610 | + ); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return _T( |
|
| 614 | + 'date_fmt_jour_mois', |
|
| 615 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 616 | + ); |
|
| 617 | + |
|
| 618 | + case 'entier': |
|
| 619 | + if ($avjc) { |
|
| 620 | + return $annee; |
|
| 621 | + } |
|
| 622 | + if ($jour) { |
|
| 623 | + return _T( |
|
| 624 | + 'date_fmt_jour_mois_annee', |
|
| 625 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 626 | + ); |
|
| 627 | + } elseif ($mois) { |
|
| 628 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 629 | + } else { |
|
| 630 | + return $annee; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + case 'nom_mois': |
|
| 634 | + return $nommois; |
|
| 635 | + |
|
| 636 | + case 'mois': |
|
| 637 | + return sprintf('%02s', $mois); |
|
| 638 | + |
|
| 639 | + case 'jour': |
|
| 640 | + return $jour; |
|
| 641 | + |
|
| 642 | + case 'journum': |
|
| 643 | + return $journum; |
|
| 644 | + |
|
| 645 | + case 'nom_jour': |
|
| 646 | + if (!$mois or !$njour) { |
|
| 647 | + return ''; |
|
| 648 | + } |
|
| 649 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 650 | + $nom = 1 + date('w', $nom); |
|
| 651 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 652 | + |
|
| 653 | + return _T('date_jour_' . $nom . $param); |
|
| 654 | + |
|
| 655 | + case 'mois_annee': |
|
| 656 | + if ($avjc) { |
|
| 657 | + return $annee; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 661 | + |
|
| 662 | + case 'annee': |
|
| 663 | + return $annee; |
|
| 664 | + |
|
| 665 | + // Cas d'une vue non definie : retomber sur le format |
|
| 666 | + // de date propose par http://www.php.net/date |
|
| 667 | + default: |
|
| 668 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 669 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 670 | + $time = strtotime($numdate); |
|
| 671 | + } |
|
| 672 | + return date($vue, $time); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | |
@@ -697,11 +697,11 @@ discard block |
||
| 697 | 697 | * Nom du jour |
| 698 | 698 | **/ |
| 699 | 699 | function nom_jour($numdate, $forme = '') { |
| 700 | - if (!($forme == 'abbr' or $forme == 'initiale')) { |
|
| 701 | - $forme = ''; |
|
| 702 | - } |
|
| 700 | + if (!($forme == 'abbr' or $forme == 'initiale')) { |
|
| 701 | + $forme = ''; |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - return affdate_base($numdate, 'nom_jour', $forme); |
|
| 704 | + return affdate_base($numdate, 'nom_jour', $forme); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | * Numéro du jour |
| 724 | 724 | **/ |
| 725 | 725 | function jour($numdate) { |
| 726 | - return affdate_base($numdate, 'jour'); |
|
| 726 | + return affdate_base($numdate, 'jour'); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | * Numéro du jour |
| 742 | 742 | **/ |
| 743 | 743 | function journum($numdate) { |
| 744 | - return affdate_base($numdate, 'journum'); |
|
| 744 | + return affdate_base($numdate, 'journum'); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * Numéro du mois (sur 2 chiffres) |
| 760 | 760 | **/ |
| 761 | 761 | function mois($numdate) { |
| 762 | - return affdate_base($numdate, 'mois'); |
|
| 762 | + return affdate_base($numdate, 'mois'); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | * Nom du mois |
| 784 | 784 | **/ |
| 785 | 785 | function nom_mois($numdate, $forme = '') { |
| 786 | - if (!($forme == 'abbr')) { |
|
| 787 | - $forme = ''; |
|
| 788 | - } |
|
| 786 | + if (!($forme == 'abbr')) { |
|
| 787 | + $forme = ''; |
|
| 788 | + } |
|
| 789 | 789 | |
| 790 | - return affdate_base($numdate, 'nom_mois', $forme); |
|
| 790 | + return affdate_base($numdate, 'nom_mois', $forme); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * Année (sur 4 chiffres) |
| 806 | 806 | **/ |
| 807 | 807 | function annee($numdate) { |
| 808 | - return affdate_base($numdate, 'annee'); |
|
| 808 | + return affdate_base($numdate, 'annee'); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -835,11 +835,11 @@ discard block |
||
| 835 | 835 | * La date formatée |
| 836 | 836 | **/ |
| 837 | 837 | function saison($numdate, $hemisphere = 'nord') { |
| 838 | - if ($hemisphere != 'sud') { |
|
| 839 | - $hemisphere = 'nord'; |
|
| 840 | - } |
|
| 838 | + if ($hemisphere != 'sud') { |
|
| 839 | + $hemisphere = 'nord'; |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | - return affdate_base($numdate, 'saison', $hemisphere); |
|
| 842 | + return affdate_base($numdate, 'saison', $hemisphere); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | |
@@ -868,11 +868,11 @@ discard block |
||
| 868 | 868 | * La date formatée |
| 869 | 869 | **/ |
| 870 | 870 | function saison_annee($numdate, $hemisphere = 'nord') { |
| 871 | - if ($hemisphere != 'sud') { |
|
| 872 | - $hemisphere = 'nord'; |
|
| 873 | - } |
|
| 871 | + if ($hemisphere != 'sud') { |
|
| 872 | + $hemisphere = 'nord'; |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - return affdate_base($numdate, 'saison_annee', $hemisphere); |
|
| 875 | + return affdate_base($numdate, 'saison_annee', $hemisphere); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | * La date formatée |
| 901 | 901 | **/ |
| 902 | 902 | function affdate($numdate, $format = 'entier') { |
| 903 | - return affdate_base($numdate, $format); |
|
| 903 | + return affdate_base($numdate, $format); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | * La date formatée |
| 928 | 928 | **/ |
| 929 | 929 | function affdate_court($numdate, $annee_courante = null) { |
| 930 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 930 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * La date formatée |
| 955 | 955 | **/ |
| 956 | 956 | function affdate_jourcourt($numdate, $annee_courante = null) { |
| 957 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 957 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | * La date formatée |
| 973 | 973 | **/ |
| 974 | 974 | function affdate_mois_annee($numdate) { |
| 975 | - return affdate_base($numdate, 'mois_annee'); |
|
| 975 | + return affdate_base($numdate, 'mois_annee'); |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | /** |
@@ -990,16 +990,16 @@ discard block |
||
| 990 | 990 | * La date formatée |
| 991 | 991 | **/ |
| 992 | 992 | function affdate_heure($numdate) { |
| 993 | - $date_array = recup_date($numdate); |
|
| 994 | - if (!$date_array) { |
|
| 995 | - return; |
|
| 996 | - } |
|
| 997 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 998 | - |
|
| 999 | - return _T('date_fmt_jour_heure', [ |
|
| 1000 | - 'jour' => affdate($numdate), |
|
| 1001 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1002 | - ]); |
|
| 993 | + $date_array = recup_date($numdate); |
|
| 994 | + if (!$date_array) { |
|
| 995 | + return; |
|
| 996 | + } |
|
| 997 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 998 | + |
|
| 999 | + return _T('date_fmt_jour_heure', [ |
|
| 1000 | + 'jour' => affdate($numdate), |
|
| 1001 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1002 | + ]); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1031,117 +1031,117 @@ discard block |
||
| 1031 | 1031 | * Texte de la date |
| 1032 | 1032 | */ |
| 1033 | 1033 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') { |
| 1034 | - $abbr = $jour = ''; |
|
| 1035 | - $affdate = 'affdate_jourcourt'; |
|
| 1036 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1037 | - $abbr = 'abbr'; |
|
| 1038 | - } |
|
| 1039 | - if (strpos($forme, 'annee') !== false) { |
|
| 1040 | - $affdate = 'affdate'; |
|
| 1041 | - } |
|
| 1042 | - if (strpos($forme, 'jour') !== false) { |
|
| 1043 | - $jour = 'jour'; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1047 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1048 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1049 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | - $dtabbr = '</abbr>'; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $date_debut = strtotime($date_debut); |
|
| 1054 | - $date_fin = strtotime($date_fin); |
|
| 1055 | - $d = date('Y-m-d', $date_debut); |
|
| 1056 | - $f = date('Y-m-d', $date_fin); |
|
| 1057 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1058 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1059 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1060 | - |
|
| 1061 | - if ($d == $f) { // meme jour |
|
| 1062 | - $nomjour = nom_jour($d, $abbr); |
|
| 1063 | - $s = $affdate($d); |
|
| 1064 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1065 | - if ($h) { |
|
| 1066 | - if ($hd == $hf) { |
|
| 1067 | - // Lundi 20 fevrier a 18h25 |
|
| 1068 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1069 | - $s = "$dtstart$s$dtabbr"; |
|
| 1070 | - } else { |
|
| 1071 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1072 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1073 | - $s = _T( |
|
| 1074 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1075 | - [ |
|
| 1076 | - 'jour' => spip_ucfirst($s), |
|
| 1077 | - 'heure_debut' => $hd, |
|
| 1078 | - 'heure_fin' => $hf, |
|
| 1079 | - 'dtstart' => $dtstart, |
|
| 1080 | - 'dtend' => $dtend, |
|
| 1081 | - 'dtabbr' => $dtabbr |
|
| 1082 | - ], |
|
| 1083 | - [ |
|
| 1084 | - 'sanitize' => false |
|
| 1085 | - ] |
|
| 1086 | - ); |
|
| 1087 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1088 | - else { |
|
| 1089 | - $s = spip_ucfirst(_T( |
|
| 1090 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1091 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1092 | - )); |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } else { |
|
| 1096 | - if ($dtabbr && $dtstart) { |
|
| 1097 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1098 | - } else { |
|
| 1099 | - $s = spip_ucfirst($s); |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - } else { |
|
| 1103 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1104 | - if (!$h) { |
|
| 1105 | - $date_debut = jour($d); |
|
| 1106 | - } else { |
|
| 1107 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | - } |
|
| 1109 | - $date_fin = $affdate($f); |
|
| 1110 | - if ($jour) { |
|
| 1111 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1112 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1113 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1114 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1115 | - } |
|
| 1116 | - if ($h) { |
|
| 1117 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1118 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1119 | - } |
|
| 1120 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | - |
|
| 1123 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1124 | - } else { |
|
| 1125 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1126 | - $date_fin = $affdate($f); |
|
| 1127 | - if ($jour) { |
|
| 1128 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1129 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1130 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1131 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1132 | - } |
|
| 1133 | - if ($h) { |
|
| 1134 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1135 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1139 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1141 | - } |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - return $s; |
|
| 1034 | + $abbr = $jour = ''; |
|
| 1035 | + $affdate = 'affdate_jourcourt'; |
|
| 1036 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1037 | + $abbr = 'abbr'; |
|
| 1038 | + } |
|
| 1039 | + if (strpos($forme, 'annee') !== false) { |
|
| 1040 | + $affdate = 'affdate'; |
|
| 1041 | + } |
|
| 1042 | + if (strpos($forme, 'jour') !== false) { |
|
| 1043 | + $jour = 'jour'; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1047 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1048 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1049 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | + $dtabbr = '</abbr>'; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $date_debut = strtotime($date_debut); |
|
| 1054 | + $date_fin = strtotime($date_fin); |
|
| 1055 | + $d = date('Y-m-d', $date_debut); |
|
| 1056 | + $f = date('Y-m-d', $date_fin); |
|
| 1057 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1058 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1059 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1060 | + |
|
| 1061 | + if ($d == $f) { // meme jour |
|
| 1062 | + $nomjour = nom_jour($d, $abbr); |
|
| 1063 | + $s = $affdate($d); |
|
| 1064 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1065 | + if ($h) { |
|
| 1066 | + if ($hd == $hf) { |
|
| 1067 | + // Lundi 20 fevrier a 18h25 |
|
| 1068 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1069 | + $s = "$dtstart$s$dtabbr"; |
|
| 1070 | + } else { |
|
| 1071 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1072 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1073 | + $s = _T( |
|
| 1074 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1075 | + [ |
|
| 1076 | + 'jour' => spip_ucfirst($s), |
|
| 1077 | + 'heure_debut' => $hd, |
|
| 1078 | + 'heure_fin' => $hf, |
|
| 1079 | + 'dtstart' => $dtstart, |
|
| 1080 | + 'dtend' => $dtend, |
|
| 1081 | + 'dtabbr' => $dtabbr |
|
| 1082 | + ], |
|
| 1083 | + [ |
|
| 1084 | + 'sanitize' => false |
|
| 1085 | + ] |
|
| 1086 | + ); |
|
| 1087 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1088 | + else { |
|
| 1089 | + $s = spip_ucfirst(_T( |
|
| 1090 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1091 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1092 | + )); |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } else { |
|
| 1096 | + if ($dtabbr && $dtstart) { |
|
| 1097 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1098 | + } else { |
|
| 1099 | + $s = spip_ucfirst($s); |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + } else { |
|
| 1103 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1104 | + if (!$h) { |
|
| 1105 | + $date_debut = jour($d); |
|
| 1106 | + } else { |
|
| 1107 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | + } |
|
| 1109 | + $date_fin = $affdate($f); |
|
| 1110 | + if ($jour) { |
|
| 1111 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1112 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1113 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1114 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1115 | + } |
|
| 1116 | + if ($h) { |
|
| 1117 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1118 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1119 | + } |
|
| 1120 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + |
|
| 1123 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1124 | + } else { |
|
| 1125 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1126 | + $date_fin = $affdate($f); |
|
| 1127 | + if ($jour) { |
|
| 1128 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1129 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1130 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1131 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1132 | + } |
|
| 1133 | + if ($h) { |
|
| 1134 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1135 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1139 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + return $s; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1162,10 +1162,10 @@ discard block |
||
| 1162 | 1162 | * Date au format ical |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function date_ical($date, $addminutes = 0) { |
| 1165 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1166 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1165 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1166 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1167 | 1167 | |
| 1168 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1168 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | |
@@ -1189,11 +1189,11 @@ discard block |
||
| 1189 | 1189 | * La date formatée |
| 1190 | 1190 | **/ |
| 1191 | 1191 | function date_iso($date_heure) { |
| 1192 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1193 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1194 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1192 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1193 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1194 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1195 | 1195 | |
| 1196 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1196 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | /** |
@@ -1216,11 +1216,11 @@ discard block |
||
| 1216 | 1216 | * La date formatée |
| 1217 | 1217 | **/ |
| 1218 | 1218 | function date_822($date_heure) { |
| 1219 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1220 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1221 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1219 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1220 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1221 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1222 | 1222 | |
| 1223 | - return date('r', $time); |
|
| 1223 | + return date('r', $time); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | /** |
@@ -1236,11 +1236,11 @@ discard block |
||
| 1236 | 1236 | * Date au format `Ymd` |
| 1237 | 1237 | **/ |
| 1238 | 1238 | function date_anneemoisjour($d) { |
| 1239 | - if (!$d) { |
|
| 1240 | - $d = date('Y-m-d'); |
|
| 1241 | - } |
|
| 1239 | + if (!$d) { |
|
| 1240 | + $d = date('Y-m-d'); |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1243 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | /** |
@@ -1256,11 +1256,11 @@ discard block |
||
| 1256 | 1256 | * Date au format `Ym` |
| 1257 | 1257 | **/ |
| 1258 | 1258 | function date_anneemois($d) { |
| 1259 | - if (!$d) { |
|
| 1260 | - $d = date('Y-m-d'); |
|
| 1261 | - } |
|
| 1259 | + if (!$d) { |
|
| 1260 | + $d = date('Y-m-d'); |
|
| 1261 | + } |
|
| 1262 | 1262 | |
| 1263 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1263 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | /** |
@@ -1276,13 +1276,13 @@ discard block |
||
| 1276 | 1276 | * Date au lundi de la même semaine au format `Ymd` |
| 1277 | 1277 | **/ |
| 1278 | 1278 | function date_debut_semaine($annee, $mois, $jour) { |
| 1279 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1280 | - if ($w_day == 0) { |
|
| 1281 | - $w_day = 7; |
|
| 1282 | - } // Gaffe: le dimanche est zero |
|
| 1283 | - $debut = $jour - $w_day + 1; |
|
| 1279 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1280 | + if ($w_day == 0) { |
|
| 1281 | + $w_day = 7; |
|
| 1282 | + } // Gaffe: le dimanche est zero |
|
| 1283 | + $debut = $jour - $w_day + 1; |
|
| 1284 | 1284 | |
| 1285 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1285 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1298,11 +1298,11 @@ discard block |
||
| 1298 | 1298 | * Date au dimanche de la même semaine au format `Ymd` |
| 1299 | 1299 | **/ |
| 1300 | 1300 | function date_fin_semaine($annee, $mois, $jour) { |
| 1301 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1302 | - if ($w_day == 0) { |
|
| 1303 | - $w_day = 7; |
|
| 1304 | - } // Gaffe: le dimanche est zero |
|
| 1305 | - $debut = $jour - $w_day + 1; |
|
| 1301 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1302 | + if ($w_day == 0) { |
|
| 1303 | + $w_day = 7; |
|
| 1304 | + } // Gaffe: le dimanche est zero |
|
| 1305 | + $debut = $jour - $w_day + 1; |
|
| 1306 | 1306 | |
| 1307 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1307 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1308 | 1308 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Logos |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -37,34 +37,34 @@ discard block |
||
| 37 | 37 | **/ |
| 38 | 38 | function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on', $compat_old_logos = true) { |
| 39 | 39 | |
| 40 | - $mode = preg_replace(',\W,', '', $mode); |
|
| 41 | - if ($mode) { |
|
| 42 | - // chercher dans la base |
|
| 43 | - $mode_document = 'logo' . $mode; |
|
| 44 | - $objet = objet_type($_id_objet); |
|
| 45 | - $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . intval($id)); |
|
| 46 | - if ($doc) { |
|
| 47 | - include_spip('inc/documents'); |
|
| 48 | - $d = get_spip_doc($doc['fichier']); |
|
| 49 | - return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc]; |
|
| 50 | - } |
|
| 40 | + $mode = preg_replace(',\W,', '', $mode); |
|
| 41 | + if ($mode) { |
|
| 42 | + // chercher dans la base |
|
| 43 | + $mode_document = 'logo' . $mode; |
|
| 44 | + $objet = objet_type($_id_objet); |
|
| 45 | + $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . intval($id)); |
|
| 46 | + if ($doc) { |
|
| 47 | + include_spip('inc/documents'); |
|
| 48 | + $d = get_spip_doc($doc['fichier']); |
|
| 49 | + return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc]; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - # deprecated TODO remove |
|
| 53 | - if ($compat_old_logos) { |
|
| 54 | - # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 55 | - $type = type_du_logo($_id_objet); |
|
| 56 | - $nom = $type . $mode . intval($id); |
|
| 52 | + # deprecated TODO remove |
|
| 53 | + if ($compat_old_logos) { |
|
| 54 | + # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 55 | + $type = type_du_logo($_id_objet); |
|
| 56 | + $nom = $type . $mode . intval($id); |
|
| 57 | 57 | |
| 58 | - foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 59 | - if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 60 | - return [$d, _DIR_LOGOS, $nom, $format, @filemtime($d)]; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 58 | + foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 59 | + if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 60 | + return [$d, _DIR_LOGOS, $nom, $format, @filemtime($d)]; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - # coherence de type pour servir comme filtre (formulaire_login) |
|
| 67 | - return []; |
|
| 66 | + # coherence de type pour servir comme filtre (formulaire_login) |
|
| 67 | + return []; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @deprecated 4.0 MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base |
| 84 | 84 | **/ |
| 85 | 85 | function type_du_logo($_id_objet) { |
| 86 | - return $GLOBALS['table_logos'][$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 86 | + return $GLOBALS['table_logos'][$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Exceptions standards (historique) |
| 90 | 90 | $GLOBALS['table_logos'] = [ |
| 91 | - 'id_article' => 'art', |
|
| 92 | - 'id_auteur' => 'aut', |
|
| 93 | - 'id_rubrique' => 'rub', |
|
| 94 | - 'id_groupe' => 'groupe', |
|
| 91 | + 'id_article' => 'art', |
|
| 92 | + 'id_auteur' => 'aut', |
|
| 93 | + 'id_rubrique' => 'rub', |
|
| 94 | + 'id_groupe' => 'groupe', |
|
| 95 | 95 | ]; |